summaryrefslogtreecommitdiffstats
path: root/src/net
diff options
context:
space:
mode:
authorMichael Brown2017-03-22 09:47:46 +0100
committerMichael Brown2017-03-22 10:18:02 +0100
commit39ef530088859ccbbcf29bf6af2cf9f0307dc476 (patch)
tree1f90063aa65d6fa2065bdb7f430aebf70623856e /src/net
parent[build] Avoid confusing sparse in single-argument DBG() macros (diff)
downloadipxe-39ef530088859ccbbcf29bf6af2cf9f0307dc476.tar.gz
ipxe-39ef530088859ccbbcf29bf6af2cf9f0307dc476.tar.xz
ipxe-39ef530088859ccbbcf29bf6af2cf9f0307dc476.zip
[infiniband] Return status code from ib_create_cq() and ib_create_qp()
Any underlying errors arising during ib_create_cq() or ib_create_qp() are lost since the functions simply return NULL on error. This makes debugging harder, since a debug-enabled build is required to discover the root cause of the error. Fix by returning a status code from these functions, thereby allowing any underlying errors to be propagated. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/net')
-rw-r--r--src/net/infiniband.c45
-rw-r--r--src/net/infiniband/ib_cmrc.c23
-rw-r--r--src/net/infiniband/ib_mi.c17
3 files changed, 45 insertions, 40 deletions
diff --git a/src/net/infiniband.c b/src/net/infiniband.c
index 15ff0529..fa45653e 100644
--- a/src/net/infiniband.c
+++ b/src/net/infiniband.c
@@ -92,11 +92,12 @@ struct errortab infiniband_errors[] __errortab = {
* @v ibdev Infiniband device
* @v num_cqes Number of completion queue entries
* @v op Completion queue operations
- * @ret cq New completion queue
+ * @v new_cq New completion queue to fill in
+ * @ret rc Return status code
*/
-struct ib_completion_queue *
-ib_create_cq ( struct ib_device *ibdev, unsigned int num_cqes,
- struct ib_completion_queue_operations *op ) {
+int ib_create_cq ( struct ib_device *ibdev, unsigned int num_cqes,
+ struct ib_completion_queue_operations *op,
+ struct ib_completion_queue **new_cq ) {
struct ib_completion_queue *cq;
int rc;
@@ -104,8 +105,10 @@ ib_create_cq ( struct ib_device *ibdev, unsigned int num_cqes,
/* Allocate and initialise data structure */
cq = zalloc ( sizeof ( *cq ) );
- if ( ! cq )
+ if ( ! cq ) {
+ rc = -ENOMEM;
goto err_alloc_cq;
+ }
cq->ibdev = ibdev;
list_add_tail ( &cq->list, &ibdev->cqs );
cq->num_cqes = num_cqes;
@@ -122,14 +125,15 @@ ib_create_cq ( struct ib_device *ibdev, unsigned int num_cqes,
DBGC ( ibdev, "IBDEV %s created %d-entry completion queue %p (%p) "
"with CQN %#lx\n", ibdev->name, num_cqes, cq,
ib_cq_get_drvdata ( cq ), cq->cqn );
- return cq;
+ *new_cq = cq;
+ return 0;
ibdev->op->destroy_cq ( ibdev, cq );
err_dev_create_cq:
list_del ( &cq->list );
free ( cq );
err_alloc_cq:
- return NULL;
+ return rc;
}
/**
@@ -186,19 +190,19 @@ void ib_poll_cq ( struct ib_device *ibdev,
* @v recv_cq Receive completion queue
* @v op Queue pair operations
* @v name Queue pair name
- * @ret qp Queue pair
+ * @v new_qp New queue pair to fill in
+ * @ret rc Return status code
*
* The queue pair will be left in the INIT state; you must call
* ib_modify_qp() before it is ready to use for sending and receiving.
*/
-struct ib_queue_pair * ib_create_qp ( struct ib_device *ibdev,
- enum ib_queue_pair_type type,
- unsigned int num_send_wqes,
- struct ib_completion_queue *send_cq,
- unsigned int num_recv_wqes,
- struct ib_completion_queue *recv_cq,
- struct ib_queue_pair_operations *op,
- const char *name ) {
+int ib_create_qp ( struct ib_device *ibdev, enum ib_queue_pair_type type,
+ unsigned int num_send_wqes,
+ struct ib_completion_queue *send_cq,
+ unsigned int num_recv_wqes,
+ struct ib_completion_queue *recv_cq,
+ struct ib_queue_pair_operations *op, const char *name,
+ struct ib_queue_pair **new_qp ) {
struct ib_queue_pair *qp;
size_t total_size;
int rc;
@@ -210,8 +214,10 @@ struct ib_queue_pair * ib_create_qp ( struct ib_device *ibdev,
( num_send_wqes * sizeof ( qp->send.iobufs[0] ) ) +
( num_recv_wqes * sizeof ( qp->recv.iobufs[0] ) ) );
qp = zalloc ( total_size );
- if ( ! qp )
+ if ( ! qp ) {
+ rc = -ENOMEM;
goto err_alloc_qp;
+ }
qp->ibdev = ibdev;
list_add_tail ( &qp->list, &ibdev->qps );
qp->type = type;
@@ -265,7 +271,8 @@ struct ib_queue_pair * ib_create_qp ( struct ib_device *ibdev,
ibdev->name, qp->qpn, qp->ext_qpn );
}
- return qp;
+ *new_qp = qp;
+ return 0;
ibdev->op->destroy_qp ( ibdev, qp );
err_dev_create_qp:
@@ -274,7 +281,7 @@ struct ib_queue_pair * ib_create_qp ( struct ib_device *ibdev,
list_del ( &qp->list );
free ( qp );
err_alloc_qp:
- return NULL;
+ return rc;
}
/**
diff --git a/src/net/infiniband/ib_cmrc.c b/src/net/infiniband/ib_cmrc.c
index 2cd49018..b8f4bf36 100644
--- a/src/net/infiniband/ib_cmrc.c
+++ b/src/net/infiniband/ib_cmrc.c
@@ -423,23 +423,20 @@ int ib_cmrc_open ( struct interface *xfer, struct ib_device *ibdev,
}
/* Create completion queue */
- cmrc->cq = ib_create_cq ( ibdev, IB_CMRC_NUM_CQES,
- &ib_cmrc_completion_ops );
- if ( ! cmrc->cq ) {
- DBGC ( cmrc, "CMRC %s %s could not create completion queue\n",
- ibdev->name, cmrc->name );
- rc = -ENOMEM;
+ if ( ( rc = ib_create_cq ( ibdev, IB_CMRC_NUM_CQES,
+ &ib_cmrc_completion_ops, &cmrc->cq ) ) != 0){
+ DBGC ( cmrc, "CMRC %s %s could not create completion queue: "
+ "%s\n", ibdev->name, cmrc->name, strerror ( rc ) );
goto err_create_cq;
}
/* Create queue pair */
- cmrc->qp = ib_create_qp ( ibdev, IB_QPT_RC, IB_CMRC_NUM_SEND_WQES,
- cmrc->cq, IB_CMRC_NUM_RECV_WQES, cmrc->cq,
- &ib_cmrc_queue_pair_ops, name );
- if ( ! cmrc->qp ) {
- DBGC ( cmrc, "CMRC %s %s could not create queue pair\n",
- ibdev->name, cmrc->name );
- rc = -ENOMEM;
+ if ( ( rc = ib_create_qp ( ibdev, IB_QPT_RC, IB_CMRC_NUM_SEND_WQES,
+ cmrc->cq, IB_CMRC_NUM_RECV_WQES, cmrc->cq,
+ &ib_cmrc_queue_pair_ops, name,
+ &cmrc->qp ) ) != 0 ) {
+ DBGC ( cmrc, "CMRC %s %s could not create queue pair: %s\n",
+ ibdev->name, cmrc->name, strerror ( rc ) );
goto err_create_qp;
}
ib_qp_set_ownerdata ( cmrc->qp, cmrc );
diff --git a/src/net/infiniband/ib_mi.c b/src/net/infiniband/ib_mi.c
index 548a1c82..149c1e4d 100644
--- a/src/net/infiniband/ib_mi.c
+++ b/src/net/infiniband/ib_mi.c
@@ -357,19 +357,20 @@ struct ib_mad_interface * ib_create_mi ( struct ib_device *ibdev,
INIT_LIST_HEAD ( &mi->madx );
/* Create completion queue */
- mi->cq = ib_create_cq ( ibdev, IB_MI_NUM_CQES, &ib_mi_completion_ops );
- if ( ! mi->cq ) {
- DBGC ( mi, "MI %p could not allocate completion queue\n", mi );
+ if ( ( rc = ib_create_cq ( ibdev, IB_MI_NUM_CQES, &ib_mi_completion_ops,
+ &mi->cq ) ) != 0 ) {
+ DBGC ( mi, "MI %p could not create completion queue: %s\n",
+ mi, strerror ( rc ) );
goto err_create_cq;
}
/* Create queue pair */
name = ( ( type == IB_QPT_SMI ) ? "SMI" : "GSI" );
- mi->qp = ib_create_qp ( ibdev, type, IB_MI_NUM_SEND_WQES, mi->cq,
- IB_MI_NUM_RECV_WQES, mi->cq,
- &ib_mi_queue_pair_ops, name );
- if ( ! mi->qp ) {
- DBGC ( mi, "MI %p could not allocate queue pair\n", mi );
+ if ( ( rc = ib_create_qp ( ibdev, type, IB_MI_NUM_SEND_WQES, mi->cq,
+ IB_MI_NUM_RECV_WQES, mi->cq,
+ &ib_mi_queue_pair_ops, name, &mi->qp ) )!=0){
+ DBGC ( mi, "MI %p could not create queue pair: %s\n",
+ mi, strerror ( rc ) );
goto err_create_qp;
}
ib_qp_set_ownerdata ( mi->qp, mi );