firewirereg.h revision 1.11 1 /* $NetBSD: firewirereg.h,v 1.11 2010/03/29 03:05:27 kiyohara Exp $ */
2 /*-
3 * Copyright (c) 2003 Hidetoshi Shimokawa
4 * Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the acknowledgement as bellow:
17 *
18 * This product includes software developed by K. Kobayashi and H. Shimokawa
19 *
20 * 4. The name of the author may not be used to endorse or promote products
21 * derived from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
27 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 *
35 * $FreeBSD: src/sys/dev/firewire/firewirereg.h,v 1.50 2007/07/20 03:42:57 simokawa Exp $
36 *
37 */
38 #ifndef _FIREWIREREG_H_
39 #define _FIREWIREREG_H_
40
41 #include <sys/uio.h>
42
43 #define PROJECT_STR "The NetBSD Project"
44
45 STAILQ_HEAD(fw_xferlist, fw_xfer);
46
47 struct fw_device {
48 uint16_t dst;
49 struct fw_eui64 eui;
50 uint8_t speed;
51 uint8_t maxrec;
52 uint8_t nport;
53 uint8_t power;
54 #define CSRROMOFF 0x400
55 #define CSRROMSIZE 0x400
56 int rommax; /* offset from 0xffff f000 0000 */
57 uint32_t csrrom[CSRROMSIZE/4];
58 int rcnt;
59 struct firewire_comm *fc;
60 uint32_t status;
61 #define FWDEVNEW 0
62 #define FWDEVINIT 1
63 #define FWDEVATTACHED 2
64 #define FWDEVINVAL 3
65 STAILQ_ENTRY(fw_device) link;
66 device_t sbp;
67 };
68
69 struct firewire_softc {
70 device_t dev;
71 SLIST_HEAD(, firewire_dev_list) devlist;
72 void *si_drv1;
73 struct firewire_comm *fc;
74 };
75
76 struct firewire_dev_list {
77 SLIST_ENTRY(firewire_dev_list) link;
78 device_t dev;
79 struct fw_device *fwdev;
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 u_char valid_res;
102 };
103
104 struct firewire_comm {
105 device_t dev;
106 device_t bdev;
107 uint16_t busid:10,
108 nodeid:6;
109 u_int mode;
110 u_int nport;
111 u_int speed;
112 u_int maxrec;
113 u_int irm;
114 u_int max_node;
115 u_int max_hop;
116 #define FWPHYASYST (1 << 0)
117 uint32_t status;
118 #define FWBUSDETACHOK (-3)
119 #define FWBUSDETACH (-2)
120 #define FWBUSNOTREADY (-1)
121 #define FWBUSRESET 0
122 #define FWBUSINIT 1
123 #define FWBUSCYMELECT 2
124 #define FWBUSMGRELECT 3
125 #define FWBUSMGRDONE 4
126 #define FWBUSEXPLORE 5
127 #define FWBUSPHYCONF 6
128 #define FWBUSEXPDONE 7
129 #define FWBUSCOMPLETION 10
130 int nisodma;
131 struct fw_eui64 eui;
132 struct fw_xferq
133 *arq, *atq, *ars, *ats, *it[FW_MAX_DMACH],*ir[FW_MAX_DMACH];
134 struct fw_xferlist tlabels[0x40];
135 u_char last_tlabel[0x40];
136 kmutex_t tlabel_lock;
137 STAILQ_HEAD(, fw_bind) binds;
138 STAILQ_HEAD(, fw_device) devices;
139 u_int sid_cnt;
140 #define CSRSIZE 0x4000
141 uint32_t csr_arc[CSRSIZE/4];
142 #define CROMSIZE 0x400
143 uint32_t *config_rom;
144 struct crom_src_buf *crom_src_buf;
145 struct crom_src *crom_src;
146 struct crom_chunk *crom_root;
147 struct fw_topology_map *topology_map;
148 struct fw_speed_map *speed_map;
149 struct callout busprobe_callout;
150 struct callout bmr_callout;
151 struct callout timeout_callout;
152 uint32_t (*cyctimer) (struct firewire_comm *);
153 void (*ibr) (struct firewire_comm *);
154 uint32_t (*set_bmr) (struct firewire_comm *, uint32_t);
155 int (*ioctl) (dev_t, u_long, void *, int, struct lwp *);
156 int (*irx_enable) (struct firewire_comm *, int);
157 int (*irx_disable) (struct firewire_comm *, int);
158 int (*itx_enable) (struct firewire_comm *, int);
159 int (*itx_disable) (struct firewire_comm *, int);
160 void (*timeout) (struct firewire_comm *);
161 void (*set_intr) (struct firewire_comm *, int);
162 void (*irx_post) (struct firewire_comm *, uint32_t *);
163 void (*itx_post) (struct firewire_comm *, uint32_t *);
164 const struct tcode_info *tcode;
165 bus_dma_tag_t dmat;
166 kmutex_t fc_mtx;
167 kmutex_t wait_lock;
168 kcondvar_t fc_cv;
169 struct lwp *probe_thread;
170 };
171 #define CSRARC(sc, offset) ((sc)->csr_arc[(offset)/4])
172
173
174 struct fw_xferq {
175 int flag;
176 #define FWXFERQ_CHTAGMASK 0xff
177 #define FWXFERQ_RUNNING (1 << 8)
178 #define FWXFERQ_STREAM (1 << 9)
179
180 #define FWXFERQ_BULK (1 << 11)
181 #define FWXFERQ_MODEMASK (7 << 10)
182
183 #define FWXFERQ_EXTBUF (1 << 13)
184 #define FWXFERQ_OPEN (1 << 14)
185
186 #define FWXFERQ_HANDLER (1 << 16)
187 #define FWXFERQ_WAKEUP (1 << 17)
188 void (*start) (struct firewire_comm*);
189 int dmach;
190 struct fw_xferlist q;
191 u_int queued;
192 u_int maxq;
193 u_int psize;
194 struct fwdma_alloc_multi *buf;
195 u_int bnchunk;
196 u_int bnpacket;
197 struct fw_bulkxfer *bulkxfer;
198 STAILQ_HEAD(, fw_bulkxfer) stvalid;
199 STAILQ_HEAD(, fw_bulkxfer) stfree;
200 STAILQ_HEAD(, fw_bulkxfer) stdma;
201 struct fw_bulkxfer *stproc;
202 struct selinfo rsel;
203 void *sc;
204 void (*hand) (struct fw_xferq *);
205 kmutex_t q_mtx;
206 };
207
208 #define FW_GMTX(fc) (&(fc)->fc_mtx)
209 #define FW_GLOCK(fc) fw_mtx_lock(FW_GMTX(fc))
210 #define FW_GUNLOCK(fc) fw_mtx_unlock(FW_GMTX(fc))
211 #define FW_GLOCK_ASSERT(fc) fw_mtx_assert(FW_GMTX(fc), MA_OWNED)
212
213 struct fw_bulkxfer {
214 int poffset;
215 struct mbuf *mbuf;
216 STAILQ_ENTRY(fw_bulkxfer) link;
217 void *start;
218 void *end;
219 int resp;
220 };
221
222 struct fw_bind {
223 u_int64_t start;
224 u_int64_t end;
225 struct fw_xferlist xferlist;
226 STAILQ_ENTRY(fw_bind) fclist;
227 STAILQ_ENTRY(fw_bind) chlist;
228 void *sc;
229 kmutex_t fwb_mtx;
230 };
231
232 struct fw_xfer {
233 void *sc;
234 struct firewire_comm *fc;
235 struct fw_xferq *q;
236 struct timeval tv;
237 int8_t resp;
238 #define FWXF_INIT 0x00
239 #define FWXF_INQ 0x01
240 #define FWXF_START 0x02
241 #define FWXF_SENT 0x04
242 #define FWXF_SENTERR 0x08
243 #define FWXF_BUSY 0x10
244 #define FWXF_RCVD 0x20
245
246 #define FWXF_WAKE 0x80
247 uint8_t flag;
248 int8_t tl;
249 void (*hand) (struct fw_xfer *);
250 struct {
251 struct fw_pkt hdr;
252 uint32_t *payload;
253 uint16_t pay_len;
254 uint8_t spd;
255 } send, recv;
256 struct mbuf *mbuf;
257 STAILQ_ENTRY(fw_xfer) link;
258 STAILQ_ENTRY(fw_xfer) tlabel;
259 struct malloc_type *malloc;
260 kcondvar_t cv;
261 };
262
263 struct fw_rcv_buf {
264 struct firewire_comm *fc;
265 struct fw_xfer *xfer;
266 struct iovec *vec;
267 u_int nvec;
268 uint8_t spd;
269 };
270
271 int fw_tbuf_update (struct firewire_comm *, int, int);
272 int fw_rbuf_update (struct firewire_comm *, int, int);
273 int fwdev_makedev (struct firewire_softc *);
274 int fwdev_destroydev (struct firewire_softc *);
275
276 struct fw_device *fw_noderesolve_nodeid(struct firewire_comm *, int);
277 struct fw_device *fw_noderesolve_eui64(struct firewire_comm *,
278 struct fw_eui64 *);
279 int fw_asyreq(struct firewire_comm *, int, struct fw_xfer*);
280 void fw_xferwake(struct fw_xfer *);
281 int fw_xferwait(struct fw_xfer *);
282 void fw_drain_txq(struct firewire_comm *);
283 void fw_busreset(struct firewire_comm *, uint32_t);
284 void fw_init(struct firewire_comm *);
285 struct fw_bind *fw_bindlookup(struct firewire_comm *, uint16_t, uint32_t);
286 int fw_bindadd(struct firewire_comm *, struct fw_bind *);
287 int fw_bindremove(struct firewire_comm *, struct fw_bind *);
288 int fw_xferlist_add(struct fw_xferlist *, struct malloc_type *, int, int, int,
289 struct firewire_comm *, void *, void (*)(struct fw_xfer *));
290 void fw_xferlist_remove(struct fw_xferlist *);
291 struct fw_xfer *fw_xfer_alloc(struct malloc_type *);
292 struct fw_xfer *fw_xfer_alloc_buf(struct malloc_type *, int, int);
293 void fw_xfer_done(struct fw_xfer *);
294 void fw_xfer_unload(struct fw_xfer*);
295 void fw_xfer_free(struct fw_xfer*);
296 void fw_xfer_free_buf(struct fw_xfer*);
297 void fw_asy_callback_free(struct fw_xfer *);
298 void fw_sidrcv(struct firewire_comm *, uint32_t *, u_int);
299 void fw_rcv(struct fw_rcv_buf *);
300 uint16_t fw_crc16(uint32_t *, uint32_t);
301 int fw_open_isodma(struct firewire_comm *, int);
302
303 extern int firewire_debug;
304 extern int firewire_phydma_enable;
305
306 #define FWPRI ((PZERO+8)|PCATCH)
307
308 /* compatibility shim for 4.X */
309 #define bio buf
310 #define bio_bcount b_bcount
311 #define bio_cmd b_flags
312 #define bio_count b_count
313 #define bio_data b_data
314 #define bio_dev b_dev
315 #define bio_error b_error
316 #define bio_flags b_flags
317 #define bio_offset b_blkno
318 #define bio_resid b_resid
319 #define BIO_READ B_READ
320 #define BIO_WRITE B_WRITE
321
322 MALLOC_DECLARE(M_FW);
323 MALLOC_DECLARE(M_FWXFER);
324
325 #endif /* _FIREWIREREG_H_ */
326