--- //depot/vendor/freebsd/src/sys/dev/advansys/adv_eisa.c 2012-03-12 19:30:21.000000000 0000 +++ //depot/user/jhb/cleanup/sys/dev/advansys/adv_eisa.c 2012-08-29 15:00:11.000000000 0000 @@ -131,17 +131,27 @@ return 0; } +/* + * The adv_b stuff to handle twin-channel cards will not work in its current + * incarnation. It tries to reuse the same softc since adv_alloc() doesn't + * actually allocate a softc. It also tries to reuse the same unit number + * for both sims. This can be re-enabled if someone fixes it properly. + */ static int adv_eisa_attach(device_t dev) { struct adv_softc *adv; +#if 0 struct adv_softc *adv_b; +#endif struct resource *io; struct resource *irq; int rid, error; void *ih; +#if 0 adv_b = NULL; +#endif rid = 0; io = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE); @@ -162,8 +172,8 @@ switch (eisa_get_id(dev) & ~0xF) { case EISA_DEVICE_ID_ADVANSYS_750: - adv_b = adv_alloc(dev, rman_get_bustag(io), - rman_get_bushandle(io) + ADV_EISA_OFFSET_CHAN2); +#if 0 + adv_b = adv_alloc(dev, io, ADV_EISA_OFFSET_CHAN2); if (adv_b == NULL) goto bad; @@ -183,26 +193,28 @@ /* nsegments */ ~0, /* maxsegsz */ ADV_EISA_MAX_DMA_COUNT, /* flags */ 0, - /* lockfunc */ busdma_lock_mutex, - /* lockarg */ &Giant, + /* lockfunc */ NULL, + /* lockarg */ NULL, &adv_b->parent_dmat); if (error != 0) { - printf("%s: Could not allocate DMA tag - error %d\n", - adv_name(adv_b), error); + device_printf(dev, "Could not allocate DMA tag - error %d\n", + error); adv_free(adv_b); goto bad; } adv_b->init_level++; +#endif /* FALLTHROUGH */ case EISA_DEVICE_ID_ADVANSYS_740: - adv = adv_alloc(dev, rman_get_bustag(io), - rman_get_bushandle(io) + ADV_EISA_OFFSET_CHAN1); + adv = adv_alloc(dev, io, ADV_EISA_OFFSET_CHAN1); if (adv == NULL) { +#if 0 if (adv_b != NULL) adv_free(adv_b); +#endif goto bad; } @@ -222,13 +234,13 @@ /* nsegments */ ~0, /* maxsegsz */ ADV_EISA_MAX_DMA_COUNT, /* flags */ 0, - /* lockfunc */ busdma_lock_mutex, - /* lockarg */ &Giant, + /* lockfunc */ NULL, + /* lockarg */ NULL, &adv->parent_dmat); if (error != 0) { - printf("%s: Could not allocate DMA tag - error %d\n", - adv_name(adv), error); + device_printf(dev, "Could not allocate DMA tag - error %d\n", + error); adv_free(adv); goto bad; } @@ -244,7 +256,7 @@ if (overrun_buf == NULL) { /* Need to allocate our overrun buffer */ if (bus_dma_tag_create( - /* parent */ adv->parent_dmat, + /* parent */ bus_get_dma_tag(dev), /* alignment */ 8, /* boundary */ 0, /* lowaddr */ ADV_EISA_MAX_DMA_ADDR, @@ -255,8 +267,8 @@ /* nsegments */ 1, /* maxsegsz */ BUS_SPACE_MAXSIZE_32BIT, /* flags */ 0, - /* lockfunc */ busdma_lock_mutex, - /* lockarg */ &Giant, + /* lockfunc */ NULL, + /* lockarg */ NULL, &overrun_dmat) != 0) { adv_free(adv); goto bad; @@ -292,14 +304,17 @@ if (adv_init(adv) != 0) { adv_free(adv); +#if 0 if (adv_b != NULL) adv_free(adv_b); - return(-1); +#endif + goto bad; } adv->max_dma_count = ADV_EISA_MAX_DMA_COUNT; adv->max_dma_addr = ADV_EISA_MAX_DMA_ADDR; +#if 0 if (adv_b != NULL) { /* * Stop the chip. @@ -317,24 +332,33 @@ adv_b->max_dma_addr = ADV_EISA_MAX_DMA_ADDR; } } +#endif /* * Enable our interrupt handler. */ - bus_setup_intr(dev, irq, INTR_TYPE_CAM|INTR_ENTROPY, NULL, adv_intr, - adv, &ih); + if (bus_setup_intr(dev, irq, INTR_TYPE_CAM|INTR_ENTROPY|INTR_MPSAFE, NULL, + adv_intr, adv, &ih) != 0) { + adv_free(adv); + goto bad; + } - /* Attach sub-devices - always succeeds */ - adv_attach(adv); + /* Attach sub-devices */ + if (adv_attach(adv) != 0) { + adv_free(adv); + goto bad; + } +#if 0 if (adv_b != NULL) adv_attach(adv_b); +#endif return 0; bad: bus_release_resource(dev, SYS_RES_IOPORT, 0, io); bus_release_resource(dev, SYS_RES_IRQ, 0, irq); - return -1; + return ENXIO; } static device_method_t adv_eisa_methods[] = { --- //depot/vendor/freebsd/src/sys/dev/advansys/adv_isa.c 2012-03-12 19:30:21.000000000 0000 +++ //depot/user/jhb/cleanup/sys/dev/advansys/adv_isa.c 2012-08-29 15:00:11.000000000 0000 @@ -135,12 +135,13 @@ if ((port_index > max_port_index) || (iobase != adv_isa_ioports[port_index])) { if (bootverbose) - printf("adv%d: Invalid baseport of 0x%lx specified. " - "Nearest valid baseport is 0x%x. Failing " - "probe.\n", device_get_unit(dev), iobase, - (port_index <= max_port_index) ? - adv_isa_ioports[port_index] : - adv_isa_ioports[max_port_index]); + device_printf(dev, + "Invalid baseport of 0x%lx specified. " + "Nearest valid baseport is 0x%x. Failing " + "probe.\n", iobase, + (port_index <= max_port_index) ? + adv_isa_ioports[port_index] : + adv_isa_ioports[max_port_index]); return ENXIO; } max_port_index = port_index; @@ -169,8 +170,7 @@ if (iores == NULL) continue; - if (adv_find_signature(rman_get_bustag(iores), - rman_get_bushandle(iores)) == 0) { + if (adv_find_signature(iores) == 0) { bus_release_resource(dev, SYS_RES_IOPORT, 0, iores); continue; } @@ -179,8 +179,7 @@ * Got one. Now allocate our softc * and see if we can initialize the card. */ - adv = adv_alloc(dev, rman_get_bustag(iores), - rman_get_bushandle(iores)); + adv = adv_alloc(dev, iores, 0); if (adv == NULL) { bus_release_resource(dev, SYS_RES_IOPORT, 0, iores); break; @@ -238,13 +237,13 @@ /* nsegments */ ~0, /* maxsegsz */ maxsegsz, /* flags */ 0, - /* lockfunc */ busdma_lock_mutex, - /* lockarg */ &Giant, + /* lockfunc */ NULL, + /* lockarg */ NULL, &adv->parent_dmat); if (error != 0) { - printf("%s: Could not allocate DMA tag - error %d\n", - adv_name(adv), error); + device_printf(dev, + "Could not allocate DMA tag - error %d\n", error); adv_free(adv); bus_release_resource(dev, SYS_RES_IOPORT, 0, iores); break; @@ -335,8 +334,11 @@ irqres = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE); if (irqres == NULL || - bus_setup_intr(dev, irqres, INTR_TYPE_CAM|INTR_ENTROPY, - NULL, adv_intr, adv, &ih)) { + bus_setup_intr(dev, irqres, INTR_TYPE_CAM|INTR_ENTROPY| + INTR_MPSAFE, NULL, adv_intr, adv, &ih) != 0) { + if (irqres != NULL) + bus_release_resource(dev, SYS_RES_IRQ, rid, + irqres); bus_dmamap_unload(overrun_dmat, overrun_dmamap); bus_dmamem_free(overrun_dmat, overrun_buf, overrun_dmamap); --- //depot/vendor/freebsd/src/sys/dev/advansys/adv_pci.c 2012-03-12 19:30:21.000000000 0000 +++ //depot/user/jhb/cleanup/sys/dev/advansys/adv_pci.c 2012-08-30 02:05:23.000000000 0000 @@ -138,7 +138,6 @@ { struct adv_softc *adv; u_int32_t id; - u_int32_t command; int error, rid, irqrid; void *ih; struct resource *iores, *irqres; @@ -146,19 +145,8 @@ /* * Determine the chip version. */ - id = pci_read_config(dev, PCIR_DEVVENDOR, /*bytes*/4); - command = pci_read_config(dev, PCIR_COMMAND, /*bytes*/1); - - /* - * These cards do not allow memory mapped accesses, so we must - * ensure that I/O accesses are available or we won't be able - * to talk to them. - */ - if ((command & (PCIM_CMD_PORTEN|PCIM_CMD_BUSMASTEREN)) - != (PCIM_CMD_PORTEN|PCIM_CMD_BUSMASTEREN)) { - command |= PCIM_CMD_PORTEN|PCIM_CMD_BUSMASTEREN; - pci_write_config(dev, PCIR_COMMAND, command, /*bytes*/1); - } + id = pci_get_devid(dev); + pci_enable_busmaster(dev); /* * Early chips can't handle non-zero latency timer settings. @@ -174,13 +162,12 @@ if (iores == NULL) return ENXIO; - if (adv_find_signature(rman_get_bustag(iores), - rman_get_bushandle(iores)) == 0) { + if (adv_find_signature(iores) == 0) { bus_release_resource(dev, SYS_RES_IOPORT, rid, iores); return ENXIO; } - adv = adv_alloc(dev, rman_get_bustag(iores), rman_get_bushandle(iores)); + adv = adv_alloc(dev, iores, 0); if (adv == NULL) { bus_release_resource(dev, SYS_RES_IOPORT, rid, iores); return ENXIO; @@ -199,13 +186,13 @@ /* nsegments */ ~0, /* maxsegsz */ ADV_PCI_MAX_DMA_COUNT, /* flags */ 0, - /* lockfunc */ busdma_lock_mutex, - /* lockarg */ &Giant, + /* lockfunc */ NULL, + /* lockarg */ NULL, &adv->parent_dmat); if (error != 0) { - printf("%s: Could not allocate DMA tag - error %d\n", - adv_name(adv), error); + device_printf(dev, "Could not allocate DMA tag - error %d\n", + error); adv_free(adv); bus_release_resource(dev, SYS_RES_IOPORT, rid, iores); return ENXIO; @@ -227,8 +214,8 @@ /* nsegments */ 1, /* maxsegsz */ BUS_SPACE_MAXSIZE_32BIT, /* flags */ 0, - /* lockfunc */ busdma_lock_mutex, - /* lockarg */ &Giant, + /* lockfunc */ NULL, + /* lockarg */ NULL, &overrun_dmat) != 0) { bus_dma_tag_destroy(adv->parent_dmat); adv_free(adv); @@ -308,14 +295,22 @@ irqres = bus_alloc_resource_any(dev, SYS_RES_IRQ, &irqrid, RF_SHAREABLE | RF_ACTIVE); if (irqres == NULL || - bus_setup_intr(dev, irqres, INTR_TYPE_CAM|INTR_ENTROPY, NULL, - adv_intr, adv, &ih)) { + bus_setup_intr(dev, irqres, INTR_TYPE_CAM|INTR_ENTROPY|INTR_MPSAFE, + NULL, adv_intr, adv, &ih) != 0) { + if (irqres != NULL) + bus_release_resource(dev, SYS_RES_IRQ, irqrid, irqres); adv_free(adv); bus_release_resource(dev, SYS_RES_IOPORT, rid, iores); return ENXIO; } - adv_attach(adv); + if (adv_attach(adv) != 0) { + bus_teardown_intr(dev, irqres, ih); + bus_release_resource(dev, SYS_RES_IRQ, irqrid, irqres); + adv_free(adv); + bus_release_resource(dev, SYS_RES_IOPORT, rid, iores); + return ENXIO; + } return 0; } --- //depot/vendor/freebsd/src/sys/dev/advansys/advansys.c 2009-07-10 08:25:14.000000000 0000 +++ //depot/user/jhb/cleanup/sys/dev/advansys/advansys.c 2012-08-30 02:05:23.000000000 0000 @@ -49,6 +49,7 @@ __FBSDID("$FreeBSD: src/sys/dev/advansys/advansys.c,v 1.36 2009/07/10 08:18:08 scottl Exp $"); #include +#include #include #include #include @@ -79,6 +80,7 @@ static void adv_action(struct cam_sim *sim, union ccb *ccb); static void adv_execute_ccb(void *arg, bus_dma_segment_t *dm_segs, int nsegments, int error); +static void adv_intr_locked(struct adv_softc *adv); static void adv_poll(struct cam_sim *sim); static void adv_run_doneq(struct adv_softc *adv); static struct adv_ccb_info * @@ -97,15 +99,14 @@ adv_get_ccb_info(struct adv_softc *adv) { struct adv_ccb_info *cinfo; - int opri; - opri = splcam(); + if (!dumping) + mtx_assert(&adv->lock, MA_OWNED); if ((cinfo = SLIST_FIRST(&adv->free_ccb_infos)) != NULL) { SLIST_REMOVE_HEAD(&adv->free_ccb_infos, links); } else { cinfo = adv_alloc_ccb_info(adv); } - splx(opri); return (cinfo); } @@ -113,12 +114,11 @@ static __inline void adv_free_ccb_info(struct adv_softc *adv, struct adv_ccb_info *cinfo) { - int opri; - opri = splcam(); + if (!dumping) + mtx_assert(&adv->lock, MA_OWNED); cinfo->state = ACCB_FREE; SLIST_INSERT_HEAD(&adv->free_ccb_infos, cinfo, links); - splx(opri); } static __inline void @@ -139,6 +139,9 @@ static void adv_clear_state_really(struct adv_softc *adv, union ccb* ccb) { + + if (!dumping) + mtx_assert(&adv->lock, MA_OWNED); if ((adv->state & ADV_BUSDMA_BLOCK_CLEARED) != 0) adv->state &= ~(ADV_BUSDMA_BLOCK_CLEARED|ADV_BUSDMA_BLOCK); if ((adv->state & ADV_RESOURCE_SHORTAGE) != 0) { @@ -164,13 +167,14 @@ */ ccb_h = LIST_FIRST(&adv->pending_ccbs); while (ccb_h != NULL) { - ccb_h->timeout_ch = - timeout(adv_timeout, (caddr_t)ccb_h, - (ccb_h->timeout * hz) / 1000); + cinfo = ccb_h->ccb_cinfo_ptr; + callout_reset(&cinfo->timer, + ccb_h->timeout * hz / 1000, adv_timeout, + ccb_h); ccb_h = LIST_NEXT(ccb_h, sim_links.le); } adv->state &= ~ADV_IN_TIMEOUT; - printf("%s: No longer in timeout\n", adv_name(adv)); + device_printf(adv->dev, "No longer in timeout\n"); } } if (adv->state == 0) @@ -186,15 +190,6 @@ *physaddr = segs->ds_addr; } -char * -adv_name(struct adv_softc *adv) -{ - static char name[10]; - - snprintf(name, sizeof(name), "adv%d", adv->unit); - return (name); -} - static void adv_action(struct cam_sim *sim, union ccb *ccb) { @@ -203,6 +198,7 @@ CAM_DEBUG(ccb->ccb_h.path, CAM_DEBUG_TRACE, ("adv_action\n")); adv = (struct adv_softc *)cam_sim_softc(sim); + mtx_assert(&adv->lock, MA_OWNED); switch (ccb->ccb_h.func_code) { /* Common cases first */ @@ -229,10 +225,8 @@ * to a single buffer */ if ((ccb_h->flags & CAM_DATA_PHYS) == 0) { - int s; int error; - s = splsoftvm(); error = bus_dmamap_load(adv->buffer_dmat, cinfo->dmamap, @@ -250,7 +244,6 @@ adv_set_state(adv, ADV_BUSDMA_BLOCK); } - splx(s); } else { struct bus_dma_segment seg; @@ -299,7 +292,6 @@ target_bit_vector targ_mask; struct adv_transinfo *tconf; u_int update_type; - int s; cts = &ccb->cts; targ_mask = ADV_TID_TO_TARGET_MASK(cts->ccb_h.target_id); @@ -320,7 +312,6 @@ break; } - s = splcam(); scsi = &cts->proto_specific.scsi; spi = &cts->xport_specific.spi; if ((update_type & ADV_TRANS_GOAL) != 0) { @@ -387,7 +378,6 @@ spi->sync_offset, update_type); } - splx(s); ccb->ccb_h.status = CAM_REQ_CMP; xpt_done(ccb); break; @@ -400,7 +390,6 @@ struct ccb_trans_settings *cts; struct adv_transinfo *tconf; target_bit_vector target_mask; - int s; cts = &ccb->cts; target_mask = ADV_TID_TO_TARGET_MASK(cts->ccb_h.target_id); @@ -416,7 +405,6 @@ scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB; spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB; - s = splcam(); if (cts->type == CTS_TYPE_CURRENT_SETTINGS) { tconf = &adv->tinfo[cts->ccb_h.target_id].current; if ((adv->disc_enable & target_mask) != 0) @@ -432,7 +420,6 @@ } spi->sync_period = tconf->period; spi->sync_offset = tconf->offset; - splx(s); spi->bus_width = MSG_EXT_WDTR_BUS_8_BIT; spi->valid = CTS_SPI_VALID_SYNC_RATE | CTS_SPI_VALID_SYNC_OFFSET @@ -454,13 +441,10 @@ } case XPT_RESET_BUS: /* Reset the specified SCSI bus */ { - int s; - s = splcam(); adv_stop_execution(adv); adv_reset_bus(adv, /*initiate_reset*/TRUE); adv_start_execution(adv); - splx(s); ccb->ccb_h.status = CAM_REQ_CMP; xpt_done(ccb); @@ -521,13 +505,14 @@ struct adv_ccb_info *cinfo; struct adv_scsi_q scsiq; struct adv_sg_head sghead; - int s; csio = (struct ccb_scsiio *)arg; ccb_h = &csio->ccb_h; sim = xpt_path_sim(ccb_h->path); adv = (struct adv_softc *)cam_sim_softc(sim); cinfo = (struct adv_ccb_info *)csio->ccb_h.ccb_cinfo_ptr; + if (!dumping) + mtx_assert(&adv->lock, MA_OWNED); /* * Setup our done routine to release the simq on @@ -596,8 +581,6 @@ scsiq.sg_head = NULL; } - s = splcam(); - /* * Last time we need to check if this SCB needs to * be aborted. @@ -608,7 +591,6 @@ adv_clear_state(adv, (union ccb *)csio); adv_free_ccb_info(adv, cinfo); xpt_done((union ccb *)csio); - splx(s); return; } @@ -621,16 +603,14 @@ adv_clear_state(adv, (union ccb *)csio); adv_free_ccb_info(adv, cinfo); xpt_done((union ccb *)csio); - splx(s); return; } cinfo->state |= ACCB_ACTIVE; ccb_h->status |= CAM_SIM_QUEUED; LIST_INSERT_HEAD(&adv->pending_ccbs, ccb_h, sim_links.le); /* Schedule our timeout */ - ccb_h->timeout_ch = - timeout(adv_timeout, csio, (ccb_h->timeout * hz)/1000); - splx(s); + callout_reset(&cinfo->timer, ccb_h->timeout * hz /1000, adv_timeout, + csio); } static struct adv_ccb_info * @@ -641,11 +621,12 @@ cinfo = &adv->ccb_infos[adv->ccb_infos_allocated]; cinfo->state = ACCB_FREE; + callout_init_mtx(&cinfo->timer, &adv->lock, 0); error = bus_dmamap_create(adv->buffer_dmat, /*flags*/0, &cinfo->dmamap); if (error != 0) { - printf("%s: Unable to allocate CCB info " - "dmamap - error %d\n", adv_name(adv), error); + device_printf(adv->dev, "Unable to allocate CCB info " + "dmamap - error %d\n", error); return (NULL); } adv->ccb_infos_allocated++; @@ -655,28 +636,28 @@ static void adv_destroy_ccb_info(struct adv_softc *adv, struct adv_ccb_info *cinfo) { + + callout_drain(&cinfo->timer); bus_dmamap_destroy(adv->buffer_dmat, cinfo->dmamap); } void adv_timeout(void *arg) { - int s; union ccb *ccb; struct adv_softc *adv; - struct adv_ccb_info *cinfo; + struct adv_ccb_info *cinfo, *cinfo2; ccb = (union ccb *)arg; adv = (struct adv_softc *)xpt_path_sim(ccb->ccb_h.path)->softc; cinfo = (struct adv_ccb_info *)ccb->ccb_h.ccb_cinfo_ptr; + mtx_assert(&adv->lock, MA_OWNED); xpt_print_path(ccb->ccb_h.path); printf("Timed out\n"); - s = splcam(); /* Have we been taken care of already?? */ if (cinfo == NULL || cinfo->state == ACCB_FREE) { - splx(s); return; } @@ -702,7 +683,8 @@ ccb_h = LIST_FIRST(&adv->pending_ccbs); while (ccb_h != NULL) { - untimeout(adv_timeout, ccb_h, ccb_h->timeout_ch); + cinfo2 = ccb_h->ccb_cinfo_ptr; + callout_stop(&cinfo2->timer); ccb_h = LIST_NEXT(ccb_h, sim_links.le); } @@ -713,8 +695,7 @@ adv_abort_ccb(adv, ccb->ccb_h.target_id, ccb->ccb_h.target_lun, ccb, CAM_CMD_TIMEOUT, /*queued_only*/FALSE); - ccb->ccb_h.timeout_ch = - timeout(adv_timeout, ccb, 2 * hz); + callout_reset(&cinfo->timer, 2 * hz, adv_timeout, ccb); } else { /* Our attempt to perform an abort failed, go for a reset */ xpt_print_path(ccb->ccb_h.path); @@ -724,11 +705,10 @@ adv_reset_bus(adv, /*initiate_reset*/TRUE); } adv_start_execution(adv); - splx(s); } struct adv_softc * -adv_alloc(device_t dev, bus_space_tag_t tag, bus_space_handle_t bsh) +adv_alloc(device_t dev, struct resource *res, long offset) { struct adv_softc *adv = device_get_softc(dev); @@ -738,9 +718,9 @@ LIST_INIT(&adv->pending_ccbs); SLIST_INIT(&adv->free_ccb_infos); adv->dev = dev; - adv->unit = device_get_unit(dev); - adv->tag = tag; - adv->bsh = bsh; + adv->res = res; + adv->reg_off = offset; + mtx_init(&adv->lock, "adv", NULL, MTX_DEF); return(adv); } @@ -773,6 +753,7 @@ if (adv->ccb_infos != NULL) free(adv->ccb_infos, M_DEVBUF); case 0: + mtx_destroy(&adv->lock); break; } } @@ -786,6 +767,7 @@ u_int16_t config_lsw; u_int16_t config_msw; + mtx_lock(&adv->lock); adv_lib_init(adv); /* @@ -794,14 +776,16 @@ adv_write_lram_16(adv, ADV_HALTCODE_W, 0x00FE); adv_stop_execution(adv); if (adv_stop_chip(adv) == 0 || adv_is_chip_halted(adv) == 0) { - printf("adv%d: Unable to halt adapter. Initialization" - "failed\n", adv->unit); + mtx_unlock(&adv->lock); + device_printf(adv->dev, + "Unable to halt adapter. Initialization failed\n"); return (1); } ADV_OUTW(adv, ADV_REG_PROG_COUNTER, ADV_MCODE_START_ADDR); if (ADV_INW(adv, ADV_REG_PROG_COUNTER) != ADV_MCODE_START_ADDR) { - printf("adv%d: Unable to set program counter. Initialization" - "failed\n", adv->unit); + mtx_unlock(&adv->lock); + device_printf(adv->dev, + "Unable to set program counter. Initialization failed\n"); return (1); } @@ -876,8 +860,8 @@ } else { u_int8_t sync_data; - printf("adv%d: Warning EEPROM Checksum mismatch. " - "Using default device parameters\n", adv->unit); + device_printf(adv->dev, "Warning EEPROM Checksum mismatch. " + "Using default device parameters\n"); /* Set reasonable defaults since we can't read the EEPROM */ adv->isa_dma_speed = /*ADV_DEF_ISA_DMA_SPEED*/1; @@ -940,13 +924,15 @@ * to be 100% correct. */ if (adv_set_eeprom_config(adv, &eeprom_config) != 0) - printf("%s: WARNING! Failure writing to EEPROM.\n", - adv_name(adv)); + device_printf(adv->dev, + "WARNING! Failure writing to EEPROM.\n"); #endif adv_set_chip_scsiid(adv, adv->scsi_id); - if (adv_init_lram_and_mcode(adv)) + if (adv_init_lram_and_mcode(adv)) { + mtx_unlock(&adv->lock); return (1); + } adv->disc_enable = adv->user_disc_enable; @@ -969,10 +955,12 @@ } adv_write_lram_8(adv, ADVV_USE_TAGGED_QNG_B, TARGET_BIT_VECTOR_SET); adv_write_lram_8(adv, ADVV_CAN_TAGGED_QNG_B, TARGET_BIT_VECTOR_SET); - printf("adv%d: AdvanSys %s Host Adapter, SCSI ID %d, queue depth %d\n", - adv->unit, (adv->type & ADV_ULTRA) && (max_sync == 0) - ? "Ultra SCSI" : "SCSI", - adv->scsi_id, adv->max_openings); + device_printf(adv->dev, + "AdvanSys %s Host Adapter, SCSI ID %d, queue depth %d\n", + (adv->type & ADV_ULTRA) && (max_sync == 0) + ? "Ultra SCSI" : "SCSI", + adv->scsi_id, adv->max_openings); + mtx_unlock(&adv->lock); return (0); } @@ -980,14 +968,24 @@ adv_intr(void *arg) { struct adv_softc *adv; + + adv = arg; + mtx_lock(&adv->lock); + adv_intr_locked(adv); + mtx_unlock(&adv->lock); +} + +void +adv_intr_locked(struct adv_softc *adv) +{ u_int16_t chipstat; u_int16_t saved_ram_addr; u_int8_t ctrl_reg; u_int8_t saved_ctrl_reg; u_int8_t host_flag; - adv = (struct adv_softc *)arg; - + if (!dumping) + mtx_assert(&adv->lock, MA_OWNED); chipstat = ADV_INW(adv, ADV_CHIP_STATUS); /* Is it for us? */ @@ -1000,7 +998,7 @@ ADV_CC_TEST)); if ((chipstat & (ADV_CSW_SCSI_RESET_LATCH|ADV_CSW_SCSI_RESET_ACTIVE))) { - printf("Detected Bus Reset\n"); + device_printf(adv->dev, "Detected Bus Reset\n"); adv_reset_bus(adv, /*initiate_reset*/FALSE); return; } @@ -1128,9 +1126,11 @@ { struct adv_ccb_info *cinfo; + if (!dumping) + mtx_assert(&adv->lock, MA_OWNED); cinfo = (struct adv_ccb_info *)ccb->ccb_h.ccb_cinfo_ptr; LIST_REMOVE(&ccb->ccb_h, sim_links.le); - untimeout(adv_timeout, ccb, ccb->ccb_h.timeout_ch); + callout_stop(&cinfo->timer); if ((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) { bus_dmasync_op_t op; @@ -1239,7 +1239,7 @@ case QHSTA_M_MICRO_CODE_ERROR_HALT: default: panic("%s: Unhandled Host status error %x", - adv_name(adv), host_stat); + device_get_nameunit(adv->dev), host_stat); /* NOTREACHED */ } break; @@ -1280,7 +1280,8 @@ static void adv_poll(struct cam_sim *sim) { - adv_intr(cam_sim_softc(sim)); + + adv_intr_locked(cam_sim_softc(sim)); } /* @@ -1350,7 +1351,7 @@ /* maxsegsz */ BUS_SPACE_MAXSIZE_32BIT, /* flags */ BUS_DMA_ALLOCNOW, /* lockfunc */ busdma_lock_mutex, - /* lockarg */ &Giant, + /* lockarg */ &adv->lock, &adv->buffer_dmat) != 0) { return (ENXIO); } @@ -1371,7 +1372,7 @@ /* maxsegsz */ BUS_SPACE_MAXSIZE_32BIT, /* flags */ 0, /* lockfunc */ busdma_lock_mutex, - /* lockarg */ &Giant, + /* lockarg */ &adv->lock, &adv->sense_dmat) != 0) { return (ENXIO); } @@ -1398,8 +1399,8 @@ * Fire up the chip */ if (adv_start_chip(adv) != 1) { - printf("adv%d: Unable to start on board processor. Aborting.\n", - adv->unit); + device_printf(adv->dev, + "Unable to start on board processor. Aborting.\n"); return (ENXIO); } @@ -1413,8 +1414,8 @@ /* * Construct our SIM entry. */ - adv->sim = cam_sim_alloc(adv_action, adv_poll, "adv", adv, adv->unit, - &Giant, 1, adv->max_openings, devq); + adv->sim = cam_sim_alloc(adv_action, adv_poll, "adv", adv, + device_get_unit(adv->dev), &adv->lock, 1, adv->max_openings, devq); if (adv->sim == NULL) return (ENOMEM); @@ -1423,8 +1424,10 @@ * * XXX Twin Channel EISA Cards??? */ + mtx_lock(&adv->lock); if (xpt_bus_register(adv->sim, adv->dev, 0) != CAM_SUCCESS) { cam_sim_free(adv->sim, /*free devq*/TRUE); + mtx_unlock(&adv->lock); return (ENXIO); } @@ -1433,6 +1436,7 @@ != CAM_REQ_CMP) { xpt_bus_deregister(cam_sim_path(adv->sim)); cam_sim_free(adv->sim, /*free devq*/TRUE); + mtx_unlock(&adv->lock); return (ENXIO); } @@ -1442,6 +1446,7 @@ csa.callback = advasync; csa.callback_arg = adv; xpt_action((union ccb *)&csa); + mtx_unlock(&adv->lock); return (0); } MODULE_DEPEND(adv, cam, 1, 1, 1); --- //depot/vendor/freebsd/src/sys/dev/advansys/advansys.h 2005-01-06 01:48:14.000000000 0000 +++ //depot/user/jhb/cleanup/sys/dev/advansys/advansys.h 2012-08-29 15:00:11.000000000 0000 @@ -38,9 +38,7 @@ #include -struct adv_softc * adv_alloc(device_t dev, bus_space_tag_t tag, - bus_space_handle_t bsh); -char * adv_name(struct adv_softc *adv); +struct adv_softc * adv_alloc(device_t dev, struct resource *res, long offset); void adv_map(void *arg, bus_dma_segment_t *segs, int nseg, int error); void adv_free(struct adv_softc *adv); @@ -50,6 +48,6 @@ void adv_done(struct adv_softc *adv, union ccb* ccb, u_int done_stat, u_int host_stat, u_int scsi_stat, u_int q_no); -timeout_t adv_timeout; +void adv_timeout(void *arg); #endif /* _ADVANSYS_H_ */ --- //depot/vendor/freebsd/src/sys/dev/advansys/advlib.c 2006-11-02 00:56:24.000000000 0000 +++ //depot/user/jhb/cleanup/sys/dev/advansys/advlib.c 2012-08-30 02:05:23.000000000 0000 @@ -45,7 +45,10 @@ __FBSDID("$FreeBSD: src/sys/dev/advansys/advlib.c,v 1.26 2006/11/02 00:54:33 mjacob Exp $"); #include +#include +#include #include +#include #include #include @@ -298,6 +301,7 @@ struct adv_softc *adv; adv = (struct adv_softc *)callback_arg; + mtx_assert(&adv->lock, MA_OWNED); switch (code) { case AC_FOUND_DEVICE: { @@ -460,12 +464,12 @@ * found, 0 otherwise. */ int -adv_find_signature(bus_space_tag_t tag, bus_space_handle_t bsh) +adv_find_signature(struct resource *res) { u_int16_t signature; - if (bus_space_read_1(tag, bsh, ADV_SIGNATURE_BYTE) == ADV_1000_ID1B) { - signature = bus_space_read_2(tag, bsh, ADV_SIGNATURE_WORD); + if (bus_read_1(res, ADV_SIGNATURE_BYTE) == ADV_1000_ID1B) { + signature = bus_read_2(res, ADV_SIGNATURE_WORD); if ((signature == ADV_1000_ID0W) || (signature == ADV_1000_ID0W_FIX)) return (1); @@ -594,8 +598,8 @@ retval = adv_load_microcode(adv, 0, (u_int16_t *)adv_mcode, adv_mcode_size); if (retval != adv_mcode_chksum) { - printf("adv%d: Microcode download failed checksum!\n", - adv->unit); + device_printf(adv->dev, + "Microcode download failed checksum!\n"); return (1); } @@ -692,6 +696,8 @@ u_int8_t sg_entry_cnt_minus_one; u_int8_t tid_no; + if (!dumping) + mtx_assert(&adv->lock, MA_OWNED); scsiq->q1.q_no = 0; retval = 1; /* Default to error case */ target_ix = scsiq->q2.target_ix; @@ -938,6 +944,8 @@ u_int8_t q_cntl; u_int8_t tid_no; + if (!dumping) + mtx_assert(&adv->lock, MA_OWNED); int_halt_code = adv_read_lram_16(adv, ADVV_HALTCODE_W); halt_qp = adv_read_lram_8(adv, ADVV_CURCDB_B); halt_q_addr = ADV_QNO_TO_QADDR(halt_qp); @@ -966,6 +974,7 @@ target_mask, tid_no); } else if (int_halt_code == ADV_HALT_CHK_CONDITION) { struct adv_target_transinfo* tinfo; + struct adv_ccb_info *cinfo; union ccb *ccb; u_int32_t cinfo_index; u_int8_t tag_code; @@ -1008,6 +1017,7 @@ */ cinfo_index = adv_read_lram_32(adv, halt_q_addr + ADV_SCSIQ_D_CINFO_IDX); + cinfo = &adv->ccb_infos[cinfo_index]; ccb = adv->ccb_infos[cinfo_index].ccb; xpt_freeze_devq(ccb->ccb_h.path, /*count*/1); ccb->ccb_h.status |= CAM_DEV_QFRZN; @@ -1021,9 +1031,7 @@ * Ensure we have enough time to actually * retrieve the sense. */ - untimeout(adv_timeout, (caddr_t)ccb, ccb->ccb_h.timeout_ch); - ccb->ccb_h.timeout_ch = - timeout(adv_timeout, (caddr_t)ccb, 5 * hz); + callout_reset(&cinfo->timer, 5 * hz, adv_timeout, ccb); } else if (int_halt_code == ADV_HALT_SDTR_REJECTED) { struct ext_msg out_msg; @@ -1090,6 +1098,7 @@ u_int old_offset; u_int8_t sdtr_data; + mtx_assert(&adv->lock, MA_OWNED); tinfo = &adv->tinfo[tid]; /* Filter our input */ @@ -1102,10 +1111,8 @@ if ((type & ADV_TRANS_CUR) != 0 && ((old_period != period || old_offset != offset) || period == 0 || offset == 0) /*Changes in asyn fix settings*/) { - int s; int halted; - s = splcam(); halted = adv_is_chip_halted(adv); if (halted == 0) /* Must halt the chip first */ @@ -1125,7 +1132,6 @@ /* Start the chip again */ adv_start_chip(adv); - splx(s); tinfo->current.period = period; tinfo->current.offset = offset; @@ -1235,8 +1241,8 @@ u_int16_t set_value, int count) { ADV_OUTW(adv, ADV_LRAM_ADDR, s_addr); - bus_space_set_multi_2(adv->tag, adv->bsh, ADV_LRAM_DATA, - set_value, count); + bus_set_multi_2(adv->res, adv->reg_off + ADV_LRAM_DATA, + set_value, count); } static u_int32_t @@ -1507,8 +1513,8 @@ ADV_OUTW(adv, ADV_REG_PROG_COUNTER, ADV_MCODE_START_ADDR); if (ADV_INW(adv, ADV_REG_PROG_COUNTER) != ADV_MCODE_START_ADDR) { - printf("adv%d: Unable to set program counter. Aborting.\n", - adv->unit); + device_printf(adv->dev, + "Unable to set program counter. Aborting.\n"); return (1); } return (0); @@ -2002,6 +2008,8 @@ u_int8_t target_ix; int count; + if (!dumping) + mtx_assert(&adv->lock, MA_OWNED); scsiq = &scsiq_buf; target_ix = ADV_TIDLUN_TO_IX(target, lun); count = 0; @@ -2045,6 +2053,8 @@ int i; union ccb *ccb; + if (!dumping) + mtx_assert(&adv->lock, MA_OWNED); i = 200; while ((ADV_INW(adv, ADV_CHIP_STATUS) & ADV_CSW_SCSI_RESET_ACTIVE) != 0 && i--) --- //depot/vendor/freebsd/src/sys/dev/advansys/advlib.h 2009-07-10 08:25:14.000000000 0000 +++ //depot/user/jhb/cleanup/sys/dev/advansys/advlib.h 2012-08-29 15:00:11.000000000 0000 @@ -94,6 +94,7 @@ struct adv_ccb_info { adv_ccb_state state; bus_dmamap_t dmamap; + struct callout timer; union ccb* ccb; SLIST_ENTRY(adv_ccb_info) links; }; @@ -496,8 +497,8 @@ struct adv_softc { device_t dev; - bus_space_tag_t tag; - bus_space_handle_t bsh; + struct resource *res; + long reg_off; struct cam_sim *sim; LIST_HEAD(, ccb_hdr) pending_ccbs; struct adv_ccb_info *ccb_infos; @@ -539,8 +540,7 @@ adv_state state; struct cam_path *path; - int unit; - int init_level; + int init_level; u_int32_t max_dma_addr; u_int32_t max_dma_count; u_int8_t isa_dma_speed; @@ -554,6 +554,7 @@ u_int8_t ccb_infos_allocated; u_int8_t *sdtr_period_tbl; u_int8_t sdtr_period_tbl_size; + struct mtx lock; }; /* @@ -793,7 +794,7 @@ u_int16_t value); /* Intialization */ -int adv_find_signature(bus_space_tag_t tag, bus_space_handle_t bsh); +int adv_find_signature(struct resource *res); void adv_lib_init(struct adv_softc *adv); u_int16_t adv_get_eeprom_config(struct adv_softc *adv, @@ -846,11 +847,11 @@ struct cam_path *path, void *arg); #define ADV_INB(adv, offset) \ - bus_space_read_1((adv)->tag, (adv)->bsh, offset) + bus_read_1((adv)->res, (adv)->reg_off + offset) #define ADV_INW(adv, offset) \ - bus_space_read_2((adv)->tag, (adv)->bsh, offset) + bus_read_2((adv)->res, (adv)->reg_off + offset) #define ADV_INSB(adv, offset, valp, count) \ - bus_space_read_multi_1((adv)->tag, (adv)->bsh, offset, valp, count) + bus_read_multi_1((adv)->res, (adv)->reg_off + offset, valp, count) /* These controllers seem to have problems with PIO on some fast processors */ static __inline void ADV_INSW(struct adv_softc *, u_int, u_int16_t *, u_int); @@ -858,13 +859,13 @@ ADV_INSW(struct adv_softc *adv, u_int offset, u_int16_t *valp, u_int count) { while (count--) - *valp++ = bus_space_read_2(adv->tag, adv->bsh, offset); + *valp++ = bus_read_2(adv->res, adv->reg_off + offset); } #define ADV_OUTB(adv, offset, val) \ - bus_space_write_1((adv)->tag, (adv)->bsh, offset, val) + bus_write_1((adv)->res, (adv)->reg_off + offset, val) #define ADV_OUTW(adv, offset, val) \ - bus_space_write_2((adv)->tag, (adv)->bsh, offset, val) + bus_write_2((adv)->res, (adv)->reg_off + offset, val) /* These controllers seem to have problems with PIO on some fast processors */ static __inline void ADV_OUTSW(struct adv_softc *, u_int, u_int16_t *, u_int); @@ -872,7 +873,7 @@ ADV_OUTSW(struct adv_softc *adv, u_int offset, u_int16_t *valp, u_int count) { while (count--) - bus_space_write_2(adv->tag, adv->bsh, offset, *valp++); + bus_write_2(adv->res, adv->reg_off + offset, *valp++); } #endif /* _ADVLIB_H_ */