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