Lines Matching refs:host
147 static struct scsi_ctrl_blk *initio_find_busy_scb(struct initio_host * host, u16 tarlun);
148 static struct scsi_ctrl_blk *initio_find_done_scb(struct initio_host * host);
150 static int tulip_main(struct initio_host * host);
152 static int initio_next_state(struct initio_host * host);
153 static int initio_state_1(struct initio_host * host);
154 static int initio_state_2(struct initio_host * host);
155 static int initio_state_3(struct initio_host * host);
156 static int initio_state_4(struct initio_host * host);
157 static int initio_state_5(struct initio_host * host);
158 static int initio_state_6(struct initio_host * host);
159 static int initio_state_7(struct initio_host * host);
160 static int initio_xfer_data_in(struct initio_host * host);
161 static int initio_xfer_data_out(struct initio_host * host);
162 static int initio_xpad_in(struct initio_host * host);
163 static int initio_xpad_out(struct initio_host * host);
164 static int initio_status_msg(struct initio_host * host);
166 static int initio_msgin(struct initio_host * host);
167 static int initio_msgin_sync(struct initio_host * host);
168 static int initio_msgin_accept(struct initio_host * host);
169 static int initio_msgout_reject(struct initio_host * host);
170 static int initio_msgin_extend(struct initio_host * host);
172 static int initio_msgout_ide(struct initio_host * host);
173 static int initio_msgout_abort_targ(struct initio_host * host);
174 static int initio_msgout_abort_tag(struct initio_host * host);
176 static int initio_bus_device_reset(struct initio_host * host);
177 static void initio_select_atn(struct initio_host * host, struct scsi_ctrl_blk * scb);
178 static void initio_select_atn3(struct initio_host * host, struct scsi_ctrl_blk * scb);
179 static void initio_select_atn_stop(struct initio_host * host, struct scsi_ctrl_blk * scb);
180 static int int_initio_busfree(struct initio_host * host);
181 static int int_initio_scsi_rst(struct initio_host * host);
182 static int int_initio_bad_seq(struct initio_host * host);
183 static int int_initio_resel(struct initio_host * host);
184 static int initio_sync_done(struct initio_host * host);
185 static int wdtr_done(struct initio_host * host);
186 static int wait_tulip(struct initio_host * host);
187 static int initio_wait_done_disc(struct initio_host * host);
188 static int initio_wait_disc(struct initio_host * host);
189 static void tulip_scsi(struct initio_host * host);
190 static int initio_post_scsi_rst(struct initio_host * host);
537 static void initio_stop_bm(struct initio_host * host) in initio_stop_bm() argument
540 if (inb(host->addr + TUL_XStatus) & XPEND) { /* if DMA xfer is pending, abort DMA xfer */ in initio_stop_bm()
541 outb(TAX_X_ABT | TAX_X_CLR_FIFO, host->addr + TUL_XCmd); in initio_stop_bm()
543 while ((inb(host->addr + TUL_Int) & XABT) == 0) in initio_stop_bm()
546 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_stop_bm()
557 static int initio_reset_scsi(struct initio_host * host, int seconds) in initio_reset_scsi() argument
559 outb(TSC_RST_BUS, host->addr + TUL_SCtrl0); in initio_reset_scsi()
561 while (!((host->jsint = inb(host->addr + TUL_SInt)) & TSS_SCSIRST_INT)) in initio_reset_scsi()
565 outb(0, host->addr + TUL_SSignal); in initio_reset_scsi()
572 inb(host->addr + TUL_SInt); in initio_reset_scsi()
589 static void initio_init(struct initio_host * host, u8 *bios_addr) in initio_init() argument
596 initio_read_eeprom(host->addr); in initio_init()
598 host->max_tar = 8; in initio_init()
600 host->max_tar = 16; in initio_init()
602 host->config = i91unvramp->NVM_SCSIInfo[0].NVM_ChConfig1; in initio_init()
604 host->scsi_id = i91unvramp->NVM_SCSIInfo[0].NVM_ChSCSIID; in initio_init()
605 host->idmask = ~(1 << host->scsi_id); in initio_init()
609 outb(inb(host->addr + TUL_PCMD) | 0x40, host->addr + TUL_PCMD); in initio_init()
613 outb(0x1F, host->addr + TUL_Mask); in initio_init()
615 initio_stop_bm(host); in initio_init()
617 outb(TSC_RST_CHIP, host->addr + TUL_SCtrl0); in initio_init()
620 outb(host->scsi_id << 4, host->addr + TUL_SScsiId); in initio_init()
624 if (host->config & HCC_EN_PAR) in initio_init()
625 host->sconf1 = (TSC_INITDEFAULT | TSC_EN_SCSI_PAR); in initio_init()
627 host->sconf1 = (TSC_INITDEFAULT); in initio_init()
628 outb(host->sconf1, host->addr + TUL_SConfig); in initio_init()
631 outb(TSC_HW_RESELECT, host->addr + TUL_SCtrl1); in initio_init()
633 outb(0, host->addr + TUL_SPeriod); in initio_init()
636 outb(153, host->addr + TUL_STimeOut); in initio_init()
639 outb((host->config & (HCC_ACT_TERM1 | HCC_ACT_TERM2)), in initio_init()
640 host->addr + TUL_XCtrl); in initio_init()
641 outb(((host->config & HCC_AUTO_TERM) >> 4) | in initio_init()
642 (inb(host->addr + TUL_GCTRL1) & 0xFE), in initio_init()
643 host->addr + TUL_GCTRL1); in initio_init()
648 i < host->max_tar; in initio_init()
650 host->targets[i].flags = *flags & ~(TCF_SYNC_DONE | TCF_WDTR_DONE); in initio_init()
651 if (host->targets[i].flags & TCF_EN_255) in initio_init()
652 host->targets[i].drv_flags = TCF_DRV_255_63; in initio_init()
654 host->targets[i].drv_flags = 0; in initio_init()
655 host->targets[i].js_period = 0; in initio_init()
656 host->targets[i].sconfig0 = host->sconf1; in initio_init()
657 host->targets[i].heads = *heads++; in initio_init()
658 if (host->targets[i].heads == 255) in initio_init()
659 host->targets[i].drv_flags = TCF_DRV_255_63; in initio_init()
661 host->targets[i].drv_flags = 0; in initio_init()
662 host->targets[i].sectors = *heads++; in initio_init()
663 host->targets[i].flags &= ~TCF_BUSY; in initio_init()
664 host->act_tags[i] = 0; in initio_init()
665 host->max_tags[i] = 0xFF; in initio_init()
668 host->addr, host->pci_dev->irq, in initio_init()
669 host->bios_addr, host->scsi_id); in initio_init()
671 if (host->config & HCC_SCSI_RESET) { in initio_init()
673 initio_reset_scsi(host, 10); in initio_init()
675 outb(0x17, host->addr + TUL_SCFG1); in initio_init()
676 outb(0xE9, host->addr + TUL_SIntEnable); in initio_init()
686 static struct scsi_ctrl_blk *initio_alloc_scb(struct initio_host *host) in initio_alloc_scb() argument
691 spin_lock_irqsave(&host->avail_lock, flags); in initio_alloc_scb()
692 if ((scb = host->first_avail) != NULL) { in initio_alloc_scb()
696 if ((host->first_avail = scb->next) == NULL) in initio_alloc_scb()
697 host->last_avail = NULL; in initio_alloc_scb()
701 spin_unlock_irqrestore(&host->avail_lock, flags); in initio_alloc_scb()
713 static void initio_release_scb(struct initio_host * host, struct scsi_ctrl_blk * cmnd) in initio_release_scb() argument
720 spin_lock_irqsave(&(host->avail_lock), flags); in initio_release_scb()
724 if (host->last_avail != NULL) { in initio_release_scb()
725 host->last_avail->next = cmnd; in initio_release_scb()
726 host->last_avail = cmnd; in initio_release_scb()
728 host->first_avail = cmnd; in initio_release_scb()
729 host->last_avail = cmnd; in initio_release_scb()
731 spin_unlock_irqrestore(&(host->avail_lock), flags); in initio_release_scb()
735 static void initio_append_pend_scb(struct initio_host * host, struct scsi_ctrl_blk * scbp) in initio_append_pend_scb() argument
743 if (host->last_pending != NULL) { in initio_append_pend_scb()
744 host->last_pending->next = scbp; in initio_append_pend_scb()
745 host->last_pending = scbp; in initio_append_pend_scb()
747 host->first_pending = scbp; in initio_append_pend_scb()
748 host->last_pending = scbp; in initio_append_pend_scb()
753 static void initio_push_pend_scb(struct initio_host * host, struct scsi_ctrl_blk * scbp) in initio_push_pend_scb() argument
760 if ((scbp->next = host->first_pending) != NULL) { in initio_push_pend_scb()
761 host->first_pending = scbp; in initio_push_pend_scb()
763 host->first_pending = scbp; in initio_push_pend_scb()
764 host->last_pending = scbp; in initio_push_pend_scb()
768 static struct scsi_ctrl_blk *initio_find_first_pend_scb(struct initio_host * host) in initio_find_first_pend_scb() argument
773 first = host->first_pending; in initio_find_first_pend_scb()
778 if ((host->act_tags[first->target] == 0) && in initio_find_first_pend_scb()
779 !(host->targets[first->target].flags & TCF_BUSY)) in initio_find_first_pend_scb()
782 if ((host->act_tags[first->target] >= in initio_find_first_pend_scb()
783 host->max_tags[first->target]) | in initio_find_first_pend_scb()
784 (host->targets[first->target].flags & TCF_BUSY)) { in initio_find_first_pend_scb()
795 static void initio_unlink_pend_scb(struct initio_host * host, struct scsi_ctrl_blk * scb) in initio_unlink_pend_scb() argument
803 prev = tmp = host->first_pending; in initio_unlink_pend_scb()
806 if (tmp == host->first_pending) { in initio_unlink_pend_scb()
807 if ((host->first_pending = tmp->next) == NULL) in initio_unlink_pend_scb()
808 host->last_pending = NULL; in initio_unlink_pend_scb()
811 if (tmp == host->last_pending) in initio_unlink_pend_scb()
812 host->last_pending = prev; in initio_unlink_pend_scb()
822 static void initio_append_busy_scb(struct initio_host * host, struct scsi_ctrl_blk * scbp) in initio_append_busy_scb() argument
829 host->act_tags[scbp->target]++; in initio_append_busy_scb()
831 host->targets[scbp->target].flags |= TCF_BUSY; in initio_append_busy_scb()
834 if (host->last_busy != NULL) { in initio_append_busy_scb()
835 host->last_busy->next = scbp; in initio_append_busy_scb()
836 host->last_busy = scbp; in initio_append_busy_scb()
838 host->first_busy = scbp; in initio_append_busy_scb()
839 host->last_busy = scbp; in initio_append_busy_scb()
844 static struct scsi_ctrl_blk *initio_pop_busy_scb(struct initio_host * host) in initio_pop_busy_scb() argument
849 if ((tmp = host->first_busy) != NULL) { in initio_pop_busy_scb()
850 if ((host->first_busy = tmp->next) == NULL) in initio_pop_busy_scb()
851 host->last_busy = NULL; in initio_pop_busy_scb()
854 host->act_tags[tmp->target]--; in initio_pop_busy_scb()
856 host->targets[tmp->target].flags &= ~TCF_BUSY; in initio_pop_busy_scb()
865 static void initio_unlink_busy_scb(struct initio_host * host, struct scsi_ctrl_blk * scb) in initio_unlink_busy_scb() argument
873 prev = tmp = host->first_busy; in initio_unlink_busy_scb()
876 if (tmp == host->first_busy) { in initio_unlink_busy_scb()
877 if ((host->first_busy = tmp->next) == NULL) in initio_unlink_busy_scb()
878 host->last_busy = NULL; in initio_unlink_busy_scb()
881 if (tmp == host->last_busy) in initio_unlink_busy_scb()
882 host->last_busy = prev; in initio_unlink_busy_scb()
886 host->act_tags[tmp->target]--; in initio_unlink_busy_scb()
888 host->targets[tmp->target].flags &= ~TCF_BUSY; in initio_unlink_busy_scb()
897 struct scsi_ctrl_blk *initio_find_busy_scb(struct initio_host * host, u16 tarlun) in initio_find_busy_scb() argument
903 prev = tmp = host->first_busy; in initio_find_busy_scb()
918 static void initio_append_done_scb(struct initio_host * host, struct scsi_ctrl_blk * scbp) in initio_append_done_scb() argument
926 if (host->last_done != NULL) { in initio_append_done_scb()
927 host->last_done->next = scbp; in initio_append_done_scb()
928 host->last_done = scbp; in initio_append_done_scb()
930 host->first_done = scbp; in initio_append_done_scb()
931 host->last_done = scbp; in initio_append_done_scb()
935 struct scsi_ctrl_blk *initio_find_done_scb(struct initio_host * host) in initio_find_done_scb() argument
939 if ((tmp = host->first_done) != NULL) { in initio_find_done_scb()
940 if ((host->first_done = tmp->next) == NULL) in initio_find_done_scb()
941 host->last_done = NULL; in initio_find_done_scb()
950 static int initio_abort_srb(struct initio_host * host, struct scsi_cmnd *srbp) in initio_abort_srb() argument
955 spin_lock_irqsave(&host->semaph_lock, flags); in initio_abort_srb()
957 if ((host->semaph == 0) && (host->active == NULL)) { in initio_abort_srb()
959 outb(0x1F, host->addr + TUL_Mask); in initio_abort_srb()
960 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_abort_srb()
962 tulip_main(host); in initio_abort_srb()
963 spin_lock_irqsave(&host->semaph_lock, flags); in initio_abort_srb()
964 host->semaph = 1; in initio_abort_srb()
965 outb(0x0F, host->addr + TUL_Mask); in initio_abort_srb()
966 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_abort_srb()
969 prev = tmp = host->first_pending; /* Check Pend queue */ in initio_abort_srb()
973 if (tmp == host->active) { in initio_abort_srb()
974 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_abort_srb()
976 } else if (tmp == host->first_pending) { in initio_abort_srb()
977 if ((host->first_pending = tmp->next) == NULL) in initio_abort_srb()
978 host->last_pending = NULL; in initio_abort_srb()
981 if (tmp == host->last_pending) in initio_abort_srb()
982 host->last_pending = prev; 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()
995 prev = tmp = host->first_busy; /* Check Busy queue */ in initio_abort_srb()
998 if (tmp == host->active) { in initio_abort_srb()
999 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_abort_srb()
1002 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_abort_srb()
1005 host->act_tags[tmp->target]--; in initio_abort_srb()
1006 if (tmp == host->first_busy) { in initio_abort_srb()
1007 if ((host->first_busy = tmp->next) == NULL) in initio_abort_srb()
1008 host->last_busy = NULL; in initio_abort_srb()
1011 if (tmp == host->last_busy) in initio_abort_srb()
1012 host->last_busy = prev; in initio_abort_srb()
1020 (*tmp->post) ((u8 *) host, (u8 *) tmp); in initio_abort_srb()
1021 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_abort_srb()
1028 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_abort_srb()
1033 static int initio_bad_seq(struct initio_host * host) in initio_bad_seq() argument
1037 printk("initio_bad_seg c=%d\n", host->index); in initio_bad_seq()
1039 if ((scb = host->active) != NULL) { in initio_bad_seq()
1040 initio_unlink_busy_scb(host, scb); in initio_bad_seq()
1043 initio_append_done_scb(host, scb); in initio_bad_seq()
1045 initio_stop_bm(host); in initio_bad_seq()
1046 initio_reset_scsi(host, 8); /* 7/29/98 */ in initio_bad_seq()
1047 return initio_post_scsi_rst(host); in initio_bad_seq()
1052 static void initio_exec_scb(struct initio_host * host, struct scsi_ctrl_blk * scb) in initio_exec_scb() argument
1061 spin_lock_irqsave(&host->semaph_lock, flags); in initio_exec_scb()
1063 initio_append_pend_scb(host, scb); /* Append this SCB to Pending queue */ in initio_exec_scb()
1066 if (host->semaph == 1) { in initio_exec_scb()
1068 outb(0x1F, host->addr + TUL_Mask); in initio_exec_scb()
1069 host->semaph = 0; in initio_exec_scb()
1070 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_exec_scb()
1072 tulip_main(host); in initio_exec_scb()
1074 spin_lock_irqsave(&host->semaph_lock, flags); in initio_exec_scb()
1075 host->semaph = 1; in initio_exec_scb()
1076 outb(0x0F, host->addr + TUL_Mask); in initio_exec_scb()
1078 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_exec_scb()
1083 static int initio_isr(struct initio_host * host) in initio_isr() argument
1085 if (inb(host->addr + TUL_Int) & TSS_INT_PENDING) { in initio_isr()
1086 if (host->semaph == 1) { in initio_isr()
1087 outb(0x1F, host->addr + TUL_Mask); in initio_isr()
1089 host->semaph = 0; in initio_isr()
1091 tulip_main(host); in initio_isr()
1093 host->semaph = 1; in initio_isr()
1094 outb(0x0F, host->addr + TUL_Mask); in initio_isr()
1101 static int tulip_main(struct initio_host * host) in tulip_main() argument
1106 tulip_scsi(host); /* Call tulip_scsi */ in tulip_main()
1109 while ((scb = initio_find_done_scb(host)) != NULL) { /* find done entry */ in tulip_main()
1111 host->max_tags[scb->target] = in tulip_main()
1112 host->act_tags[scb->target] - 1; in tulip_main()
1114 initio_append_pend_scb(host, scb); in tulip_main()
1143 initio_push_pend_scb(host, scb); in tulip_main()
1158 (*scb->post) ((u8 *) host, (u8 *) scb); in tulip_main()
1162 if (inb(host->addr + TUL_SStatus0) & TSS_INT_PENDING) in tulip_main()
1164 if (host->active) /* return to OS and wait for xfer_done_ISR/Selected_ISR */ in tulip_main()
1167 if (initio_find_first_pend_scb(host) == NULL) in tulip_main()
1173 static void tulip_scsi(struct initio_host * host) in tulip_scsi() argument
1179 if ((host->jsstatus0 = inb(host->addr + TUL_SStatus0)) & TSS_INT_PENDING) { in tulip_scsi()
1180 host->phase = host->jsstatus0 & TSS_PH_MASK; in tulip_scsi()
1181 host->jsstatus1 = inb(host->addr + TUL_SStatus1); in tulip_scsi()
1182 host->jsint = inb(host->addr + TUL_SInt); in tulip_scsi()
1183 if (host->jsint & TSS_SCSIRST_INT) { /* SCSI bus reset detected */ in tulip_scsi()
1184 int_initio_scsi_rst(host); in tulip_scsi()
1187 if (host->jsint & TSS_RESEL_INT) { /* if selected/reselected interrupt */ in tulip_scsi()
1188 if (int_initio_resel(host) == 0) in tulip_scsi()
1189 initio_next_state(host); in tulip_scsi()
1192 if (host->jsint & TSS_SEL_TIMEOUT) { in tulip_scsi()
1193 int_initio_busfree(host); in tulip_scsi()
1196 if (host->jsint & TSS_DISC_INT) { /* BUS disconnection */ in tulip_scsi()
1197 int_initio_busfree(host); /* unexpected bus free or sel timeout */ in tulip_scsi()
1200 if (host->jsint & (TSS_FUNC_COMP | TSS_BUS_SERV)) { /* func complete or Bus service */ in tulip_scsi()
1201 if ((scb = host->active) != NULL) in tulip_scsi()
1202 initio_next_state(host); in tulip_scsi()
1206 if (host->active != NULL) in tulip_scsi()
1209 if ((scb = initio_find_first_pend_scb(host)) == NULL) in tulip_scsi()
1213 outb((host->scsi_id << 4) | (scb->target & 0x0F), in tulip_scsi()
1214 host->addr + TUL_SScsiId); in tulip_scsi()
1216 active_tc = &host->targets[scb->target]; in tulip_scsi()
1223 outb(active_tc->js_period, host->addr + TUL_SPeriod); in tulip_scsi()
1225 initio_select_atn_stop(host, scb); in tulip_scsi()
1228 initio_select_atn_stop(host, scb); in tulip_scsi()
1231 initio_select_atn3(host, scb); in tulip_scsi()
1233 initio_select_atn(host, scb); in tulip_scsi()
1237 while (wait_tulip(host) != -1) { in tulip_scsi()
1238 if (initio_next_state(host) == -1) in tulip_scsi()
1243 initio_select_atn_stop(host, scb); in tulip_scsi()
1246 while (wait_tulip(host) != -1) { in tulip_scsi()
1247 if (initio_next_state(host) == -1) in tulip_scsi()
1252 if (initio_abort_srb(host, scb->srb) != 0) { in tulip_scsi()
1253 initio_unlink_pend_scb(host, scb); in tulip_scsi()
1254 initio_release_scb(host, scb); in tulip_scsi()
1257 initio_select_atn_stop(host, scb); in tulip_scsi()
1261 initio_unlink_pend_scb(host, scb); in tulip_scsi()
1263 initio_append_done_scb(host, scb); in tulip_scsi()
1278 static int initio_next_state(struct initio_host * host) in initio_next_state() argument
1282 next = host->active->next_state; in initio_next_state()
1286 next = initio_state_1(host); in initio_next_state()
1289 next = initio_state_2(host); in initio_next_state()
1292 next = initio_state_3(host); in initio_next_state()
1295 next = initio_state_4(host); in initio_next_state()
1298 next = initio_state_5(host); in initio_next_state()
1301 next = initio_state_6(host); in initio_next_state()
1304 next = initio_state_7(host); in initio_next_state()
1307 return initio_bus_device_reset(host); in initio_next_state()
1309 return initio_bad_seq(host); in initio_next_state()
1324 static int initio_state_1(struct initio_host * host) in initio_state_1() argument
1326 struct scsi_ctrl_blk *scb = host->active; in initio_state_1()
1327 struct target_control *active_tc = host->active_tc; in initio_state_1()
1333 initio_unlink_pend_scb(host, scb); in initio_state_1()
1334 initio_append_busy_scb(host, scb); in initio_state_1()
1336 outb(active_tc->sconfig0, host->addr + TUL_SConfig ); in initio_state_1()
1338 if (host->phase == MSG_OUT) { in initio_state_1()
1339 outb(TSC_EN_BUS_IN | TSC_HW_RESELECT, host->addr + TUL_SCtrl1); in initio_state_1()
1340 outb(scb->ident, host->addr + TUL_SFifo); in initio_state_1()
1343 outb(scb->tagmsg, host->addr + TUL_SFifo); in initio_state_1()
1344 outb(scb->tagid, host->addr + TUL_SFifo); in initio_state_1()
1348 outb(MSG_EXTEND, host->addr + TUL_SFifo); in initio_state_1()
1349 outb(2, host->addr + TUL_SFifo); /* Extended msg length */ in initio_state_1()
1350 outb(3, host->addr + TUL_SFifo); /* Sync request */ in initio_state_1()
1351 outb(1, host->addr + TUL_SFifo); /* Start from 16 bits */ in initio_state_1()
1354 outb(MSG_EXTEND, host->addr + TUL_SFifo); in initio_state_1()
1355 outb(3, host->addr + TUL_SFifo); /* extended msg length */ in initio_state_1()
1356 outb(1, host->addr + TUL_SFifo); /* sync request */ in initio_state_1()
1357 outb(initio_rate_tbl[active_tc->flags & TCF_SCSI_RATE], host->addr + TUL_SFifo); in initio_state_1()
1358 outb(MAX_OFFSET, host->addr + TUL_SFifo); /* REQ/ACK offset */ in initio_state_1()
1360 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_state_1()
1361 if (wait_tulip(host) == -1) in initio_state_1()
1364 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_state_1()
1365 outb((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)), host->addr + TUL_SSignal); in initio_state_1()
1379 static int initio_state_2(struct initio_host * host) in initio_state_2() argument
1381 struct scsi_ctrl_blk *scb = host->active; in initio_state_2()
1382 struct target_control *active_tc = host->active_tc; in initio_state_2()
1387 initio_unlink_pend_scb(host, scb); in initio_state_2()
1388 initio_append_busy_scb(host, scb); in initio_state_2()
1390 outb(active_tc->sconfig0, host->addr + TUL_SConfig); in initio_state_2()
1392 if (host->jsstatus1 & TSS_CMD_PH_CMP) in initio_state_2()
1395 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_state_2()
1396 outb((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)), host->addr + TUL_SSignal); in initio_state_2()
1408 static int initio_state_3(struct initio_host * host) in initio_state_3() argument
1410 struct scsi_ctrl_blk *scb = host->active; in initio_state_3()
1411 struct target_control *active_tc = host->active_tc; in initio_state_3()
1418 switch (host->phase) { in initio_state_3()
1421 outb(scb->cdb[i], host->addr + TUL_SFifo); in initio_state_3()
1422 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_state_3()
1423 if (wait_tulip(host) == -1) in initio_state_3()
1425 if (host->phase == CMD_OUT) in initio_state_3()
1426 return initio_bad_seq(host); in initio_state_3()
1431 if (initio_msgin(host) == -1) in initio_state_3()
1436 if (initio_status_msg(host) == -1) in initio_state_3()
1442 outb(MSG_NOP, host->addr + TUL_SFifo); /* msg nop */ in initio_state_3()
1443 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_state_3()
1444 if (wait_tulip(host) == -1) in initio_state_3()
1449 outb(MSG_EXTEND, host->addr + TUL_SFifo); in initio_state_3()
1450 outb(3, host->addr + TUL_SFifo); /* ext. msg len */ in initio_state_3()
1451 outb(1, host->addr + TUL_SFifo); /* sync request */ in initio_state_3()
1452 outb(initio_rate_tbl[active_tc->flags & TCF_SCSI_RATE], host->addr + TUL_SFifo); in initio_state_3()
1453 outb(MAX_OFFSET, host->addr + TUL_SFifo); /* REQ/ACK offset */ in initio_state_3()
1454 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_state_3()
1455 if (wait_tulip(host) == -1) in initio_state_3()
1457 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_state_3()
1458 outb(inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7), host->addr + TUL_SSignal); in initio_state_3()
1463 return initio_bad_seq(host); in initio_state_3()
1475 static int initio_state_4(struct initio_host * host) in initio_state_4() argument
1477 struct scsi_ctrl_blk *scb = host->active; in initio_state_4()
1489 switch (host->phase) { in initio_state_4()
1494 if ((initio_status_msg(host)) == -1) in initio_state_4()
1500 if (initio_msgin(host) == -1) in initio_state_4()
1505 if (host->jsstatus0 & TSS_PAR_ERROR) { in initio_state_4()
1508 if (initio_msgout_ide(host) == -1) in initio_state_4()
1512 outb(MSG_NOP, host->addr + TUL_SFifo); /* msg nop */ in initio_state_4()
1513 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_state_4()
1514 if (wait_tulip(host) == -1) in initio_state_4()
1520 return initio_xfer_data_in(host); in initio_state_4()
1523 return initio_xfer_data_out(host); in initio_state_4()
1526 return initio_bad_seq(host); in initio_state_4()
1539 static int initio_state_5(struct initio_host * host) in initio_state_5() argument
1541 struct scsi_ctrl_blk *scb = host->active; in initio_state_5()
1548 cnt = inl(host->addr + TUL_SCnt0) & 0x0FFFFFF; in initio_state_5()
1550 if (inb(host->addr + TUL_XCmd) & 0x20) { in initio_state_5()
1553 if (host->jsstatus0 & TSS_PAR_ERROR) in initio_state_5()
1555 if (inb(host->addr + TUL_XStatus) & XPEND) { /* DMA xfer pending, Send STOP */ in initio_state_5()
1557 outb(inb(host->addr + TUL_XCtrl) | 0x80, host->addr + TUL_XCtrl); in initio_state_5()
1559 while (inb(host->addr + TUL_XStatus) & XPEND) in initio_state_5()
1564 if ((inb(host->addr + TUL_SStatus1) & TSS_XFER_CMP) == 0) { in initio_state_5()
1565 if (host->active_tc->js_period & TSC_WIDE_SCSI) in initio_state_5()
1566 cnt += (inb(host->addr + TUL_SFifoCnt) & 0x1F) << 1; in initio_state_5()
1568 cnt += (inb(host->addr + TUL_SFifoCnt) & 0x1F); in initio_state_5()
1570 if (inb(host->addr + TUL_XStatus) & XPEND) { /* if DMA xfer is pending, abort DMA xfer */ in initio_state_5()
1571 outb(TAX_X_ABT, host->addr + TUL_XCmd); in initio_state_5()
1573 while ((inb(host->addr + TUL_Int) & XABT) == 0) in initio_state_5()
1576 if ((cnt == 1) && (host->phase == DATA_OUT)) { in initio_state_5()
1577 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_state_5()
1578 if (wait_tulip(host) == -1) in initio_state_5()
1582 if ((inb(host->addr + TUL_SStatus1) & TSS_XFER_CMP) == 0) in initio_state_5()
1583 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_state_5()
1628 static int initio_state_6(struct initio_host * host) in initio_state_6() argument
1630 struct scsi_ctrl_blk *scb = host->active; in initio_state_6()
1636 switch (host->phase) { in initio_state_6()
1638 if ((initio_status_msg(host)) == -1) in initio_state_6()
1644 if ((initio_msgin(host)) == -1) in initio_state_6()
1649 outb(MSG_NOP, host->addr + TUL_SFifo); /* msg nop */ in initio_state_6()
1650 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_state_6()
1651 if (wait_tulip(host) == -1) in initio_state_6()
1656 return initio_xpad_in(host); in initio_state_6()
1659 return initio_xpad_out(host); in initio_state_6()
1662 return initio_bad_seq(host); in initio_state_6()
1673 int initio_state_7(struct initio_host * host) in initio_state_7() argument
1681 cnt = inb(host->addr + TUL_SFifoCnt) & 0x1F; in initio_state_7()
1684 inb(host->addr + TUL_SFifo); in initio_state_7()
1686 switch (host->phase) { in initio_state_7()
1689 return initio_bad_seq(host); in initio_state_7()
1703 static int initio_xfer_data_in(struct initio_host * host) in initio_xfer_data_in() argument
1705 struct scsi_ctrl_blk *scb = host->active; in initio_xfer_data_in()
1710 outl(scb->buflen, host->addr + TUL_SCnt0); in initio_xfer_data_in()
1711 outb(TSC_XF_DMA_IN, host->addr + TUL_SCmd); /* 7/25/95 */ in initio_xfer_data_in()
1714 outl(((u32) scb->sglen) << 3, host->addr + TUL_XCntH); in initio_xfer_data_in()
1715 outl(scb->bufptr, host->addr + TUL_XAddH); in initio_xfer_data_in()
1716 outb(TAX_SG_IN, host->addr + TUL_XCmd); in initio_xfer_data_in()
1718 outl(scb->buflen, host->addr + TUL_XCntH); in initio_xfer_data_in()
1719 outl(scb->bufptr, host->addr + TUL_XAddH); in initio_xfer_data_in()
1720 outb(TAX_X_IN, host->addr + TUL_XCmd); in initio_xfer_data_in()
1735 static int initio_xfer_data_out(struct initio_host * host) in initio_xfer_data_out() argument
1737 struct scsi_ctrl_blk *scb = host->active; in initio_xfer_data_out()
1742 outl(scb->buflen, host->addr + TUL_SCnt0); in initio_xfer_data_out()
1743 outb(TSC_XF_DMA_OUT, host->addr + TUL_SCmd); in initio_xfer_data_out()
1746 outl(((u32) scb->sglen) << 3, host->addr + TUL_XCntH); in initio_xfer_data_out()
1747 outl(scb->bufptr, host->addr + TUL_XAddH); in initio_xfer_data_out()
1748 outb(TAX_SG_OUT, host->addr + TUL_XCmd); in initio_xfer_data_out()
1750 outl(scb->buflen, host->addr + TUL_XCntH); in initio_xfer_data_out()
1751 outl(scb->bufptr, host->addr + TUL_XAddH); in initio_xfer_data_out()
1752 outb(TAX_X_OUT, host->addr + TUL_XCmd); in initio_xfer_data_out()
1759 int initio_xpad_in(struct initio_host * host) in initio_xpad_in() argument
1761 struct scsi_ctrl_blk *scb = host->active; in initio_xpad_in()
1762 struct target_control *active_tc = host->active_tc; in initio_xpad_in()
1768 outl(2, host->addr + TUL_SCnt0); in initio_xpad_in()
1770 outl(1, host->addr + TUL_SCnt0); in initio_xpad_in()
1772 outb(TSC_XF_FIFO_IN, host->addr + TUL_SCmd); in initio_xpad_in()
1773 if (wait_tulip(host) == -1) in initio_xpad_in()
1775 if (host->phase != DATA_IN) { in initio_xpad_in()
1776 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_xpad_in()
1779 inb(host->addr + TUL_SFifo); in initio_xpad_in()
1783 int initio_xpad_out(struct initio_host * host) in initio_xpad_out() argument
1785 struct scsi_ctrl_blk *scb = host->active; in initio_xpad_out()
1786 struct target_control *active_tc = host->active_tc; in initio_xpad_out()
1792 outl(2, host->addr + TUL_SCnt0); in initio_xpad_out()
1794 outl(1, host->addr + TUL_SCnt0); in initio_xpad_out()
1796 outb(0, host->addr + TUL_SFifo); in initio_xpad_out()
1797 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_xpad_out()
1798 if ((wait_tulip(host)) == -1) in initio_xpad_out()
1800 if (host->phase != DATA_OUT) { /* Disable wide CPU to allow read 16 bits */ in initio_xpad_out()
1801 outb(TSC_HW_RESELECT, host->addr + TUL_SCtrl1); in initio_xpad_out()
1802 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_xpad_out()
1808 int initio_status_msg(struct initio_host * host) in initio_status_msg() argument
1810 struct scsi_ctrl_blk *scb = host->active; in initio_status_msg()
1813 outb(TSC_CMD_COMP, host->addr + TUL_SCmd); in initio_status_msg()
1814 if (wait_tulip(host) == -1) in initio_status_msg()
1818 scb->tastat = inb(host->addr + TUL_SFifo); in initio_status_msg()
1820 if (host->phase == MSG_OUT) { in initio_status_msg()
1821 if (host->jsstatus0 & TSS_PAR_ERROR) in initio_status_msg()
1822 outb(MSG_PARITY, host->addr + TUL_SFifo); in initio_status_msg()
1824 outb(MSG_NOP, host->addr + TUL_SFifo); in initio_status_msg()
1825 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_status_msg()
1826 return wait_tulip(host); in initio_status_msg()
1828 if (host->phase == MSG_IN) { in initio_status_msg()
1829 msg = inb(host->addr + TUL_SFifo); in initio_status_msg()
1830 if (host->jsstatus0 & TSS_PAR_ERROR) { /* Parity error */ in initio_status_msg()
1831 if ((initio_msgin_accept(host)) == -1) in initio_status_msg()
1833 if (host->phase != MSG_OUT) in initio_status_msg()
1834 return initio_bad_seq(host); in initio_status_msg()
1835 outb(MSG_PARITY, host->addr + TUL_SFifo); in initio_status_msg()
1836 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_status_msg()
1837 return wait_tulip(host); in initio_status_msg()
1842 return initio_bad_seq(host); in initio_status_msg()
1843 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_status_msg()
1844 outb(TSC_MSG_ACCEPT, host->addr + TUL_SCmd); in initio_status_msg()
1845 return initio_wait_done_disc(host); in initio_status_msg()
1850 return initio_msgin_accept(host); in initio_status_msg()
1853 return initio_bad_seq(host); in initio_status_msg()
1858 int int_initio_busfree(struct initio_host * host) in int_initio_busfree() argument
1860 struct scsi_ctrl_blk *scb = host->active; in int_initio_busfree()
1864 initio_unlink_pend_scb(host, scb); in int_initio_busfree()
1866 initio_append_done_scb(host, scb); in int_initio_busfree()
1868 initio_unlink_busy_scb(host, scb); in int_initio_busfree()
1870 initio_append_done_scb(host, scb); in int_initio_busfree()
1872 host->active = NULL; in int_initio_busfree()
1873 host->active_tc = NULL; in int_initio_busfree()
1875 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); /* Flush SCSI FIFO */ in int_initio_busfree()
1876 outb(TSC_INITDEFAULT, host->addr + TUL_SConfig); in int_initio_busfree()
1877 outb(TSC_HW_RESELECT, host->addr + TUL_SCtrl1); /* Enable HW reselect */ in int_initio_busfree()
1892 static int int_initio_scsi_rst(struct initio_host * host) in int_initio_scsi_rst() argument
1898 if (inb(host->addr + TUL_XStatus) & 0x01) { in int_initio_scsi_rst()
1899 outb(TAX_X_ABT | TAX_X_CLR_FIFO, host->addr + TUL_XCmd); in int_initio_scsi_rst()
1901 while ((inb(host->addr + TUL_Int) & 0x04) == 0) in int_initio_scsi_rst()
1903 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in int_initio_scsi_rst()
1906 while ((scb = initio_pop_busy_scb(host)) != NULL) { in int_initio_scsi_rst()
1908 initio_append_done_scb(host, scb); in int_initio_scsi_rst()
1910 host->active = NULL; in int_initio_scsi_rst()
1911 host->active_tc = NULL; in int_initio_scsi_rst()
1914 for (i = 0; i < host->max_tar; i++) in int_initio_scsi_rst()
1915 host->targets[i].flags &= ~(TCF_SYNC_DONE | TCF_WDTR_DONE); in int_initio_scsi_rst()
1928 int int_initio_resel(struct initio_host * host) in int_initio_resel() argument
1935 if ((scb = host->active) != NULL) { in int_initio_resel()
1939 host->active = NULL; in int_initio_resel()
1942 tar = inb(host->addr + TUL_SBusId); in int_initio_resel()
1944 lun = inb(host->addr + TUL_SIdent) & 0x0F; in int_initio_resel()
1946 active_tc = &host->targets[tar]; in int_initio_resel()
1947 host->active_tc = active_tc; in int_initio_resel()
1948 outb(active_tc->sconfig0, host->addr + TUL_SConfig); in int_initio_resel()
1949 outb(active_tc->js_period, host->addr + TUL_SPeriod); in int_initio_resel()
1953 if ((initio_msgin_accept(host)) == -1) in int_initio_resel()
1955 if (host->phase != MSG_IN) in int_initio_resel()
1957 outl(1, host->addr + TUL_SCnt0); in int_initio_resel()
1958 outb(TSC_XF_FIFO_IN, host->addr + TUL_SCmd); in int_initio_resel()
1959 if (wait_tulip(host) == -1) in int_initio_resel()
1961 msg = inb(host->addr + TUL_SFifo); /* Read Tag Message */ in int_initio_resel()
1966 if (initio_msgin_accept(host) == -1) in int_initio_resel()
1969 if (host->phase != MSG_IN) in int_initio_resel()
1972 outl(1, host->addr + TUL_SCnt0); in int_initio_resel()
1973 outb(TSC_XF_FIFO_IN, host->addr + TUL_SCmd); in int_initio_resel()
1974 if (wait_tulip(host) == -1) in int_initio_resel()
1976 tag = inb(host->addr + TUL_SFifo); /* Read Tag ID */ in int_initio_resel()
1977 scb = host->scb + tag; in int_initio_resel()
1979 return initio_msgout_abort_tag(host); in int_initio_resel()
1982 return initio_msgout_abort_tag(host); in int_initio_resel()
1984 host->active = scb; in int_initio_resel()
1985 if ((initio_msgin_accept(host)) == -1) in int_initio_resel()
1989 if ((scb = initio_find_busy_scb(host, tar | (lun << 8))) == NULL) { in int_initio_resel()
1990 return initio_msgout_abort_targ(host); in int_initio_resel()
1992 host->active = scb; in int_initio_resel()
1994 if ((initio_msgin_accept(host)) == -1) in int_initio_resel()
2009 static int int_initio_bad_seq(struct initio_host * host) in int_initio_bad_seq() argument
2014 initio_reset_scsi(host, 10); in int_initio_bad_seq()
2016 while ((scb = initio_pop_busy_scb(host)) != NULL) { in int_initio_bad_seq()
2018 initio_append_done_scb(host, scb); in int_initio_bad_seq()
2020 for (i = 0; i < host->max_tar; i++) in int_initio_bad_seq()
2021 host->targets[i].flags &= ~(TCF_SYNC_DONE | TCF_WDTR_DONE); in int_initio_bad_seq()
2034 static int initio_msgout_abort_targ(struct initio_host * host) in initio_msgout_abort_targ() argument
2037 …outb(((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)) | TSC_SET_ATN), host->addr + TUL_SSignal… in initio_msgout_abort_targ()
2038 if (initio_msgin_accept(host) == -1) in initio_msgout_abort_targ()
2040 if (host->phase != MSG_OUT) in initio_msgout_abort_targ()
2041 return initio_bad_seq(host); in initio_msgout_abort_targ()
2043 outb(MSG_ABORT, host->addr + TUL_SFifo); in initio_msgout_abort_targ()
2044 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_msgout_abort_targ()
2046 return initio_wait_disc(host); in initio_msgout_abort_targ()
2057 static int initio_msgout_abort_tag(struct initio_host * host) in initio_msgout_abort_tag() argument
2060 …outb(((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)) | TSC_SET_ATN), host->addr + TUL_SSignal… in initio_msgout_abort_tag()
2061 if (initio_msgin_accept(host) == -1) in initio_msgout_abort_tag()
2063 if (host->phase != MSG_OUT) in initio_msgout_abort_tag()
2064 return initio_bad_seq(host); in initio_msgout_abort_tag()
2066 outb(MSG_ABORT_TAG, host->addr + TUL_SFifo); in initio_msgout_abort_tag()
2067 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_msgout_abort_tag()
2069 return initio_wait_disc(host); in initio_msgout_abort_tag()
2079 static int initio_msgin(struct initio_host * host) in initio_msgin() argument
2084 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_msgin()
2086 outl(1, host->addr + TUL_SCnt0); in initio_msgin()
2087 outb(TSC_XF_FIFO_IN, host->addr + TUL_SCmd); in initio_msgin()
2088 if (wait_tulip(host) == -1) in initio_msgin()
2091 switch (inb(host->addr + TUL_SFifo)) { in initio_msgin()
2093 outb(TSC_MSG_ACCEPT, host->addr + TUL_SCmd); in initio_msgin()
2094 return initio_wait_disc(host); in initio_msgin()
2098 initio_msgin_accept(host); in initio_msgin()
2101 outb((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)), in initio_msgin()
2102 host->addr + TUL_SSignal); in initio_msgin()
2103 active_tc = host->active_tc; in initio_msgin()
2105 outb(((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)) | TSC_SET_ATN), in initio_msgin()
2106 host->addr + TUL_SSignal); in initio_msgin()
2107 initio_msgin_accept(host); in initio_msgin()
2110 initio_msgin_extend(host); in initio_msgin()
2113 initio_msgin_accept(host); in initio_msgin()
2116 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_msgin()
2117 outb(TSC_MSG_ACCEPT, host->addr + TUL_SCmd); in initio_msgin()
2118 return initio_wait_done_disc(host); in initio_msgin()
2120 initio_msgout_reject(host); in initio_msgin()
2123 if (host->phase != MSG_IN) in initio_msgin()
2124 return host->phase; in initio_msgin()
2129 static int initio_msgout_reject(struct initio_host * host) in initio_msgout_reject() argument
2131 …outb(((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)) | TSC_SET_ATN), host->addr + TUL_SSignal… in initio_msgout_reject()
2133 if (initio_msgin_accept(host) == -1) in initio_msgout_reject()
2136 if (host->phase == MSG_OUT) { in initio_msgout_reject()
2137 outb(MSG_REJ, host->addr + TUL_SFifo); /* Msg reject */ in initio_msgout_reject()
2138 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_msgout_reject()
2139 return wait_tulip(host); in initio_msgout_reject()
2141 return host->phase; in initio_msgout_reject()
2144 static int initio_msgout_ide(struct initio_host * host) in initio_msgout_ide() argument
2146 outb(MSG_IDE, host->addr + TUL_SFifo); /* Initiator Detected Error */ in initio_msgout_ide()
2147 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_msgout_ide()
2148 return wait_tulip(host); in initio_msgout_ide()
2151 static int initio_msgin_extend(struct initio_host * host) in initio_msgin_extend() argument
2155 if (initio_msgin_accept(host) != MSG_IN) in initio_msgin_extend()
2156 return host->phase; in initio_msgin_extend()
2159 outl(1, host->addr + TUL_SCnt0); in initio_msgin_extend()
2160 outb(TSC_XF_FIFO_IN, host->addr + TUL_SCmd); in initio_msgin_extend()
2161 if (wait_tulip(host) == -1) in initio_msgin_extend()
2164 len = inb(host->addr + TUL_SFifo); in initio_msgin_extend()
2165 host->msg[0] = len; in initio_msgin_extend()
2168 if ((initio_msgin_accept(host)) != MSG_IN) in initio_msgin_extend()
2169 return host->phase; in initio_msgin_extend()
2170 outl(1, host->addr + TUL_SCnt0); in initio_msgin_extend()
2171 outb(TSC_XF_FIFO_IN, host->addr + TUL_SCmd); in initio_msgin_extend()
2172 if (wait_tulip(host) == -1) in initio_msgin_extend()
2174 host->msg[idx++] = inb(host->addr + TUL_SFifo); in initio_msgin_extend()
2176 if (host->msg[1] == 1) { /* if it's synchronous data transfer request */ in initio_msgin_extend()
2178 if (host->msg[0] != 3) /* if length is not right */ in initio_msgin_extend()
2179 return initio_msgout_reject(host); in initio_msgin_extend()
2180 if (host->active_tc->flags & TCF_NO_SYNC_NEGO) { /* Set OFFSET=0 to do async, nego back */ in initio_msgin_extend()
2181 host->msg[3] = 0; in initio_msgin_extend()
2183 if (initio_msgin_sync(host) == 0 && in initio_msgin_extend()
2184 (host->active_tc->flags & TCF_SYNC_DONE)) { in initio_msgin_extend()
2185 initio_sync_done(host); in initio_msgin_extend()
2186 return initio_msgin_accept(host); in initio_msgin_extend()
2190 r = inb(host->addr + TUL_SSignal); in initio_msgin_extend()
2192 host->addr + TUL_SSignal); in initio_msgin_extend()
2193 if (initio_msgin_accept(host) != MSG_OUT) in initio_msgin_extend()
2194 return host->phase; in initio_msgin_extend()
2196 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_msgin_extend()
2198 initio_sync_done(host); in initio_msgin_extend()
2200 outb(MSG_EXTEND, host->addr + TUL_SFifo); in initio_msgin_extend()
2201 outb(3, host->addr + TUL_SFifo); in initio_msgin_extend()
2202 outb(1, host->addr + TUL_SFifo); in initio_msgin_extend()
2203 outb(host->msg[2], host->addr + TUL_SFifo); in initio_msgin_extend()
2204 outb(host->msg[3], host->addr + TUL_SFifo); in initio_msgin_extend()
2205 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_msgin_extend()
2206 return wait_tulip(host); in initio_msgin_extend()
2208 if (host->msg[0] != 2 || host->msg[1] != 3) in initio_msgin_extend()
2209 return initio_msgout_reject(host); in initio_msgin_extend()
2211 if (host->active_tc->flags & TCF_NO_WDTR) { in initio_msgin_extend()
2212 host->msg[2] = 0; in initio_msgin_extend()
2214 if (host->msg[2] > 2) /* > 32 bits */ in initio_msgin_extend()
2215 return initio_msgout_reject(host); in initio_msgin_extend()
2216 if (host->msg[2] == 2) { /* == 32 */ in initio_msgin_extend()
2217 host->msg[2] = 1; in initio_msgin_extend()
2219 if ((host->active_tc->flags & TCF_NO_WDTR) == 0) { in initio_msgin_extend()
2220 wdtr_done(host); in initio_msgin_extend()
2221 if ((host->active_tc->flags & (TCF_SYNC_DONE | TCF_NO_SYNC_NEGO)) == 0) in initio_msgin_extend()
2222 …outb(((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)) | TSC_SET_ATN), host->addr + TUL_SSignal… in initio_msgin_extend()
2223 return initio_msgin_accept(host); in initio_msgin_extend()
2227 …outb(((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)) | TSC_SET_ATN), host->addr + TUL_SSignal… in initio_msgin_extend()
2229 if (initio_msgin_accept(host) != MSG_OUT) in initio_msgin_extend()
2230 return host->phase; in initio_msgin_extend()
2232 outb(MSG_EXTEND, host->addr + TUL_SFifo); in initio_msgin_extend()
2233 outb(2, host->addr + TUL_SFifo); in initio_msgin_extend()
2234 outb(3, host->addr + TUL_SFifo); in initio_msgin_extend()
2235 outb(host->msg[2], host->addr + TUL_SFifo); in initio_msgin_extend()
2236 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_msgin_extend()
2237 return wait_tulip(host); in initio_msgin_extend()
2240 static int initio_msgin_sync(struct initio_host * host) in initio_msgin_sync() argument
2244 default_period = initio_rate_tbl[host->active_tc->flags & TCF_SCSI_RATE]; in initio_msgin_sync()
2245 if (host->msg[3] > MAX_OFFSET) { in initio_msgin_sync()
2246 host->msg[3] = MAX_OFFSET; in initio_msgin_sync()
2247 if (host->msg[2] < default_period) { in initio_msgin_sync()
2248 host->msg[2] = default_period; in initio_msgin_sync()
2251 if (host->msg[2] >= 59) /* Change to async */ in initio_msgin_sync()
2252 host->msg[3] = 0; in initio_msgin_sync()
2256 if (host->msg[3] == 0) { in initio_msgin_sync()
2259 if (host->msg[2] < default_period) { in initio_msgin_sync()
2260 host->msg[2] = default_period; in initio_msgin_sync()
2263 if (host->msg[2] >= 59) { in initio_msgin_sync()
2264 host->msg[3] = 0; in initio_msgin_sync()
2270 static int wdtr_done(struct initio_host * host) in wdtr_done() argument
2272 host->active_tc->flags &= ~TCF_SYNC_DONE; in wdtr_done()
2273 host->active_tc->flags |= TCF_WDTR_DONE; in wdtr_done()
2275 host->active_tc->js_period = 0; in wdtr_done()
2276 if (host->msg[2]) /* if 16 bit */ in wdtr_done()
2277 host->active_tc->js_period |= TSC_WIDE_SCSI; in wdtr_done()
2278 host->active_tc->sconfig0 &= ~TSC_ALT_PERIOD; in wdtr_done()
2279 outb(host->active_tc->sconfig0, host->addr + TUL_SConfig); in wdtr_done()
2280 outb(host->active_tc->js_period, host->addr + TUL_SPeriod); in wdtr_done()
2285 static int initio_sync_done(struct initio_host * host) in initio_sync_done() argument
2289 host->active_tc->flags |= TCF_SYNC_DONE; in initio_sync_done()
2291 if (host->msg[3]) { in initio_sync_done()
2292 host->active_tc->js_period |= host->msg[3]; in initio_sync_done()
2294 if (initio_rate_tbl[i] >= host->msg[2]) /* pick the big one */ in initio_sync_done()
2297 host->active_tc->js_period |= (i << 4); in initio_sync_done()
2298 host->active_tc->sconfig0 |= TSC_ALT_PERIOD; in initio_sync_done()
2300 outb(host->active_tc->sconfig0, host->addr + TUL_SConfig); in initio_sync_done()
2301 outb(host->active_tc->js_period, host->addr + TUL_SPeriod); in initio_sync_done()
2307 static int initio_post_scsi_rst(struct initio_host * host) in initio_post_scsi_rst() argument
2313 host->active = NULL; in initio_post_scsi_rst()
2314 host->active_tc = NULL; in initio_post_scsi_rst()
2315 host->flags = 0; in initio_post_scsi_rst()
2317 while ((scb = initio_pop_busy_scb(host)) != NULL) { in initio_post_scsi_rst()
2319 initio_append_done_scb(host, scb); in initio_post_scsi_rst()
2322 active_tc = &host->targets[0]; in initio_post_scsi_rst()
2323 for (i = 0; i < host->max_tar; active_tc++, i++) { in initio_post_scsi_rst()
2327 active_tc->sconfig0 = host->sconf1; in initio_post_scsi_rst()
2328 host->act_tags[0] = 0; /* 07/22/98 */ in initio_post_scsi_rst()
2329 host->targets[i].flags &= ~TCF_BUSY; /* 07/22/98 */ in initio_post_scsi_rst()
2335 static void initio_select_atn_stop(struct initio_host * host, struct scsi_ctrl_blk * scb) in initio_select_atn_stop() argument
2339 host->active = scb; in initio_select_atn_stop()
2340 host->active_tc = &host->targets[scb->target]; in initio_select_atn_stop()
2341 outb(TSC_SELATNSTOP, host->addr + TUL_SCmd); in initio_select_atn_stop()
2345 static void initio_select_atn(struct initio_host * host, struct scsi_ctrl_blk * scb) in initio_select_atn() argument
2352 outb(scb->ident, host->addr + TUL_SFifo); in initio_select_atn()
2354 outb(scb->cdb[i], host->addr + TUL_SFifo); in initio_select_atn()
2355 host->active_tc = &host->targets[scb->target]; in initio_select_atn()
2356 host->active = scb; in initio_select_atn()
2357 outb(TSC_SEL_ATN, host->addr + TUL_SCmd); in initio_select_atn()
2360 static void initio_select_atn3(struct initio_host * host, struct scsi_ctrl_blk * scb) in initio_select_atn3() argument
2367 outb(scb->ident, host->addr + TUL_SFifo); in initio_select_atn3()
2368 outb(scb->tagmsg, host->addr + TUL_SFifo); in initio_select_atn3()
2369 outb(scb->tagid, host->addr + TUL_SFifo); in initio_select_atn3()
2371 outb(scb->cdb[i], host->addr + TUL_SFifo); in initio_select_atn3()
2372 host->active_tc = &host->targets[scb->target]; in initio_select_atn3()
2373 host->active = scb; in initio_select_atn3()
2374 outb(TSC_SEL_ATN3, host->addr + TUL_SCmd); in initio_select_atn3()
2384 int initio_bus_device_reset(struct initio_host * host) in initio_bus_device_reset() argument
2386 struct scsi_ctrl_blk *scb = host->active; in initio_bus_device_reset()
2387 struct target_control *active_tc = host->active_tc; in initio_bus_device_reset()
2391 if (host->phase != MSG_OUT) in initio_bus_device_reset()
2392 return int_initio_bad_seq(host); /* Unexpected phase */ in initio_bus_device_reset()
2394 initio_unlink_pend_scb(host, scb); in initio_bus_device_reset()
2395 initio_release_scb(host, scb); in initio_bus_device_reset()
2403 prev = tmp = host->first_busy; /* Check Busy queue */ in initio_bus_device_reset()
2407 if (tmp == host->first_busy) { in initio_bus_device_reset()
2408 if ((host->first_busy = tmp->next) == NULL) in initio_bus_device_reset()
2409 host->last_busy = NULL; in initio_bus_device_reset()
2412 if (tmp == host->last_busy) in initio_bus_device_reset()
2413 host->last_busy = prev; in initio_bus_device_reset()
2416 initio_append_done_scb(host, tmp); in initio_bus_device_reset()
2424 outb(MSG_DEVRST, host->addr + TUL_SFifo); in initio_bus_device_reset()
2425 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_bus_device_reset()
2426 return initio_wait_disc(host); in initio_bus_device_reset()
2430 static int initio_msgin_accept(struct initio_host * host) in initio_msgin_accept() argument
2432 outb(TSC_MSG_ACCEPT, host->addr + TUL_SCmd); in initio_msgin_accept()
2433 return wait_tulip(host); in initio_msgin_accept()
2436 static int wait_tulip(struct initio_host * host) in wait_tulip() argument
2439 while (!((host->jsstatus0 = inb(host->addr + TUL_SStatus0)) in wait_tulip()
2443 host->jsint = inb(host->addr + TUL_SInt); in wait_tulip()
2444 host->phase = host->jsstatus0 & TSS_PH_MASK; in wait_tulip()
2445 host->jsstatus1 = inb(host->addr + TUL_SStatus1); in wait_tulip()
2447 if (host->jsint & TSS_RESEL_INT) /* if SCSI bus reset detected */ in wait_tulip()
2448 return int_initio_resel(host); in wait_tulip()
2449 if (host->jsint & TSS_SEL_TIMEOUT) /* if selected/reselected timeout interrupt */ in wait_tulip()
2450 return int_initio_busfree(host); in wait_tulip()
2451 if (host->jsint & TSS_SCSIRST_INT) /* if SCSI bus reset detected */ in wait_tulip()
2452 return int_initio_scsi_rst(host); in wait_tulip()
2454 if (host->jsint & TSS_DISC_INT) { /* BUS disconnection */ in wait_tulip()
2455 if (host->flags & HCF_EXPECT_DONE_DISC) { in wait_tulip()
2456 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); /* Flush SCSI FIFO */ in wait_tulip()
2457 initio_unlink_busy_scb(host, host->active); in wait_tulip()
2458 host->active->hastat = 0; in wait_tulip()
2459 initio_append_done_scb(host, host->active); in wait_tulip()
2460 host->active = NULL; in wait_tulip()
2461 host->active_tc = NULL; in wait_tulip()
2462 host->flags &= ~HCF_EXPECT_DONE_DISC; in wait_tulip()
2463 outb(TSC_INITDEFAULT, host->addr + TUL_SConfig); in wait_tulip()
2464 outb(TSC_HW_RESELECT, host->addr + TUL_SCtrl1); /* Enable HW reselect */ in wait_tulip()
2467 if (host->flags & HCF_EXPECT_DISC) { in wait_tulip()
2468 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); /* Flush SCSI FIFO */ in wait_tulip()
2469 host->active = NULL; in wait_tulip()
2470 host->active_tc = NULL; in wait_tulip()
2471 host->flags &= ~HCF_EXPECT_DISC; in wait_tulip()
2472 outb(TSC_INITDEFAULT, host->addr + TUL_SConfig); in wait_tulip()
2473 outb(TSC_HW_RESELECT, host->addr + TUL_SCtrl1); /* Enable HW reselect */ in wait_tulip()
2476 return int_initio_busfree(host); in wait_tulip()
2479 if (host->jsint & (TSS_FUNC_COMP | TSS_BUS_SERV)) in wait_tulip()
2480 return host->phase; in wait_tulip()
2481 return host->phase; in wait_tulip()
2484 static int initio_wait_disc(struct initio_host * host) in initio_wait_disc() argument
2486 while (!((host->jsstatus0 = inb(host->addr + TUL_SStatus0)) & TSS_INT_PENDING)) in initio_wait_disc()
2489 host->jsint = inb(host->addr + TUL_SInt); in initio_wait_disc()
2491 if (host->jsint & TSS_SCSIRST_INT) /* if SCSI bus reset detected */ in initio_wait_disc()
2492 return int_initio_scsi_rst(host); in initio_wait_disc()
2493 if (host->jsint & TSS_DISC_INT) { /* BUS disconnection */ in initio_wait_disc()
2494 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); /* Flush SCSI FIFO */ in initio_wait_disc()
2495 outb(TSC_INITDEFAULT, host->addr + TUL_SConfig); in initio_wait_disc()
2496 outb(TSC_HW_RESELECT, host->addr + TUL_SCtrl1); /* Enable HW reselect */ in initio_wait_disc()
2497 host->active = NULL; in initio_wait_disc()
2500 return initio_bad_seq(host); in initio_wait_disc()
2503 static int initio_wait_done_disc(struct initio_host * host) in initio_wait_done_disc() argument
2505 while (!((host->jsstatus0 = inb(host->addr + TUL_SStatus0)) in initio_wait_done_disc()
2509 host->jsint = inb(host->addr + TUL_SInt); in initio_wait_done_disc()
2511 if (host->jsint & TSS_SCSIRST_INT) /* if SCSI bus reset detected */ in initio_wait_done_disc()
2512 return int_initio_scsi_rst(host); in initio_wait_done_disc()
2513 if (host->jsint & TSS_DISC_INT) { /* BUS disconnection */ in initio_wait_done_disc()
2514 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); /* Flush SCSI FIFO */ in initio_wait_done_disc()
2515 outb(TSC_INITDEFAULT, host->addr + TUL_SConfig); in initio_wait_done_disc()
2516 outb(TSC_HW_RESELECT, host->addr + TUL_SCtrl1); /* Enable HW reselect */ in initio_wait_done_disc()
2517 initio_unlink_busy_scb(host, host->active); in initio_wait_done_disc()
2519 initio_append_done_scb(host, host->active); in initio_wait_done_disc()
2520 host->active = NULL; in initio_wait_done_disc()
2523 return initio_bad_seq(host); in initio_wait_done_disc()
2562 static void initio_build_scb(struct initio_host * host, struct scsi_ctrl_blk * cblk, struct scsi_cm… in initio_build_scb() argument
2582 dma_addr = dma_map_single(&host->pci_dev->dev, cmnd->sense_buffer, in initio_build_scb()
2606 dma_addr = dma_map_single(&host->pci_dev->dev, &cblk->sglist[0], in initio_build_scb()
2645 struct initio_host *host = (struct initio_host *) cmd->device->host->hostdata; in i91u_queuecommand_lck() local
2650 cmnd = initio_alloc_scb(host); in i91u_queuecommand_lck()
2654 initio_build_scb(host, cmnd, cmd); in i91u_queuecommand_lck()
2655 initio_exec_scb(host, cmnd); in i91u_queuecommand_lck()
2670 struct initio_host *host; in DEF_SCSI_QCMD() local
2672 host = (struct initio_host *) cmnd->device->host->hostdata; in DEF_SCSI_QCMD()
2674 spin_lock_irq(cmnd->device->host->host_lock); in DEF_SCSI_QCMD()
2675 initio_reset_scsi(host, 0); in DEF_SCSI_QCMD()
2676 spin_unlock_irq(cmnd->device->host->host_lock); in DEF_SCSI_QCMD()
2697 struct initio_host *host; /* Point to Host adapter control block */ in i91u_biosparam() local
2700 host = (struct initio_host *) sdev->host->hostdata; in i91u_biosparam()
2701 tc = &host->targets[sdev->id]; in i91u_biosparam()
2771 struct initio_host *host; in i91uSCBPost() local
2774 host = (struct initio_host *) host_mem; in i91uSCBPost()
2779 initio_release_scb(host, cblk); /* Release SCB for current channel */ in i91uSCBPost()
2822 i91u_unmap_scb(host->pci_dev, cmnd); in i91uSCBPost()
2824 initio_release_scb(host, cblk); /* Release SCB for current channel */ in i91uSCBPost()
2843 struct initio_host *host; in initio_probe_one() local
2870 host = (struct initio_host *)shost->hostdata; in initio_probe_one()
2871 memset(host, 0, sizeof(struct initio_host)); in initio_probe_one()
2872 host->addr = pci_resource_start(pdev, 0); in initio_probe_one()
2873 host->bios_addr = bios_seg; in initio_probe_one()
2875 if (!request_region(host->addr, 256, "i91u")) { in initio_probe_one()
2876 printk(KERN_WARNING "initio: I/O port range 0x%x is busy.\n", host->addr); in initio_probe_one()
2898 host->pci_dev = pdev; in initio_probe_one()
2900 host->semaph = 1; in initio_probe_one()
2901 spin_lock_init(&host->semaph_lock); in initio_probe_one()
2902 host->num_scbs = num_scb; in initio_probe_one()
2903 host->scb = scb; in initio_probe_one()
2904 host->next_pending = scb; in initio_probe_one()
2905 host->next_avail = scb; in initio_probe_one()
2913 host->scb_end = tmp; in initio_probe_one()
2914 host->first_avail = scb; in initio_probe_one()
2915 host->last_avail = prev; in initio_probe_one()
2916 spin_lock_init(&host->avail_lock); in initio_probe_one()
2918 initio_init(host, phys_to_virt(((u32)bios_seg << 4))); in initio_probe_one()
2920 host->jsstatus0 = 0; in initio_probe_one()
2922 shost->io_port = host->addr; in initio_probe_one()
2925 shost->unique_id = host->addr; in initio_probe_one()
2926 shost->max_id = host->max_tar; in initio_probe_one()
2929 shost->this_id = host->scsi_id; /* Assign HCS index */ in initio_probe_one()
2930 shost->base = host->addr; in initio_probe_one()
2949 kfree(host->scb); in initio_probe_one()
2951 release_region(host->addr, 256); in initio_probe_one()
2969 struct Scsi_Host *host = pci_get_drvdata(pdev); in initio_remove_one() local
2970 struct initio_host *s = (struct initio_host *)host->hostdata; in initio_remove_one()
2971 scsi_remove_host(host); in initio_remove_one()
2972 free_irq(pdev->irq, host); in initio_remove_one()
2974 scsi_host_put(host); in initio_remove_one()