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