在 2021/8/11 22:46, Jian Shen 写道:
Use netdev_feature_xxx helpers to replace the logical operation for netdev features.
Signed-off-by: Jian Shen shenjian15@huawei.com
drivers/net/ethernet/amd/amd8111e.c | 8 +++- drivers/net/ethernet/amd/xgbe/xgbe-dev.c | 20 ++++++--- drivers/net/ethernet/amd/xgbe/xgbe-drv.c | 72 ++++++++++++++++++++----------- drivers/net/ethernet/amd/xgbe/xgbe-main.c | 68 ++++++++++++++++------------- 4 files changed, 103 insertions(+), 65 deletions(-)
diff --git a/drivers/net/ethernet/amd/amd8111e.c b/drivers/net/ethernet/amd/amd8111e.c index 92e4246..1757eac 100644 --- a/drivers/net/ethernet/amd/amd8111e.c +++ b/drivers/net/ethernet/amd/amd8111e.c @@ -1790,7 +1790,9 @@ static int amd8111e_probe_one(struct pci_dev *pdev, SET_NETDEV_DEV(dev, &pdev->dev);
#if AMD8111E_VLAN_TAG_USED
- dev->features |= NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX;
netdev_feature_set_bits(NETIF_F_HW_VLAN_CTAG_TX |
NETIF_F_HW_VLAN_CTAG_RX,
&dev->features);
#endif
lp = netdev_priv(dev);
@@ -1829,7 +1831,9 @@ static int amd8111e_probe_one(struct pci_dev *pdev, netif_napi_add(dev, &lp->napi, amd8111e_rx_poll, 32);
#if AMD8111E_VLAN_TAG_USED
- dev->features |= NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX;
- netdev_feature_set_bits(NETIF_F_HW_VLAN_CTAG_TX |
NETIF_F_HW_VLAN_CTAG_RX,
#endif /* Probe the external PHY */ amd8111e_probe_ext_phy(dev);&dev->features);
diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c index d5fd49d..6e1a5fb 100644 --- a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c +++ b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c @@ -449,7 +449,8 @@ static void xgbe_config_rss(struct xgbe_prv_data *pdata) if (!pdata->hw_feat.rss) return;
- if (pdata->netdev->features & NETIF_F_RXHASH)
- if (netdev_feature_test_bit(NETIF_F_RXHASH_BIT,
ret = xgbe_enable_rss(pdata); else ret = xgbe_disable_rss(pdata);pdata->netdev->features))
@@ -948,7 +949,8 @@ static int xgbe_set_promiscuous_mode(struct xgbe_prv_data *pdata, if (enable) { xgbe_disable_rx_vlan_filtering(pdata); } else {
if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER)
if (netdev_feature_test_bit(NETIF_F_HW_VLAN_CTAG_FILTER_BIT,
}pdata->netdev->features)) xgbe_enable_rx_vlan_filtering(pdata);
@@ -1990,7 +1992,7 @@ static int xgbe_dev_read(struct xgbe_channel *channel) rdata->rx.len = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, PL);
/* Set checksum done indicator as appropriate */
- if (netdev->features & NETIF_F_RXCSUM) {
- if (netdev_feature_test_bit(NETIF_F_RXCSUM_BIT, netdev->features)) { XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, CSUM_DONE, 1); XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
@@ -2021,7 +2023,8 @@ static int xgbe_dev_read(struct xgbe_channel *channel) if (!err || !etlt) { /* No error if err is 0 or etlt is 0 */ if ((etlt == 0x09) &&
(netdev->features & NETIF_F_HW_VLAN_CTAG_RX)) {
(netdev_feature_test_bit(NETIF_F_HW_VLAN_CTAG_RX_BIT,
netdev->features))) { XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, VLAN_CTAG, 1); packet->vlan_ctag = XGMAC_GET_BITS_LE(rdesc->desc0,
@@ -2823,7 +2826,8 @@ static void xgbe_config_mac_speed(struct xgbe_prv_data *pdata)
static void xgbe_config_checksum_offload(struct xgbe_prv_data *pdata) {
- if (pdata->netdev->features & NETIF_F_RXCSUM)
- if (netdev_feature_test_bit(NETIF_F_RXCSUM_BIT,
xgbe_enable_rx_csum(pdata); else xgbe_disable_rx_csum(pdata);pdata->netdev->features))
@@ -2838,12 +2842,14 @@ static void xgbe_config_vlan_support(struct xgbe_prv_data *pdata) /* Set the current VLAN Hash Table register value */ xgbe_update_vlan_hash_table(pdata);
- if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER)
- if (netdev_feature_test_bit(NETIF_F_HW_VLAN_CTAG_FILTER_BIT,
xgbe_enable_rx_vlan_filtering(pdata); else xgbe_disable_rx_vlan_filtering(pdata);pdata->netdev->features))
- if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
- if (netdev_feature_test_bit(NETIF_F_HW_VLAN_CTAG_RX_BIT,
xgbe_enable_rx_vlan_stripping(pdata); else xgbe_disable_rx_vlan_stripping(pdata);pdata->netdev->features))
diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c index dff9eec..cbf23e0 100644 --- a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c +++ b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c @@ -2188,37 +2188,46 @@ static void xgbe_fix_features(struct net_device *netdev, struct xgbe_prv_data *pdata = netdev_priv(netdev); netdev_features_t vxlan_base;
- vxlan_base = NETIF_F_GSO_UDP_TUNNEL | NETIF_F_RX_UDP_TUNNEL_PORT;
netdev_feature_zero(&vxlan_base);
netdev_feature_set_bits(NETIF_F_GSO_UDP_TUNNEL |
NETIF_F_RX_UDP_TUNNEL_PORT,
&vxlan_base);
if (!pdata->hw_feat.vxn) return;
/* VXLAN CSUM requires VXLAN base */
- if ((*features & NETIF_F_GSO_UDP_TUNNEL_CSUM) &&
!(*features & NETIF_F_GSO_UDP_TUNNEL)) {
- if (netdev_feature_test_bit(NETIF_F_GSO_UDP_TUNNEL_CSUM_BIT,
*features) &&
netdev_notice(netdev, "forcing tx udp tunnel support\n");!netdev_feature_test_bit(NETIF_F_GSO_UDP_TUNNEL_BIT, *features)) {
*features |= NETIF_F_GSO_UDP_TUNNEL;
netdev_feature_set_bit(NETIF_F_GSO_UDP_TUNNEL_BIT, features);
}
/* Can't do one without doing the other */
- if ((*features & vxlan_base) != vxlan_base) {
- if (!netdev_feature_subset(*features, vxlan_base)) { netdev_notice(netdev, "forcing both tx and rx udp tunnel support\n");
*features |= vxlan_base;
}netdev_feature_or(features, *features, vxlan_base);
- if (*features & (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM)) {
if (!(*features & NETIF_F_GSO_UDP_TUNNEL_CSUM)) {
- if (netdev_feature_test_bits(NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM,
*features)) {
if (!netdev_feature_test_bit(NETIF_F_GSO_UDP_TUNNEL_CSUM_BIT,
*features)) { netdev_notice(netdev, "forcing tx udp tunnel checksumming on\n");
*features |= NETIF_F_GSO_UDP_TUNNEL_CSUM;
netdev_feature_set_bit(NETIF_F_GSO_UDP_TUNNEL_CSUM_BIT,
} } else {features);
if (*features & NETIF_F_GSO_UDP_TUNNEL_CSUM) {
if (netdev_feature_test_bit(NETIF_F_GSO_UDP_TUNNEL_CSUM_BIT,
*features)) { netdev_notice(netdev, "forcing tx udp tunnel checksumming off\n");
*features &= ~NETIF_F_GSO_UDP_TUNNEL_CSUM;
netdev_feature_clear_bit(NETIF_F_GSO_UDP_TUNNEL_CSUM_BIT,
} } }features);
@@ -2228,37 +2237,47 @@ static int xgbe_set_features(struct net_device *netdev, { struct xgbe_prv_data *pdata = netdev_priv(netdev); struct xgbe_hw_if *hw_if = &pdata->hw_if;
- netdev_features_t rxhash, rxcsum, rxvlan, rxvlan_filter;
- bool rxhash, rxcsum, rxvlan, rxvlan_filter; int ret = 0;
- rxhash = pdata->netdev_features & NETIF_F_RXHASH;
- rxcsum = pdata->netdev_features & NETIF_F_RXCSUM;
- rxvlan = pdata->netdev_features & NETIF_F_HW_VLAN_CTAG_RX;
- rxvlan_filter = pdata->netdev_features & NETIF_F_HW_VLAN_CTAG_FILTER;
- rxhash = netdev_feature_test_bit(NETIF_F_RXHASH_BIT,
pdata->netdev_features);
- rxcsum = netdev_feature_test_bit(NETIF_F_RXCSUM_BIT,
pdata->netdev_features);
- rxvlan = netdev_feature_test_bit(NETIF_F_HW_VLAN_CTAG_RX_BIT,
pdata->netdev_features);
- rxvlan_filter = netdev_feature_test_bit(NETIF_F_HW_VLAN_CTAG_FILTER_BIT,
pdata->netdev_features);
- if ((features & NETIF_F_RXHASH) && !rxhash)
- if (netdev_feature_test_bit(NETIF_F_RXHASH_BIT, features) && !rxhash) ret = hw_if->enable_rss(pdata);
- else if (!(features & NETIF_F_RXHASH) && rxhash)
- else if (!netdev_feature_test_bit(NETIF_F_RXHASH_BIT, features) &&
ret = hw_if->disable_rss(pdata); if (ret) return ret;rxhash)
- if ((features & NETIF_F_RXCSUM) && !rxcsum)
- if (netdev_feature_test_bit(NETIF_F_RXCSUM_BIT, features) && !rxcsum) hw_if->enable_rx_csum(pdata);
- else if (!(features & NETIF_F_RXCSUM) && rxcsum)
- else if (!netdev_feature_test_bit(NETIF_F_RXCSUM_BIT, features) &&
hw_if->disable_rx_csum(pdata);rxcsum)
- if ((features & NETIF_F_HW_VLAN_CTAG_RX) && !rxvlan)
- if (netdev_feature_test_bit(NETIF_F_HW_VLAN_CTAG_RX_BIT, features) &&
hw_if->enable_rx_vlan_stripping(pdata);!rxvlan)
- else if (!(features & NETIF_F_HW_VLAN_CTAG_RX) && rxvlan)
- else if (!netdev_feature_test_bit(NETIF_F_HW_VLAN_CTAG_RX_BIT,
hw_if->disable_rx_vlan_stripping(pdata);features) && rxvlan)
- if ((features & NETIF_F_HW_VLAN_CTAG_FILTER) && !rxvlan_filter)
- if (netdev_feature_test_bit(NETIF_F_HW_VLAN_CTAG_FILTER_BIT,
hw_if->enable_rx_vlan_filtering(pdata);features) && !rxvlan_filter)
- else if (!(features & NETIF_F_HW_VLAN_CTAG_FILTER) && rxvlan_filter)
- else if (!netdev_feature_test_bit(NETIF_F_HW_VLAN_CTAG_FILTER_BIT,
hw_if->disable_rx_vlan_filtering(pdata);features) && rxvlan_filter)
- pdata->netdev_features = features;
- netdev_feature_copy(&features, pdata->netdev_features);
it shoule be "netdev_feature_copy(pdata->netdev_features, &features);"
DBGPR("<--xgbe_set_features\n");
@@ -2584,7 +2603,8 @@ static int xgbe_rx_poll(struct xgbe_channel *channel, int budget)
/* Be sure we don't exceed the configured MTU */ max_len = netdev->mtu + ETH_HLEN;
if (!(netdev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
if (!netdev_feature_test_bit(NETIF_F_HW_VLAN_CTAG_RX_BIT,
(skb->protocol == htons(ETH_P_8021Q))) max_len += VLAN_HLEN;netdev->features) &&
diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-main.c b/drivers/net/ethernet/amd/xgbe/xgbe-main.c index a218dc6..ace7324 100644 --- a/drivers/net/ethernet/amd/xgbe/xgbe-main.c +++ b/drivers/net/ethernet/amd/xgbe/xgbe-main.c @@ -342,45 +342,53 @@ int xgbe_config_netdev(struct xgbe_prv_data *pdata) #endif
/* Set device features */
- netdev->hw_features = NETIF_F_SG |
NETIF_F_IP_CSUM |
NETIF_F_IPV6_CSUM |
NETIF_F_RXCSUM |
NETIF_F_TSO |
NETIF_F_TSO6 |
NETIF_F_GRO |
NETIF_F_HW_VLAN_CTAG_RX |
NETIF_F_HW_VLAN_CTAG_TX |
NETIF_F_HW_VLAN_CTAG_FILTER;
netdev_feature_zero(&netdev->hw_features);
netdev_feature_set_bits(NETIF_F_SG |
NETIF_F_IP_CSUM |
NETIF_F_IPV6_CSUM |
NETIF_F_RXCSUM |
NETIF_F_TSO |
NETIF_F_TSO6 |
NETIF_F_GRO |
NETIF_F_HW_VLAN_CTAG_RX |
NETIF_F_HW_VLAN_CTAG_TX |
NETIF_F_HW_VLAN_CTAG_FILTER,
&netdev->hw_features);
if (pdata->hw_feat.rss)
netdev->hw_features |= NETIF_F_RXHASH;
netdev_feature_set_bit(NETIF_F_RXHASH_BIT,
&netdev->hw_features);
if (pdata->hw_feat.vxn) {
netdev->hw_enc_features = NETIF_F_SG |
NETIF_F_IP_CSUM |
NETIF_F_IPV6_CSUM |
NETIF_F_RXCSUM |
NETIF_F_TSO |
NETIF_F_TSO6 |
NETIF_F_GRO |
NETIF_F_GSO_UDP_TUNNEL |
NETIF_F_GSO_UDP_TUNNEL_CSUM;
netdev->hw_features |= NETIF_F_GSO_UDP_TUNNEL |
NETIF_F_GSO_UDP_TUNNEL_CSUM;
netdev_feature_zero(&netdev->hw_enc_features);
netdev_feature_set_bits(NETIF_F_SG |
NETIF_F_IP_CSUM |
NETIF_F_IPV6_CSUM |
NETIF_F_RXCSUM |
NETIF_F_TSO |
NETIF_F_TSO6 |
NETIF_F_GRO |
NETIF_F_GSO_UDP_TUNNEL |
NETIF_F_GSO_UDP_TUNNEL_CSUM,
&netdev->hw_enc_features);
netdev_feature_set_bits(NETIF_F_GSO_UDP_TUNNEL |
NETIF_F_GSO_UDP_TUNNEL_CSUM,
&netdev->hw_features);
netdev->udp_tunnel_nic_info = xgbe_get_udp_tunnel_info(); }
- netdev->vlan_features |= NETIF_F_SG |
NETIF_F_IP_CSUM |
NETIF_F_IPV6_CSUM |
NETIF_F_TSO |
NETIF_F_TSO6;
- netdev_feature_set_bits(NETIF_F_SG |
NETIF_F_IP_CSUM |
NETIF_F_IPV6_CSUM |
NETIF_F_TSO |
NETIF_F_TSO6,
&netdev->vlan_features);
- netdev->features |= netdev->hw_features;
- pdata->netdev_features = netdev->features;
netdev_feature_or(&netdev->features, netdev->features,
netdev->hw_features);
netdev_feature_copy(&pdata->netdev_features, netdev->features);
netdev->priv_flags |= IFF_UNICAST_FLT; netdev->min_mtu = 0;