Skip to content

Commit 7a4ea5d

Browse files
nehebkuba-moo
authored andcommitted
net: hisilicon: hns: use ethtool string helpers
The latter is the preferred way to copy ethtool strings. Avoids manually incrementing the pointer. Cleans up the code quite well. Signed-off-by: Rosen Penev <rosenp@gmail.com> Reviewed-by: Jijie Shao <shaojijie@huawei.com> Link: https://patch.msgid.link/20241101220023.290926-1-rosenp@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 7d1c2d5 commit 7a4ea5d

File tree

13 files changed

+122
-157
lines changed

13 files changed

+122
-157
lines changed

drivers/net/ethernet/hisilicon/hns/hnae.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ struct hnae_ae_ops {
512512
struct net_device_stats *net_stats);
513513
void (*get_stats)(struct hnae_handle *handle, u64 *data);
514514
void (*get_strings)(struct hnae_handle *handle,
515-
u32 stringset, u8 *data);
515+
u32 stringset, u8 **data);
516516
int (*get_sset_count)(struct hnae_handle *handle, int stringset);
517517
void (*update_led_status)(struct hnae_handle *handle);
518518
int (*set_led_id)(struct hnae_handle *handle,

drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -730,15 +730,14 @@ static void hns_ae_get_stats(struct hnae_handle *handle, u64 *data)
730730
hns_dsaf_get_stats(vf_cb->dsaf_dev, p, vf_cb->port_index);
731731
}
732732

733-
static void hns_ae_get_strings(struct hnae_handle *handle,
734-
u32 stringset, u8 *data)
733+
static void hns_ae_get_strings(struct hnae_handle *handle, u32 stringset,
734+
u8 **data)
735735
{
736736
int port;
737737
int idx;
738738
struct hns_mac_cb *mac_cb;
739739
struct hns_ppe_cb *ppe_cb;
740740
struct dsaf_device *dsaf_dev = hns_ae_get_dsaf_dev(handle->dev);
741-
u8 *p = data;
742741
struct hnae_vf_cb *vf_cb;
743742

744743
assert(handle);
@@ -748,19 +747,14 @@ static void hns_ae_get_strings(struct hnae_handle *handle,
748747
mac_cb = hns_get_mac_cb(handle);
749748
ppe_cb = hns_get_ppe_cb(handle);
750749

751-
for (idx = 0; idx < handle->q_num; idx++) {
752-
hns_rcb_get_strings(stringset, p, idx);
753-
p += ETH_GSTRING_LEN * hns_rcb_get_ring_sset_count(stringset);
754-
}
755-
756-
hns_ppe_get_strings(ppe_cb, stringset, p);
757-
p += ETH_GSTRING_LEN * hns_ppe_get_sset_count(stringset);
750+
for (idx = 0; idx < handle->q_num; idx++)
751+
hns_rcb_get_strings(stringset, data, idx);
758752

759-
hns_mac_get_strings(mac_cb, stringset, p);
760-
p += ETH_GSTRING_LEN * hns_mac_get_sset_count(mac_cb, stringset);
753+
hns_ppe_get_strings(ppe_cb, stringset, data);
754+
hns_mac_get_strings(mac_cb, stringset, data);
761755

762756
if (mac_cb->mac_type == HNAE_PORT_SERVICE)
763-
hns_dsaf_get_strings(stringset, p, port, dsaf_dev);
757+
hns_dsaf_get_strings(stringset, data, port, dsaf_dev);
764758
}
765759

766760
static int hns_ae_get_sset_count(struct hnae_handle *handle, int stringset)

drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -669,16 +669,15 @@ static void hns_gmac_get_stats(void *mac_drv, u64 *data)
669669
}
670670
}
671671

672-
static void hns_gmac_get_strings(u32 stringset, u8 *data)
672+
static void hns_gmac_get_strings(u32 stringset, u8 **data)
673673
{
674-
u8 *buff = data;
675674
u32 i;
676675

677676
if (stringset != ETH_SS_STATS)
678677
return;
679678

680679
for (i = 0; i < ARRAY_SIZE(g_gmac_stats_string); i++)
681-
ethtool_puts(&buff, g_gmac_stats_string[i].desc);
680+
ethtool_puts(data, g_gmac_stats_string[i].desc);
682681
}
683682

684683
static int hns_gmac_get_sset_count(int stringset)

drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,8 +1190,7 @@ void hns_mac_get_stats(struct hns_mac_cb *mac_cb, u64 *data)
11901190
mac_ctrl_drv->get_ethtool_stats(mac_ctrl_drv, data);
11911191
}
11921192

