Skip to content

Commit

Permalink
cxgb4/cxgb4vf: Program hash region for {t4/t4vf}_change_mac()
Browse files Browse the repository at this point in the history
{t4/t4_vf}_change_mac() API's were only doing additions to MPS_TCAM.
This will fail, when the number of tcam entries is limited particularly
in vf's.
This fix programs hash region with the mac address, when TCAM
addtion fails for {t4/t4vf}_change_mac(). Since the locally maintained
driver list for hash entries is shared across mac_{sync/unsync}(),
added an extra parameter if_mac to track the address added thorugh
{t4/t4vf}_change_mac()

Signed-off-by: Arjun Vynipadath <arjun@chelsio.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Arjun Vynipadath authored and David S. Miller committed Feb 3, 2019
1 parent 1d2f4eb commit 3f8cfd0
Showing 4 changed files with 136 additions and 40 deletions.
3 changes: 2 additions & 1 deletion drivers/net/ethernet/chelsio/cxgb4/cxgb4.h
Original file line number Diff line number Diff line change
@@ -568,7 +568,7 @@ struct sge_rspq;
struct port_info {
struct adapter *adapter;
u16 viid;
s16 xact_addr_filt; /* index of exact MAC address filter */
int xact_addr_filt; /* index of exact MAC address filter */
u16 rss_size; /* size of VI's RSS table slice */
s8 mdio_addr;
enum fw_port_type port_type;
@@ -860,6 +860,7 @@ struct doorbell_stats {
struct hash_mac_addr {
struct list_head list;
u8 addr[ETH_ALEN];
unsigned int iface_mac;
};

struct uld_msix_bmap {
71 changes: 59 additions & 12 deletions drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
Original file line number Diff line number Diff line change
@@ -433,6 +433,60 @@ static int set_rxmode(struct net_device *dev, int mtu, bool sleep_ok)
}

/**
* cxgb4_change_mac - Update match filter for a MAC address.
* @pi: the port_info
* @viid: the VI id
* @tcam_idx: TCAM index of existing filter for old value of MAC address,
* or -1
* @addr: the new MAC address value
* @persist: whether a new MAC allocation should be persistent
* @add_smt: if true also add the address to the HW SMT
*
* Modifies an MPS filter and sets it to the new MAC address if
* @tcam_idx >= 0, or adds the MAC address to a new filter if
* @tcam_idx < 0. In the latter case the address is added persistently
* if @persist is %true.
* Addresses are programmed to hash region, if tcam runs out of entries.
*
*/
static int cxgb4_change_mac(struct port_info *pi, unsigned int viid,
int *tcam_idx, const u8 *addr, bool persist,
u8 *smt_idx)
{
struct adapter *adapter = pi->adapter;
struct hash_mac_addr *entry, *new_entry;
int ret;

ret = t4_change_mac(adapter, adapter->mbox, viid,
*tcam_idx, addr, persist, smt_idx);
/* We ran out of TCAM entries. try programming hash region. */
if (ret == -ENOMEM) {
/* If the MAC address to be updated is in the hash addr
* list, update it from the list
*/
list_for_each_entry(entry, &adapter->mac_hlist, list) {
if (entry->iface_mac) {
ether_addr_copy(entry->addr, addr);
goto set_hash;
}
}
new_entry = kzalloc(sizeof(*new_entry), GFP_KERNEL);
if (!new_entry)
return -ENOMEM;
ether_addr_copy(new_entry->addr, addr);
new_entry->iface_mac = true;
list_add_tail(&new_entry->list, &adapter->mac_hlist);
set_hash:
ret = cxgb4_set_addr_hash(pi);
} else if (ret >= 0) {
*tcam_idx = ret;
ret = 0;
}

return ret;
}

/*
* link_start - enable a port
* @dev: the port to enable
*
@@ -450,15 +504,9 @@ static int link_start(struct net_device *dev)
*/
ret = t4_set_rxmode(pi->adapter, mb, pi->viid, dev->mtu, -1, -1, -1,
!!(dev->features & NETIF_F_HW_VLAN_CTAG_RX), true);
if (ret == 0) {
ret = t4_change_mac(pi->adapter, mb, pi->viid,
pi->xact_addr_filt, dev->dev_addr, true,
&pi->smt_idx);
if (ret >= 0) {
pi->xact_addr_filt = ret;
ret = 0;
}
}
if (ret == 0)
ret = cxgb4_change_mac(pi, pi->viid, &pi->xact_addr_filt,
dev->dev_addr, true, &pi->smt_idx);
if (ret == 0)
ret = t4_link_l1cfg(pi->adapter, mb, pi->tx_chan,
&pi->link_cfg);
@@ -2839,9 +2887,8 @@ static int cxgb_set_mac_addr(struct net_device *dev, void *p)
if (!is_valid_ether_addr(addr->sa_data))
return -EADDRNOTAVAIL;

ret = t4_change_mac(pi->adapter, pi->adapter->pf, pi->viid,
pi->xact_addr_filt, addr->sa_data, true,
&pi->smt_idx);
ret = cxgb4_change_mac(pi, pi->viid, &pi->xact_addr_filt,
addr->sa_data, true, &pi->smt_idx);
if (ret < 0)
return ret;

3 changes: 2 additions & 1 deletion drivers/net/ethernet/chelsio/cxgb4vf/adapter.h
Original file line number Diff line number Diff line change
@@ -94,7 +94,7 @@ struct port_info {
struct adapter *adapter; /* our adapter */
u32 vlan_id; /* vlan id for VST */
u16 viid; /* virtual interface ID */
s16 xact_addr_filt; /* index of our MAC address filter */
int xact_addr_filt; /* index of our MAC address filter */
u16 rss_size; /* size of VI's RSS table slice */
u8 pidx; /* index into adapter port[] */
s8 mdio_addr;
@@ -352,6 +352,7 @@ struct sge {
struct hash_mac_addr {
struct list_head list;
u8 addr[ETH_ALEN];
unsigned int iface_mac;
};

struct mbox_list {
99 changes: 73 additions & 26 deletions drivers/net/ethernet/chelsio/cxgb4vf/cxgb4vf_main.c
Original file line number Diff line number Diff line change
@@ -236,6 +236,73 @@ void t4vf_os_portmod_changed(struct adapter *adapter, int pidx)
"inserted\n", dev->name, pi->mod_type);
}

static int cxgb4vf_set_addr_hash(struct port_info *pi)
{
struct adapter *adapter = pi->adapter;
u64 vec = 0;
bool ucast = false;
struct hash_mac_addr *entry;

/* Calculate the hash vector for the updated list and program it */
list_for_each_entry(entry, &adapter->mac_hlist, list) {
ucast |= is_unicast_ether_addr(entry->addr);
vec |= (1ULL << hash_mac_addr(entry->addr));
}
return t4vf_set_addr_hash(adapter, pi->viid, ucast, vec, false);
}

/**
* cxgb4vf_change_mac - Update match filter for a MAC address.
* @pi: the port_info
* @viid: the VI id
* @tcam_idx: TCAM index of existing filter for old value of MAC address,
* or -1
* @addr: the new MAC address value
* @persist: whether a new MAC allocation should be persistent
* @add_smt: if true also add the address to the HW SMT
*
* Modifies an MPS filter and sets it to the new MAC address if
* @tcam_idx >= 0, or adds the MAC address to a new filter if
* @tcam_idx < 0. In the latter case the address is added persistently
* if @persist is %true.
* Addresses are programmed to hash region, if tcam runs out of entries.
*
*/
static int cxgb4vf_change_mac(struct port_info *pi, unsigned int viid,
int *tcam_idx, const u8 *addr, bool persistent)
{
struct hash_mac_addr *new_entry, *entry;
struct adapter *adapter = pi->adapter;
int ret;

ret = t4vf_change_mac(adapter, viid, *tcam_idx, addr, persistent);
/* We ran out of TCAM entries. try programming hash region. */
if (ret == -ENOMEM) {
/* If the MAC address to be updated is in the hash addr
* list, update it from the list
*/
list_for_each_entry(entry, &adapter->mac_hlist, list) {
if (entry->iface_mac) {
ether_addr_copy(entry->addr, addr);
goto set_hash;
}
}
new_entry = kzalloc(sizeof(*new_entry), GFP_KERNEL);
if (!new_entry)
return -ENOMEM;
ether_addr_copy(new_entry->addr, addr);
new_entry->iface_mac = true;
list_add_tail(&new_entry->list, &adapter->mac_hlist);
set_hash:
ret = cxgb4vf_set_addr_hash(pi);
} else if (ret >= 0) {
*tcam_idx = ret;
ret = 0;
}

return ret;
}

/*
* Net device operations.
* ======================
@@ -259,14 +326,10 @@ static int link_start(struct net_device *dev)
*/
ret = t4vf_set_rxmode(pi->adapter, pi->viid, dev->mtu, -1, -1, -1, 1,
true);
if (ret == 0) {
ret = t4vf_change_mac(pi->adapter, pi->viid,
pi->xact_addr_filt, dev->dev_addr, true);
if (ret >= 0) {
pi->xact_addr_filt = ret;
ret = 0;
}
}
if (ret == 0)
ret = cxgb4vf_change_mac(pi, pi->viid,
&pi->xact_addr_filt,
dev->dev_addr, true);

/*
* We don't need to actually "start the link" itself since the
@@ -870,21 +933,6 @@ static struct net_device_stats *cxgb4vf_get_stats(struct net_device *dev)
return ns;
}

static inline int cxgb4vf_set_addr_hash(struct port_info *pi)
{
struct adapter *adapter = pi->adapter;
u64 vec = 0;
bool ucast = false;
struct hash_mac_addr *entry;

/* Calculate the hash vector for the updated list and program it */
list_for_each_entry(entry, &adapter->mac_hlist, list) {
ucast |= is_unicast_ether_addr(entry->addr);
vec |= (1ULL << hash_mac_addr(entry->addr));
}
return t4vf_set_addr_hash(adapter, pi->viid, ucast, vec, false);
}

static int cxgb4vf_mac_sync(struct net_device *netdev, const u8 *mac_addr)
{
struct port_info *pi = netdev_priv(netdev);
@@ -1166,13 +1214,12 @@ static int cxgb4vf_set_mac_addr(struct net_device *dev, void *_addr)
if (!is_valid_ether_addr(addr->sa_data))
return -EADDRNOTAVAIL;

ret = t4vf_change_mac(pi->adapter, pi->viid, pi->xact_addr_filt,
addr->sa_data, true);
ret = cxgb4vf_change_mac(pi, pi->viid, &pi->xact_addr_filt,
addr->sa_data, true);
if (ret < 0)
return ret;

memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
pi->xact_addr_filt = ret;
return 0;
}

0 comments on commit 3f8cfd0

Please sign in to comment.