]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/firewire/firewirereg.h
This commit was generated by cvs2svn to compensate for changes in r107609,
[FreeBSD/FreeBSD.git] / sys / dev / firewire / firewirereg.h
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 #if __FreeBSD_version >= 500000
38 typedef struct thread fw_proc;
39 #include <sys/selinfo.h>
40 #else
41 typedef struct proc fw_proc;
42 #include <sys/select.h>
43 #endif
44
45 #define splfw splimp
46
47 struct fw_device{
48         u_int16_t dst;
49         struct fw_eui64 eui;
50         u_int32_t spec;
51         u_int32_t ver;
52         u_int8_t speed;
53         u_int8_t maxrec;
54         u_int8_t nport;
55         u_int8_t power;
56 #define CSRROMOFF 0x400
57 #define CSRROMSIZE 0x400
58         int rommax;     /* offset from 0xffff f000 0000 */
59         u_int32_t csrrom[CSRROMSIZE/4];
60         int rcnt;
61         struct firewire_comm *fc;
62         u_int32_t status;
63 #define FWDEVINIT       1
64 #define FWDEVATTACHED   2
65 #define FWDEVINVAL      3
66         TAILQ_ENTRY(fw_device) link;
67 #if 0
68         LIST_HEAD(, fw_xfer) txqueue;
69         LIST_HEAD(, fw_xfer) rxqueue;
70 #endif
71 };
72 struct firewire_softc {
73 #if __FreeBSD_version >= 500000
74         dev_t dev;
75 #else
76         dev_t dev[FWMAXNDMA+1];
77 #endif
78         struct firewire_comm *fc;
79 };
80 #define FW_MAX_DMACH 0x20
81 #define FW_MAX_DEVCH FW_MAX_DMACH
82 #define FW_XFERTIMEOUT 1
83 struct firewire_dev_comm {
84         device_t dev;
85         struct firewire_comm *fc;
86         void (*post_explore) __P((void *));
87 };
88
89 struct tcode_info {
90         u_char hdr_len; /* IEEE1394 header length */
91         u_char flag;
92 #define FWTI_REQ        (1 << 0)
93 #define FWTI_RES        (1 << 1)
94 #define FWTI_TLABEL     (1 << 2)
95 #define FWTI_BLOCK_STR  (1 << 3)
96 #define FWTI_BLOCK_ASY  (1 << 4)
97 };
98
99 struct firewire_comm{
100         device_t dev;
101         device_t bdev;
102         u_int16_t busid:10,
103                   nodeid:6;
104         u_int mode;
105         u_int nport;
106         u_int speed;
107         u_int maxrec;
108         u_int irm;
109         u_int max_node;
110         u_int max_hop;
111         u_int max_asyretry;
112 #define FWPHYASYST (1 << 0)
113         u_int retry_count;
114         u_int32_t ongobus:10,
115                   ongonode:6,
116                   ongoaddr:16;
117         struct fw_device *ongodev;
118         struct fw_eui64 ongoeui;
119 #define FWMAXCSRDIR     16
120         SLIST_HEAD(, csrdir) ongocsr;
121         SLIST_HEAD(, csrdir) csrfree;
122         struct csrdir{
123                 u_int32_t ongoaddr;
124                 u_int32_t off;
125                 SLIST_ENTRY(csrdir) link;
126         };
127         u_int32_t status;
128 #define FWBUSRESET      0
129 #define FWBUSINIT       1
130 #define FWBUSCYMELECT   2
131 #define FWBUSMGRELECT   3
132 #define FWBUSMGRDONE    4
133 #define FWBUSEXPLORE    5
134 #define FWBUSPHYCONF    6
135 #define FWBUSEXPDONE    7
136 #define FWBUSCOMPLETION 10
137         int nisodma;
138         u_int8_t eui[8];
139         STAILQ_HEAD(fw_queue, fw_xfer);
140         struct fw_xferq {
141                 int flag;
142 #define FWXFERQ_CHTAGMASK 0xff
143 #define FWXFERQ_RUNNING (1 << 8)
144 #define FWXFERQ_STREAM (1 << 9)
145
146 #define FWXFERQ_PACKET (1 << 10)
147 #define FWXFERQ_BULK (1 << 11)
148 #define FWXFERQ_DV (1 << 12)
149 #define FWXFERQ_MODEMASK (7 << 10)
150
151 #define FWXFERQ_EXTBUF (1 << 13)
152 #define FWXFERQ_OPEN (1 << 14)
153
154 #define FWXFERQ_HANDLER (1 << 16)
155 #define FWXFERQ_WAKEUP (1 << 17)
156
157                 void (*start) __P((struct firewire_comm*));
158                 void (*drain) __P((struct firewire_comm*, struct fw_xfer*));
159                 struct fw_queue q;
160                 u_int queued;
161                 u_int maxq;
162                 u_int psize;
163                 u_int packets;
164                 u_int error;
165                 STAILQ_HEAD(, fw_bind) binds;
166                 caddr_t buf;
167                 u_int bnchunk;
168                 u_int bnpacket;
169                 u_int btpacket;
170                 struct fw_bulkxfer *bulkxfer;
171                 STAILQ_HEAD(, fw_bulkxfer) stvalid;
172                 STAILQ_HEAD(, fw_bulkxfer) stfree;
173                 struct fw_bulkxfer *stdma;
174                 struct fw_bulkxfer *stdma2;
175                 struct fw_bulkxfer *stproc;
176                 u_int procptr;
177                 int dvdbc, dvdiff, dvsync;
178                 struct fw_dvbuf *dvbuf;
179                 STAILQ_HEAD(, fw_dvbuf) dvvalid;
180                 STAILQ_HEAD(, fw_dvbuf) dvfree;
181                 struct fw_dvbuf *dvdma;
182                 struct fw_dvbuf *dvproc;
183                 u_int dvptr;
184                 u_int dvpacket;
185                 u_int need_wakeup;
186                 struct selinfo rsel;
187                 caddr_t sc;
188                 void (*hand) __P((struct fw_xferq *));
189         };
190         struct fw_xferq
191                 *arq, *atq, *ars, *ats, *it[FW_MAX_DMACH],*ir[FW_MAX_DMACH];
192         struct fw_bulkxfer{
193                 u_int32_t flag;
194                 caddr_t buf;
195                 STAILQ_ENTRY(fw_bulkxfer) link;
196                 caddr_t start;
197                 caddr_t end;
198                 u_int npacket;
199         };
200         struct fw_dvbuf{
201                 caddr_t buf;
202                 STAILQ_ENTRY(fw_dvbuf) link;
203         };
204         struct tlabel{
205                 struct fw_xfer  *xfer;
206                 STAILQ_ENTRY(tlabel) link;
207         };
208         STAILQ_HEAD(, tlabel) tlabels[0x40];
209         struct fw_bind{
210                 u_int32_t start_hi, start_lo, addrlen;
211                 struct fw_xfer* xfer;
212                 STAILQ_ENTRY(fw_bind) fclist;
213                 STAILQ_ENTRY(fw_bind) chlist;
214         };
215         STAILQ_HEAD(, fw_bind) binds;
216         TAILQ_HEAD(, fw_device) devices;
217         STAILQ_HEAD(, fw_xfer)  pending;
218         volatile u_int32_t *sid_buf;
219         u_int  sid_cnt;
220 #define CSRSIZE 0x4000
221         u_int32_t csr_arc[CSRSIZE/4];
222 #define CROMSIZE 0x400
223         u_int32_t *config_rom;
224         struct fw_topology_map *topology_map;
225         struct fw_speed_map *speed_map;
226         struct callout_handle tlhandle;
227         struct callout_handle bmrhandle;
228         struct callout_handle timeouthandle;
229         struct callout_handle retry_probe_handle;
230         u_int32_t (*cyctimer) __P((struct  firewire_comm *));
231         void (*ibr) __P((struct firewire_comm *));
232         u_int32_t (*set_bmr) __P((struct firewire_comm *, u_int32_t));
233         int (*ioctl) __P((dev_t, u_long, caddr_t, int, fw_proc *));
234         int (*irx_enable) __P((struct firewire_comm *, int));
235         int (*irx_disable) __P((struct firewire_comm *, int));
236         int (*itx_enable) __P((struct firewire_comm *, int));
237         int (*itx_disable) __P((struct firewire_comm *, int));
238         void (*timeout) __P((void *));
239         void (*poll) __P((struct firewire_comm *, int, int));
240         void (*set_intr) __P((struct firewire_comm *, int));
241         void (*irx_post) __P((struct firewire_comm *, u_int32_t *));
242         void (*itx_post) __P((struct firewire_comm *, u_int32_t *));
243         struct tcode_info *tcode;
244 };
245 #define CSRARC(sc, offset) ((sc)->csr_arc[(offset)/4])
246
247
248 struct fw_xfer{
249         caddr_t sc;
250         struct firewire_comm *fc;
251         struct fw_xferq *q;
252         struct callout_handle ch;
253         time_t time;
254         struct fw_tlabel *tlabel;
255         u_int8_t spd;
256         u_int8_t tcode;
257         int resp;
258 #define FWXF_INIT 0
259 #define FWXF_INQ 1
260 #define FWXF_START 2
261 #define FWXF_SENT 3
262 #define FWXF_SENTERR 4
263 #define FWXF_BUSY 8
264 #define FWXF_RCVD 10
265         int state;
266         u_int8_t retry;
267         u_int8_t tl;
268         int sub;
269         int32_t dst;
270         u_int8_t act_type;
271 #define FWACT_NULL      0
272 #define FWACT_XFER      2
273 #define FWACT_CH        3
274         void (*retry_req) __P((struct fw_xfer *));
275         union{
276                 void (*hand) __P((struct fw_xfer *));
277
278         } act;
279         union{
280                 struct {
281                         struct fw_device *device;
282                 } req;
283                 struct {
284                         struct stch *channel;
285                 } stream;
286         } mode;
287         struct {
288                 u_int16_t len, off;
289                 caddr_t buf;
290         } send, recv;
291         struct mbuf *mbuf;
292         STAILQ_ENTRY(fw_xfer) link;
293 };
294 void fw_sidrcv __P((struct firewire_comm *, caddr_t, u_int, u_int));
295 void fw_rcv __P((struct firewire_comm *, caddr_t, u_int, u_int, u_int, u_int));
296 void fw_xfer_free __P(( struct fw_xfer*));
297 struct fw_xfer *fw_xfer_alloc __P((void));
298 void fw_init __P((struct firewire_comm *));
299 int fw_tbuf_update __P((struct firewire_comm *, int, int));
300 int fw_rbuf_update __P((struct firewire_comm *, int, int));
301 int fw_readreqq __P((struct firewire_comm *, u_int32_t, u_int32_t, u_int32_t *));
302 int fw_writereqb __P((struct firewire_comm *, u_int32_t, u_int32_t, u_int32_t, u_int32_t *));
303 int fw_readresb __P((struct firewire_comm *, u_int32_t, u_int32_t, u_int32_t, u_int32_t*));
304 int fw_writeres __P((struct firewire_comm *, u_int32_t, u_int32_t));
305 u_int32_t getcsrdata __P((struct fw_device *, u_int8_t));
306 void fw_asybusy __P((struct fw_xfer *));
307 int fw_bindadd __P((struct firewire_comm *, struct fw_bind *));
308 int fw_bindremove __P((struct firewire_comm *, struct fw_bind *));
309 int fw_asyreq __P((struct firewire_comm *, int, struct fw_xfer*));
310 void fw_busreset __P((struct firewire_comm *));
311 u_int16_t fw_crc16 __P((u_int32_t *, u_int32_t));
312 void fw_xfer_timeout __P((void *));
313 void fw_xfer_done __P((struct fw_xfer *));
314 void fw_asy_callback __P((struct fw_xfer *));
315 struct fw_device *fw_noderesolve __P((struct firewire_comm *, struct fw_eui64));
316 struct fw_bind *fw_bindlookup __P((struct firewire_comm *, u_int32_t, u_int32_t));
317
318
319 extern int firewire_debug;
320 extern devclass_t firewire_devclass;
321
322 #define DV_BROADCAST_ON (1<<30)
323 #define         IP_CHANNELS     0x0234
324
325 #define         STATE_CLEAR     0x0000
326 #define         STATE_SET       0x0004
327 #define         NODE_IDS        0x0008
328 #define         RESET_START     0x000c
329 #define         SPLIT_TIMEOUT_HI        0x0018
330 #define         SPLIT_TIMEOUT_LO        0x001c
331 #define         CYCLE_TIME      0x0200
332 #define         BUS_TIME        0x0210
333 #define         BUS_MGR_ID      0x021c
334 #define         BANDWIDTH_AV    0x0220
335 #define         CHANNELS_AV_HI  0x0224
336 #define         CHANNELS_AV_LO  0x0228
337
338 #define         CONF_ROM        0x0400
339
340 #define         TOPO_MAP        0x1000
341 #define         SPED_MAP        0x2000
342
343 #define         oMPR            0x900
344 #define         oPCR            0x904
345
346 #define         iMPR            0x980
347 #define         iPCR            0x984
348
349 #define         FWPRI           ((PZERO+8)|PCATCH)
350
351 #ifdef __alpha__
352 #undef vtophys
353 #define vtophys(va)     alpha_XXX_dmamap((vm_offset_t)(va))
354 #endif /* __alpha__ */