Deleted Added
full compact
if_ndis_usb.c (188939) if_ndis_usb.c (189488)
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

--- 17 unchanged lines hidden (view full) ---

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
33#include <sys/cdefs.h>
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

--- 17 unchanged lines hidden (view full) ---

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
33#include <sys/cdefs.h>
34__FBSDID("$FreeBSD: head/sys/dev/if_ndis/if_ndis_usb.c 188939 2009-02-23 18:16:17Z thompsa $");
34__FBSDID("$FreeBSD: head/sys/dev/if_ndis/if_ndis_usb.c 189488 2009-03-07 07:26:22Z weongyo $");
35
36#include <sys/param.h>
37#include <sys/systm.h>
38#include <sys/sockio.h>
39#include <sys/module.h>
40#include <sys/malloc.h>
41#include <sys/kernel.h>
42#include <sys/socket.h>

--- 4 unchanged lines hidden (view full) ---

47#include <net/ethernet.h>
48#include <net/if_dl.h>
49#include <net/if_media.h>
50
51#include <net/bpf.h>
52
53#include <sys/bus.h>
54#include <machine/bus.h>
35
36#include <sys/param.h>
37#include <sys/systm.h>
38#include <sys/sockio.h>
39#include <sys/module.h>
40#include <sys/malloc.h>
41#include <sys/kernel.h>
42#include <sys/socket.h>

--- 4 unchanged lines hidden (view full) ---

47#include <net/ethernet.h>
48#include <net/if_dl.h>
49#include <net/if_media.h>
50
51#include <net/bpf.h>
52
53#include <sys/bus.h>
54#include <machine/bus.h>
55#include <legacy/dev/usb/usb.h>
56#include <legacy/dev/usb/usbdi.h>
57#include <legacy/dev/usb/usbdi_util.h>
58#include <legacy/dev/usb/usbdivar.h>
59#include "usbdevs.h"
55#include
56#include <dev/usb/usb_core.h>
60
61#include <net80211/ieee80211_var.h>
62
63#include <compat/ndis/pe_var.h>
64#include <compat/ndis/cfg_var.h>
65#include <compat/ndis/resource_var.h>
66#include <compat/ndis/ntoskrnl_var.h>
67#include <compat/ndis/ndis_var.h>

--- 41 unchanged lines hidden (view full) ---

