1 /* $NetBSD: if_cue.c,v 1.91 2020/03/15 23:04:50 thorpej Exp $ */ 2 3 /* 4 * Copyright (c) 1997, 1998, 1999, 2000 5 * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by Bill Paul. 18 * 4. Neither the name of the author nor the names of any co-contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD 26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 * THE POSSIBILITY OF SUCH DAMAGE. 33 * 34 * $FreeBSD: src/sys/dev/usb/if_cue.c,v 1.4 2000/01/16 22:45:06 wpaul Exp $ 35 */ 36 37 /* 38 * CATC USB-EL1210A USB to ethernet driver. Used in the CATC Netmate 39 * adapters and others. 40 * 41 * Written by Bill Paul <wpaul@ee.columbia.edu> 42 * Electrical Engineering Department 43 * Columbia University, New York City 44 */ 45 46 /* 47 * The CATC USB-EL1210A provides USB ethernet support at 10Mbps. The 48 * RX filter uses a 512-bit multicast hash table, single perfect entry 49 * for the station address, and promiscuous mode. Unlike the ADMtek 50 * and KLSI chips, the CATC ASIC supports read and write combining 51 * mode where multiple packets can be transferred using a single bulk 52 * transaction, which helps performance a great deal. 53 */ 54 55 /* 56 * Ported to NetBSD and somewhat rewritten by Lennart Augustsson. 57 */ 58 59 #include <sys/cdefs.h> 60 __KERNEL_RCSID(0, "$NetBSD: if_cue.c,v 1.91 2020/03/15 23:04:50 thorpej Exp $"); 61 62 #ifdef _KERNEL_OPT 63 #include "opt_inet.h" 64 #include "opt_usb.h" 65 #endif 66 67 #include <sys/param.h> 68 69 #include <dev/usb/usbnet.h> 70 #include <dev/usb/if_cuereg.h> 71 72 #ifdef INET 73 #include <netinet/in.h> 74 #include <netinet/if_inarp.h> 75 #endif 76 77 #ifdef CUE_DEBUG 78 #define DPRINTF(x) if (cuedebug) printf x 79 #define DPRINTFN(n, x) if (cuedebug >= (n)) printf x 80 int cuedebug = 0; 81 #else 82 #define DPRINTF(x) 83 #define DPRINTFN(n, x) 84 #endif 85 86 #define CUE_BUFSZ 1536 87 #define CUE_MIN_FRAMELEN 60 88 #define CUE_RX_FRAMES 1 89 #define CUE_TX_FRAMES 1 90 91 #define CUE_CONFIG_NO 1 92 #define CUE_IFACE_IDX 0 93 94 #define CUE_RX_LIST_CNT 1 95 #define CUE_TX_LIST_CNT 1 96 97 struct cue_type { 98 uint16_t cue_vid; 99 uint16_t cue_did; 100 }; 101 102 struct cue_softc; 103 104 struct cue_chain { 105 struct cue_softc *cue_sc; 106 struct usbd_xfer *cue_xfer; 107 char *cue_buf; 108 struct mbuf *cue_mbuf; 109 int cue_idx; 110 }; 111 112 struct cue_cdata { 113 struct cue_chain cue_tx_chain[CUE_TX_LIST_CNT]; 114 struct cue_chain cue_rx_chain[CUE_RX_LIST_CNT]; 115 int cue_tx_prod; 116 int cue_tx_cnt; 117 }; 118 119 struct cue_softc { 120 struct usbnet cue_un; 121 uint8_t cue_mctab[CUE_MCAST_TABLE_LEN]; 122 }; 123 124 /* 125 * Various supported device vendors/products. 126 */ 127 static const struct usb_devno cue_devs[] = { 128 { USB_VENDOR_CATC, USB_PRODUCT_CATC_NETMATE }, 129 { USB_VENDOR_CATC, USB_PRODUCT_CATC_NETMATE2 }, 130 { USB_VENDOR_SMARTBRIDGES, USB_PRODUCT_SMARTBRIDGES_SMARTLINK }, 131 /* Belkin F5U111 adapter covered by NETMATE entry */ 132 }; 133 #define cue_lookup(v, p) (usb_lookup(cue_devs, v, p)) 134 135 static int cue_match(device_t, cfdata_t, void *); 136 static void cue_attach(device_t, device_t, void *); 137 138 CFATTACH_DECL_NEW(cue, sizeof(struct cue_softc), cue_match, cue_attach, 139 usbnet_detach, usbnet_activate); 140 141 static unsigned cue_uno_tx_prepare(struct usbnet *, struct mbuf *, 142 struct usbnet_chain *); 143 static void cue_uno_rx_loop(struct usbnet *, struct usbnet_chain *, uint32_t); 144 static int cue_uno_ioctl(struct ifnet *, u_long, void *); 145 static void cue_uno_stop(struct ifnet *, int); 146 static int cue_uno_init(struct ifnet *); 147 static void cue_uno_tick(struct usbnet *); 148 149 static const struct usbnet_ops cue_ops = { 150 .uno_stop = cue_uno_stop, 151 .uno_ioctl = cue_uno_ioctl, 152 .uno_tx_prepare = cue_uno_tx_prepare, 153 .uno_rx_loop = cue_uno_rx_loop, 154 .uno_init = cue_uno_init, 155 .uno_tick = cue_uno_tick, 156 }; 157 158 #ifdef CUE_DEBUG 159 static int 160 cue_csr_read_1(struct usbnet *un, int reg) 161 { 162 usb_device_request_t req; 163 usbd_status err; 164 uint8_t val = 0; 165 166 if (usbnet_isdying(un)) 167 return 0; 168 169 req.bmRequestType = UT_READ_VENDOR_DEVICE; 170 req.bRequest = CUE_CMD_READREG; 171 USETW(req.wValue, 0); 172 USETW(req.wIndex, reg); 173 USETW(req.wLength, 1); 174 175 err = usbd_do_request(un->un_udev, &req, &val); 176 177 if (err) { 178 DPRINTF(("%s: cue_csr_read_1: reg=%#x err=%s\n", 179 device_xname(un->un_dev), reg, usbd_errstr(err))); 180 return 0; 181 } 182 183 DPRINTFN(10,("%s: cue_csr_read_1 reg=%#x val=%#x\n", 184 device_xname(un->un_dev), reg, val)); 185 186 return val; 187 } 188 #endif 189 190 static int 191 cue_csr_read_2(struct usbnet *un, int reg) 192 { 193 usb_device_request_t req; 194 usbd_status err; 195 uWord val; 196 197 if (usbnet_isdying(un)) 198 return 0; 199 200 req.bmRequestType = UT_READ_VENDOR_DEVICE; 201 req.bRequest = CUE_CMD_READREG; 202 USETW(req.wValue, 0); 203 USETW(req.wIndex, reg); 204 USETW(req.wLength, 2); 205 206 err = usbd_do_request(un->un_udev, &req, &val); 207 208 DPRINTFN(10,("%s: cue_csr_read_2 reg=%#x val=%#x\n", 209 device_xname(un->un_dev), reg, UGETW(val))); 210 211 if (err) { 212 DPRINTF(("%s: cue_csr_read_2: reg=%#x err=%s\n", 213 device_xname(un->un_dev), reg, usbd_errstr(err))); 214 return 0; 215 } 216 217 return UGETW(val); 218 } 219 220 static int 221 cue_csr_write_1(struct usbnet *un, int reg, int val) 222 { 223 usb_device_request_t req; 224 usbd_status err; 225 226 if (usbnet_isdying(un)) 227 return 0; 228 229 DPRINTFN(10,("%s: cue_csr_write_1 reg=%#x val=%#x\n", 230 device_xname(un->un_dev), reg, val)); 231 232 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 233 req.bRequest = CUE_CMD_WRITEREG; 234 USETW(req.wValue, val); 235 USETW(req.wIndex, reg); 236 USETW(req.wLength, 0); 237 238 err = usbd_do_request(un->un_udev, &req, NULL); 239 240 if (err) { 241 DPRINTF(("%s: cue_csr_write_1: reg=%#x err=%s\n", 242 device_xname(un->un_dev), reg, usbd_errstr(err))); 243 return -1; 244 } 245 246 DPRINTFN(20,("%s: cue_csr_write_1, after reg=%#x val=%#x\n", 247 device_xname(un->un_dev), reg, cue_csr_read_1(un, reg))); 248 249 return 0; 250 } 251 252 #if 0 253 static int 254 cue_csr_write_2(struct usbnet *un, int reg, int aval) 255 { 256 usb_device_request_t req; 257 usbd_status err; 258 uWord val; 259 int s; 260 261 if (usbnet_isdying(un)) 262 return 0; 263 264 DPRINTFN(10,("%s: cue_csr_write_2 reg=%#x val=%#x\n", 265 device_xname(un->un_dev), reg, aval)); 266 267 USETW(val, aval); 268 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 269 req.bRequest = CUE_CMD_WRITEREG; 270 USETW(req.wValue, val); 271 USETW(req.wIndex, reg); 272 USETW(req.wLength, 0); 273 274 err = usbd_do_request(un->un_udev, &req, NULL); 275 276 if (err) { 277 DPRINTF(("%s: cue_csr_write_2: reg=%#x err=%s\n", 278 device_xname(un->un_dev), reg, usbd_errstr(err))); 279 return -1; 280 } 281 282 return 0; 283 } 284 #endif 285 286 static int 287 cue_mem(struct usbnet *un, int cmd, int addr, void *buf, int len) 288 { 289 usb_device_request_t req; 290 usbd_status err; 291 292 DPRINTFN(10,("%s: cue_mem cmd=%#x addr=%#x len=%d\n", 293 device_xname(un->un_dev), cmd, addr, len)); 294 295 if (cmd == CUE_CMD_READSRAM) 296 req.bmRequestType = UT_READ_VENDOR_DEVICE; 297 else 298 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 299 req.bRequest = cmd; 300 USETW(req.wValue, 0); 301 USETW(req.wIndex, addr); 302 USETW(req.wLength, len); 303 304 err = usbd_do_request(un->un_udev, &req, buf); 305 306 if (err) { 307 DPRINTF(("%s: cue_csr_mem: addr=%#x err=%s\n", 308 device_xname(un->un_dev), addr, usbd_errstr(err))); 309 return -1; 310 } 311 312 return 0; 313 } 314 315 static int 316 cue_getmac(struct usbnet *un) 317 { 318 usb_device_request_t req; 319 usbd_status err; 320 321 DPRINTFN(10,("%s: cue_getmac\n", device_xname(un->un_dev))); 322 323 req.bmRequestType = UT_READ_VENDOR_DEVICE; 324 req.bRequest = CUE_CMD_GET_MACADDR; 325 USETW(req.wValue, 0); 326 USETW(req.wIndex, 0); 327 USETW(req.wLength, ETHER_ADDR_LEN); 328 329 err = usbd_do_request(un->un_udev, &req, un->un_eaddr); 330 331 if (err) { 332 printf("%s: read MAC address failed\n", 333 device_xname(un->un_dev)); 334 return -1; 335 } 336 337 return 0; 338 } 339 340 #define CUE_POLY 0xEDB88320 341 #define CUE_BITS 9 342 343 static uint32_t 344 cue_crc(const char *addr) 345 { 346 uint32_t idx, bit, data, crc; 347 348 /* Compute CRC for the address value. */ 349 crc = 0xFFFFFFFF; /* initial value */ 350 351 for (idx = 0; idx < 6; idx++) { 352 for (data = *addr++, bit = 0; bit < 8; bit++, data >>= 1) 353 crc = (crc >> 1) ^ (((crc ^ data) & 1) ? CUE_POLY : 0); 354 } 355 356 return crc & ((1 << CUE_BITS) - 1); 357 } 358 359 static void 360 cue_setiff_locked(struct usbnet *un) 361 { 362 struct cue_softc *sc = usbnet_softc(un); 363 struct ethercom *ec = usbnet_ec(un); 364 struct ifnet *ifp = usbnet_ifp(un); 365 struct ether_multi *enm; 366 struct ether_multistep step; 367 uint32_t h, i; 368 369 DPRINTFN(2,("%s: cue_setiff if_flags=%#x\n", 370 device_xname(un->un_dev), ifp->if_flags)); 371 372 if (ifp->if_flags & IFF_PROMISC) { 373 allmulti: 374 ifp->if_flags |= IFF_ALLMULTI; 375 for (i = 0; i < CUE_MCAST_TABLE_LEN; i++) 376 sc->cue_mctab[i] = 0xFF; 377 cue_mem(un, CUE_CMD_WRITESRAM, CUE_MCAST_TABLE_ADDR, 378 &sc->cue_mctab, CUE_MCAST_TABLE_LEN); 379 return; 380 } 381 382 /* first, zot all the existing hash bits */ 383 for (i = 0; i < CUE_MCAST_TABLE_LEN; i++) 384 sc->cue_mctab[i] = 0; 385 386 /* now program new ones */ 387 ETHER_LOCK(ec); 388 ETHER_FIRST_MULTI(step, ec, enm); 389 while (enm != NULL) { 390 if (memcmp(enm->enm_addrlo, 391 enm->enm_addrhi, ETHER_ADDR_LEN) != 0) { 392 ETHER_UNLOCK(ec); 393 goto allmulti; 394 } 395 396 h = cue_crc(enm->enm_addrlo); 397 sc->cue_mctab[h >> 3] |= 1 << (h & 0x7); 398 ETHER_NEXT_MULTI(step, enm); 399 } 400 ETHER_UNLOCK(ec); 401 402 ifp->if_flags &= ~IFF_ALLMULTI; 403 404 /* 405 * Also include the broadcast address in the filter 406 * so we can receive broadcast frames. 407 */ 408 if (ifp->if_flags & IFF_BROADCAST) { 409 h = cue_crc(etherbroadcastaddr); 410 sc->cue_mctab[h >> 3] |= 1 << (h & 0x7); 411 } 412 413 cue_mem(un, CUE_CMD_WRITESRAM, CUE_MCAST_TABLE_ADDR, 414 &sc->cue_mctab, CUE_MCAST_TABLE_LEN); 415 } 416 417 static void 418 cue_reset(struct usbnet *un) 419 { 420 usb_device_request_t req; 421 usbd_status err; 422 423 DPRINTFN(2,("%s: cue_reset\n", device_xname(un->un_dev))); 424 425 if (usbnet_isdying(un)) 426 return; 427 428 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 429 req.bRequest = CUE_CMD_RESET; 430 USETW(req.wValue, 0); 431 USETW(req.wIndex, 0); 432 USETW(req.wLength, 0); 433 434 err = usbd_do_request(un->un_udev, &req, NULL); 435 436 if (err) 437 printf("%s: reset failed\n", device_xname(un->un_dev)); 438 439 /* Wait a little while for the chip to get its brains in order. */ 440 usbd_delay_ms(un->un_udev, 1); 441 } 442 443 /* 444 * Probe for a CATC chip. 445 */ 446 static int 447 cue_match(device_t parent, cfdata_t match, void *aux) 448 { 449 struct usb_attach_arg *uaa = aux; 450 451 return cue_lookup(uaa->uaa_vendor, uaa->uaa_product) != NULL ? 452 UMATCH_VENDOR_PRODUCT : UMATCH_NONE; 453 } 454 455 /* 456 * Attach the interface. Allocate softc structures, do ifmedia 457 * setup and ethernet/BPF attach. 458 */ 459 static void 460 cue_attach(device_t parent, device_t self, void *aux) 461 { 462 struct cue_softc *sc = device_private(self); 463 struct usbnet * const un = &sc->cue_un; 464 struct usb_attach_arg *uaa = aux; 465 char *devinfop; 466 struct usbd_device * dev = uaa->uaa_device; 467 usbd_status err; 468 usb_interface_descriptor_t *id; 469 usb_endpoint_descriptor_t *ed; 470 int i; 471 472 KASSERT((void *)sc == un); 473 474 DPRINTFN(5,(" : cue_attach: sc=%p, dev=%p", sc, dev)); 475 476 aprint_naive("\n"); 477 aprint_normal("\n"); 478 devinfop = usbd_devinfo_alloc(dev, 0); 479 aprint_normal_dev(self, "%s\n", devinfop); 480 usbd_devinfo_free(devinfop); 481 482 err = usbd_set_config_no(dev, CUE_CONFIG_NO, 1); 483 if (err) { 484 aprint_error_dev(self, "failed to set configuration" 485 ", err=%s\n", usbd_errstr(err)); 486 return; 487 } 488 489 un->un_dev = self; 490 un->un_udev = dev; 491 un->un_sc = sc; 492 un->un_ops = &cue_ops; 493 un->un_rx_xfer_flags = USBD_SHORT_XFER_OK; 494 un->un_tx_xfer_flags = USBD_FORCE_SHORT_XFER; 495 un->un_rx_list_cnt = CUE_RX_LIST_CNT; 496 un->un_tx_list_cnt = CUE_TX_LIST_CNT; 497 un->un_rx_bufsz = CUE_BUFSZ; 498 un->un_tx_bufsz = CUE_BUFSZ; 499 500 err = usbd_device2interface_handle(dev, CUE_IFACE_IDX, &un->un_iface); 501 if (err) { 502 aprint_error_dev(self, "getting interface handle failed\n"); 503 return; 504 } 505 506 id = usbd_get_interface_descriptor(un->un_iface); 507 508 /* Find endpoints. */ 509 for (i = 0; i < id->bNumEndpoints; i++) { 510 ed = usbd_interface2endpoint_descriptor(un->un_iface, i); 511 if (ed == NULL) { 512 aprint_error_dev(self, "couldn't get ep %d\n", i); 513 return; 514 } 515 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN && 516 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) { 517 un->un_ed[USBNET_ENDPT_RX] = ed->bEndpointAddress; 518 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT && 519 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) { 520 un->un_ed[USBNET_ENDPT_TX] = ed->bEndpointAddress; 521 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN && 522 UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) { 523 un->un_ed[USBNET_ENDPT_INTR] = ed->bEndpointAddress; 524 } 525 } 526 527 /* First level attach. */ 528 usbnet_attach(un, "cuedet"); 529 530 #if 0 531 /* Reset the adapter. */ 532 cue_reset(un); 533 #endif 534 /* 535 * Get station address. 536 */ 537 cue_getmac(un); 538 539 usbnet_attach_ifp(un, IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST, 540 0, NULL); 541 } 542 543 static void 544 cue_uno_tick(struct usbnet *un) 545 { 546 struct ifnet *ifp = usbnet_ifp(un); 547 548 usbnet_lock_core(un); 549 550 net_stat_ref_t nsr = IF_STAT_GETREF(ifp); 551 if (cue_csr_read_2(un, CUE_RX_FRAMEERR)) 552 if_statinc_ref(nsr, if_ierrors); 553 554 if_statadd_ref(nsr, if_collisions, 555 cue_csr_read_2(un, CUE_TX_SINGLECOLL)); 556 if_statadd_ref(nsr, if_collisions, 557 cue_csr_read_2(un, CUE_TX_MULTICOLL)); 558 if_statadd_ref(nsr, if_collisions, 559 cue_csr_read_2(un, CUE_TX_EXCESSCOLL)); 560 IF_STAT_PUTREF(ifp); 561 562 usbnet_unlock_core(un); 563 } 564 565 static void 566 cue_uno_rx_loop(struct usbnet *un, struct usbnet_chain *c, uint32_t total_len) 567 { 568 struct ifnet *ifp = usbnet_ifp(un); 569 uint8_t *buf = c->unc_buf; 570 uint16_t len; 571 572 DPRINTFN(5,("%s: %s: total_len=%d len=%d\n", 573 device_xname(un->un_dev), __func__, 574 total_len, le16dec(buf))); 575 576 len = UGETW(buf); 577 if (total_len < 2 || 578 len > total_len - 2 || 579 len < sizeof(struct ether_header)) { 580 if_statinc(ifp, if_ierrors); 581 return; 582 } 583 584 /* No errors; receive the packet. */ 585 usbnet_enqueue(un, buf + 2, len, 0, 0, 0); 586 } 587 588 static unsigned 589 cue_uno_tx_prepare(struct usbnet *un, struct mbuf *m, struct usbnet_chain *c) 590 { 591 unsigned total_len; 592 593 DPRINTFN(5,("%s: %s: mbuf len=%d\n", 594 device_xname(un->un_dev), __func__, 595 m->m_pkthdr.len)); 596 597 if ((unsigned)m->m_pkthdr.len > un->un_tx_bufsz - 2) 598 return 0; 599 600 /* 601 * Copy the mbuf data into a contiguous buffer, leaving two 602 * bytes at the beginning to hold the frame length. 603 */ 604 m_copydata(m, 0, m->m_pkthdr.len, c->unc_buf + 2); 605 606 total_len = m->m_pkthdr.len + 2; 607 608 /* The first two bytes are the frame length */ 609 c->unc_buf[0] = (uint8_t)m->m_pkthdr.len; 610 c->unc_buf[1] = (uint8_t)(m->m_pkthdr.len >> 8); 611 612 return total_len; 613 } 614 615 static int 616 cue_init_locked(struct ifnet *ifp) 617 { 618 struct usbnet * const un = ifp->if_softc; 619 int i, ctl; 620 const u_char *eaddr; 621 622 DPRINTFN(10,("%s: %s: enter\n", device_xname(un->un_dev),__func__)); 623 624 if (usbnet_isdying(un)) 625 return -1; 626 627 /* Cancel pending I/O */ 628 usbnet_stop(un, ifp, 1); 629 630 /* Reset the interface. */ 631 #if 1 632 cue_reset(un); 633 #endif 634 635 /* Set advanced operation modes. */ 636 cue_csr_write_1(un, CUE_ADVANCED_OPMODES, 637 CUE_AOP_EMBED_RXLEN | 0x03); /* 1 wait state */ 638 639 eaddr = CLLADDR(ifp->if_sadl); 640 /* Set MAC address */ 641 for (i = 0; i < ETHER_ADDR_LEN; i++) 642 cue_csr_write_1(un, CUE_PAR0 - i, eaddr[i]); 643 644 /* Enable RX logic. */ 645 ctl = CUE_ETHCTL_RX_ON | CUE_ETHCTL_MCAST_ON; 646 if (ifp->if_flags & IFF_PROMISC) 647 ctl |= CUE_ETHCTL_PROMISC; 648 cue_csr_write_1(un, CUE_ETHCTL, ctl); 649 650 /* Load the multicast filter. */ 651 cue_setiff_locked(un); 652 653 /* 654 * Set the number of RX and TX buffers that we want 655 * to reserve inside the ASIC. 656 */ 657 cue_csr_write_1(un, CUE_RX_BUFPKTS, CUE_RX_FRAMES); 658 cue_csr_write_1(un, CUE_TX_BUFPKTS, CUE_TX_FRAMES); 659 660 /* Set advanced operation modes. */ 661 cue_csr_write_1(un, CUE_ADVANCED_OPMODES, 662 CUE_AOP_EMBED_RXLEN | 0x01); /* 1 wait state */ 663 664 /* Program the LED operation. */ 665 cue_csr_write_1(un, CUE_LEDCTL, CUE_LEDCTL_FOLLOW_LINK); 666 667 return usbnet_init_rx_tx(un); 668 } 669 670 static int 671 cue_uno_init(struct ifnet *ifp) 672 { 673 struct usbnet * const un = ifp->if_softc; 674 int rv; 675 676 usbnet_lock_core(un); 677 usbnet_busy(un); 678 rv = cue_init_locked(ifp); 679 usbnet_unbusy(un); 680 usbnet_unlock_core(un); 681 682 return rv; 683 } 684 685 static int 686 cue_uno_ioctl(struct ifnet *ifp, u_long cmd, void *data) 687 { 688 struct usbnet * const un = ifp->if_softc; 689 690 usbnet_lock_core(un); 691 usbnet_busy(un); 692 693 switch (cmd) { 694 case SIOCADDMULTI: 695 case SIOCDELMULTI: 696 cue_setiff_locked(un); 697 break; 698 default: 699 break; 700 } 701 702 usbnet_unbusy(un); 703 usbnet_unlock_core(un); 704 705 return 0; 706 } 707 708 /* Stop and reset the adapter. */ 709 static void 710 cue_uno_stop(struct ifnet *ifp, int disable) 711 { 712 struct usbnet * const un = ifp->if_softc; 713 714 DPRINTFN(10,("%s: %s: enter\n", device_xname(un->un_dev), __func__)); 715 716 cue_csr_write_1(un, CUE_ETHCTL, 0); 717 cue_reset(un); 718 } 719 720 #ifdef _MODULE 721 #include "ioconf.c" 722 #endif 723 724 USBNET_MODULE(cue) 725