1 /* $NetBSD: firewirereg.h,v 1.9 2009/06/20 09:40:52 cegger Exp $ */
3 * Copyright (c) 2003 Hidetoshi Shimokawa
4 * Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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 $
41 STAILQ_HEAD(fw_xferlist
, fw_xfer
);
50 #define CSRROMOFF 0x400
51 #define CSRROMSIZE 0x400
52 int rommax
; /* offset from 0xffff f000 0000 */
53 uint32_t csrrom
[CSRROMSIZE
/4];
55 struct firewire_comm
*fc
;
59 #define FWDEVATTACHED 2
61 STAILQ_ENTRY(fw_device
) link
;
65 struct firewire_softc
{
67 SLIST_HEAD(, firewire_dev_list
) devlist
;
70 struct firewire_comm
*fc
;
72 struct firewire_dev_list
{
73 SLIST_ENTRY(firewire_dev_list
) link
;
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
{
84 struct firewire_comm
*fc
;
85 void (*post_busreset
) (void *);
86 void (*post_explore
) (void *);
90 u_char hdr_len
; /* IEEE1394 header length */
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)
100 struct firewire_comm
{
112 #define FWPHYASYST (1 << 0)
114 #define FWBUSDETACH (-2)
115 #define FWBUSNOTREADY (-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
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
;
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
;
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)
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
*);
191 struct fw_xferlist q
;
195 struct fwdma_alloc_multi
*buf
;
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
;
205 void (*hand
) (struct fw_xferq
*);
211 STAILQ_ENTRY(fw_bulkxfer
) link
;
220 struct fw_xferlist xferlist
;
221 STAILQ_ENTRY(fw_bind
) fclist
;
222 STAILQ_ENTRY(fw_bind
) chlist
;
228 struct firewire_comm
*fc
;
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
243 void (*hand
) (struct fw_xfer
*);
251 STAILQ_ENTRY(fw_xfer
) link
;
252 STAILQ_ENTRY(fw_xfer
) tlabel
;
253 struct malloc_type
*malloc
;
257 struct firewire_comm
*fc
;
258 struct fw_xfer
*xfer
;
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 */
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
);