Pārlūkot izejas kodu

[infiniband] Always create an SMA and a GMA

tags/v0.9.8
Michael Brown 15 gadus atpakaļ
vecāks
revīzija
92cf240020

+ 0
- 13
src/drivers/infiniband/linda.c Parādīt failu

@@ -30,7 +30,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
30 30
 #include <gpxe/bitbash.h>
31 31
 #include <gpxe/malloc.h>
32 32
 #include <gpxe/iobuf.h>
33
-#include <gpxe/ib_sma.h>
34 33
 #include "linda.h"
35 34
 
36 35
 /**
@@ -97,9 +96,6 @@ struct linda {
97 96
 	struct i2c_bit_basher i2c;
98 97
 	/** I2C serial EEPROM */
99 98
 	struct i2c_device eeprom;
100
-
101
-	/** Subnet management agent */
102
-	struct ib_sma sma;
103 99
 };
104 100
 
105 101
 /***************************************************************************
@@ -2335,12 +2331,6 @@ static int linda_probe ( struct pci_device *pci,
2335 2331
 	if ( ( rc = linda_init_ib_serdes ( linda ) ) != 0 )
2336 2332
 		goto err_init_ib_serdes;
2337 2333
 
2338
-	/* Create the SMA */
2339
-	if ( ( rc = ib_create_sma ( &linda->sma, ibdev ) ) != 0 )
2340
-		goto err_create_sma;
2341
-	/* If the SMA doesn't get context 0, we're screwed */
2342
-	assert ( linda_qpn_to_ctx ( linda->sma.gma.qp->qpn ) == 0 );
2343
-
2344 2334
 	/* Register Infiniband device */
