Re: [PATCH] ure improvement

2017-07-27 Thread sc dying
On 2017/07/27 12:22, Martin Pieuchot wrote:
> On 25/07/17(Tue) 00:30, sc dying wrote:
>> On 2017/07/24 14:35, Martin Pieuchot wrote:
>>> [...]
>>> Here's a diff to try and play with.  I'd guess the problem is in
>>> pipe_close().  Which state has the EP you're closing?  Do we close
>>> the EP correctly?
>>
>> EP 3 is RX pipe, EP 4 is TX pipe.
>> Looks good to me.
>
> Does that mean it works?  Do you still see a RXERROR with it?

Still get IOERROR.

>>> - /* Mask the endpoint */
>>> + /* Stop the endpoint */
>>> + bus_dmamap_sync(sdev->ictx_dma.tag, sdev->ictx_dma.map, 0,
>>> +sc->sc_pagesize, BUS_DMASYNC_POSTREAD);
>>> + state = letoh32(XHCI_EPCTX_STATE(sdev->ep_ctx[xp->dci - 1]->info_lo));
>>
>> Do you wanna see output context (device context, 6.2.1)?
>
> I'm not sure why would I, could you elaborate?
>
> I though the Endpoint Context, sec. 6.2.3, is enough.  Updated diff with
> a corrected letoh32().

The input context gives the data to xHC from system software, and
device context (aka output context) gives the data to software from xHC.
We will peek the endpoint state modified by xHC, so that we should see
octx_dma.
xhci_setaddr is a good example. It peeks the state of slot context
in debug code.

>
> Index: xhci.c
> ===
> RCS file: /cvs/src/sys/dev/usb/xhci.c,v
> retrieving revision 1.73
> diff -u -p -r1.73 xhci.c
> --- xhci.c 22 Jun 2017 02:44:37 - 1.73
> +++ xhci.c 27 Jul 2017 12:21:54 -
> @@ -1251,13 +1251,22 @@ xhci_pipe_close(struct usbd_pipe *pipe)
>   struct xhci_softc *sc = (struct xhci_softc *)pipe->device->bus;
>   struct xhci_pipe *lxp, *xp = (struct xhci_pipe *)pipe;
>   struct xhci_soft_dev *sdev = >sc_sdevs[xp->slot];
> + uint32_t state;
>   int i;
>
>   /* Root Hub */
>   if (pipe->device->depth == 0)
>   return;
>
> - /* Mask the endpoint */
> + /* If required, stop the endpoint */
> + bus_dmamap_sync(sdev->ictx_dma.tag, sdev->ictx_dma.map, 0,
> +sc->sc_pagesize, BUS_DMASYNC_POSTREAD);
> + state = XHCI_EPCTX_STATE(letoh32(sdev->ep_ctx[xp->dci - 1]->info_lo));
> + printf("%s: EP %d state=%x\n", DEVNAME(sc), xp->dci, state);
> + if (state != XHCI_EP_STOPPED && xhci_cmd_stop_ep(sc, xp->slot, xp->dci))
> + DPRINTF(("%s: error stopping ep (%d)\n", DEVNAME(sc), xp->dci));
> +
> + /* Mask it */
>   sdev->input_ctx->drop_flags = htole32(XHCI_INCTX_MASK_DCI(xp->dci));
>   sdev->input_ctx->add_flags = 0;
>
>



Re: [PATCH] ure improvement

2017-07-27 Thread Martin Pieuchot
On 25/07/17(Tue) 00:30, sc dying wrote:
> On 2017/07/24 14:35, Martin Pieuchot wrote:
> > [...]
> > Here's a diff to try and play with.  I'd guess the problem is in
> > pipe_close().  Which state has the EP you're closing?  Do we close
> > the EP correctly?
> 
> EP 3 is RX pipe, EP 4 is TX pipe.
> Looks good to me.

Does that mean it works?  Do you still see a RXERROR with it?

> > - /* Mask the endpoint */
> > + /* Stop the endpoint */
> > + bus_dmamap_sync(sdev->ictx_dma.tag, sdev->ictx_dma.map, 0,
> > +sc->sc_pagesize, BUS_DMASYNC_POSTREAD);
> > + state = letoh32(XHCI_EPCTX_STATE(sdev->ep_ctx[xp->dci - 1]->info_lo));
> 
> Do you wanna see output context (device context, 6.2.1)?

I'm not sure why would I, could you elaborate?

I though the Endpoint Context, sec. 6.2.3, is enough.  Updated diff with
a corrected letoh32().

Index: xhci.c
===
RCS file: /cvs/src/sys/dev/usb/xhci.c,v
retrieving revision 1.73
diff -u -p -r1.73 xhci.c
--- xhci.c  22 Jun 2017 02:44:37 -  1.73
+++ xhci.c  27 Jul 2017 12:21:54 -
@@ -1251,13 +1251,22 @@ xhci_pipe_close(struct usbd_pipe *pipe)
struct xhci_softc *sc = (struct xhci_softc *)pipe->device->bus;
struct xhci_pipe *lxp, *xp = (struct xhci_pipe *)pipe;
struct xhci_soft_dev *sdev = >sc_sdevs[xp->slot];
+   uint32_t state;
int i;
 
/* Root Hub */
if (pipe->device->depth == 0)
return;
 
