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