1/*- 2 * Copyright (c) 1999,2000 Jonathan Lemon 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 *
| 1/*- 2 * Copyright (c) 1999,2000 Jonathan Lemon 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 *
|
27 */ 28 29/* 30 * Disk driver for Compaq SMART RAID adapters. 31 */ 32 33#include <sys/param.h> 34#include <sys/systm.h> 35#include <sys/kernel.h> 36 37#include <sys/bio.h> 38#include <sys/bus.h> 39#include <sys/conf.h> 40#include <sys/cons.h> 41 42#include <machine/bus_memio.h> 43#include <machine/bus_pio.h> 44#include <machine/bus.h> 45#include <sys/rman.h> 46 47#include <vm/vm.h> 48#include <vm/pmap.h> 49#include <machine/md_var.h> 50 51#include <geom/geom_disk.h> 52 53#include <dev/ida/idareg.h> 54#include <dev/ida/idavar.h> 55 56/* prototypes */ 57static int idad_probe(device_t dev); 58static int idad_attach(device_t dev); 59static int idad_detach(device_t dev); 60 61static d_strategy_t idad_strategy; 62static dumper_t idad_dump; 63 64static devclass_t idad_devclass; 65 66static device_method_t idad_methods[] = { 67 DEVMETHOD(device_probe, idad_probe), 68 DEVMETHOD(device_attach, idad_attach), 69 DEVMETHOD(device_detach, idad_detach), 70 { 0, 0 } 71}; 72 73static driver_t idad_driver = { 74 "idad", 75 idad_methods, 76 sizeof(struct idad_softc) 77}; 78 79DRIVER_MODULE(idad, ida, idad_driver, idad_devclass, 0, 0); 80 81/* 82 * Read/write routine for a buffer. Finds the proper unit, range checks 83 * arguments, and schedules the transfer. Does not wait for the transfer 84 * to complete. Multi-page transfers are supported. All I/O requests must 85 * be a multiple of a sector in length. 86 */ 87static void 88idad_strategy(struct bio *bp) 89{ 90 struct idad_softc *drv; 91 int s; 92 93 drv = bp->bio_disk->d_drv1; 94 if (drv == NULL) { 95 bp->bio_error = EINVAL; 96 goto bad; 97 } 98 99 /* 100 * software write protect check 101 */ 102 if (drv->flags & DRV_WRITEPROT && (bp->bio_cmd == BIO_WRITE)) { 103 bp->bio_error = EROFS; 104 goto bad; 105 } 106 107 bp->bio_driver1 = drv; 108 s = splbio(); 109 ida_submit_buf(drv->controller, bp); 110 splx(s); 111 return; 112 113bad: 114 bp->bio_flags |= BIO_ERROR; 115 116 /* 117 * Correctly set the buf to indicate a completed transfer 118 */ 119 bp->bio_resid = bp->bio_bcount; 120 biodone(bp); 121 return; 122} 123 124static int 125idad_dump(void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t length) 126{ 127 128 struct idad_softc *drv; 129 int error = 0; 130 struct disk *dp; 131 132 dp = arg; 133 drv = dp->d_drv1; 134 if (drv == NULL) 135 return (ENXIO); 136 137 drv->controller->flags &= ~IDA_INTERRUPTS; 138 139 if (length > 0) { 140 error = ida_command(drv->controller, CMD_WRITE, virtual, 141 length, drv->drive, offset / DEV_BSIZE, DMA_DATA_OUT); 142 } 143 drv->controller->flags |= IDA_INTERRUPTS; 144 return (error); 145} 146 147void 148idad_intr(struct bio *bp) 149{ 150 struct idad_softc *drv; 151 152 drv = bp->bio_disk->d_drv1; 153 154 if (bp->bio_flags & BIO_ERROR) 155 bp->bio_error = EIO; 156 else 157 bp->bio_resid = 0; 158 159 biodone(bp); 160} 161 162static int 163idad_probe(device_t dev) 164{ 165 166 device_set_desc(dev, "Compaq Logical Drive"); 167 return (0); 168} 169 170static int 171idad_attach(device_t dev) 172{ 173 struct ida_drive_info dinfo; 174 struct idad_softc *drv; 175 device_t parent; 176 int error; 177 178 drv = (struct idad_softc *)device_get_softc(dev); 179 parent = device_get_parent(dev); 180 drv->dev = dev; 181 drv->controller = (struct ida_softc *)device_get_softc(parent); 182 drv->unit = device_get_unit(dev); 183 drv->drive = drv->controller->num_drives; 184 drv->controller->num_drives++; 185 186 error = ida_command(drv->controller, CMD_GET_LOG_DRV_INFO, 187 &dinfo, sizeof(dinfo), drv->drive, 0, DMA_DATA_IN); 188 if (error) { 189 device_printf(dev, "CMD_GET_LOG_DRV_INFO failed\n"); 190 return (ENXIO); 191 } 192 193 drv->cylinders = dinfo.dp.ncylinders; 194 drv->heads = dinfo.dp.nheads; 195 drv->sectors = dinfo.dp.nsectors; 196 drv->secsize = dinfo.secsize == 0 ? 512 : dinfo.secsize; 197 drv->secperunit = dinfo.secperunit; 198 199 /* XXX 200 * other initialization 201 */ 202 device_printf(dev, "%uMB (%u sectors), blocksize=%d\n", 203 drv->secperunit / ((1024 * 1024) / drv->secsize), 204 drv->secperunit, drv->secsize); 205
| 27 */ 28 29/* 30 * Disk driver for Compaq SMART RAID adapters. 31 */ 32 33#include <sys/param.h> 34#include <sys/systm.h> 35#include <sys/kernel.h> 36 37#include <sys/bio.h> 38#include <sys/bus.h> 39#include <sys/conf.h> 40#include <sys/cons.h> 41 42#include <machine/bus_memio.h> 43#include <machine/bus_pio.h> 44#include <machine/bus.h> 45#include <sys/rman.h> 46 47#include <vm/vm.h> 48#include <vm/pmap.h> 49#include <machine/md_var.h> 50 51#include <geom/geom_disk.h> 52 53#include <dev/ida/idareg.h> 54#include <dev/ida/idavar.h> 55 56/* prototypes */ 57static int idad_probe(device_t dev); 58static int idad_attach(device_t dev); 59static int idad_detach(device_t dev); 60 61static d_strategy_t idad_strategy; 62static dumper_t idad_dump; 63 64static devclass_t idad_devclass; 65 66static device_method_t idad_methods[] = { 67 DEVMETHOD(device_probe, idad_probe), 68 DEVMETHOD(device_attach, idad_attach), 69 DEVMETHOD(device_detach, idad_detach), 70 { 0, 0 } 71}; 72 73static driver_t idad_driver = { 74 "idad", 75 idad_methods, 76 sizeof(struct idad_softc) 77}; 78 79DRIVER_MODULE(idad, ida, idad_driver, idad_devclass, 0, 0); 80 81/* 82 * Read/write routine for a buffer. Finds the proper unit, range checks 83 * arguments, and schedules the transfer. Does not wait for the transfer 84 * to complete. Multi-page transfers are supported. All I/O requests must 85 * be a multiple of a sector in length. 86 */ 87static void 88idad_strategy(struct bio *bp) 89{ 90 struct idad_softc *drv; 91 int s; 92 93 drv = bp->bio_disk->d_drv1; 94 if (drv == NULL) { 95 bp->bio_error = EINVAL; 96 goto bad; 97 } 98 99 /* 100 * software write protect check 101 */ 102 if (drv->flags & DRV_WRITEPROT && (bp->bio_cmd == BIO_WRITE)) { 103 bp->bio_error = EROFS; 104 goto bad; 105 } 106 107 bp->bio_driver1 = drv; 108 s = splbio(); 109 ida_submit_buf(drv->controller, bp); 110 splx(s); 111 return; 112 113bad: 114 bp->bio_flags |= BIO_ERROR; 115 116 /* 117 * Correctly set the buf to indicate a completed transfer 118 */ 119 bp->bio_resid = bp->bio_bcount; 120 biodone(bp); 121 return; 122} 123 124static int 125idad_dump(void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t length) 126{ 127 128 struct idad_softc *drv; 129 int error = 0; 130 struct disk *dp; 131 132 dp = arg; 133 drv = dp->d_drv1; 134 if (drv == NULL) 135 return (ENXIO); 136 137 drv->controller->flags &= ~IDA_INTERRUPTS; 138 139 if (length > 0) { 140 error = ida_command(drv->controller, CMD_WRITE, virtual, 141 length, drv->drive, offset / DEV_BSIZE, DMA_DATA_OUT); 142 } 143 drv->controller->flags |= IDA_INTERRUPTS; 144 return (error); 145} 146 147void 148idad_intr(struct bio *bp) 149{ 150 struct idad_softc *drv; 151 152 drv = bp->bio_disk->d_drv1; 153 154 if (bp->bio_flags & BIO_ERROR) 155 bp->bio_error = EIO; 156 else 157 bp->bio_resid = 0; 158 159 biodone(bp); 160} 161 162static int 163idad_probe(device_t dev) 164{ 165 166 device_set_desc(dev, "Compaq Logical Drive"); 167 return (0); 168} 169 170static int 171idad_attach(device_t dev) 172{ 173 struct ida_drive_info dinfo; 174 struct idad_softc *drv; 175 device_t parent; 176 int error; 177 178 drv = (struct idad_softc *)device_get_softc(dev); 179 parent = device_get_parent(dev); 180 drv->dev = dev; 181 drv->controller = (struct ida_softc *)device_get_softc(parent); 182 drv->unit = device_get_unit(dev); 183 drv->drive = drv->controller->num_drives; 184 drv->controller->num_drives++; 185 186 error = ida_command(drv->controller, CMD_GET_LOG_DRV_INFO, 187 &dinfo, sizeof(dinfo), drv->drive, 0, DMA_DATA_IN); 188 if (error) { 189 device_printf(dev, "CMD_GET_LOG_DRV_INFO failed\n"); 190 return (ENXIO); 191 } 192 193 drv->cylinders = dinfo.dp.ncylinders; 194 drv->heads = dinfo.dp.nheads; 195 drv->sectors = dinfo.dp.nsectors; 196 drv->secsize = dinfo.secsize == 0 ? 512 : dinfo.secsize; 197 drv->secperunit = dinfo.secperunit; 198 199 /* XXX 200 * other initialization 201 */ 202 device_printf(dev, "%uMB (%u sectors), blocksize=%d\n", 203 drv->secperunit / ((1024 * 1024) / drv->secsize), 204 drv->secperunit, drv->secsize); 205
|