From patchwork Tue May 10 00:04:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iyappan Subramanian X-Patchwork-Id: 9052131 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D6119BF29F for ; Tue, 10 May 2016 00:06:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D6D7B20123 for ; Tue, 10 May 2016 00:06:32 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D28DA200F0 for ; Tue, 10 May 2016 00:06:31 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1azvAk-00060R-VL; Tue, 10 May 2016 00:05:11 +0000 Received: from mail-pf0-x232.google.com ([2607:f8b0:400e:c00::232]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1azv9q-0004Wt-LK for linux-arm-kernel@lists.infradead.org; Tue, 10 May 2016 00:04:17 +0000 Received: by mail-pf0-x232.google.com with SMTP id 77so81172131pfv.2 for ; Mon, 09 May 2016 17:03:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=apm.com; s=apm; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DHnl8g/4sLJO/UraP2TFAWkQsTfG5+9tCJpE+1kTyx0=; b=aNW/mU0w0Hj3v2jJQvUviSBrXOwJgic4o6GN8wpmjstSMr3DUI7Aa1vhu3FLfwdXsp U3jsRaOTozCzNOkuCQo2hzTNSsV9TEVa/O0SUe4rz1ndq8CrEZnF5cWyAqpFIQSvUhkF iEzeekt1yOxsKI7L/6T5q604jv29Xdkyi28mE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=DHnl8g/4sLJO/UraP2TFAWkQsTfG5+9tCJpE+1kTyx0=; b=BBWPvoBlixXAHRXa6aW/fVyLeaa8IaZQGpsQsvTUi1C/I3hKGuVMmOaSKizgytScUJ DUIO/filoZhdWTMj7zPrJx4N9zhPaD3BKWiBFIkT3UbUsQkTZiQ3lqB090G+qCNIwQBu VMMVOUnoPl2Vyu79AZSrLJKMgsDTVFVb1hoxY2QDi6k1xSwohu7+0EDWZKeyDhqYlcyN 83nMW26+7j7yeNg9v8UCdUsxZL7/bOGKB723P4mj3Qv3GCqjcgofI53Fq5uqx7Fzbo2v zqwBFNhiE5L6mO4djSbiBlEQj0/qSNNsRyCyOyXW2wyZ3U7zmhdDE9JiKVlVopQwY8Kn BplA== X-Gm-Message-State: AOPr4FXGs842ujxCi37MbqsYYrHIGBFz7GHpE0SEDLb3k2tijB/udWoIKYYIKTnAqfZIg1Vn X-Received: by 10.98.82.19 with SMTP id g19mr53706200pfb.157.1462838634153; Mon, 09 May 2016 17:03:54 -0700 (PDT) Received: from isubrama-dev.amcc.com ([206.80.4.98]) by smtp.gmail.com with ESMTPSA id d186sm43109296pfa.45.2016.05.09.17.03.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 May 2016 17:03:53 -0700 (PDT) From: Iyappan Subramanian To: davem@davemloft.net, netdev@vger.kernel.org Subject: [PATCH 5/6] drivers: net: xgene: Using static MSS values Date: Mon, 9 May 2016 17:04:15 -0700 Message-Id: <1462838656-22043-6-git-send-email-isubramanian@apm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1462838656-22043-1-git-send-email-isubramanian@apm.com> References: <1462838656-22043-1-git-send-email-isubramanian@apm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160509_170414_907358_989DAA2D X-CRM114-Status: GOOD ( 15.92 ) X-Spam-Score: -2.7 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: toanle@apm.com, patches@apm.com, linux-arm-kernel@lists.infradead.org, Iyappan Subramanian MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-6.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Due to the nature of hardware design for TSO, if the MSS values that are stored in the register, changes during TSO operation, data corruption may occur. This patch fixes the issue by using one of the predefined MSS values. Signed-off-by: Iyappan Subramanian Tested-by: Toan Le --- drivers/net/ethernet/apm/xgene/xgene_enet_hw.c | 2 - drivers/net/ethernet/apm/xgene/xgene_enet_hw.h | 2 + drivers/net/ethernet/apm/xgene/xgene_enet_main.c | 45 ++++++++++++++++++++++- drivers/net/ethernet/apm/xgene/xgene_enet_main.h | 6 +-- drivers/net/ethernet/apm/xgene/xgene_enet_xgmac.c | 20 ++++++++-- 5 files changed, 66 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/apm/xgene/xgene_enet_hw.c b/drivers/net/ethernet/apm/xgene/xgene_enet_hw.c index 0050878..2f5638f 100644 --- a/drivers/net/ethernet/apm/xgene/xgene_enet_hw.c +++ b/drivers/net/ethernet/apm/xgene/xgene_enet_hw.c @@ -219,8 +219,6 @@ void xgene_enet_parse_error(struct xgene_enet_desc_ring *ring, struct xgene_enet_pdata *pdata, enum xgene_enet_err_code status) { - struct rtnl_link_stats64 *stats = &pdata->stats; - switch (status) { case INGRESS_CRC: ring->rx_crc_errors++; diff --git a/drivers/net/ethernet/apm/xgene/xgene_enet_hw.h b/drivers/net/ethernet/apm/xgene/xgene_enet_hw.h index ecfeffe..a3c12dc 100644 --- a/drivers/net/ethernet/apm/xgene/xgene_enet_hw.h +++ b/drivers/net/ethernet/apm/xgene/xgene_enet_hw.h @@ -227,6 +227,8 @@ enum xgene_enet_rm { #define TCPHDR_LEN 6 #define IPHDR_POS 6 #define IPHDR_LEN 6 +#define MSS_POS 20 +#define MSS_LEN 2 #define EC_POS 22 /* Enable checksum */ #define EC_LEN 1 #define ET_POS 23 /* Enable TSO */ diff --git a/drivers/net/ethernet/apm/xgene/xgene_enet_main.c b/drivers/net/ethernet/apm/xgene/xgene_enet_main.c index d992ae8..af272cb 100644 --- a/drivers/net/ethernet/apm/xgene/xgene_enet_main.c +++ b/drivers/net/ethernet/apm/xgene/xgene_enet_main.c @@ -179,6 +179,46 @@ static int xgene_enet_tx_completion(struct xgene_enet_desc_ring *cp_ring, return ret; } +static void apm_enet_init_mss_values(struct net_device *ndev) +{ + struct xgene_enet_pdata *pdata = netdev_priv(ndev); + int i; + + pdata->mss_sw[0] = 64; + pdata->mss_sw[1] = 1024; + pdata->mss_sw[2] = 1400; + pdata->mss_sw[3] = 1446; + + for (i = 0; i < NUM_MSS_REG; i++) + pdata->mac_ops->set_mss(pdata, pdata->mss_sw[i], i); +} + +static int apm_enet_get_mss_index(struct net_device *ndev, u32 new_mss) +{ + struct xgene_enet_pdata *pdata = netdev_priv(ndev); + int i; + + for (i = NUM_MSS_REG - 1; i >= 0; i--) { + if (new_mss >= pdata->mss_sw[i]) + return i; + } + + return -1; +} + +static int xgene_enet_setup_mss(struct net_device *ndev, u64 *hopinfo, u32 mss) +{ + int mss_index; + + mss_index = apm_enet_get_mss_index(ndev, mss); + if (mss_index < 0) + return mss_index; + + *hopinfo |= SET_VAL(MSS, mss_index); + + return 0; +} + static u64 xgene_enet_work_msg(struct sk_buff *skb) { struct net_device *ndev = skb->dev; @@ -227,6 +267,9 @@ static u64 xgene_enet_work_msg(struct sk_buff *skb) if (!mss || ((skb->len - hdr_len) <= mss)) goto out; + if (xgene_enet_setup_mss(ndev, &hopinfo, mss)) + return 0; + hopinfo |= SET_BIT(ET); } } else if (iph->protocol == IPPROTO_UDP) { @@ -1625,7 +1668,7 @@ static int xgene_enet_probe(struct platform_device *pdev) if (pdata->phy_mode == PHY_INTERFACE_MODE_XGMII) { ndev->features |= NETIF_F_TSO; - pdata->mss = XGENE_ENET_MSS; + apm_enet_init_mss_values(ndev); } ndev->hw_features = ndev->features; diff --git a/drivers/net/ethernet/apm/xgene/xgene_enet_main.h b/drivers/net/ethernet/apm/xgene/xgene_enet_main.h index 092fbec..20a8b59 100644 --- a/drivers/net/ethernet/apm/xgene/xgene_enet_main.h +++ b/drivers/net/ethernet/apm/xgene/xgene_enet_main.h @@ -46,7 +46,7 @@ #define NUM_PKT_BUF 64 #define NUM_BUFPOOL 32 #define MAX_EXP_BUFFS 256 -#define XGENE_ENET_MSS 1448 +#define NUM_MSS_REG 4 #define XGENE_MIN_ENET_FRAME_SIZE 60 #define XGENE_MAX_ENET_IRQ 16 @@ -141,7 +141,7 @@ struct xgene_mac_ops { void (*tx_disable)(struct xgene_enet_pdata *pdata); void (*rx_disable)(struct xgene_enet_pdata *pdata); void (*set_mac_addr)(struct xgene_enet_pdata *pdata); - void (*set_mss)(struct xgene_enet_pdata *pdata); + void (*set_mss)(struct xgene_enet_pdata *pdata, u16 mss, u8 index); void (*link_state)(struct work_struct *work); }; @@ -208,7 +208,7 @@ struct xgene_enet_pdata { u8 eth_bufnum; u8 bp_bufnum; u16 ring_num; - u32 mss; + u32 mss_sw[NUM_MSS_REG]; u8 tx_delay; u8 rx_delay; }; diff --git a/drivers/net/ethernet/apm/xgene/xgene_enet_xgmac.c b/drivers/net/ethernet/apm/xgene/xgene_enet_xgmac.c index ba030dc..cb9f681 100644 --- a/drivers/net/ethernet/apm/xgene/xgene_enet_xgmac.c +++ b/drivers/net/ethernet/apm/xgene/xgene_enet_xgmac.c @@ -184,9 +184,24 @@ static void xgene_xgmac_set_mac_addr(struct xgene_enet_pdata *pdata) xgene_enet_wr_mac(pdata, HSTMACADR_MSW_ADDR, addr1); } -static void xgene_xgmac_set_mss(struct xgene_enet_pdata *pdata) +static void xgene_xgmac_set_mss(struct xgene_enet_pdata *pdata, u16 mss, + u8 index) { - xgene_enet_wr_csr(pdata, XG_TSIF_MSS_REG0_ADDR, pdata->mss); + bool reg_index; + u32 data; + + xgene_enet_rd_csr(pdata, XG_TSIF_MSS_REG0_ADDR, &data); + reg_index = (index < 2) ? 0 : 1; + + if (!(index & 0x1)) { + data &= 0xffff0000; + data |= mss; + } else { + data &= 0xffff; + data |= (mss << 16); + } + + xgene_enet_wr_csr(pdata, XG_TSIF_MSS_REG0_ADDR + reg_index * 4, data); } static u32 xgene_enet_link_status(struct xgene_enet_pdata *pdata) @@ -210,7 +225,6 @@ static void xgene_xgmac_init(struct xgene_enet_pdata *pdata) xgene_enet_wr_mac(pdata, AXGMAC_CONFIG_1, data); xgene_xgmac_set_mac_addr(pdata); - xgene_xgmac_set_mss(pdata); xgene_enet_rd_csr(pdata, XG_RSIF_CONFIG_REG_ADDR, &data); data |= CFG_RSIF_FPBUFF_TIMEOUT_EN;