Parcourir la source

[infiniband] Provide a general mechanism for path record lookups

Generalise out the path record lookup code from IPoIB.
tags/v0.9.8
Michael Brown il y a 15 ans
Parent
révision
d6b47871de
4 fichiers modifiés avec 247 ajouts et 108 suppressions
  1. 8
    108
      src/drivers/net/ipoib.c
  2. 1
    0
      src/include/gpxe/errfile.h
  3. 17
    0
      src/include/gpxe/ib_pathrec.h
  4. 221
    0
      src/net/infiniband/ib_pathrec.c

+ 8
- 108
src/drivers/net/ipoib.c Voir le fichier

@@ -29,6 +29,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
29 29
 #include <gpxe/netdevice.h>
30 30
 #include <gpxe/infiniband.h>
31 31
 #include <gpxe/ib_qset.h>
32
+#include <gpxe/ib_pathrec.h>
32 33
 #include <gpxe/ipoib.h>
33 34
 
34 35
 /** @file
@@ -78,9 +79,6 @@ struct ipoib_device {
78 79
 	int broadcast_attached;
79 80
 };
80 81
 
81
-/** TID half used to identify get path record replies */
82
-#define IPOIB_TID_GET_PATH_REC 0x11111111UL
83
-
84 82
 /** TID half used to identify multicast member record replies */
85 83
 #define IPOIB_TID_MC_MEMBER_REC 0x22222222UL
86 84
 
@@ -118,12 +116,6 @@ struct ipoib_peer {
118 116
 	uint8_t key;
119 117
 	/** MAC address */
120 118
 	struct ipoib_mac mac;
121
-	/** LID */
122
-	unsigned int lid;
123
-	/** Service level */
124
-	unsigned int sl;
125
-	/** Rate */
126
-	unsigned int rate;
127 119
 };
128 120
 
129 121
 /** Number of IPoIB peer cache entries
@@ -352,63 +344,6 @@ struct ll_protocol ipoib_protocol __ll_protocol = {
352 344
  ****************************************************************************
353 345
  */
354 346
 
355
-/**
356
- * Transmit path record request
357
- *
358
- * @v ipoib		IPoIB device
359
- * @v gid		Destination GID
360
- * @ret rc		Return status code
361
- */
362
-static int ipoib_get_path_record ( struct ipoib_device *ipoib,
363
-				   struct ib_gid *gid ) {
364
-	struct ib_device *ibdev = ipoib->ibdev;
365
-	struct io_buffer *iobuf;
366
-	struct ib_mad_sa *sa;
367
-	struct ib_address_vector av;
368
-	int rc;
369
-
370
-	/* Allocate I/O buffer */
371
-	iobuf = alloc_iob ( sizeof ( *sa ) );
372
-	if ( ! iobuf )
373
-		return -ENOMEM;
374
-	iob_put ( iobuf, sizeof ( *sa ) );
375
-	sa = iobuf->data;
376
-	memset ( sa, 0, sizeof ( *sa ) );
377
-
378
-	/* Construct path record request */
379
-	sa->mad_hdr.base_version = IB_MGMT_BASE_VERSION;
380
-	sa->mad_hdr.mgmt_class = IB_MGMT_CLASS_SUBN_ADM;
381
-	sa->mad_hdr.class_version = 2;
382
-	sa->mad_hdr.method = IB_MGMT_METHOD_GET;
383
-	sa->mad_hdr.attr_id = htons ( IB_SA_ATTR_PATH_REC );
384
-	sa->mad_hdr.tid[0] = IPOIB_TID_GET_PATH_REC;
385
-	sa->mad_hdr.tid[1] = ipoib_meta_tid++;
386
-	sa->sa_hdr.comp_mask[1] =
387
-		htonl ( IB_SA_PATH_REC_DGID | IB_SA_PATH_REC_SGID );
388
-	memcpy ( &sa->sa_data.path_record.dgid, gid,
389
-		 sizeof ( sa->sa_data.path_record.dgid ) );
390
-	memcpy ( &sa->sa_data.path_record.sgid, &ibdev->gid,
391
-		 sizeof ( sa->sa_data.path_record.sgid ) );
392
-
393
-	/* Construct address vector */
394
-	memset ( &av, 0, sizeof ( av ) );
395
-	av.lid = ibdev->sm_lid;
396
-	av.sl = ibdev->sm_sl;
397
-	av.qpn = IB_QPN_GMA;
398
-	av.qkey = IB_QKEY_GMA;
399
-
400
-	/* Post send request */
401
-	if ( ( rc = ib_post_send ( ibdev, ipoib->meta.qp, &av,
402
-				   iobuf ) ) != 0 ) {
403
-		DBGC ( ipoib, "IPoIB %p could not send get path record: %s\n",
404
-		       ipoib, strerror ( rc ) );
405
-		free_iob ( iobuf );
406
-		return rc;
407
-	}
408
-
409
-	return 0;
410
-}
411
-
412 347
 /**
413 348
  * Transmit multicast group membership request
414 349
  *
@@ -484,7 +419,7 @@ static int ipoib_transmit ( struct net_device *netdev,
484 419
 	struct ipoib_hdr *ipoib_hdr;
485 420
 	struct ipoib_peer *dest;
486 421
 	struct ib_address_vector av;
487
-	struct ib_gid *gid;
422
+	int rc;
488 423
 
489 424
 	/* Sanity check */
