]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net: hns3: use hns3_get_ops() helper to reduce the unnecessary middle layer conversion
authorJijie Shao <shaojijie@huawei.com>
Mon, 23 Jun 2025 04:00:39 +0000 (12:00 +0800)
committerJakub Kicinski <kuba@kernel.org>
Wed, 25 Jun 2025 00:09:21 +0000 (17:09 -0700)
There are too many indirection layers in the HNS3 driver code,
This issue was previously discussed with the maintainer,
who suggested adding a helper function to fix the issue.
In fact, the hns3_get_ops() helper is already defined
and can fix this issue.

This patch uses hns3_get_ops() helper to reduce the unnecessary
middle layer conversion. Apply it to the whole HNS3 driver.
The former discusstion can be checked from the link.

Link: https://patchwork.kernel.org/project/netdevbpf/patch/20230310081404.947-1-lanhao@huawei.com/
Signed-off-by: Jijie Shao <shaojijie@huawei.com>
Reviewed-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
Link: https://patch.msgid.link/20250623040043.857782-4-shaojijie@huawei.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c

index 4f6ed7c7ee68994ae4b7753c96ed8789a4f3ade6..35e57eebcf579b888c45f152ec6ed97dd8b4f98f 100644 (file)
@@ -1239,7 +1239,7 @@ static const struct hns3_dbg_func hns3_dbg_cmd_func[] = {
 static int hns3_dbg_read_cmd(struct hns3_dbg_data *dbg_data,
                             enum hnae3_dbg_cmd cmd, char *buf, int len)
 {
-       const struct hnae3_ae_ops *ops = dbg_data->handle->ae_algo->ops;
+       const struct hnae3_ae_ops *ops = hns3_get_ops(dbg_data->handle);
        const struct hns3_dbg_func *cmd_func;
        u32 i;
 
index 6babc636145b9c824fd51f373e12db1484cc2d9d..208a2dfc07ec827aba1f1881b4f89519e720bd32 100644 (file)
@@ -960,7 +960,7 @@ static void hns3_nic_set_rx_mode(struct net_device *netdev)
 
 void hns3_request_update_promisc_mode(struct hnae3_handle *handle)
 {
-       const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
+       const struct hnae3_ae_ops *ops = hns3_get_ops(handle);
 
        if (ops->request_update_promisc_mode)
                ops->request_update_promisc_mode(handle);
index b75766a94536aa37ee0627e7a6591453f5c378e0..c590daad497ca50d4b44dd166080a35a015a48b0 100644 (file)
@@ -489,7 +489,7 @@ static const struct hns3_pflag_desc hns3_priv_flags[HNAE3_PFLAG_MAX] = {
 static int hns3_get_sset_count(struct net_device *netdev, int stringset)
 {
        struct hnae3_handle *h = hns3_get_handle(netdev);
-       const struct hnae3_ae_ops *ops = h->ae_algo->ops;
+       const struct hnae3_ae_ops *ops = hns3_get_ops(h);
 
        if (!ops->get_sset_count)
                return -EOPNOTSUPP;
@@ -540,7 +540,7 @@ static void hns3_get_strings_tqps(struct hnae3_handle *handle, u8 **data)
 static void hns3_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
 {
        struct hnae3_handle *h = hns3_get_handle(netdev);
-       const struct hnae3_ae_ops *ops = h->ae_algo->ops;
+       const struct hnae3_ae_ops *ops = hns3_get_ops(h);
        int i;
 
        if (!ops->get_strings)
@@ -725,7 +725,7 @@ static int hns3_set_pauseparam(struct net_device *netdev,
 static void hns3_get_ksettings(struct hnae3_handle *h,
                               struct ethtool_link_ksettings *cmd)
 {
-       const struct hnae3_ae_ops *ops = h->ae_algo->ops;
+       const struct hnae3_ae_ops *ops = hns3_get_ops(h);
 
        /* 1.auto_neg & speed & duplex from cmd */
        if (ops->get_ksettings_an_result)
@@ -814,7 +814,7 @@ static int hns3_check_ksettings_param(const struct net_device *netdev,
                                      const struct ethtool_link_ksettings *cmd)
 {
        struct hnae3_handle *handle = hns3_get_handle(netdev);
-       const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
+       const struct hnae3_ae_ops *ops = hns3_get_ops(handle);
        u8 module_type = HNAE3_MODULE_TYPE_UNKNOWN;
        u8 media_type = HNAE3_MEDIA_TYPE_UNKNOWN;
        u32 lane_num;
@@ -862,7 +862,7 @@ static int hns3_set_link_ksettings(struct net_device *netdev,
 {
        struct hnae3_handle *handle = hns3_get_handle(netdev);
        struct hnae3_ae_dev *ae_dev = hns3_get_ae_dev(handle);
-       const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
+       const struct hnae3_ae_ops *ops = hns3_get_ops(handle);
        int ret;
 
        /* Chip don't support this mode. */
@@ -1031,7 +1031,7 @@ static int hns3_set_reset(struct net_device *netdev, u32 *flags)
        enum hnae3_reset_type rst_type = HNAE3_NONE_RESET;
        struct hnae3_handle *h = hns3_get_handle(netdev);
        struct hnae3_ae_dev *ae_dev = hns3_get_ae_dev(h);
-       const struct hnae3_ae_ops *ops = h->ae_algo->ops;
+       const struct hnae3_ae_ops *ops = hns3_get_ops(h);
        const struct hns3_reset_type_map *rst_type_map;
        enum ethtool_reset_flags rst_flags;
        u32 i, size;
@@ -1313,7 +1313,7 @@ static int hns3_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
 static int hns3_nway_reset(struct net_device *netdev)
 {
        struct hnae3_handle *handle = hns3_get_handle(netdev);
-       const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
+       const struct hnae3_ae_ops *ops = hns3_get_ops(handle);
        struct phy_device *phy = netdev->phydev;
        int autoneg;
 
@@ -1663,7 +1663,7 @@ static void hns3_get_fec_stats(struct net_device *netdev,
 {
        struct hnae3_handle *handle = hns3_get_handle(netdev);
        struct hnae3_ae_dev *ae_dev = hns3_get_ae_dev(handle);
-       const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
+       const struct hnae3_ae_ops *ops = hns3_get_ops(handle);
 
        if (!hnae3_ae_dev_fec_stats_supported(ae_dev) || !ops->get_fec_stats)
                return;
@@ -1714,7 +1714,7 @@ static int hns3_get_fecparam(struct net_device *netdev,
 {
        struct hnae3_handle *handle = hns3_get_handle(netdev);
        struct hnae3_ae_dev *ae_dev = hns3_get_ae_dev(handle);
-       const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
+       const struct hnae3_ae_ops *ops = hns3_get_ops(handle);
        u8 fec_ability;
        u8 fec_mode;
 
@@ -1739,7 +1739,7 @@ static int hns3_set_fecparam(struct net_device *netdev,
 {
        struct hnae3_handle *handle = hns3_get_handle(netdev);
        struct hnae3_ae_dev *ae_dev = hns3_get_ae_dev(handle);
-       const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
+       const struct hnae3_ae_ops *ops = hns3_get_ops(handle);
        u32 fec_mode;
 
        if (!test_bit(HNAE3_DEV_SUPPORT_FEC_B, ae_dev->caps))
@@ -1761,7 +1761,7 @@ static int hns3_get_module_info(struct net_device *netdev,
 
        struct hnae3_handle *handle = hns3_get_handle(netdev);
        struct hnae3_ae_dev *ae_dev = hns3_get_ae_dev(handle);
-       const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
+       const struct hnae3_ae_ops *ops = hns3_get_ops(handle);
        struct hns3_sfp_type sfp_type;
        int ret;
 
@@ -1811,7 +1811,7 @@ static int hns3_get_module_eeprom(struct net_device *netdev,
 {
        struct hnae3_handle *handle = hns3_get_handle(netdev);
        struct hnae3_ae_dev *ae_dev = hns3_get_ae_dev(handle);
-       const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
+       const struct hnae3_ae_ops *ops = hns3_get_ops(handle);
 
        if (ae_dev->dev_version < HNAE3_DEVICE_VERSION_V2 ||
            !ops->get_module_eeprom)