if_cue.c revision 1.26.2.3 1 1.26.2.3 bouyer /* $NetBSD: if_cue.c,v 1.26.2.3 2000/11/22 16:05:02 bouyer Exp $ */
2 1.26.2.2 bouyer /*
3 1.26.2.2 bouyer * Copyright (c) 1997, 1998, 1999, 2000
4 1.26.2.2 bouyer * Bill Paul <wpaul (at) ee.columbia.edu>. All rights reserved.
5 1.26.2.2 bouyer *
6 1.26.2.2 bouyer * Redistribution and use in source and binary forms, with or without
7 1.26.2.2 bouyer * modification, are permitted provided that the following conditions
8 1.26.2.2 bouyer * are met:
9 1.26.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
10 1.26.2.2 bouyer * notice, this list of conditions and the following disclaimer.
11 1.26.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
12 1.26.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
13 1.26.2.2 bouyer * documentation and/or other materials provided with the distribution.
14 1.26.2.2 bouyer * 3. All advertising materials mentioning features or use of this software
15 1.26.2.2 bouyer * must display the following acknowledgement:
16 1.26.2.2 bouyer * This product includes software developed by Bill Paul.
17 1.26.2.2 bouyer * 4. Neither the name of the author nor the names of any co-contributors
18 1.26.2.2 bouyer * may be used to endorse or promote products derived from this software
19 1.26.2.2 bouyer * without specific prior written permission.
20 1.26.2.2 bouyer *
21 1.26.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
22 1.26.2.2 bouyer * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 1.26.2.2 bouyer * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 1.26.2.2 bouyer * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
25 1.26.2.2 bouyer * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 1.26.2.2 bouyer * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 1.26.2.2 bouyer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 1.26.2.2 bouyer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 1.26.2.2 bouyer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 1.26.2.2 bouyer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 1.26.2.2 bouyer * THE POSSIBILITY OF SUCH DAMAGE.
32 1.26.2.2 bouyer *
33 1.26.2.2 bouyer * $FreeBSD: src/sys/dev/usb/if_cue.c,v 1.4 2000/01/16 22:45:06 wpaul Exp $
34 1.26.2.2 bouyer */
35 1.26.2.2 bouyer
36 1.26.2.2 bouyer /*
37 1.26.2.2 bouyer * CATC USB-EL1210A USB to ethernet driver. Used in the CATC Netmate
38 1.26.2.2 bouyer * adapters and others.
39 1.26.2.2 bouyer *
40 1.26.2.2 bouyer * Written by Bill Paul <wpaul (at) ee.columbia.edu>
41 1.26.2.2 bouyer * Electrical Engineering Department
42 1.26.2.2 bouyer * Columbia University, New York City
43 1.26.2.2 bouyer */
44 1.26.2.2 bouyer
45 1.26.2.2 bouyer /*
46 1.26.2.2 bouyer * The CATC USB-EL1210A provides USB ethernet support at 10Mbps. The
47 1.26.2.2 bouyer * RX filter uses a 512-bit multicast hash table, single perfect entry
48 1.26.2.2 bouyer * for the station address, and promiscuous mode. Unlike the ADMtek
49 1.26.2.2 bouyer * and KLSI chips, the CATC ASIC supports read and write combining
50 1.26.2.2 bouyer * mode where multiple packets can be transfered using a single bulk
51 1.26.2.2 bouyer * transaction, which helps performance a great deal.
52 1.26.2.2 bouyer */
53 1.26.2.2 bouyer
54 1.26.2.2 bouyer /*
55 1.26.2.2 bouyer * Ported to NetBSD and somewhat rewritten by Lennart Augustsson.
56 1.26.2.2 bouyer */
57 1.26.2.2 bouyer
58 1.26.2.2 bouyer /*
59 1.26.2.2 bouyer * TODO:
60 1.26.2.2 bouyer * proper cleanup on errors
61 1.26.2.2 bouyer */
62 1.26.2.2 bouyer #if defined(__NetBSD__)
63 1.26.2.2 bouyer #include "opt_inet.h"
64 1.26.2.2 bouyer #include "opt_ns.h"
65 1.26.2.2 bouyer #include "bpfilter.h"
66 1.26.2.2 bouyer #include "rnd.h"
67 1.26.2.2 bouyer #elif defined(__OpenBSD__)
68 1.26.2.2 bouyer #include "bpfilter.h"
69 1.26.2.2 bouyer #endif /* defined(__OpenBSD__) */
70 1.26.2.2 bouyer
71 1.26.2.2 bouyer #include <sys/param.h>
72 1.26.2.2 bouyer #include <sys/systm.h>
73 1.26.2.2 bouyer #if !defined(__OpenBSD__)
74 1.26.2.2 bouyer #include <sys/callout.h>
75 1.26.2.2 bouyer #endif
76 1.26.2.2 bouyer #include <sys/sockio.h>
77 1.26.2.2 bouyer #include <sys/mbuf.h>
78 1.26.2.2 bouyer #include <sys/malloc.h>
79 1.26.2.2 bouyer #include <sys/kernel.h>
80 1.26.2.2 bouyer #include <sys/socket.h>
81 1.26.2.2 bouyer
82 1.26.2.2 bouyer #if defined(__FreeBSD__)
83 1.26.2.2 bouyer
84 1.26.2.2 bouyer #include <net/ethernet.h>
85 1.26.2.2 bouyer #include <machine/clock.h> /* for DELAY */
86 1.26.2.2 bouyer #include <sys/bus.h>
87 1.26.2.2 bouyer
88 1.26.2.2 bouyer #elif defined(__NetBSD__) || defined(__OpenBSD__)
89 1.26.2.2 bouyer
90 1.26.2.2 bouyer #include <sys/device.h>
91 1.26.2.2 bouyer #if NRND > 0
92 1.26.2.2 bouyer #include <sys/rnd.h>
93 1.26.2.2 bouyer #endif
94 1.26.2.2 bouyer
95 1.26.2.2 bouyer #endif
96 1.26.2.2 bouyer
97 1.26.2.2 bouyer #include <net/if.h>
98 1.26.2.2 bouyer #if defined(__NetBSD__) || defined(__FreeBSD__)
99 1.26.2.2 bouyer #include <net/if_arp.h>
100 1.26.2.2 bouyer #endif
101 1.26.2.2 bouyer #include <net/if_dl.h>
102 1.26.2.2 bouyer
103 1.26.2.2 bouyer #if defined(__NetBSD__) || defined(__OpenBSD__)
104 1.26.2.2 bouyer #define BPF_MTAP(ifp, m) bpf_mtap((ifp)->if_bpf, (m))
105 1.26.2.2 bouyer #else
106 1.26.2.2 bouyer #define BPF_MTAP(ifp, m) bpf_mtap((ifp), (m))
107 1.26.2.2 bouyer #endif
108 1.26.2.2 bouyer
109 1.26.2.2 bouyer #if defined(__FreeBSD__) || NBPFILTER > 0
110 1.26.2.2 bouyer #include <net/bpf.h>
111 1.26.2.2 bouyer #endif
112 1.26.2.2 bouyer
113 1.26.2.2 bouyer #if defined(__NetBSD__)
114 1.26.2.2 bouyer #include <net/if_ether.h>
115 1.26.2.2 bouyer #ifdef INET
116 1.26.2.2 bouyer #include <netinet/in.h>
117 1.26.2.2 bouyer #include <netinet/if_inarp.h>
118 1.26.2.2 bouyer #endif
119 1.26.2.2 bouyer #endif /* defined(__NetBSD__) */
120 1.26.2.2 bouyer
121 1.26.2.2 bouyer #if defined(__OpenBSD__)
122 1.26.2.2 bouyer #ifdef INET
123 1.26.2.2 bouyer #include <netinet/in.h>
124 1.26.2.2 bouyer #include <netinet/in_systm.h>
125 1.26.2.2 bouyer #include <netinet/in_var.h>
126 1.26.2.2 bouyer #include <netinet/ip.h>
127 1.26.2.2 bouyer #include <netinet/if_ether.h>
128 1.26.2.2 bouyer #endif
129 1.26.2.2 bouyer #endif /* defined(__OpenBSD__) */
130 1.26.2.2 bouyer
131 1.26.2.2 bouyer #if defined(__NetBSD__) || defined(__OpenBSD__)
132 1.26.2.2 bouyer #ifdef NS
133 1.26.2.2 bouyer #include <netns/ns.h>
134 1.26.2.2 bouyer #include <netns/ns_if.h>
135 1.26.2.2 bouyer #endif
136 1.26.2.2 bouyer #endif /* defined(__NetBSD__) || defined(__OpenBSD__) */
137 1.26.2.2 bouyer
138 1.26.2.2 bouyer #include <dev/usb/usb.h>
139 1.26.2.2 bouyer #include <dev/usb/usbdi.h>
140 1.26.2.2 bouyer #include <dev/usb/usbdi_util.h>
141 1.26.2.2 bouyer #include <dev/usb/usbdevs.h>
142 1.26.2.2 bouyer
143 1.26.2.2 bouyer #ifdef __FreeBSD__
144 1.26.2.2 bouyer #include <dev/usb/usb_ethersubr.h>
145 1.26.2.2 bouyer #endif
146 1.26.2.2 bouyer
147 1.26.2.2 bouyer #include <dev/usb/if_cuereg.h>
148 1.26.2.2 bouyer
149 1.26.2.2 bouyer #ifdef CUE_DEBUG
150 1.26.2.2 bouyer #define DPRINTF(x) if (cuedebug) logprintf x
151 1.26.2.2 bouyer #define DPRINTFN(n,x) if (cuedebug >= (n)) logprintf x
152 1.26.2.2 bouyer int cuedebug = 0;
153 1.26.2.2 bouyer #else
154 1.26.2.2 bouyer #define DPRINTF(x)
155 1.26.2.2 bouyer #define DPRINTFN(n,x)
156 1.26.2.2 bouyer #endif
157 1.26.2.2 bouyer
158 1.26.2.2 bouyer /*
159 1.26.2.2 bouyer * Various supported device vendors/products.
160 1.26.2.2 bouyer */
161 1.26.2.2 bouyer Static struct cue_type cue_devs[] = {
162 1.26.2.2 bouyer { USB_VENDOR_CATC, USB_PRODUCT_CATC_NETMATE },
163 1.26.2.2 bouyer { USB_VENDOR_CATC, USB_PRODUCT_CATC_NETMATE2 },
164 1.26.2.2 bouyer { USB_VENDOR_SMARTBRIDGES, USB_PRODUCT_SMARTBRIDGES_SMARTLINK },
165 1.26.2.2 bouyer /* Belkin F5U111 adapter covered by NETMATE entry */
166 1.26.2.2 bouyer { 0, 0 }
167 1.26.2.2 bouyer };
168 1.26.2.2 bouyer
169 1.26.2.2 bouyer USB_DECLARE_DRIVER(cue);
170 1.26.2.2 bouyer
171 1.26.2.2 bouyer Static int cue_open_pipes(struct cue_softc *);
172 1.26.2.2 bouyer Static int cue_tx_list_init(struct cue_softc *);
173 1.26.2.2 bouyer Static int cue_rx_list_init(struct cue_softc *);
174 1.26.2.2 bouyer Static int cue_newbuf(struct cue_softc *, struct cue_chain *, struct mbuf *);
175 1.26.2.2 bouyer Static int cue_send(struct cue_softc *, struct mbuf *, int);
176 1.26.2.2 bouyer Static void cue_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
177 1.26.2.2 bouyer Static void cue_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
178 1.26.2.2 bouyer Static void cue_tick(void *);
179 1.26.2.2 bouyer Static void cue_start(struct ifnet *);
180 1.26.2.2 bouyer Static int cue_ioctl(struct ifnet *, u_long, caddr_t);
181 1.26.2.2 bouyer Static void cue_init(void *);
182 1.26.2.2 bouyer Static void cue_stop(struct cue_softc *);
183 1.26.2.2 bouyer Static void cue_watchdog(struct ifnet *);
184 1.26.2.2 bouyer
185 1.26.2.2 bouyer Static void cue_setmulti(struct cue_softc *);
186 1.26.2.2 bouyer Static u_int32_t cue_crc(caddr_t);
187 1.26.2.2 bouyer Static void cue_reset(struct cue_softc *);
188 1.26.2.2 bouyer
189 1.26.2.2 bouyer Static int cue_csr_read_1(struct cue_softc *, int);
190 1.26.2.2 bouyer Static int cue_csr_write_1(struct cue_softc *, int, int);
191 1.26.2.2 bouyer Static int cue_csr_read_2(struct cue_softc *, int);
192 1.26.2.2 bouyer #if 0
193 1.26.2.2 bouyer Static int cue_csr_write_2(struct cue_softc *, int, int);
194 1.26.2.2 bouyer #endif
195 1.26.2.2 bouyer Static int cue_mem(struct cue_softc *, int, int, void *, int);
196 1.26.2.2 bouyer Static int cue_getmac(struct cue_softc *, void *);
197 1.26.2.2 bouyer
198 1.26.2.2 bouyer #ifdef __FreeBSD__
199 1.26.2.2 bouyer #ifndef lint
200 1.26.2.2 bouyer static const char rcsid[] =
201 1.26.2.2 bouyer "$FreeBSD: src/sys/dev/usb/if_cue.c,v 1.4 2000/01/16 22:45:06 wpaul Exp $";
202 1.26.2.2 bouyer #endif
203 1.26.2.2 bouyer
204 1.26.2.2 bouyer Static void cue_rxstart(struct ifnet *);
205 1.26.2.2 bouyer Static void cue_shutdown(device_t);
206 1.26.2.2 bouyer
207 1.26.2.2 bouyer Static struct usb_qdat cue_qdat;
208 1.26.2.2 bouyer
209 1.26.2.2 bouyer Static device_method_t cue_methods[] = {
210 1.26.2.2 bouyer /* Device interface */
211 1.26.2.2 bouyer DEVMETHOD(device_probe, cue_match),
212 1.26.2.2 bouyer DEVMETHOD(device_attach, cue_attach),
213 1.26.2.2 bouyer DEVMETHOD(device_detach, cue_detach),
214 1.26.2.2 bouyer DEVMETHOD(device_shutdown, cue_shutdown),
215 1.26.2.2 bouyer
216 1.26.2.2 bouyer { 0, 0 }
217 1.26.2.2 bouyer };
218 1.26.2.2 bouyer
219 1.26.2.2 bouyer Static driver_t cue_driver = {
220 1.26.2.2 bouyer "cue",
221 1.26.2.2 bouyer cue_methods,
222 1.26.2.2 bouyer sizeof(struct cue_softc)
223 1.26.2.2 bouyer };
224 1.26.2.2 bouyer
225 1.26.2.2 bouyer Static devclass_t cue_devclass;
226 1.26.2.2 bouyer
227 1.26.2.2 bouyer DRIVER_MODULE(if_cue, uhub, cue_driver, cue_devclass, usbd_driver_load, 0);
228 1.26.2.2 bouyer
229 1.26.2.2 bouyer #endif /* defined(__FreeBSD__) */
230 1.26.2.2 bouyer
231 1.26.2.2 bouyer #define CUE_DO_REQUEST(dev, req, data) \
232 1.26.2.2 bouyer usbd_do_request_flags(dev, req, data, USBD_NO_TSLEEP, NULL)
233 1.26.2.2 bouyer
234 1.26.2.2 bouyer #define CUE_SETBIT(sc, reg, x) \
235 1.26.2.2 bouyer cue_csr_write_1(sc, reg, cue_csr_read_1(sc, reg) | (x))
236 1.26.2.2 bouyer
237 1.26.2.2 bouyer #define CUE_CLRBIT(sc, reg, x) \
238 1.26.2.2 bouyer cue_csr_write_1(sc, reg, cue_csr_read_1(sc, reg) & ~(x))
239 1.26.2.2 bouyer
240 1.26.2.2 bouyer Static int
241 1.26.2.2 bouyer cue_csr_read_1(struct cue_softc *sc, int reg)
242 1.26.2.2 bouyer {
243 1.26.2.2 bouyer usb_device_request_t req;
244 1.26.2.2 bouyer usbd_status err;
245 1.26.2.2 bouyer u_int8_t val = 0;
246 1.26.2.2 bouyer int s;
247 1.26.2.2 bouyer
248 1.26.2.2 bouyer if (sc->cue_dying)
249 1.26.2.2 bouyer return (0);
250 1.26.2.2 bouyer
251 1.26.2.2 bouyer req.bmRequestType = UT_READ_VENDOR_DEVICE;
252 1.26.2.2 bouyer req.bRequest = CUE_CMD_READREG;
253 1.26.2.2 bouyer USETW(req.wValue, 0);
254 1.26.2.2 bouyer USETW(req.wIndex, reg);
255 1.26.2.2 bouyer USETW(req.wLength, 1);
256 1.26.2.2 bouyer
257 1.26.2.2 bouyer s = splusb();
258 1.26.2.2 bouyer err = CUE_DO_REQUEST(sc->cue_udev, &req, &val);
259 1.26.2.2 bouyer splx(s);
260 1.26.2.2 bouyer
261 1.26.2.2 bouyer if (err) {
262 1.26.2.2 bouyer DPRINTF(("%s: cue_csr_read_1: reg=0x%x err=%s\n",
263 1.26.2.2 bouyer USBDEVNAME(sc->cue_dev), reg, usbd_errstr(err)));
264 1.26.2.2 bouyer return (0);
265 1.26.2.2 bouyer }
266 1.26.2.2 bouyer
267 1.26.2.2 bouyer DPRINTFN(10,("%s: cue_csr_read_1 reg=0x%x val=0x%x\n",
268 1.26.2.2 bouyer USBDEVNAME(sc->cue_dev), reg, val));
269 1.26.2.2 bouyer
270 1.26.2.2 bouyer return (val);
271 1.26.2.2 bouyer }
272 1.26.2.2 bouyer
273 1.26.2.2 bouyer Static int
274 1.26.2.2 bouyer cue_csr_read_2(struct cue_softc *sc, int reg)
275 1.26.2.2 bouyer {
276 1.26.2.2 bouyer usb_device_request_t req;
277 1.26.2.2 bouyer usbd_status err;
278 1.26.2.2 bouyer uWord val;
279 1.26.2.2 bouyer int s;
280 1.26.2.2 bouyer
281 1.26.2.2 bouyer if (sc->cue_dying)
282 1.26.2.2 bouyer return (0);
283 1.26.2.2 bouyer
284 1.26.2.2 bouyer req.bmRequestType = UT_READ_VENDOR_DEVICE;
285 1.26.2.2 bouyer req.bRequest = CUE_CMD_READREG;
286 1.26.2.2 bouyer USETW(req.wValue, 0);
287 1.26.2.2 bouyer USETW(req.wIndex, reg);
288 1.26.2.2 bouyer USETW(req.wLength, 2);
289 1.26.2.2 bouyer
290 1.26.2.2 bouyer s = splusb();
291 1.26.2.2 bouyer err = CUE_DO_REQUEST(sc->cue_udev, &req, &val);
292 1.26.2.2 bouyer splx(s);
293 1.26.2.2 bouyer
294 1.26.2.2 bouyer DPRINTFN(10,("%s: cue_csr_read_2 reg=0x%x val=0x%x\n",
295 1.26.2.2 bouyer USBDEVNAME(sc->cue_dev), reg, UGETW(val)));
296 1.26.2.2 bouyer
297 1.26.2.2 bouyer if (err) {
298 1.26.2.2 bouyer DPRINTF(("%s: cue_csr_read_2: reg=0x%x err=%s\n",
299 1.26.2.2 bouyer USBDEVNAME(sc->cue_dev), reg, usbd_errstr(err)));
300 1.26.2.2 bouyer return (0);
301 1.26.2.2 bouyer }
302 1.26.2.2 bouyer
303 1.26.2.2 bouyer return (UGETW(val));
304 1.26.2.2 bouyer }
305 1.26.2.2 bouyer
306 1.26.2.2 bouyer Static int
307 1.26.2.2 bouyer cue_csr_write_1(struct cue_softc *sc, int reg, int val)
308 1.26.2.2 bouyer {
309 1.26.2.2 bouyer usb_device_request_t req;
310 1.26.2.2 bouyer usbd_status err;
311 1.26.2.2 bouyer int s;
312 1.26.2.2 bouyer
313 1.26.2.2 bouyer if (sc->cue_dying)
314 1.26.2.2 bouyer return (0);
315 1.26.2.2 bouyer
316 1.26.2.2 bouyer DPRINTFN(10,("%s: cue_csr_write_1 reg=0x%x val=0x%x\n",
317 1.26.2.2 bouyer USBDEVNAME(sc->cue_dev), reg, val));
318 1.26.2.2 bouyer
319 1.26.2.2 bouyer req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
320 1.26.2.2 bouyer req.bRequest = CUE_CMD_WRITEREG;
321 1.26.2.2 bouyer USETW(req.wValue, val);
322 1.26.2.2 bouyer USETW(req.wIndex, reg);
323 1.26.2.2 bouyer USETW(req.wLength, 0);
324 1.26.2.2 bouyer
325 1.26.2.2 bouyer s = splusb();
326 1.26.2.2 bouyer err = CUE_DO_REQUEST(sc->cue_udev, &req, NULL);
327 1.26.2.2 bouyer splx(s);
328 1.26.2.2 bouyer
329 1.26.2.2 bouyer if (err) {
330 1.26.2.2 bouyer DPRINTF(("%s: cue_csr_write_1: reg=0x%x err=%s\n",
331 1.26.2.2 bouyer USBDEVNAME(sc->cue_dev), reg, usbd_errstr(err)));
332 1.26.2.2 bouyer return (-1);
333 1.26.2.2 bouyer }
334 1.26.2.2 bouyer
335 1.26.2.2 bouyer DPRINTFN(20,("%s: cue_csr_write_1, after reg=0x%x val=0x%x\n",
336 1.26.2.2 bouyer USBDEVNAME(sc->cue_dev), reg, cue_csr_read_1(sc, reg)));
337 1.26.2.2 bouyer
338 1.26.2.2 bouyer return (0);
339 1.26.2.2 bouyer }
340 1.26.2.2 bouyer
341 1.26.2.2 bouyer #if 0
342 1.26.2.2 bouyer Static int
343 1.26.2.2 bouyer cue_csr_write_2(struct cue_softc *sc, int reg, int aval)
344 1.26.2.2 bouyer {
345 1.26.2.2 bouyer usb_device_request_t req;
346 1.26.2.2 bouyer usbd_status err;
347 1.26.2.2 bouyer uWord val;
348 1.26.2.2 bouyer int s;
349 1.26.2.2 bouyer
350 1.26.2.2 bouyer if (sc->cue_dying)
351 1.26.2.2 bouyer return (0);
352 1.26.2.2 bouyer
353 1.26.2.2 bouyer DPRINTFN(10,("%s: cue_csr_write_2 reg=0x%x val=0x%x\n",
354 1.26.2.2 bouyer USBDEVNAME(sc->cue_dev), reg, aval));
355 1.26.2.2 bouyer
356 1.26.2.2 bouyer USETW(val, aval);
357 1.26.2.2 bouyer req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
358 1.26.2.2 bouyer req.bRequest = CUE_CMD_WRITEREG;
359 1.26.2.2 bouyer USETW(req.wValue, val);
360 1.26.2.2 bouyer USETW(req.wIndex, reg);
361 1.26.2.2 bouyer USETW(req.wLength, 0);
362 1.26.2.2 bouyer
363 1.26.2.2 bouyer s = splusb();
364 1.26.2.2 bouyer err = CUE_DO_REQUEST(sc->cue_udev, &req, NULL);
365 1.26.2.2 bouyer splx(s);
366 1.26.2.2 bouyer
367 1.26.2.2 bouyer if (err) {
368 1.26.2.2 bouyer DPRINTF(("%s: cue_csr_write_2: reg=0x%x err=%s\n",
369 1.26.2.2 bouyer USBDEVNAME(sc->cue_dev), reg, usbd_errstr(err)));
370 1.26.2.2 bouyer return (-1);
371 1.26.2.2 bouyer }
372 1.26.2.2 bouyer
373 1.26.2.2 bouyer return (0);
374 1.26.2.2 bouyer }
375 1.26.2.2 bouyer #endif
376 1.26.2.2 bouyer
377 1.26.2.2 bouyer Static int
378 1.26.2.2 bouyer cue_mem(struct cue_softc *sc, int cmd, int addr, void *buf, int len)
379 1.26.2.2 bouyer {
380 1.26.2.2 bouyer usb_device_request_t req;
381 1.26.2.2 bouyer usbd_status err;
382 1.26.2.2 bouyer int s;
383 1.26.2.2 bouyer
384 1.26.2.2 bouyer DPRINTFN(10,("%s: cue_mem cmd=0x%x addr=0x%x len=%d\n",
385 1.26.2.2 bouyer USBDEVNAME(sc->cue_dev), cmd, addr, len));
386 1.26.2.2 bouyer
387 1.26.2.2 bouyer if (cmd == CUE_CMD_READSRAM)
388 1.26.2.2 bouyer req.bmRequestType = UT_READ_VENDOR_DEVICE;
389 1.26.2.2 bouyer else
390 1.26.2.2 bouyer req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
391 1.26.2.2 bouyer req.bRequest = cmd;
392 1.26.2.2 bouyer USETW(req.wValue, 0);
393 1.26.2.2 bouyer USETW(req.wIndex, addr);
394 1.26.2.2 bouyer USETW(req.wLength, len);
395 1.26.2.2 bouyer
396 1.26.2.2 bouyer s = splusb();
397 1.26.2.2 bouyer err = CUE_DO_REQUEST(sc->cue_udev, &req, buf);
398 1.26.2.2 bouyer splx(s);
399 1.26.2.2 bouyer
400 1.26.2.2 bouyer if (err) {
401 1.26.2.2 bouyer DPRINTF(("%s: cue_csr_mem: addr=0x%x err=%s\n",
402 1.26.2.2 bouyer USBDEVNAME(sc->cue_dev), addr, usbd_errstr(err)));
403 1.26.2.2 bouyer return (-1);
404 1.26.2.2 bouyer }
405 1.26.2.2 bouyer
406 1.26.2.2 bouyer return (0);
407 1.26.2.2 bouyer }
408 1.26.2.2 bouyer
409 1.26.2.2 bouyer Static int
410 1.26.2.2 bouyer cue_getmac(struct cue_softc *sc, void *buf)
411 1.26.2.2 bouyer {
412 1.26.2.2 bouyer usb_device_request_t req;
413 1.26.2.2 bouyer usbd_status err;
414 1.26.2.2 bouyer int s;
415 1.26.2.2 bouyer
416 1.26.2.2 bouyer DPRINTFN(10,("%s: cue_getmac\n", USBDEVNAME(sc->cue_dev)));
417 1.26.2.2 bouyer
418 1.26.2.2 bouyer req.bmRequestType = UT_READ_VENDOR_DEVICE;
419 1.26.2.2 bouyer req.bRequest = CUE_CMD_GET_MACADDR;
420 1.26.2.2 bouyer USETW(req.wValue, 0);
421 1.26.2.2 bouyer USETW(req.wIndex, 0);
422 1.26.2.2 bouyer USETW(req.wLength, ETHER_ADDR_LEN);
423 1.26.2.2 bouyer
424 1.26.2.2 bouyer s = splusb();
425 1.26.2.2 bouyer err = CUE_DO_REQUEST(sc->cue_udev, &req, buf);
426 1.26.2.2 bouyer splx(s);
427 1.26.2.2 bouyer
428 1.26.2.2 bouyer if (err) {
429 1.26.2.2 bouyer printf("%s: read MAC address failed\n", USBDEVNAME(sc->cue_dev));
430 1.26.2.2 bouyer return (-1);
431 1.26.2.2 bouyer }
432 1.26.2.2 bouyer
433 1.26.2.2 bouyer return (0);
434 1.26.2.2 bouyer }
435 1.26.2.2 bouyer
436 1.26.2.2 bouyer #define CUE_POLY 0xEDB88320
437 1.26.2.2 bouyer #define CUE_BITS 9
438 1.26.2.2 bouyer
439 1.26.2.2 bouyer Static u_int32_t
440 1.26.2.2 bouyer cue_crc(caddr_t addr)
441 1.26.2.2 bouyer {
442 1.26.2.2 bouyer u_int32_t idx, bit, data, crc;
443 1.26.2.2 bouyer
444 1.26.2.2 bouyer /* Compute CRC for the address value. */
445 1.26.2.2 bouyer crc = 0xFFFFFFFF; /* initial value */
446 1.26.2.2 bouyer
447 1.26.2.2 bouyer for (idx = 0; idx < 6; idx++) {
448 1.26.2.2 bouyer for (data = *addr++, bit = 0; bit < 8; bit++, data >>= 1)
449 1.26.2.2 bouyer crc = (crc >> 1) ^ (((crc ^ data) & 1) ? CUE_POLY : 0);
450 1.26.2.2 bouyer }
451 1.26.2.2 bouyer
452 1.26.2.2 bouyer return (crc & ((1 << CUE_BITS) - 1));
453 1.26.2.2 bouyer }
454 1.26.2.2 bouyer
455 1.26.2.2 bouyer Static void
456 1.26.2.2 bouyer cue_setmulti(struct cue_softc *sc)
457 1.26.2.2 bouyer {
458 1.26.2.2 bouyer struct ifnet *ifp;
459 1.26.2.2 bouyer #if defined(__FreeBSD__)
460 1.26.2.2 bouyer struct ifmultiaddr *ifma;
461 1.26.2.2 bouyer #elif defined(__NetBSD__) || defined(__OpenBSD__)
462 1.26.2.2 bouyer struct ether_multi *enm;
463 1.26.2.2 bouyer struct ether_multistep step;
464 1.26.2.2 bouyer #endif /* defined(__NetBSD__) || defined(__OpenBSD__) */
465 1.26.2.2 bouyer u_int32_t h, i;
466 1.26.2.2 bouyer
467 1.26.2.2 bouyer ifp = GET_IFP(sc);
468 1.26.2.2 bouyer
469 1.26.2.2 bouyer DPRINTFN(2,("%s: cue_setmulti if_flags=0x%x\n",
470 1.26.2.2 bouyer USBDEVNAME(sc->cue_dev), ifp->if_flags));
471 1.26.2.2 bouyer
472 1.26.2.2 bouyer if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
473 1.26.2.2 bouyer for (i = 0; i < CUE_MCAST_TABLE_LEN; i++)
474 1.26.2.2 bouyer sc->cue_mctab[i] = 0xFF;
475 1.26.2.2 bouyer cue_mem(sc, CUE_CMD_WRITESRAM, CUE_MCAST_TABLE_ADDR,
476 1.26.2.2 bouyer &sc->cue_mctab, CUE_MCAST_TABLE_LEN);
477 1.26.2.2 bouyer return;
478 1.26.2.2 bouyer }
479 1.26.2.2 bouyer
480 1.26.2.2 bouyer /* first, zot all the existing hash bits */
481 1.26.2.2 bouyer for (i = 0; i < CUE_MCAST_TABLE_LEN; i++)
482 1.26.2.2 bouyer sc->cue_mctab[i] = 0;
483 1.26.2.2 bouyer
484 1.26.2.2 bouyer /* now program new ones */
485 1.26.2.2 bouyer #if defined(__FreeBSD__)
486 1.26.2.2 bouyer for (ifma = ifp->if_multiaddrs.lh_first; ifma != NULL;
487 1.26.2.2 bouyer ifma = ifma->ifma_link.le_next) {
488 1.26.2.2 bouyer if (ifma->ifma_addr->sa_family != AF_LINK)
489 1.26.2.2 bouyer continue;
490 1.26.2.2 bouyer h = cue_crc(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
491 1.26.2.2 bouyer sc->cue_mctab[h >> 3] |= 1 << (h & 0x7);
492 1.26.2.2 bouyer }
493 1.26.2.2 bouyer #elif defined(__NetBSD__) || defined(__OpenBSD__)
494 1.26.2.2 bouyer #if defined(__NetBSD__)
495 1.26.2.2 bouyer ETHER_FIRST_MULTI(step, &sc->cue_ec, enm);
496 1.26.2.2 bouyer #else
497 1.26.2.2 bouyer ETHER_FIRST_MULTI(step, &sc->arpcom, enm);
498 1.26.2.2 bouyer #endif
499 1.26.2.2 bouyer while (enm != NULL) {
500 1.26.2.2 bouyer #if 0
501 1.26.2.2 bouyer if (memcmp(enm->enm_addrlo,
502 1.26.2.2 bouyer enm->enm_addrhi, ETHER_ADDR_LEN) != 0) {
503 1.26.2.2 bouyer ifp->if_flags |= IFF_ALLMULTI;
504 1.26.2.2 bouyer /* XXX what now? */
505 1.26.2.2 bouyer return;
506 1.26.2.2 bouyer }
507 1.26.2.2 bouyer #endif
508 1.26.2.2 bouyer h = cue_crc(enm->enm_addrlo);
509 1.26.2.2 bouyer sc->cue_mctab[h >> 3] |= 1 << (h & 0x7);
510 1.26.2.2 bouyer ETHER_NEXT_MULTI(step, enm);
511 1.26.2.2 bouyer }
512 1.26.2.2 bouyer #endif /* defined(__NetBSD__) || defined(__OpenBSD__) */
513 1.26.2.2 bouyer
514 1.26.2.2 bouyer /*
515 1.26.2.2 bouyer * Also include the broadcast address in the filter
516 1.26.2.2 bouyer * so we can receive broadcast frames.
517 1.26.2.2 bouyer */
518 1.26.2.2 bouyer if (ifp->if_flags & IFF_BROADCAST) {
519 1.26.2.2 bouyer h = cue_crc(etherbroadcastaddr);
520 1.26.2.2 bouyer sc->cue_mctab[h >> 3] |= 1 << (h & 0x7);
521 1.26.2.2 bouyer }
522 1.26.2.2 bouyer
523 1.26.2.2 bouyer cue_mem(sc, CUE_CMD_WRITESRAM, CUE_MCAST_TABLE_ADDR,
524 1.26.2.2 bouyer &sc->cue_mctab, CUE_MCAST_TABLE_LEN);
525 1.26.2.2 bouyer }
526 1.26.2.2 bouyer
527 1.26.2.2 bouyer Static void
528 1.26.2.2 bouyer cue_reset(struct cue_softc *sc)
529 1.26.2.2 bouyer {
530 1.26.2.2 bouyer usb_device_request_t req;
531 1.26.2.2 bouyer usbd_status err;
532 1.26.2.2 bouyer int s;
533 1.26.2.2 bouyer
534 1.26.2.2 bouyer DPRINTFN(2,("%s: cue_reset\n", USBDEVNAME(sc->cue_dev)));
535 1.26.2.2 bouyer
536 1.26.2.2 bouyer if (sc->cue_dying)
537 1.26.2.2 bouyer return;
538 1.26.2.2 bouyer
539 1.26.2.2 bouyer req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
540 1.26.2.2 bouyer req.bRequest = CUE_CMD_RESET;
541 1.26.2.2 bouyer USETW(req.wValue, 0);
542 1.26.2.2 bouyer USETW(req.wIndex, 0);
543 1.26.2.2 bouyer USETW(req.wLength, 0);
544 1.26.2.2 bouyer
545 1.26.2.2 bouyer s = splusb();
546 1.26.2.2 bouyer err = CUE_DO_REQUEST(sc->cue_udev, &req, NULL);
547 1.26.2.2 bouyer splx(s);
548 1.26.2.2 bouyer
549 1.26.2.2 bouyer if (err)
550 1.26.2.2 bouyer printf("%s: reset failed\n", USBDEVNAME(sc->cue_dev));
551 1.26.2.2 bouyer
552 1.26.2.2 bouyer /* Wait a little while for the chip to get its brains in order. */
553 1.26.2.2 bouyer delay(1000); /* XXX */
554 1.26.2.2 bouyer }
555 1.26.2.2 bouyer
556 1.26.2.2 bouyer /*
557 1.26.2.2 bouyer * Probe for a CATC chip.
558 1.26.2.2 bouyer */
559 1.26.2.2 bouyer USB_MATCH(cue)
560 1.26.2.2 bouyer {
561 1.26.2.2 bouyer USB_MATCH_START(cue, uaa);
562 1.26.2.2 bouyer struct cue_type *t;
563 1.26.2.2 bouyer
564 1.26.2.2 bouyer if (uaa->iface != NULL)
565 1.26.2.2 bouyer return (UMATCH_NONE);
566 1.26.2.2 bouyer
567 1.26.2.2 bouyer for (t = cue_devs; t->cue_vid != 0; t++)
568 1.26.2.2 bouyer if (uaa->vendor == t->cue_vid && uaa->product == t->cue_did)
569 1.26.2.2 bouyer return (UMATCH_VENDOR_PRODUCT);
570 1.26.2.2 bouyer
571 1.26.2.2 bouyer return (UMATCH_NONE);
572 1.26.2.2 bouyer }
573 1.26.2.2 bouyer
574 1.26.2.2 bouyer /*
575 1.26.2.2 bouyer * Attach the interface. Allocate softc structures, do ifmedia
576 1.26.2.2 bouyer * setup and ethernet/BPF attach.
577 1.26.2.2 bouyer */
578 1.26.2.2 bouyer USB_ATTACH(cue)
579 1.26.2.2 bouyer {
580 1.26.2.2 bouyer USB_ATTACH_START(cue, sc, uaa);
581 1.26.2.2 bouyer char devinfo[1024];
582 1.26.2.2 bouyer int s;
583 1.26.2.2 bouyer u_char eaddr[ETHER_ADDR_LEN];
584 1.26.2.2 bouyer usbd_device_handle dev = uaa->device;
585 1.26.2.2 bouyer usbd_interface_handle iface;
586 1.26.2.2 bouyer usbd_status err;
587 1.26.2.2 bouyer struct ifnet *ifp;
588 1.26.2.2 bouyer usb_interface_descriptor_t *id;
589 1.26.2.2 bouyer usb_endpoint_descriptor_t *ed;
590 1.26.2.2 bouyer int i;
591 1.26.2.2 bouyer
592 1.26.2.2 bouyer #ifdef __FreeBSD__
593 1.26.2.2 bouyer bzero(sc, sizeof(struct cue_softc));
594 1.26.2.2 bouyer #endif
595 1.26.2.2 bouyer
596 1.26.2.2 bouyer DPRINTFN(5,(" : cue_attach: sc=%p, dev=%p", sc, dev));
597 1.26.2.2 bouyer
598 1.26.2.2 bouyer usbd_devinfo(dev, 0, devinfo);
599 1.26.2.2 bouyer USB_ATTACH_SETUP;
600 1.26.2.2 bouyer printf("%s: %s\n", USBDEVNAME(sc->cue_dev), devinfo);
601 1.26.2.2 bouyer
602 1.26.2.2 bouyer err = usbd_set_config_no(dev, CUE_CONFIG_NO, 1);
603 1.26.2.2 bouyer if (err) {
604 1.26.2.2 bouyer printf("%s: setting config no failed\n",
605 1.26.2.2 bouyer USBDEVNAME(sc->cue_dev));
606 1.26.2.2 bouyer USB_ATTACH_ERROR_RETURN;
607 1.26.2.2 bouyer }
608 1.26.2.2 bouyer
609 1.26.2.2 bouyer sc->cue_udev = dev;
610 1.26.2.2 bouyer sc->cue_product = uaa->product;
611 1.26.2.2 bouyer sc->cue_vendor = uaa->vendor;
612 1.26.2.2 bouyer
613 1.26.2.2 bouyer err = usbd_device2interface_handle(dev, CUE_IFACE_IDX, &iface);
614 1.26.2.2 bouyer if (err) {
615 1.26.2.2 bouyer printf("%s: getting interface handle failed\n",
616 1.26.2.2 bouyer USBDEVNAME(sc->cue_dev));
617 1.26.2.2 bouyer USB_ATTACH_ERROR_RETURN;
618 1.26.2.2 bouyer }
619 1.26.2.2 bouyer
620 1.26.2.2 bouyer sc->cue_iface = iface;
621 1.26.2.2 bouyer id = usbd_get_interface_descriptor(iface);
622 1.26.2.2 bouyer
623 1.26.2.2 bouyer /* Find endpoints. */
624 1.26.2.2 bouyer for (i = 0; i < id->bNumEndpoints; i++) {
625 1.26.2.2 bouyer ed = usbd_interface2endpoint_descriptor(iface, i);
626 1.26.2.2 bouyer if (ed == NULL) {
627 1.26.2.2 bouyer printf("%s: couldn't get ep %d\n",
628 1.26.2.2 bouyer USBDEVNAME(sc->cue_dev), i);
629 1.26.2.2 bouyer USB_ATTACH_ERROR_RETURN;
630 1.26.2.2 bouyer }
631 1.26.2.2 bouyer if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
632 1.26.2.2 bouyer UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
633 1.26.2.2 bouyer sc->cue_ed[CUE_ENDPT_RX] = ed->bEndpointAddress;
634 1.26.2.2 bouyer } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
635 1.26.2.2 bouyer UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
636 1.26.2.2 bouyer sc->cue_ed[CUE_ENDPT_TX] = ed->bEndpointAddress;
637 1.26.2.2 bouyer } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
638 1.26.2.2 bouyer UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
639 1.26.2.2 bouyer sc->cue_ed[CUE_ENDPT_INTR] = ed->bEndpointAddress;
640 1.26.2.2 bouyer }
641 1.26.2.2 bouyer }
642 1.26.2.2 bouyer
643 1.26.2.2 bouyer #if 0
644 1.26.2.2 bouyer /* Reset the adapter. */
645 1.26.2.2 bouyer cue_reset(sc);
646 1.26.2.2 bouyer #endif
647 1.26.2.2 bouyer /*
648 1.26.2.2 bouyer * Get station address.
649 1.26.2.2 bouyer */
650 1.26.2.2 bouyer cue_getmac(sc, &eaddr);
651 1.26.2.2 bouyer
652 1.26.2.2 bouyer s = splimp();
653 1.26.2.2 bouyer
654 1.26.2.2 bouyer /*
655 1.26.2.2 bouyer * A CATC chip was detected. Inform the world.
656 1.26.2.2 bouyer */
657 1.26.2.2 bouyer #if defined(__FreeBSD__)
658 1.26.2.2 bouyer printf("%s: Ethernet address: %6D\n", USBDEVNAME(sc->cue_dev), eaddr, ":");
659 1.26.2.2 bouyer
660 1.26.2.2 bouyer bcopy(eaddr, (char *)&sc->arpcom.ac_enaddr, ETHER_ADDR_LEN);
661 1.26.2.2 bouyer
662 1.26.2.2 bouyer ifp = &sc->arpcom.ac_if;
663 1.26.2.2 bouyer ifp->if_softc = sc;
664 1.26.2.2 bouyer ifp->if_unit = USBDEVNAME(sc->cue_dev);
665 1.26.2.2 bouyer ifp->if_name = "cue";
666 1.26.2.2 bouyer ifp->if_mtu = ETHERMTU;
667 1.26.2.2 bouyer ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
668 1.26.2.2 bouyer ifp->if_ioctl = cue_ioctl;
669 1.26.2.2 bouyer ifp->if_output = ether_output;
670 1.26.2.2 bouyer ifp->if_start = cue_start;
671 1.26.2.2 bouyer ifp->if_watchdog = cue_watchdog;
672 1.26.2.2 bouyer ifp->if_init = cue_init;
673 1.26.2.2 bouyer ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
674 1.26.2.2 bouyer
675 1.26.2.2 bouyer cue_qdat.ifp = ifp;
676 1.26.2.2 bouyer cue_qdat.if_rxstart = cue_rxstart;
677 1.26.2.2 bouyer
678 1.26.2.2 bouyer /*
679 1.26.2.2 bouyer * Call MI attach routines.
680 1.26.2.2 bouyer */
681 1.26.2.2 bouyer if_attach(ifp);
682 1.26.2.2 bouyer ether_ifattach(ifp);
683 1.26.2.2 bouyer bpfattach(ifp, DLT_EN10MB, sizeof(struct ether_header));
684 1.26.2.2 bouyer usb_register_netisr();
685 1.26.2.2 bouyer
686 1.26.2.2 bouyer #elif defined(__NetBSD__) || defined(__OpenBSD__)
687 1.26.2.2 bouyer
688 1.26.2.2 bouyer printf("%s: Ethernet address %s\n", USBDEVNAME(sc->cue_dev),
689 1.26.2.2 bouyer ether_sprintf(eaddr));
690 1.26.2.2 bouyer
691 1.26.2.2 bouyer /* Initialize interface info.*/
692 1.26.2.2 bouyer ifp = GET_IFP(sc);
693 1.26.2.2 bouyer ifp->if_softc = sc;
694 1.26.2.2 bouyer ifp->if_mtu = ETHERMTU;
695 1.26.2.2 bouyer ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
696 1.26.2.2 bouyer ifp->if_ioctl = cue_ioctl;
697 1.26.2.2 bouyer ifp->if_start = cue_start;
698 1.26.2.2 bouyer ifp->if_watchdog = cue_watchdog;
699 1.26.2.2 bouyer #if defined(__OpenBSD__)
700 1.26.2.2 bouyer ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
701 1.26.2.2 bouyer #endif
702 1.26.2.2 bouyer strncpy(ifp->if_xname, USBDEVNAME(sc->cue_dev), IFNAMSIZ);
703 1.26.2.2 bouyer
704 1.26.2.2 bouyer /* Attach the interface. */
705 1.26.2.2 bouyer if_attach(ifp);
706 1.26.2.2 bouyer Ether_ifattach(ifp, eaddr);
707 1.26.2.2 bouyer #if NRND > 0
708 1.26.2.2 bouyer rnd_attach_source(&sc->rnd_source, USBDEVNAME(sc->cue_dev),
709 1.26.2.2 bouyer RND_TYPE_NET, 0);
710 1.26.2.2 bouyer #endif
711 1.26.2.2 bouyer
712 1.26.2.2 bouyer #endif /* defined(__NetBSD__) || defined(__OpenBSD__) */
713 1.26.2.2 bouyer
714 1.26.2.2 bouyer usb_callout_init(sc->cue_stat_ch);
715 1.26.2.2 bouyer
716 1.26.2.2 bouyer sc->cue_attached = 1;
717 1.26.2.2 bouyer splx(s);
718 1.26.2.2 bouyer
719 1.26.2.2 bouyer usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->cue_udev,
720 1.26.2.2 bouyer USBDEV(sc->cue_dev));
721 1.26.2.2 bouyer
722 1.26.2.2 bouyer USB_ATTACH_SUCCESS_RETURN;
723 1.26.2.2 bouyer }
724 1.26.2.2 bouyer
725 1.26.2.2 bouyer USB_DETACH(cue)
726 1.26.2.2 bouyer {
727 1.26.2.2 bouyer USB_DETACH_START(cue, sc);
728 1.26.2.2 bouyer struct ifnet *ifp = GET_IFP(sc);
729 1.26.2.2 bouyer int s;
730 1.26.2.2 bouyer
731 1.26.2.2 bouyer DPRINTFN(2,("%s: %s: enter\n", USBDEVNAME(sc->cue_dev), __FUNCTION__));
732 1.26.2.2 bouyer
733 1.26.2.2 bouyer s = splusb();
734 1.26.2.2 bouyer
735 1.26.2.2 bouyer usb_uncallout(sc->cue_stat_ch, cue_tick, sc);
736 1.26.2.2 bouyer
737 1.26.2.2 bouyer if (!sc->cue_attached) {
738 1.26.2.2 bouyer /* Detached before attached finished, so just bail out. */
739 1.26.2.2 bouyer splx(s);
740 1.26.2.2 bouyer return (0);
741 1.26.2.2 bouyer }
742 1.26.2.2 bouyer
743 1.26.2.2 bouyer if (ifp->if_flags & IFF_RUNNING)
744 1.26.2.2 bouyer cue_stop(sc);
745 1.26.2.2 bouyer
746 1.26.2.2 bouyer #if defined(__NetBSD__)
747 1.26.2.2 bouyer #if NRND > 0
748 1.26.2.2 bouyer rnd_detach_source(&sc->rnd_source);
749 1.26.2.2 bouyer #endif
750 1.26.2.2 bouyer ether_ifdetach(ifp);
751 1.26.2.2 bouyer #endif /* __NetBSD__ */
752 1.26.2.2 bouyer
753 1.26.2.2 bouyer if_detach(ifp);
754 1.26.2.2 bouyer
755 1.26.2.2 bouyer #ifdef DIAGNOSTIC
756 1.26.2.2 bouyer if (sc->cue_ep[CUE_ENDPT_TX] != NULL ||
757 1.26.2.2 bouyer sc->cue_ep[CUE_ENDPT_RX] != NULL ||
758 1.26.2.2 bouyer sc->cue_ep[CUE_ENDPT_INTR] != NULL)
759 1.26.2.2 bouyer printf("%s: detach has active endpoints\n",
760 1.26.2.2 bouyer USBDEVNAME(sc->cue_dev));
761 1.26.2.2 bouyer #endif
762 1.26.2.2 bouyer
763 1.26.2.2 bouyer sc->cue_attached = 0;
764 1.26.2.2 bouyer splx(s);
765 1.26.2.2 bouyer
766 1.26.2.2 bouyer usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->cue_udev,
767 1.26.2.2 bouyer USBDEV(sc->cue_dev));
768 1.26.2.2 bouyer
769 1.26.2.2 bouyer return (0);
770 1.26.2.2 bouyer }
771 1.26.2.2 bouyer
772 1.26.2.2 bouyer #if defined(__NetBSD__) || defined(__OpenBSD__)
773 1.26.2.2 bouyer int
774 1.26.2.2 bouyer cue_activate(device_ptr_t self, enum devact act)
775 1.26.2.2 bouyer {
776 1.26.2.2 bouyer struct cue_softc *sc = (struct cue_softc *)self;
777 1.26.2.2 bouyer
778 1.26.2.2 bouyer DPRINTFN(2,("%s: %s: enter\n", USBDEVNAME(sc->cue_dev), __FUNCTION__));
779 1.26.2.2 bouyer
780 1.26.2.2 bouyer switch (act) {
781 1.26.2.2 bouyer case DVACT_ACTIVATE:
782 1.26.2.2 bouyer return (EOPNOTSUPP);
783 1.26.2.2 bouyer break;
784 1.26.2.2 bouyer
785 1.26.2.2 bouyer case DVACT_DEACTIVATE:
786 1.26.2.2 bouyer /* Deactivate the interface. */
787 1.26.2.2 bouyer if_deactivate(&sc->cue_ec.ec_if);
788 1.26.2.2 bouyer sc->cue_dying = 1;
789 1.26.2.2 bouyer break;
790 1.26.2.2 bouyer }
791 1.26.2.2 bouyer return (0);
792 1.26.2.2 bouyer }
793 1.26.2.2 bouyer #endif /* defined(__NetBSD__) || defined(__OpenBSD__) */
794 1.26.2.2 bouyer
795 1.26.2.2 bouyer /*
796 1.26.2.2 bouyer * Initialize an RX descriptor and attach an MBUF cluster.
797 1.26.2.2 bouyer */
798 1.26.2.2 bouyer Static int
799 1.26.2.2 bouyer cue_newbuf(struct cue_softc *sc, struct cue_chain *c, struct mbuf *m)
800 1.26.2.2 bouyer {
801 1.26.2.2 bouyer struct mbuf *m_new = NULL;
802 1.26.2.2 bouyer
803 1.26.2.2 bouyer if (m == NULL) {
804 1.26.2.2 bouyer MGETHDR(m_new, M_DONTWAIT, MT_DATA);
805 1.26.2.2 bouyer if (m_new == NULL) {
806 1.26.2.2 bouyer printf("%s: no memory for rx list "
807 1.26.2.2 bouyer "-- packet dropped!\n", USBDEVNAME(sc->cue_dev));
808 1.26.2.2 bouyer return (ENOBUFS);
809 1.26.2.2 bouyer }
810 1.26.2.2 bouyer
811 1.26.2.2 bouyer MCLGET(m_new, M_DONTWAIT);
812 1.26.2.2 bouyer if (!(m_new->m_flags & M_EXT)) {
813 1.26.2.2 bouyer printf("%s: no memory for rx list "
814 1.26.2.2 bouyer "-- packet dropped!\n", USBDEVNAME(sc->cue_dev));
815 1.26.2.2 bouyer m_freem(m_new);
816 1.26.2.2 bouyer return (ENOBUFS);
817 1.26.2.2 bouyer }
818 1.26.2.2 bouyer m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
819 1.26.2.2 bouyer } else {
820 1.26.2.2 bouyer m_new = m;
821 1.26.2.2 bouyer m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
822 1.26.2.2 bouyer m_new->m_data = m_new->m_ext.ext_buf;
823 1.26.2.2 bouyer }
824 1.26.2.2 bouyer
825 1.26.2.2 bouyer m_adj(m_new, ETHER_ALIGN);
826 1.26.2.2 bouyer c->cue_mbuf = m_new;
827 1.26.2.2 bouyer
828 1.26.2.2 bouyer return (0);
829 1.26.2.2 bouyer }
830 1.26.2.2 bouyer
831 1.26.2.2 bouyer Static int
832 1.26.2.2 bouyer cue_rx_list_init(struct cue_softc *sc)
833 1.26.2.2 bouyer {
834 1.26.2.2 bouyer struct cue_cdata *cd;
835 1.26.2.2 bouyer struct cue_chain *c;
836 1.26.2.2 bouyer int i;
837 1.26.2.2 bouyer
838 1.26.2.2 bouyer cd = &sc->cue_cdata;
839 1.26.2.2 bouyer for (i = 0; i < CUE_RX_LIST_CNT; i++) {
840 1.26.2.2 bouyer c = &cd->cue_rx_chain[i];
841 1.26.2.2 bouyer c->cue_sc = sc;
842 1.26.2.2 bouyer c->cue_idx = i;
843 1.26.2.2 bouyer if (cue_newbuf(sc, c, NULL) == ENOBUFS)
844 1.26.2.2 bouyer return (ENOBUFS);
845 1.26.2.2 bouyer if (c->cue_xfer == NULL) {
846 1.26.2.2 bouyer c->cue_xfer = usbd_alloc_xfer(sc->cue_udev);
847 1.26.2.2 bouyer if (c->cue_xfer == NULL)
848 1.26.2.2 bouyer return (ENOBUFS);
849 1.26.2.2 bouyer c->cue_buf = usbd_alloc_buffer(c->cue_xfer, CUE_BUFSZ);
850 1.26.2.2 bouyer if (c->cue_buf == NULL) {
851 1.26.2.2 bouyer usbd_free_xfer(c->cue_xfer);
852 1.26.2.2 bouyer return (ENOBUFS);
853 1.26.2.2 bouyer }
854 1.26.2.2 bouyer }
855 1.26.2.2 bouyer }
856 1.26.2.2 bouyer
857 1.26.2.2 bouyer return (0);
858 1.26.2.2 bouyer }
859 1.26.2.2 bouyer
860 1.26.2.2 bouyer Static int
861 1.26.2.2 bouyer cue_tx_list_init(struct cue_softc *sc)
862 1.26.2.2 bouyer {
863 1.26.2.2 bouyer struct cue_cdata *cd;
864 1.26.2.2 bouyer struct cue_chain *c;
865 1.26.2.2 bouyer int i;
866 1.26.2.2 bouyer
867 1.26.2.2 bouyer cd = &sc->cue_cdata;
868 1.26.2.2 bouyer for (i = 0; i < CUE_TX_LIST_CNT; i++) {
869 1.26.2.2 bouyer c = &cd->cue_tx_chain[i];
870 1.26.2.2 bouyer c->cue_sc = sc;
871 1.26.2.2 bouyer c->cue_idx = i;
872 1.26.2.2 bouyer c->cue_mbuf = NULL;
873 1.26.2.2 bouyer if (c->cue_xfer == NULL) {
874 1.26.2.2 bouyer c->cue_xfer = usbd_alloc_xfer(sc->cue_udev);
875 1.26.2.2 bouyer if (c->cue_xfer == NULL)
876 1.26.2.2 bouyer return (ENOBUFS);
877 1.26.2.2 bouyer c->cue_buf = usbd_alloc_buffer(c->cue_xfer, CUE_BUFSZ);
878 1.26.2.2 bouyer if (c->cue_buf == NULL) {
879 1.26.2.2 bouyer usbd_free_xfer(c->cue_xfer);
880 1.26.2.2 bouyer return (ENOBUFS);
881 1.26.2.2 bouyer }
882 1.26.2.2 bouyer }
883 1.26.2.2 bouyer }
884 1.26.2.2 bouyer
885 1.26.2.2 bouyer return (0);
886 1.26.2.2 bouyer }
887 1.26.2.2 bouyer
888 1.26.2.2 bouyer #ifdef __FreeBSD__
889 1.26.2.2 bouyer Static void
890 1.26.2.2 bouyer cue_rxstart(struct ifnet *ifp)
891 1.26.2.2 bouyer {
892 1.26.2.2 bouyer struct cue_softc *sc;
893 1.26.2.2 bouyer struct cue_chain *c;
894 1.26.2.2 bouyer
895 1.26.2.2 bouyer sc = ifp->if_softc;
896 1.26.2.2 bouyer c = &sc->cue_cdata.cue_rx_chain[sc->cue_cdata.cue_rx_prod];
897 1.26.2.2 bouyer
898 1.26.2.2 bouyer if (cue_newbuf(sc, c, NULL) == ENOBUFS) {
899 1.26.2.2 bouyer ifp->if_ierrors++;
900 1.26.2.2 bouyer return;
901 1.26.2.2 bouyer }
902 1.26.2.2 bouyer
903 1.26.2.2 bouyer /* Setup new transfer. */
904 1.26.2.2 bouyer usbd_setup_xfer(c->cue_xfer, sc->cue_ep[CUE_ENDPT_RX],
905 1.26.2.2 bouyer c, c->cue_buf, CUE_BUFSZ, USBD_SHORT_XFER_OK | USBD_NO_COPY,
906 1.26.2.2 bouyer USBD_NO_TIMEOUT, cue_rxeof);
907 1.26.2.2 bouyer usbd_transfer(c->cue_xfer);
908 1.26.2.2 bouyer }
909 1.26.2.2 bouyer #endif
910 1.26.2.2 bouyer
911 1.26.2.2 bouyer /*
912 1.26.2.2 bouyer * A frame has been uploaded: pass the resulting mbuf chain up to
913 1.26.2.2 bouyer * the higher level protocols.
914 1.26.2.2 bouyer */
915 1.26.2.2 bouyer Static void
916 1.26.2.2 bouyer cue_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
917 1.26.2.2 bouyer {
918 1.26.2.2 bouyer struct cue_chain *c = priv;
919 1.26.2.2 bouyer struct cue_softc *sc = c->cue_sc;
920 1.26.2.2 bouyer struct ifnet *ifp = GET_IFP(sc);
921 1.26.2.2 bouyer struct mbuf *m;
922 1.26.2.2 bouyer int total_len = 0;
923 1.26.2.2 bouyer u_int16_t len;
924 1.26.2.2 bouyer #if defined(__NetBSD__) || defined(__OpenBSD__)
925 1.26.2.2 bouyer int s;
926 1.26.2.2 bouyer #endif /* defined(__NetBSD__) || defined(__OpenBSD__) */
927 1.26.2.2 bouyer
928 1.26.2.2 bouyer DPRINTFN(10,("%s: %s: enter status=%d\n", USBDEVNAME(sc->cue_dev),
929 1.26.2.2 bouyer __FUNCTION__, status));
930 1.26.2.2 bouyer
931 1.26.2.2 bouyer if (sc->cue_dying)
932 1.26.2.2 bouyer return;
933 1.26.2.2 bouyer
934 1.26.2.2 bouyer if (!(ifp->if_flags & IFF_RUNNING))
935 1.26.2.2 bouyer return;
936 1.26.2.2 bouyer
937 1.26.2.2 bouyer if (status != USBD_NORMAL_COMPLETION) {
938 1.26.2.2 bouyer if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
939 1.26.2.2 bouyer return;
940 1.26.2.2 bouyer sc->cue_rx_errs++;
941 1.26.2.2 bouyer if (usbd_ratecheck(&sc->cue_rx_notice)) {
942 1.26.2.2 bouyer printf("%s: %u usb errors on rx: %s\n",
943 1.26.2.2 bouyer USBDEVNAME(sc->cue_dev), sc->cue_rx_errs,
944 1.26.2.2 bouyer usbd_errstr(status));
945 1.26.2.2 bouyer sc->cue_rx_errs = 0;
946 1.26.2.2 bouyer }
947 1.26.2.2 bouyer if (status == USBD_STALLED)
948 1.26.2.2 bouyer usbd_clear_endpoint_stall(sc->cue_ep[CUE_ENDPT_RX]);
949 1.26.2.2 bouyer goto done;
950 1.26.2.2 bouyer }
951 1.26.2.2 bouyer
952 1.26.2.2 bouyer usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL);
953 1.26.2.2 bouyer
954 1.26.2.2 bouyer memcpy(mtod(c->cue_mbuf, char *), c->cue_buf, total_len);
955 1.26.2.2 bouyer
956 1.26.2.2 bouyer m = c->cue_mbuf;
957 1.26.2.2 bouyer len = UGETW(mtod(m, u_int8_t *));
958 1.26.2.2 bouyer
959 1.26.2.2 bouyer /* No errors; receive the packet. */
960 1.26.2.2 bouyer total_len = len;
961 1.26.2.2 bouyer
962 1.26.2.2 bouyer if (len < sizeof(struct ether_header)) {
963 1.26.2.2 bouyer ifp->if_ierrors++;
964 1.26.2.2 bouyer goto done;
965 1.26.2.2 bouyer }
966 1.26.2.2 bouyer
967 1.26.2.2 bouyer ifp->if_ipackets++;
968 1.26.2.2 bouyer m_adj(m, sizeof(u_int16_t));
969 1.26.2.2 bouyer m->m_pkthdr.len = m->m_len = total_len;
970 1.26.2.2 bouyer
971 1.26.2.2 bouyer #if defined(__FreeBSD__)
972 1.26.2.2 bouyer m->m_pkthdr.rcvif = (struct ifnet *)&cue_qdat;
973 1.26.2.2 bouyer /* Put the packet on the special USB input queue. */
974 1.26.2.2 bouyer usb_ether_input(m);
975 1.26.2.2 bouyer
976 1.26.2.2 bouyer return;
977 1.26.2.2 bouyer #elif defined(__NetBSD__) || defined(__OpenBSD__)
978 1.26.2.2 bouyer m->m_pkthdr.rcvif = ifp;
979 1.26.2.2 bouyer
980 1.26.2.2 bouyer s = splimp();
981 1.26.2.2 bouyer
982 1.26.2.2 bouyer /* XXX ugly */
983 1.26.2.2 bouyer if (cue_newbuf(sc, c, NULL) == ENOBUFS) {
984 1.26.2.2 bouyer ifp->if_ierrors++;
985 1.26.2.2 bouyer goto done1;
986 1.26.2.2 bouyer }
987 1.26.2.2 bouyer
988 1.26.2.2 bouyer #if NBPFILTER > 0
989 1.26.2.2 bouyer /*
990 1.26.2.2 bouyer * Handle BPF listeners. Let the BPF user see the packet, but
991 1.26.2.2 bouyer * don't pass it up to the ether_input() layer unless it's
992 1.26.2.2 bouyer * a broadcast packet, multicast packet, matches our ethernet
993 1.26.2.2 bouyer * address or the interface is in promiscuous mode.
994 1.26.2.2 bouyer */
995 1.26.2.2 bouyer if (ifp->if_bpf)
996 1.26.2.2 bouyer BPF_MTAP(ifp, m);
997 1.26.2.2 bouyer #endif
998 1.26.2.2 bouyer
999 1.26.2.2 bouyer DPRINTFN(10,("%s: %s: deliver %d\n", USBDEVNAME(sc->cue_dev),
1000 1.26.2.2 bouyer __FUNCTION__, m->m_len));
1001 1.26.2.2 bouyer IF_INPUT(ifp, m);
1002 1.26.2.2 bouyer done1:
1003 1.26.2.2 bouyer splx(s);
1004 1.26.2.2 bouyer #endif /* defined(__NetBSD__) || defined(__OpenBSD__) */
1005 1.26.2.2 bouyer
1006 1.26.2.2 bouyer done:
1007 1.26.2.2 bouyer /* Setup new transfer. */
1008 1.26.2.2 bouyer usbd_setup_xfer(c->cue_xfer, sc->cue_ep[CUE_ENDPT_RX],
1009 1.26.2.2 bouyer c, c->cue_buf, CUE_BUFSZ, USBD_SHORT_XFER_OK | USBD_NO_COPY,
1010 1.26.2.2 bouyer USBD_NO_TIMEOUT, cue_rxeof);
1011 1.26.2.2 bouyer usbd_transfer(c->cue_xfer);
1012 1.26.2.2 bouyer
1013 1.26.2.2 bouyer DPRINTFN(10,("%s: %s: start rx\n", USBDEVNAME(sc->cue_dev),
1014 1.26.2.2 bouyer __FUNCTION__));
1015 1.26.2.2 bouyer }
1016 1.26.2.2 bouyer
1017 1.26.2.2 bouyer /*
1018 1.26.2.2 bouyer * A frame was downloaded to the chip. It's safe for us to clean up
1019 1.26.2.2 bouyer * the list buffers.
1020 1.26.2.2 bouyer */
1021 1.26.2.2 bouyer Static void
1022 1.26.2.2 bouyer cue_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
1023 1.26.2.2 bouyer {
1024 1.26.2.2 bouyer struct cue_chain *c = priv;
1025 1.26.2.2 bouyer struct cue_softc *sc = c->cue_sc;
1026 1.26.2.2 bouyer struct ifnet *ifp = GET_IFP(sc);
1027 1.26.2.2 bouyer int s;
1028 1.26.2.2 bouyer
1029 1.26.2.2 bouyer if (sc->cue_dying)
1030 1.26.2.2 bouyer return;
1031 1.26.2.2 bouyer
1032 1.26.2.2 bouyer s = splimp();
1033 1.26.2.2 bouyer
1034 1.26.2.2 bouyer DPRINTFN(10,("%s: %s: enter status=%d\n", USBDEVNAME(sc->cue_dev),
1035 1.26.2.2 bouyer __FUNCTION__, status));
1036 1.26.2.2 bouyer
1037 1.26.2.2 bouyer ifp->if_timer = 0;
1038 1.26.2.2 bouyer ifp->if_flags &= ~IFF_OACTIVE;
1039 1.26.2.2 bouyer
1040 1.26.2.2 bouyer if (status != USBD_NORMAL_COMPLETION) {
1041 1.26.2.2 bouyer if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
1042 1.26.2.2 bouyer splx(s);
1043 1.26.2.2 bouyer return;
1044 1.26.2.2 bouyer }
1045 1.26.2.2 bouyer ifp->if_oerrors++;
1046 1.26.2.2 bouyer printf("%s: usb error on tx: %s\n", USBDEVNAME(sc->cue_dev),
1047 1.26.2.2 bouyer usbd_errstr(status));
1048 1.26.2.2 bouyer if (status == USBD_STALLED)
1049 1.26.2.2 bouyer usbd_clear_endpoint_stall(sc->cue_ep[CUE_ENDPT_TX]);
1050 1.26.2.2 bouyer splx(s);
1051 1.26.2.2 bouyer return;
1052 1.26.2.2 bouyer }
1053 1.26.2.2 bouyer
1054 1.26.2.2 bouyer ifp->if_opackets++;
1055 1.26.2.2 bouyer
1056 1.26.2.2 bouyer #if defined(__FreeBSD__)
1057 1.26.2.2 bouyer c->cue_mbuf->m_pkthdr.rcvif = ifp;
1058 1.26.2.2 bouyer usb_tx_done(c->cue_mbuf);
1059 1.26.2.2 bouyer c->cue_mbuf = NULL;
1060 1.26.2.2 bouyer #elif defined(__NetBSD__) || defined(__OpenBSD__)
1061 1.26.2.2 bouyer m_freem(c->cue_mbuf);
1062 1.26.2.2 bouyer c->cue_mbuf = NULL;
1063 1.26.2.2 bouyer
1064 1.26.2.2 bouyer if (ifp->if_snd.ifq_head != NULL)
1065 1.26.2.2 bouyer cue_start(ifp);
1066 1.26.2.2 bouyer #endif /* defined(__NetBSD__) || defined(__OpenBSD__) */
1067 1.26.2.2 bouyer
1068 1.26.2.2 bouyer splx(s);
1069 1.26.2.2 bouyer }
1070 1.26.2.2 bouyer
1071 1.26.2.2 bouyer Static void
1072 1.26.2.2 bouyer cue_tick(void *xsc)
1073 1.26.2.2 bouyer {
1074 1.26.2.2 bouyer struct cue_softc *sc = xsc;
1075 1.26.2.2 bouyer struct ifnet *ifp;
1076 1.26.2.2 bouyer int s;
1077 1.26.2.2 bouyer
1078 1.26.2.2 bouyer if (sc == NULL)
1079 1.26.2.2 bouyer return;
1080 1.26.2.2 bouyer
1081 1.26.2.2 bouyer if (sc->cue_dying)
1082 1.26.2.2 bouyer return;
1083 1.26.2.2 bouyer
1084 1.26.2.2 bouyer DPRINTFN(2,("%s: %s: enter\n", USBDEVNAME(sc->cue_dev), __FUNCTION__));
1085 1.26.2.2 bouyer
1086 1.26.2.2 bouyer s = splimp();
1087 1.26.2.2 bouyer
1088 1.26.2.2 bouyer ifp = GET_IFP(sc);
1089 1.26.2.2 bouyer
1090 1.26.2.2 bouyer ifp->if_collisions += cue_csr_read_2(sc, CUE_TX_SINGLECOLL);
1091 1.26.2.2 bouyer ifp->if_collisions += cue_csr_read_2(sc, CUE_TX_MULTICOLL);
1092 1.26.2.2 bouyer ifp->if_collisions += cue_csr_read_2(sc, CUE_TX_EXCESSCOLL);
1093 1.26.2.2 bouyer
1094 1.26.2.2 bouyer if (cue_csr_read_2(sc, CUE_RX_FRAMEERR))
1095 1.26.2.2 bouyer ifp->if_ierrors++;
1096 1.26.2.2 bouyer
1097 1.26.2.2 bouyer usb_callout(sc->cue_stat_ch, hz, cue_tick, sc);
1098 1.26.2.2 bouyer
1099 1.26.2.2 bouyer splx(s);
1100 1.26.2.2 bouyer }
1101 1.26.2.2 bouyer
1102 1.26.2.2 bouyer Static int
1103 1.26.2.2 bouyer cue_send(struct cue_softc *sc, struct mbuf *m, int idx)
1104 1.26.2.2 bouyer {
1105 1.26.2.2 bouyer int total_len;
1106 1.26.2.2 bouyer struct cue_chain *c;
1107 1.26.2.2 bouyer usbd_status err;
1108 1.26.2.2 bouyer
1109 1.26.2.2 bouyer c = &sc->cue_cdata.cue_tx_chain[idx];
1110 1.26.2.2 bouyer
1111 1.26.2.2 bouyer /*
1112 1.26.2.2 bouyer * Copy the mbuf data into a contiguous buffer, leaving two
1113 1.26.2.2 bouyer * bytes at the beginning to hold the frame length.
1114 1.26.2.2 bouyer */
1115 1.26.2.2 bouyer m_copydata(m, 0, m->m_pkthdr.len, c->cue_buf + 2);
1116 1.26.2.2 bouyer c->cue_mbuf = m;
1117 1.26.2.2 bouyer
1118 1.26.2.2 bouyer total_len = m->m_pkthdr.len + 2;
1119 1.26.2.2 bouyer
1120 1.26.2.2 bouyer DPRINTFN(10,("%s: %s: total_len=%d\n",
1121 1.26.2.2 bouyer USBDEVNAME(sc->cue_dev), __FUNCTION__, total_len));
1122 1.26.2.2 bouyer
1123 1.26.2.2 bouyer /* The first two bytes are the frame length */
1124 1.26.2.2 bouyer c->cue_buf[0] = (u_int8_t)m->m_pkthdr.len;
1125 1.26.2.2 bouyer c->cue_buf[1] = (u_int8_t)(m->m_pkthdr.len >> 8);
1126 1.26.2.2 bouyer
1127 1.26.2.2 bouyer /* XXX 10000 */
1128 1.26.2.2 bouyer usbd_setup_xfer(c->cue_xfer, sc->cue_ep[CUE_ENDPT_TX],
1129 1.26.2.2 bouyer c, c->cue_buf, total_len, USBD_NO_COPY, 10000, cue_txeof);
1130 1.26.2.2 bouyer
1131 1.26.2.2 bouyer /* Transmit */
1132 1.26.2.2 bouyer err = usbd_transfer(c->cue_xfer);
1133 1.26.2.2 bouyer if (err != USBD_IN_PROGRESS) {
1134 1.26.2.2 bouyer printf("%s: cue_send error=%s\n", USBDEVNAME(sc->cue_dev),
1135 1.26.2.2 bouyer usbd_errstr(err));
1136 1.26.2.2 bouyer cue_stop(sc);
1137 1.26.2.2 bouyer return (EIO);
1138 1.26.2.2 bouyer }
1139 1.26.2.2 bouyer
1140 1.26.2.2 bouyer sc->cue_cdata.cue_tx_cnt++;
1141 1.26.2.2 bouyer
1142 1.26.2.2 bouyer return (0);
1143 1.26.2.2 bouyer }
1144 1.26.2.2 bouyer
1145 1.26.2.2 bouyer Static void
1146 1.26.2.2 bouyer cue_start(struct ifnet *ifp)
1147 1.26.2.2 bouyer {
1148 1.26.2.2 bouyer struct cue_softc *sc = ifp->if_softc;
1149 1.26.2.2 bouyer struct mbuf *m_head = NULL;
1150 1.26.2.2 bouyer
1151 1.26.2.2 bouyer if (sc->cue_dying)
1152 1.26.2.2 bouyer return;
1153 1.26.2.2 bouyer
1154 1.26.2.2 bouyer DPRINTFN(10,("%s: %s: enter\n", USBDEVNAME(sc->cue_dev),__FUNCTION__));
1155 1.26.2.2 bouyer
1156 1.26.2.2 bouyer if (ifp->if_flags & IFF_OACTIVE)
1157 1.26.2.2 bouyer return;
1158 1.26.2.2 bouyer
1159 1.26.2.2 bouyer IF_DEQUEUE(&ifp->if_snd, m_head);
1160 1.26.2.2 bouyer if (m_head == NULL)
1161 1.26.2.2 bouyer return;
1162 1.26.2.2 bouyer
1163 1.26.2.2 bouyer if (cue_send(sc, m_head, 0)) {
1164 1.26.2.2 bouyer IF_PREPEND(&ifp->if_snd, m_head);
1165 1.26.2.2 bouyer ifp->if_flags |= IFF_OACTIVE;
1166 1.26.2.2 bouyer return;
1167 1.26.2.2 bouyer }
1168 1.26.2.2 bouyer
1169 1.26.2.2 bouyer #if NBPFILTER > 0
1170 1.26.2.2 bouyer /*
1171 1.26.2.2 bouyer * If there's a BPF listener, bounce a copy of this frame
1172 1.26.2.2 bouyer * to him.
1173 1.26.2.2 bouyer */
1174 1.26.2.2 bouyer if (ifp->if_bpf)
1175 1.26.2.2 bouyer BPF_MTAP(ifp, m_head);
1176 1.26.2.2 bouyer #endif
1177 1.26.2.2 bouyer
1178 1.26.2.2 bouyer ifp->if_flags |= IFF_OACTIVE;
1179 1.26.2.2 bouyer
1180 1.26.2.2 bouyer /*
1181 1.26.2.2 bouyer * Set a timeout in case the chip goes out to lunch.
1182 1.26.2.2 bouyer */
1183 1.26.2.2 bouyer ifp->if_timer = 5;
1184 1.26.2.2 bouyer }
1185 1.26.2.2 bouyer
1186 1.26.2.2 bouyer Static void
1187 1.26.2.2 bouyer cue_init(void *xsc)
1188 1.26.2.2 bouyer {
1189 1.26.2.2 bouyer struct cue_softc *sc = xsc;
1190 1.26.2.2 bouyer struct ifnet *ifp = GET_IFP(sc);
1191 1.26.2.2 bouyer int i, s, ctl;
1192 1.26.2.2 bouyer u_char *eaddr;
1193 1.26.2.2 bouyer
1194 1.26.2.2 bouyer if (sc->cue_dying)
1195 1.26.2.2 bouyer return;
1196 1.26.2.2 bouyer
1197 1.26.2.2 bouyer DPRINTFN(10,("%s: %s: enter\n", USBDEVNAME(sc->cue_dev),__FUNCTION__));
1198 1.26.2.2 bouyer
1199 1.26.2.2 bouyer if (ifp->if_flags & IFF_RUNNING)
1200 1.26.2.2 bouyer return;
1201 1.26.2.2 bouyer
1202 1.26.2.2 bouyer s = splimp();
1203 1.26.2.2 bouyer
1204 1.26.2.2 bouyer /*
1205 1.26.2.2 bouyer * Cancel pending I/O and free all RX/TX buffers.
1206 1.26.2.2 bouyer */
1207 1.26.2.2 bouyer #if 1
1208 1.26.2.2 bouyer cue_reset(sc);
1209 1.26.2.2 bouyer #endif
1210 1.26.2.2 bouyer
1211 1.26.2.2 bouyer /* Set advanced operation modes. */
1212 1.26.2.2 bouyer cue_csr_write_1(sc, CUE_ADVANCED_OPMODES,
1213 1.26.2.2 bouyer CUE_AOP_EMBED_RXLEN | 0x03); /* 1 wait state */
1214 1.26.2.2 bouyer
1215 1.26.2.2 bouyer #if defined(__FreeBSD__) || defined(__OpenBSD__)
1216 1.26.2.2 bouyer eaddr = sc->arpcom.ac_enaddr;
1217 1.26.2.2 bouyer #elif defined(__NetBSD__)
1218 1.26.2.2 bouyer eaddr = LLADDR(ifp->if_sadl);
1219 1.26.2.2 bouyer #endif /* defined(__NetBSD__) || defined(__OpenBSD__) */
1220 1.26.2.2 bouyer /* Set MAC address */
1221 1.26.2.2 bouyer for (i = 0; i < ETHER_ADDR_LEN; i++)
1222 1.26.2.2 bouyer cue_csr_write_1(sc, CUE_PAR0 - i, eaddr[i]);
1223 1.26.2.2 bouyer
1224 1.26.2.2 bouyer /* Enable RX logic. */
1225 1.26.2.2 bouyer ctl = CUE_ETHCTL_RX_ON | CUE_ETHCTL_MCAST_ON;
1226 1.26.2.2 bouyer if (ifp->if_flags & IFF_PROMISC)
1227 1.26.2.2 bouyer ctl |= CUE_ETHCTL_PROMISC;
1228 1.26.2.2 bouyer cue_csr_write_1(sc, CUE_ETHCTL, ctl);
1229 1.26.2.2 bouyer
1230 1.26.2.2 bouyer /* Init TX ring. */
1231 1.26.2.2 bouyer if (cue_tx_list_init(sc) == ENOBUFS) {
1232 1.26.2.2 bouyer printf("%s: tx list init failed\n", USBDEVNAME(sc->cue_dev));
1233 1.26.2.2 bouyer splx(s);
1234 1.26.2.2 bouyer return;
1235 1.26.2.2 bouyer }
1236 1.26.2.2 bouyer
1237 1.26.2.2 bouyer /* Init RX ring. */
1238 1.26.2.2 bouyer if (cue_rx_list_init(sc) == ENOBUFS) {
1239 1.26.2.2 bouyer printf("%s: rx list init failed\n", USBDEVNAME(sc->cue_dev));
1240 1.26.2.2 bouyer splx(s);
1241 1.26.2.2 bouyer return;
1242 1.26.2.2 bouyer }
1243 1.26.2.2 bouyer
1244 1.26.2.2 bouyer /* Load the multicast filter. */
1245 1.26.2.2 bouyer cue_setmulti(sc);
1246 1.26.2.2 bouyer
1247 1.26.2.2 bouyer /*
1248 1.26.2.2 bouyer * Set the number of RX and TX buffers that we want
1249 1.26.2.2 bouyer * to reserve inside the ASIC.
1250 1.26.2.2 bouyer */
1251 1.26.2.2 bouyer cue_csr_write_1(sc, CUE_RX_BUFPKTS, CUE_RX_FRAMES);
1252 1.26.2.2 bouyer cue_csr_write_1(sc, CUE_TX_BUFPKTS, CUE_TX_FRAMES);
1253 1.26.2.2 bouyer
1254 1.26.2.2 bouyer /* Set advanced operation modes. */
1255 1.26.2.2 bouyer cue_csr_write_1(sc, CUE_ADVANCED_OPMODES,
1256 1.26.2.2 bouyer CUE_AOP_EMBED_RXLEN | 0x01); /* 1 wait state */
1257 1.26.2.2 bouyer
1258 1.26.2.2 bouyer /* Program the LED operation. */
1259 1.26.2.2 bouyer cue_csr_write_1(sc, CUE_LEDCTL, CUE_LEDCTL_FOLLOW_LINK);
1260 1.26.2.2 bouyer
1261 1.26.2.2 bouyer if (sc->cue_ep[CUE_ENDPT_RX] == NULL) {
1262 1.26.2.2 bouyer if (cue_open_pipes(sc)) {
1263 1.26.2.2 bouyer splx(s);
1264 1.26.2.2 bouyer return;
1265 1.26.2.2 bouyer }
1266 1.26.2.2 bouyer }
1267 1.26.2.2 bouyer
1268 1.26.2.2 bouyer ifp->if_flags |= IFF_RUNNING;
1269 1.26.2.2 bouyer ifp->if_flags &= ~IFF_OACTIVE;
1270 1.26.2.2 bouyer
1271 1.26.2.2 bouyer splx(s);
1272 1.26.2.2 bouyer
1273 1.26.2.2 bouyer usb_callout(sc->cue_stat_ch, hz, cue_tick, sc);
1274 1.26.2.2 bouyer }
1275 1.26.2.2 bouyer
1276 1.26.2.2 bouyer Static int
1277 1.26.2.2 bouyer cue_open_pipes(struct cue_softc *sc)
1278 1.26.2.2 bouyer {
1279 1.26.2.2 bouyer struct cue_chain *c;
1280 1.26.2.2 bouyer usbd_status err;
1281 1.26.2.2 bouyer int i;
1282 1.26.2.2 bouyer
1283 1.26.2.2 bouyer /* Open RX and TX pipes. */
1284 1.26.2.2 bouyer err = usbd_open_pipe(sc->cue_iface, sc->cue_ed[CUE_ENDPT_RX],
1285 1.26.2.2 bouyer USBD_EXCLUSIVE_USE, &sc->cue_ep[CUE_ENDPT_RX]);
1286 1.26.2.2 bouyer if (err) {
1287 1.26.2.2 bouyer printf("%s: open rx pipe failed: %s\n",
1288 1.26.2.2 bouyer USBDEVNAME(sc->cue_dev), usbd_errstr(err));
1289 1.26.2.2 bouyer return (EIO);
1290 1.26.2.2 bouyer }
1291 1.26.2.2 bouyer err = usbd_open_pipe(sc->cue_iface, sc->cue_ed[CUE_ENDPT_TX],
1292 1.26.2.2 bouyer USBD_EXCLUSIVE_USE, &sc->cue_ep[CUE_ENDPT_TX]);
1293 1.26.2.2 bouyer if (err) {
1294 1.26.2.2 bouyer printf("%s: open tx pipe failed: %s\n",
1295 1.26.2.2 bouyer USBDEVNAME(sc->cue_dev), usbd_errstr(err));
1296 1.26.2.2 bouyer return (EIO);
1297 1.26.2.2 bouyer }
1298 1.26.2.2 bouyer
1299 1.26.2.2 bouyer /* Start up the receive pipe. */
1300 1.26.2.2 bouyer for (i = 0; i < CUE_RX_LIST_CNT; i++) {
1301 1.26.2.2 bouyer c = &sc->cue_cdata.cue_rx_chain[i];
1302 1.26.2.2 bouyer usbd_setup_xfer(c->cue_xfer, sc->cue_ep[CUE_ENDPT_RX],
1303 1.26.2.2 bouyer c, c->cue_buf, CUE_BUFSZ,
1304 1.26.2.2 bouyer USBD_SHORT_XFER_OK | USBD_NO_COPY, USBD_NO_TIMEOUT,
1305 1.26.2.2 bouyer cue_rxeof);
1306 1.26.2.2 bouyer usbd_transfer(c->cue_xfer);
1307 1.26.2.2 bouyer }
1308 1.26.2.2 bouyer
1309 1.26.2.2 bouyer return (0);
1310 1.26.2.2 bouyer }
1311 1.26.2.2 bouyer
1312 1.26.2.2 bouyer Static int
1313 1.26.2.2 bouyer cue_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
1314 1.26.2.2 bouyer {
1315 1.26.2.2 bouyer struct cue_softc *sc = ifp->if_softc;
1316 1.26.2.2 bouyer #if defined(__NetBSD__) || defined(__OpenBSD__)
1317 1.26.2.2 bouyer struct ifaddr *ifa = (struct ifaddr *)data;
1318 1.26.2.2 bouyer struct ifreq *ifr = (struct ifreq *)data;
1319 1.26.2.2 bouyer #endif
1320 1.26.2.2 bouyer int s, error = 0;
1321 1.26.2.2 bouyer
1322 1.26.2.2 bouyer if (sc->cue_dying)
1323 1.26.2.2 bouyer return (EIO);
1324 1.26.2.2 bouyer
1325 1.26.2.2 bouyer s = splimp();
1326 1.26.2.2 bouyer
1327 1.26.2.2 bouyer switch(command) {
1328 1.26.2.2 bouyer #if defined(__FreeBSD__)
1329 1.26.2.2 bouyer case SIOCSIFADDR:
1330 1.26.2.2 bouyer case SIOCGIFADDR:
1331 1.26.2.2 bouyer case SIOCSIFMTU:
1332 1.26.2.2 bouyer error = ether_ioctl(ifp, command, data);
1333 1.26.2.2 bouyer break;
1334 1.26.2.2 bouyer #elif defined(__NetBSD__) || defined(__OpenBSD__)
1335 1.26.2.2 bouyer case SIOCSIFADDR:
1336 1.26.2.2 bouyer ifp->if_flags |= IFF_UP;
1337 1.26.2.2 bouyer cue_init(sc);
1338 1.26.2.2 bouyer
1339 1.26.2.2 bouyer switch (ifa->ifa_addr->sa_family) {
1340 1.26.2.2 bouyer #ifdef INET
1341 1.26.2.2 bouyer case AF_INET:
1342 1.26.2.2 bouyer #if defined(__NetBSD__)
1343 1.26.2.2 bouyer arp_ifinit(ifp, ifa);
1344 1.26.2.2 bouyer #else
1345 1.26.2.2 bouyer arp_ifinit(&sc->arpcom, ifa);
1346 1.26.2.2 bouyer #endif
1347 1.26.2.2 bouyer break;
1348 1.26.2.2 bouyer #endif /* INET */
1349 1.26.2.2 bouyer #ifdef NS
1350 1.26.2.2 bouyer case AF_NS:
1351 1.26.2.2 bouyer {
1352 1.26.2.2 bouyer struct ns_addr *ina = &IA_SNS(ifa)->sns_addr;
1353 1.26.2.2 bouyer
1354 1.26.2.2 bouyer if (ns_nullhost(*ina))
1355 1.26.2.2 bouyer ina->x_host = *(union ns_host *)
1356 1.26.2.2 bouyer LLADDR(ifp->if_sadl);
1357 1.26.2.2 bouyer else
1358 1.26.2.2 bouyer memcpy(LLADDR(ifp->if_sadl),
1359 1.26.2.2 bouyer ina->x_host.c_host,
1360 1.26.2.2 bouyer ifp->if_addrlen);
1361 1.26.2.2 bouyer break;
1362 1.26.2.2 bouyer }
1363 1.26.2.2 bouyer #endif /* NS */
1364 1.26.2.2 bouyer }
1365 1.26.2.2 bouyer break;
1366 1.26.2.2 bouyer
1367 1.26.2.2 bouyer case SIOCSIFMTU:
1368 1.26.2.2 bouyer if (ifr->ifr_mtu > ETHERMTU)
1369 1.26.2.2 bouyer error = EINVAL;
1370 1.26.2.2 bouyer else
1371 1.26.2.2 bouyer ifp->if_mtu = ifr->ifr_mtu;
1372 1.26.2.2 bouyer break;
1373 1.26.2.2 bouyer
1374 1.26.2.2 bouyer #endif /* defined(__NetBSD__) || defined(__OpenBSD__) */
1375 1.26.2.2 bouyer
1376 1.26.2.2 bouyer case SIOCSIFFLAGS:
1377 1.26.2.2 bouyer if (ifp->if_flags & IFF_UP) {
1378 1.26.2.2 bouyer if (ifp->if_flags & IFF_RUNNING &&
1379 1.26.2.2 bouyer ifp->if_flags & IFF_PROMISC &&
1380 1.26.2.2 bouyer !(sc->cue_if_flags & IFF_PROMISC)) {
1381 1.26.2.2 bouyer CUE_SETBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
1382 1.26.2.2 bouyer cue_setmulti(sc);
1383 1.26.2.2 bouyer } else if (ifp->if_flags & IFF_RUNNING &&
1384 1.26.2.2 bouyer !(ifp->if_flags & IFF_PROMISC) &&
1385 1.26.2.2 bouyer sc->cue_if_flags & IFF_PROMISC) {
1386 1.26.2.2 bouyer CUE_CLRBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
1387 1.26.2.2 bouyer cue_setmulti(sc);
1388 1.26.2.2 bouyer } else if (!(ifp->if_flags & IFF_RUNNING))
1389 1.26.2.2 bouyer cue_init(sc);
1390 1.26.2.2 bouyer } else {
1391 1.26.2.2 bouyer if (ifp->if_flags & IFF_RUNNING)
1392 1.26.2.2 bouyer cue_stop(sc);
1393 1.26.2.2 bouyer }
1394 1.26.2.2 bouyer sc->cue_if_flags = ifp->if_flags;
1395 1.26.2.2 bouyer error = 0;
1396 1.26.2.2 bouyer break;
1397 1.26.2.2 bouyer case SIOCADDMULTI:
1398 1.26.2.2 bouyer case SIOCDELMULTI:
1399 1.26.2.2 bouyer cue_setmulti(sc);
1400 1.26.2.2 bouyer error = 0;
1401 1.26.2.2 bouyer break;
1402 1.26.2.2 bouyer default:
1403 1.26.2.2 bouyer error = EINVAL;
1404 1.26.2.2 bouyer break;
1405 1.26.2.2 bouyer }
1406 1.26.2.2 bouyer
1407 1.26.2.2 bouyer splx(s);
1408 1.26.2.2 bouyer
1409 1.26.2.2 bouyer return (error);
1410 1.26.2.2 bouyer }
1411 1.26.2.2 bouyer
1412 1.26.2.2 bouyer Static void
1413 1.26.2.2 bouyer cue_watchdog(struct ifnet *ifp)
1414 1.26.2.2 bouyer {
1415 1.26.2.2 bouyer struct cue_softc *sc = ifp->if_softc;
1416 1.26.2.2 bouyer
1417 1.26.2.2 bouyer DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->cue_dev),__FUNCTION__));
1418 1.26.2.2 bouyer
1419 1.26.2.2 bouyer if (sc->cue_dying)
1420 1.26.2.2 bouyer return;
1421 1.26.2.2 bouyer
1422 1.26.2.2 bouyer ifp->if_oerrors++;
1423 1.26.2.2 bouyer printf("%s: watchdog timeout\n", USBDEVNAME(sc->cue_dev));
1424 1.26.2.2 bouyer
1425 1.26.2.2 bouyer /*
1426 1.26.2.2 bouyer * The polling business is a kludge to avoid allowing the
1427 1.26.2.2 bouyer * USB code to call tsleep() in usbd_delay_ms(), which will
1428 1.26.2.2 bouyer * kill us since the watchdog routine is invoked from
1429 1.26.2.2 bouyer * interrupt context.
1430 1.26.2.2 bouyer */
1431 1.26.2.2 bouyer usbd_set_polling(sc->cue_udev, 1);
1432 1.26.2.2 bouyer cue_stop(sc);
1433 1.26.2.2 bouyer cue_init(sc);
1434 1.26.2.2 bouyer usbd_set_polling(sc->cue_udev, 0);
1435 1.26.2.2 bouyer
1436 1.26.2.2 bouyer if (ifp->if_snd.ifq_head != NULL)
1437 1.26.2.2 bouyer cue_start(ifp);
1438 1.26.2.2 bouyer }
1439 1.26.2.2 bouyer
1440 1.26.2.2 bouyer /*
1441 1.26.2.2 bouyer * Stop the adapter and free any mbufs allocated to the
1442 1.26.2.2 bouyer * RX and TX lists.
1443 1.26.2.2 bouyer */
1444 1.26.2.2 bouyer Static void
1445 1.26.2.2 bouyer cue_stop(struct cue_softc *sc)
1446 1.26.2.2 bouyer {
1447 1.26.2.2 bouyer usbd_status err;
1448 1.26.2.2 bouyer struct ifnet *ifp;
1449 1.26.2.2 bouyer int i;
1450 1.26.2.2 bouyer
1451 1.26.2.2 bouyer DPRINTFN(10,("%s: %s: enter\n", USBDEVNAME(sc->cue_dev),__FUNCTION__));
1452 1.26.2.2 bouyer
1453 1.26.2.2 bouyer ifp = GET_IFP(sc);
1454 1.26.2.2 bouyer ifp->if_timer = 0;
1455 1.26.2.2 bouyer
1456 1.26.2.2 bouyer cue_csr_write_1(sc, CUE_ETHCTL, 0);
1457 1.26.2.2 bouyer cue_reset(sc);
1458 1.26.2.2 bouyer usb_uncallout(sc->cue_stat_ch, cue_tick, sc);
1459 1.26.2.2 bouyer
1460 1.26.2.2 bouyer /* Stop transfers. */
1461 1.26.2.2 bouyer if (sc->cue_ep[CUE_ENDPT_RX] != NULL) {
1462 1.26.2.2 bouyer err = usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_RX]);
1463 1.26.2.2 bouyer if (err) {
1464 1.26.2.2 bouyer printf("%s: abort rx pipe failed: %s\n",
1465 1.26.2.2 bouyer USBDEVNAME(sc->cue_dev), usbd_errstr(err));
1466 1.26.2.2 bouyer }
1467 1.26.2.2 bouyer err = usbd_close_pipe(sc->cue_ep[CUE_ENDPT_RX]);
1468 1.26.2.2 bouyer if (err) {
1469 1.26.2.2 bouyer printf("%s: close rx pipe failed: %s\n",
1470 1.26.2.2 bouyer USBDEVNAME(sc->cue_dev), usbd_errstr(err));
1471 1.26.2.2 bouyer }
1472 1.26.2.2 bouyer sc->cue_ep[CUE_ENDPT_RX] = NULL;
1473 1.26.2.2 bouyer }
1474 1.26.2.2 bouyer
1475 1.26.2.2 bouyer if (sc->cue_ep[CUE_ENDPT_TX] != NULL) {
1476 1.26.2.2 bouyer err = usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_TX]);
1477 1.26.2.2 bouyer if (err) {
1478 1.26.2.2 bouyer printf("%s: abort tx pipe failed: %s\n",
1479 1.26.2.2 bouyer USBDEVNAME(sc->cue_dev), usbd_errstr(err));
1480 1.26.2.2 bouyer }
1481 1.26.2.2 bouyer err = usbd_close_pipe(sc->cue_ep[CUE_ENDPT_TX]);
1482 1.26.2.2 bouyer if (err) {
1483 1.26.2.2 bouyer printf("%s: close tx pipe failed: %s\n",
1484 1.26.2.2 bouyer USBDEVNAME(sc->cue_dev), usbd_errstr(err));
1485 1.26.2.2 bouyer }
1486 1.26.2.2 bouyer sc->cue_ep[CUE_ENDPT_TX] = NULL;
1487 1.26.2.2 bouyer }
1488 1.26.2.2 bouyer
1489 1.26.2.2 bouyer if (sc->cue_ep[CUE_ENDPT_INTR] != NULL) {
1490 1.26.2.2 bouyer err = usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_INTR]);
1491 1.26.2.2 bouyer if (err) {
1492 1.26.2.2 bouyer printf("%s: abort intr pipe failed: %s\n",
1493 1.26.2.2 bouyer USBDEVNAME(sc->cue_dev), usbd_errstr(err));
1494 1.26.2.2 bouyer }
1495 1.26.2.2 bouyer err = usbd_close_pipe(sc->cue_ep[CUE_ENDPT_INTR]);
1496 1.26.2.2 bouyer if (err) {
1497 1.26.2.2 bouyer printf("%s: close intr pipe failed: %s\n",
1498 1.26.2.2 bouyer USBDEVNAME(sc->cue_dev), usbd_errstr(err));
1499 1.26.2.2 bouyer }
1500 1.26.2.2 bouyer sc->cue_ep[CUE_ENDPT_INTR] = NULL;
1501 1.26.2.2 bouyer }
1502 1.26.2.2 bouyer
1503 1.26.2.2 bouyer /* Free RX resources. */
1504 1.26.2.2 bouyer for (i = 0; i < CUE_RX_LIST_CNT; i++) {
1505 1.26.2.2 bouyer if (sc->cue_cdata.cue_rx_chain[i].cue_mbuf != NULL) {
1506 1.26.2.2 bouyer m_freem(sc->cue_cdata.cue_rx_chain[i].cue_mbuf);
1507 1.26.2.2 bouyer sc->cue_cdata.cue_rx_chain[i].cue_mbuf = NULL;
1508 1.26.2.2 bouyer }
1509 1.26.2.2 bouyer if (sc->cue_cdata.cue_rx_chain[i].cue_xfer != NULL) {
1510 1.26.2.2 bouyer usbd_free_xfer(sc->cue_cdata.cue_rx_chain[i].cue_xfer);
1511 1.26.2.2 bouyer sc->cue_cdata.cue_rx_chain[i].cue_xfer = NULL;
1512 1.26.2.2 bouyer }
1513 1.26.2.2 bouyer }
1514 1.26.2.2 bouyer
1515 1.26.2.2 bouyer /* Free TX resources. */
1516 1.26.2.2 bouyer for (i = 0; i < CUE_TX_LIST_CNT; i++) {
1517 1.26.2.2 bouyer if (sc->cue_cdata.cue_tx_chain[i].cue_mbuf != NULL) {
1518 1.26.2.2 bouyer m_freem(sc->cue_cdata.cue_tx_chain[i].cue_mbuf);
1519 1.26.2.2 bouyer sc->cue_cdata.cue_tx_chain[i].cue_mbuf = NULL;
1520 1.26.2.2 bouyer }
1521 1.26.2.2 bouyer if (sc->cue_cdata.cue_tx_chain[i].cue_xfer != NULL) {
1522 1.26.2.2 bouyer usbd_free_xfer(sc->cue_cdata.cue_tx_chain[i].cue_xfer);
1523 1.26.2.2 bouyer sc->cue_cdata.cue_tx_chain[i].cue_xfer = NULL;
1524 1.26.2.2 bouyer }
1525 1.26.2.2 bouyer }
1526 1.26.2.2 bouyer
1527 1.26.2.2 bouyer ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
1528 1.26.2.2 bouyer }
1529 1.26.2.2 bouyer
1530 1.26.2.2 bouyer #ifdef __FreeBSD__
1531 1.26.2.2 bouyer /*
1532 1.26.2.2 bouyer * Stop all chip I/O so that the kernel's probe routines don't
1533 1.26.2.2 bouyer * get confused by errant DMAs when rebooting.
1534 1.26.2.2 bouyer */
1535 1.26.2.2 bouyer Static void
1536 1.26.2.2 bouyer cue_shutdown(device_t dev)
1537 1.26.2.2 bouyer {
1538 1.26.2.2 bouyer struct cue_softc *sc;
1539 1.26.2.2 bouyer
1540 1.26.2.2 bouyer sc = device_get_softc(dev);
1541 1.26.2.2 bouyer
1542 1.26.2.2 bouyer cue_reset(sc);
1543 1.26.2.2 bouyer cue_stop(sc);
1544 1.26.2.2 bouyer }
1545 1.26.2.2 bouyer #endif
1546