From nobody Thu Oct 9 20:24:08 2025 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 23FB313A26D; Tue, 17 Jun 2025 01:09:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750122599; cv=none; b=b+Sm5cLnE/x86/ywz0raHGC7jU6QsbNUHnmwPCWYtB4lcae4vNAhmvFGHMWiEY56E7m7Gfr6+dUpBiJV4MVlyXH9VcL0VP07aGBZCBjEebUQn1+pxMyG97b/AqdXquBXjvfUCoPv6HUCgDf0r60MW51GWd8+yNj4isI9edCWE0Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750122599; c=relaxed/simple; bh=1/f78jaeBtKiqIzOnwVRXPhOzaS2KkfcDdjaLP55PXU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WAkOkba5ZJsbw0KdwStKjEhUjx31LaxZ7A8lZnnQPtnmed1LX3q1ohvTjB8vV6y7OxHT2T8HIFHbXh2SISzYy5zYNZNfmZ8JYKKyGQUupifaHALG8vGXtc1d1j6d68o/v44EGxBzDR6K90eMMChBPBoKIdaSXXlQGp+IyfSAbCU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4bLpf43rVGz2TSLS; Tue, 17 Jun 2025 09:08:28 +0800 (CST) Received: from kwepemk100013.china.huawei.com (unknown [7.202.194.61]) by mail.maildlp.com (Postfix) with ESMTPS id 1873914011F; Tue, 17 Jun 2025 09:09:55 +0800 (CST) Received: from localhost.localdomain (10.90.31.46) by kwepemk100013.china.huawei.com (7.202.194.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Tue, 17 Jun 2025 09:09:54 +0800 From: Jijie Shao To: , , , , , CC: , , , , , , , , , , Subject: [PATCH V2 net-next 2/8] net: hns3: use hns3_get_ae_dev() helper to reduce the unnecessary middle layer conversion Date: Tue, 17 Jun 2025 09:02:49 +0800 Message-ID: <20250617010255.1183069-3-shaojijie@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20250617010255.1183069-1-shaojijie@huawei.com> References: <20250617010255.1183069-1-shaojijie@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems200002.china.huawei.com (7.221.188.68) To kwepemk100013.china.huawei.com (7.202.194.61) Content-Type: text/plain; charset="utf-8" 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_ae_dev() helper is already defined and can fix this issue. This patch uses hns3_get_ae_dev() 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.9= 47-1-lanhao@huawei.com/ Signed-off-by: Jijie Shao Reviewed-by: Michal Swiatkowski --- ChangeLog: v1 -> v2: - Change commit message and title, suggested by Michal Swiatkowski. v1: https://lore.kernel.org/all/20250612021317.1487943-1-shaojijie@huawei= .com/ --- .../ethernet/hisilicon/hns3/hns3_debugfs.c | 8 ++--- .../net/ethernet/hisilicon/hns3/hns3_enet.c | 12 +++---- .../ethernet/hisilicon/hns3/hns3_ethtool.c | 36 +++++++++---------- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c b/drivers/n= et/ethernet/hisilicon/hns3/hns3_debugfs.c index 4e5d8bc39a1b..4f6ed7c7ee68 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c @@ -684,7 +684,7 @@ static int hns3_dbg_rx_queue_info(struct hnae3_handle *= h, char *buf, int len) { char data_str[ARRAY_SIZE(rx_queue_info_items)][HNS3_DBG_DATA_STR_LEN]; - struct hnae3_ae_dev *ae_dev =3D pci_get_drvdata(h->pdev); + struct hnae3_ae_dev *ae_dev =3D hns3_get_ae_dev(h); char *result[ARRAY_SIZE(rx_queue_info_items)]; struct hns3_nic_priv *priv =3D h->priv; char content[HNS3_DBG_INFO_LEN]; @@ -789,7 +789,7 @@ static int hns3_dbg_tx_queue_info(struct hnae3_handle *= h, char *buf, int len) { char data_str[ARRAY_SIZE(tx_queue_info_items)][HNS3_DBG_DATA_STR_LEN]; - struct hnae3_ae_dev *ae_dev =3D pci_get_drvdata(h->pdev); + struct hnae3_ae_dev *ae_dev =3D hns3_get_ae_dev(h); char *result[ARRAY_SIZE(tx_queue_info_items)]; struct hns3_nic_priv *priv =3D h->priv; char content[HNS3_DBG_INFO_LEN]; @@ -1034,7 +1034,7 @@ static int hns3_dbg_tx_bd_info(struct hns3_dbg_data *= d, char *buf, int len) static void hns3_dbg_dev_caps(struct hnae3_handle *h, char *buf, int len, int *pos) { - struct hnae3_ae_dev *ae_dev =3D pci_get_drvdata(h->pdev); + struct hnae3_ae_dev *ae_dev =3D hns3_get_ae_dev(h); unsigned long *caps =3D ae_dev->caps; u32 i, state; =20 @@ -1364,7 +1364,7 @@ hns3_dbg_common_file_init(struct hnae3_handle *handle= , u32 cmd) =20 int hns3_dbg_init(struct hnae3_handle *handle) { - struct hnae3_ae_dev *ae_dev =3D pci_get_drvdata(handle->pdev); + struct hnae3_ae_dev *ae_dev =3D hns3_get_ae_dev(handle); const char *name =3D pci_name(handle->pdev); int ret; u32 i; diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/= ethernet/hisilicon/hns3/hns3_enet.c index 5c8c62ea6ac0..6babc636145b 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c @@ -547,9 +547,9 @@ void hns3_set_vector_coalesce_rx_ql(struct hns3_enet_tq= p_vector *tqp_vector, static void hns3_vector_coalesce_init(struct hns3_enet_tqp_vector *tqp_vec= tor, struct hns3_nic_priv *priv) { - struct hnae3_ae_dev *ae_dev =3D pci_get_drvdata(priv->ae_handle->pdev); struct hns3_enet_coalesce *tx_coal =3D &tqp_vector->tx_group.coal; struct hns3_enet_coalesce *rx_coal =3D &tqp_vector->rx_group.coal; + struct hnae3_ae_dev *ae_dev =3D hns3_get_ae_dev(priv->ae_handle); struct hns3_enet_coalesce *ptx_coal =3D &priv->tx_coal; struct hns3_enet_coalesce *prx_coal =3D &priv->rx_coal; =20 @@ -1304,7 +1304,7 @@ static int hns3_get_l4_protocol(struct sk_buff *skb, = u8 *ol4_proto, static bool hns3_tunnel_csum_bug(struct sk_buff *skb) { struct hns3_nic_priv *priv =3D netdev_priv(skb->dev); - struct hnae3_ae_dev *ae_dev =3D pci_get_drvdata(priv->ae_handle->pdev); + struct hnae3_ae_dev *ae_dev =3D hns3_get_ae_dev(priv->ae_handle); union l4_hdr_info l4; =20 /* device version above V3(include V3), the hardware can @@ -1504,7 +1504,7 @@ static int hns3_handle_vtags(struct hns3_enet_ring *t= x_ring, * VLAN enabled, only one VLAN header is allowed in skb, otherwise it * will cause RAS error. */ - ae_dev =3D pci_get_drvdata(handle->pdev); + ae_dev =3D hns3_get_ae_dev(handle); if (unlikely(skb_vlan_tagged_multi(skb) && ae_dev->dev_version <=3D HNAE3_DEVICE_VERSION_V2 && handle->port_base_vlan_state =3D=3D @@ -4747,7 +4747,7 @@ static int hns3_nic_init_vector_data(struct hns3_nic_= priv *priv) =20 static void hns3_nic_init_coal_cfg(struct hns3_nic_priv *priv) { - struct hnae3_ae_dev *ae_dev =3D pci_get_drvdata(priv->ae_handle->pdev); + struct hnae3_ae_dev *ae_dev =3D hns3_get_ae_dev(priv->ae_handle); struct hns3_enet_coalesce *tx_coal =3D &priv->tx_coal; struct hns3_enet_coalesce *rx_coal =3D &priv->rx_coal; =20 @@ -5226,7 +5226,7 @@ static void hns3_info_show(struct hns3_nic_priv *priv) static void hns3_set_cq_period_mode(struct hns3_nic_priv *priv, enum dim_cq_period_mode mode, bool is_tx) { - struct hnae3_ae_dev *ae_dev =3D pci_get_drvdata(priv->ae_handle->pdev); + struct hnae3_ae_dev *ae_dev =3D hns3_get_ae_dev(priv->ae_handle); struct hnae3_handle *handle =3D priv->ae_handle; int i; =20 @@ -5264,7 +5264,7 @@ void hns3_cq_period_mode_init(struct hns3_nic_priv *p= riv, =20 static void hns3_state_init(struct hnae3_handle *handle) { - struct hnae3_ae_dev *ae_dev =3D pci_get_drvdata(handle->pdev); + struct hnae3_ae_dev *ae_dev =3D hns3_get_ae_dev(handle); struct net_device *netdev =3D handle->kinfo.netdev; struct hns3_nic_priv *priv =3D netdev_priv(netdev); =20 diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c b/drivers/n= et/ethernet/hisilicon/hns3/hns3_ethtool.c index 6715222aeb66..ae220f49df64 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c @@ -86,7 +86,7 @@ static int hns3_get_sset_count(struct net_device *netdev,= int stringset); static int hns3_lp_setup(struct net_device *ndev, enum hnae3_loop loop, bo= ol en) { struct hnae3_handle *h =3D hns3_get_handle(ndev); - struct hnae3_ae_dev *ae_dev =3D pci_get_drvdata(h->pdev); + struct hnae3_ae_dev *ae_dev =3D hns3_get_ae_dev(h); int ret; =20 if (!h->ae_algo->ops->set_loopback || @@ -171,7 +171,7 @@ static void hns3_lp_setup_skb(struct sk_buff *skb) * the purpose of mac or serdes selftest. */ handle =3D hns3_get_handle(ndev); - ae_dev =3D pci_get_drvdata(handle->pdev); + ae_dev =3D hns3_get_ae_dev(handle); if (ae_dev->dev_version < HNAE3_DEVICE_VERSION_V2) ethh->h_dest[5] +=3D HNS3_NIC_LB_DST_MAC_ADDR; eth_zero_addr(ethh->h_source); @@ -692,7 +692,7 @@ static void hns3_get_pauseparam(struct net_device *netd= ev, struct ethtool_pauseparam *param) { struct hnae3_handle *h =3D hns3_get_handle(netdev); - struct hnae3_ae_dev *ae_dev =3D pci_get_drvdata(h->pdev); + struct hnae3_ae_dev *ae_dev =3D hns3_get_ae_dev(h); =20 if (!test_bit(HNAE3_DEV_SUPPORT_PAUSE_B, ae_dev->caps)) return; @@ -706,7 +706,7 @@ static int hns3_set_pauseparam(struct net_device *netde= v, struct ethtool_pauseparam *param) { struct hnae3_handle *h =3D hns3_get_handle(netdev); - struct hnae3_ae_dev *ae_dev =3D pci_get_drvdata(h->pdev); + struct hnae3_ae_dev *ae_dev =3D hns3_get_ae_dev(h); =20 if (!test_bit(HNAE3_DEV_SUPPORT_PAUSE_B, ae_dev->caps)) return -EOPNOTSUPP; @@ -751,7 +751,7 @@ static int hns3_get_link_ksettings(struct net_device *n= etdev, struct ethtool_link_ksettings *cmd) { struct hnae3_handle *h =3D hns3_get_handle(netdev); - struct hnae3_ae_dev *ae_dev =3D pci_get_drvdata(h->pdev); + struct hnae3_ae_dev *ae_dev =3D hns3_get_ae_dev(h); const struct hnae3_ae_ops *ops; u8 module_type; u8 media_type; @@ -861,7 +861,7 @@ static int hns3_set_link_ksettings(struct net_device *n= etdev, const struct ethtool_link_ksettings *cmd) { struct hnae3_handle *handle =3D hns3_get_handle(netdev); - struct hnae3_ae_dev *ae_dev =3D pci_get_drvdata(handle->pdev); + struct hnae3_ae_dev *ae_dev =3D hns3_get_ae_dev(handle); const struct hnae3_ae_ops *ops =3D handle->ae_algo->ops; int ret; =20 @@ -932,7 +932,7 @@ static u32 hns3_get_rss_key_size(struct net_device *net= dev) static u32 hns3_get_rss_indir_size(struct net_device *netdev) { struct hnae3_handle *h =3D hns3_get_handle(netdev); - struct hnae3_ae_dev *ae_dev =3D pci_get_drvdata(h->pdev); + struct hnae3_ae_dev *ae_dev =3D hns3_get_ae_dev(h); =20 return ae_dev->dev_specs.rss_ind_tbl_size; } @@ -954,7 +954,7 @@ static int hns3_set_rss(struct net_device *netdev, struct netlink_ext_ack *extack) { struct hnae3_handle *h =3D hns3_get_handle(netdev); - struct hnae3_ae_dev *ae_dev =3D pci_get_drvdata(h->pdev); + struct hnae3_ae_dev *ae_dev =3D hns3_get_ae_dev(h); =20 if (!h->ae_algo->ops->set_rss) return -EOPNOTSUPP; @@ -1024,7 +1024,7 @@ static int hns3_set_reset(struct net_device *netdev, = u32 *flags) { enum hnae3_reset_type rst_type =3D HNAE3_NONE_RESET; struct hnae3_handle *h =3D hns3_get_handle(netdev); - struct hnae3_ae_dev *ae_dev =3D pci_get_drvdata(h->pdev); + struct hnae3_ae_dev *ae_dev =3D hns3_get_ae_dev(h); const struct hnae3_ae_ops *ops =3D h->ae_algo->ops; const struct hns3_reset_type_map *rst_type_map; enum ethtool_reset_flags rst_flags; @@ -1189,7 +1189,7 @@ static int hns3_set_tx_push(struct net_device *netdev= , u32 tx_push) { struct hns3_nic_priv *priv =3D netdev_priv(netdev); struct hnae3_handle *h =3D hns3_get_handle(netdev); - struct hnae3_ae_dev *ae_dev =3D pci_get_drvdata(h->pdev); + struct hnae3_ae_dev *ae_dev =3D hns3_get_ae_dev(h); u32 old_state =3D test_bit(HNS3_NIC_STATE_TX_PUSH_ENABLE, &priv->state); =20 if (!test_bit(HNAE3_DEV_SUPPORT_TX_PUSH_B, ae_dev->caps) && tx_push) @@ -1377,7 +1377,7 @@ static int hns3_check_gl_coalesce_para(struct net_dev= ice *netdev, struct ethtool_coalesce *cmd) { struct hnae3_handle *handle =3D hns3_get_handle(netdev); - struct hnae3_ae_dev *ae_dev =3D pci_get_drvdata(handle->pdev); + struct hnae3_ae_dev *ae_dev =3D hns3_get_ae_dev(handle); u32 rx_gl, tx_gl; =20 if (cmd->rx_coalesce_usecs > ae_dev->dev_specs.max_int_gl) { @@ -1449,7 +1449,7 @@ static int hns3_check_ql_coalesce_param(struct net_de= vice *netdev, struct ethtool_coalesce *cmd) { struct hnae3_handle *handle =3D hns3_get_handle(netdev); - struct hnae3_ae_dev *ae_dev =3D pci_get_drvdata(handle->pdev); + struct hnae3_ae_dev *ae_dev =3D hns3_get_ae_dev(handle); =20 if ((cmd->tx_max_coalesced_frames || cmd->rx_max_coalesced_frames) && !ae_dev->dev_specs.int_ql_max) { @@ -1473,7 +1473,7 @@ hns3_check_cqe_coalesce_param(struct net_device *netd= ev, struct kernel_ethtool_coalesce *kernel_coal) { struct hnae3_handle *handle =3D hns3_get_handle(netdev); - struct hnae3_ae_dev *ae_dev =3D pci_get_drvdata(handle->pdev); + struct hnae3_ae_dev *ae_dev =3D hns3_get_ae_dev(handle); =20 if ((kernel_coal->use_cqe_mode_tx || kernel_coal->use_cqe_mode_rx) && !hnae3_ae_dev_cq_supported(ae_dev)) { @@ -1649,7 +1649,7 @@ static void hns3_get_fec_stats(struct net_device *net= dev, struct ethtool_fec_stats *fec_stats) { struct hnae3_handle *handle =3D hns3_get_handle(netdev); - struct hnae3_ae_dev *ae_dev =3D pci_get_drvdata(handle->pdev); + struct hnae3_ae_dev *ae_dev =3D hns3_get_ae_dev(handle); const struct hnae3_ae_ops *ops =3D handle->ae_algo->ops; =20 if (!hnae3_ae_dev_fec_stats_supported(ae_dev) || !ops->get_fec_stats) @@ -1700,7 +1700,7 @@ static int hns3_get_fecparam(struct net_device *netde= v, struct ethtool_fecparam *fec) { struct hnae3_handle *handle =3D hns3_get_handle(netdev); - struct hnae3_ae_dev *ae_dev =3D pci_get_drvdata(handle->pdev); + struct hnae3_ae_dev *ae_dev =3D hns3_get_ae_dev(handle); const struct hnae3_ae_ops *ops =3D handle->ae_algo->ops; u8 fec_ability; u8 fec_mode; @@ -1725,7 +1725,7 @@ static int hns3_set_fecparam(struct net_device *netde= v, struct ethtool_fecparam *fec) { struct hnae3_handle *handle =3D hns3_get_handle(netdev); - struct hnae3_ae_dev *ae_dev =3D pci_get_drvdata(handle->pdev); + struct hnae3_ae_dev *ae_dev =3D hns3_get_ae_dev(handle); const struct hnae3_ae_ops *ops =3D handle->ae_algo->ops; u32 fec_mode; =20 @@ -1747,7 +1747,7 @@ static int hns3_get_module_info(struct net_device *ne= tdev, #define HNS3_SFF_8636_V1_3 0x03 =20 struct hnae3_handle *handle =3D hns3_get_handle(netdev); - struct hnae3_ae_dev *ae_dev =3D pci_get_drvdata(handle->pdev); + struct hnae3_ae_dev *ae_dev =3D hns3_get_ae_dev(handle); const struct hnae3_ae_ops *ops =3D handle->ae_algo->ops; struct hns3_sfp_type sfp_type; int ret; @@ -1797,7 +1797,7 @@ static int hns3_get_module_eeprom(struct net_device *= netdev, struct ethtool_eeprom *ee, u8 *data) { struct hnae3_handle *handle =3D hns3_get_handle(netdev); - struct hnae3_ae_dev *ae_dev =3D pci_get_drvdata(handle->pdev); + struct hnae3_ae_dev *ae_dev =3D hns3_get_ae_dev(handle); const struct hnae3_ae_ops *ops =3D handle->ae_algo->ops; =20 if (ae_dev->dev_version < HNAE3_DEVICE_VERSION_V2 || --=20 2.33.0