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/lnc/if_lnc_cbus.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) 1994-2000
    3  *      Paul Richards. All rights reserved.
    4  *
    5  * PC-98 port by Chiharu Shibata & FreeBSD(98) porting team.
    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  *    verbatim and that no modifications are made prior to this
   13  *    point in the file.
   14  * 2. Redistributions in binary form must reproduce the above copyright
   15  *    notice, this list of conditions and the following disclaimer in the
   16  *    documentation and/or other materials provided with the distribution.
   17  * 3. The name Paul Richards may not be used to endorse or promote products
   18  *    derived from this software without specific prior written permission.
   19  *
   20  * THIS SOFTWARE IS PROVIDED BY PAUL RICHARDS ``AS IS'' AND
   21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   23  * ARE DISCLAIMED.  IN NO EVENT SHALL PAUL RICHARDS BE LIABLE
   24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   30  * SUCH DAMAGE.
   31  *
   32  */
   33 
   34 #include <sys/cdefs.h>
   35 __FBSDID("$FreeBSD$");
   36 
   37 #include <sys/param.h>
   38 #include <sys/systm.h>
   39 #include <sys/bus.h>
   40 #include <sys/kernel.h>
   41 #include <sys/module.h>
   42 #include <sys/malloc.h>
   43 #include <sys/socket.h>
   44 
   45 #include <machine/clock.h>      /* DELAY() */
   46 #include <machine/bus.h>
   47 #include <machine/resource.h>
   48 #include <sys/rman.h>
   49 
   50 #include <net/ethernet.h>
   51 #include <net/if.h>
   52 #include <net/if_arp.h>
   53 
   54 #include <isa/isavar.h>
   55 
   56 #include <dev/lnc/if_lncvar.h>
   57 #include <dev/lnc/if_lncreg.h>
   58 
   59 static struct isa_pnp_id lnc_pnp_ids[] = {
   60         {0,     NULL}
   61 };
   62 
   63 static bus_addr_t lnc_ioaddr_cnet98s[CNET98S_IOSIZE] = {
   64         0x000, 0x001, 0x002, 0x003, 0x004, 0x005, 0x006, 0x007,
   65         0x008, 0x009, 0x00a, 0x00b, 0x00c, 0x00d, 0x00e, 0x00f,
   66         0x400, 0x401, 0x402, 0x403, 0x404, 0x405, 0x406, 0x407,
   67         0x408, 0x409, 0x40a, 0x40b, 0x40c, 0x40d, 0x40e, 0x40f,
   68 };
   69 
   70 static int
   71 lnc_legacy_probe(device_t dev)
   72 {
   73         struct lnc_softc *sc = device_get_softc(dev);
   74         u_int16_t tmp;
   75 
   76         sc->portrid = 0;
   77         sc->portres = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &sc->portrid,
   78                                           lnc_ioaddr_cnet98s, CNET98S_IOSIZE,
   79                                           RF_ACTIVE);
   80 
   81         if (! sc->portres) {
   82                 device_printf(dev, "Failed to allocate I/O ports\n");
   83                 lnc_release_resources(dev);
   84                 return (ENXIO);
   85         }
   86 
   87         isa_load_resourcev(sc->portres, lnc_ioaddr_cnet98s, CNET98S_IOSIZE);
   88 
   89         sc->lnc_btag = rman_get_bustag(sc->portres);
   90         sc->lnc_bhandle = rman_get_bushandle(sc->portres);
   91 
   92         /* Reset */
   93         tmp = lnc_inw(CNET98S_RESET);
   94         lnc_outw(CNET98S_RESET, tmp);
   95         DELAY(500);
   96 
   97         sc->rap = CNET98S_RAP;
   98         sc->rdp = CNET98S_RDP;
   99         sc->nic.mem_mode = DMA_FIXED;
  100 
  101         if ((sc->nic.ic = lance_probe(sc))) {
  102                 sc->nic.ident = CNET98S;
  103                 device_set_desc(dev, "C-NET(98)S");
  104                 lnc_release_resources(dev);
  105                 return (0);
  106         } else {
  107                 lnc_release_resources(dev);
  108                 return (ENXIO);
  109         }
  110 }
  111 
  112 static int
  113 lnc_isa_probe(device_t dev)
  114 {
  115         int pnp;
  116 
  117         pnp = ISA_PNP_PROBE(device_get_parent(dev), dev, lnc_pnp_ids);
  118         if (pnp == ENOENT) {
  119                 /* It's not a PNP card, see if we support it by probing it */
  120                 return (lnc_legacy_probe(dev));
  121         } else if (pnp == ENXIO) {
  122                 return (ENXIO);
  123         } else {
  124                 /* Found PNP card we support */
  125                 return (0);
  126         }
  127 }
  128 
  129 static void
  130 lnc_alloc_callback(void *arg, bus_dma_segment_t *seg, int nseg, int error)
  131 {
  132         /* Do nothing */
  133         return;
  134 }
  135 
  136 static int
  137 lnc_isa_attach(device_t dev)
  138 {
  139         lnc_softc_t *sc = device_get_softc(dev);
  140         int err = 0;
  141         bus_size_t lnc_mem_size;
  142 
  143         device_printf(dev, "Attaching %s\n", device_get_desc(dev));
  144 
  145         sc->portrid = 0;
  146         sc->portres = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &sc->portrid,
  147                                           lnc_ioaddr_cnet98s, CNET98S_IOSIZE,
  148                                           RF_ACTIVE);
  149 
  150         if (! sc->portres) {
  151                 device_printf(dev, "Failed to allocate I/O ports\n");
  152                 lnc_release_resources(dev);
  153                 return (ENXIO);
  154         }
  155 
  156         isa_load_resourcev(sc->portres, lnc_ioaddr_cnet98s, CNET98S_IOSIZE);
  157 
  158         sc->lnc_btag = rman_get_bustag(sc->portres);
  159         sc->lnc_bhandle = rman_get_bushandle(sc->portres);
  160 
  161         sc->drqrid = 0;
  162         sc->drqres = NULL;
  163 
  164         if (isa_get_irq(dev) == -1)
  165                 bus_set_resource(dev, SYS_RES_IRQ, 0,  6, 1);
  166 
  167         sc->irqrid = 0;
  168         sc->irqres = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irqrid,
  169                                             RF_ACTIVE);
  170 
  171         if (! sc->irqres) {
  172                 device_printf(dev, "Failed to allocate irq\n");
  173                 lnc_release_resources(dev);
  174                 return (ENXIO);
  175         }
  176 
  177         err = bus_setup_intr(dev, sc->irqres, INTR_TYPE_NET, lncintr,
  178                              sc, &sc->intrhand);
  179 
  180         if (err) {
  181                 device_printf(dev, "Failed to setup irq handler\n");
  182                 lnc_release_resources(dev);
  183                 return (err);
  184         }
  185 
  186         /* XXX temp setting for nic */
  187         sc->nic.mem_mode = DMA_FIXED;
  188         sc->nrdre  = NRDRE;
  189         sc->ntdre  = NTDRE;
  190 
  191         if (sc->nic.ident == CNET98S) {
  192             sc->rap = CNET98S_RAP;
  193             sc->rdp = CNET98S_RDP;
  194         } else if (sc->nic.ident == NE2100) {
  195             sc->rap = PCNET_RAP;
  196             sc->rdp = PCNET_RDP;
  197             sc->bdp = PCNET_BDP;
  198         } else {
  199             sc->rap = BICC_RAP;
  200             sc->rdp = BICC_RDP;
  201         }
  202 
  203         /* Create a DMA tag describing the ring memory we need */
  204 
  205         lnc_mem_size = ((NDESC(sc->nrdre) + NDESC(sc->ntdre)) *
  206                          sizeof(struct host_ring_entry));
  207 
  208         lnc_mem_size += (NDESC(sc->nrdre) * RECVBUFSIZE) +
  209                         (NDESC(sc->ntdre) * TRANSBUFSIZE);
  210 
  211         err = bus_dma_tag_create(NULL,                  /* parent */
  212                                  4,                     /* alignement */
  213                                  0,                     /* boundary */
  214                                  BUS_SPACE_MAXADDR_24BIT,       /* lowaddr */
  215                                  BUS_SPACE_MAXADDR,     /* highaddr */
  216                                  NULL, NULL,            /* filter, filterarg */
  217                                  lnc_mem_size,          /* segsize */
  218                                  1,                     /* nsegments */
  219                                  BUS_SPACE_MAXSIZE_32BIT,       /* maxsegsize */
  220                                  0,                     /* flags */
  221                                  busdma_lock_mutex,     /* lockfunc */
  222                                  &Giant,                /* lockarg */
  223                                  &sc->dmat);
  224 
  225         if (err) {
  226                 device_printf(dev, "Can't create DMA tag\n");
  227                 lnc_release_resources(dev);
  228                 return (ENOMEM);
  229         }
  230 
  231         err = bus_dmamem_alloc(sc->dmat, (void **)&sc->recv_ring,
  232                                BUS_DMA_NOWAIT, &sc->dmamap);
  233 
  234         if (err) {
  235                 device_printf(dev, "Couldn't allocate memory\n");
  236                 lnc_release_resources(dev);
  237                 return (ENOMEM);
  238         }
  239 
  240         err = bus_dmamap_load(sc->dmat, sc->dmamap, sc->recv_ring, lnc_mem_size,
  241                         lnc_alloc_callback, sc->recv_ring, BUS_DMA_NOWAIT);
  242 
  243         if (err) {
  244                 device_printf(dev, "Couldn't load DMA map\n");
  245                 lnc_release_resources(dev);
  246                 return (ENOMEM);
  247         }
  248 
  249         /* Call generic attach code */
  250         if (! lnc_attach_common(dev)) {
  251                 device_printf(dev, "Generic attach code failed\n");
  252                 lnc_release_resources(dev);
  253                 return (ENXIO);
  254         }
  255 
  256         /*
  257          * ISA Configuration
  258          *
  259          * XXX - Following parameters are Contec C-NET(98)S only.
  260          *       So, check the Ethernet address here.
  261          *
  262          *       Contec uses 00 80 4c ?? ?? ??
  263          */ 
  264         if (sc->arpcom.ac_enaddr[0] == (u_char)0x00 &&
  265             sc->arpcom.ac_enaddr[1] == (u_char)0x80 &&
  266             sc->arpcom.ac_enaddr[2] == (u_char)0x4c) {
  267                 lnc_outw(sc->rap, MSRDA);
  268                 lnc_outw(CNET98S_IDP, 0x0006);
  269                 lnc_outw(sc->rap, MSWRA);
  270                 lnc_outw(CNET98S_IDP, 0x0006);
  271 #ifdef DIAGNOSTIC
  272                 lnc_outw(sc->rap, MC);
  273                 printf("ISACSR2 = %x\n", lnc_inw(CNET98S_IDP));
  274 #endif
  275                 lnc_outw(sc->rap, LED1);
  276                 lnc_outw(CNET98S_IDP, LED_PSE | LED_XMTE);
  277                 lnc_outw(sc->rap, LED2);
  278                 lnc_outw(CNET98S_IDP, LED_PSE | LED_RCVE);
  279                 lnc_outw(sc->rap, LED3);
  280                 lnc_outw(CNET98S_IDP, LED_PSE | LED_COLE);
  281         }
  282 
  283         return (0);
  284 }
  285 
  286 static int
  287 lnc_isa_detach(device_t dev)
  288 {
  289         lnc_softc_t *sc = device_get_softc(dev);
  290         int s = splimp();
  291 
  292         ether_ifdetach(&sc->arpcom.ac_if);
  293         splx(s);
  294 
  295         lnc_stop(sc);
  296         lnc_release_resources(dev);
  297 
  298         return (0);
  299 }
  300 
  301 static device_method_t lnc_isa_methods[] = {
  302 /*      DEVMETHOD(device_identify,      lnc_isa_identify), */
  303         DEVMETHOD(device_probe,         lnc_isa_probe),
  304         DEVMETHOD(device_attach,        lnc_isa_attach),
  305         DEVMETHOD(device_detach,        lnc_isa_detach),
  306 #ifdef notyet
  307         DEVMETHOD(device_suspend,       lnc_isa_suspend),
  308         DEVMETHOD(device_resume,        lnc_isa_resume),
  309         DEVMETHOD(device_shutdown,      lnc_isa_shutdown),
  310 #endif
  311         { 0, 0 }
  312 };
  313 
  314 static driver_t lnc_isa_driver = {
  315         "lnc",
  316         lnc_isa_methods,
  317         sizeof(struct lnc_softc),
  318 };
  319 
  320 DRIVER_MODULE(lnc, isa, lnc_isa_driver, lnc_devclass, 0, 0);
  321 MODULE_DEPEND(lnc, isa, 1, 1, 1);
  322 MODULE_DEPEND(lnc, ether, 1, 1, 1);

Cache object: 4550c1864953c65f2c721e8f27e617b7


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