Browse Source

Started IB driver rewrite

tags/v0.9.3
Michael Brown 17 years ago
parent
commit
7b6d11e713

+ 7
- 0
src/drivers/net/mlx_ipoib/ib_mt25218.c View File

@@ -1586,6 +1586,13 @@ static void prep_send_wqe_buf(void *qph,
1586 1586
 		len += offset;
1587 1587
 	}
1588 1588
 	snd_wqe->mpointer[0].byte_count = cpu_to_be32(len);
1589
+
1590
+	DBG ( "prep_send_wqe_buf()\n" );
1591
+	DBG ( "snd_wqe:\n" );
1592
+	DBG_HD ( snd_wqe, sizeof ( *snd_wqe ) );
1593
+	DBG ( "packet:\n" );
1594
+	DBG_HD ( bus_to_virt(be32_to_cpu(snd_wqe->mpointer[0].local_addr_l)),
1595
+		 len );
1589 1596
 }
1590 1597
 
1591 1598
 static void *alloc_ud_av(void)

+ 201
- 5
src/drivers/net/mlx_ipoib/mt25218.c View File

@@ -10,6 +10,15 @@ Skeleton NIC driver for Etherboot
10 10
  * your option) any later version.
11 11
  */
12 12
 
13
+#include <errno.h>
14
+#include <gpxe/pci.h>
15
+#include <gpxe/iobuf.h>
16
+#include <gpxe/netdevice.h>
17
+#include <gpxe/infiniband.h>
18
+
19
+struct mlx_nic {
20
+};
21
+
13 22
 /* to get some global routines like printf */
14 23
 #include "etherboot.h"
15 24
 /* to get the interface to the body of the program */
@@ -145,6 +154,131 @@ static void mt25218_transmit(struct nic *nic, const char *dest,	/* Destination *
145 154
 	}
146 155
 }
147 156
 
157
+/**
158
+ * Open network device
159
+ *
160
+ * @v netdev		Network device
161
+ * @ret rc		Return status code
162
+ */
163
+static int mlx_open ( struct net_device *netdev ) {
164
+	return 0;
165
+}
166
+
167
+/**
168
+ * Close network device
169
+ *
170
+ * @v netdev		Network device
171
+ */
172
+static void mlx_close ( struct net_device *netdev ) {
173
+}
174
+
175
+#warning "Broadcast address?"
176
+static uint8_t ib_broadcast[IB_ALEN] = { 0xff, };
177
+
178
+
179
+/**
180
+ * Transmit packet
181
+ *
182
+ * @v netdev		Network device
183
+ * @v iobuf		I/O buffer
184
+ * @ret rc		Return status code
185
+ */
186
+static int mlx_transmit ( struct net_device *netdev,
187
+			  struct io_buffer *iobuf ) {
188
+	struct ibhdr *ibhdr = iobuf->data;
189
+
190
+	DBG ( "Sending packet:\n" );
191
+	//	DBG_HD ( iobuf->data, iob_len ( iobuf ) );
192
+
193
+	DBG ( "Peer:\n" );
194
+	DBG_HD ( &ibhdr->peer[0], IB_ALEN );
195
+	DBG ( "Bcast:\n" );
196
+	DBG_HD ( &ib_broadcast[0], IB_ALEN );
197
+
198
+	iob_pull ( iobuf, sizeof ( *ibhdr ) );	
199
+
200
+	if ( memcmp ( ibhdr->peer, ib_broadcast, IB_ALEN ) == 0 ) {
201
+		printf ( "Sending broadcast packet\n" );
202
+		return send_bcast_packet ( ibhdr->proto, iobuf->data,
203
+					   iob_len ( iobuf ) );
204
+	} else {
205
+		printf ( "Sending unicast packet\n" );
206
+		return send_ucast_packet ( ibhdr->peer, ibhdr->proto,
207
+					   iobuf->data, iob_len ( iobuf ) );
208
+	}
209
+}
210
+
211
+/**
212
+ * Poll for completed and received packets
213
+ *
214
+ * @v netdev		Network device
215
+ */
216
+static void mlx_poll ( struct net_device *netdev ) {
217
+	struct ib_cqe_st ib_cqe;
218
+	uint8_t num_cqes;
219
+	unsigned int len;
220
+	struct io_buffer *iobuf;
221
+	void *buf;
222
+	int rc;
223
+
224
+	if ( ( rc = poll_error_buf() ) != 0 ) {
225
+		DBG ( "poll_error_buf() failed: %s\n", strerror ( rc ) );
226
+		return;
227
+	}
228
+
229
+	if ( ( rc = drain_eq() ) != 0 ) {
230
+		DBG ( "drain_eq() failed: %s\n", strerror ( rc ) );
231
+		return;
232
+	}
233
+
234
+	if ( ( rc = ib_poll_cq ( ipoib_data.rcv_cqh, &ib_cqe,
235
+				 &num_cqes ) ) != 0 ) {
236
+		DBG ( "ib_poll_cq() failed: %s\n", strerror ( rc ) );
237
+		return;
238
+	}
239
+
240
+	if ( ! num_cqes )
241
+		return;
242
+
243
+	if ( ib_cqe.is_error ) {
244
+		DBG ( "cqe error\n" );
245
+		free_wqe ( ib_cqe.wqe );
246
+		return;
247
+	}
248
+
249
+	len = ib_cqe.count;
250
+	iobuf = alloc_iob ( len );
251
+	if ( ! iobuf ) {
252
+		DBG ( "out of memory\n" );
253
+		free_wqe ( ib_cqe.wqe );
254
+		return;
255
+	}
256
+	memcpy ( iob_put ( iobuf, len ), buf, len );
257
+	DBG ( "Received packet:\n" );
258
+	DBG_HD ( iobuf->data, iob_len ( iobuf ) );
259
+
260
+	netdev_rx ( netdev, iobuf );
261
+
262
+	free_wqe ( ib_cqe.wqe );
263
+}
264
+
265
+/**
266
+ * Enable or disable interrupts
267
+ *
268
+ * @v netdev		Network device
269
+ * @v enable		Interrupts should be enabled
270
+ */
271
+static void mlx_irq ( struct net_device *netdev, int enable ) {
272
+}
273
+
274
+static struct net_device_operations mlx_operations = {
275
+	.open		= mlx_open,
276
+	.close		= mlx_close,
277
+	.transmit	= mlx_transmit,
278
+	.poll		= mlx_poll,
279
+	.irq		= mlx_irq,
280
+};
281
+
148 282
 /**************************************************************************
149 283
 DISABLE - Turn off ethernet interface
150 284
 ***************************************************************************/
@@ -165,6 +299,21 @@ static void mt25218_disable(struct nic *nic)
165 299
 	}