2345 2335
 	if ( ( rc = register_ibdev ( ibdev ) ) != 0 ) {
2346 2336
 		DBGC ( linda, "Linda %p could not register IB "
@@ -2352,8 +2342,6 @@ static int linda_probe ( struct pci_device *pci,
2352 2342
 
2353 2343
 	unregister_ibdev ( ibdev );
2354 2344
  err_register_ibdev:
2355
-	ib_destroy_sma ( &linda->sma );
2356
- err_create_sma:
2357 2345
 	linda_fini_recv ( linda );
2358 2346
  err_init_recv:
2359 2347
 	linda_fini_send ( linda );
@@ -2376,7 +2364,6 @@ static void linda_remove ( struct pci_device *pci ) {
2376 2364
 	struct linda *linda = ib_get_drvdata ( ibdev );
2377 2365
 
2378 2366
 	unregister_ibdev ( ibdev );
2379
-	ib_destroy_sma ( &linda->sma );
2380 2367
 	linda_fini_recv ( linda );
2381 2368
 	linda_fini_send ( linda );
2382 2369
 	ibdev_put ( ibdev );

+ 3
- 7
src/include/gpxe/ib_gma.h Parādīt failu

@@ -12,13 +12,9 @@ FILE_LICENCE ( GPL2_OR_LATER );
12 12
 #include <gpxe/list.h>
13 13
 #include <gpxe/retry.h>
14 14
 #include <gpxe/tables.h>
15
+#include <gpxe/infiniband.h>
15 16
 
16
-struct ib_device;
17
-struct ib_completion_queue;
18
-struct ib_queue_pair;
19
-union ib_mad;
20 17
 struct ib_gma;
21
-enum ib_queue_pair_type;
22 18
 
23 19
 /** A GMA attribute handler */
24 20
 struct ib_gma_handler {
@@ -68,8 +64,8 @@ struct ib_gma {
68 64
 
69 65
 extern int ib_gma_request ( struct ib_gma *gma, union ib_mad *mad,
70 66
 			    struct ib_address_vector *av, int retry );
71
-extern int ib_create_gma ( struct ib_gma *gma, struct ib_device *ibdev,
72
-			   enum ib_queue_pair_type type );
67
+extern struct ib_gma * ib_create_gma ( struct ib_device *ibdev,
68
+				       enum ib_queue_pair_type type );
73 69
 extern void ib_destroy_gma ( struct ib_gma *gma );
74 70
 
75 71
 #endif /* _GPXE_IB_GMA_H */

+ 0
- 24
src/include/gpxe/ib_sma.h Parādīt failu

@@ -1,24 +0,0 @@
1
-#ifndef _GPXE_IB_SMA_H
2
-#define _GPXE_IB_SMA_H
3
-
4
-/** @file
5
- *
6
- * Infiniband Subnet Management Agent
7
- *
8
- */
9
-
10
-FILE_LICENCE ( GPL2_OR_LATER );
11
-
12
-#include <gpxe/infiniband.h>
13
-#include <gpxe/ib_gma.h>
14
-
15
-/** An Infiniband Subnet Management Agent */
16
-struct ib_sma {
17
-	/** General management agent */
18
-	struct ib_gma gma;
19
-};
20
-
21
-extern int ib_create_sma ( struct ib_sma *sma, struct ib_device *ibdev );
22
-extern void ib_destroy_sma ( struct ib_sma *sma );
23
-
24
-#endif /* _GPXE_IB_SMA_H */

+ 4
- 2
src/include/gpxe/infiniband.h Parādīt failu

@@ -14,7 +14,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
14 14
 #include <gpxe/device.h>
15 15
 #include <gpxe/ib_packet.h>
16 16
 #include <gpxe/ib_mad.h>
17
-#include <gpxe/ib_gma.h>
18 17
 
19 18
 /** Subnet management QPN */
20 19
 #define IB_QPN_SMA 0
@@ -46,6 +45,7 @@ struct ib_device;
46 45
 struct ib_queue_pair;
47 46
 struct ib_address_vector;
48 47
 struct ib_completion_queue;
48
+struct ib_gma;
49 49
 
50 50
 /** An Infiniband Work Queue */
51 51
 struct ib_work_queue {
@@ -387,8 +387,10 @@ struct ib_device {
387 387
 	/** Outbound packet sequence number */
388 388
 	uint32_t psn;
389 389
 
390
+	/** Subnet management agent */
391
+	struct ib_gma *sma;
390 392
 	/** General management agent */
391
-	struct ib_gma gma;
393
+	struct ib_gma *gma;
392 394
 
393 395
 	/** Driver private data */
394 396
 	void *drv_priv;

+ 23
- 10
src/net/infiniband.c Parādīt failu

@@ -33,6 +33,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
33 33
 #include <gpxe/ipoib.h>
34 34
 #include <gpxe/process.h>
35 35
 #include <gpxe/infiniband.h>
36
+#include <gpxe/ib_gma.h>
36 37
 
37 38
 /** @file
38 39
  *
@@ -510,6 +511,22 @@ int ib_open ( struct ib_device *ibdev ) {
510 511
 		return 0;
511 512
 	}
512 513
 
514
+	/* Create subnet management agent */
515
+	ibdev->sma = ib_create_gma ( ibdev, IB_QPT_SMA );
516
+	if ( ! ibdev->sma ) {
517
+		DBGC ( ibdev, "IBDEV %p could not create SMA\n", ibdev );
518
+		rc = -ENOMEM;
519
+		goto err_create_sma;
520
+	}
521
+
522
+	/* Create general management agent */
523
+	ibdev->gma = ib_create_gma ( ibdev, IB_QPT_GMA );
524
+	if ( ! ibdev->gma ) {
525
+		DBGC ( ibdev, "IBDEV %p could not create GMA\n", ibdev );
526
+		rc = -ENOMEM;
527
+		goto err_create_gma;
528
+	}
529
+
513 530
 	/* Open device */
514 531
 	if ( ( rc = ibdev->op->open ( ibdev ) ) != 0 ) {
515 532
 		DBGC ( ibdev, "IBDEV %p could not open: %s\n",
@@ -517,20 +534,15 @@ int ib_open ( struct ib_device *ibdev ) {
517 534
 		goto err_open;
518 535
 	}
519 536
 
520
-	/* Create general management agent */
521
-	if ( ( rc = ib_create_gma ( &ibdev->gma, ibdev, IB_QPT_GMA ) ) != 0 ) {
522
-		DBGC ( ibdev, "IBDEV %p could not create GMA: %s\n",
523
-		       ibdev, strerror ( rc ) );
524
-		goto err_create_gma;
525
-	}
526
-
527 537
 	assert ( ibdev->open_count == 1 );
528 538
 	return 0;
529 539
 
530
-	ib_destroy_gma ( &ibdev->gma );
531
- err_create_gma:
532 540
 	ibdev->op->close ( ibdev );
533 541
  err_open:
542
+	ib_destroy_gma ( ibdev->gma );
543
+ err_create_gma:
544
+	ib_destroy_gma ( ibdev->sma );
545
+ err_create_sma:
534 546
 	assert ( ibdev->open_count == 1 );
535 547
 	ibdev->open_count = 0;
536 548
 	return rc;
@@ -548,7 +560,8 @@ void ib_close ( struct ib_device *ibdev ) {
548 560
 
549 561
 	/* Close device if this was the last remaining requested opening */
550 562
 	if ( ibdev->open_count == 0 ) {
551
-		ib_destroy_gma ( &ibdev->gma );
563
+		ib_destroy_gma ( ibdev->gma );
564
+		ib_destroy_gma ( ibdev->sma );
552 565
 		ibdev->op->close ( ibdev );
553 566
 	}
554 567
 }

+ 266
- 12
src/net/infiniband/ib_gma.c Parādīt failu

@@ -68,12 +68,264 @@ struct ib_mad_request {
68 68
  */
69 69
 #define IB_GMA_NUM_CQES 8
70 70
 
71
-/** GMA TID magic signature */
71
+/** TID magic signature */
72 72
 #define IB_GMA_TID_MAGIC ( ( 'g' << 24 ) | ( 'P' << 16 ) | ( 'X' << 8 ) | 'E' )
73 73
 
74 74
 /** TID to use for next MAD request */
75 75
 static unsigned int next_request_tid;
76 76
 
77
+/*****************************************************************************
78
+ *
79
+ * Subnet management MAD handlers
80
+ *
81
+ *****************************************************************************
82
+ */
83
+
84
+/**
85
+ * Get node information
86
+ *
87
+ * @v gma		General management agent
88
+ * @v mad		MAD
89
+ * @ret rc		Return status code
90
+ */
91
+static int ib_sma_get_node_info ( struct ib_gma *gma,
92
+				  union ib_mad *mad ) {
93
+	struct ib_device *ibdev = gma->ibdev;
94
+	struct ib_node_info *node_info = &mad->smp.smp_data.node_info;
95
+
96
+	memset ( node_info, 0, sizeof ( *node_info ) );
97
+	node_info->base_version = IB_MGMT_BASE_VERSION;
98
+	node_info->class_version = IB_SMP_CLASS_VERSION;
99
+	node_info->node_type = IB_NODE_TYPE_HCA;
100
+	node_info->num_ports = ib_get_hca_info ( ibdev, &node_info->sys_guid );
101
+	memcpy ( &node_info->node_guid, &node_info->sys_guid,
102
+		 sizeof ( node_info->node_guid ) );
103
+	memcpy ( &node_info->port_guid, &ibdev->gid.u.half[1],
104
+		 sizeof ( node_info->port_guid ) );
105
+	node_info->partition_cap = htons ( 1 );
106
+	node_info->local_port_num = ibdev->port;
107
+
108
+	return 0;
109
+}
110
+
111
+/**
112
+ * Get node description
113
+ *
114
+ * @v gma		General management agent
115
+ * @v mad		MAD
116
+ * @ret rc		Return status code
117
+ */
118
+static int ib_sma_get_node_desc ( struct ib_gma *gma,
119
+				  union ib_mad *mad ) {
120
+	struct ib_device *ibdev = gma->ibdev;
121
+	struct ib_node_desc *node_desc = &mad->smp.smp_data.node_desc;
122
+	struct ib_gid_half *guid = &ibdev->gid.u.half[1];
123
+
124
+	memset ( node_desc, 0, sizeof ( *node_desc ) );
125
+	snprintf ( node_desc->node_string, sizeof ( node_desc->node_string ),
126
+		   "gPXE %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x (%s)",
127
+		   guid->bytes[0], guid->bytes[1], guid->bytes[2],
128
+		   guid->bytes[3], guid->bytes[4], guid->bytes[5],
129
+		   guid->bytes[6], guid->bytes[7], ibdev->dev->name );
130
+
131
+	return 0;
132
+}
133
+
134
+/**
135
+ * Get GUID information
136
+ *
137
+ * @v gma		General management agent
138
+ * @v mad		MAD
139
+ * @ret rc		Return status code
140
+ */
141
+static int ib_sma_get_guid_info ( struct ib_gma *gma,
142
+				  union ib_mad *mad ) {
143
+	struct ib_device *ibdev = gma->ibdev;
144
+	struct ib_guid_info *guid_info = &mad->smp.smp_data.guid_info;
145
+
146
+	memset ( guid_info, 0, sizeof ( *guid_info ) );
147
+	memcpy ( guid_info->guid[0], &ibdev->gid.u.half[1],
148
+		 sizeof ( guid_info->guid[0] ) );
149
+
150
+	return 0;
151
+}
152
+
153
+/**
154
+ * Get port information
155
+ *
156
+ * @v gma		General management agent
157
+ * @v mad		MAD
158
+ * @ret rc		Return status code
159
+ */
160
+static int ib_sma_get_port_info ( struct ib_gma *gma,
161
+				  union ib_mad *mad ) {
162
+	struct ib_device *ibdev = gma->ibdev;
163
+	struct ib_port_info *port_info = &mad->smp.smp_data.port_info;
164
+
165
+	memset ( port_info, 0, sizeof ( *port_info ) );
166
+	memcpy ( port_info->gid_prefix, &ibdev->gid.u.half[0],
167
+		 sizeof ( port_info->gid_prefix ) );
168
+	port_info->lid = ntohs ( ibdev->lid );
169
+	port_info->mastersm_lid = ntohs ( ibdev->sm_lid );
170
+	port_info->local_port_num = ibdev->port;
171
+	port_info->link_width_enabled = ibdev->link_width;
172
+	port_info->link_width_supported = ibdev->link_width;
173
+	port_info->link_width_active = ibdev->link_width;
174
+	port_info->link_speed_supported__port_state =
175
+		( ( ibdev->link_speed << 4 ) | ibdev->port_state );
176
+	port_info->port_phys_state__link_down_def_state =
177
+		( ( IB_PORT_PHYS_STATE_POLLING << 4 ) |
178
+		  IB_PORT_PHYS_STATE_POLLING );
179
+	port_info->link_speed_active__link_speed_enabled =
180
+		( ( ibdev->link_speed << 4 ) | ibdev->link_speed );
181
+	port_info->neighbour_mtu__mastersm_sl =
182
+		( ( IB_MTU_2048 << 4 ) | ibdev->sm_sl );
183
+	port_info->vl_cap__init_type = ( IB_VL_0 << 4 );
184
+	port_info->init_type_reply__mtu_cap = IB_MTU_2048;
185
+	port_info->operational_vls__enforcement = ( IB_VL_0 << 4 );
186
+	port_info->guid_cap = 1;
187
+
188
+	return 0;
189
+}
190
+
191
+/**
192
+ * Set port information
193
+ *
194
+ * @v gma		General management agent
195
+ * @v mad		MAD
196
+ * @ret rc		Return status code
197
+ */
198
+static int ib_sma_set_port_info ( struct ib_gma *gma,
199
+				  union ib_mad *mad ) {
200
+	struct ib_device *ibdev = gma->ibdev;
201
+	const struct ib_port_info *port_info = &mad->smp.smp_data.port_info;
202
+	int rc;
203
+
204
+	memcpy ( &ibdev->gid.u.half[0], port_info->gid_prefix,
205
+		 sizeof ( ibdev->gid.u.half[0] ) );
206
+	ibdev->lid = ntohs ( port_info->lid );
207
+	ibdev->sm_lid = ntohs ( port_info->mastersm_lid );
208
+	ibdev->sm_sl = ( port_info->neighbour_mtu__mastersm_sl & 0xf );
209
+
210
+	if ( ( rc = ib_set_port_info ( ibdev, port_info ) ) != 0 ) {
211
+		DBGC ( ibdev, "IBDEV %p could not set port information: %s\n",
212
+		       ibdev, strerror ( rc ) );
213
+		mad->hdr.status =
214
+			htons ( IB_MGMT_STATUS_UNSUPPORTED_METHOD_ATTR );
215
+	}
216
+
217
+	return ib_sma_get_port_info ( gma, mad );
218
+}
219
+
220
+/**
221
+ * Get partition key table
222
+ *
223
+ * @v gma		General management agent
224
+ * @v mad		MAD
225
+ * @ret rc		Return status code
226
+ */
227
+static int ib_sma_get_pkey_table ( struct ib_gma *gma,
228
+				   union ib_mad *mad ) {
229
+	struct ib_device *ibdev = gma->ibdev;
230
+	struct ib_pkey_table *pkey_table = &mad->smp.smp_data.pkey_table;
231
+
232
+	memset ( pkey_table, 0, sizeof ( *pkey_table ) );
233
+	pkey_table->pkey[0] = htons ( ibdev->pkey );
234
+
235
+	return 0;
236
+}
237
+
238
+/**
239
+ * Set partition key table
240
+ *
241
+ * @v gma		General management agent
242
+ * @v mad		MAD
243
+ * @ret rc		Return status code
244
+ */
245
+static int ib_sma_set_pkey_table ( struct ib_gma *gma,
246
+				   union ib_mad *mad ) {
247
+	struct ib_device *ibdev = gma->ibdev;
248
+	struct ib_pkey_table *pkey_table = &mad->smp.smp_data.pkey_table;
249
+
250
+	ibdev->pkey = ntohs ( pkey_table->pkey[0] );
251
+
252
+	return ib_sma_get_pkey_table ( gma, mad );
253
+}
254
+
255
+/** List of attribute handlers */
256
+struct ib_gma_handler ib_sma_handlers[] __ib_gma_handler = {
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_NODE_INFO ),
264
+		.handle = ib_sma_get_node_info,
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_GET,
271
+		.resp_method = IB_MGMT_METHOD_GET_RESP,
272
+		.attr_id = htons ( IB_SMP_ATTR_NODE_DESC ),
273
+		.handle = ib_sma_get_node_desc,
274
+	},
275
+	{
276
+		.mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED,
277
+		.mgmt_class_ignore = IB_SMP_CLASS_IGNORE,
278
+		.class_version = IB_SMP_CLASS_VERSION,
279
+		.method = IB_MGMT_METHOD_GET,
280
+		.resp_method = IB_MGMT_METHOD_GET_RESP,
281
+		.attr_id = htons ( IB_SMP_ATTR_GUID_INFO ),
282
+		.handle = ib_sma_get_guid_info,
283
+	},
284
+	{
285
+		.mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED,
286
+		.mgmt_class_ignore = IB_SMP_CLASS_IGNORE,
287
+		.class_version = IB_SMP_CLASS_VERSION,
288
+		.method = IB_MGMT_METHOD_GET,
289
+		.resp_method = IB_MGMT_METHOD_GET_RESP,
290
+		.attr_id = htons ( IB_SMP_ATTR_PORT_INFO ),
291
+		.handle = ib_sma_get_port_info,
292
+	},
293
+	{
294
+		.mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED,
295
+		.mgmt_class_ignore = IB_SMP_CLASS_IGNORE,
296
+		.class_version = IB_SMP_CLASS_VERSION,
297
+		.method = IB_MGMT_METHOD_SET,
298
+		.resp_method = IB_MGMT_METHOD_GET_RESP,
299
+		.attr_id = htons ( IB_SMP_ATTR_PORT_INFO ),
300
+		.handle = ib_sma_set_port_info,
301
+	},
302
+	{
303
+		.mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED,
304
+		.mgmt_class_ignore = IB_SMP_CLASS_IGNORE,
305
+		.class_version = IB_SMP_CLASS_VERSION,
306
+		.method = IB_MGMT_METHOD_GET,
307
+		.resp_method = IB_MGMT_METHOD_GET_RESP,
308
+		.attr_id = htons ( IB_SMP_ATTR_PKEY_TABLE ),
309
+		.handle = ib_sma_get_pkey_table,
310
+	},
311
+	{
312
+		.mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED,
313
+		.mgmt_class_ignore = IB_SMP_CLASS_IGNORE,
314
+		.class_version = IB_SMP_CLASS_VERSION,
315
+		.method = IB_MGMT_METHOD_SET,
316
+		.resp_method = IB_MGMT_METHOD_GET_RESP,
317
+		.attr_id = htons ( IB_SMP_ATTR_PKEY_TABLE ),
318
+		.handle = ib_sma_set_pkey_table,
319
+	},
320
+};
321
+
322
+/*****************************************************************************
323
+ *
324
+ * General management agent
325
+ *
326
+ *****************************************************************************
327
+ */
328
+
77 329
 /**
78 330
  * Call attribute handler
79 331
  *
@@ -341,18 +593,19 @@ int ib_gma_request ( struct ib_gma *gma, union ib_mad *mad,
341 593
 /**
342 594
  * Create GMA
343 595
  *
344
- * @v gma		General management agent
345 596
  * @v ibdev		Infiniband device
346 597
  * @v type		Queue pair type
347
- * @ret rc		Return status code
598
+ * @ret gma		General management agent, or NULL
348 599
  */
349
-int ib_create_gma ( struct ib_gma *gma, struct ib_device *ibdev,
350
-		    enum ib_queue_pair_type type ) {
600
+struct ib_gma * ib_create_gma ( struct ib_device *ibdev,
601
+				enum ib_queue_pair_type type ) {
602
+	struct ib_gma *gma;
351 603
 	unsigned long qkey;
352
-	int rc;
353 604
 
354
-	/* Initialise fields */
355
-	memset ( gma, 0, sizeof ( *gma ) );
605
+	/* Allocate and initialise fields */
606
+	gma = zalloc ( sizeof ( *gma ) );
607
+	if ( ! gma )
608
+		goto err_alloc;
356 609
 	gma->ibdev = ibdev;
357 610
 	INIT_LIST_HEAD ( &gma->requests );
358 611
 
@@ -362,7 +615,6 @@ int ib_create_gma ( struct ib_gma *gma, struct ib_device *ibdev,
362 615
 	if ( ! gma->cq ) {
363 616
 		DBGC ( gma, "GMA %p could not allocate completion queue\n",
364 617
 		       gma );
365
-		rc = -ENOMEM;
366 618
 		goto err_create_cq;
367 619
 	}
368 620
 
@@ -372,7 +624,6 @@ int ib_create_gma ( struct ib_gma *gma, struct ib_device *ibdev,
372 624
 				 IB_GMA_NUM_RECV_WQES, gma->cq, qkey );
373 625
 	if ( ! gma->qp ) {
374 626
 		DBGC ( gma, "GMA %p could not allocate queue pair\n", gma );
375
-		rc = -ENOMEM;
376 627
 		goto err_create_qp;
377 628
 	}
378 629
 	ib_qp_set_ownerdata ( gma->qp, gma );
@@ -381,13 +632,15 @@ int ib_create_gma ( struct ib_gma *gma, struct ib_device *ibdev,
381 632
 
382 633
 	/* Fill receive ring */
383 634
 	ib_refill_recv ( ibdev, gma->qp );
384
-	return 0;
635
+	return gma;
385 636
 
386 637
 	ib_destroy_qp ( ibdev, gma->qp );
387 638
  err_create_qp:
388 639
 	ib_destroy_cq ( ibdev, gma->cq );
389 640
  err_create_cq:
390
-	return rc;
641
+	free ( gma );
642
+ err_alloc:
643
+	return NULL;
391 644
 }
392 645
 
393 646
 /**
@@ -409,4 +662,5 @@ void ib_destroy_gma ( struct ib_gma *gma ) {
409 662
 
410 663
 	ib_destroy_qp ( ibdev, gma->qp );
411 664
 	ib_destroy_cq ( ibdev, gma->cq );
665
+	free ( gma );
412 666
 }

+ 2
- 2
src/net/infiniband/ib_mcast.c Parādīt failu

@@ -84,7 +84,7 @@ static int ib_mc_member_request ( struct ib_gma *gma, struct ib_gid *gid,
84 84
  */
85 85
 int ib_mcast_join ( struct ib_device *ibdev, struct ib_queue_pair *qp,
86 86
 		    struct ib_gid *gid ) {
87
-	struct ib_gma *gma = &ibdev->gma;
87
+	struct ib_gma *gma = ibdev->gma;
88 88
 	int rc;
89 89
 
90 90
 	DBGC ( gma, "GMA %p QPN %lx joining %08x:%08x:%08x:%08x\n",
@@ -120,7 +120,7 @@ int ib_mcast_join ( struct ib_device *ibdev, struct ib_queue_pair *qp,
120 120
  */
121 121
 void ib_mcast_leave ( struct ib_device *ibdev, struct ib_queue_pair *qp,
122 122
 		      struct ib_gid *gid ) {
123
-	struct ib_gma *gma = &ibdev->gma;
123
+	struct ib_gma *gma = ibdev->gma;
124 124
 
125 125
 	DBGC ( gma, "GMA %p QPN %lx leaving %08x:%08x:%08x:%08x\n",
126 126
 	       gma, qp->qpn, ntohl ( gid->u.dwords[0] ),

+ 1
- 1
src/net/infiniband/ib_pathrec.c Parādīt failu

@@ -98,7 +98,7 @@ ib_find_path_cache_entry ( struct ib_device *ibdev, struct ib_gid *dgid ) {
98 98
  */
99 99
 int ib_resolve_path ( struct ib_device *ibdev,
100 100
 		      struct ib_address_vector *av ) {
101
-	struct ib_gma *gma = &ibdev->gma;
101
+	struct ib_gma *gma = ibdev->gma;
102 102
 	struct ib_gid *gid = &av->gid;
103 103
 	struct ib_cached_path_record *cached;
104 104
 	union ib_mad mad;

+ 0
- 319
src/net/infiniband/ib_sma.c Parādīt failu

@@ -1,319 +0,0 @@
1
-/*
2
- * Copyright (C) 2008 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 <stdint.h>
22
-#include <stdlib.h>
23
-#include <string.h>
24
-#include <errno.h>
25
-#include <stdio.h>
26
-#include <unistd.h>
27
-#include <byteswap.h>
28
-#include <gpxe/infiniband.h>
29
-#include <gpxe/ib_gma.h>
30
-#include <gpxe/ib_sma.h>
31
-
32
-/**
33
- * @file
34
- *
35
- * Infiniband Subnet Management Agent
36
- *
37
- */
38
-
39
-/**
40
- * Get node information
41
- *
42
- * @v gma		General management agent
43
- * @v mad		MAD
44
- * @ret rc		Return status code
45
- */
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;
50
-
51
-	memset ( node_info, 0, sizeof ( *node_info ) );
52
-	node_info->base_version = IB_MGMT_BASE_VERSION;
53
-	node_info->class_version = IB_SMP_CLASS_VERSION;
54
-	node_info->node_type = IB_NODE_TYPE_HCA;
55
-	node_info->num_ports = ib_get_hca_info ( ibdev, &node_info->sys_guid );
56
-	memcpy ( &node_info->node_guid, &node_info->sys_guid,
57
-		 sizeof ( node_info->node_guid ) );
58
-	memcpy ( &node_info->port_guid, &ibdev->gid.u.half[1],
59
-		 sizeof ( node_info->port_guid ) );
60
-	node_info->partition_cap = htons ( 1 );
61
-	node_info->local_port_num = ibdev->port;
62
-
63
-	return 0;
64
-}
65
-
66
-/**
67
- * Get node description
68
- *
69
- * @v gma		General management agent
70
- * @v mad		MAD
71
- * @ret rc		Return status code
72
- */
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;
77
-	struct ib_gid_half *guid = &ibdev->gid.u.half[1];
78
-
79
-	memset ( node_desc, 0, sizeof ( *node_desc ) );
80
-	snprintf ( node_desc->node_string, sizeof ( node_desc->node_string ),
81
-		   "gPXE %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x (%s)",
82
-		   guid->bytes[0], guid->bytes[1], guid->bytes[2],
83
-		   guid->bytes[3], guid->bytes[4], guid->bytes[5],
84
-		   guid->bytes[6], guid->bytes[7], ibdev->dev->name );
85
-
86
-	return 0;
87
-}
88
-
89
-/**
90
- * Get GUID information
91
- *
92
- * @v gma		General management agent
93
- * @v mad		MAD
94
- * @ret rc		Return status code
95
- */
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;
100
-
101
-	memset ( guid_info, 0, sizeof ( *guid_info ) );
102
-	memcpy ( guid_info->guid[0], &ibdev->gid.u.half[1],
103
-		 sizeof ( guid_info->guid[0] ) );
104
-
105
-	return 0;
106
-}
107
-
108
-/**
109
- * Get port information
110
- *
111
- * @v gma		General management agent
112
- * @v mad		MAD
113
- * @ret rc		Return status code
114
- */
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;
119
-
120
-	memset ( port_info, 0, sizeof ( *port_info ) );
121
-	memcpy ( port_info->gid_prefix, &ibdev->gid.u.half[0],
122
-		 sizeof ( port_info->gid_prefix ) );
123
-	port_info->lid = ntohs ( ibdev->lid );
124
-	port_info->mastersm_lid = ntohs ( ibdev->sm_lid );
125
-	port_info->local_port_num = ibdev->port;
126
-	port_info->link_width_enabled = ibdev->link_width;
127
-	port_info->link_width_supported = ibdev->link_width;
128
-	port_info->link_width_active = ibdev->link_width;
129
-	port_info->link_speed_supported__port_state =
130
-		( ( ibdev->link_speed << 4 ) | ibdev->port_state );
131
-	port_info->port_phys_state__link_down_def_state =
132
-		( ( IB_PORT_PHYS_STATE_POLLING << 4 ) |
133
-		  IB_PORT_PHYS_STATE_POLLING );
134
-	port_info->link_speed_active__link_speed_enabled =
135
-		( ( ibdev->link_speed << 4 ) | ibdev->link_speed );
136
-	port_info->neighbour_mtu__mastersm_sl =
137
-		( ( IB_MTU_2048 << 4 ) | ibdev->sm_sl );
138
-	port_info->vl_cap__init_type = ( IB_VL_0 << 4 );
139
-	port_info->init_type_reply__mtu_cap = IB_MTU_2048;
140
-	port_info->operational_vls__enforcement = ( IB_VL_0 << 4 );
141
-	port_info->guid_cap = 1;
142
-
143
-	return 0;
144
-}
145
-
146
-/**
147
- * Set port information
148
- *
149
- * @v gma		General management agent
150
- * @v mad		MAD
151
- * @ret rc		Return status code
152
- */
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;
158
-
159
-	memcpy ( &ibdev->gid.u.half[0], port_info->gid_prefix,
160
-		 sizeof ( ibdev->gid.u.half[0] ) );
161
-	ibdev->lid = ntohs ( port_info->lid );
162
-	ibdev->sm_lid = ntohs ( port_info->mastersm_lid );
163
-	ibdev->sm_sl = ( port_info->neighbour_mtu__mastersm_sl & 0xf );
164
-
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 );
170
-	}
171
-
172
-	return ib_sma_get_port_info ( gma, mad );
173
-}
174
-
175
-/**
176
- * Get partition key table
177
- *
178
- * @v gma		General management agent
179
- * @v mad		MAD
180
- * @ret rc		Return status code
181
- */
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;
186
-
187
-	memset ( pkey_table, 0, sizeof ( *pkey_table ) );
188
-	pkey_table->pkey[0] = htons ( ibdev->pkey );
189
-
190
-	return 0;
191
-}
192
-
193
-/**
194
- * Set partition key table
195
- *
196
- * @v gma		General management agent
197
- * @v mad		MAD
198
- * @ret rc		Return status code
199
- */
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;
204
-
205
-	ibdev->pkey = ntohs ( pkey_table->pkey[0] );
206
-
207
-	return ib_sma_get_pkey_table ( gma, mad );
208
-}
209
-
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
-	},
275
-};
276
-
277
-/**
278
- * Create SMA
279
- *
280
- * @v sma		Subnet management agent
281
- * @v ibdev		Infiniband device
282
- * @v op		Subnet management operations
283
- * @ret rc		Return status code
284
- */
285
-int ib_create_sma ( struct ib_sma *sma, struct ib_device *ibdev ) {
286
-	int rc;
287
-
288
-	/* Initialise GMA */
289
-	if ( ( rc = ib_create_gma ( &sma->gma, ibdev, IB_QPT_SMA ) ) != 0 ) {
290
-		DBGC ( sma, "SMA %p could not create GMA: %s\n",
291
-		       sma, strerror ( rc ) );
292
-		goto err_create_gma;
293
-	}
294
-
295
-	/* If we don't get QP0, we can't function */
296
-	if ( sma->gma.qp->qpn != IB_QPN_SMA ) {
297
-		DBGC ( sma, "SMA %p on QPN %lx, needs to be on QPN 0\n",
298
-		       sma, sma->gma.qp->qpn );
299
-		rc = -ENOTSUP;
300
-		goto err_not_qp0;
301
-	}
302
-
303
-	return 0;
304
-
305
- err_not_qp0:
306
-	ib_destroy_gma ( &sma->gma );
307
- err_create_gma:
308
-	return rc;
309
-}
310
-
311
-/**
312
- * Destroy SMA
313
- *
314
- * @v sma		Subnet management agent
315
- */
316
-void ib_destroy_sma ( struct ib_sma *sma ) {
317
-
318
-	ib_destroy_gma ( &sma->gma );
319
-}

Notiek ielāde…
Atcelt
Saglabāt