Thu Mar 3 05:53:49 2022 UTC ()
aue(4): Simplify.  No functional change.


(riastradh)
diff -r1.183 -r1.184 src/sys/dev/usb/if_aue.c

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

--- src/sys/dev/usb/if_aue.c 2022/03/03 05:53:41 1.183
+++ src/sys/dev/usb/if_aue.c 2022/03/03 05:53:48 1.184
@@ -1,1008 +1,1004 @@ @@ -1,1008 +1,1004 @@
1/* $NetBSD: if_aue.c,v 1.183 2022/03/03 05:53:41 riastradh Exp $ */ 1/* $NetBSD: if_aue.c,v 1.184 2022/03/03 05:53:48 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.183 2022/03/03 05:53:41 riastradh Exp $"); 79__KERNEL_RCSID(0, "$NetBSD: if_aue.c,v 1.184 2022/03/03 05:53:48 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 if (usbnet_isdying(un)) 287 if (usbnet_isdying(un))
288 return 0; 288 return 0;
289 289
290 req.bmRequestType = UT_READ_VENDOR_DEVICE; 290 req.bmRequestType = UT_READ_VENDOR_DEVICE;
291 req.bRequest = AUE_UR_READREG; 291 req.bRequest = AUE_UR_READREG;
292 USETW(req.wValue, 0); 292 USETW(req.wValue, 0);
293 USETW(req.wIndex, reg); 293 USETW(req.wIndex, reg);
294 USETW(req.wLength, 1); 294 USETW(req.wLength, 1);
295 295
296 err = usbd_do_request(un->un_udev, &req, &val); 296 err = usbd_do_request(un->un_udev, &req, &val);
297 297
298 if (err) { 298 if (err) {
299 AUEHIST_FUNC(); 299 AUEHIST_FUNC();
300 AUEHIST_CALLARGS("aue%jd: reg=%#jx err=%jd", 300 AUEHIST_CALLARGS("aue%jd: reg=%#jx err=%jd",
301 device_unit(un->un_dev), reg, err, 0); 301 device_unit(un->un_dev), reg, err, 0);
302 return 0; 302 return 0;
303 } 303 }
304 304
305 return val; 305 return val;
306} 306}
307 307
308static int 308static int
309aue_csr_read_2(struct aue_softc *sc, int reg) 309aue_csr_read_2(struct aue_softc *sc, int reg)
310{ 310{
311 struct usbnet * const un = &sc->aue_un; 311 struct usbnet * const un = &sc->aue_un;
312 usb_device_request_t req; 312 usb_device_request_t req;
313 usbd_status err; 313 usbd_status err;
314 uWord val; 314 uWord val;
315 315
316 if (usbnet_isdying(un)) 316 if (usbnet_isdying(un))
317 return 0; 317 return 0;
318 318
319 req.bmRequestType = UT_READ_VENDOR_DEVICE; 319 req.bmRequestType = UT_READ_VENDOR_DEVICE;
320 req.bRequest = AUE_UR_READREG; 320 req.bRequest = AUE_UR_READREG;
321 USETW(req.wValue, 0); 321 USETW(req.wValue, 0);
322 USETW(req.wIndex, reg); 322 USETW(req.wIndex, reg);
323 USETW(req.wLength, 2); 323 USETW(req.wLength, 2);
324 324
325 err = usbd_do_request(un->un_udev, &req, &val); 325 err = usbd_do_request(un->un_udev, &req, &val);
326 326
327 if (err) { 327 if (err) {
328 AUEHIST_FUNC(); 328 AUEHIST_FUNC();
329 AUEHIST_CALLARGS("aue%jd: reg=%#jx err=%jd", 329 AUEHIST_CALLARGS("aue%jd: reg=%#jx err=%jd",
330 device_unit(un->un_dev), reg, err, 0); 330 device_unit(un->un_dev), reg, err, 0);
331 return 0; 331 return 0;
332 } 332 }
333 333
334 return UGETW(val); 334 return UGETW(val);
335} 335}
336 336
337static int 337static int
338aue_csr_write_1(struct aue_softc *sc, int reg, int aval) 338aue_csr_write_1(struct aue_softc *sc, int reg, int aval)
339{ 339{
340 struct usbnet * const un = &sc->aue_un; 340 struct usbnet * const un = &sc->aue_un;
341 usb_device_request_t req; 341 usb_device_request_t req;
342 usbd_status err; 342 usbd_status err;
343 uByte val; 343 uByte val;
344 344
345 if (usbnet_isdying(un)) 345 if (usbnet_isdying(un))
346 return 0; 346 return 0;
347 347
348 val = aval; 348 val = aval;
349 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 349 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
350 req.bRequest = AUE_UR_WRITEREG; 350 req.bRequest = AUE_UR_WRITEREG;
351 USETW(req.wValue, val); 351 USETW(req.wValue, val);
352 USETW(req.wIndex, reg); 352 USETW(req.wIndex, reg);
353 USETW(req.wLength, 1); 353 USETW(req.wLength, 1);
354 354
355 err = usbd_do_request(un->un_udev, &req, &val); 355 err = usbd_do_request(un->un_udev, &req, &val);
356 356
357 if (err) { 357 if (err) {
358 AUEHIST_FUNC(); 358 AUEHIST_FUNC();
359 AUEHIST_CALLARGS("aue%jd: reg=%#jx err=%jd", 359 AUEHIST_CALLARGS("aue%jd: reg=%#jx err=%jd",
360 device_unit(un->un_dev), reg, err, 0); 360 device_unit(un->un_dev), reg, err, 0);
361 return -1; 361 return -1;
362 } 362 }
363 363
364 return 0; 364 return 0;
365} 365}
366 366
367static int 367static int
368aue_csr_write_2(struct aue_softc *sc, int reg, int aval) 368aue_csr_write_2(struct aue_softc *sc, int reg, int aval)
369{ 369{
370 struct usbnet * const un = &sc->aue_un; 370 struct usbnet * const un = &sc->aue_un;
371 usb_device_request_t req; 371 usb_device_request_t req;
372 usbd_status err; 372 usbd_status err;
373 uWord val; 373 uWord val;
374 374
375 if (usbnet_isdying(un)) 375 if (usbnet_isdying(un))
376 return 0; 376 return 0;
377 377
378 USETW(val, aval); 378 USETW(val, aval);
379 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 379 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
380 req.bRequest = AUE_UR_WRITEREG; 380 req.bRequest = AUE_UR_WRITEREG;
381 USETW(req.wValue, aval); 381 USETW(req.wValue, aval);
382 USETW(req.wIndex, reg); 382 USETW(req.wIndex, reg);
383 USETW(req.wLength, 2); 383 USETW(req.wLength, 2);
384 384
385 err = usbd_do_request(un->un_udev, &req, &val); 385 err = usbd_do_request(un->un_udev, &req, &val);
386 386
387 if (err) { 387 if (err) {
388 AUEHIST_FUNC(); 388 AUEHIST_FUNC();
389 AUEHIST_CALLARGS("aue%jd: reg=%#jx err=%jd", 389 AUEHIST_CALLARGS("aue%jd: reg=%#jx err=%jd",
390 device_unit(un->un_dev), reg, err, 0); 390 device_unit(un->un_dev), reg, err, 0);
391 return -1; 391 return -1;
392 } 392 }
393 393
394 return 0; 394 return 0;
395} 395}
396 396
397/* 397/*
398 * Read a word of data stored in the EEPROM at address 'addr.' 398 * Read a word of data stored in the EEPROM at address 'addr.'
399 */ 399 */
400static int 400static int
401aue_eeprom_getword(struct aue_softc *sc, int addr) 401aue_eeprom_getword(struct aue_softc *sc, int addr)
402{ 402{
403 struct usbnet * const un = &sc->aue_un; 403 struct usbnet * const un = &sc->aue_un;
404 int i; 404 int i;
405 405
406 AUEHIST_FUNC(); AUEHIST_CALLED(); 406 AUEHIST_FUNC(); AUEHIST_CALLED();
407 407
408 aue_csr_write_1(sc, AUE_EE_REG, addr); 408 aue_csr_write_1(sc, AUE_EE_REG, addr);
409 aue_csr_write_1(sc, AUE_EE_CTL, AUE_EECTL_READ); 409 aue_csr_write_1(sc, AUE_EE_CTL, AUE_EECTL_READ);
410 410
411 for (i = 0; i < AUE_TIMEOUT; i++) { 411 for (i = 0; i < AUE_TIMEOUT; i++) {
412 if (aue_csr_read_1(sc, AUE_EE_CTL) & AUE_EECTL_DONE) 412 if (aue_csr_read_1(sc, AUE_EE_CTL) & AUE_EECTL_DONE)
413 break; 413 break;
414 } 414 }
415 415
416 if (i == AUE_TIMEOUT) { 416 if (i == AUE_TIMEOUT) {
417 printf("%s: EEPROM read timed out\n", 417 printf("%s: EEPROM read timed out\n",
418 device_xname(un->un_dev)); 418 device_xname(un->un_dev));
419 } 419 }
420 420
421 return aue_csr_read_2(sc, AUE_EE_DATA); 421 return aue_csr_read_2(sc, AUE_EE_DATA);
422} 422}
423 423
424/* 424/*
425 * Read the MAC from the EEPROM. It's at offset 0. 425 * Read the MAC from the EEPROM. It's at offset 0.
426 */ 426 */
427static void 427static void
428aue_read_mac(struct usbnet *un) 428aue_read_mac(struct usbnet *un)
429{ 429{
430 struct aue_softc *sc = usbnet_softc(un); 430 struct aue_softc *sc = usbnet_softc(un);
431 int i; 431 int i;
432 int off = 0; 432 int off = 0;
433 int word; 433 int word;
434 434
435 usbnet_isowned_core(un); 435 usbnet_isowned_core(un);
436 436
437 AUEHIST_FUNC(); 437 AUEHIST_FUNC();
438 AUEHIST_CALLARGS("aue%jd: enter", 438 AUEHIST_CALLARGS("aue%jd: enter",
439 device_unit(un->un_dev), 0, 0, 0); 439 device_unit(un->un_dev), 0, 0, 0);
440 440
441 for (i = 0; i < 3; i++) { 441 for (i = 0; i < 3; i++) {
442 word = aue_eeprom_getword(sc, off + i); 442 word = aue_eeprom_getword(sc, off + i);
443 un->un_eaddr[2 * i] = (u_char)word; 443 un->un_eaddr[2 * i] = (u_char)word;
444 un->un_eaddr[2 * i + 1] = (u_char)(word >> 8); 444 un->un_eaddr[2 * i + 1] = (u_char)(word >> 8);
445 } 445 }
446} 446}
447 447
448static int 448static int
449aue_uno_mii_read_reg(struct usbnet *un, int phy, int reg, uint16_t *val) 449aue_uno_mii_read_reg(struct usbnet *un, int phy, int reg, uint16_t *val)
450{ 450{
451 struct aue_softc *sc = usbnet_softc(un); 451 struct aue_softc *sc = usbnet_softc(un);
452 int i; 452 int i;
453 453
454 AUEHIST_FUNC(); 454 AUEHIST_FUNC();
455 455
456#if 0 456#if 0
457 /* 457 /*
458 * The Am79C901 HomePNA PHY actually contains 458 * The Am79C901 HomePNA PHY actually contains
459 * two transceivers: a 1Mbps HomePNA PHY and a 459 * two transceivers: a 1Mbps HomePNA PHY and a
460 * 10Mbps full/half duplex ethernet PHY with 460 * 10Mbps full/half duplex ethernet PHY with
461 * NWAY autoneg. However in the ADMtek adapter, 461 * NWAY autoneg. However in the ADMtek adapter,
462 * only the 1Mbps PHY is actually connected to 462 * only the 1Mbps PHY is actually connected to
463 * anything, so we ignore the 10Mbps one. It 463 * anything, so we ignore the 10Mbps one. It
464 * happens to be configured for MII address 3, 464 * happens to be configured for MII address 3,
465 * so we filter that out. 465 * so we filter that out.
466 */ 466 */
467 if (sc->aue_vendor == USB_VENDOR_ADMTEK && 467 if (sc->aue_vendor == USB_VENDOR_ADMTEK &&
468 sc->aue_product == USB_PRODUCT_ADMTEK_PEGASUS) { 468 sc->aue_product == USB_PRODUCT_ADMTEK_PEGASUS) {
469 if (phy == 3) 469 if (phy == 3)
470 return EINVAL; 470 return EINVAL;
471 } 471 }
472#endif 472#endif
473 473
474 aue_csr_write_1(sc, AUE_PHY_ADDR, phy); 474 aue_csr_write_1(sc, AUE_PHY_ADDR, phy);
475 aue_csr_write_1(sc, AUE_PHY_CTL, reg | AUE_PHYCTL_READ); 475 aue_csr_write_1(sc, AUE_PHY_CTL, reg | AUE_PHYCTL_READ);
476 476
477 for (i = 0; i < AUE_TIMEOUT; i++) { 477 for (i = 0; i < AUE_TIMEOUT; i++) {
478 if (usbnet_isdying(un)) 478 if (usbnet_isdying(un))
479 return ENXIO; 479 return ENXIO;
480 if (aue_csr_read_1(sc, AUE_PHY_CTL) & AUE_PHYCTL_DONE) 480 if (aue_csr_read_1(sc, AUE_PHY_CTL) & AUE_PHYCTL_DONE)
481 break; 481 break;
482 } 482 }
483 483
484 if (i == AUE_TIMEOUT) { 484 if (i == AUE_TIMEOUT) {
485 AUEHIST_CALLARGS("aue%jd: phy=%#jx reg=%#jx read timed out", 485 AUEHIST_CALLARGS("aue%jd: phy=%#jx reg=%#jx read timed out",
486 device_unit(un->un_dev), phy, reg, 0); 486 device_unit(un->un_dev), phy, reg, 0);
487 return ETIMEDOUT; 487 return ETIMEDOUT;
488 } 488 }
489 489
490 *val = aue_csr_read_2(sc, AUE_PHY_DATA); 490 *val = aue_csr_read_2(sc, AUE_PHY_DATA);
491 491
492 AUEHIST_CALLARGSN(11, "aue%jd: phy=%#jx reg=%#jx => 0x%04jx", 492 AUEHIST_CALLARGSN(11, "aue%jd: phy=%#jx reg=%#jx => 0x%04jx",
493 device_unit(un->un_dev), phy, reg, *val); 493 device_unit(un->un_dev), phy, reg, *val);
494 494
495 return 0; 495 return 0;
496} 496}
497 497
498static int 498static int
499aue_uno_mii_write_reg(struct usbnet *un, int phy, int reg, uint16_t val) 499aue_uno_mii_write_reg(struct usbnet *un, int phy, int reg, uint16_t val)
500{ 500{
501 struct aue_softc *sc = usbnet_softc(un); 501 struct aue_softc *sc = usbnet_softc(un);
502 int i; 502 int i;
503 503
504 AUEHIST_FUNC(); 504 AUEHIST_FUNC();
505 AUEHIST_CALLARGSN(11, "aue%jd: phy=%jd reg=%jd data=0x%04jx", 505 AUEHIST_CALLARGSN(11, "aue%jd: phy=%jd reg=%jd data=0x%04jx",
506 device_unit(un->un_dev), phy, reg, val); 506 device_unit(un->un_dev), phy, reg, val);
507 507
508#if 0 508#if 0
509 if (sc->aue_vendor == USB_VENDOR_ADMTEK && 509 if (sc->aue_vendor == USB_VENDOR_ADMTEK &&
510 sc->aue_product == USB_PRODUCT_ADMTEK_PEGASUS) { 510 sc->aue_product == USB_PRODUCT_ADMTEK_PEGASUS) {
511 if (phy == 3) 511 if (phy == 3)
512 return EINVAL; 512 return EINVAL;
513 } 513 }
514#endif 514#endif
515 515
516 aue_csr_write_2(sc, AUE_PHY_DATA, val); 516 aue_csr_write_2(sc, AUE_PHY_DATA, val);
517 aue_csr_write_1(sc, AUE_PHY_ADDR, phy); 517 aue_csr_write_1(sc, AUE_PHY_ADDR, phy);
518 aue_csr_write_1(sc, AUE_PHY_CTL, reg | AUE_PHYCTL_WRITE); 518 aue_csr_write_1(sc, AUE_PHY_CTL, reg | AUE_PHYCTL_WRITE);
519 519
520 for (i = 0; i < AUE_TIMEOUT; i++) { 520 for (i = 0; i < AUE_TIMEOUT; i++) {
521 if (usbnet_isdying(un)) 521 if (usbnet_isdying(un))
522 return ENXIO; 522 return ENXIO;
523 if (aue_csr_read_1(sc, AUE_PHY_CTL) & AUE_PHYCTL_DONE) 523 if (aue_csr_read_1(sc, AUE_PHY_CTL) & AUE_PHYCTL_DONE)
524 break; 524 break;
525 } 525 }
526 526
527 if (i == AUE_TIMEOUT) { 527 if (i == AUE_TIMEOUT) {
528 DPRINTF("aue%jd: phy=%#jx reg=%#jx val=%#jx write timed out", 528 DPRINTF("aue%jd: phy=%#jx reg=%#jx val=%#jx write timed out",
529 device_unit(un->un_dev), phy, reg, val); 529 device_unit(un->un_dev), phy, reg, val);
530 return ETIMEDOUT; 530 return ETIMEDOUT;
531 } 531 }
532 532
533 return 0; 533 return 0;
534} 534}
535 535
536static void 536static void
537aue_uno_mii_statchg(struct ifnet *ifp) 537aue_uno_mii_statchg(struct ifnet *ifp)
538{ 538{
539 struct usbnet *un = ifp->if_softc; 539 struct usbnet *un = ifp->if_softc;
540 struct aue_softc *sc = usbnet_softc(un); 540 struct aue_softc *sc = usbnet_softc(un);
541 struct mii_data *mii = usbnet_mii(un); 541 struct mii_data *mii = usbnet_mii(un);
542 const bool hadlink __diagused = usbnet_havelink(un); 542 const bool hadlink __diagused = usbnet_havelink(un);
543 543
544 AUEHIST_FUNC(); AUEHIST_CALLED(); 544 AUEHIST_FUNC(); AUEHIST_CALLED();
545 AUEHIST_CALLARGSN(5, "aue%jd: ifp=%#jx link=%jd", 545 AUEHIST_CALLARGSN(5, "aue%jd: ifp=%#jx link=%jd",
546 device_unit(un->un_dev), (uintptr_t)ifp, hadlink, 0); 546 device_unit(un->un_dev), (uintptr_t)ifp, hadlink, 0);
547 547
548 AUE_CLRBIT(sc, AUE_CTL0, AUE_CTL0_RX_ENB | AUE_CTL0_TX_ENB); 548 AUE_CLRBIT(sc, AUE_CTL0, AUE_CTL0_RX_ENB | AUE_CTL0_TX_ENB);
549 549
550 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_100_TX) { 550 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_100_TX) {
551 AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_SPEEDSEL); 551 AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_SPEEDSEL);
552 } else { 552 } else {
553 AUE_CLRBIT(sc, AUE_CTL1, AUE_CTL1_SPEEDSEL); 553 AUE_CLRBIT(sc, AUE_CTL1, AUE_CTL1_SPEEDSEL);
554 } 554 }
555 555
556 if ((mii->mii_media_active & IFM_FDX) != 0) 556 if ((mii->mii_media_active & IFM_FDX) != 0)
557 AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_DUPLEX); 557 AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_DUPLEX);
558 else 558 else
559 AUE_CLRBIT(sc, AUE_CTL1, AUE_CTL1_DUPLEX); 559 AUE_CLRBIT(sc, AUE_CTL1, AUE_CTL1_DUPLEX);
560 560
561 AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_RX_ENB | AUE_CTL0_TX_ENB); 561 AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_RX_ENB | AUE_CTL0_TX_ENB);
562 562
563 if (mii->mii_media_status & IFM_ACTIVE && 563 if (mii->mii_media_status & IFM_ACTIVE &&
564 IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) { 564 IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
565 usbnet_set_link(un, true); 565 usbnet_set_link(un, true);
566 } 566 }
567 567
568 /* 568 /*
569 * Set the LED modes on the LinkSys adapter. 569 * Set the LED modes on the LinkSys adapter.
570 * This turns on the 'dual link LED' bin in the auxmode 570 * This turns on the 'dual link LED' bin in the auxmode
571 * register of the Broadcom PHY. 571 * register of the Broadcom PHY.
572 */ 572 */
573 if (!usbnet_isdying(un) && (un->un_flags & LSYS)) { 573 if (!usbnet_isdying(un) && (un->un_flags & LSYS)) {
574 uint16_t auxmode; 574 uint16_t auxmode;
575 aue_uno_mii_read_reg(un, 0, 0x1b, &auxmode); 575 aue_uno_mii_read_reg(un, 0, 0x1b, &auxmode);
576 aue_uno_mii_write_reg(un, 0, 0x1b, auxmode | 0x04); 576 aue_uno_mii_write_reg(un, 0, 0x1b, auxmode | 0x04);
577 } 577 }
578 578
579 if (usbnet_havelink(un) != hadlink) { 579 if (usbnet_havelink(un) != hadlink) {
580 DPRINTFN(5, "aue%jd: exit link %jd", 580 DPRINTFN(5, "aue%jd: exit link %jd",
581 device_unit(un->un_dev), usbnet_havelink(un), 0, 0); 581 device_unit(un->un_dev), usbnet_havelink(un), 0, 0);
582 } 582 }
583} 583}
584 584
585#define AUE_POLY 0xEDB88320 585#define AUE_POLY 0xEDB88320
586#define AUE_BITS 6 586#define AUE_BITS 6
587 587
588static uint32_t 588static uint32_t
589aue_crc(void *addrv) 589aue_crc(void *addrv)
590{ 590{
591 uint32_t idx, bit, data, crc; 591 uint32_t idx, bit, data, crc;
592 char *addr = addrv; 592 char *addr = addrv;
593 593
594 /* Compute CRC for the address value. */ 594 /* Compute CRC for the address value. */
595 crc = 0xFFFFFFFF; /* initial value */ 595 crc = 0xFFFFFFFF; /* initial value */
596 596
597 for (idx = 0; idx < 6; idx++) { 597 for (idx = 0; idx < 6; idx++) {
598 for (data = *addr++, bit = 0; bit < 8; bit++, data >>= 1) 598 for (data = *addr++, bit = 0; bit < 8; bit++, data >>= 1)
599 crc = (crc >> 1) ^ (((crc ^ data) & 1) ? AUE_POLY : 0); 599 crc = (crc >> 1) ^ (((crc ^ data) & 1) ? AUE_POLY : 0);
600 } 600 }
601 601
602 return crc & ((1 << AUE_BITS) - 1); 602 return crc & ((1 << AUE_BITS) - 1);
603} 603}
604 604
605static void 605static void
606aue_uno_mcast(struct ifnet *ifp) 606aue_uno_mcast(struct ifnet *ifp)
607{ 607{
608 struct usbnet * const un = ifp->if_softc; 608 struct usbnet * const un = ifp->if_softc;
609 struct aue_softc * const sc = usbnet_softc(un); 609 struct aue_softc * const sc = usbnet_softc(un);
610 struct ethercom * ec = usbnet_ec(un); 610 struct ethercom * ec = usbnet_ec(un);
611 struct ether_multi *enm; 611 struct ether_multi *enm;
612 struct ether_multistep step; 612 struct ether_multistep step;
613 uint32_t h = 0, i; 613 uint32_t h = 0, i;
614 uint8_t hashtbl[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; 614 uint8_t hashtbl[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
615 615
616 AUEHIST_FUNC(); 616 AUEHIST_FUNC();
617 AUEHIST_CALLARGSN(5, "aue%jd: enter", device_unit(un->un_dev), 0, 0, 0); 617 AUEHIST_CALLARGSN(5, "aue%jd: enter", device_unit(un->un_dev), 0, 0, 0);
618 618
619 if (ifp->if_flags & IFF_PROMISC) { 619 if (ifp->if_flags & IFF_PROMISC) {
620 ETHER_LOCK(ec); 620 ETHER_LOCK(ec);
621allmulti: 621allmulti:
622 ec->ec_flags |= ETHER_F_ALLMULTI; 622 ec->ec_flags |= ETHER_F_ALLMULTI;
623 ETHER_UNLOCK(ec); 623 ETHER_UNLOCK(ec);
624 AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_ALLMULTI); 624 AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_ALLMULTI);
625 return; 625 return;
626 } 626 }
627 627
628 /* now program new ones */ 628 /* now program new ones */
629 ETHER_LOCK(ec); 629 ETHER_LOCK(ec);
630 ETHER_FIRST_MULTI(step, ec, enm); 630 ETHER_FIRST_MULTI(step, ec, enm);
631 while (enm != NULL) { 631 while (enm != NULL) {
632 if (memcmp(enm->enm_addrlo, 632 if (memcmp(enm->enm_addrlo,
633 enm->enm_addrhi, ETHER_ADDR_LEN) != 0) { 633 enm->enm_addrhi, ETHER_ADDR_LEN) != 0) {
634 goto allmulti; 634 goto allmulti;
635 } 635 }
636 636
637 h = aue_crc(enm->enm_addrlo); 637 h = aue_crc(enm->enm_addrlo);
638 hashtbl[h >> 3] |= 1 << (h & 0x7); 638 hashtbl[h >> 3] |= 1 << (h & 0x7);
639 ETHER_NEXT_MULTI(step, enm); 639 ETHER_NEXT_MULTI(step, enm);
640 } 640 }
641 ec->ec_flags &= ~ETHER_F_ALLMULTI; 641 ec->ec_flags &= ~ETHER_F_ALLMULTI;
642 ETHER_UNLOCK(ec); 642 ETHER_UNLOCK(ec);
643 643
644 AUE_CLRBIT(sc, AUE_CTL0, AUE_CTL0_ALLMULTI); 644 AUE_CLRBIT(sc, AUE_CTL0, AUE_CTL0_ALLMULTI);
645 645
646 /* write the hashtable */ 646 /* write the hashtable */
647 for (i = 0; i < 8; i++) 647 for (i = 0; i < 8; i++)
648 aue_csr_write_1(sc, AUE_MAR0 + i, hashtbl[i]); 648 aue_csr_write_1(sc, AUE_MAR0 + i, hashtbl[i]);
649} 649}
650 650
651static void 651static void
652aue_reset_pegasus_II(struct aue_softc *sc) 652aue_reset_pegasus_II(struct aue_softc *sc)
653{ 653{
654 /* Magic constants taken from Linux driver. */ 654 /* Magic constants taken from Linux driver. */
655 aue_csr_write_1(sc, AUE_REG_1D, 0); 655 aue_csr_write_1(sc, AUE_REG_1D, 0);
656 aue_csr_write_1(sc, AUE_REG_7B, 2); 656 aue_csr_write_1(sc, AUE_REG_7B, 2);
657#if 0 657#if 0
658 if ((un->un_flags & PNA) && mii_mode) 658 if ((un->un_flags & PNA) && mii_mode)
659 aue_csr_write_1(sc, AUE_REG_81, 6); 659 aue_csr_write_1(sc, AUE_REG_81, 6);
660 else 660 else
661#endif 661#endif
662 aue_csr_write_1(sc, AUE_REG_81, 2); 662 aue_csr_write_1(sc, AUE_REG_81, 2);
663} 663}
664 664
665static void 665static void
666aue_reset(struct aue_softc *sc) 666aue_reset(struct aue_softc *sc)
667{ 667{
668 struct usbnet * const un = &sc->aue_un; 668 struct usbnet * const un = &sc->aue_un;
669 int i; 669 int i;
670 670
671 AUEHIST_FUNC(); 671 AUEHIST_FUNC();
672 AUEHIST_CALLARGSN(2, "aue%jd: enter", device_unit(un->un_dev), 0, 0, 0); 672 AUEHIST_CALLARGSN(2, "aue%jd: enter", device_unit(un->un_dev), 0, 0, 0);
673 673
674 AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_RESETMAC); 674 AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_RESETMAC);
675 675
676 for (i = 0; i < AUE_TIMEOUT; i++) { 676 for (i = 0; i < AUE_TIMEOUT; i++) {
677 if (usbnet_isdying(un)) 677 if (usbnet_isdying(un))
678 return; 678 return;
679 if (!(aue_csr_read_1(sc, AUE_CTL1) & AUE_CTL1_RESETMAC)) 679 if (!(aue_csr_read_1(sc, AUE_CTL1) & AUE_CTL1_RESETMAC))
680 break; 680 break;
681 } 681 }
682 682
683 if (i == AUE_TIMEOUT) 683 if (i == AUE_TIMEOUT)
684 printf("%s: reset failed\n", device_xname(un->un_dev)); 684 printf("%s: reset failed\n", device_xname(un->un_dev));
685 685
686#if 0 686#if 0
687 /* XXX what is mii_mode supposed to be */ 687 /* XXX what is mii_mode supposed to be */
688 if (sc->sc_mii_mode && (un->un_flags & PNA)) 688 if (sc->sc_mii_mode && (un->un_flags & PNA))
689 aue_csr_write_1(sc, AUE_GPIO1, 0x34); 689 aue_csr_write_1(sc, AUE_GPIO1, 0x34);
690 else 690 else
691 aue_csr_write_1(sc, AUE_GPIO1, 0x26); 691 aue_csr_write_1(sc, AUE_GPIO1, 0x26);
692#endif 692#endif
693 693
694 /* 694 /*
695 * The PHY(s) attached to the Pegasus chip may be held 695 * The PHY(s) attached to the Pegasus chip may be held
696 * in reset until we flip on the GPIO outputs. Make sure 696 * in reset until we flip on the GPIO outputs. Make sure
697 * to set the GPIO pins high so that the PHY(s) will 697 * to set the GPIO pins high so that the PHY(s) will
698 * be enabled. 698 * be enabled.
699 * 699 *
700 * Note: We force all of the GPIO pins low first, *then* 700 * Note: We force all of the GPIO pins low first, *then*
701 * enable the ones we want. 701 * enable the ones we want.
702 */ 702 */
703 if (un->un_flags & LSYS) { 703 if (un->un_flags & LSYS) {
704 /* Grrr. LinkSys has to be different from everyone else. */ 704 /* Grrr. LinkSys has to be different from everyone else. */
705 aue_csr_write_1(sc, AUE_GPIO0, 705 aue_csr_write_1(sc, AUE_GPIO0,
706 AUE_GPIO_SEL0 | AUE_GPIO_SEL1); 706 AUE_GPIO_SEL0 | AUE_GPIO_SEL1);
707 } else { 707 } else {
708 aue_csr_write_1(sc, AUE_GPIO0, 708 aue_csr_write_1(sc, AUE_GPIO0,
709 AUE_GPIO_OUT0 | AUE_GPIO_SEL0); 709 AUE_GPIO_OUT0 | AUE_GPIO_SEL0);
710 } 710 }
711 aue_csr_write_1(sc, AUE_GPIO0, 711 aue_csr_write_1(sc, AUE_GPIO0,
712 AUE_GPIO_OUT0 | AUE_GPIO_SEL0 | AUE_GPIO_SEL1); 712 AUE_GPIO_OUT0 | AUE_GPIO_SEL0 | AUE_GPIO_SEL1);
713 713
714 if (un->un_flags & PII) 714 if (un->un_flags & PII)
715 aue_reset_pegasus_II(sc); 715 aue_reset_pegasus_II(sc);
716 716
717 /* Wait a little while for the chip to get its brains in order. */ 717 /* Wait a little while for the chip to get its brains in order. */
718 delay(10000); /* XXX */ 718 delay(10000); /* XXX */
719 //usbd_delay_ms(un->un_udev, 10); /* XXX */ 719 //usbd_delay_ms(un->un_udev, 10); /* XXX */
720 720
721 DPRINTFN(2, "aue%jd: exit", device_unit(un->un_dev), 0, 0, 0); 721 DPRINTFN(2, "aue%jd: exit", device_unit(un->un_dev), 0, 0, 0);
722} 722}
723 723
724/* 724/*
725 * Probe for a Pegasus chip. 725 * Probe for a Pegasus chip.
726 */ 726 */
727static int 727static int
728aue_match(device_t parent, cfdata_t match, void *aux) 728aue_match(device_t parent, cfdata_t match, void *aux)
729{ 729{
730 struct usb_attach_arg *uaa = aux; 730 struct usb_attach_arg *uaa = aux;
731 731
732 /* 732 /*
733 * Some manufacturers use the same vendor and product id for 733 * Some manufacturers use the same vendor and product id for
734 * different devices. We need to sanity check the DeviceClass 734 * different devices. We need to sanity check the DeviceClass
735 * in this case 735 * in this case
736 * Currently known guilty products: 736 * Currently known guilty products:
737 * 0x050d/0x0121 Belkin Bluetooth and USB2LAN 737 * 0x050d/0x0121 Belkin Bluetooth and USB2LAN
738 * 738 *
739 * If this turns out to be more common, we could use a quirk 739 * If this turns out to be more common, we could use a quirk
740 * table. 740 * table.
741 */ 741 */
742 if (uaa->uaa_vendor == USB_VENDOR_BELKIN && 742 if (uaa->uaa_vendor == USB_VENDOR_BELKIN &&
743 uaa->uaa_product == USB_PRODUCT_BELKIN_USB2LAN) { 743 uaa->uaa_product == USB_PRODUCT_BELKIN_USB2LAN) {
744 usb_device_descriptor_t *dd; 744 usb_device_descriptor_t *dd;
745 745
746 dd = usbd_get_device_descriptor(uaa->uaa_device); 746 dd = usbd_get_device_descriptor(uaa->uaa_device);
747 if (dd != NULL && 747 if (dd != NULL &&
748 dd->bDeviceClass != UDCLASS_IN_INTERFACE) 748 dd->bDeviceClass != UDCLASS_IN_INTERFACE)
749 return UMATCH_NONE; 749 return UMATCH_NONE;
750 } 750 }
751 751
752 return aue_lookup(uaa->uaa_vendor, uaa->uaa_product) != NULL ? 752 return aue_lookup(uaa->uaa_vendor, uaa->uaa_product) != NULL ?
753 UMATCH_VENDOR_PRODUCT : UMATCH_NONE; 753 UMATCH_VENDOR_PRODUCT : UMATCH_NONE;
754} 754}
755 755
756/* 756/*
757 * Attach the interface. Allocate softc structures, do ifmedia 757 * Attach the interface. Allocate softc structures, do ifmedia
758 * setup and ethernet/BPF attach. 758 * setup and ethernet/BPF attach.
759 */ 759 */
760static void 760static void
761aue_attach(device_t parent, device_t self, void *aux) 761aue_attach(device_t parent, device_t self, void *aux)
762{ 762{
763 USBNET_MII_DECL_DEFAULT(unm); 763 USBNET_MII_DECL_DEFAULT(unm);
764 struct aue_softc * const sc = device_private(self); 764 struct aue_softc * const sc = device_private(self);
765 struct usbnet * const un = &sc->aue_un; 765 struct usbnet * const un = &sc->aue_un;
766 struct usb_attach_arg *uaa = aux; 766 struct usb_attach_arg *uaa = aux;
767 char *devinfop; 767 char *devinfop;
768 struct usbd_device *dev = uaa->uaa_device; 768 struct usbd_device *dev = uaa->uaa_device;
769 usbd_status err; 769 usbd_status err;
770 usb_interface_descriptor_t *id; 770 usb_interface_descriptor_t *id;
771 usb_endpoint_descriptor_t *ed; 771 usb_endpoint_descriptor_t *ed;
772 int i; 772 int i;
773 773
774 AUEHIST_FUNC(); 774 AUEHIST_FUNC();
775 AUEHIST_CALLARGSN(2, "aue%jd: enter sc=%#jx", 775 AUEHIST_CALLARGSN(2, "aue%jd: enter sc=%#jx",
776 device_unit(self), (uintptr_t)sc, 0, 0); 776 device_unit(self), (uintptr_t)sc, 0, 0);
777 777
778 KASSERT((void *)sc == un); 778 KASSERT((void *)sc == un);
779 779
780 aprint_naive("\n"); 780 aprint_naive("\n");
781 aprint_normal("\n"); 781 aprint_normal("\n");
782 devinfop = usbd_devinfo_alloc(uaa->uaa_device, 0); 782 devinfop = usbd_devinfo_alloc(uaa->uaa_device, 0);
783 aprint_normal_dev(self, "%s\n", devinfop); 783 aprint_normal_dev(self, "%s\n", devinfop);
784 usbd_devinfo_free(devinfop); 784 usbd_devinfo_free(devinfop);
785 785
786 un->un_dev = self; 786 un->un_dev = self;
787 un->un_udev = dev; 787 un->un_udev = dev;
788 un->un_sc = sc; 788 un->un_sc = sc;
789 un->un_ops = &aue_ops; 789 un->un_ops = &aue_ops;
790 un->un_intr = &sc->aue_intr; 790 un->un_intr = &sc->aue_intr;
791 un->un_rx_xfer_flags = USBD_SHORT_XFER_OK; 791 un->un_rx_xfer_flags = USBD_SHORT_XFER_OK;
792 un->un_tx_xfer_flags = USBD_FORCE_SHORT_XFER; 792 un->un_tx_xfer_flags = USBD_FORCE_SHORT_XFER;
793 un->un_rx_list_cnt = AUE_RX_LIST_CNT; 793 un->un_rx_list_cnt = AUE_RX_LIST_CNT;
794 un->un_tx_list_cnt = AUE_RX_LIST_CNT; 794 un->un_tx_list_cnt = AUE_RX_LIST_CNT;
795 un->un_rx_bufsz = AUE_BUFSZ; 795 un->un_rx_bufsz = AUE_BUFSZ;
796 un->un_tx_bufsz = AUE_BUFSZ; 796 un->un_tx_bufsz = AUE_BUFSZ;
797 797
798 sc->aue_intr.uni_buf = &sc->aue_ibuf; 798 sc->aue_intr.uni_buf = &sc->aue_ibuf;
799 sc->aue_intr.uni_bufsz = sizeof(sc->aue_ibuf); 799 sc->aue_intr.uni_bufsz = sizeof(sc->aue_ibuf);
800 sc->aue_intr.uni_interval = AUE_INTR_INTERVAL; 800 sc->aue_intr.uni_interval = AUE_INTR_INTERVAL;
801 801
802 err = usbd_set_config_no(dev, AUE_CONFIG_NO, 1); 802 err = usbd_set_config_no(dev, AUE_CONFIG_NO, 1);
803 if (err) { 803 if (err) {
804 aprint_error_dev(self, "failed to set configuration" 804 aprint_error_dev(self, "failed to set configuration"
805 ", err=%s\n", usbd_errstr(err)); 805 ", err=%s\n", usbd_errstr(err));
806 return; 806 return;
807 } 807 }
808 808
809 err = usbd_device2interface_handle(dev, AUE_IFACE_IDX, &un->un_iface); 809 err = usbd_device2interface_handle(dev, AUE_IFACE_IDX, &un->un_iface);
810 if (err) { 810 if (err) {
811 aprint_error_dev(self, "getting interface handle failed\n"); 811 aprint_error_dev(self, "getting interface handle failed\n");
812 return; 812 return;
813 } 813 }
814 814
815 un->un_flags = aue_lookup(uaa->uaa_vendor, uaa->uaa_product)->aue_flags; 815 un->un_flags = aue_lookup(uaa->uaa_vendor, uaa->uaa_product)->aue_flags;
816 816
817 id = usbd_get_interface_descriptor(un->un_iface); 817 id = usbd_get_interface_descriptor(un->un_iface);
818 818
819 /* Find endpoints. */ 819 /* Find endpoints. */
820 for (i = 0; i < id->bNumEndpoints; i++) { 820 for (i = 0; i < id->bNumEndpoints; i++) {
821 ed = usbd_interface2endpoint_descriptor(un->un_iface, i); 821 ed = usbd_interface2endpoint_descriptor(un->un_iface, i);
822 if (ed == NULL) { 822 if (ed == NULL) {
823 aprint_error_dev(self, 823 aprint_error_dev(self,
824 "couldn't get endpoint descriptor %d\n", i); 824 "couldn't get endpoint descriptor %d\n", i);
825 return; 825 return;
826 } 826 }
827 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN && 827 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
828 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) { 828 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
829 un->un_ed[USBNET_ENDPT_RX] = ed->bEndpointAddress; 829 un->un_ed[USBNET_ENDPT_RX] = ed->bEndpointAddress;
830 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT && 830 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
831 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) { 831 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
832 un->un_ed[USBNET_ENDPT_TX] = ed->bEndpointAddress; 832 un->un_ed[USBNET_ENDPT_TX] = ed->bEndpointAddress;
833 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN && 833 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
834 UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) { 834 UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
835 un->un_ed[USBNET_ENDPT_INTR] = ed->bEndpointAddress; 835 un->un_ed[USBNET_ENDPT_INTR] = ed->bEndpointAddress;
836 } 836 }
837 } 837 }
838 838
839 if (un->un_ed[USBNET_ENDPT_RX] == 0 || 839 if (un->un_ed[USBNET_ENDPT_RX] == 0 ||
840 un->un_ed[USBNET_ENDPT_TX] == 0 || 840 un->un_ed[USBNET_ENDPT_TX] == 0 ||
841 un->un_ed[USBNET_ENDPT_INTR] == 0) { 841 un->un_ed[USBNET_ENDPT_INTR] == 0) {
842 aprint_error_dev(self, "missing endpoint\n"); 842 aprint_error_dev(self, "missing endpoint\n");
843 return; 843 return;
844 } 844 }
845 845
846 /* First level attach. */ 846 /* First level attach. */
847 usbnet_attach(un, "auedet"); 847 usbnet_attach(un, "auedet");
848 848
849 usbnet_lock_core(un); 849 usbnet_lock_core(un);
850 850
851 /* Reset the adapter and get station address from the EEPROM. */ 851 /* Reset the adapter and get station address from the EEPROM. */
852 aue_reset(sc); 852 aue_reset(sc);
853 aue_read_mac(un); 853 aue_read_mac(un);
854 854
855 usbnet_unlock_core(un); 855 usbnet_unlock_core(un);
856 856
857 usbnet_attach_ifp(un, IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST, 857 usbnet_attach_ifp(un, IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST,
858 0, &unm); 858 0, &unm);
859} 859}
860 860
861static void 861static void
862aue_uno_intr(struct usbnet *un, usbd_status status) 862aue_uno_intr(struct usbnet *un, usbd_status status)
863{ 863{
864 struct ifnet *ifp = usbnet_ifp(un); 864 struct ifnet *ifp = usbnet_ifp(un);
865 struct aue_softc *sc = usbnet_softc(un); 865 struct aue_softc *sc = usbnet_softc(un);
866 struct aue_intrpkt *p = &sc->aue_ibuf; 866 struct aue_intrpkt *p = &sc->aue_ibuf;
867 867
868 AUEHIST_FUNC(); 868 AUEHIST_FUNC();
869 AUEHIST_CALLARGSN(20, "aue%jd: enter txstat0 %#jx\n", 869 AUEHIST_CALLARGSN(20, "aue%jd: enter txstat0 %#jx\n",
870 device_unit(un->un_dev), p->aue_txstat0, 0, 0); 870 device_unit(un->un_dev), p->aue_txstat0, 0, 0);
871 871
872 if (p->aue_txstat0) 872 if (p->aue_txstat0)
873 if_statinc(ifp, if_oerrors); 873 if_statinc(ifp, if_oerrors);
874 874
875 if (p->aue_txstat0 & (AUE_TXSTAT0_LATECOLL | AUE_TXSTAT0_EXCESSCOLL)) 875 if (p->aue_txstat0 & (AUE_TXSTAT0_LATECOLL | AUE_TXSTAT0_EXCESSCOLL))
876 if_statinc(ifp, if_collisions); 876 if_statinc(ifp, if_collisions);
877} 877}
878 878
879static void 879static void
880aue_uno_rx_loop(struct usbnet *un, struct usbnet_chain *c, uint32_t total_len) 880aue_uno_rx_loop(struct usbnet *un, struct usbnet_chain *c, uint32_t total_len)
881{ 881{
882 struct ifnet *ifp = usbnet_ifp(un); 882 struct ifnet *ifp = usbnet_ifp(un);
883 uint8_t *buf = c->unc_buf; 883 uint8_t *buf = c->unc_buf;
884 struct aue_rxpkt r; 884 struct aue_rxpkt r;
885 uint32_t pktlen; 885 uint32_t pktlen;
886 886
887 AUEHIST_FUNC(); 887 AUEHIST_FUNC();
888 AUEHIST_CALLARGSN(10, "aue%jd: enter len %ju", 888 AUEHIST_CALLARGSN(10, "aue%jd: enter len %ju",
889 device_unit(un->un_dev), total_len, 0, 0); 889 device_unit(un->un_dev), total_len, 0, 0);
890 890
891 if (total_len <= 4 + ETHER_CRC_LEN) { 891 if (total_len <= 4 + ETHER_CRC_LEN) {
892 if_statinc(ifp, if_ierrors); 892 if_statinc(ifp, if_ierrors);
893 return; 893 return;
894 } 894 }
895 895
896 memcpy(&r, buf + total_len - 4, sizeof(r)); 896 memcpy(&r, buf + total_len - 4, sizeof(r));
897 897
898 /* Turn off all the non-error bits in the rx status word. */ 898 /* Turn off all the non-error bits in the rx status word. */
899 r.aue_rxstat &= AUE_RXSTAT_MASK; 899 r.aue_rxstat &= AUE_RXSTAT_MASK;
900 if (r.aue_rxstat) { 900 if (r.aue_rxstat) {
901 if_statinc(ifp, if_ierrors); 901 if_statinc(ifp, if_ierrors);
902 return; 902 return;
903 } 903 }
904 904
905 /* No errors; receive the packet. */ 905 /* No errors; receive the packet. */
906 pktlen = total_len - ETHER_CRC_LEN - 4; 906 pktlen = total_len - ETHER_CRC_LEN - 4;
907 907
908 usbnet_enqueue(un, buf, pktlen, 0, 0, 0); 908 usbnet_enqueue(un, buf, pktlen, 0, 0, 0);
909} 909}
910 910
911static unsigned 911static unsigned
912aue_uno_tx_prepare(struct usbnet *un, struct mbuf *m, struct usbnet_chain *c) 912aue_uno_tx_prepare(struct usbnet *un, struct mbuf *m, struct usbnet_chain *c)
913{ 913{
914 uint8_t *buf = c->unc_buf; 914 uint8_t *buf = c->unc_buf;
915 int total_len; 915 int total_len;
916 916
917 AUEHIST_FUNC(); 917 AUEHIST_FUNC();
918 AUEHIST_CALLARGSN(10, "aue%jd: enter pktlen=%jd", 918 AUEHIST_CALLARGSN(10, "aue%jd: enter pktlen=%jd",
919 device_unit(un->un_dev), m->m_pkthdr.len, 0, 0); 919 device_unit(un->un_dev), m->m_pkthdr.len, 0, 0);
920 920
921 if ((unsigned)m->m_pkthdr.len > un->un_tx_bufsz - 2) 921 if ((unsigned)m->m_pkthdr.len > un->un_tx_bufsz - 2)
922 return 0; 922 return 0;
923 923
924 /* 924 /*
925 * Copy the mbuf data into a contiguous buffer, leaving two 925 * Copy the mbuf data into a contiguous buffer, leaving two
926 * bytes at the beginning to hold the frame length. 926 * bytes at the beginning to hold the frame length.
927 */ 927 */
928 m_copydata(m, 0, m->m_pkthdr.len, buf + 2); 928 m_copydata(m, 0, m->m_pkthdr.len, buf + 2);
929 929
930 /* 930 /*
931 * The ADMtek documentation says that the packet length is 931 * The ADMtek documentation says that the packet length is
932 * supposed to be specified in the first two bytes of the 932 * supposed to be specified in the first two bytes of the
933 * transfer, however it actually seems to ignore this info 933 * transfer, however it actually seems to ignore this info
934 * and base the frame size on the bulk transfer length. 934 * and base the frame size on the bulk transfer length.
935 */ 935 */
936 buf[0] = (uint8_t)m->m_pkthdr.len; 936 buf[0] = (uint8_t)m->m_pkthdr.len;
937 buf[1] = (uint8_t)(m->m_pkthdr.len >> 8); 937 buf[1] = (uint8_t)(m->m_pkthdr.len >> 8);
938 total_len = m->m_pkthdr.len + 2; 938 total_len = m->m_pkthdr.len + 2;
939 939
940 DPRINTFN(5, "aue%jd: send %jd bytes", 940 DPRINTFN(5, "aue%jd: send %jd bytes",
941 device_unit(un->un_dev), total_len, 0, 0); 941 device_unit(un->un_dev), total_len, 0, 0);
942 942
943 return total_len; 943 return total_len;
944} 944}
945 945
946static int 946static int
947aue_uno_init(struct ifnet *ifp) 947aue_uno_init(struct ifnet *ifp)
948{ 948{
949 struct usbnet * const un = ifp->if_softc; 949 struct usbnet * const un = ifp->if_softc;
950 struct aue_softc *sc = usbnet_softc(un); 950 struct aue_softc *sc = usbnet_softc(un);
951 int i, rv; 951 int i;
952 const u_char *eaddr; 952 const u_char *eaddr;
953 953
954 AUEHIST_FUNC(); 954 AUEHIST_FUNC();
955 AUEHIST_CALLARGSN(5, "aue%jd: enter link=%jd", 955 AUEHIST_CALLARGSN(5, "aue%jd: enter link=%jd",
956 device_unit(un->un_dev), usbnet_havelink(un), 0, 0); 956 device_unit(un->un_dev), usbnet_havelink(un), 0, 0);
957 957
958 if (usbnet_isdying(un)) 958 if (usbnet_isdying(un))
959 return EIO; 959 return EIO;
960 960
961 /* Cancel pending I/O */ 961 /* Cancel pending I/O */
962 if (ifp->if_flags & IFF_RUNNING) 962 if (ifp->if_flags & IFF_RUNNING)
963 return 0; 963 return 0;
964 964
965 /* Reset the interface. */ 965 /* Reset the interface. */
966 aue_reset(sc); 966 aue_reset(sc);
967 967
968 eaddr = CLLADDR(ifp->if_sadl); 968 eaddr = CLLADDR(ifp->if_sadl);
969 for (i = 0; i < ETHER_ADDR_LEN; i++) 969 for (i = 0; i < ETHER_ADDR_LEN; i++)
970 aue_csr_write_1(sc, AUE_PAR0 + i, eaddr[i]); 970 aue_csr_write_1(sc, AUE_PAR0 + i, eaddr[i]);
971 971
972 /* If we want promiscuous mode, set the allframes bit. */ 972 /* If we want promiscuous mode, set the allframes bit. */
973 if (ifp->if_flags & IFF_PROMISC) 973 if (ifp->if_flags & IFF_PROMISC)
974 AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC); 974 AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC);
975 else 975 else
976 AUE_CLRBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC); 976 AUE_CLRBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC);
977 977
978 /* Enable RX and TX */ 978 /* Enable RX and TX */
979 aue_csr_write_1(sc, AUE_CTL0, AUE_CTL0_RXSTAT_APPEND | AUE_CTL0_RX_ENB); 979 aue_csr_write_1(sc, AUE_CTL0, AUE_CTL0_RXSTAT_APPEND | AUE_CTL0_RX_ENB);
980 AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_TX_ENB); 980 AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_TX_ENB);
981 AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_EP3_CLR); 981 AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_EP3_CLR);
982 982
983 rv = usbnet_init_rx_tx(un); 983 return usbnet_init_rx_tx(un);
984 
985 //mii_mediachg(mii); 
986 
987 return rv; 
988} 984}
989 985
990static void 986static void
991aue_uno_stop(struct ifnet *ifp, int disable) 987aue_uno_stop(struct ifnet *ifp, int disable)
992{ 988{
993 struct usbnet * const un = ifp->if_softc; 989 struct usbnet * const un = ifp->if_softc;
994 struct aue_softc * const sc = usbnet_softc(un); 990 struct aue_softc * const sc = usbnet_softc(un);
995 991
996 AUEHIST_FUNC(); 992 AUEHIST_FUNC();
997 AUEHIST_CALLARGSN(5, "aue%jd: enter", device_unit(un->un_dev), 0, 0, 0); 993 AUEHIST_CALLARGSN(5, "aue%jd: enter", device_unit(un->un_dev), 0, 0, 0);
998 994
999 aue_csr_write_1(sc, AUE_CTL0, 0); 995 aue_csr_write_1(sc, AUE_CTL0, 0);
1000 aue_csr_write_1(sc, AUE_CTL1, 0); 996 aue_csr_write_1(sc, AUE_CTL1, 0);
1001 aue_reset(sc); 997 aue_reset(sc);
1002} 998}
1003 999
1004#ifdef _MODULE 1000#ifdef _MODULE
1005#include "ioconf.c" 1001#include "ioconf.c"
1006#endif 1002#endif
1007 1003
1008USBNET_MODULE(aue) 1004USBNET_MODULE(aue)