jcs's openbsd hax
openbsd

Add preliminary support for RTL8157.

Tested:
RTL8153 (0x5c20/0x5c30): stsp

kevlo 449dd8e0 1a842094

+703 -198
+9 -5
share/man/man4/ure.4
··· 1 - .\" $OpenBSD: ure.4,v 1.10 2023/05/06 08:14:26 kevlo Exp $ 1 + .\" $OpenBSD: ure.4,v 1.11 2025/05/23 03:06:09 kevlo Exp $ 2 2 .\" 3 3 .\" Copyright (c) 2015 Kevin Lo <kevlo@FreeBSD.org> 4 4 .\" All rights reserved. ··· 26 26 .\" 27 27 .\" $FreeBSD: head/share/man/man4/ure.4 291557 2015-12-01 05:12:13Z kevlo $ 28 28 .\" 29 - .Dd $Mdocdate: May 6 2023 $ 29 + .Dd $Mdocdate: May 23 2025 $ 30 30 .Dt URE 4 31 31 .Os 32 32 .Sh NAME 33 33 .Nm ure 34 - .Nd Realtek RTL8152/RTL8153/RTL8153B/RTL8153D/RTL8156 10/100/1Gb/2.5Gb USB Ethernet device 34 + .Nd Realtek RTL8152/RTL8153/RTL8156/RTL8157 10/100/1Gb/2.5Gb/5Gb \ 35 + USB Ethernet device 35 36 .Sh SYNOPSIS 36 37 .Cd "ure* at uhub?" 37 38 .Cd "rgephy* at mii?" ··· 40 41 The 41 42 .Nm 42 43 driver provides support for USB Ethernet adapters based on the Realtek 43 - RTL8152, RTL8153, RTL8153B, RTL8153D and RTL8156 chipsets. 44 + RTL8152, RTL8153, RTL8153B, RTL8153D, RTL8156, RTL8156B and RTL8157 chipsets. 44 45 .Pp 45 46 The RTL8152 contains an integrated Fast Ethernet MAC, which supports 46 47 both 10 and 100Mbps speeds in either full or half duplex. 47 48 The RTL8153, RTL8153B and RTL8153D have Gigabit Ethernet MACs and additionally 48 49 support 1000Mbps speeds. 49 - NICs based on the RTL8156 are capable of 10, 100, 1000 and 2500Mbps operation. 50 + NICs based on the RTL8156 and RTL8156B are capable of 10, 100, 1000 and 51 + 2500Mbps operation. 52 + The RTL8157 is a USB 3.0 device, which contains a 10/100/1Gb/2.5Gb/5Gb 53 + Ethernet MAC. 50 54 .Pp 51 55 For more information on configuring this device, see 52 56 .Xr ifconfig 8 .
+3 -3
share/man/man4/usb.4
··· 1 - .\" $OpenBSD: usb.4,v 1.221 2025/03/26 23:39:00 hastings Exp $ 1 + .\" $OpenBSD: usb.4,v 1.222 2025/05/23 03:06:09 kevlo Exp $ 2 2 .\" $NetBSD: usb.4,v 1.15 1999/07/29 14:20:32 augustss Exp $ 3 3 .\" 4 4 .\" Copyright (c) 1999 The NetBSD Foundation, Inc. ··· 28 28 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 29 .\" POSSIBILITY OF SUCH DAMAGE. 30 30 .\" 31 - .Dd $Mdocdate: March 26 2025 $ 31 + .Dd $Mdocdate: May 23 2025 $ 32 32 .Dt USB 4 33 33 .Os 34 34 .Sh NAME ··· 138 138 .It Xr udav 4 139 139 Davicom DM9601 10/100 USB Ethernet device 140 140 .It Xr ure 4 141 - Realtek RTL8152/RTL8153/RTL8153B/RTL8153D/RTL8156 10/100/1Gb/2.5Gb USB Ethernet device 141 + Realtek RTL8152/RTL8153/RTL8156/RTL8157 10/100/1Gb/2.5Gb/5Gb USB Ethernet device 142 142 .It Xr url 4 143 143 Realtek RTL8150L 10/100 USB Ethernet device 144 144 .It Xr urndis 4
+627 -184
sys/dev/usb/if_ure.c
··· 1 - /* $OpenBSD: if_ure.c,v 1.35 2024/05/23 03:21:09 jsg Exp $ */ 1 + /* $OpenBSD: if_ure.c,v 1.36 2025/05/23 03:06:09 kevlo Exp $ */ 2 2 /*- 3 3 * Copyright (c) 2015, 2016, 2019 Kevin Lo <kevlo@openbsd.org> 4 4 * Copyright (c) 2020 Jonathon Fletcher <jonathon.fletcher@gmail.com> ··· 119 119 { USB_VENDOR_REALTEK, USB_PRODUCT_REALTEK_RTL8152B }, 120 120 { USB_VENDOR_REALTEK, USB_PRODUCT_REALTEK_RTL8153 }, 121 121 { USB_VENDOR_REALTEK, USB_PRODUCT_REALTEK_RTL8156 }, 122 + { USB_VENDOR_REALTEK, USB_PRODUCT_REALTEK_RTL8157 }, 122 123 { USB_VENDOR_SAMSUNG2, USB_PRODUCT_SAMSUNG2_RTL8153 }, 123 124 { USB_VENDOR_TOSHIBA, USB_PRODUCT_TOSHIBA_RTL8153B }, 124 125 { USB_VENDOR_TPLINK, USB_PRODUCT_TPLINK_EU300 }, ··· 156 157 int ure_write_4(struct ure_softc *, uint16_t, uint16_t, uint32_t); 157 158 uint16_t ure_ocp_reg_read(struct ure_softc *, uint16_t); 158 159 void ure_ocp_reg_write(struct ure_softc *, uint16_t, uint16_t); 160 + uint16_t ure_rtl8157_ocp_reg_read(struct ure_softc *, uint16_t); 161 + void ure_rtl8157_ocp_reg_write(struct ure_softc *, uint16_t, 162 + uint16_t); 163 + uint32_t ure_ocp_cmd_read(struct ure_softc *, uint16_t, int); 164 + void ure_ocp_cmd_write(struct ure_softc *, uint16_t, int, uint32_t); 159 165 160 166 void ure_init(void *); 161 167 void ure_stop(struct ure_softc *); ··· 169 175 void ure_lock_mii(struct ure_softc *); 170 176 void ure_unlock_mii(struct ure_softc *); 171 177 172 - int ure_encap_txpkt(struct mbuf *, char *, uint32_t); 178 + void ure_decap(struct ure_softc *, struct ure_chain *, uint32_t); 179 + int ure_encap_txpkt(struct ure_softc *, struct mbuf *, char *, 180 + uint32_t); 173 181 int ure_encap_xfer(struct ifnet *, struct ure_softc *, 174 182 struct ure_chain *); 183 + void ure_rxcsum(struct ure_rxpkt *, struct mbuf *); 184 + void ure_rxcsum_v2(struct ure_rxpkt_v2 *, struct mbuf *); 175 185 void ure_rxeof(struct usbd_xfer *, void *, usbd_status); 176 186 void ure_txeof(struct usbd_xfer *, void *, usbd_status); 177 187 int ure_xfer_list_init(struct ure_softc *, struct ure_chain *, ··· 191 201 void ure_rxvlan(struct ure_softc *); 192 202 int ure_ioctl(struct ifnet *, u_long, caddr_t); 193 203 void ure_rtl8152_init(struct ure_softc *); 194 - void ure_rtl8153_init(struct ure_softc *); 195 - void ure_rtl8153b_init(struct ure_softc *); 196 - void ure_rtl8152_nic_reset(struct ure_softc *); 197 - void ure_rtl8153_nic_reset(struct ure_softc *); 204 + int ure_rtl8153_init(struct ure_softc *); 205 + int ure_rtl8153b_init(struct ure_softc *); 206 + int ure_rtl8157_init(struct ure_softc *); 207 + int ure_rtl8152_nic_reset(struct ure_softc *); 208 + int ure_rtl8153_nic_reset(struct ure_softc *); 198 209 uint16_t ure_rtl8153_phy_status(struct ure_softc *, int); 199 - void ure_wait_for_flash(struct ure_softc *); 210 + int ure_wait_for_flash(struct ure_softc *); 200 211 void ure_reset_bmu(struct ure_softc *); 201 212 void ure_disable_teredo(struct ure_softc *); 202 213 203 - #define URE_SETBIT_1(sc, reg, index, x) \ 214 + #define URE_SETBIT_1(sc, reg, index, x) \ 204 215 ure_write_1(sc, reg, index, ure_read_1(sc, reg, index) | (x)) 205 - #define URE_SETBIT_2(sc, reg, index, x) \ 216 + #define URE_SETBIT_2(sc, reg, index, x) \ 206 217 ure_write_2(sc, reg, index, ure_read_2(sc, reg, index) | (x)) 207 - #define URE_SETBIT_4(sc, reg, index, x) \ 218 + #define URE_SETBIT_4(sc, reg, index, x) \ 208 219 ure_write_4(sc, reg, index, ure_read_4(sc, reg, index) | (x)) 209 220 210 - #define URE_CLRBIT_1(sc, reg, index, x) \ 221 + #define URE_CLRBIT_1(sc, reg, index, x) \ 211 222 ure_write_1(sc, reg, index, ure_read_1(sc, reg, index) & ~(x)) 212 - #define URE_CLRBIT_2(sc, reg, index, x) \ 223 + #define URE_CLRBIT_2(sc, reg, index, x) \ 213 224 ure_write_2(sc, reg, index, ure_read_2(sc, reg, index) & ~(x)) 214 - #define URE_CLRBIT_4(sc, reg, index, x) \ 225 + #define URE_CLRBIT_4(sc, reg, index, x) \ 215 226 ure_write_4(sc, reg, index, ure_read_4(sc, reg, index) & ~(x)) 227 + 228 + #define URE_OCP_CMD_SETBIT(sc, addr, type, x) \ 229 + ure_ocp_cmd_write(sc, addr, type, \ 230 + ure_ocp_cmd_read(sc, addr, type) | (x)) 231 + 232 + #define URE_OCP_CMD_CLRBIT(sc, addr, type, x) \ 233 + ure_ocp_cmd_write(sc, addr, type, \ 234 + ure_ocp_cmd_read(sc, addr, type) & ~(x)) 216 235 217 236 int 218 237 ure_ctl(struct ure_softc *sc, uint8_t rw, uint16_t val, uint16_t index, ··· 352 371 return (ure_write_mem(sc, reg, index | URE_BYTE_EN_DWORD, &temp, 4)); 353 372 } 354 373 374 + inline uint16_t 375 + ure_phy_read(struct ure_softc *sc, uint16_t addr) 376 + { 377 + return sc->ure_phy_read(sc, addr); 378 + } 379 + 380 + inline void 381 + ure_phy_write(struct ure_softc *sc, uint16_t addr, uint16_t data) 382 + { 383 + return sc->ure_phy_write(sc, addr, data); 384 + } 385 + 355 386 uint16_t 356 387 ure_ocp_reg_read(struct ure_softc *sc, uint16_t addr) 357 388 { ··· 374 405 ure_write_2(sc, reg, URE_MCU_TYPE_PLA, data); 375 406 } 376 407 408 + uint16_t 409 + ure_rtl8157_ocp_reg_read(struct ure_softc *sc, uint16_t addr) 410 + { 411 + int i; 412 + 413 + for (i = 0; i < 10; i++) { 414 + if (!(ure_read_2(sc, URE_USB_TGPHY_CMD, URE_MCU_TYPE_USB) & 415 + URE_TGPHY_CMD_BUSY)) 416 + break; 417 + usbd_delay_ms(sc->ure_udev, 1); 418 + } 419 + if (i == 10) { 420 + printf("%s: PHY read timeout\n", sc->ure_dev.dv_xname); 421 + return (0xffff); 422 + } 423 + 424 + ure_write_2(sc, URE_USB_TGPHY_ADDR, URE_MCU_TYPE_USB, addr); 425 + ure_write_2(sc, URE_USB_TGPHY_CMD, URE_MCU_TYPE_USB, 426 + URE_TGPHY_CMD_BUSY); 427 + 428 + for (i = 0; i < 10; i++) { 429 + if (!(ure_read_2(sc, URE_USB_TGPHY_CMD, URE_MCU_TYPE_USB) & 430 + URE_TGPHY_CMD_BUSY)) 431 + break; 432 + usbd_delay_ms(sc->ure_udev, 1); 433 + } 434 + if (i == 10) { 435 + printf("%s: PHY read timeout\n", sc->ure_dev.dv_xname); 436 + return (0xffff); 437 + } 438 + 439 + return (ure_read_2(sc, URE_USB_TGPHY_DATA, URE_MCU_TYPE_USB)); 440 + } 441 + 442 + void 443 + ure_rtl8157_ocp_reg_write(struct ure_softc *sc, uint16_t addr, uint16_t data) 444 + { 445 + int i; 446 + 447 + ure_write_2(sc, URE_USB_TGPHY_DATA, URE_MCU_TYPE_USB, data); 448 + 449 + ure_write_2(sc, URE_USB_TGPHY_ADDR, URE_MCU_TYPE_USB, addr); 450 + ure_write_2(sc, URE_USB_TGPHY_CMD, URE_MCU_TYPE_USB, 451 + URE_TGPHY_CMD_BUSY | URE_TGPHY_CMD_WRITE); 452 + 453 + for (i = 0; i < 10; i++) { 454 + if (!(ure_read_2(sc, URE_USB_TGPHY_CMD, URE_MCU_TYPE_USB) & 455 + URE_TGPHY_CMD_BUSY)) 456 + break; 457 + usbd_delay_ms(sc->ure_udev, 1); 458 + } 459 + if (i == 10) 460 + printf("%s: PHY write timeout\n", sc->ure_dev.dv_xname); 461 + } 462 + 463 + uint32_t 464 + ure_ocp_cmd_read(struct ure_softc *sc, uint16_t addr, int type) 465 + { 466 + uint16_t cmd; 467 + int i; 468 + 469 + cmd = (type == URE_CMD_TYPE_BMU) ? URE_CMD_BMU : URE_CMD_IP; 470 + 471 + for (i = 0; i < 10; i++) { 472 + if (!(ure_read_2(sc, URE_USB_CMD, URE_MCU_TYPE_USB) & 473 + URE_CMD_BUSY)) 474 + break; 475 + usbd_delay_ms(sc->ure_udev, 1); 476 + } 477 + if (i == 10) 478 + printf("%s: timeout waiting for read command\n", 479 + sc->ure_dev.dv_xname); 480 + 481 + ure_write_2(sc, URE_USB_CMD_ADDR, URE_MCU_TYPE_USB, addr); 482 + ure_write_2(sc, URE_USB_CMD, URE_MCU_TYPE_USB, cmd | URE_CMD_BUSY); 483 + 484 + for (i = 0; i < 10; i++) { 485 + if (!(ure_read_2(sc, URE_USB_CMD, URE_MCU_TYPE_USB) & 486 + URE_CMD_BUSY)) 487 + break; 488 + usbd_delay_ms(sc->ure_udev, 1); 489 + } 490 + if (i == 10) 491 + printf("%s: timeout waiting for read command\n", 492 + sc->ure_dev.dv_xname); 493 + 494 + return (ure_read_4(sc, URE_USB_CMD_DATA, URE_MCU_TYPE_USB)); 495 + } 496 + 497 + void 498 + ure_ocp_cmd_write(struct ure_softc *sc, uint16_t addr, int type, uint32_t data) 499 + { 500 + uint16_t cmd; 501 + int i; 502 + 503 + cmd = (type == URE_CMD_TYPE_BMU) ? URE_CMD_BMU : URE_CMD_IP; 504 + 505 + for (i = 0; i < 10; i++) { 506 + if (!(ure_read_2(sc, URE_USB_CMD, URE_MCU_TYPE_USB) & 507 + URE_CMD_BUSY)) 508 + break; 509 + usbd_delay_ms(sc->ure_udev, 1); 510 + } 511 + if (i == 10) 512 + printf("%s: timeout waiting for write command\n", 513 + sc->ure_dev.dv_xname); 514 + 515 + ure_write_4(sc, URE_USB_CMD_DATA, URE_MCU_TYPE_USB, data); 516 + 517 + ure_write_2(sc, URE_USB_CMD_ADDR, URE_MCU_TYPE_USB, addr); 518 + ure_write_2(sc, URE_USB_CMD, URE_MCU_TYPE_USB, 519 + cmd | URE_CMD_BUSY | URE_CMD_WRITE); 520 + } 521 + 377 522 int 378 523 ure_miibus_readreg(struct device *dev, int phy, int reg) 379 524 { ··· 388 533 return ure_read_1(sc, URE_PLA_PHYSTATUS, URE_MCU_TYPE_PLA); 389 534 390 535 ure_lock_mii(sc); 391 - val = ure_ocp_reg_read(sc, URE_OCP_BASE_MII + reg * 2); 536 + val = ure_phy_read(sc, URE_OCP_BASE_MII + reg * 2); 392 537 ure_unlock_mii(sc); 393 538 394 539 return val; /* letoh16? */ ··· 400 545 struct ure_softc *sc = (void *)dev; 401 546 402 547 ure_lock_mii(sc); 403 - ure_ocp_reg_write(sc, URE_OCP_BASE_MII + reg * 2, val); /* htole16? */ 548 + ure_phy_write(sc, URE_OCP_BASE_MII + reg * 2, val); /* htole16? */ 404 549 ure_unlock_mii(sc); 405 550 } 406 551 ··· 457 602 ure_write_1(sc, URE_PLA_CRWECR, URE_MCU_TYPE_PLA, URE_CRWECR_NORAML); 458 603 459 604 if (!(sc->ure_flags & URE_FLAG_8152)) { 460 - if (sc->ure_flags & URE_FLAG_8156B) 605 + if (sc->ure_flags & (URE_FLAG_8156B | URE_FLAG_8157)) 461 606 URE_CLRBIT_2(sc, URE_USB_RX_AGGR_NUM, URE_MCU_TYPE_USB, 462 607 URE_RX_AGGR_NUM_MASK); 463 608 464 - reg = sc->ure_rxbufsz - URE_FRAMELEN(ifp->if_mtu) - 465 - sizeof(struct ure_rxpkt) - URE_RX_BUF_ALIGN; 609 + reg = sc->ure_rxbufsz - URE_FRAMELEN(ifp->if_mtu); 610 + if (sc->ure_flags & URE_FLAG_8157) 611 + reg -= sizeof(struct ure_rxpkt_v2) + URE_8157_BUF_ALIGN; 612 + else 613 + reg -= sizeof(struct ure_rxpkt) + URE_RX_BUF_ALIGN; 614 + 466 615 if (sc->ure_flags & 467 - (URE_FLAG_8153B | URE_FLAG_8156 | URE_FLAG_8156B)) { 616 + (URE_FLAG_8153B | URE_FLAG_8156 | URE_FLAG_8156B | 617 + URE_FLAG_8157)) { 468 618 ure_write_2(sc, URE_USB_RX_EARLY_SIZE, URE_MCU_TYPE_USB, 469 - reg / 8); 619 + (sc->ure_flags & URE_FLAG_8157) ? 620 + reg / URE_8157_BUF_ALIGN : reg / URE_RX_BUF_ALIGN); 470 621 471 622 ure_write_2(sc, URE_USB_RX_EARLY_AGG, URE_MCU_TYPE_USB, 472 623 (sc->ure_flags & URE_FLAG_8153B) ? 158 : 80); 473 624 ure_write_2(sc, URE_USB_PM_CTRL_STATUS, 474 625 URE_MCU_TYPE_USB, 1875); 626 + 627 + if (sc->ure_udev->speed == USB_SPEED_HIGH) { 628 + reg = ure_read_2(sc, URE_USB_L1_CTRL, 629 + URE_MCU_TYPE_USB); 630 + reg &= ~0x0f; 631 + ure_write_2(sc, URE_USB_L1_CTRL, 632 + URE_MCU_TYPE_USB, reg | 0x01); 633 + } 475 634 } else { 476 635 ure_write_2(sc, URE_USB_RX_EARLY_SIZE, URE_MCU_TYPE_USB, 477 636 reg / 4); ··· 512 671 /* Enable transmit and receive. */ 513 672 URE_SETBIT_1(sc, URE_PLA_CR, URE_MCU_TYPE_PLA, URE_CR_RE | URE_CR_TE); 514 673 515 - if (sc->ure_flags & (URE_FLAG_8153B | URE_FLAG_8156 | URE_FLAG_8156B)) { 674 + if (sc->ure_flags & 675 + (URE_FLAG_8153B | URE_FLAG_8156 | URE_FLAG_8156B | URE_FLAG_8157)) { 516 676 ure_write_1(sc, URE_USB_UPT_RXDMA_OWN, URE_MCU_TYPE_USB, 517 677 URE_OWN_UPDATE | URE_OWN_CLEAR); 518 678 } ··· 528 688 struct ifmedia *ifm = &sc->ure_ifmedia; 529 689 int anar, gig, err, reg; 530 690 531 - if (sc->ure_flags & (URE_FLAG_8156 | URE_FLAG_8156B)) { 691 + if (sc->ure_flags & (URE_FLAG_8156 | URE_FLAG_8156B | URE_FLAG_8157)) { 532 692 if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER) 533 693 return (EINVAL); 534 694 535 695 if (!(sc->ure_chip & URE_CHIP_VER_7420)) { 536 - reg = ure_ocp_reg_read(sc, URE_OCP_10GBT_CTRL); 696 + reg = ure_phy_read(sc, URE_OCP_10GBT_CTRL); 697 + if (reg == 0xffff) 698 + return (EINVAL); 537 699 reg &= ~URE_ADV_2500TFDX; 538 700 } 701 + if (sc->ure_flags & URE_FLAG_8157) 702 + reg &= ~URE_ADV_5000TFDX; 539 703 540 - anar = gig = 0; 704 + anar = ANAR_TX_FD | ANAR_TX | ANAR_10_FD | ANAR_10; 705 + gig = GTCR_ADV_1000TFDX | GTCR_ADV_1000THDX; 706 + 541 707 switch (IFM_SUBTYPE(ifm->ifm_media)) { 542 708 case IFM_AUTO: 543 - anar |= ANAR_TX_FD | ANAR_TX | ANAR_10_FD | ANAR_10; 544 - gig |= GTCR_ADV_1000TFDX | GTCR_ADV_1000THDX; 545 709 if (!(sc->ure_chip & URE_CHIP_VER_7420)) 546 710 reg |= URE_ADV_2500TFDX; 711 + if (sc->ure_flags & URE_FLAG_8157) 712 + reg |= URE_ADV_5000TFDX; 713 + break; 714 + case IFM_5000_T: 715 + reg |= URE_ADV_2500TFDX | URE_ADV_5000TFDX; 716 + ifp->if_baudrate = IF_Gbps(5); 547 717 break; 548 718 case IFM_2500_T: 549 - anar |= ANAR_TX_FD | ANAR_TX | ANAR_10_FD | ANAR_10; 550 - gig |= GTCR_ADV_1000TFDX | GTCR_ADV_1000THDX; 551 719 reg |= URE_ADV_2500TFDX; 552 720 ifp->if_baudrate = IF_Mbps(2500); 553 721 break; 554 722 case IFM_1000_T: 555 - anar |= ANAR_TX_FD | ANAR_TX | ANAR_10_FD | ANAR_10; 556 - gig |= GTCR_ADV_1000TFDX | GTCR_ADV_1000THDX; 557 723 ifp->if_baudrate = IF_Gbps(1); 558 724 break; 559 725 case IFM_100_TX: 560 - anar |= ANAR_TX | ANAR_TX_FD; 726 + anar &= ~(ANAR_10_FD | ANAR_10); 727 + gig = 0; 561 728 ifp->if_baudrate = IF_Mbps(100); 562 729 break; 563 730 case IFM_10_T: 564 - anar |= ANAR_10 | ANAR_10_FD; 731 + anar &= ~(ANAR_TX_FD | ANAR_TX); 732 + gig = 0; 565 733 ifp->if_baudrate = IF_Mbps(10); 566 734 break; 567 735 default: ··· 570 738 return (EINVAL); 571 739 } 572 740 573 - ure_ocp_reg_write(sc, URE_OCP_BASE_MII + MII_ANAR * 2, 741 + ure_phy_write(sc, URE_OCP_BASE_MII + MII_ANAR * 2, 574 742 anar | ANAR_PAUSE_ASYM | ANAR_FC); 575 - ure_ocp_reg_write(sc, URE_OCP_BASE_MII + MII_100T2CR * 2, gig); 743 + ure_phy_write(sc, URE_OCP_BASE_MII + MII_100T2CR * 2, gig); 576 744 if (!(sc->ure_chip & URE_CHIP_VER_7420)) 577 - ure_ocp_reg_write(sc, URE_OCP_10GBT_CTRL, reg); 578 - ure_ocp_reg_write(sc, URE_OCP_BASE_MII + MII_BMCR, 745 + ure_phy_write(sc, URE_OCP_10GBT_CTRL, reg); 746 + ure_phy_write(sc, URE_OCP_BASE_MII + MII_BMCR, 579 747 BMCR_AUTOEN | BMCR_STARTNEG); 580 748 581 749 return (0); ··· 601 769 struct mii_data *mii = &sc->ure_mii; 602 770 uint16_t status = 0; 603 771 604 - if (sc->ure_flags & (URE_FLAG_8156 | URE_FLAG_8156B)) { 772 + if (sc->ure_flags & (URE_FLAG_8156 | URE_FLAG_8156B | URE_FLAG_8157)) { 605 773 ifmr->ifm_status = IFM_AVALID; 606 774 if (ure_get_link_status(sc)) { 607 775 ifmr->ifm_status |= IFM_ACTIVE; 776 + ifmr->ifm_active = IFM_ETHER; 608 777 status = ure_read_2(sc, URE_PLA_PHYSTATUS, 609 778 URE_MCU_TYPE_PLA); 610 779 if ((status & URE_PHYSTATUS_FDX) || 611 - (status & URE_PHYSTATUS_2500MBPS)) 780 + (status & URE_PHYSTATUS_2500MBPS) || 781 + (status & URE_PHYSTATUS_5000MBPS)) 612 782 ifmr->ifm_active |= IFM_FDX; 613 783 else 614 784 ifmr->ifm_active |= IFM_HDX; ··· 620 790 ifmr->ifm_active |= IFM_1000_T; 621 791 else if (status & URE_PHYSTATUS_2500MBPS) 622 792 ifmr->ifm_active |= IFM_2500_T; 793 + else if (status & URE_PHYSTATUS_5000MBPS) 794 + ifmr->ifm_active |= IFM_5000_T; 623 795 } 624 796 return; 625 797 } ··· 645 817 ifmedia_add(&sc->ure_ifmedia, IFM_ETHER | IFM_2500_T | IFM_FDX, 646 818 0, NULL); 647 819 } 820 + if (sc->ure_flags & URE_FLAG_8157) { 821 + ifmedia_add(&sc->ure_ifmedia, IFM_ETHER | IFM_5000_T, 0, NULL); 822 + ifmedia_add(&sc->ure_ifmedia, IFM_ETHER | IFM_5000_T | IFM_FDX, 823 + 0, NULL); 824 + } 648 825 } 649 826 650 827 void ··· 653 830 struct ifnet *ifp = &sc->ure_ac.ac_if; 654 831 int link = LINK_STATE_DOWN; 655 832 656 - if (ure_get_link_status(sc)) 833 + if (ure_get_link_status(sc)) { 657 834 link = LINK_STATE_UP; 835 + /* Enable transmit and receive. */ 836 + URE_SETBIT_1(sc, URE_PLA_CR, URE_MCU_TYPE_PLA, 837 + URE_CR_RE | URE_CR_TE); 838 + } 658 839 659 840 if (ifp->if_link_state != link) { 660 841 ifp->if_link_state = link; ··· 735 916 struct ifnet *ifp = &sc->ure_ac.ac_if; 736 917 uint16_t reg; 737 918 738 - if (sc->ure_flags & (URE_FLAG_8156 | URE_FLAG_8156B)) { 919 + if (sc->ure_flags & (URE_FLAG_8156 | URE_FLAG_8156B | URE_FLAG_8157)) { 739 920 reg = ure_read_2(sc, URE_PLA_RCR1, URE_MCU_TYPE_PLA); 740 921 reg &= ~(URE_INNER_VLAN | URE_OUTER_VLAN); 741 922 if (ifp->if_capabilities & IFCAP_VLAN_HWTAGGING) ··· 755 936 { 756 937 int i; 757 938 758 - if (sc->ure_flags & URE_FLAG_8156) { 939 + if (sc->ure_flags & URE_FLAG_8157) 940 + URE_CLRBIT_1(sc, URE_PLA_CR, URE_MCU_TYPE_PLA, 941 + URE_CR_TE | URE_CR_RE); 942 + else if (sc->ure_flags & URE_FLAG_8156) { 759 943 URE_CLRBIT_1(sc, URE_PLA_CR, URE_MCU_TYPE_PLA, URE_CR_TE); 760 944 URE_CLRBIT_2(sc, URE_USB_BMU_RESET, URE_MCU_TYPE_USB, 761 945 BMU_RESET_EP_IN); ··· 824 1008 struct ure_chain *c; 825 1009 struct ifnet *ifp = &sc->ure_ac.ac_if; 826 1010 usbd_status err; 827 - int s, i; 1011 + int s, i, error; 828 1012 829 1013 s = splnet(); 830 1014 ··· 832 1016 ure_stop(sc); 833 1017 834 1018 if (sc->ure_flags & URE_FLAG_8152) 835 - ure_rtl8152_nic_reset(sc); 1019 + error = ure_rtl8152_nic_reset(sc); 836 1020 else 837 - ure_rtl8153_nic_reset(sc); 1021 + error = ure_rtl8153_nic_reset(sc); 1022 + 1023 + if (error != 0) { 1024 + splx(s); 1025 + return; 1026 + } 838 1027 839 1028 if (ure_xfer_list_init(sc, sc->ure_cdata.ure_rx_chain, 840 1029 sc->ure_rxbufsz, URE_RX_LIST_CNT) == ENOBUFS) { ··· 910 1099 struct ure_cdata *cd = &sc->ure_cdata; 911 1100 struct ure_chain *c; 912 1101 struct mbuf *m = NULL; 913 - uint32_t new_buflen; 1102 + uint32_t descsize, new_buflen; 914 1103 int s, mlen; 915 1104 916 1105 if (!(sc->ure_flags & URE_FLAG_LINK) || ··· 929 1118 930 1119 mlen = m->m_pkthdr.len; 931 1120 1121 + descsize = (sc->ure_flags & URE_FLAG_8157) ? 1122 + sizeof(struct ure_txpkt_v2) : sizeof(struct ure_txpkt); 932 1123 /* Discard packet larger than buffer. */ 933 - if (mlen + sizeof(struct ure_txpkt) >= c->uc_bufmax) { 1124 + if (mlen + descsize >= c->uc_bufmax) { 934 1125 ifq_deq_commit(&ifp->if_snd, m); 935 1126 m_freem(m); 936 1127 ifp->if_oerrors++; ··· 941 1132 * If packet larger than remaining space, send buffer and 942 1133 * continue. 943 1134 */ 944 - new_buflen = roundup(c->uc_buflen, URE_TX_BUF_ALIGN); 945 - if (new_buflen + sizeof(struct ure_txpkt) + mlen >= 946 - c->uc_bufmax) { 1135 + new_buflen = roundup(c->uc_buflen, 1136 + (sc->ure_flags & URE_FLAG_8157) ? 1137 + URE_8157_BUF_ALIGN : URE_TX_BUF_ALIGN); 1138 + if (new_buflen + descsize + mlen >= c->uc_bufmax) { 947 1139 ifq_deq_rollback(&ifp->if_snd, m); 948 1140 SLIST_REMOVE_HEAD(&cd->ure_tx_free, uc_list); 949 1141 if (ure_encap_xfer(ifp, sc, c)) { ··· 956 1148 } 957 1149 958 1150 /* Append packet to current buffer. */ 959 - mlen = ure_encap_txpkt(m, c->uc_buf + new_buflen, 1151 + mlen = ure_encap_txpkt(sc, m, c->uc_buf + new_buflen, 960 1152 c->uc_bufmax - new_buflen); 961 1153 if (mlen <= 0) { 962 1154 ifq_deq_rollback(&ifp->if_snd, m); ··· 1100 1292 uint32_t pwrctrl; 1101 1293 1102 1294 /* Disable ALDPS. */ 1103 - ure_ocp_reg_write(sc, URE_OCP_ALDPS_CONFIG, URE_ENPDNPS | URE_LINKENA | 1295 + ure_phy_write(sc, URE_OCP_ALDPS_CONFIG, URE_ENPDNPS | URE_LINKENA | 1104 1296 URE_DIS_SDSAVE); 1105 1297 usbd_delay_ms(sc->ure_udev, 20); 1106 1298 ··· 1129 1321 URE_RX_AGG_DISABLE | URE_RX_ZERO_EN); 1130 1322 } 1131 1323 1132 - void 1324 + int 1133 1325 ure_rtl8153_init(struct ure_softc *sc) 1134 1326 { 1135 1327 uint16_t reg; ··· 1146 1338 break; 1147 1339 usbd_delay_ms(sc->ure_udev, 20); 1148 1340 } 1149 - if (i == 500) 1341 + if (i == 500) { 1150 1342 printf("%s: timeout waiting for chip autoload\n", 1151 1343 sc->ure_dev.dv_xname); 1344 + return (ETIMEDOUT); 1345 + } 1152 1346 1153 1347 ure_rtl8153_phy_status(sc, 0); 1154 1348 1155 1349 if (sc->ure_chip & (URE_CHIP_VER_5C00 | URE_CHIP_VER_5C10 | 1156 1350 URE_CHIP_VER_5C20)) { 1157 - ure_ocp_reg_write(sc, URE_OCP_ADC_CFG, 1351 + ure_phy_write(sc, URE_OCP_ADC_CFG, 1158 1352 URE_CKADSEL_L | URE_ADC_EN | URE_EN_EMI_L); 1159 1353 } 1160 1354 ··· 1223 1417 URE_RX_AGG_DISABLE | URE_RX_ZERO_EN); 1224 1418 1225 1419 URE_SETBIT_2(sc, URE_PLA_RSTTALLY, URE_MCU_TYPE_PLA, URE_TALLY_RESET); 1420 + 1421 + return (0); 1226 1422 } 1227 1423 1228 - void 1424 + int 1229 1425 ure_rtl8153b_init(struct ure_softc *sc) 1230 1426 { 1231 1427 uint16_t reg; ··· 1245 1441 1246 1442 URE_CLRBIT_2(sc, URE_USB_LPM_CONFIG, URE_MCU_TYPE_USB, LPM_U1U2_EN); 1247 1443 1248 - if (sc->ure_flags & URE_FLAG_8156B) 1249 - ure_wait_for_flash(sc); 1444 + if (sc->ure_flags & URE_FLAG_8156B) { 1445 + if (ure_wait_for_flash(sc) != 0) 1446 + return (ETIMEDOUT); 1447 + } 1250 1448 1251 1449 for (i = 0; i < 500; i++) { 1252 1450 if (ure_read_2(sc, URE_PLA_BOOT_CTRL, URE_MCU_TYPE_PLA) & ··· 1254 1452 break; 1255 1453 usbd_delay_ms(sc->ure_udev, 20); 1256 1454 } 1257 - if (i == 500) 1455 + if (i == 500) { 1258 1456 printf("%s: timeout waiting for chip autoload\n", 1259 1457 sc->ure_dev.dv_xname); 1458 + return (ETIMEDOUT); 1459 + } 1260 1460 1261 1461 ure_rtl8153_phy_status(sc, 0); 1262 1462 ure_rtl8153_phy_status(sc, URE_PHY_STAT_LAN_ON); ··· 1327 1527 URE_FC_PATCH_TASK); 1328 1528 } 1329 1529 1330 - /* MAC clock speed down. */ 1331 1530 if (sc->ure_flags & (URE_FLAG_8156 | URE_FLAG_8156B)) { 1332 - ure_write_2(sc, URE_PLA_MAC_PWR_CTRL, URE_MCU_TYPE_PLA, 0x0403); 1333 - reg = ure_read_2(sc, URE_PLA_MAC_PWR_CTRL2, URE_MCU_TYPE_PLA); 1334 - reg &= ~URE_EEE_SPDWN_RATIO_MASK; 1335 - reg |= URE_MAC_CLK_SPDWN_EN | 0x0003; 1336 - ure_write_2(sc, URE_PLA_MAC_PWR_CTRL2, URE_MCU_TYPE_PLA, reg); 1337 - 1531 + /* MAC clock speed down. */ 1338 1532 URE_CLRBIT_2(sc, URE_PLA_MAC_PWR_CTRL3, URE_MCU_TYPE_PLA, 1339 1533 URE_PLA_MCU_SPDWN_EN); 1340 1534 1341 1535 reg = ure_read_2(sc, URE_PLA_EXTRA_STATUS, URE_MCU_TYPE_PLA); 1536 + reg &= ~URE_CUR_LINK_OK; 1342 1537 if (ure_read_2(sc, URE_PLA_PHYSTATUS, URE_MCU_TYPE_PLA) & 1343 1538 URE_PHYSTATUS_LINK) 1344 1539 reg |= URE_CUR_LINK_OK; 1345 - else 1346 - reg &= ~URE_CUR_LINK_OK; 1347 1540 ure_write_2(sc, URE_PLA_EXTRA_STATUS, URE_MCU_TYPE_PLA, 1348 1541 reg | URE_POLL_LINK_CHG); 1349 1542 } else ··· 1364 1557 * 0: MDIO force mode 1365 1558 * 1: MMD force mode 1366 1559 */ 1367 - reg = ure_ocp_reg_read(sc, 0xa5b4); 1368 - if (reg & 0x8000) 1369 - ure_ocp_reg_write(sc, 0xa5b4, reg & ~0x8000); 1560 + ure_phy_write(sc, 0xa5b4, 1561 + ure_phy_read(sc, 0xa5b4) & ~0x8000); 1370 1562 } 1371 1563 1372 1564 URE_SETBIT_2(sc, URE_PLA_RSTTALLY, URE_MCU_TYPE_PLA, URE_TALLY_RESET); 1565 + 1566 + return (0); 1373 1567 } 1374 1568 1375 - void 1569 + int 1570 + ure_rtl8157_init(struct ure_softc *sc) 1571 + { 1572 + uint16_t reg; 1573 + int i; 1574 + 1575 + URE_SETBIT_1(sc, 0xcffe, URE_MCU_TYPE_USB, 0x0008); 1576 + URE_CLRBIT_1(sc, 0xd3ca, URE_MCU_TYPE_USB, 0x0001); 1577 + URE_CLRBIT_1(sc, URE_USB_ECM_OP, URE_MCU_TYPE_USB, URE_EN_ALL_SPEED); 1578 + URE_SETBIT_2(sc, URE_USB_ECM_OPTION, URE_MCU_TYPE_USB, 1579 + URE_BYPASS_MAC_RESET); 1580 + URE_SETBIT_2(sc, URE_USB_U2P3_CTRL, URE_MCU_TYPE_USB, URE_RX_DETECT8); 1581 + 1582 + URE_CLRBIT_2(sc, URE_USB_LPM_CONFIG, URE_MCU_TYPE_USB, LPM_U1U2_EN); 1583 + 1584 + for (i = 0; i < 500; i++) { 1585 + if (ure_read_2(sc, URE_PLA_BOOT_CTRL, URE_MCU_TYPE_PLA) & 1586 + URE_AUTOLOAD_DONE) 1587 + break; 1588 + usbd_delay_ms(sc->ure_udev, 20); 1589 + } 1590 + if (i == 500) { 1591 + printf("%s: timeout waiting for chip autoload\n", 1592 + sc->ure_dev.dv_xname); 1593 + return (ETIMEDOUT); 1594 + } 1595 + 1596 + if (ure_wait_for_flash(sc) != 0) 1597 + return (ETIMEDOUT); 1598 + 1599 + ure_rtl8153_phy_status(sc, 0); 1600 + ure_rtl8153_phy_status(sc, URE_PHY_STAT_LAN_ON); 1601 + 1602 + URE_OCP_CMD_CLRBIT(sc, URE_USB_U2P3_CTRL2, URE_CMD_TYPE_IP, 1603 + URE_U2P3_CTRL2_ENABLE); 1604 + 1605 + /* Disable interrupt mitigation. */ 1606 + URE_CLRBIT_1(sc, 0xcf04, URE_MCU_TYPE_USB, 0x87); 1607 + 1608 + URE_CLRBIT_2(sc, URE_USB_SPEED_OPTION, URE_MCU_TYPE_USB, 1609 + URE_RG_PWRDN_EN | URE_ALL_SPEED_OFF); 1610 + 1611 + /* Enable auto speed up. */ 1612 + URE_SETBIT_2(sc, URE_USB_FW_CTRL, URE_MCU_TYPE_USB, URE_AUTO_SPEEDUP); 1613 + 1614 + /* MSC timer = 4095 * 8ms = 32760 ms. */ 1615 + ure_write_2(sc, URE_USB_MSC_TIMER, URE_MCU_TYPE_USB, 4095); 1616 + 1617 + /* U1/U2/L1 idle timer, 500 us. */ 1618 + ure_write_2(sc, URE_USB_U1U2_TIMER, URE_MCU_TYPE_USB, 500); 1619 + 1620 + URE_CLRBIT_2(sc, URE_USB_POWER_CUT, URE_MCU_TYPE_USB, URE_PWR_EN); 1621 + URE_CLRBIT_2(sc, URE_USB_MISC_0, URE_MCU_TYPE_USB, URE_PCUT_STATUS); 1622 + URE_CLRBIT_1(sc, URE_USB_MISC_2, URE_MCU_TYPE_USB, 0x02); 1623 + 1624 + URE_CLRBIT_1(sc, URE_PLA_INDICATE_FALG, URE_MCU_TYPE_PLA, 1625 + URE_UPCOMING_RUNTIME_D3); 1626 + URE_CLRBIT_1(sc, URE_PLA_SUSPEND_FLAG, URE_MCU_TYPE_PLA, 1627 + URE_LINK_CHG_EVENT); 1628 + URE_CLRBIT_2(sc, URE_PLA_EXTRA_STATUS, URE_MCU_TYPE_PLA, 1629 + URE_LINK_CHANGE_FLAG); 1630 + 1631 + ure_write_1(sc, URE_PLA_CRWECR, URE_MCU_TYPE_PLA, URE_CRWECR_CONFIG); 1632 + URE_CLRBIT_2(sc, URE_PLA_CONFIG34, URE_MCU_TYPE_PLA, 1633 + URE_LINK_OFF_WAKE_EN); 1634 + ure_write_1(sc, URE_PLA_CRWECR, URE_MCU_TYPE_PLA, URE_CRWECR_NORAML); 1635 + 1636 + URE_CLRBIT_2(sc, URE_PLA_RCR, URE_MCU_TYPE_PLA, URE_SLOT_EN); 1637 + URE_SETBIT_2(sc, URE_PLA_CPCR, URE_MCU_TYPE_PLA, URE_FLOW_CTRL_EN); 1638 + 1639 + /* Enable fc timer and set timer to 600 ms. */ 1640 + ure_write_2(sc, URE_USB_FC_TIMER, URE_MCU_TYPE_USB, 1641 + URE_CTRL_TIMER_EN | 75); 1642 + 1643 + reg = ure_read_2(sc, URE_USB_FW_CTRL, URE_MCU_TYPE_USB); 1644 + reg &= ~URE_AUTO_SPEEDUP; 1645 + if (!(ure_read_2(sc, URE_PLA_POL_GPIO_CTRL, URE_MCU_TYPE_PLA) & 1646 + URE_DACK_DET_EN)) 1647 + reg |= URE_FLOW_CTRL_PATCH_2; 1648 + ure_write_2(sc, URE_USB_FW_CTRL, URE_MCU_TYPE_USB, reg); 1649 + 1650 + URE_SETBIT_2(sc, URE_USB_FW_TASK, URE_MCU_TYPE_USB, URE_FC_PATCH_TASK); 1651 + 1652 + /* Disable bypass_turn_off_clk_in_aldps. */ 1653 + URE_CLRBIT_1(sc, 0xd3c8, URE_MCU_TYPE_PLA, 0x01); 1654 + 1655 + /* MAC clock speed down. */ 1656 + URE_CLRBIT_2(sc, URE_PLA_MAC_PWR_CTRL3, URE_MCU_TYPE_PLA, 1657 + URE_PLA_MCU_SPDWN_EN); 1658 + 1659 + reg = ure_read_2(sc, URE_PLA_EXTRA_STATUS, URE_MCU_TYPE_PLA); 1660 + reg &= ~URE_CUR_LINK_OK; 1661 + if (ure_read_2(sc, URE_PLA_PHYSTATUS, URE_MCU_TYPE_PLA) & 1662 + URE_PHYSTATUS_LINK) 1663 + reg |= URE_CUR_LINK_OK; 1664 + ure_write_2(sc, URE_PLA_EXTRA_STATUS, URE_MCU_TYPE_PLA, 1665 + reg | URE_POLL_LINK_CHG); 1666 + 1667 + /* Enable Rx aggregation. */ 1668 + URE_CLRBIT_2(sc, URE_USB_USB_CTRL, URE_MCU_TYPE_USB, 1669 + URE_RX_AGG_DISABLE | 0x0400); 1670 + 1671 + /* Disable Rx zero len. */ 1672 + URE_OCP_CMD_CLRBIT(sc, 0x2300, URE_CMD_TYPE_BMU, 0x00000008); 1673 + 1674 + URE_CLRBIT_1(sc, 0xd4ae, URE_MCU_TYPE_USB, 0x02); 1675 + 1676 + reg = ure_phy_read(sc, 0xa5b4); 1677 + if (reg == 0xffff) 1678 + return (EINVAL); 1679 + ure_phy_write(sc, 0xa5b4, reg & ~0x8000); 1680 + 1681 + URE_SETBIT_2(sc, URE_PLA_RSTTALLY, URE_MCU_TYPE_PLA, URE_TALLY_RESET); 1682 + 1683 + return (0); 1684 + } 1685 + 1686 + int 1376 1687 ure_rtl8152_nic_reset(struct ure_softc *sc) 1377 1688 { 1378 1689 uint32_t rx_fifo1, rx_fifo2; 1379 1690 int i; 1380 1691 1381 1692 /* Disable ALDPS. */ 1382 - ure_ocp_reg_write(sc, URE_OCP_ALDPS_CONFIG, URE_ENPDNPS | URE_LINKENA | 1693 + ure_phy_write(sc, URE_OCP_ALDPS_CONFIG, URE_ENPDNPS | URE_LINKENA | 1383 1694 URE_DIS_SDSAVE); 1384 1695 usbd_delay_ms(sc->ure_udev, 20); 1385 1696 ··· 1398 1709 break; 1399 1710 usbd_delay_ms(sc->ure_udev, 1); 1400 1711 } 1401 - if (i == URE_TIMEOUT) 1712 + if (i == URE_TIMEOUT) { 1402 1713 printf("%s: timeout waiting for OOB control\n", 1403 1714 sc->ure_dev.dv_xname); 1715 + return (ETIMEDOUT); 1716 + } 1404 1717 URE_SETBIT_2(sc, URE_PLA_SFF_STS_7, URE_MCU_TYPE_PLA, URE_RE_INIT_LL); 1405 1718 for (i = 0; i < URE_TIMEOUT; i++) { 1406 1719 if (ure_read_1(sc, URE_PLA_OOB_CTRL, URE_MCU_TYPE_PLA) & ··· 1408 1721 break; 1409 1722 usbd_delay_ms(sc->ure_udev, 1); 1410 1723 } 1411 - if (i == URE_TIMEOUT) 1724 + if (i == URE_TIMEOUT) { 1412 1725 printf("%s: timeout waiting for OOB control\n", 1413 1726 sc->ure_dev.dv_xname); 1727 + return (ETIMEDOUT); 1728 + } 1414 1729 1415 1730 ure_reset(sc); 1416 1731 ··· 1443 1758 URE_SETBIT_2(sc, URE_PLA_TCR0, URE_MCU_TYPE_PLA, URE_TCR0_AUTO_FIFO); 1444 1759 1445 1760 /* Enable ALDPS. */ 1446 - ure_ocp_reg_write(sc, URE_OCP_ALDPS_CONFIG, 1761 + ure_phy_write(sc, URE_OCP_ALDPS_CONFIG, 1447 1762 URE_ENPWRSAVE | URE_ENPDNPS | URE_LINKENA | URE_DIS_SDSAVE); 1763 + 1764 + return (0); 1448 1765 } 1449 1766 1450 - void 1767 + int 1451 1768 ure_rtl8153_nic_reset(struct ure_softc *sc) 1452 1769 { 1453 1770 struct ifnet *ifp = &sc->ure_ac.ac_if; ··· 1455 1772 uint8_t u1u2[8] = { 0 }; 1456 1773 int i; 1457 1774 1458 - if (sc->ure_flags & (URE_FLAG_8153B | URE_FLAG_8156 | URE_FLAG_8156B)) { 1775 + switch (sc->ure_flags & URE_FLAG_CHIP_MASK) { 1776 + case URE_FLAG_8153B: 1777 + case URE_FLAG_8156: 1778 + case URE_FLAG_8156B: 1779 + case URE_FLAG_8157: 1459 1780 URE_CLRBIT_2(sc, URE_USB_LPM_CONFIG, URE_MCU_TYPE_USB, 1460 1781 LPM_U1U2_EN); 1461 - } else { 1782 + break; 1783 + default: 1462 1784 memset(u1u2, 0x00, sizeof(u1u2)); 1463 1785 ure_write_mem(sc, URE_USB_TOLERANCE, URE_BYTE_EN_SIX_BYTES, 1464 1786 u1u2, sizeof(u1u2)); 1787 + break; 1465 1788 } 1466 1789 URE_CLRBIT_2(sc, URE_USB_U2P3_CTRL, URE_MCU_TYPE_USB, URE_U2P3_ENABLE); 1467 1790 1468 1791 /* Disable ALDPS. */ 1469 - ure_ocp_reg_write(sc, URE_OCP_POWER_CFG, 1470 - ure_ocp_reg_read(sc, URE_OCP_POWER_CFG) & ~URE_EN_ALDPS); 1792 + ure_phy_write(sc, URE_OCP_POWER_CFG, 1793 + ure_phy_read(sc, URE_OCP_POWER_CFG) & ~URE_EN_ALDPS); 1471 1794 for (i = 0; i < 20; i++) { 1472 1795 usbd_delay_ms(sc->ure_udev, 1); 1473 1796 if (ure_read_2(sc, 0xe000, URE_MCU_TYPE_PLA) & 0x0100) ··· 1485 1808 URE_CLRBIT_1(sc, URE_PLA_OOB_CTRL, URE_MCU_TYPE_PLA, URE_NOW_IS_OOB); 1486 1809 URE_CLRBIT_2(sc, URE_PLA_SFF_STS_7, URE_MCU_TYPE_PLA, URE_MCU_BORW_EN); 1487 1810 1488 - if (!(sc->ure_flags & (URE_FLAG_8156 | URE_FLAG_8156B))) { 1811 + if (!(sc->ure_flags & 1812 + (URE_FLAG_8156 | URE_FLAG_8156B | URE_FLAG_8157))) { 1489 1813 for (i = 0; i < URE_TIMEOUT; i++) { 1490 1814 if (ure_read_1(sc, URE_PLA_OOB_CTRL, URE_MCU_TYPE_PLA) & 1491 1815 URE_LINK_LIST_READY) 1492 1816 break; 1493 1817 usbd_delay_ms(sc->ure_udev, 1); 1494 1818 } 1495 - if (i == URE_TIMEOUT) 1819 + if (i == URE_TIMEOUT) { 1496 1820 printf("%s: timeout waiting for OOB control\n", 1497 1821 sc->ure_dev.dv_xname); 1822 + return (ETIMEDOUT); 1823 + } 1498 1824 URE_SETBIT_2(sc, URE_PLA_SFF_STS_7, URE_MCU_TYPE_PLA, 1499 1825 URE_RE_INIT_LL); 1500 1826 for (i = 0; i < URE_TIMEOUT; i++) { ··· 1503 1829 break; 1504 1830 usbd_delay_ms(sc->ure_udev, 1); 1505 1831 } 1506 - if (i == URE_TIMEOUT) 1832 + if (i == URE_TIMEOUT) { 1507 1833 printf("%s: timeout waiting for OOB control\n", 1508 1834 sc->ure_dev.dv_xname); 1835 + return (ETIMEDOUT); 1836 + } 1509 1837 } 1510 1838 1511 1839 ure_rxvlan(sc); 1512 1840 1513 1841 ure_write_2(sc, URE_PLA_RMS, URE_MCU_TYPE_PLA, 1514 1842 URE_FRAMELEN(ifp->if_mtu)); 1515 - ure_write_1(sc, URE_PLA_MTPS, URE_MCU_TYPE_PLA, MTPS_JUMBO); 1843 + ure_write_1(sc, URE_PLA_MTPS, URE_MCU_TYPE_PLA, 1844 + (sc->ure_flags & URE_FLAG_8157) ? MTPS_MAX : MTPS_JUMBO); 1516 1845 1517 - if (sc->ure_flags & (URE_FLAG_8156 | URE_FLAG_8156B)) { 1846 + if (sc->ure_flags & (URE_FLAG_8156 | URE_FLAG_8156B | URE_FLAG_8157)) { 1518 1847 ure_write_2(sc, URE_PLA_RX_FIFO_FULL, URE_MCU_TYPE_PLA, 1519 1848 (sc->ure_flags & URE_FLAG_8156) ? 1024 : 512); 1520 1849 ure_write_2(sc, URE_PLA_RX_FIFO_EMPTY, URE_MCU_TYPE_PLA, ··· 1537 1866 URE_CLRBIT_2(sc, URE_PLA_MAC_PWR_CTRL3, URE_MCU_TYPE_PLA, 1538 1867 URE_PLA_MCU_SPDWN_EN); 1539 1868 1540 - URE_CLRBIT_2(sc, URE_USB_SPEED_OPTION, URE_MCU_TYPE_USB, 1541 - URE_RG_PWRDN_EN | URE_ALL_SPEED_OFF); 1869 + if (!(sc->ure_flags & URE_FLAG_8157)) 1870 + URE_CLRBIT_2(sc, URE_USB_SPEED_OPTION, URE_MCU_TYPE_USB, 1871 + URE_RG_PWRDN_EN | URE_ALL_SPEED_OFF); 1542 1872 1543 1873 ure_write_4(sc, URE_USB_RX_BUF_TH, URE_MCU_TYPE_USB, 1544 1874 0x00600400); ··· 1576 1906 } 1577 1907 1578 1908 /* Enable ALDPS. */ 1579 - ure_ocp_reg_write(sc, URE_OCP_POWER_CFG, 1580 - ure_ocp_reg_read(sc, URE_OCP_POWER_CFG) | URE_EN_ALDPS); 1909 + ure_phy_write(sc, URE_OCP_POWER_CFG, 1910 + ure_phy_read(sc, URE_OCP_POWER_CFG) | URE_EN_ALDPS); 1581 1911 1912 + if (sc->ure_flags & URE_FLAG_8157) { 1913 + /* Clear SDR. */ 1914 + URE_SETBIT_1(sc, 0xd378, URE_MCU_TYPE_USB, 0x0080); 1915 + URE_CLRBIT_2(sc, 0xcd06, URE_MCU_TYPE_USB, 0x8000); 1916 + } 1582 1917 if ((sc->ure_chip & (URE_CHIP_VER_5C20 | URE_CHIP_VER_5C30)) || 1583 1918 (sc->ure_flags & (URE_FLAG_8156 | URE_FLAG_8156B))) 1584 1919 URE_SETBIT_2(sc, URE_USB_U2P3_CTRL, URE_MCU_TYPE_USB, ··· 1588 1923 if (sc->ure_udev->speed == USB_SPEED_SUPER) 1589 1924 URE_SETBIT_2(sc, URE_USB_LPM_CONFIG, URE_MCU_TYPE_USB, 1590 1925 LPM_U1U2_EN); 1591 - } else { 1926 + } else if (!(sc->ure_flags & URE_FLAG_8157)) { 1592 1927 memset(u1u2, 0xff, sizeof(u1u2)); 1593 1928 ure_write_mem(sc, URE_USB_TOLERANCE, URE_BYTE_EN_SIX_BYTES, 1594 1929 u1u2, sizeof(u1u2)); 1595 1930 } 1931 + 1932 + return (0); 1596 1933 } 1597 1934 1598 1935 uint16_t ··· 1602 1939 int i; 1603 1940 1604 1941 for (i = 0; i < 500; i++) { 1605 - reg = ure_ocp_reg_read(sc, URE_OCP_PHY_STATUS) & 1942 + reg = ure_phy_read(sc, URE_OCP_PHY_STATUS) & 1606 1943 URE_PHY_STAT_MASK; 1607 1944 if (desired) { 1608 1945 if (reg == desired) ··· 1622 1959 return reg; 1623 1960 } 1624 1961 1625 - void 1962 + int 1626 1963 ure_wait_for_flash(struct ure_softc *sc) 1627 1964 { 1628 1965 int i; ··· 1635 1972 if (ure_read_2(sc, URE_USB_GPHY_CTRL, 1636 1973 URE_MCU_TYPE_USB) & URE_GPHY_PATCH_DONE) 1637 1974 break; 1638 - DELAY(1000); 1975 + usbd_delay_ms(sc->ure_udev, 1); 1639 1976 } 1640 - if (i == 100) 1977 + if (i == 100) { 1641 1978 printf("%s: timeout waiting for loading flash\n", 1642 1979 sc->ure_dev.dv_xname); 1980 + return (ETIMEDOUT); 1981 + } 1643 1982 } 1983 + 1984 + return (0); 1644 1985 } 1645 1986 1646 1987 void ··· 1648 1989 { 1649 1990 uint8_t reg; 1650 1991 1651 - reg = ure_read_1(sc, URE_USB_BMU_RESET, URE_MCU_TYPE_USB); 1652 - reg &= ~(BMU_RESET_EP_IN | BMU_RESET_EP_OUT); 1653 - ure_write_1(sc, URE_USB_BMU_RESET, URE_MCU_TYPE_USB, reg); 1654 - reg |= BMU_RESET_EP_IN | BMU_RESET_EP_OUT; 1655 - ure_write_1(sc, URE_USB_BMU_RESET, URE_MCU_TYPE_USB, reg); 1992 + if (sc->ure_flags & URE_FLAG_8157) { 1993 + URE_OCP_CMD_SETBIT(sc, 0x2350, URE_CMD_TYPE_BMU, 0x00000002); 1994 + URE_OCP_CMD_SETBIT(sc, 0x2360, URE_CMD_TYPE_BMU, 0x00000001); 1995 + URE_OCP_CMD_SETBIT(sc, 0x2350, URE_CMD_TYPE_BMU, 0x00000001); 1996 + URE_OCP_CMD_SETBIT(sc, 0x2450, URE_CMD_TYPE_BMU, 0x00000002); 1997 + URE_OCP_CMD_SETBIT(sc, 0x2460, URE_CMD_TYPE_BMU, 0x00000001); 1998 + URE_OCP_CMD_SETBIT(sc, 0x2450, URE_CMD_TYPE_BMU, 0x00000001); 1999 + } else { 2000 + reg = ure_read_1(sc, URE_USB_BMU_RESET, URE_MCU_TYPE_USB); 2001 + reg &= ~(BMU_RESET_EP_IN | BMU_RESET_EP_OUT); 2002 + ure_write_1(sc, URE_USB_BMU_RESET, URE_MCU_TYPE_USB, reg); 2003 + reg |= BMU_RESET_EP_IN | BMU_RESET_EP_OUT; 2004 + ure_write_1(sc, URE_USB_BMU_RESET, URE_MCU_TYPE_USB, reg); 2005 + } 1656 2006 } 1657 2007 1658 2008 void 1659 2009 ure_disable_teredo(struct ure_softc *sc) 1660 2010 { 1661 - if (sc->ure_flags & (URE_FLAG_8153B | URE_FLAG_8156 | URE_FLAG_8156B)) 2011 + if (sc->ure_flags & 2012 + (URE_FLAG_8153B | URE_FLAG_8156 | URE_FLAG_8156B | URE_FLAG_8157)) 1662 2013 ure_write_1(sc, URE_PLA_TEREDO_CFG, URE_MCU_TYPE_PLA, 0xff); 1663 2014 else { 1664 2015 URE_CLRBIT_2(sc, URE_PLA_TEREDO_CFG, URE_MCU_TYPE_PLA, ··· 1700 2051 1701 2052 case SIOCGIFMEDIA: 1702 2053 case SIOCSIFMEDIA: 1703 - if (sc->ure_flags & (URE_FLAG_8156 | URE_FLAG_8156B)) 2054 + if (sc->ure_flags & 2055 + (URE_FLAG_8156 | URE_FLAG_8156B | URE_FLAG_8157)) 1704 2056 error = ifmedia_ioctl(ifp, ifr, &sc->ure_ifmedia, cmd); 1705 2057 else 1706 2058 error = ifmedia_ioctl(ifp, ifr, &sc->ure_mii.mii_media, ··· 1776 2128 s = splnet(); 1777 2129 1778 2130 sc->ure_phyno = 0; 2131 + sc->ure_phy_read = ure_ocp_reg_read; 2132 + sc->ure_phy_write = ure_ocp_reg_write; 1779 2133 printf("%s: ", sc->ure_dev.dv_xname); 1780 2134 1781 2135 ver = ure_read_2(sc, URE_PLA_TCR1, URE_MCU_TYPE_PLA) & URE_VERSION_MASK; 1782 2136 switch (ver) { 2137 + case 0x1030: 2138 + sc->ure_flags = URE_FLAG_8157; 2139 + sc->ure_txbufsz = URE_8156_TX_BUFSZ; 2140 + sc->ure_phy_read = ure_rtl8157_ocp_reg_read; 2141 + sc->ure_phy_write = ure_rtl8157_ocp_reg_write; 2142 + printf("RTL8157 (0x1030)"); 2143 + break; 1783 2144 case 0x4c00: 1784 2145 sc->ure_flags = URE_FLAG_8152; 1785 2146 sc->ure_rxbufsz = URE_8152_RX_BUFSZ; ··· 1818 2179 break; 1819 2180 case 0x7020: 1820 2181 sc->ure_flags = URE_FLAG_8156; 2182 + sc->ure_txbufsz = URE_8156_TX_BUFSZ; 1821 2183 printf("RTL8156 (0x7020)"); 1822 2184 break; 1823 2185 case 0x7030: 1824 2186 sc->ure_flags = URE_FLAG_8156; 2187 + sc->ure_txbufsz = URE_8156_TX_BUFSZ; 1825 2188 printf("RTL8156 (0x7030)"); 1826 2189 break; 1827 2190 case 0x7410: 1828 2191 sc->ure_flags = URE_FLAG_8156B; 2192 + sc->ure_txbufsz = URE_8156_TX_BUFSZ; 1829 2193 printf("RTL8156B (0x7410)"); 1830 2194 break; 1831 2195 case 0x7420: ··· 1838 2202 break; 1839 2203 } 1840 2204 1841 - if (sc->ure_flags & URE_FLAG_8152) 2205 + switch (sc->ure_flags & URE_FLAG_CHIP_MASK) { 2206 + case URE_FLAG_8152: 1842 2207 ure_rtl8152_init(sc); 1843 - else if (sc->ure_flags & (URE_FLAG_8153B | URE_FLAG_8156 | 1844 - URE_FLAG_8156B)) 1845 - ure_rtl8153b_init(sc); 1846 - else 1847 - ure_rtl8153_init(sc); 2208 + break; 2209 + case URE_FLAG_8153B: 2210 + case URE_FLAG_8156: 2211 + case URE_FLAG_8156B: 2212 + if (ure_rtl8153b_init(sc) != 0) 2213 + return; 2214 + break; 2215 + case URE_FLAG_8157: 2216 + if (ure_rtl8157_init(sc) != 0) 2217 + return; 2218 + break; 2219 + default: 2220 + if (ure_rtl8153_init(sc) != 0) 2221 + return; 2222 + break; 2223 + } 1848 2224 1849 2225 if (sc->ure_chip & URE_CHIP_VER_4C00) 1850 2226 ure_read_mem(sc, URE_PLA_IDR, URE_MCU_TYPE_PLA, eaddr, ··· 1872 2248 ifp->if_capabilities |= IFCAP_VLAN_HWTAGGING; 1873 2249 #endif 1874 2250 1875 - if (sc->ure_flags & (URE_FLAG_8156 | URE_FLAG_8156B)) { 2251 + if (sc->ure_flags & (URE_FLAG_8156 | URE_FLAG_8156B | URE_FLAG_8157)) { 1876 2252 ifmedia_init(&sc->ure_ifmedia, IFM_IMASK, ure_ifmedia_upd, 1877 2253 ure_ifmedia_sts); 1878 2254 ure_add_media_types(sc); ··· 1965 2341 mii = &sc->ure_mii; 1966 2342 1967 2343 s = splnet(); 1968 - if (sc->ure_flags & (URE_FLAG_8156 | URE_FLAG_8156B)) 2344 + if (sc->ure_flags & (URE_FLAG_8156 | URE_FLAG_8156B | URE_FLAG_8157)) 1969 2345 ure_link_state(sc); 1970 2346 else { 1971 2347 mii_tick(mii); ··· 1992 2368 } 1993 2369 1994 2370 void 2371 + ure_rxcsum(struct ure_rxpkt *rxhdr, struct mbuf *m) 2372 + { 2373 + uint32_t cflags, rxvlan; 2374 + 2375 + cflags = letoh32(rxhdr->ure_csum); 2376 + rxvlan = letoh32(rxhdr->ure_vlan); 2377 + 2378 + /* Check IP header checksum. */ 2379 + if ((rxvlan & URE_RXPKT_IPV4) && !(cflags & URE_RXPKT_IPSUMBAD)) 2380 + m->m_pkthdr.csum_flags |= M_IPV4_CSUM_IN_OK; 2381 + 2382 + /* Check TCP/UDP checksum. */ 2383 + if ((rxvlan & (URE_RXPKT_IPV4 | URE_RXPKT_IPV6)) && 2384 + (((rxvlan & URE_RXPKT_TCP) && !(cflags & URE_RXPKT_TCPSUMBAD)) || 2385 + ((rxvlan & URE_RXPKT_UDP) && !(cflags & URE_RXPKT_UDPSUMBAD)))) 2386 + m->m_pkthdr.csum_flags |= M_TCP_CSUM_IN_OK | M_UDP_CSUM_IN_OK; 2387 + #if NVLAN > 0 2388 + if (rxvlan & URE_RXPKT_VLAN_TAG) { 2389 + m->m_pkthdr.ether_vtag = swap16(rxvlan & URE_RXPKT_VLAN_DATA); 2390 + m->m_flags |= M_VLANTAG; 2391 + } 2392 + #endif 2393 + } 2394 + 2395 + void 2396 + ure_rxcsum_v2(struct ure_rxpkt_v2 *rxhdr2, struct mbuf *m) 2397 + { 2398 + uint32_t cflags, rxvlan, vtag; 2399 + 2400 + cflags = letoh32(rxhdr2->ure_csum); 2401 + rxvlan = letoh32(rxhdr2->ure_vlan); 2402 + vtag = letoh32(rxhdr2->ure_pktlen); 2403 + 2404 + /* Check IP header checksum. */ 2405 + if ((cflags & (URE_RXPKT_V2_IPV4 | URE_RXPKT_V2_IPSUMBAD)) != 2406 + (URE_RXPKT_V2_IPV4 | URE_RXPKT_V2_IPSUMBAD)) 2407 + m->m_pkthdr.csum_flags |= M_IPV4_CSUM_IN_OK; 2408 + 2409 + /* Check TCP/UDP checksum. */ 2410 + if ((cflags & (URE_RXPKT_V2_IPV4 | URE_RXPKT_V2_IPV6)) && 2411 + (((cflags & (URE_RXPKT_V2_TCP | URE_RXPKT_V2_TCPSUMBAD)) == 2412 + URE_RXPKT_V2_TCP) || 2413 + ((cflags & (URE_RXPKT_V2_UDP | URE_RXPKT_V2_UDPSUMBAD)) == 2414 + URE_RXPKT_V2_UDP))) 2415 + m->m_pkthdr.csum_flags |= M_TCP_CSUM_IN_OK | M_UDP_CSUM_IN_OK; 2416 + #if NVLAN > 0 2417 + if (vtag & URE_RXPKT_V2_VLAN_TAG) { 2418 + m->m_pkthdr.ether_vtag = 2419 + swap16((rxvlan >> 16) & URE_RXPKT_VLAN_DATA); 2420 + m->m_flags |= M_VLANTAG; 2421 + } 2422 + #endif 2423 + } 2424 + 2425 + void 1995 2426 ure_rxeof(struct usbd_xfer *xfer, void *priv, usbd_status status) 1996 2427 { 1997 2428 struct ure_chain *c = (struct ure_chain *)priv; 1998 2429 struct ure_softc *sc = c->uc_sc; 1999 2430 struct ifnet *ifp = &sc->ure_ac.ac_if; 2000 - u_char *buf = c->uc_buf; 2001 - uint32_t cflags, rxvlan, total_len; 2002 - struct mbuf_list ml = MBUF_LIST_INITIALIZER(); 2003 - struct mbuf *m; 2004 - int pktlen = 0, s; 2005 - struct ure_rxpkt rxhdr; 2431 + uint32_t total_len; 2006 2432 2007 2433 if (usbd_is_dying(sc->ure_udev)) 2008 2434 return; ··· 2025 2451 2026 2452 usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL); 2027 2453 DPRINTFN(3, ("received %d bytes\n", total_len)); 2028 - 2029 - do { 2030 - if (total_len < sizeof(rxhdr)) { 2031 - DPRINTF(("too few bytes left for a packet header\n")); 2032 - ifp->if_ierrors++; 2033 - goto done; 2034 - } 2035 - 2036 - buf += roundup(pktlen, URE_RX_BUF_ALIGN); 2037 - 2038 - memcpy(&rxhdr, buf, sizeof(rxhdr)); 2039 - total_len -= sizeof(rxhdr); 2040 - 2041 - pktlen = letoh32(rxhdr.ure_pktlen) & URE_RXPKT_LEN_MASK; 2042 - DPRINTFN(4, ("next packet is %d bytes\n", pktlen)); 2043 - if (pktlen > total_len) { 2044 - DPRINTF(("not enough bytes left for next packet\n")); 2045 - ifp->if_ierrors++; 2046 - goto done; 2047 - } 2048 - 2049 - total_len -= roundup(pktlen, URE_RX_BUF_ALIGN); 2050 - buf += sizeof(rxhdr); 2051 - 2052 - m = m_devget(buf, pktlen - ETHER_CRC_LEN, ETHER_ALIGN); 2053 - if (m == NULL) { 2054 - DPRINTF(("unable to allocate mbuf for next packet\n")); 2055 - ifp->if_ierrors++; 2056 - goto done; 2057 - } 2058 - 2059 - cflags = letoh32(rxhdr.ure_csum); 2060 - rxvlan = letoh32(rxhdr.ure_vlan); 2061 - 2062 - /* Check IP header checksum. */ 2063 - if ((rxvlan & URE_RXPKT_IPV4) && 2064 - !(cflags & URE_RXPKT_IPSUMBAD)) 2065 - m->m_pkthdr.csum_flags |= M_IPV4_CSUM_IN_OK; 2066 - 2067 - /* Check TCP/UDP checksum. */ 2068 - if ((rxvlan & (URE_RXPKT_IPV4 | URE_RXPKT_IPV6)) && 2069 - (((rxvlan & URE_RXPKT_TCP) && 2070 - !(cflags & URE_RXPKT_TCPSUMBAD)) || 2071 - ((rxvlan & URE_RXPKT_UDP) && 2072 - !(cflags & URE_RXPKT_UDPSUMBAD)))) 2073 - m->m_pkthdr.csum_flags |= M_TCP_CSUM_IN_OK | 2074 - M_UDP_CSUM_IN_OK; 2075 - #if NVLAN > 0 2076 - if (rxvlan & URE_RXPKT_VLAN_TAG) { 2077 - m->m_pkthdr.ether_vtag = 2078 - swap16(rxvlan & URE_RXPKT_VLAN_DATA); 2079 - m->m_flags |= M_VLANTAG; 2080 - } 2081 - #endif 2082 - 2083 - ml_enqueue(&ml, m); 2084 - } while (total_len > 0); 2454 + ure_decap(sc, c, total_len); 2085 2455 2086 2456 done: 2087 - s = splnet(); 2088 - if_input(ifp, &ml); 2089 - splx(s); 2090 - memset(c->uc_buf, 0, sc->ure_rxbufsz); 2091 - 2092 2457 usbd_setup_xfer(xfer, sc->ure_ep[URE_ENDPT_RX], c, c->uc_buf, 2093 2458 sc->ure_rxbufsz, USBD_SHORT_XFER_OK | USBD_NO_COPY, 2094 2459 USBD_NO_TIMEOUT, ure_rxeof); 2095 2460 usbd_transfer(xfer); 2096 2461 } 2097 - 2098 2462 2099 2463 void 2100 2464 ure_txeof(struct usbd_xfer *xfer, void *priv, usbd_status status) ··· 2145 2509 splx(s); 2146 2510 } 2147 2511 2512 + void 2513 + ure_decap(struct ure_softc *sc, struct ure_chain *c, uint32_t len) 2514 + { 2515 + struct ifnet *ifp = &sc->ure_ac.ac_if; 2516 + u_char *buf = c->uc_buf; 2517 + uint32_t hdrsize; 2518 + struct mbuf_list ml = MBUF_LIST_INITIALIZER(); 2519 + struct mbuf *m; 2520 + int pktlen = 0, align, s; 2521 + struct ure_rxpkt rxhdr; 2522 + struct ure_rxpkt_v2 rxhdr2; 2523 + 2524 + align = (sc->ure_flags & URE_FLAG_8157) ? 2525 + URE_8157_BUF_ALIGN : URE_RX_BUF_ALIGN; 2526 + hdrsize = (sc->ure_flags & URE_FLAG_8157) ? 2527 + sizeof(rxhdr2) : sizeof(rxhdr); 2528 + 2529 + do { 2530 + if (len < hdrsize) { 2531 + DPRINTF(("too few bytes left for a packet header\n")); 2532 + ifp->if_ierrors++; 2533 + break; 2534 + } 2535 + 2536 + buf += roundup(pktlen, align); 2537 + 2538 + if (sc->ure_flags & URE_FLAG_8157) { 2539 + memcpy(&rxhdr2, buf, hdrsize); 2540 + pktlen = 2541 + letoh32(rxhdr2.ure_pktlen) & URE_RXPKT_V2_LEN_MASK; 2542 + pktlen >>= 17; 2543 + } else { 2544 + memcpy(&rxhdr, buf, hdrsize); 2545 + pktlen = letoh32(rxhdr.ure_pktlen) & URE_RXPKT_LEN_MASK; 2546 + } 2547 + 2548 + len -= hdrsize; 2549 + DPRINTFN(4, ("next packet is %d bytes\n", pktlen)); 2550 + if (pktlen > len) { 2551 + DPRINTF(("not enough bytes left for next packet\n")); 2552 + ifp->if_ierrors++; 2553 + break; 2554 + } 2555 + 2556 + len -= roundup(pktlen, align); 2557 + buf += hdrsize; 2558 + 2559 + m = m_devget(buf, pktlen - ETHER_CRC_LEN, ETHER_ALIGN); 2560 + if (m == NULL) { 2561 + DPRINTF(("unable to allocate mbuf for next packet\n")); 2562 + ifp->if_ierrors++; 2563 + break; 2564 + } 2565 + 2566 + if (sc->ure_flags & URE_FLAG_8157) 2567 + ure_rxcsum_v2(&rxhdr2, m); 2568 + else 2569 + ure_rxcsum(&rxhdr, m); 2570 + 2571 + ml_enqueue(&ml, m); 2572 + } while (len > 0); 2573 + 2574 + s = splnet(); 2575 + if_input(ifp, &ml); 2576 + splx(s); 2577 + memset(c->uc_buf, 0, sc->ure_rxbufsz); 2578 + } 2579 + 2148 2580 int 2149 - ure_encap_txpkt(struct mbuf *m, char *buf, uint32_t maxlen) 2581 + ure_encap_txpkt(struct ure_softc *sc, struct mbuf *m, char *buf, 2582 + uint32_t maxlen) 2150 2583 { 2151 2584 struct ure_txpkt txhdr; 2152 - uint32_t len = sizeof(txhdr), cflags = 0; 2585 + struct ure_txpkt_v2 txhdr2; 2586 + uint32_t len, cflags = 0; 2153 2587 2588 + len = (sc->ure_flags & URE_FLAG_8157) ? sizeof(txhdr2) : sizeof(txhdr); 2154 2589 if (len + m->m_pkthdr.len > maxlen) 2155 2590 return (-1); 2156 2591 ··· 2168 2603 cflags |= URE_TXPKT_VLAN_TAG | swap16(m->m_pkthdr.ether_vtag); 2169 2604 #endif 2170 2605 2171 - txhdr.ure_pktlen = htole32(m->m_pkthdr.len | URE_TXPKT_TX_FS | 2172 - URE_TXPKT_TX_LS); 2173 - txhdr.ure_vlan = htole32(cflags); 2174 - memcpy(buf, &txhdr, len); 2606 + if (sc->ure_flags & URE_FLAG_8157) { 2607 + txhdr2.ure_cmdstat = htole32(URE_TXPKT_TX_FS | URE_TXPKT_TX_LS); 2608 + txhdr2.ure_vlan = htole32(cflags); 2609 + txhdr2.ure_pktlen = htole32(m->m_pkthdr.len << 4); 2610 + txhdr2.ure_signature = htole32(URE_TXPKT_SIGNATURE); 2611 + memcpy(buf, &txhdr2, len); 2612 + } else { 2613 + txhdr.ure_pktlen = htole32(m->m_pkthdr.len | URE_TXPKT_TX_FS | 2614 + URE_TXPKT_TX_LS); 2615 + txhdr.ure_vlan = htole32(cflags); 2616 + memcpy(buf, &txhdr, len); 2617 + } 2175 2618 2176 2619 m_copydata(m, 0, m->m_pkthdr.len, buf + len); 2177 2620 len += m->m_pkthdr.len;
+64 -6
sys/dev/usb/if_urereg.h
··· 1 - /* $OpenBSD: if_urereg.h,v 1.13 2023/08/15 08:27:30 miod Exp $ */ 1 + /* $OpenBSD: if_urereg.h,v 1.14 2025/05/23 03:06:09 kevlo Exp $ */ 2 2 /*- 3 3 * Copyright (c) 2015, 2016, 2019 Kevin Lo <kevlo@openbsd.org> 4 4 * All rights reserved. ··· 110 110 #define URE_USB_USB2PHY 0xb41e 111 111 #define URE_USB_SSPHYLINK1 0xb426 112 112 #define URE_USB_SSPHYLINK2 0xb428 113 + #define URE_USB_L1_CTRL 0xb45e 113 114 #define URE_USB_U2P3_CTRL 0xb460 114 115 #define URE_USB_CSR_DUMMY1 0xb464 115 116 #define URE_USB_CSR_DUMMY2 0xb466 116 117 #define URE_USB_DEV_STAT 0xb808 118 + #define URE_USB_U2P3_CTRL2 0xc2c0 117 119 #define URE_USB_CONNECT_TIMER 0xcbf8 118 120 #define URE_USB_MSC_TIMER 0xcbfc 119 121 #define URE_USB_BURST_SIZE 0xcfc0 ··· 142 144 #define URE_USB_U1U2_TIMER 0xd4da 143 145 #define URE_USB_FW_TASK 0xd4e8 144 146 #define URE_USB_RX_AGGR_NUM 0xd4ee 147 + #define URE_USB_CMD_ADDR 0xd5d6 148 + #define URE_USB_CMD_DATA 0xd5d8 149 + #define URE_USB_CMD 0xd5dc 150 + #define URE_USB_TGPHY_ADDR 0xd630 151 + #define URE_USB_TGPHY_DATA 0xd632 152 + #define URE_USB_TGPHY_CMD 0xd634 145 153 #define URE_USB_UPS_CTRL 0xd800 146 154 #define URE_USB_POWER_CUT 0xd80a 147 155 #define URE_USB_MISC_0 0xd81a 148 - #define URE_USB_POWER_CUT 0xd80a 149 156 #define URE_USB_AFE_CTRL2 0xd824 150 157 #define URE_USB_UPS_FLAGS 0xd848 151 158 #define URE_USB_WDT11_CTRL 0xe43c ··· 235 242 /* URE_PLA_MTPS */ 236 243 #define MTPS_DEFAULT 96 237 244 #define MTPS_JUMBO 192 245 + #define MTPS_MAX 255 238 246 239 247 /* URE_PLA_RSTTALLY */ 240 248 #define URE_TALLY_RESET 0x0001 ··· 362 370 #define URE_PHYSTATUS_100MBPS 0x0008 363 371 #define URE_PHYSTATUS_1000MBPS 0x0010 364 372 #define URE_PHYSTATUS_2500MBPS 0x0400 373 + #define URE_PHYSTATUS_5000MBPS 0x1000 365 374 366 375 /* URE_PLA_CONFIG6 */ 367 376 #define URE_LANWAKE_CLR_EN 0x01 ··· 447 456 /* URE_USB_RX_AGGR_NUM */ 448 457 #define URE_RX_AGGR_NUM_MASK 0x1ff 449 458 459 + /* URE_USB_CMD */ 460 + #define URE_CMD_BMU 0x0000 461 + #define URE_CMD_BUSY 0x0001 462 + #define URE_CMD_WRITE 0x0002 463 + #define URE_CMD_IP 0x0004 464 + 465 + /* URE_USB_TGPHY_CMD */ 466 + #define URE_TGPHY_CMD_BUSY 0x0001 467 + #define URE_TGPHY_CMD_WRITE 0x0002 468 + 450 469 /* URE_USB_UPS_CTRL */ 451 470 #define URE_POWER_CUT 0x0100 452 471 ··· 461 480 /* URE_USB_U2P3_CTRL */ 462 481 #define URE_U2P3_ENABLE 0x0001 463 482 #define URE_RX_DETECT8 0x0008 483 + 484 + /* URE_USB_U2P3_CTRL2 */ 485 + #define URE_U2P3_CTRL2_ENABLE 0x20000000 464 486 465 487 /* URE_USB_POWER_CUT */ 466 488 #define URE_PWR_EN 0x0001 ··· 529 551 #define URE_CKADSEL_L 0x0100 530 552 531 553 #define URE_ADV_2500TFDX 0x0080 554 + #define URE_ADV_5000TFDX 0x0100 532 555 533 556 #define URE_MCU_TYPE_PLA 0x0100 534 557 #define URE_MCU_TYPE_USB 0x0000 ··· 578 601 #define URE_TXPKT_VLAN_TAG (1 << 16) 579 602 } __packed; 580 603 604 + struct ure_rxpkt_v2 { 605 + uint32_t ure_pktlen; 606 + #define URE_RXPKT_V2_LEN_MASK 0xfffe0000 607 + #define URE_RXPKT_V2_VLAN_TAG (1 << 3) 608 + uint32_t ure_vlan; 609 + uint32_t ure_csum; 610 + #define URE_RXPKT_V2_IPSUMBAD (1 << 26) 611 + #define URE_RXPKT_V2_UDPSUMBAD (1 << 25) 612 + #define URE_RXPKT_V2_TCPSUMBAD (1 << 24) 613 + #define URE_RXPKT_V2_IPV6 (1 << 15) 614 + #define URE_RXPKT_V2_IPV4 (1 << 14) 615 + #define URE_RXPKT_V2_UDP (1 << 11) 616 + #define URE_RXPKT_V2_TCP (1 << 10) 617 + uint32_t ure_rsvd0; 618 + } __packed; 619 + 620 + struct ure_txpkt_v2 { 621 + uint32_t ure_cmdstat; 622 + uint32_t ure_vlan; 623 + uint32_t ure_pktlen; 624 + uint32_t ure_signature; 625 + #define URE_TXPKT_SIGNATURE 0xa8000000 626 + } __packed; 627 + 581 628 #define URE_ENDPT_RX 0 582 629 #define URE_ENDPT_TX 1 583 630 #define URE_ENDPT_MAX 2 ··· 586 633 #define URE_RX_LIST_CNT 1 587 634 #define URE_TX_BUF_ALIGN 4 588 635 #define URE_RX_BUF_ALIGN 8 636 + #define URE_8157_BUF_ALIGN 16 589 637 590 638 #define URE_TX_BUFSZ 16384 639 + #define URE_8156_TX_BUFSZ 32768 591 640 #define URE_8152_RX_BUFSZ 16384 592 641 #define URE_8153_RX_BUFSZ 32768 593 642 643 + #define URE_CMD_TYPE_BMU 0 644 + #define URE_CMD_TYPE_IP 1 645 + 594 646 struct ure_chain { 595 647 struct ure_softc *uc_sc; 596 648 struct usbd_xfer *uc_xfer; ··· 634 686 635 687 int ure_phyno; 636 688 689 + uint16_t (*ure_phy_read)(struct ure_softc *, uint16_t); 690 + void (*ure_phy_write)(struct ure_softc *, uint16_t, 691 + uint16_t); 692 + 637 693 u_int ure_flags; 638 694 #define URE_FLAG_LINK 0x0001 639 - #define URE_FLAG_8152 0x1000 /* RTL8152 */ 640 - #define URE_FLAG_8153B 0x2000 /* RTL8153B */ 641 - #define URE_FLAG_8156 0x4000 /* RTL8156 */ 642 - #define URE_FLAG_8156B 0x8000 /* RTL8156B */ 695 + #define URE_FLAG_8152 0x0010 /* RTL8152 */ 696 + #define URE_FLAG_8153B 0x0020 /* RTL8153B */ 697 + #define URE_FLAG_8156 0x0040 /* RTL8156 */ 698 + #define URE_FLAG_8156B 0x0080 /* RTL8156B */ 699 + #define URE_FLAG_8157 0x0100 /* RTL8157 */ 700 + #define URE_FLAG_CHIP_MASK 0x01f0 643 701 644 702 u_int ure_chip; 645 703 #define URE_CHIP_VER_4C00 0x01