linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Salil Mehta <salil.mehta@huawei.com>
To: <davem@davemloft.net>
Cc: <salil.mehta@huawei.com>, <yisen.zhuang@huawei.com>,
	<lipeng321@huawei.com>, <mehta.salil@opnsrc.net>,
	<netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<linuxarm@huawei.com>, liuzhongzhu <liuzhongzhu@huawei.com>
Subject: [RFC net-next 4/9] net: hns3: Add "vf vlan table" information query function
Date: Sun, 2 Dec 2018 23:09:28 +0000	[thread overview]
Message-ID: <20181202230933.15560-5-salil.mehta@huawei.com> (raw)
In-Reply-To: <20181202230933.15560-1-salil.mehta@huawei.com>

From: liuzhongzhu <liuzhongzhu@huawei.com>

This patch prints vf vlan table information.

debugfs command:
echo dump port vlan tbl 0 > cmd

Sample Command:
root@(none)# echo dump vf vlan tbl 0 > cmd
vlan | vf filter bitMap:
0000 | 00000000:00000000:00000000:00000000:00000000:00000000:00000000:00000001
root@(none)#

Signed-off-by: liuzhongzhu <liuzhongzhu@huawei.com>
Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c |  1 +
 .../ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c | 93 ++++++++++++++++++++++
 2 files changed, 94 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
index 51af55f34e55..80a081e87b96 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
@@ -212,6 +212,7 @@ static void hns3_dbg_help(struct hnae3_handle *h)
 	dev_info(&h->pdev->dev, "dump qos buf cfg\n");
 	dev_info(&h->pdev->dev, "dump mac tbl\n");
 	dev_info(&h->pdev->dev, "dump port vlan tbl\n");
+	dev_info(&h->pdev->dev, "dump vf vlan tbl [vf id]\n");
 }
 
 static ssize_t hns3_dbg_cmd_read(struct file *filp, char __user *buffer,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
index 4a034a59fcb2..20e64abe7c5a 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
@@ -608,6 +608,97 @@ static void hclge_dbg_dump_port_vlan_table(struct hclge_dev *hdev)
 	kfree(vlan_bitmap);
 }
 
