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/ic/ld_aac.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: ld_aac.c,v 1.13.2.2 2008/10/03 09:12:16 jdc Exp $      */
    2 
    3 /*-
    4  * Copyright (c) 2002 The NetBSD Foundation, Inc.
    5  * All rights reserved.
    6  *
    7  * This code is derived from software contributed to The NetBSD Foundation
    8  * by Andrew Doran.
    9  *
   10  * Redistribution and use in source and binary forms, with or without
   11  * modification, are permitted provided that the following conditions
   12  * are met:
   13  * 1. Redistributions of source code must retain the above copyright
   14  *    notice, this list of conditions and the following disclaimer.
   15  * 2. Redistributions in binary form must reproduce the above copyright
   16  *    notice, this list of conditions and the following disclaimer in the
   17  *    documentation and/or other materials provided with the distribution.
   18  * 3. All advertising materials mentioning features or use of this software
   19  *    must display the following acknowledgement:
   20  *        This product includes software developed by the NetBSD
   21  *        Foundation, Inc. and its contributors.
   22  * 4. Neither the name of The NetBSD Foundation nor the names of its
   23  *    contributors may be used to endorse or promote products derived
   24  *    from this software without specific prior written permission.
   25  *
   26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   36  * POSSIBILITY OF SUCH DAMAGE.
   37  */
   38 
   39 #include <sys/cdefs.h>
   40 __KERNEL_RCSID(0, "$NetBSD: ld_aac.c,v 1.13.2.2 2008/10/03 09:12:16 jdc Exp $");
   41 
   42 #include "rnd.h"
   43 
   44 #include <sys/param.h>
   45 #include <sys/systm.h>
   46 #include <sys/kernel.h>
   47 #include <sys/device.h>
   48 #include <sys/buf.h>
   49 #include <sys/bufq.h>
   50 #include <sys/endian.h>
   51 #include <sys/dkio.h>
   52 #include <sys/disk.h>
   53 #if NRND > 0
   54 #include <sys/rnd.h>
   55 #endif
   56 
   57 #include <machine/bus.h>
   58 
   59 #include <uvm/uvm_extern.h>
   60 
   61 #include <dev/ldvar.h>
   62 
   63 #include <dev/ic/aacreg.h>
   64 #include <dev/ic/aacvar.h>
   65 
   66 struct ld_aac_softc {
   67         struct  ld_softc sc_ld;
   68         int     sc_hwunit;
   69 };
   70 
   71 static void     ld_aac_attach(struct device *, struct device *, void *);
   72 static void     ld_aac_intr(struct aac_ccb *);
   73 static int      ld_aac_dobio(struct ld_aac_softc *, void *, int, daddr_t, int,
   74                              struct buf *);
   75 static int      ld_aac_dump(struct ld_softc *, void *, int, int);
   76 static int      ld_aac_match(struct device *, struct cfdata *, void *);
   77 static int      ld_aac_start(struct ld_softc *, struct buf *);
   78 
   79 CFATTACH_DECL(ld_aac, sizeof(struct ld_aac_softc),
   80     ld_aac_match, ld_aac_attach, NULL, NULL);
   81 
   82 static int
   83 ld_aac_match(struct device *parent, struct cfdata *match,
   84     void *aux)
   85 {
   86 
   87         return (1);
   88 }
   89 
   90 static void
   91 ld_aac_attach(struct device *parent, struct device *self, void *aux)
   92 {
   93         struct aac_attach_args *aaca;
   94         struct aac_drive *hdr;
   95         struct ld_aac_softc *sc;
   96         struct ld_softc *ld;
   97         struct aac_softc *aac;
   98 
   99         aaca = aux;
  100         aac = (struct aac_softc *)parent;
  101         sc = (struct ld_aac_softc *)self;
  102         ld = &sc->sc_ld;
  103         hdr = &aac->sc_hdr[aaca->aaca_unit];
  104 
  105         sc->sc_hwunit = aaca->aaca_unit;
  106         ld->sc_flags = LDF_ENABLED;
  107         ld->sc_maxxfer = AAC_MAX_XFER(aac);
  108         ld->sc_secperunit = hdr->hd_size;
  109         ld->sc_secsize = AAC_SECTOR_SIZE;
  110         ld->sc_maxqueuecnt = (aac->sc_max_fibs - AAC_NCCBS_RESERVE) / aac->sc_nunits;
  111         ld->sc_start = ld_aac_start;
  112         ld->sc_dump = ld_aac_dump;
  113 
  114         aprint_normal(": %s\n",
  115             aac_describe_code(aac_container_types, hdr->hd_devtype));
  116         ldattach(ld);
  117 }
  118 
  119 static int
  120 ld_aac_dobio(struct ld_aac_softc *sc, void *data, int datasize, daddr_t blkno,
  121              int dowrite, struct buf *bp)
  122 {
  123         struct aac_blockread_response *brr;
  124         struct aac_blockwrite_response *bwr;
  125         struct aac_ccb *ac;
  126         struct aac_softc *aac;
  127         struct aac_fib *fib;
  128         bus_dmamap_t xfer;
  129         u_int32_t status;
  130         u_int16_t size;
  131         int s, rv, i;
  132 
  133         aac = (struct aac_softc *)device_parent(&sc->sc_ld.sc_dv);
  134 
  135         /*
  136          * Allocate a command control block and map the data transfer.
  137          */
  138         ac = aac_ccb_alloc(aac, (dowrite ? AAC_CCB_DATA_OUT : AAC_CCB_DATA_IN));
  139         if (ac == NULL)
  140                 return EBUSY;
  141         ac->ac_data = data;
  142         ac->ac_datalen = datasize;
  143 
  144         if ((rv = aac_ccb_map(aac, ac)) != 0) {
  145                 aac_ccb_free(aac, ac);
  146                 return (rv);
  147         }
  148 
  149         /*
  150          * Build the command.
  151          */
  152         fib = ac->ac_fib;
  153 
  154         fib->Header.XferState = htole32(AAC_FIBSTATE_HOSTOWNED |
  155             AAC_FIBSTATE_INITIALISED | AAC_FIBSTATE_FROMHOST |
  156             AAC_FIBSTATE_REXPECTED | AAC_FIBSTATE_NORM |
  157             AAC_FIBSTATE_ASYNC | AAC_FIBSTATE_FAST_RESPONSE );
  158 
  159         if (aac->sc_quirks & AAC_QUIRK_RAW_IO) {
  160                 struct aac_raw_io *raw;
  161                 struct aac_sg_entryraw *sge;
  162                 struct aac_sg_tableraw *sgt;
  163 
  164                 raw = (struct aac_raw_io *)&fib->data[0];
  165                 fib->Header.Command = htole16(RawIo);
  166                 raw->BlockNumber = htole64(blkno);
  167                 raw->ByteCount = htole32(datasize);
  168                 raw->ContainerId = htole16(sc->sc_hwunit);
  169                 raw->BpTotal = 0;
  170                 raw->BpComplete = 0;
  171                 size = sizeof(struct aac_raw_io);
  172                 sgt = &raw->SgMapRaw;
  173                 raw->Flags = (dowrite ? 0 : 1);
  174 
  175                 xfer = ac->ac_dmamap_xfer;
  176                 sgt->SgCount = xfer->dm_nsegs;
  177                 sge = sgt->SgEntryRaw;
  178 
  179                 for (i = 0; i < xfer->dm_nsegs; i++, sge++) {
  180                         sge->SgAddress = htole64(xfer->dm_segs[i].ds_addr);
  181                         sge->SgByteCount = htole32(xfer->dm_segs[i].ds_len);
  182                         sge->Next = 0;
  183                         sge->Prev = 0;
  184                         sge->Flags = 0;
  185                 }
  186                 size += xfer->dm_nsegs * sizeof(struct aac_sg_entryraw);
  187                 size = sizeof(fib->Header) + size;
  188                 fib->Header.Size = htole16(size);
  189         } else if ((aac->sc_quirks & AAC_QUIRK_SG_64BIT) == 0) {
  190                 struct aac_blockread *br;
  191                 struct aac_blockwrite *bw;
  192                 struct aac_sg_entry *sge;
  193                 struct aac_sg_table *sgt;
  194 
  195                 fib->Header.Command = htole16(ContainerCommand);
  196                 if (dowrite) {
  197                         bw = (struct aac_blockwrite *)&fib->data[0];
  198                         bw->Command = htole32(VM_CtBlockWrite);
  199                         bw->ContainerId = htole32(sc->sc_hwunit);
  200                         bw->BlockNumber = htole32(blkno);
  201                         bw->ByteCount = htole32(datasize);
  202                         bw->Stable = htole32(CUNSTABLE);
  203                         /* CSTABLE sometimes?  FUA? */
  204 
  205                         size = sizeof(struct aac_blockwrite);
  206                         sgt = &bw->SgMap;
  207                 } else {
  208                         br = (struct aac_blockread *)&fib->data[0];
  209                         br->Command = htole32(VM_CtBlockRead);
  210                         br->ContainerId = htole32(sc->sc_hwunit);
  211                         br->BlockNumber = htole32(blkno);
  212                         br->ByteCount = htole32(datasize);
  213 
  214                         size = sizeof(struct aac_blockread);
  215                         sgt = &br->SgMap;
  216                 }
  217 
  218                 xfer = ac->ac_dmamap_xfer;
  219                 sgt->SgCount = xfer->dm_nsegs;
  220                 sge = sgt->SgEntry;
  221 
  222                 for (i = 0; i < xfer->dm_nsegs; i++, sge++) {
  223                         sge->SgAddress = htole32(xfer->dm_segs[i].ds_addr);
  224                         sge->SgByteCount = htole32(xfer->dm_segs[i].ds_len);
  225                         AAC_DPRINTF(AAC_D_IO,
  226                             ("#%d va %p pa %lx len %lx\n", i, data,
  227                             (u_long)xfer->dm_segs[i].ds_addr,
  228                             (u_long)xfer->dm_segs[i].ds_len));
  229                 }
  230 
  231                 size += xfer->dm_nsegs * sizeof(struct aac_sg_entry);
  232                 size = sizeof(fib->Header) + size;
  233                 fib->Header.Size = htole16(size);
  234         } else {
  235                 struct aac_blockread64 *br;
  236                 struct aac_blockwrite64 *bw;
  237                 struct aac_sg_entry64 *sge;
  238                 struct aac_sg_table64 *sgt;
  239 
  240                 fib->Header.Command = htole16(ContainerCommand64);
  241                 if (dowrite) {
  242                         bw = (struct aac_blockwrite64 *)&fib->data[0];
  243                         bw->Command = htole32(VM_CtHostWrite64);
  244                         bw->BlockNumber = htole32(blkno);
  245                         bw->ContainerId = htole16(sc->sc_hwunit);
  246                         bw->SectorCount = htole16(datasize / AAC_BLOCK_SIZE);
  247                         bw->Pad = 0;
  248                         bw->Flags = 0;
  249 
  250                         size = sizeof(struct aac_blockwrite64);
  251                         sgt = &bw->SgMap64;
  252                 } else {
  253                         br = (struct aac_blockread64 *)&fib->data[0];
  254                         br->Command = htole32(VM_CtHostRead64);
  255                         br->BlockNumber = htole32(blkno);
  256                         br->ContainerId = htole16(sc->sc_hwunit);
  257                         br->SectorCount = htole16(datasize / AAC_BLOCK_SIZE);
  258                         br->Pad = 0;
  259                         br->Flags = 0;
  260 
  261                         size = sizeof(struct aac_blockread64);
  262                         sgt = &br->SgMap64;
  263                 }
  264 
  265                 xfer = ac->ac_dmamap_xfer;
  266                 sgt->SgCount = xfer->dm_nsegs;
  267                 sge = sgt->SgEntry64;
  268 
  269                 for (i = 0; i < xfer->dm_nsegs; i++, sge++) {
  270                         /*
  271                          * XXX - This is probably an alignment issue on non-x86
  272                          * platforms since this is a packed array of 64/32-bit
  273                          * tuples, so every other SgAddress is 32-bit, but not
  274                          * 64-bit aligned.
  275                          */
  276                         sge->SgAddress = htole64(xfer->dm_segs[i].ds_addr);
  277                         sge->SgByteCount = htole32(xfer->dm_segs[i].ds_len);
  278                         AAC_DPRINTF(AAC_D_IO,
  279                             ("#%d va %p pa %lx len %lx\n", i, data,
  280                             (u_int64_t)xfer->dm_segs[i].ds_addr,
  281                             (u_long)xfer->dm_segs[i].ds_len));
  282                 }
  283                 size += xfer->dm_nsegs * sizeof(struct aac_sg_entry64);
  284                 size = sizeof(fib->Header) + size;
  285                 fib->Header.Size = htole16(size);
  286         }
  287 
  288         if (bp == NULL) {
  289                 /*
  290                  * Polled commands must not sit on the software queue.  Wait
  291                  * up to 30 seconds for the command to complete.
  292                  */
  293                 s = splbio();
  294                 rv = aac_ccb_poll(aac, ac, 30000);
  295                 aac_ccb_unmap(aac, ac);
  296                 aac_ccb_free(aac, ac);
  297                 splx(s);
  298 
  299                 if (rv == 0) {
  300                         if (dowrite) {
  301                                 bwr = (struct aac_blockwrite_response *)
  302                                     &ac->ac_fib->data[0];
  303                                 status = le32toh(bwr->Status);
  304                         } else {
  305                                 brr = (struct aac_blockread_response *)
  306                                     &ac->ac_fib->data[0];
  307                                 status = le32toh(brr->Status);
  308                         }
  309 
  310                         if (status != ST_OK) {
  311                                 printf("%s: I/O error: %s\n",
  312                                     sc->sc_ld.sc_dv.dv_xname,
  313                                     aac_describe_code(aac_command_status_table,
  314                                     status));
  315                                 rv = EIO;
  316                         }
  317                 }
  318         } else {
  319                 ac->ac_device = (struct device *)sc;
  320                 ac->ac_context = bp;
  321                 ac->ac_intr = ld_aac_intr;
  322                 aac_ccb_enqueue(aac, ac);
  323                 rv = 0;
  324         }
  325 
  326         return (rv);
  327 }
  328 
  329 static int
  330 ld_aac_start(struct ld_softc *ld, struct buf *bp)
  331 {
  332 
  333         return (ld_aac_dobio((struct ld_aac_softc *)ld, bp->b_data,
  334             bp->b_bcount, bp->b_rawblkno, (bp->b_flags & B_READ) == 0, bp));
  335 }
  336 
  337 static void
  338 ld_aac_intr(struct aac_ccb *ac)
  339 {
  340         struct aac_blockread_response *brr;
  341         struct aac_blockwrite_response *bwr;
  342         struct ld_aac_softc *sc;
  343         struct aac_softc *aac;
  344         struct buf *bp;
  345         u_int32_t status;
  346 
  347         bp = ac->ac_context;
  348         sc = (struct ld_aac_softc *)ac->ac_device;
  349         aac = (struct aac_softc *)device_parent(&sc->sc_ld.sc_dv);
  350 
  351         if ((bp->b_flags & B_READ) != 0) {
  352                 brr = (struct aac_blockread_response *)&ac->ac_fib->data[0];
  353                 status = le32toh(brr->Status);
  354         } else {
  355                 bwr = (struct aac_blockwrite_response *)&ac->ac_fib->data[0];
  356                 status = le32toh(bwr->Status);
  357         }
  358 
  359         aac_ccb_unmap(aac, ac);
  360         aac_ccb_free(aac, ac);
  361 
  362         if (status != ST_OK) {
  363                 bp->b_flags |= B_ERROR;
  364                 bp->b_error = EIO;
  365                 bp->b_resid = bp->b_bcount;
  366 
  367                 printf("%s: I/O error: %s\n", sc->sc_ld.sc_dv.dv_xname,
  368                     aac_describe_code(aac_command_status_table, status));
  369         } else
  370                 bp->b_resid = 0;
  371 
  372         lddone(&sc->sc_ld, bp);
  373 }
  374 
  375 static int
  376 ld_aac_dump(struct ld_softc *ld, void *data, int blkno, int blkcnt)
  377 {
  378 
  379         return (ld_aac_dobio((struct ld_aac_softc *)ld, data,
  380             blkcnt * ld->sc_secsize, blkno, 1, NULL));
  381 }

Cache object: e80b49998f2f8c6e05ea5fc5413b739c


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