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