From patchwork Wed Dec 21 15:25:36 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: 35415 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp3587114wrn; Wed, 21 Dec 2022 07:28:57 -0800 (PST) X-Google-Smtp-Source: AMrXdXtTWu3lXCGlI+ZeUUC0GD2EPgBHZHQTK8O6dq7wmiVExxNcJ8YqFnB252xcCqq84mReY1U9 X-Received: by 2002:a17:902:ca89:b0:189:cfce:529e with SMTP id v9-20020a170902ca8900b00189cfce529emr2121853pld.62.1671636537295; Wed, 21 Dec 2022 07:28:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671636537; cv=none; d=google.com; s=arc-20160816; b=LQ4hNiJS1/Ji4Z+Qsp2sRRxzclZLViRnp141shr2urabFr5dmbaLMYT4ZML5eFmUwx D+SSiapqnaFp+BOi9HC76IAb6W/9U2uc2b9VtSvf9HbtgktAnaGa9hBUwYJ0Gvg/1aZC wcCbpfpB7cM3GpRXRYYNMzBSCJ6exkGi3vXtQeD7HWNHhdbGqA3+O4AgPWYTPsSB+soh /Mb0Q3NTqdjZe3OhiwXUodDwiw08q+vcZxrqDZlRyR8djrvgyjJO1vpkXY5B4lruXZu4 ZC5FbMa/UP6D49CQl3b1ZQfslYRKY9+aotg0U8NJPGL5Z6N1TqqOG1ciqNVv9mvsNEkL qMUw== 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=fe+MrVyRK0YJrQ5IISCTbJAwTu34d4aUgYLMWTnozu8=; b=yW8gayloFej7QOcFgZK+OSXg5oyIHZlvAf1Pkh3ZQsEJH7zwj9VTJWfHOy7rveIwnS YeK6I54YLpQKXIsbps9w7F+gJsgdvppkeITwVO4wy/R9TJ4B2BxnV+uXbtAlQMyKh4Ar aygAdHAHvKIwR9vY/Y5qs+RfGQnzqCNEztN6XBPwvGFMzfebFkfRqRCKIVyG9VGwEQQq iKdz5zli855DtWThwL/iprNcYUEy55a8OikzEdUpzeRCGTTlT87z3ALJOgYOc/avqtex eLqKEuik4rf6CI2RuBLJyjMiHEjGJEWtjVUByJbuYflUGea+ZswpklsSpVKwfG7ZvUJr nk2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=CDoXZtWS; 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 n14-20020a170902f60e00b0019103c51486si16281421plg.331.2022.12.21.07.28.44; Wed, 21 Dec 2022 07:28:57 -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=CDoXZtWS; 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 S234761AbiLUP16 (ORCPT + 99 others); Wed, 21 Dec 2022 10:27:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234672AbiLUP0Y (ORCPT ); Wed, 21 Dec 2022 10:26:24 -0500 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D8B12494F for ; Wed, 21 Dec 2022 07:25:58 -0800 (PST) Received: by mail-ed1-x530.google.com with SMTP id i9so22493790edj.4 for ; Wed, 21 Dec 2022 07:25:58 -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=fe+MrVyRK0YJrQ5IISCTbJAwTu34d4aUgYLMWTnozu8=; b=CDoXZtWSuqSgf1ZhWX4srtfwzRtK7hLLRRi08mtcnwwk5SpnA6XYeR1tPXz6hwdAw/ jbOdmxt1q/2fsSR2MN6I21zFzf9NZG7/WRpyw3OcgYOQcO21UDLgrsT5Yj3SxDeWUPnR UzsYnjuK40f5jaGu8K/PKhAzZFm8cTXGlVS4G31nD6RX7p8EkQdQBaW9LO0Ji5Gn8O/U IbbskQA0G37X2gVZ+piZ5H2CeqH4MCtpPX69rXf36h7ijU00LbOFB1KxXfkBBGTK729l 1iCbmMtueiiKU3iQe+NxrY+MMZY5tvQZuAOYjM/xUfvkZU1xi0FOl2Bbk5/glMMpPyv8 2VIQ== 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=fe+MrVyRK0YJrQ5IISCTbJAwTu34d4aUgYLMWTnozu8=; b=JWiUNewV3LO4I8YZpx3GKZBoT9nh74oUlyKZWGnxku+Q8kV3zEMOwhTxwnYFOeUOgU wuUQOnx6Z1O9vEZihbBp53kbX9SzqtOAE2yuoS+FtZD0BeUKhcGvpzx6mWernuVPDslc suvKt6Xo//ipMxRzCNFesO9Vogb4fI8KDabOigh4u6Mi/d3qLM5OnoIyf2GNZoLSKsVR i3K8pdiHjD2nj+Jny1TuCRBYEgQjF25k7YESQkZzp5P5stMhbsVgrBVLup+qs8VRpzzS DXGF0uCEEVOpn8TvuUHHiUwfsDp2hk5n+bmxOCHC25z3NjxjnjW85dxS0M7RT/K4FK56 F4uQ== X-Gm-Message-State: AFqh2kpnBPUeuo7BStpeIkSS/Npkbd9kJnDd7QPqzuMDrR9p5jHPfCZE SMAqj2pMjwX4f2THt0ur+Q8hQA== X-Received: by 2002:aa7:dd13:0:b0:463:ba73:9139 with SMTP id i19-20020aa7dd13000000b00463ba739139mr1792081edv.2.1671636357033; Wed, 21 Dec 2022 07:25:57 -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.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Dec 2022 07:25:56 -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 17/18] can: m_can: Implement BQL Date: Wed, 21 Dec 2022 16:25:36 +0100 Message-Id: <20221221152537.751564-18-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?1752837953399645049?= X-GMAIL-MSGID: =?utf-8?q?1752837953399645049?= Implement byte queue limiting in preparation for the use of xmit_more(). Signed-off-by: Markus Schneider-Pargmann --- drivers/net/can/m_can/m_can.c | 43 ++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index 076fa60317c2..719a7dfe154a 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -443,6 +443,8 @@ 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); + netdev_reset_queue(cdev->net); + spin_lock(&cdev->tx_handling_spinlock); cdev->tx_fifo_in_flight = 0; spin_unlock(&cdev->tx_handling_spinlock); @@ -988,23 +990,25 @@ static int m_can_poll(struct napi_struct *napi, int quota) * echo. timestamp is used for peripherals to ensure correct ordering * by rx-offload, and is ignored for non-peripherals. */ -static void m_can_tx_update_stats(struct m_can_classdev *cdev, - unsigned int msg_mark, - u32 timestamp) +static unsigned int m_can_tx_update_stats(struct m_can_classdev *cdev, + unsigned int msg_mark, u32 timestamp) { struct net_device *dev = cdev->net; struct net_device_stats *stats = &dev->stats; + unsigned int frame_len; if (cdev->is_peripheral) stats->tx_bytes += can_rx_offload_get_echo_skb(&cdev->offload, msg_mark, timestamp, - NULL); + &frame_len); else - stats->tx_bytes += can_get_echo_skb(dev, msg_mark, NULL); + stats->tx_bytes += can_get_echo_skb(dev, msg_mark, &frame_len); stats->tx_packets++; + + return frame_len; } static int m_can_echo_tx_event(struct net_device *dev) @@ -1017,6 +1021,7 @@ static int m_can_echo_tx_event(struct net_device *dev) int err = 0; unsigned int msg_mark; int processed = 0; + int processed_frame_len = 0; struct m_can_classdev *cdev = netdev_priv(dev); @@ -1045,10 +1050,14 @@ static int m_can_echo_tx_event(struct net_device *dev) fgi = (++fgi >= cdev->mcfg[MRAM_TXE].num ? 0 : fgi); /* update stats */ - m_can_tx_update_stats(cdev, msg_mark, timestamp); + processed_frame_len += m_can_tx_update_stats(cdev, msg_mark, + timestamp); + ++processed; } + netdev_completed_queue(cdev->net, processed, processed_frame_len); + if (ack_fgi != -1) m_can_write(cdev, M_CAN_TXEFA, FIELD_PREP(TXEFA_EFAI_MASK, ack_fgi)); @@ -1148,10 +1157,12 @@ static irqreturn_t m_can_isr(int irq, void *dev_id) if (ir & IR_TC) { /* Transmission Complete Interrupt*/ u32 timestamp = 0; + unsigned int frame_len; if (cdev->is_peripheral) timestamp = m_can_get_timestamp(cdev); - m_can_tx_update_stats(cdev, 0, timestamp); + frame_len = m_can_tx_update_stats(cdev, 0, timestamp); + netdev_completed_queue(cdev->net, 1, frame_len); netif_wake_queue(dev); } } else { @@ -1667,6 +1678,7 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev, u32 cccr, fdflags; int err; int putidx; + unsigned int frame_len = can_skb_get_frame_len(skb); /* Generate ID field for TX buffer Element */ /* Common to all supported M_CAN versions */ @@ -1712,7 +1724,7 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev, } m_can_write(cdev, M_CAN_TXBTIE, 0x1); - can_put_echo_skb(skb, dev, 0, 0); + can_put_echo_skb(skb, dev, 0, frame_len); m_can_write(cdev, M_CAN_TXBAR, 0x1); /* End of xmit function for version 3.0.x */ @@ -1750,7 +1762,7 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev, /* Push loopback echo. * Will be looped back on TX interrupt based on message marker */ - can_put_echo_skb(skb, dev, putidx, 0); + can_put_echo_skb(skb, dev, putidx, frame_len); /* Enable TX FIFO element to start transfer */ m_can_write(cdev, M_CAN_TXBAR, (1 << putidx)); @@ -1833,14 +1845,23 @@ static netdev_tx_t m_can_start_xmit(struct sk_buff *skb, struct net_device *dev) { struct m_can_classdev *cdev = netdev_priv(dev); + netdev_tx_t ret; + unsigned int frame_len; if (can_dev_dropped_skb(dev, skb)) return NETDEV_TX_OK; + frame_len = can_skb_get_frame_len(skb); + if (cdev->is_peripheral) - return m_can_start_peripheral_xmit(cdev, skb); + ret = m_can_start_peripheral_xmit(cdev, skb); else - return m_can_start_fast_xmit(cdev, skb); + ret = m_can_start_fast_xmit(cdev, skb); + + if (ret == NETDEV_TX_OK) + netdev_sent_queue(dev, frame_len); + + return ret; } static int m_can_open(struct net_device *dev)