Skip to content

Commit

Permalink
[netdevice] Make ll_broadcast per-netdevice rather than per-ll_protocol
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Michael Brown committed Jul 17, 2009
1 parent 54ec367 commit d092901
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 58 deletions.
2 changes: 1 addition & 1 deletion src/arch/i386/interface/pxe/pxe_undi.c
Expand Up @@ -300,7 +300,7 @@ PXENV_EXIT_t pxenv_undi_transmit ( struct s_PXENV_UNDI_TRANSMIT
ll_dest = destaddr;
DBG2 ( " DEST %s", ll_protocol->ntoa ( ll_dest ) );
} else {
ll_dest = ll_protocol->ll_broadcast;
ll_dest = pxe_netdev->ll_broadcast;
DBG2 ( " BCAST" );
}

Expand Down
19 changes: 18 additions & 1 deletion src/drivers/net/ipoib.c
Expand Up @@ -348,7 +348,6 @@ struct ll_protocol ipoib_protocol __ll_protocol = {
.ll_proto = htons ( ARPHRD_INFINIBAND ),
.ll_addr_len = IPOIB_ALEN,
.ll_header_len = IPOIB_HLEN,
.ll_broadcast = ( uint8_t * ) &ipoib_broadcast,
.push = ipoib_push,
.pull = ipoib_pull,
.ntoa = ipoib_ntoa,
Expand Down Expand Up @@ -1132,3 +1131,21 @@ void ipoib_remove ( struct ib_device *ibdev ) {
netdev_nullify ( netdev );
netdev_put ( netdev );
}

/**
* Allocate IPoIB device
*
* @v priv_size Size of driver private data
* @ret netdev Network device, or NULL
*/
struct net_device * alloc_ipoibdev ( size_t priv_size ) {
struct net_device *netdev;

netdev = alloc_netdev ( priv_size );
if ( netdev ) {
netdev->ll_protocol = &ipoib_protocol;
netdev->ll_broadcast = ( uint8_t * ) &ipoib_broadcast;
netdev->max_pkt_len = IPOIB_PKT_LEN;
}
return netdev;
}
2 changes: 1 addition & 1 deletion src/drivers/net/legacy.c
Expand Up @@ -122,7 +122,7 @@ int legacy_probe ( void *hwdev,

/* Do not remove this message */
printf ( "WARNING: Using legacy NIC wrapper on %s\n",
ethernet_protocol.ntoa ( nic.node_addr ) );
netdev->ll_protocol->ntoa ( nic.node_addr ) );

legacy_registered = 1;
return 0;
Expand Down
8 changes: 3 additions & 5 deletions src/drivers/net/phantom/phantom.c
Expand Up @@ -1156,7 +1156,7 @@ static int phantom_open ( struct net_device *netdev ) {
* firmware doesn't currently support this.
*/
if ( ( rc = phantom_add_macaddr ( phantom,
netdev->ll_protocol->ll_broadcast ) ) != 0 )
netdev->ll_broadcast ) ) != 0 )
goto err_add_macaddr_broadcast;
if ( ( rc = phantom_add_macaddr ( phantom,
netdev->ll_addr ) ) != 0 )
Expand All @@ -1166,8 +1166,7 @@ static int phantom_open ( struct net_device *netdev ) {

phantom_del_macaddr ( phantom, netdev->ll_addr );
err_add_macaddr_unicast:
phantom_del_macaddr ( phantom,
netdev->ll_protocol->ll_broadcast );
phantom_del_macaddr ( phantom, netdev->ll_broadcast );
err_add_macaddr_broadcast:
phantom_destroy_tx_ctx ( phantom );
err_create_tx_ctx:
Expand All @@ -1191,8 +1190,7 @@ static void phantom_close ( struct net_device *netdev ) {

/* Shut down the port */
phantom_del_macaddr ( phantom, netdev->ll_addr );
phantom_del_macaddr ( phantom,
netdev->ll_protocol->ll_broadcast );
phantom_del_macaddr ( phantom, netdev->ll_broadcast );
phantom_destroy_tx_ctx ( phantom );
phantom_destroy_rx_ctx ( phantom );
free_dma ( phantom->desc, sizeof ( *(phantom->desc) ) );
Expand Down
22 changes: 1 addition & 21 deletions src/include/gpxe/ethernet.h
Expand Up @@ -10,28 +10,8 @@
FILE_LICENCE ( GPL2_OR_LATER );

#include <stdint.h>
#include <gpxe/netdevice.h>
#include <gpxe/if_ether.h>

extern struct ll_protocol ethernet_protocol;

extern const char * eth_ntoa ( const void *ll_addr );

/**
* Allocate Ethernet device
*
* @v priv_size Size of driver private data
* @ret netdev Network device, or NULL
*/
static inline struct net_device * alloc_etherdev ( size_t priv_size ) {
struct net_device *netdev;

netdev = alloc_netdev ( priv_size );
if ( netdev ) {
netdev->ll_protocol = &ethernet_protocol;
netdev->max_pkt_len = ETH_FRAME_LEN;
}
return netdev;
}
extern struct net_device * alloc_etherdev ( size_t priv_size );

#endif /* _GPXE_ETHERNET_H */
21 changes: 1 addition & 20 deletions src/include/gpxe/ipoib.h
Expand Up @@ -54,29 +54,10 @@ struct ipoib_hdr {
} __attribute__ (( packed )) u;
} __attribute__ (( packed ));

extern struct ll_protocol ipoib_protocol;

extern const char * ipoib_ntoa ( const void *ll_addr );

/**
* Allocate IPoIB device
*
* @v priv_size Size of driver private data
* @ret netdev Network device, or NULL
*/
static inline struct net_device * alloc_ipoibdev ( size_t priv_size ) {
struct net_device *netdev;

netdev = alloc_netdev ( priv_size );
if ( netdev ) {
netdev->ll_protocol = &ipoib_protocol;
netdev->max_pkt_len = IPOIB_PKT_LEN;
}
return netdev;
}

extern void ipoib_link_state_changed ( struct ib_device *ibdev );
extern int ipoib_probe ( struct ib_device *ibdev );
extern void ipoib_remove ( struct ib_device *ibdev );
extern struct net_device * alloc_ipoibdev ( size_t priv_size );

#endif /* _GPXE_IPOIB_H */
4 changes: 2 additions & 2 deletions src/include/gpxe/netdevice.h
Expand Up @@ -144,8 +144,6 @@ struct ll_protocol {
uint8_t ll_addr_len;
/** Link-layer header length */
uint8_t ll_header_len;
/** Link-layer broadcast address */
const uint8_t *ll_broadcast;
};

/** Network device operations */
Expand Down Expand Up @@ -261,6 +259,8 @@ struct net_device {
* For Ethernet, this is the MAC address.
*/
uint8_t ll_addr[MAX_LL_ADDR_LEN];
/** Link-layer broadcast address */
const uint8_t *ll_broadcast;

/** Current device state
*
Expand Down
3 changes: 1 addition & 2 deletions src/interface/efi/efi_snp.c
Expand Up @@ -129,8 +129,7 @@ static void efi_snp_set_mode ( struct efi_snp_device *snpdev ) {
EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST );
assert ( ll_addr_len <= sizeof ( mode->CurrentAddress ) );
memcpy ( &mode->CurrentAddress, netdev->ll_addr, ll_addr_len );
memcpy ( &mode->BroadcastAddress, netdev->ll_protocol->ll_broadcast,
ll_addr_len );
memcpy ( &mode->BroadcastAddress, netdev->ll_broadcast, ll_addr_len );
memcpy ( &mode->PermanentAddress, netdev->ll_addr, ll_addr_len );
mode->IfType = ntohs ( netdev->ll_protocol->ll_proto );
mode->MacAddressChangeable = TRUE;
Expand Down
3 changes: 1 addition & 2 deletions src/net/aoe.c
Expand Up @@ -440,8 +440,7 @@ int aoe_attach ( struct ata_device *ata, struct net_device *netdev,
return -ENOMEM;
aoe->refcnt.free = aoe_free;
aoe->netdev = netdev_get ( netdev );
memcpy ( aoe->target, ethernet_protocol.ll_broadcast,
sizeof ( aoe->target ) );
memcpy ( aoe->target, netdev->ll_broadcast, sizeof ( aoe->target ) );
aoe->tag = AOE_TAG_MAGIC;
aoe->timer.expired = aoe_timer_expired;

Expand Down
2 changes: 1 addition & 1 deletion src/net/arp.c
Expand Up @@ -156,7 +156,7 @@ int arp_resolve ( struct net_device *netdev, struct net_protocol *net_protocol,

/* Transmit ARP request */
if ( ( rc = net_tx ( iobuf, netdev, &arp_protocol,
ll_protocol->ll_broadcast ) ) != 0 )
netdev->ll_broadcast ) ) != 0 )
return rc;

