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/ata/ata_raid_promise.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 /*      $NetBSD: ata_raid_promise.c,v 1.3 2003/12/14 05:37:25 thorpej Exp $     */
    2 
    3 /*-
    4  * Copyright (c) 2000,2001,2002 Søren Schmidt <sos@FreeBSD.org>
    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  *    without modification, immediately at the beginning of the file.
   13  * 2. Redistributions in binary form must reproduce the above copyright
   14  *    notice, this list of conditions and the following disclaimer in the
   15  *    documentation and/or other materials provided with the distribution.
   16  * 3. The name of the author may not be used to endorse or promote products
   17  *    derived from this software without specific prior written permission.
   18  *
   19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   29  */
   30 
   31 /*
   32  * Support for parsing Promise ATA RAID controller configuration blocks.
   33  *
   34  * Adapted to NetBSD by Jason R. Thorpe of Wasabi Systems, Inc.
   35  */
   36 
   37 #include <sys/cdefs.h>
   38 __KERNEL_RCSID(0, "$NetBSD: ata_raid_promise.c,v 1.3 2003/12/14 05:37:25 thorpej Exp $");
   39 
   40 #include <sys/param.h>
   41 #include <sys/buf.h>
   42 #include <sys/conf.h>
   43 #include <sys/device.h>
   44 #include <sys/disk.h>
   45 #include <sys/disklabel.h>
   46 #include <sys/fcntl.h>
   47 #include <sys/malloc.h>
   48 #include <sys/vnode.h>
   49 
   50 #include <miscfs/specfs/specdev.h>
   51 
   52 #include <dev/ata/atareg.h>
   53 #include <dev/ata/atavar.h>
   54 #include <dev/ata/wdvar.h>
   55 
   56 #include <dev/ata/ata_raidreg.h>
   57 #include <dev/ata/ata_raidvar.h>
   58 
   59 #ifdef ATA_RAID_DEBUG
   60 #define DPRINTF(x)      printf x
   61 #else
   62 #define DPRINTF(x)      /* nothing */
   63 #endif
   64 
   65 int
   66 ata_raid_read_config_promise(struct wd_softc *sc)
   67 {
   68         struct promise_raid_conf *info;
   69         struct vnode *vp;
   70         int bmajor, error, count;
   71         u_int disk;
   72         dev_t dev;
   73         uint32_t cksum, *ckptr;
   74         struct ataraid_array_info *aai;
   75         struct ataraid_disk_info *adi;
   76 
   77         info = malloc(sizeof(*info), M_DEVBUF, M_WAITOK);
   78         
   79         bmajor = devsw_name2blk(sc->sc_dev.dv_xname, NULL, 0);
   80 
   81         /* Get a vnode for the raw partition of this disk. */
   82         dev = MAKEDISKDEV(bmajor, sc->sc_dev.dv_unit, RAW_PART);
   83         error = bdevvp(dev, &vp);
   84         if (error)
   85                 goto out;
   86 
   87         error = VOP_OPEN(vp, FREAD, NOCRED, 0);
   88         if (error) {
   89                 vput(vp);
   90                 goto out;
   91         }
   92 
   93         error = ata_raid_config_block_rw(vp, PR_LBA(sc), info,
   94             sizeof(*info), B_READ);
   95         vput(vp);
   96         if (error) {
   97                 printf("%s: error %d reading Promise config block\n",
   98                     sc->sc_dev.dv_xname, error);
   99                 goto out;
  100         }
  101 
  102         /* Check the signature. */
  103         if (strncmp(info->promise_id, PR_MAGIC, sizeof(PR_MAGIC)) != 0) {
  104                 DPRINTF(("%s: Promise signature check failed\n",
  105                     sc->sc_dev.dv_xname));
  106                 error = ESRCH;
  107                 goto out;
  108         }
  109 
  110         /* Verify the checksum. */
  111         for (cksum = 0, ckptr = (uint32_t *) info, count = 0; count < 511;
  112              count++)
  113                 cksum += *ckptr++;
  114         if (cksum != *ckptr) {
  115                 DPRINTF(("%s: Promise checksum failed\n", sc->sc_dev.dv_xname));
  116                 error = ESRCH;
  117                 goto out;
  118         }
  119 
  120         if (info->raid.integrity != PR_I_VALID) {
  121                 DPRINTF(("%s: Promise config block marked invalid\n",
  122                     sc->sc_dev.dv_xname));
  123                 error = ESRCH;
  124                 goto out;
  125         }
  126 
  127         /*
  128          * Lookup or allocate a new array info structure for
  129          * this array.
  130          */
  131         aai = ata_raid_get_array_info(ATA_RAID_TYPE_PROMISE,
  132             info->raid.array_number);
  133 
  134         if (info->raid.generation == 0 ||
  135             info->raid.generation > aai->aai_generation) {
  136                 aai->aai_generation = info->raid.generation;
  137                 /* aai_type and aai_arrayno filled in already */
  138                 if ((info->raid.status &
  139                      (PR_S_VALID | PR_S_ONLINE | PR_S_INITED | PR_S_READY)) ==
  140                     (PR_S_VALID | PR_S_ONLINE | PR_S_INITED | PR_S_READY)) {
  141                         aai->aai_status |= AAI_S_READY;
  142                         if (info->raid.status & PR_S_DEGRADED)
  143                                 aai->aai_status |= AAI_S_DEGRADED;
  144                 } else
  145                         aai->aai_status &= ~AAI_S_READY;
  146 
  147                 switch (info->raid.type) {
  148                 case PR_T_RAID0:
  149                         aai->aai_level = AAI_L_RAID0;
  150                         break;
  151 
  152                 case PR_T_RAID1:
  153                         aai->aai_level = AAI_L_RAID1;
  154                         if (info->raid.array_width > 1)
  155                                 aai->aai_level |= AAI_L_RAID0;
  156                         break;
  157 
  158                 case PR_T_SPAN:
  159                         aai->aai_level = AAI_L_SPAN;
  160                         break;
  161 
  162                 default:
  163                         printf("%s: unknown Promise RAID type 0x%02x\n",
  164                             sc->sc_dev.dv_xname, info->raid.type);
  165                         error = EINVAL;
  166                         goto out;
  167                 }
  168 
  169                 aai->aai_interleave = 1U << info->raid.stripe_shift;
  170                 aai->aai_width = info->raid.array_width;
  171                 aai->aai_ndisks = info->raid.total_disks;
  172                 aai->aai_heads = info->raid.heads + 1;
  173                 aai->aai_sectors = info->raid.sectors;
  174                 aai->aai_cylinders = info->raid.cylinders + 1;
  175                 aai->aai_capacity = info->raid.total_sectors;
  176                 aai->aai_offset = 0;
  177                 aai->aai_reserved = 63;
  178 
  179                 for (disk = 0; disk < aai->aai_ndisks; disk++) {
  180                         adi = &aai->aai_disks[disk];
  181                         adi->adi_status = 0;
  182                         if (info->raid.disk[disk].flags & PR_F_ONLINE)
  183                                 adi->adi_status |= ADI_S_ONLINE;
  184                         if (info->raid.disk[disk].flags & PR_F_ASSIGNED)
  185                                 adi->adi_status |= ADI_S_ASSIGNED;
  186                         if (info->raid.disk[disk].flags & PR_F_SPARE) {
  187                                 adi->adi_status &= ~ADI_S_ONLINE;
  188                                 adi->adi_status |= ADI_S_SPARE;
  189                         }
  190                         if (info->raid.disk[disk].flags &
  191                             (PR_F_REDIR | PR_F_DOWN))
  192                                 adi->adi_status &= ~ADI_S_ONLINE;
  193                 }
  194         }
  195         adi = &aai->aai_disks[info->raid.disk_number];
  196         if (adi->adi_status) {
  197                 adi->adi_dev = &sc->sc_dev;
  198                 adi->adi_sectors = info->raid.disk_sectors;
  199                 adi->adi_compsize = sc->sc_capacity - aai->aai_reserved;
  200         }
  201 
  202         error = 0;
  203 
  204  out:
  205         free(info, M_DEVBUF);
  206         return (error);
  207 }

Cache object: d64869cd9d4b6fc40ce0ec9b8372426b


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