]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/firewire/firewirereg.h
This commit was generated by cvs2svn to compensate for changes in r167802,
[FreeBSD/FreeBSD.git] / sys / dev / firewire / firewirereg.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$
35  *
36  */
37
38 #ifdef __DragonFly__
39 typedef d_thread_t fw_proc;
40 #include <sys/select.h>
41 #elif __FreeBSD_version >= 500000
42 typedef struct thread fw_proc;
43 #include <sys/selinfo.h>
44 #else
45 typedef struct proc fw_proc;
46 #include <sys/select.h>
47 #endif
48
49 #include <sys/uio.h>
50
51 #define splfw splimp
52
53 struct fw_device{
54         uint16_t dst;
55         struct fw_eui64 eui;
56         uint8_t speed;
57         uint8_t maxrec;
58         uint8_t nport;
59         uint8_t power;
60 #define CSRROMOFF 0x400
61 #define CSRROMSIZE 0x400
62         int rommax;     /* offset from 0xffff f000 0000 */
63         uint32_t csrrom[CSRROMSIZE/4];
64         int rcnt;
65         struct firewire_comm *fc;
66         uint32_t status;
67 #define FWDEVINIT       1
68 #define FWDEVATTACHED   2
69 #define FWDEVINVAL      3
70         STAILQ_ENTRY(fw_device) link;
71 };
72
73 struct firewire_softc {
74 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
75         struct cdev *dev;
76 #endif
77         struct firewire_comm *fc;
78 };
79
80 #define FW_MAX_DMACH 0x20
81 #define FW_MAX_DEVCH FW_MAX_DMACH
82 #define FW_XFERTIMEOUT 1
83
84 struct firewire_dev_comm {
85         device_t dev;
86         struct firewire_comm *fc;
87         void (*post_busreset) (void *);
88         void (*post_explore) (void *);
89 };
90
91 struct tcode_info {
92         u_char hdr_len; /* IEEE1394 header length */
93         u_char flag;
94 #define FWTI_REQ        (1 << 0)
95 #define FWTI_RES        (1 << 1)
96 #define FWTI_TLABEL     (1 << 2)
97 #define FWTI_BLOCK_STR  (1 << 3)
98 #define FWTI_BLOCK_ASY  (1 << 4)
99 };
100
101 struct firewire_comm{
102         device_t dev;
103         device_t bdev;
104         uint16_t busid:10,
105                   nodeid:6;
106         u_int mode;
107         u_int nport;
108         u_int speed;
109         u_int maxrec;
110         u_int irm;
111         u_int max_node;
112         u_int max_hop;
113 #define FWPHYASYST (1 << 0)
114         uint32_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         uint32_t status;
123 #define FWBUSNOTREADY   (-1)
124 #define FWBUSRESET      0
125 #define FWBUSINIT       1
126 #define FWBUSCYMELECT   2
127 #define FWBUSMGRELECT   3
128 #define FWBUSMGRDONE    4
129 #define FWBUSEXPLORE    5
130 #define FWBUSPHYCONF    6
131 #define FWBUSEXPDONE    7
132 #define FWBUSCOMPLETION 10
133         int nisodma;
134         struct fw_eui64 eui;
135         struct fw_xferq
136                 *arq, *atq, *ars, *ats, *it[FW_MAX_DMACH],*ir[FW_MAX_DMACH];
137         STAILQ_HEAD(, tlabel) tlabels[0x40];
138         STAILQ_HEAD(, fw_bind) binds;
139         STAILQ_HEAD(, fw_device) devices;
140         u_int  sid_cnt;
141 #define CSRSIZE 0x4000
142         uint32_t csr_arc[CSRSIZE/4];
143 #define CROMSIZE 0x400
144         uint32_t *config_rom;
145         struct crom_src_buf *crom_src_buf;
146         struct crom_src *crom_src;
147         struct crom_chunk *crom_root;
148         struct fw_topology_map *topology_map;
149         struct fw_speed_map *speed_map;
150         struct callout busprobe_callout;
151         struct callout bmr_callout;
152         struct callout timeout_callout;
153         uint32_t (*cyctimer) (struct  firewire_comm *);
154         void (*ibr) (struct firewire_comm *);
155         uint32_t (*set_bmr) (struct firewire_comm *, uint32_t);
156         int (*ioctl) (struct cdev *, u_long, caddr_t, int, fw_proc *);
157         int (*irx_enable) (struct firewire_comm *, int);
158         int (*irx_disable) (struct firewire_comm *, int);
159         int (*itx_enable) (struct firewire_comm *, int);
160         int (*itx_disable) (struct firewire_comm *, int);
161         void (*timeout) (void *);
162         void (*poll) (struct firewire_comm *, int, int);
163         void (*set_intr) (struct firewire_comm *, int);
164         void (*irx_post) (struct firewire_comm *, uint32_t *);
165         void (*itx_post) (struct firewire_comm *, uint32_t *);
166         struct tcode_info *tcode;
167         bus_dma_tag_t dmat;
168 };
169 #define CSRARC(sc, offset) ((sc)->csr_arc[(offset)/4])
170
171 struct csrdir{
172         uint32_t ongoaddr;
173         uint32_t off;
174         SLIST_ENTRY(csrdir) link;
175 };
176
177 struct fw_xferq {
178         int flag;
179 #define FWXFERQ_CHTAGMASK 0xff
180 #define FWXFERQ_RUNNING (1 << 8)
181 #define FWXFERQ_STREAM (1 << 9)
182
183 #define FWXFERQ_BULK (1 << 11)
184 #define FWXFERQ_MODEMASK (7 << 10)
185
186 #define FWXFERQ_EXTBUF (1 << 13)
187 #define FWXFERQ_OPEN (1 << 14)
188
189 #define FWXFERQ_HANDLER (1 << 16)
190 #define FWXFERQ_WAKEUP (1 << 17)
191         void (*start) (struct firewire_comm*);
192         int dmach;
193         STAILQ_HEAD(, fw_xfer) q;
194         u_int queued;
195         u_int maxq;
196         u_int psize;
197         STAILQ_HEAD(, fw_bind) binds;
198         struct fwdma_alloc_multi *buf;
199         u_int bnchunk;
200         u_int bnpacket;
201         struct fw_bulkxfer *bulkxfer;
202         STAILQ_HEAD(, fw_bulkxfer) stvalid;
203         STAILQ_HEAD(, fw_bulkxfer) stfree;
204         STAILQ_HEAD(, fw_bulkxfer) stdma;
205         struct fw_bulkxfer *stproc;
206         struct selinfo rsel;
207         caddr_t sc;
208         void (*hand) (struct fw_xferq *);
209 };
210
211 struct fw_bulkxfer{
212         int poffset;
213         struct mbuf *mbuf;
214         STAILQ_ENTRY(fw_bulkxfer) link;
215         caddr_t start;
216         caddr_t end;
217         int resp;
218 };
219
220 struct tlabel{
221         struct fw_xfer  *xfer;
222         STAILQ_ENTRY(tlabel) link;
223 };
224
225 struct fw_bind{
226         u_int64_t start;
227         u_int64_t end;
228         STAILQ_HEAD(, fw_xfer) xferlist;
229         STAILQ_ENTRY(fw_bind) fclist;
230         STAILQ_ENTRY(fw_bind) chlist;
231 #define FWACT_NULL      0
232 #define FWACT_XFER      2
233 #define FWACT_CH        3
234         uint8_t act_type;
235         uint8_t sub;
236 };
237
238 struct fw_xfer{
239         caddr_t sc;
240         struct firewire_comm *fc;
241         struct fw_xferq *q;
242         struct timeval tv;
243         int8_t resp;
244 #define FWXF_INIT 0
245 #define FWXF_INQ 1
246 #define FWXF_START 2
247 #define FWXF_SENT 3
248 #define FWXF_SENTERR 4
249 #define FWXF_BUSY 8
250 #define FWXF_RCVD 10
251         uint8_t state;
252         uint8_t tl;
253         void (*hand) (struct fw_xfer *);
254         struct {
255                 struct fw_pkt hdr;
256                 uint32_t *payload;
257                 uint16_t pay_len;
258                 uint8_t spd;
259         } send, recv;
260         struct mbuf *mbuf;
261         STAILQ_ENTRY(fw_xfer) link;
262         struct malloc_type *malloc;
263 };
264
265 struct fw_rcv_buf {
266         struct firewire_comm *fc;
267         struct fw_xfer *xfer;
268         struct iovec *vec;
269         u_int nvec;
270         uint8_t spd;
271 };
272
273 void fw_sidrcv (struct firewire_comm *, uint32_t *, u_int);
274 void fw_rcv (struct fw_rcv_buf *);
275 void fw_xfer_unload ( struct fw_xfer*);
276 void fw_xfer_free_buf ( struct fw_xfer*);
277 void fw_xfer_free ( struct fw_xfer*);
278 struct fw_xfer *fw_xfer_alloc (struct malloc_type *);
279 struct fw_xfer *fw_xfer_alloc_buf (struct malloc_type *, int, int);
280 void fw_init (struct firewire_comm *);
281 int fw_tbuf_update (struct firewire_comm *, int, int);
282 int fw_rbuf_update (struct firewire_comm *, int, int);
283 void fw_asybusy (struct fw_xfer *);
284 int fw_bindadd (struct firewire_comm *, struct fw_bind *);
285 int fw_bindremove (struct firewire_comm *, struct fw_bind *);
286 int fw_asyreq (struct firewire_comm *, int, struct fw_xfer*);
287 void fw_busreset (struct firewire_comm *);
288 uint16_t fw_crc16 (uint32_t *, uint32_t);
289 void fw_xfer_timeout (void *);
290 void fw_xfer_done (struct fw_xfer *);
291 void fw_asy_callback (struct fw_xfer *);
292 void fw_asy_callback_free (struct fw_xfer *);
293 struct fw_device *fw_noderesolve_nodeid (struct firewire_comm *, int);
294 struct fw_device *fw_noderesolve_eui64 (struct firewire_comm *, struct fw_eui64 *);
295 struct fw_bind *fw_bindlookup (struct firewire_comm *, uint16_t, uint32_t);
296 void fw_drain_txq (struct firewire_comm *);
297 int fwdev_makedev (struct firewire_softc *);
298 int fwdev_destroydev (struct firewire_softc *);
299 void fwdev_clone (void *, struct ucred *, char *, int, struct cdev **);
300
301 extern int firewire_debug;
302 extern devclass_t firewire_devclass;
303
304 #ifdef __DragonFly__
305 #define         FWPRI           PCATCH
306 #else
307 #define         FWPRI           ((PZERO+8)|PCATCH)
308 #endif
309
310 #if defined(__DragonFly__) || __FreeBSD_version < 500000
311 #define CALLOUT_INIT(x) callout_init(x)
312 #else
313 #define CALLOUT_INIT(x) callout_init(x, 0 /* mpsafe */)
314 #endif
315
316 #if defined(__DragonFly__) || __FreeBSD_version < 500000
317 /* compatibility shim for 4.X */
318 #define bio buf
319 #define bio_bcount b_bcount
320 #define bio_cmd b_flags
321 #define bio_count b_count
322 #define bio_data b_data
323 #define bio_dev b_dev
324 #define bio_error b_error
325 #define bio_flags b_flags
326 #define bio_offset b_offset
327 #define bio_resid b_resid
328 #define BIO_ERROR B_ERROR
329 #define BIO_READ B_READ
330 #define BIO_WRITE B_WRITE
331 #define MIN(a,b) (((a)<(b))?(a):(b))
332 #define MAX(a,b) (((a)>(b))?(a):(b))
333 #endif
334
335 MALLOC_DECLARE(M_FW);
336 MALLOC_DECLARE(M_FWXFER);