usb: eth: asix88179: Use a fixed URB buffer size and misc cleanup
cover usb: eth: asix88179: Use a fixed URB buffer size and misc cleanup
This series fixes an issue resulting in unusabe Ethernet thanks to use of large URB buffer size. It also include miscellaneous cleanup and refactor to make the driver closer match the Linux ASIX AX88xxx driver.
The URB buffer size change patch is the only patch that was needed to fix the non working Ethernet issue observed on a Rockchip RK3528 board using a UGREEN USB 3.0 (AX88179B) or UGREEN USB 2.0 (AX88772E) Ethernet adapter. Remaining patches is a biproduct of debugging that issue.
Jonas Karlman (6):
usb: eth: asix88179: Use negative ECOMM return value
usb: eth: asix88179: Use a fixed URB buffer size of 16 KiB
usb: eth: asix88179: Make functions static and align params
usb: eth: asix88179: Refactor asix_send_common() to closer match Linux
usb: eth: asix88179: Refactor ax88179_eth_recv() to closer match Linux
usb: eth: asix88179: Add read_rom_hwaddr() ops
drivers/usb/eth/asix88179.c | 134 ++++++++++++++++++------------------ 1 file changed, 68 insertions(+), 66 deletions(-)
Signature · 1 line
2.52.0
PATCH 1/6 usb: eth: asix88179: Use negative ECOMM return value
The ASIX 88179 driver asix_read/write_cmd() return a positive error value instead of a typical negative error value. This return value is checked in the asix_read/write_mac() to control a debug() print and can also propagate to probe() and write_hwaddr() ops.
Change to use a proper negative ECOMM return value when read/write a command. Also update to use the ETH_ALEN const instead of 6 for consistent use in asix_read/write_mac().
--- drivers/usb/eth/asix88179.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/usb/eth/asix88179.c +8 -7
@@ -235,7 +235,7 @@ static int asix_write_cmd(struct ueth_data *dev, u8 cmd, u16 value, u16 index, size, USB_CTRL_SET_TIMEOUT); -return len == size ?0 :ECOMM ; +return len == size ?0 : -ECOMM ; } static int asix_read_cmd(struct ueth_data *dev, u8 cmd, u16 value, u16 index,
@@ -260,15 +260,16 @@ static int asix_read_cmd(struct ueth_data *dev, u8 cmd, u16 value, u16 index,memcpy (data, buf, size); -return len == size ?0 :ECOMM ; +return len == size ?0 : -ECOMM ; }static int asix_read_mac (struct ueth_data *dev,uint8_t *enetaddr) {int ret; - ret =asix_read_cmd (dev,AX_ACCESS_MAC ,AX_NODE_ID ,6 ,6 , enetaddr); -if (ret <0 ) + ret =asix_read_cmd (dev,AX_ACCESS_MAC ,AX_NODE_ID , +ETH_ALEN ,ETH_ALEN , enetaddr); +if (ret)debug ("Failed to read MAC address: %02x\n" , ret);return ret;
@@ -278,9 +279,9 @@ static int asix_write_mac(struct ueth_data *dev, uint8_t *enetaddr) {int ret; - ret =asix_write_cmd (dev,AX_ACCESS_MAC ,AX_NODE_ID ,ETH_ALEN , -ETH_ALEN , enetaddr); -if (ret <0 ) + ret =asix_write_cmd (dev,AX_ACCESS_MAC ,AX_NODE_ID , +ETH_ALEN ,ETH_ALEN , enetaddr); +if (ret)debug ("Failed to set MAC address: %02x\n" , ret);return ret;
Signature · 1 line
2.52.0
Re: [PATCH 1/6] usb: eth: asix88179: Use negative ECOMM return value
Quoted 35 lines · Jonas Karlman
The ASIX 88179 driver asix_read/write_cmd() return a positive error value instead of a typical negative error value. This return value is checked in the asix_read/write_mac() to control a
debug()print and can also propagate toprobe()andwrite_hwaddr()ops.Change to use a proper negative ECOMM return value when read/write a command. Also update to use the
ETH_ALENconst instead of 6 for consistent use in asix_read/write_mac().Signed-off-by Jonas Karlman <[email protected]>--- drivers/usb/eth/asix88179.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)drivers/usb/eth/asix88179.c +2
-2@@ -235,7 +235,7 @@ static int asix_write_cmd(struct ueth_data *dev, u8 cmd, u16 value, u16 index, size, USB_CTRL_SET_TIMEOUT); -return len == size ?0 :ECOMM ; +return len == size ?0 : -ECOMM ; } static int asix_read_cmd(struct ueth_data *dev, u8 cmd, u16 value, u16 index,@@ -260,15 +260,16 @@ static int asix_read_cmd(struct ueth_data *dev, u8 cmd, u16 value, u16 index,memcpy (data, buf, size); -return len == size ?0 :ECOMM ; +return len == size ?0 : -ECOMM ; }
drivers/usb/eth/asix88179.c static int asix_read_cmd(struct ueth_data *dev, u8 cmd, u16 value, u16 index, · line 273
Quoted 10 lines
drivers/usb/eth/asix88179.c +3
-2static int asix_read_mac (struct ueth_data *dev,uint8_t *enetaddr) {int ret; - ret =asix_read_cmd (dev,AX_ACCESS_MAC ,AX_NODE_ID ,6 ,6 , enetaddr); -if (ret <0 ) + ret =asix_read_cmd (dev,AX_ACCESS_MAC ,AX_NODE_ID , +ETH_ALEN ,ETH_ALEN , enetaddr); +if (ret)debug ("Failed to read MAC address: %02x\n" , ret);
This print likely needs to be fixed too, it prints unsigned hex while the value is now signed int.
drivers/usb/eth/asix88179.c static int asix_write_mac(struct ueth_data *dev, uint8_t *enetaddr) · line 285
Quoted 13 lines
drivers/usb/eth/asix88179.c +3
-3return ret;@@ -278,9 +279,9 @@ static int asix_write_mac(struct ueth_data *dev, uint8_t *enetaddr) {int ret; - ret =asix_write_cmd (dev,AX_ACCESS_MAC ,AX_NODE_ID ,ETH_ALEN , -ETH_ALEN , enetaddr); -if (ret <0 ) + ret =asix_write_cmd (dev,AX_ACCESS_MAC ,AX_NODE_ID , +ETH_ALEN ,ETH_ALEN , enetaddr); +if (ret)debug ("Failed to set MAC address: %02x\n" , ret);
DTTO
PATCH 2/6 usb: eth: asix88179: Use a fixed URB buffer size of 16 KiB
In reply to Jonas KarlmanThe commit 05278af8b3df ("eth: asix88179: packet drop when receiving large fragmented packets") adjusted the URB buffer size to allow large fragmented packets. However, this change result in use of a large URB buffer size for slow speed connections, e.g. 10/100M use 26 KiB.
Using a ASIX AX88179B USB 3.0 or ASIX AX88772E USB 2.0 Ethernet adapter on a Rockchip RK3528 with a DWC2 USB controller this large URB buffer size result in invalid rx_hdr and result in unusable Ethernet.
The data read back from AX_RX_BULKIN_QCTRL after being configured also does not match the values in the AX88179_BULKIN_SIZE array.
Change to use a fixed URB buffer size of 16 KiB to fix use of Ethernet, anything larger seem to result in unusable Ethernet. With the 16 KiB URB buffer size use of TFTP_BLOCKSIZE=15360 seem to work okay.
---
Please note that the vendor driver 3.5.0 seems to use a different BULKIN_SIZE array for the AX88179A/88772D variants, see [1].
[1] https://github.com/mmoya/asix-usb-nic-linux-driver/blob/main/ax88179a_772d.c#L24-L30
--- drivers/usb/eth/asix88179.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/usb/eth/asix88179.c +2 -6
@@ -173,7 +173,7 @@#define USB_BULK_SEND_TIMEOUT 5000#define USB_BULK_RECV_TIMEOUT 5000 -#define AX_RX_URB_SIZE 1024 * 0x1a +#define AX_RX_URB_SIZE 16384#define BLK_FRAME_SIZE 0x200#define PHY_CONNECT_TIMEOUT 5000#define PHY_RESET_TIMEOUT 500
@@ -206,7 +206,6 @@ struct asix_private {uint8_t *pkt_data;uint32_t *pkt_hdr;int flags; -int rx_urb_size;int maxpacketsize; };
@@ -333,8 +332,6 @@ static int asix_basic_reset(struct ueth_data *dev,memcpy (tmp, &AX88179_BULKIN_SIZE [0 ],5 );asix_write_cmd (dev,AX_ACCESS_MAC ,AX_RX_BULKIN_QCTRL ,5 ,5 , tmp); - dev_priv->rx_urb_size =1024 *20 ; -/* Water Level configuration */ *tmp =0x34 ;asix_write_cmd (dev,AX_ACCESS_MAC ,AX_PAUSE_WATERLVL_LOW ,1 ,1 , tmp);
@@ -476,7 +473,6 @@ static int asix_init_common(struct ueth_data *dev,/* RX bulk configuration */ asix_write_cmd (dev,AX_ACCESS_MAC ,AX_RX_BULKIN_QCTRL ,5 ,5 , tmp); - dev_priv->rx_urb_size = (1024 * (tmp[3 ] +2 ));if (*tmp16 &GMII_PHY_PHYSR_FULL ) mode |=AX_MEDIUM_FULL_DUPLEX ; asix_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
@@ -574,7 +570,7 @@ int ax88179_eth_recv(struct udevice *dev, int flags, uchar **packetp)if (!(flags Ð_RECV_CHECK_DEVICE ))return -EAGAIN ; - ret =usb_ether_receive (ueth, priv->rx_urb_size); + ret =usb_ether_receive (ueth,AX_RX_URB_SIZE );if (ret <0 )return ret;
Signature · 1 line
2.52.0
Re: [PATCH 2/6] usb: eth: asix88179: Use a fixed URB buffer size of 16 KiB
Quoted 5 lines · Jonas Karlman
The commit
05278af8b3df("eth: asix88179: packet drop when receiving large fragmented packets") adjusted the URB buffer size to allow large fragmented packets. However, this change result in use of a large URB buffer size for slow speed connections, e.g. 10/100M use 26 KiB.
Quoted 8 lines
Using a ASIX AX88179B USB 3.0 or ASIX AX88772E USB 2.0 Ethernet adapter on a Rockchip RK3528 with a DWC2 USB controller this large URB buffer size result in invalid
rx_hdrand result in unusable Ethernet.The data read back from
AX_RX_BULKIN_QCTRLafter being configured also does not match the values in theAX88179_BULKIN_SIZEarray.Change to use a fixed URB buffer size of 16 KiB to fix use of Ethernet,
Why 16 kiB and not something else ?
Is this a USB controller related problem/limitation ? Maybe the DWC2 driver needs fixing instead, to handler larger buffers ?
Re: [PATCH 2/6] usb: eth: asix88179: Use a fixed URB buffer size of 16 KiB
Hi Marek,
Quoted 10 lines · Marek Vasut
Quoted 9 lines · Jonas Karlman
The commit
05278af8b3df("eth: asix88179: packet drop when receiving large fragmented packets") adjusted the URB buffer size to allow large fragmented packets. However, this change result in use of a large URB buffer size for slow speed connections, e.g. 10/100M use 26 KiB.Using a ASIX AX88179B USB 3.0 or ASIX AX88772E USB 2.0 Ethernet adapter on a Rockchip RK3528 with a DWC2 USB controller this large URB buffer size result in invalid
rx_hdrand result in unusable Ethernet.
Quoted 6 lines
Quoted 4 lines
The data read back from
AX_RX_BULKIN_QCTRLafter being configured also does not match the values in theAX88179_BULKIN_SIZEarray.Change to use a fixed URB buffer size of 16 KiB to fix use of Ethernet,
Why 16 kiB and not something else ?
Using anything larger than 16 KiB resulted in issues, and a datasheet for the older AX88772 prior to the D revision mention default 16 KiB for "Maximum Frame Burst transfer on USB bus" so 16 KiB seemed like a safe size to use for newer revisions, and this also made it possible to use fragmented packets up to just below 16 KiB.
Quoted 3 lines
Is this a USB controller related problem/limitation ? Maybe the DWC2 driver needs fixing instead, to handler larger buffers ?
I accidentally mixed up what host controller was being used, the board in question is using a generic-echi controller not the DWC2 as I stated.
Below follow some debug prints, what can be observed is that when length=26624 is returned from ehci_submit_bulk_msg the ax88179_eth_recv will return len >16 KiB and that result in the rx_hdr at the end of the returned buffer being bogus data, e.g. for following:
BOOTP broadcast 1
** asix_send_common(), len 342
ehci_submit_bulk_msg: dev='usb@ff100000', udev=00000000f9f2c520 dev=00000000f9f2c520, pipe=c0018303, buffer=00000000f9ee0680, length=350, req=0000000000000000 TOKEN=0x80008c00
Tx: len = 346, actual = 350, err = 0
ax88179_eth_recv: first try, len=0
ehci_submit_bulk_msg: dev='usb@ff100000', udev=00000000f9f2c520 dev=00000000f9f2c520, pipe=c0010383, buffer=00000000f9f2cf00, length=26624, req=0000000000000000 TOKEN=0xa7808d00
ax88179_eth_recv: second try, len=16512
ax88179_eth_recv: 2 packets received, pkt header at 112
ax88179_eth_recv: return packet of 106 bytes (1 packets left)
ax88179_eth_recv: return packet of 0 bytes (0 packets left)
The buffers returned from the AX88179 contains something like:
<packet data N><N+1>... <packet header N><N+1>... <RX HDR>
Above the "2 packets received, pkt header at 112" seem to indicate that the pkt header is in the middle of the packet data, in other instances the rx_hdr seem to indicate that the buffer contains thousands of packets, i.e. the rx_hdr is likely bogus when more than 16 KiB is returned from ehci_submit_bulk_msg.
More info and debug prints:
=> dm tree -e usb
Class Seq Probed Driver Name
-----------------------------------------------------------
pinconfig 277 [ + ] pinconfig usb pinconfig 278 [ + ] pinconfig `-- usb-host-en pinconfig 280 [ ] pinconfig usb-wifi-pwr nop 0 [ ] dwc3-generic-wrapper usb@fe500000 usb_gadget 0 [ ] dwc3-generic-periphe `-- usb@fe500000 usb 0 [ + ] ehci_generic usb@ff100000 usb_hub 0 [ + ] usb_hub `-- usb_hub usb_hub 1 [ + ] usb_hub `-- usb_hub ethernet 0 [ + ] ax88179_eth `-- ax88179_eth bootdev 2 [ + ] eth_bootdev `-- ax88179_eth.bootdev nop 1 [ + ] rockchip_usb2phy usb2phy@ffdf0000 phy 1 [ ] rockchip_usb2phy_por |-- otg-port phy 2 [ + ] rockchip_usb2phy_por |-- host-port clk 3 [ + ] rockchip_usb2phy_clo `-- clk_usbphy_480m
=> usb tree
USB device tree:
1 Hub (480 Mb/s, 0mA)
| u-boot EHCI Host Controller
|
+-2 Hub (480 Mb/s, 100mA)
| USB 2.0 Hub
|
+-3 Vendor specific (480 Mb/s, 100mA)
| ASIX AX88772E 00CFCE77
|=> dhcp
** asix_init_common()asix_write_cmd() cmd=0x01 value=0x000b index=0x0002 size=2usb_control_msg: request: 0x1, requesttype: 0x40, value 0xB index 0x2 length 0x2ehci_submit_control_msg: dev='usb@ff100000', udev=00000000f9f2c520, udev->dev='ax88179_eth', portnr=3 dev=00000000f9f2c520, pipe=80000303, buffer=00000000f9ee0bc0, length=2, req=00000000f9ee0ac0 req=1 (0x1), type=64 (0x40), value=11 (0xb), index=2
TOKEN=0x8d01asix_read_cmd() cmd=0x02 value=0x0003 index=0x0001 size=2usb_control_msg: request: 0x2, requesttype: 0xC0, value 0x3 index 0x1 length 0x2ehci_submit_control_msg: dev='usb@ff100000', udev=00000000f9f2c520, udev->dev='ax88179_eth', portnr=3 dev=00000000f9f2c520, pipe=80000383, buffer=00000000f9ee0b80, length=2, req=00000000f9ee0a80 req=2 (0x2), type=192 (0xc0), value=3 (0x3), index=1
TOKEN=0x8c00asix_read_cmd() cmd=0x01 value=0x0002 index=0x0001 size=1usb_control_msg: request: 0x1, requesttype: 0xC0, value 0x2 index 0x1 length 0x1ehci_submit_control_msg: dev='usb@ff100000', udev=00000000f9f2c520, udev->dev='ax88179_eth', portnr=3 dev=00000000f9f2c520, pipe=80000383, buffer=00000000f9ee0bc0, length=1, req=00000000f9ee0ac0 req=1 (0x1), type=192 (0xc0), value=2 (0x2), index=1
TOKEN=0x8c00asix_read_cmd() cmd=0x02 value=0x0003 index=0x0011 size=2usb_control_msg: request: 0x2, requesttype: 0xC0, value 0x3 index 0x11 length 0x2ehci_submit_control_msg: dev='usb@ff100000', udev=00000000f9f2c520, udev->dev='ax88179_eth', portnr=3 dev=00000000f9f2c520, pipe=80000383, buffer=00000000f9ee0bc0, length=2, req=00000000f9ee0ac0 req=2 (0x2), type=192 (0xc0), value=3 (0x3), index=17
TOKEN=0x8c00asix_write_cmd() cmd=0x01 value=0x002e index=0x0005 size=5usb_control_msg: request: 0x1, requesttype: 0x40, value 0x2E index 0x5 length 0x5ehci_submit_control_msg: dev='usb@ff100000', udev=00000000f9f2c520, udev->dev='ax88179_eth', portnr=3 dev=00000000f9f2c520, pipe=80000303, buffer=00000000f9ee0bc0, length=5, req=00000000f9ee0ac0 req=1 (0x1), type=64 (0x40), value=46 (0x2e), index=5
TOKEN=0x8d01asix_write_cmd() cmd=0x01 value=0x0022 index=0x0002 size=2usb_control_msg: request: 0x1, requesttype: 0x40, value 0x22 index 0x2 length 0x2ehci_submit_control_msg: dev='usb@ff100000', udev=00000000f9f2c520, udev->dev='ax88179_eth', portnr=3 dev=00000000f9f2c520, pipe=80000303, buffer=00000000f9ee0bc0, length=2, req=00000000f9ee0ac0 req=1 (0x1), type=64 (0x40), value=34 (0x22), index=2
TOKEN=0x8d01
BOOTP broadcast 1
** asix_send_common(), len 342ehci_submit_bulk_msg: dev='usb@ff100000', udev=00000000f9f2c520
dev=00000000f9f2c520, pipe=c0018303, buffer=00000000f9ee0680, length=350, req=0000000000000000 TOKEN=0x80008c00
Tx: len = 346, actual = 350, err = 0ax88179_eth_recv: first try, len=0ehci_submit_bulk_msg: dev='usb@ff100000', udev=00000000f9f2c520
dev=00000000f9f2c520, pipe=c0010383, buffer=00000000f9f2cf00, length=26624, req=0000000000000000 TOKEN=0xa7808d00ax88179_eth_recv: second try, len=16512ax88179_eth_recv: 2 packets received, pkt header at 112ax88179_eth_recv: return packet of 106 bytes (1 packets left)ax88179_eth_recv: return packet of 0 bytes (0 packets left)
BOOTP broadcast 2
** asix_send_common(), len 342ehci_submit_bulk_msg: dev='usb@ff100000', udev=00000000f9f2c520
dev=00000000f9f2c520, pipe=c0018303, buffer=00000000f9ee0680, length=350, req=0000000000000000 TOKEN=0x8c00
Tx: len = 346, actual = 350, err = 0ax88179_eth_recv: first try, len=0ehci_submit_bulk_msg: dev='usb@ff100000', udev=00000000f9f2c520
dev=00000000f9f2c520, pipe=c0010383, buffer=00000000f9f2cf00, length=26624, req=0000000000000000 TOKEN=0x27808d00ax88179_eth_recv: second try, len=16512ax88179_eth_recv: 2 packets received, pkt header at 112ax88179_eth_recv: return packet of 106 bytes (1 packets left)ax88179_eth_recv: return packet of 0 bytes (0 packets left)
BOOTP broadcast 3
** asix_send_common(), len 342ehci_submit_bulk_msg: dev='usb@ff100000', udev=00000000f9f2c520
dev=00000000f9f2c520, pipe=c0018303, buffer=00000000f9ee0680, length=350, req=0000000000000000 TOKEN=0x80008c00
Tx: len = 346, actual = 350, err = 0ax88179_eth_recv: first try, len=0ehci_submit_bulk_msg: dev='usb@ff100000', udev=00000000f9f2c520
dev=00000000f9f2c520, pipe=c0010383, buffer=00000000f9f2cf00, length=26624, req=0000000000000000 TOKEN=0xa7a88d00ax88179_eth_recv: second try, len=16472ax88179_eth_recv: 2 packets received, pkt header at 72ax88179_eth_recv: return packet of 3938 bytes (1 packets left)
** asix_send_common(), len 342ehci_submit_bulk_msg: dev='usb@ff100000', udev=00000000f9f2c520
dev=00000000f9f2c520, pipe=c0018303, buffer=00000000f9ee0600, length=350, req=0000000000000000 TOKEN=0x8c00
Tx: len = 346, actual = 350, err = 0ax88179_eth_recv: return packet of 0 bytes (0 packets left)ax88179_eth_recv: first try, len=0ehci_submit_bulk_msg: dev='usb@ff100000', udev=00000000f9f2c520
dev=00000000f9f2c520, pipe=c0010383, buffer=00000000f9f2cf00, length=26624, req=0000000000000000 TOKEN=0x27a88d00ax88179_eth_recv: second try, len=16472ax88179_eth_recv: 2 packets received, pkt header at 72ax88179_eth_recv: return packet of 3938 bytes (1 packets left)
DHCP client bound to address 192.168.42.234 (3365 ms)
Using ax88179_eth device
TFTP from server 192.168.2.50; our IP address is 192.168.42.234; sending through gateway 192.168.42.1 Filename 'default'.
Load address: 0xc00800
Loading: ** asix_send_common(), len 42ehci_submit_bulk_msg: dev='usb@ff100000', udev=00000000f9f2c520
dev=00000000f9f2c520, pipe=c0018303, buffer=00000000f9ee0580, length=50, req=0000000000000000 TOKEN=0x80008c00
Tx: len = 46, actual = 50, err = 0ax88179_eth_recv: return packet of 0 bytes (0 packets left)ax88179_eth_recv: first try, len=0ehci_submit_bulk_msg: dev='usb@ff100000', udev=00000000f9f2c520
dev=00000000f9f2c520, pipe=c0010383, buffer=00000000f9f2cf00, length=26624, req=0000000000000000 TOKEN=0xa7988d00ax88179_eth_recv: second try, len=16488ax88179_eth_recv: 2 packets received, pkt header at 88ax88179_eth_recv: return packet of 0 bytes (1 packets left)ax88179_eth_recv: return packet of 0 bytes (0 packets left)ax88179_eth_recv: first try, len=0ehci_submit_bulk_msg: dev='usb@ff100000', udev=00000000f9f2c520
dev=00000000f9f2c520, pipe=c0010383, buffer=00000000f9f2cf00, length=26624, req=0000000000000000 TOKEN=0x27a88d00ax88179_eth_recv: second try, len=16472ax88179_eth_recv: 2 packets received, pkt header at 72ax88179_eth_recv: return packet of 3650 bytes (1 packets left)ax88179_eth_recv: return packet of 4949 bytes (0 packets left)ax88179_eth_recv: first try, len=0ax88179_eth_recv: first try, len=0ehci_submit_bulk_msg: dev='usb@ff100000', udev=00000000f9f2c520
dev=00000000f9f2c520, pipe=c0010383, buffer=00000000f9f2cf00, length=26624, req=0000000000000000 TOKEN=0xa7808d00ax88179_eth_recv: second try, len=16512ax88179_eth_recv: 2 packets received, pkt header at 112ax88179_eth_recv: return packet of 106 bytes (1 packets left)ax88179_eth_recv: return packet of 0 bytes (0 packets left)ax88179_eth_recv: first try, len=0ehci_submit_bulk_msg: dev='usb@ff100000', udev=00000000f9f2c520
dev=00000000f9f2c520, pipe=c0010383, buffer=00000000f9f2cf00, length=26624, req=0000000000000000 TOKEN=0x26189d00ax88179_eth_recv: second try, len=16872ax88179_eth_recv: 2 packets received, pkt header at 472ax88179_eth_recv: return packet of 0 bytes (1 packets left)ax88179_eth_recv: return packet of 0 bytes (0 packets left)ax88179_eth_recv: first try, len=0ehci_submit_bulk_msg: dev='usb@ff100000', udev=00000000f9f2c520
dev=00000000f9f2c520, pipe=c0010383, buffer=00000000f9f2cf00, length=26624, req=0000000000000000 TOKEN=0xa7b08d00ax88179_eth_recv: second try, len=16464ax88179_eth_recv: 2 packets received, pkt header at 64ax88179_eth_recv: return packet of 3360 bytes (1 packets left)ax88179_eth_recv: return packet of 0 bytes (0 packets left)ax88179_eth_recv: first try, len=0ehci_submit_bulk_msg: dev='usb@ff100000', udev=00000000f9f2c520
dev=00000000f9f2c520, pipe=c0010383, buffer=00000000f9f2cf00, length=26624, req=0000000000000000 TOKEN=0x27b08d00ax88179_eth_recv: second try, len=16464ax88179_eth_recv: 2 packets received, pkt header at 64ax88179_eth_recv: return packet of 5681 bytes (1 packets left)ax88179_eth_recv: return packet of 3141 bytes (0 packets left)ax88179_eth_recv: first try, len=0
** asix_send_common(), len 42ehci_submit_bulk_msg: dev='usb@ff100000', udev=00000000f9f2c520
dev=00000000f9f2c520, pipe=c0018303, buffer=00000000f9ee0680, length=50, req=0000000000000000 TOKEN=0x8c00
Tx: len = 46, actual = 50, err = 0ax88179_eth_recv: first try, len=0ehci_submit_bulk_msg: dev='usb@ff100000', udev=00000000f9f2c520
dev=00000000f9f2c520, pipe=c0010383, buffer=00000000f9f2cf00, length=26624, req=0000000000000000 TOKEN=0xa7a88d00ax88179_eth_recv: second try, len=16472ax88179_eth_recv: 2 packets received, pkt header at 72ax88179_eth_recv: return packet of 0 bytes (1 packets left)ax88179_eth_recv: return packet of 64 bytes (0 packets left)
** asix_send_common(), len 82ehci_submit_bulk_msg: dev='usb@ff100000', udev=00000000f9f2c520
dev=00000000f9f2c520, pipe=c0018303, buffer=00000000f9ee0600, length=90, req=0000000000000000 TOKEN=0x80008c00
Tx: len = 86, actual = 90, err = 0ax88179_eth_recv: first try, len=0ax88179_eth_recv: first try, len=0ehci_submit_bulk_msg: dev='usb@ff100000', udev=00000000f9f2c520
dev=00000000f9f2c520, pipe=c0010383, buffer=00000000f9f2cf00, length=26624, req=0000000000000000 TOKEN=0x27b08d00ax88179_eth_recv: second try, len=16464ax88179_eth_recv: 2 packets received, pkt header at 64ax88179_eth_recv: return packet of 63 bytes (1 packets left)
TFTP error: 'File not found' (1)
Not retrying...
** ax88179_eth_stop()
Regards,
Jonas
Re: [PATCH 2/6] usb: eth: asix88179: Use a fixed URB buffer size of 16 KiB
Hi Marek,
Quoted 27 lines · Jonas Karlman
Hi Marek,
Quoted 10 lines · Marek Vasut
Quoted 9 lines · Jonas Karlman
The commit
05278af8b3df("eth: asix88179: packet drop when receiving large fragmented packets") adjusted the URB buffer size to allow large fragmented packets. However, this change result in use of a large URB buffer size for slow speed connections, e.g. 10/100M use 26 KiB.Using a ASIX AX88179B USB 3.0 or ASIX AX88772E USB 2.0 Ethernet adapter on a Rockchip RK3528 with a DWC2 USB controller this large URB buffer size result in invalid
rx_hdrand result in unusable Ethernet.Quoted 6 lines
Quoted 4 lines
The data read back from
AX_RX_BULKIN_QCTRLafter being configured also does not match the values in theAX88179_BULKIN_SIZEarray.Change to use a fixed URB buffer size of 16 KiB to fix use of Ethernet,
Why 16 kiB and not something else ?
Using anything larger than 16 KiB resulted in issues, and a datasheet for the older AX88772 prior to the D revision mention default 16 KiB for "Maximum Frame Burst transfer on USB bus" so 16 KiB seemed like a safe size to use for newer revisions, and this also made it possible to use fragmented packets up to just below 16 KiB.
Quoted 1 line
Quoted 5 lines
Quoted 2 lines
Is this a USB controller related problem/limitation ? Maybe the DWC2 driver needs fixing instead, to handler larger buffers ?
I accidentally mixed up what host controller was being used, the board in question is using a generic-echi controller not the DWC2 as I stated.
I dove deeper and it looks like there could be an issue with ehci-hcd and handling of short packets, see below debug print that dumps the qTD and where it can be seen that the first packet is short and using the xfr_bytes - totalbytes of the first qTD with a short packet fixes my issue.
BOOTP broadcast 4
** asix_send_common(), len 342
ehci_submit_bulk_msg: dev='usb@ff100000', udev=00000000f9f2d520 dev=00000000f9f2d520, pipe=c0018303, buffer=00000000f9ee13c0, length=350, req=0000000000000000
QH: next=0x1, alt=0x11, token=0x8c00, totalbytes=0, xfr_bytes=0
qTD[0]: next=0x1, alt=0x1, token=0x8c00, totalbytes=0, xfr_bytes=350 TOKEN=0x8c00
Tx: len = 346, actual = 350, err = 0
ax88179_eth_recv: first try, len=0
ehci_submit_bulk_msg: dev='usb@ff100000', udev=00000000f9f2d520 dev=00000000f9f2d520, pipe=c0010383, buffer=00000000f9f2df00, length=26624, req=0000000000000000
QH: next=0x1, alt=0x11, token=0xa7808d00, totalbytes=10112
qTD[0]: next=0xf9f2a140, alt=0x1, token=0xbe989d00, totalbytes=16024, xfr_bytes=16384 <<-- SHORT qTD[1]: next=0x1, alt=0x1, token=0xa7808d00, totalbytes=10112, xfr_bytes=10240 <<-- SHORT TOKEN=0xa7808d00
ax88179_eth_recv: second try, len=16512
ax88179_eth_recv: 2 packets received, pkt header at 112
ax88179_eth_recv: return packet of 0 bytes (1 packets left)
ax88179_eth_recv: return packet of 0 bytes (0 packets left)
ax88179_eth_recv: first try, len=0
ehci_submit_bulk_msg: dev='usb@ff100000', udev=00000000f9f2d520 dev=00000000f9f2d520, pipe=c0010383, buffer=00000000f9f2df00, length=26624, req=0000000000000000
QH: next=0x1, alt=0x11, token=0x27a08d00, totalbytes=10144
qTD[0]: next=0xf9f2a140, alt=0x1, token=0x3e889d00, totalbytes=16008, xfr_bytes=16384 <<-- SHORT qTD[1]: next=0x1, alt=0x1, token=0x27a08d00, totalbytes=10144, xfr_bytes=10240 <<-- SHORT TOKEN=0x27a08d00
ax88179_eth_recv: second try, len=16480
ax88179_eth_recv: 2 packets received, pkt header at 80
ax88179_eth_recv: return packet of 5429 bytes (1 packets left)
ax88179_eth_recv: return packet of 4149 bytes (0 packets left)
The diff below seem to solve my issue even better, aligns the ehci transfers to only use one qTD with a 20kb buffer for optimal performance.
But that is probably still not a good solution, ehci-hcd should probably gain proper support for short packet handling and usb_ether_register() could start using a 4kb aligned rxbuf to make sure 20kb transfers instead of 16kb transfers are used for ehci controllers.
Maybe I should just drop this patch and address your feedback on remaining patches for v2?
drivers/usb/eth/asix88179.c +0 -1
@@ -475,7 +475,6 @@ static int asix_init_common(struct ueth_data *dev,/* RX bulk configuration */ asix_write_cmd (dev,AX_ACCESS_MAC ,AX_RX_BULKIN_QCTRL ,5 ,5 , tmp); - dev_priv->rx_urb_size = (1024 * (tmp[3 ] +2 ));if (*tmp16 &GMII_PHY_PHYSR_FULL ) mode |=AX_MEDIUM_FULL_DUPLEX ; asix_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
drivers/usb/eth/usb_ether.c +1 -1
@@ -72,7 +72,7 @@ int usb_ether_register(struct udevice *dev, struct ueth_data *ueth, int rxsize) } ueth->rxsize = rxsize; - ueth->rxbuf =memalign (ARCH_DMA_MINALIGN , rxsize); + ueth->rxbuf =memalign (4096 , rxsize);if (!ueth->rxbuf)return -ENOMEM ;
Regards,
Jonas
Quoted 63 lines
Below follow some debug prints, what can be observed is that when length=26624 is returned from
ehci_submit_bulk_msgtheax88179_eth_recvwill return len >16 KiB and that result in therx_hdrat the end of the returned buffer being bogus data, e.g. for following:BOOTP broadcast 1
**asix_send_common(), len 342
ehci_submit_bulk_msg: dev='usb@ff100000', udev=00000000f9f2c520 dev=00000000f9f2c520, pipe=c0018303, buffer=00000000f9ee0680, length=350, req=0000000000000000 TOKEN=0x80008c00
Tx: len = 346, actual = 350, err = 0
ax88179_eth_recv: first try, len=0
ehci_submit_bulk_msg: dev='usb@ff100000', udev=00000000f9f2c520 dev=00000000f9f2c520, pipe=c0010383, buffer=00000000f9f2cf00, length=26624, req=0000000000000000 TOKEN=0xa7808d00
ax88179_eth_recv: second try, len=16512
ax88179_eth_recv: 2 packets received, pkt header at 112
ax88179_eth_recv: return packet of 106 bytes (1 packets left)
ax88179_eth_recv: return packet of 0 bytes (0 packets left)The buffers returned from the AX88179 contains something like:
<packet data N><N+1>... <packet header N><N+1>... <RX HDR>
Above the "2 packets received, pkt header at 112" seem to indicate that the pkt header is in the middle of the packet data, in other instances the
rx_hdrseem to indicate that the buffer contains thousands of packets, i.e. therx_hdris likely bogus when more than 16 KiB is returned fromehci_submit_bulk_msg.More info and debug prints:
=> dm tree -e usb
Class Seq Probed Driver Name
-----------------------------------------------------------pinconfig 277 [ + ] pinconfig usb pinconfig 278 [ + ] pinconfig `-- usb-host-en pinconfig 280 [ ] pinconfig usb-wifi-pwr nop 0 [ ] dwc3-generic-wrapper usb@fe500000 usb_gadget 0 [ ] dwc3-generic-periphe `-- usb@fe500000 usb 0 [ + ] ehci_generic usb@ff100000 usb_hub 0 [ + ] usb_hub `-- usb_hub usb_hub 1 [ + ] usb_hub `-- usb_hub ethernet 0 [ + ] ax88179_eth `-- ax88179_eth bootdev 2 [ + ] eth_bootdev `-- ax88179_eth.bootdev nop 1 [ + ] rockchip_usb2phy usb2phy@ffdf0000 phy 1 [ ] rockchip_usb2phy_por |-- otg-port phy 2 [ + ] rockchip_usb2phy_por |-- host-port clk 3 [ + ] rockchip_usb2phy_clo `-- clk_usbphy_480m=> usb tree
USB device tree:
1 Hub (480 Mb/s, 0mA)
| u-boot EHCI Host Controller
|+-2 Hub (480 Mb/s, 100mA) | USB 2.0 Hub | +-3 Vendor specific (480 Mb/s, 100mA) | ASIX AX88772E 00CFCE77 |
[snip]
Quoted 2 lines
Regards,
Jonas
Re: [PATCH 2/6] usb: eth: asix88179: Use a fixed URB buffer size of 16 KiB
On 1/30/26 9:13 PM, Jonas Karlman wrote:
Hello Jonas,
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Is this a USB controller related problem/limitation ? Maybe the DWC2 driver needs fixing instead, to handler larger buffers ?
I accidentally mixed up what host controller was being used, the board in question is using a generic-echi controller not the DWC2 as I stated.
I dove deeper
Thank you for doing that.
Quoted 30 lines
and it looks like there could be an issue with ehci-hcd
and handling of short packets, see below debug print that dumps the qTD and where it can be seen that the first packet is short and using thexfr_bytes- totalbytes of the first qTD with a short packet fixes my issue.BOOTP broadcast 4 ** asix_send_common(), len 342 ehci_submit_bulk_msg: dev='usb@ff100000', udev=00000000f9f2d520 dev=00000000f9f2d520, pipe=c0018303, buffer=00000000f9ee13c0, length=350, req=0000000000000000 QH: next=0x1, alt=0x11, token=0x8c00, totalbytes=0, xfr_bytes=0 qTD[0]: next=0x1, alt=0x1, token=0x8c00, totalbytes=0, xfr_bytes=350 TOKEN=0x8c00 Tx: len = 346, actual = 350, err = 0 ax88179_eth_recv: first try, len=0 ehci_submit_bulk_msg: dev='usb@ff100000', udev=00000000f9f2d520 dev=00000000f9f2d520, pipe=c0010383, buffer=00000000f9f2df00, length=26624, req=0000000000000000 QH: next=0x1, alt=0x11, token=0xa7808d00, totalbytes=10112 qTD[0]: next=0xf9f2a140, alt=0x1, token=0xbe989d00, totalbytes=16024, xfr_bytes=16384 <<-- SHORT qTD[1]: next=0x1, alt=0x1, token=0xa7808d00, totalbytes=10112, xfr_bytes=10240 <<-- SHORT TOKEN=0xa7808d00 ax88179_eth_recv: second try, len=16512 ax88179_eth_recv: 2 packets received, pkt header at 112 ax88179_eth_recv: return packet of 0 bytes (1 packets left) ax88179_eth_recv: return packet of 0 bytes (0 packets left) ax88179_eth_recv: first try, len=0 ehci_submit_bulk_msg: dev='usb@ff100000', udev=00000000f9f2d520 dev=00000000f9f2d520, pipe=c0010383, buffer=00000000f9f2df00, length=26624, req=0000000000000000
Quoted 8 lines
QH: next=0x1, alt=0x11, token=0x27a08d00, totalbytes=10144 qTD[0]: next=0xf9f2a140, alt=0x1, token=0x3e889d00, totalbytes=16008, xfr_bytes=16384 <<-- SHORT qTD[1]: next=0x1, alt=0x1, token=0x27a08d00, totalbytes=10144, xfr_bytes=10240 <<-- SHORT TOKEN=0x27a08d00 ax88179_eth_recv: second try, len=16480 ax88179_eth_recv: 2 packets received, pkt header at 80 ax88179_eth_recv: return packet of 5429 bytes (1 packets left) ax88179_eth_recv: return packet of 4149 bytes (0 packets left)
Could you please share the printing diff ?
Maybe I am missing something, but the transfers above are longer than 20 kiB ? Also, how does the printout look _after_ the change below was applied ?
Quoted 11 lines
The diff below seem to solve my issue even better, aligns the ehci transfers to only use one qTD with a 20kb buffer for optimal performance.
But that is probably still not a good solution, ehci-hcd should probably gain proper support for short packet handling and
usb_ether_register()could start using a 4kb aligned rxbuf to make sure 20kb transfers instead of 16kb transfers are used for ehci controllers.Maybe I should just drop this patch and address your feedback on remaining patches for v2?
Maybe at least a subset of these patches can be picked that way, yes.
Quoted 17 lines
drivers/usb/eth/asix88179.c +0
-1@@ -475,7 +475,6 @@ static int asix_init_common(struct ueth_data *dev,/* RX bulk configuration */ asix_write_cmd (dev,AX_ACCESS_MAC ,AX_RX_BULKIN_QCTRL ,5 ,5 , tmp); - dev_priv->rx_urb_size = (1024 * (tmp[3 ] +2 ));if (*tmp16 &GMII_PHY_PHYSR_FULL ) mode |=AX_MEDIUM_FULL_DUPLEX ; asix_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,drivers/usb/eth/usb_ether.c +0
-0
drivers/usb/eth/usb_ether.c int usb_ether_register(struct udevice *dev, struct ueth_data *ueth, int rxsize) · line 75
Quoted 5 lines
drivers/usb/eth/usb_ether.c +1
-1@@ -72,7 +72,7 @@ int usb_ether_register(struct udevice *dev, struct ueth_data *ueth, int rxsize) } ueth->rxsize = rxsize; - ueth->rxbuf =memalign (ARCH_DMA_MINALIGN , rxsize); + ueth->rxbuf =memalign (4096 , rxsize);
What is your current ARCH_DMA_MINALIGN ?
Re: [PATCH 2/6] usb: eth: asix88179: Use a fixed URB buffer size of 16 KiB
In reply to Jonas KarlmanOn 1/30/26 11:54 AM, Jonas Karlman wrote:
Hello Jonas,
Quoted 9 lines
Quoted 3 lines
Quoted 1 line
Change to use a fixed URB buffer size of 16 KiB to fix use of Ethernet,
Why 16 kiB and not something else ?
Using anything larger than 16 KiB resulted in issues, and a datasheet for the older AX88772 prior to the D revision mention default 16 KiB for "Maximum Frame Burst transfer on USB bus" so 16 KiB seemed like a safe size to use for newer revisions, and this also made it possible to use fragmented packets up to just below 16 KiB.
Please include this information in the commit message.
Quoted 29 lines
Quoted 2 lines
Is this a USB controller related problem/limitation ? Maybe the DWC2 driver needs fixing instead, to handler larger buffers ?
I accidentally mixed up what host controller was being used, the board in question is using a generic-echi controller not the DWC2 as I stated.
Below follow some debug prints, what can be observed is that when length=26624 is returned from
ehci_submit_bulk_msgtheax88179_eth_recvwill return len >16 KiB and that result in therx_hdrat the end of the returned buffer being bogus data, e.g. for following:BOOTP broadcast 1 ** asix_send_common(), len 342 ehci_submit_bulk_msg: dev='usb@ff100000', udev=00000000f9f2c520 dev=00000000f9f2c520, pipe=c0018303, buffer=00000000f9ee0680, length=350, req=0000000000000000 TOKEN=0x80008c00 Tx: len = 346, actual = 350, err = 0 ax88179_eth_recv: first try, len=0 ehci_submit_bulk_msg: dev='usb@ff100000', udev=00000000f9f2c520 dev=00000000f9f2c520, pipe=c0010383, buffer=00000000f9f2cf00, length=26624, req=0000000000000000 TOKEN=0xa7808d00 ax88179_eth_recv: second try, len=16512 ax88179_eth_recv: 2 packets received, pkt header at 112 ax88179_eth_recv: return packet of 106 bytes (1 packets left) ax88179_eth_recv: return packet of 0 bytes (0 packets left)The buffers returned from the AX88179 contains something like:
Quoted 7 lines
<packet data N><N+1>... <packet header N><N+1>... <RX HDR>
Above the "2 packets received, pkt header at 112" seem to indicate that the pkt header is in the middle of the packet data, in other instances the
rx_hdrseem to indicate that the buffer contains thousands of packets, i.e. therx_hdris likely bogus when more than 16 KiB is returned fromehci_submit_bulk_msg.
Is this maybe some wrap-around ? 16 kiB x4 is 65536 , which is 16bit limit.
PATCH 3/6 usb: eth: asix88179: Make functions static and align params
In reply to Jonas KarlmanMake internal functions static, align function parameters and drop unnecessary != 0 checks to cleanup code.
--- drivers/usb/eth/asix88179.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/usb/eth/asix88179.c +10 -10
@@ -414,7 +414,7 @@ static int asix_wait_link(struct ueth_data *dev) }static int asix_init_common (struct ueth_data *dev, -struct asix_private *dev_priv) +struct asix_private *dev_priv) {u8 buf[2 ], tmp[5 ], link_sts;u16 *tmp16, mode;
@@ -426,14 +426,14 @@ static int asix_init_common(struct ueth_data *dev,/* Configure RX control register => start operation */ *tmp16 =AX_RX_CTL_DROPCRCERR |AX_RX_CTL_IPE |AX_RX_CTL_START |AX_RX_CTL_AP |AX_RX_CTL_AMALL |AX_RX_CTL_AB ; -if (asix_write_cmd (dev,AX_ACCESS_MAC ,AX_RX_CTL ,2 ,2 , tmp16) !=0 ) +if (asix_write_cmd (dev,AX_ACCESS_MAC ,AX_RX_CTL ,2 ,2 , tmp16)) goto out_err; -if (asix_wait_link (dev) !=0 ) { +if (asix_wait_link (dev)) {/*reset device and try again*/ printf ("Reset Ethernet Device\n" );asix_basic_reset (dev, dev_priv); -if (asix_wait_link (dev) !=0 ) +if (asix_wait_link (dev)) goto out_err; }
@@ -484,8 +484,8 @@ out_err: }static int asix_send_common (struct ueth_data *dev, -struct asix_private *dev_priv, -void *packet,int length) +struct asix_private *dev_priv, +void *packet,int length) {int err;u32 packet_len, tx_hdr2;
@@ -530,7 +530,7 @@ static int ax88179_eth_start(struct udevice *dev)return asix_init_common (&priv->ueth, priv); } -void ax88179_eth_stop (struct udevice *dev) +static void ax88179_eth_stop (struct udevice *dev) {struct asix_private *priv =dev_get_priv (dev);struct ueth_data *ueth = &priv->ueth;
@@ -543,14 +543,14 @@ void ax88179_eth_stop(struct udevice *dev) priv->pkt_hdr =NULL ; } -int ax88179_eth_send (struct udevice *dev,void *packet,int length) +static int ax88179_eth_send (struct udevice *dev,void *packet,int length) {struct asix_private *priv =dev_get_priv (dev);return asix_send_common (&priv->ueth, priv, packet, length); } -int ax88179_eth_recv (struct udevice *dev,int flags,uchar **packetp) +static int ax88179_eth_recv (struct udevice *dev,int flags,uchar **packetp) {struct asix_private *priv =dev_get_priv (dev);struct ueth_data *ueth = &priv->ueth;
@@ -630,7 +630,7 @@ static int ax88179_free_pkt(struct udevice *dev, uchar *packet, int packet_len)return 0 ; } -int ax88179_write_hwaddr (struct udevice *dev) +static int ax88179_write_hwaddr (struct udevice *dev) {struct eth_pdata *pdata =dev_get_plat (dev);struct asix_private *priv =dev_get_priv (dev);
Signature · 1 line
2.52.0
Re: [PATCH 3/6] usb: eth: asix88179: Make functions static and align params
Quoted 4 lines · Jonas Karlman
Make internal functions static, align function parameters and drop unnecessary != 0 checks to cleanup code.
Signed-off-by Jonas Karlman <[email protected]>
PATCH 4/6 usb: eth: asix88179: Refactor asix_send_common() to closer match Linux
In reply to Jonas KarlmanRefactor asix_send_common() to closer match the Linux variant.
This change has no intended functional change, it only makes the code closer match the Linux ASIX AX88xxx driver.
--- drivers/usb/eth/asix88179.c | 43 +++++++++++++++---------------------- 1 file changed, 17 insertions(+), 26 deletions(-)
drivers/usb/eth/asix88179.c +17 -26
@@ -487,40 +487,31 @@ static int asix_send_common(struct ueth_data *dev,struct asix_private *dev_priv, void *packet, int length) { - int err; -u32 packet_len, tx_hdr2; -int actual_len, framesize; - ALLOC_CACHE_ALIGN_BUFFER(unsigned char, msg, - PKTSIZE + (2 * sizeof(packet_len))); + u32 tx_hdr1, tx_hdr2; +int actual_len, ret; + ALLOC_CACHE_ALIGN_BUFFER(unsigned char, msg, PKTSIZE + 8);debug ("** %s(), len %d\n" , __func__, length); - packet_len = length; -cpu_to_le32s (&packet_len); - -memcpy (msg, &packet_len,sizeof (packet_len)); - framesize = dev_priv->maxpacketsize; + tx_hdr1 = length; tx_hdr2 =0 ; -if (((length +8 ) % framesize) ==0 ) +if (((length +8 ) % dev_priv->maxpacketsize) ==0 ) tx_hdr2 |=0x80008000 ;/* Enable padding */ -cpu_to_le32s (&tx_hdr2); - -memcpy (msg +sizeof (packet_len), &tx_hdr2,sizeof (tx_hdr2)); +put_unaligned_le32 (tx_hdr1, msg); +put_unaligned_le32 (tx_hdr2, msg +4 ); +memcpy (msg +8 , packet, length); -memcpy (msg +sizeof (packet_len) +sizeof (tx_hdr2), - (void *)packet, length); + ret =usb_bulk_msg (dev->pusb_dev, +usb_sndbulkpipe (dev->pusb_dev, dev->ep_out), + msg, + length +8 , + &actual_len, +USB_BULK_SEND_TIMEOUT ); +debug ("Tx: len = %u, actual = %u, err = %d\n" , + length +8 , actual_len, ret); - err =usb_bulk_msg (dev->pusb_dev, -usb_sndbulkpipe (dev->pusb_dev, dev->ep_out), - (void *)msg, - length +sizeof (packet_len) +sizeof (tx_hdr2), - &actual_len, -USB_BULK_SEND_TIMEOUT ); -debug ("Tx: len = %zu, actual = %u, err = %d\n" , - length +sizeof (packet_len), actual_len, err); - -return err; +return ret; }static int ax88179_eth_start (struct udevice *dev)
Signature · 1 line
2.52.0
Re: [PATCH 4/6] usb: eth: asix88179: Refactor asix_send_common() to closer match Linux
Quoted 16 lines · Jonas Karlman
Refactor
asix_send_common()to closer match the Linux variant.This change has no intended functional change, it only makes the code closer match the Linux ASIX AX88xxx driver.
Signed-off-by Jonas Karlman <[email protected]>--- drivers/usb/eth/asix88179.c | 43 +++++++++++++++---------------------- 1 file changed, 17 insertions(+), 26 deletions(-)drivers/usb/eth/asix88179.c +0
-0@@ -487,40 +487,31 @@ static int asix_send_common(struct ueth_data *dev, struct asix_private *dev_priv,
drivers/usb/eth/asix88179.c static int asix_send_common(struct ueth_data *dev, · line 492
Quoted 10 lines
drivers/usb/eth/asix88179.c +3
-5void *packet, int length) { - int err; -u32 packet_len, tx_hdr2; -int actual_len, framesize; - ALLOC_CACHE_ALIGN_BUFFER(unsigned char, msg, - PKTSIZE + (2 * sizeof(packet_len))); +u32 tx_hdr1, tx_hdr2; +int actual_len, ret; + ALLOC_CACHE_ALIGN_BUFFER(unsigned char, msg, PKTSIZE + 8);
Please at least add a code comment about what this 8 means, it was clear from the previous sizeof() use, now it is a magic number.
PATCH 5/6 usb: eth: asix88179: Refactor ax88179_eth_recv() to closer match Linux
In reply to Jonas KarlmanRefactor ax88179_eth_recv() to closer match the Linux ASIX AX88xxx driver variant.
This change has a minor intended functional change, e.g. it enforces that packets flagged as DROP or CRC_ERR is fully skipped.
--- drivers/usb/eth/asix88179.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-)
drivers/usb/eth/asix88179.c +16 -17
@@ -547,6 +547,7 @@ static int ax88179_eth_recv(struct udevice *dev, int flags, uchar **packetp)struct ueth_data *ueth = &priv->ueth;int ret, len;u16 pkt_len; +u32 pkt_hdr;/* No packet left, get a new one */ if (priv->pkt_cnt ==0 ) {
@@ -570,34 +571,29 @@ static int ax88179_eth_recv(struct udevice *dev, int flags, uchar **packetp) }if (len <4 ) { -usb_ether_advance_rxbuf (ueth,-1 ); -return -EMSGSIZE ; - } - - rx_hdr = *(u32 *)(ptr + len -4 ); -le32_to_cpus (&rx_hdr); - - pkt_cnt = (u16 )rx_hdr; -if (pkt_cnt ==0 ) {usb_ether_advance_rxbuf (ueth,-1 );return 0 ; } + rx_hdr =get_unaligned_le32 (ptr + len -4 ); + pkt_cnt = (u16 )rx_hdr; hdr_off = (u16)(rx_hdr >>16 ); -if (hdr_off > len -4 ) { + +if (pkt_cnt ==0 || pkt_cnt *4 + hdr_off > len) {usb_ether_advance_rxbuf (ueth,-1 ); -return -EIO ; +return 0 ; } priv->pkt_cnt = pkt_cnt; priv->pkt_data = ptr; priv->pkt_hdr = (u32 *)(ptr + hdr_off); -debug ("%s: %d packets received, pkt header at %d\n" , - __func__, (int )priv->pkt_cnt, (int )hdr_off); +debug ("%s: %u packets received, pkt header at %u\n" , + __func__, priv->pkt_cnt, hdr_off); } -le32_to_cpus (priv->pkt_hdr); - pkt_len = (*priv->pkt_hdr >>16 ) &0x1fff ; + pkt_hdr = *priv->pkt_hdr; +le32_to_cpus (&pkt_hdr); + pkt_len = (pkt_hdr >>16 ) &0x1fff ; *packetp = priv->pkt_data +2 ;
@@ -605,8 +601,11 @@ static int ax88179_eth_recv(struct udevice *dev, int flags, uchar **packetp) priv->pkt_cnt--; priv->pkt_hdr++; -debug ("%s: return packet of %d bytes (%d packets left)\n" , - __func__, (int )pkt_len, priv->pkt_cnt); +if (pkt_hdr & (AX_RXHDR_DROP_ERR |AX_RXHDR_CRC_ERR )) + pkt_len =0 ; + +debug ("%s: return packet of %u bytes (%u packets left)\n" , + __func__, pkt_len, priv->pkt_cnt);return pkt_len; }
Signature · 1 line
2.52.0
Re: [PATCH 5/6] usb: eth: asix88179: Refactor ax88179_eth_recv() to closer match Linux
Quoted 5 lines · Jonas Karlman
Refactor
ax88179_eth_recv()to closer match the Linux ASIX AX88xxx driver variant.This change has a minor intended functional change, e.g. it enforces that packets flagged as DROP or
CRC_ERRis fully skipped.
Can that functional change be a separate patch ? I think it can, since it is only a bit of new code at the end of the function. If it can, please split the refactoring from new functionality.
PATCH 6/6 usb: eth: asix88179: Add read_rom_hwaddr() ops
In reply to Jonas KarlmanThe ASIX 88179 driver already has helpers for reading the MAC address.
Add support for the read_rom_hwaddr() ops using the existing asix_read_mac() helper function.
--- drivers/usb/eth/asix88179.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/usb/eth/asix88179.c +15 -0
@@ -629,6 +629,20 @@ static int ax88179_write_hwaddr(struct udevice *dev)return asix_write_mac (ueth, pdata->enetaddr); } +static int ax88179_read_rom_hwaddr (struct udevice *dev) +{ +struct eth_pdata *pdata =dev_get_plat (dev); +struct asix_private *priv =dev_get_priv (dev); +struct ueth_data *ueth = &priv->ueth; +int ret; + + ret =asix_read_mac (ueth, pdata->enetaddr); +if (ret) +memset (pdata->enetaddr,0 ,ETH_ALEN ); + +return 0 ; +} +static int ax88179_eth_probe (struct udevice *dev) {struct eth_pdata *pdata =dev_get_plat (dev);
@@ -666,6 +680,7 @@ static const struct eth_ops ax88179_eth_ops = { .free_pkt = ax88179_free_pkt, .stop = ax88179_eth_stop, .write_hwaddr = ax88179_write_hwaddr, + .read_rom_hwaddr = ax88179_read_rom_hwaddr, };U_BOOT_DRIVER (ax88179_eth) = {
Signature · 1 line
2.52.0
Re: [PATCH 6/6] usb: eth: asix88179: Add read_rom_hwaddr() ops
Quoted 6 lines · Jonas Karlman
The ASIX 88179 driver already has helpers for reading the MAC address.
Add support for the
read_rom_hwaddr()ops using the existingasix_read_mac()helper function.Signed-off-by Jonas Karlman <[email protected]>