From patchwork Thu Aug 31 08:22:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kristian Evensen X-Patchwork-Id: 808121 X-Patchwork-Delegate: pepe2k@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133; helo=bombadil.infradead.org; envelope-from=lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="EQ4ahZdW"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="g4OifWCZ"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xjb4C2N5hz9s3w for ; Thu, 31 Aug 2017 18:23:39 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Subject:Message-Id: Date:To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=EKA9G1lGgKy5q7KnCM8A+78JGuXk8wu5Itk3WsmY9N4=; b=EQ4ahZdW5hwUT4 VOR9gv9bIVwnbRNUIvdV0ddQhAbKY4UfFZaa7J1fHOo3E6wKmVfPGUn6wAct4InhTpuvKL7fgrAEt Vvrx241eKymEFKuvli3xoFyF8sCtOZDePd0O12Q3cpY33ikn4CAWmTRP9VxA2Ux+8sb9D0HcUYwT9 6JrdpMuaA20Wfq3Xls3VXnOBYB8Tu2CBcSox9ALaPFWQpd02KRUPVw6iEu4QmMQs0dU2mm2bcifYd Ip2sdRtnr8ia4ivJQ4DcThG6DkavPwXGJkYOFMcFffm6jP5I5pXn0rCupIsmlQF47paGy5pSIJ4aU Pkvg1GtgEka26UbHAlQA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dnKkx-00079t-PQ; Thu, 31 Aug 2017 08:23:19 +0000 Received: from mail-lf0-x243.google.com ([2a00:1450:4010:c07::243]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dnKkt-000776-Jr for lede-dev@lists.infradead.org; Thu, 31 Aug 2017 08:23:17 +0000 Received: by mail-lf0-x243.google.com with SMTP id h132so12209lfh.2 for ; Thu, 31 Aug 2017 01:22:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=1eVo5fRWj1w3YKUyLNvDxRA68tVuRAp9L+DYWfMCMG0=; b=g4OifWCZDnwAFrLbLxix69z+KnjajFJMf3Mvi7bt0kOwoXOhJgpyZ8T03rnZo0qlQC ca/WV1NMSoLF1n2cBOydhE0PnHsH9D+cbw6H1kQdgWarl98gpgDS6q/Szqv1kJ31SSZd GmkTMK1+FF9U7jXTLXQkWeNRMeUyhb5WBnx0sLPR91ko803whv2N4A44s+xq7serMjmA XMSmQI0+Thdgy76SSBYN3d2+4dzhMVzPNbdSh3kwS6+6U2dBQ+n6E1iJk82w9i/Ehz3t xxsT1u2/ZIWyxMyU2YneM8tlkavE8M/IsZTTDsDgSgrGfhbA1zrRWVeCXP05A6pnz7Wk jUUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=1eVo5fRWj1w3YKUyLNvDxRA68tVuRAp9L+DYWfMCMG0=; b=gUxgLRao24/LFGroGCbloq2Ri3ZZ3Y1Mf9gWQkV9oxNsRwYwTmibZbbYF4nu347k7h jV2/Dn2s17M3fbgdSRdMadQcRFIo/2BwhUdobriVzYU0XCiCViYkOvNCy7+se52GofJi xaIgtBbIlNKYnE1epgDDbqSnmwtGqHXFsCZvNhTVrTVt1EHoaeC1lHY/K6s/HhEplqEA rYHw8fXG9oGWN0pWIT2pF0s64q6OzSEka8WfYUwtU1so+KpX0slYqudVyAkRZoHHZAXj FRalHw/5eHjcrkuLJSEzbkHimINFaYx92YAHP0iJQ6REl3SiandiTyD02hs09khu7U3i +9Ew== X-Gm-Message-State: AHYfb5gsrVMPe6n99lfl5TVa35IemsQqINhMjT71Vxi+S+UyQ2fhK3FR estCPJprplfxcc1j X-Received: by 10.46.7.81 with SMTP id i17mr1882889ljd.78.1504167772710; Thu, 31 Aug 2017 01:22:52 -0700 (PDT) Received: from localhost.localdomain ([193.213.155.210]) by smtp.gmail.com with ESMTPSA id x4sm201238lfa.66.2017.08.31.01.22.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 31 Aug 2017 01:22:52 -0700 (PDT) From: Kristian Evensen To: lede-dev@lists.infradead.org Date: Thu, 31 Aug 2017 10:22:45 +0200 Message-Id: <20170831082245.22255-1-kristian.evensen@gmail.com> X-Mailer: git-send-email 2.11.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170831_012315_874143_F0791E93 X-CRM114-Status: GOOD ( 16.47 ) X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (kristian.evensen[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain Subject: [LEDE-DEV] [PATCH] ramips: Improve stability of the mt7621 switch X-BeenThere: lede-dev@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kristian Evensen MIME-Version: 1.0 Sender: "Lede-dev" Errors-To: lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The switch on the mt7621 soc seems to sometimes struggle with Ethernet pause frames. If a pause frame is received at the incorrect time, the switch will for some reason hang and no data can be sent. Most of the time, a router has to be rebooted before the switch will work again, while sometimes the switch recovers by itself. I am able to reliably trigger this error on the ZBT WG2926 and 3526 by saturating the router/switch with small (<100B) packets, or by spamming the router with pause frames while sending traffic. The error message looks something like this (and will in most cases loop over and over): [10203960.260000] mtk_soc_eth 1e100000.ethernet eth0: transmit timed out [10203960.260000] mtk_soc_eth 1e100000.ethernet eth0: dma_cfg:80000065 [10203960.270000] mtk_soc_eth 1e100000.ethernet eth0: tx_ring=0, base=0ef10000, max=512, ctx=118, dtx=118, fdx=117, next=118 [10203960.280000] mtk_soc_eth 1e100000.ethernet eth0: rx_ring=0, base=0ef12000, max=512, calc=380, drx=381 This commit works around the issue by not advertising pause frame support during auto negotiation. However, I have found at least one switch which sends pause frames anyway. In case a pause frame is sent and triggers the error, we reset all ports on the switch. This also makes the switch work properly again. Without this change, my routers would crash within 15 minutes when testing. With the change, the same test has been running for three days without any problems. Disabling pause frames is maybe not ideal, but since this error only happens when the router/switch is completely swamped, then users/protocols/applications should not notice a difference. It might even be better to drop packets right away, than to buffer them for a given time. Signed-off-by: Kristian Evensen --- .../drivers/net/ethernet/mtk/gsw_mt7621.c | 8 +++++++ .../drivers/net/ethernet/mtk/mtk_eth_soc.c | 3 +++ .../drivers/net/ethernet/mtk/mtk_eth_soc.h | 1 + .../drivers/net/ethernet/mtk/soc_mt7621.c | 26 ++++++++++++++++++++++ 4 files changed, 38 insertions(+) diff --git a/target/linux/ramips/files-4.9/drivers/net/ethernet/mtk/gsw_mt7621.c b/target/linux/ramips/files-4.9/drivers/net/ethernet/mtk/gsw_mt7621.c index 3adad48c88..9814dae8fa 100644 --- a/target/linux/ramips/files-4.9/drivers/net/ethernet/mtk/gsw_mt7621.c +++ b/target/linux/ramips/files-4.9/drivers/net/ethernet/mtk/gsw_mt7621.c @@ -186,6 +186,14 @@ static void mt7621_hw_init(struct mt7620_gsw *gsw, struct device_node *np) mt7530_mdio_w32(gsw, 0x7a74, 0x44); mt7530_mdio_w32(gsw, 0x7a7c, 0x44); + /* Disable pause frame */ + for (i = 0; i <= 4; i++) { + val = _mt7620_mii_read(gsw, i, 0x04); + pr_info("Auto-negotiate register: %u %x\n", i, val); + val &= ~BIT(10); + _mt7620_mii_write(gsw, i, 0x04, val); + } + /* turn on all PHYs */ for (i = 0; i <= 4; i++) { val = _mt7620_mii_read(gsw, i, 0); diff --git a/target/linux/ramips/files-4.9/drivers/net/ethernet/mtk/mtk_eth_soc.c b/target/linux/ramips/files-4.9/drivers/net/ethernet/mtk/mtk_eth_soc.c index 5f4afade06..de5b97a996 100644 --- a/target/linux/ramips/files-4.9/drivers/net/ethernet/mtk/mtk_eth_soc.c +++ b/target/linux/ramips/files-4.9/drivers/net/ethernet/mtk/mtk_eth_soc.c @@ -1426,6 +1426,9 @@ static void fe_reset_pending(struct fe_priv *priv) dev_close(dev); } rtnl_unlock(); + + if (priv->soc->reset_ports) + priv->soc->reset_ports(priv); } static const struct fe_work_t fe_work[] = { diff --git a/target/linux/ramips/files-4.9/drivers/net/ethernet/mtk/mtk_eth_soc.h b/target/linux/ramips/files-4.9/drivers/net/ethernet/mtk/mtk_eth_soc.h index 05f550fa26..0539ce4761 100644 --- a/target/linux/ramips/files-4.9/drivers/net/ethernet/mtk/mtk_eth_soc.h +++ b/target/linux/ramips/files-4.9/drivers/net/ethernet/mtk/mtk_eth_soc.h @@ -392,6 +392,7 @@ struct fe_soc_data { u16 val); int (*mdio_read)(struct mii_bus *bus, int phy_addr, int phy_reg); void (*mdio_adjust_link)(struct fe_priv *priv, int port); + void (*reset_ports)(struct fe_priv *priv); void *swpriv; u32 pdma_glo_cfg; diff --git a/target/linux/ramips/files-4.9/drivers/net/ethernet/mtk/soc_mt7621.c b/target/linux/ramips/files-4.9/drivers/net/ethernet/mtk/soc_mt7621.c index ce41b342e7..8f9dc35875 100644 --- a/target/linux/ramips/files-4.9/drivers/net/ethernet/mtk/soc_mt7621.c +++ b/target/linux/ramips/files-4.9/drivers/net/ethernet/mtk/soc_mt7621.c @@ -16,6 +16,7 @@ #include #include #include +#include #include @@ -157,6 +158,30 @@ static void mt7621_set_mac(struct fe_priv *priv, unsigned char *mac) spin_unlock_irqrestore(&priv->page_lock, flags); } +static void mt7621_reset_ports(struct fe_priv *priv) +{ + struct mt7620_gsw *gsw = priv->soc->swpriv; + u8 i; + u32 val; + + /* Disable all ports */ + for (i = 0; i <= 4; i++) { + val = _mt7620_mii_read(gsw, i, 0x0); + val |= BIT(11); + _mt7620_mii_write(gsw, i, 0x0, val); + } + + /* Allow ports a (short) time to settle */ + udelay(1000); + + /* Enable ports */ + for (i = 0; i <= 4; i++) { + val = _mt7620_mii_read(gsw, i, 0); + val &= ~BIT(11); + _mt7620_mii_write(gsw, i, 0, val); + } +} + static struct fe_soc_data mt7621_data = { .init_data = mt7621_init_data, .reset_fe = mt7621_fe_reset, @@ -175,6 +200,7 @@ static struct fe_soc_data mt7621_data = { .mdio_read = mt7620_mdio_read, .mdio_write = mt7620_mdio_write, .mdio_adjust_link = mt7620_mdio_link_adjust, + .reset_ports = mt7621_reset_ports, }; const struct of_device_id of_fe_match[] = {