aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSalil Mehta <salil.mehta@huawei.com>2018-03-22 10:28:57 -0400
committerDavid S. Miller <davem@davemloft.net>2018-03-22 15:29:04 -0400
commit7a01c89723301c343f75862098e4fa0885b75b3b (patch)
treed6e8b3a76fabbe365d4dfcc6347b963114b38747
parent6988eb2a9b7772d57b1d09bdf769db4c697869ea (diff)
net: hns3: Add support to re-initialize the hclge device
After the hardware reset we should re-fetch the configuration from PF like queue info and tc info. This might have impact on allocations made like that of TQPs. Hence, we should release all such allocations and re-allocate fresh according to new fetched configuration after reset. Signed-off-by: Salil Mehta <salil.mehta@huawei.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c106
-rw-r--r--drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.h14
2 files changed, 106 insertions, 14 deletions
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
index bd45b1117446..6dd75614cc67 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
@@ -10,6 +10,8 @@
10 10
11#define HCLGEVF_NAME "hclgevf" 11#define HCLGEVF_NAME "hclgevf"
12 12
13static int hclgevf_init_hdev(struct hclgevf_dev *hdev);
14static void hclgevf_uninit_hdev(struct hclgevf_dev *hdev);
13static struct hnae3_ae_algo ae_algovf; 15static struct hnae3_ae_algo ae_algovf;
14 16
15static const struct pci_device_id ae_algovf_pci_tbl[] = { 17static const struct pci_device_id ae_algovf_pci_tbl[] = {
@@ -209,6 +211,12 @@ static int hclgevf_alloc_tqps(struct hclgevf_dev *hdev)
209 struct hclgevf_tqp *tqp; 211 struct hclgevf_tqp *tqp;
210 int i; 212 int i;
211 213
214 /* if this is on going reset then we need to re-allocate the TPQs
215 * since we cannot assume we would get same number of TPQs back from PF
216 */
217 if (hclgevf_dev_ongoing_reset(hdev))
218 devm_kfree(&hdev->pdev->dev, hdev->htqp);
219
212 hdev->htqp = devm_kcalloc(&hdev->pdev->dev, hdev->num_tqps, 220 hdev->htqp = devm_kcalloc(&hdev->pdev->dev, hdev->num_tqps,
213 sizeof(struct hclgevf_tqp), GFP_KERNEL); 221 sizeof(struct hclgevf_tqp), GFP_KERNEL);
214 if (!hdev->htqp) 222 if (!hdev->htqp)
@@ -252,6 +260,12 @@ static int hclgevf_knic_setup(struct hclgevf_dev *hdev)
252 new_tqps = kinfo->rss_size * kinfo->num_tc; 260 new_tqps = kinfo->rss_size * kinfo->num_tc;
253 kinfo->num_tqps = min(new_tqps, hdev->num_tqps); 261 kinfo->num_tqps = min(new_tqps, hdev->num_tqps);
254 262
263 /* if this is on going reset then we need to re-allocate the hnae queues
264 * as well since number of TPQs from PF might have changed.
265 */
266 if (hclgevf_dev_ongoing_reset(hdev))
267 devm_kfree(&hdev->pdev->dev, kinfo->tqp);
268
255 kinfo->tqp = devm_kcalloc(&hdev->pdev->dev, kinfo->num_tqps, 269 kinfo->tqp = devm_kcalloc(&hdev->pdev->dev, kinfo->num_tqps,
256 sizeof(struct hnae3_queue *), GFP_KERNEL); 270 sizeof(struct hnae3_queue *), GFP_KERNEL);
257 if (!kinfo->tqp) 271 if (!kinfo->tqp)
@@ -878,10 +892,18 @@ static int hclgevf_reset_wait(struct hclgevf_dev *hdev)
878 892
879static int hclgevf_reset_stack(struct hclgevf_dev *hdev) 893static int hclgevf_reset_stack(struct hclgevf_dev *hdev)
880{ 894{
895 int ret;
896
881 /* uninitialize the nic client */ 897 /* uninitialize the nic client */
882 hclgevf_notify_client(hdev, HNAE3_UNINIT_CLIENT); 898 hclgevf_notify_client(hdev, HNAE3_UNINIT_CLIENT);
883 899
884 /* re-initialize the hclge device - add code here */ 900 /* re-initialize the hclge device */
901 ret = hclgevf_init_hdev(hdev);
902 if (ret) {
903 dev_err(&hdev->pdev->dev,
904 "hclge device re-init failed, VF is disabled!\n");
905 return ret;
906 }
885 907
886 /* bring up the nic client again */ 908 /* bring up the nic client again */
887 hclgevf_notify_client(hdev, HNAE3_INIT_CLIENT); 909 hclgevf_notify_client(hdev, HNAE3_INIT_CLIENT);
@@ -1179,6 +1201,22 @@ static int hclgevf_configure(struct hclgevf_dev *hdev)
1179 return hclgevf_get_tc_info(hdev); 1201 return hclgevf_get_tc_info(hdev);
1180} 1202}
1181 1203
1204static int hclgevf_alloc_hdev(struct hnae3_ae_dev *ae_dev)
1205{
1206 struct pci_dev *pdev = ae_dev->pdev;
1207 struct hclgevf_dev *hdev = ae_dev->priv;
1208
1209 hdev = devm_kzalloc(&pdev->dev, sizeof(*hdev), GFP_KERNEL);
1210 if (!hdev)
1211 return -ENOMEM;
1212
1213 hdev->pdev = pdev;
1214 hdev->ae_dev = ae_dev;
1215 ae_dev->priv = hdev;
1216
1217 return 0;
1218}
1219
1182static int hclgevf_init_roce_base_info(struct hclgevf_dev *hdev) 1220static int hclgevf_init_roce_base_info(struct hclgevf_dev *hdev)
1183{ 1221{
1184 struct hnae3_handle *roce = &hdev->roce; 1222 struct hnae3_handle *roce = &hdev->roce;
@@ -1284,6 +1322,10 @@ static void hclgevf_ae_stop(struct hnae3_handle *handle)
1284 1322
1285static void hclgevf_state_init(struct hclgevf_dev *hdev) 1323static void hclgevf_state_init(struct hclgevf_dev *hdev)
1286{ 1324{
1325 /* if this is on going reset then skip this initialization */
1326 if (hclgevf_dev_ongoing_reset(hdev))
1327 return;
1328
1287 /* setup tasks for the MBX */ 1329 /* setup tasks for the MBX */
1288 INIT_WORK(&hdev->mbx_service_task, hclgevf_mailbox_service_task); 1330 INIT_WORK(&hdev->mbx_service_task, hclgevf_mailbox_service_task);
1289 clear_bit(HCLGEVF_STATE_MBX_SERVICE_SCHED, &hdev->state); 1331 clear_bit(HCLGEVF_STATE_MBX_SERVICE_SCHED, &hdev->state);
@@ -1325,6 +1367,10 @@ static int hclgevf_init_msi(struct hclgevf_dev *hdev)
1325 int vectors; 1367 int vectors;
1326 int i; 1368 int i;
1327 1369
1370 /* if this is on going reset then skip this initialization */
1371 if (hclgevf_dev_ongoing_reset(hdev))
1372 return 0;
1373
1328 hdev->num_msi = HCLGEVF_MAX_VF_VECTOR_NUM; 1374 hdev->num_msi = HCLGEVF_MAX_VF_VECTOR_NUM;
1329 1375
1330 vectors = pci_alloc_irq_vectors(pdev, 1, hdev->num_msi, 1376 vectors = pci_alloc_irq_vectors(pdev, 1, hdev->num_msi,
@@ -1375,6 +1421,10 @@ static int hclgevf_misc_irq_init(struct hclgevf_dev *hdev)
1375{ 1421{
1376 int ret = 0; 1422 int ret = 0;
1377 1423
1424 /* if this is on going reset then skip this initialization */
1425 if (hclgevf_dev_ongoing_reset(hdev))
1426 return 0;
1427
1378 hclgevf_get_misc_vector(hdev); 1428 hclgevf_get_misc_vector(hdev);
1379 1429
1380 ret = request_irq(hdev->misc_vector.vector_irq, hclgevf_misc_irq_handle, 1430 ret = request_irq(hdev->misc_vector.vector_irq, hclgevf_misc_irq_handle,
@@ -1485,6 +1535,14 @@ static int hclgevf_pci_init(struct hclgevf_dev *hdev)
1485 struct hclgevf_hw *hw; 1535 struct hclgevf_hw *hw;
1486 int ret; 1536 int ret;
1487 1537
1538 /* check if we need to skip initialization of pci. This will happen if
1539 * device is undergoing VF reset. Otherwise, we would need to
1540 * re-initialize pci interface again i.e. when device is not going
1541 * through *any* reset or actually undergoing full reset.
1542 */
1543 if (hclgevf_dev_ongoing_reset(hdev))
1544 return 0;
1545
1488 ret = pci_enable_device(pdev); 1546 ret = pci_enable_device(pdev);
1489 if (ret) { 1547 if (ret) {
1490 dev_err(&pdev->dev, "failed to enable PCI device\n"); 1548 dev_err(&pdev->dev, "failed to enable PCI device\n");
@@ -1536,19 +1594,16 @@ static void hclgevf_pci_uninit(struct hclgevf_dev *hdev)
1536 pci_set_drvdata(pdev, NULL); 1594 pci_set_drvdata(pdev, NULL);
1537} 1595}
1538 1596
1539static int hclgevf_init_ae_dev(struct hnae3_ae_dev *ae_dev) 1597static int hclgevf_init_hdev(struct hclgevf_dev *hdev)
1540{ 1598{
1541 struct pci_dev *pdev = ae_dev->pdev; 1599 struct pci_dev *pdev = hdev->pdev;
1542 struct hclgevf_dev *hdev;
1543 int ret; 1600 int ret;
1544 1601
1545 hdev = devm_kzalloc(&pdev->dev, sizeof(*hdev), GFP_KERNEL); 1602 /* check if device is on-going full reset(i.e. pcie as well) */
1546 if (!hdev) 1603 if (hclgevf_dev_ongoing_full_reset(hdev)) {
1547 return -ENOMEM; 1604 dev_warn(&pdev->dev, "device is going full reset\n");
1548 1605 hclgevf_uninit_hdev(hdev);
1549 hdev->pdev = pdev; 1606 }
1550 hdev->ae_dev = ae_dev;
1551 ae_dev->priv = hdev;
1552 1607
1553 ret = hclgevf_pci_init(hdev); 1608 ret = hclgevf_pci_init(hdev);
1554 if (ret) { 1609 if (ret) {
@@ -1633,15 +1688,38 @@ err_irq_init:
1633 return ret; 1688 return ret;
1634} 1689}
1635 1690
1636static void hclgevf_uninit_ae_dev(struct hnae3_ae_dev *ae_dev) 1691static void hclgevf_uninit_hdev(struct hclgevf_dev *hdev)
1637{ 1692{
1638 struct hclgevf_dev *hdev = ae_dev->priv;
1639
1640 hclgevf_cmd_uninit(hdev); 1693 hclgevf_cmd_uninit(hdev);
1641 hclgevf_misc_irq_uninit(hdev); 1694 hclgevf_misc_irq_uninit(hdev);
1642 hclgevf_state_uninit(hdev); 1695 hclgevf_state_uninit(hdev);
1643 hclgevf_uninit_msi(hdev); 1696 hclgevf_uninit_msi(hdev);
1644 hclgevf_pci_uninit(hdev); 1697 hclgevf_pci_uninit(hdev);
1698}
1699
1700static int hclgevf_init_ae_dev(struct hnae3_ae_dev *ae_dev)
1701{
1702 struct pci_dev *pdev = ae_dev->pdev;
1703 int ret;
1704
1705 ret = hclgevf_alloc_hdev(ae_dev);
1706 if (ret) {
1707 dev_err(&pdev->dev, "hclge device allocation failed\n");
1708 return ret;
1709 }
1710
1711 ret = hclgevf_init_hdev(ae_dev->priv);
1712 if (ret)
1713 dev_err(&pdev->dev, "hclge device initialization failed\n");
1714
1715 return ret;
1716}
1717
1718static void hclgevf_uninit_ae_dev(struct hnae3_ae_dev *ae_dev)
1719{
1720 struct hclgevf_dev *hdev = ae_dev->priv;
1721
1722 hclgevf_uninit_hdev(hdev);
1645 ae_dev->priv = NULL; 1723 ae_dev->priv = NULL;
1646} 1724}
1647 1725
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.h b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.h
index afdb15d54f03..8cdc6027671f 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.h
@@ -169,6 +169,20 @@ struct hclgevf_dev {
169 u32 flag; 169 u32 flag;
170}; 170};
171 171
172static inline bool hclgevf_dev_ongoing_reset(struct hclgevf_dev *hdev)
173{
174 return (hdev &&
175 (test_bit(HCLGEVF_STATE_RST_HANDLING, &hdev->state)) &&
176 (hdev->nic.reset_level == HNAE3_VF_RESET));
177}
178
179static inline bool hclgevf_dev_ongoing_full_reset(struct hclgevf_dev *hdev)
180{
181 return (hdev &&
182 (test_bit(HCLGEVF_STATE_RST_HANDLING, &hdev->state)) &&
183 (hdev->nic.reset_level == HNAE3_VF_FULL_RESET));
184}
185
172int hclgevf_send_mbx_msg(struct hclgevf_dev *hdev, u16 code, u16 subcode, 186int hclgevf_send_mbx_msg(struct hclgevf_dev *hdev, u16 code, u16 subcode,
173 const u8 *msg_data, u8 msg_len, bool need_resp, 187 const u8 *msg_data, u8 msg_len, bool need_resp,
174 u8 *resp_data, u16 resp_len); 188 u8 *resp_data, u16 resp_len);