Skip to content

Commit ff6acd6

Browse files
Dennis Dalessandrodledford
authored andcommitted
IB/rdmavt: Add device structure allocation
This patch adds rdmavt device structure allocation in rdamvt. The ib_device alloc is now done in rdmavt instead of the driver. Drivers need to tell rdmavt the number of ports when calling. A side of effect of this patch is fixing a bug with port initialization where the device structure port array was allocated over top of an existing one. Reviewed-by: Ira Weiny <[email protected]> Signed-off-by: Dennis Dalessandro <[email protected]> Signed-off-by: Doug Ledford <[email protected]>
1 parent e85ec33 commit ff6acd6

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

drivers/infiniband/sw/rdmavt/vt.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,24 @@ static void rvt_cleanup(void)
6767
}
6868
module_exit(rvt_cleanup);
6969

70+
struct rvt_dev_info *rvt_alloc_device(size_t size, int nports)
71+
{
72+
struct rvt_dev_info *rdi = ERR_PTR(-ENOMEM);
73+
74+
rdi = (struct rvt_dev_info *)ib_alloc_device(size);
75+
if (!rdi)
76+
return rdi;
77+
78+
rdi->ports = kcalloc(nports,
79+
sizeof(struct rvt_ibport **),
80+
GFP_KERNEL);
81+
if (!rdi->ports)
82+
ib_dealloc_device(&rdi->ibdev);
83+
84+
return rdi;
85+
}
86+
EXPORT_SYMBOL(rvt_alloc_device);
87+
7088
static int rvt_query_device(struct ib_device *ibdev,
7189
struct ib_device_attr *props,
7290
struct ib_udata *uhw)
@@ -434,18 +452,6 @@ EXPORT_SYMBOL(rvt_unregister_device);
434452
int rvt_init_port(struct rvt_dev_info *rdi, struct rvt_ibport *port,
435453
int portnum, u16 *pkey_table)
436454
{
437-
if (!rdi->dparms.nports) {
438-
rvt_pr_err(rdi, "Driver says it has no ports.\n");
439-
return -EINVAL;
440-
}
441-
442-
rdi->ports = kcalloc(rdi->dparms.nports,
443-
sizeof(struct rvt_ibport **),
444-
GFP_KERNEL);
445-
if (!rdi->ports) {
446-
rvt_pr_err(rdi, "Could not allocate port mem.\n");
447-
return -ENOMEM;
448-
}
449455

450456
rdi->ports[portnum] = port;
451457
rdi->ports[portnum]->pkey_table = pkey_table;

include/rdma/rdma_vt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ static inline struct rvt_qp *rvt_lookup_qpn(struct rvt_dev_info *rdi,
394394
return qp;
395395
}
396396

397+
struct rvt_dev_info *rvt_alloc_device(size_t size, int nports);
397398
int rvt_register_device(struct rvt_dev_info *rvd);
398399
void rvt_unregister_device(struct rvt_dev_info *rvd);
399400
int rvt_check_ah(struct ib_device *ibdev, struct ib_ah_attr *ah_attr);

0 commit comments

Comments
 (0)