Lines Matching full:host
28 * This is the Linux low-level SCSI driver for Initio INI-9X00U/UW SCSI host
131 static struct scsi_ctrl_blk *initio_find_busy_scb(struct initio_host * host, u16 tarlun);
132 static struct scsi_ctrl_blk *initio_find_done_scb(struct initio_host * host);
134 static int tulip_main(struct initio_host * host);
136 static int initio_next_state(struct initio_host * host);
137 static int initio_state_1(struct initio_host * host);
138 static int initio_state_2(struct initio_host * host);
139 static int initio_state_3(struct initio_host * host);
140 static int initio_state_4(struct initio_host * host);
141 static int initio_state_5(struct initio_host * host);
142 static int initio_state_6(struct initio_host * host);
143 static int initio_state_7(struct initio_host * host);
144 static int initio_xfer_data_in(struct initio_host * host);
145 static int initio_xfer_data_out(struct initio_host * host);
146 static int initio_xpad_in(struct initio_host * host);
147 static int initio_xpad_out(struct initio_host * host);
148 static int initio_status_msg(struct initio_host * host);
150 static int initio_msgin(struct initio_host * host);
151 static int initio_msgin_sync(struct initio_host * host);
152 static int initio_msgin_accept(struct initio_host * host);
153 static int initio_msgout_reject(struct initio_host * host);
154 static int initio_msgin_extend(struct initio_host * host);
156 static int initio_msgout_ide(struct initio_host * host);
157 static int initio_msgout_abort_targ(struct initio_host * host);
158 static int initio_msgout_abort_tag(struct initio_host * host);
160 static int initio_bus_device_reset(struct initio_host * host);
161 static void initio_select_atn(struct initio_host * host, struct scsi_ctrl_blk * scb);
162 static void initio_select_atn3(struct initio_host * host, struct scsi_ctrl_blk * scb);
163 static void initio_select_atn_stop(struct initio_host * host, struct scsi_ctrl_blk * scb);
164 static int int_initio_busfree(struct initio_host * host);
165 static int int_initio_scsi_rst(struct initio_host * host);
166 static int int_initio_bad_seq(struct initio_host * host);
167 static int int_initio_resel(struct initio_host * host);
168 static int initio_sync_done(struct initio_host * host);
169 static int wdtr_done(struct initio_host * host);
170 static int wait_tulip(struct initio_host * host);
171 static int initio_wait_done_disc(struct initio_host * host);
172 static int initio_wait_disc(struct initio_host * host);
173 static void tulip_scsi(struct initio_host * host);
174 static int initio_post_scsi_rst(struct initio_host * host);
193 /* -- Host Adapter Structure -- */
486 * @base: Base of InitIO Host Adapter
488 * Retrieve the host adapter configuration data from E2Prom. If the
516 * @host: InitIO we are stopping
521 static void initio_stop_bm(struct initio_host * host) in initio_stop_bm() argument
524 if (inb(host->addr + TUL_XStatus) & XPEND) { /* if DMA xfer is pending, abort DMA xfer */ in initio_stop_bm()
525 outb(TAX_X_ABT | TAX_X_CLR_FIFO, host->addr + TUL_XCmd); in initio_stop_bm()
527 while ((inb(host->addr + TUL_Int) & XABT) == 0) in initio_stop_bm()
530 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_stop_bm()
534 * initio_reset_scsi - Reset SCSI host controller
535 * @host: InitIO host to reset
541 static int initio_reset_scsi(struct initio_host * host, int seconds) in initio_reset_scsi() argument
543 outb(TSC_RST_BUS, host->addr + TUL_SCtrl0); in initio_reset_scsi()
545 while (!((host->jsint = inb(host->addr + TUL_SInt)) & TSS_SCSIRST_INT)) in initio_reset_scsi()
549 outb(0, host->addr + TUL_SSignal); in initio_reset_scsi()
556 inb(host->addr + TUL_SInt); in initio_reset_scsi()
561 * initio_init - set up an InitIO host adapter
562 * @host: InitIO host adapter
566 * Set up the host adapter and devices according to the configuration
573 static void initio_init(struct initio_host * host, u8 *bios_addr) in initio_init() argument
580 initio_read_eeprom(host->addr); in initio_init()
582 host->max_tar = 8; in initio_init()
584 host->max_tar = 16; in initio_init()
586 host->config = i91unvramp->NVM_SCSIInfo[0].NVM_ChConfig1; in initio_init()
588 host->scsi_id = i91unvramp->NVM_SCSIInfo[0].NVM_ChSCSIID; in initio_init()
589 host->idmask = ~(1 << host->scsi_id); in initio_init()
593 outb(inb(host->addr + TUL_PCMD) | 0x40, host->addr + TUL_PCMD); in initio_init()
597 outb(0x1F, host->addr + TUL_Mask); in initio_init()
599 initio_stop_bm(host); in initio_init()
601 outb(TSC_RST_CHIP, host->addr + TUL_SCtrl0); in initio_init()
604 outb(host->scsi_id << 4, host->addr + TUL_SScsiId); in initio_init()
608 if (host->config & HCC_EN_PAR) in initio_init()
609 host->sconf1 = (TSC_INITDEFAULT | TSC_EN_SCSI_PAR); in initio_init()
611 host->sconf1 = (TSC_INITDEFAULT); in initio_init()
612 outb(host->sconf1, host->addr + TUL_SConfig); in initio_init()
615 outb(TSC_HW_RESELECT, host->addr + TUL_SCtrl1); in initio_init()
617 outb(0, host->addr + TUL_SPeriod); in initio_init()
620 outb(153, host->addr + TUL_STimeOut); in initio_init()
623 outb((host->config & (HCC_ACT_TERM1 | HCC_ACT_TERM2)), in initio_init()
624 host->addr + TUL_XCtrl); in initio_init()
625 outb(((host->config & HCC_AUTO_TERM) >> 4) | in initio_init()
626 (inb(host->addr + TUL_GCTRL1) & 0xFE), in initio_init()
627 host->addr + TUL_GCTRL1); in initio_init()
632 i < host->max_tar; in initio_init()
634 host->targets[i].flags = *flags & ~(TCF_SYNC_DONE | TCF_WDTR_DONE); in initio_init()
635 if (host->targets[i].flags & TCF_EN_255) in initio_init()
636 host->targets[i].drv_flags = TCF_DRV_255_63; in initio_init()
638 host->targets[i].drv_flags = 0; in initio_init()
639 host->targets[i].js_period = 0; in initio_init()
640 host->targets[i].sconfig0 = host->sconf1; in initio_init()
641 host->targets[i].heads = *heads++; in initio_init()
642 if (host->targets[i].heads == 255) in initio_init()
643 host->targets[i].drv_flags = TCF_DRV_255_63; in initio_init()
645 host->targets[i].drv_flags = 0; in initio_init()
646 host->targets[i].sectors = *heads++; in initio_init()
647 host->targets[i].flags &= ~TCF_BUSY; in initio_init()
648 host->act_tags[i] = 0; in initio_init()
649 host->max_tags[i] = 0xFF; in initio_init()
652 host->addr, host->pci_dev->irq, in initio_init()
653 host->bios_addr, host->scsi_id); in initio_init()
655 if (host->config & HCC_SCSI_RESET) { in initio_init()
657 initio_reset_scsi(host, 10); in initio_init()
659 outb(0x17, host->addr + TUL_SCFG1); in initio_init()
660 outb(0xE9, host->addr + TUL_SIntEnable); in initio_init()
665 * @host: InitIO host we are allocating for
670 static struct scsi_ctrl_blk *initio_alloc_scb(struct initio_host *host) in initio_alloc_scb() argument
675 spin_lock_irqsave(&host->avail_lock, flags); in initio_alloc_scb()
676 if ((scb = host->first_avail) != NULL) { in initio_alloc_scb()
680 if ((host->first_avail = scb->next) == NULL) in initio_alloc_scb()
681 host->last_avail = NULL; in initio_alloc_scb()
685 spin_unlock_irqrestore(&host->avail_lock, flags); in initio_alloc_scb()
691 * @host: InitIO host that owns the SCB
694 * Return an allocated SCB to the host free list
697 static void initio_release_scb(struct initio_host * host, struct scsi_ctrl_blk * cmnd) in initio_release_scb() argument
704 spin_lock_irqsave(&(host->avail_lock), flags); in initio_release_scb()
708 if (host->last_avail != NULL) { in initio_release_scb()
709 host->last_avail->next = cmnd; in initio_release_scb()
710 host->last_avail = cmnd; in initio_release_scb()
712 host->first_avail = cmnd; in initio_release_scb()
713 host->last_avail = cmnd; in initio_release_scb()
715 spin_unlock_irqrestore(&(host->avail_lock), flags); in initio_release_scb()
719 static void initio_append_pend_scb(struct initio_host * host, struct scsi_ctrl_blk * scbp) in initio_append_pend_scb() argument
727 if (host->last_pending != NULL) { in initio_append_pend_scb()
728 host->last_pending->next = scbp; in initio_append_pend_scb()
729 host->last_pending = scbp; in initio_append_pend_scb()
731 host->first_pending = scbp; in initio_append_pend_scb()
732 host->last_pending = scbp; in initio_append_pend_scb()
737 static void initio_push_pend_scb(struct initio_host * host, struct scsi_ctrl_blk * scbp) in initio_push_pend_scb() argument
744 if ((scbp->next = host->first_pending) != NULL) { in initio_push_pend_scb()
745 host->first_pending = scbp; in initio_push_pend_scb()
747 host->first_pending = scbp; in initio_push_pend_scb()
748 host->last_pending = scbp; in initio_push_pend_scb()
752 static struct scsi_ctrl_blk *initio_find_first_pend_scb(struct initio_host * host) in initio_find_first_pend_scb() argument
757 first = host->first_pending; in initio_find_first_pend_scb()
762 if ((host->act_tags[first->target] == 0) && in initio_find_first_pend_scb()
763 !(host->targets[first->target].flags & TCF_BUSY)) in initio_find_first_pend_scb()
766 if ((host->act_tags[first->target] >= in initio_find_first_pend_scb()
767 host->max_tags[first->target]) | in initio_find_first_pend_scb()
768 (host->targets[first->target].flags & TCF_BUSY)) { in initio_find_first_pend_scb()
779 static void initio_unlink_pend_scb(struct initio_host * host, struct scsi_ctrl_blk * scb) in initio_unlink_pend_scb() argument
787 prev = tmp = host->first_pending; in initio_unlink_pend_scb()
790 if (tmp == host->first_pending) { in initio_unlink_pend_scb()
791 if ((host->first_pending = tmp->next) == NULL) in initio_unlink_pend_scb()
792 host->last_pending = NULL; in initio_unlink_pend_scb()
795 if (tmp == host->last_pending) in initio_unlink_pend_scb()
796 host->last_pending = prev; in initio_unlink_pend_scb()
806 static void initio_append_busy_scb(struct initio_host * host, struct scsi_ctrl_blk * scbp) in initio_append_busy_scb() argument
813 host->act_tags[scbp->target]++; in initio_append_busy_scb()
815 host->targets[scbp->target].flags |= TCF_BUSY; in initio_append_busy_scb()
818 if (host->last_busy != NULL) { in initio_append_busy_scb()
819 host->last_busy->next = scbp; in initio_append_busy_scb()
820 host->last_busy = scbp; in initio_append_busy_scb()
822 host->first_busy = scbp; in initio_append_busy_scb()
823 host->last_busy = scbp; in initio_append_busy_scb()
828 static struct scsi_ctrl_blk *initio_pop_busy_scb(struct initio_host * host) in initio_pop_busy_scb() argument
833 if ((tmp = host->first_busy) != NULL) { in initio_pop_busy_scb()
834 if ((host->first_busy = tmp->next) == NULL) in initio_pop_busy_scb()
835 host->last_busy = NULL; in initio_pop_busy_scb()
838 host->act_tags[tmp->target]--; in initio_pop_busy_scb()
840 host->targets[tmp->target].flags &= ~TCF_BUSY; in initio_pop_busy_scb()
849 static void initio_unlink_busy_scb(struct initio_host * host, struct scsi_ctrl_blk * scb) in initio_unlink_busy_scb() argument
857 prev = tmp = host->first_busy; in initio_unlink_busy_scb()
860 if (tmp == host->first_busy) { in initio_unlink_busy_scb()
861 if ((host->first_busy = tmp->next) == NULL) in initio_unlink_busy_scb()
862 host->last_busy = NULL; in initio_unlink_busy_scb()
865 if (tmp == host->last_busy) in initio_unlink_busy_scb()
866 host->last_busy = prev; in initio_unlink_busy_scb()
870 host->act_tags[tmp->target]--; in initio_unlink_busy_scb()
872 host->targets[tmp->target].flags &= ~TCF_BUSY; in initio_unlink_busy_scb()
881 struct scsi_ctrl_blk *initio_find_busy_scb(struct initio_host * host, u16 tarlun) in initio_find_busy_scb() argument
887 prev = tmp = host->first_busy; in initio_find_busy_scb()
902 static void initio_append_done_scb(struct initio_host * host, struct scsi_ctrl_blk * scbp) in initio_append_done_scb() argument
910 if (host->last_done != NULL) { in initio_append_done_scb()
911 host->last_done->next = scbp; in initio_append_done_scb()
912 host->last_done = scbp; in initio_append_done_scb()
914 host->first_done = scbp; in initio_append_done_scb()
915 host->last_done = scbp; in initio_append_done_scb()
919 struct scsi_ctrl_blk *initio_find_done_scb(struct initio_host * host) in initio_find_done_scb() argument
923 if ((tmp = host->first_done) != NULL) { in initio_find_done_scb()
924 if ((host->first_done = tmp->next) == NULL) in initio_find_done_scb()
925 host->last_done = NULL; in initio_find_done_scb()
934 static int initio_abort_srb(struct initio_host * host, struct scsi_cmnd *srbp) in initio_abort_srb() argument
939 spin_lock_irqsave(&host->semaph_lock, flags); in initio_abort_srb()
941 if ((host->semaph == 0) && (host->active == NULL)) { in initio_abort_srb()
943 outb(0x1F, host->addr + TUL_Mask); in initio_abort_srb()
944 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_abort_srb()
946 tulip_main(host); in initio_abort_srb()
947 spin_lock_irqsave(&host->semaph_lock, flags); in initio_abort_srb()
948 host->semaph = 1; in initio_abort_srb()
949 outb(0x0F, host->addr + TUL_Mask); in initio_abort_srb()
950 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_abort_srb()
953 prev = tmp = host->first_pending; /* Check Pend queue */ in initio_abort_srb()
957 if (tmp == host->active) { in initio_abort_srb()
958 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_abort_srb()
960 } else if (tmp == host->first_pending) { in initio_abort_srb()
961 if ((host->first_pending = tmp->next) == NULL) in initio_abort_srb()
962 host->last_pending = NULL; in initio_abort_srb()
965 if (tmp == host->last_pending) in initio_abort_srb()
966 host->last_pending = prev; in initio_abort_srb()
971 (*tmp->post) ((u8 *) host, (u8 *) tmp); in initio_abort_srb()
972 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_abort_srb()
979 prev = tmp = host->first_busy; /* Check Busy queue */ in initio_abort_srb()
982 if (tmp == host->active) { in initio_abort_srb()
983 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_abort_srb()
986 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_abort_srb()
989 host->act_tags[tmp->target]--; in initio_abort_srb()
990 if (tmp == host->first_busy) { in initio_abort_srb()
991 if ((host->first_busy = tmp->next) == NULL) in initio_abort_srb()
992 host->last_busy = NULL; in initio_abort_srb()
995 if (tmp == host->last_busy) in initio_abort_srb()
996 host->last_busy = prev; in initio_abort_srb()
1004 (*tmp->post) ((u8 *) host, (u8 *) tmp); in initio_abort_srb()
1005 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_abort_srb()
1012 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_abort_srb()
1017 static int initio_bad_seq(struct initio_host * host) in initio_bad_seq() argument
1021 printk("initio_bad_seg c=%d\n", host->index); in initio_bad_seq()
1023 if ((scb = host->active) != NULL) { in initio_bad_seq()
1024 initio_unlink_busy_scb(host, scb); in initio_bad_seq()
1027 initio_append_done_scb(host, scb); in initio_bad_seq()
1029 initio_stop_bm(host); in initio_bad_seq()
1030 initio_reset_scsi(host, 8); /* 7/29/98 */ in initio_bad_seq()
1031 return initio_post_scsi_rst(host); in initio_bad_seq()
1036 static void initio_exec_scb(struct initio_host * host, struct scsi_ctrl_blk * scb) in initio_exec_scb() argument
1045 spin_lock_irqsave(&host->semaph_lock, flags); in initio_exec_scb()
1047 initio_append_pend_scb(host, scb); /* Append this SCB to Pending queue */ in initio_exec_scb()
1050 if (host->semaph == 1) { in initio_exec_scb()
1052 outb(0x1F, host->addr + TUL_Mask); in initio_exec_scb()
1053 host->semaph = 0; in initio_exec_scb()
1054 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_exec_scb()
1056 tulip_main(host); in initio_exec_scb()
1058 spin_lock_irqsave(&host->semaph_lock, flags); in initio_exec_scb()
1059 host->semaph = 1; in initio_exec_scb()
1060 outb(0x0F, host->addr + TUL_Mask); in initio_exec_scb()
1062 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_exec_scb()
1067 static int initio_isr(struct initio_host * host) in initio_isr() argument
1069 if (inb(host->addr + TUL_Int) & TSS_INT_PENDING) { in initio_isr()
1070 if (host->semaph == 1) { in initio_isr()
1071 outb(0x1F, host->addr + TUL_Mask); in initio_isr()
1073 host->semaph = 0; in initio_isr()
1075 tulip_main(host); in initio_isr()
1077 host->semaph = 1; in initio_isr()
1078 outb(0x0F, host->addr + TUL_Mask); in initio_isr()
1085 static int tulip_main(struct initio_host * host) in tulip_main() argument
1090 tulip_scsi(host); /* Call tulip_scsi */ in tulip_main()
1093 while ((scb = initio_find_done_scb(host)) != NULL) { /* find done entry */ in tulip_main()
1095 host->max_tags[scb->target] = in tulip_main()
1096 host->act_tags[scb->target] - 1; in tulip_main()
1098 initio_append_pend_scb(host, scb); in tulip_main()
1127 initio_push_pend_scb(host, scb); in tulip_main()
1142 (*scb->post) ((u8 *) host, (u8 *) scb); in tulip_main()
1146 if (inb(host->addr + TUL_SStatus0) & TSS_INT_PENDING) in tulip_main()
1148 if (host->active) /* return to OS and wait for xfer_done_ISR/Selected_ISR */ in tulip_main()
1151 if (initio_find_first_pend_scb(host) == NULL) in tulip_main()
1157 static void tulip_scsi(struct initio_host * host) in tulip_scsi() argument
1163 if ((host->jsstatus0 = inb(host->addr + TUL_SStatus0)) & TSS_INT_PENDING) { in tulip_scsi()
1164 host->phase = host->jsstatus0 & TSS_PH_MASK; in tulip_scsi()
1165 host->jsstatus1 = inb(host->addr + TUL_SStatus1); in tulip_scsi()
1166 host->jsint = inb(host->addr + TUL_SInt); in tulip_scsi()
1167 if (host->jsint & TSS_SCSIRST_INT) { /* SCSI bus reset detected */ in tulip_scsi()
1168 int_initio_scsi_rst(host); in tulip_scsi()
1171 if (host->jsint & TSS_RESEL_INT) { /* if selected/reselected interrupt */ in tulip_scsi()
1172 if (int_initio_resel(host) == 0) in tulip_scsi()
1173 initio_next_state(host); in tulip_scsi()
1176 if (host->jsint & TSS_SEL_TIMEOUT) { in tulip_scsi()
1177 int_initio_busfree(host); in tulip_scsi()
1180 if (host->jsint & TSS_DISC_INT) { /* BUS disconnection */ in tulip_scsi()
1181 int_initio_busfree(host); /* unexpected bus free or sel timeout */ in tulip_scsi()
1184 if (host->jsint & (TSS_FUNC_COMP | TSS_BUS_SERV)) { /* func complete or Bus service */ in tulip_scsi()
1185 if ((scb = host->active) != NULL) in tulip_scsi()
1186 initio_next_state(host); in tulip_scsi()
1190 if (host->active != NULL) in tulip_scsi()
1193 if ((scb = initio_find_first_pend_scb(host)) == NULL) in tulip_scsi()
1197 outb((host->scsi_id << 4) | (scb->target & 0x0F), in tulip_scsi()
1198 host->addr + TUL_SScsiId); in tulip_scsi()
1200 active_tc = &host->targets[scb->target]; in tulip_scsi()
1207 outb(active_tc->js_period, host->addr + TUL_SPeriod); in tulip_scsi()
1209 initio_select_atn_stop(host, scb); in tulip_scsi()
1212 initio_select_atn_stop(host, scb); in tulip_scsi()
1215 initio_select_atn3(host, scb); in tulip_scsi()
1217 initio_select_atn(host, scb); in tulip_scsi()
1221 while (wait_tulip(host) != -1) { in tulip_scsi()
1222 if (initio_next_state(host) == -1) in tulip_scsi()
1227 initio_select_atn_stop(host, scb); in tulip_scsi()
1230 while (wait_tulip(host) != -1) { in tulip_scsi()
1231 if (initio_next_state(host) == -1) in tulip_scsi()
1236 if (initio_abort_srb(host, scb->srb) != 0) { in tulip_scsi()
1237 initio_unlink_pend_scb(host, scb); in tulip_scsi()
1238 initio_release_scb(host, scb); in tulip_scsi()
1241 initio_select_atn_stop(host, scb); in tulip_scsi()
1245 initio_unlink_pend_scb(host, scb); in tulip_scsi()
1247 initio_append_done_scb(host, scb); in tulip_scsi()
1254 * @host: InitIO host we are processing
1262 static int initio_next_state(struct initio_host * host) in initio_next_state() argument
1266 next = host->active->next_state; in initio_next_state()
1270 next = initio_state_1(host); in initio_next_state()
1273 next = initio_state_2(host); in initio_next_state()
1276 next = initio_state_3(host); in initio_next_state()
1279 next = initio_state_4(host); in initio_next_state()
1282 next = initio_state_5(host); in initio_next_state()
1285 next = initio_state_6(host); in initio_next_state()
1288 next = initio_state_7(host); in initio_next_state()
1291 return initio_bus_device_reset(host); in initio_next_state()
1293 return initio_bad_seq(host); in initio_next_state()
1303 * @host: InitIO host we are controlling
1308 static int initio_state_1(struct initio_host * host) in initio_state_1() argument
1310 struct scsi_ctrl_blk *scb = host->active; in initio_state_1()
1311 struct target_control *active_tc = host->active_tc; in initio_state_1()
1317 initio_unlink_pend_scb(host, scb); in initio_state_1()
1318 initio_append_busy_scb(host, scb); in initio_state_1()
1320 outb(active_tc->sconfig0, host->addr + TUL_SConfig ); in initio_state_1()
1322 if (host->phase == MSG_OUT) { in initio_state_1()
1323 outb(TSC_EN_BUS_IN | TSC_HW_RESELECT, host->addr + TUL_SCtrl1); in initio_state_1()
1324 outb(scb->ident, host->addr + TUL_SFifo); in initio_state_1()
1327 outb(scb->tagmsg, host->addr + TUL_SFifo); in initio_state_1()
1328 outb(scb->tagid, host->addr + TUL_SFifo); in initio_state_1()
1332 outb(MSG_EXTEND, host->addr + TUL_SFifo); in initio_state_1()
1333 outb(2, host->addr + TUL_SFifo); /* Extended msg length */ in initio_state_1()
1334 outb(3, host->addr + TUL_SFifo); /* Sync request */ in initio_state_1()
1335 outb(1, host->addr + TUL_SFifo); /* Start from 16 bits */ in initio_state_1()
1338 outb(MSG_EXTEND, host->addr + TUL_SFifo); in initio_state_1()
1339 outb(3, host->addr + TUL_SFifo); /* extended msg length */ in initio_state_1()
1340 outb(1, host->addr + TUL_SFifo); /* sync request */ in initio_state_1()
1341 outb(initio_rate_tbl[active_tc->flags & TCF_SCSI_RATE], host->addr + TUL_SFifo); in initio_state_1()
1342 outb(MAX_OFFSET, host->addr + TUL_SFifo); /* REQ/ACK offset */ in initio_state_1()
1344 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_state_1()
1345 if (wait_tulip(host) == -1) in initio_state_1()
1348 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_state_1()
1349 outb((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)), host->addr + TUL_SSignal); in initio_state_1()
1357 * @host: InitIO host we are controlling
1363 static int initio_state_2(struct initio_host * host) in initio_state_2() argument
1365 struct scsi_ctrl_blk *scb = host->active; in initio_state_2()
1366 struct target_control *active_tc = host->active_tc; in initio_state_2()
1371 initio_unlink_pend_scb(host, scb); in initio_state_2()
1372 initio_append_busy_scb(host, scb); in initio_state_2()
1374 outb(active_tc->sconfig0, host->addr + TUL_SConfig); in initio_state_2()
1376 if (host->jsstatus1 & TSS_CMD_PH_CMP) in initio_state_2()
1379 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_state_2()
1380 outb((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)), host->addr + TUL_SSignal); in initio_state_2()
1387 * @host: InitIO host we are controlling
1392 static int initio_state_3(struct initio_host * host) in initio_state_3() argument
1394 struct scsi_ctrl_blk *scb = host->active; in initio_state_3()
1395 struct target_control *active_tc = host->active_tc; in initio_state_3()
1402 switch (host->phase) { in initio_state_3()
1405 outb(scb->cdb[i], host->addr + TUL_SFifo); in initio_state_3()
1406 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_state_3()
1407 if (wait_tulip(host) == -1) in initio_state_3()
1409 if (host->phase == CMD_OUT) in initio_state_3()
1410 return initio_bad_seq(host); in initio_state_3()
1415 if (initio_msgin(host) == -1) in initio_state_3()
1420 if (initio_status_msg(host) == -1) in initio_state_3()
1426 outb(MSG_NOP, host->addr + TUL_SFifo); /* msg nop */ in initio_state_3()
1427 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_state_3()
1428 if (wait_tulip(host) == -1) in initio_state_3()
1433 outb(MSG_EXTEND, host->addr + TUL_SFifo); in initio_state_3()
1434 outb(3, host->addr + TUL_SFifo); /* ext. msg len */ in initio_state_3()
1435 outb(1, host->addr + TUL_SFifo); /* sync request */ in initio_state_3()
1436 outb(initio_rate_tbl[active_tc->flags & TCF_SCSI_RATE], host->addr + TUL_SFifo); in initio_state_3()
1437 outb(MAX_OFFSET, host->addr + TUL_SFifo); /* REQ/ACK offset */ in initio_state_3()
1438 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_state_3()
1439 if (wait_tulip(host) == -1) in initio_state_3()
1441 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_state_3()
1442 outb(inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7), host->addr + TUL_SSignal); in initio_state_3()
1447 return initio_bad_seq(host); in initio_state_3()
1454 * @host: InitIO host we are controlling
1459 static int initio_state_4(struct initio_host * host) in initio_state_4() argument
1461 struct scsi_ctrl_blk *scb = host->active; in initio_state_4()
1473 switch (host->phase) { in initio_state_4()
1478 if ((initio_status_msg(host)) == -1) in initio_state_4()
1484 if (initio_msgin(host) == -1) in initio_state_4()
1489 if (host->jsstatus0 & TSS_PAR_ERROR) { in initio_state_4()
1492 if (initio_msgout_ide(host) == -1) in initio_state_4()
1496 outb(MSG_NOP, host->addr + TUL_SFifo); /* msg nop */ in initio_state_4()
1497 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_state_4()
1498 if (wait_tulip(host) == -1) in initio_state_4()
1504 return initio_xfer_data_in(host); in initio_state_4()
1507 return initio_xfer_data_out(host); in initio_state_4()
1510 return initio_bad_seq(host); in initio_state_4()
1518 * @host: InitIO host we are controlling
1523 static int initio_state_5(struct initio_host * host) in initio_state_5() argument
1525 struct scsi_ctrl_blk *scb = host->active; in initio_state_5()
1532 cnt = inl(host->addr + TUL_SCnt0) & 0x0FFFFFF; in initio_state_5()
1534 if (inb(host->addr + TUL_XCmd) & 0x20) { in initio_state_5()
1537 if (host->jsstatus0 & TSS_PAR_ERROR) in initio_state_5()
1539 if (inb(host->addr + TUL_XStatus) & XPEND) { /* DMA xfer pending, Send STOP */ in initio_state_5()
1541 outb(inb(host->addr + TUL_XCtrl) | 0x80, host->addr + TUL_XCtrl); in initio_state_5()
1543 while (inb(host->addr + TUL_XStatus) & XPEND) in initio_state_5()
1548 if ((inb(host->addr + TUL_SStatus1) & TSS_XFER_CMP) == 0) { in initio_state_5()
1549 if (host->active_tc->js_period & TSC_WIDE_SCSI) in initio_state_5()
1550 cnt += (inb(host->addr + TUL_SFifoCnt) & 0x1F) << 1; in initio_state_5()
1552 cnt += (inb(host->addr + TUL_SFifoCnt) & 0x1F); in initio_state_5()
1554 if (inb(host->addr + TUL_XStatus) & XPEND) { /* if DMA xfer is pending, abort DMA xfer */ in initio_state_5()
1555 outb(TAX_X_ABT, host->addr + TUL_XCmd); in initio_state_5()
1557 while ((inb(host->addr + TUL_Int) & XABT) == 0) in initio_state_5()
1560 if ((cnt == 1) && (host->phase == DATA_OUT)) { in initio_state_5()
1561 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_state_5()
1562 if (wait_tulip(host) == -1) in initio_state_5()
1566 if ((inb(host->addr + TUL_SStatus1) & TSS_XFER_CMP) == 0) in initio_state_5()
1567 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_state_5()
1607 * @host: InitIO host we are controlling
1612 static int initio_state_6(struct initio_host * host) in initio_state_6() argument
1614 struct scsi_ctrl_blk *scb = host->active; in initio_state_6()
1620 switch (host->phase) { in initio_state_6()
1622 if ((initio_status_msg(host)) == -1) in initio_state_6()
1628 if ((initio_msgin(host)) == -1) in initio_state_6()
1633 outb(MSG_NOP, host->addr + TUL_SFifo); /* msg nop */ in initio_state_6()
1634 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_state_6()
1635 if (wait_tulip(host) == -1) in initio_state_6()
1640 return initio_xpad_in(host); in initio_state_6()
1643 return initio_xpad_out(host); in initio_state_6()
1646 return initio_bad_seq(host); in initio_state_6()
1653 * @host: InitIO host we are controlling
1657 int initio_state_7(struct initio_host * host) in initio_state_7() argument
1665 cnt = inb(host->addr + TUL_SFifoCnt) & 0x1F; in initio_state_7()
1668 inb(host->addr + TUL_SFifo); in initio_state_7()
1670 switch (host->phase) { in initio_state_7()
1673 return initio_bad_seq(host); in initio_state_7()
1681 * @host: InitIO host in use
1687 static int initio_xfer_data_in(struct initio_host * host) in initio_xfer_data_in() argument
1689 struct scsi_ctrl_blk *scb = host->active; in initio_xfer_data_in()
1694 outl(scb->buflen, host->addr + TUL_SCnt0); in initio_xfer_data_in()
1695 outb(TSC_XF_DMA_IN, host->addr + TUL_SCmd); /* 7/25/95 */ in initio_xfer_data_in()
1698 outl(((u32) scb->sglen) << 3, host->addr + TUL_XCntH); in initio_xfer_data_in()
1699 outl(scb->bufptr, host->addr + TUL_XAddH); in initio_xfer_data_in()
1700 outb(TAX_SG_IN, host->addr + TUL_XCmd); in initio_xfer_data_in()
1702 outl(scb->buflen, host->addr + TUL_XCntH); in initio_xfer_data_in()
1703 outl(scb->bufptr, host->addr + TUL_XAddH); in initio_xfer_data_in()
1704 outb(TAX_X_IN, host->addr + TUL_XCmd); in initio_xfer_data_in()
1712 * @host: InitIO host in use
1719 static int initio_xfer_data_out(struct initio_host * host) in initio_xfer_data_out() argument
1721 struct scsi_ctrl_blk *scb = host->active; in initio_xfer_data_out()
1726 outl(scb->buflen, host->addr + TUL_SCnt0); in initio_xfer_data_out()
1727 outb(TSC_XF_DMA_OUT, host->addr + TUL_SCmd); in initio_xfer_data_out()
1730 outl(((u32) scb->sglen) << 3, host->addr + TUL_XCntH); in initio_xfer_data_out()
1731 outl(scb->bufptr, host->addr + TUL_XAddH); in initio_xfer_data_out()
1732 outb(TAX_SG_OUT, host->addr + TUL_XCmd); in initio_xfer_data_out()
1734 outl(scb->buflen, host->addr + TUL_XCntH); in initio_xfer_data_out()
1735 outl(scb->bufptr, host->addr + TUL_XAddH); in initio_xfer_data_out()
1736 outb(TAX_X_OUT, host->addr + TUL_XCmd); in initio_xfer_data_out()
1743 int initio_xpad_in(struct initio_host * host) in initio_xpad_in() argument
1745 struct scsi_ctrl_blk *scb = host->active; in initio_xpad_in()
1746 struct target_control *active_tc = host->active_tc; in initio_xpad_in()
1752 outl(2, host->addr + TUL_SCnt0); in initio_xpad_in()
1754 outl(1, host->addr + TUL_SCnt0); in initio_xpad_in()
1756 outb(TSC_XF_FIFO_IN, host->addr + TUL_SCmd); in initio_xpad_in()
1757 if (wait_tulip(host) == -1) in initio_xpad_in()
1759 if (host->phase != DATA_IN) { in initio_xpad_in()
1760 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_xpad_in()
1763 inb(host->addr + TUL_SFifo); in initio_xpad_in()
1767 int initio_xpad_out(struct initio_host * host) in initio_xpad_out() argument
1769 struct scsi_ctrl_blk *scb = host->active; in initio_xpad_out()
1770 struct target_control *active_tc = host->active_tc; in initio_xpad_out()
1776 outl(2, host->addr + TUL_SCnt0); in initio_xpad_out()
1778 outl(1, host->addr + TUL_SCnt0); in initio_xpad_out()
1780 outb(0, host->addr + TUL_SFifo); in initio_xpad_out()
1781 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_xpad_out()
1782 if ((wait_tulip(host)) == -1) in initio_xpad_out()
1784 if (host->phase != DATA_OUT) { /* Disable wide CPU to allow read 16 bits */ in initio_xpad_out()
1785 outb(TSC_HW_RESELECT, host->addr + TUL_SCtrl1); in initio_xpad_out()
1786 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_xpad_out()
1792 int initio_status_msg(struct initio_host * host) in initio_status_msg() argument
1794 struct scsi_ctrl_blk *scb = host->active; in initio_status_msg()
1797 outb(TSC_CMD_COMP, host->addr + TUL_SCmd); in initio_status_msg()
1798 if (wait_tulip(host) == -1) in initio_status_msg()
1802 scb->tastat = inb(host->addr + TUL_SFifo); in initio_status_msg()
1804 if (host->phase == MSG_OUT) { in initio_status_msg()
1805 if (host->jsstatus0 & TSS_PAR_ERROR) in initio_status_msg()
1806 outb(MSG_PARITY, host->addr + TUL_SFifo); in initio_status_msg()
1808 outb(MSG_NOP, host->addr + TUL_SFifo); in initio_status_msg()
1809 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_status_msg()
1810 return wait_tulip(host); in initio_status_msg()
1812 if (host->phase == MSG_IN) { in initio_status_msg()
1813 msg = inb(host->addr + TUL_SFifo); in initio_status_msg()
1814 if (host->jsstatus0 & TSS_PAR_ERROR) { /* Parity error */ in initio_status_msg()
1815 if ((initio_msgin_accept(host)) == -1) in initio_status_msg()
1817 if (host->phase != MSG_OUT) in initio_status_msg()
1818 return initio_bad_seq(host); in initio_status_msg()
1819 outb(MSG_PARITY, host->addr + TUL_SFifo); in initio_status_msg()
1820 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_status_msg()
1821 return wait_tulip(host); in initio_status_msg()
1826 return initio_bad_seq(host); in initio_status_msg()
1827 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_status_msg()
1828 outb(TSC_MSG_ACCEPT, host->addr + TUL_SCmd); in initio_status_msg()
1829 return initio_wait_done_disc(host); in initio_status_msg()
1834 return initio_msgin_accept(host); in initio_status_msg()
1837 return initio_bad_seq(host); in initio_status_msg()
1842 int int_initio_busfree(struct initio_host * host) in int_initio_busfree() argument
1844 struct scsi_ctrl_blk *scb = host->active; in int_initio_busfree()
1848 initio_unlink_pend_scb(host, scb); in int_initio_busfree()
1850 initio_append_done_scb(host, scb); in int_initio_busfree()
1852 initio_unlink_busy_scb(host, scb); in int_initio_busfree()
1854 initio_append_done_scb(host, scb); in int_initio_busfree()
1856 host->active = NULL; in int_initio_busfree()
1857 host->active_tc = NULL; in int_initio_busfree()
1859 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); /* Flush SCSI FIFO */ in int_initio_busfree()
1860 outb(TSC_INITDEFAULT, host->addr + TUL_SConfig); in int_initio_busfree()
1861 outb(TSC_HW_RESELECT, host->addr + TUL_SCtrl1); /* Enable HW reselect */ in int_initio_busfree()
1868 * @host: Host seeing the reset
1876 static int int_initio_scsi_rst(struct initio_host * host) in int_initio_scsi_rst() argument
1882 if (inb(host->addr + TUL_XStatus) & 0x01) { in int_initio_scsi_rst()
1883 outb(TAX_X_ABT | TAX_X_CLR_FIFO, host->addr + TUL_XCmd); in int_initio_scsi_rst()
1885 while ((inb(host->addr + TUL_Int) & 0x04) == 0) in int_initio_scsi_rst()
1887 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in int_initio_scsi_rst()
1890 while ((scb = initio_pop_busy_scb(host)) != NULL) { in int_initio_scsi_rst()
1892 initio_append_done_scb(host, scb); in int_initio_scsi_rst()
1894 host->active = NULL; in int_initio_scsi_rst()
1895 host->active_tc = NULL; in int_initio_scsi_rst()
1898 for (i = 0; i < host->max_tar; i++) in int_initio_scsi_rst()
1899 host->targets[i].flags &= ~(TCF_SYNC_DONE | TCF_WDTR_DONE); in int_initio_scsi_rst()
1905 * @host: InitIO host adapter
1912 int int_initio_resel(struct initio_host * host) in int_initio_resel() argument
1919 if ((scb = host->active) != NULL) { in int_initio_resel()
1923 host->active = NULL; in int_initio_resel()
1926 tar = inb(host->addr + TUL_SBusId); in int_initio_resel()
1928 lun = inb(host->addr + TUL_SIdent) & 0x0F; in int_initio_resel()
1930 active_tc = &host->targets[tar]; in int_initio_resel()
1931 host->active_tc = active_tc; in int_initio_resel()
1932 outb(active_tc->sconfig0, host->addr + TUL_SConfig); in int_initio_resel()
1933 outb(active_tc->js_period, host->addr + TUL_SPeriod); in int_initio_resel()
1937 if ((initio_msgin_accept(host)) == -1) in int_initio_resel()
1939 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()
1945 msg = inb(host->addr + TUL_SFifo); /* Read Tag Message */ in int_initio_resel()
1950 if (initio_msgin_accept(host) == -1) in int_initio_resel()
1953 if (host->phase != MSG_IN) in int_initio_resel()
1956 outl(1, host->addr + TUL_SCnt0); in int_initio_resel()
1957 outb(TSC_XF_FIFO_IN, host->addr + TUL_SCmd); in int_initio_resel()
1958 if (wait_tulip(host) == -1) in int_initio_resel()
1960 tag = inb(host->addr + TUL_SFifo); /* Read Tag ID */ in int_initio_resel()
1961 scb = host->scb + tag; in int_initio_resel()
1963 return initio_msgout_abort_tag(host); in int_initio_resel()
1966 return initio_msgout_abort_tag(host); in int_initio_resel()
1968 host->active = scb; in int_initio_resel()
1969 if ((initio_msgin_accept(host)) == -1) in int_initio_resel()
1973 if ((scb = initio_find_busy_scb(host, tar | (lun << 8))) == NULL) { in int_initio_resel()
1974 return initio_msgout_abort_targ(host); in int_initio_resel()
1976 host->active = scb; in int_initio_resel()
1978 if ((initio_msgin_accept(host)) == -1) in int_initio_resel()
1987 * @host: InitIO host flagging event
1989 * We have ended up out of phase somehow. Reset the host controller
1993 static int int_initio_bad_seq(struct initio_host * host) in int_initio_bad_seq() argument
1998 initio_reset_scsi(host, 10); in int_initio_bad_seq()
2000 while ((scb = initio_pop_busy_scb(host)) != NULL) { in int_initio_bad_seq()
2002 initio_append_done_scb(host, scb); in int_initio_bad_seq()
2004 for (i = 0; i < host->max_tar; i++) in int_initio_bad_seq()
2005 host->targets[i].flags &= ~(TCF_SYNC_DONE | TCF_WDTR_DONE); in int_initio_bad_seq()
2012 * @host: InitIO host
2018 static int initio_msgout_abort_targ(struct initio_host * host) in initio_msgout_abort_targ() argument
2021 …outb(((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)) | TSC_SET_ATN), host->addr + TUL_SSignal… in initio_msgout_abort_targ()
2022 if (initio_msgin_accept(host) == -1) in initio_msgout_abort_targ()
2024 if (host->phase != MSG_OUT) in initio_msgout_abort_targ()
2025 return initio_bad_seq(host); in initio_msgout_abort_targ()
2027 outb(MSG_ABORT, host->addr + TUL_SFifo); in initio_msgout_abort_targ()
2028 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_msgout_abort_targ()
2030 return initio_wait_disc(host); in initio_msgout_abort_targ()
2035 * @host: InitIO host
2041 static int initio_msgout_abort_tag(struct initio_host * host) in initio_msgout_abort_tag() argument
2044 …outb(((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)) | TSC_SET_ATN), host->addr + TUL_SSignal… in initio_msgout_abort_tag()
2045 if (initio_msgin_accept(host) == -1) in initio_msgout_abort_tag()
2047 if (host->phase != MSG_OUT) in initio_msgout_abort_tag()
2048 return initio_bad_seq(host); in initio_msgout_abort_tag()
2050 outb(MSG_ABORT_TAG, host->addr + TUL_SFifo); in initio_msgout_abort_tag()
2051 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_msgout_abort_tag()
2053 return initio_wait_disc(host); in initio_msgout_abort_tag()
2059 * @host: InitIO Host
2063 static int initio_msgin(struct initio_host * host) in initio_msgin() argument
2068 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_msgin()
2070 outl(1, host->addr + TUL_SCnt0); in initio_msgin()
2071 outb(TSC_XF_FIFO_IN, host->addr + TUL_SCmd); in initio_msgin()
2072 if (wait_tulip(host) == -1) in initio_msgin()
2075 switch (inb(host->addr + TUL_SFifo)) { in initio_msgin()
2077 outb(TSC_MSG_ACCEPT, host->addr + TUL_SCmd); in initio_msgin()
2078 return initio_wait_disc(host); in initio_msgin()
2082 initio_msgin_accept(host); in initio_msgin()
2085 outb((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)), in initio_msgin()
2086 host->addr + TUL_SSignal); in initio_msgin()
2087 active_tc = host->active_tc; in initio_msgin()
2089 outb(((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)) | TSC_SET_ATN), in initio_msgin()
2090 host->addr + TUL_SSignal); in initio_msgin()
2091 initio_msgin_accept(host); in initio_msgin()
2094 initio_msgin_extend(host); in initio_msgin()
2097 initio_msgin_accept(host); in initio_msgin()
2100 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_msgin()
2101 outb(TSC_MSG_ACCEPT, host->addr + TUL_SCmd); in initio_msgin()
2102 return initio_wait_done_disc(host); in initio_msgin()
2104 initio_msgout_reject(host); in initio_msgin()
2107 if (host->phase != MSG_IN) in initio_msgin()
2108 return host->phase; in initio_msgin()
2113 static int initio_msgout_reject(struct initio_host * host) in initio_msgout_reject() argument
2115 …outb(((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)) | TSC_SET_ATN), host->addr + TUL_SSignal… in initio_msgout_reject()
2117 if (initio_msgin_accept(host) == -1) in initio_msgout_reject()
2120 if (host->phase == MSG_OUT) { in initio_msgout_reject()
2121 outb(MSG_REJ, host->addr + TUL_SFifo); /* Msg reject */ in initio_msgout_reject()
2122 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_msgout_reject()
2123 return wait_tulip(host); in initio_msgout_reject()
2125 return host->phase; in initio_msgout_reject()
2128 static int initio_msgout_ide(struct initio_host * host) in initio_msgout_ide() argument
2130 outb(MSG_IDE, host->addr + TUL_SFifo); /* Initiator Detected Error */ in initio_msgout_ide()
2131 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_msgout_ide()
2132 return wait_tulip(host); in initio_msgout_ide()
2135 static int initio_msgin_extend(struct initio_host * host) in initio_msgin_extend() argument
2139 if (initio_msgin_accept(host) != MSG_IN) in initio_msgin_extend()
2140 return host->phase; in initio_msgin_extend()
2143 outl(1, host->addr + TUL_SCnt0); in initio_msgin_extend()
2144 outb(TSC_XF_FIFO_IN, host->addr + TUL_SCmd); in initio_msgin_extend()
2145 if (wait_tulip(host) == -1) in initio_msgin_extend()
2148 len = inb(host->addr + TUL_SFifo); in initio_msgin_extend()
2149 host->msg[0] = len; in initio_msgin_extend()
2152 if ((initio_msgin_accept(host)) != MSG_IN) in initio_msgin_extend()
2153 return host->phase; in initio_msgin_extend()
2154 outl(1, host->addr + TUL_SCnt0); in initio_msgin_extend()
2155 outb(TSC_XF_FIFO_IN, host->addr + TUL_SCmd); in initio_msgin_extend()
2156 if (wait_tulip(host) == -1) in initio_msgin_extend()
2158 host->msg[idx++] = inb(host->addr + TUL_SFifo); in initio_msgin_extend()
2160 if (host->msg[1] == 1) { /* if it's synchronous data transfer request */ in initio_msgin_extend()
2162 if (host->msg[0] != 3) /* if length is not right */ in initio_msgin_extend()
2163 return initio_msgout_reject(host); in initio_msgin_extend()
2164 if (host->active_tc->flags & TCF_NO_SYNC_NEGO) { /* Set OFFSET=0 to do async, nego back */ in initio_msgin_extend()
2165 host->msg[3] = 0; in initio_msgin_extend()
2167 if (initio_msgin_sync(host) == 0 && in initio_msgin_extend()
2168 (host->active_tc->flags & TCF_SYNC_DONE)) { in initio_msgin_extend()
2169 initio_sync_done(host); in initio_msgin_extend()
2170 return initio_msgin_accept(host); in initio_msgin_extend()
2174 r = inb(host->addr + TUL_SSignal); in initio_msgin_extend()
2176 host->addr + TUL_SSignal); in initio_msgin_extend()
2177 if (initio_msgin_accept(host) != MSG_OUT) in initio_msgin_extend()
2178 return host->phase; in initio_msgin_extend()
2180 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_msgin_extend()
2182 initio_sync_done(host); in initio_msgin_extend()
2184 outb(MSG_EXTEND, host->addr + TUL_SFifo); in initio_msgin_extend()
2185 outb(3, host->addr + TUL_SFifo); in initio_msgin_extend()
2186 outb(1, host->addr + TUL_SFifo); in initio_msgin_extend()
2187 outb(host->msg[2], host->addr + TUL_SFifo); in initio_msgin_extend()
2188 outb(host->msg[3], host->addr + TUL_SFifo); in initio_msgin_extend()
2189 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_msgin_extend()
2190 return wait_tulip(host); in initio_msgin_extend()
2192 if (host->msg[0] != 2 || host->msg[1] != 3) in initio_msgin_extend()
2193 return initio_msgout_reject(host); in initio_msgin_extend()
2195 if (host->active_tc->flags & TCF_NO_WDTR) { in initio_msgin_extend()
2196 host->msg[2] = 0; in initio_msgin_extend()
2198 if (host->msg[2] > 2) /* > 32 bits */ in initio_msgin_extend()
2199 return initio_msgout_reject(host); in initio_msgin_extend()
2200 if (host->msg[2] == 2) { /* == 32 */ in initio_msgin_extend()
2201 host->msg[2] = 1; in initio_msgin_extend()
2203 if ((host->active_tc->flags & TCF_NO_WDTR) == 0) { in initio_msgin_extend()
2204 wdtr_done(host); in initio_msgin_extend()
2205 if ((host->active_tc->flags & (TCF_SYNC_DONE | TCF_NO_SYNC_NEGO)) == 0) in initio_msgin_extend()
2206 …outb(((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)) | TSC_SET_ATN), host->addr + TUL_SSignal… in initio_msgin_extend()
2207 return initio_msgin_accept(host); in initio_msgin_extend()
2211 …outb(((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)) | TSC_SET_ATN), host->addr + TUL_SSignal… in initio_msgin_extend()
2213 if (initio_msgin_accept(host) != MSG_OUT) in initio_msgin_extend()
2214 return host->phase; in initio_msgin_extend()
2216 outb(MSG_EXTEND, host->addr + TUL_SFifo); in initio_msgin_extend()
2217 outb(2, host->addr + TUL_SFifo); in initio_msgin_extend()
2218 outb(3, host->addr + TUL_SFifo); in initio_msgin_extend()
2219 outb(host->msg[2], host->addr + TUL_SFifo); in initio_msgin_extend()
2220 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_msgin_extend()
2221 return wait_tulip(host); in initio_msgin_extend()
2224 static int initio_msgin_sync(struct initio_host * host) in initio_msgin_sync() argument
2228 default_period = initio_rate_tbl[host->active_tc->flags & TCF_SCSI_RATE]; in initio_msgin_sync()
2229 if (host->msg[3] > MAX_OFFSET) { in initio_msgin_sync()
2230 host->msg[3] = MAX_OFFSET; in initio_msgin_sync()
2231 if (host->msg[2] < default_period) { in initio_msgin_sync()
2232 host->msg[2] = default_period; in initio_msgin_sync()
2235 if (host->msg[2] >= 59) /* Change to async */ in initio_msgin_sync()
2236 host->msg[3] = 0; in initio_msgin_sync()
2240 if (host->msg[3] == 0) { in initio_msgin_sync()
2243 if (host->msg[2] < default_period) { in initio_msgin_sync()
2244 host->msg[2] = default_period; in initio_msgin_sync()
2247 if (host->msg[2] >= 59) { in initio_msgin_sync()
2248 host->msg[3] = 0; in initio_msgin_sync()
2254 static int wdtr_done(struct initio_host * host) in wdtr_done() argument
2256 host->active_tc->flags &= ~TCF_SYNC_DONE; in wdtr_done()
2257 host->active_tc->flags |= TCF_WDTR_DONE; in wdtr_done()
2259 host->active_tc->js_period = 0; in wdtr_done()
2260 if (host->msg[2]) /* if 16 bit */ in wdtr_done()
2261 host->active_tc->js_period |= TSC_WIDE_SCSI; in wdtr_done()
2262 host->active_tc->sconfig0 &= ~TSC_ALT_PERIOD; in wdtr_done()
2263 outb(host->active_tc->sconfig0, host->addr + TUL_SConfig); in wdtr_done()
2264 outb(host->active_tc->js_period, host->addr + TUL_SPeriod); in wdtr_done()
2269 static int initio_sync_done(struct initio_host * host) in initio_sync_done() argument
2273 host->active_tc->flags |= TCF_SYNC_DONE; in initio_sync_done()
2275 if (host->msg[3]) { in initio_sync_done()
2276 host->active_tc->js_period |= host->msg[3]; in initio_sync_done()
2278 if (initio_rate_tbl[i] >= host->msg[2]) /* pick the big one */ in initio_sync_done()
2281 host->active_tc->js_period |= (i << 4); in initio_sync_done()
2282 host->active_tc->sconfig0 |= TSC_ALT_PERIOD; in initio_sync_done()
2284 outb(host->active_tc->sconfig0, host->addr + TUL_SConfig); in initio_sync_done()
2285 outb(host->active_tc->js_period, host->addr + TUL_SPeriod); in initio_sync_done()
2291 static int initio_post_scsi_rst(struct initio_host * host) in initio_post_scsi_rst() argument
2297 host->active = NULL; in initio_post_scsi_rst()
2298 host->active_tc = NULL; in initio_post_scsi_rst()
2299 host->flags = 0; in initio_post_scsi_rst()
2301 while ((scb = initio_pop_busy_scb(host)) != NULL) { in initio_post_scsi_rst()
2303 initio_append_done_scb(host, scb); in initio_post_scsi_rst()
2306 active_tc = &host->targets[0]; in initio_post_scsi_rst()
2307 for (i = 0; i < host->max_tar; active_tc++, i++) { in initio_post_scsi_rst()
2311 active_tc->sconfig0 = host->sconf1; in initio_post_scsi_rst()
2312 host->act_tags[0] = 0; /* 07/22/98 */ in initio_post_scsi_rst()
2313 host->targets[i].flags &= ~TCF_BUSY; /* 07/22/98 */ in initio_post_scsi_rst()
2319 static void initio_select_atn_stop(struct initio_host * host, struct scsi_ctrl_blk * scb) in initio_select_atn_stop() argument
2323 host->active = scb; in initio_select_atn_stop()
2324 host->active_tc = &host->targets[scb->target]; in initio_select_atn_stop()
2325 outb(TSC_SELATNSTOP, host->addr + TUL_SCmd); in initio_select_atn_stop()
2329 static void initio_select_atn(struct initio_host * host, struct scsi_ctrl_blk * scb) in initio_select_atn() argument
2336 outb(scb->ident, host->addr + TUL_SFifo); in initio_select_atn()
2338 outb(scb->cdb[i], host->addr + TUL_SFifo); in initio_select_atn()
2339 host->active_tc = &host->targets[scb->target]; in initio_select_atn()
2340 host->active = scb; in initio_select_atn()
2341 outb(TSC_SEL_ATN, host->addr + TUL_SCmd); in initio_select_atn()
2344 static void initio_select_atn3(struct initio_host * host, struct scsi_ctrl_blk * scb) in initio_select_atn3() argument
2351 outb(scb->ident, host->addr + TUL_SFifo); in initio_select_atn3()
2352 outb(scb->tagmsg, host->addr + TUL_SFifo); in initio_select_atn3()
2353 outb(scb->tagid, host->addr + TUL_SFifo); in initio_select_atn3()
2355 outb(scb->cdb[i], host->addr + TUL_SFifo); in initio_select_atn3()
2356 host->active_tc = &host->targets[scb->target]; in initio_select_atn3()
2357 host->active = scb; in initio_select_atn3()
2358 outb(TSC_SEL_ATN3, host->addr + TUL_SCmd); in initio_select_atn3()
2363 * @host: InitIO host to reset
2368 int initio_bus_device_reset(struct initio_host * host) in initio_bus_device_reset() argument
2370 struct scsi_ctrl_blk *scb = host->active; in initio_bus_device_reset()
2371 struct target_control *active_tc = host->active_tc; in initio_bus_device_reset()
2375 if (host->phase != MSG_OUT) in initio_bus_device_reset()
2376 return int_initio_bad_seq(host); /* Unexpected phase */ in initio_bus_device_reset()
2378 initio_unlink_pend_scb(host, scb); in initio_bus_device_reset()
2379 initio_release_scb(host, scb); in initio_bus_device_reset()
2387 prev = tmp = host->first_busy; /* Check Busy queue */ in initio_bus_device_reset()
2391 if (tmp == host->first_busy) { in initio_bus_device_reset()
2392 if ((host->first_busy = tmp->next) == NULL) in initio_bus_device_reset()
2393 host->last_busy = NULL; in initio_bus_device_reset()
2396 if (tmp == host->last_busy) in initio_bus_device_reset()
2397 host->last_busy = prev; in initio_bus_device_reset()
2400 initio_append_done_scb(host, tmp); in initio_bus_device_reset()
2408 outb(MSG_DEVRST, host->addr + TUL_SFifo); in initio_bus_device_reset()
2409 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_bus_device_reset()
2410 return initio_wait_disc(host); in initio_bus_device_reset()
2414 static int initio_msgin_accept(struct initio_host * host) in initio_msgin_accept() argument
2416 outb(TSC_MSG_ACCEPT, host->addr + TUL_SCmd); in initio_msgin_accept()
2417 return wait_tulip(host); in initio_msgin_accept()
2420 static int wait_tulip(struct initio_host * host) in wait_tulip() argument
2423 while (!((host->jsstatus0 = inb(host->addr + TUL_SStatus0)) in wait_tulip()
2427 host->jsint = inb(host->addr + TUL_SInt); in wait_tulip()
2428 host->phase = host->jsstatus0 & TSS_PH_MASK; in wait_tulip()
2429 host->jsstatus1 = inb(host->addr + TUL_SStatus1); in wait_tulip()
2431 if (host->jsint & TSS_RESEL_INT) /* if SCSI bus reset detected */ in wait_tulip()
2432 return int_initio_resel(host); in wait_tulip()
2433 if (host->jsint & TSS_SEL_TIMEOUT) /* if selected/reselected timeout interrupt */ in wait_tulip()
2434 return int_initio_busfree(host); in wait_tulip()
2435 if (host->jsint & TSS_SCSIRST_INT) /* if SCSI bus reset detected */ in wait_tulip()
2436 return int_initio_scsi_rst(host); in wait_tulip()
2438 if (host->jsint & TSS_DISC_INT) { /* BUS disconnection */ in wait_tulip()
2439 if (host->flags & HCF_EXPECT_DONE_DISC) { in wait_tulip()
2440 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); /* Flush SCSI FIFO */ in wait_tulip()
2441 initio_unlink_busy_scb(host, host->active); in wait_tulip()
2442 host->active->hastat = 0; in wait_tulip()
2443 initio_append_done_scb(host, host->active); in wait_tulip()
2444 host->active = NULL; in wait_tulip()
2445 host->active_tc = NULL; in wait_tulip()
2446 host->flags &= ~HCF_EXPECT_DONE_DISC; in wait_tulip()
2447 outb(TSC_INITDEFAULT, host->addr + TUL_SConfig); in wait_tulip()
2448 outb(TSC_HW_RESELECT, host->addr + TUL_SCtrl1); /* Enable HW reselect */ in wait_tulip()
2451 if (host->flags & HCF_EXPECT_DISC) { in wait_tulip()
2452 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); /* Flush SCSI FIFO */ in wait_tulip()
2453 host->active = NULL; in wait_tulip()
2454 host->active_tc = NULL; in wait_tulip()
2455 host->flags &= ~HCF_EXPECT_DISC; in wait_tulip()
2456 outb(TSC_INITDEFAULT, host->addr + TUL_SConfig); in wait_tulip()
2457 outb(TSC_HW_RESELECT, host->addr + TUL_SCtrl1); /* Enable HW reselect */ in wait_tulip()
2460 return int_initio_busfree(host); in wait_tulip()
2463 if (host->jsint & (TSS_FUNC_COMP | TSS_BUS_SERV)) in wait_tulip()
2464 return host->phase; in wait_tulip()
2465 return host->phase; in wait_tulip()
2468 static int initio_wait_disc(struct initio_host * host) in initio_wait_disc() argument
2470 while (!((host->jsstatus0 = inb(host->addr + TUL_SStatus0)) & TSS_INT_PENDING)) in initio_wait_disc()
2473 host->jsint = inb(host->addr + TUL_SInt); in initio_wait_disc()
2475 if (host->jsint & TSS_SCSIRST_INT) /* if SCSI bus reset detected */ in initio_wait_disc()
2476 return int_initio_scsi_rst(host); in initio_wait_disc()
2477 if (host->jsint & TSS_DISC_INT) { /* BUS disconnection */ in initio_wait_disc()
2478 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); /* Flush SCSI FIFO */ in initio_wait_disc()
2479 outb(TSC_INITDEFAULT, host->addr + TUL_SConfig); in initio_wait_disc()
2480 outb(TSC_HW_RESELECT, host->addr + TUL_SCtrl1); /* Enable HW reselect */ in initio_wait_disc()
2481 host->active = NULL; in initio_wait_disc()
2484 return initio_bad_seq(host); in initio_wait_disc()
2487 static int initio_wait_done_disc(struct initio_host * host) in initio_wait_done_disc() argument
2489 while (!((host->jsstatus0 = inb(host->addr + TUL_SStatus0)) in initio_wait_done_disc()
2493 host->jsint = inb(host->addr + TUL_SInt); in initio_wait_done_disc()
2495 if (host->jsint & TSS_SCSIRST_INT) /* if SCSI bus reset detected */ in initio_wait_done_disc()
2496 return int_initio_scsi_rst(host); in initio_wait_done_disc()
2497 if (host->jsint & TSS_DISC_INT) { /* BUS disconnection */ in initio_wait_done_disc()
2498 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); /* Flush SCSI FIFO */ in initio_wait_done_disc()
2499 outb(TSC_INITDEFAULT, host->addr + TUL_SConfig); in initio_wait_done_disc()
2500 outb(TSC_HW_RESELECT, host->addr + TUL_SCtrl1); /* Enable HW reselect */ in initio_wait_done_disc()
2501 initio_unlink_busy_scb(host, host->active); in initio_wait_done_disc()
2503 initio_append_done_scb(host, host->active); in initio_wait_done_disc()
2504 host->active = NULL; in initio_wait_done_disc()
2507 return initio_bad_seq(host); in initio_wait_done_disc()
2537 * @host: InitIO host taking the command
2542 * suitable for feeding to the InitIO host controller. This also requires
2546 static void initio_build_scb(struct initio_host * host, struct scsi_ctrl_blk * cblk, struct scsi_cm… in initio_build_scb() argument
2566 dma_addr = dma_map_single(&host->pci_dev->dev, cmnd->sense_buffer, in initio_build_scb()
2590 dma_addr = dma_map_single(&host->pci_dev->dev, &cblk->sglist[0], in initio_build_scb()
2621 * Attempts to queue a new command with the host adapter. Will return
2622 * zero if successful or indicate a host busy condition if not (which
2629 struct initio_host *host = (struct initio_host *) cmd->device->host->hostdata; in i91u_queuecommand_lck() local
2634 cmnd = initio_alloc_scb(host); in i91u_queuecommand_lck()
2638 initio_build_scb(host, cmnd, cmd); in i91u_queuecommand_lck()
2639 initio_exec_scb(host, cmnd); in i91u_queuecommand_lck()
2654 struct initio_host *host; in DEF_SCSI_QCMD() local
2656 host = (struct initio_host *) cmnd->device->host->hostdata; in DEF_SCSI_QCMD()
2658 spin_lock_irq(cmnd->device->host->host_lock); in DEF_SCSI_QCMD()
2659 initio_reset_scsi(host, 0); in DEF_SCSI_QCMD()
2660 spin_unlock_irq(cmnd->device->host->host_lock); in DEF_SCSI_QCMD()
2672 * Map the device geometry in a manner compatible with the host
2681 struct initio_host *host; /* Point to Host adapter control block */ in i91u_biosparam() local
2684 host = (struct initio_host *) sdev->host->hostdata; in i91u_biosparam()
2685 tc = &host->targets[sdev->id]; in i91u_biosparam()
2745 * @host: Pointer to host adapter control block.
2755 struct initio_host *host; in i91uSCBPost() local
2758 host = (struct initio_host *) host_mem; in i91uSCBPost()
2763 initio_release_scb(host, cblk); /* Release SCB for current channel */ in i91uSCBPost()
2783 phase sequence was requested by the target. The host adapter in i91uSCBPost()
2784 will generate a SCSI Reset Condition, notifying the host with in i91uSCBPost()
2806 i91u_unmap_scb(host->pci_dev, cmnd); in i91uSCBPost()
2808 initio_release_scb(host, cblk); /* Release SCB for current channel */ in i91uSCBPost()
2827 struct initio_host *host; in initio_probe_one() local
2850 printk(KERN_WARNING "initio: Could not allocate host structure.\n"); in initio_probe_one()
2854 host = (struct initio_host *)shost->hostdata; in initio_probe_one()
2855 memset(host, 0, sizeof(struct initio_host)); in initio_probe_one()
2856 host->addr = pci_resource_start(pdev, 0); in initio_probe_one()
2857 host->bios_addr = bios_seg; in initio_probe_one()
2859 if (!request_region(host->addr, 256, "i91u")) { in initio_probe_one()
2860 printk(KERN_WARNING "initio: I/O port range 0x%x is busy.\n", host->addr); in initio_probe_one()
2882 host->pci_dev = pdev; in initio_probe_one()
2884 host->semaph = 1; in initio_probe_one()
2885 spin_lock_init(&host->semaph_lock); in initio_probe_one()
2886 host->num_scbs = num_scb; in initio_probe_one()
2887 host->scb = scb; in initio_probe_one()
2888 host->next_pending = scb; in initio_probe_one()
2889 host->next_avail = scb; in initio_probe_one()
2897 host->scb_end = tmp; in initio_probe_one()
2898 host->first_avail = scb; in initio_probe_one()
2899 host->last_avail = prev; in initio_probe_one()
2900 spin_lock_init(&host->avail_lock); in initio_probe_one()
2902 initio_init(host, phys_to_virt(((u32)bios_seg << 4))); in initio_probe_one()
2904 host->jsstatus0 = 0; in initio_probe_one()
2906 shost->io_port = host->addr; in initio_probe_one()
2909 shost->unique_id = host->addr; in initio_probe_one()
2910 shost->max_id = host->max_tar; in initio_probe_one()
2913 shost->this_id = host->scsi_id; /* Assign HCS index */ in initio_probe_one()
2914 shost->base = host->addr; in initio_probe_one()
2933 kfree(host->scb); in initio_probe_one()
2935 release_region(host->addr, 256); in initio_probe_one()
2953 struct Scsi_Host *host = pci_get_drvdata(pdev); in initio_remove_one() local
2954 struct initio_host *s = (struct initio_host *)host->hostdata; in initio_remove_one()
2955 scsi_remove_host(host); in initio_remove_one()
2956 free_irq(pdev->irq, host); in initio_remove_one()
2958 scsi_host_put(host); in initio_remove_one()