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