From patchwork Tue Aug 21 11:36:07 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yan Burman X-Patchwork-Id: 1354901 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 7139DDFB34 for ; Tue, 21 Aug 2012 12:41:00 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1T3niJ-0005Cs-H8; Tue, 21 Aug 2012 12:37:44 +0000 Received: from mail-we0-f177.google.com ([74.125.82.177]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1T3niE-0005Bm-Gs for linux-arm-kernel@lists.infradead.org; Tue, 21 Aug 2012 12:37:39 +0000 Received: by weyr3 with SMTP id r3so4955010wey.36 for ; Tue, 21 Aug 2012 05:37:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:from:to:content-type:date:message-id:mime-version:x-mailer :content-transfer-encoding; bh=9lK1jJj6eeSxf/NXr+ncNSK/n3d9WBB4ehWqO5WFozs=; b=pJzuWiKiUmMn1KWt6ChTbn8G8wUr2cqZ6DoCsWM7OE7Yr6StVJUTdCEmmMTTnBRXCC Axotzcv7wHs6yrUBZLh3XcHEBSlY3ubC0S4z8u5T/UlT64Xykjh18oWq/Uiiz16fELyI MJSbWZLD2UwdtzF+nWSJC3xGl/usBxALOqq8kJfdnWtpPJ56/va6nHkzgJt8HNSfBESR t6x/egeyzkXOzw0M5GmkH0THo2aoSGWysOvqV3W7U7bFJZPbFxUhNbZ+h7bmAe2U1g7Y 6lqV9A+neftp10A77696D/iZB5/eveIhj6N7NJrt8yCVrWoUwcHvbekbToDXUibJktMv ZM4A== Received: by 10.180.91.228 with SMTP id ch4mr37705838wib.7.1345552656568; Tue, 21 Aug 2012 05:37:36 -0700 (PDT) Received: from [10.0.0.26] (IGLD-84-228-68-178.inter.net.il. [84.228.68.178]) by mx.google.com with ESMTPS id b7sm3890798wiz.9.2012.08.21.05.37.34 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 21 Aug 2012 05:37:35 -0700 (PDT) Subject: [PATCH v3] ARM: ep93xx: Use HW MAC filter in ethernet driver From: Yan Burman To: linux-arm-kernel@lists.infradead.org, hsweeten@visionengravers.com, rmallon@gmail.com Date: Tue, 21 Aug 2012 14:36:07 +0300 Message-Id: <1345548967.4262.2.camel@localhost> Mime-Version: 1.0 X-Mailer: Evolution 2.6.3 (2.6.3-2.fc5) X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.82.177 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (burman.yan[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org ARM: ep93xx: Use HW MAC filter in ethernet driver Use HW MAC filtering for broadcasts and multicasts. Do not always work in promiscuous mode. Partially based on kernel 2.6.20.4 driver from cirrus logic. Tested on 9302 and 9315 based boards. Changes from v2: * Some more minor style changes Changes from v1: * Some minor style fixes * Use CRC32 code instead of duplicating code * Fixed multicast reception (tested with omping) Signed-off-by: Yan Burman diff --git a/drivers/net/ethernet/cirrus/Kconfig b/drivers/net/ethernet/cirrus/Kconfig index 8388e36..b7b154f 100644 --- a/drivers/net/ethernet/cirrus/Kconfig +++ b/drivers/net/ethernet/cirrus/Kconfig @@ -46,6 +46,7 @@ config EP93XX_ETH depends on ARM && ARCH_EP93XX select NET_CORE select MII + select CRC32 help This is a driver for the ethernet hardware included in EP93xx CPUs. Say Y if you are building a kernel for EP93xx based devices. diff --git a/drivers/net/ethernet/cirrus/ep93xx_eth.c b/drivers/net/ethernet/cirrus/ep93xx_eth.c index 78c5521..a92a033 100644 --- a/drivers/net/ethernet/cirrus/ep93xx_eth.c +++ b/drivers/net/ethernet/cirrus/ep93xx_eth.c @@ -25,6 +25,7 @@ #include #include #include +#include #include @@ -37,8 +38,32 @@ #define MAX_PKT_SIZE 2044 #define PKT_BUF_SIZE 2048 +#define HASH_TBL_ENTRIES 8 + #define REG_RXCTL 0x0000 -#define REG_RXCTL_DEFAULT 0x00073800 +#define REG_RXCTL_PAUSEA (1 << 20) +#define REG_RXCTL_RXFCE1 (1 << 19) +#define REG_RXCTL_RXFCE0 (1 << 18) +#define REG_RXCTL_BCRC (1 << 17) +#define REG_RXCTL_SRXON (1 << 16) +#define REG_RXCTL_RCRCA (1 << 13) +#define REG_RXCTL_RA (1 << 12) +#define REG_RXCTL_PA (1 << 11) +#define REG_RXCTL_BA (1 << 10) +#define REG_RXCTL_MA (1 << 9) +#define REG_RXCTL_IAHA (1 << 8) +#define REG_RXCTL_IA3 (1 << 3) +#define REG_RXCTL_IA2 (1 << 2) +#define REG_RXCTL_IA1 (1 << 1) +#define REG_RXCTL_IA0 (1 << 0) +#define REG_RXCTL_DEFAULT (REG_RXCTL_BA | \ + REG_RXCTL_RA | \ + REG_RXCTL_RCRCA | \ + REG_RXCTL_SRXON | \ + REG_RXCTL_BCRC | \ + REG_RXCTL_RXFCE0 | \ + REG_RXCTL_IA0) + #define REG_TXCTL 0x0004 #define REG_TXCTL_ENABLE 0x00000001 #define REG_MIICMD 0x0010 @@ -57,6 +82,12 @@ #define REG_INTSTS_RX 0x00000004 #define REG_INTSTSC 0x002c #define REG_AFP 0x004c +#define REG_AFP_IA0 0 +#define REG_AFP_IA1 1 +#define REG_AFP_IA2 2 +#define REG_AFP_IA3 3 +#define REG_AFP_DTxP 6 +#define REG_AFP_HASH 7 #define REG_INDAD0 0x0050 #define REG_INDAD1 0x0051 #define REG_INDAD2 0x0052 @@ -386,6 +417,51 @@ static int ep93xx_xmit(struct sk_buff *skb, struct net_device *dev) return NETDEV_TX_OK; } +static void ep93xx_set_mcast_tbl(struct net_device *dev, u8 *buf) +{ + struct netdev_hw_addr *ha; + u32 crc; + + netdev_for_each_mc_addr(ha, dev) { + crc = ether_crc_le(ETH_ALEN, ha->addr); + buf[crc >> 29] |= (1 << ((crc >> 26) & 7)); + } +} + +static int ep93xx_ind_addr_write(struct net_device *dev, int afp, char *buf) +{ + u32 rxctl; + unsigned int i, len; + struct ep93xx_priv *ep = netdev_priv(dev); + + switch (afp) { + case REG_AFP_IA0: + case REG_AFP_IA1: + case REG_AFP_IA2: + case REG_AFP_IA3: + case REG_AFP_DTxP: + len = ETH_ALEN; + break; + + case REG_AFP_HASH: + len = HASH_TBL_ENTRIES; + break; + + default: + pr_crit("invalid afp value: %d\n", afp); + return -EINVAL; + } + + rxctl = rdl(ep, REG_RXCTL); + wrl(ep, REG_RXCTL, rxctl & ~REG_RXCTL_SRXON); + wrl(ep, REG_AFP, afp); + for (i = 0; i < len; i++) + wrb(ep, REG_INDAD0 + i, buf[i]); + wrl(ep, REG_RXCTL, rxctl); + + return 0; +} + static void ep93xx_tx_complete(struct net_device *dev) { struct ep93xx_priv *ep = netdev_priv(dev); @@ -615,13 +691,7 @@ static int ep93xx_start_hw(struct net_device *dev) wrl(ep, REG_RXDENQ, RX_QUEUE_ENTRIES); wrl(ep, REG_RXSTSENQ, RX_QUEUE_ENTRIES); - wrb(ep, REG_INDAD0, dev->dev_addr[0]); - wrb(ep, REG_INDAD1, dev->dev_addr[1]); - wrb(ep, REG_INDAD2, dev->dev_addr[2]); - wrb(ep, REG_INDAD3, dev->dev_addr[3]); - wrb(ep, REG_INDAD4, dev->dev_addr[4]); - wrb(ep, REG_INDAD5, dev->dev_addr[5]); - wrl(ep, REG_AFP, 0); + ep93xx_ind_addr_write(dev, REG_AFP_IA0, dev->dev_addr); wrl(ep, REG_MAXFRMLEN, (MAX_PKT_SIZE << 16) | MAX_PKT_SIZE); @@ -647,6 +717,30 @@ static void ep93xx_stop_hw(struct net_device *dev) pr_crit("hw failed to reset\n"); } +static void ep93xx_set_multicast_list(struct net_device *dev) +{ + struct ep93xx_priv *ep = netdev_priv(dev); + + if (dev->flags & IFF_PROMISC) { + wrl(ep, REG_RXCTL, REG_RXCTL_PA | rdl(ep, REG_RXCTL)); + } else if (dev->flags & IFF_ALLMULTI) { + wrl(ep, REG_RXCTL, REG_RXCTL_MA | + (rdl(ep, REG_RXCTL) & ~REG_RXCTL_PA)); + ep93xx_ind_addr_write(dev, REG_AFP_HASH, + "\xff\xff\xff\xff\xff\xff\xff\xff"); + } else if (!netdev_mc_empty(dev)) { + u8 tbl_multi[HASH_TBL_ENTRIES + 1] = {0}; + + ep93xx_set_mcast_tbl(dev, tbl_multi); + wrl(ep, REG_RXCTL, REG_RXCTL_MA | + (rdl(ep, REG_RXCTL) & ~REG_RXCTL_PA)); + ep93xx_ind_addr_write(dev, REG_AFP_HASH, tbl_multi); + } else { + wrl(ep, REG_RXCTL, + rdl(ep, REG_RXCTL) & ~(REG_RXCTL_PA | REG_RXCTL_MA)); + } +} + static int ep93xx_open(struct net_device *dev) { struct ep93xx_priv *ep = netdev_priv(dev); @@ -754,6 +848,7 @@ static const struct net_device_ops ep93xx_netdev_ops = { .ndo_validate_addr = eth_validate_addr, .ndo_change_mtu = eth_change_mtu, .ndo_set_mac_address = eth_mac_addr, + .ndo_set_rx_mode = ep93xx_set_multicast_list, }; static struct net_device *ep93xx_dev_alloc(struct ep93xx_eth_data *data)