aic7xxx.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:185k
- /**************************** Initialization **********************************/
- /*
- * Allocate a controller structure for a new device
- * and perform initial initializion.
- */
- struct ahc_softc *
- ahc_alloc(void *platform_arg, char *name)
- {
- struct ahc_softc *ahc;
- int i;
- #ifndef __FreeBSD__
- ahc = malloc(sizeof(*ahc), M_DEVBUF, M_NOWAIT);
- if (!ahc) {
- printf("aic7xxx: cannot malloc softc!n");
- free(name, M_DEVBUF);
- return NULL;
- }
- #else
- ahc = device_get_softc((device_t)platform_arg);
- #endif
- memset(ahc, 0, sizeof(*ahc));
- LIST_INIT(&ahc->pending_scbs);
- /* We don't know our unit number until the OSM sets it */
- ahc->name = name;
- ahc->unit = -1;
- ahc->description = NULL;
- ahc->channel = 'A';
- ahc->channel_b = 'B';
- ahc->chip = AHC_NONE;
- ahc->features = AHC_FENONE;
- ahc->bugs = AHC_BUGNONE;
- ahc->flags = AHC_FNONE;
- for (i = 0; i < 16; i++)
- TAILQ_INIT(&ahc->untagged_queues[i]);
- if (ahc_platform_alloc(ahc, platform_arg) != 0) {
- ahc_free(ahc);
- ahc = NULL;
- }
- return (ahc);
- }
- int
- ahc_softc_init(struct ahc_softc *ahc)
- {
- /* The IRQMS bit is only valid on VL and EISA chips */
- if ((ahc->chip & AHC_PCI) == 0)
- ahc->unpause = ahc_inb(ahc, HCNTRL) & IRQMS;
- else
- ahc->unpause = 0;
- ahc->pause = ahc->unpause | PAUSE;
- /* XXX The shared scb data stuff should be deprecated */
- if (ahc->scb_data == NULL) {
- ahc->scb_data = malloc(sizeof(*ahc->scb_data),
- M_DEVBUF, M_NOWAIT);
- if (ahc->scb_data == NULL)
- return (ENOMEM);
- memset(ahc->scb_data, 0, sizeof(*ahc->scb_data));
- }
- return (0);
- }
- void
- ahc_softc_insert(struct ahc_softc *ahc)
- {
- struct ahc_softc *list_ahc;
- #if AHC_PCI_CONFIG > 0
- /*
- * Second Function PCI devices need to inherit some
- * settings from function 0.
- */
- if ((ahc->chip & AHC_BUS_MASK) == AHC_PCI
- && (ahc->features & AHC_MULTI_FUNC) != 0) {
- TAILQ_FOREACH(list_ahc, &ahc_tailq, links) {
- ahc_dev_softc_t list_pci;
- ahc_dev_softc_t pci;
- list_pci = list_ahc->dev_softc;
- pci = ahc->dev_softc;
- if (ahc_get_pci_slot(list_pci) == ahc_get_pci_slot(pci)
- && ahc_get_pci_bus(list_pci) == ahc_get_pci_bus(pci)) {
- struct ahc_softc *master;
- struct ahc_softc *slave;
- if (ahc_get_pci_function(list_pci) == 0) {
- master = list_ahc;
- slave = ahc;
- } else {
- master = ahc;
- slave = list_ahc;
- }
- slave->flags &= ~AHC_BIOS_ENABLED;
- slave->flags |=
- master->flags & AHC_BIOS_ENABLED;
- slave->flags &= ~AHC_PRIMARY_CHANNEL;
- slave->flags |=
- master->flags & AHC_PRIMARY_CHANNEL;
- break;
- }
- }
- }
- #endif
- /*
- * Insertion sort into our list of softcs.
- */
- list_ahc = TAILQ_FIRST(&ahc_tailq);
- while (list_ahc != NULL
- && ahc_softc_comp(list_ahc, ahc) <= 0)
- list_ahc = TAILQ_NEXT(list_ahc, links);
- if (list_ahc != NULL)
- TAILQ_INSERT_BEFORE(list_ahc, ahc, links);
- else
- TAILQ_INSERT_TAIL(&ahc_tailq, ahc, links);
- ahc->init_level++;
- }
- void
- ahc_set_unit(struct ahc_softc *ahc, int unit)
- {
- ahc->unit = unit;
- }
- void
- ahc_set_name(struct ahc_softc *ahc, char *name)
- {
- if (ahc->name != NULL)
- free(ahc->name, M_DEVBUF);
- ahc->name = name;
- }
- void
- ahc_free(struct ahc_softc *ahc)
- {
- int i;
- ahc_fini_scbdata(ahc);
- switch (ahc->init_level) {
- default:
- case 5:
- ahc_shutdown(ahc);
- TAILQ_REMOVE(&ahc_tailq, ahc, links);
- /* FALLTHROUGH */
- case 4:
- ahc_dmamap_unload(ahc, ahc->shared_data_dmat,
- ahc->shared_data_dmamap);
- /* FALLTHROUGH */
- case 3:
- ahc_dmamem_free(ahc, ahc->shared_data_dmat, ahc->qoutfifo,
- ahc->shared_data_dmamap);
- ahc_dmamap_destroy(ahc, ahc->shared_data_dmat,
- ahc->shared_data_dmamap);
- /* FALLTHROUGH */
- case 2:
- ahc_dma_tag_destroy(ahc, ahc->shared_data_dmat);
- case 1:
- #ifndef __linux__
- ahc_dma_tag_destroy(ahc, ahc->buffer_dmat);
- #endif
- break;
- case 0:
- break;
- }
- #ifndef __linux__
- ahc_dma_tag_destroy(ahc, ahc->parent_dmat);
- #endif
- ahc_platform_free(ahc);
- for (i = 0; i < AHC_NUM_TARGETS; i++) {
- struct ahc_tmode_tstate *tstate;
- tstate = ahc->enabled_targets[i];
- if (tstate != NULL) {
- #if AHC_TARGET_MODE
- int j;
- for (j = 0; j < AHC_NUM_LUNS; j++) {
- struct ahc_tmode_lstate *lstate;
- lstate = tstate->enabled_luns[j];
- if (lstate != NULL) {
- xpt_free_path(lstate->path);
- free(lstate, M_DEVBUF);
- }
- }
- #endif
- free(tstate, M_DEVBUF);
- }
- }
- #if AHC_TARGET_MODE
- if (ahc->black_hole != NULL) {
- xpt_free_path(ahc->black_hole->path);
- free(ahc->black_hole, M_DEVBUF);
- }
- #endif
- if (ahc->name != NULL)
- free(ahc->name, M_DEVBUF);
- #ifndef __FreeBSD__
- free(ahc, M_DEVBUF);
- #endif
- return;
- }
- void
- ahc_shutdown(void *arg)
- {
- struct ahc_softc *ahc;
- int i;
- ahc = (struct ahc_softc *)arg;
- /* This will reset most registers to 0, but not all */
- ahc_reset(ahc);
- ahc_outb(ahc, SCSISEQ, 0);
- ahc_outb(ahc, SXFRCTL0, 0);
- ahc_outb(ahc, DSPCISTATUS, 0);
- for (i = TARG_SCSIRATE; i < HA_274_BIOSCTRL; i++)
- ahc_outb(ahc, i, 0);
- }
- /*
- * Reset the controller and record some information about it
- * that is only availabel just after a reset.
- */
- int
- ahc_reset(struct ahc_softc *ahc)
- {
- u_int sblkctl;
- u_int sxfrctl1_a, sxfrctl1_b;
- int wait;
-
- /*
- * Preserve the value of the SXFRCTL1 register for all channels.
- * It contains settings that affect termination and we don't want
- * to disturb the integrity of the bus.
- */
- ahc_pause(ahc);
- sxfrctl1_b = 0;
- if ((ahc->chip & AHC_CHIPID_MASK) == AHC_AIC7770) {
- u_int sblkctl;
- /*
- * Save channel B's settings in case this chip
- * is setup for TWIN channel operation.
- */
- sblkctl = ahc_inb(ahc, SBLKCTL);
- ahc_outb(ahc, SBLKCTL, sblkctl | SELBUSB);
- sxfrctl1_b = ahc_inb(ahc, SXFRCTL1);
- ahc_outb(ahc, SBLKCTL, sblkctl & ~SELBUSB);
- }
- sxfrctl1_a = ahc_inb(ahc, SXFRCTL1);
- ahc_outb(ahc, HCNTRL, CHIPRST | ahc->pause);
- /*
- * Ensure that the reset has finished
- */
- wait = 1000;
- do {
- ahc_delay(1000);
- } while (--wait && !(ahc_inb(ahc, HCNTRL) & CHIPRSTACK));
- if (wait == 0) {
- printf("%s: WARNING - Failed chip reset! "
- "Trying to initialize anyway.n", ahc_name(ahc));
- }
- ahc_outb(ahc, HCNTRL, ahc->pause);
- /* Determine channel configuration */
- sblkctl = ahc_inb(ahc, SBLKCTL) & (SELBUSB|SELWIDE);
- /* No Twin Channel PCI cards */
- if ((ahc->chip & AHC_PCI) != 0)
- sblkctl &= ~SELBUSB;
- switch (sblkctl) {
- case 0:
- /* Single Narrow Channel */
- break;
- case 2:
- /* Wide Channel */
- ahc->features |= AHC_WIDE;
- break;
- case 8:
- /* Twin Channel */
- ahc->features |= AHC_TWIN;
- break;
- default:
- printf(" Unsupported adapter type. Ignoringn");
- return(-1);
- }
- /*
- * Reload sxfrctl1.
- *
- * We must always initialize STPWEN to 1 before we
- * restore the saved values. STPWEN is initialized
- * to a tri-state condition which can only be cleared
- * by turning it on.
- */
- if ((ahc->features & AHC_TWIN) != 0) {
- u_int sblkctl;
- sblkctl = ahc_inb(ahc, SBLKCTL);
- ahc_outb(ahc, SBLKCTL, sblkctl | SELBUSB);
- ahc_outb(ahc, SXFRCTL1, sxfrctl1_b);
- ahc_outb(ahc, SBLKCTL, sblkctl & ~SELBUSB);
- }
- ahc_outb(ahc, SXFRCTL1, sxfrctl1_a);
- #ifdef AHC_DUMP_SEQ
- if (ahc->init_level == 0)
- ahc_dumpseq(ahc);
- #endif
- return (0);
- }
- /*
- * Determine the number of SCBs available on the controller
- */
- int
- ahc_probe_scbs(struct ahc_softc *ahc) {
- int i;
- for (i = 0; i < AHC_SCB_MAX; i++) {
- ahc_outb(ahc, SCBPTR, i);
- ahc_outb(ahc, SCB_BASE, i);
- if (ahc_inb(ahc, SCB_BASE) != i)
- break;
- ahc_outb(ahc, SCBPTR, 0);
- if (ahc_inb(ahc, SCB_BASE) != 0)
- break;
- }
- return (i);
- }
- static void
- ahc_dmamap_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error)
- {
- bus_addr_t *baddr;
- baddr = (bus_addr_t *)arg;
- *baddr = segs->ds_addr;
- }
- static void
- ahc_build_free_scb_list(struct ahc_softc *ahc)
- {
- int i;
- for (i = 0; i < ahc->scb_data->maxhscbs; i++) {
- ahc_outb(ahc, SCBPTR, i);
- /* Clear the control byte. */
- ahc_outb(ahc, SCB_CONTROL, 0);
- /* Set the next pointer */
- if ((ahc->flags & AHC_PAGESCBS) != 0)
- ahc_outb(ahc, SCB_NEXT, i+1);
- else
- ahc_outb(ahc, SCB_NEXT, SCB_LIST_NULL);
- /* Make the tag number invalid */
- ahc_outb(ahc, SCB_TAG, SCB_LIST_NULL);
- }
- /* Make sure that the last SCB terminates the free list */
- ahc_outb(ahc, SCBPTR, i-1);
- ahc_outb(ahc, SCB_NEXT, SCB_LIST_NULL);
- /* Ensure we clear the 0 SCB's control byte. */
- ahc_outb(ahc, SCBPTR, 0);
- ahc_outb(ahc, SCB_CONTROL, 0);
- }
- static int
- ahc_init_scbdata(struct ahc_softc *ahc)
- {
- struct scb_data *scb_data;
- scb_data = ahc->scb_data;
- SLIST_INIT(&scb_data->free_scbs);
- SLIST_INIT(&scb_data->sg_maps);
- /* Allocate SCB resources */
- scb_data->scbarray =
- (struct scb *)malloc(sizeof(struct scb) * AHC_SCB_MAX_ALLOC,
- M_DEVBUF, M_NOWAIT);
- if (scb_data->scbarray == NULL)
- return (ENOMEM);
- memset(scb_data->scbarray, 0, sizeof(struct scb) * AHC_SCB_MAX_ALLOC);
- /* Determine the number of hardware SCBs and initialize them */
- scb_data->maxhscbs = ahc_probe_scbs(ahc);
- if ((ahc->flags & AHC_PAGESCBS) != 0) {
- /* SCB 0 heads the free list */
- ahc_outb(ahc, FREE_SCBH, 0);
- } else {
- ahc_outb(ahc, FREE_SCBH, SCB_LIST_NULL);
- }
- if (ahc->scb_data->maxhscbs == 0) {
- printf("%s: No SCB space foundn", ahc_name(ahc));
- return (ENXIO);
- }
- ahc_build_free_scb_list(ahc);
- /*
- * Create our DMA tags. These tags define the kinds of device
- * accessible memory allocations and memory mappings we will
- * need to perform during normal operation.
- *
- * Unless we need to further restrict the allocation, we rely
- * on the restrictions of the parent dmat, hence the common
- * use of MAXADDR and MAXSIZE.
- */
- /* DMA tag for our hardware scb structures */
- if (ahc_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1,
- /*boundary*/BUS_SPACE_MAXADDR_32BIT + 1,
- /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
- /*highaddr*/BUS_SPACE_MAXADDR,
- /*filter*/NULL, /*filterarg*/NULL,
- AHC_SCB_MAX_ALLOC * sizeof(struct hardware_scb),
- /*nsegments*/1,
- /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT,
- /*flags*/0, &scb_data->hscb_dmat) != 0) {
- goto error_exit;
- }
- scb_data->init_level++;
- /* Allocation for our hscbs */
- if (ahc_dmamem_alloc(ahc, scb_data->hscb_dmat,
- (void **)&scb_data->hscbs,
- BUS_DMA_NOWAIT, &scb_data->hscb_dmamap) != 0) {
- goto error_exit;
- }
- scb_data->init_level++;
- /* And permanently map them */
- ahc_dmamap_load(ahc, scb_data->hscb_dmat, scb_data->hscb_dmamap,
- scb_data->hscbs,
- AHC_SCB_MAX_ALLOC * sizeof(struct hardware_scb),
- ahc_dmamap_cb, &scb_data->hscb_busaddr, /*flags*/0);
- scb_data->init_level++;
- /* DMA tag for our sense buffers */
- if (ahc_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1,
- /*boundary*/BUS_SPACE_MAXADDR_32BIT + 1,
- /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
- /*highaddr*/BUS_SPACE_MAXADDR,
- /*filter*/NULL, /*filterarg*/NULL,
- AHC_SCB_MAX_ALLOC * sizeof(struct scsi_sense_data),
- /*nsegments*/1,
- /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT,
- /*flags*/0, &scb_data->sense_dmat) != 0) {
- goto error_exit;
- }
- scb_data->init_level++;
- /* Allocate them */
- if (ahc_dmamem_alloc(ahc, scb_data->sense_dmat,
- (void **)&scb_data->sense,
- BUS_DMA_NOWAIT, &scb_data->sense_dmamap) != 0) {
- goto error_exit;
- }
- scb_data->init_level++;
- /* And permanently map them */
- ahc_dmamap_load(ahc, scb_data->sense_dmat, scb_data->sense_dmamap,
- scb_data->sense,
- AHC_SCB_MAX_ALLOC * sizeof(struct scsi_sense_data),
- ahc_dmamap_cb, &scb_data->sense_busaddr, /*flags*/0);
- scb_data->init_level++;
- /* DMA tag for our S/G structures. We allocate in page sized chunks */
- if (ahc_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1,
- /*boundary*/BUS_SPACE_MAXADDR_32BIT + 1,
- /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
- /*highaddr*/BUS_SPACE_MAXADDR,
- /*filter*/NULL, /*filterarg*/NULL,
- PAGE_SIZE, /*nsegments*/1,
- /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT,
- /*flags*/0, &scb_data->sg_dmat) != 0) {
- goto error_exit;
- }
- scb_data->init_level++;
- /* Perform initial CCB allocation */
- memset(scb_data->hscbs, 0,
- AHC_SCB_MAX_ALLOC * sizeof(struct hardware_scb));
- ahc_alloc_scbs(ahc);
- if (scb_data->numscbs == 0) {
- printf("%s: ahc_init_scbdata - "
- "Unable to allocate initial scbsn",
- ahc_name(ahc));
- goto error_exit;
- }
- /*
- * Tell the sequencer which SCB will be the next one it receives.
- */
- ahc->next_queued_scb = ahc_get_scb(ahc);
- ahc_outb(ahc, NEXT_QUEUED_SCB, ahc->next_queued_scb->hscb->tag);
- /*
- * Note that we were successfull
- */
- return (0);
- error_exit:
- return (ENOMEM);
- }
- static void
- ahc_fini_scbdata(struct ahc_softc *ahc)
- {
- struct scb_data *scb_data;
- scb_data = ahc->scb_data;
- if (scb_data == NULL)
- return;
- switch (scb_data->init_level) {
- default:
- case 7:
- {
- struct sg_map_node *sg_map;
- while ((sg_map = SLIST_FIRST(&scb_data->sg_maps))!= NULL) {
- SLIST_REMOVE_HEAD(&scb_data->sg_maps, links);
- ahc_dmamap_unload(ahc, scb_data->sg_dmat,
- sg_map->sg_dmamap);
- ahc_dmamem_free(ahc, scb_data->sg_dmat,
- sg_map->sg_vaddr,
- sg_map->sg_dmamap);
- free(sg_map, M_DEVBUF);
- }
- ahc_dma_tag_destroy(ahc, scb_data->sg_dmat);
- }
- case 6:
- ahc_dmamap_unload(ahc, scb_data->sense_dmat,
- scb_data->sense_dmamap);
- case 5:
- ahc_dmamem_free(ahc, scb_data->sense_dmat, scb_data->sense,
- scb_data->sense_dmamap);
- ahc_dmamap_destroy(ahc, scb_data->sense_dmat,
- scb_data->sense_dmamap);
- case 4:
- ahc_dma_tag_destroy(ahc, scb_data->sense_dmat);
- case 3:
- ahc_dmamap_unload(ahc, scb_data->hscb_dmat,
- scb_data->hscb_dmamap);
- case 2:
- ahc_dmamem_free(ahc, scb_data->hscb_dmat, scb_data->hscbs,
- scb_data->hscb_dmamap);
- ahc_dmamap_destroy(ahc, scb_data->hscb_dmat,
- scb_data->hscb_dmamap);
- case 1:
- ahc_dma_tag_destroy(ahc, scb_data->hscb_dmat);
- break;
- case 0:
- break;
- }
- if (scb_data->scbarray != NULL)
- free(scb_data->scbarray, M_DEVBUF);
- }
- void
- ahc_alloc_scbs(struct ahc_softc *ahc)
- {
- struct scb_data *scb_data;
- struct scb *next_scb;
- struct sg_map_node *sg_map;
- bus_addr_t physaddr;
- struct ahc_dma_seg *segs;
- int newcount;
- int i;
- scb_data = ahc->scb_data;
- if (scb_data->numscbs >= AHC_SCB_MAX_ALLOC)
- /* Can't allocate any more */
- return;
- next_scb = &scb_data->scbarray[scb_data->numscbs];
- sg_map = malloc(sizeof(*sg_map), M_DEVBUF, M_NOWAIT);
- if (sg_map == NULL)
- return;
- /* Allocate S/G space for the next batch of SCBS */
- if (ahc_dmamem_alloc(ahc, scb_data->sg_dmat,
- (void **)&sg_map->sg_vaddr,
- BUS_DMA_NOWAIT, &sg_map->sg_dmamap) != 0) {
- free(sg_map, M_DEVBUF);
- return;
- }
- SLIST_INSERT_HEAD(&scb_data->sg_maps, sg_map, links);
- ahc_dmamap_load(ahc, scb_data->sg_dmat, sg_map->sg_dmamap,
- sg_map->sg_vaddr, PAGE_SIZE, ahc_dmamap_cb,
- &sg_map->sg_physaddr, /*flags*/0);
- segs = sg_map->sg_vaddr;
- physaddr = sg_map->sg_physaddr;
- newcount = (PAGE_SIZE / (AHC_NSEG * sizeof(struct ahc_dma_seg)));
- newcount = MIN(newcount, (AHC_SCB_MAX_ALLOC - scb_data->numscbs));
- for (i = 0; i < newcount; i++) {
- struct scb_platform_data *pdata;
- #ifndef __linux__
- int error;
- #endif
- pdata = (struct scb_platform_data *)malloc(sizeof(*pdata),
- M_DEVBUF, M_NOWAIT);
- if (pdata == NULL)
- break;
- next_scb->platform_data = pdata;
- next_scb->sg_map = sg_map;
- next_scb->sg_list = segs;
- /*
- * The sequencer always starts with the second entry.
- * The first entry is embedded in the scb.
- */
- next_scb->sg_list_phys = physaddr + sizeof(struct ahc_dma_seg);
- next_scb->ahc_softc = ahc;
- next_scb->flags = SCB_FREE;
- #ifndef __linux__
- error = ahc_dmamap_create(ahc, ahc->buffer_dmat, /*flags*/0,
- &next_scb->dmamap);
- if (error != 0)
- break;
- #endif
- next_scb->hscb = &scb_data->hscbs[scb_data->numscbs];
- next_scb->hscb->tag = ahc->scb_data->numscbs;
- SLIST_INSERT_HEAD(&ahc->scb_data->free_scbs,
- next_scb, links.sle);
- segs += AHC_NSEG;
- physaddr += (AHC_NSEG * sizeof(struct ahc_dma_seg));
- next_scb++;
- ahc->scb_data->numscbs++;
- }
- }
- void
- ahc_controller_info(struct ahc_softc *ahc, char *buf)
- {
- int len;
- len = sprintf(buf, "%s: ", ahc_chip_names[ahc->chip & AHC_CHIPID_MASK]);
- buf += len;
- if ((ahc->features & AHC_TWIN) != 0)
- len = sprintf(buf, "Twin Channel, A SCSI Id=%d, "
- "B SCSI Id=%d, primary %c, ",
- ahc->our_id, ahc->our_id_b,
- (ahc->flags & AHC_PRIMARY_CHANNEL) + 'A');
- else {
- const char *speed;
- const char *type;
- speed = "";
- if ((ahc->features & AHC_ULTRA) != 0) {
- speed = "Ultra ";
- } else if ((ahc->features & AHC_DT) != 0) {
- speed = "Ultra160 ";
- } else if ((ahc->features & AHC_ULTRA2) != 0) {
- speed = "Ultra2 ";
- }
- if ((ahc->features & AHC_WIDE) != 0) {
- type = "Wide";
- } else {
- type = "Single";
- }
- len = sprintf(buf, "%s%s Channel %c, SCSI Id=%d, ",
- speed, type, ahc->channel, ahc->our_id);
- }
- buf += len;
- if ((ahc->flags & AHC_PAGESCBS) != 0)
- sprintf(buf, "%d/%d SCBs",
- ahc->scb_data->maxhscbs, AHC_MAX_QUEUE);
- else
- sprintf(buf, "%d SCBs", ahc->scb_data->maxhscbs);
- }
- /*
- * Start the board, ready for normal operation
- */
- int
- ahc_init(struct ahc_softc *ahc)
- {
- int max_targ;
- int i;
- int term;
- u_int scsi_conf;
- u_int scsiseq_template;
- u_int ultraenb;
- u_int discenable;
- u_int tagenable;
- size_t driver_data_size;
- uint32_t physaddr;
- #ifdef AHC_DEBUG_SEQUENCER
- ahc->flags |= AHC_SEQUENCER_DEBUG;
- #endif
- #ifdef AHC_PRINT_SRAM
- printf("Scratch Ram:");
- for (i = 0x20; i < 0x5f; i++) {
- if (((i % 8) == 0) && (i != 0)) {
- printf ("n ");
- }
- printf (" 0x%x", ahc_inb(ahc, i));
- }
- if ((ahc->features & AHC_MORE_SRAM) != 0) {
- for (i = 0x70; i < 0x7f; i++) {
- if (((i % 8) == 0) && (i != 0)) {
- printf ("n ");
- }
- printf (" 0x%x", ahc_inb(ahc, i));
- }
- }
- printf ("n");
- #endif
- max_targ = 15;
- /*
- * Assume we have a board at this stage and it has been reset.
- */
- if ((ahc->flags & AHC_USEDEFAULTS) != 0)
- ahc->our_id = ahc->our_id_b = 7;
-
- /*
- * Default to allowing initiator operations.
- */
- ahc->flags |= AHC_INITIATORROLE;
- /*
- * Only allow target mode features if this unit has them enabled.
- */
- if ((AHC_TMODE_ENABLE & (0x1 << ahc->unit)) == 0)
- ahc->features &= ~AHC_TARGETMODE;
- #ifndef __linux__
- /* DMA tag for mapping buffers into device visible space. */
- if (ahc_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1,
- /*boundary*/BUS_SPACE_MAXADDR_32BIT + 1,
- /*lowaddr*/BUS_SPACE_MAXADDR,
- /*highaddr*/BUS_SPACE_MAXADDR,
- /*filter*/NULL, /*filterarg*/NULL,
- /*maxsize*/MAXBSIZE, /*nsegments*/AHC_NSEG,
- /*maxsegsz*/AHC_MAXTRANSFER_SIZE,
- /*flags*/BUS_DMA_ALLOCNOW,
- &ahc->buffer_dmat) != 0) {
- return (ENOMEM);
- }
- #endif
- ahc->init_level++;
- /*
- * DMA tag for our command fifos and other data in system memory
- * the card's sequencer must be able to access. For initiator
- * roles, we need to allocate space for the the qinfifo and qoutfifo.
- * The qinfifo and qoutfifo are composed of 256 1 byte elements.
- * When providing for the target mode role, we must additionally
- * provide space for the incoming target command fifo and an extra
- * byte to deal with a dma bug in some chip versions.
- */
- driver_data_size = 2 * 256 * sizeof(uint8_t);
- if ((ahc->features & AHC_TARGETMODE) != 0)
- driver_data_size += AHC_TMODE_CMDS * sizeof(struct target_cmd)
- + /*DMA WideOdd Bug Buffer*/1;
- if (ahc_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1,
- /*boundary*/BUS_SPACE_MAXADDR_32BIT + 1,
- /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
- /*highaddr*/BUS_SPACE_MAXADDR,
- /*filter*/NULL, /*filterarg*/NULL,
- driver_data_size,
- /*nsegments*/1,
- /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT,
- /*flags*/0, &ahc->shared_data_dmat) != 0) {
- return (ENOMEM);
- }
- ahc->init_level++;
- /* Allocation of driver data */
- if (ahc_dmamem_alloc(ahc, ahc->shared_data_dmat,
- (void **)&ahc->qoutfifo,
- BUS_DMA_NOWAIT, &ahc->shared_data_dmamap) != 0) {
- return (ENOMEM);
- }
- ahc->init_level++;
- /* And permanently map it in */
- ahc_dmamap_load(ahc, ahc->shared_data_dmat, ahc->shared_data_dmamap,
- ahc->qoutfifo, driver_data_size, ahc_dmamap_cb,
- &ahc->shared_data_busaddr, /*flags*/0);
- if ((ahc->features & AHC_TARGETMODE) != 0) {
- ahc->targetcmds = (struct target_cmd *)ahc->qoutfifo;
- ahc->qoutfifo = (uint8_t *)&ahc->targetcmds[AHC_TMODE_CMDS];
- ahc->dma_bug_buf = ahc->shared_data_busaddr
- + driver_data_size - 1;
- /* All target command blocks start out invalid. */
- for (i = 0; i < AHC_TMODE_CMDS; i++)
- ahc->targetcmds[i].cmd_valid = 0;
- ahc_sync_tqinfifo(ahc, BUS_DMASYNC_PREREAD);
- ahc->tqinfifonext = 1;
- ahc_outb(ahc, KERNEL_TQINPOS, ahc->tqinfifonext - 1);
- ahc_outb(ahc, TQINPOS, ahc->tqinfifonext);
- ahc->qoutfifo = (uint8_t *)&ahc->targetcmds[256];
- }
- ahc->qinfifo = &ahc->qoutfifo[256];
- ahc->init_level++;
- /* Allocate SCB data now that buffer_dmat is initialized */
- if (ahc->scb_data->maxhscbs == 0)
- if (ahc_init_scbdata(ahc) != 0)
- return (ENOMEM);
- /*
- * Allocate a tstate to house information for our
- * initiator presence on the bus as well as the user
- * data for any target mode initiator.
- */
- if (ahc_alloc_tstate(ahc, ahc->our_id, 'A') == NULL) {
- printf("%s: unable to allocate ahc_tmode_tstate. "
- "Failing attachn", ahc_name(ahc));
- return (ENOMEM);
- }
- if ((ahc->features & AHC_TWIN) != 0) {
- if (ahc_alloc_tstate(ahc, ahc->our_id_b, 'B') == NULL) {
- printf("%s: unable to allocate ahc_tmode_tstate. "
- "Failing attachn", ahc_name(ahc));
- return (ENOMEM);
- }
- }
- ahc_outb(ahc, SEQ_FLAGS, 0);
- ahc_outb(ahc, SEQ_FLAGS2, 0);
- if (ahc->scb_data->maxhscbs < AHC_SCB_MAX_ALLOC) {
- ahc->flags |= AHC_PAGESCBS;
- } else {
- ahc->flags &= ~AHC_PAGESCBS;
- }
- #ifdef AHC_DEBUG
- if (ahc_debug & AHC_SHOWMISC) {
- printf("%s: hardware scb %d bytes; kernel scb %d bytes; "
- "ahc_dma %d bytesn",
- ahc_name(ahc),
- sizeof(struct hardware_scb),
- sizeof(struct scb),
- sizeof(struct ahc_dma_seg));
- }
- #endif /* AHC_DEBUG */
- /* Set the SCSI Id, SXFRCTL0, SXFRCTL1, and SIMODE1, for both channels*/
- if (ahc->features & AHC_TWIN) {
- /*
- * The device is gated to channel B after a chip reset,
- * so set those values first
- */
- ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) | SELBUSB);
- term = (ahc->flags & AHC_TERM_ENB_B) != 0 ? STPWEN : 0;
- ahc_outb(ahc, SCSIID, ahc->our_id_b);
- scsi_conf = ahc_inb(ahc, SCSICONF + 1);
- ahc_outb(ahc, SXFRCTL1, (scsi_conf & (ENSPCHK|STIMESEL))
- |term|ahc->seltime_b|ENSTIMER|ACTNEGEN);
- if ((ahc->features & AHC_ULTRA2) != 0)
- ahc_outb(ahc, SIMODE0, ahc_inb(ahc, SIMODE0)|ENIOERR);
- ahc_outb(ahc, SIMODE1, ENSELTIMO|ENSCSIRST|ENSCSIPERR);
- ahc_outb(ahc, SXFRCTL0, DFON|SPIOEN);
- if ((scsi_conf & RESET_SCSI) != 0
- && (ahc->flags & AHC_INITIATORROLE) != 0)
- ahc->flags |= AHC_RESET_BUS_B;
- /* Select Channel A */
- ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) & ~SELBUSB);
- }
- term = (ahc->flags & AHC_TERM_ENB_A) != 0 ? STPWEN : 0;
- if ((ahc->features & AHC_ULTRA2) != 0)
- ahc_outb(ahc, SCSIID_ULTRA2, ahc->our_id);
- else
- ahc_outb(ahc, SCSIID, ahc->our_id);
- scsi_conf = ahc_inb(ahc, SCSICONF);
- ahc_outb(ahc, SXFRCTL1, (scsi_conf & (ENSPCHK|STIMESEL))
- |term|ahc->seltime
- |ENSTIMER|ACTNEGEN);
- if ((ahc->features & AHC_ULTRA2) != 0)
- ahc_outb(ahc, SIMODE0, ahc_inb(ahc, SIMODE0)|ENIOERR);
- ahc_outb(ahc, SIMODE1, ENSELTIMO|ENSCSIRST|ENSCSIPERR);
- ahc_outb(ahc, SXFRCTL0, DFON|SPIOEN);
- if ((scsi_conf & RESET_SCSI) != 0
- && (ahc->flags & AHC_INITIATORROLE) != 0)
- ahc->flags |= AHC_RESET_BUS_A;
- /*
- * Look at the information that board initialization or
- * the board bios has left us.
- */
- ultraenb = 0;
- tagenable = ALL_TARGETS_MASK;
- /* Grab the disconnection disable table and invert it for our needs */
- if (ahc->flags & AHC_USEDEFAULTS) {
- printf("%s: Host Adapter Bios disabled. Using default SCSI "
- "device parametersn", ahc_name(ahc));
- ahc->flags |= AHC_EXTENDED_TRANS_A|AHC_EXTENDED_TRANS_B|
- AHC_TERM_ENB_A|AHC_TERM_ENB_B;
- discenable = ALL_TARGETS_MASK;
- if ((ahc->features & AHC_ULTRA) != 0)
- ultraenb = ALL_TARGETS_MASK;
- } else {
- discenable = ~((ahc_inb(ahc, DISC_DSB + 1) << 8)
- | ahc_inb(ahc, DISC_DSB));
- if ((ahc->features & (AHC_ULTRA|AHC_ULTRA2)) != 0)
- ultraenb = (ahc_inb(ahc, ULTRA_ENB + 1) << 8)
- | ahc_inb(ahc, ULTRA_ENB);
- }
- if ((ahc->features & (AHC_WIDE|AHC_TWIN)) == 0)
- max_targ = 7;
- for (i = 0; i <= max_targ; i++) {
- struct ahc_initiator_tinfo *tinfo;
- struct ahc_tmode_tstate *tstate;
- u_int our_id;
- u_int target_id;
- char channel;
- channel = 'A';
- our_id = ahc->our_id;
- target_id = i;
- if (i > 7 && (ahc->features & AHC_TWIN) != 0) {
- channel = 'B';
- our_id = ahc->our_id_b;
- target_id = i % 8;
- }
- tinfo = ahc_fetch_transinfo(ahc, channel, our_id,
- target_id, &tstate);
- /* Default to async narrow across the board */
- memset(tinfo, 0, sizeof(*tinfo));
- if (ahc->flags & AHC_USEDEFAULTS) {
- if ((ahc->features & AHC_WIDE) != 0)
- tinfo->user.width = MSG_EXT_WDTR_BUS_16_BIT;
- /*
- * These will be truncated when we determine the
- * connection type we have with the target.
- */
- tinfo->user.period = ahc_syncrates->period;
- tinfo->user.offset = ~0;
- } else {
- u_int scsirate;
- uint16_t mask;
- /* Take the settings leftover in scratch RAM. */
- scsirate = ahc_inb(ahc, TARG_SCSIRATE + i);
- mask = (0x01 << i);
- if ((ahc->features & AHC_ULTRA2) != 0) {
- u_int offset;
- u_int maxsync;
- if ((scsirate & SOFS) == 0x0F) {
- /*
- * Haven't negotiated yet,
- * so the format is different.
- */
- scsirate = (scsirate & SXFR) >> 4
- | (ultraenb & mask)
- ? 0x08 : 0x0
- | (scsirate & WIDEXFER);
- offset = MAX_OFFSET_ULTRA2;
- } else
- offset = ahc_inb(ahc, TARG_OFFSET + i);
- if ((scsirate & ~WIDEXFER) == 0 && offset != 0)
- /* Set to the lowest sync rate, 5MHz */
- scsirate |= 0x1c;
- maxsync = AHC_SYNCRATE_ULTRA2;
- if ((ahc->features & AHC_DT) != 0)
- maxsync = AHC_SYNCRATE_DT;
- tinfo->user.period =
- ahc_find_period(ahc, scsirate, maxsync);
- if (offset == 0)
- tinfo->user.period = 0;
- else
- tinfo->user.offset = ~0;
- if ((scsirate & SXFR_ULTRA2) <= 8/*10MHz*/
- && (ahc->features & AHC_DT) != 0)
- tinfo->user.ppr_options =
- MSG_EXT_PPR_DT_REQ;
- } else if ((scsirate & SOFS) != 0) {
- if ((scsirate & SXFR) == 0x40
- && (ultraenb & mask) != 0) {
- /* Treat 10MHz as a non-ultra speed */
- scsirate &= ~SXFR;
- ultraenb &= ~mask;
- }
- tinfo->user.period =
- ahc_find_period(ahc, scsirate,
- (ultraenb & mask)
- ? AHC_SYNCRATE_ULTRA
- : AHC_SYNCRATE_FAST);
- if (tinfo->user.period != 0)
- tinfo->user.offset = ~0;
- }
- if (tinfo->user.period == 0)
- tinfo->user.offset = 0;
- if ((scsirate & WIDEXFER) != 0
- && (ahc->features & AHC_WIDE) != 0)
- tinfo->user.width = MSG_EXT_WDTR_BUS_16_BIT;
- tinfo->user.protocol_version = 4;
- if ((ahc->features & AHC_DT) != 0)
- tinfo->user.transport_version = 3;
- else
- tinfo->user.transport_version = 2;
- tinfo->goal.protocol_version = 2;
- tinfo->goal.transport_version = 2;
- tinfo->curr.protocol_version = 2;
- tinfo->curr.transport_version = 2;
- }
- tstate->ultraenb = ultraenb;
- }
- ahc->user_discenable = discenable;
- ahc->user_tagenable = tagenable;
- /* There are no untagged SCBs active yet. */
- for (i = 0; i < 16; i++) {
- ahc_unbusy_tcl(ahc, BUILD_TCL(i << 4, 0));
- if ((ahc->flags & AHC_SCB_BTT) != 0) {
- int lun;
- /*
- * The SCB based BTT allows an entry per
- * target and lun pair.
- */
- for (lun = 1; lun < AHC_NUM_LUNS; lun++)
- ahc_unbusy_tcl(ahc, BUILD_TCL(i << 4, lun));
- }
- }
- /* All of our queues are empty */
- for (i = 0; i < 256; i++)
- ahc->qoutfifo[i] = SCB_LIST_NULL;
- ahc_sync_qoutfifo(ahc, BUS_DMASYNC_PREREAD);
- for (i = 0; i < 256; i++)
- ahc->qinfifo[i] = SCB_LIST_NULL;
- if ((ahc->features & AHC_MULTI_TID) != 0) {
- ahc_outb(ahc, TARGID, 0);
- ahc_outb(ahc, TARGID + 1, 0);
- }
- /*
- * Tell the sequencer where it can find our arrays in memory.
- */
- physaddr = ahc->scb_data->hscb_busaddr;
- ahc_outb(ahc, HSCB_ADDR, physaddr & 0xFF);
- ahc_outb(ahc, HSCB_ADDR + 1, (physaddr >> 8) & 0xFF);
- ahc_outb(ahc, HSCB_ADDR + 2, (physaddr >> 16) & 0xFF);
- ahc_outb(ahc, HSCB_ADDR + 3, (physaddr >> 24) & 0xFF);
- physaddr = ahc->shared_data_busaddr;
- ahc_outb(ahc, SHARED_DATA_ADDR, physaddr & 0xFF);
- ahc_outb(ahc, SHARED_DATA_ADDR + 1, (physaddr >> 8) & 0xFF);
- ahc_outb(ahc, SHARED_DATA_ADDR + 2, (physaddr >> 16) & 0xFF);
- ahc_outb(ahc, SHARED_DATA_ADDR + 3, (physaddr >> 24) & 0xFF);
- /*
- * Initialize the group code to command length table.
- * This overrides the values in TARG_SCSIRATE, so only
- * setup the table after we have processed that information.
- */
- ahc_outb(ahc, CMDSIZE_TABLE, 5);
- ahc_outb(ahc, CMDSIZE_TABLE + 1, 9);
- ahc_outb(ahc, CMDSIZE_TABLE + 2, 9);
- ahc_outb(ahc, CMDSIZE_TABLE + 3, 0);
- ahc_outb(ahc, CMDSIZE_TABLE + 4, 15);
- ahc_outb(ahc, CMDSIZE_TABLE + 5, 11);
- ahc_outb(ahc, CMDSIZE_TABLE + 6, 0);
- ahc_outb(ahc, CMDSIZE_TABLE + 7, 0);
-
- /* Tell the sequencer of our initial queue positions */
- ahc_outb(ahc, KERNEL_QINPOS, 0);
- ahc_outb(ahc, QINPOS, 0);
- ahc_outb(ahc, QOUTPOS, 0);
- /*
- * Use the built in queue management registers
- * if they are available.
- */
- if ((ahc->features & AHC_QUEUE_REGS) != 0) {
- ahc_outb(ahc, QOFF_CTLSTA, SCB_QSIZE_256);
- ahc_outb(ahc, SDSCB_QOFF, 0);
- ahc_outb(ahc, SNSCB_QOFF, 0);
- ahc_outb(ahc, HNSCB_QOFF, 0);
- }
- /* We don't have any waiting selections */
- ahc_outb(ahc, WAITING_SCBH, SCB_LIST_NULL);
- /* Our disconnection list is empty too */
- ahc_outb(ahc, DISCONNECTED_SCBH, SCB_LIST_NULL);
- /* Message out buffer starts empty */
- ahc_outb(ahc, MSG_OUT, MSG_NOOP);
- /*
- * Setup the allowed SCSI Sequences based on operational mode.
- * If we are a target, we'll enalbe select in operations once
- * we've had a lun enabled.
- */
- scsiseq_template = ENSELO|ENAUTOATNO|ENAUTOATNP;
- if ((ahc->flags & AHC_INITIATORROLE) != 0)
- scsiseq_template |= ENRSELI;
- ahc_outb(ahc, SCSISEQ_TEMPLATE, scsiseq_template);
- /*
- * Load the Sequencer program and Enable the adapter
- * in "fast" mode.
- */
- if (bootverbose)
- printf("%s: Downloading Sequencer Program...",
- ahc_name(ahc));
- ahc_loadseq(ahc);
- if ((ahc->features & AHC_ULTRA2) != 0) {
- int wait;
- /*
- * Wait for up to 500ms for our transceivers
- * to settle. If the adapter does not have
- * a cable attached, the tranceivers may
- * never settle, so don't complain if we
- * fail here.
- */
- ahc_pause(ahc);
- for (wait = 5000;
- (ahc_inb(ahc, SBLKCTL) & (ENAB40|ENAB20)) == 0 && wait;
- wait--)
- ahc_delay(100);
- ahc_unpause(ahc);
- }
- return (0);
- }
- void
- ahc_intr_enable(struct ahc_softc *ahc, int enable)
- {
- u_int hcntrl;
- hcntrl = ahc_inb(ahc, HCNTRL);
- hcntrl &= ~INTEN;
- ahc->pause &= ~INTEN;
- ahc->unpause &= ~INTEN;
- if (enable) {
- hcntrl |= INTEN;
- ahc->pause |= INTEN;
- ahc->unpause |= INTEN;
- }
- ahc_outb(ahc, HCNTRL, hcntrl);
- }
- /*
- * Ensure that the card is paused in a location
- * outside of all critical sections and that all
- * pending work is completed prior to returning.
- * This routine should only be called from outside
- * an interrupt context.
- */
- void
- ahc_pause_and_flushwork(struct ahc_softc *ahc)
- {
- int intstat;
- int maxloops;
- maxloops = 1000;
- ahc->flags |= AHC_ALL_INTERRUPTS;
- intstat = 0;
- do {
- ahc_intr(ahc);
- ahc_pause(ahc);
- ahc_clear_critical_section(ahc);
- if (intstat == 0xFF && (ahc->features & AHC_REMOVABLE) != 0)
- break;
- maxloops--;
- } while (((intstat = ahc_inb(ahc, INTSTAT)) & INT_PEND) && --maxloops);
- if (maxloops == 0) {
- printf("Infinite interrupt loop, INTSTAT = %x",
- ahc_inb(ahc, INTSTAT));
- }
- ahc_platform_flushwork(ahc);
- ahc->flags &= ~AHC_ALL_INTERRUPTS;
- }
- int
- ahc_suspend(struct ahc_softc *ahc)
- {
- uint8_t *ptr;
- int i;
- ahc_pause_and_flushwork(ahc);
- if (LIST_FIRST(&ahc->pending_scbs) != NULL)
- return (EBUSY);
- #if AHC_TARGET_MODE
- /*
- * XXX What about ATIOs that have not yet been serviced?
- * Perhaps we should just refuse to be suspended if we
- * are acting in a target role.
- */
- if (ahc->pending_device != NULL)
- return (EBUSY);
- #endif
- /* Save volatile registers */
- if ((ahc->features & AHC_TWIN) != 0) {
- ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) | SELBUSB);
- ahc->suspend_state.channel[1].scsiseq = ahc_inb(ahc, SCSISEQ);
- ahc->suspend_state.channel[1].sxfrctl0 = ahc_inb(ahc, SXFRCTL0);
- ahc->suspend_state.channel[1].sxfrctl1 = ahc_inb(ahc, SXFRCTL1);
- ahc->suspend_state.channel[1].simode0 = ahc_inb(ahc, SIMODE0);
- ahc->suspend_state.channel[1].simode1 = ahc_inb(ahc, SIMODE1);
- ahc->suspend_state.channel[1].seltimer = ahc_inb(ahc, SELTIMER);
- ahc->suspend_state.channel[1].seqctl = ahc_inb(ahc, SEQCTL);
- ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) & ~SELBUSB);
- }
- ahc->suspend_state.channel[0].scsiseq = ahc_inb(ahc, SCSISEQ);
- ahc->suspend_state.channel[0].sxfrctl0 = ahc_inb(ahc, SXFRCTL0);
- ahc->suspend_state.channel[0].sxfrctl1 = ahc_inb(ahc, SXFRCTL1);
- ahc->suspend_state.channel[0].simode0 = ahc_inb(ahc, SIMODE0);
- ahc->suspend_state.channel[0].simode1 = ahc_inb(ahc, SIMODE1);
- ahc->suspend_state.channel[0].seltimer = ahc_inb(ahc, SELTIMER);
- ahc->suspend_state.channel[0].seqctl = ahc_inb(ahc, SEQCTL);
- if ((ahc->chip & AHC_PCI) != 0) {
- ahc->suspend_state.dscommand0 = ahc_inb(ahc, DSCOMMAND0);
- ahc->suspend_state.dspcistatus = ahc_inb(ahc, DSPCISTATUS);
- }
- if ((ahc->features & AHC_DT) != 0) {
- u_int sfunct;
- sfunct = ahc_inb(ahc, SFUNCT) & ~ALT_MODE;
- ahc_outb(ahc, SFUNCT, sfunct | ALT_MODE);
- ahc->suspend_state.optionmode = ahc_inb(ahc, OPTIONMODE);
- ahc_outb(ahc, SFUNCT, sfunct);
- ahc->suspend_state.crccontrol1 = ahc_inb(ahc, CRCCONTROL1);
- }
- if ((ahc->features & AHC_MULTI_FUNC) != 0)
- ahc->suspend_state.scbbaddr = ahc_inb(ahc, SCBBADDR);
- if ((ahc->features & AHC_ULTRA2) != 0)
- ahc->suspend_state.dff_thrsh = ahc_inb(ahc, DFF_THRSH);
- ptr = ahc->suspend_state.scratch_ram;
- for (i = 0; i < 64; i++)
- *ptr++ = ahc_inb(ahc, SRAM_BASE + i);
- if ((ahc->features & AHC_MORE_SRAM) != 0) {
- for (i = 0; i < 16; i++)
- *ptr++ = ahc_inb(ahc, TARG_OFFSET + i);
- }
- ptr = ahc->suspend_state.btt;
- if ((ahc->flags & AHC_SCB_BTT) != 0) {
- for (i = 0;i < AHC_NUM_TARGETS; i++) {
- int j;
- for (j = 0;j < AHC_NUM_LUNS; j++) {
- u_int tcl;
- tcl = BUILD_TCL(i << 4, j);
- *ptr = ahc_index_busy_tcl(ahc, tcl);
- }
- }
- }
- ahc_shutdown(ahc);
- return (0);
- }
- int
- ahc_resume(struct ahc_softc *ahc)
- {
- uint8_t *ptr;
- int i;
- ahc_reset(ahc);
- ahc_build_free_scb_list(ahc);
- /* Restore volatile registers */
- if ((ahc->features & AHC_TWIN) != 0) {
- ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) | SELBUSB);
- ahc_outb(ahc, SCSIID, ahc->our_id);
- ahc_outb(ahc, SCSISEQ, ahc->suspend_state.channel[1].scsiseq);
- ahc_outb(ahc, SXFRCTL0, ahc->suspend_state.channel[1].sxfrctl0);
- ahc_outb(ahc, SXFRCTL1, ahc->suspend_state.channel[1].sxfrctl1);
- ahc_outb(ahc, SIMODE0, ahc->suspend_state.channel[1].simode0);
- ahc_outb(ahc, SIMODE1, ahc->suspend_state.channel[1].simode1);
- ahc_outb(ahc, SELTIMER, ahc->suspend_state.channel[1].seltimer);
- ahc_outb(ahc, SEQCTL, ahc->suspend_state.channel[1].seqctl);
- ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) & ~SELBUSB);
- }
- ahc_outb(ahc, SCSISEQ, ahc->suspend_state.channel[0].scsiseq);
- ahc_outb(ahc, SXFRCTL0, ahc->suspend_state.channel[0].sxfrctl0);
- ahc_outb(ahc, SXFRCTL1, ahc->suspend_state.channel[0].sxfrctl1);
- ahc_outb(ahc, SIMODE0, ahc->suspend_state.channel[0].simode0);
- ahc_outb(ahc, SIMODE1, ahc->suspend_state.channel[0].simode1);
- ahc_outb(ahc, SELTIMER, ahc->suspend_state.channel[0].seltimer);
- ahc_outb(ahc, SEQCTL, ahc->suspend_state.channel[0].seqctl);
- if ((ahc->features & AHC_ULTRA2) != 0)
- ahc_outb(ahc, SCSIID_ULTRA2, ahc->our_id);
- else
- ahc_outb(ahc, SCSIID, ahc->our_id);
- if ((ahc->chip & AHC_PCI) != 0) {
- ahc_outb(ahc, DSCOMMAND0, ahc->suspend_state.dscommand0);
- ahc_outb(ahc, DSPCISTATUS, ahc->suspend_state.dspcistatus);
- }
- if ((ahc->features & AHC_DT) != 0) {
- u_int sfunct;
- sfunct = ahc_inb(ahc, SFUNCT) & ~ALT_MODE;
- ahc_outb(ahc, SFUNCT, sfunct | ALT_MODE);
- ahc_outb(ahc, OPTIONMODE, ahc->suspend_state.optionmode);
- ahc_outb(ahc, SFUNCT, sfunct);
- ahc_outb(ahc, CRCCONTROL1, ahc->suspend_state.crccontrol1);
- }
- if ((ahc->features & AHC_MULTI_FUNC) != 0)
- ahc_outb(ahc, SCBBADDR, ahc->suspend_state.scbbaddr);
- if ((ahc->features & AHC_ULTRA2) != 0)
- ahc_outb(ahc, DFF_THRSH, ahc->suspend_state.dff_thrsh);
- ptr = ahc->suspend_state.scratch_ram;
- for (i = 0; i < 64; i++)
- ahc_outb(ahc, SRAM_BASE + i, *ptr++);
- if ((ahc->features & AHC_MORE_SRAM) != 0) {
- for (i = 0; i < 16; i++)
- ahc_outb(ahc, TARG_OFFSET + i, *ptr++);
- }
- ptr = ahc->suspend_state.btt;
- if ((ahc->flags & AHC_SCB_BTT) != 0) {
- for (i = 0;i < AHC_NUM_TARGETS; i++) {
- int j;
- for (j = 0;j < AHC_NUM_LUNS; j++) {
- u_int tcl;
- tcl = BUILD_TCL(i << 4, j);
- ahc_busy_tcl(ahc, tcl, *ptr);
- }
- }
- }
- return (0);
- }
- /************************** Busy Target Table *********************************/
- /*
- * Return the untagged transaction id for a given target/channel lun.
- * Optionally, clear the entry.
- */
- u_int
- ahc_index_busy_tcl(struct ahc_softc *ahc, u_int tcl)
- {
- u_int scbid;
- u_int target_offset;
- if ((ahc->flags & AHC_SCB_BTT) != 0) {
- u_int saved_scbptr;
-
- saved_scbptr = ahc_inb(ahc, SCBPTR);
- ahc_outb(ahc, SCBPTR, TCL_LUN(tcl));
- scbid = ahc_inb(ahc, SCB_64_BTT + TCL_TARGET_OFFSET(tcl));
- ahc_outb(ahc, SCBPTR, saved_scbptr);
- } else {
- target_offset = TCL_TARGET_OFFSET(tcl);
- scbid = ahc_inb(ahc, BUSY_TARGETS + target_offset);
- }
- return (scbid);
- }
- void
- ahc_unbusy_tcl(struct ahc_softc *ahc, u_int tcl)
- {
- u_int target_offset;
- if ((ahc->flags & AHC_SCB_BTT) != 0) {
- u_int saved_scbptr;
-
- saved_scbptr = ahc_inb(ahc, SCBPTR);
- ahc_outb(ahc, SCBPTR, TCL_LUN(tcl));
- ahc_outb(ahc, SCB_64_BTT+TCL_TARGET_OFFSET(tcl), SCB_LIST_NULL);
- ahc_outb(ahc, SCBPTR, saved_scbptr);
- } else {
- target_offset = TCL_TARGET_OFFSET(tcl);
- ahc_outb(ahc, BUSY_TARGETS + target_offset, SCB_LIST_NULL);
- }
- }
- void
- ahc_busy_tcl(struct ahc_softc *ahc, u_int tcl, u_int scbid)
- {
- u_int target_offset;
- if ((ahc->flags & AHC_SCB_BTT) != 0) {
- u_int saved_scbptr;
-
- saved_scbptr = ahc_inb(ahc, SCBPTR);
- ahc_outb(ahc, SCBPTR, TCL_LUN(tcl));
- ahc_outb(ahc, SCB_64_BTT + TCL_TARGET_OFFSET(tcl), scbid);
- ahc_outb(ahc, SCBPTR, saved_scbptr);
- } else {
- target_offset = TCL_TARGET_OFFSET(tcl);
- ahc_outb(ahc, BUSY_TARGETS + target_offset, scbid);
- }
- }
- /************************** SCB and SCB queue management **********************/
- int
- ahc_match_scb(struct ahc_softc *ahc, struct scb *scb, int target,
- char channel, int lun, u_int tag, role_t role)
- {
- int targ = SCB_GET_TARGET(ahc, scb);
- char chan = SCB_GET_CHANNEL(ahc, scb);
- int slun = SCB_GET_LUN(scb);
- int match;
- match = ((chan == channel) || (channel == ALL_CHANNELS));
- if (match != 0)
- match = ((targ == target) || (target == CAM_TARGET_WILDCARD));
- if (match != 0)
- match = ((lun == slun) || (lun == CAM_LUN_WILDCARD));
- if (match != 0) {
- #if AHC_TARGET_MODE
- int group;
- group = XPT_FC_GROUP(scb->io_ctx->ccb_h.func_code);
- if (role == ROLE_INITIATOR) {
- match = (group != XPT_FC_GROUP_TMODE)
- && ((tag == scb->hscb->tag)
- || (tag == SCB_LIST_NULL));
- } else if (role == ROLE_TARGET) {
- match = (group == XPT_FC_GROUP_TMODE)
- && ((tag == scb->io_ctx->csio.tag_id)
- || (tag == SCB_LIST_NULL));
- }
- #else /* !AHC_TARGET_MODE */
- match = ((tag == scb->hscb->tag) || (tag == SCB_LIST_NULL));
- #endif /* AHC_TARGET_MODE */
- }
- return match;
- }
- void
- ahc_freeze_devq(struct ahc_softc *ahc, struct scb *scb)
- {
- int target;
- char channel;
- int lun;
- target = SCB_GET_TARGET(ahc, scb);
- lun = SCB_GET_LUN(scb);
- channel = SCB_GET_CHANNEL(ahc, scb);
-
- ahc_search_qinfifo(ahc, target, channel, lun,
- /*tag*/SCB_LIST_NULL, ROLE_UNKNOWN,
- CAM_REQUEUE_REQ, SEARCH_COMPLETE);
- ahc_platform_freeze_devq(ahc, scb);
- }
- void
- ahc_qinfifo_requeue_tail(struct ahc_softc *ahc, struct scb *scb)
- {
- struct scb *prev_scb;
- prev_scb = NULL;
- if (ahc_qinfifo_count(ahc) != 0) {
- u_int prev_tag;
- uint8_t prev_pos;
- prev_pos = ahc->qinfifonext - 1;
- prev_tag = ahc->qinfifo[prev_pos];
- prev_scb = ahc_lookup_scb(ahc, prev_tag);
- }
- ahc_qinfifo_requeue(ahc, prev_scb, scb);
- if ((ahc->features & AHC_QUEUE_REGS) != 0) {
- ahc_outb(ahc, HNSCB_QOFF, ahc->qinfifonext);
- } else {
- ahc_outb(ahc, KERNEL_QINPOS, ahc->qinfifonext);
- }
- }
- static void
- ahc_qinfifo_requeue(struct ahc_softc *ahc, struct scb *prev_scb,
- struct scb *scb)
- {
- if (prev_scb == NULL) {
- ahc_outb(ahc, NEXT_QUEUED_SCB, scb->hscb->tag);
- } else {
- prev_scb->hscb->next = scb->hscb->tag;
- ahc_sync_scb(ahc, prev_scb,
- BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
- }
- ahc->qinfifo[ahc->qinfifonext++] = scb->hscb->tag;
- scb->hscb->next = ahc->next_queued_scb->hscb->tag;
- ahc_sync_scb(ahc, scb, BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
- }
- static int
- ahc_qinfifo_count(struct ahc_softc *ahc)
- {
- u_int8_t qinpos;
- u_int8_t diff;
- if ((ahc->features & AHC_QUEUE_REGS) != 0) {
- qinpos = ahc_inb(ahc, SNSCB_QOFF);
- ahc_outb(ahc, SNSCB_QOFF, qinpos);
- } else
- qinpos = ahc_inb(ahc, QINPOS);
- diff = ahc->qinfifonext - qinpos;
- return (diff);
- }
- int
- ahc_search_qinfifo(struct ahc_softc *ahc, int target, char channel,
- int lun, u_int tag, role_t role, uint32_t status,
- ahc_search_action action)
- {
- struct scb *scb;
- struct scb *prev_scb;
- uint8_t qinstart;
- uint8_t qinpos;
- uint8_t qintail;
- uint8_t next, prev;
- uint8_t curscbptr;
- int found;
- int maxtarget;
- int i;
- int have_qregs;
- qintail = ahc->qinfifonext;
- have_qregs = (ahc->features & AHC_QUEUE_REGS) != 0;
- if (have_qregs) {
- qinstart = ahc_inb(ahc, SNSCB_QOFF);
- ahc_outb(ahc, SNSCB_QOFF, qinstart);
- } else
- qinstart = ahc_inb(ahc, QINPOS);
- qinpos = qinstart;
- next = ahc_inb(ahc, NEXT_QUEUED_SCB);
- found = 0;
- prev_scb = NULL;
- if (action == SEARCH_COMPLETE) {
- /*
- * Don't attempt to run any queued untagged transactions
- * until we are done with the abort process.
- */
- ahc_freeze_untagged_queues(ahc);
- }
- /*
- * Start with an empty queue. Entries that are not chosen
- * for removal will be re-added to the queue as we go.
- */
- ahc->qinfifonext = qinpos;
- ahc_outb(ahc, NEXT_QUEUED_SCB, ahc->next_queued_scb->hscb->tag);
- while (qinpos != qintail) {
- scb = ahc_lookup_scb(ahc, ahc->qinfifo[qinpos]);
- if (scb == NULL) {
- printf("qinpos = %d, SCB index = %dn",
- qinpos, ahc->qinfifo[qinpos]);
- panic("Loop 1n");
- }
- if (ahc_match_scb(ahc, scb, target, channel, lun, tag, role)) {
- /*
- * We found an scb that needs to be acted on.
- */
- found++;
- switch (action) {
- case SEARCH_COMPLETE:
- {
- cam_status ostat;
- cam_status cstat;
- ostat = ahc_get_transaction_status(scb);
- if (ostat == CAM_REQ_INPROG)
- ahc_set_transaction_status(scb,
- status);
- cstat = ahc_get_transaction_status(scb);
- if (cstat != CAM_REQ_CMP)
- ahc_freeze_scb(scb);
- if ((scb->flags & SCB_ACTIVE) == 0)
- printf("Inactive SCB in qinfifon");
- ahc_done(ahc, scb);
- /* FALLTHROUGH */
- case SEARCH_REMOVE:
- break;
- }
- case SEARCH_COUNT:
- ahc_qinfifo_requeue(ahc, prev_scb, scb);
- prev_scb = scb;
- break;
- }
- } else {
- ahc_qinfifo_requeue(ahc, prev_scb, scb);
- prev_scb = scb;
- }
- qinpos++;
- }
- if ((ahc->features & AHC_QUEUE_REGS) != 0) {
- ahc_outb(ahc, HNSCB_QOFF, ahc->qinfifonext);
- } else {
- ahc_outb(ahc, KERNEL_QINPOS, ahc->qinfifonext);
- }
- if (action != SEARCH_COUNT
- && (found != 0)
- && (qinstart != ahc->qinfifonext)) {
- /*
- * The sequencer may be in the process of dmaing
- * down the SCB at the beginning of the queue.
- * This could be problematic if either the first,
- * or the second SCB is removed from the queue
- * (the first SCB includes a pointer to the "next"
- * SCB to dma). If we have removed any entries, swap
- * the first element in the queue with the next HSCB
- * so the sequencer will notice that NEXT_QUEUED_SCB
- * has changed during its dma attempt and will retry
- * the DMA.
- */
- scb = ahc_lookup_scb(ahc, ahc->qinfifo[qinstart]);
- if (scb == NULL) {
- printf("found = %d, qinstart = %d, qinfifionext = %dn",
- found, qinstart, ahc->qinfifonext);
- panic("First/Second Qinfifo fixupn");
- }
- /*
- * ahc_swap_with_next_hscb forces our next pointer to
- * point to the reserved SCB for future commands. Save
- * and restore our original next pointer to maintain
- * queue integrity.
- */
- next = scb->hscb->next;
- ahc->scb_data->scbindex[scb->hscb->tag] = NULL;
- ahc_swap_with_next_hscb(ahc, scb);
- scb->hscb->next = next;
- ahc->qinfifo[qinstart] = scb->hscb->tag;
- /* Tell the card about the new head of the qinfifo. */
- ahc_outb(ahc, NEXT_QUEUED_SCB, scb->hscb->tag);
- /* Fixup the tail "next" pointer. */
- qintail = ahc->qinfifonext - 1;
- scb = ahc_lookup_scb(ahc, ahc->qinfifo[qintail]);
- scb->hscb->next = ahc->next_queued_scb->hscb->tag;
- }
- /*
- * Search waiting for selection list.
- */
- curscbptr = ahc_inb(ahc, SCBPTR);
- next = ahc_inb(ahc, WAITING_SCBH); /* Start at head of list. */
- prev = SCB_LIST_NULL;
- while (next != SCB_LIST_NULL) {
- uint8_t scb_index;
- ahc_outb(ahc, SCBPTR, next);
- scb_index = ahc_inb(ahc, SCB_TAG);
- if (scb_index >= ahc->scb_data->numscbs) {
- printf("Waiting List inconsistency. "
- "SCB index == %d, yet numscbs == %d.",
- scb_index, ahc->scb_data->numscbs);
- ahc_dump_card_state(ahc);
- panic("for safety");
- }
- scb = ahc_lookup_scb(ahc, scb_index);
- if (scb == NULL) {
- printf("scb_index = %d, next = %dn",
- scb_index, next);
- panic("Waiting List traversaln");
- }
- if (ahc_match_scb(ahc, scb, target, channel,
- lun, SCB_LIST_NULL, role)) {
- /*
- * We found an scb that needs to be acted on.
- */
- found++;
- switch (action) {
- case SEARCH_COMPLETE:
- {
- cam_status ostat;
- cam_status cstat;
- ostat = ahc_get_transaction_status(scb);
- if (ostat == CAM_REQ_INPROG)
- ahc_set_transaction_status(scb,
- status);
- cstat = ahc_get_transaction_status(scb);
- if (cstat != CAM_REQ_CMP)
- ahc_freeze_scb(scb);
- if ((scb->flags & SCB_ACTIVE) == 0)
- printf("Inactive SCB in Waiting Listn");
- ahc_done(ahc, scb);
- /* FALLTHROUGH */
- }
- case SEARCH_REMOVE:
- next = ahc_rem_wscb(ahc, next, prev);
- break;
- case SEARCH_COUNT:
- prev = next;
- next = ahc_inb(ahc, SCB_NEXT);
- break;
- }
- } else {
-
- prev = next;
- next = ahc_inb(ahc, SCB_NEXT);
- }
- }
- ahc_outb(ahc, SCBPTR, curscbptr);
- /*
- * And lastly, the untagged holding queues.
- */
- i = 0;
- if ((ahc->flags & AHC_SCB_BTT) == 0) {
- maxtarget = 16;
- if (target != CAM_TARGET_WILDCARD) {
- i = target;
- if (channel == 'B')
- i += 8;
- maxtarget = i + 1;
- }
- } else {
- maxtarget = 0;
- }
- for (; i < maxtarget; i++) {
- struct scb_tailq *untagged_q;
- struct scb *next_scb;
- untagged_q = &(ahc->untagged_queues[i]);
- next_scb = TAILQ_FIRST(untagged_q);
- while (next_scb != NULL) {
- scb = next_scb;
- next_scb = TAILQ_NEXT(scb, links.tqe);
- /*
- * The head of the list may be the currently
- * active untagged command for a device.
- * We're only searching for commands that
- * have not been started. A transaction
- * marked active but still in the qinfifo
- * is removed by the qinfifo scanning code
- * above.
- */
- if ((scb->flags & SCB_ACTIVE) != 0)
- continue;
- if (ahc_match_scb(ahc, scb, target, channel,
- lun, SCB_LIST_NULL, role)) {
- /*
- * We found an scb that needs to be acted on.
- */
- found++;
- switch (action) {
- case SEARCH_COMPLETE:
- {
- cam_status ostat;
- cam_status cstat;
- ostat = ahc_get_transaction_status(scb);
- if (ostat == CAM_REQ_INPROG)
- ahc_set_transaction_status(scb,
- status);
- cstat = ahc_get_transaction_status(scb);
- if (cstat != CAM_REQ_CMP)
- ahc_freeze_scb(scb);
- if ((scb->flags & SCB_ACTIVE) == 0)
- printf("Inactive SCB in untaggedQn");
- ahc_done(ahc, scb);
- break;
- }
- case SEARCH_REMOVE:
- TAILQ_REMOVE(untagged_q, scb,
- links.tqe);
- break;
- case SEARCH_COUNT:
- break;
- }
- }
- }
- }
- if (action == SEARCH_COMPLETE)
- ahc_release_untagged_queues(ahc);
- return (found);
- }
- int
- ahc_search_disc_list(struct ahc_softc *ahc, int target, char channel,
- int lun, u_int tag, int stop_on_first, int remove,
- int save_state)
- {
- struct scb *scbp;
- u_int next;
- u_int prev;
- u_int count;
- u_int active_scb;
- count = 0;
- next = ahc_inb(ahc, DISCONNECTED_SCBH);
- prev = SCB_LIST_NULL;
- if (save_state) {
- /* restore this when we're done */
- active_scb = ahc_inb(ahc, SCBPTR);
- } else
- /* Silence compiler */
- active_scb = SCB_LIST_NULL;
- while (next != SCB_LIST_NULL) {
- u_int scb_index;
- ahc_outb(ahc, SCBPTR, next);
- scb_index = ahc_inb(ahc, SCB_TAG);
- if (scb_index >= ahc->scb_data->numscbs) {
- printf("Disconnected List inconsistency. "
- "SCB index == %d, yet numscbs == %d.",
- scb_index, ahc->scb_data->numscbs);
- ahc_dump_card_state(ahc);
- panic("for safety");
- }
- if (next == prev) {
- panic("Disconnected List Loop. "
- "cur SCBPTR == %x, prev SCBPTR == %x.",
- next, prev);
- }
- scbp = ahc_lookup_scb(ahc, scb_index);
- if (ahc_match_scb(ahc, scbp, target, channel, lun,
- tag, ROLE_INITIATOR)) {
- count++;
- if (remove) {
- next =
- ahc_rem_scb_from_disc_list(ahc, prev, next);
- } else {
- prev = next;
- next = ahc_inb(ahc, SCB_NEXT);
- }
- if (stop_on_first)
- break;
- } else {
- prev = next;
- next = ahc_inb(ahc, SCB_NEXT);
- }
- }
- if (save_state)
- ahc_outb(ahc, SCBPTR, active_scb);
- return (count);
- }
- /*
- * Remove an SCB from the on chip list of disconnected transactions.
- * This is empty/unused if we are not performing SCB paging.
- */
- static u_int
- ahc_rem_scb_from_disc_list(struct ahc_softc *ahc, u_int prev, u_int scbptr)
- {
- u_int next;
- ahc_outb(ahc, SCBPTR, scbptr);
- next = ahc_inb(ahc, SCB_NEXT);
- ahc_outb(ahc, SCB_CONTROL, 0);
- ahc_add_curscb_to_free_list(ahc);
- if (prev != SCB_LIST_NULL) {
- ahc_outb(ahc, SCBPTR, prev);
- ahc_outb(ahc, SCB_NEXT, next);
- } else
- ahc_outb(ahc, DISCONNECTED_SCBH, next);
- return (next);
- }
- /*
- * Add the SCB as selected by SCBPTR onto the on chip list of
- * free hardware SCBs. This list is empty/unused if we are not
- * performing SCB paging.
- */
- static void
- ahc_add_curscb_to_free_list(struct ahc_softc *ahc)
- {
- /*
- * Invalidate the tag so that our abort
- * routines don't think it's active.
- */
- ahc_outb(ahc, SCB_TAG, SCB_LIST_NULL);
- if ((ahc->flags & AHC_PAGESCBS) != 0) {
- ahc_outb(ahc, SCB_NEXT, ahc_inb(ahc, FREE_SCBH));
- ahc_outb(ahc, FREE_SCBH, ahc_inb(ahc, SCBPTR));
- }
- }
- /*
- * Manipulate the waiting for selection list and return the
- * scb that follows the one that we remove.
- */
- static u_int
- ahc_rem_wscb(struct ahc_softc *ahc, u_int scbpos, u_int prev)
- {
- u_int curscb, next;
- /*
- * Select the SCB we want to abort and
- * pull the next pointer out of it.
- */
- curscb = ahc_inb(ahc, SCBPTR);
- ahc_outb(ahc, SCBPTR, scbpos);
- next = ahc_inb(ahc, SCB_NEXT);
- /* Clear the necessary fields */
- ahc_outb(ahc, SCB_CONTROL, 0);
- ahc_add_curscb_to_free_list(ahc);
- /* update the waiting list */
- if (prev == SCB_LIST_NULL) {
- /* First in the list */
- ahc_outb(ahc, WAITING_SCBH, next);
- /*
- * Ensure we aren't attempting to perform
- * selection for this entry.
- */
- ahc_outb(ahc, SCSISEQ, (ahc_inb(ahc, SCSISEQ) & ~ENSELO));
- } else {
- /*
- * Select the scb that pointed to us
- * and update its next pointer.
- */
- ahc_outb(ahc, SCBPTR, prev);
- ahc_outb(ahc, SCB_NEXT, next);
- }
- /*
- * Point us back at the original scb position.
- */
- ahc_outb(ahc, SCBPTR, curscb);
- return next;
- }
- /******************************** Error Handling ******************************/
- /*
- * Abort all SCBs that match the given description (target/channel/lun/tag),
- * setting their status to the passed in status if the status has not already
- * been modified from CAM_REQ_INPROG. This routine assumes that the sequencer
- * is paused before it is called.
- */
- int
- ahc_abort_scbs(struct ahc_softc *ahc, int target, char channel,
- int lun, u_int tag, role_t role, uint32_t status)
- {
- struct scb *scbp;
- struct scb *scbp_next;
- u_int active_scb;
- int i, j;
- int maxtarget;
- int minlun;
- int maxlun;
- int found;
- /*
- * Don't attempt to run any queued untagged transactions
- * until we are done with the abort process.
- */
- ahc_freeze_untagged_queues(ahc);
- /* restore this when we're done */
- active_scb = ahc_inb(ahc, SCBPTR);
- found = ahc_search_qinfifo(ahc, target, channel, lun, SCB_LIST_NULL,
- role, CAM_REQUEUE_REQ, SEARCH_COMPLETE);
- /*
- * Clean out the busy target table for any untagged commands.
- */
- i = 0;
- maxtarget = 16;
- if (target != CAM_TARGET_WILDCARD) {
- i = target;
- if (channel == 'B')
- i += 8;
- maxtarget = i + 1;
- }
- if (lun == CAM_LUN_WILDCARD) {
- /*
- * Unless we are using an SCB based
- * busy targets table, there is only
- * one table entry for all luns of
- * a target.
- */
- minlun = 0;
- maxlun = 1;
- if ((ahc->flags & AHC_SCB_BTT) != 0)
- maxlun = AHC_NUM_LUNS;
- } else {
- minlun = lun;
- maxlun = lun + 1;
- }
- if (role != ROLE_TARGET) {
- for (;i < maxtarget; i++) {
- for (j = minlun;j < maxlun; j++) {
- u_int scbid;
- u_int tcl;
- tcl = BUILD_TCL(i << 4, j);
- scbid = ahc_index_busy_tcl(ahc, tcl);
- scbp = ahc_lookup_scb(ahc, scbid);
- if (scbp == NULL
- || ahc_match_scb(ahc, scbp, target, channel,
- lun, tag, role) == 0)
- continue;
- ahc_unbusy_tcl(ahc, BUILD_TCL(i << 4, j));
- }
- }
- /*
- * Go through the disconnected list and remove any entries we
- * have queued for completion, 0'ing their control byte too.
- * We save the active SCB and restore it ourselves, so there
- * is no reason for this search to restore it too.
- */
- ahc_search_disc_list(ahc, target, channel, lun, tag,
- /*stop_on_first*/FALSE, /*remove*/TRUE,
- /*save_state*/FALSE);
- }
- /*
- * Go through the hardware SCB array looking for commands that
- * were active but not on any list. In some cases, these remnants
- * might not still have mappings in the scbindex array (e.g. unexpected
- * bus free with the same scb queued for an abort). Don't hold this
- * against them.
- */
- for (i = 0; i < ahc->scb_data->maxhscbs; i++) {
- u_int scbid;
- ahc_outb(ahc, SCBPTR, i);
- scbid = ahc_inb(ahc, SCB_TAG);
- scbp = ahc_lookup_scb(ahc, scbid);
- if ((scbp == NULL && scbid != SCB_LIST_NULL)
- || (scbp != NULL
- && ahc_match_scb(ahc, scbp, target, channel, lun, tag, role)))
- ahc_add_curscb_to_free_list(ahc);
- }
- /*
- * Go through the pending CCB list and look for
- * commands for this target that are still active.
- * These are other tagged commands that were
- * disconnected when the reset occurred.
- */
- scbp_next = LIST_FIRST(&ahc->pending_scbs);
- while (scbp_next != NULL) {
- scbp = scbp_next;
- scbp_next = LIST_NEXT(scbp, pending_links);
- if (ahc_match_scb(ahc, scbp, target, channel, lun, tag, role)) {
- cam_status ostat;
- ostat = ahc_get_transaction_status(scbp);
- if (ostat == CAM_REQ_INPROG)
- ahc_set_transaction_status(scbp, status);
- if (ahc_get_transaction_status(scbp) != CAM_REQ_CMP)
- ahc_freeze_scb(scbp);
- if ((scbp->flags & SCB_ACTIVE) == 0)
- printf("Inactive SCB on pending listn");
- ahc_done(ahc, scbp);
- found++;
- }
- }
- ahc_outb(ahc, SCBPTR, active_scb);
- ahc_platform_abort_scbs(ahc, target, channel, lun, tag, role, status);
- ahc_release_untagged_queues(ahc);
- return found;
- }
- static void
- ahc_reset_current_bus(struct ahc_softc *ahc)
- {
- uint8_t scsiseq;
- ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) & ~ENSCSIRST);
- scsiseq = ahc_inb(ahc, SCSISEQ);
- ahc_outb(ahc, SCSISEQ, scsiseq | SCSIRSTO);
- ahc_delay(AHC_BUSRESET_DELAY);
- /* Turn off the bus reset */
- ahc_outb(ahc, SCSISEQ, scsiseq & ~SCSIRSTO);
- ahc_clear_intstat(ahc);
- /* Re-enable reset interrupts */
- ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) | ENSCSIRST);
- }
- int
- ahc_reset_channel(struct ahc_softc *ahc, char channel, int initiate_reset)
- {
- struct ahc_devinfo devinfo;
- u_int initiator, target, max_scsiid;
- u_int sblkctl;
- u_int scsiseq;
- u_int simode1;
- int found;
- int restart_needed;
- char cur_channel;
- ahc->pending_device = NULL;
- ahc_compile_devinfo(&devinfo,
- CAM_TARGET_WILDCARD,
- CAM_TARGET_WILDCARD,
- CAM_LUN_WILDCARD,
- channel, ROLE_UNKNOWN);
- ahc_pause(ahc);
- /* Make sure the sequencer is in a safe location. */
- ahc_clear_critical_section(ahc);
- /*
- * Run our command complete fifos to ensure that we perform
- * completion processing on any commands that 'completed'
- * before the reset occurred.
- */
- ahc_run_qoutfifo(ahc);
- #if AHC_TARGET_MODE
- if ((ahc->flags & AHC_TARGETROLE) != 0) {
- ahc_run_tqinfifo(ahc, /*paused*/TRUE);
- }
- #endif
- /*
- * Reset the bus if we are initiating this reset
- */
- sblkctl = ahc_inb(ahc, SBLKCTL);
- cur_channel = 'A';
- if ((ahc->features & AHC_TWIN) != 0
- && ((sblkctl & SELBUSB) != 0))
- cur_channel = 'B';
- scsiseq = ahc_inb(ahc, SCSISEQ_TEMPLATE);
- if (cur_channel != channel) {
- /* Case 1: Command for another bus is active
- * Stealthily reset the other bus without
- * upsetting the current bus.
- */
- ahc_outb(ahc, SBLKCTL, sblkctl ^ SELBUSB);
- simode1 = ahc_inb(ahc, SIMODE1) & ~(ENBUSFREE|ENSCSIRST);
- ahc_outb(ahc, SIMODE1, simode1);
- if (initiate_reset)
- ahc_reset_current_bus(ahc);
- ahc_clear_intstat(ahc);
- #if AHC_TARGET_MODE
- /*
- * Bus resets clear ENSELI, so we cannot
- * defer re-enabling bus reset interrupts
- * if we are in target mode.
- */
- if ((ahc->flags & AHC_TARGETROLE) != 0)
- ahc_outb(ahc, SIMODE1, simode1 | ENSCSIRST);
- #endif
- ahc_outb(ahc, SCSISEQ, scsiseq & (ENSELI|ENRSELI|ENAUTOATNP));
- ahc_outb(ahc, SBLKCTL, sblkctl);
- restart_needed = FALSE;
- } else {
- /* Case 2: A command from this bus is active or we're idle */
- ahc_clear_msg_state(ahc);
- simode1 = ahc_inb(ahc, SIMODE1) & ~(ENBUSFREE|ENSCSIRST);
- ahc_outb(ahc, SIMODE1, simode1);
- if (initiate_reset)
- ahc_reset_current_bus(ahc);
- ahc_clear_intstat(ahc);
- #if AHC_TARGET_MODE
- /*
- * Bus resets clear ENSELI, so we cannot
- * defer re-enabling bus reset interrupts
- * if we are in target mode.
- */
- if ((ahc->flags & AHC_TARGETROLE) != 0)
- ahc_outb(ahc, SIMODE1, simode1 | ENSCSIRST);
- #endif
- ahc_outb(ahc, SCSISEQ, scsiseq & (ENSELI|ENRSELI|ENAUTOATNP));
- restart_needed = TRUE;
- }
- /*
- * Clean up all the state information for the
- * pending transactions on this bus.
- */
- found = ahc_abort_scbs(ahc, CAM_TARGET_WILDCARD, channel,
- CAM_LUN_WILDCARD, SCB_LIST_NULL,
- ROLE_UNKNOWN, CAM_SCSI_BUS_RESET);
- max_scsiid = (ahc->features & AHC_WIDE) ? 15 : 7;
- #ifdef AHC_TARGET_MODE
- /*
- * Send an immediate notify ccb to all target more peripheral
- * drivers affected by this action.
- */
- for (target = 0; target <= max_scsiid; target++) {
- struct ahc_tmode_tstate* tstate;
- u_int lun;
- tstate = ahc->enabled_targets[target];
- if (tstate == NULL)
- continue;
- 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, CAM_TARGET_WILDCARD,
- EVENT_TYPE_BUS_RESET, /*arg*/0);
- ahc_send_lstate_events(ahc, lstate);
- }
- }
- #endif
- /* Notify the XPT that a bus reset occurred */
- ahc_send_async(ahc, devinfo.channel, CAM_TARGET_WILDCARD,
- CAM_LUN_WILDCARD, AC_BUS_RESET, NULL);
- /*
- * Revert to async/narrow transfers until we renegotiate.
- */
- for (target = 0; target <= max_scsiid; target++) {
- if (ahc->enabled_targets[target] == NULL)
- continue;
- for (initiator = 0; initiator <= max_scsiid; initiator++) {
- struct ahc_devinfo devinfo;
- ahc_compile_devinfo(&devinfo, target, initiator,
- CAM_LUN_WILDCARD,
- channel, ROLE_UNKNOWN);
- 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);
- }
- }
- if (restart_needed)
- ahc_restart(ahc);
- else
- ahc_unpause(ahc);
- return found;
- }
- /***************************** Residual Processing ****************************/
- /*
- * Calculate the residual for a just completed SCB.
- */
- void
- ahc_calc_residual(struct scb *scb)
- {
- struct hardware_scb *hscb;
- struct status_pkt *spkt;
- uint32_t sgptr;
- uint32_t resid_sgptr;
- uint32_t resid;
- /*
- * 5 cases.
- * 1) No residual.
- * SG_RESID_VALID clear in sgptr.
- * 2) Transferless command
- * 3) Never performed any transfers.
- * sgptr has SG_FULL_RESID set.
- * 4) No residual but target did not
- * save data pointers after the
- * last transfer, so sgptr was
- * never updated.
- * 5) We have a partial residual.
- * Use residual_sgptr to determine
- * where we are.
- */
- hscb = scb->hscb;
- sgptr = ahc_le32toh(hscb->sgptr);
- if ((sgptr & SG_RESID_VALID) == 0)
- /* Case 1 */
- return;
- sgptr &= ~SG_RESID_VALID;
- if ((sgptr & SG_LIST_NULL) != 0)
- /* Case 2 */
- return;
- spkt = &hscb->shared_data.status;
- resid_sgptr = ahc_le32toh(spkt->residual_sg_ptr);
- if ((sgptr & SG_FULL_RESID) != 0) {
- /* Case 3 */
- resid = ahc_get_transfer_length(scb);
- } else if ((resid_sgptr & SG_LIST_NULL) != 0) {
- /* Case 4 */
- return;
- } else if ((resid_sgptr & ~SG_PTR_MASK) != 0) {
- panic("Bogus resid sgptr value 0x%xn", resid_sgptr);
- } else {
- struct ahc_dma_seg *sg;
- /*
- * Remainder of the SG where the transfer
- * stopped.
- */
- resid = ahc_le32toh(spkt->residual_datacnt) & AHC_SG_LEN_MASK;
- sg = ahc_sg_bus_to_virt(scb, resid_sgptr & SG_PTR_MASK);
- /* The residual sg_ptr always points to the next sg */
- sg--;
- /*
- * Add up the contents of all residual
- * SG segments that are after the SG where
- * the transfer stopped.
- */
- while ((ahc_le32toh(sg->len) & AHC_DMA_LAST_SEG) == 0) {
- sg++;
- resid += ahc_le32toh(sg->len) & AHC_SG_LEN_MASK;
- }
- }
- if ((scb->flags & SCB_SENSE) == 0)
- ahc_set_residual(scb, resid);
- else
- ahc_set_sense_residual(scb, resid);
- #ifdef AHC_DEBUG
- if ((ahc_debug & AHC_SHOWMISC) != 0) {
- ahc_print_path(ahc, scb);
- printf("Handled Residual of %d bytesn", resid);
- }
- #endif
- }
- /******************************* Target Mode **********************************/
- #ifdef AHC_TARGET_MODE
- /*
- * Add a target mode event to this lun's queue
- */
- 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)
- {
- struct ahc_tmode_event *event;
- int pending;
- xpt_freeze_devq(lstate->path, /*count*/1);
- if (lstate->event_w_idx >= lstate->event_r_idx)
- pending = lstate->event_w_idx - lstate->event_r_idx;
- else
- pending = AHC_TMODE_EVENT_BUFFER_SIZE + 1
- - (lstate->event_r_idx - lstate->event_w_idx);
- if (event_type == EVENT_TYPE_BUS_RESET
- || event_type == MSG_BUS_DEV_RESET) {
- /*
- * Any earlier events are irrelevant, so reset our buffer.
- * This has the effect of allowing us to deal with reset
- * floods (an external device holding down the reset line)
- * without losing the event that is really interesting.
- */
- lstate->event_r_idx = 0;
- lstate->event_w_idx = 0;
- xpt_release_devq(lstate->path, pending, /*runqueue*/FALSE);
- }
- if (pending == AHC_TMODE_EVENT_BUFFER_SIZE) {
- xpt_print_path(lstate->path);
- printf("immediate event %x:%x lostn",
- lstate->event_buffer[lstate->event_r_idx].event_type,
- lstate->event_buffer[lstate->event_r_idx].event_arg);
- lstate->event_r_idx++;
- if (lstate->event_r_idx == AHC_TMODE_EVENT_BUFFER_SIZE)
- lstate->event_r_idx = 0;
- xpt_release_devq(lstate->path, /*count*/1, /*runqueue*/FALSE);
- }
- event = &lstate->event_buffer[lstate->event_w_idx];
- event->initiator_id = initiator_id;
- event->event_type = event_type;
- event->event_arg = event_arg;
- lstate->event_w_idx++;
- if (lstate->event_w_idx == AHC_TMODE_EVENT_BUFFER_SIZE)
- lstate->event_w_idx = 0;
- }
- /*
- * Send any target mode events queued up waiting
- * for immediate notify resources.
- */
- void
- ahc_send_lstate_events(struct ahc_softc *ahc, struct ahc_tmode_lstate *lstate)
- {
- struct ccb_hdr *ccbh;
- struct ccb_immed_notify *inot;
- while (lstate->event_r_idx != lstate->event_w_idx
- && (ccbh = SLIST_FIRST(&lstate->immed_notifies)) != NULL) {
- struct ahc_tmode_event *event;
- event = &lstate->event_buffer[lstate->event_r_idx];
- SLIST_REMOVE_HEAD(&lstate->immed_notifies, sim_links.sle);
- inot = (struct ccb_immed_notify *)ccbh;
- switch (event->event_type) {
- case EVENT_TYPE_BUS_RESET:
- ccbh->status = CAM_SCSI_BUS_RESET|CAM_DEV_QFRZN;
- break;
- default:
- ccbh->status = CAM_MESSAGE_RECV|CAM_DEV_QFRZN;
- inot->message_args[0] = event->event_type;
- inot->message_args[1] = event->event_arg;
- break;
- }
- inot->initiator_id = event->initiator_id;
- inot->sense_len = 0;
- xpt_done((union ccb *)inot);
- lstate->event_r_idx++;
- if (lstate->event_r_idx == AHC_TMODE_EVENT_BUFFER_SIZE)
- lstate->event_r_idx = 0;
- }
- }
- #endif
- /******************** Sequencer Program Patching/Download *********************/
- #ifdef AHC_DUMP_SEQ
- void
- ahc_dumpseq(struct ahc_softc* ahc)
- {
- int i;
- int max_prog;
- if ((ahc->chip & AHC_BUS_MASK) < AHC_PCI)
- max_prog = 448;
- else if ((ahc->features & AHC_ULTRA2) != 0)
- max_prog = 768;
- else
- max_prog = 512;
- ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS|FASTMODE|LOADRAM);
- ahc_outb(ahc, SEQADDR0, 0);
- ahc_outb(ahc, SEQADDR1, 0);
- for (i = 0; i < max_prog; i++) {
- uint8_t ins_bytes[4];
- ahc_insb(ahc, SEQRAM, ins_bytes, 4);
- printf("0x%08xn", ins_bytes[0] << 24
- | ins_bytes[1] << 16
- | ins_bytes[2] << 8
- | ins_bytes[3]);
- }
- }
- #endif
- static void
- ahc_loadseq(struct ahc_softc *ahc)
- {
- struct cs cs_table[num_critical_sections];
- u_int begin_set[num_critical_sections];
- u_int end_set[num_critical_sections];
- struct patch *cur_patch;
- u_int cs_count;
- u_int cur_cs;
- u_int i;
- int downloaded;
- u_int skip_addr;
- u_int sg_prefetch_cnt;
- uint8_t download_consts[7];
- /*
- * Start out with 0 critical sections
- * that apply to this firmware load.
- */
- cs_count = 0;
- cur_cs = 0;
- memset(begin_set, 0, sizeof(begin_set));
- memset(end_set, 0, sizeof(end_set));
- /* Setup downloadable constant table */
- download_consts[QOUTFIFO_OFFSET] = 0;
- if (ahc->targetcmds != NULL)
- download_consts[QOUTFIFO_OFFSET] += 32;
- download_consts[QINFIFO_OFFSET] = download_consts[QOUTFIFO_OFFSET] + 1;
- download_consts[CACHESIZE_MASK] = ahc->pci_cachesize - 1;
- download_consts[INVERTED_CACHESIZE_MASK] = ~(ahc->pci_cachesize - 1);
- sg_prefetch_cnt = ahc->pci_cachesize;
- if (sg_prefetch_cnt < (2 * sizeof(struct ahc_dma_seg)))
- sg_prefetch_cnt = 2 * sizeof(struct ahc_dma_seg);
- download_consts[SG_PREFETCH_CNT] = sg_prefetch_cnt;
- download_consts[SG_PREFETCH_ALIGN_MASK] = ~(sg_prefetch_cnt - 1);
- download_consts[SG_PREFETCH_ADDR_MASK] = (sg_prefetch_cnt - 1);
- cur_patch = patches;
- downloaded = 0;
- skip_addr = 0;
- ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS|FASTMODE|LOADRAM);
- ahc_outb(ahc, SEQADDR0, 0);
- ahc_outb(ahc, SEQADDR1, 0);
- for (i = 0; i < sizeof(seqprog)/4; i++) {
- if (ahc_check_patch(ahc, &cur_patch, i, &skip_addr) == 0) {
- /*
- * Don't download this instruction as it
- * is in a patch that was removed.
- */
- continue;
- }
- /*
- * Move through the CS table until we find a CS
- * that might apply to this instruction.
- */
- for (; cur_cs < num_critical_sections; cur_cs++) {
- if (critical_sections[cur_cs].end <= i) {
- if (begin_set[cs_count] == TRUE
- && end_set[cs_count] == FALSE) {
- cs_table[cs_count].end = downloaded;
- end_set[cs_count] = TRUE;
- cs_count++;
- }
- continue;
- }
- if (critical_sections[cur_cs].begin <= i
- && begin_set[cs_count] == FALSE) {
- cs_table[cs_count].begin = downloaded;
- begin_set[cs_count] = TRUE;
- }
- break;
- }
- ahc_download_instr(ahc, i, download_consts);
- downloaded++;
- }
- ahc->num_critical_sections = cs_count;
- if (cs_count != 0) {
- cs_count *= sizeof(struct cs);
- ahc->critical_sections = malloc(cs_count, M_DEVBUF, M_NOWAIT);
- if (ahc->critical_sections == NULL)
- panic("ahc_loadseq: Could not malloc");
- memcpy(ahc->critical_sections, cs_table, cs_count);
- }
- ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS|FASTMODE);
- ahc_restart(ahc);
- if (bootverbose)
- printf(" %d instructions downloadedn", downloaded);
- }
- static int
- ahc_check_patch(struct ahc_softc *ahc, struct patch **start_patch,
- u_int start_instr, u_int *skip_addr)
- {
- struct patch *cur_patch;
- struct patch *last_patch;
- u_int num_patches;
- num_patches = sizeof(patches)/sizeof(struct patch);
- last_patch = &patches[num_patches];
- cur_patch = *start_patch;
- while (cur_patch < last_patch && start_instr == cur_patch->begin) {
- if (cur_patch->patch_func(ahc) == 0) {
- /* Start rejecting code */
- *skip_addr = start_instr + cur_patch->skip_instr;
- cur_patch += cur_patch->skip_patch;
- } else {
- /* Accepted this patch. Advance to the next
- * one and wait for our intruction pointer to
- * hit this point.
- */
- cur_patch++;
- }
- }
- *start_patch = cur_patch;
- if (start_instr < *skip_addr)
- /* Still skipping */
- return (0);
- return (1);
- }
- static void
- ahc_download_instr(struct ahc_softc *ahc, u_int instrptr, uint8_t *dconsts)
- {
- union ins_formats instr;
- struct ins_format1 *fmt1_ins;
- struct ins_format3 *fmt3_ins;
- u_int opcode;
- /*
- * The firmware is always compiled into a little endian format.
- */
- instr.integer = ahc_le32toh(*(uint32_t*)&seqprog[instrptr * 4]);
- fmt1_ins = &instr.format1;
- fmt3_ins = NULL;
- /* Pull the opcode */
- opcode = instr.format1.opcode;
- switch (opcode) {
- case AIC_OP_JMP:
- case AIC_OP_JC:
- case AIC_OP_JNC:
- case AIC_OP_CALL:
- case AIC_OP_JNE:
- case AIC_OP_JNZ:
- case AIC_OP_JE:
- case AIC_OP_JZ:
- {
- struct patch *cur_patch;
- int address_offset;
- u_int address;
- u_int skip_addr;
- u_int i;
- fmt3_ins = &instr.format3;
- address_offset = 0;
- address = fmt3_ins->address;
- cur_patch = patches;
- skip_addr = 0;
- for (i = 0; i < address;) {
- ahc_check_patch(ahc, &cur_patch, i, &skip_addr);
- if (skip_addr > i) {
- int end_addr;
- end_addr = MIN(address, skip_addr);
- address_offset += end_addr - i;
- i = skip_addr;
- } else {
- i++;
- }
- }
- address -= address_offset;
- fmt3_ins->address = address;
- /* FALLTHROUGH */
- }
- case AIC_OP_OR:
- case AIC_OP_AND:
- case AIC_OP_XOR:
- case AIC_OP_ADD:
- case AIC_OP_ADC:
- case AIC_OP_BMOV:
- if (fmt1_ins->parity != 0) {
- fmt1_ins->immediate = dconsts[fmt1_ins->immediate];
- }
- fmt1_ins->parity = 0;
- if ((ahc->features & AHC_CMD_CHAN) == 0
- && opcode == AIC_OP_BMOV) {
- /*
- * Block move was added at the same time
- * as the command channel. Verify that
- * this is only a move of a single element
- * and convert the BMOV to a MOV
- * (AND with an immediate of FF).
- */
- if (fmt1_ins->immediate != 1)
- panic("%s: BMOV not supportedn",
- ahc_name(ahc));
- fmt1_ins->opcode = AIC_OP_AND;
- fmt1_ins->immediate = 0xff;
- }
- /* FALLTHROUGH */
- case AIC_OP_ROL:
- if ((ahc->features & AHC_ULTRA2) != 0) {
- int i, count;
- /* Calculate odd parity for the instruction */
- for (i = 0, count = 0; i < 31; i++) {
- uint32_t mask;
- mask = 0x01 << i;
- if ((instr.integer & mask) != 0)
- count++;
- }
- if ((count & 0x01) == 0)
- instr.format1.parity = 1;
- } else {
- /* Compress the instruction for older sequencers */
- if (fmt3_ins != NULL) {
- instr.integer =
- fmt3_ins->immediate
- | (fmt3_ins->source << 8)
- | (fmt3_ins->address << 16)
- | (fmt3_ins->opcode << 25);
- } else {
- instr.integer =
- fmt1_ins->immediate
- | (fmt1_ins->source << 8)
- | (fmt1_ins->destination << 16)
- | (fmt1_ins->ret << 24)
- | (fmt1_ins->opcode << 25);
- }
- }
- /* The sequencer is a little endian cpu */
- instr.integer = ahc_htole32(instr.integer);
- ahc_outsb(ahc, SEQRAM, instr.bytes, 4);
- break;
- default:
- panic("Unknown opcode encountered in seq program");
- break;
- }
- }
- void
- ahc_dump_card_state(struct ahc_softc *ahc)
- {
- struct scb *scb;
- struct scb_tailq *untagged_q;
- int target;
- int maxtarget;
- int i;
- uint8_t last_phase;
- uint8_t qinpos;
- uint8_t qintail;
- uint8_t qoutpos;
- uint8_t scb_index;
- uint8_t saved_scbptr;
- saved_scbptr = ahc_inb(ahc, SCBPTR);
- last_phase = ahc_inb(ahc, LASTPHASE);
- printf("%s: Dumping Card State %s, at SEQADDR 0x%xn",
- ahc_name(ahc), ahc_lookup_phase_entry(last_phase)->phasemsg,
- ahc_inb(ahc, SEQADDR0) | (ahc_inb(ahc, SEQADDR1) << 8));
- printf("ACCUM = 0x%x, SINDEX = 0x%x, DINDEX = 0x%x, ARG_2 = 0x%xn",
- ahc_inb(ahc, ACCUM), ahc_inb(ahc, SINDEX), ahc_inb(ahc, DINDEX),
- ahc_inb(ahc, ARG_2));
- printf("HCNT = 0x%xn", ahc_inb(ahc, HCNT));
- printf("SCSISEQ = 0x%x, SBLKCTL = 0x%xn",
- ahc_inb(ahc, SCSISEQ), ahc_inb(ahc, SBLKCTL));
- printf(" DFCNTRL = 0x%x, DFSTATUS = 0x%xn",
- ahc_inb(ahc, DFCNTRL), ahc_inb(ahc, DFSTATUS));
- printf("LASTPHASE = 0x%x, SCSISIGI = 0x%x, SXFRCTL0 = 0x%xn",
- last_phase, ahc_inb(ahc, SCSISIGI), ahc_inb(ahc, SXFRCTL0));
- printf("SSTAT0 = 0x%x, SSTAT1 = 0x%xn",
- ahc_inb(ahc, SSTAT0), ahc_inb(ahc, SSTAT1));
- if ((ahc->features & AHC_DT) != 0)
- printf("SCSIPHASE = 0x%xn", ahc_inb(ahc, SCSIPHASE));
- printf("STACK == 0x%x, 0x%x, 0x%x, 0x%xn",
- ahc_inb(ahc, STACK) | (ahc_inb(ahc, STACK) << 8),
- ahc_inb(ahc, STACK) | (ahc_inb(ahc, STACK) << 8),
- ahc_inb(ahc, STACK) | (ahc_inb(ahc, STACK) << 8),
- ahc_inb(ahc, STACK) | (ahc_inb(ahc, STACK) << 8));
- printf("SCB count = %dn", ahc->scb_data->numscbs);
- printf("Kernel NEXTQSCB = %dn", ahc->next_queued_scb->hscb->tag);
- printf("Card NEXTQSCB = %dn", ahc_inb(ahc, NEXT_QUEUED_SCB));
- /* QINFIFO */
- printf("QINFIFO entries: ");
- if ((ahc->features & AHC_QUEUE_REGS) != 0) {
- qinpos = ahc_inb(ahc, SNSCB_QOFF);
- ahc_outb(ahc, SNSCB_QOFF, qinpos);
- } else
- qinpos = ahc_inb(ahc, QINPOS);
- qintail = ahc->qinfifonext;
- while (qinpos != qintail) {
- printf("%d ", ahc->qinfifo[qinpos]);
- qinpos++;
- }
- printf("n");
- printf("Waiting Queue entries: ");
- scb_index = ahc_inb(ahc, WAITING_SCBH);
- i = 0;
- while (scb_index != SCB_LIST_NULL && i++ < 256) {
- ahc_outb(ahc, SCBPTR, scb_index);
- printf("%d:%d ", scb_index, ahc_inb(ahc, SCB_TAG));
- scb_index = ahc_inb(ahc, SCB_NEXT);
- }
- printf("n");
- printf("Disconnected Queue entries: ");
- scb_index = ahc_inb(ahc, DISCONNECTED_SCBH);
- i = 0;
- while (scb_index != SCB_LIST_NULL && i++ < 256) {
- ahc_outb(ahc, SCBPTR, scb_index);
- printf("%d:%d ", scb_index, ahc_inb(ahc, SCB_TAG));
- scb_index = ahc_inb(ahc, SCB_NEXT);
- }
- printf("n");
-
- ahc_sync_qoutfifo(ahc, BUS_DMASYNC_POSTREAD);
- printf("QOUTFIFO entries: ");
- qoutpos = ahc->qoutfifonext;
- i = 0;
- while (ahc->qoutfifo[qoutpos] != SCB_LIST_NULL && i++ < 256) {
- printf("%d ", ahc->qoutfifo[qoutpos]);
- qoutpos++;
- }
- printf("n");
- printf("Sequencer Free SCB List: ");
- scb_index = ahc_inb(ahc, FREE_SCBH);
- i = 0;
- while (scb_index != SCB_LIST_NULL && i++ < 256) {
- ahc_outb(ahc, SCBPTR, scb_index);
- printf("%d ", scb_index);
- scb_index = ahc_inb(ahc, SCB_NEXT);
- }
- printf("n");
- printf("Pending list: ");
- i = 0;
- LIST_FOREACH(scb, &ahc->pending_scbs, pending_links) {
- if (i++ > 256)
- break;
- if (scb != LIST_FIRST(&ahc->pending_scbs))
- printf(", ");
- printf("%d", scb->hscb->tag);
- if ((ahc->flags & AHC_PAGESCBS) == 0) {
- ahc_outb(ahc, SCBPTR, scb->hscb->tag);
- printf("(0x%x, 0x%x)", ahc_inb(ahc, SCB_CONTROL),
- ahc_inb(ahc, SCB_TAG));
- }
- }
- printf("n");
- printf("Kernel Free SCB list: ");
- i = 0;
- SLIST_FOREACH(scb, &ahc->scb_data->free_scbs, links.sle) {
- if (i++ > 256)
- break;
- printf("%d ", scb->hscb->tag);
- }
- printf("n");
- maxtarget = (ahc->features & (AHC_WIDE|AHC_TWIN)) ? 15 : 7;
- for (target = 0; target <= maxtarget; target++) {
- untagged_q = &ahc->untagged_queues[target];
- if (TAILQ_FIRST(untagged_q) == NULL)
- continue;
- printf("Untagged Q(%d): ", target);
- i = 0;
- TAILQ_FOREACH(scb, untagged_q, links.tqe) {
- if (i++ > 256)
- break;
- printf("%d ", scb->hscb->tag);
- }
- printf("n");
- }
- ahc_platform_dump_card_state(ahc);
- ahc_outb(ahc, SCBPTR, saved_scbptr);
- }
- /************************* Target Mode ****************************************/
- #ifdef AHC_TARGET_MODE
- cam_status
- ahc_find_tmode_devs(struct ahc_softc *ahc, struct cam_sim *sim, union ccb *ccb,
- struct ahc_tmode_tstate **tstate,
- struct ahc_tmode_lstate **lstate,
- int notfound_failure)
- {
- if ((ahc->features & AHC_TARGETMODE) == 0)
- return (CAM_REQ_INVALID);
- /*
- * Handle the 'black hole' device that sucks up
- * requests to unattached luns on enabled targets.
- */
- if (ccb->ccb_h.target_id == CAM_TARGET_WILDCARD
- && ccb->ccb_h.target_lun == CAM_LUN_WILDCARD) {
- *tstate = NULL;
- *lstate = ahc->black_hole;
- } else {
- u_int max_id;
- max_id = (ahc->features & AHC_WIDE) ? 15 : 7;
- if (ccb->ccb_h.target_id > max_id)
- return (CAM_TID_INVALID);
- if (ccb->ccb_h.target_lun >= AHC_NUM_LUNS)
- return (CAM_LUN_INVALID);
- *tstate = ahc->enabled_targets[ccb->ccb_h.target_id];
- *lstate = NULL;
- if (*tstate != NULL)
- *lstate =
- (*tstate)->enabled_luns[ccb->ccb_h.target_lun];
- }
- if (notfound_failure != 0 && *lstate == NULL)
- return (CAM_PATH_INVALID);
- return (CAM_REQ_CMP);
- }
- void
- ahc_handle_en_lun(struct ahc_softc *ahc, struct cam_sim *sim, union ccb *ccb)
- {
- struct ahc_tmode_tstate *tstate;
- struct ahc_tmode_lstate *lstate;
- struct ccb_en_lun *cel;
- cam_status status;
- u_int target;
- u_int lun;
- u_int target_mask;
- u_long s;
- char channel;
- status = ahc_find_tmode_devs(ahc, sim, ccb, &tstate, &lstate,
- /*notfound_failure*/FALSE);
- if (status != CAM_REQ_CMP) {
- ccb->ccb_h.status = status;
- return;
- }
- if ((ahc->features & AHC_MULTIROLE) != 0) {
- u_int our_id;
- if (cam_sim_bus(sim) == 0)
- our_id = ahc->our_id;
- else
- our_id = ahc->our_id_b;
- if (ccb->ccb_h.target_id != our_id) {
- if ((ahc->features & AHC_MULTI_TID) != 0
- && (ahc->flags & AHC_INITIATORROLE) != 0) {
- /*
- * Only allow additional targets if
- * the initiator role is disabled.
- * The hardware cannot handle a re-select-in
- * on the initiator id during a re-select-out
- * on a different target id.
- */
- status = CAM_TID_INVALID;
- } else if ((ahc->flags & AHC_INITIATORROLE) != 0
- || ahc->enabled_luns > 0) {
- /*
- * Only allow our target id to change
- * if the initiator role is not configured
- * and there are no enabled luns which
- * are attached to the currently registered
- * scsi id.
- */
- status = CAM_TID_INVALID;
- }
- }
- }
- if (status != CAM_REQ_CMP) {
- ccb->ccb_h.status = status;
- return;
- }
- /*
- * We now have an id that is valid.
- * If we aren't in target mode, switch modes.
- */
- if ((ahc->flags & AHC_TARGETROLE) == 0
- && ccb->ccb_h.target_id != CAM_TARGET_WILDCARD) {
- u_long s;
- printf("Configuring Target Moden");
- ahc_lock(ahc, &s);
- if (LIST_FIRST(&ahc->pending_scbs) != NULL) {
- ccb->ccb_h.status = CAM_BUSY;
- ahc_unlock(ahc, &s);
- return;
- }
- ahc->flags |= AHC_TARGETROLE;
- if ((ahc->features & AHC_MULTIROLE) == 0)
- ahc->flags &= ~AHC_INITIATORROLE;
- ahc_pause(ahc);
- ahc_loadseq(ahc);
- ahc_unlock(ahc, &s);
- }
- cel = &ccb->cel;
- target = ccb->ccb_h.target_id;
- lun = ccb->ccb_h.target_lun;
- channel = SIM_CHANNEL(ahc, sim);
- target_mask = 0x01 << target;
- if (channel == 'B')
- target_mask <<= 8;
- if (cel->enable != 0) {
- u_int scsiseq;
- /* Are we already enabled?? */
- if (lstate != NULL) {
- xpt_print_path(ccb->ccb_h.path);
- printf("Lun already enabledn");
- ccb->ccb_h.status = CAM_LUN_ALRDY_ENA;
- return;
- }
- if (cel->grp6_len != 0
- || cel->grp7_len != 0) {
- /*
- * Don't (yet?) support vendor
- * specific commands.
- */
- ccb->ccb_h.status = CAM_REQ_INVALID;
- printf("Non-zero Group Codesn");
- return;
- }
- /*
- * Seems to be okay.
- * Setup our data structures.
- */
- if (target != CAM_TARGET_WILDCARD && tstate == NULL) {
- tstate = ahc_alloc_tstate(ahc, target, channel);
- if (tstate == NULL) {
- xpt_print_path(ccb->ccb_h.path);
- printf("Couldn't allocate tstaten");
- ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
- return;
- }
- }
- lstate = malloc(sizeof(*lstate), M_DEVBUF, M_NOWAIT);
- if (lstate == NULL) {
- xpt_print_path(ccb->ccb_h.path);
- printf("Couldn't allocate lstaten");
- ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
- return;
- }
- memset(lstate, 0, sizeof(*lstate));
- status = xpt_create_path(&lstate->path, /*periph*/NULL,
- xpt_path_path_id(ccb->ccb_h.path),
- xpt_path_target_id(ccb->ccb_h.path),
- xpt_path_lun_id(ccb->ccb_h.path));
- if (status != CAM_REQ_CMP) {
- free(lstate, M_DEVBUF);
- xpt_print_path(ccb->ccb_h.path);
- printf("Couldn't allocate pathn");
- ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
- return;
- }
- SLIST_INIT(&lstate->accept_tios);
- SLIST_INIT(&lstate->immed_notifies);
- ahc_lock(ahc, &s);
- ahc_pause(ahc);
- if (target != CAM_TARGET_WILDCARD) {
- tstate->enabled_luns[lun] = lstate;
- ahc->enabled_luns++;
- if ((ahc->features & AHC_MULTI_TID) != 0) {
- u_int targid_mask;
- targid_mask = ahc_inb(ahc, TARGID)
- | (ahc_inb(ahc, TARGID + 1) << 8);
- targid_mask |= target_mask;
- ahc_outb(ahc, TARGID, targid_mask);
- ahc_outb(ahc, TARGID+1, (targid_mask >> 8));
-
- ahc_update_scsiid(ahc, targid_mask);
- } else {
- u_int our_id;
- char channel;
- channel = SIM_CHANNEL(ahc, sim);
- our_id = SIM_SCSI_ID(ahc, sim);
- /*
- * This can only happen if selections
- * are not enabled
- */
- if (target != our_id) {
- u_int sblkctl;
- char cur_channel;
- int swap;
- sblkctl = ahc_inb(ahc, SBLKCTL);
- cur_channel = (sblkctl & SELBUSB)
- ? 'B' : 'A';
- if ((ahc->features & AHC_TWIN) == 0)
- cur_channel = 'A';
- swap = cur_channel != channel;
- if (channel == 'A')
- ahc->our_id = target;
- else
- ahc->our_id_b = target;
- if (swap)
- ahc_outb(ahc, SBLKCTL,
- sblkctl ^ SELBUSB);
- ahc_outb(ahc, SCSIID, target);
- if (swap)
- ahc_outb(ahc, SBLKCTL, sblkctl);
- }
- }
- } else
- ahc->black_hole = lstate;
- /* Allow select-in operations */
- if (ahc->black_hole != NULL && ahc->enabled_luns > 0) {
- scsiseq = ahc_inb(ahc, SCSISEQ_TEMPLATE);
- scsiseq |= ENSELI;
- ahc_outb(ahc, SCSISEQ_TEMPLATE, scsiseq);
- scsiseq = ahc_inb(ahc, SCSISEQ);
- scsiseq |= ENSELI;
- ahc_outb(ahc, SCSISEQ, scsiseq);
- }
- ahc_unpause(ahc);
- ahc_unlock(ahc, &s);
- ccb->ccb_h.status = CAM_REQ_CMP;
- xpt_print_path(ccb->ccb_h.path);
- printf("Lun now enabled for target moden");
- } else {
- struct scb *scb;
- int i, empty;
- if (lstate == NULL) {
- ccb->ccb_h.status = CAM_LUN_INVALID;
- return;
- }
- ahc_lock(ahc, &s);
-
- ccb->ccb_h.status = CAM_REQ_CMP;
- LIST_FOREACH(scb, &ahc->pending_scbs, pending_links) {
- struct ccb_hdr *ccbh;
- ccbh = &scb->io_ctx->ccb_h;
- if (ccbh->func_code == XPT_CONT_TARGET_IO
- && !xpt_path_comp(ccbh->path, ccb->ccb_h.path)){
- printf("CTIO pendingn");
- ccb->ccb_h.status = CAM_REQ_INVALID;
- ahc_unlock(ahc, &s);
- return;
- }
- }
- if (SLIST_FIRST(&lstate->accept_tios) != NULL) {
- printf("ATIOs pendingn");
- ccb->ccb_h.status = CAM_REQ_INVALID;
- }
- if (SLIST_FIRST(&lstate->immed_notifies) != NULL) {
- printf("INOTs pendingn");
- ccb->ccb_h.status = CAM_REQ_INVALID;
- }
- if (ccb->ccb_h.status != CAM_REQ_CMP) {
- ahc_unlock(ahc, &s);
- return;
- }
- xpt_print_path(ccb->ccb_h.path);
- printf("Target mode disabledn");
- xpt_free_path(lstate->path);
- free(lstate, M_DEVBUF);
- ahc_pause(ahc);
- /* Can we clean up the target too? */
- if (target != CAM_TARGET_WILDCARD) {
- tstate->enabled_luns[lun] = NULL;
- ahc->enabled_luns--;
- for (empty = 1, i = 0; i < 8; i++)
- if (tstate->enabled_luns[i] != NULL) {
- empty = 0;
- break;
- }
- if (empty) {
- ahc_free_tstate(ahc, target, channel,
- /*force*/FALSE);
- if (ahc->features & AHC_MULTI_TID) {
- u_int targid_mask;
- targid_mask = ahc_inb(ahc, TARGID)
- | (ahc_inb(ahc, TARGID + 1)
- << 8);
- targid_mask &= ~target_mask;
- ahc_outb(ahc, TARGID, targid_mask);
- ahc_outb(ahc, TARGID+1,
- (targid_mask >> 8));
- ahc_update_scsiid(ahc, targid_mask);
- }
- }
- } else {
- ahc->black_hole = NULL;
- /*
- * We can't allow selections without
- * our black hole device.
- */
- empty = TRUE;
- }
- if (ahc->enabled_luns == 0) {
- /* Disallow select-in */
- u_int scsiseq;
- scsiseq = ahc_inb(ahc, SCSISEQ_TEMPLATE);
- scsiseq &= ~ENSELI;
- ahc_outb(ahc, SCSISEQ_TEMPLATE, scsiseq);
- scsiseq = ahc_inb(ahc, SCSISEQ);
- scsiseq &= ~ENSELI;
- ahc_outb(ahc, SCSISEQ, scsiseq);
- if ((ahc->features & AHC_MULTIROLE) == 0) {
- printf("Configuring Initiator Moden");
- ahc->flags &= ~AHC_TARGETROLE;
- ahc->flags |= AHC_INITIATORROLE;
- ahc_pause(ahc);
- ahc_loadseq(ahc);
- }
- }
- ahc_unpause(ahc);
- ahc_unlock(ahc, &s);
- }
- }
- static void
- ahc_update_scsiid(struct ahc_softc *ahc, u_int targid_mask)
- {
- u_int scsiid_mask;
- u_int scsiid;
- if ((ahc->features & AHC_MULTI_TID) == 0)
- panic("ahc_update_scsiid called on non-multitid unitn");
- /*
- * Since we will rely on the the TARGID mask
- * for selection enables, ensure that OID
- * in SCSIID is not set to some other ID
- * that we don't want to allow selections on.
- */
- if ((ahc->features & AHC_ULTRA2) != 0)
- scsiid = ahc_inb(ahc, SCSIID_ULTRA2);
- else
- scsiid = ahc_inb(ahc, SCSIID);
- scsiid_mask = 0x1 << (scsiid & OID);
- if ((targid_mask & scsiid_mask) == 0) {
- u_int our_id;
- /* ffs counts from 1 */
- our_id = ffs(targid_mask);
- if (our_id == 0)
- our_id = ahc->our_id;
- else
- our_id--;
- scsiid &= TID;
- scsiid |= our_id;
- }
- if ((ahc->features & AHC_ULTRA2) != 0)
- ahc_outb(ahc, SCSIID_ULTRA2, scsiid);
- else
- ahc_outb(ahc, SCSIID, scsiid);
- }
- void
- ahc_run_tqinfifo(struct ahc_softc *ahc, int paused)
- {
- struct target_cmd *cmd;
- /*
- * If the card supports auto-access pause,
- * we can access the card directly regardless
- * of whether it is paused or not.
- */
- if ((ahc->features & AHC_AUTOPAUSE) != 0)
- paused = TRUE;
- ahc_sync_tqinfifo(ahc, BUS_DMASYNC_POSTREAD);
- while ((cmd = &ahc->targetcmds[ahc->tqinfifonext])->cmd_valid != 0) {
- /*
- * Only advance through the queue if we
- * have the resources to process the command.
- */
- if (ahc_handle_target_cmd(ahc, cmd) != 0)
- break;
- cmd->cmd_valid = 0;
- ahc_dmamap_sync(ahc, ahc->shared_data_dmat,
- ahc->shared_data_dmamap,
- ahc_targetcmd_offset(ahc, ahc->tqinfifonext),
- sizeof(struct target_cmd),
- BUS_DMASYNC_PREREAD);
- ahc->tqinfifonext++;
- /*
- * Lazily update our position in the target mode incoming
- * command queue as seen by the sequencer.
- */
- if ((ahc->tqinfifonext & (HOST_TQINPOS - 1)) == 1) {
- if ((ahc->features & AHC_HS_MAILBOX) != 0) {
- u_int hs_mailbox;
- hs_mailbox = ahc_inb(ahc, HS_MAILBOX);
- hs_mailbox &= ~HOST_TQINPOS;
- hs_mailbox |= ahc->tqinfifonext & HOST_TQINPOS;
- ahc_outb(ahc, HS_MAILBOX, hs_mailbox);
- } else {
- if (!paused)
- ahc_pause(ahc);
- ahc_outb(ahc, KERNEL_TQINPOS,
- ahc->tqinfifonext & HOST_TQINPOS);
- if (!paused)
- ahc_unpause(ahc);
- }
- }
- }
- }
- static int
- ahc_handle_target_cmd(struct ahc_softc *ahc, struct target_cmd *cmd)
- {
- struct ahc_tmode_tstate *tstate;
- struct ahc_tmode_lstate *lstate;
- struct ccb_accept_tio *atio;
- uint8_t *byte;
- int initiator;
- int target;
- int lun;
- initiator = SCSIID_TARGET(ahc, cmd->scsiid);
- target = SCSIID_OUR_ID(cmd->scsiid);
- lun = (cmd->identify & MSG_IDENTIFY_LUNMASK);
- byte = cmd->bytes;
- tstate = ahc->enabled_targets[target];
- lstate = NULL;
- if (tstate != NULL)
- lstate = tstate->enabled_luns[lun];
- /*
- * Commands for disabled luns go to the black hole driver.
- */
- if (lstate == NULL)
- lstate = ahc->black_hole;
- atio = (struct ccb_accept_tio*)SLIST_FIRST(&lstate->accept_tios);
- if (atio == NULL) {
- ahc->flags |= AHC_TQINFIFO_BLOCKED;
- /*
- * Wait for more ATIOs from the peripheral driver for this lun.
- */
- return (1);
- } else
- ahc->flags &= ~AHC_TQINFIFO_BLOCKED;
- #if 0
- printf("Incoming command from %d for %d:%d%sn",
- initiator, target, lun,
- lstate == ahc->black_hole ? "(Black Holed)" : "");
- #endif
- SLIST_REMOVE_HEAD(&lstate->accept_tios, sim_links.sle);
- if (lstate == ahc->black_hole) {
- /* Fill in the wildcards */
- atio->ccb_h.target_id = target;
- atio->ccb_h.target_lun = lun;
- }
- /*
- * Package it up and send it off to
- * whomever has this lun enabled.
- */
- atio->sense_len = 0;
- atio->init_id = initiator;
- if (byte[0] != 0xFF) {
- /* Tag was included */
- atio->tag_action = *byte++;
- atio->tag_id = *byte++;
- atio->ccb_h.flags = CAM_TAG_ACTION_VALID;
- } else {
- atio->ccb_h.flags = 0;
- }
- byte++;
- /* Okay. Now determine the cdb size based on the command code */
- switch (*byte >> CMD_GROUP_CODE_SHIFT) {
- case 0:
- atio->cdb_len = 6;
- break;
- case 1:
- case 2:
- atio->cdb_len = 10;
- break;
- case 4:
- atio->cdb_len = 16;
- break;
- case 5:
- atio->cdb_len = 12;
- break;
- case 3:
- default:
- /* Only copy the opcode. */
- atio->cdb_len = 1;
- printf("Reserved or VU command code type encounteredn");
- break;
- }
-
- memcpy(atio->cdb_io.cdb_bytes, byte, atio->cdb_len);
- atio->ccb_h.status |= CAM_CDB_RECVD;
- if ((cmd->identify & MSG_IDENTIFY_DISCFLAG) == 0) {
- /*
- * We weren't allowed to disconnect.
- * We're hanging on the bus until a
- * continue target I/O comes in response
- * to this accept tio.
- */
- #if 0
- printf("Received Immediate Command %d:%d:%d - %pn",
- initiator, target, lun, ahc->pending_device);
- #endif
- ahc->pending_device = lstate;
- ahc_freeze_ccb((union ccb *)atio);
- atio->ccb_h.flags |= CAM_DIS_DISCONNECT;
- }
- xpt_done((union ccb*)atio);
- return (0);
- }
- #endif