No empty .Rs/.Re
[netbsd-mini2440.git] / sys / dev / ieee1394 / firewirereg.h
blobc14ad4707422e580e191554b95eecad24f4b039d
1 /* $NetBSD: firewirereg.h,v 1.9 2009/06/20 09:40:52 cegger Exp $ */
2 /*-
3 * Copyright (c) 2003 Hidetoshi Shimokawa
4 * Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa
5 * All rights reserved.
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:
18 * This product includes software developed by K. Kobayashi and H. Shimokawa
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.
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.
35 * $FreeBSD: src/sys/dev/firewire/firewirereg.h,v 1.50 2007/07/20 03:42:57 simokawa Exp $
39 #include <sys/uio.h>
41 STAILQ_HEAD(fw_xferlist, fw_xfer);
43 struct fw_device{
44 uint16_t dst;
45 struct fw_eui64 eui;
46 uint8_t speed;
47 uint8_t maxrec;
48 uint8_t nport;
49 uint8_t power;
50 #define CSRROMOFF 0x400
51 #define CSRROMSIZE 0x400
52 int rommax; /* offset from 0xffff f000 0000 */
53 uint32_t csrrom[CSRROMSIZE/4];
54 int rcnt;
55 struct firewire_comm *fc;
56 uint32_t status;
57 #define FWDEVNEW 0
58 #define FWDEVINIT 1
59 #define FWDEVATTACHED 2
60 #define FWDEVINVAL 3
61 STAILQ_ENTRY(fw_device) link;
62 device_t sbp;
65 struct firewire_softc {
66 device_t dev;
67 SLIST_HEAD(, firewire_dev_list) devlist;
68 void *si_drv1;
69 int si_iosize_max;
70 struct firewire_comm *fc;
72 struct firewire_dev_list {
73 SLIST_ENTRY(firewire_dev_list) link;
74 device_t dev;
75 struct fw_device *fwdev;
78 #define FW_MAX_DMACH 0x20
79 #define FW_MAX_DEVCH FW_MAX_DMACH
80 #define FW_XFERTIMEOUT 1
82 struct firewire_dev_comm {
83 device_t dev;
84 struct firewire_comm *fc;
85 void (*post_busreset) (void *);
86 void (*post_explore) (void *);
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 u_char valid_res;
100 struct firewire_comm{
101 device_t dev;
102 device_t bdev;
103 uint16_t busid:10,
104 nodeid:6;
105 u_int mode;
106 u_int nport;
107 u_int speed;
108 u_int maxrec;
109 u_int irm;
110 u_int max_node;
111 u_int max_hop;
112 #define FWPHYASYST (1 << 0)
113 uint32_t status;
114 #define FWBUSDETACH (-2)
115 #define FWBUSNOTREADY (-1)
116 #define FWBUSRESET 0
117 #define FWBUSINIT 1
118 #define FWBUSCYMELECT 2
119 #define FWBUSMGRELECT 3
120 #define FWBUSMGRDONE 4
121 #define FWBUSEXPLORE 5
122 #define FWBUSPHYCONF 6
123 #define FWBUSEXPDONE 7
124 #define FWBUSCOMPLETION 10
125 int nisodma;
126 struct fw_eui64 eui;
127 struct fw_xferq
128 *arq, *atq, *ars, *ats, *it[FW_MAX_DMACH],*ir[FW_MAX_DMACH];
129 struct fw_xferlist tlabels[0x40];
130 u_char last_tlabel[0x40];
131 fw_mtx_t tlabel_lock;
132 STAILQ_HEAD(, fw_bind) binds;
133 STAILQ_HEAD(, fw_device) devices;
134 u_int sid_cnt;
135 #define CSRSIZE 0x4000
136 uint32_t csr_arc[CSRSIZE/4];
137 #define CROMSIZE 0x400
138 uint32_t *config_rom;
139 struct crom_src_buf *crom_src_buf;
140 struct crom_src *crom_src;
141 struct crom_chunk *crom_root;
142 struct fw_topology_map *topology_map;
143 struct fw_speed_map *speed_map;
144 struct callout busprobe_callout;
145 struct callout bmr_callout;
146 struct callout timeout_callout;
147 fw_task_t task_timeout;
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) (fw_dev_t, u_long, void *, int, fw_proc_t);
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 const struct tcode_info *tcode;
162 bus_dma_tag_t dmat;
163 fw_mtx_t mtx;
164 fw_mtx_t wait_lock;
165 struct taskqueue *taskqueue;
166 fw_proc_t probe_thread;
168 #define CSRARC(sc, offset) ((sc)->csr_arc[(offset)/4])
170 #define FW_GMTX(fc) (&(fc)->mtx)
171 #define FW_GLOCK(fc) fw_mtx_lock(FW_GMTX(fc))
172 #define FW_GUNLOCK(fc) fw_mtx_unlock(FW_GMTX(fc))
173 #define FW_GLOCK_ASSERT(fc) fw_mtx_assert(FW_GMTX(fc), MA_OWNED)
175 struct fw_xferq {
176 int flag;
177 #define FWXFERQ_CHTAGMASK 0xff
178 #define FWXFERQ_RUNNING (1 << 8)
179 #define FWXFERQ_STREAM (1 << 9)
181 #define FWXFERQ_BULK (1 << 11)
182 #define FWXFERQ_MODEMASK (7 << 10)
184 #define FWXFERQ_EXTBUF (1 << 13)
185 #define FWXFERQ_OPEN (1 << 14)
187 #define FWXFERQ_HANDLER (1 << 16)
188 #define FWXFERQ_WAKEUP (1 << 17)
189 void (*start) (struct firewire_comm*);
190 int dmach;
191 struct fw_xferlist q;
192 u_int queued;
193 u_int maxq;
194 u_int psize;
195 struct fwdma_alloc_multi *buf;
196 u_int bnchunk;
197 u_int bnpacket;
198 struct fw_bulkxfer *bulkxfer;
199 STAILQ_HEAD(, fw_bulkxfer) stvalid;
200 STAILQ_HEAD(, fw_bulkxfer) stfree;
201 STAILQ_HEAD(, fw_bulkxfer) stdma;
202 struct fw_bulkxfer *stproc;
203 struct selinfo rsel;
204 void *sc;
205 void (*hand) (struct fw_xferq *);
208 struct fw_bulkxfer{
209 int poffset;
210 struct mbuf *mbuf;
211 STAILQ_ENTRY(fw_bulkxfer) link;
212 void *start;
213 void *end;
214 int resp;
217 struct fw_bind{
218 u_int64_t start;
219 u_int64_t end;
220 struct fw_xferlist xferlist;
221 STAILQ_ENTRY(fw_bind) fclist;
222 STAILQ_ENTRY(fw_bind) chlist;
223 void *sc;
226 struct fw_xfer{
227 void *sc;
228 struct firewire_comm *fc;
229 struct fw_xferq *q;
230 struct timeval tv;
231 int8_t resp;
232 #define FWXF_INIT 0x00
233 #define FWXF_INQ 0x01
234 #define FWXF_START 0x02
235 #define FWXF_SENT 0x04
236 #define FWXF_SENTERR 0x08
237 #define FWXF_BUSY 0x10
238 #define FWXF_RCVD 0x20
240 #define FWXF_WAKE 0x80
241 uint8_t flag;
242 int8_t tl;
243 void (*hand) (struct fw_xfer *);
244 struct {
245 struct fw_pkt hdr;
246 uint32_t *payload;
247 uint16_t pay_len;
248 uint8_t spd;
249 } send, recv;
250 struct mbuf *mbuf;
251 STAILQ_ENTRY(fw_xfer) link;
252 STAILQ_ENTRY(fw_xfer) tlabel;
253 struct malloc_type *malloc;
256 struct fw_rcv_buf {
257 struct firewire_comm *fc;
258 struct fw_xfer *xfer;
259 struct iovec *vec;
260 u_int nvec;
261 uint8_t spd;
264 void fw_sidrcv (struct firewire_comm *, uint32_t *, u_int);
265 void fw_rcv (struct fw_rcv_buf *);
266 void fw_xfer_unload ( struct fw_xfer*);
267 void fw_xfer_free_buf ( struct fw_xfer*);
268 void fw_xfer_free ( struct fw_xfer*);
269 struct fw_xfer *fw_xfer_alloc (struct malloc_type *);
270 struct fw_xfer *fw_xfer_alloc_buf (struct malloc_type *, int, int);
271 void fw_init (struct firewire_comm *);
272 int fw_tbuf_update (struct firewire_comm *, int, int);
273 int fw_rbuf_update (struct firewire_comm *, int, int);
274 int fw_bindadd (struct firewire_comm *, struct fw_bind *);
275 int fw_bindremove (struct firewire_comm *, struct fw_bind *);
276 int fw_xferlist_add (struct fw_xferlist *, struct malloc_type *, int, int, int,
277 struct firewire_comm *, void *, void (*)(struct fw_xfer *));
278 void fw_xferlist_remove (struct fw_xferlist *);
279 int fw_asyreq (struct firewire_comm *, int, struct fw_xfer*);
280 void fw_busreset (struct firewire_comm *, uint32_t);
281 uint16_t fw_crc16 (uint32_t *, uint32_t);
282 void fw_xfer_timeout (void *);
283 void fw_xfer_done (struct fw_xfer *);
284 void fw_xferwake (struct fw_xfer *);
285 int fw_xferwait (struct fw_xfer *);
286 void fw_asy_callback_free (struct fw_xfer *);
287 struct fw_device *fw_noderesolve_nodeid (struct firewire_comm *, int);
288 struct fw_device *fw_noderesolve_eui64 (struct firewire_comm *, struct fw_eui64 *);
289 struct fw_bind *fw_bindlookup (struct firewire_comm *, uint16_t, uint32_t);
290 void fw_drain_txq (struct firewire_comm *);
291 int fwdev_makedev (struct firewire_softc *);
292 int fwdev_destroydev (struct firewire_softc *);
293 int fw_open_isodma(struct firewire_comm *, int);
295 extern int firewire_debug;
296 extern struct cfdriver ieee1394if_cd;
297 extern int firewire_phydma_enable;
299 #define FWPRI ((PZERO+8)|PCATCH)
301 /* compatibility shim for 4.X */
302 #define bio buf
303 #define bio_bcount b_bcount
304 #define bio_cmd b_flags
305 #define bio_count b_count
306 #define bio_data b_data
307 #define bio_dev b_dev
308 #define bio_error b_error
309 #define bio_flags b_flags
310 #define bio_offset b_blkno
311 #define bio_resid b_resid
312 #define BIO_READ B_READ
313 #define BIO_WRITE B_WRITE
315 MALLOC_DECLARE(M_FW);
316 MALLOC_DECLARE(M_FWXFER);