firewirereg.h revision 116376
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 116376 2003-06-15 04:09:26Z 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;
146116376Ssimokawa	struct crom_src_buf *crom_src_buf;
147116376Ssimokawa	struct crom_src *crom_src;
148116376Ssimokawa	struct crom_chunk *crom_root;
149103285Sikob	struct fw_topology_map *topology_map;
150103285Sikob	struct fw_speed_map *speed_map;
151108853Ssimokawa	struct callout busprobe_callout;
152110193Ssimokawa	struct callout bmr_callout;
153110193Ssimokawa	struct callout timeout_callout;
154110193Ssimokawa	struct callout retry_probe_callout;
155103285Sikob	u_int32_t (*cyctimer) __P((struct  firewire_comm *));
156103285Sikob	void (*ibr) __P((struct firewire_comm *));
157103285Sikob	u_int32_t (*set_bmr) __P((struct firewire_comm *, u_int32_t));
158103285Sikob	int (*ioctl) __P((dev_t, u_long, caddr_t, int, fw_proc *));
159103285Sikob	int (*irx_enable) __P((struct firewire_comm *, int));
160103285Sikob	int (*irx_disable) __P((struct firewire_comm *, int));
161103285Sikob	int (*itx_enable) __P((struct firewire_comm *, int));
162103285Sikob	int (*itx_disable) __P((struct firewire_comm *, int));
163103285Sikob	void (*timeout) __P((void *));
164103285Sikob	void (*poll) __P((struct firewire_comm *, int, int));
165103285Sikob	void (*set_intr) __P((struct firewire_comm *, int));
166103285Sikob	void (*irx_post) __P((struct firewire_comm *, u_int32_t *));
167103285Sikob	void (*itx_post) __P((struct firewire_comm *, u_int32_t *));
168103285Sikob	struct tcode_info *tcode;
169113584Ssimokawa	bus_dma_tag_t dmat;
170103285Sikob};
171103285Sikob#define CSRARC(sc, offset) ((sc)->csr_arc[(offset)/4])
172103285Sikob
173109645Ssimokawastruct csrdir{
174109645Ssimokawa	u_int32_t ongoaddr;
175109645Ssimokawa	u_int32_t off;
176109645Ssimokawa	SLIST_ENTRY(csrdir) link;
177109645Ssimokawa};
178103285Sikob
179109645Ssimokawastruct fw_xferq {
180109645Ssimokawa	int flag;
181109645Ssimokawa#define FWXFERQ_CHTAGMASK 0xff
182109645Ssimokawa#define FWXFERQ_RUNNING (1 << 8)
183109645Ssimokawa#define FWXFERQ_STREAM (1 << 9)
184109645Ssimokawa
185109645Ssimokawa#define FWXFERQ_BULK (1 << 11)
186109645Ssimokawa#define FWXFERQ_MODEMASK (7 << 10)
187109645Ssimokawa
188109645Ssimokawa#define FWXFERQ_EXTBUF (1 << 13)
189109645Ssimokawa#define FWXFERQ_OPEN (1 << 14)
190109645Ssimokawa
191109645Ssimokawa#define FWXFERQ_HANDLER (1 << 16)
192109645Ssimokawa#define FWXFERQ_WAKEUP (1 << 17)
193109645Ssimokawa
194109645Ssimokawa	void (*start) __P((struct firewire_comm*));
195113584Ssimokawa	STAILQ_HEAD(, fw_xfer) q;
196109645Ssimokawa	u_int queued;
197109645Ssimokawa	u_int maxq;
198109645Ssimokawa	u_int psize;
199109645Ssimokawa	STAILQ_HEAD(, fw_bind) binds;
200113584Ssimokawa	struct fwdma_alloc_multi *buf;
201109645Ssimokawa	u_int bnchunk;
202109645Ssimokawa	u_int bnpacket;
203109645Ssimokawa	struct fw_bulkxfer *bulkxfer;
204109645Ssimokawa	STAILQ_HEAD(, fw_bulkxfer) stvalid;
205109645Ssimokawa	STAILQ_HEAD(, fw_bulkxfer) stfree;
206109890Ssimokawa	STAILQ_HEAD(, fw_bulkxfer) stdma;
207109645Ssimokawa	struct fw_bulkxfer *stproc;
208109645Ssimokawa	struct selinfo rsel;
209109645Ssimokawa	caddr_t sc;
210109645Ssimokawa	void (*hand) __P((struct fw_xferq *));
211109645Ssimokawa};
212109645Ssimokawa
213109645Ssimokawastruct fw_bulkxfer{
214113584Ssimokawa	int poffset;
215111942Ssimokawa	struct mbuf *mbuf;
216109645Ssimokawa	STAILQ_ENTRY(fw_bulkxfer) link;
217109645Ssimokawa	caddr_t start;
218109645Ssimokawa	caddr_t end;
219111942Ssimokawa	int resp;
220109645Ssimokawa};
221109645Ssimokawa
222109645Ssimokawastruct tlabel{
223109645Ssimokawa	struct fw_xfer  *xfer;
224109645Ssimokawa	STAILQ_ENTRY(tlabel) link;
225109645Ssimokawa};
226109645Ssimokawa
227109645Ssimokawastruct fw_bind{
228109645Ssimokawa	u_int32_t start_hi, start_lo, addrlen;
229113584Ssimokawa	STAILQ_HEAD(, fw_xfer) xferlist;
230109645Ssimokawa	STAILQ_ENTRY(fw_bind) fclist;
231109645Ssimokawa	STAILQ_ENTRY(fw_bind) chlist;
232113584Ssimokawa#define FWACT_NULL	0
233113584Ssimokawa#define FWACT_XFER	2
234113584Ssimokawa#define FWACT_CH	3
235113584Ssimokawa	u_int8_t act_type;
236113584Ssimokawa	u_int8_t sub;
237109645Ssimokawa};
238109645Ssimokawa
239103285Sikobstruct fw_xfer{
240103285Sikob	caddr_t sc;
241103285Sikob	struct firewire_comm *fc;
242103285Sikob	struct fw_xferq *q;
243110577Ssimokawa	struct timeval tv;
244113584Ssimokawa	/* XXX should be removed */
245113584Ssimokawa	u_int32_t dst; /* XXX for if_fwe */
246103285Sikob	u_int8_t spd;
247113584Ssimokawa	int8_t resp;
248103285Sikob#define FWXF_INIT 0
249103285Sikob#define FWXF_INQ 1
250103285Sikob#define FWXF_START 2
251103285Sikob#define FWXF_SENT 3
252103285Sikob#define FWXF_SENTERR 4
253103285Sikob#define FWXF_BUSY 8
254103285Sikob#define FWXF_RCVD 10
255113584Ssimokawa	u_int8_t state;
256103285Sikob	u_int8_t retry;
257103285Sikob	u_int8_t tl;
258103285Sikob	void (*retry_req) __P((struct fw_xfer *));
259103285Sikob	union{
260103285Sikob		void (*hand) __P((struct fw_xfer *));
261103285Sikob	} act;
262103285Sikob	struct {
263113584Ssimokawa		int len;
264103285Sikob		caddr_t buf;
265103285Sikob	} send, recv;
266103285Sikob	struct mbuf *mbuf;
267103285Sikob	STAILQ_ENTRY(fw_xfer) link;
268110269Ssimokawa	struct malloc_type *malloc;
269103285Sikob};
270113584Ssimokawavoid fw_sidrcv __P((struct firewire_comm *, u_int32_t *, u_int));
271113584Ssimokawavoid fw_rcv __P((struct firewire_comm *, struct iovec *, int, u_int, u_int));
272113584Ssimokawavoid fw_xfer_unload __P(( struct fw_xfer*));
273103285Sikobvoid fw_xfer_free __P(( struct fw_xfer*));
274110269Ssimokawastruct fw_xfer *fw_xfer_alloc __P((struct malloc_type *));
275113584Ssimokawastruct fw_xfer *fw_xfer_alloc_buf __P((struct malloc_type *, int, int));
276103285Sikobvoid fw_init __P((struct firewire_comm *));
277103285Sikobint fw_tbuf_update __P((struct firewire_comm *, int, int));
278103285Sikobint fw_rbuf_update __P((struct firewire_comm *, int, int));
279103285Sikobvoid fw_asybusy __P((struct fw_xfer *));
280103285Sikobint fw_bindadd __P((struct firewire_comm *, struct fw_bind *));
281103285Sikobint fw_bindremove __P((struct firewire_comm *, struct fw_bind *));
282103285Sikobint fw_asyreq __P((struct firewire_comm *, int, struct fw_xfer*));
283103285Sikobvoid fw_busreset __P((struct firewire_comm *));
284103285Sikobu_int16_t fw_crc16 __P((u_int32_t *, u_int32_t));
285103285Sikobvoid fw_xfer_timeout __P((void *));
286103285Sikobvoid fw_xfer_done __P((struct fw_xfer *));
287103285Sikobvoid fw_asy_callback __P((struct fw_xfer *));
288110072Ssimokawastruct fw_device *fw_noderesolve_nodeid __P((struct firewire_comm *, int));
289110582Ssimokawastruct fw_device *fw_noderesolve_eui64 __P((struct firewire_comm *, struct fw_eui64 *));
290106813Ssimokawastruct fw_bind *fw_bindlookup __P((struct firewire_comm *, u_int32_t, u_int32_t));
291110798Ssimokawavoid fw_drain_txq __P((struct firewire_comm *));
292103285Sikob
293106813Ssimokawa
294103285Sikobextern int firewire_debug;
295103285Sikobextern devclass_t firewire_devclass;
296103285Sikob
297103285Sikob#define		FWPRI		((PZERO+8)|PCATCH)
298103285Sikob
299111615Ssimokawa#if __FreeBSD_version >= 500000
300111615Ssimokawa#define CALLOUT_INIT(x) callout_init(x, 0 /* mpsafe */)
301111615Ssimokawa#else
302111615Ssimokawa#define CALLOUT_INIT(x) callout_init(x)
303111615Ssimokawa#endif
304111615Ssimokawa
305110195SsimokawaMALLOC_DECLARE(M_FW);
306110269SsimokawaMALLOC_DECLARE(M_FWXFER);
307