在 2021/8/11 22:45, 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/virtio_net.c | 51 +++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 18 deletions(-)
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 2e42210..5859f8f 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -2635,11 +2635,12 @@ static int virtnet_set_features(struct net_device *dev, u64 offloads; int err;
- if ((dev->features ^ features) & NETIF_F_LRO) {
- if (netdev_feature_test_bit(NETIF_F_LRO_BIT, dev->features) !=
if (vi->xdp_enabled) return -EBUSY;netdev_feature_test_bit(NETIF_F_LRO_BIT, features)) {
if (features & NETIF_F_LRO)
else offloads = vi->guest_offloads_capable &if (netdev_feature_test_bit(NETIF_F_LRO_BIT, features)) offloads = vi->guest_offloads_capable;
@@ -2878,7 +2879,8 @@ static int virtnet_find_vqs(struct virtnet_info *vi) if (vi->has_cvq) { vi->cvq = vqs[total_vqs - 1]; if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VLAN))
vi->dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
netdev_feature_set_bit(NETIF_F_HW_VLAN_CTAG_FILTER_BIT,
&vi->dev->features);
}
for (i = 0; i < vi->max_queue_pairs; i++) {
@@ -3089,7 +3091,8 @@ static int virtnet_probe(struct virtio_device *vdev) dev->priv_flags |= IFF_UNICAST_FLT | IFF_LIVE_ADDR_CHANGE | IFF_TX_SKB_NO_LINEAR; dev->netdev_ops = &virtnet_netdev;
- dev->features = NETIF_F_HIGHDMA;
netdev_feature_zero(&dev->features);
netdev_feature_set_bit(NETIF_F_HIGHDMA_BIT, &dev->features);
dev->ethtool_ops = &virtnet_ethtool_ops; SET_NETDEV_DEV(dev, &vdev->dev);
@@ -3097,37 +3100,49 @@ static int virtnet_probe(struct virtio_device *vdev) /* Do we support "hardware" checksums? */ if (virtio_has_feature(vdev, VIRTIO_NET_F_CSUM)) { /* This opens up the world of extra features. */
dev->hw_features |= NETIF_F_HW_CSUM | NETIF_F_SG;
netdev_feature_set_bits(NETIF_F_HW_CSUM | NETIF_F_SG,
if (csum)&dev->hw_features);
dev->features |= NETIF_F_HW_CSUM | NETIF_F_SG;
netdev_feature_set_bits(NETIF_F_HW_CSUM | NETIF_F_SG,
&dev->features);
if (virtio_has_feature(vdev, VIRTIO_NET_F_GSO)) {
dev->hw_features |= NETIF_F_TSO
| NETIF_F_TSO_ECN | NETIF_F_TSO6;
netdev_feature_set_bits(NETIF_F_TSO | NETIF_F_TSO_ECN |
NETIF_F_TSO6,
} /* Individual feature bits: what can host handle? */ if (virtio_has_feature(vdev, VIRTIO_NET_F_HOST_TSO4))&dev->hw_features);
dev->hw_features |= NETIF_F_TSO;
netdev_feature_set_bit(NETIF_F_TSO_BIT,
if (virtio_has_feature(vdev, VIRTIO_NET_F_HOST_TSO6))&dev->hw_features);
dev->hw_features |= NETIF_F_TSO6;
netdev_feature_set_bit(NETIF_F_TSO6_BIT,
if (virtio_has_feature(vdev, VIRTIO_NET_F_HOST_ECN))&dev->hw_features);
dev->hw_features |= NETIF_F_TSO_ECN;
netdev_feature_set_bit(NETIF_F_TSO_ECN_BIT,
&dev->hw_features);
dev->features |= NETIF_F_GSO_ROBUST;
netdev_feature_set_bit(NETIF_F_GSO_ROBUST_BIT, &dev->features);
if (gso)
dev->features |= dev->hw_features & NETIF_F_ALL_TSO;
if (gso) {
netdev_features_t tmp;
netdev_feature_zero(&tmp);
netdev_feature_set_bits(NETIF_F_ALL_TSO, &tmp);
netdev_feature_and(&dev->features, dev->hw_features,
tmp);
it shoule be netdev_feature_copy(&tmp, dev->hw_features); netdev_feature_and_bits(NETIF_F_ALL_TSO, &tmp); netdev_feature_or(&dev->features, dev->features, tmp);
will fix it in next version
/* (!csum && gso) case will be fixed by register_netdev() */ } if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_CSUM))}
dev->features |= NETIF_F_RXCSUM;
if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO4) || virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO6))netdev_feature_set_bit(NETIF_F_RXCSUM_BIT, &dev->features);
dev->features |= NETIF_F_LRO;
if (virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS))netdev_feature_set_bit(NETIF_F_LRO_BIT, &dev->features);
dev->hw_features |= NETIF_F_LRO;
netdev_feature_set_bit(NETIF_F_LRO_BIT, &dev->hw_features);
- dev->vlan_features = dev->features;
netdev_feature_copy(&dev->vlan_features, dev->features);
/* MTU range: 68 - 65535 */ dev->min_mtu = MIN_MTU;