Commit a21b75c3 authored by Hao Lan's avatar Hao Lan Committed by Jiantao Xiao
Browse files

net: hns3: support debugfs for wake on lan

driver inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I7ON9Y


CVE: NA

----------------------------------------------------------------------

Implement debugfs for wake on lan to hns3. The debugfs
support verify the firmware wake on lan configuration.

Signed-off-by: default avatarHao Lan <lanhao@huawei.com>
Signed-off-by: default avatarJiantao Xiao <xiaojiantao1@h-partners.com>
Reviewed-by: default avatarYue Haibing <yuehaibing@huawei.com>
Signed-off-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
parent 32e6e17f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -335,6 +335,7 @@ enum hnae3_dbg_cmd {
	HNAE3_DBG_CMD_UMV_INFO,
	HNAE3_DBG_CMD_PAGE_POOL_INFO,
	HNAE3_DBG_CMD_COAL_INFO,
	HNAE3_DBG_CMD_WOL_INFO,
	HNAE3_DBG_CMD_UNKNOWN,
};

+7 −0
Original line number Diff line number Diff line
@@ -357,6 +357,13 @@ static struct hns3_dbg_cmd_info hns3_dbg_cmd[] = {
		.buf_len = HNS3_DBG_READ_LEN_1MB,
		.init = hns3_dbg_common_file_init,
	},
	{
		.name = "wol_info",
		.cmd = HNAE3_DBG_CMD_WOL_INFO,
		.dentry = HNS3_DBG_DENTRY_COMMON,
		.buf_len = HNS3_DBG_READ_LEN,
		.init = hns3_dbg_common_file_init,
	},
};

static struct hns3_dbg_cap_info hns3_dbg_cap[] = {
+62 −0
Original line number Diff line number Diff line
@@ -2513,6 +2513,64 @@ static int hclge_dbg_dump_mac_mc(struct hclge_dev *hdev, char *buf, int len)
	return 0;
}

static void hclge_dump_wol_mode(u32 mode, char *buf, int len, int *pos)
{
	if (mode & WAKE_PHY)
		*pos += scnprintf(buf + *pos, len - *pos, "  [p]phy\n");

	if (mode & WAKE_UCAST)
		*pos += scnprintf(buf + *pos, len - *pos, "  [u]unicast\n");

	if (mode & WAKE_MCAST)
		*pos += scnprintf(buf + *pos, len - *pos, "  [m]multicast\n");

	if (mode & WAKE_BCAST)
		*pos += scnprintf(buf + *pos, len - *pos, "  [b]broadcast\n");

	if (mode & WAKE_ARP)
		*pos += scnprintf(buf + *pos, len - *pos, "  [a]arp\n");

	if (mode & WAKE_MAGIC)
		*pos += scnprintf(buf + *pos, len - *pos, "  [g]magic\n");

	if (mode & WAKE_MAGICSECURE)
		*pos += scnprintf(buf + *pos, len - *pos,
				 "  [s]magic secured\n");

	if (mode & WAKE_FILTER)
		*pos += scnprintf(buf + *pos, len - *pos, "  [f]filter\n");
}

static int hclge_dbg_dump_wol_info(struct hclge_dev *hdev, char *buf, int len)
{
	u32 wol_supported;
	int pos = 0;
	u32 mode;

	if (!hnae3_ae_dev_wol_supported(hdev->ae_dev)) {
		pos += scnprintf(buf + pos, len - pos,
				 "wake-on-lan is unsupported\n");
		return 0;
	}

	pos += scnprintf(buf + pos, len - pos, "wake-on-lan mode:\n");
	pos += scnprintf(buf + pos, len - pos, " supported:\n");
	if (hclge_get_wol_supported_mode(hdev, &wol_supported))
		return -EINVAL;

	hclge_dump_wol_mode(wol_supported, buf, len, &pos);

	pos += scnprintf(buf + pos, len - pos, " current:\n");
	if (hclge_get_wol_cfg(hdev, &mode))
		return -EINVAL;
	if (mode)
		hclge_dump_wol_mode(mode, buf, len, &pos);
	else
		pos += scnprintf(buf + pos, len - pos, "  [d]disabled\n");

	return 0;
}

static const struct hclge_dbg_func hclge_dbg_cmd_func[] = {
	{
		.cmd = HNAE3_DBG_CMD_TM_NODES,
@@ -2662,6 +2720,10 @@ static const struct hclge_dbg_func hclge_dbg_cmd_func[] = {
		.cmd = HNAE3_DBG_CMD_UMV_INFO,
		.dbg_dump = hclge_dbg_dump_umv_info,
	},
	{
		.cmd = HNAE3_DBG_CMD_WOL_INFO,
		.dbg_dump = hclge_dbg_dump_wol_info,
	},
};

int hclge_dbg_read_cmd(struct hnae3_handle *handle, enum hnae3_dbg_cmd cmd,
+22 −2
Original line number Diff line number Diff line
@@ -12081,7 +12081,7 @@ static struct hclge_wol_info *hclge_get_wol_info(struct hnae3_handle *handle)
	return &vport->back->hw.mac.wol;
}

static int hclge_get_wol_supported_mode(struct hclge_dev *hdev,
int hclge_get_wol_supported_mode(struct hclge_dev *hdev,
				 u32 *wol_supported)
{
	struct hclge_query_wol_supported_cmd *wol_supported_cmd;
@@ -12104,6 +12104,26 @@ static int hclge_get_wol_supported_mode(struct hclge_dev *hdev,
	return 0;
}

int hclge_get_wol_cfg(struct hclge_dev *hdev, u32 *mode)
{
	struct hclge_wol_cfg_cmd *wol_cfg_cmd;
	struct hclge_desc desc;
	int ret;

	hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_WOL_CFG, true);
	ret = hclge_cmd_send(&hdev->hw, &desc, 1);
	if (ret) {
		dev_err(&hdev->pdev->dev,
			"failed to get wol config, ret = %d\n", ret);
		return ret;
	}

	wol_cfg_cmd = (struct hclge_wol_cfg_cmd *)desc.data;
	*mode = le32_to_cpu(wol_cfg_cmd->wake_on_lan_mode);

	return 0;
}

static int hclge_set_wol_cfg(struct hclge_dev *hdev,
			     struct hclge_wol_info *wol_info)
{
+2 −0
Original line number Diff line number Diff line
@@ -1156,6 +1156,8 @@ int hclge_register_sysfs(struct hclge_dev *hdev);
void hclge_unregister_sysfs(struct hclge_dev *hdev);
int hclge_cfg_mac_speed_dup_hw(struct hclge_dev *hdev, int speed, u8 duplex,
			       u8 lane_num);
int hclge_get_wol_supported_mode(struct hclge_dev *hdev, u32 *wol_supported);
int hclge_get_wol_cfg(struct hclge_dev *hdev, u32 *mode);
struct hclge_vport *hclge_get_vf_vport(struct hclge_dev *hdev, int vf);
int hclge_inform_vf_reset(struct hclge_vport *vport, u16 reset_type);
void hclge_reset_task_schedule(struct hclge_dev *hdev);