Add NETIF_F_RXFCS and NETIF_F_RXALL features for the AX88179A and take a trailing FCS into account for MTU verification when checking packet length in rx_fixup(). In order to update AX_RX_CTL via ax88179_data->rxctl, writes to rxctl are protected by rx_ctl_lock. Count dropped packets and those with incorrect FCS. Suggested-by: Benjamin Larsson Signed-off-by: Birger Koblitz --- drivers/net/usb/ax88179_178a.c | 6 ++++- drivers/net/usb/ax88179_lib.c | 26 ++++++++++++++----- drivers/net/usb/ax88179_lib.h | 4 +++ drivers/net/usb/ax88179a_devices.c | 53 +++++++++++++++++++++++++++++++++++--- 4 files changed, 78 insertions(+), 11 deletions(-) diff --git a/drivers/net/usb/ax88179_178a.c b/drivers/net/usb/ax88179_178a.c index 88dce368eacfeee5df4062ff277041427f6ff475..520cb3c107028c1629168e7530ed863104dc2717 100644 --- a/drivers/net/usb/ax88179_178a.c +++ b/drivers/net/usb/ax88179_178a.c @@ -683,7 +683,9 @@ static int ax88179_bind(struct usbnet *dev, struct usb_interface *intf) return -ENOMEM; dev->driver_priv = ax179_data; - mutex_init(&ax179_data->medium_status_mutex); + ax179_data->dev = dev; + spin_lock_init(&ax179_data->rx_ctl_lock); + INIT_WORK(&ax179_data->set_multicast, ax88179_deferred_multicast_write); ax179_data->resume = ax88179_resume; ax179_data->suspend = ax88179_suspend; @@ -738,6 +740,8 @@ static void ax88179_unbind(struct usbnet *dev, struct usb_interface *intf) struct ax88179_data *ax179_data = dev->driver_priv; u16 tmp16; + cancel_work_sync(&ax179_data->set_multicast); + /* Configure RX control register => stop operation */ tmp16 = AX_RX_CTL_STOP; ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, &tmp16); diff --git a/drivers/net/usb/ax88179_lib.c b/drivers/net/usb/ax88179_lib.c index b57d5be56ecec5f818e03c552a29cf815f5079e6..d2a55f7d6f5364d7f351dcc295d3200aa1d9d9d6 100644 --- a/drivers/net/usb/ax88179_lib.c +++ b/drivers/net/usb/ax88179_lib.c @@ -347,6 +347,20 @@ int ax88179_set_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom, u8 return ret; } +void ax88179_deferred_multicast_write(struct work_struct *param) +{ + struct ax88179_data *data = container_of(param, struct ax88179_data, set_multicast); + struct usbnet *dev = data->dev; + u8 *m_filter; + + m_filter = ((u8 *)dev->data); + + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MULFLTARY, + AX_MCAST_FLTSIZE, AX_MCAST_FLTSIZE, m_filter); + + ax88179_write_u16(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, READ_ONCE(data->rxctl)); +} + void ax88179_set_multicast(struct net_device *net) { struct usbnet *dev = netdev_priv(net); @@ -356,6 +370,7 @@ void ax88179_set_multicast(struct net_device *net) data = dev->driver_priv; + spin_lock(&data->rx_ctl_lock); if (data->chip_version >= AX_VERSION_AX88179A) { rxctl = READ_ONCE(data->rxctl); rxctl &= ~(AX_RX_CTL_IPE | AX_RX_CTL_DROPCRCERR | AX_RX_CTL_PRO | @@ -390,16 +405,15 @@ void ax88179_set_multicast(struct net_device *net) *(m_filter + (crc_bits >> 3)) |= (1 << (crc_bits & 7)); } - ax88179_write_cmd_async(dev, AX_ACCESS_MAC, AX_MULFLTARY, - AX_MCAST_FLTSIZE, AX_MCAST_FLTSIZE, - m_filter); - rxctl |= AX_RX_CTL_AM; } WRITE_ONCE(data->rxctl, rxctl); - ax88179_write_cmd_async(dev, AX_ACCESS_MAC, AX_RX_CTL, - 2, 2, &data->rxctl); + + spin_unlock(&data->rx_ctl_lock); + + /* defer register writes to a sleepable context */ + schedule_work(&data->set_multicast); } int ax88179_set_features(struct net_device *net, netdev_features_t features) diff --git a/drivers/net/usb/ax88179_lib.h b/drivers/net/usb/ax88179_lib.h index 401c0bed3d28b4b94f0a0cad7509cd7087ef0639..db401389de306de2324c8176f04b8f796ef36475 100644 --- a/drivers/net/usb/ax88179_lib.h +++ b/drivers/net/usb/ax88179_lib.h @@ -292,6 +292,7 @@ enum ax_chip_version { struct ax88179_data { struct mutex medium_status_mutex; /* protect AX_MEDIUM_STATUS_MODE */ + spinlock_t rx_ctl_lock; /* protect AX_RX_CTL */ u8 eee_enabled; u8 eee_active; u16 rxctl; @@ -315,6 +316,8 @@ struct ax88179_data { struct phy_device *phydev; struct phylink *phylink; struct phylink_config phylink_config; + struct usbnet *dev; + struct work_struct set_multicast; int (*resume)(struct usb_interface *intf); int (*suspend)(struct usb_interface *intf, pm_message_t message); }; @@ -352,6 +355,7 @@ int ax88179_change_mtu(struct net_device *net, int new_mtu); int ax88179_set_mac_addr(struct net_device *net, void *p); int ax88179_suspend_wrapper(struct usb_interface *intf, pm_message_t message); int ax88179_resume_wrapper(struct usb_interface *intf); +void ax88179_deferred_multicast_write(struct work_struct *param); extern const struct driver_info ax88179a_info; extern const struct driver_info ax88772d_info; diff --git a/drivers/net/usb/ax88179a_devices.c b/drivers/net/usb/ax88179a_devices.c index 7192674690749bcf2953d774630e8de32ed5c386..72be6fb7b817cce153ed050360874f4132172d3a 100644 --- a/drivers/net/usb/ax88179a_devices.c +++ b/drivers/net/usb/ax88179a_devices.c @@ -717,10 +717,12 @@ static int ax88179a_mii_ioctl(struct net_device *net, struct ifreq *rq, int cmd) static int ax88179a_set_features(struct net_device *net, netdev_features_t features) { struct usbnet *dev = netdev_priv(net); + struct ax88179_data *ax179_data; netdev_features_t changed; int ret; u8 tmp; + ax179_data = dev->driver_priv; changed = net->features ^ features; ret = ax88179_set_features(net, features); @@ -780,6 +782,25 @@ static int ax88179a_set_features(struct net_device *net, netdev_features_t featu if (ret < 0) return ret; } + + if (changed & (NETIF_F_RXFCS | NETIF_F_RXALL)) { + u16 rxctl; + + spin_lock(&ax179_data->rx_ctl_lock); + rxctl = READ_ONCE(ax179_data->rxctl); + if (features & (NETIF_F_RXFCS | NETIF_F_RXALL)) + rxctl |= AX_RX_CTL_DROPCRCERR; + else + rxctl &= ~AX_RX_CTL_DROPCRCERR; + WRITE_ONCE(ax179_data->rxctl, rxctl); + spin_unlock(&ax179_data->rx_ctl_lock); + ret = ax88179_write_u16(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, + READ_ONCE(ax179_data->rxctl)); + + if (ret < 0) + return ret; + } + return 0; } @@ -852,8 +873,8 @@ static int ax88179a_bind(struct usbnet *dev, struct usb_interface *intf) ax179_data->fw_version[2], ax179_data->fw_version[3]); /* The AX88279 requires both the AX_RX_CTL_IPE and AX_RX_CTL_DROPCRCERR - * bits set in AX_RX_CTL for creating correct RX-URBs. AX_RX_CTL_DROPCRCERR - * is anyway set for all chips, make sure AX_RX_CTL_IPE is set via ip_align. + * bits set in AX_RX_CTL for creating correct RX-URBs. Make sure + * AX_RX_CTL_IPE is set via ip_align. * Also configure eeprom access parameters. */ if (ax179_data->chip_version == AX_VERSION_AX88279) { @@ -894,6 +915,9 @@ static int ax88179a_bind(struct usbnet *dev, struct usb_interface *intf) dev->net->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM | NETIF_F_TSO; + if (ax179_data->chip_version == AX_VERSION_AX88179A) + dev->net->hw_features |= NETIF_F_RXFCS | NETIF_F_RXALL; + netif_set_tso_max_size(dev->net, 16384); /* Enable Transmission of Link Speed byte in interrupt URB */ @@ -1039,9 +1063,14 @@ static int ax88179a_rx_fixup(struct usbnet *dev, struct sk_buff *skb) pkt_end = 0; while (pkt_cnt--) { u64 pkt_desc = get_unaligned_le64(pkt_desc_ptr); + netdev_features_t features = dev->net->features; u32 pkt_len_plus_padd; + u32 fcs_trailer = 0; u32 pkt_len; + if (features & (NETIF_F_RXFCS | NETIF_F_RXALL)) + fcs_trailer = ETH_FCS_LEN; + pkt_len = FIELD_GET(AX179A_RX_PD_LEN, pkt_desc); pkt_len -= (ax179_data->ip_align ? 2 : 0); pkt_len_plus_padd = ((pkt_len + 7 + (ax179_data->ip_align ? 2 : 0)) & 0x7FFF8); @@ -1050,10 +1079,19 @@ static int ax88179a_rx_fixup(struct usbnet *dev, struct sk_buff *skb) if (pkt_end > hdr_off || (pkt_cnt == 0 && pkt_end != hdr_off)) goto err; - if (pkt_desc & AX179A_RX_PD_DROP || !(pkt_desc & AX179A_RX_PD_RX_OK) || - pkt_len > (dev->hard_mtu + AX179A_RX_HW_PAD) || pkt_len < 2 + ETH_HLEN) { + if (((pkt_desc & AX179A_RX_PD_DROP || !(pkt_desc & AX179A_RX_PD_RX_OK)) && + !(features & NETIF_F_RXALL)) || + pkt_len > dev->hard_mtu + AX179A_RX_HW_PAD + fcs_trailer || + pkt_len < 2 + ETH_HLEN + fcs_trailer) { skb_pull(skb, pkt_len_plus_padd); + if (pkt_desc & AX179A_RX_PD_DROP) + dev->net->stats.rx_dropped++; + + if (!(pkt_desc & AX179A_RX_PD_RX_OK)) { + dev->net->stats.rx_crc_errors++; + dev->net->stats.rx_errors++; + } /* Next RX Packet Descriptor */ pkt_desc_ptr++; continue; @@ -1063,6 +1101,9 @@ static int ax88179a_rx_fixup(struct usbnet *dev, struct sk_buff *skb) if (!ax_skb) goto err; + if (!(features & NETIF_F_RXFCS)) + pkt_len -= fcs_trailer; + skb_put(ax_skb, pkt_len); memcpy(ax_skb->data, skb->data + (ax179_data->ip_align ? AX179A_RX_HW_PAD : 0), pkt_len); @@ -1216,6 +1257,7 @@ static int ax88179a_reset(struct usbnet *dev) ax88179_write_u8(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, *tmp); /* Configure RX control register => start operation */ + spin_lock(&ax179_data->rx_ctl_lock); rxctl = AX_RX_CTL_START | AX_RX_CTL_AP | AX_RX_CTL_AMALL | AX_RX_CTL_AB; if (ax179_data->chip_version == AX_VERSION_AX88279) rxctl |= AX_RX_CTL_DROPCRCERR; @@ -1223,7 +1265,10 @@ static int ax88179a_reset(struct usbnet *dev) rxctl |= AX_RX_CTL_IPE; if (dev->net->flags & IFF_PROMISC) rxctl |= AX_RX_CTL_PRO; + if (dev->net->features & (NETIF_F_RXFCS | NETIF_F_RXALL)) + rxctl |= AX_RX_CTL_DROPCRCERR; WRITE_ONCE(ax179_data->rxctl, rxctl); + spin_unlock(&ax179_data->rx_ctl_lock); ax88179_write_u16(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, rxctl); if (ax179_data->chip_version < AX_VERSION_AX88179A) -- 2.47.3