Browse Source

[netdevice] Make ll_broadcast per-netdevice rather than per-ll_protocol

IPoIB has a link-layer broadcast address that varies according to the
partition key.  We currently go through several contortions to pretend
that the link-layer address is a fixed constant; by making the
broadcast address a property of the network device rather than the
link-layer protocol it will be possible to simplify IPoIB's broadcast
handling.
tags/v0.9.8
Michael Brown 15 years ago
parent
commit
d09290161e

+ 1
- 1
src/arch/i386/interface/pxe/pxe_undi.c View File

300
 			ll_dest = destaddr;
300
 			ll_dest = destaddr;
301
 			DBG2 ( " DEST %s", ll_protocol->ntoa ( ll_dest ) );
301
 			DBG2 ( " DEST %s", ll_protocol->ntoa ( ll_dest ) );
302
 		} else {
302
 		} else {
303
-			ll_dest = ll_protocol->ll_broadcast;
303
+			ll_dest = pxe_netdev->ll_broadcast;
304
 			DBG2 ( " BCAST" );
304
 			DBG2 ( " BCAST" );
305
 		}
305
 		}
306
 
306
 

+ 18
- 1
src/drivers/net/ipoib.c View File

348
 	.ll_proto	= htons ( ARPHRD_INFINIBAND ),
348
 	.ll_proto	= htons ( ARPHRD_INFINIBAND ),
349
 	.ll_addr_len	= IPOIB_ALEN,
349
 	.ll_addr_len	= IPOIB_ALEN,
350
 	.ll_header_len	= IPOIB_HLEN,
350
 	.ll_header_len	= IPOIB_HLEN,
351
-	.ll_broadcast	= ( uint8_t * ) &ipoib_broadcast,
352
 	.push		= ipoib_push,
351
 	.push		= ipoib_push,
353
 	.pull		= ipoib_pull,
352
 	.pull		= ipoib_pull,
354
 	.ntoa		= ipoib_ntoa,
353
 	.ntoa		= ipoib_ntoa,
1132
 	netdev_nullify ( netdev );
1131
 	netdev_nullify ( netdev );
1133
 	netdev_put ( netdev );
1132
 	netdev_put ( netdev );
1134
 }
1133
 }
1134
+
1135
+/**
1136
+ * Allocate IPoIB device
1137
+ *
1138
+ * @v priv_size		Size of driver private data
1139
+ * @ret netdev		Network device, or NULL
1140
+ */
1141
+struct net_device * alloc_ipoibdev ( size_t priv_size ) {
1142
+	struct net_device *netdev;
1143
+
1144
+	netdev = alloc_netdev ( priv_size );
1145
+	if ( netdev ) {
1146
+		netdev->ll_protocol = &ipoib_protocol;
1147
+		netdev->ll_broadcast = ( uint8_t * ) &ipoib_broadcast;
1148
+		netdev->max_pkt_len = IPOIB_PKT_LEN;
1149
+	}
1150
+	return netdev;
1151
+}

+ 1
- 1
src/drivers/net/legacy.c View File

122
 
122
 
123
 	/* Do not remove this message */
123
 	/* Do not remove this message */
124
 	printf ( "WARNING: Using legacy NIC wrapper on %s\n",
124
 	printf ( "WARNING: Using legacy NIC wrapper on %s\n",
125
-		 ethernet_protocol.ntoa ( nic.node_addr ) );
125
+		 netdev->ll_protocol->ntoa ( nic.node_addr ) );
126
 
126
 
127
 	legacy_registered = 1;
127
 	legacy_registered = 1;
128
 	return 0;
128
 	return 0;

+ 3
- 5
src/drivers/net/phantom/phantom.c View File

1156
 	 * firmware doesn't currently support this.
1156
 	 * firmware doesn't currently support this.
1157
 	 */
1157
 	 */
