Skip to content

Commit

Permalink
net: use helpers to access uc list V2
Browse files Browse the repository at this point in the history
This patch introduces three macros to work with uc list from net drivers.

Signed-off-by: Jiri Pirko <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Jiri Pirko authored and davem330 committed Jan 25, 2010
1 parent 9010bc3 commit 32e7bfc
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 33 deletions.
5 changes: 2 additions & 3 deletions drivers/net/bnx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
#include <linux/cache.h>
#include <linux/firmware.h>
#include <linux/log2.h>
#include <linux/list.h>

#if defined(CONFIG_CNIC) || defined(CONFIG_CNIC_MODULE)
#define BCM_CNIC 1
Expand Down Expand Up @@ -3579,14 +3578,14 @@ bnx2_set_rx_mode(struct net_device *dev)
sort_mode |= BNX2_RPM_SORT_USER0_MC_HSH_EN;
}

if (dev->uc.count > BNX2_MAX_UNICAST_ADDRESSES) {
if (netdev_uc_count(dev) > 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)) {
/* Add all entries into to the match filter list */
i = 0;
list_for_each_entry(ha, &dev->uc.list, list) {
netdev_for_each_uc_addr(ha, dev) {
bnx2_set_mac_addr(bp, ha->addr,
i + BNX2_START_UNICAST_ADDRESS_INDEX);
sort_mode |= (1 <<
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/e1000/e1000_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2139,7 +2139,7 @@ static void e1000_set_rx_mode(struct net_device *netdev)
rctl |= E1000_RCTL_VFE;
}

if (netdev->uc.count > rar_entries - 1) {
if (netdev_uc_count(netdev) > rar_entries - 1) {
rctl |= E1000_RCTL_UPE;
} else if (!(netdev->flags & IFF_PROMISC)) {
rctl &= ~E1000_RCTL_UPE;
Expand All @@ -2162,7 +2162,7 @@ static void e1000_set_rx_mode(struct net_device *netdev)
*/
i = 1;
if (use_uc)
list_for_each_entry(ha, &netdev->uc.list, list) {
netdev_for_each_uc_addr(ha, netdev) {
if (i == rar_entries)
break;
e1000_rar_set(hw, ha->addr, i++);
Expand Down
7 changes: 4 additions & 3 deletions drivers/net/igb/igb_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2905,12 +2905,13 @@ static int igb_write_uc_addr_list(struct net_device *netdev)
int count = 0;

/* return ENOMEM indicating insufficient memory for addresses */
if (netdev->uc.count > rar_entries)
if (netdev_uc_count(netdev) > rar_entries)
return -ENOMEM;

if (netdev->uc.count && rar_entries) {
if (!netdev_uc_empty(netdev) && rar_entries) {
struct netdev_hw_addr *ha;
list_for_each_entry(ha, &netdev->uc.list, list) {

netdev_for_each_uc_addr(ha, netdev) {
if (!rar_entries)
break;
igb_rar_set_qsel(adapter, ha->addr,
Expand Down
7 changes: 3 additions & 4 deletions drivers/net/ixgbe/ixgbe_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <linux/pci.h>
#include <linux/delay.h>
#include <linux/sched.h>
#include <linux/list.h>
#include <linux/netdevice.h>

#include "ixgbe.h"
Expand Down Expand Up @@ -1347,7 +1346,7 @@ static void ixgbe_add_uc_addr(struct ixgbe_hw *hw, u8 *addr, u32 vmdq)
/**
* ixgbe_update_uc_addr_list_generic - Updates MAC list of secondary addresses
* @hw: pointer to hardware structure
* @uc_list: the list of new addresses
* @netdev: pointer to net device structure
*
* The given list replaces any existing list. Clears the secondary addrs from
* receive address registers. Uses unused receive address registers for the
Expand All @@ -1357,7 +1356,7 @@ static void ixgbe_add_uc_addr(struct ixgbe_hw *hw, u8 *addr, u32 vmdq)
* manually putting the device into promiscuous mode.
**/
s32 ixgbe_update_uc_addr_list_generic(struct ixgbe_hw *hw,
struct list_head *uc_list)
struct net_device *netdev)
{
u32 i;
u32 old_promisc_setting = hw->addr_ctrl.overflow_promisc;
Expand All @@ -1381,7 +1380,7 @@ s32 ixgbe_update_uc_addr_list_generic(struct ixgbe_hw *hw,
}

/* Add the new addresses */
list_for_each_entry(ha, uc_list, list) {
netdev_for_each_uc_addr(ha, netdev) {
hw_dbg(hw, " Adding the secondary addresses:\n");
ixgbe_add_uc_addr(hw, ha->addr, 0);
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ixgbe/ixgbe_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ 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,
struct list_head *uc_list);
struct net_device *netdev);
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
2 changes: 1 addition & 1 deletion drivers/net/ixgbe/ixgbe_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2568,7 +2568,7 @@ void ixgbe_set_rx_mode(struct net_device *netdev)
IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);

/* reprogram secondary unicast list */
hw->mac.ops.update_uc_addr_list(hw, &netdev->uc.list);
hw->mac.ops.update_uc_addr_list(hw, netdev);

/* 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,7 +30,7 @@

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

/* Vendor ID */
#define IXGBE_INTEL_VENDOR_ID 0x8086
Expand Down Expand Up @@ -2405,7 +2405,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 *, struct list_head *);
s32 (*update_uc_addr_list)(struct ixgbe_hw *, struct net_device *);
s32 (*update_mc_addr_list)(struct ixgbe_hw *, u8 *, u32,
ixgbe_mc_addr_itr);
s32 (*enable_mc)(struct ixgbe_hw *);
Expand Down
3 changes: 1 addition & 2 deletions drivers/net/mv643xx_eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
#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 @@ -1697,7 +1696,7 @@ static u32 uc_addr_filter_mask(struct net_device *dev)
return 0;

nibbles = 1 << (dev->dev_addr[5] & 0x0f);
list_for_each_entry(ha, &dev->uc.list, list) {
netdev_for_each_uc_addr(ha, dev) {
if (memcmp(dev->dev_addr, ha->addr, 5))
return 0;
if ((dev->dev_addr[5] ^ ha->addr[5]) & 0xf0)
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/niu.c
Original file line number Diff line number Diff line change
Expand Up @@ -6372,7 +6372,7 @@ static void niu_set_rx_mode(struct net_device *dev)
if ((dev->flags & IFF_ALLMULTI) || (dev->mc_count > 0))
np->flags |= NIU_FLAGS_MCAST;

alt_cnt = dev->uc.count;
alt_cnt = netdev_uc_count(dev);
if (alt_cnt > niu_num_alt_addr(np)) {
alt_cnt = 0;
np->flags |= NIU_FLAGS_PROMISC;
Expand All @@ -6381,7 +6381,7 @@ static void niu_set_rx_mode(struct net_device *dev)
if (alt_cnt) {
int index = 0;

list_for_each_entry(ha, &dev->uc.list, list) {
netdev_for_each_uc_addr(ha, dev) {
err = niu_set_alt_mac(np, index, ha->addr);
if (err)
printk(KERN_WARNING PFX "%s: Error %d "
Expand Down
10 changes: 5 additions & 5 deletions drivers/net/stmmac/dwmac1000_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ static void dwmac1000_set_filter(struct net_device *dev)
unsigned int value = 0;

DBG(KERN_INFO "%s: # mcasts %d, # unicast %d\n",
__func__, dev->mc_count, dev->uc.count);
__func__, dev->mc_count, netdev_uc_count(dev));

if (dev->flags & IFF_PROMISC)
value = GMAC_FRAME_FILTER_PR;
Expand Down Expand Up @@ -117,17 +117,17 @@ static void dwmac1000_set_filter(struct net_device *dev)
}

/* Handle multiple unicast addresses (perfect filtering)*/
if (dev->uc.count > GMAC_MAX_UNICAST_ADDRESSES)
if (netdev_uc_count(dev) > GMAC_MAX_UNICAST_ADDRESSES)
/* Switch to promiscuous mode is more than 16 addrs
are required */
value |= GMAC_FRAME_FILTER_PR;
else {
int reg = 1;
struct netdev_hw_addr *ha;

list_for_each_entry(ha, &dev->uc.list, list) {
dwmac1000_set_umac_addr(ioaddr, ha->addr, reg);
reg++;
netdev_for_each_uc_addr(ha, dev) {
dwmac1000_set_umac_addr(ioaddr, ha->addr, reg);
reg++;
}
}

Expand Down
12 changes: 7 additions & 5 deletions drivers/net/virtio_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ static void virtnet_set_rx_mode(struct net_device *dev)
struct virtio_net_ctrl_mac *mac_data;
struct dev_addr_list *addr;
struct netdev_hw_addr *ha;
int uc_count;
void *buf;
int i;

Expand All @@ -701,8 +702,9 @@ static void virtnet_set_rx_mode(struct net_device *dev)
dev_warn(&dev->dev, "Failed to %sable allmulti mode.\n",
allmulti ? "en" : "dis");

uc_count = netdev_uc_count(dev);
/* MAC filter - use one buffer for both lists */
mac_data = buf = kzalloc(((dev->uc.count + dev->mc_count) * ETH_ALEN) +
mac_data = buf = kzalloc(((uc_count + dev->mc_count) * ETH_ALEN) +
(2 * sizeof(mac_data->entries)), GFP_ATOMIC);
if (!buf) {
dev_warn(&dev->dev, "No memory for MAC address buffer\n");
Expand All @@ -712,16 +714,16 @@ static void virtnet_set_rx_mode(struct net_device *dev)
sg_init_table(sg, 2);

/* Store the unicast list and count in the front of the buffer */
mac_data->entries = dev->uc.count;
mac_data->entries = uc_count;
i = 0;
list_for_each_entry(ha, &dev->uc.list, list)
netdev_for_each_uc_addr(ha, dev)
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));
sizeof(mac_data->entries) + (uc_count * ETH_ALEN));

/* multicast list and count fill the end */
mac_data = (void *)&mac_data->macs[dev->uc.count][0];
mac_data = (void *)&mac_data->macs[uc_count][0];

mac_data->entries = dev->mc_count;
addr = dev->mc_list;
Expand Down
2 changes: 1 addition & 1 deletion drivers/s390/net/qeth_l2_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ 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);

list_for_each_entry(ha, &dev->uc.list, list)
netdev_for_each_uc_addr(ha, dev)
qeth_l2_add_mc(card, ha->addr, 1);

spin_unlock_bh(&card->mclock);
Expand Down
5 changes: 5 additions & 0 deletions include/linux/netdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ struct netdev_hw_addr_list {
int count;
};

#define netdev_uc_count(dev) ((dev)->uc.count)
#define netdev_uc_empty(dev) ((dev)->uc.count == 0)
#define netdev_for_each_uc_addr(ha, dev) \
list_for_each_entry(ha, &dev->uc.list, list)

struct hh_cache {
struct hh_cache *hh_next; /* Next entry */
atomic_t hh_refcnt; /* number of users */
Expand Down
4 changes: 2 additions & 2 deletions net/core/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -3665,10 +3665,10 @@ void __dev_set_rx_mode(struct net_device *dev)
/* Unicast addresses changes may only happen under the rtnl,
* therefore calling __dev_set_promiscuity here is safe.
*/
if (dev->uc.count > 0 && !dev->uc_promisc) {
if (!netdev_uc_empty(dev) && !dev->uc_promisc) {
__dev_set_promiscuity(dev, 1);
dev->uc_promisc = 1;
} else if (dev->uc.count == 0 && dev->uc_promisc) {
} else if (netdev_uc_empty(dev) && dev->uc_promisc) {
__dev_set_promiscuity(dev, -1);
dev->uc_promisc = 0;
}
Expand Down

0 comments on commit 32e7bfc

Please sign in to comment.