2 * Copyright (c) 2003 Hidetoshi Shimokawa
3 * Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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:
17 * This product includes software developed by K. Kobayashi and H. Shimokawa
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.
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.
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>
45 typedef struct proc fw_proc;
46 #include <sys/select.h>
60 #define CSRROMOFF 0x400
61 #define CSRROMSIZE 0x400
62 int rommax; /* offset from 0xffff f000 0000 */
63 uint32_t csrrom[CSRROMSIZE/4];
65 struct firewire_comm *fc;
68 #define FWDEVATTACHED 2
70 STAILQ_ENTRY(fw_device) link;
73 struct firewire_softc {
74 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
77 struct firewire_comm *fc;
80 #define FW_MAX_DMACH 0x20
81 #define FW_MAX_DEVCH FW_MAX_DMACH
82 #define FW_XFERTIMEOUT 1
84 struct firewire_dev_comm {
86 struct firewire_comm *fc;
87 void (*post_busreset) (void *);
88 void (*post_explore) (void *);
92 u_char hdr_len; /* IEEE1394 header length */
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)
101 struct firewire_comm{
114 #define FWPHYASYST (1 << 0)
119 struct fw_device *ongodev;
120 struct fw_eui64 ongoeui;
121 #define FWMAXCSRDIR 16
122 SLIST_HEAD(, csrdir) ongocsr;
123 SLIST_HEAD(, csrdir) csrfree;
125 #define FWBUSNOTREADY (-1)
128 #define FWBUSCYMELECT 2
129 #define FWBUSMGRELECT 3
130 #define FWBUSMGRDONE 4
131 #define FWBUSEXPLORE 5
132 #define FWBUSPHYCONF 6
133 #define FWBUSEXPDONE 7
134 #define FWBUSCOMPLETION 10
138 *arq, *atq, *ars, *ats, *it[FW_MAX_DMACH],*ir[FW_MAX_DMACH];
139 STAILQ_HEAD(, tlabel) tlabels[0x40];
140 STAILQ_HEAD(, fw_bind) binds;
141 STAILQ_HEAD(, fw_device) devices;
143 #define CSRSIZE 0x4000
144 uint32_t csr_arc[CSRSIZE/4];
145 #define CROMSIZE 0x400
146 uint32_t *config_rom;
147 struct crom_src_buf *crom_src_buf;
148 struct crom_src *crom_src;
149 struct crom_chunk *crom_root;
150 struct fw_topology_map *topology_map;
151 struct fw_speed_map *speed_map;
152 struct callout busprobe_callout;
153 struct callout bmr_callout;
154 struct callout timeout_callout;
155 struct callout retry_probe_callout;
156 uint32_t (*cyctimer) (struct firewire_comm *);
157 void (*ibr) (struct firewire_comm *);
158 uint32_t (*set_bmr) (struct firewire_comm *, uint32_t);
159 int (*ioctl) (struct cdev *, u_long, caddr_t, int, fw_proc *);
160 int (*irx_enable) (struct firewire_comm *, int);
161 int (*irx_disable) (struct firewire_comm *, int);
162 int (*itx_enable) (struct firewire_comm *, int);
163 int (*itx_disable) (struct firewire_comm *, int);
164 void (*timeout) (void *);
165 void (*poll) (struct firewire_comm *, int, int);
166 void (*set_intr) (struct firewire_comm *, int);
167 void (*irx_post) (struct firewire_comm *, uint32_t *);
168 void (*itx_post) (struct firewire_comm *, uint32_t *);
169 struct tcode_info *tcode;
172 #define CSRARC(sc, offset) ((sc)->csr_arc[(offset)/4])
177 SLIST_ENTRY(csrdir) link;
182 #define FWXFERQ_CHTAGMASK 0xff
183 #define FWXFERQ_RUNNING (1 << 8)
184 #define FWXFERQ_STREAM (1 << 9)
186 #define FWXFERQ_BULK (1 << 11)
187 #define FWXFERQ_MODEMASK (7 << 10)
189 #define FWXFERQ_EXTBUF (1 << 13)
190 #define FWXFERQ_OPEN (1 << 14)
192 #define FWXFERQ_HANDLER (1 << 16)
193 #define FWXFERQ_WAKEUP (1 << 17)
194 void (*start) (struct firewire_comm*);
196 STAILQ_HEAD(, fw_xfer) q;
200 STAILQ_HEAD(, fw_bind) binds;
201 struct fwdma_alloc_multi *buf;
204 struct fw_bulkxfer *bulkxfer;
205 STAILQ_HEAD(, fw_bulkxfer) stvalid;
206 STAILQ_HEAD(, fw_bulkxfer) stfree;
207 STAILQ_HEAD(, fw_bulkxfer) stdma;
208 struct fw_bulkxfer *stproc;
211 void (*hand) (struct fw_xferq *);
217 STAILQ_ENTRY(fw_bulkxfer) link;
224 struct fw_xfer *xfer;
225 STAILQ_ENTRY(tlabel) link;
231 STAILQ_HEAD(, fw_xfer) xferlist;
232 STAILQ_ENTRY(fw_bind) fclist;
233 STAILQ_ENTRY(fw_bind) chlist;
243 struct firewire_comm *fc;
251 #define FWXF_SENTERR 4
257 void (*retry_req) (struct fw_xfer *);
259 void (*hand) (struct fw_xfer *);
268 STAILQ_ENTRY(fw_xfer) link;
269 struct malloc_type *malloc;
273 struct firewire_comm *fc;
274 struct fw_xfer *xfer;
280 void fw_sidrcv (struct firewire_comm *, uint32_t *, u_int);
281 void fw_rcv (struct fw_rcv_buf *);
282 void fw_xfer_unload ( struct fw_xfer*);
283 void fw_xfer_free_buf ( struct fw_xfer*);
284 void fw_xfer_free ( struct fw_xfer*);
285 struct fw_xfer *fw_xfer_alloc (struct malloc_type *);
286 struct fw_xfer *fw_xfer_alloc_buf (struct malloc_type *, int, int);
287 void fw_init (struct firewire_comm *);
288 int fw_tbuf_update (struct firewire_comm *, int, int);
289 int fw_rbuf_update (struct firewire_comm *, int, int);
290 void fw_asybusy (struct fw_xfer *);
291 int fw_bindadd (struct firewire_comm *, struct fw_bind *);
292 int fw_bindremove (struct firewire_comm *, struct fw_bind *);
293 int fw_asyreq (struct firewire_comm *, int, struct fw_xfer*);
294 void fw_busreset (struct firewire_comm *);
295 uint16_t fw_crc16 (uint32_t *, uint32_t);
296 void fw_xfer_timeout (void *);
297 void fw_xfer_done (struct fw_xfer *);
298 void fw_asy_callback (struct fw_xfer *);
299 void fw_asy_callback_free (struct fw_xfer *);
300 struct fw_device *fw_noderesolve_nodeid (struct firewire_comm *, int);
301 struct fw_device *fw_noderesolve_eui64 (struct firewire_comm *, struct fw_eui64 *);
302 struct fw_bind *fw_bindlookup (struct firewire_comm *, uint16_t, uint32_t);
303 void fw_drain_txq (struct firewire_comm *);
304 int fwdev_makedev (struct firewire_softc *);
305 int fwdev_destroydev (struct firewire_softc *);
306 void fwdev_clone (void *, char *, int, struct cdev **);
308 extern int firewire_debug;
309 extern devclass_t firewire_devclass;
314 #define FWPRI ((PZERO+8)|PCATCH)
317 #if defined(__DragonFly__) || __FreeBSD_version < 500000
318 #define CALLOUT_INIT(x) callout_init(x)
320 #define CALLOUT_INIT(x) callout_init(x, 0 /* mpsafe */)
323 #if defined(__DragonFly__) || __FreeBSD_version < 500000
324 /* compatibility shim for 4.X */
326 #define bio_bcount b_bcount
327 #define bio_cmd b_flags
328 #define bio_count b_count
329 #define bio_data b_data
330 #define bio_dev b_dev
331 #define bio_error b_error
332 #define bio_flags b_flags
333 #define bio_offset b_offset
334 #define bio_resid b_resid
335 #define BIO_ERROR B_ERROR
336 #define BIO_READ B_READ
337 #define BIO_WRITE B_WRITE
338 #define MIN(a,b) (((a)<(b))?(a):(b))
339 #define MAX(a,b) (((a)>(b))?(a):(b))
342 MALLOC_DECLARE(M_FW);
343 MALLOC_DECLARE(M_FWXFER);