proc->thread stage 2: MAJOR revamping of system calls, ucred, jail API,
[dragonfly.git] / sys / bus / firewire / firewirereg.h
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: src/sys/dev/firewire/firewirereg.h,v 1.1.2.14 2003/05/01 06:24:37 simokawa Exp $
35  * $DragonFly: src/sys/bus/firewire/firewirereg.h,v 1.3 2003/06/23 17:55:30 dillon Exp $
36  *
37  */
38
39 #if __FreeBSD_version >= 500000
40 typedef struct thread fw_proc;
41 #include <sys/selinfo.h>
42 #else
43 typedef struct thread fw_proc;
44 #include <sys/select.h>
45 #endif
46
47 #include <sys/uio.h>
48
49 #define splfw splimp
50
51 struct fw_device{
52         u_int16_t dst;
53         struct fw_eui64 eui;
54         u_int8_t speed;
55         u_int8_t maxrec;
56         u_int8_t nport;
57         u_int8_t power;
58 #define CSRROMOFF 0x400
59 #define CSRROMSIZE 0x400
60         int rommax;     /* offset from 0xffff f000 0000 */
61         u_int32_t csrrom[CSRROMSIZE/4];
62         int rcnt;
63         struct firewire_comm *fc;
64         u_int32_t status;
65 #define FWDEVINIT       1
66 #define FWDEVATTACHED   2
67 #define FWDEVINVAL      3
68         STAILQ_ENTRY(fw_device) link;
69 };
70
71 struct firewire_softc {
72 #if __FreeBSD_version >= 500000
73         dev_t dev;
74 #else
75         dev_t dev[FWMAXNDMA+1];
76 #endif
77         struct firewire_comm *fc;
78 };
79
80 #define FW_MAX_DMACH 0x20
81 #define FW_MAX_DEVCH FW_MAX_DMACH
82 #define FW_XFERTIMEOUT 1
83
84 struct firewire_dev_comm {
85         device_t dev;
86         struct firewire_comm *fc;
87         void (*post_busreset) __P((void *));
88         void (*post_explore) __P((void *));
89 };
90
91 struct tcode_info {
92         u_char hdr_len; /* IEEE1394 header length */
93         u_char flag;
94 #define FWTI_REQ        (1 << 0)
95 #define FWTI_RES        (1 << 1)
96 #define FWTI_TLABEL     (1 << 2)
97 #define FWTI_BLOCK_STR  (1 << 3)
98 #define FWTI_BLOCK_ASY  (1 << 4)
99 };
100
101 struct firewire_comm{
102         device_t dev;
103         device_t bdev;
104         u_int16_t busid:10,
105                   nodeid:6;
106         u_int mode;
107         u_int nport;
108         u_int speed;
109         u_int maxrec;
110         u_int irm;
111         u_int max_node;
112         u_int max_hop;
113         u_int max_asyretry;
114 #define FWPHYASYST (1 << 0)
115         u_int retry_count;
116         u_int32_t ongobus:10,
117                   ongonode:6,
118                   ongoaddr:16;
119         struct fw_device *ongodev;
120         struct fw_eui64 ongoeui;
121 #define FWMAXCSRDIR     16
122         SLIST_HEAD(, csrdir) ongocsr;
123         SLIST_HEAD(, csrdir) csrfree;
124         u_int32_t status;
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;
141         STAILQ_HEAD(, fw_xfer)  pending;
142         u_int  sid_cnt;
143 #define CSRSIZE 0x4000
144         u_int32_t csr_arc[CSRSIZE/4];
145 #define CROMSIZE 0x400
146         u_int32_t *config_rom;
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         struct callout retry_probe_callout;
153         u_int32_t (*cyctimer) __P((struct  firewire_comm *));
154         void (*ibr) __P((struct firewire_comm *));
155         u_int32_t (*set_bmr) __P((struct firewire_comm *, u_int32_t));
156         int (*ioctl) __P((dev_t, u_long, caddr_t, int, fw_proc *));
157         int (*irx_enable) __P((struct firewire_comm *, int));
158         int (*irx_disable) __P((struct firewire_comm *, int));
159         int (*itx_enable) __P((struct firewire_comm *, int));
160         int (*itx_disable) __P((struct firewire_comm *, int));
161         void (*timeout) __P((void *));
162         void (*poll) __P((struct firewire_comm *, int, int));
163         void (*set_intr) __P((struct firewire_comm *, int));
164         void (*irx_post) __P((struct firewire_comm *, u_int32_t *));
165         void (*itx_post) __P((struct firewire_comm *, u_int32_t *));
166         struct tcode_info *tcode;
167         bus_dma_tag_t dmat;
168 };
169 #define CSRARC(sc, offset) ((sc)->csr_arc[(offset)/4])
170
171 struct csrdir{
172         u_int32_t ongoaddr;
173         u_int32_t off;
174         SLIST_ENTRY(csrdir) link;
175 };
176
177 struct fw_xferq {
178         int flag;
179 #define FWXFERQ_CHTAGMASK 0xff
180 #define FWXFERQ_RUNNING (1 << 8)
181 #define FWXFERQ_STREAM (1 << 9)
182
183 #define FWXFERQ_BULK (1 << 11)
184 #define FWXFERQ_MODEMASK (7 << 10)
185
186 #define FWXFERQ_EXTBUF (1 << 13)
187 #define FWXFERQ_OPEN (1 << 14)
188
189 #define FWXFERQ_HANDLER (1 << 16)
190 #define FWXFERQ_WAKEUP (1 << 17)
191
192         void (*start) __P((struct firewire_comm*));
193         STAILQ_HEAD(, fw_xfer) q;
194         u_int queued;
195         u_int maxq;
196         u_int psize;
197         STAILQ_HEAD(, fw_bind) binds;
198         struct fwdma_alloc_multi *buf;
199         u_int bnchunk;
200         u_int bnpacket;
201         struct fw_bulkxfer *bulkxfer;
202         STAILQ_HEAD(, fw_bulkxfer) stvalid;
203         STAILQ_HEAD(, fw_bulkxfer) stfree;
204         STAILQ_HEAD(, fw_bulkxfer) stdma;
205         struct fw_bulkxfer *stproc;
206         struct selinfo rsel;
207         caddr_t sc;
208         void (*hand) __P((struct fw_xferq *));
209 };
210
211 struct fw_bulkxfer{
212         int poffset;
213         struct mbuf *mbuf;
214         STAILQ_ENTRY(fw_bulkxfer) link;
215         caddr_t start;
216         caddr_t end;
217         int resp;
218 };
219
220 struct tlabel{
221         struct fw_xfer  *xfer;
222         STAILQ_ENTRY(tlabel) link;
223 };
224
225 struct fw_bind{
226         u_int32_t start_hi, start_lo, addrlen;
227         STAILQ_HEAD(, fw_xfer) xferlist;
228         STAILQ_ENTRY(fw_bind) fclist;
229         STAILQ_ENTRY(fw_bind) chlist;
230 #define FWACT_NULL      0
231 #define FWACT_XFER      2
232 #define FWACT_CH        3
233         u_int8_t act_type;
234         u_int8_t sub;
235 };
236
237 struct fw_xfer{
238         caddr_t sc;
239         struct firewire_comm *fc;
240         struct fw_xferq *q;
241         struct timeval tv;
242         /* XXX should be removed */
243         u_int32_t dst; /* XXX for if_fwe */
244         u_int8_t spd;
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;
256         void (*retry_req) __P((struct fw_xfer *));
257         union{
258                 void (*hand) __P((struct fw_xfer *));
259         } act;
260         struct {
261                 int len;
262                 caddr_t buf;
263         } send, recv;
264         struct mbuf *mbuf;
265         STAILQ_ENTRY(fw_xfer) link;
266         struct malloc_type *malloc;
267 };
268 void fw_sidrcv __P((struct firewire_comm *, u_int32_t *, u_int));
269 void fw_rcv __P((struct firewire_comm *, struct iovec *, int, u_int, u_int));
270 void fw_xfer_unload __P(( struct fw_xfer*));
271 void fw_xfer_free __P(( struct fw_xfer*));
272 struct fw_xfer *fw_xfer_alloc __P((struct malloc_type *));
273 struct fw_xfer *fw_xfer_alloc_buf __P((struct malloc_type *, int, int));
274 void fw_init __P((struct firewire_comm *));
275 int fw_tbuf_update __P((struct firewire_comm *, int, int));
276 int fw_rbuf_update __P((struct firewire_comm *, int, int));
277 void fw_asybusy __P((struct fw_xfer *));
278 int fw_bindadd __P((struct firewire_comm *, struct fw_bind *));
279 int fw_bindremove __P((struct firewire_comm *, struct fw_bind *));
280 int fw_asyreq __P((struct firewire_comm *, int, struct fw_xfer*));
281 void fw_busreset __P((struct firewire_comm *));
282 u_int16_t fw_crc16 __P((u_int32_t *, u_int32_t));
283 void fw_xfer_timeout __P((void *));
284 void fw_xfer_done __P((struct fw_xfer *));
285 void fw_asy_callback __P((struct fw_xfer *));
286 struct fw_device *fw_noderesolve_nodeid __P((struct firewire_comm *, int));
287 struct fw_device *fw_noderesolve_eui64 __P((struct firewire_comm *, struct fw_eui64 *));
288 struct fw_bind *fw_bindlookup __P((struct firewire_comm *, u_int32_t, u_int32_t));
289 void fw_drain_txq __P((struct firewire_comm *));
290
291
292 extern int firewire_debug;
293 extern devclass_t firewire_devclass;
294
295 #define         FWPRI           ((PZERO+8)|PCATCH)
296
297 #if __FreeBSD_version >= 500000
298 #define CALLOUT_INIT(x) callout_init(x, 0 /* mpsafe */)
299 #else
300 #define CALLOUT_INIT(x) callout_init(x)
301 #endif
302
303 MALLOC_DECLARE(M_FW);
304 MALLOC_DECLARE(M_FWXFER);