Skip to content

Commit 3efb960

Browse files
321lipengdavem330
authored andcommitted
net: hns3: Refactor the initialization of command queue
There is no necessary to reallocate the descriptor and remap the descriptor memory in reset process, But there is still some other action exist in both reset process and initialization process. To reuse the common interface in reset process and initialization process, This patch moves out the descriptor allocate and memory maping from interface cmdq_init. Signed-off-by: qumingguang <[email protected]> Signed-off-by: Lipeng <[email protected]> Signed-off-by: Yunsheng Lin <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent cf9cca2 commit 3efb960

File tree

3 files changed

+33
-16
lines changed

3 files changed

+33
-16
lines changed

drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static void hclge_free_cmd_desc(struct hclge_cmq_ring *ring)
6262
ring->desc = NULL;
6363
}
6464

65-
static int hclge_init_cmd_queue(struct hclge_dev *hdev, int ring_type)
65+
static int hclge_alloc_cmd_queue(struct hclge_dev *hdev, int ring_type)
6666
{
6767
struct hclge_hw *hw = &hdev->hw;
6868
struct hclge_cmq_ring *ring =
@@ -79,9 +79,6 @@ static int hclge_init_cmd_queue(struct hclge_dev *hdev, int ring_type)
7979
return ret;
8080
}
8181

82-
ring->next_to_clean = 0;
83-
ring->next_to_use = 0;
84-
8582
return 0;
8683
}
8784

@@ -302,37 +299,52 @@ static enum hclge_cmd_status hclge_cmd_query_firmware_version(
302299
return ret;
303300
}
304301

305-
int hclge_cmd_init(struct hclge_dev *hdev)
302+
int hclge_cmd_queue_init(struct hclge_dev *hdev)
306303
{
307-
u32 version;
308304
int ret;
309305

310306
/* Setup the queue entries for use cmd queue */
311307
hdev->hw.cmq.csq.desc_num = HCLGE_NIC_CMQ_DESC_NUM;
312308
hdev->hw.cmq.crq.desc_num = HCLGE_NIC_CMQ_DESC_NUM;
313309

314-
/* Setup the lock for command queue */
315-
spin_lock_init(&hdev->hw.cmq.csq.lock);
316-
spin_lock_init(&hdev->hw.cmq.crq.lock);
317-
318310
/* Setup Tx write back timeout */
319311
hdev->hw.cmq.tx_timeout = HCLGE_CMDQ_TX_TIMEOUT;
320312

321313
/* Setup queue rings */
322-
ret = hclge_init_cmd_queue(hdev, HCLGE_TYPE_CSQ);
314+
ret = hclge_alloc_cmd_queue(hdev, HCLGE_TYPE_CSQ);
323315
if (ret) {
324316
dev_err(&hdev->pdev->dev,
325317
"CSQ ring setup error %d\n", ret);
326318
return ret;
327319
}
328320

329-
ret = hclge_init_cmd_queue(hdev, HCLGE_TYPE_CRQ);
321+
ret = hclge_alloc_cmd_queue(hdev, HCLGE_TYPE_CRQ);
330322
if (ret) {
331323
dev_err(&hdev->pdev->dev,
332324
"CRQ ring setup error %d\n", ret);
333325
goto err_csq;
334326
}
335327

328+
return 0;
329+
err_csq:
330+
hclge_free_cmd_desc(&hdev->hw.cmq.csq);
331+
return ret;
332+
}
333+
334+
int hclge_cmd_init(struct hclge_dev *hdev)
335+
{
336+
u32 version;
337+
int ret;
338+
339+
hdev->hw.cmq.csq.next_to_clean = 0;
340+
hdev->hw.cmq.csq.next_to_use = 0;
341+
hdev->hw.cmq.crq.next_to_clean = 0;
342+
hdev->hw.cmq.crq.next_to_use = 0;
343+
344+
/* Setup the lock for command queue */
345+
spin_lock_init(&hdev->hw.cmq.csq.lock);
346+
spin_lock_init(&hdev->hw.cmq.crq.lock);
347+
336348
hclge_cmd_init_regs(&hdev->hw);
337349

338350
ret = hclge_cmd_query_firmware_version(&hdev->hw, &version);
@@ -346,9 +358,6 @@ int hclge_cmd_init(struct hclge_dev *hdev)
346358
dev_info(&hdev->pdev->dev, "The firmware version is %08x\n", version);
347359

348360
return 0;
349-
err_csq:
350-
hclge_free_cmd_desc(&hdev->hw.cmq.csq);
351-
return ret;
352361
}
353362

354363
static void hclge_destroy_queue(struct hclge_cmq_ring *ring)

drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,4 +750,5 @@ enum hclge_cmd_status hclge_cmd_mdio_read(struct hclge_hw *hw,
750750
struct hclge_desc *desc);
751751

752752
void hclge_destroy_cmd_queue(struct hclge_hw *hw);
753+
int hclge_cmd_queue_init(struct hclge_dev *hdev);
753754
#endif

drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4446,7 +4446,14 @@ static int hclge_init_ae_dev(struct hnae3_ae_dev *ae_dev)
44464446
goto err_pci_init;
44474447
}
44484448

4449-
/* Command queue initialize */
4449+
/* Firmware command queue initialize */
4450+
ret = hclge_cmd_queue_init(hdev);
4451+
if (ret) {
4452+
dev_err(&pdev->dev, "Cmd queue init failed, ret = %d.\n", ret);
4453+
return ret;
4454+
}
4455+
4456+
/* Firmware command initialize */
44504457
ret = hclge_cmd_init(hdev);
44514458
if (ret)
44524459
goto err_cmd_init;

0 commit comments

Comments
 (0)