提交 a6d818e3 编写于 作者: Y Yunsheng Lin 提交者: David S. Miller

net: hns3: Add vport alive state checking support

Currently there is no way for pf to know if a vf device is
alive or not, so PF does not know which vf to notify when
reset happens, or which vf's mtu is invalid when vf and pf
share the same hardware mtu setting.

This patch adds vport alive state checking support, in order
to support the above scenario.
Signed-off-by: NYunsheng Lin <linyunsheng@huawei.com>
Signed-off-by: NJian Shen <shenjian15@huawei.com>
Signed-off-by: NSalil Mehta <salil.mehta@huawei.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 e6d7d79d
...@@ -36,6 +36,8 @@ enum HCLGE_MBX_OPCODE { ...@@ -36,6 +36,8 @@ enum HCLGE_MBX_OPCODE {
HCLGE_MBX_BIND_FUNC_QUEUE, /* (VF -> PF) bind function and queue */ HCLGE_MBX_BIND_FUNC_QUEUE, /* (VF -> PF) bind function and queue */
HCLGE_MBX_GET_LINK_STATUS, /* (VF -> PF) get link status */ HCLGE_MBX_GET_LINK_STATUS, /* (VF -> PF) get link status */
HCLGE_MBX_QUEUE_RESET, /* (VF -> PF) reset queue */ HCLGE_MBX_QUEUE_RESET, /* (VF -> PF) reset queue */
HCLGE_MBX_KEEP_ALIVE, /* (VF -> PF) send keep alive cmd */
HCLGE_MBX_SET_ALIVE, /* (VF -> PF) set alive state */
}; };
/* below are per-VF mac-vlan subcodes */ /* below are per-VF mac-vlan subcodes */
......
...@@ -210,6 +210,10 @@ struct hnae3_ae_dev { ...@@ -210,6 +210,10 @@ struct hnae3_ae_dev {
* Enable the hardware * Enable the hardware
* stop() * stop()
* Disable the hardware * Disable the hardware
* start_client()
* Inform the hclge that client has been started
* stop_client()
* Inform the hclge that client has been stopped
* get_status() * get_status()
* Get the carrier state of the back channel of the handle, 1 for ok, 0 for * Get the carrier state of the back channel of the handle, 1 for ok, 0 for
* non-ok * non-ok
...@@ -319,6 +323,8 @@ struct hnae3_ae_ops { ...@@ -319,6 +323,8 @@ struct hnae3_ae_ops {
struct hnae3_ae_dev *ae_dev); struct hnae3_ae_dev *ae_dev);
int (*start)(struct hnae3_handle *handle); int (*start)(struct hnae3_handle *handle);
void (*stop)(struct hnae3_handle *handle); void (*stop)(struct hnae3_handle *handle);
int (*client_start)(struct hnae3_handle *handle);
void (*client_stop)(struct hnae3_handle *handle);
int (*get_status)(struct hnae3_handle *handle); int (*get_status)(struct hnae3_handle *handle);
void (*get_ksettings_an_result)(struct hnae3_handle *handle, void (*get_ksettings_an_result)(struct hnae3_handle *handle,
u8 *auto_neg, u32 *speed, u8 *duplex); u8 *auto_neg, u32 *speed, u8 *duplex);
......
...@@ -3540,6 +3540,22 @@ static void hns3_nic_set_priv_ops(struct net_device *netdev) ...@@ -3540,6 +3540,22 @@ static void hns3_nic_set_priv_ops(struct net_device *netdev)
priv->ops.maybe_stop_tx = hns3_nic_maybe_stop_tx; priv->ops.maybe_stop_tx = hns3_nic_maybe_stop_tx;
} }
static int hns3_client_start(struct hnae3_handle *handle)
{
if (!handle->ae_algo->ops->client_start)
return 0;
return handle->ae_algo->ops->client_start(handle);
}
static void hns3_client_stop(struct hnae3_handle *handle)
{
if (!handle->ae_algo->ops->client_stop)
return;
handle->ae_algo->ops->client_stop(handle);
}
static int hns3_client_init(struct hnae3_handle *handle) static int hns3_client_init(struct hnae3_handle *handle)
{ {
struct pci_dev *pdev = handle->pdev; struct pci_dev *pdev = handle->pdev;
...@@ -3607,6 +3623,12 @@ static int hns3_client_init(struct hnae3_handle *handle) ...@@ -3607,6 +3623,12 @@ static int hns3_client_init(struct hnae3_handle *handle)
goto out_reg_netdev_fail; goto out_reg_netdev_fail;
} }
ret = hns3_client_start(handle);
if (ret) {
dev_err(priv->dev, "hns3_client_start fail! ret=%d\n", ret);
goto out_reg_netdev_fail;
}
hns3_dcbnl_setup(handle); hns3_dcbnl_setup(handle);
/* MTU range: (ETH_MIN_MTU(kernel default) - 9702) */ /* MTU range: (ETH_MIN_MTU(kernel default) - 9702) */
...@@ -3635,6 +3657,8 @@ static void hns3_client_uninit(struct hnae3_handle *handle, bool reset) ...@@ -3635,6 +3657,8 @@ static void hns3_client_uninit(struct hnae3_handle *handle, bool reset)
struct hns3_nic_priv *priv = netdev_priv(netdev); struct hns3_nic_priv *priv = netdev_priv(netdev);
int ret; int ret;
hns3_client_stop(handle);
hns3_remove_hw_addr(netdev); hns3_remove_hw_addr(netdev);
if (netdev->reg_state != NETREG_UNINITIALIZED) if (netdev->reg_state != NETREG_UNINITIALIZED)
......
...@@ -2911,6 +2911,19 @@ static void hclge_mailbox_service_task(struct work_struct *work) ...@@ -2911,6 +2911,19 @@ static void hclge_mailbox_service_task(struct work_struct *work)
clear_bit(HCLGE_STATE_MBX_HANDLING, &hdev->state); clear_bit(HCLGE_STATE_MBX_HANDLING, &hdev->state);
} }
static void hclge_update_vport_alive(struct hclge_dev *hdev)
{
int i;
/* start from vport 1 for PF is always alive */
for (i = 1; i < hdev->num_alloc_vport; i++) {
struct hclge_vport *vport = &hdev->vport[i];
if (time_after(jiffies, vport->last_active_jiffies + 8 * HZ))
clear_bit(HCLGE_VPORT_STATE_ALIVE, &vport->state);
}
}
static void hclge_service_task(struct work_struct *work) static void hclge_service_task(struct work_struct *work)
{ {
struct hclge_dev *hdev = struct hclge_dev *hdev =
...@@ -2923,6 +2936,7 @@ static void hclge_service_task(struct work_struct *work) ...@@ -2923,6 +2936,7 @@ static void hclge_service_task(struct work_struct *work)
hclge_update_speed_duplex(hdev); hclge_update_speed_duplex(hdev);
hclge_update_link_status(hdev); hclge_update_link_status(hdev);
hclge_update_vport_alive(hdev);
hclge_service_complete(hdev); hclge_service_complete(hdev);
} }
...@@ -5208,6 +5222,32 @@ static void hclge_ae_stop(struct hnae3_handle *handle) ...@@ -5208,6 +5222,32 @@ static void hclge_ae_stop(struct hnae3_handle *handle)
hclge_update_link_status(hdev); hclge_update_link_status(hdev);
} }
int hclge_vport_start(struct hclge_vport *vport)
{
set_bit(HCLGE_VPORT_STATE_ALIVE, &vport->state);
vport->last_active_jiffies = jiffies;
return 0;
}
void hclge_vport_stop(struct hclge_vport *vport)
{
clear_bit(HCLGE_VPORT_STATE_ALIVE, &vport->state);
}
static int hclge_client_start(struct hnae3_handle *handle)
{
struct hclge_vport *vport = hclge_get_vport(handle);
return hclge_vport_start(vport);
}
static void hclge_client_stop(struct hnae3_handle *handle)
{
struct hclge_vport *vport = hclge_get_vport(handle);
hclge_vport_stop(vport);
}
static int hclge_get_mac_vlan_cmd_status(struct hclge_vport *vport, static int hclge_get_mac_vlan_cmd_status(struct hclge_vport *vport,
u16 cmdq_resp, u8 resp_code, u16 cmdq_resp, u8 resp_code,
enum hclge_mac_vlan_tbl_opcode op) enum hclge_mac_vlan_tbl_opcode op)
...@@ -7189,6 +7229,17 @@ static void hclge_stats_clear(struct hclge_dev *hdev) ...@@ -7189,6 +7229,17 @@ static void hclge_stats_clear(struct hclge_dev *hdev)
memset(&hdev->hw_stats, 0, sizeof(hdev->hw_stats)); memset(&hdev->hw_stats, 0, sizeof(hdev->hw_stats));
} }
static void hclge_reset_vport_state(struct hclge_dev *hdev)
{
struct hclge_vport *vport = hdev->vport;
int i;
for (i = 0; i < hdev->num_alloc_vport; i++) {
hclge_vport_start(vport);
vport++;
}
}
static int hclge_reset_ae_dev(struct hnae3_ae_dev *ae_dev) static int hclge_reset_ae_dev(struct hnae3_ae_dev *ae_dev)
{ {
struct hclge_dev *hdev = ae_dev->priv; struct hclge_dev *hdev = ae_dev->priv;
...@@ -7274,6 +7325,8 @@ static int hclge_reset_ae_dev(struct hnae3_ae_dev *ae_dev) ...@@ -7274,6 +7325,8 @@ static int hclge_reset_ae_dev(struct hnae3_ae_dev *ae_dev)
if (hclge_enable_tm_hw_error(hdev, true)) if (hclge_enable_tm_hw_error(hdev, true))
dev_err(&pdev->dev, "failed to enable TM hw error interrupts\n"); dev_err(&pdev->dev, "failed to enable TM hw error interrupts\n");
hclge_reset_vport_state(hdev);
dev_info(&pdev->dev, "Reset done, %s driver initialization finished.\n", dev_info(&pdev->dev, "Reset done, %s driver initialization finished.\n",
HCLGE_DRIVER_NAME); HCLGE_DRIVER_NAME);
...@@ -7682,6 +7735,8 @@ static const struct hnae3_ae_ops hclge_ops = { ...@@ -7682,6 +7735,8 @@ static const struct hnae3_ae_ops hclge_ops = {
.set_loopback = hclge_set_loopback, .set_loopback = hclge_set_loopback,
.start = hclge_ae_start, .start = hclge_ae_start,
.stop = hclge_ae_stop, .stop = hclge_ae_stop,
.client_start = hclge_client_start,
.client_stop = hclge_client_stop,
.get_status = hclge_get_status, .get_status = hclge_get_status,
.get_ksettings_an_result = hclge_get_ksettings_an_result, .get_ksettings_an_result = hclge_get_ksettings_an_result,
.update_speed_duplex_h = hclge_update_speed_duplex_h, .update_speed_duplex_h = hclge_update_speed_duplex_h,
......
...@@ -728,6 +728,11 @@ struct hclge_rss_tuple_cfg { ...@@ -728,6 +728,11 @@ struct hclge_rss_tuple_cfg {
u8 ipv6_fragment_en; u8 ipv6_fragment_en;
}; };
enum HCLGE_VPORT_STATE {
HCLGE_VPORT_STATE_ALIVE,
HCLGE_VPORT_STATE_MAX
};
struct hclge_vport { struct hclge_vport {
u16 alloc_tqps; /* Allocated Tx/Rx queues */ u16 alloc_tqps; /* Allocated Tx/Rx queues */
...@@ -753,6 +758,9 @@ struct hclge_vport { ...@@ -753,6 +758,9 @@ struct hclge_vport {
struct hclge_dev *back; /* Back reference to associated dev */ struct hclge_dev *back; /* Back reference to associated dev */
struct hnae3_handle nic; struct hnae3_handle nic;
struct hnae3_handle roce; struct hnae3_handle roce;
unsigned long state;
unsigned long last_active_jiffies;
}; };
void hclge_promisc_param_init(struct hclge_promisc_param *param, bool en_uc, void hclge_promisc_param_init(struct hclge_promisc_param *param, bool en_uc,
...@@ -800,4 +808,6 @@ int hclge_reset_tqp(struct hnae3_handle *handle, u16 queue_id); ...@@ -800,4 +808,6 @@ int hclge_reset_tqp(struct hnae3_handle *handle, u16 queue_id);
void hclge_reset_vf_queue(struct hclge_vport *vport, u16 queue_id); void hclge_reset_vf_queue(struct hclge_vport *vport, u16 queue_id);
int hclge_cfg_flowctrl(struct hclge_dev *hdev); int hclge_cfg_flowctrl(struct hclge_dev *hdev);
int hclge_func_reset_cmd(struct hclge_dev *hdev, int func_id); int hclge_func_reset_cmd(struct hclge_dev *hdev, int func_id);
int hclge_vport_start(struct hclge_vport *vport);
void hclge_vport_stop(struct hclge_vport *vport);
#endif #endif
...@@ -301,6 +301,21 @@ static int hclge_set_vf_vlan_cfg(struct hclge_vport *vport, ...@@ -301,6 +301,21 @@ static int hclge_set_vf_vlan_cfg(struct hclge_vport *vport,
return status; return status;
} }
static int hclge_set_vf_alive(struct hclge_vport *vport,
struct hclge_mbx_vf_to_pf_cmd *mbx_req,
bool gen_resp)
{
bool alive = !!mbx_req->msg[2];
int ret = 0;
if (alive)
ret = hclge_vport_start(vport);
else
hclge_vport_stop(vport);
return ret;
}
static int hclge_get_vf_tcinfo(struct hclge_vport *vport, static int hclge_get_vf_tcinfo(struct hclge_vport *vport,
struct hclge_mbx_vf_to_pf_cmd *mbx_req, struct hclge_mbx_vf_to_pf_cmd *mbx_req,
bool gen_resp) bool gen_resp)
...@@ -380,6 +395,12 @@ static void hclge_reset_vf(struct hclge_vport *vport, ...@@ -380,6 +395,12 @@ static void hclge_reset_vf(struct hclge_vport *vport,
hclge_gen_resp_to_vf(vport, mbx_req, ret, NULL, 0); hclge_gen_resp_to_vf(vport, mbx_req, ret, NULL, 0);
} }
static void hclge_vf_keep_alive(struct hclge_vport *vport,
struct hclge_mbx_vf_to_pf_cmd *mbx_req)
{
vport->last_active_jiffies = jiffies;
}
static bool hclge_cmd_crq_empty(struct hclge_hw *hw) static bool hclge_cmd_crq_empty(struct hclge_hw *hw)
{ {
u32 tail = hclge_read_dev(hw, HCLGE_NIC_CRQ_TAIL_REG); u32 tail = hclge_read_dev(hw, HCLGE_NIC_CRQ_TAIL_REG);
...@@ -457,6 +478,13 @@ void hclge_mbx_handler(struct hclge_dev *hdev) ...@@ -457,6 +478,13 @@ void hclge_mbx_handler(struct hclge_dev *hdev)
"PF failed(%d) to config VF's VLAN\n", "PF failed(%d) to config VF's VLAN\n",
ret); ret);
break; break;
case HCLGE_MBX_SET_ALIVE:
ret = hclge_set_vf_alive(vport, req, false);
if (ret)
dev_err(&hdev->pdev->dev,
"PF failed(%d) to set VF's ALIVE\n",
ret);
break;
case HCLGE_MBX_GET_QINFO: case HCLGE_MBX_GET_QINFO:
ret = hclge_get_vf_queue_info(vport, req, true); ret = hclge_get_vf_queue_info(vport, req, true);
if (ret) if (ret)
...@@ -484,6 +512,9 @@ void hclge_mbx_handler(struct hclge_dev *hdev) ...@@ -484,6 +512,9 @@ void hclge_mbx_handler(struct hclge_dev *hdev)
case HCLGE_MBX_RESET: case HCLGE_MBX_RESET:
hclge_reset_vf(vport, req); hclge_reset_vf(vport, req);
break; break;
case HCLGE_MBX_KEEP_ALIVE:
hclge_vf_keep_alive(vport, req);
break;
default: default:
dev_err(&hdev->pdev->dev, dev_err(&hdev->pdev->dev,
"un-supported mailbox message, code = %d\n", "un-supported mailbox message, code = %d\n",
......
...@@ -1515,6 +1515,28 @@ static void hclgevf_mailbox_service_task(struct work_struct *work) ...@@ -1515,6 +1515,28 @@ static void hclgevf_mailbox_service_task(struct work_struct *work)
clear_bit(HCLGEVF_STATE_MBX_HANDLING, &hdev->state); clear_bit(HCLGEVF_STATE_MBX_HANDLING, &hdev->state);
} }
static void hclgevf_keep_alive_timer(struct timer_list *t)
{
struct hclgevf_dev *hdev = from_timer(hdev, t, keep_alive_timer);
schedule_work(&hdev->keep_alive_task);
mod_timer(&hdev->keep_alive_timer, jiffies + 2 * HZ);
}
static void hclgevf_keep_alive_task(struct work_struct *work)
{
struct hclgevf_dev *hdev;
u8 respmsg;
int ret;
hdev = container_of(work, struct hclgevf_dev, keep_alive_task);
ret = hclgevf_send_mbx_msg(hdev, HCLGE_MBX_KEEP_ALIVE, 0, NULL,
0, false, &respmsg, sizeof(u8));
if (ret)
dev_err(&hdev->pdev->dev,
"VF sends keep alive cmd failed(=%d)\n", ret);
}
static void hclgevf_service_task(struct work_struct *work) static void hclgevf_service_task(struct work_struct *work)
{ {
struct hclgevf_dev *hdev; struct hclgevf_dev *hdev;
...@@ -1767,6 +1789,38 @@ static void hclgevf_ae_stop(struct hnae3_handle *handle) ...@@ -1767,6 +1789,38 @@ static void hclgevf_ae_stop(struct hnae3_handle *handle)
hclgevf_update_link_status(hdev, 0); hclgevf_update_link_status(hdev, 0);
} }
static int hclgevf_set_alive(struct hnae3_handle *handle, bool alive)
{
struct hclgevf_dev *hdev = hclgevf_ae_get_hdev(handle);
u8 msg_data;
msg_data = alive ? 1 : 0;
return hclgevf_send_mbx_msg(hdev, HCLGE_MBX_SET_ALIVE,
0, &msg_data, 1, false, NULL, 0);
}
static int hclgevf_client_start(struct hnae3_handle *handle)
{
struct hclgevf_dev *hdev = hclgevf_ae_get_hdev(handle);
mod_timer(&hdev->keep_alive_timer, jiffies + 2 * HZ);
return hclgevf_set_alive(handle, true);
}
static void hclgevf_client_stop(struct hnae3_handle *handle)
{
struct hclgevf_dev *hdev = hclgevf_ae_get_hdev(handle);
int ret;
ret = hclgevf_set_alive(handle, false);
if (ret)
dev_warn(&hdev->pdev->dev,
"%s failed %d\n", __func__, ret);
del_timer_sync(&hdev->keep_alive_timer);
cancel_work_sync(&hdev->keep_alive_task);
}
static void hclgevf_state_init(struct hclgevf_dev *hdev) static void hclgevf_state_init(struct hclgevf_dev *hdev)
{ {
/* setup tasks for the MBX */ /* setup tasks for the MBX */
...@@ -2279,6 +2333,7 @@ static void hclgevf_uninit_hdev(struct hclgevf_dev *hdev) ...@@ -2279,6 +2333,7 @@ static void hclgevf_uninit_hdev(struct hclgevf_dev *hdev)
static int hclgevf_init_ae_dev(struct hnae3_ae_dev *ae_dev) static int hclgevf_init_ae_dev(struct hnae3_ae_dev *ae_dev)
{ {
struct pci_dev *pdev = ae_dev->pdev; struct pci_dev *pdev = ae_dev->pdev;
struct hclgevf_dev *hdev;
int ret; int ret;
ret = hclgevf_alloc_hdev(ae_dev); ret = hclgevf_alloc_hdev(ae_dev);
...@@ -2288,10 +2343,16 @@ static int hclgevf_init_ae_dev(struct hnae3_ae_dev *ae_dev) ...@@ -2288,10 +2343,16 @@ static int hclgevf_init_ae_dev(struct hnae3_ae_dev *ae_dev)
} }
ret = hclgevf_init_hdev(ae_dev->priv); ret = hclgevf_init_hdev(ae_dev->priv);
if (ret) if (ret) {
dev_err(&pdev->dev, "hclge device initialization failed\n"); dev_err(&pdev->dev, "hclge device initialization failed\n");
return ret;
}
return ret; hdev = ae_dev->priv;
timer_setup(&hdev->keep_alive_timer, hclgevf_keep_alive_timer, 0);
INIT_WORK(&hdev->keep_alive_task, hclgevf_keep_alive_task);
return 0;
} }
static void hclgevf_uninit_ae_dev(struct hnae3_ae_dev *ae_dev) static void hclgevf_uninit_ae_dev(struct hnae3_ae_dev *ae_dev)
...@@ -2413,6 +2474,8 @@ static const struct hnae3_ae_ops hclgevf_ops = { ...@@ -2413,6 +2474,8 @@ static const struct hnae3_ae_ops hclgevf_ops = {
.uninit_client_instance = hclgevf_uninit_client_instance, .uninit_client_instance = hclgevf_uninit_client_instance,
.start = hclgevf_ae_start, .start = hclgevf_ae_start,
.stop = hclgevf_ae_stop, .stop = hclgevf_ae_stop,
.client_start = hclgevf_client_start,
.client_stop = hclgevf_client_stop,
.map_ring_to_vector = hclgevf_map_ring_to_vector, .map_ring_to_vector = hclgevf_map_ring_to_vector,
.unmap_ring_from_vector = hclgevf_unmap_ring_from_vector, .unmap_ring_from_vector = hclgevf_unmap_ring_from_vector,
.get_vector = hclgevf_get_vector, .get_vector = hclgevf_get_vector,
......
...@@ -201,7 +201,9 @@ struct hclgevf_dev { ...@@ -201,7 +201,9 @@ struct hclgevf_dev {
struct hclgevf_mbx_arq_ring arq; /* mailbox async rx queue */ struct hclgevf_mbx_arq_ring arq; /* mailbox async rx queue */
struct timer_list service_timer; struct timer_list service_timer;
struct timer_list keep_alive_timer;
struct work_struct service_task; struct work_struct service_task;
struct work_struct keep_alive_task;
struct work_struct rst_service_task; struct work_struct rst_service_task;
struct work_struct mbx_service_task; struct work_struct mbx_service_task;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册