Bläddra i källkod

[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>
tags/v1.20.1
Michael Brown 7 år sedan
förälder
incheckning
39ef530088

+ 8
- 8
src/drivers/infiniband/flexboot_nodnic.c Visa fil

@@ -860,6 +860,7 @@ static int flexboot_nodnic_eth_open ( struct net_device *netdev ) {
860 860
 	mlx_uint64	cq_size = 0;
861 861
 	mlx_uint32	qpn = 0;
862 862
 	nodnic_port_state state = nodnic_port_state_down;
863
+	int rc;
863 864
 
864 865
 	if ( port->port_priv.port_state & NODNIC_PORT_OPENED ) {
865 866
 		DBGC ( flexboot_nodnic, "%s: port %d is already opened\n",
@@ -877,11 +878,11 @@ static int flexboot_nodnic_eth_open ( struct net_device *netdev ) {
877 878
 	}
878 879
 	INIT_LIST_HEAD ( &dummy_cq->work_queues );
879 880
 
880
-	port->eth_qp = ib_create_qp ( ibdev, IB_QPT_ETH,
881
-					FLEXBOOT_NODNIC_ETH_NUM_SEND_WQES, dummy_cq,
882
-					FLEXBOOT_NODNIC_ETH_NUM_RECV_WQES, dummy_cq,
883
-					&flexboot_nodnic_eth_qp_op, netdev->name );
884
-	if ( !port->eth_qp ) {
881
+	if ( ( rc = ib_create_qp ( ibdev, IB_QPT_ETH,
882
+				   FLEXBOOT_NODNIC_ETH_NUM_SEND_WQES, dummy_cq,
883
+				   FLEXBOOT_NODNIC_ETH_NUM_RECV_WQES, dummy_cq,
884
+				   &flexboot_nodnic_eth_qp_op, netdev->name,
885
+				   &port->eth_qp ) ) != 0 ) {
885 886
 		DBGC ( flexboot_nodnic, "flexboot_nodnic %p port %d could not create queue pair\n",
886 887
 				 flexboot_nodnic, ibdev->port );
887 888
 		status = MLX_OUT_OF_RESOURCES;
@@ -894,9 +895,8 @@ static int flexboot_nodnic_eth_open ( struct net_device *netdev ) {
894 895
 	MLX_FATAL_CHECK_STATUS(status, get_cq_size_err,
895 896
 			"nodnic_port_get_cq_size failed");
896 897
 
897
-	port->eth_cq = ib_create_cq ( ibdev, cq_size,
898
-			&flexboot_nodnic_eth_cq_op );
899
-	if ( !port->eth_cq ) {
898
+	if ( ( rc = ib_create_cq ( ibdev, cq_size, &flexboot_nodnic_eth_cq_op,
899
+				   &port->eth_cq ) ) != 0 ) {
900 900
 		DBGC ( flexboot_nodnic,
901 901
 			"flexboot_nodnic %p port %d could not create completion queue\n",
902 902
 			flexboot_nodnic, ibdev->port );

+ 8
- 12
src/drivers/infiniband/hermon.c Visa fil

@@ -3261,24 +3261,20 @@ static int hermon_eth_open ( struct net_device *netdev ) {
3261 3261
 		goto err_open;
3262 3262
 
3263 3263
 	/* Allocate completion queue */
3264
-	port->eth_cq = ib_create_cq ( ibdev, HERMON_ETH_NUM_CQES,
3265
-				      &hermon_eth_cq_op );
3266
-	if ( ! port->eth_cq ) {
3264
+	if ( ( rc = ib_create_cq ( ibdev, HERMON_ETH_NUM_CQES,
3265
+				   &hermon_eth_cq_op, &port->eth_cq ) ) != 0 ) {
3267 3266
 		DBGC ( hermon, "Hermon %p port %d could not create completion "
3268
-		       "queue\n", hermon, ibdev->port );
3269
-		rc = -ENOMEM;
3267
+		       "queue: %s\n", hermon, ibdev->port, strerror ( rc ) );
3270 3268
 		goto err_create_cq;
3271 3269
 	}
3272 3270
 
3273 3271
 	/* Allocate queue pair */
3274
-	port->eth_qp = ib_create_qp ( ibdev, IB_QPT_ETH,
3275
-				      HERMON_ETH_NUM_SEND_WQES, port->eth_cq,
3276
-				      HERMON_ETH_NUM_RECV_WQES, port->eth_cq,
3277
-				      &hermon_eth_qp_op, netdev->name );
3278
-	if ( ! port->eth_qp ) {
3272
+	if ( ( rc = ib_create_qp ( ibdev, IB_QPT_ETH, HERMON_ETH_NUM_SEND_WQES,
3273
+				   port->eth_cq, HERMON_ETH_NUM_RECV_WQES,
3274
+				   port->eth_cq, &hermon_eth_qp_op,
3275
+				   netdev->name, &port->eth_qp ) ) != 0 ) {
3279 3276
 		DBGC ( hermon, "Hermon %p port %d could not create queue "
3280
-		       "pair\n", hermon, ibdev->port );
3281
-		rc = -ENOMEM;
3277
+		       "pair: %s\n", hermon, ibdev->port, strerror ( rc ) );
3282 3278
 		goto err_create_qp;
3283 3279
 	}
3284 3280
 	ib_qp_set_ownerdata ( port->eth_qp, netdev );

+ 8
- 11
src/drivers/net/eoib.c Visa fil

@@ -538,22 +538,19 @@ static int eoib_open ( struct net_device *netdev ) {
538 538
 	}
539 539
 
540 540
 	/* Allocate completion queue */
541
-	eoib->cq = ib_create_cq ( ibdev, EOIB_NUM_CQES, &eoib_cq_op );
542
-	if ( ! eoib->cq ) {
543
-		DBGC ( eoib, "EoIB %s could not allocate completion queue\n",
544
-		       eoib->name );
545
-		rc = -ENOMEM;
541
+	if ( ( rc = ib_create_cq ( ibdev, EOIB_NUM_CQES, &eoib_cq_op,
542
+				   &eoib->cq ) ) != 0 ) {
543
+		DBGC ( eoib, "EoIB %s could not create completion queue: %s\n",
544
+		       eoib->name, strerror ( rc ) );
546 545
 		goto err_create_cq;
547 546
 	}
548 547
 
549 548
 	/* Allocate queue pair */
550
-	eoib->qp = ib_create_qp ( ibdev, IB_QPT_UD, EOIB_NUM_SEND_WQES,
549
+	if ( ( rc = ib_create_qp ( ibdev, IB_QPT_UD, EOIB_NUM_SEND_WQES,
551 550
 				   eoib->cq, EOIB_NUM_RECV_WQES, eoib->cq,
552
-				  &eoib_qp_op, netdev->name );
553
-	if ( ! eoib->qp ) {
554
-		DBGC ( eoib, "EoIB %s could not allocate queue pair\n",
555
-		       eoib->name );
556
-		rc = -ENOMEM;
551
+				   &eoib_qp_op, netdev->name, &eoib->qp ) )!=0){
552
+		DBGC ( eoib, "EoIB %s could not create queue pair: %s\n",
553
+		       eoib->name, strerror ( rc ) );
557 554
 		goto err_create_qp;
558 555
 	}
559 556
 	ib_qp_set_ownerdata ( eoib->qp, eoib );

+ 9
- 11
src/drivers/net/ipoib.c Visa fil

@@ -854,22 +854,20 @@ static int ipoib_open ( struct net_device *netdev ) {
854 854
 	}
855 855
 
856 856
 	/* Allocate completion queue */
857
-	ipoib->cq = ib_create_cq ( ibdev, IPOIB_NUM_CQES, &ipoib_cq_op );
858
-	if ( ! ipoib->cq ) {
859
-		DBGC ( ipoib, "IPoIB %p could not allocate completion queue\n",
860
-		       ipoib );
861
-		rc = -ENOMEM;
857
+	if ( ( rc = ib_create_cq ( ibdev, IPOIB_NUM_CQES, &ipoib_cq_op,
858
+				   &ipoib->cq ) ) != 0 ) {
859
+		DBGC ( ipoib, "IPoIB %p could not create completion queue: "
860
+		       "%s\n", ipoib, strerror ( rc ) );
862 861
 		goto err_create_cq;
863 862
 	}
864 863
 
865 864
 	/* Allocate queue pair */
866
-	ipoib->qp = ib_create_qp ( ibdev, IB_QPT_UD, IPOIB_NUM_SEND_WQES,
865
+	if ( ( rc = ib_create_qp ( ibdev, IB_QPT_UD, IPOIB_NUM_SEND_WQES,
867 866
 				   ipoib->cq, IPOIB_NUM_RECV_WQES, ipoib->cq,
868
-				   &ipoib_qp_op, netdev->name );
869
-	if ( ! ipoib->qp ) {
870
-		DBGC ( ipoib, "IPoIB %p could not allocate queue pair\n",
871
-		       ipoib );
872
-		rc = -ENOMEM;
867
+				   &ipoib_qp_op, netdev->name,
868
+				   &ipoib->qp ) ) != 0 ) {
869
+		DBGC ( ipoib, "IPoIB %p could not create queue pair: %s\n",
870
+		       ipoib, strerror ( rc ) );
873 871
 		goto err_create_qp;
874 872
 	}
875 873
 	ib_qp_set_ownerdata ( ipoib->qp, ipoib );

+ 10
- 8
src/include/ipxe/infiniband.h Visa fil

@@ -493,18 +493,20 @@ struct ib_driver {
493 493
 /** Declare an Infiniband driver */
494 494
 #define __ib_driver __table_entry ( IB_DRIVERS, 01 )
495 495
 
496
-extern struct ib_completion_queue *
497
-ib_create_cq ( struct ib_device *ibdev, unsigned int num_cqes,
498
-	       struct ib_completion_queue_operations *op );
496
+extern int ib_create_cq ( struct ib_device *ibdev, unsigned int num_cqes,
497
+			  struct ib_completion_queue_operations *op,
498
+			  struct ib_completion_queue **new_cq );
499 499
 extern void ib_destroy_cq ( struct ib_device *ibdev,
500 500
 			    struct ib_completion_queue *cq );
501 501
 extern void ib_poll_cq ( struct ib_device *ibdev,
502 502
 			 struct ib_completion_queue *cq );
503
-extern struct ib_queue_pair *
504
-ib_create_qp ( struct ib_device *ibdev, enum ib_queue_pair_type type,
505
-	       unsigned int num_send_wqes, struct ib_completion_queue *send_cq,
506
-	       unsigned int num_recv_wqes, struct ib_completion_queue *recv_cq,
507
-	       struct ib_queue_pair_operations *op, const char *name );
503
+extern int ib_create_qp ( struct ib_device *ibdev, enum ib_queue_pair_type type,
504
+			  unsigned int num_send_wqes,
505
+			  struct ib_completion_queue *send_cq,
506
+			  unsigned int num_recv_wqes,
507
+			  struct ib_completion_queue *recv_cq,
508
+			  struct ib_queue_pair_operations *op,
509
+			  const char *name, struct ib_queue_pair **new_qp );
508 510
 extern int ib_modify_qp ( struct ib_device *ibdev, struct ib_queue_pair *qp );
509 511
 extern void ib_destroy_qp ( struct ib_device *ibdev,
510 512
 			    struct ib_queue_pair *qp );

+ 26
- 19
src/net/infiniband.c Visa fil

@@ -92,11 +92,12 @@ struct errortab infiniband_errors[] __errortab = {
92 92
  * @v ibdev		Infiniband device
93 93
  * @v num_cqes		Number of completion queue entries
94 94
  * @v op		Completion queue operations
95
- * @ret cq		New completion queue
95
+ * @v new_cq		New completion queue to fill in
96
+ * @ret rc		Return status code
96 97
  */
97
-struct ib_completion_queue *
98
-ib_create_cq ( struct ib_device *ibdev, unsigned int num_cqes,
99
-	       struct ib_completion_queue_operations *op ) {
98
+int ib_create_cq ( struct ib_device *ibdev, unsigned int num_cqes,
99
+		   struct ib_completion_queue_operations *op,
100
+		   struct ib_completion_queue **new_cq ) {
100 101
 	struct ib_completion_queue *cq;
101 102
 	int rc;
102 103
 
@@ -104,8 +105,10 @@ ib_create_cq ( struct ib_device *ibdev, unsigned int num_cqes,
104 105
 
105 106
 	/* Allocate and initialise data structure */
106 107
 	cq = zalloc ( sizeof ( *cq ) );
107
-	if ( ! cq )
108
+	if ( ! cq ) {
109
+		rc = -ENOMEM;
108 110
 		goto err_alloc_cq;
111
+	}
109 112
 	cq->ibdev = ibdev;
110 113
 	list_add_tail ( &cq->list, &ibdev->cqs );
111 114
 	cq->num_cqes = num_cqes;
@@ -122,14 +125,15 @@ ib_create_cq ( struct ib_device *ibdev, unsigned int num_cqes,
122 125
 	DBGC ( ibdev, "IBDEV %s created %d-entry completion queue %p (%p) "
123 126
 	       "with CQN %#lx\n", ibdev->name, num_cqes, cq,
124 127
 	       ib_cq_get_drvdata ( cq ), cq->cqn );
125
-	return cq;
128
+	*new_cq = cq;
129
+	return 0;
126 130
 
127 131
 	ibdev->op->destroy_cq ( ibdev, cq );
128 132
  err_dev_create_cq:
129 133
 	list_del ( &cq->list );
130 134
 	free ( cq );
131 135
  err_alloc_cq:
132
-	return NULL;
136
+	return rc;
133 137
 }
134 138
 
135 139
 /**
@@ -186,19 +190,19 @@ void ib_poll_cq ( struct ib_device *ibdev,
186 190
  * @v recv_cq		Receive completion queue
187 191
  * @v op		Queue pair operations
188 192
  * @v name		Queue pair name
189
- * @ret qp		Queue pair
193
+ * @v new_qp		New queue pair to fill in
194
+ * @ret rc		Return status code
190 195
  *
191 196
  * The queue pair will be left in the INIT state; you must call
192 197
  * ib_modify_qp() before it is ready to use for sending and receiving.
193 198
  */
194
-struct ib_queue_pair * ib_create_qp ( struct ib_device *ibdev,
195
-				      enum ib_queue_pair_type type,
196
-				      unsigned int num_send_wqes,
197
-				      struct ib_completion_queue *send_cq,
198
-				      unsigned int num_recv_wqes,
199
-				      struct ib_completion_queue *recv_cq,
200
-				      struct ib_queue_pair_operations *op,
201
-				      const char *name ) {
199
+int ib_create_qp ( struct ib_device *ibdev, enum ib_queue_pair_type type,
200
+		   unsigned int num_send_wqes,
201
+		   struct ib_completion_queue *send_cq,
202
+		   unsigned int num_recv_wqes,
203
+		   struct ib_completion_queue *recv_cq,
204
+		   struct ib_queue_pair_operations *op, const char *name,
205
+		   struct ib_queue_pair **new_qp ) {
202 206
 	struct ib_queue_pair *qp;
203 207
 	size_t total_size;
204 208
 	int rc;
@@ -210,8 +214,10 @@ struct ib_queue_pair * ib_create_qp ( struct ib_device *ibdev,
210 214
 		       ( num_send_wqes * sizeof ( qp->send.iobufs[0] ) ) +
211 215
 		       ( num_recv_wqes * sizeof ( qp->recv.iobufs[0] ) ) );
212 216
 	qp = zalloc ( total_size );
213
-	if ( ! qp )
217
+	if ( ! qp ) {
218
+		rc = -ENOMEM;
214 219
 		goto err_alloc_qp;
220
+	}
215 221
 	qp->ibdev = ibdev;
216 222
 	list_add_tail ( &qp->list, &ibdev->qps );
217 223
 	qp->type = type;
@@ -265,7 +271,8 @@ struct ib_queue_pair * ib_create_qp ( struct ib_device *ibdev,
265 271
 		       ibdev->name, qp->qpn, qp->ext_qpn );
266 272
 	}
267 273
 
268
-	return qp;
274
+	*new_qp = qp;
275
+	return 0;
269 276
 
270 277
 	ibdev->op->destroy_qp ( ibdev, qp );
271 278
  err_dev_create_qp:
@@ -274,7 +281,7 @@ struct ib_queue_pair * ib_create_qp ( struct ib_device *ibdev,
274 281
 	list_del ( &qp->list );
275 282
 	free ( qp );
276 283
  err_alloc_qp:
277
-	return NULL;
284
+	return rc;
278 285
 }
279 286
 
280 287
 /**

+ 10
- 13
src/net/infiniband/ib_cmrc.c Visa fil

@@ -423,23 +423,20 @@ int ib_cmrc_open ( struct interface *xfer, struct ib_device *ibdev,
423 423
 	}
424 424
 
425 425
 	/* Create completion queue */
426
-	cmrc->cq = ib_create_cq ( ibdev, IB_CMRC_NUM_CQES,
427
-				  &ib_cmrc_completion_ops );
428
-	if ( ! cmrc->cq ) {
429
-		DBGC ( cmrc, "CMRC %s %s could not create completion queue\n",
430
-		       ibdev->name, cmrc->name );
431
-		rc = -ENOMEM;
426
+	if ( ( rc = ib_create_cq ( ibdev, IB_CMRC_NUM_CQES,
427
+				   &ib_cmrc_completion_ops, &cmrc->cq ) ) != 0){
428
+		DBGC ( cmrc, "CMRC %s %s could not create completion queue: "
429
+		       "%s\n", ibdev->name, cmrc->name, strerror ( rc ) );
432 430
 		goto err_create_cq;
433 431
 	}
434 432
 
435 433
 	/* Create queue pair */
436
-	cmrc->qp = ib_create_qp ( ibdev, IB_QPT_RC, IB_CMRC_NUM_SEND_WQES,
437
-				  cmrc->cq, IB_CMRC_NUM_RECV_WQES, cmrc->cq,
438
-				  &ib_cmrc_queue_pair_ops, name );
439
-	if ( ! cmrc->qp ) {
440
-		DBGC ( cmrc, "CMRC %s %s could not create queue pair\n",
441
-		       ibdev->name, cmrc->name );
442
-		rc = -ENOMEM;
434
+	if ( ( rc = ib_create_qp ( ibdev, IB_QPT_RC, IB_CMRC_NUM_SEND_WQES,
435
+				   cmrc->cq, IB_CMRC_NUM_RECV_WQES, cmrc->cq,
436
+				   &ib_cmrc_queue_pair_ops, name,
437
+				   &cmrc->qp ) ) != 0 ) {
438
+		DBGC ( cmrc, "CMRC %s %s could not create queue pair: %s\n",
439
+		       ibdev->name, cmrc->name, strerror ( rc ) );
443 440
 		goto err_create_qp;
444 441
 	}
445 442
 	ib_qp_set_ownerdata ( cmrc->qp, cmrc );

+ 9
- 8
src/net/infiniband/ib_mi.c Visa fil

@@ -357,19 +357,20 @@ struct ib_mad_interface * ib_create_mi ( struct ib_device *ibdev,
357 357
 	INIT_LIST_HEAD ( &mi->madx );
358 358
 
359 359
 	/* Create completion queue */
360
-	mi->cq = ib_create_cq ( ibdev, IB_MI_NUM_CQES, &ib_mi_completion_ops );
361
-	if ( ! mi->cq ) {
362
-		DBGC ( mi, "MI %p could not allocate completion queue\n", mi );
360
+	if ( ( rc = ib_create_cq ( ibdev, IB_MI_NUM_CQES, &ib_mi_completion_ops,
361
+				   &mi->cq ) ) != 0 ) {
362
+		DBGC ( mi, "MI %p could not create completion queue: %s\n",
363
+		       mi, strerror ( rc ) );
363 364
 		goto err_create_cq;
364 365
 	}
365 366
 
366 367
 	/* Create queue pair */
367 368
 	name = ( ( type == IB_QPT_SMI ) ? "SMI" : "GSI" );
368
-	mi->qp = ib_create_qp ( ibdev, type, IB_MI_NUM_SEND_WQES, mi->cq,
369
-				IB_MI_NUM_RECV_WQES, mi->cq,
370
-				&ib_mi_queue_pair_ops, name );
371
-	if ( ! mi->qp ) {
372
-		DBGC ( mi, "MI %p could not allocate queue pair\n", mi );
369
+	if ( ( rc = ib_create_qp ( ibdev, type, IB_MI_NUM_SEND_WQES, mi->cq,
370
+				   IB_MI_NUM_RECV_WQES, mi->cq,
371
+				   &ib_mi_queue_pair_ops, name, &mi->qp ) )!=0){
372
+		DBGC ( mi, "MI %p could not create queue pair: %s\n",
373
+		       mi, strerror ( rc ) );
373 374
 		goto err_create_qp;
374 375
 	}
375 376
 	ib_qp_set_ownerdata ( mi->qp, mi );

Laddar…
Avbryt
Spara