This commit represents a major revamping of the clock interrupt and timebase
[dragonfly.git] / sys / bus / firewire / firewire.h
1 /*
2  * Copyright (c) 2003 Hidetoshi Shimokawa
3  * Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. All advertising materials mentioning features or use of this software
15  *    must display the acknowledgement as bellow:
16  *
17  *    This product includes software developed by K. Kobayashi and H. Shimokawa
18  *
19  * 4. The name of the author may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
26  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  * 
34  * $FreeBSD: src/sys/dev/firewire/firewire.h,v 1.2.2.8 2003/04/28 03:29:18 simokawa Exp $
35  * $DragonFly: src/sys/bus/firewire/firewire.h,v 1.2 2003/06/17 04:28:25 dillon Exp $
36  *
37  */
38
39 #ifndef _FIREWIRE_H
40 #define _FIREWIRE_H 1
41
42 #define DEV_DEF  0
43 #define DEV_DV   2
44
45 struct fw_isochreq {
46         unsigned char   ch:6,
47                         tag:2;
48 };
49
50 struct fw_isobufreq {
51         struct {
52                 unsigned int nchunk;
53                 unsigned int npacket;
54                 unsigned int psize;
55         } tx, rx;
56 };
57
58 struct fw_addr {
59         unsigned long hi;
60         unsigned long lo;
61 };
62
63 struct fw_asybindreq {
64         struct fw_addr start;
65         unsigned long len;
66 };
67
68 struct fw_reg_req_t {
69         unsigned long addr;
70         unsigned long data;
71 };
72
73 #define MAXREC(x)       (2 << (x))
74 #define FWPMAX_S400 (2048 + 20) /* MAXREC plus space for control data */
75 #define FWMAXQUEUE 64
76
77 #define FWLOCALBUS      0xffc0
78
79 #define FWTCODE_WREQQ   0
80 #define FWTCODE_WREQB   1
81 #define FWTCODE_WRES    2
82 #define FWTCODE_RREQQ   4
83 #define FWTCODE_RREQB   5
84 #define FWTCODE_RRESQ   6
85 #define FWTCODE_RRESB   7
86 #define FWTCODE_CYCS    8
87 #define FWTCODE_LREQ    9
88 #define FWTCODE_STREAM  0xa
89 #define FWTCODE_LRES    0xb
90 #define FWTCODE_PHY     0xe
91
92 #define FWRETRY_1       0
93 #define FWRETRY_X       1
94 #define FWRETRY_A       2
95 #define FWRETRY_B       3
96
97 #define FWRCODE_COMPLETE        0
98 #define FWRCODE_ER_CONFL        4
99 #define FWRCODE_ER_DATA         5
100 #define FWRCODE_ER_TYPE         6
101 #define FWRCODE_ER_ADDR         7
102
103 #define FWSPD_S100      0
104 #define FWSPD_S200      1
105 #define FWSPD_S400      2
106
107 #define FWP_TL_VALID (1 << 7)
108
109 struct fw_isohdr {
110         u_int32_t hdr[1];
111 };
112
113 struct fw_asyhdr {
114         u_int32_t hdr[4];
115 };
116
117 #if BYTE_ORDER == BIG_ENDIAN
118 #define BIT4x2(x,y)      u_int8_t  x:4, y:4
119 #define BIT16x2(x,y)    u_int32_t x:16, y:16
120 #else
121 #define BIT4x2(x,y)      u_int8_t  y:4, x:4
122 #define BIT16x2(x,y)    u_int32_t y:16, x:16
123 #endif
124
125
126 #if BYTE_ORDER == BIG_ENDIAN
127 #define COMMON_HDR(a,b,c,d)     u_int32_t a:16,b:8,c:4,d:4
128 #define COMMON_RES(a,b,c,d)     u_int32_t a:16,b:4,c:4,d:8
129 #else
130 #define COMMON_HDR(a,b,c,d)     u_int32_t d:4,c:4,b:8,a:16
131 #define COMMON_RES(a,b,c,d)     u_int32_t d:8,c:4,b:4,a:16
132 #endif
133
134 struct fw_pkt {
135         union {
136                 u_int32_t ld[0];
137                 struct {
138                         COMMON_HDR(, , tcode, );
139                 } common;
140                 struct {
141                         COMMON_HDR(len, chtag, tcode, sy);
142                         u_int32_t payload[0];
143                 } stream;
144                 struct {
145                         COMMON_HDR(dst, tlrt, tcode, pri);
146                         BIT16x2(src, );
147                 } hdr;
148                 struct {
149                         COMMON_HDR(dst, tlrt, tcode, pri);
150                         BIT16x2(src, dest_hi);
151                         u_int32_t dest_lo;
152                 } rreqq;
153                 struct {
154                         COMMON_HDR(dst, tlrt, tcode, pri);
155                         COMMON_RES(src, rtcode, , );
156                         u_int32_t :32;
157                 } wres;
158                 struct {
159                         COMMON_HDR(dst, tlrt, tcode, pri);
160                         BIT16x2(src, dest_hi);
161                         u_int32_t dest_lo;
162                         BIT16x2(len, extcode);
163                 } rreqb;
164                 struct {
165                         COMMON_HDR(dst, tlrt, tcode, pri);
166                         BIT16x2(src, dest_hi);
167                         u_int32_t dest_lo;
168                         u_int32_t data;
169                 } wreqq;
170                 struct {
171                         COMMON_HDR(dst, tlrt, tcode, pri);
172                         BIT16x2(src, dest_hi);
173                         u_int32_t dest_lo;
174                         u_int32_t data;
175                 } cyc;
176                 struct {
177                         COMMON_HDR(dst, tlrt, tcode, pri);
178                         COMMON_RES(src, rtcode, , );
179                         u_int32_t :32;
180                         u_int32_t data;
181                 } rresq;
182                 struct {
183                         COMMON_HDR(dst, tlrt, tcode, pri);
184                         BIT16x2(src, dest_hi);
185                         u_int32_t dest_lo;
186                         BIT16x2(len, extcode);
187                         u_int32_t payload[0];
188                 } wreqb;
189                 struct {
190                         COMMON_HDR(dst, tlrt, tcode, pri);
191                         BIT16x2(src, dest_hi);
192                         u_int32_t dest_lo;
193                         BIT16x2(len, extcode);
194 #define FW_LREQ_MSKSWAP 1
195 #define FW_LREQ_CMPSWAP 2
196 #define FW_LREQ_FTADD   3
197 #define FW_LREQ_LTADD   4
198 #define FW_LREQ_BDADD   5
199 #define FW_LREQ_WRADD   6
200                         u_int32_t payload[0];
201                 } lreq;
202                 struct {
203                         COMMON_HDR(dst, tlrt, tcode, pri);
204                         COMMON_RES(src, rtcode, , );
205                         u_int32_t :32;
206                         BIT16x2(len, extcode);
207                         u_int32_t payload[0];
208                 } rresb;
209                 struct {
210                         COMMON_HDR(dst, tlrt, tcode, pri);
211                         COMMON_RES(src, rtcode, , );
212                         u_int32_t :32;
213                         BIT16x2(len, extcode);
214                         u_int32_t payload[0];
215                 } lres;
216         } mode;
217 };
218
219 struct fw_eui64 {
220         u_int32_t hi, lo;
221 };
222 #define FW_EUI64_BYTE(eui, x) \
223         ((((x)<4)?                              \
224                 ((eui)->hi >> (8*(3-(x)))):     \
225                 ((eui)->lo >> (8*(7-(x))))      \
226         ) & 0xff)
227 #define FW_EUI64_EQUAL(x, y) \
228         ((x).hi == (y).hi && (x).lo == (y).lo)
229
230 struct fw_asyreq {
231         struct fw_asyreq_t{
232                 unsigned char sped;
233                 unsigned int type;
234 #define FWASREQNODE     0
235 #define FWASREQEUI      1
236 #define FWASRESTL       2
237 #define FWASREQSTREAM   3
238                 unsigned short len;
239                 union {
240                         struct fw_eui64 eui;
241                 }dst;
242         }req;
243         struct fw_pkt pkt;
244         u_int32_t data[512];
245 };
246
247 struct fw_devinfo {
248         struct fw_eui64 eui;
249         u_int16_t dst;
250         u_int16_t status;
251 };
252
253 #define FW_MAX_DEVLST 70
254 struct fw_devlstreq {
255         u_int16_t n;
256         u_int16_t info_len;
257         struct fw_devinfo dev[FW_MAX_DEVLST];
258 };
259
260 #define FW_SELF_ID_PORT_CONNECTED_TO_CHILD 3
261 #define FW_SELF_ID_PORT_CONNECTED_TO_PARENT 2
262 #define FW_SELF_ID_PORT_NOT_CONNECTED 1
263 #define FW_SELF_ID_PORT_NOT_EXISTS 0
264 #if BYTE_ORDER == BIG_ENDIAN
265 union fw_self_id {
266         struct {
267                 u_int32_t id:2,
268                           phy_id:6,
269                           sequel:1,
270                           link_active:1,
271                           gap_count:6,
272                           phy_speed:2,
273                           phy_delay:2,
274                           contender:1,
275                           power_class:3,
276                           port0:2,
277                           port1:2,
278                           port2:2,
279                           initiated_reset:1,
280                           more_packets:1;
281         } p0;
282         struct {
283                 u_int32_t
284                           id:2,
285                           phy_id:6,
286                           sequel:1,
287                           sequence_num:3,
288                           :2,
289                           porta:2,
290                           portb:2,
291                           portc:2,
292                           portd:2,
293                           porte:2,
294                           portf:2,
295                           portg:2,
296                           porth:2,
297                           :1,
298                           more_packets:1;
299         } p1;
300 };
301 #else
302 union fw_self_id {
303         struct {
304                 u_int32_t more_packets:1,
305                           initiated_reset:1,
306                           port2:2,
307                           port1:2,
308                           port0:2,
309                           power_class:3,
310                           contender:1,
311                           phy_delay:2,
312                           phy_speed:2,
313                           gap_count:6,
314                           link_active:1,
315                           sequel:1,
316                           phy_id:6,
317                           id:2;
318         } p0;
319         struct {
320                 u_int32_t more_packets:1,
321                           reserved1:1,
322                           porth:2,
323                           portg:2,
324                           portf:2,
325                           porte:2,
326                           portd:2,
327                           portc:2,
328                           portb:2,
329                           porta:2,
330                           reserved2:2,
331                           sequence_num:3,
332                           sequel:1,
333                           phy_id:6,
334                           id:2;
335         } p1;
336 };
337 #endif
338
339
340 struct fw_topology_map {
341         u_int32_t crc:16,
342                   crc_len:16;
343         u_int32_t generation;
344         u_int32_t self_id_count:16,
345                   node_count:16;
346         union fw_self_id self_id[4*64];
347 };
348
349 struct fw_speed_map {
350         u_int32_t crc:16,
351                   crc_len:16;
352         u_int32_t generation;
353         u_int8_t  speed[64][64];
354 };
355
356 struct fw_crom_buf {
357         struct fw_eui64 eui;
358         int len;
359         void *ptr;
360 };
361
362 /*
363  * FireWire specific system requests.
364  */
365 #define FW_SSTBUF       _IOWR('S', 86, struct fw_isobufreq)
366 #define FW_GSTBUF       _IOWR('S', 87, struct fw_isobufreq)
367 #define FW_SRSTREAM     _IOWR('S', 88, struct fw_isochreq)
368 #define FW_GRSTREAM     _IOWR('S', 89, struct fw_isochreq)
369 #define FW_STSTREAM     _IOWR('S', 90, struct fw_isochreq)
370 #define FW_GTSTREAM     _IOWR('S', 91, struct fw_isochreq)
371
372 #define FW_ASYREQ       _IOWR('S', 92, struct fw_asyreq)
373 #define FW_IBUSRST      _IOR('S', 1, unsigned int)
374 #define FW_GDEVLST      _IOWR('S', 2, struct fw_devlstreq)
375 #define FW_SBINDADDR    _IOWR('S', 3, struct fw_asybindreq)
376 #define FW_CBINDADDR    _IOWR('S', 4, struct fw_asybindreq)
377 #define FW_GTPMAP       _IOR('S', 5, struct fw_topology_map)
378 #define FW_GCROM        _IOWR('S', 7, struct fw_crom_buf)
379
380 #define FW_SDEUI64      _IOW('S', 20, struct fw_eui64)
381 #define FW_GDEUI64      _IOR('S', 21, struct fw_eui64)
382
383 #define FWOHCI_RDREG    _IOWR('S', 80, struct fw_reg_req_t)
384 #define FWOHCI_WRREG    _IOWR('S', 81, struct fw_reg_req_t)
385
386 #define DUMPDMA         _IOWR('S', 82, u_int32_t)
387
388 #ifdef _KERNEL
389
390 #define FWMAXNDMA 0x100 /* 8 bits DMA channel id. in device No. */
391
392 #if __FreeBSD_version < 500000
393 #define dev2unit(x)     ((minor(x) & 0xff) | (minor(x) >> 8))
394 #define unit2minor(x)   (((x) & 0xff) | (((x) << 8) & ~0xffff))
395 #endif
396
397 #define UNIT2MIN(x)     (((x) & 0xff) << 8)
398 #define DEV2UNIT(x)     ((dev2unit(x) & 0xff00) >> 8)
399 #define DEV2DMACH(x)    (dev2unit(x) & 0xff)
400
401 #define FWMEM_FLAG      0x10000
402 #define DEV_FWMEM(x)    (dev2unit(x) & FWMEM_FLAG)
403 #endif
404 #endif