isp.c revision 1.15.2.1 1 /* $NetBSD: isp.c,v 1.15.2.1 1998/05/08 06:14:33 mycroft Exp $ */
2
3 /*
4 * Machine Independent (well, as best as possible)
5 * code for the Qlogic ISP SCSI adapters.
6 *
7 * Specific probe attach and support routines for Qlogic ISP SCSI adapters.
8 *
9 * Copyright (c) 1997 by Matthew Jacob
10 * NASA AMES Research Center.
11 * All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice immediately at the beginning of the file, without modification,
18 * this list of conditions, and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 * 3. The name of the author may not be used to endorse or promote products
23 * derived from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 */
37
38 /*
39 * Inspiration and ideas about this driver are from Erik Moe's Linux driver
40 * (qlogicisp.c) and Dave Miller's SBus version of same (qlogicisp.c)
41 */
42
43 #include <sys/types.h>
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/kernel.h>
47 #include <sys/errno.h>
48 #include <sys/ioctl.h>
49 #include <sys/device.h>
50 #include <sys/malloc.h>
51 #include <sys/buf.h>
52 #include <sys/proc.h>
53 #include <sys/user.h>
54
55
56 #include <dev/scsipi/scsi_all.h>
57 #include <dev/scsipi/scsipi_all.h>
58 #include <dev/scsipi/scsiconf.h>
59
60 #include <dev/scsipi/scsi_message.h>
61 #include <dev/scsipi/scsipi_debug.h>
62 #include <dev/scsipi/scsiconf.h>
63
64 #include <vm/vm.h>
65 #include <vm/vm_param.h>
66 #include <vm/pmap.h>
67
68 #include <dev/ic/ispreg.h>
69 #include <dev/ic/ispvar.h>
70 #include <dev/ic/ispmbox.h>
71
72 #define MBOX_DELAY_COUNT 1000000 / 100
73
74 struct cfdriver isp_cd = {
75 NULL, "isp", DV_DULL
76 };
77
78 static void ispminphys __P((struct buf *));
79 static int32_t ispscsicmd __P((struct scsipi_xfer *xs));
80 static void isp_mboxcmd __P((struct ispsoftc *, mbreg_t *));
81
82 static struct scsipi_adapter isp_switch = {
83 ispscsicmd, ispminphys, 0, 0
84 };
85
86 static struct scsipi_device isp_dev = { NULL, NULL, NULL, NULL };
87
88 #define IDPRINTF(lev, x) if (isp->isp_dblev >= lev) printf x
89
90 static int isp_poll __P((struct ispsoftc *, struct scsipi_xfer *, int));
91 static int isp_parse_status
92 __P((struct ispsoftc *, ispstatusreq_t *, struct scsipi_xfer *));
93 static void isp_lostcmd
94 __P((struct ispsoftc *, struct scsipi_xfer *, ispreq_t *));
95 static void isp_fibre_init __P((struct ispsoftc *));
96 static void isp_fw_state __P((struct ispsoftc *));
97 static void isp_dumpregs __P((struct ispsoftc *, const char *));
98 static void isp_setdparm __P((struct ispsoftc *));
99 static void isp_prtstst __P((ispstatusreq_t *));
100
101 #define WATCHI (30 * hz)
102 static void isp_watch __P((void *));
103 /*
104 * Reset Hardware.
105 */
106 void
107 isp_reset(isp)
108 struct ispsoftc *isp;
109 {
110 mbreg_t mbs;
111 int loops, i, cf_flags, dodnld = 1;
112 char *revname;
113
114 revname = "(unknown)";
115
116 isp->isp_state = ISP_NILSTATE;
117 cf_flags = isp->isp_dev.dv_cfdata->cf_flags;
118
119 /*
120 * Basic types have been set in the MD code.
121 * See if we can't figure out more here.
122 */
123 if (isp->isp_type & ISP_HA_FC) {
124 isp->isp_dblev = 2;
125 revname = "2100";
126 } else {
127 isp->isp_dblev = 1;
128 i = ISP_READ(isp, BIU_CONF0) & BIU_CONF0_HW_MASK;
129 switch (i) {
130 default:
131 printf("%s: unknown ISP type %x\n", isp->isp_name, i);
132 isp->isp_type = ISP_HA_SCSI_1020;
133 break;
134 case 1:
135 case 2:
136 revname = "1020";
137 isp->isp_type = ISP_HA_SCSI_1020;
138 break;
139 case 3:
140 revname = "1040A";
141 isp->isp_type = ISP_HA_SCSI_1040A;
142 break;
143 case 5:
144 revname = "1040B";
145 isp->isp_type = ISP_HA_SCSI_1040B;
146 break;
147 }
148 }
149
150 /*
151 * Do MD specific pre initialization
152 */
153 ISP_RESET0(isp);
154 isp_setdparm(isp);
155
156 /*
157 * Hit the chip over the head with hammer,
158 * and give the ISP a chance to recover.
159 */
160
161 if (isp->isp_type & ISP_HA_SCSI) {
162 ISP_WRITE(isp, BIU_ICR, BIU_ICR_SOFT_RESET);
163 /*
164 * A slight delay...
165 */
166 delay(100);
167
168 /*
169 * Clear data && control DMA engines.
170 */
171 ISP_WRITE(isp, CDMA_CONTROL,
172 DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
173 ISP_WRITE(isp, DDMA_CONTROL,
174 DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
175 } else {
176 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
177 /*
178 * A slight delay...
179 */
180 delay(100);
181 ISP_WRITE(isp, CDMA2100_CONTROL,
182 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
183 ISP_WRITE(isp, TDMA2100_CONTROL,
184 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
185 ISP_WRITE(isp, RDMA2100_CONTROL,
186 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
187 }
188
189 /*
190 * Wait for ISP to be ready to go...
191 */
192 loops = MBOX_DELAY_COUNT;
193 for (;;) {
194 if (isp->isp_type & ISP_HA_SCSI) {
195 if (!(ISP_READ(isp, BIU_ICR) & BIU_ICR_SOFT_RESET))
196 break;
197 } else {
198 if (!(ISP_READ(isp, BIU2100_CSR) & BIU2100_SOFT_RESET))
199 break;
200 }
201 delay(100);
202 if (--loops < 0) {
203 isp_dumpregs(isp, "chip reset timed out");
204 return;
205 }
206 }
207 /*
208 * More initialization
209 */
210 if (isp->isp_type & ISP_HA_SCSI) {
211 ISP_WRITE(isp, BIU_CONF1, 0);
212 } else {
213 ISP_WRITE(isp, BIU2100_CSR, 0);
214 ISP_WRITE(isp, RISC_MTR2100, 0x1212); /* FM */
215 }
216
217 ISP_WRITE(isp, HCCR, HCCR_CMD_RESET);
218 delay(100);
219
220 if (isp->isp_type & ISP_HA_SCSI) {
221 ISP_SETBITS(isp, BIU_CONF1, isp->isp_mdvec->dv_conf1);
222 if (isp->isp_mdvec->dv_conf1 & BIU_BURST_ENABLE) {
223 ISP_SETBITS(isp, CDMA_CONF, DMA_ENABLE_BURST);
224 ISP_SETBITS(isp, DDMA_CONF, DMA_ENABLE_BURST);
225 }
226 }
227 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE); /* release paused processor */
228
229 /*
230 * Do MD specific post initialization
231 */
232 ISP_RESET1(isp);
233
234 /*
235 * Enable interrupts
236 */
237 ENABLE_INTS(isp);
238
239 /*
240 * Do some sanity checking.
241 */
242 mbs.param[0] = MBOX_NO_OP;
243 isp_mboxcmd(isp, &mbs);
244 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
245 isp_dumpregs(isp, "NOP test failed");
246 return;
247 }
248
249 if (isp->isp_type & ISP_HA_SCSI) {
250 mbs.param[0] = MBOX_MAILBOX_REG_TEST;
251 mbs.param[1] = 0xdead;
252 mbs.param[2] = 0xbeef;
253 mbs.param[3] = 0xffff;
254 mbs.param[4] = 0x1111;
255 mbs.param[5] = 0xa5a5;
256 isp_mboxcmd(isp, &mbs);
257 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
258 isp_dumpregs(isp,
259 "Mailbox Register test didn't complete");
260 return;
261 }
262 if (mbs.param[1] != 0xdead || mbs.param[2] != 0xbeef ||
263 mbs.param[3] != 0xffff || mbs.param[4] != 0x1111 ||
264 mbs.param[5] != 0xa5a5) {
265 isp_dumpregs(isp, "Register Test Failed");
266 return;
267 }
268
269 }
270
271 /*
272 * Download new Firmware, unless requested not to do so.
273 * This is made slightly trickier in some cases where the
274 * firmware of the ROM revision is newer than the revision
275 * compiled into the driver. So, where we used to compare
276 * versions of our f/w and the ROM f/w, now we just see
277 * whether we have f/w at all and whether a config flag
278 * has disabled our download.
279 */
280 if (isp->isp_mdvec->dv_fwlen == 0 || (cf_flags & 0x80) != 0) {
281 dodnld = 0;
282 }
283
284 if (dodnld) {
285 for (i = 0; i < isp->isp_mdvec->dv_fwlen; i++) {
286 mbs.param[0] = MBOX_WRITE_RAM_WORD;
287 mbs.param[1] = isp->isp_mdvec->dv_codeorg + i;
288 mbs.param[2] = isp->isp_mdvec->dv_ispfw[i];
289 isp_mboxcmd(isp, &mbs);
290 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
291 isp_dumpregs(isp, "f/w download failed");
292
293 return;
294 }
295 }
296
297 if (isp->isp_mdvec->dv_fwlen) {
298 /*
299 * Verify that it downloaded correctly.
300 */
301 mbs.param[0] = MBOX_VERIFY_CHECKSUM;
302 mbs.param[1] = isp->isp_mdvec->dv_codeorg;
303 isp_mboxcmd(isp, &mbs);
304 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
305 isp_dumpregs(isp, "ram checksum failure");
306 return;
307 }
308 }
309 } else {
310 IDPRINTF(2, ("%s: skipping f/w download\n", isp->isp_name));
311 }
312
313 /*
314 * Now start it rolling.
315 *
316 * If we didn't actually download f/w,
317 * we still need to (re)start it.
318 */
319
320 mbs.param[0] = MBOX_EXEC_FIRMWARE;
321 mbs.param[1] = isp->isp_mdvec->dv_codeorg;
322 isp_mboxcmd(isp, &mbs);
323
324 if (isp->isp_type & ISP_HA_SCSI) {
325 /*
326 * Set CLOCK RATE
327 */
328 if (((sdparam *)isp->isp_param)->isp_clock) {
329 mbs.param[0] = MBOX_SET_CLOCK_RATE;
330 mbs.param[1] = ((sdparam *)isp->isp_param)->isp_clock;
331 isp_mboxcmd(isp, &mbs);
332 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
333 isp_dumpregs(isp, "failed to set CLOCKRATE");
334 return;
335 }
336 }
337 }
338 mbs.param[0] = MBOX_ABOUT_FIRMWARE;
339 isp_mboxcmd(isp, &mbs);
340 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
341 isp_dumpregs(isp, "ABOUT FIRMWARE command failed");
342 return;
343 }
344 printf("%s: Board Revision %s, %s F/W Revision %d.%d\n",
345 isp->isp_name, revname, dodnld? "loaded" : "ROM",
346 mbs.param[1], mbs.param[2]);
347 isp_fw_state(isp);
348 isp->isp_state = ISP_RESETSTATE;
349 }
350
351 /*
352 * Initialize Hardware to known state
353 */
354 void
355 isp_init(isp)
356 struct ispsoftc *isp;
357 {
358 sdparam *sdp;
359 mbreg_t mbs;
360 int s, i, l;
361
362 if (isp->isp_type & ISP_HA_FC) {
363 isp_fibre_init(isp);
364 return;
365 }
366
367 sdp = isp->isp_param;
368
369 /*
370 * Try and figure out if we're connected to a differential bus.
371 * You have to pause the RISC processor to read SXP registers.
372 */
373 s = splbio();
374 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
375 if (ISP_READ(isp, SXP_PINS_DIFF) & SXP_PINS_DIFF_SENSE) {
376 sdp->isp_diffmode = 1;
377 printf("%s: Differential Mode\n", isp->isp_name);
378 } else {
379 /*
380 * Force pullups on.
381 */
382 sdp->isp_req_ack_active_neg = 1;
383 sdp->isp_data_line_active_neg = 1;
384 sdp->isp_diffmode = 0;
385 }
386 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE); /* release paused processor */
387
388 mbs.param[0] = MBOX_GET_INIT_SCSI_ID;
389 isp_mboxcmd(isp, &mbs);
390 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
391 (void) splx(s);
392 isp_dumpregs(isp, "failed to get initiator id");
393 return;
394 }
395 if (mbs.param[1] != sdp->isp_initiator_id) {
396 printf("%s: setting Initiator ID to %d\n", isp->isp_name,
397 sdp->isp_initiator_id);
398 mbs.param[0] = MBOX_SET_INIT_SCSI_ID;
399 mbs.param[1] = sdp->isp_initiator_id;
400 isp_mboxcmd(isp, &mbs);
401 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
402 (void) splx(s);
403 isp_dumpregs(isp, "failed to set initiator id");
404 return;
405 }
406 } else {
407 IDPRINTF(2, ("%s: leaving Initiator ID at %d\n", isp->isp_name,
408 sdp->isp_initiator_id));
409 }
410
411 mbs.param[0] = MBOX_SET_RETRY_COUNT;
412 mbs.param[1] = sdp->isp_retry_count;
413 mbs.param[2] = sdp->isp_retry_delay;
414 isp_mboxcmd(isp, &mbs);
415 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
416 (void) splx(s);
417 isp_dumpregs(isp, "failed to set retry count and delay");
418 return;
419 }
420
421 mbs.param[0] = MBOX_SET_ASYNC_DATA_SETUP_TIME;
422 mbs.param[1] = sdp->isp_async_data_setup;
423 isp_mboxcmd(isp, &mbs);
424 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
425 (void) splx(s);
426 isp_dumpregs(isp, "failed to set async data setup time");
427 return;
428 }
429
430 mbs.param[0] = MBOX_SET_ACTIVE_NEG_STATE;
431 mbs.param[1] = (sdp->isp_req_ack_active_neg << 4) |
432 (sdp->isp_data_line_active_neg << 5);
433 isp_mboxcmd(isp, &mbs);
434 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
435 (void) splx(s);
436 isp_dumpregs(isp, "failed to set active neg state");
437 return;
438 }
439
440 mbs.param[0] = MBOX_SET_TAG_AGE_LIMIT;
441 mbs.param[1] = sdp->isp_tag_aging;
442 isp_mboxcmd(isp, &mbs);
443 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
444 (void) splx(s);
445 isp_dumpregs(isp, "failed to set tag age limit");
446 return;
447 }
448
449 mbs.param[0] = MBOX_SET_SELECT_TIMEOUT;
450 mbs.param[1] = sdp->isp_selection_timeout;
451 isp_mboxcmd(isp, &mbs);
452 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
453 (void) splx(s);
454 isp_dumpregs(isp, "failed to set selection timeout");
455 return;
456 }
457
458 #ifdef 0
459 printf("%s: device parameters, W=wide, S=sync, T=TagEnable\n",
460 isp->isp_name);
461 #endif
462
463 for (i = 0; i < MAX_TARGETS; i++) {
464 #ifdef 0
465 char bz[8];
466
467 if (sdp->isp_devparam[i].dev_flags & DPARM_SYNC) {
468 u_int16_t cj = (sdp->isp_devparam[i].sync_offset << 8) |
469 (sdp->isp_devparam[i].sync_period);
470 if (cj == ISP_20M_SYNCPARMS) {
471 cj = 20;
472 } else if (ISP_10M_SYNCPARMS) {
473 cj = 20;
474 } else if (ISP_08M_SYNCPARMS) {
475 cj = 20;
476 } else if (ISP_05M_SYNCPARMS) {
477 cj = 20;
478 } else if (ISP_04M_SYNCPARMS) {
479 cj = 20;
480 } else {
481 cj = 0;
482 }
483 if (sdp->isp_devparam[i].dev_flags & DPARM_WIDE)
484 cj <<= 1;
485 sprintf(bz, "%02dMBs", cj);
486 } else {
487 sprintf(bz, "Async");
488 }
489 if (sdp->isp_devparam[i].dev_flags & DPARM_WIDE)
490 bz[5] = 'W';
491 else
492 bz[5] = ' ';
493 if (sdp->isp_devparam[i].dev_flags & DPARM_TQING)
494 bz[6] = 'T';
495 else
496 bz[6] = ' ';
497 bz[7] = 0;
498 printf(" Tgt%x:%s", i, bz);
499 if (((i+1) & 0x3) == 0)
500 printf("\n");
501 #endif
502 if (sdp->isp_devparam[i].dev_enable == 0)
503 continue;
504
505 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
506 mbs.param[1] = i << 8;
507 mbs.param[2] = sdp->isp_devparam[i].dev_flags << 8;
508 mbs.param[3] =
509 (sdp->isp_devparam[i].sync_offset << 8) |
510 (sdp->isp_devparam[i].sync_period);
511
512 IDPRINTF(5, ("%s: target %d flags %x offset %x period %x\n",
513 isp->isp_name, i, sdp->isp_devparam[i].dev_flags,
514 sdp->isp_devparam[i].sync_offset,
515 sdp->isp_devparam[i].sync_period));
516 isp_mboxcmd(isp, &mbs);
517 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
518 printf("%s: failed to set parameters for target %d\n",
519 isp->isp_name, i);
520 printf("%s: flags %x offset %x period %x\n",
521 isp->isp_name, sdp->isp_devparam[i].dev_flags,
522 sdp->isp_devparam[i].sync_offset,
523 sdp->isp_devparam[i].sync_period);
524 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
525 mbs.param[1] = i << 8;
526 mbs.param[2] = DPARM_DEFAULT << 8;
527 mbs.param[3] = ISP_10M_SYNCPARMS;
528 isp_mboxcmd(isp, &mbs);
529 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
530 (void) splx(s);
531 printf("%s: failed even to set defaults\n",
532 isp->isp_name);
533 return;
534 }
535 }
536 for (l = 0; l < MAX_LUNS; l++) {
537 mbs.param[0] = MBOX_SET_DEV_QUEUE_PARAMS;
538 mbs.param[1] = (i << 8) | l;
539 mbs.param[2] = sdp->isp_max_queue_depth;
540 mbs.param[3] = sdp->isp_devparam[i].exc_throttle;
541 isp_mboxcmd(isp, &mbs);
542 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
543 (void) splx(s);
544 isp_dumpregs(isp, "failed to set device queue "
545 "parameters");
546 return;
547 }
548 }
549 }
550
551 /*
552 * Set up DMA for the request and result mailboxes.
553 */
554 if (ISP_MBOXDMASETUP(isp)) {
555 (void) splx(s);
556 printf("%s: can't setup dma mailboxes\n", isp->isp_name);
557 return;
558 }
559
560 mbs.param[0] = MBOX_INIT_RES_QUEUE;
561 mbs.param[1] = RESULT_QUEUE_LEN(isp);
562 mbs.param[2] = (u_int16_t) (isp->isp_result_dma >> 16);
563 mbs.param[3] = (u_int16_t) (isp->isp_result_dma & 0xffff);
564 mbs.param[4] = 0;
565 mbs.param[5] = 0;
566 isp_mboxcmd(isp, &mbs);
567 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
568 (void) splx(s);
569 isp_dumpregs(isp, "set of response queue failed");
570 return;
571 }
572 isp->isp_residx = 0;
573
574 mbs.param[0] = MBOX_INIT_REQ_QUEUE;
575 mbs.param[1] = RQUEST_QUEUE_LEN(isp);
576 mbs.param[2] = (u_int16_t) (isp->isp_rquest_dma >> 16);
577 mbs.param[3] = (u_int16_t) (isp->isp_rquest_dma & 0xffff);
578 mbs.param[4] = 0;
579 mbs.param[5] = 0;
580 isp_mboxcmd(isp, &mbs);
581 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
582 (void) splx(s);
583 isp_dumpregs(isp, "set of request queue failed");
584 return;
585 }
586 isp->isp_reqidx = 0;
587
588 /*
589 * Unfortunately, this is the only way right now for
590 * forcing a sync renegotiation. If we boot off of
591 * an Alpha, it's put the chip in SYNC mode, but we
592 * haven't necessarily set up the parameters the
593 * same, so we'll have to yank the reset line to
594 * get everyone to renegotiate.
595 */
596
597 mbs.param[0] = MBOX_BUS_RESET;
598 mbs.param[1] = 2;
599 isp_mboxcmd(isp, &mbs);
600 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
601 (void) splx(s);
602 isp_dumpregs(isp, "SCSI bus reset failed");
603 }
604 /*
605 * This is really important to have set after a bus reset.
606 */
607 isp->isp_sendmarker = 1;
608 (void) splx(s);
609 isp->isp_state = ISP_INITSTATE;
610 }
611
612 static void
613 isp_fibre_init(isp)
614 struct ispsoftc *isp;
615 {
616 fcparam *fcp;
617 isp_icb_t *icbp;
618 mbreg_t mbs;
619 int s, count;
620
621 fcp = isp->isp_param;
622
623 fcp->isp_retry_count = 0;
624 fcp->isp_retry_delay = 1;
625
626 s = splbio();
627 mbs.param[0] = MBOX_SET_RETRY_COUNT;
628 mbs.param[1] = fcp->isp_retry_count;
629 mbs.param[2] = fcp->isp_retry_delay;
630 isp_mboxcmd(isp, &mbs);
631 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
632 (void) splx(s);
633 isp_dumpregs(isp, "failed to set retry count and delay");
634 return;
635 }
636
637 if (ISP_MBOXDMASETUP(isp)) {
638 (void) splx(s);
639 printf("%s: can't setup DMA for mailboxes\n", isp->isp_name);
640 return;
641 }
642
643 icbp = (isp_icb_t *) fcp->isp_scratch;
644 bzero(icbp, sizeof (*icbp));
645 #if 0
646 icbp->icb_maxfrmlen = ICB_DFLT_FRMLEN;
647 MAKE_NODE_NAME(isp, icbp);
648 icbp->icb_rqstqlen = RQUEST_QUEUE_LEN(isp);
649 icbp->icb_rsltqlen = RESULT_QUEUE_LEN(isp);
650 icbp->icb_rqstaddr[0] = (u_int16_t) (isp->isp_rquest_dma & 0xffff);
651 icbp->icb_rqstaddr[1] = (u_int16_t) (isp->isp_rquest_dma >> 16);
652 icbp->icb_respaddr[0] = (u_int16_t) (isp->isp_result_dma & 0xffff);
653 icbp->icb_respaddr[1] = (u_int16_t) (isp->isp_result_dma >> 16);
654 #endif
655 icbp->icb_version = 1;
656 icbp->icb_maxfrmlen = ICB_DFLT_FRMLEN;
657 icbp->icb_maxalloc = 256;
658 icbp->icb_execthrottle = 16;
659 icbp->icb_retry_delay = 5;
660 icbp->icb_retry_count = 0;
661 MAKE_NODE_NAME(isp, icbp);
662 icbp->icb_rqstqlen = RQUEST_QUEUE_LEN(isp);
663 icbp->icb_rsltqlen = RESULT_QUEUE_LEN(isp);
664 icbp->icb_rqstaddr[0] = (u_int16_t) (isp->isp_rquest_dma & 0xffff);
665 icbp->icb_rqstaddr[1] = (u_int16_t) (isp->isp_rquest_dma >> 16);
666 icbp->icb_respaddr[0] = (u_int16_t) (isp->isp_result_dma & 0xffff);
667 icbp->icb_respaddr[1] = (u_int16_t) (isp->isp_result_dma >> 16);
668
669 mbs.param[0] = MBOX_INIT_FIRMWARE;
670 mbs.param[1] = 0;
671 mbs.param[2] = (u_int16_t) (fcp->isp_scdma >> 16);
672 mbs.param[3] = (u_int16_t) (fcp->isp_scdma & 0xffff);
673 mbs.param[4] = 0;
674 mbs.param[5] = 0;
675 mbs.param[6] = 0;
676 mbs.param[7] = 0;
677 isp_mboxcmd(isp, &mbs);
678 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
679 (void) splx(s);
680 isp_dumpregs(isp, "INIT FIRMWARE failed");
681 return;
682 }
683 isp->isp_reqidx = 0;
684 isp->isp_residx = 0;
685
686 /*
687 * Wait up to 3 seconds for FW to go to READY state.
688 *
689 * This is all very much not right. The problem here
690 * is that the cable may not be plugged in, or there
691 * may be many many members of the loop that haven't
692 * been logged into.
693 *
694 * This model of doing things doesn't support dynamic
695 * attachment, so we just plain lose (for now).
696 */
697 for (count = 0; count < 3000; count++) {
698 isp_fw_state(isp);
699 if (fcp->isp_fwstate == FW_READY)
700 break;
701 delay(1000); /* wait one millisecond */
702 }
703
704 isp->isp_sendmarker = 1;
705
706 (void) splx(s);
707 isp->isp_state = ISP_INITSTATE;
708 }
709
710 /*
711 * Complete attachment of Hardware, include subdevices.
712 */
713 void
714 isp_attach(isp)
715 struct ispsoftc *isp;
716 {
717 /*
718 * Start the watchdog timer.
719 */
720 timeout(isp_watch, isp, WATCHI);
721
722 /*
723 * And complete initialization
724 */
725 isp->isp_state = ISP_RUNSTATE;
726 isp->isp_link.scsipi_scsi.channel = SCSI_CHANNEL_ONLY_ONE;
727 isp->isp_link.adapter_softc = isp;
728 isp->isp_link.device = &isp_dev;
729 isp->isp_link.adapter = &isp_switch;
730
731 if (isp->isp_type & ISP_HA_FC) {
732 fcparam *fcp = isp->isp_param;
733 mbreg_t mbs;
734 int s;
735
736 isp->isp_link.scsipi_scsi.max_target = MAX_FC_TARG-1;
737 isp->isp_link.openings = RQUEST_QUEUE_LEN(isp)/(MAX_FC_TARG-1);
738 s = splbio();
739 mbs.param[0] = MBOX_GET_LOOP_ID;
740 isp_mboxcmd(isp, &mbs);
741 (void) splx(s);
742 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
743 isp_dumpregs(isp, "GET LOOP ID failed");
744 return;
745 }
746 fcp->isp_loopid = mbs.param[1];
747 if (fcp->isp_loopid) {
748 printf("%s: Loop ID 0x%x\n", isp->isp_name,
749 fcp->isp_loopid);
750 }
751 isp->isp_link.scsipi_scsi.adapter_target = 0xff;
752 } else {
753 isp->isp_link.openings = RQUEST_QUEUE_LEN(isp)/(MAX_TARGETS-1);
754 isp->isp_link.scsipi_scsi.max_target = MAX_TARGETS-1;
755 isp->isp_link.scsipi_scsi.adapter_target =
756 ((sdparam *)isp->isp_param)->isp_initiator_id;
757 }
758 if (isp->isp_link.openings < 2)
759 isp->isp_link.openings = 2;
760 isp->isp_link.type = BUS_SCSI;
761 config_found((void *)isp, &isp->isp_link, scsiprint);
762 }
763
764
765 /*
766 * Free any associated resources prior to decommissioning.
767 */
768 void
769 isp_uninit(isp)
770 struct ispsoftc *isp;
771 {
772 untimeout(isp_watch, isp);
773 }
774
775 /*
776 * minphys our xfers
777 *
778 * Unfortunately, the buffer pointer describes the target device- not the
779 * adapter device, so we can't use the pointer to find out what kind of
780 * adapter we are and adjust accordingly.
781 */
782
783 static void
784 ispminphys(bp)
785 struct buf *bp;
786 {
787 /*
788 * XX: Only the 1020 has a 24 bit limit.
789 */
790 if (bp->b_bcount >= (1 << 24)) {
791 bp->b_bcount = (1 << 24);
792 }
793 minphys(bp);
794 }
795
796 /*
797 * start an xfer
798 */
799 static int32_t
800 ispscsicmd(xs)
801 struct scsipi_xfer *xs;
802 {
803 struct ispsoftc *isp;
804 u_int8_t iptr, optr;
805 union {
806 ispreq_t *_reqp;
807 ispreqt2_t *_t2reqp;
808 } _u;
809 #define reqp _u._reqp
810 #define t2reqp _u._t2reqp
811 int s, i;
812
813 isp = xs->sc_link->adapter_softc;
814
815 if (isp->isp_type & ISP_HA_FC) {
816 if (xs->cmdlen > 12) {
817 printf("%s: unsupported cdb length for fibre (%d)\n",
818 isp->isp_name, xs->cmdlen);
819 xs->error = XS_DRIVER_STUFFUP;
820 return (COMPLETE);
821 }
822 }
823 optr = ISP_READ(isp, OUTMAILBOX4);
824 iptr = isp->isp_reqidx;
825
826 reqp = (ispreq_t *) ISP_QUEUE_ENTRY(isp->isp_rquest, iptr);
827 iptr = (iptr + 1) & (RQUEST_QUEUE_LEN(isp) - 1);
828 if (iptr == optr) {
829 printf("%s: Request Queue Overflow\n", isp->isp_name);
830 xs->error = XS_DRIVER_STUFFUP;
831 return (TRY_AGAIN_LATER);
832 }
833
834 s = splbio();
835 if (isp->isp_type & ISP_HA_FC)
836 DISABLE_INTS(isp);
837
838 if (isp->isp_sendmarker) {
839 ispmarkreq_t *marker = (ispmarkreq_t *) reqp;
840
841 bzero((void *) marker, sizeof (*marker));
842 marker->req_header.rqs_entry_count = 1;
843 marker->req_header.rqs_entry_type = RQSTYPE_MARKER;
844 marker->req_modifier = SYNC_ALL;
845
846 isp->isp_sendmarker = 0;
847
848 if (((iptr + 1) & (RQUEST_QUEUE_LEN(isp) - 1)) == optr) {
849 ISP_WRITE(isp, INMAILBOX4, iptr);
850 isp->isp_reqidx = iptr;
851
852 if (isp->isp_type & ISP_HA_FC)
853 ENABLE_INTS(isp);
854 (void) splx(s);
855 printf("%s: Request Queue Overflow+\n", isp->isp_name);
856 xs->error = XS_DRIVER_STUFFUP;
857 return (TRY_AGAIN_LATER);
858 }
859 reqp = (ispreq_t *) ISP_QUEUE_ENTRY(isp->isp_rquest, iptr);
860 iptr = (iptr + 1) & (RQUEST_QUEUE_LEN(isp) - 1);
861 }
862
863 bzero((void *) reqp, sizeof (_u));
864 reqp->req_header.rqs_entry_count = 1;
865 if (isp->isp_type & ISP_HA_FC) {
866 reqp->req_header.rqs_entry_type = RQSTYPE_T2RQS;
867 } else {
868 reqp->req_header.rqs_entry_type = RQSTYPE_REQUEST;
869 }
870 reqp->req_header.rqs_flags = 0;
871 reqp->req_header.rqs_seqno = isp->isp_seqno++;
872
873 for (i = 0; i < RQUEST_QUEUE_LEN(isp); i++) {
874 if (isp->isp_xflist[i] == NULL)
875 break;
876 }
877 if (i == RQUEST_QUEUE_LEN(isp)) {
878 panic("%s: ran out of xflist pointers\n", isp->isp_name);
879 /* NOTREACHED */
880 } else {
881 /*
882 * Never have a handle that is zero, so
883 * set req_handle off by one.
884 */
885 isp->isp_xflist[i] = xs;
886 reqp->req_handle = i+1;
887 }
888
889 if (isp->isp_type & ISP_HA_FC) {
890 /*
891 * See comment in isp_intr
892 */
893 xs->resid = 0;
894 /*
895 * The QL2100 always requires some kind of tag.
896 */
897 if (xs->flags & SCSI_POLL) {
898 t2reqp->req_flags = REQFLAG_STAG;
899 } else {
900 t2reqp->req_flags = REQFLAG_OTAG;
901 }
902 } else {
903 if (xs->flags & SCSI_POLL) {
904 reqp->req_flags = 0;
905 } else {
906 reqp->req_flags = REQFLAG_OTAG;
907 }
908 }
909 reqp->req_lun_trn = xs->sc_link->scsipi_scsi.lun;
910 reqp->req_target = xs->sc_link->scsipi_scsi.target;
911 if (isp->isp_type & ISP_HA_SCSI) {
912 reqp->req_cdblen = xs->cmdlen;
913 }
914 bcopy((void *)xs->cmd, reqp->req_cdb, xs->cmdlen);
915
916 IDPRINTF(5, ("%s(%d.%d): START%d cmd 0x%x datalen %d\n", isp->isp_name,
917 xs->sc_link->scsipi_scsi.target, xs->sc_link->scsipi_scsi.lun,
918 reqp->req_header.rqs_seqno, *(u_char *) xs->cmd, xs->datalen));
919
920 reqp->req_time = xs->timeout / 1000;
921 if (reqp->req_time == 0 && xs->timeout)
922 reqp->req_time = 1;
923 if (ISP_DMASETUP(isp, xs, reqp, &iptr, optr)) {
924 if (isp->isp_type & ISP_HA_FC)
925 ENABLE_INTS(isp);
926 (void) splx(s);
927 xs->error = XS_DRIVER_STUFFUP;
928 return (COMPLETE);
929 }
930 xs->error = 0;
931 ISP_WRITE(isp, INMAILBOX4, iptr);
932 isp->isp_reqidx = iptr;
933 if (isp->isp_type & ISP_HA_FC)
934 ENABLE_INTS(isp);
935 (void) splx(s);
936 if ((xs->flags & SCSI_POLL) == 0) {
937 return (SUCCESSFULLY_QUEUED);
938 }
939
940 /*
941 * If we can't use interrupts, poll on completion.
942 */
943 if (isp_poll(isp, xs, xs->timeout)) {
944 #if 0
945 /* XXX try to abort it, or whatever */
946 if (isp_poll(isp, xs, xs->timeout) {
947 /* XXX really nuke it */
948 }
949 #endif
950 /*
951 * If no other error occurred but we didn't finish,
952 * something bad happened.
953 */
954 if ((xs->flags & ITSDONE) == 0 && xs->error == XS_NOERROR) {
955 isp_lostcmd(isp, xs, reqp);
956 xs->error = XS_DRIVER_STUFFUP;
957 }
958 }
959 return (COMPLETE);
960 #undef reqp
961 #undef t2reqp
962 }
963
964 /*
965 * Interrupt Service Routine(s)
966 */
967
968 int
969 isp_poll(isp, xs, mswait)
970 struct ispsoftc *isp;
971 struct scsipi_xfer *xs;
972 int mswait;
973 {
974
975 while (mswait) {
976 /* Try the interrupt handling routine */
977 (void)isp_intr((void *)isp);
978
979 /* See if the xs is now done */
980 if (xs->flags & ITSDONE)
981 return (0);
982 delay(1000); /* wait one millisecond */
983 mswait--;
984 }
985 return (1);
986 }
987
988 int
989 isp_intr(arg)
990 void *arg;
991 {
992 struct scsipi_xfer *xs;
993 struct ispsoftc *isp = arg;
994 u_int16_t iptr, optr, isr;
995
996 isr = ISP_READ(isp, BIU_ISR);
997 if (isp->isp_type & ISP_HA_FC) {
998 if (isr == 0 || (isr & BIU2100_ISR_RISC_INT) == 0) {
999 if (isr) {
1000 IDPRINTF(3, ("%s: isp_intr isr=%x\n",
1001 isp->isp_name, isr));
1002 }
1003 return (0);
1004 }
1005 } else {
1006 if (isr == 0 || (isr & BIU_ISR_RISC_INT) == 0) {
1007 if (isr) {
1008 IDPRINTF(3, ("%s: isp_intr isr=%x\n",
1009 isp->isp_name, isr));
1010 }
1011 return (0);
1012 }
1013 }
1014
1015 optr = isp->isp_residx;
1016 if (ISP_READ(isp, BIU_SEMA) & 1) {
1017 u_int16_t mbox0 = ISP_READ(isp, OUTMAILBOX0);
1018 switch (mbox0) {
1019 case ASYNC_BUS_RESET:
1020 case ASYNC_TIMEOUT_RESET:
1021 printf("%s: bus or timeout reset\n", isp->isp_name);
1022 isp->isp_sendmarker = 1;
1023 break;
1024 case ASYNC_LIP_OCCURRED:
1025 printf("%s: LIP occurred\n", isp->isp_name);
1026 break;
1027 case ASYNC_LOOP_UP:
1028 printf("%s: Loop UP\n", isp->isp_name);
1029 break;
1030 case ASYNC_LOOP_DOWN:
1031 printf("%s: Loop DOWN\n", isp->isp_name);
1032 break;
1033 default:
1034 printf("%s: async %x\n", isp->isp_name, mbox0);
1035 break;
1036 }
1037 ISP_WRITE(isp, BIU_SEMA, 0);
1038 }
1039
1040 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
1041 iptr = ISP_READ(isp, OUTMAILBOX5);
1042 if (optr == iptr) {
1043 IDPRINTF(3, ("why intr? isr %x iptr %x optr %x\n",
1044 isr, optr, iptr));
1045 }
1046 ENABLE_INTS(isp);
1047
1048 while (optr != iptr) {
1049 ispstatusreq_t *sp;
1050 int buddaboom = 0;
1051
1052 sp = (ispstatusreq_t *) ISP_QUEUE_ENTRY(isp->isp_result, optr);
1053
1054 optr = (optr + 1) & (RESULT_QUEUE_LEN(isp)-1);
1055 if (sp->req_header.rqs_entry_type != RQSTYPE_RESPONSE) {
1056 printf("%s: not RESPONSE in RESPONSE Queue (0x%x)\n",
1057 isp->isp_name, sp->req_header.rqs_entry_type);
1058 if (sp->req_header.rqs_entry_type != RQSTYPE_REQUEST) {
1059 ISP_WRITE(isp, INMAILBOX5, optr);
1060 continue;
1061 }
1062 buddaboom = 1;
1063 }
1064
1065 if (sp->req_header.rqs_flags & 0xf) {
1066 if (sp->req_header.rqs_flags & RQSFLAG_CONTINUATION) {
1067 ISP_WRITE(isp, INMAILBOX5, optr);
1068 continue;
1069 }
1070 printf("%s: rqs_flags=%x\n", isp->isp_name,
1071 sp->req_header.rqs_flags & 0xf);
1072 }
1073 if (sp->req_handle > RQUEST_QUEUE_LEN(isp) ||
1074 sp->req_handle < 1) {
1075 printf("%s: bad request handle %d\n", isp->isp_name,
1076 sp->req_handle);
1077 ISP_WRITE(isp, INMAILBOX5, optr);
1078 continue;
1079 }
1080 xs = (struct scsipi_xfer *) isp->isp_xflist[sp->req_handle - 1];
1081 if (xs == NULL) {
1082 printf("%s: NULL xs in xflist\n", isp->isp_name);
1083 ISP_WRITE(isp, INMAILBOX5, optr);
1084 continue;
1085 }
1086 isp->isp_xflist[sp->req_handle - 1] = NULL;
1087 if (sp->req_status_flags & RQSTF_BUS_RESET) {
1088 isp->isp_sendmarker = 1;
1089 }
1090 if (buddaboom) {
1091 xs->error = XS_DRIVER_STUFFUP;
1092 }
1093 xs->status = sp->req_scsi_status & 0xff;
1094 if (isp->isp_type & ISP_HA_SCSI) {
1095 if (sp->req_state_flags & RQSF_GOT_SENSE) {
1096 bcopy(sp->req_sense_data, &xs->sense.scsi_sense,
1097 sizeof (xs->sense.scsi_sense));
1098 xs->error = XS_SENSE;
1099 }
1100 } else {
1101 if (xs->status == SCSI_CHECK) {
1102 xs->error = XS_SENSE;
1103 bcopy(sp->req_sense_data, &xs->sense.scsi_sense,
1104 sizeof (xs->sense.scsi_sense));
1105 sp->req_state_flags |= RQSF_GOT_SENSE;
1106 }
1107 }
1108 if (xs->error == 0 && xs->status == SCSI_BUSY) {
1109 xs->error = XS_BUSY;
1110 }
1111
1112 if (sp->req_header.rqs_entry_type == RQSTYPE_RESPONSE) {
1113 if (xs->error == 0 && sp->req_completion_status)
1114 xs->error = isp_parse_status(isp, sp, xs);
1115 } else {
1116 printf("%s: unknown return %x\n", isp->isp_name,
1117 sp->req_header.rqs_entry_type);
1118 if (xs->error == 0)
1119 xs->error = XS_DRIVER_STUFFUP;
1120 }
1121 if (isp->isp_type & ISP_HA_SCSI) {
1122 xs->resid = sp->req_resid;
1123 } else if (sp->req_scsi_status & RQCS_RU) {
1124 xs->resid = sp->req_resid;
1125 IDPRINTF(3, ("%s: cnt %d rsd %d\n", isp->isp_name,
1126 xs->datalen, sp->req_resid));
1127 }
1128 xs->flags |= ITSDONE;
1129 if (xs->datalen) {
1130 ISP_DMAFREE(isp, xs, sp->req_handle - 1);
1131 }
1132 if (isp->isp_dblev >= 5) {
1133 printf("%s(%d.%d): FINISH%d cmd 0x%x resid %d STS %x",
1134 isp->isp_name, xs->sc_link->scsipi_scsi.target,
1135 xs->sc_link->scsipi_scsi.lun, sp->req_header.rqs_seqno,
1136 *(u_char *) xs->cmd, xs->resid, xs->status);
1137 if (sp->req_state_flags & RQSF_GOT_SENSE) {
1138 printf(" Skey: %x", xs->sense.scsi_sense.flags);
1139 if (xs->error != XS_SENSE) {
1140 printf(" BUT NOT SET");
1141 }
1142 }
1143 printf(" xs->error %d\n", xs->error);
1144 }
1145 ISP_WRITE(isp, INMAILBOX5, optr);
1146 scsipi_done(xs);
1147 }
1148 isp->isp_residx = optr;
1149 return (1);
1150 }
1151
1152 /*
1153 * Support routines.
1154 */
1155
1156 static int
1157 isp_parse_status(isp, sp, xs)
1158 struct ispsoftc *isp;
1159 ispstatusreq_t *sp;
1160 struct scsipi_xfer *xs;
1161 {
1162 switch (sp->req_completion_status) {
1163 case RQCS_COMPLETE:
1164 return (XS_NOERROR);
1165 break;
1166
1167 case RQCS_INCOMPLETE:
1168 if ((sp->req_state_flags & RQSF_GOT_TARGET) == 0) {
1169 return (XS_SELTIMEOUT);
1170 }
1171 printf("%s: incomplete, state %x\n",
1172 isp->isp_name, sp->req_state_flags);
1173 break;
1174
1175 case RQCS_TRANSPORT_ERROR:
1176 printf("%s: transport error\n", isp->isp_name);
1177 isp_prtstst(sp);
1178 break;
1179
1180 case RQCS_DATA_OVERRUN:
1181 if (isp->isp_type & ISP_HA_FC) {
1182 xs->resid = sp->req_resid;
1183 break;
1184 }
1185 return (XS_NOERROR);
1186
1187 case RQCS_DATA_UNDERRUN:
1188 if (isp->isp_type & ISP_HA_FC) {
1189 xs->resid = sp->req_resid;
1190 break;
1191 }
1192 return (XS_NOERROR);
1193
1194 case RQCS_TIMEOUT:
1195 return (XS_TIMEOUT);
1196
1197 case RQCS_RESET_OCCURRED:
1198 printf("%s: reset occurred\n", isp->isp_name);
1199 isp->isp_sendmarker = 1;
1200 break;
1201
1202 case RQCS_ABORTED:
1203 printf("%s: command aborted\n", isp->isp_name);
1204 isp->isp_sendmarker = 1;
1205 break;
1206
1207 case RQCS_PORT_UNAVAILABLE:
1208 /*
1209 * No such port on the loop. Moral equivalent of SELTIMEO
1210 */
1211 return (XS_SELTIMEOUT);
1212
1213 case RQCS_PORT_LOGGED_OUT:
1214 printf("%s: port logout for target %d\n",
1215 isp->isp_name, xs->sc_link->scsipi_scsi.target);
1216 break;
1217
1218 case RQCS_PORT_CHANGED:
1219 printf("%s: port changed for target %d\n",
1220 isp->isp_name, xs->sc_link->scsipi_scsi.target);
1221 break;
1222
1223 case RQCS_PORT_BUSY:
1224 printf("%s: port busy for target %d\n",
1225 isp->isp_name, xs->sc_link->scsipi_scsi.target);
1226 return (XS_BUSY);
1227
1228 default:
1229 printf("%s: comp status %x\n", isp->isp_name,
1230 sp->req_completion_status);
1231 break;
1232 }
1233 return (XS_DRIVER_STUFFUP);
1234 }
1235
1236 #define HINIB(x) ((x) >> 0x4)
1237 #define LONIB(x) ((x) & 0xf)
1238 #define MAKNIB(a, b) (((a) << 4) | (b))
1239 static u_int8_t mbpcnt[] = {
1240 MAKNIB(1, 1), /* 0x00: MBOX_NO_OP */
1241 MAKNIB(5, 5), /* 0x01: MBOX_LOAD_RAM */
1242 MAKNIB(2, 0), /* 0x02: MBOX_EXEC_FIRMWARE */
1243 MAKNIB(5, 5), /* 0x03: MBOX_DUMP_RAM */
1244 MAKNIB(3, 3), /* 0x04: MBOX_WRITE_RAM_WORD */
1245 MAKNIB(2, 3), /* 0x05: MBOX_READ_RAM_WORD */
1246 MAKNIB(6, 6), /* 0x06: MBOX_MAILBOX_REG_TEST */
1247 MAKNIB(2, 3), /* 0x07: MBOX_VERIFY_CHECKSUM */
1248 MAKNIB(1, 3), /* 0x08: MBOX_ABOUT_FIRMWARE */
1249 MAKNIB(0, 0), /* 0x09: */
1250 MAKNIB(0, 0), /* 0x0a: */
1251 MAKNIB(0, 0), /* 0x0b: */
1252 MAKNIB(0, 0), /* 0x0c: */
1253 MAKNIB(0, 0), /* 0x0d: */
1254 MAKNIB(1, 2), /* 0x0e: MBOX_CHECK_FIRMWARE */
1255 MAKNIB(0, 0), /* 0x0f: */
1256 MAKNIB(5, 5), /* 0x10: MBOX_INIT_REQ_QUEUE */
1257 MAKNIB(6, 6), /* 0x11: MBOX_INIT_RES_QUEUE */
1258 MAKNIB(4, 4), /* 0x12: MBOX_EXECUTE_IOCB */
1259 MAKNIB(2, 2), /* 0x13: MBOX_WAKE_UP */
1260 MAKNIB(1, 6), /* 0x14: MBOX_STOP_FIRMWARE */
1261 MAKNIB(4, 4), /* 0x15: MBOX_ABORT */
1262 MAKNIB(2, 2), /* 0x16: MBOX_ABORT_DEVICE */
1263 MAKNIB(3, 3), /* 0x17: MBOX_ABORT_TARGET */
1264 MAKNIB(2, 2), /* 0x18: MBOX_BUS_RESET */
1265 MAKNIB(2, 3), /* 0x19: MBOX_STOP_QUEUE */
1266 MAKNIB(2, 3), /* 0x1a: MBOX_START_QUEUE */
1267 MAKNIB(2, 3), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
1268 MAKNIB(2, 3), /* 0x1c: MBOX_ABORT_QUEUE */
1269 MAKNIB(2, 4), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
1270 MAKNIB(0, 0), /* 0x1e: */
1271 MAKNIB(1, 3), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
1272 MAKNIB(1, 2), /* 0x20: MBOX_GET_INIT_SCSI_ID */
1273 MAKNIB(1, 2), /* 0x21: MBOX_GET_SELECT_TIMEOUT */
1274 MAKNIB(1, 3), /* 0x22: MBOX_GET_RETRY_COUNT */
1275 MAKNIB(1, 2), /* 0x23: MBOX_GET_TAG_AGE_LIMIT */
1276 MAKNIB(1, 2), /* 0x24: MBOX_GET_CLOCK_RATE */
1277 MAKNIB(1, 2), /* 0x25: MBOX_GET_ACT_NEG_STATE */
1278 MAKNIB(1, 2), /* 0x26: MBOX_GET_ASYNC_DATA_SETUP_TIME */
1279 MAKNIB(1, 3), /* 0x27: MBOX_GET_PCI_PARAMS */
1280 MAKNIB(2, 4), /* 0x28: MBOX_GET_TARGET_PARAMS */
1281 MAKNIB(2, 4), /* 0x29: MBOX_GET_DEV_QUEUE_PARAMS */
1282 MAKNIB(0, 0), /* 0x2a: */
1283 MAKNIB(0, 0), /* 0x2b: */
1284 MAKNIB(0, 0), /* 0x2c: */
1285 MAKNIB(0, 0), /* 0x2d: */
1286 MAKNIB(0, 0), /* 0x2e: */
1287 MAKNIB(0, 0), /* 0x2f: */
1288 MAKNIB(2, 2), /* 0x30: MBOX_SET_INIT_SCSI_ID */
1289 MAKNIB(2, 2), /* 0x31: MBOX_SET_SELECT_TIMEOUT */
1290 MAKNIB(3, 3), /* 0x32: MBOX_SET_RETRY_COUNT */
1291 MAKNIB(2, 2), /* 0x33: MBOX_SET_TAG_AGE_LIMIT */
1292 MAKNIB(2, 2), /* 0x34: MBOX_SET_CLOCK_RATE */
1293 MAKNIB(2, 2), /* 0x35: MBOX_SET_ACTIVE_NEG_STATE */
1294 MAKNIB(2, 2), /* 0x36: MBOX_SET_ASYNC_DATA_SETUP_TIME */
1295 MAKNIB(3, 3), /* 0x37: MBOX_SET_PCI_CONTROL_PARAMS */
1296 MAKNIB(4, 4), /* 0x38: MBOX_SET_TARGET_PARAMS */
1297 MAKNIB(4, 4), /* 0x39: MBOX_SET_DEV_QUEUE_PARAMS */
1298 MAKNIB(0, 0), /* 0x3a: */
1299 MAKNIB(0, 0), /* 0x3b: */
1300 MAKNIB(0, 0), /* 0x3c: */
1301 MAKNIB(0, 0), /* 0x3d: */
1302 MAKNIB(0, 0), /* 0x3e: */
1303 MAKNIB(0, 0), /* 0x3f: */
1304 MAKNIB(1, 2), /* 0x40: MBOX_RETURN_BIOS_BLOCK_ADDR */
1305 MAKNIB(6, 1), /* 0x41: MBOX_WRITE_FOUR_RAM_WORDS */
1306 MAKNIB(2, 3), /* 0x42: MBOX_EXEC_BIOS_IOCB */
1307 MAKNIB(0, 0), /* 0x43: */
1308 MAKNIB(0, 0), /* 0x44: */
1309 MAKNIB(0, 0), /* 0x45: */
1310 MAKNIB(0, 0), /* 0x46: */
1311 MAKNIB(0, 0), /* 0x47: */
1312 MAKNIB(0, 0), /* 0x48: */
1313 MAKNIB(0, 0), /* 0x49: */
1314 MAKNIB(0, 0), /* 0x4a: */
1315 MAKNIB(0, 0), /* 0x4b: */
1316 MAKNIB(0, 0), /* 0x4c: */
1317 MAKNIB(0, 0), /* 0x4d: */
1318 MAKNIB(0, 0), /* 0x4e: */
1319 MAKNIB(0, 0), /* 0x4f: */
1320 MAKNIB(0, 0), /* 0x50: */
1321 MAKNIB(0, 0), /* 0x51: */
1322 MAKNIB(0, 0), /* 0x52: */
1323 MAKNIB(0, 0), /* 0x53: */
1324 MAKNIB(8, 0), /* 0x54: MBOX_EXEC_COMMAND_IOCB_A64 */
1325 MAKNIB(0, 0), /* 0x55: */
1326 MAKNIB(0, 0), /* 0x56: */
1327 MAKNIB(0, 0), /* 0x57: */
1328 MAKNIB(0, 0), /* 0x58: */
1329 MAKNIB(0, 0), /* 0x59: */
1330 MAKNIB(0, 0), /* 0x5a: */
1331 MAKNIB(0, 0), /* 0x5b: */
1332 MAKNIB(0, 0), /* 0x5c: */
1333 MAKNIB(0, 0), /* 0x5d: */
1334 MAKNIB(0, 0), /* 0x5e: */
1335 MAKNIB(0, 0), /* 0x5f: */
1336 MAKNIB(8, 6), /* 0x60: MBOX_INIT_FIRMWARE */
1337 MAKNIB(0, 0), /* 0x60: MBOX_GET_INIT_CONTROL_BLOCK (FORMAT?) */
1338 MAKNIB(2, 1), /* 0x62: MBOX_INIT_LIP */
1339 MAKNIB(8, 1), /* 0x63: MBOX_GET_FC_AL_POSITION_MAP */
1340 MAKNIB(8, 1), /* 0x64: MBOX_GET_PORT_DB */
1341 MAKNIB(3, 1), /* 0x65: MBOX_CLEAR_ACA */
1342 MAKNIB(3, 1), /* 0x66: MBOX_TARGET_RESET */
1343 MAKNIB(3, 1), /* 0x67: MBOX_CLEAR_TASK_SET */
1344 MAKNIB(3, 1), /* 0x69: MBOX_ABORT_TASK_SET */
1345 MAKNIB(1, 2) /* 0x69: MBOX_GET_FW_STATE */
1346 };
1347 #define NMBCOM (sizeof (mbpcnt) / sizeof (mbpcnt[0]))
1348
1349 static void
1350 isp_mboxcmd(isp, mbp)
1351 struct ispsoftc *isp;
1352 mbreg_t *mbp;
1353 {
1354 int outparam, inparam;
1355 int loops;
1356 u_int8_t opcode;
1357
1358 if (mbp->param[0] == ISP2100_SET_PCI_PARAM) {
1359 opcode = mbp->param[0] = MBOX_SET_PCI_PARAMETERS;
1360 inparam = 4;
1361 outparam = 4;
1362 goto command_known;
1363 } else if (mbp->param[0] > NMBCOM) {
1364 printf("%s: bad command %x\n", isp->isp_name, mbp->param[0]);
1365 return;
1366 }
1367
1368 opcode = mbp->param[0];
1369 inparam = HINIB(mbpcnt[mbp->param[0]]);
1370 outparam = LONIB(mbpcnt[mbp->param[0]]);
1371
1372 if (inparam == 0 && outparam == 0) {
1373 printf("%s: no parameters for %x\n", isp->isp_name,
1374 mbp->param[0]);
1375 return;
1376 }
1377
1378
1379 command_known:
1380 /*
1381 * Make sure we can send some words..
1382 */
1383
1384 loops = MBOX_DELAY_COUNT;
1385 while ((ISP_READ(isp, HCCR) & HCCR_HOST_INT) != 0) {
1386 delay(100);
1387 if (--loops < 0) {
1388 printf("%s: isp_mboxcmd timeout #1\n", isp->isp_name);
1389 return;
1390 }
1391 }
1392
1393 /*
1394 * Write input parameters
1395 */
1396 switch (inparam) {
1397 case 8: ISP_WRITE(isp, INMAILBOX7, mbp->param[7]); mbp->param[7] = 0;
1398 case 7: ISP_WRITE(isp, INMAILBOX6, mbp->param[6]); mbp->param[6] = 0;
1399 case 6: ISP_WRITE(isp, INMAILBOX5, mbp->param[5]); mbp->param[5] = 0;
1400 case 5: ISP_WRITE(isp, INMAILBOX4, mbp->param[4]); mbp->param[4] = 0;
1401 case 4: ISP_WRITE(isp, INMAILBOX3, mbp->param[3]); mbp->param[3] = 0;
1402 case 3: ISP_WRITE(isp, INMAILBOX2, mbp->param[2]); mbp->param[2] = 0;
1403 case 2: ISP_WRITE(isp, INMAILBOX1, mbp->param[1]); mbp->param[1] = 0;
1404 case 1: ISP_WRITE(isp, INMAILBOX0, mbp->param[0]); mbp->param[0] = 0;
1405 }
1406
1407 /*
1408 * Clear semaphore on mailbox registers
1409 */
1410 ISP_WRITE(isp, BIU_SEMA, 0);
1411
1412 /*
1413 * Clear RISC int condition.
1414 */
1415 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
1416
1417 /*
1418 * Set Host Interrupt condition so that RISC will pick up mailbox regs.
1419 */
1420 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
1421
1422 /*
1423 * Wait until RISC int is set, except 2100
1424 */
1425 if ((isp->isp_type & ISP_HA_FC) == 0) {
1426 loops = MBOX_DELAY_COUNT;
1427 while ((ISP_READ(isp, BIU_ISR) & BIU_ISR_RISC_INT) == 0) {
1428 delay(100);
1429 if (--loops < 0) {
1430 printf("%s: isp_mboxcmd timeout #2\n",
1431 isp->isp_name);
1432 return;
1433 }
1434 }
1435 }
1436
1437 /*
1438 * Check to make sure that the semaphore has been set.
1439 */
1440 loops = MBOX_DELAY_COUNT;
1441 while ((ISP_READ(isp, BIU_SEMA) & 1) == 0) {
1442 delay(100);
1443 if (--loops < 0) {
1444 printf("%s: isp_mboxcmd timeout #3\n", isp->isp_name);
1445 return;
1446 }
1447 }
1448
1449 /*
1450 * Make sure that the MBOX_BUSY has gone away
1451 */
1452 loops = MBOX_DELAY_COUNT;
1453 while (ISP_READ(isp, OUTMAILBOX0) == MBOX_BUSY) {
1454 delay(100);
1455 if (--loops < 0) {
1456 printf("%s: isp_mboxcmd timeout #4\n", isp->isp_name);
1457 return;
1458 }
1459 }
1460
1461
1462 /*
1463 * Pick up output parameters.
1464 */
1465 switch (outparam) {
1466 case 8: mbp->param[7] = ISP_READ(isp, OUTMAILBOX7);
1467 case 7: mbp->param[6] = ISP_READ(isp, OUTMAILBOX6);
1468 case 6: mbp->param[5] = ISP_READ(isp, OUTMAILBOX5);
1469 case 5: mbp->param[4] = ISP_READ(isp, OUTMAILBOX4);
1470 case 4: mbp->param[3] = ISP_READ(isp, OUTMAILBOX3);
1471 case 3: mbp->param[2] = ISP_READ(isp, OUTMAILBOX2);
1472 case 2: mbp->param[1] = ISP_READ(isp, OUTMAILBOX1);
1473 case 1: mbp->param[0] = ISP_READ(isp, OUTMAILBOX0);
1474 }
1475
1476 /*
1477 * Clear RISC int.
1478 */
1479 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
1480
1481 /*
1482 * Release semaphore on mailbox registers
1483 */
1484 ISP_WRITE(isp, BIU_SEMA, 0);
1485
1486 /*
1487 * Just to be chatty here...
1488 */
1489 switch(mbp->param[0]) {
1490 case MBOX_COMMAND_COMPLETE:
1491 break;
1492 case MBOX_INVALID_COMMAND:
1493 /*
1494 * GET_CLOCK_RATE can fail a lot
1495 * So can a couple of other commands.
1496 */
1497 if (isp->isp_dblev > 1 && opcode != MBOX_GET_CLOCK_RATE) {
1498 printf("%s: mbox cmd %x failed with INVALID_COMMAND\n",
1499 isp->isp_name, opcode);
1500 }
1501 break;
1502 case MBOX_HOST_INTERFACE_ERROR:
1503 printf("%s: mbox cmd %x failed with HOST_INTERFACE_ERROR\n",
1504 isp->isp_name, opcode);
1505 break;
1506 case MBOX_TEST_FAILED:
1507 printf("%s: mbox cmd %x failed with TEST_FAILED\n",
1508 isp->isp_name, opcode);
1509 break;
1510 case MBOX_COMMAND_ERROR:
1511 printf("%s: mbox cmd %x failed with COMMAND_ERROR\n",
1512 isp->isp_name, opcode);
1513 break;
1514 case MBOX_COMMAND_PARAM_ERROR:
1515 printf("%s: mbox cmd %x failed with COMMAND_PARAM_ERROR\n",
1516 isp->isp_name, opcode);
1517 break;
1518
1519 case ASYNC_LIP_OCCURRED:
1520 break;
1521
1522 default:
1523 /*
1524 * The expected return of EXEC_FIRMWARE is zero.
1525 */
1526 if ((opcode == MBOX_EXEC_FIRMWARE && mbp->param[0] != 0) ||
1527 (opcode != MBOX_EXEC_FIRMWARE)) {
1528 printf("%s: mbox cmd %x failed with error %x\n",
1529 isp->isp_name, opcode, mbp->param[0]);
1530 }
1531 break;
1532 }
1533 }
1534
1535 static void
1536 isp_lostcmd(struct ispsoftc *isp, struct scsipi_xfer *xs, ispreq_t *req)
1537 {
1538 mbreg_t mbs;
1539
1540 mbs.param[0] = MBOX_GET_FIRMWARE_STATUS;
1541 isp_mboxcmd(isp, &mbs);
1542 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1543 isp_dumpregs(isp, "couldn't GET FIRMWARE STATUS");
1544 return;
1545 }
1546 if (mbs.param[1]) {
1547 printf("%s: %d commands on completion queue\n",
1548 isp->isp_name, mbs.param[1]);
1549 }
1550 if (xs == NULL || xs->sc_link == NULL)
1551 return;
1552
1553 mbs.param[0] = MBOX_GET_DEV_QUEUE_STATUS;
1554 mbs.param[1] =
1555 xs->sc_link->scsipi_scsi.target << 8 | xs->sc_link->scsipi_scsi.lun;
1556 isp_mboxcmd(isp, &mbs);
1557 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1558 isp_dumpregs(isp, "couldn't GET DEVICE QUEUE STATUS");
1559 return;
1560 }
1561 printf("%s: lost command for target %d lun %d, %d active of %d, "
1562 "Queue State: %x\n", isp->isp_name, xs->sc_link->scsipi_scsi.target,
1563 xs->sc_link->scsipi_scsi.lun, mbs.param[2], mbs.param[3], mbs.param[1]);
1564
1565 isp_dumpregs(isp, "lost command");
1566 /*
1567 * XXX: Need to try and do something to recover.
1568 */
1569 #if 0
1570 mbs.param[0] = MBOX_STOP_QUEUE;
1571 mbs.param[1] =
1572 xs->sc_link->scsipi_scsi.target << 8 | xs->sc_link->scsipi_scsi.lun;
1573 isp_mboxcmd(isp, &mbs);
1574 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1575 isp_dumpregs(isp, "couldn't stop device queue");
1576 return;
1577 }
1578 printf("%s: tgt %d lun %d, state %x\n", isp->isp_name,
1579 xs->sc_link->scsipi_scsi.target, xs->sc_link->scsipi_scsi.lun,
1580 mbs.param[2] & 0xff);
1581
1582 /*
1583 * If Queue Aborted, need to do a SendMarker
1584 */
1585 if (mbs.param[1] & 0x1)
1586 isp->isp_sendmarker = 1;
1587 if (req == NULL)
1588 return;
1589
1590 isp->isp_sendmarker = 1;
1591
1592 mbs.param[0] = MBOX_ABORT;
1593 mbs.param[1] =
1594 (xs->sc_link->scsipi_scsi.target << 8) | xs->sc_link->scsipi_scsi.lun;
1595 mbs.param[2] = (req->req_handle - 1) >> 16;
1596 mbs.param[3] = (req->req_handle - 1) & 0xffff;
1597 isp_mboxcmd(isp, &mbs);
1598 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1599 printf("%s: couldn't abort command\n", isp->isp_name );
1600 mbs.param[0] = MBOX_ABORT_DEVICE;
1601 mbs.param[1] = (xs->sc_link->scsipi_scsi.target << 8) |
1602 xs->sc_link->scsipi_scsi.lun;
1603 isp_mboxcmd(isp, &mbs);
1604 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1605 printf("%s: couldn't abort device\n", isp->isp_name );
1606 } else {
1607 if (isp_poll(isp, xs, xs->timeout)) {
1608 isp_lostcmd(isp, xs, NULL);
1609 }
1610 }
1611 } else {
1612 if (isp_poll(isp, xs, xs->timeout)) {
1613 isp_lostcmd(isp, xs, NULL);
1614 }
1615 }
1616 mbs.param[0] = MBOX_START_QUEUE;
1617 mbs.param[1] =
1618 xs->sc_link->scsipi_scsi.target << 8 | xs->sc_link->scsipi_scsi.lun;
1619 isp_mboxcmd(isp, &mbs);
1620 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1621 isp_dumpregs(isp, "couldn't start device queue");
1622 }
1623 #endif
1624 }
1625
1626 static void
1627 isp_dumpregs(struct ispsoftc *isp, const char *msg)
1628 {
1629 printf("%s: %s\n", isp->isp_name, msg);
1630 if (isp->isp_type & ISP_HA_SCSI)
1631 printf("\tbiu_conf1=%x", ISP_READ(isp, BIU_CONF1));
1632 else
1633 printf("\tbiu_csr=%x", ISP_READ(isp, BIU2100_CSR));
1634 printf(" biu_icr=%x biu_isr=%x biu_sema=%x ", ISP_READ(isp, BIU_ICR),
1635 ISP_READ(isp, BIU_ISR), ISP_READ(isp, BIU_SEMA));
1636 printf("risc_hccr=%x\n", ISP_READ(isp, HCCR));
1637
1638 if (isp->isp_type & ISP_HA_SCSI) {
1639 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
1640 printf("\tcdma_conf=%x cdma_sts=%x cdma_fifostat=%x\n",
1641 ISP_READ(isp, CDMA_CONF), ISP_READ(isp, CDMA_STATUS),
1642 ISP_READ(isp, CDMA_FIFO_STS));
1643 printf("\tddma_conf=%x ddma_sts=%x ddma_fifostat=%x\n",
1644 ISP_READ(isp, DDMA_CONF), ISP_READ(isp, DDMA_STATUS),
1645 ISP_READ(isp, DDMA_FIFO_STS));
1646 printf("\tsxp_int=%x sxp_gross=%x sxp(scsi_ctrl)=%x\n",
1647 ISP_READ(isp, SXP_INTERRUPT),
1648 ISP_READ(isp, SXP_GROSS_ERR),
1649 ISP_READ(isp, SXP_PINS_CONTROL));
1650 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
1651 }
1652 ISP_DUMPREGS(isp);
1653 }
1654
1655 static void
1656 isp_fw_state(struct ispsoftc *isp)
1657 {
1658 mbreg_t mbs;
1659 if (isp->isp_type & ISP_HA_FC) {
1660 int once = 0;
1661 fcparam *fcp = isp->isp_param;
1662 again:
1663 mbs.param[0] = MBOX_GET_FW_STATE;
1664 isp_mboxcmd(isp, &mbs);
1665 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1666 if (mbs.param[0] == ASYNC_LIP_OCCURRED) {
1667 if (!once++) {
1668 goto again;
1669 }
1670 }
1671 isp_dumpregs(isp, "GET FIRMWARE STATE failed");
1672 return;
1673 }
1674 fcp->isp_fwstate = mbs.param[1];
1675 }
1676 }
1677
1678 static void
1679 isp_setdparm(struct ispsoftc *isp)
1680 {
1681 int i;
1682 mbreg_t mbs;
1683 sdparam *sdp;
1684
1685 isp->isp_fwrev = 0;
1686 if (isp->isp_type & ISP_HA_FC) {
1687 /*
1688 * ROM in 2100 doesn't appear to support ABOUT_FIRMWARE
1689 */
1690 return;
1691 }
1692
1693 mbs.param[0] = MBOX_ABOUT_FIRMWARE;
1694 isp_mboxcmd(isp, &mbs);
1695 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1696 IDPRINTF(2, ("1st ABOUT FIRMWARE command failed"));
1697 } else {
1698 isp->isp_fwrev =
1699 (((u_int16_t) mbs.param[1]) << 10) + mbs.param[2];
1700 }
1701
1702
1703 sdp = (sdparam *) isp->isp_param;
1704 /*
1705 * Try and get old clock rate out before we hit the
1706 * chip over the head- but if and only if we don't
1707 * know our desired clock rate.
1708 */
1709 if (isp->isp_mdvec->dv_clock == 0) {
1710 mbs.param[0] = MBOX_GET_CLOCK_RATE;
1711 isp_mboxcmd(isp, &mbs);
1712 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1713 sdp->isp_clock = mbs.param[1];
1714 printf("%s: using board clock 0x%x\n",
1715 isp->isp_name, sdp->isp_clock);
1716 }
1717 } else {
1718 sdp->isp_clock = isp->isp_mdvec->dv_clock;
1719 }
1720
1721 mbs.param[0] = MBOX_GET_ACT_NEG_STATE;
1722 isp_mboxcmd(isp, &mbs);
1723 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1724 IDPRINTF(5, ("could not GET ACT NEG STATE"));
1725 sdp->isp_req_ack_active_neg = 1;
1726 sdp->isp_data_line_active_neg = 1;
1727 } else {
1728 sdp->isp_req_ack_active_neg = (mbs.param[1] >> 4) & 0x1;
1729 sdp->isp_data_line_active_neg = (mbs.param[1] >> 5) & 0x1;
1730 }
1731 for (i = 0; i < MAX_TARGETS; i++) {
1732 mbs.param[0] = MBOX_GET_TARGET_PARAMS;
1733 mbs.param[1] = i << 8;
1734 isp_mboxcmd(isp, &mbs);
1735 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1736 IDPRINTF(5, ("cannot get params for target %d", i));
1737 sdp->isp_devparam[i].sync_period =
1738 ISP_10M_SYNCPARMS & 0xff;
1739 sdp->isp_devparam[i].sync_offset =
1740 ISP_10M_SYNCPARMS >> 8;
1741 sdp->isp_devparam[i].dev_flags = DPARM_DEFAULT;
1742 } else {
1743 #if 0
1744 printf("%s: target %d - flags 0x%x, sync %x\n",
1745 isp->isp_name, i, mbs.param[2], mbs.param[3]);
1746 #endif
1747 sdp->isp_devparam[i].dev_flags = mbs.param[2] >> 8;
1748 /*
1749 * The maximum period we can really see
1750 * here is 100 (decimal), or 400 ns.
1751 * For some unknown reason we sometimes
1752 * get back wildass numbers from the
1753 * boot device's paramaters.
1754 */
1755 if ((mbs.param[3] & 0xff) <= 0x64) {
1756 sdp->isp_devparam[i].sync_period =
1757 mbs.param[3] & 0xff;
1758 sdp->isp_devparam[i].sync_offset =
1759 mbs.param[3] >> 8;
1760 }
1761 }
1762 }
1763
1764 /*
1765 * Set Default Host Adapter Parameters
1766 * XXX: Should try and get them out of NVRAM
1767 */
1768 sdp->isp_adapter_enabled = 1;
1769 sdp->isp_cmd_dma_burst_enable = 1;
1770 sdp->isp_data_dma_burst_enabl = 1;
1771 sdp->isp_fifo_threshold = 2;
1772 sdp->isp_initiator_id = 7;
1773 sdp->isp_async_data_setup = 6;
1774 sdp->isp_selection_timeout = 250;
1775 sdp->isp_max_queue_depth = 256;
1776 sdp->isp_tag_aging = 8;
1777 sdp->isp_bus_reset_delay = 3;
1778 sdp->isp_retry_count = 0;
1779 sdp->isp_retry_delay = 1;
1780
1781 for (i = 0; i < MAX_TARGETS; i++) {
1782 sdp->isp_devparam[i].exc_throttle = 16;
1783 sdp->isp_devparam[i].dev_enable = 1;
1784 }
1785 }
1786
1787 static void
1788 isp_phoenix(struct ispsoftc *isp)
1789 {
1790 struct scsipi_xfer *tlist[MAXISPREQUEST], *xs;
1791 int i;
1792
1793 for (i = 0; i < RQUEST_QUEUE_LEN(isp); i++) {
1794 tlist[i] = (struct scsipi_xfer *) isp->isp_xflist[i];
1795 }
1796 isp_reset(isp);
1797 isp_init(isp);
1798 isp->isp_state = ISP_RUNSTATE;
1799
1800 for (i = 0; i < RQUEST_QUEUE_LEN(isp); i++) {
1801 xs = tlist[i];
1802 if (xs == NULL)
1803 continue;
1804 xs->resid = xs->datalen;
1805 xs->error = XS_DRIVER_STUFFUP;
1806 xs->flags |= ITSDONE;
1807 scsipi_done(xs);
1808 }
1809 }
1810
1811 static void
1812 isp_watch(void *arg)
1813 {
1814 int s, i;
1815 struct ispsoftc *isp = arg;
1816 struct scsipi_xfer *xs;
1817
1818 /*
1819 * Look for completely dead commands (but not polled ones)
1820 */
1821 s = splbio();
1822 for (i = 0; i < RQUEST_QUEUE_LEN(isp); i++) {
1823 if ((xs = (struct scsipi_xfer *) isp->isp_xflist[i]) == NULL) {
1824 continue;
1825 }
1826 if (xs->flags & SCSI_POLL)
1827 continue;
1828 if (xs->timeout == 0) {
1829 continue;
1830 }
1831 xs->timeout -= (WATCHI * 1000);
1832 if (xs->timeout > -(2 * WATCHI * 1000)) {
1833 continue;
1834 }
1835 printf("%s: commands really timed out!\n", isp->isp_name);
1836
1837 isp_phoenix(isp);
1838 break;
1839 }
1840 (void) splx(s);
1841 timeout(isp_watch, arg, WATCHI);
1842 }
1843
1844 static void
1845 isp_prtstst(ispstatusreq_t *sp)
1846 {
1847 printf("states->");
1848 if (sp->req_state_flags & RQSF_GOT_BUS)
1849 printf("GOT_BUS ");
1850 if (sp->req_state_flags & RQSF_GOT_TARGET)
1851 printf("GOT_TGT ");
1852 if (sp->req_state_flags & RQSF_SENT_CDB)
1853 printf("SENT_CDB ");
1854 if (sp->req_state_flags & RQSF_XFRD_DATA)
1855 printf("XFRD_DATA ");
1856 if (sp->req_state_flags & RQSF_GOT_STATUS)
1857 printf("GOT_STS ");
1858 if (sp->req_state_flags & RQSF_GOT_SENSE)
1859 printf("GOT_SNS ");
1860 if (sp->req_state_flags & RQSF_XFER_COMPLETE)
1861 printf("XFR_CMPLT ");
1862 printf("\n");
1863 printf("status->");
1864 if (sp->req_status_flags & RQSTF_DISCONNECT)
1865 printf("Disconnect ");
1866 if (sp->req_status_flags & RQSTF_SYNCHRONOUS)
1867 printf("Sync_xfr ");
1868 if (sp->req_status_flags & RQSTF_PARITY_ERROR)
1869 printf("Parity ");
1870 if (sp->req_status_flags & RQSTF_BUS_RESET)
1871 printf("Bus_Reset ");
1872 if (sp->req_status_flags & RQSTF_DEVICE_RESET)
1873 printf("Device_Reset ");
1874 if (sp->req_status_flags & RQSTF_ABORTED)
1875 printf("Aborted ");
1876 if (sp->req_status_flags & RQSTF_TIMEOUT)
1877 printf("Timeout ");
1878 if (sp->req_status_flags & RQSTF_NEGOTIATION)
1879 printf("Negotiation ");
1880 printf("\n");
1881 }
1882