Commit d746ca95 authored by Anton Blanchard's avatar Anton Blanchard Committed by David S. Miller

ibmveth: Fix endian issues with MAC addresses

The code to load a MAC address into a u64 for passing to the
hypervisor via a register is broken on little endian.

Create a helper function called ibmveth_encode_mac_addr
which does the right thing in both big and little endian.

We were storing the MAC address in a long in struct ibmveth_adapter.
It's never used so remove it - we don't need another place in the
driver where we create endian issues with MAC addresses.
Signed-off-by: default avatarAnton Blanchard <anton@samba.org>
Cc: stable@vger.kernel.org
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 0a13404d
...@@ -522,10 +522,21 @@ static int ibmveth_register_logical_lan(struct ibmveth_adapter *adapter, ...@@ -522,10 +522,21 @@ static int ibmveth_register_logical_lan(struct ibmveth_adapter *adapter,
return rc; return rc;
} }
static u64 ibmveth_encode_mac_addr(u8 *mac)
{
int i;
u64 encoded = 0;
for (i = 0; i < ETH_ALEN; i++)
encoded = (encoded << 8) | mac[i];
return encoded;
}
static int ibmveth_open(struct net_device *netdev) static int ibmveth_open(struct net_device *netdev)
{ {
struct ibmveth_adapter *adapter = netdev_priv(netdev); struct ibmveth_adapter *adapter = netdev_priv(netdev);
u64 mac_address = 0; u64 mac_address;
int rxq_entries = 1; int rxq_entries = 1;
unsigned long lpar_rc; unsigned long lpar_rc;
int rc; int rc;
...@@ -579,8 +590,7 @@ static int ibmveth_open(struct net_device *netdev) ...@@ -579,8 +590,7 @@ static int ibmveth_open(struct net_device *netdev)
adapter->rx_queue.num_slots = rxq_entries; adapter->rx_queue.num_slots = rxq_entries;
adapter->rx_queue.toggle = 1; adapter->rx_queue.toggle = 1;
memcpy(&mac_address, netdev->dev_addr, netdev->addr_len); mac_address = ibmveth_encode_mac_addr(netdev->dev_addr);
mac_address = mac_address >> 16;
rxq_desc.fields.flags_len = IBMVETH_BUF_VALID | rxq_desc.fields.flags_len = IBMVETH_BUF_VALID |
adapter->rx_queue.queue_len; adapter->rx_queue.queue_len;
...@@ -1183,8 +1193,8 @@ static void ibmveth_set_multicast_list(struct net_device *netdev) ...@@ -1183,8 +1193,8 @@ static void ibmveth_set_multicast_list(struct net_device *netdev)
/* add the addresses to the filter table */ /* add the addresses to the filter table */
netdev_for_each_mc_addr(ha, netdev) { netdev_for_each_mc_addr(ha, netdev) {
/* add the multicast address to the filter table */ /* add the multicast address to the filter table */
unsigned long mcast_addr = 0; u64 mcast_addr;
memcpy(((char *)&mcast_addr)+2, ha->addr, ETH_ALEN); mcast_addr = ibmveth_encode_mac_addr(ha->addr);
lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address, lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address,
IbmVethMcastAddFilter, IbmVethMcastAddFilter,
mcast_addr); mcast_addr);
...@@ -1372,9 +1382,6 @@ static int ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id) ...@@ -1372,9 +1382,6 @@ static int ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id)
netif_napi_add(netdev, &adapter->napi, ibmveth_poll, 16); netif_napi_add(netdev, &adapter->napi, ibmveth_poll, 16);
adapter->mac_addr = 0;
memcpy(&adapter->mac_addr, mac_addr_p, ETH_ALEN);
netdev->irq = dev->irq; netdev->irq = dev->irq;
netdev->netdev_ops = &ibmveth_netdev_ops; netdev->netdev_ops = &ibmveth_netdev_ops;
netdev->ethtool_ops = &netdev_ethtool_ops; netdev->ethtool_ops = &netdev_ethtool_ops;
...@@ -1383,7 +1390,7 @@ static int ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id) ...@@ -1383,7 +1390,7 @@ static int ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id)
NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM; NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
netdev->features |= netdev->hw_features; netdev->features |= netdev->hw_features;
memcpy(netdev->dev_addr, &adapter->mac_addr, netdev->addr_len); memcpy(netdev->dev_addr, mac_addr_p, ETH_ALEN);
for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) { for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) {
struct kobject *kobj = &adapter->rx_buff_pool[i].kobj; struct kobject *kobj = &adapter->rx_buff_pool[i].kobj;
......
...@@ -138,7 +138,6 @@ struct ibmveth_adapter { ...@@ -138,7 +138,6 @@ struct ibmveth_adapter {
struct napi_struct napi; struct napi_struct napi;
struct net_device_stats stats; struct net_device_stats stats;
unsigned int mcastFilterSize; unsigned int mcastFilterSize;
unsigned long mac_addr;
void * buffer_list_addr; void * buffer_list_addr;
void * filter_list_addr; void * filter_list_addr;
dma_addr_t buffer_list_dma; dma_addr_t buffer_list_dma;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment