From patchwork Wed Jun 21 09:23:49 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: 110903 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4234300vqr; Wed, 21 Jun 2023 02:32:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7/9iHDuj3YdCny3n2/B6ShjJUB6uH/2SKlvEjjEA5DQbJQbS/kcgyZqs5qIwzNw5JpHFSN X-Received: by 2002:a17:902:6b88:b0:1b5:553e:4ea1 with SMTP id p8-20020a1709026b8800b001b5553e4ea1mr8682251plk.1.1687339971891; Wed, 21 Jun 2023 02:32:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687339971; cv=none; d=google.com; s=arc-20160816; b=YxfOmFqqbEfCQR4JifqqXUkAfvZ1eMRUMK2PS5pNCZYhvwFOS3fOAcz+oQVGUwAjFk IB3+PgOaxhQzz/87/Q67UPuvoaJU4OX0CK057zBB6nhbC0IyZCki1UIRoIn9sJrBm1Js CjIfb4TdYI9oKODIoW00DS4x+krZkT8OVQcsYgWAgIgdhqQzjihIKKJgWSo29PXKY7j2 u31S9vOjlyIfu/lOv3TCu7rGLPWmF8uKGVGv8UhxeS11WDp9NuDB/c+UpRIAEXn7RSL0 8OH21ERS2cGOg/t68q2z1ZIr9Wt9RBzfVYkS1SixXHLvPO7mhvnqG3vSaa41fli70gfs 6qDQ== 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=YnUnzSIjjASfPwMtskRGblxnthY3N6SsU/Hyarpa4rM=; b=M8R6HBSnpJ1KuRzwu1OSesexxUjy87rkeA1cpFVro2hyn0zyW12iEqnU0mv85/HoZb 9Rn9a1zTRDRAMnfPW1+JMOakSq8SGAJZ4YteXk6SAMP3R0vmHeMki2lmvWnr07GGM/AS Seu4Po3189w/JPmYUkP3n5LWu+7C/Q5lRwNFoFU6Mv2RZVwtU5bZpp81XUM3NJ5sk1Qu CRuLw0v8NCiUcog5kWRBF18jFyjYYUG+PsDkD3+Z4ssBkmRMSL9bbfEPmzUKE3vAfmrD WygeebMJ1KJfU1UHAFpuT44KotnRjI7VrOli9cv07EzeU7NhBDhA8GhSI9mHh69VZIrl vhvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20221208.gappssmtp.com header.s=20221208 header.b=yjtIIVhk; 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 i1-20020a170902c94100b001b676f312a8si3869797pla.440.2023.06.21.02.32.38; Wed, 21 Jun 2023 02:32:51 -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.20221208.gappssmtp.com header.s=20221208 header.b=yjtIIVhk; 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 S232077AbjFUJZT (ORCPT + 99 others); Wed, 21 Jun 2023 05:25:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231478AbjFUJY1 (ORCPT ); Wed, 21 Jun 2023 05:24:27 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDD691BD4 for ; Wed, 21 Jun 2023 02:24:09 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-31121494630so6561349f8f.3 for ; Wed, 21 Jun 2023 02:24:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20221208.gappssmtp.com; s=20221208; t=1687339448; x=1689931448; 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=YnUnzSIjjASfPwMtskRGblxnthY3N6SsU/Hyarpa4rM=; b=yjtIIVhkCxt+LK4zSutC32yInmFrQPo5BiQFauqWivAsL1FhOmTYP0rQ5Lx8m5N7wc ZFefMPgm0r3cPw6uYOVgeDMe837pyzSLVvSyCk6JtWgZP+VV+/v26YLldf9XYQ1vvuk9 ceMef06EL50wQBiJloKbb+dd+4xvgkZg/a1Au1OioI2Q0uCumXRgMMLL5d4Nc9X0lnAW sovSPJe3MXmpZWX5SMO2Zv4FLEEr5MTK3EifoPa/0EHJvUrKu3lPgISvCxaKCVxkL9Yz RYl5gftoSeS/WkyZXZlG5s3iXNx1oURdhOBg1ITYQCzcKct13A0I/fb6rrvG+1Gpvdro 00zQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687339448; x=1689931448; 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=YnUnzSIjjASfPwMtskRGblxnthY3N6SsU/Hyarpa4rM=; b=CGYvX6KKuCps+vKDd7ti9/hK4LjAaTjhSWXSSM2edoelgEbS3NPq9bVya5TpxXOySu 3jpds0LBiu3MvJzYz+M/H2TnYCh1oIRLICb4HWxZk6ph8M9k9RZtDZ5xmuV07eaYTZKg f/I8wBfYIdn0CBL6NTA21k1KXJGJWqMJFonI3aBlyhAmwNf+eEzp3mQBJR8TOES2W48g abk0UufkqwuztMCOpd+CCD1A7T6lFIFP7gO4BYfWSLw33tNQ4ABSK9O81090c79pNvXy YPRd+7/r/CoFEnR4gsiT8zBUHP8RlNTg9tDYztwPUcUe7eLmNMbUnAdr0T9VO0wu9zcp M/aQ== X-Gm-Message-State: AC+VfDw+XFNvTuTN/JiIjAqrqXmVgH3JMrjw0Vu6zGgwBMNvsC0NigZO HDJMH/9iYHKFGuNksx3+fPGd4w== X-Received: by 2002:adf:fc47:0:b0:30f:b953:f9fa with SMTP id e7-20020adffc47000000b0030fb953f9famr12220712wrs.16.1687339448146; Wed, 21 Jun 2023 02:24:08 -0700 (PDT) Received: from blmsp.fritz.box ([2001:4091:a247:82fa:b762:4f68:e1ed:5041]) by smtp.gmail.com with ESMTPSA id i11-20020adffdcb000000b002fda1b12a0bsm4022115wrs.2.2023.06.21.02.24.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jun 2023 02:24:07 -0700 (PDT) From: Markus Schneider-Pargmann To: Marc Kleine-Budde , Chandrasekar Ramakrishnan , Wolfgang Grandegger Cc: Vincent MAILHOL , Simon Horman , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Julien Panis , Markus Schneider-Pargmann Subject: [PATCH v4 11/12] can: m_can: Implement BQL Date: Wed, 21 Jun 2023 11:23:49 +0200 Message-Id: <20230621092350.3130866-12-msp@baylibre.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230621092350.3130866-1-msp@baylibre.com> References: <20230621092350.3130866-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, T_SCC_BODY_TEXT_LINE 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?1769304198044566252?= X-GMAIL-MSGID: =?utf-8?q?1769304198044566252?= 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 38bdab9b5cd6..62e275c87c29 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -468,6 +468,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); @@ -1022,29 +1024,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, + unsigned 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); @@ -1083,6 +1090,7 @@ static int m_can_echo_tx_event(struct net_device *dev) int err = 0; unsigned int msg_mark; int processed = 0; + unsigned int processed_frame_len = 0; struct m_can_classdev *cdev = netdev_priv(dev); @@ -1111,7 +1119,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; } @@ -1119,7 +1129,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; } @@ -1194,11 +1204,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)) { @@ -1715,6 +1726,7 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev, u32 cccr, fdflags; int err; u32 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 */ @@ -1760,7 +1772,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 */ @@ -1798,7 +1810,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)); @@ -1869,14 +1881,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)