if_kue.c (187970) | if_kue.c (188412) |
---|---|
1/*- 2 * Copyright (c) 1997, 1998, 1999, 2000 3 * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 30 * THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1997, 1998, 1999, 2000 3 * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 30 * THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33#include <sys/cdefs.h> |
34__FBSDID("$FreeBSD: head/sys/dev/usb2/ethernet/if_kue2.c 187970 2009-02-01 00:51:25Z thompsa $"); | 34__FBSDID("$FreeBSD: head/sys/dev/usb2/ethernet/if_kue2.c 188412 2009-02-09 22:02:38Z thompsa $"); |
35 36/* 37 * Kawasaki LSI KL5KUSB101B USB to ethernet adapter driver. 38 * 39 * Written by Bill Paul <wpaul@ee.columbia.edu> 40 * Electrical Engineering Department 41 * Columbia University, New York City 42 */ --- 17 unchanged lines hidden (view full) --- 60 * powered on and retain its firmware. In this case, we don't need 61 * to load the firmware a second time. 62 * 63 * Special thanks to Rob Furr for providing an ADS Technologies 64 * adapter for development and testing. No monkeys were harmed during 65 * the development of this driver. 66 */ 67 | 35 36/* 37 * Kawasaki LSI KL5KUSB101B USB to ethernet adapter driver. 38 * 39 * Written by Bill Paul <wpaul@ee.columbia.edu> 40 * Electrical Engineering Department 41 * Columbia University, New York City 42 */ --- 17 unchanged lines hidden (view full) --- 60 * powered on and retain its firmware. In this case, we don't need 61 * to load the firmware a second time. 62 * 63 * Special thanks to Rob Furr for providing an ADS Technologies 64 * adapter for development and testing. No monkeys were harmed during 65 * the development of this driver. 66 */ 67 |
68/* 69 * NOTE: all function names beginning like "kue_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 kue_softc 80 | |
81#define USB_DEBUG_VAR kue_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 kue_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_kuereg.h> 94#include <dev/usb2/ethernet/if_kuefw.h> --- 40 unchanged lines hidden (view full) --- 135 136/* prototypes */ 137 138static device_probe_t kue_probe; 139static device_attach_t kue_attach; 140static device_detach_t kue_detach; 141static device_shutdown_t kue_shutdown; 142 | 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_kuereg.h> 85#include <dev/usb2/ethernet/if_kuefw.h> --- 40 unchanged lines hidden (view full) --- 126 127/* prototypes */ 128 129static device_probe_t kue_probe; 130static device_attach_t kue_attach; 131static device_detach_t kue_detach; 132static device_shutdown_t kue_shutdown; 133 |
143static usb2_callback_t kue_bulk_read_clear_stall_callback; | |
144static usb2_callback_t kue_bulk_read_callback; | 134static usb2_callback_t kue_bulk_read_callback; |
145static usb2_callback_t kue_bulk_write_clear_stall_callback; | |
146static usb2_callback_t kue_bulk_write_callback; 147 | 135static usb2_callback_t kue_bulk_write_callback; 136 |
148static usb2_config_td_command_t kue_cfg_promisc_upd; 149static usb2_config_td_command_t kue_config_copy; 150static usb2_config_td_command_t kue_cfg_first_time_setup; 151static usb2_config_td_command_t kue_cfg_pre_init; 152static usb2_config_td_command_t kue_cfg_init; 153static usb2_config_td_command_t kue_cfg_tick; 154static usb2_config_td_command_t kue_cfg_pre_stop; 155static usb2_config_td_command_t kue_cfg_stop; | 137static usb2_ether_fn_t kue_attach_post; 138static usb2_ether_fn_t kue_init; 139static usb2_ether_fn_t kue_stop; 140static usb2_ether_fn_t kue_start; 141static usb2_ether_fn_t kue_setmulti; 142static usb2_ether_fn_t kue_setpromisc; |
156 | 143 |
157static void kue_cfg_do_request(struct kue_softc *, | 144static int kue_do_request(struct kue_softc *, |
158 struct usb2_device_request *, void *); | 145 struct usb2_device_request *, void *); |
159static void kue_cfg_setword(struct kue_softc *, uint8_t, uint16_t); 160static void kue_cfg_ctl(struct kue_softc *, uint8_t, uint8_t, uint16_t, 161 void *, uint16_t); 162static void kue_cfg_load_fw(struct kue_softc *); 163static void kue_cfg_reset(struct kue_softc *); 164static void kue_start_cb(struct ifnet *); 165static void kue_start_transfers(struct kue_softc *); 166static void kue_init_cb(void *); 167static int kue_ioctl_cb(struct ifnet *, u_long, caddr_t); 168static void kue_watchdog(void *); | 146static int kue_setword(struct kue_softc *, uint8_t, uint16_t); 147static int kue_ctl(struct kue_softc *, uint8_t, uint8_t, uint16_t, 148 void *, int); 149static int kue_load_fw(struct kue_softc *); 150static void kue_reset(struct kue_softc *); |
169 170#if USB_DEBUG 171static int kue_debug = 0; 172 173SYSCTL_NODE(_hw_usb2, OID_AUTO, kue, CTLFLAG_RW, 0, "USB kue"); 174SYSCTL_INT(_hw_usb2_kue, OID_AUTO, debug, CTLFLAG_RW, &kue_debug, 0, 175 "Debug level"); 176#endif 177 178static const struct usb2_config kue_config[KUE_N_TRANSFER] = { 179 180 [KUE_BULK_DT_WR] = { 181 .type = UE_BULK, 182 .endpoint = UE_ADDR_ANY, 183 .direction = UE_DIR_OUT, 184 .mh.bufsize = (MCLBYTES + 2 + 64), 185 .mh.flags = {.pipe_bof = 1,}, | 151 152#if USB_DEBUG 153static int kue_debug = 0; 154 155SYSCTL_NODE(_hw_usb2, OID_AUTO, kue, CTLFLAG_RW, 0, "USB kue"); 156SYSCTL_INT(_hw_usb2_kue, OID_AUTO, debug, CTLFLAG_RW, &kue_debug, 0, 157 "Debug level"); 158#endif 159 160static const struct usb2_config kue_config[KUE_N_TRANSFER] = { 161 162 [KUE_BULK_DT_WR] = { 163 .type = UE_BULK, 164 .endpoint = UE_ADDR_ANY, 165 .direction = UE_DIR_OUT, 166 .mh.bufsize = (MCLBYTES + 2 + 64), 167 .mh.flags = {.pipe_bof = 1,}, |
186 .mh.callback = &kue_bulk_write_callback, | 168 .mh.callback = kue_bulk_write_callback, |
187 .mh.timeout = 10000, /* 10 seconds */ 188 }, 189 190 [KUE_BULK_DT_RD] = { 191 .type = UE_BULK, 192 .endpoint = UE_ADDR_ANY, 193 .direction = UE_DIR_IN, 194 .mh.bufsize = (MCLBYTES + 2), 195 .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, | 169 .mh.timeout = 10000, /* 10 seconds */ 170 }, 171 172 [KUE_BULK_DT_RD] = { 173 .type = UE_BULK, 174 .endpoint = UE_ADDR_ANY, 175 .direction = UE_DIR_IN, 176 .mh.bufsize = (MCLBYTES + 2), 177 .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, |
196 .mh.callback = &kue_bulk_read_callback, | 178 .mh.callback = kue_bulk_read_callback, |
197 .mh.timeout = 0, /* no timeout */ 198 }, | 179 .mh.timeout = 0, /* no timeout */ 180 }, |
199 200 [KUE_BULK_CS_WR] = { 201 .type = UE_CONTROL, 202 .endpoint = 0x00, /* Control pipe */ 203 .direction = UE_DIR_ANY, 204 .mh.bufsize = sizeof(struct usb2_device_request), 205 .mh.flags = {}, 206 .mh.callback = &kue_bulk_write_clear_stall_callback, 207 .mh.timeout = 1000, /* 1 second */ 208 .mh.interval = 50, /* 50ms */ 209 }, 210 211 [KUE_BULK_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 = &kue_bulk_read_clear_stall_callback, 218 .mh.timeout = 1000, /* 1 second */ 219 .mh.interval = 50, /* 50ms */ 220 }, | |
221}; 222 223static device_method_t kue_methods[] = { 224 /* Device interface */ 225 DEVMETHOD(device_probe, kue_probe), 226 DEVMETHOD(device_attach, kue_attach), 227 DEVMETHOD(device_detach, kue_detach), 228 DEVMETHOD(device_shutdown, kue_shutdown), --- 9 unchanged lines hidden (view full) --- 238 239static devclass_t kue_devclass; 240 241DRIVER_MODULE(kue, ushub, kue_driver, kue_devclass, NULL, 0); 242MODULE_DEPEND(kue, usb2_ethernet, 1, 1, 1); 243MODULE_DEPEND(kue, usb2_core, 1, 1, 1); 244MODULE_DEPEND(kue, ether, 1, 1, 1); 245 | 181}; 182 183static device_method_t kue_methods[] = { 184 /* Device interface */ 185 DEVMETHOD(device_probe, kue_probe), 186 DEVMETHOD(device_attach, kue_attach), 187 DEVMETHOD(device_detach, kue_detach), 188 DEVMETHOD(device_shutdown, kue_shutdown), --- 9 unchanged lines hidden (view full) --- 198 199static devclass_t kue_devclass; 200 201DRIVER_MODULE(kue, ushub, kue_driver, kue_devclass, NULL, 0); 202MODULE_DEPEND(kue, usb2_ethernet, 1, 1, 1); 203MODULE_DEPEND(kue, usb2_core, 1, 1, 1); 204MODULE_DEPEND(kue, ether, 1, 1, 1); 205 |
206static const struct usb2_ether_methods kue_ue_methods = { 207 .ue_attach_post = kue_attach_post, 208 .ue_start = kue_start, 209 .ue_init = kue_init, 210 .ue_stop = kue_stop, 211 .ue_setmulti = kue_setmulti, 212 .ue_setpromisc = kue_setpromisc, 213}; 214 |
|
246/* 247 * We have a custom do_request function which is almost like the 248 * regular do_request function, except it has a much longer timeout. 249 * Why? Because we need to make requests over the control endpoint 250 * to download the firmware to the device, which can take longer 251 * than the default timeout. 252 */ | 215/* 216 * We have a custom do_request function which is almost like the 217 * regular do_request function, except it has a much longer timeout. 218 * Why? Because we need to make requests over the control endpoint 219 * to download the firmware to the device, which can take longer 220 * than the default timeout. 221 */ |
253static void 254kue_cfg_do_request(struct kue_softc *sc, struct usb2_device_request *req, | 222static int 223kue_do_request(struct kue_softc *sc, struct usb2_device_request *req, |
255 void *data) 256{ | 224 void *data) 225{ |
257 uint16_t length; | |
258 usb2_error_t err; 259 | 226 usb2_error_t err; 227 |
260 if (usb2_config_td_is_gone(&sc->sc_config_td)) { 261 goto error; 262 } 263 err = usb2_do_request_flags 264 (sc->sc_udev, &sc->sc_mtx, req, data, 0, NULL, 60000); | 228 err = usb2_ether_do_request(&sc->sc_ue, req, data, 60000); |
265 | 229 |
266 if (err) { 267 DPRINTF("device request failed, err=%s " 268 "(ignored)\n", usb2_errstr(err)); 269 270error: 271 length = UGETW(req->wLength); 272 273 if ((req->bmRequestType & UT_READ) && length) { 274 bzero(data, length); 275 } 276 } | 230 return (err); |
277} 278 | 231} 232 |
279static void 280kue_cfg_setword(struct kue_softc *sc, uint8_t breq, uint16_t word) | 233static int 234kue_setword(struct kue_softc *sc, uint8_t breq, uint16_t word) |
281{ 282 struct usb2_device_request req; 283 284 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 285 req.bRequest = breq; 286 USETW(req.wValue, word); 287 USETW(req.wIndex, 0); 288 USETW(req.wLength, 0); 289 | 235{ 236 struct usb2_device_request req; 237 238 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 239 req.bRequest = breq; 240 USETW(req.wValue, word); 241 USETW(req.wIndex, 0); 242 USETW(req.wLength, 0); 243 |
290 kue_cfg_do_request(sc, &req, NULL); | 244 return (kue_do_request(sc, &req, NULL)); |
291} 292 | 245} 246 |
293static void 294kue_cfg_ctl(struct kue_softc *sc, uint8_t rw, uint8_t breq, 295 uint16_t val, void *data, uint16_t len) | 247static int 248kue_ctl(struct kue_softc *sc, uint8_t rw, uint8_t breq, 249 uint16_t val, void *data, int len) |
296{ 297 struct usb2_device_request req; 298 | 250{ 251 struct usb2_device_request req; 252 |
299 if (rw == KUE_CTL_WRITE) { | 253 if (rw == KUE_CTL_WRITE) |
300 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; | 254 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; |
301 } else { | 255 else |
302 req.bmRequestType = UT_READ_VENDOR_DEVICE; | 256 req.bmRequestType = UT_READ_VENDOR_DEVICE; |
303 } | |
304 | 257 |
258 |
|
305 req.bRequest = breq; 306 USETW(req.wValue, val); 307 USETW(req.wIndex, 0); 308 USETW(req.wLength, len); 309 | 259 req.bRequest = breq; 260 USETW(req.wValue, val); 261 USETW(req.wIndex, 0); 262 USETW(req.wLength, len); 263 |
310 kue_cfg_do_request(sc, &req, data); | 264 return (kue_do_request(sc, &req, data)); |
311} 312 | 265} 266 |
313static void 314kue_cfg_load_fw(struct kue_softc *sc) | 267static int 268kue_load_fw(struct kue_softc *sc) |
315{ 316 struct usb2_device_descriptor *dd; 317 uint16_t hwrev; | 269{ 270 struct usb2_device_descriptor *dd; 271 uint16_t hwrev; |
272 usb2_error_t err; |
|
318 | 273 |
319 dd = usb2_get_device_descriptor(sc->sc_udev); | 274 dd = usb2_get_device_descriptor(sc->sc_ue.ue_udev); |
320 hwrev = UGETW(dd->bcdDevice); 321 322 /* 323 * First, check if we even need to load the firmware. 324 * If the device was still attached when the system was 325 * rebooted, it may already have firmware loaded in it. 326 * If this is the case, we don't need to do it again. 327 * And in fact, if we try to load it again, we'll hang, 328 * so we have to avoid this condition if we don't want 329 * to look stupid. 330 * 331 * We can test this quickly by checking the bcdRevision 332 * code. The NIC will return a different revision code if 333 * it's probed while the firmware is still loaded and 334 * running. 335 */ | 275 hwrev = UGETW(dd->bcdDevice); 276 277 /* 278 * First, check if we even need to load the firmware. 279 * If the device was still attached when the system was 280 * rebooted, it may already have firmware loaded in it. 281 * If this is the case, we don't need to do it again. 282 * And in fact, if we try to load it again, we'll hang, 283 * so we have to avoid this condition if we don't want 284 * to look stupid. 285 * 286 * We can test this quickly by checking the bcdRevision 287 * code. The NIC will return a different revision code if 288 * it's probed while the firmware is still loaded and 289 * running. 290 */ |
336 if (hwrev == 0x0202) { 337 return; 338 } 339 /* load code segment */ 340 kue_cfg_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SEND_SCAN, | 291 if (hwrev == 0x0202) 292 return(0); 293 294 /* Load code segment */ 295 err = kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SEND_SCAN, |
341 0, kue_code_seg, sizeof(kue_code_seg)); | 296 0, kue_code_seg, sizeof(kue_code_seg)); |
297 if (err) { 298 device_printf(sc->sc_ue.ue_dev, "failed to load code segment: %s\n", 299 usb2_errstr(err)); 300 return(ENXIO); 301 } |
|
342 | 302 |
343 /* load fixup segment */ 344 kue_cfg_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SEND_SCAN, | 303 /* Load fixup segment */ 304 err = kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SEND_SCAN, |
345 0, kue_fix_seg, sizeof(kue_fix_seg)); | 305 0, kue_fix_seg, sizeof(kue_fix_seg)); |
306 if (err) { 307 device_printf(sc->sc_ue.ue_dev, "failed to load fixup segment: %s\n", 308 usb2_errstr(err)); 309 return(ENXIO); 310 } |
|
346 | 311 |
347 /* send trigger command */ 348 kue_cfg_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SEND_SCAN, | 312 /* Send trigger command. */ 313 err = kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SEND_SCAN, |
349 0, kue_trig_seg, sizeof(kue_trig_seg)); | 314 0, kue_trig_seg, sizeof(kue_trig_seg)); |
315 if (err) { 316 device_printf(sc->sc_ue.ue_dev, "failed to load trigger segment: %s\n", 317 usb2_errstr(err)); 318 return(ENXIO); 319 } 320 321 return (0); |
|
350} 351 352static void | 322} 323 324static void |
353kue_cfg_promisc_upd(struct kue_softc *sc, 354 struct usb2_config_td_cc *cc, uint16_t refcount) | 325kue_setpromisc(struct usb2_ether *ue) |
355{ | 326{ |
356 kue_cfg_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SET_MCAST_FILTERS, 357 cc->if_nhash, cc->if_hash, cc->if_nhash * ETHER_ADDR_LEN); | 327 struct kue_softc *sc = usb2_ether_getsc(ue); 328 struct ifnet *ifp = usb2_ether_getifp(ue); |
358 | 329 |
359 kue_cfg_setword(sc, KUE_CMD_SET_PKT_FILTER, cc->if_rxfilt); | 330 KUE_LOCK_ASSERT(sc, MA_OWNED); 331 332 if (ifp->if_flags & IFF_PROMISC) 333 sc->sc_rxfilt |= KUE_RXFILT_PROMISC; 334 else 335 sc->sc_rxfilt &= ~KUE_RXFILT_PROMISC; 336 337 kue_setword(sc, KUE_CMD_SET_PKT_FILTER, sc->sc_rxfilt); |
360} 361 362static void | 338} 339 340static void |
363kue_mchash(struct usb2_config_td_cc *cc, const uint8_t *ptr) | 341kue_setmulti(struct usb2_ether *ue) |
364{ | 342{ |
365 uint8_t i; | 343 struct kue_softc *sc = usb2_ether_getsc(ue); 344 struct ifnet *ifp = usb2_ether_getifp(ue); 345 struct ifmultiaddr *ifma; 346 int i = 0; |
366 | 347 |
367 i = cc->if_nhash; | 348 KUE_LOCK_ASSERT(sc, MA_OWNED); |
368 | 349 |
369 /* 370 * If there are too many addresses for the internal filter, 371 * switch over to allmulti mode. 372 */ 373 if (i == cc->if_mhash) { 374 cc->if_rxfilt |= KUE_RXFILT_ALLMULTI; 375 } else { 376 bcopy(ptr, cc->if_hash + (i * ETHER_ADDR_LEN), ETHER_ADDR_LEN); 377 cc->if_nhash++; | 350 if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) { 351 sc->sc_rxfilt |= KUE_RXFILT_ALLMULTI; 352 sc->sc_rxfilt &= ~KUE_RXFILT_MULTICAST; 353 kue_setword(sc, KUE_CMD_SET_PKT_FILTER, sc->sc_rxfilt); 354 return; |
378 } | 355 } |
379} | |
380 | 356 |
381static void 382kue_config_copy(struct kue_softc *sc, 383 struct usb2_config_td_cc *cc, uint16_t refcount) 384{ 385 bzero(cc, sizeof(*cc)); | 357 sc->sc_rxfilt &= ~KUE_RXFILT_ALLMULTI; |
386 | 358 |
387 cc->if_mhash = sc->sc_mcfilt_max; 388 cc->if_rxfilt = (KUE_RXFILT_UNICAST | KUE_RXFILT_BROADCAST); | 359 IF_ADDR_LOCK(ifp); 360 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) 361 { 362 if (ifma->ifma_addr->sa_family != AF_LINK) 363 continue; 364 /* 365 * If there are too many addresses for the 366 * internal filter, switch over to allmulti mode. 367 */ 368 if (i == KUE_MCFILTCNT(sc)) 369 break; 370 bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr), 371 KUE_MCFILT(sc, i), ETHER_ADDR_LEN); 372 i++; 373 } 374 IF_ADDR_UNLOCK(ifp); |
389 | 375 |
390 usb2_ether_cc(sc->sc_ifp, &kue_mchash, cc); 391 392 /* 393 * If we want promiscuous mode, set the all-frames bit: 394 */ 395 if (cc->if_flags & IFF_PROMISC) { 396 cc->if_rxfilt |= KUE_RXFILT_PROMISC; | 376 if (i == KUE_MCFILTCNT(sc)) 377 sc->sc_rxfilt |= KUE_RXFILT_ALLMULTI; 378 else { 379 sc->sc_rxfilt |= KUE_RXFILT_MULTICAST; 380 kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SET_MCAST_FILTERS, 381 i, sc->sc_mcfilters, i * ETHER_ADDR_LEN); |
397 } | 382 } |
398 if ((cc->if_flags & IFF_ALLMULTI) || 399 (cc->if_flags & IFF_PROMISC)) { 400 cc->if_rxfilt |= KUE_RXFILT_ALLMULTI; 401 } else if (cc->if_nhash) { 402 cc->if_rxfilt |= KUE_RXFILT_MULTICAST; 403 } | 383 384 kue_setword(sc, KUE_CMD_SET_PKT_FILTER, sc->sc_rxfilt); |
404} 405 406/* 407 * Issue a SET_CONFIGURATION command to reset the MAC. This should be 408 * done after the firmware is loaded into the adapter in order to 409 * bring it into proper operation. 410 */ 411static void | 385} 386 387/* 388 * Issue a SET_CONFIGURATION command to reset the MAC. This should be 389 * done after the firmware is loaded into the adapter in order to 390 * bring it into proper operation. 391 */ 392static void |
412kue_cfg_reset(struct kue_softc *sc) | 393kue_reset(struct kue_softc *sc) |
413{ 414 struct usb2_config_descriptor *cd; 415 usb2_error_t err; 416 | 394{ 395 struct usb2_config_descriptor *cd; 396 usb2_error_t err; 397 |
417 cd = usb2_get_config_descriptor(sc->sc_udev); | 398 cd = usb2_get_config_descriptor(sc->sc_ue.ue_udev); |
418 | 399 |
419 err = usb2_req_set_config(sc->sc_udev, &sc->sc_mtx, | 400 err = usb2_req_set_config(sc->sc_ue.ue_udev, &sc->sc_mtx, |
420 cd->bConfigurationValue); | 401 cd->bConfigurationValue); |
421 if (err) { | 402 if (err) |
422 DPRINTF("reset failed (ignored)\n"); | 403 DPRINTF("reset failed (ignored)\n"); |
404 405 /* wait a little while for the chip to get its brains in order */ 406 usb2_ether_pause(&sc->sc_ue, hz / 100); 407} 408 409static void 410kue_attach_post(struct usb2_ether *ue) 411{ 412 struct kue_softc *sc = usb2_ether_getsc(ue); 413 int error; 414 415 /* load the firmware into the NIC */ 416 error = kue_load_fw(sc); 417 if (error) { 418 device_printf(sc->sc_ue.ue_dev, "could not load firmware\n"); 419 /* ignore the error */ |
|
423 } | 420 } |
424 /* 425 * wait a little while for the chip to get its brains in order: 426 */ 427 err = usb2_config_td_sleep(&sc->sc_config_td, hz / 100); | 421 422 /* reset the adapter */ 423 kue_reset(sc); 424 425 /* read ethernet descriptor */ 426 kue_ctl(sc, KUE_CTL_READ, KUE_CMD_GET_ETHER_DESCRIPTOR, 427 0, &sc->sc_desc, sizeof(sc->sc_desc)); 428 429 /* copy in ethernet address */ 430 memcpy(ue->ue_eaddr, sc->sc_desc.kue_macaddr, sizeof(ue->ue_eaddr)); |
428} 429 430/* 431 * Probe for a KLSI chip. 432 */ 433static int 434kue_probe(device_t dev) 435{ 436 struct usb2_attach_arg *uaa = device_get_ivars(dev); 437 | 431} 432 433/* 434 * Probe for a KLSI chip. 435 */ 436static int 437kue_probe(device_t dev) 438{ 439 struct usb2_attach_arg *uaa = device_get_ivars(dev); 440 |
438 if (uaa->usb2_mode != USB_MODE_HOST) { | 441 if (uaa->usb2_mode != USB_MODE_HOST) |
439 return (ENXIO); | 442 return (ENXIO); |
440 } 441 if (uaa->info.bConfigIndex != KUE_CONFIG_IDX) { | 443 if (uaa->info.bConfigIndex != KUE_CONFIG_IDX) |
442 return (ENXIO); | 444 return (ENXIO); |
443 } 444 if (uaa->info.bIfaceIndex != KUE_IFACE_IDX) { | 445 if (uaa->info.bIfaceIndex != KUE_IFACE_IDX) |
445 return (ENXIO); | 446 return (ENXIO); |
446 } | 447 |
447 return (usb2_lookup_id_by_uaa(kue_devs, sizeof(kue_devs), uaa)); 448} 449 450/* 451 * Attach the interface. Allocate softc structures, do 452 * setup and ethernet/BPF attach. 453 */ 454static int 455kue_attach(device_t dev) 456{ 457 struct usb2_attach_arg *uaa = device_get_ivars(dev); 458 struct kue_softc *sc = device_get_softc(dev); | 448 return (usb2_lookup_id_by_uaa(kue_devs, sizeof(kue_devs), uaa)); 449} 450 451/* 452 * Attach the interface. Allocate softc structures, do 453 * setup and ethernet/BPF attach. 454 */ 455static int 456kue_attach(device_t dev) 457{ 458 struct usb2_attach_arg *uaa = device_get_ivars(dev); 459 struct kue_softc *sc = device_get_softc(dev); |
459 int32_t error; | 460 struct usb2_ether *ue = &sc->sc_ue; |
460 uint8_t iface_index; | 461 uint8_t iface_index; |
462 int error; |
|
461 | 463 |
462 sc->sc_udev = uaa->device; 463 sc->sc_dev = dev; 464 sc->sc_unit = device_get_unit(dev); 465 | |
466 device_set_usb2_desc(dev); | 464 device_set_usb2_desc(dev); |
465 mtx_init(&sc->sc_mtx, device_get_nameunit(dev), NULL, MTX_DEF); |
|
467 | 466 |
468 mtx_init(&sc->sc_mtx, "kue lock", NULL, MTX_DEF | MTX_RECURSE); 469 470 usb2_callout_init_mtx(&sc->sc_watchdog, &sc->sc_mtx, 0); 471 | |
472 iface_index = KUE_IFACE_IDX; 473 error = usb2_transfer_setup(uaa->device, &iface_index, 474 sc->sc_xfer, kue_config, KUE_N_TRANSFER, sc, &sc->sc_mtx); 475 if (error) { | 467 iface_index = KUE_IFACE_IDX; 468 error = usb2_transfer_setup(uaa->device, &iface_index, 469 sc->sc_xfer, kue_config, KUE_N_TRANSFER, sc, &sc->sc_mtx); 470 if (error) { |
476 device_printf(dev, "allocating USB " 477 "transfers failed!\n"); | 471 device_printf(dev, "allocating USB transfers failed!\n"); |
478 goto detach; 479 } | 472 goto detach; 473 } |
480 error = usb2_config_td_setup(&sc->sc_config_td, sc, &sc->sc_mtx, 481 NULL, sizeof(struct usb2_config_td_cc), 16); 482 if (error) { 483 device_printf(dev, "could not setup config " 484 "thread!\n"); | 474 475 sc->sc_mcfilters = malloc(KUE_MCFILTCNT(sc) * ETHER_ADDR_LEN, 476 M_USBDEV, M_WAITOK); 477 if (sc->sc_mcfilters == NULL) { 478 device_printf(dev, "failed allocating USB memory!\n"); |
485 goto detach; 486 } | 479 goto detach; 480 } |
487 mtx_lock(&sc->sc_mtx); | |
488 | 481 |
489 /* start setup */ | 482 ue->ue_sc = sc; 483 ue->ue_dev = dev; 484 ue->ue_udev = uaa->device; 485 ue->ue_mtx = &sc->sc_mtx; 486 ue->ue_methods = &kue_ue_methods; |
490 | 487 |
491 usb2_config_td_queue_command 492 (&sc->sc_config_td, NULL, &kue_cfg_first_time_setup, 0, 0); 493 494 kue_watchdog(sc); 495 mtx_unlock(&sc->sc_mtx); | 488 error = usb2_ether_ifattach(ue); 489 if (error) { 490 device_printf(dev, "could not attach interface\n"); 491 goto detach; 492 } |
496 return (0); /* success */ 497 498detach: 499 kue_detach(dev); 500 return (ENXIO); /* failure */ 501} 502 | 493 return (0); /* success */ 494 495detach: 496 kue_detach(dev); 497 return (ENXIO); /* failure */ 498} 499 |
503static void 504kue_cfg_first_time_setup(struct kue_softc *sc, 505 struct usb2_config_td_cc *cc, uint16_t refcount) 506{ 507 struct ifnet *ifp; 508 509 /* load the firmware into the NIC */ 510 511 kue_cfg_load_fw(sc); 512 513 /* reset the adapter */ 514 515 kue_cfg_reset(sc); 516 517 /* read ethernet descriptor */ 518 kue_cfg_ctl(sc, KUE_CTL_READ, KUE_CMD_GET_ETHER_DESCRIPTOR, 519 0, &sc->sc_desc, sizeof(sc->sc_desc)); 520 521 sc->sc_mcfilt_max = KUE_MCFILTCNT(sc); 522 if (sc->sc_mcfilt_max > KUE_MCFILT_MAX) { 523 sc->sc_mcfilt_max = KUE_MCFILT_MAX; 524 } 525 mtx_unlock(&sc->sc_mtx); 526 527 ifp = if_alloc(IFT_ETHER); 528 529 mtx_lock(&sc->sc_mtx); 530 531 if (ifp == NULL) { 532 printf("kue%d: could not if_alloc()\n", 533 sc->sc_unit); 534 goto done; 535 } 536 537 ifp->if_softc = sc; 538 if_initname(ifp, "kue", sc->sc_unit); 539 ifp->if_mtu = ETHERMTU; 540 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; 541 ifp->if_ioctl = kue_ioctl_cb; 542 ifp->if_start = kue_start_cb; 543 ifp->if_watchdog = NULL; 544 ifp->if_init = kue_init_cb; 545 ifp->if_baudrate = 10000000; 546 IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN); 547 ifp->if_snd.ifq_drv_maxlen = IFQ_MAXLEN; 548 IFQ_SET_READY(&ifp->if_snd); 549 550 sc->sc_ifp = ifp; 551 552 mtx_unlock(&sc->sc_mtx); 553 554 ether_ifattach(ifp, sc->sc_desc.kue_macaddr); 555 556 mtx_lock(&sc->sc_mtx); 557done: 558 return; 559} 560 | |
561static int 562kue_detach(device_t dev) 563{ 564 struct kue_softc *sc = device_get_softc(dev); | 500static int 501kue_detach(device_t dev) 502{ 503 struct kue_softc *sc = device_get_softc(dev); |
565 struct ifnet *ifp; | 504 struct usb2_ether *ue = &sc->sc_ue; |
566 | 505 |
567 usb2_config_td_drain(&sc->sc_config_td); 568 569 mtx_lock(&sc->sc_mtx); 570 571 usb2_callout_stop(&sc->sc_watchdog); 572 573 kue_cfg_pre_stop(sc, NULL, 0); 574 575 ifp = sc->sc_ifp; 576 577 mtx_unlock(&sc->sc_mtx); 578 579 /* stop all USB transfers first */ | |
580 usb2_transfer_unsetup(sc->sc_xfer, KUE_N_TRANSFER); | 506 usb2_transfer_unsetup(sc->sc_xfer, KUE_N_TRANSFER); |
581 582 /* get rid of any late children */ 583 bus_generic_detach(dev); 584 585 if (ifp) { 586 ether_ifdetach(ifp); 587 if_free(ifp); 588 } 589 usb2_config_td_unsetup(&sc->sc_config_td); 590 591 usb2_callout_drain(&sc->sc_watchdog); 592 | 507 usb2_ether_ifdetach(ue); |
593 mtx_destroy(&sc->sc_mtx); | 508 mtx_destroy(&sc->sc_mtx); |
509 free(sc->sc_mcfilters, M_USBDEV); |
|
594 595 return (0); 596} 597 598/* 599 * A frame has been uploaded: pass the resulting mbuf chain up to 600 * the higher level protocols. 601 */ 602static void | 510 511 return (0); 512} 513 514/* 515 * A frame has been uploaded: pass the resulting mbuf chain up to 516 * the higher level protocols. 517 */ 518static void |
603kue_bulk_read_clear_stall_callback(struct usb2_xfer *xfer) 604{ 605 struct kue_softc *sc = xfer->priv_sc; 606 struct usb2_xfer *xfer_other = sc->sc_xfer[KUE_BULK_DT_RD]; 607 608 if (usb2_clear_stall_callback(xfer, xfer_other)) { 609 DPRINTF("stall cleared\n"); 610 sc->sc_flags &= ~KUE_FLAG_READ_STALL; 611 usb2_transfer_start(xfer_other); 612 } 613} 614 615static void | |
616kue_bulk_read_callback(struct usb2_xfer *xfer) 617{ 618 struct kue_softc *sc = xfer->priv_sc; | 519kue_bulk_read_callback(struct usb2_xfer *xfer) 520{ 521 struct kue_softc *sc = xfer->priv_sc; |
619 struct ifnet *ifp = sc->sc_ifp; 620 struct mbuf *m = NULL; | 522 struct usb2_ether *ue = &sc->sc_ue; 523 struct ifnet *ifp = usb2_ether_getifp(ue); |
621 uint8_t buf[2]; | 524 uint8_t buf[2]; |
622 uint16_t len; | 525 int len; |
623 624 switch (USB_GET_STATE(xfer)) { 625 case USB_ST_TRANSFERRED: 626 627 if (xfer->actlen <= (2 + sizeof(struct ether_header))) { 628 ifp->if_ierrors++; 629 goto tr_setup; 630 } 631 usb2_copy_out(xfer->frbuffers, 0, buf, 2); | 526 527 switch (USB_GET_STATE(xfer)) { 528 case USB_ST_TRANSFERRED: 529 530 if (xfer->actlen <= (2 + sizeof(struct ether_header))) { 531 ifp->if_ierrors++; 532 goto tr_setup; 533 } 534 usb2_copy_out(xfer->frbuffers, 0, buf, 2); |
632 | 535 xfer->actlen -= 2; |
633 len = buf[0] | (buf[1] << 8); | 536 len = buf[0] | (buf[1] << 8); |
537 len = min(xfer->actlen, len); |
|
634 | 538 |
635 xfer->actlen -= 2; 636 637 m = usb2_ether_get_mbuf(); 638 639 if (m == NULL) { 640 ifp->if_ierrors++; 641 goto tr_setup; 642 } 643 xfer->actlen = min(xfer->actlen, m->m_len); 644 xfer->actlen = min(xfer->actlen, len); 645 646 usb2_copy_out(xfer->frbuffers, 2, m->m_data, xfer->actlen); 647 648 ifp->if_ipackets++; 649 m->m_pkthdr.rcvif = ifp; 650 m->m_pkthdr.len = m->m_len = xfer->actlen; 651 | 539 usb2_ether_rxbuf(ue, xfer->frbuffers, 2, len); 540 /* FALLTHROUGH */ |
652 case USB_ST_SETUP: 653tr_setup: | 541 case USB_ST_SETUP: 542tr_setup: |
654 655 if (sc->sc_flags & KUE_FLAG_READ_STALL) { 656 usb2_transfer_start(sc->sc_xfer[KUE_BULK_CS_RD]); 657 } else { 658 xfer->frlengths[0] = xfer->max_data_length; 659 usb2_start_hardware(xfer); 660 } 661 662 /* 663 * At the end of a USB callback it is always safe to unlock 664 * the private mutex of a device! That is why we do the 665 * "if_input" here, and not some lines up! 666 */ 667 if (m) { 668 mtx_unlock(&sc->sc_mtx); 669 (ifp->if_input) (ifp, m); 670 mtx_lock(&sc->sc_mtx); 671 } | 543 xfer->frlengths[0] = xfer->max_data_length; 544 usb2_start_hardware(xfer); 545 usb2_ether_rxflush(ue); |
672 return; 673 674 default: /* Error */ | 546 return; 547 548 default: /* Error */ |
549 DPRINTF("bulk read error, %s\n", 550 usb2_errstr(xfer->error)); 551 |
|
675 if (xfer->error != USB_ERR_CANCELLED) { 676 /* try to clear stall first */ | 552 if (xfer->error != USB_ERR_CANCELLED) { 553 /* try to clear stall first */ |
677 sc->sc_flags |= KUE_FLAG_READ_STALL; 678 usb2_transfer_start(sc->sc_xfer[KUE_BULK_CS_RD]); | 554 xfer->flags.stall_pipe = 1; 555 goto tr_setup; |
679 } | 556 } |
680 DPRINTF("bulk read error, %s\n", 681 usb2_errstr(xfer->error)); | |
682 return; 683 684 } 685} 686 687static void | 557 return; 558 559 } 560} 561 562static void |
688kue_bulk_write_clear_stall_callback(struct usb2_xfer *xfer) 689{ 690 struct kue_softc *sc = xfer->priv_sc; 691 struct usb2_xfer *xfer_other = sc->sc_xfer[KUE_BULK_DT_WR]; 692 693 if (usb2_clear_stall_callback(xfer, xfer_other)) { 694 DPRINTF("stall cleared\n"); 695 sc->sc_flags &= ~KUE_FLAG_WRITE_STALL; 696 usb2_transfer_start(xfer_other); 697 } 698} 699 700static void | |
701kue_bulk_write_callback(struct usb2_xfer *xfer) 702{ 703 struct kue_softc *sc = xfer->priv_sc; | 563kue_bulk_write_callback(struct usb2_xfer *xfer) 564{ 565 struct kue_softc *sc = xfer->priv_sc; |
704 struct ifnet *ifp = sc->sc_ifp; | 566 struct ifnet *ifp = usb2_ether_getifp(&sc->sc_ue); |
705 struct mbuf *m; | 567 struct mbuf *m; |
706 uint32_t total_len; 707 uint32_t temp_len; | 568 int total_len; 569 int temp_len; |
708 uint8_t buf[2]; 709 710 switch (USB_GET_STATE(xfer)) { 711 case USB_ST_TRANSFERRED: 712 DPRINTFN(11, "transfer complete\n"); | 570 uint8_t buf[2]; 571 572 switch (USB_GET_STATE(xfer)) { 573 case USB_ST_TRANSFERRED: 574 DPRINTFN(11, "transfer complete\n"); |
713 | |
714 ifp->if_opackets++; 715 | 575 ifp->if_opackets++; 576 |
577 /* FALLTHROUGH */ |
|
716 case USB_ST_SETUP: | 578 case USB_ST_SETUP: |
717 718 if (sc->sc_flags & KUE_FLAG_WRITE_STALL) { 719 usb2_transfer_start(sc->sc_xfer[KUE_BULK_CS_WR]); 720 goto done; 721 } | 579tr_setup: |
722 IFQ_DRV_DEQUEUE(&ifp->if_snd, m); 723 | 580 IFQ_DRV_DEQUEUE(&ifp->if_snd, m); 581 |
724 if (m == NULL) { 725 goto done; 726 } 727 if (m->m_pkthdr.len > MCLBYTES) { | 582 if (m == NULL) 583 return; 584 if (m->m_pkthdr.len > MCLBYTES) |
728 m->m_pkthdr.len = MCLBYTES; | 585 m->m_pkthdr.len = MCLBYTES; |
729 } | |
730 temp_len = (m->m_pkthdr.len + 2); 731 total_len = (temp_len + (64 - (temp_len % 64))); 732 733 /* the first two bytes are the frame length */ 734 735 buf[0] = (uint8_t)(m->m_pkthdr.len); 736 buf[1] = (uint8_t)(m->m_pkthdr.len >> 8); 737 --- 12 unchanged lines hidden (view full) --- 750 * of this frame to him: 751 */ 752 BPF_MTAP(ifp, m); 753 754 m_freem(m); 755 756 usb2_start_hardware(xfer); 757 | 586 temp_len = (m->m_pkthdr.len + 2); 587 total_len = (temp_len + (64 - (temp_len % 64))); 588 589 /* the first two bytes are the frame length */ 590 591 buf[0] = (uint8_t)(m->m_pkthdr.len); 592 buf[1] = (uint8_t)(m->m_pkthdr.len >> 8); 593 --- 12 unchanged lines hidden (view full) --- 606 * of this frame to him: 607 */ 608 BPF_MTAP(ifp, m); 609 610 m_freem(m); 611 612 usb2_start_hardware(xfer); 613 |
758done: | |
759 return; 760 761 default: /* Error */ 762 DPRINTFN(11, "transfer error, %s\n", 763 usb2_errstr(xfer->error)); 764 | 614 return; 615 616 default: /* Error */ 617 DPRINTFN(11, "transfer error, %s\n", 618 usb2_errstr(xfer->error)); 619 |
620 ifp->if_oerrors++; 621 |
|
765 if (xfer->error != USB_ERR_CANCELLED) { 766 /* try to clear stall first */ | 622 if (xfer->error != USB_ERR_CANCELLED) { 623 /* try to clear stall first */ |
767 sc->sc_flags |= KUE_FLAG_WRITE_STALL; 768 usb2_transfer_start(sc->sc_xfer[KUE_BULK_CS_WR]); | 624 xfer->flags.stall_pipe = 1; 625 goto tr_setup; |
769 } | 626 } |
770 ifp->if_oerrors++; | |
771 return; 772 773 } 774} 775 776static void | 627 return; 628 629 } 630} 631 632static void |
777kue_start_cb(struct ifnet *ifp) | 633kue_start(struct usb2_ether *ue) |
778{ | 634{ |
779 struct kue_softc *sc = ifp->if_softc; | 635 struct kue_softc *sc = usb2_ether_getsc(ue); |
780 | 636 |
781 mtx_lock(&sc->sc_mtx); 782 783 kue_start_transfers(sc); 784 785 mtx_unlock(&sc->sc_mtx); | 637 /* 638 * start the USB transfers, if not already started: 639 */ 640 usb2_transfer_start(sc->sc_xfer[KUE_BULK_DT_RD]); 641 usb2_transfer_start(sc->sc_xfer[KUE_BULK_DT_WR]); |
786} 787 788static void | 642} 643 644static void |
789kue_start_transfers(struct kue_softc *sc) | 645kue_init(struct usb2_ether *ue) |
790{ | 646{ |
791 if ((sc->sc_flags & KUE_FLAG_LL_READY) && 792 (sc->sc_flags & KUE_FLAG_HL_READY)) { | 647 struct kue_softc *sc = usb2_ether_getsc(ue); 648 struct ifnet *ifp = usb2_ether_getifp(ue); |
793 | 649 |
794 /* 795 * start the USB transfers, if not already started: 796 */ 797 usb2_transfer_start(sc->sc_xfer[KUE_BULK_DT_RD]); 798 usb2_transfer_start(sc->sc_xfer[KUE_BULK_DT_WR]); 799 } 800} | 650 KUE_LOCK_ASSERT(sc, MA_OWNED); |
801 | 651 |
802static void 803kue_init_cb(void *arg) 804{ 805 struct kue_softc *sc = arg; 806 807 mtx_lock(&sc->sc_mtx); 808 usb2_config_td_queue_command 809 (&sc->sc_config_td, &kue_cfg_pre_init, 810 &kue_cfg_init, 0, 0); 811 mtx_unlock(&sc->sc_mtx); 812} 813 814static void 815kue_cfg_pre_init(struct kue_softc *sc, 816 struct usb2_config_td_cc *cc, uint16_t refcount) 817{ 818 struct ifnet *ifp = sc->sc_ifp; 819 820 /* immediate configuration */ 821 822 kue_cfg_pre_stop(sc, cc, 0); 823 824 ifp->if_drv_flags |= IFF_DRV_RUNNING; 825 826 sc->sc_flags |= KUE_FLAG_HL_READY; 827} 828 829static void 830kue_cfg_init(struct kue_softc *sc, 831 struct usb2_config_td_cc *cc, uint16_t refcount) 832{ | |
833 /* set MAC address */ | 652 /* set MAC address */ |
834 kue_cfg_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SET_MAC, 835 0, cc->if_lladdr, ETHER_ADDR_LEN); | 653 kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SET_MAC, 654 0, IF_LLADDR(ifp), ETHER_ADDR_LEN); |
836 837 /* I'm not sure how to tune these. */ 838#if 0 839 /* 840 * Leave this one alone for now; setting it 841 * wrong causes lockups on some machines/controllers. 842 */ | 655 656 /* I'm not sure how to tune these. */ 657#if 0 658 /* 659 * Leave this one alone for now; setting it 660 * wrong causes lockups on some machines/controllers. 661 */ |
843 kue_cfg_setword(sc, KUE_CMD_SET_SOFS, 1); | 662 kue_setword(sc, KUE_CMD_SET_SOFS, 1); |
844#endif | 663#endif |
845 kue_cfg_setword(sc, KUE_CMD_SET_URB_SIZE, 64); | 664 kue_setword(sc, KUE_CMD_SET_URB_SIZE, 64); |
846 847 /* load the multicast filter */ | 665 666 /* load the multicast filter */ |
848 kue_cfg_promisc_upd(sc, cc, 0); | 667 kue_setpromisc(ue); |
849 | 668 |
850 sc->sc_flags |= (KUE_FLAG_READ_STALL | 851 KUE_FLAG_WRITE_STALL | 852 KUE_FLAG_LL_READY); | 669 usb2_transfer_set_stall(sc->sc_xfer[KUE_BULK_DT_WR]); |
853 | 670 |
854 kue_start_transfers(sc); | 671 ifp->if_drv_flags |= IFF_DRV_RUNNING; 672 kue_start(ue); |
855} 856 | 673} 674 |
857static int 858kue_ioctl_cb(struct ifnet *ifp, u_long command, caddr_t data) 859{ 860 struct kue_softc *sc = ifp->if_softc; 861 int error = 0; 862 863 switch (command) { 864 case SIOCSIFFLAGS: 865 mtx_lock(&sc->sc_mtx); 866 if (ifp->if_flags & IFF_UP) { 867 if (ifp->if_drv_flags & IFF_DRV_RUNNING) { 868 usb2_config_td_queue_command 869 (&sc->sc_config_td, &kue_config_copy, 870 &kue_cfg_promisc_upd, 0, 0); 871 } else { 872 usb2_config_td_queue_command 873 (&sc->sc_config_td, &kue_cfg_pre_init, 874 &kue_cfg_init, 0, 0); 875 } 876 } else { 877 if (ifp->if_drv_flags & IFF_DRV_RUNNING) { 878 usb2_config_td_queue_command 879 (&sc->sc_config_td, &kue_cfg_pre_stop, 880 &kue_cfg_stop, 0, 0); 881 } 882 } 883 mtx_unlock(&sc->sc_mtx); 884 break; 885 886 case SIOCADDMULTI: 887 case SIOCDELMULTI: 888 mtx_lock(&sc->sc_mtx); 889 usb2_config_td_queue_command 890 (&sc->sc_config_td, &kue_config_copy, 891 &kue_cfg_promisc_upd, 0, 0); 892 mtx_unlock(&sc->sc_mtx); 893 break; 894 895 default: 896 error = ether_ioctl(ifp, command, data); 897 break; 898 } 899 return (error); 900} 901 | |
902static void | 675static void |
903kue_cfg_tick(struct kue_softc *sc, 904 struct usb2_config_td_cc *cc, uint16_t refcount) | 676kue_stop(struct usb2_ether *ue) |
905{ | 677{ |
906 struct ifnet *ifp = sc->sc_ifp; | 678 struct kue_softc *sc = usb2_ether_getsc(ue); 679 struct ifnet *ifp = usb2_ether_getifp(ue); |
907 | 680 |
908 if ((ifp == NULL)) { 909 /* not ready */ 910 return; 911 } 912 /* start stopped transfers, if any */ | 681 KUE_LOCK_ASSERT(sc, MA_OWNED); |
913 | 682 |
914 kue_start_transfers(sc); 915} | 683 ifp->if_drv_flags &= ~IFF_DRV_RUNNING; |
916 | 684 |
917/* 918 * Stop the adapter and free any mbufs allocated to the 919 * RX and TX lists. 920 */ 921static void 922kue_watchdog(void *arg) 923{ 924 struct kue_softc *sc = arg; 925 926 usb2_config_td_queue_command 927 (&sc->sc_config_td, NULL, &kue_cfg_tick, 0, 0); 928 929 usb2_callout_reset(&sc->sc_watchdog, 930 hz, &kue_watchdog, sc); 931} 932 933static void 934kue_cfg_pre_stop(struct kue_softc *sc, 935 struct usb2_config_td_cc *cc, uint16_t refcount) 936{ 937 struct ifnet *ifp = sc->sc_ifp; 938 939 if (cc) { 940 /* copy the needed configuration */ 941 kue_config_copy(sc, cc, refcount); 942 } 943 /* immediate configuration */ 944 945 if (ifp) { 946 /* clear flags */ 947 ifp->if_drv_flags &= ~IFF_DRV_RUNNING; 948 } 949 sc->sc_flags &= ~(KUE_FLAG_HL_READY | 950 KUE_FLAG_LL_READY); 951 | |
952 /* 953 * stop all the transfers, if not already stopped: 954 */ 955 usb2_transfer_stop(sc->sc_xfer[KUE_BULK_DT_WR]); 956 usb2_transfer_stop(sc->sc_xfer[KUE_BULK_DT_RD]); | 685 /* 686 * stop all the transfers, if not already stopped: 687 */ 688 usb2_transfer_stop(sc->sc_xfer[KUE_BULK_DT_WR]); 689 usb2_transfer_stop(sc->sc_xfer[KUE_BULK_DT_RD]); |
957 usb2_transfer_stop(sc->sc_xfer[KUE_BULK_CS_WR]); 958 usb2_transfer_stop(sc->sc_xfer[KUE_BULK_CS_RD]); | |
959} 960 | 690} 691 |
961static void 962kue_cfg_stop(struct kue_softc *sc, 963 struct usb2_config_td_cc *cc, uint16_t refcount) 964{ 965 return; 966} 967 | |
968/* 969 * Stop all chip I/O so that the kernel's probe routines don't 970 * get confused by errant DMAs when rebooting. 971 */ 972static int 973kue_shutdown(device_t dev) 974{ 975 struct kue_softc *sc = device_get_softc(dev); 976 | 692/* 693 * Stop all chip I/O so that the kernel's probe routines don't 694 * get confused by errant DMAs when rebooting. 695 */ 696static int 697kue_shutdown(device_t dev) 698{ 699 struct kue_softc *sc = device_get_softc(dev); 700 |
977 mtx_lock(&sc->sc_mtx); | 701 usb2_ether_ifshutdown(&sc->sc_ue); |
978 | 702 |
979 usb2_config_td_queue_command 980 (&sc->sc_config_td, &kue_cfg_pre_stop, 981 &kue_cfg_stop, 0, 0); 982 983 mtx_unlock(&sc->sc_mtx); 984 | |
985 return (0); 986} | 703 return (0); 704} |