1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65 #include <sys/timeout.h>
66
67
68 #if !defined(SMALL_KERNEL)
69 #define NCR53C9X_DEBUG 1
70 #endif
71
72
73 #define NCR_NTARG 16
74 #define NCR_NLUN 8
75
76 #define NCR_ABORT_TIMEOUT 2000
77 #define NCR_SENSE_TIMEOUT 1000
78
79 #define FREQTOCCF(freq) (((freq + 4) / 5))
80
81
82
83
84
85 #define NCR_VARIANT_ESP100 0
86 #define NCR_VARIANT_ESP100A 1
87 #define NCR_VARIANT_ESP200 2
88 #define NCR_VARIANT_NCR53C94 3
89 #define NCR_VARIANT_NCR53C96 4
90 #define NCR_VARIANT_ESP406 5
91 #define NCR_VARIANT_FAS408 6
92 #define NCR_VARIANT_FAS216 7
93 #define NCR_VARIANT_AM53C974 8
94 #define NCR_VARIANT_FAS366 9
95 #define NCR_VARIANT_MAX 10
96
97
98
99
100
101
102
103
104
105 struct ncr53c9x_ecb {
106 TAILQ_ENTRY(ncr53c9x_ecb) chain;
107 struct scsi_xfer *xs;
108 int flags;
109 #define ECB_ALLOC 0x01
110 #define ECB_READY 0x02
111 #define ECB_SENSE 0x04
112 #define ECB_ABORT 0x40
113 #define ECB_RESET 0x80
114 #define ECB_TENTATIVE_DONE 0x100
115 int timeout;
116 struct timeout to;
117
118 struct {
119 u_char msg[3];
120 struct scsi_generic cmd;
121 } cmd;
122 char *daddr;
123 int clen;
124 int dleft;
125 u_char stat;
126 u_char tag[2];
127 u_char pad[1];
128
129 #if NCR53C9X_DEBUG > 1
130 char trace[1000];
131 #endif
132 };
133 #if NCR53C9X_DEBUG > 1
134 #define ECB_TRACE(ecb, msg, a, b) do { \
135 const char *f = "[" msg "]"; \
136 int n = strlen((ecb)->trace); \
137 if (n < (sizeof((ecb)->trace)-100)) \
138 snprintf((ecb)->trace + n, sizeof((ecb)->trace) - n, f, a, b); \
139 } while(0)
140 #else
141 #define ECB_TRACE(ecb, msg, a, b)
142 #endif
143
144
145
146
147
148
149
150
151
152
153
154
155
156 struct ncr53c9x_linfo {
157 int64_t lun;
158 LIST_ENTRY(ncr53c9x_linfo) link;
159 time_t last_used;
160 unsigned char used;
161 unsigned char avail;
162 unsigned char busy;
163 struct ncr53c9x_ecb *untagged;
164 struct ncr53c9x_ecb *queued[256];
165 };
166
167 struct ncr53c9x_tinfo {
168 int cmds;
169 int dconns;
170 int touts;
171 int perrs;
172 int senses;
173 u_char flags;
174 #define T_NEED_TO_RESET 0x01
175 #define T_NEGOTIATE 0x02
176 #define T_BUSY 0x04
177 #define T_SYNCMODE 0x08
178 #define T_SYNCHOFF 0x10
179 #define T_RSELECTOFF 0x20
180 #define T_TAG 0x40
181 #define T_WIDE 0x80
182 u_char period;
183 u_char offset;
184 u_char cfg3;
185 u_char nextag;
186 u_char width;
187 LIST_HEAD(lun_list, ncr53c9x_linfo) luns;
188 struct ncr53c9x_linfo *lun[NCR_NLUN];
189 };
190
191
192 #define TINFO_LUN(t, l) ((((l) < NCR_NLUN) && (((t)->lun[(l)]) != NULL)) ? \
193 ((t)->lun[(l)]) : ncr53c9x_lunsearch((t), (int64_t)(l)))
194
195
196 #define LOGLINE(p)
197
198 #define NCR_SHOWECBS 0x01
199 #define NCR_SHOWINTS 0x02
200 #define NCR_SHOWCMDS 0x04
201 #define NCR_SHOWMISC 0x08
202 #define NCR_SHOWTRAC 0x10
203 #define NCR_SHOWSTART 0x20
204 #define NCR_SHOWPHASE 0x40
205 #define NCR_SHOWDMA 0x80
206 #define NCR_SHOWCCMDS 0x100
207 #define NCR_SHOWMSGS 0x200
208
209 #ifdef NCR53C9X_DEBUG
210 extern int ncr53c9x_debug;
211 #define NCR_ECBS(str) \
212 do {if (ncr53c9x_debug & NCR_SHOWECBS) printf str;} while (0)
213 #define NCR_MISC(str) \
214 do {if (ncr53c9x_debug & NCR_SHOWMISC) printf str;} while (0)
215 #define NCR_INTS(str) \
216 do {if (ncr53c9x_debug & NCR_SHOWINTS) printf str;} while (0)
217 #define NCR_TRACE(str) \
218 do {if (ncr53c9x_debug & NCR_SHOWTRAC) printf str;} while (0)
219 #define NCR_CMDS(str) \
220 do {if (ncr53c9x_debug & NCR_SHOWCMDS) printf str;} while (0)
221 #define NCR_START(str) \
222 do {if (ncr53c9x_debug & NCR_SHOWSTART) printf str;}while (0)
223 #define NCR_PHASE(str) \
224 do {if (ncr53c9x_debug & NCR_SHOWPHASE) printf str;}while (0)
225 #define NCR_DMA(str) \
226 do {if (ncr53c9x_debug & NCR_SHOWDMA) printf str;}while (0)
227 #define NCR_MSGS(str) \
228 do {if (ncr53c9x_debug & NCR_SHOWMSGS) printf str;}while (0)
229 #else
230 #define NCR_ECBS(str)
231 #define NCR_MISC(str)
232 #define NCR_INTS(str)
233 #define NCR_TRACE(str)
234 #define NCR_CMDS(str)
235 #define NCR_START(str)
236 #define NCR_PHASE(str)
237 #define NCR_DMA(str)
238 #define NCR_MSGS(str)
239 #endif
240
241 #define NCR_MAX_MSG_LEN 8
242
243 struct ncr53c9x_softc;
244
245
246
247
248 struct ncr53c9x_glue {
249
250 u_char (*gl_read_reg)(struct ncr53c9x_softc *, int);
251 void (*gl_write_reg)(struct ncr53c9x_softc *, int, u_char);
252 int (*gl_dma_isintr)(struct ncr53c9x_softc *);
253 void (*gl_dma_reset)(struct ncr53c9x_softc *);
254 int (*gl_dma_intr)(struct ncr53c9x_softc *);
255 int (*gl_dma_setup)(struct ncr53c9x_softc *,
256 caddr_t *, size_t *, int, size_t *);
257 void (*gl_dma_go)(struct ncr53c9x_softc *);
258 void (*gl_dma_stop)(struct ncr53c9x_softc *);
259 int (*gl_dma_isactive)(struct ncr53c9x_softc *);
260
261
262 void (*gl_clear_latched_intr)(struct ncr53c9x_softc *);
263 };
264
265 struct ncr53c9x_softc {
266 struct device sc_dev;
267
268 struct timeout sc_watchdog;
269 struct scsi_link sc_link;
270
271 struct ncr53c9x_glue *sc_glue;
272
273 int sc_ntarg;
274 int sc_cfflags;
275
276
277 u_char sc_cfg1;
278 u_char sc_cfg2;
279 u_char sc_cfg3;
280 u_char sc_cfg3_fscsi;
281 u_char sc_cfg4;
282 u_char sc_cfg5;
283 u_char sc_ccf;
284 u_char sc_timeout;
285
286
287 u_char sc_espintr;
288 u_char sc_espstat;
289 u_char sc_espstep;
290 u_char sc_espstat2;
291 u_char sc_espfflags;
292
293
294 TAILQ_HEAD(ecb_list, ncr53c9x_ecb) ready_list;
295
296 struct ncr53c9x_ecb *sc_nexus;
297 struct ncr53c9x_tinfo sc_tinfo[NCR_NTARG];
298
299
300 caddr_t sc_dp;
301 ssize_t sc_dleft;
302
303
304 int sc_phase;
305 int sc_prevphase;
306 u_char sc_state;
307 u_char sc_flags;
308 u_char sc_selid;
309 u_char sc_lastcmd;
310
311
312 u_short sc_msgify;
313 u_short sc_msgout;
314 u_short sc_msgpriq;
315 u_short sc_msgoutq;
316
317 u_char *sc_omess;
318 caddr_t sc_omp;
319 size_t sc_omlen;
320 u_char *sc_imess;
321 caddr_t sc_imp;
322 size_t sc_imlen;
323
324 caddr_t sc_cmdp;
325 size_t sc_cmdlen;
326
327
328 int sc_freq;
329 int sc_id;
330 int sc_rev;
331 int sc_features;
332 int sc_minsync;
333 int sc_maxxfer;
334 };
335
336
337 #define NCR_IDLE 1
338 #define NCR_SELECTING 2
339 #define NCR_RESELECTED 3
340 #define NCR_IDENTIFIED 4
341 #define NCR_CONNECTED 5
342 #define NCR_DISCONNECT 6
343 #define NCR_CMDCOMPLETE 7
344 #define NCR_CLEANING 8
345 #define NCR_SBR 9
346
347
348 #define NCR_DROP_MSGI 0x01
349 #define NCR_ABORTING 0x02
350 #define NCR_DOINGDMA 0x04
351 #define NCR_SYNCHNEGO 0x08
352 #define NCR_ICCS 0x10
353 #define NCR_WAITI 0x20
354 #define NCR_ATN 0x40
355 #define NCR_EXPECT_ILLCMD 0x80
356
357
358 #define NCR_F_HASCFG3 0x01
359 #define NCR_F_FASTSCSI 0x02
360 #define NCR_F_DMASELECT 0x04
361 #define NCR_F_SELATN3 0x08
362
363
364 #define SEND_DEV_RESET 0x0001
365 #define SEND_PARITY_ERROR 0x0002
366 #define SEND_INIT_DET_ERR 0x0004
367 #define SEND_REJECT 0x0008
368 #define SEND_IDENTIFY 0x0010
369 #define SEND_ABORT 0x0020
370 #define SEND_WDTR 0x0040
371 #define SEND_SDTR 0x0080
372 #define SEND_TAG 0x0100
373
374
375 #define ST_MASK 0x3e
376
377
378 #define IOI 0x01
379 #define CDI 0x02
380 #define MSGI 0x04
381
382
383 #define DATA_OUT_PHASE (0)
384 #define DATA_IN_PHASE (IOI)
385 #define COMMAND_PHASE (CDI)
386 #define STATUS_PHASE (CDI|IOI)
387 #define MESSAGE_OUT_PHASE (MSGI|CDI)
388 #define MESSAGE_IN_PHASE (MSGI|CDI|IOI)
389
390 #define PHASE_MASK (MSGI|CDI|IOI)
391
392
393 #define BUSFREE_PHASE 0x100
394 #define INVALID_PHASE 0x101
395 #define PSEUDO_PHASE 0x100
396
397
398
399
400 #define NCR_READ_REG(sc, reg) \
401 (*(sc)->sc_glue->gl_read_reg)((sc), (reg))
402 #define NCR_WRITE_REG(sc, reg, val) \
403 (*(sc)->sc_glue->gl_write_reg)((sc), (reg), (val))
404
405 #ifdef NCR53C9X_DEBUG
406 #define NCRCMD(sc, cmd) do { \
407 if (ncr53c9x_debug & NCR_SHOWCCMDS) \
408 printf("<cmd:0x%x %d>", (unsigned)cmd, __LINE__); \
409 sc->sc_lastcmd = cmd; \
410 NCR_WRITE_REG(sc, NCR_CMD, cmd); \
411 } while (0)
412 #else
413 #define NCRCMD(sc, cmd) NCR_WRITE_REG(sc, NCR_CMD, cmd)
414 #endif
415
416
417
418
419 #define NCRDMA_ISINTR(sc) (*(sc)->sc_glue->gl_dma_isintr)((sc))
420 #define NCRDMA_RESET(sc) (*(sc)->sc_glue->gl_dma_reset)((sc))
421 #define NCRDMA_INTR(sc) (*(sc)->sc_glue->gl_dma_intr)((sc))
422 #define NCRDMA_SETUP(sc, addr, len, datain, dmasize) \
423 (*(sc)->sc_glue->gl_dma_setup)((sc), (addr), (len), (datain), (dmasize))
424 #define NCRDMA_GO(sc) (*(sc)->sc_glue->gl_dma_go)((sc))
425 #define NCRDMA_ISACTIVE(sc) (*(sc)->sc_glue->gl_dma_isactive)((sc))
426
427
428
429
430
431 #define ncr53c9x_cpb2stp(sc, cpb) \
432 ((250 * (cpb)) / (sc)->sc_freq)
433
434 void ncr53c9x_attach(struct ncr53c9x_softc *,
435 struct scsi_adapter *, struct scsi_device *);
436 int ncr53c9x_scsi_cmd(struct scsi_xfer *);
437 void ncr53c9x_reset(struct ncr53c9x_softc *);
438 int ncr53c9x_intr(void *);
439 void ncr53c9x_init(struct ncr53c9x_softc *, int);