xref: /netbsd/sys/dev/ieee1394/fwohcivar.h (revision bf9ec67e)
1 /*	$NetBSD: fwohcivar.h,v 1.17 2002/01/16 01:47:37 eeh Exp $	*/
2 
3 /*-
4  * Copyright (c) 2000 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Matt Thomas of the 3am Software Foundry.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *        This product includes software developed by the NetBSD
21  *        Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 #ifndef _DEV_IEEE1394_FWOHCIVAR_H_
40 #define	_DEV_IEEE1394_FWOHCIVAR_H_
41 
42 #include <sys/mbuf.h>
43 #include <sys/callout.h>
44 #include <sys/queue.h>
45 
46 #include <machine/bus.h>
47 
48 #define	OHCI_PAGE_SIZE		0x0800
49 #define	OHCI_BUF_ARRQ_CNT	16
50 #define	OHCI_BUF_ARRS_CNT	8
51 #define	OHCI_BUF_ATRQ_CNT	(8*8)
52 #define	OHCI_BUF_ATRS_CNT	(8*8)
53 #define	OHCI_BUF_IR_CNT		8
54 #define	OHCI_BUF_CNT							\
55 	(OHCI_BUF_ARRQ_CNT + OHCI_BUF_ARRS_CNT + OHCI_BUF_ATRQ_CNT +	\
56 	    OHCI_BUF_ATRS_CNT + OHCI_BUF_IR_CNT + 1 + 1)
57 
58 #define	OHCI_LOOP		1000
59 #define	OHCI_SELFID_TIMEOUT	(hz * 3)
60 #define OHCI_ASYNC_STREAM	0x40
61 
62 struct fwohci_softc;
63 struct fwohci_pkt;
64 
65 struct fwohci_buf {
66 	TAILQ_ENTRY(fwohci_buf) fb_list;
67 	bus_dma_segment_t fb_seg;
68 	int fb_nseg;
69 	bus_dmamap_t fb_dmamap;		/* DMA map of the buffer */
70 	caddr_t fb_buf;			/* kernel virtual addr of the buffer */
71 	struct fwohci_desc *fb_desc;	/* kernel virtual addr of descriptor */
72 	bus_addr_t fb_daddr;		/* physical addr of the descriptor */
73 	int fb_off;
74 	struct mbuf *fb_m;
75 	void *fb_statusarg;
76 	void (*fb_callback)(struct device *, struct mbuf *);
77 	int (*fb_statuscb)(struct fwohci_softc *, void *, struct fwohci_pkt *);
78 };
79 
80 struct fwohci_pkt {
81 	int	fp_tcode;
82 	int	fp_hlen;
83 	int	fp_dlen;
84 	u_int32_t fp_hdr[4];
85 	struct uio fp_uio;
86 	struct iovec fp_iov[6];
87 	u_int32_t *fp_trail;
88 	struct mbuf *fp_m;
89 	u_int16_t fp_status;
90 	void *fp_statusarg;
91 	int (*fp_statuscb)(struct fwohci_softc *, void *, struct fwohci_pkt *);
92 	void (*fp_callback)(struct device *, struct mbuf *);
93 };
94 
95 struct fwohci_handler {
96 	LIST_ENTRY(fwohci_handler) fh_list;
97 	u_int32_t	fh_tcode;	/* ARRQ   / ARRS   / IR   */
98 	u_int32_t	fh_key1;	/* addrhi / srcid  / chan */
99 	u_int32_t	fh_key2;	/* addrlo / tlabel / tag  */
100 	int		(*fh_handler)(struct fwohci_softc *, void *,
101 	    struct fwohci_pkt *);
102 	void		*fh_handarg;
103 };
104 
105 struct fwohci_ctx {
106 	int	fc_ctx;
107 	int	fc_type;	/* FWOHCI_CTX_(ASYNC|ISO_SINGLE|ISO_MULTI) */
108 	int	fc_bufcnt;
109 	u_int32_t	*fc_branch;
110 	TAILQ_HEAD(fwohci_buf_s, fwohci_buf) fc_buf;
111 	struct fwohci_buf_s fc_buf2; /* for iso */
112 	LIST_HEAD(, fwohci_handler) fc_handler;
113 	struct fwohci_buf *fc_buffers;
114 };
115 
116 struct fwohci_uidtbl {
117 	int		fu_valid;
118 	u_int8_t	fu_uid[8];
119 };
120 
121 /*
122  * Needed to keep track of outstanding packets during a read op. Since the
123  * packet stream is asynch it's possible to parse a response packet before the
124  * ack bits are processed. In this case something needs to track whether the
125  * abuf is still valid before possibly attempting to use items from within it.
126  */
127 
128 struct fwohci_cb {
129 	struct ieee1394_abuf *ab;
130 	int count;
131 	int abuf_valid;
132 };
133 
134 struct fwohci_softc {
135 	struct ieee1394_softc sc_sc1394;
136 	struct evcnt sc_intrcnt;
137 	struct evcnt sc_isocnt;
138 	struct evcnt sc_isopktcnt;
139 
140 	bus_space_tag_t sc_memt;
141 	bus_space_handle_t sc_memh;
142 	bus_dma_tag_t sc_dmat;
143 	bus_size_t sc_memsize;
144 #if 0
145 
146 /* Mandatory structures to get the link enabled
147  */
148 	bus_dmamap_t sc_configrom_map;
149 	bus_dmamap_t sc_selfid_map;
150 	u_int32_t *sc_selfid_buf;
151 	u_int32_t *sc_configrom;
152 #endif
153 
154 	bus_dma_segment_t sc_dseg;
155 	int sc_dnseg;
156 	bus_dmamap_t sc_ddmamap;
157 	struct fwohci_desc *sc_desc;
158 	u_int8_t *sc_descmap;
159 	int sc_descsize;
160 	int sc_isoctx;
161 
162 	void *sc_shutdownhook;
163 	void *sc_powerhook;
164 	struct callout sc_selfid_callout;
165 	int sc_selfid_fail;
166 
167 	struct fwohci_ctx *sc_ctx_arrq;
168 	struct fwohci_ctx *sc_ctx_arrs;
169 	struct fwohci_ctx *sc_ctx_atrq;
170 	struct fwohci_ctx *sc_ctx_atrs;
171 	struct fwohci_ctx **sc_ctx_ir;
172 	struct fwohci_buf sc_buf_cnfrom;
173 	struct fwohci_buf sc_buf_selfid;
174 
175 	struct proc *sc_event_thread;
176 
177 	int sc_dying;
178 	u_int32_t sc_intmask;
179 	u_int32_t sc_iso;
180 
181 	u_int8_t sc_csr[CSR_SB_END];
182 
183 	struct fwohci_uidtbl *sc_uidtbl;
184 	u_int16_t sc_nodeid;			/* Full Node ID of this node */
185 	u_int8_t sc_rootid;			/* Phy ID of Root */
186 	u_int8_t sc_irmid;			/* Phy ID of IRM */
187 	u_int8_t sc_tlabel;			/* Transaction Label */
188 
189 	LIST_HEAD(, ieee1394_softc) sc_nodelist;
190 };
191 
192 int fwohci_init (struct fwohci_softc *, const struct evcnt *);
193 int fwohci_intr (void *);
194 int fwohci_print (void *, const char *);
195 int fwohci_detach(struct fwohci_softc *, int);
196 int fwohci_activate(struct device *, enum devact);
197 
198 /* Macros to read and write the OHCI registers
199  */
200 #define	OHCI_CSR_WRITE(sc, reg, val) \
201 	bus_space_write_4((sc)->sc_memt, (sc)->sc_memh, reg, htole32(val))
202 #define	OHCI_CSR_READ(sc, reg) \
203 	le32toh(bus_space_read_4((sc)->sc_memt, (sc)->sc_memh, reg))
204 
205 #define FWOHCI_CTX_ASYNC	0
206 #define FWOHCI_CTX_ISO_SINGLE	1	/* for async stream */
207 #define FWOHCI_CTX_ISO_MULTI	2	/* for isochronous */
208 
209 /* Locators. */
210 
211 #include "locators.h"
212 
213 #define fwbuscf_idhi cf_loc[FWBUSCF_IDHI]
214 #define FWBUS_UNK_IDHI FWBUSCF_IDHI_DEFAULT
215 
216 #define fwbuscf_idlo cf_loc[FWBUSCF_IDLO]
217 #define FWBUS_UNK_IDLO FWBUSCF_IDLO_DEFAULT
218 
219 #endif	/* _DEV_IEEE1394_FWOHCIVAR_H_ */
220