Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp5831024rwj; Wed, 21 Dec 2022 07:33:59 -0800 (PST) X-Google-Smtp-Source: AMrXdXvyXb9ZGA+osyFPeBwDCPUQkMdupFhyByDS44BtkVL0dHFTehuQd+Xk+u1XQrJgNEnFq7xa X-Received: by 2002:a17:906:18e2:b0:7c1:4bb:b157 with SMTP id e2-20020a17090618e200b007c104bbb157mr6027250ejf.4.1671636839397; Wed, 21 Dec 2022 07:33:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671636839; cv=none; d=google.com; s=arc-20160816; b=yqUFy4OWzwTo5ay03Z/fw9RLLqiQUqW2XK6yMfA4hzbeX3OQVvr+fzIiDZc3L+UGah DGBebEItAEw79n17N4M771wiBk+QaJg7o8z8GxknMMyf2Bw/75en8RMP5lOJY98ODWNs gJ3pHqeoxF+Hn2SOkG8YqHJj0TaDY/rXwETMYdEbu11F8zbhvYr2oBludrYK+Znxlvpg uGAsaGQPwzB5ZPhDn8vtUzo1CboeHAiqrWfU95trCc6QL7vvGh0so82rVF+ot7YaB9ZL J3tWJgHYcFP1mOlf7tEzuFeAZ9R7cVh66Ye2eUfOEbi1TnjVvcDsQRBAHZWqUWYZuUdm oXzw== 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=gcS8xyo2Dgj5yMo5Xr3Z635PKRFPJKOjB+bkL8yToDY=; b=CzOxGLXxtzcqdVGZwR0m03d2xQs5q/v6ByX3W8qr38DO8Y8WSvnSfspjSDah61h1wn hwLOexXM8zeF6/81umj2+lMRqdU+WvfzF6duTYaQUAc/wCTqL1mQBLl9V1zEbNd6+ryb yK24L+1Ug62nv6wyGzORPZHkTKSFJGmdSpLjBLFoufnttPQ26NjkLIZy1vCTWWCPCoLw 7cypRc7ogs1xajXsVDqY5BfzK/yelzK9gTUr2HARIyIzwNxc9LFoA4q4++m5Ny60oZet LIe/fYfdxq59PayU9zY0CzXwssFo6oQgH+9nKv4I8VyEfnTkZUBLEgo1vnOqM7kZ4IDF AgXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=CFhgTNct; 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 dt17-20020a170907729100b008241a5eece4si7600649ejc.102.2022.12.21.07.33.43; Wed, 21 Dec 2022 07:33:59 -0800 (PST) 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.20210112.gappssmtp.com header.s=20210112 header.b=CFhgTNct; 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 S234865AbiLUP1S (ORCPT + 69 others); Wed, 21 Dec 2022 10:27:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234720AbiLUP0M (ORCPT ); Wed, 21 Dec 2022 10:26:12 -0500 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDA92248FD for ; Wed, 21 Dec 2022 07:25:55 -0800 (PST) Received: by mail-ed1-x52f.google.com with SMTP id m21so11988893edc.3 for ; Wed, 21 Dec 2022 07:25:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; 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=gcS8xyo2Dgj5yMo5Xr3Z635PKRFPJKOjB+bkL8yToDY=; b=CFhgTNctTBBcpXqMmSekbNfE4brWtUHR39nIQAD56RUSUjL+/48SuhLR8BchvSIV1s 6ZOl2Y78SE8EpANS3lUArmq8DmQUFmd+0cPr0s2cgYpd8LIAeUSi6412yP54iShKCeae CX69FgzLGlI+1+fRiFJg5kPaWsAjkmS9qv0dT8z2visvyC/xYgd0je33bNpTUSNxFoz1 zthoX2Y6BI3H7V6KJ7yq8hZ+O7/8qEomECFVJol1hJjQ6cfTzq1yiYveTb//xbwudOHk li1e0q3ro7m6W4OMKGpAZQRsiA3gU/dOF2AK24ZssjnQKyYycCfXO6PtlHesoPIzyuol xrJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=gcS8xyo2Dgj5yMo5Xr3Z635PKRFPJKOjB+bkL8yToDY=; b=w5GB94usXrAA3t4zKCIcVU9u1tDDpLEMjFs8j8nMEKW3bJm3JAptEHRUzYBA2rOwVS 8QvUnpzyaj09LljV4Q0Y+suz6nt4yYFUeLdPq7dugQaT70hesfhDbuQ0R8WWUBJy12Qc OwlW6wUxGe8SU9Z2Uf2YWXerVqE6zarPkMReTKSHFhsz5qLCbu7WgZeyasZJLw8mDnqo uXlo6j4g9R4FCQWRmDR7U7Zg6v6vCcZxxXab44o+ntexDjqb9vJbumxmZSv+3Tpk/tFl sLPb+3KhMPtrzFwyoudseQS8TR0GMwtpodg7GAmHTA2YtFrGn6CdXVI2l8EzBxsTJZmS e8hw== X-Gm-Message-State: AFqh2kpeA7TnwrwmZGZj5j5yWiaq1K72Yt97P5Nc5kD9uET0hh3ZOg9W 8zHYJLnvJEE4Wo3YDgZAh+WsAidyn9InCnms X-Received: by 2002:a05:6402:24a0:b0:467:7c73:4805 with SMTP id q32-20020a05640224a000b004677c734805mr6673498eda.5.1671636355577; Wed, 21 Dec 2022 07:25:55 -0800 (PST) Received: from blmsp.fritz.box ([2001:4091:a245:805c:8713:84e4:2a9e:cbe8]) by smtp.gmail.com with ESMTPSA id n19-20020aa7c793000000b0045cf4f72b04sm7105428eds.94.2022.12.21.07.25.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Dec 2022 07:25:55 -0800 (PST) From: Markus Schneider-Pargmann To: Marc Kleine-Budde , Chandrasekar Ramakrishnan , Wolfgang Grandegger Cc: Vincent MAILHOL , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Markus Schneider-Pargmann Subject: [PATCH 16/18] can: m_can: Use tx_fifo_in_flight for netif_queue control Date: Wed, 21 Dec 2022 16:25:35 +0100 Message-Id: <20221221152537.751564-17-msp@baylibre.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221221152537.751564-1-msp@baylibre.com> References: <20221221152537.751564-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 autolearn=ham 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 | 58 +++++++++++------------------------ 1 file changed, 18 insertions(+), 40 deletions(-) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index 90c9ff474149..076fa60317c2 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -369,16 +369,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); @@ -1064,6 +1054,8 @@ static int m_can_echo_tx_event(struct net_device *dev) ack_fgi)); spin_lock(&cdev->tx_handling_spinlock); + if (cdev->tx_fifo_in_flight >= cdev->nr_tx_ops && processed > 0) + netif_wake_queue(cdev->net); cdev->tx_fifo_in_flight -= processed; spin_unlock(&cdev->tx_handling_spinlock); @@ -1167,10 +1159,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); } } @@ -1677,7 +1665,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; int putidx; @@ -1733,24 +1720,6 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev, char buf[TXB_ELEMENT_SIZE]; /* 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; @@ -1787,11 +1756,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; @@ -1830,10 +1794,16 @@ static netdev_tx_t m_can_start_peripheral_xmit(struct m_can_classdev *cdev, return NETDEV_TX_OK; } - netif_stop_queue(cdev->net); - spin_lock(&cdev->tx_handling_spinlock); ++cdev->tx_fifo_in_flight; + if (cdev->tx_fifo_in_flight >= cdev->nr_tx_ops) { + netif_stop_queue(cdev->net); + if (cdev->tx_fifo_in_flight > cdev->nr_tx_ops) { + netdev_err(cdev->net, "hard_xmit called while TX FIFO full\n"); + spin_unlock(&cdev->tx_handling_spinlock); + return NETDEV_TX_BUSY; + } + } spin_unlock(&cdev->tx_handling_spinlock); m_can_tx_queue_skb(cdev, skb); @@ -1846,6 +1816,14 @@ static netdev_tx_t m_can_start_fast_xmit(struct m_can_classdev *cdev, { spin_lock(&cdev->tx_handling_spinlock); ++cdev->tx_fifo_in_flight; + if (cdev->tx_fifo_in_flight >= cdev->nr_tx_ops) { + netif_stop_queue(cdev->net); + if (cdev->tx_fifo_in_flight > cdev->nr_tx_ops) { + netdev_err(cdev->net, "hard_xmit called while TX FIFO full\n"); + spin_unlock(&cdev->tx_handling_spinlock); + return NETDEV_TX_BUSY; + } + } spin_unlock(&cdev->tx_handling_spinlock); return m_can_tx_handler(cdev, skb); -- 2.38.1