Bläddra i källkod

[infiniband] Split queue set functionality out of ipoib.c to ib_qset.c

tags/v0.9.8
Michael Brown 15 år sedan
förälder
incheckning
b25a4b6c8a
4 ändrade filer med 204 tillägg och 137 borttagningar
  1. 32
    137
      src/drivers/net/ipoib.c
  2. 1
    0
      src/include/gpxe/errfile.h
  3. 38
    0
      src/include/gpxe/ib_qset.h
  4. 133
    0
      src/net/infiniband/ib_qset.c

+ 32
- 137
src/drivers/net/ipoib.c Visa fil

@@ -28,6 +28,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
28 28
 #include <gpxe/iobuf.h>
29 29
 #include <gpxe/netdevice.h>
30 30
 #include <gpxe/infiniband.h>
31
+#include <gpxe/ib_qset.h>
31 32
 #include <gpxe/ipoib.h>
32 33
 
33 34
 /** @file
@@ -53,16 +54,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
53 54
 /** Number of IPoIB metadata completion entries */
54 55
 #define IPOIB_META_NUM_CQES 8
55 56
 
56
-/** An IPoIB queue set */
57
-struct ipoib_queue_set {
58
-	/** Completion queue */
59
-	struct ib_completion_queue *cq;
60
-	/** Queue pair */
61
-	struct ib_queue_pair *qp;
62
-	/** Receive work queue maximum fill level */
63
-	unsigned int recv_max_fill;
64
-};
65
-
66 57
 /** An IPoIB device */
