From e8a59242bccb7ffe062097be020e67bacffc82cf Mon Sep 17 00:00:00 2001 From: Haibin Lu Date: Wed, 14 Aug 2024 14:31:08 +0800 Subject: [PATCH 1/7] UNIC: Solve the problem of redundant print in ub mode driver inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/IAKMX4 CVE: NA ----------------------------------------------------------- When network device is reset, pf driver is uninstalled, or vf is disabled, the command for clearing or restoring the vf rate is issued to the firmware. However, the ub mode does not support vf rate limiting. Therefore, the firmware returns an error for this interface in ub mode, causing redundant printing. This patch adds the judgment of whether the UB mode is used before the configuration command is delivered to the firmware to prevent redundant printing. In addition, this patch deletes the implementation of ndo_set_vf_rate in ub mode. Fixes: 737ec46e9632 ("UNIC: Adds the process of UNIC driver initializing") Signed-off-by: Haibin Lu --- drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 1 - drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c | 9 +++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c index 0875adf3cfd4..0f8aaed254bb 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c @@ -3305,7 +3305,6 @@ const struct net_device_ops hns3_unic_netdev_ops = { #endif .ndo_get_vf_config = hns3_nic_get_vf_config, .ndo_set_vf_link_state = hns3_nic_set_vf_link_state, - .ndo_set_vf_rate = hns3_nic_set_vf_rate, .ndo_select_queue = hns3_nic_select_queue, }; diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c index 132b6446d485..b1bec2c0f19d 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c @@ -594,6 +594,15 @@ int hclge_tm_qs_shaper_cfg(struct hclge_vport *vport, int max_tx_rate) u32 shaper_para; int ret, i; +#if CONFIG_HNS3_UBL + /* vf rate limiting is not supported in ub link mode, a success message + * is directly returned to prevent redundant failure information from + * being printed in the reset and uninstallation processes. + */ + if (hnae3_dev_ubl_supported(hdev->ae_dev)) + return 0; +#endif + if (!max_tx_rate) max_tx_rate = hdev->ae_dev->dev_specs.max_tm_rate; -- Gitee From c12d1b0e631021f38d0d0dd7f57eaf607611185c Mon Sep 17 00:00:00 2001 From: Junxin Chen Date: Thu, 15 Aug 2024 21:54:02 +0800 Subject: [PATCH 2/7] UNIC: bugfix for mguid's memory not be free after netdev init fail driver inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/IAKMX4 CVE: NA ----------------------------------------------------------- Currently, during driver initialization, the mguid table entry is added to the chip by default, which requests memory to save information. However, if there is a netdev registration failure during the driver loading process, the memory of these memory will not be released, resulting in memory leaks. This patch adds memory release processing for the mguid when an abnormal exit occurs during the initialization process. Fixes: a1799222294b ("UNIC: Support using MC GUID and table management") Signed-off-by: Haibin Lu Signed-off-by: Junxin Chen --- .../net/ethernet/hisilicon/hns3/hns3_enet.c | 4 + .../net/ethernet/hisilicon/hns3/hns3_unic.c | 73 ++++++++++++++----- .../net/ethernet/hisilicon/hns3/hns3_unic.h | 1 + 3 files changed, 60 insertions(+), 18 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c index 0f8aaed254bb..9de28d7da992 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c @@ -5826,6 +5826,10 @@ static int hns3_client_init(struct hnae3_handle *handle) out_reg_netdev_fail: hns3_state_uninit(handle); +#ifdef CONFIG_HNS3_UBL + if (hns3_ubl_supported(handle)) + hns3_unic_uninit(netdev); +#endif out_dbg_init: hns3_dbg_uninit(handle); hns3_client_stop(handle); diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_unic.c b/drivers/net/ethernet/hisilicon/hns3/hns3_unic.c index 1e4ea94db134..6d0646966bf5 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_unic.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_unic.c @@ -27,6 +27,18 @@ #define HNS3_UNIC_LB_TEST_PACKET_SIZE 128 +static const u8 mc_guid[][HNS3_SIMPLE_GUID_LEN] = { + {0xff, 0xff, 0xff, 0xff, 0x01, 0x00}, /* DHCPv4 */ + {0xff, 0xff, 0xff, 0xff, 0x01, 0x01}, /* DHCPv6 */ + {0xff, 0xff, 0xff, 0xff, 0x01, 0x02}, /* IP notify */ + {0xff, 0xff, 0xff, 0xff, 0x01, 0x03}, /* ULDP */ + {0xff, 0xff, 0xff, 0xff, 0x01, 0x04}, /* ULAP */ + {0xff, 0xff, 0xff, 0xff, 0x01, 0x05}, /* Time sync */ + {0xff, 0xff, 0xff, 0xff, 0x01, 0x06}, /* NPIC */ + {0xff, 0xff, 0xff, 0xff, 0x01, 0x07}, /* NNP */ + {0xff, 0xff, 0xff, 0xff, 0x01, 0x08}, /* PHCP */ +}; + void hns3_unic_set_default_cc(struct sk_buff *skb) { struct ublhdr *ubl = (struct ublhdr *)skb->data; @@ -325,23 +337,12 @@ void hns3_unic_set_rx_mode(struct net_device *netdev) hns3_request_update_promisc_mode(h); } -int hns3_unic_init_guid(struct net_device *netdev) +static int hns3_unic_init_func_guid(struct net_device *netdev) { - const u8 mc_guid[][HNS3_SIMPLE_GUID_LEN] = { - {0xff, 0xff, 0xff, 0xff, 0x01, 0x00}, /* DHCPv4 */ - {0xff, 0xff, 0xff, 0xff, 0x01, 0x01}, /* DHCPv6 */ - {0xff, 0xff, 0xff, 0xff, 0x01, 0x02}, /* IP notify */ - {0xff, 0xff, 0xff, 0xff, 0x01, 0x03}, /* ULDP */ - {0xff, 0xff, 0xff, 0xff, 0x01, 0x04}, /* ULAP */ - {0xff, 0xff, 0xff, 0xff, 0x01, 0x05}, /* Time sync */ - {0xff, 0xff, 0xff, 0xff, 0x01, 0x06}, /* NPIC */ - {0xff, 0xff, 0xff, 0xff, 0x01, 0x07}, /* NNP */ - {0xff, 0xff, 0xff, 0xff, 0x01, 0x08}, /* PHCP */ - }; struct hns3_nic_priv *priv = netdev_priv(netdev); struct hnae3_handle *h = priv->ae_handle; u8 temp_guid_addr[UBL_ALEN]; - int ret, i; + int ret; if (!h->ae_algo->ops->get_func_guid || !h->ae_algo->ops->set_func_guid) { @@ -355,6 +356,18 @@ int hns3_unic_init_guid(struct net_device *netdev) return ret; } + memcpy(netdev->dev_addr, temp_guid_addr, netdev->addr_len); + memcpy(netdev->perm_addr, temp_guid_addr, netdev->addr_len); + + h->ae_algo->ops->set_func_guid(h, netdev->dev_addr); + + return 0; +} + +static int hns3_unic_init_mc_guid(struct net_device *netdev) +{ + int i, ret; + for (i = 0; i < ARRAY_SIZE(mc_guid); i++) { ret = hns3_unic_add_mc_guid(netdev, mc_guid[i]); if (ret) { @@ -363,11 +376,6 @@ int hns3_unic_init_guid(struct net_device *netdev) } } - memcpy(netdev->dev_addr, temp_guid_addr, netdev->addr_len); - memcpy(netdev->perm_addr, temp_guid_addr, netdev->addr_len); - - h->ae_algo->ops->set_func_guid(h, netdev->dev_addr); - return 0; err_add_mc_guid: @@ -377,6 +385,35 @@ int hns3_unic_init_guid(struct net_device *netdev) return ret; } +int hns3_unic_init_guid(struct net_device *netdev) +{ + int ret; + + ret = hns3_unic_init_func_guid(netdev); + if (ret) + return ret; + + return hns3_unic_init_mc_guid(netdev); +} + +static void hns3_unic_uninit_mc_guid(struct net_device *netdev) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(mc_guid); i++) + (void)hns3_unic_del_mc_guid(netdev, mc_guid[i]); +} + +static void hns3_unic_uninit_guid(struct net_device *netdev) +{ + hns3_unic_uninit_mc_guid(netdev); +} + +void hns3_unic_uninit(struct net_device *netdev) +{ + hns3_unic_uninit_guid(netdev); +} + int hns3_unic_fill_skb_desc(struct hns3_nic_priv *priv, struct hns3_enet_ring *ring, struct sk_buff *skb, struct hns3_desc *desc, diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_unic.h b/drivers/net/ethernet/hisilicon/hns3/hns3_unic.h index 8245f887f67c..b034302c8640 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_unic.h +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_unic.h @@ -53,6 +53,7 @@ static inline void hns3_unic_format_sim_guid_addr(char *format_simple_guid_addr, void hns3_unic_set_default_cc(struct sk_buff *skb); int hns3_unic_init(struct net_device *netdev); +void hns3_unic_uninit(struct net_device *netdev); u8 hns3_unic_get_l3_type(struct net_device *netdev, u32 ol_info, u32 l234info); void hns3_unic_lp_setup_skb(struct sk_buff *skb); void hns3_unic_lb_check_skb_data(struct hns3_enet_ring *ring, -- Gitee From 82dc8c56d573eccab8570b62de1eac0b3898ff95 Mon Sep 17 00:00:00 2001 From: Junxin Chen Date: Thu, 15 Aug 2024 22:45:46 +0800 Subject: [PATCH 3/7] unic: deleted redundant code and added default processing driver inclusion category: cleancode bugzilla: https://gitee.com/openeuler/kernel/issues/IAKMX4 CVE: NA ---------------------------------------------------------------- Currently, there are some issues in the driver code, such as unused function parameters, redundant code implementation, and undefined default branches in switches. This patch addresses these issues while also fixing some problems that do not affect functionality but do affect code readability, such as relocating the unic debugfs and fastpatch code. Fixes: 1cdab7738ac9 ("UNIC: Supports query, configuration, and management of IP entry") Signed-off-by: Haibin Lu Signed-off-by: Junxin Chen --- drivers/net/ethernet/hisilicon/hns3/Makefile | 2 +- drivers/net/ethernet/hisilicon/hns3/hnae3.h | 2 + .../hns3/hns3_common/hclge_comm_unic_addr.c | 2 + .../net/ethernet/hisilicon/hns3/hns3_unic.c | 18 +- .../hisilicon/hns3/hns3pf/hclge_debugfs.c | 187 +--------------- .../hisilicon/hns3/hns3pf/hclge_debugfs.h | 4 + .../hisilicon/hns3/hns3pf/hclge_err.c | 2 +- .../hisilicon/hns3/hns3pf/hclge_main.c | 59 ----- .../hisilicon/hns3/hns3pf/hclge_main.h | 6 + .../hisilicon/hns3/hns3pf/hclge_udma.c | 58 +++++ .../hisilicon/hns3/hns3pf/hclge_udma.h | 2 + .../hns3/hns3pf/hclge_unic_debugfs.c | 202 ++++++++++++++++++ .../hns3/hns3pf/hclge_unic_debugfs.h | 26 +++ .../hisilicon/hns3/hns3pf/hclge_unic_guid.c | 27 ++- .../hisilicon/hns3/hns3pf/hclge_unic_guid.h | 12 ++ .../hisilicon/hns3/hns3pf/hclge_unic_ip.c | 7 +- 16 files changed, 355 insertions(+), 261 deletions(-) create mode 100644 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_unic_debugfs.c create mode 100644 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_unic_debugfs.h diff --git a/drivers/net/ethernet/hisilicon/hns3/Makefile b/drivers/net/ethernet/hisilicon/hns3/Makefile index ec994681c30e..9c20446a2d0d 100644 --- a/drivers/net/ethernet/hisilicon/hns3/Makefile +++ b/drivers/net/ethernet/hisilicon/hns3/Makefile @@ -33,6 +33,6 @@ hclge-objs = hns3pf/hclge_main.o hns3pf/hclge_mdio.o hns3pf/hclge_tm.o hns3pf/hc hclge-objs += hns3pf/hclge_ext.o hclge-$(CONFIG_HNS3_UBL) += hns3_common/hclge_comm_unic_addr.o hns3pf/hclge_unic_ip.o hns3pf/hclge_unic_guid.o \ - hns3pf/hclge_unic_addr.o + hns3pf/hclge_unic_addr.o hns3pf/hclge_unic_debugfs.o hclge-$(CONFIG_UB_UDMA_HNS3) += hns3pf/hclge_udma.o hclge-$(CONFIG_HNS3_DCB) += hns3pf/hclge_dcb.o diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h b/drivers/net/ethernet/hisilicon/hns3/hnae3.h index 55d75a83d818..60f79f3285bb 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h +++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h @@ -383,11 +383,13 @@ enum hnae3_dbg_cmd { HNAE3_DBG_CMD_PAGE_POOL_INFO, HNAE3_DBG_CMD_COAL_INFO, HNAE3_DBG_CMD_WOL_INFO, +#ifdef CONFIG_HNS3_UBL HNAE3_DBG_CMD_IP_SPEC, HNAE3_DBG_CMD_GUID_SPEC, HNAE3_DBG_CMD_IP_LIST, HNAE3_DBG_CMD_GUID_LIST, HNAE3_DBG_CMD_FASTPATH_INFO, +#endif HNAE3_DBG_CMD_UNKNOWN, }; diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_common/hclge_comm_unic_addr.c b/drivers/net/ethernet/hisilicon/hns3/hns3_common/hclge_comm_unic_addr.c index 5c11aaa80620..c04c1715fbf5 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_common/hclge_comm_unic_addr.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_common/hclge_comm_unic_addr.c @@ -53,6 +53,8 @@ hclge_comm_unic_update_addr_node(struct hclge_comm_unic_addr_node *addr_node, if (addr_node->state == HCLGE_COMM_UNIC_ADDR_TO_ADD) addr_node->state = HCLGE_COMM_UNIC_ADDR_ACTIVE; break; + default: + break; } } diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_unic.c b/drivers/net/ethernet/hisilicon/hns3/hns3_unic.c index 6d0646966bf5..d15b9899f03e 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_unic.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_unic.c @@ -101,8 +101,8 @@ u8 hns3_unic_get_l3_type(struct net_device *netdev, u32 ol_info, u32 l234info) return UB_UNKNOWN_CFG_TYPE; } -static int addr_event(struct notifier_block *nb, unsigned long event, - struct sockaddr *sa, struct net_device *ndev) +static int addr_event(unsigned long event, struct sockaddr *sa, + struct net_device *ndev) { struct hnae3_handle *handle; int ret; @@ -153,7 +153,7 @@ static int unic_inetaddr_event(struct notifier_block *this, unsigned long event, in.sin_family = AF_INET; in.sin_addr.s_addr = ifa4->ifa_address; - return addr_event(this, event, (struct sockaddr *)&in, ndev); + return addr_event(event, (struct sockaddr *)&in, ndev); } static int unic_inet6addr_event(struct notifier_block *this, unsigned long event, @@ -166,7 +166,7 @@ static int unic_inet6addr_event(struct notifier_block *this, unsigned long event in6.sin6_family = AF_INET6; in6.sin6_addr = ifa6->addr; - return addr_event(this, event, (struct sockaddr *)&in6, ndev); + return addr_event(event, (struct sockaddr *)&in6, ndev); } static struct notifier_block unic_inetaddr_notifier = { @@ -179,14 +179,14 @@ static struct notifier_block unic_inet6addr_notifier = { void register_ipaddr_notifier(void) { - register_inetaddr_notifier(&unic_inetaddr_notifier); - register_inet6addr_notifier(&unic_inet6addr_notifier); + (void)register_inetaddr_notifier(&unic_inetaddr_notifier); + (void)register_inet6addr_notifier(&unic_inet6addr_notifier); } void unregister_ipaddr_notifier(void) { - unregister_inetaddr_notifier(&unic_inetaddr_notifier); - unregister_inet6addr_notifier(&unic_inet6addr_notifier); + (void)unregister_inetaddr_notifier(&unic_inetaddr_notifier); + (void)unregister_inet6addr_notifier(&unic_inet6addr_notifier); } #define UNIC_DHCPV4_PROTO 0x0100 @@ -251,7 +251,7 @@ void hns3_unic_lb_check_skb_data(struct hns3_enet_ring *ring, if (is_success) tqp_vector->rx_group.total_packets++; else - print_hex_dump(KERN_ERR, "ubl selftest:", DUMP_PREFIX_OFFSET, + print_hex_dump(KERN_ERR, "selftest:", DUMP_PREFIX_OFFSET, HNS3_UNIC_DUMP_ROW_SIZE, 1, skb->data, len, true); dev_kfree_skb_any(skb); diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c index 5da8c55548be..01e0c589818b 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c @@ -6,7 +6,7 @@ #include "hclge_debugfs.h" #include "hclge_err.h" #include "hclge_main.h" -#include "hclge_comm_unic_addr.h" +#include "hclge_unic_debugfs.h" #include "hclge_regs.h" #include "hclge_tm.h" #include "hclge_udma.h" @@ -726,9 +726,9 @@ static const struct hclge_dbg_reg_type_info hclge_dbg_reg_info[] = { * for example, name = "pkt_num"(len: 7), the prototype of item data is u32, * and print as "%u"(maxlen: 10), so the interval should be at least 5. */ -static void hclge_dbg_fill_content(char *content, u16 len, - const struct hclge_dbg_item *items, - const char **result, u16 size) +void hclge_dbg_fill_content(char *content, u16 len, + const struct hclge_dbg_item *items, + const char **result, u16 size) { #define HCLGE_DBG_LINE_END_LEN 2 char *pos = content; @@ -764,7 +764,7 @@ static void hclge_dbg_fill_content(char *content, u16 len, *pos++ = '\0'; } -static char *hclge_dbg_get_func_id_str(char *buf, u8 id) +char *hclge_dbg_get_func_id_str(char *buf, u8 id) { if (id) sprintf(buf, "vf%u", id - 1U); @@ -3221,181 +3221,6 @@ static int hclge_dbg_dump_wol_info(struct hclge_dev *hdev, char *buf, int len) return 0; } -static int hclge_dbg_dump_ip_spec(struct hclge_dev *hdev, char *buf, int len) -{ - struct unic_ip_table_info *iptbl_info = &hdev->iptbl_info; - u8 func_num = pci_num_vf(hdev->pdev) + 1; - struct hclge_vport *vport; - int pos = 0; - u8 i; - - pos += scnprintf(buf, len, "num_alloc_vport : %u\n", - hdev->num_alloc_vport); - pos += scnprintf(buf + pos, len - pos, "max_ip_table_size : %u\n", - iptbl_info->max_iptbl_size); - pos += scnprintf(buf + pos, len - pos, "priv_ip_table_size : %u\n", - iptbl_info->priv_iptbl_size); - - mutex_lock(&hdev->vport_lock); - pos += scnprintf(buf + pos, len - pos, "share_ip_table_size : %u\n", - iptbl_info->share_iptbl_size); - for (i = 0; i < func_num; i++) { - vport = &hdev->vport[i]; - pos += scnprintf(buf + pos, len - pos, - "vport(%u) used_ip_table_num : %u\n", - i, vport->used_iptbl_num); - } - mutex_unlock(&hdev->vport_lock); - - return 0; -} - -static int hclge_dbg_dump_guid_spec(struct hclge_dev *hdev, char *buf, int len) -{ - u16 mc_guid_tbl_size; - - mc_guid_tbl_size = min(HCLGE_UNIC_MC_GUID_NUM, - hdev->ae_dev->dev_specs.guid_tbl_space - - HCLGE_VPORT_NUM); - scnprintf(buf, len, "function guid tbl size: %u\nmc guid tbl size: %u\n", - HCLGE_VPORT_NUM, mc_guid_tbl_size); - - return 0; -} - -#define HCLGE_UNIC_DBG_DATA_STR_LEN 50 -#define HCLGE_UNIC_IPV6_LEN 16 - -static const struct hclge_dbg_item ip_list_items[] = { - { "FUNC_ID", 2 }, - { "IP_ADDR", 34 }, - { "STATE", 2 }, -}; - -static int hclge_dbg_dump_ip_list(struct hclge_dev *hdev, char *buf, int len) -{ - char data_str[ARRAY_SIZE(ip_list_items)][HCLGE_UNIC_DBG_DATA_STR_LEN]; - char content[HCLGE_DBG_INFO_LEN], str_id[HCLGE_DBG_ID_LEN]; - struct hclge_comm_unic_addr_node *ip_node, *tmp; - char *result[ARRAY_SIZE(ip_list_items)]; - struct hclge_vport *vport; - struct list_head *list; - u16 used_iptbl_num = 0; - u32 func_id; - int pos = 0; - int i; - - for (i = 0; i < ARRAY_SIZE(ip_list_items); i++) - result[i] = &data_str[i][0]; - - for (i = 0; i < hdev->num_alloc_vport; i++) - used_iptbl_num += hdev->vport[i].used_iptbl_num; - - pos += scnprintf(buf + pos, len - pos, "used ip number: %u\n", - used_iptbl_num); - - hclge_dbg_fill_content(content, sizeof(content), ip_list_items, - NULL, ARRAY_SIZE(ip_list_items)); - pos += scnprintf(buf + pos, len - pos, "%s", content); - - for (func_id = 0; func_id < hdev->num_alloc_vport; func_id++) { - vport = &hdev->vport[func_id]; - list = &vport->ip_list; - spin_lock_bh(&vport->ip_list_lock); - list_for_each_entry_safe(ip_node, tmp, list, node) { - i = 0; - result[i++] = hclge_dbg_get_func_id_str(str_id, - func_id); - sprintf(result[i++], "%pI6c", &ip_node->ip_addr.s6_addr); - sprintf(result[i++], "%5s", - hclge_entry_state_str[ip_node->state]); - hclge_dbg_fill_content(content, sizeof(content), - ip_list_items, - (const char **)result, - ARRAY_SIZE(ip_list_items)); - - if (len - pos < strlen(content)) { - spin_unlock_bh(&vport->ip_list_lock); - dev_warn(&hdev->pdev->dev, - "Warning: IP list debugfs buffer overflow.\n"); - return 0; - } - - pos += scnprintf(buf + pos, len - pos, "%s", content); - } - spin_unlock_bh(&vport->ip_list_lock); - } - return 0; -} - -static int hclge_dbg_dump_guid_list(struct hclge_dev *hdev, char *buf, int len) -{ - char format_guid_addr[HCLGE_COMM_FORMAT_GUID_ADDR_LEN]; - struct hclge_comm_unic_addr_node *guid_node, *tmp; - char str_id[HCLGE_DBG_ID_LEN]; - struct hclge_vport *vport; - struct list_head *list; - u16 func_id; - int pos = 0; - u16 i; - - pos += scnprintf(buf + pos, len - pos, "used mc guid number: %u\n", - hdev->used_mc_guid_num); - pos += scnprintf(buf + pos, len - pos, "mc guid table bitmap: "); - for (i = 0; i < BITS_TO_LONGS(HCLGE_UNIC_MC_GUID_NUM); i++) - pos += scnprintf(buf + pos, len - pos, "%lx ", - hdev->mc_guid_tbl_bmap[i]); - pos += scnprintf(buf + pos, len - pos, "\nMC GUID LIST:\n"); - pos += scnprintf(buf + pos, len - pos, "No. FUNC_ID %-48s STATE\n", "MC_GUID"); - for (func_id = 0, i = 0; func_id < hdev->num_alloc_vport; func_id++) { - vport = &hdev->vport[func_id]; - list = &vport->mc_guid_list; - spin_lock_bh(&vport->mguid_list_lock); - list_for_each_entry_safe(guid_node, tmp, list, node) { - hclge_comm_format_guid_addr(format_guid_addr, - guid_node->mguid); - pos += scnprintf(buf + pos, len - pos, - "%-3d %-7s %-48s %s\n", i++, - hclge_dbg_get_func_id_str(str_id, func_id), - format_guid_addr, - hclge_entry_state_str[guid_node->state]); - } - spin_unlock_bh(&vport->mguid_list_lock); - } - return 0; -} - -static int hclge_dbg_dump_fastpath_info(struct hclge_dev *hdev, char *buf, - int len) -{ - struct hclge_config_fastpath_cmd *fp_info; - struct hclge_desc desc; - int pos = 0; - int ret; - - hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_COMM_CFG_FASTPATH, true); - - ret = hclge_cmd_send(&hdev->hw, &desc, 1); - if (ret) { - dev_err(&hdev->pdev->dev, - "failed to dump fastpath_info, ret = %d\n", ret); - return ret; - } - - fp_info = (struct hclge_config_fastpath_cmd *)desc.data; - - pos += scnprintf(buf + pos, len - pos, "fastpath_en: %u\n", - fp_info->fastpath_en); - pos += scnprintf(buf + pos, len - pos, "ssu_cfg_status: 0x%x\n", - le32_to_cpu(fp_info->ssu_cfg_status)); - pos += scnprintf(buf + pos, len - pos, "igu_cfg_status: 0x%x\n", - le32_to_cpu(fp_info->igu_cfg_status)); - pos += scnprintf(buf + pos, len - pos, "ppp_cfg_status: 0x%x\n", - le32_to_cpu(fp_info->ppp_cfg_status)); - - return 0; -} - static const struct hclge_dbg_func hclge_dbg_cmd_func[] = { { .cmd = HNAE3_DBG_CMD_TM_NODES, @@ -3549,6 +3374,7 @@ static const struct hclge_dbg_func hclge_dbg_cmd_func[] = { .cmd = HNAE3_DBG_CMD_WOL_INFO, .dbg_dump = hclge_dbg_dump_wol_info, }, +#ifdef CONFIG_HNS3_UBL { .cmd = HNAE3_DBG_CMD_IP_SPEC, .dbg_dump = hclge_dbg_dump_ip_spec, @@ -3569,6 +3395,7 @@ static const struct hclge_dbg_func hclge_dbg_cmd_func[] = { .cmd = HNAE3_DBG_CMD_FASTPATH_INFO, .dbg_dump = hclge_dbg_dump_fastpath_info, }, +#endif }; int hclge_dbg_read_cmd(struct hnae3_handle *handle, enum hnae3_dbg_cmd cmd, diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.h b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.h index 3c17c11a7ba0..56d91f653c0d 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.h +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.h @@ -128,5 +128,9 @@ struct hclge_dbg_vlan_cfg { int hclge_dbg_cmd_send(struct hclge_dev *hdev, struct hclge_desc *desc_src, int index, int bd_num, enum hclge_opcode_type cmd); +void hclge_dbg_fill_content(char *content, u16 len, + const struct hclge_dbg_item *items, + const char **result, u16 size); +char *hclge_dbg_get_func_id_str(char *buf, u8 id); #endif diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c index 5f66a4f497c4..84b65994cb9d 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c @@ -3193,7 +3193,7 @@ bool hclge_find_error_source(struct hclge_dev *hdev) HCLGE_RAS_REG_ERR_MASK; #if IS_ENABLED(CONFIG_UB_UDMA_HNS3) udma_err_src_flag = hclge_get_udma_error_reg(hdev) & - HCLGE_RAS_REG_ERR_MASK_UB; + HCLGE_RAS_REG_ERR_MASK_UB; return msix_src_flag || hw_err_src_flag || udma_err_src_flag; #else diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c index d6db0c83e4d7..e76180cc6e82 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c @@ -12439,65 +12439,6 @@ static int hclge_set_wol(struct hnae3_handle *handle, return ret; } -#if IS_ENABLED(CONFIG_UB_UDMA_HNS3) -static int hclge_set_fastpath_cmd(struct hnae3_ae_dev *ae_dev, bool fastpath_en) -{ - struct hclge_dev *hdev = ae_dev->priv; - struct hclge_config_fastpath_cmd *req; - struct hclge_desc desc; - - if (!hnae3_dev_udma_supported(ae_dev)) - return 0; - - hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_COMM_CFG_FASTPATH, false); - req = (struct hclge_config_fastpath_cmd *)desc.data; - req->fastpath_en = fastpath_en; - - return hclge_cmd_send(&hdev->hw, &desc, 1); -} - -static int hclge_set_fastpath(struct hnae3_ae_dev *ae_dev, bool fastpath_en) -{ - struct hclge_dev *hdev = ae_dev->priv; - int last_bad_ret = 0; - int ret; - - while (test_bit(HCLGE_STATE_RST_HANDLING, &hdev->state)) - msleep(HCLGE_WAIT_RESET_DONE); - - rtnl_lock(); - ret = hclge_notify_client(hdev, HNAE3_DOWN_CLIENT); - if (ret) { - rtnl_unlock(); - return ret; - } - - ret = hclge_tm_flush_cfg(hdev, true); - if (ret) { - rtnl_unlock(); - return ret; - } - - ret = hclge_set_fastpath_cmd(ae_dev, fastpath_en); - if (ret) { - dev_err(&hdev->pdev->dev, - "failed to set fastpath, ret = %d\n", ret); - last_bad_ret = ret; - } - - ret = hclge_tm_flush_cfg(hdev, false); - if (ret) - last_bad_ret = ret; - - ret = hclge_notify_client(hdev, HNAE3_UP_CLIENT); - if (ret) - last_bad_ret = ret; - - rtnl_unlock(); - return last_bad_ret; -} -#endif - static int hclge_init_ae_dev(struct hnae3_ae_dev *ae_dev) { struct pci_dev *pdev = ae_dev->pdev; diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h index a0d22c00b22f..120cc567443d 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h @@ -1137,6 +1137,12 @@ struct hclge_link_mode_bmap { enum ethtool_link_mode_bit_indices link_mode; }; +static inline u16 hclge_unic_real_mguid_tbl_size(struct hclge_dev *hdev) +{ + return min(HCLGE_UNIC_MC_GUID_NUM, + hdev->ae_dev->dev_specs.guid_tbl_space - HCLGE_VPORT_NUM); +} + int hclge_set_vport_promisc_mode(struct hclge_vport *vport, bool en_uc_pmc, bool en_mc_pmc, bool en_bc_pmc); int hclge_add_uc_addr_common(struct hclge_vport *vport, diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_udma.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_udma.c index a3bbb6dd17d5..c67cc53e5edb 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_udma.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_udma.c @@ -16,6 +16,7 @@ #include "hclge_main.h" #include "hclge_err.h" #include "hclge_debugfs.h" +#include "hclge_tm.h" #include "hclge_udma.h" static const struct hclge_dbg_status_dfx_info hclge_dbg_rst_info_ub[] = { @@ -136,3 +137,60 @@ void hclge_dbg_dump_udma_rst_info(struct hclge_dev *hdev, char *buf, int len, } } } + +int hclge_set_fastpath_cmd(struct hnae3_ae_dev *ae_dev, bool fastpath_en) +{ + struct hclge_dev *hdev = ae_dev->priv; + struct hclge_config_fastpath_cmd *req; + struct hclge_desc desc; + + if (!hnae3_dev_udma_supported(ae_dev)) + return 0; + + hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_COMM_CFG_FASTPATH, false); + req = (struct hclge_config_fastpath_cmd *)desc.data; + req->fastpath_en = fastpath_en; + + return hclge_cmd_send(&hdev->hw, &desc, 1); +} + +int hclge_set_fastpath(struct hnae3_ae_dev *ae_dev, bool fastpath_en) +{ + struct hclge_dev *hdev = ae_dev->priv; + int last_bad_ret = 0; + int ret; + + while (test_bit(HCLGE_STATE_RST_HANDLING, &hdev->state)) + msleep(HCLGE_WAIT_RESET_DONE); + + rtnl_lock(); + ret = hclge_notify_client(hdev, HNAE3_DOWN_CLIENT); + if (ret) { + rtnl_unlock(); + return ret; + } + + ret = hclge_tm_flush_cfg(hdev, true); + if (ret) { + rtnl_unlock(); + return ret; + } + + ret = hclge_set_fastpath_cmd(ae_dev, fastpath_en); + if (ret) { + dev_err(&hdev->pdev->dev, + "failed to set fastpath, ret = %d\n", ret); + last_bad_ret = ret; + } + + ret = hclge_tm_flush_cfg(hdev, false); + if (ret) + last_bad_ret = ret; + + ret = hclge_notify_client(hdev, HNAE3_UP_CLIENT); + if (ret) + last_bad_ret = ret; + + rtnl_unlock(); + return last_bad_ret; +} diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_udma.h b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_udma.h index b3a99df54218..433923abd322 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_udma.h +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_udma.h @@ -29,5 +29,7 @@ int hclge_init_udma_client_instance(struct hnae3_ae_dev *ae_dev, u32 hclge_get_udma_error_reg(struct hclge_dev *hdev); void hclge_dbg_dump_udma_rst_info(struct hclge_dev *hdev, char *buf, int len, int *pos); +int hclge_set_fastpath_cmd(struct hnae3_ae_dev *ae_dev, bool fastpath_en); +int hclge_set_fastpath(struct hnae3_ae_dev *ae_dev, bool fastpath_en); #endif diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_unic_debugfs.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_unic_debugfs.c new file mode 100644 index 000000000000..00a9d7022e89 --- /dev/null +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_unic_debugfs.c @@ -0,0 +1,202 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* Copyright (c) 2024-2024 Hisilicon Limited. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + */ + +#include "hclge_comm_unic_addr.h" +#include "hclge_debugfs.h" +#include "hclge_unic_debugfs.h" + +int hclge_dbg_dump_ip_spec(struct hclge_dev *hdev, char *buf, int len) +{ + struct unic_ip_table_info *iptbl_info = &hdev->iptbl_info; + u8 func_num = pci_num_vf(hdev->pdev) + 1; + struct hclge_vport *vport; + int pos = 0; + u8 i; + + pos += scnprintf(buf, len, "num_alloc_vport : %u\n", + hdev->num_alloc_vport); + pos += scnprintf(buf + pos, len - pos, "max_ip_table_size : %u\n", + iptbl_info->max_iptbl_size); + pos += scnprintf(buf + pos, len - pos, "priv_ip_table_size : %u\n", + iptbl_info->priv_iptbl_size); + + mutex_lock(&hdev->vport_lock); + pos += scnprintf(buf + pos, len - pos, "share_ip_table_size : %u\n", + iptbl_info->share_iptbl_size); + for (i = 0; i < func_num; i++) { + vport = &hdev->vport[i]; + pos += scnprintf(buf + pos, len - pos, + "vport(%u) used_ip_table_num : %u\n", + i, vport->used_iptbl_num); + } + mutex_unlock(&hdev->vport_lock); + + return 0; +} + +int hclge_dbg_dump_guid_spec(struct hclge_dev *hdev, char *buf, int len) +{ + u16 mc_guid_tbl_size; + + mc_guid_tbl_size = hclge_unic_real_mguid_tbl_size(hdev); + scnprintf(buf, len, "function guid tbl size: %u\nmc guid tbl size: %u\n", + HCLGE_VPORT_NUM, mc_guid_tbl_size); + + return 0; +} + +#define HCLGE_UNIC_DBG_DATA_STR_LEN 50 +#define HCLGE_UNIC_IPV6_LEN 16 + +static const struct hclge_dbg_item ip_list_items[] = { + { "FUNC_ID", 2 }, + { "IP_ADDR", 34 }, + { "STATE", 2 }, +}; + +static const char * const hclge_unic_entry_state_str[] = { + "TO_ADD", "TO_DEL", "ACTIVE" +}; + +int hclge_dbg_dump_ip_list(struct hclge_dev *hdev, char *buf, int len) +{ + char data_str[ARRAY_SIZE(ip_list_items)][HCLGE_UNIC_DBG_DATA_STR_LEN]; + char content[HCLGE_DBG_INFO_LEN], str_id[HCLGE_DBG_ID_LEN]; + struct hclge_comm_unic_addr_node *ip_node, *tmp; + char *result[ARRAY_SIZE(ip_list_items)]; + struct hclge_vport *vport; + struct list_head *list; + u16 used_iptbl_num = 0; + u32 func_id; + int pos = 0; + int i; + + for (i = 0; i < ARRAY_SIZE(ip_list_items); i++) + result[i] = &data_str[i][0]; + + for (i = 0; i < hdev->num_alloc_vport; i++) + used_iptbl_num += hdev->vport[i].used_iptbl_num; + + pos += scnprintf(buf + pos, len - pos, "used ip number: %u\n", + used_iptbl_num); + + hclge_dbg_fill_content(content, sizeof(content), ip_list_items, + NULL, ARRAY_SIZE(ip_list_items)); + pos += scnprintf(buf + pos, len - pos, "%s", content); + + for (func_id = 0; func_id < hdev->num_alloc_vport; func_id++) { + vport = &hdev->vport[func_id]; + list = &vport->ip_list; + spin_lock_bh(&vport->ip_list_lock); + list_for_each_entry_safe(ip_node, tmp, list, node) { + i = 0; + result[i++] = hclge_dbg_get_func_id_str(str_id, + func_id); + sprintf(result[i++], "%pI6c", &ip_node->ip_addr.s6_addr); + sprintf(result[i++], "%5s", + hclge_unic_entry_state_str[ip_node->state]); + hclge_dbg_fill_content(content, sizeof(content), + ip_list_items, + (const char **)result, + ARRAY_SIZE(ip_list_items)); + + if (len - pos < strlen(content)) { + spin_unlock_bh(&vport->ip_list_lock); + dev_warn(&hdev->pdev->dev, + "Warning: IP list debugfs buffer overflow.\n"); + return 0; + } + + pos += scnprintf(buf + pos, len - pos, "%s", content); + } + spin_unlock_bh(&vport->ip_list_lock); + } + return 0; +} + +int hclge_dbg_dump_guid_list(struct hclge_dev *hdev, char *buf, int len) +{ +#define HCLGE_UNIC_GUID_DUMP_SIZE 68 + + char format_guid_addr[HCLGE_COMM_FORMAT_GUID_ADDR_LEN]; + struct hclge_comm_unic_addr_node *guid_node, *tmp; + char str_id[HCLGE_DBG_ID_LEN]; + struct hclge_vport *vport; + struct list_head *list; + u16 func_id; + int pos = 0; + u16 i; + + pos += scnprintf(buf + pos, len - pos, "used mc guid number: %u\n", + hdev->used_mc_guid_num); + pos += scnprintf(buf + pos, len - pos, "mc guid table bitmap: "); + for (i = 0; i < BITS_TO_LONGS(HCLGE_UNIC_MC_GUID_NUM); i++) + pos += scnprintf(buf + pos, len - pos, "%lx ", + hdev->mc_guid_tbl_bmap[i]); + pos += scnprintf(buf + pos, len - pos, "\nMC GUID LIST:\n"); + pos += scnprintf(buf + pos, len - pos, "No. FUNC_ID %-48s STATE\n", "MC_GUID"); + for (func_id = 0, i = 0; func_id < hdev->num_alloc_vport; func_id++) { + vport = &hdev->vport[func_id]; + list = &vport->mc_guid_list; + spin_lock_bh(&vport->mguid_list_lock); + list_for_each_entry_safe(guid_node, tmp, list, node) { + if (len - pos < HCLGE_UNIC_GUID_DUMP_SIZE) { + spin_unlock_bh(&vport->mguid_list_lock); + dev_warn(&hdev->pdev->dev, + "Warning: GUID list debugfs buffer overflow.\n"); + return 0; + } + + hclge_comm_format_guid_addr(format_guid_addr, + guid_node->mguid); + pos += scnprintf(buf + pos, len - pos, + "%-3d %-7s %-48s %s\n", i++, + hclge_dbg_get_func_id_str(str_id, func_id), + format_guid_addr, + hclge_unic_entry_state_str[guid_node->state]); + } + spin_unlock_bh(&vport->mguid_list_lock); + } + return 0; +} + +int hclge_dbg_dump_fastpath_info(struct hclge_dev *hdev, char *buf, int len) +{ + struct hclge_config_fastpath_cmd *fp_info; + struct hclge_desc desc; + int pos = 0; + int ret; + + hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_COMM_CFG_FASTPATH, true); + + ret = hclge_cmd_send(&hdev->hw, &desc, 1); + if (ret) { + dev_err(&hdev->pdev->dev, + "failed to dump fastpath_info, ret = %d\n", ret); + return ret; + } + + fp_info = (struct hclge_config_fastpath_cmd *)desc.data; + + pos += scnprintf(buf + pos, len - pos, "fastpath_en: %u\n", + fp_info->fastpath_en); + pos += scnprintf(buf + pos, len - pos, "ssu_cfg_status: 0x%x\n", + le32_to_cpu(fp_info->ssu_cfg_status)); + pos += scnprintf(buf + pos, len - pos, "igu_cfg_status: 0x%x\n", + le32_to_cpu(fp_info->igu_cfg_status)); + pos += scnprintf(buf + pos, len - pos, "ppp_cfg_status: 0x%x\n", + le32_to_cpu(fp_info->ppp_cfg_status)); + + return 0; +} diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_unic_debugfs.h b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_unic_debugfs.h new file mode 100644 index 000000000000..de30d9189d86 --- /dev/null +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_unic_debugfs.h @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* Copyright (c) 2024-2024 Hisilicon Limited. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + */ + +#ifndef __HCLGE_UNIC_DEBUGFS_H +#define __HCLGE_UNIC_DEBUGFS_H + +#include "hclge_main.h" + +int hclge_dbg_dump_ip_spec(struct hclge_dev *hdev, char *buf, int len); +int hclge_dbg_dump_guid_spec(struct hclge_dev *hdev, char *buf, int len); +int hclge_dbg_dump_ip_list(struct hclge_dev *hdev, char *buf, int len); +int hclge_dbg_dump_guid_list(struct hclge_dev *hdev, char *buf, int len); +int hclge_dbg_dump_fastpath_info(struct hclge_dev *hdev, char *buf, int len); + +#endif diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_unic_guid.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_unic_guid.c index efb760f0c209..44a6b54539bc 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_unic_guid.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_unic_guid.c @@ -183,8 +183,8 @@ int hclge_unic_add_mc_guid_common(struct hclge_vport *vport, goto err_no_space; is_new_guid = true; memset(desc[0].data, 0, sizeof(desc[0].data)); - memset(desc[1].data, 0, sizeof(desc[0].data)); - memset(desc[2].data, 0, sizeof(desc[0].data)); + memset(desc[1].data, 0, sizeof(desc[1].data)); + memset(desc[2].data, 0, sizeof(desc[2].data)); } ret = hclge_unic_fill_add_desc(vport, &req, desc, is_new_guid); @@ -213,11 +213,15 @@ int hclge_unic_add_mc_guid_common(struct hclge_vport *vport, static bool hclge_unic_is_all_function_deleted(struct hclge_desc *desc) { -#define HCLGE_UNIC_DWORD_OF_MGUID 4 + struct hclge_unic_mc_guid_cfg_cmd_1 *resp1; + struct hclge_unic_mc_guid_cfg_cmd_2 *resp2; int i; + resp1 = (struct hclge_unic_mc_guid_cfg_cmd_1 *)desc[1].data; + resp2 = (struct hclge_unic_mc_guid_cfg_cmd_2 *)desc[2].data; + for (i = 0; i < HCLGE_UNIC_DWORD_OF_MGUID; i++) { - if (desc[1].data[2 + i] || desc[2].data[2 + i]) + if (resp1->guid_data_h[i] || resp2->guid_data_l[i]) return false; } @@ -404,6 +408,8 @@ static void hclge_unic_uninit_vport_guid_list(struct hclge_vport *vport) list_del(&guid_node->node); kfree(guid_node); break; + default: + break; } } @@ -437,15 +443,14 @@ void hclge_unic_uninit_mguid_table(struct hclge_dev *hdev) int hclge_unic_set_vf_mc_guid(struct hclge_vport *vport, struct hclge_mbx_vf_to_pf_cmd *mbx_req) { - __le16 proto = *(__le16 *)(mbx_req->msg.data); struct hclge_dev *hdev = vport->back; - __le16 *mguid_proto = NULL; + __le16 *mguid_proto; u8 mguid[UBL_ALEN]; int ret = 0; - memset(mguid, 0xff, UBL_ALEN); + memset(mguid, 0xff, HCLGE_COMM_MGUID_PREFIX_LEN); mguid_proto = (__le16 *)&mguid[HCLGE_COMM_MGUID_PREFIX_LEN]; - *mguid_proto = proto; + *mguid_proto = *(__le16 *)(mbx_req->msg.data); if (mbx_req->msg.subcode == HCLGE_MBX_MC_GUID_MC_ADD) { ret = hclge_unic_update_guid_list(vport, @@ -509,6 +514,8 @@ static void hclge_unic_build_del_list(struct list_head *list, kfree(guid_node); } break; + default: + break; } } } @@ -525,8 +532,8 @@ static void hclge_unic_unsync_del_list(struct hclge_vport *vport, list_for_each_entry_safe(guid_node, tmp, tmp_del_list, node) { ret = unsync(vport, guid_node->mguid); if (!ret || ret == -ENOENT) { - /* clear all mac addr from hardware, but remain these - * mac addr in the mac list, and restore them after + /* clear all guid addr from hardware, but remain these + * guid addr in the guid list, and restore them after * vf reset finished. */ if (!is_del_list && diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_unic_guid.h b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_unic_guid.h index 56f11f43a553..ac81424903a7 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_unic_guid.h +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_unic_guid.h @@ -19,6 +19,18 @@ struct hclge_unic_mc_guid_cfg_cmd { __le16 hit_info; }; +#define HCLGE_UNIC_CMD_HDR_LEN_OF_MGUID 8 +#define HCLGE_UNIC_DWORD_OF_MGUID 4 +struct hclge_unic_mc_guid_cfg_cmd_1 { + u8 rsvd[HCLGE_UNIC_CMD_HDR_LEN_OF_MGUID]; + __le32 guid_data_h[HCLGE_UNIC_DWORD_OF_MGUID]; +}; + +struct hclge_unic_mc_guid_cfg_cmd_2 { + u8 rsvd[HCLGE_UNIC_CMD_HDR_LEN_OF_MGUID]; + __le32 guid_data_l[HCLGE_UNIC_DWORD_OF_MGUID]; +}; + #define HCLGE_UNIC_BIT_NUM_PER_BD 128 #define HCLGE_UNIC_ENTRY_VLD_B 0 diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_unic_ip.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_unic_ip.c index 39b2a6a07d85..a12ca70d7648 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_unic_ip.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_unic_ip.c @@ -403,10 +403,11 @@ static bool hclge_unic_need_sync_ip_table(struct hclge_vport *vport) void hclge_unic_sync_ip_table(struct hclge_dev *hdev) { + struct hclge_vport *vport; int i; for (i = 0; i < hdev->num_alloc_vport; i++) { - struct hclge_vport *vport = &hdev->vport[i]; + vport = &hdev->vport[i]; if (!hclge_unic_need_sync_ip_table(vport)) continue; @@ -459,6 +460,8 @@ static void hclge_unic_build_ip_del_list(struct list_head *list, kfree(ip_cfg); } break; + default: + break; } } } @@ -541,6 +544,8 @@ static void hclge_unic_uninit_vport_ip_list(struct hclge_vport *vport) list_del(&ip_node->node); kfree(ip_node); break; + default: + break; } } -- Gitee From f408b37664ccdd225cd144a35a79b86394b91fd4 Mon Sep 17 00:00:00 2001 From: Junxin Chen Date: Thu, 15 Aug 2024 23:35:26 +0800 Subject: [PATCH 4/7] unic: fix issue that return value is not processed driver inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/IAKMX4 CVE: NA ----------------------------------------------------------- The current code implementation has some functions that do not handle return values, which may pose security risks. This patch adds return value handling and removes redundant return value processing. Fixes: 97d2f8090892 ("UNIC: Debugfs supports query of ip and guid table's list and specification") Signed-off-by: Haibin Lu Signed-off-by: Junxin Chen --- .../net/ethernet/hisilicon/hns3/hns3_unic.c | 18 +++++----- .../hisilicon/hns3/hns3_unic_debugfs.c | 34 ++++++++++++++----- .../hisilicon/hns3/hns3_unic_debugfs.h | 1 - .../hisilicon/hns3/hns3pf/hclge_main.c | 7 ++-- .../hisilicon/hns3/hns3pf/hclge_main.h | 4 +-- .../hisilicon/hns3/hns3pf/hclge_udma.c | 6 +++- .../hisilicon/hns3/hns3pf/hclge_unic_guid.c | 34 ++++++------------- .../hisilicon/hns3/hns3pf/hclge_unic_ip.c | 15 ++++---- .../hisilicon/hns3/hns3pf/hclge_unic_ip.h | 2 +- .../hisilicon/hns3/hns3vf/hclgevf_udma.c | 3 ++ .../hisilicon/hns3/hns3vf/hclgevf_unic_ip.c | 15 ++++---- .../hisilicon/hns3/hns3vf/hclgevf_unic_ip.h | 1 - 12 files changed, 75 insertions(+), 65 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_unic.c b/drivers/net/ethernet/hisilicon/hns3/hns3_unic.c index d15b9899f03e..9559dff38c93 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_unic.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_unic.c @@ -274,6 +274,9 @@ static int hns3_unic_add_mc_guid(struct net_device *netdev, struct hnae3_handle *h = hns3_get_handle(netdev); u8 mguid[UBL_ALEN] = {0}; + if (!h->ae_algo->ops->add_addr) + return -EOPNOTSUPP; + if (!hns3_unic_mguid_valid_check(addr)) { hns3_unic_format_sim_guid_addr(format_simple_guid_addr, addr); netdev_err(netdev, "Add mc guid err! invalid guid: %s\n", @@ -282,11 +285,9 @@ static int hns3_unic_add_mc_guid(struct net_device *netdev, } hns3_unic_extern_mc_guid(mguid, addr); - if (h->ae_algo->ops->add_addr) - return h->ae_algo->ops->add_addr(h, (const u8 *)mguid, - HNAE3_UNIC_MCGUID_ADDR); - return 0; + return h->ae_algo->ops->add_addr(h, (const u8 *)mguid, + HNAE3_UNIC_MCGUID_ADDR); } static int hns3_unic_del_mc_guid(struct net_device *netdev, @@ -296,6 +297,9 @@ static int hns3_unic_del_mc_guid(struct net_device *netdev, struct hnae3_handle *h = hns3_get_handle(netdev); u8 mguid[UBL_ALEN] = {0}; + if (!h->ae_algo->ops->rm_addr) + return -EOPNOTSUPP; + if (!hns3_unic_mguid_valid_check(addr)) { hns3_unic_format_sim_guid_addr(format_simple_guid_addr, addr); netdev_err(netdev, "Del mc guid err! invalid guid: %s\n", @@ -304,11 +308,9 @@ static int hns3_unic_del_mc_guid(struct net_device *netdev, } hns3_unic_extern_mc_guid(mguid, addr); - if (h->ae_algo->ops->rm_addr) - return h->ae_algo->ops->rm_addr(h, (const u8 *)mguid, - HNAE3_UNIC_MCGUID_ADDR); - return 0; + return h->ae_algo->ops->rm_addr(h, (const u8 *)mguid, + HNAE3_UNIC_MCGUID_ADDR); } static u8 hns3_unic_get_netdev_flags(struct net_device *netdev) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_unic_debugfs.c b/drivers/net/ethernet/hisilicon/hns3/hns3_unic_debugfs.c index 2b2727c6b0b0..ff7106a00a31 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_unic_debugfs.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_unic_debugfs.c @@ -20,9 +20,6 @@ #include "hns3_enet.h" #include "hns3_unic_debugfs.h" -static const char ub_dbg_root_name[] = "ub"; -static struct dentry *ub_dbg_root; - static struct hns3_dbg_dentry_info ub_dbg_dentry[] = { { .name = "ip_tbl" @@ -172,26 +169,34 @@ static const struct file_operations ub_dbg_fops = { .read = hns3_unic_dbg_read, }; -static int hns3_unic_dbg_file_init(struct hnae3_handle *handle, u32 cmd) +static int hns3_unic_dbg_file_init(struct hnae3_handle *handle, u32 index) { struct hns3_dbg_data *data; struct dentry *entry_dir; + struct dentry *file; data = devm_kzalloc(&handle->pdev->dev, sizeof(*data), GFP_KERNEL); if (!data) return -ENOMEM; data->handle = handle; - data->cmd = ub_dbg_cmd[cmd].cmd; - entry_dir = ub_dbg_dentry[ub_dbg_cmd[cmd].dentry].dentry; - debugfs_create_file(ub_dbg_cmd[cmd].name, 0400, entry_dir, - data, &ub_dbg_fops); + data->cmd = ub_dbg_cmd[index].cmd; + entry_dir = ub_dbg_dentry[ub_dbg_cmd[index].dentry].dentry; + file = debugfs_create_file(ub_dbg_cmd[index].name, 0400, entry_dir, + data, &ub_dbg_fops); + if (IS_ERR_OR_NULL(file)) { + dev_err(&handle->pdev->dev, "failed to create %s file.\n", + ub_dbg_cmd[index].name); + return -EFAULT; + } return 0; } int hns3_unic_dbg_init(struct hnae3_handle *handle, struct dentry *parent) { + char ub_dbg_root_name[] = "ub"; + struct dentry *ub_dbg_root; int ret = 0; u32 i; @@ -206,10 +211,21 @@ int hns3_unic_dbg_init(struct hnae3_handle *handle, struct dentry *parent) return -ENOMEM; ub_dbg_root = debugfs_create_dir(ub_dbg_root_name, parent); + if (IS_ERR_OR_NULL(ub_dbg_root)) { + dev_err(&handle->pdev->dev, + "failed to create unic debugfs root dir.\n"); + return -EFAULT; + } - for (i = 0; i < UB_DBG_DENTRY_END; i++) + for (i = 0; i < ARRAY_SIZE(ub_dbg_dentry); i++) { ub_dbg_dentry[i].dentry = debugfs_create_dir(ub_dbg_dentry[i].name, ub_dbg_root); + if (IS_ERR_OR_NULL(ub_dbg_dentry[i].dentry)) { + dev_err(&handle->pdev->dev, "failed to create %s dir.\n", + ub_dbg_dentry[i].name); + return -EFAULT; + } + } for (i = 0; i < ARRAY_SIZE(ub_dbg_cmd); i++) { if (!ub_dbg_cmd[i].init) { diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_unic_debugfs.h b/drivers/net/ethernet/hisilicon/hns3/hns3_unic_debugfs.h index dfac780d827a..476e5b23a8e4 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_unic_debugfs.h +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_unic_debugfs.h @@ -20,7 +20,6 @@ enum hns3_dbg_ub_dentry_type { UB_DBG_DENTRY_IP, UB_DBG_DENTRY_GUID, UB_DBG_DENTRY_FASTPATH, - UB_DBG_DENTRY_END, }; int hns3_unic_dbg_init(struct hnae3_handle *handle, struct dentry *parent); diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c index e76180cc6e82..811a13a146f8 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c @@ -12543,11 +12543,8 @@ static int hclge_init_ae_dev(struct hnae3_ae_dev *ae_dev) goto err_mdiobus_unreg; #ifdef CONFIG_HNS3_UBL - if (hnae3_dev_ubl_supported(ae_dev)) { - ret = hclge_unic_init_iptbl_info(hdev); - if (ret) - goto err_mdiobus_unreg; - } + if (hnae3_dev_ubl_supported(ae_dev)) + hclge_unic_init_iptbl_info(hdev); #endif ret = hclge_mac_init(hdev); diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h index 120cc567443d..8b27c044c364 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h @@ -97,8 +97,8 @@ #define HCLGE_UMV_TBL_SIZE 3072 #define HCLGE_DEFAULT_UMV_SPACE_PER_PF \ (HCLGE_UMV_TBL_SIZE / HCLGE_MAX_PF_NUM) -#define HCLGE_DEFAULT_GUID_TBL_SIZE 64 -#define HCLGE_DEFAULT_IP_TBL_SIZE 1024 +#define HCLGE_DEFAULT_GUID_TBL_SIZE 320 +#define HCLGE_DEFAULT_IP_TBL_SIZE 1024 #define HCLGE_TQP_RESET_TRY_TIMES 200 diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_udma.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_udma.c index c67cc53e5edb..308ef30e24ee 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_udma.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_udma.c @@ -80,6 +80,9 @@ int hclge_init_udma_client_instance(struct hnae3_ae_dev *ae_dev, return 0; client = hdev->udma_client; + if (!client->ops->init_instance) + return -EOPNOTSUPP; + ret = hclge_init_udma_base_info(vport); if (ret) return ret; @@ -105,7 +108,8 @@ int hclge_init_udma_client_instance(struct hnae3_ae_dev *ae_dev, while (test_bit(HCLGE_STATE_RST_HANDLING, &hdev->state)) msleep(HCLGE_WAIT_RESET_DONE); - hdev->udma_client->ops->uninit_instance(&vport->udma, 0); + if (hdev->udma_client->ops->uninit_instance) + hdev->udma_client->ops->uninit_instance(&vport->udma, 0); return ret; } diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_unic_guid.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_unic_guid.c index 44a6b54539bc..9c992996306e 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_unic_guid.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_unic_guid.c @@ -68,7 +68,6 @@ static int hclge_unic_lookup_mc_guid(struct hclge_vport *vport, struct hclge_unic_mc_guid_cfg_cmd *resp; struct hclge_dev *hdev = vport->back; u16 resp_code; - u16 retval; int ret; resp = (struct hclge_unic_mc_guid_cfg_cmd *)desc[0].data; @@ -85,13 +84,8 @@ static int hclge_unic_lookup_mc_guid(struct hclge_vport *vport, ret); return ret; } - resp_code = resp->hit_info; - retval = le16_to_cpu(desc[0].retval); - if (retval) { - dev_err(&hdev->pdev->dev, "cmdq execute failed for lookup mc guid, status = %u.\n", - retval); - return -EIO; - } else if (!(resp_code & HCLGE_UNIC_GUID_HIT)) { + resp_code = le16_to_cpu(resp->hit_info); + if (!(resp_code & HCLGE_UNIC_GUID_HIT)) { dev_dbg(&hdev->pdev->dev, "lookup mc guid failed for miss.\n"); return -ENOENT; } @@ -108,19 +102,18 @@ static int hclge_unic_fill_add_desc(struct hclge_vport *vport, struct hclge_dev *hdev = vport->back; u16 mc_guid_tbl_size; - mc_guid_tbl_size = min(HCLGE_UNIC_MC_GUID_NUM, - hdev->ae_dev->dev_specs.guid_tbl_space - - HCLGE_VPORT_NUM); + mc_guid_tbl_size = hclge_unic_real_mguid_tbl_size(hdev); if (is_new_guid) { req->index = find_first_zero_bit(hdev->mc_guid_tbl_bmap, HCLGE_UNIC_MC_GUID_NUM); - if (req->index >= mc_guid_tbl_size) - return -ENOSPC; } else { rsp = (struct hclge_unic_mc_guid_cfg_cmd *)desc[0].data; req->index = rsp->index; } + if (req->index >= mc_guid_tbl_size) + return -ENOSPC; + if (vport->vport_id >= HCLGE_VPORT_NUM) return -EIO; req->ad_data = req->index; @@ -140,7 +133,6 @@ static int hclge_unic_add_mc_guid_cmd(struct hclge_vport *vport, struct hclge_desc *desc) { struct hclge_dev *hdev = vport->back; - u16 retval; int ret; req->vld_lookup_flag = BIT(HCLGE_UNIC_ENTRY_VLD_B); @@ -156,18 +148,12 @@ static int hclge_unic_add_mc_guid_cmd(struct hclge_vport *vport, dev_err(&hdev->pdev->dev, "add mc guid failed, ret = %d\n", ret); return ret; } - retval = le16_to_cpu(desc[0].retval); - if (retval) { - dev_err(&hdev->pdev->dev, "cmdq execute failed for add mc guid, status = %u.\n", - retval); - return -EIO; - } return 0; } -int hclge_unic_add_mc_guid_common(struct hclge_vport *vport, - const unsigned char *mguid) +static int hclge_unic_add_mc_guid_common(struct hclge_vport *vport, + const unsigned char *mguid) { struct hclge_unic_mc_guid_cfg_cmd req = {0}; struct hclge_dev *hdev = vport->back; @@ -179,7 +165,7 @@ int hclge_unic_add_mc_guid_common(struct hclge_vport *vport, ret = hclge_unic_lookup_mc_guid(vport, &req, desc); if (ret) { if (hdev->used_mc_guid_num >= - hdev->ae_dev->dev_specs.guid_tbl_space - HCLGE_VPORT_NUM) + hclge_unic_real_mguid_tbl_size(hdev)) goto err_no_space; is_new_guid = true; memset(desc[0].data, 0, sizeof(desc[0].data)); @@ -200,7 +186,7 @@ int hclge_unic_add_mc_guid_common(struct hclge_vport *vport, hdev->used_mc_guid_num++; } - return 0; + return ret; err_no_space: /* if already overflow, not to print each time */ if (!(vport->overflow_promisc_flags & HNAE3_OVERFLOW_MGP)) { diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_unic_ip.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_unic_ip.c index a12ca70d7648..c53c08791026 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_unic_ip.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_unic_ip.c @@ -165,7 +165,7 @@ static int hclge_unic_add_ip_tbl(struct hclge_vport *vport, HCLGE_IP_TBL_ADD); } -int hclge_unic_init_iptbl_info(struct hclge_dev *hdev) +void hclge_unic_init_iptbl_info(struct hclge_dev *hdev) { struct unic_ip_table_info *iptbl_info = &hdev->iptbl_info; @@ -177,8 +177,6 @@ int hclge_unic_init_iptbl_info(struct hclge_dev *hdev) memset(&iptbl_info->ipaddr_to_assemble, 0, sizeof(struct sockaddr_in6)); iptbl_info->upper_ip_addr_state = HCLGE_UNIC_IP_ADDR_NOTSET; - - return 0; } void hclge_unic_reset_iptbl_space(struct hclge_dev *hdev) @@ -245,16 +243,19 @@ int hclge_unic_update_ip_list(struct hclge_vport *vport, struct in6_addr ip_addr; int ret; - hclge_comm_unic_convert_ip_addr(addr, &ip_addr); + ret = hclge_comm_unic_convert_ip_addr(addr, &ip_addr); + if (ret) { + dev_err(&hdev->pdev->dev, + "failed to convert ip addr, ret = %d", ret); + return ret; + } ret = hclge_comm_unic_update_addr_list(&vport->ip_list, &vport->ip_list_lock, state, (const unsigned char *)&ip_addr); if (ret == -ENOENT) - dev_err(&hdev->pdev->dev, - "failed to delete ip %pI6c from ip list\n", - ip_addr.s6_addr); + dev_err(&hdev->pdev->dev, "failed to delete ip from ip list\n"); if (!ret) set_bit(HCLGE_VPORT_STATE_IP_TBL_CHANGE, &vport->state); diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_unic_ip.h b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_unic_ip.h index 5c0cd5af9fb4..203bcab1b42f 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_unic_ip.h +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_unic_ip.h @@ -24,7 +24,7 @@ struct hclge_dev; #define HCLGE_UNIC_IP_ADDR_NOTSET 255 #define HCLGE_UNIC_IP_TBL_MISS 1 -int hclge_unic_init_iptbl_info(struct hclge_dev *hdev); +void hclge_unic_init_iptbl_info(struct hclge_dev *hdev); void hclge_unic_reset_iptbl_space(struct hclge_dev *hdev); void hclge_unic_sync_ip_table(struct hclge_dev *hdev); void hclge_unic_restore_ip_table(struct hclge_vport *vport); diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_udma.c b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_udma.c index eb0164ba2855..37c362762657 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_udma.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_udma.c @@ -69,6 +69,9 @@ int hclgevf_init_udma_client_instance(struct hnae3_ae_dev *ae_dev, !hdev->nic_client) return 0; + if (!client->ops->init_instance) + return -EOPNOTSUPP; + ret = hclgevf_init_udma_base_info(hdev); if (ret) return ret; diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_unic_ip.c b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_unic_ip.c index 79131ca418a5..9048f6bf8271 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_unic_ip.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_unic_ip.c @@ -29,16 +29,19 @@ int hclgevf_unic_update_ip_list(struct hnae3_handle *handle, struct in6_addr ip_addr; int ret; - hclge_comm_unic_convert_ip_addr(addr, &ip_addr); + ret = hclge_comm_unic_convert_ip_addr(addr, &ip_addr); + if (ret) { + dev_err(&hdev->pdev->dev, + "failed to convert ip addr, ret = %d", ret); + return ret; + } ret = hclge_comm_unic_update_addr_list(&hdev->ip_table.ip_list, &hdev->ip_table.ip_list_lock, state, (const unsigned char *)&ip_addr); if (ret == -ENOENT) - dev_err(&hdev->pdev->dev, - "failed to delete ip %pI6c from ip list\n", - ip_addr.s6_addr); + dev_err(&hdev->pdev->dev, "failed to delete ip from ip list\n"); return ret; } @@ -107,8 +110,8 @@ static void hclgevf_unic_config_ip_list(struct hnae3_handle *h, ret = hclgevf_unic_add_del_ip_addr(hdev, ip_node); if (ret) { dev_err(&hdev->pdev->dev, - "failed to configure ip %pI6c, state = %d, ret = %d\n", - ip_node->ip_addr.s6_addr, ip_node->state, ret); + "failed to configure ip, state = %d, ret = %d\n", + ip_node->state, ret); return; } if (ip_node->state == HCLGE_COMM_UNIC_ADDR_TO_ADD) { diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_unic_ip.h b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_unic_ip.h index 1bbbe24ed5de..940beeaab049 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_unic_ip.h +++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_unic_ip.h @@ -15,7 +15,6 @@ #ifndef __HCLGEVF_UNIC_IP_H #define __HCLGEVF_UNIC_IP_H -#include #include #include -- Gitee From a2960a090ee22f8c20a1ecddcb493faeb558efd5 Mon Sep 17 00:00:00 2001 From: Junxin Chen Date: Thu, 15 Aug 2024 23:40:55 +0800 Subject: [PATCH 5/7] ubl: correct comments and delete unused EXPORT_SYMBOL driver inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/IAKMX4 CVE: NA ----------------------------------------------------------- The interfaces ubl_create_header and ubl_add_sw_ctype are currently not being used externally. In order to minimize the exposure and reduce security risks as much as possible. This patch removes the export of these interfaces and corrects some comments. Fixes: eb44201ee79c ("ubl: add CONFIG_UBL definition and UBL interface") Signed-off-by: Haibin Lu Signed-off-by: Junxin Chen --- drivers/net/ub/dev/ubl.c | 30 ++++++++++++++++-------------- drivers/net/ub/dev/ubl.h | 12 ++++-------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/drivers/net/ub/dev/ubl.c b/drivers/net/ub/dev/ubl.c index b49a6b0e30b8..bdae93f016ae 100644 --- a/drivers/net/ub/dev/ubl.c +++ b/drivers/net/ub/dev/ubl.c @@ -49,15 +49,15 @@ static __be16 ubl_type_to_proto(u8 type) * @skb: buffer to alter * @ctype: indicates the packet type * - * The packet type cannot be known by parsing packe from user, + * The packet type cannot be known by parsing packets from user, * which leads to restrictions on the use of socket. - * Add cs_type field to indicate the packet type. And sw_ctype + * Add sw_ctype field to indicate the packet type. And sw_ctype * exists only during software prcessing. * +----------+----+-----+-----------+ * | sw_ctype | CC | NPI | L3 Packet | * +----------+----+-----+-----------+ */ -int ubl_add_sw_ctype(struct sk_buff *skb, u8 ctype) +static int ubl_add_sw_ctype(struct sk_buff *skb, u8 ctype) { u8 *pkt_cfg; @@ -77,12 +77,12 @@ int ubl_add_sw_ctype(struct sk_buff *skb, u8 ctype) * @type: ubl type field * @daddr: not used in ubl * @saddr: not used in ubl - * @len: packet length (<= skb->len) + * @len: packet length (<= skb->len) * */ -int ubl_create_header(struct sk_buff *skb, struct net_device *dev, - unsigned short type, const void *daddr, - const void *saddr, unsigned int len) +static int ubl_create_header(struct sk_buff *skb, struct net_device *dev, + unsigned short type, const void *daddr, + const void *saddr, unsigned int len) { u8 ctype = UB_NOIP_CFG_TYPE; int ret = -UBL_HLEN; @@ -104,10 +104,10 @@ int ubl_create_header(struct sk_buff *skb, struct net_device *dev, return ret; } -EXPORT_SYMBOL(ubl_create_header); /** - * ubl_header_parse_protocol - parse packets protocol before send it to driver. + * ubl_header_parse_protocol - parse packets protocol before sending it to + * driver. * @skb: buffer to alter * * parse packets based on packet data if skb->protocol is ETH_P_ALL or 0. @@ -145,17 +145,17 @@ void ubl_setup(struct net_device *dev) EXPORT_SYMBOL(ubl_setup); /** - * alloc_ubldev_mqs - Allocates and sets up an ub-n device + * alloc_ubldev_mqs - Allocates and sets up a ub-link device * @sizeof_priv: Size of additional driver-private structure to be allocated * for this ubl device * @txqs: The number of TX queues this device has. * @rxqs: The number of RX queues this device has. * * Fill in the fields of the device structure with ubl-generic - * values. Basically does everything except registering the device. + * values. Basically done everything except registering the device. * - * Constructs a new net device, complete with a private data area of - * size (sizeof_priv). A 32-byte (not bit) alignment is enforced for + * Constructs a new net device, completing with a private data area of + * size (sizeof_priv). A 32-byte (not bit) alignment is enforced for * this private data area. */ @@ -179,7 +179,9 @@ EXPORT_SYMBOL(alloc_ubldev_mqs); __be16 ubl_type_trans(struct sk_buff *skb, struct net_device *dev, u8 type) { skb->dev = dev; - ubl_add_sw_ctype(skb, type); + if (ubl_add_sw_ctype(skb, type)) + net_warn_ratelimited("add sw ctype failed\n"); + skb_reset_mac_header(skb); if (type == UB_IPV4_CFG_TYPE || type == UB_IPV6_CFG_TYPE) skb_pull_inline(skb, UBL_HLEN + 1); diff --git a/drivers/net/ub/dev/ubl.h b/drivers/net/ub/dev/ubl.h index 74a3df38abb8..a4018a27f0d7 100644 --- a/drivers/net/ub/dev/ubl.h +++ b/drivers/net/ub/dev/ubl.h @@ -12,8 +12,8 @@ * */ -#ifndef __LINUX_UBL_H -#define __LINUX_UBL_H +#ifndef __UBL_H +#define __UBL_H #include #include @@ -51,8 +51,8 @@ /** * struct ublhdr - ub link header - * @h_cc: cc - * @h_npi: npi + * @h_cc: congestion control + * @h_npi: network partition identifier */ struct ublhdr { __be16 h_cc; @@ -71,14 +71,10 @@ static inline void *ubl_rmv_sw_ctype(struct sk_buff *skb) return pskb_pull(skb, sizeof(u8)); } -int ubl_create_header(struct sk_buff *skb, struct net_device *dev, - unsigned short type, const void *daddr, - const void *saddr, unsigned int len); void ubl_setup(struct net_device *dev); __be16 ubl_type_trans(struct sk_buff *skb, struct net_device *dev, u8 type); struct net_device *alloc_ubldev_mqs(int sizeof_priv, unsigned int txqs, unsigned int rxqs); -int ubl_add_sw_ctype(struct sk_buff *skb, u8 ctype); #define alloc_ubldev_mq(sizeof_priv, count) \ alloc_ubldev_mqs((sizeof_priv), (count), (count)) -- Gitee From 8f2643bd6f133e09962ddeed334f02bd2ada5763 Mon Sep 17 00:00:00 2001 From: Haibin Lu Date: Thu, 22 Aug 2024 14:17:43 +0800 Subject: [PATCH 6/7] UNIC: Fix the issue that RPS cannot hash sw irq to multiple cores. driver inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/IAKMX4 CVE: NA ----------------------------------------------------------- In UBL support mode, the chip supports only the RSS feature that uses dip as key. If the hash calculated by the hardware is transmitted to the SKB, the software interrupt for receiving packets can be hashed to only one core after the kernel RPS feature is enabled. This patch ensures that the hash value calculated by the hardware is not set in the SKB when the driver constructs the SKB in the case of UBL support. This can significantly improve the hashing effect of the rps feature. Fixes: 737ec46e9632 ("UNIC: Adds the process of UNIC driver initializing") Signed-off-by: Haibin Lu --- drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c index 9de28d7da992..95c61f0509df 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c @@ -4685,6 +4685,10 @@ static int hns3_handle_bdinfo(struct hns3_enet_ring *ring, struct sk_buff *skb) ring->tqp_vector->rx_group.total_bytes += len; +#ifdef CONFIG_HNS3_UBL + if (hns3_ubl_supported(hns3_get_handle(netdev))) + return 0; +#endif hns3_set_rx_skb_rss_type(ring, skb, le32_to_cpu(desc->rx.rss_hash), l234info, ol_info); return 0; -- Gitee From e62daf7f8d798f0483b40ce3ebe1f3bd28893f04 Mon Sep 17 00:00:00 2001 From: Guangwei Zhang Date: Thu, 22 Aug 2024 19:46:32 +0800 Subject: [PATCH 7/7] Fix the issue that the debugfs query inconsistency. driver inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/IAKMX4 CVE: NA ---------------------------------------------------------------------- This patch modifies the implementation of debugfs: When the user process stops unexpectedly, not all data of debugfs is read. In this case, the save_buf pointer is not released. When the user process is called next time, save_buf is used to copy the cached data to the user space. As a result, the queried data is inconsistent. To solve this problem, determine whether the function is invoked for the first time based on the value of *ppos. If *ppos is 0, obtain the actual data. Fixes: 97d2f8090892 ("UNIC: Debugfs supports query of ip and guid table's list and specification") Signed-off-by: Guangwei Zhang --- drivers/net/ethernet/hisilicon/hns3/hns3_unic_debugfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_unic_debugfs.c b/drivers/net/ethernet/hisilicon/hns3/hns3_unic_debugfs.c index ff7106a00a31..051e81b87558 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_unic_debugfs.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_unic_debugfs.c @@ -136,8 +136,10 @@ static ssize_t hns3_unic_dbg_read(struct file *filp, char __user *buffer, /* save the buffer addr until the last read operation */ *save_buf = read_buf; + } - /* get data ready for the first time to read */ + /* get data ready for the first time to read */ + if (!*ppos) { ret = hns3_unic_dbg_read_cmd(dbg_data, ub_dbg_cmd[index].cmd, read_buf, ub_dbg_cmd[index].buf_len); -- Gitee