firewirereg.h revision 110129
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: head/sys/dev/firewire/firewirereg.h 110129 2003-01-31 03:09:13Z simokawa $
34 *
35 */
36
37#if __FreeBSD_version >= 500000
38typedef	struct thread fw_proc;
39#include <sys/selinfo.h>
40#else
41typedef	struct proc fw_proc;
42#include <sys/select.h>
43#endif
44
45#define	splfw splimp
46
47struct 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
75struct firewire_softc {
76#if __FreeBSD_version >= 500000
77	dev_t dev;
78#else
79	dev_t dev[FWMAXNDMA+1];
80#endif
81	struct firewire_comm *fc;
82};
83
84#define FW_MAX_DMACH 0x20
85#define FW_MAX_DEVCH FW_MAX_DMACH
86#define FW_XFERTIMEOUT 1
87
88struct firewire_dev_comm {
89	device_t dev;
90	struct firewire_comm *fc;
91	void (*post_explore) __P((void *));
92};
93
94struct tcode_info {
95	u_char hdr_len;	/* IEEE1394 header length */
96	u_char flag;
97#define FWTI_REQ	(1 << 0)
98#define FWTI_RES	(1 << 1)
99#define FWTI_TLABEL	(1 << 2)
100#define FWTI_BLOCK_STR	(1 << 3)
101#define FWTI_BLOCK_ASY	(1 << 4)
102};
103
104struct firewire_comm{
105	device_t dev;
106	device_t bdev;
107	u_int16_t busid:10,
108		  nodeid:6;
109	u_int mode;
110	u_int nport;
111	u_int speed;
112	u_int maxrec;
113	u_int irm;
114	u_int max_node;
115	u_int max_hop;
116	u_int max_asyretry;
117#define FWPHYASYST (1 << 0)
118	u_int retry_count;
119	u_int32_t ongobus:10,
120		  ongonode:6,
121		  ongoaddr:16;
122	struct fw_device *ongodev;
123	struct fw_eui64 ongoeui;
124#define	FWMAXCSRDIR     16
125	SLIST_HEAD(, csrdir) ongocsr;
126	SLIST_HEAD(, csrdir) csrfree;
127	u_int32_t status;
128#define	FWBUSRESET	0
129#define	FWBUSINIT	1
130#define	FWBUSCYMELECT	2
131#define	FWBUSMGRELECT	3
132#define	FWBUSMGRDONE	4
133#define	FWBUSEXPLORE	5
134#define	FWBUSPHYCONF	6
135#define	FWBUSEXPDONE	7
136#define	FWBUSCOMPLETION	10
137	int nisodma;
138	struct fw_eui64 eui;
139	STAILQ_HEAD(fw_queue, fw_xfer);
140	struct fw_xferq
141		*arq, *atq, *ars, *ats, *it[FW_MAX_DMACH],*ir[FW_MAX_DMACH];
142	STAILQ_HEAD(, tlabel) tlabels[0x40];
143	STAILQ_HEAD(, fw_bind) binds;
144	TAILQ_HEAD(, fw_device) devices;
145	STAILQ_HEAD(, fw_xfer)	pending;
146	volatile u_int32_t *sid_buf;
147	u_int  sid_cnt;
148#define CSRSIZE 0x4000
149	u_int32_t csr_arc[CSRSIZE/4];
150#define CROMSIZE 0x400
151	u_int32_t *config_rom;
152	struct fw_topology_map *topology_map;
153	struct fw_speed_map *speed_map;
154	struct callout busprobe_callout;
155	struct callout_handle bmrhandle;
156	struct callout_handle timeouthandle;
157	struct callout_handle retry_probe_handle;
158	u_int32_t (*cyctimer) __P((struct  firewire_comm *));
159	void (*ibr) __P((struct firewire_comm *));
160	u_int32_t (*set_bmr) __P((struct firewire_comm *, u_int32_t));
161	int (*ioctl) __P((dev_t, u_long, caddr_t, int, fw_proc *));
162	int (*irx_enable) __P((struct firewire_comm *, int));
163	int (*irx_disable) __P((struct firewire_comm *, int));
164	int (*itx_enable) __P((struct firewire_comm *, int));
165	int (*itx_disable) __P((struct firewire_comm *, int));
166	void (*timeout) __P((void *));
167	void (*poll) __P((struct firewire_comm *, int, int));
168	void (*set_intr) __P((struct firewire_comm *, int));
169	void (*irx_post) __P((struct firewire_comm *, u_int32_t *));
170	void (*itx_post) __P((struct firewire_comm *, u_int32_t *));
171	struct tcode_info *tcode;
172};
173#define CSRARC(sc, offset) ((sc)->csr_arc[(offset)/4])
174
175struct csrdir{
176	u_int32_t ongoaddr;
177	u_int32_t off;
178	SLIST_ENTRY(csrdir) link;
179};
180
181struct fw_xferq {
182	int flag;
183#define FWXFERQ_CHTAGMASK 0xff
184#define FWXFERQ_RUNNING (1 << 8)
185#define FWXFERQ_STREAM (1 << 9)
186
187#define FWXFERQ_PACKET (1 << 10)
188#define FWXFERQ_BULK (1 << 11)
189#if 0 /* BROKEN */
190#define FWXFERQ_DV (1 << 12)
191#endif
192#define FWXFERQ_MODEMASK (7 << 10)
193
194#define FWXFERQ_EXTBUF (1 << 13)
195#define FWXFERQ_OPEN (1 << 14)
196
197#define FWXFERQ_HANDLER (1 << 16)
198#define FWXFERQ_WAKEUP (1 << 17)
199
200	void (*start) __P((struct firewire_comm*));
201	void (*drain) __P((struct firewire_comm*, struct fw_xfer*));
202	struct fw_queue q;
203	u_int queued;
204	u_int maxq;
205	u_int psize;
206	u_int packets;
207	STAILQ_HEAD(, fw_bind) binds;
208	caddr_t buf;
209	u_int bnchunk;
210	u_int bnpacket;
211	struct fw_bulkxfer *bulkxfer;
212	STAILQ_HEAD(, fw_bulkxfer) stvalid;
213	STAILQ_HEAD(, fw_bulkxfer) stfree;
214	STAILQ_HEAD(, fw_bulkxfer) stdma;
215	struct fw_bulkxfer *stproc;
216#ifdef FWXFERQ_DV
217	int dvdbc, dvdiff, dvsync, dvoffset;
218	struct fw_dvbuf *dvbuf;
219	STAILQ_HEAD(, fw_dvbuf) dvvalid;
220	STAILQ_HEAD(, fw_dvbuf) dvfree;
221	struct fw_dvbuf *dvdma;
222	struct fw_dvbuf *dvproc;
223	u_int dvptr;
224	u_int dvpacket;
225#endif
226	struct selinfo rsel;
227	caddr_t sc;
228	void (*hand) __P((struct fw_xferq *));
229};
230
231struct fw_bulkxfer{
232	caddr_t buf;
233	STAILQ_ENTRY(fw_bulkxfer) link;
234	caddr_t start;
235	caddr_t end;
236	u_int npacket;
237};
238
239struct fw_dvbuf{
240	caddr_t buf;
241	STAILQ_ENTRY(fw_dvbuf) link;
242};
243
244struct tlabel{
245	struct fw_xfer  *xfer;
246	STAILQ_ENTRY(tlabel) link;
247};
248
249struct fw_bind{
250	u_int32_t start_hi, start_lo, addrlen;
251	struct fw_xfer* xfer;
252	STAILQ_ENTRY(fw_bind) fclist;
253	STAILQ_ENTRY(fw_bind) chlist;
254};
255
256struct fw_xfer{
257	caddr_t sc;
258	struct firewire_comm *fc;
259	struct fw_xferq *q;
260	struct callout_handle ch;
261	time_t time;
262	struct fw_tlabel *tlabel;
263	u_int8_t spd;
264	u_int8_t tcode;
265	int resp;
266#define FWXF_INIT 0
267#define FWXF_INQ 1
268#define FWXF_START 2
269#define FWXF_SENT 3
270#define FWXF_SENTERR 4
271#define FWXF_BUSY 8
272#define FWXF_RCVD 10
273	int state;
274	u_int8_t retry;
275	u_int8_t tl;
276	int sub;
277	int32_t dst;
278	u_int8_t act_type;
279#define FWACT_NULL	0
280#define FWACT_XFER	2
281#define FWACT_CH	3
282	void (*retry_req) __P((struct fw_xfer *));
283	union{
284		void (*hand) __P((struct fw_xfer *));
285
286	} act;
287	union{
288		struct {
289			struct fw_device *device;
290		} req;
291		struct {
292			struct stch *channel;
293		} stream;
294	} mode;
295	struct {
296		u_int16_t len, off;
297		caddr_t buf;
298	} send, recv;
299	struct mbuf *mbuf;
300	STAILQ_ENTRY(fw_xfer) link;
301};
302void fw_sidrcv __P((struct firewire_comm *, caddr_t, u_int, u_int));
303void fw_rcv __P((struct firewire_comm *, caddr_t, u_int, u_int, u_int, u_int));
304void fw_xfer_free __P(( struct fw_xfer*));
305struct fw_xfer *fw_xfer_alloc __P((void));
306void fw_init __P((struct firewire_comm *));
307int fw_tbuf_update __P((struct firewire_comm *, int, int));
308int fw_rbuf_update __P((struct firewire_comm *, int, int));
309int fw_readreqq __P((struct firewire_comm *, u_int32_t, u_int32_t, u_int32_t *));
310int fw_writereqb __P((struct firewire_comm *, u_int32_t, u_int32_t, u_int32_t, u_int32_t *));
311int fw_readresb __P((struct firewire_comm *, u_int32_t, u_int32_t, u_int32_t, u_int32_t*));
312int fw_writeres __P((struct firewire_comm *, u_int32_t, u_int32_t));
313u_int32_t getcsrdata __P((struct fw_device *, u_int8_t));
314void fw_asybusy __P((struct fw_xfer *));
315int fw_bindadd __P((struct firewire_comm *, struct fw_bind *));
316int fw_bindremove __P((struct firewire_comm *, struct fw_bind *));
317int fw_asyreq __P((struct firewire_comm *, int, struct fw_xfer*));
318void fw_busreset __P((struct firewire_comm *));
319u_int16_t fw_crc16 __P((u_int32_t *, u_int32_t));
320void fw_xfer_timeout __P((void *));
321void fw_xfer_done __P((struct fw_xfer *));
322void fw_asy_callback __P((struct fw_xfer *));
323struct fw_device *fw_noderesolve_nodeid __P((struct firewire_comm *, int));
324struct fw_device *fw_noderesolve_eui64 __P((struct firewire_comm *, struct fw_eui64));
325struct fw_bind *fw_bindlookup __P((struct firewire_comm *, u_int32_t, u_int32_t));
326
327
328extern int firewire_debug;
329extern devclass_t firewire_devclass;
330
331#define DV_BROADCAST_ON (1<<30)
332#define		IP_CHANNELS	0x0234
333
334#define		STATE_CLEAR	0x0000
335#define		STATE_SET	0x0004
336#define		NODE_IDS	0x0008
337#define		RESET_START	0x000c
338#define		SPLIT_TIMEOUT_HI	0x0018
339#define		SPLIT_TIMEOUT_LO	0x001c
340#define		CYCLE_TIME	0x0200
341#define		BUS_TIME	0x0204
342#define		BUSY_TIMEOUT	0x0210
343#define		BUS_MGR_ID	0x021c
344#define		BANDWIDTH_AV	0x0220
345#define		CHANNELS_AV_HI	0x0224
346#define		CHANNELS_AV_LO	0x0228
347
348#define		CONF_ROM	0x0400
349
350#define		TOPO_MAP	0x1000
351#define		SPED_MAP	0x2000
352
353#define		oMPR		0x900
354#define		oPCR		0x904
355
356#define		iMPR		0x980
357#define		iPCR		0x984
358
359#define		FWPRI		((PZERO+8)|PCATCH)
360
361#ifdef __alpha__
362#undef vtophys
363#define vtophys(va)	alpha_XXX_dmamap((vm_offset_t)(va))
364#endif /* __alpha__ */
365