fwohcivar.h revision 1.17 1 1.17 eeh /* $NetBSD: fwohcivar.h,v 1.17 2002/01/16 01:47:37 eeh 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/mbuf.h>
43 1.4 onoe #include <sys/callout.h>
44 1.4 onoe #include <sys/queue.h>
45 1.4 onoe
46 1.4 onoe #include <machine/bus.h>
47 1.2 onoe
48 1.2 onoe #define OHCI_PAGE_SIZE 0x0800
49 1.2 onoe #define OHCI_BUF_ARRQ_CNT 16
50 1.2 onoe #define OHCI_BUF_ARRS_CNT 8
51 1.2 onoe #define OHCI_BUF_ATRQ_CNT (8*8)
52 1.2 onoe #define OHCI_BUF_ATRS_CNT (8*8)
53 1.15 haya #define OHCI_BUF_IR_CNT 8
54 1.10 enami #define OHCI_BUF_CNT \
55 1.10 enami (OHCI_BUF_ARRQ_CNT + OHCI_BUF_ARRS_CNT + OHCI_BUF_ATRQ_CNT + \
56 1.10 enami OHCI_BUF_ATRS_CNT + OHCI_BUF_IR_CNT + 1 + 1)
57 1.2 onoe
58 1.2 onoe #define OHCI_LOOP 1000
59 1.4 onoe #define OHCI_SELFID_TIMEOUT (hz * 3)
60 1.15 haya #define OHCI_ASYNC_STREAM 0x40
61 1.2 onoe
62 1.2 onoe struct fwohci_softc;
63 1.12 jmc struct fwohci_pkt;
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.2 onoe struct fwohci_uidtbl {
117 1.5 onoe int fu_valid;
118 1.5 onoe u_int8_t fu_uid[8];
119 1.14 jmc };
120 1.14 jmc
121 1.14 jmc /*
122 1.14 jmc * Needed to keep track of outstanding packets during a read op. Since the
123 1.14 jmc * packet stream is asynch it's possible to parse a response packet before the
124 1.14 jmc * ack bits are processed. In this case something needs to track whether the
125 1.14 jmc * abuf is still valid before possibly attempting to use items from within it.
126 1.14 jmc */
127 1.14 jmc
128 1.14 jmc struct fwohci_cb {
129 1.14 jmc struct ieee1394_abuf *ab;
130 1.14 jmc int count;
131 1.14 jmc int abuf_valid;
132 1.2 onoe };
133 1.2 onoe
134 1.1 matt struct fwohci_softc {
135 1.1 matt struct ieee1394_softc sc_sc1394;
136 1.3 matt struct evcnt sc_intrcnt;
137 1.15 haya struct evcnt sc_isocnt;
138 1.15 haya struct evcnt sc_isopktcnt;
139 1.1 matt
140 1.1 matt bus_space_tag_t sc_memt;
141 1.1 matt bus_space_handle_t sc_memh;
142 1.1 matt bus_dma_tag_t sc_dmat;
143 1.1 matt bus_size_t sc_memsize;
144 1.3 matt #if 0
145 1.3 matt
146 1.3 matt /* Mandatory structures to get the link enabled
147 1.3 matt */
148 1.3 matt bus_dmamap_t sc_configrom_map;
149 1.3 matt bus_dmamap_t sc_selfid_map;
150 1.3 matt u_int32_t *sc_selfid_buf;
151 1.3 matt u_int32_t *sc_configrom;
152 1.3 matt #endif
153 1.2 onoe
154 1.2 onoe bus_dma_segment_t sc_dseg;
155 1.2 onoe int sc_dnseg;
156 1.2 onoe bus_dmamap_t sc_ddmamap;
157 1.4 onoe struct fwohci_desc *sc_desc;
158 1.6 onoe u_int8_t *sc_descmap;
159 1.2 onoe int sc_descsize;
160 1.4 onoe int sc_isoctx;
161 1.2 onoe
162 1.4 onoe void *sc_shutdownhook;
163 1.4 onoe void *sc_powerhook;
164 1.4 onoe struct callout sc_selfid_callout;
165 1.6 onoe int sc_selfid_fail;
166 1.2 onoe
167 1.2 onoe struct fwohci_ctx *sc_ctx_arrq;
168 1.2 onoe struct fwohci_ctx *sc_ctx_arrs;
169 1.2 onoe struct fwohci_ctx *sc_ctx_atrq;
170 1.2 onoe struct fwohci_ctx *sc_ctx_atrs;
171 1.2 onoe struct fwohci_ctx **sc_ctx_ir;
172 1.2 onoe struct fwohci_buf sc_buf_cnfrom;
173 1.2 onoe struct fwohci_buf sc_buf_selfid;
174 1.2 onoe
175 1.10 enami struct proc *sc_event_thread;
176 1.10 enami
177 1.10 enami int sc_dying;
178 1.10 enami u_int32_t sc_intmask;
179 1.10 enami u_int32_t sc_iso;
180 1.9 jmc
181 1.10 enami u_int8_t sc_csr[CSR_SB_END];
182 1.2 onoe
183 1.2 onoe struct fwohci_uidtbl *sc_uidtbl;
184 1.4 onoe u_int16_t sc_nodeid; /* Full Node ID of this node */
185 1.4 onoe u_int8_t sc_rootid; /* Phy ID of Root */
186 1.4 onoe u_int8_t sc_irmid; /* Phy ID of IRM */
187 1.4 onoe u_int8_t sc_tlabel; /* Transaction Label */
188 1.11 jmc
189 1.9 jmc LIST_HEAD(, ieee1394_softc) sc_nodelist;
190 1.1 matt };
191 1.1 matt
192 1.3 matt int fwohci_init (struct fwohci_softc *, const struct evcnt *);
193 1.3 matt int fwohci_intr (void *);
194 1.3 matt int fwohci_print (void *, const char *);
195 1.16 ichiro int fwohci_detach(struct fwohci_softc *, int);
196 1.16 ichiro int fwohci_activate(struct device *, enum devact);
197 1.1 matt
198 1.1 matt /* Macros to read and write the OHCI registers
199 1.1 matt */
200 1.8 enami #define OHCI_CSR_WRITE(sc, reg, val) \
201 1.8 enami bus_space_write_4((sc)->sc_memt, (sc)->sc_memh, reg, htole32(val))
202 1.8 enami #define OHCI_CSR_READ(sc, reg) \
203 1.8 enami le32toh(bus_space_read_4((sc)->sc_memt, (sc)->sc_memh, reg))
204 1.15 haya
205 1.15 haya #define FWOHCI_CTX_ASYNC 0
206 1.15 haya #define FWOHCI_CTX_ISO_SINGLE 1 /* for async stream */
207 1.15 haya #define FWOHCI_CTX_ISO_MULTI 2 /* for isochronous */
208 1.13 jmc
209 1.13 jmc /* Locators. */
210 1.13 jmc
211 1.13 jmc #include "locators.h"
212 1.13 jmc
213 1.13 jmc #define fwbuscf_idhi cf_loc[FWBUSCF_IDHI]
214 1.13 jmc #define FWBUS_UNK_IDHI FWBUSCF_IDHI_DEFAULT
215 1.13 jmc
216 1.13 jmc #define fwbuscf_idlo cf_loc[FWBUSCF_IDLO]
217 1.13 jmc #define FWBUS_UNK_IDLO FWBUSCF_IDLO_DEFAULT
218 1.1 matt
219 1.1 matt #endif /* _DEV_IEEE1394_FWOHCIVAR_H_ */
220