-   /* Mask the endpoint */
+   /* If required, stop the endpoint */
+   bus_dmamap_sync(sdev->ictx_dma.tag, sdev->ictx_dma.map, 0,
+   sc->sc_pagesize, BUS_DMASYNC_POSTREAD);
+   state = XHCI_EPCTX_STATE(letoh32(sdev->ep_ctx[xp->dci - 1]->info_lo));
+   printf("%s: EP %d state=%x\n", DEVNAME(sc), xp->dci, state);
+   if (state != XHCI_EP_STOPPED && xhci_cmd_stop_ep(sc, xp->slot, xp->dci))
+   DPRINTF(("%s: error stopping ep (%d)\n", DEVNAME(sc), xp->dci));
+
+   /* Mask it */
sdev->input_ctx->drop_flags = htole32(XHCI_INCTX_MASK_DCI(xp->dci));
sdev->input_ctx->add_flags = 0;
 



Re: [PATCH] ure improvement

2017-07-21 Thread sc dying
On 2017/07/20 08:31, Martin Pieuchot wrote:
> On 18/07/17(Tue) 13:43, sc dying wrote:
>> On 2017/07/18 09:12, Martin Pieuchot wrote:
>>> On 17/07/17(Mon) 15:24, sc dying wrote:
 On 2017/07/17 08:24, Martin Pieuchot wrote:
> On 15/07/17(Sat) 21:16, sc dying wrote:
>> - 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.
>>>
>>> This is certainly a bug in the way pipe are closed, or more likely in
>>> xhci(4).  Can you reproduce the problem on ehci(4)?  Do you find
>>> anything useful if you define XHCI_DEBUG in your kernel?
>>
>> This problem is not seen on ehci.
>>
>> On xhci with XHCI_DEBUG, curiously, it does not happen.
>> I'll look into this.
>
> Great, I committed your diff without this chunk.  I'd be glad to hear
> from you if you find the problem with xhci(4).

Thank you for applying the patch.

About IOERROR, it happens even if XHCI_DEBUG is defined.
It happens on usb 3 mode port, but does not on usb 2
even if it is xhci's port.

All I did for test are
1) Plug-in the device
2) ifconfig ure0 inet6 fe80::1
3) ping6 from other host to fe80::1
4) ifconfig ure0 down
5) ifconfig ure0 up
6) ping6 again

I forgot step 3) to check if the device replies to ping.

If the device does not receive any packets, it can be re-up
without errors and works correctly after interface down and up.
However, once it receives a packet, re-opening bulk-in pipe for RX
immediately fails with TXERR (event_xfer translates it to IOERROR).

xhci 4.6.6 says closing all pipes transitions the device state
from Configured to Addressed.
I thought it is needed to issue configure_ep and SET_CONFIG to transition
the device to Configured state correcly again as described in 4.6.6,
but this does not explain why the device works on usb 2.



Re: [PATCH] ure improvement

2017-07-20 Thread Martin Pieuchot
On 18/07/17(Tue) 13:43, sc dying wrote:
> On 2017/07/18 09:12, Martin Pieuchot wrote:
> > On 17/07/17(Mon) 15:24, sc dying wrote:
> >> On 2017/07/17 08:24, Martin Pieuchot wrote:
> >>> On 15/07/17(Sat) 21:16, sc dying wrote:
>  - 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.
> >
> > This is certainly a bug in the way pipe are closed, or more likely in
> > xhci(4).  Can you reproduce the problem on ehci(4)?  Do you find
> > anything useful if you define XHCI_DEBUG in your kernel?
> 
> This problem is not seen on ehci.
> 
> On xhci with XHCI_DEBUG, curiously, it does not happen.
> I'll look into this.

Great, I committed your diff without this chunk.  I'd be glad to hear
from you if you find the problem with xhci(4).



Re: [PATCH] ure improvement

2017-07-18 Thread sc dying
On 2017/07/18 09:12, Martin Pieuchot wrote:
> On 17/07/17(Mon) 15:24, sc dying wrote:
>> On 2017/07/17 08:24, Martin Pieuchot wrote:
>>> On 15/07/17(Sat) 21:16, sc dying wrote:
 - 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.
>
> This is certainly a bug in the way pipe are closed, or more likely in
> xhci(4).  Can you reproduce the problem on ehci(4)?  Do you find
> anything useful if you define XHCI_DEBUG in your kernel?

This problem is not seen on ehci.

On xhci with XHCI_DEBUG, curiously, it does not happen.
I'll look into this.



Re: [PATCH] ure improvement

2017-07-18 Thread Martin Pieuchot
On 17/07/17(Mon) 15:24, sc dying wrote:
> On 2017/07/17 08:24, Martin Pieuchot wrote:
> > On 15/07/17(Sat) 21:16, sc dying wrote:
> >> 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).

That's the two supported chips, so that should be good enough.

> >> - 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.

This is certainly a bug in the way pipe are closed, or more likely in
xhci(4).  Can you reproduce the problem on ehci(4)?  Do you find
anything useful if you define XHCI_DEBUG in your kernel?



Re: [PATCH] ure improvement

2017-07-17 Thread sc dying
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.cWed May  3 22:20:15 2017
+++ sys/dev/usb/if_ure.cMon 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,
+>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(, 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);


Re: [PATCH] ure improvement

2017-07-17 Thread Martin Pieuchot
On 15/07/17(Sat) 21:16, sc dying wrote:
> Hi,
> 
> This patch does:
> 
> - Enable RX aggregation.

Does it work on all chips?

> - Fix RX packet buffer alignment, using roundup() macro in sys/params.h.

Why is that needed?  pktlen should already be aligned, no?

> - 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.

> - 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.

> --- 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,
> + >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(, 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);
> 



[PATCH] ure improvement

2017-07-15 Thread sc dying
Hi,

This patch does:

- Enable RX aggregation.
- Fix RX packet buffer alignment, using roundup() macro in sys/params.h.
- 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.
- Make the chip recognize given MAC address.
- Remove ure_reset in ure_init, becasue its already called from ure_stop.

Regards,

--- 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,
+ >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(, 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);