490 425
 	if ( iob_len ( iobuf ) < sizeof ( *ipoib_hdr ) ) {
@@ -513,21 +448,16 @@ static int ipoib_transmit ( struct net_device *netdev,
513 448
 		/* Broadcast */
514 449
 		av.qpn = IB_QPN_BROADCAST;
515 450
 		av.lid = ipoib->broadcast_lid;
516
-		gid = &ipoib->broadcast_gid;
451
+		memcpy ( &av.gid, &ipoib->broadcast_gid, sizeof ( av.gid ) );
517 452
 	} else {
518 453
 		/* Unicast */
519
-		if ( ! dest->lid ) {
520
-			/* No LID yet - get path record to fetch LID */
521
-			ipoib_get_path_record ( ipoib, &dest->mac.gid );
522
-			return -ENOENT;
523
-		}
524 454
 		av.qpn = ntohl ( dest->mac.qpn );
525
-		av.lid = dest->lid;
526
-		av.rate = dest->rate;
527
-		av.sl = dest->sl;
528
-		gid = &dest->mac.gid;
455
+		memcpy ( &av.gid, &dest->mac.gid, sizeof ( av.gid ) );
456
+		if ( ( rc = ib_resolve_path ( ibdev, &av ) ) != 0 ) {
457
+			/* Path not resolved yet */
458
+			return rc;
459
+		}
529 460
 	}
530
-	memcpy ( &av.gid, gid, sizeof ( av.gid ) );
531 461
 
532 462
 	return ib_post_send ( ibdev, ipoib->data.qp, &av, iobuf );
533 463
 }
@@ -617,33 +547,6 @@ static void ipoib_meta_complete_send ( struct ib_device *ibdev __unused,
617 547
 	free_iob ( iobuf );
618 548
 }
619 549
 
