Skip to content

Commit 016a005

Browse files
xavierhwdledford
authored andcommitted
RDMA/hns: Move priv in order to add multiple hns_roce support
Move the data member called priv from hns_roce_hw to hns_roce_dev structure in order to support multiple hns_roce devices in one system at the same time. For example, there are two hip06 engines in the system. Signed-off-by: Lijun Ou <[email protected]> Signed-off-by: Shaobo Xu <[email protected]> Signed-off-by: Wei Hu (Xavier) <[email protected]> Signed-off-by: Doug Ledford <[email protected]>
1 parent 08805fd commit 016a005

File tree

2 files changed

+35
-28
lines changed

2 files changed

+35
-28
lines changed

drivers/infiniband/hw/hns/hns_roce_device.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,6 @@ struct hns_roce_hw {
535535
int (*poll_cq)(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc);
536536
int (*dereg_mr)(struct hns_roce_dev *hr_dev, struct hns_roce_mr *mr);
537537
int (*destroy_cq)(struct ib_cq *ibcq);
538-
void *priv;
539538
};
540539

541540
struct hns_roce_dev {
@@ -572,6 +571,7 @@ struct hns_roce_dev {
572571
dma_addr_t tptr_dma_addr; /*only for hw v1*/
573572
u32 tptr_size; /*only for hw v1*/
574573
const struct hns_roce_hw *hw;
574+
void *priv;
575575
};
576576

577577
static inline struct hns_roce_dev *to_hr_dev(struct ib_device *ib_dev)

drivers/infiniband/hw/hns/hns_roce_hw_v1.c

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ static void hns_roce_set_sdb_ext(struct hns_roce_dev *hr_dev, u32 ext_sdb_alept,
473473
dma_addr_t sdb_dma_addr;
474474
u32 val;
475475

476-
priv = (struct hns_roce_v1_priv *)hr_dev->hw->priv;
476+
priv = (struct hns_roce_v1_priv *)hr_dev->priv;
477477
db = &priv->db_table;
478478

479479
/* Configure extend SDB threshold */
@@ -512,7 +512,7 @@ static void hns_roce_set_odb_ext(struct hns_roce_dev *hr_dev, u32 ext_odb_alept,
512512
dma_addr_t odb_dma_addr;
513513
u32 val;
514514

515-
priv = (struct hns_roce_v1_priv *)hr_dev->hw->priv;
515+
priv = (struct hns_roce_v1_priv *)hr_dev->priv;
516516
db = &priv->db_table;
517517

518518
/* Configure extend ODB threshold */
@@ -548,7 +548,7 @@ static int hns_roce_db_ext_init(struct hns_roce_dev *hr_dev, u32 sdb_ext_mod,
548548
dma_addr_t odb_dma_addr;
549549
int ret = 0;
550550

551-
priv = (struct hns_roce_v1_priv *)hr_dev->hw->priv;
551+
priv = (struct hns_roce_v1_priv *)hr_dev->priv;
552552
db = &priv->db_table;
553553

554554
db->ext_db = kmalloc(sizeof(*db->ext_db), GFP_KERNEL);
@@ -669,7 +669,7 @@ static int hns_roce_v1_rsv_lp_qp(struct hns_roce_dev *hr_dev)
669669
u8 port = 0;
670670
u8 sl;
671671

672-
priv = (struct hns_roce_v1_priv *)hr_dev->hw->priv;
672+
priv = (struct hns_roce_v1_priv *)hr_dev->priv;
673673
free_mr = &priv->free_mr;
674674

675675
/* Reserved cq for loop qp */
@@ -817,7 +817,7 @@ static void hns_roce_v1_release_lp_qp(struct hns_roce_dev *hr_dev)
817817
int ret;
818818
int i;
819819

820-
priv = (struct hns_roce_v1_priv *)hr_dev->hw->priv;
820+
priv = (struct hns_roce_v1_priv *)hr_dev->priv;
821821
free_mr = &priv->free_mr;
822822

823823
for (i = 0; i < HNS_ROCE_V1_RESV_QP; i++) {
@@ -851,7 +851,7 @@ static int hns_roce_db_init(struct hns_roce_dev *hr_dev)
851851
u32 odb_evt_mod;
852852
int ret = 0;
853853

854-
priv = (struct hns_roce_v1_priv *)hr_dev->hw->priv;
854+
priv = (struct hns_roce_v1_priv *)hr_dev->priv;
855855
db = &priv->db_table;
856856

857857
memset(db, 0, sizeof(*db));
@@ -907,7 +907,7 @@ static int hns_roce_v1_recreate_lp_qp(struct hns_roce_dev *hr_dev)
907907
unsigned long end =
908908
msecs_to_jiffies(HNS_ROCE_V1_RECREATE_LP_QP_TIMEOUT_MSECS) + jiffies;
909909

910-
priv = (struct hns_roce_v1_priv *)hr_dev->hw->priv;
910+
priv = (struct hns_roce_v1_priv *)hr_dev->priv;
911911
free_mr = &priv->free_mr;
912912

913913
lp_qp_work = kzalloc(sizeof(struct hns_roce_recreate_lp_qp_work),
@@ -983,7 +983,7 @@ static void hns_roce_v1_mr_free_work_fn(struct work_struct *work)
983983
hr_dev = to_hr_dev(mr_work->ib_dev);
984984
dev = &hr_dev->pdev->dev;
985985

986-
priv = (struct hns_roce_v1_priv *)hr_dev->hw->priv;
986+
priv = (struct hns_roce_v1_priv *)hr_dev->priv;
987987
free_mr = &priv->free_mr;
988988
mr_free_cq = free_mr->mr_free_cq;
989989

@@ -1039,7 +1039,7 @@ int hns_roce_v1_dereg_mr(struct hns_roce_dev *hr_dev, struct hns_roce_mr *mr)
10391039
int npages;
10401040
int ret = 0;
10411041

1042-
priv = (struct hns_roce_v1_priv *)hr_dev->hw->priv;
1042+
priv = (struct hns_roce_v1_priv *)hr_dev->priv;
10431043
free_mr = &priv->free_mr;
10441044

10451045
if (mr->enabled) {
@@ -1104,7 +1104,7 @@ static void hns_roce_db_free(struct hns_roce_dev *hr_dev)
11041104
struct hns_roce_v1_priv *priv;
11051105
struct hns_roce_db_table *db;
11061106

1107-
priv = (struct hns_roce_v1_priv *)hr_dev->hw->priv;
1107+
priv = (struct hns_roce_v1_priv *)hr_dev->priv;
11081108
db = &priv->db_table;
11091109

11101110
if (db->sdb_ext_mod) {
@@ -1134,7 +1134,7 @@ static int hns_roce_raq_init(struct hns_roce_dev *hr_dev)
11341134
struct hns_roce_raq_table *raq;
11351135
struct device *dev = &hr_dev->pdev->dev;
11361136

1137-
priv = (struct hns_roce_v1_priv *)hr_dev->hw->priv;
1137+
priv = (struct hns_roce_v1_priv *)hr_dev->priv;
11381138
raq = &priv->raq_table;
11391139

11401140
raq->e_raq_buf = kzalloc(sizeof(*(raq->e_raq_buf)), GFP_KERNEL);
@@ -1211,7 +1211,7 @@ static void hns_roce_raq_free(struct hns_roce_dev *hr_dev)
12111211
struct hns_roce_v1_priv *priv;
12121212
struct hns_roce_raq_table *raq;
12131213

1214-
priv = (struct hns_roce_v1_priv *)hr_dev->hw->priv;
1214+
priv = (struct hns_roce_v1_priv *)hr_dev->priv;
12151215
raq = &priv->raq_table;
12161216

12171217
dma_free_coherent(dev, HNS_ROCE_V1_RAQ_SIZE, raq->e_raq_buf->buf,
@@ -1245,7 +1245,7 @@ static int hns_roce_bt_init(struct hns_roce_dev *hr_dev)
12451245
struct hns_roce_v1_priv *priv;
12461246
int ret;
12471247

1248-
priv = (struct hns_roce_v1_priv *)hr_dev->hw->priv;
1248+
priv = (struct hns_roce_v1_priv *)hr_dev->priv;
12491249

12501250
priv->bt_table.qpc_buf.buf = dma_alloc_coherent(dev,
12511251
HNS_ROCE_BT_RSV_BUF_SIZE, &priv->bt_table.qpc_buf.map,
@@ -1287,7 +1287,7 @@ static void hns_roce_bt_free(struct hns_roce_dev *hr_dev)
12871287
struct device *dev = &hr_dev->pdev->dev;
12881288
struct hns_roce_v1_priv *priv;
12891289

1290-
priv = (struct hns_roce_v1_priv *)hr_dev->hw->priv;
1290+
priv = (struct hns_roce_v1_priv *)hr_dev->priv;
12911291

12921292
dma_free_coherent(dev, HNS_ROCE_BT_RSV_BUF_SIZE,
12931293
priv->bt_table.cqc_buf.buf, priv->bt_table.cqc_buf.map);
@@ -1305,7 +1305,7 @@ static int hns_roce_tptr_init(struct hns_roce_dev *hr_dev)
13051305
struct hns_roce_buf_list *tptr_buf;
13061306
struct hns_roce_v1_priv *priv;
13071307

1308-
priv = (struct hns_roce_v1_priv *)hr_dev->hw->priv;
1308+
priv = (struct hns_roce_v1_priv *)hr_dev->priv;
13091309
tptr_buf = &priv->tptr_table.tptr_buf;
13101310

13111311
/*
@@ -1331,7 +1331,7 @@ static void hns_roce_tptr_free(struct hns_roce_dev *hr_dev)
13311331
struct hns_roce_buf_list *tptr_buf;
13321332
struct hns_roce_v1_priv *priv;
13331333

1334-
priv = (struct hns_roce_v1_priv *)hr_dev->hw->priv;
1334+
priv = (struct hns_roce_v1_priv *)hr_dev->priv;
13351335
tptr_buf = &priv->tptr_table.tptr_buf;
13361336

13371337
dma_free_coherent(dev, HNS_ROCE_V1_TPTR_BUF_SIZE,
@@ -1345,7 +1345,7 @@ static int hns_roce_free_mr_init(struct hns_roce_dev *hr_dev)
13451345
struct hns_roce_v1_priv *priv;
13461346
int ret = 0;
13471347

1348-
priv = (struct hns_roce_v1_priv *)hr_dev->hw->priv;
1348+
priv = (struct hns_roce_v1_priv *)hr_dev->priv;
13491349
free_mr = &priv->free_mr;
13501350

13511351
free_mr->free_mr_wq = create_singlethread_workqueue("hns_roce_free_mr");
@@ -1369,7 +1369,7 @@ static void hns_roce_free_mr_free(struct hns_roce_dev *hr_dev)
13691369
struct hns_roce_free_mr *free_mr;
13701370
struct hns_roce_v1_priv *priv;
13711371

1372-
priv = (struct hns_roce_v1_priv *)hr_dev->hw->priv;
1372+
priv = (struct hns_roce_v1_priv *)hr_dev->priv;
13731373
free_mr = &priv->free_mr;
13741374

13751375
flush_workqueue(free_mr->free_mr_wq);
@@ -1433,7 +1433,7 @@ static int hns_roce_des_qp_init(struct hns_roce_dev *hr_dev)
14331433
struct hns_roce_v1_priv *priv;
14341434
struct hns_roce_des_qp *des_qp;
14351435

1436-
priv = (struct hns_roce_v1_priv *)hr_dev->hw->priv;
1436+
priv = (struct hns_roce_v1_priv *)hr_dev->priv;
14371437
des_qp = &priv->des_qp;
14381438

14391439
des_qp->requeue_flag = 1;
@@ -1451,7 +1451,7 @@ static void hns_roce_des_qp_free(struct hns_roce_dev *hr_dev)
14511451
struct hns_roce_v1_priv *priv;
14521452
struct hns_roce_des_qp *des_qp;
14531453

1454-
priv = (struct hns_roce_v1_priv *)hr_dev->hw->priv;
1454+
priv = (struct hns_roce_v1_priv *)hr_dev->priv;
14551455
des_qp = &priv->des_qp;
14561456

14571457
des_qp->requeue_flag = 0;
@@ -1942,7 +1942,7 @@ void hns_roce_v1_write_cqc(struct hns_roce_dev *hr_dev,
19421942
dma_addr_t tptr_dma_addr;
19431943
int offset;
19441944

1945-
priv = (struct hns_roce_v1_priv *)hr_dev->hw->priv;
1945+
priv = (struct hns_roce_v1_priv *)hr_dev->priv;
19461946
tptr_buf = &priv->tptr_table.tptr_buf;
19471947

19481948
cq_context = mb_buf;
@@ -2290,7 +2290,7 @@ int hns_roce_v1_clear_hem(struct hns_roce_dev *hr_dev,
22902290
void __iomem *bt_cmd;
22912291
u64 bt_ba = 0;
22922292

2293-
priv = (struct hns_roce_v1_priv *)hr_dev->hw->priv;
2293+
priv = (struct hns_roce_v1_priv *)hr_dev->priv;
22942294

22952295
switch (table->type) {
22962296
case HEM_TYPE_QPC:
@@ -3665,7 +3665,7 @@ static void hns_roce_v1_destroy_qp_work_fn(struct work_struct *work)
36653665
qp_work_entry = container_of(work, struct hns_roce_qp_work, work);
36663666
hr_dev = to_hr_dev(qp_work_entry->ib_dev);
36673667
dev = &hr_dev->pdev->dev;
3668-
priv = (struct hns_roce_v1_priv *)hr_dev->hw->priv;
3668+
priv = (struct hns_roce_v1_priv *)hr_dev->priv;
36693669
hr_qp = qp_work_entry->qp;
36703670
qpn = hr_qp->qpn;
36713671

@@ -3782,7 +3782,7 @@ int hns_roce_v1_destroy_qp(struct ib_qp *ibqp)
37823782
qp_work->sdb_inv_cnt = qp_work_entry.sdb_inv_cnt;
37833783
qp_work->sche_cnt = qp_work_entry.sche_cnt;
37843784

3785-
priv = (struct hns_roce_v1_priv *)hr_dev->hw->priv;
3785+
priv = (struct hns_roce_v1_priv *)hr_dev->priv;
37863786
queue_work(priv->des_qp.qp_wq, &qp_work->work);
37873787
dev_dbg(dev, "Begin destroy QP(0x%lx) work.\n", hr_qp->qpn);
37883788
}
@@ -3842,8 +3842,6 @@ int hns_roce_v1_destroy_cq(struct ib_cq *ibcq)
38423842
return ret;
38433843
}
38443844

3845-
struct hns_roce_v1_priv hr_v1_priv;
3846-
38473845
static const struct hns_roce_hw hns_roce_hw_v1 = {
38483846
.reset = hns_roce_v1_reset,
38493847
.hw_profile = hns_roce_v1_profile,
@@ -3864,7 +3862,6 @@ static const struct hns_roce_hw hns_roce_hw_v1 = {
38643862
.poll_cq = hns_roce_v1_poll_cq,
38653863
.dereg_mr = hns_roce_v1_dereg_mr,
38663864
.destroy_cq = hns_roce_v1_destroy_cq,
3867-
.priv = &hr_v1_priv,
38683865
};
38693866

38703867
static const struct of_device_id hns_roce_of_match[] = {
@@ -4046,6 +4043,12 @@ static int hns_roce_probe(struct platform_device *pdev)
40464043
if (!hr_dev)
40474044
return -ENOMEM;
40484045

4046+
hr_dev->priv = kzalloc(sizeof(struct hns_roce_v1_priv), GFP_KERNEL);
4047+
if (!hr_dev->priv) {
4048+
ret = -ENOMEM;
4049+
goto error_failed_kzalloc;
4050+
}
4051+
40494052
hr_dev->pdev = pdev;
40504053
platform_set_drvdata(pdev, hr_dev);
40514054

@@ -4071,6 +4074,9 @@ static int hns_roce_probe(struct platform_device *pdev)
40714074
return 0;
40724075

40734076
error_failed_get_cfg:
4077+
kfree(hr_dev->priv);
4078+
4079+
error_failed_kzalloc:
40744080
ib_dealloc_device(&hr_dev->ib_dev);
40754081

40764082
return ret;
@@ -4085,6 +4091,7 @@ static int hns_roce_remove(struct platform_device *pdev)
40854091
struct hns_roce_dev *hr_dev = platform_get_drvdata(pdev);
40864092

40874093
hns_roce_exit(hr_dev);
4094+
kfree(hr_dev->priv);
40884095
ib_dealloc_device(&hr_dev->ib_dev);
40894096

40904097
return 0;

0 commit comments

Comments
 (0)