firewire.h revision 110193
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: head/sys/dev/firewire/firewire.h 110193 2003-02-01 14:42:49Z simokawa $ 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 44struct 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 59struct dv_data_req_t { 60 unsigned long index; 61 unsigned long len; 62 unsigned long off; 63}; 64#endif 65 66struct fw_isochreq { 67 unsigned char ch:6, 68 tag:2; 69}; 70 71struct fw_isobufreq { 72 struct { 73 unsigned int nchunk; 74 unsigned int npacket; 75 unsigned int psize; 76 } tx, rx; 77}; 78 79struct fw_addr { 80 unsigned long hi; 81 unsigned long lo; 82}; 83 84struct fw_asybindreq { 85 struct fw_addr start; 86 unsigned long len; 87}; 88 89struct 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 130struct fw_isohdr { 131 u_int32_t hdr[1]; 132}; 133 134struct 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 163struct 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 310struct 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#define FW_EUI64_EQUAL(x, y) \ 319 ((x).hi == (y).hi && (x).lo == (y).lo) 320 321struct fw_asyreq { 322 struct fw_asyreq_t{ 323 unsigned char sped; 324 unsigned int type; 325#define FWASREQNODE 0 326#define FWASREQEUI 1 327#define FWASRESTL 2 328#define FWASREQSTREAM 3 329 unsigned short len; 330 union { 331 struct fw_eui64 eui; 332 }dst; 333 }req; 334 struct fw_pkt pkt; 335 u_int32_t data[512]; 336}; 337 338struct fw_devinfo { 339 struct fw_eui64 eui; 340 u_int16_t dst; 341 u_int16_t status; 342}; 343 344#define FW_MAX_DEVLST 70 345struct fw_devlstreq { 346 u_int16_t n; 347 u_int16_t info_len; 348 struct fw_devinfo dev[FW_MAX_DEVLST]; 349}; 350 351#define FW_SELF_ID_PORT_CONNECTED_TO_CHILD 3 352#define FW_SELF_ID_PORT_CONNECTED_TO_PARENT 2 353#define FW_SELF_ID_PORT_NOT_CONNECTED 1 354#define FW_SELF_ID_PORT_NOT_EXISTS 0 355#if 0 356union fw_self_id { 357 struct { 358 u_int32_t more_packets:1, 359 initiated_reset:1, 360 port2:2, 361 port1:2, 362 port0:2, 363 power_class:3, 364 contender:1, 365 phy_delay:2, 366 phy_speed:2, 367 gap_count:6, 368 link_active:1, 369 sequel:1, 370 phy_id:6, 371 id:2; 372 } p0; 373 struct { 374 u_int32_t more_packets:1, 375 reserved1:1, 376 porth:2, 377 portg:2, 378 portf:2, 379 porte:2, 380 portd:2, 381 portc:2, 382 portb:2, 383 porta:2, 384 reserved2:2, 385 sequence_num:3, 386 sequel:1, 387 phy_id:6, 388 id:2; 389 } p1; 390}; 391#else 392union fw_self_id { 393 struct { 394 u_int8_t more_packets:1, 395 initiated_reset:1, 396 port2:2, 397 port1:2, 398 port0:2; 399 u_int8_t power_class:3, 400 contender:1, 401 phy_delay:2, 402 phy_speed:2; 403 u_int8_t gap_count:6, 404 link_active:1, 405 sequel:1; 406 u_int8_t phy_id:6, 407 id:2; 408 } p0; 409 struct { 410 u_int8_t more_packets:1, 411 reserved1:1, 412 porth:2, 413 portg:2, 414 portf:2; 415 u_int8_t porte:2, 416 portd:2, 417 portc:2, 418 portb:2; 419 u_int8_t porta:2, 420 reserved2:2, 421 sequence_num:3, 422 sequel:1; 423 u_int8_t phy_id:6, 424 id:2; 425 } p1; 426}; 427#endif 428 429 430struct fw_topology_map { 431 u_int32_t crc:16, 432 crc_len:16; 433 u_int32_t generation; 434 u_int32_t self_id_count:16, 435 node_count:16; 436 union fw_self_id self_id[4*64]; 437}; 438 439struct fw_speed_map { 440 u_int32_t crc:16, 441 crc_len:16; 442 u_int32_t generation; 443 u_int8_t speed[64][64]; 444}; 445 446struct fw_crom_buf { 447 struct fw_eui64 eui; 448 int len; 449 void *ptr; 450}; 451 452#define FWSTMAXCHUNK 16 453/* 454 * FireWire specific system requests. 455 */ 456#if 0 457#define FW_SSTDV _IOWR('S', 85, unsigned int) 458#endif 459#define FW_SSTBUF _IOWR('S', 86, struct fw_isobufreq) 460#define FW_GSTBUF _IOWR('S', 87, struct fw_isobufreq) 461#define FW_SRSTREAM _IOWR('S', 88, struct fw_isochreq) 462#define FW_GRSTREAM _IOWR('S', 89, struct fw_isochreq) 463#define FW_STSTREAM _IOWR('S', 90, struct fw_isochreq) 464#define FW_GTSTREAM _IOWR('S', 91, struct fw_isochreq) 465 466#define FW_ASYREQ _IOWR('S', 92, struct fw_asyreq) 467#define FW_IBUSRST _IOR('S', 1, unsigned int) 468#define FW_GDEVLST _IOWR('S', 2, struct fw_devlstreq) 469#define FW_SBINDADDR _IOWR('S', 3, struct fw_asybindreq) 470#define FW_CBINDADDR _IOWR('S', 4, struct fw_asybindreq) 471#define FW_GTPMAP _IOR('S', 5, struct fw_topology_map) 472#define FW_GCROM _IOWR('S', 7, struct fw_crom_buf) 473 474#define FWOHCI_RDREG _IOWR('S', 80, struct fw_reg_req_t) 475#define FWOHCI_WRREG _IOWR('S', 81, struct fw_reg_req_t) 476 477#define DUMPDMA _IOWR('S', 82, u_int32_t) 478 479#ifdef _KERNEL 480 481#define FWMAXNDMA 0x100 /* 8 bits DMA channel id. in device No. */ 482 483#if __FreeBSD_version < 500000 484#define dev2unit(x) ((minor(x) & 0xff) | (minor(x) >> 8)) 485#define unit2minor(x) (((x) & 0xff) | (((x) << 8) & ~0xffff)) 486#endif 487 488#define UNIT2MIN(x) (((x) & 0xff) << 8) 489#define DEV2UNIT(x) ((dev2unit(x) & 0xff00) >> 8) 490#define DEV2DMACH(x) (dev2unit(x) & 0xff) 491 492#define FWMEM_FLAG 0x10000 493#define DEV_FWMEM(x) (dev2unit(x) & FWMEM_FLAG) 494#endif 495#endif 496