Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp449520ybv; Wed, 19 Feb 2020 02:55:00 -0800 (PST) X-Google-Smtp-Source: APXvYqzAIkiOoLQ+jgFsXEY/xZJJrG0j2Z3iLXvg9sOWfKVtc9EO12RnwGwGyScr6fmxcR7WQtZi X-Received: by 2002:a05:6830:1d4:: with SMTP id r20mr5018319ota.107.1582109699949; Wed, 19 Feb 2020 02:54:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582109699; cv=none; d=google.com; s=arc-20160816; b=ls6H8FyiU4btWKbtTOb60Qg7DUjcp0yVkQYMGd54ZxaM67LU0s+0+KKd/cI2uh3wcF zBMosrTBfybQCu4HgNCOy4tPldreTXEW1sMFdhENp1FJjgrIcgg0MfLU8emNozJ/kH6K mbzyWrchmEzJ5KOD8fuHOEdkTJTapjDjwN9VeqBUsHUppuHzwp1/glr4OfXyGcuWQyqe Lsl0+nH6mocXzfCIhGwl2JKUVc4125+X8/h9xQulmUc/MODyZy7A7vo6u5x6mfnHW88n rFgiI4K+MN6EeL6a3So3w6Wg2Okm77ajUEBXAH36e66irsIaKxYr7QvyMIVX6xf2JVye hYkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=58XYs8C6g/w78OkWpqEWdhjO/xmxHii1sQgIqmMpU/0=; b=ykf5xU/F1MNsX9faA11yD/WrlyeKIK6ikETB7nMUdWYFTdQUUemIz0oeTvvFNsPS5f PRz8FNQBc39Rw/KMDnRJZMaESNs/HcuhfkmHVnHrsV9xuP6r9wFyG6t7LfNB/YNmkuep znHHl6uESjYDr5aQIGSof9E2TtAx5BDIgLPBknT1RnVNAH2uxr+5IWX4DQ6UDHsly4tc 218nbLbAljxRk0Kghx4nxQKts7WeOLyBu/CFOXJnSjriMcYwLRL6yArSyAtQM+ZHBfod EENt9rmLOeoMYlHDjklasvp/rQcIW81PBT+ClqwyQlXiZvBELDCqKWG8Mwrz0lTWOLAW eiRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@geanix.com header.s=first header.b=ToWkT2Zf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=geanix.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l23si837411otj.302.2020.02.19.02.54.48; Wed, 19 Feb 2020 02:54:59 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@geanix.com header.s=first header.b=ToWkT2Zf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=geanix.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727283AbgBSKy2 (ORCPT + 99 others); Wed, 19 Feb 2020 05:54:28 -0500 Received: from first.geanix.com ([116.203.34.67]:57166 "EHLO first.geanix.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726469AbgBSKy1 (ORCPT ); Wed, 19 Feb 2020 05:54:27 -0500 Received: from localhost (_gateway [172.20.0.1]) by first.geanix.com (Postfix) with ESMTPSA id 39F58C002E; Wed, 19 Feb 2020 10:54:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=geanix.com; s=first; t=1582109664; bh=VYzKQ++/LYo+JsJQba43uJIM0DxFk+Tyra4KIcUC6ok=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ToWkT2ZfnJ5WjreqQSliA3cmR8LK8Opg/rzbo23501MrL/0av9f+fF45I1FkFzNCe Xlcru5V6JEsg6nus6IyJMIqY1yDywGvWl7JuzR04Rf2vABGW3kvmXwSv+7syjwY/VP CoR1g+iUNtgxJnjSwAi3nZJWA9u5LCXey2nTLwwihHWzayBJ7xQzkVdhvsz2YQIlQA hFrLtcoo95giSTQF85ff7XcGZ9ZAQ9zHQrrHTQaSzUN7mPZya80WSiKQC9c2fYKbSU ZraIHf3N1o041Z1L5bgI9YCYl7bbzMqYJbeh4cX1j4qVMfGA2SHKRtfmSK3/mmfgS1 PpJjCpfdJ5/jw== From: Esben Haabendal To: netdev@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Andrew Lunn , "David S . Miller" , Michal Simek , =?UTF-8?q?Petr=20=C5=A0tetiar?= Subject: [PATCH net 4/4] net: ll_temac: Handle DMA halt condition caused by buffer underrun Date: Wed, 19 Feb 2020 11:54:23 +0100 Message-Id: X-Mailer: git-send-email 2.25.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=4.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,UNPARSEABLE_RELAY,URIBL_BLOCKED autolearn=disabled version=3.4.3 X-Spam-Checker-Version: SpamAssassin 3.4.3 (2019-12-06) on eb9da72b0f73 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The SDMA engine used by TEMAC halts operation when it has finished processing of the last buffer descriptor in the buffer ring. Unfortunately, no interrupt event is generated when this happens, so we need to setup another mechanism to make sure DMA operation is restarted when enough buffers have been added to the ring. Fixes: 92744989533c ("net: add Xilinx ll_temac device driver") Signed-off-by: Esben Haabendal --- drivers/net/ethernet/xilinx/ll_temac.h | 3 ++ drivers/net/ethernet/xilinx/ll_temac_main.c | 47 ++++++++++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/xilinx/ll_temac.h b/drivers/net/ethernet/xilinx/ll_temac.h index 99fe059e5c7f..53fb8141f1a6 100644 --- a/drivers/net/ethernet/xilinx/ll_temac.h +++ b/drivers/net/ethernet/xilinx/ll_temac.h @@ -380,6 +380,9 @@ struct temac_local { /* DMA channel control setup */ u32 tx_chnl_ctrl; u32 rx_chnl_ctrl; + u8 coalesce_count_rx; + + struct delayed_work restart_work; }; /* Wrappers for temac_ior()/temac_iow() function pointers above */ diff --git a/drivers/net/ethernet/xilinx/ll_temac_main.c b/drivers/net/ethernet/xilinx/ll_temac_main.c index 255207f2fd27..90b486becb5b 100644 --- a/drivers/net/ethernet/xilinx/ll_temac_main.c +++ b/drivers/net/ethernet/xilinx/ll_temac_main.c @@ -51,6 +51,7 @@ #include #include #include +#include #include #include #include @@ -920,6 +921,17 @@ temac_start_xmit(struct sk_buff *skb, struct net_device *ndev) return NETDEV_TX_OK; } +static int ll_temac_recv_buffers_available(struct temac_local *lp) +{ + int available; + + if (!lp->rx_skb[lp->rx_bd_ci]) + return 0; + available = 1 + lp->rx_bd_tail - lp->rx_bd_ci; + if (available <= 0) + available += RX_BD_NUM; + return available; +} static void ll_temac_recv(struct net_device *ndev) { @@ -990,6 +1002,18 @@ static void ll_temac_recv(struct net_device *ndev) lp->rx_bd_ci = 0; } while (rx_bd != lp->rx_bd_tail); + /* DMA operations will halt when the last buffer descriptor is + * processed (ie. the one pointed to by RX_TAILDESC_PTR). + * When that happens, no more interrupt events will be + * generated. No IRQ_COAL or IRQ_DLY, and not even an + * IRQ_ERR. To avoid stalling, we schedule a delayed work + * when there is a potential risk of that happening. The work + * will call this function, and thus re-schedule itself until + * enough buffers are available again. + */ + if (ll_temac_recv_buffers_available(lp) < lp->coalesce_count_rx) + schedule_delayed_work(&lp->restart_work, HZ / 1000); + /* Allocate new buffers for those buffer descriptors that were * passed to network stack. Note that GFP_ATOMIC allocations * can fail (e.g. when a larger burst of GFP_ATOMIC @@ -1045,6 +1069,18 @@ static void ll_temac_recv(struct net_device *ndev) spin_unlock_irqrestore(&lp->rx_lock, flags); } +/* Function scheduled to ensure a restart in case of DMA halt + * condition caused by running out of buffer descriptors. + */ +static void ll_temac_restart_work_func(struct work_struct *work) +{ + struct temac_local *lp = container_of(work, struct temac_local, + restart_work.work); + struct net_device *ndev = lp->ndev; + + ll_temac_recv(ndev); +} + static irqreturn_t ll_temac_tx_irq(int irq, void *_ndev) { struct net_device *ndev = _ndev; @@ -1137,6 +1173,8 @@ static int temac_stop(struct net_device *ndev) dev_dbg(&ndev->dev, "temac_close()\n"); + cancel_delayed_work_sync(&lp->restart_work); + free_irq(lp->tx_irq, ndev); free_irq(lp->rx_irq, ndev); @@ -1258,6 +1296,7 @@ static int temac_probe(struct platform_device *pdev) lp->dev = &pdev->dev; lp->options = XTE_OPTION_DEFAULTS; spin_lock_init(&lp->rx_lock); + INIT_DELAYED_WORK(&lp->restart_work, ll_temac_restart_work_func); /* Setup mutex for synchronization of indirect register access */ if (pdata) { @@ -1364,6 +1403,7 @@ static int temac_probe(struct platform_device *pdev) */ lp->tx_chnl_ctrl = 0x10220000; lp->rx_chnl_ctrl = 0xff070000; + lp->coalesce_count_rx = 0x07; /* Finished with the DMA node; drop the reference */ of_node_put(dma_np); @@ -1395,11 +1435,14 @@ static int temac_probe(struct platform_device *pdev) (pdata->tx_irq_count << 16); else lp->tx_chnl_ctrl = 0x10220000; - if (pdata->rx_irq_timeout || pdata->rx_irq_count) + if (pdata->rx_irq_timeout || pdata->rx_irq_count) { lp->rx_chnl_ctrl = (pdata->rx_irq_timeout << 24) | (pdata->rx_irq_count << 16); - else + lp->coalesce_count_rx = pdata->rx_irq_count; + } else { lp->rx_chnl_ctrl = 0xff070000; + lp->coalesce_count_rx = 0x07; + } } /* Error handle returned DMA RX and TX interrupts */ -- 2.25.0