seagate.c revision 1.23 1 /*
2 * ST01/02, Future Domain TMC-885, TMC-950 SCSI driver
3 *
4 * Copyright 1994, Charles Hannum (mycroft (at) ai.mit.edu)
5 * Copyright 1994, Kent Palmkvist (kentp (at) isy.liu.se)
6 * Copyright 1994, Robert Knier (rknier (at) qgraph.com)
7 * Copyright 1992, 1994 Drew Eckhardt (drew (at) colorado.edu)
8 * Copyright 1994, Julian Elischer (julian (at) tfs.com)
9 *
10 * Others that has contributed by example code is
11 * Glen Overby (overby (at) cray.com)
12 * Tatu Yllnen
13 * Brian E Litzinger
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE DEVELOPERS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37 /*
38 * kentp 940307 alpha version based on newscsi-03 version of Julians SCSI-code
39 * kentp 940314 Added possibility to not use messages
40 * rknier 940331 Added fast transfer code
41 * rknier 940407 Added assembler coded data transfers
42 */
43
44 /*
45 * What should really be done:
46 *
47 * Add missing tests for timeouts
48 * Restructure interrupt enable/disable code (runs to long with int disabled)
49 * Find bug? giving problem with tape status
50 * Add code to handle Future Domain 840, 841, 880 and 881
51 * adjust timeouts (startup is very slow)
52 * add code to use tagged commands in SCSI2
53 * Add code to handle slow devices better (sleep if device not disconnecting)
54 * Fix unnecessary interrupts
55 */
56
57 /*
58 * Note to users trying to share a disk between DOS and unix:
59 * The ST01/02 is a translating host-adapter. It is not giving DOS
60 * the same number of heads/tracks/sectors as specified by the disk.
61 * It is therefore important to look at what numbers DOS thinks the
62 * disk has. Use these to disklabel your disk in an appropriate manner
63 */
64
65 #include <sys/types.h>
66 #include <sys/param.h>
67 #include <sys/systm.h>
68 #include <sys/kernel.h>
69 #include <sys/errno.h>
70 #include <sys/ioctl.h>
71 #include <sys/device.h>
72 #include <sys/buf.h>
73 #include <sys/proc.h>
74 #include <sys/user.h>
75 #include <sys/queue.h>
76 #include <sys/malloc.h>
77
78 #include <machine/intr.h>
79 #include <machine/pio.h>
80
81 #include <dev/scsipi/scsi_all.h>
82 #include <dev/scsipi/scsipi_all.h>
83 #include <dev/scsipi/scsi_message.h>
84 #include <dev/scsipi/scsiconf.h>
85
86 #include <dev/isa/isareg.h>
87 #include <dev/isa/isavar.h>
88 #include <i386/isa/isa_machdep.h> /* XXX USES ISA HOLE DIRECTLY */
89
90 #define SEA_SCB_MAX 32 /* allow maximally 8 scsi control blocks */
91 #define SCB_TABLE_SIZE 8 /* start with 8 scb entries in table */
92 #define BLOCK_SIZE 512 /* size of READ/WRITE areas on SCSI card */
93
94 /*
95 * defining SEA_BLINDTRANSFER will make DATA IN and DATA OUT to be done with
96 * blind transfers, i.e. no check is done for scsi phase changes. This will
97 * result in data loss if the scsi device does not send its data using
98 * BLOCK_SIZE bytes at a time.
99 * If SEA_BLINDTRANSFER defined and SEA_ASSEMBLER also defined will result in
100 * the use of blind transfers coded in assembler. SEA_ASSEMBLER is no good
101 * without SEA_BLINDTRANSFER defined.
102 */
103 #define SEA_BLINDTRANSFER /* do blind transfers */
104 #define SEA_ASSEMBLER /* Use assembly code for fast transfers */
105
106 /*
107 * defining SEA_NOMSGS causes messages not to be used (thereby disabling
108 * disconnects)
109 */
110 #undef SEA_NOMSGS
111
112 /*
113 * defining SEA_NODATAOUT makes dataout phase being aborted
114 */
115 #undef SEA_NODATAOUT
116
117 /* Debugging definitions. Should not be used unless you want a lot of
118 printouts even under normal conditions */
119
120 #undef SEA_DEBUGQUEUE /* Display info about queue-lengths */
121
122 /******************************* board definitions **************************/
123 /*
124 * CONTROL defines
125 */
126 #define CMD_RST 0x01 /* scsi reset */
127 #define CMD_SEL 0x02 /* scsi select */
128 #define CMD_BSY 0x04 /* scsi busy */
129 #define CMD_ATTN 0x08 /* scsi attention */
130 #define CMD_START_ARB 0x10 /* start arbitration bit */
131 #define CMD_EN_PARITY 0x20 /* enable scsi parity generation */
132 #define CMD_INTR 0x40 /* enable scsi interrupts */
133 #define CMD_DRVR_ENABLE 0x80 /* scsi enable */
134
135 /*
136 * STATUS
137 */
138 #define STAT_BSY 0x01 /* scsi busy */
139 #define STAT_MSG 0x02 /* scsi msg */
140 #define STAT_IO 0x04 /* scsi I/O */
141 #define STAT_CD 0x08 /* scsi C/D */
142 #define STAT_REQ 0x10 /* scsi req */
143 #define STAT_SEL 0x20 /* scsi select */
144 #define STAT_PARITY 0x40 /* parity error bit */
145 #define STAT_ARB_CMPL 0x80 /* arbitration complete bit */
146
147 /*
148 * REQUESTS
149 */
150 #define PH_DATAOUT (0)
151 #define PH_DATAIN (STAT_IO)
152 #define PH_CMD (STAT_CD)
153 #define PH_STAT (STAT_CD | STAT_IO)
154 #define PH_MSGOUT (STAT_MSG | STAT_CD)
155 #define PH_MSGIN (STAT_MSG | STAT_CD | STAT_IO)
156
157 #define PH_MASK (STAT_MSG | STAT_CD | STAT_IO)
158
159 #define PH_INVALID 0xff
160
161 #define SEA_RAMOFFSET 0x00001800
162
163 #define BASE_CMD (CMD_INTR | CMD_EN_PARITY)
164
165 #define SEAGATE 1 /* Seagate ST0[12] */
166 #define FDOMAIN 2 /* Future Domain TMC-{885,950} */
167 #define FDOMAIN840 3 /* Future Domain TMC-{84[01],88[01]} */
168
169 /******************************************************************************/
170
171 /* scsi control block used to keep info about a scsi command */
172 struct sea_scb {
173 u_char *data; /* position in data buffer so far */
174 int datalen; /* bytes remaining to transfer */
175 TAILQ_ENTRY(sea_scb) chain;
176 struct scsipi_xfer *xs; /* the scsipi_xfer for this cmd */
177 int flags; /* status of the instruction */
178 #define SCB_FREE 0
179 #define SCB_ACTIVE 1
180 #define SCB_ABORTED 2
181 #define SCB_TIMEOUT 4
182 #define SCB_ERROR 8
183 };
184
185 /*
186 * data structure describing current status of the scsi bus. One for each
187 * controller card.
188 */
189 struct sea_softc {
190 struct device sc_dev;
191 struct isadev sc_id;
192 void *sc_ih;
193
194 int type; /* board type */
195 caddr_t maddr; /* Base address for card */
196 caddr_t maddr_cr_sr; /* Address of control and status reg */
197 caddr_t maddr_dr; /* Address of data register */
198
199 struct scsipi_link sc_link; /* prototype for subdevs */
200 TAILQ_HEAD(, sea_scb) free_list, ready_list, nexus_list;
201 struct sea_scb *nexus; /* currently connected command */
202 int numscbs; /* number of scsi control blocks */
203 struct sea_scb scb[SCB_TABLE_SIZE];
204
205 int our_id; /* our scsi id */
206 u_char our_id_mask;
207 volatile u_char busy[8]; /* index=target, bit=lun, Keep track of
208 busy luns at device target */
209 };
210
211 /* flag showing if main routine is running. */
212 static volatile int main_running = 0;
213
214 #define STATUS (*(volatile u_char *)sea->maddr_cr_sr)
215 #define CONTROL STATUS
216 #define DATA (*(volatile u_char *)sea->maddr_dr)
217
218 /*
219 * These are "special" values for the tag parameter passed to sea_select
220 * Not implemented right now.
221 */
222 #define TAG_NEXT -1 /* Use next free tag */
223 #define TAG_NONE -2 /*
224 * Establish I_T_L nexus instead of I_T_L_Q
225 * even on SCSI-II devices.
226 */
227
228 typedef struct {
229 char *signature;
230 int offset, length;
231 int type;
232 } BiosSignature;
233
234 /*
235 * Signatures for automatic recognition of board type
236 */
237 static const BiosSignature signatures[] = {
238 {"ST01 v1.7 (C) Copyright 1987 Seagate", 15, 37, SEAGATE},
239 {"SCSI BIOS 2.00 (C) Copyright 1987 Seagate", 15, 40, SEAGATE},
240
241 /*
242 * The following two lines are NOT mistakes. One detects ROM revision
243 * 3.0.0, the other 3.2. Since seagate has only one type of SCSI adapter,
244 * and this is not going to change, the "SEAGATE" and "SCSI" together
245 * are probably "good enough"
246 */
247 {"SEAGATE SCSI BIOS ", 16, 17, SEAGATE},
248 {"SEAGATE SCSI BIOS ", 17, 17, SEAGATE},
249
250 /*
251 * However, future domain makes several incompatible SCSI boards, so specific
252 * signatures must be used.
253 */
254 {"FUTURE DOMAIN CORP. (C) 1986-1989 V5.0C2/14/89", 5, 45, FDOMAIN},
255 {"FUTURE DOMAIN CORP. (C) 1986-1989 V6.0A7/28/89", 5, 46, FDOMAIN},
256 {"FUTURE DOMAIN CORP. (C) 1986-1990 V6.0105/31/90",5, 47, FDOMAIN},
257 {"FUTURE DOMAIN CORP. (C) 1986-1990 V6.0209/18/90",5, 47, FDOMAIN},
258 {"FUTURE DOMAIN CORP. (C) 1986-1990 V7.009/18/90", 5, 46, FDOMAIN},
259 {"FUTURE DOMAIN CORP. (C) 1992 V8.00.004/02/92", 5, 44, FDOMAIN},
260 {"FUTURE DOMAIN TMC-950", 5, 21, FDOMAIN},
261 };
262
263 #define nsignatures (sizeof(signatures) / sizeof(signatures[0]))
264
265 #ifdef notdef
266 static const char *bases[] = {
267 (char *) 0xc8000, (char *) 0xca000, (char *) 0xcc000,
268 (char *) 0xce000, (char *) 0xdc000, (char *) 0xde000
269 };
270
271 #define nbases (sizeof(bases) / sizeof(bases[0]))
272 #endif
273
274 int seaintr __P((void *));
275 int sea_scsi_cmd __P((struct scsipi_xfer *));
276 void sea_timeout __P((void *));
277 void sea_done __P((struct sea_softc *, struct sea_scb *));
278 struct sea_scb *sea_get_scb __P((struct sea_softc *, int));
279 void sea_free_scb __P((struct sea_softc *, struct sea_scb *, int));
280 static void sea_main __P((void));
281 static void sea_information_transfer __P((struct sea_softc *));
282 int sea_poll __P((struct sea_softc *, struct scsipi_xfer *, int));
283 void sea_init __P((struct sea_softc *));
284 void sea_send_scb __P((struct sea_softc *sea, struct sea_scb *scb));
285 void sea_reselect __P((struct sea_softc *sea));
286 int sea_select __P((struct sea_softc *sea, struct sea_scb *scb));
287 int sea_transfer_pio __P((struct sea_softc *sea, u_char *phase,
288 int *count, u_char **data));
289 int sea_abort __P((struct sea_softc *, struct sea_scb *scb));
290
291 struct scsipi_adapter sea_switch = {
292 sea_scsi_cmd,
293 minphys, /* no special minphys(), since driver uses PIO */
294 0,
295 0,
296 };
297
298 /* the below structure is so we have a default dev struct for our link struct */
299 struct scsipi_device sea_dev = {
300 NULL, /* use default error handler */
301 NULL, /* have a queue, served by this */
302 NULL, /* have no async handler */
303 NULL, /* Use default 'done' routine */
304 };
305
306 int seaprobe __P((struct device *, void *, void *));
307 void seaattach __P((struct device *, struct device *, void *));
308
309 struct cfattach sea_ca = {
310 sizeof(struct sea_softc), seaprobe, seaattach
311 };
312
313 struct cfdriver sea_cd = {
314 NULL, "sea", DV_DULL
315 };
316
317 #ifdef SEA_DEBUGQUEUE
318 void
319 sea_queue_length(sea)
320 struct sea_softc *sea;
321 {
322 struct sea_scb *scb;
323 int connected, issued, disconnected;
324
325 connected = sea->nexus ? 1 : 0;
326 for (scb = sea->ready_list.tqh_first, issued = 0; scb;
327 scb = scb->chain.tqe_next, issued++);
328 for (scb = sea->nexus_list.tqh_first, disconnected = 0; scb;
329 scb = scb->chain.tqe_next, disconnected++);
330 printf("%s: length: %d/%d/%d\n", sea->sc_dev.dv_xname, connected,
331 issued, disconnected);
332 }
333 #endif
334
335 /*
336 * Check if the device can be found at the port given and if so, detect the
337 * type the type of board. Set it up ready for further work. Takes the isa_dev
338 * structure from autoconf as an argument.
339 * Returns 1 if card recognized, 0 if errors.
340 */
341 int
342 seaprobe(parent, match, aux)
343 struct device *parent;
344 void *match, *aux;
345 {
346 struct sea_softc *sea = match;
347 struct isa_attach_args *ia = aux;
348 int i;
349
350 /*
351 * Could try to find a board by looking through all possible addresses.
352 * This is not done the right way now, because I have not found a way
353 * to get a boards virtual memory address given its physical. There is
354 * a function that returns the physical address for a given virtual
355 * address, but not the other way around.
356 */
357
358 if (ia->ia_maddr == MADDRUNK) {
359 /* XXX */
360 return 0;
361 } else
362 sea->maddr = ISA_HOLE_VADDR(ia->ia_maddr);
363
364 /* check board type */ /* No way to define this through config */
365 for (i = 0; i < nsignatures; i++)
366 if (!bcmp(sea->maddr + signatures[i].offset,
367 signatures[i].signature, signatures[i].length)) {
368 sea->type = signatures[i].type;
369 break;
370 }
371
372 /* Find controller and data memory addresses */
373 switch (sea->type) {
374 case SEAGATE:
375 case FDOMAIN840:
376 sea->maddr_cr_sr =
377 (void *) (((u_char *)sea->maddr) + 0x1a00);
378 sea->maddr_dr =
379 (void *) (((u_char *)sea->maddr) + 0x1c00);
380 break;
381 case FDOMAIN:
382 sea->maddr_cr_sr =
383 (void *) (((u_char *)sea->maddr) + 0x1c00);
384 sea->maddr_dr =
385 (void *) (((u_char *)sea->maddr) + 0x1e00);
386 break;
387 default:
388 #ifdef DEBUG
389 printf("%s: board type unknown at address 0x%x\n",
390 sea->sc_dev.dv_xname, ia->ia_maddr);
391 #endif
392 return 0;
393 }
394
395 /* Test controller RAM (works the same way on future domain cards?) */
396 *((u_char *)sea->maddr + SEA_RAMOFFSET) = 0xa5;
397 *((u_char *)sea->maddr + SEA_RAMOFFSET + 1) = 0x5a;
398
399 if ((*((u_char *)sea->maddr + SEA_RAMOFFSET) != 0xa5) ||
400 (*((u_char *)sea->maddr + SEA_RAMOFFSET + 1) != 0x5a)) {
401 printf("%s: board RAM failure\n", sea->sc_dev.dv_xname);
402 return 0;
403 }
404
405 ia->ia_drq = DRQUNK;
406 ia->ia_msize = 0x2000;
407 ia->ia_iosize = 0;
408 return 1;
409 }
410
411 /*
412 * Attach all sub-devices we can find
413 */
414 void
415 seaattach(parent, self, aux)
416 struct device *parent, *self;
417 void *aux;
418 {
419 struct isa_attach_args *ia = aux;
420 struct sea_softc *sea = (void *)self;
421
422 sea_init(sea);
423
424 /*
425 * fill in the prototype scsipi_link.
426 */
427 sea->sc_link.scsipi_scsi.channel = SCSI_CHANNEL_ONLY_ONE;
428 sea->sc_link.adapter_softc = sea;
429 sea->sc_link.scsipi_scsi.adapter_target = sea->our_id;
430 sea->sc_link.adapter = &sea_switch;
431 sea->sc_link.device = &sea_dev;
432 sea->sc_link.openings = 1;
433 sea->sc_link.scsipi_scsi.max_target = 7;
434 sea->sc_link.type = BUS_SCSI;
435
436 printf("\n");
437
438 #ifdef NEWCONFIG
439 isa_establish(&sea->sc_id, &sea->sc_deV);
440 #endif
441 sea->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
442 IPL_BIO, seaintr, sea);
443
444 /*
445 * ask the adapter what subunits are present
446 */
447 config_found(self, &sea->sc_link, scsiprint);
448 }
449
450 /*
451 * Catch an interrupt from the adaptor
452 */
453 int
454 seaintr(arg)
455 void *arg;
456 {
457 struct sea_softc *sea = arg;
458
459 #ifdef DEBUG /* extra overhead, and only needed for intr debugging */
460 if ((STATUS & STAT_PARITY) == 0 &&
461 (STATUS & (STAT_SEL | STAT_IO)) != (STAT_SEL | STAT_IO))
462 return 0;
463 #endif
464
465 loop:
466 /* dispatch to appropriate routine if found and done=0 */
467 /* should check to see that this card really caused the interrupt */
468
469 if (STATUS & STAT_PARITY) {
470 /* Parity error interrupt */
471 printf("%s: parity error\n", sea->sc_dev.dv_xname);
472 return 1;
473 }
474
475 if ((STATUS & (STAT_SEL | STAT_IO)) == (STAT_SEL | STAT_IO)) {
476 /* Reselect interrupt */
477 sea_reselect(sea);
478 if (!main_running)
479 sea_main();
480 goto loop;
481 }
482
483 return 1;
484 }
485
486 /*
487 * Setup data structures, and reset the board and the SCSI bus.
488 */
489 void
490 sea_init(sea)
491 struct sea_softc *sea;
492 {
493 int i;
494
495 /* Reset the scsi bus (I don't know if this is needed */
496 CONTROL = BASE_CMD | CMD_DRVR_ENABLE | CMD_RST;
497 delay(25); /* hold reset for at least 25 microseconds */
498 CONTROL = BASE_CMD;
499 delay(10); /* wait a Bus Clear Delay (800 ns + bus free delay (800 ns) */
500
501 /* Set our id (don't know anything about this) */
502 switch (sea->type) {
503 case SEAGATE:
504 sea->our_id = 7;
505 break;
506 case FDOMAIN:
507 case FDOMAIN840:
508 sea->our_id = 6;
509 break;
510 }
511 sea->our_id_mask = 1 << sea->our_id;
512
513 /* init fields used by our routines */
514 sea->nexus = 0;
515 TAILQ_INIT(&sea->ready_list);
516 TAILQ_INIT(&sea->nexus_list);
517 TAILQ_INIT(&sea->free_list);
518 for (i = 0; i < 8; i++)
519 sea->busy[i] = 0x00;
520
521 /* link up the free list of scbs */
522 sea->numscbs = SCB_TABLE_SIZE;
523 for (i = 0; i < SCB_TABLE_SIZE; i++) {
524 TAILQ_INSERT_TAIL(&sea->free_list, &sea->scb[i], chain);
525 }
526 }
527
528 /*
529 * start a scsi operation given the command and the data address. Also needs
530 * the unit, target and lu.
531 */
532 int
533 sea_scsi_cmd(xs)
534 struct scsipi_xfer *xs;
535 {
536 struct scsipi_link *sc_link = xs->sc_link;
537 struct sea_softc *sea = sc_link->adapter_softc;
538 struct sea_scb *scb;
539 int flags;
540 int s;
541
542 SC_DEBUG(sc_link, SDEV_DB2, ("sea_scsi_cmd\n"));
543
544 flags = xs->flags;
545 if ((flags & (ITSDONE|INUSE)) != INUSE) {
546 printf("%s: done or not in use?\n", sea->sc_dev.dv_xname);
547 xs->flags &= ~ITSDONE;
548 xs->flags |= INUSE;
549 }
550 if ((scb = sea_get_scb(sea, flags)) == NULL) {
551 xs->error = XS_DRIVER_STUFFUP;
552 return TRY_AGAIN_LATER;
553 }
554 scb->flags = SCB_ACTIVE;
555 scb->xs = xs;
556
557 if (flags & SCSI_RESET) {
558 /*
559 * Try to send a reset command to the card.
560 * XXX Not implemented.
561 */
562 printf("%s: resetting\n", sea->sc_dev.dv_xname);
563 xs->error = XS_DRIVER_STUFFUP;
564 return COMPLETE;
565 }
566
567 /*
568 * Put all the arguments for the xfer in the scb
569 */
570 scb->datalen = xs->datalen;
571 scb->data = xs->data;
572
573 #ifdef SEA_DEBUGQUEUE
574 sea_queue_length(sea);
575 #endif
576
577 s = splbio();
578
579 sea_send_scb(sea, scb);
580
581 /*
582 * Usually return SUCCESSFULLY QUEUED
583 */
584 if ((flags & SCSI_POLL) == 0) {
585 timeout(sea_timeout, scb, (xs->timeout * hz) / 1000);
586 splx(s);
587 return SUCCESSFULLY_QUEUED;
588 }
589
590 splx(s);
591
592 /*
593 * If we can't use interrupts, poll on completion
594 */
595 if (sea_poll(sea, xs, xs->timeout)) {
596 sea_timeout(scb);
597 if (sea_poll(sea, xs, 2000))
598 sea_timeout(scb);
599 }
600 return COMPLETE;
601 }
602
603 /*
604 * Get a free scb. If there are none, see if we can allocate a new one. If so,
605 * put it in the hash table too; otherwise return an error or sleep.
606 */
607 struct sea_scb *
608 sea_get_scb(sea, flags)
609 struct sea_softc *sea;
610 int flags;
611 {
612 int s;
613 struct sea_scb *scb;
614
615 s = splbio();
616
617 /*
618 * If we can and have to, sleep waiting for one to come free
619 * but only if we can't allocate a new one.
620 */
621 for (;;) {
622 scb = sea->free_list.tqh_first;
623 if (scb) {
624 TAILQ_REMOVE(&sea->free_list, scb, chain);
625 break;
626 }
627 if (sea->numscbs < SEA_SCB_MAX) {
628 scb = (struct sea_scb *) malloc(sizeof(struct sea_scb),
629 M_TEMP, M_NOWAIT);
630 if (scb) {
631 bzero(scb, sizeof(struct sea_scb));
632 sea->numscbs++;
633 } else
634 printf("%s: can't malloc scb\n",
635 sea->sc_dev.dv_xname);
636 break;
637 }
638 if ((flags & SCSI_NOSLEEP) != 0)
639 break;
640 tsleep(&sea->free_list, PRIBIO, "seascb", 0);
641 }
642
643 splx(s);
644 return scb;
645 }
646
647 /*
648 * Try to send this command to the board. Because this board does not use any
649 * mailboxes, this routine simply adds the command to the queue held by the
650 * sea_softc structure.
651 * A check is done to see if the command contains a REQUEST_SENSE command, and
652 * if so the command is put first in the queue, otherwise the command is added
653 * to the end of the queue. ?? Not correct ??
654 */
655 void
656 sea_send_scb(sea, scb)
657 struct sea_softc *sea;
658 struct sea_scb *scb;
659 {
660
661 TAILQ_INSERT_TAIL(&sea->ready_list, scb, chain);
662 /* Try to do some work on the card. */
663 if (!main_running)
664 sea_main();
665 }
666
667 /*
668 * Coroutine that runs as long as more work can be done on the seagate host
669 * adapter in a system. Both sea_scsi_cmd and sea_intr will try to start it in
670 * case it is not running.
671 */
672 void
673 sea_main()
674 {
675 struct sea_softc *sea;
676 struct sea_scb *scb;
677 int done;
678 int unit;
679 int s;
680
681 main_running = 1;
682
683 /*
684 * This should not be run with interrupts disabled, but use the splx
685 * code instead.
686 */
687 loop:
688 done = 1;
689 for (unit = 0; unit < sea_cd.cd_ndevs; unit++) {
690 sea = sea_cd.cd_devs[unit];
691 if (!sea)
692 continue;
693 s = splbio();
694 if (!sea->nexus) {
695 /*
696 * Search through the ready_list for a command
697 * destined for a target that's not busy.
698 */
699 for (scb = sea->ready_list.tqh_first; scb;
700 scb = scb->chain.tqe_next) {
701 if (!(sea->busy[scb->xs->sc_link->scsipi_scsi.target] &
702 (1 << scb->xs->sc_link->scsipi_scsi.lun))) {
703 TAILQ_REMOVE(&sea->ready_list, scb,
704 chain);
705
706 /* Re-enable interrupts. */
707 splx(s);
708
709 /*
710 * Attempt to establish an I_T_L nexus.
711 * On success, sea->nexus is set.
712 * On failure, we must add the command
713 * back to the issue queue so we can
714 * keep trying.
715 */
716
717 /*
718 * REQUEST_SENSE commands are issued
719 * without tagged queueing, even on
720 * SCSI-II devices because the
721 * contingent alligence condition
722 * exists for the entire unit.
723 */
724
725 /*
726 * First check that if any device has
727 * tried a reconnect while we have done
728 * other things with interrupts
729 * disabled.
730 */
731
732 if ((STATUS & (STAT_SEL | STAT_IO)) ==
733 (STAT_SEL | STAT_IO)) {
734 sea_reselect(sea);
735 break;
736 }
737 if (sea_select(sea, scb)) {
738 s = splbio();
739 TAILQ_INSERT_HEAD(&sea->ready_list,
740 scb, chain);
741 splx(s);
742 } else
743 break;
744 } /* if target/lun is not busy */
745 } /* for scb */
746 if (!sea->nexus) {
747 /* check for reselection phase */
748 if ((STATUS & (STAT_SEL | STAT_IO)) ==
749 (STAT_SEL | STAT_IO)) {
750 sea_reselect(sea);
751 }
752 }
753 } /* if (!sea->nexus) */
754
755 splx(s);
756 if (sea->nexus) { /* we are connected. Do the task */
757 sea_information_transfer(sea);
758 done = 0;
759 } else
760 break;
761 } /* for instance */
762
763 if (!done)
764 goto loop;
765
766 main_running = 0;
767 }
768
769 void
770 sea_free_scb(sea, scb, flags)
771 struct sea_softc *sea;
772 struct sea_scb *scb;
773 int flags;
774 {
775 int s;
776
777 s = splbio();
778
779 scb->flags = SCB_FREE;
780 TAILQ_INSERT_HEAD(&sea->free_list, scb, chain);
781
782 /*
783 * If there were none, wake anybody waiting for one to come free,
784 * starting with queued entries.
785 */
786 if (!scb->chain.tqe_next)
787 wakeup((caddr_t)&sea->free_list);
788
789 splx(s);
790 }
791
792 void
793 sea_timeout(arg)
794 void *arg;
795 {
796 struct sea_scb *scb = arg;
797 struct scsipi_xfer *xs = scb->xs;
798 struct scsipi_link *sc_link = xs->sc_link;
799 struct sea_softc *sea = sc_link->adapter_softc;
800 int s;
801
802 scsi_print_addr(sc_link);
803 printf("timed out");
804
805 s = splbio();
806
807 /*
808 * If it has been through before, then
809 * a previous abort has failed, don't
810 * try abort again
811 */
812 if (scb->flags & SCB_ABORTED) {
813 /* abort timed out */
814 printf(" AGAIN\n");
815 scb->xs->retries = 0;
816 scb->flags |= SCB_ABORTED;
817 sea_done(sea, scb);
818 } else {
819 /* abort the operation that has timed out */
820 printf("\n");
821 scb->flags |= SCB_ABORTED;
822 sea_abort(sea, scb);
823 /* 2 secs for the abort */
824 if ((xs->flags & SCSI_POLL) == 0)
825 timeout(sea_timeout, scb, 2 * hz);
826 }
827
828 splx(s);
829 }
830
831 void
832 sea_reselect(sea)
833 struct sea_softc *sea;
834 {
835 u_char target_mask;
836 int i;
837 u_char lun, phase;
838 u_char msg[3];
839 int len;
840 u_char *data;
841 struct sea_scb *scb;
842 int abort = 0;
843
844 if (!((target_mask = STATUS) & STAT_SEL)) {
845 printf("%s: wrong state 0x%x\n", sea->sc_dev.dv_xname,
846 target_mask);
847 return;
848 }
849
850 /* wait for a device to win the reselection phase */
851 /* signals this by asserting the I/O signal */
852 for (i = 10; i && (STATUS & (STAT_SEL | STAT_IO | STAT_BSY)) !=
853 (STAT_SEL | STAT_IO | 0); i--);
854 /* !! Check for timeout here */
855 /* the data bus contains original initiator id ORed with target id */
856 target_mask = DATA;
857 /* see that we really are the initiator */
858 if (!(target_mask & sea->our_id_mask)) {
859 printf("%s: polled reselection was not for me: 0x%x\n",
860 sea->sc_dev.dv_xname, target_mask);
861 return;
862 }
863 /* find target who won */
864 target_mask &= ~sea->our_id_mask;
865 /* host responds by asserting the BSY signal */
866 CONTROL = BASE_CMD | CMD_DRVR_ENABLE | CMD_BSY;
867 /* target should respond by deasserting the SEL signal */
868 for (i = 50000; i && (STATUS & STAT_SEL); i++);
869 /* remove the busy status */
870 CONTROL = BASE_CMD | CMD_DRVR_ENABLE;
871 /* we are connected. Now we wait for the MSGIN condition */
872 for (i = 50000; i && !(STATUS & STAT_REQ); i--);
873 /* !! Add timeout check here */
874 /* hope we get an IDENTIFY message */
875 len = 3;
876 data = msg;
877 phase = PH_MSGIN;
878 sea_transfer_pio(sea, &phase, &len, &data);
879
880 if (MSG_ISIDENTIFY(msg[0])) {
881 printf("%s: expecting IDENTIFY message, got 0x%x\n",
882 sea->sc_dev.dv_xname, msg[0]);
883 abort = 1;
884 scb = NULL;
885 } else {
886 lun = msg[0] & 0x07;
887
888 /*
889 * Find the command corresponding to the I_T_L or I_T_L_Q nexus
890 * we just reestablished, and remove it from the disconnected
891 * queue.
892 */
893 for (scb = sea->nexus_list.tqh_first; scb;
894 scb = scb->chain.tqe_next)
895 if (target_mask == (1 << scb->xs->sc_link->scsipi_scsi.target) &&
896 lun == scb->xs->sc_link->scsipi_scsi.lun) {
897 TAILQ_REMOVE(&sea->nexus_list, scb,
898 chain);
899 break;
900 }
901 if (!scb) {
902 printf("%s: target %02x lun %d not disconnected\n",
903 sea->sc_dev.dv_xname, target_mask, lun);
904 /*
905 * Since we have an established nexus that we can't do
906 * anything with, we must abort it.
907 */
908 abort = 1;
909 }
910 }
911
912 if (abort) {
913 msg[0] = MSG_ABORT;
914 len = 1;
915 data = msg;
916 phase = PH_MSGOUT;
917 CONTROL = BASE_CMD | CMD_ATTN;
918 sea_transfer_pio(sea, &phase, &len, &data);
919 } else
920 sea->nexus = scb;
921
922 return;
923 }
924
925 /*
926 * Transfer data in given phase using polled I/O.
927 */
928 int
929 sea_transfer_pio(sea, phase, count, data)
930 struct sea_softc *sea;
931 u_char *phase;
932 int *count;
933 u_char **data;
934 {
935 register u_char p = *phase, tmp;
936 register int c = *count;
937 register u_char *d = *data;
938 int timeout;
939
940 do {
941 /*
942 * Wait for assertion of REQ, after which the phase bits will
943 * be valid.
944 */
945 for (timeout = 0; timeout < 50000; timeout++)
946 if ((tmp = STATUS) & STAT_REQ)
947 break;
948 if (!(tmp & STAT_REQ)) {
949 printf("%s: timeout waiting for STAT_REQ\n",
950 sea->sc_dev.dv_xname);
951 break;
952 }
953
954 /*
955 * Check for phase mismatch. Reached if the target decides
956 * that it has finished the transfer.
957 */
958 if (sea->type == FDOMAIN840)
959 tmp = ((tmp & 0x08) >> 2) |
960 ((tmp & 0x02) << 2) |
961 (tmp & 0xf5);
962 if ((tmp & PH_MASK) != p)
963 break;
964
965 /* Do actual transfer from SCSI bus to/from memory. */
966 if (!(p & STAT_IO))
967 DATA = *d;
968 else
969 *d = DATA;
970 ++d;
971
972 /*
973 * The SCSI standard suggests that in MSGOUT phase, the
974 * initiator should drop ATN on the last byte of the message
975 * phase after REQ has been asserted for the handshake but
976 * before the initiator raises ACK.
977 * Don't know how to accomplish this on the ST01/02.
978 */
979
980 #if 0
981 /*
982 * XXX
983 * The st01 code doesn't wait for STAT_REQ to be deasserted.
984 * Is this ok?
985 */
986 for (timeout = 0; timeout < 200000L; timeout++)
987 if (!(STATUS & STAT_REQ))
988 break;
989 if (STATUS & STAT_REQ)
990 printf("%s: timeout on wait for !STAT_REQ",
991 sea->sc_dev.dv_xname);
992 #endif
993 } while (--c);
994
995 *count = c;
996 *data = d;
997 tmp = STATUS;
998 if (tmp & STAT_REQ)
999 *phase = tmp & PH_MASK;
1000 else
1001 *phase = PH_INVALID;
1002
1003 if (c && (*phase != p))
1004 return -1;
1005 return 0;
1006 }
1007
1008 /*
1009 * Establish I_T_L or I_T_L_Q nexus for new or existing command including
1010 * ARBITRATION, SELECTION, and initial message out for IDENTIFY and queue
1011 * messages. Return -1 if selection could not execute for some reason, 0 if
1012 * selection succeded or failed because the target did not respond.
1013 */
1014 int
1015 sea_select(sea, scb)
1016 struct sea_softc *sea;
1017 struct sea_scb *scb;
1018 {
1019 u_char msg[3], phase;
1020 u_char *data;
1021 int len;
1022 int timeout;
1023
1024 CONTROL = BASE_CMD;
1025 DATA = sea->our_id_mask;
1026 CONTROL = (BASE_CMD & ~CMD_INTR) | CMD_START_ARB;
1027
1028 /* wait for arbitration to complete */
1029 for (timeout = 0; timeout < 3000000L; timeout++)
1030 if (STATUS & STAT_ARB_CMPL)
1031 break;
1032 if (!(STATUS & STAT_ARB_CMPL)) {
1033 if (STATUS & STAT_SEL) {
1034 printf("%s: arbitration lost\n", sea->sc_dev.dv_xname);
1035 scb->flags |= SCB_ERROR;
1036 } else {
1037 printf("%s: arbitration timeout\n",
1038 sea->sc_dev.dv_xname);
1039 scb->flags |= SCB_TIMEOUT;
1040 }
1041 CONTROL = BASE_CMD;
1042 return -1;
1043 }
1044
1045 delay(2);
1046 DATA = (u_char)((1 << scb->xs->sc_link->scsipi_scsi.target) |
1047 sea->our_id_mask);
1048 CONTROL =
1049 #ifdef SEA_NOMSGS
1050 (BASE_CMD & ~CMD_INTR) | CMD_DRVR_ENABLE | CMD_SEL;
1051 #else
1052 (BASE_CMD & ~CMD_INTR) | CMD_DRVR_ENABLE | CMD_SEL | CMD_ATTN;
1053 #endif
1054 delay(1);
1055
1056 /* wait for a bsy from target */
1057 for (timeout = 0; timeout < 2000000L; timeout++)
1058 if (STATUS & STAT_BSY)
1059 break;
1060 if (!(STATUS & STAT_BSY)) {
1061 /* should return some error to the higher level driver */
1062 CONTROL = BASE_CMD;
1063 scb->flags |= SCB_TIMEOUT;
1064 return 0;
1065 }
1066
1067 /* Try to make the target to take a message from us */
1068 #ifdef SEA_NOMSGS
1069 CONTROL = (BASE_CMD & ~CMD_INTR) | CMD_DRVR_ENABLE;
1070 #else
1071 CONTROL = (BASE_CMD & ~CMD_INTR) | CMD_DRVR_ENABLE | CMD_ATTN;
1072 #endif
1073 delay(1);
1074
1075 /* should start a msg_out phase */
1076 for (timeout = 0; timeout < 2000000L; timeout++)
1077 if (STATUS & STAT_REQ)
1078 break;
1079 /* Remove ATN. */
1080 CONTROL = BASE_CMD | CMD_DRVR_ENABLE;
1081 if (!(STATUS & STAT_REQ)) {
1082 /*
1083 * This should not be taken as an error, but more like an
1084 * unsupported feature! Should set a flag indicating that the
1085 * target don't support messages, and continue without failure.
1086 * (THIS IS NOT AN ERROR!)
1087 */
1088 } else {
1089 msg[0] = MSG_IDENTIFY(scb->xs->sc_link->scsipi_scsi.lun, 1);
1090 len = 1;
1091 data = msg;
1092 phase = PH_MSGOUT;
1093 /* Should do test on result of sea_transfer_pio(). */
1094 sea_transfer_pio(sea, &phase, &len, &data);
1095 }
1096 if (!(STATUS & STAT_BSY))
1097 printf("%s: after successful arbitrate: no STAT_BSY!\n",
1098 sea->sc_dev.dv_xname);
1099
1100 sea->nexus = scb;
1101 sea->busy[scb->xs->sc_link->scsipi_scsi.target] |=
1102 1 << scb->xs->sc_link->scsipi_scsi.lun;
1103 /* This assignment should depend on possibility to send a message to target. */
1104 CONTROL = BASE_CMD | CMD_DRVR_ENABLE;
1105 /* XXX Reset pointer in command? */
1106 return 0;
1107 }
1108
1109 /*
1110 * Send an abort to the target. Return 1 success, 0 on failure.
1111 */
1112 int
1113 sea_abort(sea, scb)
1114 struct sea_softc *sea;
1115 struct sea_scb *scb;
1116 {
1117 struct sea_scb *tmp;
1118 u_char msg, phase, *msgptr;
1119 int len;
1120
1121 /*
1122 * If the command hasn't been issued yet, we simply remove it from the
1123 * issue queue
1124 * XXX Could avoid this loop.
1125 */
1126 for (tmp = sea->ready_list.tqh_first; tmp; tmp = tmp->chain.tqe_next)
1127 if (scb == tmp) {
1128 TAILQ_REMOVE(&sea->ready_list, scb, chain);
1129 /* XXX Set some type of error result for operation. */
1130 return 1;
1131 }
1132
1133 /*
1134 * If any commands are connected, we're going to fail the abort and let
1135 * the high level SCSI driver retry at a later time or issue a reset.
1136 */
1137 if (sea->nexus)
1138 return 0;
1139
1140 /*
1141 * If the command is currently disconnected from the bus, and there are
1142 * no connected commands, we reconnect the I_T_L or I_T_L_Q nexus
1143 * associated with it, go into message out, and send an abort message.
1144 */
1145 for (tmp = sea->nexus_list.tqh_first; tmp;
1146 tmp = tmp->chain.tqe_next)
1147 if (scb == tmp) {
1148 if (sea_select(sea, scb))
1149 return 0;
1150
1151 msg = MSG_ABORT;
1152 msgptr = &msg;
1153 len = 1;
1154 phase = PH_MSGOUT;
1155 CONTROL = BASE_CMD | CMD_ATTN;
1156 sea_transfer_pio(sea, &phase, &len, &msgptr);
1157
1158 for (tmp = sea->nexus_list.tqh_first; tmp;
1159 tmp = tmp->chain.tqe_next)
1160 if (scb == tmp) {
1161 TAILQ_REMOVE(&sea->nexus_list,
1162 scb, chain);
1163 /* XXX Set some type of error result
1164 for the operation. */
1165 return 1;
1166 }
1167 }
1168
1169 /* Command not found in any queue; race condition? */
1170 return 1;
1171 }
1172
1173 void
1174 sea_done(sea, scb)
1175 struct sea_softc *sea;
1176 struct sea_scb *scb;
1177 {
1178 struct scsipi_xfer *xs = scb->xs;
1179
1180 untimeout(sea_timeout, scb);
1181
1182 xs->resid = scb->datalen;
1183
1184 /* XXXX need to get status */
1185 if (scb->flags == SCB_ACTIVE) {
1186 xs->resid = 0;
1187 } else {
1188 if (scb->flags & (SCB_TIMEOUT | SCB_ABORTED))
1189 xs->error = XS_TIMEOUT;
1190 if (scb->flags & SCB_ERROR)
1191 xs->error = XS_DRIVER_STUFFUP;
1192 }
1193 xs->flags |= ITSDONE;
1194 sea_free_scb(sea, scb, xs->flags);
1195 scsipi_done(xs);
1196 }
1197
1198 /*
1199 * Wait for completion of command in polled mode.
1200 */
1201 int
1202 sea_poll(sea, xs, count)
1203 struct sea_softc *sea;
1204 struct scsipi_xfer *xs;
1205 int count;
1206 {
1207 int s;
1208
1209 while (count) {
1210 /* try to do something */
1211 s = splbio();
1212 if (!main_running)
1213 sea_main();
1214 splx(s);
1215 if (xs->flags & ITSDONE)
1216 return 0;
1217 delay(1000);
1218 count--;
1219 }
1220 return 1;
1221 }
1222
1223 /*
1224 * Do the transfer. We know we are connected. Update the flags, and call
1225 * sea_done() when task accomplished. Dialog controlled by the target.
1226 */
1227 void
1228 sea_information_transfer(sea)
1229 struct sea_softc *sea;
1230 {
1231 int timeout;
1232 u_char msgout = MSG_NOOP;
1233 int len;
1234 int s;
1235 u_char *data;
1236 u_char phase, tmp, old_phase = PH_INVALID;
1237 struct sea_scb *scb = sea->nexus;
1238 int loop;
1239
1240 for (timeout = 0; timeout < 10000000L; timeout++) {
1241 tmp = STATUS;
1242 if (tmp & STAT_PARITY)
1243 printf("%s: parity error detected\n",
1244 sea->sc_dev.dv_xname);
1245 if (!(tmp & STAT_BSY)) {
1246 for (loop = 0; loop < 20; loop++)
1247 if ((tmp = STATUS) & STAT_BSY)
1248 break;
1249 if (!(tmp & STAT_BSY)) {
1250 printf("%s: !STAT_BSY unit in data transfer!\n",
1251 sea->sc_dev.dv_xname);
1252 s = splbio();
1253 sea->nexus = NULL;
1254 scb->flags = SCB_ERROR;
1255 splx(s);
1256 sea_done(sea, scb);
1257 return;
1258 }
1259 }
1260
1261 /* we only have a valid SCSI phase when REQ is asserted */
1262 if (!(tmp & STAT_REQ))
1263 continue;
1264
1265 if (sea->type == FDOMAIN840)
1266 tmp = ((tmp & 0x08) >> 2) |
1267 ((tmp & 0x02) << 2) |
1268 (tmp & 0xf5);
1269 phase = tmp & PH_MASK;
1270 if (phase != old_phase)
1271 old_phase = phase;
1272
1273 switch (phase) {
1274 case PH_DATAOUT:
1275 #ifdef SEA_NODATAOUT
1276 printf("%s: SEA_NODATAOUT set, attempted DATAOUT aborted\n",
1277 sea->sc_dev.dv_xname);
1278 msgout = MSG_ABORT;
1279 CONTROL = BASE_CMD | CMD_ATTN;
1280 break;
1281 #endif
1282 case PH_DATAIN:
1283 if (!scb->data)
1284 printf("no data address!\n");
1285 #ifdef SEA_BLINDTRANSFER
1286 if (scb->datalen && !(scb->datalen % BLOCK_SIZE)) {
1287 while (scb->datalen) {
1288 for (loop = 0; loop < 50000; loop++)
1289 if ((tmp = STATUS) & STAT_REQ)
1290 break;
1291 if (!(tmp & STAT_REQ)) {
1292 printf("%s: timeout waiting for STAT_REQ\n",
1293 sea->sc_dev.dv_xname);
1294 /* XXX Do something? */
1295 }
1296 if (sea->type == FDOMAIN840)
1297 tmp = ((tmp & 0x08) >> 2) |
1298 ((tmp & 0x02) << 2) |
1299 (tmp & 0xf5);
1300 if ((tmp & PH_MASK) != phase)
1301 break;
1302 if (!(phase & STAT_IO)) {
1303 #ifdef SEA_ASSEMBLER
1304 asm("shr $2, %%ecx\n\t\
1305 cld\n\t\
1306 rep\n\t\
1307 movsl" :
1308 "=S" (scb->data) :
1309 "0" (scb->data),
1310 "D" (sea->maddr_dr),
1311 "c" (BLOCK_SIZE) :
1312 "%ecx", "%edi");
1313 #else
1314 for (count = 0;
1315 count < BLOCK_SIZE;
1316 count++)
1317 DATA = *(scb->data++);
1318 #endif
1319 } else {
1320 #ifdef SEA_ASSEMBLER
1321 asm("shr $2, %%ecx\n\t\
1322 cld\n\t\
1323 rep\n\t\
1324 movsl" :
1325 "=D" (scb->data) :
1326 "S" (sea->maddr_dr),
1327 "0" (scb->data),
1328 "c" (BLOCK_SIZE) :
1329 "%ecx", "%esi");
1330 #else
1331 for (count = 0;
1332 count < BLOCK_SIZE;
1333 count++)
1334 *(scb->data++) = DATA;
1335 #endif
1336 }
1337 scb->datalen -= BLOCK_SIZE;
1338 }
1339 }
1340 #endif
1341 if (scb->datalen)
1342 sea_transfer_pio(sea, &phase, &scb->datalen,
1343 &scb->data);
1344 break;
1345 case PH_MSGIN:
1346 /* Multibyte messages should not be present here. */
1347 len = 1;
1348 data = &tmp;
1349 sea_transfer_pio(sea, &phase, &len, &data);
1350 /* scb->MessageIn = tmp; */
1351
1352 switch (tmp) {
1353 case MSG_ABORT:
1354 scb->flags = SCB_ABORTED;
1355 printf("sea: command aborted by target\n");
1356 CONTROL = BASE_CMD;
1357 sea_done(sea, scb);
1358 return;
1359 case MSG_CMDCOMPLETE:
1360 s = splbio();
1361 sea->nexus = NULL;
1362 splx(s);
1363 sea->busy[scb->xs->sc_link->scsipi_scsi.target] &=
1364 ~(1 << scb->xs->sc_link->scsipi_scsi.lun);
1365 CONTROL = BASE_CMD;
1366 sea_done(sea, scb);
1367 return;
1368 case MSG_MESSAGE_REJECT:
1369 printf("%s: message_reject recieved\n",
1370 sea->sc_dev.dv_xname);
1371 break;
1372 case MSG_DISCONNECT:
1373 s = splbio();
1374 TAILQ_INSERT_TAIL(&sea->nexus_list,
1375 scb, chain);
1376 sea->nexus = NULL;
1377 CONTROL = BASE_CMD;
1378 splx(s);
1379 return;
1380 case MSG_SAVEDATAPOINTER:
1381 case MSG_RESTOREPOINTERS:
1382 /* save/restore of pointers are ignored */
1383 break;
1384 default:
1385 /*
1386 * This should be handled in the pio data
1387 * transfer phase, as the ATN should be raised
1388 * before ACK goes false when rejecting a
1389 * message.
1390 */
1391 printf("%s: unknown message in: %x\n",
1392 sea->sc_dev.dv_xname, tmp);
1393 break;
1394 } /* switch (tmp) */
1395 break;
1396 case PH_MSGOUT:
1397 len = 1;
1398 data = &msgout;
1399 /* sea->last_message = msgout; */
1400 sea_transfer_pio(sea, &phase, &len, &data);
1401 if (msgout == MSG_ABORT) {
1402 printf("%s: sent message abort to target\n",
1403 sea->sc_dev.dv_xname);
1404 s = splbio();
1405 sea->busy[scb->xs->sc_link->scsipi_scsi.target] &=
1406 ~(1 << scb->xs->sc_link->scsipi_scsi.lun);
1407 sea->nexus = NULL;
1408 scb->flags = SCB_ABORTED;
1409 splx(s);
1410 /* enable interrupt from scsi */
1411 sea_done(sea, scb);
1412 return;
1413 }
1414 msgout = MSG_NOOP;
1415 break;
1416 case PH_CMD:
1417 len = scb->xs->cmdlen;
1418 data = (char *) scb->xs->cmd;
1419 sea_transfer_pio(sea, &phase, &len, &data);
1420 break;
1421 case PH_STAT:
1422 len = 1;
1423 data = &tmp;
1424 sea_transfer_pio(sea, &phase, &len, &data);
1425 scb->xs->status = tmp;
1426 break;
1427 default:
1428 printf("sea: unknown phase\n");
1429 } /* switch (phase) */
1430 } /* for (...) */
1431
1432 /* If we get here we have got a timeout! */
1433 printf("%s: timeout in data transfer\n", sea->sc_dev.dv_xname);
1434 scb->flags = SCB_TIMEOUT;
1435 /* XXX Should I clear scsi-bus state? */
1436 sea_done(sea, scb);
1437 }
1438