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/idt/idt_pci.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) 2000, 2001 Richard Hodges and Matriplex, inc.
    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  * 3. All advertising materials mentioning features or use of this software
   14  *    must display the following acknowledgement:
   15  *    This product includes software developed by Matriplex, inc.
   16  * 4. The name of the author may not be used to endorse or promote products
   17  *    derived from this software without specific prior written permission.
   18  *
   19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
   21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   22  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
   23  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
   25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   27  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
   28  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   29  * POSSIBILITY OF SUCH DAMAGE.
   30  *
   31  ******************************************************************************
   32  *
   33  * This driver is derived from the Nicstar driver by Mark Tinguely, and
   34  * some of the original driver still exists here.  Those portions are...
   35  *   Copyright (c) 1996, 1997, 1998, 1999 Mark Tinguely
   36  *   All rights reserved.
   37  */
   38 
   39 #include <sys/cdefs.h>
   40 __FBSDID("$FreeBSD$");
   41 
   42 #include <sys/param.h>
   43 #include <sys/systm.h>
   44 #include <sys/kernel.h>
   45 #include <sys/lock.h>
   46 #include <sys/malloc.h>
   47 #include <sys/mutex.h>
   48 #include <sys/socket.h>
   49 #include <sys/socketvar.h>
   50 
   51 #include <sys/bus.h>
   52 #include <sys/conf.h>
   53 
   54 #include <sys/module.h>
   55 #include <machine/bus_memio.h>
   56 #include <machine/bus.h>
   57 #include <machine/resource.h>
   58 #include <sys/rman.h>
   59 
   60 #include <net/if.h>
   61 #include <net/if_arp.h>
   62 
   63 #include <netatm/port.h>
   64 #include <netatm/queue.h>
   65 #include <netatm/atm.h>
   66 #include <netatm/atm_sys.h>
   67 #include <netatm/atm_sap.h>
   68 #include <netatm/atm_cm.h>
   69 #include <netatm/atm_if.h>
   70 #include <netatm/atm_stack.h>
   71 #include <netatm/atm_pcb.h>
   72 #include <netatm/atm_var.h>
   73 
   74 #include <dev/pci/pcireg.h>
   75 #include <dev/pci/pcivar.h>
   76 
   77 #include <dev/idt/idtreg.h>
   78 #include <dev/idt/idtvar.h>
   79 
   80 #define IDT_VID         0x111d
   81 #define IDT_NICSTAR_DID 0x0001
   82 
   83 struct pci_type {
   84         u_int16_t       pci_vid;
   85         u_int16_t       pci_did;
   86         char *          pci_name;
   87 } pci_devs[] = {
   88         { IDT_VID, IDT_NICSTAR_DID, "IDT IDT77201/211 NICStAR ATM Adapter" },
   89         { 0, 0, NULL }
   90 };
   91 
   92 uma_zone_t      idt_nif_zone;
   93 uma_zone_t      idt_vcc_zone;
   94 
   95 static int      idt_probe       (device_t);
   96 static int      idt_attach      (device_t);
   97 static int      idt_detach      (device_t);
   98 static int      idt_shutdown    (device_t);
   99 static void     idt_free        (device_t);
  100 static int      idt_modevent    (module_t, int, void *);
  101 
  102 static int
  103 idt_probe(device_t dev)
  104 {
  105         struct pci_type *t = pci_devs;
  106 
  107         while(t->pci_name != NULL) {
  108                 if ((pci_get_vendor(dev) == t->pci_vid) &&
  109                     (pci_get_device(dev) == t->pci_did)) {
  110                         device_set_desc(dev, t->pci_name);
  111                         return(0);
  112                 }
  113                 t++;
  114         }
  115 
  116         return(ENXIO);
  117 }
  118 
  119 /******************************************************************************
  120  *
  121  *  Attach device
  122  *
  123  * Date first: 11/14/2000  last: 06/10/2001
  124  */
  125 
  126 static int
  127 idt_attach(device_t dev)
  128 {
  129         struct idt_softc *sc;
  130         int error;
  131 
  132         sc = device_get_softc(dev);
  133         sc->dev = dev;
  134         error = 0;
  135 
  136         pci_enable_busmaster(dev);
  137 
  138         /* count = 2 (times 32 PCI clocks) */
  139         pci_write_config(dev, PCIR_LATTIMER, 0x20, 1);
  140 
  141         /* Map IDT registers */
  142         sc->mem_rid = 0x14;
  143         sc->mem_type = SYS_RES_MEMORY;
  144         sc->mem = bus_alloc_resource_any(dev, sc->mem_type, &sc->mem_rid,
  145                                          RF_ACTIVE);
  146         if (sc->mem == NULL) {
  147                 device_printf(dev, "could not map registers.\n");
  148                 error = ENXIO;
  149                 goto fail;
  150         }
  151         sc->bustag = rman_get_bustag(sc->mem);
  152         sc->bushandle = rman_get_bushandle(sc->mem);
  153 
  154         /* Map interrupt */
  155         sc->irq_rid = 0;
  156         sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irq_rid,
  157                                          RF_ACTIVE | RF_SHAREABLE);
  158         if (sc->irq == NULL) {
  159                 device_printf(dev, "could not map interrupt.\n");
  160                 error = ENXIO;
  161                 goto fail;
  162         }
  163 
  164         error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET, nicstar_intr,
  165                                sc, &sc->irq_ih);
  166         if (error) {
  167                 device_printf(dev, "could not setup irq.\n");
  168                 error = ENXIO;
  169                 goto fail;
  170         }
  171 
  172         sc->virt_baseaddr = (vm_offset_t)rman_get_virtual(sc->mem);
  173         sc->cmd_reg = sc->virt_baseaddr + REGCMD;       /* old reg */
  174         sc->stat_reg = sc->virt_baseaddr + REGSTAT;     /* old reg */
  175         sc->reg_cmd = (u_long *)(sc->virt_baseaddr + REGCMD);
  176         sc->reg_stat = (u_long *)(sc->virt_baseaddr + REGSTAT);
  177         sc->reg_cfg = (u_long *)(sc->virt_baseaddr + REGCFG);
  178         sc->reg_data = (u_long *)(sc->virt_baseaddr + 0);
  179         sc->reg_tsqh = (u_long *)(sc->virt_baseaddr + REGTSQH);
  180         sc->reg_gp = (u_long *)(sc->virt_baseaddr + REGGP);
  181         sc->pci_rev = pci_get_revid(dev);
  182         sc->timer_wrap = 0;
  183 
  184         callout_handle_init(&sc->ch);
  185 
  186         phys_init(sc);          /* initialize the hardware */
  187         nicstar_init(sc);       /* allocate and initialize */
  188         
  189         error = idt_harp_init(sc);
  190         if (error)
  191                 goto fail;
  192 
  193         return (0);
  194 fail:
  195         idt_free(dev);
  196         return (error);
  197 }
  198 
  199 /******************************************************************************
  200  *
  201  *  Detach device
  202  *
  203  * Date first: 11/14/2000  last: 11/14/2000
  204  */
  205 
  206 static int
  207 idt_detach(device_t dev)
  208 {
  209         struct idt_softc *sc;
  210         int error;
  211 
  212         sc = device_get_softc(dev);
  213         error = 0;
  214 
  215         /*
  216          * De-Register this interface with ATM core services
  217          */
  218         error = atm_physif_deregister(&sc->iu_cmn);
  219 
  220         idt_device_stop(sc);    /* Stop the device */
  221 
  222         /*
  223          * Lock out all device interupts.
  224          */
  225         DEVICE_LOCK(&sc->iu_cmn);
  226         idt_free(dev);
  227         idt_release_mem(sc);
  228         DEVICE_UNLOCK(&sc->iu_cmn);
  229 
  230         return (error);
  231 }
  232 
  233 /******************************************************************************
  234  *
  235  *  Shutdown device
  236  *
  237  * Date first: 11/14/2000  last: 11/14/2000
  238  */
  239 
  240 static int
  241 idt_shutdown(device_t dev)
  242 {
  243 
  244         struct idt_softc *sc;
  245 
  246         sc = device_get_softc(dev);
  247 
  248         idt_device_stop(sc);    /* Stop the device */
  249 
  250         return (0);
  251 }
  252 
  253 static void
  254 idt_free (device_t dev)
  255 {
  256         struct idt_softc *sc;
  257 
  258         sc = device_get_softc(dev);
  259 
  260         if (sc->irq_ih)
  261                 bus_teardown_intr(dev, sc->irq, sc->irq_ih);
  262         if (sc->irq)
  263                 bus_release_resource(dev, SYS_RES_IRQ, sc->irq_rid, sc->irq);
  264         if (sc->mem)
  265                 bus_release_resource(dev, sc->mem_type, sc->mem_rid, sc->mem);
  266 
  267         return;
  268 }
  269 
  270 static int
  271 idt_modevent (module_t mod, int type, void *data)
  272 {
  273         int error;
  274 
  275         error = 0;
  276 
  277         switch (type) {
  278         case MOD_LOAD:
  279                 idt_nif_zone = uma_zcreate("idt nif",
  280                         sizeof(struct atm_nif),
  281                         NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
  282                 if (idt_nif_zone == NULL)
  283                         panic("hfa_modevent:uma_zcreate nif");
  284                 uma_zone_set_max(idt_nif_zone, 20);
  285 
  286                 idt_vcc_zone = uma_zcreate("idt vcc",
  287                         sizeof(Idt_vcc),
  288                         NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
  289                 if (idt_vcc_zone == NULL)
  290                         panic("hfa_modevent: uma_zcreate vcc");
  291                 uma_zone_set_max(idt_vcc_zone, 100);
  292 
  293                 break;
  294 
  295         case MOD_UNLOAD:
  296                 uma_zdestroy(idt_nif_zone);
  297                 uma_zdestroy(idt_vcc_zone);
  298 
  299                 break;
  300         default:
  301                 break;
  302         }
  303 
  304         return (error);
  305 }
  306 
  307 static device_method_t idt_methods[] = {
  308         DEVMETHOD(device_probe,         idt_probe),
  309         DEVMETHOD(device_attach,        idt_attach),
  310         DEVMETHOD(device_detach,        idt_detach),
  311         DEVMETHOD(device_shutdown,      idt_shutdown),
  312         {0, 0}
  313 };
  314 
  315 static driver_t idt_driver = {
  316         "idt",
  317         idt_methods,
  318         sizeof(struct idt_softc)
  319 };
  320 
  321 static devclass_t idt_devclass;
  322 
  323 DRIVER_MODULE(idt, pci, idt_driver, idt_devclass, idt_modevent, 0);
  324 MODULE_VERSION(idt, 1);

Cache object: bde2b800fc6f6d3503b99d888afe0bd1


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