620
-/**
621
- * Handle received IPoIB path record
622
- *
623
- * @v ipoib		IPoIB device
624
- * @v path_record	Path record
625
- */
626
-static void ipoib_recv_path_record ( struct ipoib_device *ipoib,
627
-				     struct ib_path_record *path_record ) {
628
-	struct ipoib_peer *peer;
629
-
630
-	/* Locate peer cache entry */
631
-	peer = ipoib_lookup_peer_by_gid ( &path_record->dgid );
632
-	if ( ! peer ) {
633
-		DBGC ( ipoib, "IPoIB %p received unsolicited path record\n",
634
-		       ipoib );
635
-		return;
636
-	}
637
-
638
-	/* Update path cache entry */
639
-	peer->lid = ntohs ( path_record->dlid );
640
-	peer->sl = ( path_record->reserved__sl & 0x0f );
641
-	peer->rate = ( path_record->rate_selector__rate & 0x3f );
642
-
643
-	DBG ( "IPoIB peer %x has dlid %x sl %x rate %x\n",
644
-	      peer->key, peer->lid, peer->sl, peer->rate );
645
-}
646
-
647 550
 /**
648 551
  * Handle received IPoIB multicast membership record
649 552
  *
@@ -710,9 +613,6 @@ ipoib_meta_complete_recv ( struct ib_device *ibdev __unused,
710 613
 	}
711 614
 
712 615
 	switch ( sa->mad_hdr.tid[0] ) {
713
-	case IPOIB_TID_GET_PATH_REC:
714
-		ipoib_recv_path_record ( ipoib, &sa->sa_data.path_record );
715
-		break;
716 616
 	case IPOIB_TID_MC_MEMBER_REC:
717 617
 		ipoib_recv_mc_member_record ( ipoib,
718 618
 					      &sa->sa_data.mc_member_record );

+ 1
- 0
src/include/gpxe/errfile.h Voir le fichier

@@ -145,6 +145,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
145 145
 #define ERRFILE_icmp			( ERRFILE_NET | 0x00190000 )
146 146
 #define ERRFILE_ib_qset			( ERRFILE_NET | 0x001a0000 )
147 147
 #define ERRFILE_ib_gma			( ERRFILE_NET | 0x001b0000 )
148
+#define ERRFILE_ib_pathrec		( ERRFILE_NET | 0x001c0000 )
148 149
 
149 150
 #define ERRFILE_image		      ( ERRFILE_IMAGE | 0x00000000 )
150 151
 #define ERRFILE_elf		      ( ERRFILE_IMAGE | 0x00010000 )

+ 17
- 0
src/include/gpxe/ib_pathrec.h Voir le fichier

@@ -0,0 +1,17 @@
1
+#ifndef _GPXE_IB_PATHREC_H
2
+#define _GPXE_IB_PATHREC_H
3
+
4
+/** @file
5
+ *
6
+ * Infiniband path records
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER );
11
+
12
+#include <gpxe/infiniband.h>
13
+
14
+extern int ib_resolve_path ( struct ib_device *ibdev,
15
+			     struct ib_address_vector *av );
16
+
17
+#endif /* _GPXE_IB_PATHREC_H */

+ 221
- 0
src/net/infiniband/ib_pathrec.c Voir le fichier

