Skip to content

Commit 9970308

Browse files
Jie Wangdavem330
authored andcommitted
net: hns3: refactor hclge_comm_send function in PF/VF drivers
Currently, there are two different sets of special command codes in PF and VF cmdq modules, this is because VF driver only uses small part of all the command codes. In other words, these not used command codes in VF are also sepcial command codes theoretically. So this patch unifes the special command codes and deletes the bool param is_pf of hclge_comm_send. All the related functions are refactored according to the new hclge_comm_send function prototype. Signed-off-by: Jie Wang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 9667b81 commit 9970308

File tree

4 files changed

+38
-53
lines changed

4 files changed

+38
-53
lines changed

drivers/net/ethernet/hisilicon/hns3/hns3_common/hclge_comm_cmd.c

Lines changed: 29 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void hclge_comm_cmd_setup_basic_desc(struct hclge_desc *desc,
7373
desc->flag |= cpu_to_le16(HCLGE_COMM_CMD_FLAG_WR);
7474
}
7575

76-
int hclge_comm_firmware_compat_config(struct hnae3_ae_dev *ae_dev, bool is_pf,
76+
int hclge_comm_firmware_compat_config(struct hnae3_ae_dev *ae_dev,
7777
struct hclge_comm_hw *hw, bool en)
7878
{
7979
struct hclge_comm_firmware_compat_cmd *req;
@@ -96,7 +96,7 @@ int hclge_comm_firmware_compat_config(struct hnae3_ae_dev *ae_dev, bool is_pf,
9696
req->compat = cpu_to_le32(compat);
9797
}
9898

99-
return hclge_comm_cmd_send(hw, &desc, 1, is_pf);
99+
return hclge_comm_cmd_send(hw, &desc, 1);
100100
}
101101

102102
void hclge_comm_free_cmd_desc(struct hclge_comm_cmq_ring *ring)
@@ -209,7 +209,7 @@ int hclge_comm_cmd_query_version_and_capability(struct hnae3_ae_dev *ae_dev,
209209
resp = (struct hclge_comm_query_version_cmd *)desc.data;
210210
resp->api_caps = hclge_comm_build_api_caps();
211211

212-
ret = hclge_comm_cmd_send(hw, &desc, 1, is_pf);
212+
ret = hclge_comm_cmd_send(hw, &desc, 1);
213213
if (ret)
214214
return ret;
215215

@@ -227,46 +227,32 @@ int hclge_comm_cmd_query_version_and_capability(struct hnae3_ae_dev *ae_dev,
227227
return ret;
228228
}
229229

230-
static bool hclge_is_elem_in_array(const u16 *spec_opcode, u32 size, u16 opcode)
230+
static const u16 spec_opcode[] = { HCLGE_COMM_OPC_STATS_64_BIT,
231+
HCLGE_COMM_OPC_STATS_32_BIT,
232+
HCLGE_COMM_OPC_STATS_MAC,
233+
HCLGE_COMM_OPC_STATS_MAC_ALL,
234+
HCLGE_COMM_OPC_QUERY_32_BIT_REG,
235+
HCLGE_COMM_OPC_QUERY_64_BIT_REG,
236+
HCLGE_COMM_QUERY_CLEAR_MPF_RAS_INT,
237+
HCLGE_COMM_QUERY_CLEAR_PF_RAS_INT,
238+
HCLGE_COMM_QUERY_CLEAR_ALL_MPF_MSIX_INT,
239+
HCLGE_COMM_QUERY_CLEAR_ALL_PF_MSIX_INT,
240+
HCLGE_COMM_QUERY_ALL_ERR_INFO };
241+
242+
static bool hclge_comm_is_special_opcode(u16 opcode)
231243
{
244+
/* these commands have several descriptors,
245+
* and use the first one to save opcode and return value
246+
*/
232247
u32 i;
233248

234-
for (i = 0; i < size; i++) {
249+
for (i = 0; i < ARRAY_SIZE(spec_opcode); i++)
235250
if (spec_opcode[i] == opcode)
236251
return true;
237-
}
238252

239253
return false;
240254
}
241255

242-
static const u16 pf_spec_opcode[] = { HCLGE_COMM_OPC_STATS_64_BIT,
243-
HCLGE_COMM_OPC_STATS_32_BIT,
244-
HCLGE_COMM_OPC_STATS_MAC,
245-
HCLGE_COMM_OPC_STATS_MAC_ALL,
246-
HCLGE_COMM_OPC_QUERY_32_BIT_REG,
247-
HCLGE_COMM_OPC_QUERY_64_BIT_REG,
248-
HCLGE_COMM_QUERY_CLEAR_MPF_RAS_INT,
249-
HCLGE_COMM_QUERY_CLEAR_PF_RAS_INT,
250-
HCLGE_COMM_QUERY_CLEAR_ALL_MPF_MSIX_INT,
251-
HCLGE_COMM_QUERY_CLEAR_ALL_PF_MSIX_INT,
252-
HCLGE_COMM_QUERY_ALL_ERR_INFO };
253-
254-
static const u16 vf_spec_opcode[] = { HCLGE_COMM_OPC_STATS_64_BIT,
255-
HCLGE_COMM_OPC_STATS_32_BIT,
256-
HCLGE_COMM_OPC_STATS_MAC };
257-
258-
static bool hclge_comm_is_special_opcode(u16 opcode, bool is_pf)
259-
{
260-
/* these commands have several descriptors,
261-
* and use the first one to save opcode and return value
262-
*/
263-
const u16 *spec_opcode = is_pf ? pf_spec_opcode : vf_spec_opcode;
264-
u32 size = is_pf ? ARRAY_SIZE(pf_spec_opcode) :
265-
ARRAY_SIZE(vf_spec_opcode);
266-
267-
return hclge_is_elem_in_array(spec_opcode, size, opcode);
268-
}
269-
270256
static int hclge_comm_ring_space(struct hclge_comm_cmq_ring *ring)
271257
{
272258
int ntc = ring->next_to_clean;
@@ -378,7 +364,7 @@ static int hclge_comm_cmd_convert_err_code(u16 desc_ret)
378364

379365
static int hclge_comm_cmd_check_retval(struct hclge_comm_hw *hw,
380366
struct hclge_desc *desc, int num,
381-
int ntc, bool is_pf)
367+
int ntc)
382368
{
383369
u16 opcode, desc_ret;
384370
int handle;
@@ -390,7 +376,7 @@ static int hclge_comm_cmd_check_retval(struct hclge_comm_hw *hw,
390376
if (ntc >= hw->cmq.csq.desc_num)
391377
ntc = 0;
392378
}
393-
if (likely(!hclge_comm_is_special_opcode(opcode, is_pf)))
379+
if (likely(!hclge_comm_is_special_opcode(opcode)))
394380
desc_ret = le16_to_cpu(desc[num - 1].retval);
395381
else
396382
desc_ret = le16_to_cpu(desc[0].retval);
@@ -402,7 +388,7 @@ static int hclge_comm_cmd_check_retval(struct hclge_comm_hw *hw,
402388

403389
static int hclge_comm_cmd_check_result(struct hclge_comm_hw *hw,
404390
struct hclge_desc *desc,
405-
int num, int ntc, bool is_pf)
391+
int num, int ntc)
406392
{
407393
bool is_completed = false;
408394
int handle, ret;
@@ -416,7 +402,7 @@ static int hclge_comm_cmd_check_result(struct hclge_comm_hw *hw,
416402
if (!is_completed)
417403
ret = -EBADE;
418404
else
419-
ret = hclge_comm_cmd_check_retval(hw, desc, num, ntc, is_pf);
405+
ret = hclge_comm_cmd_check_retval(hw, desc, num, ntc);
420406

421407
/* Clean the command send queue */
422408
handle = hclge_comm_cmd_csq_clean(hw);
@@ -433,13 +419,12 @@ static int hclge_comm_cmd_check_result(struct hclge_comm_hw *hw,
433419
* @hw: pointer to the hw struct
434420
* @desc: prefilled descriptor for describing the command
435421
* @num : the number of descriptors to be sent
436-
* @is_pf: bool to judge pf/vf module
437422
*
438423
* This is the main send command for command queue, it
439424
* sends the queue, cleans the queue, etc
440425
**/
441426
int hclge_comm_cmd_send(struct hclge_comm_hw *hw, struct hclge_desc *desc,
442-
int num, bool is_pf)
427+
int num)
443428
{
444429
struct hclge_comm_cmq_ring *csq = &hw->cmq.csq;
445430
int ret;
@@ -474,7 +459,7 @@ int hclge_comm_cmd_send(struct hclge_comm_hw *hw, struct hclge_desc *desc,
474459
hclge_comm_write_dev(hw, HCLGE_COMM_NIC_CSQ_TAIL_REG,
475460
hw->cmq.csq.next_to_use);
476461

477-
ret = hclge_comm_cmd_check_result(hw, desc, num, ntc, is_pf);
462+
ret = hclge_comm_cmd_check_result(hw, desc, num, ntc);
478463

479464
spin_unlock_bh(&hw->cmq.csq.lock);
480465

@@ -495,12 +480,12 @@ static void hclge_comm_cmd_uninit_regs(struct hclge_comm_hw *hw)
495480
hclge_comm_write_dev(hw, HCLGE_COMM_NIC_CRQ_TAIL_REG, 0);
496481
}
497482

498-
void hclge_comm_cmd_uninit(struct hnae3_ae_dev *ae_dev, bool is_pf,
483+
void hclge_comm_cmd_uninit(struct hnae3_ae_dev *ae_dev,
499484
struct hclge_comm_hw *hw)
500485
{
501486
struct hclge_comm_cmq *cmdq = &hw->cmq;
502487

503-
hclge_comm_firmware_compat_config(ae_dev, is_pf, hw, false);
488+
hclge_comm_firmware_compat_config(ae_dev, hw, false);
504489
set_bit(HCLGE_COMM_STATE_CMD_DISABLE, &hw->comm_state);
505490

506491
/* wait to ensure that the firmware completes the possible left
@@ -612,7 +597,7 @@ int hclge_comm_cmd_init(struct hnae3_ae_dev *ae_dev, struct hclge_comm_hw *hw,
612597
/* ask the firmware to enable some features, driver can work without
613598
* it.
614599
*/
615-
ret = hclge_comm_firmware_compat_config(ae_dev, is_pf, hw, true);
600+
ret = hclge_comm_firmware_compat_config(ae_dev, hw, true);
616601
if (ret)
617602
dev_warn(&ae_dev->pdev->dev,
618603
"Firmware compatible features not enabled(%d).\n",

drivers/net/ethernet/hisilicon/hns3/hns3_common/hclge_comm_cmd.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,15 @@ int hclge_comm_cmd_query_version_and_capability(struct hnae3_ae_dev *ae_dev,
209209
u32 *fw_version, bool is_pf);
210210
int hclge_comm_alloc_cmd_queue(struct hclge_comm_hw *hw, int ring_type);
211211
int hclge_comm_cmd_send(struct hclge_comm_hw *hw, struct hclge_desc *desc,
212-
int num, bool is_pf);
212+
int num);
213213
void hclge_comm_cmd_reuse_desc(struct hclge_desc *desc, bool is_read);
214-
int hclge_comm_firmware_compat_config(struct hnae3_ae_dev *ae_dev, bool is_pf,
214+
int hclge_comm_firmware_compat_config(struct hnae3_ae_dev *ae_dev,
215215
struct hclge_comm_hw *hw, bool en);
216216
void hclge_comm_free_cmd_desc(struct hclge_comm_cmq_ring *ring);
217217
void hclge_comm_cmd_setup_basic_desc(struct hclge_desc *desc,
218218
enum hclge_comm_opcode_type opcode,
219219
bool is_read);
220-
void hclge_comm_cmd_uninit(struct hnae3_ae_dev *ae_dev, bool is_pf,
220+
void hclge_comm_cmd_uninit(struct hnae3_ae_dev *ae_dev,
221221
struct hclge_comm_hw *hw);
222222
int hclge_comm_cmd_queue_init(struct pci_dev *pdev, struct hclge_comm_hw *hw);
223223
int hclge_comm_cmd_init(struct hnae3_ae_dev *ae_dev, struct hclge_comm_hw *hw,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ static const struct key_info tuple_key_info[] = {
490490
**/
491491
int hclge_cmd_send(struct hclge_hw *hw, struct hclge_desc *desc, int num)
492492
{
493-
return hclge_comm_cmd_send(&hw->hw, desc, num, true);
493+
return hclge_comm_cmd_send(&hw->hw, desc, num);
494494
}
495495

496496
static int hclge_mac_update_stats_defective(struct hclge_dev *hdev)
@@ -11968,7 +11968,7 @@ static int hclge_init_ae_dev(struct hnae3_ae_dev *ae_dev)
1196811968
err_msi_uninit:
1196911969
pci_free_irq_vectors(pdev);
1197011970
err_cmd_uninit:
11971-
hclge_comm_cmd_uninit(hdev->ae_dev, true, &hdev->hw.hw);
11971+
hclge_comm_cmd_uninit(hdev->ae_dev, &hdev->hw.hw);
1197211972
err_devlink_uninit:
1197311973
hclge_devlink_uninit(hdev);
1197411974
err_pci_uninit:
@@ -12360,7 +12360,7 @@ static void hclge_uninit_ae_dev(struct hnae3_ae_dev *ae_dev)
1236012360
hclge_config_nic_hw_error(hdev, false);
1236112361
hclge_config_rocee_ras_interrupt(hdev, false);
1236212362

12363-
hclge_comm_cmd_uninit(hdev->ae_dev, true, &hdev->hw.hw);
12363+
hclge_comm_cmd_uninit(hdev->ae_dev, &hdev->hw.hw);
1236412364
hclge_misc_irq_uninit(hdev);
1236512365
hclge_devlink_uninit(hdev);
1236612366
hclge_pci_uninit(hdev);

drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ static const u32 tqp_intr_reg_addr_list[] = {HCLGEVF_TQP_INTR_CTRL_REG,
102102
*/
103103
int hclgevf_cmd_send(struct hclgevf_hw *hw, struct hclge_desc *desc, int num)
104104
{
105-
return hclge_comm_cmd_send(&hw->hw, desc, num, false);
105+
return hclge_comm_cmd_send(&hw->hw, desc, num);
106106
}
107107

108108
void hclgevf_arq_init(struct hclgevf_dev *hdev)
@@ -3498,7 +3498,7 @@ static int hclgevf_init_hdev(struct hclgevf_dev *hdev)
34983498
hclgevf_state_uninit(hdev);
34993499
hclgevf_uninit_msi(hdev);
35003500
err_cmd_init:
3501-
hclge_comm_cmd_uninit(hdev->ae_dev, false, &hdev->hw.hw);
3501+
hclge_comm_cmd_uninit(hdev->ae_dev, &hdev->hw.hw);
35023502
err_cmd_queue_init:
35033503
hclgevf_devlink_uninit(hdev);
35043504
err_devlink_init:
@@ -3522,7 +3522,7 @@ static void hclgevf_uninit_hdev(struct hclgevf_dev *hdev)
35223522
hclgevf_uninit_msi(hdev);
35233523
}
35243524

3525-
hclge_comm_cmd_uninit(hdev->ae_dev, false, &hdev->hw.hw);
3525+
hclge_comm_cmd_uninit(hdev->ae_dev, &hdev->hw.hw);
35263526
hclgevf_devlink_uninit(hdev);
35273527
hclgevf_pci_uninit(hdev);
35283528
hclgevf_uninit_mac_list(hdev);

0 commit comments

Comments
 (0)