diff mbox series

[RFC,net-next,3/8] net: hns3: add support for devlink get info for PF

Message ID 1625553692-2773-4-git-send-email-huangguangbin2@huawei.com
State Superseded
Headers show
Series net: hns3: add support devlink | expand

Commit Message

huangguangbin (A) July 6, 2021, 6:41 a.m. UTC
From: Yufeng Mo <moyufeng@huawei.com>

Add devlink get info support for HNS3 ethernet PF driver.

Signed-off-by: Yufeng Mo <moyufeng@huawei.com>
Signed-off-by: Guangbin Huang <huangguangbin2@huawei.com>
---
 .../ethernet/hisilicon/hns3/hns3pf/hclge_devlink.c | 28 ++++++++++++++++++++++
 1 file changed, 28 insertions(+)

Comments

Jakub Kicinski July 6, 2021, 11:14 p.m. UTC | #1
On Tue, 6 Jul 2021 14:41:27 +0800 Guangbin Huang wrote:
> +	return devlink_info_version_running_put(req, "fw-version", version_str);

Please use one of the existing names instead of "fw-version",
e.g. DEVLINK_INFO_VERSION_GENERIC_FW.
huangguangbin (A) July 7, 2021, 9:21 a.m. UTC | #2
On 2021/7/7 7:14, Jakub Kicinski wrote:
> On Tue, 6 Jul 2021 14:41:27 +0800 Guangbin Huang wrote:

>> +	return devlink_info_version_running_put(req, "fw-version", version_str);

> 

> Please use one of the existing names instead of "fw-version",

> e.g. DEVLINK_INFO_VERSION_GENERIC_FW.

> .

> 

Ok, thanks.
diff mbox series

Patch

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_devlink.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_devlink.c
index 03b822b0a8e7..1646e9e234fe 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_devlink.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_devlink.c
@@ -5,7 +5,35 @@ 
 
 #include "hclge_devlink.h"
 
+static int hclge_devlink_info_get(struct devlink *devlink,
+				  struct devlink_info_req *req,
+				  struct netlink_ext_ack *extack)
+{
+#define	HCLGE_DEVLINK_FW_STRING_LEN	32
+	struct hclge_devlink_priv *priv = devlink_priv(devlink);
+	char version_str[HCLGE_DEVLINK_FW_STRING_LEN];
+	struct hclge_dev *hdev = priv->hdev;
+	int ret;
+
+	ret = devlink_info_driver_name_put(req, KBUILD_MODNAME);
+	if (ret)
+		return ret;
+
+	snprintf(version_str, sizeof(version_str), "%lu.%lu.%lu.%lu",
+		 hnae3_get_field(hdev->fw_version, HNAE3_FW_VERSION_BYTE3_MASK,
+				 HNAE3_FW_VERSION_BYTE3_SHIFT),
+		 hnae3_get_field(hdev->fw_version, HNAE3_FW_VERSION_BYTE2_MASK,
+				 HNAE3_FW_VERSION_BYTE2_SHIFT),
+		 hnae3_get_field(hdev->fw_version, HNAE3_FW_VERSION_BYTE1_MASK,
+				 HNAE3_FW_VERSION_BYTE1_SHIFT),
+		 hnae3_get_field(hdev->fw_version, HNAE3_FW_VERSION_BYTE0_MASK,
+				 HNAE3_FW_VERSION_BYTE0_SHIFT));
+
+	return devlink_info_version_running_put(req, "fw-version", version_str);
+}
+
 static const struct devlink_ops hclge_devlink_ops = {
+	.info_get = hclge_devlink_info_get,
 };
 
 int hclge_devlink_init(struct hclge_dev *hdev)