109
110static devclass_t ndis_devclass;
111
112DRIVER_MODULE(ndis, uhub, ndis_driver, ndis_devclass, ndisdrv_modevent, 0);
113
114static int
115ndisusb_devcompare(interface_type bustype, struct ndis_usb_type *t, device_t dev)
116{
57
58#include <net80211/ieee80211_var.h>
59
60#include <compat/ndis/pe_var.h>
61#include <compat/ndis/cfg_var.h>
62#include <compat/ndis/resource_var.h>
63#include <compat/ndis/ntoskrnl_var.h>
64#include <compat/ndis/ndis_var.h>

--- 41 unchanged lines hidden (view full) ---

106
107static devclass_t ndis_devclass;
108
109DRIVER_MODULE(ndis, uhub, ndis_driver, ndis_devclass, ndisdrv_modevent, 0);
110
111static int
112ndisusb_devcompare(interface_type bustype, struct ndis_usb_type *t, device_t dev)
113{
117 struct usb_attach_arg *uaa;
114 struct usb2_attach_arg *uaa;
118
119 if (bustype != PNPBus)
120 return (FALSE);
121
122 uaa = device_get_ivars(dev);
123
124 while (t->ndis_name != NULL) {
115
116 if (bustype != PNPBus)
117 return (FALSE);
118
119 uaa = device_get_ivars(dev);
120
121 while (t->ndis_name != NULL) {
125 if ((uaa->vendor == t->ndis_vid) &&
126 (uaa->product == t->ndis_did)) {
122 if ((uaa->info.idVendor == t->ndis_vid) &&
123 (uaa->info.idProduct == t->ndis_did)) {
127 device_set_desc(dev, t->ndis_name);
128 return (TRUE);
129 }
130 t++;
131 }
132
133 return (FALSE);
134}
135
136static int
137ndisusb_match(device_t self)
138{
139 struct drvdb_ent *db;
124 device_set_desc(dev, t->ndis_name);
125 return (TRUE);
126 }
127 t++;
128 }
129
130 return (FALSE);
131}
132
133static int
134ndisusb_match(device_t self)
135{
136 struct drvdb_ent *db;
140 struct usb_attach_arg *uaa = device_get_ivars(self);
137 struct usb2_attach_arg *uaa = device_get_ivars(self);
141
138
139 if (uaa->usb2_mode != USB_MODE_HOST)
140 return (ENXIO);
141 if (uaa->info.bConfigIndex != NDISUSB_CONFIG_NO)
142 return (ENXIO);
143 if (uaa->info.bIfaceIndex != NDISUSB_IFACE_INDEX)
144 return (ENXIO);
145
142 if (windrv_lookup(0, "USB Bus") == NULL)
146 if (windrv_lookup(0, "USB Bus") == NULL)
143 return (UMATCH_NONE);
147 return (ENXIO);
144
148
145 if (uaa->iface != NULL)
146 return (UMATCH_NONE);
147
148 db = windrv_match((matchfuncptr)ndisusb_devcompare, self);
149 if (db == NULL)
149 db = windrv_match((matchfuncptr)ndisusb_devcompare, self);
150 if (db == NULL)
150 return (UMATCH_NONE);
151 return (ENXIO);
152 uaa->driver_info = db;
151
153
152 return (UMATCH_VENDOR_PRODUCT);
154 return (0);
153}
154
155static int
156ndisusb_attach(device_t self)
157{
155}
156
157static int
158ndisusb_attach(device_t self)
159{
158 struct drvdb_ent *db;
160 const struct drvdb_ent *db;
159 struct ndisusb_softc *dummy = device_get_softc(self);
161 struct ndisusb_softc *dummy = device_get_softc(self);
160 struct usb_attach_arg *uaa = device_get_ivars(self);
162 struct usb2_attach_arg *uaa = device_get_ivars(self);
161 struct ndis_softc *sc;
162 struct ndis_usb_type *t;
163 driver_object *drv;
164 int devidx = 0;
163 struct ndis_softc *sc;
164 struct ndis_usb_type *t;
165 driver_object *drv;
166 int devidx = 0;
165 usbd_status status;
166
167
168 db = uaa->driver_info;
167 sc = (struct ndis_softc *)dummy;
169 sc = (struct ndis_softc *)dummy;
168
169 if (uaa->device == NULL)
170 return ENXIO;
171
172 db = windrv_match((matchfuncptr)ndisusb_devcompare, self);
173 if (db == NULL)
174 return (ENXIO);
175
176 sc->ndis_dev = self;
177 sc->ndis_dobj = db->windrv_object;
178 sc->ndis_regvals = db->windrv_regvals;
179 sc->ndis_iftype = PNPBus;
170 sc->ndis_dev = self;
171 sc->ndis_dobj = db->windrv_object;
172 sc->ndis_regvals = db->windrv_regvals;
173 sc->ndis_iftype = PNPBus;
174 sc->ndisusb_dev = uaa->device;
180
181 /* Create PDO for this device instance */
182
183 drv = windrv_lookup(0, "USB Bus");
184 windrv_create_pdo(drv, self);
185
175
176 /* Create PDO for this device instance */
177
178 drv = windrv_lookup(0, "USB Bus");
179 windrv_create_pdo(drv, self);
180
186 status = usbd_set_config_no(uaa->device, NDISUSB_CONFIG_NO, 0);
187 if (status != USBD_NORMAL_COMPLETION) {
188 device_printf(self, "setting config no failed\n");
189 return (ENXIO);
190 }
191
192 /* Figure out exactly which device we matched. */
193
194 t = db->windrv_devlist;
195
196 while (t->ndis_name != NULL) {
181 /* Figure out exactly which device we matched. */
182
183 t = db->windrv_devlist;
184
185 while (t->ndis_name != NULL) {
197 if ((uaa->vendor == t->ndis_vid) &&
198 (uaa->product == t->ndis_did)) {
186 if ((uaa->info.idVendor == t->ndis_vid) &&
187 (uaa->info.idProduct == t->ndis_did)) {
199 sc->ndis_devidx = devidx;
200 break;
201 }
202 t++;
203 devidx++;
204 }
205
206 if (ndis_attach(self) != 0)
207 return ENXIO;
208
188 sc->ndis_devidx = devidx;
189 break;
190 }
191 t++;
192 devidx++;
193 }
194
195 if (ndis_attach(self) != 0)
196 return ENXIO;
197
209 usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, uaa->device, self);
210
211 return 0;
212}
213
214static int
215ndisusb_detach(device_t self)
216{
217 int i;
218 struct ndis_softc *sc = device_get_softc(self);
198 return 0;
199}
200
201static int
202ndisusb_detach(device_t self)
203{
204 int i;
205 struct ndis_softc *sc = device_get_softc(self);
219 struct usb_attach_arg *uaa = device_get_ivars(self);
206 struct ndisusb_ep *ne;;
220
221 sc->ndisusb_status |= NDISUSB_STATUS_DETACH;
222
223 for (i = 0; i < NDISUSB_ENDPT_MAX; i++) {
207
208 sc->ndisusb_status |= NDISUSB_STATUS_DETACH;
209
210 for (i = 0; i < NDISUSB_ENDPT_MAX; i++) {
224 if (sc->ndisusb_ep[i] == NULL)
225 continue;
226
227 usbd_abort_pipe(sc->ndisusb_ep[i]);
228 usbd_close_pipe(sc->ndisusb_ep[i]);
229 sc->ndisusb_ep[i] = NULL;
211 ne = &sc->ndisusb_ep[i];
212 usb2_transfer_unsetup(ne->ne_xfer, 1);
230 }
231
213 }
214
232 if (sc->ndisusb_iin_buf != NULL) {
233 free(sc->ndisusb_iin_buf, M_USBDEV);
234 sc->ndisusb_iin_buf = NULL;
235 }
236
237 ndis_pnpevent_nic(self, NDIS_PNP_EVENT_SURPRISE_REMOVED);
215 ndis_pnpevent_nic(self, NDIS_PNP_EVENT_SURPRISE_REMOVED);
238 ndis_cancel_timerlist();
239
216
240 usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, uaa->device, self);
241
242 return ndis_detach(self);
243}
244
245static struct resource_list *
246ndis_get_resource_list(device_t dev, device_t child)
247{
248 struct ndis_softc *sc;
249
250 sc = device_get_softc(dev);
251 return (BUS_GET_RESOURCE_LIST(device_get_parent(sc->ndis_dev), dev));
252}
217 return ndis_detach(self);
218}
219
220static struct resource_list *
221ndis_get_resource_list(device_t dev, device_t child)
222{
223 struct ndis_softc *sc;
224
225 sc = device_get_softc(dev);
226 return (BUS_GET_RESOURCE_LIST(device_get_parent(sc->ndis_dev), dev));
227}