From: chandu@amd.com
To: dev@dpdk.org
Cc: Ravi1.Kumar@amd.com, Amaranath.Somalapuram@amd.com
Subject: [dpdk-dev] [PATCH v1 1/2] net/axgbe: add additional MAC address support
Date: Fri, 28 Feb 2020 19:36:07 +0530 [thread overview]
Message-ID: <20200228140608.668-1-chandu@amd.com> (raw)
From: Chandu Babu N <chandu@amd.com>
Supports adding MAC addresses to enable whitelist filtering to
accept packets
implement eth_dev_ops mac_addr_set, mac_addr_add, mac_addr_remove and
set_mc_addr_list
Signed-off-by: Chandu Babu N <chandu@amd.com>
---
drivers/net/axgbe/axgbe_dev.c | 29 ++++++++++
drivers/net/axgbe/axgbe_ethdev.c | 94 ++++++++++++++++++++++++++++++--
drivers/net/axgbe/axgbe_ethdev.h | 4 +-
3 files changed, 121 insertions(+), 6 deletions(-)
diff --git a/drivers/net/axgbe/axgbe_dev.c b/drivers/net/axgbe/axgbe_dev.c
index 2e796c0b3..f830b7230 100644
--- a/drivers/net/axgbe/axgbe_dev.c
+++ b/drivers/net/axgbe/axgbe_dev.c
@@ -1008,6 +1008,35 @@ static void axgbe_enable_mtl_interrupts(struct axgbe_port *pdata)
}
}
+void axgbe_set_mac_addn_addr(struct axgbe_port *pdata, u8 *addr, uint32_t index)
+{
+ unsigned int mac_addr_hi, mac_addr_lo;
+ u8 *mac_addr;
+
+ mac_addr_lo = 0;
+ mac_addr_hi = 0;
+
+ if (addr) {
+ mac_addr = (u8 *)&mac_addr_lo;
+ mac_addr[0] = addr[0];
+ mac_addr[1] = addr[1];
+ mac_addr[2] = addr[2];
+ mac_addr[3] = addr[3];
+ mac_addr = (u8 *)&mac_addr_hi;
+ mac_addr[0] = addr[4];
+ mac_addr[1] = addr[5];
+
+ /*Address Enable: Use this Addr for Perfect Filtering */
+ AXGMAC_SET_BITS(mac_addr_hi, MAC_MACA1HR, AE, 1);
+ }
+
+ PMD_DRV_LOG(DEBUG, "%s mac address at %#x\n",
+ addr ? "set" : "clear", index);
+
+ AXGMAC_IOWRITE(pdata, MAC_MACAHR(index), mac_addr_hi);
+ AXGMAC_IOWRITE(pdata, MAC_MACALR(index), mac_addr_lo);
+}
+
static int axgbe_set_mac_address(struct axgbe_port *pdata, u8 *addr)
{
unsigned int mac_addr_hi, mac_addr_lo;
diff --git a/drivers/net/axgbe/axgbe_ethdev.c b/drivers/net/axgbe/axgbe_ethdev.c
index 00974e737..34cc0fbb8 100644
--- a/drivers/net/axgbe/axgbe_ethdev.c
+++ b/drivers/net/axgbe/axgbe_ethdev.c
@@ -20,6 +20,16 @@ static int axgbe_dev_promiscuous_enable(struct rte_eth_dev *dev);
static int axgbe_dev_promiscuous_disable(struct rte_eth_dev *dev);
static int axgbe_dev_allmulticast_enable(struct rte_eth_dev *dev);
static int axgbe_dev_allmulticast_disable(struct rte_eth_dev *dev);
+static int axgbe_dev_mac_addr_set(struct rte_eth_dev *dev,
+ struct rte_ether_addr *mac_addr);
+static int axgbe_dev_mac_addr_add(struct rte_eth_dev *dev,
+ struct rte_ether_addr *mac_addr,
+ uint32_t index,
+ uint32_t vmdq);
+static void axgbe_dev_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index);
+static int axgbe_dev_set_mc_addr_list(struct rte_eth_dev *dev,
+ struct rte_ether_addr *mc_addr_set,
+ uint32_t nb_mc_addr);
static int axgbe_dev_link_update(struct rte_eth_dev *dev,
int wait_to_complete);
static int axgbe_dev_get_regs(struct rte_eth_dev *dev,
@@ -160,6 +170,10 @@ static const struct eth_dev_ops axgbe_eth_dev_ops = {
.promiscuous_disable = axgbe_dev_promiscuous_disable,
.allmulticast_enable = axgbe_dev_allmulticast_enable,
.allmulticast_disable = axgbe_dev_allmulticast_disable,
+ .mac_addr_set = axgbe_dev_mac_addr_set,
+ .mac_addr_add = axgbe_dev_mac_addr_add,
+ .mac_addr_remove = axgbe_dev_mac_addr_remove,
+ .set_mc_addr_list = axgbe_dev_set_mc_addr_list,
.link_update = axgbe_dev_link_update,
.get_reg = axgbe_dev_get_regs,
.stats_get = axgbe_dev_stats_get,
@@ -370,6 +384,74 @@ axgbe_dev_allmulticast_disable(struct rte_eth_dev *dev)
return 0;
}
+static int
+axgbe_dev_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
+{
+ struct axgbe_port *pdata = dev->data->dev_private;
+
+ /* Set Default MAC Addr */
+ axgbe_set_mac_addn_addr(pdata, (u8 *)mac_addr, 0);
+
+ return 0;
+}
+
+static int
+axgbe_dev_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
+ uint32_t index, uint32_t pool __rte_unused)
+{
+ struct axgbe_port *pdata = dev->data->dev_private;
+ struct axgbe_hw_features *hw_feat = &pdata->hw_feat;
+
+ if (index > hw_feat->addn_mac) {
+ PMD_DRV_LOG(ERR, "Invalid Index %d\n", index);
+ return -EINVAL;
+ }
+ axgbe_set_mac_addn_addr(pdata, (u8 *)mac_addr, index);
+ return 0;
+}
+
+static void
+axgbe_dev_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
+{
+ struct axgbe_port *pdata = dev->data->dev_private;
+ struct axgbe_hw_features *hw_feat = &pdata->hw_feat;
+
+ if (index > hw_feat->addn_mac) {
+ PMD_DRV_LOG(ERR, "Invalid Index %d\n", index);
+ return;
+ }
+ axgbe_set_mac_addn_addr(pdata, NULL, index);
+}
+
+static int
+axgbe_dev_set_mc_addr_list(struct rte_eth_dev *dev,
+ struct rte_ether_addr *mc_addr_set,
+ uint32_t nb_mc_addr)
+{
+ struct axgbe_port *pdata = dev->data->dev_private;
+ struct axgbe_hw_features *hw_feat = &pdata->hw_feat;
+ uint32_t index = 1; /* 0 is always default mac */
+ uint32_t i;
+
+ if (nb_mc_addr > hw_feat->addn_mac) {
+ PMD_DRV_LOG(ERR, "Invalid Index %d\n", nb_mc_addr);
+ return -EINVAL;
+ }
+
+ /* clear unicast addresses */
+ for (i = 1; i < hw_feat->addn_mac; i++) {
+ if (rte_is_zero_ether_addr(&dev->data->mac_addrs[i]))
+ continue;
+ memset(&dev->data->mac_addrs[i], 0,
+ sizeof(struct rte_ether_addr));
+ }
+
+ while (nb_mc_addr--)
+ axgbe_set_mac_addn_addr(pdata, (u8 *)mc_addr_set++, index++);
+
+ return 0;
+}
+
/* return 0 means link status changed, -1 means not changed */
static int
axgbe_dev_link_update(struct rte_eth_dev *dev,
@@ -809,7 +891,7 @@ axgbe_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
dev_info->max_tx_queues = pdata->tx_ring_count;
dev_info->min_rx_bufsize = AXGBE_RX_MIN_BUF_SIZE;
dev_info->max_rx_pktlen = AXGBE_RX_MAX_BUF_SIZE;
- dev_info->max_mac_addrs = AXGBE_MAX_MAC_ADDRS;
+ dev_info->max_mac_addrs = pdata->hw_feat.addn_mac + 1;
dev_info->speed_capa = ETH_LINK_SPEED_10G;
dev_info->rx_offload_capa =
@@ -1044,6 +1126,7 @@ eth_axgbe_dev_init(struct rte_eth_dev *eth_dev)
struct axgbe_port *pdata;
struct rte_pci_device *pci_dev;
uint32_t reg, mac_lo, mac_hi;
+ uint32_t len;
int ret;
eth_dev->dev_ops = &axgbe_eth_dev_ops;
@@ -1113,12 +1196,13 @@ eth_axgbe_dev_init(struct rte_eth_dev *eth_dev)
pdata->mac_addr.addr_bytes[4] = mac_hi & 0xff;
pdata->mac_addr.addr_bytes[5] = (mac_hi >> 8) & 0xff;
- eth_dev->data->mac_addrs = rte_zmalloc("axgbe_mac_addr",
- RTE_ETHER_ADDR_LEN, 0);
+ len = RTE_ETHER_ADDR_LEN * AXGBE_MAX_MAC_ADDRS;
+ eth_dev->data->mac_addrs = rte_zmalloc("axgbe_mac_addr", len, 0);
+
if (!eth_dev->data->mac_addrs) {
PMD_INIT_LOG(ERR,
- "Failed to alloc %u bytes needed to store MAC addr tbl",
- RTE_ETHER_ADDR_LEN);
+ "Failed to alloc %u bytes needed to "
+ "store MAC addresses", len);
return -ENOMEM;
}
diff --git a/drivers/net/axgbe/axgbe_ethdev.h b/drivers/net/axgbe/axgbe_ethdev.h
index a1083b17b..781d170e5 100644
--- a/drivers/net/axgbe/axgbe_ethdev.h
+++ b/drivers/net/axgbe/axgbe_ethdev.h
@@ -16,7 +16,7 @@
#define AXGBE_TX_MAX_BUF_SIZE (0x3fff & ~(64 - 1))
#define AXGBE_RX_MAX_BUF_SIZE (0x3fff & ~(64 - 1))
#define AXGBE_RX_MIN_BUF_SIZE (RTE_ETHER_MAX_LEN + VLAN_HLEN)
-#define AXGBE_MAX_MAC_ADDRS 1
+#define AXGBE_MAX_MAC_ADDRS 32
#define AXGBE_RX_BUF_ALIGN 64
@@ -631,5 +631,7 @@ void axgbe_init_function_ptrs_dev(struct axgbe_hw_if *hw_if);
void axgbe_init_function_ptrs_phy(struct axgbe_phy_if *phy_if);
void axgbe_init_function_ptrs_phy_v2(struct axgbe_phy_if *phy_if);
void axgbe_init_function_ptrs_i2c(struct axgbe_i2c_if *i2c_if);
+void axgbe_set_mac_addn_addr(struct axgbe_port *pdata, u8 *addr,
+ uint32_t index);
#endif /* RTE_ETH_AXGBE_H_ */
--
2.17.1
next reply other threads:[~2020-02-28 14:06 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-28 14:06 chandu [this message]
2020-02-28 14:06 ` [dpdk-dev] [PATCH v1 2/2] net/axgbe: add unicast hash table for mac address chandu
-- strict thread matches above, loose matches on Subject: below --
2020-02-28 14:20 [dpdk-dev] [PATCH v1 1/2] net/axgbe: add additional MAC address support chandu
2020-03-06 9:56 ` Kumar, Ravi1
2020-03-06 15:06 ` Ferruh Yigit
2020-02-28 13:59 chandu
2020-02-28 14:03 ` Ferruh Yigit
2020-02-28 14:15 ` Namburu, Chandu-babu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200228140608.668-1-chandu@amd.com \
--to=chandu@amd.com \
--cc=Amaranath.Somalapuram@amd.com \
--cc=Ravi1.Kumar@amd.com \
--cc=dev@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.