Deleted Added
full compact
if_rue.c (187970) if_rue.c (188412)
1/*-
2 * Copyright (c) 2001-2003, Shunsuke Akiyama <akiyama@FreeBSD.org>.
3 * Copyright (c) 1997, 1998, 1999, 2000 Bill Paul <wpaul@ee.columbia.edu>.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 43 unchanged lines hidden (view full) ---

52 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
53 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
54 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
55 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
56 * THE POSSIBILITY OF SUCH DAMAGE.
57 */
58
59#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2001-2003, Shunsuke Akiyama <akiyama@FreeBSD.org>.
3 * Copyright (c) 1997, 1998, 1999, 2000 Bill Paul <wpaul@ee.columbia.edu>.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 43 unchanged lines hidden (view full) ---

52 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
53 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
54 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
55 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
56 * THE POSSIBILITY OF SUCH DAMAGE.
57 */
58
59#include <sys/cdefs.h>
60__FBSDID("$FreeBSD: head/sys/dev/usb2/ethernet/if_rue2.c 187970 2009-02-01 00:51:25Z thompsa $");
60__FBSDID("$FreeBSD: head/sys/dev/usb2/ethernet/if_rue2.c 188412 2009-02-09 22:02:38Z thompsa $");
61
62/*
63 * RealTek RTL8150 USB to fast ethernet controller driver.
64 * Datasheet is available from
65 * ftp://ftp.realtek.com.tw/lancard/data_sheet/8150/.
66 */
67
61
62/*
63 * RealTek RTL8150 USB to fast ethernet controller driver.
64 * Datasheet is available from
65 * ftp://ftp.realtek.com.tw/lancard/data_sheet/8150/.
66 */
67
68/*
69 * NOTE: all function names beginning like "rue_cfg_" can only
70 * be called from within the config thread function !
71 */
72
73#include <dev/usb2/include/usb2_devid.h>
74#include <dev/usb2/include/usb2_standard.h>
75#include <dev/usb2/include/usb2_mfunc.h>
76#include <dev/usb2/include/usb2_error.h>
77
68#include <dev/usb2/include/usb2_devid.h>
69#include <dev/usb2/include/usb2_standard.h>
70#include <dev/usb2/include/usb2_mfunc.h>
71#include <dev/usb2/include/usb2_error.h>
72
78#define usb2_config_td_cc usb2_ether_cc
79#define usb2_config_td_softc rue_softc
80
81#define USB_DEBUG_VAR rue_debug
82
83#include <dev/usb2/core/usb2_core.h>
84#include <dev/usb2/core/usb2_lookup.h>
85#include <dev/usb2/core/usb2_process.h>
73#define USB_DEBUG_VAR rue_debug
74
75#include <dev/usb2/core/usb2_core.h>
76#include <dev/usb2/core/usb2_lookup.h>
77#include <dev/usb2/core/usb2_process.h>
86#include <dev/usb2/core/usb2_config_td.h>
87#include <dev/usb2/core/usb2_debug.h>
88#include <dev/usb2/core/usb2_request.h>
89#include <dev/usb2/core/usb2_busdma.h>
90#include <dev/usb2/core/usb2_util.h>
91
92#include <dev/usb2/ethernet/usb2_ethernet.h>
93#include <dev/usb2/ethernet/if_ruereg.h>
94

--- 16 unchanged lines hidden (view full) ---

111
112/* prototypes */
113
114static device_probe_t rue_probe;
115static device_attach_t rue_attach;
116static device_detach_t rue_detach;
117static device_shutdown_t rue_shutdown;
118
78#include <dev/usb2/core/usb2_debug.h>
79#include <dev/usb2/core/usb2_request.h>
80#include <dev/usb2/core/usb2_busdma.h>
81#include <dev/usb2/core/usb2_util.h>
82
83#include <dev/usb2/ethernet/usb2_ethernet.h>
84#include <dev/usb2/ethernet/if_ruereg.h>
85

--- 16 unchanged lines hidden (view full) ---

