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/netif/ndis/if_ndis_u4b.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
    3  *      Bill Paul <wpaul@windriver.com>.  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 Bill Paul.
   16  * 4. Neither the name of the author nor the names of any co-contributors
   17  *    may be used to endorse or promote products derived from this software
   18  *    without specific prior written permission.
   19  *
   20  * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``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 Bill Paul OR THE VOICES IN HIS HEAD
   24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
   30  * THE POSSIBILITY OF SUCH DAMAGE.
   31  *
   32  * $FreeBSD: src/sys/dev/if_ndis/if_ndis_usb.c,v 1.26 2012/11/17 01:51:54 svnexp Exp $
   33  */
   34 
   35 #include <sys/param.h>
   36 #include <sys/systm.h>
   37 #include <sys/sockio.h>
   38 #include <sys/module.h>
   39 #include <sys/malloc.h>
   40 #include <sys/kernel.h>
   41 #include <sys/socket.h>
   42 #include <sys/sysctl.h>
   43 
   44 #include <net/if.h>
   45 #include <net/if_arp.h>
   46 #include <net/ethernet.h>
   47 #include <net/if_dl.h>
   48 #include <net/if_media.h>
   49 
   50 #include <net/bpf.h>
   51 
   52 #include <sys/bus.h>
   53 #include <bus/u4b/usb.h>
   54 #include <bus/u4b/usbdi.h>
   55 
   56 #include <netproto/802_11/ieee80211_var.h>
   57 
   58 #include <emulation/ndis/pe_var.h>
   59 #include <emulation/ndis/cfg_var.h>
   60 #include <emulation/ndis/resource_var.h>
   61 #include <emulation/ndis/ntoskrnl_var.h>
   62 #include <emulation/ndis/ndis_var.h>
   63 #include <emulation/ndis/u4bd_var.h>
   64 #include <dev/netif/ndis/if_ndisvar.h>
   65 
   66 SYSCTL_NODE(_hw, OID_AUTO, ndisusb, CTLFLAG_RD, 0, "NDIS USB driver parameters");
   67 
   68 MODULE_DEPEND(ndis, usb, 1, 1, 1);
   69 
   70 static device_probe_t ndisusb_match;
   71 static device_attach_t ndisusb_attach;
   72 static device_detach_t ndisusb_detach;
   73 static bus_get_resource_list_t ndis_get_resource_list;
   74 
   75 extern int ndisdrv_modevent     (module_t, int, void *);
   76 extern int ndis_attach          (device_t);
   77 extern int ndis_shutdown        (device_t);
   78 extern int ndis_detach          (device_t);
   79 extern int ndis_suspend         (device_t);
   80 extern int ndis_resume          (device_t);
   81 
   82 extern unsigned char drv_data[];
   83 
   84 static device_method_t ndis_methods[] = {
   85         /* Device interface */
   86         DEVMETHOD(device_probe,         ndisusb_match),
   87         DEVMETHOD(device_attach,        ndisusb_attach),
   88         DEVMETHOD(device_detach,        ndisusb_detach),
   89         DEVMETHOD(device_shutdown,      ndis_shutdown),
   90 
   91         /* bus interface */
   92         DEVMETHOD(bus_get_resource_list, ndis_get_resource_list),
   93 
   94         DEVMETHOD_END
   95 };
   96 
   97 static driver_t ndis_driver = {
   98         "ndis",
   99         ndis_methods,
  100         sizeof(struct ndis_softc)
  101 };
  102 
  103 static devclass_t ndis_devclass;
  104 
  105 DRIVER_MODULE(if_ndis, uhub, ndis_driver, ndis_devclass, ndisdrv_modevent,
  106     NULL);
  107 
  108 static int
  109 ndisusb_devcompare(interface_type bustype, struct ndis_usb_type *t, device_t dev)
  110 {
  111         struct usb_attach_arg *uaa;
  112 
  113         if (bustype != PNPBus)
  114                 return (FALSE);
  115 
  116         uaa = device_get_ivars(dev);
  117 
  118         while (t->ndis_name != NULL) {
  119                 if ((uaa->info.idVendor == t->ndis_vid) &&
  120                     (uaa->info.idProduct == t->ndis_did)) {
  121                         device_set_desc(dev, t->ndis_name);
  122                         return (TRUE);
  123                 }
  124                 t++;
  125         }
  126 
  127         return (FALSE);
  128 }
  129 
  130 static int
  131 ndisusb_match(device_t self)
  132 {
  133         struct drvdb_ent *db;
  134         struct usb_attach_arg *uaa = device_get_ivars(self);
  135 
  136         if (uaa->usb_mode != USB_MODE_HOST)
  137                 return (ENXIO);
  138         if (uaa->info.bConfigIndex != NDISUSB_CONFIG_NO)
  139                 return (ENXIO);
  140         if (uaa->info.bIfaceIndex != NDISUSB_IFACE_INDEX)
  141                 return (ENXIO);
  142 
  143         if (windrv_lookup(0, "USB Bus") == NULL)
  144                 return (ENXIO);
  145 
  146         db = windrv_match((matchfuncptr)ndisusb_devcompare, self);
  147         if (db == NULL)
  148                 return (ENXIO);
  149         uaa->driver_ivar = db;
  150 
  151         return (0);
  152 }
  153 
  154 static int
  155 ndisusb_attach(device_t self)
  156 {
  157         const struct drvdb_ent  *db;
  158         struct ndisusb_softc *dummy = device_get_softc(self);
  159         struct usb_attach_arg *uaa = device_get_ivars(self);
  160         struct ndis_softc       *sc;
  161         struct ndis_usb_type    *t;
  162         driver_object           *drv;
  163         int                     devidx = 0;
  164 
  165         device_set_usb_desc(self);
  166         db = uaa->driver_ivar;
  167         sc = (struct ndis_softc *)dummy;
  168         sc->ndis_dev = self;
  169         lockinit(&sc->ndisusb_lock, "NDIS USB", 0, LK_CANRECURSE);
  170         sc->ndis_dobj = db->windrv_object;
  171         sc->ndis_regvals = db->windrv_regvals;
  172         sc->ndis_iftype = PNPBus;
  173         sc->ndisusb_dev = uaa->device;
  174 
  175         /* Create PDO for this device instance */
  176 
  177         drv = windrv_lookup(0, "USB Bus");
  178         windrv_create_pdo(drv, self);
  179 
  180         /* Figure out exactly which device we matched. */
  181 
  182         t = db->windrv_devlist;
  183 
  184         while (t->ndis_name != NULL) {
  185                 if ((uaa->info.idVendor == t->ndis_vid) &&
  186                     (uaa->info.idProduct == t->ndis_did)) {
  187                         sc->ndis_devidx = devidx;
  188                         break;
  189                 }
  190                 t++;
  191                 devidx++;
  192         }
  193 
  194         if (ndis_attach(self) != 0)
  195                 return (ENXIO);
  196 
  197         return (0);
  198 }
  199 
  200 static int
  201 ndisusb_detach(device_t self)
  202 {
  203         int i;
  204         struct ndis_softc       *sc = device_get_softc(self);
  205         struct ndisusb_ep       *ne;
  206 
  207         sc->ndisusb_status |= NDISUSB_STATUS_DETACH;
  208 
  209         ndis_pnpevent_nic(self, NDIS_PNP_EVENT_SURPRISE_REMOVED);
  210 
  211         if (sc->ndisusb_status & NDISUSB_STATUS_SETUP_EP) {
  212                 usbd_transfer_unsetup(sc->ndisusb_dread_ep.ne_xfer, 1);
  213                 usbd_transfer_unsetup(sc->ndisusb_dwrite_ep.ne_xfer, 1);
  214         }
  215         for (i = 0; i < NDISUSB_ENDPT_MAX; i++) {
  216                 ne = &sc->ndisusb_ep[i];
  217                 usbd_transfer_unsetup(ne->ne_xfer, 1);
  218         }
  219 
  220         (void)ndis_detach(self);
  221 
  222         lockuninit(&sc->ndisusb_lock);
  223         return (0);
  224 }
  225 
  226 static struct resource_list *
  227 ndis_get_resource_list(device_t dev, device_t child)
  228 {
  229         struct ndis_softc       *sc;
  230 
  231         sc = device_get_softc(dev);
  232         return (BUS_GET_RESOURCE_LIST(device_get_parent(sc->ndis_dev), dev));
  233 }

Cache object: 5908c487d356dcdb7c6596cdba1d8b7f


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