Lines Matching +full:ld +full:- +full:pulse +full:- +full:delay +full:- +full:us
1 /*-
4 * SPDX-License-Identifier: BSD-3-Clause
6 * Copyright (c) 1994-2002, 2004 Justin T. Gibbs.
7 * Copyright (c) 2000-2003 Adaptec Inc.
21 * 3. Neither the names of the above-listed copyright holders nor the names
74 { DPARERR, "Data-path Parity Error" },
82 { P_DATAOUT, MSG_NOOP, "in Data-out phase" },
83 { P_DATAIN, MSG_INITIATOR_DET_ERR, "in Data-in phase" },
84 { P_DATAOUT_DT, MSG_NOOP, "in DT Data-out phase" },
85 { P_DATAIN_DT, MSG_INITIATOR_DET_ERR, "in DT Data-in phase" },
87 { P_MESGOUT, MSG_NOOP, "in Message-out phase" },
89 { P_MESGIN, MSG_PARITY_ERROR, "in Message-in phase" },
98 static const u_int num_phases = NUM_ELEMENTS(ahd_phase_table) - 1;
266 if ((ahd->bugs & AHD_PKTIZED_STATUS_BUG) != 0) { in ahd_currently_packetized()
270 * for non-zero LQISTATE instead. in ahd_currently_packetized()
313 ahd_outb(ahd, SCSISIGO, 0); /* De-assert BSY */ in ahd_restart()
329 ahd_outb(ahd, TQINPOS, ahd->tqinfifonext); in ahd_restart()
395 printf("%s: Warning - GSFIFO SCB %d invalid\n", in ahd_flush_qoutfifo()
428 * also delay a bit so that status has a chance in ahd_flush_qoutfifo()
445 * so that we update our in-core copy of the in ahd_flush_qoutfifo()
519 printf("%s: Warning - DMA-up and complete " in ahd_flush_qoutfifo()
524 hscb_ptr = (uint8_t *)scb->hscb; in ahd_flush_qoutfifo()
540 printf("%s: Warning - Complete Qfrz SCB %d invalid\n", in ahd_flush_qoutfifo()
557 printf("%s: Warning - Complete SCB %d invalid\n", in ahd_flush_qoutfifo()
573 ahd->flags |= AHD_UPDATE_PEND_CMDS; in ahd_flush_qoutfifo()
705 sgptr -= 0x100; in ahd_run_data_fifo()
760 if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0) { in ahd_run_data_fifo()
764 data_addr = sg->addr; in ahd_run_data_fifo()
765 data_len = sg->len; in ahd_run_data_fifo()
771 data_addr = sg->len & AHD_SG_HIGH_ADDR_MASK; in ahd_run_data_fifo()
773 data_addr |= sg->addr; in ahd_run_data_fifo()
774 data_len = sg->len; in ahd_run_data_fifo()
799 if ((ahd->features & AHD_NEW_DFCNTRL_OPTS) != 0) { in ahd_run_data_fifo()
826 ahd_inb_scbram(ahd, SCB_FIFO_USE_COUNT) - 1); in ahd_run_data_fifo()
834 * of the entry - the valid value toggles each time through
848 if ((ahd->flags & AHD_RUNNING_QOUTFIFO) != 0) in ahd_run_qoutfifo()
850 ahd->flags |= AHD_RUNNING_QOUTFIFO; in ahd_run_qoutfifo()
853 completion = &ahd->qoutfifo[ahd->qoutfifonext]; in ahd_run_qoutfifo()
855 if (completion->valid_tag != ahd->qoutfifonext_valid_tag) in ahd_run_qoutfifo()
858 scb_index = aic_le16toh(completion->tag); in ahd_run_qoutfifo()
864 ahd->qoutfifonext); in ahd_run_qoutfifo()
867 } else if ((completion->sg_status & SG_STATUS_VALID) != 0) { in ahd_run_qoutfifo()
873 ahd->qoutfifonext = (ahd->qoutfifonext+1) & (AHD_QOUT_SIZE-1); in ahd_run_qoutfifo()
874 if (ahd->qoutfifonext == 0) in ahd_run_qoutfifo()
875 ahd->qoutfifonext_valid_tag ^= QOUTFIFO_ENTRY_VALID; in ahd_run_qoutfifo()
877 ahd->flags &= ~AHD_RUNNING_QOUTFIFO; in ahd_run_qoutfifo()
924 if ((ahd->bugs & AHD_INTCOLLISION_BUG) != 0) { in ahd_handle_seqint()
960 ahd_outb(ahd, SAVED_SCSIID, scb->hscb->scsiid); in ahd_handle_seqint()
961 ahd_outb(ahd, SAVED_LUN, scb->hscb->lun); in ahd_handle_seqint()
1020 ahd_outq(ahd, HADDR, scb->sense_busaddr); in ahd_handle_seqint()
1055 * If a target takes us into the command phase in ahd_handle_seqint()
1097 scb->hscb->control &= ~(TAG_ENB|SCB_TAG_TYPE); in ahd_handle_seqint()
1098 scb->hscb->control |= MK_MESSAGE; in ahd_handle_seqint()
1099 ahd_outb(ahd, SCB_CONTROL, scb->hscb->control); in ahd_handle_seqint()
1101 ahd_outb(ahd, SAVED_SCSIID, scb->hscb->scsiid); in ahd_handle_seqint()
1109 scb->flags &= ~SCB_PACKETIZED; in ahd_handle_seqint()
1110 scb->flags |= SCB_ABORT|SCB_CMDPHASE_ABORT; in ahd_handle_seqint()
1117 * non-pack processing. in ahd_handle_seqint()
1121 if ((ahd->bugs & AHD_CLRLQO_AUTOCLR_BUG) != 0) { in ahd_handle_seqint()
1157 ahd->msgout_buf[0] = MSG_ABORT_TASK; in ahd_handle_seqint()
1158 ahd->msgout_len = 1; in ahd_handle_seqint()
1159 ahd->msgout_index = 0; in ahd_handle_seqint()
1160 ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT; in ahd_handle_seqint()
1180 printf("%s: PDATA_REINIT - DFCNTRL = 0x%x " in ahd_handle_seqint()
1205 if (ahd->msg_type == MSG_TYPE_NONE) { in ahd_handle_seqint()
1234 ahd->msg_type = in ahd_handle_seqint()
1236 ahd->msgin_index = 0; in ahd_handle_seqint()
1242 ahd->msg_type = in ahd_handle_seqint()
1244 ahd->msgin_index = 0; in ahd_handle_seqint()
1264 "target - issuing BUS DEVICE RESET\n", in ahd_handle_seqint()
1287 ahd->msgout_buf[0] = MSG_BUS_DEV_RESET; in ahd_handle_seqint()
1288 ahd->msgout_len = 1; in ahd_handle_seqint()
1289 ahd->msgout_index = 0; in ahd_handle_seqint()
1290 ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT; in ahd_handle_seqint()
1358 ahd_lookup_phase_entry(lastphase)->phasemsg, in ahd_handle_seqint()
1361 printf("%s seen Data Phase. Length = %ld. " in ahd_handle_seqint()
1365 aic_get_transfer_length(scb), scb->sg_count); in ahd_handle_seqint()
1393 && (scb->flags & SCB_RECOVERY_SCB) != 0) in ahd_handle_seqint()
1421 scb->hscb->task_management); in ahd_handle_seqint()
1425 switch (scb->hscb->task_management) { in ahd_handle_seqint()
1430 lun = scb->hscb->lun; in ahd_handle_seqint()
1437 lun = scb->hscb->lun; in ahd_handle_seqint()
1502 seqintcode - TRACEPOINT0); in ahd_handle_seqint()
1588 if ((ahd->bugs & AHD_CLRLQO_AUTOCLR_BUG) != 0) in ahd_handle_scsiint()
1618 printf("%s: ahd_intr - referenced scb not " in ahd_handle_scsiint()
1639 * also revert us to async/narrow transfers until in ahd_handle_scsiint()
1717 packetized = (scb->flags & SCB_PACKETIZED) != 0; in ahd_handle_scsiint()
1735 * on the bus in a non-packetized in ahd_handle_scsiint()
1749 * Busfrees that occur in non-packetized phases are in ahd_handle_scsiint()
1760 * the interrupt is a pulse, so in a perfect world, we in ahd_handle_scsiint()
1765 * the ENBUSFREE if the busfree occurred during a non-pack in ahd_handle_scsiint()
1771 && (ahd->bugs & AHD_BUSFREEREV_BUG) != 0) in ahd_handle_scsiint()
1812 && (ahd->bugs & AHD_NLQICRC_DELAYED_BUG) != 0) { in ahd_handle_transmission_error()
1878 * is asserted while in message out to take us in ahd_handle_transmission_error()
1899 * We detected a CRC error in a NON-LQ packet. in ahd_handle_transmission_error()
1937 * LQIRETRY. Should the target stay in a non-pkt in ahd_handle_transmission_error()
1961 ahd_lookup_phase_entry(curphase)->phasemsg); in ahd_handle_transmission_error()
1976 ahd->send_msg_perror = msg_out; in ahd_handle_transmission_error()
1978 scb->flags |= SCB_TRANSMISSION_ERROR; in ahd_handle_transmission_error()
2069 if ((ahd->bugs & AHD_CLRLQO_AUTOCLR_BUG) != 0) in ahd_handle_pkt_busfree()
2103 if (scb->crc_retry_count < AHD_MAX_LQ_CRC_ERRORS) { in ahd_handle_pkt_busfree()
2110 scb->crc_retry_count++; in ahd_handle_pkt_busfree()
2136 if (ahd->src_mode != AHD_MODE_SCSI) { in ahd_handle_pkt_busfree()
2161 * Non-packetized unexpected or expected busfree.
2197 ppr_busfree = (ahd->msg_flags & MSG_FLAG_EXPECT_PPR_BUSFREE) != 0; in ahd_handle_nonpkt_busfree()
2214 sent_msg = ahd->msgout_buf[ahd->msgout_index - 1]; in ahd_handle_nonpkt_busfree()
2216 printf("SCB %d - Abort%s Completed.\n", in ahd_handle_nonpkt_busfree()
2223 if ((scb->flags & SCB_CMDPHASE_ABORT) != 0) { in ahd_handle_nonpkt_busfree()
2237 saved_lun = scb->hscb->lun; in ahd_handle_nonpkt_busfree()
2252 && scb->io_ctx->ccb_h.func_code== XPT_RESET_DEV in ahd_handle_nonpkt_busfree()
2274 * with non-ppr negotiation. in ahd_handle_nonpkt_busfree()
2283 if ((tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ)!=0) { in ahd_handle_nonpkt_busfree()
2299 tinfo->curr.transport_version = 2; in ahd_handle_nonpkt_busfree()
2300 tinfo->goal.transport_version = 2; in ahd_handle_nonpkt_busfree()
2301 tinfo->goal.ppr_options = 0; in ahd_handle_nonpkt_busfree()
2314 * Negotiation Rejected. Go-narrow and in ahd_handle_nonpkt_busfree()
2336 * Negotiation Rejected. Go-async and in ahd_handle_nonpkt_busfree()
2356 } else if ((ahd->msg_flags & MSG_FLAG_EXPECT_IDE_BUSFREE) != 0 in ahd_handle_nonpkt_busfree()
2364 } else if ((ahd->msg_flags & MSG_FLAG_EXPECT_QASREJ_BUSFREE) in ahd_handle_nonpkt_busfree()
2382 && ((ahd->msg_flags & MSG_FLAG_EXPECT_PPR_BUSFREE) != 0)) { in ahd_handle_nonpkt_busfree()
2386 if ((ahd->msg_flags & MSG_FLAG_IU_REQ_CHANGED) != 0) { in ahd_handle_nonpkt_busfree()
2407 if ((scb->hscb->control & TAG_ENB) != 0) in ahd_handle_nonpkt_busfree()
2425 ahd_lookup_phase_entry(lastphase)->phasemsg, in ahd_handle_nonpkt_busfree()
2484 * us prior to completing the command. Since we don't in ahd_handle_proto_violation()
2523 ahd->msgout_buf[0] = MSG_ABORT_TASK; in ahd_handle_proto_violation()
2524 ahd->msgout_len = 1; in ahd_handle_proto_violation()
2525 ahd->msgout_index = 0; in ahd_handle_proto_violation()
2526 ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT; in ahd_handle_proto_violation()
2529 scb->flags |= SCB_ABORT; in ahd_handle_proto_violation()
2532 ahd_lookup_phase_entry(curphase)->phasemsg); in ahd_handle_proto_violation()
2554 devinfo->channel, in ahd_force_renegotiation()
2555 devinfo->our_scsiid, in ahd_force_renegotiation()
2556 devinfo->target, in ahd_force_renegotiation()
2578 if (ahd->num_critical_sections == 0) in ahd_clear_critical_section()
2600 cs = ahd->critical_sections; in ahd_clear_critical_section()
2601 for (i = 0; i < ahd->num_critical_sections; i++, cs++) { in ahd_clear_critical_section()
2603 if (cs->begin < seqaddr && cs->end >= seqaddr) in ahd_clear_critical_section()
2607 if (i == ahd->num_critical_sections) in ahd_clear_critical_section()
2645 * we cannot re-enable busfree detection within in ahd_clear_critical_section()
2655 ahd_set_modes(ahd, ahd->saved_src_mode, ahd->saved_dst_mode); in ahd_clear_critical_section()
2656 ahd_outb(ahd, HCNTRL, ahd->unpause); in ahd_clear_critical_section()
2701 if ((ahd->bugs & AHD_CLRLQO_AUTOCLR_BUG) != 0) { in ahd_clear_intstat()
2723 hscb = scb->hscb; in ahd_print_scb()
2726 hscb->control, in ahd_print_scb()
2727 hscb->scsiid, in ahd_print_scb()
2728 hscb->lun, in ahd_print_scb()
2729 hscb->cdb_len); in ahd_print_scb()
2731 for (i = 0; i < sizeof(hscb->shared_data.idata.cdb); i++) in ahd_print_scb()
2732 printf("%#02x", hscb->shared_data.idata.cdb[i]); in ahd_print_scb()
2734 (uint32_t)((aic_le64toh(hscb->dataptr) >> 32) & 0xFFFFFFFF), in ahd_print_scb()
2735 (uint32_t)(aic_le64toh(hscb->dataptr) & 0xFFFFFFFF), in ahd_print_scb()
2736 aic_le32toh(hscb->datacnt), in ahd_print_scb()
2737 aic_le32toh(hscb->sgptr), in ahd_print_scb()
2747 if (scb->sg_count > 0) { in ahd_dump_sglist()
2748 if ((scb->ahd_softc->flags & AHD_64BIT_ADDRESSING) != 0) { in ahd_dump_sglist()
2751 sg_list = (struct ahd_dma64_seg*)scb->sg_list; in ahd_dump_sglist()
2752 for (i = 0; i < scb->sg_count; i++) { in ahd_dump_sglist()
2756 printf("sg[%d] - Addr 0x%x%x : Length %d%s\n", in ahd_dump_sglist()
2767 sg_list = (struct ahd_dma_seg*)scb->sg_list; in ahd_dump_sglist()
2768 for (i = 0; i < scb->sg_count; i++) { in ahd_dump_sglist()
2772 printf("sg[%d] - Addr 0x%x%x : Length %d%s\n", in ahd_dump_sglist()
2795 master_tstate = ahd->enabled_targets[ahd->our_id]; in ahd_alloc_tstate()
2796 if (ahd->enabled_targets[scsi_id] != NULL in ahd_alloc_tstate()
2797 && ahd->enabled_targets[scsi_id] != master_tstate) in ahd_alloc_tstate()
2798 panic("%s: ahd_alloc_tstate - Target already allocated", in ahd_alloc_tstate()
2808 * until an initiator talks to us. in ahd_alloc_tstate()
2812 memset(tstate->enabled_luns, 0, sizeof(tstate->enabled_luns)); in ahd_alloc_tstate()
2814 memset(&tstate->transinfo[i].curr, 0, in ahd_alloc_tstate()
2815 sizeof(tstate->transinfo[i].curr)); in ahd_alloc_tstate()
2816 memset(&tstate->transinfo[i].goal, 0, in ahd_alloc_tstate()
2817 sizeof(tstate->transinfo[i].goal)); in ahd_alloc_tstate()
2821 ahd->enabled_targets[scsi_id] = tstate; in ahd_alloc_tstate()
2839 if (scsi_id == ahd->our_id in ahd_free_tstate()
2843 tstate = ahd->enabled_targets[scsi_id]; in ahd_free_tstate()
2846 ahd->enabled_targets[scsi_id] = NULL; in ahd_free_tstate()
2883 transinfo = &tinfo->user; in ahd_devlimited_syncrate()
2885 transinfo = &tinfo->goal; in ahd_devlimited_syncrate()
2886 *ppr_options &= (transinfo->ppr_options|MSG_EXT_PPR_PCOMP_EN); in ahd_devlimited_syncrate()
2887 if (transinfo->width == MSG_EXT_WDTR_BUS_8_BIT) { in ahd_devlimited_syncrate()
2891 if (transinfo->period == 0) { in ahd_devlimited_syncrate()
2895 *period = MAX(*period, transinfo->period); in ahd_devlimited_syncrate()
2956 if ((ahd->bugs & AHD_PACED_NEGTABLE_BUG) != 0) in ahd_validate_offset()
2965 *offset = MIN(*offset, tinfo->user.offset); in ahd_validate_offset()
2967 *offset = MIN(*offset, tinfo->goal.offset); in ahd_validate_offset()
2981 if (ahd->features & AHD_WIDE) { in ahd_validate_width()
2993 *bus_width = MIN(tinfo->user.width, *bus_width); in ahd_validate_width()
2995 *bus_width = MIN(tinfo->goal.width, *bus_width); in ahd_validate_width()
3012 auto_negotiate_orig = tstate->auto_negotiate; in ahd_update_neg_request()
3020 if ((ahd->features & AHD_WIDE) != 0) in ahd_update_neg_request()
3021 tinfo->curr.width = AHD_WIDTH_UNKNOWN; in ahd_update_neg_request()
3022 tinfo->curr.period = AHD_PERIOD_UNKNOWN; in ahd_update_neg_request()
3023 tinfo->curr.offset = AHD_OFFSET_UNKNOWN; in ahd_update_neg_request()
3025 if (tinfo->curr.period != tinfo->goal.period in ahd_update_neg_request()
3026 || tinfo->curr.width != tinfo->goal.width in ahd_update_neg_request()
3027 || tinfo->curr.offset != tinfo->goal.offset in ahd_update_neg_request()
3028 || tinfo->curr.ppr_options != tinfo->goal.ppr_options in ahd_update_neg_request()
3030 && (tinfo->goal.offset != 0 in ahd_update_neg_request()
3031 || tinfo->goal.width != MSG_EXT_WDTR_BUS_8_BIT in ahd_update_neg_request()
3032 || tinfo->goal.ppr_options != 0))) in ahd_update_neg_request()
3033 tstate->auto_negotiate |= devinfo->target_mask; in ahd_update_neg_request()
3035 tstate->auto_negotiate &= ~devinfo->target_mask; in ahd_update_neg_request()
3037 return (auto_negotiate_orig != tstate->auto_negotiate); in ahd_update_neg_request()
3044 * active update, the specified target is currently talking to us on
3069 tinfo = ahd_fetch_transinfo(ahd, devinfo->channel, devinfo->our_scsiid, in ahd_set_syncrate()
3070 devinfo->target, &tstate); in ahd_set_syncrate()
3073 tinfo->user.period = period; in ahd_set_syncrate()
3074 tinfo->user.offset = offset; in ahd_set_syncrate()
3075 tinfo->user.ppr_options = ppr_options; in ahd_set_syncrate()
3079 tinfo->goal.period = period; in ahd_set_syncrate()
3080 tinfo->goal.offset = offset; in ahd_set_syncrate()
3081 tinfo->goal.ppr_options = ppr_options; in ahd_set_syncrate()
3084 old_period = tinfo->curr.period; in ahd_set_syncrate()
3085 old_offset = tinfo->curr.offset; in ahd_set_syncrate()
3086 old_ppr = tinfo->curr.ppr_options; in ahd_set_syncrate()
3094 tinfo->curr.period = period; in ahd_set_syncrate()
3095 tinfo->curr.offset = offset; in ahd_set_syncrate()
3096 tinfo->curr.ppr_options = ppr_options; in ahd_set_syncrate()
3098 ahd_send_async(ahd, devinfo->channel, devinfo->target, in ahd_set_syncrate()
3106 ahd_name(ahd), devinfo->target, in ahd_set_syncrate()
3136 ahd_name(ahd), devinfo->target, in ahd_set_syncrate()
3143 * Always refresh the neg-table to handle the case of the in ahd_set_syncrate()
3153 ahd_update_neg_table(ahd, devinfo, &tinfo->curr); in ahd_set_syncrate()
3156 if (ahd->msg_type != MSG_TYPE_NONE) { in ahd_set_syncrate()
3165 ahd->msg_flags |= MSG_FLAG_EXPECT_PPR_BUSFREE in ahd_set_syncrate()
3173 ahd->msg_flags |= MSG_FLAG_EXPECT_PPR_BUSFREE; in ahd_set_syncrate()
3189 * active update, the specified target is currently talking to us on
3205 tinfo = ahd_fetch_transinfo(ahd, devinfo->channel, devinfo->our_scsiid, in ahd_set_width()
3206 devinfo->target, &tstate); in ahd_set_width()
3209 tinfo->user.width = width; in ahd_set_width()
3212 tinfo->goal.width = width; in ahd_set_width()
3214 oldwidth = tinfo->curr.width; in ahd_set_width()
3218 tinfo->curr.width = width; in ahd_set_width()
3219 ahd_send_async(ahd, devinfo->channel, devinfo->target, in ahd_set_width()
3223 ahd_name(ahd), devinfo->target, in ahd_set_width()
3231 ahd_update_neg_table(ahd, devinfo, &tinfo->curr); in ahd_set_width()
3251 ahd_send_async(ahd, devinfo->channel, devinfo->target, in ahd_set_tags()
3252 devinfo->lun, AC_TRANSFER_NEG, &alg); in ahd_set_tags()
3265 uint8_t iocell_opts[sizeof(ahd->iocell_opts)]; in ahd_update_neg_table()
3271 ahd_outb(ahd, NEGOADDR, devinfo->target); in ahd_update_neg_table()
3272 period = tinfo->period; in ahd_update_neg_table()
3273 offset = tinfo->offset; in ahd_update_neg_table()
3274 memcpy(iocell_opts, ahd->iocell_opts, sizeof(ahd->iocell_opts)); in ahd_update_neg_table()
3275 ppr_opts = tinfo->ppr_options & (MSG_EXT_PPR_QAS_REQ|MSG_EXT_PPR_DT_REQ in ahd_update_neg_table()
3281 if ((ahd->bugs & AHD_PACED_NEGTABLE_BUG) != 0) { in ahd_update_neg_table()
3304 if ((tinfo->ppr_options & MSG_EXT_PPR_PCOMP_EN) == 0) in ahd_update_neg_table()
3309 * Precomp should be disabled for non-paced transfers. in ahd_update_neg_table()
3313 if ((ahd->features & AHD_NEW_IOCELL_OPTS) != 0 in ahd_update_neg_table()
3318 * compatible with non-packetized in ahd_update_neg_table()
3325 if ((ahd->bugs & AHD_PACED_NEGTABLE_BUG) != 0) { in ahd_update_neg_table()
3328 * on non-paced transfers. in ahd_update_neg_table()
3344 if (tinfo->width == MSG_EXT_WDTR_BUS_16_BIT) in ahd_update_neg_table()
3349 * give us the opportunity to send command packets in ahd_update_neg_table()
3350 * without us asserting attention. in ahd_update_neg_table()
3352 if ((tinfo->ppr_options & MSG_EXT_PPR_IU_REQ) == 0) in ahd_update_neg_table()
3385 LIST_FOREACH(pending_scb, &ahd->pending_scbs, pending_links) { in ahd_update_pending_scbs()
3393 if ((tstate->auto_negotiate & devinfo.target_mask) == 0 in ahd_update_pending_scbs()
3394 && (pending_scb->flags & SCB_AUTO_NEGOTIATE) != 0) { in ahd_update_pending_scbs()
3395 pending_scb->flags &= ~SCB_AUTO_NEGOTIATE; in ahd_update_pending_scbs()
3396 pending_scb->hscb->control &= ~MK_MESSAGE; in ahd_update_pending_scbs()
3417 * effect whether we select-out with ATN. It is only in ahd_update_pending_scbs()
3428 LIST_FOREACH(pending_scb, &ahd->pending_scbs, pending_links) { in ahd_update_pending_scbs()
3436 control |= pending_scb->hscb->control & MK_MESSAGE; in ahd_update_pending_scbs()
3486 devinfo->target, devinfo->lun); in ahd_print_devinfo()
3501 if (phase == entry->phase) in ahd_lookup_phase_entry()
3511 devinfo->our_scsiid = our_id; in ahd_compile_devinfo()
3512 devinfo->target = target; in ahd_compile_devinfo()
3513 devinfo->lun = lun; in ahd_compile_devinfo()
3514 devinfo->target_offset = target; in ahd_compile_devinfo()
3515 devinfo->channel = channel; in ahd_compile_devinfo()
3516 devinfo->role = role; in ahd_compile_devinfo()
3518 devinfo->target_offset += 8; in ahd_compile_devinfo()
3519 devinfo->target_mask = (0x01 << devinfo->target_offset); in ahd_compile_devinfo()
3529 our_id = SCSIID_OUR_ID(scb->hscb->scsiid); in ahd_scb_devinfo()
3531 if ((scb->hscb->control & TARGET_SCB) != 0) in ahd_scb_devinfo()
3553 ahd->msgout_index = 0; in ahd_setup_initiator_msgout()
3554 ahd->msgout_len = 0; in ahd_setup_initiator_msgout()
3557 ahd->msg_flags |= MSG_FLAG_PACKETIZED; in ahd_setup_initiator_msgout()
3559 if (ahd->send_msg_perror in ahd_setup_initiator_msgout()
3561 ahd->msgout_buf[ahd->msgout_index++] = ahd->send_msg_perror; in ahd_setup_initiator_msgout()
3562 ahd->msgout_len++; in ahd_setup_initiator_msgout()
3563 ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT; in ahd_setup_initiator_msgout()
3571 "I_T msgin. Issuing NO-OP\n", ahd_name(ahd)); in ahd_setup_initiator_msgout()
3573 ahd->msgout_buf[ahd->msgout_index++] = MSG_NOOP; in ahd_setup_initiator_msgout()
3574 ahd->msgout_len++; in ahd_setup_initiator_msgout()
3575 ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT; in ahd_setup_initiator_msgout()
3579 if ((scb->flags & SCB_DEVICE_RESET) == 0 in ahd_setup_initiator_msgout()
3580 && (scb->flags & SCB_PACKETIZED) == 0 in ahd_setup_initiator_msgout()
3585 if ((scb->hscb->control & DISCENB) != 0) in ahd_setup_initiator_msgout()
3587 ahd->msgout_buf[ahd->msgout_index++] = identify_msg; in ahd_setup_initiator_msgout()
3588 ahd->msgout_len++; in ahd_setup_initiator_msgout()
3590 if ((scb->hscb->control & TAG_ENB) != 0) { in ahd_setup_initiator_msgout()
3591 ahd->msgout_buf[ahd->msgout_index++] = in ahd_setup_initiator_msgout()
3592 scb->hscb->control & (TAG_ENB|SCB_TAG_TYPE); in ahd_setup_initiator_msgout()
3593 ahd->msgout_buf[ahd->msgout_index++] = SCB_GET_TAG(scb); in ahd_setup_initiator_msgout()
3594 ahd->msgout_len += 2; in ahd_setup_initiator_msgout()
3598 if (scb->flags & SCB_DEVICE_RESET) { in ahd_setup_initiator_msgout()
3599 ahd->msgout_buf[ahd->msgout_index++] = MSG_BUS_DEV_RESET; in ahd_setup_initiator_msgout()
3600 ahd->msgout_len++; in ahd_setup_initiator_msgout()
3612 } else if ((scb->flags & SCB_ABORT) != 0) { in ahd_setup_initiator_msgout()
3613 if ((scb->hscb->control & TAG_ENB) != 0) { in ahd_setup_initiator_msgout()
3614 ahd->msgout_buf[ahd->msgout_index++] = MSG_ABORT_TAG; in ahd_setup_initiator_msgout()
3616 ahd->msgout_buf[ahd->msgout_index++] = MSG_ABORT; in ahd_setup_initiator_msgout()
3618 ahd->msgout_len++; in ahd_setup_initiator_msgout()
3621 (scb->hscb->control & TAG_ENB) != 0 ? " Tag" : ""); in ahd_setup_initiator_msgout()
3631 } else if ((scb->flags & (SCB_AUTO_NEGOTIATE|SCB_NEGOTIATE)) != 0) { in ahd_setup_initiator_msgout()
3644 printf("SCSIID = %x, target_mask = %x\n", scb->hscb->scsiid, in ahd_setup_initiator_msgout()
3645 devinfo->target_mask); in ahd_setup_initiator_msgout()
3648 "SCB flags = %x", SCB_GET_TAG(scb), scb->hscb->control, in ahd_setup_initiator_msgout()
3650 scb->flags); in ahd_setup_initiator_msgout()
3659 scb->hscb->control &= ~MK_MESSAGE; in ahd_setup_initiator_msgout()
3660 ahd->msgout_index = 0; in ahd_setup_initiator_msgout()
3661 ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT; in ahd_setup_initiator_msgout()
3685 tinfo = ahd_fetch_transinfo(ahd, devinfo->channel, devinfo->our_scsiid, in ahd_build_transfer_msg()
3686 devinfo->target, &tstate); in ahd_build_transfer_msg()
3693 period = tinfo->goal.period; in ahd_build_transfer_msg()
3694 offset = tinfo->goal.offset; in ahd_build_transfer_msg()
3695 ppr_options = tinfo->goal.ppr_options; in ahd_build_transfer_msg()
3697 if (devinfo->role == ROLE_TARGET) in ahd_build_transfer_msg()
3700 &ppr_options, devinfo->role); in ahd_build_transfer_msg()
3701 dowide = tinfo->curr.width != tinfo->goal.width; in ahd_build_transfer_msg()
3702 dosync = tinfo->curr.offset != offset || tinfo->curr.period != period; in ahd_build_transfer_msg()
3711 dowide = tinfo->goal.width != MSG_EXT_WDTR_BUS_8_BIT; in ahd_build_transfer_msg()
3712 dosync = tinfo->goal.offset != 0; in ahd_build_transfer_msg()
3720 if ((ahd->features & AHD_WIDE) != 0) in ahd_build_transfer_msg()
3731 if (devinfo->role == ROLE_TARGET) in ahd_build_transfer_msg()
3737 * is capable of handling (based on whether an LVD->SE in ahd_build_transfer_msg()
3743 offset = tinfo->goal.offset; in ahd_build_transfer_msg()
3745 doppr ? tinfo->goal.width in ahd_build_transfer_msg()
3746 : tinfo->curr.width, in ahd_build_transfer_msg()
3747 devinfo->role); in ahd_build_transfer_msg()
3750 tinfo->goal.width, ppr_options); in ahd_build_transfer_msg()
3755 ahd_construct_wdtr(ahd, devinfo, tinfo->goal.width); in ahd_build_transfer_msg()
3769 ahd->msgout_buf[ahd->msgout_index++] = MSG_EXTENDED; in ahd_construct_sdtr()
3770 ahd->msgout_buf[ahd->msgout_index++] = MSG_EXT_SDTR_LEN; in ahd_construct_sdtr()
3771 ahd->msgout_buf[ahd->msgout_index++] = MSG_EXT_SDTR; in ahd_construct_sdtr()
3772 ahd->msgout_buf[ahd->msgout_index++] = period; in ahd_construct_sdtr()
3773 ahd->msgout_buf[ahd->msgout_index++] = offset; in ahd_construct_sdtr()
3774 ahd->msgout_len += 5; in ahd_construct_sdtr()
3777 ahd_name(ahd), devinfo->channel, devinfo->target, in ahd_construct_sdtr()
3778 devinfo->lun, period, offset); in ahd_construct_sdtr()
3790 ahd->msgout_buf[ahd->msgout_index++] = MSG_EXTENDED; in ahd_construct_wdtr()
3791 ahd->msgout_buf[ahd->msgout_index++] = MSG_EXT_WDTR_LEN; in ahd_construct_wdtr()
3792 ahd->msgout_buf[ahd->msgout_index++] = MSG_EXT_WDTR; in ahd_construct_wdtr()
3793 ahd->msgout_buf[ahd->msgout_index++] = bus_width; in ahd_construct_wdtr()
3794 ahd->msgout_len += 4; in ahd_construct_wdtr()
3797 ahd_name(ahd), devinfo->channel, devinfo->target, in ahd_construct_wdtr()
3798 devinfo->lun, bus_width); in ahd_construct_wdtr()
3820 ahd->msgout_buf[ahd->msgout_index++] = MSG_EXTENDED; in ahd_construct_ppr()
3821 ahd->msgout_buf[ahd->msgout_index++] = MSG_EXT_PPR_LEN; in ahd_construct_ppr()
3822 ahd->msgout_buf[ahd->msgout_index++] = MSG_EXT_PPR; in ahd_construct_ppr()
3823 ahd->msgout_buf[ahd->msgout_index++] = period; in ahd_construct_ppr()
3824 ahd->msgout_buf[ahd->msgout_index++] = 0; in ahd_construct_ppr()
3825 ahd->msgout_buf[ahd->msgout_index++] = offset; in ahd_construct_ppr()
3826 ahd->msgout_buf[ahd->msgout_index++] = bus_width; in ahd_construct_ppr()
3827 ahd->msgout_buf[ahd->msgout_index++] = ppr_options; in ahd_construct_ppr()
3828 ahd->msgout_len += 8; in ahd_construct_ppr()
3832 devinfo->channel, devinfo->target, devinfo->lun, in ahd_construct_ppr()
3847 ahd->send_msg_perror = 0; in ahd_clear_msg_state()
3848 ahd->msg_flags = MSG_FLAG_NONE; in ahd_clear_msg_state()
3849 ahd->msgout_len = 0; in ahd_clear_msg_state()
3850 ahd->msgin_index = 0; in ahd_clear_msg_state()
3851 ahd->msg_type = MSG_TYPE_NONE; in ahd_clear_msg_state()
3884 switch (ahd->msg_type) { in ahd_handle_message_phase()
3891 if (ahd->msgout_len == 0 && ahd->send_msg_perror == 0) in ahd_handle_message_phase()
3906 ->phasemsg); in ahd_handle_message_phase()
3913 * us or should be passed back to in ahd_handle_message_phase()
3917 ahd->send_msg_perror = 0; in ahd_handle_message_phase()
3918 ahd->msg_type = MSG_TYPE_INITIATOR_MSGIN; in ahd_handle_message_phase()
3919 ahd->msgin_index = 0; in ahd_handle_message_phase()
3926 if (ahd->send_msg_perror) { in ahd_handle_message_phase()
3931 printf(" byte 0x%x\n", ahd->send_msg_perror); in ahd_handle_message_phase()
3939 if ((ahd->msg_flags & MSG_FLAG_PACKETIZED) != 0 in ahd_handle_message_phase()
3940 && ahd->send_msg_perror == MSG_INITIATOR_DET_ERR) in ahd_handle_message_phase()
3941 ahd->msg_flags |= MSG_FLAG_EXPECT_IDE_BUSFREE; in ahd_handle_message_phase()
3943 ahd_outb(ahd, RETURN_2, ahd->send_msg_perror); in ahd_handle_message_phase()
3948 msgdone = ahd->msgout_index == ahd->msgout_len; in ahd_handle_message_phase()
3952 * Re-assert ATN, reset our message index to in ahd_handle_message_phase()
3955 ahd->msgout_index = 0; in ahd_handle_message_phase()
3959 lastbyte = ahd->msgout_index == (ahd->msgout_len - 1); in ahd_handle_message_phase()
3973 ahd->msgout_buf[ahd->msgout_index]); in ahd_handle_message_phase()
3975 ahd_outb(ahd, RETURN_2, ahd->msgout_buf[ahd->msgout_index++]); in ahd_handle_message_phase()
3996 ->phasemsg); in ahd_handle_message_phase()
3999 ahd->msgin_index = 0; in ahd_handle_message_phase()
4001 && (ahd->send_msg_perror != 0 in ahd_handle_message_phase()
4002 || (ahd->msgout_len != 0 in ahd_handle_message_phase()
4003 && ahd->msgout_index == 0))) { in ahd_handle_message_phase()
4004 ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT; in ahd_handle_message_phase()
4012 ahd->msgin_buf[ahd->msgin_index] = ahd_inb(ahd, SCSIBUS); in ahd_handle_message_phase()
4016 ahd->msgin_buf[ahd->msgin_index]); in ahd_handle_message_phase()
4026 ahd->msgin_index = 0; in ahd_handle_message_phase()
4030 * assert ATN so the target takes us to the in ahd_handle_message_phase()
4033 if (ahd->msgout_len != 0) { in ahd_handle_message_phase()
4043 ahd->msgin_index++; in ahd_handle_message_phase()
4064 if (ahd->msgout_len == 0) in ahd_handle_message_phase()
4074 && ahd->msgout_index > 0) in ahd_handle_message_phase()
4083 * us or should be passed back to in ahd_handle_message_phase()
4086 ahd->msg_type = MSG_TYPE_TARGET_MSGOUT; in ahd_handle_message_phase()
4088 ahd->msgin_index = 0; in ahd_handle_message_phase()
4096 msgdone = ahd->msgout_index == ahd->msgout_len; in ahd_handle_message_phase()
4108 ahd_outb(ahd, SCSIDAT, ahd->msgout_buf[ahd->msgout_index++]); in ahd_handle_message_phase()
4133 ahd->msgin_buf[ahd->msgin_index] = ahd_inb(ahd, SCSIDAT); in ahd_handle_message_phase()
4138 * us to go to bus free. The sequencer has already in ahd_handle_message_phase()
4145 ahd->msgin_index++; in ahd_handle_message_phase()
4152 ahd->msgin_index = 0; in ahd_handle_message_phase()
4158 if (ahd->msgout_len != 0) { in ahd_handle_message_phase()
4162 ahd->msg_type = MSG_TYPE_TARGET_MSGIN; in ahd_handle_message_phase()
4163 ahd->msgin_index = 0; in ahd_handle_message_phase()
4183 if ((ahd->msg_flags & MSG_FLAG_PACKETIZED) != 0) { in ahd_handle_message_phase()
4216 while (index < ahd->msgout_len) { in ahd_sent_msg()
4217 if (ahd->msgout_buf[index] == MSG_EXTENDED) { in ahd_sent_msg()
4220 end_index = index + 1 + ahd->msgout_buf[index + 1]; in ahd_sent_msg()
4221 if (ahd->msgout_buf[index+2] == msgval in ahd_sent_msg()
4224 if (ahd->msgout_index > end_index) in ahd_sent_msg()
4226 } else if (ahd->msgout_index > index) in ahd_sent_msg()
4230 } else if (ahd->msgout_buf[index] >= MSG_SIMPLE_TASK in ahd_sent_msg()
4231 && ahd->msgout_buf[index] <= MSG_IGN_WIDE_RESIDUE) { in ahd_sent_msg()
4237 && ahd->msgout_index > index in ahd_sent_msg()
4238 && (ahd->msgout_buf[index] == msgval in ahd_sent_msg()
4239 || ((ahd->msgout_buf[index] & MSG_IDENTIFYFLAG) != 0 in ahd_sent_msg()
4266 tinfo = ahd_fetch_transinfo(ahd, devinfo->channel, devinfo->our_scsiid, in ahd_parse_msg()
4267 devinfo->target, &tstate); in ahd_parse_msg()
4280 switch (ahd->msgin_buf[0]) { in ahd_parse_msg()
4301 if (ahd->msgin_index < 2) in ahd_parse_msg()
4303 switch (ahd->msgin_buf[2]) { in ahd_parse_msg()
4311 if (ahd->msgin_buf[1] != MSG_EXT_SDTR_LEN) { in ahd_parse_msg()
4323 if (ahd->msgin_index < (MSG_EXT_SDTR_LEN + 1)) in ahd_parse_msg()
4326 period = ahd->msgin_buf[3]; in ahd_parse_msg()
4328 saved_offset = offset = ahd->msgin_buf[4]; in ahd_parse_msg()
4330 &ppr_options, devinfo->role); in ahd_parse_msg()
4332 tinfo->curr.width, devinfo->role); in ahd_parse_msg()
4337 ahd_name(ahd), devinfo->channel, in ahd_parse_msg()
4338 devinfo->target, devinfo->lun, in ahd_parse_msg()
4339 ahd->msgin_buf[3], saved_offset, in ahd_parse_msg()
4355 /* Went too low - force async */ in ahd_parse_msg()
4363 && devinfo->role == ROLE_INITIATOR) { in ahd_parse_msg()
4366 ahd_name(ahd), devinfo->channel, in ahd_parse_msg()
4367 devinfo->target, devinfo->lun); in ahd_parse_msg()
4369 ahd->msgout_index = 0; in ahd_parse_msg()
4370 ahd->msgout_len = 0; in ahd_parse_msg()
4373 ahd->msgout_index = 0; in ahd_parse_msg()
4386 if (ahd->msgin_buf[1] != MSG_EXT_WDTR_LEN) { in ahd_parse_msg()
4398 if (ahd->msgin_index < (MSG_EXT_WDTR_LEN + 1)) in ahd_parse_msg()
4401 bus_width = ahd->msgin_buf[3]; in ahd_parse_msg()
4404 devinfo->role); in ahd_parse_msg()
4408 ahd_name(ahd), devinfo->channel, in ahd_parse_msg()
4409 devinfo->target, devinfo->lun, in ahd_parse_msg()
4424 ahd_name(ahd), devinfo->channel, in ahd_parse_msg()
4425 devinfo->target, devinfo->lun, in ahd_parse_msg()
4434 && devinfo->role == ROLE_INITIATOR) { in ahd_parse_msg()
4437 ahd_name(ahd), devinfo->channel, in ahd_parse_msg()
4438 devinfo->target, devinfo->lun); in ahd_parse_msg()
4440 ahd->msgout_index = 0; in ahd_parse_msg()
4441 ahd->msgout_len = 0; in ahd_parse_msg()
4443 ahd->msgout_index = 0; in ahd_parse_msg()
4465 ahd->msgout_index = 0; in ahd_parse_msg()
4466 ahd->msgout_len = 0; in ahd_parse_msg()
4468 ahd->msgout_index = 0; in ahd_parse_msg()
4484 if (ahd->msgin_buf[1] != MSG_EXT_PPR_LEN) { in ahd_parse_msg()
4496 if (ahd->msgin_index < (MSG_EXT_PPR_LEN + 1)) in ahd_parse_msg()
4499 period = ahd->msgin_buf[3]; in ahd_parse_msg()
4500 offset = ahd->msgin_buf[5]; in ahd_parse_msg()
4501 bus_width = ahd->msgin_buf[6]; in ahd_parse_msg()
4503 ppr_options = ahd->msgin_buf[7]; in ahd_parse_msg()
4523 devinfo->role); in ahd_parse_msg()
4525 &ppr_options, devinfo->role); in ahd_parse_msg()
4527 bus_width, devinfo->role); in ahd_parse_msg()
4545 if (devinfo->role != ROLE_TARGET) in ahd_parse_msg()
4548 ahd_name(ahd), devinfo->channel, in ahd_parse_msg()
4549 devinfo->target, devinfo->lun); in ahd_parse_msg()
4553 ahd_name(ahd), devinfo->channel, in ahd_parse_msg()
4554 devinfo->target, devinfo->lun); in ahd_parse_msg()
4555 ahd->msgout_index = 0; in ahd_parse_msg()
4556 ahd->msgout_len = 0; in ahd_parse_msg()
4559 ahd->msgout_index = 0; in ahd_parse_msg()
4567 ahd_name(ahd), devinfo->channel, in ahd_parse_msg()
4568 devinfo->target, devinfo->lun, in ahd_parse_msg()
4569 saved_width, ahd->msgin_buf[3], in ahd_parse_msg()
4607 if (devinfo->role != ROLE_TARGET) { in ahd_parse_msg()
4612 if (ahd->msgin_buf[0] == MSG_ABORT_TAG) in ahd_parse_msg()
4614 ahd_abort_scbs(ahd, devinfo->target, devinfo->channel, in ahd_parse_msg()
4615 devinfo->lun, tag, ROLE_TARGET, in ahd_parse_msg()
4618 tstate = ahd->enabled_targets[devinfo->our_scsiid]; in ahd_parse_msg()
4622 lstate = tstate->enabled_luns[devinfo->lun]; in ahd_parse_msg()
4625 devinfo->our_scsiid, in ahd_parse_msg()
4626 ahd->msgin_buf[0], in ahd_parse_msg()
4642 ahd->msg_flags |= MSG_FLAG_EXPECT_QASREJ_BUSFREE; in ahd_parse_msg()
4654 ahd->msgout_index = 0; in ahd_parse_msg()
4655 ahd->msgout_len = 1; in ahd_parse_msg()
4656 ahd->msgout_buf[0] = MSG_MESSAGE_REJECT; in ahd_parse_msg()
4663 ahd->msgout_len = 0; in ahd_parse_msg()
4689 tinfo = ahd_fetch_transinfo(ahd, devinfo->channel, in ahd_handle_msg_reject()
4690 devinfo->our_scsiid, in ahd_handle_msg_reject()
4691 devinfo->target, &tstate); in ahd_handle_msg_reject()
4697 && tinfo->goal.period <= AHD_SYNCRATE_PACED) { in ahd_handle_msg_reject()
4699 * Target may not like our SPI-4 PPR Options. in ahd_handle_msg_reject()
4706 ahd_name(ahd), devinfo->channel, in ahd_handle_msg_reject()
4707 devinfo->target, devinfo->lun); in ahd_handle_msg_reject()
4709 tinfo->goal.period = AHD_SYNCRATE_DT; in ahd_handle_msg_reject()
4710 tinfo->goal.ppr_options &= MSG_EXT_PPR_IU_REQ in ahd_handle_msg_reject()
4716 * Attempt to negotiate SPI-2 style. in ahd_handle_msg_reject()
4721 ahd_name(ahd), devinfo->channel, in ahd_handle_msg_reject()
4722 devinfo->target, devinfo->lun); in ahd_handle_msg_reject()
4724 tinfo->goal.ppr_options = 0; in ahd_handle_msg_reject()
4725 tinfo->curr.transport_version = 2; in ahd_handle_msg_reject()
4726 tinfo->goal.transport_version = 2; in ahd_handle_msg_reject()
4728 ahd->msgout_index = 0; in ahd_handle_msg_reject()
4729 ahd->msgout_len = 0; in ahd_handle_msg_reject()
4731 ahd->msgout_index = 0; in ahd_handle_msg_reject()
4737 devinfo->channel, devinfo->target, devinfo->lun); in ahd_handle_msg_reject()
4748 if (tinfo->goal.offset != tinfo->curr.offset) { in ahd_handle_msg_reject()
4750 ahd->msgout_index = 0; in ahd_handle_msg_reject()
4751 ahd->msgout_len = 0; in ahd_handle_msg_reject()
4753 ahd->msgout_index = 0; in ahd_handle_msg_reject()
4764 ahd_name(ahd), devinfo->channel, in ahd_handle_msg_reject()
4765 devinfo->target, devinfo->lun); in ahd_handle_msg_reject()
4766 } else if ((scb->hscb->control & MSG_SIMPLE_TASK) != 0) { in ahd_handle_msg_reject()
4770 tag_type = (scb->hscb->control & MSG_SIMPLE_TASK); in ahd_handle_msg_reject()
4774 "Performing non-tagged I/O\n", ahd_name(ahd), in ahd_handle_msg_reject()
4775 devinfo->channel, devinfo->target, devinfo->lun); in ahd_handle_msg_reject()
4781 ahd_name(ahd), devinfo->channel, devinfo->target, in ahd_handle_msg_reject()
4782 devinfo->lun, tag_type == MSG_ORDERED_TASK in ahd_handle_msg_reject()
4794 scb->hscb->control &= mask; in ahd_handle_msg_reject()
4799 ahd_busy_tcl(ahd, BUILD_TCL(scb->hscb->scsiid, devinfo->lun), in ahd_handle_msg_reject()
4817 ahd->msg_flags |= MSG_FLAG_EXPECT_PPR_BUSFREE in ahd_handle_msg_reject()
4821 ahd->msgout_index = 0; in ahd_handle_msg_reject()
4822 ahd->msgout_len = 0; in ahd_handle_msg_reject()
4824 ahd->msgout_index = 0; in ahd_handle_msg_reject()
4830 printf("%s:%c:%d: Message reject for %x -- ignored\n", in ahd_handle_msg_reject()
4831 ahd_name(ahd), devinfo->channel, devinfo->target, in ahd_handle_msg_reject()
4895 if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0) { in ahd_handle_ign_wide_residue()
4904 sg--; in ahd_handle_ign_wide_residue()
4905 sglen = aic_le32toh(sg->len) & AHD_SG_LEN_MASK; in ahd_handle_ign_wide_residue()
4906 if (sg != scb->sg_list in ahd_handle_ign_wide_residue()
4908 sg--; in ahd_handle_ign_wide_residue()
4909 sglen = aic_le32toh(sg->len); in ahd_handle_ign_wide_residue()
4933 sg--; in ahd_handle_ign_wide_residue()
4934 sglen = aic_le32toh(sg->len) & AHD_SG_LEN_MASK; in ahd_handle_ign_wide_residue()
4935 if (sg != scb->sg_list in ahd_handle_ign_wide_residue()
4937 sg--; in ahd_handle_ign_wide_residue()
4938 sglen = aic_le32toh(sg->len); in ahd_handle_ign_wide_residue()
4956 * to handle this mid-transfer ignore wide in ahd_handle_ign_wide_residue()
4968 * sequencer re-enters a data phase. in ahd_handle_ign_wide_residue()
5001 while (--wait && !(ahd_inb(ahd, MDFFSTAT) & FIFOFREE)) in ahd_reinitialize_dataptrs()
5025 if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0) { in ahd_reinitialize_dataptrs()
5031 sg--; in ahd_reinitialize_dataptrs()
5033 dataptr = aic_le64toh(sg->addr) in ahd_reinitialize_dataptrs()
5034 + (aic_le32toh(sg->len) & AHD_SG_LEN_MASK) in ahd_reinitialize_dataptrs()
5035 - resid; in ahd_reinitialize_dataptrs()
5043 sg--; in ahd_reinitialize_dataptrs()
5045 dataptr = aic_le32toh(sg->addr) in ahd_reinitialize_dataptrs()
5046 + (aic_le32toh(sg->len) & AHD_SG_LEN_MASK) in ahd_reinitialize_dataptrs()
5047 - resid; in ahd_reinitialize_dataptrs()
5049 (aic_le32toh(sg->len) & ~AHD_SG_LEN_MASK) >> 24); in ahd_reinitialize_dataptrs()
5070 found = ahd_abort_scbs(ahd, devinfo->target, devinfo->channel, in ahd_handle_devreset()
5071 lun, SCB_LIST_NULL, devinfo->role, in ahd_handle_devreset()
5079 tstate = ahd->enabled_targets[devinfo->our_scsiid]; in ahd_handle_devreset()
5086 max_lun = AHD_NUM_LUNS - 1; in ahd_handle_devreset()
5094 lstate = tstate->enabled_luns[cur_lun]; in ahd_handle_devreset()
5098 ahd_queue_lstate_event(ahd, lstate, devinfo->our_scsiid, in ahd_handle_devreset()
5115 ahd_send_async(ahd, devinfo->channel, devinfo->target, in ahd_handle_devreset()
5122 message, devinfo->channel, devinfo->target, found); in ahd_handle_devreset()
5137 ahd->msgout_index = 0; in ahd_setup_target_msgin()
5138 ahd->msgout_len = 0; in ahd_setup_target_msgin()
5140 if (scb != NULL && (scb->flags & SCB_AUTO_NEGOTIATE) != 0) in ahd_setup_target_msgin()
5145 ahd->msgout_index = 0; in ahd_setup_target_msgin()
5146 ahd->msg_type = MSG_TYPE_TARGET_MSGIN; in ahd_setup_target_msgin()
5156 if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0) in ahd_sglist_size()
5164 * OS will allocate full pages to us, so it doesn't make sense to request
5179 /* Get us as close as possible to a page in size. */ in ahd_sglist_allocsize()
5219 ahd->seep_config = malloc(sizeof(*ahd->seep_config), in ahd_alloc()
5221 if (ahd->seep_config == NULL) { in ahd_alloc()
5225 LIST_INIT(&ahd->pending_scbs); in ahd_alloc()
5226 LIST_INIT(&ahd->timedout_scbs); in ahd_alloc()
5228 ahd->name = name; in ahd_alloc()
5229 ahd->unit = -1; in ahd_alloc()
5230 ahd->description = NULL; in ahd_alloc()
5231 ahd->bus_description = NULL; in ahd_alloc()
5232 ahd->channel = 'A'; in ahd_alloc()
5233 ahd->chip = AHD_NONE; in ahd_alloc()
5234 ahd->features = AHD_FENONE; in ahd_alloc()
5235 ahd->bugs = AHD_BUGNONE; in ahd_alloc()
5236 ahd->flags = AHD_SPCHK_ENB_A|AHD_RESET_BUS_A|AHD_TERM_ENB_A in ahd_alloc()
5238 aic_timer_init(&ahd->reset_timer); in ahd_alloc()
5239 aic_timer_init(&ahd->stat_timer); in ahd_alloc()
5240 ahd->int_coalescing_timer = AHD_INT_COALESCING_TIMER_DEFAULT; in ahd_alloc()
5241 ahd->int_coalescing_maxcmds = AHD_INT_COALESCING_MAXCMDS_DEFAULT; in ahd_alloc()
5242 ahd->int_coalescing_mincmds = AHD_INT_COALESCING_MINCMDS_DEFAULT; in ahd_alloc()
5243 ahd->int_coalescing_threshold = AHD_INT_COALESCING_THRESHOLD_DEFAULT; in ahd_alloc()
5244 ahd->int_coalescing_stop_threshold = in ahd_alloc()
5266 ahd->unpause = 0; in ahd_softc_init()
5267 ahd->pause = PAUSE; in ahd_softc_init()
5281 if ((ahd->features & AHD_MULTI_FUNC) != 0) { in ahd_softc_insert()
5286 list_pci = list_ahd->dev_softc; in ahd_softc_insert()
5287 pci = ahd->dev_softc; in ahd_softc_insert()
5300 slave->flags &= ~AHD_BIOS_ENABLED; in ahd_softc_insert()
5301 slave->flags |= in ahd_softc_insert()
5302 master->flags & AHD_BIOS_ENABLED; in ahd_softc_insert()
5320 ahd->init_level++; in ahd_softc_insert()
5326 ahd->unit = unit; in ahd_set_unit()
5332 if (ahd->name != NULL) in ahd_set_name()
5333 free(ahd->name, M_DEVBUF); in ahd_set_name()
5334 ahd->name = name; in ahd_set_name()
5343 switch (ahd->init_level) { in ahd_free()
5349 aic_dmamap_unload(ahd, ahd->shared_data_dmat, in ahd_free()
5350 ahd->shared_data_map.dmamap); in ahd_free()
5353 aic_dmamem_free(ahd, ahd->shared_data_dmat, ahd->qoutfifo, in ahd_free()
5354 ahd->shared_data_map.dmamap); in ahd_free()
5357 aic_dma_tag_destroy(ahd, ahd->shared_data_dmat); in ahd_free()
5359 aic_dma_tag_destroy(ahd, ahd->buffer_dmat); in ahd_free()
5365 aic_dma_tag_destroy(ahd, ahd->parent_dmat); in ahd_free()
5371 tstate = ahd->enabled_targets[i]; in ahd_free()
5379 lstate = tstate->enabled_luns[j]; in ahd_free()
5381 xpt_free_path(lstate->path); in ahd_free()
5390 if (ahd->black_hole != NULL) { in ahd_free()
5391 xpt_free_path(ahd->black_hole->path); in ahd_free()
5392 free(ahd->black_hole, M_DEVBUF); in ahd_free()
5395 if (ahd->name != NULL) in ahd_free()
5396 free(ahd->name, M_DEVBUF); in ahd_free()
5397 if (ahd->seep_config != NULL) in ahd_free()
5398 free(ahd->seep_config, M_DEVBUF); in ahd_free()
5399 if (ahd->saved_stack != NULL) in ahd_free()
5400 free(ahd->saved_stack, M_DEVBUF); in ahd_free()
5414 aic_timer_stop(&ahd->reset_timer); in ahd_shutdown()
5415 aic_timer_stop(&ahd->stat_timer); in ahd_shutdown()
5424 * non-zero, this reset occurred after initial configuration
5447 cmd = aic_pci_read_config(ahd->dev_softc, PCIR_COMMAND, /*bytes*/2); in ahd_reset()
5448 if ((ahd->bugs & AHD_PCIX_CHIPRST_BUG) != 0) { in ahd_reset()
5461 aic_pci_write_config(ahd->dev_softc, PCIR_COMMAND, in ahd_reset()
5464 ahd_outb(ahd, HCNTRL, CHIPRST | ahd->pause); in ahd_reset()
5467 * Ensure that the reset has finished. We delay 1000us in ahd_reset()
5475 } while (--wait && !(ahd_inb(ahd, HCNTRL) & CHIPRSTACK)); in ahd_reset()
5478 printf("%s: WARNING - Failed chip reset! " in ahd_reset()
5482 ahd_outb(ahd, HCNTRL, ahd->pause); in ahd_reset()
5484 if ((ahd->bugs & AHD_PCIX_CHIPRST_BUG) != 0) { in ahd_reset()
5489 aic_pci_write_config(ahd->dev_softc, PCIR_STATUS + 1, in ahd_reset()
5491 aic_pci_write_config(ahd->dev_softc, PCIR_COMMAND, in ahd_reset()
5510 * to a tri-state condition which can only be cleared in ahd_reset()
5517 ahd->features &= ~AHD_WIDE; in ahd_reset()
5519 ahd->features |= AHD_WIDE; in ahd_reset()
5523 * re-initialize the chip to our liking. in ahd_reset()
5564 *baddr = segs->ds_addr; in ahd_dmamap_cb()
5572 for (i = 0; i < ahd->scb_data.maxhscbs; i++) { in ahd_initialize_hscbs()
5589 scb_data = &ahd->scb_data; in ahd_init_scbdata()
5590 TAILQ_INIT(&scb_data->free_scbs); in ahd_init_scbdata()
5592 LIST_INIT(&scb_data->free_scb_lists[i]); in ahd_init_scbdata()
5593 LIST_INIT(&scb_data->any_dev_free_scb_list); in ahd_init_scbdata()
5594 SLIST_INIT(&scb_data->hscb_maps); in ahd_init_scbdata()
5595 SLIST_INIT(&scb_data->sg_maps); in ahd_init_scbdata()
5596 SLIST_INIT(&scb_data->sense_maps); in ahd_init_scbdata()
5599 scb_data->maxhscbs = ahd_probe_scbs(ahd); in ahd_init_scbdata()
5600 if (scb_data->maxhscbs == 0) { in ahd_init_scbdata()
5619 if (aic_dma_tag_create(ahd, ahd->parent_dmat, /*alignment*/1, in ahd_init_scbdata()
5626 /*flags*/0, &scb_data->hscb_dmat) != 0) { in ahd_init_scbdata()
5630 scb_data->init_level++; in ahd_init_scbdata()
5633 if (aic_dma_tag_create(ahd, ahd->parent_dmat, /*alignment*/8, in ahd_init_scbdata()
5640 /*flags*/0, &scb_data->sg_dmat) != 0) { in ahd_init_scbdata()
5649 scb_data->init_level++; in ahd_init_scbdata()
5652 if (aic_dma_tag_create(ahd, ahd->parent_dmat, /*alignment*/1, in ahd_init_scbdata()
5659 /*flags*/0, &scb_data->sense_dmat) != 0) { in ahd_init_scbdata()
5663 scb_data->init_level++; in ahd_init_scbdata()
5669 if (scb_data->numscbs == 0) { in ahd_init_scbdata()
5670 printf("%s: ahd_init_scbdata - " in ahd_init_scbdata()
5694 LIST_FOREACH(scb, &ahd->pending_scbs, pending_links) { in ahd_find_scb_by_tag()
5702 TAILQ_FOREACH(scb, &ahd->scb_data.free_scbs, links.tqe) { in ahd_find_scb_by_tag()
5716 LIST_FOREACH(scb, &ahd->scb_data.any_dev_free_scb_list, links.le) { in ahd_find_scb_by_tag()
5729 scb_data = &ahd->scb_data; in ahd_fini_scbdata()
5733 switch (scb_data->init_level) { in ahd_fini_scbdata()
5739 while ((sns_map = SLIST_FIRST(&scb_data->sense_maps)) != NULL) { in ahd_fini_scbdata()
5740 SLIST_REMOVE_HEAD(&scb_data->sense_maps, links); in ahd_fini_scbdata()
5741 aic_dmamap_unload(ahd, scb_data->sense_dmat, in ahd_fini_scbdata()
5742 sns_map->dmamap); in ahd_fini_scbdata()
5743 aic_dmamem_free(ahd, scb_data->sense_dmat, in ahd_fini_scbdata()
5744 sns_map->vaddr, sns_map->dmamap); in ahd_fini_scbdata()
5747 aic_dma_tag_destroy(ahd, scb_data->sense_dmat); in ahd_fini_scbdata()
5754 while ((sg_map = SLIST_FIRST(&scb_data->sg_maps)) != NULL) { in ahd_fini_scbdata()
5755 SLIST_REMOVE_HEAD(&scb_data->sg_maps, links); in ahd_fini_scbdata()
5756 aic_dmamap_unload(ahd, scb_data->sg_dmat, in ahd_fini_scbdata()
5757 sg_map->dmamap); in ahd_fini_scbdata()
5758 aic_dmamem_free(ahd, scb_data->sg_dmat, in ahd_fini_scbdata()
5759 sg_map->vaddr, sg_map->dmamap); in ahd_fini_scbdata()
5762 aic_dma_tag_destroy(ahd, scb_data->sg_dmat); in ahd_fini_scbdata()
5769 while ((hscb_map = SLIST_FIRST(&scb_data->hscb_maps)) != NULL) { in ahd_fini_scbdata()
5770 SLIST_REMOVE_HEAD(&scb_data->hscb_maps, links); in ahd_fini_scbdata()
5771 aic_dmamap_unload(ahd, scb_data->hscb_dmat, in ahd_fini_scbdata()
5772 hscb_map->dmamap); in ahd_fini_scbdata()
5773 aic_dmamem_free(ahd, scb_data->hscb_dmat, in ahd_fini_scbdata()
5774 hscb_map->vaddr, hscb_map->dmamap); in ahd_fini_scbdata()
5777 aic_dma_tag_destroy(ahd, scb_data->hscb_dmat); in ahd_fini_scbdata()
5808 ahd->flags &= ~AHD_HAD_FIRST_SEL; in ahd_setup_iocell_workaround()
5817 if ((ahd->flags & AHD_HAD_FIRST_SEL) != 0) in ahd_iocell_first_selection()
5838 ahd->flags |= AHD_HAD_FIRST_SEL; in ahd_iocell_first_selection()
5849 scb->flags |= SCB_ON_COL_LIST; in ahd_add_col_list()
5851 free_list = &ahd->scb_data.free_scb_lists[col_idx]; in ahd_add_col_list()
5852 free_tailq = &ahd->scb_data.free_scbs; in ahd_add_col_list()
5870 scb->flags &= ~SCB_ON_COL_LIST; in ahd_rem_col_list()
5872 free_list = &ahd->scb_data.free_scb_lists[col_idx]; in ahd_rem_col_list()
5873 free_tailq = &ahd->scb_data.free_scbs; in ahd_rem_col_list()
5904 TAILQ_FOREACH(scb, &ahd->scb_data.free_scbs, links.tqe) { in ahd_get_scb()
5910 if ((scb = LIST_FIRST(&ahd->scb_data.any_dev_free_scb_list)) == NULL) { in ahd_get_scb()
5919 && (scb->col_scb != NULL) in ahd_get_scb()
5920 && (scb->col_scb->flags & SCB_ACTIVE) == 0) { in ahd_get_scb()
5921 LIST_REMOVE(scb->col_scb, links.le); in ahd_get_scb()
5922 ahd_add_col_list(ahd, scb->col_scb, col_idx); in ahd_get_scb()
5925 scb->flags |= SCB_ACTIVE; in ahd_get_scb()
5937 scb->flags = SCB_FLAG_NONE; in ahd_free_scb()
5938 scb->hscb->control = 0; in ahd_free_scb()
5939 ahd->scb_data.scbindex[SCB_GET_TAG(scb)] = NULL; in ahd_free_scb()
5941 if (scb->col_scb == NULL) { in ahd_free_scb()
5945 LIST_INSERT_HEAD(&ahd->scb_data.any_dev_free_scb_list, in ahd_free_scb()
5947 } else if ((scb->col_scb->flags & SCB_ON_COL_LIST) != 0) { in ahd_free_scb()
5953 ahd_rem_col_list(ahd, scb->col_scb); in ahd_free_scb()
5954 LIST_INSERT_HEAD(&ahd->scb_data.any_dev_free_scb_list, in ahd_free_scb()
5956 LIST_INSERT_HEAD(&ahd->scb_data.any_dev_free_scb_list, in ahd_free_scb()
5957 scb->col_scb, links.le); in ahd_free_scb()
5958 } else if ((scb->col_scb->flags in ahd_free_scb()
5960 && (scb->col_scb->hscb->control & TAG_ENB) != 0) { in ahd_free_scb()
5963 * is still active in a non-packetized, tagged, context. in ahd_free_scb()
5964 * Put us on the SCB collision list. in ahd_free_scb()
5967 AHD_GET_SCB_COL_IDX(ahd, scb->col_scb)); in ahd_free_scb()
5975 LIST_INSERT_HEAD(&ahd->scb_data.any_dev_free_scb_list, in ahd_free_scb()
5999 scb_data = &ahd->scb_data; in ahd_alloc_scbs()
6000 if (scb_data->numscbs >= AHD_SCB_MAX_ALLOC) in ahd_alloc_scbs()
6004 if (scb_data->scbs_left != 0) { in ahd_alloc_scbs()
6007 offset = (PAGE_SIZE / sizeof(*hscb)) - scb_data->scbs_left; in ahd_alloc_scbs()
6008 hscb_map = SLIST_FIRST(&scb_data->hscb_maps); in ahd_alloc_scbs()
6009 hscb = &((struct hardware_scb *)hscb_map->vaddr)[offset]; in ahd_alloc_scbs()
6010 hscb_busaddr = hscb_map->busaddr + (offset * sizeof(*hscb)); in ahd_alloc_scbs()
6018 if (aic_dmamem_alloc(ahd, scb_data->hscb_dmat, in ahd_alloc_scbs()
6019 (void **)&hscb_map->vaddr, in ahd_alloc_scbs()
6021 &hscb_map->dmamap) != 0) { in ahd_alloc_scbs()
6026 SLIST_INSERT_HEAD(&scb_data->hscb_maps, hscb_map, links); in ahd_alloc_scbs()
6028 aic_dmamap_load(ahd, scb_data->hscb_dmat, hscb_map->dmamap, in ahd_alloc_scbs()
6029 hscb_map->vaddr, PAGE_SIZE, ahd_dmamap_cb, in ahd_alloc_scbs()
6030 &hscb_map->busaddr, /*flags*/0); in ahd_alloc_scbs()
6032 hscb = (struct hardware_scb *)hscb_map->vaddr; in ahd_alloc_scbs()
6033 hscb_busaddr = hscb_map->busaddr; in ahd_alloc_scbs()
6034 scb_data->scbs_left = PAGE_SIZE / sizeof(*hscb); in ahd_alloc_scbs()
6037 if (scb_data->sgs_left != 0) { in ahd_alloc_scbs()
6041 - scb_data->sgs_left) * ahd_sglist_size(ahd); in ahd_alloc_scbs()
6042 sg_map = SLIST_FIRST(&scb_data->sg_maps); in ahd_alloc_scbs()
6043 segs = sg_map->vaddr + offset; in ahd_alloc_scbs()
6044 sg_busaddr = sg_map->busaddr + offset; in ahd_alloc_scbs()
6052 if (aic_dmamem_alloc(ahd, scb_data->sg_dmat, in ahd_alloc_scbs()
6053 (void **)&sg_map->vaddr, in ahd_alloc_scbs()
6055 &sg_map->dmamap) != 0) { in ahd_alloc_scbs()
6060 SLIST_INSERT_HEAD(&scb_data->sg_maps, sg_map, links); in ahd_alloc_scbs()
6062 aic_dmamap_load(ahd, scb_data->sg_dmat, sg_map->dmamap, in ahd_alloc_scbs()
6063 sg_map->vaddr, ahd_sglist_allocsize(ahd), in ahd_alloc_scbs()
6064 ahd_dmamap_cb, &sg_map->busaddr, /*flags*/0); in ahd_alloc_scbs()
6066 segs = sg_map->vaddr; in ahd_alloc_scbs()
6067 sg_busaddr = sg_map->busaddr; in ahd_alloc_scbs()
6068 scb_data->sgs_left = in ahd_alloc_scbs()
6076 if (scb_data->sense_left != 0) { in ahd_alloc_scbs()
6079 offset = PAGE_SIZE - (AHD_SENSE_BUFSIZE * scb_data->sense_left); in ahd_alloc_scbs()
6080 sense_map = SLIST_FIRST(&scb_data->sense_maps); in ahd_alloc_scbs()
6081 sense_data = sense_map->vaddr + offset; in ahd_alloc_scbs()
6082 sense_busaddr = sense_map->busaddr + offset; in ahd_alloc_scbs()
6090 if (aic_dmamem_alloc(ahd, scb_data->sense_dmat, in ahd_alloc_scbs()
6091 (void **)&sense_map->vaddr, in ahd_alloc_scbs()
6092 BUS_DMA_NOWAIT, &sense_map->dmamap) != 0) { in ahd_alloc_scbs()
6097 SLIST_INSERT_HEAD(&scb_data->sense_maps, sense_map, links); in ahd_alloc_scbs()
6099 aic_dmamap_load(ahd, scb_data->sense_dmat, sense_map->dmamap, in ahd_alloc_scbs()
6100 sense_map->vaddr, PAGE_SIZE, ahd_dmamap_cb, in ahd_alloc_scbs()
6101 &sense_map->busaddr, /*flags*/0); in ahd_alloc_scbs()
6103 sense_data = sense_map->vaddr; in ahd_alloc_scbs()
6104 sense_busaddr = sense_map->busaddr; in ahd_alloc_scbs()
6105 scb_data->sense_left = PAGE_SIZE / AHD_SENSE_BUFSIZE; in ahd_alloc_scbs()
6112 newcount = MIN(scb_data->sense_left, scb_data->scbs_left); in ahd_alloc_scbs()
6113 newcount = MIN(newcount, scb_data->sgs_left); in ahd_alloc_scbs()
6114 newcount = MIN(newcount, (AHD_SCB_MAX_ALLOC - scb_data->numscbs)); in ahd_alloc_scbs()
6115 scb_data->sense_left -= newcount; in ahd_alloc_scbs()
6116 scb_data->scbs_left -= newcount; in ahd_alloc_scbs()
6117 scb_data->sgs_left -= newcount; in ahd_alloc_scbs()
6134 next_scb->platform_data = pdata; in ahd_alloc_scbs()
6135 next_scb->hscb_map = hscb_map; in ahd_alloc_scbs()
6136 next_scb->sg_map = sg_map; in ahd_alloc_scbs()
6137 next_scb->sense_map = sense_map; in ahd_alloc_scbs()
6138 next_scb->sg_list = segs; in ahd_alloc_scbs()
6139 next_scb->sense_data = sense_data; in ahd_alloc_scbs()
6140 next_scb->sense_busaddr = sense_busaddr; in ahd_alloc_scbs()
6142 next_scb->hscb = hscb; in ahd_alloc_scbs()
6143 hscb->hscb_busaddr = aic_htole32(hscb_busaddr); in ahd_alloc_scbs()
6149 next_scb->sg_list_busaddr = sg_busaddr; in ahd_alloc_scbs()
6150 if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0) in ahd_alloc_scbs()
6151 next_scb->sg_list_busaddr in ahd_alloc_scbs()
6154 next_scb->sg_list_busaddr += sizeof(struct ahd_dma_seg); in ahd_alloc_scbs()
6155 next_scb->ahd_softc = ahd; in ahd_alloc_scbs()
6156 next_scb->flags = SCB_FLAG_NONE; in ahd_alloc_scbs()
6157 error = aic_dmamap_create(ahd, ahd->buffer_dmat, /*flags*/0, in ahd_alloc_scbs()
6158 &next_scb->dmamap); in ahd_alloc_scbs()
6165 next_scb->hscb->tag = aic_htole16(scb_data->numscbs); in ahd_alloc_scbs()
6166 col_tag = scb_data->numscbs ^ 0x100; in ahd_alloc_scbs()
6167 next_scb->col_scb = ahd_find_scb_by_tag(ahd, col_tag); in ahd_alloc_scbs()
6168 if (next_scb->col_scb != NULL) in ahd_alloc_scbs()
6169 next_scb->col_scb->col_scb = next_scb; in ahd_alloc_scbs()
6170 aic_timer_init(&next_scb->io_timer); in ahd_alloc_scbs()
6178 scb_data->numscbs++; in ahd_alloc_scbs()
6190 len = sprintf(buf, "%s: ", ahd_chip_names[ahd->chip & AHD_CHIPID_MASK]); in ahd_controller_info()
6194 if ((ahd->features & AHD_WIDE) != 0) { in ahd_controller_info()
6200 speed, type, ahd->channel, ahd->our_id); in ahd_controller_info()
6203 sprintf(buf, "%s, %d SCBs", ahd->bus_description, in ahd_controller_info()
6204 ahd->scb_data.maxhscbs); in ahd_controller_info()
6241 ahd->stack_size = ahd_probe_stack_size(ahd); in ahd_init()
6242 ahd->saved_stack = malloc(ahd->stack_size * sizeof(uint16_t), in ahd_init()
6244 if (ahd->saved_stack == NULL) in ahd_init()
6248 * Verify that the compiler hasn't over-agressively in ahd_init()
6256 ahd->flags |= AHD_SEQUENCER_DEBUG; in ahd_init()
6262 ahd->flags |= AHD_INITIATORROLE; in ahd_init()
6268 tmode_enable = ((AHD_TMODE_ENABLE & (0x1 << ahd->unit)) != 0); in ahd_init()
6269 resource_int_value(device_get_name(ahd->dev_softc), in ahd_init()
6270 device_get_unit(ahd->dev_softc), in ahd_init()
6274 ahd->features &= ~AHD_TARGETMODE; in ahd_init()
6276 if (bootverbose && ((ahd->features & AHD_TARGETMODE) != 0)) in ahd_init()
6281 ahd->features &= ~AHD_TARGETMODE; in ahd_init()
6285 if (aic_dma_tag_create(ahd, ahd->parent_dmat, /*alignment*/1, in ahd_init()
6287 /*lowaddr*/ahd->flags & AHD_39BIT_ADDRESSING in ahd_init()
6292 /*maxsize*/(AHD_NSEG - 1) * PAGE_SIZE, in ahd_init()
6296 &ahd->buffer_dmat) != 0) { in ahd_init()
6300 ahd->init_level++; in ahd_init()
6309 driver_data_size = AHD_SCB_MAX * sizeof(*ahd->qoutfifo) in ahd_init()
6311 if ((ahd->features & AHD_TARGETMODE) != 0) in ahd_init()
6313 if ((ahd->bugs & AHD_PKT_BITBUCKET_BUG) != 0) in ahd_init()
6315 if (aic_dma_tag_create(ahd, ahd->parent_dmat, /*alignment*/1, in ahd_init()
6323 /*flags*/0, &ahd->shared_data_dmat) != 0) { in ahd_init()
6327 ahd->init_level++; in ahd_init()
6330 if (aic_dmamem_alloc(ahd, ahd->shared_data_dmat, in ahd_init()
6331 (void **)&ahd->shared_data_map.vaddr, in ahd_init()
6333 &ahd->shared_data_map.dmamap) != 0) { in ahd_init()
6337 ahd->init_level++; in ahd_init()
6340 aic_dmamap_load(ahd, ahd->shared_data_dmat, ahd->shared_data_map.dmamap, in ahd_init()
6341 ahd->shared_data_map.vaddr, driver_data_size, in ahd_init()
6342 ahd_dmamap_cb, &ahd->shared_data_map.busaddr, in ahd_init()
6344 ahd->qoutfifo = (struct ahd_completion *)ahd->shared_data_map.vaddr; in ahd_init()
6345 next_vaddr = (uint8_t *)&ahd->qoutfifo[AHD_QOUT_SIZE]; in ahd_init()
6346 next_baddr = ahd->shared_data_map.busaddr in ahd_init()
6348 if ((ahd->features & AHD_TARGETMODE) != 0) { in ahd_init()
6349 ahd->targetcmds = (struct target_cmd *)next_vaddr; in ahd_init()
6354 if ((ahd->bugs & AHD_PKT_BITBUCKET_BUG) != 0) { in ahd_init()
6355 ahd->overrun_buf = next_vaddr; in ahd_init()
6367 ahd->next_queued_hscb = (struct hardware_scb *)next_vaddr; in ahd_init()
6368 ahd->next_queued_hscb_map = &ahd->shared_data_map; in ahd_init()
6369 ahd->next_queued_hscb->hscb_busaddr = aic_htole32(next_baddr); in ahd_init()
6371 ahd->init_level++; in ahd_init()
6377 if ((ahd->flags & AHD_INITIATORROLE) == 0) in ahd_init()
6378 ahd->flags &= ~AHD_RESET_BUS_A; in ahd_init()
6391 if ((ahd->flags & AHD_CURRENT_SENSING) == 0) in ahd_init()
6405 (fstat & FLX_FSTAT_BUSY) != 0 && i; i--) { in ahd_init()
6414 printf("%s: Timedout during current-sensing test\n", in ahd_init()
6461 aic_timer_reset(&ahd->stat_timer, AHD_STAT_UPDATE_MS, in ahd_init()
6488 ahd->hs_mailbox = 0; in ahd_chip_init()
6492 ahd_outb(ahd, IOWNID, ahd->our_id); in ahd_chip_init()
6493 ahd_outb(ahd, TOWNID, ahd->our_id); in ahd_chip_init()
6494 sxfrctl1 = (ahd->flags & AHD_TERM_ENB_A) != 0 ? STPWEN : 0; in ahd_chip_init()
6495 sxfrctl1 |= (ahd->flags & AHD_SPCHK_ENB_A) != 0 ? ENSPCHK : 0; in ahd_chip_init()
6496 if ((ahd->bugs & AHD_LONG_SETIMO_BUG) in ahd_chip_init()
6497 && (ahd->seltime != STIMESEL_MIN)) { in ahd_chip_init()
6503 sxfrctl1 |= ahd->seltime + STIMESEL_BUG_ADJ; in ahd_chip_init()
6505 sxfrctl1 |= ahd->seltime; in ahd_chip_init()
6509 ahd_outb(ahd, SXFRCTL1, sxfrctl1|ahd->seltime|ENSTIMER|ACTNEGEN); in ahd_chip_init()
6521 wait--) in ahd_chip_init()
6544 if ((ahd->bugs & AHD_BUSFREEREV_BUG) != 0) { in ahd_chip_init()
6550 if ((ahd->chip & AHD_BUS_MASK) == AHD_PCIX) in ahd_chip_init()
6558 if ((ahd->bugs & AHD_LQOOVERRUN_BUG) != 0) in ahd_chip_init()
6564 if ((ahd->flags & AHD_HP_BOARD) != 0) { in ahd_chip_init()
6603 if ((ahd->bugs & AHD_PKT_LUN_BUG) != 0) { in ahd_chip_init()
6618 if ((ahd->bugs & AHD_PKT_LUN_BUG) != 0) { in ahd_chip_init()
6620 sizeof(ahd->next_queued_hscb->pkt_long_lun) - 1); in ahd_chip_init()
6624 ahd_outb(ahd, CDBLIMIT, SCB_CDB_LEN_PTR - 1); in ahd_chip_init()
6635 if ((ahd->features & AHD_NEW_IOCELL_OPTS) == 0) { in ahd_chip_init()
6652 tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id, in ahd_chip_init()
6654 ahd_compile_devinfo(&devinfo, ahd->our_id, in ahd_chip_init()
6657 ahd_update_neg_table(ahd, &devinfo, &tinfo->curr); in ahd_chip_init()
6668 if ((ahd->bugs & AHD_ABORT_LQI_BUG) == 0) in ahd_chip_init()
6675 ahd->qoutfifonext = 0; in ahd_chip_init()
6676 ahd->qoutfifonext_valid_tag = QOUTFIFO_ENTRY_VALID; in ahd_chip_init()
6679 ahd->qoutfifo[i].valid_tag = 0; in ahd_chip_init()
6682 ahd->qinfifonext = 0; in ahd_chip_init()
6684 ahd->qinfifo[i] = SCB_LIST_NULL; in ahd_chip_init()
6686 if ((ahd->features & AHD_TARGETMODE) != 0) { in ahd_chip_init()
6689 ahd->targetcmds[i].cmd_valid = 0; in ahd_chip_init()
6691 ahd->tqinfifonext = 1; in ahd_chip_init()
6692 ahd_outb(ahd, KERNEL_TQINPOS, ahd->tqinfifonext - 1); in ahd_chip_init()
6693 ahd_outb(ahd, TQINPOS, ahd->tqinfifonext); in ahd_chip_init()
6720 ahd->qfreeze_cnt = 0; in ahd_chip_init()
6727 busaddr = ahd->shared_data_map.busaddr; in ahd_chip_init()
6737 if ((ahd->flags & AHD_INITIATORROLE) != 0) in ahd_chip_init()
6767 ahd->qinfifonext = 0; in ahd_chip_init()
6768 ahd_set_hnscb_qoff(ahd, ahd->qinfifonext); in ahd_chip_init()
6777 busaddr = aic_le32toh(ahd->next_queued_hscb->hscb_busaddr); in ahd_chip_init()
6785 ahd_update_coalescing_values(ahd, ahd->int_coalescing_timer, in ahd_chip_init()
6786 ahd->int_coalescing_maxcmds, in ahd_chip_init()
6787 ahd->int_coalescing_mincmds); in ahd_chip_init()
6804 ahd->our_id = 7; in ahd_default_config()
6811 if (ahd_alloc_tstate(ahd, ahd->our_id, 'A') == NULL) { in ahd_default_config()
6824 tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id, in ahd_default_config()
6829 tinfo->user.protocol_version = 4; in ahd_default_config()
6830 tinfo->user.transport_version = 4; in ahd_default_config()
6833 ahd->user_discenable |= target_mask; in ahd_default_config()
6834 tstate->discenable |= target_mask; in ahd_default_config()
6835 ahd->user_tagenable |= target_mask; in ahd_default_config()
6837 tinfo->user.period = AHD_SYNCRATE_DT; in ahd_default_config()
6839 tinfo->user.period = AHD_SYNCRATE_160; in ahd_default_config()
6841 tinfo->user.offset = MAX_OFFSET; in ahd_default_config()
6842 tinfo->user.ppr_options = MSG_EXT_PPR_RD_STRM in ahd_default_config()
6848 if ((ahd->features & AHD_RTI) != 0) in ahd_default_config()
6849 tinfo->user.ppr_options |= MSG_EXT_PPR_RTI; in ahd_default_config()
6851 tinfo->user.width = MSG_EXT_WDTR_BUS_16_BIT; in ahd_default_config()
6857 tinfo->goal.protocol_version = 2; in ahd_default_config()
6858 tinfo->goal.transport_version = 2; in ahd_default_config()
6859 tinfo->curr.protocol_version = 2; in ahd_default_config()
6860 tinfo->curr.transport_version = 2; in ahd_default_config()
6861 ahd_compile_devinfo(&devinfo, ahd->our_id, in ahd_default_config()
6864 tstate->tagenable &= ~target_mask; in ahd_default_config()
6883 max_targ = sc->max_targets & CFMAXTARG; in ahd_parse_cfgdata()
6884 ahd->our_id = sc->brtime_id & CFSCSIID; in ahd_parse_cfgdata()
6891 if (ahd_alloc_tstate(ahd, ahd->our_id, 'A') == NULL) { in ahd_parse_cfgdata()
6905 tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id, in ahd_parse_cfgdata()
6907 user_tinfo = &tinfo->user; in ahd_parse_cfgdata()
6912 tinfo->user.protocol_version = 4; in ahd_parse_cfgdata()
6913 tinfo->user.transport_version = 4; in ahd_parse_cfgdata()
6916 ahd->user_discenable &= ~target_mask; in ahd_parse_cfgdata()
6917 tstate->discenable &= ~target_mask; in ahd_parse_cfgdata()
6918 ahd->user_tagenable &= ~target_mask; in ahd_parse_cfgdata()
6919 if (sc->device_flags[targ] & CFDISC) { in ahd_parse_cfgdata()
6920 tstate->discenable |= target_mask; in ahd_parse_cfgdata()
6921 ahd->user_discenable |= target_mask; in ahd_parse_cfgdata()
6922 ahd->user_tagenable |= target_mask; in ahd_parse_cfgdata()
6927 sc->device_flags[targ] &= ~CFPACKETIZED; in ahd_parse_cfgdata()
6930 user_tinfo->ppr_options = 0; in ahd_parse_cfgdata()
6931 user_tinfo->period = (sc->device_flags[targ] & CFXFER); in ahd_parse_cfgdata()
6932 if (user_tinfo->period < CFXFER_ASYNC) { in ahd_parse_cfgdata()
6933 if (user_tinfo->period <= AHD_PERIOD_10MHz) in ahd_parse_cfgdata()
6934 user_tinfo->ppr_options |= MSG_EXT_PPR_DT_REQ; in ahd_parse_cfgdata()
6935 user_tinfo->offset = MAX_OFFSET; in ahd_parse_cfgdata()
6937 user_tinfo->offset = 0; in ahd_parse_cfgdata()
6938 user_tinfo->period = AHD_ASYNC_XFER_PERIOD; in ahd_parse_cfgdata()
6941 if (user_tinfo->period <= AHD_SYNCRATE_160) in ahd_parse_cfgdata()
6942 user_tinfo->period = AHD_SYNCRATE_DT; in ahd_parse_cfgdata()
6945 if ((sc->device_flags[targ] & CFPACKETIZED) != 0) { in ahd_parse_cfgdata()
6946 user_tinfo->ppr_options |= MSG_EXT_PPR_RD_STRM in ahd_parse_cfgdata()
6950 if ((ahd->features & AHD_RTI) != 0) in ahd_parse_cfgdata()
6951 user_tinfo->ppr_options |= MSG_EXT_PPR_RTI; in ahd_parse_cfgdata()
6954 if ((sc->device_flags[targ] & CFQAS) != 0) in ahd_parse_cfgdata()
6955 user_tinfo->ppr_options |= MSG_EXT_PPR_QAS_REQ; in ahd_parse_cfgdata()
6957 if ((sc->device_flags[targ] & CFWIDEB) != 0) in ahd_parse_cfgdata()
6958 user_tinfo->width = MSG_EXT_WDTR_BUS_16_BIT; in ahd_parse_cfgdata()
6960 user_tinfo->width = MSG_EXT_WDTR_BUS_8_BIT; in ahd_parse_cfgdata()
6963 printf("(%d): %x:%x:%x:%x\n", targ, user_tinfo->width, in ahd_parse_cfgdata()
6964 user_tinfo->period, user_tinfo->offset, in ahd_parse_cfgdata()
6965 user_tinfo->ppr_options); in ahd_parse_cfgdata()
6971 tstate->tagenable &= ~target_mask; in ahd_parse_cfgdata()
6972 tinfo->goal.protocol_version = 2; in ahd_parse_cfgdata()
6973 tinfo->goal.transport_version = 2; in ahd_parse_cfgdata()
6974 tinfo->curr.protocol_version = 2; in ahd_parse_cfgdata()
6975 tinfo->curr.transport_version = 2; in ahd_parse_cfgdata()
6976 ahd_compile_devinfo(&devinfo, ahd->our_id, in ahd_parse_cfgdata()
6986 ahd->flags &= ~AHD_SPCHK_ENB_A; in ahd_parse_cfgdata()
6987 if (sc->bios_control & CFSPARITY) in ahd_parse_cfgdata()
6988 ahd->flags |= AHD_SPCHK_ENB_A; in ahd_parse_cfgdata()
6990 ahd->flags &= ~AHD_RESET_BUS_A; in ahd_parse_cfgdata()
6991 if (sc->bios_control & CFRESETB) in ahd_parse_cfgdata()
6992 ahd->flags |= AHD_RESET_BUS_A; in ahd_parse_cfgdata()
6994 ahd->flags &= ~AHD_EXTENDED_TRANS_A; in ahd_parse_cfgdata()
6995 if (sc->bios_control & CFEXTEND) in ahd_parse_cfgdata()
6996 ahd->flags |= AHD_EXTENDED_TRANS_A; in ahd_parse_cfgdata()
6998 ahd->flags &= ~AHD_BIOS_ENABLED; in ahd_parse_cfgdata()
6999 if ((sc->bios_control & CFBIOSSTATE) == CFBS_ENABLED) in ahd_parse_cfgdata()
7000 ahd->flags |= AHD_BIOS_ENABLED; in ahd_parse_cfgdata()
7002 ahd->flags &= ~AHD_STPWLEVEL_A; in ahd_parse_cfgdata()
7003 if ((sc->adapter_control & CFSTPWLEVEL) != 0) in ahd_parse_cfgdata()
7004 ahd->flags |= AHD_STPWLEVEL_A; in ahd_parse_cfgdata()
7020 if ((vpd->bios_flags & VPDBOOTHOST) != 0) in ahd_parse_vpddata()
7021 ahd->flags |= AHD_BOOT_CHANNEL; in ahd_parse_vpddata()
7032 ahd->pause &= ~INTEN; in ahd_intr_enable()
7033 ahd->unpause &= ~INTEN; in ahd_intr_enable()
7036 ahd->pause |= INTEN; in ahd_intr_enable()
7037 ahd->unpause |= INTEN; in ahd_intr_enable()
7048 ahd->int_coalescing_timer = timer; in ahd_update_coalescing_values()
7054 ahd->int_coalescing_maxcmds = maxcmds; in ahd_update_coalescing_values()
7056 ahd_outb(ahd, INT_COALESCING_MAXCMDS, -maxcmds); in ahd_update_coalescing_values()
7057 ahd_outb(ahd, INT_COALESCING_MINCMDS, -mincmds); in ahd_update_coalescing_values()
7064 ahd->hs_mailbox &= ~ENINT_COALESCE; in ahd_enable_coalescing()
7066 ahd->hs_mailbox |= ENINT_COALESCE; in ahd_enable_coalescing()
7067 ahd_outb(ahd, HS_MAILBOX, ahd->hs_mailbox); in ahd_enable_coalescing()
7086 ahd->flags |= AHD_ALL_INTERRUPTS; in ahd_pause_and_flushwork()
7093 ahd->qfreeze_cnt--; in ahd_pause_and_flushwork()
7094 ahd_outw(ahd, KERNEL_QFREEZE_COUNT, ahd->qfreeze_cnt); in ahd_pause_and_flushwork()
7111 } while (--maxloops in ahd_pause_and_flushwork()
7112 && (intstat != 0xFF || (ahd->features & AHD_REMOVABLE) == 0) in ahd_pause_and_flushwork()
7122 ahd->qfreeze_cnt++; in ahd_pause_and_flushwork()
7123 ahd_outw(ahd, KERNEL_QFREEZE_COUNT, ahd->qfreeze_cnt); in ahd_pause_and_flushwork()
7128 ahd->flags &= ~AHD_ALL_INTERRUPTS; in ahd_pause_and_flushwork()
7137 if (LIST_FIRST(&ahd->pending_scbs) != NULL) { in ahd_suspend()
7229 group = XPT_FC_GROUP(scb->io_ctx->ccb_h.func_code); in ahd_match_scb()
7236 && ((tag == scb->io_ctx->csio.tag_id) in ahd_match_scb()
7278 prev_pos = AHD_QIN_WRAP(ahd->qinfifonext - 1); in ahd_qinfifo_requeue_tail()
7279 prev_tag = ahd->qinfifo[prev_pos]; in ahd_qinfifo_requeue_tail()
7283 ahd_set_hnscb_qoff(ahd, ahd->qinfifonext); in ahd_qinfifo_requeue_tail()
7294 busaddr = aic_le32toh(scb->hscb->hscb_busaddr); in ahd_qinfifo_requeue()
7297 prev_scb->hscb->next_hscb_busaddr = scb->hscb->hscb_busaddr; in ahd_qinfifo_requeue()
7301 ahd->qinfifo[AHD_QIN_WRAP(ahd->qinfifonext)] = SCB_GET_TAG(scb); in ahd_qinfifo_requeue()
7302 ahd->qinfifonext++; in ahd_qinfifo_requeue()
7303 scb->hscb->next_hscb_busaddr = ahd->next_queued_hscb->hscb_busaddr; in ahd_qinfifo_requeue()
7317 wrap_qinfifonext = AHD_QIN_WRAP(ahd->qinfifonext); in ahd_qinfifo_count()
7319 return (wrap_qinfifonext - wrap_qinpos); in ahd_qinfifo_count()
7322 + NUM_ELEMENTS(ahd->qinfifo) - wrap_qinpos); in ahd_qinfifo_count()
7342 LIST_FOREACH(scb, &ahd->pending_scbs, pending_links) { in ahd_reset_cmds_pending()
7345 ahd_outw(ahd, CMDS_PENDING, pending_cmds - ahd_qinfifo_count(ahd)); in ahd_reset_cmds_pending()
7347 ahd->flags &= ~AHD_UPDATE_PEND_CMDS; in ahd_reset_cmds_pending()
7402 qintail = AHD_QIN_WRAP(ahd->qinfifonext); in ahd_search_qinfifo()
7410 qinstart, ahd->qinfifonext); in ahd_search_qinfifo()
7415 * for removal will be re-added to the queue as we go. in ahd_search_qinfifo()
7417 ahd->qinfifonext = qinstart; in ahd_search_qinfifo()
7418 busaddr = aic_le32toh(ahd->next_queued_hscb->hscb_busaddr); in ahd_search_qinfifo()
7422 scb = ahd_lookup_scb(ahd, ahd->qinfifo[qinpos]); in ahd_search_qinfifo()
7425 qinpos, ahd->qinfifo[qinpos]); in ahd_search_qinfifo()
7437 if ((scb->flags & SCB_ACTIVE) == 0) in ahd_search_qinfifo()
7444 printf(" 0x%x", ahd->qinfifo[qinpos]); in ahd_search_qinfifo()
7458 ahd_set_hnscb_qoff(ahd, ahd->qinfifonext); in ahd_search_qinfifo()
7488 if (scbid >= ahd->scb_data.numscbs) { in ahd_search_qinfifo()
7491 ahd_name(ahd), scbid, ahd->scb_data.numscbs); in ahd_search_qinfifo()
7532 if ((mk_msg_scb->flags & SCB_ACTIVE) == 0) in ahd_search_qinfifo()
7544 * main per-target list. in ahd_search_qinfifo()
7553 ahd_inw(ahd, CMDS_PENDING)-1); in ahd_search_qinfifo()
7612 if (scbid >= ahd->scb_data.numscbs) { in ahd_search_scb_list()
7615 ahd_name(ahd), scbid, ahd->scb_data.numscbs); in ahd_search_scb_list()
7636 if ((scb->flags & SCB_ACTIVE) == 0) in ahd_search_scb_list()
7657 ahd_outw(ahd, CMDS_PENDING, ahd_inw(ahd, CMDS_PENDING) - found); in ahd_search_scb_list()
7820 scbp_next = LIST_FIRST(&ahd->pending_scbs); in ahd_abort_scbs()
7832 if ((scbp->flags & SCB_ACTIVE) == 0) in ahd_abort_scbs()
7840 ahd->flags |= AHD_UPDATE_PEND_CMDS; in ahd_abort_scbs()
7859 if ((ahd->bugs & AHD_SCSIRST_BUG) != 0) { in ahd_reset_current_bus()
7885 ahd->pending_device = NULL; in ahd_reset_channel()
7898 if ((ahd->flags & AHD_TARGETROLE) != 0) { in ahd_reset_channel()
7963 max_scsiid = (ahd->features & AHD_WIDE) ? 15 : 7; in ahd_reset_channel()
7965 if (ahd->enabled_targets[target] == NULL) in ahd_reset_channel()
7982 max_scsiid = (ahd->features & AHD_WIDE) ? 15 : 7; in ahd_reset_channel()
7992 tstate = ahd->enabled_targets[target]; in ahd_reset_channel()
7998 lstate = tstate->enabled_luns[lun]; in ahd_reset_channel()
8018 if ((ahd->flags & AHD_RESET_POLL_ACTIVE) == 0) { in ahd_reset_channel()
8019 ahd->flags |= AHD_RESET_POLL_ACTIVE; in ahd_reset_channel()
8021 aic_timer_reset(&ahd->reset_timer, 0, ahd_reset_poll, ahd); in ahd_reset_channel()
8039 aic_timer_reset(&ahd->reset_timer, AHD_RESET_POLL_MS, in ahd_reset_poll()
8051 ahd->flags &= ~AHD_RESET_POLL_ACTIVE; in ahd_reset_poll()
8064 enint_coal = ahd->hs_mailbox & ENINT_COALESCE; in ahd_stat_timer()
8065 if (ahd->cmdcmplt_total > ahd->int_coalescing_threshold) in ahd_stat_timer()
8067 else if (ahd->cmdcmplt_total < ahd->int_coalescing_stop_threshold) in ahd_stat_timer()
8070 if (enint_coal != (ahd->hs_mailbox & ENINT_COALESCE)) { in ahd_stat_timer()
8078 ahd->cmdcmplt_total); in ahd_stat_timer()
8082 ahd->cmdcmplt_bucket = (ahd->cmdcmplt_bucket+1) & (AHD_STAT_BUCKETS-1); in ahd_stat_timer()
8083 ahd->cmdcmplt_total -= ahd->cmdcmplt_counts[ahd->cmdcmplt_bucket]; in ahd_stat_timer()
8084 ahd->cmdcmplt_counts[ahd->cmdcmplt_bucket] = 0; in ahd_stat_timer()
8085 aic_timer_reset(&ahd->stat_timer, AHD_STAT_UPDATE_MS, in ahd_stat_timer()
8094 if (scb->hscb->shared_data.istatus.scsi_status != 0) { in ahd_handle_scb_status()
8109 * The sequencer freezes its select-out queue in ahd_handle_scsi_status()
8117 hscb = scb->hscb; in ahd_handle_scsi_status()
8129 ahd->qfreeze_cnt++; in ahd_handle_scsi_status()
8130 ahd_outw(ahd, KERNEL_QFREEZE_COUNT, ahd->qfreeze_cnt); in ahd_handle_scsi_status()
8136 if ((scb->flags & SCB_SENSE) != 0) { in ahd_handle_scsi_status()
8141 scb->flags &= ~SCB_SENSE; in ahd_handle_scsi_status()
8147 aic_set_scsi_status(scb, hscb->shared_data.istatus.scsi_status); in ahd_handle_scsi_status()
8148 switch (hscb->shared_data.istatus.scsi_status) { in ahd_handle_scsi_status()
8154 siu = (struct scsi_status_iu_header *)scb->sense_data; in ahd_handle_scsi_status()
8155 aic_set_scsi_status(scb, siu->status); in ahd_handle_scsi_status()
8160 SCB_GET_TAG(scb), siu->status); in ahd_handle_scsi_status()
8163 siu->flags, scsi_4btoul(siu->sense_length), in ahd_handle_scsi_status()
8164 scsi_4btoul(siu->pkt_failures_length)); in ahd_handle_scsi_status()
8167 if ((siu->flags & SIU_RSPVALID) != 0) { in ahd_handle_scsi_status()
8169 if (scsi_4btoul(siu->pkt_failures_length) < 4) { in ahd_handle_scsi_status()
8200 if (siu->status == SCSI_STATUS_OK) in ahd_handle_scsi_status()
8204 if ((siu->flags & SIU_SNSVALID) != 0) { in ahd_handle_scsi_status()
8205 scb->flags |= SCB_PKT_SENSE; in ahd_handle_scsi_status()
8244 tinfo = &targ_info->curr; in ahd_handle_scsi_status()
8245 sg = scb->sg_list; in ahd_handle_scsi_status()
8246 sc = (struct scsi_sense *)hscb->shared_data.idata.cdb; in ahd_handle_scsi_status()
8257 scb->sg_count = 0; in ahd_handle_scsi_status()
8261 sc->opcode = REQUEST_SENSE; in ahd_handle_scsi_status()
8262 sc->byte2 = 0; in ahd_handle_scsi_status()
8263 if (tinfo->protocol_version <= SCSI_REV_2 in ahd_handle_scsi_status()
8265 sc->byte2 = SCB_GET_LUN(scb) << 5; in ahd_handle_scsi_status()
8266 sc->unused[0] = 0; in ahd_handle_scsi_status()
8267 sc->unused[1] = 0; in ahd_handle_scsi_status()
8268 sc->length = aic_get_sense_bufsize(ahd, scb); in ahd_handle_scsi_status()
8269 sc->control = 0; in ahd_handle_scsi_status()
8278 hscb->control = 0; in ahd_handle_scsi_status()
8293 if (tstate->auto_negotiate & devinfo.target_mask) { in ahd_handle_scsi_status()
8294 hscb->control |= MK_MESSAGE; in ahd_handle_scsi_status()
8295 scb->flags &= in ahd_handle_scsi_status()
8297 scb->flags |= SCB_AUTO_NEGOTIATE; in ahd_handle_scsi_status()
8299 hscb->cdb_len = sizeof(*sc); in ahd_handle_scsi_status()
8301 scb->flags |= SCB_SENSE; in ahd_handle_scsi_status()
8310 if (ahd->scb_data.recovery_scbs == 0 in ahd_handle_scsi_status()
8311 || (scb->flags & SCB_RECOVERY_SCB) != 0) in ahd_handle_scsi_status()
8353 hscb = scb->hscb; in ahd_calc_residual()
8354 sgptr = aic_le32toh(hscb->sgptr); in ahd_calc_residual()
8370 spkt = &hscb->shared_data.istatus; in ahd_calc_residual()
8371 resid_sgptr = aic_le32toh(spkt->residual_sgptr); in ahd_calc_residual()
8396 resid = aic_le32toh(spkt->residual_datacnt) & AHD_SG_LEN_MASK; in ahd_calc_residual()
8400 sg--; in ahd_calc_residual()
8407 while ((aic_le32toh(sg->len) & AHD_DMA_LAST_SEG) == 0) { in ahd_calc_residual()
8409 resid += aic_le32toh(sg->len) & AHD_SG_LEN_MASK; in ahd_calc_residual()
8412 if ((scb->flags & SCB_SENSE) == 0) in ahd_calc_residual()
8421 (scb->flags & SCB_SENSE) ? "Sense " : "", resid); in ahd_calc_residual()
8438 xpt_freeze_devq(lstate->path, /*count*/1); in ahd_queue_lstate_event()
8439 if (lstate->event_w_idx >= lstate->event_r_idx) in ahd_queue_lstate_event()
8440 pending = lstate->event_w_idx - lstate->event_r_idx; in ahd_queue_lstate_event()
8443 - (lstate->event_r_idx - lstate->event_w_idx); in ahd_queue_lstate_event()
8449 * This has the effect of allowing us to deal with reset in ahd_queue_lstate_event()
8453 lstate->event_r_idx = 0; in ahd_queue_lstate_event()
8454 lstate->event_w_idx = 0; in ahd_queue_lstate_event()
8455 xpt_release_devq(lstate->path, pending, /*runqueue*/FALSE); in ahd_queue_lstate_event()
8459 xpt_print_path(lstate->path); in ahd_queue_lstate_event()
8461 lstate->event_buffer[lstate->event_r_idx].event_type, in ahd_queue_lstate_event()
8462 lstate->event_buffer[lstate->event_r_idx].event_arg); in ahd_queue_lstate_event()
8463 lstate->event_r_idx++; in ahd_queue_lstate_event()
8464 if (lstate->event_r_idx == AHD_TMODE_EVENT_BUFFER_SIZE) in ahd_queue_lstate_event()
8465 lstate->event_r_idx = 0; in ahd_queue_lstate_event()
8466 xpt_release_devq(lstate->path, /*count*/1, /*runqueue*/FALSE); in ahd_queue_lstate_event()
8469 event = &lstate->event_buffer[lstate->event_w_idx]; in ahd_queue_lstate_event()
8470 event->initiator_id = initiator_id; in ahd_queue_lstate_event()
8471 event->event_type = event_type; in ahd_queue_lstate_event()
8472 event->event_arg = event_arg; in ahd_queue_lstate_event()
8473 lstate->event_w_idx++; in ahd_queue_lstate_event()
8474 if (lstate->event_w_idx == AHD_TMODE_EVENT_BUFFER_SIZE) in ahd_queue_lstate_event()
8475 lstate->event_w_idx = 0; in ahd_queue_lstate_event()
8488 while (lstate->event_r_idx != lstate->event_w_idx in ahd_send_lstate_events()
8489 && (ccbh = SLIST_FIRST(&lstate->immed_notifies)) != NULL) { in ahd_send_lstate_events()
8492 event = &lstate->event_buffer[lstate->event_r_idx]; in ahd_send_lstate_events()
8493 SLIST_REMOVE_HEAD(&lstate->immed_notifies, sim_links.sle); in ahd_send_lstate_events()
8495 switch (event->event_type) { in ahd_send_lstate_events()
8497 ccbh->status = CAM_SCSI_BUS_RESET|CAM_DEV_QFRZN; in ahd_send_lstate_events()
8500 ccbh->status = CAM_MESSAGE_RECV|CAM_DEV_QFRZN; in ahd_send_lstate_events()
8501 inot->arg = event->event_type; in ahd_send_lstate_events()
8502 inot->seq_id = event->event_arg; in ahd_send_lstate_events()
8505 inot->initiator_id = event->initiator_id; in ahd_send_lstate_events()
8507 lstate->event_r_idx++; in ahd_send_lstate_events()
8508 if (lstate->event_r_idx == AHD_TMODE_EVENT_BUFFER_SIZE) in ahd_send_lstate_events()
8509 lstate->event_r_idx = 0; in ahd_send_lstate_events()
8582 * just the cache size might leave us with only a portion in ahd_loadseq()
8592 sg_prefetch_align = ahd->pci_cachesize; in ahd_loadseq()
8598 cacheline_mask = sg_prefetch_align - 1; in ahd_loadseq()
8614 if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0) in ahd_loadseq()
8631 sg_prefetch_cnt_limit = -(sg_prefetch_cnt - sg_size + 1); in ahd_loadseq()
8634 download_consts[SG_PREFETCH_ALIGN_MASK] = ~(sg_prefetch_align - 1); in ahd_loadseq()
8635 download_consts[SG_PREFETCH_ADDR_MASK] = (sg_prefetch_align - 1); in ahd_loadseq()
8638 (ahd->overrun_buf - (uint8_t *)ahd->qoutfifo) / 256; in ahd_loadseq()
8680 ahd->num_critical_sections = cs_count; in ahd_loadseq()
8683 ahd->critical_sections = malloc(cs_count, M_DEVBUF, M_NOWAIT); in ahd_loadseq()
8684 if (ahd->critical_sections == NULL) in ahd_loadseq()
8686 memcpy(ahd->critical_sections, cs_table, cs_count); in ahd_loadseq()
8693 ahd_name(ahd), ahd->features, ahd->bugs, ahd->flags); in ahd_loadseq()
8709 while (cur_patch < last_patch && start_instr == cur_patch->begin) { in ahd_check_patch()
8710 if (cur_patch->patch_func(ahd) == 0) { in ahd_check_patch()
8712 *skip_addr = start_instr + cur_patch->skip_instr; in ahd_check_patch()
8713 cur_patch += cur_patch->skip_patch; in ahd_check_patch()
8750 address_offset += end_addr - i; in ahd_resolve_seqaddr()
8756 return (address - address_offset); in ahd_resolve_seqaddr()
8788 fmt3_ins->address = ahd_resolve_seqaddr(ahd, fmt3_ins->address); in ahd_download_instr()
8797 if (fmt1_ins->parity != 0) { in ahd_download_instr()
8798 fmt1_ins->immediate = dconsts[fmt1_ins->immediate]; in ahd_download_instr()
8800 fmt1_ins->parity = 0; in ahd_download_instr()
8840 * "back-fills" with zeros when "poping' in ahd_probe_stack_size()
8849 for (i = last_probe+1; i > 0; i--) { in ahd_probe_stack_size()
8950 ahd_build_mode_state(ahd, ahd->saved_src_mode, in ahd_dump_card_state()
8951 ahd->saved_dst_mode)); in ahd_dump_card_state()
9001 ahd->scb_data.numscbs, ahd_inw(ahd, CMDS_PENDING), in ahd_dump_card_state()
9012 LIST_FOREACH(scb, &ahd->pending_scbs, pending_links) { in ahd_dump_card_state()
9027 TAILQ_FOREACH(scb, &ahd->scb_data.free_scbs, links.tqe) { in ahd_dump_card_state()
9039 LIST_FOREACH(scb, &ahd->scb_data.any_dev_free_scb_list, links.le) { in ahd_dump_card_state()
9046 printf("Sequencer Complete DMA-inprog list: "); in ahd_dump_card_state()
9066 printf("Sequencer DMA-Up and Complete list: "); in ahd_dump_card_state()
9158 ahd_set_modes(ahd, ahd->saved_src_mode, ahd->saved_dst_mode); in ahd_dump_card_state()
9174 for (i = 0; i < ahd->stack_size; i++) { in ahd_dump_card_state()
9175 ahd->saved_stack[i] = in ahd_dump_card_state()
9177 printf(" 0x%x", ahd->saved_stack[i]); in ahd_dump_card_state()
9179 for (i = ahd->stack_size-1; i >= 0; i--) { in ahd_dump_card_state()
9180 ahd_outb(ahd, STACK, ahd->saved_stack[i] & 0xFF); in ahd_dump_card_state()
9181 ahd_outb(ahd, STACK, (ahd->saved_stack[i] >> 8) & 0xFF); in ahd_dump_card_state()
9222 ahd = scb->ahd_softc; in ahd_timeout()
9223 if ((scb->flags & SCB_ACTIVE) != 0) { in ahd_timeout()
9224 if ((scb->flags & SCB_TIMEDOUT) == 0) { in ahd_timeout()
9225 LIST_INSERT_HEAD(&ahd->timedout_scbs, scb, in ahd_timeout()
9227 scb->flags |= SCB_TIMEDOUT; in ahd_timeout()
9257 printf("%s: Recovery Initiated - Card was %spaused\n", ahd_name(ahd), in ahd_recover_commands()
9264 if (LIST_EMPTY(&ahd->timedout_scbs) != 0) { in ahd_recover_commands()
9270 * requires or - more likely - interrupts in ahd_recover_commands()
9281 * This test only catches non-packetized transactions. in ahd_recover_commands()
9294 while ((scb = LIST_FIRST(&ahd->timedout_scbs)) != NULL) { in ahd_recover_commands()
9304 printf("SCB %d - timed out\n", SCB_GET_TAG(scb)); in ahd_recover_commands()
9306 if (scb->flags & (SCB_DEVICE_RESET|SCB_ABORT)) { in ahd_recover_commands()
9326 scb->flags &= ~SCB_TIMEDOUT; in ahd_recover_commands()
9331 * If the active SCB is not us, assume that in ahd_recover_commands()
9336 * untimed-out command is outstanding. in ahd_recover_commands()
9349 active_scb->flags |= SCB_RECOVERY_SCB|SCB_DEVICE_RESET; in ahd_recover_commands()
9389 * Actually re-queue this SCB in an attempt in ahd_recover_commands()
9393 * timed-out device. in ahd_recover_commands()
9395 scb->flags |= SCB_DEVICE_RESET; in ahd_recover_commands()
9396 scb->hscb->cdb_len = 0; in ahd_recover_commands()
9397 scb->hscb->task_attribute = 0; in ahd_recover_commands()
9398 scb->hscb->task_management = SIU_TASKMGMT_ABORT_TASK; in ahd_recover_commands()
9401 if ((scb->flags & SCB_PACKETIZED) != 0) { in ahd_recover_commands()
9410 scb->hscb->task_management); in ahd_recover_commands()
9413 * If non-packetized, set the MK_MESSAGE control in ahd_recover_commands()
9422 scb->hscb->control |= MK_MESSAGE|DISCONNECTED; in ahd_recover_commands()
9425 * The sequencer will never re-reference the in ahd_recover_commands()
9426 * in-core SCB. To make sure we are notified in ahd_recover_commands()
9456 while ((scb = LIST_FIRST(&ahd->timedout_scbs)) != NULL) { in ahd_recover_commands()
9458 scb->flags &= ~SCB_TIMEDOUT; in ahd_recover_commands()
9465 * Re-schedule a timeout for the passed in SCB if we determine that some
9468 * if it is non-NULL.
9479 (scb->flags & SCB_OTHERTCL_TIMEOUT) != 0 in ahd_other_scb_timeout()
9484 scb->flags |= SCB_OTHERTCL_TIMEOUT; in ahd_other_scb_timeout()
9487 if ((other_scb->flags in ahd_other_scb_timeout()
9489 || (other_scb->flags & SCB_RECOVERY_SCB) != 0) { in ahd_other_scb_timeout()
9495 LIST_FOREACH(other_scb, &ahd->pending_scbs, pending_links) { in ahd_other_scb_timeout()
9496 if ((other_scb->flags in ahd_other_scb_timeout()
9498 || (other_scb->flags & SCB_RECOVERY_SCB) != 0) { in ahd_other_scb_timeout()
9579 /* Place the chip into write-enable mode */ in ahd_write_seeprom()
9614 * Wait ~100us for the serial eeprom to satisfy our request.
9622 while ((ahd_inb(ahd, SEESTAT) & (SEEARBACK|SEEBUSY)) != 0 && --cnt) in ahd_wait_seeprom()
9648 || (-checksum & 0xFF) != vpd->vpd_checksum) in ahd_verify_vpd_cksum()
9657 || (-checksum & 0xFF) != vpd->checksum) in ahd_verify_vpd_cksum()
9670 maxaddr = (sizeof(*sc)/2) - 1; in ahd_verify_cksum()
9677 || (checksum & 0xFFFF) != sc->checksum) { in ahd_verify_cksum()
9710 /* Currently a no-op */ in ahd_release_seeprom()
9764 while ((ahd_inb(ahd, BRDCTL) & FLXARBACK) == 0 && --cnt) in ahd_wait_flexport()
9781 if ((ahd->features & AHD_TARGETMODE) == 0) in ahd_find_tmode_devs()
9788 if (ccb->ccb_h.target_id == CAM_TARGET_WILDCARD in ahd_find_tmode_devs()
9789 && ccb->ccb_h.target_lun == CAM_LUN_WILDCARD) { in ahd_find_tmode_devs()
9791 *lstate = ahd->black_hole; in ahd_find_tmode_devs()
9795 max_id = (ahd->features & AHD_WIDE) ? 15 : 7; in ahd_find_tmode_devs()
9796 if (ccb->ccb_h.target_id > max_id) in ahd_find_tmode_devs()
9799 if (ccb->ccb_h.target_lun >= AHD_NUM_LUNS) in ahd_find_tmode_devs()
9802 *tstate = ahd->enabled_targets[ccb->ccb_h.target_id]; in ahd_find_tmode_devs()
9806 (*tstate)->enabled_luns[ccb->ccb_h.target_lun]; in ahd_find_tmode_devs()
9834 ccb->ccb_h.status = status; in ahd_handle_en_lun()
9838 if ((ahd->features & AHD_MULTIROLE) != 0) { in ahd_handle_en_lun()
9841 our_id = ahd->our_id; in ahd_handle_en_lun()
9842 if (ccb->ccb_h.target_id != our_id in ahd_handle_en_lun()
9843 && ccb->ccb_h.target_id != CAM_TARGET_WILDCARD) { in ahd_handle_en_lun()
9844 if ((ahd->features & AHD_MULTI_TID) != 0 in ahd_handle_en_lun()
9845 && (ahd->flags & AHD_INITIATORROLE) != 0) { in ahd_handle_en_lun()
9849 * The hardware cannot handle a re-select-in in ahd_handle_en_lun()
9850 * on the initiator id during a re-select-out in ahd_handle_en_lun()
9854 } else if ((ahd->flags & AHD_INITIATORROLE) != 0 in ahd_handle_en_lun()
9855 || ahd->enabled_luns > 0) { in ahd_handle_en_lun()
9869 ccb->ccb_h.status = status; in ahd_handle_en_lun()
9877 if ((ahd->flags & AHD_TARGETROLE) == 0 in ahd_handle_en_lun()
9878 && ccb->ccb_h.target_id != CAM_TARGET_WILDCARD) { in ahd_handle_en_lun()
9880 if (LIST_FIRST(&ahd->pending_scbs) != NULL) { in ahd_handle_en_lun()
9881 ccb->ccb_h.status = CAM_BUSY; in ahd_handle_en_lun()
9884 ahd->flags |= AHD_TARGETROLE; in ahd_handle_en_lun()
9885 if ((ahd->features & AHD_MULTIROLE) == 0) in ahd_handle_en_lun()
9886 ahd->flags &= ~AHD_INITIATORROLE; in ahd_handle_en_lun()
9891 cel = &ccb->cel; in ahd_handle_en_lun()
9892 target = ccb->ccb_h.target_id; in ahd_handle_en_lun()
9893 lun = ccb->ccb_h.target_lun; in ahd_handle_en_lun()
9899 if (cel->enable != 0) { in ahd_handle_en_lun()
9904 xpt_print_path(ccb->ccb_h.path); in ahd_handle_en_lun()
9907 ccb->ccb_h.status = CAM_LUN_ALRDY_ENA; in ahd_handle_en_lun()
9911 if (cel->grp6_len != 0 in ahd_handle_en_lun()
9912 || cel->grp7_len != 0) { in ahd_handle_en_lun()
9917 ccb->ccb_h.status = CAM_REQ_INVALID; in ahd_handle_en_lun()
9918 printf("Non-zero Group Codes\n"); in ahd_handle_en_lun()
9929 xpt_print_path(ccb->ccb_h.path); in ahd_handle_en_lun()
9931 ccb->ccb_h.status = CAM_RESRC_UNAVAIL; in ahd_handle_en_lun()
9937 xpt_print_path(ccb->ccb_h.path); in ahd_handle_en_lun()
9939 ccb->ccb_h.status = CAM_RESRC_UNAVAIL; in ahd_handle_en_lun()
9943 status = xpt_create_path(&lstate->path, /*periph*/NULL, in ahd_handle_en_lun()
9944 xpt_path_path_id(ccb->ccb_h.path), in ahd_handle_en_lun()
9945 xpt_path_target_id(ccb->ccb_h.path), in ahd_handle_en_lun()
9946 xpt_path_lun_id(ccb->ccb_h.path)); in ahd_handle_en_lun()
9949 xpt_print_path(ccb->ccb_h.path); in ahd_handle_en_lun()
9951 ccb->ccb_h.status = CAM_RESRC_UNAVAIL; in ahd_handle_en_lun()
9954 SLIST_INIT(&lstate->accept_tios); in ahd_handle_en_lun()
9955 SLIST_INIT(&lstate->immed_notifies); in ahd_handle_en_lun()
9958 tstate->enabled_luns[lun] = lstate; in ahd_handle_en_lun()
9959 ahd->enabled_luns++; in ahd_handle_en_lun()
9961 if ((ahd->features & AHD_MULTI_TID) != 0) { in ahd_handle_en_lun()
9987 if ((ahd->features & AHD_TWIN) == 0) in ahd_handle_en_lun()
9990 ahd->our_id = target; in ahd_handle_en_lun()
10003 ahd->black_hole = lstate; in ahd_handle_en_lun()
10004 /* Allow select-in operations */ in ahd_handle_en_lun()
10005 if (ahd->black_hole != NULL && ahd->enabled_luns > 0) { in ahd_handle_en_lun()
10014 ccb->ccb_h.status = CAM_REQ_CMP; in ahd_handle_en_lun()
10015 xpt_print_path(ccb->ccb_h.path); in ahd_handle_en_lun()
10022 ccb->ccb_h.status = CAM_LUN_INVALID; in ahd_handle_en_lun()
10026 ccb->ccb_h.status = CAM_REQ_CMP; in ahd_handle_en_lun()
10027 LIST_FOREACH(scb, &ahd->pending_scbs, pending_links) { in ahd_handle_en_lun()
10030 ccbh = &scb->io_ctx->ccb_h; in ahd_handle_en_lun()
10031 if (ccbh->func_code == XPT_CONT_TARGET_IO in ahd_handle_en_lun()
10032 && !xpt_path_comp(ccbh->path, ccb->ccb_h.path)){ in ahd_handle_en_lun()
10034 ccb->ccb_h.status = CAM_REQ_INVALID; in ahd_handle_en_lun()
10039 if (SLIST_FIRST(&lstate->accept_tios) != NULL) { in ahd_handle_en_lun()
10041 while ((cancel_ccb = (union ccb *)SLIST_FIRST(&lstate->accept_tios)) != NULL) { in ahd_handle_en_lun()
10042 SLIST_REMOVE_HEAD(&lstate->accept_tios, sim_links.sle); in ahd_handle_en_lun()
10043 cancel_ccb->ccb_h.status = CAM_REQ_ABORTED; in ahd_handle_en_lun()
10048 if (SLIST_FIRST(&lstate->immed_notifies) != NULL) { in ahd_handle_en_lun()
10050 while ((cancel_ccb = (union ccb *)SLIST_FIRST(&lstate->immed_notifies)) != NULL) { in ahd_handle_en_lun()
10051 SLIST_REMOVE_HEAD(&lstate->immed_notifies, sim_links.sle); in ahd_handle_en_lun()
10052 cancel_ccb->ccb_h.status = CAM_REQ_ABORTED; in ahd_handle_en_lun()
10057 if (ccb->ccb_h.status != CAM_REQ_CMP) { in ahd_handle_en_lun()
10061 xpt_print_path(ccb->ccb_h.path); in ahd_handle_en_lun()
10063 xpt_free_path(lstate->path); in ahd_handle_en_lun()
10069 tstate->enabled_luns[lun] = NULL; in ahd_handle_en_lun()
10070 ahd->enabled_luns--; in ahd_handle_en_lun()
10072 if (tstate->enabled_luns[i] != NULL) { in ahd_handle_en_lun()
10080 if (ahd->features & AHD_MULTI_TID) { in ahd_handle_en_lun()
10090 ahd->black_hole = NULL; in ahd_handle_en_lun()
10098 if (ahd->enabled_luns == 0) { in ahd_handle_en_lun()
10099 /* Disallow select-in */ in ahd_handle_en_lun()
10109 if ((ahd->features & AHD_MULTIROLE) == 0) { in ahd_handle_en_lun()
10111 ahd->flags &= ~AHD_TARGETROLE; in ahd_handle_en_lun()
10112 ahd->flags |= AHD_INITIATORROLE; in ahd_handle_en_lun()
10134 if ((ahd->features & AHD_MULTI_TID) == 0) in ahd_update_scsiid()
10135 panic("ahd_update_scsiid called on non-multitid unit\n"); in ahd_update_scsiid()
10143 if ((ahd->features & AHD_ULTRA2) != 0) in ahd_update_scsiid()
10154 our_id = ahd->our_id; in ahd_update_scsiid()
10156 our_id--; in ahd_update_scsiid()
10160 if ((ahd->features & AHD_ULTRA2) != 0) in ahd_update_scsiid()
10173 while ((cmd = &ahd->targetcmds[ahd->tqinfifonext])->cmd_valid != 0) { in ahd_run_tqinfifo()
10181 cmd->cmd_valid = 0; in ahd_run_tqinfifo()
10182 ahd_dmamap_sync(ahd, ahd->shared_data_dmat, in ahd_run_tqinfifo()
10183 ahd->shared_data_dmamap, in ahd_run_tqinfifo()
10184 ahd_targetcmd_offset(ahd, ahd->tqinfifonext), in ahd_run_tqinfifo()
10187 ahd->tqinfifonext++; in ahd_run_tqinfifo()
10193 if ((ahd->tqinfifonext & (HOST_TQINPOS - 1)) == 1) { in ahd_run_tqinfifo()
10198 hs_mailbox |= ahd->tqinfifonext & HOST_TQINPOS; in ahd_run_tqinfifo()
10215 initiator = SCSIID_TARGET(ahd, cmd->scsiid); in ahd_handle_target_cmd()
10216 target = SCSIID_OUR_ID(cmd->scsiid); in ahd_handle_target_cmd()
10217 lun = (cmd->identify & MSG_IDENTIFY_LUNMASK); in ahd_handle_target_cmd()
10219 byte = cmd->bytes; in ahd_handle_target_cmd()
10220 tstate = ahd->enabled_targets[target]; in ahd_handle_target_cmd()
10223 lstate = tstate->enabled_luns[lun]; in ahd_handle_target_cmd()
10229 lstate = ahd->black_hole; in ahd_handle_target_cmd()
10231 atio = (struct ccb_accept_tio*)SLIST_FIRST(&lstate->accept_tios); in ahd_handle_target_cmd()
10233 ahd->flags |= AHD_TQINFIFO_BLOCKED; in ahd_handle_target_cmd()
10239 ahd->flags &= ~AHD_TQINFIFO_BLOCKED; in ahd_handle_target_cmd()
10244 lstate == ahd->black_hole ? "(Black Holed)" : ""); in ahd_handle_target_cmd()
10246 SLIST_REMOVE_HEAD(&lstate->accept_tios, sim_links.sle); in ahd_handle_target_cmd()
10248 if (lstate == ahd->black_hole) { in ahd_handle_target_cmd()
10250 atio->ccb_h.target_id = target; in ahd_handle_target_cmd()
10251 atio->ccb_h.target_lun = lun; in ahd_handle_target_cmd()
10258 atio->sense_len = 0; in ahd_handle_target_cmd()
10259 atio->init_id = initiator; in ahd_handle_target_cmd()
10262 atio->tag_action = *byte++; in ahd_handle_target_cmd()
10263 atio->tag_id = *byte++; in ahd_handle_target_cmd()
10264 atio->ccb_h.flags |= CAM_TAG_ACTION_VALID; in ahd_handle_target_cmd()
10266 atio->ccb_h.flags &= ~CAM_TAG_ACTION_VALID; in ahd_handle_target_cmd()
10273 atio->cdb_len = 6; in ahd_handle_target_cmd()
10277 atio->cdb_len = 10; in ahd_handle_target_cmd()
10280 atio->cdb_len = 16; in ahd_handle_target_cmd()
10283 atio->cdb_len = 12; in ahd_handle_target_cmd()
10288 atio->cdb_len = 1; in ahd_handle_target_cmd()
10293 memcpy(atio->cdb_io.cdb_bytes, byte, atio->cdb_len); in ahd_handle_target_cmd()
10295 atio->ccb_h.status |= CAM_CDB_RECVD; in ahd_handle_target_cmd()
10297 if ((cmd->identify & MSG_IDENTIFY_DISCFLAG) == 0) { in ahd_handle_target_cmd()
10306 printf("Received Immediate Command %d:%d:%d - %p\n", in ahd_handle_target_cmd()
10307 initiator, target, lun, ahd->pending_device); in ahd_handle_target_cmd()
10309 ahd->pending_device = lstate; in ahd_handle_target_cmd()
10311 atio->ccb_h.flags |= CAM_DIS_DISCONNECT; in ahd_handle_target_cmd()
10313 atio->ccb_h.flags &= ~CAM_DIS_DISCONNECT; in ahd_handle_target_cmd()