Skip to content

Commit

Permalink
net: convert unicast addr list
Browse files Browse the repository at this point in the history
This patch converts unicast address list to standard list_head using
previously introduced struct netdev_hw_addr. It also relaxes the
locking. Original spinlock (still used for multicast addresses) is not
needed and is no longer used for a protection of this list. All
reading and writing takes place under rtnl (with no changes).

I also removed a possibility to specify the length of the address
while adding or deleting unicast address. It's always dev->addr_len.

The convertion touched especially e1000 and ixgbe codes when the
change is not so trivial.

Signed-off-by: Jiri Pirko <[email protected]>

 drivers/net/bnx2.c               |   13 +--
 drivers/net/e1000/e1000_main.c   |   24 +++--
 drivers/net/ixgbe/ixgbe_common.c |   14 ++--
 drivers/net/ixgbe/ixgbe_common.h |    4 +-
 drivers/net/ixgbe/ixgbe_main.c   |    6 +-
 drivers/net/ixgbe/ixgbe_type.h   |    4 +-
 drivers/net/macvlan.c            |   11 +-
 drivers/net/mv643xx_eth.c        |   11 +-
 drivers/net/niu.c                |    7 +-
 drivers/net/virtio_net.c         |    7 +-
 drivers/s390/net/qeth_l2_main.c  |    6 +-
 drivers/scsi/fcoe/fcoe.c         |   16 ++--
 include/linux/netdevice.h        |   18 ++--
 net/8021q/vlan.c                 |    4 +-
 net/8021q/vlan_dev.c             |   10 +-
 net/core/dev.c                   |  195 +++++++++++++++++++++++++++-----------
 net/dsa/slave.c                  |   10 +-
 net/packet/af_packet.c           |    4 +-
 18 files changed, 227 insertions(+), 137 deletions(-)
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Jiri Pirko authored and davem330 committed May 30, 2009
1 parent ae63e80 commit ccffad2
Show file tree
Hide file tree
Showing 18 changed files with 227 additions and 137 deletions.
13 changes: 6 additions & 7 deletions drivers/net/bnx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include <linux/cache.h>
#include <linux/firmware.h>
#include <linux/log2.h>
#include <linux/list.h>

#include "bnx2.h"
#include "bnx2_fw.h"
Expand Down Expand Up @@ -3310,7 +3311,7 @@ bnx2_set_rx_mode(struct net_device *dev)
{
struct bnx2 *bp = netdev_priv(dev);
u32 rx_mode, sort_mode;
struct dev_addr_list *uc_ptr;
struct netdev_hw_addr *ha;
int i;

if (!netif_running(dev))
Expand Down Expand Up @@ -3369,21 +3370,19 @@ bnx2_set_rx_mode(struct net_device *dev)
sort_mode |= BNX2_RPM_SORT_USER0_MC_HSH_EN;
}

