Thu Mar 3 05:52:55 2022 UTC ()
aue(4): Reduce aue_uno_mcast from aue_uno_init to aue_setiff_locked.

This operation only needs to update the hardware to reflect
SIOCADDMULTI/SIOCDELMULTI.  Not clear that everything in aue(4) needs
to be reset -- in fact I'm pretty sure that's undesirable!

WARNING: I have not tested this with a real aue(4) device.


(riastradh)
diff -r1.177 -r1.178 src/sys/dev/usb/if_aue.c

cvs diff -r1.177 -r1.178 src/sys/dev/usb/if_aue.c (switch to unified diff)

--- src/sys/dev/usb/if_aue.c 2022/03/03 05:52:46 1.177
+++ src/sys/dev/usb/if_aue.c 2022/03/03 05:52:55 1.178
@@ -1,1037 +1,1033 @@ @@ -1,1037 +1,1033 @@
1/* $NetBSD: if_aue.c,v 1.177 2022/03/03 05:52:46 riastradh Exp $ */ 1/* $NetBSD: if_aue.c,v 1.178 2022/03/03 05:52:55 riastradh Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1997, 1998, 1999, 2000 4 * Copyright (c) 1997, 1998, 1999, 2000
5 * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved. 5 * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software 15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement: 16 * must display the following acknowledgement:
17 * This product includes software developed by Bill Paul. 17 * This product includes software developed by Bill Paul.
18 * 4. Neither the name of the author nor the names of any co-contributors 18 * 4. Neither the name of the author nor the names of any co-contributors
19 * may be used to endorse or promote products derived from this software 19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission. 20 * without specific prior written permission.
21 * 21 *
22 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND 22 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD 25 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32 * THE POSSIBILITY OF SUCH DAMAGE. 32 * THE POSSIBILITY OF SUCH DAMAGE.
33 * 33 *
34 * $FreeBSD: src/sys/dev/usb/if_aue.c,v 1.11 2000/01/14 01:36:14 wpaul Exp $ 34 * $FreeBSD: src/sys/dev/usb/if_aue.c,v 1.11 2000/01/14 01:36:14 wpaul Exp $
35 */ 35 */
36 36
37/* 37/*
38 * ADMtek AN986 Pegasus and AN8511 Pegasus II USB to ethernet driver. 38 * ADMtek AN986 Pegasus and AN8511 Pegasus II USB to ethernet driver.
39 * Datasheet is available from http://www.admtek.com.tw. 39 * Datasheet is available from http://www.admtek.com.tw.
40 * 40 *
41 * Written by Bill Paul <wpaul@ee.columbia.edu> 41 * Written by Bill Paul <wpaul@ee.columbia.edu>
42 * Electrical Engineering Department 42 * Electrical Engineering Department
43 * Columbia University, New York City 43 * Columbia University, New York City
44 */ 44 */
45 45
46/* 46/*
47 * The Pegasus chip uses four USB "endpoints" to provide 10/100 ethernet 47 * The Pegasus chip uses four USB "endpoints" to provide 10/100 ethernet
48 * support: the control endpoint for reading/writing registers, burst 48 * support: the control endpoint for reading/writing registers, burst
49 * read endpoint for packet reception, burst write for packet transmission 49 * read endpoint for packet reception, burst write for packet transmission
50 * and one for "interrupts." The chip uses the same RX filter scheme 50 * and one for "interrupts." The chip uses the same RX filter scheme
51 * as the other ADMtek ethernet parts: one perfect filter entry for the 51 * as the other ADMtek ethernet parts: one perfect filter entry for the
52 * the station address and a 64-bit multicast hash table. The chip supports 52 * the station address and a 64-bit multicast hash table. The chip supports
53 * both MII and HomePNA attachments. 53 * both MII and HomePNA attachments.
54 * 54 *
55 * Since the maximum data transfer speed of USB is supposed to be 12Mbps, 55 * Since the maximum data transfer speed of USB is supposed to be 12Mbps,
56 * you're never really going to get 100Mbps speeds from this device. I 56 * you're never really going to get 100Mbps speeds from this device. I
57 * think the idea is to allow the device to connect to 10 or 100Mbps 57 * think the idea is to allow the device to connect to 10 or 100Mbps
58 * networks, not necessarily to provide 100Mbps performance. Also, since 58 * networks, not necessarily to provide 100Mbps performance. Also, since
59 * the controller uses an external PHY chip, it's possible that board 59 * the controller uses an external PHY chip, it's possible that board
60 * designers might simply choose a 10Mbps PHY. 60 * designers might simply choose a 10Mbps PHY.
61 * 61 *
62 * Registers are accessed using usbd_do_request(). Packet transfers are 62 * Registers are accessed using usbd_do_request(). Packet transfers are
63 * done using usbd_transfer() and friends. 63 * done using usbd_transfer() and friends.
64 */ 64 */
65 65
66/* 66/*
67 * Ported to NetBSD and somewhat rewritten by Lennart Augustsson. 67 * Ported to NetBSD and somewhat rewritten by Lennart Augustsson.
68 */ 68 */
69 69
70/* 70/*
71 * TODO: 71 * TODO:
72 * better error messages from rxstat 72 * better error messages from rxstat
73 * more error checks 73 * more error checks
74 * investigate short rx problem 74 * investigate short rx problem
75 * proper cleanup on errors 75 * proper cleanup on errors
76 */ 76 */
77 77
78#include <sys/cdefs.h> 78#include <sys/cdefs.h>
79__KERNEL_RCSID(0, "$NetBSD: if_aue.c,v 1.177 2022/03/03 05:52:46 riastradh Exp $"); 79__KERNEL_RCSID(0, "$NetBSD: if_aue.c,v 1.178 2022/03/03 05:52:55 riastradh Exp $");
80 80
81#ifdef _KERNEL_OPT 81#ifdef _KERNEL_OPT
82#include "opt_usb.h" 82#include "opt_usb.h"
83#include "opt_inet.h" 83#include "opt_inet.h"
84#endif 84#endif
85 85
86#include <sys/param.h> 86#include <sys/param.h>
87 87
88#include <dev/usb/usbnet.h> 88#include <dev/usb/usbnet.h>
89#include <dev/usb/usbhist.h> 89#include <dev/usb/usbhist.h>
90#include <dev/usb/if_auereg.h> 90#include <dev/usb/if_auereg.h>
91 91
92#ifdef INET 92#ifdef INET
93#include <netinet/in.h> 93#include <netinet/in.h>
94#include <netinet/if_inarp.h> 94#include <netinet/if_inarp.h>
95#endif 95#endif
96 96
97#ifdef USB_DEBUG 97#ifdef USB_DEBUG
98#ifndef AUE_DEBUG 98#ifndef AUE_DEBUG
99#define auedebug 0 99#define auedebug 0
100#else 100#else
101static int auedebug = 10; 101static int auedebug = 10;
102 102
103SYSCTL_SETUP(sysctl_hw_aue_setup, "sysctl hw.aue setup") 103SYSCTL_SETUP(sysctl_hw_aue_setup, "sysctl hw.aue setup")
104{ 104{
105 int err; 105 int err;
106 const struct sysctlnode *rnode; 106 const struct sysctlnode *rnode;
107 const struct sysctlnode *cnode; 107 const struct sysctlnode *cnode;
108 108
109 err = sysctl_createv(clog, 0, NULL, &rnode, 109 err = sysctl_createv(clog, 0, NULL, &rnode,
110 CTLFLAG_PERMANENT, CTLTYPE_NODE, "aue", 110 CTLFLAG_PERMANENT, CTLTYPE_NODE, "aue",
111 SYSCTL_DESCR("aue global controls"), 111 SYSCTL_DESCR("aue global controls"),
112 NULL, 0, NULL, 0, CTL_HW, CTL_CREATE, CTL_EOL); 112 NULL, 0, NULL, 0, CTL_HW, CTL_CREATE, CTL_EOL);
113 113
114 if (err) 114 if (err)
115 goto fail; 115 goto fail;
116 116
117 /* control debugging printfs */ 117 /* control debugging printfs */
118 err = sysctl_createv(clog, 0, &rnode, &cnode, 118 err = sysctl_createv(clog, 0, &rnode, &cnode,
119 CTLFLAG_PERMANENT | CTLFLAG_READWRITE, CTLTYPE_INT, 119 CTLFLAG_PERMANENT | CTLFLAG_READWRITE, CTLTYPE_INT,
120 "debug", SYSCTL_DESCR("Enable debugging output"), 120 "debug", SYSCTL_DESCR("Enable debugging output"),
121 NULL, 0, &auedebug, sizeof(auedebug), CTL_CREATE, CTL_EOL); 121 NULL, 0, &auedebug, sizeof(auedebug), CTL_CREATE, CTL_EOL);
122 if (err) 122 if (err)
123 goto fail; 123 goto fail;
124 124
125 return; 125 return;
126fail: 126fail:
127 aprint_error("%s: sysctl_createv failed (err = %d)\n", __func__, err); 127 aprint_error("%s: sysctl_createv failed (err = %d)\n", __func__, err);
128} 128}
129 129
130#endif /* AUE_DEBUG */ 130#endif /* AUE_DEBUG */
131#endif /* USB_DEBUG */ 131#endif /* USB_DEBUG */
132 132
133#define DPRINTF(FMT,A,B,C,D) USBHIST_LOGN(auedebug,1,FMT,A,B,C,D) 133#define DPRINTF(FMT,A,B,C,D) USBHIST_LOGN(auedebug,1,FMT,A,B,C,D)
134#define DPRINTFN(N,FMT,A,B,C,D) USBHIST_LOGN(auedebug,N,FMT,A,B,C,D) 134#define DPRINTFN(N,FMT,A,B,C,D) USBHIST_LOGN(auedebug,N,FMT,A,B,C,D)
135#define AUEHIST_FUNC() USBHIST_FUNC() 135#define AUEHIST_FUNC() USBHIST_FUNC()
136#define AUEHIST_CALLED(name) USBHIST_CALLED(auedebug) 136#define AUEHIST_CALLED(name) USBHIST_CALLED(auedebug)
137#define AUEHIST_CALLARGS(FMT,A,B,C,D) \ 137#define AUEHIST_CALLARGS(FMT,A,B,C,D) \
138 USBHIST_CALLARGS(auedebug,FMT,A,B,C,D) 138 USBHIST_CALLARGS(auedebug,FMT,A,B,C,D)
139#define AUEHIST_CALLARGSN(N,FMT,A,B,C,D) \ 139#define AUEHIST_CALLARGSN(N,FMT,A,B,C,D) \
140 USBHIST_CALLARGSN(auedebug,N,FMT,A,B,C,D) 140 USBHIST_CALLARGSN(auedebug,N,FMT,A,B,C,D)
141 141
142#define AUE_TX_LIST_CNT 1 142#define AUE_TX_LIST_CNT 1
143#define AUE_RX_LIST_CNT 1 143#define AUE_RX_LIST_CNT 1
144 144
145struct aue_softc { 145struct aue_softc {
146 struct usbnet aue_un; 146 struct usbnet aue_un;
147 struct usbnet_intr aue_intr; 147 struct usbnet_intr aue_intr;
148 struct aue_intrpkt aue_ibuf; 148 struct aue_intrpkt aue_ibuf;
149}; 149};
150 150
151#define AUE_TIMEOUT 1000 151#define AUE_TIMEOUT 1000
152#define AUE_BUFSZ 1536 152#define AUE_BUFSZ 1536
153#define AUE_MIN_FRAMELEN 60 153#define AUE_MIN_FRAMELEN 60
154#define AUE_TX_TIMEOUT 10000 /* ms */ 154#define AUE_TX_TIMEOUT 10000 /* ms */
155#define AUE_INTR_INTERVAL 100 /* ms */ 155#define AUE_INTR_INTERVAL 100 /* ms */
156 156
157/* 157/*
158 * Various supported device vendors/products. 158 * Various supported device vendors/products.
159 */ 159 */
160struct aue_type { 160struct aue_type {
161 struct usb_devno aue_dev; 161 struct usb_devno aue_dev;
162 uint16_t aue_flags; 162 uint16_t aue_flags;
163#define LSYS 0x0001 /* use Linksys reset */ 163#define LSYS 0x0001 /* use Linksys reset */
164#define PNA 0x0002 /* has Home PNA */ 164#define PNA 0x0002 /* has Home PNA */
165#define PII 0x0004 /* Pegasus II chip */ 165#define PII 0x0004 /* Pegasus II chip */
166}; 166};
167 167
168static const struct aue_type aue_devs[] = { 168static const struct aue_type aue_devs[] = {
169 {{ USB_VENDOR_3COM, USB_PRODUCT_3COM_3C460B}, PII }, 169 {{ USB_VENDOR_3COM, USB_PRODUCT_3COM_3C460B}, PII },
170 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX1}, PNA | PII }, 170 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX1}, PNA | PII },
171 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX2}, PII }, 171 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX2}, PII },
172 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_UFE1000}, LSYS }, 172 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_UFE1000}, LSYS },
173 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX4}, PNA }, 173 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX4}, PNA },
174 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX5}, PNA }, 174 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX5}, PNA },
175 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX6}, PII }, 175 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX6}, PII },
176 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX7}, PII }, 176 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX7}, PII },
177 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX8}, PII }, 177 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX8}, PII },
178 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX9}, PNA }, 178 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX9}, PNA },
179 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX10}, 0 }, 179 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX10}, 0 },
180 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_DSB650TX_PNA}, 0 }, 180 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_DSB650TX_PNA}, 0 },
181 {{ USB_VENDOR_ACCTON, USB_PRODUCT_ACCTON_USB320_EC}, 0 }, 181 {{ USB_VENDOR_ACCTON, USB_PRODUCT_ACCTON_USB320_EC}, 0 },
182 {{ USB_VENDOR_ACCTON, USB_PRODUCT_ACCTON_SS1001}, PII }, 182 {{ USB_VENDOR_ACCTON, USB_PRODUCT_ACCTON_SS1001}, PII },
183 {{ USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUS}, PNA }, 183 {{ USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUS}, PNA },
184 {{ USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUSII}, PII }, 184 {{ USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUSII}, PII },
185 {{ USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUSII_2}, PII }, 185 {{ USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUSII_2}, PII },
186 {{ USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUSII_3}, PII }, 186 {{ USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUSII_3}, PII },
187 {{ USB_VENDOR_AEI, USB_PRODUCT_AEI_USBTOLAN}, PII }, 187 {{ USB_VENDOR_AEI, USB_PRODUCT_AEI_USBTOLAN}, PII },
188 {{ USB_VENDOR_BELKIN, USB_PRODUCT_BELKIN_USB2LAN}, PII }, 188 {{ USB_VENDOR_BELKIN, USB_PRODUCT_BELKIN_USB2LAN}, PII },
189 {{ USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USB100}, 0 }, 189 {{ USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USB100}, 0 },
190 {{ USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USBLP100}, PNA }, 190 {{ USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USBLP100}, PNA },
191 {{ USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USBEL100}, 0 }, 191 {{ USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USBEL100}, 0 },
192 {{ USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USBE100}, PII }, 192 {{ USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USBE100}, PII },
193 {{ USB_VENDOR_COMPAQ, USB_PRODUCT_COMPAQ_HNE200}, PII }, 193 {{ USB_VENDOR_COMPAQ, USB_PRODUCT_COMPAQ_HNE200}, PII },
194 {{ USB_VENDOR_COREGA, USB_PRODUCT_COREGA_FETHER_USB_TX}, 0 }, 194 {{ USB_VENDOR_COREGA, USB_PRODUCT_COREGA_FETHER_USB_TX}, 0 },
195 {{ USB_VENDOR_COREGA, USB_PRODUCT_COREGA_FETHER_USB_TXS},PII }, 195 {{ USB_VENDOR_COREGA, USB_PRODUCT_COREGA_FETHER_USB_TXS},PII },
196 {{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX4}, LSYS | PII }, 196 {{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX4}, LSYS | PII },
197 {{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX1}, LSYS }, 197 {{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX1}, LSYS },
198 {{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX}, LSYS }, 198 {{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX}, LSYS },
199 {{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX_PNA}, PNA }, 199 {{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX_PNA}, PNA },
200 {{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX3}, LSYS | PII }, 200 {{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX3}, LSYS | PII },
201 {{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX2}, LSYS | PII }, 201 {{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX2}, LSYS | PII },
202 {{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650}, 0 }, 202 {{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650}, 0 },
203 {{ USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX0}, 0 }, 203 {{ USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX0}, 0 },
204 {{ USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX1}, LSYS }, 204 {{ USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX1}, LSYS },
205 {{ USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX2}, 0 }, 205 {{ USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX2}, 0 },
206 {{ USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX3}, LSYS }, 206 {{ USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX3}, LSYS },
207 {{ USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBLTX}, PII }, 207 {{ USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBLTX}, PII },
208 {{ USB_VENDOR_ELSA, USB_PRODUCT_ELSA_USB2ETHERNET}, 0 }, 208 {{ USB_VENDOR_ELSA, USB_PRODUCT_ELSA_USB2ETHERNET}, 0 },
209 {{ USB_VENDOR_HAWKING, USB_PRODUCT_HAWKING_UF100}, PII }, 209 {{ USB_VENDOR_HAWKING, USB_PRODUCT_HAWKING_UF100}, PII },
210 {{ USB_VENDOR_HP, USB_PRODUCT_HP_HN210E}, PII }, 210 {{ USB_VENDOR_HP, USB_PRODUCT_HP_HN210E}, PII },
211 {{ USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBETTX}, 0 }, 211 {{ USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBETTX}, 0 },
212 {{ USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBETTXS}, PII }, 212 {{ USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBETTXS}, PII },
213 {{ USB_VENDOR_IODATA, USB_PRODUCT_IODATA_ETXUS2}, PII }, 213 {{ USB_VENDOR_IODATA, USB_PRODUCT_IODATA_ETXUS2}, PII },
214 {{ USB_VENDOR_KINGSTON, USB_PRODUCT_KINGSTON_KNU101TX}, 0 }, 214 {{ USB_VENDOR_KINGSTON, USB_PRODUCT_KINGSTON_KNU101TX}, 0 },
215 {{ USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10TX1}, LSYS | PII }, 215 {{ USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10TX1}, LSYS | PII },
216 {{ USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10T}, LSYS }, 216 {{ USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10T}, LSYS },
217 {{ USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB100TX}, LSYS }, 217 {{ USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB100TX}, LSYS },
218 {{ USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB100H1}, LSYS | PNA }, 218 {{ USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB100H1}, LSYS | PNA },
219 {{ USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10TA}, LSYS }, 219 {{ USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10TA}, LSYS },
220 {{ USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10TX2}, LSYS | PII }, 220 {{ USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10TX2}, LSYS | PII },
221 {{ USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUATX1}, 0 }, 221 {{ USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUATX1}, 0 },
222 {{ USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUATX5}, 0 }, 222 {{ USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUATX5}, 0 },
223 {{ USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUA2TX5}, PII }, 223 {{ USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUA2TX5}, PII },
224 {{ USB_VENDOR_MICROSOFT, USB_PRODUCT_MICROSOFT_MN110}, PII }, 224 {{ USB_VENDOR_MICROSOFT, USB_PRODUCT_MICROSOFT_MN110}, PII },
225 {{ USB_VENDOR_NETGEAR, USB_PRODUCT_NETGEAR_FA101}, PII }, 225 {{ USB_VENDOR_NETGEAR, USB_PRODUCT_NETGEAR_FA101}, PII },
226 {{ USB_VENDOR_SIEMENS, USB_PRODUCT_SIEMENS_SPEEDSTREAM}, PII }, 226 {{ USB_VENDOR_SIEMENS, USB_PRODUCT_SIEMENS_SPEEDSTREAM}, PII },
227 {{ USB_VENDOR_SMARTBRIDGES, USB_PRODUCT_SMARTBRIDGES_SMARTNIC},PII }, 227 {{ USB_VENDOR_SMARTBRIDGES, USB_PRODUCT_SMARTBRIDGES_SMARTNIC},PII },
228 {{ USB_VENDOR_SMC, USB_PRODUCT_SMC_2202USB}, 0 }, 228 {{ USB_VENDOR_SMC, USB_PRODUCT_SMC_2202USB}, 0 },
229 {{ USB_VENDOR_SMC, USB_PRODUCT_SMC_2206USB}, PII }, 229 {{ USB_VENDOR_SMC, USB_PRODUCT_SMC_2206USB}, PII },
230 {{ USB_VENDOR_SOHOWARE, USB_PRODUCT_SOHOWARE_NUB100}, 0 }, 230 {{ USB_VENDOR_SOHOWARE, USB_PRODUCT_SOHOWARE_NUB100}, 0 },
231}; 231};
232#define aue_lookup(v, p) ((const struct aue_type *)usb_lookup(aue_devs, v, p)) 232#define aue_lookup(v, p) ((const struct aue_type *)usb_lookup(aue_devs, v, p))
233 233
234static int aue_match(device_t, cfdata_t, void *); 234static int aue_match(device_t, cfdata_t, void *);
235static void aue_attach(device_t, device_t, void *); 235static void aue_attach(device_t, device_t, void *);
236 236
237CFATTACH_DECL_NEW(aue, sizeof(struct aue_softc), aue_match, aue_attach, 237CFATTACH_DECL_NEW(aue, sizeof(struct aue_softc), aue_match, aue_attach,
238 usbnet_detach, usbnet_activate); 238 usbnet_detach, usbnet_activate);
239 239
240static void aue_reset_pegasus_II(struct aue_softc *); 240static void aue_reset_pegasus_II(struct aue_softc *);
241 241
242static void aue_uno_stop(struct ifnet *, int); 242static void aue_uno_stop(struct ifnet *, int);
243static void aue_uno_mcast(struct ifnet *); 243static void aue_uno_mcast(struct ifnet *);
244static int aue_uno_mii_read_reg(struct usbnet *, int, int, uint16_t *); 244static int aue_uno_mii_read_reg(struct usbnet *, int, int, uint16_t *);
245static int aue_uno_mii_write_reg(struct usbnet *, int, int, uint16_t); 245static int aue_uno_mii_write_reg(struct usbnet *, int, int, uint16_t);
246static void aue_uno_mii_statchg(struct ifnet *); 246static void aue_uno_mii_statchg(struct ifnet *);
247static unsigned aue_uno_tx_prepare(struct usbnet *, struct mbuf *, 247static unsigned aue_uno_tx_prepare(struct usbnet *, struct mbuf *,
248 struct usbnet_chain *); 248 struct usbnet_chain *);
249static void aue_uno_rx_loop(struct usbnet *, struct usbnet_chain *, uint32_t); 249static void aue_uno_rx_loop(struct usbnet *, struct usbnet_chain *, uint32_t);
250static int aue_uno_init(struct ifnet *); 250static int aue_uno_init(struct ifnet *);
251static void aue_uno_intr(struct usbnet *, usbd_status); 251static void aue_uno_intr(struct usbnet *, usbd_status);
252 252
253static const struct usbnet_ops aue_ops = { 253static const struct usbnet_ops aue_ops = {
254 .uno_stop = aue_uno_stop, 254 .uno_stop = aue_uno_stop,
255 .uno_mcast = aue_uno_mcast, 255 .uno_mcast = aue_uno_mcast,
256 .uno_read_reg = aue_uno_mii_read_reg, 256 .uno_read_reg = aue_uno_mii_read_reg,
257 .uno_write_reg = aue_uno_mii_write_reg, 257 .uno_write_reg = aue_uno_mii_write_reg,
258 .uno_statchg = aue_uno_mii_statchg, 258 .uno_statchg = aue_uno_mii_statchg,
259 .uno_tx_prepare = aue_uno_tx_prepare, 259 .uno_tx_prepare = aue_uno_tx_prepare,
260 .uno_rx_loop = aue_uno_rx_loop, 260 .uno_rx_loop = aue_uno_rx_loop,
261 .uno_init = aue_uno_init, 261 .uno_init = aue_uno_init,
262 .uno_intr = aue_uno_intr, 262 .uno_intr = aue_uno_intr,
263}; 263};
264 264
265static uint32_t aue_crc(void *); 265static uint32_t aue_crc(void *);
266static void aue_reset(struct aue_softc *); 266static void aue_reset(struct aue_softc *);
267 267
268static int aue_csr_read_1(struct aue_softc *, int); 268static int aue_csr_read_1(struct aue_softc *, int);
269static int aue_csr_write_1(struct aue_softc *, int, int); 269static int aue_csr_write_1(struct aue_softc *, int, int);
270static int aue_csr_read_2(struct aue_softc *, int); 270static int aue_csr_read_2(struct aue_softc *, int);
271static int aue_csr_write_2(struct aue_softc *, int, int); 271static int aue_csr_write_2(struct aue_softc *, int, int);
272 272
273#define AUE_SETBIT(sc, reg, x) \ 273#define AUE_SETBIT(sc, reg, x) \
274 aue_csr_write_1(sc, reg, aue_csr_read_1(sc, reg) | (x)) 274 aue_csr_write_1(sc, reg, aue_csr_read_1(sc, reg) | (x))
275 275
276#define AUE_CLRBIT(sc, reg, x) \ 276#define AUE_CLRBIT(sc, reg, x) \
277 aue_csr_write_1(sc, reg, aue_csr_read_1(sc, reg) & ~(x)) 277 aue_csr_write_1(sc, reg, aue_csr_read_1(sc, reg) & ~(x))
278 278
279static int 279static int
280aue_csr_read_1(struct aue_softc *sc, int reg) 280aue_csr_read_1(struct aue_softc *sc, int reg)
281{ 281{
282 struct usbnet * const un = &sc->aue_un; 282 struct usbnet * const un = &sc->aue_un;
283 usb_device_request_t req; 283 usb_device_request_t req;
284 usbd_status err; 284 usbd_status err;
285 uByte val = 0; 285 uByte val = 0;
286 286
287 usbnet_isowned_core(un); 287 usbnet_isowned_core(un);
288 288
289 if (usbnet_isdying(un)) 289 if (usbnet_isdying(un))
290 return 0; 290 return 0;
291 291
292 req.bmRequestType = UT_READ_VENDOR_DEVICE; 292 req.bmRequestType = UT_READ_VENDOR_DEVICE;
293 req.bRequest = AUE_UR_READREG; 293 req.bRequest = AUE_UR_READREG;
294 USETW(req.wValue, 0); 294 USETW(req.wValue, 0);
295 USETW(req.wIndex, reg); 295 USETW(req.wIndex, reg);
296 USETW(req.wLength, 1); 296 USETW(req.wLength, 1);
297 297
298 err = usbd_do_request(un->un_udev, &req, &val); 298 err = usbd_do_request(un->un_udev, &req, &val);
299 299
300 if (err) { 300 if (err) {
301 AUEHIST_FUNC(); 301 AUEHIST_FUNC();
302 AUEHIST_CALLARGS("aue%jd: reg=%#jx err=%jd", 302 AUEHIST_CALLARGS("aue%jd: reg=%#jx err=%jd",
303 device_unit(un->un_dev), reg, err, 0); 303 device_unit(un->un_dev), reg, err, 0);
304 return 0; 304 return 0;
305 } 305 }
306 306
307 return val; 307 return val;
308} 308}
309 309
310static int 310static int
311aue_csr_read_2(struct aue_softc *sc, int reg) 311aue_csr_read_2(struct aue_softc *sc, int reg)
312{ 312{
313 struct usbnet * const un = &sc->aue_un; 313 struct usbnet * const un = &sc->aue_un;
314 usb_device_request_t req; 314 usb_device_request_t req;
315 usbd_status err; 315 usbd_status err;
316 uWord val; 316 uWord val;
317 317
318 usbnet_isowned_core(un); 318 usbnet_isowned_core(un);
319 319
320 if (usbnet_isdying(un)) 320 if (usbnet_isdying(un))
321 return 0; 321 return 0;
322 322
323 req.bmRequestType = UT_READ_VENDOR_DEVICE; 323 req.bmRequestType = UT_READ_VENDOR_DEVICE;
324 req.bRequest = AUE_UR_READREG; 324 req.bRequest = AUE_UR_READREG;
325 USETW(req.wValue, 0); 325 USETW(req.wValue, 0);
326 USETW(req.wIndex, reg); 326 USETW(req.wIndex, reg);
327 USETW(req.wLength, 2); 327 USETW(req.wLength, 2);
328 328
329 err = usbd_do_request(un->un_udev, &req, &val); 329 err = usbd_do_request(un->un_udev, &req, &val);
330 330
331 if (err) { 331 if (err) {
332 AUEHIST_FUNC(); 332 AUEHIST_FUNC();
333 AUEHIST_CALLARGS("aue%jd: reg=%#jx err=%jd", 333 AUEHIST_CALLARGS("aue%jd: reg=%#jx err=%jd",
334 device_unit(un->un_dev), reg, err, 0); 334 device_unit(un->un_dev), reg, err, 0);
335 return 0; 335 return 0;
336 } 336 }
337 337
338 return UGETW(val); 338 return UGETW(val);
339} 339}
340 340
341static int 341static int
342aue_csr_write_1(struct aue_softc *sc, int reg, int aval) 342aue_csr_write_1(struct aue_softc *sc, int reg, int aval)
343{ 343{
344 struct usbnet * const un = &sc->aue_un; 344 struct usbnet * const un = &sc->aue_un;
345 usb_device_request_t req; 345 usb_device_request_t req;
346 usbd_status err; 346 usbd_status err;
347 uByte val; 347 uByte val;
348 348
349 usbnet_isowned_core(un); 349 usbnet_isowned_core(un);
350 350
351 if (usbnet_isdying(un)) 351 if (usbnet_isdying(un))
352 return 0; 352 return 0;
353 353
354 val = aval; 354 val = aval;
355 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 355 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
356 req.bRequest = AUE_UR_WRITEREG; 356 req.bRequest = AUE_UR_WRITEREG;
357 USETW(req.wValue, val); 357 USETW(req.wValue, val);
358 USETW(req.wIndex, reg); 358 USETW(req.wIndex, reg);
359 USETW(req.wLength, 1); 359 USETW(req.wLength, 1);
360 360
361 err = usbd_do_request(un->un_udev, &req, &val); 361 err = usbd_do_request(un->un_udev, &req, &val);
362 362
363 if (err) { 363 if (err) {
364 AUEHIST_FUNC(); 364 AUEHIST_FUNC();
365 AUEHIST_CALLARGS("aue%jd: reg=%#jx err=%jd", 365 AUEHIST_CALLARGS("aue%jd: reg=%#jx err=%jd",
366 device_unit(un->un_dev), reg, err, 0); 366 device_unit(un->un_dev), reg, err, 0);
367 return -1; 367 return -1;
368 } 368 }
369 369
370 return 0; 370 return 0;
371} 371}
372 372
373static int 373static int
374aue_csr_write_2(struct aue_softc *sc, int reg, int aval) 374aue_csr_write_2(struct aue_softc *sc, int reg, int aval)
375{ 375{
376 struct usbnet * const un = &sc->aue_un; 376 struct usbnet * const un = &sc->aue_un;
377 usb_device_request_t req; 377 usb_device_request_t req;
378 usbd_status err; 378 usbd_status err;
379 uWord val; 379 uWord val;
380 380
381 usbnet_isowned_core(un); 381 usbnet_isowned_core(un);
382 382
383 if (usbnet_isdying(un)) 383 if (usbnet_isdying(un))
384 return 0; 384 return 0;
385 385
386 USETW(val, aval); 386 USETW(val, aval);
387 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 387 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
388 req.bRequest = AUE_UR_WRITEREG; 388 req.bRequest = AUE_UR_WRITEREG;
389 USETW(req.wValue, aval); 389 USETW(req.wValue, aval);
390 USETW(req.wIndex, reg); 390 USETW(req.wIndex, reg);
391 USETW(req.wLength, 2); 391 USETW(req.wLength, 2);
392 392
393 err = usbd_do_request(un->un_udev, &req, &val); 393 err = usbd_do_request(un->un_udev, &req, &val);
394 394
395 if (err) { 395 if (err) {
396 AUEHIST_FUNC(); 396 AUEHIST_FUNC();
397 AUEHIST_CALLARGS("aue%jd: reg=%#jx err=%jd", 397 AUEHIST_CALLARGS("aue%jd: reg=%#jx err=%jd",
398 device_unit(un->un_dev), reg, err, 0); 398 device_unit(un->un_dev), reg, err, 0);
399 return -1; 399 return -1;
400 } 400 }
401 401
402 return 0; 402 return 0;
403} 403}
404 404
405/* 405/*
406 * Read a word of data stored in the EEPROM at address 'addr.' 406 * Read a word of data stored in the EEPROM at address 'addr.'
407 */ 407 */
408static int 408static int
409aue_eeprom_getword(struct aue_softc *sc, int addr) 409aue_eeprom_getword(struct aue_softc *sc, int addr)
410{ 410{
411 struct usbnet * const un = &sc->aue_un; 411 struct usbnet * const un = &sc->aue_un;
412 int i; 412 int i;
413 413
414 AUEHIST_FUNC(); AUEHIST_CALLED(); 414 AUEHIST_FUNC(); AUEHIST_CALLED();
415 415
416 aue_csr_write_1(sc, AUE_EE_REG, addr); 416 aue_csr_write_1(sc, AUE_EE_REG, addr);
417 aue_csr_write_1(sc, AUE_EE_CTL, AUE_EECTL_READ); 417 aue_csr_write_1(sc, AUE_EE_CTL, AUE_EECTL_READ);
418 418
419 for (i = 0; i < AUE_TIMEOUT; i++) { 419 for (i = 0; i < AUE_TIMEOUT; i++) {
420 if (aue_csr_read_1(sc, AUE_EE_CTL) & AUE_EECTL_DONE) 420 if (aue_csr_read_1(sc, AUE_EE_CTL) & AUE_EECTL_DONE)
421 break; 421 break;
422 } 422 }
423 423
424 if (i == AUE_TIMEOUT) { 424 if (i == AUE_TIMEOUT) {
425 printf("%s: EEPROM read timed out\n", 425 printf("%s: EEPROM read timed out\n",
426 device_xname(un->un_dev)); 426 device_xname(un->un_dev));
427 } 427 }
428 428
429 return aue_csr_read_2(sc, AUE_EE_DATA); 429 return aue_csr_read_2(sc, AUE_EE_DATA);
430} 430}
431 431
432/* 432/*
433 * Read the MAC from the EEPROM. It's at offset 0. 433 * Read the MAC from the EEPROM. It's at offset 0.
434 */ 434 */
435static void 435static void
436aue_read_mac(struct usbnet *un) 436aue_read_mac(struct usbnet *un)
437{ 437{
438 struct aue_softc *sc = usbnet_softc(un); 438 struct aue_softc *sc = usbnet_softc(un);
439 int i; 439 int i;
440 int off = 0; 440 int off = 0;
441 int word; 441 int word;
442 442
443 usbnet_isowned_core(un); 443 usbnet_isowned_core(un);
444 444
445 AUEHIST_FUNC(); 445 AUEHIST_FUNC();
446 AUEHIST_CALLARGS("aue%jd: enter", 446 AUEHIST_CALLARGS("aue%jd: enter",
447 device_unit(un->un_dev), 0, 0, 0); 447 device_unit(un->un_dev), 0, 0, 0);
448 448
449 for (i = 0; i < 3; i++) { 449 for (i = 0; i < 3; i++) {
450 word = aue_eeprom_getword(sc, off + i); 450 word = aue_eeprom_getword(sc, off + i);
451 un->un_eaddr[2 * i] = (u_char)word; 451 un->un_eaddr[2 * i] = (u_char)word;
452 un->un_eaddr[2 * i + 1] = (u_char)(word >> 8); 452 un->un_eaddr[2 * i + 1] = (u_char)(word >> 8);
453 } 453 }
454} 454}
455 455
456static int 456static int
457aue_uno_mii_read_reg(struct usbnet *un, int phy, int reg, uint16_t *val) 457aue_uno_mii_read_reg(struct usbnet *un, int phy, int reg, uint16_t *val)
458{ 458{
459 struct aue_softc *sc = usbnet_softc(un); 459 struct aue_softc *sc = usbnet_softc(un);
460 int i; 460 int i;
461 461
462 AUEHIST_FUNC(); 462 AUEHIST_FUNC();
463 463
464#if 0 464#if 0
465 /* 465 /*
466 * The Am79C901 HomePNA PHY actually contains 466 * The Am79C901 HomePNA PHY actually contains
467 * two transceivers: a 1Mbps HomePNA PHY and a 467 * two transceivers: a 1Mbps HomePNA PHY and a
468 * 10Mbps full/half duplex ethernet PHY with 468 * 10Mbps full/half duplex ethernet PHY with
469 * NWAY autoneg. However in the ADMtek adapter, 469 * NWAY autoneg. However in the ADMtek adapter,
470 * only the 1Mbps PHY is actually connected to 470 * only the 1Mbps PHY is actually connected to
471 * anything, so we ignore the 10Mbps one. It 471 * anything, so we ignore the 10Mbps one. It
472 * happens to be configured for MII address 3, 472 * happens to be configured for MII address 3,
473 * so we filter that out. 473 * so we filter that out.
474 */ 474 */
475 if (sc->aue_vendor == USB_VENDOR_ADMTEK && 475 if (sc->aue_vendor == USB_VENDOR_ADMTEK &&
476 sc->aue_product == USB_PRODUCT_ADMTEK_PEGASUS) { 476 sc->aue_product == USB_PRODUCT_ADMTEK_PEGASUS) {
477 if (phy == 3) 477 if (phy == 3)
478 return EINVAL; 478 return EINVAL;
479 } 479 }
480#endif 480#endif
481 481
482 aue_csr_write_1(sc, AUE_PHY_ADDR, phy); 482 aue_csr_write_1(sc, AUE_PHY_ADDR, phy);
483 aue_csr_write_1(sc, AUE_PHY_CTL, reg | AUE_PHYCTL_READ); 483 aue_csr_write_1(sc, AUE_PHY_CTL, reg | AUE_PHYCTL_READ);
484 484
485 for (i = 0; i < AUE_TIMEOUT; i++) { 485 for (i = 0; i < AUE_TIMEOUT; i++) {
486 if (usbnet_isdying(un)) 486 if (usbnet_isdying(un))
487 return ENXIO; 487 return ENXIO;
488 if (aue_csr_read_1(sc, AUE_PHY_CTL) & AUE_PHYCTL_DONE) 488 if (aue_csr_read_1(sc, AUE_PHY_CTL) & AUE_PHYCTL_DONE)
489 break; 489 break;
490 } 490 }
491 491
492 if (i == AUE_TIMEOUT) { 492 if (i == AUE_TIMEOUT) {
493 AUEHIST_CALLARGS("aue%jd: phy=%#jx reg=%#jx read timed out", 493 AUEHIST_CALLARGS("aue%jd: phy=%#jx reg=%#jx read timed out",
494 device_unit(un->un_dev), phy, reg, 0); 494 device_unit(un->un_dev), phy, reg, 0);
495 return ETIMEDOUT; 495 return ETIMEDOUT;
496 } 496 }
497 497
498 *val = aue_csr_read_2(sc, AUE_PHY_DATA); 498 *val = aue_csr_read_2(sc, AUE_PHY_DATA);
499 499
500 AUEHIST_CALLARGSN(11, "aue%jd: phy=%#jx reg=%#jx => 0x%04jx", 500 AUEHIST_CALLARGSN(11, "aue%jd: phy=%#jx reg=%#jx => 0x%04jx",
501 device_unit(un->un_dev), phy, reg, *val); 501 device_unit(un->un_dev), phy, reg, *val);
502 502
503 return 0; 503 return 0;
504} 504}
505 505
506static int 506static int
507aue_uno_mii_write_reg(struct usbnet *un, int phy, int reg, uint16_t val) 507aue_uno_mii_write_reg(struct usbnet *un, int phy, int reg, uint16_t val)
508{ 508{
509 struct aue_softc *sc = usbnet_softc(un); 509 struct aue_softc *sc = usbnet_softc(un);
510 int i; 510 int i;
511 511
512 AUEHIST_FUNC(); 512 AUEHIST_FUNC();
513 AUEHIST_CALLARGSN(11, "aue%jd: phy=%jd reg=%jd data=0x%04jx", 513 AUEHIST_CALLARGSN(11, "aue%jd: phy=%jd reg=%jd data=0x%04jx",
514 device_unit(un->un_dev), phy, reg, val); 514 device_unit(un->un_dev), phy, reg, val);
515 515
516#if 0 516#if 0
517 if (sc->aue_vendor == USB_VENDOR_ADMTEK && 517 if (sc->aue_vendor == USB_VENDOR_ADMTEK &&
518 sc->aue_product == USB_PRODUCT_ADMTEK_PEGASUS) { 518 sc->aue_product == USB_PRODUCT_ADMTEK_PEGASUS) {
519 if (phy == 3) 519 if (phy == 3)
520 return EINVAL; 520 return EINVAL;
521 } 521 }
522#endif 522#endif
523 523
524 aue_csr_write_2(sc, AUE_PHY_DATA, val); 524 aue_csr_write_2(sc, AUE_PHY_DATA, val);
525 aue_csr_write_1(sc, AUE_PHY_ADDR, phy); 525 aue_csr_write_1(sc, AUE_PHY_ADDR, phy);
526 aue_csr_write_1(sc, AUE_PHY_CTL, reg | AUE_PHYCTL_WRITE); 526 aue_csr_write_1(sc, AUE_PHY_CTL, reg | AUE_PHYCTL_WRITE);
527 527
528 for (i = 0; i < AUE_TIMEOUT; i++) { 528 for (i = 0; i < AUE_TIMEOUT; i++) {
529 if (usbnet_isdying(un)) 529 if (usbnet_isdying(un))
530 return ENXIO; 530 return ENXIO;
531 if (aue_csr_read_1(sc, AUE_PHY_CTL) & AUE_PHYCTL_DONE) 531 if (aue_csr_read_1(sc, AUE_PHY_CTL) & AUE_PHYCTL_DONE)
532 break; 532 break;
533 } 533 }
534 534
535 if (i == AUE_TIMEOUT) { 535 if (i == AUE_TIMEOUT) {
536 DPRINTF("aue%jd: phy=%#jx reg=%#jx val=%#jx write timed out", 536 DPRINTF("aue%jd: phy=%#jx reg=%#jx val=%#jx write timed out",
537 device_unit(un->un_dev), phy, reg, val); 537 device_unit(un->un_dev), phy, reg, val);
538 return ETIMEDOUT; 538 return ETIMEDOUT;
539 } 539 }
540 540
541 return 0; 541 return 0;
542} 542}
543 543
544static void 544static void
545aue_uno_mii_statchg(struct ifnet *ifp) 545aue_uno_mii_statchg(struct ifnet *ifp)
546{ 546{
547 struct usbnet *un = ifp->if_softc; 547 struct usbnet *un = ifp->if_softc;
548 struct aue_softc *sc = usbnet_softc(un); 548 struct aue_softc *sc = usbnet_softc(un);
549 struct mii_data *mii = usbnet_mii(un); 549 struct mii_data *mii = usbnet_mii(un);
550 const bool hadlink __diagused = usbnet_havelink(un); 550 const bool hadlink __diagused = usbnet_havelink(un);
551 551
552 AUEHIST_FUNC(); AUEHIST_CALLED(); 552 AUEHIST_FUNC(); AUEHIST_CALLED();
553 AUEHIST_CALLARGSN(5, "aue%jd: ifp=%#jx link=%jd", 553 AUEHIST_CALLARGSN(5, "aue%jd: ifp=%#jx link=%jd",
554 device_unit(un->un_dev), (uintptr_t)ifp, hadlink, 0); 554 device_unit(un->un_dev), (uintptr_t)ifp, hadlink, 0);
555 555
556 AUE_CLRBIT(sc, AUE_CTL0, AUE_CTL0_RX_ENB | AUE_CTL0_TX_ENB); 556 AUE_CLRBIT(sc, AUE_CTL0, AUE_CTL0_RX_ENB | AUE_CTL0_TX_ENB);
557 557
558 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_100_TX) { 558 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_100_TX) {
559 AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_SPEEDSEL); 559 AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_SPEEDSEL);
560 } else { 560 } else {
561 AUE_CLRBIT(sc, AUE_CTL1, AUE_CTL1_SPEEDSEL); 561 AUE_CLRBIT(sc, AUE_CTL1, AUE_CTL1_SPEEDSEL);
562 } 562 }
563 563
564 if ((mii->mii_media_active & IFM_FDX) != 0) 564 if ((mii->mii_media_active & IFM_FDX) != 0)
565 AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_DUPLEX); 565 AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_DUPLEX);
566 else 566 else
567 AUE_CLRBIT(sc, AUE_CTL1, AUE_CTL1_DUPLEX); 567 AUE_CLRBIT(sc, AUE_CTL1, AUE_CTL1_DUPLEX);
568 568
569 AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_RX_ENB | AUE_CTL0_TX_ENB); 569 AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_RX_ENB | AUE_CTL0_TX_ENB);
570 570
571 if (mii->mii_media_status & IFM_ACTIVE && 571 if (mii->mii_media_status & IFM_ACTIVE &&
572 IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) { 572 IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
573 usbnet_set_link(un, true); 573 usbnet_set_link(un, true);
574 } 574 }
575 575
576 /* 576 /*
577 * Set the LED modes on the LinkSys adapter. 577 * Set the LED modes on the LinkSys adapter.
578 * This turns on the 'dual link LED' bin in the auxmode 578 * This turns on the 'dual link LED' bin in the auxmode
579 * register of the Broadcom PHY. 579 * register of the Broadcom PHY.
580 */ 580 */
581 if (!usbnet_isdying(un) && (un->un_flags & LSYS)) { 581 if (!usbnet_isdying(un) && (un->un_flags & LSYS)) {
582 uint16_t auxmode; 582 uint16_t auxmode;
583 aue_uno_mii_read_reg(un, 0, 0x1b, &auxmode); 583 aue_uno_mii_read_reg(un, 0, 0x1b, &auxmode);
584 aue_uno_mii_write_reg(un, 0, 0x1b, auxmode | 0x04); 584 aue_uno_mii_write_reg(un, 0, 0x1b, auxmode | 0x04);
585 } 585 }
586 586
587 if (usbnet_havelink(un) != hadlink) { 587 if (usbnet_havelink(un) != hadlink) {
588 DPRINTFN(5, "aue%jd: exit link %jd", 588 DPRINTFN(5, "aue%jd: exit link %jd",
589 device_unit(un->un_dev), usbnet_havelink(un), 0, 0); 589 device_unit(un->un_dev), usbnet_havelink(un), 0, 0);
590 } 590 }
591} 591}
592 592
593#define AUE_POLY 0xEDB88320 593#define AUE_POLY 0xEDB88320
594#define AUE_BITS 6 594#define AUE_BITS 6
595 595
596static uint32_t 596static uint32_t
597aue_crc(void *addrv) 597aue_crc(void *addrv)
598{ 598{
599 uint32_t idx, bit, data, crc; 599 uint32_t idx, bit, data, crc;
600 char *addr = addrv; 600 char *addr = addrv;
601 601
602 /* Compute CRC for the address value. */ 602 /* Compute CRC for the address value. */
603 crc = 0xFFFFFFFF; /* initial value */ 603 crc = 0xFFFFFFFF; /* initial value */
604 604
605 for (idx = 0; idx < 6; idx++) { 605 for (idx = 0; idx < 6; idx++) {
606 for (data = *addr++, bit = 0; bit < 8; bit++, data >>= 1) 606 for (data = *addr++, bit = 0; bit < 8; bit++, data >>= 1)
607 crc = (crc >> 1) ^ (((crc ^ data) & 1) ? AUE_POLY : 0); 607 crc = (crc >> 1) ^ (((crc ^ data) & 1) ? AUE_POLY : 0);
608 } 608 }
609 609
610 return crc & ((1 << AUE_BITS) - 1); 610 return crc & ((1 << AUE_BITS) - 1);
611} 611}
612 612
613static void 613static void
614aue_setiff_locked(struct usbnet *un) 614aue_setiff_locked(struct usbnet *un)
615{ 615{
616 struct aue_softc * const sc = usbnet_softc(un); 616 struct aue_softc * const sc = usbnet_softc(un);
617 struct ifnet * const ifp = usbnet_ifp(un); 617 struct ifnet * const ifp = usbnet_ifp(un);
618 struct ethercom * ec = usbnet_ec(un); 618 struct ethercom * ec = usbnet_ec(un);
619 struct ether_multi *enm; 619 struct ether_multi *enm;
620 struct ether_multistep step; 620 struct ether_multistep step;
621 uint32_t h = 0, i; 621 uint32_t h = 0, i;
622 uint8_t hashtbl[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; 622 uint8_t hashtbl[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
623 623
624 AUEHIST_FUNC(); 624 AUEHIST_FUNC();
625 AUEHIST_CALLARGSN(5, "aue%jd: enter", device_unit(un->un_dev), 0, 0, 0); 625 AUEHIST_CALLARGSN(5, "aue%jd: enter", device_unit(un->un_dev), 0, 0, 0);
626 626
627 usbnet_isowned_core(un); 627 usbnet_isowned_core(un);
628 628
629 if (ifp->if_flags & IFF_PROMISC) { 629 if (ifp->if_flags & IFF_PROMISC) {
630allmulti: 630allmulti:
631 ifp->if_flags |= IFF_ALLMULTI; 631 ifp->if_flags |= IFF_ALLMULTI;
632 AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_ALLMULTI); 632 AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_ALLMULTI);
633 return; 633 return;
634 } 634 }
635 635
636 AUE_CLRBIT(sc, AUE_CTL0, AUE_CTL0_ALLMULTI); 636 AUE_CLRBIT(sc, AUE_CTL0, AUE_CTL0_ALLMULTI);
637 637
638 /* now program new ones */ 638 /* now program new ones */
639 ETHER_LOCK(ec); 639 ETHER_LOCK(ec);
640 ETHER_FIRST_MULTI(step, ec, enm); 640 ETHER_FIRST_MULTI(step, ec, enm);
641 while (enm != NULL) { 641 while (enm != NULL) {
642 if (memcmp(enm->enm_addrlo, 642 if (memcmp(enm->enm_addrlo,
643 enm->enm_addrhi, ETHER_ADDR_LEN) != 0) { 643 enm->enm_addrhi, ETHER_ADDR_LEN) != 0) {
644 ETHER_UNLOCK(ec); 644 ETHER_UNLOCK(ec);
645 goto allmulti; 645 goto allmulti;
646 } 646 }
647 647
648 h = aue_crc(enm->enm_addrlo); 648 h = aue_crc(enm->enm_addrlo);
649 hashtbl[h >> 3] |= 1 << (h & 0x7); 649 hashtbl[h >> 3] |= 1 << (h & 0x7);
650 ETHER_NEXT_MULTI(step, enm); 650 ETHER_NEXT_MULTI(step, enm);
651 } 651 }
652 ETHER_UNLOCK(ec); 652 ETHER_UNLOCK(ec);
653 653
654 /* write the hashtable */ 654 /* write the hashtable */
655 for (i = 0; i < 8; i++) 655 for (i = 0; i < 8; i++)
656 aue_csr_write_1(sc, AUE_MAR0 + i, hashtbl[i]); 656 aue_csr_write_1(sc, AUE_MAR0 + i, hashtbl[i]);
657 657
658 ifp->if_flags &= ~IFF_ALLMULTI; 658 ifp->if_flags &= ~IFF_ALLMULTI;
659} 659}
660 660
661static void 661static void
662aue_reset_pegasus_II(struct aue_softc *sc) 662aue_reset_pegasus_II(struct aue_softc *sc)
663{ 663{
664 /* Magic constants taken from Linux driver. */ 664 /* Magic constants taken from Linux driver. */
665 aue_csr_write_1(sc, AUE_REG_1D, 0); 665 aue_csr_write_1(sc, AUE_REG_1D, 0);
666 aue_csr_write_1(sc, AUE_REG_7B, 2); 666 aue_csr_write_1(sc, AUE_REG_7B, 2);
667#if 0 667#if 0
668 if ((un->un_flags & PNA) && mii_mode) 668 if ((un->un_flags & PNA) && mii_mode)
669 aue_csr_write_1(sc, AUE_REG_81, 6); 669 aue_csr_write_1(sc, AUE_REG_81, 6);
670 else 670 else
671#endif 671#endif
672 aue_csr_write_1(sc, AUE_REG_81, 2); 672 aue_csr_write_1(sc, AUE_REG_81, 2);
673} 673}
674 674
675static void 675static void
676aue_reset(struct aue_softc *sc) 676aue_reset(struct aue_softc *sc)
677{ 677{
678 struct usbnet * const un = &sc->aue_un; 678 struct usbnet * const un = &sc->aue_un;
679 int i; 679 int i;
680 680
681 AUEHIST_FUNC(); 681 AUEHIST_FUNC();
682 AUEHIST_CALLARGSN(2, "aue%jd: enter", device_unit(un->un_dev), 0, 0, 0); 682 AUEHIST_CALLARGSN(2, "aue%jd: enter", device_unit(un->un_dev), 0, 0, 0);
683 683
684 AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_RESETMAC); 684 AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_RESETMAC);
685 685
686 for (i = 0; i < AUE_TIMEOUT; i++) { 686 for (i = 0; i < AUE_TIMEOUT; i++) {
687 if (usbnet_isdying(un)) 687 if (usbnet_isdying(un))
688 return; 688 return;
689 if (!(aue_csr_read_1(sc, AUE_CTL1) & AUE_CTL1_RESETMAC)) 689 if (!(aue_csr_read_1(sc, AUE_CTL1) & AUE_CTL1_RESETMAC))
690 break; 690 break;
691 } 691 }
692 692
693 if (i == AUE_TIMEOUT) 693 if (i == AUE_TIMEOUT)
694 printf("%s: reset failed\n", device_xname(un->un_dev)); 694 printf("%s: reset failed\n", device_xname(un->un_dev));
695 695
696#if 0 696#if 0
697 /* XXX what is mii_mode supposed to be */ 697 /* XXX what is mii_mode supposed to be */
698 if (sc->sc_mii_mode && (un->un_flags & PNA)) 698 if (sc->sc_mii_mode && (un->un_flags & PNA))
699 aue_csr_write_1(sc, AUE_GPIO1, 0x34); 699 aue_csr_write_1(sc, AUE_GPIO1, 0x34);
700 else 700 else
701 aue_csr_write_1(sc, AUE_GPIO1, 0x26); 701 aue_csr_write_1(sc, AUE_GPIO1, 0x26);
702#endif 702#endif
703 703
704 /* 704 /*
705 * The PHY(s) attached to the Pegasus chip may be held 705 * The PHY(s) attached to the Pegasus chip may be held
706 * in reset until we flip on the GPIO outputs. Make sure 706 * in reset until we flip on the GPIO outputs. Make sure
707 * to set the GPIO pins high so that the PHY(s) will 707 * to set the GPIO pins high so that the PHY(s) will
708 * be enabled. 708 * be enabled.
709 * 709 *
710 * Note: We force all of the GPIO pins low first, *then* 710 * Note: We force all of the GPIO pins low first, *then*
711 * enable the ones we want. 711 * enable the ones we want.
712 */ 712 */
713 if (un->un_flags & LSYS) { 713 if (un->un_flags & LSYS) {
714 /* Grrr. LinkSys has to be different from everyone else. */ 714 /* Grrr. LinkSys has to be different from everyone else. */
715 aue_csr_write_1(sc, AUE_GPIO0, 715 aue_csr_write_1(sc, AUE_GPIO0,
716 AUE_GPIO_SEL0 | AUE_GPIO_SEL1); 716 AUE_GPIO_SEL0 | AUE_GPIO_SEL1);
717 } else { 717 } else {
718 aue_csr_write_1(sc, AUE_GPIO0, 718 aue_csr_write_1(sc, AUE_GPIO0,
719 AUE_GPIO_OUT0 | AUE_GPIO_SEL0); 719 AUE_GPIO_OUT0 | AUE_GPIO_SEL0);
720 } 720 }
721 aue_csr_write_1(sc, AUE_GPIO0, 721 aue_csr_write_1(sc, AUE_GPIO0,
722 AUE_GPIO_OUT0 | AUE_GPIO_SEL0 | AUE_GPIO_SEL1); 722 AUE_GPIO_OUT0 | AUE_GPIO_SEL0 | AUE_GPIO_SEL1);
723 723
724 if (un->un_flags & PII) 724 if (un->un_flags & PII)
725 aue_reset_pegasus_II(sc); 725 aue_reset_pegasus_II(sc);
726 726
727 /* Wait a little while for the chip to get its brains in order. */ 727 /* Wait a little while for the chip to get its brains in order. */
728 delay(10000); /* XXX */ 728 delay(10000); /* XXX */
729 //usbd_delay_ms(un->un_udev, 10); /* XXX */ 729 //usbd_delay_ms(un->un_udev, 10); /* XXX */
730 730
731 DPRINTFN(2, "aue%jd: exit", device_unit(un->un_dev), 0, 0, 0); 731 DPRINTFN(2, "aue%jd: exit", device_unit(un->un_dev), 0, 0, 0);
732} 732}
733 733
734/* 734/*
735 * Probe for a Pegasus chip. 735 * Probe for a Pegasus chip.
736 */ 736 */
737static int 737static int
738aue_match(device_t parent, cfdata_t match, void *aux) 738aue_match(device_t parent, cfdata_t match, void *aux)
739{ 739{
740 struct usb_attach_arg *uaa = aux; 740 struct usb_attach_arg *uaa = aux;
741 741
742 /* 742 /*
743 * Some manufacturers use the same vendor and product id for 743 * Some manufacturers use the same vendor and product id for
744 * different devices. We need to sanity check the DeviceClass 744 * different devices. We need to sanity check the DeviceClass
745 * in this case 745 * in this case
746 * Currently known guilty products: 746 * Currently known guilty products:
747 * 0x050d/0x0121 Belkin Bluetooth and USB2LAN 747 * 0x050d/0x0121 Belkin Bluetooth and USB2LAN
748 * 748 *
749 * If this turns out to be more common, we could use a quirk 749 * If this turns out to be more common, we could use a quirk
750 * table. 750 * table.
751 */ 751 */
752 if (uaa->uaa_vendor == USB_VENDOR_BELKIN && 752 if (uaa->uaa_vendor == USB_VENDOR_BELKIN &&
753 uaa->uaa_product == USB_PRODUCT_BELKIN_USB2LAN) { 753 uaa->uaa_product == USB_PRODUCT_BELKIN_USB2LAN) {
754 usb_device_descriptor_t *dd; 754 usb_device_descriptor_t *dd;
755 755
756 dd = usbd_get_device_descriptor(uaa->uaa_device); 756 dd = usbd_get_device_descriptor(uaa->uaa_device);
757 if (dd != NULL && 757 if (dd != NULL &&
758 dd->bDeviceClass != UDCLASS_IN_INTERFACE) 758 dd->bDeviceClass != UDCLASS_IN_INTERFACE)
759 return UMATCH_NONE; 759 return UMATCH_NONE;
760 } 760 }
761 761
762 return aue_lookup(uaa->uaa_vendor, uaa->uaa_product) != NULL ? 762 return aue_lookup(uaa->uaa_vendor, uaa->uaa_product) != NULL ?
763 UMATCH_VENDOR_PRODUCT : UMATCH_NONE; 763 UMATCH_VENDOR_PRODUCT : UMATCH_NONE;
764} 764}
765 765
766/* 766/*
767 * Attach the interface. Allocate softc structures, do ifmedia 767 * Attach the interface. Allocate softc structures, do ifmedia
768 * setup and ethernet/BPF attach. 768 * setup and ethernet/BPF attach.
769 */ 769 */
770static void 770static void
771aue_attach(device_t parent, device_t self, void *aux) 771aue_attach(device_t parent, device_t self, void *aux)
772{ 772{
773 USBNET_MII_DECL_DEFAULT(unm); 773 USBNET_MII_DECL_DEFAULT(unm);
774 struct aue_softc * const sc = device_private(self); 774 struct aue_softc * const sc = device_private(self);
775 struct usbnet * const un = &sc->aue_un; 775 struct usbnet * const un = &sc->aue_un;
776 struct usb_attach_arg *uaa = aux; 776 struct usb_attach_arg *uaa = aux;
777 char *devinfop; 777 char *devinfop;
778 struct usbd_device *dev = uaa->uaa_device; 778 struct usbd_device *dev = uaa->uaa_device;
779 usbd_status err; 779 usbd_status err;
780 usb_interface_descriptor_t *id; 780 usb_interface_descriptor_t *id;
781 usb_endpoint_descriptor_t *ed; 781 usb_endpoint_descriptor_t *ed;
782 int i; 782 int i;
783 783
784 AUEHIST_FUNC(); 784 AUEHIST_FUNC();
785 AUEHIST_CALLARGSN(2, "aue%jd: enter sc=%#jx", 785 AUEHIST_CALLARGSN(2, "aue%jd: enter sc=%#jx",
786 device_unit(self), (uintptr_t)sc, 0, 0); 786 device_unit(self), (uintptr_t)sc, 0, 0);
787 787
788 KASSERT((void *)sc == un); 788 KASSERT((void *)sc == un);
789 789
790 aprint_naive("\n"); 790 aprint_naive("\n");
791 aprint_normal("\n"); 791 aprint_normal("\n");
792 devinfop = usbd_devinfo_alloc(uaa->uaa_device, 0); 792 devinfop = usbd_devinfo_alloc(uaa->uaa_device, 0);
793 aprint_normal_dev(self, "%s\n", devinfop); 793 aprint_normal_dev(self, "%s\n", devinfop);
794 usbd_devinfo_free(devinfop); 794 usbd_devinfo_free(devinfop);
795 795
796 un->un_dev = self; 796 un->un_dev = self;
797 un->un_udev = dev; 797 un->un_udev = dev;
798 un->un_sc = sc; 798 un->un_sc = sc;
799 un->un_ops = &aue_ops; 799 un->un_ops = &aue_ops;
800 un->un_intr = &sc->aue_intr; 800 un->un_intr = &sc->aue_intr;
801 un->un_rx_xfer_flags = USBD_SHORT_XFER_OK; 801 un->un_rx_xfer_flags = USBD_SHORT_XFER_OK;
802 un->un_tx_xfer_flags = USBD_FORCE_SHORT_XFER; 802 un->un_tx_xfer_flags = USBD_FORCE_SHORT_XFER;
803 un->un_rx_list_cnt = AUE_RX_LIST_CNT; 803 un->un_rx_list_cnt = AUE_RX_LIST_CNT;
804 un->un_tx_list_cnt = AUE_RX_LIST_CNT; 804 un->un_tx_list_cnt = AUE_RX_LIST_CNT;
805 un->un_rx_bufsz = AUE_BUFSZ; 805 un->un_rx_bufsz = AUE_BUFSZ;
806 un->un_tx_bufsz = AUE_BUFSZ; 806 un->un_tx_bufsz = AUE_BUFSZ;
807 807
808 sc->aue_intr.uni_buf = &sc->aue_ibuf; 808 sc->aue_intr.uni_buf = &sc->aue_ibuf;
809 sc->aue_intr.uni_bufsz = sizeof(sc->aue_ibuf); 809 sc->aue_intr.uni_bufsz = sizeof(sc->aue_ibuf);
810 sc->aue_intr.uni_interval = AUE_INTR_INTERVAL; 810 sc->aue_intr.uni_interval = AUE_INTR_INTERVAL;
811 811
812 err = usbd_set_config_no(dev, AUE_CONFIG_NO, 1); 812 err = usbd_set_config_no(dev, AUE_CONFIG_NO, 1);
813 if (err) { 813 if (err) {
814 aprint_error_dev(self, "failed to set configuration" 814 aprint_error_dev(self, "failed to set configuration"
815 ", err=%s\n", usbd_errstr(err)); 815 ", err=%s\n", usbd_errstr(err));
816 return; 816 return;
817 } 817 }
818 818
819 err = usbd_device2interface_handle(dev, AUE_IFACE_IDX, &un->un_iface); 819 err = usbd_device2interface_handle(dev, AUE_IFACE_IDX, &un->un_iface);
820 if (err) { 820 if (err) {
821 aprint_error_dev(self, "getting interface handle failed\n"); 821 aprint_error_dev(self, "getting interface handle failed\n");
822 return; 822 return;
823 } 823 }
824 824
825 un->un_flags = aue_lookup(uaa->uaa_vendor, uaa->uaa_product)->aue_flags; 825 un->un_flags = aue_lookup(uaa->uaa_vendor, uaa->uaa_product)->aue_flags;
826 826
827 id = usbd_get_interface_descriptor(un->un_iface); 827 id = usbd_get_interface_descriptor(un->un_iface);
828 828
829 /* Find endpoints. */ 829 /* Find endpoints. */
830 for (i = 0; i < id->bNumEndpoints; i++) { 830 for (i = 0; i < id->bNumEndpoints; i++) {
831 ed = usbd_interface2endpoint_descriptor(un->un_iface, i); 831 ed = usbd_interface2endpoint_descriptor(un->un_iface, i);
832 if (ed == NULL) { 832 if (ed == NULL) {
833 aprint_error_dev(self, 833 aprint_error_dev(self,
834 "couldn't get endpoint descriptor %d\n", i); 834 "couldn't get endpoint descriptor %d\n", i);
835 return; 835 return;
836 } 836 }
837 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN && 837 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
838 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) { 838 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
839 un->un_ed[USBNET_ENDPT_RX] = ed->bEndpointAddress; 839 un->un_ed[USBNET_ENDPT_RX] = ed->bEndpointAddress;
840 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT && 840 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
841 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) { 841 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
842 un->un_ed[USBNET_ENDPT_TX] = ed->bEndpointAddress; 842 un->un_ed[USBNET_ENDPT_TX] = ed->bEndpointAddress;
843 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN && 843 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
844 UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) { 844 UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
845 un->un_ed[USBNET_ENDPT_INTR] = ed->bEndpointAddress; 845 un->un_ed[USBNET_ENDPT_INTR] = ed->bEndpointAddress;
846 } 846 }
847 } 847 }
848 848
849 if (un->un_ed[USBNET_ENDPT_RX] == 0 || 849 if (un->un_ed[USBNET_ENDPT_RX] == 0 ||
850 un->un_ed[USBNET_ENDPT_TX] == 0 || 850 un->un_ed[USBNET_ENDPT_TX] == 0 ||
851 un->un_ed[USBNET_ENDPT_INTR] == 0) { 851 un->un_ed[USBNET_ENDPT_INTR] == 0) {
852 aprint_error_dev(self, "missing endpoint\n"); 852 aprint_error_dev(self, "missing endpoint\n");
853 return; 853 return;
854 } 854 }
855 855
856 /* First level attach. */ 856 /* First level attach. */
857 usbnet_attach(un, "auedet"); 857 usbnet_attach(un, "auedet");
858 858
859 usbnet_lock_core(un); 859 usbnet_lock_core(un);
860 860
861 /* Reset the adapter and get station address from the EEPROM. */ 861 /* Reset the adapter and get station address from the EEPROM. */
862 aue_reset(sc); 862 aue_reset(sc);
863 aue_read_mac(un); 863 aue_read_mac(un);
864 864
865 usbnet_unlock_core(un); 865 usbnet_unlock_core(un);
866 866
867 usbnet_attach_ifp(un, IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST, 867 usbnet_attach_ifp(un, IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST,
868 0, &unm); 868 0, &unm);
869} 869}
870 870
871static void 871static void
872aue_uno_intr(struct usbnet *un, usbd_status status) 872aue_uno_intr(struct usbnet *un, usbd_status status)
873{ 873{
874 struct ifnet *ifp = usbnet_ifp(un); 874 struct ifnet *ifp = usbnet_ifp(un);
875 struct aue_softc *sc = usbnet_softc(un); 875 struct aue_softc *sc = usbnet_softc(un);
876 struct aue_intrpkt *p = &sc->aue_ibuf; 876 struct aue_intrpkt *p = &sc->aue_ibuf;
877 877
878 AUEHIST_FUNC(); 878 AUEHIST_FUNC();
879 AUEHIST_CALLARGSN(20, "aue%jd: enter txstat0 %#jx\n", 879 AUEHIST_CALLARGSN(20, "aue%jd: enter txstat0 %#jx\n",
880 device_unit(un->un_dev), p->aue_txstat0, 0, 0); 880 device_unit(un->un_dev), p->aue_txstat0, 0, 0);
881 881
882 if (p->aue_txstat0) 882 if (p->aue_txstat0)
883 if_statinc(ifp, if_oerrors); 883 if_statinc(ifp, if_oerrors);
884 884
885 if (p->aue_txstat0 & (AUE_TXSTAT0_LATECOLL | AUE_TXSTAT0_EXCESSCOLL)) 885 if (p->aue_txstat0 & (AUE_TXSTAT0_LATECOLL | AUE_TXSTAT0_EXCESSCOLL))
886 if_statinc(ifp, if_collisions); 886 if_statinc(ifp, if_collisions);
887} 887}
888 888
889static void 889static void
890aue_uno_rx_loop(struct usbnet *un, struct usbnet_chain *c, uint32_t total_len) 890aue_uno_rx_loop(struct usbnet *un, struct usbnet_chain *c, uint32_t total_len)
891{ 891{
892 struct ifnet *ifp = usbnet_ifp(un); 892 struct ifnet *ifp = usbnet_ifp(un);
893 uint8_t *buf = c->unc_buf; 893 uint8_t *buf = c->unc_buf;
894 struct aue_rxpkt r; 894 struct aue_rxpkt r;
895 uint32_t pktlen; 895 uint32_t pktlen;
896 896
897 AUEHIST_FUNC(); 897 AUEHIST_FUNC();
898 AUEHIST_CALLARGSN(10, "aue%jd: enter len %ju", 898 AUEHIST_CALLARGSN(10, "aue%jd: enter len %ju",
899 device_unit(un->un_dev), total_len, 0, 0); 899 device_unit(un->un_dev), total_len, 0, 0);
900 900
901 if (total_len <= 4 + ETHER_CRC_LEN) { 901 if (total_len <= 4 + ETHER_CRC_LEN) {
902 if_statinc(ifp, if_ierrors); 902 if_statinc(ifp, if_ierrors);
903 return; 903 return;
904 } 904 }
905 905
906 memcpy(&r, buf + total_len - 4, sizeof(r)); 906 memcpy(&r, buf + total_len - 4, sizeof(r));
907 907
908 /* Turn off all the non-error bits in the rx status word. */ 908 /* Turn off all the non-error bits in the rx status word. */
909 r.aue_rxstat &= AUE_RXSTAT_MASK; 909 r.aue_rxstat &= AUE_RXSTAT_MASK;
910 if (r.aue_rxstat) { 910 if (r.aue_rxstat) {
911 if_statinc(ifp, if_ierrors); 911 if_statinc(ifp, if_ierrors);
912 return; 912 return;
913 } 913 }
914 914
915 /* No errors; receive the packet. */ 915 /* No errors; receive the packet. */
916 pktlen = total_len - ETHER_CRC_LEN - 4; 916 pktlen = total_len - ETHER_CRC_LEN - 4;
917 917
918 usbnet_enqueue(un, buf, pktlen, 0, 0, 0); 918 usbnet_enqueue(un, buf, pktlen, 0, 0, 0);
919} 919}
920 920
921static unsigned 921static unsigned
922aue_uno_tx_prepare(struct usbnet *un, struct mbuf *m, struct usbnet_chain *c) 922aue_uno_tx_prepare(struct usbnet *un, struct mbuf *m, struct usbnet_chain *c)
923{ 923{
924 uint8_t *buf = c->unc_buf; 924 uint8_t *buf = c->unc_buf;
925 int total_len; 925 int total_len;
926 926
927 AUEHIST_FUNC(); 927 AUEHIST_FUNC();
928 AUEHIST_CALLARGSN(10, "aue%jd: enter pktlen=%jd", 928 AUEHIST_CALLARGSN(10, "aue%jd: enter pktlen=%jd",
929 device_unit(un->un_dev), m->m_pkthdr.len, 0, 0); 929 device_unit(un->un_dev), m->m_pkthdr.len, 0, 0);
930 930
931 if ((unsigned)m->m_pkthdr.len > un->un_tx_bufsz - 2) 931 if ((unsigned)m->m_pkthdr.len > un->un_tx_bufsz - 2)
932 return 0; 932 return 0;
933 933
934 /* 934 /*
935 * Copy the mbuf data into a contiguous buffer, leaving two 935 * Copy the mbuf data into a contiguous buffer, leaving two
936 * bytes at the beginning to hold the frame length. 936 * bytes at the beginning to hold the frame length.
937 */ 937 */
938 m_copydata(m, 0, m->m_pkthdr.len, buf + 2); 938 m_copydata(m, 0, m->m_pkthdr.len, buf + 2);
939 939
940 /* 940 /*
941 * The ADMtek documentation says that the packet length is 941 * The ADMtek documentation says that the packet length is
942 * supposed to be specified in the first two bytes of the 942 * supposed to be specified in the first two bytes of the
943 * transfer, however it actually seems to ignore this info 943 * transfer, however it actually seems to ignore this info
944 * and base the frame size on the bulk transfer length. 944 * and base the frame size on the bulk transfer length.
945 */ 945 */
946 buf[0] = (uint8_t)m->m_pkthdr.len; 946 buf[0] = (uint8_t)m->m_pkthdr.len;
947 buf[1] = (uint8_t)(m->m_pkthdr.len >> 8); 947 buf[1] = (uint8_t)(m->m_pkthdr.len >> 8);
948 total_len = m->m_pkthdr.len + 2; 948 total_len = m->m_pkthdr.len + 2;
949 949
950 DPRINTFN(5, "aue%jd: send %jd bytes", 950 DPRINTFN(5, "aue%jd: send %jd bytes",
951 device_unit(un->un_dev), total_len, 0, 0); 951 device_unit(un->un_dev), total_len, 0, 0);
952 952
953 return total_len; 953 return total_len;
954} 954}
955 955
956static int 956static int
957aue_uno_init(struct ifnet *ifp) 957aue_uno_init(struct ifnet *ifp)
958{ 958{
959 struct usbnet * const un = ifp->if_softc; 959 struct usbnet * const un = ifp->if_softc;
960 struct aue_softc *sc = usbnet_softc(un); 960 struct aue_softc *sc = usbnet_softc(un);
961 int i, rv; 961 int i, rv;
962 const u_char *eaddr; 962 const u_char *eaddr;
963 963
964 AUEHIST_FUNC(); 964 AUEHIST_FUNC();
965 AUEHIST_CALLARGSN(5, "aue%jd: enter link=%jd", 965 AUEHIST_CALLARGSN(5, "aue%jd: enter link=%jd",
966 device_unit(un->un_dev), usbnet_havelink(un), 0, 0); 966 device_unit(un->un_dev), usbnet_havelink(un), 0, 0);
967 967
968 if (usbnet_isdying(un)) 968 if (usbnet_isdying(un))
969 return EIO; 969 return EIO;
970 970
971 /* Cancel pending I/O */ 971 /* Cancel pending I/O */
972 if (ifp->if_flags & IFF_RUNNING) 972 if (ifp->if_flags & IFF_RUNNING)
973 return 0; 973 return 0;
974 974
975 /* Reset the interface. */ 975 /* Reset the interface. */
976 aue_reset(sc); 976 aue_reset(sc);
977 977
978 eaddr = CLLADDR(ifp->if_sadl); 978 eaddr = CLLADDR(ifp->if_sadl);
979 for (i = 0; i < ETHER_ADDR_LEN; i++) 979 for (i = 0; i < ETHER_ADDR_LEN; i++)
980 aue_csr_write_1(sc, AUE_PAR0 + i, eaddr[i]); 980 aue_csr_write_1(sc, AUE_PAR0 + i, eaddr[i]);
981 981
982 /* If we want promiscuous mode, set the allframes bit. */ 982 /* If we want promiscuous mode, set the allframes bit. */
983 if (ifp->if_flags & IFF_PROMISC) 983 if (ifp->if_flags & IFF_PROMISC)
984 AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC); 984 AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC);
985 else 985 else
986 AUE_CLRBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC); 986 AUE_CLRBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC);
987 987
988 rv = usbnet_init_rx_tx(un); 988 rv = usbnet_init_rx_tx(un);
989 989
990 /* Load the multicast filter. */ 990 /* Load the multicast filter. */
991 aue_setiff_locked(un); 991 aue_setiff_locked(un);
992 992
993 /* Enable RX and TX */ 993 /* Enable RX and TX */
994 aue_csr_write_1(sc, AUE_CTL0, AUE_CTL0_RXSTAT_APPEND | AUE_CTL0_RX_ENB); 994 aue_csr_write_1(sc, AUE_CTL0, AUE_CTL0_RXSTAT_APPEND | AUE_CTL0_RX_ENB);
995 AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_TX_ENB); 995 AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_TX_ENB);
996 AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_EP3_CLR); 996 AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_EP3_CLR);
997 997
998 //mii_mediachg(mii); 998 //mii_mediachg(mii);
999 999
1000 return rv; 1000 return rv;
1001} 1001}
1002 1002
1003static void 1003static void
1004aue_uno_mcast(struct ifnet *ifp) 1004aue_uno_mcast(struct ifnet *ifp)
1005{ 1005{
1006 1006
1007 AUEHIST_FUNC(); 1007 AUEHIST_FUNC();
1008 AUEHIST_CALLARGSN(5, "aue%jd: enter", 1008 AUEHIST_CALLARGSN(5, "aue%jd: enter",
1009 device_unit(((struct usbnet *)(ifp->if_softc))->un_dev), 1009 device_unit(((struct usbnet *)(ifp->if_softc))->un_dev),
1010 0, 0, 0); 1010 0, 0, 0);
1011 1011
1012 /* 1012 aue_setiff_locked(ifp);
1013 * XXX I feel like this is pretty heavy-handed! Maybe we could 
1014 * make do with aue_setiff_locked instead? 
1015 */ 
1016 aue_uno_init(ifp); 
1017} 1013}
1018 1014
1019static void 1015static void
1020aue_uno_stop(struct ifnet *ifp, int disable) 1016aue_uno_stop(struct ifnet *ifp, int disable)
1021{ 1017{
1022 struct usbnet * const un = ifp->if_softc; 1018 struct usbnet * const un = ifp->if_softc;
1023 struct aue_softc * const sc = usbnet_softc(un); 1019 struct aue_softc * const sc = usbnet_softc(un);
1024 1020
1025 AUEHIST_FUNC(); 1021 AUEHIST_FUNC();
1026 AUEHIST_CALLARGSN(5, "aue%jd: enter", device_unit(un->un_dev), 0, 0, 0); 1022 AUEHIST_CALLARGSN(5, "aue%jd: enter", device_unit(un->un_dev), 0, 0, 0);
1027 1023
1028 aue_csr_write_1(sc, AUE_CTL0, 0); 1024 aue_csr_write_1(sc, AUE_CTL0, 0);
1029 aue_csr_write_1(sc, AUE_CTL1, 0); 1025 aue_csr_write_1(sc, AUE_CTL1, 0);
1030 aue_reset(sc); 1026 aue_reset(sc);
1031} 1027}
1032 1028
1033#ifdef _MODULE 1029#ifdef _MODULE
1034#include "ioconf.c" 1030#include "ioconf.c"
1035#endif 1031#endif
1036 1032
1037USBNET_MODULE(aue) 1033USBNET_MODULE(aue)