1158
 	if ( ( rc = phantom_add_macaddr ( phantom,
1158
 	if ( ( rc = phantom_add_macaddr ( phantom,
1159
-				   netdev->ll_protocol->ll_broadcast ) ) != 0 )
1159
+					  netdev->ll_broadcast ) ) != 0 )
1160
 		goto err_add_macaddr_broadcast;
1160
 		goto err_add_macaddr_broadcast;
1161
 	if ( ( rc = phantom_add_macaddr ( phantom,
1161
 	if ( ( rc = phantom_add_macaddr ( phantom,
1162
 					  netdev->ll_addr ) ) != 0 )
1162
 					  netdev->ll_addr ) ) != 0 )
1166
 
1166
 
1167
 	phantom_del_macaddr ( phantom, netdev->ll_addr );
1167
 	phantom_del_macaddr ( phantom, netdev->ll_addr );
1168
  err_add_macaddr_unicast:
1168
  err_add_macaddr_unicast:
1169
-	phantom_del_macaddr ( phantom,
1170
-			      netdev->ll_protocol->ll_broadcast );
1169
+	phantom_del_macaddr ( phantom, netdev->ll_broadcast );
1171
  err_add_macaddr_broadcast:
1170
  err_add_macaddr_broadcast:
1172
 	phantom_destroy_tx_ctx ( phantom );
1171
 	phantom_destroy_tx_ctx ( phantom );
1173
  err_create_tx_ctx:
1172
  err_create_tx_ctx:
1191
 
1190
 
1192
 	/* Shut down the port */
1191
 	/* Shut down the port */
1193
 	phantom_del_macaddr ( phantom, netdev->ll_addr );
1192
 	phantom_del_macaddr ( phantom, netdev->ll_addr );
1194
-	phantom_del_macaddr ( phantom,
1195
-			      netdev->ll_protocol->ll_broadcast );
1193
+	phantom_del_macaddr ( phantom, netdev->ll_broadcast );
1196
 	phantom_destroy_tx_ctx ( phantom );
1194
 	phantom_destroy_tx_ctx ( phantom );
1197
 	phantom_destroy_rx_ctx ( phantom );
1195
 	phantom_destroy_rx_ctx ( phantom );
1198
 	free_dma ( phantom->desc, sizeof ( *(phantom->desc) ) );
1196
 	free_dma ( phantom->desc, sizeof ( *(phantom->desc) ) );

+ 1
- 21
src/include/gpxe/ethernet.h View File

10
 FILE_LICENCE ( GPL2_OR_LATER );
10
 FILE_LICENCE ( GPL2_OR_LATER );
11
 
11
 
12
 #include <stdint.h>
12
 #include <stdint.h>
13
-#include <gpxe/netdevice.h>
14
-#include <gpxe/if_ether.h>
15
-
16
-extern struct ll_protocol ethernet_protocol;
17
 
13
 
18
 extern const char * eth_ntoa ( const void *ll_addr );
14
 extern const char * eth_ntoa ( const void *ll_addr );
19
-
20
-/**
21
- * Allocate Ethernet device
22
- *
23
- * @v priv_size		Size of driver private data
24
- * @ret netdev		Network device, or NULL
25
- */
26
-static inline struct net_device * alloc_etherdev ( size_t priv_size ) {
27
-	struct net_device *netdev;
28
-
29
-	netdev = alloc_netdev ( priv_size );
30
-	if ( netdev ) {
31
-		netdev->ll_protocol = &ethernet_protocol;
32
-		netdev->max_pkt_len = ETH_FRAME_LEN;
33
-	}
34
-	return netdev;
35
-}
15
+extern struct net_device * alloc_etherdev ( size_t priv_size );
36
 
16
 
37
 #endif /* _GPXE_ETHERNET_H */
17
 #endif /* _GPXE_ETHERNET_H */

+ 1
- 20
src/include/gpxe/ipoib.h View File

54
 	} __attribute__ (( packed )) u;
