Browse Source

[infiniband] Implement SMA as an instance of a GMA

The GMA code was based upon the SMA code.  We can save space by making
the SMA simply an instance of the GMA.
tags/v0.9.8
Michael Brown 15 years ago
parent
commit
165074c188

+ 3
- 8
src/drivers/infiniband/linda.c View File

272
 	return 0;
272
 	return 0;
273
 }
273
 }
274
 
274
 
275
-/** Linda subnet management operations */
276
-static struct ib_sma_operations linda_sma_operations = {
277
-	.set_port_info	= linda_set_port_info,
278
-};
279
-
280
 /***************************************************************************
275
 /***************************************************************************
281
  *
276
  *
282
  * Context allocation
277
  * Context allocation
1464
 	.close		= linda_close,
1459
 	.close		= linda_close,
1465
 	.mcast_attach	= linda_mcast_attach,
1460
 	.mcast_attach	= linda_mcast_attach,
1466
 	.mcast_detach	= linda_mcast_detach,
1461
 	.mcast_detach	= linda_mcast_detach,
1462
+	.set_port_info	= linda_set_port_info,
1467
 };
1463
 };
1468
 
1464
 
1469
 /***************************************************************************
1465
 /***************************************************************************
2340
 		goto err_init_ib_serdes;
2336
 		goto err_init_ib_serdes;
2341
 
2337
 
2342
 	/* Create the SMA */
2338
 	/* Create the SMA */
2343
-	if ( ( rc = ib_create_sma ( &linda->sma, ibdev,
2344
-				    &linda_sma_operations ) ) != 0 )
2339
+	if ( ( rc = ib_create_sma ( &linda->sma, ibdev ) ) != 0 )
2345
 		goto err_create_sma;
2340
 		goto err_create_sma;
2346
 	/* If the SMA doesn't get context 0, we're screwed */
2341
 	/* If the SMA doesn't get context 0, we're screwed */
2347
-	assert ( linda_qpn_to_ctx ( linda->sma.qp->qpn ) == 0 );
2342
+	assert ( linda_qpn_to_ctx ( linda->sma.gma.qp->qpn ) == 0 );
2348
 
2343
 
2349
 	/* Register Infiniband device */
2344
 	/* Register Infiniband device */
2350
 	if ( ( rc = register_ibdev ( ibdev ) ) != 0 ) {
2345
 	if ( ( rc = register_ibdev ( ibdev ) ) != 0 ) {

+ 2
- 0
src/include/gpxe/ib_gma.h View File

23
 struct ib_gma_handler {
23
 struct ib_gma_handler {
24
 	/** Management class */
24
 	/** Management class */
25
 	uint8_t mgmt_class;
25
 	uint8_t mgmt_class;
26
+	/** Management class don't-care bits */
27
+	uint8_t mgmt_class_ignore;
26
 	/** Class version */
28
 	/** Class version */
27
 	uint8_t class_version;
29
 	uint8_t class_version;
28
 	/** Method */
30
 	/** Method */

+ 3
- 0
src/include/gpxe/ib_mad.h View File

30
 	uint8_t reserved[28];
30
 	uint8_t reserved[28];
31
 } __attribute__ (( packed ));
31
 } __attribute__ (( packed ));
32
 
32
 
33
+/** Bits to ignore in the management class for subnet management MADs */
34
+#define IB_SMP_CLASS_IGNORE			0x80
35
+
33
 /** Subnet management class version */
36
 /** Subnet management class version */
34
 #define IB_SMP_CLASS_VERSION			1
37
 #define IB_SMP_CLASS_VERSION			1
35
 
38
 

+ 4
- 39
src/include/gpxe/ib_sma.h View File

10
 FILE_LICENCE ( GPL2_OR_LATER );
10
 FILE_LICENCE ( GPL2_OR_LATER );
11
 
11
 
12
 #include <gpxe/infiniband.h>
12
 #include <gpxe/infiniband.h>
13
-
14
-/** Infiniband Subnet Management Agent operations */
15
-struct ib_sma_operations {
16
-	/** Set port information
17
-	 *
18
-	 * @v ibdev		Infiniband device
19
-	 * @v port_info		New port information
20
-	 */
21
-	int ( * set_port_info ) ( struct ib_device *ibdev,
22
-				  const struct ib_port_info *port_info );
23
-};
13
+#include <gpxe/ib_gma.h>
24
 
14
 
25
 /** An Infiniband Subnet Management Agent */
15
 /** An Infiniband Subnet Management Agent */
26
 struct ib_sma {
16
 struct ib_sma {
27
-	/** Infiniband device */
28
-	struct ib_device *ibdev;
29
-	/** SMA operations */
30
-	struct ib_sma_operations *op;
31
-	/** SMA completion queue */
32
-	struct ib_completion_queue *cq;
33
-	/** SMA queue pair */
34
-	struct ib_queue_pair *qp;
17
+	/** General management agent */
18
+	struct ib_gma gma;
35
 };
19
 };
36
 
20
 
37
-/** SMA number of send WQEs
38
- *
39
- * This is a policy decision.
40
- */
41
-#define IB_SMA_NUM_SEND_WQES 4
42
-
43
-/** SMA number of receive WQEs
44
- *
45
- * This is a policy decision.
46
- */
47
-#define IB_SMA_NUM_RECV_WQES 2
48
-
49
-/** SMA number of completion queue entries
50
- *
51
- * This is a policy decision
52
- */
53
-#define IB_SMA_NUM_CQES 8
54
-
55
-extern int ib_create_sma ( struct ib_sma *sma, struct ib_device *ibdev,
56
-			   struct ib_sma_operations *op );
21
+extern int ib_create_sma ( struct ib_sma *sma, struct ib_device *ibdev );
57
 extern void ib_destroy_sma ( struct ib_sma *sma );
22
 extern void ib_destroy_sma ( struct ib_sma *sma );
58
 
23
 
59
 #endif /* _GPXE_IB_SMA_H */
24
 #endif /* _GPXE_IB_SMA_H */

+ 12
- 0
src/include/gpxe/infiniband.h View File

327
 	void ( * mcast_detach ) ( struct ib_device *ibdev,
327
 	void ( * mcast_detach ) ( struct ib_device *ibdev,
328
 				  struct ib_queue_pair *qp,
328
 				  struct ib_queue_pair *qp,
329
 				  struct ib_gid *gid );
329
 				  struct ib_gid *gid );
330
+	/** Set port information
331
+	 *
332
+	 * @v ibdev		Infiniband device
333
+	 * @v port_info		New port information
334
+	 *
335
+	 * This method is required only by adapters that do not have
336
+	 * an embedded SMA.
337
+	 */
338
+	int ( * set_port_info ) ( struct ib_device *ibdev,
339
+				  const struct ib_port_info *port_info );
330
 };
340
 };
