From: wangpeiyang wangpeiyang1@huawei.com
driver inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I94FVZ CVE: NA
----------------------------------------------------------------------
The patch provides a customized interface to modify the MAC mode.
Signed-off-by: wangpeiyang wangpeiyang1@huawei.com 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 | 7 ++++ .../net/ethernet/hisilicon/hns3/hns3_ext.h | 1 + .../hisilicon/hns3/hns3pf/hclge_ext.c | 33 +++++++++++++++++++ .../hisilicon/hns3/hns3pf/hclge_main.c | 11 ++++--- .../hisilicon/hns3/hns3pf/hclge_main.h | 1 + 6 files changed, 50 insertions(+), 4 deletions(-)
diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3_ext.h b/drivers/net/ethernet/hisilicon/hns3/hnae3_ext.h index 608846538612..ba707032f52e 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hnae3_ext.h +++ b/drivers/net/ethernet/hisilicon/hns3/hnae3_ext.h @@ -48,6 +48,7 @@ enum hnae3_ext_opcode { HNAE3_EXT_OPC_GET_HILINK_REF_LOS, HNAE3_EXT_OPC_GET_PORT_FAULT_STATUS, HNAE3_EXT_OPC_GET_PORT_TYPE, + HNAE3_EXT_OPC_SET_MAC_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 c3e16523bf33..d4cdab636ff0 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_ext.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ext.c @@ -475,3 +475,10 @@ int nic_get_port_wire_type(struct net_device *ndev, u32 *wire_type) wire_type, sizeof(*wire_type)); } EXPORT_SYMBOL(nic_get_port_wire_type); + +int nic_set_mac_state(struct net_device *ndev, int enable) +{ + return nic_invoke_pri_ops(ndev, HNAE3_EXT_OPC_SET_MAC_STATE, + &enable, sizeof(enable)); +} +EXPORT_SYMBOL(nic_set_mac_state); diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_ext.h b/drivers/net/ethernet/hisilicon/hns3/hns3_ext.h index 4361b89c0521..907cbaf2a3f1 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_ext.h +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ext.h @@ -50,4 +50,5 @@ int nic_disable_clock(struct net_device *ndev); int nic_set_pfc_time_cfg(struct net_device *ndev, u16 time); int nic_get_port_fault_status(struct net_device *ndev, u32 fault_type, u32 *status); int nic_get_port_wire_type(struct net_device *ndev, u32 *wire_type); +int nic_set_mac_state(struct net_device *ndev, int enable); #endif diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_ext.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_ext.c index 67b41309c0fe..8b6f75cad7f7 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_ext.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_ext.c @@ -650,6 +650,38 @@ static int hclge_get_port_wire_type(struct hclge_dev *hdev, void *data, return 0; }
+static void hclge_set_phy_state(struct hclge_dev *hdev, bool enable) +{ + struct phy_device *phydev = hdev->hw.mac.phydev; + + if (!phydev) + return; + + if (enable && (phydev->state == PHY_READY || phydev->state == PHY_HALTED)) + phy_start(phydev); + else if (!enable && (phy_is_started(phydev) || phydev->state == PHY_DOWN || + phydev->state == PHY_ERROR)) + phy_stop(phydev); +} + +static int hclge_set_mac_state(struct hclge_dev *hdev, void *data, + size_t length) +{ + bool enable; + int ret; + + if (length != sizeof(int)) + return -EINVAL; + + enable = !!*(int *)data; + ret = hclge_cfg_mac_mode(hdev, enable); + + if (!ret && !hclge_comm_dev_phy_imp_supported(hdev->ae_dev)) + hclge_set_phy_state(hdev, enable); + + return ret; +} + static void hclge_ext_resotre_config(struct hclge_dev *hdev) { if (hdev->reset_type != HNAE3_IMP_RESET && @@ -821,6 +853,7 @@ static const hclge_priv_ops_fn hclge_ext_func_arr[] = { [HNAE3_EXT_OPC_GET_HILINK_REF_LOS] = hclge_get_hilink_ref_los, [HNAE3_EXT_OPC_GET_PORT_FAULT_STATUS] = hclge_get_port_fault_status, [HNAE3_EXT_OPC_GET_PORT_TYPE] = hclge_get_port_wire_type, + [HNAE3_EXT_OPC_SET_MAC_STATE] = hclge_set_mac_state, };
int hclge_ext_ops_handle(struct hnae3_handle *handle, int opcode, diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c index a21a0a9b3345..7be100810818 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c @@ -7491,7 +7491,7 @@ static void hclge_enable_fd(struct hnae3_handle *handle, bool enable) hclge_task_schedule(hdev, 0); }
-static void hclge_cfg_mac_mode(struct hclge_dev *hdev, bool enable) +int hclge_cfg_mac_mode(struct hclge_dev *hdev, bool enable) { #define HCLGE_LINK_STATUS_WAIT_CNT 3
@@ -7520,14 +7520,17 @@ static void hclge_cfg_mac_mode(struct hclge_dev *hdev, bool enable)
ret = hclge_cmd_send(&hdev->hw, &desc, 1); if (ret) { - dev_err(&hdev->pdev->dev, - "mac enable fail, ret =%d.\n", ret); - return; + dev_err(&hdev->pdev->dev, "failed to %s mac, ret = %d.\n", + enable ? "enable" : "disable", ret); + + return ret; }
if (!enable) hclge_mac_link_status_wait(hdev, HCLGE_LINK_STATUS_DOWN, HCLGE_LINK_STATUS_WAIT_CNT); + + return 0; }
static int hclge_config_switch_param(struct hclge_dev *hdev, int vfid, diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h index 7c16936af5a8..4e692d5c8e7c 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h @@ -1169,4 +1169,5 @@ void hclge_reset_task_schedule(struct hclge_dev *hdev); void hclge_reset_event(struct pci_dev *pdev, struct hnae3_handle *handle); void hclge_get_media_type(struct hnae3_handle *handle, u8 *media_type, u8 *module_type); +int hclge_cfg_mac_mode(struct hclge_dev *hdev, bool enable); #endif