return -ENOENT;
Expand Down
19 changes: 18 additions & 1 deletion src/net/ethernet.c
Expand Up @@ -145,9 +145,26 @@ struct ll_protocol ethernet_protocol __ll_protocol = {
.ll_proto = htons ( ARPHRD_ETHER ),
.ll_addr_len = ETH_ALEN,
.ll_header_len = ETH_HLEN,
.ll_broadcast = eth_broadcast,
.push = eth_push,
.pull = eth_pull,
.ntoa = eth_ntoa,
.mc_hash = eth_mc_hash,
};

/**
* Allocate Ethernet device
*
* @v priv_size Size of driver private data
* @ret netdev Network device, or NULL
*/
struct net_device * alloc_etherdev ( size_t priv_size ) {
struct net_device *netdev;

netdev = alloc_netdev ( priv_size );
if ( netdev ) {
netdev->ll_protocol = &ethernet_protocol;
netdev->ll_broadcast = eth_broadcast;
netdev->max_pkt_len = ETH_FRAME_LEN;
}
return netdev;
}
2 changes: 1 addition & 1 deletion src/net/ipv4.c
Expand Up @@ -271,7 +271,7 @@ static int ipv4_ll_addr ( struct in_addr dest, struct in_addr src,

if ( dest.s_addr == INADDR_BROADCAST ) {
/* Broadcast address */
memcpy ( ll_dest, ll_protocol->ll_broadcast,
memcpy ( ll_dest, netdev->ll_broadcast,
ll_protocol->ll_addr_len );
return 0;
} else if ( IN_MULTICAST ( ntohl ( dest.s_addr ) ) ) {
Expand Down

0 comments on commit d092901

Please sign in to comment.