From patchwork Wed Dec 21 15:25:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Schneider-Pargmann X-Patchwork-Id: 35413 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp3586966wrn; Wed, 21 Dec 2022 07:28:39 -0800 (PST) X-Google-Smtp-Source: AMrXdXvTV+Dc09+nd/zCYdqxGgX/i70xqDV2G5aeJfy8vPero6496Yyv+5GXD0rmb55MKzYDX/BQ X-Received: by 2002:a17:90a:138b:b0:21a:dc1:e805 with SMTP id i11-20020a17090a138b00b0021a0dc1e805mr2454384pja.31.1671636518837; Wed, 21 Dec 2022 07:28:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671636518; cv=none; d=google.com; s=arc-20160816; b=CRyQ9Lf+w4EPY8LsiOwtSmBpvRnu3NvQ4AntU/SYO/0SjqVElJwEg7fHfUjAL3Vvf2 KxUEKTxjIAMpMghYOvUZilP10Qt/K3ec9mTRDASkoHHyWGAo+eUzo9ekCxV+2BGr28Na JKizQCOWfVg9Tf5FfcQaMM2eoC7cZSiY/+aLBCGVt0imGO1Qpm2CXGuP1BktWE/Zu/pY 3aUmewgR2NmXrOBI4oKyXD4UHKU/xjgUusNgpGDSnjZRELx7zwXSHhBeu6PsgbfN2mwD ddkrWlRx7wgfQs/9sXCaBPX3uO3XaLnlSa0J1rArbdAhKLc5286vp+OxVNYJBXiMnGDZ 3lxQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nb6-20020a17090b35c600b00225a710a560si723412pjb.73.2022.12.21.07.28.25; Wed, 21 Dec 2022 07:28:38 -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 + 99 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752837933948355758?= X-GMAIL-MSGID: =?utf-8?q?1752837933948355758?= 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);