54
 	} __attribute__ (( packed )) u;
55
 } __attribute__ (( packed ));
55
 } __attribute__ (( packed ));
56
 
56
 
57
-extern struct ll_protocol ipoib_protocol;
58
-
59
 extern const char * ipoib_ntoa ( const void *ll_addr );
57
 extern const char * ipoib_ntoa ( const void *ll_addr );
60
-
61
-/**
62
- * Allocate IPoIB device
63
- *
64
- * @v priv_size		Size of driver private data
65
- * @ret netdev		Network device, or NULL
66
- */
67
-static inline struct net_device * alloc_ipoibdev ( size_t priv_size ) {
68
-	struct net_device *netdev;
69
-
70
-	netdev = alloc_netdev ( priv_size );
71
-	if ( netdev ) {
72
-		netdev->ll_protocol = &ipoib_protocol;
73
-		netdev->max_pkt_len = IPOIB_PKT_LEN;
74
-	}
75
-	return netdev;
76
-}
77
-
78
 extern void ipoib_link_state_changed ( struct ib_device *ibdev );
58
 extern void ipoib_link_state_changed ( struct ib_device *ibdev );
79
 extern int ipoib_probe ( struct ib_device *ibdev );
59
 extern int ipoib_probe ( struct ib_device *ibdev );
80
 extern void ipoib_remove ( struct ib_device *ibdev );
60
 extern void ipoib_remove ( struct ib_device *ibdev );
61
+extern struct net_device * alloc_ipoibdev ( size_t priv_size );
81
 
62
 
82
 #endif /* _GPXE_IPOIB_H */
63
 #endif /* _GPXE_IPOIB_H */

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

144
 	uint8_t ll_addr_len;
144
 	uint8_t ll_addr_len;
145
 	/** Link-layer header length */
145
 	/** Link-layer header length */
146
 	uint8_t ll_header_len;
146
 	uint8_t ll_header_len;
147
-	/** Link-layer broadcast address */
148
-	const uint8_t *ll_broadcast;
149
 };
147
 };
150
 
148
 
151
 /** Network device operations */
149
 /** Network device operations */
261
 	 * For Ethernet, this is the MAC address.
259
 	 * For Ethernet, this is the MAC address.
262
 	 */
260
 	 */
263
 	uint8_t ll_addr[MAX_LL_ADDR_LEN];
261
 	uint8_t ll_addr[MAX_LL_ADDR_LEN];
262
+	/** Link-layer broadcast address */
263
+	const uint8_t *ll_broadcast;
264
 
264
 
265
 	/** Current device state
265
 	/** Current device state
266
 	 *
266
 	 *

+ 1
- 2
src/interface/efi/efi_snp.c View File

129
 				    EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST );
129
 				    EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST );
130
 	assert ( ll_addr_len <= sizeof ( mode->CurrentAddress ) );
130
 	assert ( ll_addr_len <= sizeof ( mode->CurrentAddress ) );
131
 	memcpy ( &mode->CurrentAddress, netdev->ll_addr, ll_addr_len );
131
 	memcpy ( &mode->CurrentAddress, netdev->ll_addr, ll_addr_len );
132
-	memcpy ( &mode->BroadcastAddress, netdev->ll_protocol->ll_broadcast,
133
-		 ll_addr_len );
132
+	memcpy ( &mode->BroadcastAddress, netdev->ll_broadcast, ll_addr_len );
134
 	memcpy ( &mode->PermanentAddress, netdev->ll_addr, ll_addr_len );
133
 	memcpy ( &mode->PermanentAddress, netdev->ll_addr, ll_addr_len );
135
 	mode->IfType = ntohs ( netdev->ll_protocol->ll_proto );
134
 	mode->IfType = ntohs ( netdev->ll_protocol->ll_proto );
136
 	mode->MacAddressChangeable = TRUE;
135
 	mode->MacAddressChangeable = TRUE;

+ 1
- 2
src/net/aoe.c View File

440
 		return -ENOMEM;
440
 		return -ENOMEM;
441
 	aoe->refcnt.free = aoe_free;
441
 	aoe->refcnt.free = aoe_free;
442
 	aoe->netdev = netdev_get ( netdev );
442
 	aoe->netdev = netdev_get ( netdev );
443
-	memcpy ( aoe->target, ethernet_protocol.ll_broadcast,
444
-		 sizeof ( aoe->target ) );
443
+	memcpy ( aoe->target, netdev->ll_broadcast, sizeof ( aoe->target ) );
445
 	aoe->tag = AOE_TAG_MAGIC;
444
 	aoe->tag = AOE_TAG_MAGIC;
446
 	aoe->timer.expired = aoe_timer_expired;
445
 	aoe->timer.expired = aoe_timer_expired;
447
 
446
 

+ 1
- 1
src/net/arp.c View File

156
 
156
 
157
 	/* Transmit ARP request */
