aic7xxx.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:185k
- /*
- * Core routines and tables shareable across OS platforms.
- *
- * Copyright (c) 1994-2001 Justin T. Gibbs.
- * Copyright (c) 2000-2001 Adaptec Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions, and the following disclaimer,
- * without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- * substantially similar to the "NO WARRANTY" disclaimer below
- * ("Disclaimer") and any redistribution must be conditioned upon
- * including a substantially similar Disclaimer requirement for further
- * binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- * of any contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- *
- * $Id: //depot/aic7xxx/aic7xxx/aic7xxx.c#50 $
- *
- * $FreeBSD: src/sys/dev/aic7xxx/aic7xxx.c,v 1.61 2000/11/13 03:35:43 gibbs Exp $
- */
- #include "aic7xxx_osm.h"
- #include "aic7xxx_inline.h"
- #include "aicasm/aicasm_insformat.h"
- /****************************** Softc Data ************************************/
- struct ahc_softc_tailq ahc_tailq = TAILQ_HEAD_INITIALIZER(ahc_tailq);
- /***************************** Lookup Tables **********************************/
- char *ahc_chip_names[] =
- {
- "NONE",
- "aic7770",
- "aic7850",
- "aic7855",
- "aic7859",
- "aic7860",
- "aic7870",
- "aic7880",
- "aic7895",
- "aic7895C",
- "aic7890/91",
- "aic7896/97",
- "aic7892",
- "aic7899"
- };
- static const u_int num_chip_names = NUM_ELEMENTS(ahc_chip_names);
- /*
- * Hardware error codes.
- */
- struct ahc_hard_error_entry {
- uint8_t errno;
- char *errmesg;
- };
- static struct ahc_hard_error_entry ahc_hard_errors[] = {
- { ILLHADDR, "Illegal Host Access" },
- { ILLSADDR, "Illegal Sequencer Address referrenced" },
- { ILLOPCODE, "Illegal Opcode in sequencer program" },
- { SQPARERR, "Sequencer Parity Error" },
- { DPARERR, "Data-path Parity Error" },
- { MPARERR, "Scratch or SCB Memory Parity Error" },
- { PCIERRSTAT, "PCI Error detected" },
- { CIOPARERR, "CIOBUS Parity Error" },
- };
- static const u_int num_errors = NUM_ELEMENTS(ahc_hard_errors);
- static struct ahc_phase_table_entry ahc_phase_table[] =
- {
- { P_DATAOUT, MSG_NOOP, "in Data-out phase" },
- { P_DATAIN, MSG_INITIATOR_DET_ERR, "in Data-in phase" },
- { P_DATAOUT_DT, MSG_NOOP, "in DT Data-out phase" },
- { P_DATAIN_DT, MSG_INITIATOR_DET_ERR, "in DT Data-in phase" },
- { P_COMMAND, MSG_NOOP, "in Command phase" },
- { P_MESGOUT, MSG_NOOP, "in Message-out phase" },
- { P_STATUS, MSG_INITIATOR_DET_ERR, "in Status phase" },
- { P_MESGIN, MSG_PARITY_ERROR, "in Message-in phase" },
- { P_BUSFREE, MSG_NOOP, "while idle" },
- { 0, MSG_NOOP, "in unknown phase" }
- };
- /*
- * In most cases we only wish to itterate over real phases, so
- * exclude the last element from the count.
- */
- static const u_int num_phases = NUM_ELEMENTS(ahc_phase_table) - 1;
- /*
- * Valid SCSIRATE values. (p. 3-17)
- * Provides a mapping of tranfer periods in ns to the proper value to
- * stick in the scsixfer reg.
- */
- static struct ahc_syncrate ahc_syncrates[] =
- {
- /* ultra2 fast/ultra period rate */
- { 0x42, 0x000, 9, "80.0" },
- { 0x03, 0x000, 10, "40.0" },
- { 0x04, 0x000, 11, "33.0" },
- { 0x05, 0x100, 12, "20.0" },
- { 0x06, 0x110, 15, "16.0" },
- { 0x07, 0x120, 18, "13.4" },
- { 0x08, 0x000, 25, "10.0" },
- { 0x19, 0x010, 31, "8.0" },
- { 0x1a, 0x020, 37, "6.67" },
- { 0x1b, 0x030, 43, "5.7" },
- { 0x1c, 0x040, 50, "5.0" },
- { 0x00, 0x050, 56, "4.4" },
- { 0x00, 0x060, 62, "4.0" },
- { 0x00, 0x070, 68, "3.6" },
- { 0x00, 0x000, 0, NULL }
- };
- /* Our Sequencer Program */
- #include "aic7xxx_seq.h"
- /**************************** Function Declarations ***************************/
- static void ahc_force_renegotiation(struct ahc_softc *ahc);
- static struct ahc_tmode_tstate*
- ahc_alloc_tstate(struct ahc_softc *ahc,
- u_int scsi_id, char channel);
- #ifdef AHC_TARGET_MODE
- static void ahc_free_tstate(struct ahc_softc *ahc,
- u_int scsi_id, char channel, int force);
- #endif
- static struct ahc_syncrate*
- ahc_devlimited_syncrate(struct ahc_softc *ahc,
- struct ahc_initiator_tinfo *,
- u_int *period,
- u_int *ppr_options,
- role_t role);
- static void ahc_update_pending_scbs(struct ahc_softc *ahc);
- static void ahc_fetch_devinfo(struct ahc_softc *ahc,
- struct ahc_devinfo *devinfo);
- static void ahc_scb_devinfo(struct ahc_softc *ahc,
- struct ahc_devinfo *devinfo,
- struct scb *scb);
- static void ahc_assert_atn(struct ahc_softc *ahc);
- static void ahc_setup_initiator_msgout(struct ahc_softc *ahc,
- struct ahc_devinfo *devinfo,
- struct scb *scb);
- static void ahc_build_transfer_msg(struct ahc_softc *ahc,
- struct ahc_devinfo *devinfo);
- static void ahc_construct_sdtr(struct ahc_softc *ahc,
- struct ahc_devinfo *devinfo,
- u_int period, u_int offset);
- static void ahc_construct_wdtr(struct ahc_softc *ahc,
- struct ahc_devinfo *devinfo,
- u_int bus_width);
- static void ahc_construct_ppr(struct ahc_softc *ahc,
- struct ahc_devinfo *devinfo,
- u_int period, u_int offset,
- u_int bus_width, u_int ppr_options);
- static void ahc_clear_msg_state(struct ahc_softc *ahc);
- static void ahc_handle_message_phase(struct ahc_softc *ahc);
- typedef enum {
- AHCMSG_1B,
- AHCMSG_2B,
- AHCMSG_EXT
- } ahc_msgtype;
- static int ahc_sent_msg(struct ahc_softc *ahc, ahc_msgtype type,
- u_int msgval, int full);
- static int ahc_parse_msg(struct ahc_softc *ahc,
- struct ahc_devinfo *devinfo);
- static int ahc_handle_msg_reject(struct ahc_softc *ahc,
- struct ahc_devinfo *devinfo);
- static void ahc_handle_ign_wide_residue(struct ahc_softc *ahc,
- struct ahc_devinfo *devinfo);
- static void ahc_reinitialize_dataptrs(struct ahc_softc *ahc);
- static void ahc_handle_devreset(struct ahc_softc *ahc,
- struct ahc_devinfo *devinfo,
- cam_status status, char *message,
- int verbose_level);
- #if AHC_TARGET_MODE
- static void ahc_setup_target_msgin(struct ahc_softc *ahc,
- struct ahc_devinfo *devinfo,
- struct scb *scb);
- #endif
- static bus_dmamap_callback_t ahc_dmamap_cb;
- static void ahc_build_free_scb_list(struct ahc_softc *ahc);
- static int ahc_init_scbdata(struct ahc_softc *ahc);
- static void ahc_fini_scbdata(struct ahc_softc *ahc);
- static void ahc_qinfifo_requeue(struct ahc_softc *ahc,
- struct scb *prev_scb,
- struct scb *scb);
- static int ahc_qinfifo_count(struct ahc_softc *ahc);
- static u_int ahc_rem_scb_from_disc_list(struct ahc_softc *ahc,
- u_int prev, u_int scbptr);
- static void ahc_add_curscb_to_free_list(struct ahc_softc *ahc);
- static u_int ahc_rem_wscb(struct ahc_softc *ahc,
- u_int scbpos, u_int prev);
- static void ahc_reset_current_bus(struct ahc_softc *ahc);
- #ifdef AHC_DUMP_SEQ
- static void ahc_dumpseq(struct ahc_softc *ahc);
- #endif
- static void ahc_loadseq(struct ahc_softc *ahc);
- static int ahc_check_patch(struct ahc_softc *ahc,
- struct patch **start_patch,
- u_int start_instr, u_int *skip_addr);
- static void ahc_download_instr(struct ahc_softc *ahc,
- u_int instrptr, uint8_t *dconsts);
- #ifdef AHC_TARGET_MODE
- static void ahc_queue_lstate_event(struct ahc_softc *ahc,
- struct ahc_tmode_lstate *lstate,
- u_int initiator_id,
- u_int event_type,
- u_int event_arg);
- static void ahc_update_scsiid(struct ahc_softc *ahc,
- u_int targid_mask);
- static int ahc_handle_target_cmd(struct ahc_softc *ahc,
- struct target_cmd *cmd);
- #endif
- /************************* Sequencer Execution Control ************************/
- /*
- * Restart the sequencer program from address zero
- */
- void
- ahc_restart(struct ahc_softc *ahc)
- {
- ahc_pause(ahc);
- ahc_outb(ahc, SCSISIGO, 0); /* De-assert BSY */
- ahc_outb(ahc, MSG_OUT, MSG_NOOP); /* No message to send */
- ahc_outb(ahc, SXFRCTL1, ahc_inb(ahc, SXFRCTL1) & ~BITBUCKET);
- ahc_outb(ahc, LASTPHASE, P_BUSFREE);
- /*
- * Ensure that the sequencer's idea of TQINPOS
- * matches our own. The sequencer increments TQINPOS
- * only after it sees a DMA complete and a reset could
- * occur before the increment leaving the kernel to believe
- * the command arrived but the sequencer to not.
- */
- ahc_outb(ahc, TQINPOS, ahc->tqinfifonext);
- /* Always allow reselection */
- ahc_outb(ahc, SCSISEQ,
- ahc_inb(ahc, SCSISEQ_TEMPLATE) & (ENSELI|ENRSELI|ENAUTOATNP));
- if ((ahc->features & AHC_CMD_CHAN) != 0) {
- /* Ensure that no DMA operations are in progress */
- ahc_outb(ahc, CCSCBCNT, 0);
- ahc_outb(ahc, CCSGCTL, 0);
- ahc_outb(ahc, CCSCBCTL, 0);
- }
- /*
- * If we were in the process of DMA'ing SCB data into
- * an SCB, replace that SCB on the free list. This prevents
- * an SCB leak.
- */
- if ((ahc_inb(ahc, SEQ_FLAGS2) & SCB_DMA) != 0) {
- ahc_add_curscb_to_free_list(ahc);
- ahc_outb(ahc, SEQ_FLAGS2,
- ahc_inb(ahc, SEQ_FLAGS2) & ~SCB_DMA);
- }
- ahc_outb(ahc, MWI_RESIDUAL, 0);
- ahc_outb(ahc, SEQCTL, FASTMODE);
- ahc_outb(ahc, SEQADDR0, 0);
- ahc_outb(ahc, SEQADDR1, 0);
- ahc_unpause(ahc);
- }
- /************************* Input/Output Queues ********************************/
- void
- ahc_run_qoutfifo(struct ahc_softc *ahc)
- {
- struct scb *scb;
- u_int scb_index;
- ahc_sync_qoutfifo(ahc, BUS_DMASYNC_POSTREAD);
- while (ahc->qoutfifo[ahc->qoutfifonext] != SCB_LIST_NULL) {
- scb_index = ahc->qoutfifo[ahc->qoutfifonext];
- if ((ahc->qoutfifonext & 0x03) == 0x03) {
- u_int modnext;
- /*
- * Clear 32bits of QOUTFIFO at a time
- * so that we don't clobber an incoming
- * byte DMA to the array on architectures
- * that only support 32bit load and store
- * operations.
- */
- modnext = ahc->qoutfifonext & ~0x3;
- *((uint32_t *)(&ahc->qoutfifo[modnext])) = 0xFFFFFFFFUL;
- ahc_dmamap_sync(ahc, ahc->shared_data_dmat,
- ahc->shared_data_dmamap,
- /*offset*/modnext, /*len*/4,
- BUS_DMASYNC_PREREAD);
- }
- ahc->qoutfifonext++;
- scb = ahc_lookup_scb(ahc, scb_index);
- if (scb == NULL) {
- printf("%s: WARNING no command for scb %d "
- "(cmdcmplt)nQOUTPOS = %dn",
- ahc_name(ahc), scb_index,
- ahc->qoutfifonext - 1);
- continue;
- }
- /*
- * Save off the residual
- * if there is one.
- */
- ahc_update_residual(scb);
- ahc_done(ahc, scb);
- }
- }
- void
- ahc_run_untagged_queues(struct ahc_softc *ahc)
- {
- int i;
- for (i = 0; i < 16; i++)
- ahc_run_untagged_queue(ahc, &ahc->untagged_queues[i]);
- }
- void
- ahc_run_untagged_queue(struct ahc_softc *ahc, struct scb_tailq *queue)
- {
- struct scb *scb;
- if (ahc->untagged_queue_lock != 0)
- return;
- if ((scb = TAILQ_FIRST(queue)) != NULL
- && (scb->flags & SCB_ACTIVE) == 0) {
- scb->flags |= SCB_ACTIVE;
- ahc_queue_scb(ahc, scb);
- }
- }
- /************************* Interrupt Handling *********************************/
- void
- ahc_handle_brkadrint(struct ahc_softc *ahc)
- {
- /*
- * We upset the sequencer :-(
- * Lookup the error message
- */
- int i;
- int error;
- error = ahc_inb(ahc, ERROR);
- for (i = 0; error != 1 && i < num_errors; i++)
- error >>= 1;
- printf("%s: brkadrint, %s at seqaddr = 0x%xn",
- ahc_name(ahc), ahc_hard_errors[i].errmesg,
- ahc_inb(ahc, SEQADDR0) |
- (ahc_inb(ahc, SEQADDR1) << 8));
- ahc_dump_card_state(ahc);
- /* Tell everyone that this HBA is no longer availible */
- ahc_abort_scbs(ahc, CAM_TARGET_WILDCARD, ALL_CHANNELS,
- CAM_LUN_WILDCARD, SCB_LIST_NULL, ROLE_UNKNOWN,
- CAM_NO_HBA);
- /* Disable all interrupt sources by resetting the controller */
- ahc_shutdown(ahc);
- }
- void
- ahc_handle_seqint(struct ahc_softc *ahc, u_int intstat)
- {
- struct scb *scb;
- struct ahc_devinfo devinfo;
-
- ahc_fetch_devinfo(ahc, &devinfo);
- /*
- * Clear the upper byte that holds SEQINT status
- * codes and clear the SEQINT bit. We will unpause
- * the sequencer, if appropriate, after servicing
- * the request.
- */
- ahc_outb(ahc, CLRINT, CLRSEQINT);
- switch (intstat & SEQINT_MASK) {
- case BAD_STATUS:
- {
- u_int scb_index;
- struct hardware_scb *hscb;
- /*
- * Set the default return value to 0 (don't
- * send sense). The sense code will change
- * this if needed.
- */
- ahc_outb(ahc, RETURN_1, 0);
- /*
- * The sequencer will notify us when a command
- * has an error that would be of interest to
- * the kernel. This allows us to leave the sequencer
- * running in the common case of command completes
- * without error. The sequencer will already have
- * dma'd the SCB back up to us, so we can reference
- * the in kernel copy directly.
- */
- scb_index = ahc_inb(ahc, SCB_TAG);
- scb = ahc_lookup_scb(ahc, scb_index);
- if (scb == NULL) {
- printf("%s:%c:%d: ahc_intr - referenced scb "
- "not valid during seqint 0x%x scb(%d)n",
- ahc_name(ahc), devinfo.channel,
- devinfo.target, intstat, scb_index);
- ahc_dump_card_state(ahc);
- panic("for safety");
- goto unpause;
- }
- hscb = scb->hscb;
- /* Don't want to clobber the original sense code */
- if ((scb->flags & SCB_SENSE) != 0) {
- /*
- * Clear the SCB_SENSE Flag and have
- * the sequencer do a normal command
- * complete.
- */
- scb->flags &= ~SCB_SENSE;
- ahc_set_transaction_status(scb, CAM_AUTOSENSE_FAIL);
- break;
- }
- ahc_set_transaction_status(scb, CAM_SCSI_STATUS_ERROR);
- /* Freeze the queue until the client sees the error. */
- ahc_freeze_devq(ahc, scb);
- ahc_freeze_scb(scb);
- ahc_set_scsi_status(scb, hscb->shared_data.status.scsi_status);
- switch (hscb->shared_data.status.scsi_status) {
- case SCSI_STATUS_OK:
- printf("%s: Interrupted for staus of 0???n",
- ahc_name(ahc));
- break;
- case SCSI_STATUS_CMD_TERMINATED:
- case SCSI_STATUS_CHECK_COND:
- {
- struct ahc_dma_seg *sg;
- struct scsi_sense *sc;
- struct ahc_initiator_tinfo *targ_info;
- struct ahc_tmode_tstate *tstate;
- struct ahc_transinfo *tinfo;
- #ifdef AHC_DEBUG
- if (ahc_debug & AHC_SHOWSENSE) {
- ahc_print_path(ahc, scb);
- printf("SCB %d: requests Check Statusn",
- scb->hscb->tag);
- }
- #endif
- if (ahc_perform_autosense(scb) == 0)
- break;
- targ_info = ahc_fetch_transinfo(ahc,
- devinfo.channel,
- devinfo.our_scsiid,
- devinfo.target,
- &tstate);
- tinfo = &targ_info->curr;
- sg = scb->sg_list;
- sc = (struct scsi_sense *)(&hscb->shared_data.cdb);
- /*
- * Save off the residual if there is one.
- */
- ahc_update_residual(scb);
- #ifdef AHC_DEBUG
- if (ahc_debug & AHC_SHOWSENSE) {
- ahc_print_path(ahc, scb);
- printf("Sending Sensen");
- }
- #endif
- sg->addr = ahc_get_sense_bufaddr(ahc, scb);
- sg->len = ahc_get_sense_bufsize(ahc, scb);
- sg->len |= AHC_DMA_LAST_SEG;
- /* Fixup byte order */
- sg->addr = ahc_htole32(sg->addr);
- sg->len = ahc_htole32(sg->len);
- sc->opcode = REQUEST_SENSE;
- sc->byte2 = 0;
- if (tinfo->protocol_version <= SCSI_REV_2
- && SCB_GET_LUN(scb) < 8)
- sc->byte2 = SCB_GET_LUN(scb) << 5;
- sc->unused[0] = 0;
- sc->unused[1] = 0;
- sc->length = sg->len;
- sc->control = 0;
- /*
- * We can't allow the target to disconnect.
- * This will be an untagged transaction and
- * having the target disconnect will make this
- * transaction indestinguishable from outstanding
- * tagged transactions.
- */
- hscb->control = 0;
- /*
- * This request sense could be because the
- * the device lost power or in some other
- * way has lost our transfer negotiations.
- * Renegotiate if appropriate. Unit attention
- * errors will be reported before any data
- * phases occur.
- */
- if (ahc_get_residual(scb)
- == ahc_get_transfer_length(scb)) {
- ahc_update_neg_request(ahc, &devinfo,
- tstate, targ_info,
- /*force*/TRUE);
- }
- if (tstate->auto_negotiate & devinfo.target_mask) {
- hscb->control |= MK_MESSAGE;
- scb->flags &= ~SCB_NEGOTIATE;
- scb->flags |= SCB_AUTO_NEGOTIATE;
- }
- hscb->cdb_len = sizeof(*sc);
- hscb->dataptr = sg->addr;
- hscb->datacnt = sg->len;
- hscb->sgptr = scb->sg_list_phys | SG_FULL_RESID;
- hscb->sgptr = ahc_htole32(hscb->sgptr);
- scb->sg_count = 1;
- scb->flags |= SCB_SENSE;
- ahc_qinfifo_requeue_tail(ahc, scb);
- ahc_outb(ahc, RETURN_1, SEND_SENSE);
- #ifdef __FreeBSD__
- /*
- * Ensure we have enough time to actually
- * retrieve the sense.
- */
- untimeout(ahc_timeout, (caddr_t)scb,
- scb->io_ctx->ccb_h.timeout_ch);
- scb->io_ctx->ccb_h.timeout_ch =
- timeout(ahc_timeout, (caddr_t)scb, 5 * hz);
- #endif
- break;
- }
- default:
- break;
- }
- break;
- }
- case NO_MATCH:
- {
- /* Ensure we don't leave the selection hardware on */
- ahc_outb(ahc, SCSISEQ,
- ahc_inb(ahc, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP));
- printf("%s:%c:%d: no active SCB for reconnecting "
- "target - issuing BUS DEVICE RESETn",
- ahc_name(ahc), devinfo.channel, devinfo.target);
- printf("SAVED_SCSIID == 0x%x, SAVED_LUN == 0x%x, "
- "ARG_1 == 0x%x ACCUM = 0x%xn",
- ahc_inb(ahc, SAVED_SCSIID), ahc_inb(ahc, SAVED_LUN),
- ahc_inb(ahc, ARG_1), ahc_inb(ahc, ACCUM));
- printf("SEQ_FLAGS == 0x%x, SCBPTR == 0x%x, BTT == 0x%x, "
- "SINDEX == 0x%xn",
- ahc_inb(ahc, SEQ_FLAGS), ahc_inb(ahc, SCBPTR),
- ahc_index_busy_tcl(ahc,
- BUILD_TCL(ahc_inb(ahc, SAVED_SCSIID),
- ahc_inb(ahc, SAVED_LUN))),
- ahc_inb(ahc, SINDEX));
- printf("SCSIID == 0x%x, SCB_SCSIID == 0x%x, SCB_LUN == 0x%x, "
- "SCB_TAG == 0x%x, SCB_CONTROL == 0x%xn",
- ahc_inb(ahc, SCSIID), ahc_inb(ahc, SCB_SCSIID),
- ahc_inb(ahc, SCB_LUN), ahc_inb(ahc, SCB_TAG),
- ahc_inb(ahc, SCB_CONTROL));
- printf("SCSIBUSL == 0x%x, SCSISIGI == 0x%xn",
- ahc_inb(ahc, SCSIBUSL), ahc_inb(ahc, SCSISIGI));
- printf("SXFRCTL0 == 0x%xn", ahc_inb(ahc, SXFRCTL0));
- printf("SEQCTL == 0x%xn", ahc_inb(ahc, SEQCTL));
- ahc_dump_card_state(ahc);
- ahc->msgout_buf[0] = MSG_BUS_DEV_RESET;
- ahc->msgout_len = 1;
- ahc->msgout_index = 0;
- ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
- ahc_outb(ahc, MSG_OUT, HOST_MSG);
- ahc_assert_atn(ahc);
- break;
- }
- case SEND_REJECT:
- {
- u_int rejbyte = ahc_inb(ahc, ACCUM);
- printf("%s:%c:%d: Warning - unknown message received from "
- "target (0x%x). Rejectingn",
- ahc_name(ahc), devinfo.channel, devinfo.target, rejbyte);
- break;
- }
- case NO_IDENT:
- {
- /*
- * The reconnecting target either did not send an identify
- * message, or did, but we didn't find an SCB to match and
- * before it could respond to our ATN/abort, it hit a dataphase.
- * The only safe thing to do is to blow it away with a bus
- * reset.
- */
- int found;
- printf("%s:%c:%d: Target did not send an IDENTIFY message. "
- "LASTPHASE = 0x%x, SAVED_SCSIID == 0x%xn",
- ahc_name(ahc), devinfo.channel, devinfo.target,
- ahc_inb(ahc, LASTPHASE), ahc_inb(ahc, SAVED_SCSIID));
- found = ahc_reset_channel(ahc, devinfo.channel,
- /*initiate reset*/TRUE);
- printf("%s: Issued Channel %c Bus Reset. "
- "%d SCBs abortedn", ahc_name(ahc), devinfo.channel,
- found);
- return;
- }
- case IGN_WIDE_RES:
- ahc_handle_ign_wide_residue(ahc, &devinfo);
- break;
- case PDATA_REINIT:
- ahc_reinitialize_dataptrs(ahc);
- break;
- case BAD_PHASE:
- {
- u_int lastphase;
- lastphase = ahc_inb(ahc, LASTPHASE);
- printf("%s:%c:%d: unknown scsi bus phase %x, "
- "lastphase = 0x%x. Attempting to continuen",
- ahc_name(ahc), devinfo.channel, devinfo.target,
- lastphase, ahc_inb(ahc, SCSISIGI));
- break;
- }
- case MISSED_BUSFREE:
- {
- u_int lastphase;
- lastphase = ahc_inb(ahc, LASTPHASE);
- printf("%s:%c:%d: Missed busfree. "
- "Lastphase = 0x%x, Curphase = 0x%xn",
- ahc_name(ahc), devinfo.channel, devinfo.target,
- lastphase, ahc_inb(ahc, SCSISIGI));
- ahc_restart(ahc);
- return;
- }
- case HOST_MSG_LOOP:
- {
- /*
- * The sequencer has encountered a message phase
- * that requires host assistance for completion.
- * While handling the message phase(s), we will be
- * notified by the sequencer after each byte is
- * transfered so we can track bus phase changes.
- *
- * If this is the first time we've seen a HOST_MSG_LOOP
- * interrupt, initialize the state of the host message
- * loop.
- */
- if (ahc->msg_type == MSG_TYPE_NONE) {
- struct scb *scb;
- u_int scb_index;
- u_int bus_phase;
- bus_phase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK;
- if (bus_phase != P_MESGIN
- && bus_phase != P_MESGOUT) {
- printf("ahc_intr: HOST_MSG_LOOP bad "
- "phase 0x%xn",
- bus_phase);
- /*
- * Probably transitioned to bus free before
- * we got here. Just punt the message.
- */
- ahc_clear_intstat(ahc);
- ahc_restart(ahc);
- return;
- }
- scb_index = ahc_inb(ahc, SCB_TAG);
- scb = ahc_lookup_scb(ahc, scb_index);
- if (devinfo.role == ROLE_INITIATOR) {
- if (scb == NULL)
- panic("HOST_MSG_LOOP with "
- "invalid SCB %xn", scb_index);
- if (bus_phase == P_MESGOUT)
- ahc_setup_initiator_msgout(ahc,
- &devinfo,
- scb);
- else {
- ahc->msg_type =
- MSG_TYPE_INITIATOR_MSGIN;
- ahc->msgin_index = 0;
- }
- }
- #if AHC_TARGET_MODE
- else {
- if (bus_phase == P_MESGOUT) {
- ahc->msg_type =
- MSG_TYPE_TARGET_MSGOUT;
- ahc->msgin_index = 0;
- }
- else
- ahc_setup_target_msgin(ahc,
- &devinfo,
- scb);
- }
- #endif
- }
- ahc_handle_message_phase(ahc);
- break;
- }
- case PERR_DETECTED:
- {
- /*
- * If we've cleared the parity error interrupt
- * but the sequencer still believes that SCSIPERR
- * is true, it must be that the parity error is
- * for the currently presented byte on the bus,
- * and we are not in a phase (data-in) where we will
- * eventually ack this byte. Ack the byte and
- * throw it away in the hope that the target will
- * take us to message out to deliver the appropriate
- * error message.
- */
- if ((intstat & SCSIINT) == 0
- && (ahc_inb(ahc, SSTAT1) & SCSIPERR) != 0) {
- if ((ahc->features & AHC_DT) == 0) {
- u_int curphase;
- /*
- * The hardware will only let you ack bytes
- * if the expected phase in SCSISIGO matches
- * the current phase. Make sure this is
- * currently the case.
- */
- curphase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK;
- ahc_outb(ahc, LASTPHASE, curphase);
- ahc_outb(ahc, SCSISIGO, curphase);
- }
- ahc_inb(ahc, SCSIDATL);
- }
- break;
- }
- case DATA_OVERRUN:
- {
- /*
- * When the sequencer detects an overrun, it
- * places the controller in "BITBUCKET" mode
- * and allows the target to complete its transfer.
- * Unfortunately, none of the counters get updated
- * when the controller is in this mode, so we have
- * no way of knowing how large the overrun was.
- */
- u_int scbindex = ahc_inb(ahc, SCB_TAG);
- u_int lastphase = ahc_inb(ahc, LASTPHASE);
- u_int i;
- scb = ahc_lookup_scb(ahc, scbindex);
- for (i = 0; i < num_phases; i++) {
- if (lastphase == ahc_phase_table[i].phase)
- break;
- }
- ahc_print_path(ahc, scb);
- printf("data overrun detected %s."
- " Tag == 0x%x.n",
- ahc_phase_table[i].phasemsg,
- scb->hscb->tag);
- ahc_print_path(ahc, scb);
- printf("%s seen Data Phase. Length = %ld. NumSGs = %d.n",
- ahc_inb(ahc, SEQ_FLAGS) & DPHASE ? "Have" : "Haven't",
- ahc_get_transfer_length(scb), scb->sg_count);
- if (scb->sg_count > 0) {
- for (i = 0; i < scb->sg_count; i++) {
- printf("sg[%d] - Addr 0x%x%x : Length %dn",
- i,
- (ahc_le32toh(scb->sg_list[i].len) >> 24
- & SG_HIGH_ADDR_BITS),
- ahc_le32toh(scb->sg_list[i].addr),
- ahc_le32toh(scb->sg_list[i].len)
- & AHC_SG_LEN_MASK);
- }
- }
- /*
- * Set this and it will take effect when the
- * target does a command complete.
- */
- ahc_freeze_devq(ahc, scb);
- ahc_set_transaction_status(scb, CAM_DATA_RUN_ERR);
- ahc_freeze_scb(scb);
- if ((ahc->features & AHC_ULTRA2) != 0) {
- /*
- * Clear the channel in case we return
- * to data phase later.
- */
- ahc_outb(ahc, SXFRCTL0,
- ahc_inb(ahc, SXFRCTL0) | CLRSTCNT|CLRCHN);
- ahc_outb(ahc, SXFRCTL0,
- ahc_inb(ahc, SXFRCTL0) | CLRSTCNT|CLRCHN);
- }
- if ((ahc->flags & AHC_39BIT_ADDRESSING) != 0) {
- u_int dscommand1;
- /* Ensure HHADDR is 0 for future DMA operations. */
- dscommand1 = ahc_inb(ahc, DSCOMMAND1);
- ahc_outb(ahc, DSCOMMAND1, dscommand1 | HADDLDSEL0);
- ahc_outb(ahc, HADDR, 0);
- ahc_outb(ahc, DSCOMMAND1, dscommand1);
- }
- break;
- }
- case MKMSG_FAILED:
- {
- u_int scbindex;
- printf("%s:%c:%d:%d: Attempt to issue message failedn",
- ahc_name(ahc), devinfo.channel, devinfo.target,
- devinfo.lun);
- scbindex = ahc_inb(ahc, SCB_TAG);
- scb = ahc_lookup_scb(ahc, scbindex);
- if (scb != NULL
- && (scb->flags & SCB_RECOVERY_SCB) != 0)
- /*
- * Ensure that we didn't put a second instance of this
- * SCB into the QINFIFO.
- */
- ahc_search_qinfifo(ahc, SCB_GET_TARGET(ahc, scb),
- SCB_GET_CHANNEL(ahc, scb),
- SCB_GET_LUN(scb), scb->hscb->tag,
- ROLE_INITIATOR, /*status*/0,
- SEARCH_REMOVE);
- break;
- }
- case NO_FREE_SCB:
- {
- printf("%s: No free or disconnected SCBsn", ahc_name(ahc));
- ahc_dump_card_state(ahc);
- panic("for safety");
- break;
- }
- case SCB_MISMATCH:
- {
- u_int scbptr;
- scbptr = ahc_inb(ahc, SCBPTR);
- printf("Bogus TAG after DMA. SCBPTR %d, tag %d, our tag %dn",
- scbptr, ahc_inb(ahc, ARG_1),
- ahc->scb_data->hscbs[scbptr].tag);
- ahc_dump_card_state(ahc);
- panic("for saftey");
- break;
- }
- case OUT_OF_RANGE:
- {
- printf("%s: BTT calculation out of rangen", ahc_name(ahc));
- printf("SAVED_SCSIID == 0x%x, SAVED_LUN == 0x%x, "
- "ARG_1 == 0x%x ACCUM = 0x%xn",
- ahc_inb(ahc, SAVED_SCSIID), ahc_inb(ahc, SAVED_LUN),
- ahc_inb(ahc, ARG_1), ahc_inb(ahc, ACCUM));
- printf("SEQ_FLAGS == 0x%x, SCBPTR == 0x%x, BTT == 0x%x, "
- "SINDEX == 0x%xn, A == 0x%xn",
- ahc_inb(ahc, SEQ_FLAGS), ahc_inb(ahc, SCBPTR),
- ahc_index_busy_tcl(ahc,
- BUILD_TCL(ahc_inb(ahc, SAVED_SCSIID),
- ahc_inb(ahc, SAVED_LUN))),
- ahc_inb(ahc, SINDEX),
- ahc_inb(ahc, ACCUM));
- printf("SCSIID == 0x%x, SCB_SCSIID == 0x%x, SCB_LUN == 0x%x, "
- "SCB_TAG == 0x%x, SCB_CONTROL == 0x%xn",
- ahc_inb(ahc, SCSIID), ahc_inb(ahc, SCB_SCSIID),
- ahc_inb(ahc, SCB_LUN), ahc_inb(ahc, SCB_TAG),
- ahc_inb(ahc, SCB_CONTROL));
- printf("SCSIBUSL == 0x%x, SCSISIGI == 0x%xn",
- ahc_inb(ahc, SCSIBUSL), ahc_inb(ahc, SCSISIGI));
- ahc_dump_card_state(ahc);
- panic("for safety");
- break;
- }
- default:
- printf("ahc_intr: seqint, "
- "intstat == 0x%x, scsisigi = 0x%xn",
- intstat, ahc_inb(ahc, SCSISIGI));
- break;
- }
- unpause:
- /*
- * The sequencer is paused immediately on
- * a SEQINT, so we should restart it when
- * we're done.
- */
- ahc_unpause(ahc);
- }
- void
- ahc_handle_scsiint(struct ahc_softc *ahc, u_int intstat)
- {
- u_int scb_index;
- u_int status0;
- u_int status;
- struct scb *scb;
- char cur_channel;
- char intr_channel;
- /* Make sure the sequencer is in a safe location. */
- ahc_clear_critical_section(ahc);
- if ((ahc->features & AHC_TWIN) != 0
- && ((ahc_inb(ahc, SBLKCTL) & SELBUSB) != 0))
- cur_channel = 'B';
- else
- cur_channel = 'A';
- intr_channel = cur_channel;
- if ((ahc->features & AHC_ULTRA2) != 0)
- status0 = ahc_inb(ahc, SSTAT0) & IOERR;
- else
- status0 = 0;
- status = ahc_inb(ahc, SSTAT1) & (SELTO|SCSIRSTI|BUSFREE|SCSIPERR);
- if (status == 0 && status0 == 0) {
- if ((ahc->features & AHC_TWIN) != 0) {
- /* Try the other channel */
- ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) ^ SELBUSB);
- status = ahc_inb(ahc, SSTAT1)
- & (SELTO|SCSIRSTI|BUSFREE|SCSIPERR);
- intr_channel = (cur_channel == 'A') ? 'B' : 'A';
- }
- if (status == 0) {
- printf("%s: Spurious SCSI interruptn", ahc_name(ahc));
- ahc_outb(ahc, CLRINT, CLRSCSIINT);
- ahc_unpause(ahc);
- return;
- }
- }
- scb_index = ahc_inb(ahc, SCB_TAG);
- scb = ahc_lookup_scb(ahc, scb_index);
- if (scb != NULL
- && (ahc_inb(ahc, SEQ_FLAGS) & IDENTIFY_SEEN) == 0)
- scb = NULL;
- if ((ahc->features & AHC_ULTRA2) != 0
- && (status0 & IOERR) != 0) {
- int now_lvd;
- now_lvd = ahc_inb(ahc, SBLKCTL) & ENAB40;
- printf("%s: Transceiver State Has Changed to %s moden",
- ahc_name(ahc), now_lvd ? "LVD" : "SE");
- ahc_outb(ahc, CLRSINT0, CLRIOERR);
- /*
- * When transitioning to SE mode, the reset line
- * glitches, triggering an arbitration bug in some
- * Ultra2 controllers. This bug is cleared when we
- * assert the reset line. Since a reset glitch has
- * already occurred with this transition and a
- * transceiver state change is handled just like
- * a bus reset anyway, asserting the reset line
- * ourselves is safe.
- */
- ahc_reset_channel(ahc, intr_channel,
- /*Initiate Reset*/now_lvd == 0);
- } else if ((status & SCSIRSTI) != 0) {
- printf("%s: Someone reset channel %cn",
- ahc_name(ahc), intr_channel);
- if (intr_channel != cur_channel)
- ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) ^ SELBUSB);
- ahc_reset_channel(ahc, intr_channel, /*Initiate Reset*/FALSE);
- } else if ((status & SCSIPERR) != 0) {
- /*
- * Determine the bus phase and queue an appropriate message.
- * SCSIPERR is latched true as soon as a parity error
- * occurs. If the sequencer acked the transfer that
- * caused the parity error and the currently presented
- * transfer on the bus has correct parity, SCSIPERR will
- * be cleared by CLRSCSIPERR. Use this to determine if
- * we should look at the last phase the sequencer recorded,
- * or the current phase presented on the bus.
- */
- u_int mesg_out;
- u_int curphase;
- u_int errorphase;
- u_int lastphase;
- u_int scsirate;
- u_int i;
- u_int sstat2;
- lastphase = ahc_inb(ahc, LASTPHASE);
- curphase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK;
- sstat2 = ahc_inb(ahc, SSTAT2);
- ahc_outb(ahc, CLRSINT1, CLRSCSIPERR);
- /*
- * For all phases save DATA, the sequencer won't
- * automatically ack a byte that has a parity error
- * in it. So the only way that the current phase
- * could be 'data-in' is if the parity error is for
- * an already acked byte in the data phase. During
- * synchronous data-in transfers, we may actually
- * ack bytes before latching the current phase in
- * LASTPHASE, leading to the discrepancy between
- * curphase and lastphase.
- */
- if ((ahc_inb(ahc, SSTAT1) & SCSIPERR) != 0
- || curphase == P_DATAIN || curphase == P_DATAIN_DT)
- errorphase = curphase;
- else
- errorphase = lastphase;
- for (i = 0; i < num_phases; i++) {
- if (errorphase == ahc_phase_table[i].phase)
- break;
- }
- mesg_out = ahc_phase_table[i].mesg_out;
- if (scb != NULL)
- ahc_print_path(ahc, scb);
- else
- printf("%s:%c:%d: ", ahc_name(ahc), intr_channel,
- SCSIID_TARGET(ahc, ahc_inb(ahc, SAVED_SCSIID)));
- scsirate = ahc_inb(ahc, SCSIRATE);
- printf("parity error detected %s. "
- "SEQADDR(0x%x) SCSIRATE(0x%x)n",
- ahc_phase_table[i].phasemsg,
- ahc_inb(ahc, SEQADDR0) | (ahc_inb(ahc, SEQADDR1) << 8),
- scsirate);
- if ((ahc->features & AHC_DT) != 0) {
- if ((sstat2 & CRCVALERR) != 0)
- printf("tCRC Value Mismatchn");
- if ((sstat2 & CRCENDERR) != 0)
- printf("tNo terminal CRC packet receviedn");
- if ((sstat2 & CRCREQERR) != 0)
- printf("tIllegal CRC packet requestn");
- if ((sstat2 & DUAL_EDGE_ERR) != 0)
- printf("tUnexpected %sDT Data Phasen",
- (scsirate & SINGLE_EDGE) ? "" : "non-");
- }
- /*
- * We've set the hardware to assert ATN if we
- * get a parity error on "in" phases, so all we
- * need to do is stuff the message buffer with
- * the appropriate message. "In" phases have set
- * mesg_out to something other than MSG_NOP.
- */
- if (mesg_out != MSG_NOOP) {
- if (ahc->msg_type != MSG_TYPE_NONE)
- ahc->send_msg_perror = TRUE;
- else
- ahc_outb(ahc, MSG_OUT, mesg_out);
- }
- /*
- * Force a renegotiation with this target just in
- * case we are out of sync for some external reason
- * unknown (or unreported) by the target.
- */
- ahc_force_renegotiation(ahc);
- ahc_outb(ahc, CLRINT, CLRSCSIINT);
- ahc_unpause(ahc);
- } else if ((status & SELTO) != 0) {
- u_int scbptr;
- /* Stop the selection */
- ahc_outb(ahc, SCSISEQ, 0);
- /* No more pending messages */
- ahc_clear_msg_state(ahc);
- /* Clear interrupt state */
- ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) & ~ENBUSFREE);
- ahc_outb(ahc, CLRSINT1, CLRSELTIMEO|CLRBUSFREE|CLRSCSIPERR);
- /*
- * Although the driver does not care about the
- * 'Selection in Progress' status bit, the busy
- * LED does. SELINGO is only cleared by a sucessfull
- * selection, so we must manually clear it to insure
- * the LED turns off just incase no future successful
- * selections occur (e.g. no devices on the bus).
- */
- ahc_outb(ahc, CLRSINT0, CLRSELINGO);
- scbptr = ahc_inb(ahc, WAITING_SCBH);
- ahc_outb(ahc, SCBPTR, scbptr);
- scb_index = ahc_inb(ahc, SCB_TAG);
- scb = ahc_lookup_scb(ahc, scb_index);
- if (scb == NULL) {
- printf("%s: ahc_intr - referenced scb not "
- "valid during SELTO scb(%d, %d)n",
- ahc_name(ahc), scbptr, scb_index);
- } else {
- ahc_set_transaction_status(scb, CAM_SEL_TIMEOUT);
- ahc_freeze_devq(ahc, scb);
- }
- ahc_outb(ahc, CLRINT, CLRSCSIINT);
- /*
- * Force a renegotiation with this target just in
- * case the cable was pulled and will later be
- * re-attached. The target may forget its negotiation
- * settings with us should it attempt to reselect
- * during the interruption. The target will not issue
- * a unit attention in this case, so we must always
- * renegotiate.
- */
- ahc_force_renegotiation(ahc);
- ahc_restart(ahc);
- } else if ((status & BUSFREE) != 0
- && (ahc_inb(ahc, SIMODE1) & ENBUSFREE) != 0) {
- u_int lastphase;
- u_int saved_scsiid;
- u_int saved_lun;
- u_int target;
- u_int initiator_role_id;
- char channel;
- int printerror;
- /*
- * Clear our selection hardware as soon as possible.
- * We may have an entry in the waiting Q for this target,
- * that is affected by this busfree and we don't want to
- * go about selecting the target while we handle the event.
- */
- ahc_outb(ahc, SCSISEQ,
- ahc_inb(ahc, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP));
- /*
- * Disable busfree interrupts and clear the busfree
- * interrupt status. We do this here so that several
- * bus transactions occur prior to clearing the SCSIINT
- * latch. It can take a bit for the clearing to take effect.
- */
- ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) & ~ENBUSFREE);
- ahc_outb(ahc, CLRSINT1, CLRBUSFREE|CLRSCSIPERR);
- /*
- * Look at what phase we were last in.
- * If its message out, chances are pretty good
- * that the busfree was in response to one of
- * our abort requests.
- */
- lastphase = ahc_inb(ahc, LASTPHASE);
- saved_scsiid = ahc_inb(ahc, SAVED_SCSIID);
- saved_lun = ahc_inb(ahc, SAVED_LUN);
- target = SCSIID_TARGET(ahc, saved_scsiid);
- initiator_role_id = SCSIID_OUR_ID(saved_scsiid);
- channel = SCSIID_CHANNEL(ahc, saved_scsiid);
- printerror = 1;
- if (lastphase == P_MESGOUT) {
- struct ahc_devinfo devinfo;
- u_int tag;
- ahc_fetch_devinfo(ahc, &devinfo);
- tag = SCB_LIST_NULL;
- if (ahc_sent_msg(ahc, AHCMSG_1B, MSG_ABORT_TAG, TRUE)
- || ahc_sent_msg(ahc, AHCMSG_1B, MSG_ABORT, TRUE)) {
- if (ahc->msgout_buf[ahc->msgout_index - 1]
- == MSG_ABORT_TAG)
- tag = scb->hscb->tag;
- ahc_print_path(ahc, scb);
- printf("SCB %d - Abort%s Completed.n",
- scb->hscb->tag, tag == SCB_LIST_NULL ?
- "" : " Tag");
- ahc_abort_scbs(ahc, target, channel,
- saved_lun, tag,
- ROLE_INITIATOR,
- CAM_REQ_ABORTED);
- printerror = 0;
- } else if (ahc_sent_msg(ahc, AHCMSG_1B,
- MSG_BUS_DEV_RESET, TRUE)) {
- #ifdef __FreeBSD__
- /*
- * Don't mark the user's request for this BDR
- * as completing with CAM_BDR_SENT. CAM3
- * specifies CAM_REQ_CMP.
- */
- if (scb != NULL
- && scb->io_ctx->ccb_h.func_code== XPT_RESET_DEV
- && ahc_match_scb(ahc, scb, target, channel,
- CAM_LUN_WILDCARD,
- SCB_LIST_NULL,
- ROLE_INITIATOR)) {
- ahc_set_transaction_status(scb, CAM_REQ_CMP);
- }
- #endif
- ahc_compile_devinfo(&devinfo,
- initiator_role_id,
- target,
- CAM_LUN_WILDCARD,
- channel,
- ROLE_INITIATOR);
- ahc_handle_devreset(ahc, &devinfo,
- CAM_BDR_SENT,
- "Bus Device Reset",
- /*verbose_level*/0);
- printerror = 0;
- } else if (ahc_sent_msg(ahc, AHCMSG_EXT,
- MSG_EXT_PPR, FALSE)) {
- struct ahc_initiator_tinfo *tinfo;
- struct ahc_tmode_tstate *tstate;
- /*
- * PPR Rejected. Try non-ppr negotiation
- * and retry command.
- */
- tinfo = ahc_fetch_transinfo(ahc,
- devinfo.channel,
- devinfo.our_scsiid,
- devinfo.target,
- &tstate);
- tinfo->curr.transport_version = 2;
- tinfo->goal.transport_version = 2;
- tinfo->goal.ppr_options = 0;
- ahc_qinfifo_requeue_tail(ahc, scb);
- printerror = 0;
- } else if (ahc_sent_msg(ahc, AHCMSG_EXT,
- MSG_EXT_WDTR, FALSE)
- || ahc_sent_msg(ahc, AHCMSG_EXT,
- MSG_EXT_SDTR, FALSE)) {
- /*
- * Negotiation Rejected. Go-async and
- * retry command.
- */
- ahc_set_width(ahc, &devinfo,
- MSG_EXT_WDTR_BUS_8_BIT,
- AHC_TRANS_CUR|AHC_TRANS_GOAL,
- /*paused*/TRUE);
- ahc_set_syncrate(ahc, &devinfo,
- /*syncrate*/NULL,
- /*period*/0, /*offset*/0,
- /*ppr_options*/0,
- AHC_TRANS_CUR|AHC_TRANS_GOAL,
- /*paused*/TRUE);
- ahc_qinfifo_requeue_tail(ahc, scb);
- printerror = 0;
- }
- }
- if (printerror != 0) {
- u_int i;
- if (scb != NULL) {
- u_int tag;
- if ((scb->hscb->control & TAG_ENB) != 0)
- tag = scb->hscb->tag;
- else
- tag = SCB_LIST_NULL;
- ahc_print_path(ahc, scb);
- ahc_abort_scbs(ahc, target, channel,
- SCB_GET_LUN(scb), tag,
- ROLE_INITIATOR,
- CAM_UNEXP_BUSFREE);
- } else {
- /*
- * We had not fully identified this connection,
- * so we cannot abort anything.
- */
- printf("%s: ", ahc_name(ahc));
- }
- for (i = 0; i < num_phases; i++) {
- if (lastphase == ahc_phase_table[i].phase)
- break;
- }
- printf("Unexpected busfree %sn"
- "SEQADDR == 0x%xn",
- ahc_phase_table[i].phasemsg,
- ahc_inb(ahc, SEQADDR0)
- | (ahc_inb(ahc, SEQADDR1) << 8));
- }
- ahc_clear_msg_state(ahc);
- ahc_outb(ahc, CLRINT, CLRSCSIINT);
- ahc_restart(ahc);
- } else {
- printf("%s: Missing case in ahc_handle_scsiint. status = %xn",
- ahc_name(ahc), status);
- ahc_outb(ahc, CLRINT, CLRSCSIINT);
- }
- }
- /*
- * Force renegotiation to occur the next time we initiate
- * a command to the current device.
- */
- static void
- ahc_force_renegotiation(struct ahc_softc *ahc)
- {
- struct ahc_devinfo devinfo;
- struct ahc_initiator_tinfo *targ_info;
- struct ahc_tmode_tstate *tstate;
- ahc_fetch_devinfo(ahc, &devinfo);
- targ_info = ahc_fetch_transinfo(ahc,
- devinfo.channel,
- devinfo.our_scsiid,
- devinfo.target,
- &tstate);
- ahc_update_neg_request(ahc, &devinfo, tstate,
- targ_info, /*force*/TRUE);
- }
- #define AHC_MAX_STEPS 2000
- void
- ahc_clear_critical_section(struct ahc_softc *ahc)
- {
- int stepping;
- int steps;
- u_int simode0;
- u_int simode1;
- if (ahc->num_critical_sections == 0)
- return;
- stepping = FALSE;
- steps = 0;
- simode0 = 0;
- simode1 = 0;
- for (;;) {
- struct cs *cs;
- u_int seqaddr;
- u_int i;
- seqaddr = ahc_inb(ahc, SEQADDR0)
- | (ahc_inb(ahc, SEQADDR1) << 8);
- /*
- * Seqaddr represents the next instruction to execute,
- * so we are really executing the instruction just
- * before it.
- */
- if (seqaddr != 0)
- seqaddr -= 1;
- cs = ahc->critical_sections;
- for (i = 0; i < ahc->num_critical_sections; i++, cs++) {
-
- if (cs->begin < seqaddr && cs->end >= seqaddr)
- break;
- }
- if (i == ahc->num_critical_sections)
- break;
- if (steps > AHC_MAX_STEPS) {
- printf("%s: Infinite loop in critical sectionn",
- ahc_name(ahc));
- ahc_dump_card_state(ahc);
- panic("critical section loop");
- }
- steps++;
- if (stepping == FALSE) {
- /*
- * Disable all interrupt sources so that the
- * sequencer will not be stuck by a pausing
- * interrupt condition while we attempt to
- * leave a critical section.
- */
- simode0 = ahc_inb(ahc, SIMODE0);
- ahc_outb(ahc, SIMODE0, 0);
- simode1 = ahc_inb(ahc, SIMODE1);
- ahc_outb(ahc, SIMODE1, 0);
- ahc_outb(ahc, CLRINT, CLRSCSIINT);
- ahc_outb(ahc, SEQCTL, ahc_inb(ahc, SEQCTL) | STEP);
- stepping = TRUE;
- }
- ahc_outb(ahc, HCNTRL, ahc->unpause);
- do {
- ahc_delay(200);
- } while (!ahc_is_paused(ahc));
- }
- if (stepping) {
- ahc_outb(ahc, SIMODE0, simode0);
- ahc_outb(ahc, SIMODE1, simode1);
- ahc_outb(ahc, SEQCTL, ahc_inb(ahc, SEQCTL) & ~STEP);
- }
- }
- /*
- * Clear any pending interrupt status.
- */
- void
- ahc_clear_intstat(struct ahc_softc *ahc)
- {
- /* Clear any interrupt conditions this may have caused */
- ahc_outb(ahc, CLRSINT1, CLRSELTIMEO|CLRATNO|CLRSCSIRSTI
- |CLRBUSFREE|CLRSCSIPERR|CLRPHASECHG|
- CLRREQINIT);
- ahc_outb(ahc, CLRSINT0, CLRSELDO|CLRSELDI|CLRSELINGO);
- ahc_outb(ahc, CLRINT, CLRSCSIINT);
- }
- /**************************** Debugging Routines ******************************/
- void
- ahc_print_scb(struct scb *scb)
- {
- int i;
- struct hardware_scb *hscb = scb->hscb;
- printf("scb:%p control:0x%x scsiid:0x%x lun:%d cdb_len:%dn",
- (void *)scb,
- hscb->control,
- hscb->scsiid,
- hscb->lun,
- hscb->cdb_len);
- printf("Shared Data: ");
- for (i = 0; i < sizeof(hscb->shared_data.cdb); i++)
- printf("%#02x", hscb->shared_data.cdb[i]);
- printf(" dataptr:%#x datacnt:%#x sgptr:%#x tag:%#xn",
- ahc_le32toh(hscb->dataptr),
- ahc_le32toh(hscb->datacnt),
- ahc_le32toh(hscb->sgptr),
- hscb->tag);
- if (scb->sg_count > 0) {
- for (i = 0; i < scb->sg_count; i++) {
- printf("sg[%d] - Addr 0x%x%x : Length %dn",
- i,
- (ahc_le32toh(scb->sg_list[i].len) >> 24
- & SG_HIGH_ADDR_BITS),
- ahc_le32toh(scb->sg_list[i].addr),
- ahc_le32toh(scb->sg_list[i].len));
- }
- }
- }
- /************************* Transfer Negotiation *******************************/
- /*
- * Allocate per target mode instance (ID we respond to as a target)
- * transfer negotiation data structures.
- */
- static struct ahc_tmode_tstate *
- ahc_alloc_tstate(struct ahc_softc *ahc, u_int scsi_id, char channel)
- {
- struct ahc_tmode_tstate *master_tstate;
- struct ahc_tmode_tstate *tstate;
- int i;
- master_tstate = ahc->enabled_targets[ahc->our_id];
- if (channel == 'B') {
- scsi_id += 8;
- master_tstate = ahc->enabled_targets[ahc->our_id_b + 8];
- }
- if (ahc->enabled_targets[scsi_id] != NULL
- && ahc->enabled_targets[scsi_id] != master_tstate)
- panic("%s: ahc_alloc_tstate - Target already allocated",
- ahc_name(ahc));
- tstate = malloc(sizeof(*tstate), M_DEVBUF, M_NOWAIT);
- if (tstate == NULL)
- return (NULL);
- /*
- * If we have allocated a master tstate, copy user settings from
- * the master tstate (taken from SRAM or the EEPROM) for this
- * channel, but reset our current and goal settings to async/narrow
- * until an initiator talks to us.
- */
- if (master_tstate != NULL) {
- memcpy(tstate, master_tstate, sizeof(*tstate));
- memset(tstate->enabled_luns, 0, sizeof(tstate->enabled_luns));
- tstate->ultraenb = 0;
- for (i = 0; i < 16; i++) {
- memset(&tstate->transinfo[i].curr, 0,
- sizeof(tstate->transinfo[i].curr));
- memset(&tstate->transinfo[i].goal, 0,
- sizeof(tstate->transinfo[i].goal));
- }
- } else
- memset(tstate, 0, sizeof(*tstate));
- ahc->enabled_targets[scsi_id] = tstate;
- return (tstate);
- }
- #ifdef AHC_TARGET_MODE
- /*
- * Free per target mode instance (ID we respond to as a target)
- * transfer negotiation data structures.
- */
- static void
- ahc_free_tstate(struct ahc_softc *ahc, u_int scsi_id, char channel, int force)
- {
- struct ahc_tmode_tstate *tstate;
- /*
- * Don't clean up our "master" tstate.
- * It has our default user settings.
- */
- if (((channel == 'B' && scsi_id == ahc->our_id_b)
- || (channel == 'A' && scsi_id == ahc->our_id))
- && force == FALSE)
- return;
- if (channel == 'B')
- scsi_id += 8;
- tstate = ahc->enabled_targets[scsi_id];
- if (tstate != NULL)
- free(tstate, M_DEVBUF);
- ahc->enabled_targets[scsi_id] = NULL;
- }
- #endif
- /*
- * Called when we have an active connection to a target on the bus,
- * this function finds the nearest syncrate to the input period limited
- * by the capabilities of the bus connectivity of and sync settings for
- * the target.
- */
- struct ahc_syncrate *
- ahc_devlimited_syncrate(struct ahc_softc *ahc,
- struct ahc_initiator_tinfo *tinfo,
- u_int *period, u_int *ppr_options, role_t role) {
- struct ahc_transinfo *transinfo;
- u_int maxsync;
- if ((ahc->features & AHC_ULTRA2) != 0) {
- if ((ahc_inb(ahc, SBLKCTL) & ENAB40) != 0
- && (ahc_inb(ahc, SSTAT2) & EXP_ACTIVE) == 0) {
- maxsync = AHC_SYNCRATE_DT;
- } else {
- maxsync = AHC_SYNCRATE_ULTRA;
- /* Can't do DT on an SE bus */
- *ppr_options &= ~MSG_EXT_PPR_DT_REQ;
- }
- } else if ((ahc->features & AHC_ULTRA) != 0) {
- maxsync = AHC_SYNCRATE_ULTRA;
- } else {
- maxsync = AHC_SYNCRATE_FAST;
- }
- /*
- * Never allow a value higher than our current goal
- * period otherwise we may allow a target initiated
- * negotiation to go above the limit as set by the
- * user. In the case of an initiator initiated
- * sync negotiation, we limit based on the user
- * setting. This allows the system to still accept
- * incoming negotiations even if target initiated
- * negotiation is not performed.
- */
- if (role == ROLE_TARGET)
- transinfo = &tinfo->user;
- else
- transinfo = &tinfo->goal;
- *ppr_options &= transinfo->ppr_options;
- if (transinfo->period == 0) {
- *period = 0;
- *ppr_options = 0;
- return (NULL);
- }
- *period = MAX(*period, transinfo->period);
- return (ahc_find_syncrate(ahc, period, ppr_options, maxsync));
- }
- /*
- * Look up the valid period to SCSIRATE conversion in our table.
- * Return the period and offset that should be sent to the target
- * if this was the beginning of an SDTR.
- */
- struct ahc_syncrate *
- ahc_find_syncrate(struct ahc_softc *ahc, u_int *period,
- u_int *ppr_options, u_int maxsync)
- {
- struct ahc_syncrate *syncrate;
- if ((ahc->features & AHC_DT) == 0)
- *ppr_options &= ~MSG_EXT_PPR_DT_REQ;
- /* Skip all DT only entries if DT is not available */
- if ((*ppr_options & MSG_EXT_PPR_DT_REQ) == 0
- && maxsync < AHC_SYNCRATE_ULTRA2)
- maxsync = AHC_SYNCRATE_ULTRA2;
-
- for (syncrate = &ahc_syncrates[maxsync];
- syncrate->rate != NULL;
- syncrate++) {
- /*
- * The Ultra2 table doesn't go as low
- * as for the Fast/Ultra cards.
- */
- if ((ahc->features & AHC_ULTRA2) != 0
- && (syncrate->sxfr_u2 == 0))
- break;
- if (*period <= syncrate->period) {
- /*
- * When responding to a target that requests
- * sync, the requested rate may fall between
- * two rates that we can output, but still be
- * a rate that we can receive. Because of this,
- * we want to respond to the target with
- * the same rate that it sent to us even
- * if the period we use to send data to it
- * is lower. Only lower the response period
- * if we must.
- */
- if (syncrate == &ahc_syncrates[maxsync])
- *period = syncrate->period;
- /*
- * At some speeds, we only support
- * ST transfers.
- */
- if ((syncrate->sxfr_u2 & ST_SXFR) != 0)
- *ppr_options &= ~MSG_EXT_PPR_DT_REQ;
- break;
- }
- }
- if ((*period == 0)
- || (syncrate->rate == NULL)
- || ((ahc->features & AHC_ULTRA2) != 0
- && (syncrate->sxfr_u2 == 0))) {
- /* Use asynchronous transfers. */
- *period = 0;
- syncrate = NULL;
- *ppr_options &= ~MSG_EXT_PPR_DT_REQ;
- }
- return (syncrate);
- }
- /*
- * Convert from an entry in our syncrate table to the SCSI equivalent
- * sync "period" factor.
- */
- u_int
- ahc_find_period(struct ahc_softc *ahc, u_int scsirate, u_int maxsync)
- {
- struct ahc_syncrate *syncrate;
- if ((ahc->features & AHC_ULTRA2) != 0)
- scsirate &= SXFR_ULTRA2;
- else
- scsirate &= SXFR;
- syncrate = &ahc_syncrates[maxsync];
- while (syncrate->rate != NULL) {
- if ((ahc->features & AHC_ULTRA2) != 0) {
- if (syncrate->sxfr_u2 == 0)
- break;
- else if (scsirate == (syncrate->sxfr_u2 & SXFR_ULTRA2))
- return (syncrate->period);
- } else if (scsirate == (syncrate->sxfr & SXFR)) {
- return (syncrate->period);
- }
- syncrate++;
- }
- return (0); /* async */
- }
- /*
- * Truncate the given synchronous offset to a value the
- * current adapter type and syncrate are capable of.
- */
- void
- ahc_validate_offset(struct ahc_softc *ahc,
- struct ahc_initiator_tinfo *tinfo,
- struct ahc_syncrate *syncrate,
- u_int *offset, int wide, role_t role)
- {
- u_int maxoffset;
- /* Limit offset to what we can do */
- if (syncrate == NULL) {
- maxoffset = 0;
- } else if ((ahc->features & AHC_ULTRA2) != 0) {
- maxoffset = MAX_OFFSET_ULTRA2;
- } else {
- if (wide)
- maxoffset = MAX_OFFSET_16BIT;
- else
- maxoffset = MAX_OFFSET_8BIT;
- }
- *offset = MIN(*offset, maxoffset);
- if (tinfo != NULL) {
- if (role == ROLE_TARGET)
- *offset = MIN(*offset, tinfo->user.offset);
- else
- *offset = MIN(*offset, tinfo->goal.offset);
- }
- }
- /*
- * Truncate the given transfer width parameter to a value the
- * current adapter type is capable of.
- */
- void
- ahc_validate_width(struct ahc_softc *ahc, struct ahc_initiator_tinfo *tinfo,
- u_int *bus_width, role_t role)
- {
- switch (*bus_width) {
- default:
- if (ahc->features & AHC_WIDE) {
- /* Respond Wide */
- *bus_width = MSG_EXT_WDTR_BUS_16_BIT;
- break;
- }
- /* FALLTHROUGH */
- case MSG_EXT_WDTR_BUS_8_BIT:
- *bus_width = MSG_EXT_WDTR_BUS_8_BIT;
- break;
- }
- if (tinfo != NULL) {
- if (role == ROLE_TARGET)
- *bus_width = MIN(tinfo->user.width, *bus_width);
- else
- *bus_width = MIN(tinfo->goal.width, *bus_width);
- }
- }
- /*
- * Update the bitmask of targets for which the controller should
- * negotiate with at the next convenient oportunity. This currently
- * means the next time we send the initial identify messages for
- * a new transaction.
- */
- int
- ahc_update_neg_request(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
- struct ahc_tmode_tstate *tstate,
- struct ahc_initiator_tinfo *tinfo, int force)
- {
- u_int auto_negotiate_orig;
- auto_negotiate_orig = tstate->auto_negotiate;
- if (tinfo->curr.period != tinfo->goal.period
- || tinfo->curr.width != tinfo->goal.width
- || tinfo->curr.offset != tinfo->goal.offset
- || tinfo->curr.ppr_options != tinfo->goal.ppr_options
- || (force
- && (tinfo->goal.period != 0
- || tinfo->goal.width != MSG_EXT_WDTR_BUS_8_BIT
- || tinfo->goal.ppr_options != 0)))
- tstate->auto_negotiate |= devinfo->target_mask;
- else
- tstate->auto_negotiate &= ~devinfo->target_mask;
- return (auto_negotiate_orig != tstate->auto_negotiate);
- }
- /*
- * Update the user/goal/curr tables of synchronous negotiation
- * parameters as well as, in the case of a current or active update,
- * any data structures on the host controller. In the case of an
- * active update, the specified target is currently talking to us on
- * the bus, so the transfer parameter update must take effect
- * immediately.
- */
- void
- ahc_set_syncrate(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
- struct ahc_syncrate *syncrate, u_int period,
- u_int offset, u_int ppr_options, u_int type, int paused)
- {
- struct ahc_initiator_tinfo *tinfo;
- struct ahc_tmode_tstate *tstate;
- u_int old_period;
- u_int old_offset;
- u_int old_ppr;
- int active;
- int update_needed;
- active = (type & AHC_TRANS_ACTIVE) == AHC_TRANS_ACTIVE;
- update_needed = 0;
- if (syncrate == NULL) {
- period = 0;
- offset = 0;
- }
- tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid,
- devinfo->target, &tstate);
- if ((type & AHC_TRANS_USER) != 0) {
- tinfo->user.period = period;
- tinfo->user.offset = offset;
- tinfo->user.ppr_options = ppr_options;
- }
- if ((type & AHC_TRANS_GOAL) != 0) {
- tinfo->goal.period = period;
- tinfo->goal.offset = offset;
- tinfo->goal.ppr_options = ppr_options;
- }
- old_period = tinfo->curr.period;
- old_offset = tinfo->curr.offset;
- old_ppr = tinfo->curr.ppr_options;
- if ((type & AHC_TRANS_CUR) != 0
- && (old_period != period
- || old_offset != offset
- || old_ppr != ppr_options)) {
- u_int scsirate;
- update_needed++;
- scsirate = tinfo->scsirate;
- if ((ahc->features & AHC_ULTRA2) != 0) {
- scsirate &= ~(SXFR_ULTRA2|SINGLE_EDGE|ENABLE_CRC);
- if (syncrate != NULL) {
- scsirate |= syncrate->sxfr_u2;
- if ((ppr_options & MSG_EXT_PPR_DT_REQ) != 0)
- scsirate |= ENABLE_CRC;
- else
- scsirate |= SINGLE_EDGE;
- }
- } else {
- scsirate &= ~(SXFR|SOFS);
- /*
- * Ensure Ultra mode is set properly for
- * this target.
- */
- tstate->ultraenb &= ~devinfo->target_mask;
- if (syncrate != NULL) {
- if (syncrate->sxfr & ULTRA_SXFR) {
- tstate->ultraenb |=
- devinfo->target_mask;
- }
- scsirate |= syncrate->sxfr & SXFR;
- scsirate |= offset & SOFS;
- }
- if (active) {
- u_int sxfrctl0;
- sxfrctl0 = ahc_inb(ahc, SXFRCTL0);
- sxfrctl0 &= ~FAST20;
- if (tstate->ultraenb & devinfo->target_mask)
- sxfrctl0 |= FAST20;
- ahc_outb(ahc, SXFRCTL0, sxfrctl0);
- }
- }
- if (active) {
- ahc_outb(ahc, SCSIRATE, scsirate);
- if ((ahc->features & AHC_ULTRA2) != 0)
- ahc_outb(ahc, SCSIOFFSET, offset);
- }
- tinfo->scsirate = scsirate;
- tinfo->curr.period = period;
- tinfo->curr.offset = offset;
- tinfo->curr.ppr_options = ppr_options;
- ahc_send_async(ahc, devinfo->channel, devinfo->target,
- CAM_LUN_WILDCARD, AC_TRANSFER_NEG, NULL);
- if (bootverbose) {
- if (offset != 0) {
- printf("%s: target %d synchronous at %sMHz%s, "
- "offset = 0x%xn", ahc_name(ahc),
- devinfo->target, syncrate->rate,
- (ppr_options & MSG_EXT_PPR_DT_REQ)
- ? " DT" : "", offset);
- } else {
- printf("%s: target %d using "
- "asynchronous transfersn",
- ahc_name(ahc), devinfo->target);
- }
- }
- }
- update_needed += ahc_update_neg_request(ahc, devinfo, tstate,
- tinfo, /*force*/FALSE);
- if (update_needed)
- ahc_update_pending_scbs(ahc);
- }
- /*
- * Update the user/goal/curr tables of wide negotiation
- * parameters as well as, in the case of a current or active update,
- * any data structures on the host controller. In the case of an
- * active update, the specified target is currently talking to us on
- * the bus, so the transfer parameter update must take effect
- * immediately.
- */
- void
- ahc_set_width(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
- u_int width, u_int type, int paused)
- {
- struct ahc_initiator_tinfo *tinfo;
- struct ahc_tmode_tstate *tstate;
- u_int oldwidth;
- int active;
- int update_needed;
- active = (type & AHC_TRANS_ACTIVE) == AHC_TRANS_ACTIVE;
- update_needed = 0;
- tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid,
- devinfo->target, &tstate);
- if ((type & AHC_TRANS_USER) != 0)
- tinfo->user.width = width;
- if ((type & AHC_TRANS_GOAL) != 0)
- tinfo->goal.width = width;
- oldwidth = tinfo->curr.width;
- if ((type & AHC_TRANS_CUR) != 0 && oldwidth != width) {
- u_int scsirate;
- update_needed++;
- scsirate = tinfo->scsirate;
- scsirate &= ~WIDEXFER;
- if (width == MSG_EXT_WDTR_BUS_16_BIT)
- scsirate |= WIDEXFER;
- tinfo->scsirate = scsirate;
- if (active)
- ahc_outb(ahc, SCSIRATE, scsirate);
- tinfo->curr.width = width;
- ahc_send_async(ahc, devinfo->channel, devinfo->target,
- CAM_LUN_WILDCARD, AC_TRANSFER_NEG, NULL);
- if (bootverbose) {
- printf("%s: target %d using %dbit transfersn",
- ahc_name(ahc), devinfo->target,
- 8 * (0x01 << width));
- }
- }
- update_needed += ahc_update_neg_request(ahc, devinfo, tstate,
- tinfo, /*force*/FALSE);
- if (update_needed)
- ahc_update_pending_scbs(ahc);
- }
- /*
- * Update the current state of tagged queuing for a given target.
- */
- void
- ahc_set_tags(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
- ahc_queue_alg alg)
- {
- ahc_platform_set_tags(ahc, devinfo, alg);
- ahc_send_async(ahc, devinfo->channel, devinfo->target,
- devinfo->lun, AC_TRANSFER_NEG, &alg);
- }
- /*
- * When the transfer settings for a connection change, update any
- * in-transit SCBs to contain the new data so the hardware will
- * be set correctly during future (re)selections.
- */
- static void
- ahc_update_pending_scbs(struct ahc_softc *ahc)
- {
- struct scb *pending_scb;
- int pending_scb_count;
- int i;
- int paused;
- u_int saved_scbptr;
- /*
- * Traverse the pending SCB list and ensure that all of the
- * SCBs there have the proper settings.
- */
- pending_scb_count = 0;
- LIST_FOREACH(pending_scb, &ahc->pending_scbs, pending_links) {
- struct ahc_devinfo devinfo;
- struct hardware_scb *pending_hscb;
- struct ahc_initiator_tinfo *tinfo;
- struct ahc_tmode_tstate *tstate;
- ahc_scb_devinfo(ahc, &devinfo, pending_scb);
- tinfo = ahc_fetch_transinfo(ahc, devinfo.channel,
- devinfo.our_scsiid,
- devinfo.target, &tstate);
- pending_hscb = pending_scb->hscb;
- pending_hscb->control &= ~ULTRAENB;
- if ((tstate->ultraenb & devinfo.target_mask) != 0)
- pending_hscb->control |= ULTRAENB;
- pending_hscb->scsirate = tinfo->scsirate;
- pending_hscb->scsioffset = tinfo->curr.offset;
- if ((tstate->auto_negotiate & devinfo.target_mask) == 0
- && (pending_scb->flags & SCB_AUTO_NEGOTIATE) != 0) {
- pending_scb->flags &= ~SCB_AUTO_NEGOTIATE;
- pending_hscb->control &= ~MK_MESSAGE;
- }
- ahc_sync_scb(ahc, pending_scb,
- BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
- pending_scb_count++;
- }
- if (pending_scb_count == 0)
- return;
- if (ahc_is_paused(ahc)) {
- paused = 1;
- } else {
- paused = 0;
- ahc_pause(ahc);
- }
- saved_scbptr = ahc_inb(ahc, SCBPTR);
- /* Ensure that the hscbs down on the card match the new information */
- for (i = 0; i < ahc->scb_data->maxhscbs; i++) {
- struct hardware_scb *pending_hscb;
- u_int control;
- u_int scb_tag;
- ahc_outb(ahc, SCBPTR, i);
- scb_tag = ahc_inb(ahc, SCB_TAG);
- pending_scb = ahc_lookup_scb(ahc, scb_tag);
- if (pending_scb == NULL)
- continue;
- pending_hscb = pending_scb->hscb;
- control = ahc_inb(ahc, SCB_CONTROL);
- control &= ~(ULTRAENB|MK_MESSAGE);
- control |= pending_hscb->control & (ULTRAENB|MK_MESSAGE);
- ahc_outb(ahc, SCB_CONTROL, control);
- ahc_outb(ahc, SCB_SCSIRATE, pending_hscb->scsirate);
- ahc_outb(ahc, SCB_SCSIOFFSET, pending_hscb->scsioffset);
- }
- ahc_outb(ahc, SCBPTR, saved_scbptr);
- if (paused == 0)
- ahc_unpause(ahc);
- }
- /**************************** Pathing Information *****************************/
- static void
- ahc_fetch_devinfo(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
- {
- u_int saved_scsiid;
- role_t role;
- int our_id;
- if (ahc_inb(ahc, SSTAT0) & TARGET)
- role = ROLE_TARGET;
- else
- role = ROLE_INITIATOR;
- if (role == ROLE_TARGET
- && (ahc->features & AHC_MULTI_TID) != 0
- && (ahc_inb(ahc, SEQ_FLAGS) & CMDPHASE_PENDING) != 0) {
- /* We were selected, so pull our id from TARGIDIN */
- our_id = ahc_inb(ahc, TARGIDIN) & OID;
- } else if ((ahc->features & AHC_ULTRA2) != 0)
- our_id = ahc_inb(ahc, SCSIID_ULTRA2) & OID;
- else
- our_id = ahc_inb(ahc, SCSIID) & OID;
- saved_scsiid = ahc_inb(ahc, SAVED_SCSIID);
- ahc_compile_devinfo(devinfo,
- our_id,
- SCSIID_TARGET(ahc, saved_scsiid),
- ahc_inb(ahc, SAVED_LUN),
- SCSIID_CHANNEL(ahc, saved_scsiid),
- role);
- }
- struct ahc_phase_table_entry*
- ahc_lookup_phase_entry(int phase)
- {
- struct ahc_phase_table_entry *entry;
- struct ahc_phase_table_entry *last_entry;
- /*
- * num_phases doesn't include the default entry which
- * will be returned if the phase doesn't match.
- */
- last_entry = &ahc_phase_table[num_phases];
- for (entry = ahc_phase_table; entry < last_entry; entry++) {
- if (phase == entry->phase)
- break;
- }
- return (entry);
- }
- void
- ahc_compile_devinfo(struct ahc_devinfo *devinfo, u_int our_id, u_int target,
- u_int lun, char channel, role_t role)
- {
- devinfo->our_scsiid = our_id;
- devinfo->target = target;
- devinfo->lun = lun;
- devinfo->target_offset = target;
- devinfo->channel = channel;
- devinfo->role = role;
- if (channel == 'B')
- devinfo->target_offset += 8;
- devinfo->target_mask = (0x01 << devinfo->target_offset);
- }
- static void
- ahc_scb_devinfo(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
- struct scb *scb)
- {
- role_t role;
- int our_id;
- our_id = SCSIID_OUR_ID(scb->hscb->scsiid);
- role = ROLE_INITIATOR;
- if ((scb->hscb->control & TARGET_SCB) != 0)
- role = ROLE_TARGET;
- ahc_compile_devinfo(devinfo, our_id, SCB_GET_TARGET(ahc, scb),
- SCB_GET_LUN(scb), SCB_GET_CHANNEL(ahc, scb), role);
- }
- /************************ Message Phase Processing ****************************/
- static void
- ahc_assert_atn(struct ahc_softc *ahc)
- {
- u_int scsisigo;
- scsisigo = ATNO;
- if ((ahc->features & AHC_DT) == 0)
- scsisigo |= ahc_inb(ahc, SCSISIGI);
- ahc_outb(ahc, SCSISIGO, scsisigo);
- }
- /*
- * When an initiator transaction with the MK_MESSAGE flag either reconnects
- * or enters the initial message out phase, we are interrupted. Fill our
- * outgoing message buffer with the appropriate message and beging handing
- * the message phase(s) manually.
- */
- static void
- ahc_setup_initiator_msgout(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
- struct scb *scb)
- {
- /*
- * To facilitate adding multiple messages together,
- * each routine should increment the index and len
- * variables instead of setting them explicitly.
- */
- ahc->msgout_index = 0;
- ahc->msgout_len = 0;
- if ((scb->flags & SCB_DEVICE_RESET) == 0
- && ahc_inb(ahc, MSG_OUT) == MSG_IDENTIFYFLAG) {
- u_int identify_msg;
- identify_msg = MSG_IDENTIFYFLAG | SCB_GET_LUN(scb);
- if ((scb->hscb->control & DISCENB) != 0)
- identify_msg |= MSG_IDENTIFY_DISCFLAG;
- ahc->msgout_buf[ahc->msgout_index++] = identify_msg;
- ahc->msgout_len++;
- if ((scb->hscb->control & TAG_ENB) != 0) {
- ahc->msgout_buf[ahc->msgout_index++] =
- scb->hscb->control & (TAG_ENB|SCB_TAG_TYPE);
- ahc->msgout_buf[ahc->msgout_index++] = scb->hscb->tag;
- ahc->msgout_len += 2;
- }
- }
- if (scb->flags & SCB_DEVICE_RESET) {
- ahc->msgout_buf[ahc->msgout_index++] = MSG_BUS_DEV_RESET;
- ahc->msgout_len++;
- ahc_print_path(ahc, scb);
- printf("Bus Device Reset Message Sentn");
- /*
- * Clear our selection hardware in advance of
- * the busfree. We may have an entry in the waiting
- * Q for this target, and we don't want to go about
- * selecting while we handle the busfree and blow it
- * away.
- */
- ahc_outb(ahc, SCSISEQ, (ahc_inb(ahc, SCSISEQ) & ~ENSELO));
- } else if ((scb->flags & SCB_ABORT) != 0) {
- if ((scb->hscb->control & TAG_ENB) != 0)
- ahc->msgout_buf[ahc->msgout_index++] = MSG_ABORT_TAG;
- else
- ahc->msgout_buf[ahc->msgout_index++] = MSG_ABORT;
- ahc->msgout_len++;
- ahc_print_path(ahc, scb);
- printf("Abort%s Message Sentn",
- (scb->hscb->control & TAG_ENB) != 0 ? " Tag" : "");
- /*
- * Clear our selection hardware in advance of
- * the busfree. We may have an entry in the waiting
- * Q for this target, and we don't want to go about
- * selecting while we handle the busfree and blow it
- * away.
- */
- ahc_outb(ahc, SCSISEQ, (ahc_inb(ahc, SCSISEQ) & ~ENSELO));
- } else if ((scb->flags & (SCB_AUTO_NEGOTIATE|SCB_NEGOTIATE)) != 0) {
- ahc_build_transfer_msg(ahc, devinfo);
- } else {
- printf("ahc_intr: AWAITING_MSG for an SCB that "
- "does not have a waiting messagen");
- printf("SCSIID = %x, target_mask = %xn", scb->hscb->scsiid,
- devinfo->target_mask);
- panic("SCB = %d, SCB Control = %x, MSG_OUT = %x "
- "SCB flags = %x", scb->hscb->tag, scb->hscb->control,
- ahc_inb(ahc, MSG_OUT), scb->flags);
- }
- /*
- * Clear the MK_MESSAGE flag from the SCB so we aren't
- * asked to send this message again.
- */
- ahc_outb(ahc, SCB_CONTROL, ahc_inb(ahc, SCB_CONTROL) & ~MK_MESSAGE);
- scb->hscb->control &= ~MK_MESSAGE;
- ahc->msgout_index = 0;
- ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
- }
- /*
- * Build an appropriate transfer negotiation message for the
- * currently active target.
- */
- static void
- ahc_build_transfer_msg(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
- {
- /*
- * We need to initiate transfer negotiations.
- * If our current and goal settings are identical,
- * we want to renegotiate due to a check condition.
- */
- struct ahc_initiator_tinfo *tinfo;
- struct ahc_tmode_tstate *tstate;
- struct ahc_syncrate *rate;
- int dowide;
- int dosync;
- int doppr;
- int use_ppr;
- u_int period;
- u_int ppr_options;
- u_int offset;
- tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid,
- devinfo->target, &tstate);
- /*
- * Filter our period based on the current connection.
- * If we can't perform DT transfers on this segment (not in LVD
- * mode for instance), then our decision to issue a PPR message
- * may change.
- */
- period = tinfo->goal.period;
- ppr_options = tinfo->goal.ppr_options;
- /* Target initiated PPR is not allowed in the SCSI spec */
- if (devinfo->role == ROLE_TARGET)
- ppr_options = 0;
- rate = ahc_devlimited_syncrate(ahc, tinfo, &period,
- &ppr_options, devinfo->role);
- dowide = tinfo->curr.width != tinfo->goal.width;
- dosync = tinfo->curr.period != period;
- doppr = tinfo->curr.ppr_options != ppr_options;
- if (!dowide && !dosync && !doppr) {
- dowide = tinfo->goal.width != MSG_EXT_WDTR_BUS_8_BIT;
- dosync = tinfo->goal.period != 0;
- doppr = tinfo->goal.ppr_options != 0;
- }
- if (!dowide && !dosync && !doppr) {
- panic("ahc_intr: AWAITING_MSG for negotiation, "
- "but no negotiation neededn");
- }
- use_ppr = (tinfo->curr.transport_version >= 3) || doppr;
- /* Target initiated PPR is not allowed in the SCSI spec */
- if (devinfo->role == ROLE_TARGET)
- use_ppr = 0;
- /*
- * Both the PPR message and SDTR message require the
- * goal syncrate to be limited to what the target device
- * is capable of handling (based on whether an LVD->SE
- * expander is on the bus), so combine these two cases.
- * Regardless, guarantee that if we are using WDTR and SDTR
- * messages that WDTR comes first.
- */
- if (use_ppr || (dosync && !dowide)) {
- offset = tinfo->goal.offset;
- ahc_validate_offset(ahc, tinfo, rate, &offset,
- use_ppr ? tinfo->goal.width
- : tinfo->curr.width,
- devinfo->role);
- if (use_ppr) {
- ahc_construct_ppr(ahc, devinfo, period, offset,
- tinfo->goal.width, ppr_options);
- } else {
- ahc_construct_sdtr(ahc, devinfo, period, offset);
- }
- } else {
- ahc_construct_wdtr(ahc, devinfo, tinfo->goal.width);
- }
- }
- /*
- * Build a synchronous negotiation message in our message
- * buffer based on the input parameters.
- */
- static void
- ahc_construct_sdtr(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
- u_int period, u_int offset)
- {
- ahc->msgout_buf[ahc->msgout_index++] = MSG_EXTENDED;
- ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_SDTR_LEN;
- ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_SDTR;
- ahc->msgout_buf[ahc->msgout_index++] = period;
- ahc->msgout_buf[ahc->msgout_index++] = offset;
- ahc->msgout_len += 5;
- if (bootverbose) {
- printf("(%s:%c:%d:%d): Sending SDTR period %x, offset %xn",
- ahc_name(ahc), devinfo->channel, devinfo->target,
- devinfo->lun, period, offset);
- }
- }
- /*
- * Build a wide negotiation message in our message
- * buffer based on the input parameters.
- */
- static void
- ahc_construct_wdtr(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
- u_int bus_width)
- {
- ahc->msgout_buf[ahc->msgout_index++] = MSG_EXTENDED;
- ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_WDTR_LEN;
- ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_WDTR;
- ahc->msgout_buf[ahc->msgout_index++] = bus_width;
- ahc->msgout_len += 4;
- if (bootverbose) {
- printf("(%s:%c:%d:%d): Sending WDTR %xn",
- ahc_name(ahc), devinfo->channel, devinfo->target,
- devinfo->lun, bus_width);
- }
- }
- /*
- * Build a parallel protocol request message in our message
- * buffer based on the input parameters.
- */
- static void
- ahc_construct_ppr(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
- u_int period, u_int offset, u_int bus_width,
- u_int ppr_options)
- {
- ahc->msgout_buf[ahc->msgout_index++] = MSG_EXTENDED;
- ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_PPR_LEN;
- ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_PPR;
- ahc->msgout_buf[ahc->msgout_index++] = period;
- ahc->msgout_buf[ahc->msgout_index++] = 0;
- ahc->msgout_buf[ahc->msgout_index++] = offset;
- ahc->msgout_buf[ahc->msgout_index++] = bus_width;
- ahc->msgout_buf[ahc->msgout_index++] = ppr_options;
- ahc->msgout_len += 8;
- if (bootverbose) {
- printf("(%s:%c:%d:%d): Sending PPR bus_width %x, period %x, "
- "offset %x, ppr_options %xn", ahc_name(ahc),
- devinfo->channel, devinfo->target, devinfo->lun,
- bus_width, period, offset, ppr_options);
- }
- }
- /*
- * Clear any active message state.
- */
- static void
- ahc_clear_msg_state(struct ahc_softc *ahc)
- {
- ahc->msgout_len = 0;
- ahc->msgin_index = 0;
- ahc->msg_type = MSG_TYPE_NONE;
- if ((ahc_inb(ahc, SCSISIGI) & ATNI) != 0) {
- /*
- * The target didn't care to respond to our
- * message request, so clear ATN.
- */
- ahc_outb(ahc, CLRSINT1, CLRATNO);
- }
- ahc_outb(ahc, MSG_OUT, MSG_NOOP);
- ahc_outb(ahc, SEQ_FLAGS2,
- ahc_inb(ahc, SEQ_FLAGS2) & ~TARGET_MSG_PENDING);
- }
- /*
- * Manual message loop handler.
- */
- static void
- ahc_handle_message_phase(struct ahc_softc *ahc)
- {
- struct ahc_devinfo devinfo;
- u_int bus_phase;
- int end_session;
- ahc_fetch_devinfo(ahc, &devinfo);
- end_session = FALSE;
- bus_phase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK;
- reswitch:
- switch (ahc->msg_type) {
- case MSG_TYPE_INITIATOR_MSGOUT:
- {
- int lastbyte;
- int phasemis;
- int msgdone;
- if (ahc->msgout_len == 0)
- panic("HOST_MSG_LOOP interrupt with no active message");
- phasemis = bus_phase != P_MESGOUT;
- if (phasemis) {
- if (bus_phase == P_MESGIN) {
- /*
- * Change gears and see if
- * this messages is of interest to
- * us or should be passed back to
- * the sequencer.
- */
- ahc_outb(ahc, CLRSINT1, CLRATNO);
- ahc->send_msg_perror = FALSE;
- ahc->msg_type = MSG_TYPE_INITIATOR_MSGIN;
- ahc->msgin_index = 0;
- goto reswitch;
- }
- end_session = TRUE;
- break;
- }
- if (ahc->send_msg_perror) {
- ahc_outb(ahc, CLRSINT1, CLRATNO);
- ahc_outb(ahc, CLRSINT1, CLRREQINIT);
- ahc_outb(ahc, SCSIDATL, MSG_PARITY_ERROR);
- break;
- }
- msgdone = ahc->msgout_index == ahc->msgout_len;
- if (msgdone) {
- /*
- * The target has requested a retry.
- * Re-assert ATN, reset our message index to
- * 0, and try again.
- */
- ahc->msgout_index = 0;
- ahc_assert_atn(ahc);
- }
- lastbyte = ahc->msgout_index == (ahc->msgout_len - 1);
- if (lastbyte) {
- /* Last byte is signified by dropping ATN */
- ahc_outb(ahc, CLRSINT1, CLRATNO);
- }
- /*
- * Clear our interrupt status and present
- * the next byte on the bus.
- */
- ahc_outb(ahc, CLRSINT1, CLRREQINIT);
- ahc_outb(ahc, SCSIDATL, ahc->msgout_buf[ahc->msgout_index++]);
- break;
- }
- case MSG_TYPE_INITIATOR_MSGIN:
- {
- int phasemis;
- int message_done;
- phasemis = bus_phase != P_MESGIN;
- if (phasemis) {
- ahc->msgin_index = 0;
- if (bus_phase == P_MESGOUT
- && (ahc->send_msg_perror == TRUE
- || (ahc->msgout_len != 0
- && ahc->msgout_index == 0))) {
- ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
- goto reswitch;
- }
- end_session = TRUE;
- break;
- }
- /* Pull the byte in without acking it */
- ahc->msgin_buf[ahc->msgin_index] = ahc_inb(ahc, SCSIBUSL);
- message_done = ahc_parse_msg(ahc, &devinfo);
- if (message_done) {
- /*
- * Clear our incoming message buffer in case there
- * is another message following this one.
- */
- ahc->msgin_index = 0;
- /*
- * If this message illicited a response,
- * assert ATN so the target takes us to the
- * message out phase.
- */
- if (ahc->msgout_len != 0)
- ahc_assert_atn(ahc);
- } else
- ahc->msgin_index++;
- /* Ack the byte */
- ahc_outb(ahc, CLRSINT1, CLRREQINIT);
- ahc_inb(ahc, SCSIDATL);
- break;
- }
- case MSG_TYPE_TARGET_MSGIN:
- {
- int msgdone;
- int msgout_request;
- if (ahc->msgout_len == 0)
- panic("Target MSGIN with no active message");
- /*
- * If we interrupted a mesgout session, the initiator
- * will not know this until our first REQ. So, we
- * only honor mesgout requests after we've sent our
- * first byte.
- */
- if ((ahc_inb(ahc, SCSISIGI) & ATNI) != 0
- && ahc->msgout_index > 0)
- msgout_request = TRUE;
- else
- msgout_request = FALSE;
- if (msgout_request) {
- /*
- * Change gears and see if
- * this messages is of interest to
- * us or should be passed back to
- * the sequencer.
- */
- ahc->msg_type = MSG_TYPE_TARGET_MSGOUT;
- ahc_outb(ahc, SCSISIGO, P_MESGOUT | BSYO);
- ahc->msgin_index = 0;
- /* Dummy read to REQ for first byte */
- ahc_inb(ahc, SCSIDATL);
- ahc_outb(ahc, SXFRCTL0,
- ahc_inb(ahc, SXFRCTL0) | SPIOEN);
- break;
- }
- msgdone = ahc->msgout_index == ahc->msgout_len;
- if (msgdone) {
- ahc_outb(ahc, SXFRCTL0,
- ahc_inb(ahc, SXFRCTL0) & ~SPIOEN);
- end_session = TRUE;
- break;
- }
- /*
- * Present the next byte on the bus.
- */
- ahc_outb(ahc, SXFRCTL0, ahc_inb(ahc, SXFRCTL0) | SPIOEN);
- ahc_outb(ahc, SCSIDATL, ahc->msgout_buf[ahc->msgout_index++]);
- break;
- }
- case MSG_TYPE_TARGET_MSGOUT:
- {
- int lastbyte;
- int msgdone;
- /*
- * The initiator signals that this is
- * the last byte by dropping ATN.
- */
- lastbyte = (ahc_inb(ahc, SCSISIGI) & ATNI) == 0;
- /*
- * Read the latched byte, but turn off SPIOEN first
- * so that we don't inadvertantly cause a REQ for the
- * next byte.
- */
- ahc_outb(ahc, SXFRCTL0, ahc_inb(ahc, SXFRCTL0) & ~SPIOEN);
- ahc->msgin_buf[ahc->msgin_index] = ahc_inb(ahc, SCSIDATL);
- msgdone = ahc_parse_msg(ahc, &devinfo);
- if (msgdone == MSGLOOP_TERMINATED) {
- /*
- * The message is *really* done in that it caused
- * us to go to bus free. The sequencer has already
- * been reset at this point, so pull the ejection
- * handle.
- */
- return;
- }
-
- ahc->msgin_index++;
- /*
- * XXX Read spec about initiator dropping ATN too soon
- * and use msgdone to detect it.
- */
- if (msgdone == MSGLOOP_MSGCOMPLETE) {
- ahc->msgin_index = 0;
- /*
- * If this message illicited a response, transition
- * to the Message in phase and send it.
- */
- if (ahc->msgout_len != 0) {
- ahc_outb(ahc, SCSISIGO, P_MESGIN | BSYO);
- ahc_outb(ahc, SXFRCTL0,
- ahc_inb(ahc, SXFRCTL0) | SPIOEN);
- ahc->msg_type = MSG_TYPE_TARGET_MSGIN;
- ahc->msgin_index = 0;
- break;
- }
- }
- if (lastbyte)
- end_session = TRUE;
- else {
- /* Ask for the next byte. */
- ahc_outb(ahc, SXFRCTL0,
- ahc_inb(ahc, SXFRCTL0) | SPIOEN);
- }
- break;
- }
- default:
- panic("Unknown REQINIT message type");
- }
- if (end_session) {
- ahc_clear_msg_state(ahc);
- ahc_outb(ahc, RETURN_1, EXIT_MSG_LOOP);
- } else
- ahc_outb(ahc, RETURN_1, CONT_MSG_LOOP);
- }
- /*
- * See if we sent a particular extended message to the target.
- * If "full" is true, return true only if the target saw the full
- * message. If "full" is false, return true if the target saw at
- * least the first byte of the message.
- */
- static int
- ahc_sent_msg(struct ahc_softc *ahc, ahc_msgtype type, u_int msgval, int full)
- {
- int found;
- u_int index;
- found = FALSE;
- index = 0;
- while (index < ahc->msgout_len) {
- if (ahc->msgout_buf[index] == MSG_EXTENDED) {
- u_int end_index;
- end_index = index + 1 + ahc->msgout_buf[index + 1];
- if (ahc->msgout_buf[index+2] == msgval
- && type == AHCMSG_EXT) {
- if (full) {
- if (ahc->msgout_index > end_index)
- found = TRUE;
- } else if (ahc->msgout_index > index)
- found = TRUE;
- }
- index = end_index;
- } else if (ahc->msgout_buf[index] >= MSG_SIMPLE_TASK
- && ahc->msgout_buf[index] <= MSG_IGN_WIDE_RESIDUE) {
- /* Skip tag type and tag id or residue param*/
- index += 2;
- } else {
- /* Single byte message */
- if (type == AHCMSG_1B
- && ahc->msgout_buf[index] == msgval
- && ahc->msgout_index > index)
- found = TRUE;
- index++;
- }
- if (found)
- break;
- }
- return (found);
- }
- /*
- * Wait for a complete incoming message, parse it, and respond accordingly.
- */
- static int
- ahc_parse_msg(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
- {
- struct ahc_initiator_tinfo *tinfo;
- struct ahc_tmode_tstate *tstate;
- int reject;
- int done;
- int response;
- u_int targ_scsirate;
- done = MSGLOOP_IN_PROG;
- response = FALSE;
- reject = FALSE;
- tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid,
- devinfo->target, &tstate);
- targ_scsirate = tinfo->scsirate;
- /*
- * Parse as much of the message as is availible,
- * rejecting it if we don't support it. When
- * the entire message is availible and has been
- * handled, return MSGLOOP_MSGCOMPLETE, indicating
- * that we have parsed an entire message.
- *
- * In the case of extended messages, we accept the length
- * byte outright and perform more checking once we know the
- * extended message type.
- */
- switch (ahc->msgin_buf[0]) {
- case MSG_MESSAGE_REJECT:
- response = ahc_handle_msg_reject(ahc, devinfo);
- /* FALLTHROUGH */
- case MSG_NOOP:
- done = MSGLOOP_MSGCOMPLETE;
- break;
- case MSG_EXTENDED:
- {
- /* Wait for enough of the message to begin validation */
- if (ahc->msgin_index < 2)
- break;
- switch (ahc->msgin_buf[2]) {
- case MSG_EXT_SDTR:
- {
- struct ahc_syncrate *syncrate;
- u_int period;
- u_int ppr_options;
- u_int offset;
- u_int saved_offset;
-
- if (ahc->msgin_buf[1] != MSG_EXT_SDTR_LEN) {
- reject = TRUE;
- break;
- }
- /*
- * Wait until we have both args before validating
- * and acting on this message.
- *
- * Add one to MSG_EXT_SDTR_LEN to account for
- * the extended message preamble.
- */
- if (ahc->msgin_index < (MSG_EXT_SDTR_LEN + 1))
- break;
- period = ahc->msgin_buf[3];
- ppr_options = 0;
- saved_offset = offset = ahc->msgin_buf[4];
- syncrate = ahc_devlimited_syncrate(ahc, tinfo, &period,
- &ppr_options,
- devinfo->role);
- ahc_validate_offset(ahc, tinfo, syncrate, &offset,
- targ_scsirate & WIDEXFER,
- devinfo->role);
- if (bootverbose) {
- printf("(%s:%c:%d:%d): Received "
- "SDTR period %x, offset %xnt"
- "Filtered to period %x, offset %xn",
- ahc_name(ahc), devinfo->channel,
- devinfo->target, devinfo->lun,
- ahc->msgin_buf[3], saved_offset,
- period, offset);
- }
- ahc_set_syncrate(ahc, devinfo,
- syncrate, period,
- offset, ppr_options,
- AHC_TRANS_ACTIVE|AHC_TRANS_GOAL,
- /*paused*/TRUE);
- /*
- * See if we initiated Sync Negotiation
- * and didn't have to fall down to async
- * transfers.
- */
- if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_SDTR, TRUE)) {
- /* We started it */
- if (saved_offset != offset) {
- /* Went too low - force async */
- reject = TRUE;
- }
- } else {
- /*
- * Send our own SDTR in reply
- */
- if (bootverbose
- && devinfo->role == ROLE_INITIATOR) {
- printf("(%s:%c:%d:%d): Target "
- "Initiated SDTRn",
- ahc_name(ahc), devinfo->channel,
- devinfo->target, devinfo->lun);
- }
- ahc->msgout_index = 0;
- ahc->msgout_len = 0;
- ahc_construct_sdtr(ahc, devinfo,
- period, offset);
- ahc->msgout_index = 0;
- response = TRUE;
- }
- done = MSGLOOP_MSGCOMPLETE;
- break;
- }
- case MSG_EXT_WDTR:
- {
- u_int bus_width;
- u_int saved_width;
- u_int sending_reply;
- sending_reply = FALSE;
- if (ahc->msgin_buf[1] != MSG_EXT_WDTR_LEN) {
- reject = TRUE;
- break;
- }
- /*
- * Wait until we have our arg before validating
- * and acting on this message.
- *
- * Add one to MSG_EXT_WDTR_LEN to account for
- * the extended message preamble.
- */
- if (ahc->msgin_index < (MSG_EXT_WDTR_LEN + 1))
- break;
- bus_width = ahc->msgin_buf[3];
- saved_width = bus_width;
- ahc_validate_width(ahc, tinfo, &bus_width,
- devinfo->role);
- if (bootverbose) {
- printf("(%s:%c:%d:%d): Received WDTR "
- "%x filtered to %xn",
- ahc_name(ahc), devinfo->channel,
- devinfo->target, devinfo->lun,
- saved_width, bus_width);
- }
- if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_WDTR, TRUE)) {
- /*
- * Don't send a WDTR back to the
- * target, since we asked first.
- * If the width went higher than our
- * request, reject it.
- */
- if (saved_width > bus_width) {
- reject = TRUE;
- printf("(%s:%c:%d:%d): requested %dBit "
- "transfers. Rejecting...n",
- ahc_name(ahc), devinfo->channel,
- devinfo->target, devinfo->lun,
- 8 * (0x01 << bus_width));
- bus_width = 0;
- }
- } else {
- /*
- * Send our own WDTR in reply
- */
- if (bootverbose
- && devinfo->role == ROLE_INITIATOR) {
- printf("(%s:%c:%d:%d): Target "
- "Initiated WDTRn",
- ahc_name(ahc), devinfo->channel,
- devinfo->target, devinfo->lun);
- }
- ahc->msgout_index = 0;
- ahc->msgout_len = 0;
- ahc_construct_wdtr(ahc, devinfo, bus_width);
- ahc->msgout_index = 0;
- response = TRUE;
- sending_reply = TRUE;
- }
- ahc_set_width(ahc, devinfo, bus_width,
- AHC_TRANS_ACTIVE|AHC_TRANS_GOAL,
- /*paused*/TRUE);
- /* After a wide message, we are async */
- ahc_set_syncrate(ahc, devinfo,
- /*syncrate*/NULL, /*period*/0,
- /*offset*/0, /*ppr_options*/0,
- AHC_TRANS_ACTIVE, /*paused*/TRUE);
- if (sending_reply == FALSE && reject == FALSE) {
- if (tinfo->goal.period) {
- ahc->msgout_index = 0;
- ahc->msgout_len = 0;
- ahc_build_transfer_msg(ahc, devinfo);
- ahc->msgout_index = 0;
- response = TRUE;
- }
- }
- done = MSGLOOP_MSGCOMPLETE;
- break;
- }
- case MSG_EXT_PPR:
- {
- struct ahc_syncrate *syncrate;
- u_int period;
- u_int offset;
- u_int bus_width;
- u_int ppr_options;
- u_int saved_width;
- u_int saved_offset;
- u_int saved_ppr_options;
- if (ahc->msgin_buf[1] != MSG_EXT_PPR_LEN) {
- reject = TRUE;
- break;
- }
- /*
- * Wait until we have all args before validating
- * and acting on this message.
- *
- * Add one to MSG_EXT_PPR_LEN to account for
- * the extended message preamble.
- */
- if (ahc->msgin_index < (MSG_EXT_PPR_LEN + 1))
- break;
- period = ahc->msgin_buf[3];
- offset = ahc->msgin_buf[5];
- bus_width = ahc->msgin_buf[6];
- saved_width = bus_width;
- ppr_options = ahc->msgin_buf[7];
- /*
- * According to the spec, a DT only
- * period factor with no DT option
- * set implies async.
- */
- if ((ppr_options & MSG_EXT_PPR_DT_REQ) == 0
- && period == 9)
- offset = 0;
- saved_ppr_options = ppr_options;
- saved_offset = offset;
- /*
- * Mask out any options we don't support
- * on any controller. Transfer options are
- * only available if we are negotiating wide.
- */
- ppr_options &= MSG_EXT_PPR_DT_REQ;
- if (bus_width == 0)
- ppr_options = 0;
- ahc_validate_width(ahc, tinfo, &bus_width,
- devinfo->role);
- syncrate = ahc_devlimited_syncrate(ahc, tinfo, &period,
- &ppr_options,
- devinfo->role);
- ahc_validate_offset(ahc, tinfo, syncrate,
- &offset, bus_width,
- devinfo->role);
- if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_PPR, TRUE)) {
- /*
- * If we are unable to do any of the
- * requested options (we went too low),
- * then we'll have to reject the message.
- */
- if (saved_width > bus_width
- || saved_offset != offset
- || saved_ppr_options != ppr_options) {
- reject = TRUE;
- period = 0;
- offset = 0;
- bus_width = 0;
- ppr_options = 0;
- syncrate = NULL;
- }
- } else {
- if (devinfo->role != ROLE_TARGET)
- printf("(%s:%c:%d:%d): Target "
- "Initiated PPRn",
- ahc_name(ahc), devinfo->channel,
- devinfo->target, devinfo->lun);
- else
- printf("(%s:%c:%d:%d): Initiator "
- "Initiated PPRn",
- ahc_name(ahc), devinfo->channel,
- devinfo->target, devinfo->lun);
- ahc->msgout_index = 0;
- ahc->msgout_len = 0;
- ahc_construct_ppr(ahc, devinfo, period, offset,
- bus_width, ppr_options);
- ahc->msgout_index = 0;
- response = TRUE;
- }
- if (bootverbose) {
- printf("(%s:%c:%d:%d): Received PPR width %x, "
- "period %x, offset %x,options %xn"
- "tFiltered to width %x, period %x, "
- "offset %x, options %xn",
- ahc_name(ahc), devinfo->channel,
- devinfo->target, devinfo->lun,
- saved_width, ahc->msgin_buf[3],
- saved_offset, saved_ppr_options,
- bus_width, period, offset, ppr_options);
- }
- ahc_set_width(ahc, devinfo, bus_width,
- AHC_TRANS_ACTIVE|AHC_TRANS_GOAL,
- /*paused*/TRUE);
- ahc_set_syncrate(ahc, devinfo,
- syncrate, period,
- offset, ppr_options,
- AHC_TRANS_ACTIVE|AHC_TRANS_GOAL,
- /*paused*/TRUE);
- done = MSGLOOP_MSGCOMPLETE;
- break;
- }
- default:
- /* Unknown extended message. Reject it. */
- reject = TRUE;
- break;
- }
- break;
- }
- #ifdef AHC_TARGET_MODE
- case MSG_BUS_DEV_RESET:
- ahc_handle_devreset(ahc, devinfo,
- CAM_BDR_SENT,
- "Bus Device Reset Received",
- /*verbose_level*/0);
- ahc_restart(ahc);
- done = MSGLOOP_TERMINATED;
- break;
- case MSG_ABORT_TAG:
- case MSG_ABORT:
- case MSG_CLEAR_QUEUE:
- {
- int tag;
- /* Target mode messages */
- if (devinfo->role != ROLE_TARGET) {
- reject = TRUE;
- break;
- }
- tag = SCB_LIST_NULL;
- if (ahc->msgin_buf[0] == MSG_ABORT_TAG)
- tag = ahc_inb(ahc, INITIATOR_TAG);
- ahc_abort_scbs(ahc, devinfo->target, devinfo->channel,
- devinfo->lun, tag, ROLE_TARGET,
- CAM_REQ_ABORTED);
- tstate = ahc->enabled_targets[devinfo->our_scsiid];
- if (tstate != NULL) {
- struct ahc_tmode_lstate* lstate;
- lstate = tstate->enabled_luns[devinfo->lun];
- if (lstate != NULL) {
- ahc_queue_lstate_event(ahc, lstate,
- devinfo->our_scsiid,
- ahc->msgin_buf[0],
- /*arg*/tag);
- ahc_send_lstate_events(ahc, lstate);
- }
- }
- ahc_restart(ahc);
- done = MSGLOOP_TERMINATED;
- break;
- }
- #endif
- case MSG_TERM_IO_PROC:
- default:
- reject = TRUE;
- break;
- }
- if (reject) {
- /*
- * Setup to reject the message.
- */
- ahc->msgout_index = 0;
- ahc->msgout_len = 1;
- ahc->msgout_buf[0] = MSG_MESSAGE_REJECT;
- done = MSGLOOP_MSGCOMPLETE;
- response = TRUE;
- }
- if (done != MSGLOOP_IN_PROG && !response)
- /* Clear the outgoing message buffer */
- ahc->msgout_len = 0;
- return (done);
- }
- /*
- * Process a message reject message.
- */
- static int
- ahc_handle_msg_reject(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
- {
- /*
- * What we care about here is if we had an
- * outstanding SDTR or WDTR message for this
- * target. If we did, this is a signal that
- * the target is refusing negotiation.
- */
- struct scb *scb;
- struct ahc_initiator_tinfo *tinfo;
- struct ahc_tmode_tstate *tstate;
- u_int scb_index;
- u_int last_msg;
- int response = 0;
- scb_index = ahc_inb(ahc, SCB_TAG);
- scb = ahc_lookup_scb(ahc, scb_index);
- tinfo = ahc_fetch_transinfo(ahc, devinfo->channel,
- devinfo->our_scsiid,
- devinfo->target, &tstate);
- /* Might be necessary */
- last_msg = ahc_inb(ahc, LAST_MSG);
- if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_PPR, /*full*/FALSE)) {
- /*
- * Target does not support the PPR message.
- * Attempt to negotiate SPI-2 style.
- */
- if (bootverbose) {
- printf("(%s:%c:%d:%d): PPR Rejected. "
- "Trying WDTR/SDTRn",
- ahc_name(ahc), devinfo->channel,
- devinfo->target, devinfo->lun);
- }
- tinfo->goal.ppr_options = 0;
- tinfo->curr.transport_version = 2;
- tinfo->goal.transport_version = 2;
- ahc->msgout_index = 0;
- ahc->msgout_len = 0;
- ahc_build_transfer_msg(ahc, devinfo);
- ahc->msgout_index = 0;
- response = 1;
- } else if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_WDTR, /*full*/FALSE)) {
- /* note 8bit xfers */
- printf("(%s:%c:%d:%d): refuses WIDE negotiation. Using "
- "8bit transfersn", ahc_name(ahc),
- devinfo->channel, devinfo->target, devinfo->lun);
- ahc_set_width(ahc, devinfo, MSG_EXT_WDTR_BUS_8_BIT,
- AHC_TRANS_ACTIVE|AHC_TRANS_GOAL,
- /*paused*/TRUE);
- /*
- * No need to clear the sync rate. If the target
- * did not accept the command, our syncrate is
- * unaffected. If the target started the negotiation,
- * but rejected our response, we already cleared the
- * sync rate before sending our WDTR.
- */
- if (tinfo->goal.period) {
- /* Start the sync negotiation */
- ahc->msgout_index = 0;
- ahc->msgout_len = 0;
- ahc_build_transfer_msg(ahc, devinfo);
- ahc->msgout_index = 0;
- response = 1;
- }
- } else if (ahc_sent_msg(ahc, AHCMSG_EXT, MSG_EXT_SDTR, /*full*/FALSE)) {
- /* note asynch xfers and clear flag */
- ahc_set_syncrate(ahc, devinfo, /*syncrate*/NULL, /*period*/0,
- /*offset*/0, /*ppr_options*/0,
- AHC_TRANS_ACTIVE|AHC_TRANS_GOAL,
- /*paused*/TRUE);
- printf("(%s:%c:%d:%d): refuses synchronous negotiation. "
- "Using asynchronous transfersn",
- ahc_name(ahc), devinfo->channel,
- devinfo->target, devinfo->lun);
- } else if ((scb->hscb->control & MSG_SIMPLE_TASK) != 0) {
- int tag_type;
- int mask;
- tag_type = (scb->hscb->control & MSG_SIMPLE_TASK);
- if (tag_type == MSG_SIMPLE_TASK) {
- printf("(%s:%c:%d:%d): refuses tagged commands. "
- "Performing non-tagged I/On", ahc_name(ahc),
- devinfo->channel, devinfo->target, devinfo->lun);
- ahc_set_tags(ahc, devinfo, AHC_QUEUE_NONE);
- mask = ~0x23;
- } else {
- printf("(%s:%c:%d:%d): refuses %s tagged commands. "
- "Performing simple queue tagged I/O onlyn",
- ahc_name(ahc), devinfo->channel, devinfo->target,
- devinfo->lun, tag_type == MSG_ORDERED_TASK
- ? "ordered" : "head of queue");
- ahc_set_tags(ahc, devinfo, AHC_QUEUE_BASIC);
- mask = ~0x03;
- }
- /*
- * Resend the identify for this CCB as the target
- * may believe that the selection is invalid otherwise.
- */
- ahc_outb(ahc, SCB_CONTROL,
- ahc_inb(ahc, SCB_CONTROL) & mask);
- scb->hscb->control &= mask;
- ahc_set_transaction_tag(scb, /*enabled*/FALSE,
- /*type*/MSG_SIMPLE_TASK);
- ahc_outb(ahc, MSG_OUT, MSG_IDENTIFYFLAG);
- ahc_assert_atn(ahc);
- /*
- * This transaction is now at the head of
- * the untagged queue for this target.
- */
- if ((ahc->flags & AHC_SCB_BTT) == 0) {
- struct scb_tailq *untagged_q;
- untagged_q =
- &(ahc->untagged_queues[devinfo->target_offset]);
- TAILQ_INSERT_HEAD(untagged_q, scb, links.tqe);
- scb->flags |= SCB_UNTAGGEDQ;
- }
- ahc_busy_tcl(ahc, BUILD_TCL(scb->hscb->scsiid, devinfo->lun),
- scb->hscb->tag);
- /*
- * Requeue all tagged commands for this target
- * currently in our posession so they can be
- * converted to untagged commands.
- */
- ahc_search_qinfifo(ahc, SCB_GET_TARGET(ahc, scb),
- SCB_GET_CHANNEL(ahc, scb),
- SCB_GET_LUN(scb), /*tag*/SCB_LIST_NULL,
- ROLE_INITIATOR, CAM_REQUEUE_REQ,
- SEARCH_COMPLETE);
- } else {
- /*
- * Otherwise, we ignore it.
- */
- printf("%s:%c:%d: Message reject for %x -- ignoredn",
- ahc_name(ahc), devinfo->channel, devinfo->target,
- last_msg);
- }
- return (response);
- }
- /*
- * Process an ingnore wide residue message.
- */
- static void
- ahc_handle_ign_wide_residue(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
- {
- u_int scb_index;
- struct scb *scb;
- scb_index = ahc_inb(ahc, SCB_TAG);
- scb = ahc_lookup_scb(ahc, scb_index);
- /*
- * XXX Actually check data direction in the sequencer?
- * Perhaps add datadir to some spare bits in the hscb?
- */
- if ((ahc_inb(ahc, SEQ_FLAGS) & DPHASE) == 0
- || ahc_get_transfer_dir(scb) != CAM_DIR_IN) {
- /*
- * Ignore the message if we haven't
- * seen an appropriate data phase yet.
- */
- } else {
- /*
- * If the residual occurred on the last
- * transfer and the transfer request was
- * expected to end on an odd count, do
- * nothing. Otherwise, subtract a byte
- * and update the residual count accordingly.
- */
- uint32_t sgptr;
- sgptr = ahc_inb(ahc, SCB_RESIDUAL_SGPTR);
- if ((sgptr & SG_LIST_NULL) != 0
- && ahc_inb(ahc, DATA_COUNT_ODD) == 1) {
- /*
- * If the residual occurred on the last
- * transfer and the transfer request was
- * expected to end on an odd count, do
- * nothing.
- */
- } else {
- struct ahc_dma_seg *sg;
- uint32_t data_cnt;
- uint32_t data_addr;
- uint32_t sglen;
- /* Pull in the rest of the sgptr */
- sgptr |= (ahc_inb(ahc, SCB_RESIDUAL_SGPTR + 3) << 24)
- | (ahc_inb(ahc, SCB_RESIDUAL_SGPTR + 2) << 16)
- | (ahc_inb(ahc, SCB_RESIDUAL_SGPTR + 1) << 8);
- sgptr &= SG_PTR_MASK;
- data_cnt = (ahc_inb(ahc, SCB_RESIDUAL_DATACNT+3) << 24)
- | (ahc_inb(ahc, SCB_RESIDUAL_DATACNT+2) << 16)
- | (ahc_inb(ahc, SCB_RESIDUAL_DATACNT+1) << 8)
- | (ahc_inb(ahc, SCB_RESIDUAL_DATACNT));
- data_addr = (ahc_inb(ahc, SHADDR + 3) << 24)
- | (ahc_inb(ahc, SHADDR + 2) << 16)
- | (ahc_inb(ahc, SHADDR + 1) << 8)
- | (ahc_inb(ahc, SHADDR));
- data_cnt += 1;
- data_addr -= 1;
- sg = ahc_sg_bus_to_virt(scb, sgptr);
- /*
- * The residual sg ptr points to the next S/G
- * to load so we must go back one.
- */
- sg--;
- sglen = ahc_le32toh(sg->len) & AHC_SG_LEN_MASK;
- if (sg != scb->sg_list
- && sglen < (data_cnt & AHC_SG_LEN_MASK)) {
- sg--;
- sglen = ahc_le32toh(sg->len);
- /*
- * Preserve High Address and SG_LIST bits
- * while setting the count to 1.
- */
- data_cnt = 1 | (sglen & (~AHC_SG_LEN_MASK));
- data_addr = ahc_le32toh(sg->addr)
- + (sglen & AHC_SG_LEN_MASK) - 1;
- /*
- * Increment sg so it points to the
- * "next" sg.
- */
- sg++;
- sgptr = ahc_sg_virt_to_bus(scb, sg);
- ahc_outb(ahc, SCB_RESIDUAL_SGPTR + 3,
- sgptr >> 24);
- ahc_outb(ahc, SCB_RESIDUAL_SGPTR + 2,
- sgptr >> 16);
- ahc_outb(ahc, SCB_RESIDUAL_SGPTR + 1,
- sgptr >> 8);
- ahc_outb(ahc, SCB_RESIDUAL_SGPTR, sgptr);
- }
- ahc_outb(ahc, SCB_RESIDUAL_DATACNT + 3, data_cnt >> 24);
- ahc_outb(ahc, SCB_RESIDUAL_DATACNT + 2, data_cnt >> 16);
- ahc_outb(ahc, SCB_RESIDUAL_DATACNT + 1, data_cnt >> 8);
- ahc_outb(ahc, SCB_RESIDUAL_DATACNT, data_cnt);
- }
- }
- }
- /*
- * Reinitialize the data pointers for the active transfer
- * based on its current residual.
- */
- static void
- ahc_reinitialize_dataptrs(struct ahc_softc *ahc)
- {
- struct scb *scb;
- struct ahc_dma_seg *sg;
- u_int scb_index;
- uint32_t sgptr;
- uint32_t resid;
- uint32_t dataptr;
- scb_index = ahc_inb(ahc, SCB_TAG);
- scb = ahc_lookup_scb(ahc, scb_index);
- sgptr = (ahc_inb(ahc, SCB_RESIDUAL_SGPTR + 3) << 24)
- | (ahc_inb(ahc, SCB_RESIDUAL_SGPTR + 2) << 16)
- | (ahc_inb(ahc, SCB_RESIDUAL_SGPTR + 1) << 8)
- | ahc_inb(ahc, SCB_RESIDUAL_SGPTR);
- sgptr &= SG_PTR_MASK;
- sg = ahc_sg_bus_to_virt(scb, sgptr);
- /* The residual sg_ptr always points to the next sg */
- sg--;
- resid = (ahc_inb(ahc, SCB_RESIDUAL_DATACNT + 2) << 16)
- | (ahc_inb(ahc, SCB_RESIDUAL_DATACNT + 1) << 8)
- | ahc_inb(ahc, SCB_RESIDUAL_DATACNT);
- dataptr = ahc_le32toh(sg->addr)
- + (ahc_le32toh(sg->len) & AHC_SG_LEN_MASK)
- - resid;
- if ((ahc->flags & AHC_39BIT_ADDRESSING) != 0) {
- u_int dscommand1;
- dscommand1 = ahc_inb(ahc, DSCOMMAND1);
- ahc_outb(ahc, DSCOMMAND1, dscommand1 | HADDLDSEL0);
- ahc_outb(ahc, HADDR,
- (ahc_le32toh(sg->len) >> 24) & SG_HIGH_ADDR_BITS);
- ahc_outb(ahc, DSCOMMAND1, dscommand1);
- }
- ahc_outb(ahc, HADDR + 3, dataptr >> 24);
- ahc_outb(ahc, HADDR + 2, dataptr >> 16);
- ahc_outb(ahc, HADDR + 1, dataptr >> 8);
- ahc_outb(ahc, HADDR, dataptr);
- ahc_outb(ahc, HCNT + 2, resid >> 16);
- ahc_outb(ahc, HCNT + 1, resid >> 8);
- ahc_outb(ahc, HCNT, resid);
- if ((ahc->features & AHC_ULTRA2) == 0) {
- ahc_outb(ahc, STCNT + 2, resid >> 16);
- ahc_outb(ahc, STCNT + 1, resid >> 8);
- ahc_outb(ahc, STCNT, resid);
- }
- }
- /*
- * Handle the effects of issuing a bus device reset message.
- */
- static void
- ahc_handle_devreset(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
- cam_status status, char *message, int verbose_level)
- {
- #ifdef AHC_TARGET_MODE
- struct ahc_tmode_tstate* tstate;
- u_int lun;
- #endif
- int found;
- found = ahc_abort_scbs(ahc, devinfo->target, devinfo->channel,
- CAM_LUN_WILDCARD, SCB_LIST_NULL, devinfo->role,
- status);
- #ifdef AHC_TARGET_MODE
- /*
- * Send an immediate notify ccb to all target mord peripheral
- * drivers affected by this action.
- */
- tstate = ahc->enabled_targets[devinfo->our_scsiid];
- if (tstate != NULL) {
- for (lun = 0; lun < AHC_NUM_LUNS; lun++) {
- struct ahc_tmode_lstate* lstate;
- lstate = tstate->enabled_luns[lun];
- if (lstate == NULL)
- continue;
- ahc_queue_lstate_event(ahc, lstate, devinfo->our_scsiid,
- MSG_BUS_DEV_RESET, /*arg*/0);
- ahc_send_lstate_events(ahc, lstate);
- }
- }
- #endif
- /*
- * Go back to async/narrow transfers and renegotiate.
- */
- ahc_set_width(ahc, devinfo, MSG_EXT_WDTR_BUS_8_BIT,
- AHC_TRANS_CUR, /*paused*/TRUE);
- ahc_set_syncrate(ahc, devinfo, /*syncrate*/NULL,
- /*period*/0, /*offset*/0, /*ppr_options*/0,
- AHC_TRANS_CUR, /*paused*/TRUE);
-
- ahc_send_async(ahc, devinfo->channel, devinfo->target,
- CAM_LUN_WILDCARD, AC_SENT_BDR, NULL);
- if (message != NULL
- && (verbose_level <= bootverbose))
- printf("%s: %s on %c:%d. %d SCBs abortedn", ahc_name(ahc),
- message, devinfo->channel, devinfo->target, found);
- }
- #ifdef AHC_TARGET_MODE
- static void
- ahc_setup_target_msgin(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
- struct scb *scb)
- {
- /*
- * To facilitate adding multiple messages together,
- * each routine should increment the index and len
- * variables instead of setting them explicitly.
- */
- ahc->msgout_index = 0;
- ahc->msgout_len = 0;
- if (scb != NULL && (scb->flags & SCB_AUTO_NEGOTIATE) != 0)
- ahc_build_transfer_msg(ahc, devinfo);
- else
- panic("ahc_intr: AWAITING target message with no message");
- ahc->msgout_index = 0;
- ahc->msg_type = MSG_TYPE_TARGET_MSGIN;
- }
- #endif