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.h>
   56 #include <machine/resource.h>
   57 #include <sys/rman.h>
   58 
   59 #include <net/if.h>
   60 #include <net/if_arp.h>
   61 
   62 #include <netatm/port.h>
   63 #include <netatm/queue.h>
   64 #include <netatm/atm.h>
   65 #include <netatm/atm_sys.h>
   66 #include <netatm/atm_sap.h>
   67 #include <netatm/atm_cm.h>
   68 #include <netatm/atm_if.h>
   69 #include <netatm/atm_stack.h>
   70 #include <netatm/atm_pcb.h>
   71 #include <netatm/atm_var.h>
   72 
   73 #include <dev/pci/pcireg.h>
   74 #include <dev/pci/pcivar.h>
   75 
   76 #include <dev/idt/idtreg.h>
   77 #include <dev/idt/idtvar.h>
   78 
   79 #define IDT_VID         0x111d
   80 #define IDT_NICSTAR_DID 0x0001
   81 
   82 struct pci_type {
   83         u_int16_t       pci_vid;
   84         u_int16_t       pci_did;
   85         char *          pci_name;
   86 } pci_devs[] = {
   87         { IDT_VID, IDT_NICSTAR_DID, "IDT IDT77201/211 NICStAR ATM Adapter" },
   88         { 0, 0, NULL }
   89 };
   90 
   91 uma_zone_t      idt_nif_zone;
   92 uma_zone_t      idt_vcc_zone;
   93 
   94 static int      idt_probe       (device_t);
   95 static int      idt_attach      (device_t);
   96 static int      idt_detach      (device_t);
   97 static int      idt_shutdown    (device_t);
   98 static void     idt_free        (device_t);
   99 static int      idt_modevent    (module_t, int, void *);
  100 
  101 static int
  102 idt_probe(device_t dev)
  103 {
  104         struct pci_type *t = pci_devs;
  105 
  106         while(t->pci_name != NULL) {
  107                 if ((pci_get_vendor(dev) == t->pci_vid) &&
  108                     (pci_get_device(dev) == t->pci_did)) {
  109                         device_set_desc(dev, t->pci_name);
  110                         return(BUS_PROBE_DEFAULT);
  111                 }
  112                 t++;
  113         }
  114 
  115         return(ENXIO);
  116 }
  117 
  118 /******************************************************************************
  119  *
  120  *  Attach device
  121  *
  122  * Date first: 11/14/2000  last: 06/10/2001
  123  */
  124 
  125 static int
  126 idt_attach(device_t dev)
  127 {
  128         struct idt_softc *sc;
  129         int error;
  130 
  131         sc = device_get_softc(dev);
  132         sc->dev = dev;
  133         error = 0;
  134 
  135         pci_enable_busmaster(dev);
  136 
  137         /* count = 2 (times 32 PCI clocks) */
  138         pci_write_config(dev, PCIR_LATTIMER, 0x20, 1);
  139 
  140         /* Map IDT registers */
  141         sc->mem_rid = 0x14;
  142         sc->mem_type = SYS_RES_MEMORY;
  143         sc->mem = bus_alloc_resource_any(dev, sc->mem_type, &sc->mem_rid,
  144                                          RF_ACTIVE);
  145         if (sc->mem == NULL) {
  146                 device_printf(dev, "could not map registers.\n");
  147                 error = ENXIO;
  148                 goto fail;
  149         }
  150         sc->bustag = rman_get_bustag(sc->mem);
  151         sc->bushandle = rman_get_bushandle(sc->mem);
  152 
  153         /* Map interrupt */
  154         sc->irq_rid = 0;
  155         sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irq_rid,
  156                                          RF_ACTIVE | RF_SHAREABLE);
  157         if (sc->irq == NULL) {
  158                 device_printf(dev, "could not map interrupt.\n");
  159                 error = ENXIO;
  160                 goto fail;
  161         }
  162 
  163         error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET, nicstar_intr,
  164                                sc, &sc->irq_ih);
  165         if (error) {
  166                 device_printf(dev, "could not setup irq.\n");
  167                 error = ENXIO;
  168                 goto fail;
  169         }
  170 
  171         sc->virt_baseaddr = (vm_offset_t)rman_get_virtual(sc->mem);
  172         sc->cmd_reg = sc->virt_baseaddr + REGCMD;       /* old reg */
  173         sc->stat_reg = sc->virt_baseaddr + REGSTAT;     /* old reg */
  174         sc->reg_cmd = (u_long *)(sc->virt_baseaddr + REGCMD);
  175         sc->reg_stat = (u_long *)(sc->virt_baseaddr + REGSTAT);
  176         sc->reg_cfg = (u_long *)(sc->virt_baseaddr + REGCFG);
  177         sc->reg_data = (u_long *)(sc->virt_baseaddr + 0);
  178         sc->reg_tsqh = (u_long *)(sc->virt_baseaddr + REGTSQH);
  179         sc->reg_gp = (u_long *)(sc->virt_baseaddr + REGGP);
  180         sc->pci_rev = pci_get_revid(dev);
  181         sc->timer_wrap = 0;
  182 
  183         callout_handle_init(&sc->ch);
  184 
  185         phys_init(sc);          /* initialize the hardware */
  186         nicstar_init(sc);       /* allocate and initialize */
  187         
  188         error = idt_harp_init(sc);
  189         if (error)
  190                 goto fail;
  191 
  192         return (0);
  193 fail:
  194         idt_free(dev);
  195         return (error);
  196 }
  197 
  198 /******************************************************************************
  199  *
  200  *  Detach device
  201  *
  202  * Date first: 11/14/2000  last: 11/14/2000
  203  */
  204 
  205 static int
  206 idt_detach(device_t dev)
  207 {
  208         struct idt_softc *sc;
  209         int error;
  210 
  211         sc = device_get_softc(dev);
  212         error = 0;
  213 
  214         /*
  215          * De-Register this interface with ATM core services
  216          */
  217         error = atm_physif_deregister(&sc->iu_cmn);
  218 
  219         idt_device_stop(sc);    /* Stop the device */
  220 
  221         /*
  222          * Lock out all device interupts.
  223          */
  224         DEVICE_LOCK(&sc->iu_cmn);
  225         idt_free(dev);
  226         idt_release_mem(sc);
  227         DEVICE_UNLOCK(&sc->iu_cmn);
  228 
  229         return (error);
  230 }
  231 
  232 /******************************************************************************
  233  *
  234  *  Shutdown device
  235  *
  236  * Date first: 11/14/2000  last: 11/14/2000
  237  */
  238 
  239 static int
  240 idt_shutdown(device_t dev)
  241 {
  242 
  243         struct idt_softc *sc;
  244 
  245         sc = device_get_softc(dev);
  246 
  247         idt_device_stop(sc);    /* Stop the device */
  248 
  249         return (0);
  250 }
  251 
  252 static void
  253 idt_free (device_t dev)
  254 {
  255         struct idt_softc *sc;
  256 
  257         sc = device_get_softc(dev);
  258 
  259         if (sc->irq_ih)
  260                 bus_teardown_intr(dev, sc->irq, sc->irq_ih);
  261         if (sc->irq)
  262                 bus_release_resource(dev, SYS_RES_IRQ, sc->irq_rid, sc->irq);
  263         if (sc->mem)
  264                 bus_release_resource(dev, sc->mem_type, sc->mem_rid, sc->mem);
  265 
  266         return;
  267 }
  268 
  269 static int
  270 idt_modevent (module_t mod, int type, void *data)
  271 {
  272         int error;
  273 
  274         error = 0;
  275 
  276         switch (type) {
  277         case MOD_LOAD:
  278                 idt_nif_zone = uma_zcreate("idt nif",
  279                         sizeof(struct atm_nif),
  280                         NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
  281                 if (idt_nif_zone == NULL)
  282                         panic("hfa_modevent:uma_zcreate nif");
  283                 uma_zone_set_max(idt_nif_zone, 20);
  284 
  285                 idt_vcc_zone = uma_zcreate("idt vcc",
  286                         sizeof(Idt_vcc),
  287                         NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
  288                 if (idt_vcc_zone == NULL)
  289                         panic("hfa_modevent: uma_zcreate vcc");
  290                 uma_zone_set_max(idt_vcc_zone, 100);
  291 
  292                 break;
  293 
  294         case MOD_UNLOAD:
  295                 uma_zdestroy(idt_nif_zone);
  296                 uma_zdestroy(idt_vcc_zone);
  297 
  298                 break;
  299         default:
  300                 break;
  301         }
  302 
  303         return (error);
  304 }
  305 
  306 static device_method_t idt_methods[] = {
  307         DEVMETHOD(device_probe,         idt_probe),
  308         DEVMETHOD(device_attach,        idt_attach),
  309         DEVMETHOD(device_detach,        idt_detach),
  310         DEVMETHOD(device_shutdown,      idt_shutdown),
  311         {0, 0}
  312 };
  313 
  314 static driver_t idt_driver = {
  315         "idt",
  316         idt_methods,
  317         sizeof(struct idt_softc)
  318 };
  319 
  320 static devclass_t idt_devclass;
  321 
  322 DRIVER_MODULE(idt, pci, idt_driver, idt_devclass, idt_modevent, 0);
  323 MODULE_VERSION(idt, 1);

Cache object: b42a14b73ddcdbef29e07eea8f9461c3


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