331
 
341
 
332
 /** An Infiniband device */
342
 /** An Infiniband device */
420
 			      struct ib_queue_pair *qp, struct ib_gid *gid );
430
 			      struct ib_queue_pair *qp, struct ib_gid *gid );
421
 extern int ib_get_hca_info ( struct ib_device *ibdev,
431
 extern int ib_get_hca_info ( struct ib_device *ibdev,
422
 			     struct ib_gid_half *hca_guid );
432
 			     struct ib_gid_half *hca_guid );
433
+extern int ib_set_port_info ( struct ib_device *ibdev,
434
+			      const struct ib_port_info *port_info );
423
 extern struct ib_device * alloc_ibdev ( size_t priv_size );
435
 extern struct ib_device * alloc_ibdev ( size_t priv_size );
424
 extern int register_ibdev ( struct ib_device *ibdev );
436
 extern int register_ibdev ( struct ib_device *ibdev );
425
 extern void unregister_ibdev ( struct ib_device *ibdev );
437
 extern void unregister_ibdev ( struct ib_device *ibdev );

+ 25
- 0
src/net/infiniband.c View File

644
 	return num_ports;
644
 	return num_ports;
645
 }
645
 }
646
 
646
 
647
+/** Set port information
648
+ *
649
+ * @v ibdev		Infiniband device
650
+ * @v port_info		New port information
651
+ */
652
+int ib_set_port_info ( struct ib_device *ibdev,
653
+		       const struct ib_port_info *port_info ) {
654
+	int rc;
655
+
656
+	/* Adapters with embedded SMAs do not need to support this method */
657
+	if ( ! ibdev->op->set_port_info ) {
658
+		DBGC ( ibdev, "IBDEV %p does not support setting port "
659
+		       "information\n", ibdev );
660
+		return -ENOTSUP;
661
+	}
662
+
663
+	if ( ( rc = ibdev->op->set_port_info ( ibdev, port_info ) ) != 0 ) {
664
+		DBGC ( ibdev, "IBDEV %p could not set port information: %s\n",
665
+		       ibdev, strerror ( rc ) );
666
+		return rc;
667
+	}
668
+
669
+	return 0;
670
+};
671
+
647
 /***************************************************************************
672
 /***************************************************************************
648
  *
673
  *
649
  * Event queues
674
  * Event queues

+ 2
- 1
src/net/infiniband/ib_gma.c View File

86
 	struct ib_gma_handler *handler;
86
 	struct ib_gma_handler *handler;
87
 
87
 
88
 	for_each_table_entry ( handler, IB_GMA_HANDLERS ) {
88
 	for_each_table_entry ( handler, IB_GMA_HANDLERS ) {
89
-		if ( ( handler->mgmt_class == hdr->mgmt_class ) &&
89
+		if ( ( ( handler->mgmt_class & ~handler->mgmt_class_ignore ) ==
90
+		       ( hdr->mgmt_class & ~handler->mgmt_class_ignore ) ) &&
90
 		     ( handler->class_version == hdr->class_version ) &&
91
 		     ( handler->class_version == hdr->class_version ) &&
91
 		     ( handler->method == hdr->method ) &&
92
 		     ( handler->method == hdr->method ) &&
92
 		     ( handler->attr_id == hdr->attr_id ) ) {
93
 		     ( handler->attr_id == hdr->attr_id ) ) {

+ 142
- 315
src/net/infiniband/ib_sma.c View File

26
 #include <unistd.h>
26
 #include <unistd.h>
27
 #include <byteswap.h>
27
 #include <byteswap.h>
28
 #include <gpxe/infiniband.h>
28
 #include <gpxe/infiniband.h>
29
-#include <gpxe/iobuf.h>
29
+#include <gpxe/ib_gma.h>
30
 #include <gpxe/ib_sma.h>
30
 #include <gpxe/ib_sma.h>
31
 
31
 
32
 /**
32
 /**
39
 /**
39
 /**
40
  * Get node information
40
  * Get node information
41
  *
41
  *
42
- * @v sma		Subnet management agent
43
- * @v get		Attribute to get
42
+ * @v gma		General management agent
43
+ * @v mad		MAD
44
+ * @ret rc		Return status code
44
  */
