Skip to content

Commit c89f44f

Browse files
kchuah4davem330
authored andcommitted
net: stmmac: Add support for VLAN promiscuous mode
For dwmac4, enable VLAN promiscuity when MAC controller is requested to enter promiscuous mode. Signed-off-by: Chuah, Kim Tatt <kim.tatt.chuah@intel.com> Signed-off-by: Ong Boon Leong <boon.leong.ong@intel.com> Signed-off-by: Tan, Tee Min <tee.min.tan@intel.com> Signed-off-by: Wong Vee Khee <vee.khee.wong@intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 58e64a3 commit c89f44f

3 files changed

Lines changed: 69 additions & 0 deletions

File tree

‎drivers/net/ethernet/stmicro/stmmac/common.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ struct mac_device_info {
473473
unsigned int xlgmac;
474474
unsigned int num_vlan;
475475
u32 vlan_filter[32];
476+
unsigned int promisc;
476477
};
477478

478479
struct stmmac_rx_routing {

‎drivers/net/ethernet/stmicro/stmmac/dwmac4.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
#define GMAC_VLAN_CSVL BIT(19)
9191
#define GMAC_VLAN_VLC GENMASK(17, 16)
9292
#define GMAC_VLAN_VLC_SHIFT 16
93+
#define GMAC_VLAN_VLHT GENMASK(15, 0)
9394

9495
/* MAC VLAN Tag */
9596
#define GMAC_VLAN_TAG_VID GENMASK(15, 0)

‎drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,12 @@ static int dwmac4_add_hw_vlan_rx_fltr(struct net_device *dev,
450450
if (vid > 4095)
451451
return -EINVAL;
452452

453+
if (hw->promisc) {
454+
netdev_err(dev,
455+
"Adding VLAN in promisc mode not supported\n");
456+
return -EPERM;
457+
}
458+
453459
/* Single Rx VLAN Filter */
454460
if (hw->num_vlan == 1) {
455461
/* For single VLAN filter, VID 0 means VLAN promiscuous */
@@ -499,6 +505,12 @@ static int dwmac4_del_hw_vlan_rx_fltr(struct net_device *dev,
499505
{
500506
int i, ret = 0;
501507

508+
if (hw->promisc) {
509+
netdev_err(dev,
510+
"Deleting VLAN in promisc mode not supported\n");
511+
return -EPERM;
512+
}
513+
502514
/* Single Rx VLAN Filter */
503515
if (hw->num_vlan == 1) {
504516
if ((hw->vlan_filter[0] & GMAC_VLAN_TAG_VID) == vid) {
@@ -523,9 +535,45 @@ static int dwmac4_del_hw_vlan_rx_fltr(struct net_device *dev,
523535
return ret;
524536
}
525537

538+
static void dwmac4_vlan_promisc_enable(struct net_device *dev,
539+
struct mac_device_info *hw)
540+
{
541+
void __iomem *ioaddr = hw->pcsr;
542+
u32 value;
543+
u32 hash;
544+
u32 val;
545+
int i;
546+
547+
/* Single Rx VLAN Filter */
548+
if (hw->num_vlan == 1) {
549+
dwmac4_write_single_vlan(dev, 0);
550+
return;
551+
}
552+
553+
/* Extended Rx VLAN Filter Enable */
554+
for (i = 0; i < hw->num_vlan; i++) {
555+
if (hw->vlan_filter[i] & GMAC_VLAN_TAG_DATA_VEN) {
556+
val = hw->vlan_filter[i] & ~GMAC_VLAN_TAG_DATA_VEN;
557+
dwmac4_write_vlan_filter(dev, hw, i, val);
558+
}
559+
}
560+
561+
hash = readl(ioaddr + GMAC_VLAN_HASH_TABLE);
562+
if (hash & GMAC_VLAN_VLHT) {
563+
value = readl(ioaddr + GMAC_VLAN_TAG);
564+
if (value & GMAC_VLAN_VTHM) {
565+
value &= ~GMAC_VLAN_VTHM;
566+
writel(value, ioaddr + GMAC_VLAN_TAG);
567+
}
568+
}
569+
}
570+
526571
static void dwmac4_restore_hw_vlan_rx_fltr(struct net_device *dev,
527572
struct mac_device_info *hw)
528573
{
574+
void __iomem *ioaddr = hw->pcsr;
575+
u32 value;
576+
u32 hash;
529577
u32 val;
530578
int i;
531579

@@ -542,6 +590,13 @@ static void dwmac4_restore_hw_vlan_rx_fltr(struct net_device *dev,
542590
dwmac4_write_vlan_filter(dev, hw, i, val);
543591
}
544592
}
593+
594+
hash = readl(ioaddr + GMAC_VLAN_HASH_TABLE);
595+
if (hash & GMAC_VLAN_VLHT) {
596+
value = readl(ioaddr + GMAC_VLAN_TAG);
597+
value |= GMAC_VLAN_VTHM;
598+
writel(value, ioaddr + GMAC_VLAN_TAG);
599+
}
545600
}
546601

547602
static void dwmac4_set_filter(struct mac_device_info *hw,
@@ -624,6 +679,18 @@ static void dwmac4_set_filter(struct mac_device_info *hw,
624679
value |= GMAC_PACKET_FILTER_VTFE;
625680

626681
writel(value, ioaddr + GMAC_PACKET_FILTER);
682+
683+
if (dev->flags & IFF_PROMISC) {
684+
if (!hw->promisc) {
685+
hw->promisc = 1;
686+
dwmac4_vlan_promisc_enable(dev, hw);
687+
}
688+
} else {
689+
if (hw->promisc) {
690+
hw->promisc = 0;
691+
dwmac4_restore_hw_vlan_rx_fltr(dev, hw);
692+
}
693+
}
627694
}
628695

629696
static void dwmac4_flow_ctrl(struct mac_device_info *hw, unsigned int duplex,

0 commit comments

Comments
 (0)