From: shaojijie shaojijie@huawei.com
driver inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I94FVZ CVE: NA
----------------------------------------------------------------------
The patch provides an interface for enabling or disabling the optical module.
Signed-off-by: shaojijie shaojijie@huawei.com Signed-off-by: Jiantao Xiao xiaojiantao1@h-partners.com --- .../net/ethernet/hisilicon/hns3/hnae3_ext.h | 1 + .../net/ethernet/hisilicon/hns3/hns3_ext.c | 9 +++++++ .../net/ethernet/hisilicon/hns3/hns3_ext.h | 1 + .../hisilicon/hns3/hns3pf/hclge_ext.c | 25 +++++++++++++++++++ .../hisilicon/hns3/hns3pf/hclge_ext.h | 6 +++++ 5 files changed, 42 insertions(+)
diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3_ext.h b/drivers/net/ethernet/hisilicon/hns3/hnae3_ext.h index 3d9654883144..54aab1270953 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hnae3_ext.h +++ b/drivers/net/ethernet/hisilicon/hns3/hnae3_ext.h @@ -40,6 +40,7 @@ enum hnae3_ext_opcode { HNAE3_EXT_OPC_GET_PORT_EXT_NUM_INFO, HNAE3_EXT_OPC_GET_PORT_NUM, HNAE3_EXT_OPC_GET_PRESENT, + HNAE3_EXT_OPC_SET_SFP_STATE, };
struct hnae3_pfc_storm_para { diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_ext.c b/drivers/net/ethernet/hisilicon/hns3/hns3_ext.c index b6b0320753f6..77f359f2a205 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_ext.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ext.c @@ -410,3 +410,12 @@ int nic_get_sfp_present(struct net_device *ndev, int *present) present, sizeof(*present)); } EXPORT_SYMBOL(nic_get_sfp_present); + +int nic_set_sfp_state(struct net_device *ndev, bool en) +{ + u32 state = en ? 1 : 0; + + return nic_invoke_pri_ops(ndev, HNAE3_EXT_OPC_SET_SFP_STATE, + &state, sizeof(state)); +} +EXPORT_SYMBOL(nic_set_sfp_state); diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_ext.h b/drivers/net/ethernet/hisilicon/hns3/hns3_ext.h index 464f030da38a..cbf993691c92 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_ext.h +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ext.h @@ -38,4 +38,5 @@ 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); +int nic_set_sfp_state(struct net_device *ndev, bool en); #endif diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_ext.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_ext.c index bf4e607245dd..5d58780f7c74 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_ext.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_ext.c @@ -467,6 +467,30 @@ static int hclge_get_sfp_present(struct hclge_dev *hdev, void *data, return 0; }
+static int hclge_set_sfp_state(struct hclge_dev *hdev, void *data, + size_t length) +{ + struct hclge_sfp_enable_cmd *req; + struct hclge_desc desc; + u32 state; + int ret; + + if (length != sizeof(u32)) + return -EINVAL; + + state = *(u32 *)data; + hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_SFP_SET_STATUS, false); + req = (struct hclge_sfp_enable_cmd *)desc.data; + req->sfp_enable = cpu_to_le32(state); + + ret = hclge_cmd_send(&hdev->hw, &desc, 1); + if (ret) + dev_err(&hdev->pdev->dev, + "failed to set sfp state, ret = %d\n", ret); + + return ret; +} + static void hclge_ext_resotre_config(struct hclge_dev *hdev) { if (hdev->reset_type != HNAE3_IMP_RESET && @@ -630,6 +654,7 @@ static const hclge_priv_ops_fn hclge_ext_func_arr[] = { [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, + [HNAE3_EXT_OPC_SET_SFP_STATE] = hclge_set_sfp_state, };
int hclge_ext_ops_handle(struct hnae3_handle *handle, int opcode, diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_ext.h b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_ext.h index ae6f0afef1f1..607bd1668cdc 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_ext.h +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_ext.h @@ -78,6 +78,11 @@ struct hclge_sfp_present_cmd { __le32 rsv[5]; };
+struct hclge_sfp_enable_cmd { + __le32 sfp_enable; + __le32 rsv[5]; +}; + enum hclge_ext_opcode_type { HCLGE_OPC_CONFIG_SWITCH_PARAM = 0x1033, HCLGE_OPC_CONFIG_VLAN_FILTER = 0x1100, @@ -88,6 +93,7 @@ enum hclge_ext_opcode_type { HCLGE_OPC_GET_PORT_NUM = 0x7006, HCLGE_OPC_CFG_PAUSE_STORM_PARA = 0x7019, HCLGE_OPC_SFP_GET_PRESENT = 0x7101, + HCLGE_OPC_SFP_SET_STATUS = 0x7102, };
struct hclge_reset_fail_type_map {