xref: /freebsd/sys/dev/firewire/firewirereg.h (revision 2d3ce7133ad8cd5bfd8ac6b3c3d42dd3e493e911)
1 /*
2  * Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the acknowledgement as bellow:
15  *
16  *    This product includes software developed by K. Kobayashi and H. Shimokawa
17  *
18  * 4. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
25  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  * $FreeBSD$
34  *
35  */
36 
37 #if __FreeBSD_version >= 500000
38 typedef	struct thread fw_proc;
39 #include <sys/selinfo.h>
40 #else
41 typedef	struct proc fw_proc;
42 #include <sys/select.h>
43 #endif
44 
45 #define	splfw splimp
46 
47 struct fw_device{
48 	u_int16_t dst;
49 	struct fw_eui64 eui;
50 #if 0
51 	u_int32_t spec;
52 	u_int32_t ver;
53 #endif
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 	TAILQ_ENTRY(fw_device) link;
69 #if 0
70 	LIST_HEAD(, fw_xfer) txqueue;
71 	LIST_HEAD(, fw_xfer) rxqueue;
72 #endif
73 };
74 struct firewire_softc {
75 #if __FreeBSD_version >= 500000
76 	dev_t dev;
77 #else
78 	dev_t dev[FWMAXNDMA+1];
79 #endif
80 	struct firewire_comm *fc;
81 };
82 #define FW_MAX_DMACH 0x20
83 #define FW_MAX_DEVCH FW_MAX_DMACH
84 #define FW_XFERTIMEOUT 1
85 struct firewire_dev_comm {
86 	device_t dev;
87 	struct firewire_comm *fc;
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 	struct csrdir{
125 		u_int32_t ongoaddr;
126 		u_int32_t off;
127 		SLIST_ENTRY(csrdir) link;
128 	};
129 	u_int32_t status;
130 #define	FWBUSRESET	0
131 #define	FWBUSINIT	1
132 #define	FWBUSCYMELECT	2
133 #define	FWBUSMGRELECT	3
134 #define	FWBUSMGRDONE	4
135 #define	FWBUSEXPLORE	5
136 #define	FWBUSPHYCONF	6
137 #define	FWBUSEXPDONE	7
138 #define	FWBUSCOMPLETION	10
139 	int nisodma;
140 	u_int8_t eui[8];
141 	STAILQ_HEAD(fw_queue, fw_xfer);
142 	struct fw_xferq {
143 		int flag;
144 #define FWXFERQ_CHTAGMASK 0xff
145 #define FWXFERQ_RUNNING (1 << 8)
146 #define FWXFERQ_STREAM (1 << 9)
147 
148 #define FWXFERQ_PACKET (1 << 10)
149 #define FWXFERQ_BULK (1 << 11)
150 #define FWXFERQ_DV (1 << 12)
151 #define FWXFERQ_MODEMASK (7 << 10)
152 
153 #define FWXFERQ_EXTBUF (1 << 13)
154 #define FWXFERQ_OPEN (1 << 14)
155 
156 #define FWXFERQ_HANDLER (1 << 16)
157 #define FWXFERQ_WAKEUP (1 << 17)
158 
159 		void (*start) __P((struct firewire_comm*));
160 		void (*drain) __P((struct firewire_comm*, struct fw_xfer*));
161 		struct fw_queue q;
162 		u_int queued;
163 		u_int maxq;
164 		u_int psize;
165 		u_int packets;
166 		u_int error;
167 		STAILQ_HEAD(, fw_bind) binds;
168 		caddr_t buf;
169 		u_int bnchunk;
170 		u_int bnpacket;
171 		u_int btpacket;
172 		struct fw_bulkxfer *bulkxfer;
173 		STAILQ_HEAD(, fw_bulkxfer) stvalid;
174 		STAILQ_HEAD(, fw_bulkxfer) stfree;
175 		struct fw_bulkxfer *stdma;
176 		struct fw_bulkxfer *stdma2;
177 		struct fw_bulkxfer *stproc;
178 		u_int procptr;
179 		int dvdbc, dvdiff, dvsync, dvoffset;
180 		struct fw_dvbuf *dvbuf;
181 		STAILQ_HEAD(, fw_dvbuf) dvvalid;
182 		STAILQ_HEAD(, fw_dvbuf) dvfree;
183 		struct fw_dvbuf *dvdma;
184 		struct fw_dvbuf *dvproc;
185 		u_int dvptr;
186 		u_int dvpacket;
187 		u_int need_wakeup;
188 		struct selinfo rsel;
189 		caddr_t sc;
190 		void (*hand) __P((struct fw_xferq *));
191 	};
192 	struct fw_xferq
193 		*arq, *atq, *ars, *ats, *it[FW_MAX_DMACH],*ir[FW_MAX_DMACH];
194 	struct fw_bulkxfer{
195 		u_int32_t flag;
196 		caddr_t buf;
197 		STAILQ_ENTRY(fw_bulkxfer) link;
198 		caddr_t start;
199 		caddr_t end;
200 		u_int npacket;
201 	};
202 	struct fw_dvbuf{
203 		caddr_t buf;
204 		STAILQ_ENTRY(fw_dvbuf) link;
205 	};
206 	struct tlabel{
207 		struct fw_xfer  *xfer;
208 		STAILQ_ENTRY(tlabel) link;
209 	};
210 	STAILQ_HEAD(, tlabel) tlabels[0x40];
211 	struct fw_bind{
212 		u_int32_t start_hi, start_lo, addrlen;
213 		struct fw_xfer* xfer;
214 		STAILQ_ENTRY(fw_bind) fclist;
215 		STAILQ_ENTRY(fw_bind) chlist;
216 	};
217 	STAILQ_HEAD(, fw_bind) binds;
218 	TAILQ_HEAD(, fw_device) devices;
219 	STAILQ_HEAD(, fw_xfer)	pending;
220 	volatile u_int32_t *sid_buf;
221 	u_int  sid_cnt;
222 #define CSRSIZE 0x4000
223 	u_int32_t csr_arc[CSRSIZE/4];
224 #define CROMSIZE 0x400
225 	u_int32_t *config_rom;
226 	struct fw_topology_map *topology_map;
227 	struct fw_speed_map *speed_map;
228 	struct callout busprobe_callout;
229 	struct callout_handle bmrhandle;
230 	struct callout_handle timeouthandle;
231 	struct callout_handle retry_probe_handle;
232 	u_int32_t (*cyctimer) __P((struct  firewire_comm *));
233 	void (*ibr) __P((struct firewire_comm *));
234 	u_int32_t (*set_bmr) __P((struct firewire_comm *, u_int32_t));
235 	int (*ioctl) __P((dev_t, u_long, caddr_t, int, fw_proc *));
236 	int (*irx_enable) __P((struct firewire_comm *, int));
237 	int (*irx_disable) __P((struct firewire_comm *, int));
238 	int (*itx_enable) __P((struct firewire_comm *, int));
239 	int (*itx_disable) __P((struct firewire_comm *, int));
240 	void (*timeout) __P((void *));
241 	void (*poll) __P((struct firewire_comm *, int, int));
242 	void (*set_intr) __P((struct firewire_comm *, int));
243 	void (*irx_post) __P((struct firewire_comm *, u_int32_t *));
244 	void (*itx_post) __P((struct firewire_comm *, u_int32_t *));
245 	struct tcode_info *tcode;
246 };
247 #define CSRARC(sc, offset) ((sc)->csr_arc[(offset)/4])
248 
249 
250 struct fw_xfer{
251 	caddr_t sc;
252 	struct firewire_comm *fc;
253 	struct fw_xferq *q;
254 	struct callout_handle ch;
255 	time_t time;
256 	struct fw_tlabel *tlabel;
257 	u_int8_t spd;
258 	u_int8_t tcode;
259 	int resp;
260 #define FWXF_INIT 0
261 #define FWXF_INQ 1
262 #define FWXF_START 2
263 #define FWXF_SENT 3
264 #define FWXF_SENTERR 4
265 #define FWXF_BUSY 8
266 #define FWXF_RCVD 10
267 	int state;
268 	u_int8_t retry;
269 	u_int8_t tl;
270 	int sub;
271 	int32_t dst;
272 	u_int8_t act_type;
273 #define FWACT_NULL	0
274 #define FWACT_XFER	2
275 #define FWACT_CH	3
276 	void (*retry_req) __P((struct fw_xfer *));
277 	union{
278 		void (*hand) __P((struct fw_xfer *));
279 
280 	} act;
281 	union{
282 		struct {
283 			struct fw_device *device;
284 		} req;
285 		struct {
286 			struct stch *channel;
287 		} stream;
288 	} mode;
289 	struct {
290 		u_int16_t len, off;
291 		caddr_t buf;
292 	} send, recv;
293 	struct mbuf *mbuf;
294 	STAILQ_ENTRY(fw_xfer) link;
295 };
296 void fw_sidrcv __P((struct firewire_comm *, caddr_t, u_int, u_int));
297 void fw_rcv __P((struct firewire_comm *, caddr_t, u_int, u_int, u_int, u_int));
298 void fw_xfer_free __P(( struct fw_xfer*));
299 struct fw_xfer *fw_xfer_alloc __P((void));
300 void fw_init __P((struct firewire_comm *));
301 int fw_tbuf_update __P((struct firewire_comm *, int, int));
302 int fw_rbuf_update __P((struct firewire_comm *, int, int));
303 int fw_readreqq __P((struct firewire_comm *, u_int32_t, u_int32_t, u_int32_t *));
304 int fw_writereqb __P((struct firewire_comm *, u_int32_t, u_int32_t, u_int32_t, u_int32_t *));
305 int fw_readresb __P((struct firewire_comm *, u_int32_t, u_int32_t, u_int32_t, u_int32_t*));
306 int fw_writeres __P((struct firewire_comm *, u_int32_t, u_int32_t));
307 u_int32_t getcsrdata __P((struct fw_device *, u_int8_t));
308 void fw_asybusy __P((struct fw_xfer *));
309 int fw_bindadd __P((struct firewire_comm *, struct fw_bind *));
310 int fw_bindremove __P((struct firewire_comm *, struct fw_bind *));
311 int fw_asyreq __P((struct firewire_comm *, int, struct fw_xfer*));
312 void fw_busreset __P((struct firewire_comm *));
313 u_int16_t fw_crc16 __P((u_int32_t *, u_int32_t));
314 void fw_xfer_timeout __P((void *));
315 void fw_xfer_done __P((struct fw_xfer *));
316 void fw_asy_callback __P((struct fw_xfer *));
317 struct fw_device *fw_noderesolve __P((struct firewire_comm *, struct fw_eui64));
318 struct fw_bind *fw_bindlookup __P((struct firewire_comm *, u_int32_t, u_int32_t));
319 
320 
321 extern int firewire_debug;
322 extern devclass_t firewire_devclass;
323 
324 #define DV_BROADCAST_ON (1<<30)
325 #define		IP_CHANNELS	0x0234
326 
327 #define		STATE_CLEAR	0x0000
328 #define		STATE_SET	0x0004
329 #define		NODE_IDS	0x0008
330 #define		RESET_START	0x000c
331 #define		SPLIT_TIMEOUT_HI	0x0018
332 #define		SPLIT_TIMEOUT_LO	0x001c
333 #define		CYCLE_TIME	0x0200
334 #define		BUS_TIME	0x0210
335 #define		BUS_MGR_ID	0x021c
336 #define		BANDWIDTH_AV	0x0220
337 #define		CHANNELS_AV_HI	0x0224
338 #define		CHANNELS_AV_LO	0x0228
339 
340 #define		CONF_ROM	0x0400
341 
342 #define		TOPO_MAP	0x1000
343 #define		SPED_MAP	0x2000
344 
345 #define		oMPR		0x900
346 #define		oPCR		0x904
347 
348 #define		iMPR		0x980
349 #define		iPCR		0x984
350 
351 #define		FWPRI		((PZERO+8)|PCATCH)
352 
353 #ifdef __alpha__
354 #undef vtophys
355 #define vtophys(va)	alpha_XXX_dmamap((vm_offset_t)(va))
356 #endif /* __alpha__ */
357