DEVFS - remove dev_ops_add(), dev_ops_get(), and get_dev()
[dragonfly.git] / sys / bus / firewire / firewirereg.h
CommitLineData
984263bc
MD
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 *
78748771 34 * $FreeBSD: src/sys/dev/firewire/firewirereg.h,v 1.33 2004/01/06 14:30:46 simokawa Exp $
b13267a5 35 * $DragonFly: src/sys/bus/firewire/firewirereg.h,v 1.12 2006/09/10 01:26:32 dillon Exp $
984263bc
MD
36 *
37 */
38
78748771 39#ifdef __DragonFly__
fef8985e 40typedef struct thread fw_proc;
78748771 41#elif __FreeBSD_version >= 500000
984263bc 42typedef struct thread fw_proc;
984263bc 43#else
78748771 44typedef struct proc fw_proc;
984263bc
MD
45#endif
46
9183fa5b 47#include <sys/selinfo.h>
984263bc
MD
48#include <sys/uio.h>
49
fef8985e
MD
50struct dev_ioctl_args;
51
984263bc
MD
52struct fw_device{
53 u_int16_t dst;
54 struct fw_eui64 eui;
55 u_int8_t speed;
56 u_int8_t maxrec;
57 u_int8_t nport;
58 u_int8_t power;
59#define CSRROMOFF 0x400
60#define CSRROMSIZE 0x400
61 int rommax; /* offset from 0xffff f000 0000 */
62 u_int32_t csrrom[CSRROMSIZE/4];
63 int rcnt;
64 struct firewire_comm *fc;
65 u_int32_t status;
66#define FWDEVINIT 1
67#define FWDEVATTACHED 2
68#define FWDEVINVAL 3
69 STAILQ_ENTRY(fw_device) link;
70};
71
72struct firewire_softc {
90dec0df 73#if defined(__FreeBSD__) && __FreeBSD_version >= 500000
b13267a5 74 cdev_t dev;
984263bc
MD
75#endif
76 struct firewire_comm *fc;
77};
78
79#define FW_MAX_DMACH 0x20
80#define FW_MAX_DEVCH FW_MAX_DMACH
81#define FW_XFERTIMEOUT 1
82
83struct firewire_dev_comm {
84 device_t dev;
85 struct firewire_comm *fc;
330ca0ab
RG
86 void (*post_busreset) (void *);
87 void (*post_explore) (void *);
984263bc
MD
88};
89
90struct tcode_info {
91 u_char hdr_len; /* IEEE1394 header length */
92 u_char flag;
93#define FWTI_REQ (1 << 0)
94#define FWTI_RES (1 << 1)
95#define FWTI_TLABEL (1 << 2)
96#define FWTI_BLOCK_STR (1 << 3)
97#define FWTI_BLOCK_ASY (1 << 4)
98};
99
100struct firewire_comm{
101 device_t dev;
102 device_t bdev;
103 u_int16_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 u_int max_asyretry;
113#define FWPHYASYST (1 << 0)
114 u_int retry_count;
115 u_int32_t ongobus:10,
116 ongonode:6,
117 ongoaddr:16;
118 struct fw_device *ongodev;
119 struct fw_eui64 ongoeui;
120#define FWMAXCSRDIR 16
121 SLIST_HEAD(, csrdir) ongocsr;
122 SLIST_HEAD(, csrdir) csrfree;
123 u_int32_t status;
78748771 124#define FWBUSNOTREADY (-1)
984263bc
MD
125#define FWBUSRESET 0
126#define FWBUSINIT 1
127#define FWBUSCYMELECT 2
128#define FWBUSMGRELECT 3
129#define FWBUSMGRDONE 4
130#define FWBUSEXPLORE 5
131#define FWBUSPHYCONF 6
132#define FWBUSEXPDONE 7
133#define FWBUSCOMPLETION 10
134 int nisodma;
135 struct fw_eui64 eui;
136 struct fw_xferq
137 *arq, *atq, *ars, *ats, *it[FW_MAX_DMACH],*ir[FW_MAX_DMACH];
138 STAILQ_HEAD(, tlabel) tlabels[0x40];
139 STAILQ_HEAD(, fw_bind) binds;
140 STAILQ_HEAD(, fw_device) devices;
984263bc
MD
141 u_int sid_cnt;
142#define CSRSIZE 0x4000
143 u_int32_t csr_arc[CSRSIZE/4];
144#define CROMSIZE 0x400
145 u_int32_t *config_rom;
78748771
JS
146 struct crom_src_buf *crom_src_buf;
147 struct crom_src *crom_src;
148 struct crom_chunk *crom_root;
984263bc
MD
149 struct fw_topology_map *topology_map;
150 struct fw_speed_map *speed_map;
151 struct callout busprobe_callout;
152 struct callout bmr_callout;
153 struct callout timeout_callout;
154 struct callout retry_probe_callout;
330ca0ab
RG
155 u_int32_t (*cyctimer) (struct firewire_comm *);
156 void (*ibr) (struct firewire_comm *);
157 u_int32_t (*set_bmr) (struct firewire_comm *, u_int32_t);
fef8985e 158 int (*ioctl) (struct dev_ioctl_args *);
330ca0ab
RG
159 int (*irx_enable) (struct firewire_comm *, int);
160 int (*irx_disable) (struct firewire_comm *, int);
161 int (*itx_enable) (struct firewire_comm *, int);
162 int (*itx_disable) (struct firewire_comm *, int);
163 void (*timeout) (void *);
164 void (*poll) (struct firewire_comm *, int, int);
165 void (*set_intr) (struct firewire_comm *, int);
166 void (*irx_post) (struct firewire_comm *, u_int32_t *);
167 void (*itx_post) (struct firewire_comm *, u_int32_t *);
984263bc
MD
168 struct tcode_info *tcode;
169 bus_dma_tag_t dmat;
170};
171#define CSRARC(sc, offset) ((sc)->csr_arc[(offset)/4])
172
173struct csrdir{
174 u_int32_t ongoaddr;
175 u_int32_t off;
176 SLIST_ENTRY(csrdir) link;
177};
178
179struct fw_xferq {
180 int flag;
181#define FWXFERQ_CHTAGMASK 0xff
182#define FWXFERQ_RUNNING (1 << 8)
183#define FWXFERQ_STREAM (1 << 9)
184
185#define FWXFERQ_BULK (1 << 11)
186#define FWXFERQ_MODEMASK (7 << 10)
187
188#define FWXFERQ_EXTBUF (1 << 13)
189#define FWXFERQ_OPEN (1 << 14)
190
191#define FWXFERQ_HANDLER (1 << 16)
192#define FWXFERQ_WAKEUP (1 << 17)
330ca0ab 193 void (*start) (struct firewire_comm*);
78748771 194 int dmach;
984263bc
MD
195 STAILQ_HEAD(, fw_xfer) q;
196 u_int queued;
197 u_int maxq;
198 u_int psize;
199 STAILQ_HEAD(, fw_bind) binds;
200 struct fwdma_alloc_multi *buf;
201 u_int bnchunk;
202 u_int bnpacket;
203 struct fw_bulkxfer *bulkxfer;
204 STAILQ_HEAD(, fw_bulkxfer) stvalid;
205 STAILQ_HEAD(, fw_bulkxfer) stfree;
206 STAILQ_HEAD(, fw_bulkxfer) stdma;
207 struct fw_bulkxfer *stproc;
208 struct selinfo rsel;
209 caddr_t sc;
330ca0ab 210 void (*hand) (struct fw_xferq *);
984263bc
MD
211};
212
213struct fw_bulkxfer{
214 int poffset;
215 struct mbuf *mbuf;
216 STAILQ_ENTRY(fw_bulkxfer) link;
217 caddr_t start;
218 caddr_t end;
219 int resp;
220};
221
222struct tlabel{
223 struct fw_xfer *xfer;
224 STAILQ_ENTRY(tlabel) link;
225};
226
227struct fw_bind{
78748771
JS
228 u_int64_t start;
229 u_int64_t end;
984263bc
MD
230 STAILQ_HEAD(, fw_xfer) xferlist;
231 STAILQ_ENTRY(fw_bind) fclist;
232 STAILQ_ENTRY(fw_bind) chlist;
233#define FWACT_NULL 0
234#define FWACT_XFER 2
235#define FWACT_CH 3
236 u_int8_t act_type;
237 u_int8_t sub;
238};
239
240struct fw_xfer{
241 caddr_t sc;
242 struct firewire_comm *fc;
243 struct fw_xferq *q;
244 struct timeval tv;
984263bc
MD
245 int8_t resp;
246#define FWXF_INIT 0
247#define FWXF_INQ 1
248#define FWXF_START 2
249#define FWXF_SENT 3
250#define FWXF_SENTERR 4
251#define FWXF_BUSY 8
252#define FWXF_RCVD 10
253 u_int8_t state;
254 u_int8_t retry;
255 u_int8_t tl;
330ca0ab 256 void (*retry_req) (struct fw_xfer *);
984263bc 257 union{
330ca0ab 258 void (*hand) (struct fw_xfer *);
984263bc
MD
259 } act;
260 struct {
78748771
JS
261 struct fw_pkt hdr;
262 u_int32_t *payload;
263 u_int16_t pay_len;
264 u_int8_t spd;
984263bc
MD
265 } send, recv;
266 struct mbuf *mbuf;
267 STAILQ_ENTRY(fw_xfer) link;
268 struct malloc_type *malloc;
269};
78748771
JS
270
271struct fw_rcv_buf {
272 struct firewire_comm *fc;
273 struct fw_xfer *xfer;
274 struct iovec *vec;
275 u_int nvec;
276 u_int8_t spd;
277};
278
330ca0ab 279void fw_sidrcv (struct firewire_comm *, u_int32_t *, u_int);
78748771 280void fw_rcv (struct fw_rcv_buf *);
330ca0ab 281void fw_xfer_unload ( struct fw_xfer*);
78748771 282void fw_xfer_free_buf ( struct fw_xfer*);
330ca0ab
RG
283void fw_xfer_free ( struct fw_xfer*);
284struct fw_xfer *fw_xfer_alloc (struct malloc_type *);
285struct fw_xfer *fw_xfer_alloc_buf (struct malloc_type *, int, int);
286void fw_init (struct firewire_comm *);
287int fw_tbuf_update (struct firewire_comm *, int, int);
288int fw_rbuf_update (struct firewire_comm *, int, int);
289void fw_asybusy (struct fw_xfer *);
290int fw_bindadd (struct firewire_comm *, struct fw_bind *);
291int fw_bindremove (struct firewire_comm *, struct fw_bind *);
292int fw_asyreq (struct firewire_comm *, int, struct fw_xfer*);
293void fw_busreset (struct firewire_comm *);
294u_int16_t fw_crc16 (u_int32_t *, u_int32_t);
295void fw_xfer_timeout (void *);
296void fw_xfer_done (struct fw_xfer *);
297void fw_asy_callback (struct fw_xfer *);
78748771 298void fw_asy_callback_free (struct fw_xfer *);
330ca0ab
RG
299struct fw_device *fw_noderesolve_nodeid (struct firewire_comm *, int);
300struct fw_device *fw_noderesolve_eui64 (struct firewire_comm *, struct fw_eui64 *);
78748771 301struct fw_bind *fw_bindlookup (struct firewire_comm *, u_int16_t, u_int32_t);
330ca0ab 302void fw_drain_txq (struct firewire_comm *);
78748771 303int fwdev_destroydev (struct firewire_softc *);
b13267a5 304void fwdev_clone (void *, char *, int, cdev_t *);
984263bc
MD
305
306extern int firewire_debug;
307extern devclass_t firewire_devclass;
308
78748771
JS
309#ifdef __DragonFly__
310#define FWPRI PCATCH
311#else
312#define FWPRI ((PZERO+8)|PCATCH)
313#endif
984263bc 314
90dec0df 315#if defined(__DragonFly__) || __FreeBSD_version < 500000
984263bc 316#define CALLOUT_INIT(x) callout_init(x)
90dec0df
JS
317#else
318#define CALLOUT_INIT(x) callout_init(x, 0 /* mpsafe */)
984263bc
MD
319#endif
320
81b5c339 321#if defined(__DragonFly__)
78748771
JS
322#define MIN(a,b) (((a)<(b))?(a):(b))
323#define MAX(a,b) (((a)>(b))?(a):(b))
324#endif
325
984263bc
MD
326MALLOC_DECLARE(M_FW);
327MALLOC_DECLARE(M_FWXFER);