67 58
 struct ipoib_device {
68 59
 	/** Network device */
@@ -70,9 +61,9 @@ struct ipoib_device {
70 61
 	/** Underlying Infiniband device */
71 62
 	struct ib_device *ibdev;
72 63
 	/** Data queue set */
73
-	struct ipoib_queue_set data;
64
+	struct ib_queue_set data;
74 65
 	/** Data queue set */
75
-	struct ipoib_queue_set meta;
66
+	struct ib_queue_set meta;
76 67
 	/** Broadcast GID */
77 68
 	struct ib_gid broadcast_gid;
78 69
 	/** Broadcast LID */
@@ -361,79 +352,6 @@ struct ll_protocol ipoib_protocol __ll_protocol = {
361 352
  ****************************************************************************
362 353
  */
363 354
 
364
-/**
365
- * Destroy queue set
366
- *
367
- * @v ipoib		IPoIB device
368
- * @v qset		Queue set
369
- */
370
-static void ipoib_destroy_qset ( struct ipoib_device *ipoib,
371
-				 struct ipoib_queue_set *qset ) {
372
-	struct ib_device *ibdev = ipoib->ibdev;
373
-
374
-	if ( qset->qp )
375
-		ib_destroy_qp ( ibdev, qset->qp );
376
-	if ( qset->cq )
377
-		ib_destroy_cq ( ibdev, qset->cq );
378
-	memset ( qset, 0, sizeof ( *qset ) );
379
-}
380
-
381
-/**
382
- * Create queue set
383
- *
384
- * @v ipoib		IPoIB device
385
- * @v qset		Queue set
386
- * @v num_cqes		Number of completion queue entries
387
- * @v cq_op		Completion queue operations
388
- * @v num_send_wqes	Number of send work queue entries
389
- * @v num_recv_wqes	Number of receive work queue entries
390
- * @v qkey		Queue key
391
- * @ret rc		Return status code
392
- */
393
-static int ipoib_create_qset ( struct ipoib_device *ipoib,
394
-			       struct ipoib_queue_set *qset,
395
-			       unsigned int num_cqes,
396
-			       struct ib_completion_queue_operations *cq_op,
397
-			       unsigned int num_send_wqes,
398
-			       unsigned int num_recv_wqes,
399
-			       unsigned long qkey ) {
400
-	struct ib_device *ibdev = ipoib->ibdev;
401
-	int rc;
402
-
403
-	/* Sanity check */
404
-	assert ( qset->cq == NULL );
405
-	assert ( qset->qp == NULL );
406
-
407
-	/* Store queue parameters */
408
-	qset->recv_max_fill = num_recv_wqes;
409
-
410
-	/* Allocate completion queue */
411
-	qset->cq = ib_create_cq ( ibdev, num_cqes, cq_op );
412
-	if ( ! qset->cq ) {
413
-		DBGC ( ipoib, "IPoIB %p could not allocate completion queue\n",
414
-		       ipoib );
415
-		rc = -ENOMEM;
416
-		goto err;
417
-	}
418
-
419
-	/* Allocate queue pair */
420
-	qset->qp = ib_create_qp ( ibdev, num_send_wqes, qset->cq,
421
-				  num_recv_wqes, qset->cq, qkey );
422
-	if ( ! qset->qp ) {
423
-		DBGC ( ipoib, "IPoIB %p could not allocate queue pair\n",
424
-		       ipoib );
425
-		rc = -ENOMEM;
426
-		goto err;
427
-	}
428
-	ib_qp_set_ownerdata ( qset->qp, ipoib->netdev );
429
-
430
-	return 0;
431
-
432
- err:
433
-	ipoib_destroy_qset ( ipoib, qset );
434
-	return rc;
435
-}
436
-
437 355
 /**
438 356
  * Transmit path record request
439 357
  *
@@ -625,9 +543,9 @@ static int ipoib_transmit ( struct net_device *netdev,
625 543
 static void ipoib_data_complete_send ( struct ib_device *ibdev __unused,
626 544
 				       struct ib_queue_pair *qp,
627 545
 				       struct io_buffer *iobuf, int rc ) {
628
-	struct net_device *netdev = ib_qp_get_ownerdata ( qp );
546
+	struct ipoib_device *ipoib = ib_qp_get_ownerdata ( qp );
629 547
 
630
-	netdev_tx_complete_err ( netdev, iobuf, rc );
548
+	netdev_tx_complete_err ( ipoib->netdev, iobuf, rc );
631 549
 }
632 550
 
633 551
 /**
@@ -643,8 +561,8 @@ static void ipoib_data_complete_recv ( struct ib_device *ibdev __unused,
643 561
 				       struct ib_queue_pair *qp,
644 562
 				       struct ib_address_vector *av,
645 563
 				       struct io_buffer *iobuf, int rc ) {
646
-	struct net_device *netdev = ib_qp_get_ownerdata ( qp );
647
-	struct ipoib_device *ipoib = netdev->priv;
564
+	struct ipoib_device *ipoib = ib_qp_get_ownerdata ( qp );
565
+	struct net_device *netdev = ipoib->netdev;
648 566
 	struct ipoib_hdr *ipoib_hdr;
649 567
 	struct ipoib_peer *src;
650 568
 
@@ -690,8 +608,7 @@ static struct ib_completion_queue_operations ipoib_data_cq_op = {
690 608
 static void ipoib_meta_complete_send ( struct ib_device *ibdev __unused,
691 609
 				       struct ib_queue_pair *qp,
692 610
 				       struct io_buffer *iobuf, int rc ) {
693
-	struct net_device *netdev = ib_qp_get_ownerdata ( qp );
694
-	struct ipoib_device *ipoib = netdev->priv;
611
+	struct ipoib_device *ipoib = ib_qp_get_ownerdata ( qp );
695 612
 
696 613
 	if ( rc != 0 ) {
697 614
 		DBGC ( ipoib, "IPoIB %p metadata TX completion error: %s\n",
@@ -769,8 +686,7 @@ ipoib_meta_complete_recv ( struct ib_device *ibdev __unused,
769 686
 			   struct ib_queue_pair *qp,
770 687
 			   struct ib_address_vector *av __unused,
771 688
 			   struct io_buffer *iobuf, int rc ) {
772
-	struct net_device *netdev = ib_qp_get_ownerdata ( qp );
773
-	struct ipoib_device *ipoib = netdev->priv;
689
+	struct ipoib_device *ipoib = ib_qp_get_ownerdata ( qp );
774 690
 	struct ib_mad_sa *sa;
775 691
 
776 692
 	if ( rc != 0 ) {
@@ -818,28 +734,6 @@ static struct ib_completion_queue_operations ipoib_meta_cq_op = {
818 734
 	.complete_recv = ipoib_meta_complete_recv,
819 735
 };
820 736
 
821
-/**
822
- * Refill IPoIB receive ring
823
- *
824
- * @v ipoib		IPoIB device
825
- */
826
-static void ipoib_refill_recv ( struct ipoib_device *ipoib,
827
-				struct ipoib_queue_set *qset ) {
828
-	struct ib_device *ibdev = ipoib->ibdev;
829
-	struct io_buffer *iobuf;
830
-	int rc;
831
-
832
-	while ( qset->qp->recv.fill < qset->recv_max_fill ) {
833
-		iobuf = alloc_iob ( IPOIB_PKT_LEN );
834
-		if ( ! iobuf )
835
-			break;
836
-		if ( ( rc = ib_post_recv ( ibdev, qset->qp, iobuf ) ) != 0 ) {
837
-			free_iob ( iobuf );
838
-			break;
839
-		}
840
-	}
841
-}
842
-
843 737
 /**
844 738
  * Poll IPoIB network device
845 739
  *
@@ -851,8 +745,8 @@ static void ipoib_poll ( struct net_device *netdev ) {
851 745
 
852 746
 	ib_poll_cq ( ibdev, ipoib->meta.cq );
853 747
 	ib_poll_cq ( ibdev, ipoib->data.cq );
854
-	ipoib_refill_recv ( ipoib, &ipoib->meta );
855
-	ipoib_refill_recv ( ipoib, &ipoib->data );
748
+	ib_qset_refill_recv ( ibdev, &ipoib->meta );
749
+	ib_qset_refill_recv ( ibdev, &ipoib->data );
856 750
 }
857 751
 
858 752
 /**
@@ -928,46 +822,47 @@ static void ipoib_leave_broadcast_group ( struct ipoib_device *ipoib ) {
928 822
  */
929 823
 static int ipoib_open ( struct net_device *netdev ) {
930 824
 	struct ipoib_device *ipoib = netdev->priv;
825
+	struct ib_device *ibdev = ipoib->ibdev;
931 826
 	struct ipoib_mac *mac = ( ( struct ipoib_mac * ) netdev->ll_addr );
932 827
 	int rc;
933 828
 
934 829
 	/* Open IB device */
935
-	if ( ( rc = ib_open ( ipoib->ibdev ) ) != 0 ) {
830
+	if ( ( rc = ib_open ( ibdev ) ) != 0 ) {
936 831
 		DBGC ( ipoib, "IPoIB %p could not open device: %s\n",
937 832
 		       ipoib, strerror ( rc ) );
938 833
 		goto err_ib_open;
939 834
 	}
940 835
 
941 836
 	/* Allocate metadata queue set */
942
-	if ( ( rc = ipoib_create_qset ( ipoib, &ipoib->meta,
943
-					IPOIB_META_NUM_CQES,
944
-					&ipoib_meta_cq_op,
945
-					IPOIB_META_NUM_SEND_WQES,
946
-					IPOIB_META_NUM_RECV_WQES,
947
-					IB_GLOBAL_QKEY ) ) != 0 ) {
837
+	if ( ( rc = ib_create_qset ( ibdev, &ipoib->meta,
838
+				     IPOIB_META_NUM_CQES, &ipoib_meta_cq_op,
839
+				     IPOIB_META_NUM_SEND_WQES,
840
+				     IPOIB_META_NUM_RECV_WQES,
841
+				     IPOIB_PKT_LEN, IB_GLOBAL_QKEY ) ) != 0 ) {
948 842
 		DBGC ( ipoib, "IPoIB %p could not allocate metadata QP: %s\n",
949 843
 		       ipoib, strerror ( rc ) );
950 844
 		goto err_create_meta_qset;
951 845
 	}
846
+	ib_qp_set_ownerdata ( ipoib->meta.qp, ipoib );
952 847
 
953 848
 	/* Allocate data queue set */
954
-	if ( ( rc = ipoib_create_qset ( ipoib, &ipoib->data,
955
-					IPOIB_DATA_NUM_CQES,
956
-					&ipoib_data_cq_op,
957
-					IPOIB_DATA_NUM_SEND_WQES,
958
-					IPOIB_DATA_NUM_RECV_WQES,
959
-					IB_GLOBAL_QKEY ) ) != 0 ) {
849
+	if ( ( rc = ib_create_qset ( ibdev, &ipoib->data,
850
+				     IPOIB_DATA_NUM_CQES, &ipoib_data_cq_op,
851
+				     IPOIB_DATA_NUM_SEND_WQES,
852
+				     IPOIB_DATA_NUM_RECV_WQES,
853
+				     IPOIB_PKT_LEN, IB_GLOBAL_QKEY ) ) != 0 ) {
960 854
 		DBGC ( ipoib, "IPoIB %p could not allocate data QP: %s\n",
961 855
 		       ipoib, strerror ( rc ) );
962 856
 		goto err_create_data_qset;
963 857
 	}
858
+	ib_qp_set_ownerdata ( ipoib->data.qp, ipoib );
964 859
 
965 860
 	/* Update MAC address with data QPN */
966 861
 	mac->qpn = htonl ( ipoib->data.qp->qpn );
967 862
 
968 863
 	/* Fill receive rings */
969
-	ipoib_refill_recv ( ipoib, &ipoib->meta );
970
-	ipoib_refill_recv ( ipoib, &ipoib->data );
864
+	ib_qset_refill_recv ( ibdev, &ipoib->meta );
865
+	ib_qset_refill_recv ( ibdev, &ipoib->data );
971 866
 
972 867
 	/* Join broadcast group */
973 868
 	if ( ( rc = ipoib_join_broadcast_group ( ipoib ) ) != 0 ) {
@@ -979,11 +874,11 @@ static int ipoib_open ( struct net_device *netdev ) {
979 874
 	return 0;
980 875
 
981 876
  err_join_broadcast:
982
-	ipoib_destroy_qset ( ipoib, &ipoib->data );
877
+	ib_destroy_qset ( ibdev, &ipoib->data );
983 878
  err_create_data_qset:
984
-	ipoib_destroy_qset ( ipoib, &ipoib->meta );
879
+	ib_destroy_qset ( ibdev, &ipoib->meta );
985 880
  err_create_meta_qset:
986
-	ib_close ( ipoib->ibdev );
881
+	ib_close ( ibdev );
987 882
  err_ib_open:
988 883
 	return rc;
989 884
 }
@@ -1004,8 +899,8 @@ static void ipoib_close ( struct net_device *netdev ) {
1004 899
 	mac->qpn = 0;
1005 900
 
1006 901
 	/* Tear down the queues */
1007
-	ipoib_destroy_qset ( ipoib, &ipoib->data );
1008
-	ipoib_destroy_qset ( ipoib, &ipoib->meta );
902
+	ib_destroy_qset ( ipoib->ibdev, &ipoib->data );
903
+	ib_destroy_qset ( ipoib->ibdev, &ipoib->meta );
1009 904
 
1010 905
 	/* Close IB device */
1011 906
 	ib_close ( ipoib->ibdev );

+ 1
- 0
src/include/gpxe/errfile.h Visa fil

@@ -143,6 +143,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
143 143
 #define ERRFILE_ib_sma			( ERRFILE_NET | 0x00170000 )
144 144
 #define ERRFILE_ib_packet		( ERRFILE_NET | 0x00180000 )
145 145
 #define ERRFILE_icmp			( ERRFILE_NET | 0x00190000 )
146
+#define ERRFILE_ib_qset			( ERRFILE_NET | 0x001a0000 )
146 147
 
147 148
 #define ERRFILE_image		      ( ERRFILE_IMAGE | 0x00000000 )
148 149
 #define ERRFILE_elf		      ( ERRFILE_IMAGE | 0x00010000 )

+ 38
- 0
src/include/gpxe/ib_qset.h Visa fil

@@ -0,0 +1,38 @@
1
+#ifndef _GPXE_IB_QSET_H
2
+#define _GPXE_IB_QSET_H
3
+
4
+/** @file
5
+ *
6
+ * Infiniband queue sets
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER );
11
+
12
+#include <stdint.h>
13
+#include <gpxe/infiniband.h>
14
+
15
+/** An Infiniband queue set */
16
+struct ib_queue_set {
17
+	/** Completion queue */
18
+	struct ib_completion_queue *cq;
19
+	/** Queue pair */
20
+	struct ib_queue_pair *qp;
21
+	/** Receive work queue maximum fill level */
22
+	unsigned int recv_max_fill;
23
+	/** Receive packet length */
24
+	size_t recv_pkt_len;
25
+};
26
+
27
+extern int ib_create_qset ( struct ib_device *ibdev,
28
+			    struct ib_queue_set *qset, unsigned int num_cqes,
29
+			    struct ib_completion_queue_operations *cq_op,
30
+			    unsigned int num_send_wqes,
31
+			    unsigned int num_recv_wqes, size_t recv_pkt_len,
32
+			    unsigned long qkey );
33
+extern void ib_qset_refill_recv ( struct ib_device *ibdev,
34
+				  struct ib_queue_set *qset );
35
+extern void ib_destroy_qset ( struct ib_device *ibdev,
36
+			      struct ib_queue_set *qset );
37
+
38
+#endif /* _GPXE_IB_QSET_H */

+ 133
- 0
src/net/infiniband/ib_qset.c Visa fil

@@ -0,0 +1,133 @@
1
+/*
2
+ * Copyright (C) 2009 Michael Brown <mbrown@fensystems.co.uk>.
3
+ *
4
+ * This program is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as
6
+ * published by the Free Software Foundation; either version 2 of the
7
+ * License, or any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful, but
10
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ */
18
+
19
+FILE_LICENCE ( GPL2_OR_LATER );
20
+
21
+#include <errno.h>
22
+#include <string.h>
23
+#include <gpxe/iobuf.h>
24
+#include <gpxe/infiniband.h>
25
+#include <gpxe/ib_qset.h>
26
+
27
+/**
28
+ * @file
29
+ *
30
+ * Infiniband queue sets
31
+ *
32
+ */
33
+
34
+/**
35
+ * Create queue set
36
+ *
37
+ * @v ibdev		Infiniband device
38
+ * @v qset		Queue set
39
+ * @v num_cqes		Number of completion queue entries
40
+ * @v cq_op		Completion queue operations
41
+ * @v num_send_wqes	Number of send work queue entries
42
+ * @v num_recv_wqes	Number of receive work queue entries
43
+ * @v recv_pkt_len	Receive packet length
44
+ * @v qkey		Queue key
45
+ * @ret rc		Return status code
46
+ */
47
+int ib_create_qset ( struct ib_device *ibdev, struct ib_queue_set *qset,
48
+		     unsigned int num_cqes,
49
+		     struct ib_completion_queue_operations *cq_op,
50
+		     unsigned int num_send_wqes, unsigned int num_recv_wqes,
51
+		     size_t recv_pkt_len, unsigned long qkey ) {
52
+	int rc;
53
+
54
+	/* Sanity check */
55
+	assert ( qset->cq == NULL );
56
+	assert ( qset->qp == NULL );
57
+
58
+	/* Store queue parameters */
59
+	qset->recv_max_fill = num_recv_wqes;
60
+	qset->recv_pkt_len = recv_pkt_len;
61
+
62
+	/* Allocate completion queue */
63
+	qset->cq = ib_create_cq ( ibdev, num_cqes, cq_op );
64
+	if ( ! qset->cq ) {
65
+		DBGC ( ibdev, "IBDEV %p could not allocate completion queue\n",
66
+		       ibdev );
67
+		rc = -ENOMEM;
68
+		goto err;
69
+	}
70
+
71
+	/* Allocate queue pair */
72
+	qset->qp = ib_create_qp ( ibdev, num_send_wqes, qset->cq,
73
+				  num_recv_wqes, qset->cq, qkey );
74
+	if ( ! qset->qp ) {
75
+		DBGC ( ibdev, "IBDEV %p could not allocate queue pair\n",
76
+		       ibdev );
77
+		rc = -ENOMEM;
78
+		goto err;
79
+	}
80
+
81
+	return 0;
82
+
83
+ err:
84
+	ib_destroy_qset ( ibdev, qset );
85
+	return rc;
86
+}
87
+
88
+/**
89
+ * Refill IPoIB receive ring
90
+ *
91
+ * @v ibdev		Infiniband device
92
+ * @v qset		Queue set
93
+ */
94
+void ib_qset_refill_recv ( struct ib_device *ibdev,
95
+			   struct ib_queue_set *qset ) {
96
+	struct io_buffer *iobuf;
97
+	int rc;
98
+
99
+	while ( qset->qp->recv.fill < qset->recv_max_fill ) {
100
+
101
+		/* Allocate I/O buffer */
102
+		iobuf = alloc_iob ( qset->recv_pkt_len );
103
+		if ( ! iobuf ) {
104
+			/* Non-fatal; we will refill on next attempt */
105
+			return;
106
+		}
107
+
108
+		/* Post I/O buffer */
109
+		if ( ( rc = ib_post_recv ( ibdev, qset->qp, iobuf ) ) != 0 ) {
110
+			DBGC ( ibdev, "IBDEV %p could not refill: %s\n",
111
+			       ibdev, strerror ( rc ) );
112
+			free_iob ( iobuf );
113
+			/* Give up */
114
+			return;
115
+		}
116
+	}
117
+}
118
+
119
+/**
120
+ * Destroy queue set
121
+ *
122
+ * @v ibdev		Infiniband device
123
+ * @v qset		Queue set
124
+ */
125
+void ib_destroy_qset ( struct ib_device *ibdev,
126
+		       struct ib_queue_set *qset ) {
127
+
128
+	if ( qset->qp )
129
+		ib_destroy_qp ( ibdev, qset->qp );
130
+	if ( qset->cq )
131
+		ib_destroy_cq ( ibdev, qset->cq );
132
+	memset ( qset, 0, sizeof ( *qset ) );
133
+}

Laddar…
Avbryt
Spara