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/nfsmb.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) 2005 Ruslan Ermilov
    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 
   27 #include <sys/cdefs.h>
   28 __FBSDID("$FreeBSD$");
   29 
   30 #include <sys/param.h>
   31 #include <sys/bus.h>
   32 #include <sys/kernel.h>
   33 #include <sys/lock.h>
   34 #include <sys/module.h>
   35 #include <sys/mutex.h>
   36 #include <sys/systm.h>
   37 
   38 #include <machine/bus.h>
   39 #include <machine/resource.h>
   40 #include <sys/rman.h>
   41 
   42 #include <dev/pci/pcivar.h>
   43 #include <dev/pci/pcireg.h>
   44 
   45 #include <dev/smbus/smbconf.h>
   46 #include "smbus_if.h"
   47 
   48 #define NFSMB_DEBUG(x)  if (nfsmb_debug) (x)
   49 
   50 #ifdef DEBUG
   51 static int nfsmb_debug = 1;
   52 #else
   53 static int nfsmb_debug = 0;
   54 #endif
   55 
   56 /* NVIDIA nForce2/3/4 MCP */
   57 #define NFSMB_VENDORID_NVIDIA           0x10de
   58 #define NFSMB_DEVICEID_NF2_SMB          0x0064
   59 #define NFSMB_DEVICEID_NF2_ULTRA_SMB    0x0084
   60 #define NFSMB_DEVICEID_NF3_PRO150_SMB   0x00d4
   61 #define NFSMB_DEVICEID_NF3_250GB_SMB    0x00e4
   62 #define NFSMB_DEVICEID_NF4_SMB          0x0052
   63 #define NFSMB_DEVICEID_NF4_04_SMB       0x0034
   64 #define NFSMB_DEVICEID_NF4_51_SMB       0x0264
   65 #define NFSMB_DEVICEID_NF4_55_SMB       0x0368
   66 #define NFSMB_DEVICEID_NF4_61_SMB       0x03eb
   67 #define NFSMB_DEVICEID_NF4_65_SMB       0x0446
   68 #define NFSMB_DEVICEID_NF4_67_SMB       0x0542
   69 #define NFSMB_DEVICEID_NF4_73_SMB       0x07d8
   70 #define NFSMB_DEVICEID_NF4_78S_SMB      0x0752
   71 #define NFSMB_DEVICEID_NF4_79_SMB       0x0aa2
   72 
   73 /* PCI Configuration space registers */
   74 #define NF2PCI_SMBASE_1         PCIR_BAR(4)
   75 #define NF2PCI_SMBASE_2         PCIR_BAR(5)
   76 
   77 /*
   78  * ACPI 3.0, Chapter 12, SMBus Host Controller Interface.
   79  */
   80 #define SMB_PRTCL               0x00    /* protocol */
   81 #define SMB_STS                 0x01    /* status */
   82 #define SMB_ADDR                0x02    /* address */
   83 #define SMB_CMD                 0x03    /* command */
   84 #define SMB_DATA                0x04    /* 32 data registers */
   85 #define SMB_BCNT                0x24    /* number of data bytes */
   86 #define SMB_ALRM_A              0x25    /* alarm address */
   87 #define SMB_ALRM_D              0x26    /* 2 bytes alarm data */
   88 
   89 #define SMB_STS_DONE            0x80
   90 #define SMB_STS_ALRM            0x40
   91 #define SMB_STS_RES             0x20
   92 #define SMB_STS_STATUS          0x1f
   93 #define SMB_STS_OK              0x00    /* OK */
   94 #define SMB_STS_UF              0x07    /* Unknown Failure */
   95 #define SMB_STS_DANA            0x10    /* Device Address Not Acknowledged */
   96 #define SMB_STS_DED             0x11    /* Device Error Detected */
   97 #define SMB_STS_DCAD            0x12    /* Device Command Access Denied */
   98 #define SMB_STS_UE              0x13    /* Unknown Error */
   99 #define SMB_STS_DAD             0x17    /* Device Access Denied */
  100 #define SMB_STS_T               0x18    /* Timeout */
  101 #define SMB_STS_HUP             0x19    /* Host Unsupported Protocol */
  102 #define SMB_STS_B               0x1A    /* Busy */
  103 #define SMB_STS_PEC             0x1F    /* PEC (CRC-8) Error */
  104 
  105 #define SMB_PRTCL_WRITE         0x00
  106 #define SMB_PRTCL_READ          0x01
  107 #define SMB_PRTCL_QUICK         0x02
  108 #define SMB_PRTCL_BYTE          0x04
  109 #define SMB_PRTCL_BYTE_DATA     0x06
  110 #define SMB_PRTCL_WORD_DATA     0x08
  111 #define SMB_PRTCL_BLOCK_DATA    0x0a
  112 #define SMB_PRTCL_PROC_CALL     0x0c
  113 #define SMB_PRTCL_BLOCK_PROC_CALL 0x0d
  114 #define SMB_PRTCL_PEC           0x80
  115 
  116 struct nfsmb_softc {
  117         int rid;
  118         struct resource *res;
  119         bus_space_tag_t smbst;
  120         bus_space_handle_t smbsh;
  121         device_t smbus;
  122         device_t subdev;
  123         struct mtx lock;
  124 };
  125 
  126 #define NFSMB_LOCK(nfsmb)               mtx_lock(&(nfsmb)->lock)
  127 #define NFSMB_UNLOCK(nfsmb)             mtx_unlock(&(nfsmb)->lock)
  128 #define NFSMB_LOCK_ASSERT(nfsmb)        mtx_assert(&(nfsmb)->lock, MA_OWNED)
  129 
  130 #define NFSMB_SMBINB(nfsmb, register)                                   \
  131         (bus_space_read_1(nfsmb->smbst, nfsmb->smbsh, register))
  132 #define NFSMB_SMBOUTB(nfsmb, register, value) \
  133         (bus_space_write_1(nfsmb->smbst, nfsmb->smbsh, register, value))
  134 
  135 static int      nfsmb_detach(device_t dev);
  136 static int      nfsmbsub_detach(device_t dev);
  137 
  138 static int
  139 nfsmbsub_probe(device_t dev)
  140 {
  141 
  142         device_set_desc(dev, "nForce2/3/4 MCP SMBus Controller");
  143         return (BUS_PROBE_DEFAULT);
  144 }
  145 
  146 static int
  147 nfsmb_probe(device_t dev)
  148 {
  149         u_int16_t vid;
  150         u_int16_t did;
  151 
  152         vid = pci_get_vendor(dev);
  153         did = pci_get_device(dev);
  154 
  155         if (vid == NFSMB_VENDORID_NVIDIA) {
  156                 switch(did) {
  157                 case NFSMB_DEVICEID_NF2_SMB:
  158                 case NFSMB_DEVICEID_NF2_ULTRA_SMB:
  159                 case NFSMB_DEVICEID_NF3_PRO150_SMB:
  160                 case NFSMB_DEVICEID_NF3_250GB_SMB:
  161                 case NFSMB_DEVICEID_NF4_SMB:
  162                 case NFSMB_DEVICEID_NF4_04_SMB:
  163                 case NFSMB_DEVICEID_NF4_51_SMB:
  164                 case NFSMB_DEVICEID_NF4_55_SMB:
  165                 case NFSMB_DEVICEID_NF4_61_SMB:
  166                 case NFSMB_DEVICEID_NF4_65_SMB:
  167                 case NFSMB_DEVICEID_NF4_67_SMB:
  168                 case NFSMB_DEVICEID_NF4_73_SMB:
  169                 case NFSMB_DEVICEID_NF4_78S_SMB:
  170                 case NFSMB_DEVICEID_NF4_79_SMB:
  171                         device_set_desc(dev, "nForce2/3/4 MCP SMBus Controller");
  172                         return (BUS_PROBE_DEFAULT);
  173                 }
  174         }
  175 
  176         return (ENXIO);
  177 }
  178 
  179 static int
  180 nfsmbsub_attach(device_t dev)
  181 {
  182         device_t parent;
  183         struct nfsmb_softc *nfsmbsub_sc = device_get_softc(dev);
  184 
  185         parent = device_get_parent(dev);
  186 
  187         nfsmbsub_sc->rid = NF2PCI_SMBASE_2;
  188 
  189         nfsmbsub_sc->res = bus_alloc_resource_any(parent, SYS_RES_IOPORT,
  190             &nfsmbsub_sc->rid, RF_ACTIVE);
  191         if (nfsmbsub_sc->res == NULL) {
  192                 /* Older incarnations of the device used non-standard BARs. */
  193                 nfsmbsub_sc->rid = 0x54;
  194                 nfsmbsub_sc->res = bus_alloc_resource_any(parent,
  195                     SYS_RES_IOPORT, &nfsmbsub_sc->rid, RF_ACTIVE);
  196                 if (nfsmbsub_sc->res == NULL) {
  197                         device_printf(dev, "could not map i/o space\n");
  198                         return (ENXIO);
  199                 }
  200         }
  201         nfsmbsub_sc->smbst = rman_get_bustag(nfsmbsub_sc->res);
  202         nfsmbsub_sc->smbsh = rman_get_bushandle(nfsmbsub_sc->res);
  203         mtx_init(&nfsmbsub_sc->lock, device_get_nameunit(dev), "nfsmb",
  204             MTX_DEF);
  205 
  206         nfsmbsub_sc->smbus = device_add_child(dev, "smbus", -1);
  207         if (nfsmbsub_sc->smbus == NULL) {
  208                 nfsmbsub_detach(dev);
  209                 return (EINVAL);
  210         }
  211 
  212         bus_generic_attach(dev);
  213 
  214         return (0);
  215 }
  216 
  217 static int
  218 nfsmb_attach(device_t dev)
  219 {
  220         struct nfsmb_softc *nfsmb_sc = device_get_softc(dev);
  221 
  222         /* Allocate I/O space */
  223         nfsmb_sc->rid = NF2PCI_SMBASE_1;
  224 
  225         nfsmb_sc->res = bus_alloc_resource_any(dev, SYS_RES_IOPORT,
  226                 &nfsmb_sc->rid, RF_ACTIVE);
  227 
  228         if (nfsmb_sc->res == NULL) {
  229                 /* Older incarnations of the device used non-standard BARs. */
  230                 nfsmb_sc->rid = 0x50;
  231                 nfsmb_sc->res = bus_alloc_resource_any(dev,
  232                     SYS_RES_IOPORT, &nfsmb_sc->rid, RF_ACTIVE);
  233                 if (nfsmb_sc->res == NULL) {
  234                         device_printf(dev, "could not map i/o space\n");
  235                         return (ENXIO);
  236                 }
  237         }
  238 
  239         nfsmb_sc->smbst = rman_get_bustag(nfsmb_sc->res);
  240         nfsmb_sc->smbsh = rman_get_bushandle(nfsmb_sc->res);
  241         mtx_init(&nfsmb_sc->lock, device_get_nameunit(dev), "nfsmb", MTX_DEF);
  242 
  243         /* Allocate a new smbus device */
  244         nfsmb_sc->smbus = device_add_child(dev, "smbus", -1);
  245         if (!nfsmb_sc->smbus) {
  246                 nfsmb_detach(dev);
  247                 return (EINVAL);
  248         }
  249 
  250         nfsmb_sc->subdev = NULL;
  251         switch (pci_get_device(dev)) {
  252         case NFSMB_DEVICEID_NF2_SMB:
  253         case NFSMB_DEVICEID_NF2_ULTRA_SMB:
  254         case NFSMB_DEVICEID_NF3_PRO150_SMB:
  255         case NFSMB_DEVICEID_NF3_250GB_SMB:
  256         case NFSMB_DEVICEID_NF4_SMB:
  257         case NFSMB_DEVICEID_NF4_04_SMB:
  258         case NFSMB_DEVICEID_NF4_51_SMB:
  259         case NFSMB_DEVICEID_NF4_55_SMB:
  260         case NFSMB_DEVICEID_NF4_61_SMB:
  261         case NFSMB_DEVICEID_NF4_65_SMB:
  262         case NFSMB_DEVICEID_NF4_67_SMB:
  263         case NFSMB_DEVICEID_NF4_73_SMB:
  264         case NFSMB_DEVICEID_NF4_78S_SMB:
  265         case NFSMB_DEVICEID_NF4_79_SMB:
  266                 /* Trying to add secondary device as slave */
  267                 nfsmb_sc->subdev = device_add_child(dev, "nfsmb", -1);
  268                 if (!nfsmb_sc->subdev) {
  269                         nfsmb_detach(dev);
  270                         return (EINVAL);
  271                 }
  272                 break;
  273         default:
  274                 break;
  275         }
  276 
  277         bus_generic_attach(dev);
  278 
  279         return (0);
  280 }
  281 
  282 static int
  283 nfsmbsub_detach(device_t dev)
  284 {
  285         device_t parent;
  286         struct nfsmb_softc *nfsmbsub_sc = device_get_softc(dev);
  287 
  288         parent = device_get_parent(dev);
  289 
  290         if (nfsmbsub_sc->smbus) {
  291                 device_delete_child(dev, nfsmbsub_sc->smbus);
  292                 nfsmbsub_sc->smbus = NULL;
  293         }
  294         mtx_destroy(&nfsmbsub_sc->lock);
  295         if (nfsmbsub_sc->res) {
  296                 bus_release_resource(parent, SYS_RES_IOPORT, nfsmbsub_sc->rid,
  297                     nfsmbsub_sc->res);
  298                 nfsmbsub_sc->res = NULL;
  299         }
  300         return (0);
  301 }
  302 
  303 static int
  304 nfsmb_detach(device_t dev)
  305 {
  306         struct nfsmb_softc *nfsmb_sc = device_get_softc(dev);
  307 
  308         if (nfsmb_sc->subdev) {
  309                 device_delete_child(dev, nfsmb_sc->subdev);
  310                 nfsmb_sc->subdev = NULL;
  311         }
  312 
  313         if (nfsmb_sc->smbus) {
  314                 device_delete_child(dev, nfsmb_sc->smbus);
  315                 nfsmb_sc->smbus = NULL;
  316         }
  317 
  318         mtx_destroy(&nfsmb_sc->lock);
  319         if (nfsmb_sc->res) {
  320                 bus_release_resource(dev, SYS_RES_IOPORT, nfsmb_sc->rid,
  321                     nfsmb_sc->res);
  322                 nfsmb_sc->res = NULL;
  323         }
  324 
  325         return (0);
  326 }
  327 
  328 static int
  329 nfsmb_callback(device_t dev, int index, void *data)
  330 {
  331         int error = 0;
  332 
  333         switch (index) {
  334         case SMB_REQUEST_BUS:
  335         case SMB_RELEASE_BUS:
  336                 break;
  337         default:
  338                 error = EINVAL;
  339         }
  340 
  341         return (error);
  342 }
  343 
  344 static int
  345 nfsmb_wait(struct nfsmb_softc *sc)
  346 {
  347         u_char sts;
  348         int error, count;
  349 
  350         NFSMB_LOCK_ASSERT(sc);
  351         if (NFSMB_SMBINB(sc, SMB_PRTCL) != 0)
  352         {
  353                 count = 10000;
  354                 do {
  355                         DELAY(500);
  356                 } while (NFSMB_SMBINB(sc, SMB_PRTCL) != 0 && count--);
  357                 if (count == 0)
  358                         return (SMB_ETIMEOUT);
  359         }
  360 
  361         sts = NFSMB_SMBINB(sc, SMB_STS) & SMB_STS_STATUS;
  362         NFSMB_DEBUG(printf("nfsmb: STS=0x%x\n", sts));
  363 
  364         switch (sts) {
  365         case SMB_STS_OK:
  366                 error = SMB_ENOERR;
  367                 break;
  368         case SMB_STS_DANA:
  369                 error = SMB_ENOACK;
  370                 break;
  371         case SMB_STS_B:
  372                 error = SMB_EBUSY;
  373                 break;
  374         case SMB_STS_T:
  375                 error = SMB_ETIMEOUT;
  376                 break;
  377         case SMB_STS_DCAD:
  378         case SMB_STS_DAD:
  379         case SMB_STS_HUP:
  380                 error = SMB_ENOTSUPP;
  381                 break;
  382         default:
  383                 error = SMB_EBUSERR;
  384                 break;
  385         }
  386 
  387         return (error);
  388 }
  389 
  390 static int
  391 nfsmb_quick(device_t dev, u_char slave, int how)
  392 {
  393         struct nfsmb_softc *sc = (struct nfsmb_softc *)device_get_softc(dev);
  394         u_char protocol;
  395         int error;
  396 
  397         protocol = SMB_PRTCL_QUICK;
  398 
  399         switch (how) {
  400         case SMB_QWRITE:
  401                 protocol |= SMB_PRTCL_WRITE;
  402                 NFSMB_DEBUG(printf("nfsmb: QWRITE to 0x%x", slave));
  403                 break;
  404         case SMB_QREAD:
  405                 protocol |= SMB_PRTCL_READ;
  406                 NFSMB_DEBUG(printf("nfsmb: QREAD to 0x%x", slave));
  407                 break;
  408         default:
  409                 panic("%s: unknown QUICK command (%x)!", __func__, how);
  410         }
  411 
  412         NFSMB_LOCK(sc);
  413         NFSMB_SMBOUTB(sc, SMB_ADDR, slave);
  414         NFSMB_SMBOUTB(sc, SMB_PRTCL, protocol);
  415 
  416         error = nfsmb_wait(sc);
  417 
  418         NFSMB_DEBUG(printf(", error=0x%x\n", error));
  419         NFSMB_UNLOCK(sc);
  420 
  421         return (error);
  422 }
  423 
  424 static int
  425 nfsmb_sendb(device_t dev, u_char slave, char byte)
  426 {
  427         struct nfsmb_softc *sc = (struct nfsmb_softc *)device_get_softc(dev);
  428         int error;
  429 
  430         NFSMB_LOCK(sc);
  431         NFSMB_SMBOUTB(sc, SMB_CMD, byte);
  432         NFSMB_SMBOUTB(sc, SMB_ADDR, slave);
  433         NFSMB_SMBOUTB(sc, SMB_PRTCL, SMB_PRTCL_WRITE | SMB_PRTCL_BYTE);
  434 
  435         error = nfsmb_wait(sc);
  436 
  437         NFSMB_DEBUG(printf("nfsmb: SENDB to 0x%x, byte=0x%x, error=0x%x\n", slave, byte, error));
  438         NFSMB_UNLOCK(sc);
  439 
  440         return (error);
  441 }
  442 
  443 static int
  444 nfsmb_recvb(device_t dev, u_char slave, char *byte)
  445 {
  446         struct nfsmb_softc *sc = (struct nfsmb_softc *)device_get_softc(dev);
  447         int error;
  448 
  449         NFSMB_LOCK(sc);
  450         NFSMB_SMBOUTB(sc, SMB_ADDR, slave);
  451         NFSMB_SMBOUTB(sc, SMB_PRTCL, SMB_PRTCL_READ | SMB_PRTCL_BYTE);
  452 
  453         if ((error = nfsmb_wait(sc)) == SMB_ENOERR)
  454                 *byte = NFSMB_SMBINB(sc, SMB_DATA);
  455 
  456         NFSMB_DEBUG(printf("nfsmb: RECVB from 0x%x, byte=0x%x, error=0x%x\n", slave, *byte, error));
  457         NFSMB_UNLOCK(sc);
  458 
  459         return (error);
  460 }
  461 
  462 static int
  463 nfsmb_writeb(device_t dev, u_char slave, char cmd, char byte)
  464 {
  465         struct nfsmb_softc *sc = (struct nfsmb_softc *)device_get_softc(dev);
  466         int error;
  467 
  468         NFSMB_LOCK(sc);
  469         NFSMB_SMBOUTB(sc, SMB_CMD, cmd);
  470         NFSMB_SMBOUTB(sc, SMB_DATA, byte);
  471         NFSMB_SMBOUTB(sc, SMB_ADDR, slave);
  472         NFSMB_SMBOUTB(sc, SMB_PRTCL, SMB_PRTCL_WRITE | SMB_PRTCL_BYTE_DATA);
  473 
  474         error = nfsmb_wait(sc);
  475 
  476         NFSMB_DEBUG(printf("nfsmb: WRITEB to 0x%x, cmd=0x%x, byte=0x%x, error=0x%x\n", slave, cmd, byte, error));
  477         NFSMB_UNLOCK(sc);
  478 
  479         return (error);
  480 }
  481 
  482 static int
  483 nfsmb_readb(device_t dev, u_char slave, char cmd, char *byte)
  484 {
  485         struct nfsmb_softc *sc = (struct nfsmb_softc *)device_get_softc(dev);
  486         int error;
  487 
  488         NFSMB_LOCK(sc);
  489         NFSMB_SMBOUTB(sc, SMB_CMD, cmd);
  490         NFSMB_SMBOUTB(sc, SMB_ADDR, slave);
  491         NFSMB_SMBOUTB(sc, SMB_PRTCL, SMB_PRTCL_READ | SMB_PRTCL_BYTE_DATA);
  492 
  493         if ((error = nfsmb_wait(sc)) == SMB_ENOERR)
  494                 *byte = NFSMB_SMBINB(sc, SMB_DATA);
  495 
  496         NFSMB_DEBUG(printf("nfsmb: READB from 0x%x, cmd=0x%x, byte=0x%x, error=0x%x\n", slave, cmd, (unsigned char)*byte, error));
  497         NFSMB_UNLOCK(sc);
  498 
  499         return (error);
  500 }
  501 
  502 static int
  503 nfsmb_writew(device_t dev, u_char slave, char cmd, short word)
  504 {
  505         struct nfsmb_softc *sc = (struct nfsmb_softc *)device_get_softc(dev);
  506         int error;
  507 
  508         NFSMB_LOCK(sc);
  509         NFSMB_SMBOUTB(sc, SMB_CMD, cmd);
  510         NFSMB_SMBOUTB(sc, SMB_DATA, word);
  511         NFSMB_SMBOUTB(sc, SMB_DATA + 1, word >> 8);
  512         NFSMB_SMBOUTB(sc, SMB_ADDR, slave);
  513         NFSMB_SMBOUTB(sc, SMB_PRTCL, SMB_PRTCL_WRITE | SMB_PRTCL_WORD_DATA);
  514 
  515         error = nfsmb_wait(sc);
  516 
  517         NFSMB_DEBUG(printf("nfsmb: WRITEW to 0x%x, cmd=0x%x, word=0x%x, error=0x%x\n", slave, cmd, word, error));
  518         NFSMB_UNLOCK(sc);
  519 
  520         return (error);
  521 }
  522 
  523 static int
  524 nfsmb_readw(device_t dev, u_char slave, char cmd, short *word)
  525 {
  526         struct nfsmb_softc *sc = (struct nfsmb_softc *)device_get_softc(dev);
  527         int error;
  528 
  529         NFSMB_LOCK(sc);
  530         NFSMB_SMBOUTB(sc, SMB_CMD, cmd);
  531         NFSMB_SMBOUTB(sc, SMB_ADDR, slave);
  532         NFSMB_SMBOUTB(sc, SMB_PRTCL, SMB_PRTCL_READ | SMB_PRTCL_WORD_DATA);
  533 
  534         if ((error = nfsmb_wait(sc)) == SMB_ENOERR)
  535                 *word = NFSMB_SMBINB(sc, SMB_DATA) |
  536                     (NFSMB_SMBINB(sc, SMB_DATA + 1) << 8);
  537 
  538         NFSMB_DEBUG(printf("nfsmb: READW from 0x%x, cmd=0x%x, word=0x%x, error=0x%x\n", slave, cmd, (unsigned short)*word, error));
  539         NFSMB_UNLOCK(sc);
  540 
  541         return (error);
  542 }
  543 
  544 static int
  545 nfsmb_bwrite(device_t dev, u_char slave, char cmd, u_char count, char *buf)
  546 {
  547         struct nfsmb_softc *sc = (struct nfsmb_softc *)device_get_softc(dev);
  548         u_char i;
  549         int error;
  550 
  551         if (count < 1 || count > 32)
  552                 return (SMB_EINVAL);
  553 
  554         NFSMB_LOCK(sc);
  555         NFSMB_SMBOUTB(sc, SMB_CMD, cmd);
  556         NFSMB_SMBOUTB(sc, SMB_BCNT, count);
  557         for (i = 0; i < count; i++)
  558                 NFSMB_SMBOUTB(sc, SMB_DATA + i, buf[i]);
  559         NFSMB_SMBOUTB(sc, SMB_ADDR, slave);
  560         NFSMB_SMBOUTB(sc, SMB_PRTCL, SMB_PRTCL_WRITE | SMB_PRTCL_BLOCK_DATA);
  561 
  562         error = nfsmb_wait(sc);
  563 
  564         NFSMB_DEBUG(printf("nfsmb: WRITEBLK to 0x%x, count=0x%x, cmd=0x%x, error=0x%x", slave, count, cmd, error));
  565         NFSMB_UNLOCK(sc);
  566 
  567         return (error);
  568 }
  569 
  570 static int
  571 nfsmb_bread(device_t dev, u_char slave, char cmd, u_char *count, char *buf)
  572 {
  573         struct nfsmb_softc *sc = (struct nfsmb_softc *)device_get_softc(dev);
  574         u_char data, len, i;
  575         int error;
  576 
  577         if (*count < 1 || *count > 32)
  578                 return (SMB_EINVAL);
  579 
  580         NFSMB_LOCK(sc);
  581         NFSMB_SMBOUTB(sc, SMB_CMD, cmd);
  582         NFSMB_SMBOUTB(sc, SMB_ADDR, slave);
  583         NFSMB_SMBOUTB(sc, SMB_PRTCL, SMB_PRTCL_READ | SMB_PRTCL_BLOCK_DATA);
  584 
  585         if ((error = nfsmb_wait(sc)) == SMB_ENOERR) {
  586                 len = NFSMB_SMBINB(sc, SMB_BCNT);
  587                 for (i = 0; i < len; i++) {
  588                         data = NFSMB_SMBINB(sc, SMB_DATA + i);
  589                         if (i < *count)
  590                                 buf[i] = data;
  591                 }
  592                 *count = len;
  593         }
  594 
  595         NFSMB_DEBUG(printf("nfsmb: READBLK to 0x%x, count=0x%x, cmd=0x%x, error=0x%x", slave, *count, cmd, error));
  596         NFSMB_UNLOCK(sc);
  597 
  598         return (error);
  599 }
  600 
  601 static device_method_t nfsmb_methods[] = {
  602         /* Device interface */
  603         DEVMETHOD(device_probe,         nfsmb_probe),
  604         DEVMETHOD(device_attach,        nfsmb_attach),
  605         DEVMETHOD(device_detach,        nfsmb_detach),
  606 
  607         /* SMBus interface */
  608         DEVMETHOD(smbus_callback,       nfsmb_callback),
  609         DEVMETHOD(smbus_quick,          nfsmb_quick),
  610         DEVMETHOD(smbus_sendb,          nfsmb_sendb),
  611         DEVMETHOD(smbus_recvb,          nfsmb_recvb),
  612         DEVMETHOD(smbus_writeb,         nfsmb_writeb),
  613         DEVMETHOD(smbus_readb,          nfsmb_readb),
  614         DEVMETHOD(smbus_writew,         nfsmb_writew),
  615         DEVMETHOD(smbus_readw,          nfsmb_readw),
  616         DEVMETHOD(smbus_bwrite,         nfsmb_bwrite),
  617         DEVMETHOD(smbus_bread,          nfsmb_bread),
  618 
  619         { 0, 0 }
  620 };
  621 
  622 static device_method_t nfsmbsub_methods[] = {
  623         /* Device interface */
  624         DEVMETHOD(device_probe,         nfsmbsub_probe),
  625         DEVMETHOD(device_attach,        nfsmbsub_attach),
  626         DEVMETHOD(device_detach,        nfsmbsub_detach),
  627 
  628         /* SMBus interface */
  629         DEVMETHOD(smbus_callback,       nfsmb_callback),
  630         DEVMETHOD(smbus_quick,          nfsmb_quick),
  631         DEVMETHOD(smbus_sendb,          nfsmb_sendb),
  632         DEVMETHOD(smbus_recvb,          nfsmb_recvb),
  633         DEVMETHOD(smbus_writeb,         nfsmb_writeb),
  634         DEVMETHOD(smbus_readb,          nfsmb_readb),
  635         DEVMETHOD(smbus_writew,         nfsmb_writew),
  636         DEVMETHOD(smbus_readw,          nfsmb_readw),
  637         DEVMETHOD(smbus_bwrite,         nfsmb_bwrite),
  638         DEVMETHOD(smbus_bread,          nfsmb_bread),
  639 
  640         { 0, 0 }
  641 };
  642 
  643 static devclass_t nfsmb_devclass;
  644 
  645 static driver_t nfsmb_driver = {
  646         "nfsmb",
  647         nfsmb_methods,
  648         sizeof(struct nfsmb_softc),
  649 };
  650 
  651 static driver_t nfsmbsub_driver = {
  652         "nfsmb",
  653         nfsmbsub_methods,
  654         sizeof(struct nfsmb_softc),
  655 };
  656 
  657 DRIVER_MODULE(nfsmb, pci, nfsmb_driver, nfsmb_devclass, 0, 0);
  658 DRIVER_MODULE(nfsmb, nfsmb, nfsmbsub_driver, nfsmb_devclass, 0, 0);
  659 DRIVER_MODULE(smbus, nfsmb, smbus_driver, smbus_devclass, 0, 0);
  660 
  661 MODULE_DEPEND(nfsmb, pci, 1, 1, 1);
  662 MODULE_DEPEND(nfsmb, smbus, SMBUS_MINVER, SMBUS_PREFVER, SMBUS_MAXVER);
  663 MODULE_VERSION(nfsmb, 1);

Cache object: 9e31616b2bcf32ca2d0a738ff1dbe79c


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