iopvar.h revision 1.2.2.2 1 /* $NetBSD: iopvar.h,v 1.2.2.2 2000/11/22 17:34:20 bouyer 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 Andrew Doran.
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 _I2O_IOPVAR_H_
40 #define _I2O_IOPVAR_H_
41
42 /* Per-IOP statistics; not particularly useful at the moment. */
43 struct iop_stat {
44 int is_cur_swqueue;
45 int is_peak_swqueue;
46 int is_cur_hwqueue;
47 int is_peak_hwqueue;
48 int64_t is_requests;
49 int64_t is_bytes;
50 };
51
52 #ifdef _KERNEL
53
54 #include "locators.h"
55
56 /* XXX. Tunables. */
57 #define IOP_MAX_INITIATORS 32
58 #define IOP_MAX_PI_QUEUECNT 128
59 #define IOP_MAX_HW_QUEUECNT 256
60 #define IOP_MAX_HW_REPLYCNT 128
61
62 /*
63 * XXX The following should be adjusted if and when:
64 *
65 * o MAXPHYS exceeds 64kB.
66 * o A new message or reply is defined in i2o.h.
67 *
68 * As it stands, these make for a message frame of 200 bytes.
69 */
70 #define IOP_MAX_SGL_SIZE 132 /* Maximum S/G list size */
71 #define IOP_MAX_BASE_MSG_SIZE 68 /* Maximum base message size */
72 #define IOP_MAX_XFER 65536 /* Maximum transfer size */
73 #define IOP_MAX_MSG_XFERS 3 /* Maximum transfer count per msg */
74
75 #define IOP_MAX_SGL_ENTRIES (IOP_MAX_SGL_SIZE / 8)
76 #define IOP_MAX_MSG_SIZE (IOP_MAX_BASE_MSG_SIZE + IOP_MAX_SGL_SIZE)
77
78 /*
79 * Transfer descriptor.
80 */
81 struct iop_xfer {
82 bus_dmamap_t ix_map;
83 u_int ix_size;
84 u_int ix_flags;
85 };
86 #define IX_IN 0x0001 /* Data transfer from IOP */
87 #define IX_OUT 0x0002 /* Data transfer to IOP */
88
89 /*
90 * Message wrapper.
91 */
92 struct iop_msg {
93 SIMPLEQ_ENTRY(iop_msg) im_queue; /* Next queued message */
94 TAILQ_ENTRY(iop_msg) im_hash; /* Hash chain */
95 u_int im_flags; /* Control flags */
96 u_int im_tctx; /* Transaction context */
97 u_int im_tid; /* TID we're addressing */
98 void *im_dvcontext; /* Un*x device context */
99 u_int32_t im_msg[IOP_MAX_MSG_SIZE / sizeof(u_int32_t)];
100 struct iop_xfer im_xfer[IOP_MAX_MSG_XFERS];
101 };
102
103 #define IM_SYSMASK 0x00ff
104 #define IM_REPLIED 0x0001 /* Message has been replied to */
105 #define IM_ALLOCED 0x0002 /* This message wrapper is allocated */
106 #define IM_WAITING 0x0004 /* Somebody is waiting for reply */
107 #define IM_SGLOFFADJ 0x0008 /* S/G list offset adjusted */
108 #define IM_DISCARD 0x0010 /* Discard message wrapper once sent */
109
110 #define IM_USERMASK 0xff00
111 #define IM_NOWAIT 0x0100 /* Don't sleep when processing */
112 #define IM_NOICTX 0x0200 /* No initiator context field */
113 #define IM_NOINTR 0x0400 /* Don't interrupt when complete */
114
115 struct iop_initiator {
116 struct device *ii_dv;
117 void (*ii_intr)(struct device *, struct iop_msg *, void *);
118 int ii_flags;
119 int ii_ictx;
120 };
121 #define II_DISCARD 0x0001 /* Don't track state; discard msg wrappers */
122
123 #define IOP_ICTX 0
124
125 /*
126 * Per-IOP context.
127 */
128 struct iop_softc {
129 struct device sc_dv; /* generic device data */
130 bus_space_handle_t sc_ioh; /* bus space handle */
131 bus_space_tag_t sc_iot; /* bus space tag */
132 bus_dma_tag_t sc_dmat; /* bus DMA tag */
133 void *sc_ih; /* interrupt handler cookie */
134
135 struct i2o_hrt *sc_hrt; /* hardware resource table */
136 struct i2o_lct *sc_lct; /* logical configuration table */
137 int sc_nlctent; /* number of LCT entries */
138 u_int8_t *sc_lctmap; /* lct map (per-entry flags) */
139 struct i2o_status sc_status; /* status */
140 struct iop_stat sc_stat; /* counters */
141 int sc_flags; /* IOP-wide flags */
142 int sc_maxreplycnt; /* reply queue size */
143
144 SIMPLEQ_HEAD(,iop_msg) sc_queue;/* software queue */
145 int sc_maxqueuecnt; /* maximum # of msgs on h/w queue */
146
147 /*
148 * Reply queue.
149 */
150 bus_dmamap_t sc_rep_dmamap;
151 int sc_rep_size;
152 bus_addr_t sc_rep_phys;
153 caddr_t sc_rep;
154
155 /*
156 * Initiator table.
157 */
158 struct iop_initiator *sc_itab[IOP_MAX_INITIATORS];
159
160 /*
161 * The following are used only when posting the system table to
162 * the IOP. They describe PCI memory and I/O port regions.
163 */
164 bus_addr_t sc_memaddr;
165 int sc_memsize;
166 int sc_ioaddr;
167 int sc_iosize;
168 };
169
170 #define IOP_OPEN 0x01 /* Device interface open */
171 #define IOP_LCTLKHELD 0x02 /* sc_lct lock held */
172 #define IOP_LCTLKWANTED 0x04 /* sc_lct lock wanted */
173 #define IOP_DRAIN 0x08 /* Draining IOP */
174
175 #define IOP_LCTMAP_INUSE 0x01 /* target is in use */
176
177 struct iop_attach_args {
178 int ia_class; /* device class */
179 int ia_tid; /* target ID */
180 };
181 #define iopcf_tid cf_loc[IOPCF_TID] /* TID */
182
183 int iop_init(struct iop_softc *, const char *);
184 int iop_intr(void *);
185 int iop_params_get(struct iop_softc *, int, int, void *, int);
186 int iop_simple_cmd(struct iop_softc *, int, int, int);
187 void iop_strvis(const char *, int, char *, int);
188
189 int iop_initiator_register(struct iop_softc *, struct iop_initiator *);
190 void iop_initiator_unregister(struct iop_softc *, struct iop_initiator *);
191
192 int iop_lct_get(struct iop_softc *);
193 int iop_lct_lock(struct iop_softc *);
194 void iop_lct_unlock(struct iop_softc *);
195
196 int iop_msg_alloc(struct iop_softc *, struct iop_initiator *,
197 struct iop_msg **, int);
198 int iop_msg_enqueue(struct iop_softc *, struct iop_msg *);
199 void iop_msg_free(struct iop_softc *, struct iop_initiator *,
200 struct iop_msg *);
201 int iop_msg_map(struct iop_softc *, struct iop_msg *, void *, int, int);
202 int iop_msg_send(struct iop_softc *, struct iop_msg *, int);
203 void iop_msg_unmap(struct iop_softc *, struct iop_msg *);
204 int iop_msg_wait(struct iop_softc *, struct iop_msg *, int);
205
206 int iop_tid_claim(struct iop_softc *, int, int, int);
207 int iop_tid_inuse(struct iop_softc *, int);
208 int iop_tid_lct_index(struct iop_softc *, int);
209 void iop_tid_markallused(struct iop_softc *, int);
210
211 #endif /* _KERNEL */
212
213 #endif /* !_I2O_IOPVAR_H_ */
214