在 2021/7/10 23:29, Andrew Lunn 写道:
On Sat, Jul 10, 2021 at 05:40:47PM +0800, Jian Shen wrote:
For the prototype of netdev_features_t is u64, and the number
of netdevice feature bits is 64 now. So there is no space to
introduce new feature bit.
The PHY subsystem had a similar problem a while back. supported and
advertised link modes where represented as bits in a u64. We changed
to a linux bitmap, with wrappers around it. Take a look at the
linkmode_ API usage in drivers/net/phy, and some Ethernet drivers.

It is going to be a big change, but i think you need to do something
similar here. Add a netdev_feature_ API for manipulating features,
convert all users to this API, and then change the implementation of
the API to allow more bits.

You will want to make use of code re-writing tools to do most of the
work.

	Andrew
.

Hi Andrew,

Thanks for your advice.

I have thought of using linkmode_ before (https://lists.openwall.net/netdev/2021/06/19/11).

In my humble opinion, there are too many logical operations in stack and ethernet drivers,
I'm not sure changing them to the linkmode_set_ API is the best way. For  example,

below is codes in ethernet drivre:
netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER |
        NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX |
        NETIF_F_RXCSUM | NETIF_F_SG | NETIF_F_GSO |
        NETIF_F_GRO | NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_GSO_GRE |
        NETIF_F_GSO_GRE_CSUM | NETIF_F_GSO_UDP_TUNNEL |
        NETIF_F_SCTP_CRC | NETIF_F_FRAGLIST;

When using linkmode_ API, I have two choices, one is to define several feature arrays or
a whole features array including all the feature bits supported by the ethernet driver.
const int hns3_nic_vlan_features_array[] = {
    NETIF_F_HW_VLAN_CTAG_FILTER,
    NETIF_F_HW_VLAN_CTAG_TX,
    NETIF_F_HW_VLAN_CTAG_RX,
};
const int hns3_nic_tso_features_array[] = {
    NETIF_F_GSO,
    NETIF_F_TSO,
    NETIF_F_TSO6,
    NETIF_F_GSO_GRE,
    ...
};
...

linkmode_set_bit_array(hns3_nic_vlan_features_array, ARRAY_SIZE(hns3_nic_vlan_features_array), netedv->features);

When using netdev_feature_t *, then just need to add an arrary index.

netdev->features[0] |= NETIF_F_HW_VLAN_CTAG_FILTER |
        NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX | xxxxxx


Sofar I used the later way to minimize the changes. If bitmap with linkmode_ API is more acceptable,
I'm very glad to use it.

By the way, could you introduce me some code re-writing tools ? 

Thanks a lot!

Jian Shen