Lines Matching refs:host

117 static struct scsi_ctrl_blk *initio_find_busy_scb(struct initio_host * host, u16 tarlun);
118 static struct scsi_ctrl_blk *initio_find_done_scb(struct initio_host * host);
120 static int tulip_main(struct initio_host * host);
122 static int initio_next_state(struct initio_host * host);
123 static int initio_state_1(struct initio_host * host);
124 static int initio_state_2(struct initio_host * host);
125 static int initio_state_3(struct initio_host * host);
126 static int initio_state_4(struct initio_host * host);
127 static int initio_state_5(struct initio_host * host);
128 static int initio_state_6(struct initio_host * host);
129 static int initio_state_7(struct initio_host * host);
130 static int initio_xfer_data_in(struct initio_host * host);
131 static int initio_xfer_data_out(struct initio_host * host);
132 static int initio_xpad_in(struct initio_host * host);
133 static int initio_xpad_out(struct initio_host * host);
134 static int initio_status_msg(struct initio_host * host);
136 static int initio_msgin(struct initio_host * host);
137 static int initio_msgin_sync(struct initio_host * host);
138 static int initio_msgin_accept(struct initio_host * host);
139 static int initio_msgout_reject(struct initio_host * host);
140 static int initio_msgin_extend(struct initio_host * host);
142 static int initio_msgout_ide(struct initio_host * host);
143 static int initio_msgout_abort_targ(struct initio_host * host);
144 static int initio_msgout_abort_tag(struct initio_host * host);
146 static int initio_bus_device_reset(struct initio_host * host);
147 static void initio_select_atn(struct initio_host * host, struct scsi_ctrl_blk * scb);
148 static void initio_select_atn3(struct initio_host * host, struct scsi_ctrl_blk * scb);
149 static void initio_select_atn_stop(struct initio_host * host, struct scsi_ctrl_blk * scb);
150 static int int_initio_busfree(struct initio_host * host);
151 static int int_initio_scsi_rst(struct initio_host * host);
152 static int int_initio_bad_seq(struct initio_host * host);
153 static int int_initio_resel(struct initio_host * host);
154 static int initio_sync_done(struct initio_host * host);
155 static int wdtr_done(struct initio_host * host);
156 static int wait_tulip(struct initio_host * host);
157 static int initio_wait_done_disc(struct initio_host * host);
158 static int initio_wait_disc(struct initio_host * host);
159 static void tulip_scsi(struct initio_host * host);
160 static int initio_post_scsi_rst(struct initio_host * host);
507 static void initio_stop_bm(struct initio_host * host) in initio_stop_bm() argument
510 if (inb(host->addr + TUL_XStatus) & XPEND) { /* if DMA xfer is pending, abort DMA xfer */ in initio_stop_bm()
511 outb(TAX_X_ABT | TAX_X_CLR_FIFO, host->addr + TUL_XCmd); in initio_stop_bm()
513 while ((inb(host->addr + TUL_Int) & XABT) == 0) in initio_stop_bm()
516 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_stop_bm()
527 static int initio_reset_scsi(struct initio_host * host, int seconds) in initio_reset_scsi() argument
529 outb(TSC_RST_BUS, host->addr + TUL_SCtrl0); in initio_reset_scsi()
531 while (!((host->jsint = inb(host->addr + TUL_SInt)) & TSS_SCSIRST_INT)) in initio_reset_scsi()
535 outb(0, host->addr + TUL_SSignal); in initio_reset_scsi()
542 inb(host->addr + TUL_SInt); in initio_reset_scsi()
558 static void initio_init(struct initio_host * host, u8 *bios_addr) in initio_init() argument
565 initio_read_eeprom(host->addr); in initio_init()
567 host->max_tar = 8; in initio_init()
569 host->max_tar = 16; in initio_init()
571 host->config = i91unvramp->NVM_SCSIInfo[0].NVM_ChConfig1; in initio_init()
573 host->scsi_id = i91unvramp->NVM_SCSIInfo[0].NVM_ChSCSIID; in initio_init()
574 host->idmask = ~(1 << host->scsi_id); in initio_init()
578 outb(inb(host->addr + TUL_PCMD) | 0x40, host->addr + TUL_PCMD); in initio_init()
582 outb(0x1F, host->addr + TUL_Mask); in initio_init()
584 initio_stop_bm(host); in initio_init()
586 outb(TSC_RST_CHIP, host->addr + TUL_SCtrl0); in initio_init()
589 outb(host->scsi_id << 4, host->addr + TUL_SScsiId); in initio_init()
593 if (host->config & HCC_EN_PAR) in initio_init()
594 host->sconf1 = (TSC_INITDEFAULT | TSC_EN_SCSI_PAR); in initio_init()
596 host->sconf1 = (TSC_INITDEFAULT); in initio_init()
597 outb(host->sconf1, host->addr + TUL_SConfig); in initio_init()
600 outb(TSC_HW_RESELECT, host->addr + TUL_SCtrl1); in initio_init()
602 outb(0, host->addr + TUL_SPeriod); in initio_init()
605 outb(153, host->addr + TUL_STimeOut); in initio_init()
608 outb((host->config & (HCC_ACT_TERM1 | HCC_ACT_TERM2)), in initio_init()
609 host->addr + TUL_XCtrl); in initio_init()
610 outb(((host->config & HCC_AUTO_TERM) >> 4) | in initio_init()
611 (inb(host->addr + TUL_GCTRL1) & 0xFE), in initio_init()
612 host->addr + TUL_GCTRL1); in initio_init()
617 i < host->max_tar; in initio_init()
619 host->targets[i].flags = *flags & ~(TCF_SYNC_DONE | TCF_WDTR_DONE); in initio_init()
620 if (host->targets[i].flags & TCF_EN_255) in initio_init()
621 host->targets[i].drv_flags = TCF_DRV_255_63; in initio_init()
623 host->targets[i].drv_flags = 0; in initio_init()
624 host->targets[i].js_period = 0; in initio_init()
625 host->targets[i].sconfig0 = host->sconf1; in initio_init()
626 host->targets[i].heads = *heads++; in initio_init()
627 if (host->targets[i].heads == 255) in initio_init()
628 host->targets[i].drv_flags = TCF_DRV_255_63; in initio_init()
630 host->targets[i].drv_flags = 0; in initio_init()
631 host->targets[i].sectors = *heads++; in initio_init()
632 host->targets[i].flags &= ~TCF_BUSY; in initio_init()
633 host->act_tags[i] = 0; in initio_init()
634 host->max_tags[i] = 0xFF; in initio_init()
637 host->addr, host->pci_dev->irq, in initio_init()
638 host->bios_addr, host->scsi_id); in initio_init()
640 if (host->config & HCC_SCSI_RESET) { in initio_init()
642 initio_reset_scsi(host, 10); in initio_init()
644 outb(0x17, host->addr + TUL_SCFG1); in initio_init()
645 outb(0xE9, host->addr + TUL_SIntEnable); in initio_init()
655 static struct scsi_ctrl_blk *initio_alloc_scb(struct initio_host *host) in initio_alloc_scb() argument
660 spin_lock_irqsave(&host->avail_lock, flags); in initio_alloc_scb()
661 if ((scb = host->first_avail) != NULL) { in initio_alloc_scb()
665 if ((host->first_avail = scb->next) == NULL) in initio_alloc_scb()
666 host->last_avail = NULL; in initio_alloc_scb()
670 spin_unlock_irqrestore(&host->avail_lock, flags); in initio_alloc_scb()
682 static void initio_release_scb(struct initio_host * host, struct scsi_ctrl_blk * cmnd) in initio_release_scb() argument
689 spin_lock_irqsave(&(host->avail_lock), flags); in initio_release_scb()
693 if (host->last_avail != NULL) { in initio_release_scb()
694 host->last_avail->next = cmnd; in initio_release_scb()
695 host->last_avail = cmnd; in initio_release_scb()
697 host->first_avail = cmnd; in initio_release_scb()
698 host->last_avail = cmnd; in initio_release_scb()
700 spin_unlock_irqrestore(&(host->avail_lock), flags); in initio_release_scb()
704 static void initio_append_pend_scb(struct initio_host * host, struct scsi_ctrl_blk * scbp) in initio_append_pend_scb() argument
712 if (host->last_pending != NULL) { in initio_append_pend_scb()
713 host->last_pending->next = scbp; in initio_append_pend_scb()
714 host->last_pending = scbp; in initio_append_pend_scb()
716 host->first_pending = scbp; in initio_append_pend_scb()
717 host->last_pending = scbp; in initio_append_pend_scb()
722 static void initio_push_pend_scb(struct initio_host * host, struct scsi_ctrl_blk * scbp) in initio_push_pend_scb() argument
729 if ((scbp->next = host->first_pending) != NULL) { in initio_push_pend_scb()
730 host->first_pending = scbp; in initio_push_pend_scb()
732 host->first_pending = scbp; in initio_push_pend_scb()
733 host->last_pending = scbp; in initio_push_pend_scb()
737 static struct scsi_ctrl_blk *initio_find_first_pend_scb(struct initio_host * host) in initio_find_first_pend_scb() argument
742 first = host->first_pending; in initio_find_first_pend_scb()
747 if ((host->act_tags[first->target] == 0) && in initio_find_first_pend_scb()
748 !(host->targets[first->target].flags & TCF_BUSY)) in initio_find_first_pend_scb()
751 if ((host->act_tags[first->target] >= in initio_find_first_pend_scb()
752 host->max_tags[first->target]) | in initio_find_first_pend_scb()
753 (host->targets[first->target].flags & TCF_BUSY)) { in initio_find_first_pend_scb()
764 static void initio_unlink_pend_scb(struct initio_host * host, struct scsi_ctrl_blk * scb) in initio_unlink_pend_scb() argument
772 prev = tmp = host->first_pending; in initio_unlink_pend_scb()
775 if (tmp == host->first_pending) { in initio_unlink_pend_scb()
776 if ((host->first_pending = tmp->next) == NULL) in initio_unlink_pend_scb()
777 host->last_pending = NULL; in initio_unlink_pend_scb()
780 if (tmp == host->last_pending) in initio_unlink_pend_scb()
781 host->last_pending = prev; in initio_unlink_pend_scb()
791 static void initio_append_busy_scb(struct initio_host * host, struct scsi_ctrl_blk * scbp) in initio_append_busy_scb() argument
798 host->act_tags[scbp->target]++; in initio_append_busy_scb()
800 host->targets[scbp->target].flags |= TCF_BUSY; in initio_append_busy_scb()
803 if (host->last_busy != NULL) { in initio_append_busy_scb()
804 host->last_busy->next = scbp; in initio_append_busy_scb()
805 host->last_busy = scbp; in initio_append_busy_scb()
807 host->first_busy = scbp; in initio_append_busy_scb()
808 host->last_busy = scbp; in initio_append_busy_scb()
813 static struct scsi_ctrl_blk *initio_pop_busy_scb(struct initio_host * host) in initio_pop_busy_scb() argument
818 if ((tmp = host->first_busy) != NULL) { in initio_pop_busy_scb()
819 if ((host->first_busy = tmp->next) == NULL) in initio_pop_busy_scb()
820 host->last_busy = NULL; in initio_pop_busy_scb()
823 host->act_tags[tmp->target]--; in initio_pop_busy_scb()
825 host->targets[tmp->target].flags &= ~TCF_BUSY; in initio_pop_busy_scb()
834 static void initio_unlink_busy_scb(struct initio_host * host, struct scsi_ctrl_blk * scb) in initio_unlink_busy_scb() argument
842 prev = tmp = host->first_busy; in initio_unlink_busy_scb()
845 if (tmp == host->first_busy) { in initio_unlink_busy_scb()
846 if ((host->first_busy = tmp->next) == NULL) in initio_unlink_busy_scb()
847 host->last_busy = NULL; in initio_unlink_busy_scb()
850 if (tmp == host->last_busy) in initio_unlink_busy_scb()
851 host->last_busy = prev; in initio_unlink_busy_scb()
855 host->act_tags[tmp->target]--; in initio_unlink_busy_scb()
857 host->targets[tmp->target].flags &= ~TCF_BUSY; in initio_unlink_busy_scb()
866 struct scsi_ctrl_blk *initio_find_busy_scb(struct initio_host * host, u16 tarlun) in initio_find_busy_scb() argument
872 tmp = host->first_busy; in initio_find_busy_scb()
886 static void initio_append_done_scb(struct initio_host * host, struct scsi_ctrl_blk * scbp) in initio_append_done_scb() argument
894 if (host->last_done != NULL) { in initio_append_done_scb()
895 host->last_done->next = scbp; in initio_append_done_scb()
896 host->last_done = scbp; in initio_append_done_scb()
898 host->first_done = scbp; in initio_append_done_scb()
899 host->last_done = scbp; in initio_append_done_scb()
903 struct scsi_ctrl_blk *initio_find_done_scb(struct initio_host * host) in initio_find_done_scb() argument
907 if ((tmp = host->first_done) != NULL) { in initio_find_done_scb()
908 if ((host->first_done = tmp->next) == NULL) in initio_find_done_scb()
909 host->last_done = NULL; in initio_find_done_scb()
918 static int initio_abort_srb(struct initio_host * host, struct scsi_cmnd *srbp) in initio_abort_srb() argument
923 spin_lock_irqsave(&host->semaph_lock, flags); in initio_abort_srb()
925 if ((host->semaph == 0) && (host->active == NULL)) { in initio_abort_srb()
927 outb(0x1F, host->addr + TUL_Mask); in initio_abort_srb()
928 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_abort_srb()
930 tulip_main(host); in initio_abort_srb()
931 spin_lock_irqsave(&host->semaph_lock, flags); in initio_abort_srb()
932 host->semaph = 1; in initio_abort_srb()
933 outb(0x0F, host->addr + TUL_Mask); in initio_abort_srb()
934 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_abort_srb()
937 prev = tmp = host->first_pending; /* Check Pend queue */ in initio_abort_srb()
941 if (tmp == host->active) { in initio_abort_srb()
942 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_abort_srb()
944 } else if (tmp == host->first_pending) { in initio_abort_srb()
945 if ((host->first_pending = tmp->next) == NULL) in initio_abort_srb()
946 host->last_pending = NULL; in initio_abort_srb()
949 if (tmp == host->last_pending) in initio_abort_srb()
950 host->last_pending = prev; in initio_abort_srb()
955 (*tmp->post) ((u8 *) host, (u8 *) tmp); in initio_abort_srb()
956 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_abort_srb()
963 prev = tmp = host->first_busy; /* Check Busy queue */ in initio_abort_srb()
966 if (tmp == host->active) { in initio_abort_srb()
967 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_abort_srb()
970 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_abort_srb()
973 host->act_tags[tmp->target]--; in initio_abort_srb()
974 if (tmp == host->first_busy) { in initio_abort_srb()
975 if ((host->first_busy = tmp->next) == NULL) in initio_abort_srb()
976 host->last_busy = NULL; in initio_abort_srb()
979 if (tmp == host->last_busy) in initio_abort_srb()
980 host->last_busy = prev; in initio_abort_srb()
988 (*tmp->post) ((u8 *) host, (u8 *) tmp); in initio_abort_srb()
989 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_abort_srb()
996 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_abort_srb()
1001 static int initio_bad_seq(struct initio_host * host) in initio_bad_seq() argument
1005 printk("initio_bad_seg c=%d\n", host->index); in initio_bad_seq()
1007 if ((scb = host->active) != NULL) { in initio_bad_seq()
1008 initio_unlink_busy_scb(host, scb); in initio_bad_seq()
1011 initio_append_done_scb(host, scb); in initio_bad_seq()
1013 initio_stop_bm(host); in initio_bad_seq()
1014 initio_reset_scsi(host, 8); /* 7/29/98 */ in initio_bad_seq()
1015 return initio_post_scsi_rst(host); in initio_bad_seq()
1020 static void initio_exec_scb(struct initio_host * host, struct scsi_ctrl_blk * scb) in initio_exec_scb() argument
1029 spin_lock_irqsave(&host->semaph_lock, flags); in initio_exec_scb()
1031 initio_append_pend_scb(host, scb); /* Append this SCB to Pending queue */ in initio_exec_scb()
1034 if (host->semaph == 1) { in initio_exec_scb()
1036 outb(0x1F, host->addr + TUL_Mask); in initio_exec_scb()
1037 host->semaph = 0; in initio_exec_scb()
1038 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_exec_scb()
1040 tulip_main(host); in initio_exec_scb()
1042 spin_lock_irqsave(&host->semaph_lock, flags); in initio_exec_scb()
1043 host->semaph = 1; in initio_exec_scb()
1044 outb(0x0F, host->addr + TUL_Mask); in initio_exec_scb()
1046 spin_unlock_irqrestore(&host->semaph_lock, flags); in initio_exec_scb()
1051 static int initio_isr(struct initio_host * host) in initio_isr() argument
1053 if (inb(host->addr + TUL_Int) & TSS_INT_PENDING) { in initio_isr()
1054 if (host->semaph == 1) { in initio_isr()
1055 outb(0x1F, host->addr + TUL_Mask); in initio_isr()
1057 host->semaph = 0; in initio_isr()
1059 tulip_main(host); in initio_isr()
1061 host->semaph = 1; in initio_isr()
1062 outb(0x0F, host->addr + TUL_Mask); in initio_isr()
1069 static int tulip_main(struct initio_host * host) in tulip_main() argument
1074 tulip_scsi(host); /* Call tulip_scsi */ in tulip_main()
1077 while ((scb = initio_find_done_scb(host)) != NULL) { /* find done entry */ in tulip_main()
1079 host->max_tags[scb->target] = in tulip_main()
1080 host->act_tags[scb->target] - 1; in tulip_main()
1082 initio_append_pend_scb(host, scb); in tulip_main()
1111 initio_push_pend_scb(host, scb); in tulip_main()
1126 (*scb->post) ((u8 *) host, (u8 *) scb); in tulip_main()
1130 if (inb(host->addr + TUL_SStatus0) & TSS_INT_PENDING) in tulip_main()
1132 if (host->active) /* return to OS and wait for xfer_done_ISR/Selected_ISR */ in tulip_main()
1135 if (initio_find_first_pend_scb(host) == NULL) in tulip_main()
1141 static void tulip_scsi(struct initio_host * host) in tulip_scsi() argument
1147 if ((host->jsstatus0 = inb(host->addr + TUL_SStatus0)) & TSS_INT_PENDING) { in tulip_scsi()
1148 host->phase = host->jsstatus0 & TSS_PH_MASK; in tulip_scsi()
1149 host->jsstatus1 = inb(host->addr + TUL_SStatus1); in tulip_scsi()
1150 host->jsint = inb(host->addr + TUL_SInt); in tulip_scsi()
1151 if (host->jsint & TSS_SCSIRST_INT) { /* SCSI bus reset detected */ in tulip_scsi()
1152 int_initio_scsi_rst(host); in tulip_scsi()
1155 if (host->jsint & TSS_RESEL_INT) { /* if selected/reselected interrupt */ in tulip_scsi()
1156 if (int_initio_resel(host) == 0) in tulip_scsi()
1157 initio_next_state(host); in tulip_scsi()
1160 if (host->jsint & TSS_SEL_TIMEOUT) { in tulip_scsi()
1161 int_initio_busfree(host); in tulip_scsi()
1164 if (host->jsint & TSS_DISC_INT) { /* BUS disconnection */ in tulip_scsi()
1165 int_initio_busfree(host); /* unexpected bus free or sel timeout */ in tulip_scsi()
1168 if (host->jsint & (TSS_FUNC_COMP | TSS_BUS_SERV)) { /* func complete or Bus service */ in tulip_scsi()
1169 if ((scb = host->active) != NULL) in tulip_scsi()
1170 initio_next_state(host); in tulip_scsi()
1174 if (host->active != NULL) in tulip_scsi()
1177 if ((scb = initio_find_first_pend_scb(host)) == NULL) in tulip_scsi()
1181 outb((host->scsi_id << 4) | (scb->target & 0x0F), in tulip_scsi()
1182 host->addr + TUL_SScsiId); in tulip_scsi()
1184 active_tc = &host->targets[scb->target]; in tulip_scsi()
1191 outb(active_tc->js_period, host->addr + TUL_SPeriod); in tulip_scsi()
1193 initio_select_atn_stop(host, scb); in tulip_scsi()
1196 initio_select_atn_stop(host, scb); in tulip_scsi()
1199 initio_select_atn3(host, scb); in tulip_scsi()
1201 initio_select_atn(host, scb); in tulip_scsi()
1205 while (wait_tulip(host) != -1) { in tulip_scsi()
1206 if (initio_next_state(host) == -1) in tulip_scsi()
1211 initio_select_atn_stop(host, scb); in tulip_scsi()
1214 while (wait_tulip(host) != -1) { in tulip_scsi()
1215 if (initio_next_state(host) == -1) in tulip_scsi()
1220 if (initio_abort_srb(host, scb->srb) != 0) { in tulip_scsi()
1221 initio_unlink_pend_scb(host, scb); in tulip_scsi()
1222 initio_release_scb(host, scb); in tulip_scsi()
1225 initio_select_atn_stop(host, scb); in tulip_scsi()
1229 initio_unlink_pend_scb(host, scb); in tulip_scsi()
1231 initio_append_done_scb(host, scb); in tulip_scsi()
1246 static int initio_next_state(struct initio_host * host) in initio_next_state() argument
1250 next = host->active->next_state; in initio_next_state()
1254 next = initio_state_1(host); in initio_next_state()
1257 next = initio_state_2(host); in initio_next_state()
1260 next = initio_state_3(host); in initio_next_state()
1263 next = initio_state_4(host); in initio_next_state()
1266 next = initio_state_5(host); in initio_next_state()
1269 next = initio_state_6(host); in initio_next_state()
1272 next = initio_state_7(host); in initio_next_state()
1275 return initio_bus_device_reset(host); in initio_next_state()
1277 return initio_bad_seq(host); in initio_next_state()
1292 static int initio_state_1(struct initio_host * host) in initio_state_1() argument
1294 struct scsi_ctrl_blk *scb = host->active; in initio_state_1()
1295 struct target_control *active_tc = host->active_tc; in initio_state_1()
1301 initio_unlink_pend_scb(host, scb); in initio_state_1()
1302 initio_append_busy_scb(host, scb); in initio_state_1()
1304 outb(active_tc->sconfig0, host->addr + TUL_SConfig ); in initio_state_1()
1306 if (host->phase == MSG_OUT) { in initio_state_1()
1307 outb(TSC_EN_BUS_IN | TSC_HW_RESELECT, host->addr + TUL_SCtrl1); in initio_state_1()
1308 outb(scb->ident, host->addr + TUL_SFifo); in initio_state_1()
1311 outb(scb->tagmsg, host->addr + TUL_SFifo); in initio_state_1()
1312 outb(scb->tagid, host->addr + TUL_SFifo); in initio_state_1()
1316 outb(EXTENDED_MESSAGE, host->addr + TUL_SFifo); in initio_state_1()
1317 outb(2, host->addr + TUL_SFifo); /* Extended msg length */ in initio_state_1()
1318 outb(EXTENDED_SDTR, host->addr + TUL_SFifo); /* Sync request */ in initio_state_1()
1319 outb(1, host->addr + TUL_SFifo); /* Start from 16 bits */ in initio_state_1()
1322 outb(EXTENDED_MESSAGE, host->addr + TUL_SFifo); in initio_state_1()
1323 outb(3, host->addr + TUL_SFifo); /* extended msg length */ in initio_state_1()
1324 outb(EXTENDED_SDTR, host->addr + TUL_SFifo); /* sync request */ in initio_state_1()
1325 outb(initio_rate_tbl[active_tc->flags & TCF_SCSI_RATE], host->addr + TUL_SFifo); in initio_state_1()
1326 outb(MAX_OFFSET, host->addr + TUL_SFifo); /* REQ/ACK offset */ in initio_state_1()
1328 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_state_1()
1329 if (wait_tulip(host) == -1) in initio_state_1()
1332 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_state_1()
1333 outb((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)), host->addr + TUL_SSignal); in initio_state_1()
1347 static int initio_state_2(struct initio_host * host) in initio_state_2() argument
1349 struct scsi_ctrl_blk *scb = host->active; in initio_state_2()
1350 struct target_control *active_tc = host->active_tc; in initio_state_2()
1355 initio_unlink_pend_scb(host, scb); in initio_state_2()
1356 initio_append_busy_scb(host, scb); in initio_state_2()
1358 outb(active_tc->sconfig0, host->addr + TUL_SConfig); in initio_state_2()
1360 if (host->jsstatus1 & TSS_CMD_PH_CMP) in initio_state_2()
1363 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_state_2()
1364 outb((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)), host->addr + TUL_SSignal); in initio_state_2()
1376 static int initio_state_3(struct initio_host * host) in initio_state_3() argument
1378 struct scsi_ctrl_blk *scb = host->active; in initio_state_3()
1379 struct target_control *active_tc = host->active_tc; in initio_state_3()
1386 switch (host->phase) { in initio_state_3()
1389 outb(scb->cdb[i], host->addr + TUL_SFifo); in initio_state_3()
1390 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_state_3()
1391 if (wait_tulip(host) == -1) in initio_state_3()
1393 if (host->phase == CMD_OUT) in initio_state_3()
1394 return initio_bad_seq(host); in initio_state_3()
1399 if (initio_msgin(host) == -1) in initio_state_3()
1404 if (initio_status_msg(host) == -1) in initio_state_3()
1410 outb(NOP, host->addr + TUL_SFifo); /* msg nop */ in initio_state_3()
1411 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_state_3()
1412 if (wait_tulip(host) == -1) in initio_state_3()
1417 outb(EXTENDED_MESSAGE, host->addr + TUL_SFifo); in initio_state_3()
1418 outb(3, host->addr + TUL_SFifo); /* ext. msg len */ in initio_state_3()
1419 outb(EXTENDED_SDTR, host->addr + TUL_SFifo); /* sync request */ in initio_state_3()
1420 outb(initio_rate_tbl[active_tc->flags & TCF_SCSI_RATE], host->addr + TUL_SFifo); in initio_state_3()
1421 outb(MAX_OFFSET, host->addr + TUL_SFifo); /* REQ/ACK offset */ 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 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_state_3()
1426 outb(inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7), host->addr + TUL_SSignal); in initio_state_3()
1431 return initio_bad_seq(host); in initio_state_3()
1443 static int initio_state_4(struct initio_host * host) in initio_state_4() argument
1445 struct scsi_ctrl_blk *scb = host->active; in initio_state_4()
1457 switch (host->phase) { in initio_state_4()
1462 if ((initio_status_msg(host)) == -1) in initio_state_4()
1468 if (initio_msgin(host) == -1) in initio_state_4()
1473 if (host->jsstatus0 & TSS_PAR_ERROR) { in initio_state_4()
1476 if (initio_msgout_ide(host) == -1) in initio_state_4()
1480 outb(NOP, host->addr + TUL_SFifo); /* msg nop */ in initio_state_4()
1481 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_state_4()
1482 if (wait_tulip(host) == -1) in initio_state_4()
1488 return initio_xfer_data_in(host); in initio_state_4()
1491 return initio_xfer_data_out(host); in initio_state_4()
1494 return initio_bad_seq(host); in initio_state_4()
1507 static int initio_state_5(struct initio_host * host) in initio_state_5() argument
1509 struct scsi_ctrl_blk *scb = host->active; in initio_state_5()
1516 cnt = inl(host->addr + TUL_SCnt0) & 0x0FFFFFF; in initio_state_5()
1518 if (inb(host->addr + TUL_XCmd) & 0x20) { in initio_state_5()
1521 if (host->jsstatus0 & TSS_PAR_ERROR) in initio_state_5()
1523 if (inb(host->addr + TUL_XStatus) & XPEND) { /* DMA xfer pending, Send STOP */ in initio_state_5()
1525 outb(inb(host->addr + TUL_XCtrl) | 0x80, host->addr + TUL_XCtrl); in initio_state_5()
1527 while (inb(host->addr + TUL_XStatus) & XPEND) in initio_state_5()
1532 if ((inb(host->addr + TUL_SStatus1) & TSS_XFER_CMP) == 0) { in initio_state_5()
1533 if (host->active_tc->js_period & TSC_WIDE_SCSI) in initio_state_5()
1534 cnt += (inb(host->addr + TUL_SFifoCnt) & 0x1F) << 1; in initio_state_5()
1536 cnt += (inb(host->addr + TUL_SFifoCnt) & 0x1F); in initio_state_5()
1538 if (inb(host->addr + TUL_XStatus) & XPEND) { /* if DMA xfer is pending, abort DMA xfer */ in initio_state_5()
1539 outb(TAX_X_ABT, host->addr + TUL_XCmd); in initio_state_5()
1541 while ((inb(host->addr + TUL_Int) & XABT) == 0) in initio_state_5()
1544 if ((cnt == 1) && (host->phase == DATA_OUT)) { in initio_state_5()
1545 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_state_5()
1546 if (wait_tulip(host) == -1) in initio_state_5()
1550 if ((inb(host->addr + TUL_SStatus1) & TSS_XFER_CMP) == 0) in initio_state_5()
1551 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_state_5()
1596 static int initio_state_6(struct initio_host * host) in initio_state_6() argument
1598 struct scsi_ctrl_blk *scb = host->active; in initio_state_6()
1604 switch (host->phase) { in initio_state_6()
1606 if ((initio_status_msg(host)) == -1) in initio_state_6()
1612 if ((initio_msgin(host)) == -1) in initio_state_6()
1617 outb(NOP, host->addr + TUL_SFifo); /* msg nop */ in initio_state_6()
1618 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_state_6()
1619 if (wait_tulip(host) == -1) in initio_state_6()
1624 return initio_xpad_in(host); in initio_state_6()
1627 return initio_xpad_out(host); in initio_state_6()
1630 return initio_bad_seq(host); in initio_state_6()
1641 static int initio_state_7(struct initio_host * host) in initio_state_7() argument
1649 cnt = inb(host->addr + TUL_SFifoCnt) & 0x1F; in initio_state_7()
1652 inb(host->addr + TUL_SFifo); in initio_state_7()
1654 switch (host->phase) { in initio_state_7()
1657 return initio_bad_seq(host); in initio_state_7()
1671 static int initio_xfer_data_in(struct initio_host * host) in initio_xfer_data_in() argument
1673 struct scsi_ctrl_blk *scb = host->active; in initio_xfer_data_in()
1678 outl(scb->buflen, host->addr + TUL_SCnt0); in initio_xfer_data_in()
1679 outb(TSC_XF_DMA_IN, host->addr + TUL_SCmd); /* 7/25/95 */ in initio_xfer_data_in()
1682 outl(((u32) scb->sglen) << 3, host->addr + TUL_XCntH); in initio_xfer_data_in()
1683 outl(scb->bufptr, host->addr + TUL_XAddH); in initio_xfer_data_in()
1684 outb(TAX_SG_IN, host->addr + TUL_XCmd); in initio_xfer_data_in()
1686 outl(scb->buflen, host->addr + TUL_XCntH); in initio_xfer_data_in()
1687 outl(scb->bufptr, host->addr + TUL_XAddH); in initio_xfer_data_in()
1688 outb(TAX_X_IN, host->addr + TUL_XCmd); in initio_xfer_data_in()
1703 static int initio_xfer_data_out(struct initio_host * host) in initio_xfer_data_out() argument
1705 struct scsi_ctrl_blk *scb = host->active; in initio_xfer_data_out()
1710 outl(scb->buflen, host->addr + TUL_SCnt0); in initio_xfer_data_out()
1711 outb(TSC_XF_DMA_OUT, host->addr + TUL_SCmd); in initio_xfer_data_out()
1714 outl(((u32) scb->sglen) << 3, host->addr + TUL_XCntH); in initio_xfer_data_out()
1715 outl(scb->bufptr, host->addr + TUL_XAddH); in initio_xfer_data_out()
1716 outb(TAX_SG_OUT, host->addr + TUL_XCmd); in initio_xfer_data_out()
1718 outl(scb->buflen, host->addr + TUL_XCntH); in initio_xfer_data_out()
1719 outl(scb->bufptr, host->addr + TUL_XAddH); in initio_xfer_data_out()
1720 outb(TAX_X_OUT, host->addr + TUL_XCmd); in initio_xfer_data_out()
1727 int initio_xpad_in(struct initio_host * host) in initio_xpad_in() argument
1729 struct scsi_ctrl_blk *scb = host->active; in initio_xpad_in()
1730 struct target_control *active_tc = host->active_tc; in initio_xpad_in()
1736 outl(2, host->addr + TUL_SCnt0); in initio_xpad_in()
1738 outl(1, host->addr + TUL_SCnt0); in initio_xpad_in()
1740 outb(TSC_XF_FIFO_IN, host->addr + TUL_SCmd); in initio_xpad_in()
1741 if (wait_tulip(host) == -1) in initio_xpad_in()
1743 if (host->phase != DATA_IN) { in initio_xpad_in()
1744 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_xpad_in()
1747 inb(host->addr + TUL_SFifo); in initio_xpad_in()
1751 int initio_xpad_out(struct initio_host * host) in initio_xpad_out() argument
1753 struct scsi_ctrl_blk *scb = host->active; in initio_xpad_out()
1754 struct target_control *active_tc = host->active_tc; in initio_xpad_out()
1760 outl(2, host->addr + TUL_SCnt0); in initio_xpad_out()
1762 outl(1, host->addr + TUL_SCnt0); in initio_xpad_out()
1764 outb(0, host->addr + TUL_SFifo); in initio_xpad_out()
1765 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_xpad_out()
1766 if ((wait_tulip(host)) == -1) in initio_xpad_out()
1768 if (host->phase != DATA_OUT) { /* Disable wide CPU to allow read 16 bits */ in initio_xpad_out()
1769 outb(TSC_HW_RESELECT, host->addr + TUL_SCtrl1); in initio_xpad_out()
1770 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_xpad_out()
1776 int initio_status_msg(struct initio_host * host) in initio_status_msg() argument
1778 struct scsi_ctrl_blk *scb = host->active; in initio_status_msg()
1781 outb(TSC_CMD_COMP, host->addr + TUL_SCmd); in initio_status_msg()
1782 if (wait_tulip(host) == -1) in initio_status_msg()
1786 scb->tastat = inb(host->addr + TUL_SFifo); in initio_status_msg()
1788 if (host->phase == MSG_OUT) { in initio_status_msg()
1789 if (host->jsstatus0 & TSS_PAR_ERROR) in initio_status_msg()
1790 outb(MSG_PARITY_ERROR, host->addr + TUL_SFifo); in initio_status_msg()
1792 outb(NOP, host->addr + TUL_SFifo); in initio_status_msg()
1793 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_status_msg()
1794 return wait_tulip(host); in initio_status_msg()
1796 if (host->phase == MSG_IN) { in initio_status_msg()
1797 msg = inb(host->addr + TUL_SFifo); in initio_status_msg()
1798 if (host->jsstatus0 & TSS_PAR_ERROR) { /* Parity error */ in initio_status_msg()
1799 if ((initio_msgin_accept(host)) == -1) in initio_status_msg()
1801 if (host->phase != MSG_OUT) in initio_status_msg()
1802 return initio_bad_seq(host); in initio_status_msg()
1803 outb(MSG_PARITY_ERROR, host->addr + TUL_SFifo); in initio_status_msg()
1804 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_status_msg()
1805 return wait_tulip(host); in initio_status_msg()
1810 return initio_bad_seq(host); in initio_status_msg()
1811 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_status_msg()
1812 outb(TSC_MSG_ACCEPT, host->addr + TUL_SCmd); in initio_status_msg()
1813 return initio_wait_done_disc(host); in initio_status_msg()
1819 return initio_msgin_accept(host); in initio_status_msg()
1822 return initio_bad_seq(host); in initio_status_msg()
1827 int int_initio_busfree(struct initio_host * host) in int_initio_busfree() argument
1829 struct scsi_ctrl_blk *scb = host->active; in int_initio_busfree()
1833 initio_unlink_pend_scb(host, scb); in int_initio_busfree()
1835 initio_append_done_scb(host, scb); in int_initio_busfree()
1837 initio_unlink_busy_scb(host, scb); in int_initio_busfree()
1839 initio_append_done_scb(host, scb); in int_initio_busfree()
1841 host->active = NULL; in int_initio_busfree()
1842 host->active_tc = NULL; in int_initio_busfree()
1844 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); /* Flush SCSI FIFO */ in int_initio_busfree()
1845 outb(TSC_INITDEFAULT, host->addr + TUL_SConfig); in int_initio_busfree()
1846 outb(TSC_HW_RESELECT, host->addr + TUL_SCtrl1); /* Enable HW reselect */ in int_initio_busfree()
1861 static int int_initio_scsi_rst(struct initio_host * host) in int_initio_scsi_rst() argument
1867 if (inb(host->addr + TUL_XStatus) & 0x01) { in int_initio_scsi_rst()
1868 outb(TAX_X_ABT | TAX_X_CLR_FIFO, host->addr + TUL_XCmd); in int_initio_scsi_rst()
1870 while ((inb(host->addr + TUL_Int) & 0x04) == 0) in int_initio_scsi_rst()
1872 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in int_initio_scsi_rst()
1875 while ((scb = initio_pop_busy_scb(host)) != NULL) { in int_initio_scsi_rst()
1877 initio_append_done_scb(host, scb); in int_initio_scsi_rst()
1879 host->active = NULL; in int_initio_scsi_rst()
1880 host->active_tc = NULL; in int_initio_scsi_rst()
1883 for (i = 0; i < host->max_tar; i++) in int_initio_scsi_rst()
1884 host->targets[i].flags &= ~(TCF_SYNC_DONE | TCF_WDTR_DONE); in int_initio_scsi_rst()
1897 int int_initio_resel(struct initio_host * host) in int_initio_resel() argument
1904 if ((scb = host->active) != NULL) { in int_initio_resel()
1908 host->active = NULL; in int_initio_resel()
1911 tar = inb(host->addr + TUL_SBusId); in int_initio_resel()
1913 lun = inb(host->addr + TUL_SIdent) & 0x0F; in int_initio_resel()
1915 active_tc = &host->targets[tar]; in int_initio_resel()
1916 host->active_tc = active_tc; in int_initio_resel()
1917 outb(active_tc->sconfig0, host->addr + TUL_SConfig); in int_initio_resel()
1918 outb(active_tc->js_period, host->addr + TUL_SPeriod); in int_initio_resel()
1922 if ((initio_msgin_accept(host)) == -1) in int_initio_resel()
1924 if (host->phase != MSG_IN) in int_initio_resel()
1926 outl(1, host->addr + TUL_SCnt0); in int_initio_resel()
1927 outb(TSC_XF_FIFO_IN, host->addr + TUL_SCmd); in int_initio_resel()
1928 if (wait_tulip(host) == -1) in int_initio_resel()
1930 msg = inb(host->addr + TUL_SFifo); /* Read Tag Message */ in int_initio_resel()
1936 if (initio_msgin_accept(host) == -1) in int_initio_resel()
1939 if (host->phase != MSG_IN) in int_initio_resel()
1942 outl(1, host->addr + TUL_SCnt0); in int_initio_resel()
1943 outb(TSC_XF_FIFO_IN, host->addr + TUL_SCmd); in int_initio_resel()
1944 if (wait_tulip(host) == -1) in int_initio_resel()
1946 tag = inb(host->addr + TUL_SFifo); /* Read Tag ID */ in int_initio_resel()
1947 scb = host->scb + tag; in int_initio_resel()
1949 return initio_msgout_abort_tag(host); in int_initio_resel()
1952 return initio_msgout_abort_tag(host); in int_initio_resel()
1954 host->active = scb; in int_initio_resel()
1955 if ((initio_msgin_accept(host)) == -1) in int_initio_resel()
1959 if ((scb = initio_find_busy_scb(host, tar | (lun << 8))) == NULL) { in int_initio_resel()
1960 return initio_msgout_abort_targ(host); in int_initio_resel()
1962 host->active = scb; in int_initio_resel()
1964 if ((initio_msgin_accept(host)) == -1) in int_initio_resel()
1979 static int int_initio_bad_seq(struct initio_host * host) in int_initio_bad_seq() argument
1984 initio_reset_scsi(host, 10); in int_initio_bad_seq()
1986 while ((scb = initio_pop_busy_scb(host)) != NULL) { in int_initio_bad_seq()
1988 initio_append_done_scb(host, scb); in int_initio_bad_seq()
1990 for (i = 0; i < host->max_tar; i++) in int_initio_bad_seq()
1991 host->targets[i].flags &= ~(TCF_SYNC_DONE | TCF_WDTR_DONE); in int_initio_bad_seq()
2004 static int initio_msgout_abort_targ(struct initio_host * host) in initio_msgout_abort_targ() argument
2007 …outb(((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)) | TSC_SET_ATN), host->addr + TUL_SSignal… in initio_msgout_abort_targ()
2008 if (initio_msgin_accept(host) == -1) in initio_msgout_abort_targ()
2010 if (host->phase != MSG_OUT) in initio_msgout_abort_targ()
2011 return initio_bad_seq(host); in initio_msgout_abort_targ()
2013 outb(ABORT_TASK_SET, host->addr + TUL_SFifo); in initio_msgout_abort_targ()
2014 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_msgout_abort_targ()
2016 return initio_wait_disc(host); in initio_msgout_abort_targ()
2027 static int initio_msgout_abort_tag(struct initio_host * host) in initio_msgout_abort_tag() argument
2030 …outb(((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)) | TSC_SET_ATN), host->addr + TUL_SSignal… in initio_msgout_abort_tag()
2031 if (initio_msgin_accept(host) == -1) in initio_msgout_abort_tag()
2033 if (host->phase != MSG_OUT) in initio_msgout_abort_tag()
2034 return initio_bad_seq(host); in initio_msgout_abort_tag()
2036 outb(ABORT_TASK, host->addr + TUL_SFifo); in initio_msgout_abort_tag()
2037 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_msgout_abort_tag()
2039 return initio_wait_disc(host); in initio_msgout_abort_tag()
2049 static int initio_msgin(struct initio_host * host) in initio_msgin() argument
2054 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_msgin()
2056 outl(1, host->addr + TUL_SCnt0); in initio_msgin()
2057 outb(TSC_XF_FIFO_IN, host->addr + TUL_SCmd); in initio_msgin()
2058 if (wait_tulip(host) == -1) in initio_msgin()
2061 switch (inb(host->addr + TUL_SFifo)) { in initio_msgin()
2063 outb(TSC_MSG_ACCEPT, host->addr + TUL_SCmd); in initio_msgin()
2064 return initio_wait_disc(host); in initio_msgin()
2068 initio_msgin_accept(host); in initio_msgin()
2071 outb((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)), in initio_msgin()
2072 host->addr + TUL_SSignal); in initio_msgin()
2073 active_tc = host->active_tc; in initio_msgin()
2075 outb(((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)) | TSC_SET_ATN), in initio_msgin()
2076 host->addr + TUL_SSignal); in initio_msgin()
2077 initio_msgin_accept(host); in initio_msgin()
2080 initio_msgin_extend(host); in initio_msgin()
2083 initio_msgin_accept(host); in initio_msgin()
2086 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_msgin()
2087 outb(TSC_MSG_ACCEPT, host->addr + TUL_SCmd); in initio_msgin()
2088 return initio_wait_done_disc(host); in initio_msgin()
2090 initio_msgout_reject(host); in initio_msgin()
2093 if (host->phase != MSG_IN) in initio_msgin()
2094 return host->phase; in initio_msgin()
2099 static int initio_msgout_reject(struct initio_host * host) in initio_msgout_reject() argument
2101 …outb(((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)) | TSC_SET_ATN), host->addr + TUL_SSignal… in initio_msgout_reject()
2103 if (initio_msgin_accept(host) == -1) in initio_msgout_reject()
2106 if (host->phase == MSG_OUT) { in initio_msgout_reject()
2107 outb(MESSAGE_REJECT, host->addr + TUL_SFifo); /* Msg reject */ in initio_msgout_reject()
2108 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_msgout_reject()
2109 return wait_tulip(host); in initio_msgout_reject()
2111 return host->phase; in initio_msgout_reject()
2114 static int initio_msgout_ide(struct initio_host * host) in initio_msgout_ide() argument
2116 outb(INITIATOR_ERROR, host->addr + TUL_SFifo); /* Initiator Detected Error */ in initio_msgout_ide()
2117 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_msgout_ide()
2118 return wait_tulip(host); in initio_msgout_ide()
2121 static int initio_msgin_extend(struct initio_host * host) in initio_msgin_extend() argument
2125 if (initio_msgin_accept(host) != MSG_IN) in initio_msgin_extend()
2126 return host->phase; in initio_msgin_extend()
2129 outl(1, host->addr + TUL_SCnt0); in initio_msgin_extend()
2130 outb(TSC_XF_FIFO_IN, host->addr + TUL_SCmd); in initio_msgin_extend()
2131 if (wait_tulip(host) == -1) in initio_msgin_extend()
2134 len = inb(host->addr + TUL_SFifo); in initio_msgin_extend()
2135 host->msg[0] = len; in initio_msgin_extend()
2138 if ((initio_msgin_accept(host)) != MSG_IN) in initio_msgin_extend()
2139 return host->phase; in initio_msgin_extend()
2140 outl(1, host->addr + TUL_SCnt0); in initio_msgin_extend()
2141 outb(TSC_XF_FIFO_IN, host->addr + TUL_SCmd); in initio_msgin_extend()
2142 if (wait_tulip(host) == -1) in initio_msgin_extend()
2144 host->msg[idx++] = inb(host->addr + TUL_SFifo); in initio_msgin_extend()
2146 if (host->msg[1] == 1) { /* if it's synchronous data transfer request */ in initio_msgin_extend()
2148 if (host->msg[0] != 3) /* if length is not right */ in initio_msgin_extend()
2149 return initio_msgout_reject(host); in initio_msgin_extend()
2150 if (host->active_tc->flags & TCF_NO_SYNC_NEGO) { /* Set OFFSET=0 to do async, nego back */ in initio_msgin_extend()
2151 host->msg[3] = 0; in initio_msgin_extend()
2153 if (initio_msgin_sync(host) == 0 && in initio_msgin_extend()
2154 (host->active_tc->flags & TCF_SYNC_DONE)) { in initio_msgin_extend()
2155 initio_sync_done(host); in initio_msgin_extend()
2156 return initio_msgin_accept(host); in initio_msgin_extend()
2160 r = inb(host->addr + TUL_SSignal); in initio_msgin_extend()
2162 host->addr + TUL_SSignal); in initio_msgin_extend()
2163 if (initio_msgin_accept(host) != MSG_OUT) in initio_msgin_extend()
2164 return host->phase; in initio_msgin_extend()
2166 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); in initio_msgin_extend()
2168 initio_sync_done(host); in initio_msgin_extend()
2170 outb(EXTENDED_MESSAGE, host->addr + TUL_SFifo); in initio_msgin_extend()
2171 outb(3, host->addr + TUL_SFifo); in initio_msgin_extend()
2172 outb(EXTENDED_SDTR, host->addr + TUL_SFifo); in initio_msgin_extend()
2173 outb(host->msg[2], host->addr + TUL_SFifo); in initio_msgin_extend()
2174 outb(host->msg[3], host->addr + TUL_SFifo); in initio_msgin_extend()
2175 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_msgin_extend()
2176 return wait_tulip(host); in initio_msgin_extend()
2178 if (host->msg[0] != 2 || host->msg[1] != 3) in initio_msgin_extend()
2179 return initio_msgout_reject(host); in initio_msgin_extend()
2181 if (host->active_tc->flags & TCF_NO_WDTR) { in initio_msgin_extend()
2182 host->msg[2] = 0; in initio_msgin_extend()
2184 if (host->msg[2] > 2) /* > 32 bits */ in initio_msgin_extend()
2185 return initio_msgout_reject(host); in initio_msgin_extend()
2186 if (host->msg[2] == 2) { /* == 32 */ in initio_msgin_extend()
2187 host->msg[2] = 1; in initio_msgin_extend()
2189 if ((host->active_tc->flags & TCF_NO_WDTR) == 0) { in initio_msgin_extend()
2190 wdtr_done(host); in initio_msgin_extend()
2191 if ((host->active_tc->flags & (TCF_SYNC_DONE | TCF_NO_SYNC_NEGO)) == 0) in initio_msgin_extend()
2192 …outb(((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)) | TSC_SET_ATN), host->addr + TUL_SSignal… in initio_msgin_extend()
2193 return initio_msgin_accept(host); in initio_msgin_extend()
2197 …outb(((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)) | TSC_SET_ATN), host->addr + TUL_SSignal… in initio_msgin_extend()
2199 if (initio_msgin_accept(host) != MSG_OUT) in initio_msgin_extend()
2200 return host->phase; in initio_msgin_extend()
2202 outb(EXTENDED_MESSAGE, host->addr + TUL_SFifo); in initio_msgin_extend()
2203 outb(2, host->addr + TUL_SFifo); in initio_msgin_extend()
2204 outb(EXTENDED_WDTR, host->addr + TUL_SFifo); in initio_msgin_extend()
2205 outb(host->msg[2], host->addr + TUL_SFifo); in initio_msgin_extend()
2206 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_msgin_extend()
2207 return wait_tulip(host); in initio_msgin_extend()
2210 static int initio_msgin_sync(struct initio_host * host) in initio_msgin_sync() argument
2214 default_period = initio_rate_tbl[host->active_tc->flags & TCF_SCSI_RATE]; in initio_msgin_sync()
2215 if (host->msg[3] > MAX_OFFSET) { in initio_msgin_sync()
2216 host->msg[3] = MAX_OFFSET; in initio_msgin_sync()
2217 if (host->msg[2] < default_period) { in initio_msgin_sync()
2218 host->msg[2] = default_period; in initio_msgin_sync()
2221 if (host->msg[2] >= 59) /* Change to async */ in initio_msgin_sync()
2222 host->msg[3] = 0; in initio_msgin_sync()
2226 if (host->msg[3] == 0) { in initio_msgin_sync()
2229 if (host->msg[2] < default_period) { in initio_msgin_sync()
2230 host->msg[2] = default_period; in initio_msgin_sync()
2233 if (host->msg[2] >= 59) { in initio_msgin_sync()
2234 host->msg[3] = 0; in initio_msgin_sync()
2240 static int wdtr_done(struct initio_host * host) in wdtr_done() argument
2242 host->active_tc->flags &= ~TCF_SYNC_DONE; in wdtr_done()
2243 host->active_tc->flags |= TCF_WDTR_DONE; in wdtr_done()
2245 host->active_tc->js_period = 0; in wdtr_done()
2246 if (host->msg[2]) /* if 16 bit */ in wdtr_done()
2247 host->active_tc->js_period |= TSC_WIDE_SCSI; in wdtr_done()
2248 host->active_tc->sconfig0 &= ~TSC_ALT_PERIOD; in wdtr_done()
2249 outb(host->active_tc->sconfig0, host->addr + TUL_SConfig); in wdtr_done()
2250 outb(host->active_tc->js_period, host->addr + TUL_SPeriod); in wdtr_done()
2255 static int initio_sync_done(struct initio_host * host) in initio_sync_done() argument
2259 host->active_tc->flags |= TCF_SYNC_DONE; in initio_sync_done()
2261 if (host->msg[3]) { in initio_sync_done()
2262 host->active_tc->js_period |= host->msg[3]; in initio_sync_done()
2264 if (initio_rate_tbl[i] >= host->msg[2]) /* pick the big one */ in initio_sync_done()
2267 host->active_tc->js_period |= (i << 4); in initio_sync_done()
2268 host->active_tc->sconfig0 |= TSC_ALT_PERIOD; in initio_sync_done()
2270 outb(host->active_tc->sconfig0, host->addr + TUL_SConfig); in initio_sync_done()
2271 outb(host->active_tc->js_period, host->addr + TUL_SPeriod); in initio_sync_done()
2277 static int initio_post_scsi_rst(struct initio_host * host) in initio_post_scsi_rst() argument
2283 host->active = NULL; in initio_post_scsi_rst()
2284 host->active_tc = NULL; in initio_post_scsi_rst()
2285 host->flags = 0; in initio_post_scsi_rst()
2287 while ((scb = initio_pop_busy_scb(host)) != NULL) { in initio_post_scsi_rst()
2289 initio_append_done_scb(host, scb); in initio_post_scsi_rst()
2292 active_tc = &host->targets[0]; in initio_post_scsi_rst()
2293 for (i = 0; i < host->max_tar; active_tc++, i++) { in initio_post_scsi_rst()
2297 active_tc->sconfig0 = host->sconf1; in initio_post_scsi_rst()
2298 host->act_tags[0] = 0; /* 07/22/98 */ in initio_post_scsi_rst()
2299 host->targets[i].flags &= ~TCF_BUSY; /* 07/22/98 */ in initio_post_scsi_rst()
2305 static void initio_select_atn_stop(struct initio_host * host, struct scsi_ctrl_blk * scb) in initio_select_atn_stop() argument
2309 host->active = scb; in initio_select_atn_stop()
2310 host->active_tc = &host->targets[scb->target]; in initio_select_atn_stop()
2311 outb(TSC_SELATNSTOP, host->addr + TUL_SCmd); in initio_select_atn_stop()
2315 static void initio_select_atn(struct initio_host * host, struct scsi_ctrl_blk * scb) in initio_select_atn() argument
2322 outb(scb->ident, host->addr + TUL_SFifo); in initio_select_atn()
2324 outb(scb->cdb[i], host->addr + TUL_SFifo); in initio_select_atn()
2325 host->active_tc = &host->targets[scb->target]; in initio_select_atn()
2326 host->active = scb; in initio_select_atn()
2327 outb(TSC_SEL_ATN, host->addr + TUL_SCmd); in initio_select_atn()
2330 static void initio_select_atn3(struct initio_host * host, struct scsi_ctrl_blk * scb) in initio_select_atn3() argument
2337 outb(scb->ident, host->addr + TUL_SFifo); in initio_select_atn3()
2338 outb(scb->tagmsg, host->addr + TUL_SFifo); in initio_select_atn3()
2339 outb(scb->tagid, host->addr + TUL_SFifo); in initio_select_atn3()
2341 outb(scb->cdb[i], host->addr + TUL_SFifo); in initio_select_atn3()
2342 host->active_tc = &host->targets[scb->target]; in initio_select_atn3()
2343 host->active = scb; in initio_select_atn3()
2344 outb(TSC_SEL_ATN3, host->addr + TUL_SCmd); in initio_select_atn3()
2354 int initio_bus_device_reset(struct initio_host * host) in initio_bus_device_reset() argument
2356 struct scsi_ctrl_blk *scb = host->active; in initio_bus_device_reset()
2357 struct target_control *active_tc = host->active_tc; in initio_bus_device_reset()
2361 if (host->phase != MSG_OUT) in initio_bus_device_reset()
2362 return int_initio_bad_seq(host); /* Unexpected phase */ in initio_bus_device_reset()
2364 initio_unlink_pend_scb(host, scb); in initio_bus_device_reset()
2365 initio_release_scb(host, scb); in initio_bus_device_reset()
2373 prev = tmp = host->first_busy; /* Check Busy queue */ in initio_bus_device_reset()
2377 if (tmp == host->first_busy) { in initio_bus_device_reset()
2378 if ((host->first_busy = tmp->next) == NULL) in initio_bus_device_reset()
2379 host->last_busy = NULL; in initio_bus_device_reset()
2382 if (tmp == host->last_busy) in initio_bus_device_reset()
2383 host->last_busy = prev; in initio_bus_device_reset()
2386 initio_append_done_scb(host, tmp); in initio_bus_device_reset()
2394 outb(TARGET_RESET, host->addr + TUL_SFifo); in initio_bus_device_reset()
2395 outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); in initio_bus_device_reset()
2396 return initio_wait_disc(host); in initio_bus_device_reset()
2400 static int initio_msgin_accept(struct initio_host * host) in initio_msgin_accept() argument
2402 outb(TSC_MSG_ACCEPT, host->addr + TUL_SCmd); in initio_msgin_accept()
2403 return wait_tulip(host); in initio_msgin_accept()
2406 static int wait_tulip(struct initio_host * host) in wait_tulip() argument
2409 while (!((host->jsstatus0 = inb(host->addr + TUL_SStatus0)) in wait_tulip()
2413 host->jsint = inb(host->addr + TUL_SInt); in wait_tulip()
2414 host->phase = host->jsstatus0 & TSS_PH_MASK; in wait_tulip()
2415 host->jsstatus1 = inb(host->addr + TUL_SStatus1); in wait_tulip()
2417 if (host->jsint & TSS_RESEL_INT) /* if SCSI bus reset detected */ in wait_tulip()
2418 return int_initio_resel(host); in wait_tulip()
2419 if (host->jsint & TSS_SEL_TIMEOUT) /* if selected/reselected timeout interrupt */ in wait_tulip()
2420 return int_initio_busfree(host); in wait_tulip()
2421 if (host->jsint & TSS_SCSIRST_INT) /* if SCSI bus reset detected */ in wait_tulip()
2422 return int_initio_scsi_rst(host); in wait_tulip()
2424 if (host->jsint & TSS_DISC_INT) { /* BUS disconnection */ in wait_tulip()
2425 if (host->flags & HCF_EXPECT_DONE_DISC) { in wait_tulip()
2426 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); /* Flush SCSI FIFO */ in wait_tulip()
2427 initio_unlink_busy_scb(host, host->active); in wait_tulip()
2428 host->active->hastat = 0; in wait_tulip()
2429 initio_append_done_scb(host, host->active); in wait_tulip()
2430 host->active = NULL; in wait_tulip()
2431 host->active_tc = NULL; in wait_tulip()
2432 host->flags &= ~HCF_EXPECT_DONE_DISC; in wait_tulip()
2433 outb(TSC_INITDEFAULT, host->addr + TUL_SConfig); in wait_tulip()
2434 outb(TSC_HW_RESELECT, host->addr + TUL_SCtrl1); /* Enable HW reselect */ in wait_tulip()
2437 if (host->flags & HCF_EXPECT_DISC) { in wait_tulip()
2438 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); /* Flush SCSI FIFO */ in wait_tulip()
2439 host->active = NULL; in wait_tulip()
2440 host->active_tc = NULL; in wait_tulip()
2441 host->flags &= ~HCF_EXPECT_DISC; in wait_tulip()
2442 outb(TSC_INITDEFAULT, host->addr + TUL_SConfig); in wait_tulip()
2443 outb(TSC_HW_RESELECT, host->addr + TUL_SCtrl1); /* Enable HW reselect */ in wait_tulip()
2446 return int_initio_busfree(host); in wait_tulip()
2449 if (host->jsint & (TSS_FUNC_COMP | TSS_BUS_SERV)) in wait_tulip()
2450 return host->phase; in wait_tulip()
2451 return host->phase; in wait_tulip()
2454 static int initio_wait_disc(struct initio_host * host) in initio_wait_disc() argument
2456 while (!((host->jsstatus0 = inb(host->addr + TUL_SStatus0)) & TSS_INT_PENDING)) in initio_wait_disc()
2459 host->jsint = inb(host->addr + TUL_SInt); in initio_wait_disc()
2461 if (host->jsint & TSS_SCSIRST_INT) /* if SCSI bus reset detected */ in initio_wait_disc()
2462 return int_initio_scsi_rst(host); in initio_wait_disc()
2463 if (host->jsint & TSS_DISC_INT) { /* BUS disconnection */ in initio_wait_disc()
2464 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); /* Flush SCSI FIFO */ in initio_wait_disc()
2465 outb(TSC_INITDEFAULT, host->addr + TUL_SConfig); in initio_wait_disc()
2466 outb(TSC_HW_RESELECT, host->addr + TUL_SCtrl1); /* Enable HW reselect */ in initio_wait_disc()
2467 host->active = NULL; in initio_wait_disc()
2470 return initio_bad_seq(host); in initio_wait_disc()
2473 static int initio_wait_done_disc(struct initio_host * host) in initio_wait_done_disc() argument
2475 while (!((host->jsstatus0 = inb(host->addr + TUL_SStatus0)) in initio_wait_done_disc()
2479 host->jsint = inb(host->addr + TUL_SInt); in initio_wait_done_disc()
2481 if (host->jsint & TSS_SCSIRST_INT) /* if SCSI bus reset detected */ in initio_wait_done_disc()
2482 return int_initio_scsi_rst(host); in initio_wait_done_disc()
2483 if (host->jsint & TSS_DISC_INT) { /* BUS disconnection */ in initio_wait_done_disc()
2484 outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); /* Flush SCSI FIFO */ in initio_wait_done_disc()
2485 outb(TSC_INITDEFAULT, host->addr + TUL_SConfig); in initio_wait_done_disc()
2486 outb(TSC_HW_RESELECT, host->addr + TUL_SCtrl1); /* Enable HW reselect */ in initio_wait_done_disc()
2487 initio_unlink_busy_scb(host, host->active); in initio_wait_done_disc()
2489 initio_append_done_scb(host, host->active); in initio_wait_done_disc()
2490 host->active = NULL; in initio_wait_done_disc()
2493 return initio_bad_seq(host); in initio_wait_done_disc()
2532 static void initio_build_scb(struct initio_host * host, struct scsi_ctrl_blk * cblk, struct scsi_cm… in initio_build_scb() argument
2552 dma_addr = dma_map_single(&host->pci_dev->dev, cmnd->sense_buffer, in initio_build_scb()
2576 dma_addr = dma_map_single(&host->pci_dev->dev, &cblk->sglist[0], in initio_build_scb()
2615 struct initio_host *host = (struct initio_host *) cmd->device->host->hostdata; in i91u_queuecommand_lck() local
2620 cmnd = initio_alloc_scb(host); in i91u_queuecommand_lck()
2624 initio_build_scb(host, cmnd, cmd); in i91u_queuecommand_lck()
2625 initio_exec_scb(host, cmnd); in i91u_queuecommand_lck()
2640 struct initio_host *host; in DEF_SCSI_QCMD() local
2642 host = (struct initio_host *) cmnd->device->host->hostdata; in DEF_SCSI_QCMD()
2644 spin_lock_irq(cmnd->device->host->host_lock); in DEF_SCSI_QCMD()
2645 initio_reset_scsi(host, 0); in DEF_SCSI_QCMD()
2646 spin_unlock_irq(cmnd->device->host->host_lock); in DEF_SCSI_QCMD()
2667 struct initio_host *host; /* Point to Host adapter control block */ in i91u_biosparam() local
2670 host = (struct initio_host *) sdev->host->hostdata; in i91u_biosparam()
2671 tc = &host->targets[sdev->id]; in i91u_biosparam()
2739 struct initio_host *host; in i91uSCBPost() local
2742 host = (struct initio_host *) host_mem; in i91uSCBPost()
2747 initio_release_scb(host, cblk); /* Release SCB for current channel */ in i91uSCBPost()
2790 i91u_unmap_scb(host->pci_dev, cmnd); in i91uSCBPost()
2792 initio_release_scb(host, cblk); /* Release SCB for current channel */ in i91uSCBPost()
2810 struct initio_host *host; in initio_probe_one() local
2837 host = (struct initio_host *)shost->hostdata; in initio_probe_one()
2838 memset(host, 0, sizeof(struct initio_host)); in initio_probe_one()
2839 host->addr = pci_resource_start(pdev, 0); in initio_probe_one()
2840 host->bios_addr = bios_seg; in initio_probe_one()
2842 if (!request_region(host->addr, 256, "i91u")) { in initio_probe_one()
2843 printk(KERN_WARNING "initio: I/O port range 0x%x is busy.\n", host->addr); in initio_probe_one()
2865 host->pci_dev = pdev; in initio_probe_one()
2867 host->semaph = 1; in initio_probe_one()
2868 spin_lock_init(&host->semaph_lock); in initio_probe_one()
2869 host->num_scbs = num_scb; in initio_probe_one()
2870 host->scb = scb; in initio_probe_one()
2871 host->next_pending = scb; in initio_probe_one()
2872 host->next_avail = scb; in initio_probe_one()
2880 host->scb_end = tmp; in initio_probe_one()
2881 host->first_avail = scb; in initio_probe_one()
2882 host->last_avail = prev; in initio_probe_one()
2883 spin_lock_init(&host->avail_lock); in initio_probe_one()
2885 initio_init(host, phys_to_virt(((u32)bios_seg << 4))); in initio_probe_one()
2887 host->jsstatus0 = 0; in initio_probe_one()
2889 shost->io_port = host->addr; in initio_probe_one()
2892 shost->unique_id = host->addr; in initio_probe_one()
2893 shost->max_id = host->max_tar; in initio_probe_one()
2896 shost->this_id = host->scsi_id; /* Assign HCS index */ in initio_probe_one()
2897 shost->base = host->addr; in initio_probe_one()
2916 kfree(host->scb); in initio_probe_one()
2918 release_region(host->addr, 256); in initio_probe_one()
2936 struct Scsi_Host *host = pci_get_drvdata(pdev); in initio_remove_one() local
2937 struct initio_host *s = (struct initio_host *)host->hostdata; in initio_remove_one()
2938 scsi_remove_host(host); in initio_remove_one()
2939 free_irq(pdev->irq, host); in initio_remove_one()
2941 scsi_host_put(host); in initio_remove_one()