* [PATCH v1 6/8] net: stmmac: Add support for VLAN promiscuous mode
@ 2023-03-30 7:03 Boon Khai Ng
2023-03-30 17:25 ` Please ignore this review, send out by accident Boon Khai Ng
0 siblings, 1 reply; 2+ messages in thread
From: Boon Khai Ng @ 2023-03-30 7:03 UTC (permalink / raw)
To: David S . Miller; +Cc: linux-kernel, Mun Yew Tham, Tien Sung Ang, Boon Khai Ng
For dwxgmac2, enable VLAN promiscuity when MAC Controller is requested to
enter promiscuous mode.
Signed-off-by: Boon Khai Ng <boon.khai.ng@intel.com>
---
.../net/ethernet/stmicro/stmmac/dwxgmac2.h | 1 +
.../ethernet/stmicro/stmmac/dwxgmac2_core.c | 67 +++++++++++++++++++
2 files changed, 68 insertions(+)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
index 4c92828f21d6..3f11b2c52324 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
@@ -69,6 +69,7 @@
#define XGMAC_VLAN_CT BIT(1)
#define XGMAC_VLAN_OB BIT(0)
#define XGMAC_VLAN_HASH_TABLE 0x00000058
+#define XGMAC_VLAN_VLHT GENMASK(15, 0)
#define XGMAC_VLAN_INCL 0x00000060
#define XGMAC_VLAN_VLTI BIT(20)
#define XGMAC_VLAN_CSVL BIT(19)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
index feb9189ec20e..78bad5242562 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
@@ -472,6 +472,12 @@ static int dwxgmac2_add_hw_vlan_rx_fltr(struct net_device *dev,
if (vid > 4095)
return -EINVAL;
+ if (hw->promisc) {
+ netdev_err(dev,
+ "Adding VLAN in promisc mode not supported\n");
+ return -EPERM;
+ }
+
/* Single Rx VLAN Filter */
if (hw->num_vlan == 1) {
/* For single VLAN filter, VID 0 means VLAN promiscuous */
@@ -522,6 +528,12 @@ static int dwxgmac2_del_hw_vlan_rx_fltr(struct net_device *dev,
{
int i, ret = 0;
+ if (hw->promisc) {
+ netdev_err(dev,
+ "Deleting VLAN in promisc mode not supported\n");
+ return -EPERM;
+ }
+
/* Single Rx VLAN Filter */
if (hw->num_vlan == 1) {
if ((hw->vlan_filter[0] & XGMAC_VLAN_VID) == vid) {
@@ -545,9 +557,45 @@ static int dwxgmac2_del_hw_vlan_rx_fltr(struct net_device *dev,
return ret;
}
+static void dwxgmac2_vlan_promisc_enable(struct net_device *dev,
+ struct mac_device_info *hw)
+{
+ void __iomem *ioaddr = hw->pcsr;
+ u32 value;
+ u32 hash;
+ u32 val;
+ int i;
+
+ /* Single Rx VLAN Filter */
+ if (hw->num_vlan == 1) {
+ dwxgmac2_write_single_vlan(dev, 0);
+ return;
+ }
+
+ /* Extended Rx VLAN Filter Enable */
+ for (i = 0; i < hw->num_vlan; i++) {
+ if (hw->vlan_filter[i] & XGMAC_VLAN_TAG_DATA_VEN) {
+ val = hw->vlan_filter[i] & ~XGMAC_VLAN_TAG_DATA_VEN;
+ dwxgmac2_write_vlan_filter(dev, hw, i, val);
+ }
+ }
+
+ hash = readl(ioaddr + XGMAC_VLAN_HASH_TABLE);
+ if (hash & XGMAC_VLAN_VLHT) {
+ value = readl(ioaddr + XGMAC_VLAN_TAG);
+ if (value & XGMAC_VLAN_VTHM) {
+ value &= ~XGMAC_VLAN_VTHM;
+ writel(value, ioaddr + XGMAC_VLAN_TAG);
+ }
+ }
+}
+
static void dwxgmac2_restore_hw_vlan_rx_fltr(struct net_device *dev,
struct mac_device_info *hw)
{
+ void __iomem *ioaddr = hw->pcsr;
+ u32 value;
+ u32 hash;
u32 val;
int i;
@@ -564,6 +612,13 @@ static void dwxgmac2_restore_hw_vlan_rx_fltr(struct net_device *dev,
dwxgmac2_write_vlan_filter(dev, hw, i, val);
}
}
+
+ hash = readl(ioaddr + XGMAC_VLAN_HASH_TABLE);
+ if (hash & XGMAC_VLAN_VLHT) {
+ value = readl(ioaddr + XGMAC_VLAN_TAG);
+ value |= XGMAC_VLAN_VTHM;
+ writel(value, ioaddr + XGMAC_VLAN_TAG);
+ }
}
static void dwxgmac2_set_mchash(void __iomem *ioaddr, u32 *mcfilterbits,
@@ -649,6 +704,18 @@ static void dwxgmac2_set_filter(struct mac_device_info *hw,
value |= XGMAC_FILTER_VTFE;
writel(value, ioaddr + XGMAC_PACKET_FILTER);
+
+ if (dev->flags & IFF_PROMISC) {
+ if (!hw->promisc) {
+ hw->promisc = 1;
+ dwxgmac2_vlan_promisc_enable(dev, hw);
+ }
+ } else {
+ if (hw->promisc) {
+ hw->promisc = 0;
+ dwxgmac2_restore_hw_vlan_rx_fltr(dev, hw);
+ }
+ }
}
static void dwxgmac2_set_mac_loopback(void __iomem *ioaddr, bool enable)
--
2.25.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Please ignore this review, send out by accident.
2023-03-30 7:03 [PATCH v1 6/8] net: stmmac: Add support for VLAN promiscuous mode Boon Khai Ng
@ 2023-03-30 17:25 ` Boon Khai Ng
0 siblings, 0 replies; 2+ messages in thread
From: Boon Khai Ng @ 2023-03-30 17:25 UTC (permalink / raw)
To: boon.khai.ng; +Cc: davem, linux-kernel, mun.yew.tham, tien.sung.ang
My appologies for sending out this review by accident, this is meant for internal reivew,
kindly ignore and close this thread. Thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-03-30 17:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-30 7:03 [PATCH v1 6/8] net: stmmac: Add support for VLAN promiscuous mode Boon Khai Ng
2023-03-30 17:25 ` Please ignore this review, send out by accident Boon Khai Ng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®