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 #ifndef _FIREWIRE_H 38 #define _FIREWIRE_H 1 39 40 #define DEV_DEF 0 41 #define DEV_DV 2 42 43 #if 0 44 struct dv_data{ 45 u_int32_t n_write; 46 u_int32_t a_write; 47 u_int32_t k_write; 48 u_int32_t write_done; 49 u_int32_t write_len[16]; 50 u_int32_t write_off[16]; 51 u_int32_t n_read; 52 u_int32_t a_read; 53 u_int32_t k_read; 54 u_int32_t read_done; 55 u_int32_t read_len[16]; 56 u_int32_t read_off[16]; 57 }; 58 59 struct dv_data_req_t { 60 unsigned long index; 61 unsigned long len; 62 unsigned long off; 63 }; 64 #endif 65 66 struct fw_isochreq { 67 unsigned char ch:6, 68 tag:2; 69 }; 70 71 struct fw_isobufreq { 72 struct { 73 unsigned int nchunk; 74 unsigned int npacket; 75 unsigned int psize; 76 } tx, rx; 77 }; 78 79 struct fw_addr { 80 unsigned long hi; 81 unsigned long lo; 82 }; 83 84 struct fw_asybindreq { 85 struct fw_addr start; 86 unsigned long len; 87 }; 88 89 struct fw_reg_req_t { 90 unsigned long addr; 91 unsigned long data; 92 }; 93 94 #define MAXREC(x) (2 << (x)) 95 #define FWPMAX_S400 (2048 + 20) /* MAXREC plus space for control data */ 96 #define FWMAXQUEUE 128 97 98 #define FWLOCALBUS 0xffc0 99 100 #define FWTCODE_WREQQ 0 101 #define FWTCODE_WREQB 1 102 #define FWTCODE_WRES 2 103 #define FWTCODE_RREQQ 4 104 #define FWTCODE_RREQB 5 105 #define FWTCODE_RRESQ 6 106 #define FWTCODE_RRESB 7 107 #define FWTCODE_CYCS 8 108 #define FWTCODE_LREQ 9 109 #define FWTCODE_STREAM 0xa 110 #define FWTCODE_LRES 0xb 111 #define FWTCODE_PHY 0xe 112 113 #define FWRETRY_1 0 114 #define FWRETRY_X 1 115 #define FWRETRY_A 2 116 #define FWRETRY_B 3 117 118 #define FWRCODE_COMPLETE 0 119 #define FWRCODE_ER_CONFL 4 120 #define FWRCODE_ER_DATA 5 121 #define FWRCODE_ER_TYPE 6 122 #define FWRCODE_ER_ADDR 7 123 124 #define FWSPD_S100 0 125 #define FWSPD_S200 1 126 #define FWSPD_S400 2 127 128 #define FWP_TL_VALID (1 << 7) 129 130 struct fw_isohdr { 131 u_int32_t hdr[1]; 132 }; 133 134 struct fw_asyhdr { 135 u_int32_t hdr[4]; 136 }; 137 138 #if 0 139 #define FWPHYSIDSUBS(SID) (((SID) >> 23) & 1) 140 #define FWPHYSIDNODE(SID) (((SID) >> 24) & 0x3f) 141 #define FWPHYSIDLINK(SID) (((SID) >> 22) & 1) 142 #define FWPHYSIDGAP(SID) (((SID) >> 16) & 0x3f) 143 #define FWPHYSIDSPD(SID) (((SID) >> 14) & 0x3) 144 #define FWPHYSIDDEL(SID) (((SID) >> 12) & 0x3) 145 #define FWPHYSIDCON(SID) (((SID) >> 11) & 1) 146 #define FWPHYSIDPWR(SID) (((SID) >> 8) & 0x7) 147 #define FWPHYSIDP0(SID) (((SID) >> 6) & 0x3) 148 #define FWPHYSIDP1(SID) (((SID) >> 4) & 0x3) 149 #define FWPHYSIDP2(SID) (((SID) >> 2) & 0x3) 150 #define FWPHYSIDIR(SID) (((SID) >> 1) & 1) 151 #define FWPHYSIDMORE(SID) ((SID) & 1) 152 #define FWPHYSIDSEQ(SID) (((SID) >> 20) & 0x7) 153 #define FWPHYSIDPA(SID) (((SID) >> 16) & 0x3) 154 #define FWPHYSIDPB(SID) (((SID) >> 14) & 0x3) 155 #define FWPHYSIDPC(SID) (((SID) >> 12) & 0x3) 156 #define FWPHYSIDPD(SID) (((SID) >> 10) & 0x3) 157 #define FWPHYSIDPE(SID) (((SID) >> 8) & 0x3) 158 #define FWPHYSIDPF(SID) (((SID) >> 6) & 0x3) 159 #define FWPHYSIDPG(SID) (((SID) >> 4) & 0x3) 160 #define FWPHYSIDPH(SID) (((SID) >> 2) & 0x3) 161 #endif 162 163 struct fw_pkt { 164 union { 165 u_int32_t ld[0]; 166 struct { 167 u_int16_t :16; 168 u_int8_t :8; 169 u_int8_t :4, 170 tcode:4; 171 } common; 172 struct { 173 u_int16_t len; 174 u_int8_t chtag; 175 u_int8_t sy:4, 176 tcode:4; 177 u_int32_t payload[0]; 178 } stream; 179 struct { 180 u_int16_t dst; 181 u_int8_t tlrt; 182 u_int8_t pri:4, 183 tcode:4; 184 u_int16_t src; 185 } hdr; 186 struct { 187 u_int16_t dst; 188 u_int8_t tlrt; 189 u_int8_t pri:4, 190 tcode:4; 191 u_int16_t src; 192 u_int16_t dest_hi; 193 u_int32_t dest_lo; 194 } rreqq; 195 struct { 196 u_int16_t dst; 197 u_int8_t tlrt; 198 u_int8_t pri:4, 199 tcode:4; 200 u_int16_t src; 201 u_int8_t :4, 202 rtcode:4; 203 u_int8_t :8; 204 u_int32_t :32; 205 } wres; 206 struct { 207 u_int16_t dst; 208 u_int8_t tlrt; 209 u_int8_t pri:4, 210 tcode:4; 211 u_int16_t src; 212 u_int16_t dest_hi; 213 u_int32_t dest_lo; 214 u_int16_t len; 215 u_int16_t extcode:16; 216 } rreqb; 217 struct { 218 u_int16_t dst; 219 u_int8_t tlrt; 220 u_int8_t pri:4, 221 tcode:4; 222 u_int16_t src; 223 u_int16_t dest_hi; 224 u_int32_t dest_lo; 225 u_int32_t data; 226 } wreqq; 227 struct { 228 u_int16_t dst; 229 u_int8_t tlrt; 230 u_int8_t pri:4, 231 tcode:4; 232 u_int16_t src; 233 u_int16_t dest_hi; 234 u_int32_t dest_lo; 235 u_int32_t data; 236 } cyc; 237 struct { 238 u_int16_t dst; 239 u_int8_t tlrt; 240 u_int8_t pri:4, 241 tcode:4; 242 u_int16_t src; 243 u_int8_t :4, 244 rtcode:4; 245 u_int8_t :8; 246 u_int32_t :32; 247 u_int32_t data; 248 } rresq; 249 struct { 250 u_int16_t dst; 251 u_int8_t tlrt; 252 u_int8_t pri:4, 253 tcode:4; 254 u_int16_t src; 255 u_int16_t dest_hi; 256 u_int32_t dest_lo; 257 u_int16_t len; 258 u_int16_t extcode; 259 u_int32_t payload[0]; 260 } wreqb; 261 struct { 262 u_int16_t dst; 263 u_int8_t tlrt; 264 u_int8_t pri:4, 265 tcode:4; 266 u_int16_t src; 267 u_int16_t dest_hi; 268 u_int32_t dest_lo; 269 u_int16_t len; 270 u_int16_t extcode; 271 #define FW_LREQ_MSKSWAP 1 272 #define FW_LREQ_CMPSWAP 2 273 #define FW_LREQ_FTADD 3 274 #define FW_LREQ_LTADD 4 275 #define FW_LREQ_BDADD 5 276 #define FW_LREQ_WRADD 6 277 u_int32_t payload[0]; 278 } lreq; 279 struct { 280 u_int16_t dst; 281 u_int8_t tlrt; 282 u_int8_t pri:4, 283 tcode:4; 284 u_int16_t src; 285 u_int8_t :4, 286 rtcode:4; 287 u_int8_t :8; 288 u_int32_t :32; 289 u_int16_t len; 290 u_int16_t extcode; 291 u_int32_t payload[0]; 292 } rresb; 293 struct { 294 u_int16_t dst; 295 u_int8_t tlrt; 296 u_int8_t pri:4, 297 tcode:4; 298 u_int16_t src; 299 u_int8_t :4, 300 rtcode:4; 301 u_int8_t :8; 302 u_int32_t :32; 303 u_int16_t len; 304 u_int16_t extcode; 305 u_int32_t payload[0]; 306 } lres; 307 } mode; 308 }; 309 310 struct fw_eui64 { 311 u_int32_t hi, lo; 312 }; 313 #define FW_EUI64_BYTE(eui, x) \ 314 ((((x)<4)? \ 315 ((eui)->hi >> (8*(3-(x)))): \ 316 ((eui)->lo >> (8*(7-(x)))) \ 317 ) & 0xff) 318 319 struct fw_asyreq { 320 struct fw_asyreq_t{ 321 unsigned char sped; 322 unsigned int type; 323 #define FWASREQNODE 0 324 #define FWASREQEUI 1 325 #define FWASRESTL 2 326 #define FWASREQSTREAM 3 327 unsigned short len; 328 union { 329 struct fw_eui64 eui; 330 }dst; 331 }req; 332 struct fw_pkt pkt; 333 u_int32_t data[512]; 334 }; 335 336 struct fw_devinfo { 337 struct fw_eui64 eui; 338 u_int16_t dst; 339 u_int16_t status; 340 }; 341 342 #define FW_MAX_DEVLST 70 343 struct fw_devlstreq { 344 u_int16_t n; 345 u_int16_t info_len; 346 struct fw_devinfo dev[FW_MAX_DEVLST]; 347 }; 348 349 #define FW_SELF_ID_PORT_CONNECTED_TO_CHILD 3 350 #define FW_SELF_ID_PORT_CONNECTED_TO_PARENT 2 351 #define FW_SELF_ID_PORT_NOT_CONNECTED 1 352 #define FW_SELF_ID_PORT_NOT_EXISTS 0 353 #if 0 354 union fw_self_id { 355 struct { 356 u_int32_t more_packets:1, 357 initiated_reset:1, 358 port2:2, 359 port1:2, 360 port0:2, 361 power_class:3, 362 contender:1, 363 phy_delay:2, 364 phy_speed:2, 365 gap_count:6, 366 link_active:1, 367 sequel:1, 368 phy_id:6, 369 id:2; 370 } p0; 371 struct { 372 u_int32_t more_packets:1, 373 reserved1:1, 374 porth:2, 375 portg:2, 376 portf:2, 377 porte:2, 378 portd:2, 379 portc:2, 380 portb:2, 381 porta:2, 382 reserved2:2, 383 sequence_num:3, 384 sequel:1, 385 phy_id:6, 386 id:2; 387 } p1; 388 }; 389 #else 390 union fw_self_id { 391 struct { 392 u_int8_t more_packets:1, 393 initiated_reset:1, 394 port2:2, 395 port1:2, 396 port0:2; 397 u_int8_t power_class:3, 398 contender:1, 399 phy_delay:2, 400 phy_speed:2; 401 u_int8_t gap_count:6, 402 link_active:1, 403 sequel:1; 404 u_int8_t phy_id:6, 405 id:2; 406 } p0; 407 struct { 408 u_int8_t more_packets:1, 409 reserved1:1, 410 porth:2, 411 portg:2, 412 portf:2; 413 u_int8_t porte:2, 414 portd:2, 415 portc:2, 416 portb:2; 417 u_int8_t porta:2, 418 reserved2:2, 419 sequence_num:3, 420 sequel:1; 421 u_int8_t phy_id:6, 422 id:2; 423 } p1; 424 }; 425 #endif 426 427 428 struct fw_topology_map { 429 u_int32_t crc:16, 430 crc_len:16; 431 u_int32_t generation; 432 u_int32_t self_id_count:16, 433 node_count:16; 434 union fw_self_id self_id[4*64]; 435 }; 436 437 struct fw_speed_map { 438 u_int32_t crc:16, 439 crc_len:16; 440 u_int32_t generation; 441 u_int8_t speed[64][64]; 442 }; 443 444 struct fw_crom_buf { 445 struct fw_eui64 eui; 446 int len; 447 void *ptr; 448 }; 449 450 #define FWSTMAXCHUNK 16 451 /* 452 * FireWire specific system requests. 453 */ 454 #if 0 455 #define FW_SSTDV _IOWR('S', 85, unsigned int) 456 #endif 457 #define FW_SSTBUF _IOWR('S', 86, struct fw_isobufreq) 458 #define FW_GSTBUF _IOWR('S', 87, struct fw_isobufreq) 459 #define FW_SRSTREAM _IOWR('S', 88, struct fw_isochreq) 460 #define FW_GRSTREAM _IOWR('S', 89, struct fw_isochreq) 461 #define FW_STSTREAM _IOWR('S', 90, struct fw_isochreq) 462 #define FW_GTSTREAM _IOWR('S', 91, struct fw_isochreq) 463 464 #define FW_ASYREQ _IOWR('S', 92, struct fw_asyreq) 465 #define FW_IBUSRST _IOR('S', 1, unsigned int) 466 #define FW_GDEVLST _IOWR('S', 2, struct fw_devlstreq) 467 #define FW_SBINDADDR _IOWR('S', 3, struct fw_asybindreq) 468 #define FW_CBINDADDR _IOWR('S', 4, struct fw_asybindreq) 469 #define FW_GTPMAP _IOR('S', 5, struct fw_topology_map) 470 #define FW_GCROM _IOWR('S', 7, struct fw_crom_buf) 471 472 #define FWOHCI_RDREG _IOWR('S', 80, struct fw_reg_req_t) 473 #define FWOHCI_WRREG _IOWR('S', 81, struct fw_reg_req_t) 474 475 #define DUMPDMA _IOWR('S', 82, u_int32_t) 476 477 #ifdef _KERNEL 478 479 #define FWMAXNDMA 0x100 /* 8 bits DMA channel id. in device No. */ 480 481 #if __FreeBSD_version < 500000 482 #define dev2unit(x) ((minor(x) & 0xff) | (minor(x) >> 8)) 483 #define unit2minor(x) (((x) & 0xff) | (((x) << 8) & ~0xffff)) 484 #endif 485 486 #define UNIT2MIN(x) (((x) & 0xff) << 8) 487 #define DEV2UNIT(x) ((dev2unit(x) & 0xff00) >> 8) 488 #define DEV2DMACH(x) (dev2unit(x) & 0xff) 489 490 #define FWMEM_FLAG 0x10000 491 #define DEV_FWMEM(x) (dev2unit(x) & FWMEM_FLAG) 492 #endif 493 #endif 494