diff options
Diffstat (limited to 'sys/dev/ata/ata-all.c')
-rw-r--r-- | sys/dev/ata/ata-all.c | 998 |
1 files changed, 1 insertions, 997 deletions
diff --git a/sys/dev/ata/ata-all.c b/sys/dev/ata/ata-all.c index 2003ff5..3327a9d 100644 --- a/sys/dev/ata/ata-all.c +++ b/sys/dev/ata/ata-all.c @@ -51,90 +51,33 @@ __FBSDID("$FreeBSD$"); #include <dev/pci/pcivar.h> #include <ata_if.h> -#ifdef ATA_CAM #include <cam/cam.h> #include <cam/cam_ccb.h> #include <cam/cam_sim.h> #include <cam/cam_xpt_sim.h> #include <cam/cam_debug.h> -#endif - -#ifndef ATA_CAM -/* device structure */ -static d_ioctl_t ata_ioctl; -static struct cdevsw ata_cdevsw = { - .d_version = D_VERSION, - .d_flags = D_NEEDGIANT, /* we need this as newbus isn't mpsafe */ - .d_ioctl = ata_ioctl, - .d_name = "ata", -}; -#endif /* prototypes */ -#ifndef ATA_CAM -static void ata_boot_attach(void); -static device_t ata_add_child(device_t, struct ata_device *, int); -#else static void ataaction(struct cam_sim *sim, union ccb *ccb); static void atapoll(struct cam_sim *sim); -#endif static void ata_conn_event(void *, int); -#ifndef ATA_CAM -static void bswap(int8_t *, int); -static void btrim(int8_t *, int); -static void bpack(int8_t *, int8_t *, int); -#endif static void ata_interrupt_locked(void *data); -#ifdef ATA_CAM static void ata_periodic_poll(void *data); -#endif /* global vars */ MALLOC_DEFINE(M_ATA, "ata_generic", "ATA driver generic layer"); int (*ata_raid_ioctl_func)(u_long cmd, caddr_t data) = NULL; -#ifndef ATA_CAM -struct intr_config_hook *ata_delayed_attach = NULL; -#endif devclass_t ata_devclass; uma_zone_t ata_request_zone; -uma_zone_t ata_composite_zone; -#ifndef ATA_CAM -int ata_wc = 1; -int ata_setmax = 0; -#endif int ata_dma_check_80pin = 1; -/* local vars */ -#ifndef ATA_CAM -static int ata_dma = 1; -static int atapi_dma = 1; -#endif - /* sysctl vars */ static SYSCTL_NODE(_hw, OID_AUTO, ata, CTLFLAG_RD, 0, "ATA driver parameters"); -#ifndef ATA_CAM -TUNABLE_INT("hw.ata.ata_dma", &ata_dma); -SYSCTL_INT(_hw_ata, OID_AUTO, ata_dma, CTLFLAG_RDTUN, &ata_dma, 0, - "ATA disk DMA mode control"); -#endif TUNABLE_INT("hw.ata.ata_dma_check_80pin", &ata_dma_check_80pin); SYSCTL_INT(_hw_ata, OID_AUTO, ata_dma_check_80pin, CTLFLAG_RW, &ata_dma_check_80pin, 1, "Check for 80pin cable before setting ATA DMA mode"); -#ifndef ATA_CAM -TUNABLE_INT("hw.ata.atapi_dma", &atapi_dma); -SYSCTL_INT(_hw_ata, OID_AUTO, atapi_dma, CTLFLAG_RDTUN, &atapi_dma, 0, - "ATAPI device DMA mode control"); -TUNABLE_INT("hw.ata.wc", &ata_wc); -SYSCTL_INT(_hw_ata, OID_AUTO, wc, CTLFLAG_RDTUN, &ata_wc, 0, - "ATA disk write caching"); -TUNABLE_INT("hw.ata.setmax", &ata_setmax); -SYSCTL_INT(_hw_ata, OID_AUTO, setmax, CTLFLAG_RDTUN, &ata_setmax, 0, - "ATA disk set max native address"); -#endif -#ifdef ATA_CAM FEATURE(ata_cam, "ATA devices are accessed through the cam(4) driver"); -#endif /* * newbus device interface related functions @@ -150,12 +93,10 @@ ata_attach(device_t dev) { struct ata_channel *ch = device_get_softc(dev); int error, rid; -#ifdef ATA_CAM struct cam_devq *devq; const char *res; char buf[64]; int i, mode; -#endif /* check that we have a virgin channel to attach */ if (ch->r_irq) @@ -166,13 +107,7 @@ ata_attach(device_t dev) ch->state = ATA_IDLE; bzero(&ch->state_mtx, sizeof(struct mtx)); mtx_init(&ch->state_mtx, "ATA state lock", NULL, MTX_DEF); -#ifndef ATA_CAM - bzero(&ch->queue_mtx, sizeof(struct mtx)); - mtx_init(&ch->queue_mtx, "ATA queue lock", NULL, MTX_DEF); - TAILQ_INIT(&ch->ata_queue); -#endif TASK_INIT(&ch->conntask, 0, ata_conn_event, dev); -#ifdef ATA_CAM for (i = 0; i < 16; i++) { ch->user[i].revision = 0; snprintf(buf, sizeof(buf), "dev%d.sata_rev", i); @@ -207,15 +142,6 @@ ata_attach(device_t dev) ch->user[i].caps |= CTS_SATA_CAPS_D_PMREQ; } callout_init(&ch->poll_callout, 1); -#endif - -#ifndef ATA_CAM - /* reset the controller HW, the channel and device(s) */ - while (ATA_LOCKING(dev, ATA_LF_LOCK) != ch->unit) - pause("ataatch", 1); - ATA_RESET(dev); - ATA_LOCKING(dev, ATA_LF_UNLOCK); -#endif /* allocate DMA resources if DMA HW present*/ if (ch->dma.alloc) @@ -236,12 +162,6 @@ ata_attach(device_t dev) return error; } -#ifndef ATA_CAM - /* probe and attach devices on this channel unless we are in early boot */ - if (!ata_delayed_attach) - ata_identify(dev); - return (0); -#else if (ch->flags & ATA_PERIODIC_POLL) callout_reset(&ch->poll_callout, hz, ata_periodic_poll, ch); mtx_lock(&ch->state_mtx); @@ -286,17 +206,12 @@ err1: if (ch->flags & ATA_PERIODIC_POLL) callout_drain(&ch->poll_callout); return (error); -#endif } int ata_detach(device_t dev) { struct ata_channel *ch = device_get_softc(dev); -#ifndef ATA_CAM - device_t *children; - int nchildren, i; -#endif /* check that we have a valid channel to detach */ if (!ch->r_irq) @@ -306,23 +221,11 @@ ata_detach(device_t dev) mtx_lock(&ch->state_mtx); ch->state |= ATA_STALL_QUEUE; mtx_unlock(&ch->state_mtx); -#ifdef ATA_CAM if (ch->flags & ATA_PERIODIC_POLL) callout_drain(&ch->poll_callout); -#endif - -#ifndef ATA_CAM - /* detach & delete all children */ - if (!device_get_children(dev, &children, &nchildren)) { - for (i = 0; i < nchildren; i++) - if (children[i]) - device_delete_child(dev, children[i]); - free(children, M_TEMP); - } -#endif + taskqueue_drain(taskqueue_thread, &ch->conntask); -#ifdef ATA_CAM mtx_lock(&ch->state_mtx); xpt_async(AC_LOST_DEVICE, ch->path, NULL); xpt_free_path(ch->path); @@ -330,7 +233,6 @@ ata_detach(device_t dev) cam_sim_free(ch->sim, /*free_devq*/TRUE); ch->sim = NULL; mtx_unlock(&ch->state_mtx); -#endif /* release resources */ bus_teardown_intr(dev, ch->r_irq, ch->ih); @@ -342,9 +244,6 @@ ata_detach(device_t dev) ch->dma.free(dev); mtx_destroy(&ch->state_mtx); -#ifndef ATA_CAM - mtx_destroy(&ch->queue_mtx); -#endif return 0; } @@ -352,7 +251,6 @@ static void ata_conn_event(void *context, int dummy) { device_t dev = (device_t)context; -#ifdef ATA_CAM struct ata_channel *ch = device_get_softc(dev); union ccb *ccb; @@ -372,9 +270,6 @@ ata_conn_event(void *context, int dummy) } xpt_rescan(ccb); mtx_unlock(&ch->state_mtx); -#else - ata_reinit(dev); -#endif } int @@ -382,94 +277,7 @@ ata_reinit(device_t dev) { struct ata_channel *ch = device_get_softc(dev); struct ata_request *request; -#ifndef ATA_CAM - device_t *children; - int nchildren, i; - - /* check that we have a valid channel to reinit */ - if (!ch || !ch->r_irq) - return ENXIO; - - if (bootverbose) - device_printf(dev, "reiniting channel ..\n"); - - /* poll for locking the channel */ - while (ATA_LOCKING(dev, ATA_LF_LOCK) != ch->unit) - pause("atarini", 1); - - /* catch eventual request in ch->running */ - mtx_lock(&ch->state_mtx); - if (ch->state & ATA_STALL_QUEUE) { - /* Recursive reinits and reinits during detach prohobited. */ - mtx_unlock(&ch->state_mtx); - return (ENXIO); - } - if ((request = ch->running)) - callout_stop(&request->callout); - ch->running = NULL; - - /* unconditionally grap the channel lock */ - ch->state |= ATA_STALL_QUEUE; - mtx_unlock(&ch->state_mtx); - /* reset the controller HW, the channel and device(s) */ - ATA_RESET(dev); - - /* reinit the children and delete any that fails */ - if (!device_get_children(dev, &children, &nchildren)) { - mtx_lock(&Giant); /* newbus suckage it needs Giant */ - for (i = 0; i < nchildren; i++) { - /* did any children go missing ? */ - if (children[i] && device_is_attached(children[i]) && - ATA_REINIT(children[i])) { - /* - * if we had a running request and its device matches - * this child we need to inform the request that the - * device is gone. - */ - if (request && request->dev == children[i]) { - request->result = ENXIO; - device_printf(request->dev, "FAILURE - device detached\n"); - - /* if not timeout finish request here */ - if (!(request->flags & ATA_R_TIMEOUT)) - ata_finish(request); - request = NULL; - } - device_delete_child(dev, children[i]); - } - } - free(children, M_TEMP); - mtx_unlock(&Giant); /* newbus suckage dealt with, release Giant */ - } - - /* if we still have a good request put it on the queue again */ - if (request && !(request->flags & ATA_R_TIMEOUT)) { - device_printf(request->dev, - "WARNING - %s requeued due to channel reset", - ata_cmd2str(request)); - if (!(request->flags & (ATA_R_ATAPI | ATA_R_CONTROL))) - printf(" LBA=%ju", request->u.ata.lba); - printf("\n"); - request->flags |= ATA_R_REQUEUE; - ata_queue_request(request); - } - - /* we're done release the channel for new work */ - mtx_lock(&ch->state_mtx); - ch->state = ATA_IDLE; - mtx_unlock(&ch->state_mtx); - ATA_LOCKING(dev, ATA_LF_UNLOCK); - - /* Add new children. */ -/* ata_identify(dev); */ - - if (bootverbose) - device_printf(dev, "reinit done ..\n"); - - /* kick off requests on the queue */ - ata_start(dev); -#else xpt_freeze_simq(ch->sim, 1); if ((request = ch->running)) { ch->running = NULL; @@ -486,7 +294,6 @@ ata_reinit(device_t dev) /* Tell the XPT about the event */ xpt_async(AC_BUS_RESET, ch->path, NULL); xpt_release_simq(ch->sim, TRUE); -#endif return(0); } @@ -499,7 +306,6 @@ ata_suspend(device_t dev) if (!dev || !(ch = device_get_softc(dev))) return ENXIO; -#ifdef ATA_CAM if (ch->flags & ATA_PERIODIC_POLL) callout_drain(&ch->poll_callout); mtx_lock(&ch->state_mtx); @@ -507,20 +313,6 @@ ata_suspend(device_t dev) while (ch->state != ATA_IDLE) msleep(ch, &ch->state_mtx, PRIBIO, "atasusp", hz/100); mtx_unlock(&ch->state_mtx); -#else - /* wait for the channel to be IDLE or detached before suspending */ - while (ch->r_irq) { - mtx_lock(&ch->state_mtx); - if (ch->state == ATA_IDLE) { - ch->state = ATA_ACTIVE; - mtx_unlock(&ch->state_mtx); - break; - } - mtx_unlock(&ch->state_mtx); - tsleep(ch, PRIBIO, "atasusp", hz/10); - } - ATA_LOCKING(dev, ATA_LF_UNLOCK); -#endif return(0); } @@ -534,36 +326,25 @@ ata_resume(device_t dev) if (!dev || !(ch = device_get_softc(dev))) return ENXIO; -#ifdef ATA_CAM mtx_lock(&ch->state_mtx); error = ata_reinit(dev); xpt_release_simq(ch->sim, TRUE); mtx_unlock(&ch->state_mtx); if (ch->flags & ATA_PERIODIC_POLL) callout_reset(&ch->poll_callout, hz, ata_periodic_poll, ch); -#else - /* reinit the devices, we dont know what mode/state they are in */ - error = ata_reinit(dev); - /* kick off requests on the queue */ - ata_start(dev); -#endif return error; } void ata_interrupt(void *data) { -#ifdef ATA_CAM struct ata_channel *ch = (struct ata_channel *)data; mtx_lock(&ch->state_mtx); xpt_batch_start(ch->sim); -#endif ata_interrupt_locked(data); -#ifdef ATA_CAM xpt_batch_done(ch->sim); mtx_unlock(&ch->state_mtx); -#endif } static void @@ -572,9 +353,6 @@ ata_interrupt_locked(void *data) struct ata_channel *ch = (struct ata_channel *)data; struct ata_request *request; -#ifndef ATA_CAM - mtx_lock(&ch->state_mtx); -#endif do { /* ignore interrupt if its not for us */ if (ch->hw.status && !ch->hw.status(ch->dev)) @@ -600,22 +378,12 @@ ata_interrupt_locked(void *data) ch->running = NULL; if (ch->state == ATA_ACTIVE) ch->state = ATA_IDLE; -#ifdef ATA_CAM ata_cam_end_transaction(ch->dev, request); -#else - mtx_unlock(&ch->state_mtx); - ATA_LOCKING(ch->dev, ATA_LF_UNLOCK); - ata_finish(request); -#endif return; } } while (0); -#ifndef ATA_CAM - mtx_unlock(&ch->state_mtx); -#endif } -#ifdef ATA_CAM static void ata_periodic_poll(void *data) { @@ -624,7 +392,6 @@ ata_periodic_poll(void *data) callout_reset(&ch->poll_callout, hz, ata_periodic_poll, ch); ata_interrupt(ch); } -#endif void ata_print_cable(device_t dev, u_int8_t *who) @@ -633,468 +400,9 @@ ata_print_cable(device_t dev, u_int8_t *who) "DMA limited to UDMA33, %s found non-ATA66 cable\n", who); } -#ifndef ATA_CAM -int -ata_check_80pin(device_t dev, int mode) -{ - struct ata_device *atadev = device_get_softc(dev); - - if (!ata_dma_check_80pin) { - if (bootverbose) - device_printf(dev, "Skipping 80pin cable check\n"); - return mode; - } - - if (mode > ATA_UDMA2 && !(atadev->param.hwres & ATA_CABLE_ID)) { - ata_print_cable(dev, "device"); - mode = ATA_UDMA2; - } - return mode; -} -#endif - -#ifndef ATA_CAM -void -ata_setmode(device_t dev) -{ - struct ata_channel *ch = device_get_softc(device_get_parent(dev)); - struct ata_device *atadev = device_get_softc(dev); - int error, mode, pmode; - - mode = atadev->mode; - do { - pmode = mode = ata_limit_mode(dev, mode, ATA_DMA_MAX); - mode = ATA_SETMODE(device_get_parent(dev), atadev->unit, mode); - if ((ch->flags & (ATA_CHECKS_CABLE | ATA_SATA)) == 0) - mode = ata_check_80pin(dev, mode); - } while (pmode != mode); /* Interate till successfull negotiation. */ - error = ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode); - if (bootverbose) - device_printf(dev, "%ssetting %s\n", - (error) ? "FAILURE " : "", ata_mode2str(mode)); - atadev->mode = mode; -} -#endif - -/* - * device related interfaces - */ -#ifndef ATA_CAM -static int -ata_ioctl(struct cdev *dev, u_long cmd, caddr_t data, - int32_t flag, struct thread *td) -{ - device_t device, *children; - struct ata_ioc_devices *devices = (struct ata_ioc_devices *)data; - int *value = (int *)data; - int i, nchildren, error = ENOTTY; - - switch (cmd) { - case IOCATAGMAXCHANNEL: - /* In case we have channel 0..n this will return n+1. */ - *value = devclass_get_maxunit(ata_devclass); - error = 0; - break; - - case IOCATAREINIT: - if (*value >= devclass_get_maxunit(ata_devclass) || - !(device = devclass_get_device(ata_devclass, *value)) || - !device_is_attached(device)) - return ENXIO; - error = ata_reinit(device); - break; - - case IOCATAATTACH: - if (*value >= devclass_get_maxunit(ata_devclass) || - !(device = devclass_get_device(ata_devclass, *value)) || - !device_is_attached(device)) - return ENXIO; - error = DEVICE_ATTACH(device); - break; - - case IOCATADETACH: - if (*value >= devclass_get_maxunit(ata_devclass) || - !(device = devclass_get_device(ata_devclass, *value)) || - !device_is_attached(device)) - return ENXIO; - error = DEVICE_DETACH(device); - break; - - case IOCATADEVICES: - if (devices->channel >= devclass_get_maxunit(ata_devclass) || - !(device = devclass_get_device(ata_devclass, devices->channel)) || - !device_is_attached(device)) - return ENXIO; - bzero(devices->name[0], 32); - bzero(&devices->params[0], sizeof(struct ata_params)); - bzero(devices->name[1], 32); - bzero(&devices->params[1], sizeof(struct ata_params)); - if (!device_get_children(device, &children, &nchildren)) { - for (i = 0; i < nchildren; i++) { - if (children[i] && device_is_attached(children[i])) { - struct ata_device *atadev = device_get_softc(children[i]); - - if (atadev->unit == ATA_MASTER) { /* XXX SOS PM */ - strncpy(devices->name[0], - device_get_nameunit(children[i]), 32); - bcopy(&atadev->param, &devices->params[0], - sizeof(struct ata_params)); - } - if (atadev->unit == ATA_SLAVE) { /* XXX SOS PM */ - strncpy(devices->name[1], - device_get_nameunit(children[i]), 32); - bcopy(&atadev->param, &devices->params[1], - sizeof(struct ata_params)); - } - } - } - free(children, M_TEMP); - error = 0; - } - else - error = ENODEV; - break; - - default: - if (ata_raid_ioctl_func) - error = ata_raid_ioctl_func(cmd, data); - } - return error; -} -#endif - -#ifndef ATA_CAM -int -ata_device_ioctl(device_t dev, u_long cmd, caddr_t data) -{ - struct ata_device *atadev = device_get_softc(dev); - struct ata_channel *ch = device_get_softc(device_get_parent(dev)); - struct ata_ioc_request *ioc_request = (struct ata_ioc_request *)data; - struct ata_params *params = (struct ata_params *)data; - int *mode = (int *)data; - struct ata_request *request; - caddr_t buf; - int error; - - switch (cmd) { - case IOCATAREQUEST: - if (ioc_request->count > - (ch->dma.max_iosize ? ch->dma.max_iosize : DFLTPHYS)) { - return (EFBIG); - } - if (!(buf = malloc(ioc_request->count, M_ATA, M_NOWAIT))) { - return ENOMEM; - } - if (!(request = ata_alloc_request())) { - free(buf, M_ATA); - return ENOMEM; - } - request->dev = atadev->dev; - if (ioc_request->flags & ATA_CMD_WRITE) { - error = copyin(ioc_request->data, buf, ioc_request->count); - if (error) { - free(buf, M_ATA); - ata_free_request(request); - return error; - } - } - if (ioc_request->flags & ATA_CMD_ATAPI) { - request->flags = ATA_R_ATAPI; - bcopy(ioc_request->u.atapi.ccb, request->u.atapi.ccb, 16); - } - else { - request->u.ata.command = ioc_request->u.ata.command; - request->u.ata.feature = ioc_request->u.ata.feature; - request->u.ata.lba = ioc_request->u.ata.lba; - request->u.ata.count = ioc_request->u.ata.count; - } - request->timeout = ioc_request->timeout; - request->data = buf; - request->bytecount = ioc_request->count; - request->transfersize = request->bytecount; - if (ioc_request->flags & ATA_CMD_CONTROL) - request->flags |= ATA_R_CONTROL; - if (ioc_request->flags & ATA_CMD_READ) - request->flags |= ATA_R_READ; - if (ioc_request->flags & ATA_CMD_WRITE) - request->flags |= ATA_R_WRITE; - ata_queue_request(request); - if (request->flags & ATA_R_ATAPI) { - bcopy(&request->u.atapi.sense, &ioc_request->u.atapi.sense, - sizeof(struct atapi_sense)); - } - else { - ioc_request->u.ata.command = request->u.ata.command; - ioc_request->u.ata.feature = request->u.ata.feature; - ioc_request->u.ata.lba = request->u.ata.lba; - ioc_request->u.ata.count = request->u.ata.count; - } - ioc_request->error = request->result; - if (ioc_request->flags & ATA_CMD_READ) - error = copyout(buf, ioc_request->data, ioc_request->count); - else - error = 0; - free(buf, M_ATA); - ata_free_request(request); - return error; - - case IOCATAGPARM: - ata_getparam(atadev, 0); - bcopy(&atadev->param, params, sizeof(struct ata_params)); - return 0; - - case IOCATASMODE: - atadev->mode = *mode; - ata_setmode(dev); - return 0; - - case IOCATAGMODE: - *mode = atadev->mode | - (ATA_GETREV(device_get_parent(dev), atadev->unit) << 8); - return 0; - case IOCATASSPINDOWN: - atadev->spindown = *mode; - return 0; - case IOCATAGSPINDOWN: - *mode = atadev->spindown; - return 0; - default: - return ENOTTY; - } -} -#endif - -#ifndef ATA_CAM -static void -ata_boot_attach(void) -{ - struct ata_channel *ch; - int ctlr; - - mtx_lock(&Giant); /* newbus suckage it needs Giant */ - - /* kick off probe and attach on all channels */ - for (ctlr = 0; ctlr < devclass_get_maxunit(ata_devclass); ctlr++) { - if ((ch = devclass_get_softc(ata_devclass, ctlr))) { - ata_identify(ch->dev); - } - } - - /* release the hook that got us here, we are only needed once during boot */ - if (ata_delayed_attach) { - config_intrhook_disestablish(ata_delayed_attach); - free(ata_delayed_attach, M_TEMP); - ata_delayed_attach = NULL; - } - - mtx_unlock(&Giant); /* newbus suckage dealt with, release Giant */ -} -#endif - /* * misc support functions */ -#ifndef ATA_CAM -static device_t -ata_add_child(device_t parent, struct ata_device *atadev, int unit) -{ - device_t child; - - if ((child = device_add_child(parent, (unit < 0) ? NULL : "ad", unit))) { - device_set_softc(child, atadev); - device_quiet(child); - atadev->dev = child; - atadev->max_iosize = DEV_BSIZE; - atadev->mode = ATA_PIO_MAX; - } - return child; -} -#endif - -#ifndef ATA_CAM -int -ata_getparam(struct ata_device *atadev, int init) -{ - struct ata_channel *ch = device_get_softc(device_get_parent(atadev->dev)); - struct ata_request *request; - const char *res; - char buf[64]; - u_int8_t command = 0; - int error = ENOMEM, retries = 2, mode = -1; - - if (ch->devices & (ATA_ATA_MASTER << atadev->unit)) - command = ATA_ATA_IDENTIFY; - if (ch->devices & (ATA_ATAPI_MASTER << atadev->unit)) - command = ATA_ATAPI_IDENTIFY; - if (!command) - return ENXIO; - - while (retries-- > 0 && error) { - if (!(request = ata_alloc_request())) - break; - request->dev = atadev->dev; - request->timeout = 1; - request->retries = 0; - request->u.ata.command = command; - request->flags = (ATA_R_READ|ATA_R_AT_HEAD|ATA_R_DIRECT); - if (!bootverbose) - request->flags |= ATA_R_QUIET; - request->data = (void *)&atadev->param; - request->bytecount = sizeof(struct ata_params); - request->donecount = 0; - request->transfersize = DEV_BSIZE; - ata_queue_request(request); - error = request->result; - ata_free_request(request); - } - - if (!error && (isprint(atadev->param.model[0]) || - isprint(atadev->param.model[1]))) { - struct ata_params *atacap = &atadev->param; - int16_t *ptr; - - for (ptr = (int16_t *)atacap; - ptr < (int16_t *)atacap + sizeof(struct ata_params)/2; ptr++) { - *ptr = le16toh(*ptr); - } - if (!(!strncmp(atacap->model, "FX", 2) || - !strncmp(atacap->model, "NEC", 3) || - !strncmp(atacap->model, "Pioneer", 7) || - !strncmp(atacap->model, "SHARP", 5))) { - bswap(atacap->model, sizeof(atacap->model)); - bswap(atacap->revision, sizeof(atacap->revision)); - bswap(atacap->serial, sizeof(atacap->serial)); - } - btrim(atacap->model, sizeof(atacap->model)); - bpack(atacap->model, atacap->model, sizeof(atacap->model)); - btrim(atacap->revision, sizeof(atacap->revision)); - bpack(atacap->revision, atacap->revision, sizeof(atacap->revision)); - btrim(atacap->serial, sizeof(atacap->serial)); - bpack(atacap->serial, atacap->serial, sizeof(atacap->serial)); - - if (bootverbose) - printf("ata%d-%s: pio=%s wdma=%s udma=%s cable=%s wire\n", - device_get_unit(ch->dev), - ata_unit2str(atadev), - ata_mode2str(ata_pmode(atacap)), - ata_mode2str(ata_wmode(atacap)), - ata_mode2str(ata_umode(atacap)), - (atacap->hwres & ATA_CABLE_ID) ? "80":"40"); - - if (init) { - char buffer[64]; - - sprintf(buffer, "%.40s/%.8s", atacap->model, atacap->revision); - device_set_desc_copy(atadev->dev, buffer); - if ((atadev->param.config & ATA_PROTO_ATAPI) && - (atadev->param.config != ATA_CFA_MAGIC1) && - (atadev->param.config != ATA_CFA_MAGIC2)) { - if (atapi_dma && - (atadev->param.config & ATA_DRQ_MASK) != ATA_DRQ_INTR && - ata_umode(&atadev->param) >= ATA_UDMA2) - atadev->mode = ATA_DMA_MAX; - } - else { - if (ata_dma && - (ata_umode(&atadev->param) > 0 || - ata_wmode(&atadev->param) > 0)) - atadev->mode = ATA_DMA_MAX; - } - snprintf(buf, sizeof(buf), "dev%d.mode", atadev->unit); - if (resource_string_value(device_get_name(ch->dev), - device_get_unit(ch->dev), buf, &res) == 0) - mode = ata_str2mode(res); - else if (resource_string_value(device_get_name(ch->dev), - device_get_unit(ch->dev), "mode", &res) == 0) - mode = ata_str2mode(res); - if (mode >= 0) - atadev->mode = mode; - } - } - else { - if (!error) - error = ENXIO; - } - return error; -} -#endif - -#ifndef ATA_CAM -int -ata_identify(device_t dev) -{ - struct ata_channel *ch = device_get_softc(dev); - struct ata_device *atadev; - device_t *children; - device_t child, master = NULL; - int nchildren, i, n = ch->devices; - - if (bootverbose) - device_printf(dev, "Identifying devices: %08x\n", ch->devices); - - mtx_lock(&Giant); - /* Skip existing devices. */ - if (!device_get_children(dev, &children, &nchildren)) { - for (i = 0; i < nchildren; i++) { - if (children[i] && (atadev = device_get_softc(children[i]))) - n &= ~((ATA_ATA_MASTER | ATA_ATAPI_MASTER) << atadev->unit); - } - free(children, M_TEMP); - } - /* Create new devices. */ - if (bootverbose) - device_printf(dev, "New devices: %08x\n", n); - if (n == 0) { - mtx_unlock(&Giant); - return (0); - } - for (i = 0; i < ATA_PM; ++i) { - if (n & (((ATA_ATA_MASTER | ATA_ATAPI_MASTER) << i))) { - int unit = -1; - - if (!(atadev = malloc(sizeof(struct ata_device), - M_ATA, M_NOWAIT | M_ZERO))) { - device_printf(dev, "out of memory\n"); - return ENOMEM; - } - atadev->unit = i; -#ifdef ATA_STATIC_ID - if (n & (ATA_ATA_MASTER << i)) - unit = (device_get_unit(dev) << 1) + i; -#endif - if ((child = ata_add_child(dev, atadev, unit))) { - /* - * PATA slave should be identified first, to allow - * device cable detection on master to work properly. - */ - if (i == 0 && (n & ATA_PORTMULTIPLIER) == 0 && - (n & ((ATA_ATA_MASTER | ATA_ATAPI_MASTER) << 1)) != 0) { - master = child; - continue; - } - if (ata_getparam(atadev, 1)) { - device_delete_child(dev, child); - free(atadev, M_ATA); - } - } - else - free(atadev, M_ATA); - } - } - if (master) { - atadev = device_get_softc(master); - if (ata_getparam(atadev, 1)) { - device_delete_child(dev, master); - free(atadev, M_ATA); - } - } - bus_generic_probe(dev); - bus_generic_attach(dev); - mtx_unlock(&Giant); - return 0; -} -#endif - void ata_default_registers(device_t dev) { @@ -1111,110 +419,6 @@ ata_default_registers(device_t dev) ch->r_io[ATA_ALTSTAT].offset = ch->r_io[ATA_CONTROL].offset; } -#ifndef ATA_CAM -void -ata_modify_if_48bit(struct ata_request *request) -{ - struct ata_channel *ch = device_get_softc(request->parent); - struct ata_device *atadev = device_get_softc(request->dev); - - request->flags &= ~ATA_R_48BIT; - - if (((request->u.ata.lba + request->u.ata.count) >= ATA_MAX_28BIT_LBA || - request->u.ata.count > 256) && - atadev->param.support.command2 & ATA_SUPPORT_ADDRESS48) { - - /* translate command into 48bit version */ - switch (request->u.ata.command) { - case ATA_READ: - request->u.ata.command = ATA_READ48; - break; - case ATA_READ_MUL: - request->u.ata.command = ATA_READ_MUL48; - break; - case ATA_READ_DMA: - if (ch->flags & ATA_NO_48BIT_DMA) { - if (request->transfersize > DEV_BSIZE) - request->u.ata.command = ATA_READ_MUL48; - else - request->u.ata.command = ATA_READ48; - request->flags &= ~ATA_R_DMA; - } - else - request->u.ata.command = ATA_READ_DMA48; - break; - case ATA_READ_DMA_QUEUED: - if (ch->flags & ATA_NO_48BIT_DMA) { - if (request->transfersize > DEV_BSIZE) - request->u.ata.command = ATA_READ_MUL48; - else - request->u.ata.command = ATA_READ48; - request->flags &= ~ATA_R_DMA; - } - else - request->u.ata.command = ATA_READ_DMA_QUEUED48; - break; - case ATA_WRITE: - request->u.ata.command = ATA_WRITE48; - break; - case ATA_WRITE_MUL: - request->u.ata.command = ATA_WRITE_MUL48; - break; - case ATA_WRITE_DMA: - if (ch->flags & ATA_NO_48BIT_DMA) { - if (request->transfersize > DEV_BSIZE) - request->u.ata.command = ATA_WRITE_MUL48; - else - request->u.ata.command = ATA_WRITE48; - request->flags &= ~ATA_R_DMA; - } - else - request->u.ata.command = ATA_WRITE_DMA48; - break; - case ATA_WRITE_DMA_QUEUED: - if (ch->flags & ATA_NO_48BIT_DMA) { - if (request->transfersize > DEV_BSIZE) - request->u.ata.command = ATA_WRITE_MUL48; - else - request->u.ata.command = ATA_WRITE48; - request->u.ata.command = ATA_WRITE48; - request->flags &= ~ATA_R_DMA; - } - else - request->u.ata.command = ATA_WRITE_DMA_QUEUED48; - break; - case ATA_FLUSHCACHE: - request->u.ata.command = ATA_FLUSHCACHE48; - break; - case ATA_SET_MAX_ADDRESS: - request->u.ata.command = ATA_SET_MAX_ADDRESS48; - break; - default: - return; - } - request->flags |= ATA_R_48BIT; - } - else if (atadev->param.support.command2 & ATA_SUPPORT_ADDRESS48) { - - /* translate command into 48bit version */ - switch (request->u.ata.command) { - case ATA_FLUSHCACHE: - request->u.ata.command = ATA_FLUSHCACHE48; - break; - case ATA_READ_NATIVE_MAX_ADDRESS: - request->u.ata.command = ATA_READ_NATIVE_MAX_ADDRESS48; - break; - case ATA_SET_MAX_ADDRESS: - request->u.ata.command = ATA_SET_MAX_ADDRESS48; - break; - default: - return; - } - request->flags |= ATA_R_48BIT; - } -} -#endif - void ata_udelay(int interval) { @@ -1225,21 +429,6 @@ ata_udelay(int interval) pause("ataslp", interval/(1000000/hz)); } -#ifndef ATA_CAM -const char * -ata_unit2str(struct ata_device *atadev) -{ - struct ata_channel *ch = device_get_softc(device_get_parent(atadev->dev)); - static char str[8]; - - if (ch->devices & ATA_PORTMULTIPLIER) - sprintf(str, "port%d", atadev->unit); - else - sprintf(str, "%s", atadev->unit == ATA_MASTER ? "master" : "slave"); - return str; -} -#endif - const char * ata_mode2str(int mode) { @@ -1299,21 +488,6 @@ ata_str2mode(const char *str) return (-1); } -#ifndef ATA_CAM -const char * -ata_satarev2str(int rev) -{ - switch (rev) { - case 0: return ""; - case 1: return "SATA 1.5Gb/s"; - case 2: return "SATA 3Gb/s"; - case 3: return "SATA 6Gb/s"; - case 0xff: return "SATA"; - default: return "???"; - } -} -#endif - int ata_atapi(device_t dev, int target) { @@ -1322,143 +496,6 @@ ata_atapi(device_t dev, int target) return (ch->devices & (ATA_ATAPI_MASTER << target)); } -#ifndef ATA_CAM -int -ata_pmode(struct ata_params *ap) -{ - if (ap->atavalid & ATA_FLAG_64_70) { - if (ap->apiomodes & 0x02) - return ATA_PIO4; - if (ap->apiomodes & 0x01) - return ATA_PIO3; - } - if (ap->mwdmamodes & 0x04) - return ATA_PIO4; - if (ap->mwdmamodes & 0x02) - return ATA_PIO3; - if (ap->mwdmamodes & 0x01) - return ATA_PIO2; - if ((ap->retired_piomode & ATA_RETIRED_PIO_MASK) == 0x200) - return ATA_PIO2; - if ((ap->retired_piomode & ATA_RETIRED_PIO_MASK) == 0x100) - return ATA_PIO1; - if ((ap->retired_piomode & ATA_RETIRED_PIO_MASK) == 0x000) - return ATA_PIO0; - return ATA_PIO0; -} -#endif - -#ifndef ATA_CAM -int -ata_wmode(struct ata_params *ap) -{ - if (ap->mwdmamodes & 0x04) - return ATA_WDMA2; - if (ap->mwdmamodes & 0x02) - return ATA_WDMA1; - if (ap->mwdmamodes & 0x01) - return ATA_WDMA0; - return -1; -} -#endif - -#ifndef ATA_CAM -int -ata_umode(struct ata_params *ap) -{ - if (ap->atavalid & ATA_FLAG_88) { - if (ap->udmamodes & 0x40) - return ATA_UDMA6; - if (ap->udmamodes & 0x20) - return ATA_UDMA5; - if (ap->udmamodes & 0x10) - return ATA_UDMA4; - if (ap->udmamodes & 0x08) - return ATA_UDMA3; - if (ap->udmamodes & 0x04) - return ATA_UDMA2; - if (ap->udmamodes & 0x02) - return ATA_UDMA1; - if (ap->udmamodes & 0x01) - return ATA_UDMA0; - } - return -1; -} -#endif - -#ifndef ATA_CAM -int -ata_limit_mode(device_t dev, int mode, int maxmode) -{ - struct ata_device *atadev = device_get_softc(dev); - - if (maxmode && mode > maxmode) - mode = maxmode; - - if (mode >= ATA_UDMA0 && ata_umode(&atadev->param) > 0) - return min(mode, ata_umode(&atadev->param)); - - if (mode >= ATA_WDMA0 && ata_wmode(&atadev->param) > 0) - return min(mode, ata_wmode(&atadev->param)); - - if (mode > ata_pmode(&atadev->param)) - return min(mode, ata_pmode(&atadev->param)); - - return mode; -} -#endif - -#ifndef ATA_CAM -static void -bswap(int8_t *buf, int len) -{ - u_int16_t *ptr = (u_int16_t*)(buf + len); - - while (--ptr >= (u_int16_t*)buf) - *ptr = ntohs(*ptr); -} -#endif - -#ifndef ATA_CAM -static void -btrim(int8_t *buf, int len) -{ - int8_t *ptr; - - for (ptr = buf; ptr < buf+len; ++ptr) - if (!*ptr || *ptr == '_') - *ptr = ' '; - for (ptr = buf + len - 1; ptr >= buf && *ptr == ' '; --ptr) - *ptr = 0; -} -#endif - -#ifndef ATA_CAM -static void -bpack(int8_t *src, int8_t *dst, int len) -{ - int i, j, blank; - - for (i = j = blank = 0 ; i < len; i++) { - if (blank && src[i] == ' ') continue; - if (blank && src[i] != ' ') { - dst[j++] = src[i]; - blank = 0; - continue; - } - if (src[i] == ' ') { - blank = 1; - if (i == 0) - continue; - } - dst[j++] = src[i]; - } - if (j < len) - dst[j] = 0x00; -} -#endif - -#ifdef ATA_CAM static void ata_cam_begin_transaction(device_t dev, union ccb *ccb) { @@ -1928,7 +965,6 @@ atapoll(struct cam_sim *sim) ata_interrupt_locked(ch); } -#endif /* * module handeling @@ -1936,38 +972,12 @@ atapoll(struct cam_sim *sim) static int ata_module_event_handler(module_t mod, int what, void *arg) { -#ifndef ATA_CAM - static struct cdev *atacdev; -#endif switch (what) { case MOD_LOAD: -#ifndef ATA_CAM - /* register controlling device */ - atacdev = make_dev(&ata_cdevsw, 0, UID_ROOT, GID_OPERATOR, 0600, "ata"); - - if (cold) { - /* register boot attach to be run when interrupts are enabled */ - if (!(ata_delayed_attach = (struct intr_config_hook *) - malloc(sizeof(struct intr_config_hook), - M_TEMP, M_NOWAIT | M_ZERO))) { - printf("ata: malloc of delayed attach hook failed\n"); - return EIO; - } - ata_delayed_attach->ich_func = (void*)ata_boot_attach; - if (config_intrhook_establish(ata_delayed_attach) != 0) { - printf("ata: config_intrhook_establish failed\n"); - free(ata_delayed_attach, M_TEMP); - } - } -#endif return 0; case MOD_UNLOAD: -#ifndef ATA_CAM - /* deregister controlling device */ - destroy_dev(atacdev); -#endif return 0; default: @@ -1978,25 +988,19 @@ ata_module_event_handler(module_t mod, int what, void *arg) static moduledata_t ata_moduledata = { "ata", ata_module_event_handler, NULL }; DECLARE_MODULE(ata, ata_moduledata, SI_SUB_CONFIGURE, SI_ORDER_SECOND); MODULE_VERSION(ata, 1); -#ifdef ATA_CAM MODULE_DEPEND(ata, cam, 1, 1, 1); -#endif static void ata_init(void) { ata_request_zone = uma_zcreate("ata_request", sizeof(struct ata_request), NULL, NULL, NULL, NULL, 0, 0); - ata_composite_zone = uma_zcreate("ata_composite", - sizeof(struct ata_composite), - NULL, NULL, NULL, NULL, 0, 0); } SYSINIT(ata_register, SI_SUB_DRIVERS, SI_ORDER_SECOND, ata_init, NULL); static void ata_uninit(void) { - uma_zdestroy(ata_composite_zone); uma_zdestroy(ata_request_zone); } SYSUNINIT(ata_unregister, SI_SUB_DRIVERS, SI_ORDER_SECOND, ata_uninit, NULL); |