1 /* 2 * Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the acknowledgement as bellow: 15 * 16 * This product includes software developed by K. Kobayashi and H. Shimokawa 17 * 18 * 4. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 * POSSIBILITY OF SUCH DAMAGE. 32 * 33 * $FreeBSD$ 34 * 35 */ 36 37 #if __FreeBSD_version >= 500000 38 typedef struct thread fw_proc; 39 #include <sys/selinfo.h> 40 #else 41 typedef struct proc fw_proc; 42 #include <sys/select.h> 43 #endif 44 45 #define splfw splimp 46 47 struct fw_device{ 48 u_int16_t dst; 49 struct fw_eui64 eui; 50 #if 0 51 u_int32_t spec; 52 u_int32_t ver; 53 #endif 54 u_int8_t speed; 55 u_int8_t maxrec; 56 u_int8_t nport; 57 u_int8_t power; 58 #define CSRROMOFF 0x400 59 #define CSRROMSIZE 0x400 60 int rommax; /* offset from 0xffff f000 0000 */ 61 u_int32_t csrrom[CSRROMSIZE/4]; 62 int rcnt; 63 struct firewire_comm *fc; 64 u_int32_t status; 65 #define FWDEVINIT 1 66 #define FWDEVATTACHED 2 67 #define FWDEVINVAL 3 68 STAILQ_ENTRY(fw_device) link; 69 #if 0 70 LIST_HEAD(, fw_xfer) txqueue; 71 LIST_HEAD(, fw_xfer) rxqueue; 72 #endif 73 }; 74 75 struct firewire_softc { 76 #if __FreeBSD_version >= 500000 77 dev_t dev; 78 #else 79 dev_t dev[FWMAXNDMA+1]; 80 #endif 81 struct firewire_comm *fc; 82 }; 83 84 #define FW_MAX_DMACH 0x20 85 #define FW_MAX_DEVCH FW_MAX_DMACH 86 #define FW_XFERTIMEOUT 1 87 88 struct firewire_dev_comm { 89 device_t dev; 90 struct firewire_comm *fc; 91 void (*post_explore) __P((void *)); 92 }; 93 94 struct tcode_info { 95 u_char hdr_len; /* IEEE1394 header length */ 96 u_char flag; 97 #define FWTI_REQ (1 << 0) 98 #define FWTI_RES (1 << 1) 99 #define FWTI_TLABEL (1 << 2) 100 #define FWTI_BLOCK_STR (1 << 3) 101 #define FWTI_BLOCK_ASY (1 << 4) 102 }; 103 104 struct firewire_comm{ 105 device_t dev; 106 device_t bdev; 107 u_int16_t busid:10, 108 nodeid:6; 109 u_int mode; 110 u_int nport; 111 u_int speed; 112 u_int maxrec; 113 u_int irm; 114 u_int max_node; 115 u_int max_hop; 116 u_int max_asyretry; 117 #define FWPHYASYST (1 << 0) 118 u_int retry_count; 119 u_int32_t ongobus:10, 120 ongonode:6, 121 ongoaddr:16; 122 struct fw_device *ongodev; 123 struct fw_eui64 ongoeui; 124 #define FWMAXCSRDIR 16 125 SLIST_HEAD(, csrdir) ongocsr; 126 SLIST_HEAD(, csrdir) csrfree; 127 u_int32_t status; 128 #define FWBUSRESET 0 129 #define FWBUSINIT 1 130 #define FWBUSCYMELECT 2 131 #define FWBUSMGRELECT 3 132 #define FWBUSMGRDONE 4 133 #define FWBUSEXPLORE 5 134 #define FWBUSPHYCONF 6 135 #define FWBUSEXPDONE 7 136 #define FWBUSCOMPLETION 10 137 int nisodma; 138 struct fw_eui64 eui; 139 STAILQ_HEAD(fw_queue, fw_xfer); 140 struct fw_xferq 141 *arq, *atq, *ars, *ats, *it[FW_MAX_DMACH],*ir[FW_MAX_DMACH]; 142 STAILQ_HEAD(, tlabel) tlabels[0x40]; 143 STAILQ_HEAD(, fw_bind) binds; 144 STAILQ_HEAD(, fw_device) devices; 145 STAILQ_HEAD(, fw_xfer) pending; 146 volatile u_int32_t *sid_buf; 147 u_int sid_cnt; 148 #define CSRSIZE 0x4000 149 u_int32_t csr_arc[CSRSIZE/4]; 150 #define CROMSIZE 0x400 151 u_int32_t *config_rom; 152 struct fw_topology_map *topology_map; 153 struct fw_speed_map *speed_map; 154 struct callout busprobe_callout; 155 struct callout bmr_callout; 156 struct callout timeout_callout; 157 struct callout retry_probe_callout; 158 u_int32_t (*cyctimer) __P((struct firewire_comm *)); 159 void (*ibr) __P((struct firewire_comm *)); 160 u_int32_t (*set_bmr) __P((struct firewire_comm *, u_int32_t)); 161 int (*ioctl) __P((dev_t, u_long, caddr_t, int, fw_proc *)); 162 int (*irx_enable) __P((struct firewire_comm *, int)); 163 int (*irx_disable) __P((struct firewire_comm *, int)); 164 int (*itx_enable) __P((struct firewire_comm *, int)); 165 int (*itx_disable) __P((struct firewire_comm *, int)); 166 void (*timeout) __P((void *)); 167 void (*poll) __P((struct firewire_comm *, int, int)); 168 void (*set_intr) __P((struct firewire_comm *, int)); 169 void (*irx_post) __P((struct firewire_comm *, u_int32_t *)); 170 void (*itx_post) __P((struct firewire_comm *, u_int32_t *)); 171 struct tcode_info *tcode; 172 }; 173 #define CSRARC(sc, offset) ((sc)->csr_arc[(offset)/4]) 174 175 struct csrdir{ 176 u_int32_t ongoaddr; 177 u_int32_t off; 178 SLIST_ENTRY(csrdir) link; 179 }; 180 181 struct fw_xferq { 182 int flag; 183 #define FWXFERQ_CHTAGMASK 0xff 184 #define FWXFERQ_RUNNING (1 << 8) 185 #define FWXFERQ_STREAM (1 << 9) 186 187 #define FWXFERQ_PACKET (1 << 10) 188 #define FWXFERQ_BULK (1 << 11) 189 #if 0 /* BROKEN */ 190 #define FWXFERQ_DV (1 << 12) 191 #endif 192 #define FWXFERQ_MODEMASK (7 << 10) 193 194 #define FWXFERQ_EXTBUF (1 << 13) 195 #define FWXFERQ_OPEN (1 << 14) 196 197 #define FWXFERQ_HANDLER (1 << 16) 198 #define FWXFERQ_WAKEUP (1 << 17) 199 200 void (*start) __P((struct firewire_comm*)); 201 void (*drain) __P((struct firewire_comm*, struct fw_xfer*)); 202 struct fw_queue q; 203 u_int queued; 204 u_int maxq; 205 u_int psize; 206 u_int packets; 207 STAILQ_HEAD(, fw_bind) binds; 208 caddr_t buf; 209 u_int bnchunk; 210 u_int bnpacket; 211 struct fw_bulkxfer *bulkxfer; 212 STAILQ_HEAD(, fw_bulkxfer) stvalid; 213 STAILQ_HEAD(, fw_bulkxfer) stfree; 214 STAILQ_HEAD(, fw_bulkxfer) stdma; 215 struct fw_bulkxfer *stproc; 216 #ifdef FWXFERQ_DV 217 int dvdbc, dvdiff, dvsync, dvoffset; 218 struct fw_dvbuf *dvbuf; 219 STAILQ_HEAD(, fw_dvbuf) dvvalid; 220 STAILQ_HEAD(, fw_dvbuf) dvfree; 221 struct fw_dvbuf *dvdma; 222 struct fw_dvbuf *dvproc; 223 u_int dvptr; 224 u_int dvpacket; 225 #endif 226 struct selinfo rsel; 227 caddr_t sc; 228 void (*hand) __P((struct fw_xferq *)); 229 }; 230 231 struct fw_bulkxfer{ 232 caddr_t buf; 233 STAILQ_ENTRY(fw_bulkxfer) link; 234 caddr_t start; 235 caddr_t end; 236 u_int npacket; 237 }; 238 239 struct fw_dvbuf{ 240 caddr_t buf; 241 STAILQ_ENTRY(fw_dvbuf) link; 242 }; 243 244 struct tlabel{ 245 struct fw_xfer *xfer; 246 STAILQ_ENTRY(tlabel) link; 247 }; 248 249 struct fw_bind{ 250 u_int32_t start_hi, start_lo, addrlen; 251 struct fw_xfer* xfer; 252 STAILQ_ENTRY(fw_bind) fclist; 253 STAILQ_ENTRY(fw_bind) chlist; 254 }; 255 256 struct fw_xfer{ 257 caddr_t sc; 258 struct firewire_comm *fc; 259 struct fw_xferq *q; 260 #ifdef XFER_TIMEOUT 261 struct callout_handle ch; 262 #endif 263 struct timeval tv; 264 struct fw_tlabel *tlabel; 265 u_int8_t spd; 266 u_int8_t tcode; 267 int resp; 268 #define FWXF_INIT 0 269 #define FWXF_INQ 1 270 #define FWXF_START 2 271 #define FWXF_SENT 3 272 #define FWXF_SENTERR 4 273 #define FWXF_BUSY 8 274 #define FWXF_RCVD 10 275 int state; 276 u_int8_t retry; 277 u_int8_t tl; 278 int sub; 279 int32_t dst; 280 u_int8_t act_type; 281 #define FWACT_NULL 0 282 #define FWACT_XFER 2 283 #define FWACT_CH 3 284 void (*retry_req) __P((struct fw_xfer *)); 285 union{ 286 void (*hand) __P((struct fw_xfer *)); 287 } act; 288 #if 0 289 union{ 290 struct { 291 struct fw_device *device; 292 } req; 293 struct { 294 struct stch *channel; 295 } stream; 296 } mode; 297 #endif 298 struct { 299 u_int16_t len, off; 300 caddr_t buf; 301 } send, recv; 302 struct mbuf *mbuf; 303 STAILQ_ENTRY(fw_xfer) link; 304 struct malloc_type *malloc; 305 }; 306 void fw_sidrcv __P((struct firewire_comm *, caddr_t, u_int, u_int)); 307 void fw_rcv __P((struct firewire_comm *, caddr_t, u_int, u_int, u_int, u_int)); 308 void fw_xfer_free __P(( struct fw_xfer*)); 309 struct fw_xfer *fw_xfer_alloc __P((struct malloc_type *)); 310 void fw_init __P((struct firewire_comm *)); 311 int fw_tbuf_update __P((struct firewire_comm *, int, int)); 312 int fw_rbuf_update __P((struct firewire_comm *, int, int)); 313 int fw_readreqq __P((struct firewire_comm *, u_int32_t, u_int32_t, u_int32_t *)); 314 int fw_writereqb __P((struct firewire_comm *, u_int32_t, u_int32_t, u_int32_t, u_int32_t *)); 315 int fw_readresb __P((struct firewire_comm *, u_int32_t, u_int32_t, u_int32_t, u_int32_t*)); 316 int fw_writeres __P((struct firewire_comm *, u_int32_t, u_int32_t)); 317 u_int32_t getcsrdata __P((struct fw_device *, u_int8_t)); 318 void fw_asybusy __P((struct fw_xfer *)); 319 int fw_bindadd __P((struct firewire_comm *, struct fw_bind *)); 320 int fw_bindremove __P((struct firewire_comm *, struct fw_bind *)); 321 int fw_asyreq __P((struct firewire_comm *, int, struct fw_xfer*)); 322 void fw_busreset __P((struct firewire_comm *)); 323 u_int16_t fw_crc16 __P((u_int32_t *, u_int32_t)); 324 void fw_xfer_timeout __P((void *)); 325 void fw_xfer_done __P((struct fw_xfer *)); 326 void fw_asy_callback __P((struct fw_xfer *)); 327 struct fw_device *fw_noderesolve_nodeid __P((struct firewire_comm *, int)); 328 struct fw_device *fw_noderesolve_eui64 __P((struct firewire_comm *, struct fw_eui64 *)); 329 struct fw_bind *fw_bindlookup __P((struct firewire_comm *, u_int32_t, u_int32_t)); 330 void fw_drain_txq __P((struct firewire_comm *)); 331 332 333 extern int firewire_debug; 334 extern devclass_t firewire_devclass; 335 336 #define DV_BROADCAST_ON (1<<30) 337 #define IP_CHANNELS 0x0234 338 339 #define STATE_CLEAR 0x0000 340 #define STATE_SET 0x0004 341 #define NODE_IDS 0x0008 342 #define RESET_START 0x000c 343 #define SPLIT_TIMEOUT_HI 0x0018 344 #define SPLIT_TIMEOUT_LO 0x001c 345 #define CYCLE_TIME 0x0200 346 #define BUS_TIME 0x0204 347 #define BUSY_TIMEOUT 0x0210 348 #define BUS_MGR_ID 0x021c 349 #define BANDWIDTH_AV 0x0220 350 #define CHANNELS_AV_HI 0x0224 351 #define CHANNELS_AV_LO 0x0228 352 353 #define CONF_ROM 0x0400 354 355 #define TOPO_MAP 0x1000 356 #define SPED_MAP 0x2000 357 358 #define oMPR 0x900 359 #define oPCR 0x904 360 361 #define iMPR 0x980 362 #define iPCR 0x984 363 364 #define FWPRI ((PZERO+8)|PCATCH) 365 366 #ifdef __alpha__ 367 #undef vtophys 368 #define vtophys(va) alpha_XXX_dmamap((vm_offset_t)(va)) 369 #endif /* __alpha__ */ 370 371 #if __FreeBSD_version >= 500000 372 #define CALLOUT_INIT(x) callout_init(x, 0 /* mpsafe */) 373 #else 374 #define CALLOUT_INIT(x) callout_init(x) 375 #endif 376 377 MALLOC_DECLARE(M_FW); 378 MALLOC_DECLARE(M_FWXFER); 379