net: bcmgenet: Turn on offloads by default
Subsystems (3)
Doug Berger
maintainerv2 cover net: bcmgenet: Turn on offloads by default
This commit stack is based on Florian's commit 4e8aedfe78c7 ("net:
systemport: Turn on offloads by default") and enables the offloads for the bcmgenet driver by default.
The first commit adds support for the HIGHDMA feature to the driver.
The second converts the Tx checksum implementation to use the generic hardware logic rather than the deprecated IP centric methods.
The third modifies the Rx checksum implementation to use the hardware offload to compute the complete checksum rather than filtering out bad packets detected by the hardware's IP centric implementation. This may increase processing load by passing bad packets to the network stack, but it provides for more flexible handling of packets by the network stack without requiring software computation of the checksum.
The remaining commits mirror the extensions Florian made to the sysport driver to retain symmetry with that driver and to make the benefits of the hardware offloads more ubiquitous.
Doug Berger (8):
net: bcmgenet: enable NETIF_F_HIGHDMA flag
net: bcmgenet: enable NETIF_F_HW_CSUM feature
net: bcmgenet: use CHECKSUM_COMPLETE for NETIF_F_RXCSUM
net: bcmgenet: Refactor bcmgenet_set_features()
net: bcmgenet: Utilize bcmgenet_set_features() during resume/open
net: bcmgenet: Turn on offloads by default
net: bcmgenet: Be drop monitor friendly while re-allocating headroom
net: bcmgenet: Add software counters to track reallocations
drivers/net/ethernet/broadcom/genet/bcmgenet.c | 113 ++++++++++++++----------- drivers/net/ethernet/broadcom/genet/bcmgenet.h | 4 +- 2 files changed, 67 insertions(+), 50 deletions(-)
Signature · 6 lines
Changes in v2: - Added "Reviewed-by" where given - Removed no longer used private structure member dma_rx_chk_bit - Used __force casting to remove sparse warnings 2.7.4
Doug Berger
maintainerPATCH v2 1/8 net: bcmgenet: enable NETIF_F_HIGHDMA flag
This commit configures the DMA masks for the GENET driver and sets the NETIF_F_HIGHDMA flag to report support of the feature.
--- drivers/net/ethernet/broadcom/genet/bcmgenet.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/net/ethernet/broadcom/genet/bcmgenet.c +10 -2
@@ -2,7 +2,7 @@/* * Broadcom GENET (Gigabit Ethernet) controller driver * -* Copyright (c) 2014-2017 Broadcom +* Copyright (c) 2014-2019 Broadcom */ #define pr_fmt (fmt) "bcmgenet: " fmt
@@ -3537,7 +3537,7 @@ static int bcmgenet_probe(struct platform_device *pdev)/* Set hardware features */ dev->hw_features |=NETIF_F_SG |NETIF_F_IP_CSUM | -NETIF_F_IPV6_CSUM |NETIF_F_RXCSUM ; +NETIF_F_IPV6_CSUM |NETIF_F_HIGHDMA |NETIF_F_RXCSUM ;/* Request the WOL interrupt and advertise suspend if available */ priv->wol_irq_disabled = true;
@@ -3574,6 +3574,14 @@ static int bcmgenet_probe(struct platform_device *pdev)bcmgenet_set_hw_params (priv); + err = -EIO ; +if (priv->hw_params->flags &GENET_HAS_40BITS ) + err =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (40 )); +if (err) + err =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (32 )); +if (err) + goto err; +/* Mii wait queue */ init_waitqueue_head (&priv->wq);/* Always use RX_BUF_LENGTH (2KB) buffer for all chips */
Signature · 1 line
2.7.4
Doug Berger
maintainerPATCH v2 2/8 net: bcmgenet: enable NETIF_F_HW_CSUM feature
In reply to Doug BergerThe GENET hardware should be capable of generating IP checksums using the NETIF_F_HW_CSUM feature, so switch to using that feature instead of the depricated NETIF_F_IP_CSUM and NETIF_F_IPV6_CSUM.
--- drivers/net/ethernet/broadcom/genet/bcmgenet.c | 29 +++++++++++--------------- 1 file changed, 12 insertions(+), 17 deletions(-)
drivers/net/ethernet/broadcom/genet/bcmgenet.c +12 -17
@@ -549,7 +549,7 @@ static int bcmgenet_set_tx_csum(struct net_device *dev, tbuf_ctrl =bcmgenet_tbuf_ctrl_get (priv); rbuf_ctrl =bcmgenet_rbuf_readl (priv,RBUF_CTRL ); - desc_64b_en = !!(wanted & (NETIF_F_IP_CSUM |NETIF_F_IPV6_CSUM )); + desc_64b_en = !!(wanted &NETIF_F_HW_CSUM );/* enable 64 bytes descriptor in both directions (RBUF and TBUF) */ if (desc_64b_en) {
@@ -574,7 +574,7 @@ static int bcmgenet_set_features(struct net_device *dev,netdev_features_t wanted = dev->wanted_features;int ret =0 ; -if (changed & (NETIF_F_IP_CSUM |NETIF_F_IPV6_CSUM )) +if (changed &NETIF_F_HW_CSUM ) ret =bcmgenet_set_tx_csum (dev, wanted);if (changed & (NETIF_F_RXCSUM )) ret =bcmgenet_set_rx_csum (dev, wanted);
@@ -1516,24 +1516,19 @@ static struct sk_buff *bcmgenet_put_tx_csum(struct net_device *dev, ip_proto =ipv6_hdr (skb)->nexthdr;break ;default : -return skb; +/* don't use UDP flag */ + ip_proto =0 ; +break ; } offset =skb_checksum_start_offset (skb) -sizeof (*status); tx_csum_info = (offset <<STATUS_TX_CSUM_START_SHIFT ) | - (offset + skb->csum_offset); + (offset + skb->csum_offset) | +STATUS_TX_CSUM_LV ; -/* Set the length valid bit for TCP and UDP and just set -* the special UDP flag for IPv4, else just set to 0. -*/ -if (ip_proto ==IPPROTO_TCP || ip_proto ==IPPROTO_UDP ) { - tx_csum_info |=STATUS_TX_CSUM_LV ; -if (ip_proto ==IPPROTO_UDP && - ip_ver ==htons (ETH_P_IP )) - tx_csum_info |=STATUS_TX_CSUM_PROTO_UDP ; - }else { - tx_csum_info =0 ; - } +/* Set the special UDP flag for UDP */ +if (ip_proto ==IPPROTO_UDP ) + tx_csum_info |=STATUS_TX_CSUM_PROTO_UDP ; status->tx_csum_info = tx_csum_info; }
@@ -3536,8 +3531,8 @@ static int bcmgenet_probe(struct platform_device *pdev) priv->msg_enable =netif_msg_init (-1 ,GENET_MSG_DEFAULT );/* Set hardware features */ - dev->hw_features |=NETIF_F_SG |NETIF_F_IP_CSUM | -NETIF_F_IPV6_CSUM |NETIF_F_HIGHDMA |NETIF_F_RXCSUM ; + dev->hw_features |=NETIF_F_SG |NETIF_F_HIGHDMA |NETIF_F_HW_CSUM | +NETIF_F_RXCSUM ;/* Request the WOL interrupt and advertise suspend if available */ priv->wol_irq_disabled = true;
Signature · 1 line
2.7.4
Re: [PATCH net-next v2 2/8] net: bcmgenet: enable NETIF_F_HW_CSUM feature
Quoted 5 lines · Doug Berger
The GENET hardware should be capable of generating IP checksums using the
NETIF_F_HW_CSUMfeature, so switch to using that feature instead of the depricatedNETIF_F_IP_CSUMandNETIF_F_IPV6_CSUM.Signed-off-by Doug Berger <[email protected]>
Signature · 1 line
Florian
Doug Berger
maintainerPATCH v2 3/8 net: bcmgenet: use CHECKSUM_COMPLETE for NETIF_F_RXCSUM
In reply to Doug BergerThis commit updates the Rx checksum offload behavior of the driver to use the more generic CHECKSUM_COMPLETE method that supports all protocols over the CHECKSUM_UNNECESSARY method that only applies to some protocols known by the hardware.
This behavior is perceived to be superior.
--- drivers/net/ethernet/broadcom/genet/bcmgenet.c | 19 +++++++------------ drivers/net/ethernet/broadcom/genet/bcmgenet.h | 2 +- 2 files changed, 8 insertions(+), 13 deletions(-)
drivers/net/ethernet/broadcom/genet/bcmgenet.c +7 -12
@@ -521,7 +521,7 @@ static int bcmgenet_set_rx_csum(struct net_device *dev,/* enable rx checksumming */ if (rx_csum_en) - rbuf_chk_ctrl |=RBUF_RXCHK_EN ; + rbuf_chk_ctrl |=RBUF_RXCHK_EN |RBUF_L3_PARSE_DIS ;else rbuf_chk_ctrl &= ~RBUF_RXCHK_EN ; priv->desc_rxchk_en = rx_csum_en;
@@ -1739,7 +1739,6 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring,unsigned int bytes_processed =0 ;unsigned int p_index, mask;unsigned int discards; -unsigned int chksum_ok =0 ;/* Clear status before servicing to reduce spurious interrupts */ if (ring->index ==DESC_INDEX ) {
@@ -1790,9 +1789,15 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring,dmadesc_get_length_status (priv, cb->bd_addr); }else {struct status_64 *status; +__be16 rx_csum; status = (struct status_64 *)skb->data; dma_length_status = status->length_status; + rx_csum = (__force __be16)(status->rx_csum &0xffff ); +if (priv->desc_rxchk_en) { + skb->csum = (__force __wsum )ntohs (rx_csum); + skb->ip_summed =CHECKSUM_COMPLETE ; + } }/* DMA flags and length are still valid no matter how
@@ -1835,18 +1840,12 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring, goto next; }/* error packet */ - chksum_ok = (dma_flag & priv->dma_rx_chk_bit) && - priv->desc_rxchk_en; -skb_put (skb, len);if (priv->desc_64b_en) {skb_pull (skb,64 ); len -=64 ; } -if (likely (chksum_ok)) - skb->ip_summed =CHECKSUM_UNNECESSARY ; -/* remove hardware 2bytes added for IP alignment */ skb_pull (skb,2 ); len -=2 ;
@@ -3322,19 +3321,15 @@ static void bcmgenet_set_hw_params(struct bcmgenet_priv *priv)if (GENET_IS_V5 (priv) ||GENET_IS_V4 (priv)) { bcmgenet_dma_regs = bcmgenet_dma_regs_v3plus; genet_dma_ring_regs = genet_dma_ring_regs_v4; - priv->dma_rx_chk_bit =DMA_RX_CHK_V3PLUS ; }else if (GENET_IS_V3 (priv)) { bcmgenet_dma_regs = bcmgenet_dma_regs_v3plus; genet_dma_ring_regs = genet_dma_ring_regs_v123; - priv->dma_rx_chk_bit =DMA_RX_CHK_V3PLUS ; }else if (GENET_IS_V2 (priv)) { bcmgenet_dma_regs = bcmgenet_dma_regs_v2; genet_dma_ring_regs = genet_dma_ring_regs_v123; - priv->dma_rx_chk_bit =DMA_RX_CHK_V12 ; }else if (GENET_IS_V1 (priv)) { bcmgenet_dma_regs = bcmgenet_dma_regs_v1; genet_dma_ring_regs = genet_dma_ring_regs_v123; - priv->dma_rx_chk_bit =DMA_RX_CHK_V12 ; }/* enum genet_version starts at 1 */
drivers/net/ethernet/broadcom/genet/bcmgenet.h +1 -1
@@ -251,6 +251,7 @@ struct bcmgenet_mib_counters {#define RBUF_CHK_CTRL 0x14#define RBUF_RXCHK_EN (1 << 0)#define RBUF_SKIP_FCS (1 << 4) +#define RBUF_L3_PARSE_DIS (1 << 5)#define RBUF_ENERGY_CTRL 0x9c#define RBUF_EEE_EN (1 << 0)
@@ -663,7 +664,6 @@ struct bcmgenet_priv {bool desc_rxchk_en;bool crc_fwd_en; -unsigned int dma_rx_chk_bit;u32 dma_max_burst_length;u32 msg_enable;
Signature · 1 line
2.7.4
Re: [PATCH net-next v2 3/8] net: bcmgenet: use CHECKSUM_COMPLETE for NETIF_F_RXCSUM
Quoted 8 lines · Doug Berger
This commit updates the Rx checksum offload behavior of the driver to use the more generic
CHECKSUM_COMPLETEmethod that supports all protocols over theCHECKSUM_UNNECESSARYmethod that only applies to some protocols known by the hardware.This behavior is perceived to be superior.
Signed-off-by Doug Berger <[email protected]>
Signature · 1 line
Florian
Doug Berger
maintainerPATCH v2 4/8 net: bcmgenet: Refactor bcmgenet_set_features()
In reply to Doug BergerIn preparation for unconditionally enabling TX and RX checksum offloads, refactor bcmgenet_set_features() a bit such that __netdev_update_features() during register_netdev() can make sure that features are correctly programmed during network device registration.
Since we can now be called during register_netdev() with clocks gated, we need to temporarily turn them on/off in order to have a successful register programming.
We also move the CRC forward setting read into bcmgenet_set_features() since priv->crc_fwd_en matters while turning on RX checksum offload, that way we are guaranteed they are in sync in case we ever add support for NETIF_F_RXFCS at some point in the future.
--- drivers/net/ethernet/broadcom/genet/bcmgenet.c | 38 +++++++++++++------------- 1 file changed, 19 insertions(+), 19 deletions(-)
drivers/net/ethernet/broadcom/genet/bcmgenet.c +19 -19
@@ -508,8 +508,8 @@ static int bcmgenet_set_link_ksettings(struct net_device *dev,return phy_ethtool_ksettings_set (dev->phydev, cmd); } -static int bcmgenet_set_rx_csum (struct net_device *dev, -netdev_features_t wanted) +static void bcmgenet_set_rx_csum (struct net_device *dev, +netdev_features_t wanted) {struct bcmgenet_priv *priv =netdev_priv (dev);u32 rbuf_chk_ctrl;
@@ -535,12 +535,10 @@ static int bcmgenet_set_rx_csum(struct net_device *dev, rbuf_chk_ctrl &= ~RBUF_SKIP_FCS ;bcmgenet_rbuf_writel (priv, rbuf_chk_ctrl,RBUF_CHK_CTRL ); - -return 0 ; } -static int bcmgenet_set_tx_csum (struct net_device *dev, -netdev_features_t wanted) +static void bcmgenet_set_tx_csum (struct net_device *dev, +netdev_features_t wanted) {struct bcmgenet_priv *priv =netdev_priv (dev);bool desc_64b_en;
@@ -563,21 +561,27 @@ static int bcmgenet_set_tx_csum(struct net_device *dev,bcmgenet_tbuf_ctrl_set (priv, tbuf_ctrl);bcmgenet_rbuf_writel (priv, rbuf_ctrl,RBUF_CTRL ); - -return 0 ; }static int bcmgenet_set_features (struct net_device *dev,netdev_features_t features) { -netdev_features_t changed = features ^ dev->features; -netdev_features_t wanted = dev->wanted_features; -int ret =0 ; +struct bcmgenet_priv *priv =netdev_priv (dev); +u32 reg; +int ret; + + ret =clk_prepare_enable (priv->clk); +if (ret) +return ret; + +/* Make sure we reflect the value of CRC_CMD_FWD */ + reg =bcmgenet_umac_readl (priv,UMAC_CMD ); + priv->crc_fwd_en = !!(reg &CMD_CRC_FWD ); -if (changed &NETIF_F_HW_CSUM ) - ret =bcmgenet_set_tx_csum (dev, wanted); -if (changed & (NETIF_F_RXCSUM )) - ret =bcmgenet_set_rx_csum (dev, wanted); +bcmgenet_set_tx_csum (dev, features); +bcmgenet_set_rx_csum (dev, features); + +clk_disable_unprepare (priv->clk);return ret; }
@@ -2880,10 +2884,6 @@ static int bcmgenet_open(struct net_device *dev)init_umac (priv); -/* Make sure we reflect the value of CRC_CMD_FWD */ - reg =bcmgenet_umac_readl (priv,UMAC_CMD ); - priv->crc_fwd_en = !!(reg &CMD_CRC_FWD ); -bcmgenet_set_hw_addr (priv, dev->dev_addr);if (priv->internal_phy) {
Signature · 1 line
2.7.4
Doug Berger
maintainerPATCH v2 5/8 net: bcmgenet: Utilize bcmgenet_set_features() during resume/open
In reply to Doug BergerDuring driver resume and open, the HW may have lost its context/state, utilize bcmgenet_set_features() to make sure we do restore the correct set of features that were previously configured.
--- drivers/net/ethernet/broadcom/genet/bcmgenet.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/net/ethernet/broadcom/genet/bcmgenet.c +8 -0
@@ -2884,6 +2884,11 @@ static int bcmgenet_open(struct net_device *dev)init_umac (priv); +/* Apply features again in case we changed them while interface was +* down +*/ +bcmgenet_set_features (dev, dev->features); +bcmgenet_set_hw_addr (priv, dev->dev_addr);if (priv->internal_phy) {
@@ -3687,6 +3692,9 @@ static int bcmgenet_resume(struct device *d)genphy_config_aneg (dev->phydev);bcmgenet_mii_config (priv->dev, false); +/* Restore enabled features */ +bcmgenet_set_features (dev, dev->features); +bcmgenet_set_hw_addr (priv, dev->dev_addr);if (priv->internal_phy) {
Signature · 1 line
2.7.4
Doug Berger
maintainerPATCH v2 6/8 net: bcmgenet: Turn on offloads by default
In reply to Doug BergerWe can turn on the RX/TX checksum offloads and the scatter/gather features by default and make sure that those are properly reflected back to e.g: stacked devices such as VLAN.
--- drivers/net/ethernet/broadcom/genet/bcmgenet.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/net/ethernet/broadcom/genet/bcmgenet.c +5 -3
@@ -3530,9 +3530,11 @@ static int bcmgenet_probe(struct platform_device *pdev) priv->msg_enable =netif_msg_init (-1 ,GENET_MSG_DEFAULT ); -/* Set hardware features */ - dev->hw_features |=NETIF_F_SG |NETIF_F_HIGHDMA |NETIF_F_HW_CSUM | -NETIF_F_RXCSUM ; +/* Set default features */ + dev->features |=NETIF_F_SG |NETIF_F_HIGHDMA |NETIF_F_HW_CSUM | +NETIF_F_RXCSUM ; + dev->hw_features |= dev->features; + dev->vlan_features |= dev->features;/* Request the WOL interrupt and advertise suspend if available */ priv->wol_irq_disabled = true;
Signature · 1 line
2.7.4
Doug Berger
maintainerPATCH v2 7/8 net: bcmgenet: Be drop monitor friendly while re-allocating headroom
In reply to Doug BergerDuring bcmgenet_put_tx_csum() make sure we differentiate a SKB headroom re-allocation failure from the normal swap and replace path.
--- drivers/net/ethernet/broadcom/genet/bcmgenet.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/broadcom/genet/bcmgenet.c +2 -1
@@ -1499,11 +1499,12 @@ static struct sk_buff *bcmgenet_put_tx_csum(struct net_device *dev,* enough headroom for us to insert 64B status block. */ new_skb =skb_realloc_headroom (skb,sizeof (*status)); -dev_kfree_skb (skb);if (!new_skb) { +dev_kfree_skb_any (skb); dev->stats.tx_dropped++;return NULL ; } +dev_consume_skb_any (skb); skb = new_skb; }
Signature · 1 line
2.7.4
Doug Berger
maintainerPATCH v2 8/8 net: bcmgenet: Add software counters to track reallocations
In reply to Doug BergerWhen inserting the TSB, keep track of how many times we had to do it and if there was a failure in doing so, this helps profile the driver for possibly incorrect headroom settings.
--- drivers/net/ethernet/broadcom/genet/bcmgenet.c | 6 ++++++ drivers/net/ethernet/broadcom/genet/bcmgenet.h | 2 ++ 2 files changed, 8 insertions(+)
drivers/net/ethernet/broadcom/genet/bcmgenet.c +6 -0
@@ -861,6 +861,9 @@ static const struct bcmgenet_stats bcmgenet_gstrings_stats[] = {STAT_GENET_SOFT_MIB ("alloc_rx_buff_failed" , mib.alloc_rx_buff_failed),STAT_GENET_SOFT_MIB ("rx_dma_failed" , mib.rx_dma_failed),STAT_GENET_SOFT_MIB ("tx_dma_failed" , mib.tx_dma_failed), +STAT_GENET_SOFT_MIB ("tx_realloc_tsb" , mib.tx_realloc_tsb), +STAT_GENET_SOFT_MIB ("tx_realloc_tsb_failed" , + mib.tx_realloc_tsb_failed),/* Per TX queues */ STAT_GENET_Q (0 ), STAT_GENET_Q(1),
@@ -1487,6 +1490,7 @@ static void bcmgenet_tx_reclaim_all(struct net_device *dev)static struct sk_buff *bcmgenet_put_tx_csum (struct net_device *dev,struct sk_buff *skb) { +struct bcmgenet_priv *priv =netdev_priv (dev);struct status_64 *status =NULL ;struct sk_buff *new_skb;u16 offset;
@@ -1501,11 +1505,13 @@ static struct sk_buff *bcmgenet_put_tx_csum(struct net_device *dev, new_skb =skb_realloc_headroom (skb,sizeof (*status));if (!new_skb) {dev_kfree_skb_any (skb); + priv->mib.tx_realloc_tsb_failed++; dev->stats.tx_dropped++;return NULL ; }dev_consume_skb_any (skb); skb = new_skb; + priv->mib.tx_realloc_tsb++; }skb_push (skb,sizeof (*status));
drivers/net/ethernet/broadcom/genet/bcmgenet.h +2 -0
@@ -144,6 +144,8 @@ struct bcmgenet_mib_counters {u32 alloc_rx_buff_failed;u32 rx_dma_failed;u32 tx_dma_failed; +u32 tx_realloc_tsb; +u32 tx_realloc_tsb_failed; };#define UMAC_HD_BKP_CTRL 0x004
Signature · 1 line
2.7.4
David Miller
maintainerFrom: Doug Berger <[email protected]>
Date: Tue, 17 Dec 2019 16:51:07 -0800
Quoted 16 lines
This commit stack is based on Florian's commit
4e8aedfe78c7("net:
systemport: Turn on offloads by default") and enables the offloads for the bcmgenet driver by default.The first commit adds support for the HIGHDMA feature to the driver.
The second converts the Tx checksum implementation to use the generic hardware logic rather than the deprecated IP centric methods.
The third modifies the Rx checksum implementation to use the hardware offload to compute the complete checksum rather than filtering out bad packets detected by the hardware's IP centric implementation. This may increase processing load by passing bad packets to the network stack, but it provides for more flexible handling of packets by the network stack without requiring software computation of the checksum.
Quoted 3 lines
The remaining commits mirror the extensions Florian made to the sysport driver to retain symmetry with that driver and to make the benefits of the hardware offloads more ubiquitous.
Series applied, thanks.