+static void hclge_dbg_dump_vf_vlan_table(struct hclge_dev *hdev, char *cmd_buf)
+{
+	struct hclge_vlan_filter_vf_cfg_cmd *req0;
+	struct hclge_vlan_filter_vf_cfg_cmd *req1;
+	char printf_buf[HCLGE_DBG_BUF_LEN];
+	struct hclge_desc desc[2];
+	u32 *vlan_bitmap;
+	u8 vf_byte_val;
+	u8 vf_bitmap;
+	int vlan_len;
+	u32 vlan_id;
+	int ret, i;
+	bool flag;
+	u16 vf_id;
+
+	ret = kstrtou16(&cmd_buf[17], 10, &vf_id);
+	if (ret) {
+		dev_err(&hdev->pdev->dev,
+			"vf id failed. vf id max: %d\n", hdev->num_alloc_vfs);
+		return;
+	}
+
+	vlan_len = HCLGE_DBG_VLAN_ID_MAX / 8;
+	vlan_bitmap = kzalloc(vlan_len, GFP_KERNEL);
+	if (!vlan_bitmap) {
+		dev_err(&hdev->pdev->dev,
+			"port vlan table alloc memory failed\n");
+		return;
+	}
+
+	for (vlan_id = 0; vlan_id < HCLGE_DBG_VLAN_ID_MAX; vlan_id++) {
+		/* Prevent long-term occupation of the command channel. */
+		if ((vlan_id % 100) == 0)
+			msleep(100);
+
+		hclge_cmd_setup_basic_desc(&desc[0],
+					   HCLGE_OPC_VLAN_FILTER_VF_CFG, true);
+		desc[0].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
+		hclge_cmd_setup_basic_desc(&desc[1],
+					   HCLGE_OPC_VLAN_FILTER_VF_CFG, true);
+
+		req0 = (struct hclge_vlan_filter_vf_cfg_cmd *)desc[0].data;
+		req1 = (struct hclge_vlan_filter_vf_cfg_cmd *)desc[1].data;
+		req0->vlan_id = cpu_to_le16(vlan_id);
+
+		ret = hclge_cmd_send(&hdev->hw, desc, 2);
+		if (ret) {
+			dev_err(&hdev->pdev->dev,
+				"call hclge_cmd_send fail, ret = %d\n", ret);
+			kfree(vlan_bitmap);
+			return;
+		}
+
+		if (vf_id < 128)
+			vf_bitmap = req0->vf_bitmap[vf_id / 8];
+		else
+			vf_bitmap = req1->vf_bitmap[(vf_id - 128) / 8];
+
+		vf_byte_val = 1 << (vf_id % 8);
+
+		if (vf_bitmap & vf_byte_val)
+			vlan_bitmap[(u32)(vlan_id / 32)] |= 1 << (vlan_id % 32);
+	}
+
+	dev_info(&hdev->pdev->dev, "vlan | vf filter bitMap:\n");
+
+	for (vlan_id = 0; vlan_id < HCLGE_DBG_VLAN_ID_MAX / 32; vlan_id += 8) {
+		memset(printf_buf, 0, HCLGE_DBG_BUF_LEN);
+		snprintf(printf_buf, HCLGE_DBG_BUF_LEN,
+			 "%04d | ", vlan_id * 32);
+
+		flag = false;
+
+		for (i = 7; i >= 0; i--) {
+			snprintf(printf_buf + strlen(printf_buf),
+				 HCLGE_DBG_BUF_LEN - strlen(printf_buf),
+				 "%08x:", vlan_bitmap[(u32)(vlan_id + i)]);
+
+			if (vlan_bitmap[(u32)(vlan_id + i)] > 0)
+				flag = true;
+		}
+
+		printf_buf[strlen(printf_buf) - 1] = '\n';
+
+		if (flag)
+			dev_info(&hdev->pdev->dev, "%s", printf_buf);
+	}
+
+	kfree(vlan_bitmap);
+}
+
 static void hclge_dbg_fd_tcam_read(struct hclge_dev *hdev, u8 stage,
 				   bool sel_x, u32 loc)
 {
@@ -683,6 +774,8 @@ int hclge_dbg_run_cmd(struct hnae3_handle *handle, char *cmd_buf)
 		hclge_dbg_dump_mac_table(hdev);
 	} else if (strncmp(cmd_buf, "dump port vlan tbl", 18) == 0) {
 		hclge_dbg_dump_port_vlan_table(hdev);
+	} else if (strncmp(cmd_buf, "dump vf vlan tbl", 16) == 0) {
+		hclge_dbg_dump_vf_vlan_table(hdev, cmd_buf);
 	} else {
 		dev_info(&hdev->pdev->dev, "unknown command\n");
 		return -EINVAL;
-- 
2.11.0



  parent reply	other threads:[~2018-12-02 23:12 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-02 23:09 [RFC net-next 0/9] net: hns3: Add more commands to Debugfs in HNS3 driver Salil Mehta
2018-12-02 23:09 ` [RFC net-next 1/9] net: hns3: Add "bd info" query function Salil Mehta
2018-12-02 23:09 ` [RFC net-next 2/9] net: hns3: Add "mac table" information " Salil Mehta
2018-12-02 23:09 ` [RFC net-next 3/9] net: hns3: Add "port vlan " Salil Mehta
2018-12-03 23:12   ` Jakub Kicinski
2018-12-03 23:12     ` David Miller
2018-12-04 10:10       ` Salil Mehta
2018-12-04 10:55         ` Andrew Lunn
2018-12-04 20:55           ` Salil Mehta
2018-12-02 23:09 ` Salil Mehta [this message]
2018-12-02 23:09 ` [RFC net-next 5/9] net: hns3: Add "manager " Salil Mehta
2018-12-02 23:09 ` [RFC net-next 6/9] net: hns3: Add "status register" " Salil Mehta
2018-12-02 23:09 ` [RFC net-next 7/9] net: hns3: Add "dcb register" status " Salil Mehta
2018-12-02 23:09 ` [RFC net-next 8/9] net: hns3: Add "queue map" " Salil Mehta
2018-12-02 23:09 ` [RFC net-next 9/9] net: hns3: Add "tm map" status " Salil Mehta

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181202230933.15560-5-salil.mehta@huawei.com \
    --to=salil.mehta@huawei.com \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=lipeng321@huawei.com \
    --cc=liuzhongzhu@huawei.com \
    --cc=mehta.salil@opnsrc.net \
    --cc=netdev@vger.kernel.org \
    --cc=yisen.zhuang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).