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/pci/simos.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) 1998 Doug Rabson
    3  * All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  * 1. Redistributions of source code must retain the above copyright
    9  *    notice, this list of conditions and the following disclaimer.
   10  * 2. Redistributions in binary form must reproduce the above copyright
   11  *    notice, this list of conditions and the following disclaimer in the
   12  *    documentation and/or other materials provided with the distribution.
   13  *
   14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   24  * SUCH DAMAGE.
   25  *
   26  * $FreeBSD: releng/5.0/sys/pci/simos.c 103592 2002-09-19 03:40:17Z peter $
   27  */
   28 
   29 #ifdef COMPILING_LINT
   30 #warning "The simos driver is broken and is not compiled with LINT"
   31 #else
   32 
   33 #include <sys/param.h>
   34 #include <sys/systm.h>
   35 #include <sys/malloc.h>
   36 #include <sys/bio.h>
   37 #include <sys/buf.h>
   38 #include <sys/proc.h>
   39 
   40 #include <cam/cam.h>
   41 #include <cam/cam_ccb.h>
   42 #include <cam/cam_sim.h>
   43 #include <cam/cam_xpt_sim.h>
   44 #include <cam/cam_debug.h>
   45 
   46 #include <cam/scsi/scsi_all.h>
   47 #include <cam/scsi/scsi_message.h>
   48 
   49 #include <machine/clock.h>
   50 #include <vm/vm.h>
   51 #include <vm/vm_param.h>
   52 #include <vm/pmap.h>
   53 #include <sys/kernel.h>
   54 
   55 #include <pci/simos.h>
   56 
   57 #include <pci/pcireg.h>
   58 #include <pci/pcivar.h>
   59 
   60 #ifndef COMPAT_OLDPCI
   61 #error "The simos device requires the old pci compatibility shims"
   62 #endif
   63 
   64 #include <machine/alpha_cpu.h>
   65 
   66 struct simos_softc {
   67         int                     sc_unit;
   68         SimOS_SCSI*             sc_regs;
   69 
   70         /*
   71          * SimOS only supports one pending command.
   72          */
   73         struct cam_sim         *sc_sim;
   74         struct cam_path        *sc_path;
   75         struct ccb_scsiio      *sc_pending;
   76 };
   77 
   78 struct simos_softc* simosp[10];
   79 
   80 static u_long simos_unit;
   81 
   82 static const char *simos_probe(pcici_t tag, pcidi_t type);
   83 static void simos_attach(pcici_t config_d, int unit);
   84 static void simos_action(struct cam_sim *sim, union ccb *ccb);
   85 static void simos_poll(struct cam_sim *sim);
   86 
   87 struct pci_device simos_driver = {
   88         "simos",
   89         simos_probe,
   90         simos_attach,
   91         &simos_unit,
   92         NULL
   93 };
   94 COMPAT_PCI_DRIVER (simos, simos_driver);
   95 
   96 static const char *
   97 simos_probe(pcici_t tag, pcidi_t type)
   98 {       
   99         switch (type) {
  100         case 0x1291|(0x1291<<16):
  101                 return "SimOS SCSI";
  102         default:
  103                 return NULL;
  104         }
  105                 
  106 }
  107 
  108 static void    
  109 simos_attach(pcici_t config_id, int unit)
  110 {
  111         struct simos_softc* sc;
  112         struct cam_devq *devq;
  113 
  114         sc = malloc(sizeof(struct simos_softc), M_DEVBUF, M_WAITOK | M_ZERO);
  115         simosp[unit] = sc;
  116 
  117         sc->sc_unit = unit;
  118         sc->sc_regs = (SimOS_SCSI*) SIMOS_SCSI_ADDR;
  119         sc->sc_pending = 0;
  120 
  121         devq = cam_simq_alloc(/*maxopenings*/1);
  122         if (devq == NULL)
  123                 return;
  124 
  125         sc->sc_sim = cam_sim_alloc(simos_action, simos_poll, "simos", sc, unit,
  126                                    /*untagged*/1, /*tagged*/0, devq);
  127         if (sc->sc_sim == NULL) {
  128                 cam_simq_free(devq);
  129                 return;
  130         }
  131 
  132         if (xpt_bus_register(sc->sc_sim, /*bus*/0) != CAM_SUCCESS) {
  133                 cam_sim_free(sc->sc_sim, /*free_devq*/TRUE);
  134                 return;
  135         }
  136 
  137         if (xpt_create_path(&sc->sc_path, /*periph*/NULL,
  138                             cam_sim_path(sc->sc_sim), CAM_TARGET_WILDCARD,
  139                             CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
  140                 xpt_bus_deregister(cam_sim_path(sc->sc_sim));
  141                 cam_sim_free(sc->sc_sim, /*free_devq*/TRUE);
  142                 return;
  143         }
  144 
  145         alpha_register_pci_scsi(config_id->bus, config_id->slot, sc->sc_sim);
  146 
  147         return;
  148 }
  149 
  150 static void
  151 simos_start(struct simos_softc* sc, struct ccb_scsiio *csio)
  152 {
  153         struct scsi_generic *cmd;
  154         int cmdlen;
  155         caddr_t data;
  156         int datalen;
  157         int s;
  158         u_int8_t* p;
  159         int i, count, target;
  160         vm_offset_t va;
  161         vm_size_t size;
  162 
  163         cmd = (struct scsi_generic *) &csio->cdb_io.cdb_bytes;
  164         cmdlen = csio->cdb_len;
  165         data = csio->data_ptr;
  166         datalen = csio->dxfer_len;
  167 
  168         /*
  169          * Simos doesn't understand some commands
  170          */
  171         if (cmd->opcode == START_STOP || cmd->opcode == PREVENT_ALLOW
  172             || cmd->opcode == SYNCHRONIZE_CACHE) {
  173                 csio->ccb_h.status = CAM_REQ_CMP;
  174                 xpt_done((union ccb *) csio);
  175                 return;
  176         }
  177 
  178         if (sc->sc_pending) {
  179                 /*
  180                  * Don't think this can happen.
  181                  */
  182                 printf("simos_start: can't start command while one is pending\n");
  183                 csio->ccb_h.status = CAM_BUSY;
  184                 xpt_done((union ccb *) csio);
  185                 return;
  186         }
  187 
  188         s = splcam();
  189         
  190         csio->ccb_h.status |= CAM_SIM_QUEUED;
  191         sc->sc_pending = csio;
  192 
  193         target = csio->ccb_h.target_id;
  194 
  195         /*
  196          * Copy the command into SimOS' buffer
  197          */
  198         p = (u_int8_t*) cmd;
  199         count = cmdlen;
  200         for (i = 0; i < count; i++)
  201                 sc->sc_regs->cmd[i] = *p++;
  202         sc->sc_regs->length = count;
  203         sc->sc_regs->target = target;
  204         sc->sc_regs->lun = csio->ccb_h.target_lun;
  205 
  206         /*
  207          * Setup the segment descriptors.
  208          */
  209         va = (vm_offset_t) data;
  210         size = datalen;
  211         i = 0;
  212         while (size > 0) {
  213                 vm_size_t len = PAGE_SIZE - (va & PAGE_MASK);
  214                 if (len > size)
  215                         len = size;
  216                 sc->sc_regs->sgMap[i].pAddr = vtophys(va);
  217                 sc->sc_regs->sgMap[i].len = len;
  218                 size -= len;
  219                 va += len;
  220                 i++;
  221         }
  222         sc->sc_regs->sgLen = i;
  223 
  224         /*
  225          * Start the i/o.
  226          */
  227         alpha_wmb();
  228         sc->sc_regs->startIO = 1;
  229         alpha_wmb();
  230 
  231         splx(s);
  232 }
  233 
  234 static void
  235 simos_done(struct simos_softc* sc)
  236 {
  237         struct ccb_scsiio* csio = sc->sc_pending;
  238         int s, done;
  239 
  240         /*
  241          * Spurious interrupt caused by my bogus interrupt broadcasting.
  242          */
  243         if (!csio)
  244                 return;
  245 
  246         sc->sc_pending = 0;
  247 
  248         done = sc->sc_regs->done[csio->ccb_h.target_id];
  249         if (!done)
  250                 return;
  251 
  252         s = splcam();
  253 
  254         if (done >> 16)
  255                 /* Error detected */
  256                 csio->ccb_h.status = CAM_CMD_TIMEOUT;
  257         else
  258                 csio->ccb_h.status = CAM_REQ_CMP;
  259 
  260         /*
  261          * Ack the interrupt to clear it.
  262          */
  263         sc->sc_regs->done[csio->ccb_h.target_id] = 1;
  264         alpha_wmb();
  265         
  266         xpt_done((union ccb *) csio);
  267 
  268         splx(s);
  269 }
  270 
  271 static void
  272 simos_action(struct cam_sim *sim, union ccb *ccb)
  273 {
  274         struct simos_softc* sc = (struct simos_softc *)sim->softc;
  275 
  276         switch (ccb->ccb_h.func_code) {
  277         case XPT_SCSI_IO:
  278         {
  279                 struct ccb_scsiio *csio;
  280 
  281                 csio = &ccb->csio;
  282                 simos_start(sc, csio);
  283                 break;
  284         }
  285 
  286         case XPT_CALC_GEOMETRY:
  287         {
  288                 struct    ccb_calc_geometry *ccg;
  289                 u_int32_t size_mb;
  290                 u_int32_t secs_per_cylinder;
  291 
  292                 ccg = &ccb->ccg;
  293                 size_mb = ccg->volume_size
  294                         / ((1024L * 1024L) / ccg->block_size);
  295 
  296                 ccg->heads = 64;
  297                 ccg->secs_per_track = 32;
  298 
  299                 secs_per_cylinder = ccg->heads * ccg->secs_per_track;
  300                 ccg->cylinders = ccg->volume_size / secs_per_cylinder;
  301 
  302                 ccb->ccb_h.status = CAM_REQ_CMP;
  303                 xpt_done(ccb);
  304                 break;
  305         }
  306 
  307         case XPT_RESET_BUS:
  308         {
  309                 ccb->ccb_h.status = CAM_REQ_CMP;
  310                 xpt_done(ccb);
  311                 break;
  312         }
  313 
  314         case XPT_PATH_INQ:
  315         {
  316                 struct ccb_pathinq *cpi = &ccb->cpi;
  317                 
  318                 cpi->version_num = 1; /* XXX??? */
  319                 cpi->max_target = 2;
  320                 cpi->max_lun = 0;
  321                 cpi->initiator_id = 7;
  322                 cpi->bus_id = sim->bus_id;
  323                 cpi->base_transfer_speed = 3300;
  324                 strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
  325                 strncpy(cpi->hba_vid, "SimOS", HBA_IDLEN);
  326                 strncpy(cpi->dev_name, sim->sim_name, DEV_IDLEN);
  327                 cpi->unit_number = sim->unit_number;
  328 
  329                 cpi->ccb_h.status = CAM_REQ_CMP;
  330                 xpt_done(ccb);
  331                 break;
  332         }
  333 
  334         default:
  335                 ccb->ccb_h.status = CAM_REQ_INVALID;
  336                 xpt_done(ccb);
  337                 break;
  338         }
  339 }
  340 
  341 static void
  342 simos_poll(struct cam_sim *sim)
  343 {       
  344         simos_done(cam_sim_softc(sim));
  345 }
  346 
  347 void
  348 simos_intr(int unit)
  349 {
  350         /* XXX bogus */
  351         struct simos_softc* sc = simosp[unit];
  352 
  353         simos_done(sc);
  354 }
  355 
  356 
  357 #endif /* !COMPILING_LINT */

Cache object: c38a0a6067b4280ee95d2eb2239fd3d8


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