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-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 2002 Adaptec Inc.
    3  * All rights reserved.
    4  *
    5  * Written by: David Jeffery
    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  * $FreeBSD: releng/5.1/sys/dev/ips/ips_disk.c 114902 2003-05-11 06:36:49Z scottl $
   29  */
   30 
   31 
   32 #include <dev/ips/ips.h>
   33 #include <dev/ips/ips_disk.h>
   34 #include <sys/stat.h>
   35 
   36 static int ipsd_probe(device_t dev);
   37 static int ipsd_attach(device_t dev);
   38 static int ipsd_detach(device_t dev);
   39 
   40 static disk_open_t ipsd_open;
   41 static disk_close_t ipsd_close;
   42 static disk_strategy_t ipsd_strategy;
   43 
   44 static device_method_t ipsd_methods[] = {
   45         DEVMETHOD(device_probe,         ipsd_probe),
   46         DEVMETHOD(device_attach,        ipsd_attach),
   47         DEVMETHOD(device_detach,        ipsd_detach),
   48         { 0, 0 }
   49 };
   50 
   51 
   52 static driver_t ipsd_driver = {
   53         "ipsd",
   54         ipsd_methods,
   55         sizeof(ipsdisk_softc_t)
   56 };
   57 
   58 static devclass_t ipsd_devclass;
   59 DRIVER_MODULE(ipsd, ips, ipsd_driver, ipsd_devclass, 0, 0);
   60 
   61 /* handle opening of disk device.  It must set up all
   62    information about the geometry and size of the disk */
   63 static int ipsd_open(struct disk *dp)
   64 {
   65         ipsdisk_softc_t *dsc = dp->d_drv1;
   66 
   67         dsc->state |= IPS_DEV_OPEN;
   68         DEVICE_PRINTF(2, dsc->dev, "I'm open\n");
   69         return 0;
   70 }
   71 
   72 static int ipsd_close(struct disk *dp)
   73 {
   74         ipsdisk_softc_t *dsc = dp->d_drv1;
   75         dsc->state &= ~IPS_DEV_OPEN;
   76         DEVICE_PRINTF(2, dsc->dev, "I'm closed for the day\n");
   77         return 0;
   78 }
   79 
   80 /* ipsd_finish is called to clean up and return a completed IO request */
   81 void ipsd_finish(struct bio *iobuf)
   82 {
   83         if (iobuf->bio_flags & BIO_ERROR) {
   84                 ipsdisk_softc_t *dsc;
   85                 dsc = iobuf->bio_disk->d_drv1; 
   86                 device_printf(dsc->dev, "iobuf error %d\n", iobuf->bio_error);
   87         } else
   88                 iobuf->bio_resid = 0;
   89 
   90         biodone(iobuf); 
   91 }
   92 
   93 
   94 static void ipsd_strategy(struct bio *iobuf)
   95 {
   96         ipsdisk_softc_t *dsc;
   97 
   98         dsc = iobuf->bio_disk->d_drv1;  
   99         DEVICE_PRINTF(8,dsc->dev,"in strategy\n");
  100         (uint32_t)iobuf->bio_driver1 = dsc->sc->drives[dsc->disk_number].drivenum;
  101         ips_start_io_request(dsc->sc, iobuf);
  102 }
  103 
  104 static int ipsd_probe(device_t dev)
  105 {
  106         DEVICE_PRINTF(2,dev, "in probe\n");
  107         device_set_desc(dev, "Logical Drive");
  108         return 0;
  109 }
  110 
  111 static int ipsd_attach(device_t dev)
  112 {
  113         device_t adapter;
  114         ipsdisk_softc_t *dsc;
  115         u_int totalsectors;
  116 
  117         DEVICE_PRINTF(2,dev, "in attach\n");
  118 
  119         dsc = (ipsdisk_softc_t *)device_get_softc(dev);
  120         bzero(dsc, sizeof(ipsdisk_softc_t));
  121         adapter = device_get_parent(dev);
  122         dsc->dev = dev;
  123         dsc->sc = device_get_softc(adapter);
  124         dsc->unit = device_get_unit(dev);
  125         dsc->disk_number = (int) device_get_ivars(dev);
  126         dsc->ipsd_disk.d_drv1 = dsc;
  127         dsc->ipsd_disk.d_name = "ipsd";
  128         dsc->ipsd_disk.d_maxsize = IPS_MAX_IO_SIZE;
  129         dsc->ipsd_disk.d_open = ipsd_open;
  130         dsc->ipsd_disk.d_close = ipsd_close;
  131         dsc->ipsd_disk.d_strategy = ipsd_strategy;
  132 
  133         totalsectors = dsc->sc->drives[dsc->disk_number].sector_count;
  134         if ((totalsectors > 0x400000) &&
  135                         ((dsc->sc->adapter_info.miscflags & 0x8) == 0)) {
  136                 dsc->ipsd_disk.d_fwheads = IPS_NORM_HEADS;
  137                 dsc->ipsd_disk.d_fwsectors = IPS_NORM_SECTORS;
  138         } else {
  139                 dsc->ipsd_disk.d_fwheads = IPS_COMP_HEADS;
  140                 dsc->ipsd_disk.d_fwsectors = IPS_COMP_SECTORS;
  141         }
  142         dsc->ipsd_disk.d_sectorsize = IPS_BLKSIZE;
  143         dsc->ipsd_disk.d_mediasize = totalsectors * IPS_BLKSIZE;
  144         disk_create(dsc->unit, &dsc->ipsd_disk, 0, NULL, NULL);
  145 
  146         device_printf(dev, "Logical Drive  (%dMB)\n",
  147                       dsc->sc->drives[dsc->disk_number].sector_count >> 11);
  148         return 0;
  149 }
  150 
  151 static int ipsd_detach(device_t dev)
  152 {
  153         ipsdisk_softc_t *dsc;
  154 
  155         DEVICE_PRINTF(2, dev,"in detach\n");
  156         dsc = (ipsdisk_softc_t *)device_get_softc(dev);
  157         if(dsc->state & IPS_DEV_OPEN)
  158                 return (EBUSY);
  159         disk_destroy(&dsc->ipsd_disk);
  160         return 0;
  161 }
  162 

Cache object: a5f3597f26807b2b772df72b8f3b5f30


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