wd33c93var.h revision 1.4.4.2 1 1.4.4.2 yamt /* $NetBSD: wd33c93var.h,v 1.4.4.2 2006/12/30 20:48:04 yamt Exp $ */
2 1.4.4.2 yamt
3 1.4.4.2 yamt /*
4 1.4.4.2 yamt * Copyright (c) 1990 The Regents of the University of California.
5 1.4.4.2 yamt * All rights reserved.
6 1.4.4.2 yamt *
7 1.4.4.2 yamt * This code is derived from software contributed to Berkeley by
8 1.4.4.2 yamt * Van Jacobson of Lawrence Berkeley Laboratory.
9 1.4.4.2 yamt *
10 1.4.4.2 yamt * Redistribution and use in source and binary forms, with or without
11 1.4.4.2 yamt * modification, are permitted provided that the following conditions
12 1.4.4.2 yamt * are met:
13 1.4.4.2 yamt * 1. Redistributions of source code must retain the above copyright
14 1.4.4.2 yamt * notice, this list of conditions and the following disclaimer.
15 1.4.4.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
16 1.4.4.2 yamt * notice, this list of conditions and the following disclaimer in the
17 1.4.4.2 yamt * documentation and/or other materials provided with the distribution.
18 1.4.4.2 yamt * 3. Neither the name of the University nor the names of its contributors
19 1.4.4.2 yamt * may be used to endorse or promote products derived from this software
20 1.4.4.2 yamt * without specific prior written permission.
21 1.4.4.2 yamt *
22 1.4.4.2 yamt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 1.4.4.2 yamt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 1.4.4.2 yamt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 1.4.4.2 yamt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 1.4.4.2 yamt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 1.4.4.2 yamt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 1.4.4.2 yamt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.4.4.2 yamt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 1.4.4.2 yamt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.4.4.2 yamt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.4.4.2 yamt * SUCH DAMAGE.
33 1.4.4.2 yamt *
34 1.4.4.2 yamt * @(#)scsivar.h 7.1 (Berkeley) 5/8/90
35 1.4.4.2 yamt */
36 1.4.4.2 yamt #ifndef _SBICVAR_H_
37 1.4.4.2 yamt #define _SBICVAR_H_
38 1.4.4.2 yamt #include <sys/callout.h>
39 1.4.4.2 yamt #include <sys/malloc.h>
40 1.4.4.2 yamt
41 1.4.4.2 yamt #define SBIC_NTARG 8
42 1.4.4.2 yamt #define SBIC_NLUN 8
43 1.4.4.2 yamt #define SBIC_NTAGS 256
44 1.4.4.2 yamt
45 1.4.4.2 yamt #define SBIC_MAX_MSGLEN 8
46 1.4.4.2 yamt
47 1.4.4.2 yamt #define SBIC_ABORT_TIMEOUT 2000 /* time to wait for abort */
48 1.4.4.2 yamt #define SBIC_SENSE_TIMEOUT 1000 /* time to wait for sense */
49 1.4.4.2 yamt
50 1.4.4.2 yamt /*
51 1.4.4.2 yamt * ACB. Holds additional information for each SCSI command Comments: We
52 1.4.4.2 yamt * need a separate scsi command block because we may need to overwrite it
53 1.4.4.2 yamt * with a request sense command. Basically, we refrain from fiddling with
54 1.4.4.2 yamt * the scsi_xfer struct (except do the expected updating of return values).
55 1.4.4.2 yamt * We'll generally update: xs->{flags,resid,error,sense,status} and
56 1.4.4.2 yamt * occasionally xs->retries.
57 1.4.4.2 yamt */
58 1.4.4.2 yamt struct wd33c93_acb {
59 1.4.4.2 yamt TAILQ_ENTRY(wd33c93_acb) chain;
60 1.4.4.2 yamt struct scsipi_xfer *xs; /* SCSI xfer ctrl block from above */
61 1.4.4.2 yamt int flags; /* Status */
62 1.4.4.2 yamt #define ACB_FREE 0x00
63 1.4.4.2 yamt #define ACB_ACTIVE 0x01
64 1.4.4.2 yamt #define ACB_READY 0x02 /* ACB is on ready list */
65 1.4.4.2 yamt #define ACB_DONE 0x04
66 1.4.4.2 yamt #define ACB_SENSE 0x08 /* ACB Requesting sense */
67 1.4.4.2 yamt #define ACB_COMPLETE 0x10 /* Disconnected at end of xfer */
68 1.4.4.2 yamt #define ACB_RESET 0x20 /* Require Reset */
69 1.4.4.2 yamt #define ACB_ABORT 0x40 /* Require Abort */
70 1.4.4.2 yamt
71 1.4.4.2 yamt int timeout;
72 1.4.4.2 yamt struct scsipi_generic cmd; /* SCSI command block */
73 1.4.4.2 yamt int clen;
74 1.4.4.2 yamt char *daddr; /* kva for data */
75 1.4.4.2 yamt size_t dleft; /* bytes remaining */
76 1.4.4.2 yamt u_char tag_type; /* TAG Type (0x20-0x22, 0=No Tags) */
77 1.4.4.2 yamt u_char tag_id; /* TAG id number */
78 1.4.4.2 yamt };
79 1.4.4.2 yamt
80 1.4.4.2 yamt /*
81 1.4.4.2 yamt * Some info about each (possible) target on the SCSI bus. This should
82 1.4.4.2 yamt * probably have been a "per target+lunit" structure, but we'll leave it at
83 1.4.4.2 yamt * this for now. Is there a way to reliably hook it up to sc->fordriver??
84 1.4.4.2 yamt */
85 1.4.4.2 yamt
86 1.4.4.2 yamt struct wd33c93_linfo {
87 1.4.4.2 yamt LIST_ENTRY(wd33c93_linfo) link;
88 1.4.4.2 yamt time_t last_used;
89 1.4.4.2 yamt int lun;
90 1.4.4.2 yamt int used; /* # slots in use */
91 1.4.4.2 yamt u_char state;
92 1.4.4.2 yamt #define L_STATE_IDLE 0
93 1.4.4.2 yamt #define L_STATE_BUSY 1
94 1.4.4.2 yamt #define L_STATE_ESTAT 2
95 1.4.4.2 yamt struct wd33c93_acb *untagged;
96 1.4.4.2 yamt struct wd33c93_acb *queued[SBIC_NTAGS];
97 1.4.4.2 yamt };
98 1.4.4.2 yamt
99 1.4.4.2 yamt struct wd33c93_tinfo {
100 1.4.4.2 yamt int cmds; /* # of commands processed */
101 1.4.4.2 yamt int dconns; /* # of disconnects */
102 1.4.4.2 yamt
103 1.4.4.2 yamt u_char flags;
104 1.4.4.2 yamt #define T_NEED_RESET 0x01 /* Should send a BUS_DEV_RESET */
105 1.4.4.2 yamt #define T_NEGOTIATE 0x02 /* (Re)Negotiate synchronous options */
106 1.4.4.2 yamt #define T_BUSY 0x04 /* Target is busy */
107 1.4.4.2 yamt #define T_SYNCMODE 0x08 /* SYNC mode has been negotiated */
108 1.4.4.2 yamt #define T_NOSYNC 0x10 /* Force ASYNC mode */
109 1.4.4.2 yamt #define T_NODISC 0x20 /* Don't allow disconnect */
110 1.4.4.2 yamt #define T_TAG 0x40 /* Turn on TAG QUEUEs */
111 1.4.4.2 yamt #define T_WANTSYNC 0x80 /* Negotiatious should aim for sync */
112 1.4.4.2 yamt u_char period; /* Period suggestion */
113 1.4.4.2 yamt u_char offset; /* Offset suggestion */
114 1.4.4.2 yamt struct wd33c93_linfo *lun[SBIC_NLUN]; /* LUN list for this target */
115 1.4.4.2 yamt } tinfo_t;
116 1.4.4.2 yamt
117 1.4.4.2 yamt /* Look up a lun in a tinfo */
118 1.4.4.2 yamt #define TINFO_LUN(t, l) ((t)->lun[(l)])
119 1.4.4.2 yamt
120 1.4.4.2 yamt struct wd33c93_softc {
121 1.4.4.2 yamt struct device sc_dev;
122 1.4.4.2 yamt
123 1.4.4.2 yamt struct scsipi_channel sc_channel; /* proto for sub devices */
124 1.4.4.2 yamt struct scsipi_adapter sc_adapter;
125 1.4.4.2 yamt struct device *sc_child; /* attached scsibus, if any */
126 1.4.4.2 yamt struct callout sc_watchdog;
127 1.4.4.2 yamt void *sc_driver; /* driver specific field */
128 1.4.4.2 yamt
129 1.4.4.2 yamt int target; /* Currently active target */
130 1.4.4.2 yamt int lun; /* Currently active LUN */
131 1.4.4.2 yamt
132 1.4.4.2 yamt /* WD33c93 registers */
133 1.4.4.2 yamt bus_space_tag_t sc_regt;
134 1.4.4.2 yamt bus_space_handle_t sc_regh;
135 1.4.4.2 yamt
136 1.4.4.2 yamt
137 1.4.4.2 yamt /* Data about the current nexus (updated for every cmd switch) */
138 1.4.4.2 yamt caddr_t sc_daddr; /* Current data pointer */
139 1.4.4.2 yamt size_t sc_dleft; /* Data left to transfer */
140 1.4.4.2 yamt ssize_t sc_tcnt; /* number of bytes transfered */
141 1.4.4.2 yamt
142 1.4.4.2 yamt /* Lists of command blocks */
143 1.4.4.2 yamt TAILQ_HEAD(acb_list, wd33c93_acb) ready_list;
144 1.4.4.2 yamt
145 1.4.4.2 yamt struct wd33c93_acb *sc_nexus; /* current command */
146 1.4.4.2 yamt struct wd33c93_tinfo sc_tinfo[8];
147 1.4.4.2 yamt
148 1.4.4.2 yamt u_short sc_state;
149 1.4.4.2 yamt u_short sc_status;
150 1.4.4.2 yamt int sc_disc; /* current # of active nexus's */
151 1.4.4.2 yamt int sc_flags;
152 1.4.4.2 yamt
153 1.4.4.2 yamt /* Message stuff */
154 1.4.4.2 yamt u_short sc_msgify; /* Last IDENTIFY message */
155 1.4.4.2 yamt u_short sc_msgout; /* Current message out */
156 1.4.4.2 yamt u_short sc_msgpriq; /* mesg_out queue (bitmap) */
157 1.4.4.2 yamt u_short sc_msgoutq; /* mesg_out queue */
158 1.4.4.2 yamt
159 1.4.4.2 yamt u_char sc_imsg[SBIC_MAX_MSGLEN];
160 1.4.4.2 yamt u_char sc_omsg[SBIC_MAX_MSGLEN];
161 1.4.4.2 yamt u_char sc_imsglen;
162 1.4.4.2 yamt u_char sc_omsglen;
163 1.4.4.2 yamt
164 1.4.4.2 yamt /* Static hardware attributes supplied by attachment */
165 1.4.4.2 yamt int sc_id; /* SCSI ID for controller */
166 1.4.4.2 yamt int sc_clkfreq; /* wd33c93 clk freq * 10 MHz */
167 1.4.4.2 yamt uint8_t sc_dmamode; /* One of SBIC_CTL_*DMA */
168 1.4.4.2 yamt
169 1.4.4.2 yamt /* Static hardware attributes derived by wd33c93_attach() */
170 1.4.4.2 yamt int sc_chip; /* Chip variation */
171 1.4.4.2 yamt int sc_rev; /* Chip revision */
172 1.4.4.2 yamt int sc_cfflags; /* Copy of config flags */
173 1.4.4.2 yamt int sc_maxxfer; /* Maximum transfer size */
174 1.4.4.2 yamt uint8_t sc_maxoffset; /* Maximum sync ofset (bytes) */
175 1.4.4.2 yamt uint8_t sc_syncperiods[7]; /* Sync transfer periods (4ns units) */
176 1.4.4.2 yamt
177 1.4.4.2 yamt int (*sc_dmasetup) (struct wd33c93_softc *, caddr_t *,
178 1.4.4.2 yamt size_t *, int, size_t *);
179 1.4.4.2 yamt int (*sc_dmago) (struct wd33c93_softc *);
180 1.4.4.2 yamt void (*sc_dmastop) (struct wd33c93_softc *);
181 1.4.4.2 yamt void (*sc_reset) (struct wd33c93_softc *);
182 1.4.4.2 yamt };
183 1.4.4.2 yamt
184 1.4.4.2 yamt /* values for sc_flags */
185 1.4.4.2 yamt #define SBICF_SELECTED 0x01 /* bus is in selected state. */
186 1.4.4.2 yamt #define SBICF_NODMA 0x02 /* Polled transfer */
187 1.4.4.2 yamt #define SBICF_INDMA 0x04 /* DMA I/O in progress */
188 1.4.4.2 yamt #define SBICF_SYNCNEGO 0x08 /* Sync negotiation in progress */
189 1.4.4.2 yamt #define SBICF_ABORTING 0x10 /* Aborting */
190 1.4.4.2 yamt
191 1.4.4.2 yamt /* values for sc_state */
192 1.4.4.2 yamt #define SBIC_UNINITIALIZED 0 /* Driver not initialized */
193 1.4.4.2 yamt #define SBIC_IDLE 1 /* waiting for something to do */
194 1.4.4.2 yamt #define SBIC_SELECTING 2 /* SCSI command is arbiting */
195 1.4.4.2 yamt #define SBIC_RESELECTED 3 /* Has been reselected */
196 1.4.4.2 yamt #define SBIC_IDENTIFIED 4 /* Has gotten IFY but not TAG */
197 1.4.4.2 yamt #define SBIC_CONNECTED 5 /* Actively using the SCSI bus */
198 1.4.4.2 yamt #define SBIC_DISCONNECT 6 /* MSG_DISCONNECT received */
199 1.4.4.2 yamt #define SBIC_CMDCOMPLETE 7 /* MSG_CMDCOMPLETE received */
200 1.4.4.2 yamt #define SBIC_ERROR 8 /* Error has occurred */
201 1.4.4.2 yamt #define SBIC_SELTIMEOUT 9 /* Select Timeout */
202 1.4.4.2 yamt #define SBIC_CLEANING 10 /* Scrubbing ACB's */
203 1.4.4.2 yamt #define SBIC_BUSRESET 11 /* SCSI RST has been issued */
204 1.4.4.2 yamt
205 1.4.4.2 yamt /* values for sc_msgout */
206 1.4.4.2 yamt #define SEND_DEV_RESET 0x0001
207 1.4.4.2 yamt #define SEND_PARITY_ERROR 0x0002
208 1.4.4.2 yamt #define SEND_INIT_DET_ERR 0x0004
209 1.4.4.2 yamt #define SEND_REJECT 0x0008
210 1.4.4.2 yamt #define SEND_IDENTIFY 0x0010
211 1.4.4.2 yamt #define SEND_ABORT 0x0020
212 1.4.4.2 yamt #define SEND_WDTR 0x0040
213 1.4.4.2 yamt #define SEND_SDTR 0x0080
214 1.4.4.2 yamt #define SEND_TAG 0x0100
215 1.4.4.2 yamt
216 1.4.4.2 yamt /* WD33c93 chipset revisions - values for sc_rev */
217 1.4.4.2 yamt #define SBIC_CHIP_UNKNOWN 0
218 1.4.4.2 yamt #define SBIC_CHIP_WD33C93 1
219 1.4.4.2 yamt #define SBIC_CHIP_WD33C93A 2
220 1.4.4.2 yamt #define SBIC_CHIP_WD33C93B 3
221 1.4.4.2 yamt
222 1.4.4.2 yamt #define SBIC_CHIP_LIST {"UNKNOWN", "WD33C93", "WD33C93A", "WD33C93B"}
223 1.4.4.2 yamt
224 1.4.4.2 yamt /*
225 1.4.4.2 yamt * States returned by our state machine
226 1.4.4.2 yamt */
227 1.4.4.2 yamt #define SBIC_STATE_ERROR -1
228 1.4.4.2 yamt #define SBIC_STATE_DONE 0
229 1.4.4.2 yamt #define SBIC_STATE_RUNNING 1
230 1.4.4.2 yamt #define SBIC_STATE_DISCONNECT 2
231 1.4.4.2 yamt
232 1.4.4.2 yamt #define DEBUG_ACBS 0x01
233 1.4.4.2 yamt #define DEBUG_INTS 0x02
234 1.4.4.2 yamt #define DEBUG_CMDS 0x04
235 1.4.4.2 yamt #define DEBUG_MISC 0x08
236 1.4.4.2 yamt #define DEBUG_TRAC 0x10
237 1.4.4.2 yamt #define DEBUG_RSEL 0x20
238 1.4.4.2 yamt #define DEBUG_PHASE 0x40
239 1.4.4.2 yamt #define DEBUG_DMA 0x80
240 1.4.4.2 yamt #define DEBUG_CCMDS 0x100
241 1.4.4.2 yamt #define DEBUG_MSGS 0x200
242 1.4.4.2 yamt #define DEBUG_TAGS 0x400
243 1.4.4.2 yamt #define DEBUG_SYNC 0x800
244 1.4.4.2 yamt
245 1.4.4.2 yamt #ifdef DEBUG
246 1.4.4.2 yamt extern int wd33c93_debug_flags;
247 1.4.4.2 yamt #define SBIC_DEBUG(level, str) \
248 1.4.4.2 yamt do { \
249 1.4.4.2 yamt if (wd33c93_debug & __CONCAT(DEBUG_,level)) \
250 1.4.4.2 yamt printf str; \
251 1.4.4.2 yamt } while (0)
252 1.4.4.2 yamt #else
253 1.4.4.2 yamt #define SBIC_DEBUG(level, str)
254 1.4.4.2 yamt #endif
255 1.4.4.2 yamt
256 1.4.4.2 yamt struct buf;
257 1.4.4.2 yamt struct scsipi_xfer;
258 1.4.4.2 yamt
259 1.4.4.2 yamt void wd33c93_scsi_request (struct scsipi_channel *,
260 1.4.4.2 yamt scsipi_adapter_req_t, void *);
261 1.4.4.2 yamt void wd33c93_attach (struct wd33c93_softc *);
262 1.4.4.2 yamt int wd33c93_intr (struct wd33c93_softc *);
263 1.4.4.2 yamt
264 1.4.4.2 yamt #endif /* _SBICVAR_H_ */
265