157
 	/* Transmit ARP request */
158
 	if ( ( rc = net_tx ( iobuf, netdev, &arp_protocol, 
158
 	if ( ( rc = net_tx ( iobuf, netdev, &arp_protocol, 
159
-			     ll_protocol->ll_broadcast ) ) != 0 )
159
+			     netdev->ll_broadcast ) ) != 0 )
160
 		return rc;
160
 		return rc;
161
 
161
 
162
 	return -ENOENT;
162
 	return -ENOENT;

+ 18
- 1
src/net/ethernet.c View File

145
 	.ll_proto	= htons ( ARPHRD_ETHER ),
145
 	.ll_proto	= htons ( ARPHRD_ETHER ),
146
 	.ll_addr_len	= ETH_ALEN,
146
 	.ll_addr_len	= ETH_ALEN,
147
 	.ll_header_len	= ETH_HLEN,
147
 	.ll_header_len	= ETH_HLEN,
148
-	.ll_broadcast	= eth_broadcast,
149
 	.push		= eth_push,
148
 	.push		= eth_push,
150
 	.pull		= eth_pull,
149
 	.pull		= eth_pull,
151
 	.ntoa		= eth_ntoa,
150
 	.ntoa		= eth_ntoa,
152
 	.mc_hash	= eth_mc_hash,
151
 	.mc_hash	= eth_mc_hash,
153
 };
152
 };
153
+
154
+/**
155
+ * Allocate Ethernet device
156
+ *
157
+ * @v priv_size		Size of driver private data
158
+ * @ret netdev		Network device, or NULL
159
+ */
160
+struct net_device * alloc_etherdev ( size_t priv_size ) {
161
+	struct net_device *netdev;
162
+
163
+	netdev = alloc_netdev ( priv_size );
164
+	if ( netdev ) {
165
+		netdev->ll_protocol = &ethernet_protocol;
166
+		netdev->ll_broadcast = eth_broadcast;
167
+		netdev->max_pkt_len = ETH_FRAME_LEN;
168
+	}
169
+	return netdev;
170
+}

+ 1
- 1
src/net/ipv4.c View File

271
 
271
 
272
 	if ( dest.s_addr == INADDR_BROADCAST ) {
272
 	if ( dest.s_addr == INADDR_BROADCAST ) {
273
 		/* Broadcast address */
273
 		/* Broadcast address */
274
-		memcpy ( ll_dest, ll_protocol->ll_broadcast,
274
+		memcpy ( ll_dest, netdev->ll_broadcast,
275
 			 ll_protocol->ll_addr_len );
275
 			 ll_protocol->ll_addr_len );
276
 		return 0;
276
 		return 0;
277
 	} else if ( IN_MULTICAST ( ntohl ( dest.s_addr ) ) ) {
277
 	} else if ( IN_MULTICAST ( ntohl ( dest.s_addr ) ) ) {

Loading…
Cancel
Save