From patchwork Wed Jan 25 19:50:58 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: 48291 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp460821wrn; Wed, 25 Jan 2023 12:03:12 -0800 (PST) X-Google-Smtp-Source: AK7set8CeUCLirilTkNYEtv6kOvY2F1lmizoHl1Ud7mXly2TvxaMZXlpACBzNpdAieEBZUY41AY8 X-Received: by 2002:a17:90b:4c8a:b0:22c:1735:4298 with SMTP id my10-20020a17090b4c8a00b0022c17354298mr973229pjb.14.1674676992577; Wed, 25 Jan 2023 12:03:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674676992; cv=none; d=google.com; s=arc-20160816; b=W6hEWzxLtl+418kO1sURKlyaXqNGUDd5vRM20H7+kaeS2blGHLo50BWoaRom0fEfFo +rJDJxoUsSqMxmYGQB9QZmvjGm+k9hUuSJq9XavaKTaY4eCB6DWvetyp2k9fbMxDYKNw 8bFJTZVhGOLG3leMMzhGJiVbUxb/BZ8LXWy2BxHJObI2msClFNbBWDYKpWxfnHIql/7u ZD6bjrmYX1Z6oI72ssl5V0thoyvN1+BBdixoFwGNSKgbMQukA1PyBYuAdK1I5AOIeYDU 6KERamQCvxB8IjPO+l5XoBGzxh6lLb9f7erMaTK4CopVb3A57ufFDUHRI0b/uYTXNz28 vqHg== 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=ffISOqPrjVineBfCgtfl5Y+ak8BEEFsQWDBR3c2ME1A=; b=Uj6Lqgu4U6sFPgYHjkv+3kkVm/b1feXIWVXea/YlDG3Nk8uUgY6qGGoE8gVFs+lVQQ zQpEOugUlLBkQY/a3VYM5ohGpirfQHOg2Nw2UQT/QcKGpBJgV3QxYSe+3NIK4y1TKjP2 q6UrjYdBBESGB44vMlChMbAQ52Xc8dwketTyyRss5PNj0Bo6fvqkcmZA2pXzjcxpSzWX 1YF/+fb8Wgmqw2r6BTzIoCe7SNNdTExBKCCKYsspj98S2pk6aEXVvqZ8eZgtGW2bVRUX Tx9c5qWkGjU6RJT8EvoKsDeKHh+WGcLQiMUn4Cst8+HB7rSam7BupIYDTgstDQONuqE8 eV0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=0VuzDqRw; 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 p1-20020a63ab01000000b004da09fcce33si2616828pgf.583.2023.01.25.12.02.55; Wed, 25 Jan 2023 12:03:12 -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=0VuzDqRw; 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 S236090AbjAYTxA (ORCPT + 99 others); Wed, 25 Jan 2023 14:53:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236160AbjAYTwY (ORCPT ); Wed, 25 Jan 2023 14:52:24 -0500 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD45F5977E for ; Wed, 25 Jan 2023 11:51:22 -0800 (PST) Received: by mail-ej1-x630.google.com with SMTP id kt14so50661631ejc.3 for ; Wed, 25 Jan 2023 11:51:22 -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=ffISOqPrjVineBfCgtfl5Y+ak8BEEFsQWDBR3c2ME1A=; b=0VuzDqRw805Rh+kKcAf2Kr4irsZmGV3zH28nntM2EYVNES0HnLhs9pwkq3l1D9agU9 QoeI1a6uzVFwLUk6GTzaweHSluK4GvqIHb+lpuxKzL4JizJUSeOx6z4J8CP4JSJaBV48 MH7P9bTc5yJV4xFSjl4U6nG5h1GOyioXerSXqtMguE5XIx/IcEOnNYVw/RSNtBcBtybq iiEcmAwuPSVrU2z+nZXkxxS5ZDLKzq8xZmAqpY6WmupxemW9ySjYHFrpr7yWrFspMyjo 9C+XHxyUXUtLrzMfn3v8fbrdHH+AipIVwsDjJIk8+QfzKKAuUQBh/nHYWu3Ss1xrP+PZ 4FvQ== 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=ffISOqPrjVineBfCgtfl5Y+ak8BEEFsQWDBR3c2ME1A=; b=t/bjID5xSjYG160JWbYHkUomv5a76PcvgREVdYVA8wO/REA0lin/HUiPsQawq8Sp0r HnhmfEO0fJQG68pp5zy96IJJlsYA3P5kJttDK2nclYfITzbzisTfnNCD3dVL9m5M86vD Vs9Aru8tnVlDi9AhX+IoiH4d415WAy2JqUk1QaShhfdR6rSyd0llkN2hUVsNPUv259L2 5heSmAKvLWC8meSAdg1kqWuHHML/+niZwrysengmbAi0HP7sPYkKhKrc3i5E5+cIezWf PA3QXkts3jVFOdssv4pBpFx/GFFpTqr4Pf72Z0L5ep3Mcs5BmBmRnT1HM9V0Ul7xxhyg iHXg== X-Gm-Message-State: AFqh2kqJvpt1BD74sJeuT6GeZ6rlf5ex0o5qD50yH8GmPVxCgtkYNSB0 1Eq4X3xir2xz/KGbY0eN5vvAGg== X-Received: by 2002:a17:906:2c55:b0:86b:d25:450f with SMTP id f21-20020a1709062c5500b0086b0d25450fmr35270088ejh.25.1674676279544; Wed, 25 Jan 2023 11:51:19 -0800 (PST) Received: from blmsp.fritz.box ([2001:4091:a247:815f:ef74:e427:628a:752c]) by smtp.gmail.com with ESMTPSA id s15-20020a170906454f00b00872c0bccab2sm2778830ejq.35.2023.01.25.11.51.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 11:51:19 -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 v2 17/18] can: m_can: Implement BQL Date: Wed, 25 Jan 2023 20:50:58 +0100 Message-Id: <20230125195059.630377-18-msp@baylibre.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230125195059.630377-1-msp@baylibre.com> References: <20230125195059.630377-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?1756026102281340177?= X-GMAIL-MSGID: =?utf-8?q?1756026102281340177?= 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 | 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 b24ca7a1ecfc..c6a09369d1aa 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -444,6 +444,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); @@ -998,27 +1000,32 @@ 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) { + netdev_completed_queue(cdev->net, transmitted, transmitted_frame_len); + spin_lock(&cdev->tx_handling_spinlock); if (cdev->tx_fifo_in_flight >= cdev->tx_fifo_size && transmitted > 0) netif_wake_queue(cdev->net); @@ -1056,6 +1063,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); @@ -1084,7 +1092,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; } @@ -1092,7 +1102,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; } @@ -1183,11 +1193,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)) { @@ -1716,6 +1727,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 */ @@ -1761,7 +1773,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 */ @@ -1799,7 +1811,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)); @@ -1870,14 +1882,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)