if_upl.c revision 1.27.4.5 1 1.27.4.4 itohy /* $NetBSD: if_upl.c,v 1.27.4.5 2007/06/22 10:42:11 itohy Exp $ */
2 1.1 augustss /*
3 1.1 augustss * Copyright (c) 2000 The NetBSD Foundation, Inc.
4 1.1 augustss * All rights reserved.
5 1.1 augustss *
6 1.1 augustss * This code is derived from software contributed to The NetBSD Foundation
7 1.3 augustss * by Lennart Augustsson (lennart (at) augustsson.net) at
8 1.1 augustss * Carlstedt Research & Technology.
9 1.1 augustss *
10 1.1 augustss * Redistribution and use in source and binary forms, with or without
11 1.1 augustss * modification, are permitted provided that the following conditions
12 1.1 augustss * are met:
13 1.1 augustss * 1. Redistributions of source code must retain the above copyright
14 1.1 augustss * notice, this list of conditions and the following disclaimer.
15 1.1 augustss * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 augustss * notice, this list of conditions and the following disclaimer in the
17 1.1 augustss * documentation and/or other materials provided with the distribution.
18 1.1 augustss * 3. All advertising materials mentioning features or use of this software
19 1.1 augustss * must display the following acknowledgement:
20 1.1 augustss * This product includes software developed by the NetBSD
21 1.1 augustss * Foundation, Inc. and its contributors.
22 1.1 augustss * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 augustss * contributors may be used to endorse or promote products derived
24 1.1 augustss * from this software without specific prior written permission.
25 1.1 augustss *
26 1.1 augustss * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 augustss * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 augustss * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 augustss * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 augustss * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 augustss * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 augustss * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 augustss * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 augustss * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 augustss * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 augustss * POSSIBILITY OF SUCH DAMAGE.
37 1.1 augustss */
38 1.1 augustss
39 1.1 augustss /*
40 1.1 augustss * Prolific PL2301/PL2302 driver
41 1.1 augustss */
42 1.16 lukem
43 1.16 lukem #include <sys/cdefs.h>
44 1.27.4.4 itohy __KERNEL_RCSID(0, "$NetBSD: if_upl.c,v 1.27.4.5 2007/06/22 10:42:11 itohy Exp $");
45 1.1 augustss
46 1.1 augustss #include "opt_inet.h"
47 1.1 augustss #include "bpfilter.h"
48 1.1 augustss #include "rnd.h"
49 1.1 augustss
50 1.1 augustss #include <sys/param.h>
51 1.1 augustss #include <sys/systm.h>
52 1.1 augustss #include <sys/callout.h>
53 1.1 augustss #include <sys/sockio.h>
54 1.1 augustss #include <sys/mbuf.h>
55 1.1 augustss #include <sys/malloc.h>
56 1.1 augustss #include <sys/kernel.h>
57 1.1 augustss #include <sys/socket.h>
58 1.1 augustss
59 1.1 augustss #include <sys/device.h>
60 1.1 augustss #if NRND > 0
61 1.1 augustss #include <sys/rnd.h>
62 1.1 augustss #endif
63 1.1 augustss
64 1.1 augustss #include <net/if.h>
65 1.1 augustss #include <net/if_types.h>
66 1.1 augustss #include <net/if_dl.h>
67 1.1 augustss #include <net/netisr.h>
68 1.27.4.2 itohy #include <net/if_ether.h>
69 1.1 augustss
70 1.1 augustss #define BPF_MTAP(ifp, m) bpf_mtap((ifp)->if_bpf, (m))
71 1.1 augustss
72 1.1 augustss #if NBPFILTER > 0
73 1.1 augustss #include <net/bpf.h>
74 1.1 augustss #endif
75 1.1 augustss
76 1.1 augustss #ifdef INET
77 1.19 augustss #include <netinet/in.h>
78 1.19 augustss #include <netinet/in_var.h>
79 1.1 augustss #include <netinet/if_inarp.h>
80 1.1 augustss #endif
81 1.1 augustss
82 1.1 augustss
83 1.1 augustss #include <dev/usb/usb.h>
84 1.1 augustss #include <dev/usb/usbdi.h>
85 1.1 augustss #include <dev/usb/usbdi_util.h>
86 1.1 augustss #include <dev/usb/usbdevs.h>
87 1.27.4.2 itohy #include <dev/usb/usb_ethersubr.h>
88 1.1 augustss
89 1.1 augustss /*
90 1.1 augustss * 7 6 5 4 3 2 1 0
91 1.6 augustss * tx rx 1 0
92 1.1 augustss * 1110 0000 rxdata
93 1.1 augustss * 1010 0000 idle
94 1.1 augustss * 0010 0000 tx over
95 1.1 augustss * 0110 tx over + rxd
96 1.1 augustss */
97 1.1 augustss
98 1.1 augustss #define UPL_RXDATA 0x40
99 1.1 augustss #define UPL_TXOK 0x80
100 1.1 augustss
101 1.1 augustss #define UPL_INTR_PKTLEN 1
102 1.1 augustss
103 1.1 augustss #define UPL_CONFIG_NO 1
104 1.1 augustss #define UPL_IFACE_IDX 0
105 1.1 augustss
106 1.1 augustss /***/
107 1.1 augustss
108 1.1 augustss #define UPL_INTR_INTERVAL 20
109 1.1 augustss
110 1.1 augustss #define UPL_BUFSZ 1024
111 1.1 augustss
112 1.1 augustss #define UPL_RX_FRAMES 1
113 1.1 augustss #define UPL_TX_FRAMES 1
114 1.1 augustss
115 1.1 augustss #define UPL_RX_LIST_CNT 1
116 1.1 augustss #define UPL_TX_LIST_CNT 1
117 1.1 augustss
118 1.1 augustss #define UPL_ENDPT_RX 0x0
119 1.1 augustss #define UPL_ENDPT_TX 0x1
120 1.1 augustss #define UPL_ENDPT_INTR 0x2
121 1.1 augustss #define UPL_ENDPT_MAX 0x3
122 1.1 augustss
123 1.1 augustss struct upl_type {
124 1.1 augustss u_int16_t upl_vid;
125 1.1 augustss u_int16_t upl_did;
126 1.1 augustss };
127 1.1 augustss
128 1.1 augustss struct upl_cdata {
129 1.27.4.2 itohy struct ue_chain upl_tx_chain[UPL_TX_LIST_CNT];
130 1.27.4.2 itohy struct ue_chain upl_rx_chain[UPL_RX_LIST_CNT];
131 1.1 augustss int upl_tx_prod;
132 1.1 augustss int upl_tx_cons;
133 1.1 augustss int upl_tx_cnt;
134 1.1 augustss int upl_rx_prod;
135 1.1 augustss };
136 1.1 augustss
137 1.1 augustss struct upl_softc {
138 1.1 augustss USBBASEDEVICE sc_dev;
139 1.1 augustss
140 1.1 augustss struct ifnet sc_if;
141 1.1 augustss #if NRND > 0
142 1.1 augustss rndsource_element_t sc_rnd_source;
143 1.1 augustss #endif
144 1.1 augustss
145 1.1 augustss usb_callout_t sc_stat_ch;
146 1.1 augustss
147 1.1 augustss usbd_device_handle sc_udev;
148 1.1 augustss usbd_interface_handle sc_iface;
149 1.1 augustss u_int16_t sc_vendor;
150 1.1 augustss u_int16_t sc_product;
151 1.1 augustss int sc_ed[UPL_ENDPT_MAX];
152 1.1 augustss usbd_pipe_handle sc_ep[UPL_ENDPT_MAX];
153 1.1 augustss struct upl_cdata sc_cdata;
154 1.1 augustss
155 1.1 augustss uByte sc_ibuf;
156 1.1 augustss
157 1.1 augustss char sc_dying;
158 1.1 augustss char sc_attached;
159 1.1 augustss u_int sc_rx_errs;
160 1.1 augustss struct timeval sc_rx_notice;
161 1.1 augustss u_int sc_intr_errs;
162 1.1 augustss };
163 1.1 augustss
164 1.1 augustss #ifdef UPL_DEBUG
165 1.1 augustss #define DPRINTF(x) if (upldebug) logprintf x
166 1.1 augustss #define DPRINTFN(n,x) if (upldebug >= (n)) logprintf x
167 1.1 augustss int upldebug = 0;
168 1.1 augustss #else
169 1.1 augustss #define DPRINTF(x)
170 1.1 augustss #define DPRINTFN(n,x)
171 1.1 augustss #endif
172 1.1 augustss
173 1.1 augustss /*
174 1.1 augustss * Various supported device vendors/products.
175 1.1 augustss */
176 1.1 augustss Static struct upl_type sc_devs[] = {
177 1.1 augustss { USB_VENDOR_PROLIFIC, USB_PRODUCT_PROLIFIC_PL2301 },
178 1.1 augustss { USB_VENDOR_PROLIFIC, USB_PRODUCT_PROLIFIC_PL2302 },
179 1.1 augustss { 0, 0 }
180 1.1 augustss };
181 1.1 augustss
182 1.1 augustss USB_DECLARE_DRIVER(upl);
183 1.1 augustss
184 1.4 augustss Static int upl_openpipes(struct upl_softc *);
185 1.4 augustss Static int upl_send(struct upl_softc *, struct mbuf *, int);
186 1.4 augustss Static void upl_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
187 1.4 augustss Static void upl_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
188 1.4 augustss Static void upl_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
189 1.4 augustss Static void upl_start(struct ifnet *);
190 1.27.4.3 itohy Static int upl_ioctl(struct ifnet *, u_long, usb_ioctlarg_t);
191 1.27.4.2 itohy Static int upl_init(struct ifnet *);
192 1.27.4.2 itohy Static void upl_stop(struct ifnet *, int);
193 1.4 augustss Static void upl_watchdog(struct ifnet *);
194 1.4 augustss
195 1.27 dyoung Static int upl_output(struct ifnet *, struct mbuf *, const struct sockaddr *,
196 1.4 augustss struct rtentry *);
197 1.4 augustss Static void upl_input(struct ifnet *, struct mbuf *);
198 1.1 augustss
199 1.1 augustss /*
200 1.1 augustss * Probe for a Prolific chip.
201 1.1 augustss */
202 1.1 augustss USB_MATCH(upl)
203 1.1 augustss {
204 1.1 augustss USB_MATCH_START(upl, uaa);
205 1.1 augustss struct upl_type *t;
206 1.1 augustss
207 1.27.4.4 itohy #ifndef USB_USE_IFATTACH
208 1.1 augustss if (uaa->iface != NULL)
209 1.1 augustss return (UMATCH_NONE);
210 1.27.4.4 itohy #endif /* USB_USE_IFATTACH */
211 1.1 augustss
212 1.1 augustss for (t = sc_devs; t->upl_vid != 0; t++)
213 1.1 augustss if (uaa->vendor == t->upl_vid && uaa->product == t->upl_did)
214 1.1 augustss return (UMATCH_VENDOR_PRODUCT);
215 1.1 augustss
216 1.1 augustss return (UMATCH_NONE);
217 1.1 augustss }
218 1.1 augustss
219 1.1 augustss USB_ATTACH(upl)
220 1.1 augustss {
221 1.1 augustss USB_ATTACH_START(upl, sc, uaa);
222 1.22 augustss char *devinfop;
223 1.1 augustss int s;
224 1.1 augustss usbd_device_handle dev = uaa->device;
225 1.1 augustss usbd_interface_handle iface;
226 1.1 augustss usbd_status err;
227 1.1 augustss struct ifnet *ifp;
228 1.1 augustss usb_interface_descriptor_t *id;
229 1.1 augustss usb_endpoint_descriptor_t *ed;
230 1.1 augustss int i;
231 1.1 augustss
232 1.1 augustss DPRINTFN(5,(" : upl_attach: sc=%p, dev=%p", sc, dev));
233 1.1 augustss
234 1.22 augustss devinfop = usbd_devinfo_alloc(dev, 0);
235 1.1 augustss USB_ATTACH_SETUP;
236 1.22 augustss printf("%s: %s\n", USBDEVNAME(sc->sc_dev), devinfop);
237 1.22 augustss usbd_devinfo_free(devinfop);
238 1.1 augustss
239 1.9 augustss err = usbd_set_config_no(dev, UPL_CONFIG_NO, 1);
240 1.1 augustss if (err) {
241 1.1 augustss printf("%s: setting config no failed\n",
242 1.1 augustss USBDEVNAME(sc->sc_dev));
243 1.1 augustss USB_ATTACH_ERROR_RETURN;
244 1.1 augustss }
245 1.1 augustss
246 1.1 augustss sc->sc_udev = dev;
247 1.1 augustss sc->sc_product = uaa->product;
248 1.1 augustss sc->sc_vendor = uaa->vendor;
249 1.1 augustss
250 1.1 augustss err = usbd_device2interface_handle(dev, UPL_IFACE_IDX, &iface);
251 1.1 augustss if (err) {
252 1.1 augustss printf("%s: getting interface handle failed\n",
253 1.1 augustss USBDEVNAME(sc->sc_dev));
254 1.1 augustss USB_ATTACH_ERROR_RETURN;
255 1.1 augustss }
256 1.1 augustss
257 1.1 augustss sc->sc_iface = iface;
258 1.1 augustss id = usbd_get_interface_descriptor(iface);
259 1.1 augustss
260 1.1 augustss /* Find endpoints. */
261 1.1 augustss for (i = 0; i < id->bNumEndpoints; i++) {
262 1.1 augustss ed = usbd_interface2endpoint_descriptor(iface, i);
263 1.1 augustss if (ed == NULL) {
264 1.1 augustss printf("%s: couldn't get ep %d\n",
265 1.1 augustss USBDEVNAME(sc->sc_dev), i);
266 1.1 augustss USB_ATTACH_ERROR_RETURN;
267 1.1 augustss }
268 1.1 augustss if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
269 1.1 augustss UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
270 1.1 augustss sc->sc_ed[UPL_ENDPT_RX] = ed->bEndpointAddress;
271 1.1 augustss } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
272 1.1 augustss UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
273 1.1 augustss sc->sc_ed[UPL_ENDPT_TX] = ed->bEndpointAddress;
274 1.1 augustss } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
275 1.1 augustss UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
276 1.1 augustss sc->sc_ed[UPL_ENDPT_INTR] = ed->bEndpointAddress;
277 1.1 augustss }
278 1.1 augustss }
279 1.1 augustss
280 1.1 augustss if (sc->sc_ed[UPL_ENDPT_RX] == 0 || sc->sc_ed[UPL_ENDPT_TX] == 0 ||
281 1.1 augustss sc->sc_ed[UPL_ENDPT_INTR] == 0) {
282 1.1 augustss printf("%s: missing endpoint\n", USBDEVNAME(sc->sc_dev));
283 1.1 augustss USB_ATTACH_ERROR_RETURN;
284 1.1 augustss }
285 1.1 augustss
286 1.14 thorpej s = splnet();
287 1.1 augustss
288 1.1 augustss /* Initialize interface info.*/
289 1.1 augustss ifp = &sc->sc_if;
290 1.1 augustss ifp->if_softc = sc;
291 1.1 augustss ifp->if_mtu = UPL_BUFSZ;
292 1.1 augustss ifp->if_flags = IFF_POINTOPOINT | IFF_NOARP | IFF_SIMPLEX;
293 1.1 augustss ifp->if_ioctl = upl_ioctl;
294 1.1 augustss ifp->if_start = upl_start;
295 1.27.4.2 itohy ifp->if_init = upl_init;
296 1.27.4.2 itohy ifp->if_stop = upl_stop;
297 1.1 augustss ifp->if_watchdog = upl_watchdog;
298 1.1 augustss strncpy(ifp->if_xname, USBDEVNAME(sc->sc_dev), IFNAMSIZ);
299 1.1 augustss
300 1.1 augustss ifp->if_type = IFT_OTHER;
301 1.1 augustss ifp->if_addrlen = 0;
302 1.1 augustss ifp->if_hdrlen = 0;
303 1.1 augustss ifp->if_output = upl_output;
304 1.1 augustss ifp->if_input = upl_input;
305 1.1 augustss ifp->if_baudrate = 12000000;
306 1.12 augustss ifp->if_dlt = DLT_RAW;
307 1.17 itojun IFQ_SET_READY(&ifp->if_snd);
308 1.1 augustss
309 1.1 augustss /* Attach the interface. */
310 1.1 augustss if_attach(ifp);
311 1.12 augustss if_alloc_sadl(ifp);
312 1.1 augustss
313 1.1 augustss #if NBPFILTER > 0
314 1.12 augustss bpfattach(ifp, DLT_RAW, 0);
315 1.1 augustss #endif
316 1.1 augustss #if NRND > 0
317 1.1 augustss rnd_attach_source(&sc->sc_rnd_source, USBDEVNAME(sc->sc_dev),
318 1.1 augustss RND_TYPE_NET, 0);
319 1.1 augustss #endif
320 1.1 augustss
321 1.1 augustss sc->sc_attached = 1;
322 1.1 augustss splx(s);
323 1.1 augustss
324 1.1 augustss usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev,
325 1.1 augustss USBDEV(sc->sc_dev));
326 1.1 augustss
327 1.1 augustss USB_ATTACH_SUCCESS_RETURN;
328 1.1 augustss }
329 1.1 augustss
330 1.1 augustss USB_DETACH(upl)
331 1.1 augustss {
332 1.1 augustss USB_DETACH_START(upl, sc);
333 1.1 augustss struct ifnet *ifp = &sc->sc_if;
334 1.1 augustss int s;
335 1.1 augustss
336 1.18 augustss DPRINTFN(2,("%s: %s: enter\n", USBDEVNAME(sc->sc_dev), __func__));
337 1.1 augustss
338 1.1 augustss s = splusb();
339 1.1 augustss
340 1.1 augustss if (!sc->sc_attached) {
341 1.1 augustss /* Detached before attached finished, so just bail out. */
342 1.1 augustss splx(s);
343 1.1 augustss return (0);
344 1.1 augustss }
345 1.1 augustss
346 1.1 augustss if (ifp->if_flags & IFF_RUNNING)
347 1.27.4.2 itohy upl_stop(ifp, 1);
348 1.1 augustss
349 1.1 augustss #if NRND > 0
350 1.1 augustss rnd_detach_source(&sc->sc_rnd_source);
351 1.1 augustss #endif
352 1.1 augustss #if NBPFILTER > 0
353 1.1 augustss bpfdetach(ifp);
354 1.1 augustss #endif
355 1.1 augustss
356 1.1 augustss if_detach(ifp);
357 1.1 augustss
358 1.1 augustss #ifdef DIAGNOSTIC
359 1.1 augustss if (sc->sc_ep[UPL_ENDPT_TX] != NULL ||
360 1.1 augustss sc->sc_ep[UPL_ENDPT_RX] != NULL ||
361 1.1 augustss sc->sc_ep[UPL_ENDPT_INTR] != NULL)
362 1.1 augustss printf("%s: detach has active endpoints\n",
363 1.1 augustss USBDEVNAME(sc->sc_dev));
364 1.1 augustss #endif
365 1.1 augustss
366 1.1 augustss sc->sc_attached = 0;
367 1.1 augustss splx(s);
368 1.1 augustss
369 1.1 augustss usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev,
370 1.1 augustss USBDEV(sc->sc_dev));
371 1.1 augustss
372 1.1 augustss return (0);
373 1.1 augustss }
374 1.1 augustss
375 1.1 augustss int
376 1.4 augustss upl_activate(device_ptr_t self, enum devact act)
377 1.1 augustss {
378 1.1 augustss struct upl_softc *sc = (struct upl_softc *)self;
379 1.1 augustss
380 1.18 augustss DPRINTFN(2,("%s: %s: enter\n", USBDEVNAME(sc->sc_dev), __func__));
381 1.1 augustss
382 1.1 augustss switch (act) {
383 1.1 augustss case DVACT_ACTIVATE:
384 1.1 augustss return (EOPNOTSUPP);
385 1.1 augustss break;
386 1.1 augustss
387 1.1 augustss case DVACT_DEACTIVATE:
388 1.1 augustss /* Deactivate the interface. */
389 1.1 augustss if_deactivate(&sc->sc_if);
390 1.1 augustss sc->sc_dying = 1;
391 1.1 augustss break;
392 1.1 augustss }
393 1.1 augustss return (0);
394 1.1 augustss }
395 1.1 augustss
396 1.1 augustss /*
397 1.1 augustss * A frame has been uploaded: pass the resulting mbuf chain up to
398 1.1 augustss * the higher level protocols.
399 1.1 augustss */
400 1.1 augustss Static void
401 1.4 augustss upl_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
402 1.1 augustss {
403 1.27.4.2 itohy struct ue_chain *c = priv;
404 1.27.4.2 itohy struct upl_softc *sc = (void *)c->ue_dev;
405 1.1 augustss struct ifnet *ifp = &sc->sc_if;
406 1.1 augustss struct mbuf *m;
407 1.1 augustss int total_len = 0;
408 1.1 augustss int s;
409 1.1 augustss
410 1.1 augustss if (sc->sc_dying)
411 1.1 augustss return;
412 1.1 augustss
413 1.1 augustss if (!(ifp->if_flags & IFF_RUNNING))
414 1.1 augustss return;
415 1.1 augustss
416 1.27.4.2 itohy usbd_unmap_buffer(xfer);
417 1.27.4.2 itohy
418 1.1 augustss if (status != USBD_NORMAL_COMPLETION) {
419 1.1 augustss if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
420 1.1 augustss return;
421 1.1 augustss sc->sc_rx_errs++;
422 1.1 augustss if (usbd_ratecheck(&sc->sc_rx_notice)) {
423 1.1 augustss printf("%s: %u usb errors on rx: %s\n",
424 1.1 augustss USBDEVNAME(sc->sc_dev), sc->sc_rx_errs,
425 1.1 augustss usbd_errstr(status));
426 1.1 augustss sc->sc_rx_errs = 0;
427 1.1 augustss }
428 1.1 augustss if (status == USBD_STALLED)
429 1.23 augustss usbd_clear_endpoint_stall_async(sc->sc_ep[UPL_ENDPT_RX]);
430 1.1 augustss goto done;
431 1.1 augustss }
432 1.1 augustss
433 1.1 augustss usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL);
434 1.1 augustss
435 1.1 augustss DPRINTFN(9,("%s: %s: enter status=%d length=%d\n",
436 1.18 augustss USBDEVNAME(sc->sc_dev), __func__, status, total_len));
437 1.1 augustss
438 1.27.4.2 itohy m = c->ue_mbuf;
439 1.27.4.2 itohy
440 1.27.4.2 itohy /*
441 1.27.4.2 itohy * Allocate new mbuf cluster for the next transfer.
442 1.27.4.2 itohy * If that failed, discard current packet and recycle the mbuf.
443 1.27.4.2 itohy */
444 1.27.4.2 itohy if ((c->ue_mbuf = usb_ether_newbuf(NULL)) == NULL) {
445 1.27.4.2 itohy printf("%s: no memory for rx list -- packet dropped!\n",
446 1.27.4.2 itohy USBDEVNAME(sc->sc_dev));
447 1.27.4.2 itohy ifp->if_ierrors++;
448 1.27.4.2 itohy c->ue_mbuf = usb_ether_newbuf(m);
449 1.27.4.2 itohy goto done;
450 1.27.4.2 itohy }
451 1.1 augustss
452 1.1 augustss ifp->if_ipackets++;
453 1.1 augustss m->m_pkthdr.len = m->m_len = total_len;
454 1.1 augustss
455 1.1 augustss m->m_pkthdr.rcvif = ifp;
456 1.1 augustss
457 1.14 thorpej s = splnet();
458 1.1 augustss
459 1.1 augustss #if NBPFILTER > 0
460 1.1 augustss /*
461 1.1 augustss * Handle BPF listeners. Let the BPF user see the packet, but
462 1.1 augustss * don't pass it up to the ether_input() layer unless it's
463 1.1 augustss * a broadcast packet, multicast packet, matches our ethernet
464 1.1 augustss * address or the interface is in promiscuous mode.
465 1.1 augustss */
466 1.1 augustss if (ifp->if_bpf) {
467 1.1 augustss BPF_MTAP(ifp, m);
468 1.1 augustss }
469 1.1 augustss #endif
470 1.1 augustss
471 1.1 augustss DPRINTFN(10,("%s: %s: deliver %d\n", USBDEVNAME(sc->sc_dev),
472 1.18 augustss __func__, m->m_len));
473 1.1 augustss
474 1.1 augustss IF_INPUT(ifp, m);
475 1.1 augustss
476 1.1 augustss splx(s);
477 1.1 augustss
478 1.1 augustss done:
479 1.1 augustss /* Setup new transfer. */
480 1.27.4.2 itohy (void)usbd_map_buffer_mbuf(c->ue_xfer, c->ue_mbuf);
481 1.27.4.2 itohy usbd_setup_xfer(c->ue_xfer, sc->sc_ep[UPL_ENDPT_RX],
482 1.27.4.5 itohy c, NULL /* XXX buf */, UPL_BUFSZ, USBD_SHORT_XFER_OK | USBD_NO_COPY
483 1.27.4.5 itohy #ifdef __FreeBSD__ /* callback needs context */
484 1.27.4.5 itohy | USBD_CALLBACK_AS_TASK
485 1.27.4.5 itohy #endif
486 1.27.4.5 itohy ,
487 1.1 augustss USBD_NO_TIMEOUT, upl_rxeof);
488 1.27.4.2 itohy usbd_transfer(c->ue_xfer);
489 1.1 augustss
490 1.1 augustss DPRINTFN(10,("%s: %s: start rx\n", USBDEVNAME(sc->sc_dev),
491 1.18 augustss __func__));
492 1.1 augustss }
493 1.1 augustss
494 1.1 augustss /*
495 1.1 augustss * A frame was downloaded to the chip. It's safe for us to clean up
496 1.1 augustss * the list buffers.
497 1.1 augustss */
498 1.1 augustss Static void
499 1.26 christos upl_txeof(usbd_xfer_handle xfer, usbd_private_handle priv,
500 1.25 christos usbd_status status)
501 1.1 augustss {
502 1.27.4.2 itohy struct ue_chain *c = priv;
503 1.27.4.2 itohy struct upl_softc *sc = (void *)c->ue_dev;
504 1.1 augustss struct ifnet *ifp = &sc->sc_if;
505 1.1 augustss int s;
506 1.1 augustss
507 1.1 augustss if (sc->sc_dying)
508 1.1 augustss return;
509 1.1 augustss
510 1.14 thorpej s = splnet();
511 1.1 augustss
512 1.1 augustss DPRINTFN(10,("%s: %s: enter status=%d\n", USBDEVNAME(sc->sc_dev),
513 1.18 augustss __func__, status));
514 1.1 augustss
515 1.1 augustss ifp->if_timer = 0;
516 1.1 augustss ifp->if_flags &= ~IFF_OACTIVE;
517 1.1 augustss
518 1.27.4.2 itohy usbd_unmap_buffer(xfer);
519 1.27.4.2 itohy
520 1.1 augustss if (status != USBD_NORMAL_COMPLETION) {
521 1.1 augustss if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
522 1.1 augustss splx(s);
523 1.1 augustss return;
524 1.1 augustss }
525 1.1 augustss ifp->if_oerrors++;
526 1.1 augustss printf("%s: usb error on tx: %s\n", USBDEVNAME(sc->sc_dev),
527 1.1 augustss usbd_errstr(status));
528 1.1 augustss if (status == USBD_STALLED)
529 1.23 augustss usbd_clear_endpoint_stall_async(sc->sc_ep[UPL_ENDPT_TX]);
530 1.1 augustss splx(s);
531 1.1 augustss return;
532 1.1 augustss }
533 1.1 augustss
534 1.1 augustss ifp->if_opackets++;
535 1.1 augustss
536 1.27.4.2 itohy m_freem(c->ue_mbuf);
537 1.27.4.2 itohy c->ue_mbuf = NULL;
538 1.1 augustss
539 1.17 itojun if (IFQ_IS_EMPTY(&ifp->if_snd) == 0)
540 1.1 augustss upl_start(ifp);
541 1.1 augustss
542 1.1 augustss splx(s);
543 1.1 augustss }
544 1.1 augustss
545 1.1 augustss Static int
546 1.4 augustss upl_send(struct upl_softc *sc, struct mbuf *m, int idx)
547 1.1 augustss {
548 1.1 augustss int total_len;
549 1.27.4.2 itohy struct ue_chain *c;
550 1.1 augustss usbd_status err;
551 1.27.4.2 itohy int ret;
552 1.1 augustss
553 1.1 augustss c = &sc->sc_cdata.upl_tx_chain[idx];
554 1.1 augustss
555 1.27.4.2 itohy ret = usb_ether_map_tx_buffer_mbuf(c, m);
556 1.27.4.2 itohy if (ret)
557 1.27.4.2 itohy return (ret);
558 1.1 augustss
559 1.1 augustss total_len = m->m_pkthdr.len;
560 1.1 augustss
561 1.1 augustss DPRINTFN(10,("%s: %s: total_len=%d\n",
562 1.18 augustss USBDEVNAME(sc->sc_dev), __func__, total_len));
563 1.1 augustss
564 1.27.4.2 itohy usbd_setup_xfer(c->ue_xfer, sc->sc_ep[UPL_ENDPT_TX],
565 1.27.4.5 itohy c, NULL /* XXX buf */, total_len, USBD_NO_COPY
566 1.27.4.5 itohy #ifdef __FreeBSD__ /* callback needs context */
567 1.27.4.5 itohy | USBD_CALLBACK_AS_TASK
568 1.27.4.5 itohy #endif
569 1.27.4.5 itohy , USBD_DEFAULT_TIMEOUT,
570 1.1 augustss upl_txeof);
571 1.1 augustss
572 1.1 augustss /* Transmit */
573 1.27.4.2 itohy err = usbd_transfer(c->ue_xfer);
574 1.1 augustss if (err != USBD_IN_PROGRESS) {
575 1.1 augustss printf("%s: upl_send error=%s\n", USBDEVNAME(sc->sc_dev),
576 1.1 augustss usbd_errstr(err));
577 1.27.4.2 itohy upl_stop(&sc->sc_if, 0);
578 1.1 augustss return (EIO);
579 1.1 augustss }
580 1.1 augustss
581 1.1 augustss sc->sc_cdata.upl_tx_cnt++;
582 1.1 augustss
583 1.1 augustss return (0);
584 1.1 augustss }
585 1.1 augustss
586 1.1 augustss Static void
587 1.4 augustss upl_start(struct ifnet *ifp)
588 1.1 augustss {
589 1.1 augustss struct upl_softc *sc = ifp->if_softc;
590 1.1 augustss struct mbuf *m_head = NULL;
591 1.1 augustss
592 1.1 augustss if (sc->sc_dying)
593 1.1 augustss return;
594 1.1 augustss
595 1.18 augustss DPRINTFN(10,("%s: %s: enter\n", USBDEVNAME(sc->sc_dev),__func__));
596 1.1 augustss
597 1.1 augustss if (ifp->if_flags & IFF_OACTIVE)
598 1.1 augustss return;
599 1.1 augustss
600 1.17 itojun IFQ_POLL(&ifp->if_snd, m_head);
601 1.1 augustss if (m_head == NULL)
602 1.1 augustss return;
603 1.1 augustss
604 1.1 augustss if (upl_send(sc, m_head, 0)) {
605 1.1 augustss ifp->if_flags |= IFF_OACTIVE;
606 1.1 augustss return;
607 1.1 augustss }
608 1.1 augustss
609 1.17 itojun IFQ_DEQUEUE(&ifp->if_snd, m_head);
610 1.17 itojun
611 1.1 augustss #if NBPFILTER > 0
612 1.1 augustss /*
613 1.1 augustss * If there's a BPF listener, bounce a copy of this frame
614 1.1 augustss * to him.
615 1.1 augustss */
616 1.1 augustss if (ifp->if_bpf)
617 1.1 augustss BPF_MTAP(ifp, m_head);
618 1.1 augustss #endif
619 1.1 augustss
620 1.1 augustss ifp->if_flags |= IFF_OACTIVE;
621 1.1 augustss
622 1.1 augustss /*
623 1.1 augustss * Set a timeout in case the chip goes out to lunch.
624 1.1 augustss */
625 1.1 augustss ifp->if_timer = 5;
626 1.1 augustss }
627 1.1 augustss
628 1.27.4.2 itohy Static int
629 1.27.4.2 itohy upl_init(struct ifnet *ifp)
630 1.1 augustss {
631 1.27.4.2 itohy struct upl_softc *sc = ifp->if_softc;
632 1.1 augustss int s;
633 1.27.4.2 itohy struct ue_chain *c;
634 1.27.4.2 itohy int i;
635 1.1 augustss
636 1.1 augustss if (sc->sc_dying)
637 1.27.4.2 itohy return (EIO);
638 1.1 augustss
639 1.18 augustss DPRINTFN(10,("%s: %s: enter\n", USBDEVNAME(sc->sc_dev),__func__));
640 1.1 augustss
641 1.1 augustss if (ifp->if_flags & IFF_RUNNING)
642 1.27.4.2 itohy return (EIO);
643 1.1 augustss
644 1.14 thorpej s = splnet();
645 1.1 augustss
646 1.27.4.2 itohy if (sc->sc_ep[UPL_ENDPT_RX] == NULL) {
647 1.27.4.2 itohy if (upl_openpipes(sc)) {
648 1.27.4.2 itohy splx(s);
649 1.27.4.2 itohy return (EIO);
650 1.27.4.2 itohy }
651 1.27.4.2 itohy }
652 1.27.4.2 itohy
653 1.1 augustss /* Init TX ring. */
654 1.27.4.2 itohy if ((i = usb_ether_tx_list_init(USBDEV(sc->sc_dev),
655 1.27.4.2 itohy sc->sc_cdata.upl_tx_chain, UPL_TX_LIST_CNT,
656 1.27.4.2 itohy sc->sc_udev, sc->sc_ep[UPL_ENDPT_TX], NULL))) {
657 1.1 augustss printf("%s: tx list init failed\n", USBDEVNAME(sc->sc_dev));
658 1.1 augustss splx(s);
659 1.27.4.2 itohy return (i);
660 1.1 augustss }
661 1.1 augustss
662 1.1 augustss /* Init RX ring. */
663 1.27.4.2 itohy if ((i = usb_ether_rx_list_init(USBDEV(sc->sc_dev),
664 1.27.4.2 itohy sc->sc_cdata.upl_rx_chain, UPL_RX_LIST_CNT,
665 1.27.4.2 itohy sc->sc_udev, sc->sc_ep[UPL_ENDPT_RX]))) {
666 1.1 augustss printf("%s: rx list init failed\n", USBDEVNAME(sc->sc_dev));
667 1.1 augustss splx(s);
668 1.27.4.2 itohy return (i);
669 1.1 augustss }
670 1.1 augustss
671 1.27.4.2 itohy /* Start up the receive pipe. */
672 1.27.4.2 itohy for (i = 0; i < UPL_RX_LIST_CNT; i++) {
673 1.27.4.2 itohy c = &sc->sc_cdata.upl_rx_chain[i];
674 1.27.4.2 itohy (void)usbd_map_buffer_mbuf(c->ue_xfer, c->ue_mbuf);
675 1.27.4.2 itohy usbd_setup_xfer(c->ue_xfer, sc->sc_ep[UPL_ENDPT_RX],
676 1.27.4.2 itohy c, NULL /* XXX buf */, UPL_BUFSZ,
677 1.27.4.5 itohy USBD_SHORT_XFER_OK | USBD_NO_COPY
678 1.27.4.5 itohy #ifdef __FreeBSD__ /* callback needs context */
679 1.27.4.5 itohy | USBD_CALLBACK_AS_TASK
680 1.27.4.5 itohy #endif
681 1.27.4.5 itohy , USBD_NO_TIMEOUT,
682 1.27.4.2 itohy upl_rxeof);
683 1.27.4.2 itohy usbd_transfer(c->ue_xfer);
684 1.1 augustss }
685 1.1 augustss
686 1.1 augustss ifp->if_flags |= IFF_RUNNING;
687 1.1 augustss ifp->if_flags &= ~IFF_OACTIVE;
688 1.1 augustss
689 1.1 augustss splx(s);
690 1.27.4.2 itohy return (0);
691 1.1 augustss }
692 1.1 augustss
693 1.1 augustss Static int
694 1.4 augustss upl_openpipes(struct upl_softc *sc)
695 1.1 augustss {
696 1.1 augustss usbd_status err;
697 1.1 augustss
698 1.1 augustss /* Open RX and TX pipes. */
699 1.1 augustss err = usbd_open_pipe(sc->sc_iface, sc->sc_ed[UPL_ENDPT_RX],
700 1.1 augustss USBD_EXCLUSIVE_USE, &sc->sc_ep[UPL_ENDPT_RX]);
701 1.1 augustss if (err) {
702 1.1 augustss printf("%s: open rx pipe failed: %s\n",
703 1.1 augustss USBDEVNAME(sc->sc_dev), usbd_errstr(err));
704 1.1 augustss return (EIO);
705 1.1 augustss }
706 1.1 augustss err = usbd_open_pipe(sc->sc_iface, sc->sc_ed[UPL_ENDPT_TX],
707 1.1 augustss USBD_EXCLUSIVE_USE, &sc->sc_ep[UPL_ENDPT_TX]);
708 1.1 augustss if (err) {
709 1.1 augustss printf("%s: open tx pipe failed: %s\n",
710 1.1 augustss USBDEVNAME(sc->sc_dev), usbd_errstr(err));
711 1.1 augustss return (EIO);
712 1.1 augustss }
713 1.1 augustss err = usbd_open_pipe_intr(sc->sc_iface, sc->sc_ed[UPL_ENDPT_INTR],
714 1.1 augustss USBD_EXCLUSIVE_USE, &sc->sc_ep[UPL_ENDPT_INTR], sc,
715 1.19 augustss &sc->sc_ibuf, UPL_INTR_PKTLEN, upl_intr,
716 1.1 augustss UPL_INTR_INTERVAL);
717 1.1 augustss if (err) {
718 1.1 augustss printf("%s: open intr pipe failed: %s\n",
719 1.1 augustss USBDEVNAME(sc->sc_dev), usbd_errstr(err));
720 1.1 augustss return (EIO);
721 1.1 augustss }
722 1.1 augustss
723 1.1 augustss return (0);
724 1.1 augustss }
725 1.1 augustss
726 1.1 augustss Static void
727 1.26 christos upl_intr(usbd_xfer_handle xfer, usbd_private_handle priv,
728 1.25 christos usbd_status status)
729 1.1 augustss {
730 1.1 augustss struct upl_softc *sc = priv;
731 1.1 augustss struct ifnet *ifp = &sc->sc_if;
732 1.1 augustss uByte stat;
733 1.1 augustss
734 1.18 augustss DPRINTFN(15,("%s: %s: enter\n", USBDEVNAME(sc->sc_dev),__func__));
735 1.1 augustss
736 1.1 augustss if (sc->sc_dying)
737 1.1 augustss return;
738 1.1 augustss
739 1.1 augustss if (!(ifp->if_flags & IFF_RUNNING))
740 1.1 augustss return;
741 1.1 augustss
742 1.1 augustss if (status != USBD_NORMAL_COMPLETION) {
743 1.1 augustss if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
744 1.1 augustss return;
745 1.1 augustss }
746 1.1 augustss sc->sc_intr_errs++;
747 1.1 augustss if (usbd_ratecheck(&sc->sc_rx_notice)) {
748 1.1 augustss printf("%s: %u usb errors on intr: %s\n",
749 1.1 augustss USBDEVNAME(sc->sc_dev), sc->sc_rx_errs,
750 1.1 augustss usbd_errstr(status));
751 1.1 augustss sc->sc_intr_errs = 0;
752 1.1 augustss }
753 1.1 augustss if (status == USBD_STALLED)
754 1.23 augustss usbd_clear_endpoint_stall_async(sc->sc_ep[UPL_ENDPT_RX]);
755 1.1 augustss return;
756 1.1 augustss }
757 1.1 augustss
758 1.1 augustss stat = sc->sc_ibuf;
759 1.1 augustss
760 1.1 augustss if (stat == 0)
761 1.1 augustss return;
762 1.1 augustss
763 1.1 augustss DPRINTFN(10,("%s: %s: stat=0x%02x\n", USBDEVNAME(sc->sc_dev),
764 1.18 augustss __func__, stat));
765 1.1 augustss
766 1.1 augustss }
767 1.1 augustss
768 1.1 augustss Static int
769 1.27.4.3 itohy upl_ioctl(struct ifnet *ifp, u_long command, usb_ioctlarg_t data)
770 1.1 augustss {
771 1.1 augustss struct upl_softc *sc = ifp->if_softc;
772 1.27.4.2 itohy #if 0
773 1.1 augustss struct ifaddr *ifa = (struct ifaddr *)data;
774 1.1 augustss struct ifreq *ifr = (struct ifreq *)data;
775 1.27.4.2 itohy #endif
776 1.1 augustss int s, error = 0;
777 1.1 augustss
778 1.1 augustss if (sc->sc_dying)
779 1.1 augustss return (EIO);
780 1.1 augustss
781 1.1 augustss DPRINTFN(5,("%s: %s: cmd=0x%08lx\n",
782 1.18 augustss USBDEVNAME(sc->sc_dev), __func__, command));
783 1.1 augustss
784 1.14 thorpej s = splnet();
785 1.1 augustss
786 1.1 augustss switch(command) {
787 1.27.4.2 itohy #if 0
788 1.1 augustss case SIOCSIFADDR:
789 1.1 augustss ifp->if_flags |= IFF_UP;
790 1.27.4.2 itohy upl_init(ifp);
791 1.1 augustss
792 1.1 augustss switch (ifa->ifa_addr->sa_family) {
793 1.1 augustss #ifdef INET
794 1.1 augustss case AF_INET:
795 1.1 augustss break;
796 1.1 augustss #endif /* INET */
797 1.1 augustss }
798 1.1 augustss break;
799 1.1 augustss
800 1.1 augustss case SIOCSIFMTU:
801 1.1 augustss if (ifr->ifr_mtu > UPL_BUFSZ)
802 1.1 augustss error = EINVAL;
803 1.1 augustss else
804 1.1 augustss ifp->if_mtu = ifr->ifr_mtu;
805 1.1 augustss break;
806 1.1 augustss
807 1.1 augustss case SIOCSIFFLAGS:
808 1.1 augustss if (ifp->if_flags & IFF_UP) {
809 1.1 augustss if (!(ifp->if_flags & IFF_RUNNING))
810 1.27.4.2 itohy upl_init(ifp);
811 1.1 augustss } else {
812 1.1 augustss if (ifp->if_flags & IFF_RUNNING)
813 1.27.4.2 itohy upl_stop(ifp, 1);
814 1.1 augustss }
815 1.1 augustss error = 0;
816 1.1 augustss break;
817 1.27.4.2 itohy #endif
818 1.1 augustss default:
819 1.27.4.2 itohy error = ether_ioctl(ifp, command, data);
820 1.27.4.2 itohy if (error == ENETRESET) {
821 1.27.4.2 itohy /*
822 1.27.4.2 itohy * Multicast list has changed; set the hardware
823 1.27.4.2 itohy * filter accordingly.
824 1.27.4.2 itohy */
825 1.27.4.2 itohy #if 0 /* XXX not yet */
826 1.27.4.2 itohy if (ifp->if_flags & IFF_RUNNING)
827 1.27.4.2 itohy upl_setmulti(sc);
828 1.27.4.2 itohy #endif
829 1.27.4.2 itohy error = 0;
830 1.27.4.2 itohy }
831 1.1 augustss break;
832 1.1 augustss }
833 1.1 augustss
834 1.1 augustss splx(s);
835 1.1 augustss
836 1.1 augustss return (error);
837 1.1 augustss }
838 1.1 augustss
839 1.1 augustss Static void
840 1.4 augustss upl_watchdog(struct ifnet *ifp)
841 1.1 augustss {
842 1.1 augustss struct upl_softc *sc = ifp->if_softc;
843 1.1 augustss
844 1.18 augustss DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->sc_dev),__func__));
845 1.1 augustss
846 1.1 augustss if (sc->sc_dying)
847 1.1 augustss return;
848 1.1 augustss
849 1.1 augustss ifp->if_oerrors++;
850 1.1 augustss printf("%s: watchdog timeout\n", USBDEVNAME(sc->sc_dev));
851 1.1 augustss
852 1.27.4.2 itohy upl_stop(ifp, 1);
853 1.27.4.2 itohy upl_init(ifp);
854 1.1 augustss
855 1.17 itojun if (IFQ_IS_EMPTY(&ifp->if_snd) == 0)
856 1.1 augustss upl_start(ifp);
857 1.1 augustss }
858 1.1 augustss
859 1.1 augustss /*
860 1.1 augustss * Stop the adapter and free any mbufs allocated to the
861 1.1 augustss * RX and TX lists.
862 1.1 augustss */
863 1.1 augustss Static void
864 1.27.4.2 itohy upl_stop(struct ifnet *ifp, int disable)
865 1.1 augustss {
866 1.27.4.2 itohy struct upl_softc *sc = ifp->if_softc;
867 1.1 augustss usbd_status err;
868 1.1 augustss
869 1.18 augustss DPRINTFN(10,("%s: %s: enter\n", USBDEVNAME(sc->sc_dev),__func__));
870 1.1 augustss
871 1.1 augustss ifp = &sc->sc_if;
872 1.1 augustss ifp->if_timer = 0;
873 1.1 augustss
874 1.1 augustss /* Stop transfers. */
875 1.1 augustss if (sc->sc_ep[UPL_ENDPT_RX] != NULL) {
876 1.1 augustss err = usbd_abort_pipe(sc->sc_ep[UPL_ENDPT_RX]);
877 1.1 augustss if (err) {
878 1.1 augustss printf("%s: abort rx pipe failed: %s\n",
879 1.1 augustss USBDEVNAME(sc->sc_dev), usbd_errstr(err));
880 1.1 augustss }
881 1.1 augustss }
882 1.1 augustss
883 1.1 augustss if (sc->sc_ep[UPL_ENDPT_TX] != NULL) {
884 1.1 augustss err = usbd_abort_pipe(sc->sc_ep[UPL_ENDPT_TX]);
885 1.1 augustss if (err) {
886 1.1 augustss printf("%s: abort tx pipe failed: %s\n",
887 1.1 augustss USBDEVNAME(sc->sc_dev), usbd_errstr(err));
888 1.1 augustss }
889 1.1 augustss }
890 1.1 augustss
891 1.1 augustss if (sc->sc_ep[UPL_ENDPT_INTR] != NULL) {
892 1.1 augustss err = usbd_abort_pipe(sc->sc_ep[UPL_ENDPT_INTR]);
893 1.1 augustss if (err) {
894 1.1 augustss printf("%s: abort intr pipe failed: %s\n",
895 1.1 augustss USBDEVNAME(sc->sc_dev), usbd_errstr(err));
896 1.1 augustss }
897 1.27.4.2 itohy }
898 1.27.4.2 itohy
899 1.27.4.2 itohy /* Free RX/TX list resources. */
900 1.27.4.2 itohy usb_ether_rx_list_free(sc->sc_cdata.upl_rx_chain, UPL_RX_LIST_CNT);
901 1.27.4.2 itohy usb_ether_tx_list_free(sc->sc_cdata.upl_tx_chain, UPL_TX_LIST_CNT);
902 1.27.4.2 itohy
903 1.27.4.2 itohy /* Close pipes. */
904 1.27.4.2 itohy if (sc->sc_ep[UPL_ENDPT_RX] != NULL) {
905 1.27.4.2 itohy err = usbd_close_pipe(sc->sc_ep[UPL_ENDPT_RX]);
906 1.1 augustss if (err) {
907 1.27.4.2 itohy printf("%s: close rx pipe failed: %s\n",
908 1.27.4.2 itohy USBDEVNAME(sc->sc_dev), usbd_errstr(err));
909 1.1 augustss }
910 1.27.4.2 itohy sc->sc_ep[UPL_ENDPT_RX] = NULL;
911 1.1 augustss }
912 1.1 augustss
913 1.27.4.2 itohy if (sc->sc_ep[UPL_ENDPT_TX] != NULL) {
914 1.27.4.2 itohy err = usbd_close_pipe(sc->sc_ep[UPL_ENDPT_TX]);
915 1.27.4.2 itohy if (err) {
916 1.27.4.2 itohy printf("%s: close tx pipe failed: %s\n",
917 1.27.4.2 itohy USBDEVNAME(sc->sc_dev), usbd_errstr(err));
918 1.1 augustss }
919 1.27.4.2 itohy sc->sc_ep[UPL_ENDPT_TX] = NULL;
920 1.1 augustss }
921 1.1 augustss
922 1.27.4.2 itohy if (sc->sc_ep[UPL_ENDPT_INTR] != NULL) {
923 1.27.4.2 itohy err = usbd_close_pipe(sc->sc_ep[UPL_ENDPT_INTR]);
924 1.27.4.2 itohy if (err) {
925 1.27.4.2 itohy printf("%s: close intr pipe failed: %s\n",
926 1.27.4.2 itohy USBDEVNAME(sc->sc_dev), usbd_errstr(err));
927 1.1 augustss }
928 1.27.4.2 itohy sc->sc_ep[UPL_ENDPT_INTR] = NULL;
929 1.1 augustss }
930 1.1 augustss
931 1.1 augustss ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
932 1.1 augustss }
933 1.1 augustss
934 1.1 augustss Static int
935 1.27 dyoung upl_output(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *dst,
936 1.26 christos struct rtentry *rt0)
937 1.1 augustss {
938 1.17 itojun int s, len, error;
939 1.17 itojun ALTQ_DECL(struct altq_pktattr pktattr;)
940 1.1 augustss
941 1.1 augustss DPRINTFN(10,("%s: %s: enter\n",
942 1.1 augustss USBDEVNAME(((struct upl_softc *)ifp->if_softc)->sc_dev),
943 1.18 augustss __func__));
944 1.1 augustss
945 1.17 itojun /*
946 1.17 itojun * if the queueing discipline needs packet classification,
947 1.17 itojun * do it now.
948 1.17 itojun */
949 1.17 itojun IFQ_CLASSIFY(&ifp->if_snd, m, dst->sa_family, &pktattr);
950 1.17 itojun
951 1.17 itojun len = m->m_pkthdr.len;
952 1.14 thorpej s = splnet();
953 1.1 augustss /*
954 1.1 augustss * Queue message on interface, and start output if interface
955 1.1 augustss * not yet active.
956 1.1 augustss */
957 1.17 itojun IFQ_ENQUEUE(&ifp->if_snd, m, &pktattr, error);
958 1.17 itojun if (error) {
959 1.17 itojun /* mbuf is already freed */
960 1.1 augustss splx(s);
961 1.17 itojun return (error);
962 1.1 augustss }
963 1.17 itojun ifp->if_obytes += len;
964 1.1 augustss if ((ifp->if_flags & IFF_OACTIVE) == 0)
965 1.1 augustss (*ifp->if_start)(ifp);
966 1.1 augustss splx(s);
967 1.1 augustss
968 1.1 augustss return (0);
969 1.1 augustss }
970 1.1 augustss
971 1.1 augustss Static void
972 1.4 augustss upl_input(struct ifnet *ifp, struct mbuf *m)
973 1.1 augustss {
974 1.21 christos #ifdef INET
975 1.1 augustss struct ifqueue *inq;
976 1.1 augustss int s;
977 1.1 augustss
978 1.1 augustss /* XXX Assume all traffic is IP */
979 1.1 augustss
980 1.1 augustss schednetisr(NETISR_IP);
981 1.1 augustss inq = &ipintrq;
982 1.1 augustss
983 1.14 thorpej s = splnet();
984 1.1 augustss if (IF_QFULL(inq)) {
985 1.1 augustss IF_DROP(inq);
986 1.1 augustss splx(s);
987 1.7 augustss #if 0
988 1.7 augustss if (sc->sc_flags & SC_DEBUG)
989 1.7 augustss printf("%s: input queue full\n", ifp->if_xname);
990 1.7 augustss #endif
991 1.1 augustss ifp->if_iqdrops++;
992 1.1 augustss return;
993 1.1 augustss }
994 1.1 augustss IF_ENQUEUE(inq, m);
995 1.1 augustss splx(s);
996 1.21 christos #endif
997 1.1 augustss ifp->if_ipackets++;
998 1.1 augustss ifp->if_ibytes += m->m_len;
999 1.1 augustss }
1000