ncr53c9xvar.h revision 1.5 1 /* $NetBSD: ncr53c9xvar.h,v 1.5 1997/04/27 22:08:53 pk Exp $ */
2
3 /*
4 * Copyright (c) 1997 Jason R. Thorpe.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed for the NetBSD Project
18 * by Jason R. Thorpe.
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 /*
35 * Copyright (c) 1994 Peter Galbavy. All rights reserved.
36 *
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
39 * are met:
40 * 1. Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * 2. Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in the
44 * documentation and/or other materials provided with the distribution.
45 * 3. All advertising materials mentioning features or use of this software
46 * must display the following acknowledgement:
47 * This product includes software developed by Peter Galbavy.
48 * 4. The name of the author may not be used to endorse or promote products
49 * derived from this software without specific prior written permission.
50 *
51 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
52 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
53 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
54 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
55 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
56 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
60 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 */
62
63 /* Set this to 1 for normal debug, or 2 for per-target tracing. */
64 #define NCR53C9X_DEBUG 1
65
66 #define NCR_ABORT_TIMEOUT 2000 /* time to wait for abort */
67 #define NCR_SENSE_TIMEOUT 1000 /* time to wait for sense */
68
69 #define FREQTOCCF(freq) (((freq + 4) / 5))
70
71 /*
72 * NCR 53c9x variants. Note, these values are used as indexes into
73 * a table; don't modify them unless you know what you're doing.
74 */
75 #define NCR_VARIANT_ESP100 0
76 #define NCR_VARIANT_ESP100A 1
77 #define NCR_VARIANT_ESP200 2
78 #define NCR_VARIANT_NCR53C94 3
79 #define NCR_VARIANT_NCR53C96 4
80 #define NCR_VARIANT_MAX 5
81
82 /*
83 * ECB. Holds additional information for each SCSI command Comments: We
84 * need a separate scsi command block because we may need to overwrite it
85 * with a request sense command. Basicly, we refrain from fiddling with
86 * the scsi_xfer struct (except do the expected updating of return values).
87 * We'll generally update: xs->{flags,resid,error,sense,status} and
88 * occasionally xs->retries.
89 */
90 struct ncr53c9x_ecb {
91 TAILQ_ENTRY(ncr53c9x_ecb) chain;
92 struct scsi_xfer *xs; /* SCSI xfer ctrl block from above */
93 int flags;
94 #define ECB_ALLOC 0x01
95 #define ECB_NEXUS 0x02
96 #define ECB_SENSE 0x04
97 #define ECB_ABORT 0x40
98 #define ECB_RESET 0x80
99 int timeout;
100
101 struct {
102 u_char id; /* Selection Id msg */
103 struct scsi_generic cmd; /* SCSI command block */
104 } cmd;
105 int clen; /* Size of command in cmd.cmd */
106 char *daddr; /* Saved data pointer */
107 int dleft; /* Residue */
108 u_char stat; /* SCSI status byte */
109 u_char pad[3];
110
111 #if NCR53C9X_DEBUG > 1
112 char trace[1000];
113 #endif
114 };
115 #if NCR53C9X_DEBUG > 1
116 #define ECB_TRACE(ecb, msg, a, b) do { \
117 const char *f = "[" msg "]"; \
118 int n = strlen((ecb)->trace); \
119 if (n < (sizeof((ecb)->trace)-100)) \
120 sprintf((ecb)->trace + n, f, a, b); \
121 } while(0)
122 #else
123 #define ECB_TRACE(ecb, msg, a, b)
124 #endif
125
126 /*
127 * Some info about each (possible) target on the SCSI bus. This should
128 * probably have been a "per target+lunit" structure, but we'll leave it at
129 * this for now. Is there a way to reliably hook it up to sc->fordriver??
130 */
131 struct ncr53c9x_tinfo {
132 int cmds; /* #commands processed */
133 int dconns; /* #disconnects */
134 int touts; /* #timeouts */
135 int perrs; /* #parity errors */
136 int senses; /* #request sense commands sent */
137 ushort lubusy; /* What local units/subr. are busy? */
138 u_char flags;
139 #define T_NEED_TO_RESET 0x01 /* Should send a BUS_DEV_RESET */
140 #define T_NEGOTIATE 0x02 /* (Re)Negotiate synchronous options */
141 #define T_BUSY 0x04 /* Target is busy, i.e. cmd in progress */
142 #define T_SYNCMODE 0x08 /* sync mode has been negotiated */
143 #define T_SYNCHOFF 0x10 /* .. */
144 #define T_RSELECTOFF 0x20 /* .. */
145 u_char period; /* Period suggestion */
146 u_char offset; /* Offset suggestion */
147 u_char pad[3];
148 } tinfo_t;
149
150 /* Register a linenumber (for debugging) */
151 #define LOGLINE(p)
152
153 #define NCR_SHOWECBS 0x01
154 #define NCR_SHOWINTS 0x02
155 #define NCR_SHOWCMDS 0x04
156 #define NCR_SHOWMISC 0x08
157 #define NCR_SHOWTRAC 0x10
158 #define NCR_SHOWSTART 0x20
159 #define NCR_SHOWPHASE 0x40
160 #define NCR_SHOWDMA 0x80
161 #define NCR_SHOWCCMDS 0x100
162 #define NCR_SHOWMSGS 0x200
163
164 #ifdef NCR53C9X_DEBUG
165 extern int ncr53c9x_debug;
166 #define NCR_ECBS(str) \
167 do {if (ncr53c9x_debug & NCR_SHOWECBS) printf str;} while (0)
168 #define NCR_MISC(str) \
169 do {if (ncr53c9x_debug & NCR_SHOWMISC) printf str;} while (0)
170 #define NCR_INTS(str) \
171 do {if (ncr53c9x_debug & NCR_SHOWINTS) printf str;} while (0)
172 #define NCR_TRACE(str) \
173 do {if (ncr53c9x_debug & NCR_SHOWTRAC) printf str;} while (0)
174 #define NCR_CMDS(str) \
175 do {if (ncr53c9x_debug & NCR_SHOWCMDS) printf str;} while (0)
176 #define NCR_START(str) \
177 do {if (ncr53c9x_debug & NCR_SHOWSTART) printf str;}while (0)
178 #define NCR_PHASE(str) \
179 do {if (ncr53c9x_debug & NCR_SHOWPHASE) printf str;}while (0)
180 #define NCR_DMA(str) \
181 do {if (ncr53c9x_debug & NCR_SHOWDMA) printf str;}while (0)
182 #define NCR_MSGS(str) \
183 do {if (ncr53c9x_debug & NCR_SHOWMSGS) printf str;}while (0)
184 #else
185 #define NCR_ECBS(str)
186 #define NCR_MISC(str)
187 #define NCR_INTS(str)
188 #define NCR_TRACE(str)
189 #define NCR_CMDS(str)
190 #define NCR_START(str)
191 #define NCR_PHASE(str)
192 #define NCR_DMA(str)
193 #define NCR_MSGS(str)
194 #endif
195
196 #define NCR_MAX_MSG_LEN 8
197
198 struct ncr53c9x_softc;
199
200 /*
201 * Function switch used as glue to MD code.
202 */
203 struct ncr53c9x_glue {
204 /* Mandatory entry points. */
205 u_char (*gl_read_reg) __P((struct ncr53c9x_softc *, int));
206 void (*gl_write_reg) __P((struct ncr53c9x_softc *, int, u_char));
207 int (*gl_dma_isintr) __P((struct ncr53c9x_softc *));
208 void (*gl_dma_reset) __P((struct ncr53c9x_softc *));
209 int (*gl_dma_intr) __P((struct ncr53c9x_softc *));
210 int (*gl_dma_setup) __P((struct ncr53c9x_softc *,
211 caddr_t *, size_t *, int, size_t *));
212 void (*gl_dma_go) __P((struct ncr53c9x_softc *));
213 void (*gl_dma_stop) __P((struct ncr53c9x_softc *));
214 int (*gl_dma_isactive) __P((struct ncr53c9x_softc *));
215
216 /* Optional entry points. */
217 void (*gl_clear_latched_intr) __P((struct ncr53c9x_softc *));
218 };
219
220 struct ncr53c9x_softc {
221 struct device sc_dev; /* us as a device */
222
223 struct evcnt sc_intrcnt; /* intr count */
224 struct scsi_link sc_link; /* scsi lint struct */
225
226 struct ncr53c9x_glue *sc_glue; /* glue to MD code */
227
228 /* register defaults */
229 u_char sc_cfg1; /* Config 1 */
230 u_char sc_cfg2; /* Config 2, not ESP100 */
231 u_char sc_cfg3; /* Config 3, only ESP200 */
232 u_char sc_ccf; /* Clock Conversion */
233 u_char sc_timeout;
234
235 /* register copies, see espreadregs() */
236 u_char sc_espintr;
237 u_char sc_espstat;
238 u_char sc_espstep;
239 u_char sc_espfflags;
240
241 /* Lists of command blocks */
242 TAILQ_HEAD(ecb_list, ncr53c9x_ecb) free_list,
243 ready_list,
244 nexus_list;
245
246 struct ncr53c9x_ecb *sc_nexus; /* current command */
247 struct ncr53c9x_ecb sc_ecb[3*8]; /* three per target */
248 struct ncr53c9x_tinfo sc_tinfo[8];
249
250 /* Data about the current nexus (updated for every cmd switch) */
251 caddr_t sc_dp; /* Current data pointer */
252 ssize_t sc_dleft; /* Data left to transfer */
253
254 /* Adapter state */
255 int sc_phase; /* Copy of what bus phase we are in */
256 int sc_prevphase; /* Copy of what bus phase we were in */
257 u_char sc_state; /* State applicable to the adapter */
258 u_char sc_flags;
259 u_char sc_selid;
260 u_char sc_lastcmd;
261
262 /* Message stuff */
263 u_char sc_msgpriq; /* One or more messages to send (encoded) */
264 u_char sc_msgout; /* What message is on its way out? */
265 u_char sc_msgoutq; /* What messages have been sent so far? */
266 u_char sc_omess[NCR_MAX_MSG_LEN];
267 caddr_t sc_omp; /* Message pointer (for multibyte messages) */
268 size_t sc_omlen;
269 u_char sc_imess[NCR_MAX_MSG_LEN + 1];
270 caddr_t sc_imp; /* Message pointer (for multibyte messages) */
271 size_t sc_imlen;
272
273 caddr_t sc_cmdp; /* Command pointer (for DMAed commands) */
274 size_t sc_cmdlen; /* Size of command in transit */
275
276 /* hardware/openprom stuff */
277 int sc_freq; /* Freq in HZ */
278 int sc_id; /* our scsi id */
279 int sc_rev; /* esp revision */
280 int sc_minsync; /* minimum sync period / 4 */
281 int sc_maxxfer; /* maximum transfer size */
282 };
283
284 /* values for sc_state */
285 #define NCR_IDLE 1 /* waiting for something to do */
286 #define NCR_SELECTING 2 /* SCSI command is arbiting */
287 #define NCR_RESELECTED 3 /* Has been reselected */
288 #define NCR_CONNECTED 4 /* Actively using the SCSI bus */
289 #define NCR_DISCONNECT 5 /* MSG_DISCONNECT received */
290 #define NCR_CMDCOMPLETE 6 /* MSG_CMDCOMPLETE received */
291 #define NCR_CLEANING 7
292 #define NCR_SBR 8 /* Expect a SCSI RST because we commanded it */
293
294 /* values for sc_flags */
295 #define NCR_DROP_MSGI 0x01 /* Discard all msgs (parity err detected) */
296 #define NCR_ABORTING 0x02 /* Bailing out */
297 #define NCR_DOINGDMA 0x04 /* The FIFO data path is active! */
298 #define NCR_SYNCHNEGO 0x08 /* Synch negotiation in progress. */
299 #define NCR_ICCS 0x10 /* Expect status phase results */
300 #define NCR_WAITI 0x20 /* Waiting for non-DMA data to arrive */
301 #define NCR_ATN 0x40 /* ATN asserted */
302 #define NCR_EXPECT_ILLCMD 0x80 /* Expect Illegal Command Interrupt */
303
304 /* values for sc_msgout */
305 #define SEND_DEV_RESET 0x01
306 #define SEND_PARITY_ERROR 0x02
307 #define SEND_INIT_DET_ERR 0x04
308 #define SEND_REJECT 0x08
309 #define SEND_IDENTIFY 0x10
310 #define SEND_ABORT 0x20
311 #define SEND_SDTR 0x40
312 #define SEND_WDTR 0x80
313
314 /* SCSI Status codes */
315 #define ST_MASK 0x3e /* bit 0,6,7 is reserved */
316
317 /* phase bits */
318 #define IOI 0x01
319 #define CDI 0x02
320 #define MSGI 0x04
321
322 /* Information transfer phases */
323 #define DATA_OUT_PHASE (0)
324 #define DATA_IN_PHASE (IOI)
325 #define COMMAND_PHASE (CDI)
326 #define STATUS_PHASE (CDI|IOI)
327 #define MESSAGE_OUT_PHASE (MSGI|CDI)
328 #define MESSAGE_IN_PHASE (MSGI|CDI|IOI)
329
330 #define PHASE_MASK (MSGI|CDI|IOI)
331
332 /* Some pseudo phases for getphase()*/
333 #define BUSFREE_PHASE 0x100 /* Re/Selection no longer valid */
334 #define INVALID_PHASE 0x101 /* Re/Selection valid, but no REQ yet */
335 #define PSEUDO_PHASE 0x100 /* "pseudo" bit */
336
337 /*
338 * Macros to read and write the chip's registers.
339 */
340 #define NCR_READ_REG(sc, reg) \
341 (*(sc)->sc_glue->gl_read_reg)((sc), (reg))
342 #define NCR_WRITE_REG(sc, reg, val) \
343 (*(sc)->sc_glue->gl_write_reg)((sc), (reg), (val))
344
345 #ifdef NCR53C9X_DEBUG
346 #define NCRCMD(sc, cmd) do { \
347 if (ncr53c9x_debug & NCR_SHOWCCMDS) \
348 printf("<cmd:0x%x>", (unsigned)cmd); \
349 sc->sc_lastcmd = cmd; \
350 NCR_WRITE_REG(sc, NCR_CMD, cmd); \
351 } while (0)
352 #else
353 #define NCRCMD(sc, cmd) NCR_WRITE_REG(sc, NCR_CMD, cmd)
354 #endif
355
356 /*
357 * DMA macros for NCR53c9x
358 */
359 #define NCRDMA_ISINTR(sc) (*(sc)->sc_glue->gl_dma_isintr)((sc))
360 #define NCRDMA_RESET(sc) (*(sc)->sc_glue->gl_dma_reset)((sc))
361 #define NCRDMA_INTR(sc) (*(sc)->sc_glue->gl_dma_intr)((sc))
362 #define NCRDMA_SETUP(sc, addr, len, datain, dmasize) \
363 (*(sc)->sc_glue->gl_dma_setup)((sc), (addr), (len), (datain), (dmasize))
364 #define NCRDMA_GO(sc) (*(sc)->sc_glue->gl_dma_go)((sc))
365 #define NCRDMA_ISACTIVE(sc) (*(sc)->sc_glue->gl_dma_isactive)((sc))
366
367 /*
368 * Macro to convert the chip register Clock Per Byte value to
369 * Sunchronous Transfer Period.
370 */
371 #define ncr53c9x_cpb2stp(sc, cpb) \
372 ((250 * (cpb)) / (sc)->sc_freq)
373
374 void ncr53c9x_attach __P((struct ncr53c9x_softc *,
375 struct scsi_adapter *, struct scsi_device *));
376 int ncr53c9x_scsi_cmd __P((struct scsi_xfer *));
377 void ncr53c9x_reset __P((struct ncr53c9x_softc *));
378 int ncr53c9x_intr __P((struct ncr53c9x_softc *));
379