IB/rdmavt: Add device structure allocation
authorDennis Dalessandro <dennis.dalessandro@intel.com>
Fri, 22 Jan 2016 21:04:45 +0000 (13:04 -0800)
committerDoug Ledford <dledford@redhat.com>
Fri, 11 Mar 2016 01:37:27 +0000 (20:37 -0500)
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 <ira.weiny@intel.com>
Signed-off-by: Dennis Dalessandro <dennis.dalessandro@intel.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
drivers/infiniband/sw/rdmavt/vt.c
include/rdma/rdma_vt.h

index cf7cac610248c313ad7493e4ca7e90de6e1ddd7b..450caa7e38cf1f61f9230df7f4d6fd3002ac42cc 100644 (file)
@@ -67,6 +67,24 @@ static void rvt_cleanup(void)
 }
 module_exit(rvt_cleanup);
 
+struct rvt_dev_info *rvt_alloc_device(size_t size, int nports)
+{
+       struct rvt_dev_info *rdi = ERR_PTR(-ENOMEM);
+
+       rdi = (struct rvt_dev_info *)ib_alloc_device(size);
+       if (!rdi)
+               return rdi;
+
+       rdi->ports = kcalloc(nports,
+                            sizeof(struct rvt_ibport **),
+                            GFP_KERNEL);
+       if (!rdi->ports)
+               ib_dealloc_device(&rdi->ibdev);
+
+       return rdi;
+}
+EXPORT_SYMBOL(rvt_alloc_device);
+
 static int rvt_query_device(struct ib_device *ibdev,
                            struct ib_device_attr *props,
                            struct ib_udata *uhw)
@@ -434,18 +452,6 @@ EXPORT_SYMBOL(rvt_unregister_device);
 int rvt_init_port(struct rvt_dev_info *rdi, struct rvt_ibport *port,
                  int portnum, u16 *pkey_table)
 {
-       if (!rdi->dparms.nports) {
-               rvt_pr_err(rdi, "Driver says it has no ports.\n");
-               return -EINVAL;
-       }
-
-       rdi->ports = kcalloc(rdi->dparms.nports,
-                            sizeof(struct rvt_ibport **),
-                            GFP_KERNEL);
-       if (!rdi->ports) {
-               rvt_pr_err(rdi, "Could not allocate port mem.\n");
-               return -ENOMEM;
-       }
 
        rdi->ports[portnum] = port;
        rdi->ports[portnum]->pkey_table = pkey_table;
index e382cca3fc4f6a16ef21848f4d10ceae9b5601c3..7768e041f244743ef8a4cd925484084904ae311a 100644 (file)
@@ -394,6 +394,7 @@ static inline struct rvt_qp *rvt_lookup_qpn(struct rvt_dev_info *rdi,
        return qp;
 }
 
+struct rvt_dev_info *rvt_alloc_device(size_t size, int nports);
 int rvt_register_device(struct rvt_dev_info *rvd);
 void rvt_unregister_device(struct rvt_dev_info *rvd);
 int rvt_check_ah(struct ib_device *ibdev, struct ib_ah_attr *ah_attr);