From patchwork Wed Dec 21 15:25:34 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: 35411 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp3586792wrn; Wed, 21 Dec 2022 07:28:19 -0800 (PST) X-Google-Smtp-Source: AMrXdXsXPr5FR9UqqhwPoL3rSwgamRh7STUDXiEL5OmXUyFKvTU0+nfBaGNIyX7jujmWMVnPrJ1s X-Received: by 2002:a05:6a20:a88a:b0:b2:75d0:b702 with SMTP id ca10-20020a056a20a88a00b000b275d0b702mr2013560pzb.18.1671636498799; Wed, 21 Dec 2022 07:28:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671636498; cv=none; d=google.com; s=arc-20160816; b=Ed/DA6blc+1XH7tS5/yoF804+vlcfCPCFmQoGcwqzfhyHoicB+CMzcJSrKOUo8Z5QE zHcZYuk8KxTP3MpVHZoRLDgHWEjnJYX7oWh+filn9QzrZrdBtXgcTTlN5gMXr3hUDGax vFwPXzAXuRitO1l0x9bO03ucAXIrOz0iulFxryIs36jF3Kf3GOth5mqPwL8en3MffWxh +Tdb+5aX4FcPsBDRggxYbFFQLdvag2w2M2a0LNrUdc0NAwD71Ctvo6ZTQXGPHJCbDQXj A9g/kAipdl469VMnFlsk4MCJEqWyIFlI0SG8+TM+6EoDj0K3QFMjIgN4os4vSLKJB6qG Bmfg== 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=r4xNKyUsvaXfBc3iUbNwfQj7kGAAWBTHhrvCBFQZpUU=; b=Gz1KsSiQXN98mx4NcTvR7OaUsze8q+dc1nj3y4L62V54yqLIkK2grvdl1QmKlUwcB8 DqrtoNopNzU8uk2Q1DnraDi5My14+WZK6/k6F9sSVOkHLfE1AL6GDmjdYYdZyenO0rrN RINNftXmENzeen1VUvDGC82pAjsnBN6eXO2K1mV35bfF4xzzog7kvnQldMMh5tp5LPyo UnANHafHLpXz0lv/LeNIhkhxrpPHLdx5b+36MDWutleLtN7sWncIRmxerkp+y6Z4foGr UkYhwbGYeMB0uHNbBK5HPMwrS8GGpQtN97A3fB3QwDaH+O7n1UUmJBL6vHg5KvT+c3kH 9Asw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=52QxhYPs; 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 d10-20020a63734a000000b00478dfd40ef6si17329545pgn.768.2022.12.21.07.28.04; Wed, 21 Dec 2022 07:28:18 -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=52QxhYPs; 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 S234857AbiLUP1L (ORCPT + 99 others); Wed, 21 Dec 2022 10:27:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234713AbiLUP0L (ORCPT ); Wed, 21 Dec 2022 10:26:11 -0500 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34C1C248DD for ; Wed, 21 Dec 2022 07:25:55 -0800 (PST) Received: by mail-ed1-x529.google.com with SMTP id a16so22456746edb.9 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=r4xNKyUsvaXfBc3iUbNwfQj7kGAAWBTHhrvCBFQZpUU=; b=52QxhYPs+F0QvgoHcjHqY2chLRIcLMl5FPqqhjr7XB5Ej9buMkkxpu8jvstKww3K54 XRlrPL2+JVczIXnXWD2+OK602DyWULP+nVUjTvdv6QmjZ5G4AJzZTtD/2OHeOQIBvPM7 w/IRTWH2VKuTb74lJpnZiIg5gJY8Om9ZEiMcshUulCrCV2TEqvfxAuM2yao+jIQ7FEEd 5J9VVmiAP3dC0mEzwPg+6JrgUiq7aOqV36VBIzeXm9IQSeNUE1vbmUjjzuKHznpUxL94 P2hqzIk+NhRZOW49LrKUrrI5OJm6ZciFHb7YJlkaafCpgpU+IH0eY+J27Ivkq3JF32L6 NQKQ== 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=r4xNKyUsvaXfBc3iUbNwfQj7kGAAWBTHhrvCBFQZpUU=; b=pgt8ZdVfQPQMk+Zlrm1sMr9QXHvdtEoAJbJ5pn5ui2zgv3grg29w+hnB0lYIYgdwgq W4GDB2e6DsXjKKChp4fBzB/ZopzsK0VxTICDa2OrpxuFbnljCvPk7aQafQ12mp9ht4rt 3/Zqjz0bgctWWPbAeeSSD1xxIFG5JsjWVnlTDYmToHvF5RwerlkCLQhjnxHBnYtoL8zF c/imS3OrPXSL5qYKJm0YPvZ1CDT0CuSXDjVbGj1gRz7nOuCQNx39QZy86jI/ni1SQ6Cx OCtMiDVAY4x+OERW0Gru010/S2I0JD1e+DsOZ69b1GAflu+Ji4h2Q//8IXQlBZ13JACz VYhw== X-Gm-Message-State: AFqh2koo4fof0L9mAz0onLoP4PqnfkkdDogWBit3Z68WA31CffM5HEWL GHzrhFEyWZCpmZhxEhYXhK74iA== X-Received: by 2002:aa7:dd13:0:b0:47b:a6e:6b69 with SMTP id i19-20020aa7dd13000000b0047b0a6e6b69mr2080871edv.2.1671636354717; Wed, 21 Dec 2022 07:25:54 -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.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Dec 2022 07:25:54 -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 15/18] can: m_can: Introduce a tx_fifo_in_flight counter Date: Wed, 21 Dec 2022 16:25:34 +0100 Message-Id: <20221221152537.751564-16-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=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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752837913326290759?= X-GMAIL-MSGID: =?utf-8?q?1752837913326290759?= 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 --- drivers/net/can/m_can/m_can.c | 27 ++++++++++++++++++++++++++- drivers/net/can/m_can/m_can.h | 4 ++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index 42cde31fc0a8..90c9ff474149 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -452,6 +452,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(&cdev->tx_handling_spinlock); + cdev->tx_fifo_in_flight = 0; + spin_unlock(&cdev->tx_handling_spinlock); } /* For peripherals, pass skb to rx-offload, which will push skb from @@ -1022,6 +1026,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); @@ -1051,12 +1056,17 @@ 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)); + spin_lock(&cdev->tx_handling_spinlock); + cdev->tx_fifo_in_flight -= processed; + spin_unlock(&cdev->tx_handling_spinlock); + return err; } @@ -1821,11 +1831,26 @@ static netdev_tx_t m_can_start_peripheral_xmit(struct m_can_classdev *cdev, } netif_stop_queue(cdev->net); + + spin_lock(&cdev->tx_handling_spinlock); + ++cdev->tx_fifo_in_flight; + spin_unlock(&cdev->tx_handling_spinlock); + 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) +{ + spin_lock(&cdev->tx_handling_spinlock); + ++cdev->tx_fifo_in_flight; + spin_unlock(&cdev->tx_handling_spinlock); + + return m_can_tx_handler(cdev, skb); +} + static netdev_tx_t m_can_start_xmit(struct sk_buff *skb, struct net_device *dev) { @@ -1837,7 +1862,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 bf2d710c982f..adbd4765accc 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 nr_tx_ops; int next_tx_op;