sc.c revision 1.15 1 /* $NetBSD: sc.c,v 1.15 2017/10/31 14:55:45 christos Exp $ */
2
3 /*
4 * Copyright (c) 1992 OMRON Corporation.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * OMRON Corporation.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the University of
20 * California, Berkeley and its contributors.
21 * 4. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR 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 * @(#)sc.c 8.1 (Berkeley) 6/10/93
38 */
39 /*
40 * Copyright (c) 1992, 1993
41 * The Regents of the University of California. All rights reserved.
42 *
43 * This code is derived from software contributed to Berkeley by
44 * OMRON Corporation.
45 *
46 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
48 * are met:
49 * 1. Redistributions of source code must retain the above copyright
50 * notice, this list of conditions and the following disclaimer.
51 * 2. Redistributions in binary form must reproduce the above copyright
52 * notice, this list of conditions and the following disclaimer in the
53 * documentation and/or other materials provided with the distribution.
54 * 3. Neither the name of the University nor the names of its contributors
55 * may be used to endorse or promote products derived from this software
56 * without specific prior written permission.
57 *
58 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * SUCH DAMAGE.
69 *
70 * @(#)sc.c 8.1 (Berkeley) 6/10/93
71 */
72
73 /*
74 * sc.c -- SCSI Protocole Controller (SPC) driver
75 * remaked by A.Fujita, MAR-11-199
76 */
77
78
79 #define NSC 2
80
81 #include <sys/param.h>
82 #include <luna68k/stand/boot/samachdep.h>
83 #include <luna68k/stand/boot/scsireg.h>
84 #include <luna68k/stand/boot/scsivar.h>
85
86 #define SCSI_ID 7
87
88 static void screset(struct scsi_softc *);
89 static void scprobe(struct scsi_softc *, uint, uint);
90 static int issue_select(struct scsidevice *, uint8_t);
91 static void ixfer_start(struct scsidevice *, int, uint8_t, int);
92 static void ixfer_out(struct scsidevice *, int, uint8_t *);
93 static void ixfer_in(struct scsidevice *, int, uint8_t *);
94 static int scrun(int, int, uint8_t *, int, uint8_t *, int, volatile int *);
95 static int scfinish(int);
96 static void scabort(struct scsi_softc *);
97
98 struct scsi_softc scsi_softc[NSC];
99
100 /*
101 * Initialize SPC & Data Structure
102 */
103
104 int
105 scinit(int ctlr, void *addr)
106 {
107 struct scsi_softc *hs;
108 uint id;
109
110 if (ctlr < 0 || ctlr >= NSC)
111 return 0;
112
113 hs = &scsi_softc[ctlr];
114 hs->sc_ctlr = ctlr;
115 hs->sc_spc = addr;
116
117 hs->sc_flags = 0;
118 hs->sc_phase = BUS_FREE_PHASE;
119 hs->sc_target = SCSI_ID;
120
121 hs->sc_cdb = NULL;
122 hs->sc_cdblen = 0;
123 hs->sc_buf = NULL;
124 hs->sc_len = 0;
125 hs->sc_lock = NULL;
126
127 hs->sc_stat = 0;
128 hs->sc_msg[0] = 0;
129
130 screset(hs);
131
132 for (id = 0; id < 7; id++)
133 scprobe(hs, id, 0);
134
135 return 1;
136 }
137
138 static void
139 screset(struct scsi_softc *hs)
140 {
141 struct scsidevice *hd = hs->sc_spc;
142
143 printf("sc%d at 0x%08lx: ", hs->sc_ctlr, (u_long)hs->sc_spc);
144
145 /*
146 * Disable interrupts then reset the FUJI chip.
147 */
148
149 hd->scsi_sctl = SCTL_DISABLE | SCTL_CTRLRST;
150 hd->scsi_scmd = 0;
151 hd->scsi_pctl = 0;
152 hd->scsi_temp = 0;
153 hd->scsi_tch = 0;
154 hd->scsi_tcm = 0;
155 hd->scsi_tcl = 0;
156 hd->scsi_ints = 0;
157
158 /* We can use Asynchronous Transfer only */
159 printf("async");
160
161 /*
162 * Configure MB89352 with its SCSI address, all
163 * interrupts enabled & appropriate parity.
164 */
165 hd->scsi_bdid = SCSI_ID;
166 hd->scsi_sctl = SCTL_DISABLE | SCTL_ABRT_ENAB|
167 SCTL_PARITY_ENAB | SCTL_RESEL_ENAB |
168 SCTL_INTR_ENAB;
169 printf(", parity");
170
171 DELAY(400);
172 hd->scsi_sctl &= ~SCTL_DISABLE;
173
174 printf(", ID %d\n", SCSI_ID);
175 }
176
177 bool
178 scident(uint ctlr, uint target, uint lun, struct scsi_inquiry *inqout,
179 uint32_t *capout)
180 {
181 struct scsi_inquiry inqbuf;
182 struct scsi_generic_cdb inq = {
183 6,
184 { CMD_INQUIRY, 0, 0, 0, sizeof(inqbuf), 0 }
185 };
186 uint32_t capbuf[2];
187 struct scsi_generic_cdb cap = {
188 10,
189 { CMD_READ_CAPACITY, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
190 };
191 int i;
192 int tries = 10;
193
194 /*
195 * See if unit exists and is a disk then read block size & nblocks.
196 */
197 while ((i = scsi_test_unit_rdy(ctlr, target, lun)) != 0) {
198 if (i < 0 || --tries < 0)
199 return false;
200 if (i == STS_CHECKCOND) {
201 uint8_t sensebuf[8];
202 struct scsi_xsense *sp = (struct scsi_xsense *)sensebuf;
203
204 scsi_request_sense(ctlr, target, lun, sensebuf, 8);
205 if (sp->class == 7 && sp->key == 6)
206 /* drive doing an RTZ -- give it a while */
207 DELAY(1000000);
208 }
209 DELAY(1000);
210 }
211 if (scsi_immed_command(ctlr, target, lun, &inq, (uint8_t *)&inqbuf,
212 sizeof(inqbuf)) ||
213 scsi_immed_command(ctlr, target, lun, &cap, (uint8_t *)&capbuf,
214 sizeof(capbuf)))
215 /* doesn't exist or not a CCS device */
216 return false;
217
218 switch (inqbuf.type) {
219 case 0: /* disk */
220 case 4: /* WORM */
221 case 5: /* CD-ROM */
222 case 7: /* Magneto-optical */
223 break;
224 default: /* not a disk */
225 return false;
226 }
227
228 if (inqout != NULL)
229 *inqout = inqbuf;
230 if (capout != NULL) {
231 /* assume big endian */
232 capout[0] = capbuf[0];
233 capout[1] = capbuf[1];
234 }
235
236 return true;
237 }
238
239 static void
240 scprobe(struct scsi_softc *hs, uint target, uint lun)
241 {
242 struct scsi_inquiry inqbuf;
243 uint32_t capbuf[2];
244 char idstr[32];
245 int i;
246
247 if (!scident(hs->sc_ctlr, target, lun, &inqbuf, capbuf))
248 return;
249
250 memcpy(idstr, &inqbuf.vendor_id, 28);
251 for (i = 27; i > 23; --i)
252 if (idstr[i] != ' ')
253 break;
254 idstr[i + 1] = '\0';
255 for (i = 23; i > 7; --i)
256 if (idstr[i] != ' ')
257 break;
258 idstr[i + 1] = '\0';
259 for (i = 7; i >= 0; --i)
260 if (idstr[i] != ' ')
261 break;
262 idstr[i + 1] = '\0';
263
264 printf(" ID %d: %s %s rev %s", target, idstr, &idstr[8], &idstr[24]);
265 printf(", %d bytes/sect x %d sectors\n", capbuf[1], capbuf[0]);
266 }
267
268
269 /*
270 * SPC Arbitration/Selection routine
271 */
272
273 static int
274 issue_select(struct scsidevice *hd, uint8_t target)
275 {
276
277 hd->scsi_pctl = 0;
278 hd->scsi_temp = (1 << SCSI_ID) | (1 << target);
279
280 /* select timeout is hardcoded to 250ms */
281 hd->scsi_tch = 2;
282 hd->scsi_tcm = 113;
283 hd->scsi_tcl = 3;
284
285 hd->scsi_scmd = SCMD_SELECT;
286
287 return 1;
288 }
289
290
291 /*
292 * SPC Manual Transfer routines
293 */
294
295 /* not yet */
296
297
298 /*
299 * SPC Program Transfer routines
300 */
301
302 static void
303 ixfer_start(struct scsidevice *hd, int len, uint8_t phase, int wait)
304 {
305
306 hd->scsi_tch = ((len & 0xff0000) >> 16);
307 hd->scsi_tcm = ((len & 0x00ff00) >> 8);
308 hd->scsi_tcl = (len & 0x0000ff);
309 hd->scsi_pctl = phase;
310 hd->scsi_scmd = SCMD_XFR | SCMD_PROG_XFR;
311 }
312
313 static void
314 ixfer_out(struct scsidevice *hd, int len, uint8_t *buf)
315 {
316
317 for (; len > 0; len--) {
318 while (hd->scsi_ssts & SSTS_DREG_FULL) {
319 DELAY(5);
320 }
321 hd->scsi_dreg = *buf++;
322 }
323 }
324
325 static void
326 ixfer_in(struct scsidevice *hd, int len, uint8_t *buf)
327 {
328
329 for (; len > 0; len--) {
330 while (hd->scsi_ssts & SSTS_DREG_EMPTY) {
331 DELAY(5);
332 }
333 *buf++ = hd->scsi_dreg;
334 }
335 }
336
337
338 /*
339 * SPC drive routines
340 */
341
342 static int
343 scrun(int ctlr, int target, uint8_t *cdb, int cdblen, uint8_t *buf, int len,
344 volatile int *lock)
345 {
346 struct scsi_softc *hs;
347 struct scsidevice *hd;
348
349 if (ctlr < 0 || ctlr >= NSC)
350 return 0;
351
352 hs = &scsi_softc[ctlr];
353 hd = hs->sc_spc;
354 if (hd == NULL)
355 return 0;
356
357 if ((hd->scsi_ssts & (SSTS_INITIATOR | SSTS_TARGET | SSTS_BUSY)) != 0)
358 return 0;
359
360 hs->sc_flags = 0;
361 hs->sc_phase = ARB_SEL_PHASE;
362 hs->sc_target = target;
363
364 hs->sc_cdb = cdb;
365 hs->sc_cdblen = cdblen;
366 hs->sc_buf = buf;
367 hs->sc_len = len;
368 hs->sc_lock = lock;
369
370 hs->sc_stat = 0;
371 hs->sc_msg[0] = 0;
372
373 *(hs->sc_lock) = SC_IN_PROGRESS;
374 issue_select(hd, hs->sc_target);
375
376 return 1;
377 }
378
379 static int
380 scfinish(int ctlr)
381 {
382 struct scsi_softc *hs = &scsi_softc[ctlr];
383 int status = hs->sc_stat;
384
385 hs->sc_flags = 0;
386 hs->sc_phase = BUS_FREE_PHASE;
387 hs->sc_target = SCSI_ID;
388
389 hs->sc_cdb = NULL;
390 hs->sc_cdblen = 0;
391 hs->sc_buf = NULL;
392 hs->sc_len = 0;
393 hs->sc_lock = NULL;
394
395 hs->sc_stat = 0;
396 hs->sc_msg[0] = 0;
397
398 return status;
399 }
400
401 static void
402 scabort(struct scsi_softc *hs)
403 {
404 struct scsidevice *hd = hs->sc_spc;
405 int len;
406
407 printf("sc%d: abort phase=0x%x, ssts=0x%x, ints=0x%x\n",
408 hs->sc_ctlr, hd->scsi_psns, hd->scsi_ssts, hd->scsi_ints);
409
410 if (hd->scsi_psns == 0 || (hd->scsi_ssts & SSTS_INITIATOR) == 0)
411 /* no longer connected to scsi target */
412 return;
413
414 /* get the number of bytes remaining in current xfer + fudge */
415 len = (hd->scsi_tch << 16) | (hd->scsi_tcm << 8) | hd->scsi_tcl;
416
417 /* for that many bus cycles, try to send an abort msg */
418 for (len += 1024;
419 ((hd->scsi_ssts & SSTS_INITIATOR)) != 0 && --len >= 0;) {
420 hd->scsi_scmd = SCMD_SET_ATN;
421
422 while ((hd->scsi_psns & PSNS_REQ) == 0) {
423 if ((hd->scsi_ssts & SSTS_INITIATOR) == 0)
424 goto out;
425 DELAY(1);
426 }
427
428 if ((hd->scsi_psns & PHASE) == MESG_OUT_PHASE)
429 hd->scsi_scmd = SCMD_RST_ATN;
430 hd->scsi_pctl = hs->sc_phase = hd->scsi_psns & PHASE;
431
432 if (hd->scsi_psns & PHASE_IO) {
433 /* one of the input phases - read & discard a byte */
434 hd->scsi_scmd = SCMD_SET_ACK;
435 while ((hd->scsi_psns & PSNS_REQ) != 0)
436 DELAY(1);
437 (void)hd->scsi_temp;
438 } else {
439 /* one of the output phases - send an abort msg */
440 hd->scsi_temp = MSG_ABORT;
441 hd->scsi_scmd = SCMD_SET_ACK;
442 while ((hd->scsi_psns & PSNS_REQ) != 0)
443 DELAY(1);
444 }
445
446 hd->scsi_scmd = SCMD_RST_ACK;
447 }
448 out:
449 /*
450 * Either the abort was successful & the bus is disconnected or
451 * the device didn't listen. If the latter, announce the problem.
452 * Either way, reset the card & the SPC.
453 */
454 if (len < 0 && hs)
455 printf("sc%d: abort failed. phase=0x%x, ssts=0x%x\n",
456 hs->sc_ctlr, hd->scsi_psns, hd->scsi_ssts);
457 }
458
459
460 /*
461 * SCSI Command Handler
462 */
463
464 int
465 scsi_test_unit_rdy(int ctlr, int target, int lun)
466 {
467 static struct scsi_cdb6 cdb = { CMD_TEST_UNIT_READY };
468 int status;
469 volatile int lock;
470
471 #ifdef DEBUG
472 printf("scsi_test_unit_rdy( %d, %d, %d): Start\n", ctlr, target, lun);
473 #endif
474
475 cdb.lun = lun;
476
477 if (scrun(ctlr, target, (void *)&cdb, 6, NULL, 0, &lock) == 0) {
478 #ifdef DEBUG
479 printf("scsi_test_unit_rdy: Command Transfer Failed.\n");
480 #endif
481 return -1;
482 }
483
484 while ((lock == SC_IN_PROGRESS) || (lock == SC_DISCONNECTED))
485 DELAY(10);
486
487 status = scfinish(ctlr);
488
489 if (lock == SC_IO_COMPLETE) {
490 #ifdef DEBUG
491 printf("scsi_test_unit_rdy: Status -- 0x%x\n", status);
492 #endif
493 return status;
494 } else {
495 return lock;
496 }
497 }
498
499 int
500 scsi_request_sense(int ctlr, int target, int lun, uint8_t *buf,
501 unsigned int len)
502 {
503 static struct scsi_cdb6 cdb = { CMD_REQUEST_SENSE };
504 int status;
505 volatile int lock;
506
507 #ifdef DEBUG
508 printf("scsi_request_sense: Start\n");
509 #endif
510
511 /* Request Sense */
512 /* Additional Sens Length*/
513 /* cdbAllocation Length */
514 /* */
515
516 /* Addtional Sens Field */
517 /* len */
518
519 cdb.lun = lun;
520 cdb.len = len;
521
522 if (scrun(ctlr, target, (void *)&cdb, 6, buf, len, &lock) == 0) {
523 #ifdef DEBUG
524 printf("scsi_request_sense: Command Transfer Failed.\n");
525 #endif
526 return -1;
527 }
528
529 while ((lock == SC_IN_PROGRESS) || (lock == SC_DISCONNECTED))
530 DELAY(10);
531
532 status = scfinish(ctlr);
533
534 if (lock == SC_IO_COMPLETE) {
535 #ifdef DEBUG
536 printf("scsi_request_sense: Status -- 0x%x\n", status);
537 #endif
538 return status;
539 } else {
540 return lock;
541 }
542 }
543
544 int
545 scsi_immed_command(int ctlr, int target, int lun, struct scsi_generic_cdb *cdb,
546 uint8_t *buf, unsigned int len)
547 {
548 int status;
549 volatile int lock;
550
551 #ifdef DEBUG
552 printf("scsi_immed_command( %d, %d, %d, cdb(%d), buf, %d): Start\n",
553 ctlr, target, lun, cdb->len, len);
554 #endif
555
556 cdb->cdb[1] |= lun << 5;
557
558 if (scrun(ctlr, target, (void *)&cdb->cdb[0], cdb->len, buf, len,
559 &lock) == 0) {
560 #ifdef DEBUG
561 printf("scsi_immed_command: Command Transfer Failed.\n");
562 #endif
563 return -1;
564 }
565
566 while ((lock == SC_IN_PROGRESS) || (lock == SC_DISCONNECTED))
567 DELAY(10);
568
569 status = scfinish(ctlr);
570
571 if (lock == SC_IO_COMPLETE) {
572 #ifdef DEBUG
573 printf("scsi_immed_command: Status -- 0x%x\n", status);
574 #endif
575 return status;
576 } else {
577 return lock;
578 }
579 }
580
581 int
582 scsi_format_unit(int ctlr, int target, int lun)
583 {
584 static struct scsi_cdb6 cdb = { CMD_FORMAT_UNIT, 0, 0, 0, 0, 0 };
585 int status;
586 volatile int lock;
587 #ifdef DEBUG
588 int count = 0;
589 #endif
590
591 #ifdef DEBUG
592 printf("scsi_format_unit( %d, %d, %d): Start\n", ctlr, target, lun);
593 #endif
594
595 cdb.lun = lun;
596
597 if (scrun(ctlr, target, (void *)&cdb, 6, NULL, 0, &lock) == 0) {
598 #ifdef DEBUG
599 printf("scsi_format_unit: Command Transfer Failed.\n");
600 #endif
601 return -1;
602 }
603
604 while ((lock == SC_IN_PROGRESS) || (lock == SC_DISCONNECTED)) {
605 DELAY(1000000);
606 #ifdef DEBUG
607 if ((++count % 60) == 0)
608 printf("scsi_format_unit: %d\n", count / 60);
609 #endif
610 }
611
612 status = scfinish(ctlr);
613
614 if (lock == SC_IO_COMPLETE) {
615 #ifdef DEBUG
616 printf("scsi_format_unit: Status -- 0x%x\n", status);
617 #endif
618 return status;
619 } else {
620 return lock;
621 }
622 }
623
624
625 /*
626 * Interrupt Routine
627 */
628
629 int
630 scintr(void)
631 {
632 struct scsi_softc *hs;
633 struct scsidevice *hd;
634 uint8_t ints, temp;
635 int i;
636 uint8_t *buf;
637 int len;
638
639 for (i = 0; i < NSC; i++) {
640 hs = &scsi_softc[i];
641 hd = hs->sc_spc;
642 if ((ints = hd->scsi_ints) != 0)
643 goto get_intr;
644 }
645
646 /* Unknown Interrupt occured */
647 return -1;
648
649
650 /*
651 * Interrupt
652 */
653
654 get_intr:
655 #ifdef DEBUG
656 printf("scintr: INTS 0x%x, SSTS 0x%x, PCTL 0x%x, PSNS 0x%x 0x%x\n",
657 ints, hd->scsi_ssts, hd->scsi_pctl, hd->scsi_psns, hs->sc_phase);
658 #endif
659 if (ints & INTS_RESEL) {
660 if (hs->sc_phase == BUS_FREE_PHASE) {
661 temp = hd->scsi_temp & ~(1 << SCSI_ID);
662 for (i = 0; temp != 1; i++) {
663 temp >>= 1;
664 }
665 hs->sc_target = i;
666 *(hs->sc_lock) = SC_IN_PROGRESS;
667 } else
668 goto abort;
669 } else if (ints & INTS_DISCON) {
670 if ((hs->sc_msg[0] == MSG_CMD_COMPLETE) ||
671 (hs->sc_msg[0] == MSG_DISCONNECT)) {
672 hs->sc_phase = BUS_FREE_PHASE;
673 hs->sc_target = SCSI_ID;
674 if (hs->sc_msg[0] == MSG_CMD_COMPLETE) {
675 /* SCSI IO complete */
676 *(hs->sc_lock) = SC_IO_COMPLETE;
677 } else {
678 /* Disconnected from Target */
679 *(hs->sc_lock) = SC_DISCONNECTED;
680 }
681 hd->scsi_ints = ints;
682 return 0;
683 } else
684 goto abort;
685 } else if (ints & INTS_CMD_DONE) {
686 if (hs->sc_phase == BUS_FREE_PHASE)
687 goto abort;
688 else if (hs->sc_phase == MESG_IN_PHASE) {
689 hd->scsi_scmd = SCMD_RST_ACK;
690 hd->scsi_ints = ints;
691 hs->sc_phase = hd->scsi_psns & PHASE;
692 return 0;
693 }
694 if (hs->sc_flags & SC_SEL_TIMEOUT)
695 hs->sc_flags &= ~SC_SEL_TIMEOUT;
696 } else if (ints & INTS_SRV_REQ) {
697 if (hs->sc_phase != MESG_IN_PHASE)
698 goto abort;
699 } else if (ints & INTS_TIMEOUT) {
700 if (hs->sc_phase == ARB_SEL_PHASE) {
701 if (hs->sc_flags & SC_SEL_TIMEOUT) {
702 hs->sc_flags &= ~SC_SEL_TIMEOUT;
703 hs->sc_phase = BUS_FREE_PHASE;
704 hs->sc_target = SCSI_ID;
705 /* Such SCSI Device is not connected. */
706 *(hs->sc_lock) = SC_DEV_NOT_FOUND;
707 hd->scsi_ints = ints;
708 return 0;
709 } else {
710 /* wait more 250 usec */
711 hs->sc_flags |= SC_SEL_TIMEOUT;
712 hd->scsi_temp = 0;
713 hd->scsi_tch = 0;
714 hd->scsi_tcm = 0x06;
715 hd->scsi_tcl = 0x40;
716 hd->scsi_ints = ints;
717 return 0;
718 }
719 } else
720 goto abort;
721 } else
722 goto abort;
723
724 hd->scsi_ints = ints;
725
726 /*
727 * Next SCSI Transfer
728 */
729
730 while ((hd->scsi_psns & PSNS_REQ) == 0) {
731 DELAY(1);
732 }
733
734 hs->sc_phase = hd->scsi_psns & PHASE;
735
736 if ((hs->sc_phase == DATA_OUT_PHASE) ||
737 (hs->sc_phase == DATA_IN_PHASE)) {
738 len = hs->sc_len;
739 buf = hs->sc_buf;
740 } else if (hs->sc_phase == CMD_PHASE) {
741 len = hs->sc_cdblen;
742 buf = hs->sc_cdb;
743 } else if (hs->sc_phase == STATUS_PHASE) {
744 len = 1;
745 buf = &hs->sc_stat;
746 } else {
747 len = 1;
748 buf = hs->sc_msg;
749 }
750
751 ixfer_start(hd, len, hs->sc_phase, 0);
752 if (hs->sc_phase & PHASE_IO)
753 ixfer_in(hd, len, buf);
754 else
755 ixfer_out(hd, len, buf);
756
757 return 0;
758
759 /*
760 * SCSI Abort
761 */
762 abort:
763 /* SCSI IO failed */
764 scabort(hs);
765 hd->scsi_ints = ints;
766 *(hs->sc_lock) = SC_IO_FAILED;
767 return -1;
768 }
769