📄 aic79xx_osm.c
字号:
static intahd_linux_target_alloc(struct scsi_target *starget){ struct ahd_softc *ahd = *((struct ahd_softc **)dev_to_shost(&starget->dev)->hostdata); unsigned long flags; struct scsi_target **ahd_targp = ahd_linux_target_in_softc(starget); struct ahd_linux_target *targ = scsi_transport_target_data(starget); struct ahd_devinfo devinfo; struct ahd_initiator_tinfo *tinfo; struct ahd_tmode_tstate *tstate; char channel = starget->channel + 'A'; ahd_lock(ahd, &flags); BUG_ON(*ahd_targp != NULL); *ahd_targp = starget; memset(targ, 0, sizeof(*targ)); tinfo = ahd_fetch_transinfo(ahd, channel, ahd->our_id, starget->id, &tstate); ahd_compile_devinfo(&devinfo, ahd->our_id, starget->id, CAM_LUN_WILDCARD, channel, ROLE_INITIATOR); spi_min_period(starget) = AHD_SYNCRATE_MAX; /* We can do U320 */ if ((ahd->bugs & AHD_PACED_NEGTABLE_BUG) != 0) spi_max_offset(starget) = MAX_OFFSET_PACED_BUG; else spi_max_offset(starget) = MAX_OFFSET_PACED; spi_max_width(starget) = ahd->features & AHD_WIDE; ahd_set_syncrate(ahd, &devinfo, 0, 0, 0, AHD_TRANS_GOAL, /*paused*/FALSE); ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT, AHD_TRANS_GOAL, /*paused*/FALSE); ahd_unlock(ahd, &flags); return 0;}static voidahd_linux_target_destroy(struct scsi_target *starget){ struct scsi_target **ahd_targp = ahd_linux_target_in_softc(starget); *ahd_targp = NULL;}static intahd_linux_slave_alloc(struct scsi_device *sdev){ struct ahd_softc *ahd = *((struct ahd_softc **)sdev->host->hostdata); struct scsi_target *starget = sdev->sdev_target; struct ahd_linux_target *targ = scsi_transport_target_data(starget); struct ahd_linux_device *dev; if (bootverbose) printf("%s: Slave Alloc %d\n", ahd_name(ahd), sdev->id); BUG_ON(targ->sdev[sdev->lun] != NULL); dev = scsi_transport_device_data(sdev); memset(dev, 0, sizeof(*dev)); /* * We start out life using untagged * transactions of which we allow one. */ dev->openings = 1; /* * Set maxtags to 0. This will be changed if we * later determine that we are dealing with * a tagged queuing capable device. */ dev->maxtags = 0; targ->sdev[sdev->lun] = sdev; return (0);}static intahd_linux_slave_configure(struct scsi_device *sdev){ struct ahd_softc *ahd; ahd = *((struct ahd_softc **)sdev->host->hostdata); if (bootverbose) sdev_printk(KERN_INFO, sdev, "Slave Configure\n"); ahd_linux_device_queue_depth(sdev); /* Initial Domain Validation */ if (!spi_initial_dv(sdev->sdev_target)) spi_dv_device(sdev); return 0;}static voidahd_linux_slave_destroy(struct scsi_device *sdev){ struct ahd_softc *ahd; struct ahd_linux_device *dev = scsi_transport_device_data(sdev); struct ahd_linux_target *targ = scsi_transport_target_data(sdev->sdev_target); ahd = *((struct ahd_softc **)sdev->host->hostdata); if (bootverbose) printf("%s: Slave Destroy %d\n", ahd_name(ahd), sdev->id); BUG_ON(dev->active); targ->sdev[sdev->lun] = NULL;}#if defined(__i386__)/* * Return the disk geometry for the given SCSI device. */static intahd_linux_biosparam(struct scsi_device *sdev, struct block_device *bdev, sector_t capacity, int geom[]){ uint8_t *bh; int heads; int sectors; int cylinders; int ret; int extended; struct ahd_softc *ahd; ahd = *((struct ahd_softc **)sdev->host->hostdata); bh = scsi_bios_ptable(bdev); if (bh) { ret = scsi_partsize(bh, capacity, &geom[2], &geom[0], &geom[1]); kfree(bh); if (ret != -1) return (ret); } heads = 64; sectors = 32; cylinders = aic_sector_div(capacity, heads, sectors); if (aic79xx_extended != 0) extended = 1; else extended = (ahd->flags & AHD_EXTENDED_TRANS_A) != 0; if (extended && cylinders >= 1024) { heads = 255; sectors = 63; cylinders = aic_sector_div(capacity, heads, sectors); } geom[0] = heads; geom[1] = sectors; geom[2] = cylinders; return (0);}#endif/* * Abort the current SCSI command(s). */static intahd_linux_abort(struct scsi_cmnd *cmd){ int error; error = ahd_linux_queue_recovery_cmd(cmd, SCB_ABORT); if (error != 0) printf("aic79xx_abort returns 0x%x\n", error); return error;}/* * Attempt to send a target reset message to the device that timed out. */static intahd_linux_dev_reset(struct scsi_cmnd *cmd){ int error; error = ahd_linux_queue_recovery_cmd(cmd, SCB_DEVICE_RESET); if (error != 0) printf("aic79xx_dev_reset returns 0x%x\n", error); return error;}/* * Reset the SCSI bus. */static intahd_linux_bus_reset(struct scsi_cmnd *cmd){ struct ahd_softc *ahd; u_long s; int found; ahd = *(struct ahd_softc **)cmd->device->host->hostdata;#ifdef AHD_DEBUG if ((ahd_debug & AHD_SHOW_RECOVERY) != 0) printf("%s: Bus reset called for cmd %p\n", ahd_name(ahd), cmd);#endif ahd_lock(ahd, &s); found = ahd_reset_channel(ahd, scmd_channel(cmd) + 'A', /*initiate reset*/TRUE); ahd_unlock(ahd, &s); if (bootverbose) printf("%s: SCSI bus reset delivered. " "%d SCBs aborted.\n", ahd_name(ahd), found); return (SUCCESS);}struct scsi_host_template aic79xx_driver_template = { .module = THIS_MODULE, .name = "aic79xx", .proc_name = "aic79xx", .proc_info = ahd_linux_proc_info, .info = ahd_linux_info, .queuecommand = ahd_linux_queue, .eh_abort_handler = ahd_linux_abort, .eh_device_reset_handler = ahd_linux_dev_reset, .eh_bus_reset_handler = ahd_linux_bus_reset,#if defined(__i386__) .bios_param = ahd_linux_biosparam,#endif .can_queue = AHD_MAX_QUEUE, .this_id = -1, .cmd_per_lun = 2, .use_clustering = ENABLE_CLUSTERING, .slave_alloc = ahd_linux_slave_alloc, .slave_configure = ahd_linux_slave_configure, .slave_destroy = ahd_linux_slave_destroy, .target_alloc = ahd_linux_target_alloc, .target_destroy = ahd_linux_target_destroy,};/******************************** Bus DMA *************************************/intahd_dma_tag_create(struct ahd_softc *ahd, bus_dma_tag_t parent, bus_size_t alignment, bus_size_t boundary, dma_addr_t lowaddr, dma_addr_t highaddr, bus_dma_filter_t *filter, void *filterarg, bus_size_t maxsize, int nsegments, bus_size_t maxsegsz, int flags, bus_dma_tag_t *ret_tag){ bus_dma_tag_t dmat; dmat = malloc(sizeof(*dmat), M_DEVBUF, M_NOWAIT); if (dmat == NULL) return (ENOMEM); /* * Linux is very simplistic about DMA memory. For now don't * maintain all specification information. Once Linux supplies * better facilities for doing these operations, or the * needs of this particular driver change, we might need to do * more here. */ dmat->alignment = alignment; dmat->boundary = boundary; dmat->maxsize = maxsize; *ret_tag = dmat; return (0);}voidahd_dma_tag_destroy(struct ahd_softc *ahd, bus_dma_tag_t dmat){ free(dmat, M_DEVBUF);}intahd_dmamem_alloc(struct ahd_softc *ahd, bus_dma_tag_t dmat, void** vaddr, int flags, bus_dmamap_t *mapp){ *vaddr = pci_alloc_consistent(ahd->dev_softc, dmat->maxsize, mapp); if (*vaddr == NULL) return (ENOMEM); return(0);}voidahd_dmamem_free(struct ahd_softc *ahd, bus_dma_tag_t dmat, void* vaddr, bus_dmamap_t map){ pci_free_consistent(ahd->dev_softc, dmat->maxsize, vaddr, map);}intahd_dmamap_load(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map, void *buf, bus_size_t buflen, bus_dmamap_callback_t *cb, void *cb_arg, int flags){ /* * Assume for now that this will only be used during * initialization and not for per-transaction buffer mapping. */ bus_dma_segment_t stack_sg; stack_sg.ds_addr = map; stack_sg.ds_len = dmat->maxsize; cb(cb_arg, &stack_sg, /*nseg*/1, /*error*/0); return (0);}voidahd_dmamap_destroy(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map){}intahd_dmamap_unload(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map){ /* Nothing to do */ return (0);}/********************* Platform Dependent Functions ***************************//* * Compare "left hand" softc with "right hand" softc, returning: * < 0 - lahd has a lower priority than rahd * 0 - Softcs are equal * > 0 - lahd has a higher priority than rahd */intahd_softc_comp(struct ahd_softc *lahd, struct ahd_softc *rahd){ int value; /* * Under Linux, cards are ordered as follows: * 1) PCI devices that are marked as the boot controller. * 2) PCI devices with BIOS enabled sorted by bus/slot/func. * 3) All remaining PCI devices sorted by bus/slot/func. */#if 0 value = (lahd->flags & AHD_BOOT_CHANNEL) - (rahd->flags & AHD_BOOT_CHANNEL); if (value != 0) /* Controllers set for boot have a *higher* priority */ return (value);#endif value = (lahd->flags & AHD_BIOS_ENABLED) - (rahd->flags & AHD_BIOS_ENABLED); if (value != 0) /* Controllers with BIOS enabled have a *higher* priority */ return (value); /* Still equal. Sort by bus/slot/func. */ if (aic79xx_reverse_scan != 0) value = ahd_get_pci_bus(lahd->dev_softc) - ahd_get_pci_bus(rahd->dev_softc); else value = ahd_get_pci_bus(rahd->dev_softc) - ahd_get_pci_bus(lahd->dev_softc); if (value != 0) return (value); if (aic79xx_reverse_scan != 0) value = ahd_get_pci_slot(lahd->dev_softc) - ahd_get_pci_slot(rahd->dev_softc); else value = ahd_get_pci_slot(rahd->dev_softc) - ahd_get_pci_slot(lahd->dev_softc); if (value != 0) return (value); value = rahd->channel - lahd->channel; return (value);}static voidahd_linux_setup_iocell_info(u_long index, int instance, int targ, int32_t value){ if ((instance >= 0) && (instance < NUM_ELEMENTS(aic79xx_iocell_info))) { uint8_t *iocell_info; iocell_info = (uint8_t*)&aic79xx_iocell_info[instance]; iocell_info[index] = value & 0xFFFF; if (bootverbose) printf("iocell[%d:%ld] = %d\n", instance, index, value); }}static voidahd_linux_setup_tag_info_global(char *p){ int tags, i, j; tags = simple_strtoul(p + 1, NULL, 0) & 0xff; printf("Setting Global Tags= %d\n", tags); for (i = 0; i < NUM_ELEMENTS(aic79xx_tag_info); i++) { for (j = 0; j < AHD_NUM_TARGETS; j++) { aic79xx_tag_info[i].tag_commands[j] = tags; } }}static voidahd_linux_setup_tag_info(u_long arg, int instance, int targ, int32_t value){ if ((instance >= 0) && (targ >= 0) && (instance < NUM_ELEMENTS(aic79xx_tag_info)) && (targ < AHD_NUM_TARGETS)) { aic79xx_tag_info[instance].tag_commands[targ] = value & 0x1FF; if (bootverbose) printf("tag_info[%d:%d] = %d\n", instance, targ, value); }}static char *ahd_parse_brace_option(char *opt_name, char *opt_arg, char *end, int depth, void (*callback)(u_long, int, int, int32_t), u_long callback_arg){ char *tok_end; char *tok_end2; int i; int instance; int targ; int done; char tok_list[] = {'.', ',', '{', '}', '\0'}; /* All options use a ':' name/arg separator */ if (*opt_arg != ':') return (opt_arg); opt_arg++; instance = -1; targ = -1; done = FALSE; /* * Restore separator that may be in * the middle of our option argument. */ tok_end = strchr(opt_arg, '\0'); if (tok_end < end) *tok_end = ','; while (!done) { switch (*opt_arg) { case '{': if (instance == -1) { instance = 0; } else { if (depth > 1) { if (targ == -1) targ = 0; } else { printf("Malformed Option %s\n", opt_name); done = TRUE; } } opt_arg++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -