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/ips/ips_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  * Written by: David Jeffery
    3  * Copyright (c) 2002 Adaptec Inc.
    4  * All rights reserved.
    5  *
    6  * Redistribution and use in source and binary forms, with or without
    7  * modification, are permitted provided that the following conditions
    8  * are met:
    9  * 1. Redistributions of source code must retain the above copyright
   10  *    notice, this list of conditions and the following disclaimer.
   11  * 2. Redistributions in binary form must reproduce the above copyright
   12  *    notice, this list of conditions and the following disclaimer in the
   13  *    documentation and/or other materials provided with the distribution.
   14  *
   15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   25  * SUCH DAMAGE.
   26  */
   27 
   28 #include <sys/cdefs.h>
   29 __FBSDID("$FreeBSD: releng/5.3/sys/dev/ips/ips_disk.c 126364 2004-02-28 19:14:41Z scottl $");
   30 
   31 #include <dev/ips/ips.h>
   32 #include <dev/ips/ips_disk.h>
   33 #include <sys/stat.h>
   34 
   35 static int ipsd_probe(device_t dev);
   36 static int ipsd_attach(device_t dev);
   37 static int ipsd_detach(device_t dev);
   38 
   39 static disk_open_t ipsd_open;
   40 static disk_close_t ipsd_close;
   41 static disk_strategy_t ipsd_strategy;
   42 
   43 static device_method_t ipsd_methods[] = {
   44         DEVMETHOD(device_probe,         ipsd_probe),
   45         DEVMETHOD(device_attach,        ipsd_attach),
   46         DEVMETHOD(device_detach,        ipsd_detach),
   47         { 0, 0 }
   48 };
   49 
   50 
   51 static driver_t ipsd_driver = {
   52         "ipsd",
   53         ipsd_methods,
   54         sizeof(ipsdisk_softc_t)
   55 };
   56 
   57 static devclass_t ipsd_devclass;
   58 DRIVER_MODULE(ipsd, ips, ipsd_driver, ipsd_devclass, 0, 0);
   59 
   60 /* handle opening of disk device.  It must set up all
   61    information about the geometry and size of the disk */
   62 static int ipsd_open(struct disk *dp)
   63 {
   64         ipsdisk_softc_t *dsc = dp->d_drv1;
   65 
   66         dsc->state |= IPS_DEV_OPEN;
   67         DEVICE_PRINTF(2, dsc->dev, "I'm open\n");
   68         return 0;
   69 }
   70 
   71 static int ipsd_close(struct disk *dp)
   72 {
   73         ipsdisk_softc_t *dsc = dp->d_drv1;
   74         dsc->state &= ~IPS_DEV_OPEN;
   75         DEVICE_PRINTF(2, dsc->dev, "I'm closed for the day\n");
   76         return 0;
   77 }
   78 
   79 /* ipsd_finish is called to clean up and return a completed IO request */
   80 void ipsd_finish(struct bio *iobuf)
   81 {
   82         ipsdisk_softc_t *dsc;
   83         dsc = iobuf->bio_disk->d_drv1;  
   84 
   85         if (iobuf->bio_flags & BIO_ERROR) {
   86                 ipsdisk_softc_t *dsc;
   87                 dsc = iobuf->bio_disk->d_drv1; 
   88                 device_printf(dsc->dev, "iobuf error %d\n", iobuf->bio_error);
   89         } else
   90                 iobuf->bio_resid = 0;
   91 
   92         biodone(iobuf); 
   93         ips_start_io_request(dsc->sc);
   94 }
   95 
   96 
   97 static void ipsd_strategy(struct bio *iobuf)
   98 {
   99         ipsdisk_softc_t *dsc;
  100 
  101         dsc = iobuf->bio_disk->d_drv1;  
  102         DEVICE_PRINTF(8,dsc->dev,"in strategy\n");
  103         iobuf->bio_driver1 = (void *)(uintptr_t)dsc->sc->drives[dsc->disk_number].drivenum;
  104         mtx_lock(&dsc->sc->queue_mtx);
  105         bioq_disksort(&dsc->sc->queue, iobuf);
  106         mtx_unlock(&dsc->sc->queue_mtx);
  107         ips_start_io_request(dsc->sc);
  108 }
  109 
  110 static int ipsd_probe(device_t dev)
  111 {
  112         DEVICE_PRINTF(2,dev, "in probe\n");
  113         device_set_desc(dev, "Logical Drive");
  114         return 0;
  115 }
  116 
  117 static int ipsd_attach(device_t dev)
  118 {
  119         device_t adapter;
  120         ipsdisk_softc_t *dsc;
  121         u_int totalsectors;
  122 
  123         DEVICE_PRINTF(2,dev, "in attach\n");
  124 
  125         dsc = (ipsdisk_softc_t *)device_get_softc(dev);
  126         bzero(dsc, sizeof(ipsdisk_softc_t));
  127         adapter = device_get_parent(dev);
  128         dsc->dev = dev;
  129         dsc->sc = device_get_softc(adapter);
  130         dsc->unit = device_get_unit(dev);
  131         dsc->disk_number = (uintptr_t) device_get_ivars(dev);
  132         dsc->ipsd_disk = disk_alloc();
  133         dsc->ipsd_disk->d_drv1 = dsc;
  134         dsc->ipsd_disk->d_name = "ipsd";
  135         dsc->ipsd_disk->d_maxsize = IPS_MAX_IO_SIZE;
  136         dsc->ipsd_disk->d_open = ipsd_open;
  137         dsc->ipsd_disk->d_close = ipsd_close;
  138         dsc->ipsd_disk->d_strategy = ipsd_strategy;
  139 
  140         totalsectors = dsc->sc->drives[dsc->disk_number].sector_count;
  141         if ((totalsectors > 0x400000) &&
  142                         ((dsc->sc->adapter_info.miscflags & 0x8) == 0)) {
  143                 dsc->ipsd_disk->d_fwheads = IPS_NORM_HEADS;
  144                 dsc->ipsd_disk->d_fwsectors = IPS_NORM_SECTORS;
  145         } else {
  146                 dsc->ipsd_disk->d_fwheads = IPS_COMP_HEADS;
  147                 dsc->ipsd_disk->d_fwsectors = IPS_COMP_SECTORS;
  148         }
  149         dsc->ipsd_disk->d_sectorsize = IPS_BLKSIZE;
  150         dsc->ipsd_disk->d_mediasize = (off_t)totalsectors * IPS_BLKSIZE;
  151         dsc->ipsd_disk->d_unit = dsc->unit;
  152         dsc->ipsd_disk->d_flags = DISKFLAG_NEEDSGIANT;
  153         disk_create(dsc->ipsd_disk, DISK_VERSION);
  154 
  155         device_printf(dev, "Logical Drive  (%dMB)\n",
  156                       dsc->sc->drives[dsc->disk_number].sector_count >> 11);
  157         return 0;
  158 }
  159 
  160 static int ipsd_detach(device_t dev)
  161 {
  162         ipsdisk_softc_t *dsc;
  163 
  164         DEVICE_PRINTF(2, dev,"in detach\n");
  165         dsc = (ipsdisk_softc_t *)device_get_softc(dev);
  166         if(dsc->state & IPS_DEV_OPEN)
  167                 return (EBUSY);
  168         disk_destroy(dsc->ipsd_disk);
  169         return 0;
  170 }

Cache object: 7c0c46bfd716403075a43ee4ed6a326d


[ 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.