45
  */
45
-static void ib_sma_get_node_info ( struct ib_sma *sma,
46
-				   union ib_smp_data *get ) {
47
-	struct ib_device *ibdev = sma->ibdev;
48
-	struct ib_node_info *node_info = &get->node_info;
46
+static int ib_sma_get_node_info ( struct ib_gma *gma,
47
+				  union ib_mad *mad ) {
48
+	struct ib_device *ibdev = gma->ibdev;
49
+	struct ib_node_info *node_info = &mad->smp.smp_data.node_info;
49
 
50
 
50
 	memset ( node_info, 0, sizeof ( *node_info ) );
51
 	memset ( node_info, 0, sizeof ( *node_info ) );
51
 	node_info->base_version = IB_MGMT_BASE_VERSION;
52
 	node_info->base_version = IB_MGMT_BASE_VERSION;
58
 		 sizeof ( node_info->port_guid ) );
59
 		 sizeof ( node_info->port_guid ) );
59
 	node_info->partition_cap = htons ( 1 );
60
 	node_info->partition_cap = htons ( 1 );
60
 	node_info->local_port_num = ibdev->port;
61
 	node_info->local_port_num = ibdev->port;
62
+
63
+	return 0;
61
 }
64
 }
62
 
65
 
63
 /**
66
 /**
64
  * Get node description
67
  * Get node description
65
  *
68
  *
66
- * @v sma		Subnet management agent
67
- * @v get		Attribute to get
69
+ * @v gma		General management agent
70
+ * @v mad		MAD
71
+ * @ret rc		Return status code
68
  */
72
  */
69
-static void ib_sma_get_node_desc ( struct ib_sma *sma,
70
-				   union ib_smp_data *get ) {
71
-	struct ib_device *ibdev = sma->ibdev;
72
-	struct ib_node_desc *node_desc = &get->node_desc;
73
+static int ib_sma_get_node_desc ( struct ib_gma *gma,
74
+				  union ib_mad *mad ) {
75
+	struct ib_device *ibdev = gma->ibdev;
76
+	struct ib_node_desc *node_desc = &mad->smp.smp_data.node_desc;
73
 	struct ib_gid_half *guid = &ibdev->gid.u.half[1];
77
 	struct ib_gid_half *guid = &ibdev->gid.u.half[1];
74
 
78
 
75
 	memset ( node_desc, 0, sizeof ( *node_desc ) );
79
 	memset ( node_desc, 0, sizeof ( *node_desc ) );
78
 		   guid->bytes[0], guid->bytes[1], guid->bytes[2],
82
 		   guid->bytes[0], guid->bytes[1], guid->bytes[2],
79
 		   guid->bytes[3], guid->bytes[4], guid->bytes[5],
83
 		   guid->bytes[3], guid->bytes[4], guid->bytes[5],
80
 		   guid->bytes[6], guid->bytes[7], ibdev->dev->name );
84
 		   guid->bytes[6], guid->bytes[7], ibdev->dev->name );
85
+
86
+	return 0;
81
 }
87
 }
82
 
88
 
83
 /**
89
 /**
84
  * Get GUID information
90
  * Get GUID information
85
  *
91
  *
86
- * @v sma		Subnet management agent
87
- * @v get		Attribute to get
92
+ * @v gma		General management agent
93
+ * @v mad		MAD
94
+ * @ret rc		Return status code
88
  */
95
  */
89
-static void ib_sma_get_guid_info ( struct ib_sma *sma,
90
-				   union ib_smp_data *get ) {
91
-	struct ib_device *ibdev = sma->ibdev;
92
-	struct ib_guid_info *guid_info = &get->guid_info;
96
+static int ib_sma_get_guid_info ( struct ib_gma *gma,
97
+				  union ib_mad *mad ) {
98
+	struct ib_device *ibdev = gma->ibdev;
99
+	struct ib_guid_info *guid_info = &mad->smp.smp_data.guid_info;
93
 
100
 
94
 	memset ( guid_info, 0, sizeof ( *guid_info ) );
101
 	memset ( guid_info, 0, sizeof ( *guid_info ) );
95
 	memcpy ( guid_info->guid[0], &ibdev->gid.u.half[1],
102
 	memcpy ( guid_info->guid[0], &ibdev->gid.u.half[1],
96
 		 sizeof ( guid_info->guid[0] ) );
103
 		 sizeof ( guid_info->guid[0] ) );
104
+
105
+	return 0;
97
 }
106
 }
