Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'net-hns3-there-are-some-cleanup-for-the-hns3-ethernet-driver'

Hao Lan says:

====================
net: hns3: There are some cleanup for the HNS3 ethernet driver

There are some cleanup for the HNS3 ethernet driver.
====================

Link: https://lore.kernel.org/r/20230621123309.34381-1-lanhao@huawei.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

+85 -72
+1 -2
drivers/net/ethernet/hisilicon/hns3/hnae3.h
··· 647 647 int (*rm_mc_addr)(struct hnae3_handle *handle, 648 648 const unsigned char *addr); 649 649 void (*set_tso_stats)(struct hnae3_handle *handle, int enable); 650 - void (*update_stats)(struct hnae3_handle *handle, 651 - struct net_device_stats *net_stats); 650 + void (*update_stats)(struct hnae3_handle *handle); 652 651 void (*get_stats)(struct hnae3_handle *handle, u64 *data); 653 652 void (*get_mac_stats)(struct hnae3_handle *handle, 654 653 struct hns3_mac_stats *mac_stats);
+1 -2
drivers/net/ethernet/hisilicon/hns3/hns3_common/hclge_comm_rss.c
··· 305 305 return 0; 306 306 } 307 307 308 - int hclge_comm_set_rss_input_tuple(struct hnae3_handle *nic, 309 - struct hclge_comm_hw *hw, bool is_pf, 308 + int hclge_comm_set_rss_input_tuple(struct hclge_comm_hw *hw, 310 309 struct hclge_comm_rss_cfg *rss_cfg) 311 310 { 312 311 struct hclge_comm_rss_input_tuple_cmd *req;
+1 -2
drivers/net/ethernet/hisilicon/hns3/hns3_common/hclge_comm_rss.h
··· 112 112 struct hnae3_ae_dev *ae_dev, 113 113 struct hclge_comm_rss_input_tuple_cmd *req); 114 114 u64 hclge_comm_convert_rss_tuple(u8 tuple_sets); 115 - int hclge_comm_set_rss_input_tuple(struct hnae3_handle *nic, 116 - struct hclge_comm_hw *hw, bool is_pf, 115 + int hclge_comm_set_rss_input_tuple(struct hclge_comm_hw *hw, 117 116 struct hclge_comm_rss_cfg *rss_cfg); 118 117 int hclge_comm_set_rss_indir_table(struct hnae3_ae_dev *ae_dev, 119 118 struct hclge_comm_hw *hw, const u16 *indir);
+27 -11
drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
··· 438 438 const struct hns3_dbg_item *items, 439 439 const char **result, u16 size) 440 440 { 441 + #define HNS3_DBG_LINE_END_LEN 2 441 442 char *pos = content; 443 + u16 item_len; 442 444 u16 i; 443 445 444 - memset(content, ' ', len); 445 - for (i = 0; i < size; i++) { 446 - if (result) 447 - strncpy(pos, result[i], strlen(result[i])); 448 - else 449 - strncpy(pos, items[i].name, strlen(items[i].name)); 450 - 451 - pos += strlen(items[i].name) + items[i].interval; 446 + if (!len) { 447 + return; 448 + } else if (len <= HNS3_DBG_LINE_END_LEN) { 449 + *pos++ = '\0'; 450 + return; 452 451 } 453 452 453 + memset(content, ' ', len); 454 + len -= HNS3_DBG_LINE_END_LEN; 455 + 456 + for (i = 0; i < size; i++) { 457 + item_len = strlen(items[i].name) + items[i].interval; 458 + if (len < item_len) 459 + break; 460 + 461 + if (result) { 462 + if (item_len < strlen(result[i])) 463 + break; 464 + strscpy(pos, result[i], strlen(result[i])); 465 + } else { 466 + strscpy(pos, items[i].name, strlen(items[i].name)); 467 + } 468 + pos += item_len; 469 + len -= item_len; 470 + } 454 471 *pos++ = '\n'; 455 472 *pos++ = '\0'; 456 473 } ··· 958 941 { "MSS_HW_CSUM", 0 }, 959 942 }; 960 943 961 - static void hns3_dump_tx_bd_info(struct hns3_nic_priv *priv, 962 - struct hns3_desc *desc, char **result, int idx) 944 + static void hns3_dump_tx_bd_info(struct hns3_desc *desc, char **result, int idx) 963 945 { 964 946 unsigned int j = 0; 965 947 ··· 1007 991 for (i = 0; i < ring->desc_num; i++) { 1008 992 desc = &ring->desc[i]; 1009 993 1010 - hns3_dump_tx_bd_info(priv, desc, result, i); 994 + hns3_dump_tx_bd_info(desc, result, i); 1011 995 hns3_dbg_fill_content(content, sizeof(content), 1012 996 tx_bd_info_items, (const char **)result, 1013 997 ARRAY_SIZE(tx_bd_info_items));
+1 -1
drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
··· 2538 2538 if (test_bit(HNS3_NIC_STATE_DOWN, &priv->state)) 2539 2539 return; 2540 2540 2541 - handle->ae_algo->ops->update_stats(handle, &netdev->stats); 2541 + handle->ae_algo->ops->update_stats(handle); 2542 2542 2543 2543 memset(&ring_total_stats, 0, sizeof(ring_total_stats)); 2544 2544 for (idx = 0; idx < queue_num; idx++) {
+3 -4
drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
··· 228 228 } 229 229 230 230 static void hns3_lb_clear_tx_ring(struct hns3_nic_priv *priv, u32 start_ringid, 231 - u32 end_ringid, u32 budget) 231 + u32 end_ringid) 232 232 { 233 233 u32 i; 234 234 ··· 295 295 296 296 out: 297 297 hns3_lb_clear_tx_ring(priv, HNS3_NIC_LB_TEST_RING_ID, 298 - HNS3_NIC_LB_TEST_RING_ID, 299 - HNS3_NIC_LB_TEST_PKT_NUM); 298 + HNS3_NIC_LB_TEST_RING_ID); 300 299 301 300 kfree_skb(skb); 302 301 return ret_val; ··· 617 618 return; 618 619 } 619 620 620 - h->ae_algo->ops->update_stats(h, &netdev->stats); 621 + h->ae_algo->ops->update_stats(h); 621 622 622 623 /* get per-queue stats */ 623 624 p = hns3_get_stats_tqps(h, p);
+24 -5
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
··· 88 88 const struct hclge_dbg_item *items, 89 89 const char **result, u16 size) 90 90 { 91 + #define HCLGE_DBG_LINE_END_LEN 2 91 92 char *pos = content; 93 + u16 item_len; 92 94 u16 i; 93 95 96 + if (!len) { 97 + return; 98 + } else if (len <= HCLGE_DBG_LINE_END_LEN) { 99 + *pos++ = '\0'; 100 + return; 101 + } 102 + 94 103 memset(content, ' ', len); 104 + len -= HCLGE_DBG_LINE_END_LEN; 105 + 95 106 for (i = 0; i < size; i++) { 96 - if (result) 97 - strncpy(pos, result[i], strlen(result[i])); 98 - else 99 - strncpy(pos, items[i].name, strlen(items[i].name)); 100 - pos += strlen(items[i].name) + items[i].interval; 107 + item_len = strlen(items[i].name) + items[i].interval; 108 + if (len < item_len) 109 + break; 110 + 111 + if (result) { 112 + if (item_len < strlen(result[i])) 113 + break; 114 + strscpy(pos, result[i], strlen(result[i])); 115 + } else { 116 + strscpy(pos, items[i].name, strlen(items[i].name)); 117 + } 118 + pos += item_len; 119 + len -= item_len; 101 120 } 102 121 *pos++ = '\n'; 103 122 *pos++ = '\0';
+19 -28
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
··· 689 689 "Update MAC stats fail, status = %d.\n", status); 690 690 } 691 691 692 - static void hclge_update_stats(struct hnae3_handle *handle, 693 - struct net_device_stats *net_stats) 692 + static void hclge_update_stats(struct hnae3_handle *handle) 694 693 { 695 694 struct hclge_vport *vport = hclge_get_vport(handle); 696 695 struct hclge_dev *hdev = vport->back; ··· 823 824 struct hclge_vport *vport = hclge_get_vport(handle); 824 825 struct hclge_dev *hdev = vport->back; 825 826 826 - hclge_update_stats(handle, NULL); 827 + hclge_update_stats(handle); 827 828 828 829 mac_stats->tx_pause_cnt = hdev->mac_stats.mac_tx_mac_pause_num; 829 830 mac_stats->rx_pause_cnt = hdev->mac_stats.mac_rx_mac_pause_num; ··· 4964 4965 if (ret) 4965 4966 return ret; 4966 4967 4967 - ret = hclge_comm_set_rss_input_tuple(&hdev->vport[0].nic, 4968 - &hdev->hw.hw, true, 4969 - &hdev->rss_cfg); 4968 + ret = hclge_comm_set_rss_input_tuple(&hdev->hw.hw, &hdev->rss_cfg); 4970 4969 if (ret) 4971 4970 return ret; 4972 4971 ··· 6240 6243 return hclge_fd_check_ext_tuple(hdev, fs, unused_tuple); 6241 6244 } 6242 6245 6243 - static void hclge_fd_get_tcpip4_tuple(struct hclge_dev *hdev, 6244 - struct ethtool_rx_flow_spec *fs, 6246 + static void hclge_fd_get_tcpip4_tuple(struct ethtool_rx_flow_spec *fs, 6245 6247 struct hclge_fd_rule *rule, u8 ip_proto) 6246 6248 { 6247 6249 rule->tuples.src_ip[IPV4_INDEX] = ··· 6269 6273 rule->tuples_mask.ip_proto = 0xFF; 6270 6274 } 6271 6275 6272 - static void hclge_fd_get_ip4_tuple(struct hclge_dev *hdev, 6273 - struct ethtool_rx_flow_spec *fs, 6276 + static void hclge_fd_get_ip4_tuple(struct ethtool_rx_flow_spec *fs, 6274 6277 struct hclge_fd_rule *rule) 6275 6278 { 6276 6279 rule->tuples.src_ip[IPV4_INDEX] = ··· 6292 6297 rule->tuples_mask.ether_proto = 0xFFFF; 6293 6298 } 6294 6299 6295 - static void hclge_fd_get_tcpip6_tuple(struct hclge_dev *hdev, 6296 - struct ethtool_rx_flow_spec *fs, 6300 + static void hclge_fd_get_tcpip6_tuple(struct ethtool_rx_flow_spec *fs, 6297 6301 struct hclge_fd_rule *rule, u8 ip_proto) 6298 6302 { 6299 6303 be32_to_cpu_array(rule->tuples.src_ip, fs->h_u.tcp_ip6_spec.ip6src, ··· 6321 6327 rule->tuples_mask.ip_proto = 0xFF; 6322 6328 } 6323 6329 6324 - static void hclge_fd_get_ip6_tuple(struct hclge_dev *hdev, 6325 - struct ethtool_rx_flow_spec *fs, 6330 + static void hclge_fd_get_ip6_tuple(struct ethtool_rx_flow_spec *fs, 6326 6331 struct hclge_fd_rule *rule) 6327 6332 { 6328 6333 be32_to_cpu_array(rule->tuples.src_ip, fs->h_u.usr_ip6_spec.ip6src, ··· 6344 6351 rule->tuples_mask.ether_proto = 0xFFFF; 6345 6352 } 6346 6353 6347 - static void hclge_fd_get_ether_tuple(struct hclge_dev *hdev, 6348 - struct ethtool_rx_flow_spec *fs, 6354 + static void hclge_fd_get_ether_tuple(struct ethtool_rx_flow_spec *fs, 6349 6355 struct hclge_fd_rule *rule) 6350 6356 { 6351 6357 ether_addr_copy(rule->tuples.src_mac, fs->h_u.ether_spec.h_source); ··· 6380 6388 rule->ep.user_def = *info; 6381 6389 } 6382 6390 6383 - static int hclge_fd_get_tuple(struct hclge_dev *hdev, 6384 - struct ethtool_rx_flow_spec *fs, 6391 + static int hclge_fd_get_tuple(struct ethtool_rx_flow_spec *fs, 6385 6392 struct hclge_fd_rule *rule, 6386 6393 struct hclge_fd_user_def_info *info) 6387 6394 { ··· 6388 6397 6389 6398 switch (flow_type) { 6390 6399 case SCTP_V4_FLOW: 6391 - hclge_fd_get_tcpip4_tuple(hdev, fs, rule, IPPROTO_SCTP); 6400 + hclge_fd_get_tcpip4_tuple(fs, rule, IPPROTO_SCTP); 6392 6401 break; 6393 6402 case TCP_V4_FLOW: 6394 - hclge_fd_get_tcpip4_tuple(hdev, fs, rule, IPPROTO_TCP); 6403 + hclge_fd_get_tcpip4_tuple(fs, rule, IPPROTO_TCP); 6395 6404 break; 6396 6405 case UDP_V4_FLOW: 6397 - hclge_fd_get_tcpip4_tuple(hdev, fs, rule, IPPROTO_UDP); 6406 + hclge_fd_get_tcpip4_tuple(fs, rule, IPPROTO_UDP); 6398 6407 break; 6399 6408 case IP_USER_FLOW: 6400 - hclge_fd_get_ip4_tuple(hdev, fs, rule); 6409 + hclge_fd_get_ip4_tuple(fs, rule); 6401 6410 break; 6402 6411 case SCTP_V6_FLOW: 6403 - hclge_fd_get_tcpip6_tuple(hdev, fs, rule, IPPROTO_SCTP); 6412 + hclge_fd_get_tcpip6_tuple(fs, rule, IPPROTO_SCTP); 6404 6413 break; 6405 6414 case TCP_V6_FLOW: 6406 - hclge_fd_get_tcpip6_tuple(hdev, fs, rule, IPPROTO_TCP); 6415 + hclge_fd_get_tcpip6_tuple(fs, rule, IPPROTO_TCP); 6407 6416 break; 6408 6417 case UDP_V6_FLOW: 6409 - hclge_fd_get_tcpip6_tuple(hdev, fs, rule, IPPROTO_UDP); 6418 + hclge_fd_get_tcpip6_tuple(fs, rule, IPPROTO_UDP); 6410 6419 break; 6411 6420 case IPV6_USER_FLOW: 6412 - hclge_fd_get_ip6_tuple(hdev, fs, rule); 6421 + hclge_fd_get_ip6_tuple(fs, rule); 6413 6422 break; 6414 6423 case ETHER_FLOW: 6415 - hclge_fd_get_ether_tuple(hdev, fs, rule); 6424 + hclge_fd_get_ether_tuple(fs, rule); 6416 6425 break; 6417 6426 default: 6418 6427 return -EOPNOTSUPP; ··· 6569 6578 if (!rule) 6570 6579 return -ENOMEM; 6571 6580 6572 - ret = hclge_fd_get_tuple(hdev, fs, rule, &info); 6581 + ret = hclge_fd_get_tuple(fs, rule, &info); 6573 6582 if (ret) { 6574 6583 kfree(rule); 6575 6584 return ret;
+3 -8
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
··· 835 835 * Then for input key(k) and mask(v), we can calculate the value by 836 836 * the formulae: 837 837 * x = (~k) & v 838 - * y = (k ^ ~v) & k 838 + * y = k & v 839 839 */ 840 - #define calc_x(x, k, v) (x = ~(k) & (v)) 841 - #define calc_y(y, k, v) \ 842 - do { \ 843 - const typeof(k) _k_ = (k); \ 844 - const typeof(v) _v_ = (v); \ 845 - (y) = (_k_ ^ ~_v_) & (_k_); \ 846 - } while (0) 840 + #define calc_x(x, k, v) ((x) = ~(k) & (v)) 841 + #define calc_y(y, k, v) ((y) = (k) & (v)) 847 842 848 843 #define HCLGE_MAC_STATS_FIELD_OFF(f) (offsetof(struct hclge_mac_stats, f)) 849 844 #define HCLGE_STATS_READ(p, offset) (*(u64 *)((u8 *)(p) + (offset)))
+5 -9
drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
··· 121 121 return container_of(handle, struct hclgevf_dev, nic); 122 122 } 123 123 124 - static void hclgevf_update_stats(struct hnae3_handle *handle, 125 - struct net_device_stats *net_stats) 124 + static void hclgevf_update_stats(struct hnae3_handle *handle) 126 125 { 127 126 struct hclgevf_dev *hdev = hclgevf_ae_get_hdev(handle); 128 127 int status; ··· 1644 1645 hclgevf_reset_err_handle(hdev); 1645 1646 } 1646 1647 1647 - static enum hnae3_reset_type hclgevf_get_reset_level(struct hclgevf_dev *hdev, 1648 - unsigned long *addr) 1648 + static enum hnae3_reset_type hclgevf_get_reset_level(unsigned long *addr) 1649 1649 { 1650 1650 enum hnae3_reset_type rst_level = HNAE3_NONE_RESET; 1651 1651 ··· 1683 1685 1684 1686 if (hdev->default_reset_request) 1685 1687 hdev->reset_level = 1686 - hclgevf_get_reset_level(hdev, 1687 - &hdev->default_reset_request); 1688 + hclgevf_get_reset_level(&hdev->default_reset_request); 1688 1689 else 1689 1690 hdev->reset_level = HNAE3_VF_FUNC_RESET; 1690 1691 ··· 1825 1828 1826 1829 hdev->last_reset_time = jiffies; 1827 1830 hdev->reset_type = 1828 - hclgevf_get_reset_level(hdev, &hdev->reset_pending); 1831 + hclgevf_get_reset_level(&hdev->reset_pending); 1829 1832 if (hdev->reset_type != HNAE3_NONE_RESET) 1830 1833 hclgevf_reset(hdev); 1831 1834 } else if (test_and_clear_bit(HCLGEVF_RESET_REQUESTED, ··· 2157 2160 if (ret) 2158 2161 return ret; 2159 2162 2160 - ret = hclge_comm_set_rss_input_tuple(&hdev->nic, &hdev->hw.hw, 2161 - false, rss_cfg); 2163 + ret = hclge_comm_set_rss_input_tuple(&hdev->hw.hw, rss_cfg); 2162 2164 if (ret) 2163 2165 return ret; 2164 2166 }