if_cue.c (187970) | if_cue.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_cue2.c 187970 2009-02-01 00:51:25Z thompsa $"); | 34__FBSDID("$FreeBSD: head/sys/dev/usb2/ethernet/if_cue2.c 188412 2009-02-09 22:02:38Z thompsa $"); |
35 36/* 37 * CATC USB-EL1210A USB to ethernet driver. Used in the CATC Netmate 38 * adapters and others. 39 * 40 * Written by Bill Paul <wpaul@ee.columbia.edu> 41 * Electrical Engineering Department 42 * Columbia University, New York City 43 */ 44 45/* 46 * The CATC USB-EL1210A provides USB ethernet support at 10Mbps. The 47 * RX filter uses a 512-bit multicast hash table, single perfect entry 48 * for the station address, and promiscuous mode. Unlike the ADMtek 49 * and KLSI chips, the CATC ASIC supports read and write combining 50 * mode where multiple packets can be transfered using a single bulk 51 * transaction, which helps performance a great deal. 52 */ 53 | 35 36/* 37 * CATC USB-EL1210A USB to ethernet driver. Used in the CATC Netmate 38 * adapters and others. 39 * 40 * Written by Bill Paul <wpaul@ee.columbia.edu> 41 * Electrical Engineering Department 42 * Columbia University, New York City 43 */ 44 45/* 46 * The CATC USB-EL1210A provides USB ethernet support at 10Mbps. The 47 * RX filter uses a 512-bit multicast hash table, single perfect entry 48 * for the station address, and promiscuous mode. Unlike the ADMtek 49 * and KLSI chips, the CATC ASIC supports read and write combining 50 * mode where multiple packets can be transfered using a single bulk 51 * transaction, which helps performance a great deal. 52 */ 53 |
54/* 55 * NOTE: all function names beginning like "cue_cfg_" can only 56 * be called from within the config thread function ! 57 */ 58 | |
59#include <dev/usb2/include/usb2_devid.h> 60#include <dev/usb2/include/usb2_standard.h> 61#include <dev/usb2/include/usb2_mfunc.h> 62#include <dev/usb2/include/usb2_error.h> 63 | 54#include <dev/usb2/include/usb2_devid.h> 55#include <dev/usb2/include/usb2_standard.h> 56#include <dev/usb2/include/usb2_mfunc.h> 57#include <dev/usb2/include/usb2_error.h> 58 |
64#define usb2_config_td_cc usb2_ether_cc 65#define usb2_config_td_softc cue_softc 66 | |
67#define USB_DEBUG_VAR cue_debug 68 69#include <dev/usb2/core/usb2_core.h> 70#include <dev/usb2/core/usb2_lookup.h> 71#include <dev/usb2/core/usb2_process.h> | 59#define USB_DEBUG_VAR cue_debug 60 61#include <dev/usb2/core/usb2_core.h> 62#include <dev/usb2/core/usb2_lookup.h> 63#include <dev/usb2/core/usb2_process.h> |
72#include <dev/usb2/core/usb2_config_td.h> | |
73#include <dev/usb2/core/usb2_debug.h> 74#include <dev/usb2/core/usb2_request.h> 75#include <dev/usb2/core/usb2_busdma.h> 76#include <dev/usb2/core/usb2_util.h> 77 78#include <dev/usb2/ethernet/usb2_ethernet.h> 79#include <dev/usb2/ethernet/if_cuereg.h> 80 --- 11 unchanged lines hidden (view full) --- 92 93/* prototypes */ 94 95static device_probe_t cue_probe; 96static device_attach_t cue_attach; 97static device_detach_t cue_detach; 98static device_shutdown_t cue_shutdown; 99 | 64#include <dev/usb2/core/usb2_debug.h> 65#include <dev/usb2/core/usb2_request.h> 66#include <dev/usb2/core/usb2_busdma.h> 67#include <dev/usb2/core/usb2_util.h> 68 69#include <dev/usb2/ethernet/usb2_ethernet.h> 70#include <dev/usb2/ethernet/if_cuereg.h> 71 --- 11 unchanged lines hidden (view full) --- 83 84/* prototypes */ 85 86static device_probe_t cue_probe; 87static device_attach_t cue_attach; 88static device_detach_t cue_detach; 89static device_shutdown_t cue_shutdown; 90 |
100static usb2_callback_t cue_bulk_read_clear_stall_callback; | |
101static usb2_callback_t cue_bulk_read_callback; | 91static usb2_callback_t cue_bulk_read_callback; |
102static usb2_callback_t cue_bulk_write_clear_stall_callback; | |
103static usb2_callback_t cue_bulk_write_callback; 104 | 92static usb2_callback_t cue_bulk_write_callback; 93 |
105static usb2_config_td_command_t cue_cfg_promisc_upd; 106static usb2_config_td_command_t cue_config_copy; 107static usb2_config_td_command_t cue_cfg_first_time_setup; 108static usb2_config_td_command_t cue_cfg_tick; 109static usb2_config_td_command_t cue_cfg_pre_init; 110static usb2_config_td_command_t cue_cfg_init; 111static usb2_config_td_command_t cue_cfg_pre_stop; 112static usb2_config_td_command_t cue_cfg_stop; | 94static usb2_ether_fn_t cue_attach_post; 95static usb2_ether_fn_t cue_init; 96static usb2_ether_fn_t cue_stop; 97static usb2_ether_fn_t cue_start; 98static usb2_ether_fn_t cue_tick; 99static usb2_ether_fn_t cue_setmulti; 100static usb2_ether_fn_t cue_setpromisc; |
113 | 101 |
114static void cue_cfg_do_request(struct cue_softc *, 115 struct usb2_device_request *, void *); 116static uint8_t cue_cfg_csr_read_1(struct cue_softc *, uint16_t); 117static uint16_t cue_cfg_csr_read_2(struct cue_softc *, uint8_t); 118static void cue_cfg_csr_write_1(struct cue_softc *, uint16_t, uint16_t); 119static void cue_cfg_mem(struct cue_softc *, uint8_t, uint16_t, void *, 120 uint16_t); 121static void cue_cfg_getmac(struct cue_softc *, void *); 122static void cue_mchash(struct usb2_config_td_cc *, const uint8_t *); 123static void cue_cfg_reset(struct cue_softc *); 124static void cue_start_cb(struct ifnet *); 125static void cue_start_transfers(struct cue_softc *); 126static void cue_init_cb(void *); 127static int cue_ioctl_cb(struct ifnet *, u_long, caddr_t); 128static void cue_watchdog(void *); | 102static uint8_t cue_csr_read_1(struct cue_softc *, uint16_t); 103static uint16_t cue_csr_read_2(struct cue_softc *, uint8_t); 104static int cue_csr_write_1(struct cue_softc *, uint16_t, uint16_t); 105static int cue_mem(struct cue_softc *, uint8_t, uint16_t, void *, int); 106static int cue_getmac(struct cue_softc *, void *); 107static uint32_t cue_mchash(const uint8_t *); 108static void cue_reset(struct cue_softc *); |
129 130#if USB_DEBUG 131static int cue_debug = 0; 132 133SYSCTL_NODE(_hw_usb2, OID_AUTO, cue, CTLFLAG_RW, 0, "USB cue"); 134SYSCTL_INT(_hw_usb2_cue, OID_AUTO, debug, CTLFLAG_RW, &cue_debug, 0, 135 "Debug level"); 136#endif 137 138static const struct usb2_config cue_config[CUE_N_TRANSFER] = { 139 140 [CUE_BULK_DT_WR] = { 141 .type = UE_BULK, 142 .endpoint = UE_ADDR_ANY, 143 .direction = UE_DIR_OUT, 144 .mh.bufsize = (MCLBYTES + 2), 145 .mh.flags = {.pipe_bof = 1,}, | 109 110#if USB_DEBUG 111static int cue_debug = 0; 112 113SYSCTL_NODE(_hw_usb2, OID_AUTO, cue, CTLFLAG_RW, 0, "USB cue"); 114SYSCTL_INT(_hw_usb2_cue, OID_AUTO, debug, CTLFLAG_RW, &cue_debug, 0, 115 "Debug level"); 116#endif 117 118static const struct usb2_config cue_config[CUE_N_TRANSFER] = { 119 120 [CUE_BULK_DT_WR] = { 121 .type = UE_BULK, 122 .endpoint = UE_ADDR_ANY, 123 .direction = UE_DIR_OUT, 124 .mh.bufsize = (MCLBYTES + 2), 125 .mh.flags = {.pipe_bof = 1,}, |
146 .mh.callback = &cue_bulk_write_callback, | 126 .mh.callback = cue_bulk_write_callback, |
147 .mh.timeout = 10000, /* 10 seconds */ 148 }, 149 150 [CUE_BULK_DT_RD] = { 151 .type = UE_BULK, 152 .endpoint = UE_ADDR_ANY, 153 .direction = UE_DIR_IN, 154 .mh.bufsize = (MCLBYTES + 2), 155 .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, | 127 .mh.timeout = 10000, /* 10 seconds */ 128 }, 129 130 [CUE_BULK_DT_RD] = { 131 .type = UE_BULK, 132 .endpoint = UE_ADDR_ANY, 133 .direction = UE_DIR_IN, 134 .mh.bufsize = (MCLBYTES + 2), 135 .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, |
156 .mh.callback = &cue_bulk_read_callback, | 136 .mh.callback = cue_bulk_read_callback, |
157 }, | 137 }, |
158 159 [CUE_BULK_CS_WR] = { 160 .type = UE_CONTROL, 161 .endpoint = 0x00, /* Control pipe */ 162 .direction = UE_DIR_ANY, 163 .mh.bufsize = sizeof(struct usb2_device_request), 164 .mh.flags = {}, 165 .mh.callback = &cue_bulk_write_clear_stall_callback, 166 .mh.timeout = 1000, /* 1 second */ 167 .mh.interval = 50, /* 50ms */ 168 }, 169 170 [CUE_BULK_CS_RD] = { 171 .type = UE_CONTROL, 172 .endpoint = 0x00, /* Control pipe */ 173 .direction = UE_DIR_ANY, 174 .mh.bufsize = sizeof(struct usb2_device_request), 175 .mh.flags = {}, 176 .mh.callback = &cue_bulk_read_clear_stall_callback, 177 .mh.timeout = 1000, /* 1 second */ 178 .mh.interval = 50, /* 50ms */ 179 }, | |
180}; 181 182static device_method_t cue_methods[] = { 183 /* Device interface */ 184 DEVMETHOD(device_probe, cue_probe), 185 DEVMETHOD(device_attach, cue_attach), 186 DEVMETHOD(device_detach, cue_detach), 187 DEVMETHOD(device_shutdown, cue_shutdown), --- 9 unchanged lines hidden (view full) --- 197 198static devclass_t cue_devclass; 199 200DRIVER_MODULE(cue, ushub, cue_driver, cue_devclass, NULL, 0); 201MODULE_DEPEND(cue, usb2_ethernet, 1, 1, 1); 202MODULE_DEPEND(cue, usb2_core, 1, 1, 1); 203MODULE_DEPEND(cue, ether, 1, 1, 1); 204 | 138}; 139 140static device_method_t cue_methods[] = { 141 /* Device interface */ 142 DEVMETHOD(device_probe, cue_probe), 143 DEVMETHOD(device_attach, cue_attach), 144 DEVMETHOD(device_detach, cue_detach), 145 DEVMETHOD(device_shutdown, cue_shutdown), --- 9 unchanged lines hidden (view full) --- 155 156static devclass_t cue_devclass; 157 158DRIVER_MODULE(cue, ushub, cue_driver, cue_devclass, NULL, 0); 159MODULE_DEPEND(cue, usb2_ethernet, 1, 1, 1); 160MODULE_DEPEND(cue, usb2_core, 1, 1, 1); 161MODULE_DEPEND(cue, ether, 1, 1, 1); 162 |
205static void 206cue_cfg_do_request(struct cue_softc *sc, struct usb2_device_request *req, 207 void *data) 208{ 209 uint16_t length; 210 usb2_error_t err; | 163static const struct usb2_ether_methods cue_ue_methods = { 164 .ue_attach_post = cue_attach_post, 165 .ue_start = cue_start, 166 .ue_init = cue_init, 167 .ue_stop = cue_stop, 168 .ue_tick = cue_tick, 169 .ue_setmulti = cue_setmulti, 170 .ue_setpromisc = cue_setpromisc, 171}; |
211 | 172 |
212 if (usb2_config_td_is_gone(&sc->sc_config_td)) { 213 goto error; 214 } 215 err = usb2_do_request_flags 216 (sc->sc_udev, &sc->sc_mtx, req, data, 0, NULL, 1000); | 173#define CUE_SETBIT(sc, reg, x) \ 174 cue_csr_write_1(sc, reg, cue_csr_read_1(sc, reg) | (x)) |
217 | 175 |
218 if (err) { | 176#define CUE_CLRBIT(sc, reg, x) \ 177 cue_csr_write_1(sc, reg, cue_csr_read_1(sc, reg) & ~(x)) |
219 | 178 |
220 DPRINTF("device request failed, err=%s " 221 "(ignored)\n", usb2_errstr(err)); 222 223error: 224 length = UGETW(req->wLength); 225 226 if ((req->bmRequestType & UT_READ) && length) { 227 bzero(data, length); 228 } 229 } 230} 231 232#define CUE_CFG_SETBIT(sc, reg, x) \ 233 cue_cfg_csr_write_1(sc, reg, cue_cfg_csr_read_1(sc, reg) | (x)) 234 235#define CUE_CFG_CLRBIT(sc, reg, x) \ 236 cue_cfg_csr_write_1(sc, reg, cue_cfg_csr_read_1(sc, reg) & ~(x)) 237 | |
238static uint8_t | 179static uint8_t |
239cue_cfg_csr_read_1(struct cue_softc *sc, uint16_t reg) | 180cue_csr_read_1(struct cue_softc *sc, uint16_t reg) |
240{ 241 struct usb2_device_request req; 242 uint8_t val; 243 244 req.bmRequestType = UT_READ_VENDOR_DEVICE; 245 req.bRequest = CUE_CMD_READREG; 246 USETW(req.wValue, 0); 247 USETW(req.wIndex, reg); 248 USETW(req.wLength, 1); 249 | 181{ 182 struct usb2_device_request req; 183 uint8_t val; 184 185 req.bmRequestType = UT_READ_VENDOR_DEVICE; 186 req.bRequest = CUE_CMD_READREG; 187 USETW(req.wValue, 0); 188 USETW(req.wIndex, reg); 189 USETW(req.wLength, 1); 190 |
250 cue_cfg_do_request(sc, &req, &val); | 191 if (usb2_ether_do_request(&sc->sc_ue, &req, &val, 1000)) { 192 /* ignore any errors */ 193 } |
251 return (val); 252} 253 254static uint16_t | 194 return (val); 195} 196 197static uint16_t |
255cue_cfg_csr_read_2(struct cue_softc *sc, uint8_t reg) | 198cue_csr_read_2(struct cue_softc *sc, uint8_t reg) |
256{ 257 struct usb2_device_request req; 258 uint16_t val; 259 260 req.bmRequestType = UT_READ_VENDOR_DEVICE; 261 req.bRequest = CUE_CMD_READREG; 262 USETW(req.wValue, 0); 263 USETW(req.wIndex, reg); 264 USETW(req.wLength, 2); 265 | 199{ 200 struct usb2_device_request req; 201 uint16_t val; 202 203 req.bmRequestType = UT_READ_VENDOR_DEVICE; 204 req.bRequest = CUE_CMD_READREG; 205 USETW(req.wValue, 0); 206 USETW(req.wIndex, reg); 207 USETW(req.wLength, 2); 208 |
266 cue_cfg_do_request(sc, &req, &val); | 209 (void)usb2_ether_do_request(&sc->sc_ue, &req, &val, 1000); |
267 return (le16toh(val)); 268} 269 | 210 return (le16toh(val)); 211} 212 |
270static void 271cue_cfg_csr_write_1(struct cue_softc *sc, uint16_t reg, uint16_t val) | 213static int 214cue_csr_write_1(struct cue_softc *sc, uint16_t reg, uint16_t val) |
272{ 273 struct usb2_device_request req; 274 275 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 276 req.bRequest = CUE_CMD_WRITEREG; 277 USETW(req.wValue, val); 278 USETW(req.wIndex, reg); 279 USETW(req.wLength, 0); 280 | 215{ 216 struct usb2_device_request req; 217 218 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 219 req.bRequest = CUE_CMD_WRITEREG; 220 USETW(req.wValue, val); 221 USETW(req.wIndex, reg); 222 USETW(req.wLength, 0); 223 |
281 cue_cfg_do_request(sc, &req, NULL); | 224 return (usb2_ether_do_request(&sc->sc_ue, &req, NULL, 1000)); |
282} 283 | 225} 226 |
284static void 285cue_cfg_mem(struct cue_softc *sc, uint8_t cmd, uint16_t addr, 286 void *buf, uint16_t len) | 227static int 228cue_mem(struct cue_softc *sc, uint8_t cmd, uint16_t addr, void *buf, int len) |
287{ 288 struct usb2_device_request req; 289 | 229{ 230 struct usb2_device_request req; 231 |
290 if (cmd == CUE_CMD_READSRAM) { | 232 if (cmd == CUE_CMD_READSRAM) |
291 req.bmRequestType = UT_READ_VENDOR_DEVICE; | 233 req.bmRequestType = UT_READ_VENDOR_DEVICE; |
292 } else { | 234 else |
293 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; | 235 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; |
294 } | |
295 req.bRequest = cmd; 296 USETW(req.wValue, 0); 297 USETW(req.wIndex, addr); 298 USETW(req.wLength, len); 299 | 236 req.bRequest = cmd; 237 USETW(req.wValue, 0); 238 USETW(req.wIndex, addr); 239 USETW(req.wLength, len); 240 |
300 cue_cfg_do_request(sc, &req, buf); | 241 return (usb2_ether_do_request(&sc->sc_ue, &req, buf, 1000)); |
301} 302 | 242} 243 |
303static void 304cue_cfg_getmac(struct cue_softc *sc, void *buf) | 244static int 245cue_getmac(struct cue_softc *sc, void *buf) |
305{ 306 struct usb2_device_request req; 307 308 req.bmRequestType = UT_READ_VENDOR_DEVICE; 309 req.bRequest = CUE_CMD_GET_MACADDR; 310 USETW(req.wValue, 0); 311 USETW(req.wIndex, 0); 312 USETW(req.wLength, ETHER_ADDR_LEN); 313 | 246{ 247 struct usb2_device_request req; 248 249 req.bmRequestType = UT_READ_VENDOR_DEVICE; 250 req.bRequest = CUE_CMD_GET_MACADDR; 251 USETW(req.wValue, 0); 252 USETW(req.wIndex, 0); 253 USETW(req.wLength, ETHER_ADDR_LEN); 254 |
314 cue_cfg_do_request(sc, &req, buf); | 255 return (usb2_ether_do_request(&sc->sc_ue, &req, buf, 1000)); |
315} 316 317#define CUE_BITS 9 318 | 256} 257 258#define CUE_BITS 9 259 |
319static void 320cue_mchash(struct usb2_config_td_cc *cc, const uint8_t *addr) | 260static uint32_t 261cue_mchash(const uint8_t *addr) |
321{ | 262{ |
322 uint16_t h; | 263 uint32_t crc; |
323 | 264 |
324 h = ether_crc32_le(addr, ETHER_ADDR_LEN) & 325 ((1 << CUE_BITS) - 1); 326 cc->if_hash[h >> 3] |= 1 << (h & 0x7); | 265 /* Compute CRC for the address value. */ 266 crc = ether_crc32_le(addr, ETHER_ADDR_LEN); 267 268 return (crc & ((1 << CUE_BITS) - 1)); |
327} 328 329static void | 269} 270 271static void |
330cue_cfg_promisc_upd(struct cue_softc *sc, 331 struct usb2_config_td_cc *cc, uint16_t refcount) | 272cue_setpromisc(struct usb2_ether *ue) |
332{ | 273{ |
333 /* if we want promiscuous mode, set the allframes bit */ | 274 struct cue_softc *sc = usb2_ether_getsc(ue); 275 struct ifnet *ifp = usb2_ether_getifp(ue); |
334 | 276 |
335 if (cc->if_flags & IFF_PROMISC) { 336 CUE_CFG_SETBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC); 337 } else { 338 CUE_CFG_CLRBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC); 339 } | 277 CUE_LOCK_ASSERT(sc, MA_OWNED); |
340 | 278 |
341 /* write multicast hash-bits */ | 279 /* if we want promiscuous mode, set the allframes bit */ 280 if (ifp->if_flags & IFF_PROMISC) 281 CUE_SETBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC); 282 else 283 CUE_CLRBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC); |
342 | 284 |
343 cue_cfg_mem(sc, CUE_CMD_WRITESRAM, CUE_MCAST_TABLE_ADDR, 344 cc->if_hash, CUE_MCAST_TABLE_LEN); | 285 /* write multicast hash-bits */ 286 cue_setmulti(ue); |
345} 346 347static void | 287} 288 289static void |
348cue_config_copy(struct cue_softc *sc, 349 struct usb2_config_td_cc *cc, uint16_t refcount) | 290cue_setmulti(struct usb2_ether *ue) |
350{ | 291{ |
351 bzero(cc, sizeof(*cc)); 352 usb2_ether_cc(sc->sc_ifp, &cue_mchash, cc); | 292 struct cue_softc *sc = usb2_ether_getsc(ue); 293 struct ifnet *ifp = usb2_ether_getifp(ue); 294 struct ifmultiaddr *ifma; 295 uint32_t h = 0, i; 296 uint8_t hashtbl[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; 297 298 CUE_LOCK_ASSERT(sc, MA_OWNED); 299 300 if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) { 301 for (i = 0; i < 8; i++) 302 hashtbl[i] = 0xff; 303 cue_mem(sc, CUE_CMD_WRITESRAM, CUE_MCAST_TABLE_ADDR, 304 &hashtbl, 8); 305 return; 306 } 307 308 /* now program new ones */ 309 IF_ADDR_LOCK(ifp); 310 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) 311 { 312 if (ifma->ifma_addr->sa_family != AF_LINK) 313 continue; 314 h = cue_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr)); 315 hashtbl[h >> 3] |= 1 << (h & 0x7); 316 } 317 IF_ADDR_UNLOCK(ifp); 318 319 /* 320 * Also include the broadcast address in the filter 321 * so we can receive broadcast frames. 322 */ 323 if (ifp->if_flags & IFF_BROADCAST) { 324 h = cue_mchash(ifp->if_broadcastaddr); 325 hashtbl[h >> 3] |= 1 << (h & 0x7); 326 } 327 328 cue_mem(sc, CUE_CMD_WRITESRAM, CUE_MCAST_TABLE_ADDR, &hashtbl, 8); |
353} 354 355static void | 329} 330 331static void |
356cue_cfg_reset(struct cue_softc *sc) | 332cue_reset(struct cue_softc *sc) |
357{ 358 struct usb2_device_request req; 359 360 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 361 req.bRequest = CUE_CMD_RESET; 362 USETW(req.wValue, 0); 363 USETW(req.wIndex, 0); 364 USETW(req.wLength, 0); 365 | 333{ 334 struct usb2_device_request req; 335 336 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 337 req.bRequest = CUE_CMD_RESET; 338 USETW(req.wValue, 0); 339 USETW(req.wIndex, 0); 340 USETW(req.wLength, 0); 341 |
366 cue_cfg_do_request(sc, &req, NULL); | 342 if (usb2_ether_do_request(&sc->sc_ue, &req, NULL, 1000)) { 343 /* ignore any errors */ 344 } |
367 368 /* 369 * wait a little while for the chip to get its brains in order: 370 */ | 345 346 /* 347 * wait a little while for the chip to get its brains in order: 348 */ |
349 usb2_ether_pause(&sc->sc_ue, hz / 100); 350} |
|
371 | 351 |
372 (void)usb2_config_td_sleep(&sc->sc_config_td, hz / 100); | 352static void 353cue_attach_post(struct usb2_ether *ue) 354{ 355 struct cue_softc *sc = usb2_ether_getsc(ue); 356 357 cue_getmac(sc, ue->ue_eaddr); |
373} 374 375static int 376cue_probe(device_t dev) 377{ 378 struct usb2_attach_arg *uaa = device_get_ivars(dev); 379 | 358} 359 360static int 361cue_probe(device_t dev) 362{ 363 struct usb2_attach_arg *uaa = device_get_ivars(dev); 364 |
380 if (uaa->usb2_mode != USB_MODE_HOST) { | 365 if (uaa->usb2_mode != USB_MODE_HOST) |
381 return (ENXIO); | 366 return (ENXIO); |
382 } 383 if (uaa->info.bConfigIndex != CUE_CONFIG_IDX) { | 367 if (uaa->info.bConfigIndex != CUE_CONFIG_IDX) |
384 return (ENXIO); | 368 return (ENXIO); |
385 } 386 if (uaa->info.bIfaceIndex != CUE_IFACE_IDX) { | 369 if (uaa->info.bIfaceIndex != CUE_IFACE_IDX) |
387 return (ENXIO); | 370 return (ENXIO); |
388 } | 371 |
389 return (usb2_lookup_id_by_uaa(cue_devs, sizeof(cue_devs), uaa)); 390} 391 | 372 return (usb2_lookup_id_by_uaa(cue_devs, sizeof(cue_devs), uaa)); 373} 374 |
375/* 376 * Attach the interface. Allocate softc structures, do ifmedia 377 * setup and ethernet/BPF attach. 378 */ |
|
392static int 393cue_attach(device_t dev) 394{ 395 struct usb2_attach_arg *uaa = device_get_ivars(dev); 396 struct cue_softc *sc = device_get_softc(dev); | 379static int 380cue_attach(device_t dev) 381{ 382 struct usb2_attach_arg *uaa = device_get_ivars(dev); 383 struct cue_softc *sc = device_get_softc(dev); |
384 struct usb2_ether *ue = &sc->sc_ue; |
|
397 uint8_t iface_index; | 385 uint8_t iface_index; |
398 int32_t error; | 386 int error; |
399 | 387 |
400 sc->sc_udev = uaa->device; 401 sc->sc_dev = dev; 402 sc->sc_unit = device_get_unit(dev); 403 | |
404 device_set_usb2_desc(dev); | 388 device_set_usb2_desc(dev); |
389 mtx_init(&sc->sc_mtx, device_get_nameunit(dev), NULL, MTX_DEF); |
|
405 | 390 |
406 mtx_init(&sc->sc_mtx, "cue lock", NULL, MTX_DEF | MTX_RECURSE); 407 408 usb2_callout_init_mtx(&sc->sc_watchdog, &sc->sc_mtx, 0); 409 | |
410 iface_index = CUE_IFACE_IDX; 411 error = usb2_transfer_setup(uaa->device, &iface_index, 412 sc->sc_xfer, cue_config, CUE_N_TRANSFER, sc, &sc->sc_mtx); 413 if (error) { | 391 iface_index = CUE_IFACE_IDX; 392 error = usb2_transfer_setup(uaa->device, &iface_index, 393 sc->sc_xfer, cue_config, CUE_N_TRANSFER, sc, &sc->sc_mtx); 394 if (error) { |
414 device_printf(dev, "allocating USB " 415 "transfers failed!\n"); | 395 device_printf(dev, "allocating USB transfers failed!\n"); |
416 goto detach; 417 } | 396 goto detach; 397 } |
418 error = usb2_config_td_setup(&sc->sc_config_td, sc, &sc->sc_mtx, 419 NULL, sizeof(struct usb2_config_td_cc), 16); | 398 399 ue->ue_sc = sc; 400 ue->ue_dev = dev; 401 ue->ue_udev = uaa->device; 402 ue->ue_mtx = &sc->sc_mtx; 403 ue->ue_methods = &cue_ue_methods; 404 405 error = usb2_ether_ifattach(ue); |
420 if (error) { | 406 if (error) { |
421 device_printf(dev, "could not setup config " 422 "thread!\n"); | 407 device_printf(dev, "could not attach interface\n"); |
423 goto detach; 424 } | 408 goto detach; 409 } |
425 mtx_lock(&sc->sc_mtx); 426 427 /* start setup */ 428 429 usb2_config_td_queue_command 430 (&sc->sc_config_td, NULL, &cue_cfg_first_time_setup, 0, 0); 431 432 cue_watchdog(sc); 433 mtx_unlock(&sc->sc_mtx); | |
434 return (0); /* success */ 435 436detach: 437 cue_detach(dev); 438 return (ENXIO); /* failure */ 439} 440 | 410 return (0); /* success */ 411 412detach: 413 cue_detach(dev); 414 return (ENXIO); /* failure */ 415} 416 |
441static void 442cue_cfg_first_time_setup(struct cue_softc *sc, 443 struct usb2_config_td_cc *cc, uint16_t refcount) 444{ 445 uint8_t eaddr[ETHER_ADDR_LEN]; 446 struct ifnet *ifp; 447 448#if 0 449 /* Reset the adapter. */ 450 cue_cfg_reset(sc); 451#endif 452 /* 453 * Get station address. 454 */ 455 cue_cfg_getmac(sc, eaddr); 456 457 mtx_unlock(&sc->sc_mtx); 458 459 ifp = if_alloc(IFT_ETHER); 460 461 mtx_lock(&sc->sc_mtx); 462 463 if (ifp == NULL) { 464 printf("cue%d: could not if_alloc()\n", 465 sc->sc_unit); 466 goto done; 467 } 468 469 ifp->if_softc = sc; 470 if_initname(ifp, "cue", sc->sc_unit); 471 ifp->if_mtu = ETHERMTU; 472 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; 473 ifp->if_ioctl = cue_ioctl_cb; 474 ifp->if_start = cue_start_cb; 475 ifp->if_watchdog = NULL; 476 ifp->if_init = cue_init_cb; 477 ifp->if_baudrate = 10000000; 478 IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN); 479 ifp->if_snd.ifq_drv_maxlen = IFQ_MAXLEN; 480 IFQ_SET_READY(&ifp->if_snd); 481 482 sc->sc_ifp = ifp; 483 484 mtx_unlock(&sc->sc_mtx); 485 486 ether_ifattach(ifp, eaddr); 487 488 mtx_lock(&sc->sc_mtx); 489 490done: 491 return; 492} 493 | |
494static int 495cue_detach(device_t dev) 496{ 497 struct cue_softc *sc = device_get_softc(dev); | 417static int 418cue_detach(device_t dev) 419{ 420 struct cue_softc *sc = device_get_softc(dev); |
498 struct ifnet *ifp; | 421 struct usb2_ether *ue = &sc->sc_ue; |
499 | 422 |
500 usb2_config_td_drain(&sc->sc_config_td); 501 502 mtx_lock(&sc->sc_mtx); 503 504 usb2_callout_stop(&sc->sc_watchdog); 505 506 cue_cfg_pre_stop(sc, NULL, 0); 507 508 ifp = sc->sc_ifp; 509 510 mtx_unlock(&sc->sc_mtx); 511 512 /* stop all USB transfers first */ | |
513 usb2_transfer_unsetup(sc->sc_xfer, CUE_N_TRANSFER); | 423 usb2_transfer_unsetup(sc->sc_xfer, CUE_N_TRANSFER); |
514 515 /* get rid of any late children */ 516 bus_generic_detach(dev); 517 518 if (ifp) { 519 ether_ifdetach(ifp); 520 if_free(ifp); 521 } 522 usb2_config_td_unsetup(&sc->sc_config_td); 523 524 usb2_callout_drain(&sc->sc_watchdog); 525 | 424 usb2_ether_ifdetach(ue); |
526 mtx_destroy(&sc->sc_mtx); 527 528 return (0); 529} 530 531static void | 425 mtx_destroy(&sc->sc_mtx); 426 427 return (0); 428} 429 430static void |
532cue_bulk_read_clear_stall_callback(struct usb2_xfer *xfer) 533{ 534 struct cue_softc *sc = xfer->priv_sc; 535 struct usb2_xfer *xfer_other = sc->sc_xfer[CUE_BULK_DT_RD]; 536 537 if (usb2_clear_stall_callback(xfer, xfer_other)) { 538 DPRINTF("stall cleared\n"); 539 sc->sc_flags &= ~CUE_FLAG_READ_STALL; 540 usb2_transfer_start(xfer_other); 541 } 542} 543 544static void | |
545cue_bulk_read_callback(struct usb2_xfer *xfer) 546{ 547 struct cue_softc *sc = xfer->priv_sc; | 431cue_bulk_read_callback(struct usb2_xfer *xfer) 432{ 433 struct cue_softc *sc = xfer->priv_sc; |
548 struct ifnet *ifp = sc->sc_ifp; 549 struct mbuf *m = NULL; | 434 struct usb2_ether *ue = &sc->sc_ue; 435 struct ifnet *ifp = usb2_ether_getifp(ue); |
550 uint8_t buf[2]; | 436 uint8_t buf[2]; |
551 uint16_t len; | 437 int len; |
552 553 switch (USB_GET_STATE(xfer)) { 554 case USB_ST_TRANSFERRED: 555 556 if (xfer->actlen <= (2 + sizeof(struct ether_header))) { 557 ifp->if_ierrors++; 558 goto tr_setup; 559 } 560 usb2_copy_out(xfer->frbuffers, 0, buf, 2); | 438 439 switch (USB_GET_STATE(xfer)) { 440 case USB_ST_TRANSFERRED: 441 442 if (xfer->actlen <= (2 + sizeof(struct ether_header))) { 443 ifp->if_ierrors++; 444 goto tr_setup; 445 } 446 usb2_copy_out(xfer->frbuffers, 0, buf, 2); |
561 | 447 xfer->actlen -= 2; |
562 len = buf[0] | (buf[1] << 8); | 448 len = buf[0] | (buf[1] << 8); |
449 len = min(xfer->actlen, len); |
|
563 | 450 |
564 xfer->actlen -= 2; 565 566 m = usb2_ether_get_mbuf(); 567 568 if (m == NULL) { 569 ifp->if_ierrors++; 570 goto tr_setup; 571 } 572 xfer->actlen = min(xfer->actlen, m->m_len); 573 xfer->actlen = min(xfer->actlen, len); 574 575 usb2_copy_out(xfer->frbuffers, 2, m->m_data, xfer->actlen); 576 577 ifp->if_ipackets++; 578 m->m_pkthdr.rcvif = ifp; 579 m->m_pkthdr.len = m->m_len = xfer->actlen; 580 | 451 usb2_ether_rxbuf(ue, xfer->frbuffers, 2, len); 452 /* FALLTHROUGH */ |
581 case USB_ST_SETUP: 582tr_setup: | 453 case USB_ST_SETUP: 454tr_setup: |
583 584 if (sc->sc_flags & CUE_FLAG_READ_STALL) { 585 usb2_transfer_start(sc->sc_xfer[CUE_BULK_CS_RD]); 586 } else { 587 xfer->frlengths[0] = xfer->max_data_length; 588 usb2_start_hardware(xfer); 589 } 590 591 /* 592 * At the end of a USB callback it is always safe to unlock 593 * the private mutex of a device! That is why we do the 594 * "if_input" here, and not some lines up! 595 */ 596 if (m) { 597 mtx_unlock(&sc->sc_mtx); 598 (ifp->if_input) (ifp, m); 599 mtx_lock(&sc->sc_mtx); 600 } | 455 xfer->frlengths[0] = xfer->max_data_length; 456 usb2_start_hardware(xfer); 457 usb2_ether_rxflush(ue); |
601 return; 602 603 default: /* Error */ | 458 return; 459 460 default: /* Error */ |
461 DPRINTF("bulk read error, %s\n", 462 usb2_errstr(xfer->error)); 463 |
|
604 if (xfer->error != USB_ERR_CANCELLED) { 605 /* try to clear stall first */ | 464 if (xfer->error != USB_ERR_CANCELLED) { 465 /* try to clear stall first */ |
606 sc->sc_flags |= CUE_FLAG_READ_STALL; 607 usb2_transfer_start(sc->sc_xfer[CUE_BULK_CS_RD]); | 466 xfer->flags.stall_pipe = 1; 467 goto tr_setup; |
608 } | 468 } |
609 DPRINTF("bulk read error, %s\n", 610 usb2_errstr(xfer->error)); | |
611 return; 612 613 } 614} 615 616static void | 469 return; 470 471 } 472} 473 474static void |
617cue_cfg_tick(struct cue_softc *sc, 618 struct usb2_config_td_cc *cc, uint16_t refcount) 619{ 620 struct ifnet *ifp = sc->sc_ifp; 621 622 if ((ifp == NULL)) { 623 /* not ready */ 624 return; 625 } 626 ifp->if_collisions += cue_cfg_csr_read_2(sc, CUE_TX_SINGLECOLL); 627 ifp->if_collisions += cue_cfg_csr_read_2(sc, CUE_TX_MULTICOLL); 628 ifp->if_collisions += cue_cfg_csr_read_2(sc, CUE_TX_EXCESSCOLL); 629 630 if (cue_cfg_csr_read_2(sc, CUE_RX_FRAMEERR)) { 631 ifp->if_ierrors++; 632 } 633 /* start stopped transfers, if any */ 634 635 cue_start_transfers(sc); 636} 637 638static void 639cue_start_cb(struct ifnet *ifp) 640{ 641 struct cue_softc *sc = ifp->if_softc; 642 643 mtx_lock(&sc->sc_mtx); 644 645 cue_start_transfers(sc); 646 647 mtx_unlock(&sc->sc_mtx); 648} 649 650static void 651cue_start_transfers(struct cue_softc *sc) 652{ 653 if ((sc->sc_flags & CUE_FLAG_LL_READY) && 654 (sc->sc_flags & CUE_FLAG_HL_READY)) { 655 656 /* 657 * start the USB transfers, if not already started: 658 */ 659 usb2_transfer_start(sc->sc_xfer[CUE_BULK_DT_RD]); 660 usb2_transfer_start(sc->sc_xfer[CUE_BULK_DT_WR]); 661 } 662} 663 664static void 665cue_bulk_write_clear_stall_callback(struct usb2_xfer *xfer) 666{ 667 struct cue_softc *sc = xfer->priv_sc; 668 struct usb2_xfer *xfer_other = sc->sc_xfer[CUE_BULK_DT_WR]; 669 670 if (usb2_clear_stall_callback(xfer, xfer_other)) { 671 DPRINTF("stall cleared\n"); 672 sc->sc_flags &= ~CUE_FLAG_WRITE_STALL; 673 usb2_transfer_start(xfer_other); 674 } 675} 676 677static void | |
678cue_bulk_write_callback(struct usb2_xfer *xfer) 679{ 680 struct cue_softc *sc = xfer->priv_sc; | 475cue_bulk_write_callback(struct usb2_xfer *xfer) 476{ 477 struct cue_softc *sc = xfer->priv_sc; |
681 struct ifnet *ifp = sc->sc_ifp; | 478 struct ifnet *ifp = usb2_ether_getifp(&sc->sc_ue); |
682 struct mbuf *m; 683 uint8_t buf[2]; 684 685 switch (USB_GET_STATE(xfer)) { 686 case USB_ST_TRANSFERRED: 687 DPRINTFN(11, "transfer complete\n"); | 479 struct mbuf *m; 480 uint8_t buf[2]; 481 482 switch (USB_GET_STATE(xfer)) { 483 case USB_ST_TRANSFERRED: 484 DPRINTFN(11, "transfer complete\n"); |
688 | |
689 ifp->if_opackets++; 690 | 485 ifp->if_opackets++; 486 |
487 /* FALLTHROUGH */ |
|
691 case USB_ST_SETUP: | 488 case USB_ST_SETUP: |
692 693 if (sc->sc_flags & CUE_FLAG_WRITE_STALL) { 694 usb2_transfer_start(sc->sc_xfer[CUE_BULK_CS_WR]); 695 goto done; 696 } | 489tr_setup: |
697 IFQ_DRV_DEQUEUE(&ifp->if_snd, m); 698 | 490 IFQ_DRV_DEQUEUE(&ifp->if_snd, m); 491 |
699 if (m == NULL) { 700 goto done; 701 } 702 if (m->m_pkthdr.len > MCLBYTES) { | 492 if (m == NULL) 493 return; 494 if (m->m_pkthdr.len > MCLBYTES) |
703 m->m_pkthdr.len = MCLBYTES; | 495 m->m_pkthdr.len = MCLBYTES; |
704 } | |
705 xfer->frlengths[0] = (m->m_pkthdr.len + 2); 706 707 /* the first two bytes are the frame length */ 708 709 buf[0] = (uint8_t)(m->m_pkthdr.len); 710 buf[1] = (uint8_t)(m->m_pkthdr.len >> 8); 711 712 usb2_copy_in(xfer->frbuffers, 0, buf, 2); --- 6 unchanged lines hidden (view full) --- 719 * to him. 720 */ 721 BPF_MTAP(ifp, m); 722 723 m_freem(m); 724 725 usb2_start_hardware(xfer); 726 | 496 xfer->frlengths[0] = (m->m_pkthdr.len + 2); 497 498 /* the first two bytes are the frame length */ 499 500 buf[0] = (uint8_t)(m->m_pkthdr.len); 501 buf[1] = (uint8_t)(m->m_pkthdr.len >> 8); 502 503 usb2_copy_in(xfer->frbuffers, 0, buf, 2); --- 6 unchanged lines hidden (view full) --- 510 * to him. 511 */ 512 BPF_MTAP(ifp, m); 513 514 m_freem(m); 515 516 usb2_start_hardware(xfer); 517 |
727done: | |
728 return; 729 730 default: /* Error */ 731 DPRINTFN(11, "transfer error, %s\n", 732 usb2_errstr(xfer->error)); 733 | 518 return; 519 520 default: /* Error */ 521 DPRINTFN(11, "transfer error, %s\n", 522 usb2_errstr(xfer->error)); 523 |
524 ifp->if_oerrors++; 525 |
|
734 if (xfer->error != USB_ERR_CANCELLED) { 735 /* try to clear stall first */ | 526 if (xfer->error != USB_ERR_CANCELLED) { 527 /* try to clear stall first */ |
736 sc->sc_flags |= CUE_FLAG_WRITE_STALL; 737 usb2_transfer_start(sc->sc_xfer[CUE_BULK_CS_WR]); | 528 xfer->flags.stall_pipe = 1; 529 goto tr_setup; |
738 } | 530 } |
739 ifp->if_oerrors++; | |
740 return; | 531 return; |
741 | |
742 } 743} 744 745static void | 532 } 533} 534 535static void |
746cue_init_cb(void *arg) | 536cue_tick(struct usb2_ether *ue) |
747{ | 537{ |
748 struct cue_softc *sc = arg; | 538 struct cue_softc *sc = usb2_ether_getsc(ue); 539 struct ifnet *ifp = usb2_ether_getifp(ue); |
749 | 540 |
750 mtx_lock(&sc->sc_mtx); 751 usb2_config_td_queue_command 752 (&sc->sc_config_td, &cue_cfg_pre_init, 753 &cue_cfg_init, 0, 0); 754 mtx_unlock(&sc->sc_mtx); | 541 CUE_LOCK_ASSERT(sc, MA_OWNED); 542 543 ifp->if_collisions += cue_csr_read_2(sc, CUE_TX_SINGLECOLL); 544 ifp->if_collisions += cue_csr_read_2(sc, CUE_TX_MULTICOLL); 545 ifp->if_collisions += cue_csr_read_2(sc, CUE_TX_EXCESSCOLL); 546 547 if (cue_csr_read_2(sc, CUE_RX_FRAMEERR)) 548 ifp->if_ierrors++; |
755} 756 757static void | 549} 550 551static void |
758cue_cfg_pre_init(struct cue_softc *sc, 759 struct usb2_config_td_cc *cc, uint16_t refcount) | 552cue_start(struct usb2_ether *ue) |
760{ | 553{ |
761 struct ifnet *ifp = sc->sc_ifp; | 554 struct cue_softc *sc = usb2_ether_getsc(ue); |
762 | 555 |
763 /* immediate configuration */ 764 765 cue_cfg_pre_stop(sc, cc, 0); 766 767 ifp->if_drv_flags |= IFF_DRV_RUNNING; 768 769 sc->sc_flags |= CUE_FLAG_HL_READY; | 556 /* 557 * start the USB transfers, if not already started: 558 */ 559 usb2_transfer_start(sc->sc_xfer[CUE_BULK_DT_RD]); 560 usb2_transfer_start(sc->sc_xfer[CUE_BULK_DT_WR]); |
770} 771 772static void | 561} 562 563static void |
773cue_cfg_init(struct cue_softc *sc, 774 struct usb2_config_td_cc *cc, uint16_t refcount) | 564cue_init(struct usb2_ether *ue) |
775{ | 565{ |
776 uint8_t i; | 566 struct cue_softc *sc = usb2_ether_getsc(ue); 567 struct ifnet *ifp = usb2_ether_getifp(ue); 568 int i; |
777 | 569 |
570 CUE_LOCK_ASSERT(sc, MA_OWNED); 571 |
|
778 /* 779 * Cancel pending I/O and free all RX/TX buffers. 780 */ | 572 /* 573 * Cancel pending I/O and free all RX/TX buffers. 574 */ |
781 cue_cfg_stop(sc, cc, 0); | 575 cue_stop(ue); |
782#if 0 | 576#if 0 |
783 cue_cfg_reset(sc); | 577 cue_reset(sc); |
784#endif 785 /* Set MAC address */ | 578#endif 579 /* Set MAC address */ |
580 for (i = 0; i < ETHER_ADDR_LEN; i++) 581 cue_csr_write_1(sc, CUE_PAR0 - i, IF_LLADDR(ifp)[i]); |
|
786 | 582 |
787 for (i = 0; i < ETHER_ADDR_LEN; i++) { 788 cue_cfg_csr_write_1(sc, CUE_PAR0 - i, cc->if_lladdr[i]); 789 } 790 | |
791 /* Enable RX logic. */ | 583 /* Enable RX logic. */ |
792 cue_cfg_csr_write_1(sc, CUE_ETHCTL, CUE_ETHCTL_RX_ON | CUE_ETHCTL_MCAST_ON); | 584 cue_csr_write_1(sc, CUE_ETHCTL, CUE_ETHCTL_RX_ON | CUE_ETHCTL_MCAST_ON); |
793 794 /* Load the multicast filter */ | 585 586 /* Load the multicast filter */ |
795 cue_cfg_promisc_upd(sc, cc, 0); | 587 cue_setpromisc(ue); |
796 797 /* 798 * Set the number of RX and TX buffers that we want 799 * to reserve inside the ASIC. 800 */ | 588 589 /* 590 * Set the number of RX and TX buffers that we want 591 * to reserve inside the ASIC. 592 */ |
801 cue_cfg_csr_write_1(sc, CUE_RX_BUFPKTS, CUE_RX_FRAMES); 802 cue_cfg_csr_write_1(sc, CUE_TX_BUFPKTS, CUE_TX_FRAMES); | 593 cue_csr_write_1(sc, CUE_RX_BUFPKTS, CUE_RX_FRAMES); 594 cue_csr_write_1(sc, CUE_TX_BUFPKTS, CUE_TX_FRAMES); |
803 804 /* Set advanced operation modes. */ | 595 596 /* Set advanced operation modes. */ |
805 cue_cfg_csr_write_1(sc, CUE_ADVANCED_OPMODES, | 597 cue_csr_write_1(sc, CUE_ADVANCED_OPMODES, |
806 CUE_AOP_EMBED_RXLEN | 0x01);/* 1 wait state */ 807 808 /* Program the LED operation. */ | 598 CUE_AOP_EMBED_RXLEN | 0x01);/* 1 wait state */ 599 600 /* Program the LED operation. */ |
809 cue_cfg_csr_write_1(sc, CUE_LEDCTL, CUE_LEDCTL_FOLLOW_LINK); | 601 cue_csr_write_1(sc, CUE_LEDCTL, CUE_LEDCTL_FOLLOW_LINK); |
810 | 602 |
811 sc->sc_flags |= (CUE_FLAG_READ_STALL | 812 CUE_FLAG_WRITE_STALL | 813 CUE_FLAG_LL_READY); | 603 usb2_transfer_set_stall(sc->sc_xfer[CUE_BULK_DT_WR]); |
814 | 604 |
815 cue_start_transfers(sc); | 605 ifp->if_drv_flags |= IFF_DRV_RUNNING; 606 cue_start(ue); |
816} 817 | 607} 608 |
818static int 819cue_ioctl_cb(struct ifnet *ifp, u_long command, caddr_t data) 820{ 821 struct cue_softc *sc = ifp->if_softc; 822 int error = 0; 823 824 switch (command) { 825 case SIOCSIFFLAGS: 826 mtx_lock(&sc->sc_mtx); 827 if (ifp->if_flags & IFF_UP) { 828 if (ifp->if_drv_flags & IFF_DRV_RUNNING) { 829 usb2_config_td_queue_command 830 (&sc->sc_config_td, &cue_config_copy, 831 &cue_cfg_promisc_upd, 0, 0); 832 } else { 833 usb2_config_td_queue_command 834 (&sc->sc_config_td, &cue_cfg_pre_init, 835 &cue_cfg_init, 0, 0); 836 } 837 } else { 838 if (ifp->if_drv_flags & IFF_DRV_RUNNING) { 839 usb2_config_td_queue_command 840 (&sc->sc_config_td, &cue_cfg_pre_stop, 841 &cue_cfg_stop, 0, 0); 842 } 843 } 844 mtx_unlock(&sc->sc_mtx); 845 break; 846 847 case SIOCADDMULTI: 848 case SIOCDELMULTI: 849 mtx_lock(&sc->sc_mtx); 850 usb2_config_td_queue_command 851 (&sc->sc_config_td, &cue_config_copy, 852 &cue_cfg_promisc_upd, 0, 0); 853 mtx_unlock(&sc->sc_mtx); 854 break; 855 856 default: 857 error = ether_ioctl(ifp, command, data); 858 break; 859 } 860 return (error); 861} 862 863static void 864cue_watchdog(void *arg) 865{ 866 struct cue_softc *sc = arg; 867 868 mtx_assert(&sc->sc_mtx, MA_OWNED); 869 870 usb2_config_td_queue_command 871 (&sc->sc_config_td, NULL, &cue_cfg_tick, 0, 0); 872 873 usb2_callout_reset(&sc->sc_watchdog, 874 hz, &cue_watchdog, sc); 875} 876 | |
877/* 878 * Stop the adapter and free any mbufs allocated to the 879 * RX and TX lists. 880 */ 881static void | 609/* 610 * Stop the adapter and free any mbufs allocated to the 611 * RX and TX lists. 612 */ 613static void |
882cue_cfg_pre_stop(struct cue_softc *sc, 883 struct usb2_config_td_cc *cc, uint16_t refcount) | 614cue_stop(struct usb2_ether *ue) |
884{ | 615{ |
885 struct ifnet *ifp = sc->sc_ifp; | 616 struct cue_softc *sc = usb2_ether_getsc(ue); 617 struct ifnet *ifp = usb2_ether_getifp(ue); |
886 | 618 |
887 if (cc) { 888 /* copy the needed configuration */ 889 cue_config_copy(sc, cc, refcount); 890 } 891 /* immediate configuration */ | 619 CUE_LOCK_ASSERT(sc, MA_OWNED); |
892 | 620 |
893 if (ifp) { 894 /* clear flags */ 895 ifp->if_drv_flags &= ~IFF_DRV_RUNNING; 896 } 897 sc->sc_flags &= ~(CUE_FLAG_HL_READY | 898 CUE_FLAG_LL_READY); | 621 ifp->if_drv_flags &= ~IFF_DRV_RUNNING; |
899 900 /* 901 * stop all the transfers, if not already stopped: 902 */ 903 usb2_transfer_stop(sc->sc_xfer[CUE_BULK_DT_WR]); 904 usb2_transfer_stop(sc->sc_xfer[CUE_BULK_DT_RD]); | 622 623 /* 624 * stop all the transfers, if not already stopped: 625 */ 626 usb2_transfer_stop(sc->sc_xfer[CUE_BULK_DT_WR]); 627 usb2_transfer_stop(sc->sc_xfer[CUE_BULK_DT_RD]); |
905 usb2_transfer_stop(sc->sc_xfer[CUE_BULK_CS_WR]); 906 usb2_transfer_stop(sc->sc_xfer[CUE_BULK_CS_RD]); 907} | |
908 | 628 |
909static void 910cue_cfg_stop(struct cue_softc *sc, 911 struct usb2_config_td_cc *cc, uint16_t refcount) 912{ 913 cue_cfg_csr_write_1(sc, CUE_ETHCTL, 0); 914 cue_cfg_reset(sc); | 629 cue_csr_write_1(sc, CUE_ETHCTL, 0); 630 cue_reset(sc); |
915} 916 917/* 918 * Stop all chip I/O so that the kernel's probe routines don't 919 * get confused by errant DMAs when rebooting. 920 */ 921static int 922cue_shutdown(device_t dev) 923{ 924 struct cue_softc *sc = device_get_softc(dev); 925 | 631} 632 633/* 634 * Stop all chip I/O so that the kernel's probe routines don't 635 * get confused by errant DMAs when rebooting. 636 */ 637static int 638cue_shutdown(device_t dev) 639{ 640 struct cue_softc *sc = device_get_softc(dev); 641 |
926 mtx_lock(&sc->sc_mtx); | 642 usb2_ether_ifshutdown(&sc->sc_ue); |
927 | 643 |
928 usb2_config_td_queue_command 929 (&sc->sc_config_td, &cue_cfg_pre_stop, 930 &cue_cfg_stop, 0, 0); 931 932 mtx_unlock(&sc->sc_mtx); 933 | |
934 return (0); 935} | 644 return (0); 645} |