Skip to content

Commit 887c382

Browse files
Salil Mehtadavem330
authored andcommitted
net: hns3: Updates MSI/MSI-X alloc/free APIs(depricated) to new APIs
This patch migrates the HNS3 driver code from use of depricated PCI MSI/MSI-X interrupt vector allocation/free APIs to new common APIs. Signed-off-by: Salil Mehta <[email protected]> Suggested-by: Christoph Hellwig <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 97438ab commit 887c382

File tree

2 files changed

+43
-81
lines changed

2 files changed

+43
-81
lines changed

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

Lines changed: 36 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -891,14 +891,14 @@ static int hclge_query_pf_resource(struct hclge_dev *hdev)
891891
hdev->pkt_buf_size = __le16_to_cpu(req->buf_size) << HCLGE_BUF_UNIT_S;
892892

893893
if (hnae3_dev_roce_supported(hdev)) {
894-
hdev->num_roce_msix =
894+
hdev->num_roce_msi =
895895
hnae_get_field(__le16_to_cpu(req->pf_intr_vector_number),
896896
HCLGE_PF_VEC_NUM_M, HCLGE_PF_VEC_NUM_S);
897897

898898
/* PF should have NIC vectors and Roce vectors,
899899
* NIC vectors are queued before Roce vectors.
900900
*/
901-
hdev->num_msi = hdev->num_roce_msix + HCLGE_ROCE_VECTOR_OFFSET;
901+
hdev->num_msi = hdev->num_roce_msi + HCLGE_ROCE_VECTOR_OFFSET;
902902
} else {
903903
hdev->num_msi =
904904
hnae_get_field(__le16_to_cpu(req->pf_intr_vector_number),
@@ -1950,7 +1950,7 @@ static int hclge_init_roce_base_info(struct hclge_vport *vport)
19501950
struct hnae3_handle *roce = &vport->roce;
19511951
struct hnae3_handle *nic = &vport->nic;
19521952

1953-
roce->rinfo.num_vectors = vport->back->num_roce_msix;
1953+
roce->rinfo.num_vectors = vport->back->num_roce_msi;
19541954

19551955
if (vport->back->num_msi_left < vport->roce.rinfo.num_vectors ||
19561956
vport->back->num_msi_left == 0)
@@ -1968,67 +1968,47 @@ static int hclge_init_roce_base_info(struct hclge_vport *vport)
19681968
return 0;
19691969
}
19701970

1971-
static int hclge_init_msix(struct hclge_dev *hdev)
1971+
static int hclge_init_msi(struct hclge_dev *hdev)
19721972
{
19731973
struct pci_dev *pdev = hdev->pdev;
1974-
int ret, i;
1975-
1976-
hdev->msix_entries = devm_kcalloc(&pdev->dev, hdev->num_msi,
1977-
sizeof(struct msix_entry),
1978-
GFP_KERNEL);
1979-
if (!hdev->msix_entries)
1980-
return -ENOMEM;
1981-
1982-
hdev->vector_status = devm_kcalloc(&pdev->dev, hdev->num_msi,
1983-
sizeof(u16), GFP_KERNEL);
1984-
if (!hdev->vector_status)
1985-
return -ENOMEM;
1974+
int vectors;
1975+
int i;
19861976

1987-
for (i = 0; i < hdev->num_msi; i++) {
1988-
hdev->msix_entries[i].entry = i;
1989-
hdev->vector_status[i] = HCLGE_INVALID_VPORT;
1977+
vectors = pci_alloc_irq_vectors(pdev, 1, hdev->num_msi,
1978+
PCI_IRQ_MSI | PCI_IRQ_MSIX);
1979+
if (vectors < 0) {
1980+
dev_err(&pdev->dev,
1981+
"failed(%d) to allocate MSI/MSI-X vectors\n",
1982+
vectors);
1983+
return vectors;
19901984
}
1985+
if (vectors < hdev->num_msi)
1986+
dev_warn(&hdev->pdev->dev,
1987+
"requested %d MSI/MSI-X, but allocated %d MSI/MSI-X\n",
1988+
hdev->num_msi, vectors);
19911989

1992-
hdev->num_msi_left = hdev->num_msi;
1993-
hdev->base_msi_vector = hdev->pdev->irq;
1990+
hdev->num_msi = vectors;
1991+
hdev->num_msi_left = vectors;
1992+
hdev->base_msi_vector = pdev->irq;
19941993
hdev->roce_base_vector = hdev->base_msi_vector +
19951994
HCLGE_ROCE_VECTOR_OFFSET;
19961995

1997-
ret = pci_enable_msix_range(hdev->pdev, hdev->msix_entries,
1998-
hdev->num_msi, hdev->num_msi);
1999-
if (ret < 0) {
2000-
dev_info(&hdev->pdev->dev,
2001-
"MSI-X vector alloc failed: %d\n", ret);
2002-
return ret;
2003-
}
2004-
2005-
return 0;
2006-
}
2007-
2008-
static int hclge_init_msi(struct hclge_dev *hdev)
2009-
{
2010-
struct pci_dev *pdev = hdev->pdev;
2011-
int vectors;
2012-
int i;
2013-
20141996
hdev->vector_status = devm_kcalloc(&pdev->dev, hdev->num_msi,
20151997
sizeof(u16), GFP_KERNEL);
2016-
if (!hdev->vector_status)
1998+
if (!hdev->vector_status) {
1999+
pci_free_irq_vectors(pdev);
20172000
return -ENOMEM;
2001+
}
20182002

20192003
for (i = 0; i < hdev->num_msi; i++)
20202004
hdev->vector_status[i] = HCLGE_INVALID_VPORT;
20212005

2022-
vectors = pci_alloc_irq_vectors(pdev, 1, hdev->num_msi, PCI_IRQ_MSI);
2023-
if (vectors < 0) {
2024-
dev_err(&pdev->dev, "MSI vectors enable failed %d\n", vectors);
2025-
return -EINVAL;
2006+
hdev->vector_irq = devm_kcalloc(&pdev->dev, hdev->num_msi,
2007+
sizeof(int), GFP_KERNEL);
2008+
if (!hdev->vector_irq) {
2009+
pci_free_irq_vectors(pdev);
2010+
return -ENOMEM;
20262011
}
2027-
hdev->num_msi = vectors;
2028-
hdev->num_msi_left = vectors;
2029-
hdev->base_msi_vector = pdev->irq;
2030-
hdev->roce_base_vector = hdev->base_msi_vector +
2031-
HCLGE_ROCE_VECTOR_OFFSET;
20322012

20332013
return 0;
20342014
}
@@ -2704,6 +2684,7 @@ static int hclge_get_vector(struct hnae3_handle *handle, u16 vector_num,
27042684
vport->vport_id *
27052685
HCLGE_VECTOR_VF_OFFSET;
27062686
hdev->vector_status[i] = vport->vport_id;
2687+
hdev->vector_irq[i] = vector->vector;
27072688

27082689
vector++;
27092690
alloc++;
@@ -2722,15 +2703,10 @@ static int hclge_get_vector_index(struct hclge_dev *hdev, int vector)
27222703
{
27232704
int i;
27242705

2725-
for (i = 0; i < hdev->num_msi; i++) {
2726-
if (hdev->msix_entries) {
2727-
if (vector == hdev->msix_entries[i].vector)
2728-
return i;
2729-
} else {
2730-
if (vector == (hdev->base_msi_vector + i))
2731-
return i;
2732-
}
2733-
}
2706+
for (i = 0; i < hdev->num_msi; i++)
2707+
if (vector == hdev->vector_irq[i])
2708+
return i;
2709+
27342710
return -EINVAL;
27352711
}
27362712

@@ -4664,14 +4640,7 @@ static void hclge_pci_uninit(struct hclge_dev *hdev)
46644640
{
46654641
struct pci_dev *pdev = hdev->pdev;
46664642

4667-
if (hdev->flag & HCLGE_FLAG_USE_MSIX) {
4668-
pci_disable_msix(pdev);
4669-
devm_kfree(&pdev->dev, hdev->msix_entries);
4670-
hdev->msix_entries = NULL;
4671-
} else {
4672-
pci_disable_msi(pdev);
4673-
}
4674-
4643+
pci_free_irq_vectors(pdev);
46754644
pci_clear_master(pdev);
46764645
pci_release_mem_regions(pdev);
46774646
pci_disable_device(pdev);
@@ -4689,7 +4658,6 @@ static int hclge_init_ae_dev(struct hnae3_ae_dev *ae_dev)
46894658
goto err_hclge_dev;
46904659
}
46914660

4692-
hdev->flag |= HCLGE_FLAG_USE_MSIX;
46934661
hdev->pdev = pdev;
46944662
hdev->ae_dev = ae_dev;
46954663
hdev->reset_type = HNAE3_NONE_RESET;
@@ -4726,12 +4694,9 @@ static int hclge_init_ae_dev(struct hnae3_ae_dev *ae_dev)
47264694
return ret;
47274695
}
47284696

4729-
if (hdev->flag & HCLGE_FLAG_USE_MSIX)
4730-
ret = hclge_init_msix(hdev);
4731-
else
4732-
ret = hclge_init_msi(hdev);
4697+
ret = hclge_init_msi(hdev);
47334698
if (ret) {
4734-
dev_err(&pdev->dev, "Init msix/msi error, ret = %d.\n", ret);
4699+
dev_err(&pdev->dev, "Init MSI/MSI-X error, ret = %d.\n", ret);
47354700
return ret;
47364701
}
47374702

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,6 @@ struct hclge_dev {
425425
u16 num_tqps; /* Num task queue pairs of this PF */
426426
u16 num_req_vfs; /* Num VFs requested for this PF */
427427

428-
u16 num_roce_msix; /* Num of roce vectors for this PF */
429-
int roce_base_vector;
430-
431428
/* Base task tqp physical id of this PF */
432429
u16 base_tqp_pid;
433430
u16 alloc_rss_size; /* Allocated RSS task queue */
@@ -457,8 +454,10 @@ struct hclge_dev {
457454
u16 num_msi_left;
458455
u16 num_msi_used;
459456
u32 base_msi_vector;
460-
struct msix_entry *msix_entries;
461457
u16 *vector_status;
458+
int *vector_irq;
459+
u16 num_roce_msi; /* Num of roce vectors for this PF */
460+
int roce_base_vector;
462461

463462
u16 pending_udp_bitmap;
464463

@@ -482,12 +481,10 @@ struct hclge_dev {
482481
struct hnae3_client *nic_client;
483482
struct hnae3_client *roce_client;
484483

485-
#define HCLGE_FLAG_USE_MSI 0x00000001
486-
#define HCLGE_FLAG_USE_MSIX 0x00000002
487-
#define HCLGE_FLAG_MAIN 0x00000004
488-
#define HCLGE_FLAG_DCB_CAPABLE 0x00000008
489-
#define HCLGE_FLAG_DCB_ENABLE 0x00000010
490-
#define HCLGE_FLAG_MQPRIO_ENABLE 0x00000020
484+
#define HCLGE_FLAG_MAIN BIT(0)
485+
#define HCLGE_FLAG_DCB_CAPABLE BIT(1)
486+
#define HCLGE_FLAG_DCB_ENABLE BIT(2)
487+
#define HCLGE_FLAG_MQPRIO_ENABLE BIT(3)
491488
u32 flag;
492489

493490
u32 pkt_buf_size; /* Total pf buf size for tx/rx */

0 commit comments

Comments
 (0)