@@ -115,8 +115,8 @@ static inline struct verbs_device *verbs_get_device(
NULL : container_of(dev, struct verbs_device, device);
}
-typedef struct ibv_device *(*ibv_driver_init_func)(const char *uverbs_sys_path,
- int abi_version);
+typedef struct verbs_device *(*ibv_driver_init_func)(const char *uverbs_sys_path,
+ int abi_version);
typedef struct verbs_device *(*verbs_driver_init_func)(const char *uverbs_sys_path,
int abi_version);
@@ -384,9 +384,10 @@ static struct ibv_device *try_driver(struct ibv_driver *driver,
char value[16];
if (driver->init_func) {
- dev = driver->init_func(sysfs_dev->sysfs_path, sysfs_dev->abi_ver);
- if (!dev)
+ vdev = driver->init_func(sysfs_dev->sysfs_path, sysfs_dev->abi_ver);
+ if (!vdev)
return NULL;
+ dev = &vdev->device;
} else {
vdev = driver->verbs_init_func(sysfs_dev->sysfs_path, sysfs_dev->abi_ver);
if (!vdev)
@@ -171,8 +171,8 @@ static struct ibv_device_ops iwch_dev_ops = {
.free_context = iwch_free_context
};
-static struct ibv_device *cxgb3_driver_init(const char *uverbs_sys_path,
- int abi_version)
+static struct verbs_device *cxgb3_driver_init(const char *uverbs_sys_path,
+ int abi_version)
{
char devstr[IBV_SYSFS_PATH_MAX], ibdev[16], value[32], *cp;
struct iwch_device *dev;
@@ -245,13 +245,13 @@ found:
PDBG("%s found vendor %d device %d type %d\n",
__FUNCTION__, vendor, device, hca_table[i].type);
- dev = malloc(sizeof *dev);
+ dev = calloc(1, sizeof(*dev));
if (!dev) {
return NULL;
}
pthread_spin_init(&dev->lock, PTHREAD_PROCESS_PRIVATE);
- dev->ibv_dev.ops = iwch_dev_ops;
+ dev->ibv_dev.device.ops = iwch_dev_ops;
dev->hca_type = hca_table[i].type;
dev->abi_version = abi_version;
@@ -51,7 +51,7 @@ struct iwch_mr;
#define ABI_VERS 1
struct iwch_device {
- struct ibv_device ibv_dev;
+ struct verbs_device ibv_dev;
enum iwch_hca_type hca_type;
struct iwch_mr **mmid2ptr;
struct iwch_qp **qpid2ptr;
@@ -397,8 +397,8 @@ void dump_state(void)
*/
int c4iw_abi_version = 1;
-static struct ibv_device *cxgb4_driver_init(const char *uverbs_sys_path,
- int abi_version)
+static struct verbs_device *cxgb4_driver_init(const char *uverbs_sys_path,
+ int abi_version)
{
char devstr[IBV_SYSFS_PATH_MAX], ibdev[16], value[32], *cp;
struct c4iw_dev *dev;
@@ -470,7 +470,7 @@ found:
}
pthread_spin_init(&dev->lock, PTHREAD_PROCESS_PRIVATE);
- dev->ibv_dev.ops = c4iw_dev_ops;
+ dev->ibv_dev.device.ops = c4iw_dev_ops;
dev->chip_version = CHELSIO_CHIP_VERSION(hca_table[i].device >> 8);
dev->abi_version = abi_version;
list_node_init(&dev->list);
@@ -51,7 +51,7 @@ extern unsigned long c4iw_page_mask;
struct c4iw_mr;
struct c4iw_dev {
- struct ibv_device ibv_dev;
+ struct verbs_device ibv_dev;
unsigned chip_version;
int max_mr;
struct c4iw_mr **mmid2ptr;
@@ -178,8 +178,8 @@ static struct ibv_device_ops hfi1_dev_ops = {
.free_context = hfi1_free_context
};
-static struct ibv_device *hfi1_driver_init(const char *uverbs_sys_path,
- int abi_version)
+static struct verbs_device *hfi1_driver_init(const char *uverbs_sys_path,
+ int abi_version)
{
char value[8];
struct hfi1_device *dev;
@@ -204,14 +204,14 @@ static struct ibv_device *hfi1_driver_init(const char *uverbs_sys_path,
return NULL;
found:
- dev = malloc(sizeof *dev);
+ dev = calloc(1, sizeof(*dev));
if (!dev) {
fprintf(stderr, PFX "Fatal: couldn't allocate device for %s\n",
uverbs_sys_path);
return NULL;
}
- dev->ibv_dev.ops = hfi1_dev_ops;
+ dev->ibv_dev.device.ops = hfi1_dev_ops;
dev->abi_version = abi_version;
return &dev->ibv_dev;
@@ -69,7 +69,7 @@
#define PFX "hfi1: "
struct hfi1_device {
- struct ibv_device ibv_dev;
+ struct verbs_device ibv_dev;
int abi_version;
};
@@ -178,8 +178,8 @@ static struct ibv_device_ops hns_roce_dev_ops = {
.free_context = hns_roce_free_context
};
-static struct ibv_device *hns_roce_driver_init(const char *uverbs_sys_path,
- int abi_version)
+static struct verbs_device *hns_roce_driver_init(const char *uverbs_sys_path,
+ int abi_version)
{
struct hns_roce_device *dev;
char value[128];
@@ -208,14 +208,14 @@ static struct ibv_device *hns_roce_driver_init(const char *uverbs_sys_path,
return NULL;
found:
- dev = malloc(sizeof(struct hns_roce_device));
+ dev = calloc(1, sizeof(*dev));
if (!dev) {
fprintf(stderr, PFX "Fatal: couldn't allocate device for %s\n",
uverbs_sys_path);
return NULL;
}
- dev->ibv_dev.ops = hns_roce_dev_ops;
+ dev->ibv_dev.device.ops = hns_roce_dev_ops;
dev->u_hw = (struct hns_roce_u_hw *)u_hw;
dev->hw_version = hw_version;
dev->page_size = sysconf(_SC_PAGESIZE);
@@ -80,7 +80,7 @@ enum {
};
struct hns_roce_device {
- struct ibv_device ibv_dev;
+ struct verbs_device ibv_dev;
int page_size;
struct hns_roce_u_hw *u_hw;
int hw_version;
@@ -218,7 +218,8 @@ static struct ibv_device_ops i40iw_udev_ops = {
* @uverbs_sys_path: sys path
* @abi_version: not used
*/
-struct ibv_device *i40iw_driver_init(const char *uverbs_sys_path, int abi_version)
+static struct verbs_device *i40iw_driver_init(const char *uverbs_sys_path,
+ int abi_version)
{
char value[16];
struct i40iw_udevice *dev;
@@ -241,13 +242,13 @@ struct ibv_device *i40iw_driver_init(const char *uverbs_sys_path, int abi_versio
return NULL;
found:
- dev = malloc(sizeof(*dev));
+ dev = calloc(1, sizeof(*dev));
if (!dev) {
fprintf(stderr, PFX "%s: failed to allocate memory for device object\n", __func__);
return NULL;
}
- dev->ibv_dev.ops = i40iw_udev_ops;
+ dev->ibv_dev.device.ops = i40iw_udev_ops;
dev->hca_type = hca_table[i].type;
dev->page_size = I40IW_HW_PAGE_SIZE;
return &dev->ibv_dev;
@@ -69,7 +69,7 @@ enum i40iw_uhca_type {
};
struct i40iw_udevice {
- struct ibv_device ibv_dev;
+ struct verbs_device ibv_dev;
enum i40iw_uhca_type hca_type;
int page_size;
};
@@ -156,9 +156,6 @@ static inline struct i40iw_uqp *to_i40iw_uqp(struct ibv_qp *ibqp)
return to_i40iw_uxxx(qp, qp);
}
-/* i40iw_umain.c */
-struct ibv_device *i40iw_driver_init(const char *, int);
-
/* i40iw_uverbs.c */
int i40iw_uquery_device(struct ibv_context *, struct ibv_device_attr *);
int i40iw_uquery_port(struct ibv_context *, uint8_t, struct ibv_port_attr *);
@@ -177,8 +177,8 @@ static struct ibv_device_ops ipath_dev_ops = {
.free_context = ipath_free_context
};
-static struct ibv_device *ipath_driver_init(const char *uverbs_sys_path,
- int abi_version)
+static struct verbs_device *ipath_driver_init(const char *uverbs_sys_path,
+ int abi_version)
{
char value[8];
struct ipath_device *dev;
@@ -203,14 +203,14 @@ static struct ibv_device *ipath_driver_init(const char *uverbs_sys_path,
return NULL;
found:
- dev = malloc(sizeof *dev);
+ dev = calloc(1, sizeof(*dev));
if (!dev) {
fprintf(stderr, PFX "Fatal: couldn't allocate device for %s\n",
uverbs_sys_path);
return NULL;
}
- dev->ibv_dev.ops = ipath_dev_ops;
+ dev->ibv_dev.device.ops = ipath_dev_ops;
dev->abi_version = abi_version;
return &dev->ibv_dev;
@@ -49,7 +49,7 @@
#define PFX "ipath: "
struct ipath_device {
- struct ibv_device ibv_dev;
+ struct verbs_device ibv_dev;
int abi_version;
};
@@ -214,7 +214,7 @@ static struct ibv_device_ops mthca_dev_ops = {
.free_context = mthca_free_context
};
-static struct ibv_device *mthca_driver_init(const char *uverbs_sys_path,
+static struct verbs_device *mthca_driver_init(const char *uverbs_sys_path,
int abi_version)
{
char value[8];
@@ -246,14 +246,14 @@ found:
return NULL;
}
- dev = malloc(sizeof *dev);
+ dev = calloc(1, sizeof(*dev));
if (!dev) {
fprintf(stderr, PFX "Fatal: couldn't allocate device for %s\n",
uverbs_sys_path);
return NULL;
}
- dev->ibv_dev.ops = mthca_dev_ops;
+ dev->ibv_dev.device.ops = mthca_dev_ops;
dev->hca_type = hca_table[i].type;
dev->page_size = sysconf(_SC_PAGESIZE);
@@ -89,7 +89,7 @@ enum {
struct mthca_ah_page;
struct mthca_device {
- struct ibv_device ibv_dev;
+ struct verbs_device ibv_dev;
enum mthca_hca_type hca_type;
int page_size;
};
@@ -194,7 +194,8 @@ static struct ibv_device_ops nes_udev_ops = {
/**
* nes_driver_init
*/
-struct ibv_device *nes_driver_init(const char *uverbs_sys_path, int abi_version)
+static struct verbs_device *nes_driver_init(const char *uverbs_sys_path,
+ int abi_version)
{
char value[16];
struct nes_udevice *dev;
@@ -229,13 +230,13 @@ found:
sscanf(value, "%u", &nes_debug_level);
}
- dev = malloc(sizeof *dev);
+ dev = calloc(1, sizeof(*dev));
if (!dev) {
nes_debug(NES_DBG_INIT, "Fatal: couldn't allocate device for libnes\n");
return NULL;
}
- dev->ibv_dev.ops = nes_udev_ops;
+ dev->ibv_dev.device.ops = nes_udev_ops;
dev->hca_type = hca_table[i].type;
dev->page_size = sysconf(_SC_PAGESIZE);
@@ -248,7 +248,7 @@ struct nes_user_doorbell {
};
struct nes_udevice {
- struct ibv_device ibv_dev;
+ struct verbs_device ibv_dev;
enum nes_uhca_type hca_type;
int page_size;
};
@@ -351,9 +351,6 @@ static inline struct nes_uqp *to_nes_uqp(struct ibv_qp *ibqp)
}
-/* nes_umain.c */
-struct ibv_device *nes_driver_init(const char *, int);
-
/* nes_uverbs.c */
int nes_uquery_device(struct ibv_context *, struct ibv_device_attr *);
int nes_uquery_port(struct ibv_context *, uint8_t, struct ibv_port_attr *);
@@ -172,8 +172,8 @@ static void ocrdma_free_context(struct ibv_context *ibctx)
/**
* ocrdma_driver_init
*/
-struct ibv_device *ocrdma_driver_init(const char *uverbs_sys_path,
- int abi_version)
+static struct verbs_device *ocrdma_driver_init(const char *uverbs_sys_path,
+ int abi_version)
{
char value[16];
@@ -207,20 +207,20 @@ found:
return NULL;
}
- dev = malloc(sizeof *dev);
+ dev = calloc(1, sizeof(*dev));
if (!dev) {
ocrdma_err("%s() Fatal: fail allocate device for libocrdma\n",
__func__);
return NULL;
}
- bzero(dev, sizeof *dev);
+
dev->qp_tbl = malloc(OCRDMA_MAX_QP * sizeof(struct ocrdma_qp *));
if (!dev->qp_tbl)
goto qp_err;
bzero(dev->qp_tbl, OCRDMA_MAX_QP * sizeof(struct ocrdma_qp *));
pthread_mutex_init(&dev->dev_lock, NULL);
pthread_spin_init(&dev->flush_q_lock, PTHREAD_PROCESS_PRIVATE);
- dev->ibv_dev.ops = ocrdma_dev_ops;
+ dev->ibv_dev.device.ops = ocrdma_dev_ops;
list_node_init(&dev->entry);
pthread_mutex_lock(&ocrdma_dev_list_lock);
list_add_tail(&ocrdma_dev_list, &dev->entry);
@@ -54,7 +54,7 @@
struct ocrdma_qp;
struct ocrdma_device {
- struct ibv_device ibv_dev;
+ struct verbs_device ibv_dev;
struct ocrdma_qp **qp_tbl;
pthread_mutex_t dev_lock;
pthread_spinlock_t flush_q_lock;
@@ -266,8 +266,6 @@ static inline struct ocrdma_ah *get_ocrdma_ah(struct ibv_ah *ibah)
return get_ocrdma_xxx(ah, ah);
}
-struct ibv_device *ocrdma_driver_init(const char *, int);
-
void ocrdma_init_ahid_tbl(struct ocrdma_devctx *ctx);
int ocrdma_query_device(struct ibv_context *, struct ibv_device_attr *);
int ocrdma_query_port(struct ibv_context *, uint8_t, struct ibv_port_attr *);
@@ -112,7 +112,7 @@ struct qelr_buf {
};
struct qelr_device {
- struct ibv_device ibv_dev;
+ struct verbs_device ibv_dev;
};
struct qelr_devctx {
@@ -231,8 +231,8 @@ static void qelr_free_context(struct ibv_context *ibctx)
free(ctx);
}
-struct ibv_device *qelr_driver_init(const char *uverbs_sys_path,
- int abi_version)
+static struct verbs_device *qelr_driver_init(const char *uverbs_sys_path,
+ int abi_version)
{
char value[16];
struct qelr_device *dev;
@@ -265,16 +265,14 @@ found:
return NULL;
}
- dev = malloc(sizeof(*dev));
+ dev = calloc(1, sizeof(*dev));
if (!dev) {
qelr_err("%s() Fatal: fail allocate device for libqedr\n",
__func__);
return NULL;
}
- bzero(dev, sizeof(*dev));
-
- dev->ibv_dev.ops = qelr_dev_ops;
+ dev->ibv_dev.device.ops = qelr_dev_ops;
return &dev->ibv_dev;
}
@@ -40,8 +40,6 @@
#include <infiniband/driver.h>
#include <util/udma_barrier.h>
-struct ibv_device *qelr_driver_init(const char *, int);
-
int qelr_query_device(struct ibv_context *, struct ibv_device_attr *);
int qelr_query_port(struct ibv_context *, uint8_t, struct ibv_port_attr *);
@@ -891,8 +891,8 @@ static struct ibv_device_ops rxe_dev_ops = {
.free_context = rxe_free_context,
};
-static struct ibv_device *rxe_driver_init(const char *uverbs_sys_path,
- int abi_version)
+static struct verbs_device *rxe_driver_init(const char *uverbs_sys_path,
+ int abi_version)
{
struct rxe_device *dev;
char value[16];
@@ -905,7 +905,7 @@ static struct ibv_device *rxe_driver_init(const char *uverbs_sys_path,
if (strncmp(value, "rxe", 3))
return NULL;
- dev = malloc(sizeof *dev);
+ dev = calloc(1, sizeof(*dev));
if (!dev) {
fprintf(stderr,
"rxe: Fatal: couldn't allocate device for %s\n",
@@ -913,7 +913,7 @@ static struct ibv_device *rxe_driver_init(const char *uverbs_sys_path,
return NULL;
}
- dev->ibv_dev.ops = rxe_dev_ops;
+ dev->ibv_dev.device.ops = rxe_dev_ops;
dev->abi_version = abi_version;
return &dev->ibv_dev;
@@ -43,7 +43,7 @@ enum rdma_network_type {
};
struct rxe_device {
- struct ibv_device ibv_dev;
+ struct verbs_device ibv_dev;
int abi_version;
};
@@ -110,7 +110,7 @@ enum {
};
struct pvrdma_device {
- struct ibv_device ibv_dev;
+ struct verbs_device ibv_dev;
int page_size;
int abi_version;
};
@@ -198,7 +198,7 @@ static struct pvrdma_device *pvrdma_driver_init_shared(
return NULL;
}
- dev = malloc(sizeof(*dev));
+ dev = calloc(1, sizeof(*dev));
if (!dev) {
fprintf(stderr, PFX "couldn't allocate device for %s\n",
uverbs_sys_path);
@@ -207,13 +207,13 @@ static struct pvrdma_device *pvrdma_driver_init_shared(
dev->abi_version = abi_version;
dev->page_size = sysconf(_SC_PAGESIZE);
- dev->ibv_dev.ops = pvrdma_dev_ops;
+ dev->ibv_dev.device.ops = pvrdma_dev_ops;
return dev;
}
-static struct ibv_device *pvrdma_driver_init(const char *uverbs_sys_path,
- int abi_version)
+static struct verbs_device *pvrdma_driver_init(const char *uverbs_sys_path,
+ int abi_version)
{
struct pvrdma_device *dev = pvrdma_driver_init_shared(uverbs_sys_path,
abi_version);
Switch struct ibv_device to verbs_device in the provider specific device structure and use calloc to allocate it so the unset bytes are zero. This lets us change the return type of ibv_driver_init_func to struct verbs_device without changing the control flow at all. Also make a few _init functions static for consistency/simplicity. Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com> --- libibverbs/driver.h | 4 ++-- libibverbs/init.c | 5 +++-- providers/cxgb3/iwch.c | 8 ++++---- providers/cxgb3/iwch.h | 2 +- providers/cxgb4/dev.c | 6 +++--- providers/cxgb4/libcxgb4.h | 2 +- providers/hfi1verbs/hfiverbs.c | 8 ++++---- providers/hfi1verbs/hfiverbs.h | 2 +- providers/hns/hns_roce_u.c | 8 ++++---- providers/hns/hns_roce_u.h | 2 +- providers/i40iw/i40iw_umain.c | 7 ++++--- providers/i40iw/i40iw_umain.h | 5 +---- providers/ipathverbs/ipathverbs.c | 8 ++++---- providers/ipathverbs/ipathverbs.h | 2 +- providers/mthca/mthca.c | 6 +++--- providers/mthca/mthca.h | 2 +- providers/nes/nes_umain.c | 7 ++++--- providers/nes/nes_umain.h | 5 +---- providers/ocrdma/ocrdma_main.c | 10 +++++----- providers/ocrdma/ocrdma_main.h | 4 +--- providers/qedr/qelr.h | 2 +- providers/qedr/qelr_main.c | 10 ++++------ providers/qedr/qelr_main.h | 2 -- providers/rxe/rxe.c | 8 ++++---- providers/rxe/rxe.h | 2 +- providers/vmw_pvrdma/pvrdma.h | 2 +- providers/vmw_pvrdma/pvrdma_main.c | 8 ++++---- 27 files changed, 64 insertions(+), 73 deletions(-)