Lines Matching +full:spi +full:- +full:cs +full:- +full:setup +full:- +full:delay +full:- +full:ns

1 /*-
4 * SPDX-License-Identifier: BSD-3-Clause
6 * Copyright (c) 1994-2002 Justin T. Gibbs.
7 * Copyright (c) 2000-2002 Adaptec Inc.
21 * 3. Neither the names of the above-listed copyright holders nor the names
84 { DPARERR, "Data-path Parity Error" },
93 { P_DATAOUT, MSG_NOOP, "in Data-out phase" },
94 { P_DATAIN, MSG_INITIATOR_DET_ERR, "in Data-in phase" },
95 { P_DATAOUT_DT, MSG_NOOP, "in DT Data-out phase" },
96 { P_DATAIN_DT, MSG_INITIATOR_DET_ERR, "in DT Data-in phase" },
98 { P_MESGOUT, MSG_NOOP, "in Message-out phase" },
100 { P_MESGIN, MSG_PARITY_ERROR, "in Message-in phase" },
109 static const u_int num_phases = NUM_ELEMENTS(ahc_phase_table) - 1;
112 * Valid SCSIRATE values. (p. 3-17)
113 * Provides a mapping of transfer periods in ns to the proper value to
254 ahc_outb(ahc, SCSISIGO, 0); /* De-assert BSY */ in ahc_restart()
268 ahc_outb(ahc, TQINPOS, ahc->tqinfifonext); in ahc_restart()
273 if ((ahc->features & AHC_CMD_CHAN) != 0) { in ahc_restart()
298 ahc_outb(ahc, SEQCTL, ahc->seqctl); in ahc_restart()
313 while (ahc->qoutfifo[ahc->qoutfifonext] != SCB_LIST_NULL) { in ahc_run_qoutfifo()
314 scb_index = ahc->qoutfifo[ahc->qoutfifonext]; in ahc_run_qoutfifo()
315 if ((ahc->qoutfifonext & 0x03) == 0x03) { in ahc_run_qoutfifo()
325 modnext = ahc->qoutfifonext & ~0x3; in ahc_run_qoutfifo()
326 *((uint32_t *)(&ahc->qoutfifo[modnext])) = 0xFFFFFFFFUL; in ahc_run_qoutfifo()
327 aic_dmamap_sync(ahc, ahc->shared_data_dmat, in ahc_run_qoutfifo()
328 ahc->shared_data_dmamap, in ahc_run_qoutfifo()
332 ahc->qoutfifonext++; in ahc_run_qoutfifo()
339 (ahc->qoutfifonext - 1) & 0xFF); in ahc_run_qoutfifo()
358 ahc_run_untagged_queue(ahc, &ahc->untagged_queues[i]); in ahc_run_untagged_queues()
366 if (ahc->untagged_queue_lock != 0) in ahc_run_untagged_queue()
370 && (scb->flags & SCB_ACTIVE) == 0) { in ahc_run_untagged_queue()
371 scb->flags |= SCB_ACTIVE; in ahc_run_untagged_queue()
385 * We upset the sequencer :-( in ahc_handle_brkadrint()
451 printf("ahc_intr - referenced scb " in ahc_handle_seqint()
459 hscb = scb->hscb; in ahc_handle_seqint()
462 if ((scb->flags & SCB_SENSE) != 0) { in ahc_handle_seqint()
468 scb->flags &= ~SCB_SENSE; in ahc_handle_seqint()
476 aic_set_scsi_status(scb, hscb->shared_data.status.scsi_status); in ahc_handle_seqint()
477 switch (hscb->shared_data.status.scsi_status) { in ahc_handle_seqint()
494 scb->hscb->tag); in ahc_handle_seqint()
506 tinfo = &targ_info->curr; in ahc_handle_seqint()
507 sg = scb->sg_list; in ahc_handle_seqint()
508 sc = (struct scsi_sense *)(&hscb->shared_data.cdb); in ahc_handle_seqint()
519 sg->addr = ahc_get_sense_bufaddr(ahc, scb); in ahc_handle_seqint()
520 sg->len = aic_get_sense_bufsize(ahc, scb); in ahc_handle_seqint()
521 sg->len |= AHC_DMA_LAST_SEG; in ahc_handle_seqint()
524 sg->addr = aic_htole32(sg->addr); in ahc_handle_seqint()
525 sg->len = aic_htole32(sg->len); in ahc_handle_seqint()
527 sc->opcode = REQUEST_SENSE; in ahc_handle_seqint()
528 sc->byte2 = 0; in ahc_handle_seqint()
529 if (tinfo->protocol_version <= SCSI_REV_2 in ahc_handle_seqint()
531 sc->byte2 = SCB_GET_LUN(scb) << 5; in ahc_handle_seqint()
532 sc->unused[0] = 0; in ahc_handle_seqint()
533 sc->unused[1] = 0; in ahc_handle_seqint()
534 sc->length = sg->len; in ahc_handle_seqint()
535 sc->control = 0; in ahc_handle_seqint()
544 hscb->control = 0; in ahc_handle_seqint()
560 if (tstate->auto_negotiate & devinfo.target_mask) { in ahc_handle_seqint()
561 hscb->control |= MK_MESSAGE; in ahc_handle_seqint()
562 scb->flags &= ~SCB_NEGOTIATE; in ahc_handle_seqint()
563 scb->flags |= SCB_AUTO_NEGOTIATE; in ahc_handle_seqint()
565 hscb->cdb_len = sizeof(*sc); in ahc_handle_seqint()
566 hscb->dataptr = sg->addr; in ahc_handle_seqint()
567 hscb->datacnt = sg->len; in ahc_handle_seqint()
568 hscb->sgptr = scb->sg_list_phys | SG_FULL_RESID; in ahc_handle_seqint()
569 hscb->sgptr = aic_htole32(hscb->sgptr); in ahc_handle_seqint()
570 scb->sg_count = 1; in ahc_handle_seqint()
571 scb->flags |= SCB_SENSE; in ahc_handle_seqint()
581 if (ahc->scb_data->recovery_scbs == 0 in ahc_handle_seqint()
582 || (scb->flags & SCB_RECOVERY_SCB) != 0) in ahc_handle_seqint()
598 "target - issuing BUS DEVICE RESET\n", in ahc_handle_seqint()
621 ahc->msgout_buf[0] = MSG_BUS_DEV_RESET; in ahc_handle_seqint()
622 ahc->msgout_len = 1; in ahc_handle_seqint()
623 ahc->msgout_index = 0; in ahc_handle_seqint()
624 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT; in ahc_handle_seqint()
632 printf("%s:%c:%d: Warning - unknown message received from " in ahc_handle_seqint()
684 if (ahc->msg_type == MSG_TYPE_NONE) { in ahc_handle_seqint()
716 ahc->msg_type = in ahc_handle_seqint()
718 ahc->msgin_index = 0; in ahc_handle_seqint()
724 ahc->msg_type = in ahc_handle_seqint()
726 ahc->msgin_index = 0; in ahc_handle_seqint()
746 * and we are not in a phase (data-in) where we will in ahc_handle_seqint()
754 if ((ahc->features & AHC_DT) == 0) { in ahc_handle_seqint()
779 while (--wait != 0) { in ahc_handle_seqint()
831 scb->hscb->tag); in ahc_handle_seqint()
835 aic_get_transfer_length(scb), scb->sg_count); in ahc_handle_seqint()
836 if (scb->sg_count > 0) { in ahc_handle_seqint()
837 for (i = 0; i < scb->sg_count; i++) { in ahc_handle_seqint()
838 printf("sg[%d] - Addr 0x%x%x : Length %d\n", in ahc_handle_seqint()
840 (aic_le32toh(scb->sg_list[i].len) >> 24 in ahc_handle_seqint()
842 aic_le32toh(scb->sg_list[i].addr), in ahc_handle_seqint()
843 aic_le32toh(scb->sg_list[i].len) in ahc_handle_seqint()
852 if ((scb->flags & SCB_SENSE) == 0) { in ahc_handle_seqint()
855 scb->flags &= ~SCB_SENSE; in ahc_handle_seqint()
860 if ((ahc->features & AHC_ULTRA2) != 0) { in ahc_handle_seqint()
870 if ((ahc->flags & AHC_39BIT_ADDRESSING) != 0) { in ahc_handle_seqint()
891 && (scb->flags & SCB_RECOVERY_SCB) != 0) in ahc_handle_seqint()
898 SCB_GET_LUN(scb), scb->hscb->tag, in ahc_handle_seqint()
917 ahc->scb_data->hscbs[scbptr].tag); in ahc_handle_seqint()
973 if ((ahc->features & AHC_TWIN) != 0 in ahc_handle_scsiint()
980 if ((ahc->features & AHC_ULTRA2) != 0) in ahc_handle_scsiint()
986 if ((ahc->features & AHC_TWIN) != 0) { in ahc_handle_scsiint()
1010 if ((ahc->features & AHC_ULTRA2) != 0 in ahc_handle_scsiint()
1065 * could be 'data-in' is if the parity error is for in ahc_handle_scsiint()
1067 * synchronous data-in transfers, we may actually in ahc_handle_scsiint()
1089 scb->flags |= SCB_TRANSMISSION_ERROR; in ahc_handle_scsiint()
1100 if ((ahc->features & AHC_DT) != 0) { in ahc_handle_scsiint()
1112 ? "" : "non-"); in ahc_handle_scsiint()
1116 if ((ahc->features & AHC_DT) != 0 in ahc_handle_scsiint()
1134 if (ahc->msg_type != MSG_TYPE_NONE) in ahc_handle_scsiint()
1135 ahc->send_msg_perror = TRUE; in ahc_handle_scsiint()
1178 printf("%s: ahc_intr - referenced scb not " in ahc_handle_scsiint()
1259 if (ahc->msgout_buf[ahc->msgout_index - 1] in ahc_handle_scsiint()
1261 tag = scb->hscb->tag; in ahc_handle_scsiint()
1263 printf("SCB %d - Abort%s Completed.\n", in ahc_handle_scsiint()
1264 scb->hscb->tag, tag == SCB_LIST_NULL ? in ahc_handle_scsiint()
1279 && scb->io_ctx->ccb_h.func_code== XPT_RESET_DEV in ahc_handle_scsiint()
1303 * PPR Rejected. Try non-ppr negotiation in ahc_handle_scsiint()
1311 tinfo->curr.transport_version = 2; in ahc_handle_scsiint()
1312 tinfo->goal.transport_version = 2; in ahc_handle_scsiint()
1313 tinfo->goal.ppr_options = 0; in ahc_handle_scsiint()
1319 * Negotiation Rejected. Go-narrow and in ahc_handle_scsiint()
1331 * Negotiation Rejected. Go-async and in ahc_handle_scsiint()
1350 if ((scb->hscb->control & TAG_ENB) != 0) in ahc_handle_scsiint()
1351 tag = scb->hscb->tag; in ahc_handle_scsiint()
1405 devinfo->channel, in ahc_force_renegotiation()
1406 devinfo->our_scsiid, in ahc_force_renegotiation()
1407 devinfo->target, in ahc_force_renegotiation()
1422 if (ahc->num_critical_sections == 0) in ahc_clear_critical_section()
1430 struct cs *cs; in ahc_clear_critical_section() local
1442 cs = ahc->critical_sections; in ahc_clear_critical_section()
1443 for (i = 0; i < ahc->num_critical_sections; i++, cs++) { in ahc_clear_critical_section()
1445 if (cs->begin < seqaddr && cs->end >= seqaddr) in ahc_clear_critical_section()
1449 if (i == ahc->num_critical_sections) in ahc_clear_critical_section()
1470 if ((ahc->features & AHC_DT) != 0) in ahc_clear_critical_section()
1474 * Unfortunately we cannot re-enable in ahc_clear_critical_section()
1483 ahc_outb(ahc, SEQCTL, ahc->seqctl | STEP); in ahc_clear_critical_section()
1486 if ((ahc->features & AHC_DT) != 0) { in ahc_clear_critical_section()
1490 ahc_outb(ahc, HCNTRL, ahc->unpause); in ahc_clear_critical_section()
1497 ahc_outb(ahc, SEQCTL, ahc->seqctl); in ahc_clear_critical_section()
1528 struct hardware_scb *hscb = scb->hscb; in ahc_print_scb()
1532 hscb->control, in ahc_print_scb()
1533 hscb->scsiid, in ahc_print_scb()
1534 hscb->lun, in ahc_print_scb()
1535 hscb->cdb_len); in ahc_print_scb()
1537 for (i = 0; i < sizeof(hscb->shared_data.cdb); i++) in ahc_print_scb()
1538 printf("%#02x", hscb->shared_data.cdb[i]); in ahc_print_scb()
1540 aic_le32toh(hscb->dataptr), in ahc_print_scb()
1541 aic_le32toh(hscb->datacnt), in ahc_print_scb()
1542 aic_le32toh(hscb->sgptr), in ahc_print_scb()
1543 hscb->tag); in ahc_print_scb()
1544 if (scb->sg_count > 0) { in ahc_print_scb()
1545 for (i = 0; i < scb->sg_count; i++) { in ahc_print_scb()
1546 printf("sg[%d] - Addr 0x%x%x : Length %d\n", in ahc_print_scb()
1548 (aic_le32toh(scb->sg_list[i].len) >> 24 in ahc_print_scb()
1550 aic_le32toh(scb->sg_list[i].addr), in ahc_print_scb()
1551 aic_le32toh(scb->sg_list[i].len)); in ahc_print_scb()
1568 master_tstate = ahc->enabled_targets[ahc->our_id]; in ahc_alloc_tstate()
1571 master_tstate = ahc->enabled_targets[ahc->our_id_b + 8]; in ahc_alloc_tstate()
1573 if (ahc->enabled_targets[scsi_id] != NULL in ahc_alloc_tstate()
1574 && ahc->enabled_targets[scsi_id] != master_tstate) in ahc_alloc_tstate()
1575 panic("%s: ahc_alloc_tstate - Target already allocated", in ahc_alloc_tstate()
1590 memset(tstate->enabled_luns, 0, sizeof(tstate->enabled_luns)); in ahc_alloc_tstate()
1591 tstate->ultraenb = 0; in ahc_alloc_tstate()
1593 memset(&tstate->transinfo[i].curr, 0, in ahc_alloc_tstate()
1594 sizeof(tstate->transinfo[i].curr)); in ahc_alloc_tstate()
1595 memset(&tstate->transinfo[i].goal, 0, in ahc_alloc_tstate()
1596 sizeof(tstate->transinfo[i].goal)); in ahc_alloc_tstate()
1600 ahc->enabled_targets[scsi_id] = tstate; in ahc_alloc_tstate()
1618 if (((channel == 'B' && scsi_id == ahc->our_id_b) in ahc_free_tstate()
1619 || (channel == 'A' && scsi_id == ahc->our_id)) in ahc_free_tstate()
1625 tstate = ahc->enabled_targets[scsi_id]; in ahc_free_tstate()
1628 ahc->enabled_targets[scsi_id] = NULL; in ahc_free_tstate()
1646 if ((ahc->features & AHC_ULTRA2) != 0) { in ahc_devlimited_syncrate()
1655 } else if ((ahc->features & AHC_ULTRA) != 0) { in ahc_devlimited_syncrate()
1671 transinfo = &tinfo->user; in ahc_devlimited_syncrate()
1673 transinfo = &tinfo->goal; in ahc_devlimited_syncrate()
1674 *ppr_options &= transinfo->ppr_options; in ahc_devlimited_syncrate()
1675 if (transinfo->width == MSG_EXT_WDTR_BUS_8_BIT) { in ahc_devlimited_syncrate()
1679 if (transinfo->period == 0) { in ahc_devlimited_syncrate()
1684 *period = MAX(*period, transinfo->period); in ahc_devlimited_syncrate()
1699 if ((ahc->features & AHC_DT) == 0) in ahc_find_syncrate()
1708 syncrate->rate != NULL; in ahc_find_syncrate()
1714 if ((ahc->features & AHC_ULTRA2) != 0 in ahc_find_syncrate()
1715 && (syncrate->sxfr_u2 == 0)) in ahc_find_syncrate()
1718 if (*period <= syncrate->period) { in ahc_find_syncrate()
1731 *period = syncrate->period; in ahc_find_syncrate()
1737 if ((syncrate->sxfr_u2 & ST_SXFR) != 0) in ahc_find_syncrate()
1744 || (syncrate->rate == NULL) in ahc_find_syncrate()
1745 || ((ahc->features & AHC_ULTRA2) != 0 in ahc_find_syncrate()
1746 && (syncrate->sxfr_u2 == 0))) { in ahc_find_syncrate()
1764 if ((ahc->features & AHC_ULTRA2) != 0) in ahc_find_period()
1770 while (syncrate->rate != NULL) { in ahc_find_period()
1771 if ((ahc->features & AHC_ULTRA2) != 0) { in ahc_find_period()
1772 if (syncrate->sxfr_u2 == 0) in ahc_find_period()
1774 else if (scsirate == (syncrate->sxfr_u2 & SXFR_ULTRA2)) in ahc_find_period()
1775 return (syncrate->period); in ahc_find_period()
1776 } else if (scsirate == (syncrate->sxfr & SXFR)) { in ahc_find_period()
1777 return (syncrate->period); in ahc_find_period()
1799 } else if ((ahc->features & AHC_ULTRA2) != 0) { in ahc_validate_offset()
1810 *offset = MIN(*offset, tinfo->user.offset); in ahc_validate_offset()
1812 *offset = MIN(*offset, tinfo->goal.offset); in ahc_validate_offset()
1826 if (ahc->features & AHC_WIDE) { in ahc_validate_width()
1838 *bus_width = MIN(tinfo->user.width, *bus_width); in ahc_validate_width()
1840 *bus_width = MIN(tinfo->goal.width, *bus_width); in ahc_validate_width()
1857 auto_negotiate_orig = tstate->auto_negotiate; in ahc_update_neg_request()
1865 if ((ahc->features & AHC_WIDE) != 0) in ahc_update_neg_request()
1866 tinfo->curr.width = AHC_WIDTH_UNKNOWN; in ahc_update_neg_request()
1867 tinfo->curr.period = AHC_PERIOD_UNKNOWN; in ahc_update_neg_request()
1868 tinfo->curr.offset = AHC_OFFSET_UNKNOWN; in ahc_update_neg_request()
1870 if (tinfo->curr.period != tinfo->goal.period in ahc_update_neg_request()
1871 || tinfo->curr.width != tinfo->goal.width in ahc_update_neg_request()
1872 || tinfo->curr.offset != tinfo->goal.offset in ahc_update_neg_request()
1873 || tinfo->curr.ppr_options != tinfo->goal.ppr_options in ahc_update_neg_request()
1875 && (tinfo->goal.offset != 0 in ahc_update_neg_request()
1876 || tinfo->goal.width != MSG_EXT_WDTR_BUS_8_BIT in ahc_update_neg_request()
1877 || tinfo->goal.ppr_options != 0))) in ahc_update_neg_request()
1878 tstate->auto_negotiate |= devinfo->target_mask; in ahc_update_neg_request()
1880 tstate->auto_negotiate &= ~devinfo->target_mask; in ahc_update_neg_request()
1882 return (auto_negotiate_orig != tstate->auto_negotiate); in ahc_update_neg_request()
1914 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid, in ahc_set_syncrate()
1915 devinfo->target, &tstate); in ahc_set_syncrate()
1918 tinfo->user.period = period; in ahc_set_syncrate()
1919 tinfo->user.offset = offset; in ahc_set_syncrate()
1920 tinfo->user.ppr_options = ppr_options; in ahc_set_syncrate()
1924 tinfo->goal.period = period; in ahc_set_syncrate()
1925 tinfo->goal.offset = offset; in ahc_set_syncrate()
1926 tinfo->goal.ppr_options = ppr_options; in ahc_set_syncrate()
1929 old_period = tinfo->curr.period; in ahc_set_syncrate()
1930 old_offset = tinfo->curr.offset; in ahc_set_syncrate()
1931 old_ppr = tinfo->curr.ppr_options; in ahc_set_syncrate()
1940 scsirate = tinfo->scsirate; in ahc_set_syncrate()
1941 if ((ahc->features & AHC_ULTRA2) != 0) { in ahc_set_syncrate()
1944 scsirate |= syncrate->sxfr_u2; in ahc_set_syncrate()
1956 tstate->ultraenb &= ~devinfo->target_mask; in ahc_set_syncrate()
1958 if (syncrate->sxfr & ULTRA_SXFR) { in ahc_set_syncrate()
1959 tstate->ultraenb |= in ahc_set_syncrate()
1960 devinfo->target_mask; in ahc_set_syncrate()
1962 scsirate |= syncrate->sxfr & SXFR; in ahc_set_syncrate()
1970 if (tstate->ultraenb & devinfo->target_mask) in ahc_set_syncrate()
1977 if ((ahc->features & AHC_ULTRA2) != 0) in ahc_set_syncrate()
1981 tinfo->scsirate = scsirate; in ahc_set_syncrate()
1982 tinfo->curr.period = period; in ahc_set_syncrate()
1983 tinfo->curr.offset = offset; in ahc_set_syncrate()
1984 tinfo->curr.ppr_options = ppr_options; in ahc_set_syncrate()
1986 ahc_send_async(ahc, devinfo->channel, devinfo->target, in ahc_set_syncrate()
1992 devinfo->target, syncrate->rate, in ahc_set_syncrate()
1998 ahc_name(ahc), devinfo->target); in ahc_set_syncrate()
2030 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid, in ahc_set_width()
2031 devinfo->target, &tstate); in ahc_set_width()
2034 tinfo->user.width = width; in ahc_set_width()
2037 tinfo->goal.width = width; in ahc_set_width()
2039 oldwidth = tinfo->curr.width; in ahc_set_width()
2044 scsirate = tinfo->scsirate; in ahc_set_width()
2049 tinfo->scsirate = scsirate; in ahc_set_width()
2054 tinfo->curr.width = width; in ahc_set_width()
2056 ahc_send_async(ahc, devinfo->channel, devinfo->target, in ahc_set_width()
2060 ahc_name(ahc), devinfo->target, in ahc_set_width()
2079 ahc_send_async(ahc, devinfo->channel, devinfo->target, in ahc_set_tags()
2080 devinfo->lun, AC_TRANSFER_NEG, &alg); in ahc_set_tags()
2085 * in-transit SCBs to contain the new data so the hardware will
2102 LIST_FOREACH(pending_scb, &ahc->pending_scbs, pending_links) { in ahc_update_pending_scbs()
2112 pending_hscb = pending_scb->hscb; in ahc_update_pending_scbs()
2113 pending_hscb->control &= ~ULTRAENB; in ahc_update_pending_scbs()
2114 if ((tstate->ultraenb & devinfo.target_mask) != 0) in ahc_update_pending_scbs()
2115 pending_hscb->control |= ULTRAENB; in ahc_update_pending_scbs()
2116 pending_hscb->scsirate = tinfo->scsirate; in ahc_update_pending_scbs()
2117 pending_hscb->scsioffset = tinfo->curr.offset; in ahc_update_pending_scbs()
2118 if ((tstate->auto_negotiate & devinfo.target_mask) == 0 in ahc_update_pending_scbs()
2119 && (pending_scb->flags & SCB_AUTO_NEGOTIATE) != 0) { in ahc_update_pending_scbs()
2120 pending_scb->flags &= ~SCB_AUTO_NEGOTIATE; in ahc_update_pending_scbs()
2121 pending_hscb->control &= ~MK_MESSAGE; in ahc_update_pending_scbs()
2140 for (i = 0; i < ahc->scb_data->maxhscbs; i++) { in ahc_update_pending_scbs()
2151 pending_hscb = pending_scb->hscb; in ahc_update_pending_scbs()
2154 control |= pending_hscb->control & (ULTRAENB|MK_MESSAGE); in ahc_update_pending_scbs()
2156 ahc_outb(ahc, SCB_SCSIRATE, pending_hscb->scsirate); in ahc_update_pending_scbs()
2157 ahc_outb(ahc, SCB_SCSIOFFSET, pending_hscb->scsioffset); in ahc_update_pending_scbs()
2179 && (ahc->features & AHC_MULTI_TID) != 0 in ahc_fetch_devinfo()
2184 } else if ((ahc->features & AHC_ULTRA2) != 0) in ahc_fetch_devinfo()
2210 if (phase == entry->phase) in ahc_lookup_phase_entry()
2220 devinfo->our_scsiid = our_id; in ahc_compile_devinfo()
2221 devinfo->target = target; in ahc_compile_devinfo()
2222 devinfo->lun = lun; in ahc_compile_devinfo()
2223 devinfo->target_offset = target; in ahc_compile_devinfo()
2224 devinfo->channel = channel; in ahc_compile_devinfo()
2225 devinfo->role = role; in ahc_compile_devinfo()
2227 devinfo->target_offset += 8; in ahc_compile_devinfo()
2228 devinfo->target_mask = (0x01 << devinfo->target_offset); in ahc_compile_devinfo()
2234 printf("%s:%c:%d:%d: ", ahc_name(ahc), devinfo->channel, in ahc_print_devinfo()
2235 devinfo->target, devinfo->lun); in ahc_print_devinfo()
2245 our_id = SCSIID_OUR_ID(scb->hscb->scsiid); in ahc_scb_devinfo()
2247 if ((scb->flags & SCB_TARGET_SCB) != 0) in ahc_scb_devinfo()
2260 if ((ahc->features & AHC_DT) == 0) in ahc_assert_atn()
2280 ahc->msgout_index = 0; in ahc_setup_initiator_msgout()
2281 ahc->msgout_len = 0; in ahc_setup_initiator_msgout()
2283 if ((scb->flags & SCB_DEVICE_RESET) == 0 in ahc_setup_initiator_msgout()
2288 if ((scb->hscb->control & DISCENB) != 0) in ahc_setup_initiator_msgout()
2290 ahc->msgout_buf[ahc->msgout_index++] = identify_msg; in ahc_setup_initiator_msgout()
2291 ahc->msgout_len++; in ahc_setup_initiator_msgout()
2293 if ((scb->hscb->control & TAG_ENB) != 0) { in ahc_setup_initiator_msgout()
2294 ahc->msgout_buf[ahc->msgout_index++] = in ahc_setup_initiator_msgout()
2295 scb->hscb->control & (TAG_ENB|SCB_TAG_TYPE); in ahc_setup_initiator_msgout()
2296 ahc->msgout_buf[ahc->msgout_index++] = scb->hscb->tag; in ahc_setup_initiator_msgout()
2297 ahc->msgout_len += 2; in ahc_setup_initiator_msgout()
2301 if (scb->flags & SCB_DEVICE_RESET) { in ahc_setup_initiator_msgout()
2302 ahc->msgout_buf[ahc->msgout_index++] = MSG_BUS_DEV_RESET; in ahc_setup_initiator_msgout()
2303 ahc->msgout_len++; in ahc_setup_initiator_msgout()
2314 } else if ((scb->flags & SCB_ABORT) != 0) { in ahc_setup_initiator_msgout()
2315 if ((scb->hscb->control & TAG_ENB) != 0) in ahc_setup_initiator_msgout()
2316 ahc->msgout_buf[ahc->msgout_index++] = MSG_ABORT_TAG; in ahc_setup_initiator_msgout()
2318 ahc->msgout_buf[ahc->msgout_index++] = MSG_ABORT; in ahc_setup_initiator_msgout()
2319 ahc->msgout_len++; in ahc_setup_initiator_msgout()
2322 (scb->hscb->control & TAG_ENB) != 0 ? " Tag" : ""); in ahc_setup_initiator_msgout()
2331 } else if ((scb->flags & (SCB_AUTO_NEGOTIATE|SCB_NEGOTIATE)) != 0) { in ahc_setup_initiator_msgout()
2336 printf("SCSIID = %x, target_mask = %x\n", scb->hscb->scsiid, in ahc_setup_initiator_msgout()
2337 devinfo->target_mask); in ahc_setup_initiator_msgout()
2339 "SCB flags = %x", scb->hscb->tag, scb->hscb->control, in ahc_setup_initiator_msgout()
2340 ahc_inb(ahc, MSG_OUT), scb->flags); in ahc_setup_initiator_msgout()
2348 scb->hscb->control &= ~MK_MESSAGE; in ahc_setup_initiator_msgout()
2349 ahc->msgout_index = 0; in ahc_setup_initiator_msgout()
2350 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT; in ahc_setup_initiator_msgout()
2375 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid, in ahc_build_transfer_msg()
2376 devinfo->target, &tstate); in ahc_build_transfer_msg()
2383 period = tinfo->goal.period; in ahc_build_transfer_msg()
2384 offset = tinfo->goal.offset; in ahc_build_transfer_msg()
2385 ppr_options = tinfo->goal.ppr_options; in ahc_build_transfer_msg()
2387 if (devinfo->role == ROLE_TARGET) in ahc_build_transfer_msg()
2390 &ppr_options, devinfo->role); in ahc_build_transfer_msg()
2391 dowide = tinfo->curr.width != tinfo->goal.width; in ahc_build_transfer_msg()
2392 dosync = tinfo->curr.offset != offset || tinfo->curr.period != period; in ahc_build_transfer_msg()
2401 dowide = tinfo->goal.width != MSG_EXT_WDTR_BUS_8_BIT; in ahc_build_transfer_msg()
2402 dosync = tinfo->goal.offset != 0; in ahc_build_transfer_msg()
2410 if ((ahc->features & AHC_WIDE) != 0) in ahc_build_transfer_msg()
2422 if (devinfo->role == ROLE_TARGET) in ahc_build_transfer_msg()
2428 * is capable of handling (based on whether an LVD->SE in ahc_build_transfer_msg()
2434 offset = tinfo->goal.offset; in ahc_build_transfer_msg()
2436 doppr ? tinfo->goal.width in ahc_build_transfer_msg()
2437 : tinfo->curr.width, in ahc_build_transfer_msg()
2438 devinfo->role); in ahc_build_transfer_msg()
2441 tinfo->goal.width, ppr_options); in ahc_build_transfer_msg()
2446 ahc_construct_wdtr(ahc, devinfo, tinfo->goal.width); in ahc_build_transfer_msg()
2460 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXTENDED; in ahc_construct_sdtr()
2461 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_SDTR_LEN; in ahc_construct_sdtr()
2462 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_SDTR; in ahc_construct_sdtr()
2463 ahc->msgout_buf[ahc->msgout_index++] = period; in ahc_construct_sdtr()
2464 ahc->msgout_buf[ahc->msgout_index++] = offset; in ahc_construct_sdtr()
2465 ahc->msgout_len += 5; in ahc_construct_sdtr()
2468 ahc_name(ahc), devinfo->channel, devinfo->target, in ahc_construct_sdtr()
2469 devinfo->lun, period, offset); in ahc_construct_sdtr()
2481 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXTENDED; in ahc_construct_wdtr()
2482 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_WDTR_LEN; in ahc_construct_wdtr()
2483 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_WDTR; in ahc_construct_wdtr()
2484 ahc->msgout_buf[ahc->msgout_index++] = bus_width; in ahc_construct_wdtr()
2485 ahc->msgout_len += 4; in ahc_construct_wdtr()
2488 ahc_name(ahc), devinfo->channel, devinfo->target, in ahc_construct_wdtr()
2489 devinfo->lun, bus_width); in ahc_construct_wdtr()
2504 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXTENDED; in ahc_construct_ppr()
2505 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_PPR_LEN; in ahc_construct_ppr()
2506 ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_PPR; in ahc_construct_ppr()
2507 ahc->msgout_buf[ahc->msgout_index++] = period; in ahc_construct_ppr()
2508 ahc->msgout_buf[ahc->msgout_index++] = 0; in ahc_construct_ppr()
2509 ahc->msgout_buf[ahc->msgout_index++] = offset; in ahc_construct_ppr()
2510 ahc->msgout_buf[ahc->msgout_index++] = bus_width; in ahc_construct_ppr()
2511 ahc->msgout_buf[ahc->msgout_index++] = ppr_options; in ahc_construct_ppr()
2512 ahc->msgout_len += 8; in ahc_construct_ppr()
2516 devinfo->channel, devinfo->target, devinfo->lun, in ahc_construct_ppr()
2527 ahc->msgout_len = 0; in ahc_clear_msg_state()
2528 ahc->msgin_index = 0; in ahc_clear_msg_state()
2529 ahc->msg_type = MSG_TYPE_NONE; in ahc_clear_msg_state()
2622 ahc->msgout_buf[0] = MSG_ABORT_TASK; in ahc_handle_proto_violation()
2623 ahc->msgout_len = 1; in ahc_handle_proto_violation()
2624 ahc->msgout_index = 0; in ahc_handle_proto_violation()
2625 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT; in ahc_handle_proto_violation()
2628 scb->flags |= SCB_ABORT; in ahc_handle_proto_violation()
2631 ahc_lookup_phase_entry(curphase)->phasemsg); in ahc_handle_proto_violation()
2650 switch (ahc->msg_type) { in ahc_handle_message_phase()
2657 if (ahc->msgout_len == 0) in ahc_handle_message_phase()
2672 ->phasemsg); in ahc_handle_message_phase()
2683 ahc->send_msg_perror = FALSE; in ahc_handle_message_phase()
2684 ahc->msg_type = MSG_TYPE_INITIATOR_MSGIN; in ahc_handle_message_phase()
2685 ahc->msgin_index = 0; in ahc_handle_message_phase()
2692 if (ahc->send_msg_perror) { in ahc_handle_message_phase()
2697 printf(" byte 0x%x\n", ahc->send_msg_perror); in ahc_handle_message_phase()
2703 msgdone = ahc->msgout_index == ahc->msgout_len; in ahc_handle_message_phase()
2707 * Re-assert ATN, reset our message index to in ahc_handle_message_phase()
2710 ahc->msgout_index = 0; in ahc_handle_message_phase()
2714 lastbyte = ahc->msgout_index == (ahc->msgout_len - 1); in ahc_handle_message_phase()
2728 ahc->msgout_buf[ahc->msgout_index]); in ahc_handle_message_phase()
2730 ahc_outb(ahc, SCSIDATL, ahc->msgout_buf[ahc->msgout_index++]); in ahc_handle_message_phase()
2750 ->phasemsg); in ahc_handle_message_phase()
2753 ahc->msgin_index = 0; in ahc_handle_message_phase()
2755 && (ahc->send_msg_perror == TRUE in ahc_handle_message_phase()
2756 || (ahc->msgout_len != 0 in ahc_handle_message_phase()
2757 && ahc->msgout_index == 0))) { in ahc_handle_message_phase()
2758 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT; in ahc_handle_message_phase()
2766 ahc->msgin_buf[ahc->msgin_index] = ahc_inb(ahc, SCSIBUSL); in ahc_handle_message_phase()
2770 ahc->msgin_buf[ahc->msgin_index]); in ahc_handle_message_phase()
2780 ahc->msgin_index = 0; in ahc_handle_message_phase()
2787 if (ahc->msgout_len != 0) { in ahc_handle_message_phase()
2797 ahc->msgin_index++; in ahc_handle_message_phase()
2812 if (ahc->msgout_len == 0) in ahc_handle_message_phase()
2829 && ahc->msgout_index > 0) { in ahc_handle_message_phase()
2839 ahc->msg_type = MSG_TYPE_TARGET_MSGOUT; in ahc_handle_message_phase()
2852 * *de-assert* before changing phases. in ahc_handle_message_phase()
2861 * settle delay before REQ is asserted. in ahc_handle_message_phase()
2867 ahc->msgin_index = 0; in ahc_handle_message_phase()
2874 msgdone = ahc->msgout_index == ahc->msgout_len; in ahc_handle_message_phase()
2888 ahc->msgout_buf[ahc->msgout_index]); in ahc_handle_message_phase()
2891 ahc_outb(ahc, SCSIDATL, ahc->msgout_buf[ahc->msgout_index++]); in ahc_handle_message_phase()
2917 ahc->msgin_buf[ahc->msgin_index] = ahc_inb(ahc, SCSIDATL); in ahc_handle_message_phase()
2922 ahc->msgin_buf[ahc->msgin_index]); in ahc_handle_message_phase()
2936 ahc->msgin_index++; in ahc_handle_message_phase()
2943 ahc->msgin_index = 0; in ahc_handle_message_phase()
2949 if (ahc->msgout_len != 0) { in ahc_handle_message_phase()
2960 * settle delay before REQ is asserted. in ahc_handle_message_phase()
2963 * also wait a data release delay to allow in ahc_handle_message_phase()
2979 ahc->msg_type = MSG_TYPE_TARGET_MSGIN; in ahc_handle_message_phase()
2980 ahc->msgin_index = 0; in ahc_handle_message_phase()
3021 while (index < ahc->msgout_len) { in ahc_sent_msg()
3022 if (ahc->msgout_buf[index] == MSG_EXTENDED) { in ahc_sent_msg()
3025 end_index = index + 1 + ahc->msgout_buf[index + 1]; in ahc_sent_msg()
3026 if (ahc->msgout_buf[index+2] == msgval in ahc_sent_msg()
3029 if (ahc->msgout_index > end_index) in ahc_sent_msg()
3031 } else if (ahc->msgout_index > index) in ahc_sent_msg()
3035 } else if (ahc->msgout_buf[index] >= MSG_SIMPLE_TASK in ahc_sent_msg()
3036 && ahc->msgout_buf[index] <= MSG_IGN_WIDE_RESIDUE) { in ahc_sent_msg()
3042 && ahc->msgout_buf[index] == msgval in ahc_sent_msg()
3043 && ahc->msgout_index > index) in ahc_sent_msg()
3070 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid, in ahc_parse_msg()
3071 devinfo->target, &tstate); in ahc_parse_msg()
3072 targ_scsirate = tinfo->scsirate; in ahc_parse_msg()
3085 switch (ahc->msgin_buf[0]) { in ahc_parse_msg()
3106 if (ahc->msgin_index < 2) in ahc_parse_msg()
3108 switch (ahc->msgin_buf[2]) { in ahc_parse_msg()
3117 if (ahc->msgin_buf[1] != MSG_EXT_SDTR_LEN) { in ahc_parse_msg()
3129 if (ahc->msgin_index < (MSG_EXT_SDTR_LEN + 1)) in ahc_parse_msg()
3132 period = ahc->msgin_buf[3]; in ahc_parse_msg()
3134 saved_offset = offset = ahc->msgin_buf[4]; in ahc_parse_msg()
3137 devinfo->role); in ahc_parse_msg()
3140 devinfo->role); in ahc_parse_msg()
3145 ahc_name(ahc), devinfo->channel, in ahc_parse_msg()
3146 devinfo->target, devinfo->lun, in ahc_parse_msg()
3147 ahc->msgin_buf[3], saved_offset, in ahc_parse_msg()
3164 /* Went too low - force async */ in ahc_parse_msg()
3172 && devinfo->role == ROLE_INITIATOR) { in ahc_parse_msg()
3175 ahc_name(ahc), devinfo->channel, in ahc_parse_msg()
3176 devinfo->target, devinfo->lun); in ahc_parse_msg()
3178 ahc->msgout_index = 0; in ahc_parse_msg()
3179 ahc->msgout_len = 0; in ahc_parse_msg()
3182 ahc->msgout_index = 0; in ahc_parse_msg()
3195 if (ahc->msgin_buf[1] != MSG_EXT_WDTR_LEN) { in ahc_parse_msg()
3207 if (ahc->msgin_index < (MSG_EXT_WDTR_LEN + 1)) in ahc_parse_msg()
3210 bus_width = ahc->msgin_buf[3]; in ahc_parse_msg()
3213 devinfo->role); in ahc_parse_msg()
3217 ahc_name(ahc), devinfo->channel, in ahc_parse_msg()
3218 devinfo->target, devinfo->lun, in ahc_parse_msg()
3233 ahc_name(ahc), devinfo->channel, in ahc_parse_msg()
3234 devinfo->target, devinfo->lun, in ahc_parse_msg()
3243 && devinfo->role == ROLE_INITIATOR) { in ahc_parse_msg()
3246 ahc_name(ahc), devinfo->channel, in ahc_parse_msg()
3247 devinfo->target, devinfo->lun); in ahc_parse_msg()
3249 ahc->msgout_index = 0; in ahc_parse_msg()
3250 ahc->msgout_len = 0; in ahc_parse_msg()
3252 ahc->msgout_index = 0; in ahc_parse_msg()
3274 ahc->msgout_index = 0; in ahc_parse_msg()
3275 ahc->msgout_len = 0; in ahc_parse_msg()
3277 ahc->msgout_index = 0; in ahc_parse_msg()
3294 if (ahc->msgin_buf[1] != MSG_EXT_PPR_LEN) { in ahc_parse_msg()
3306 if (ahc->msgin_index < (MSG_EXT_PPR_LEN + 1)) in ahc_parse_msg()
3309 period = ahc->msgin_buf[3]; in ahc_parse_msg()
3310 offset = ahc->msgin_buf[5]; in ahc_parse_msg()
3311 bus_width = ahc->msgin_buf[6]; in ahc_parse_msg()
3313 ppr_options = ahc->msgin_buf[7]; in ahc_parse_msg()
3335 devinfo->role); in ahc_parse_msg()
3338 devinfo->role); in ahc_parse_msg()
3341 devinfo->role); in ahc_parse_msg()
3360 if (devinfo->role != ROLE_TARGET) in ahc_parse_msg()
3363 ahc_name(ahc), devinfo->channel, in ahc_parse_msg()
3364 devinfo->target, devinfo->lun); in ahc_parse_msg()
3368 ahc_name(ahc), devinfo->channel, in ahc_parse_msg()
3369 devinfo->target, devinfo->lun); in ahc_parse_msg()
3370 ahc->msgout_index = 0; in ahc_parse_msg()
3371 ahc->msgout_len = 0; in ahc_parse_msg()
3374 ahc->msgout_index = 0; in ahc_parse_msg()
3382 ahc_name(ahc), devinfo->channel, in ahc_parse_msg()
3383 devinfo->target, devinfo->lun, in ahc_parse_msg()
3384 saved_width, ahc->msgin_buf[3], in ahc_parse_msg()
3422 if (devinfo->role != ROLE_TARGET) { in ahc_parse_msg()
3427 if (ahc->msgin_buf[0] == MSG_ABORT_TAG) in ahc_parse_msg()
3429 ahc_abort_scbs(ahc, devinfo->target, devinfo->channel, in ahc_parse_msg()
3430 devinfo->lun, tag, ROLE_TARGET, in ahc_parse_msg()
3433 tstate = ahc->enabled_targets[devinfo->our_scsiid]; in ahc_parse_msg()
3437 lstate = tstate->enabled_luns[devinfo->lun]; in ahc_parse_msg()
3440 devinfo->our_scsiid, in ahc_parse_msg()
3441 ahc->msgin_buf[0], in ahc_parse_msg()
3459 * Setup to reject the message. in ahc_parse_msg()
3461 ahc->msgout_index = 0; in ahc_parse_msg()
3462 ahc->msgout_len = 1; in ahc_parse_msg()
3463 ahc->msgout_buf[0] = MSG_MESSAGE_REJECT; in ahc_parse_msg()
3470 ahc->msgout_len = 0; in ahc_parse_msg()
3496 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, in ahc_handle_msg_reject()
3497 devinfo->our_scsiid, in ahc_handle_msg_reject()
3498 devinfo->target, &tstate); in ahc_handle_msg_reject()
3505 * Attempt to negotiate SPI-2 style. in ahc_handle_msg_reject()
3510 ahc_name(ahc), devinfo->channel, in ahc_handle_msg_reject()
3511 devinfo->target, devinfo->lun); in ahc_handle_msg_reject()
3513 tinfo->goal.ppr_options = 0; in ahc_handle_msg_reject()
3514 tinfo->curr.transport_version = 2; in ahc_handle_msg_reject()
3515 tinfo->goal.transport_version = 2; in ahc_handle_msg_reject()
3516 ahc->msgout_index = 0; in ahc_handle_msg_reject()
3517 ahc->msgout_len = 0; in ahc_handle_msg_reject()
3519 ahc->msgout_index = 0; in ahc_handle_msg_reject()
3525 devinfo->channel, devinfo->target, devinfo->lun); in ahc_handle_msg_reject()
3536 if (tinfo->goal.offset != tinfo->curr.offset) { in ahc_handle_msg_reject()
3538 ahc->msgout_index = 0; in ahc_handle_msg_reject()
3539 ahc->msgout_len = 0; in ahc_handle_msg_reject()
3541 ahc->msgout_index = 0; in ahc_handle_msg_reject()
3552 ahc_name(ahc), devinfo->channel, in ahc_handle_msg_reject()
3553 devinfo->target, devinfo->lun); in ahc_handle_msg_reject()
3554 } else if ((scb->hscb->control & MSG_SIMPLE_TASK) != 0) { in ahc_handle_msg_reject()
3558 tag_type = (scb->hscb->control & MSG_SIMPLE_TASK); in ahc_handle_msg_reject()
3562 "Performing non-tagged I/O\n", ahc_name(ahc), in ahc_handle_msg_reject()
3563 devinfo->channel, devinfo->target, devinfo->lun); in ahc_handle_msg_reject()
3569 ahc_name(ahc), devinfo->channel, devinfo->target, in ahc_handle_msg_reject()
3570 devinfo->lun, tag_type == MSG_ORDERED_TASK in ahc_handle_msg_reject()
3582 scb->hscb->control &= mask; in ahc_handle_msg_reject()
3592 if ((ahc->flags & AHC_SCB_BTT) == 0) { in ahc_handle_msg_reject()
3596 &(ahc->untagged_queues[devinfo->target_offset]); in ahc_handle_msg_reject()
3598 scb->flags |= SCB_UNTAGGEDQ; in ahc_handle_msg_reject()
3600 ahc_busy_tcl(ahc, BUILD_TCL(scb->hscb->scsiid, devinfo->lun), in ahc_handle_msg_reject()
3601 scb->hscb->tag); in ahc_handle_msg_reject()
3617 printf("%s:%c:%d: Message reject for %x -- ignored\n", in ahc_handle_msg_reject()
3618 ahc_name(ahc), devinfo->channel, devinfo->target, in ahc_handle_msg_reject()
3691 sg--; in ahc_handle_ign_wide_residue()
3692 sglen = aic_le32toh(sg->len) & AHC_SG_LEN_MASK; in ahc_handle_ign_wide_residue()
3693 if (sg != scb->sg_list in ahc_handle_ign_wide_residue()
3695 sg--; in ahc_handle_ign_wide_residue()
3696 sglen = aic_le32toh(sg->len); in ahc_handle_ign_wide_residue()
3714 * to handle this mid-transfer ignore wide in ahc_handle_ign_wide_residue()
3749 sg--; in ahc_reinitialize_dataptrs()
3755 dataptr = aic_le32toh(sg->addr) in ahc_reinitialize_dataptrs()
3756 + (aic_le32toh(sg->len) & AHC_SG_LEN_MASK) in ahc_reinitialize_dataptrs()
3757 - resid; in ahc_reinitialize_dataptrs()
3758 if ((ahc->flags & AHC_39BIT_ADDRESSING) != 0) { in ahc_reinitialize_dataptrs()
3764 (aic_le32toh(sg->len) >> 24) & SG_HIGH_ADDR_BITS); in ahc_reinitialize_dataptrs()
3774 if ((ahc->features & AHC_ULTRA2) == 0) { in ahc_reinitialize_dataptrs()
3794 found = ahc_abort_scbs(ahc, devinfo->target, devinfo->channel, in ahc_handle_devreset()
3795 CAM_LUN_WILDCARD, SCB_LIST_NULL, devinfo->role, in ahc_handle_devreset()
3803 tstate = ahc->enabled_targets[devinfo->our_scsiid]; in ahc_handle_devreset()
3808 lstate = tstate->enabled_luns[lun]; in ahc_handle_devreset()
3812 ahc_queue_lstate_event(ahc, lstate, devinfo->our_scsiid, in ahc_handle_devreset()
3829 ahc_send_async(ahc, devinfo->channel, devinfo->target, in ahc_handle_devreset()
3835 message, devinfo->channel, devinfo->target, found); in ahc_handle_devreset()
3849 ahc->msgout_index = 0; in ahc_setup_target_msgin()
3850 ahc->msgout_len = 0; in ahc_setup_target_msgin()
3852 if (scb != NULL && (scb->flags & SCB_AUTO_NEGOTIATE) != 0) in ahc_setup_target_msgin()
3857 ahc->msgout_index = 0; in ahc_setup_target_msgin()
3858 ahc->msg_type = MSG_TYPE_TARGET_MSGIN; in ahc_setup_target_msgin()
3874 ahc->seep_config = malloc(sizeof(*ahc->seep_config), in ahc_alloc()
3876 if (ahc->seep_config == NULL) { in ahc_alloc()
3880 LIST_INIT(&ahc->pending_scbs); in ahc_alloc()
3881 LIST_INIT(&ahc->timedout_scbs); in ahc_alloc()
3883 ahc->name = name; in ahc_alloc()
3884 ahc->unit = -1; in ahc_alloc()
3885 ahc->description = NULL; in ahc_alloc()
3886 ahc->channel = 'A'; in ahc_alloc()
3887 ahc->channel_b = 'B'; in ahc_alloc()
3888 ahc->chip = AHC_NONE; in ahc_alloc()
3889 ahc->features = AHC_FENONE; in ahc_alloc()
3890 ahc->bugs = AHC_BUGNONE; in ahc_alloc()
3891 ahc->flags = AHC_FNONE; in ahc_alloc()
3897 ahc->seqctl = FASTMODE; in ahc_alloc()
3900 TAILQ_INIT(&ahc->untagged_queues[i]); in ahc_alloc()
3914 if ((ahc->chip & AHC_PCI) == 0) in ahc_softc_init()
3915 ahc->unpause = ahc_inb(ahc, HCNTRL) & IRQMS; in ahc_softc_init()
3917 ahc->unpause = 0; in ahc_softc_init()
3918 ahc->pause = ahc->unpause | PAUSE; in ahc_softc_init()
3920 if (ahc->scb_data == NULL) { in ahc_softc_init()
3921 ahc->scb_data = malloc(sizeof(*ahc->scb_data), in ahc_softc_init()
3923 if (ahc->scb_data == NULL) in ahc_softc_init()
3925 memset(ahc->scb_data, 0, sizeof(*ahc->scb_data)); in ahc_softc_init()
3941 if ((ahc->chip & AHC_BUS_MASK) == AHC_PCI in ahc_softc_insert()
3942 && (ahc->features & AHC_MULTI_FUNC) != 0) { in ahc_softc_insert()
3947 list_pci = list_ahc->dev_softc; in ahc_softc_insert()
3948 pci = ahc->dev_softc; in ahc_softc_insert()
3961 slave->flags &= ~AHC_BIOS_ENABLED; in ahc_softc_insert()
3962 slave->flags |= in ahc_softc_insert()
3963 master->flags & AHC_BIOS_ENABLED; in ahc_softc_insert()
3964 slave->flags &= ~AHC_PRIMARY_CHANNEL; in ahc_softc_insert()
3965 slave->flags |= in ahc_softc_insert()
3966 master->flags & AHC_PRIMARY_CHANNEL; in ahc_softc_insert()
3984 ahc->init_level++; in ahc_softc_insert()
3990 ahc->unit = unit; in ahc_set_unit()
3996 if (ahc->name != NULL) in ahc_set_name()
3997 free(ahc->name, M_DEVBUF); in ahc_set_name()
3998 ahc->name = name; in ahc_set_name()
4007 switch (ahc->init_level) { in ahc_free()
4013 aic_dmamap_unload(ahc, ahc->shared_data_dmat, in ahc_free()
4014 ahc->shared_data_dmamap); in ahc_free()
4017 aic_dmamem_free(ahc, ahc->shared_data_dmat, ahc->qoutfifo, in ahc_free()
4018 ahc->shared_data_dmamap); in ahc_free()
4021 aic_dma_tag_destroy(ahc, ahc->shared_data_dmat); in ahc_free()
4023 aic_dma_tag_destroy(ahc, ahc->buffer_dmat); in ahc_free()
4029 aic_dma_tag_destroy(ahc, ahc->parent_dmat); in ahc_free()
4035 tstate = ahc->enabled_targets[i]; in ahc_free()
4043 lstate = tstate->enabled_luns[j]; in ahc_free()
4045 xpt_free_path(lstate->path); in ahc_free()
4054 if (ahc->black_hole != NULL) { in ahc_free()
4055 xpt_free_path(ahc->black_hole->path); in ahc_free()
4056 free(ahc->black_hole, M_DEVBUF); in ahc_free()
4059 if (ahc->name != NULL) in ahc_free()
4060 free(ahc->name, M_DEVBUF); in ahc_free()
4061 if (ahc->seep_config != NULL) in ahc_free()
4062 free(ahc->seep_config, M_DEVBUF); in ahc_free()
4087 * non-zero, this reset occurred after initial configuration
4108 if ((ahc->chip & AHC_CHIPID_MASK) == AHC_AIC7770) { in ahc_reset()
4113 * is setup for TWIN channel operation. in ahc_reset()
4122 ahc_outb(ahc, HCNTRL, CHIPRST | ahc->pause); in ahc_reset()
4125 * Ensure that the reset has finished. We delay 1000us in ahc_reset()
4133 } while (--wait && !(ahc_inb(ahc, HCNTRL) & CHIPRSTACK)); in ahc_reset()
4136 printf("%s: WARNING - Failed chip reset! " in ahc_reset()
4139 ahc_outb(ahc, HCNTRL, ahc->pause); in ahc_reset()
4144 if ((ahc->chip & AHC_PCI) != 0) in ahc_reset()
4152 ahc->features |= AHC_WIDE; in ahc_reset()
4156 ahc->features |= AHC_TWIN; in ahc_reset()
4160 return(-1); in ahc_reset()
4168 * to a tri-state condition which can only be cleared in ahc_reset()
4171 if ((ahc->features & AHC_TWIN) != 0) { in ahc_reset()
4185 * re-initialize the chip to our liking. in ahc_reset()
4187 error = ahc->bus_chip_init(ahc); in ahc_reset()
4221 *baddr = segs->ds_addr; in ahc_dmamap_cb()
4231 if ((ahc->flags & AHC_LSCBS_ENABLED) != 0) in ahc_build_free_scb_list()
4234 for (i = 0; i < ahc->scb_data->maxhscbs; i++) { in ahc_build_free_scb_list()
4251 if ((ahc->flags & AHC_PAGESCBS) != 0) in ahc_build_free_scb_list()
4262 if ((ahc->flags & AHC_PAGESCBS) != 0) { in ahc_build_free_scb_list()
4271 ahc_outb(ahc, SCBPTR, i-1); in ahc_build_free_scb_list()
4280 scb_data = ahc->scb_data; in ahc_init_scbdata()
4281 SLIST_INIT(&scb_data->free_scbs); in ahc_init_scbdata()
4282 SLIST_INIT(&scb_data->sg_maps); in ahc_init_scbdata()
4285 scb_data->scbarray = in ahc_init_scbdata()
4288 if (scb_data->scbarray == NULL) in ahc_init_scbdata()
4290 memset(scb_data->scbarray, 0, sizeof(struct scb) * AHC_SCB_MAX_ALLOC); in ahc_init_scbdata()
4294 scb_data->maxhscbs = ahc_probe_scbs(ahc); in ahc_init_scbdata()
4295 if (ahc->scb_data->maxhscbs == 0) { in ahc_init_scbdata()
4311 if (aic_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1, in ahc_init_scbdata()
4319 /*flags*/0, &scb_data->hscb_dmat) != 0) { in ahc_init_scbdata()
4323 scb_data->init_level++; in ahc_init_scbdata()
4326 if (aic_dmamem_alloc(ahc, scb_data->hscb_dmat, in ahc_init_scbdata()
4327 (void **)&scb_data->hscbs, in ahc_init_scbdata()
4329 &scb_data->hscb_dmamap) != 0) { in ahc_init_scbdata()
4333 scb_data->init_level++; in ahc_init_scbdata()
4336 aic_dmamap_load(ahc, scb_data->hscb_dmat, scb_data->hscb_dmamap, in ahc_init_scbdata()
4337 scb_data->hscbs, in ahc_init_scbdata()
4339 ahc_dmamap_cb, &scb_data->hscb_busaddr, /*flags*/0); in ahc_init_scbdata()
4341 scb_data->init_level++; in ahc_init_scbdata()
4344 if (aic_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1, in ahc_init_scbdata()
4352 /*flags*/0, &scb_data->sense_dmat) != 0) { in ahc_init_scbdata()
4356 scb_data->init_level++; in ahc_init_scbdata()
4359 if (aic_dmamem_alloc(ahc, scb_data->sense_dmat, in ahc_init_scbdata()
4360 (void **)&scb_data->sense, in ahc_init_scbdata()
4361 BUS_DMA_NOWAIT, &scb_data->sense_dmamap) != 0) { in ahc_init_scbdata()
4365 scb_data->init_level++; in ahc_init_scbdata()
4368 aic_dmamap_load(ahc, scb_data->sense_dmat, scb_data->sense_dmamap, in ahc_init_scbdata()
4369 scb_data->sense, in ahc_init_scbdata()
4371 ahc_dmamap_cb, &scb_data->sense_busaddr, /*flags*/0); in ahc_init_scbdata()
4373 scb_data->init_level++; in ahc_init_scbdata()
4376 if (aic_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/8, in ahc_init_scbdata()
4383 /*flags*/0, &scb_data->sg_dmat) != 0) { in ahc_init_scbdata()
4387 scb_data->init_level++; in ahc_init_scbdata()
4390 memset(scb_data->hscbs, 0, in ahc_init_scbdata()
4395 if (scb_data->numscbs == 0) { in ahc_init_scbdata()
4396 printf("%s: ahc_init_scbdata - " in ahc_init_scbdata()
4405 ahc->next_queued_scb = ahc_get_scb(ahc); in ahc_init_scbdata()
4422 scb_data = ahc->scb_data; in ahc_fini_scbdata()
4426 switch (scb_data->init_level) { in ahc_fini_scbdata()
4432 while ((sg_map = SLIST_FIRST(&scb_data->sg_maps))!= NULL) { in ahc_fini_scbdata()
4433 SLIST_REMOVE_HEAD(&scb_data->sg_maps, links); in ahc_fini_scbdata()
4434 aic_dmamap_unload(ahc, scb_data->sg_dmat, in ahc_fini_scbdata()
4435 sg_map->sg_dmamap); in ahc_fini_scbdata()
4436 aic_dmamem_free(ahc, scb_data->sg_dmat, in ahc_fini_scbdata()
4437 sg_map->sg_vaddr, in ahc_fini_scbdata()
4438 sg_map->sg_dmamap); in ahc_fini_scbdata()
4441 aic_dma_tag_destroy(ahc, scb_data->sg_dmat); in ahc_fini_scbdata()
4444 aic_dmamap_unload(ahc, scb_data->sense_dmat, in ahc_fini_scbdata()
4445 scb_data->sense_dmamap); in ahc_fini_scbdata()
4447 aic_dmamem_free(ahc, scb_data->sense_dmat, scb_data->sense, in ahc_fini_scbdata()
4448 scb_data->sense_dmamap); in ahc_fini_scbdata()
4450 aic_dma_tag_destroy(ahc, scb_data->sense_dmat); in ahc_fini_scbdata()
4452 aic_dmamap_unload(ahc, scb_data->hscb_dmat, in ahc_fini_scbdata()
4453 scb_data->hscb_dmamap); in ahc_fini_scbdata()
4455 aic_dmamem_free(ahc, scb_data->hscb_dmat, scb_data->hscbs, in ahc_fini_scbdata()
4456 scb_data->hscb_dmamap); in ahc_fini_scbdata()
4458 aic_dma_tag_destroy(ahc, scb_data->hscb_dmat); in ahc_fini_scbdata()
4463 if (scb_data->scbarray != NULL) in ahc_fini_scbdata()
4464 free(scb_data->scbarray, M_DEVBUF); in ahc_fini_scbdata()
4478 scb_data = ahc->scb_data; in ahc_alloc_scbs()
4479 if (scb_data->numscbs >= AHC_SCB_MAX_ALLOC) in ahc_alloc_scbs()
4483 next_scb = &scb_data->scbarray[scb_data->numscbs]; in ahc_alloc_scbs()
4491 if (aic_dmamem_alloc(ahc, scb_data->sg_dmat, in ahc_alloc_scbs()
4492 (void **)&sg_map->sg_vaddr, in ahc_alloc_scbs()
4494 &sg_map->sg_dmamap) != 0) { in ahc_alloc_scbs()
4499 SLIST_INSERT_HEAD(&scb_data->sg_maps, sg_map, links); in ahc_alloc_scbs()
4501 aic_dmamap_load(ahc, scb_data->sg_dmat, sg_map->sg_dmamap, in ahc_alloc_scbs()
4502 sg_map->sg_vaddr, PAGE_SIZE, ahc_dmamap_cb, in ahc_alloc_scbs()
4503 &sg_map->sg_physaddr, /*flags*/0); in ahc_alloc_scbs()
4505 segs = sg_map->sg_vaddr; in ahc_alloc_scbs()
4506 physaddr = sg_map->sg_physaddr; in ahc_alloc_scbs()
4509 newcount = MIN(newcount, (AHC_SCB_MAX_ALLOC - scb_data->numscbs)); in ahc_alloc_scbs()
4517 next_scb->platform_data = pdata; in ahc_alloc_scbs()
4518 next_scb->sg_map = sg_map; in ahc_alloc_scbs()
4519 next_scb->sg_list = segs; in ahc_alloc_scbs()
4524 next_scb->sg_list_phys = physaddr + sizeof(struct ahc_dma_seg); in ahc_alloc_scbs()
4525 next_scb->ahc_softc = ahc; in ahc_alloc_scbs()
4526 next_scb->flags = SCB_FLAG_NONE; in ahc_alloc_scbs()
4527 error = aic_dmamap_create(ahc, ahc->buffer_dmat, /*flags*/0, in ahc_alloc_scbs()
4528 &next_scb->dmamap); in ahc_alloc_scbs()
4532 next_scb->hscb = &scb_data->hscbs[scb_data->numscbs]; in ahc_alloc_scbs()
4533 next_scb->hscb->tag = ahc->scb_data->numscbs; in ahc_alloc_scbs()
4534 aic_timer_init(&next_scb->io_timer); in ahc_alloc_scbs()
4535 SLIST_INSERT_HEAD(&ahc->scb_data->free_scbs, in ahc_alloc_scbs()
4540 ahc->scb_data->numscbs++; in ahc_alloc_scbs()
4550 len = sprintf(buf, "%s: ", ahc_chip_names[ahc->chip & AHC_CHIPID_MASK]); in ahc_controller_info()
4552 if ((ahc->features & AHC_TWIN) != 0) in ahc_controller_info()
4555 ahc->our_id, ahc->our_id_b, in ahc_controller_info()
4556 (ahc->flags & AHC_PRIMARY_CHANNEL) + 'A'); in ahc_controller_info()
4562 if ((ahc->features & AHC_ULTRA) != 0) { in ahc_controller_info()
4564 } else if ((ahc->features & AHC_DT) != 0) { in ahc_controller_info()
4566 } else if ((ahc->features & AHC_ULTRA2) != 0) { in ahc_controller_info()
4569 if ((ahc->features & AHC_WIDE) != 0) { in ahc_controller_info()
4575 speed, type, ahc->channel, ahc->our_id); in ahc_controller_info()
4579 if ((ahc->flags & AHC_PAGESCBS) != 0) in ahc_controller_info()
4581 ahc->scb_data->maxhscbs, AHC_MAX_QUEUE); in ahc_controller_info()
4583 sprintf(buf, "%d SCBs", ahc->scb_data->maxhscbs); in ahc_controller_info()
4600 if (ahc->features & AHC_TWIN) { in ahc_chip_init()
4602 * Setup Channel B first. in ahc_chip_init()
4605 term = (ahc->flags & AHC_TERM_ENB_B) != 0 ? STPWEN : 0; in ahc_chip_init()
4606 ahc_outb(ahc, SCSIID, ahc->our_id_b); in ahc_chip_init()
4609 |term|ahc->seltime_b|ENSTIMER|ACTNEGEN); in ahc_chip_init()
4610 if ((ahc->features & AHC_ULTRA2) != 0) in ahc_chip_init()
4618 term = (ahc->flags & AHC_TERM_ENB_A) != 0 ? STPWEN : 0; in ahc_chip_init()
4619 if ((ahc->features & AHC_ULTRA2) != 0) in ahc_chip_init()
4620 ahc_outb(ahc, SCSIID_ULTRA2, ahc->our_id); in ahc_chip_init()
4622 ahc_outb(ahc, SCSIID, ahc->our_id); in ahc_chip_init()
4625 |term|ahc->seltime in ahc_chip_init()
4627 if ((ahc->features & AHC_ULTRA2) != 0) in ahc_chip_init()
4635 if ((ahc->flags & AHC_SCB_BTT) != 0) { in ahc_chip_init()
4649 ahc->qoutfifo[i] = SCB_LIST_NULL; in ahc_chip_init()
4653 ahc->qinfifo[i] = SCB_LIST_NULL; in ahc_chip_init()
4655 if ((ahc->features & AHC_MULTI_TID) != 0) { in ahc_chip_init()
4663 physaddr = ahc->scb_data->hscb_busaddr; in ahc_chip_init()
4669 physaddr = ahc->shared_data_busaddr; in ahc_chip_init()
4678 * setup the table after we have processed that information. in ahc_chip_init()
4689 if ((ahc->features & AHC_HS_MAILBOX) != 0) in ahc_chip_init()
4693 if ((ahc->features & AHC_TARGETMODE) != 0) { in ahc_chip_init()
4694 ahc->tqinfifonext = 1; in ahc_chip_init()
4695 ahc_outb(ahc, KERNEL_TQINPOS, ahc->tqinfifonext - 1); in ahc_chip_init()
4696 ahc_outb(ahc, TQINPOS, ahc->tqinfifonext); in ahc_chip_init()
4698 ahc->qinfifonext = 0; in ahc_chip_init()
4699 ahc->qoutfifonext = 0; in ahc_chip_init()
4700 if ((ahc->features & AHC_QUEUE_REGS) != 0) { in ahc_chip_init()
4702 ahc_outb(ahc, HNSCB_QOFF, ahc->qinfifonext); in ahc_chip_init()
4703 ahc_outb(ahc, SNSCB_QOFF, ahc->qinfifonext); in ahc_chip_init()
4706 ahc_outb(ahc, KERNEL_QINPOS, ahc->qinfifonext); in ahc_chip_init()
4707 ahc_outb(ahc, QINPOS, ahc->qinfifonext); in ahc_chip_init()
4708 ahc_outb(ahc, QOUTPOS, ahc->qoutfifonext); in ahc_chip_init()
4721 * Setup the allowed SCSI Sequences based on operational mode. in ahc_chip_init()
4726 if ((ahc->flags & AHC_INITIATORROLE) != 0) in ahc_chip_init()
4736 ahc_outb(ahc, NEXT_QUEUED_SCB, ahc->next_queued_scb->hscb->tag); in ahc_chip_init()
4750 if ((ahc->features & AHC_ULTRA2) != 0) { in ahc_chip_init()
4762 wait--) in ahc_chip_init()
4789 ahc->flags |= AHC_SEQUENCER_DEBUG; in ahc_init()
4800 if ((ahc->features & AHC_MORE_SRAM) != 0) { in ahc_init()
4821 if ((ahc->flags & AHC_USEDEFAULTS) != 0) in ahc_init()
4822 ahc->our_id = ahc->our_id_b = 7; in ahc_init()
4827 ahc->flags |= AHC_INITIATORROLE; in ahc_init()
4833 tmode_enable = ((AHC_TMODE_ENABLE & (0x1 << ahc->unit)) != 0); in ahc_init()
4834 resource_int_value(device_get_name(ahc->dev_softc), in ahc_init()
4835 device_get_unit(ahc->dev_softc), in ahc_init()
4839 ahc->features &= ~AHC_TARGETMODE; in ahc_init()
4841 if (bootverbose && ((ahc->features & AHC_TARGETMODE) != 0)) in ahc_init()
4846 ahc->features &= ~AHC_TARGETMODE; in ahc_init()
4850 if (aic_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1, in ahc_init()
4852 /*lowaddr*/ahc->flags & AHC_39BIT_ADDRESSING in ahc_init()
4857 /*maxsize*/(AHC_NSEG - 1) * PAGE_SIZE, in ahc_init()
4861 &ahc->buffer_dmat) != 0) { in ahc_init()
4865 ahc->init_level++; in ahc_init()
4877 if ((ahc->features & AHC_TARGETMODE) != 0) in ahc_init()
4880 if (aic_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1, in ahc_init()
4888 /*flags*/0, &ahc->shared_data_dmat) != 0) { in ahc_init()
4892 ahc->init_level++; in ahc_init()
4895 if (aic_dmamem_alloc(ahc, ahc->shared_data_dmat, in ahc_init()
4896 (void **)&ahc->qoutfifo, in ahc_init()
4898 &ahc->shared_data_dmamap) != 0) { in ahc_init()
4902 ahc->init_level++; in ahc_init()
4905 aic_dmamap_load(ahc, ahc->shared_data_dmat, ahc->shared_data_dmamap, in ahc_init()
4906 ahc->qoutfifo, driver_data_size, ahc_dmamap_cb, in ahc_init()
4907 &ahc->shared_data_busaddr, /*flags*/0); in ahc_init()
4909 if ((ahc->features & AHC_TARGETMODE) != 0) { in ahc_init()
4910 ahc->targetcmds = (struct target_cmd *)ahc->qoutfifo; in ahc_init()
4911 ahc->qoutfifo = (uint8_t *)&ahc->targetcmds[AHC_TMODE_CMDS]; in ahc_init()
4912 ahc->dma_bug_buf = ahc->shared_data_busaddr in ahc_init()
4913 + driver_data_size - 1; in ahc_init()
4916 ahc->targetcmds[i].cmd_valid = 0; in ahc_init()
4919 ahc->qinfifo = &ahc->qoutfifo[256]; in ahc_init()
4921 ahc->init_level++; in ahc_init()
4924 if (ahc->scb_data->maxhscbs == 0) in ahc_init()
4933 if (ahc_alloc_tstate(ahc, ahc->our_id, 'A') == NULL) { in ahc_init()
4939 if ((ahc->features & AHC_TWIN) != 0) { in ahc_init()
4940 if (ahc_alloc_tstate(ahc, ahc->our_id_b, 'B') == NULL) { in ahc_init()
4954 if (ahc->scb_data->maxhscbs < AHC_SCB_MAX_ALLOC) { in ahc_init()
4955 ahc->flags |= AHC_PAGESCBS; in ahc_init()
4957 ahc->flags &= ~AHC_PAGESCBS; in ahc_init()
4975 if (ahc->features & AHC_TWIN) { in ahc_init()
4978 && (ahc->flags & AHC_INITIATORROLE) != 0) in ahc_init()
4979 ahc->flags |= AHC_RESET_BUS_B; in ahc_init()
4984 && (ahc->flags & AHC_INITIATORROLE) != 0) in ahc_init()
4985 ahc->flags |= AHC_RESET_BUS_A; in ahc_init()
4991 if ((ahc->flags & AHC_USEDEFAULTS) != 0) { in ahc_init()
4994 ahc->flags |= AHC_EXTENDED_TRANS_A|AHC_EXTENDED_TRANS_B| in ahc_init()
4997 if ((ahc->features & AHC_ULTRA) != 0) in ahc_init()
5002 if ((ahc->features & (AHC_ULTRA|AHC_ULTRA2)) != 0) in ahc_init()
5007 if ((ahc->features & (AHC_WIDE|AHC_TWIN)) == 0) in ahc_init()
5018 our_id = ahc->our_id; in ahc_init()
5020 if (i > 7 && (ahc->features & AHC_TWIN) != 0) { in ahc_init()
5022 our_id = ahc->our_id_b; in ahc_init()
5029 if (ahc->flags & AHC_USEDEFAULTS) { in ahc_init()
5030 if ((ahc->features & AHC_WIDE) != 0) in ahc_init()
5031 tinfo->user.width = MSG_EXT_WDTR_BUS_16_BIT; in ahc_init()
5037 tinfo->user.period = ahc_syncrates->period; in ahc_init()
5038 tinfo->user.offset = MAX_OFFSET; in ahc_init()
5046 if ((ahc->features & AHC_ULTRA2) != 0) { in ahc_init()
5066 if ((ahc->features & AHC_DT) != 0) in ahc_init()
5068 tinfo->user.period = in ahc_init()
5071 tinfo->user.period = 0; in ahc_init()
5073 tinfo->user.offset = MAX_OFFSET; in ahc_init()
5075 && (ahc->features & AHC_DT) != 0) in ahc_init()
5076 tinfo->user.ppr_options = in ahc_init()
5081 /* Treat 10MHz as a non-ultra speed */ in ahc_init()
5085 tinfo->user.period = in ahc_init()
5090 if (tinfo->user.period != 0) in ahc_init()
5091 tinfo->user.offset = MAX_OFFSET; in ahc_init()
5093 if (tinfo->user.period == 0) in ahc_init()
5094 tinfo->user.offset = 0; in ahc_init()
5096 && (ahc->features & AHC_WIDE) != 0) in ahc_init()
5097 tinfo->user.width = MSG_EXT_WDTR_BUS_16_BIT; in ahc_init()
5098 tinfo->user.protocol_version = 4; in ahc_init()
5099 if ((ahc->features & AHC_DT) != 0) in ahc_init()
5100 tinfo->user.transport_version = 3; in ahc_init()
5102 tinfo->user.transport_version = 2; in ahc_init()
5103 tinfo->goal.protocol_version = 2; in ahc_init()
5104 tinfo->goal.transport_version = 2; in ahc_init()
5105 tinfo->curr.protocol_version = 2; in ahc_init()
5106 tinfo->curr.transport_version = 2; in ahc_init()
5108 tstate->ultraenb = 0; in ahc_init()
5110 ahc->user_discenable = discenable; in ahc_init()
5111 ahc->user_tagenable = tagenable; in ahc_init()
5113 return (ahc->bus_chip_init(ahc)); in ahc_init()
5123 ahc->pause &= ~INTEN; in ahc_intr_enable()
5124 ahc->unpause &= ~INTEN; in ahc_intr_enable()
5127 ahc->pause |= INTEN; in ahc_intr_enable()
5128 ahc->unpause |= INTEN; in ahc_intr_enable()
5148 ahc->flags |= AHC_ALL_INTERRUPTS; in ahc_pause_and_flushwork()
5168 } while (--maxloops in ahc_pause_and_flushwork()
5169 && (intstat != 0xFF || (ahc->features & AHC_REMOVABLE) == 0) in ahc_pause_and_flushwork()
5177 ahc->flags &= ~AHC_ALL_INTERRUPTS; in ahc_pause_and_flushwork()
5186 if (LIST_FIRST(&ahc->pending_scbs) != NULL) { in ahc_suspend()
5197 if (ahc->pending_device != NULL) { in ahc_suspend()
5227 if ((ahc->flags & AHC_SCB_BTT) != 0) { in ahc_index_busy_tcl()
5247 if ((ahc->flags & AHC_SCB_BTT) != 0) { in ahc_unbusy_tcl()
5265 if ((ahc->flags & AHC_SCB_BTT) != 0) { in ahc_busy_tcl()
5297 group = XPT_FC_GROUP(scb->io_ctx->ccb_h.func_code); in ahc_match_scb()
5300 && ((tag == scb->hscb->tag) in ahc_match_scb()
5304 && ((tag == scb->io_ctx->csio.tag_id) in ahc_match_scb()
5308 match = ((tag == scb->hscb->tag) || (tag == SCB_LIST_NULL)); in ahc_match_scb()
5343 prev_pos = ahc->qinfifonext - 1; in ahc_qinfifo_requeue_tail()
5344 prev_tag = ahc->qinfifo[prev_pos]; in ahc_qinfifo_requeue_tail()
5348 if ((ahc->features & AHC_QUEUE_REGS) != 0) { in ahc_qinfifo_requeue_tail()
5349 ahc_outb(ahc, HNSCB_QOFF, ahc->qinfifonext); in ahc_qinfifo_requeue_tail()
5351 ahc_outb(ahc, KERNEL_QINPOS, ahc->qinfifonext); in ahc_qinfifo_requeue_tail()
5360 ahc_outb(ahc, NEXT_QUEUED_SCB, scb->hscb->tag); in ahc_qinfifo_requeue()
5362 prev_scb->hscb->next = scb->hscb->tag; in ahc_qinfifo_requeue()
5366 ahc->qinfifo[ahc->qinfifonext++] = scb->hscb->tag; in ahc_qinfifo_requeue()
5367 scb->hscb->next = ahc->next_queued_scb->hscb->tag; in ahc_qinfifo_requeue()
5377 if ((ahc->features & AHC_QUEUE_REGS) != 0) { in ahc_qinfifo_count()
5382 diff = ahc->qinfifonext - qinpos; in ahc_qinfifo_count()
5402 qintail = ahc->qinfifonext; in ahc_search_qinfifo()
5403 have_qregs = (ahc->features & AHC_QUEUE_REGS) != 0; in ahc_search_qinfifo()
5423 * for removal will be re-added to the queue as we go. in ahc_search_qinfifo()
5425 ahc->qinfifonext = qinpos; in ahc_search_qinfifo()
5426 ahc_outb(ahc, NEXT_QUEUED_SCB, ahc->next_queued_scb->hscb->tag); in ahc_search_qinfifo()
5429 scb = ahc_lookup_scb(ahc, ahc->qinfifo[qinpos]); in ahc_search_qinfifo()
5432 qinpos, ahc->qinfifo[qinpos]); in ahc_search_qinfifo()
5453 if ((scb->flags & SCB_ACTIVE) == 0) in ahc_search_qinfifo()
5473 if ((ahc->features & AHC_QUEUE_REGS) != 0) { in ahc_search_qinfifo()
5474 ahc_outb(ahc, HNSCB_QOFF, ahc->qinfifonext); in ahc_search_qinfifo()
5476 ahc_outb(ahc, KERNEL_QINPOS, ahc->qinfifonext); in ahc_search_qinfifo()
5481 && (qinstart != ahc->qinfifonext)) { in ahc_search_qinfifo()
5494 scb = ahc_lookup_scb(ahc, ahc->qinfifo[qinstart]); in ahc_search_qinfifo()
5498 found, qinstart, ahc->qinfifonext); in ahc_search_qinfifo()
5507 next = scb->hscb->next; in ahc_search_qinfifo()
5508 ahc->scb_data->scbindex[scb->hscb->tag] = NULL; in ahc_search_qinfifo()
5510 scb->hscb->next = next; in ahc_search_qinfifo()
5511 ahc->qinfifo[qinstart] = scb->hscb->tag; in ahc_search_qinfifo()
5514 ahc_outb(ahc, NEXT_QUEUED_SCB, scb->hscb->tag); in ahc_search_qinfifo()
5517 qintail = ahc->qinfifonext - 1; in ahc_search_qinfifo()
5518 scb = ahc_lookup_scb(ahc, ahc->qinfifo[qintail]); in ahc_search_qinfifo()
5519 scb->hscb->next = ahc->next_queued_scb->hscb->tag; in ahc_search_qinfifo()
5534 if (scb_index >= ahc->scb_data->numscbs) { in ahc_search_qinfifo()
5537 scb_index, ahc->scb_data->numscbs); in ahc_search_qinfifo()
5566 if ((scb->flags & SCB_ACTIVE) == 0) in ahc_search_qinfifo()
5615 if ((ahc->flags & AHC_SCB_BTT) == 0) { in ahc_search_untagged_queues()
5631 untagged_q = &(ahc->untagged_queues[i]); in ahc_search_untagged_queues()
5646 if ((scb->flags & SCB_ACTIVE) != 0) in ahc_search_untagged_queues()
5651 || (ctx != NULL && ctx != scb->io_ctx)) in ahc_search_untagged_queues()
5674 scb->flags &= ~SCB_UNTAGGEDQ; in ahc_search_untagged_queues()
5715 if (scb_index >= ahc->scb_data->numscbs) { in ahc_search_disc_list()
5718 scb_index, ahc->scb_data->numscbs); in ahc_search_disc_list()
5790 if ((ahc->flags & AHC_PAGESCBS) != 0) { in ahc_add_curscb_to_free_list()
5898 if ((ahc->flags & AHC_SCB_BTT) != 0) in ahc_abort_scbs()
5940 for (i = 0; i < ahc->scb_data->maxhscbs; i++) { in ahc_abort_scbs()
5958 scbp_next = LIST_FIRST(&ahc->pending_scbs); in ahc_abort_scbs()
5970 if ((scbp->flags & SCB_ACTIVE) == 0) in ahc_abort_scbs()
5997 /* Re-enable reset interrupts */ in ahc_reset_current_bus()
6013 ahc->pending_device = NULL; in ahc_reset_channel()
6033 * XXX - In Twin mode, the tqinfifo may have commands in ahc_reset_channel()
6042 if ((ahc->flags & AHC_TARGETROLE) != 0) { in ahc_reset_channel()
6052 if ((ahc->features & AHC_TWIN) != 0 in ahc_reset_channel()
6066 * defer re-enabling bus reset interrupts in ahc_reset_channel()
6069 if ((ahc->flags & AHC_TARGETROLE) != 0) in ahc_reset_channel()
6085 * defer re-enabling bus reset interrupts in ahc_reset_channel()
6088 if ((ahc->flags & AHC_TARGETROLE) != 0) in ahc_reset_channel()
6107 max_scsiid = (ahc->features & AHC_WIDE) ? 15 : 7; in ahc_reset_channel()
6118 tstate = ahc->enabled_targets[target]; in ahc_reset_channel()
6124 lstate = tstate->enabled_luns[lun]; in ahc_reset_channel()
6142 if (ahc->enabled_targets[target] == NULL) in ahc_reset_channel()
6195 hscb = scb->hscb; in ahc_calc_residual()
6196 sgptr = aic_le32toh(hscb->sgptr); in ahc_calc_residual()
6206 spkt = &hscb->shared_data.status; in ahc_calc_residual()
6207 resid_sgptr = aic_le32toh(spkt->residual_sg_ptr); in ahc_calc_residual()
6225 resid = aic_le32toh(spkt->residual_datacnt) & AHC_SG_LEN_MASK; in ahc_calc_residual()
6229 sg--; in ahc_calc_residual()
6236 while ((aic_le32toh(sg->len) & AHC_DMA_LAST_SEG) == 0) { in ahc_calc_residual()
6238 resid += aic_le32toh(sg->len) & AHC_SG_LEN_MASK; in ahc_calc_residual()
6241 if ((scb->flags & SCB_SENSE) == 0) in ahc_calc_residual()
6250 (scb->flags & SCB_SENSE) ? "Sense " : "", resid); in ahc_calc_residual()
6267 xpt_freeze_devq(lstate->path, /*count*/1); in ahc_queue_lstate_event()
6268 if (lstate->event_w_idx >= lstate->event_r_idx) in ahc_queue_lstate_event()
6269 pending = lstate->event_w_idx - lstate->event_r_idx; in ahc_queue_lstate_event()
6272 - (lstate->event_r_idx - lstate->event_w_idx); in ahc_queue_lstate_event()
6282 lstate->event_r_idx = 0; in ahc_queue_lstate_event()
6283 lstate->event_w_idx = 0; in ahc_queue_lstate_event()
6284 xpt_release_devq(lstate->path, pending, /*runqueue*/FALSE); in ahc_queue_lstate_event()
6288 xpt_print_path(lstate->path); in ahc_queue_lstate_event()
6290 lstate->event_buffer[lstate->event_r_idx].event_type, in ahc_queue_lstate_event()
6291 lstate->event_buffer[lstate->event_r_idx].event_arg); in ahc_queue_lstate_event()
6292 lstate->event_r_idx++; in ahc_queue_lstate_event()
6293 if (lstate->event_r_idx == AHC_TMODE_EVENT_BUFFER_SIZE) in ahc_queue_lstate_event()
6294 lstate->event_r_idx = 0; in ahc_queue_lstate_event()
6295 xpt_release_devq(lstate->path, /*count*/1, /*runqueue*/FALSE); in ahc_queue_lstate_event()
6298 event = &lstate->event_buffer[lstate->event_w_idx]; in ahc_queue_lstate_event()
6299 event->initiator_id = initiator_id; in ahc_queue_lstate_event()
6300 event->event_type = event_type; in ahc_queue_lstate_event()
6301 event->event_arg = event_arg; in ahc_queue_lstate_event()
6302 lstate->event_w_idx++; in ahc_queue_lstate_event()
6303 if (lstate->event_w_idx == AHC_TMODE_EVENT_BUFFER_SIZE) in ahc_queue_lstate_event()
6304 lstate->event_w_idx = 0; in ahc_queue_lstate_event()
6317 while (lstate->event_r_idx != lstate->event_w_idx in ahc_send_lstate_events()
6318 && (ccbh = SLIST_FIRST(&lstate->immed_notifies)) != NULL) { in ahc_send_lstate_events()
6321 event = &lstate->event_buffer[lstate->event_r_idx]; in ahc_send_lstate_events()
6322 SLIST_REMOVE_HEAD(&lstate->immed_notifies, sim_links.sle); in ahc_send_lstate_events()
6324 switch (event->event_type) { in ahc_send_lstate_events()
6326 ccbh->status = CAM_SCSI_BUS_RESET|CAM_DEV_QFRZN; in ahc_send_lstate_events()
6329 ccbh->status = CAM_MESSAGE_RECV|CAM_DEV_QFRZN; in ahc_send_lstate_events()
6330 inot->arg = event->event_type; in ahc_send_lstate_events()
6331 inot->seq_id = event->event_arg; in ahc_send_lstate_events()
6334 inot->initiator_id = event->initiator_id; in ahc_send_lstate_events()
6336 lstate->event_r_idx++; in ahc_send_lstate_events()
6337 if (lstate->event_r_idx == AHC_TMODE_EVENT_BUFFER_SIZE) in ahc_send_lstate_events()
6338 lstate->event_r_idx = 0; in ahc_send_lstate_events()
6354 for (i = 0; i < ahc->instruction_ram_size; i++) { in ahc_dumpseq()
6369 struct cs cs_table[num_critical_sections]; in ahc_loadseq()
6390 /* Setup downloadable constant table */ in ahc_loadseq()
6392 if (ahc->targetcmds != NULL) in ahc_loadseq()
6395 download_consts[CACHESIZE_MASK] = ahc->pci_cachesize - 1; in ahc_loadseq()
6396 download_consts[INVERTED_CACHESIZE_MASK] = ~(ahc->pci_cachesize - 1); in ahc_loadseq()
6397 sg_prefetch_cnt = ahc->pci_cachesize; in ahc_loadseq()
6401 download_consts[SG_PREFETCH_ALIGN_MASK] = ~(sg_prefetch_cnt - 1); in ahc_loadseq()
6402 download_consts[SG_PREFETCH_ADDR_MASK] = (sg_prefetch_cnt - 1); in ahc_loadseq()
6420 if (downloaded == ahc->instruction_ram_size) { in ahc_loadseq()
6428 ahc->instruction_ram_size); in ahc_loadseq()
6433 * Move through the CS table until we find a CS in ahc_loadseq()
6457 ahc->num_critical_sections = cs_count; in ahc_loadseq()
6459 cs_count *= sizeof(struct cs); in ahc_loadseq()
6460 ahc->critical_sections = malloc(cs_count, M_DEVBUF, M_NOWAIT); in ahc_loadseq()
6461 if (ahc->critical_sections == NULL) in ahc_loadseq()
6463 memcpy(ahc->critical_sections, cs_table, cs_count); in ahc_loadseq()
6470 ahc_name(ahc), ahc->features, ahc->bugs, ahc->flags); in ahc_loadseq()
6487 while (cur_patch < last_patch && start_instr == cur_patch->begin) { in ahc_check_patch()
6488 if (cur_patch->patch_func(ahc) == 0) { in ahc_check_patch()
6490 *skip_addr = start_instr + cur_patch->skip_instr; in ahc_check_patch()
6491 cur_patch += cur_patch->skip_patch; in ahc_check_patch()
6545 address = fmt3_ins->address; in ahc_download_instr()
6556 address_offset += end_addr - i; in ahc_download_instr()
6562 address -= address_offset; in ahc_download_instr()
6563 fmt3_ins->address = address; in ahc_download_instr()
6572 if (fmt1_ins->parity != 0) { in ahc_download_instr()
6573 fmt1_ins->immediate = dconsts[fmt1_ins->immediate]; in ahc_download_instr()
6575 fmt1_ins->parity = 0; in ahc_download_instr()
6576 if ((ahc->features & AHC_CMD_CHAN) == 0 in ahc_download_instr()
6585 if (fmt1_ins->immediate != 1) in ahc_download_instr()
6588 fmt1_ins->opcode = AIC_OP_AND; in ahc_download_instr()
6589 fmt1_ins->immediate = 0xff; in ahc_download_instr()
6593 if ((ahc->features & AHC_ULTRA2) != 0) { in ahc_download_instr()
6610 fmt3_ins->immediate in ahc_download_instr()
6611 | (fmt3_ins->source << 8) in ahc_download_instr()
6612 | (fmt3_ins->address << 16) in ahc_download_instr()
6613 | (fmt3_ins->opcode << 25); in ahc_download_instr()
6616 fmt1_ins->immediate in ahc_download_instr()
6617 | (fmt1_ins->source << 8) in ahc_download_instr()
6618 | (fmt1_ins->destination << 16) in ahc_download_instr()
6619 | (fmt1_ins->ret << 24) in ahc_download_instr()
6620 | (fmt1_ins->opcode << 25); in ahc_download_instr()
6715 ahc_name(ahc), ahc_lookup_phase_entry(last_phase)->phasemsg, in ahc_dump_card_state()
6725 if ((ahc->features & AHC_DT) != 0) in ahc_dump_card_state()
6750 printf("\nSCB count = %d\n", ahc->scb_data->numscbs); in ahc_dump_card_state()
6751 printf("Kernel NEXTQSCB = %d\n", ahc->next_queued_scb->hscb->tag); in ahc_dump_card_state()
6755 if ((ahc->features & AHC_QUEUE_REGS) != 0) { in ahc_dump_card_state()
6760 qintail = ahc->qinfifonext; in ahc_dump_card_state()
6762 printf("%d ", ahc->qinfifo[qinpos]); in ahc_dump_card_state()
6789 qoutpos = ahc->qoutfifonext; in ahc_dump_card_state()
6791 while (ahc->qoutfifo[qoutpos] != SCB_LIST_NULL && i++ < 256) { in ahc_dump_card_state()
6792 printf("%d ", ahc->qoutfifo[qoutpos]); in ahc_dump_card_state()
6808 for (i = 0; i < ahc->scb_data->maxhscbs; i++) { in ahc_dump_card_state()
6821 LIST_FOREACH(scb, &ahc->pending_scbs, pending_links) { in ahc_dump_card_state()
6824 cur_col = printf("\n%3d ", scb->hscb->tag); in ahc_dump_card_state()
6825 ahc_scb_control_print(scb->hscb->control, &cur_col, 60); in ahc_dump_card_state()
6826 ahc_scb_scsiid_print(scb->hscb->scsiid, &cur_col, 60); in ahc_dump_card_state()
6827 ahc_scb_lun_print(scb->hscb->lun, &cur_col, 60); in ahc_dump_card_state()
6828 if ((ahc->flags & AHC_PAGESCBS) == 0) { in ahc_dump_card_state()
6829 ahc_outb(ahc, SCBPTR, scb->hscb->tag); in ahc_dump_card_state()
6841 SLIST_FOREACH(scb, &ahc->scb_data->free_scbs, links.sle) { in ahc_dump_card_state()
6844 printf("%d ", scb->hscb->tag); in ahc_dump_card_state()
6848 maxtarget = (ahc->features & (AHC_WIDE|AHC_TWIN)) ? 15 : 7; in ahc_dump_card_state()
6850 untagged_q = &ahc->untagged_queues[target]; in ahc_dump_card_state()
6858 printf("%d ", scb->hscb->tag); in ahc_dump_card_state()
6876 ahc = scb->ahc_softc; in ahc_timeout()
6877 if ((scb->flags & SCB_ACTIVE) != 0) { in ahc_timeout()
6878 if ((scb->flags & SCB_TIMEDOUT) == 0) { in ahc_timeout()
6879 LIST_INSERT_HEAD(&ahc->timedout_scbs, scb, in ahc_timeout()
6881 scb->flags |= SCB_TIMEDOUT; in ahc_timeout()
6888 * Re-schedule a timeout for the passed in SCB if we determine that some
6891 * if it is non-NULL.
6902 (scb->flags & SCB_OTHERTCL_TIMEOUT) != 0 in ahc_other_scb_timeout()
6906 scb->flags |= SCB_OTHERTCL_TIMEOUT; in ahc_other_scb_timeout()
6909 if ((other_scb->flags in ahc_other_scb_timeout()
6911 || (other_scb->flags & SCB_RECOVERY_SCB) != 0) { in ahc_other_scb_timeout()
6917 LIST_FOREACH(other_scb, &ahc->pending_scbs, pending_links) { in ahc_other_scb_timeout()
6918 if ((other_scb->flags in ahc_other_scb_timeout()
6920 || (other_scb->flags & SCB_RECOVERY_SCB) != 0) { in ahc_other_scb_timeout()
6961 if (LIST_EMPTY(&ahc->timedout_scbs) != 0) { in ahc_recover_commands()
6967 * requires or - more likely - interrupts in ahc_recover_commands()
6981 while ((scb = LIST_FIRST(&ahc->timedout_scbs)) != NULL) { in ahc_recover_commands()
6994 printf("SCB 0x%x - timed out\n", scb->hscb->tag); in ahc_recover_commands()
6995 if (scb->sg_count > 0) { in ahc_recover_commands()
6996 for (i = 0; i < scb->sg_count; i++) { in ahc_recover_commands()
6997 printf("sg[%d] - Addr 0x%x : Length %d\n", in ahc_recover_commands()
6999 scb->sg_list[i].addr, in ahc_recover_commands()
7000 scb->sg_list[i].len & AHC_SG_LEN_MASK); in ahc_recover_commands()
7003 if (scb->flags & (SCB_DEVICE_RESET|SCB_ABORT)) { in ahc_recover_commands()
7023 scb->flags &= ~SCB_TIMEDOUT; in ahc_recover_commands()
7051 && (active_scb_index < ahc->scb_data->numscbs)) { in ahc_recover_commands()
7069 if ((scb->flags & SCB_TARGET_SCB) != 0) { in ahc_recover_commands()
7077 scb->hscb->tag, in ahc_recover_commands()
7091 active_scb->flags |= SCB_DEVICE_RESET; in ahc_recover_commands()
7118 if ((scb->flags & SCB_TARGET_SCB) != 0) in ahc_recover_commands()
7119 panic("Timed-out target SCB but bus idle"); in ahc_recover_commands()
7122 scb->hscb->tag, ROLE_INITIATOR, in ahc_recover_commands()
7132 * Actually re-queue this SCB in an attempt in ahc_recover_commands()
7136 * timed-out device. in ahc_recover_commands()
7147 scb->hscb->control |= MK_MESSAGE|DISCONNECTED; in ahc_recover_commands()
7148 scb->flags |= SCB_DEVICE_RESET; in ahc_recover_commands()
7158 lun, scb->hscb->tag, in ahc_recover_commands()
7164 * In the non-paging case, the sequencer will in ahc_recover_commands()
7165 * never re-reference the in-core SCB. in ahc_recover_commands()
7170 if ((ahc->flags & AHC_PAGESCBS) == 0) { in ahc_recover_commands()
7171 ahc_outb(ahc, SCBPTR, scb->hscb->tag); in ahc_recover_commands()
7200 "Flags = 0x%x\n", scb->hscb->tag, in ahc_recover_commands()
7201 scb->flags); in ahc_recover_commands()
7213 while ((scb = LIST_FIRST(&ahc->timedout_scbs)) != NULL) { in ahc_recover_commands()
7215 scb->flags &= ~SCB_TIMEDOUT; in ahc_recover_commands()
7233 if ((ahc->features & AHC_TARGETMODE) == 0) in ahc_find_tmode_devs()
7240 if (ccb->ccb_h.target_id == CAM_TARGET_WILDCARD in ahc_find_tmode_devs()
7241 && ccb->ccb_h.target_lun == CAM_LUN_WILDCARD) { in ahc_find_tmode_devs()
7243 *lstate = ahc->black_hole; in ahc_find_tmode_devs()
7247 max_id = (ahc->features & AHC_WIDE) ? 15 : 7; in ahc_find_tmode_devs()
7248 if (ccb->ccb_h.target_id > max_id) in ahc_find_tmode_devs()
7251 if (ccb->ccb_h.target_lun >= AHC_NUM_LUNS) in ahc_find_tmode_devs()
7254 *tstate = ahc->enabled_targets[ccb->ccb_h.target_id]; in ahc_find_tmode_devs()
7258 (*tstate)->enabled_luns[ccb->ccb_h.target_lun]; in ahc_find_tmode_devs()
7286 ccb->ccb_h.status = status; in ahc_handle_en_lun()
7291 our_id = ahc->our_id; in ahc_handle_en_lun()
7293 our_id = ahc->our_id_b; in ahc_handle_en_lun()
7295 if (ccb->ccb_h.target_id != our_id in ahc_handle_en_lun()
7296 && ccb->ccb_h.target_id != CAM_TARGET_WILDCARD) { in ahc_handle_en_lun()
7309 * ID to use for both select-out and in ahc_handle_en_lun()
7310 * reselect-out operations, the only target in ahc_handle_en_lun()
7316 if ((ahc->features & AHC_MULTIROLE) != 0) { in ahc_handle_en_lun()
7317 if ((ahc->features & AHC_MULTI_TID) != 0 in ahc_handle_en_lun()
7318 && (ahc->flags & AHC_INITIATORROLE) != 0) { in ahc_handle_en_lun()
7322 * The hardware cannot handle a re-select-in in ahc_handle_en_lun()
7323 * on the initiator id during a re-select-out in ahc_handle_en_lun()
7327 } else if ((ahc->flags & AHC_INITIATORROLE) != 0 in ahc_handle_en_lun()
7328 || ahc->enabled_luns > 0) { in ahc_handle_en_lun()
7338 } else if ((ahc->features & AHC_MULTI_TID) == 0 in ahc_handle_en_lun()
7339 && ahc->enabled_luns > 0) { in ahc_handle_en_lun()
7345 ccb->ccb_h.status = status; in ahc_handle_en_lun()
7353 if ((ahc->flags & AHC_TARGETROLE) == 0 in ahc_handle_en_lun()
7354 && ccb->ccb_h.target_id != CAM_TARGET_WILDCARD) { in ahc_handle_en_lun()
7358 if (LIST_FIRST(&ahc->pending_scbs) != NULL) { in ahc_handle_en_lun()
7359 ccb->ccb_h.status = CAM_BUSY; in ahc_handle_en_lun()
7362 saved_flags = ahc->flags; in ahc_handle_en_lun()
7363 ahc->flags |= AHC_TARGETROLE; in ahc_handle_en_lun()
7364 if ((ahc->features & AHC_MULTIROLE) == 0) in ahc_handle_en_lun()
7365 ahc->flags &= ~AHC_INITIATORROLE; in ahc_handle_en_lun()
7377 ahc->flags = saved_flags; in ahc_handle_en_lun()
7380 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL; in ahc_handle_en_lun()
7385 cel = &ccb->cel; in ahc_handle_en_lun()
7386 target = ccb->ccb_h.target_id; in ahc_handle_en_lun()
7387 lun = ccb->ccb_h.target_lun; in ahc_handle_en_lun()
7393 if (cel->enable != 0) { in ahc_handle_en_lun()
7398 xpt_print_path(ccb->ccb_h.path); in ahc_handle_en_lun()
7400 ccb->ccb_h.status = CAM_LUN_ALRDY_ENA; in ahc_handle_en_lun()
7404 if (cel->grp6_len != 0 in ahc_handle_en_lun()
7405 || cel->grp7_len != 0) { in ahc_handle_en_lun()
7410 ccb->ccb_h.status = CAM_REQ_INVALID; in ahc_handle_en_lun()
7411 printf("Non-zero Group Codes\n"); in ahc_handle_en_lun()
7417 * Setup our data structures. in ahc_handle_en_lun()
7422 xpt_print_path(ccb->ccb_h.path); in ahc_handle_en_lun()
7424 ccb->ccb_h.status = CAM_RESRC_UNAVAIL; in ahc_handle_en_lun()
7430 xpt_print_path(ccb->ccb_h.path); in ahc_handle_en_lun()
7432 ccb->ccb_h.status = CAM_RESRC_UNAVAIL; in ahc_handle_en_lun()
7436 status = xpt_create_path(&lstate->path, /*periph*/NULL, in ahc_handle_en_lun()
7437 xpt_path_path_id(ccb->ccb_h.path), in ahc_handle_en_lun()
7438 xpt_path_target_id(ccb->ccb_h.path), in ahc_handle_en_lun()
7439 xpt_path_lun_id(ccb->ccb_h.path)); in ahc_handle_en_lun()
7442 xpt_print_path(ccb->ccb_h.path); in ahc_handle_en_lun()
7444 ccb->ccb_h.status = CAM_RESRC_UNAVAIL; in ahc_handle_en_lun()
7447 SLIST_INIT(&lstate->accept_tios); in ahc_handle_en_lun()
7448 SLIST_INIT(&lstate->immed_notifies); in ahc_handle_en_lun()
7451 tstate->enabled_luns[lun] = lstate; in ahc_handle_en_lun()
7452 ahc->enabled_luns++; in ahc_handle_en_lun()
7454 if ((ahc->features & AHC_MULTI_TID) != 0) { in ahc_handle_en_lun()
7484 if ((ahc->features & AHC_TWIN) == 0) in ahc_handle_en_lun()
7488 ahc->our_id = target; in ahc_handle_en_lun()
7490 ahc->our_id_b = target; in ahc_handle_en_lun()
7503 ahc->black_hole = lstate; in ahc_handle_en_lun()
7504 /* Allow select-in operations */ in ahc_handle_en_lun()
7505 if (ahc->black_hole != NULL && ahc->enabled_luns > 0) { in ahc_handle_en_lun()
7514 ccb->ccb_h.status = CAM_REQ_CMP; in ahc_handle_en_lun()
7515 xpt_print_path(ccb->ccb_h.path); in ahc_handle_en_lun()
7522 ccb->ccb_h.status = CAM_LUN_INVALID; in ahc_handle_en_lun()
7526 ccb->ccb_h.status = CAM_REQ_CMP; in ahc_handle_en_lun()
7527 LIST_FOREACH(scb, &ahc->pending_scbs, pending_links) { in ahc_handle_en_lun()
7530 ccbh = &scb->io_ctx->ccb_h; in ahc_handle_en_lun()
7531 if (ccbh->func_code == XPT_CONT_TARGET_IO in ahc_handle_en_lun()
7532 && !xpt_path_comp(ccbh->path, ccb->ccb_h.path)){ in ahc_handle_en_lun()
7534 ccb->ccb_h.status = CAM_REQ_INVALID; in ahc_handle_en_lun()
7539 if (SLIST_FIRST(&lstate->accept_tios) != NULL) { in ahc_handle_en_lun()
7541 while ((cancel_ccb = (union ccb *)SLIST_FIRST(&lstate->accept_tios)) != NULL) { in ahc_handle_en_lun()
7542 SLIST_REMOVE_HEAD(&lstate->accept_tios, sim_links.sle); in ahc_handle_en_lun()
7543 cancel_ccb->ccb_h.status = CAM_REQ_ABORTED; in ahc_handle_en_lun()
7548 if (SLIST_FIRST(&lstate->immed_notifies) != NULL) { in ahc_handle_en_lun()
7550 while ((cancel_ccb = (union ccb *)SLIST_FIRST(&lstate->immed_notifies)) != NULL) { in ahc_handle_en_lun()
7551 SLIST_REMOVE_HEAD(&lstate->immed_notifies, sim_links.sle); in ahc_handle_en_lun()
7552 cancel_ccb->ccb_h.status = CAM_REQ_ABORTED; in ahc_handle_en_lun()
7557 if (ccb->ccb_h.status != CAM_REQ_CMP) { in ahc_handle_en_lun()
7561 xpt_print_path(ccb->ccb_h.path); in ahc_handle_en_lun()
7563 xpt_free_path(lstate->path); in ahc_handle_en_lun()
7569 tstate->enabled_luns[lun] = NULL; in ahc_handle_en_lun()
7570 ahc->enabled_luns--; in ahc_handle_en_lun()
7572 if (tstate->enabled_luns[i] != NULL) { in ahc_handle_en_lun()
7580 if (ahc->features & AHC_MULTI_TID) { in ahc_handle_en_lun()
7595 ahc->black_hole = NULL; in ahc_handle_en_lun()
7603 if (ahc->enabled_luns == 0) { in ahc_handle_en_lun()
7604 /* Disallow select-in */ in ahc_handle_en_lun()
7614 if ((ahc->features & AHC_MULTIROLE) == 0) { in ahc_handle_en_lun()
7616 ahc->flags &= ~AHC_TARGETROLE; in ahc_handle_en_lun()
7617 ahc->flags |= AHC_INITIATORROLE; in ahc_handle_en_lun()
7640 if ((ahc->features & AHC_MULTI_TID) == 0) in ahc_update_scsiid()
7641 panic("ahc_update_scsiid called on non-multitid unit\n"); in ahc_update_scsiid()
7649 if ((ahc->features & AHC_ULTRA2) != 0) in ahc_update_scsiid()
7660 our_id = ahc->our_id; in ahc_update_scsiid()
7662 our_id--; in ahc_update_scsiid()
7666 if ((ahc->features & AHC_ULTRA2) != 0) in ahc_update_scsiid()
7678 * If the card supports auto-access pause, in ahc_run_tqinfifo()
7682 if ((ahc->features & AHC_AUTOPAUSE) != 0) in ahc_run_tqinfifo()
7686 while ((cmd = &ahc->targetcmds[ahc->tqinfifonext])->cmd_valid != 0) { in ahc_run_tqinfifo()
7694 cmd->cmd_valid = 0; in ahc_run_tqinfifo()
7695 aic_dmamap_sync(ahc, ahc->shared_data_dmat, in ahc_run_tqinfifo()
7696 ahc->shared_data_dmamap, in ahc_run_tqinfifo()
7697 ahc_targetcmd_offset(ahc, ahc->tqinfifonext), in ahc_run_tqinfifo()
7700 ahc->tqinfifonext++; in ahc_run_tqinfifo()
7706 if ((ahc->tqinfifonext & (HOST_TQINPOS - 1)) == 1) { in ahc_run_tqinfifo()
7707 if ((ahc->features & AHC_HS_MAILBOX) != 0) { in ahc_run_tqinfifo()
7712 hs_mailbox |= ahc->tqinfifonext & HOST_TQINPOS; in ahc_run_tqinfifo()
7718 ahc->tqinfifonext & HOST_TQINPOS); in ahc_run_tqinfifo()
7737 initiator = SCSIID_TARGET(ahc, cmd->scsiid); in ahc_handle_target_cmd()
7738 target = SCSIID_OUR_ID(cmd->scsiid); in ahc_handle_target_cmd()
7739 lun = (cmd->identify & MSG_IDENTIFY_LUNMASK); in ahc_handle_target_cmd()
7741 byte = cmd->bytes; in ahc_handle_target_cmd()
7742 tstate = ahc->enabled_targets[target]; in ahc_handle_target_cmd()
7745 lstate = tstate->enabled_luns[lun]; in ahc_handle_target_cmd()
7751 lstate = ahc->black_hole; in ahc_handle_target_cmd()
7753 atio = (struct ccb_accept_tio*)SLIST_FIRST(&lstate->accept_tios); in ahc_handle_target_cmd()
7755 ahc->flags |= AHC_TQINFIFO_BLOCKED; in ahc_handle_target_cmd()
7763 ahc->flags &= ~AHC_TQINFIFO_BLOCKED; in ahc_handle_target_cmd()
7768 lstate == ahc->black_hole ? "(Black Holed)" : ""); in ahc_handle_target_cmd()
7771 SLIST_REMOVE_HEAD(&lstate->accept_tios, sim_links.sle); in ahc_handle_target_cmd()
7773 if (lstate == ahc->black_hole) { in ahc_handle_target_cmd()
7775 atio->ccb_h.target_id = target; in ahc_handle_target_cmd()
7776 atio->ccb_h.target_lun = lun; in ahc_handle_target_cmd()
7783 atio->sense_len = 0; in ahc_handle_target_cmd()
7784 atio->init_id = initiator; in ahc_handle_target_cmd()
7787 atio->tag_action = *byte++; in ahc_handle_target_cmd()
7788 atio->tag_id = *byte++; in ahc_handle_target_cmd()
7789 atio->ccb_h.flags |= CAM_TAG_ACTION_VALID; in ahc_handle_target_cmd()
7791 atio->ccb_h.flags &= ~CAM_TAG_ACTION_VALID; in ahc_handle_target_cmd()
7798 atio->cdb_len = 6; in ahc_handle_target_cmd()
7802 atio->cdb_len = 10; in ahc_handle_target_cmd()
7805 atio->cdb_len = 16; in ahc_handle_target_cmd()
7808 atio->cdb_len = 12; in ahc_handle_target_cmd()
7813 atio->cdb_len = 1; in ahc_handle_target_cmd()
7818 memcpy(atio->cdb_io.cdb_bytes, byte, atio->cdb_len); in ahc_handle_target_cmd()
7820 atio->ccb_h.status |= CAM_CDB_RECVD; in ahc_handle_target_cmd()
7822 if ((cmd->identify & MSG_IDENTIFY_DISCFLAG) == 0) { in ahc_handle_target_cmd()
7831 printf("Received Immediate Command %d:%d:%d - %p\n", in ahc_handle_target_cmd()
7832 initiator, target, lun, ahc->pending_device); in ahc_handle_target_cmd()
7835 ahc->pending_device = lstate; in ahc_handle_target_cmd()
7837 atio->ccb_h.flags |= CAM_DIS_DISCONNECT; in ahc_handle_target_cmd()
7839 atio->ccb_h.flags &= ~CAM_DIS_DISCONNECT; in ahc_handle_target_cmd()