Skip to content
Permalink
Browse files

net: sun8i-emac: fix multicast

Signed-off-by: Corentin Labbe <clabbe.montjoie@gmail.com>
  • Loading branch information...
montjoie committed Apr 25, 2017
1 parent a1c52b8 commit 43934e114a3a3358a570480c8974e4e52769cd11
Showing with 33 additions and 10 deletions.
  1. +33 −10 drivers/net/ethernet/allwinner/sun8i-emac.c
@@ -94,6 +94,10 @@
#define EMAC_FRM_FLT_CTL BIT(13)
#define EMAC_FRM_FLT_MULTICAST BIT(16)

/* Mac address */
#define EMAC_MAX_MACADDR 8
#define MAC_ADDR_TYPE_DST BIT(31)

/* Used in BASIC_CTL0 */
#define EMAC_BCTL0_FD BIT(0)
#define EMAC_BCTL0_LOOPBACK BIT(1)
@@ -520,9 +524,16 @@ static void sun8i_emac_set_macaddr(struct sun8i_emac_priv *priv,
{
u32 v;

if (index > 7) {
dev_err(priv->dev, "Too many MAC addr\n");
return;
}

dev_info(priv->dev, "device MAC address slot %d %pM", index, addr);

v = (addr[5] << 8) | addr[4];
if (index > 0)
v |= MAC_ADDR_TYPE_DST;
writel(v, priv->base + EMAC_MACADDR_HI + index * 8);

v = (addr[3] << 24) | (addr[2] << 16) | (addr[1] << 8) | addr[0];
@@ -1741,21 +1752,33 @@ static void sun8i_emac_set_rx_mode(struct net_device *ndev)
u32 v = 0;
int i = 0;
struct netdev_hw_addr *ha;
int macaddrs = netdev_uc_count(ndev) + netdev_mc_count(ndev) + 1;

/* Receive all multicast frames */
v |= EMAC_FRM_FLT_MULTICAST;
/* Receive all control frames */
v |= EMAC_FRM_FLT_CTL;
if (ndev->flags & IFF_PROMISC)
v |= EMAC_FRM_FLT_RXALL;
if (netdev_uc_count(ndev) > 7) {
v |= EMAC_FRM_FLT_RXALL;
} else {
netdev_for_each_uc_addr(ha, ndev) {
i++;
sun8i_emac_set_macaddr(priv, ha->addr, i);

if (ndev->flags & IFF_PROMISC) {
v = EMAC_FRM_FLT_RXALL;
} else if (ndev->flags & IFF_ALLMULTI) {
v |= EMAC_FRM_FLT_MULTICAST;
} else if (macaddrs <= EMAC_MAX_MACADDR) {
if (!netdev_mc_empty(ndev)) {
netdev_for_each_mc_addr(ha, ndev) {
i++;
sun8i_emac_set_macaddr(priv, ha->addr, i);
}
}
if (!netdev_uc_empty(ndev)) {
netdev_for_each_uc_addr(ha, ndev) {
i++;
sun8i_emac_set_macaddr(priv, ha->addr, i);
}
}
} else {
netdev_info(ndev, "Too many address, switching to promiscuous\n");
v = EMAC_FRM_FLT_RXALL;
}

writel(v, priv->base + EMAC_RX_FRM_FLT);
}

2 comments on commit 43934e1

@ThomasKaiser

This comment has been minimized.

Copy link

ThomasKaiser replied Apr 28, 2017

Just a quick question: Is this the fix for the reported AppleTalk problem here: https://forum.armbian.com/index.php?/topic/3236-appletalkagain/&do=findComment&comment=30443

@montjoie

This comment has been minimized.

Copy link
Owner Author

montjoie replied Apr 29, 2017

Yes

Please sign in to comment.
You can’t perform that action at this time.