firewirereg.h revision 113584
1103285Sikob/*
2113584Ssimokawa * Copyright (c) 2003 Hidetoshi Shimokawa
3103285Sikob * Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa
4103285Sikob * All rights reserved.
5103285Sikob *
6103285Sikob * Redistribution and use in source and binary forms, with or without
7103285Sikob * modification, are permitted provided that the following conditions
8103285Sikob * are met:
9103285Sikob * 1. Redistributions of source code must retain the above copyright
10103285Sikob *    notice, this list of conditions and the following disclaimer.
11103285Sikob * 2. Redistributions in binary form must reproduce the above copyright
12103285Sikob *    notice, this list of conditions and the following disclaimer in the
13103285Sikob *    documentation and/or other materials provided with the distribution.
14103285Sikob * 3. All advertising materials mentioning features or use of this software
15103285Sikob *    must display the acknowledgement as bellow:
16103285Sikob *
17103285Sikob *    This product includes software developed by K. Kobayashi and H. Shimokawa
18103285Sikob *
19103285Sikob * 4. The name of the author may not be used to endorse or promote products
20103285Sikob *    derived from this software without specific prior written permission.
21103285Sikob *
22103285Sikob * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23103285Sikob * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24103285Sikob * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25103285Sikob * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
26103285Sikob * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27103285Sikob * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28103285Sikob * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29103285Sikob * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30103285Sikob * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31103285Sikob * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32103285Sikob * POSSIBILITY OF SUCH DAMAGE.
33103285Sikob *
34103285Sikob * $FreeBSD: head/sys/dev/firewire/firewirereg.h 113584 2003-04-17 03:38:03Z simokawa $
35103285Sikob *
36103285Sikob */
37103285Sikob
38103285Sikob#if __FreeBSD_version >= 500000
39103285Sikobtypedef	struct thread fw_proc;
40103285Sikob#include <sys/selinfo.h>
41103285Sikob#else
42103285Sikobtypedef	struct proc fw_proc;
43103285Sikob#include <sys/select.h>
44103285Sikob#endif
45103285Sikob
46113584Ssimokawa#include <sys/uio.h>
47113584Ssimokawa
48103285Sikob#define	splfw splimp
49103285Sikob
50103285Sikobstruct fw_device{
51103285Sikob	u_int16_t dst;
52103285Sikob	struct fw_eui64 eui;
53103285Sikob	u_int8_t speed;
54103285Sikob	u_int8_t maxrec;
55103285Sikob	u_int8_t nport;
56103285Sikob	u_int8_t power;
57103285Sikob#define CSRROMOFF 0x400
58103285Sikob#define CSRROMSIZE 0x400
59103285Sikob	int rommax;	/* offset from 0xffff f000 0000 */
60103285Sikob	u_int32_t csrrom[CSRROMSIZE/4];
61103285Sikob	int rcnt;
62106810Ssimokawa	struct firewire_comm *fc;
63103285Sikob	u_int32_t status;
64103285Sikob#define FWDEVINIT	1
65103285Sikob#define FWDEVATTACHED	2
66103285Sikob#define FWDEVINVAL	3
67110193Ssimokawa	STAILQ_ENTRY(fw_device) link;
68103285Sikob};
69109645Ssimokawa
70103285Sikobstruct firewire_softc {
71103285Sikob#if __FreeBSD_version >= 500000
72103285Sikob	dev_t dev;
73103285Sikob#else
74103285Sikob	dev_t dev[FWMAXNDMA+1];
75103285Sikob#endif
76103285Sikob	struct firewire_comm *fc;
77103285Sikob};
78109645Ssimokawa
79103285Sikob#define FW_MAX_DMACH 0x20
80103285Sikob#define FW_MAX_DEVCH FW_MAX_DMACH
81103285Sikob#define FW_XFERTIMEOUT 1
82109645Ssimokawa
83103285Sikobstruct firewire_dev_comm {
84103285Sikob	device_t dev;
85103285Sikob	struct firewire_comm *fc;
86113584Ssimokawa	void (*post_busreset) __P((void *));
87103285Sikob	void (*post_explore) __P((void *));
88103285Sikob};
89103285Sikob
90103285Sikobstruct tcode_info {
91103285Sikob	u_char hdr_len;	/* IEEE1394 header length */
92103285Sikob	u_char flag;
93103285Sikob#define FWTI_REQ	(1 << 0)
94103285Sikob#define FWTI_RES	(1 << 1)
95103285Sikob#define FWTI_TLABEL	(1 << 2)
96103285Sikob#define FWTI_BLOCK_STR	(1 << 3)
97103285Sikob#define FWTI_BLOCK_ASY	(1 << 4)
98103285Sikob};
99103285Sikob
100103285Sikobstruct firewire_comm{
101103285Sikob	device_t dev;
102103285Sikob	device_t bdev;
103103285Sikob	u_int16_t busid:10,
104103285Sikob		  nodeid:6;
105103285Sikob	u_int mode;
106103285Sikob	u_int nport;
107103285Sikob	u_int speed;
108103285Sikob	u_int maxrec;
109103285Sikob	u_int irm;
110103285Sikob	u_int max_node;
111103285Sikob	u_int max_hop;
112103285Sikob	u_int max_asyretry;
113103285Sikob#define FWPHYASYST (1 << 0)
114103285Sikob	u_int retry_count;
115103285Sikob	u_int32_t ongobus:10,
116103285Sikob		  ongonode:6,
117103285Sikob		  ongoaddr:16;
118103285Sikob	struct fw_device *ongodev;
119103285Sikob	struct fw_eui64 ongoeui;
120103285Sikob#define	FWMAXCSRDIR     16
121103285Sikob	SLIST_HEAD(, csrdir) ongocsr;
122103285Sikob	SLIST_HEAD(, csrdir) csrfree;
123103285Sikob	u_int32_t status;
124103285Sikob#define	FWBUSRESET	0
125103285Sikob#define	FWBUSINIT	1
126103285Sikob#define	FWBUSCYMELECT	2
127103285Sikob#define	FWBUSMGRELECT	3
128103285Sikob#define	FWBUSMGRDONE	4
129103285Sikob#define	FWBUSEXPLORE	5
130103285Sikob#define	FWBUSPHYCONF	6
131103285Sikob#define	FWBUSEXPDONE	7
132103285Sikob#define	FWBUSCOMPLETION	10
133103285Sikob	int nisodma;
134109814Ssimokawa	struct fw_eui64 eui;
135103285Sikob	struct fw_xferq
136103285Sikob		*arq, *atq, *ars, *ats, *it[FW_MAX_DMACH],*ir[FW_MAX_DMACH];
137103285Sikob	STAILQ_HEAD(, tlabel) tlabels[0x40];
138103285Sikob	STAILQ_HEAD(, fw_bind) binds;
139110193Ssimokawa	STAILQ_HEAD(, fw_device) devices;
140103285Sikob	STAILQ_HEAD(, fw_xfer)	pending;
141103285Sikob	u_int  sid_cnt;
142103285Sikob#define CSRSIZE 0x4000
143103285Sikob	u_int32_t csr_arc[CSRSIZE/4];
144103285Sikob#define CROMSIZE 0x400
145103285Sikob	u_int32_t *config_rom;
146103285Sikob	struct fw_topology_map *topology_map;
147103285Sikob	struct fw_speed_map *speed_map;
148108853Ssimokawa	struct callout busprobe_callout;
149110193Ssimokawa	struct callout bmr_callout;
150110193Ssimokawa	struct callout timeout_callout;
151110193Ssimokawa	struct callout retry_probe_callout;
152103285Sikob	u_int32_t (*cyctimer) __P((struct  firewire_comm *));
153103285Sikob	void (*ibr) __P((struct firewire_comm *));
154103285Sikob	u_int32_t (*set_bmr) __P((struct firewire_comm *, u_int32_t));
155103285Sikob	int (*ioctl) __P((dev_t, u_long, caddr_t, int, fw_proc *));
156103285Sikob	int (*irx_enable) __P((struct firewire_comm *, int));
157103285Sikob	int (*irx_disable) __P((struct firewire_comm *, int));
158103285Sikob	int (*itx_enable) __P((struct firewire_comm *, int));
159103285Sikob	int (*itx_disable) __P((struct firewire_comm *, int));
160103285Sikob	void (*timeout) __P((void *));
161103285Sikob	void (*poll) __P((struct firewire_comm *, int, int));
162103285Sikob	void (*set_intr) __P((struct firewire_comm *, int));
163103285Sikob	void (*irx_post) __P((struct firewire_comm *, u_int32_t *));
164103285Sikob	void (*itx_post) __P((struct firewire_comm *, u_int32_t *));
165103285Sikob	struct tcode_info *tcode;
166113584Ssimokawa	bus_dma_tag_t dmat;
167103285Sikob};
168103285Sikob#define CSRARC(sc, offset) ((sc)->csr_arc[(offset)/4])
169103285Sikob
170109645Ssimokawastruct csrdir{
171109645Ssimokawa	u_int32_t ongoaddr;
172109645Ssimokawa	u_int32_t off;
173109645Ssimokawa	SLIST_ENTRY(csrdir) link;
174109645Ssimokawa};
175103285Sikob
176109645Ssimokawastruct fw_xferq {
177109645Ssimokawa	int flag;
178109645Ssimokawa#define FWXFERQ_CHTAGMASK 0xff
179109645Ssimokawa#define FWXFERQ_RUNNING (1 << 8)
180109645Ssimokawa#define FWXFERQ_STREAM (1 << 9)
181109645Ssimokawa
182109645Ssimokawa#define FWXFERQ_BULK (1 << 11)
183109645Ssimokawa#define FWXFERQ_MODEMASK (7 << 10)
184109645Ssimokawa
185109645Ssimokawa#define FWXFERQ_EXTBUF (1 << 13)
186109645Ssimokawa#define FWXFERQ_OPEN (1 << 14)
187109645Ssimokawa
188109645Ssimokawa#define FWXFERQ_HANDLER (1 << 16)
189109645Ssimokawa#define FWXFERQ_WAKEUP (1 << 17)
190109645Ssimokawa
191109645Ssimokawa	void (*start) __P((struct firewire_comm*));
192113584Ssimokawa	STAILQ_HEAD(, fw_xfer) q;
193109645Ssimokawa	u_int queued;
194109645Ssimokawa	u_int maxq;
195109645Ssimokawa	u_int psize;
196109645Ssimokawa	STAILQ_HEAD(, fw_bind) binds;
197113584Ssimokawa	struct fwdma_alloc_multi *buf;
198109645Ssimokawa	u_int bnchunk;
199109645Ssimokawa	u_int bnpacket;
200109645Ssimokawa	struct fw_bulkxfer *bulkxfer;
201109645Ssimokawa	STAILQ_HEAD(, fw_bulkxfer) stvalid;
202109645Ssimokawa	STAILQ_HEAD(, fw_bulkxfer) stfree;
203109890Ssimokawa	STAILQ_HEAD(, fw_bulkxfer) stdma;
204109645Ssimokawa	struct fw_bulkxfer *stproc;
205109645Ssimokawa	struct selinfo rsel;
206109645Ssimokawa	caddr_t sc;
207109645Ssimokawa	void (*hand) __P((struct fw_xferq *));
208109645Ssimokawa};
209109645Ssimokawa
210109645Ssimokawastruct fw_bulkxfer{
211113584Ssimokawa	int poffset;
212111942Ssimokawa	struct mbuf *mbuf;
213109645Ssimokawa	STAILQ_ENTRY(fw_bulkxfer) link;
214109645Ssimokawa	caddr_t start;
215109645Ssimokawa	caddr_t end;
216111942Ssimokawa	int resp;
217109645Ssimokawa};
218109645Ssimokawa
219109645Ssimokawastruct tlabel{
220109645Ssimokawa	struct fw_xfer  *xfer;
221109645Ssimokawa	STAILQ_ENTRY(tlabel) link;
222109645Ssimokawa};
223109645Ssimokawa
224109645Ssimokawastruct fw_bind{
225109645Ssimokawa	u_int32_t start_hi, start_lo, addrlen;
226113584Ssimokawa	STAILQ_HEAD(, fw_xfer) xferlist;
227109645Ssimokawa	STAILQ_ENTRY(fw_bind) fclist;
228109645Ssimokawa	STAILQ_ENTRY(fw_bind) chlist;
229113584Ssimokawa#define FWACT_NULL	0
230113584Ssimokawa#define FWACT_XFER	2
231113584Ssimokawa#define FWACT_CH	3
232113584Ssimokawa	u_int8_t act_type;
233113584Ssimokawa	u_int8_t sub;
234109645Ssimokawa};
235109645Ssimokawa
236103285Sikobstruct fw_xfer{
237103285Sikob	caddr_t sc;
238103285Sikob	struct firewire_comm *fc;
239103285Sikob	struct fw_xferq *q;
240110577Ssimokawa	struct timeval tv;
241113584Ssimokawa	/* XXX should be removed */
242113584Ssimokawa	u_int32_t dst; /* XXX for if_fwe */
243103285Sikob	u_int8_t spd;
244113584Ssimokawa	int8_t resp;
245103285Sikob#define FWXF_INIT 0
246103285Sikob#define FWXF_INQ 1
247103285Sikob#define FWXF_START 2
248103285Sikob#define FWXF_SENT 3
249103285Sikob#define FWXF_SENTERR 4
250103285Sikob#define FWXF_BUSY 8
251103285Sikob#define FWXF_RCVD 10
252113584Ssimokawa	u_int8_t state;
253103285Sikob	u_int8_t retry;
254103285Sikob	u_int8_t tl;
255103285Sikob	void (*retry_req) __P((struct fw_xfer *));
256103285Sikob	union{
257103285Sikob		void (*hand) __P((struct fw_xfer *));
258103285Sikob	} act;
259103285Sikob	struct {
260113584Ssimokawa		int len;
261103285Sikob		caddr_t buf;
262103285Sikob	} send, recv;
263103285Sikob	struct mbuf *mbuf;
264103285Sikob	STAILQ_ENTRY(fw_xfer) link;
265110269Ssimokawa	struct malloc_type *malloc;
266103285Sikob};
267113584Ssimokawavoid fw_sidrcv __P((struct firewire_comm *, u_int32_t *, u_int));
268113584Ssimokawavoid fw_rcv __P((struct firewire_comm *, struct iovec *, int, u_int, u_int));
269113584Ssimokawavoid fw_xfer_unload __P(( struct fw_xfer*));
270103285Sikobvoid fw_xfer_free __P(( struct fw_xfer*));
271110269Ssimokawastruct fw_xfer *fw_xfer_alloc __P((struct malloc_type *));
272113584Ssimokawastruct fw_xfer *fw_xfer_alloc_buf __P((struct malloc_type *, int, int));
273103285Sikobvoid fw_init __P((struct firewire_comm *));
274103285Sikobint fw_tbuf_update __P((struct firewire_comm *, int, int));
275103285Sikobint fw_rbuf_update __P((struct firewire_comm *, int, int));
276103285Sikobu_int32_t getcsrdata __P((struct fw_device *, u_int8_t));
277103285Sikobvoid fw_asybusy __P((struct fw_xfer *));
278103285Sikobint fw_bindadd __P((struct firewire_comm *, struct fw_bind *));
279103285Sikobint fw_bindremove __P((struct firewire_comm *, struct fw_bind *));
280103285Sikobint fw_asyreq __P((struct firewire_comm *, int, struct fw_xfer*));
281103285Sikobvoid fw_busreset __P((struct firewire_comm *));
282103285Sikobu_int16_t fw_crc16 __P((u_int32_t *, u_int32_t));
283103285Sikobvoid fw_xfer_timeout __P((void *));
284103285Sikobvoid fw_xfer_done __P((struct fw_xfer *));
285103285Sikobvoid fw_asy_callback __P((struct fw_xfer *));
286110072Ssimokawastruct fw_device *fw_noderesolve_nodeid __P((struct firewire_comm *, int));
287110582Ssimokawastruct fw_device *fw_noderesolve_eui64 __P((struct firewire_comm *, struct fw_eui64 *));
288106813Ssimokawastruct fw_bind *fw_bindlookup __P((struct firewire_comm *, u_int32_t, u_int32_t));
289110798Ssimokawavoid fw_drain_txq __P((struct firewire_comm *));
290103285Sikob
291106813Ssimokawa
292103285Sikobextern int firewire_debug;
293103285Sikobextern devclass_t firewire_devclass;
294103285Sikob
295103285Sikob#define DV_BROADCAST_ON (1<<30)
296103285Sikob#define		IP_CHANNELS	0x0234
297103285Sikob
298103285Sikob#define		STATE_CLEAR	0x0000
299103285Sikob#define		STATE_SET	0x0004
300103285Sikob#define		NODE_IDS	0x0008
301103285Sikob#define		RESET_START	0x000c
302103285Sikob#define		SPLIT_TIMEOUT_HI	0x0018
303103285Sikob#define		SPLIT_TIMEOUT_LO	0x001c
304103285Sikob#define		CYCLE_TIME	0x0200
305110129Ssimokawa#define		BUS_TIME	0x0204
306110129Ssimokawa#define		BUSY_TIMEOUT	0x0210
307103285Sikob#define		BUS_MGR_ID	0x021c
308103285Sikob#define		BANDWIDTH_AV	0x0220
309103285Sikob#define		CHANNELS_AV_HI	0x0224
310103285Sikob#define		CHANNELS_AV_LO	0x0228
311103285Sikob
312103285Sikob#define		CONF_ROM	0x0400
313103285Sikob
314103285Sikob#define		TOPO_MAP	0x1000
315103285Sikob#define		SPED_MAP	0x2000
316103285Sikob
317103285Sikob#define		oMPR		0x900
318103285Sikob#define		oPCR		0x904
319103285Sikob
320103285Sikob#define		iMPR		0x980
321103285Sikob#define		iPCR		0x984
322103285Sikob
323103285Sikob#define		FWPRI		((PZERO+8)|PCATCH)
324103285Sikob
325111615Ssimokawa#if __FreeBSD_version >= 500000
326111615Ssimokawa#define CALLOUT_INIT(x) callout_init(x, 0 /* mpsafe */)
327111615Ssimokawa#else
328111615Ssimokawa#define CALLOUT_INIT(x) callout_init(x)
329111615Ssimokawa#endif
330111615Ssimokawa
331110195SsimokawaMALLOC_DECLARE(M_FW);
332110269SsimokawaMALLOC_DECLARE(M_FWXFER);
333