uc_ptr = NULL;
if (dev->uc_count > BNX2_MAX_UNICAST_ADDRESSES) {
rx_mode |= BNX2_EMAC_RX_MODE_PROMISCUOUS;
sort_mode |= BNX2_RPM_SORT_USER0_PROM_EN |
BNX2_RPM_SORT_USER0_PROM_VLAN;
} else if (!(dev->flags & IFF_PROMISC)) {
uc_ptr = dev->uc_list;

/* Add all entries into to the match filter list */
for (i = 0; i < dev->uc_count; i++) {
bnx2_set_mac_addr(bp, uc_ptr->da_addr,
i = 0;
list_for_each_entry(ha, &dev->uc_list, list) {
bnx2_set_mac_addr(bp, ha->addr,
i + BNX2_START_UNICAST_ADDRESS_INDEX);
sort_mode |= (1 <<
(i + BNX2_START_UNICAST_ADDRESS_INDEX));
uc_ptr = uc_ptr->next;
i++;
}

}
Expand Down
24 changes: 15 additions & 9 deletions drivers/net/e1000/e1000_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2330,7 +2330,8 @@ static void e1000_set_rx_mode(struct net_device *netdev)
{
struct e1000_adapter *adapter = netdev_priv(netdev);
struct e1000_hw *hw = &adapter->hw;
struct dev_addr_list *uc_ptr;
struct netdev_hw_addr *ha;
bool use_uc = false;
struct dev_addr_list *mc_ptr;
u32 rctl;
u32 hash_value;
Expand Down Expand Up @@ -2369,12 +2370,11 @@ static void e1000_set_rx_mode(struct net_device *netdev)
rctl |= E1000_RCTL_VFE;
}

uc_ptr = NULL;
if (netdev->uc_count > rar_entries - 1) {
rctl |= E1000_RCTL_UPE;
} else if (!(netdev->flags & IFF_PROMISC)) {
rctl &= ~E1000_RCTL_UPE;
uc_ptr = netdev->uc_list;
use_uc = true;
}

ew32(RCTL, rctl);
Expand All @@ -2392,13 +2392,20 @@ static void e1000_set_rx_mode(struct net_device *netdev)
* if there are not 14 addresses, go ahead and clear the filters
* -- with 82571 controllers only 0-13 entries are filled here
*/
i = 1;
if (use_uc)
list_for_each_entry(ha, &netdev->uc_list, list) {
if (i == rar_entries)
break;
e1000_rar_set(hw, ha->addr, i++);
}

WARN_ON(i == rar_entries);

mc_ptr = netdev->mc_list;

for (i = 1; i < rar_entries; i++) {
if (uc_ptr) {
e1000_rar_set(hw, uc_ptr->da_addr, i);
uc_ptr = uc_ptr->next;
} else if (mc_ptr) {
for (; i < rar_entries; i++) {
if (mc_ptr) {
e1000_rar_set(hw, mc_ptr->da_addr, i);
mc_ptr = mc_ptr->next;
} else {
Expand All @@ -2408,7 +2415,6 @@ static void e1000_set_rx_mode(struct net_device *netdev)
E1000_WRITE_FLUSH();
}
}
WARN_ON(uc_ptr != NULL);

/* load any remaining addresses into the hash table */

Expand Down
14 changes: 7 additions & 7 deletions drivers/net/ixgbe/ixgbe_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <linux/pci.h>
#include <linux/delay.h>
#include <linux/sched.h>
#include <linux/list.h>
#include <linux/netdevice.h>

#include "ixgbe.h"
#include "ixgbe_common.h"
Expand Down Expand Up @@ -1356,15 +1358,14 @@ static void ixgbe_add_uc_addr(struct ixgbe_hw *hw, u8 *addr, u32 vmdq)
* Drivers using secondary unicast addresses must set user_set_promisc when
* manually putting the device into promiscuous mode.
**/
s32 ixgbe_update_uc_addr_list_generic(struct ixgbe_hw *hw, u8 *addr_list,
u32 addr_count, ixgbe_mc_addr_itr next)
s32 ixgbe_update_uc_addr_list_generic(struct ixgbe_hw *hw,
struct list_head *uc_list)
{
u8 *addr;
u32 i;
u32 old_promisc_setting = hw->addr_ctrl.overflow_promisc;
u32 uc_addr_in_use;
u32 fctrl;
u32 vmdq;
struct netdev_hw_addr *ha;

/*
* Clear accounting of old secondary address list,
Expand All @@ -1382,10 +1383,9 @@ s32 ixgbe_update_uc_addr_list_generic(struct ixgbe_hw *hw, u8 *addr_list,
}

/* Add the new addresses */
for (i = 0; i < addr_count; i++) {
list_for_each_entry(ha, uc_list, list) {
hw_dbg(hw, " Adding the secondary addresses:\n");
addr = next(hw, &addr_list, &vmdq);
ixgbe_add_uc_addr(hw, addr, vmdq);
ixgbe_add_uc_addr(hw, ha->addr, 0);
}

if (hw->addr_ctrl.overflow_promisc) {
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/ixgbe/ixgbe_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ s32 ixgbe_init_rx_addrs_generic(struct ixgbe_hw *hw);
s32 ixgbe_update_mc_addr_list_generic(struct ixgbe_hw *hw, u8 *mc_addr_list,
u32 mc_addr_count,
ixgbe_mc_addr_itr func);
s32 ixgbe_update_uc_addr_list_generic(struct ixgbe_hw *hw, u8 *addr_list,
u32 addr_count, ixgbe_mc_addr_itr func);
s32 ixgbe_update_uc_addr_list_generic(struct ixgbe_hw *hw,
struct list_head *uc_list);
s32 ixgbe_enable_mc_generic(struct ixgbe_hw *hw);
s32 ixgbe_disable_mc_generic(struct ixgbe_hw *hw);
s32 ixgbe_enable_rx_dma_generic(struct ixgbe_hw *hw, u32 regval);
Expand Down
6 changes: 1 addition & 5 deletions drivers/net/ixgbe/ixgbe_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2181,11 +2181,7 @@ static void ixgbe_set_rx_mode(struct net_device *netdev)
IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);

/* reprogram secondary unicast list */
addr_count = netdev->uc_count;
if (addr_count)
addr_list = netdev->uc_list->dmi_addr;
hw->mac.ops.update_uc_addr_list(hw, addr_list, addr_count,
ixgbe_addr_list_itr);
hw->mac.ops.update_uc_addr_list(hw, &netdev->uc_list);

/* reprogram multicast list */
addr_count = netdev->mc_count;
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/ixgbe/ixgbe_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include <linux/types.h>
#include <linux/mdio.h>
#include <linux/list.h>

/* Vendor ID */
#define IXGBE_INTEL_VENDOR_ID 0x8086
Expand Down Expand Up @@ -2223,8 +2224,7 @@ struct ixgbe_mac_operations {
s32 (*set_vmdq)(struct ixgbe_hw *, u32, u32);
s32 (*clear_vmdq)(struct ixgbe_hw *, u32, u32);
s32 (*init_rx_addrs)(struct ixgbe_hw *);
s32 (*update_uc_addr_list)(struct ixgbe_hw *, u8 *, u32,
ixgbe_mc_addr_itr);
s32 (*update_uc_addr_list)(struct ixgbe_hw *, struct list_head *);
s32 (*update_mc_addr_list)(struct ixgbe_hw *, u8 *, u32,
ixgbe_mc_addr_itr);
s32 (*enable_mc)(struct ixgbe_hw *);
Expand Down
11 changes: 6 additions & 5 deletions drivers/net/macvlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ static int macvlan_open(struct net_device *dev)
if (macvlan_addr_busy(vlan->port, dev->dev_addr))
goto out;

err = dev_unicast_add(lowerdev, dev->dev_addr, ETH_ALEN);
err = dev_unicast_add(lowerdev, dev->dev_addr);
if (err < 0)
goto out;
if (dev->flags & IFF_ALLMULTI) {
Expand All @@ -244,7 +244,7 @@ static int macvlan_open(struct net_device *dev)
return 0;

del_unicast:
dev_unicast_delete(lowerdev, dev->dev_addr, ETH_ALEN);
dev_unicast_delete(lowerdev, dev->dev_addr);
out:
return err;
}
Expand All @@ -258,7 +258,7 @@ static int macvlan_stop(struct net_device *dev)
if (dev->flags & IFF_ALLMULTI)
dev_set_allmulti(lowerdev, -1);

dev_unicast_delete(lowerdev, dev->dev_addr, ETH_ALEN);
dev_unicast_delete(lowerdev, dev->dev_addr);

macvlan_hash_del(vlan);
return 0;
Expand All @@ -282,10 +282,11 @@ static int macvlan_set_mac_address(struct net_device *dev, void *p)
if (macvlan_addr_busy(vlan->port, addr->sa_data))
return -EBUSY;

if ((err = dev_unicast_add(lowerdev, addr->sa_data, ETH_ALEN)))
err = dev_unicast_add(lowerdev, addr->sa_data);
if (err)
return err;

dev_unicast_delete(lowerdev, dev->dev_addr, ETH_ALEN);
dev_unicast_delete(lowerdev, dev->dev_addr);

macvlan_hash_change_addr(vlan, addr->sa_data);
}
Expand Down
11 changes: 6 additions & 5 deletions drivers/net/mv643xx_eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include <linux/types.h>
#include <linux/inet_lro.h>
#include <asm/system.h>
#include <linux/list.h>

static char mv643xx_eth_driver_name[] = "mv643xx_eth";
static char mv643xx_eth_driver_version[] = "1.4";
Expand Down Expand Up @@ -1721,20 +1722,20 @@ static void uc_addr_set(struct mv643xx_eth_private *mp, unsigned char *addr)

static u32 uc_addr_filter_mask(struct net_device *dev)
{
struct dev_addr_list *uc_ptr;
struct netdev_hw_addr *ha;
u32 nibbles;

if (dev->flags & IFF_PROMISC)
return 0;

nibbles = 1 << (dev->dev_addr[5] & 0x0f);
for (uc_ptr = dev->uc_list; uc_ptr != NULL; uc_ptr = uc_ptr->next) {
if (memcmp(dev->dev_addr, uc_ptr->da_addr, 5))
list_for_each_entry(ha, &dev->uc_list, list) {
if (memcmp(dev->dev_addr, ha->addr, 5))
return 0;
if ((dev->dev_addr[5] ^ uc_ptr->da_addr[5]) & 0xf0)
if ((dev->dev_addr[5] ^ ha->addr[5]) & 0xf0)
return 0;

nibbles |= 1 << (uc_ptr->da_addr[5] & 0x0f);
nibbles |= 1 << (ha->addr[5] & 0x0f);
}

return nibbles;
Expand Down
7 changes: 4 additions & 3 deletions drivers/net/niu.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <linux/log2.h>
#include <linux/jiffies.h>
#include <linux/crc32.h>
#include <linux/list.h>

#include <linux/io.h>

Expand Down Expand Up @@ -6362,6 +6363,7 @@ static void niu_set_rx_mode(struct net_device *dev)
struct niu *np = netdev_priv(dev);
int i, alt_cnt, err;
struct dev_addr_list *addr;
struct netdev_hw_addr *ha;
unsigned long flags;
u16 hash[16] = { 0, };

Expand All @@ -6383,9 +6385,8 @@ static void niu_set_rx_mode(struct net_device *dev)
if (alt_cnt) {
int index = 0;

for (addr = dev->uc_list; addr; addr = addr->next) {
err = niu_set_alt_mac(np, index,
addr->da_addr);
list_for_each_entry(ha, &dev->uc_list, list) {
err = niu_set_alt_mac(np, index, ha->addr);
if (err)
printk(KERN_WARNING PFX "%s: Error %d "
"adding alt mac %d\n",
Expand Down
7 changes: 4 additions & 3 deletions drivers/net/virtio_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ static void virtnet_set_rx_mode(struct net_device *dev)
u8 promisc, allmulti;
struct virtio_net_ctrl_mac *mac_data;
struct dev_addr_list *addr;
struct netdev_hw_addr *ha;
void *buf;
int i;

Expand Down Expand Up @@ -718,9 +719,9 @@ static void virtnet_set_rx_mode(struct net_device *dev)

/* Store the unicast list and count in the front of the buffer */
mac_data->entries = dev->uc_count;
addr = dev->uc_list;
for (i = 0; i < dev->uc_count; i++, addr = addr->next)
memcpy(&mac_data->macs[i][0], addr->da_addr, ETH_ALEN);
i = 0;
list_for_each_entry(ha, &dev->uc_list, list)
memcpy(&mac_data->macs[i++][0], ha->addr, ETH_ALEN);

sg_set_buf(&sg[0], mac_data,
sizeof(mac_data->entries) + (dev->uc_count * ETH_ALEN));
Expand Down
6 changes: 4 additions & 2 deletions drivers/s390/net/qeth_l2_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <linux/etherdevice.h>
#include <linux/mii.h>
#include <linux/ip.h>
#include <linux/list.h>

#include "qeth_core.h"

Expand Down Expand Up @@ -640,6 +641,7 @@ static void qeth_l2_set_multicast_list(struct net_device *dev)
{
struct qeth_card *card = dev->ml_priv;
struct dev_addr_list *dm;
struct netdev_hw_addr *ha;

if (card->info.type == QETH_CARD_TYPE_OSN)
return ;
Expand All @@ -653,8 +655,8 @@ static void qeth_l2_set_multicast_list(struct net_device *dev)
for (dm = dev->mc_list; dm; dm = dm->next)
qeth_l2_add_mc(card, dm->da_addr, 0);

for (dm = dev->uc_list; dm; dm = dm->next)
qeth_l2_add_mc(card, dm->da_addr, 1);
list_for_each_entry(ha, &dev->uc_list, list)
qeth_l2_add_mc(card, ha->addr, 1);

spin_unlock_bh(&card->mclock);
if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
Expand Down
16 changes: 7 additions & 9 deletions drivers/scsi/fcoe/fcoe.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ static void fcoe_update_src_mac(struct fcoe_ctlr *fip, u8 *old, u8 *new)
fc = fcoe_from_ctlr(fip);
rtnl_lock();
if (!is_zero_ether_addr(old))
dev_unicast_delete(fc->real_dev, old, ETH_ALEN);
dev_unicast_add(fc->real_dev, new, ETH_ALEN);
dev_unicast_delete(fc->real_dev, old);
dev_unicast_add(fc->real_dev, new);
rtnl_unlock();
}

Expand Down Expand Up @@ -233,13 +233,11 @@ void fcoe_netdev_cleanup(struct fcoe_softc *fc)
/* Delete secondary MAC addresses */
rtnl_lock();
memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN);
dev_unicast_delete(fc->real_dev, flogi_maddr, ETH_ALEN);
dev_unicast_delete(fc->real_dev, flogi_maddr);
if (!is_zero_ether_addr(fc->ctlr.data_src_addr))
dev_unicast_delete(fc->real_dev,
fc->ctlr.data_src_addr, ETH_ALEN);
dev_unicast_delete(fc->real_dev, fc->ctlr.data_src_addr);
if (fc->ctlr.spma)
dev_unicast_delete(fc->real_dev,
fc->ctlr.ctl_src_addr, ETH_ALEN);
dev_unicast_delete(fc->real_dev, fc->ctlr.ctl_src_addr);
dev_mc_delete(fc->real_dev, FIP_ALL_ENODE_MACS, ETH_ALEN, 0);
rtnl_unlock();
}
Expand Down Expand Up @@ -347,9 +345,9 @@ static int fcoe_netdev_config(struct fc_lport *lp, struct net_device *netdev)
*/
rtnl_lock();
memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN);
dev_unicast_add(fc->real_dev, flogi_maddr, ETH_ALEN);
dev_unicast_add(fc->real_dev, flogi_maddr);
if (fc->ctlr.spma)
dev_unicast_add(fc->real_dev, fc->ctlr.ctl_src_addr, ETH_ALEN);
dev_unicast_add(fc->real_dev, fc->ctlr.ctl_src_addr);
dev_mc_add(fc->real_dev, FIP_ALL_ENODE_MACS, ETH_ALEN, 0);
rtnl_unlock();

Expand Down
Loading

0 comments on commit ccffad2

Please sign in to comment.