if_aue.c revision 1.99.10.6 1 1.99.10.4 itohy /* $NetBSD: if_aue.c,v 1.99.10.6 2007/06/25 09:18:56 itohy Exp $ */
2 1.1 augustss /*
3 1.1 augustss * Copyright (c) 1997, 1998, 1999, 2000
4 1.1 augustss * Bill Paul <wpaul (at) ee.columbia.edu>. All rights reserved.
5 1.1 augustss *
6 1.1 augustss * Redistribution and use in source and binary forms, with or without
7 1.1 augustss * modification, are permitted provided that the following conditions
8 1.1 augustss * are met:
9 1.1 augustss * 1. Redistributions of source code must retain the above copyright
10 1.1 augustss * notice, this list of conditions and the following disclaimer.
11 1.1 augustss * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 augustss * notice, this list of conditions and the following disclaimer in the
13 1.1 augustss * documentation and/or other materials provided with the distribution.
14 1.1 augustss * 3. All advertising materials mentioning features or use of this software
15 1.1 augustss * must display the following acknowledgement:
16 1.1 augustss * This product includes software developed by Bill Paul.
17 1.1 augustss * 4. Neither the name of the author nor the names of any co-contributors
18 1.1 augustss * may be used to endorse or promote products derived from this software
19 1.1 augustss * without specific prior written permission.
20 1.1 augustss *
21 1.1 augustss * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
22 1.1 augustss * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 1.1 augustss * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 1.1 augustss * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
25 1.1 augustss * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 1.1 augustss * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 1.1 augustss * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 1.1 augustss * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 1.1 augustss * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 1.1 augustss * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 1.1 augustss * THE POSSIBILITY OF SUCH DAMAGE.
32 1.1 augustss *
33 1.1 augustss * $FreeBSD: src/sys/dev/usb/if_aue.c,v 1.11 2000/01/14 01:36:14 wpaul Exp $
34 1.1 augustss */
35 1.1 augustss
36 1.1 augustss /*
37 1.63 augustss * ADMtek AN986 Pegasus and AN8511 Pegasus II USB to ethernet driver.
38 1.63 augustss * Datasheet is available from http://www.admtek.com.tw.
39 1.1 augustss *
40 1.1 augustss * Written by Bill Paul <wpaul (at) ee.columbia.edu>
41 1.1 augustss * Electrical Engineering Department
42 1.1 augustss * Columbia University, New York City
43 1.1 augustss */
44 1.1 augustss
45 1.1 augustss /*
46 1.1 augustss * The Pegasus chip uses four USB "endpoints" to provide 10/100 ethernet
47 1.1 augustss * support: the control endpoint for reading/writing registers, burst
48 1.1 augustss * read endpoint for packet reception, burst write for packet transmission
49 1.1 augustss * and one for "interrupts." The chip uses the same RX filter scheme
50 1.1 augustss * as the other ADMtek ethernet parts: one perfect filter entry for the
51 1.1 augustss * the station address and a 64-bit multicast hash table. The chip supports
52 1.1 augustss * both MII and HomePNA attachments.
53 1.1 augustss *
54 1.1 augustss * Since the maximum data transfer speed of USB is supposed to be 12Mbps,
55 1.1 augustss * you're never really going to get 100Mbps speeds from this device. I
56 1.1 augustss * think the idea is to allow the device to connect to 10 or 100Mbps
57 1.1 augustss * networks, not necessarily to provide 100Mbps performance. Also, since
58 1.1 augustss * the controller uses an external PHY chip, it's possible that board
59 1.1 augustss * designers might simply choose a 10Mbps PHY.
60 1.1 augustss *
61 1.1 augustss * Registers are accessed using usbd_do_request(). Packet transfers are
62 1.1 augustss * done using usbd_transfer() and friends.
63 1.1 augustss */
64 1.1 augustss
65 1.1 augustss /*
66 1.1 augustss * Ported to NetBSD and somewhat rewritten by Lennart Augustsson.
67 1.1 augustss */
68 1.1 augustss
69 1.1 augustss /*
70 1.1 augustss * TODO:
71 1.1 augustss * better error messages from rxstat
72 1.1 augustss * split out if_auevar.h
73 1.1 augustss * add thread to avoid register reads from interrupt context
74 1.1 augustss * more error checks
75 1.1 augustss * investigate short rx problem
76 1.10 augustss * proper cleanup on errors
77 1.1 augustss */
78 1.68 lukem
79 1.68 lukem #include <sys/cdefs.h>
80 1.99.10.4 itohy __KERNEL_RCSID(0, "$NetBSD: if_aue.c,v 1.99.10.6 2007/06/25 09:18:56 itohy Exp $");
81 1.1 augustss
82 1.35 augustss #if defined(__NetBSD__)
83 1.1 augustss #include "opt_inet.h"
84 1.1 augustss #include "bpfilter.h"
85 1.1 augustss #include "rnd.h"
86 1.35 augustss #elif defined(__OpenBSD__)
87 1.35 augustss #include "bpfilter.h"
88 1.35 augustss #endif /* defined(__OpenBSD__) */
89 1.1 augustss
90 1.1 augustss #include <sys/param.h>
91 1.1 augustss #include <sys/systm.h>
92 1.1 augustss #include <sys/sockio.h>
93 1.56 augustss #include <sys/lock.h>
94 1.1 augustss #include <sys/mbuf.h>
95 1.1 augustss #include <sys/malloc.h>
96 1.1 augustss #include <sys/kernel.h>
97 1.1 augustss #include <sys/socket.h>
98 1.1 augustss
99 1.1 augustss #include <sys/device.h>
100 1.19 augustss #if NRND > 0
101 1.19 augustss #include <sys/rnd.h>
102 1.19 augustss #endif
103 1.1 augustss
104 1.1 augustss #include <net/if.h>
105 1.52 augustss #if defined(__NetBSD__)
106 1.1 augustss #include <net/if_arp.h>
107 1.35 augustss #endif
108 1.1 augustss #include <net/if_dl.h>
109 1.1 augustss #include <net/if_media.h>
110 1.1 augustss
111 1.23 mycroft #define BPF_MTAP(ifp, m) bpf_mtap((ifp)->if_bpf, (m))
112 1.1 augustss
113 1.52 augustss #if NBPFILTER > 0
114 1.1 augustss #include <net/bpf.h>
115 1.1 augustss #endif
116 1.1 augustss
117 1.35 augustss #if defined(__NetBSD__)
118 1.35 augustss #include <net/if_ether.h>
119 1.1 augustss #ifdef INET
120 1.79 augustss #include <netinet/in.h>
121 1.1 augustss #include <netinet/if_inarp.h>
122 1.1 augustss #endif
123 1.35 augustss #endif /* defined(__NetBSD__) */
124 1.35 augustss
125 1.35 augustss #if defined(__OpenBSD__)
126 1.35 augustss #ifdef INET
127 1.35 augustss #include <netinet/in.h>
128 1.35 augustss #include <netinet/in_systm.h>
129 1.35 augustss #include <netinet/in_var.h>
130 1.35 augustss #include <netinet/ip.h>
131 1.35 augustss #include <netinet/if_ether.h>
132 1.35 augustss #endif
133 1.35 augustss #endif /* defined(__OpenBSD__) */
134 1.1 augustss
135 1.1 augustss
136 1.1 augustss #include <dev/mii/mii.h>
137 1.1 augustss #include <dev/mii/miivar.h>
138 1.1 augustss
139 1.1 augustss #include <dev/usb/usb.h>
140 1.1 augustss #include <dev/usb/usbdi.h>
141 1.1 augustss #include <dev/usb/usbdi_util.h>
142 1.1 augustss #include <dev/usb/usbdevs.h>
143 1.99.10.2 itohy #include <dev/usb/usb_ethersubr.h>
144 1.1 augustss
145 1.95 is #if defined(__NetBSD__)
146 1.95 is #include <sys/workqueue.h>
147 1.95 is #endif
148 1.95 is
149 1.1 augustss #include <dev/usb/if_auereg.h>
150 1.1 augustss
151 1.1 augustss #ifdef AUE_DEBUG
152 1.1 augustss #define DPRINTF(x) if (auedebug) logprintf x
153 1.1 augustss #define DPRINTFN(n,x) if (auedebug >= (n)) logprintf x
154 1.8 augustss int auedebug = 0;
155 1.1 augustss #else
156 1.1 augustss #define DPRINTF(x)
157 1.1 augustss #define DPRINTFN(n,x)
158 1.1 augustss #endif
159 1.1 augustss
160 1.1 augustss /*
161 1.10 augustss * Various supported device vendors/products.
162 1.1 augustss */
163 1.41 augustss struct aue_type {
164 1.71 augustss struct usb_devno aue_dev;
165 1.62 augustss u_int16_t aue_flags;
166 1.62 augustss #define LSYS 0x0001 /* use Linksys reset */
167 1.62 augustss #define PNA 0x0002 /* has Home PNA */
168 1.62 augustss #define PII 0x0004 /* Pegasus II chip */
169 1.41 augustss };
170 1.41 augustss
171 1.51 jdolecek Static const struct aue_type aue_devs[] = {
172 1.87 augustss {{ USB_VENDOR_3COM, USB_PRODUCT_3COM_3C460B}, PII },
173 1.71 augustss {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX1}, PNA|PII },
174 1.71 augustss {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX2}, PII },
175 1.72 augustss {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_UFE1000}, LSYS },
176 1.71 augustss {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX4}, PNA },
177 1.71 augustss {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX5}, PNA },
178 1.71 augustss {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX6}, PII },
179 1.71 augustss {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX7}, PII },
180 1.71 augustss {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX8}, PII },
181 1.71 augustss {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX9}, PNA },
182 1.71 augustss {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX10}, 0 },
183 1.71 augustss {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_DSB650TX_PNA}, 0 },
184 1.71 augustss {{ USB_VENDOR_ACCTON, USB_PRODUCT_ACCTON_USB320_EC}, 0 },
185 1.72 augustss {{ USB_VENDOR_ACCTON, USB_PRODUCT_ACCTON_SS1001}, PII },
186 1.71 augustss {{ USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUS}, PNA },
187 1.71 augustss {{ USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUSII}, PII },
188 1.87 augustss {{ USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUSII_2}, PII },
189 1.93 christos {{ USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUSII_3}, PII },
190 1.99.10.6 itohy {{ USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUSII_4}, PII },
191 1.89 rjs {{ USB_VENDOR_AEI, USB_PRODUCT_AEI_USBTOLAN}, PII },
192 1.80 matt {{ USB_VENDOR_BELKIN, USB_PRODUCT_BELKIN_USB2LAN}, PII },
193 1.71 augustss {{ USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USB100}, 0 },
194 1.71 augustss {{ USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USBLP100}, PNA },
195 1.71 augustss {{ USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USBEL100}, 0 },
196 1.71 augustss {{ USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USBE100}, PII },
197 1.84 schmonz {{ USB_VENDOR_COMPAQ, USB_PRODUCT_COMPAQ_HNE200}, PII },
198 1.71 augustss {{ USB_VENDOR_COREGA, USB_PRODUCT_COREGA_FETHER_USB_TX}, 0 },
199 1.71 augustss {{ USB_VENDOR_COREGA, USB_PRODUCT_COREGA_FETHER_USB_TXS},PII },
200 1.71 augustss {{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX4}, LSYS|PII },
201 1.71 augustss {{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX1}, LSYS },
202 1.71 augustss {{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX}, LSYS },
203 1.71 augustss {{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX_PNA}, PNA },
204 1.71 augustss {{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX3}, LSYS|PII },
205 1.71 augustss {{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX2}, LSYS|PII },
206 1.71 augustss {{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650}, 0 },
207 1.99.10.6 itohy {{ USB_VENDOR_ELCON, USB_PRODUCT_ELCON_PLAN}, PNA|PII },
208 1.99.10.6 itohy {{ USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSB20}, PII },
209 1.71 augustss {{ USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX0}, 0 },
210 1.82 shiba {{ USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX1}, LSYS },
211 1.71 augustss {{ USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX2}, 0 },
212 1.82 shiba {{ USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX3}, LSYS },
213 1.73 gehenna {{ USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBLTX}, PII },
214 1.71 augustss {{ USB_VENDOR_ELSA, USB_PRODUCT_ELSA_USB2ETHERNET}, 0 },
215 1.99.10.6 itohy {{ USB_VENDOR_GIGABYTE, USB_PRODUCT_GIGABYTE_GNBR402W}, 0 },
216 1.83 augustss {{ USB_VENDOR_HAWKING, USB_PRODUCT_HAWKING_UF100}, PII },
217 1.85 augustss {{ USB_VENDOR_HP, USB_PRODUCT_HP_HN210E}, PII },
218 1.71 augustss {{ USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBETTX}, 0 },
219 1.71 augustss {{ USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBETTXS}, PII },
220 1.71 augustss {{ USB_VENDOR_KINGSTON, USB_PRODUCT_KINGSTON_KNU101TX}, 0 },
221 1.71 augustss {{ USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10TX1}, LSYS|PII },
222 1.71 augustss {{ USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10T}, LSYS },
223 1.71 augustss {{ USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB100TX}, LSYS },
224 1.71 augustss {{ USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB100H1}, LSYS|PNA },
225 1.71 augustss {{ USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10TA}, LSYS },
226 1.71 augustss {{ USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10TX2}, LSYS|PII },
227 1.99.10.6 itohy {{ USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUATX1}, 0 },
228 1.99.10.6 itohy {{ USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUATX5}, 0 },
229 1.99.10.6 itohy {{ USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUA2TX5}, PII },
230 1.83 augustss {{ USB_VENDOR_MICROSOFT, USB_PRODUCT_MICROSOFT_MN110}, PII },
231 1.99.10.6 itohy {{ USB_VENDOR_MOBILITY, USB_PRODUCT_MOBILITY_EASIDOCK}, 0 },
232 1.99.10.6 itohy {{ USB_VENDOR_NETGEAR, USB_PRODUCT_NETGEAR_FA101}, PII },
233 1.75 christos {{ USB_VENDOR_SIEMENS, USB_PRODUCT_SIEMENS_SPEEDSTREAM}, PII },
234 1.99.10.6 itohy {{ USB_VENDOR_SIIG2, USB_PRODUCT_SIIG2_USBTOETHER}, PII },
235 1.71 augustss {{ USB_VENDOR_SMARTBRIDGES, USB_PRODUCT_SMARTBRIDGES_SMARTNIC},PII },
236 1.71 augustss {{ USB_VENDOR_SMC, USB_PRODUCT_SMC_2202USB}, 0 },
237 1.77 rh {{ USB_VENDOR_SMC, USB_PRODUCT_SMC_2206USB}, PII },
238 1.71 augustss {{ USB_VENDOR_SOHOWARE, USB_PRODUCT_SOHOWARE_NUB100}, 0 },
239 1.99.10.6 itohy {{ USB_VENDOR_SOHOWARE, USB_PRODUCT_SOHOWARE_NUB110}, PII },
240 1.1 augustss };
241 1.91 christos #define aue_lookup(v, p) ((const struct aue_type *)usb_lookup(aue_devs, v, p))
242 1.1 augustss
243 1.1 augustss USB_DECLARE_DRIVER(aue);
244 1.1 augustss
245 1.95 is #if defined(__NetBSD__)
246 1.95 is Static void aue_multiwork(struct work *wkp, void *arg);
247 1.95 is #endif
248 1.95 is
249 1.64 augustss Static void aue_reset_pegasus_II(struct aue_softc *sc);
250 1.42 augustss Static int aue_send(struct aue_softc *, struct mbuf *, int);
251 1.42 augustss Static void aue_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
252 1.42 augustss Static void aue_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
253 1.42 augustss Static void aue_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
254 1.42 augustss Static void aue_tick(void *);
255 1.56 augustss Static void aue_tick_task(void *);
256 1.42 augustss Static void aue_start(struct ifnet *);
257 1.99.10.3 itohy Static int aue_ioctl(struct ifnet *, u_long, usb_ioctlarg_t);
258 1.99.10.2 itohy Static int aue_init(struct ifnet *);
259 1.99.10.2 itohy Static void aue_stop(struct ifnet *, int);
260 1.42 augustss Static void aue_watchdog(struct ifnet *);
261 1.42 augustss Static int aue_openpipes(struct aue_softc *);
262 1.42 augustss Static int aue_ifmedia_upd(struct ifnet *);
263 1.42 augustss Static void aue_ifmedia_sts(struct ifnet *, struct ifmediareq *);
264 1.42 augustss
265 1.42 augustss Static int aue_eeprom_getword(struct aue_softc *, int);
266 1.42 augustss Static void aue_read_mac(struct aue_softc *, u_char *);
267 1.42 augustss Static int aue_miibus_readreg(device_ptr_t, int, int);
268 1.42 augustss Static void aue_miibus_writereg(device_ptr_t, int, int, int);
269 1.42 augustss Static void aue_miibus_statchg(device_ptr_t);
270 1.1 augustss
271 1.56 augustss Static void aue_lock_mii(struct aue_softc *);
272 1.56 augustss Static void aue_unlock_mii(struct aue_softc *);
273 1.56 augustss
274 1.42 augustss Static void aue_setmulti(struct aue_softc *);
275 1.99.10.3 itohy Static u_int32_t aue_crc(u_int8_t *);
276 1.42 augustss Static void aue_reset(struct aue_softc *);
277 1.42 augustss
278 1.42 augustss Static int aue_csr_read_1(struct aue_softc *, int);
279 1.42 augustss Static int aue_csr_write_1(struct aue_softc *, int, int);
280 1.42 augustss Static int aue_csr_read_2(struct aue_softc *, int);
281 1.42 augustss Static int aue_csr_write_2(struct aue_softc *, int, int);
282 1.1 augustss
283 1.1 augustss #define AUE_SETBIT(sc, reg, x) \
284 1.29 augustss aue_csr_write_1(sc, reg, aue_csr_read_1(sc, reg) | (x))
285 1.1 augustss
286 1.1 augustss #define AUE_CLRBIT(sc, reg, x) \
287 1.29 augustss aue_csr_write_1(sc, reg, aue_csr_read_1(sc, reg) & ~(x))
288 1.1 augustss
289 1.34 augustss Static int
290 1.42 augustss aue_csr_read_1(struct aue_softc *sc, int reg)
291 1.1 augustss {
292 1.1 augustss usb_device_request_t req;
293 1.1 augustss usbd_status err;
294 1.1 augustss uByte val = 0;
295 1.1 augustss
296 1.30 augustss if (sc->aue_dying)
297 1.30 augustss return (0);
298 1.30 augustss
299 1.1 augustss req.bmRequestType = UT_READ_VENDOR_DEVICE;
300 1.1 augustss req.bRequest = AUE_UR_READREG;
301 1.1 augustss USETW(req.wValue, 0);
302 1.1 augustss USETW(req.wIndex, reg);
303 1.1 augustss USETW(req.wLength, 1);
304 1.1 augustss
305 1.56 augustss err = usbd_do_request(sc->aue_udev, &req, &val);
306 1.1 augustss
307 1.29 augustss if (err) {
308 1.29 augustss DPRINTF(("%s: aue_csr_read_1: reg=0x%x err=%s\n",
309 1.29 augustss USBDEVNAME(sc->aue_dev), reg, usbd_errstr(err)));
310 1.1 augustss return (0);
311 1.29 augustss }
312 1.1 augustss
313 1.1 augustss return (val);
314 1.1 augustss }
315 1.1 augustss
316 1.34 augustss Static int
317 1.42 augustss aue_csr_read_2(struct aue_softc *sc, int reg)
318 1.1 augustss {
319 1.1 augustss usb_device_request_t req;
320 1.1 augustss usbd_status err;
321 1.1 augustss uWord val;
322 1.1 augustss
323 1.30 augustss if (sc->aue_dying)
324 1.30 augustss return (0);
325 1.30 augustss
326 1.1 augustss req.bmRequestType = UT_READ_VENDOR_DEVICE;
327 1.1 augustss req.bRequest = AUE_UR_READREG;
328 1.1 augustss USETW(req.wValue, 0);
329 1.1 augustss USETW(req.wIndex, reg);
330 1.1 augustss USETW(req.wLength, 2);
331 1.1 augustss
332 1.56 augustss err = usbd_do_request(sc->aue_udev, &req, &val);
333 1.1 augustss
334 1.29 augustss if (err) {
335 1.29 augustss DPRINTF(("%s: aue_csr_read_2: reg=0x%x err=%s\n",
336 1.29 augustss USBDEVNAME(sc->aue_dev), reg, usbd_errstr(err)));
337 1.1 augustss return (0);
338 1.29 augustss }
339 1.1 augustss
340 1.1 augustss return (UGETW(val));
341 1.1 augustss }
342 1.1 augustss
343 1.34 augustss Static int
344 1.42 augustss aue_csr_write_1(struct aue_softc *sc, int reg, int aval)
345 1.1 augustss {
346 1.1 augustss usb_device_request_t req;
347 1.1 augustss usbd_status err;
348 1.1 augustss uByte val;
349 1.1 augustss
350 1.30 augustss if (sc->aue_dying)
351 1.30 augustss return (0);
352 1.30 augustss
353 1.1 augustss val = aval;
354 1.1 augustss req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
355 1.1 augustss req.bRequest = AUE_UR_WRITEREG;
356 1.1 augustss USETW(req.wValue, val);
357 1.1 augustss USETW(req.wIndex, reg);
358 1.1 augustss USETW(req.wLength, 1);
359 1.1 augustss
360 1.56 augustss err = usbd_do_request(sc->aue_udev, &req, &val);
361 1.1 augustss
362 1.29 augustss if (err) {
363 1.29 augustss DPRINTF(("%s: aue_csr_write_1: reg=0x%x err=%s\n",
364 1.29 augustss USBDEVNAME(sc->aue_dev), reg, usbd_errstr(err)));
365 1.1 augustss return (-1);
366 1.29 augustss }
367 1.1 augustss
368 1.1 augustss return (0);
369 1.1 augustss }
370 1.1 augustss
371 1.34 augustss Static int
372 1.42 augustss aue_csr_write_2(struct aue_softc *sc, int reg, int aval)
373 1.1 augustss {
374 1.1 augustss usb_device_request_t req;
375 1.1 augustss usbd_status err;
376 1.1 augustss uWord val;
377 1.30 augustss
378 1.30 augustss if (sc->aue_dying)
379 1.30 augustss return (0);
380 1.1 augustss
381 1.1 augustss USETW(val, aval);
382 1.1 augustss req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
383 1.1 augustss req.bRequest = AUE_UR_WRITEREG;
384 1.1 augustss USETW(req.wValue, aval);
385 1.1 augustss USETW(req.wIndex, reg);
386 1.1 augustss USETW(req.wLength, 2);
387 1.1 augustss
388 1.56 augustss err = usbd_do_request(sc->aue_udev, &req, &val);
389 1.1 augustss
390 1.29 augustss if (err) {
391 1.29 augustss DPRINTF(("%s: aue_csr_write_2: reg=0x%x err=%s\n",
392 1.29 augustss USBDEVNAME(sc->aue_dev), reg, usbd_errstr(err)));
393 1.1 augustss return (-1);
394 1.29 augustss }
395 1.1 augustss
396 1.1 augustss return (0);
397 1.1 augustss }
398 1.1 augustss
399 1.1 augustss /*
400 1.1 augustss * Read a word of data stored in the EEPROM at address 'addr.'
401 1.1 augustss */
402 1.34 augustss Static int
403 1.42 augustss aue_eeprom_getword(struct aue_softc *sc, int addr)
404 1.1 augustss {
405 1.1 augustss int i;
406 1.1 augustss
407 1.29 augustss aue_csr_write_1(sc, AUE_EE_REG, addr);
408 1.29 augustss aue_csr_write_1(sc, AUE_EE_CTL, AUE_EECTL_READ);
409 1.1 augustss
410 1.1 augustss for (i = 0; i < AUE_TIMEOUT; i++) {
411 1.29 augustss if (aue_csr_read_1(sc, AUE_EE_CTL) & AUE_EECTL_DONE)
412 1.1 augustss break;
413 1.1 augustss }
414 1.1 augustss
415 1.1 augustss if (i == AUE_TIMEOUT) {
416 1.1 augustss printf("%s: EEPROM read timed out\n",
417 1.1 augustss USBDEVNAME(sc->aue_dev));
418 1.1 augustss }
419 1.1 augustss
420 1.29 augustss return (aue_csr_read_2(sc, AUE_EE_DATA));
421 1.1 augustss }
422 1.1 augustss
423 1.1 augustss /*
424 1.1 augustss * Read the MAC from the EEPROM. It's at offset 0.
425 1.1 augustss */
426 1.34 augustss Static void
427 1.42 augustss aue_read_mac(struct aue_softc *sc, u_char *dest)
428 1.1 augustss {
429 1.1 augustss int i;
430 1.1 augustss int off = 0;
431 1.1 augustss int word;
432 1.1 augustss
433 1.78 augustss DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __func__));
434 1.1 augustss
435 1.1 augustss for (i = 0; i < 3; i++) {
436 1.1 augustss word = aue_eeprom_getword(sc, off + i);
437 1.1 augustss dest[2 * i] = (u_char)word;
438 1.1 augustss dest[2 * i + 1] = (u_char)(word >> 8);
439 1.1 augustss }
440 1.1 augustss }
441 1.1 augustss
442 1.56 augustss /* Get exclusive access to the MII registers */
443 1.56 augustss Static void
444 1.56 augustss aue_lock_mii(struct aue_softc *sc)
445 1.56 augustss {
446 1.67 augustss sc->aue_refcnt++;
447 1.56 augustss lockmgr(&sc->aue_mii_lock, LK_EXCLUSIVE, NULL);
448 1.56 augustss }
449 1.56 augustss
450 1.56 augustss Static void
451 1.56 augustss aue_unlock_mii(struct aue_softc *sc)
452 1.56 augustss {
453 1.56 augustss lockmgr(&sc->aue_mii_lock, LK_RELEASE, NULL);
454 1.67 augustss if (--sc->aue_refcnt < 0)
455 1.67 augustss usb_detach_wakeup(USBDEV(sc->aue_dev));
456 1.56 augustss }
457 1.56 augustss
458 1.34 augustss Static int
459 1.42 augustss aue_miibus_readreg(device_ptr_t dev, int phy, int reg)
460 1.1 augustss {
461 1.1 augustss struct aue_softc *sc = USBGETSOFTC(dev);
462 1.1 augustss int i;
463 1.1 augustss u_int16_t val;
464 1.1 augustss
465 1.69 augustss if (sc->aue_dying) {
466 1.69 augustss #ifdef DIAGNOSTIC
467 1.69 augustss printf("%s: dying\n", USBDEVNAME(sc->aue_dev));
468 1.69 augustss #endif
469 1.69 augustss return 0;
470 1.69 augustss }
471 1.69 augustss
472 1.55 augustss #if 0
473 1.1 augustss /*
474 1.1 augustss * The Am79C901 HomePNA PHY actually contains
475 1.1 augustss * two transceivers: a 1Mbps HomePNA PHY and a
476 1.1 augustss * 10Mbps full/half duplex ethernet PHY with
477 1.1 augustss * NWAY autoneg. However in the ADMtek adapter,
478 1.1 augustss * only the 1Mbps PHY is actually connected to
479 1.1 augustss * anything, so we ignore the 10Mbps one. It
480 1.1 augustss * happens to be configured for MII address 3,
481 1.1 augustss * so we filter that out.
482 1.1 augustss */
483 1.1 augustss if (sc->aue_vendor == USB_VENDOR_ADMTEK &&
484 1.1 augustss sc->aue_product == USB_PRODUCT_ADMTEK_PEGASUS) {
485 1.52 augustss if (phy == 3)
486 1.1 augustss return (0);
487 1.1 augustss }
488 1.55 augustss #endif
489 1.1 augustss
490 1.56 augustss aue_lock_mii(sc);
491 1.29 augustss aue_csr_write_1(sc, AUE_PHY_ADDR, phy);
492 1.29 augustss aue_csr_write_1(sc, AUE_PHY_CTL, reg | AUE_PHYCTL_READ);
493 1.1 augustss
494 1.1 augustss for (i = 0; i < AUE_TIMEOUT; i++) {
495 1.29 augustss if (aue_csr_read_1(sc, AUE_PHY_CTL) & AUE_PHYCTL_DONE)
496 1.1 augustss break;
497 1.1 augustss }
498 1.1 augustss
499 1.1 augustss if (i == AUE_TIMEOUT) {
500 1.52 augustss printf("%s: MII read timed out\n", USBDEVNAME(sc->aue_dev));
501 1.1 augustss }
502 1.1 augustss
503 1.29 augustss val = aue_csr_read_2(sc, AUE_PHY_DATA);
504 1.1 augustss
505 1.1 augustss DPRINTFN(11,("%s: %s: phy=%d reg=%d => 0x%04x\n",
506 1.78 augustss USBDEVNAME(sc->aue_dev), __func__, phy, reg, val));
507 1.1 augustss
508 1.56 augustss aue_unlock_mii(sc);
509 1.1 augustss return (val);
510 1.1 augustss }
511 1.1 augustss
512 1.34 augustss Static void
513 1.42 augustss aue_miibus_writereg(device_ptr_t dev, int phy, int reg, int data)
514 1.1 augustss {
515 1.1 augustss struct aue_softc *sc = USBGETSOFTC(dev);
516 1.1 augustss int i;
517 1.1 augustss
518 1.52 augustss #if 0
519 1.1 augustss if (sc->aue_vendor == USB_VENDOR_ADMTEK &&
520 1.1 augustss sc->aue_product == USB_PRODUCT_ADMTEK_PEGASUS) {
521 1.1 augustss if (phy == 3)
522 1.1 augustss return;
523 1.1 augustss }
524 1.52 augustss #endif
525 1.1 augustss
526 1.1 augustss DPRINTFN(11,("%s: %s: phy=%d reg=%d data=0x%04x\n",
527 1.78 augustss USBDEVNAME(sc->aue_dev), __func__, phy, reg, data));
528 1.1 augustss
529 1.56 augustss aue_lock_mii(sc);
530 1.29 augustss aue_csr_write_2(sc, AUE_PHY_DATA, data);
531 1.29 augustss aue_csr_write_1(sc, AUE_PHY_ADDR, phy);
532 1.29 augustss aue_csr_write_1(sc, AUE_PHY_CTL, reg | AUE_PHYCTL_WRITE);
533 1.1 augustss
534 1.1 augustss for (i = 0; i < AUE_TIMEOUT; i++) {
535 1.29 augustss if (aue_csr_read_1(sc, AUE_PHY_CTL) & AUE_PHYCTL_DONE)
536 1.1 augustss break;
537 1.1 augustss }
538 1.1 augustss
539 1.1 augustss if (i == AUE_TIMEOUT) {
540 1.1 augustss printf("%s: MII read timed out\n",
541 1.1 augustss USBDEVNAME(sc->aue_dev));
542 1.1 augustss }
543 1.56 augustss aue_unlock_mii(sc);
544 1.1 augustss }
545 1.1 augustss
546 1.34 augustss Static void
547 1.42 augustss aue_miibus_statchg(device_ptr_t dev)
548 1.1 augustss {
549 1.1 augustss struct aue_softc *sc = USBGETSOFTC(dev);
550 1.1 augustss struct mii_data *mii = GET_MII(sc);
551 1.1 augustss
552 1.78 augustss DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __func__));
553 1.1 augustss
554 1.56 augustss aue_lock_mii(sc);
555 1.1 augustss AUE_CLRBIT(sc, AUE_CTL0, AUE_CTL0_RX_ENB | AUE_CTL0_TX_ENB);
556 1.1 augustss
557 1.1 augustss if (IFM_SUBTYPE(mii->mii_media_active) == IFM_100_TX) {
558 1.1 augustss AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_SPEEDSEL);
559 1.1 augustss } else {
560 1.1 augustss AUE_CLRBIT(sc, AUE_CTL1, AUE_CTL1_SPEEDSEL);
561 1.1 augustss }
562 1.1 augustss
563 1.1 augustss if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX)
564 1.1 augustss AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_DUPLEX);
565 1.1 augustss else
566 1.1 augustss AUE_CLRBIT(sc, AUE_CTL1, AUE_CTL1_DUPLEX);
567 1.1 augustss
568 1.1 augustss AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_RX_ENB | AUE_CTL0_TX_ENB);
569 1.56 augustss aue_unlock_mii(sc);
570 1.1 augustss
571 1.2 augustss /*
572 1.2 augustss * Set the LED modes on the LinkSys adapter.
573 1.2 augustss * This turns on the 'dual link LED' bin in the auxmode
574 1.2 augustss * register of the Broadcom PHY.
575 1.2 augustss */
576 1.69 augustss if (!sc->aue_dying && (sc->aue_flags & LSYS)) {
577 1.41 augustss u_int16_t auxmode;
578 1.2 augustss auxmode = aue_miibus_readreg(dev, 0, 0x1b);
579 1.2 augustss aue_miibus_writereg(dev, 0, 0x1b, auxmode | 0x04);
580 1.1 augustss }
581 1.78 augustss DPRINTFN(5,("%s: %s: exit\n", USBDEVNAME(sc->aue_dev), __func__));
582 1.1 augustss }
583 1.1 augustss
584 1.1 augustss #define AUE_POLY 0xEDB88320
585 1.1 augustss #define AUE_BITS 6
586 1.1 augustss
587 1.79 augustss Static u_int32_t
588 1.99.10.3 itohy aue_crc(u_int8_t *addr)
589 1.1 augustss {
590 1.1 augustss u_int32_t idx, bit, data, crc;
591 1.1 augustss
592 1.1 augustss /* Compute CRC for the address value. */
593 1.1 augustss crc = 0xFFFFFFFF; /* initial value */
594 1.1 augustss
595 1.1 augustss for (idx = 0; idx < 6; idx++) {
596 1.1 augustss for (data = *addr++, bit = 0; bit < 8; bit++, data >>= 1)
597 1.1 augustss crc = (crc >> 1) ^ (((crc ^ data) & 1) ? AUE_POLY : 0);
598 1.1 augustss }
599 1.1 augustss
600 1.1 augustss return (crc & ((1 << AUE_BITS) - 1));
601 1.1 augustss }
602 1.1 augustss
603 1.34 augustss Static void
604 1.42 augustss aue_setmulti(struct aue_softc *sc)
605 1.1 augustss {
606 1.1 augustss struct ifnet *ifp;
607 1.1 augustss struct ether_multi *enm;
608 1.1 augustss struct ether_multistep step;
609 1.1 augustss u_int32_t h = 0, i;
610 1.1 augustss
611 1.78 augustss DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __func__));
612 1.1 augustss
613 1.1 augustss ifp = GET_IFP(sc);
614 1.1 augustss
615 1.54 enami if (ifp->if_flags & IFF_PROMISC) {
616 1.54 enami allmulti:
617 1.54 enami ifp->if_flags |= IFF_ALLMULTI;
618 1.1 augustss AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_ALLMULTI);
619 1.1 augustss return;
620 1.1 augustss }
621 1.1 augustss
622 1.1 augustss AUE_CLRBIT(sc, AUE_CTL0, AUE_CTL0_ALLMULTI);
623 1.1 augustss
624 1.1 augustss /* first, zot all the existing hash bits */
625 1.1 augustss for (i = 0; i < 8; i++)
626 1.29 augustss aue_csr_write_1(sc, AUE_MAR0 + i, 0);
627 1.1 augustss
628 1.1 augustss /* now program new ones */
629 1.35 augustss #if defined(__NetBSD__)
630 1.1 augustss ETHER_FIRST_MULTI(step, &sc->aue_ec, enm);
631 1.35 augustss #else
632 1.35 augustss ETHER_FIRST_MULTI(step, &sc->arpcom, enm);
633 1.35 augustss #endif
634 1.1 augustss while (enm != NULL) {
635 1.1 augustss if (memcmp(enm->enm_addrlo,
636 1.54 enami enm->enm_addrhi, ETHER_ADDR_LEN) != 0)
637 1.54 enami goto allmulti;
638 1.54 enami
639 1.1 augustss h = aue_crc(enm->enm_addrlo);
640 1.43 itojun AUE_SETBIT(sc, AUE_MAR + (h >> 3), 1 << (h & 0x7));
641 1.1 augustss ETHER_NEXT_MULTI(step, enm);
642 1.1 augustss }
643 1.54 enami
644 1.54 enami ifp->if_flags &= ~IFF_ALLMULTI;
645 1.1 augustss }
646 1.1 augustss
647 1.34 augustss Static void
648 1.63 augustss aue_reset_pegasus_II(struct aue_softc *sc)
649 1.63 augustss {
650 1.63 augustss /* Magic constants taken from Linux driver. */
651 1.63 augustss aue_csr_write_1(sc, AUE_REG_1D, 0);
652 1.63 augustss aue_csr_write_1(sc, AUE_REG_7B, 2);
653 1.63 augustss #if 0
654 1.63 augustss if ((sc->aue_flags & HAS_HOME_PNA) && mii_mode)
655 1.63 augustss aue_csr_write_1(sc, AUE_REG_81, 6);
656 1.63 augustss else
657 1.63 augustss #endif
658 1.63 augustss aue_csr_write_1(sc, AUE_REG_81, 2);
659 1.63 augustss }
660 1.63 augustss
661 1.63 augustss Static void
662 1.42 augustss aue_reset(struct aue_softc *sc)
663 1.1 augustss {
664 1.1 augustss int i;
665 1.1 augustss
666 1.78 augustss DPRINTFN(2,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __func__));
667 1.1 augustss
668 1.1 augustss AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_RESETMAC);
669 1.1 augustss
670 1.1 augustss for (i = 0; i < AUE_TIMEOUT; i++) {
671 1.29 augustss if (!(aue_csr_read_1(sc, AUE_CTL1) & AUE_CTL1_RESETMAC))
672 1.1 augustss break;
673 1.1 augustss }
674 1.1 augustss
675 1.1 augustss if (i == AUE_TIMEOUT)
676 1.1 augustss printf("%s: reset failed\n", USBDEVNAME(sc->aue_dev));
677 1.1 augustss
678 1.72 augustss #if 0
679 1.72 augustss /* XXX what is mii_mode supposed to be */
680 1.72 augustss if (sc->aue_mii_mode && (sc->aue_flags & PNA))
681 1.72 augustss aue_csr_write_1(sc, AUE_GPIO1, 0x34);
682 1.72 augustss else
683 1.72 augustss aue_csr_write_1(sc, AUE_GPIO1, 0x26);
684 1.72 augustss #endif
685 1.72 augustss
686 1.1 augustss /*
687 1.1 augustss * The PHY(s) attached to the Pegasus chip may be held
688 1.1 augustss * in reset until we flip on the GPIO outputs. Make sure
689 1.1 augustss * to set the GPIO pins high so that the PHY(s) will
690 1.1 augustss * be enabled.
691 1.1 augustss *
692 1.1 augustss * Note: We force all of the GPIO pins low first, *then*
693 1.1 augustss * enable the ones we want.
694 1.99.10.6 itohy */
695 1.62 augustss if (sc->aue_flags & LSYS) {
696 1.72 augustss /* Grrr. LinkSys has to be different from everyone else. */
697 1.79 augustss aue_csr_write_1(sc, AUE_GPIO0,
698 1.29 augustss AUE_GPIO_SEL0 | AUE_GPIO_SEL1);
699 1.72 augustss } else {
700 1.79 augustss aue_csr_write_1(sc, AUE_GPIO0,
701 1.72 augustss AUE_GPIO_OUT0 | AUE_GPIO_SEL0);
702 1.1 augustss }
703 1.99.10.6 itohy aue_csr_write_1(sc, AUE_GPIO0,
704 1.72 augustss AUE_GPIO_OUT0 | AUE_GPIO_SEL0 | AUE_GPIO_SEL1);
705 1.63 augustss
706 1.63 augustss if (sc->aue_flags & PII)
707 1.63 augustss aue_reset_pegasus_II(sc);
708 1.1 augustss
709 1.1 augustss /* Wait a little while for the chip to get its brains in order. */
710 1.29 augustss delay(10000); /* XXX */
711 1.41 augustss }
712 1.41 augustss
713 1.1 augustss /*
714 1.1 augustss * Probe for a Pegasus chip.
715 1.1 augustss */
716 1.1 augustss USB_MATCH(aue)
717 1.1 augustss {
718 1.1 augustss USB_MATCH_START(aue, uaa);
719 1.1 augustss
720 1.99.10.4 itohy #ifndef USB_USE_IFATTACH
721 1.1 augustss if (uaa->iface != NULL)
722 1.1 augustss return (UMATCH_NONE);
723 1.99.10.4 itohy #endif /* USB_USE_IFATTACH */
724 1.1 augustss
725 1.41 augustss return (aue_lookup(uaa->vendor, uaa->product) != NULL ?
726 1.41 augustss UMATCH_VENDOR_PRODUCT : UMATCH_NONE);
727 1.1 augustss }
728 1.1 augustss
729 1.1 augustss /*
730 1.1 augustss * Attach the interface. Allocate softc structures, do ifmedia
731 1.1 augustss * setup and ethernet/BPF attach.
732 1.1 augustss */
733 1.1 augustss USB_ATTACH(aue)
734 1.1 augustss {
735 1.1 augustss USB_ATTACH_START(aue, sc, uaa);
736 1.90 augustss char *devinfop;
737 1.1 augustss int s;
738 1.1 augustss u_char eaddr[ETHER_ADDR_LEN];
739 1.1 augustss struct ifnet *ifp;
740 1.1 augustss struct mii_data *mii;
741 1.1 augustss usbd_device_handle dev = uaa->device;
742 1.1 augustss usbd_interface_handle iface;
743 1.10 augustss usbd_status err;
744 1.1 augustss usb_interface_descriptor_t *id;
745 1.1 augustss usb_endpoint_descriptor_t *ed;
746 1.1 augustss int i;
747 1.1 augustss
748 1.10 augustss DPRINTFN(5,(" : aue_attach: sc=%p", sc));
749 1.1 augustss
750 1.90 augustss devinfop = usbd_devinfo_alloc(uaa->device, 0);
751 1.1 augustss USB_ATTACH_SETUP;
752 1.90 augustss printf("%s: %s\n", USBDEVNAME(sc->aue_dev), devinfop);
753 1.90 augustss usbd_devinfo_free(devinfop);
754 1.1 augustss
755 1.47 augustss err = usbd_set_config_no(dev, AUE_CONFIG_NO, 1);
756 1.1 augustss if (err) {
757 1.1 augustss printf("%s: setting config no failed\n",
758 1.1 augustss USBDEVNAME(sc->aue_dev));
759 1.1 augustss USB_ATTACH_ERROR_RETURN;
760 1.1 augustss }
761 1.1 augustss
762 1.56 augustss usb_init_task(&sc->aue_tick_task, aue_tick_task, sc);
763 1.56 augustss usb_init_task(&sc->aue_stop_task, (void (*)(void *))aue_stop, sc);
764 1.56 augustss lockinit(&sc->aue_mii_lock, PZERO, "auemii", 0, 0);
765 1.56 augustss
766 1.1 augustss err = usbd_device2interface_handle(dev, AUE_IFACE_IDX, &iface);
767 1.1 augustss if (err) {
768 1.1 augustss printf("%s: getting interface handle failed\n",
769 1.1 augustss USBDEVNAME(sc->aue_dev));
770 1.1 augustss USB_ATTACH_ERROR_RETURN;
771 1.1 augustss }
772 1.95 is #if defined(__NetBSD__)
773 1.96 is err = workqueue_create(&sc->wqp, USBDEVNAME(sc->aue_dev),
774 1.95 is aue_multiwork, sc, 0, IPL_NET, 0);
775 1.41 augustss
776 1.95 is if (err) {
777 1.95 is printf("%s: creating multicast configuration work queue\n",
778 1.95 is USBDEVNAME(sc->aue_dev));
779 1.95 is USB_ATTACH_ERROR_RETURN;
780 1.95 is }
781 1.95 is #endif
782 1.62 augustss sc->aue_flags = aue_lookup(uaa->vendor, uaa->product)->aue_flags;
783 1.1 augustss
784 1.1 augustss sc->aue_udev = dev;
785 1.1 augustss sc->aue_iface = iface;
786 1.1 augustss sc->aue_product = uaa->product;
787 1.1 augustss sc->aue_vendor = uaa->vendor;
788 1.1 augustss
789 1.1 augustss id = usbd_get_interface_descriptor(iface);
790 1.1 augustss
791 1.1 augustss /* Find endpoints. */
792 1.1 augustss for (i = 0; i < id->bNumEndpoints; i++) {
793 1.1 augustss ed = usbd_interface2endpoint_descriptor(iface, i);
794 1.27 augustss if (ed == NULL) {
795 1.1 augustss printf("%s: couldn't get endpoint descriptor %d\n",
796 1.1 augustss USBDEVNAME(sc->aue_dev), i);
797 1.1 augustss USB_ATTACH_ERROR_RETURN;
798 1.1 augustss }
799 1.1 augustss if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
800 1.27 augustss UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
801 1.1 augustss sc->aue_ed[AUE_ENDPT_RX] = ed->bEndpointAddress;
802 1.1 augustss } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
803 1.27 augustss UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
804 1.1 augustss sc->aue_ed[AUE_ENDPT_TX] = ed->bEndpointAddress;
805 1.1 augustss } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
806 1.27 augustss UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
807 1.1 augustss sc->aue_ed[AUE_ENDPT_INTR] = ed->bEndpointAddress;
808 1.1 augustss }
809 1.1 augustss }
810 1.1 augustss
811 1.1 augustss if (sc->aue_ed[AUE_ENDPT_RX] == 0 || sc->aue_ed[AUE_ENDPT_TX] == 0 ||
812 1.1 augustss sc->aue_ed[AUE_ENDPT_INTR] == 0) {
813 1.1 augustss printf("%s: missing endpoint\n", USBDEVNAME(sc->aue_dev));
814 1.1 augustss USB_ATTACH_ERROR_RETURN;
815 1.1 augustss }
816 1.1 augustss
817 1.1 augustss
818 1.56 augustss s = splnet();
819 1.1 augustss
820 1.1 augustss /* Reset the adapter. */
821 1.1 augustss aue_reset(sc);
822 1.1 augustss
823 1.1 augustss /*
824 1.1 augustss * Get station address from the EEPROM.
825 1.1 augustss */
826 1.1 augustss aue_read_mac(sc, eaddr);
827 1.1 augustss
828 1.1 augustss /*
829 1.1 augustss * A Pegasus chip was detected. Inform the world.
830 1.1 augustss */
831 1.35 augustss ifp = GET_IFP(sc);
832 1.1 augustss printf("%s: Ethernet address %s\n", USBDEVNAME(sc->aue_dev),
833 1.1 augustss ether_sprintf(eaddr));
834 1.1 augustss
835 1.1 augustss /* Initialize interface info.*/
836 1.1 augustss ifp->if_softc = sc;
837 1.1 augustss ifp->if_mtu = ETHERMTU;
838 1.1 augustss ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
839 1.1 augustss ifp->if_ioctl = aue_ioctl;
840 1.1 augustss ifp->if_start = aue_start;
841 1.99.10.2 itohy ifp->if_init = aue_init;
842 1.99.10.2 itohy ifp->if_stop = aue_stop;
843 1.1 augustss ifp->if_watchdog = aue_watchdog;
844 1.36 augustss #if defined(__OpenBSD__)
845 1.36 augustss ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
846 1.36 augustss #endif
847 1.1 augustss strncpy(ifp->if_xname, USBDEVNAME(sc->aue_dev), IFNAMSIZ);
848 1.1 augustss
849 1.50 thorpej IFQ_SET_READY(&ifp->if_snd);
850 1.50 thorpej
851 1.1 augustss /* Initialize MII/media info. */
852 1.1 augustss mii = &sc->aue_mii;
853 1.1 augustss mii->mii_ifp = ifp;
854 1.1 augustss mii->mii_readreg = aue_miibus_readreg;
855 1.1 augustss mii->mii_writereg = aue_miibus_writereg;
856 1.1 augustss mii->mii_statchg = aue_miibus_statchg;
857 1.56 augustss mii->mii_flags = MIIF_AUTOTSLEEP;
858 1.1 augustss ifmedia_init(&mii->mii_media, 0, aue_ifmedia_upd, aue_ifmedia_sts);
859 1.20 thorpej mii_attach(self, mii, 0xffffffff, MII_PHY_ANY, MII_OFFSET_ANY, 0);
860 1.1 augustss if (LIST_FIRST(&mii->mii_phys) == NULL) {
861 1.1 augustss ifmedia_add(&mii->mii_media, IFM_ETHER | IFM_NONE, 0, NULL);
862 1.1 augustss ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_NONE);
863 1.1 augustss } else
864 1.1 augustss ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_AUTO);
865 1.1 augustss
866 1.1 augustss /* Attach the interface. */
867 1.1 augustss if_attach(ifp);
868 1.35 augustss Ether_ifattach(ifp, eaddr);
869 1.19 augustss #if NRND > 0
870 1.1 augustss rnd_attach_source(&sc->rnd_source, USBDEVNAME(sc->aue_dev),
871 1.1 augustss RND_TYPE_NET, 0);
872 1.1 augustss #endif
873 1.1 augustss
874 1.33 augustss usb_callout_init(sc->aue_stat_ch);
875 1.33 augustss
876 1.24 augustss sc->aue_attached = 1;
877 1.1 augustss splx(s);
878 1.1 augustss
879 1.19 augustss usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->aue_udev,
880 1.19 augustss USBDEV(sc->aue_dev));
881 1.19 augustss
882 1.1 augustss USB_ATTACH_SUCCESS_RETURN;
883 1.1 augustss }
884 1.1 augustss
885 1.1 augustss USB_DETACH(aue)
886 1.1 augustss {
887 1.1 augustss USB_DETACH_START(aue, sc);
888 1.18 augustss struct ifnet *ifp = GET_IFP(sc);
889 1.1 augustss int s;
890 1.1 augustss
891 1.78 augustss DPRINTFN(2,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __func__));
892 1.1 augustss
893 1.58 nathanw if (!sc->aue_attached) {
894 1.58 nathanw /* Detached before attached finished, so just bail out. */
895 1.58 nathanw return (0);
896 1.58 nathanw }
897 1.58 nathanw
898 1.56 augustss usb_uncallout(sc->aue_stat_ch, aue_tick, sc);
899 1.56 augustss /*
900 1.56 augustss * Remove any pending tasks. They cannot be executing because they run
901 1.56 augustss * in the same thread as detach.
902 1.56 augustss */
903 1.56 augustss usb_rem_task(sc->aue_udev, &sc->aue_tick_task);
904 1.56 augustss usb_rem_task(sc->aue_udev, &sc->aue_stop_task);
905 1.56 augustss
906 1.1 augustss s = splusb();
907 1.24 augustss
908 1.18 augustss if (ifp->if_flags & IFF_RUNNING)
909 1.99.10.2 itohy aue_stop(ifp, 1);
910 1.18 augustss
911 1.18 augustss #if defined(__NetBSD__)
912 1.19 augustss #if NRND > 0
913 1.19 augustss rnd_detach_source(&sc->rnd_source);
914 1.19 augustss #endif
915 1.18 augustss mii_detach(&sc->aue_mii, MII_PHY_ANY, MII_OFFSET_ANY);
916 1.18 augustss ifmedia_delete_instance(&sc->aue_mii.mii_media, IFM_INST_ANY);
917 1.18 augustss ether_ifdetach(ifp);
918 1.18 augustss #endif /* __NetBSD__ */
919 1.1 augustss
920 1.1 augustss if_detach(ifp);
921 1.1 augustss
922 1.18 augustss #ifdef DIAGNOSTIC
923 1.18 augustss if (sc->aue_ep[AUE_ENDPT_TX] != NULL ||
924 1.18 augustss sc->aue_ep[AUE_ENDPT_RX] != NULL ||
925 1.18 augustss sc->aue_ep[AUE_ENDPT_INTR] != NULL)
926 1.18 augustss printf("%s: detach has active endpoints\n",
927 1.18 augustss USBDEVNAME(sc->aue_dev));
928 1.18 augustss #endif
929 1.1 augustss
930 1.24 augustss sc->aue_attached = 0;
931 1.67 augustss
932 1.67 augustss if (--sc->aue_refcnt >= 0) {
933 1.67 augustss /* Wait for processes to go away. */
934 1.67 augustss usb_detach_wait(USBDEV(sc->aue_dev));
935 1.67 augustss }
936 1.1 augustss splx(s);
937 1.19 augustss
938 1.79 augustss usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->aue_udev,
939 1.19 augustss USBDEV(sc->aue_dev));
940 1.1 augustss
941 1.1 augustss return (0);
942 1.1 augustss }
943 1.1 augustss
944 1.1 augustss int
945 1.42 augustss aue_activate(device_ptr_t self, enum devact act)
946 1.1 augustss {
947 1.1 augustss struct aue_softc *sc = (struct aue_softc *)self;
948 1.1 augustss
949 1.78 augustss DPRINTFN(2,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __func__));
950 1.1 augustss
951 1.1 augustss switch (act) {
952 1.1 augustss case DVACT_ACTIVATE:
953 1.1 augustss return (EOPNOTSUPP);
954 1.1 augustss break;
955 1.1 augustss
956 1.1 augustss case DVACT_DEACTIVATE:
957 1.18 augustss if_deactivate(&sc->aue_ec.ec_if);
958 1.1 augustss sc->aue_dying = 1;
959 1.1 augustss break;
960 1.1 augustss }
961 1.1 augustss return (0);
962 1.1 augustss }
963 1.1 augustss
964 1.34 augustss Static void
965 1.99 christos aue_intr(usbd_xfer_handle xfer, usbd_private_handle priv,
966 1.97 christos usbd_status status)
967 1.1 augustss {
968 1.1 augustss struct aue_softc *sc = priv;
969 1.1 augustss struct ifnet *ifp = GET_IFP(sc);
970 1.1 augustss struct aue_intrpkt *p = &sc->aue_cdata.aue_ibuf;
971 1.1 augustss
972 1.78 augustss DPRINTFN(15,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev),__func__));
973 1.1 augustss
974 1.18 augustss if (sc->aue_dying)
975 1.18 augustss return;
976 1.18 augustss
977 1.1 augustss if (!(ifp->if_flags & IFF_RUNNING))
978 1.1 augustss return;
979 1.1 augustss
980 1.1 augustss if (status != USBD_NORMAL_COMPLETION) {
981 1.1 augustss if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
982 1.1 augustss return;
983 1.1 augustss }
984 1.38 augustss sc->aue_intr_errs++;
985 1.38 augustss if (usbd_ratecheck(&sc->aue_rx_notice)) {
986 1.38 augustss printf("%s: %u usb errors on intr: %s\n",
987 1.57 enami USBDEVNAME(sc->aue_dev), sc->aue_intr_errs,
988 1.38 augustss usbd_errstr(status));
989 1.38 augustss sc->aue_intr_errs = 0;
990 1.38 augustss }
991 1.1 augustss if (status == USBD_STALLED)
992 1.92 augustss usbd_clear_endpoint_stall_async(sc->aue_ep[AUE_ENDPT_RX]);
993 1.1 augustss return;
994 1.1 augustss }
995 1.1 augustss
996 1.1 augustss if (p->aue_txstat0)
997 1.1 augustss ifp->if_oerrors++;
998 1.1 augustss
999 1.1 augustss if (p->aue_txstat0 & (AUE_TXSTAT0_LATECOLL | AUE_TXSTAT0_EXCESSCOLL))
1000 1.1 augustss ifp->if_collisions++;
1001 1.1 augustss }
1002 1.1 augustss
1003 1.1 augustss /*
1004 1.1 augustss * A frame has been uploaded: pass the resulting mbuf chain up to
1005 1.1 augustss * the higher level protocols.
1006 1.1 augustss */
1007 1.34 augustss Static void
1008 1.42 augustss aue_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
1009 1.1 augustss {
1010 1.99.10.2 itohy struct ue_chain *c = priv;
1011 1.99.10.2 itohy struct aue_softc *sc = (void *)c->ue_dev;
1012 1.1 augustss struct ifnet *ifp = GET_IFP(sc);
1013 1.1 augustss struct mbuf *m;
1014 1.1 augustss u_int32_t total_len;
1015 1.1 augustss struct aue_rxpkt r;
1016 1.1 augustss int s;
1017 1.1 augustss
1018 1.78 augustss DPRINTFN(10,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev),__func__));
1019 1.1 augustss
1020 1.18 augustss if (sc->aue_dying)
1021 1.18 augustss return;
1022 1.18 augustss
1023 1.99.10.2 itohy usbd_unmap_buffer(xfer);
1024 1.99.10.2 itohy
1025 1.1 augustss if (!(ifp->if_flags & IFF_RUNNING))
1026 1.1 augustss return;
1027 1.1 augustss
1028 1.1 augustss if (status != USBD_NORMAL_COMPLETION) {
1029 1.1 augustss if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
1030 1.1 augustss return;
1031 1.25 augustss sc->aue_rx_errs++;
1032 1.26 augustss if (usbd_ratecheck(&sc->aue_rx_notice)) {
1033 1.25 augustss printf("%s: %u usb errors on rx: %s\n",
1034 1.26 augustss USBDEVNAME(sc->aue_dev), sc->aue_rx_errs,
1035 1.26 augustss usbd_errstr(status));
1036 1.25 augustss sc->aue_rx_errs = 0;
1037 1.25 augustss }
1038 1.1 augustss if (status == USBD_STALLED)
1039 1.92 augustss usbd_clear_endpoint_stall_async(sc->aue_ep[AUE_ENDPT_RX]);
1040 1.1 augustss goto done;
1041 1.1 augustss }
1042 1.1 augustss
1043 1.1 augustss usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL);
1044 1.1 augustss
1045 1.1 augustss if (total_len <= 4 + ETHER_CRC_LEN) {
1046 1.1 augustss ifp->if_ierrors++;
1047 1.1 augustss goto done;
1048 1.1 augustss }
1049 1.1 augustss
1050 1.99.10.2 itohy memcpy(&r, mtod(c->ue_mbuf, char *) + total_len - 4, sizeof(r));
1051 1.1 augustss
1052 1.1 augustss /* Turn off all the non-error bits in the rx status word. */
1053 1.1 augustss r.aue_rxstat &= AUE_RXSTAT_MASK;
1054 1.1 augustss if (r.aue_rxstat) {
1055 1.1 augustss ifp->if_ierrors++;
1056 1.1 augustss goto done;
1057 1.1 augustss }
1058 1.1 augustss
1059 1.99.10.2 itohy m = c->ue_mbuf;
1060 1.99.10.2 itohy
1061 1.99.10.2 itohy /*
1062 1.99.10.2 itohy * Allocate new mbuf cluster for the next transfer.
1063 1.99.10.2 itohy * If that failed, discard current packet and recycle the mbuf.
1064 1.99.10.2 itohy */
1065 1.99.10.2 itohy if ((c->ue_mbuf = usb_ether_newbuf(NULL)) == NULL) {
1066 1.99.10.2 itohy printf("%s: no memory for rx list -- packet dropped!\n",
1067 1.99.10.2 itohy USBDEVNAME(sc->aue_dev));
1068 1.99.10.2 itohy ifp->if_ierrors++;
1069 1.99.10.2 itohy c->ue_mbuf = usb_ether_newbuf(m);
1070 1.99.10.2 itohy goto done;
1071 1.99.10.2 itohy }
1072 1.99.10.2 itohy
1073 1.1 augustss /* No errors; receive the packet. */
1074 1.1 augustss total_len -= ETHER_CRC_LEN + 4;
1075 1.1 augustss m->m_pkthdr.len = m->m_len = total_len;
1076 1.1 augustss ifp->if_ipackets++;
1077 1.1 augustss
1078 1.1 augustss m->m_pkthdr.rcvif = ifp;
1079 1.1 augustss
1080 1.56 augustss s = splnet();
1081 1.1 augustss
1082 1.25 augustss #if NBPFILTER > 0
1083 1.1 augustss /*
1084 1.1 augustss * Handle BPF listeners. Let the BPF user see the packet, but
1085 1.1 augustss * don't pass it up to the ether_input() layer unless it's
1086 1.1 augustss * a broadcast packet, multicast packet, matches our ethernet
1087 1.1 augustss * address or the interface is in promiscuous mode.
1088 1.1 augustss */
1089 1.44 thorpej if (ifp->if_bpf)
1090 1.36 augustss BPF_MTAP(ifp, m);
1091 1.25 augustss #endif
1092 1.1 augustss
1093 1.1 augustss DPRINTFN(10,("%s: %s: deliver %d\n", USBDEVNAME(sc->aue_dev),
1094 1.78 augustss __func__, m->m_len));
1095 1.35 augustss IF_INPUT(ifp, m);
1096 1.1 augustss splx(s);
1097 1.1 augustss
1098 1.1 augustss done:
1099 1.1 augustss
1100 1.1 augustss /* Setup new transfer. */
1101 1.99.10.2 itohy (void)usbd_map_buffer_mbuf(c->ue_xfer, c->ue_mbuf);
1102 1.1 augustss usbd_setup_xfer(xfer, sc->aue_ep[AUE_ENDPT_RX],
1103 1.99.10.2 itohy c, NULL /* XXX buf */, AUE_BUFSZ,
1104 1.99.10.5 itohy USBD_SHORT_XFER_OK | USBD_NO_COPY
1105 1.99.10.5 itohy #ifdef __FreeBSD__ /* callback needs context */
1106 1.99.10.5 itohy | USBD_CALLBACK_AS_TASK
1107 1.99.10.5 itohy #endif
1108 1.99.10.5 itohy ,
1109 1.1 augustss USBD_NO_TIMEOUT, aue_rxeof);
1110 1.1 augustss usbd_transfer(xfer);
1111 1.7 augustss
1112 1.1 augustss DPRINTFN(10,("%s: %s: start rx\n", USBDEVNAME(sc->aue_dev),
1113 1.78 augustss __func__));
1114 1.1 augustss }
1115 1.1 augustss
1116 1.1 augustss /*
1117 1.1 augustss * A frame was downloaded to the chip. It's safe for us to clean up
1118 1.1 augustss * the list buffers.
1119 1.1 augustss */
1120 1.1 augustss
1121 1.34 augustss Static void
1122 1.99 christos aue_txeof(usbd_xfer_handle xfer, usbd_private_handle priv,
1123 1.97 christos usbd_status status)
1124 1.1 augustss {
1125 1.99.10.2 itohy struct ue_chain *c = priv;
1126 1.99.10.2 itohy struct aue_softc *sc = (void *)c->ue_dev;
1127 1.1 augustss struct ifnet *ifp = GET_IFP(sc);
1128 1.1 augustss int s;
1129 1.1 augustss
1130 1.18 augustss if (sc->aue_dying)
1131 1.18 augustss return;
1132 1.18 augustss
1133 1.99.10.2 itohy usbd_unmap_buffer(xfer);
1134 1.99.10.2 itohy
1135 1.56 augustss s = splnet();
1136 1.1 augustss
1137 1.1 augustss DPRINTFN(10,("%s: %s: enter status=%d\n", USBDEVNAME(sc->aue_dev),
1138 1.78 augustss __func__, status));
1139 1.1 augustss
1140 1.7 augustss ifp->if_timer = 0;
1141 1.7 augustss ifp->if_flags &= ~IFF_OACTIVE;
1142 1.7 augustss
1143 1.1 augustss if (status != USBD_NORMAL_COMPLETION) {
1144 1.1 augustss if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
1145 1.1 augustss splx(s);
1146 1.1 augustss return;
1147 1.1 augustss }
1148 1.1 augustss ifp->if_oerrors++;
1149 1.1 augustss printf("%s: usb error on tx: %s\n", USBDEVNAME(sc->aue_dev),
1150 1.1 augustss usbd_errstr(status));
1151 1.1 augustss if (status == USBD_STALLED)
1152 1.92 augustss usbd_clear_endpoint_stall_async(sc->aue_ep[AUE_ENDPT_TX]);
1153 1.1 augustss splx(s);
1154 1.1 augustss return;
1155 1.1 augustss }
1156 1.1 augustss
1157 1.1 augustss ifp->if_opackets++;
1158 1.1 augustss
1159 1.99.10.2 itohy m_freem(c->ue_mbuf);
1160 1.99.10.2 itohy c->ue_mbuf = NULL;
1161 1.1 augustss
1162 1.50 thorpej if (IFQ_IS_EMPTY(&ifp->if_snd) == 0)
1163 1.1 augustss aue_start(ifp);
1164 1.1 augustss
1165 1.1 augustss splx(s);
1166 1.1 augustss }
1167 1.1 augustss
1168 1.34 augustss Static void
1169 1.42 augustss aue_tick(void *xsc)
1170 1.1 augustss {
1171 1.1 augustss struct aue_softc *sc = xsc;
1172 1.56 augustss
1173 1.78 augustss DPRINTFN(15,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev),__func__));
1174 1.56 augustss
1175 1.56 augustss if (sc == NULL)
1176 1.56 augustss return;
1177 1.56 augustss
1178 1.56 augustss if (sc->aue_dying)
1179 1.56 augustss return;
1180 1.56 augustss
1181 1.56 augustss /* Perform periodic stuff in process context. */
1182 1.98 joerg usb_add_task(sc->aue_udev, &sc->aue_tick_task, USB_TASKQ_DRIVER);
1183 1.56 augustss }
1184 1.56 augustss
1185 1.56 augustss Static void
1186 1.56 augustss aue_tick_task(void *xsc)
1187 1.56 augustss {
1188 1.56 augustss struct aue_softc *sc = xsc;
1189 1.1 augustss struct ifnet *ifp;
1190 1.1 augustss struct mii_data *mii;
1191 1.1 augustss int s;
1192 1.1 augustss
1193 1.78 augustss DPRINTFN(15,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev),__func__));
1194 1.1 augustss
1195 1.18 augustss if (sc->aue_dying)
1196 1.18 augustss return;
1197 1.18 augustss
1198 1.1 augustss ifp = GET_IFP(sc);
1199 1.1 augustss mii = GET_MII(sc);
1200 1.1 augustss if (mii == NULL)
1201 1.1 augustss return;
1202 1.1 augustss
1203 1.56 augustss s = splnet();
1204 1.1 augustss
1205 1.1 augustss mii_tick(mii);
1206 1.1 augustss if (!sc->aue_link) {
1207 1.67 augustss mii_pollstat(mii); /* XXX FreeBSD has removed this call */
1208 1.1 augustss if (mii->mii_media_status & IFM_ACTIVE &&
1209 1.1 augustss IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
1210 1.1 augustss DPRINTFN(2,("%s: %s: got link\n",
1211 1.78 augustss USBDEVNAME(sc->aue_dev),__func__));
1212 1.1 augustss sc->aue_link++;
1213 1.50 thorpej if (IFQ_IS_EMPTY(&ifp->if_snd) == 0)
1214 1.1 augustss aue_start(ifp);
1215 1.1 augustss }
1216 1.1 augustss }
1217 1.1 augustss
1218 1.33 augustss usb_callout(sc->aue_stat_ch, hz, aue_tick, sc);
1219 1.1 augustss
1220 1.1 augustss splx(s);
1221 1.1 augustss }
1222 1.1 augustss
1223 1.34 augustss Static int
1224 1.42 augustss aue_send(struct aue_softc *sc, struct mbuf *m, int idx)
1225 1.1 augustss {
1226 1.1 augustss int total_len;
1227 1.99.10.2 itohy struct ue_chain *c;
1228 1.1 augustss usbd_status err;
1229 1.99.10.2 itohy int ret;
1230 1.1 augustss
1231 1.78 augustss DPRINTFN(10,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev),__func__));
1232 1.1 augustss
1233 1.1 augustss c = &sc->aue_cdata.aue_tx_chain[idx];
1234 1.1 augustss
1235 1.99.10.2 itohy /* Prepend two bytes at the beginning to hold the frame length. */
1236 1.99.10.2 itohy M_PREPEND(m, 2, M_DONTWAIT);
1237 1.99.10.2 itohy if (m != NULL)
1238 1.99.10.2 itohy m = m_pullup(m, 2); /* just in case */
1239 1.99.10.2 itohy if (m == NULL) {
1240 1.99.10.2 itohy GET_IFP(sc)->if_oerrors++;
1241 1.99.10.2 itohy return (ENOBUFS);
1242 1.99.10.2 itohy }
1243 1.1 augustss
1244 1.1 augustss /*
1245 1.1 augustss * The ADMtek documentation says that the packet length is
1246 1.1 augustss * supposed to be specified in the first two bytes of the
1247 1.1 augustss * transfer, however it actually seems to ignore this info
1248 1.1 augustss * and base the frame size on the bulk transfer length.
1249 1.1 augustss */
1250 1.99.10.2 itohy USETW(mtod(m, char *), m->m_pkthdr.len - 2);
1251 1.99.10.2 itohy total_len = m->m_pkthdr.len;
1252 1.1 augustss
1253 1.99.10.2 itohy ret = usb_ether_map_tx_buffer_mbuf(c, m);
1254 1.99.10.2 itohy if (ret) {
1255 1.99.10.2 itohy m_freem(m);
1256 1.99.10.2 itohy return (ret);
1257 1.99.10.2 itohy }
1258 1.99.10.2 itohy
1259 1.99.10.2 itohy usbd_setup_xfer(c->ue_xfer, sc->aue_ep[AUE_ENDPT_TX],
1260 1.99.10.5 itohy c, NULL /* XXX buf */, total_len, USBD_FORCE_SHORT_XFER | USBD_NO_COPY
1261 1.99.10.5 itohy #ifdef __FreeBSD__ /* callback needs context */
1262 1.99.10.5 itohy | USBD_CALLBACK_AS_TASK
1263 1.99.10.5 itohy #endif
1264 1.99.10.5 itohy ,
1265 1.1 augustss AUE_TX_TIMEOUT, aue_txeof);
1266 1.1 augustss
1267 1.1 augustss /* Transmit */
1268 1.99.10.2 itohy err = usbd_transfer(c->ue_xfer);
1269 1.1 augustss if (err != USBD_IN_PROGRESS) {
1270 1.99.10.2 itohy c->ue_mbuf = NULL;
1271 1.99.10.2 itohy m_freem(m);
1272 1.37 augustss printf("%s: aue_send error=%s\n", USBDEVNAME(sc->aue_dev),
1273 1.37 augustss usbd_errstr(err));
1274 1.56 augustss /* Stop the interface from process context. */
1275 1.98 joerg usb_add_task(sc->aue_udev, &sc->aue_stop_task,
1276 1.98 joerg USB_TASKQ_DRIVER);
1277 1.1 augustss return (EIO);
1278 1.1 augustss }
1279 1.1 augustss DPRINTFN(5,("%s: %s: send %d bytes\n", USBDEVNAME(sc->aue_dev),
1280 1.78 augustss __func__, total_len));
1281 1.1 augustss
1282 1.1 augustss sc->aue_cdata.aue_tx_cnt++;
1283 1.1 augustss
1284 1.1 augustss return (0);
1285 1.1 augustss }
1286 1.1 augustss
1287 1.34 augustss Static void
1288 1.42 augustss aue_start(struct ifnet *ifp)
1289 1.1 augustss {
1290 1.1 augustss struct aue_softc *sc = ifp->if_softc;
1291 1.1 augustss struct mbuf *m_head = NULL;
1292 1.1 augustss
1293 1.1 augustss DPRINTFN(5,("%s: %s: enter, link=%d\n", USBDEVNAME(sc->aue_dev),
1294 1.78 augustss __func__, sc->aue_link));
1295 1.1 augustss
1296 1.18 augustss if (sc->aue_dying)
1297 1.18 augustss return;
1298 1.18 augustss
1299 1.1 augustss if (!sc->aue_link)
1300 1.1 augustss return;
1301 1.1 augustss
1302 1.1 augustss if (ifp->if_flags & IFF_OACTIVE)
1303 1.1 augustss return;
1304 1.1 augustss
1305 1.50 thorpej IFQ_POLL(&ifp->if_snd, m_head);
1306 1.1 augustss if (m_head == NULL)
1307 1.1 augustss return;
1308 1.1 augustss
1309 1.50 thorpej IFQ_DEQUEUE(&ifp->if_snd, m_head);
1310 1.50 thorpej
1311 1.25 augustss #if NBPFILTER > 0
1312 1.1 augustss /*
1313 1.1 augustss * If there's a BPF listener, bounce a copy of this frame
1314 1.1 augustss * to him.
1315 1.1 augustss */
1316 1.1 augustss if (ifp->if_bpf)
1317 1.23 mycroft BPF_MTAP(ifp, m_head);
1318 1.25 augustss #endif
1319 1.1 augustss
1320 1.99.10.2 itohy if (aue_send(sc, m_head, 0)) {
1321 1.99.10.2 itohy ifp->if_flags |= IFF_OACTIVE;
1322 1.99.10.2 itohy return;
1323 1.99.10.2 itohy }
1324 1.99.10.2 itohy
1325 1.1 augustss ifp->if_flags |= IFF_OACTIVE;
1326 1.1 augustss
1327 1.1 augustss /*
1328 1.1 augustss * Set a timeout in case the chip goes out to lunch.
1329 1.1 augustss */
1330 1.1 augustss ifp->if_timer = 5;
1331 1.1 augustss }
1332 1.1 augustss
1333 1.99.10.2 itohy Static int
1334 1.99.10.2 itohy aue_init(struct ifnet *ifp)
1335 1.1 augustss {
1336 1.99.10.2 itohy struct aue_softc *sc = ifp->if_softc;
1337 1.1 augustss struct mii_data *mii = GET_MII(sc);
1338 1.1 augustss int i, s;
1339 1.1 augustss u_char *eaddr;
1340 1.99.10.2 itohy struct ue_chain *c;
1341 1.1 augustss
1342 1.78 augustss DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __func__));
1343 1.1 augustss
1344 1.18 augustss if (sc->aue_dying)
1345 1.99.10.2 itohy return (EIO);
1346 1.18 augustss
1347 1.1 augustss if (ifp->if_flags & IFF_RUNNING)
1348 1.99.10.2 itohy return (EIO);
1349 1.1 augustss
1350 1.56 augustss s = splnet();
1351 1.1 augustss
1352 1.1 augustss /*
1353 1.1 augustss * Cancel pending I/O and free all RX/TX buffers.
1354 1.1 augustss */
1355 1.1 augustss aue_reset(sc);
1356 1.1 augustss
1357 1.52 augustss #if defined(__OpenBSD__)
1358 1.1 augustss eaddr = sc->arpcom.ac_enaddr;
1359 1.35 augustss #elif defined(__NetBSD__)
1360 1.1 augustss eaddr = LLADDR(ifp->if_sadl);
1361 1.35 augustss #endif /* defined(__NetBSD__) */
1362 1.1 augustss for (i = 0; i < ETHER_ADDR_LEN; i++)
1363 1.29 augustss aue_csr_write_1(sc, AUE_PAR0 + i, eaddr[i]);
1364 1.1 augustss
1365 1.99.10.6 itohy /* If we want promiscuous mode, set the allframes bit. */
1366 1.1 augustss if (ifp->if_flags & IFF_PROMISC)
1367 1.1 augustss AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC);
1368 1.1 augustss else
1369 1.1 augustss AUE_CLRBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC);
1370 1.1 augustss
1371 1.1 augustss /* Load the multicast filter. */
1372 1.1 augustss aue_setmulti(sc);
1373 1.1 augustss
1374 1.1 augustss /* Enable RX and TX */
1375 1.29 augustss aue_csr_write_1(sc, AUE_CTL0, AUE_CTL0_RXSTAT_APPEND | AUE_CTL0_RX_ENB);
1376 1.1 augustss AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_TX_ENB);
1377 1.1 augustss AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_EP3_CLR);
1378 1.1 augustss
1379 1.1 augustss mii_mediachg(mii);
1380 1.1 augustss
1381 1.1 augustss if (sc->aue_ep[AUE_ENDPT_RX] == NULL) {
1382 1.16 augustss if (aue_openpipes(sc)) {
1383 1.16 augustss splx(s);
1384 1.99.10.2 itohy return (EIO);
1385 1.16 augustss }
1386 1.16 augustss }
1387 1.16 augustss
1388 1.99.10.2 itohy /* Init TX ring. */
1389 1.99.10.2 itohy if ((i = usb_ether_tx_list_init(USBDEV(sc->aue_dev),
1390 1.99.10.2 itohy sc->aue_cdata.aue_tx_chain, AUE_TX_LIST_CNT,
1391 1.99.10.2 itohy sc->aue_udev, sc->aue_ep[AUE_ENDPT_TX], NULL))) {
1392 1.99.10.2 itohy printf("%s: tx list init failed\n", USBDEVNAME(sc->aue_dev));
1393 1.99.10.2 itohy splx(s);
1394 1.99.10.2 itohy return (i);
1395 1.99.10.2 itohy }
1396 1.99.10.2 itohy
1397 1.99.10.2 itohy /* Init RX ring. */
1398 1.99.10.2 itohy if ((i = usb_ether_rx_list_init(USBDEV(sc->aue_dev),
1399 1.99.10.2 itohy sc->aue_cdata.aue_rx_chain, AUE_RX_LIST_CNT,
1400 1.99.10.2 itohy sc->aue_udev, sc->aue_ep[AUE_ENDPT_RX]))) {
1401 1.99.10.2 itohy printf("%s: rx list init failed\n", USBDEVNAME(sc->aue_dev));
1402 1.99.10.2 itohy splx(s);
1403 1.99.10.2 itohy return (i);
1404 1.99.10.2 itohy }
1405 1.99.10.2 itohy
1406 1.99.10.2 itohy /* Start up the receive pipe. */
1407 1.99.10.2 itohy for (i = 0; i < AUE_RX_LIST_CNT; i++) {
1408 1.99.10.2 itohy c = &sc->aue_cdata.aue_rx_chain[i];
1409 1.99.10.2 itohy (void)usbd_map_buffer_mbuf(c->ue_xfer, c->ue_mbuf);
1410 1.99.10.2 itohy usbd_setup_xfer(c->ue_xfer, sc->aue_ep[AUE_ENDPT_RX],
1411 1.99.10.2 itohy c, NULL /* XXX buf */, AUE_BUFSZ,
1412 1.99.10.5 itohy USBD_SHORT_XFER_OK | USBD_NO_COPY
1413 1.99.10.5 itohy #ifdef __FreeBSD__ /* callback needs context */
1414 1.99.10.5 itohy | USBD_CALLBACK_AS_TASK
1415 1.99.10.5 itohy #endif
1416 1.99.10.5 itohy , USBD_NO_TIMEOUT,
1417 1.99.10.2 itohy aue_rxeof);
1418 1.99.10.2 itohy (void)usbd_transfer(c->ue_xfer); /* XXX */
1419 1.99.10.2 itohy DPRINTFN(5,("%s: %s: start read\n", USBDEVNAME(sc->aue_dev),
1420 1.99.10.2 itohy __func__));
1421 1.99.10.2 itohy }
1422 1.99.10.2 itohy
1423 1.16 augustss ifp->if_flags |= IFF_RUNNING;
1424 1.16 augustss ifp->if_flags &= ~IFF_OACTIVE;
1425 1.16 augustss
1426 1.16 augustss splx(s);
1427 1.16 augustss
1428 1.33 augustss usb_callout(sc->aue_stat_ch, hz, aue_tick, sc);
1429 1.99.10.2 itohy
1430 1.99.10.2 itohy return (0);
1431 1.16 augustss }
1432 1.16 augustss
1433 1.34 augustss Static int
1434 1.42 augustss aue_openpipes(struct aue_softc *sc)
1435 1.16 augustss {
1436 1.16 augustss usbd_status err;
1437 1.16 augustss
1438 1.1 augustss /* Open RX and TX pipes. */
1439 1.1 augustss err = usbd_open_pipe(sc->aue_iface, sc->aue_ed[AUE_ENDPT_RX],
1440 1.1 augustss USBD_EXCLUSIVE_USE, &sc->aue_ep[AUE_ENDPT_RX]);
1441 1.1 augustss if (err) {
1442 1.1 augustss printf("%s: open rx pipe failed: %s\n",
1443 1.1 augustss USBDEVNAME(sc->aue_dev), usbd_errstr(err));
1444 1.16 augustss return (EIO);
1445 1.1 augustss }
1446 1.39 augustss err = usbd_open_pipe(sc->aue_iface, sc->aue_ed[AUE_ENDPT_TX],
1447 1.1 augustss USBD_EXCLUSIVE_USE, &sc->aue_ep[AUE_ENDPT_TX]);
1448 1.1 augustss if (err) {
1449 1.1 augustss printf("%s: open tx pipe failed: %s\n",
1450 1.1 augustss USBDEVNAME(sc->aue_dev), usbd_errstr(err));
1451 1.16 augustss return (EIO);
1452 1.1 augustss }
1453 1.1 augustss err = usbd_open_pipe_intr(sc->aue_iface, sc->aue_ed[AUE_ENDPT_INTR],
1454 1.1 augustss USBD_EXCLUSIVE_USE, &sc->aue_ep[AUE_ENDPT_INTR], sc,
1455 1.79 augustss &sc->aue_cdata.aue_ibuf, AUE_INTR_PKTLEN, aue_intr,
1456 1.14 augustss AUE_INTR_INTERVAL);
1457 1.1 augustss if (err) {
1458 1.1 augustss printf("%s: open intr pipe failed: %s\n",
1459 1.1 augustss USBDEVNAME(sc->aue_dev), usbd_errstr(err));
1460 1.16 augustss return (EIO);
1461 1.1 augustss }
1462 1.1 augustss
1463 1.16 augustss return (0);
1464 1.1 augustss }
1465 1.1 augustss
1466 1.1 augustss /*
1467 1.1 augustss * Set media options.
1468 1.1 augustss */
1469 1.34 augustss Static int
1470 1.42 augustss aue_ifmedia_upd(struct ifnet *ifp)
1471 1.1 augustss {
1472 1.1 augustss struct aue_softc *sc = ifp->if_softc;
1473 1.1 augustss struct mii_data *mii = GET_MII(sc);
1474 1.1 augustss
1475 1.78 augustss DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __func__));
1476 1.1 augustss
1477 1.18 augustss if (sc->aue_dying)
1478 1.18 augustss return (0);
1479 1.18 augustss
1480 1.1 augustss sc->aue_link = 0;
1481 1.1 augustss if (mii->mii_instance) {
1482 1.1 augustss struct mii_softc *miisc;
1483 1.1 augustss for (miisc = LIST_FIRST(&mii->mii_phys); miisc != NULL;
1484 1.1 augustss miisc = LIST_NEXT(miisc, mii_list))
1485 1.1 augustss mii_phy_reset(miisc);
1486 1.1 augustss }
1487 1.1 augustss mii_mediachg(mii);
1488 1.1 augustss
1489 1.1 augustss return (0);
1490 1.1 augustss }
1491 1.1 augustss
1492 1.1 augustss /*
1493 1.1 augustss * Report current media status.
1494 1.1 augustss */
1495 1.34 augustss Static void
1496 1.42 augustss aue_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
1497 1.1 augustss {
1498 1.1 augustss struct aue_softc *sc = ifp->if_softc;
1499 1.1 augustss struct mii_data *mii = GET_MII(sc);
1500 1.1 augustss
1501 1.78 augustss DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __func__));
1502 1.1 augustss
1503 1.1 augustss mii_pollstat(mii);
1504 1.1 augustss ifmr->ifm_active = mii->mii_media_active;
1505 1.1 augustss ifmr->ifm_status = mii->mii_media_status;
1506 1.1 augustss }
1507 1.1 augustss
1508 1.34 augustss Static int
1509 1.99.10.3 itohy aue_ioctl(struct ifnet *ifp, u_long command, usb_ioctlarg_t data)
1510 1.1 augustss {
1511 1.1 augustss struct aue_softc *sc = ifp->if_softc;
1512 1.99.10.2 itohy #if 0
1513 1.1 augustss struct ifaddr *ifa = (struct ifaddr *)data;
1514 1.99.10.2 itohy #endif
1515 1.1 augustss struct ifreq *ifr = (struct ifreq *)data;
1516 1.1 augustss struct mii_data *mii;
1517 1.1 augustss int s, error = 0;
1518 1.18 augustss
1519 1.18 augustss if (sc->aue_dying)
1520 1.18 augustss return (EIO);
1521 1.1 augustss
1522 1.56 augustss s = splnet();
1523 1.1 augustss
1524 1.1 augustss switch(command) {
1525 1.99.10.2 itohy #if 0
1526 1.1 augustss case SIOCSIFADDR:
1527 1.1 augustss ifp->if_flags |= IFF_UP;
1528 1.99.10.2 itohy aue_init(ifp);
1529 1.1 augustss
1530 1.1 augustss switch (ifa->ifa_addr->sa_family) {
1531 1.1 augustss #ifdef INET
1532 1.1 augustss case AF_INET:
1533 1.35 augustss #if defined(__NetBSD__)
1534 1.1 augustss arp_ifinit(ifp, ifa);
1535 1.35 augustss #else
1536 1.35 augustss arp_ifinit(&sc->arpcom, ifa);
1537 1.35 augustss #endif
1538 1.1 augustss break;
1539 1.1 augustss #endif /* INET */
1540 1.1 augustss }
1541 1.1 augustss break;
1542 1.1 augustss
1543 1.1 augustss case SIOCSIFMTU:
1544 1.1 augustss if (ifr->ifr_mtu > ETHERMTU)
1545 1.1 augustss error = EINVAL;
1546 1.1 augustss else
1547 1.1 augustss ifp->if_mtu = ifr->ifr_mtu;
1548 1.1 augustss break;
1549 1.99.10.2 itohy #endif
1550 1.1 augustss
1551 1.1 augustss case SIOCSIFFLAGS:
1552 1.1 augustss if (ifp->if_flags & IFF_UP) {
1553 1.1 augustss if (ifp->if_flags & IFF_RUNNING &&
1554 1.1 augustss ifp->if_flags & IFF_PROMISC &&
1555 1.1 augustss !(sc->aue_if_flags & IFF_PROMISC)) {
1556 1.1 augustss AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC);
1557 1.1 augustss } else if (ifp->if_flags & IFF_RUNNING &&
1558 1.1 augustss !(ifp->if_flags & IFF_PROMISC) &&
1559 1.1 augustss sc->aue_if_flags & IFF_PROMISC) {
1560 1.1 augustss AUE_CLRBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC);
1561 1.1 augustss } else if (!(ifp->if_flags & IFF_RUNNING))
1562 1.99.10.2 itohy aue_init(ifp);
1563 1.1 augustss } else {
1564 1.1 augustss if (ifp->if_flags & IFF_RUNNING)
1565 1.99.10.2 itohy aue_stop(ifp, 1);
1566 1.1 augustss }
1567 1.1 augustss sc->aue_if_flags = ifp->if_flags;
1568 1.1 augustss error = 0;
1569 1.1 augustss break;
1570 1.99.10.2 itohy #if 0
1571 1.1 augustss case SIOCADDMULTI:
1572 1.1 augustss case SIOCDELMULTI:
1573 1.43 itojun error = (command == SIOCADDMULTI) ?
1574 1.43 itojun ether_addmulti(ifr, &sc->aue_ec) :
1575 1.43 itojun ether_delmulti(ifr, &sc->aue_ec);
1576 1.43 itojun if (error == ENETRESET) {
1577 1.88 thorpej if (ifp->if_flags & IFF_RUNNING) {
1578 1.95 is #if defined(__NetBSD__)
1579 1.95 is workqueue_enqueue(sc->wqp,&sc->wk);
1580 1.95 is /* XXX */
1581 1.95 is #else
1582 1.99.10.2 itohy aue_init(ifp);
1583 1.88 thorpej aue_setmulti(sc);
1584 1.95 is #endif
1585 1.88 thorpej }
1586 1.88 thorpej error = 0;
1587 1.43 itojun }
1588 1.1 augustss break;
1589 1.99.10.2 itohy #endif
1590 1.1 augustss case SIOCGIFMEDIA:
1591 1.1 augustss case SIOCSIFMEDIA:
1592 1.1 augustss mii = GET_MII(sc);
1593 1.1 augustss error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
1594 1.1 augustss break;
1595 1.1 augustss default:
1596 1.99.10.2 itohy error = ether_ioctl(ifp, command, data);
1597 1.99.10.2 itohy if (error == ENETRESET) {
1598 1.99.10.2 itohy if (ifp->if_flags & IFF_RUNNING) {
1599 1.99.10.2 itohy #if defined(__NetBSD__)
1600 1.99.10.2 itohy workqueue_enqueue(sc->wqp,&sc->wk);
1601 1.99.10.2 itohy /* XXX */
1602 1.99.10.2 itohy #else
1603 1.99.10.2 itohy aue_init(ifp);
1604 1.99.10.2 itohy aue_setmulti(sc);
1605 1.99.10.2 itohy #endif
1606 1.99.10.2 itohy }
1607 1.99.10.2 itohy error = 0;
1608 1.99.10.2 itohy }
1609 1.1 augustss break;
1610 1.1 augustss }
1611 1.1 augustss
1612 1.1 augustss splx(s);
1613 1.1 augustss
1614 1.1 augustss return (error);
1615 1.1 augustss }
1616 1.1 augustss
1617 1.34 augustss Static void
1618 1.42 augustss aue_watchdog(struct ifnet *ifp)
1619 1.1 augustss {
1620 1.1 augustss struct aue_softc *sc = ifp->if_softc;
1621 1.99.10.2 itohy struct ue_chain *c;
1622 1.53 augustss usbd_status stat;
1623 1.53 augustss int s;
1624 1.1 augustss
1625 1.78 augustss DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __func__));
1626 1.1 augustss
1627 1.1 augustss ifp->if_oerrors++;
1628 1.1 augustss printf("%s: watchdog timeout\n", USBDEVNAME(sc->aue_dev));
1629 1.1 augustss
1630 1.53 augustss s = splusb();
1631 1.53 augustss c = &sc->aue_cdata.aue_tx_chain[0];
1632 1.99.10.2 itohy usbd_get_xfer_status(c->ue_xfer, NULL, NULL, NULL, &stat);
1633 1.99.10.2 itohy aue_txeof(c->ue_xfer, c, stat);
1634 1.1 augustss
1635 1.50 thorpej if (IFQ_IS_EMPTY(&ifp->if_snd) == 0)
1636 1.1 augustss aue_start(ifp);
1637 1.53 augustss splx(s);
1638 1.1 augustss }
1639 1.1 augustss
1640 1.1 augustss /*
1641 1.1 augustss * Stop the adapter and free any mbufs allocated to the
1642 1.1 augustss * RX and TX lists.
1643 1.1 augustss */
1644 1.34 augustss Static void
1645 1.99.10.2 itohy aue_stop(struct ifnet *ifp, int disable)
1646 1.1 augustss {
1647 1.99.10.2 itohy struct aue_softc *sc = ifp->if_softc;
1648 1.1 augustss usbd_status err;
1649 1.1 augustss
1650 1.78 augustss DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __func__));
1651 1.1 augustss
1652 1.1 augustss ifp = GET_IFP(sc);
1653 1.1 augustss ifp->if_timer = 0;
1654 1.1 augustss
1655 1.29 augustss aue_csr_write_1(sc, AUE_CTL0, 0);
1656 1.29 augustss aue_csr_write_1(sc, AUE_CTL1, 0);
1657 1.1 augustss aue_reset(sc);
1658 1.33 augustss usb_uncallout(sc->aue_stat_ch, aue_tick, sc);
1659 1.1 augustss
1660 1.1 augustss /* Stop transfers. */
1661 1.1 augustss if (sc->aue_ep[AUE_ENDPT_RX] != NULL) {
1662 1.1 augustss err = usbd_abort_pipe(sc->aue_ep[AUE_ENDPT_RX]);
1663 1.1 augustss if (err) {
1664 1.1 augustss printf("%s: abort rx pipe failed: %s\n",
1665 1.1 augustss USBDEVNAME(sc->aue_dev), usbd_errstr(err));
1666 1.1 augustss }
1667 1.1 augustss }
1668 1.1 augustss
1669 1.1 augustss if (sc->aue_ep[AUE_ENDPT_TX] != NULL) {
1670 1.1 augustss err = usbd_abort_pipe(sc->aue_ep[AUE_ENDPT_TX]);
1671 1.1 augustss if (err) {
1672 1.1 augustss printf("%s: abort tx pipe failed: %s\n",
1673 1.1 augustss USBDEVNAME(sc->aue_dev), usbd_errstr(err));
1674 1.1 augustss }
1675 1.1 augustss }
1676 1.1 augustss
1677 1.1 augustss if (sc->aue_ep[AUE_ENDPT_INTR] != NULL) {
1678 1.1 augustss err = usbd_abort_pipe(sc->aue_ep[AUE_ENDPT_INTR]);
1679 1.1 augustss if (err) {
1680 1.1 augustss printf("%s: abort intr pipe failed: %s\n",
1681 1.1 augustss USBDEVNAME(sc->aue_dev), usbd_errstr(err));
1682 1.1 augustss }
1683 1.99.10.2 itohy }
1684 1.99.10.2 itohy
1685 1.99.10.2 itohy /* Free RX/TX resources. */
1686 1.99.10.2 itohy usb_ether_rx_list_free(sc->aue_cdata.aue_rx_chain, AUE_RX_LIST_CNT);
1687 1.99.10.2 itohy usb_ether_tx_list_free(sc->aue_cdata.aue_tx_chain, AUE_TX_LIST_CNT);
1688 1.99.10.2 itohy
1689 1.99.10.2 itohy /* Close pipes. */
1690 1.99.10.2 itohy if (sc->aue_ep[AUE_ENDPT_RX] != NULL) {
1691 1.99.10.2 itohy err = usbd_close_pipe(sc->aue_ep[AUE_ENDPT_RX]);
1692 1.1 augustss if (err) {
1693 1.99.10.2 itohy printf("%s: close rx pipe failed: %s\n",
1694 1.1 augustss USBDEVNAME(sc->aue_dev), usbd_errstr(err));
1695 1.1 augustss }
1696 1.99.10.2 itohy sc->aue_ep[AUE_ENDPT_RX] = NULL;
1697 1.1 augustss }
1698 1.1 augustss
1699 1.99.10.2 itohy if (sc->aue_ep[AUE_ENDPT_TX] != NULL) {
1700 1.99.10.2 itohy err = usbd_close_pipe(sc->aue_ep[AUE_ENDPT_TX]);
1701 1.99.10.2 itohy if (err) {
1702 1.99.10.2 itohy printf("%s: close tx pipe failed: %s\n",
1703 1.99.10.2 itohy USBDEVNAME(sc->aue_dev), usbd_errstr(err));
1704 1.1 augustss }
1705 1.99.10.2 itohy sc->aue_ep[AUE_ENDPT_TX] = NULL;
1706 1.1 augustss }
1707 1.1 augustss
1708 1.99.10.2 itohy if (sc->aue_ep[AUE_ENDPT_INTR] != NULL) {
1709 1.99.10.2 itohy err = usbd_close_pipe(sc->aue_ep[AUE_ENDPT_INTR]);
1710 1.99.10.2 itohy if (err) {
1711 1.99.10.2 itohy printf("%s: close intr pipe failed: %s\n",
1712 1.99.10.2 itohy USBDEVNAME(sc->aue_dev), usbd_errstr(err));
1713 1.1 augustss }
1714 1.99.10.2 itohy sc->aue_ep[AUE_ENDPT_INTR] = NULL;
1715 1.1 augustss }
1716 1.1 augustss
1717 1.1 augustss sc->aue_link = 0;
1718 1.1 augustss
1719 1.1 augustss ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
1720 1.1 augustss }
1721 1.95 is
1722 1.95 is #if defined(__NetBSD__)
1723 1.95 is Static void
1724 1.95 is aue_multiwork(struct work *wkp, void *arg) {
1725 1.95 is struct aue_softc *sc;
1726 1.95 is
1727 1.95 is sc = (struct aue_softc *)arg;
1728 1.95 is (void)wkp;
1729 1.95 is
1730 1.99.10.2 itohy aue_init(GET_IFP(sc));
1731 1.95 is /* XXX called by aue_init, but rc ifconfig hangs without it: */
1732 1.95 is aue_setmulti(sc);
1733 1.95 is }
1734 1.95 is #endif
1735