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/i2o/iopsp.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: iopsp.c,v 1.18 2003/06/13 02:33:09 thorpej Exp $       */
    2 
    3 /*-
    4  * Copyright (c) 2000, 2001 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 /*
   40  * Raw SCSI device support for I2O.  IOPs present SCSI devices individually;
   41  * we group them by controlling port.
   42  */
   43 
   44 #include <sys/cdefs.h>
   45 __KERNEL_RCSID(0, "$NetBSD: iopsp.c,v 1.18 2003/06/13 02:33:09 thorpej Exp $");
   46 
   47 #include "opt_i2o.h"
   48 
   49 #include <sys/param.h>
   50 #include <sys/systm.h>
   51 #include <sys/kernel.h>
   52 #include <sys/device.h>
   53 #include <sys/queue.h>
   54 #include <sys/proc.h>
   55 #include <sys/buf.h>
   56 #include <sys/endian.h>
   57 #include <sys/malloc.h>
   58 #include <sys/scsiio.h>
   59 #include <sys/lock.h>
   60 
   61 #include <machine/bswap.h>
   62 #include <machine/bus.h>
   63 
   64 #include <dev/scsipi/scsi_all.h>
   65 #include <dev/scsipi/scsi_disk.h>
   66 #include <dev/scsipi/scsipi_all.h>
   67 #include <dev/scsipi/scsiconf.h>
   68 #include <dev/scsipi/scsi_message.h>
   69 
   70 #include <dev/i2o/i2o.h>
   71 #include <dev/i2o/iopio.h>
   72 #include <dev/i2o/iopvar.h>
   73 #include <dev/i2o/iopspvar.h>
   74 
   75 static void     iopsp_adjqparam(struct device *, int);
   76 static void     iopsp_attach(struct device *, struct device *, void *);
   77 static void     iopsp_intr(struct device *, struct iop_msg *, void *);
   78 static int      iopsp_ioctl(struct scsipi_channel *, u_long,
   79                             caddr_t, int, struct proc *);
   80 static int      iopsp_match(struct device *, struct cfdata *, void *);
   81 static int      iopsp_rescan(struct iopsp_softc *);
   82 static int      iopsp_reconfig(struct device *);
   83 static void     iopsp_scsipi_request(struct scsipi_channel *,
   84                                      scsipi_adapter_req_t, void *);
   85 
   86 CFATTACH_DECL(iopsp, sizeof(struct iopsp_softc),
   87     iopsp_match, iopsp_attach, NULL, NULL);
   88 
   89 /*
   90  * Match a supported device.
   91  */
   92 static int
   93 iopsp_match(struct device *parent, struct cfdata *match, void *aux)
   94 {
   95         struct iop_attach_args *ia;
   96         struct {
   97                 struct  i2o_param_op_results pr;
   98                 struct  i2o_param_read_results prr;
   99                 struct  i2o_param_hba_ctlr_info ci;
  100         } __attribute__ ((__packed__)) param;
  101 
  102         ia = aux;
  103 
  104         if (ia->ia_class != I2O_CLASS_BUS_ADAPTER_PORT)
  105                 return (0);
  106 
  107         if (iop_field_get_all((struct iop_softc *)parent, ia->ia_tid,
  108             I2O_PARAM_HBA_CTLR_INFO, &param, sizeof(param), NULL) != 0)
  109                 return (0);
  110 
  111         return (param.ci.bustype == I2O_HBA_BUS_SCSI ||
  112             param.ci.bustype == I2O_HBA_BUS_FCA);
  113 }
  114 
  115 /*
  116  * Attach a supported device.
  117  */
  118 static void
  119 iopsp_attach(struct device *parent, struct device *self, void *aux)
  120 {
  121         struct iop_attach_args *ia;
  122         struct iopsp_softc *sc;
  123         struct iop_softc *iop;
  124         struct {
  125                 struct  i2o_param_op_results pr;
  126                 struct  i2o_param_read_results prr;
  127                 union {
  128                         struct  i2o_param_hba_ctlr_info ci;
  129                         struct  i2o_param_hba_scsi_ctlr_info sci;
  130                         struct  i2o_param_hba_scsi_port_info spi;
  131                 } p;
  132         } __attribute__ ((__packed__)) param;
  133         int fc, rv;
  134 #ifdef I2OVERBOSE
  135         int size;
  136 #endif
  137 
  138         ia = (struct iop_attach_args *)aux;
  139         sc = (struct iopsp_softc *)self;
  140         iop = (struct iop_softc *)parent;
  141 
  142         /* Register us as an initiator. */
  143         sc->sc_ii.ii_dv = self;
  144         sc->sc_ii.ii_intr = iopsp_intr;
  145         sc->sc_ii.ii_flags = 0;
  146         sc->sc_ii.ii_tid = ia->ia_tid;
  147         sc->sc_ii.ii_reconfig = iopsp_reconfig;
  148         sc->sc_ii.ii_adjqparam = iopsp_adjqparam;
  149         iop_initiator_register(iop, &sc->sc_ii);
  150 
  151         rv = iop_field_get_all(iop, ia->ia_tid, I2O_PARAM_HBA_CTLR_INFO,
  152             &param, sizeof(param), NULL);
  153         if (rv != 0)
  154                 goto bad;
  155 
  156         fc = (param.p.ci.bustype == I2O_HBA_BUS_FCA);
  157 
  158         /* 
  159          * Say what the device is.  If we can find out what the controling
  160          * device is, say what that is too.
  161          */
  162         printf(": SCSI port");
  163         iop_print_ident(iop, ia->ia_tid);
  164         printf("\n");
  165 
  166         rv = iop_field_get_all(iop, ia->ia_tid, I2O_PARAM_HBA_SCSI_CTLR_INFO,
  167             &param, sizeof(param), NULL);
  168         if (rv != 0)
  169                 goto bad;
  170 
  171 #ifdef I2OVERBOSE
  172         printf("%s: ", sc->sc_dv.dv_xname);
  173         if (fc)
  174                 printf("FC");
  175         else
  176                 printf("%d-bit", param.p.sci.maxdatawidth);
  177         printf(", max sync rate %dMHz, initiator ID %d\n",
  178             (u_int32_t)le64toh(param.p.sci.maxsyncrate) / 1000,
  179             le32toh(param.p.sci.initiatorid));
  180 #endif
  181 
  182         sc->sc_openings = 1;
  183 
  184         sc->sc_adapter.adapt_dev = &sc->sc_dv;
  185         sc->sc_adapter.adapt_nchannels = 1;
  186         sc->sc_adapter.adapt_openings = 1;
  187         sc->sc_adapter.adapt_max_periph = 1;
  188         sc->sc_adapter.adapt_ioctl = iopsp_ioctl;
  189         sc->sc_adapter.adapt_minphys = minphys;
  190         sc->sc_adapter.adapt_request = iopsp_scsipi_request;
  191 
  192         memset(&sc->sc_channel, 0, sizeof(sc->sc_channel));
  193         sc->sc_channel.chan_adapter = &sc->sc_adapter;
  194         sc->sc_channel.chan_bustype = &scsi_bustype;
  195         sc->sc_channel.chan_channel = 0;
  196         sc->sc_channel.chan_ntargets = fc ?
  197             IOPSP_MAX_FC_TARGET : param.p.sci.maxdatawidth;
  198         sc->sc_channel.chan_nluns = IOPSP_MAX_LUN;
  199         sc->sc_channel.chan_id = le32toh(param.p.sci.initiatorid);
  200         sc->sc_channel.chan_flags = SCSIPI_CHAN_NOSETTLE;
  201 
  202 #ifdef I2OVERBOSE
  203         /*
  204          * Allocate the target map.  Currently used for informational
  205          * purposes only.
  206          */
  207         size = sc->sc_channel.chan_ntargets * sizeof(struct iopsp_target);
  208         sc->sc_targetmap = malloc(size, M_DEVBUF, M_NOWAIT|M_ZERO);
  209 #endif
  210 
  211         /* Build the two maps, and attach to scsipi. */
  212         if (iopsp_reconfig(self) != 0) {
  213                 printf("%s: configure failed\n", sc->sc_dv.dv_xname);
  214                 goto bad;
  215         }
  216         config_found(self, &sc->sc_channel, scsiprint);
  217         return;
  218 
  219  bad:
  220         iop_initiator_unregister(iop, &sc->sc_ii);
  221 }
  222 
  223 /*
  224  * Scan the LCT to determine which devices we control, and enter them into
  225  * the maps.
  226  */
  227 static int
  228 iopsp_reconfig(struct device *dv)
  229 {
  230         struct iopsp_softc *sc;
  231         struct iop_softc *iop;
  232         struct i2o_lct_entry *le;
  233         struct scsipi_channel *sc_chan;
  234         struct {
  235                 struct  i2o_param_op_results pr;
  236                 struct  i2o_param_read_results prr;
  237                 struct  i2o_param_scsi_device_info sdi;
  238         } __attribute__ ((__packed__)) param;
  239         u_int tid, nent, i, targ, lun, size, s, rv, bptid;
  240         u_short *tidmap;
  241 #ifdef I2OVERBOSE
  242         struct iopsp_target *it;
  243         int syncrate;   
  244 #endif
  245 
  246         sc = (struct iopsp_softc *)dv;
  247         iop = (struct iop_softc *)sc->sc_dv.dv_parent;
  248         sc_chan = &sc->sc_channel;
  249 
  250         /* Anything to do? */
  251         if (iop->sc_chgind == sc->sc_chgind)
  252                 return (0);
  253 
  254         /*
  255          * Allocate memory for the target/LUN -> TID map.  Use zero to
  256          * denote absent targets (zero is the TID of the I2O executive,
  257          * and we never address that here).
  258          */
  259         size = sc_chan->chan_ntargets * (IOPSP_MAX_LUN) * sizeof(u_short);
  260         if ((tidmap = malloc(size, M_DEVBUF, M_WAITOK|M_ZERO)) == NULL)
  261                 return (ENOMEM);
  262 
  263 #ifdef I2OVERBOSE
  264         for (i = 0; i < sc_chan->chan_ntargets; i++)
  265                 sc->sc_targetmap[i].it_flags &= ~IT_PRESENT;
  266 #endif
  267 
  268         /*
  269          * A quick hack to handle Intel's stacked bus port arrangement.
  270          */
  271         bptid = sc->sc_ii.ii_tid;
  272         nent = iop->sc_nlctent;
  273         for (le = iop->sc_lct->entry; nent != 0; nent--, le++)
  274                 if ((le16toh(le->classid) & 4095) ==
  275                     I2O_CLASS_BUS_ADAPTER_PORT &&
  276                     (le32toh(le->usertid) & 4095) == bptid) {
  277                         bptid = le16toh(le->localtid) & 4095;
  278                         break;
  279                 }
  280 
  281         nent = iop->sc_nlctent;
  282         for (i = 0, le = iop->sc_lct->entry; i < nent; i++, le++) {
  283                 if ((le16toh(le->classid) & 4095) != I2O_CLASS_SCSI_PERIPHERAL)
  284                         continue;
  285                 if (((le32toh(le->usertid) >> 12) & 4095) != bptid)
  286                         continue;
  287                 tid = le16toh(le->localtid) & 4095;
  288 
  289                 rv = iop_field_get_all(iop, tid, I2O_PARAM_SCSI_DEVICE_INFO,
  290                     &param, sizeof(param), NULL);
  291                 if (rv != 0)
  292                         continue;
  293                 targ = le32toh(param.sdi.identifier);
  294                 lun = param.sdi.luninfo[1];
  295 #if defined(DIAGNOSTIC) || defined(I2ODEBUG)
  296                 if (targ >= sc_chan->chan_ntargets ||
  297                     lun >= sc_chan->chan_nluns) {
  298                         printf("%s: target %d,%d (tid %d): bad target/LUN\n",
  299                             sc->sc_dv.dv_xname, targ, lun, tid);
  300                         continue;
  301                 }
  302 #endif
  303 
  304 #ifdef I2OVERBOSE
  305                 /*
  306                  * If we've already described this target, and nothing has
  307                  * changed, then don't describe it again.
  308                  */
  309                 it = &sc->sc_targetmap[targ];
  310                 it->it_flags |= IT_PRESENT;
  311                 syncrate = ((int)le64toh(param.sdi.negsyncrate) + 500) / 1000;
  312                 if (it->it_width != param.sdi.negdatawidth ||
  313                     it->it_offset != param.sdi.negoffset ||
  314                     it->it_syncrate != syncrate) {
  315                         it->it_width = param.sdi.negdatawidth;
  316                         it->it_offset = param.sdi.negoffset;
  317                         it->it_syncrate = syncrate;
  318 
  319                         printf("%s: target %d (tid %d): %d-bit, ",
  320                             sc->sc_dv.dv_xname, targ, tid, it->it_width);
  321                         if (it->it_syncrate == 0)
  322                                 printf("asynchronous\n");
  323                         else
  324                                 printf("synchronous at %dMHz, offset 0x%x\n",
  325                                     it->it_syncrate, it->it_offset);
  326                 }
  327 #endif
  328 
  329                 /* Ignore the device if it's in use by somebody else. */
  330                 if ((le32toh(le->usertid) & 4095) != I2O_TID_NONE) {
  331 #ifdef I2OVERBOSE
  332                         if (sc->sc_tidmap == NULL ||
  333                             IOPSP_TIDMAP(sc->sc_tidmap, targ, lun) !=
  334                             IOPSP_TID_INUSE)
  335                                 printf("%s: target %d,%d (tid %d): in use by"
  336                                     " tid %d\n", sc->sc_dv.dv_xname,
  337                                     targ, lun, tid,
  338                                     le32toh(le->usertid) & 4095);
  339 #endif
  340                         IOPSP_TIDMAP(tidmap, targ, lun) = IOPSP_TID_INUSE;
  341                 } else
  342                         IOPSP_TIDMAP(tidmap, targ, lun) = (u_short)tid;
  343         }
  344 
  345 #ifdef I2OVERBOSE
  346         for (i = 0; i < sc_chan->chan_ntargets; i++)
  347                 if ((sc->sc_targetmap[i].it_flags & IT_PRESENT) == 0)
  348                         sc->sc_targetmap[i].it_width = 0;
  349 #endif
  350 
  351         /* Swap in the new map and return. */
  352         s = splbio();
  353         if (sc->sc_tidmap != NULL)
  354                 free(sc->sc_tidmap, M_DEVBUF);
  355         sc->sc_tidmap = tidmap;
  356         splx(s);
  357         sc->sc_chgind = iop->sc_chgind;
  358         return (0);
  359 }
  360 
  361 /*
  362  * Re-scan the bus; to be called from a higher level (e.g. scsipi).
  363  */
  364 static int
  365 iopsp_rescan(struct iopsp_softc *sc)
  366 {
  367         struct iop_softc *iop;
  368         struct iop_msg *im;
  369         struct i2o_hba_bus_scan mf;
  370         int rv;
  371 
  372         iop = (struct iop_softc *)sc->sc_dv.dv_parent;
  373 
  374         rv = lockmgr(&iop->sc_conflock, LK_EXCLUSIVE, NULL);
  375         if (rv != 0) {
  376 #ifdef I2ODEBUG
  377                 printf("iopsp_rescan: unable to acquire lock\n");
  378 #endif
  379                 return (rv);
  380         }
  381 
  382         im = iop_msg_alloc(iop, IM_WAIT);
  383 
  384         mf.msgflags = I2O_MSGFLAGS(i2o_hba_bus_scan);
  385         mf.msgfunc = I2O_MSGFUNC(sc->sc_ii.ii_tid, I2O_HBA_BUS_SCAN);
  386         mf.msgictx = sc->sc_ii.ii_ictx;
  387         mf.msgtctx = im->im_tctx;
  388 
  389         rv = iop_msg_post(iop, im, &mf, 5*60*1000);
  390         iop_msg_free(iop, im);
  391         if (rv != 0)
  392                 printf("%s: bus rescan failed (error %d)\n",
  393                     sc->sc_dv.dv_xname, rv);
  394 
  395         if ((rv = iop_lct_get(iop)) == 0)
  396                 rv = iopsp_reconfig(&sc->sc_dv);
  397 
  398         lockmgr(&iop->sc_conflock, LK_RELEASE, NULL);
  399         return (rv);
  400 }
  401 
  402 /*
  403  * Start a SCSI command.
  404  */
  405 static void
  406 iopsp_scsipi_request(struct scsipi_channel *chan, scsipi_adapter_req_t req,
  407                      void *arg)
  408 {
  409         struct scsipi_xfer *xs;
  410         struct scsipi_periph *periph;
  411         struct iopsp_softc *sc;
  412         struct iop_msg *im;
  413         struct iop_softc *iop;
  414         struct i2o_scsi_scb_exec *mf;
  415         int error, flags, tid;
  416         u_int32_t mb[IOP_MAX_MSG_SIZE / sizeof(u_int32_t)];
  417 
  418         sc = (void *)chan->chan_adapter->adapt_dev;
  419         iop = (struct iop_softc *)sc->sc_dv.dv_parent;
  420 
  421         switch (req) {
  422         case ADAPTER_REQ_RUN_XFER:
  423                 xs = arg;
  424                 periph = xs->xs_periph;
  425                 flags = xs->xs_control;
  426 
  427                 SC_DEBUG(periph, SCSIPI_DB2, ("iopsp_scsi_request run_xfer\n"));
  428 
  429                 tid = IOPSP_TIDMAP(sc->sc_tidmap, periph->periph_target,
  430                     periph->periph_lun);
  431                 if (tid == IOPSP_TID_ABSENT || tid == IOPSP_TID_INUSE) {
  432                         xs->error = XS_SELTIMEOUT;
  433                         scsipi_done(xs);
  434                         return;
  435                 }
  436 
  437                 /* Need to reset the target? */
  438                 if ((flags & XS_CTL_RESET) != 0) {
  439                         if (iop_simple_cmd(iop, tid, I2O_SCSI_DEVICE_RESET,
  440                             sc->sc_ii.ii_ictx, 1, 30*1000) != 0) {
  441 #ifdef I2ODEBUG
  442                                 printf("%s: reset failed\n",
  443                                     sc->sc_dv.dv_xname);
  444 #endif
  445                                 xs->error = XS_DRIVER_STUFFUP;
  446                         } else
  447                                 xs->error = XS_NOERROR;
  448                                 
  449                         scsipi_done(xs);
  450                         return;
  451                 }
  452 
  453 #if defined(I2ODEBUG) || defined(SCSIDEBUG)
  454                 if (xs->cmdlen > sizeof(mf->cdb))
  455                         panic("%s: CDB too large", sc->sc_dv.dv_xname);
  456 #endif
  457 
  458                 im = iop_msg_alloc(iop, IM_POLL_INTR |
  459                     IM_NOSTATUS | ((flags & XS_CTL_POLL) != 0 ? IM_POLL : 0));
  460                 im->im_dvcontext = xs;
  461 
  462                 mf = (struct i2o_scsi_scb_exec *)mb;
  463                 mf->msgflags = I2O_MSGFLAGS(i2o_scsi_scb_exec);
  464                 mf->msgfunc = I2O_MSGFUNC(tid, I2O_SCSI_SCB_EXEC);
  465                 mf->msgictx = sc->sc_ii.ii_ictx;
  466                 mf->msgtctx = im->im_tctx;
  467                 mf->flags = xs->cmdlen | I2O_SCB_FLAG_ENABLE_DISCONNECT |
  468                     I2O_SCB_FLAG_SENSE_DATA_IN_MESSAGE;
  469                 mf->datalen = xs->datalen;
  470                 memcpy(mf->cdb, xs->cmd, xs->cmdlen);
  471 
  472                 switch (xs->xs_tag_type) {
  473                 case MSG_ORDERED_Q_TAG:
  474                         mf->flags |= I2O_SCB_FLAG_ORDERED_QUEUE_TAG;
  475                         break;
  476                 case MSG_SIMPLE_Q_TAG:
  477                         mf->flags |= I2O_SCB_FLAG_SIMPLE_QUEUE_TAG;
  478                         break;
  479                 case MSG_HEAD_OF_Q_TAG:
  480                         mf->flags |= I2O_SCB_FLAG_HEAD_QUEUE_TAG;
  481                         break;
  482                 default:
  483                         break;
  484                 }
  485 
  486                 if (xs->datalen != 0) {
  487                         error = iop_msg_map_bio(iop, im, mb, xs->data,
  488                             xs->datalen, (flags & XS_CTL_DATA_OUT) == 0);
  489                         if (error) {
  490                                 xs->error = XS_DRIVER_STUFFUP;
  491                                 iop_msg_free(iop, im);
  492                                 scsipi_done(xs);
  493                                 return;
  494                         }
  495                         if ((flags & XS_CTL_DATA_IN) == 0)
  496                                 mf->flags |= I2O_SCB_FLAG_XFER_TO_DEVICE;
  497                         else
  498                                 mf->flags |= I2O_SCB_FLAG_XFER_FROM_DEVICE;
  499                 }
  500 
  501                 if (iop_msg_post(iop, im, mb, xs->timeout)) {
  502                         if (xs->datalen != 0)
  503                                 iop_msg_unmap(iop, im);
  504                         iop_msg_free(iop, im);
  505                         xs->error = XS_DRIVER_STUFFUP;
  506                         scsipi_done(xs);
  507                 }
  508                 break;
  509 
  510         case ADAPTER_REQ_GROW_RESOURCES:
  511                 /*
  512                  * Not supported.
  513                  */
  514                 break;
  515 
  516         case ADAPTER_REQ_SET_XFER_MODE:
  517                 /*
  518                  * The DDM takes care of this, and we can't modify its
  519                  * behaviour.
  520                  */
  521                 break;
  522         }
  523 }
  524 
  525 #ifdef notyet
  526 /*
  527  * Abort the specified I2O_SCSI_SCB_EXEC message and its associated SCB.
  528  */
  529 static int
  530 iopsp_scsi_abort(struct iopsp_softc *sc, int atid, struct iop_msg *aim)
  531 {
  532         struct iop_msg *im;
  533         struct i2o_scsi_scb_abort mf;
  534         struct iop_softc *iop;
  535         int rv, s;
  536 
  537         iop = (struct iop_softc *)sc->sc_dv.dv_parent;
  538         im = iop_msg_alloc(iop, IM_POLL);
  539 
  540         mf.msgflags = I2O_MSGFLAGS(i2o_scsi_scb_abort);
  541         mf.msgfunc = I2O_MSGFUNC(atid, I2O_SCSI_SCB_ABORT);
  542         mf.msgictx = sc->sc_ii.ii_ictx;
  543         mf.msgtctx = im->im_tctx;
  544         mf.tctxabort = aim->im_tctx;
  545 
  546         s = splbio();
  547         rv = iop_msg_post(iop, im, &mf, 30000);
  548         splx(s);
  549         iop_msg_free(iop, im);
  550         return (rv);
  551 }
  552 #endif
  553 
  554 /*
  555  * We have a message which has been processed and replied to by the IOP -
  556  * deal with it.
  557  */
  558 static void
  559 iopsp_intr(struct device *dv, struct iop_msg *im, void *reply)
  560 {
  561         struct scsipi_xfer *xs;
  562         struct iopsp_softc *sc;
  563         struct i2o_scsi_reply *rb;
  564         struct iop_softc *iop;
  565         u_int sl;
  566 
  567         sc = (struct iopsp_softc *)dv;
  568         xs = (struct scsipi_xfer *)im->im_dvcontext;
  569         iop = (struct iop_softc *)dv->dv_parent;
  570         rb = reply;
  571 
  572         SC_DEBUG(xs->xs_periph, SCSIPI_DB2, ("iopsp_intr\n"));
  573 
  574         if ((rb->msgflags & I2O_MSGFLAGS_FAIL) != 0) {
  575                 xs->error = XS_DRIVER_STUFFUP;
  576                 xs->resid = xs->datalen;
  577         } else {
  578                 if (rb->hbastatus != I2O_SCSI_DSC_SUCCESS) {
  579                         switch (rb->hbastatus) {
  580                         case I2O_SCSI_DSC_ADAPTER_BUSY:
  581                         case I2O_SCSI_DSC_SCSI_BUS_RESET:
  582                         case I2O_SCSI_DSC_BUS_BUSY:
  583                                 xs->error = XS_BUSY;
  584                                 break;
  585                         case I2O_SCSI_DSC_SELECTION_TIMEOUT:
  586                                 xs->error = XS_SELTIMEOUT;
  587                                 break;
  588                         case I2O_SCSI_DSC_COMMAND_TIMEOUT:
  589                         case I2O_SCSI_DSC_DEVICE_NOT_PRESENT:
  590                         case I2O_SCSI_DSC_LUN_INVALID:
  591                         case I2O_SCSI_DSC_SCSI_TID_INVALID:
  592                                 xs->error = XS_TIMEOUT;
  593                                 break;
  594                         default:
  595                                 xs->error = XS_DRIVER_STUFFUP;
  596                                 break;
  597                         }
  598                         printf("%s: HBA status 0x%02x\n", sc->sc_dv.dv_xname,
  599                            rb->hbastatus);
  600                 } else if (rb->scsistatus != SCSI_OK) {
  601                         switch (rb->scsistatus) {
  602                         case SCSI_CHECK:
  603                                 xs->error = XS_SENSE;
  604                                 sl = le32toh(rb->senselen);
  605                                 if (sl > sizeof(xs->sense.scsi_sense))
  606                                         sl = sizeof(xs->sense.scsi_sense);
  607                                 memcpy(&xs->sense.scsi_sense, rb->sense, sl);
  608                                 break;
  609                         case SCSI_QUEUE_FULL:
  610                         case SCSI_BUSY:
  611                                 xs->error = XS_BUSY;
  612                                 break;
  613                         default:
  614                                 xs->error = XS_DRIVER_STUFFUP;
  615                                 break;
  616                         }
  617                 } else
  618                         xs->error = XS_NOERROR;
  619 
  620                 xs->resid = xs->datalen - le32toh(rb->datalen);
  621                 xs->status = rb->scsistatus;
  622         }
  623 
  624         /* Free the message wrapper and pass the news to scsipi. */
  625         if (xs->datalen != 0)
  626                 iop_msg_unmap(iop, im);
  627         iop_msg_free(iop, im);
  628 
  629         scsipi_done(xs);
  630 }
  631 
  632 /*
  633  * ioctl hook; used here only to initiate low-level rescans.
  634  */
  635 static int
  636 iopsp_ioctl(struct scsipi_channel *chan, u_long cmd, caddr_t data, int flag,
  637             struct proc *p)
  638 {
  639         int rv;
  640 
  641         switch (cmd) {
  642         case SCBUSIOLLSCAN:
  643                 /*
  644                  * If it's boot time, the bus will have been scanned and the
  645                  * maps built.  Locking would stop re-configuration, but we
  646                  * want to fake success.
  647                  */
  648                 if (p != &proc0)
  649                         rv = iopsp_rescan(
  650                            (struct iopsp_softc *)chan->chan_adapter->adapt_dev);
  651                 else
  652                         rv = 0;
  653                 break;
  654 
  655         default:
  656                 rv = ENOTTY;
  657                 break;
  658         }
  659 
  660         return (rv);
  661 }
  662 
  663 /*
  664  * The number of openings available to us has changed, so inform scsipi.
  665  */
  666 static void
  667 iopsp_adjqparam(struct device *dv, int mpi)
  668 {
  669         struct iopsp_softc *sc;
  670         int s;
  671 
  672         sc = (struct iopsp_softc *)dv;
  673 
  674         s = splbio();
  675         sc->sc_adapter.adapt_openings += mpi - sc->sc_openings;
  676         sc->sc_openings = mpi;
  677         splx(s);
  678 }

Cache object: b5bec6671f3779f868a2ce1af44757d8


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