Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp9063691rwd; Wed, 21 Jun 2023 02:28:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6DMa6mUZPHVXu8JILuxHkS0/s5ca3kkIBIvZZLc8hOr025t6kSVdV86jrpbds8c8G4emKD X-Received: by 2002:a17:902:e544:b0:1b6:7c9a:3a53 with SMTP id n4-20020a170902e54400b001b67c9a3a53mr4620705plf.67.1687339735851; Wed, 21 Jun 2023 02:28:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687339735; cv=none; d=google.com; s=arc-20160816; b=qKCJUw+9SdOqgckLn5SStMiu/zYinMIL6WpOJEdu16s8E8Hhf4zLhkcSXPuJ8+MXDh 1m8a0yWZmqR6PXwQ0mV48eqYOfZ4Dp3B8ZDEQo9gNei/4P7sU2qM2idz3VLIA0DfN9Q/ NkNGExi9V56t/SKPwzPK7SvMZy1vda19nXVOJDNO5Zw0WGC+QoN+uRrAVQmztvq4dKSA DartdytA2L3+C6KMlSmWn9FaUPWd57m/lpOHkJvzAc7hYU9Pf3FhBmTUV+vUh7NZPRqX Nlz5Lk+2OwM05mWvPMK7WghqdlWCoHZ8k58536Lc77mSJhtz2xrSprlvcI6sY1LKGF/v kiDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=P6rWS7bREqVUPkH2+6lOc5shnNXmaz1zo3KIcC701tw=; b=feJXeWVZt+uqQTphpJtV1fUzvkvZdRE5fUhE7Y84aTnXFfTRsTZSVq0LrU+IpRHJlc MxYn+MC3NBJxbT6b9c5930Xf/XOnzu24eGGRptaVfCoVDeLpPiTPkMUzPLFXdMve1Jn4 mIPzvM61q0JoS3aQOkLLFFnIeGAu/kDmecaN8IvVktE7fm1TZVOStcib9zbP3BvTjBB4 tpdr/0SjD8eF4Zo0Vi5//eychxt3zDnIG24ghyAejkqj1QlC0f+Ft8GkFUjiV1aGp70r b437VtCFsy0FGHrP4NjwPeidz9gVm8hXdB3Od1hEYkCqN++kZI28xnOQTX3KKlDJyBIh H84w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20221208.gappssmtp.com header.s=20221208 header.b=IdEDUigz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e10-20020a170902e0ca00b001adb857fc79si3596807pla.105.2023.06.21.02.28.43; Wed, 21 Jun 2023 02:28:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20221208.gappssmtp.com header.s=20221208 header.b=IdEDUigz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232031AbjFUJZO (ORCPT + 99 others); Wed, 21 Jun 2023 05:25:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230414AbjFUJY1 (ORCPT ); Wed, 21 Jun 2023 05:24:27 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4AB01BD0 for ; Wed, 21 Jun 2023 02:24:08 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-3110a5f2832so5352495f8f.1 for ; Wed, 21 Jun 2023 02:24:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20221208.gappssmtp.com; s=20221208; t=1687339447; x=1689931447; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=P6rWS7bREqVUPkH2+6lOc5shnNXmaz1zo3KIcC701tw=; b=IdEDUigz2e/1Ljo91fcbJy4qTNc9c2A1u+FPRbyB8azGWrnWOlz8CI9bAgex0hX5Ji lAYk97/j3J9lMM1ctK9UHR2RWC3j355Hhwpm8vmbM9ZQEBWPuiVzcIkVjSA9gAi6fIYG O8EMOLbEGToTe7G4tBI6j58uRHEIQusPTHaqqKISVYBNirpiJiCylWAGn7MYYkKD+LYA lg7YIDwv9hXrGUcqEWn9z/ER8DCRNlFuLykGE/ScENkQxi32fE7segAodG6Za+A9uxf9 UPbJRYKHPbZ5ByaCIzmM/wKjXLyKB0yo1RwawzcljcSnpmlFhMZJvyD8ydmuzfH8TJyf NQNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687339447; x=1689931447; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=P6rWS7bREqVUPkH2+6lOc5shnNXmaz1zo3KIcC701tw=; b=ccFByTB9zpuwt1E9b4cqiUBUGOd+5sS1VUZsVZ8cGuKioVJFfHsDRmWxTtTeOCL0BB d7f3H8YlCmlquFEKi+xj657LZ5tjz7xjD6D0OdtvIg7LOTw32QyXzmmeVKAWKUjoV1Kk cW1jh/mG2W4ljdqj3mUcfFM9J9lCwUsXIigOkQ51lXCk8+DgZqYhSt7ipwPLbP4BEG4Q +oE6icnvJ4TezP5nF1IqWrCs1FCkTttk+HSSaEKvQRUmVcO807BCj2gNL0t5f3bFWJ/Y xAJZ+pKEP8gwZ061xL2rnrBn1N3+WzqShFCYCOQDOQbnzUXE51uFGiPNJsI5bCSEpg+l e6Gg== X-Gm-Message-State: AC+VfDyph6OeW3A5yeuWuL8eZgCRByTTQ4c5f5QB0PZZO5MJ/CfJNiRX rh1LwaFPje+pZ3Ko/nnLpahE5Q== X-Received: by 2002:adf:f409:0:b0:311:3eaf:f011 with SMTP id g9-20020adff409000000b003113eaff011mr7583058wro.19.1687339447165; Wed, 21 Jun 2023 02:24:07 -0700 (PDT) Received: from blmsp.fritz.box ([2001:4091:a247:82fa:b762:4f68:e1ed:5041]) by smtp.gmail.com with ESMTPSA id i11-20020adffdcb000000b002fda1b12a0bsm4022115wrs.2.2023.06.21.02.24.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jun 2023 02:24:06 -0700 (PDT) From: Markus Schneider-Pargmann To: Marc Kleine-Budde , Chandrasekar Ramakrishnan , Wolfgang Grandegger Cc: Vincent MAILHOL , Simon Horman , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Julien Panis , Markus Schneider-Pargmann Subject: [PATCH v4 10/12] can: m_can: Use tx_fifo_in_flight for netif_queue control Date: Wed, 21 Jun 2023 11:23:48 +0200 Message-Id: <20230621092350.3130866-11-msp@baylibre.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230621092350.3130866-1-msp@baylibre.com> References: <20230621092350.3130866-1-msp@baylibre.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The network queue is currently always stopped in start_xmit and continued in the interrupt handler. This is not possible anymore if we want to keep multiple transmits in flight in parallel. Use the previously introduced tx_fifo_in_flight counter to control the network queue instead. This has the benefit of not needing to ask the hardware about fifo status. This patch stops the network queue in start_xmit if the number of transmits in flight reaches the size of the fifo and wakes up the queue from the interrupt handler once the transmits in flight drops below the fifo size. This means any skbs over the limit will be rejected immediately in start_xmit (it shouldn't be possible at all to reach that state anyways). The maximum number of transmits in flight is the size of the fifo. Signed-off-by: Markus Schneider-Pargmann --- drivers/net/can/m_can/m_can.c | 85 +++++++++++------------------------ 1 file changed, 26 insertions(+), 59 deletions(-) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index 3353fd9fb3a2..38bdab9b5cd6 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -376,16 +376,6 @@ m_can_txe_fifo_read(struct m_can_classdev *cdev, u32 fgi, u32 offset, u32 *val) return cdev->ops->read_fifo(cdev, addr_offset, val, 1); } -static inline bool _m_can_tx_fifo_full(u32 txfqs) -{ - return !!(txfqs & TXFQS_TFQF); -} - -static inline bool m_can_tx_fifo_full(struct m_can_classdev *cdev) -{ - return _m_can_tx_fifo_full(m_can_read(cdev, M_CAN_TXFQS)); -} - static void m_can_config_endisable(struct m_can_classdev *cdev, bool enable) { u32 cccr = m_can_read(cdev, M_CAN_CCCR); @@ -1056,17 +1046,31 @@ static void m_can_finish_tx(struct m_can_classdev *cdev, int transmitted) unsigned long irqflags; spin_lock_irqsave(&cdev->tx_handling_spinlock, irqflags); + if (cdev->tx_fifo_in_flight >= cdev->tx_fifo_size && transmitted > 0) + netif_wake_queue(cdev->net); cdev->tx_fifo_in_flight -= transmitted; spin_unlock_irqrestore(&cdev->tx_handling_spinlock, irqflags); } -static void m_can_start_tx(struct m_can_classdev *cdev) +static netdev_tx_t m_can_start_tx(struct m_can_classdev *cdev) { unsigned long irqflags; + int tx_fifo_in_flight; spin_lock_irqsave(&cdev->tx_handling_spinlock, irqflags); - ++cdev->tx_fifo_in_flight; + tx_fifo_in_flight = cdev->tx_fifo_in_flight + 1; + if (tx_fifo_in_flight >= cdev->tx_fifo_size) { + netif_stop_queue(cdev->net); + if (tx_fifo_in_flight > cdev->tx_fifo_size) { + netdev_err_once(cdev->net, "hard_xmit called while TX FIFO full\n"); + spin_unlock_irqrestore(&cdev->tx_handling_spinlock, irqflags); + return NETDEV_TX_BUSY; + } + } + cdev->tx_fifo_in_flight = tx_fifo_in_flight; spin_unlock_irqrestore(&cdev->tx_handling_spinlock, irqflags); + + return NETDEV_TX_OK; } static int m_can_echo_tx_event(struct net_device *dev) @@ -1194,7 +1198,6 @@ static irqreturn_t m_can_isr(int irq, void *dev_id) if (cdev->is_peripheral) timestamp = m_can_get_timestamp(cdev); m_can_tx_update_stats(cdev, 0, timestamp); - netif_wake_queue(dev); m_can_finish_tx(cdev, 1); } } else { @@ -1202,10 +1205,6 @@ static irqreturn_t m_can_isr(int irq, void *dev_id) /* New TX FIFO Element arrived */ if (m_can_echo_tx_event(dev) != 0) goto out_fail; - - if (netif_queue_stopped(dev) && - !m_can_tx_fifo_full(cdev)) - netif_wake_queue(dev); } } @@ -1705,20 +1704,6 @@ static int m_can_close(struct net_device *dev) return 0; } -static int m_can_next_echo_skb_occupied(struct net_device *dev, u32 putidx) -{ - struct m_can_classdev *cdev = netdev_priv(dev); - /*get wrap around for loopback skb index */ - unsigned int wrap = cdev->can.echo_skb_max; - u32 next_idx; - - /* calculate next index */ - next_idx = (++putidx >= wrap ? 0 : putidx); - - /* check if occupied */ - return !!cdev->can.echo_skb[next_idx]; -} - static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev, struct sk_buff *skb) { @@ -1728,7 +1713,6 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev, struct net_device *dev = cdev->net; struct id_and_dlc fifo_header; u32 cccr, fdflags; - u32 txfqs; int err; u32 putidx; @@ -1783,24 +1767,6 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev, } else { /* Transmit routine for version >= v3.1.x */ - txfqs = m_can_read(cdev, M_CAN_TXFQS); - - /* Check if FIFO full */ - if (_m_can_tx_fifo_full(txfqs)) { - /* This shouldn't happen */ - netif_stop_queue(dev); - netdev_warn(dev, - "TX queue active although FIFO is full."); - - if (cdev->is_peripheral) { - kfree_skb(skb); - dev->stats.tx_dropped++; - return NETDEV_TX_OK; - } else { - return NETDEV_TX_BUSY; - } - } - /* get put index for frame */ putidx = cdev->tx_fifo_putidx; @@ -1838,11 +1804,6 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev, m_can_write(cdev, M_CAN_TXBAR, (1 << putidx)); cdev->tx_fifo_putidx = (++cdev->tx_fifo_putidx >= cdev->can.echo_skb_max ? 0 : cdev->tx_fifo_putidx); - - /* stop network queue if fifo full */ - if (m_can_tx_fifo_full(cdev) || - m_can_next_echo_skb_occupied(dev, putidx)) - netif_stop_queue(dev); } return NETDEV_TX_OK; @@ -1876,14 +1837,16 @@ static void m_can_tx_queue_skb(struct m_can_classdev *cdev, struct sk_buff *skb) static netdev_tx_t m_can_start_peripheral_xmit(struct m_can_classdev *cdev, struct sk_buff *skb) { + netdev_tx_t err; + if (cdev->can.state == CAN_STATE_BUS_OFF) { m_can_clean(cdev->net); return NETDEV_TX_OK; } - netif_stop_queue(cdev->net); - - m_can_start_tx(cdev); + err = m_can_start_tx(cdev); + if (err != NETDEV_TX_OK) + return err; m_can_tx_queue_skb(cdev, skb); @@ -1893,7 +1856,11 @@ static netdev_tx_t m_can_start_peripheral_xmit(struct m_can_classdev *cdev, static netdev_tx_t m_can_start_fast_xmit(struct m_can_classdev *cdev, struct sk_buff *skb) { - m_can_start_tx(cdev); + netdev_tx_t err; + + err = m_can_start_tx(cdev); + if (err != NETDEV_TX_OK) + return err; return m_can_tx_handler(cdev, skb); } -- 2.40.1