98
 
107
 
99
 /**
108
 /**
100
  * Get port information
109
  * Get port information
101
  *
110
  *
102
- * @v sma		Subnet management agent
103
- * @v get		Attribute to get
111
+ * @v gma		General management agent
112
+ * @v mad		MAD
113
+ * @ret rc		Return status code
104
  */
114
  */
105
-static void ib_sma_get_port_info ( struct ib_sma *sma,
106
-				   union ib_smp_data *get ) {
107
-	struct ib_device *ibdev = sma->ibdev;
108
-	struct ib_port_info *port_info = &get->port_info;
115
+static int ib_sma_get_port_info ( struct ib_gma *gma,
116
+				  union ib_mad *mad ) {
117
+	struct ib_device *ibdev = gma->ibdev;
118
+	struct ib_port_info *port_info = &mad->smp.smp_data.port_info;
109
 
119
 
110
 	memset ( port_info, 0, sizeof ( *port_info ) );
120
 	memset ( port_info, 0, sizeof ( *port_info ) );
111
 	memcpy ( port_info->gid_prefix, &ibdev->gid.u.half[0],
121
 	memcpy ( port_info->gid_prefix, &ibdev->gid.u.half[0],
129
 	port_info->init_type_reply__mtu_cap = IB_MTU_2048;
139
 	port_info->init_type_reply__mtu_cap = IB_MTU_2048;
130
 	port_info->operational_vls__enforcement = ( IB_VL_0 << 4 );
140
 	port_info->operational_vls__enforcement = ( IB_VL_0 << 4 );
131
 	port_info->guid_cap = 1;
141
 	port_info->guid_cap = 1;
142
+
143
+	return 0;
132
 }
144
 }
133
 
145
 
134
 /**
146
 /**
135
  * Set port information
147
  * Set port information
136
  *
148
  *
137
- * @v sma		Subnet management agent
138
- * @v set		Attribute to set
149
+ * @v gma		General management agent
150
+ * @v mad		MAD
139
  * @ret rc		Return status code
151
  * @ret rc		Return status code
140
  */
152
  */
141
-static int ib_sma_set_port_info ( struct ib_sma *sma,
142
-				  const union ib_smp_data *set ) {
143
-	struct ib_device *ibdev = sma->ibdev;
144
-	const struct ib_port_info *port_info = &set->port_info;
153
+static int ib_sma_set_port_info ( struct ib_gma *gma,
154
+				  union ib_mad *mad ) {
155
+	struct ib_device *ibdev = gma->ibdev;
156
+	const struct ib_port_info *port_info = &mad->smp.smp_data.port_info;
157
+	int rc;
145
 
158
 
146
 	memcpy ( &ibdev->gid.u.half[0], port_info->gid_prefix,
159
 	memcpy ( &ibdev->gid.u.half[0], port_info->gid_prefix,
147
 		 sizeof ( ibdev->gid.u.half[0] ) );
160
 		 sizeof ( ibdev->gid.u.half[0] ) );
149
 	ibdev->sm_lid = ntohs ( port_info->mastersm_lid );
162
 	ibdev->sm_lid = ntohs ( port_info->mastersm_lid );
150
 	ibdev->sm_sl = ( port_info->neighbour_mtu__mastersm_sl & 0xf );
163
 	ibdev->sm_sl = ( port_info->neighbour_mtu__mastersm_sl & 0xf );
151
 
164
 
152
-	if ( ! sma->op->set_port_info ) {
153
-		/* Not an error; we just ignore all other settings */
154
-		return 0;
165
+	if ( ( rc = ib_set_port_info ( ibdev, port_info ) ) != 0 ) {
166
+		DBGC ( ibdev, "IBDEV %p could not set port information: %s\n",
167
+		       ibdev, strerror ( rc ) );
168
+		mad->hdr.status =
169
+			htons ( IB_MGMT_STATUS_UNSUPPORTED_METHOD_ATTR );
155
 	}
170
 	}
156
 
171
 
157
-	return sma->op->set_port_info ( ibdev, port_info );
172
+	return ib_sma_get_port_info ( gma, mad );
158
 }
173
 }
159
 
174
 
160
 /**
175
 /**
161
  * Get partition key table
176
  * Get partition key table
162
  *
177
  *
163
- * @v sma		Subnet management agent
164
- * @v get		Attribute to get
178
+ * @v gma		General management agent
179
+ * @v mad		MAD
180
+ * @ret rc		Return status code
165
  */
181
  */
166
-static void ib_sma_get_pkey_table ( struct ib_sma *sma,
167
-				    union ib_smp_data *get ) {
168
-	struct ib_device *ibdev = sma->ibdev;
169
-	struct ib_pkey_table *pkey_table = &get->pkey_table;
182
+static int ib_sma_get_pkey_table ( struct ib_gma *gma,
183
+				   union ib_mad *mad ) {
184
+	struct ib_device *ibdev = gma->ibdev;
185
+	struct ib_pkey_table *pkey_table = &mad->smp.smp_data.pkey_table;
170
 
186
 
171
 	memset ( pkey_table, 0, sizeof ( *pkey_table ) );
187
 	memset ( pkey_table, 0, sizeof ( *pkey_table ) );
172
 	pkey_table->pkey[0] = htons ( ibdev->pkey );
188
 	pkey_table->pkey[0] = htons ( ibdev->pkey );
173
-}
174
 
189
 
175
-/**
176
- * Set partition key table
177
- *
178
- * @v sma		Subnet management agent
179
- * @v set		Attribute to set
180
- */
181
-static int ib_sma_set_pkey_table ( struct ib_sma *sma,
182
-				   const union ib_smp_data *get ) {
183
-	struct ib_device *ibdev = sma->ibdev;
184
-	const struct ib_pkey_table *pkey_table = &get->pkey_table;
185
-
186
-	ibdev->pkey = ntohs ( pkey_table->pkey[0] );
187
 	return 0;
190
 	return 0;
188
 }
191
 }
189
 
192
 
190
-/** An attribute handler */
191
-struct ib_sma_handler {
192
-	/** Attribute (in network byte order) */
193
-	uint16_t attr_id;
194
-	/** Get attribute
195
-	 *
196
-	 * @v sma	Subnet management agent
197
-	 * @v get	Attribute to get
198
-	 * @ret rc	Return status code
199
-	 */
200
-	void ( * get ) ( struct ib_sma *sma, union ib_smp_data *get );
201
-	/** Set attribute
202
-	 *
203
-	 * @v sma	Subnet management agent
204
-	 * @v set	Attribute to set
205
-	 * @ret rc	Return status code
206
-	 */
207
-	int ( * set ) ( struct ib_sma *sma, const union ib_smp_data *set );
208
-};
209
-
210
-/** List of attribute handlers */
211
-static struct ib_sma_handler ib_sma_handlers[] = {
212
-	{ htons ( IB_SMP_ATTR_NODE_DESC ),
213
-	  ib_sma_get_node_desc, NULL },
214
-	{ htons ( IB_SMP_ATTR_NODE_INFO ),
215
-	  ib_sma_get_node_info, NULL },
216
-	{ htons ( IB_SMP_ATTR_GUID_INFO ),
217
-	  ib_sma_get_guid_info, NULL },
218
-	{ htons ( IB_SMP_ATTR_PORT_INFO ),
219
-	  ib_sma_get_port_info, ib_sma_set_port_info },
220
-	{ htons ( IB_SMP_ATTR_PKEY_TABLE ),
221
-	  ib_sma_get_pkey_table, ib_sma_set_pkey_table },
222
-};
223
-
224
-/**
225
- * Identify attribute handler
226
- *
227
- * @v attr_id		Attribute ID (in network byte order)
228
- * @ret handler		Attribute handler (or NULL)
229
- */
230
-static struct ib_sma_handler * ib_sma_handler ( uint16_t attr_id ) {
231
-	struct ib_sma_handler *handler;
232
-	unsigned int i;
233
-
234
-	for ( i = 0 ; i < ( sizeof ( ib_sma_handlers ) /
235
-			    sizeof ( ib_sma_handlers[0] ) ) ; i++ ) {
236
-		handler = &ib_sma_handlers[i];
237
-		if ( handler->attr_id == attr_id )
238
-			return handler;
239
-	}
240
-
241
-	return NULL;
242
-}
243
-
244
 /**
193
 /**
245
- * Respond to management datagram
194
+ * Set partition key table
246
  *
195
  *
247
- * @v sma		Subnet management agent
248
- * @v mad		Management datagram
196
+ * @v gma		General management agent
197
+ * @v mad		MAD
249
  * @ret rc		Return status code
198
  * @ret rc		Return status code
250
  */
199
  */
251
-static int ib_sma_mad ( struct ib_sma *sma, union ib_mad *mad ) {
252
-	struct ib_device *ibdev = sma->ibdev;
253
-	struct ib_mad_hdr *hdr = &mad->hdr;
254
-	struct ib_mad_smp *smp = &mad->smp;
255
-	struct ib_sma_handler *handler = NULL;
256
-	unsigned int hop_pointer;
257
-	unsigned int hop_count;
258
-	int rc;
259
-
260
-	DBGC ( sma, "SMA %p received SMP with bv=%02x mc=%02x cv=%02x "
261
-	       "meth=%02x attr=%04x mod=%08x\n", sma, hdr->base_version,
262
-	       hdr->mgmt_class, hdr->class_version, hdr->method,
263
-	       ntohs ( hdr->attr_id ), ntohl ( hdr->attr_mod ) );
264
-	DBGC2_HDA ( sma, 0, mad, sizeof ( *mad ) );
265
-
266
-	/* Sanity checks */
267
-	if ( hdr->base_version != IB_MGMT_BASE_VERSION ) {
268
-		DBGC ( sma, "SMA %p unsupported base version %x\n",
269
-		       sma, hdr->base_version );
270
-		return -ENOTSUP;
271
-	}
272
-	if ( ( hdr->mgmt_class != IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE ) &&
273
-	     ( hdr->mgmt_class != IB_MGMT_CLASS_SUBN_LID_ROUTED ) ) {
274
-		DBGC ( sma, "SMA %p unsupported management class %x\n",
275
-		       sma, hdr->mgmt_class );
276
-		return -ENOTSUP;
277
-	}
278
-	if ( hdr->class_version != IB_SMP_CLASS_VERSION ) {
279
-		DBGC ( sma, "SMA %p unsupported class version %x\n",
280
-		       sma, hdr->class_version );
281
-		return -ENOTSUP;
282
-	}
283
-	if ( ( hdr->method != IB_MGMT_METHOD_GET ) &&
284
-	     ( hdr->method != IB_MGMT_METHOD_SET ) ) {
285
-		DBGC ( sma, "SMA %p unsupported method %x\n",
286
-		       sma, hdr->method );
287
-		return -ENOTSUP;
288
-	}
289
-
290
-	/* Identify handler */
291
-	if ( ! ( handler = ib_sma_handler ( hdr->attr_id ) ) ) {
292
-		DBGC ( sma, "SMA %p unsupported attribute %x\n",
293
-		       sma, ntohs ( hdr->attr_id ) );
294
-		hdr->status = htons ( IB_MGMT_STATUS_UNSUPPORTED_METHOD_ATTR );
295
-		goto respond_without_data;
296
-	}
297
-
298
-	/* Set attribute (if applicable) */
299
-	if ( hdr->method != IB_MGMT_METHOD_SET ) {
300
-		hdr->status = htons ( IB_MGMT_STATUS_OK );
301
-		goto respond;
302
-	}
303
-	if ( ! handler->set ) {
304
-		DBGC ( sma, "SMA %p attribute %x is unsettable\n",
305
-		       sma, ntohs ( hdr->attr_id ) );
306
-		hdr->status = htons ( IB_MGMT_STATUS_UNSUPPORTED_METHOD_ATTR );
307
-		goto respond;
308
-	}
309
-	if ( ( rc = handler->set ( sma, &smp->smp_data ) ) != 0 ) {
310
-		DBGC ( sma, "SMA %p could not set attribute %x: %s\n",
311
-		       sma, ntohs ( hdr->attr_id ), strerror ( rc ) );
312
-		hdr->status = htons ( IB_MGMT_STATUS_UNSUPPORTED_METHOD_ATTR );
313
-		goto respond;
314
-	}
315
-
316
-	hdr->status = htons ( IB_MGMT_STATUS_OK );
317
-
318
- respond:
319
-	/* Get attribute */
320
-	handler->get ( sma, &smp->smp_data );
321
-
322
- respond_without_data:
323
-
324
-	/* Set method to "Get Response" */
325
-	hdr->method = IB_MGMT_METHOD_GET_RESP;
326
-
327
-	/* Set response fields for directed route SMPs */
328
-	if ( hdr->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE ) {
329
-		hdr->status |= htons ( IB_SMP_STATUS_D_INBOUND );
330
-		hop_pointer = smp->mad_hdr.class_specific.smp.hop_pointer;
331
-		hop_count = smp->mad_hdr.class_specific.smp.hop_count;
332
-		assert ( hop_count == hop_pointer );
333
-		if ( hop_pointer < ( sizeof ( smp->return_path.hops ) /
334
-				     sizeof ( smp->return_path.hops[0] ) ) ) {
335
-			smp->return_path.hops[hop_pointer] = ibdev->port;
336
-		} else {
337
-			DBGC ( sma, "SMA %p invalid hop pointer %d\n",
338
-			       sma, hop_pointer );
339
-			return -EINVAL;
340
-		}
341
-	}
342
-
343
-	DBGC ( sma, "SMA %p responding with status=%04x\n",
344
-	       sma, ntohs ( hdr->status ) );
345
-	DBGC2_HDA ( sma, 0, mad, sizeof ( *mad ) );
346
-
347
-	return 0;
348
-}
349
-
350
-/**
351
- * Complete SMA send
352
- *
353
- *
354
- * @v ibdev		Infiniband device
355
- * @v qp		Queue pair
356
- * @v iobuf		I/O buffer
357
- * @v rc		Completion status code
358
- */
359
-static void ib_sma_complete_send ( struct ib_device *ibdev __unused,
360
-				   struct ib_queue_pair *qp,
361
-				   struct io_buffer *iobuf, int rc ) {
362
-	struct ib_sma *sma = ib_qp_get_ownerdata ( qp );
200
+static int ib_sma_set_pkey_table ( struct ib_gma *gma,
201
+				   union ib_mad *mad ) {
202
+	struct ib_device *ibdev = gma->ibdev;
203
+	struct ib_pkey_table *pkey_table = &mad->smp.smp_data.pkey_table;
363
 
204
 
364
-	if ( rc != 0 ) {
365
-		DBGC ( sma, "SMA %p send completion error: %s\n",
366
-		       sma, strerror ( rc ) );
367
-	}
368
-	free_iob ( iobuf );
369
-}
370
-
371
-/**
372
- * Complete SMA receive
373
- *
374
- *
375
- * @v ibdev		Infiniband device
376
- * @v qp		Queue pair
377
- * @v av		Address vector
378
- * @v iobuf		I/O buffer
379
- * @v rc		Completion status code
380
- */
381
-static void ib_sma_complete_recv ( struct ib_device *ibdev,
382
-				   struct ib_queue_pair *qp,
383
-				   struct ib_address_vector *av,
384
-				   struct io_buffer *iobuf, int rc ) {
385
-	struct ib_sma *sma = ib_qp_get_ownerdata ( qp );
386
-	union ib_mad *mad;
387
-
388
-	/* Ignore errors */
389
-	if ( rc != 0 ) {
390
-		DBGC ( sma, "SMA %p RX error: %s\n", sma, strerror ( rc ) );
391
-		goto err;
392
-	}
393
-
394
-	/* Sanity check */
395
-	if ( iob_len ( iobuf ) != sizeof ( *mad ) ) {
396
-		DBGC ( sma, "SMA %p RX bad size (%zd bytes)\n",
397
-		       sma, iob_len ( iobuf ) );
398
-		goto err;
399
-	}
400
-	mad = iobuf->data;
401
-
402
-	/* Construct MAD response */
403
-	if ( ( rc = ib_sma_mad ( sma, mad ) ) != 0 ) {
404
-		DBGC ( sma, "SMA %p could not construct MAD response: %s\n",
405
-		       sma, strerror ( rc ) );
406
-		goto err;
407
-	}
408
-
409
-	/* Send MAD response */
410
-	if ( ( rc = ib_post_send ( ibdev, qp, av, iobuf ) ) != 0 ) {
411
-		DBGC ( sma, "SMA %p could not send MAD response: %s\n",
412
-		       sma, strerror ( rc ) );
413
-		goto err;
414
-	}
415
-
416
-	return;
205
+	ibdev->pkey = ntohs ( pkey_table->pkey[0] );
417
 
206
 
418
- err:
419
-	free_iob ( iobuf );
207
+	return ib_sma_get_pkey_table ( gma, mad );
420
 }
208
 }
421
 
209
 
422
-/** SMA completion operations */
423
-static struct ib_completion_queue_operations ib_sma_completion_ops = {
424
-	.complete_send = ib_sma_complete_send,
425
-	.complete_recv = ib_sma_complete_recv,
210
+/** List of attribute handlers */
211
+struct ib_gma_handler ib_sma_handlers[] __ib_gma_handler = {
212
+	{
213
+		.mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED,
214
+		.mgmt_class_ignore = IB_SMP_CLASS_IGNORE,
215
+		.class_version = IB_SMP_CLASS_VERSION,
216
+		.method = IB_MGMT_METHOD_GET,
217
+		.resp_method = IB_MGMT_METHOD_GET_RESP,
218
+		.attr_id = htons ( IB_SMP_ATTR_NODE_INFO ),
219
+		.handle = ib_sma_get_node_info,
220
+	},
221
+	{
222
+		.mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED,
223
+		.mgmt_class_ignore = IB_SMP_CLASS_IGNORE,
224
+		.class_version = IB_SMP_CLASS_VERSION,
225
+		.method = IB_MGMT_METHOD_GET,
226
+		.resp_method = IB_MGMT_METHOD_GET_RESP,
227
+		.attr_id = htons ( IB_SMP_ATTR_NODE_DESC ),
228
+		.handle = ib_sma_get_node_desc,
229
+	},
230
+	{
231
+		.mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED,
232
+		.mgmt_class_ignore = IB_SMP_CLASS_IGNORE,
233
+		.class_version = IB_SMP_CLASS_VERSION,
234
+		.method = IB_MGMT_METHOD_GET,
235
+		.resp_method = IB_MGMT_METHOD_GET_RESP,
236
+		.attr_id = htons ( IB_SMP_ATTR_GUID_INFO ),
237
+		.handle = ib_sma_get_guid_info,
238
+	},
239
+	{
240
+		.mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED,
241
+		.mgmt_class_ignore = IB_SMP_CLASS_IGNORE,
242
+		.class_version = IB_SMP_CLASS_VERSION,
243
+		.method = IB_MGMT_METHOD_GET,
244
+		.resp_method = IB_MGMT_METHOD_GET_RESP,
245
+		.attr_id = htons ( IB_SMP_ATTR_PORT_INFO ),
246
+		.handle = ib_sma_get_port_info,
247
+	},
248
+	{
249
+		.mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED,
250
+		.mgmt_class_ignore = IB_SMP_CLASS_IGNORE,
251
+		.class_version = IB_SMP_CLASS_VERSION,
252
+		.method = IB_MGMT_METHOD_SET,
253
+		.resp_method = IB_MGMT_METHOD_GET_RESP,
254
+		.attr_id = htons ( IB_SMP_ATTR_PORT_INFO ),
255
+		.handle = ib_sma_set_port_info,
256
+	},
257
+	{
258
+		.mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED,
259
+		.mgmt_class_ignore = IB_SMP_CLASS_IGNORE,
260
+		.class_version = IB_SMP_CLASS_VERSION,
261
+		.method = IB_MGMT_METHOD_GET,
262
+		.resp_method = IB_MGMT_METHOD_GET_RESP,
263
+		.attr_id = htons ( IB_SMP_ATTR_PKEY_TABLE ),
264
+		.handle = ib_sma_get_pkey_table,
265
+	},
266
+	{
267
+		.mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED,
268
+		.mgmt_class_ignore = IB_SMP_CLASS_IGNORE,
269
+		.class_version = IB_SMP_CLASS_VERSION,
270
+		.method = IB_MGMT_METHOD_SET,
271
+		.resp_method = IB_MGMT_METHOD_GET_RESP,
272
+		.attr_id = htons ( IB_SMP_ATTR_PKEY_TABLE ),
273
+		.handle = ib_sma_set_pkey_table,
274
+	},
426
 };
275
 };
427
 
276
 
428
 /**
277
 /**
433
  * @v op		Subnet management operations
282
  * @v op		Subnet management operations
434
  * @ret rc		Return status code
283
  * @ret rc		Return status code
435
  */
284
  */
436
-int ib_create_sma ( struct ib_sma *sma, struct ib_device *ibdev,
437
-		    struct ib_sma_operations *op ) {
285
+int ib_create_sma ( struct ib_sma *sma, struct ib_device *ibdev ) {
438
 	int rc;
286
 	int rc;
439
 
287
 
440
-	/* Initialise fields */
441
-	memset ( sma, 0, sizeof ( *sma ) );
442
-	sma->ibdev = ibdev;
443
-	sma->op = op;
444
-
445
-	/* Create completion queue */
446
-	sma->cq = ib_create_cq ( ibdev, IB_SMA_NUM_CQES,
447
-				 &ib_sma_completion_ops );
448
-	if ( ! sma->cq ) {
449
-		rc = -ENOMEM;
450
-		goto err_create_cq;
451
-	}
452
-
453
-	/* Create queue pair */
454
-	sma->qp = ib_create_qp ( ibdev, IB_SMA_NUM_SEND_WQES, sma->cq,
455
-				 IB_SMA_NUM_RECV_WQES, sma->cq, 0 );
456
-	if ( ! sma->qp ) {
457
-		rc = -ENOMEM;
458
-		goto err_create_qp;
288
+	/* Initialise GMA */
289
+	if ( ( rc = ib_create_gma ( &sma->gma, ibdev, 0 ) ) != 0 ) {
290
+		DBGC ( sma, "SMA %p could not create GMA: %s\n",
291
+		       sma, strerror ( rc ) );
292
+		goto err_create_gma;
459
 	}
293
 	}
460
-	ib_qp_set_ownerdata ( sma->qp, sma );
461
 
294
 
462
 	/* If we don't get QP0, we can't function */
295
 	/* If we don't get QP0, we can't function */
463
-	if ( sma->qp->qpn != IB_QPN_SMA ) {
296
+	if ( sma->gma.qp->qpn != IB_QPN_SMA ) {
464
 		DBGC ( sma, "SMA %p on QPN %lx, needs to be on QPN 0\n",
297
 		DBGC ( sma, "SMA %p on QPN %lx, needs to be on QPN 0\n",
465
-		       sma, sma->qp->qpn );
298
+		       sma, sma->gma.qp->qpn );
466
 		rc = -ENOTSUP;
299
 		rc = -ENOTSUP;
467
 		goto err_not_qp0;
300
 		goto err_not_qp0;
468
 	}
301
 	}
469
 
302
 
470
-	/* Fill receive ring */
471
-	ib_refill_recv ( ibdev, sma->qp );
472
 	return 0;
303
 	return 0;
473
 
304
 
474
  err_not_qp0:
305
  err_not_qp0:
475
-	ib_destroy_qp ( ibdev, sma->qp );
476
- err_create_qp:
477
-	ib_destroy_cq ( ibdev, sma->cq );
478
- err_create_cq:
306
+	ib_destroy_gma ( &sma->gma );
307
+ err_create_gma:
479
 	return rc;
308
 	return rc;
480
 }
309
 }
481
 
310
 
485
  * @v sma		Subnet management agent
314
  * @v sma		Subnet management agent
486
  */
315
  */
487
 void ib_destroy_sma ( struct ib_sma *sma ) {
316
 void ib_destroy_sma ( struct ib_sma *sma ) {
488
-	struct ib_device *ibdev = sma->ibdev;
489
 
317
 
490
-	ib_destroy_qp ( ibdev, sma->qp );
491
-	ib_destroy_cq ( ibdev, sma->cq );
318
+	ib_destroy_gma ( &sma->gma );
492
 }
319
 }

Loading…
Cancel
Save