1/*- 2 * Copyright (c) 1999 Jonathan Lemon 3 * Copyright (c) 1999, 2000 Michael Smith 4 * Copyright (c) 2000 BSDi 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28/* 29 * Copyright (c) 2002 Eric Moore 30 * Copyright (c) 2002 LSI Logic Corporation 31 * All rights reserved. 32 * 33 * Redistribution and use in source and binary forms, with or without 34 * modification, are permitted provided that the following conditions 35 * are met: 36 * 1. Redistributions of source code must retain the above copyright 37 * notice, this list of conditions and the following disclaimer. 38 * 2. Redistributions in binary form must reproduce the above copyright 39 * notice, this list of conditions and the following disclaimer in the 40 * documentation and/or other materials provided with the distribution. 41 * 3. The party using or redistributing the source code and binary forms 42 * agrees to the disclaimer below and the terms and conditions set forth 43 * herein. 44 * 45 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 46 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 47 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 48 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 49 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 51 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 53 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 54 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 55 * SUCH DAMAGE. 56 */ 57 58#include <sys/cdefs.h>
| 1/*- 2 * Copyright (c) 1999 Jonathan Lemon 3 * Copyright (c) 1999, 2000 Michael Smith 4 * Copyright (c) 2000 BSDi 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28/* 29 * Copyright (c) 2002 Eric Moore 30 * Copyright (c) 2002 LSI Logic Corporation 31 * All rights reserved. 32 * 33 * Redistribution and use in source and binary forms, with or without 34 * modification, are permitted provided that the following conditions 35 * are met: 36 * 1. Redistributions of source code must retain the above copyright 37 * notice, this list of conditions and the following disclaimer. 38 * 2. Redistributions in binary form must reproduce the above copyright 39 * notice, this list of conditions and the following disclaimer in the 40 * documentation and/or other materials provided with the distribution. 41 * 3. The party using or redistributing the source code and binary forms 42 * agrees to the disclaimer below and the terms and conditions set forth 43 * herein. 44 * 45 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 46 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 47 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 48 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 49 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 51 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 53 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 54 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 55 * SUCH DAMAGE. 56 */ 57 58#include <sys/cdefs.h>
|
59__FBSDID("$FreeBSD: head/sys/dev/amr/amr_disk.c 120988 2003-10-10 22:49:40Z ps $");
| 59__FBSDID("$FreeBSD: head/sys/dev/amr/amr_disk.c 125975 2004-02-18 21:36:53Z phk $");
|
60 61/* 62 * Disk driver for AMI MegaRaid controllers 63 */ 64 65#include <sys/param.h> 66#include <sys/systm.h> 67#include <sys/kernel.h> 68 69#include <dev/amr/amr_compat.h> 70#include <sys/bus.h> 71#include <sys/conf.h> 72 73#include <machine/bus.h> 74#include <sys/rman.h> 75 76#include <dev/amr/amrio.h> 77#include <dev/amr/amrreg.h> 78#include <dev/amr/amrvar.h> 79#include <dev/amr/amr_tables.h> 80 81/* prototypes */ 82static int amrd_probe(device_t dev); 83static int amrd_attach(device_t dev); 84static int amrd_detach(device_t dev); 85 86static disk_open_t amrd_open; 87static disk_strategy_t amrd_strategy; 88 89static devclass_t amrd_devclass; 90#ifdef FREEBSD_4 91static int disks_registered = 0; 92#endif 93 94static device_method_t amrd_methods[] = { 95 DEVMETHOD(device_probe, amrd_probe), 96 DEVMETHOD(device_attach, amrd_attach), 97 DEVMETHOD(device_detach, amrd_detach), 98 { 0, 0 } 99}; 100 101static driver_t amrd_driver = { 102 "amrd", 103 amrd_methods, 104 sizeof(struct amrd_softc) 105}; 106 107DRIVER_MODULE(amrd, amr, amrd_driver, amrd_devclass, 0, 0); 108 109static int 110amrd_open(struct disk *dp) 111{ 112 struct amrd_softc *sc = (struct amrd_softc *)dp->d_drv1; 113#if __FreeBSD_version < 500000 /* old buf style */ 114 struct disklabel *label; 115#endif 116 117 debug_called(1); 118 119 if (sc == NULL) 120 return (ENXIO); 121 122 /* controller not active? */ 123 if (sc->amrd_controller->amr_state & AMR_STATE_SHUTDOWN) 124 return(ENXIO); 125 126#if __FreeBSD_version < 500000 /* old buf style */ 127 label = &sc->amrd_disk.d_label; 128 bzero(label, sizeof(*label)); 129 label->d_type = DTYPE_SCSI; 130 label->d_secsize = AMR_BLKSIZE; 131 label->d_nsectors = sc->amrd_drive->al_sectors; 132 label->d_ntracks = sc->amrd_drive->al_heads; 133 label->d_ncylinders = sc->amrd_drive->al_cylinders; 134 label->d_secpercyl = sc->amrd_drive->al_sectors * sc->amrd_drive->al_heads; 135 label->d_secperunit = sc->amrd_drive->al_size; 136#else
| 60 61/* 62 * Disk driver for AMI MegaRaid controllers 63 */ 64 65#include <sys/param.h> 66#include <sys/systm.h> 67#include <sys/kernel.h> 68 69#include <dev/amr/amr_compat.h> 70#include <sys/bus.h> 71#include <sys/conf.h> 72 73#include <machine/bus.h> 74#include <sys/rman.h> 75 76#include <dev/amr/amrio.h> 77#include <dev/amr/amrreg.h> 78#include <dev/amr/amrvar.h> 79#include <dev/amr/amr_tables.h> 80 81/* prototypes */ 82static int amrd_probe(device_t dev); 83static int amrd_attach(device_t dev); 84static int amrd_detach(device_t dev); 85 86static disk_open_t amrd_open; 87static disk_strategy_t amrd_strategy; 88 89static devclass_t amrd_devclass; 90#ifdef FREEBSD_4 91static int disks_registered = 0; 92#endif 93 94static device_method_t amrd_methods[] = { 95 DEVMETHOD(device_probe, amrd_probe), 96 DEVMETHOD(device_attach, amrd_attach), 97 DEVMETHOD(device_detach, amrd_detach), 98 { 0, 0 } 99}; 100 101static driver_t amrd_driver = { 102 "amrd", 103 amrd_methods, 104 sizeof(struct amrd_softc) 105}; 106 107DRIVER_MODULE(amrd, amr, amrd_driver, amrd_devclass, 0, 0); 108 109static int 110amrd_open(struct disk *dp) 111{ 112 struct amrd_softc *sc = (struct amrd_softc *)dp->d_drv1; 113#if __FreeBSD_version < 500000 /* old buf style */ 114 struct disklabel *label; 115#endif 116 117 debug_called(1); 118 119 if (sc == NULL) 120 return (ENXIO); 121 122 /* controller not active? */ 123 if (sc->amrd_controller->amr_state & AMR_STATE_SHUTDOWN) 124 return(ENXIO); 125 126#if __FreeBSD_version < 500000 /* old buf style */ 127 label = &sc->amrd_disk.d_label; 128 bzero(label, sizeof(*label)); 129 label->d_type = DTYPE_SCSI; 130 label->d_secsize = AMR_BLKSIZE; 131 label->d_nsectors = sc->amrd_drive->al_sectors; 132 label->d_ntracks = sc->amrd_drive->al_heads; 133 label->d_ncylinders = sc->amrd_drive->al_cylinders; 134 label->d_secpercyl = sc->amrd_drive->al_sectors * sc->amrd_drive->al_heads; 135 label->d_secperunit = sc->amrd_drive->al_size; 136#else
|
137 sc->amrd_disk.d_sectorsize = AMR_BLKSIZE; 138 sc->amrd_disk.d_mediasize = (off_t)sc->amrd_drive->al_size * AMR_BLKSIZE; 139 sc->amrd_disk.d_fwsectors = sc->amrd_drive->al_sectors; 140 sc->amrd_disk.d_fwheads = sc->amrd_drive->al_heads;
| 137 sc->amrd_disk->d_sectorsize = AMR_BLKSIZE; 138 sc->amrd_disk->d_mediasize = (off_t)sc->amrd_drive->al_size * AMR_BLKSIZE; 139 sc->amrd_disk->d_fwsectors = sc->amrd_drive->al_sectors; 140 sc->amrd_disk->d_fwheads = sc->amrd_drive->al_heads;
|
141#endif 142 143 return (0); 144} 145/******************************************************************************** 146 * System crashdump support 147 */ 148 149static int 150amrd_dump(void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t length) 151{ 152 153 struct amrd_softc *amrd_sc; 154 struct amr_softc *amr_sc; 155 int error; 156 struct disk *dp; 157 158 dp = arg; 159 amrd_sc = (struct amrd_softc *)dp->d_drv1; 160 amr_sc = (struct amr_softc *)amrd_sc->amrd_controller; 161 if (!amrd_sc || !amr_sc) 162 return(ENXIO); 163 164 if (length > 0) { 165 int driveno = amrd_sc->amrd_drive - amr_sc->amr_drive; 166 if ((error = amr_dump_blocks(amr_sc,driveno,offset / AMR_BLKSIZE ,(void *)virtual,(int) length / AMR_BLKSIZE )) != 0) 167 return(error); 168 169 } 170 return(0); 171} 172 173/* 174 * Read/write routine for a buffer. Finds the proper unit, range checks 175 * arguments, and schedules the transfer. Does not wait for the transfer 176 * to complete. Multi-page transfers are supported. All I/O requests must 177 * be a multiple of a sector in length. 178 */ 179static void 180amrd_strategy(struct bio *bio) 181{ 182 struct amrd_softc *sc = (struct amrd_softc *)bio->bio_disk->d_drv1; 183 184 /* bogus disk? */ 185 if (sc == NULL) { 186 bio->bio_error = EINVAL; 187 goto bad; 188 } 189 190 amr_submit_bio(sc->amrd_controller, bio); 191 return; 192 193 bad: 194 bio->bio_flags |= BIO_ERROR; 195 196 /* 197 * Correctly set the buf to indicate a completed transfer 198 */ 199 bio->bio_resid = bio->bio_bcount; 200 biodone(bio); 201 return; 202} 203 204void 205amrd_intr(void *data) 206{ 207 struct bio *bio = (struct bio *)data; 208 209 debug_called(2); 210 211 if (bio->bio_flags & BIO_ERROR) { 212 bio->bio_error = EIO; 213 debug(1, "i/o error\n"); 214 } else { 215 bio->bio_resid = 0; 216 } 217 218 AMR_BIO_FINISH(bio); 219} 220 221static int 222amrd_probe(device_t dev) 223{ 224 225 debug_called(1); 226 227 device_set_desc(dev, "LSILogic MegaRAID logical drive"); 228 return (0); 229} 230 231static int 232amrd_attach(device_t dev) 233{ 234 struct amrd_softc *sc = (struct amrd_softc *)device_get_softc(dev); 235 device_t parent; 236 237 debug_called(1); 238 239 parent = device_get_parent(dev); 240 sc->amrd_controller = (struct amr_softc *)device_get_softc(parent); 241 sc->amrd_unit = device_get_unit(dev); 242 sc->amrd_drive = device_get_ivars(dev); 243 sc->amrd_dev = dev; 244 245 device_printf(dev, "%uMB (%u sectors) RAID %d (%s)\n", 246 sc->amrd_drive->al_size / ((1024 * 1024) / AMR_BLKSIZE), 247 sc->amrd_drive->al_size, sc->amrd_drive->al_properties & AMR_DRV_RAID_MASK, 248 amr_describe_code(amr_table_drvstate, AMR_DRV_CURSTATE(sc->amrd_drive->al_state))); 249
| 141#endif 142 143 return (0); 144} 145/******************************************************************************** 146 * System crashdump support 147 */ 148 149static int 150amrd_dump(void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t length) 151{ 152 153 struct amrd_softc *amrd_sc; 154 struct amr_softc *amr_sc; 155 int error; 156 struct disk *dp; 157 158 dp = arg; 159 amrd_sc = (struct amrd_softc *)dp->d_drv1; 160 amr_sc = (struct amr_softc *)amrd_sc->amrd_controller; 161 if (!amrd_sc || !amr_sc) 162 return(ENXIO); 163 164 if (length > 0) { 165 int driveno = amrd_sc->amrd_drive - amr_sc->amr_drive; 166 if ((error = amr_dump_blocks(amr_sc,driveno,offset / AMR_BLKSIZE ,(void *)virtual,(int) length / AMR_BLKSIZE )) != 0) 167 return(error); 168 169 } 170 return(0); 171} 172 173/* 174 * Read/write routine for a buffer. Finds the proper unit, range checks 175 * arguments, and schedules the transfer. Does not wait for the transfer 176 * to complete. Multi-page transfers are supported. All I/O requests must 177 * be a multiple of a sector in length. 178 */ 179static void 180amrd_strategy(struct bio *bio) 181{ 182 struct amrd_softc *sc = (struct amrd_softc *)bio->bio_disk->d_drv1; 183 184 /* bogus disk? */ 185 if (sc == NULL) { 186 bio->bio_error = EINVAL; 187 goto bad; 188 } 189 190 amr_submit_bio(sc->amrd_controller, bio); 191 return; 192 193 bad: 194 bio->bio_flags |= BIO_ERROR; 195 196 /* 197 * Correctly set the buf to indicate a completed transfer 198 */ 199 bio->bio_resid = bio->bio_bcount; 200 biodone(bio); 201 return; 202} 203 204void 205amrd_intr(void *data) 206{ 207 struct bio *bio = (struct bio *)data; 208 209 debug_called(2); 210 211 if (bio->bio_flags & BIO_ERROR) { 212 bio->bio_error = EIO; 213 debug(1, "i/o error\n"); 214 } else { 215 bio->bio_resid = 0; 216 } 217 218 AMR_BIO_FINISH(bio); 219} 220 221static int 222amrd_probe(device_t dev) 223{ 224 225 debug_called(1); 226 227 device_set_desc(dev, "LSILogic MegaRAID logical drive"); 228 return (0); 229} 230 231static int 232amrd_attach(device_t dev) 233{ 234 struct amrd_softc *sc = (struct amrd_softc *)device_get_softc(dev); 235 device_t parent; 236 237 debug_called(1); 238 239 parent = device_get_parent(dev); 240 sc->amrd_controller = (struct amr_softc *)device_get_softc(parent); 241 sc->amrd_unit = device_get_unit(dev); 242 sc->amrd_drive = device_get_ivars(dev); 243 sc->amrd_dev = dev; 244 245 device_printf(dev, "%uMB (%u sectors) RAID %d (%s)\n", 246 sc->amrd_drive->al_size / ((1024 * 1024) / AMR_BLKSIZE), 247 sc->amrd_drive->al_size, sc->amrd_drive->al_properties & AMR_DRV_RAID_MASK, 248 amr_describe_code(amr_table_drvstate, AMR_DRV_CURSTATE(sc->amrd_drive->al_state))); 249
|
250 sc->amrd_disk.d_drv1 = sc; 251 sc->amrd_disk.d_maxsize = (AMR_NSEG - 1) * PAGE_SIZE; 252 sc->amrd_disk.d_open = amrd_open; 253 sc->amrd_disk.d_strategy = amrd_strategy; 254 sc->amrd_disk.d_name = "amrd"; 255 sc->amrd_disk.d_dump = (dumper_t *)amrd_dump; 256 disk_create(sc->amrd_unit, &sc->amrd_disk, 0, NULL, NULL);
| 250 sc->amrd_disk = disk_alloc(); 251 sc->amrd_disk->d_drv1 = sc; 252 sc->amrd_disk->d_maxsize = (AMR_NSEG - 1) * PAGE_SIZE; 253 sc->amrd_disk->d_open = amrd_open; 254 sc->amrd_disk->d_strategy = amrd_strategy; 255 sc->amrd_disk->d_name = "amrd"; 256 sc->amrd_disk->d_dump = (dumper_t *)amrd_dump; 257 sc->amrd_disk->d_unit = sc->amrd_unit; 258 sc->amrd_disk->d_flags = DISKFLAG_NEEDSGIANT; 259 disk_create(sc->amrd_disk, DISK_VERSION);
|
257#ifdef FREEBSD_4 258 disks_registered++; 259#endif 260 261 return (0); 262} 263 264static int 265amrd_detach(device_t dev) 266{ 267 struct amrd_softc *sc = (struct amrd_softc *)device_get_softc(dev); 268 269 debug_called(1); 270
| 260#ifdef FREEBSD_4 261 disks_registered++; 262#endif 263 264 return (0); 265} 266 267static int 268amrd_detach(device_t dev) 269{ 270 struct amrd_softc *sc = (struct amrd_softc *)device_get_softc(dev); 271 272 debug_called(1); 273
|
271 if (sc->amrd_disk.d_flags & DISKFLAG_OPEN)
| 274 if (sc->amrd_disk->d_flags & DISKFLAG_OPEN)
|
272 return(EBUSY); 273 274#ifdef FREEBSD_4 275 if (--disks_registered == 0) 276 cdevsw_remove(&amrddisk_cdevsw); 277#else
| 275 return(EBUSY); 276 277#ifdef FREEBSD_4 278 if (--disks_registered == 0) 279 cdevsw_remove(&amrddisk_cdevsw); 280#else
|
278 disk_destroy(&sc->amrd_disk);
| 281 disk_destroy(sc->amrd_disk);
|
279#endif 280 return(0); 281} 282
| 282#endif 283 return(0); 284} 285
|