diff options
author | sos <sos@FreeBSD.org> | 2008-04-11 11:30:27 +0000 |
---|---|---|
committer | sos <sos@FreeBSD.org> | 2008-04-11 11:30:27 +0000 |
commit | e7012ad33098903c6d2cd65d0210c9e2ad229c7f (patch) | |
tree | 8fa27bd351846e77967ad0e3d556eb1f6ab38be0 /sys | |
parent | 5dd963773ae028c909b38502e98d913b021614d9 (diff) | |
download | FreeBSD-src-e7012ad33098903c6d2cd65d0210c9e2ad229c7f.zip FreeBSD-src-e7012ad33098903c6d2cd65d0210c9e2ad229c7f.tar.gz |
Fix the brokenness in the former commit, sorry for the mess.
The problem is that the PM support is part of a much larger WIP here, but due to popular demand I decided to get some of it imported.
Also I forgot the mention:
HW sponsored by: Vitsch Electronics / VEHosting
Diffstat (limited to 'sys')
-rw-r--r-- | sys/dev/ata/ata-all.c | 59 | ||||
-rw-r--r-- | sys/dev/ata/ata-all.h | 9 | ||||
-rw-r--r-- | sys/dev/ata/ata-disk.c | 9 | ||||
-rw-r--r-- | sys/dev/ata/ata-dma.c | 35 | ||||
-rw-r--r-- | sys/dev/ata/ata-queue.c | 8 | ||||
-rw-r--r-- | sys/dev/ata/ata-raid.c | 35 | ||||
-rw-r--r-- | sys/dev/ata/atapi-cam.c | 3 | ||||
-rw-r--r-- | sys/dev/ata/atapi-cd.c | 10 | ||||
-rw-r--r-- | sys/dev/ata/atapi-fd.c | 3 | ||||
-rw-r--r-- | sys/dev/ata/atapi-tape.c | 3 |
10 files changed, 91 insertions, 83 deletions
diff --git a/sys/dev/ata/ata-all.c b/sys/dev/ata/ata-all.c index 2f1f317..5435851 100644 --- a/sys/dev/ata/ata-all.c +++ b/sys/dev/ata/ata-all.c @@ -71,12 +71,12 @@ MALLOC_DEFINE(M_ATA, "ata_generic", "ATA driver generic layer"); int (*ata_raid_ioctl_func)(u_long cmd, caddr_t data) = NULL; struct intr_config_hook *ata_delayed_attach = NULL; devclass_t ata_devclass; -uma_zone_t ata_request_zone; uma_zone_t ata_composite_zone; int ata_wc = 1; int ata_setmax = 0; /* local vars */ +static uma_zone_t ata_request_zone; static int ata_dma = 1; static int atapi_dma = 1; @@ -451,7 +451,7 @@ ata_device_ioctl(device_t dev, u_long cmd, caddr_t data) if (!(buf = malloc(ioc_request->count, M_ATA, M_NOWAIT))) { return ENOMEM; } - if (!(request = ata_alloc_request())) { + if (!(request = ata_alloc_request(dev))) { free(buf, M_ATA); return ENOMEM; } @@ -463,7 +463,6 @@ ata_device_ioctl(device_t dev, u_long cmd, caddr_t data) return error; } } - request->dev = dev; if (ioc_request->flags & ATA_CMD_ATAPI) { request->flags = ATA_R_ATAPI; bcopy(ioc_request->u.atapi.ccb, request->u.atapi.ccb, 16); @@ -588,9 +587,8 @@ ata_getparam(struct ata_device *atadev, int init) return ENXIO; while (retries-- > 0 && error) { - if (!(request = ata_alloc_request())) + if (!(request = ata_alloc_request(atadev->dev))) break; - request->dev = atadev->dev; request->timeout = 1; request->retries = 0; request->u.ata.command = command; @@ -1004,6 +1002,57 @@ bpack(int8_t *src, int8_t *dst, int len) dst[j] = 0x00; } +struct ata_request * +ata_alloc_request(device_t dev) +{ + struct ata_channel *ch = device_get_softc(device_get_parent(dev)); + struct ata_request *request; + + if ((request = uma_zalloc(ata_request_zone, M_NOWAIT | M_ZERO))) { + if (bus_dma_tag_create(ch->dma.dmatag, PAGE_SIZE, PAGE_SIZE, + ch->dma.max_address, BUS_SPACE_MAXADDR, + NULL, NULL, PAGE_SIZE, 1, PAGE_SIZE, + 0, NULL, NULL, &request->dma.sg_tag)) { + device_printf(ch->dev, "FAILURE - create sg_tag\n"); + return NULL; + } + if (bus_dmamem_alloc(request->dma.sg_tag, (void **)&request->dma.sg, 0, + &request->dma.sg_map)) { + device_printf(ch->dev, "FAILURE - alloc sg_map\n"); + bus_dma_tag_destroy(request->dma.sg_tag); + return NULL; + } + if (bus_dma_tag_create(ch->dma.dmatag, + ch->dma.alignment, ch->dma.boundary, + ch->dma.max_address, BUS_SPACE_MAXADDR, + NULL, NULL, ch->dma.max_iosize, + ATA_DMA_ENTRIES, ch->dma.segsize, + BUS_DMA_ALLOCNOW, NULL, NULL, + &request->dma.data_tag)) { + device_printf(ch->dev, "FAILURE - create data_tag\n"); + bus_dmamem_free(request->dma.sg_tag, request->dma.sg, + request->dma.sg_map); + bus_dma_tag_destroy(request->dma.sg_tag); + return NULL; + } + request->dev = dev; + } + else + device_printf(dev, "FAILURE - ata_alloc_request\n"); + return request; +} + +void +ata_free_request(struct ata_request *request) +{ + if (!(request->flags & ATA_R_DANGER2)) + if (request->dma.data_tag) + bus_dma_tag_destroy(request->dma.data_tag); + if (request->dma.sg_tag) { + bus_dma_tag_destroy(request->dma.sg_tag); + uma_zfree(ata_request_zone, request); + } +} /* * module handeling diff --git a/sys/dev/ata/ata-all.h b/sys/dev/ata/ata-all.h index 6470e35..5065661 100644 --- a/sys/dev/ata/ata-all.h +++ b/sys/dev/ata/ata-all.h @@ -581,12 +581,9 @@ void ata_generic_reset(device_t dev); int ata_generic_command(struct ata_request *request); /* macros for alloc/free of struct ata_request */ -extern uma_zone_t ata_request_zone; -#define ata_alloc_request() uma_zalloc(ata_request_zone, M_NOWAIT | M_ZERO) -#define ata_free_request(request) { \ - if (!(request->flags & ATA_R_DANGER2)) \ - uma_zfree(ata_request_zone, request); \ - } +struct ata_request *ata_alloc_request(device_t dev); +void ata_free_request(struct ata_request *request); + /* macros for alloc/free of struct ata_composite */ extern uma_zone_t ata_composite_zone; #define ata_alloc_composite() uma_zalloc(ata_composite_zone, M_NOWAIT | M_ZERO) diff --git a/sys/dev/ata/ata-disk.c b/sys/dev/ata/ata-disk.c index a4d7959..668ae72 100644 --- a/sys/dev/ata/ata-disk.c +++ b/sys/dev/ata/ata-disk.c @@ -224,12 +224,11 @@ ad_spindown(void *priv) return; device_printf(dev, "Idle, spin down\n"); atadev->spindown_state = 1; - if (!(request = ata_alloc_request())) { + if (!(request = ata_alloc_request(dev))) { device_printf(dev, "FAILURE - out of memory in ad_spindown\n"); return; } request->flags = ATA_R_CONTROL; - request->dev = dev; request->timeout = 5; request->retries = 1; request->callback = ad_power_callback; @@ -249,14 +248,13 @@ ad_strategy(struct bio *bp) callout_reset(&atadev->spindown_timer, hz * atadev->spindown, ad_spindown, dev); - if (!(request = ata_alloc_request())) { + if (!(request = ata_alloc_request(dev))) { device_printf(dev, "FAILURE - out of memory in start\n"); biofinish(bp, NULL, ENOMEM); return; } /* setup request */ - request->dev = dev; request->bio = bp; request->callback = ad_done; if (atadev->spindown_state) { @@ -450,11 +448,10 @@ ad_set_geometry(device_t dev) adp->total_secs / (adp->heads * adp->sectors), adp->heads, adp->sectors); - if (!(request = ata_alloc_request())) + if (!(request = ata_alloc_request(dev))) return; /* get the max native size the device supports */ - request->dev = dev; request->u.ata.command = ATA_READ_NATIVE_MAX_ADDRESS; request->u.ata.lba = 0; request->u.ata.count = 0; diff --git a/sys/dev/ata/ata-dma.c b/sys/dev/ata/ata-dma.c index 10db9aa..851dde8 100644 --- a/sys/dev/ata/ata-dma.c +++ b/sys/dev/ata/ata-dma.c @@ -201,20 +201,6 @@ ata_dmaload(struct ata_request *request, void *addr, int *entries) return EIO; } - if (bus_dma_tag_create(ch->dma.dmatag, PAGE_SIZE, PAGE_SIZE, - ch->dma.max_address, BUS_SPACE_MAXADDR, - NULL, NULL, MAXTABSZ, 1, MAXTABSZ, - 0, NULL, NULL, &request->dma.sg_tag)) { - device_printf(request->dev, "FAILURE - create sg_tag\n"); - goto error; - } - - if (bus_dmamem_alloc(request->dma.sg_tag, (void **)&request->dma.sg, 0, - &request->dma.sg_map)) { - device_printf(request->dev, "FAILURE - alloc sg_map\n"); - goto error; - } - if (bus_dmamap_load(request->dma.sg_tag, request->dma.sg_map, request->dma.sg, MAXTABSZ, ata_dmasetupc_cb, &dcba, BUS_DMA_NOWAIT) || dcba.error){ @@ -225,16 +211,6 @@ ata_dmaload(struct ata_request *request, void *addr, int *entries) } request->dma.sg_bus = dcba.maddr; - if (bus_dma_tag_create(ch->dma.dmatag, ch->dma.alignment, ch->dma.boundary, - ch->dma.max_address, BUS_SPACE_MAXADDR, - NULL, NULL, ch->dma.max_iosize, - ATA_DMA_ENTRIES, ch->dma.segsize, - BUS_DMA_ALLOCNOW, NULL, NULL, - &request->dma.data_tag)) { - device_printf(request->dev, "FAILURE - create data_tag\n"); - goto error; - } - if (bus_dmamap_create(request->dma.data_tag, 0, &request->dma.data_map)) { device_printf(request->dev, "FAILURE - create data_map\n"); goto error; @@ -288,14 +264,12 @@ ata_dmaunload(struct ata_request *request) request->dma.cur_iosize = 0; } + if (request->dma.data_map) { bus_dmamap_destroy(request->dma.data_tag, request->dma.data_map); request->dma.data_map = NULL; } - if (request->dma.data_tag) { - bus_dma_tag_destroy(request->dma.data_tag); - request->dma.data_tag = NULL; - } + if (request->dma.sg_bus) { bus_dmamap_unload(request->dma.sg_tag, request->dma.sg_map); bus_dmamem_free(request->dma.sg_tag, request->dma.sg, @@ -304,9 +278,6 @@ ata_dmaunload(struct ata_request *request) request->dma.sg_bus = 0; request->dma.sg_map = NULL; } - if (request->dma.sg_tag) { - bus_dma_tag_destroy(request->dma.sg_tag); - request->dma.sg_tag = NULL; - } + return 0; } diff --git a/sys/dev/ata/ata-queue.c b/sys/dev/ata/ata-queue.c index 763058c..e20f0d1 100644 --- a/sys/dev/ata/ata-queue.c +++ b/sys/dev/ata/ata-queue.c @@ -56,7 +56,7 @@ ata_queue_request(struct ata_request *request) /* treat request as virgin (this might be an ATA_R_REQUEUE) */ request->result = request->status = request->error = 0; - /* check that that the device is still valid */ + /* check that the device is still valid */ if (!(request->parent = device_get_parent(request->dev))) { request->result = ENXIO; if (request->callback) @@ -119,11 +119,10 @@ int ata_controlcmd(device_t dev, u_int8_t command, u_int16_t feature, u_int64_t lba, u_int16_t count) { - struct ata_request *request = ata_alloc_request(); + struct ata_request *request = ata_alloc_request(dev); int error = ENOMEM; if (request) { - request->dev = dev; request->u.ata.command = command; request->u.ata.lba = lba; request->u.ata.count = count; @@ -142,12 +141,11 @@ int ata_atapicmd(device_t dev, u_int8_t *ccb, caddr_t data, int count, int flags, int timeout) { - struct ata_request *request = ata_alloc_request(); + struct ata_request *request = ata_alloc_request(dev); struct ata_device *atadev = device_get_softc(dev); int error = ENOMEM; if (request) { - request->dev = dev; if ((atadev->param.config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_12) bcopy(ccb, request->u.atapi.ccb, 12); else diff --git a/sys/dev/ata/ata-raid.c b/sys/dev/ata/ata-raid.c index 50a872b..01c586b 100644 --- a/sys/dev/ata/ata-raid.c +++ b/sys/dev/ata/ata-raid.c @@ -83,7 +83,7 @@ static int ata_raid_sis_read_meta(device_t dev, struct ar_softc **raidp); static int ata_raid_sis_write_meta(struct ar_softc *rdp); static int ata_raid_via_read_meta(device_t dev, struct ar_softc **raidp); static int ata_raid_via_write_meta(struct ar_softc *rdp); -static struct ata_request *ata_raid_init_request(struct ar_softc *rdp, struct bio *bio); +static struct ata_request *ata_raid_init_request(device_t dev, struct ar_softc *rdp, struct bio *bio); static int ata_raid_send_request(struct ata_request *request); static int ata_raid_rw(device_t dev, u_int64_t lba, void *data, u_int bcount, int flags); static char * ata_raid_format(struct ar_softc *rdp); @@ -263,7 +263,7 @@ ata_raid_flush(struct bio *bp) for (disk = 0; disk < rdp->total_disks; disk++) { if ((dev = rdp->disks[disk].dev) == NULL) continue; - if (!(request = ata_raid_init_request(rdp, bp))) + if (!(request = ata_raid_init_request(dev, rdp, bp))) return ENOMEM; request->dev = dev; request->u.ata.command = ATA_FLUSHCACHE; @@ -353,7 +353,7 @@ ata_raid_strategy(struct bio *bp) if (!(drv == 0 && rdp->format == AR_F_HPTV2_RAID)) lba += rdp->offset_sectors; - if (!(request = ata_raid_init_request(rdp, bp))) { + if (!(request = ata_raid_init_request(rdp->disks[drv].dev, rdp, bp))) { biofinish(bp, NULL, EIO); return; } @@ -375,7 +375,7 @@ ata_raid_strategy(struct bio *bp) return; } request->this = drv; - request->dev = rdp->disks[request->this].dev; + request->dev = rdp->disks[drv].dev; ata_raid_send_request(request); break; @@ -457,12 +457,14 @@ ata_raid_strategy(struct bio *bp) /* do we have a spare to rebuild on ? */ if (rdp->disks[this].flags & AR_DF_SPARE) { if ((composite = ata_alloc_composite())) { - if ((rebuild = ata_alloc_request())) { + if ((rebuild = ata_raid_init_request( + rdp->disks[this].dev, rdp, bp))) { rdp->rebuild_lba = blk + chunk; - bcopy(request, rebuild, - sizeof(struct ata_request)); + rebuild->data = request->data; + rebuild->bytecount = request->bytecount; + rebuild->u.ata.lba = request->u.ata.lba; + rebuild->u.ata.count = request->u.ata.count; rebuild->this = this; - rebuild->dev = rdp->disks[this].dev; rebuild->flags &= ~ATA_R_READ; rebuild->flags |= ATA_R_WRITE; mtx_init(&composite->lock, @@ -518,14 +520,16 @@ ata_raid_strategy(struct bio *bp) int this = drv + rdp->width; if ((composite = ata_alloc_composite())) { - if ((mirror = ata_alloc_request())) { + if ((mirror = ata_raid_init_request( + rdp->disks[this].dev, rdp, bp))) { if ((blk <= rdp->rebuild_lba) && ((blk + chunk) > rdp->rebuild_lba)) rdp->rebuild_lba = blk + chunk; - bcopy(request, mirror, - sizeof(struct ata_request)); + mirror->data = request->data; + mirror->bytecount = request->bytecount; + mirror->u.ata.lba = request->u.ata.lba; + mirror->u.ata.count = request->u.ata.count; mirror->this = this; - mirror->dev = rdp->disks[this].dev; mtx_init(&composite->lock, "ATA PseudoRAID mirror lock", NULL, MTX_DEF); @@ -4020,11 +4024,11 @@ ata_raid_via_write_meta(struct ar_softc *rdp) } static struct ata_request * -ata_raid_init_request(struct ar_softc *rdp, struct bio *bio) +ata_raid_init_request(device_t dev, struct ar_softc *rdp, struct bio *bio) { struct ata_request *request; - if (!(request = ata_alloc_request())) { + if (!(request = ata_alloc_request(dev))) { printf("FAILURE - out of memory in ata_raid_init_request\n"); return NULL; } @@ -4095,13 +4099,12 @@ ata_raid_rw(device_t dev, u_int64_t lba, void *data, u_int bcount, int flags) return ENOMEM; } - if (!(request = ata_alloc_request())) { + if (!(request = ata_alloc_request(dev))) { device_printf(dev, "FAILURE - out of memory in ata_raid_rw\n"); return ENOMEM; } /* setup request */ - request->dev = dev; request->timeout = 10; request->retries = 0; request->data = data; diff --git a/sys/dev/ata/atapi-cam.c b/sys/dev/ata/atapi-cam.c index d8f0b86..6e4a2ab 100644 --- a/sys/dev/ata/atapi-cam.c +++ b/sys/dev/ata/atapi-cam.c @@ -531,7 +531,7 @@ atapi_action(struct cam_sim *sim, union ccb *ccb) printf("cannot allocate ATAPI/CAM hcb\n"); goto action_oom; } - if ((request = ata_alloc_request()) == NULL) { + if ((request = ata_alloc_request(softc->atadev[tid]->dev)) == NULL) { printf("cannot allocate ATAPI/CAM request\n"); goto action_oom; } @@ -618,7 +618,6 @@ atapi_action(struct cam_sim *sim, union ccb *ccb) goto action_oom; } } - request->dev = softc->atadev[tid]->dev; request->driver = hcb; request->data = buf; request->bytecount = len; diff --git a/sys/dev/ata/atapi-cd.c b/sys/dev/ata/atapi-cd.c index a64cfeb..f9fcf97 100644 --- a/sys/dev/ata/atapi-cd.c +++ b/sys/dev/ata/atapi-cd.c @@ -691,13 +691,11 @@ acd_geom_access(struct g_provider *pp, int dr, int dw, int de) 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int timeout = 60, track; - if (!(request = ata_alloc_request())) + if (!(request = ata_alloc_request(dev))) return ENOMEM; /* wait if drive is not finished loading the medium */ while (timeout--) { - bzero(request, sizeof(struct ata_request)); - request->dev = dev; bcopy(ccb, request->u.atapi.ccb, 16); request->flags = ATA_R_ATAPI; request->timeout = 5; @@ -857,11 +855,10 @@ acd_strategy(struct bio *bp) ccb[7] = count>>8; ccb[8] = count; - if (!(request = ata_alloc_request())) { + if (!(request = ata_alloc_request(dev))) { g_io_deliver(bp, ENOMEM); return; } - request->dev = dev; request->bio = bp; bcopy(ccb, request->u.atapi.ccb, (atadev->param.config & ATA_PROTO_MASK) == @@ -1221,10 +1218,9 @@ acd_get_progress(device_t dev, int *finished) struct ata_request *request; int8_t dummy[8]; - if (!(request = ata_alloc_request())) + if (!(request = ata_alloc_request(dev))) return ENOMEM; - request->dev = dev; bcopy(ccb, request->u.atapi.ccb, 16); request->data = dummy; request->bytecount = sizeof(dummy); diff --git a/sys/dev/ata/atapi-fd.c b/sys/dev/ata/atapi-fd.c index 9a26399..45a1b17 100644 --- a/sys/dev/ata/atapi-fd.c +++ b/sys/dev/ata/atapi-fd.c @@ -233,11 +233,10 @@ afd_strategy(struct bio *bp) ccb[7] = count>>8; ccb[8] = count; - if (!(request = ata_alloc_request())) { + if (!(request = ata_alloc_request(dev))) { biofinish(bp, NULL, ENOMEM); return; } - request->dev = dev; request->bio = bp; bcopy(ccb, request->u.atapi.ccb, (atadev->param.config & ATA_PROTO_MASK) == diff --git a/sys/dev/ata/atapi-tape.c b/sys/dev/ata/atapi-tape.c index 3304907..aa65226 100644 --- a/sys/dev/ata/atapi-tape.c +++ b/sys/dev/ata/atapi-tape.c @@ -421,11 +421,10 @@ ast_strategy(struct bio *bp) ccb[3] = blkcount >> 8; ccb[4] = blkcount; - if (!(request = ata_alloc_request())) { + if (!(request = ata_alloc_request(dev))) { biofinish(bp, NULL, ENOMEM); return; } - request->dev = dev; request->driver = bp; bcopy(ccb, request->u.atapi.ccb, (atadev->param.config & ATA_PROTO_MASK) == |