@@ -0,0 +1,221 @@
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 <stdint.h>
22
+#include <string.h>
23
+#include <byteswap.h>
24
+#include <errno.h>
25
+#include <gpxe/infiniband.h>
26
+#include <gpxe/ib_gma.h>
27
+#include <gpxe/ib_pathrec.h>
28
+
29
+/** @file
30
+ *
31
+ * Infiniband path lookups
32
+ *
33
+ */
34
+
35
+/** Number of path record cache entries
36
+ *
37
+ * Must be a power of two.
38
+ */
39
+#define IB_NUM_CACHED_PATHS 4
40
+
41
+/** A path record cache entry */
42
+struct ib_cached_path_record {
43
+	/** Infiniband device's port GID
44
+	 *
45
+	 * Used to disambiguate cache entries when we have multiple
46
+	 * Infiniband devices, without having to maintain a pointer to
47
+	 * the Infiniband device.
48
+	 */
49
+	struct ib_gid sgid;
50
+	/** Destination GID */
51
+	struct ib_gid dgid;
52
+	/** Destination LID */
53
+	unsigned int dlid;
54
+	/** Rate */
55
+	unsigned int rate;
56
+	/** Service level */
57
+	unsigned int sl;
58
+};
59
+
60
+/** Path record cache */
61
+static struct ib_cached_path_record ib_path_cache[IB_NUM_CACHED_PATHS];
62
+
63
+/** Oldest path record cache entry index */
64
+static unsigned int ib_path_cache_idx;
65
+
66
+/**
67
+ * Find path record cache entry
68
+ *
69
+ * @v ibdev		Infiniband device
70
+ * @v dgid		Destination GID
71
+ * @ret cached		Path record cache entry, or NULL
72
+ */
73
+static struct ib_cached_path_record *
74
+ib_find_path_cache_entry ( struct ib_device *ibdev, struct ib_gid *dgid ) {
75
+	struct ib_cached_path_record *cached;
76
+	unsigned int i;
77
+
78
+	for ( i = 0 ; i < IB_NUM_CACHED_PATHS ; i++ ) {
79
+		cached = &ib_path_cache[i];
80
+		if ( memcmp ( &cached->sgid, &ibdev->gid,
81
+			      sizeof ( cached->sgid ) ) != 0 )
82
+			continue;
83
+		if ( memcmp ( &cached->dgid, dgid,
84
+			      sizeof ( cached->dgid ) ) != 0 )
85
+			continue;
86
+		return cached;
87
+	}
88
+
89
+	return NULL;
90
+}
91
+
92
+/**
93
+ * Resolve path record
94
+ *
95
+ * @v ibdev		Infiniband device
96
+ * @v av		Address vector to complete
97
+ * @ret rc		Return status code
98
+ */
99
+int ib_resolve_path ( struct ib_device *ibdev,
100
+		      struct ib_address_vector *av ) {
101
+	struct ib_gid *gid = &av->gid;
102
+	struct ib_cached_path_record *cached;
103
+	union ib_mad mad;
104
+	struct ib_mad_sa *sa = &mad.sa;
105
+	unsigned int cache_idx;
106
+	int rc;
107
+
108
+	/* Sanity check */
109
+	if ( ! av->gid_present ) {
110
+		DBGC ( ibdev, "IBDEV %p attempt to look up path record "
111
+		       "without GID\n", ibdev );
112
+		return -EINVAL;
113
+	}
114
+
115
+	/* Look in cache for a matching entry */
116
+	cached = ib_find_path_cache_entry ( ibdev, gid );
117
+	if ( cached && cached->dlid ) {
118
+		/* Populated entry found */
119
+		av->lid = cached->dlid;
120
+		av->rate = cached->rate;
121
+		av->sl = cached->sl;
122
+		DBGC2 ( ibdev, "IBDEV %p cache hit for %08x:%08x:%08x:%08x\n",
123
+			ibdev, htonl ( gid->u.dwords[0] ),
124
+			htonl ( gid->u.dwords[1] ), htonl ( gid->u.dwords[2] ),
125
+			htonl ( gid->u.dwords[3] ) );
126
+		return 0;
127
+	}
128
+	DBGC ( ibdev, "IBDEV %p cache miss for %08x:%08x:%08x:%08x%s\n", ibdev,
129
+	       htonl ( gid->u.dwords[0] ), htonl ( gid->u.dwords[1] ),
130
+	       htonl ( gid->u.dwords[2] ), htonl ( gid->u.dwords[3] ),
131
+	       ( cached ? " (in progress)" : "" ) );
132
+
133
+	/* If no unresolved entry was found, then create a new one */
134
+	if ( ! cached ) {
135
+		cache_idx = ( (ib_path_cache_idx++) % IB_NUM_CACHED_PATHS );
136
+		cached = &ib_path_cache[cache_idx];
137
+		memset ( cached, 0, sizeof ( *cached ) );
138
+		memcpy ( &cached->sgid, &ibdev->gid, sizeof ( cached->sgid ) );
139
+		memcpy ( &cached->dgid, gid, sizeof ( cached->dgid ) );
140
+	}
141
+
142
+	/* Construct path record request */
143
+	memset ( sa, 0, sizeof ( *sa ) );
144
+	sa->mad_hdr.base_version = IB_MGMT_BASE_VERSION;
145
+	sa->mad_hdr.mgmt_class = IB_MGMT_CLASS_SUBN_ADM;
146
+	sa->mad_hdr.class_version = IB_SA_CLASS_VERSION;
147
+	sa->mad_hdr.method = IB_MGMT_METHOD_GET;
148
+	sa->mad_hdr.attr_id = htons ( IB_SA_ATTR_PATH_REC );
149
+	sa->sa_hdr.comp_mask[1] =
150
+		htonl ( IB_SA_PATH_REC_DGID | IB_SA_PATH_REC_SGID );
151
+	memcpy ( &sa->sa_data.path_record.dgid, &cached->dgid,
152
+		 sizeof ( sa->sa_data.path_record.dgid ) );
153
+	memcpy ( &sa->sa_data.path_record.sgid, &cached->sgid,
154
+		 sizeof ( sa->sa_data.path_record.sgid ) );
155
+
156
+	/* Issue path record request */
157
+	if ( ( rc = ib_gma_request ( &ibdev->gma, &mad, NULL ) ) != 0 ) {
158
+		DBGC ( ibdev, "IBDEV %p could not get path record: %s\n",
159
+		       ibdev, strerror ( rc ) );
160
+		return rc;
161
+	}
162
+
163
+	/* Not found yet */
164
+	return -ENOENT;
165
+}
166
+
167
+/**
168
+ * Handle path record response
169
+ *
170
+ * @v ibdev		Infiniband device
171
+ * @v mad		MAD
172
+ * @ret rc		Return status code
173
+ */
174
+static int ib_handle_path_record ( struct ib_device *ibdev,
175
+				   union ib_mad *mad ) {
176
+	struct ib_path_record *path_record = &mad->sa.sa_data.path_record;
177
+	struct ib_gid *dgid = &path_record->dgid;
178
+	struct ib_cached_path_record *cached;
179
+	unsigned int dlid;
180
+	unsigned int sl;
181
+	unsigned int rate;
182
+
183
+	/* Ignore if not a success */
184
+	if ( mad->hdr.status != htons ( IB_MGMT_STATUS_OK ) ) {
185
+		DBGC ( ibdev, "IBDEV %p path record lookup failed with status "
186
+		       "%04x\n", ibdev, ntohs ( mad->hdr.status ) );
187
+		return -EINVAL;
188
+	}
189
+
190
+	/* Extract values from MAD */
191
+	dlid = ntohs ( path_record->dlid );
192
+	sl = ( path_record->reserved__sl & 0x0f );
193
+	rate = ( path_record->rate_selector__rate & 0x3f );
194
+	DBGC ( ibdev, "IBDEV %p path to %08x:%08x:%08x:%08x is %04x sl %d "
195
+	       "rate %d\n", ibdev, htonl ( dgid->u.dwords[0] ),
196
+	       htonl ( dgid->u.dwords[1] ), htonl ( dgid->u.dwords[2] ),
197
+	       htonl ( dgid->u.dwords[3] ), dlid, sl, rate );
198
+
199
+	/* Look for a matching cache entry to fill in */
200
+	if ( ( cached = ib_find_path_cache_entry ( ibdev, dgid ) ) != NULL ) {
201
+		DBGC ( ibdev, "IBDEV %p cache add for %08x:%08x:%08x:%08x\n",
202
+		       ibdev, htonl ( dgid->u.dwords[0] ),
203
+		       htonl ( dgid->u.dwords[1] ),
204
+		       htonl ( dgid->u.dwords[2] ),
205
+		       htonl ( dgid->u.dwords[3] ) );
206
+		cached->dlid = dlid;
207
+		cached->rate = rate;
208
+		cached->sl = sl;
209
+	}
210
+
211
+	return 0;
212
+}
213
+
214
+/** Path record response handler */
215
+struct ib_mad_handler ib_path_record_handler __ib_mad_handler = {
216
+	.mgmt_class = IB_MGMT_CLASS_SUBN_ADM,
217
+	.class_version = IB_SA_CLASS_VERSION,
218
+	.method = IB_MGMT_METHOD_GET_RESP,
219
+	.attr_id = htons ( IB_SA_ATTR_PATH_REC ),
220
+	.handle = ib_handle_path_record,
221
+};

Chargement…
Annuler
Enregistrer