From patchwork Thu Oct 3 19:18:37 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Merello X-Patchwork-Id: 280402 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 0CC722C00D1 for ; Fri, 4 Oct 2013 05:19:05 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755085Ab3JCTSu (ORCPT ); Thu, 3 Oct 2013 15:18:50 -0400 Received: from mail-ee0-f54.google.com ([74.125.83.54]:52356 "EHLO mail-ee0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754377Ab3JCTSs (ORCPT ); Thu, 3 Oct 2013 15:18:48 -0400 Received: by mail-ee0-f54.google.com with SMTP id e53so1339085eek.13 for ; Thu, 03 Oct 2013 12:18:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=L0B8hz5Pls6ODIYiiKYW4NRGvEDZFSex9Nc9YvsLx24=; b=YyCP4m1T0DqLA2YBFN30RaLeeXbaTdPrmtddVI+ggnmXUuTh252bmkMXTlYJF9Wwu1 kZL5dgLipdVO1gTXQBeL0ARldLPjiWYn4t6m2rQcdqz28Waxutp+S6dijr6QOkD+DgvM 1qOCJMlcl0zKafO9x3nGY9cVf+s6T60mPGDF8nM9EOV7eihlJ7jE8STTMRplTfKWRBkl Ahda7oLx5U+UnNamcI6UumDvVoIYmEcAZ0QDCG2Y/9s5Y6hcBc5n9vi0/BT9v3pw3lvF ObseaQeVZqzBtAUdmLLIyrRNalpAQV0hcus4nOlpykDA+uDtCRtAcdbCthcmwGdEdLML sXlA== X-Received: by 10.14.218.197 with SMTP id k45mr15137883eep.32.1380827927166; Thu, 03 Oct 2013 12:18:47 -0700 (PDT) Received: from localhost.localdomain (host96-15-dynamic.249-95-r.retail.telecomitalia.it. [95.249.15.96]) by mx.google.com with ESMTPSA id r48sm19037072eev.14.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 03 Oct 2013 12:18:46 -0700 (PDT) From: Andrea Merello To: jie.yang@atheros.com, xiong.huang@atheros.com Cc: davem@davemloft.net, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Andrea Merello Subject: [PATCH] atl1e: enable support for NETIF_F_RXALL and NETIF_F_RXCRC features Date: Thu, 3 Oct 2013 21:18:37 +0200 Message-Id: <1380827917-22992-1-git-send-email-andrea.merello@gmail.com> X-Mailer: git-send-email 1.8.1.2 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch allows (optionally, via ethtool) the atl1e NIC to: - Receive bad frames (runt, bad-fcs, etc..) - Receive full frames without stripping the FCS. This has been tested on my board by injecting runt and bad-fcs frames with a FPGA-based device. The particular scenario of receiving very short frames (<4 bytes) without passing FCS to the upper layer has been also tested: This could be potentially dangerous because the driver performs a 4 byte subtraction on the frame length, but I finally have NOT added anything to avoid this because it seems the NIC always discards frames so much short.. If someone still have some reason to worry about this, please tell me.. I will add an explicit SW check.. Signed-off-by: Andrea Merello --- drivers/net/ethernet/atheros/atl1e/atl1e_main.c | 46 ++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/atheros/atl1e/atl1e_main.c b/drivers/net/ethernet/atheros/atl1e/atl1e_main.c index 1966444..7a73f3a 100644 --- a/drivers/net/ethernet/atheros/atl1e/atl1e_main.c +++ b/drivers/net/ethernet/atheros/atl1e/atl1e_main.c @@ -313,6 +313,34 @@ static void atl1e_set_multi(struct net_device *netdev) } } +static void __atl1e_rx_mode(netdev_features_t features, u32 *mac_ctrl_data) +{ + + if (features & NETIF_F_RXALL) { + /* enable RX of ALL frames */ + *mac_ctrl_data |= MAC_CTRL_DBG; + } else { + /* disable RX of ALL frames */ + *mac_ctrl_data &= ~MAC_CTRL_DBG; + } +} + +static void atl1e_rx_mode(struct net_device *netdev, + netdev_features_t features) +{ + struct atl1e_adapter *adapter = netdev_priv(netdev); + u32 mac_ctrl_data = 0; + + netdev_dbg(adapter->netdev, "%s\n", __func__); + + atl1e_irq_disable(adapter); + mac_ctrl_data = AT_READ_REG(&adapter->hw, REG_MAC_CTRL); + __atl1e_rx_mode(features, &mac_ctrl_data); + AT_WRITE_REG(&adapter->hw, REG_MAC_CTRL, mac_ctrl_data); + atl1e_irq_enable(adapter); +} + + static void __atl1e_vlan_mode(netdev_features_t features, u32 *mac_ctrl_data) { if (features & NETIF_F_HW_VLAN_CTAG_RX) { @@ -394,6 +422,10 @@ static int atl1e_set_features(struct net_device *netdev, if (changed & NETIF_F_HW_VLAN_CTAG_RX) atl1e_vlan_mode(netdev, features); + if (changed & NETIF_F_RXALL) + atl1e_rx_mode(netdev, features); + + return 0; } @@ -1057,7 +1089,8 @@ static void atl1e_setup_mac_ctrl(struct atl1e_adapter *adapter) value |= MAC_CTRL_PROMIS_EN; if (netdev->flags & IFF_ALLMULTI) value |= MAC_CTRL_MC_ALL_EN; - + if (netdev->features & NETIF_F_RXALL) + value |= MAC_CTRL_DBG; AT_WRITE_REG(hw, REG_MAC_CTRL, value); } @@ -1405,7 +1438,8 @@ static void atl1e_clean_rx_irq(struct atl1e_adapter *adapter, u8 que, rx_page_desc[que].rx_nxseq++; /* error packet */ - if (prrs->pkt_flag & RRS_IS_ERR_FRAME) { + if ((prrs->pkt_flag & RRS_IS_ERR_FRAME) && + !(netdev->features & NETIF_F_RXALL)) { if (prrs->err_flag & (RRS_ERR_BAD_CRC | RRS_ERR_DRIBBLE | RRS_ERR_CODE | RRS_ERR_TRUNC)) { @@ -1418,7 +1452,10 @@ static void atl1e_clean_rx_irq(struct atl1e_adapter *adapter, u8 que, } packet_size = ((prrs->word1 >> RRS_PKT_SIZE_SHIFT) & - RRS_PKT_SIZE_MASK) - 4; /* CRC */ + RRS_PKT_SIZE_MASK); + if (likely(!(netdev->features & NETIF_F_RXFCS))) + packet_size -= 4; /* CRC */ + skb = netdev_alloc_skb_ip_align(netdev, packet_size); if (skb == NULL) goto skip_pkt; @@ -2245,7 +2282,8 @@ static int atl1e_init_netdev(struct net_device *netdev, struct pci_dev *pdev) NETIF_F_HW_VLAN_CTAG_RX; netdev->features = netdev->hw_features | NETIF_F_LLTX | NETIF_F_HW_VLAN_CTAG_TX; - + /* not enabled by default */ + netdev->hw_features |= NETIF_F_RXALL | NETIF_F_RXFCS; return 0; }