firewirereg.h revision 109890
1103285Sikob/* 2103285Sikob * Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa 3103285Sikob * All rights reserved. 4103285Sikob * 5103285Sikob * Redistribution and use in source and binary forms, with or without 6103285Sikob * modification, are permitted provided that the following conditions 7103285Sikob * are met: 8103285Sikob * 1. Redistributions of source code must retain the above copyright 9103285Sikob * notice, this list of conditions and the following disclaimer. 10103285Sikob * 2. Redistributions in binary form must reproduce the above copyright 11103285Sikob * notice, this list of conditions and the following disclaimer in the 12103285Sikob * documentation and/or other materials provided with the distribution. 13103285Sikob * 3. All advertising materials mentioning features or use of this software 14103285Sikob * must display the acknowledgement as bellow: 15103285Sikob * 16103285Sikob * This product includes software developed by K. Kobayashi and H. Shimokawa 17103285Sikob * 18103285Sikob * 4. The name of the author may not be used to endorse or promote products 19103285Sikob * derived from this software without specific prior written permission. 20103285Sikob * 21103285Sikob * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22103285Sikob * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23103285Sikob * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24103285Sikob * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 25103285Sikob * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26103285Sikob * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27103285Sikob * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28103285Sikob * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29103285Sikob * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30103285Sikob * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31103285Sikob * POSSIBILITY OF SUCH DAMAGE. 32103285Sikob * 33103285Sikob * $FreeBSD: head/sys/dev/firewire/firewirereg.h 109890 2003-01-26 15:39:04Z simokawa $ 34103285Sikob * 35103285Sikob */ 36103285Sikob 37103285Sikob#if __FreeBSD_version >= 500000 38103285Sikobtypedef struct thread fw_proc; 39103285Sikob#include <sys/selinfo.h> 40103285Sikob#else 41103285Sikobtypedef struct proc fw_proc; 42103285Sikob#include <sys/select.h> 43103285Sikob#endif 44103285Sikob 45103285Sikob#define splfw splimp 46103285Sikob 47103285Sikobstruct fw_device{ 48103285Sikob u_int16_t dst; 49103285Sikob struct fw_eui64 eui; 50108701Ssimokawa#if 0 51103285Sikob u_int32_t spec; 52103285Sikob u_int32_t ver; 53108701Ssimokawa#endif 54103285Sikob u_int8_t speed; 55103285Sikob u_int8_t maxrec; 56103285Sikob u_int8_t nport; 57103285Sikob u_int8_t power; 58103285Sikob#define CSRROMOFF 0x400 59103285Sikob#define CSRROMSIZE 0x400 60103285Sikob int rommax; /* offset from 0xffff f000 0000 */ 61103285Sikob u_int32_t csrrom[CSRROMSIZE/4]; 62103285Sikob int rcnt; 63106810Ssimokawa struct firewire_comm *fc; 64103285Sikob u_int32_t status; 65103285Sikob#define FWDEVINIT 1 66103285Sikob#define FWDEVATTACHED 2 67103285Sikob#define FWDEVINVAL 3 68103285Sikob TAILQ_ENTRY(fw_device) link; 69106810Ssimokawa#if 0 70103285Sikob LIST_HEAD(, fw_xfer) txqueue; 71103285Sikob LIST_HEAD(, fw_xfer) rxqueue; 72106810Ssimokawa#endif 73103285Sikob}; 74109645Ssimokawa 75103285Sikobstruct firewire_softc { 76103285Sikob#if __FreeBSD_version >= 500000 77103285Sikob dev_t dev; 78103285Sikob#else 79103285Sikob dev_t dev[FWMAXNDMA+1]; 80103285Sikob#endif 81103285Sikob struct firewire_comm *fc; 82103285Sikob}; 83109645Ssimokawa 84103285Sikob#define FW_MAX_DMACH 0x20 85103285Sikob#define FW_MAX_DEVCH FW_MAX_DMACH 86103285Sikob#define FW_XFERTIMEOUT 1 87109645Ssimokawa 88103285Sikobstruct firewire_dev_comm { 89103285Sikob device_t dev; 90103285Sikob struct firewire_comm *fc; 91103285Sikob void (*post_explore) __P((void *)); 92103285Sikob}; 93103285Sikob 94103285Sikobstruct tcode_info { 95103285Sikob u_char hdr_len; /* IEEE1394 header length */ 96103285Sikob u_char flag; 97103285Sikob#define FWTI_REQ (1 << 0) 98103285Sikob#define FWTI_RES (1 << 1) 99103285Sikob#define FWTI_TLABEL (1 << 2) 100103285Sikob#define FWTI_BLOCK_STR (1 << 3) 101103285Sikob#define FWTI_BLOCK_ASY (1 << 4) 102103285Sikob}; 103103285Sikob 104103285Sikobstruct firewire_comm{ 105103285Sikob device_t dev; 106103285Sikob device_t bdev; 107103285Sikob u_int16_t busid:10, 108103285Sikob nodeid:6; 109103285Sikob u_int mode; 110103285Sikob u_int nport; 111103285Sikob u_int speed; 112103285Sikob u_int maxrec; 113103285Sikob u_int irm; 114103285Sikob u_int max_node; 115103285Sikob u_int max_hop; 116103285Sikob u_int max_asyretry; 117103285Sikob#define FWPHYASYST (1 << 0) 118103285Sikob u_int retry_count; 119103285Sikob u_int32_t ongobus:10, 120103285Sikob ongonode:6, 121103285Sikob ongoaddr:16; 122103285Sikob struct fw_device *ongodev; 123103285Sikob struct fw_eui64 ongoeui; 124103285Sikob#define FWMAXCSRDIR 16 125103285Sikob SLIST_HEAD(, csrdir) ongocsr; 126103285Sikob SLIST_HEAD(, csrdir) csrfree; 127103285Sikob u_int32_t status; 128103285Sikob#define FWBUSRESET 0 129103285Sikob#define FWBUSINIT 1 130103285Sikob#define FWBUSCYMELECT 2 131103285Sikob#define FWBUSMGRELECT 3 132103285Sikob#define FWBUSMGRDONE 4 133103285Sikob#define FWBUSEXPLORE 5 134103285Sikob#define FWBUSPHYCONF 6 135103285Sikob#define FWBUSEXPDONE 7 136103285Sikob#define FWBUSCOMPLETION 10 137103285Sikob int nisodma; 138109814Ssimokawa struct fw_eui64 eui; 139103285Sikob STAILQ_HEAD(fw_queue, fw_xfer); 140103285Sikob struct fw_xferq 141103285Sikob *arq, *atq, *ars, *ats, *it[FW_MAX_DMACH],*ir[FW_MAX_DMACH]; 142103285Sikob STAILQ_HEAD(, tlabel) tlabels[0x40]; 143103285Sikob STAILQ_HEAD(, fw_bind) binds; 144103285Sikob TAILQ_HEAD(, fw_device) devices; 145103285Sikob STAILQ_HEAD(, fw_xfer) pending; 146103285Sikob volatile u_int32_t *sid_buf; 147103285Sikob u_int sid_cnt; 148103285Sikob#define CSRSIZE 0x4000 149103285Sikob u_int32_t csr_arc[CSRSIZE/4]; 150103285Sikob#define CROMSIZE 0x400 151103285Sikob u_int32_t *config_rom; 152103285Sikob struct fw_topology_map *topology_map; 153103285Sikob struct fw_speed_map *speed_map; 154108853Ssimokawa struct callout busprobe_callout; 155103285Sikob struct callout_handle bmrhandle; 156103285Sikob struct callout_handle timeouthandle; 157103285Sikob struct callout_handle retry_probe_handle; 158103285Sikob u_int32_t (*cyctimer) __P((struct firewire_comm *)); 159103285Sikob void (*ibr) __P((struct firewire_comm *)); 160103285Sikob u_int32_t (*set_bmr) __P((struct firewire_comm *, u_int32_t)); 161103285Sikob int (*ioctl) __P((dev_t, u_long, caddr_t, int, fw_proc *)); 162103285Sikob int (*irx_enable) __P((struct firewire_comm *, int)); 163103285Sikob int (*irx_disable) __P((struct firewire_comm *, int)); 164103285Sikob int (*itx_enable) __P((struct firewire_comm *, int)); 165103285Sikob int (*itx_disable) __P((struct firewire_comm *, int)); 166103285Sikob void (*timeout) __P((void *)); 167103285Sikob void (*poll) __P((struct firewire_comm *, int, int)); 168103285Sikob void (*set_intr) __P((struct firewire_comm *, int)); 169103285Sikob void (*irx_post) __P((struct firewire_comm *, u_int32_t *)); 170103285Sikob void (*itx_post) __P((struct firewire_comm *, u_int32_t *)); 171103285Sikob struct tcode_info *tcode; 172103285Sikob}; 173103285Sikob#define CSRARC(sc, offset) ((sc)->csr_arc[(offset)/4]) 174103285Sikob 175109645Ssimokawastruct csrdir{ 176109645Ssimokawa u_int32_t ongoaddr; 177109645Ssimokawa u_int32_t off; 178109645Ssimokawa SLIST_ENTRY(csrdir) link; 179109645Ssimokawa}; 180103285Sikob 181109645Ssimokawastruct fw_xferq { 182109645Ssimokawa int flag; 183109645Ssimokawa#define FWXFERQ_CHTAGMASK 0xff 184109645Ssimokawa#define FWXFERQ_RUNNING (1 << 8) 185109645Ssimokawa#define FWXFERQ_STREAM (1 << 9) 186109645Ssimokawa 187109645Ssimokawa#define FWXFERQ_PACKET (1 << 10) 188109645Ssimokawa#define FWXFERQ_BULK (1 << 11) 189109890Ssimokawa#if 0 /* BROKEN */ 190109645Ssimokawa#define FWXFERQ_DV (1 << 12) 191109802Ssimokawa#endif 192109645Ssimokawa#define FWXFERQ_MODEMASK (7 << 10) 193109645Ssimokawa 194109645Ssimokawa#define FWXFERQ_EXTBUF (1 << 13) 195109645Ssimokawa#define FWXFERQ_OPEN (1 << 14) 196109645Ssimokawa 197109645Ssimokawa#define FWXFERQ_HANDLER (1 << 16) 198109645Ssimokawa#define FWXFERQ_WAKEUP (1 << 17) 199109645Ssimokawa 200109645Ssimokawa void (*start) __P((struct firewire_comm*)); 201109645Ssimokawa void (*drain) __P((struct firewire_comm*, struct fw_xfer*)); 202109645Ssimokawa struct fw_queue q; 203109645Ssimokawa u_int queued; 204109645Ssimokawa u_int maxq; 205109645Ssimokawa u_int psize; 206109645Ssimokawa u_int packets; 207109645Ssimokawa u_int error; 208109645Ssimokawa STAILQ_HEAD(, fw_bind) binds; 209109645Ssimokawa caddr_t buf; 210109645Ssimokawa u_int bnchunk; 211109645Ssimokawa u_int bnpacket; 212109645Ssimokawa u_int btpacket; 213109645Ssimokawa struct fw_bulkxfer *bulkxfer; 214109645Ssimokawa STAILQ_HEAD(, fw_bulkxfer) stvalid; 215109645Ssimokawa STAILQ_HEAD(, fw_bulkxfer) stfree; 216109890Ssimokawa STAILQ_HEAD(, fw_bulkxfer) stdma; 217109645Ssimokawa struct fw_bulkxfer *stproc; 218109890Ssimokawa#ifdef FWXFERQ_DV 219109645Ssimokawa int dvdbc, dvdiff, dvsync, dvoffset; 220109645Ssimokawa struct fw_dvbuf *dvbuf; 221109645Ssimokawa STAILQ_HEAD(, fw_dvbuf) dvvalid; 222109645Ssimokawa STAILQ_HEAD(, fw_dvbuf) dvfree; 223109645Ssimokawa struct fw_dvbuf *dvdma; 224109645Ssimokawa struct fw_dvbuf *dvproc; 225109645Ssimokawa u_int dvptr; 226109645Ssimokawa u_int dvpacket; 227109890Ssimokawa#endif 228109645Ssimokawa struct selinfo rsel; 229109645Ssimokawa caddr_t sc; 230109645Ssimokawa void (*hand) __P((struct fw_xferq *)); 231109645Ssimokawa}; 232109645Ssimokawa 233109645Ssimokawastruct fw_bulkxfer{ 234109645Ssimokawa caddr_t buf; 235109645Ssimokawa STAILQ_ENTRY(fw_bulkxfer) link; 236109645Ssimokawa caddr_t start; 237109645Ssimokawa caddr_t end; 238109645Ssimokawa u_int npacket; 239109645Ssimokawa}; 240109645Ssimokawa 241109645Ssimokawastruct fw_dvbuf{ 242109645Ssimokawa caddr_t buf; 243109645Ssimokawa STAILQ_ENTRY(fw_dvbuf) link; 244109645Ssimokawa}; 245109645Ssimokawa 246109645Ssimokawastruct tlabel{ 247109645Ssimokawa struct fw_xfer *xfer; 248109645Ssimokawa STAILQ_ENTRY(tlabel) link; 249109645Ssimokawa}; 250109645Ssimokawa 251109645Ssimokawastruct fw_bind{ 252109645Ssimokawa u_int32_t start_hi, start_lo, addrlen; 253109645Ssimokawa struct fw_xfer* xfer; 254109645Ssimokawa STAILQ_ENTRY(fw_bind) fclist; 255109645Ssimokawa STAILQ_ENTRY(fw_bind) chlist; 256109645Ssimokawa}; 257109645Ssimokawa 258103285Sikobstruct fw_xfer{ 259103285Sikob caddr_t sc; 260103285Sikob struct firewire_comm *fc; 261103285Sikob struct fw_xferq *q; 262103285Sikob struct callout_handle ch; 263103285Sikob time_t time; 264103285Sikob struct fw_tlabel *tlabel; 265103285Sikob u_int8_t spd; 266103285Sikob u_int8_t tcode; 267103285Sikob int resp; 268103285Sikob#define FWXF_INIT 0 269103285Sikob#define FWXF_INQ 1 270103285Sikob#define FWXF_START 2 271103285Sikob#define FWXF_SENT 3 272103285Sikob#define FWXF_SENTERR 4 273103285Sikob#define FWXF_BUSY 8 274103285Sikob#define FWXF_RCVD 10 275103285Sikob int state; 276103285Sikob u_int8_t retry; 277103285Sikob u_int8_t tl; 278103285Sikob int sub; 279103285Sikob int32_t dst; 280103285Sikob u_int8_t act_type; 281103285Sikob#define FWACT_NULL 0 282103285Sikob#define FWACT_XFER 2 283103285Sikob#define FWACT_CH 3 284103285Sikob void (*retry_req) __P((struct fw_xfer *)); 285103285Sikob union{ 286103285Sikob void (*hand) __P((struct fw_xfer *)); 287103285Sikob 288103285Sikob } act; 289103285Sikob union{ 290103285Sikob struct { 291103285Sikob struct fw_device *device; 292103285Sikob } req; 293103285Sikob struct { 294103285Sikob struct stch *channel; 295103285Sikob } stream; 296103285Sikob } mode; 297103285Sikob struct { 298103285Sikob u_int16_t len, off; 299103285Sikob caddr_t buf; 300103285Sikob } send, recv; 301103285Sikob struct mbuf *mbuf; 302103285Sikob STAILQ_ENTRY(fw_xfer) link; 303103285Sikob}; 304103285Sikobvoid fw_sidrcv __P((struct firewire_comm *, caddr_t, u_int, u_int)); 305103285Sikobvoid fw_rcv __P((struct firewire_comm *, caddr_t, u_int, u_int, u_int, u_int)); 306103285Sikobvoid fw_xfer_free __P(( struct fw_xfer*)); 307103285Sikobstruct fw_xfer *fw_xfer_alloc __P((void)); 308103285Sikobvoid fw_init __P((struct firewire_comm *)); 309103285Sikobint fw_tbuf_update __P((struct firewire_comm *, int, int)); 310103285Sikobint fw_rbuf_update __P((struct firewire_comm *, int, int)); 311103285Sikobint fw_readreqq __P((struct firewire_comm *, u_int32_t, u_int32_t, u_int32_t *)); 312103285Sikobint fw_writereqb __P((struct firewire_comm *, u_int32_t, u_int32_t, u_int32_t, u_int32_t *)); 313103285Sikobint fw_readresb __P((struct firewire_comm *, u_int32_t, u_int32_t, u_int32_t, u_int32_t*)); 314103285Sikobint fw_writeres __P((struct firewire_comm *, u_int32_t, u_int32_t)); 315103285Sikobu_int32_t getcsrdata __P((struct fw_device *, u_int8_t)); 316103285Sikobvoid fw_asybusy __P((struct fw_xfer *)); 317103285Sikobint fw_bindadd __P((struct firewire_comm *, struct fw_bind *)); 318103285Sikobint fw_bindremove __P((struct firewire_comm *, struct fw_bind *)); 319103285Sikobint fw_asyreq __P((struct firewire_comm *, int, struct fw_xfer*)); 320103285Sikobvoid fw_busreset __P((struct firewire_comm *)); 321103285Sikobu_int16_t fw_crc16 __P((u_int32_t *, u_int32_t)); 322103285Sikobvoid fw_xfer_timeout __P((void *)); 323103285Sikobvoid fw_xfer_done __P((struct fw_xfer *)); 324103285Sikobvoid fw_asy_callback __P((struct fw_xfer *)); 325106810Ssimokawastruct fw_device *fw_noderesolve __P((struct firewire_comm *, struct fw_eui64)); 326106813Ssimokawastruct fw_bind *fw_bindlookup __P((struct firewire_comm *, u_int32_t, u_int32_t)); 327103285Sikob 328106813Ssimokawa 329103285Sikobextern int firewire_debug; 330103285Sikobextern devclass_t firewire_devclass; 331103285Sikob 332103285Sikob#define DV_BROADCAST_ON (1<<30) 333103285Sikob#define IP_CHANNELS 0x0234 334103285Sikob 335103285Sikob#define STATE_CLEAR 0x0000 336103285Sikob#define STATE_SET 0x0004 337103285Sikob#define NODE_IDS 0x0008 338103285Sikob#define RESET_START 0x000c 339103285Sikob#define SPLIT_TIMEOUT_HI 0x0018 340103285Sikob#define SPLIT_TIMEOUT_LO 0x001c 341103285Sikob#define CYCLE_TIME 0x0200 342103285Sikob#define BUS_TIME 0x0210 343103285Sikob#define BUS_MGR_ID 0x021c 344103285Sikob#define BANDWIDTH_AV 0x0220 345103285Sikob#define CHANNELS_AV_HI 0x0224 346103285Sikob#define CHANNELS_AV_LO 0x0228 347103285Sikob 348103285Sikob#define CONF_ROM 0x0400 349103285Sikob 350103285Sikob#define TOPO_MAP 0x1000 351103285Sikob#define SPED_MAP 0x2000 352103285Sikob 353103285Sikob#define oMPR 0x900 354103285Sikob#define oPCR 0x904 355103285Sikob 356103285Sikob#define iMPR 0x980 357103285Sikob#define iPCR 0x984 358103285Sikob 359103285Sikob#define FWPRI ((PZERO+8)|PCATCH) 360103285Sikob 361103285Sikob#ifdef __alpha__ 362103285Sikob#undef vtophys 363103285Sikob#define vtophys(va) alpha_XXX_dmamap((vm_offset_t)(va)) 364103285Sikob#endif /* __alpha__ */ 365