From patchwork Wed Mar 15 11:05:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Schneider-Pargmann X-Patchwork-Id: 70145 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2268154wrd; Wed, 15 Mar 2023 04:22:43 -0700 (PDT) X-Google-Smtp-Source: AK7set9n3xCJk9OwUgFgZT8aWmbIwsDk9j5WATi1blT2PX12kCX6BLHTF1qgcAc6qx1sW5BT3Wkx X-Received: by 2002:a17:902:d486:b0:19c:a866:6a76 with SMTP id c6-20020a170902d48600b0019ca8666a76mr2499038plg.42.1678879363572; Wed, 15 Mar 2023 04:22:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678879363; cv=none; d=google.com; s=arc-20160816; b=ZRWiGJjLA53XGhQlW6+QzyYJ+TEcoSwKp2jswEHqMD7UNeWPNYVzc+dVZ6NaWVY100 xdU9hvh/lNjsSYpPVg4muIrEKO7HPasOtiBPowNXMbc56lJ6aoS5kr7huLYF+KwTmjaH KRuU7TwuVhP7c8OTmZvAUNtXpV0H52HEsp+NO4iioyL3UTWaoD4VToStdif4SiqAOu5y kLUQD6/rxSPcJBnC3fUP4WJXJKpR/Vcy69FOtZeK/Cm5S/DY73F2ZN47VMZCVjggaW2J SA1OB2vr+m+g60L9pe8TN21S1T8xd3QO3DmySA/0Xol5EYYSbklUAWJXg6KSdOHsT+zp GlyA== 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=G+EKCJNwn+0jFeGZ8T3IHbGM+D1iiujj1KVvmsIMQMw=; b=S1KTUvnsV1hyqiR/SSQpbhBPPGlajvwxSvciIrv9ovRkgU/unG0WLxyhWCv07N2qzn 1jK/bMwuL5tx1utk4k1CXXroQxXuE+r6qGN/erNXdDlDdRxcgyIRt7Xg391BsWCHKl/n mJ85Htj5tJ32GIHEkTR+YQEWvU4HguReMko8TaTgsVPWjqhH3UDLSWpjf2rHumk8fekZ momMM0pNi7Bwxi63dKJygf0r4ZI9t1rH3iEZksT5a8LuFo32yyjWjUN2P5kkMVzjGWHi CTqpHng6clmm+8z9fl/Oq6IhMhXC2vZIKxah3N+9HvNOYVMgLVW3bjOHS/pxBOTAX8lr Q0HA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=8DPRIzT+; 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 l19-20020a170902eb1300b001a05347d088si5077022plb.201.2023.03.15.04.22.28; Wed, 15 Mar 2023 04:22:43 -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.20210112.gappssmtp.com header.s=20210112 header.b=8DPRIzT+; 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 S232018AbjCOLHW (ORCPT + 99 others); Wed, 15 Mar 2023 07:07:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231714AbjCOLGo (ORCPT ); Wed, 15 Mar 2023 07:06:44 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE41F80E25 for ; Wed, 15 Mar 2023 04:06:36 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id bh21-20020a05600c3d1500b003ed1ff06fb0so904332wmb.3 for ; Wed, 15 Mar 2023 04:06:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; t=1678878396; 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=G+EKCJNwn+0jFeGZ8T3IHbGM+D1iiujj1KVvmsIMQMw=; b=8DPRIzT+e47FNhbQ2zSHDerldk8oZzC4RC0B2tmmmy1Kj1e0ivYvTz59s6Q18Xk4HX ZVRJ8qt/wGDm+18q2CC7Q1ZgnD/mOgeUfc1krkPQNCrN4ioOgn29i3U9UMESAEzWWtBy UTqZr/0c3BwBn0sAgC9Rm/W56WpvNcBJuDbjg/DZwDLTNJ3jsRnCqPClr255VJkVnyw6 RKLDU7Whlixf80Cb0KAniBGMYyy8/Bg7qelqNGw9MImxh3vEhfZBaaPv4xd5gGdgGT1c JNbQo6HCJIUMj2ro0U4c44qoNIZ+fitTZaU2tM20K5/WUR3WEYdmDUuH0VnedMa2fnTR p8Og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678878396; 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=G+EKCJNwn+0jFeGZ8T3IHbGM+D1iiujj1KVvmsIMQMw=; b=zXxAIaV2fxi8+n/2pBwXtfY2laqZEm901hzXM091oYzKQyb+qJgkhKVsGbdQcs/3RL TE8vlh3oDIEcK9CZCOWZDXvYps0NstEoaQkcmaWNfTVELLO06IrCSr2F/LXPuzDw97Ow 2FKF/Wq2jnPWBRvlcjkgLw6mektSN4vGPTx4wBtxzm0mSWEZD8XiF5h1r4X1ElZAXFmX 7VTCu0JZKYHlQTpGXHoOhiZWf9B20Ae10kjTXrRIMf/O6E5gbUMn7k+yrFgy/J8kCeON zjMNOUOHQgx4NGWa8PC+36/4ovsUc1Dp6hII0Pwrel2ZaS0Uh2pWG/V/41cNXWctq9gy E1Fw== X-Gm-Message-State: AO0yUKWtFEjs+ka8Mgm3i8/EwaQeHkxEMQ8PvvRodaA9CNvGxvgNbaxd xOK2tQjMB4AM8tXnsuv5KsgQ4w== X-Received: by 2002:a05:600c:154b:b0:3ea:e554:77fe with SMTP id f11-20020a05600c154b00b003eae55477femr18003374wmg.12.1678878396165; Wed, 15 Mar 2023 04:06:36 -0700 (PDT) Received: from blmsp.fritz.box ([2001:4090:a247:8056:be7d:83e:a6a5:4659]) by smtp.gmail.com with ESMTPSA id l4-20020a7bc444000000b003eafc47eb09sm1460563wmi.43.2023.03.15.04.06.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 04:06:35 -0700 (PDT) From: Markus Schneider-Pargmann To: Marc Kleine-Budde , Chandrasekar Ramakrishnan , Wolfgang Grandegger Cc: Vincent MAILHOL , Simon Horman , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Markus Schneider-Pargmann Subject: [PATCH v3 13/16] can: m_can: Introduce a tx_fifo_in_flight counter Date: Wed, 15 Mar 2023 12:05:43 +0100 Message-Id: <20230315110546.2518305-14-msp@baylibre.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230315110546.2518305-1-msp@baylibre.com> References: <20230315110546.2518305-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?1760432607154040141?= X-GMAIL-MSGID: =?utf-8?q?1760432607154040141?= Keep track of the number of transmits in flight. This patch prepares the driver to control the network interface queue based on this counter. By itself this counter be implemented with an atomic, but as we need to do other things in the critical sections later I am using a spinlock instead. Signed-off-by: Markus Schneider-Pargmann Reviewed-by: Simon Horman --- drivers/net/can/m_can/m_can.c | 41 ++++++++++++++++++++++++++++++++++- drivers/net/can/m_can/m_can.h | 4 ++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index 27d36bcc094c..4ad8f08f8284 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -442,6 +442,7 @@ static u32 m_can_get_timestamp(struct m_can_classdev *cdev) static void m_can_clean(struct net_device *net) { struct m_can_classdev *cdev = netdev_priv(net); + unsigned long irqflags; for (int i = 0; i != cdev->tx_fifo_size; ++i) { if (!cdev->tx_ops[i].skb) @@ -453,6 +454,10 @@ static void m_can_clean(struct net_device *net) for (int i = 0; i != cdev->can.echo_skb_max; ++i) can_free_echo_skb(cdev->net, i, NULL); + + spin_lock_irqsave(&cdev->tx_handling_spinlock, irqflags); + cdev->tx_fifo_in_flight = 0; + spin_unlock_irqrestore(&cdev->tx_handling_spinlock, irqflags); } /* For peripherals, pass skb to rx-offload, which will push skb from @@ -1023,6 +1028,24 @@ static void m_can_tx_update_stats(struct m_can_classdev *cdev, stats->tx_packets++; } +static void m_can_finish_tx(struct m_can_classdev *cdev, int transmitted) +{ + unsigned long irqflags; + + spin_lock_irqsave(&cdev->tx_handling_spinlock, irqflags); + 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) +{ + unsigned long irqflags; + + spin_lock_irqsave(&cdev->tx_handling_spinlock, irqflags); + ++cdev->tx_fifo_in_flight; + spin_unlock_irqrestore(&cdev->tx_handling_spinlock, irqflags); +} + static int m_can_echo_tx_event(struct net_device *dev) { u32 txe_count = 0; @@ -1032,6 +1055,7 @@ static int m_can_echo_tx_event(struct net_device *dev) int i = 0; int err = 0; unsigned int msg_mark; + int processed = 0; struct m_can_classdev *cdev = netdev_priv(dev); @@ -1061,12 +1085,15 @@ static int m_can_echo_tx_event(struct net_device *dev) /* update stats */ m_can_tx_update_stats(cdev, msg_mark, timestamp); + ++processed; } if (ack_fgi != -1) m_can_write(cdev, M_CAN_TXEFA, FIELD_PREP(TXEFA_EFAI_MASK, ack_fgi)); + m_can_finish_tx(cdev, processed); + return err; } @@ -1161,6 +1188,7 @@ static irqreturn_t m_can_isr(int irq, void *dev_id) 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 { if (ir & (IR_TEFN | IR_TEFW)) { @@ -1846,11 +1874,22 @@ static netdev_tx_t m_can_start_peripheral_xmit(struct m_can_classdev *cdev, } netif_stop_queue(cdev->net); + + m_can_start_tx(cdev); + m_can_tx_queue_skb(cdev, skb); return NETDEV_TX_OK; } +static netdev_tx_t m_can_start_fast_xmit(struct m_can_classdev *cdev, + struct sk_buff *skb) +{ + m_can_start_tx(cdev); + + return m_can_tx_handler(cdev, skb); +} + static netdev_tx_t m_can_start_xmit(struct sk_buff *skb, struct net_device *dev) { @@ -1862,7 +1901,7 @@ static netdev_tx_t m_can_start_xmit(struct sk_buff *skb, if (cdev->is_peripheral) return m_can_start_peripheral_xmit(cdev, skb); else - return m_can_tx_handler(cdev, skb); + return m_can_start_fast_xmit(cdev, skb); } static int m_can_open(struct net_device *dev) diff --git a/drivers/net/can/m_can/m_can.h b/drivers/net/can/m_can/m_can.h index 2e1a52980a18..e230cf320a6c 100644 --- a/drivers/net/can/m_can/m_can.h +++ b/drivers/net/can/m_can/m_can.h @@ -109,6 +109,10 @@ struct m_can_classdev { // Store this internally to avoid fetch delays on peripheral chips int tx_fifo_putidx; + /* Protects shared state between start_xmit and m_can_isr */ + spinlock_t tx_handling_spinlock; + int tx_fifo_in_flight; + struct m_can_tx_op *tx_ops; int tx_fifo_size; int next_tx_op;