From patchwork Wed Mar 15 11:05:45 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: 70143 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2267816wrd; Wed, 15 Mar 2023 04:21:51 -0700 (PDT) X-Google-Smtp-Source: AK7set+M4sGMdOSxE1ISSDxd+2YyOFYkSOJ0eEG9T2Xh/3TLPRm3BJzkp4MJUCUjiBkHF6h8ABRD X-Received: by 2002:a05:6a20:431a:b0:cb:aacb:312c with SMTP id h26-20020a056a20431a00b000cbaacb312cmr46103571pzk.27.1678879310861; Wed, 15 Mar 2023 04:21:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678879310; cv=none; d=google.com; s=arc-20160816; b=Yun2+K4hLFi1o4cpnHfF6CvHuFlBgP1pvtDs41wnQ2r0raHimFBLctBcz5YAaQ63GU SSdyCgKwAPrrMVPCk1LeX8dEUVKjlWVRYKTpb1d9XusXvTfafQxvDKNg9JlKdFp/+pF/ XMGVuwQMzUwzMjrN0v/impe62HW4FzRvACU991+3a6K3hOZK8LZqWrcEhk8rfz9hZvUO bv64kztrmeT/7cqpsA9bkAEbwyMiiiFvW/0zWfZB3j7kWWrnyMuJkMl0QL6JeQebygn9 cJr32jIs5mHJeZF5aGfR0+T2pma1+vjYp7Rc8Ch2rUmfGcvE7sjg3JErBDpyqD1RHoZt RN9A== 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=LD4Xs3iN23TSbUWYlmTbPodYFQvDAfJaowT5cFCRCnM=; b=YkyEDsGVovuS3h80w/+Z/ZSPLQhgvbxtGBZnjwag1eXA+zTKqqDTR0rolHQJQGD+vx 3RLQpw9+R0nOOJgiiPp5zeLmWl9kifjeCyIeZCuTFjKPi97kDMmadlhxeLe2QGeAYVGC N73o4AYzkFkKfAEfgl5KWafd/+cOfNAeNgvyvcp5KmfK9yyIeKPJxLPtdojQQPVFpurA QmQEsxHmtTbOKccQGxE7Zxi+ARjlejNZJahHDUAUqlWV2r4h9aw94yCB1h80FG7Gqd7Y d2cZ9cYOBqKPVfc4A/NPInU9gPOaKSJVYI+s9PeoKteOKymghSdunj7NhJoFQQjTEe4m Ve3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=VoFEESwU; 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 f6-20020a635106000000b004d184dbf598si4715191pgb.519.2023.03.15.04.21.35; Wed, 15 Mar 2023 04:21:50 -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=VoFEESwU; 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 S231849AbjCOLHr (ORCPT + 99 others); Wed, 15 Mar 2023 07:07:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231532AbjCOLGs (ORCPT ); Wed, 15 Mar 2023 07:06:48 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89B9780921 for ; Wed, 15 Mar 2023 04:06:38 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id k25-20020a7bc419000000b003ed23114fa7so819372wmi.4 for ; Wed, 15 Mar 2023 04:06:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; t=1678878398; 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=LD4Xs3iN23TSbUWYlmTbPodYFQvDAfJaowT5cFCRCnM=; b=VoFEESwUBxmtW5+nFMxby7XevZg++Mn56tGd/ZTLrjpLfzXJod8dWaZ2eV8vwQbYyf txwnnaG2WiOSY4BzyI1yZTIdL9HiwlOY95Uq/C+XWMDzKJ3LP7/i5rVQlQunamZ6d15A 4Ckj2kAv4yokvb600hQmZM41P8+aHd0TXYRfApazNhEfLALIQCGuGEWtz7QLmwwRsdXD SmyLsqq1lIctg5ZmkjNvrh2D/Ga1oowyyb4WaFj6MHiEMY7WKfAgbUK85IPpX+bcpVSP OG+WQWs6ESGUqOdj2cCCq2jp6TO+5gAFivnXHjK46ztFbpjeNuf2wHeVwwe3FhSDA3F9 VswQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678878398; 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=LD4Xs3iN23TSbUWYlmTbPodYFQvDAfJaowT5cFCRCnM=; b=OYGlPTFPGyuGqgnB49T9JE7P+ds1blV9DUWmM5GIuqCjz6XYmOA7QJQTAgrNuiIWRA 1Iinw31UDcyOcdwkDf43TEJsoEn0eGGEMIni9StOHN1DEo4GMRbHtAJZdTSKf0FzIe9T zeHV2LQ7gcl3r3ooHIe7bNvOL5hnBDainA2HgzIrnemMlbHdqT1XXpBEtxyVH4rQYils MDvVqSsBxAyNIKl1yhLHD1t9MtYOF5Mz0V/xSWj8lGqZu8xJpqTqAJn2iWKfvIHFa6n1 9t+FX/siW3I/uYTGQeAbvqgpWE8HGtzlwYSddQr/fPfzxKXYS7uuroJNGliSJI9s3rAw IGgA== X-Gm-Message-State: AO0yUKW1CZe2X9z3XmuIbbqo04mBRR/GdV1Rc+ujX/1NqWNTx7sT/LS1 kvK1uqp7WNW1jR0336llSaGFJg== X-Received: by 2002:a05:600c:a48:b0:3ed:245f:97a with SMTP id c8-20020a05600c0a4800b003ed245f097amr9194559wmq.19.1678878398171; Wed, 15 Mar 2023 04:06:38 -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.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 04:06:37 -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 15/16] can: m_can: Implement BQL Date: Wed, 15 Mar 2023 12:05:45 +0100 Message-Id: <20230315110546.2518305-16-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=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?1760432551861700934?= X-GMAIL-MSGID: =?utf-8?q?1760432551861700934?= Implement byte queue limiting in preparation for the use of xmit_more(). Signed-off-by: Markus Schneider-Pargmann Reviewed-by: Simon Horman --- drivers/net/can/m_can/m_can.c | 49 +++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index 3cb3d01e1a61..63d6e95717e3 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -445,6 +445,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_irqsave(&cdev->tx_handling_spinlock, irqflags); cdev->tx_fifo_in_flight = 0; spin_unlock_irqrestore(&cdev->tx_handling_spinlock, irqflags); @@ -999,29 +1001,34 @@ 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 void m_can_finish_tx(struct m_can_classdev *cdev, int transmitted) +static void m_can_finish_tx(struct m_can_classdev *cdev, int transmitted, + int transmitted_frame_len) { unsigned long irqflags; + netdev_completed_queue(cdev->net, transmitted, transmitted_frame_len); + spin_lock_irqsave(&cdev->tx_handling_spinlock, irqflags); if (cdev->tx_fifo_in_flight >= cdev->tx_fifo_size && transmitted > 0) netif_wake_queue(cdev->net); @@ -1060,6 +1067,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); @@ -1088,7 +1096,9 @@ 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; } @@ -1096,7 +1106,7 @@ static int m_can_echo_tx_event(struct net_device *dev) m_can_write(cdev, M_CAN_TXEFA, FIELD_PREP(TXEFA_EFAI_MASK, ack_fgi)); - m_can_finish_tx(cdev, processed); + m_can_finish_tx(cdev, processed, processed_frame_len); return err; } @@ -1187,11 +1197,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); - m_can_finish_tx(cdev, 1); + frame_len = m_can_tx_update_stats(cdev, 0, timestamp); + m_can_finish_tx(cdev, 1, frame_len); } } else { if (ir & (IR_TEFN | IR_TEFW)) { @@ -1720,6 +1731,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 */ @@ -1765,7 +1777,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 */ @@ -1804,7 +1816,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)); @@ -1875,14 +1887,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)