166 300
 }
167 301
 
302
+/**
303
+ * Remove PCI device
304
+ *
305
+ * @v pci		PCI device
306
+ */
307
+static void mlx_remove ( struct pci_device *pci ) {
308
+	struct net_device *netdev = pci_get_drvdata ( pci );
309
+	struct mlx_nic *mlx = netdev->priv;
310
+
311
+	unregister_netdev ( netdev );
312
+	ipoib_close(0);
313
+	netdev_nullify ( netdev );
314
+	netdev_put ( netdev );
315
+}
316
+
168 317
 static struct nic_operations mt25218_operations = {
169 318
 	.connect	= dummy_connect,
170 319
 	.poll		= mt25218_poll,
@@ -233,12 +382,59 @@ static int mt25218_probe(struct nic *nic, struct pci_device *pci)
233 382
 	return 0;
234 383
 }
235 384
 
236
-static struct pci_device_id mt25218_nics[] = {
385
+/**
386
+ * Probe PCI device
387
+ *
388
+ * @v pci		PCI device
389
+ * @v id		PCI ID
390
+ * @ret rc		Return status code
391
+ */
392
+static int mlx_probe ( struct pci_device *pci,
393
+		       const struct pci_device_id *id __unused ) {
394
+	struct net_device *netdev;
395
+	struct mlx_nic *mlx;
396
+	int rc;
397
+
398
+	/* Allocate net device */
399
+	netdev = alloc_ibdev ( sizeof ( *mlx ) );
400
+	if ( ! netdev )
401
+		return -ENOMEM;
402
+	netdev_init ( netdev, &mlx_operations );
403
+	mlx = netdev->priv;
404
+	pci_set_drvdata ( pci, netdev );
405
+	netdev->dev = &pci->dev;
406
+	memset ( mlx, 0, sizeof ( *mlx ) );
407
+
408
+	/* Fix up PCI device */
409
+	adjust_pci_device ( pci );
410
+
411
+	/* Initialise hardware */
412
+	if ( ( rc = ipoib_init ( pci ) ) != 0 )
413
+		goto err_ipoib_init;
414
+	memcpy ( netdev->ll_addr, ipoib_data.port_gid_raw, IB_ALEN );
415
+
416
+	/* Register network device */
417
+	if ( ( rc = register_netdev ( netdev ) ) != 0 )
418
+		goto err_register_netdev;
419
+
420
+	return 0;
421
+
422
+ err_register_netdev:
423
+ err_ipoib_init:
424
+	ipoib_close(0);
425
+	netdev_nullify ( netdev );
426
+	netdev_put ( netdev );
427
+	return rc;
428
+}
429
+
430
+static struct pci_device_id mlx_nics[] = {
237 431
 	PCI_ROM(0x15b3, 0x6282, "MT25218", "MT25218 HCA driver"),
238 432
 	PCI_ROM(0x15b3, 0x6274, "MT25204", "MT25204 HCA driver"),
239 433
 };
240 434
 
241
-PCI_DRIVER ( mt25218_driver, mt25218_nics, PCI_NO_CLASS );
242
-
243
-DRIVER ( "MT25218", nic_driver, pci_driver, mt25218_driver,
244
-	 mt25218_probe, mt25218_disable );
435
+struct pci_driver mlx_driver __pci_driver = {
436
+	.ids = mlx_nics,
437
+	.id_count = ( sizeof ( mlx_nics ) / sizeof ( mlx_nics[0] ) ),
438
+	.probe = mlx_probe,
439
+	.remove = mlx_remove,
440
+};

+ 1
- 0
src/include/gpxe/errfile.h View File

@@ -123,6 +123,7 @@
123 123
 #define ERRFILE_dhcp			( ERRFILE_NET | 0x00100000 )
124 124
 #define ERRFILE_dns			( ERRFILE_NET | 0x00110000 )
125 125
 #define ERRFILE_tftp			( ERRFILE_NET | 0x00120000 )
126
+#define ERRFILE_infiniband		( ERRFILE_NET | 0x00130000 )
126 127
 
127 128
 #define ERRFILE_image		      ( ERRFILE_IMAGE | 0x00000000 )
128 129
 #define ERRFILE_elf		      ( ERRFILE_IMAGE | 0x00010000 )

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

@@ -0,0 +1,52 @@
1
+#ifndef _GPXE_INFINIBAND_H
2
+#define _GPXE_INFINIBAND_H
3
+
4
+/** @file
5
+ *
6
+ * Infiniband protocol
7
+ *
8
+ */
9
+
10
+#include <stdint.h>
11
+#include <gpxe/netdevice.h>
12
+
13
+/** Infiniband hardware address length */
14
+#define IB_ALEN 20
15
+#define IB_HLEN 24
16
+
17
+/** An Infiniband header
18
+ *
19
+ * This data structure doesn't represent the on-wire format, but does
20
+ * contain all the information required by the driver to construct the
21
+ * packet.
22
+ */
23
+struct ibhdr {
24
+	/** Peer address */
25
+	uint8_t peer[IB_ALEN];
26
+	/** Network-layer protocol */
27
+	uint16_t proto;
28
+	/** Reserved, must be zero */
29
+	uint16_t reserved;
30
+} __attribute__ (( packed ));
31
+
32
+extern struct ll_protocol infiniband_protocol;
33
+
34
+extern const char * ib_ntoa ( const void *ll_addr );
35
+
36
+/**
37
+ * Allocate Infiniband device
38
+ *
39
+ * @v priv_size		Size of driver private data
40
+ * @ret netdev		Network device, or NULL
41
+ */
42
+static inline struct net_device * alloc_ibdev ( size_t priv_size ) {
43
+	struct net_device *netdev;
44
+
45
+	netdev = alloc_netdev ( priv_size );
46
+	if ( netdev ) {
47
+		netdev->ll_protocol = &infiniband_protocol;
48
+	}
49
+	return netdev;
50
+}
51
+
52
+#endif /* _GPXE_INFINIBAND_H */

+ 2
- 2
src/include/gpxe/netdevice.h View File

@@ -19,10 +19,10 @@ struct ll_protocol;
19 19
 struct device;
20 20
 
21 21
 /** Maximum length of a link-layer address */
22
-#define MAX_LL_ADDR_LEN 6
22
+#define MAX_LL_ADDR_LEN 20
23 23
 
24 24
 /** Maximum length of a link-layer header */
25
-#define MAX_LL_HEADER_LEN 16
25
+#define MAX_LL_HEADER_LEN 32
26 26
 
27 27
 /** Maximum length of a network-layer address */
28 28
 #define MAX_NET_ADDR_LEN 4

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

@@ -0,0 +1,118 @@
1
+/*
2
+ * Copyright (C) 2007 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
+#include <stdint.h>
20
+#include <stdio.h>
21
+#include <string.h>
22
+#include <byteswap.h>
23
+#include <errno.h>
24
+#include <assert.h>
25
+#include <gpxe/if_arp.h>
26
+#include <gpxe/netdevice.h>
27
+#include <gpxe/iobuf.h>
28
+#include <gpxe/infiniband.h>
29
+
30
+/** @file
31
+ *
32
+ * Infiniband protocol
33
+ *
34
+ */
35
+
36
+/** Infiniband broadcast MAC address */
37
+static uint8_t ib_broadcast[IB_ALEN] = { 0xff, };
38
+
39
+/**
40
+ * Transmit Infiniband packet
41
+ *
42
+ * @v iobuf		I/O buffer
43
+ * @v netdev		Network device
44
+ * @v net_protocol	Network-layer protocol
45
+ * @v ll_dest		Link-layer destination address
46
+ *
47
+ * Prepends the Infiniband link-layer header and transmits the packet.
48
+ */
49
+static int ib_tx ( struct io_buffer *iobuf, struct net_device *netdev,
50
+		   struct net_protocol *net_protocol, const void *ll_dest ) {
51
+	struct ibhdr *ibhdr = iob_push ( iobuf, sizeof ( *ibhdr ) );
52
+
53
+
54
+	/* Build Infiniband header */
55
+	memcpy ( ibhdr->peer, ll_dest, IB_ALEN );
56
+	ibhdr->proto = net_protocol->net_proto;
57
+	ibhdr->reserved = 0;
58
+
59
+	/* Hand off to network device */
60
+	return netdev_tx ( netdev, iobuf );
61
+}
62
+
63
+/**
64
+ * Process received Infiniband packet
65
+ *
66
+ * @v iobuf	I/O buffer
67
+ * @v netdev	Network device
68
+ *
69
+ * Strips off the Infiniband link-layer header and passes up to the
70
+ * network-layer protocol.
71
+ */
72
+static int ib_rx ( struct io_buffer *iobuf, struct net_device *netdev ) {
73
+	struct ibhdr *ibhdr = iobuf->data;
74
+
75
+	/* Sanity check */
76
+	if ( iob_len ( iobuf ) < sizeof ( *ibhdr ) ) {
77
+		DBG ( "Infiniband packet too short (%d bytes)\n",
78
+		      iob_len ( iobuf ) );
79
+		free_iob ( iobuf );
80
+		return -EINVAL;
81
+	}
82
+
83
+	/* Strip off Infiniband header */
84
+	iob_pull ( iobuf, sizeof ( *ibhdr ) );
85
+
86
+	/* Hand off to network-layer protocol */
87
+	return net_rx ( iobuf, netdev, ibhdr->proto, ibhdr->peer );
88
+}
89
+
90
+/**
91
+ * Transcribe Infiniband address
92
+ *
93
+ * @v ll_addr	Link-layer address
94
+ * @ret string	Link-layer address in human-readable format
95
+ */
96
+const char * ib_ntoa ( const void *ll_addr ) {
97
+	static char buf[61];
98
+	const uint8_t *ib_addr = ll_addr;
99
+	unsigned int i;
100
+	char *p = buf;
101
+
102
+	for ( i = 0 ; i < IB_ALEN ; i++ ) {
103
+		p += sprintf ( p, ":%02x", ib_addr[i] );
104
+	}
105
+	return ( buf + 1 );
106
+}
107
+
108
+/** Infiniband protocol */
109
+struct ll_protocol infiniband_protocol __ll_protocol = {
110
+	.name		= "Infiniband",
111
+	.ll_proto	= htons ( ARPHRD_INFINIBAND ),
112
+	.ll_addr_len	= IB_ALEN,
113
+	.ll_header_len	= IB_HLEN,
114
+	.ll_broadcast	= ib_broadcast,
115
+	.tx		= ib_tx,
116
+	.rx		= ib_rx,
117
+	.ntoa		= ib_ntoa,
118
+};

Loading…
Cancel
Save