102
103/* prototypes */
104
105static device_probe_t rue_probe;
106static device_attach_t rue_attach;
107static device_detach_t rue_detach;
108static device_shutdown_t rue_shutdown;
109
119static usb2_callback_t rue_intr_clear_stall_callback;
110static miibus_readreg_t rue_miibus_readreg;
111static miibus_writereg_t rue_miibus_writereg;
112static miibus_statchg_t rue_miibus_statchg;
113
120static usb2_callback_t rue_intr_callback;
114static usb2_callback_t rue_intr_callback;
121static usb2_callback_t rue_bulk_read_clear_stall_callback;
122static usb2_callback_t rue_bulk_read_callback;
115static usb2_callback_t rue_bulk_read_callback;
123static usb2_callback_t rue_bulk_write_clear_stall_callback;
124static usb2_callback_t rue_bulk_write_callback;
125
116static usb2_callback_t rue_bulk_write_callback;
117
126static usb2_config_td_command_t rue_config_copy;
127static usb2_config_td_command_t rue_cfg_promisc_upd;
128static usb2_config_td_command_t rue_cfg_first_time_setup;
129static usb2_config_td_command_t rue_cfg_tick;
130static usb2_config_td_command_t rue_cfg_pre_init;
131static usb2_config_td_command_t rue_cfg_init;
132static usb2_config_td_command_t rue_cfg_ifmedia_upd;
133static usb2_config_td_command_t rue_cfg_pre_stop;
134static usb2_config_td_command_t rue_cfg_stop;
118static usb2_ether_fn_t rue_attach_post;
119static usb2_ether_fn_t rue_init;
120static usb2_ether_fn_t rue_stop;
121static usb2_ether_fn_t rue_start;
122static usb2_ether_fn_t rue_tick;
123static usb2_ether_fn_t rue_setmulti;
124static usb2_ether_fn_t rue_setpromisc;
135
125
136static void rue_cfg_do_request(struct rue_softc *sc, struct usb2_device_request *req, void *data);
137static void rue_cfg_read_mem(struct rue_softc *sc, uint16_t addr, void *buf, uint16_t len);
138static void rue_cfg_write_mem(struct rue_softc *sc, uint16_t addr, void *buf, uint16_t len);
139static uint8_t rue_cfg_csr_read_1(struct rue_softc *sc, uint16_t reg);
140static uint16_t rue_cfg_csr_read_2(struct rue_softc *sc, uint16_t reg);
141static void rue_cfg_csr_write_1(struct rue_softc *sc, uint16_t reg, uint8_t val);
142static void rue_cfg_csr_write_2(struct rue_softc *sc, uint16_t reg, uint16_t val);
143static void rue_cfg_csr_write_4(struct rue_softc *sc, int reg, uint32_t val);
126static int rue_read_mem(struct rue_softc *, uint16_t, void *, int);
127static int rue_write_mem(struct rue_softc *, uint16_t, void *, int);
128static uint8_t rue_csr_read_1(struct rue_softc *, uint16_t);
129static uint16_t rue_csr_read_2(struct rue_softc *, uint16_t);
130static int rue_csr_write_1(struct rue_softc *, uint16_t, uint8_t);
131static int rue_csr_write_2(struct rue_softc *, uint16_t, uint16_t);
132static int rue_csr_write_4(struct rue_softc *, int, uint32_t);
144
133
145static miibus_readreg_t rue_cfg_miibus_readreg;
146static miibus_writereg_t rue_cfg_miibus_writereg;
147static miibus_statchg_t rue_cfg_miibus_statchg;
134static void rue_reset(struct rue_softc *);
135static int rue_ifmedia_upd(struct ifnet *);
136static void rue_ifmedia_sts(struct ifnet *, struct ifmediareq *);
148
137
149static void rue_cfg_reset(struct rue_softc *sc);
150static void rue_start_cb(struct ifnet *ifp);
151static void rue_start_transfers(struct rue_softc *sc);
152static void rue_init_cb(void *arg);
153static int rue_ifmedia_upd_cb(struct ifnet *ifp);
154static void rue_ifmedia_sts_cb(struct ifnet *ifp, struct ifmediareq *ifmr);
155static int rue_ioctl_cb(struct ifnet *ifp, u_long command, caddr_t data);
156static void rue_watchdog(void *arg);
157
158static const struct usb2_config rue_config[RUE_N_TRANSFER] = {
159
160 [RUE_BULK_DT_WR] = {
161 .type = UE_BULK,
162 .endpoint = UE_ADDR_ANY,
163 .direction = UE_DIR_OUT,
164 .mh.bufsize = MCLBYTES,
165 .mh.flags = {.pipe_bof = 1,.force_short_xfer = 1,},
138static const struct usb2_config rue_config[RUE_N_TRANSFER] = {
139
140 [RUE_BULK_DT_WR] = {
141 .type = UE_BULK,
142 .endpoint = UE_ADDR_ANY,
143 .direction = UE_DIR_OUT,
144 .mh.bufsize = MCLBYTES,
145 .mh.flags = {.pipe_bof = 1,.force_short_xfer = 1,},
166 .mh.callback = &rue_bulk_write_callback,
146 .mh.callback = rue_bulk_write_callback,
167 .mh.timeout = 10000, /* 10 seconds */
168 },
169
170 [RUE_BULK_DT_RD] = {
171 .type = UE_BULK,
172 .endpoint = UE_ADDR_ANY,
173 .direction = UE_DIR_IN,
174 .mh.bufsize = (MCLBYTES + 4),
175 .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
147 .mh.timeout = 10000, /* 10 seconds */
148 },
149
150 [RUE_BULK_DT_RD] = {
151 .type = UE_BULK,
152 .endpoint = UE_ADDR_ANY,
153 .direction = UE_DIR_IN,
154 .mh.bufsize = (MCLBYTES + 4),
155 .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
176 .mh.callback = &rue_bulk_read_callback,
156 .mh.callback = rue_bulk_read_callback,
177 .mh.timeout = 0, /* no timeout */
178 },
179
157 .mh.timeout = 0, /* no timeout */
158 },
159
180 [RUE_BULK_CS_WR] = {
181 .type = UE_CONTROL,
182 .endpoint = 0x00, /* Control pipe */
183 .direction = UE_DIR_ANY,
184 .mh.bufsize = sizeof(struct usb2_device_request),
185 .mh.flags = {},
186 .mh.callback = &rue_bulk_write_clear_stall_callback,
187 .mh.timeout = 1000, /* 1 second */
188 .mh.interval = 50, /* 50ms */
189 },
190
191 [RUE_BULK_CS_RD] = {
192 .type = UE_CONTROL,
193 .endpoint = 0x00, /* Control pipe */
194 .direction = UE_DIR_ANY,
195 .mh.bufsize = sizeof(struct usb2_device_request),
196 .mh.flags = {},
197 .mh.callback = &rue_bulk_read_clear_stall_callback,
198 .mh.timeout = 1000, /* 1 second */
199 .mh.interval = 50, /* 50ms */
200 },
201
202 [RUE_INTR_DT_RD] = {
203 .type = UE_INTERRUPT,
204 .endpoint = UE_ADDR_ANY,
205 .direction = UE_DIR_IN,
206 .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
207 .mh.bufsize = 0, /* use wMaxPacketSize */
160 [RUE_INTR_DT_RD] = {
161 .type = UE_INTERRUPT,
162 .endpoint = UE_ADDR_ANY,
163 .direction = UE_DIR_IN,
164 .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
165 .mh.bufsize = 0, /* use wMaxPacketSize */
208 .mh.callback = &rue_intr_callback,
166 .mh.callback = rue_intr_callback,
209 },
167 },
210
211 [RUE_INTR_CS_RD] = {
212 .type = UE_CONTROL,
213 .endpoint = 0x00, /* Control pipe */
214 .direction = UE_DIR_ANY,
215 .mh.bufsize = sizeof(struct usb2_device_request),
216 .mh.flags = {},
217 .mh.callback = &rue_intr_clear_stall_callback,
218 .mh.timeout = 1000, /* 1 second */
219 .mh.interval = 50, /* 50ms */
220 },
221};
222
223static device_method_t rue_methods[] = {
224 /* Device interface */
225 DEVMETHOD(device_probe, rue_probe),
226 DEVMETHOD(device_attach, rue_attach),
227 DEVMETHOD(device_detach, rue_detach),
228 DEVMETHOD(device_shutdown, rue_shutdown),
229
230 /* Bus interface */
231 DEVMETHOD(bus_print_child, bus_generic_print_child),
232 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
233
234 /* MII interface */
168};
169
170static device_method_t rue_methods[] = {
171 /* Device interface */
172 DEVMETHOD(device_probe, rue_probe),
173 DEVMETHOD(device_attach, rue_attach),
174 DEVMETHOD(device_detach, rue_detach),
175 DEVMETHOD(device_shutdown, rue_shutdown),
176
177 /* Bus interface */
178 DEVMETHOD(bus_print_child, bus_generic_print_child),
179 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
180
181 /* MII interface */
235 DEVMETHOD(miibus_readreg, rue_cfg_miibus_readreg),
236 DEVMETHOD(miibus_writereg, rue_cfg_miibus_writereg),
237 DEVMETHOD(miibus_statchg, rue_cfg_miibus_statchg),
182 DEVMETHOD(miibus_readreg, rue_miibus_readreg),
183 DEVMETHOD(miibus_writereg, rue_miibus_writereg),
184 DEVMETHOD(miibus_statchg, rue_miibus_statchg),
238
239 {0, 0}
240};
241
242static driver_t rue_driver = {
243 .name = "rue",
244 .methods = rue_methods,
245 .size = sizeof(struct rue_softc),
246};
247
248static devclass_t rue_devclass;
249
250DRIVER_MODULE(rue, ushub, rue_driver, rue_devclass, NULL, 0);
251DRIVER_MODULE(miibus, rue, miibus_driver, miibus_devclass, 0, 0);
252MODULE_DEPEND(rue, usb2_ethernet, 1, 1, 1);
253MODULE_DEPEND(rue, usb2_core, 1, 1, 1);
254MODULE_DEPEND(rue, ether, 1, 1, 1);
255MODULE_DEPEND(rue, miibus, 1, 1, 1);
256
185
186 {0, 0}
187};
188
189static driver_t rue_driver = {
190 .name = "rue",
191 .methods = rue_methods,
192 .size = sizeof(struct rue_softc),
193};
194
195static devclass_t rue_devclass;
196
197DRIVER_MODULE(rue, ushub, rue_driver, rue_devclass, NULL, 0);
198DRIVER_MODULE(miibus, rue, miibus_driver, miibus_devclass, 0, 0);
199MODULE_DEPEND(rue, usb2_ethernet, 1, 1, 1);
200MODULE_DEPEND(rue, usb2_core, 1, 1, 1);
201MODULE_DEPEND(rue, ether, 1, 1, 1);
202MODULE_DEPEND(rue, miibus, 1, 1, 1);
203
257static void
258rue_cfg_do_request(struct rue_softc *sc, struct usb2_device_request *req,
259 void *data)
260{
261 uint16_t length;
262 usb2_error_t err;
204static const struct usb2_ether_methods rue_ue_methods = {
205 .ue_attach_post = rue_attach_post,
206 .ue_start = rue_start,
207 .ue_init = rue_init,
208 .ue_stop = rue_stop,
209 .ue_tick = rue_tick,
210 .ue_setmulti = rue_setmulti,
211 .ue_setpromisc = rue_setpromisc,
212 .ue_mii_upd = rue_ifmedia_upd,
213 .ue_mii_sts = rue_ifmedia_sts,
214};
263
215
264 if (usb2_config_td_is_gone(&sc->sc_config_td)) {
265 goto error;
266 }
267 err = usb2_do_request_flags
268 (sc->sc_udev, &sc->sc_mtx, req, data, 0, NULL, 1000);
216#define RUE_SETBIT(sc, reg, x) \
217 rue_csr_write_1(sc, reg, rue_csr_read_1(sc, reg) | (x))
269
218
270 if (err) {
219#define RUE_CLRBIT(sc, reg, x) \
220 rue_csr_write_1(sc, reg, rue_csr_read_1(sc, reg) & ~(x))
271
221
272 DPRINTF("device request failed, err=%s "
273 "(ignored)\n", usb2_errstr(err));
274
275error:
276 length = UGETW(req->wLength);
277
278 if ((req->bmRequestType & UT_READ) && length) {
279 bzero(data, length);
280 }
281 }
282}
283
284#define RUE_CFG_SETBIT(sc, reg, x) \
285 rue_cfg_csr_write_1(sc, reg, rue_cfg_csr_read_1(sc, reg) | (x))
286
287#define RUE_CFG_CLRBIT(sc, reg, x) \
288 rue_cfg_csr_write_1(sc, reg, rue_cfg_csr_read_1(sc, reg) & ~(x))
289
290static void
291rue_cfg_read_mem(struct rue_softc *sc, uint16_t addr, void *buf,
292 uint16_t len)
222static int
223rue_read_mem(struct rue_softc *sc, uint16_t addr, void *buf, int len)
293{
294 struct usb2_device_request req;
295
296 req.bmRequestType = UT_READ_VENDOR_DEVICE;
297 req.bRequest = UR_SET_ADDRESS;
298 USETW(req.wValue, addr);
299 USETW(req.wIndex, 0);
300 USETW(req.wLength, len);
301
224{
225 struct usb2_device_request req;
226
227 req.bmRequestType = UT_READ_VENDOR_DEVICE;
228 req.bRequest = UR_SET_ADDRESS;
229 USETW(req.wValue, addr);
230 USETW(req.wIndex, 0);
231 USETW(req.wLength, len);
232
302 rue_cfg_do_request(sc, &req, buf);
233 return (usb2_ether_do_request(&sc->sc_ue, &req, buf, 1000));
303}
304
234}
235
305static void
306rue_cfg_write_mem(struct rue_softc *sc, uint16_t addr, void *buf,
307 uint16_t len)
236static int
237rue_write_mem(struct rue_softc *sc, uint16_t addr, void *buf, int len)
308{
309 struct usb2_device_request req;
310
311 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
312 req.bRequest = UR_SET_ADDRESS;
313 USETW(req.wValue, addr);
314 USETW(req.wIndex, 0);
315 USETW(req.wLength, len);
316
238{
239 struct usb2_device_request req;
240
241 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
242 req.bRequest = UR_SET_ADDRESS;
243 USETW(req.wValue, addr);
244 USETW(req.wIndex, 0);
245 USETW(req.wLength, len);
246
317 rue_cfg_do_request(sc, &req, buf);
247 return (usb2_ether_do_request(&sc->sc_ue, &req, buf, 1000));
318}
319
320static uint8_t
248}
249
250static uint8_t
321rue_cfg_csr_read_1(struct rue_softc *sc, uint16_t reg)
251rue_csr_read_1(struct rue_softc *sc, uint16_t reg)
322{
323 uint8_t val;
324
252{
253 uint8_t val;
254
325 rue_cfg_read_mem(sc, reg, &val, 1);
255 rue_read_mem(sc, reg, &val, 1);
326 return (val);
327}
328
329static uint16_t
256 return (val);
257}
258
259static uint16_t
330rue_cfg_csr_read_2(struct rue_softc *sc, uint16_t reg)
260rue_csr_read_2(struct rue_softc *sc, uint16_t reg)
331{
332 uint8_t val[2];
333
261{
262 uint8_t val[2];
263
334 rue_cfg_read_mem(sc, reg, &val, 2);
264 rue_read_mem(sc, reg, &val, 2);
335 return (UGETW(val));
336}
337
265 return (UGETW(val));
266}
267
338static void
339rue_cfg_csr_write_1(struct rue_softc *sc, uint16_t reg, uint8_t val)
268static int
269rue_csr_write_1(struct rue_softc *sc, uint16_t reg, uint8_t val)
340{
270{
341 rue_cfg_write_mem(sc, reg, &val, 1);
271 return (rue_write_mem(sc, reg, &val, 1));
342}
343
272}
273
344static void
345rue_cfg_csr_write_2(struct rue_softc *sc, uint16_t reg, uint16_t val)
274static int
275rue_csr_write_2(struct rue_softc *sc, uint16_t reg, uint16_t val)
346{
347 uint8_t temp[2];
348
349 USETW(temp, val);
276{
277 uint8_t temp[2];
278
279 USETW(temp, val);
350 rue_cfg_write_mem(sc, reg, &temp, 2);
280 return (rue_write_mem(sc, reg, &temp, 2));
351}
352
281}
282
353static void
354rue_cfg_csr_write_4(struct rue_softc *sc, int reg, uint32_t val)
283static int
284rue_csr_write_4(struct rue_softc *sc, int reg, uint32_t val)
355{
356 uint8_t temp[4];
357
358 USETDW(temp, val);
285{
286 uint8_t temp[4];
287
288 USETDW(temp, val);
359 rue_cfg_write_mem(sc, reg, &temp, 4);
289 return (rue_write_mem(sc, reg, &temp, 4));
360}
361
362static int
290}
291
292static int
363rue_cfg_miibus_readreg(device_t dev, int phy, int reg)
293rue_miibus_readreg(device_t dev, int phy, int reg)
364{
365 struct rue_softc *sc = device_get_softc(dev);
366 uint16_t rval;
367 uint16_t ruereg;
294{
295 struct rue_softc *sc = device_get_softc(dev);
296 uint16_t rval;
297 uint16_t ruereg;
368 uint8_t do_unlock;
298 int locked;
369
299
370 if (phy != 0) { /* RTL8150 supports PHY == 0, only */
300 if (phy != 0) /* RTL8150 supports PHY == 0, only */
371 return (0);
301 return (0);
372 }
373 /* avoid recursive locking */
374 if (mtx_owned(&sc->sc_mtx)) {
375 do_unlock = 0;
376 } else {
377 mtx_lock(&sc->sc_mtx);
378 do_unlock = 1;
379 }
380
302
303 locked = mtx_owned(&sc->sc_mtx);
304 if (!locked)
305 RUE_LOCK(sc);
306
381 switch (reg) {
382 case MII_BMCR:
383 ruereg = RUE_BMCR;
384 break;
385 case MII_BMSR:
386 ruereg = RUE_BMSR;
387 break;
388 case MII_ANAR:

--- 5 unchanged lines hidden (view full) ---

394 case MII_ANLPAR:
395 ruereg = RUE_ANLP;
396 break;
397 case MII_PHYIDR1:
398 case MII_PHYIDR2:
399 rval = 0;
400 goto done;
401 default:
307 switch (reg) {
308 case MII_BMCR:
309 ruereg = RUE_BMCR;
310 break;
311 case MII_BMSR:
312 ruereg = RUE_BMSR;
313 break;
314 case MII_ANAR:

--- 5 unchanged lines hidden (view full) ---

320 case MII_ANLPAR:
321 ruereg = RUE_ANLP;
322 break;
323 case MII_PHYIDR1:
324 case MII_PHYIDR2:
325 rval = 0;
326 goto done;
327 default:
402 if ((RUE_REG_MIN <= reg) && (reg <= RUE_REG_MAX)) {
403 rval = rue_cfg_csr_read_1(sc, reg);
328 if (RUE_REG_MIN <= reg && reg <= RUE_REG_MAX) {
329 rval = rue_csr_read_1(sc, reg);
404 goto done;
405 }
330 goto done;
331 }
406 printf("rue%d: bad phy register\n", sc->sc_unit);
332 device_printf(sc->sc_ue.ue_dev, "bad phy register\n");
407 rval = 0;
408 goto done;
409 }
410
333 rval = 0;
334 goto done;
335 }
336
411 rval = rue_cfg_csr_read_2(sc, ruereg);
337 rval = rue_csr_read_2(sc, ruereg);
412done:
338done:
413 if (do_unlock) {
414 mtx_unlock(&sc->sc_mtx);
415 }
339 if (!locked)
340 RUE_UNLOCK(sc);
416 return (rval);
417}
418
419static int
341 return (rval);
342}
343
344static int
420rue_cfg_miibus_writereg(device_t dev, int phy, int reg, int data)
345rue_miibus_writereg(device_t dev, int phy, int reg, int data)
421{
422 struct rue_softc *sc = device_get_softc(dev);
423 uint16_t ruereg;
346{
347 struct rue_softc *sc = device_get_softc(dev);
348 uint16_t ruereg;
424 uint8_t do_unlock;
349 int locked;
425
350
426 if (phy != 0) { /* RTL8150 supports PHY == 0, only */
351 if (phy != 0) /* RTL8150 supports PHY == 0, only */
427 return (0);
352 return (0);
428 }
429 /* avoid recursive locking */
430 if (mtx_owned(&sc->sc_mtx)) {
431 do_unlock = 0;
432 } else {
433 mtx_lock(&sc->sc_mtx);
434 do_unlock = 1;
435 }
436
353
354 locked = mtx_owned(&sc->sc_mtx);
355 if (!locked)
356 RUE_LOCK(sc);
357
437 switch (reg) {
438 case MII_BMCR:
439 ruereg = RUE_BMCR;
440 break;
441 case MII_BMSR:
442 ruereg = RUE_BMSR;
443 break;
444 case MII_ANAR:

--- 4 unchanged lines hidden (view full) ---

449 break;
450 case MII_ANLPAR:
451 ruereg = RUE_ANLP;
452 break;
453 case MII_PHYIDR1:
454 case MII_PHYIDR2:
455 goto done;
456 default:
358 switch (reg) {
359 case MII_BMCR:
360 ruereg = RUE_BMCR;
361 break;
362 case MII_BMSR:
363 ruereg = RUE_BMSR;
364 break;
365 case MII_ANAR:

--- 4 unchanged lines hidden (view full) ---

370 break;
371 case MII_ANLPAR:
372 ruereg = RUE_ANLP;
373 break;
374 case MII_PHYIDR1:
375 case MII_PHYIDR2:
376 goto done;
377 default:
457 if ((RUE_REG_MIN <= reg) && (reg <= RUE_REG_MAX)) {
458 rue_cfg_csr_write_1(sc, reg, data);
378 if (RUE_REG_MIN <= reg && reg <= RUE_REG_MAX) {
379 rue_csr_write_1(sc, reg, data);
459 goto done;
460 }
380 goto done;
381 }
461 printf("%s: bad phy register\n",
462 sc->sc_name);
382 device_printf(sc->sc_ue.ue_dev, " bad phy register\n");
463 goto done;
464 }
383 goto done;
384 }
465 rue_cfg_csr_write_2(sc, ruereg, data);
385 rue_csr_write_2(sc, ruereg, data);
466done:
386done:
467 if (do_unlock) {
468 mtx_unlock(&sc->sc_mtx);
469 }
387 if (!locked)
388 RUE_UNLOCK(sc);
470 return (0);
471}
472
473static void
389 return (0);
390}
391
392static void
474rue_cfg_miibus_statchg(device_t dev)
393rue_miibus_statchg(device_t dev)
475{
476 /*
477 * When the code below is enabled the card starts doing weird
478 * things after link going from UP to DOWN and back UP.
479 *
480 * Looks like some of register writes below messes up PHY
481 * interface.
482 *
483 * No visible regressions were found after commenting this code
484 * out, so that disable it for good.
485 */
486#if 0
487 struct rue_softc *sc = device_get_softc(dev);
488 struct mii_data *mii = GET_MII(sc);
489 uint16_t bmcr;
394{
395 /*
396 * When the code below is enabled the card starts doing weird
397 * things after link going from UP to DOWN and back UP.
398 *
399 * Looks like some of register writes below messes up PHY
400 * interface.
401 *
402 * No visible regressions were found after commenting this code
403 * out, so that disable it for good.
404 */
405#if 0
406 struct rue_softc *sc = device_get_softc(dev);
407 struct mii_data *mii = GET_MII(sc);
408 uint16_t bmcr;
490 uint8_t do_unlock;
409 int locked;
491
410
492 /* avoid recursive locking */
493 if (mtx_owned(&sc->sc_mtx)) {
494 do_unlock = 0;
495 } else {
496 mtx_lock(&sc->sc_mtx);
497 do_unlock = 1;
498 }
411 locked = mtx_owned(&sc->sc_mtx);
412 if (!locked)
413 RUE_LOCK(sc);
499
414
500 RUE_CFG_CLRBIT(sc, RUE_CR, (RUE_CR_RE | RUE_CR_TE));
415 RUE_CLRBIT(sc, RUE_CR, (RUE_CR_RE | RUE_CR_TE));
501
416
502 bmcr = rue_cfg_csr_read_2(sc, RUE_BMCR);
417 bmcr = rue_csr_read_2(sc, RUE_BMCR);
503
504 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_100_TX)
505 bmcr |= RUE_BMCR_SPD_SET;
506 else
507 bmcr &= ~RUE_BMCR_SPD_SET;
508
509 if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX)
510 bmcr |= RUE_BMCR_DUPLEX;
511 else
512 bmcr &= ~RUE_BMCR_DUPLEX;
513
418
419 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_100_TX)
420 bmcr |= RUE_BMCR_SPD_SET;
421 else
422 bmcr &= ~RUE_BMCR_SPD_SET;
423
424 if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX)
425 bmcr |= RUE_BMCR_DUPLEX;
426 else
427 bmcr &= ~RUE_BMCR_DUPLEX;
428
514 rue_cfg_csr_write_2(sc, RUE_BMCR, bmcr);
429 rue_csr_write_2(sc, RUE_BMCR, bmcr);
515
430
516 RUE_CFG_SETBIT(sc, RUE_CR, (RUE_CR_RE | RUE_CR_TE));
431 RUE_SETBIT(sc, RUE_CR, (RUE_CR_RE | RUE_CR_TE));
517
432
518 if (do_unlock) {
519 mtx_unlock(&sc->sc_mtx);
520 }
433 if (!locked)
434 RUE_UNLOCK(sc);
521#endif
522}
523
524static void
435#endif
436}
437
438static void
525rue_mchash(struct usb2_config_td_cc *cc, const uint8_t *ptr)
439rue_setpromisc(struct usb2_ether *ue)
526{
440{
527 uint8_t h;
441 struct rue_softc *sc = usb2_ether_getsc(ue);
442 struct ifnet *ifp = usb2_ether_getifp(ue);
528
443
529 h = ether_crc32_be(ptr, ETHER_ADDR_LEN) >> 26;
530 cc->if_hash[h / 8] |= 1 << (h & 7);
531 cc->if_nhash = 1;
532}
444 RUE_LOCK_ASSERT(sc, MA_OWNED);
533
445
534static void
535rue_config_copy(struct rue_softc *sc,
536 struct usb2_config_td_cc *cc, uint16_t refcount)
537{
538 bzero(cc, sizeof(*cc));
539 usb2_ether_cc(sc->sc_ifp, &rue_mchash, cc);
446 /* If we want promiscuous mode, set the allframes bit. */
447 if (ifp->if_flags & IFF_PROMISC)
448 RUE_SETBIT(sc, RUE_RCR, RUE_RCR_AAP);
449 else
450 RUE_CLRBIT(sc, RUE_RCR, RUE_RCR_AAP);
540}
541
542/*
543 * Program the 64-bit multicast hash filter.
544 */
545static void
451}
452
453/*
454 * Program the 64-bit multicast hash filter.
455 */
456static void
546rue_cfg_promisc_upd(struct rue_softc *sc,
547 struct usb2_config_td_cc *cc, uint16_t refcount)
457rue_setmulti(struct usb2_ether *ue)
548{
458{
459 struct rue_softc *sc = usb2_ether_getsc(ue);
460 struct ifnet *ifp = usb2_ether_getifp(ue);
549 uint16_t rxcfg;
461 uint16_t rxcfg;
462 int h = 0;
463 uint32_t hashes[2] = { 0, 0 };
464 struct ifmultiaddr *ifma;
465 int mcnt = 0;
550
466
551 rxcfg = rue_cfg_csr_read_2(sc, RUE_RCR);
467 RUE_LOCK_ASSERT(sc, MA_OWNED);
552
468
553 if ((cc->if_flags & IFF_ALLMULTI) ||
554 (cc->if_flags & IFF_PROMISC)) {
469 rxcfg = rue_csr_read_2(sc, RUE_RCR);
470
471 if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
555 rxcfg |= (RUE_RCR_AAM | RUE_RCR_AAP);
556 rxcfg &= ~RUE_RCR_AM;
472 rxcfg |= (RUE_RCR_AAM | RUE_RCR_AAP);
473 rxcfg &= ~RUE_RCR_AM;
557 rue_cfg_csr_write_2(sc, RUE_RCR, rxcfg);
558 rue_cfg_csr_write_4(sc, RUE_MAR0, 0xFFFFFFFF);
559 rue_cfg_csr_write_4(sc, RUE_MAR4, 0xFFFFFFFF);
474 rue_csr_write_2(sc, RUE_RCR, rxcfg);
475 rue_csr_write_4(sc, RUE_MAR0, 0xFFFFFFFF);
476 rue_csr_write_4(sc, RUE_MAR4, 0xFFFFFFFF);
560 return;
561 }
477 return;
478 }
562 /* first, zero all the existing hash bits */
563 rue_cfg_csr_write_4(sc, RUE_MAR0, 0);
564 rue_cfg_csr_write_4(sc, RUE_MAR4, 0);
565
479
566 if (cc->if_nhash)
480 /* first, zot all the existing hash bits */
481 rue_csr_write_4(sc, RUE_MAR0, 0);
482 rue_csr_write_4(sc, RUE_MAR4, 0);
483
484 /* now program new ones */
485 IF_ADDR_LOCK(ifp);
486 TAILQ_FOREACH (ifma, &ifp->if_multiaddrs, ifma_link)
487 {
488 if (ifma->ifma_addr->sa_family != AF_LINK)
489 continue;
490 h = ether_crc32_be(LLADDR((struct sockaddr_dl *)
491 ifma->ifma_addr), ETHER_ADDR_LEN) >> 26;
492 if (h < 32)
493 hashes[0] |= (1 << h);
494 else
495 hashes[1] |= (1 << (h - 32));
496 mcnt++;
497 }
498 IF_ADDR_UNLOCK(ifp);
499
500 if (mcnt)
567 rxcfg |= RUE_RCR_AM;
568 else
569 rxcfg &= ~RUE_RCR_AM;
570
571 rxcfg &= ~(RUE_RCR_AAM | RUE_RCR_AAP);
572
501 rxcfg |= RUE_RCR_AM;
502 else
503 rxcfg &= ~RUE_RCR_AM;
504
505 rxcfg &= ~(RUE_RCR_AAM | RUE_RCR_AAP);
506
573 rue_cfg_csr_write_2(sc, RUE_RCR, rxcfg);
574 rue_cfg_write_mem(sc, RUE_MAR0, cc->if_hash, 4);
575 rue_cfg_write_mem(sc, RUE_MAR4, cc->if_hash + 4, 4);
507 rue_csr_write_2(sc, RUE_RCR, rxcfg);
508 rue_csr_write_4(sc, RUE_MAR0, hashes[0]);
509 rue_csr_write_4(sc, RUE_MAR4, hashes[1]);
576}
577
578static void
510}
511
512static void
579rue_cfg_reset(struct rue_softc *sc)
513rue_reset(struct rue_softc *sc)
580{
514{
581 usb2_error_t err;
582 uint16_t to;
515 int i;
583
516
584 rue_cfg_csr_write_1(sc, RUE_CR, RUE_CR_SOFT_RST);
517 rue_csr_write_1(sc, RUE_CR, RUE_CR_SOFT_RST);
585
518
586 for (to = 0;; to++) {
519 for (i = 0; i != RUE_TIMEOUT; i++) {
520 if (usb2_ether_pause(&sc->sc_ue, hz / 1000))
521 break;
522 if (!(rue_csr_read_1(sc, RUE_CR) & RUE_CR_SOFT_RST))
523 break;
524 }
525 if (i == RUE_TIMEOUT)
526 device_printf(sc->sc_ue.ue_dev, "reset never completed!\n");
587
527
588 if (to < RUE_TIMEOUT) {
528 usb2_ether_pause(&sc->sc_ue, hz / 100);
529}
589
530
590 err = usb2_config_td_sleep(&sc->sc_config_td, hz / 100);
531static void
532rue_attach_post(struct usb2_ether *ue)
533{
534 struct rue_softc *sc = usb2_ether_getsc(ue);
591
535
592 if (err) {
593 break;
594 }
595 if (!(rue_cfg_csr_read_1(sc, RUE_CR) & RUE_CR_SOFT_RST)) {
596 break;
597 }
598 } else {
599 printf("%s: reset timeout!\n",
600 sc->sc_name);
601 break;
602 }
603 }
536 /* reset the adapter */
537 rue_reset(sc);
604
538
605 err = usb2_config_td_sleep(&sc->sc_config_td, hz / 100);
539 /* get station address from the EEPROM */
540 rue_read_mem(sc, RUE_EEPROM_IDR0, ue->ue_eaddr, ETHER_ADDR_LEN);
606}
607
608/*
609 * Probe for a RTL8150 chip.
610 */
611static int
612rue_probe(device_t dev)
613{
614 struct usb2_attach_arg *uaa = device_get_ivars(dev);
615
541}
542
543/*
544 * Probe for a RTL8150 chip.
545 */
546static int
547rue_probe(device_t dev)
548{
549 struct usb2_attach_arg *uaa = device_get_ivars(dev);
550
616 if (uaa->usb2_mode != USB_MODE_HOST) {
551 if (uaa->usb2_mode != USB_MODE_HOST)
617 return (ENXIO);
552 return (ENXIO);
618 }
619 if (uaa->info.bConfigIndex != RUE_CONFIG_IDX) {
553 if (uaa->info.bConfigIndex != RUE_CONFIG_IDX)
620 return (ENXIO);
554 return (ENXIO);
621 }
622 if (uaa->info.bIfaceIndex != RUE_IFACE_IDX) {
555 if (uaa->info.bIfaceIndex != RUE_IFACE_IDX)
623 return (ENXIO);
556 return (ENXIO);
624 }
557
625 return (usb2_lookup_id_by_uaa(rue_devs, sizeof(rue_devs), uaa));
626}
627
628/*
629 * Attach the interface. Allocate softc structures, do ifmedia
630 * setup and ethernet/BPF attach.
631 */
632static int
633rue_attach(device_t dev)
634{
635 struct usb2_attach_arg *uaa = device_get_ivars(dev);
636 struct rue_softc *sc = device_get_softc(dev);
558 return (usb2_lookup_id_by_uaa(rue_devs, sizeof(rue_devs), uaa));
559}
560
561/*
562 * Attach the interface. Allocate softc structures, do ifmedia
563 * setup and ethernet/BPF attach.
564 */
565static int
566rue_attach(device_t dev)
567{
568 struct usb2_attach_arg *uaa = device_get_ivars(dev);
569 struct rue_softc *sc = device_get_softc(dev);
637 int32_t error;
570 struct usb2_ether *ue = &sc->sc_ue;
638 uint8_t iface_index;
571 uint8_t iface_index;
572 int error;
639
573
640 sc->sc_udev = uaa->device;
641 sc->sc_dev = dev;
642 sc->sc_unit = device_get_unit(dev);
643
644 device_set_usb2_desc(dev);
574 device_set_usb2_desc(dev);
575 mtx_init(&sc->sc_mtx, device_get_nameunit(dev), NULL, MTX_DEF);
645
576
646 snprintf(sc->sc_name, sizeof(sc->sc_name), "%s",
647 device_get_nameunit(dev));
648
649 mtx_init(&sc->sc_mtx, "rue lock", NULL, MTX_DEF | MTX_RECURSE);
650
651 usb2_callout_init_mtx(&sc->sc_watchdog, &sc->sc_mtx, 0);
652
653 iface_index = RUE_IFACE_IDX;
654 error = usb2_transfer_setup(uaa->device, &iface_index,
655 sc->sc_xfer, rue_config, RUE_N_TRANSFER,
656 sc, &sc->sc_mtx);
657 if (error) {
577 iface_index = RUE_IFACE_IDX;
578 error = usb2_transfer_setup(uaa->device, &iface_index,
579 sc->sc_xfer, rue_config, RUE_N_TRANSFER,
580 sc, &sc->sc_mtx);
581 if (error) {
658 device_printf(dev, "allocating USB "
659 "transfers failed!\n");
582 device_printf(dev, "allocating USB transfers failed!\n");
660 goto detach;
661 }
583 goto detach;
584 }
662 error = usb2_config_td_setup(&sc->sc_config_td, sc, &sc->sc_mtx,
663 NULL, sizeof(struct usb2_config_td_cc), 16);
585
586 ue->ue_sc = sc;
587 ue->ue_dev = dev;
588 ue->ue_udev = uaa->device;
589 ue->ue_mtx = &sc->sc_mtx;
590 ue->ue_methods = &rue_ue_methods;
591
592 error = usb2_ether_ifattach(ue);
664 if (error) {
593 if (error) {
665 device_printf(dev, "could not setup config "
666 "thread!\n");
594 device_printf(dev, "could not attach interface\n");
667 goto detach;
668 }
595 goto detach;
596 }
669 mtx_lock(&sc->sc_mtx);
670
671 sc->sc_flags |= RUE_FLAG_WAIT_LINK;
672
673 /* start setup */
674
675 usb2_config_td_queue_command
676 (&sc->sc_config_td, NULL, &rue_cfg_first_time_setup, 0, 0);
677
678 rue_watchdog(sc);
679 mtx_unlock(&sc->sc_mtx);
680 return (0); /* success */
681
682detach:
683 rue_detach(dev);
684 return (ENXIO); /* failure */
685}
686
597 return (0); /* success */
598
599detach:
600 rue_detach(dev);
601 return (ENXIO); /* failure */
602}
603
687static void
688rue_cfg_first_time_setup(struct rue_softc *sc,
689 struct usb2_config_td_cc *cc, uint16_t refcount)
690{
691 struct ifnet *ifp;
692 int error;
693 uint8_t eaddr[min(ETHER_ADDR_LEN, 6)];
694
695 /* reset the adapter */
696 rue_cfg_reset(sc);
697
698 /* get station address from the EEPROM */
699 rue_cfg_read_mem(sc, RUE_EEPROM_IDR0,
700 eaddr, ETHER_ADDR_LEN);
701
702 mtx_unlock(&sc->sc_mtx);
703
704 ifp = if_alloc(IFT_ETHER);
705
706 mtx_lock(&sc->sc_mtx);
707
708 if (ifp == NULL) {
709 printf("%s: could not if_alloc()\n",
710 sc->sc_name);
711 goto done;
712 }
713
714 ifp->if_softc = sc;
715 if_initname(ifp, "rue", sc->sc_unit);
716 ifp->if_mtu = ETHERMTU;
717 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
718 ifp->if_ioctl = rue_ioctl_cb;
719 ifp->if_start = rue_start_cb;
720 ifp->if_watchdog = NULL;
721 ifp->if_init = rue_init_cb;
722 IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN);
723 ifp->if_snd.ifq_drv_maxlen = IFQ_MAXLEN;
724 IFQ_SET_READY(&ifp->if_snd);
725
726 /*
727 * XXX need Giant when accessing the device structures !
728 */
729
730 mtx_unlock(&sc->sc_mtx);
731
732 mtx_lock(&Giant);
733
734 /* MII setup */
735 error = mii_phy_probe(sc->sc_dev, &sc->sc_miibus,
736 &rue_ifmedia_upd_cb,
737 &rue_ifmedia_sts_cb);
738 mtx_unlock(&Giant);
739
740 mtx_lock(&sc->sc_mtx);
741
742 if (error) {
743 printf("%s: MII without any PHY!\n",
744 sc->sc_name);
745 if_free(ifp);
746 goto done;
747 }
748 sc->sc_ifp = ifp;
749
750 mtx_unlock(&sc->sc_mtx);
751
752 /*
753 * Call MI attach routine.
754 */
755
756 ether_ifattach(ifp, eaddr);
757
758 mtx_lock(&sc->sc_mtx);
759
760done:
761 return;
762}
763
764static int
765rue_detach(device_t dev)
766{
767 struct rue_softc *sc = device_get_softc(dev);
604static int
605rue_detach(device_t dev)
606{
607 struct rue_softc *sc = device_get_softc(dev);
768 struct ifnet *ifp;
608 struct usb2_ether *ue = &sc->sc_ue;
769
609
770 usb2_config_td_drain(&sc->sc_config_td);
771
772 mtx_lock(&sc->sc_mtx);
773
774 usb2_callout_stop(&sc->sc_watchdog);
775
776 rue_cfg_pre_stop(sc, NULL, 0);
777
778 ifp = sc->sc_ifp;
779
780 mtx_unlock(&sc->sc_mtx);
781
782 /* stop all USB transfers first */
783 usb2_transfer_unsetup(sc->sc_xfer, RUE_N_TRANSFER);
610 usb2_transfer_unsetup(sc->sc_xfer, RUE_N_TRANSFER);
784
785 /* get rid of any late children */
786 bus_generic_detach(dev);
787
788 if (ifp) {
789 ether_ifdetach(ifp);
790 if_free(ifp);
791 }
792 usb2_config_td_unsetup(&sc->sc_config_td);
793
794 usb2_callout_drain(&sc->sc_watchdog);
795
611 usb2_ether_ifdetach(ue);
796 mtx_destroy(&sc->sc_mtx);
797
798 return (0);
799}
800
801static void
612 mtx_destroy(&sc->sc_mtx);
613
614 return (0);
615}
616
617static void
802rue_intr_clear_stall_callback(struct usb2_xfer *xfer)
803{
804 struct rue_softc *sc = xfer->priv_sc;
805 struct usb2_xfer *xfer_other = sc->sc_xfer[RUE_INTR_DT_RD];
806
807 if (usb2_clear_stall_callback(xfer, xfer_other)) {
808 DPRINTF("stall cleared\n");
809 sc->sc_flags &= ~RUE_FLAG_INTR_STALL;
810 usb2_transfer_start(xfer_other);
811 }
812}
813
814static void
815rue_intr_callback(struct usb2_xfer *xfer)
816{
817 struct rue_softc *sc = xfer->priv_sc;
618rue_intr_callback(struct usb2_xfer *xfer)
619{
620 struct rue_softc *sc = xfer->priv_sc;
818 struct ifnet *ifp = sc->sc_ifp;
621 struct ifnet *ifp = usb2_ether_getifp(&sc->sc_ue);
819 struct rue_intrpkt pkt;
820
821 switch (USB_GET_STATE(xfer)) {
822 case USB_ST_TRANSFERRED:
823
824 if (ifp && (ifp->if_drv_flags & IFF_DRV_RUNNING) &&
825 (xfer->actlen >= sizeof(pkt))) {
826
827 usb2_copy_out(xfer->frbuffers, 0, &pkt, sizeof(pkt));
828
829 ifp->if_ierrors += pkt.rue_rxlost_cnt;
830 ifp->if_ierrors += pkt.rue_crcerr_cnt;
831 ifp->if_collisions += pkt.rue_col_cnt;
832 }
622 struct rue_intrpkt pkt;
623
624 switch (USB_GET_STATE(xfer)) {
625 case USB_ST_TRANSFERRED:
626
627 if (ifp && (ifp->if_drv_flags & IFF_DRV_RUNNING) &&
628 (xfer->actlen >= sizeof(pkt))) {
629
630 usb2_copy_out(xfer->frbuffers, 0, &pkt, sizeof(pkt));
631
632 ifp->if_ierrors += pkt.rue_rxlost_cnt;
633 ifp->if_ierrors += pkt.rue_crcerr_cnt;
634 ifp->if_collisions += pkt.rue_col_cnt;
635 }
636 /* FALLTHROUGH */
833 case USB_ST_SETUP:
637 case USB_ST_SETUP:
834 if (sc->sc_flags & RUE_FLAG_INTR_STALL) {
835 usb2_transfer_start(sc->sc_xfer[RUE_INTR_CS_RD]);
836 } else {
837 xfer->frlengths[0] = xfer->max_data_length;
838 usb2_start_hardware(xfer);
839 }
638tr_setup:
639 xfer->frlengths[0] = xfer->max_data_length;
640 usb2_start_hardware(xfer);
840 return;
841
842 default: /* Error */
843 if (xfer->error != USB_ERR_CANCELLED) {
641 return;
642
643 default: /* Error */
644 if (xfer->error != USB_ERR_CANCELLED) {
844 /* start clear stall */
845 sc->sc_flags |= RUE_FLAG_INTR_STALL;
846 usb2_transfer_start(sc->sc_xfer[RUE_INTR_CS_RD]);
645 /* try to clear stall first */
646 xfer->flags.stall_pipe = 1;
647 goto tr_setup;
847 }
848 return;
849 }
850}
851
852static void
648 }
649 return;
650 }
651}
652
653static void
853rue_bulk_read_clear_stall_callback(struct usb2_xfer *xfer)
854{
855 struct rue_softc *sc = xfer->priv_sc;
856 struct usb2_xfer *xfer_other = sc->sc_xfer[RUE_BULK_DT_RD];
857
858 if (usb2_clear_stall_callback(xfer, xfer_other)) {
859 DPRINTF("stall cleared\n");
860 sc->sc_flags &= ~RUE_FLAG_READ_STALL;
861 usb2_transfer_start(xfer_other);
862 }
863}
864
865static void
866rue_bulk_read_callback(struct usb2_xfer *xfer)
867{
868 struct rue_softc *sc = xfer->priv_sc;
654rue_bulk_read_callback(struct usb2_xfer *xfer)
655{
656 struct rue_softc *sc = xfer->priv_sc;
869 struct ifnet *ifp = sc->sc_ifp;
657 struct usb2_ether *ue = &sc->sc_ue;
658 struct ifnet *ifp = usb2_ether_getifp(ue);
870 uint16_t status;
659 uint16_t status;
871 struct mbuf *m = NULL;
872
873 switch (USB_GET_STATE(xfer)) {
874 case USB_ST_TRANSFERRED:
875
876 if (xfer->actlen < 4) {
877 ifp->if_ierrors++;
878 goto tr_setup;
879 }
880 usb2_copy_out(xfer->frbuffers, xfer->actlen - 4,
881 &status, sizeof(status));
660
661 switch (USB_GET_STATE(xfer)) {
662 case USB_ST_TRANSFERRED:
663
664 if (xfer->actlen < 4) {
665 ifp->if_ierrors++;
666 goto tr_setup;
667 }
668 usb2_copy_out(xfer->frbuffers, xfer->actlen - 4,
669 &status, sizeof(status));
670 xfer->actlen -= 4;
882
671
883 status = le16toh(status);
884
885 /* check recieve packet was valid or not */
672 /* check recieve packet was valid or not */
886
673 status = le16toh(status);
887 if ((status & RUE_RXSTAT_VALID) == 0) {
888 ifp->if_ierrors++;
889 goto tr_setup;
890 }
674 if ((status & RUE_RXSTAT_VALID) == 0) {
675 ifp->if_ierrors++;
676 goto tr_setup;
677 }
891 xfer->actlen -= 4;
892
893 if (xfer->actlen < sizeof(struct ether_header)) {
894 ifp->if_ierrors++;
895 goto tr_setup;
896 }
897 m = usb2_ether_get_mbuf();
898
899 if (m == NULL) {
900 ifp->if_ierrors++;
901 goto tr_setup;
902 }
903 xfer->actlen = min(xfer->actlen, m->m_len);
904
905 usb2_copy_out(xfer->frbuffers, 0, m->m_data, xfer->actlen);
906
907 ifp->if_ipackets++;
908 m->m_pkthdr.rcvif = ifp;
909 m->m_pkthdr.len = m->m_len = xfer->actlen;
910
678 usb2_ether_rxbuf(ue, xfer->frbuffers, 0, xfer->actlen);
679 /* FALLTHROUGH */
911 case USB_ST_SETUP:
912tr_setup:
680 case USB_ST_SETUP:
681tr_setup:
913
914 if (sc->sc_flags & RUE_FLAG_READ_STALL) {
915 usb2_transfer_start(sc->sc_xfer[RUE_BULK_CS_RD]);
916 } else {
917 xfer->frlengths[0] = xfer->max_data_length;
918 usb2_start_hardware(xfer);
919 }
920
921 /*
922 * At the end of a USB callback it is always safe to unlock
923 * the private mutex of a device! That is why we do the
924 * "if_input" here, and not some lines up!
925 */
926 if (m) {
927 mtx_unlock(&sc->sc_mtx);
928 (ifp->if_input) (ifp, m);
929 mtx_lock(&sc->sc_mtx);
930 }
682 xfer->frlengths[0] = xfer->max_data_length;
683 usb2_start_hardware(xfer);
684 usb2_ether_rxflush(ue);
931 return;
932
933 default: /* Error */
685 return;
686
687 default: /* Error */
688 DPRINTF("bulk read error, %s\n",
689 usb2_errstr(xfer->error));
690
934 if (xfer->error != USB_ERR_CANCELLED) {
935 /* try to clear stall first */
691 if (xfer->error != USB_ERR_CANCELLED) {
692 /* try to clear stall first */
936 sc->sc_flags |= RUE_FLAG_READ_STALL;
937 usb2_transfer_start(sc->sc_xfer[RUE_BULK_CS_RD]);
693 xfer->flags.stall_pipe = 1;
694 goto tr_setup;
938 }
695 }
939 DPRINTF("bulk read error, %s\n",
940 usb2_errstr(xfer->error));
941 return;
696 return;
942
943 }
944}
945
946static void
697 }
698}
699
700static void
947rue_bulk_write_clear_stall_callback(struct usb2_xfer *xfer)
948{
949 struct rue_softc *sc = xfer->priv_sc;
950 struct usb2_xfer *xfer_other = sc->sc_xfer[RUE_BULK_DT_WR];
951
952 if (usb2_clear_stall_callback(xfer, xfer_other)) {
953 DPRINTF("stall cleared\n");
954 sc->sc_flags &= ~RUE_FLAG_WRITE_STALL;
955 usb2_transfer_start(xfer_other);
956 }
957}
958
959static void
960rue_bulk_write_callback(struct usb2_xfer *xfer)
961{
962 struct rue_softc *sc = xfer->priv_sc;
701rue_bulk_write_callback(struct usb2_xfer *xfer)
702{
703 struct rue_softc *sc = xfer->priv_sc;
963 struct ifnet *ifp = sc->sc_ifp;
704 struct ifnet *ifp = usb2_ether_getifp(&sc->sc_ue);
964 struct mbuf *m;
705 struct mbuf *m;
965 uint32_t temp_len;
706 int temp_len;
966
967 switch (USB_GET_STATE(xfer)) {
968 case USB_ST_TRANSFERRED:
969 DPRINTFN(11, "transfer complete\n");
707
708 switch (USB_GET_STATE(xfer)) {
709 case USB_ST_TRANSFERRED:
710 DPRINTFN(11, "transfer complete\n");
970
971 ifp->if_opackets++;
972
711 ifp->if_opackets++;
712
713 /* FALLTHROUGH */
973 case USB_ST_SETUP:
714 case USB_ST_SETUP:
974
975 if (sc->sc_flags & RUE_FLAG_WRITE_STALL) {
976 usb2_transfer_start(sc->sc_xfer[RUE_BULK_CS_WR]);
977 goto done;
978 }
979 if (sc->sc_flags & RUE_FLAG_WAIT_LINK) {
715tr_setup:
716 if ((sc->sc_flags & RUE_FLAG_LINK) == 0) {
980 /*
981 * don't send anything if there is no link !
982 */
717 /*
718 * don't send anything if there is no link !
719 */
983 goto done;
720 return;
984 }
985 IFQ_DRV_DEQUEUE(&ifp->if_snd, m);
986
721 }
722 IFQ_DRV_DEQUEUE(&ifp->if_snd, m);
723
987 if (m == NULL) {
988 goto done;
989 }
990 if (m->m_pkthdr.len > MCLBYTES) {
724 if (m == NULL)
725 return;
726 if (m->m_pkthdr.len > MCLBYTES)
991 m->m_pkthdr.len = MCLBYTES;
727 m->m_pkthdr.len = MCLBYTES;
992 }
993 temp_len = m->m_pkthdr.len;
994
995 usb2_m_copy_in(xfer->frbuffers, 0,
996 m, 0, m->m_pkthdr.len);
997
998 /*
999 * This is an undocumented behavior.
1000 * RTL8150 chip doesn't send frame length smaller than

--- 11 unchanged lines hidden (view full) ---

1012 * of this frame to him:
1013 */
1014 BPF_MTAP(ifp, m);
1015
1016 m_freem(m);
1017
1018 usb2_start_hardware(xfer);
1019
728 temp_len = m->m_pkthdr.len;
729
730 usb2_m_copy_in(xfer->frbuffers, 0,
731 m, 0, m->m_pkthdr.len);
732
733 /*
734 * This is an undocumented behavior.
735 * RTL8150 chip doesn't send frame length smaller than

--- 11 unchanged lines hidden (view full) ---

747 * of this frame to him:
748 */
749 BPF_MTAP(ifp, m);
750
751 m_freem(m);
752
753 usb2_start_hardware(xfer);
754
1020done:
1021 return;
1022
1023 default: /* Error */
1024 DPRINTFN(11, "transfer error, %s\n",
1025 usb2_errstr(xfer->error));
1026
755 return;
756
757 default: /* Error */
758 DPRINTFN(11, "transfer error, %s\n",
759 usb2_errstr(xfer->error));
760
761 ifp->if_oerrors++;
762
1027 if (xfer->error != USB_ERR_CANCELLED) {
1028 /* try to clear stall first */
763 if (xfer->error != USB_ERR_CANCELLED) {
764 /* try to clear stall first */
1029 sc->sc_flags |= RUE_FLAG_WRITE_STALL;
1030 usb2_transfer_start(sc->sc_xfer[RUE_BULK_CS_WR]);
765 xfer->flags.stall_pipe = 1;
766 goto tr_setup;
1031 }
767 }
1032 ifp->if_oerrors++;
1033 return;
768 return;
1034
1035 }
1036}
1037
1038static void
769 }
770}
771
772static void
1039rue_cfg_tick(struct rue_softc *sc,
1040 struct usb2_config_td_cc *cc, uint16_t refcount)
773rue_tick(struct usb2_ether *ue)
1041{
774{
1042 struct ifnet *ifp = sc->sc_ifp;
775 struct rue_softc *sc = usb2_ether_getsc(ue);
1043 struct mii_data *mii = GET_MII(sc);
1044
776 struct mii_data *mii = GET_MII(sc);
777
1045 if ((ifp == NULL) ||
1046 (mii == NULL)) {
1047 /* not ready */
1048 return;
1049 }
1050 mii_tick(mii);
778 RUE_LOCK_ASSERT(sc, MA_OWNED);
1051
779
1052 mii_pollstat(mii);
1053
1054 if ((sc->sc_flags & RUE_FLAG_WAIT_LINK) &&
1055 (mii->mii_media_status & IFM_ACTIVE) &&
1056 (IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE)) {
1057 sc->sc_flags &= ~RUE_FLAG_WAIT_LINK;
780 mii_tick(mii);
781 if ((sc->sc_flags & RUE_FLAG_LINK) == 0
782 && mii->mii_media_status & IFM_ACTIVE &&
783 IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
784 sc->sc_flags |= RUE_FLAG_LINK;
785 rue_start(ue);
1058 }
786 }
1059 sc->sc_media_active = mii->mii_media_active;
1060 sc->sc_media_status = mii->mii_media_status;
1061
1062 /* start stopped transfers, if any */
1063
1064 rue_start_transfers(sc);
1065}
1066
1067static void
787}
788
789static void
1068rue_start_cb(struct ifnet *ifp)
790rue_start(struct usb2_ether *ue)
1069{
791{
1070 struct rue_softc *sc = ifp->if_softc;
792 struct rue_softc *sc = usb2_ether_getsc(ue);
1071
793
1072 mtx_lock(&sc->sc_mtx);
1073
1074 rue_start_transfers(sc);
1075
1076 mtx_unlock(&sc->sc_mtx);
794 /*
795 * start the USB transfers, if not already started:
796 */
797 usb2_transfer_start(sc->sc_xfer[RUE_INTR_DT_RD]);
798 usb2_transfer_start(sc->sc_xfer[RUE_BULK_DT_RD]);
799 usb2_transfer_start(sc->sc_xfer[RUE_BULK_DT_WR]);
1077}
1078
1079static void
800}
801
802static void
1080rue_start_transfers(struct rue_softc *sc)
803rue_init(struct usb2_ether *ue)
1081{
804{
1082 if ((sc->sc_flags & RUE_FLAG_LL_READY) &&
1083 (sc->sc_flags & RUE_FLAG_HL_READY)) {
805 struct rue_softc *sc = usb2_ether_getsc(ue);
806 struct ifnet *ifp = usb2_ether_getifp(ue);
1084
807
1085 /*
1086 * start the USB transfers, if not already started:
1087 */
1088 usb2_transfer_start(sc->sc_xfer[RUE_INTR_DT_RD]);
1089 usb2_transfer_start(sc->sc_xfer[RUE_BULK_DT_RD]);
1090 usb2_transfer_start(sc->sc_xfer[RUE_BULK_DT_WR]);
1091 }
1092}
808 RUE_LOCK_ASSERT(sc, MA_OWNED);
1093
809
1094static void
1095rue_init_cb(void *arg)
1096{
1097 struct rue_softc *sc = arg;
1098
1099 mtx_lock(&sc->sc_mtx);
1100 usb2_config_td_queue_command
1101 (&sc->sc_config_td, &rue_cfg_pre_init,
1102 &rue_cfg_init, 0, 0);
1103 mtx_unlock(&sc->sc_mtx);
1104}
1105
1106static void
1107rue_cfg_pre_init(struct rue_softc *sc,
1108 struct usb2_config_td_cc *cc, uint16_t refcount)
1109{
1110 struct ifnet *ifp = sc->sc_ifp;
1111
1112 /* immediate configuration */
1113
1114 rue_cfg_pre_stop(sc, cc, 0);
1115
1116 ifp->if_drv_flags |= IFF_DRV_RUNNING;
1117
1118 sc->sc_flags |= RUE_FLAG_HL_READY;
1119}
1120
1121static void
1122rue_cfg_init(struct rue_softc *sc,
1123 struct usb2_config_td_cc *cc, uint16_t refcount)
1124{
1125 struct mii_data *mii = GET_MII(sc);
1126 uint16_t rxcfg;
1127
1128 /*
1129 * Cancel pending I/O
1130 */
810 /*
811 * Cancel pending I/O
812 */
813 rue_reset(sc);
1131
814
1132 rue_cfg_stop(sc, cc, 0);
815 /* Set MAC address */
816 rue_write_mem(sc, RUE_IDR0, IF_LLADDR(ifp), ETHER_ADDR_LEN);
1133
817
1134 /* set MAC address */
818 rue_stop(ue);
1135
819
1136 rue_cfg_write_mem(sc, RUE_IDR0, cc->if_lladdr, ETHER_ADDR_LEN);
1137
1138 /*
1139 * Set the initial TX and RX configuration.
1140 */
820 /*
821 * Set the initial TX and RX configuration.
822 */
1141 rue_cfg_csr_write_1(sc, RUE_TCR, RUE_TCR_CONFIG);
823 rue_csr_write_1(sc, RUE_TCR, RUE_TCR_CONFIG);
824 rue_csr_write_2(sc, RUE_RCR, RUE_RCR_CONFIG|RUE_RCR_AB);
1142
825
1143 rxcfg = RUE_RCR_CONFIG;
1144
1145 /* Set capture broadcast bit to capture broadcast frames. */
1146 if (cc->if_flags & IFF_BROADCAST)
1147 rxcfg |= RUE_RCR_AB;
1148 else
1149 rxcfg &= ~RUE_RCR_AB;
1150
1151 rue_cfg_csr_write_2(sc, RUE_RCR, rxcfg);
1152
1153 /* Load the multicast filter */
826 /* Load the multicast filter */
1154 rue_cfg_promisc_upd(sc, cc, 0);
827 rue_setpromisc(ue);
828 /* Load the multicast filter. */
829 rue_setmulti(ue);
1155
1156 /* Enable RX and TX */
830
831 /* Enable RX and TX */
1157 rue_cfg_csr_write_1(sc, RUE_CR, (RUE_CR_TE | RUE_CR_RE | RUE_CR_EP3CLREN));
832 rue_csr_write_1(sc, RUE_CR, (RUE_CR_TE | RUE_CR_RE | RUE_CR_EP3CLREN));
1158
833
1159 mii_mediachg(mii);
834 usb2_transfer_set_stall(sc->sc_xfer[RUE_BULK_DT_WR]);
1160
835
1161 sc->sc_flags |= (RUE_FLAG_READ_STALL |
1162 RUE_FLAG_WRITE_STALL |
1163 RUE_FLAG_LL_READY);
1164
1165 rue_start_transfers(sc);
836 ifp->if_drv_flags |= IFF_DRV_RUNNING;
837 rue_start(ue);
1166}
1167
1168/*
1169 * Set media options.
1170 */
1171static int
838}
839
840/*
841 * Set media options.
842 */
843static int
1172rue_ifmedia_upd_cb(struct ifnet *ifp)
844rue_ifmedia_upd(struct ifnet *ifp)
1173{
1174 struct rue_softc *sc = ifp->if_softc;
845{
846 struct rue_softc *sc = ifp->if_softc;
1175
1176 mtx_lock(&sc->sc_mtx);
1177 usb2_config_td_queue_command
1178 (&sc->sc_config_td, NULL,
1179 &rue_cfg_ifmedia_upd, 0, 0);
1180 mtx_unlock(&sc->sc_mtx);
1181
1182 return (0);
1183}
1184
1185static void
1186rue_cfg_ifmedia_upd(struct rue_softc *sc,
1187 struct usb2_config_td_cc *cc, uint16_t refcount)
1188{
1189 struct ifnet *ifp = sc->sc_ifp;
1190 struct mii_data *mii = GET_MII(sc);
1191
847 struct mii_data *mii = GET_MII(sc);
848
1192 if ((ifp == NULL) ||
1193 (mii == NULL)) {
1194 /* not ready */
1195 return;
1196 }
1197 sc->sc_flags |= RUE_FLAG_WAIT_LINK;
849 RUE_LOCK_ASSERT(sc, MA_OWNED);
1198
850
851 sc->sc_flags &= ~RUE_FLAG_LINK;
1199 if (mii->mii_instance) {
1200 struct mii_softc *miisc;
1201
852 if (mii->mii_instance) {
853 struct mii_softc *miisc;
854
1202 LIST_FOREACH(miisc, &mii->mii_phys, mii_list) {
855 LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
1203 mii_phy_reset(miisc);
856 mii_phy_reset(miisc);
1204 }
1205 }
1206 mii_mediachg(mii);
857 }
858 mii_mediachg(mii);
859 return (0);
1207}
1208
1209/*
1210 * Report current media status.
1211 */
1212static void
860}
861
862/*
863 * Report current media status.
864 */
865static void
1213rue_ifmedia_sts_cb(struct ifnet *ifp, struct ifmediareq *ifmr)
866rue_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
1214{
1215 struct rue_softc *sc = ifp->if_softc;
867{
868 struct rue_softc *sc = ifp->if_softc;
869 struct mii_data *mii = GET_MII(sc);
1216
870
1217 mtx_lock(&sc->sc_mtx);
1218
1219 ifmr->ifm_active = sc->sc_media_active;
1220 ifmr->ifm_status = sc->sc_media_status;
1221
1222 mtx_unlock(&sc->sc_mtx);
871 RUE_LOCK(sc);
872 mii_pollstat(mii);
873 RUE_UNLOCK(sc);
874 ifmr->ifm_active = mii->mii_media_active;
875 ifmr->ifm_status = mii->mii_media_status;
1223}
1224
876}
877
1225static int
1226rue_ioctl_cb(struct ifnet *ifp, u_long command, caddr_t data)
1227{
1228 struct rue_softc *sc = ifp->if_softc;
1229 struct mii_data *mii;
1230 int error = 0;
1231
1232 switch (command) {
1233 case SIOCSIFFLAGS:
1234
1235 mtx_lock(&sc->sc_mtx);
1236 if (ifp->if_flags & IFF_UP) {
1237 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
1238 usb2_config_td_queue_command
1239 (&sc->sc_config_td, &rue_config_copy,
1240 &rue_cfg_promisc_upd, 0, 0);
1241 } else {
1242 usb2_config_td_queue_command
1243 (&sc->sc_config_td, &rue_cfg_pre_init,
1244 &rue_cfg_init, 0, 0);
1245 }
1246 } else {
1247 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
1248 usb2_config_td_queue_command
1249 (&sc->sc_config_td, &rue_cfg_pre_stop,
1250 &rue_cfg_stop, 0, 0);
1251 }
1252 }
1253 mtx_unlock(&sc->sc_mtx);
1254 break;
1255
1256 case SIOCADDMULTI:
1257 case SIOCDELMULTI:
1258 mtx_lock(&sc->sc_mtx);
1259 usb2_config_td_queue_command
1260 (&sc->sc_config_td, &rue_config_copy,
1261 &rue_cfg_promisc_upd, 0, 0);
1262 mtx_unlock(&sc->sc_mtx);
1263 break;
1264
1265 case SIOCGIFMEDIA:
1266 case SIOCSIFMEDIA:
1267 mii = GET_MII(sc);
1268 if (mii == NULL) {
1269 error = EINVAL;
1270 } else {
1271 error = ifmedia_ioctl
1272 (ifp, (void *)data, &mii->mii_media, command);
1273 }
1274 break;
1275
1276 default:
1277 error = ether_ioctl(ifp, command, data);
1278 break;
1279 }
1280 return (error);
1281}
1282
1283static void
878static void
1284rue_watchdog(void *arg)
879rue_stop(struct usb2_ether *ue)
1285{
880{
1286 struct rue_softc *sc = arg;
881 struct rue_softc *sc = usb2_ether_getsc(ue);
882 struct ifnet *ifp = usb2_ether_getifp(ue);
1287
883
1288 mtx_assert(&sc->sc_mtx, MA_OWNED);
884 RUE_LOCK_ASSERT(sc, MA_OWNED);
1289
885
1290 usb2_config_td_queue_command
1291 (&sc->sc_config_td, NULL, &rue_cfg_tick, 0, 0);
886 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
887 sc->sc_flags &= ~RUE_FLAG_LINK;
1292
888
1293 usb2_callout_reset(&sc->sc_watchdog,
1294 hz, &rue_watchdog, sc);
1295}
1296
1297/*
1298 * NOTE: can be called when "ifp" is NULL
1299 */
1300static void
1301rue_cfg_pre_stop(struct rue_softc *sc,
1302 struct usb2_config_td_cc *cc, uint16_t refcount)
1303{
1304 struct ifnet *ifp = sc->sc_ifp;
1305
1306 if (cc) {
1307 /* copy the needed configuration */
1308 rue_config_copy(sc, cc, refcount);
1309 }
1310 /* immediate configuration */
1311
1312 if (ifp) {
1313 /* clear flags */
1314 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
1315 }
1316 sc->sc_flags &= ~(RUE_FLAG_HL_READY |
1317 RUE_FLAG_LL_READY);
1318
1319 sc->sc_flags |= RUE_FLAG_WAIT_LINK;
1320
1321 /*
1322 * stop all the transfers, if not already stopped:
1323 */
1324 usb2_transfer_stop(sc->sc_xfer[RUE_BULK_DT_WR]);
1325 usb2_transfer_stop(sc->sc_xfer[RUE_BULK_DT_RD]);
889 /*
890 * stop all the transfers, if not already stopped:
891 */
892 usb2_transfer_stop(sc->sc_xfer[RUE_BULK_DT_WR]);
893 usb2_transfer_stop(sc->sc_xfer[RUE_BULK_DT_RD]);
1326 usb2_transfer_stop(sc->sc_xfer[RUE_BULK_CS_WR]);
1327 usb2_transfer_stop(sc->sc_xfer[RUE_BULK_CS_RD]);
1328 usb2_transfer_stop(sc->sc_xfer[RUE_INTR_DT_RD]);
894 usb2_transfer_stop(sc->sc_xfer[RUE_INTR_DT_RD]);
1329 usb2_transfer_stop(sc->sc_xfer[RUE_INTR_CS_RD]);
1330}
1331
895
1332static void
1333rue_cfg_stop(struct rue_softc *sc,
1334 struct usb2_config_td_cc *cc, uint16_t refcount)
1335{
1336 rue_cfg_csr_write_1(sc, RUE_CR, 0x00);
896 rue_csr_write_1(sc, RUE_CR, 0x00);
1337
897
1338 rue_cfg_reset(sc);
898 rue_reset(sc);
1339}
1340
1341/*
1342 * Stop all chip I/O so that the kernel's probe routines don't
1343 * get confused by errant DMAs when rebooting.
1344 */
1345static int
1346rue_shutdown(device_t dev)
1347{
1348 struct rue_softc *sc = device_get_softc(dev);
1349
899}
900
901/*
902 * Stop all chip I/O so that the kernel's probe routines don't
903 * get confused by errant DMAs when rebooting.
904 */
905static int
906rue_shutdown(device_t dev)
907{
908 struct rue_softc *sc = device_get_softc(dev);
909
1350 mtx_lock(&sc->sc_mtx);
910 usb2_ether_ifshutdown(&sc->sc_ue);
1351
911
1352 usb2_config_td_queue_command
1353 (&sc->sc_config_td, &rue_cfg_pre_stop,
1354 &rue_cfg_stop, 0, 0);
1355
1356 mtx_unlock(&sc->sc_mtx);
1357
1358 return (0);
1359}
912 return (0);
913}