From nobody Sun Nov 24 14:35:45 2024 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF7BE1F7569; Mon, 4 Nov 2024 20:48:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730753308; cv=none; b=jY6EeG6ADg7nvYkoER+UQLiX7xpZdvxb2P54ta0FBcWpHxHQg4Cr3DJ1VL95NILNS/7Detyp2ZN1uToKxLu6yAUKH+AUGehGy4rXqf/ygiJBI5A1NiF4KUrcIX8ZoV8x3U9UyeWp+Dc0bAvrR8Jy5vcth1XvDW4ce/htLMm2sO4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730753308; c=relaxed/simple; bh=8EnhGD2qlhj8Z6sW8iG8NB8c0Is3MLT8Zp3OfNibmls=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=UfZRazksIOZMOy5A8nOX81Phz6JgpEig3MQ3D4smFwULa81pCai/7W23DZPcUhYxajDha3aUGQYiNNG+OvCgnVBV5KNiOG3MIvus31gDp84Zvm/HqSFkqTL7ez5fQxsBNo8WvQDMawfI/qHrAZ123RCUpX2JOYzkvPqCJN4sl1E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=SFbxJ06E; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SFbxJ06E" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-20ca388d242so46239395ad.2; Mon, 04 Nov 2024 12:48:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730753306; x=1731358106; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=fg1kGUhfncmA8PwYI9BJDMVXGlhNrkCz2YzfyCWQjec=; b=SFbxJ06EFjXT/t29Ed+YYUdBlBMylJ7uvdlKBb/bxpzsSDXpL8yAF+FR/uUhXHODcw uJXDeMO7M3Rmo71MSGgeePwLyaRxRJKm76YjQOcDf2wT2gznO4iecjRXuhlMjbdOiNao dWgqM4Q8gW0avR2SLnXN+WMChiPB/RI/sUqi/IG+jwiHamnCkdzHpnWYLQtwaQQfuzJr ge2jfbZ+CagevtsFaGqVS+GJELpEoFiSGh3VBrqfl2Cq4B9PcJDbZmrDFFiToY9fWR1O pHoRCrV7gDyfTzZAu55QU60CQxJiWAwNpTEqBLXKl39KpqSPBwZfI6rD1lyUmeTqcvuN XD+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730753306; x=1731358106; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fg1kGUhfncmA8PwYI9BJDMVXGlhNrkCz2YzfyCWQjec=; b=ABvzZbXYWwYeVEv0Svo/6E6TZ5DVLeatKzHF7fRtpG9jF3U9wkDZLTChYnul++vABk YPg2goPd+zCfbDEklBwEbD6GznM4UPwsU4ragtrzBqi8SqVuC0SPhfHM8U7Pm8S4NUbl 156dg2UQI+U5gKXfWHlL4YVv6C62BNiyRb+HGiyHgrS1r5C1oD27kudh06xN8u0qazTg uzKGh5BIGkFHaxTASKlExuBYtBUjzknuxY64aACbt4m1qflUyNNYQitkiRVHQZKy0ex5 tyh+D+GpT3ka/ME29bC8o29ErBChUoF//nf+zBPglR9HlqgyGjYSKblfkroU4yDzYDi4 Cshg== X-Forwarded-Encrypted: i=1; AJvYcCXtKIXmXIXjhSem6b2qOcAqsoQXP6kc3tJecrUhRFhON9h+NPIbQaU+DpZdWABCGYbeJQUso0UTQXzYHO4=@vger.kernel.org X-Gm-Message-State: AOJu0Yy3FO2Hmf/KqVWJPND5ijzrby2sdNVwThT3Zg3ri0ofTrCcAYmF iRv/MBfOtxr+RzLljcLy/VbKKy9USAfBbBvFGuD+O33SxMHaKMmPxvnoOX4t X-Google-Smtp-Source: AGHT+IHfHRv0jMa19eosOtiDt2co1VlwhIZJtgvkHrlXq/nss6E70COsdiTiL3FykNuKgAYgTyWVrw== X-Received: by 2002:a17:903:1c7:b0:206:a87c:2864 with SMTP id d9443c01a7336-2111afd6ca6mr155354385ad.42.1730753305647; Mon, 04 Nov 2024 12:48:25 -0800 (PST) Received: from ryzen.lan ([2601:644:8200:dab8::a86]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-211057a6815sm66245235ad.135.2024.11.04.12.48.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 12:48:25 -0800 (PST) From: Rosen Penev To: netdev@vger.kernel.org Cc: Jian Shen , Salil Mehta , Jijie Shao , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-kernel@vger.kernel.org (open list) Subject: [PATCHv2 net-next] net: hisilicon: hns3: use ethtool string helpers Date: Mon, 4 Nov 2024 12:48:23 -0800 Message-ID: <20241104204823.297277-1-rosenp@gmail.com> X-Mailer: git-send-email 2.47.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Jijie Shao Tested-by: Jijie Shao --- v2: remove now useless define MAX_PREFIX_LENGTH drivers/net/ethernet/hisilicon/hns3/hnae3.h | 2 +- .../hns3/hns3_common/hclge_comm_tqp_stats.c | 11 ++-- .../hns3/hns3_common/hclge_comm_tqp_stats.h | 2 +- .../ethernet/hisilicon/hns3/hns3_ethtool.c | 54 ++++++------------- .../hisilicon/hns3/hns3pf/hclge_main.c | 50 +++++++---------- .../hisilicon/hns3/hns3vf/hclgevf_main.c | 6 +-- 6 files changed, 44 insertions(+), 81 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h b/drivers/net/ethe= rnet/hisilicon/hns3/hnae3.h index 27dbe367f3d3..710a8f9f2248 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h +++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h @@ -677,7 +677,7 @@ struct hnae3_ae_ops { void (*get_mac_stats)(struct hnae3_handle *handle, struct hns3_mac_stats *mac_stats); void (*get_strings)(struct hnae3_handle *handle, - u32 stringset, u8 *data); + u32 stringset, u8 **data); int (*get_sset_count)(struct hnae3_handle *handle, int stringset); =20 void (*get_regs)(struct hnae3_handle *handle, u32 *version, diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_common/hclge_comm_tqp= _stats.c b/drivers/net/ethernet/hisilicon/hns3/hns3_common/hclge_comm_tqp_s= tats.c index 2b31188ff555..f9a3d6fc4416 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_common/hclge_comm_tqp_stats.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_common/hclge_comm_tqp_stats.c @@ -36,27 +36,22 @@ int hclge_comm_tqps_get_sset_count(struct hnae3_handle = *handle) } EXPORT_SYMBOL_GPL(hclge_comm_tqps_get_sset_count); =20 -u8 *hclge_comm_tqps_get_strings(struct hnae3_handle *handle, u8 *data) +void hclge_comm_tqps_get_strings(struct hnae3_handle *handle, u8 **data) { struct hnae3_knic_private_info *kinfo =3D &handle->kinfo; - u8 *buff =3D data; u16 i; =20 for (i =3D 0; i < kinfo->num_tqps; i++) { struct hclge_comm_tqp *tqp =3D container_of(kinfo->tqp[i], struct hclge_comm_tqp, q); - snprintf(buff, ETH_GSTRING_LEN, "txq%u_pktnum_rcd", tqp->index); - buff +=3D ETH_GSTRING_LEN; + ethtool_sprintf(data, "txq%u_pktnum_rcd", tqp->index); } =20 for (i =3D 0; i < kinfo->num_tqps; i++) { struct hclge_comm_tqp *tqp =3D container_of(kinfo->tqp[i], struct hclge_comm_tqp, q); - snprintf(buff, ETH_GSTRING_LEN, "rxq%u_pktnum_rcd", tqp->index); - buff +=3D ETH_GSTRING_LEN; + ethtool_sprintf(data, "rxq%u_pktnum_rcd", tqp->index); } - - return buff; } EXPORT_SYMBOL_GPL(hclge_comm_tqps_get_strings); =20 diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_common/hclge_comm_tqp= _stats.h b/drivers/net/ethernet/hisilicon/hns3/hns3_common/hclge_comm_tqp_s= tats.h index a46350162ee8..b9ff424c0bc2 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_common/hclge_comm_tqp_stats.h +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_common/hclge_comm_tqp_stats.h @@ -32,7 +32,7 @@ struct hclge_comm_tqp { =20 u64 *hclge_comm_tqps_get_stats(struct hnae3_handle *handle, u64 *data); int hclge_comm_tqps_get_sset_count(struct hnae3_handle *handle); -u8 *hclge_comm_tqps_get_strings(struct hnae3_handle *handle, u8 *data); +void hclge_comm_tqps_get_strings(struct hnae3_handle *handle, u8 **data); void hclge_comm_reset_tqp_stats(struct hnae3_handle *handle); int hclge_comm_tqps_update_stats(struct hnae3_handle *handle, struct hclge_comm_hw *hw); diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c b/drivers/n= et/ethernet/hisilicon/hns3/hns3_ethtool.c index 97eaeec1952b..34a07fffadbb 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c @@ -509,54 +509,37 @@ static int hns3_get_sset_count(struct net_device *net= dev, int stringset) } } =20 -static void *hns3_update_strings(u8 *data, const struct hns3_stats *stats, - u32 stat_count, u32 num_tqps, const char *prefix) +static void hns3_update_strings(u8 **data, const struct hns3_stats *stats, + u32 stat_count, u32 num_tqps, + const char *prefix) { -#define MAX_PREFIX_SIZE (6 + 4) - u32 size_left; u32 i, j; - u32 n1; =20 - for (i =3D 0; i < num_tqps; i++) { - for (j =3D 0; j < stat_count; j++) { - data[ETH_GSTRING_LEN - 1] =3D '\0'; - - /* first, prepend the prefix string */ - n1 =3D scnprintf(data, MAX_PREFIX_SIZE, "%s%u_", - prefix, i); - size_left =3D (ETH_GSTRING_LEN - 1) - n1; - - /* now, concatenate the stats string to it */ - strncat(data, stats[j].stats_string, size_left); - data +=3D ETH_GSTRING_LEN; - } - } - - return data; + for (i =3D 0; i < num_tqps; i++) + for (j =3D 0; j < stat_count; j++) + ethtool_sprintf(data, "%s%u_%s", prefix, i, + stats[j].stats_string); } =20 -static u8 *hns3_get_strings_tqps(struct hnae3_handle *handle, u8 *data) +static void hns3_get_strings_tqps(struct hnae3_handle *handle, u8 **data) { struct hnae3_knic_private_info *kinfo =3D &handle->kinfo; const char tx_prefix[] =3D "txq"; const char rx_prefix[] =3D "rxq"; =20 /* get strings for Tx */ - data =3D hns3_update_strings(data, hns3_txq_stats, HNS3_TXQ_STATS_COUNT, - kinfo->num_tqps, tx_prefix); + hns3_update_strings(data, hns3_txq_stats, HNS3_TXQ_STATS_COUNT, + kinfo->num_tqps, tx_prefix); =20 /* get strings for Rx */ - data =3D hns3_update_strings(data, hns3_rxq_stats, HNS3_RXQ_STATS_COUNT, - kinfo->num_tqps, rx_prefix); - - return data; + hns3_update_strings(data, hns3_rxq_stats, HNS3_RXQ_STATS_COUNT, + kinfo->num_tqps, rx_prefix); } =20 static void hns3_get_strings(struct net_device *netdev, u32 stringset, u8 = *data) { struct hnae3_handle *h =3D hns3_get_handle(netdev); const struct hnae3_ae_ops *ops =3D h->ae_algo->ops; - char *buff =3D (char *)data; int i; =20 if (!ops->get_strings) @@ -564,18 +547,15 @@ static void hns3_get_strings(struct net_device *netde= v, u32 stringset, u8 *data) =20 switch (stringset) { case ETH_SS_STATS: - buff =3D hns3_get_strings_tqps(h, buff); - ops->get_strings(h, stringset, (u8 *)buff); + hns3_get_strings_tqps(h, &data); + ops->get_strings(h, stringset, &data); break; case ETH_SS_TEST: - ops->get_strings(h, stringset, data); + ops->get_strings(h, stringset, &data); break; case ETH_SS_PRIV_FLAGS: - for (i =3D 0; i < HNS3_PRIV_FLAGS_LEN; i++) { - snprintf(buff, ETH_GSTRING_LEN, "%s", - hns3_priv_flags[i].name); - buff +=3D ETH_GSTRING_LEN; - } + for (i =3D 0; i < HNS3_PRIV_FLAGS_LEN; i++) + ethtool_puts(&data, hns3_priv_flags[i].name); break; default: break; diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c b/driv= ers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c index 728f4777e51f..5fc08d686d25 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c @@ -595,25 +595,21 @@ static u64 *hclge_comm_get_stats(struct hclge_dev *hd= ev, return buf; } =20 -static u8 *hclge_comm_get_strings(struct hclge_dev *hdev, u32 stringset, - const struct hclge_comm_stats_str strs[], - int size, u8 *data) +static void hclge_comm_get_strings(struct hclge_dev *hdev, u32 stringset, + const struct hclge_comm_stats_str strs[], + int size, u8 **data) { - char *buff =3D (char *)data; u32 i; =20 if (stringset !=3D ETH_SS_STATS) - return buff; + return; =20 for (i =3D 0; i < size; i++) { if (strs[i].stats_num > hdev->ae_dev->dev_specs.mac_stats_num) continue; =20 - snprintf(buff, ETH_GSTRING_LEN, "%s", strs[i].desc); - buff =3D buff + ETH_GSTRING_LEN; + ethtool_puts(data, strs[i].desc); } - - return (u8 *)buff; } =20 static void hclge_update_stats_for_all(struct hclge_dev *hdev) @@ -718,44 +714,38 @@ static int hclge_get_sset_count(struct hnae3_handle *= handle, int stringset) } =20 static void hclge_get_strings(struct hnae3_handle *handle, u32 stringset, - u8 *data) + u8 **data) { struct hclge_vport *vport =3D hclge_get_vport(handle); struct hclge_dev *hdev =3D vport->back; - u8 *p =3D (char *)data; + const char *str; int size; =20 if (stringset =3D=3D ETH_SS_STATS) { size =3D ARRAY_SIZE(g_mac_stats_string); - p =3D hclge_comm_get_strings(hdev, stringset, g_mac_stats_string, - size, p); - p =3D hclge_comm_tqps_get_strings(handle, p); + hclge_comm_get_strings(hdev, stringset, g_mac_stats_string, + size, data); + hclge_comm_tqps_get_strings(handle, data); } else if (stringset =3D=3D ETH_SS_TEST) { if (handle->flags & HNAE3_SUPPORT_EXTERNAL_LOOPBACK) { - memcpy(p, hns3_nic_test_strs[HNAE3_LOOP_EXTERNAL], - ETH_GSTRING_LEN); - p +=3D ETH_GSTRING_LEN; + str =3D hns3_nic_test_strs[HNAE3_LOOP_EXTERNAL]; + ethtool_puts(data, str); } if (handle->flags & HNAE3_SUPPORT_APP_LOOPBACK) { - memcpy(p, hns3_nic_test_strs[HNAE3_LOOP_APP], - ETH_GSTRING_LEN); - p +=3D ETH_GSTRING_LEN; + str =3D hns3_nic_test_strs[HNAE3_LOOP_APP]; + ethtool_puts(data, str); } if (handle->flags & HNAE3_SUPPORT_SERDES_SERIAL_LOOPBACK) { - memcpy(p, hns3_nic_test_strs[HNAE3_LOOP_SERIAL_SERDES], - ETH_GSTRING_LEN); - p +=3D ETH_GSTRING_LEN; + str =3D hns3_nic_test_strs[HNAE3_LOOP_SERIAL_SERDES]; + ethtool_puts(data, str); } if (handle->flags & HNAE3_SUPPORT_SERDES_PARALLEL_LOOPBACK) { - memcpy(p, - hns3_nic_test_strs[HNAE3_LOOP_PARALLEL_SERDES], - ETH_GSTRING_LEN); - p +=3D ETH_GSTRING_LEN; + str =3D hns3_nic_test_strs[HNAE3_LOOP_PARALLEL_SERDES]; + ethtool_puts(data, str); } if (handle->flags & HNAE3_SUPPORT_PHY_LOOPBACK) { - memcpy(p, hns3_nic_test_strs[HNAE3_LOOP_PHY], - ETH_GSTRING_LEN); - p +=3D ETH_GSTRING_LEN; + str =3D hns3_nic_test_strs[HNAE3_LOOP_PHY]; + ethtool_puts(data, str); } } } diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c b/dr= ivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c index 896f1eb172d3..8739da317897 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c @@ -130,12 +130,10 @@ static int hclgevf_get_sset_count(struct hnae3_handle= *handle, int strset) } =20 static void hclgevf_get_strings(struct hnae3_handle *handle, u32 strset, - u8 *data) + u8 **data) { - u8 *p =3D (char *)data; - if (strset =3D=3D ETH_SS_STATS) - p =3D hclge_comm_tqps_get_strings(handle, p); + hclge_comm_tqps_get_strings(handle, data); } =20 static void hclgevf_get_stats(struct hnae3_handle *handle, u64 *data) --=20 2.47.0