1193-
void hns_mac_get_strings(struct hns_mac_cb *mac_cb,
1194-
int stringset, u8 *data)
1193+
void hns_mac_get_strings(struct hns_mac_cb *mac_cb, int stringset, u8 **data)
11951194
{
11961195
struct mac_driver *mac_ctrl_drv = hns_mac_get_drv(mac_cb);
11971196

drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ struct mac_driver {
378378
void (*get_regs)(void *mac_drv, void *data);
379379
int (*get_regs_count)(void);
380380
/* get strings name for ethtool statistic */
381-
void (*get_strings)(u32 stringset, u8 *data);
381+
void (*get_strings)(u32 stringset, u8 **data);
382382
/* get the number of strings*/
383383
int (*get_sset_count)(int stringset);
384384

@@ -445,7 +445,7 @@ int hns_mac_config_mac_loopback(struct hns_mac_cb *mac_cb,
445445
enum hnae_loop loop, int en);
446446
void hns_mac_update_stats(struct hns_mac_cb *mac_cb);
447447
void hns_mac_get_stats(struct hns_mac_cb *mac_cb, u64 *data);
448-
void hns_mac_get_strings(struct hns_mac_cb *mac_cb, int stringset, u8 *data);
448+
void hns_mac_get_strings(struct hns_mac_cb *mac_cb, int stringset, u8 **data);
449449
int hns_mac_get_sset_count(struct hns_mac_cb *mac_cb, int stringset);
450450
void hns_mac_get_regs(struct hns_mac_cb *mac_cb, void *data);
451451
int hns_mac_get_regs_count(struct hns_mac_cb *mac_cb);

drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c

Lines changed: 24 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2590,55 +2590,34 @@ void hns_dsaf_get_regs(struct dsaf_device *ddev, u32 port, void *data)
25902590
p[i] = 0xdddddddd;
25912591
}
25922592

2593-
static char *hns_dsaf_get_node_stats_strings(char *data, int node,
2594-
struct dsaf_device *dsaf_dev)
2593+
static void hns_dsaf_get_node_stats_strings(u8 **data, int node,
2594+
struct dsaf_device *dsaf_dev)
25952595
{
2596-
char *buff = data;
2597-
int i;
25982596
bool is_ver1 = AE_IS_VER1(dsaf_dev->dsaf_ver);
2597+
int i;
25992598

2600-
snprintf(buff, ETH_GSTRING_LEN, "innod%d_pad_drop_pkts", node);
2601-
buff += ETH_GSTRING_LEN;
2602-
snprintf(buff, ETH_GSTRING_LEN, "innod%d_manage_pkts", node);
2603-
buff += ETH_GSTRING_LEN;
2604-
snprintf(buff, ETH_GSTRING_LEN, "innod%d_rx_pkts", node);
2605-
buff += ETH_GSTRING_LEN;
2606-
snprintf(buff, ETH_GSTRING_LEN, "innod%d_rx_pkt_id", node);
2607-
buff += ETH_GSTRING_LEN;
2608-
snprintf(buff, ETH_GSTRING_LEN, "innod%d_rx_pause_frame", node);
2609-
buff += ETH_GSTRING_LEN;
2610-
snprintf(buff, ETH_GSTRING_LEN, "innod%d_release_buf_num", node);
2611-
buff += ETH_GSTRING_LEN;
2612-
snprintf(buff, ETH_GSTRING_LEN, "innod%d_sbm_drop_pkts", node);
2613-
buff += ETH_GSTRING_LEN;
2614-
snprintf(buff, ETH_GSTRING_LEN, "innod%d_crc_false_pkts", node);
2615-
buff += ETH_GSTRING_LEN;
2616-
snprintf(buff, ETH_GSTRING_LEN, "innod%d_bp_drop_pkts", node);
2617-
buff += ETH_GSTRING_LEN;
2618-
snprintf(buff, ETH_GSTRING_LEN, "innod%d_lookup_rslt_drop_pkts", node);
2619-
buff += ETH_GSTRING_LEN;
2620-
snprintf(buff, ETH_GSTRING_LEN, "innod%d_local_rslt_fail_pkts", node);
2621-
buff += ETH_GSTRING_LEN;
2622-
snprintf(buff, ETH_GSTRING_LEN, "innod%d_vlan_drop_pkts", node);
2623-
buff += ETH_GSTRING_LEN;
2624-
snprintf(buff, ETH_GSTRING_LEN, "innod%d_stp_drop_pkts", node);
2625-
buff += ETH_GSTRING_LEN;
2599+
ethtool_sprintf(data, "innod%d_pad_drop_pkts", node);
2600+
ethtool_sprintf(data, "innod%d_manage_pkts", node);
2601+
ethtool_sprintf(data, "innod%d_rx_pkts", node);
2602+
ethtool_sprintf(data, "innod%d_rx_pkt_id", node);
2603+
ethtool_sprintf(data, "innod%d_rx_pause_frame", node);
2604+
ethtool_sprintf(data, "innod%d_release_buf_num", node);
2605+
ethtool_sprintf(data, "innod%d_sbm_drop_pkts", node);
2606+
ethtool_sprintf(data, "innod%d_crc_false_pkts", node);
2607+
ethtool_sprintf(data, "innod%d_bp_drop_pkts", node);
2608+
ethtool_sprintf(data, "innod%d_lookup_rslt_drop_pkts", node);
2609+
ethtool_sprintf(data, "innod%d_local_rslt_fail_pkts", node);
2610+
ethtool_sprintf(data, "innod%d_vlan_drop_pkts", node);
2611+
ethtool_sprintf(data, "innod%d_stp_drop_pkts", node);
26262612
if (node < DSAF_SERVICE_NW_NUM && !is_ver1) {
26272613
for (i = 0; i < DSAF_PRIO_NR; i++) {
2628-
snprintf(buff + 0 * ETH_GSTRING_LEN * DSAF_PRIO_NR,
2629-
ETH_GSTRING_LEN, "inod%d_pfc_prio%d_pkts",
2630-
node, i);
2631-
snprintf(buff + 1 * ETH_GSTRING_LEN * DSAF_PRIO_NR,
2632-
ETH_GSTRING_LEN, "onod%d_pfc_prio%d_pkts",
2633-
node, i);
2634-
buff += ETH_GSTRING_LEN;
2614+
ethtool_sprintf(data, "inod%d_pfc_prio%d_pkts", node,
2615+
i);
2616+
ethtool_sprintf(data, "onod%d_pfc_prio%d_pkts", node,
2617+
i);
26352618
}
2636-
buff += 1 * DSAF_PRIO_NR * ETH_GSTRING_LEN;
26372619
}
2638-
snprintf(buff, ETH_GSTRING_LEN, "onnod%d_tx_pkts", node);
2639-
buff += ETH_GSTRING_LEN;
2640-
2641-
return buff;
2620+
ethtool_sprintf(data, "onnod%d_tx_pkts", node);
26422621
}
26432622

26442623
static u64 *hns_dsaf_get_node_stats(struct dsaf_device *ddev, u64 *data,
@@ -2720,21 +2699,20 @@ int hns_dsaf_get_sset_count(struct dsaf_device *dsaf_dev, int stringset)
27202699
*@port:port index
27212700
*@dsaf_dev: dsaf device
27222701
*/
2723-
void hns_dsaf_get_strings(int stringset, u8 *data, int port,
2702+
void hns_dsaf_get_strings(int stringset, u8 **data, int port,
27242703
struct dsaf_device *dsaf_dev)
27252704
{
2726-
char *buff = (char *)data;
27272705
int node = port;
27282706

27292707
if (stringset != ETH_SS_STATS)
27302708
return;
27312709

27322710
/* for ge/xge node info */
2733-
buff = hns_dsaf_get_node_stats_strings(buff, node, dsaf_dev);
2711+
hns_dsaf_get_node_stats_strings(data, node, dsaf_dev);
27342712

27352713
/* for ppe node info */
27362714
node = port + DSAF_PPE_INODE_BASE;
2737-
(void)hns_dsaf_get_node_stats_strings(buff, node, dsaf_dev);
2715+
hns_dsaf_get_node_stats_strings(data, node, dsaf_dev);
27382716
}
27392717

27402718
/**

drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ void hns_dsaf_update_stats(struct dsaf_device *dsaf_dev, u32 inode_num);
442442

443443
int hns_dsaf_get_sset_count(struct dsaf_device *dsaf_dev, int stringset);
444444
void hns_dsaf_get_stats(struct dsaf_device *ddev, u64 *data, int port);
445-
void hns_dsaf_get_strings(int stringset, u8 *data, int port,
445+
void hns_dsaf_get_strings(int stringset, u8 **data, int port,
446446
struct dsaf_device *dsaf_dev);
447447

448448
void hns_dsaf_get_regs(struct dsaf_device *ddev, u32 port, void *data);

drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -457,24 +457,23 @@ int hns_ppe_get_regs_count(void)
457457
* @stringset: string set type
458458
* @data: output string
459459
*/
460-
void hns_ppe_get_strings(struct hns_ppe_cb *ppe_cb, int stringset, u8 *data)
460+
void hns_ppe_get_strings(struct hns_ppe_cb *ppe_cb, int stringset, u8 **data)
461461
{
462462
int index = ppe_cb->index;
463-
u8 *buff = data;
464-
465-
ethtool_sprintf(&buff, "ppe%d_rx_sw_pkt", index);
466-
ethtool_sprintf(&buff, "ppe%d_rx_pkt_ok", index);
467-
ethtool_sprintf(&buff, "ppe%d_rx_drop_pkt_no_bd", index);
468-
ethtool_sprintf(&buff, "ppe%d_rx_alloc_buf_fail", index);
469-
ethtool_sprintf(&buff, "ppe%d_rx_alloc_buf_wait", index);
470-
ethtool_sprintf(&buff, "ppe%d_rx_pkt_drop_no_buf", index);
471-
ethtool_sprintf(&buff, "ppe%d_rx_pkt_err_fifo_full", index);
472-
473-
ethtool_sprintf(&buff, "ppe%d_tx_bd", index);
474-
ethtool_sprintf(&buff, "ppe%d_tx_pkt", index);
475-
ethtool_sprintf(&buff, "ppe%d_tx_pkt_ok", index);
476-
ethtool_sprintf(&buff, "ppe%d_tx_pkt_err_fifo_empty", index);
477-
ethtool_sprintf(&buff, "ppe%d_tx_pkt_err_csum_fail", index);
463+
464+
ethtool_sprintf(data, "ppe%d_rx_sw_pkt", index);
465+
ethtool_sprintf(data, "ppe%d_rx_pkt_ok", index);
466+
ethtool_sprintf(data, "ppe%d_rx_drop_pkt_no_bd", index);
467+
ethtool_sprintf(data, "ppe%d_rx_alloc_buf_fail", index);
468+
ethtool_sprintf(data, "ppe%d_rx_alloc_buf_wait", index);
469+
ethtool_sprintf(data, "ppe%d_rx_pkt_drop_no_buf", index);
470+
ethtool_sprintf(data, "ppe%d_rx_pkt_err_fifo_full", index);
471+
472+
ethtool_sprintf(data, "ppe%d_tx_bd", index);
473+
ethtool_sprintf(data, "ppe%d_tx_pkt", index);
474+
ethtool_sprintf(data, "ppe%d_tx_pkt_ok", index);
475+
ethtool_sprintf(data, "ppe%d_tx_pkt_err_fifo_empty", index);
476+
ethtool_sprintf(data, "ppe%d_tx_pkt_err_csum_fail", index);
478477
}
479478

480479
void hns_ppe_get_stats(struct hns_ppe_cb *ppe_cb, u64 *data)

drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ int hns_ppe_get_sset_count(int stringset);
109109
int hns_ppe_get_regs_count(void);
110110
void hns_ppe_get_regs(struct hns_ppe_cb *ppe_cb, void *data);
111111

112-
void hns_ppe_get_strings(struct hns_ppe_cb *ppe_cb, int stringset, u8 *data);
112+
void hns_ppe_get_strings(struct hns_ppe_cb *ppe_cb, int stringset, u8 **data);
113113
void hns_ppe_get_stats(struct hns_ppe_cb *ppe_cb, u64 *data);
114114
void hns_ppe_set_tso_enable(struct hns_ppe_cb *ppe_cb, u32 value);
115115
void hns_ppe_set_rss_key(struct hns_ppe_cb *ppe_cb,

drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -923,44 +923,42 @@ int hns_rcb_get_ring_regs_count(void)
923923
*@data:strings name value
924924
*@index:queue index
925925
*/
926-
void hns_rcb_get_strings(int stringset, u8 *data, int index)
926+
void hns_rcb_get_strings(int stringset, u8 **data, int index)
927927
{
928-
u8 *buff = data;
929-
930928
if (stringset != ETH_SS_STATS)
931929
return;
932930

933-
ethtool_sprintf(&buff, "tx_ring%d_rcb_pkt_num", index);
934-
ethtool_sprintf(&buff, "tx_ring%d_ppe_tx_pkt_num", index);
935-
ethtool_sprintf(&buff, "tx_ring%d_ppe_drop_pkt_num", index);
936-
ethtool_sprintf(&buff, "tx_ring%d_fbd_num", index);
937-
938-
ethtool_sprintf(&buff, "tx_ring%d_pkt_num", index);
939-
ethtool_sprintf(&buff, "tx_ring%d_bytes", index);
940-
ethtool_sprintf(&buff, "tx_ring%d_err_cnt", index);
941-
ethtool_sprintf(&buff, "tx_ring%d_io_err", index);
942-
ethtool_sprintf(&buff, "tx_ring%d_sw_err", index);
943-
ethtool_sprintf(&buff, "tx_ring%d_seg_pkt", index);
944-
ethtool_sprintf(&buff, "tx_ring%d_restart_queue", index);
945-
ethtool_sprintf(&buff, "tx_ring%d_tx_busy", index);
946-
947-
ethtool_sprintf(&buff, "rx_ring%d_rcb_pkt_num", index);
948-
ethtool_sprintf(&buff, "rx_ring%d_ppe_pkt_num", index);
949-
ethtool_sprintf(&buff, "rx_ring%d_ppe_drop_pkt_num", index);
950-
ethtool_sprintf(&buff, "rx_ring%d_fbd_num", index);
951-
952-
ethtool_sprintf(&buff, "rx_ring%d_pkt_num", index);
953-
ethtool_sprintf(&buff, "rx_ring%d_bytes", index);
954-
ethtool_sprintf(&buff, "rx_ring%d_err_cnt", index);
955-
ethtool_sprintf(&buff, "rx_ring%d_io_err", index);
956-
ethtool_sprintf(&buff, "rx_ring%d_sw_err", index);
957-
ethtool_sprintf(&buff, "rx_ring%d_seg_pkt", index);
958-
ethtool_sprintf(&buff, "rx_ring%d_reuse_pg", index);
959-
ethtool_sprintf(&buff, "rx_ring%d_len_err", index);
960-
ethtool_sprintf(&buff, "rx_ring%d_non_vld_desc_err", index);
961-
ethtool_sprintf(&buff, "rx_ring%d_bd_num_err", index);
962-
ethtool_sprintf(&buff, "rx_ring%d_l2_err", index);
963-
ethtool_sprintf(&buff, "rx_ring%d_l3l4csum_err", index);
931+
ethtool_sprintf(data, "tx_ring%d_rcb_pkt_num", index);
932+
ethtool_sprintf(data, "tx_ring%d_ppe_tx_pkt_num", index);
933+
ethtool_sprintf(data, "tx_ring%d_ppe_drop_pkt_num", index);
934+
ethtool_sprintf(data, "tx_ring%d_fbd_num", index);
935+
936+
ethtool_sprintf(data, "tx_ring%d_pkt_num", index);
937+
ethtool_sprintf(data, "tx_ring%d_bytes", index);
938+
ethtool_sprintf(data, "tx_ring%d_err_cnt", index);
939+
ethtool_sprintf(data, "tx_ring%d_io_err", index);
940+
ethtool_sprintf(data, "tx_ring%d_sw_err", index);
941+
ethtool_sprintf(data, "tx_ring%d_seg_pkt", index);
942+
ethtool_sprintf(data, "tx_ring%d_restart_queue", index);
943+
ethtool_sprintf(data, "tx_ring%d_tx_busy", index);
944+
945+
ethtool_sprintf(data, "rx_ring%d_rcb_pkt_num", index);
946+
ethtool_sprintf(data, "rx_ring%d_ppe_pkt_num", index);
947+
ethtool_sprintf(data, "rx_ring%d_ppe_drop_pkt_num", index);
948+
ethtool_sprintf(data, "rx_ring%d_fbd_num", index);
949+
950+
ethtool_sprintf(data, "rx_ring%d_pkt_num", index);
951+
ethtool_sprintf(data, "rx_ring%d_bytes", index);
952+
ethtool_sprintf(data, "rx_ring%d_err_cnt", index);
953+
ethtool_sprintf(data, "rx_ring%d_io_err", index);
954+
ethtool_sprintf(data, "rx_ring%d_sw_err", index);
955+
ethtool_sprintf(data, "rx_ring%d_seg_pkt", index);
956+
ethtool_sprintf(data, "rx_ring%d_reuse_pg", index);
957+
ethtool_sprintf(data, "rx_ring%d_len_err", index);
958+
ethtool_sprintf(data, "rx_ring%d_non_vld_desc_err", index);
959+
ethtool_sprintf(data, "rx_ring%d_bd_num_err", index);
960+
ethtool_sprintf(data, "rx_ring%d_l2_err", index);
961+
ethtool_sprintf(data, "rx_ring%d_l3l4csum_err", index);
964962
}
965963

966964
void hns_rcb_get_common_regs(struct rcb_common_cb *rcb_com, void *data)

0 commit comments

Comments
 (0)