Lines Matching +full:ultra +full:- +full:compact

4  * Copyright (c) 1994-2002 Justin T. Gibbs.
5 * Copyright (c) 2000-2002 Adaptec Inc.
19 * 3. Neither the names of the above-listed copyright holders nor the names
78 { DPARERR, "Data-path Parity Error" },
87 { P_DATAOUT, NOP, "in Data-out phase" },
88 { P_DATAIN, INITIATOR_ERROR, "in Data-in phase" },
89 { P_DATAOUT_DT, NOP, "in DT Data-out phase" },
90 { P_DATAIN_DT, INITIATOR_ERROR, "in DT Data-in phase" },
92 { P_MESGOUT, NOP, "in Message-out phase" },
94 { P_MESGIN, MSG_PARITY_ERROR, "in Message-in phase" },
103 static const u_int num_phases = ARRAY_SIZE(ahc_phase_table) - 1;
106 * Valid SCSIRATE values. (p. 3-17)
112 /* ultra2 fast/ultra period rate */
278 if ((ahc->flags & AHC_SCB_BTT) == 0) in ahc_freeze_untagged_queues()
279 ahc->untagged_queue_lock++; in ahc_freeze_untagged_queues()
291 if ((ahc->flags & AHC_SCB_BTT) == 0) { in ahc_release_untagged_queues()
292 ahc->untagged_queue_lock--; in ahc_release_untagged_queues()
293 if (ahc->untagged_queue_lock == 0) in ahc_release_untagged_queues()
310 if ((ahc->features & AHC_ULTRA2) != 0) in ahc_pause_bug_fix()
316 * Returns non-zero status if the sequencer is stopped.
334 ahc_outb(ahc, HCNTRL, ahc->pause); in ahc_pause()
360 ahc_outb(ahc, HCNTRL, ahc->unpause); in ahc_unpause()
369 sg_index = (sg_busaddr - scb->sg_list_phys)/sizeof(struct ahc_dma_seg); in ahc_sg_bus_to_virt()
373 return (&scb->sg_list[sg_index]); in ahc_sg_bus_to_virt()
382 sg_index = sg - &scb->sg_list[1]; in ahc_sg_virt_to_bus()
384 return (scb->sg_list_phys + (sg_index * sizeof(*scb->sg_list))); in ahc_sg_virt_to_bus()
390 return (ahc->scb_data->hscb_busaddr in ahc_hscb_busaddr()
397 ahc_dmamap_sync(ahc, ahc->scb_data->hscb_dmat, in ahc_sync_scb()
398 ahc->scb_data->hscb_dmamap, in ahc_sync_scb()
399 /*offset*/(scb->hscb - ahc->hscbs) * sizeof(*scb->hscb), in ahc_sync_scb()
400 /*len*/sizeof(*scb->hscb), op); in ahc_sync_scb()
406 if (scb->sg_count == 0) in ahc_sync_sglist()
409 ahc_dmamap_sync(ahc, ahc->scb_data->sg_dmat, scb->sg_map->sg_dmamap, in ahc_sync_sglist()
410 /*offset*/(scb->sg_list - scb->sg_map->sg_vaddr) in ahc_sync_sglist()
412 /*len*/sizeof(struct ahc_dma_seg) * scb->sg_count, op); in ahc_sync_sglist()
419 return (((uint8_t *)&ahc->targetcmds[index]) - ahc->qoutfifo); in ahc_targetcmd_offset()
433 sgptr = ahc_le32toh(scb->hscb->sgptr); in ahc_update_residual()
454 *tstate = ahc->enabled_targets[our_id]; in ahc_fetch_transinfo()
455 return (&(*tstate)->transinfo[remote_id]); in ahc_fetch_transinfo()
524 if ((scb = SLIST_FIRST(&ahc->scb_data->free_scbs)) == NULL) { in ahc_get_scb()
526 scb = SLIST_FIRST(&ahc->scb_data->free_scbs); in ahc_get_scb()
530 SLIST_REMOVE_HEAD(&ahc->scb_data->free_scbs, links.sle); in ahc_get_scb()
542 hscb = scb->hscb; in ahc_free_scb()
544 ahc->scb_data->scbindex[hscb->tag] = NULL; in ahc_free_scb()
545 scb->flags = SCB_FREE; in ahc_free_scb()
546 hscb->control = 0; in ahc_free_scb()
548 SLIST_INSERT_HEAD(&ahc->scb_data->free_scbs, scb, links.sle); in ahc_free_scb()
559 scb = ahc->scb_data->scbindex[tag]; in ahc_lookup_scb()
576 * SCB to download is saved off in ahc->next_queued_scb. in ahc_swap_with_next_hscb()
584 q_hscb = ahc->next_queued_scb->hscb; in ahc_swap_with_next_hscb()
585 saved_tag = q_hscb->tag; in ahc_swap_with_next_hscb()
586 memcpy(q_hscb, scb->hscb, sizeof(*scb->hscb)); in ahc_swap_with_next_hscb()
587 if ((scb->flags & SCB_CDB32_PTR) != 0) { in ahc_swap_with_next_hscb()
588 q_hscb->shared_data.cdb_ptr = in ahc_swap_with_next_hscb()
589 ahc_htole32(ahc_hscb_busaddr(ahc, q_hscb->tag) in ahc_swap_with_next_hscb()
592 q_hscb->tag = saved_tag; in ahc_swap_with_next_hscb()
593 q_hscb->next = scb->hscb->tag; in ahc_swap_with_next_hscb()
596 ahc->next_queued_scb->hscb = scb->hscb; in ahc_swap_with_next_hscb()
597 scb->hscb = q_hscb; in ahc_swap_with_next_hscb()
600 ahc->scb_data->scbindex[scb->hscb->tag] = scb; in ahc_swap_with_next_hscb()
611 if (scb->hscb->tag == SCB_LIST_NULL in ahc_queue_scb()
612 || scb->hscb->next == SCB_LIST_NULL) in ahc_queue_scb()
614 scb->hscb->tag, scb->hscb->next); in ahc_queue_scb()
619 scb->hscb->lun &= LID; in ahc_queue_scb()
621 scb->hscb->lun |= SCB_XFERLEN_ODD; in ahc_queue_scb()
626 ahc->qinfifo[ahc->qinfifonext++] = scb->hscb->tag; in ahc_queue_scb()
635 if ((ahc->features & AHC_QUEUE_REGS) != 0) { in ahc_queue_scb()
636 ahc_outb(ahc, HNSCB_QOFF, ahc->qinfifonext); in ahc_queue_scb()
638 if ((ahc->features & AHC_AUTOPAUSE) == 0) in ahc_queue_scb()
640 ahc_outb(ahc, KERNEL_QINPOS, ahc->qinfifonext); in ahc_queue_scb()
641 if ((ahc->features & AHC_AUTOPAUSE) == 0) in ahc_queue_scb()
651 offset = scb - ahc->scb_data->scbarray; in ahc_get_sense_buf()
652 return (&ahc->scb_data->sense[offset]); in ahc_get_sense_buf()
660 offset = scb - ahc->scb_data->scbarray; in ahc_get_sense_bufaddr()
661 return (ahc->scb_data->sense_busaddr in ahc_get_sense_bufaddr()
669 ahc_dmamap_sync(ahc, ahc->shared_data_dmat, ahc->shared_data_dmamap, in ahc_sync_qoutfifo()
677 if ((ahc->flags & AHC_TARGETROLE) != 0) { in ahc_sync_tqinfifo()
678 ahc_dmamap_sync(ahc, ahc->shared_data_dmat, in ahc_sync_tqinfifo()
679 ahc->shared_data_dmamap, in ahc_sync_tqinfifo()
689 * into our in-core command complete fifos.
699 ahc_dmamap_sync(ahc, ahc->shared_data_dmat, ahc->shared_data_dmamap, in ahc_check_cmdcmpltqueues()
700 /*offset*/ahc->qoutfifonext, /*len*/1, in ahc_check_cmdcmpltqueues()
702 if (ahc->qoutfifo[ahc->qoutfifonext] != SCB_LIST_NULL) in ahc_check_cmdcmpltqueues()
705 if ((ahc->flags & AHC_TARGETROLE) != 0 in ahc_check_cmdcmpltqueues()
706 && (ahc->flags & AHC_TQINFIFO_BLOCKED) == 0) { in ahc_check_cmdcmpltqueues()
707 ahc_dmamap_sync(ahc, ahc->shared_data_dmat, in ahc_check_cmdcmpltqueues()
708 ahc->shared_data_dmamap, in ahc_check_cmdcmpltqueues()
709 ahc_targetcmd_offset(ahc, ahc->tqinfifofnext), in ahc_check_cmdcmpltqueues()
712 if (ahc->targetcmds[ahc->tqinfifonext].cmd_valid != 0) in ahc_check_cmdcmpltqueues()
727 if ((ahc->pause & INTEN) == 0) { in ahc_intr()
730 * and may be disabled for re-entrancy reasons, in ahc_intr()
738 * infer the cause of the interrupt by checking our in-core in ahc_intr()
742 if ((ahc->flags & (AHC_ALL_INTERRUPTS|AHC_EDGE_INTERRUPT)) == 0 in ahc_intr()
751 if (ahc->unsolicited_ints > 500) { in ahc_intr()
752 ahc->unsolicited_ints = 0; in ahc_intr()
753 if ((ahc->chip & AHC_PCI) != 0 in ahc_intr()
755 ahc->bus_intr(ahc); in ahc_intr()
758 ahc->unsolicited_ints++; in ahc_intr()
761 ahc->unsolicited_ints = 0; in ahc_intr()
777 if ((ahc->flags & AHC_TARGETROLE) != 0) in ahc_intr()
786 if (intstat == 0xFF && (ahc->features & AHC_REMOVABLE) != 0) { in ahc_intr()
817 ahc_outb(ahc, SCSISIGO, 0); /* De-assert BSY */ in ahc_restart()
831 ahc_outb(ahc, TQINPOS, ahc->tqinfifonext); in ahc_restart()
836 if ((ahc->features & AHC_CMD_CHAN) != 0) { in ahc_restart()
861 ahc_outb(ahc, SEQCTL, ahc->seqctl); in ahc_restart()
882 while (ahc->qoutfifo[ahc->qoutfifonext] != SCB_LIST_NULL) { in ahc_run_qoutfifo()
884 scb_index = ahc->qoutfifo[ahc->qoutfifonext]; in ahc_run_qoutfifo()
885 if ((ahc->qoutfifonext & 0x03) == 0x03) { in ahc_run_qoutfifo()
895 modnext = ahc->qoutfifonext & ~0x3; in ahc_run_qoutfifo()
896 *((uint32_t *)(&ahc->qoutfifo[modnext])) = 0xFFFFFFFFUL; in ahc_run_qoutfifo()
897 ahc_dmamap_sync(ahc, ahc->shared_data_dmat, in ahc_run_qoutfifo()
898 ahc->shared_data_dmamap, in ahc_run_qoutfifo()
902 ahc->qoutfifonext++; in ahc_run_qoutfifo()
909 (ahc->qoutfifonext - 1) & 0xFF); in ahc_run_qoutfifo()
928 ahc_run_untagged_queue(ahc, &ahc->untagged_queues[i]); in ahc_run_untagged_queues()
936 if (ahc->untagged_queue_lock != 0) in ahc_run_untagged_queue()
940 && (scb->flags & SCB_ACTIVE) == 0) { in ahc_run_untagged_queue()
941 scb->flags |= SCB_ACTIVE; in ahc_run_untagged_queue()
951 * We upset the sequencer :-( in ahc_handle_brkadrint()
1017 printk("ahc_intr - referenced scb " in ahc_handle_seqint()
1025 hscb = scb->hscb; in ahc_handle_seqint()
1028 if ((scb->flags & SCB_SENSE) != 0) { in ahc_handle_seqint()
1034 scb->flags &= ~SCB_SENSE; in ahc_handle_seqint()
1042 ahc_set_scsi_status(scb, hscb->shared_data.status.scsi_status); in ahc_handle_seqint()
1043 switch (hscb->shared_data.status.scsi_status) { in ahc_handle_seqint()
1060 scb->hscb->tag); in ahc_handle_seqint()
1072 tinfo = &targ_info->curr; in ahc_handle_seqint()
1073 sg = scb->sg_list; in ahc_handle_seqint()
1074 sc = (struct scsi_sense *)(&hscb->shared_data.cdb); in ahc_handle_seqint()
1085 sg->addr = ahc_get_sense_bufaddr(ahc, scb); in ahc_handle_seqint()
1086 sg->len = ahc_get_sense_bufsize(ahc, scb); in ahc_handle_seqint()
1087 sg->len |= AHC_DMA_LAST_SEG; in ahc_handle_seqint()
1090 sg->addr = ahc_htole32(sg->addr); in ahc_handle_seqint()
1091 sg->len = ahc_htole32(sg->len); in ahc_handle_seqint()
1093 sc->opcode = REQUEST_SENSE; in ahc_handle_seqint()
1094 sc->byte2 = 0; in ahc_handle_seqint()
1095 if (tinfo->protocol_version <= SCSI_REV_2 in ahc_handle_seqint()
1097 sc->byte2 = SCB_GET_LUN(scb) << 5; in ahc_handle_seqint()
1098 sc->unused[0] = 0; in ahc_handle_seqint()
1099 sc->unused[1] = 0; in ahc_handle_seqint()
1100 sc->length = sg->len; in ahc_handle_seqint()
1101 sc->control = 0; in ahc_handle_seqint()
1110 hscb->control = 0; in ahc_handle_seqint()
1126 if (tstate->auto_negotiate & devinfo.target_mask) { in ahc_handle_seqint()
1127 hscb->control |= MK_MESSAGE; in ahc_handle_seqint()
1128 scb->flags &= ~SCB_NEGOTIATE; in ahc_handle_seqint()
1129 scb->flags |= SCB_AUTO_NEGOTIATE; in ahc_handle_seqint()
1131 hscb->cdb_len = sizeof(*sc); in ahc_handle_seqint()
1132 hscb->dataptr = sg->addr; in ahc_handle_seqint()
1133 hscb->datacnt = sg->len; in ahc_handle_seqint()
1134 hscb->sgptr = scb->sg_list_phys | SG_FULL_RESID; in ahc_handle_seqint()
1135 hscb->sgptr = ahc_htole32(hscb->sgptr); in ahc_handle_seqint()
1136 scb->sg_count = 1; in ahc_handle_seqint()
1137 scb->flags |= SCB_SENSE; in ahc_handle_seqint()
1159 "target - issuing BUS DEVICE RESET\n", in ahc_handle_seqint()
1182 ahc->msgout_buf[0] = TARGET_RESET; in ahc_handle_seqint()
1183 ahc->msgout_len = 1; in ahc_handle_seqint()
1184 ahc->msgout_index = 0; in ahc_handle_seqint()
1185 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT; in ahc_handle_seqint()
1193 printk("%s:%c:%d: Warning - unknown message received from " in ahc_handle_seqint()
1245 if (ahc->msg_type == MSG_TYPE_NONE) { in ahc_handle_seqint()
1278 ahc->msg_type = in ahc_handle_seqint()
1280 ahc->msgin_index = 0; in ahc_handle_seqint()
1286 ahc->msg_type = in ahc_handle_seqint()
1288 ahc->msgin_index = 0; in ahc_handle_seqint()
1307 * and we are not in a phase (data-in) where we will in ahc_handle_seqint()
1316 if ((ahc->features & AHC_DT) == 0) { in ahc_handle_seqint()
1341 while (--wait != 0) { in ahc_handle_seqint()
1393 scb->hscb->tag); in ahc_handle_seqint()
1397 ahc_get_transfer_length(scb), scb->sg_count); in ahc_handle_seqint()
1398 if (scb->sg_count > 0) { in ahc_handle_seqint()
1399 for (i = 0; i < scb->sg_count; i++) { in ahc_handle_seqint()
1401 printk("sg[%d] - Addr 0x%x%x : Length %d\n", in ahc_handle_seqint()
1403 (ahc_le32toh(scb->sg_list[i].len) >> 24 in ahc_handle_seqint()
1405 ahc_le32toh(scb->sg_list[i].addr), in ahc_handle_seqint()
1406 ahc_le32toh(scb->sg_list[i].len) in ahc_handle_seqint()
1415 if ((scb->flags & SCB_SENSE) == 0) { in ahc_handle_seqint()
1418 scb->flags &= ~SCB_SENSE; in ahc_handle_seqint()
1423 if ((ahc->features & AHC_ULTRA2) != 0) { in ahc_handle_seqint()
1433 if ((ahc->flags & AHC_39BIT_ADDRESSING) != 0) { in ahc_handle_seqint()
1454 && (scb->flags & SCB_RECOVERY_SCB) != 0) in ahc_handle_seqint()
1461 SCB_GET_LUN(scb), scb->hscb->tag, in ahc_handle_seqint()
1480 ahc->scb_data->hscbs[scbptr].tag); in ahc_handle_seqint()
1536 if ((ahc->features & AHC_TWIN) != 0 in ahc_handle_scsiint()
1543 if ((ahc->features & AHC_ULTRA2) != 0) in ahc_handle_scsiint()
1549 if ((ahc->features & AHC_TWIN) != 0) { in ahc_handle_scsiint()
1573 if ((ahc->features & AHC_ULTRA2) != 0 in ahc_handle_scsiint()
1628 * could be 'data-in' is if the parity error is for in ahc_handle_scsiint()
1630 * synchronous data-in transfers, we may actually in ahc_handle_scsiint()
1652 scb->flags |= SCB_TRANSMISSION_ERROR; in ahc_handle_scsiint()
1663 if ((ahc->features & AHC_DT) != 0) { in ahc_handle_scsiint()
1675 ? "" : "non-"); in ahc_handle_scsiint()
1679 if ((ahc->features & AHC_DT) != 0 in ahc_handle_scsiint()
1697 if (ahc->msg_type != MSG_TYPE_NONE) in ahc_handle_scsiint()
1698 ahc->send_msg_perror = TRUE; in ahc_handle_scsiint()
1741 printk("%s: ahc_intr - referenced scb not " in ahc_handle_scsiint()
1822 if (ahc->msgout_buf[ahc->msgout_index - 1] in ahc_handle_scsiint()
1824 tag = scb->hscb->tag; in ahc_handle_scsiint()
1826 printk("SCB %d - Abort%s Completed.\n", in ahc_handle_scsiint()
1827 scb->hscb->tag, tag == SCB_LIST_NULL ? in ahc_handle_scsiint()
1853 * PPR Rejected. Try non-ppr negotiation in ahc_handle_scsiint()
1861 tinfo->curr.transport_version = 2; in ahc_handle_scsiint()
1862 tinfo->goal.transport_version = 2; in ahc_handle_scsiint()
1863 tinfo->goal.ppr_options = 0; in ahc_handle_scsiint()
1869 * Negotiation Rejected. Go-narrow and in ahc_handle_scsiint()
1881 * Negotiation Rejected. Go-async and in ahc_handle_scsiint()
1900 if ((scb->hscb->control & TAG_ENB) != 0) in ahc_handle_scsiint()
1901 tag = scb->hscb->tag; in ahc_handle_scsiint()
1955 devinfo->channel, in ahc_force_renegotiation()
1956 devinfo->our_scsiid, in ahc_force_renegotiation()
1957 devinfo->target, in ahc_force_renegotiation()
1972 if (ahc->num_critical_sections == 0) in ahc_clear_critical_section()
1993 seqaddr -= 1; in ahc_clear_critical_section()
1994 cs = ahc->critical_sections; in ahc_clear_critical_section()
1995 for (i = 0; i < ahc->num_critical_sections; i++, cs++) { in ahc_clear_critical_section()
1996 if (cs->begin < seqaddr && cs->end >= seqaddr) in ahc_clear_critical_section()
2000 if (i == ahc->num_critical_sections) in ahc_clear_critical_section()
2022 if ((ahc->features & AHC_DT) != 0) in ahc_clear_critical_section()
2026 * Unfortunately we cannot re-enable in ahc_clear_critical_section()
2035 ahc_outb(ahc, SEQCTL, ahc->seqctl | STEP); in ahc_clear_critical_section()
2038 if ((ahc->features & AHC_DT) != 0) { in ahc_clear_critical_section()
2042 ahc_outb(ahc, HCNTRL, ahc->unpause); in ahc_clear_critical_section()
2049 ahc_outb(ahc, SEQCTL, ahc->seqctl); in ahc_clear_critical_section()
2081 struct hardware_scb *hscb = scb->hscb;
2085 hscb->control,
2086 hscb->scsiid,
2087 hscb->lun,
2088 hscb->cdb_len);
2090 for (i = 0; i < sizeof(hscb->shared_data.cdb); i++)
2091 printk("%#02x", hscb->shared_data.cdb[i]);
2093 ahc_le32toh(hscb->dataptr),
2094 ahc_le32toh(hscb->datacnt),
2095 ahc_le32toh(hscb->sgptr),
2096 hscb->tag);
2097 if (scb->sg_count > 0) {
2098 for (i = 0; i < scb->sg_count; i++) {
2099 printk("sg[%d] - Addr 0x%x%x : Length %d\n",
2101 (ahc_le32toh(scb->sg_list[i].len) >> 24
2103 ahc_le32toh(scb->sg_list[i].addr),
2104 ahc_le32toh(scb->sg_list[i].len));
2122 master_tstate = ahc->enabled_targets[ahc->our_id]; in ahc_alloc_tstate()
2125 master_tstate = ahc->enabled_targets[ahc->our_id_b + 8]; in ahc_alloc_tstate()
2127 if (ahc->enabled_targets[scsi_id] != NULL in ahc_alloc_tstate()
2128 && ahc->enabled_targets[scsi_id] != master_tstate) in ahc_alloc_tstate()
2129 panic("%s: ahc_alloc_tstate - Target already allocated", in ahc_alloc_tstate()
2143 memset(tstate->enabled_luns, 0, sizeof(tstate->enabled_luns)); in ahc_alloc_tstate()
2144 tstate->ultraenb = 0; in ahc_alloc_tstate()
2146 memset(&tstate->transinfo[i].curr, 0, in ahc_alloc_tstate()
2147 sizeof(tstate->transinfo[i].curr)); in ahc_alloc_tstate()
2148 memset(&tstate->transinfo[i].goal, 0, in ahc_alloc_tstate()
2149 sizeof(tstate->transinfo[i].goal)); in ahc_alloc_tstate()
2153 ahc->enabled_targets[scsi_id] = tstate; in ahc_alloc_tstate()
2171 if (((channel == 'B' && scsi_id == ahc->our_id_b) in ahc_free_tstate()
2172 || (channel == 'A' && scsi_id == ahc->our_id)) in ahc_free_tstate()
2178 tstate = ahc->enabled_targets[scsi_id]; in ahc_free_tstate()
2180 ahc->enabled_targets[scsi_id] = NULL; in ahc_free_tstate()
2198 if ((ahc->features & AHC_ULTRA2) != 0) { in ahc_devlimited_syncrate()
2207 } else if ((ahc->features & AHC_ULTRA) != 0) { in ahc_devlimited_syncrate()
2223 transinfo = &tinfo->user; in ahc_devlimited_syncrate()
2225 transinfo = &tinfo->goal; in ahc_devlimited_syncrate()
2226 *ppr_options &= transinfo->ppr_options; in ahc_devlimited_syncrate()
2227 if (transinfo->width == MSG_EXT_WDTR_BUS_8_BIT) { in ahc_devlimited_syncrate()
2231 if (transinfo->period == 0) { in ahc_devlimited_syncrate()
2236 *period = max(*period, (u_int)transinfo->period); in ahc_devlimited_syncrate()
2251 if ((ahc->features & AHC_DT) == 0) in ahc_find_syncrate()
2261 if ((ahc->features & (AHC_DT | AHC_ULTRA2)) == 0 in ahc_find_syncrate()
2264 if ((ahc->features & (AHC_DT | AHC_ULTRA2 | AHC_ULTRA)) == 0 in ahc_find_syncrate()
2269 syncrate->rate != NULL; in ahc_find_syncrate()
2274 * as for the Fast/Ultra cards. in ahc_find_syncrate()
2276 if ((ahc->features & AHC_ULTRA2) != 0 in ahc_find_syncrate()
2277 && (syncrate->sxfr_u2 == 0)) in ahc_find_syncrate()
2280 if (*period <= syncrate->period) { in ahc_find_syncrate()
2293 *period = syncrate->period; in ahc_find_syncrate()
2299 if ((syncrate->sxfr_u2 & ST_SXFR) != 0) in ahc_find_syncrate()
2306 || (syncrate->rate == NULL) in ahc_find_syncrate()
2307 || ((ahc->features & AHC_ULTRA2) != 0 in ahc_find_syncrate()
2308 && (syncrate->sxfr_u2 == 0))) { in ahc_find_syncrate()
2326 if ((ahc->features & AHC_ULTRA2) != 0) in ahc_find_period()
2332 if ((ahc->features & AHC_DT) == 0 && maxsync < AHC_SYNCRATE_ULTRA2) in ahc_find_period()
2334 if ((ahc->features & (AHC_DT | AHC_ULTRA2)) == 0 in ahc_find_period()
2337 if ((ahc->features & (AHC_DT | AHC_ULTRA2 | AHC_ULTRA)) == 0 in ahc_find_period()
2343 while (syncrate->rate != NULL) { in ahc_find_period()
2345 if ((ahc->features & AHC_ULTRA2) != 0) { in ahc_find_period()
2346 if (syncrate->sxfr_u2 == 0) in ahc_find_period()
2348 else if (scsirate == (syncrate->sxfr_u2 & SXFR_ULTRA2)) in ahc_find_period()
2349 return (syncrate->period); in ahc_find_period()
2350 } else if (scsirate == (syncrate->sxfr & SXFR)) { in ahc_find_period()
2351 return (syncrate->period); in ahc_find_period()
2373 } else if ((ahc->features & AHC_ULTRA2) != 0) { in ahc_validate_offset()
2384 *offset = min(*offset, (u_int)tinfo->user.offset); in ahc_validate_offset()
2386 *offset = min(*offset, (u_int)tinfo->goal.offset); in ahc_validate_offset()
2400 if (ahc->features & AHC_WIDE) { in ahc_validate_width()
2412 *bus_width = min((u_int)tinfo->user.width, *bus_width); in ahc_validate_width()
2414 *bus_width = min((u_int)tinfo->goal.width, *bus_width); in ahc_validate_width()
2431 auto_negotiate_orig = tstate->auto_negotiate; in ahc_update_neg_request()
2439 if ((ahc->features & AHC_WIDE) != 0) in ahc_update_neg_request()
2440 tinfo->curr.width = AHC_WIDTH_UNKNOWN; in ahc_update_neg_request()
2441 tinfo->curr.period = AHC_PERIOD_UNKNOWN; in ahc_update_neg_request()
2442 tinfo->curr.offset = AHC_OFFSET_UNKNOWN; in ahc_update_neg_request()
2444 if (tinfo->curr.period != tinfo->goal.period in ahc_update_neg_request()
2445 || tinfo->curr.width != tinfo->goal.width in ahc_update_neg_request()
2446 || tinfo->curr.offset != tinfo->goal.offset in ahc_update_neg_request()
2447 || tinfo->curr.ppr_options != tinfo->goal.ppr_options in ahc_update_neg_request()
2449 && (tinfo->goal.offset != 0 in ahc_update_neg_request()
2450 || tinfo->goal.width != MSG_EXT_WDTR_BUS_8_BIT in ahc_update_neg_request()
2451 || tinfo->goal.ppr_options != 0))) in ahc_update_neg_request()
2452 tstate->auto_negotiate |= devinfo->target_mask; in ahc_update_neg_request()
2454 tstate->auto_negotiate &= ~devinfo->target_mask; in ahc_update_neg_request()
2456 return (auto_negotiate_orig != tstate->auto_negotiate); in ahc_update_neg_request()
2488 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid, in ahc_set_syncrate()
2489 devinfo->target, &tstate); in ahc_set_syncrate()
2492 tinfo->user.period = period; in ahc_set_syncrate()
2493 tinfo->user.offset = offset; in ahc_set_syncrate()
2494 tinfo->user.ppr_options = ppr_options; in ahc_set_syncrate()
2498 tinfo->goal.period = period; in ahc_set_syncrate()
2499 tinfo->goal.offset = offset; in ahc_set_syncrate()
2500 tinfo->goal.ppr_options = ppr_options; in ahc_set_syncrate()
2503 old_period = tinfo->curr.period; in ahc_set_syncrate()
2504 old_offset = tinfo->curr.offset; in ahc_set_syncrate()
2505 old_ppr = tinfo->curr.ppr_options; in ahc_set_syncrate()
2514 scsirate = tinfo->scsirate; in ahc_set_syncrate()
2515 if ((ahc->features & AHC_ULTRA2) != 0) { in ahc_set_syncrate()
2519 scsirate |= syncrate->sxfr_u2; in ahc_set_syncrate()
2529 * Ensure Ultra mode is set properly for in ahc_set_syncrate()
2532 tstate->ultraenb &= ~devinfo->target_mask; in ahc_set_syncrate()
2534 if (syncrate->sxfr & ULTRA_SXFR) { in ahc_set_syncrate()
2535 tstate->ultraenb |= in ahc_set_syncrate()
2536 devinfo->target_mask; in ahc_set_syncrate()
2538 scsirate |= syncrate->sxfr & SXFR; in ahc_set_syncrate()
2546 if (tstate->ultraenb & devinfo->target_mask) in ahc_set_syncrate()
2553 if ((ahc->features & AHC_ULTRA2) != 0) in ahc_set_syncrate()
2557 tinfo->scsirate = scsirate; in ahc_set_syncrate()
2558 tinfo->curr.period = period; in ahc_set_syncrate()
2559 tinfo->curr.offset = offset; in ahc_set_syncrate()
2560 tinfo->curr.ppr_options = ppr_options; in ahc_set_syncrate()
2562 ahc_send_async(ahc, devinfo->channel, devinfo->target, in ahc_set_syncrate()
2568 devinfo->target, syncrate->rate, in ahc_set_syncrate()
2574 ahc_name(ahc), devinfo->target); in ahc_set_syncrate()
2606 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid, in ahc_set_width()
2607 devinfo->target, &tstate); in ahc_set_width()
2610 tinfo->user.width = width; in ahc_set_width()
2613 tinfo->goal.width = width; in ahc_set_width()
2615 oldwidth = tinfo->curr.width; in ahc_set_width()
2620 scsirate = tinfo->scsirate; in ahc_set_width()
2625 tinfo->scsirate = scsirate; in ahc_set_width()
2630 tinfo->curr.width = width; in ahc_set_width()
2632 ahc_send_async(ahc, devinfo->channel, devinfo->target, in ahc_set_width()
2636 ahc_name(ahc), devinfo->target, in ahc_set_width()
2654 struct scsi_device *sdev = cmd->device; in ahc_set_tags()
2657 ahc_send_async(ahc, devinfo->channel, devinfo->target, in ahc_set_tags()
2658 devinfo->lun, AC_TRANSFER_NEG); in ahc_set_tags()
2663 * in-transit SCBs to contain the new data so the hardware will
2680 LIST_FOREACH(pending_scb, &ahc->pending_scbs, pending_links) { in ahc_update_pending_scbs()
2690 pending_hscb = pending_scb->hscb; in ahc_update_pending_scbs()
2691 pending_hscb->control &= ~ULTRAENB; in ahc_update_pending_scbs()
2692 if ((tstate->ultraenb & devinfo.target_mask) != 0) in ahc_update_pending_scbs()
2693 pending_hscb->control |= ULTRAENB; in ahc_update_pending_scbs()
2694 pending_hscb->scsirate = tinfo->scsirate; in ahc_update_pending_scbs()
2695 pending_hscb->scsioffset = tinfo->curr.offset; in ahc_update_pending_scbs()
2696 if ((tstate->auto_negotiate & devinfo.target_mask) == 0 in ahc_update_pending_scbs()
2697 && (pending_scb->flags & SCB_AUTO_NEGOTIATE) != 0) { in ahc_update_pending_scbs()
2698 pending_scb->flags &= ~SCB_AUTO_NEGOTIATE; in ahc_update_pending_scbs()
2699 pending_hscb->control &= ~MK_MESSAGE; in ahc_update_pending_scbs()
2718 for (i = 0; i < ahc->scb_data->maxhscbs; i++) { in ahc_update_pending_scbs()
2729 pending_hscb = pending_scb->hscb; in ahc_update_pending_scbs()
2732 control |= pending_hscb->control & (ULTRAENB|MK_MESSAGE); in ahc_update_pending_scbs()
2734 ahc_outb(ahc, SCB_SCSIRATE, pending_hscb->scsirate); in ahc_update_pending_scbs()
2735 ahc_outb(ahc, SCB_SCSIOFFSET, pending_hscb->scsioffset); in ahc_update_pending_scbs()
2757 && (ahc->features & AHC_MULTI_TID) != 0 in ahc_fetch_devinfo()
2762 } else if ((ahc->features & AHC_ULTRA2) != 0) in ahc_fetch_devinfo()
2788 if (phase == entry->phase) in ahc_lookup_phase_entry()
2798 devinfo->our_scsiid = our_id; in ahc_compile_devinfo()
2799 devinfo->target = target; in ahc_compile_devinfo()
2800 devinfo->lun = lun; in ahc_compile_devinfo()
2801 devinfo->target_offset = target; in ahc_compile_devinfo()
2802 devinfo->channel = channel; in ahc_compile_devinfo()
2803 devinfo->role = role; in ahc_compile_devinfo()
2805 devinfo->target_offset += 8; in ahc_compile_devinfo()
2806 devinfo->target_mask = (0x01 << devinfo->target_offset); in ahc_compile_devinfo()
2812 printk("%s:%c:%d:%d: ", ahc_name(ahc), devinfo->channel, in ahc_print_devinfo()
2813 devinfo->target, devinfo->lun); in ahc_print_devinfo()
2823 our_id = SCSIID_OUR_ID(scb->hscb->scsiid); in ahc_scb_devinfo()
2825 if ((scb->flags & SCB_TARGET_SCB) != 0) in ahc_scb_devinfo()
2839 if ((ahc->features & AHC_DT) == 0) in ahc_assert_atn()
2859 ahc->msgout_index = 0; in ahc_setup_initiator_msgout()
2860 ahc->msgout_len = 0; in ahc_setup_initiator_msgout()
2862 if ((scb->flags & SCB_DEVICE_RESET) == 0 in ahc_setup_initiator_msgout()
2867 if ((scb->hscb->control & DISCENB) != 0) in ahc_setup_initiator_msgout()
2869 ahc->msgout_buf[ahc->msgout_index++] = identify_msg; in ahc_setup_initiator_msgout()
2870 ahc->msgout_len++; in ahc_setup_initiator_msgout()
2872 if ((scb->hscb->control & TAG_ENB) != 0) { in ahc_setup_initiator_msgout()
2873 ahc->msgout_buf[ahc->msgout_index++] = in ahc_setup_initiator_msgout()
2874 scb->hscb->control & (TAG_ENB|SCB_TAG_TYPE); in ahc_setup_initiator_msgout()
2875 ahc->msgout_buf[ahc->msgout_index++] = scb->hscb->tag; in ahc_setup_initiator_msgout()
2876 ahc->msgout_len += 2; in ahc_setup_initiator_msgout()
2880 if (scb->flags & SCB_DEVICE_RESET) { in ahc_setup_initiator_msgout()
2881 ahc->msgout_buf[ahc->msgout_index++] = TARGET_RESET; in ahc_setup_initiator_msgout()
2882 ahc->msgout_len++; in ahc_setup_initiator_msgout()
2893 } else if ((scb->flags & SCB_ABORT) != 0) { in ahc_setup_initiator_msgout()
2894 if ((scb->hscb->control & TAG_ENB) != 0) in ahc_setup_initiator_msgout()
2895 ahc->msgout_buf[ahc->msgout_index++] = ABORT_TASK; in ahc_setup_initiator_msgout()
2897 ahc->msgout_buf[ahc->msgout_index++] = ABORT_TASK_SET; in ahc_setup_initiator_msgout()
2898 ahc->msgout_len++; in ahc_setup_initiator_msgout()
2901 (scb->hscb->control & TAG_ENB) != 0 ? " Tag" : ""); in ahc_setup_initiator_msgout()
2910 } else if ((scb->flags & (SCB_AUTO_NEGOTIATE|SCB_NEGOTIATE)) != 0) { in ahc_setup_initiator_msgout()
2915 printk("SCSIID = %x, target_mask = %x\n", scb->hscb->scsiid, in ahc_setup_initiator_msgout()
2916 devinfo->target_mask); in ahc_setup_initiator_msgout()
2918 "SCB flags = %x", scb->hscb->tag, scb->hscb->control, in ahc_setup_initiator_msgout()
2919 ahc_inb(ahc, MSG_OUT), scb->flags); in ahc_setup_initiator_msgout()
2927 scb->hscb->control &= ~MK_MESSAGE; in ahc_setup_initiator_msgout()
2928 ahc->msgout_index = 0; in ahc_setup_initiator_msgout()
2929 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT; in ahc_setup_initiator_msgout()
2954 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid, in ahc_build_transfer_msg()
2955 devinfo->target, &tstate); in ahc_build_transfer_msg()
2962 period = tinfo->goal.period; in ahc_build_transfer_msg()
2963 offset = tinfo->goal.offset; in ahc_build_transfer_msg()
2964 ppr_options = tinfo->goal.ppr_options; in ahc_build_transfer_msg()
2966 if (devinfo->role == ROLE_TARGET) in ahc_build_transfer_msg()
2969 &ppr_options, devinfo->role); in ahc_build_transfer_msg()
2970 dowide = tinfo->curr.width != tinfo->goal.width; in ahc_build_transfer_msg()
2971 dosync = tinfo->curr.offset != offset || tinfo->curr.period != period; in ahc_build_transfer_msg()
2980 dowide = tinfo->goal.width != MSG_EXT_WDTR_BUS_8_BIT; in ahc_build_transfer_msg()
2981 dosync = tinfo->goal.offset != 0; in ahc_build_transfer_msg()
2989 if ((ahc->features & AHC_WIDE) != 0) in ahc_build_transfer_msg()
3001 if (devinfo->role == ROLE_TARGET) in ahc_build_transfer_msg()
3007 * is capable of handling (based on whether an LVD->SE in ahc_build_transfer_msg()
3014 offset = tinfo->goal.offset; in ahc_build_transfer_msg()
3016 doppr ? tinfo->goal.width in ahc_build_transfer_msg()
3017 : tinfo->curr.width, in ahc_build_transfer_msg()
3018 devinfo->role); in ahc_build_transfer_msg()
3021 tinfo->goal.width, ppr_options); in ahc_build_transfer_msg()
3026 ahc_construct_wdtr(ahc, devinfo, tinfo->goal.width); in ahc_build_transfer_msg()
3040 ahc->msgout_index += spi_populate_sync_msg( in ahc_construct_sdtr()
3041 ahc->msgout_buf + ahc->msgout_index, period, offset); in ahc_construct_sdtr()
3042 ahc->msgout_len += 5; in ahc_construct_sdtr()
3045 ahc_name(ahc), devinfo->channel, devinfo->target, in ahc_construct_sdtr()
3046 devinfo->lun, period, offset); in ahc_construct_sdtr()
3058 ahc->msgout_index += spi_populate_width_msg( in ahc_construct_wdtr()
3059 ahc->msgout_buf + ahc->msgout_index, bus_width); in ahc_construct_wdtr()
3060 ahc->msgout_len += 4; in ahc_construct_wdtr()
3063 ahc_name(ahc), devinfo->channel, devinfo->target, in ahc_construct_wdtr()
3064 devinfo->lun, bus_width); in ahc_construct_wdtr()
3079 ahc->msgout_index += spi_populate_ppr_msg( in ahc_construct_ppr()
3080 ahc->msgout_buf + ahc->msgout_index, period, offset, in ahc_construct_ppr()
3082 ahc->msgout_len += 8; in ahc_construct_ppr()
3086 devinfo->channel, devinfo->target, devinfo->lun, in ahc_construct_ppr()
3097 ahc->msgout_len = 0; in ahc_clear_msg_state()
3098 ahc->msgin_index = 0; in ahc_clear_msg_state()
3099 ahc->msg_type = MSG_TYPE_NONE; in ahc_clear_msg_state()
3193 ahc->msgout_buf[0] = ABORT_TASK; in ahc_handle_proto_violation()
3194 ahc->msgout_len = 1; in ahc_handle_proto_violation()
3195 ahc->msgout_index = 0; in ahc_handle_proto_violation()
3196 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT; in ahc_handle_proto_violation()
3199 scb->flags |= SCB_ABORT; in ahc_handle_proto_violation()
3202 ahc_lookup_phase_entry(curphase)->phasemsg); in ahc_handle_proto_violation()
3221 switch (ahc->msg_type) { in ahc_handle_message_phase()
3228 if (ahc->msgout_len == 0) in ahc_handle_message_phase()
3243 ->phasemsg); in ahc_handle_message_phase()
3254 ahc->send_msg_perror = FALSE; in ahc_handle_message_phase()
3255 ahc->msg_type = MSG_TYPE_INITIATOR_MSGIN; in ahc_handle_message_phase()
3256 ahc->msgin_index = 0; in ahc_handle_message_phase()
3263 if (ahc->send_msg_perror) { in ahc_handle_message_phase()
3268 printk(" byte 0x%x\n", ahc->send_msg_perror); in ahc_handle_message_phase()
3274 msgdone = ahc->msgout_index == ahc->msgout_len; in ahc_handle_message_phase()
3278 * Re-assert ATN, reset our message index to in ahc_handle_message_phase()
3281 ahc->msgout_index = 0; in ahc_handle_message_phase()
3285 lastbyte = ahc->msgout_index == (ahc->msgout_len - 1); in ahc_handle_message_phase()
3299 ahc->msgout_buf[ahc->msgout_index]); in ahc_handle_message_phase()
3301 ahc_outb(ahc, SCSIDATL, ahc->msgout_buf[ahc->msgout_index++]); in ahc_handle_message_phase()
3321 ->phasemsg); in ahc_handle_message_phase()
3324 ahc->msgin_index = 0; in ahc_handle_message_phase()
3326 && (ahc->send_msg_perror == TRUE in ahc_handle_message_phase()
3327 || (ahc->msgout_len != 0 in ahc_handle_message_phase()
3328 && ahc->msgout_index == 0))) { in ahc_handle_message_phase()
3329 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT; in ahc_handle_message_phase()
3337 ahc->msgin_buf[ahc->msgin_index] = ahc_inb(ahc, SCSIBUSL); in ahc_handle_message_phase()
3341 ahc->msgin_buf[ahc->msgin_index]); in ahc_handle_message_phase()
3351 ahc->msgin_index = 0; in ahc_handle_message_phase()
3358 if (ahc->msgout_len != 0) { in ahc_handle_message_phase()
3368 ahc->msgin_index++; in ahc_handle_message_phase()
3384 if (ahc->msgout_len == 0) in ahc_handle_message_phase()
3394 && ahc->msgout_index > 0) in ahc_handle_message_phase()
3407 ahc->msg_type = MSG_TYPE_TARGET_MSGOUT; in ahc_handle_message_phase()
3409 ahc->msgin_index = 0; in ahc_handle_message_phase()
3417 msgdone = ahc->msgout_index == ahc->msgout_len; in ahc_handle_message_phase()
3429 ahc_outb(ahc, SCSIDATL, ahc->msgout_buf[ahc->msgout_index++]); in ahc_handle_message_phase()
3449 ahc->msgin_buf[ahc->msgin_index] = ahc_inb(ahc, SCSIDATL); in ahc_handle_message_phase()
3461 ahc->msgin_index++; in ahc_handle_message_phase()
3468 ahc->msgin_index = 0; in ahc_handle_message_phase()
3474 if (ahc->msgout_len != 0) { in ahc_handle_message_phase()
3478 ahc->msg_type = MSG_TYPE_TARGET_MSGIN; in ahc_handle_message_phase()
3479 ahc->msgin_index = 0; in ahc_handle_message_phase()
3520 while (index < ahc->msgout_len) { in ahc_sent_msg()
3521 if (ahc->msgout_buf[index] == EXTENDED_MESSAGE) { in ahc_sent_msg()
3524 end_index = index + 1 + ahc->msgout_buf[index + 1]; in ahc_sent_msg()
3525 if (ahc->msgout_buf[index+2] == msgval in ahc_sent_msg()
3529 if (ahc->msgout_index > end_index) in ahc_sent_msg()
3531 } else if (ahc->msgout_index > index) in ahc_sent_msg()
3535 } else if (ahc->msgout_buf[index] >= SIMPLE_QUEUE_TAG in ahc_sent_msg()
3536 && ahc->msgout_buf[index] <= IGNORE_WIDE_RESIDUE) { in ahc_sent_msg()
3543 && ahc->msgout_buf[index] == msgval in ahc_sent_msg()
3544 && ahc->msgout_index > index) in ahc_sent_msg()
3571 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid, in ahc_parse_msg()
3572 devinfo->target, &tstate); in ahc_parse_msg()
3573 targ_scsirate = tinfo->scsirate; in ahc_parse_msg()
3586 switch (ahc->msgin_buf[0]) { in ahc_parse_msg()
3607 if (ahc->msgin_index < 2) in ahc_parse_msg()
3609 switch (ahc->msgin_buf[2]) { in ahc_parse_msg()
3618 if (ahc->msgin_buf[1] != MSG_EXT_SDTR_LEN) { in ahc_parse_msg()
3630 if (ahc->msgin_index < (MSG_EXT_SDTR_LEN + 1)) in ahc_parse_msg()
3633 period = ahc->msgin_buf[3]; in ahc_parse_msg()
3635 saved_offset = offset = ahc->msgin_buf[4]; in ahc_parse_msg()
3638 devinfo->role); in ahc_parse_msg()
3641 devinfo->role); in ahc_parse_msg()
3646 ahc_name(ahc), devinfo->channel, in ahc_parse_msg()
3647 devinfo->target, devinfo->lun, in ahc_parse_msg()
3648 ahc->msgin_buf[3], saved_offset, in ahc_parse_msg()
3665 /* Went too low - force async */ in ahc_parse_msg()
3673 && devinfo->role == ROLE_INITIATOR) { in ahc_parse_msg()
3676 ahc_name(ahc), devinfo->channel, in ahc_parse_msg()
3677 devinfo->target, devinfo->lun); in ahc_parse_msg()
3679 ahc->msgout_index = 0; in ahc_parse_msg()
3680 ahc->msgout_len = 0; in ahc_parse_msg()
3683 ahc->msgout_index = 0; in ahc_parse_msg()
3696 if (ahc->msgin_buf[1] != MSG_EXT_WDTR_LEN) { in ahc_parse_msg()
3708 if (ahc->msgin_index < (MSG_EXT_WDTR_LEN + 1)) in ahc_parse_msg()
3711 bus_width = ahc->msgin_buf[3]; in ahc_parse_msg()
3714 devinfo->role); in ahc_parse_msg()
3718 ahc_name(ahc), devinfo->channel, in ahc_parse_msg()
3719 devinfo->target, devinfo->lun, in ahc_parse_msg()
3734 ahc_name(ahc), devinfo->channel, in ahc_parse_msg()
3735 devinfo->target, devinfo->lun, in ahc_parse_msg()
3744 && devinfo->role == ROLE_INITIATOR) { in ahc_parse_msg()
3747 ahc_name(ahc), devinfo->channel, in ahc_parse_msg()
3748 devinfo->target, devinfo->lun); in ahc_parse_msg()
3750 ahc->msgout_index = 0; in ahc_parse_msg()
3751 ahc->msgout_len = 0; in ahc_parse_msg()
3753 ahc->msgout_index = 0; in ahc_parse_msg()
3776 ahc->msgout_index = 0; in ahc_parse_msg()
3777 ahc->msgout_len = 0; in ahc_parse_msg()
3779 ahc->msgout_index = 0; in ahc_parse_msg()
3796 if (ahc->msgin_buf[1] != MSG_EXT_PPR_LEN) { in ahc_parse_msg()
3808 if (ahc->msgin_index < (MSG_EXT_PPR_LEN + 1)) in ahc_parse_msg()
3811 period = ahc->msgin_buf[3]; in ahc_parse_msg()
3812 offset = ahc->msgin_buf[5]; in ahc_parse_msg()
3813 bus_width = ahc->msgin_buf[6]; in ahc_parse_msg()
3815 ppr_options = ahc->msgin_buf[7]; in ahc_parse_msg()
3837 devinfo->role); in ahc_parse_msg()
3840 devinfo->role); in ahc_parse_msg()
3843 devinfo->role); in ahc_parse_msg()
3862 if (devinfo->role != ROLE_TARGET) in ahc_parse_msg()
3865 ahc_name(ahc), devinfo->channel, in ahc_parse_msg()
3866 devinfo->target, devinfo->lun); in ahc_parse_msg()
3870 ahc_name(ahc), devinfo->channel, in ahc_parse_msg()
3871 devinfo->target, devinfo->lun); in ahc_parse_msg()
3872 ahc->msgout_index = 0; in ahc_parse_msg()
3873 ahc->msgout_len = 0; in ahc_parse_msg()
3876 ahc->msgout_index = 0; in ahc_parse_msg()
3884 ahc_name(ahc), devinfo->channel, in ahc_parse_msg()
3885 devinfo->target, devinfo->lun, in ahc_parse_msg()
3886 saved_width, ahc->msgin_buf[3], in ahc_parse_msg()
3924 if (devinfo->role != ROLE_TARGET) { in ahc_parse_msg()
3929 if (ahc->msgin_buf[0] == ABORT_TASK) in ahc_parse_msg()
3931 ahc_abort_scbs(ahc, devinfo->target, devinfo->channel, in ahc_parse_msg()
3932 devinfo->lun, tag, ROLE_TARGET, in ahc_parse_msg()
3935 tstate = ahc->enabled_targets[devinfo->our_scsiid]; in ahc_parse_msg()
3939 lstate = tstate->enabled_luns[devinfo->lun]; in ahc_parse_msg()
3942 devinfo->our_scsiid, in ahc_parse_msg()
3943 ahc->msgin_buf[0], in ahc_parse_msg()
3963 ahc->msgout_index = 0; in ahc_parse_msg()
3964 ahc->msgout_len = 1; in ahc_parse_msg()
3965 ahc->msgout_buf[0] = MESSAGE_REJECT; in ahc_parse_msg()
3972 ahc->msgout_len = 0; in ahc_parse_msg()
3998 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, in ahc_handle_msg_reject()
3999 devinfo->our_scsiid, in ahc_handle_msg_reject()
4000 devinfo->target, &tstate); in ahc_handle_msg_reject()
4007 * Attempt to negotiate SPI-2 style. in ahc_handle_msg_reject()
4012 ahc_name(ahc), devinfo->channel, in ahc_handle_msg_reject()
4013 devinfo->target, devinfo->lun); in ahc_handle_msg_reject()
4015 tinfo->goal.ppr_options = 0; in ahc_handle_msg_reject()
4016 tinfo->curr.transport_version = 2; in ahc_handle_msg_reject()
4017 tinfo->goal.transport_version = 2; in ahc_handle_msg_reject()
4018 ahc->msgout_index = 0; in ahc_handle_msg_reject()
4019 ahc->msgout_len = 0; in ahc_handle_msg_reject()
4021 ahc->msgout_index = 0; in ahc_handle_msg_reject()
4028 devinfo->channel, devinfo->target, devinfo->lun); in ahc_handle_msg_reject()
4039 if (tinfo->goal.offset != tinfo->curr.offset) { in ahc_handle_msg_reject()
4042 ahc->msgout_index = 0; in ahc_handle_msg_reject()
4043 ahc->msgout_len = 0; in ahc_handle_msg_reject()
4045 ahc->msgout_index = 0; in ahc_handle_msg_reject()
4056 ahc_name(ahc), devinfo->channel, in ahc_handle_msg_reject()
4057 devinfo->target, devinfo->lun); in ahc_handle_msg_reject()
4058 } else if ((scb->hscb->control & SIMPLE_QUEUE_TAG) != 0) { in ahc_handle_msg_reject()
4062 tag_type = (scb->hscb->control & SIMPLE_QUEUE_TAG); in ahc_handle_msg_reject()
4066 "Performing non-tagged I/O\n", ahc_name(ahc), in ahc_handle_msg_reject()
4067 devinfo->channel, devinfo->target, devinfo->lun); in ahc_handle_msg_reject()
4068 ahc_set_tags(ahc, scb->io_ctx, devinfo, AHC_QUEUE_NONE); in ahc_handle_msg_reject()
4073 ahc_name(ahc), devinfo->channel, devinfo->target, in ahc_handle_msg_reject()
4074 devinfo->lun, tag_type == ORDERED_QUEUE_TAG in ahc_handle_msg_reject()
4076 ahc_set_tags(ahc, scb->io_ctx, devinfo, AHC_QUEUE_BASIC); in ahc_handle_msg_reject()
4086 scb->hscb->control &= mask; in ahc_handle_msg_reject()
4096 if ((ahc->flags & AHC_SCB_BTT) == 0) { in ahc_handle_msg_reject()
4100 &(ahc->untagged_queues[devinfo->target_offset]); in ahc_handle_msg_reject()
4102 scb->flags |= SCB_UNTAGGEDQ; in ahc_handle_msg_reject()
4104 ahc_busy_tcl(ahc, BUILD_TCL(scb->hscb->scsiid, devinfo->lun), in ahc_handle_msg_reject()
4105 scb->hscb->tag); in ahc_handle_msg_reject()
4121 printk("%s:%c:%d: Message reject for %x -- ignored\n", in ahc_handle_msg_reject()
4122 ahc_name(ahc), devinfo->channel, devinfo->target, in ahc_handle_msg_reject()
4190 data_addr -= 1; in ahc_handle_ign_wide_residue()
4199 sg--; in ahc_handle_ign_wide_residue()
4200 sglen = ahc_le32toh(sg->len) & AHC_SG_LEN_MASK; in ahc_handle_ign_wide_residue()
4201 if (sg != scb->sg_list in ahc_handle_ign_wide_residue()
4204 sg--; in ahc_handle_ign_wide_residue()
4205 sglen = ahc_le32toh(sg->len); in ahc_handle_ign_wide_residue()
4211 data_addr = ahc_le32toh(sg->addr) in ahc_handle_ign_wide_residue()
4212 + (sglen & AHC_SG_LEN_MASK) - 1; in ahc_handle_ign_wide_residue()
4225 * to handle this mid-transfer ignore wide in ahc_handle_ign_wide_residue()
4261 sg--; in ahc_reinitialize_dataptrs()
4267 dataptr = ahc_le32toh(sg->addr) in ahc_reinitialize_dataptrs()
4268 + (ahc_le32toh(sg->len) & AHC_SG_LEN_MASK) in ahc_reinitialize_dataptrs()
4269 - resid; in ahc_reinitialize_dataptrs()
4270 if ((ahc->flags & AHC_39BIT_ADDRESSING) != 0) { in ahc_reinitialize_dataptrs()
4276 (ahc_le32toh(sg->len) >> 24) & SG_HIGH_ADDR_BITS); in ahc_reinitialize_dataptrs()
4286 if ((ahc->features & AHC_ULTRA2) == 0) { in ahc_reinitialize_dataptrs()
4306 found = ahc_abort_scbs(ahc, devinfo->target, devinfo->channel, in ahc_handle_devreset()
4307 CAM_LUN_WILDCARD, SCB_LIST_NULL, devinfo->role, in ahc_handle_devreset()
4315 tstate = ahc->enabled_targets[devinfo->our_scsiid]; in ahc_handle_devreset()
4320 lstate = tstate->enabled_luns[lun]; in ahc_handle_devreset()
4324 ahc_queue_lstate_event(ahc, lstate, devinfo->our_scsiid, in ahc_handle_devreset()
4341 ahc_send_async(ahc, devinfo->channel, devinfo->target, in ahc_handle_devreset()
4347 message, devinfo->channel, devinfo->target, found); in ahc_handle_devreset()
4361 ahc->msgout_index = 0; in ahc_setup_target_msgin()
4362 ahc->msgout_len = 0; in ahc_setup_target_msgin()
4364 if (scb != NULL && (scb->flags & SCB_AUTO_NEGOTIATE) != 0) in ahc_setup_target_msgin()
4369 ahc->msgout_index = 0; in ahc_setup_target_msgin()
4370 ahc->msg_type = MSG_TYPE_TARGET_MSGIN; in ahc_setup_target_msgin()
4391 ahc->seep_config = kmalloc(sizeof(*ahc->seep_config), GFP_ATOMIC); in ahc_alloc()
4392 if (ahc->seep_config == NULL) { in ahc_alloc()
4397 LIST_INIT(&ahc->pending_scbs); in ahc_alloc()
4399 ahc->name = name; in ahc_alloc()
4400 ahc->unit = -1; in ahc_alloc()
4401 ahc->description = NULL; in ahc_alloc()
4402 ahc->channel = 'A'; in ahc_alloc()
4403 ahc->channel_b = 'B'; in ahc_alloc()
4404 ahc->chip = AHC_NONE; in ahc_alloc()
4405 ahc->features = AHC_FENONE; in ahc_alloc()
4406 ahc->bugs = AHC_BUGNONE; in ahc_alloc()
4407 ahc->flags = AHC_FNONE; in ahc_alloc()
4413 ahc->seqctl = FASTMODE; in ahc_alloc()
4416 TAILQ_INIT(&ahc->untagged_queues[i]); in ahc_alloc()
4429 if ((ahc->chip & AHC_PCI) == 0) in ahc_softc_init()
4430 ahc->unpause = ahc_inb(ahc, HCNTRL) & IRQMS; in ahc_softc_init()
4432 ahc->unpause = 0; in ahc_softc_init()
4433 ahc->pause = ahc->unpause | PAUSE; in ahc_softc_init()
4435 if (ahc->scb_data == NULL) { in ahc_softc_init()
4436 ahc->scb_data = kzalloc(sizeof(*ahc->scb_data), GFP_ATOMIC); in ahc_softc_init()
4437 if (ahc->scb_data == NULL) in ahc_softc_init()
4447 ahc->unit = unit; in ahc_set_unit()
4453 kfree(ahc->name); in ahc_set_name()
4454 ahc->name = name; in ahc_set_name()
4462 switch (ahc->init_level) { in ahc_free()
4468 ahc_dmamap_unload(ahc, ahc->shared_data_dmat, in ahc_free()
4469 ahc->shared_data_dmamap); in ahc_free()
4472 ahc_dmamem_free(ahc, ahc->shared_data_dmat, ahc->qoutfifo, in ahc_free()
4473 ahc->shared_data_dmamap); in ahc_free()
4474 ahc_dmamap_destroy(ahc, ahc->shared_data_dmat, in ahc_free()
4475 ahc->shared_data_dmamap); in ahc_free()
4478 ahc_dma_tag_destroy(ahc, ahc->shared_data_dmat); in ahc_free()
4491 tstate = ahc->enabled_targets[i]; in ahc_free()
4499 lstate = tstate->enabled_luns[j]; in ahc_free()
4501 xpt_free_path(lstate->path); in ahc_free()
4510 if (ahc->black_hole != NULL) { in ahc_free()
4511 xpt_free_path(ahc->black_hole->path); in ahc_free()
4512 kfree(ahc->black_hole); in ahc_free()
4515 kfree(ahc->name); in ahc_free()
4516 kfree(ahc->seep_config); in ahc_free()
4542 * non-zero, this reset occurred after initial configuration
4563 if ((ahc->chip & AHC_CHIPID_MASK) == AHC_AIC7770) { in ahc_reset()
4577 ahc_outb(ahc, HCNTRL, CHIPRST | ahc->pause); in ahc_reset()
4588 } while (--wait && !(ahc_inb(ahc, HCNTRL) & CHIPRSTACK)); in ahc_reset()
4591 printk("%s: WARNING - Failed chip reset! " in ahc_reset()
4594 ahc_outb(ahc, HCNTRL, ahc->pause); in ahc_reset()
4599 if ((ahc->chip & AHC_PCI) != 0) in ahc_reset()
4607 ahc->features |= AHC_WIDE; in ahc_reset()
4611 ahc->features |= AHC_TWIN; in ahc_reset()
4615 return(-1); in ahc_reset()
4623 * to a tri-state condition which can only be cleared in ahc_reset()
4626 if ((ahc->features & AHC_TWIN) != 0) { in ahc_reset()
4640 * re-initialize the chip to our liking. in ahc_reset()
4642 error = ahc->bus_chip_init(ahc); in ahc_reset()
4677 *baddr = segs->ds_addr; in ahc_dmamap_cb()
4687 if ((ahc->flags & AHC_LSCBS_ENABLED) != 0) in ahc_build_free_scb_list()
4690 for (i = 0; i < ahc->scb_data->maxhscbs; i++) { in ahc_build_free_scb_list()
4707 if ((ahc->flags & AHC_PAGESCBS) != 0) in ahc_build_free_scb_list()
4718 if ((ahc->flags & AHC_PAGESCBS) != 0) { in ahc_build_free_scb_list()
4727 ahc_outb(ahc, SCBPTR, i-1); in ahc_build_free_scb_list()
4736 scb_data = ahc->scb_data; in ahc_init_scbdata()
4737 SLIST_INIT(&scb_data->free_scbs); in ahc_init_scbdata()
4738 SLIST_INIT(&scb_data->sg_maps); in ahc_init_scbdata()
4741 scb_data->scbarray = kcalloc(AHC_SCB_MAX_ALLOC, sizeof(struct scb), in ahc_init_scbdata()
4743 if (scb_data->scbarray == NULL) in ahc_init_scbdata()
4748 scb_data->maxhscbs = ahc_probe_scbs(ahc); in ahc_init_scbdata()
4749 if (ahc->scb_data->maxhscbs == 0) { in ahc_init_scbdata()
4765 if (ahc_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1, in ahc_init_scbdata()
4773 /*flags*/0, &scb_data->hscb_dmat) != 0) { in ahc_init_scbdata()
4777 scb_data->init_level++; in ahc_init_scbdata()
4780 if (ahc_dmamem_alloc(ahc, scb_data->hscb_dmat, in ahc_init_scbdata()
4781 (void **)&scb_data->hscbs, in ahc_init_scbdata()
4782 BUS_DMA_NOWAIT, &scb_data->hscb_dmamap) != 0) { in ahc_init_scbdata()
4786 scb_data->init_level++; in ahc_init_scbdata()
4789 ahc_dmamap_load(ahc, scb_data->hscb_dmat, scb_data->hscb_dmamap, in ahc_init_scbdata()
4790 scb_data->hscbs, in ahc_init_scbdata()
4792 ahc_dmamap_cb, &scb_data->hscb_busaddr, /*flags*/0); in ahc_init_scbdata()
4794 scb_data->init_level++; in ahc_init_scbdata()
4797 if (ahc_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1, in ahc_init_scbdata()
4805 /*flags*/0, &scb_data->sense_dmat) != 0) { in ahc_init_scbdata()
4809 scb_data->init_level++; in ahc_init_scbdata()
4812 if (ahc_dmamem_alloc(ahc, scb_data->sense_dmat, in ahc_init_scbdata()
4813 (void **)&scb_data->sense, in ahc_init_scbdata()
4814 BUS_DMA_NOWAIT, &scb_data->sense_dmamap) != 0) { in ahc_init_scbdata()
4818 scb_data->init_level++; in ahc_init_scbdata()
4821 ahc_dmamap_load(ahc, scb_data->sense_dmat, scb_data->sense_dmamap, in ahc_init_scbdata()
4822 scb_data->sense, in ahc_init_scbdata()
4824 ahc_dmamap_cb, &scb_data->sense_busaddr, /*flags*/0); in ahc_init_scbdata()
4826 scb_data->init_level++; in ahc_init_scbdata()
4829 if (ahc_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/8, in ahc_init_scbdata()
4836 /*flags*/0, &scb_data->sg_dmat) != 0) { in ahc_init_scbdata()
4840 scb_data->init_level++; in ahc_init_scbdata()
4843 memset(scb_data->hscbs, 0, in ahc_init_scbdata()
4847 if (scb_data->numscbs == 0) { in ahc_init_scbdata()
4848 printk("%s: ahc_init_scbdata - " in ahc_init_scbdata()
4857 ahc->next_queued_scb = ahc_get_scb(ahc); in ahc_init_scbdata()
4874 scb_data = ahc->scb_data; in ahc_fini_scbdata()
4878 switch (scb_data->init_level) { in ahc_fini_scbdata()
4884 while ((sg_map = SLIST_FIRST(&scb_data->sg_maps))!= NULL) { in ahc_fini_scbdata()
4885 SLIST_REMOVE_HEAD(&scb_data->sg_maps, links); in ahc_fini_scbdata()
4886 ahc_dmamap_unload(ahc, scb_data->sg_dmat, in ahc_fini_scbdata()
4887 sg_map->sg_dmamap); in ahc_fini_scbdata()
4888 ahc_dmamem_free(ahc, scb_data->sg_dmat, in ahc_fini_scbdata()
4889 sg_map->sg_vaddr, in ahc_fini_scbdata()
4890 sg_map->sg_dmamap); in ahc_fini_scbdata()
4893 ahc_dma_tag_destroy(ahc, scb_data->sg_dmat); in ahc_fini_scbdata()
4897 ahc_dmamap_unload(ahc, scb_data->sense_dmat, in ahc_fini_scbdata()
4898 scb_data->sense_dmamap); in ahc_fini_scbdata()
4901 ahc_dmamem_free(ahc, scb_data->sense_dmat, scb_data->sense, in ahc_fini_scbdata()
4902 scb_data->sense_dmamap); in ahc_fini_scbdata()
4903 ahc_dmamap_destroy(ahc, scb_data->sense_dmat, in ahc_fini_scbdata()
4904 scb_data->sense_dmamap); in ahc_fini_scbdata()
4907 ahc_dma_tag_destroy(ahc, scb_data->sense_dmat); in ahc_fini_scbdata()
4910 ahc_dmamap_unload(ahc, scb_data->hscb_dmat, in ahc_fini_scbdata()
4911 scb_data->hscb_dmamap); in ahc_fini_scbdata()
4914 ahc_dmamem_free(ahc, scb_data->hscb_dmat, scb_data->hscbs, in ahc_fini_scbdata()
4915 scb_data->hscb_dmamap); in ahc_fini_scbdata()
4916 ahc_dmamap_destroy(ahc, scb_data->hscb_dmat, in ahc_fini_scbdata()
4917 scb_data->hscb_dmamap); in ahc_fini_scbdata()
4920 ahc_dma_tag_destroy(ahc, scb_data->hscb_dmat); in ahc_fini_scbdata()
4925 kfree(scb_data->scbarray); in ahc_fini_scbdata()
4939 scb_data = ahc->scb_data; in ahc_alloc_scbs()
4940 if (scb_data->numscbs >= AHC_SCB_MAX_ALLOC) in ahc_alloc_scbs()
4944 next_scb = &scb_data->scbarray[scb_data->numscbs]; in ahc_alloc_scbs()
4952 if (ahc_dmamem_alloc(ahc, scb_data->sg_dmat, in ahc_alloc_scbs()
4953 (void **)&sg_map->sg_vaddr, in ahc_alloc_scbs()
4954 BUS_DMA_NOWAIT, &sg_map->sg_dmamap) != 0) { in ahc_alloc_scbs()
4959 SLIST_INSERT_HEAD(&scb_data->sg_maps, sg_map, links); in ahc_alloc_scbs()
4961 ahc_dmamap_load(ahc, scb_data->sg_dmat, sg_map->sg_dmamap, in ahc_alloc_scbs()
4962 sg_map->sg_vaddr, PAGE_SIZE, ahc_dmamap_cb, in ahc_alloc_scbs()
4963 &sg_map->sg_physaddr, /*flags*/0); in ahc_alloc_scbs()
4965 segs = sg_map->sg_vaddr; in ahc_alloc_scbs()
4966 physaddr = sg_map->sg_physaddr; in ahc_alloc_scbs()
4969 newcount = min(newcount, (AHC_SCB_MAX_ALLOC - scb_data->numscbs)); in ahc_alloc_scbs()
4976 next_scb->platform_data = pdata; in ahc_alloc_scbs()
4977 next_scb->sg_map = sg_map; in ahc_alloc_scbs()
4978 next_scb->sg_list = segs; in ahc_alloc_scbs()
4983 next_scb->sg_list_phys = physaddr + sizeof(struct ahc_dma_seg); in ahc_alloc_scbs()
4984 next_scb->ahc_softc = ahc; in ahc_alloc_scbs()
4985 next_scb->flags = SCB_FREE; in ahc_alloc_scbs()
4986 next_scb->hscb = &scb_data->hscbs[scb_data->numscbs]; in ahc_alloc_scbs()
4987 next_scb->hscb->tag = ahc->scb_data->numscbs; in ahc_alloc_scbs()
4988 SLIST_INSERT_HEAD(&ahc->scb_data->free_scbs, in ahc_alloc_scbs()
4993 ahc->scb_data->numscbs++; in ahc_alloc_scbs()
5002 len = sprintf(buf, "%s: ", ahc_chip_names[ahc->chip & AHC_CHIPID_MASK]); in ahc_controller_info()
5004 if ((ahc->features & AHC_TWIN) != 0) in ahc_controller_info()
5007 ahc->our_id, ahc->our_id_b, in ahc_controller_info()
5008 (ahc->flags & AHC_PRIMARY_CHANNEL) + 'A'); in ahc_controller_info()
5014 if ((ahc->features & AHC_ULTRA) != 0) { in ahc_controller_info()
5015 speed = "Ultra "; in ahc_controller_info()
5016 } else if ((ahc->features & AHC_DT) != 0) { in ahc_controller_info()
5018 } else if ((ahc->features & AHC_ULTRA2) != 0) { in ahc_controller_info()
5021 if ((ahc->features & AHC_WIDE) != 0) { in ahc_controller_info()
5027 speed, type, ahc->channel, ahc->our_id); in ahc_controller_info()
5031 if ((ahc->flags & AHC_PAGESCBS) != 0) in ahc_controller_info()
5033 ahc->scb_data->maxhscbs, AHC_MAX_QUEUE); in ahc_controller_info()
5035 sprintf(buf, "%d SCBs", ahc->scb_data->maxhscbs); in ahc_controller_info()
5052 if (ahc->features & AHC_TWIN) { in ahc_chip_init()
5058 term = (ahc->flags & AHC_TERM_ENB_B) != 0 ? STPWEN : 0; in ahc_chip_init()
5059 ahc_outb(ahc, SCSIID, ahc->our_id_b); in ahc_chip_init()
5062 |term|ahc->seltime_b|ENSTIMER|ACTNEGEN); in ahc_chip_init()
5063 if ((ahc->features & AHC_ULTRA2) != 0) in ahc_chip_init()
5071 term = (ahc->flags & AHC_TERM_ENB_A) != 0 ? STPWEN : 0; in ahc_chip_init()
5072 if ((ahc->features & AHC_ULTRA2) != 0) in ahc_chip_init()
5073 ahc_outb(ahc, SCSIID_ULTRA2, ahc->our_id); in ahc_chip_init()
5075 ahc_outb(ahc, SCSIID, ahc->our_id); in ahc_chip_init()
5078 |term|ahc->seltime in ahc_chip_init()
5080 if ((ahc->features & AHC_ULTRA2) != 0) in ahc_chip_init()
5088 if ((ahc->flags & AHC_SCB_BTT) != 0) { in ahc_chip_init()
5102 ahc->qoutfifo[i] = SCB_LIST_NULL; in ahc_chip_init()
5106 ahc->qinfifo[i] = SCB_LIST_NULL; in ahc_chip_init()
5108 if ((ahc->features & AHC_MULTI_TID) != 0) { in ahc_chip_init()
5116 physaddr = ahc->scb_data->hscb_busaddr; in ahc_chip_init()
5122 physaddr = ahc->shared_data_busaddr; in ahc_chip_init()
5142 if ((ahc->features & AHC_HS_MAILBOX) != 0) in ahc_chip_init()
5146 if ((ahc->features & AHC_TARGETMODE) != 0) { in ahc_chip_init()
5147 ahc->tqinfifonext = 1; in ahc_chip_init()
5148 ahc_outb(ahc, KERNEL_TQINPOS, ahc->tqinfifonext - 1); in ahc_chip_init()
5149 ahc_outb(ahc, TQINPOS, ahc->tqinfifonext); in ahc_chip_init()
5151 ahc->qinfifonext = 0; in ahc_chip_init()
5152 ahc->qoutfifonext = 0; in ahc_chip_init()
5153 if ((ahc->features & AHC_QUEUE_REGS) != 0) { in ahc_chip_init()
5155 ahc_outb(ahc, HNSCB_QOFF, ahc->qinfifonext); in ahc_chip_init()
5156 ahc_outb(ahc, SNSCB_QOFF, ahc->qinfifonext); in ahc_chip_init()
5159 ahc_outb(ahc, KERNEL_QINPOS, ahc->qinfifonext); in ahc_chip_init()
5160 ahc_outb(ahc, QINPOS, ahc->qinfifonext); in ahc_chip_init()
5161 ahc_outb(ahc, QOUTPOS, ahc->qoutfifonext); in ahc_chip_init()
5179 if ((ahc->flags & AHC_INITIATORROLE) != 0) in ahc_chip_init()
5189 ahc_outb(ahc, NEXT_QUEUED_SCB, ahc->next_queued_scb->hscb->tag); in ahc_chip_init()
5203 if ((ahc->features & AHC_ULTRA2) != 0) { in ahc_chip_init()
5215 wait--) in ahc_chip_init()
5238 ahc->flags |= AHC_SEQUENCER_DEBUG; in ahc_init()
5249 if ((ahc->features & AHC_MORE_SRAM) != 0) { in ahc_init()
5270 if ((ahc->flags & AHC_USEDEFAULTS) != 0) in ahc_init()
5271 ahc->our_id = ahc->our_id_b = 7; in ahc_init()
5276 ahc->flags |= AHC_INITIATORROLE; in ahc_init()
5281 if ((AHC_TMODE_ENABLE & (0x1 << ahc->unit)) == 0) in ahc_init()
5282 ahc->features &= ~AHC_TARGETMODE; in ahc_init()
5284 ahc->init_level++; in ahc_init()
5296 if ((ahc->features & AHC_TARGETMODE) != 0) in ahc_init()
5299 if (ahc_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1, in ahc_init()
5307 /*flags*/0, &ahc->shared_data_dmat) != 0) { in ahc_init()
5311 ahc->init_level++; in ahc_init()
5314 if (ahc_dmamem_alloc(ahc, ahc->shared_data_dmat, in ahc_init()
5315 (void **)&ahc->qoutfifo, in ahc_init()
5316 BUS_DMA_NOWAIT, &ahc->shared_data_dmamap) != 0) { in ahc_init()
5320 ahc->init_level++; in ahc_init()
5323 ahc_dmamap_load(ahc, ahc->shared_data_dmat, ahc->shared_data_dmamap, in ahc_init()
5324 ahc->qoutfifo, driver_data_size, ahc_dmamap_cb, in ahc_init()
5325 &ahc->shared_data_busaddr, /*flags*/0); in ahc_init()
5327 if ((ahc->features & AHC_TARGETMODE) != 0) { in ahc_init()
5328 ahc->targetcmds = (struct target_cmd *)ahc->qoutfifo; in ahc_init()
5329 ahc->qoutfifo = (uint8_t *)&ahc->targetcmds[AHC_TMODE_CMDS]; in ahc_init()
5330 ahc->dma_bug_buf = ahc->shared_data_busaddr in ahc_init()
5331 + driver_data_size - 1; in ahc_init()
5334 ahc->targetcmds[i].cmd_valid = 0; in ahc_init()
5336 ahc->qoutfifo = (uint8_t *)&ahc->targetcmds[256]; in ahc_init()
5338 ahc->qinfifo = &ahc->qoutfifo[256]; in ahc_init()
5340 ahc->init_level++; in ahc_init()
5343 if (ahc->scb_data->maxhscbs == 0) in ahc_init()
5352 if (ahc_alloc_tstate(ahc, ahc->our_id, 'A') == NULL) { in ahc_init()
5358 if ((ahc->features & AHC_TWIN) != 0) { in ahc_init()
5359 if (ahc_alloc_tstate(ahc, ahc->our_id_b, 'B') == NULL) { in ahc_init()
5366 if (ahc->scb_data->maxhscbs < AHC_SCB_MAX_ALLOC) { in ahc_init()
5367 ahc->flags |= AHC_PAGESCBS; in ahc_init()
5369 ahc->flags &= ~AHC_PAGESCBS; in ahc_init()
5387 if (ahc->features & AHC_TWIN) { in ahc_init()
5390 && (ahc->flags & AHC_INITIATORROLE) != 0) in ahc_init()
5391 ahc->flags |= AHC_RESET_BUS_B; in ahc_init()
5396 && (ahc->flags & AHC_INITIATORROLE) != 0) in ahc_init()
5397 ahc->flags |= AHC_RESET_BUS_A; in ahc_init()
5403 if ((ahc->flags & AHC_USEDEFAULTS) != 0) { in ahc_init()
5406 ahc->flags |= AHC_EXTENDED_TRANS_A|AHC_EXTENDED_TRANS_B| in ahc_init()
5409 if ((ahc->features & AHC_ULTRA) != 0) in ahc_init()
5414 if ((ahc->features & (AHC_ULTRA|AHC_ULTRA2)) != 0) in ahc_init()
5419 if ((ahc->features & (AHC_WIDE|AHC_TWIN)) == 0) in ahc_init()
5430 our_id = ahc->our_id; in ahc_init()
5432 if (i > 7 && (ahc->features & AHC_TWIN) != 0) { in ahc_init()
5434 our_id = ahc->our_id_b; in ahc_init()
5441 if (ahc->flags & AHC_USEDEFAULTS) { in ahc_init()
5442 if ((ahc->features & AHC_WIDE) != 0) in ahc_init()
5443 tinfo->user.width = MSG_EXT_WDTR_BUS_16_BIT; in ahc_init()
5449 tinfo->user.period = ahc_syncrates->period; in ahc_init()
5450 tinfo->user.offset = MAX_OFFSET; in ahc_init()
5458 if ((ahc->features & AHC_ULTRA2) != 0) { in ahc_init()
5478 if ((ahc->features & AHC_DT) != 0) in ahc_init()
5480 tinfo->user.period = in ahc_init()
5483 tinfo->user.period = 0; in ahc_init()
5485 tinfo->user.offset = MAX_OFFSET; in ahc_init()
5487 && (ahc->features & AHC_DT) != 0) in ahc_init()
5488 tinfo->user.ppr_options = in ahc_init()
5493 /* Treat 10MHz as a non-ultra speed */ in ahc_init()
5497 tinfo->user.period = in ahc_init()
5502 if (tinfo->user.period != 0) in ahc_init()
5503 tinfo->user.offset = MAX_OFFSET; in ahc_init()
5505 if (tinfo->user.period == 0) in ahc_init()
5506 tinfo->user.offset = 0; in ahc_init()
5508 && (ahc->features & AHC_WIDE) != 0) in ahc_init()
5509 tinfo->user.width = MSG_EXT_WDTR_BUS_16_BIT; in ahc_init()
5510 tinfo->user.protocol_version = 4; in ahc_init()
5511 if ((ahc->features & AHC_DT) != 0) in ahc_init()
5512 tinfo->user.transport_version = 3; in ahc_init()
5514 tinfo->user.transport_version = 2; in ahc_init()
5515 tinfo->goal.protocol_version = 2; in ahc_init()
5516 tinfo->goal.transport_version = 2; in ahc_init()
5517 tinfo->curr.protocol_version = 2; in ahc_init()
5518 tinfo->curr.transport_version = 2; in ahc_init()
5520 tstate->ultraenb = 0; in ahc_init()
5522 ahc->user_discenable = discenable; in ahc_init()
5523 ahc->user_tagenable = tagenable; in ahc_init()
5525 return (ahc->bus_chip_init(ahc)); in ahc_init()
5535 ahc->pause &= ~INTEN; in ahc_intr_enable()
5536 ahc->unpause &= ~INTEN; in ahc_intr_enable()
5539 ahc->pause |= INTEN; in ahc_intr_enable()
5540 ahc->unpause |= INTEN; in ahc_intr_enable()
5560 ahc->flags |= AHC_ALL_INTERRUPTS; in ahc_pause_and_flushwork()
5580 } while (--maxloops in ahc_pause_and_flushwork()
5581 && (intstat != 0xFF || (ahc->features & AHC_REMOVABLE) == 0) in ahc_pause_and_flushwork()
5589 ahc->flags &= ~AHC_ALL_INTERRUPTS; in ahc_pause_and_flushwork()
5598 if (LIST_FIRST(&ahc->pending_scbs) != NULL) { in ahc_suspend()
5609 if (ahc->pending_device != NULL) { in ahc_suspend()
5638 if ((ahc->flags & AHC_SCB_BTT) != 0) { in ahc_index_busy_tcl()
5658 if ((ahc->flags & AHC_SCB_BTT) != 0) { in ahc_unbusy_tcl()
5676 if ((ahc->flags & AHC_SCB_BTT) != 0) { in ahc_busy_tcl()
5708 group = XPT_FC_GROUP(scb->io_ctx->ccb_h.func_code); in ahc_match_scb()
5711 && ((tag == scb->hscb->tag) in ahc_match_scb()
5715 && ((tag == scb->io_ctx->csio.tag_id) in ahc_match_scb()
5719 match = ((tag == scb->hscb->tag) || (tag == SCB_LIST_NULL)); in ahc_match_scb()
5754 prev_pos = ahc->qinfifonext - 1; in ahc_qinfifo_requeue_tail()
5755 prev_tag = ahc->qinfifo[prev_pos]; in ahc_qinfifo_requeue_tail()
5759 if ((ahc->features & AHC_QUEUE_REGS) != 0) { in ahc_qinfifo_requeue_tail()
5760 ahc_outb(ahc, HNSCB_QOFF, ahc->qinfifonext); in ahc_qinfifo_requeue_tail()
5762 ahc_outb(ahc, KERNEL_QINPOS, ahc->qinfifonext); in ahc_qinfifo_requeue_tail()
5771 ahc_outb(ahc, NEXT_QUEUED_SCB, scb->hscb->tag); in ahc_qinfifo_requeue()
5773 prev_scb->hscb->next = scb->hscb->tag; in ahc_qinfifo_requeue()
5777 ahc->qinfifo[ahc->qinfifonext++] = scb->hscb->tag; in ahc_qinfifo_requeue()
5778 scb->hscb->next = ahc->next_queued_scb->hscb->tag; in ahc_qinfifo_requeue()
5788 if ((ahc->features & AHC_QUEUE_REGS) != 0) { in ahc_qinfifo_count()
5793 diff = ahc->qinfifonext - qinpos; in ahc_qinfifo_count()
5813 qintail = ahc->qinfifonext; in ahc_search_qinfifo()
5814 have_qregs = (ahc->features & AHC_QUEUE_REGS) != 0; in ahc_search_qinfifo()
5834 * for removal will be re-added to the queue as we go. in ahc_search_qinfifo()
5836 ahc->qinfifonext = qinpos; in ahc_search_qinfifo()
5837 ahc_outb(ahc, NEXT_QUEUED_SCB, ahc->next_queued_scb->hscb->tag); in ahc_search_qinfifo()
5840 scb = ahc_lookup_scb(ahc, ahc->qinfifo[qinpos]); in ahc_search_qinfifo()
5843 qinpos, ahc->qinfifo[qinpos]); in ahc_search_qinfifo()
5864 if ((scb->flags & SCB_ACTIVE) == 0) in ahc_search_qinfifo()
5883 if ((ahc->features & AHC_QUEUE_REGS) != 0) { in ahc_search_qinfifo()
5884 ahc_outb(ahc, HNSCB_QOFF, ahc->qinfifonext); in ahc_search_qinfifo()
5886 ahc_outb(ahc, KERNEL_QINPOS, ahc->qinfifonext); in ahc_search_qinfifo()
5891 && (qinstart != ahc->qinfifonext)) { in ahc_search_qinfifo()
5904 scb = ahc_lookup_scb(ahc, ahc->qinfifo[qinstart]); in ahc_search_qinfifo()
5908 found, qinstart, ahc->qinfifonext); in ahc_search_qinfifo()
5917 next = scb->hscb->next; in ahc_search_qinfifo()
5918 ahc->scb_data->scbindex[scb->hscb->tag] = NULL; in ahc_search_qinfifo()
5920 scb->hscb->next = next; in ahc_search_qinfifo()
5921 ahc->qinfifo[qinstart] = scb->hscb->tag; in ahc_search_qinfifo()
5924 ahc_outb(ahc, NEXT_QUEUED_SCB, scb->hscb->tag); in ahc_search_qinfifo()
5927 qintail = ahc->qinfifonext - 1; in ahc_search_qinfifo()
5928 scb = ahc_lookup_scb(ahc, ahc->qinfifo[qintail]); in ahc_search_qinfifo()
5929 scb->hscb->next = ahc->next_queued_scb->hscb->tag; in ahc_search_qinfifo()
5944 if (scb_index >= ahc->scb_data->numscbs) { in ahc_search_qinfifo()
5947 scb_index, ahc->scb_data->numscbs); in ahc_search_qinfifo()
5976 if ((scb->flags & SCB_ACTIVE) == 0) in ahc_search_qinfifo()
6024 if ((ahc->flags & AHC_SCB_BTT) == 0) { in ahc_search_untagged_queues()
6042 untagged_q = &(ahc->untagged_queues[i]); in ahc_search_untagged_queues()
6058 if ((scb->flags & SCB_ACTIVE) != 0) in ahc_search_untagged_queues()
6063 || (ctx != NULL && ctx != scb->io_ctx)) in ahc_search_untagged_queues()
6082 if ((scb->flags & SCB_ACTIVE) == 0) in ahc_search_untagged_queues()
6088 scb->flags &= ~SCB_UNTAGGEDQ; in ahc_search_untagged_queues()
6129 if (scb_index >= ahc->scb_data->numscbs) { in ahc_search_disc_list()
6132 scb_index, ahc->scb_data->numscbs); in ahc_search_disc_list()
6204 if ((ahc->flags & AHC_PAGESCBS) != 0) { in ahc_add_curscb_to_free_list()
6313 if ((ahc->flags & AHC_SCB_BTT) != 0) in ahc_abort_scbs()
6355 for (i = 0; i < ahc->scb_data->maxhscbs; i++) { in ahc_abort_scbs()
6373 scbp_next = LIST_FIRST(&ahc->pending_scbs); in ahc_abort_scbs()
6385 if ((scbp->flags & SCB_ACTIVE) == 0) in ahc_abort_scbs()
6412 /* Re-enable reset interrupts */ in ahc_reset_current_bus()
6428 ahc->pending_device = NULL; in ahc_reset_channel()
6448 * XXX - In Twin mode, the tqinfifo may have commands in ahc_reset_channel()
6455 * to compact the tqinfifo appropriately. in ahc_reset_channel()
6457 if ((ahc->flags & AHC_TARGETROLE) != 0) { in ahc_reset_channel()
6467 if ((ahc->features & AHC_TWIN) != 0 in ahc_reset_channel()
6481 * defer re-enabling bus reset interrupts in ahc_reset_channel()
6484 if ((ahc->flags & AHC_TARGETROLE) != 0) in ahc_reset_channel()
6500 * defer re-enabling bus reset interrupts in ahc_reset_channel()
6503 if ((ahc->flags & AHC_TARGETROLE) != 0) in ahc_reset_channel()
6522 max_scsiid = (ahc->features & AHC_WIDE) ? 15 : 7; in ahc_reset_channel()
6533 tstate = ahc->enabled_targets[target]; in ahc_reset_channel()
6539 lstate = tstate->enabled_luns[lun]; in ahc_reset_channel()
6558 if (ahc->enabled_targets[target] == NULL) in ahc_reset_channel()
6612 hscb = scb->hscb; in ahc_calc_residual()
6613 sgptr = ahc_le32toh(hscb->sgptr); in ahc_calc_residual()
6623 spkt = &hscb->shared_data.status; in ahc_calc_residual()
6624 resid_sgptr = ahc_le32toh(spkt->residual_sg_ptr); in ahc_calc_residual()
6640 resid = ahc_le32toh(spkt->residual_datacnt) & AHC_SG_LEN_MASK; in ahc_calc_residual()
6644 sg--; in ahc_calc_residual()
6651 while ((ahc_le32toh(sg->len) & AHC_DMA_LAST_SEG) == 0) { in ahc_calc_residual()
6653 resid += ahc_le32toh(sg->len) & AHC_SG_LEN_MASK; in ahc_calc_residual()
6656 if ((scb->flags & SCB_SENSE) == 0) in ahc_calc_residual()
6665 (scb->flags & SCB_SENSE) ? "Sense " : "", resid); in ahc_calc_residual()
6682 xpt_freeze_devq(lstate->path, /*count*/1); in ahc_queue_lstate_event()
6683 if (lstate->event_w_idx >= lstate->event_r_idx) in ahc_queue_lstate_event()
6684 pending = lstate->event_w_idx - lstate->event_r_idx; in ahc_queue_lstate_event()
6687 - (lstate->event_r_idx - lstate->event_w_idx); in ahc_queue_lstate_event()
6697 lstate->event_r_idx = 0; in ahc_queue_lstate_event()
6698 lstate->event_w_idx = 0; in ahc_queue_lstate_event()
6699 xpt_release_devq(lstate->path, pending, /*runqueue*/FALSE); in ahc_queue_lstate_event()
6703 xpt_print_path(lstate->path); in ahc_queue_lstate_event()
6705 lstate->event_buffer[lstate->event_r_idx].event_type, in ahc_queue_lstate_event()
6706 lstate->event_buffer[lstate->event_r_idx].event_arg); in ahc_queue_lstate_event()
6707 lstate->event_r_idx++; in ahc_queue_lstate_event()
6708 if (lstate->event_r_idx == AHC_TMODE_EVENT_BUFFER_SIZE) in ahc_queue_lstate_event()
6709 lstate->event_r_idx = 0; in ahc_queue_lstate_event()
6710 xpt_release_devq(lstate->path, /*count*/1, /*runqueue*/FALSE); in ahc_queue_lstate_event()
6713 event = &lstate->event_buffer[lstate->event_w_idx]; in ahc_queue_lstate_event()
6714 event->initiator_id = initiator_id; in ahc_queue_lstate_event()
6715 event->event_type = event_type; in ahc_queue_lstate_event()
6716 event->event_arg = event_arg; in ahc_queue_lstate_event()
6717 lstate->event_w_idx++; in ahc_queue_lstate_event()
6718 if (lstate->event_w_idx == AHC_TMODE_EVENT_BUFFER_SIZE) in ahc_queue_lstate_event()
6719 lstate->event_w_idx = 0; in ahc_queue_lstate_event()
6732 while (lstate->event_r_idx != lstate->event_w_idx in ahc_send_lstate_events()
6733 && (ccbh = SLIST_FIRST(&lstate->immed_notifies)) != NULL) { in ahc_send_lstate_events()
6736 event = &lstate->event_buffer[lstate->event_r_idx]; in ahc_send_lstate_events()
6737 SLIST_REMOVE_HEAD(&lstate->immed_notifies, sim_links.sle); in ahc_send_lstate_events()
6739 switch (event->event_type) { in ahc_send_lstate_events()
6741 ccbh->status = CAM_SCSI_BUS_RESET|CAM_DEV_QFRZN; in ahc_send_lstate_events()
6744 ccbh->status = CAM_MESSAGE_RECV|CAM_DEV_QFRZN; in ahc_send_lstate_events()
6745 inot->message_args[0] = event->event_type; in ahc_send_lstate_events()
6746 inot->message_args[1] = event->event_arg; in ahc_send_lstate_events()
6749 inot->initiator_id = event->initiator_id; in ahc_send_lstate_events()
6750 inot->sense_len = 0; in ahc_send_lstate_events()
6752 lstate->event_r_idx++; in ahc_send_lstate_events()
6753 if (lstate->event_r_idx == AHC_TMODE_EVENT_BUFFER_SIZE) in ahc_send_lstate_events()
6754 lstate->event_r_idx = 0; in ahc_send_lstate_events()
6770 for (i = 0; i < ahc->instruction_ram_size; i++) { in ahc_dumpseq()
6808 if (ahc->targetcmds != NULL) in ahc_loadseq()
6811 download_consts[CACHESIZE_MASK] = ahc->pci_cachesize - 1; in ahc_loadseq()
6812 download_consts[INVERTED_CACHESIZE_MASK] = ~(ahc->pci_cachesize - 1); in ahc_loadseq()
6813 sg_prefetch_cnt = ahc->pci_cachesize; in ahc_loadseq()
6817 download_consts[SG_PREFETCH_ALIGN_MASK] = ~(sg_prefetch_cnt - 1); in ahc_loadseq()
6818 download_consts[SG_PREFETCH_ADDR_MASK] = (sg_prefetch_cnt - 1); in ahc_loadseq()
6836 if (downloaded == ahc->instruction_ram_size) { in ahc_loadseq()
6844 ahc->instruction_ram_size); in ahc_loadseq()
6873 ahc->num_critical_sections = cs_count; in ahc_loadseq()
6877 ahc->critical_sections = kmemdup(cs_table, cs_count, GFP_ATOMIC); in ahc_loadseq()
6878 if (ahc->critical_sections == NULL) in ahc_loadseq()
6886 ahc_name(ahc), ahc->features, ahc->bugs, ahc->flags); in ahc_loadseq()
6903 while (cur_patch < last_patch && start_instr == cur_patch->begin) { in ahc_check_patch()
6905 if (cur_patch->patch_func(ahc) == 0) { in ahc_check_patch()
6908 *skip_addr = start_instr + cur_patch->skip_instr; in ahc_check_patch()
6909 cur_patch += cur_patch->skip_patch; in ahc_check_patch()
6963 address = fmt3_ins->address; in ahc_download_instr()
6975 address_offset += end_addr - i; in ahc_download_instr()
6981 address -= address_offset; in ahc_download_instr()
6982 fmt3_ins->address = address; in ahc_download_instr()
6991 if (fmt1_ins->parity != 0) { in ahc_download_instr()
6992 fmt1_ins->immediate = dconsts[fmt1_ins->immediate]; in ahc_download_instr()
6994 fmt1_ins->parity = 0; in ahc_download_instr()
6995 if ((ahc->features & AHC_CMD_CHAN) == 0 in ahc_download_instr()
7004 if (fmt1_ins->immediate != 1) in ahc_download_instr()
7007 fmt1_ins->opcode = AIC_OP_AND; in ahc_download_instr()
7008 fmt1_ins->immediate = 0xff; in ahc_download_instr()
7012 if ((ahc->features & AHC_ULTRA2) != 0) { in ahc_download_instr()
7029 fmt3_ins->immediate in ahc_download_instr()
7030 | (fmt3_ins->source << 8) in ahc_download_instr()
7031 | (fmt3_ins->address << 16) in ahc_download_instr()
7032 | (fmt3_ins->opcode << 25); in ahc_download_instr()
7035 fmt1_ins->immediate in ahc_download_instr()
7036 | (fmt1_ins->source << 8) in ahc_download_instr()
7037 | (fmt1_ins->destination << 16) in ahc_download_instr()
7038 | (fmt1_ins->ret << 24) in ahc_download_instr()
7039 | (fmt1_ins->opcode << 25); in ahc_download_instr()
7127 ahc_name(ahc), ahc_lookup_phase_entry(last_phase)->phasemsg, in ahc_dump_card_state()
7137 if ((ahc->features & AHC_DT) != 0) in ahc_dump_card_state()
7162 printk("\nSCB count = %d\n", ahc->scb_data->numscbs); in ahc_dump_card_state()
7163 printk("Kernel NEXTQSCB = %d\n", ahc->next_queued_scb->hscb->tag); in ahc_dump_card_state()
7167 if ((ahc->features & AHC_QUEUE_REGS) != 0) { in ahc_dump_card_state()
7172 qintail = ahc->qinfifonext; in ahc_dump_card_state()
7174 printk("%d ", ahc->qinfifo[qinpos]); in ahc_dump_card_state()
7201 qoutpos = ahc->qoutfifonext; in ahc_dump_card_state()
7203 while (ahc->qoutfifo[qoutpos] != SCB_LIST_NULL && i++ < 256) { in ahc_dump_card_state()
7204 printk("%d ", ahc->qoutfifo[qoutpos]); in ahc_dump_card_state()
7220 for (i = 0; i < ahc->scb_data->maxhscbs; i++) { in ahc_dump_card_state()
7233 LIST_FOREACH(scb, &ahc->pending_scbs, pending_links) { in ahc_dump_card_state()
7236 cur_col = printk("\n%3d ", scb->hscb->tag); in ahc_dump_card_state()
7237 ahc_scb_control_print(scb->hscb->control, &cur_col, 60); in ahc_dump_card_state()
7238 ahc_scb_scsiid_print(scb->hscb->scsiid, &cur_col, 60); in ahc_dump_card_state()
7239 ahc_scb_lun_print(scb->hscb->lun, &cur_col, 60); in ahc_dump_card_state()
7240 if ((ahc->flags & AHC_PAGESCBS) == 0) { in ahc_dump_card_state()
7241 ahc_outb(ahc, SCBPTR, scb->hscb->tag); in ahc_dump_card_state()
7253 SLIST_FOREACH(scb, &ahc->scb_data->free_scbs, links.sle) { in ahc_dump_card_state()
7256 printk("%d ", scb->hscb->tag); in ahc_dump_card_state()
7260 maxtarget = (ahc->features & (AHC_WIDE|AHC_TWIN)) ? 15 : 7; in ahc_dump_card_state()
7262 untagged_q = &ahc->untagged_queues[target]; in ahc_dump_card_state()
7270 printk("%d ", scb->hscb->tag); in ahc_dump_card_state()
7290 if ((ahc->features & AHC_TARGETMODE) == 0) in ahc_find_tmode_devs()
7297 if (ccb->ccb_h.target_id == CAM_TARGET_WILDCARD in ahc_find_tmode_devs()
7298 && ccb->ccb_h.target_lun == CAM_LUN_WILDCARD) { in ahc_find_tmode_devs()
7300 *lstate = ahc->black_hole; in ahc_find_tmode_devs()
7304 max_id = (ahc->features & AHC_WIDE) ? 16 : 8; in ahc_find_tmode_devs()
7305 if (ccb->ccb_h.target_id >= max_id) in ahc_find_tmode_devs()
7308 if (ccb->ccb_h.target_lun >= AHC_NUM_LUNS) in ahc_find_tmode_devs()
7311 *tstate = ahc->enabled_targets[ccb->ccb_h.target_id]; in ahc_find_tmode_devs()
7315 (*tstate)->enabled_luns[ccb->ccb_h.target_lun]; in ahc_find_tmode_devs()
7343 ccb->ccb_h.status = status; in ahc_handle_en_lun()
7348 our_id = ahc->our_id; in ahc_handle_en_lun()
7350 our_id = ahc->our_id_b; in ahc_handle_en_lun()
7352 if (ccb->ccb_h.target_id != our_id) { in ahc_handle_en_lun()
7365 * ID to use for both select-out and in ahc_handle_en_lun()
7366 * reselect-out operations, the only target in ahc_handle_en_lun()
7372 if ((ahc->features & AHC_MULTIROLE) != 0) { in ahc_handle_en_lun()
7374 if ((ahc->features & AHC_MULTI_TID) != 0 in ahc_handle_en_lun()
7375 && (ahc->flags & AHC_INITIATORROLE) != 0) { in ahc_handle_en_lun()
7379 * The hardware cannot handle a re-select-in in ahc_handle_en_lun()
7380 * on the initiator id during a re-select-out in ahc_handle_en_lun()
7384 } else if ((ahc->flags & AHC_INITIATORROLE) != 0 in ahc_handle_en_lun()
7385 || ahc->enabled_luns > 0) { in ahc_handle_en_lun()
7395 } else if ((ahc->features & AHC_MULTI_TID) == 0 in ahc_handle_en_lun()
7396 && ahc->enabled_luns > 0) { in ahc_handle_en_lun()
7403 ccb->ccb_h.status = status; in ahc_handle_en_lun()
7411 if ((ahc->flags & AHC_TARGETROLE) == 0 in ahc_handle_en_lun()
7412 && ccb->ccb_h.target_id != CAM_TARGET_WILDCARD) { in ahc_handle_en_lun()
7418 if (LIST_FIRST(&ahc->pending_scbs) != NULL) { in ahc_handle_en_lun()
7419 ccb->ccb_h.status = CAM_BUSY; in ahc_handle_en_lun()
7423 saved_flags = ahc->flags; in ahc_handle_en_lun()
7424 ahc->flags |= AHC_TARGETROLE; in ahc_handle_en_lun()
7425 if ((ahc->features & AHC_MULTIROLE) == 0) in ahc_handle_en_lun()
7426 ahc->flags &= ~AHC_INITIATORROLE; in ahc_handle_en_lun()
7438 ahc->flags = saved_flags; in ahc_handle_en_lun()
7442 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL; in ahc_handle_en_lun()
7448 cel = &ccb->cel; in ahc_handle_en_lun()
7449 target = ccb->ccb_h.target_id; in ahc_handle_en_lun()
7450 lun = ccb->ccb_h.target_lun; in ahc_handle_en_lun()
7456 if (cel->enable != 0) { in ahc_handle_en_lun()
7461 xpt_print_path(ccb->ccb_h.path); in ahc_handle_en_lun()
7463 ccb->ccb_h.status = CAM_LUN_ALRDY_ENA; in ahc_handle_en_lun()
7467 if (cel->grp6_len != 0 in ahc_handle_en_lun()
7468 || cel->grp7_len != 0) { in ahc_handle_en_lun()
7473 ccb->ccb_h.status = CAM_REQ_INVALID; in ahc_handle_en_lun()
7474 printk("Non-zero Group Codes\n"); in ahc_handle_en_lun()
7485 xpt_print_path(ccb->ccb_h.path); in ahc_handle_en_lun()
7487 ccb->ccb_h.status = CAM_RESRC_UNAVAIL; in ahc_handle_en_lun()
7493 xpt_print_path(ccb->ccb_h.path); in ahc_handle_en_lun()
7495 ccb->ccb_h.status = CAM_RESRC_UNAVAIL; in ahc_handle_en_lun()
7498 status = xpt_create_path(&lstate->path, /*periph*/NULL, in ahc_handle_en_lun()
7499 xpt_path_path_id(ccb->ccb_h.path), in ahc_handle_en_lun()
7500 xpt_path_target_id(ccb->ccb_h.path), in ahc_handle_en_lun()
7501 xpt_path_lun_id(ccb->ccb_h.path)); in ahc_handle_en_lun()
7504 xpt_print_path(ccb->ccb_h.path); in ahc_handle_en_lun()
7506 ccb->ccb_h.status = CAM_RESRC_UNAVAIL; in ahc_handle_en_lun()
7509 SLIST_INIT(&lstate->accept_tios); in ahc_handle_en_lun()
7510 SLIST_INIT(&lstate->immed_notifies); in ahc_handle_en_lun()
7514 tstate->enabled_luns[lun] = lstate; in ahc_handle_en_lun()
7515 ahc->enabled_luns++; in ahc_handle_en_lun()
7517 if ((ahc->features & AHC_MULTI_TID) != 0) { in ahc_handle_en_lun()
7546 if ((ahc->features & AHC_TWIN) == 0) in ahc_handle_en_lun()
7550 ahc->our_id = target; in ahc_handle_en_lun()
7552 ahc->our_id_b = target; in ahc_handle_en_lun()
7565 ahc->black_hole = lstate; in ahc_handle_en_lun()
7566 /* Allow select-in operations */ in ahc_handle_en_lun()
7567 if (ahc->black_hole != NULL && ahc->enabled_luns > 0) { in ahc_handle_en_lun()
7577 ccb->ccb_h.status = CAM_REQ_CMP; in ahc_handle_en_lun()
7578 xpt_print_path(ccb->ccb_h.path); in ahc_handle_en_lun()
7585 ccb->ccb_h.status = CAM_LUN_INVALID; in ahc_handle_en_lun()
7591 ccb->ccb_h.status = CAM_REQ_CMP; in ahc_handle_en_lun()
7592 LIST_FOREACH(scb, &ahc->pending_scbs, pending_links) { in ahc_handle_en_lun()
7595 ccbh = &scb->io_ctx->ccb_h; in ahc_handle_en_lun()
7596 if (ccbh->func_code == XPT_CONT_TARGET_IO in ahc_handle_en_lun()
7597 && !xpt_path_comp(ccbh->path, ccb->ccb_h.path)){ in ahc_handle_en_lun()
7599 ccb->ccb_h.status = CAM_REQ_INVALID; in ahc_handle_en_lun()
7605 if (SLIST_FIRST(&lstate->accept_tios) != NULL) { in ahc_handle_en_lun()
7607 ccb->ccb_h.status = CAM_REQ_INVALID; in ahc_handle_en_lun()
7610 if (SLIST_FIRST(&lstate->immed_notifies) != NULL) { in ahc_handle_en_lun()
7612 ccb->ccb_h.status = CAM_REQ_INVALID; in ahc_handle_en_lun()
7615 if (ccb->ccb_h.status != CAM_REQ_CMP) { in ahc_handle_en_lun()
7620 xpt_print_path(ccb->ccb_h.path); in ahc_handle_en_lun()
7622 xpt_free_path(lstate->path); in ahc_handle_en_lun()
7628 tstate->enabled_luns[lun] = NULL; in ahc_handle_en_lun()
7629 ahc->enabled_luns--; in ahc_handle_en_lun()
7631 if (tstate->enabled_luns[i] != NULL) { in ahc_handle_en_lun()
7639 if (ahc->features & AHC_MULTI_TID) { in ahc_handle_en_lun()
7655 ahc->black_hole = NULL; in ahc_handle_en_lun()
7663 if (ahc->enabled_luns == 0) { in ahc_handle_en_lun()
7664 /* Disallow select-in */ in ahc_handle_en_lun()
7674 if ((ahc->features & AHC_MULTIROLE) == 0) { in ahc_handle_en_lun()
7676 ahc->flags &= ~AHC_TARGETROLE; in ahc_handle_en_lun()
7677 ahc->flags |= AHC_INITIATORROLE; in ahc_handle_en_lun()
7701 if ((ahc->features & AHC_MULTI_TID) == 0) in ahc_update_scsiid()
7702 panic("ahc_update_scsiid called on non-multitid unit\n"); in ahc_update_scsiid()
7710 if ((ahc->features & AHC_ULTRA2) != 0) in ahc_update_scsiid()
7721 our_id = ahc->our_id; in ahc_update_scsiid()
7723 our_id--; in ahc_update_scsiid()
7727 if ((ahc->features & AHC_ULTRA2) != 0) in ahc_update_scsiid()
7739 * If the card supports auto-access pause, in ahc_run_tqinfifo()
7743 if ((ahc->features & AHC_AUTOPAUSE) != 0) in ahc_run_tqinfifo()
7747 while ((cmd = &ahc->targetcmds[ahc->tqinfifonext])->cmd_valid != 0) { in ahc_run_tqinfifo()
7756 cmd->cmd_valid = 0; in ahc_run_tqinfifo()
7757 ahc_dmamap_sync(ahc, ahc->shared_data_dmat, in ahc_run_tqinfifo()
7758 ahc->shared_data_dmamap, in ahc_run_tqinfifo()
7759 ahc_targetcmd_offset(ahc, ahc->tqinfifonext), in ahc_run_tqinfifo()
7762 ahc->tqinfifonext++; in ahc_run_tqinfifo()
7768 if ((ahc->tqinfifonext & (HOST_TQINPOS - 1)) == 1) { in ahc_run_tqinfifo()
7769 if ((ahc->features & AHC_HS_MAILBOX) != 0) { in ahc_run_tqinfifo()
7774 hs_mailbox |= ahc->tqinfifonext & HOST_TQINPOS; in ahc_run_tqinfifo()
7780 ahc->tqinfifonext & HOST_TQINPOS); in ahc_run_tqinfifo()
7799 initiator = SCSIID_TARGET(ahc, cmd->scsiid); in ahc_handle_target_cmd()
7800 target = SCSIID_OUR_ID(cmd->scsiid); in ahc_handle_target_cmd()
7801 lun = (cmd->identify & MSG_IDENTIFY_LUNMASK); in ahc_handle_target_cmd()
7803 byte = cmd->bytes; in ahc_handle_target_cmd()
7804 tstate = ahc->enabled_targets[target]; in ahc_handle_target_cmd()
7807 lstate = tstate->enabled_luns[lun]; in ahc_handle_target_cmd()
7813 lstate = ahc->black_hole; in ahc_handle_target_cmd()
7815 atio = (struct ccb_accept_tio*)SLIST_FIRST(&lstate->accept_tios); in ahc_handle_target_cmd()
7817 ahc->flags |= AHC_TQINFIFO_BLOCKED; in ahc_handle_target_cmd()
7825 ahc->flags &= ~AHC_TQINFIFO_BLOCKED; in ahc_handle_target_cmd()
7829 lstate == ahc->black_hole ? "(Black Holed)" : ""); in ahc_handle_target_cmd()
7831 SLIST_REMOVE_HEAD(&lstate->accept_tios, sim_links.sle); in ahc_handle_target_cmd()
7833 if (lstate == ahc->black_hole) { in ahc_handle_target_cmd()
7835 atio->ccb_h.target_id = target; in ahc_handle_target_cmd()
7836 atio->ccb_h.target_lun = lun; in ahc_handle_target_cmd()
7843 atio->sense_len = 0; in ahc_handle_target_cmd()
7844 atio->init_id = initiator; in ahc_handle_target_cmd()
7847 atio->tag_action = *byte++; in ahc_handle_target_cmd()
7848 atio->tag_id = *byte++; in ahc_handle_target_cmd()
7849 atio->ccb_h.flags = CAM_TAG_ACTION_VALID; in ahc_handle_target_cmd()
7851 atio->ccb_h.flags = 0; in ahc_handle_target_cmd()
7858 atio->cdb_len = 6; in ahc_handle_target_cmd()
7862 atio->cdb_len = 10; in ahc_handle_target_cmd()
7865 atio->cdb_len = 16; in ahc_handle_target_cmd()
7868 atio->cdb_len = 12; in ahc_handle_target_cmd()
7873 atio->cdb_len = 1; in ahc_handle_target_cmd()
7878 memcpy(atio->cdb_io.cdb_bytes, byte, atio->cdb_len); in ahc_handle_target_cmd()
7880 atio->ccb_h.status |= CAM_CDB_RECVD; in ahc_handle_target_cmd()
7882 if ((cmd->identify & MSG_IDENTIFY_DISCFLAG) == 0) { in ahc_handle_target_cmd()
7890 printk("Received Immediate Command %d:%d:%d - %p\n", in ahc_handle_target_cmd()
7891 initiator, target, lun, ahc->pending_device); in ahc_handle_target_cmd()
7893 ahc->pending_device = lstate; in ahc_handle_target_cmd()
7895 atio->ccb_h.flags |= CAM_DIS_DISCONNECT; in ahc_handle_target_cmd()