Commit de2b192e authored by Tian Jiang's avatar Tian Jiang Committed by Jiantao Xiao
Browse files

net: hns3: add support query the presence of optical module

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


CVE: NA

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

The patch provides an interface to check whether the optical module
is inserted.

Signed-off-by: default avatarTian Jiang <jiangtian6@h-partners.com>
Signed-off-by: default avatarshaojijie <shaojijie@huawei.com>
Signed-off-by: default avatarJiantao Xiao <xiaojiantao1@h-partners.com>
parent dd347d0d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ enum hnae3_ext_opcode {
	HNAE3_EXT_OPC_GET_PORT_EXT_ID_INFO,
	HNAE3_EXT_OPC_GET_PORT_EXT_NUM_INFO,
	HNAE3_EXT_OPC_GET_PORT_NUM,
	HNAE3_EXT_OPC_GET_PRESENT,
};

struct hnae3_pfc_storm_para {
+7 −0
Original line number Diff line number Diff line
@@ -396,3 +396,10 @@ int nic_set_tx_timeout(struct net_device *ndev, int tx_timeout)
	return 0;
}
EXPORT_SYMBOL(nic_set_tx_timeout);

int nic_get_sfp_present(struct net_device *ndev, int *present)
{
	return nic_invoke_pri_ops(ndev, HNAE3_EXT_OPC_GET_PRESENT,
				  present, sizeof(*present));
}
EXPORT_SYMBOL(nic_get_sfp_present);
+1 −0
Original line number Diff line number Diff line
@@ -36,4 +36,5 @@ int nic_get_io_die_num(struct net_device *ndev, u32 *io_die_num);
int nic_get_port_num_of_die(struct net_device *ndev, u32 *port_num);
int nic_get_port_num_per_chip(struct net_device *ndev, u32 *port_num);
int nic_set_tx_timeout(struct net_device *ndev, int tx_timeout);
int nic_get_sfp_present(struct net_device *ndev, int *present);
#endif
+22 −0
Original line number Diff line number Diff line
@@ -440,6 +440,27 @@ static int hclge_get_port_num(struct hclge_dev *hdev, void *data,
	return 0;
}

static int hclge_get_sfp_present(struct hclge_dev *hdev, void *data,
				 size_t length)
{
	struct hclge_sfp_present_cmd *resp;
	struct hclge_desc desc;
	int ret;

	if (length != sizeof(u32))
		return -EINVAL;

	ret = hclge_get_info_from_cmd(hdev, &desc, 1, HCLGE_OPC_SFP_GET_PRESENT);
	if (ret) {
		dev_err(&hdev->pdev->dev, "failed to get sfp present, ret = %d\n", ret);
		return ret;
	}

	resp = (struct hclge_sfp_present_cmd *)desc.data;
	*(u32 *)data = le32_to_cpu(resp->sfp_present);
	return 0;
}

static void hclge_ext_resotre_config(struct hclge_dev *hdev)
{
	if (hdev->reset_type != HNAE3_IMP_RESET &&
@@ -601,6 +622,7 @@ static const hclge_priv_ops_fn hclge_ext_func_arr[] = {
	[HNAE3_EXT_OPC_GET_PORT_EXT_ID_INFO] = hclge_get_extend_port_id_info,
	[HNAE3_EXT_OPC_GET_PORT_EXT_NUM_INFO] = hclge_get_extend_port_num_info,
	[HNAE3_EXT_OPC_GET_PORT_NUM] = hclge_get_port_num,
	[HNAE3_EXT_OPC_GET_PRESENT] = hclge_get_sfp_present,
};

int hclge_ext_ops_handle(struct hnae3_handle *handle, int opcode,
+6 −0
Original line number Diff line number Diff line
@@ -73,6 +73,11 @@ struct hclge_torus_cfg_cmd {
	__le32 torus_en;
};

struct hclge_sfp_present_cmd {
	__le32 sfp_present;
	__le32 rsv[5];
};

enum hclge_ext_opcode_type {
	HCLGE_OPC_CONFIG_SWITCH_PARAM = 0x1033,
	HCLGE_OPC_CONFIG_VLAN_FILTER = 0x1100,
@@ -82,6 +87,7 @@ enum hclge_ext_opcode_type {
	HCLGE_OPC_GET_CHIP_NUM = 0x7005,
	HCLGE_OPC_GET_PORT_NUM = 0x7006,
	HCLGE_OPC_CFG_PAUSE_STORM_PARA = 0x7019,
	HCLGE_OPC_SFP_GET_PRESENT = 0x7101,
};

struct hclge_reset_fail_type_map {