fwohcivar.h revision 1.19 1 1.19 haya /* $NetBSD: fwohcivar.h,v 1.19 2002/12/04 00:28:41 haya Exp $ */
2 1.7 enami
3 1.1 matt /*-
4 1.1 matt * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 1.1 matt * All rights reserved.
6 1.1 matt *
7 1.1 matt * This code is derived from software contributed to The NetBSD Foundation
8 1.1 matt * by Matt Thomas of the 3am Software Foundry.
9 1.1 matt *
10 1.1 matt * Redistribution and use in source and binary forms, with or without
11 1.1 matt * modification, are permitted provided that the following conditions
12 1.1 matt * are met:
13 1.1 matt * 1. Redistributions of source code must retain the above copyright
14 1.1 matt * notice, this list of conditions and the following disclaimer.
15 1.1 matt * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 matt * notice, this list of conditions and the following disclaimer in the
17 1.1 matt * documentation and/or other materials provided with the distribution.
18 1.1 matt * 3. All advertising materials mentioning features or use of this software
19 1.1 matt * must display the following acknowledgement:
20 1.1 matt * This product includes software developed by the NetBSD
21 1.1 matt * Foundation, Inc. and its contributors.
22 1.1 matt * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 matt * contributors may be used to endorse or promote products derived
24 1.1 matt * from this software without specific prior written permission.
25 1.1 matt *
26 1.1 matt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 matt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 matt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 matt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 matt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 matt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 matt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 matt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 matt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 matt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 matt * POSSIBILITY OF SUCH DAMAGE.
37 1.1 matt */
38 1.1 matt
39 1.1 matt #ifndef _DEV_IEEE1394_FWOHCIVAR_H_
40 1.1 matt #define _DEV_IEEE1394_FWOHCIVAR_H_
41 1.1 matt
42 1.4 onoe #include <sys/callout.h>
43 1.4 onoe #include <sys/queue.h>
44 1.4 onoe
45 1.4 onoe #include <machine/bus.h>
46 1.2 onoe
47 1.2 onoe #define OHCI_PAGE_SIZE 0x0800
48 1.2 onoe #define OHCI_BUF_ARRQ_CNT 16
49 1.2 onoe #define OHCI_BUF_ARRS_CNT 8
50 1.2 onoe #define OHCI_BUF_ATRQ_CNT (8*8)
51 1.2 onoe #define OHCI_BUF_ATRS_CNT (8*8)
52 1.15 haya #define OHCI_BUF_IR_CNT 8
53 1.10 enami #define OHCI_BUF_CNT \
54 1.10 enami (OHCI_BUF_ARRQ_CNT + OHCI_BUF_ARRS_CNT + OHCI_BUF_ATRQ_CNT + \
55 1.10 enami OHCI_BUF_ATRS_CNT + OHCI_BUF_IR_CNT + 1 + 1)
56 1.2 onoe
57 1.2 onoe #define OHCI_LOOP 1000
58 1.4 onoe #define OHCI_SELFID_TIMEOUT (hz * 3)
59 1.19 haya #define OHCI_ASYNC_STREAM 0x100
60 1.2 onoe
61 1.2 onoe struct fwohci_softc;
62 1.12 jmc struct fwohci_pkt;
63 1.18 itojun struct mbuf;
64 1.2 onoe
65 1.2 onoe struct fwohci_buf {
66 1.2 onoe TAILQ_ENTRY(fwohci_buf) fb_list;
67 1.2 onoe bus_dma_segment_t fb_seg;
68 1.2 onoe int fb_nseg;
69 1.15 haya bus_dmamap_t fb_dmamap; /* DMA map of the buffer */
70 1.15 haya caddr_t fb_buf; /* kernel virtual addr of the buffer */
71 1.15 haya struct fwohci_desc *fb_desc; /* kernel virtual addr of descriptor */
72 1.15 haya bus_addr_t fb_daddr; /* physical addr of the descriptor */
73 1.2 onoe int fb_off;
74 1.2 onoe struct mbuf *fb_m;
75 1.12 jmc void *fb_statusarg;
76 1.2 onoe void (*fb_callback)(struct device *, struct mbuf *);
77 1.12 jmc int (*fb_statuscb)(struct fwohci_softc *, void *, struct fwohci_pkt *);
78 1.2 onoe };
79 1.2 onoe
80 1.2 onoe struct fwohci_pkt {
81 1.2 onoe int fp_tcode;
82 1.2 onoe int fp_hlen;
83 1.2 onoe int fp_dlen;
84 1.2 onoe u_int32_t fp_hdr[4];
85 1.6 onoe struct uio fp_uio;
86 1.6 onoe struct iovec fp_iov[6];
87 1.2 onoe u_int32_t *fp_trail;
88 1.10 enami struct mbuf *fp_m;
89 1.12 jmc u_int16_t fp_status;
90 1.12 jmc void *fp_statusarg;
91 1.12 jmc int (*fp_statuscb)(struct fwohci_softc *, void *, struct fwohci_pkt *);
92 1.2 onoe void (*fp_callback)(struct device *, struct mbuf *);
93 1.2 onoe };
94 1.2 onoe
95 1.2 onoe struct fwohci_handler {
96 1.2 onoe LIST_ENTRY(fwohci_handler) fh_list;
97 1.2 onoe u_int32_t fh_tcode; /* ARRQ / ARRS / IR */
98 1.2 onoe u_int32_t fh_key1; /* addrhi / srcid / chan */
99 1.2 onoe u_int32_t fh_key2; /* addrlo / tlabel / tag */
100 1.2 onoe int (*fh_handler)(struct fwohci_softc *, void *,
101 1.11 jmc struct fwohci_pkt *);
102 1.2 onoe void *fh_handarg;
103 1.2 onoe };
104 1.2 onoe
105 1.2 onoe struct fwohci_ctx {
106 1.2 onoe int fc_ctx;
107 1.15 haya int fc_type; /* FWOHCI_CTX_(ASYNC|ISO_SINGLE|ISO_MULTI) */
108 1.2 onoe int fc_bufcnt;
109 1.2 onoe u_int32_t *fc_branch;
110 1.6 onoe TAILQ_HEAD(fwohci_buf_s, fwohci_buf) fc_buf;
111 1.15 haya struct fwohci_buf_s fc_buf2; /* for iso */
112 1.2 onoe LIST_HEAD(, fwohci_handler) fc_handler;
113 1.17 eeh struct fwohci_buf *fc_buffers;
114 1.2 onoe };
115 1.2 onoe
116 1.19 haya
117 1.19 haya
118 1.19 haya struct fwohci_ir_ctx {
119 1.19 haya struct fwohci_softc *irc_sc;
120 1.19 haya
121 1.19 haya int irc_num; /* context number */
122 1.19 haya int irc_flags; /* IEEE1394_IR_* */
123 1.19 haya int irc_status;
124 1.19 haya #define IRC_STATUS_READY 0x0001
125 1.19 haya #define IRC_STATUS_RUN 0x0002
126 1.19 haya #define IRC_STATUS_SLEEPING 0x0004
127 1.19 haya #define IRC_STATUS_RECEIVE 0x0008
128 1.19 haya
129 1.19 haya int irc_pktcount;
130 1.19 haya
131 1.19 haya int irc_channel; /* channel number */
132 1.19 haya int irc_tagbm; /* tag bitmap */
133 1.19 haya int irc_maxsize; /* maxmum data size for a packet */
134 1.19 haya
135 1.19 haya int irc_maxqueuelen; /* for debug purpose */
136 1.19 haya int irc_maxqueuepos;
137 1.19 haya
138 1.19 haya struct fwohci_desc *irc_readtop; /* where data start */
139 1.19 haya struct fwohci_desc *irc_writeend; /* where branch addr is 0 */
140 1.19 haya u_int32_t irc_savedbranch;
141 1.19 haya
142 1.19 haya struct fwohci_iso_buf *irc_buf_ptr;
143 1.19 haya
144 1.19 haya /* data for descriptor */
145 1.19 haya bus_dma_segment_t irc_desc_seg;
146 1.19 haya bus_dmamap_t irc_desc_dmamap;
147 1.19 haya int irc_desc_num; /* number of descriptors */
148 1.19 haya int irc_desc_size; /* actual size in byte */
149 1.19 haya struct fwohci_desc *irc_desc_map; /* Do not change */
150 1.19 haya int irc_desc_nsegs;
151 1.19 haya
152 1.19 haya volatile void *irc_waitchan; /* wait channel */
153 1.19 haya struct selinfo irc_sel;
154 1.19 haya
155 1.19 haya /* data for buffer */
156 1.19 haya bus_dma_segment_t irc_buf_segs[16];
157 1.19 haya bus_dmamap_t irc_buf_dmamap;
158 1.19 haya int irc_buf_totalsize;
159 1.19 haya int irc_buf_nsegs;
160 1.19 haya u_int8_t *irc_buf;
161 1.19 haya
162 1.19 haya /* for debug purpose */
163 1.19 haya #ifdef FWOHCI_WAIT_DEBUG
164 1.19 haya u_int16_t irc_cycle[3]; /* 0 for wait time, 1 for intr time */
165 1.19 haya #endif
166 1.19 haya };
167 1.19 haya
168 1.19 haya
169 1.19 haya
170 1.19 haya /*
171 1.19 haya * Context dedicated for isochronous transmit. Two data structure are
172 1.19 haya * defined.
173 1.19 haya */
174 1.19 haya struct fwohci_it_ctx;
175 1.19 haya
176 1.19 haya #define IEEE1394_IT_PKTHDR 0x0001
177 1.19 haya
178 1.19 haya struct fwohci_it_dmabuf {
179 1.19 haya struct fwohci_it_ctx *itd_ctx;
180 1.19 haya int itd_num;
181 1.19 haya int itd_flags;
182 1.19 haya #define ITD_FLAGS_LOCK 0x0001
183 1.19 haya #define ITD_FLAGS_UNLOCK 0x0000
184 1.19 haya #define ITD_FLAGS_LOCK_MASK 0x0001
185 1.19 haya
186 1.19 haya /* memory for descriptor */
187 1.19 haya struct fwohci_desc *itd_desc; /* top of descriptor */
188 1.19 haya bus_addr_t itd_desc_phys; /* physical addr of 1st descriptor */
189 1.19 haya int itd_descsize; /* number of total descriptors */
190 1.19 haya struct fwohci_desc *itd_lastdesc; /* last valid descriptor */
191 1.19 haya
192 1.19 haya int itd_maxpacket; /* maximum packets for the buffer */
193 1.19 haya int itd_npacket; /* number of valid packets */
194 1.19 haya int itd_maxsize; /* maximum packet size */
195 1.19 haya
196 1.19 haya /* DMA buffer */
197 1.19 haya #define FWOHCI_MAX_ITDATASEG 8
198 1.19 haya bus_dma_segment_t itd_seg[FWOHCI_MAX_ITDATASEG];
199 1.19 haya bus_dmamap_t itd_dmamap;
200 1.19 haya int itd_size; /* count in byte */
201 1.19 haya u_int8_t *itd_buf;
202 1.19 haya int itd_nsegs;
203 1.19 haya
204 1.19 haya /* header store descriptor */
205 1.19 haya struct fwohci_desc *itd_store;
206 1.19 haya bus_addr_t itd_store_phys;
207 1.19 haya
208 1.19 haya u_int32_t itd_savedbranch;
209 1.19 haya
210 1.19 haya #if 0
211 1.19 haya int fwohci_itd_construct(struct fwohci_it_ctx *, struct fwohci_it_dmabuf *, int no, struct fwohci_desc *desc, int descsize, int maxsize, paddr_t scratch);
212 1.19 haya void fwohci_itd_destruct(struct fwohci_it_dmabuf *);
213 1.19 haya int fwohci_itd_writedata(struct fwohci_it_dmabuf *, int ndata,
214 1.19 haya struct ieee1394_it_datalist *);
215 1.19 haya int fwohci_itd_link(struct fwohci_it_dmabuf *, struct fwohci_it_dmabuf *);
216 1.19 haya bus_addr_t fwohci_itd_list_head(struct fwohci_it_dmabuf *);
217 1.19 haya void fwohci_itd_clean(struct fwohci_it_dmabuf *);
218 1.19 haya int fwohci_itd_isfilled(struct fwohci_it_dmabuf *);
219 1.19 haya int fwohci_itd_hasdata(struct fwohci_it_dmabuf *);
220 1.19 haya int fwohci_itd_isfull(struct fwohci_it_dmabuf *);
221 1.19 haya #endif
222 1.19 haya #define fwohci_itd_list_head(itd) (itd)->itd_desc_phys
223 1.19 haya #define fwohci_itd_hasdata(itd) (itd)->itd_npacket
224 1.19 haya #define fwohci_itd_isfull(itd) \
225 1.19 haya ((itd)->itd_npacket == (itd)->itd_maxpacket)
226 1.19 haya #define fwohci_itd_islocked(itd) \
227 1.19 haya ((itd)->itd_flags & ITD_FLAGS_LOCK)
228 1.19 haya };
229 1.19 haya
230 1.19 haya
231 1.19 haya struct fwohci_it_ctx {
232 1.19 haya struct fwohci_softc *itc_sc;
233 1.19 haya
234 1.19 haya int itc_num; /* context number */
235 1.19 haya
236 1.19 haya volatile int itc_flags; /* flags */
237 1.19 haya #define ITC_FLAGS_RUN 0x0001
238 1.19 haya
239 1.19 haya int itc_channel; /* channel number */
240 1.19 haya int itc_tag; /* tag */
241 1.19 haya int itc_maxsize; /* maxmum data size for a packet */
242 1.19 haya int itc_speed; /* speed */
243 1.19 haya
244 1.19 haya struct fwohci_it_dmabuf *itc_buf; /* array for fwohci_it_dmabuf */
245 1.19 haya int itc_bufnum; /* const: num of elements in itc_buf array */
246 1.19 haya
247 1.19 haya #if 1
248 1.19 haya volatile struct fwohci_it_dmabuf *itc_buf_start;
249 1.19 haya struct fwohci_it_dmabuf *itc_buf_end;
250 1.19 haya struct fwohci_it_dmabuf *itc_buf_linkend;
251 1.19 haya #endif
252 1.19 haya volatile int16_t itc_buf_cnt; /* # buffers which contain data */
253 1.19 haya #if 0
254 1.19 haya int16_t itc_bufidx_start;
255 1.19 haya int16_t itc_bufidx_end;
256 1.19 haya int16_t itc_bufidx_linkend;
257 1.19 haya #endif
258 1.19 haya
259 1.19 haya /* data for descriptor */
260 1.19 haya bus_dma_segment_t itc_dseg;
261 1.19 haya bus_dmamap_t itc_ddmamap;
262 1.19 haya int itc_descsize; /* count in byte */
263 1.19 haya u_int8_t *itc_descmap;
264 1.19 haya int itc_dnsegs;
265 1.19 haya
266 1.19 haya volatile u_int32_t *itc_scratch; /* descriptor decoder will write */
267 1.19 haya u_int32_t itc_scratch_paddr;
268 1.19 haya
269 1.19 haya volatile void *itc_waitchan; /* wait channel */
270 1.19 haya
271 1.19 haya int itc_outpkt; /* only for debugging */
272 1.19 haya
273 1.19 haya #if 0
274 1.19 haya struct fwohci_it_ctx *fwohci_it_ctx_construct(int);
275 1.19 haya void fwohci_it_ctx_destruct(struct fwohci_it_ctx *);
276 1.19 haya void fwohci_it_ctx_intr(struct fwohci_it_ctx *);
277 1.19 haya int fwohci_it_ctx_writedata(ieee1394_it_tag_t, int ndata,
278 1.19 haya struct ieee1394_it_datalist *);
279 1.19 haya private:
280 1.19 haya void fwohci_it_ctx_run(struct fwohci_it_ctx *itc);
281 1.19 haya void fwohci_it_intr(struct fwohci_softc *, struct fwohci_it_ctx *);
282 1.19 haya #endif
283 1.19 haya #define INC_BUF(itc, buf) \
284 1.19 haya do { \
285 1.19 haya if (++buf == (itc)->itc_buf + (itc)->itc_bufnum) { \
286 1.19 haya buf = &(itc)->itc_buf[0]; \
287 1.19 haya } \
288 1.19 haya } while (0)
289 1.19 haya };
290 1.19 haya
291 1.2 onoe struct fwohci_uidtbl {
292 1.5 onoe int fu_valid;
293 1.5 onoe u_int8_t fu_uid[8];
294 1.14 jmc };
295 1.14 jmc
296 1.14 jmc /*
297 1.14 jmc * Needed to keep track of outstanding packets during a read op. Since the
298 1.14 jmc * packet stream is asynch it's possible to parse a response packet before the
299 1.14 jmc * ack bits are processed. In this case something needs to track whether the
300 1.14 jmc * abuf is still valid before possibly attempting to use items from within it.
301 1.14 jmc */
302 1.14 jmc
303 1.14 jmc struct fwohci_cb {
304 1.14 jmc struct ieee1394_abuf *ab;
305 1.14 jmc int count;
306 1.14 jmc int abuf_valid;
307 1.2 onoe };
308 1.2 onoe
309 1.1 matt struct fwohci_softc {
310 1.1 matt struct ieee1394_softc sc_sc1394;
311 1.3 matt struct evcnt sc_intrcnt;
312 1.15 haya struct evcnt sc_isocnt;
313 1.19 haya struct evcnt sc_ascnt;
314 1.19 haya struct evcnt sc_itintrcnt;
315 1.1 matt
316 1.1 matt bus_space_tag_t sc_memt;
317 1.1 matt bus_space_handle_t sc_memh;
318 1.1 matt bus_dma_tag_t sc_dmat;
319 1.1 matt bus_size_t sc_memsize;
320 1.3 matt #if 0
321 1.3 matt
322 1.3 matt /* Mandatory structures to get the link enabled
323 1.3 matt */
324 1.3 matt bus_dmamap_t sc_configrom_map;
325 1.3 matt bus_dmamap_t sc_selfid_map;
326 1.3 matt u_int32_t *sc_selfid_buf;
327 1.3 matt u_int32_t *sc_configrom;
328 1.3 matt #endif
329 1.2 onoe
330 1.2 onoe bus_dma_segment_t sc_dseg;
331 1.2 onoe int sc_dnseg;
332 1.2 onoe bus_dmamap_t sc_ddmamap;
333 1.4 onoe struct fwohci_desc *sc_desc;
334 1.6 onoe u_int8_t *sc_descmap;
335 1.2 onoe int sc_descsize;
336 1.4 onoe int sc_isoctx;
337 1.19 haya int sc_itctx;
338 1.2 onoe
339 1.4 onoe void *sc_shutdownhook;
340 1.4 onoe void *sc_powerhook;
341 1.4 onoe struct callout sc_selfid_callout;
342 1.6 onoe int sc_selfid_fail;
343 1.2 onoe
344 1.2 onoe struct fwohci_ctx *sc_ctx_arrq;
345 1.2 onoe struct fwohci_ctx *sc_ctx_arrs;
346 1.2 onoe struct fwohci_ctx *sc_ctx_atrq;
347 1.2 onoe struct fwohci_ctx *sc_ctx_atrs;
348 1.19 haya struct fwohci_ctx **sc_ctx_as; /* previously sc_ctx_ir */
349 1.2 onoe struct fwohci_buf sc_buf_cnfrom;
350 1.2 onoe struct fwohci_buf sc_buf_selfid;
351 1.19 haya
352 1.19 haya struct fwohci_ir_ctx **sc_ctx_ir;
353 1.19 haya struct fwohci_it_ctx **sc_ctx_it;
354 1.2 onoe
355 1.10 enami struct proc *sc_event_thread;
356 1.10 enami
357 1.10 enami int sc_dying;
358 1.10 enami u_int32_t sc_intmask;
359 1.10 enami u_int32_t sc_iso;
360 1.9 jmc
361 1.10 enami u_int8_t sc_csr[CSR_SB_END];
362 1.2 onoe
363 1.2 onoe struct fwohci_uidtbl *sc_uidtbl;
364 1.4 onoe u_int16_t sc_nodeid; /* Full Node ID of this node */
365 1.4 onoe u_int8_t sc_rootid; /* Phy ID of Root */
366 1.4 onoe u_int8_t sc_irmid; /* Phy ID of IRM */
367 1.4 onoe u_int8_t sc_tlabel; /* Transaction Label */
368 1.11 jmc
369 1.9 jmc LIST_HEAD(, ieee1394_softc) sc_nodelist;
370 1.1 matt };
371 1.1 matt
372 1.3 matt int fwohci_init (struct fwohci_softc *, const struct evcnt *);
373 1.3 matt int fwohci_intr (void *);
374 1.3 matt int fwohci_print (void *, const char *);
375 1.16 ichiro int fwohci_detach(struct fwohci_softc *, int);
376 1.16 ichiro int fwohci_activate(struct device *, enum devact);
377 1.1 matt
378 1.1 matt /* Macros to read and write the OHCI registers
379 1.1 matt */
380 1.8 enami #define OHCI_CSR_WRITE(sc, reg, val) \
381 1.8 enami bus_space_write_4((sc)->sc_memt, (sc)->sc_memh, reg, htole32(val))
382 1.8 enami #define OHCI_CSR_READ(sc, reg) \
383 1.8 enami le32toh(bus_space_read_4((sc)->sc_memt, (sc)->sc_memh, reg))
384 1.15 haya
385 1.15 haya #define FWOHCI_CTX_ASYNC 0
386 1.15 haya #define FWOHCI_CTX_ISO_SINGLE 1 /* for async stream */
387 1.15 haya #define FWOHCI_CTX_ISO_MULTI 2 /* for isochronous */
388 1.13 jmc
389 1.13 jmc /* Locators. */
390 1.13 jmc
391 1.13 jmc #include "locators.h"
392 1.13 jmc
393 1.13 jmc #define fwbuscf_idhi cf_loc[FWBUSCF_IDHI]
394 1.13 jmc #define FWBUS_UNK_IDHI FWBUSCF_IDHI_DEFAULT
395 1.13 jmc
396 1.13 jmc #define fwbuscf_idlo cf_loc[FWBUSCF_IDLO]
397 1.13 jmc #define FWBUS_UNK_IDLO FWBUSCF_IDLO_DEFAULT
398 1.1 matt
399 1.1 matt #endif /* _DEV_IEEE1394_FWOHCIVAR_H_ */
400