The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/dev/mfi/mfi_disk.c

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 2006 IronPort Systems
    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  */
   26 
   27 #include <sys/cdefs.h>
   28 __FBSDID("$FreeBSD: releng/10.0/sys/dev/mfi/mfi_disk.c 248627 2013-03-22 22:46:19Z delphij $");
   29 
   30 #include "opt_mfi.h"
   31 
   32 #include <sys/param.h>
   33 #include <sys/systm.h>
   34 #include <sys/kernel.h>
   35 #include <sys/selinfo.h>
   36 #include <sys/module.h>
   37 #include <sys/malloc.h>
   38 #include <sys/sysctl.h>
   39 #include <sys/uio.h>
   40 
   41 #include <sys/bio.h>
   42 #include <sys/bus.h>
   43 #include <sys/conf.h>
   44 #include <sys/disk.h>
   45 #include <geom/geom_disk.h>
   46 
   47 #include <vm/vm.h>
   48 #include <vm/pmap.h>
   49 
   50 #include <machine/md_var.h>
   51 #include <machine/bus.h>
   52 #include <sys/rman.h>
   53 
   54 #include <dev/mfi/mfireg.h>
   55 #include <dev/mfi/mfi_ioctl.h>
   56 #include <dev/mfi/mfivar.h>
   57 
   58 static int      mfi_disk_probe(device_t dev);
   59 static int      mfi_disk_attach(device_t dev);
   60 static int      mfi_disk_detach(device_t dev);
   61 
   62 static disk_open_t      mfi_disk_open;
   63 static disk_close_t     mfi_disk_close;
   64 static disk_strategy_t  mfi_disk_strategy;
   65 static dumper_t         mfi_disk_dump;
   66 
   67 static devclass_t       mfi_disk_devclass;
   68 
   69 static device_method_t mfi_disk_methods[] = {
   70         DEVMETHOD(device_probe,         mfi_disk_probe),
   71         DEVMETHOD(device_attach,        mfi_disk_attach),
   72         DEVMETHOD(device_detach,        mfi_disk_detach),
   73         { 0, 0 }
   74 };
   75 
   76 static driver_t mfi_disk_driver = {
   77         "mfid",
   78         mfi_disk_methods,
   79         sizeof(struct mfi_disk)
   80 };
   81 
   82 DRIVER_MODULE(mfid, mfi, mfi_disk_driver, mfi_disk_devclass, 0, 0);
   83 
   84 static int
   85 mfi_disk_probe(device_t dev)
   86 {
   87 
   88         return (0);
   89 }
   90 
   91 static int
   92 mfi_disk_attach(device_t dev)
   93 {
   94         struct mfi_disk *sc;
   95         struct mfi_ld_info *ld_info;
   96         struct mfi_disk_pending *ld_pend;
   97         uint64_t sectors;
   98         uint32_t secsize;
   99         char *state;
  100 
  101         sc = device_get_softc(dev);
  102         ld_info = device_get_ivars(dev);
  103 
  104         sc->ld_dev = dev;
  105         sc->ld_id = ld_info->ld_config.properties.ld.v.target_id;
  106         sc->ld_unit = device_get_unit(dev);
  107         sc->ld_info = ld_info;
  108         sc->ld_controller = device_get_softc(device_get_parent(dev));
  109         sc->ld_flags = 0;
  110 
  111         sectors = ld_info->size;
  112         secsize = MFI_SECTOR_LEN;
  113         mtx_lock(&sc->ld_controller->mfi_io_lock);
  114         TAILQ_INSERT_TAIL(&sc->ld_controller->mfi_ld_tqh, sc, ld_link);
  115         TAILQ_FOREACH(ld_pend, &sc->ld_controller->mfi_ld_pend_tqh,
  116             ld_link) {
  117                 TAILQ_REMOVE(&sc->ld_controller->mfi_ld_pend_tqh,
  118                     ld_pend, ld_link);
  119                 free(ld_pend, M_MFIBUF);
  120                 break;
  121         }
  122         mtx_unlock(&sc->ld_controller->mfi_io_lock);
  123 
  124         switch (ld_info->ld_config.params.state) {
  125         case MFI_LD_STATE_OFFLINE:
  126                 state = "offline";
  127                 break;
  128         case MFI_LD_STATE_PARTIALLY_DEGRADED:
  129                 state = "partially degraded";
  130                 break;
  131         case MFI_LD_STATE_DEGRADED:
  132                 state = "degraded";
  133                 break;
  134         case MFI_LD_STATE_OPTIMAL:
  135                 state = "optimal";
  136                 break;
  137         default:
  138                 state = "unknown";
  139                 break;
  140         }
  141 
  142         if ( strlen(ld_info->ld_config.properties.name) == 0 ) {
  143                 device_printf(dev,
  144                       "%juMB (%ju sectors) RAID volume (no label) is %s\n",
  145                        sectors / (1024 * 1024 / secsize), sectors, state);
  146         } else {
  147                 device_printf(dev,
  148                       "%juMB (%ju sectors) RAID volume '%s' is %s\n",
  149                       sectors / (1024 * 1024 / secsize), sectors,
  150                       ld_info->ld_config.properties.name, state);
  151         }
  152 
  153         sc->ld_disk = disk_alloc();
  154         sc->ld_disk->d_drv1 = sc;
  155         sc->ld_disk->d_maxsize = min(sc->ld_controller->mfi_max_io * secsize,
  156             (sc->ld_controller->mfi_max_sge - 1) * PAGE_SIZE);
  157         sc->ld_disk->d_name = "mfid";
  158         sc->ld_disk->d_open = mfi_disk_open;
  159         sc->ld_disk->d_close = mfi_disk_close;
  160         sc->ld_disk->d_strategy = mfi_disk_strategy;
  161         sc->ld_disk->d_dump = mfi_disk_dump;
  162         sc->ld_disk->d_unit = sc->ld_unit;
  163         sc->ld_disk->d_sectorsize = secsize;
  164         sc->ld_disk->d_mediasize = sectors * secsize;
  165         if (sc->ld_disk->d_mediasize >= (1 * 1024 * 1024)) {
  166                 sc->ld_disk->d_fwheads = 255;
  167                 sc->ld_disk->d_fwsectors = 63;
  168         } else {
  169                 sc->ld_disk->d_fwheads = 64;
  170                 sc->ld_disk->d_fwsectors = 32;
  171         }
  172         disk_create(sc->ld_disk, DISK_VERSION);
  173 
  174         return (0);
  175 }
  176 
  177 static int
  178 mfi_disk_detach(device_t dev)
  179 {
  180         struct mfi_disk *sc;
  181 
  182         sc = device_get_softc(dev);
  183 
  184         mtx_lock(&sc->ld_controller->mfi_io_lock);
  185         if (((sc->ld_disk->d_flags & DISKFLAG_OPEN) ||
  186             (sc->ld_flags & MFI_DISK_FLAGS_OPEN)) &&
  187             (sc->ld_controller->mfi_keep_deleted_volumes ||
  188             sc->ld_controller->mfi_detaching)) {
  189                 mtx_unlock(&sc->ld_controller->mfi_io_lock);
  190                 return (EBUSY);
  191         }
  192         mtx_unlock(&sc->ld_controller->mfi_io_lock);
  193 
  194         disk_destroy(sc->ld_disk);
  195         mtx_lock(&sc->ld_controller->mfi_io_lock);
  196         TAILQ_REMOVE(&sc->ld_controller->mfi_ld_tqh, sc, ld_link);
  197         mtx_unlock(&sc->ld_controller->mfi_io_lock);
  198         free(sc->ld_info, M_MFIBUF);
  199         return (0);
  200 }
  201 
  202 static int
  203 mfi_disk_open(struct disk *dp)
  204 {
  205         struct mfi_disk *sc;
  206         int error;
  207 
  208         sc = dp->d_drv1;
  209         mtx_lock(&sc->ld_controller->mfi_io_lock);
  210         if (sc->ld_flags & MFI_DISK_FLAGS_DISABLED)
  211                 error = ENXIO;
  212         else {
  213                 sc->ld_flags |= MFI_DISK_FLAGS_OPEN;
  214                 error = 0;
  215         }
  216         mtx_unlock(&sc->ld_controller->mfi_io_lock);
  217 
  218         return (error);
  219 }
  220 
  221 static int
  222 mfi_disk_close(struct disk *dp)
  223 {
  224         struct mfi_disk *sc;
  225 
  226         sc = dp->d_drv1;
  227         mtx_lock(&sc->ld_controller->mfi_io_lock);
  228         sc->ld_flags &= ~MFI_DISK_FLAGS_OPEN;
  229         mtx_unlock(&sc->ld_controller->mfi_io_lock);
  230 
  231         return (0);
  232 }
  233 
  234 int
  235 mfi_disk_disable(struct mfi_disk *sc)
  236 {
  237 
  238         mtx_assert(&sc->ld_controller->mfi_io_lock, MA_OWNED);
  239         if (sc->ld_flags & MFI_DISK_FLAGS_OPEN) {
  240                 if (sc->ld_controller->mfi_delete_busy_volumes)
  241                         return (0);
  242                 device_printf(sc->ld_dev, "Unable to delete busy ld device\n");
  243                 return (EBUSY);
  244         }
  245         sc->ld_flags |= MFI_DISK_FLAGS_DISABLED;
  246         return (0);
  247 }
  248 
  249 void
  250 mfi_disk_enable(struct mfi_disk *sc)
  251 {
  252 
  253         mtx_assert(&sc->ld_controller->mfi_io_lock, MA_OWNED);
  254         sc->ld_flags &= ~MFI_DISK_FLAGS_DISABLED;
  255 }
  256 
  257 static void
  258 mfi_disk_strategy(struct bio *bio)
  259 {
  260         struct mfi_disk *sc;
  261         struct mfi_softc *controller;
  262 
  263         sc = bio->bio_disk->d_drv1;
  264 
  265         if (sc == NULL) {
  266                 bio->bio_error = EINVAL;
  267                 bio->bio_flags |= BIO_ERROR;
  268                 bio->bio_resid = bio->bio_bcount;
  269                 biodone(bio);
  270                 return;
  271         }
  272 
  273         controller = sc->ld_controller;
  274         if (controller->adpreset) {
  275                 bio->bio_error = EBUSY;
  276                 return;
  277         }
  278 
  279         if (controller->hw_crit_error) {
  280                 bio->bio_error = EBUSY;
  281                 return;
  282         }
  283 
  284         if (controller->issuepend_done == 0) {
  285                 bio->bio_error = EBUSY;
  286                 return;
  287         }
  288 
  289         bio->bio_driver1 = (void *)(uintptr_t)sc->ld_id;
  290         /* Mark it as LD IO */
  291         bio->bio_driver2 = (void *)MFI_LD_IO;
  292         mtx_lock(&controller->mfi_io_lock);
  293         mfi_enqueue_bio(controller, bio);
  294         mfi_startio(controller);
  295         mtx_unlock(&controller->mfi_io_lock);
  296         return;
  297 }
  298 
  299 void
  300 mfi_disk_complete(struct bio *bio)
  301 {
  302         struct mfi_disk *sc;
  303         struct mfi_frame_header *hdr;
  304 
  305         sc = bio->bio_disk->d_drv1;
  306         hdr = bio->bio_driver1;
  307 
  308         if (bio->bio_flags & BIO_ERROR) {
  309                 bio->bio_resid = bio->bio_bcount;
  310                 if (bio->bio_error == 0)
  311                         bio->bio_error = EIO;
  312                 disk_err(bio, "hard error", -1, 1);
  313         } else {
  314                 bio->bio_resid = 0;
  315         }
  316         biodone(bio);
  317 }
  318 
  319 static int
  320 mfi_disk_dump(void *arg, void *virt, vm_offset_t phys, off_t offset, size_t len)
  321 {
  322         struct mfi_disk *sc;
  323         struct mfi_softc *parent_sc;
  324         struct disk *dp;
  325         int error;
  326 
  327         dp = arg;
  328         sc = dp->d_drv1;
  329         parent_sc = sc->ld_controller;
  330 
  331         if (len > 0) {
  332                 if ((error = mfi_dump_blocks(parent_sc, sc->ld_id, offset /
  333                     MFI_SECTOR_LEN, virt, len)) != 0)
  334                         return (error);
  335         } else {
  336                 /* mfi_sync_cache(parent_sc, sc->ld_id); */
  337         }
  338 
  339         return (0);
  340 }

Cache object: a1fa282540d9ec01eb87ef6d3e5ad346


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.