Lines Matching +full:clk +full:- +full:phase +full:-
1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (c) 1994-1998 Initio Corporation
14 * This is the Linux low-level SCSI driver for Initio INI-9X00U/UW SCSI host
17 * 08/06/97 hc - v1.01h
18 * - Support inic-940 and inic-935
19 * 09/26/97 hc - v1.01i
20 * - Make correction from J.W. Schultz suggestion
21 * 10/13/97 hc - Support reset function
22 * 10/21/97 hc - v1.01j
23 * - Support 32 LUN (SCSI 3)
24 * 01/14/98 hc - v1.01k
25 * - Fix memory allocation problem
26 * 03/04/98 hc - v1.01l
27 * - Fix tape rewind which will hang the system problem
28 * - Set can_queue to initio_num_scb
29 * 06/25/98 hc - v1.01m
30 * - Get it work for kernel version >= 2.1.75
31 * - Dynamic assign SCSI bus reset holding time in initio_init()
32 * 07/02/98 hc - v1.01n
33 * - Support 0002134A
34 * 08/07/98 hc - v1.01o
35 * - Change the initio_abort_srb routine to use scsi_done. <01>
36 * 09/07/98 hl - v1.02
37 * - Change the INI9100U define and proc_dir_entry to
40 * 09/20/98 wh - v1.02a
41 * - Support Abort command.
42 * - Handle reset routine.
43 * 09/21/98 hl - v1.03
44 * - remove comments.
45 * 12/09/98 bv - v1.03a
46 * - Removed unused code
47 * 12/13/98 bv - v1.03b
48 * - Remove cli() locking for kernels >= 2.1.95. This uses
51 * 09/01/99 bv - v1.03d
52 * - Fixed a deadlock problem in SMP.
53 * 21/01/99 bv - v1.03e
54 * - Add support for the Domex 3192U PCI SCSI
57 * 22/02/99 bv - v1.03f
58 * - Didn't detect the INIC-950 in 2.0.x correctly.
60 * 05/07/99 bv - v1.03g
61 * - Changed the assumption that HZ = 100
62 * 10/17/03 mc - v1.04
63 * - added new DMA API support
64 * 06/01/04 jmd - v1.04a
65 * - Re-add reset_bus support
83 #include <linux/dma-mapping.h>
97 #define i91u_REVID "Initio INI-9X00U/UW SCSI device driver; Revision: 1.04a"
116 /*--- forward references ---*/
168 /* ---- INTERNAL VARIABLES ---- */
175 /*----------- header -----------*/
179 /* -- Host Adapter Structure -- */
210 0, 0}; /* - CheckSum - */
235 /*-- forward reference --*/
243 --------- -------- ------------------ -------
244 1 1 , 0 A5,A4,A3,A2,A1,A0 D15-D0
246 +-----------------------------------------------------
248 CS -----+
249 +--+ +--+ +--+ +--+ +--+
252 CLK -------+ +--+ +--+ +--+ +--+ +--
255 +--1-----1--+
257 DI ----+ +--0------------------
260 -------------------------------------------+
262 DO +---
269 * initio_se2_instr - bitbang an instruction
283 outb(SE2CS | SE2CLK | SE2DO, base + TUL_NVRAM); /* +CLK */ in initio_se2_instr()
288 b = SE2CS | SE2DO; /* -CLK+dataBit */ in initio_se2_instr()
290 b = SE2CS; /* -CLK */ in initio_se2_instr()
293 outb(b | SE2CLK, base + TUL_NVRAM); /* +CLK */ in initio_se2_instr()
297 outb(SE2CS, base + TUL_NVRAM); /* -CLK */ in initio_se2_instr()
303 * initio_se2_ew_en - Enable erase/write
311 outb(0, base + TUL_NVRAM); /* -CS */ in initio_se2_ew_en()
317 * initio_se2_ew_ds - Disable erase/write
325 outb(0, base + TUL_NVRAM); /* -CS */ in initio_se2_ew_ds()
331 * initio_se2_rd - read E2PROM word
346 for (i = 15; i >= 0; i--) { in initio_se2_rd()
347 outb(SE2CS | SE2CLK, base + TUL_NVRAM); /* +CLK */ in initio_se2_rd()
349 outb(SE2CS, base + TUL_NVRAM); /* -CLK */ in initio_se2_rd()
364 * initio_se2_wr - read E2PROM word
379 for (i = 15; i >= 0; i--) { in initio_se2_wr()
381 outb(SE2CS | SE2DO, base + TUL_NVRAM); /* -CLK+dataBit 1 */ in initio_se2_wr()
383 outb(SE2CS, base + TUL_NVRAM); /* -CLK+dataBit 0 */ in initio_se2_wr()
385 outb(SE2CS | SE2CLK, base + TUL_NVRAM); /* +CLK */ in initio_se2_wr()
389 outb(SE2CS, base + TUL_NVRAM); /* -CLK */ in initio_se2_wr()
391 outb(0, base + TUL_NVRAM); /* -CS */ in initio_se2_wr()
398 outb(SE2CS | SE2CLK, base + TUL_NVRAM); /* +CLK */ in initio_se2_wr()
400 outb(SE2CS, base + TUL_NVRAM); /* -CLK */ in initio_se2_wr()
405 outb(0, base + TUL_NVRAM); /* -CS */ in initio_se2_wr()
409 * initio_se2_rd_all - read hostadapter NV configuration
413 * and header marker are valid. Returns 1 on success -1 on error.
428 if (i91unvramp->NVM_Signature != INI_SIGNATURE) in initio_se2_rd_all()
429 return -1; in initio_se2_rd_all()
434 if (i91unvramp->NVM_CheckSum != chksum) in initio_se2_rd_all()
435 return -1; in initio_se2_rd_all()
440 * initio_se2_update_all - Update E2PROM
470 * initio_read_eeprom - Retrieve configuration
500 * initio_stop_bm - stop bus master
509 if (inb(host->addr + TUL_XStatus) & XPEND) { /* if DMA xfer is pending, abort DMA xfer */ in initio_stop_bm()
510 outb(TAX_X_ABT | TAX_X_CLR_FIFO, host->addr + TUL_XCmd); in initio_stop_bm()
512 while ((inb(host->addr + TUL_Int) & XABT) == 0) in initio_stop_bm()
515 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_stop_bm()
519 * initio_reset_scsi - Reset SCSI host controller
528 outb(TSC_RST_BUS, host->addr + TUL_SCtrl0); in initio_reset_scsi()
530 while (!((host->jsint = inb(host->addr + TUL_SInt)) & TSS_SCSIRST_INT)) in initio_reset_scsi()
534 outb(0, host->addr + TUL_SSignal); in initio_reset_scsi()
541 inb(host->addr + TUL_SInt); in initio_reset_scsi()
546 * initio_init - set up an InitIO host adapter
553 * Locking: Calls E2PROM layer code which is not re-enterable so must
564 initio_read_eeprom(host->addr); in initio_init()
565 if (i91unvramp->NVM_SCSIInfo[0].NVM_NumOfTarg == 8) in initio_init()
566 host->max_tar = 8; in initio_init()
568 host->max_tar = 16; in initio_init()
570 host->config = i91unvramp->NVM_SCSIInfo[0].NVM_ChConfig1; in initio_init()
572 host->scsi_id = i91unvramp->NVM_SCSIInfo[0].NVM_ChSCSIID; in initio_init()
573 host->idmask = ~(1 << host->scsi_id); in initio_init()
577 outb(inb(host->addr + TUL_PCMD) | 0x40, host->addr + TUL_PCMD); in initio_init()
581 outb(0x1F, host->addr + TUL_Mask); in initio_init()
584 /* --- Initialize the tulip --- */ in initio_init()
585 outb(TSC_RST_CHIP, host->addr + TUL_SCtrl0); in initio_init()
588 outb(host->scsi_id << 4, host->addr + TUL_SScsiId); in initio_init()
590 /* Enable Initiator Mode ,phase latch,alternate sync period mode, in initio_init()
592 if (host->config & HCC_EN_PAR) in initio_init()
593 host->sconf1 = (TSC_INITDEFAULT | TSC_EN_SCSI_PAR); in initio_init()
595 host->sconf1 = (TSC_INITDEFAULT); in initio_init()
596 outb(host->sconf1, host->addr + TUL_SConfig); in initio_init()
599 outb(TSC_HW_RESELECT, host->addr + TUL_SCtrl1); in initio_init()
601 outb(0, host->addr + TUL_SPeriod); in initio_init()
604 outb(153, host->addr + TUL_STimeOut); in initio_init()
607 outb((host->config & (HCC_ACT_TERM1 | HCC_ACT_TERM2)), in initio_init()
608 host->addr + TUL_XCtrl); in initio_init()
609 outb(((host->config & HCC_AUTO_TERM) >> 4) | in initio_init()
610 (inb(host->addr + TUL_GCTRL1) & 0xFE), in initio_init()
611 host->addr + TUL_GCTRL1); in initio_init()
614 flags = & (i91unvramp->NVM_SCSIInfo[0].NVM_Targ0Config), in initio_init()
616 i < host->max_tar; in initio_init()
618 host->targets[i].flags = *flags & ~(TCF_SYNC_DONE | TCF_WDTR_DONE); in initio_init()
619 if (host->targets[i].flags & TCF_EN_255) in initio_init()
620 host->targets[i].drv_flags = TCF_DRV_255_63; in initio_init()
622 host->targets[i].drv_flags = 0; in initio_init()
623 host->targets[i].js_period = 0; in initio_init()
624 host->targets[i].sconfig0 = host->sconf1; in initio_init()
625 host->targets[i].heads = *heads++; in initio_init()
626 if (host->targets[i].heads == 255) in initio_init()
627 host->targets[i].drv_flags = TCF_DRV_255_63; in initio_init()
629 host->targets[i].drv_flags = 0; in initio_init()
630 host->targets[i].sectors = *heads++; in initio_init()
631 host->targets[i].flags &= ~TCF_BUSY; in initio_init()
632 host->act_tags[i] = 0; in initio_init()
633 host->max_tags[i] = 0xFF; in initio_init()
636 host->addr, host->pci_dev->irq, in initio_init()
637 host->bios_addr, host->scsi_id); in initio_init()
639 if (host->config & HCC_SCSI_RESET) { in initio_init()
643 outb(0x17, host->addr + TUL_SCFG1); in initio_init()
644 outb(0xE9, host->addr + TUL_SIntEnable); in initio_init()
648 * initio_alloc_scb - Allocate an SCB
659 spin_lock_irqsave(&host->avail_lock, flags); in initio_alloc_scb()
660 if ((scb = host->first_avail) != NULL) { in initio_alloc_scb()
664 if ((host->first_avail = scb->next) == NULL) in initio_alloc_scb()
665 host->last_avail = NULL; in initio_alloc_scb()
666 scb->next = NULL; in initio_alloc_scb()
667 scb->status = SCB_RENT; in initio_alloc_scb()
669 spin_unlock_irqrestore(&host->avail_lock, flags); in initio_alloc_scb()
674 * initio_release_scb - Release an SCB
688 spin_lock_irqsave(&(host->avail_lock), flags); in initio_release_scb()
689 cmnd->srb = NULL; in initio_release_scb()
690 cmnd->status = 0; in initio_release_scb()
691 cmnd->next = NULL; in initio_release_scb()
692 if (host->last_avail != NULL) { in initio_release_scb()
693 host->last_avail->next = cmnd; in initio_release_scb()
694 host->last_avail = cmnd; in initio_release_scb()
696 host->first_avail = cmnd; in initio_release_scb()
697 host->last_avail = cmnd; in initio_release_scb()
699 spin_unlock_irqrestore(&(host->avail_lock), flags); in initio_release_scb()
709 scbp->status = SCB_PEND; in initio_append_pend_scb()
710 scbp->next = NULL; in initio_append_pend_scb()
711 if (host->last_pending != NULL) { in initio_append_pend_scb()
712 host->last_pending->next = scbp; in initio_append_pend_scb()
713 host->last_pending = scbp; in initio_append_pend_scb()
715 host->first_pending = scbp; in initio_append_pend_scb()
716 host->last_pending = scbp; in initio_append_pend_scb()
727 scbp->status = SCB_PEND; in initio_push_pend_scb()
728 if ((scbp->next = host->first_pending) != NULL) { in initio_push_pend_scb()
729 host->first_pending = scbp; in initio_push_pend_scb()
731 host->first_pending = scbp; in initio_push_pend_scb()
732 host->last_pending = scbp; in initio_push_pend_scb()
741 first = host->first_pending; in initio_find_first_pend_scb()
743 if (first->opcode != ExecSCSI) in initio_find_first_pend_scb()
745 if (first->tagmsg == 0) { in initio_find_first_pend_scb()
746 if ((host->act_tags[first->target] == 0) && in initio_find_first_pend_scb()
747 !(host->targets[first->target].flags & TCF_BUSY)) in initio_find_first_pend_scb()
750 if ((host->act_tags[first->target] >= in initio_find_first_pend_scb()
751 host->max_tags[first->target]) | in initio_find_first_pend_scb()
752 (host->targets[first->target].flags & TCF_BUSY)) { in initio_find_first_pend_scb()
753 first = first->next; in initio_find_first_pend_scb()
758 first = first->next; in initio_find_first_pend_scb()
771 prev = tmp = host->first_pending; in initio_unlink_pend_scb()
774 if (tmp == host->first_pending) { in initio_unlink_pend_scb()
775 if ((host->first_pending = tmp->next) == NULL) in initio_unlink_pend_scb()
776 host->last_pending = NULL; in initio_unlink_pend_scb()
778 prev->next = tmp->next; in initio_unlink_pend_scb()
779 if (tmp == host->last_pending) in initio_unlink_pend_scb()
780 host->last_pending = prev; in initio_unlink_pend_scb()
782 tmp->next = NULL; in initio_unlink_pend_scb()
786 tmp = tmp->next; in initio_unlink_pend_scb()
796 if (scbp->tagmsg) in initio_append_busy_scb()
797 host->act_tags[scbp->target]++; in initio_append_busy_scb()
799 host->targets[scbp->target].flags |= TCF_BUSY; in initio_append_busy_scb()
800 scbp->status = SCB_BUSY; in initio_append_busy_scb()
801 scbp->next = NULL; in initio_append_busy_scb()
802 if (host->last_busy != NULL) { in initio_append_busy_scb()
803 host->last_busy->next = scbp; in initio_append_busy_scb()
804 host->last_busy = scbp; in initio_append_busy_scb()
806 host->first_busy = scbp; in initio_append_busy_scb()
807 host->last_busy = scbp; in initio_append_busy_scb()
817 if ((tmp = host->first_busy) != NULL) { in initio_pop_busy_scb()
818 if ((host->first_busy = tmp->next) == NULL) in initio_pop_busy_scb()
819 host->last_busy = NULL; in initio_pop_busy_scb()
820 tmp->next = NULL; in initio_pop_busy_scb()
821 if (tmp->tagmsg) in initio_pop_busy_scb()
822 host->act_tags[tmp->target]--; in initio_pop_busy_scb()
824 host->targets[tmp->target].flags &= ~TCF_BUSY; in initio_pop_busy_scb()
841 prev = tmp = host->first_busy; in initio_unlink_busy_scb()
844 if (tmp == host->first_busy) { in initio_unlink_busy_scb()
845 if ((host->first_busy = tmp->next) == NULL) in initio_unlink_busy_scb()
846 host->last_busy = NULL; in initio_unlink_busy_scb()
848 prev->next = tmp->next; in initio_unlink_busy_scb()
849 if (tmp == host->last_busy) in initio_unlink_busy_scb()
850 host->last_busy = prev; in initio_unlink_busy_scb()
852 tmp->next = NULL; in initio_unlink_busy_scb()
853 if (tmp->tagmsg) in initio_unlink_busy_scb()
854 host->act_tags[tmp->target]--; in initio_unlink_busy_scb()
856 host->targets[tmp->target].flags &= ~TCF_BUSY; in initio_unlink_busy_scb()
860 tmp = tmp->next; in initio_unlink_busy_scb()
871 tmp = host->first_busy; in initio_find_busy_scb()
873 scbp_tarlun = (tmp->lun << 8) | (tmp->target); in initio_find_busy_scb()
877 tmp = tmp->next; in initio_find_busy_scb()
891 scbp->status = SCB_DONE; in initio_append_done_scb()
892 scbp->next = NULL; in initio_append_done_scb()
893 if (host->last_done != NULL) { in initio_append_done_scb()
894 host->last_done->next = scbp; in initio_append_done_scb()
895 host->last_done = scbp; in initio_append_done_scb()
897 host->first_done = scbp; in initio_append_done_scb()
898 host->last_done = scbp; in initio_append_done_scb()
906 if ((tmp = host->first_done) != NULL) { in initio_find_done_scb()
907 if ((host->first_done = tmp->next) == NULL) in initio_find_done_scb()
908 host->last_done = NULL; in initio_find_done_scb()
909 tmp->next = NULL; in initio_find_done_scb()
922 spin_lock_irqsave(&host->semaph_lock, flags); in initio_abort_srb()
924 if ((host->semaph == 0) && (host->active == NULL)) { in initio_abort_srb()
926 outb(0x1F, host->addr + TUL_Mask); in initio_abort_srb()
927 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_abort_srb()
930 spin_lock_irqsave(&host->semaph_lock, flags); in initio_abort_srb()
931 host->semaph = 1; in initio_abort_srb()
932 outb(0x0F, host->addr + TUL_Mask); in initio_abort_srb()
933 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_abort_srb()
936 prev = tmp = host->first_pending; /* Check Pend queue */ in initio_abort_srb()
939 if (tmp->srb == srbp) { in initio_abort_srb()
940 if (tmp == host->active) { in initio_abort_srb()
941 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_abort_srb()
943 } else if (tmp == host->first_pending) { in initio_abort_srb()
944 if ((host->first_pending = tmp->next) == NULL) in initio_abort_srb()
945 host->last_pending = NULL; in initio_abort_srb()
947 prev->next = tmp->next; in initio_abort_srb()
948 if (tmp == host->last_pending) in initio_abort_srb()
949 host->last_pending = prev; in initio_abort_srb()
951 tmp->hastat = HOST_ABORTED; in initio_abort_srb()
952 tmp->flags |= SCF_DONE; in initio_abort_srb()
953 if (tmp->flags & SCF_POST) in initio_abort_srb()
954 (*tmp->post) ((u8 *) host, (u8 *) tmp); in initio_abort_srb()
955 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_abort_srb()
959 tmp = tmp->next; in initio_abort_srb()
962 prev = tmp = host->first_busy; /* Check Busy queue */ in initio_abort_srb()
964 if (tmp->srb == srbp) { in initio_abort_srb()
965 if (tmp == host->active) { in initio_abort_srb()
966 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_abort_srb()
968 } else if (tmp->tagmsg == 0) { in initio_abort_srb()
969 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_abort_srb()
972 host->act_tags[tmp->target]--; in initio_abort_srb()
973 if (tmp == host->first_busy) { in initio_abort_srb()
974 if ((host->first_busy = tmp->next) == NULL) in initio_abort_srb()
975 host->last_busy = NULL; in initio_abort_srb()
977 prev->next = tmp->next; in initio_abort_srb()
978 if (tmp == host->last_busy) in initio_abort_srb()
979 host->last_busy = prev; in initio_abort_srb()
981 tmp->next = NULL; in initio_abort_srb()
984 tmp->hastat = HOST_ABORTED; in initio_abort_srb()
985 tmp->flags |= SCF_DONE; in initio_abort_srb()
986 if (tmp->flags & SCF_POST) in initio_abort_srb()
987 (*tmp->post) ((u8 *) host, (u8 *) tmp); in initio_abort_srb()
988 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_abort_srb()
993 tmp = tmp->next; in initio_abort_srb()
995 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_abort_srb()
1004 printk("initio_bad_seg c=%d\n", host->index); in initio_bad_seq()
1006 if ((scb = host->active) != NULL) { in initio_bad_seq()
1008 scb->hastat = HOST_BAD_PHAS; in initio_bad_seq()
1009 scb->tastat = 0; in initio_bad_seq()
1023 scb->mode = 0; in initio_exec_scb()
1025 scb->sgidx = 0; in initio_exec_scb()
1026 scb->sgmax = scb->sglen; in initio_exec_scb()
1028 spin_lock_irqsave(&host->semaph_lock, flags); in initio_exec_scb()
1033 if (host->semaph == 1) { in initio_exec_scb()
1035 outb(0x1F, host->addr + TUL_Mask); in initio_exec_scb()
1036 host->semaph = 0; in initio_exec_scb()
1037 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_exec_scb()
1041 spin_lock_irqsave(&host->semaph_lock, flags); in initio_exec_scb()
1042 host->semaph = 1; in initio_exec_scb()
1043 outb(0x0F, host->addr + TUL_Mask); in initio_exec_scb()
1045 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_exec_scb()
1052 if (inb(host->addr + TUL_Int) & TSS_INT_PENDING) { in initio_isr()
1053 if (host->semaph == 1) { in initio_isr()
1054 outb(0x1F, host->addr + TUL_Mask); in initio_isr()
1056 host->semaph = 0; in initio_isr()
1060 host->semaph = 1; in initio_isr()
1061 outb(0x0F, host->addr + TUL_Mask); in initio_isr()
1077 if (scb->tastat == INI_QUEUE_FULL) { in tulip_main()
1078 host->max_tags[scb->target] = in tulip_main()
1079 host->act_tags[scb->target] - 1; in tulip_main()
1080 scb->tastat = 0; in tulip_main()
1084 if (!(scb->mode & SCM_RSENS)) { /* not in auto req. sense mode */ in tulip_main()
1085 if (scb->tastat == 2) { in tulip_main()
1089 if (scb->flags & SCF_SENSE) { in tulip_main()
1091 len = scb->senselen; in tulip_main()
1094 scb->buflen = scb->senselen; in tulip_main()
1095 scb->bufptr = scb->senseptr; in tulip_main()
1096 scb->flags &= ~(SCF_SG | SCF_DIR); /* for xfer_data_in */ in tulip_main()
1099 scb->mode = SCM_RSENS; in tulip_main()
1100 scb->ident &= 0xBF; /* Disable Disconnect */ in tulip_main()
1101 scb->tagmsg = 0; in tulip_main()
1102 scb->tastat = 0; in tulip_main()
1103 scb->cdblen = 6; in tulip_main()
1104 scb->cdb[0] = SCSICMD_RequestSense; in tulip_main()
1105 scb->cdb[1] = 0; in tulip_main()
1106 scb->cdb[2] = 0; in tulip_main()
1107 scb->cdb[3] = 0; in tulip_main()
1108 scb->cdb[4] = len; in tulip_main()
1109 scb->cdb[5] = 0; in tulip_main()
1116 if (scb->tastat == 2) { /* check contition status again after sending in tulip_main()
1118 scb->hastat = HOST_BAD_PHAS; in tulip_main()
1120 scb->tastat = 2; in tulip_main()
1122 scb->flags |= SCF_DONE; in tulip_main()
1123 if (scb->flags & SCF_POST) { in tulip_main()
1125 (*scb->post) ((u8 *) host, (u8 *) scb); in tulip_main()
1129 if (inb(host->addr + TUL_SStatus0) & TSS_INT_PENDING) in tulip_main()
1131 if (host->active) /* return to OS and wait for xfer_done_ISR/Selected_ISR */ in tulip_main()
1146 if ((host->jsstatus0 = inb(host->addr + TUL_SStatus0)) & TSS_INT_PENDING) { in tulip_scsi()
1147 host->phase = host->jsstatus0 & TSS_PH_MASK; in tulip_scsi()
1148 host->jsstatus1 = inb(host->addr + TUL_SStatus1); in tulip_scsi()
1149 host->jsint = inb(host->addr + TUL_SInt); in tulip_scsi()
1150 if (host->jsint & TSS_SCSIRST_INT) { /* SCSI bus reset detected */ in tulip_scsi()
1154 if (host->jsint & TSS_RESEL_INT) { /* if selected/reselected interrupt */ in tulip_scsi()
1159 if (host->jsint & TSS_SEL_TIMEOUT) { in tulip_scsi()
1163 if (host->jsint & TSS_DISC_INT) { /* BUS disconnection */ in tulip_scsi()
1167 if (host->jsint & (TSS_FUNC_COMP | TSS_BUS_SERV)) { /* func complete or Bus service */ in tulip_scsi()
1168 if (host->active) in tulip_scsi()
1173 if (host->active != NULL) in tulip_scsi()
1180 outb((host->scsi_id << 4) | (scb->target & 0x0F), in tulip_scsi()
1181 host->addr + TUL_SScsiId); in tulip_scsi()
1182 if (scb->opcode == ExecSCSI) { in tulip_scsi()
1183 active_tc = &host->targets[scb->target]; in tulip_scsi()
1185 if (scb->tagmsg) in tulip_scsi()
1186 active_tc->drv_flags |= TCF_DRV_EN_TAG; in tulip_scsi()
1188 active_tc->drv_flags &= ~TCF_DRV_EN_TAG; in tulip_scsi()
1190 outb(active_tc->js_period, host->addr + TUL_SPeriod); in tulip_scsi()
1191 if ((active_tc->flags & (TCF_WDTR_DONE | TCF_NO_WDTR)) == 0) { /* do wdtr negotiation */ in tulip_scsi()
1194 …if ((active_tc->flags & (TCF_SYNC_DONE | TCF_NO_SYNC_NEGO)) == 0) { /* do sync negotiation … in tulip_scsi()
1197 if (scb->tagmsg) in tulip_scsi()
1203 if (scb->flags & SCF_POLL) { in tulip_scsi()
1204 while (wait_tulip(host) != -1) { in tulip_scsi()
1205 if (initio_next_state(host) == -1) in tulip_scsi()
1209 } else if (scb->opcode == BusDevRst) { in tulip_scsi()
1211 scb->next_state = 8; in tulip_scsi()
1212 if (scb->flags & SCF_POLL) { in tulip_scsi()
1213 while (wait_tulip(host) != -1) { in tulip_scsi()
1214 if (initio_next_state(host) == -1) in tulip_scsi()
1218 } else if (scb->opcode == AbortCmd) { in tulip_scsi()
1219 if (initio_abort_srb(host, scb->srb) != 0) { in tulip_scsi()
1223 scb->opcode = BusDevRst; in tulip_scsi()
1225 scb->next_state = 8; in tulip_scsi()
1229 scb->hastat = 0x16; /* bad command */ in tulip_scsi()
1236 * initio_next_state - Next SCSI state
1249 next = host->active->next_state; in initio_next_state()
1285 * initio_state_1 - SCSI state machine
1293 struct scsi_ctrl_blk *scb = host->active; in initio_state_1()
1294 struct target_control *active_tc = host->active_tc; in initio_state_1()
1296 printk("-s1-"); in initio_state_1()
1303 outb(active_tc->sconfig0, host->addr + TUL_SConfig ); in initio_state_1()
1305 if (host->phase == MSG_OUT) { in initio_state_1()
1306 outb(TSC_EN_BUS_IN | TSC_HW_RESELECT, host->addr + TUL_SCtrl1); in initio_state_1()
1307 outb(scb->ident, host->addr + TUL_SFifo); in initio_state_1()
1309 if (scb->tagmsg) { in initio_state_1()
1310 outb(scb->tagmsg, host->addr + TUL_SFifo); in initio_state_1()
1311 outb(scb->tagid, host->addr + TUL_SFifo); in initio_state_1()
1313 if ((active_tc->flags & (TCF_WDTR_DONE | TCF_NO_WDTR)) == 0) { in initio_state_1()
1314 active_tc->flags |= TCF_WDTR_DONE; in initio_state_1()
1315 outb(EXTENDED_MESSAGE, host->addr + TUL_SFifo); in initio_state_1()
1316 outb(2, host->addr + TUL_SFifo); /* Extended msg length */ in initio_state_1()
1317 outb(EXTENDED_SDTR, host->addr + TUL_SFifo); /* Sync request */ in initio_state_1()
1318 outb(1, host->addr + TUL_SFifo); /* Start from 16 bits */ in initio_state_1()
1319 } else if ((active_tc->flags & (TCF_SYNC_DONE | TCF_NO_SYNC_NEGO)) == 0) { in initio_state_1()
1320 active_tc->flags |= TCF_SYNC_DONE; in initio_state_1()
1321 outb(EXTENDED_MESSAGE, host->addr + TUL_SFifo); in initio_state_1()
1322 outb(3, host->addr + TUL_SFifo); /* extended msg length */ in initio_state_1()
1323 outb(EXTENDED_SDTR, host->addr + TUL_SFifo); /* sync request */ in initio_state_1()
1324 outb(initio_rate_tbl[active_tc->flags & TCF_SCSI_RATE], host->addr + TUL_SFifo); in initio_state_1()
1325 outb(MAX_OFFSET, host->addr + TUL_SFifo); /* REQ/ACK offset */ in initio_state_1()
1327 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_state_1()
1328 if (wait_tulip(host) == -1) in initio_state_1()
1329 return -1; in initio_state_1()
1331 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_state_1()
1332 outb((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)), host->addr + TUL_SSignal); in initio_state_1()
1339 * initio_state_2 - SCSI state machine
1348 struct scsi_ctrl_blk *scb = host->active; in initio_state_2()
1349 struct target_control *active_tc = host->active_tc; in initio_state_2()
1351 printk("-s2-"); in initio_state_2()
1357 outb(active_tc->sconfig0, host->addr + TUL_SConfig); in initio_state_2()
1359 if (host->jsstatus1 & TSS_CMD_PH_CMP) in initio_state_2()
1362 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_state_2()
1363 outb((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)), host->addr + TUL_SSignal); in initio_state_2()
1369 * initio_state_3 - SCSI state machine
1377 struct scsi_ctrl_blk *scb = host->active; in initio_state_3()
1378 struct target_control *active_tc = host->active_tc; in initio_state_3()
1382 printk("-s3-"); in initio_state_3()
1385 switch (host->phase) { in initio_state_3()
1386 case CMD_OUT: /* Command out phase */ in initio_state_3()
1387 for (i = 0; i < (int) scb->cdblen; i++) in initio_state_3()
1388 outb(scb->cdb[i], host->addr + TUL_SFifo); in initio_state_3()
1389 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_state_3()
1390 if (wait_tulip(host) == -1) in initio_state_3()
1391 return -1; in initio_state_3()
1392 if (host->phase == CMD_OUT) in initio_state_3()
1396 case MSG_IN: /* Message in phase */ in initio_state_3()
1397 scb->next_state = 3; in initio_state_3()
1398 if (initio_msgin(host) == -1) in initio_state_3()
1399 return -1; in initio_state_3()
1402 case STATUS_IN: /* Status phase */ in initio_state_3()
1403 if (initio_status_msg(host) == -1) in initio_state_3()
1404 return -1; in initio_state_3()
1407 case MSG_OUT: /* Message out phase */ in initio_state_3()
1408 if (active_tc->flags & (TCF_SYNC_DONE | TCF_NO_SYNC_NEGO)) { in initio_state_3()
1409 outb(NOP, host->addr + TUL_SFifo); /* msg nop */ in initio_state_3()
1410 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_state_3()
1411 if (wait_tulip(host) == -1) in initio_state_3()
1412 return -1; in initio_state_3()
1414 active_tc->flags |= TCF_SYNC_DONE; in initio_state_3()
1416 outb(EXTENDED_MESSAGE, host->addr + TUL_SFifo); in initio_state_3()
1417 outb(3, host->addr + TUL_SFifo); /* ext. msg len */ in initio_state_3()
1418 outb(EXTENDED_SDTR, host->addr + TUL_SFifo); /* sync request */ in initio_state_3()
1419 outb(initio_rate_tbl[active_tc->flags & TCF_SCSI_RATE], host->addr + TUL_SFifo); in initio_state_3()
1420 outb(MAX_OFFSET, host->addr + TUL_SFifo); /* REQ/ACK offset */ in initio_state_3()
1421 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_state_3()
1422 if (wait_tulip(host) == -1) in initio_state_3()
1423 return -1; in initio_state_3()
1424 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_state_3()
1425 outb(inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7), host->addr + TUL_SSignal); in initio_state_3()
1436 * initio_state_4 - SCSI state machine
1444 struct scsi_ctrl_blk *scb = host->active; in initio_state_4()
1447 printk("-s4-"); in initio_state_4()
1449 if ((scb->flags & SCF_DIR) == SCF_NO_XF) { in initio_state_4()
1453 if (scb->buflen == 0) in initio_state_4()
1456 switch (host->phase) { in initio_state_4()
1458 case STATUS_IN: /* Status phase */ in initio_state_4()
1459 if ((scb->flags & SCF_DIR) != 0) /* if direction bit set then report data underrun */ in initio_state_4()
1460 scb->hastat = HOST_DO_DU; in initio_state_4()
1461 if ((initio_status_msg(host)) == -1) in initio_state_4()
1462 return -1; in initio_state_4()
1465 case MSG_IN: /* Message in phase */ in initio_state_4()
1466 scb->next_state = 0x4; in initio_state_4()
1467 if (initio_msgin(host) == -1) in initio_state_4()
1468 return -1; in initio_state_4()
1471 case MSG_OUT: /* Message out phase */ in initio_state_4()
1472 if (host->jsstatus0 & TSS_PAR_ERROR) { in initio_state_4()
1473 scb->buflen = 0; in initio_state_4()
1474 scb->hastat = HOST_DO_DU; in initio_state_4()
1475 if (initio_msgout_ide(host) == -1) in initio_state_4()
1476 return -1; in initio_state_4()
1479 outb(NOP, host->addr + TUL_SFifo); /* msg nop */ in initio_state_4()
1480 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_state_4()
1481 if (wait_tulip(host) == -1) in initio_state_4()
1482 return -1; in initio_state_4()
1486 case DATA_IN: /* Data in phase */ in initio_state_4()
1489 case DATA_OUT: /* Data out phase */ in initio_state_4()
1500 * initio_state_5 - SCSI state machine
1503 * State after dma xfer done or phase change before xfer done
1508 struct scsi_ctrl_blk *scb = host->active; in initio_state_5()
1512 printk("-s5-"); in initio_state_5()
1514 /*------ get remaining count -------*/ in initio_state_5()
1515 cnt = inl(host->addr + TUL_SCnt0) & 0x0FFFFFF; in initio_state_5()
1517 if (inb(host->addr + TUL_XCmd) & 0x20) { in initio_state_5()
1518 /* ----------------------- DATA_IN ----------------------------- */ in initio_state_5()
1520 if (host->jsstatus0 & TSS_PAR_ERROR) in initio_state_5()
1521 scb->hastat = HOST_DO_DU; in initio_state_5()
1522 if (inb(host->addr + TUL_XStatus) & XPEND) { /* DMA xfer pending, Send STOP */ in initio_state_5()
1524 outb(inb(host->addr + TUL_XCtrl) | 0x80, host->addr + TUL_XCtrl); in initio_state_5()
1526 while (inb(host->addr + TUL_XStatus) & XPEND) in initio_state_5()
1530 /*-------- DATA OUT -----------*/ in initio_state_5()
1531 if ((inb(host->addr + TUL_SStatus1) & TSS_XFER_CMP) == 0) { in initio_state_5()
1532 if (host->active_tc->js_period & TSC_WIDE_SCSI) in initio_state_5()
1533 cnt += (inb(host->addr + TUL_SFifoCnt) & 0x1F) << 1; in initio_state_5()
1535 cnt += (inb(host->addr + TUL_SFifoCnt) & 0x1F); in initio_state_5()
1537 if (inb(host->addr + TUL_XStatus) & XPEND) { /* if DMA xfer is pending, abort DMA xfer */ in initio_state_5()
1538 outb(TAX_X_ABT, host->addr + TUL_XCmd); in initio_state_5()
1540 while ((inb(host->addr + TUL_Int) & XABT) == 0) in initio_state_5()
1543 if ((cnt == 1) && (host->phase == DATA_OUT)) { in initio_state_5()
1544 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_state_5()
1545 if (wait_tulip(host) == -1) in initio_state_5()
1546 return -1; in initio_state_5()
1549 if ((inb(host->addr + TUL_SStatus1) & TSS_XFER_CMP) == 0) in initio_state_5()
1550 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_state_5()
1554 scb->buflen = 0; in initio_state_5()
1558 xcnt = (long) scb->buflen - cnt; /* xcnt== bytes already xferred */ in initio_state_5()
1559 scb->buflen = (u32) cnt; /* cnt == bytes left to be xferred */ in initio_state_5()
1560 if (scb->flags & SCF_SG) { in initio_state_5()
1564 sgp = &scb->sglist[scb->sgidx]; in initio_state_5()
1565 for (i = scb->sgidx; i < scb->sgmax; sgp++, i++) { in initio_state_5()
1566 xcnt -= (long) sgp->len; in initio_state_5()
1568 xcnt += (long) sgp->len; /* xcnt == bytes xferred in this sgp */ in initio_state_5()
1569 sgp->data += (u32) xcnt; /* new ptr to be xfer */ in initio_state_5()
1570 sgp->len -= (u32) xcnt; /* new len to be xfer */ in initio_state_5()
1571 scb->bufptr += ((u32) (i - scb->sgidx) << 3); in initio_state_5()
1573 scb->sglen = (u8) (scb->sgmax - i); in initio_state_5()
1575 scb->sgidx = (u16) i; in initio_state_5()
1583 scb->bufptr += (u32) xcnt; in initio_state_5()
1589 * initio_state_6 - SCSI state machine
1592 * State after Data phase
1597 struct scsi_ctrl_blk *scb = host->active; in initio_state_6()
1600 printk("-s6-"); in initio_state_6()
1603 switch (host->phase) { in initio_state_6()
1604 case STATUS_IN: /* Status phase */ in initio_state_6()
1605 if ((initio_status_msg(host)) == -1) in initio_state_6()
1606 return -1; in initio_state_6()
1609 case MSG_IN: /* Message in phase */ in initio_state_6()
1610 scb->next_state = 6; in initio_state_6()
1611 if ((initio_msgin(host)) == -1) in initio_state_6()
1612 return -1; in initio_state_6()
1615 case MSG_OUT: /* Message out phase */ in initio_state_6()
1616 outb(NOP, host->addr + TUL_SFifo); /* msg nop */ in initio_state_6()
1617 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_state_6()
1618 if (wait_tulip(host) == -1) in initio_state_6()
1619 return -1; in initio_state_6()
1622 case DATA_IN: /* Data in phase */ in initio_state_6()
1625 case DATA_OUT: /* Data out phase */ in initio_state_6()
1635 * initio_state_7 - SCSI state machine
1645 printk("-s7-"); in initio_state_7()
1648 cnt = inb(host->addr + TUL_SFifoCnt) & 0x1F; in initio_state_7()
1651 inb(host->addr + TUL_SFifo); in initio_state_7()
1653 switch (host->phase) { in initio_state_7()
1654 case DATA_IN: /* Data in phase */ in initio_state_7()
1655 case DATA_OUT: /* Data out phase */ in initio_state_7()
1663 * initio_xfer_data_in - Commence data input
1672 struct scsi_ctrl_blk *scb = host->active; in initio_xfer_data_in()
1674 if ((scb->flags & SCF_DIR) == SCF_DOUT) in initio_xfer_data_in()
1677 outl(scb->buflen, host->addr + TUL_SCnt0); in initio_xfer_data_in()
1678 outb(TSC_XF_DMA_IN, host->addr + TUL_SCmd); /* 7/25/95 */ in initio_xfer_data_in()
1680 if (scb->flags & SCF_SG) { /* S/G xfer */ in initio_xfer_data_in()
1681 outl(((u32) scb->sglen) << 3, host->addr + TUL_XCntH); in initio_xfer_data_in()
1682 outl(scb->bufptr, host->addr + TUL_XAddH); in initio_xfer_data_in()
1683 outb(TAX_SG_IN, host->addr + TUL_XCmd); in initio_xfer_data_in()
1685 outl(scb->buflen, host->addr + TUL_XCntH); in initio_xfer_data_in()
1686 outl(scb->bufptr, host->addr + TUL_XAddH); in initio_xfer_data_in()
1687 outb(TAX_X_IN, host->addr + TUL_XCmd); in initio_xfer_data_in()
1689 scb->next_state = 0x5; in initio_xfer_data_in()
1694 * initio_xfer_data_out - Commence data output
1704 struct scsi_ctrl_blk *scb = host->active; in initio_xfer_data_out()
1706 if ((scb->flags & SCF_DIR) == SCF_DIN) in initio_xfer_data_out()
1709 outl(scb->buflen, host->addr + TUL_SCnt0); in initio_xfer_data_out()
1710 outb(TSC_XF_DMA_OUT, host->addr + TUL_SCmd); in initio_xfer_data_out()
1712 if (scb->flags & SCF_SG) { /* S/G xfer */ in initio_xfer_data_out()
1713 outl(((u32) scb->sglen) << 3, host->addr + TUL_XCntH); in initio_xfer_data_out()
1714 outl(scb->bufptr, host->addr + TUL_XAddH); in initio_xfer_data_out()
1715 outb(TAX_SG_OUT, host->addr + TUL_XCmd); in initio_xfer_data_out()
1717 outl(scb->buflen, host->addr + TUL_XCntH); in initio_xfer_data_out()
1718 outl(scb->bufptr, host->addr + TUL_XAddH); in initio_xfer_data_out()
1719 outb(TAX_X_OUT, host->addr + TUL_XCmd); in initio_xfer_data_out()
1722 scb->next_state = 0x5; in initio_xfer_data_out()
1728 struct scsi_ctrl_blk *scb = host->active; in initio_xpad_in()
1729 struct target_control *active_tc = host->active_tc; in initio_xpad_in()
1731 if ((scb->flags & SCF_DIR) != SCF_NO_DCHK) in initio_xpad_in()
1732 scb->hastat = HOST_DO_DU; /* over run */ in initio_xpad_in()
1734 if (active_tc->js_period & TSC_WIDE_SCSI) in initio_xpad_in()
1735 outl(2, host->addr + TUL_SCnt0); in initio_xpad_in()
1737 outl(1, host->addr + TUL_SCnt0); in initio_xpad_in()
1739 outb(TSC_XF_FIFO_IN, host->addr + TUL_SCmd); in initio_xpad_in()
1740 if (wait_tulip(host) == -1) in initio_xpad_in()
1741 return -1; in initio_xpad_in()
1742 if (host->phase != DATA_IN) { in initio_xpad_in()
1743 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_xpad_in()
1746 inb(host->addr + TUL_SFifo); in initio_xpad_in()
1752 struct scsi_ctrl_blk *scb = host->active; in initio_xpad_out()
1753 struct target_control *active_tc = host->active_tc; in initio_xpad_out()
1755 if ((scb->flags & SCF_DIR) != SCF_NO_DCHK) in initio_xpad_out()
1756 scb->hastat = HOST_DO_DU; /* over run */ in initio_xpad_out()
1758 if (active_tc->js_period & TSC_WIDE_SCSI) in initio_xpad_out()
1759 outl(2, host->addr + TUL_SCnt0); in initio_xpad_out()
1761 outl(1, host->addr + TUL_SCnt0); in initio_xpad_out()
1763 outb(0, host->addr + TUL_SFifo); in initio_xpad_out()
1764 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_xpad_out()
1765 if ((wait_tulip(host)) == -1) in initio_xpad_out()
1766 return -1; in initio_xpad_out()
1767 if (host->phase != DATA_OUT) { /* Disable wide CPU to allow read 16 bits */ in initio_xpad_out()
1768 outb(TSC_HW_RESELECT, host->addr + TUL_SCtrl1); in initio_xpad_out()
1769 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_xpad_out()
1777 struct scsi_ctrl_blk *scb = host->active; in initio_status_msg()
1780 outb(TSC_CMD_COMP, host->addr + TUL_SCmd); in initio_status_msg()
1781 if (wait_tulip(host) == -1) in initio_status_msg()
1782 return -1; in initio_status_msg()
1785 scb->tastat = inb(host->addr + TUL_SFifo); in initio_status_msg()
1787 if (host->phase == MSG_OUT) { in initio_status_msg()
1788 if (host->jsstatus0 & TSS_PAR_ERROR) in initio_status_msg()
1789 outb(MSG_PARITY_ERROR, host->addr + TUL_SFifo); in initio_status_msg()
1791 outb(NOP, host->addr + TUL_SFifo); in initio_status_msg()
1792 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_status_msg()
1795 if (host->phase == MSG_IN) { in initio_status_msg()
1796 msg = inb(host->addr + TUL_SFifo); in initio_status_msg()
1797 if (host->jsstatus0 & TSS_PAR_ERROR) { /* Parity error */ in initio_status_msg()
1798 if ((initio_msgin_accept(host)) == -1) in initio_status_msg()
1799 return -1; in initio_status_msg()
1800 if (host->phase != MSG_OUT) in initio_status_msg()
1802 outb(MSG_PARITY_ERROR, host->addr + TUL_SFifo); in initio_status_msg()
1803 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_status_msg()
1808 if ((scb->tastat & 0x18) == 0x10) /* No link support */ in initio_status_msg()
1810 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_status_msg()
1811 outb(TSC_MSG_ACCEPT, host->addr + TUL_SCmd); in initio_status_msg()
1817 if ((scb->tastat & 0x18) == 0x10) in initio_status_msg()
1828 struct scsi_ctrl_blk *scb = host->active; in int_initio_busfree()
1831 if (scb->status & SCB_SELECT) { /* selection timeout */ in int_initio_busfree()
1833 scb->hastat = HOST_SEL_TOUT; in int_initio_busfree()
1837 scb->hastat = HOST_BUS_FREE; in int_initio_busfree()
1840 host->active = NULL; in int_initio_busfree()
1841 host->active_tc = NULL; in int_initio_busfree()
1843 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); /* Flush SCSI FIFO */ in int_initio_busfree()
1844 outb(TSC_INITDEFAULT, host->addr + TUL_SConfig); in int_initio_busfree()
1845 outb(TSC_HW_RESELECT, host->addr + TUL_SCtrl1); /* Enable HW reselect */ in int_initio_busfree()
1846 return -1; in int_initio_busfree()
1851 * int_initio_scsi_rst - SCSI reset occurred
1866 if (inb(host->addr + TUL_XStatus) & 0x01) { in int_initio_scsi_rst()
1867 outb(TAX_X_ABT | TAX_X_CLR_FIFO, host->addr + TUL_XCmd); in int_initio_scsi_rst()
1869 while ((inb(host->addr + TUL_Int) & 0x04) == 0) in int_initio_scsi_rst()
1871 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in int_initio_scsi_rst()
1875 scb->hastat = HOST_BAD_PHAS; in int_initio_scsi_rst()
1878 host->active = NULL; in int_initio_scsi_rst()
1879 host->active_tc = NULL; in int_initio_scsi_rst()
1882 for (i = 0; i < host->max_tar; i++) in int_initio_scsi_rst()
1883 host->targets[i].flags &= ~(TCF_SYNC_DONE | TCF_WDTR_DONE); in int_initio_scsi_rst()
1884 return -1; in int_initio_scsi_rst()
1888 * int_initio_resel - Reselection occurred
1903 if ((scb = host->active) != NULL) { in int_initio_resel()
1905 if (scb->status & SCB_SELECT) /* if waiting for selection complete */ in int_initio_resel()
1906 scb->status &= ~SCB_SELECT; in int_initio_resel()
1907 host->active = NULL; in int_initio_resel()
1909 /* --------- get target id---------------------- */ in int_initio_resel()
1910 tar = inb(host->addr + TUL_SBusId); in int_initio_resel()
1911 /* ------ get LUN from Identify message----------- */ in int_initio_resel()
1912 lun = inb(host->addr + TUL_SIdent) & 0x0F; in int_initio_resel()
1913 /* 07/22/98 from 0x1F -> 0x0F */ in int_initio_resel()
1914 active_tc = &host->targets[tar]; in int_initio_resel()
1915 host->active_tc = active_tc; in int_initio_resel()
1916 outb(active_tc->sconfig0, host->addr + TUL_SConfig); in int_initio_resel()
1917 outb(active_tc->js_period, host->addr + TUL_SPeriod); in int_initio_resel()
1919 /* ------------- tag queueing ? ------------------- */ in int_initio_resel()
1920 if (active_tc->drv_flags & TCF_DRV_EN_TAG) { in int_initio_resel()
1921 if ((initio_msgin_accept(host)) == -1) in int_initio_resel()
1922 return -1; in int_initio_resel()
1923 if (host->phase != MSG_IN) in int_initio_resel()
1925 outl(1, host->addr + TUL_SCnt0); in int_initio_resel()
1926 outb(TSC_XF_FIFO_IN, host->addr + TUL_SCmd); in int_initio_resel()
1927 if (wait_tulip(host) == -1) in int_initio_resel()
1928 return -1; in int_initio_resel()
1929 msg = inb(host->addr + TUL_SFifo); /* Read Tag Message */ in int_initio_resel()
1935 if (initio_msgin_accept(host) == -1) in int_initio_resel()
1936 return -1; in int_initio_resel()
1938 if (host->phase != MSG_IN) in int_initio_resel()
1941 outl(1, host->addr + TUL_SCnt0); in int_initio_resel()
1942 outb(TSC_XF_FIFO_IN, host->addr + TUL_SCmd); in int_initio_resel()
1943 if (wait_tulip(host) == -1) in int_initio_resel()
1944 return -1; in int_initio_resel()
1945 tag = inb(host->addr + TUL_SFifo); /* Read Tag ID */ in int_initio_resel()
1946 scb = host->scb + tag; in int_initio_resel()
1947 if (scb->target != tar || scb->lun != lun) { in int_initio_resel()
1950 if (scb->status != SCB_BUSY) { /* 03/24/95 */ in int_initio_resel()
1953 host->active = scb; in int_initio_resel()
1954 if ((initio_msgin_accept(host)) == -1) in int_initio_resel()
1955 return -1; in int_initio_resel()
1961 host->active = scb; in int_initio_resel()
1962 if (!(active_tc->drv_flags & TCF_DRV_EN_TAG)) { in int_initio_resel()
1963 if ((initio_msgin_accept(host)) == -1) in int_initio_resel()
1964 return -1; in int_initio_resel()
1971 * int_initio_bad_seq - out of phase
1974 * We have ended up out of phase somehow. Reset the host controller
1979 { /* target wrong phase */ in int_initio_bad_seq()
1986 scb->hastat = HOST_BAD_PHAS; in int_initio_bad_seq()
1989 for (i = 0; i < host->max_tar; i++) in int_initio_bad_seq()
1990 host->targets[i].flags &= ~(TCF_SYNC_DONE | TCF_WDTR_DONE); in int_initio_bad_seq()
1991 return -1; in int_initio_bad_seq()
1996 * initio_msgout_abort_targ - abort a tag
2006 …outb(((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)) | TSC_SET_ATN), host->addr + TUL_SSignal… in initio_msgout_abort_targ()
2007 if (initio_msgin_accept(host) == -1) in initio_msgout_abort_targ()
2008 return -1; in initio_msgout_abort_targ()
2009 if (host->phase != MSG_OUT) in initio_msgout_abort_targ()
2012 outb(ABORT_TASK_SET, host->addr + TUL_SFifo); in initio_msgout_abort_targ()
2013 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_msgout_abort_targ()
2019 * initio_msgout_abort_tag - abort a tag
2029 …outb(((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)) | TSC_SET_ATN), host->addr + TUL_SSignal… in initio_msgout_abort_tag()
2030 if (initio_msgin_accept(host) == -1) in initio_msgout_abort_tag()
2031 return -1; in initio_msgout_abort_tag()
2032 if (host->phase != MSG_OUT) in initio_msgout_abort_tag()
2035 outb(ABORT_TASK, host->addr + TUL_SFifo); in initio_msgout_abort_tag()
2036 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_msgout_abort_tag()
2043 * initio_msgin - Message in
2053 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_msgin()
2055 outl(1, host->addr + TUL_SCnt0); in initio_msgin()
2056 outb(TSC_XF_FIFO_IN, host->addr + TUL_SCmd); in initio_msgin()
2057 if (wait_tulip(host) == -1) in initio_msgin()
2058 return -1; in initio_msgin()
2060 switch (inb(host->addr + TUL_SFifo)) { in initio_msgin()
2062 outb(TSC_MSG_ACCEPT, host->addr + TUL_SCmd); in initio_msgin()
2070 outb((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)), in initio_msgin()
2071 host->addr + TUL_SSignal); in initio_msgin()
2072 active_tc = host->active_tc; in initio_msgin()
2073 if ((active_tc->flags & (TCF_SYNC_DONE | TCF_NO_SYNC_NEGO)) == 0) /* do sync nego */ in initio_msgin()
2074 outb(((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)) | TSC_SET_ATN), in initio_msgin()
2075 host->addr + TUL_SSignal); in initio_msgin()
2085 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_msgin()
2086 outb(TSC_MSG_ACCEPT, host->addr + TUL_SCmd); in initio_msgin()
2092 if (host->phase != MSG_IN) in initio_msgin()
2093 return host->phase; in initio_msgin()
2100 …outb(((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)) | TSC_SET_ATN), host->addr + TUL_SSignal… in initio_msgout_reject()
2102 if (initio_msgin_accept(host) == -1) in initio_msgout_reject()
2103 return -1; in initio_msgout_reject()
2105 if (host->phase == MSG_OUT) { in initio_msgout_reject()
2106 outb(MESSAGE_REJECT, host->addr + TUL_SFifo); /* Msg reject */ in initio_msgout_reject()
2107 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_msgout_reject()
2110 return host->phase; in initio_msgout_reject()
2115 outb(INITIATOR_ERROR, host->addr + TUL_SFifo); /* Initiator Detected Error */ in initio_msgout_ide()
2116 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_msgout_ide()
2125 return host->phase; in initio_msgin_extend()
2128 outl(1, host->addr + TUL_SCnt0); in initio_msgin_extend()
2129 outb(TSC_XF_FIFO_IN, host->addr + TUL_SCmd); in initio_msgin_extend()
2130 if (wait_tulip(host) == -1) in initio_msgin_extend()
2131 return -1; in initio_msgin_extend()
2133 len = inb(host->addr + TUL_SFifo); in initio_msgin_extend()
2134 host->msg[0] = len; in initio_msgin_extend()
2135 for (idx = 1; len != 0; len--) { in initio_msgin_extend()
2138 return host->phase; in initio_msgin_extend()
2139 outl(1, host->addr + TUL_SCnt0); in initio_msgin_extend()
2140 outb(TSC_XF_FIFO_IN, host->addr + TUL_SCmd); in initio_msgin_extend()
2141 if (wait_tulip(host) == -1) in initio_msgin_extend()
2142 return -1; in initio_msgin_extend()
2143 host->msg[idx++] = inb(host->addr + TUL_SFifo); in initio_msgin_extend()
2145 if (host->msg[1] == 1) { /* if it's synchronous data transfer request */ in initio_msgin_extend()
2147 if (host->msg[0] != 3) /* if length is not right */ in initio_msgin_extend()
2149 if (host->active_tc->flags & TCF_NO_SYNC_NEGO) { /* Set OFFSET=0 to do async, nego back */ in initio_msgin_extend()
2150 host->msg[3] = 0; in initio_msgin_extend()
2153 (host->active_tc->flags & TCF_SYNC_DONE)) { in initio_msgin_extend()
2159 r = inb(host->addr + TUL_SSignal); in initio_msgin_extend()
2161 host->addr + TUL_SSignal); in initio_msgin_extend()
2163 return host->phase; in initio_msgin_extend()
2165 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_msgin_extend()
2169 outb(EXTENDED_MESSAGE, host->addr + TUL_SFifo); in initio_msgin_extend()
2170 outb(3, host->addr + TUL_SFifo); in initio_msgin_extend()
2171 outb(EXTENDED_SDTR, host->addr + TUL_SFifo); in initio_msgin_extend()
2172 outb(host->msg[2], host->addr + TUL_SFifo); in initio_msgin_extend()
2173 outb(host->msg[3], host->addr + TUL_SFifo); in initio_msgin_extend()
2174 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_msgin_extend()
2177 if (host->msg[0] != 2 || host->msg[1] != 3) in initio_msgin_extend()
2180 if (host->active_tc->flags & TCF_NO_WDTR) { in initio_msgin_extend()
2181 host->msg[2] = 0; in initio_msgin_extend()
2183 if (host->msg[2] > 2) /* > 32 bits */ in initio_msgin_extend()
2185 if (host->msg[2] == 2) { /* == 32 */ in initio_msgin_extend()
2186 host->msg[2] = 1; in initio_msgin_extend()
2188 if ((host->active_tc->flags & TCF_NO_WDTR) == 0) { in initio_msgin_extend()
2190 if ((host->active_tc->flags & (TCF_SYNC_DONE | TCF_NO_SYNC_NEGO)) == 0) in initio_msgin_extend()
2191 …outb(((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)) | TSC_SET_ATN), host->addr + TUL_SSignal… in initio_msgin_extend()
2196 …outb(((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)) | TSC_SET_ATN), host->addr + TUL_SSignal… in initio_msgin_extend()
2199 return host->phase; in initio_msgin_extend()
2201 outb(EXTENDED_MESSAGE, host->addr + TUL_SFifo); in initio_msgin_extend()
2202 outb(2, host->addr + TUL_SFifo); in initio_msgin_extend()
2203 outb(EXTENDED_WDTR, host->addr + TUL_SFifo); in initio_msgin_extend()
2204 outb(host->msg[2], host->addr + TUL_SFifo); in initio_msgin_extend()
2205 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_msgin_extend()
2213 default_period = initio_rate_tbl[host->active_tc->flags & TCF_SCSI_RATE]; in initio_msgin_sync()
2214 if (host->msg[3] > MAX_OFFSET) { in initio_msgin_sync()
2215 host->msg[3] = MAX_OFFSET; in initio_msgin_sync()
2216 if (host->msg[2] < default_period) { in initio_msgin_sync()
2217 host->msg[2] = default_period; in initio_msgin_sync()
2220 if (host->msg[2] >= 59) /* Change to async */ in initio_msgin_sync()
2221 host->msg[3] = 0; in initio_msgin_sync()
2225 if (host->msg[3] == 0) { in initio_msgin_sync()
2228 if (host->msg[2] < default_period) { in initio_msgin_sync()
2229 host->msg[2] = default_period; in initio_msgin_sync()
2232 if (host->msg[2] >= 59) { in initio_msgin_sync()
2233 host->msg[3] = 0; in initio_msgin_sync()
2241 host->active_tc->flags &= ~TCF_SYNC_DONE; in wdtr_done()
2242 host->active_tc->flags |= TCF_WDTR_DONE; in wdtr_done()
2244 host->active_tc->js_period = 0; in wdtr_done()
2245 if (host->msg[2]) /* if 16 bit */ in wdtr_done()
2246 host->active_tc->js_period |= TSC_WIDE_SCSI; in wdtr_done()
2247 host->active_tc->sconfig0 &= ~TSC_ALT_PERIOD; in wdtr_done()
2248 outb(host->active_tc->sconfig0, host->addr + TUL_SConfig); in wdtr_done()
2249 outb(host->active_tc->js_period, host->addr + TUL_SPeriod); in wdtr_done()
2258 host->active_tc->flags |= TCF_SYNC_DONE; in initio_sync_done()
2260 if (host->msg[3]) { in initio_sync_done()
2261 host->active_tc->js_period |= host->msg[3]; in initio_sync_done()
2263 if (initio_rate_tbl[i] >= host->msg[2]) /* pick the big one */ in initio_sync_done()
2266 host->active_tc->js_period |= (i << 4); in initio_sync_done()
2267 host->active_tc->sconfig0 |= TSC_ALT_PERIOD; in initio_sync_done()
2269 outb(host->active_tc->sconfig0, host->addr + TUL_SConfig); in initio_sync_done()
2270 outb(host->active_tc->js_period, host->addr + TUL_SPeriod); in initio_sync_done()
2272 return -1; in initio_sync_done()
2282 host->active = NULL; in initio_post_scsi_rst()
2283 host->active_tc = NULL; in initio_post_scsi_rst()
2284 host->flags = 0; in initio_post_scsi_rst()
2287 scb->hastat = HOST_BAD_PHAS; in initio_post_scsi_rst()
2291 active_tc = &host->targets[0]; in initio_post_scsi_rst()
2292 for (i = 0; i < host->max_tar; active_tc++, i++) { in initio_post_scsi_rst()
2293 active_tc->flags &= ~(TCF_SYNC_DONE | TCF_WDTR_DONE); in initio_post_scsi_rst()
2295 active_tc->js_period = 0; in initio_post_scsi_rst()
2296 active_tc->sconfig0 = host->sconf1; in initio_post_scsi_rst()
2297 host->act_tags[0] = 0; /* 07/22/98 */ in initio_post_scsi_rst()
2298 host->targets[i].flags &= ~TCF_BUSY; /* 07/22/98 */ in initio_post_scsi_rst()
2301 return -1; in initio_post_scsi_rst()
2306 scb->status |= SCB_SELECT; in initio_select_atn_stop()
2307 scb->next_state = 0x1; in initio_select_atn_stop()
2308 host->active = scb; in initio_select_atn_stop()
2309 host->active_tc = &host->targets[scb->target]; in initio_select_atn_stop()
2310 outb(TSC_SELATNSTOP, host->addr + TUL_SCmd); in initio_select_atn_stop()
2318 scb->status |= SCB_SELECT; in initio_select_atn()
2319 scb->next_state = 0x2; in initio_select_atn()
2321 outb(scb->ident, host->addr + TUL_SFifo); in initio_select_atn()
2322 for (i = 0; i < (int) scb->cdblen; i++) in initio_select_atn()
2323 outb(scb->cdb[i], host->addr + TUL_SFifo); in initio_select_atn()
2324 host->active_tc = &host->targets[scb->target]; in initio_select_atn()
2325 host->active = scb; in initio_select_atn()
2326 outb(TSC_SEL_ATN, host->addr + TUL_SCmd); in initio_select_atn()
2333 scb->status |= SCB_SELECT; in initio_select_atn3()
2334 scb->next_state = 0x2; in initio_select_atn3()
2336 outb(scb->ident, host->addr + TUL_SFifo); in initio_select_atn3()
2337 outb(scb->tagmsg, host->addr + TUL_SFifo); in initio_select_atn3()
2338 outb(scb->tagid, host->addr + TUL_SFifo); in initio_select_atn3()
2339 for (i = 0; i < scb->cdblen; i++) in initio_select_atn3()
2340 outb(scb->cdb[i], host->addr + TUL_SFifo); in initio_select_atn3()
2341 host->active_tc = &host->targets[scb->target]; in initio_select_atn3()
2342 host->active = scb; in initio_select_atn3()
2343 outb(TSC_SEL_ATN3, host->addr + TUL_SCmd); in initio_select_atn3()
2347 * initio_bus_device_reset - SCSI Bus Device Reset
2355 struct scsi_ctrl_blk *scb = host->active; in initio_bus_device_reset()
2356 struct target_control *active_tc = host->active_tc; in initio_bus_device_reset()
2360 if (host->phase != MSG_OUT) in initio_bus_device_reset()
2361 return int_initio_bad_seq(host); /* Unexpected phase */ in initio_bus_device_reset()
2367 tar = scb->target; /* target */ in initio_bus_device_reset()
2368 active_tc->flags &= ~(TCF_SYNC_DONE | TCF_WDTR_DONE | TCF_BUSY); in initio_bus_device_reset()
2372 prev = tmp = host->first_busy; /* Check Busy queue */ in initio_bus_device_reset()
2374 if (tmp->target == tar) { in initio_bus_device_reset()
2376 if (tmp == host->first_busy) { in initio_bus_device_reset()
2377 if ((host->first_busy = tmp->next) == NULL) in initio_bus_device_reset()
2378 host->last_busy = NULL; in initio_bus_device_reset()
2380 prev->next = tmp->next; in initio_bus_device_reset()
2381 if (tmp == host->last_busy) in initio_bus_device_reset()
2382 host->last_busy = prev; in initio_bus_device_reset()
2384 tmp->hastat = HOST_ABORTED; in initio_bus_device_reset()
2391 tmp = tmp->next; in initio_bus_device_reset()
2393 outb(TARGET_RESET, host->addr + TUL_SFifo); in initio_bus_device_reset()
2394 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_bus_device_reset()
2401 outb(TSC_MSG_ACCEPT, host->addr + TUL_SCmd); in initio_msgin_accept()
2408 while (!((host->jsstatus0 = inb(host->addr + TUL_SStatus0)) in wait_tulip()
2412 host->jsint = inb(host->addr + TUL_SInt); in wait_tulip()
2413 host->phase = host->jsstatus0 & TSS_PH_MASK; in wait_tulip()
2414 host->jsstatus1 = inb(host->addr + TUL_SStatus1); in wait_tulip()
2416 if (host->jsint & TSS_RESEL_INT) /* if SCSI bus reset detected */ in wait_tulip()
2418 if (host->jsint & TSS_SEL_TIMEOUT) /* if selected/reselected timeout interrupt */ in wait_tulip()
2420 if (host->jsint & TSS_SCSIRST_INT) /* if SCSI bus reset detected */ in wait_tulip()
2423 if (host->jsint & TSS_DISC_INT) { /* BUS disconnection */ in wait_tulip()
2424 if (host->flags & HCF_EXPECT_DONE_DISC) { in wait_tulip()
2425 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); /* Flush SCSI FIFO */ in wait_tulip()
2426 initio_unlink_busy_scb(host, host->active); in wait_tulip()
2427 host->active->hastat = 0; in wait_tulip()
2428 initio_append_done_scb(host, host->active); in wait_tulip()
2429 host->active = NULL; in wait_tulip()
2430 host->active_tc = NULL; in wait_tulip()
2431 host->flags &= ~HCF_EXPECT_DONE_DISC; in wait_tulip()
2432 outb(TSC_INITDEFAULT, host->addr + TUL_SConfig); in wait_tulip()
2433 outb(TSC_HW_RESELECT, host->addr + TUL_SCtrl1); /* Enable HW reselect */ in wait_tulip()
2434 return -1; in wait_tulip()
2436 if (host->flags & HCF_EXPECT_DISC) { in wait_tulip()
2437 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); /* Flush SCSI FIFO */ in wait_tulip()
2438 host->active = NULL; in wait_tulip()
2439 host->active_tc = NULL; in wait_tulip()
2440 host->flags &= ~HCF_EXPECT_DISC; in wait_tulip()
2441 outb(TSC_INITDEFAULT, host->addr + TUL_SConfig); in wait_tulip()
2442 outb(TSC_HW_RESELECT, host->addr + TUL_SCtrl1); /* Enable HW reselect */ in wait_tulip()
2443 return -1; in wait_tulip()
2448 if (host->jsint & (TSS_FUNC_COMP | TSS_BUS_SERV)) in wait_tulip()
2449 return host->phase; in wait_tulip()
2450 return host->phase; in wait_tulip()
2455 while (!((host->jsstatus0 = inb(host->addr + TUL_SStatus0)) & TSS_INT_PENDING)) in initio_wait_disc()
2458 host->jsint = inb(host->addr + TUL_SInt); in initio_wait_disc()
2460 if (host->jsint & TSS_SCSIRST_INT) /* if SCSI bus reset detected */ in initio_wait_disc()
2462 if (host->jsint & TSS_DISC_INT) { /* BUS disconnection */ in initio_wait_disc()
2463 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); /* Flush SCSI FIFO */ in initio_wait_disc()
2464 outb(TSC_INITDEFAULT, host->addr + TUL_SConfig); in initio_wait_disc()
2465 outb(TSC_HW_RESELECT, host->addr + TUL_SCtrl1); /* Enable HW reselect */ in initio_wait_disc()
2466 host->active = NULL; in initio_wait_disc()
2467 return -1; in initio_wait_disc()
2474 while (!((host->jsstatus0 = inb(host->addr + TUL_SStatus0)) in initio_wait_done_disc()
2478 host->jsint = inb(host->addr + TUL_SInt); in initio_wait_done_disc()
2480 if (host->jsint & TSS_SCSIRST_INT) /* if SCSI bus reset detected */ in initio_wait_done_disc()
2482 if (host->jsint & TSS_DISC_INT) { /* BUS disconnection */ in initio_wait_done_disc()
2483 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); /* Flush SCSI FIFO */ in initio_wait_done_disc()
2484 outb(TSC_INITDEFAULT, host->addr + TUL_SConfig); in initio_wait_done_disc()
2485 outb(TSC_HW_RESELECT, host->addr + TUL_SCtrl1); /* Enable HW reselect */ in initio_wait_done_disc()
2486 initio_unlink_busy_scb(host, host->active); in initio_wait_done_disc()
2488 initio_append_done_scb(host, host->active); in initio_wait_done_disc()
2489 host->active = NULL; in initio_wait_done_disc()
2490 return -1; in initio_wait_done_disc()
2496 * i91u_intr - IRQ handler
2510 spin_lock_irqsave(dev->host_lock, flags); in i91u_intr()
2511 r = initio_isr((struct initio_host *)dev->hostdata); in i91u_intr()
2512 spin_unlock_irqrestore(dev->host_lock, flags); in i91u_intr()
2521 * initio_build_scb - Build the mappings and SCB
2540 cblk->post = i91uSCBPost; /* i91u's callback routine */ in initio_build_scb()
2541 cblk->srb = cmnd; in initio_build_scb()
2542 cblk->opcode = ExecSCSI; in initio_build_scb()
2543 cblk->flags = SCF_POST; /* After SCSI done, call post routine */ in initio_build_scb()
2544 cblk->target = cmnd->device->id; in initio_build_scb()
2545 cblk->lun = cmnd->device->lun; in initio_build_scb()
2546 cblk->ident = cmnd->device->lun | DISC_ALLOW; in initio_build_scb()
2548 cblk->flags |= SCF_SENSE; /* Turn on auto request sense */ in initio_build_scb()
2551 dma_addr = dma_map_single(&host->pci_dev->dev, cmnd->sense_buffer, in initio_build_scb()
2553 cblk->senseptr = (u32)dma_addr; in initio_build_scb()
2554 cblk->senselen = SENSE_SIZE; in initio_build_scb()
2555 initio_priv(cmnd)->sense_dma_addr = dma_addr; in initio_build_scb()
2556 cblk->cdblen = cmnd->cmd_len; in initio_build_scb()
2559 cblk->hastat = 0; in initio_build_scb()
2560 cblk->tastat = 0; in initio_build_scb()
2562 memcpy(cblk->cdb, cmnd->cmnd, cmnd->cmd_len); in initio_build_scb()
2565 if (cmnd->device->tagged_supported) { /* Tag Support */ in initio_build_scb()
2566 cblk->tagmsg = SIMPLE_QUEUE_TAG; /* Do simple tag only */ in initio_build_scb()
2568 cblk->tagmsg = 0; /* No tag support */ in initio_build_scb()
2575 dma_addr = dma_map_single(&host->pci_dev->dev, &cblk->sglist[0], in initio_build_scb()
2578 cblk->bufptr = (u32)dma_addr; in initio_build_scb()
2579 initio_priv(cmnd)->sglist_dma_addr = dma_addr; in initio_build_scb()
2581 cblk->sglen = nseg; in initio_build_scb()
2583 cblk->flags |= SCF_SG; /* Turn on SG list flag */ in initio_build_scb()
2585 sg = &cblk->sglist[0]; in initio_build_scb()
2586 scsi_for_each_sg(cmnd, sglist, cblk->sglen, i) { in initio_build_scb()
2587 sg->data = cpu_to_le32((u32)sg_dma_address(sglist)); in initio_build_scb()
2588 sg->len = cpu_to_le32((u32)sg_dma_len(sglist)); in initio_build_scb()
2593 cblk->buflen = (scsi_bufflen(cmnd) > total_len) ? in initio_build_scb()
2596 cblk->buflen = 0; in initio_build_scb()
2597 cblk->sglen = 0; in initio_build_scb()
2602 * i91u_queuecommand_lck - Queue a new command if possible
2611 struct initio_host *host = (struct initio_host *) cmd->device->host->hostdata; in i91u_queuecommand_lck()
2626 * i91u_bus_reset - reset the SCSI bus in DEF_SCSI_QCMD()
2636 host = (struct initio_host *) cmnd->device->host->hostdata; in DEF_SCSI_QCMD()
2638 spin_lock_irq(cmnd->device->host->host_lock); in DEF_SCSI_QCMD()
2640 spin_unlock_irq(cmnd->device->host->host_lock); in DEF_SCSI_QCMD()
2646 * i91u_biosparam - return the "logical geometry
2664 host = (struct initio_host *) sdev->host->hostdata; in i91u_biosparam()
2665 tc = &host->targets[sdev->id]; in i91u_biosparam()
2667 if (tc->heads) { in i91u_biosparam()
2668 info_array[0] = tc->heads; in i91u_biosparam()
2669 info_array[1] = tc->sectors; in i91u_biosparam()
2670 info_array[2] = (unsigned long)capacity / tc->heads / tc->sectors; in i91u_biosparam()
2672 if (tc->drv_flags & TCF_DRV_255_63) { in i91u_biosparam()
2695 * i91u_unmap_scb - Unmap a command
2706 if (initio_priv(cmnd)->sense_dma_addr) { in i91u_unmap_scb()
2707 dma_unmap_single(&pci_dev->dev, in i91u_unmap_scb()
2708 initio_priv(cmnd)->sense_dma_addr, in i91u_unmap_scb()
2710 initio_priv(cmnd)->sense_dma_addr = 0; in i91u_unmap_scb()
2715 dma_unmap_single(&pci_dev->dev, in i91u_unmap_scb()
2716 initio_priv(cmnd)->sglist_dma_addr, in i91u_unmap_scb()
2725 * i91uSCBPost - SCSI callback
2739 if ((cmnd = cblk->srb) == NULL) { in i91uSCBPost()
2749 switch (cblk->hastat) { in i91uSCBPost()
2753 cblk->hastat = 0; in i91uSCBPost()
2756 case 0x11: /* Selection time out-The initiator selection or target in i91uSCBPost()
2758 cblk->hastat = DID_TIME_OUT; in i91uSCBPost()
2761 case 0x14: /* Target bus phase sequence failure-An invalid bus phase or bus in i91uSCBPost()
2762 phase sequence was requested by the target. The host adapter in i91uSCBPost()
2765 cblk->hastat = DID_RESET; in i91uSCBPost()
2769 cblk->hastat = DID_ABORT; in i91uSCBPost()
2772 case 0x12: /* Data overrun/underrun-The target attempted to transfer more data in i91uSCBPost()
2775 case 0x13: /* Unexpected bus free-The target dropped the SCSI BSY at an unexpected time. */ in i91uSCBPost()
2779 printk("ini9100u: %x %x\n", cblk->hastat, cblk->tastat); in i91uSCBPost()
2780 cblk->hastat = DID_ERROR; /* Couldn't find any better */ in i91uSCBPost()
2784 cmnd->result = cblk->tastat | (cblk->hastat << 16); in i91uSCBPost()
2785 i91u_unmap_scb(host->pci_dev, cmnd); in i91uSCBPost()
2792 .name = "Initio INI-9X00U/UW SCSI device driver",
2822 if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) { in initio_probe_one()
2824 error = -ENODEV; in initio_probe_one()
2830 error = -ENOMEM; in initio_probe_one()
2833 host = (struct initio_host *)shost->hostdata; in initio_probe_one()
2835 host->addr = pci_resource_start(pdev, 0); in initio_probe_one()
2836 host->bios_addr = bios_seg; in initio_probe_one()
2838 if (!request_region(host->addr, 256, "i91u")) { in initio_probe_one()
2839 printk(KERN_WARNING "initio: I/O port range 0x%x is busy.\n", host->addr); in initio_probe_one()
2840 error = -ENODEV; in initio_probe_one()
2847 num_scb = MAX_TARGETS + 3; /* 1-tape, 1-CD_ROM, 1- extra */ in initio_probe_one()
2849 for (; num_scb >= MAX_TARGETS + 3; num_scb--) { in initio_probe_one()
2858 error = -ENOMEM; in initio_probe_one()
2862 host->pci_dev = pdev; in initio_probe_one()
2864 host->semaph = 1; in initio_probe_one()
2865 spin_lock_init(&host->semaph_lock); in initio_probe_one()
2866 host->num_scbs = num_scb; in initio_probe_one()
2867 host->scb = scb; in initio_probe_one()
2868 host->next_pending = scb; in initio_probe_one()
2869 host->next_avail = scb; in initio_probe_one()
2871 tmp->tagid = i; in initio_probe_one()
2873 prev->next = tmp; in initio_probe_one()
2876 prev->next = NULL; in initio_probe_one()
2877 host->scb_end = tmp; in initio_probe_one()
2878 host->first_avail = scb; in initio_probe_one()
2879 host->last_avail = prev; in initio_probe_one()
2880 spin_lock_init(&host->avail_lock); in initio_probe_one()
2884 host->jsstatus0 = 0; in initio_probe_one()
2886 shost->io_port = host->addr; in initio_probe_one()
2887 shost->n_io_port = 0xff; in initio_probe_one()
2888 shost->can_queue = num_scb; /* 03/05/98 */ in initio_probe_one()
2889 shost->unique_id = host->addr; in initio_probe_one()
2890 shost->max_id = host->max_tar; in initio_probe_one()
2891 shost->max_lun = 32; /* 10/21/97 */ in initio_probe_one()
2892 shost->irq = pdev->irq; in initio_probe_one()
2893 shost->this_id = host->scsi_id; /* Assign HCS index */ in initio_probe_one()
2894 shost->base = host->addr; in initio_probe_one()
2895 shost->sg_tablesize = TOTAL_SG_ENTRY; in initio_probe_one()
2897 error = request_irq(pdev->irq, i91u_intr, IRQF_SHARED, "i91u", shost); in initio_probe_one()
2899 printk(KERN_WARNING "initio: Unable to request IRQ %d\n", pdev->irq); in initio_probe_one()
2905 error = scsi_add_host(shost, &pdev->dev); in initio_probe_one()
2911 free_irq(pdev->irq, shost); in initio_probe_one()
2913 kfree(host->scb); in initio_probe_one()
2915 release_region(host->addr, 256); in initio_probe_one()
2924 * initio_remove_one - control shutdown
2934 struct initio_host *s = (struct initio_host *)host->hostdata; in initio_remove_one()
2936 free_irq(pdev->irq, host); in initio_remove_one()
2937 release_region(s->addr, 256); in initio_remove_one()
2962 MODULE_DESCRIPTION("Initio INI-9X00U/UW SCSI device driver");