On 2017/07/17 08:24, Martin Pieuchot wrote: > On 15/07/17(Sat) 21:16, sc dying wrote: >> Hi, >> >> This patch does: >> >> - Enable RX aggregation. > > Does it work on all chips?
I don't have all, but it works with mine that have RTL8152 (ver 4c10) and RTL8153 (ver 5c20). > >> - Fix RX packet buffer alignment, using roundup() macro in sys/params.h. > > Why is that needed? pktlen should already be aligned, no? If RX_AGG is enabled, multiple packets may be received in a transaction and the chip puts each packet on 8 bytes boundary. For the first packet buf points at aligned buffer, but for second packet the buf + pktlen might points at unaligned pointer as pktlen is the actual length of packet. It should be rounded up. > >> - Call usbd_set_config before configuring endpoints in ure_init to fix >> an error when re-opening pipes. I grabbed the code from if_kue.c. > > Which error? Calling usbd_set_config() should be avoid as much as > possible in driver code. Without patch, ure on usb-3 port says this error ure0: usb errors on rx: IOERROR when down the interface and it up. > >> - Make the chip recognize given MAC address. > > Nice > >> - Remove ure_reset in ure_init, becasue its already called from ure_stop. > > Your diff do not apply, please check your mail setup. I attached the patch. gmail will encode it with base64. Sorry about that.
--- sys/dev/usb/if_ure.c Wed May 3 22:20:15 2017 +++ sys/dev/usb/if_ure.c Mon Jun 19 09:11:09 2017 @@ -470,8 +470,6 @@ ure_init(void *xsc) /* Cancel pending I/O. */ ure_stop(sc); - ure_reset(sc); - if (ure_rx_list_init(sc) == ENOBUFS) { printf("%s: rx list init failed\n", sc->ure_dev.dv_xname); splx(s); @@ -484,9 +482,18 @@ ure_init(void *xsc) return; } +#define URE_CONFIG_NO 1 + if (usbd_set_config_no(sc->ure_udev, URE_CONFIG_NO, 1) || + usbd_device2interface_handle(sc->ure_udev, URE_IFACE_IDX, + &sc->ure_iface)) + printf("%s: set_config failed\n", sc->ure_dev.dv_xname); + usbd_delay_ms(sc->ure_udev, 10); + /* Set MAC address. */ + ure_write_1(sc, URE_PLA_CRWECR, URE_MCU_TYPE_PLA, URE_CRWECR_CONFIG); ure_write_mem(sc, URE_PLA_IDR, URE_MCU_TYPE_PLA | URE_BYTE_EN_SIX_BYTES, sc->ure_ac.ac_enaddr, 8); + ure_write_1(sc, URE_PLA_CRWECR, URE_MCU_TYPE_PLA, URE_CRWECR_NORAML); /* Reset the packet filter. */ ure_write_2(sc, URE_PLA_FMC, URE_MCU_TYPE_PLA, @@ -683,10 +690,10 @@ ure_rtl8152_init(struct ure_softc *sc) URE_GPHY_STS_MSK | URE_SPEED_DOWN_MSK | URE_SPDWN_RXDV_MSK | URE_SPDWN_LINKCHG_MSK); - /* Disable Rx aggregation. */ + /* Enable Rx aggregation. */ ure_write_2(sc, URE_USB_USB_CTRL, URE_MCU_TYPE_USB, - ure_read_2(sc, URE_USB_USB_CTRL, URE_MCU_TYPE_USB) | - URE_RX_AGG_DISABLE); + ure_read_2(sc, URE_USB_USB_CTRL, URE_MCU_TYPE_USB) & + ~URE_RX_AGG_DISABLE); /* Disable ALDPS. */ ure_ocp_reg_write(sc, URE_OCP_ALDPS_CONFIG, URE_ENPDNPS | URE_LINKENA | @@ -835,10 +842,10 @@ ure_rtl8153_init(struct ure_softc *sc) ure_init_fifo(sc); - /* Disable Rx aggregation. */ + /* Enable Rx aggregation. */ ure_write_2(sc, URE_USB_USB_CTRL, URE_MCU_TYPE_USB, - ure_read_2(sc, URE_USB_USB_CTRL, URE_MCU_TYPE_USB) | - URE_RX_AGG_DISABLE); + ure_read_2(sc, URE_USB_USB_CTRL, URE_MCU_TYPE_USB) & + ~URE_RX_AGG_DISABLE); val = ure_read_2(sc, URE_USB_U2P3_CTRL, URE_MCU_TYPE_USB); if (!(sc->ure_chip & (URE_CHIP_VER_5C00 | URE_CHIP_VER_5C10))) @@ -1289,7 +1296,7 @@ ure_rxeof(struct usbd_xfer *xfer, void *priv, usbd_sta goto done; } - buf += pktlen; + buf += roundup(pktlen, 8); memcpy(&rxhdr, buf, sizeof(rxhdr)); total_len -= sizeof(rxhdr); @@ -1302,7 +1309,7 @@ ure_rxeof(struct usbd_xfer *xfer, void *priv, usbd_sta goto done; } - total_len -= pktlen; + total_len -= roundup(pktlen, 8); buf += sizeof(rxhdr); m = m_devget(buf, pktlen, ETHER_ALIGN);