Message ID | 20230621092350.3130866-2-msp@baylibre.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4231613vqr; Wed, 21 Jun 2023 02:27:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5Qc/wBv16ytAWCZIgR4CEdEYBFyQRC/WL7PVVx18jrMn1d85Jc0l73YAleaHPQZs//1LXk X-Received: by 2002:a17:90a:19ca:b0:25f:20f:2f7d with SMTP id 10-20020a17090a19ca00b0025f020f2f7dmr8475071pjj.2.1687339637663; Wed, 21 Jun 2023 02:27:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687339637; cv=none; d=google.com; s=arc-20160816; b=jTO58082M0RcCJ3f+ffHOYbwyP00Bjzg8GshZo45d+LpkMSDiJDoUbUn8O2aM1eKc2 8WcHZW0Q8Z4owwOqC2729wn12YK2uqwJnFyjSqWuY+zetFABtmcLDYhsXkOR++ebeOBm 2vLBKteQ/tgkQhG6/fwQgFU+/RRxcfWCg22lcdUjvXoJc4jicvQtRxUHSjUW3D1xJYPR kY268lfxjML+ceKiV5QIfVCXV2938pF28Me7pSwzzFnhLJoN3mDQMAGFavTozYiIO9tz dg05Yp4QhGrl+TBjc03bXDVlWuBqxbFhMggnAufBtOEXMxGXGIHQ12DVZ1X811nzjB1n cADg== 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=IztrjGfMix5tskQ3YAq+GbppbknMQpNbHYwT+eFcuyg=; b=tQLKarGnsxBQGxeR/O4Ru79XZgkJQqsVQgDQqCv+znFKOdGNqTU0KpO2skcxMR7F7m DrthJFbhK+u8k7mCKRLruoL/1YDyJ0s6VnxQuC5NfYK+77VwFdnuBNriMh+dQ5rh0hCv chvTGal4Nlm3uQvTh+/XLiB74mjQVqkSw2ykGIz9ynodDeAg+YiGOlS6/H9ve1lSS6gn 2TL5SCS3uuB9XLRHDHBTdmSlBIDu/4CKXb0pVbRV0Z/D2Lpw2bpMewHCVP/oxosB1J06 nEXhKZdwkPv5gzuvbIFFnBVudpa23u7MgtMUtPju1UrP9Zq66nszHadZJ+D7TUGhR6UQ L4Aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20221208.gappssmtp.com header.s=20221208 header.b=SSp73YYG; 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 u4-20020a17090a400400b0025679bf9761si3627986pjc.56.2023.06.21.02.27.04; Wed, 21 Jun 2023 02:27:17 -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=SSp73YYG; 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 S231437AbjFUJY0 (ORCPT <rfc822;maxin.john@gmail.com> + 99 others); Wed, 21 Jun 2023 05:24:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230498AbjFUJYR (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 21 Jun 2023 05:24:17 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CFA11BE1 for <linux-kernel@vger.kernel.org>; Wed, 21 Jun 2023 02:23:58 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-3f9bff0a543so3543865e9.3 for <linux-kernel@vger.kernel.org>; Wed, 21 Jun 2023 02:23:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20221208.gappssmtp.com; s=20221208; t=1687339437; x=1689931437; 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=IztrjGfMix5tskQ3YAq+GbppbknMQpNbHYwT+eFcuyg=; b=SSp73YYGJCLinA3gBiXji4iBZRTLr1zODBJib8/+eDTd0p8hHxbpzpM4rDaJTwBI2q wUXpB2ygTtS94+2COr8bDgaPanKW63gfCFh8/wUg0IxDRX1gjlJZwbSnb626jiDo8gaf VUzhtMUnB8UGGPKQD3cV5kEMtsMlUPtg+ydQr0DRUnOOT6d7kEAyuEs36aMiVDVXMVS5 M8SpQtwBxKw/HIZpqdgdixsdKHnbZpzrVMsyD4tJC0Ooaked6WlOqngC6HkK5U1rDriR hW+86VycgFP9UpOLwPDHBfgK4bxIvKl52rvFKyjT9maD01ncc+frQmQ2c4O8C5GI+GyG LzuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687339437; x=1689931437; 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=IztrjGfMix5tskQ3YAq+GbppbknMQpNbHYwT+eFcuyg=; b=GA1NwqxU6+4FB5hM8JgolgRj3fILOct5WidEeds770Ygo4FmxqkZTq95vzNwSMgE5j 2UICcQX6psY0Sdn0zXJyYHq7R52LchanMJyngcv/PAqKyeVi2GZYYQCaP+brk1a9iEPD 2j/X36YrXOU5ujlCVPIhze8oRgcTpTnP/PPCjKgt6xMdaPAqPbBbDGFhTaEz4jkve+JW 11Nc7GaUi08RGYwu8L4dbc3SHjqYKXyrbwD/P4/JYY5S6Q6x4CppYqjM4FEItCTLwaVD xKW5suGH8gycwhK5AkB+6wTQ5gZgoHjB4gCOMHHaMi3HdWIbeYpC2PYIB1LJPIznnVcb 9FJQ== X-Gm-Message-State: AC+VfDwUqLFziO0kdhhRCcL/nOsG5nhz6f+6xB60SPCxMA94gV7uYTIm RnmWN/+3MOricmk30+nXpc8AnQ== X-Received: by 2002:a7b:c405:0:b0:3f9:b1c5:ece0 with SMTP id k5-20020a7bc405000000b003f9b1c5ece0mr5500353wmi.10.1687339437046; Wed, 21 Jun 2023 02:23:57 -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.23.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jun 2023 02:23:56 -0700 (PDT) From: Markus Schneider-Pargmann <msp@baylibre.com> To: Marc Kleine-Budde <mkl@pengutronix.de>, Chandrasekar Ramakrishnan <rcsekar@samsung.com>, Wolfgang Grandegger <wg@grandegger.com> Cc: Vincent MAILHOL <mailhol.vincent@wanadoo.fr>, Simon Horman <simon.horman@corigine.com>, "David S . Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Julien Panis <jpanis@baylibre.com>, Markus Schneider-Pargmann <msp@baylibre.com> Subject: [PATCH v4 01/12] can: m_can: Write transmit header and data in one transaction Date: Wed, 21 Jun 2023 11:23:39 +0200 Message-Id: <20230621092350.3130866-2-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 Content-Transfer-Encoding: 8bit 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769303847679326566?= X-GMAIL-MSGID: =?utf-8?q?1769303847679326566?= |
Series |
can: m_can: Optimizations for m_can/tcan part 2
|
|
Commit Message
Markus Schneider-Pargmann
June 21, 2023, 9:23 a.m. UTC
Combine header and data before writing to the transmit fifo to reduce
the overhead for peripheral chips.
Signed-off-by: Markus Schneider-Pargmann <msp@baylibre.com>
---
drivers/net/can/m_can/m_can.c | 34 +++++++++++++++++++++-------------
1 file changed, 21 insertions(+), 13 deletions(-)
Comments
On Wed, Jun 21, 2023 at 11:23:39AM +0200, Markus Schneider-Pargmann wrote: > Combine header and data before writing to the transmit fifo to reduce > the overhead for peripheral chips. > > Signed-off-by: Markus Schneider-Pargmann <msp@baylibre.com> > --- > drivers/net/can/m_can/m_can.c | 34 +++++++++++++++++++++------------- > 1 file changed, 21 insertions(+), 13 deletions(-) > > diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c > index a5003435802b..5251073987ee 100644 > --- a/drivers/net/can/m_can/m_can.c > +++ b/drivers/net/can/m_can/m_can.c > @@ -317,6 +317,12 @@ struct id_and_dlc { > u32 dlc; > }; > > +struct m_can_fifo_element { > + u32 id; > + u32 dlc; > + u8 data[CANFD_MAX_DLEN]; > +}; > + > static inline u32 m_can_read(struct m_can_classdev *cdev, enum m_can_reg reg) > { > return cdev->ops->read_reg(cdev, reg); > @@ -1622,6 +1628,8 @@ static int m_can_next_echo_skb_occupied(struct net_device *dev, int putidx) > static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev) > { > struct canfd_frame *cf = (struct canfd_frame *)cdev->tx_skb->data; > + u8 len_padded = DIV_ROUND_UP(cf->len, 4); > + struct m_can_fifo_element fifo_element; > struct net_device *dev = cdev->net; > struct sk_buff *skb = cdev->tx_skb; > struct id_and_dlc fifo_header; Hi Markus, GCC 12.3.0 complains that fifo_header is not (no longer) used. drivers/net/can/m_can/m_can.c:1635:20: warning: unused variable 'fifo_header' [-Wunused-variable] struct id_and_dlc fifo_header;
Hi Markus,
kernel test robot noticed the following build warnings:
[auto build test WARNING on ac9a78681b921877518763ba0e89202254349d1b]
url: https://github.com/intel-lab-lkp/linux/commits/Markus-Schneider-Pargmann/can-m_can-Write-transmit-header-and-data-in-one-transaction/20230621-173848
base: ac9a78681b921877518763ba0e89202254349d1b
patch link: https://lore.kernel.org/r/20230621092350.3130866-2-msp%40baylibre.com
patch subject: [PATCH v4 01/12] can: m_can: Write transmit header and data in one transaction
config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20230622/202306220154.20bzOw90-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce: (https://download.01.org/0day-ci/archive/20230622/202306220154.20bzOw90-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202306220154.20bzOw90-lkp@intel.com/
All warnings (new ones prefixed by >>):
drivers/net/can/m_can/m_can.c: In function 'm_can_tx_handler':
>> drivers/net/can/m_can/m_can.c:1635:27: warning: unused variable 'fifo_header' [-Wunused-variable]
1635 | struct id_and_dlc fifo_header;
| ^~~~~~~~~~~
vim +/fifo_header +1635 drivers/net/can/m_can/m_can.c
10c1c3975a6663 Mario Huettel 2017-04-08 1627
441ac340169b79 Dan Murphy 2019-05-09 1628 static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev)
e0d1f4816f2a7e Dong Aisheng 2014-07-16 1629 {
441ac340169b79 Dan Murphy 2019-05-09 1630 struct canfd_frame *cf = (struct canfd_frame *)cdev->tx_skb->data;
9a10b9d9f7e946 Markus Schneider-Pargmann 2023-06-21 1631 u8 len_padded = DIV_ROUND_UP(cf->len, 4);
9a10b9d9f7e946 Markus Schneider-Pargmann 2023-06-21 1632 struct m_can_fifo_element fifo_element;
441ac340169b79 Dan Murphy 2019-05-09 1633 struct net_device *dev = cdev->net;
441ac340169b79 Dan Murphy 2019-05-09 1634 struct sk_buff *skb = cdev->tx_skb;
812270e5445bd1 Matt Kline 2021-08-16 @1635 struct id_and_dlc fifo_header;
812270e5445bd1 Matt Kline 2021-08-16 1636 u32 cccr, fdflags;
c1eaf8b9bd3145 Markus Schneider-Pargmann 2022-12-06 1637 u32 txfqs;
812270e5445bd1 Matt Kline 2021-08-16 1638 int err;
10c1c3975a6663 Mario Huettel 2017-04-08 1639 int putidx;
e0d1f4816f2a7e Dong Aisheng 2014-07-16 1640
e04b2cfe61072c Marc Kleine-Budde 2021-05-05 1641 cdev->tx_skb = NULL;
e04b2cfe61072c Marc Kleine-Budde 2021-05-05 1642
10c1c3975a6663 Mario Huettel 2017-04-08 1643 /* Generate ID field for TX buffer Element */
10c1c3975a6663 Mario Huettel 2017-04-08 1644 /* Common to all supported M_CAN versions */
e0d1f4816f2a7e Dong Aisheng 2014-07-16 1645 if (cf->can_id & CAN_EFF_FLAG) {
9a10b9d9f7e946 Markus Schneider-Pargmann 2023-06-21 1646 fifo_element.id = cf->can_id & CAN_EFF_MASK;
9a10b9d9f7e946 Markus Schneider-Pargmann 2023-06-21 1647 fifo_element.id |= TX_BUF_XTD;
e0d1f4816f2a7e Dong Aisheng 2014-07-16 1648 } else {
9a10b9d9f7e946 Markus Schneider-Pargmann 2023-06-21 1649 fifo_element.id = ((cf->can_id & CAN_SFF_MASK) << 18);
e0d1f4816f2a7e Dong Aisheng 2014-07-16 1650 }
e0d1f4816f2a7e Dong Aisheng 2014-07-16 1651
e0d1f4816f2a7e Dong Aisheng 2014-07-16 1652 if (cf->can_id & CAN_RTR_FLAG)
9a10b9d9f7e946 Markus Schneider-Pargmann 2023-06-21 1653 fifo_element.id |= TX_BUF_RTR;
e0d1f4816f2a7e Dong Aisheng 2014-07-16 1654
441ac340169b79 Dan Murphy 2019-05-09 1655 if (cdev->version == 30) {
10c1c3975a6663 Mario Huettel 2017-04-08 1656 netif_stop_queue(dev);
10c1c3975a6663 Mario Huettel 2017-04-08 1657
9a10b9d9f7e946 Markus Schneider-Pargmann 2023-06-21 1658 fifo_element.dlc = can_fd_len2dlc(cf->len) << 16;
80646733f11c2e Dong Aisheng 2014-11-18 1659
812270e5445bd1 Matt Kline 2021-08-16 1660 /* Write the frame ID, DLC, and payload to the FIFO element. */
9a10b9d9f7e946 Markus Schneider-Pargmann 2023-06-21 1661 err = m_can_fifo_write(cdev, 0, M_CAN_FIFO_ID, &fifo_element, 2);
e39381770ec9ca Matt Kline 2021-08-16 1662 if (err)
e39381770ec9ca Matt Kline 2021-08-16 1663 goto out_fail;
e39381770ec9ca Matt Kline 2021-08-16 1664
812270e5445bd1 Matt Kline 2021-08-16 1665 err = m_can_fifo_write(cdev, 0, M_CAN_FIFO_DATA,
9a10b9d9f7e946 Markus Schneider-Pargmann 2023-06-21 1666 cf->data, len_padded);
e39381770ec9ca Matt Kline 2021-08-16 1667 if (err)
e39381770ec9ca Matt Kline 2021-08-16 1668 goto out_fail;
80646733f11c2e Dong Aisheng 2014-11-18 1669
441ac340169b79 Dan Murphy 2019-05-09 1670 if (cdev->can.ctrlmode & CAN_CTRLMODE_FD) {
441ac340169b79 Dan Murphy 2019-05-09 1671 cccr = m_can_read(cdev, M_CAN_CCCR);
20779943a080c5 Torin Cooper-Bennun 2021-05-04 1672 cccr &= ~CCCR_CMR_MASK;
80646733f11c2e Dong Aisheng 2014-11-18 1673 if (can_is_canfd_skb(skb)) {
80646733f11c2e Dong Aisheng 2014-11-18 1674 if (cf->flags & CANFD_BRS)
20779943a080c5 Torin Cooper-Bennun 2021-05-04 1675 cccr |= FIELD_PREP(CCCR_CMR_MASK,
20779943a080c5 Torin Cooper-Bennun 2021-05-04 1676 CCCR_CMR_CANFD_BRS);
80646733f11c2e Dong Aisheng 2014-11-18 1677 else
20779943a080c5 Torin Cooper-Bennun 2021-05-04 1678 cccr |= FIELD_PREP(CCCR_CMR_MASK,
20779943a080c5 Torin Cooper-Bennun 2021-05-04 1679 CCCR_CMR_CANFD);
80646733f11c2e Dong Aisheng 2014-11-18 1680 } else {
20779943a080c5 Torin Cooper-Bennun 2021-05-04 1681 cccr |= FIELD_PREP(CCCR_CMR_MASK, CCCR_CMR_CAN);
80646733f11c2e Dong Aisheng 2014-11-18 1682 }
441ac340169b79 Dan Murphy 2019-05-09 1683 m_can_write(cdev, M_CAN_CCCR, cccr);
80646733f11c2e Dong Aisheng 2014-11-18 1684 }
441ac340169b79 Dan Murphy 2019-05-09 1685 m_can_write(cdev, M_CAN_TXBTIE, 0x1);
2e8e79c416aae1 Marc Kleine-Budde 2022-03-17 1686
2e8e79c416aae1 Marc Kleine-Budde 2022-03-17 1687 can_put_echo_skb(skb, dev, 0, 0);
2e8e79c416aae1 Marc Kleine-Budde 2022-03-17 1688
441ac340169b79 Dan Murphy 2019-05-09 1689 m_can_write(cdev, M_CAN_TXBAR, 0x1);
10c1c3975a6663 Mario Huettel 2017-04-08 1690 /* End of xmit function for version 3.0.x */
10c1c3975a6663 Mario Huettel 2017-04-08 1691 } else {
10c1c3975a6663 Mario Huettel 2017-04-08 1692 /* Transmit routine for version >= v3.1.x */
10c1c3975a6663 Mario Huettel 2017-04-08 1693
c1eaf8b9bd3145 Markus Schneider-Pargmann 2022-12-06 1694 txfqs = m_can_read(cdev, M_CAN_TXFQS);
c1eaf8b9bd3145 Markus Schneider-Pargmann 2022-12-06 1695
10c1c3975a6663 Mario Huettel 2017-04-08 1696 /* Check if FIFO full */
c1eaf8b9bd3145 Markus Schneider-Pargmann 2022-12-06 1697 if (_m_can_tx_fifo_full(txfqs)) {
10c1c3975a6663 Mario Huettel 2017-04-08 1698 /* This shouldn't happen */
10c1c3975a6663 Mario Huettel 2017-04-08 1699 netif_stop_queue(dev);
10c1c3975a6663 Mario Huettel 2017-04-08 1700 netdev_warn(dev,
10c1c3975a6663 Mario Huettel 2017-04-08 1701 "TX queue active although FIFO is full.");
441ac340169b79 Dan Murphy 2019-05-09 1702
441ac340169b79 Dan Murphy 2019-05-09 1703 if (cdev->is_peripheral) {
f524f829b75a7d Dan Murphy 2019-05-09 1704 kfree_skb(skb);
f524f829b75a7d Dan Murphy 2019-05-09 1705 dev->stats.tx_dropped++;
f524f829b75a7d Dan Murphy 2019-05-09 1706 return NETDEV_TX_OK;
f524f829b75a7d Dan Murphy 2019-05-09 1707 } else {
10c1c3975a6663 Mario Huettel 2017-04-08 1708 return NETDEV_TX_BUSY;
10c1c3975a6663 Mario Huettel 2017-04-08 1709 }
f524f829b75a7d Dan Murphy 2019-05-09 1710 }
10c1c3975a6663 Mario Huettel 2017-04-08 1711
10c1c3975a6663 Mario Huettel 2017-04-08 1712 /* get put index for frame */
c1eaf8b9bd3145 Markus Schneider-Pargmann 2022-12-06 1713 putidx = FIELD_GET(TXFQS_TFQPI_MASK, txfqs);
812270e5445bd1 Matt Kline 2021-08-16 1714
812270e5445bd1 Matt Kline 2021-08-16 1715 /* Construct DLC Field, with CAN-FD configuration.
812270e5445bd1 Matt Kline 2021-08-16 1716 * Use the put index of the fifo as the message marker,
812270e5445bd1 Matt Kline 2021-08-16 1717 * used in the TX interrupt for sending the correct echo frame.
812270e5445bd1 Matt Kline 2021-08-16 1718 */
10c1c3975a6663 Mario Huettel 2017-04-08 1719
10c1c3975a6663 Mario Huettel 2017-04-08 1720 /* get CAN FD configuration of frame */
10c1c3975a6663 Mario Huettel 2017-04-08 1721 fdflags = 0;
10c1c3975a6663 Mario Huettel 2017-04-08 1722 if (can_is_canfd_skb(skb)) {
10c1c3975a6663 Mario Huettel 2017-04-08 1723 fdflags |= TX_BUF_FDF;
10c1c3975a6663 Mario Huettel 2017-04-08 1724 if (cf->flags & CANFD_BRS)
10c1c3975a6663 Mario Huettel 2017-04-08 1725 fdflags |= TX_BUF_BRS;
10c1c3975a6663 Mario Huettel 2017-04-08 1726 }
10c1c3975a6663 Mario Huettel 2017-04-08 1727
9a10b9d9f7e946 Markus Schneider-Pargmann 2023-06-21 1728 fifo_element.dlc = FIELD_PREP(TX_BUF_MM_MASK, putidx) |
e39381770ec9ca Matt Kline 2021-08-16 1729 FIELD_PREP(TX_BUF_DLC_MASK, can_fd_len2dlc(cf->len)) |
e39381770ec9ca Matt Kline 2021-08-16 1730 fdflags | TX_BUF_EFC;
10c1c3975a6663 Mario Huettel 2017-04-08 1731
9a10b9d9f7e946 Markus Schneider-Pargmann 2023-06-21 1732 memcpy_and_pad(fifo_element.data, CANFD_MAX_DLEN, &cf->data,
9a10b9d9f7e946 Markus Schneider-Pargmann 2023-06-21 1733 cf->len, 0);
9a10b9d9f7e946 Markus Schneider-Pargmann 2023-06-21 1734
9a10b9d9f7e946 Markus Schneider-Pargmann 2023-06-21 1735 err = m_can_fifo_write(cdev, putidx, M_CAN_FIFO_ID,
9a10b9d9f7e946 Markus Schneider-Pargmann 2023-06-21 1736 &fifo_element, 2 + len_padded);
e39381770ec9ca Matt Kline 2021-08-16 1737 if (err)
e39381770ec9ca Matt Kline 2021-08-16 1738 goto out_fail;
10c1c3975a6663 Mario Huettel 2017-04-08 1739
10c1c3975a6663 Mario Huettel 2017-04-08 1740 /* Push loopback echo.
10c1c3975a6663 Mario Huettel 2017-04-08 1741 * Will be looped back on TX interrupt based on message marker
10c1c3975a6663 Mario Huettel 2017-04-08 1742 */
1dcb6e57db8334 Vincent Mailhol 2021-01-11 1743 can_put_echo_skb(skb, dev, putidx, 0);
10c1c3975a6663 Mario Huettel 2017-04-08 1744
10c1c3975a6663 Mario Huettel 2017-04-08 1745 /* Enable TX FIFO element to start transfer */
441ac340169b79 Dan Murphy 2019-05-09 1746 m_can_write(cdev, M_CAN_TXBAR, (1 << putidx));
10c1c3975a6663 Mario Huettel 2017-04-08 1747
10c1c3975a6663 Mario Huettel 2017-04-08 1748 /* stop network queue if fifo full */
441ac340169b79 Dan Murphy 2019-05-09 1749 if (m_can_tx_fifo_full(cdev) ||
10c1c3975a6663 Mario Huettel 2017-04-08 1750 m_can_next_echo_skb_occupied(dev, putidx))
10c1c3975a6663 Mario Huettel 2017-04-08 1751 netif_stop_queue(dev);
10c1c3975a6663 Mario Huettel 2017-04-08 1752 }
e0d1f4816f2a7e Dong Aisheng 2014-07-16 1753
e0d1f4816f2a7e Dong Aisheng 2014-07-16 1754 return NETDEV_TX_OK;
e39381770ec9ca Matt Kline 2021-08-16 1755
e39381770ec9ca Matt Kline 2021-08-16 1756 out_fail:
e39381770ec9ca Matt Kline 2021-08-16 1757 netdev_err(dev, "FIFO write returned %d\n", err);
e39381770ec9ca Matt Kline 2021-08-16 1758 m_can_disable_all_interrupts(cdev);
e39381770ec9ca Matt Kline 2021-08-16 1759 return NETDEV_TX_BUSY;
e0d1f4816f2a7e Dong Aisheng 2014-07-16 1760 }
e0d1f4816f2a7e Dong Aisheng 2014-07-16 1761
Hi Simon, On Wed, Jun 21, 2023 at 04:19:06PM +0200, Simon Horman wrote: > On Wed, Jun 21, 2023 at 11:23:39AM +0200, Markus Schneider-Pargmann wrote: > > Combine header and data before writing to the transmit fifo to reduce > > the overhead for peripheral chips. > > > > Signed-off-by: Markus Schneider-Pargmann <msp@baylibre.com> > > --- > > drivers/net/can/m_can/m_can.c | 34 +++++++++++++++++++++------------- > > 1 file changed, 21 insertions(+), 13 deletions(-) > > > > diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c > > index a5003435802b..5251073987ee 100644 > > --- a/drivers/net/can/m_can/m_can.c > > +++ b/drivers/net/can/m_can/m_can.c > > @@ -317,6 +317,12 @@ struct id_and_dlc { > > u32 dlc; > > }; > > > > +struct m_can_fifo_element { > > + u32 id; > > + u32 dlc; > > + u8 data[CANFD_MAX_DLEN]; > > +}; > > + > > static inline u32 m_can_read(struct m_can_classdev *cdev, enum m_can_reg reg) > > { > > return cdev->ops->read_reg(cdev, reg); > > @@ -1622,6 +1628,8 @@ static int m_can_next_echo_skb_occupied(struct net_device *dev, int putidx) > > static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev) > > { > > struct canfd_frame *cf = (struct canfd_frame *)cdev->tx_skb->data; > > + u8 len_padded = DIV_ROUND_UP(cf->len, 4); > > + struct m_can_fifo_element fifo_element; > > struct net_device *dev = cdev->net; > > struct sk_buff *skb = cdev->tx_skb; > > struct id_and_dlc fifo_header; > > Hi Markus, > > GCC 12.3.0 complains that fifo_header is not (no longer) used. > > drivers/net/can/m_can/m_can.c:1635:20: warning: unused variable 'fifo_header' [-Wunused-variable] > struct id_and_dlc fifo_header; Yes, I moved everything to fifo_element on purpose and then forgot to remove fifo_header. Removing it now. Thanks, Markus > > -- > pw-bot: changes-requested >
diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index a5003435802b..5251073987ee 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -317,6 +317,12 @@ struct id_and_dlc { u32 dlc; }; +struct m_can_fifo_element { + u32 id; + u32 dlc; + u8 data[CANFD_MAX_DLEN]; +}; + static inline u32 m_can_read(struct m_can_classdev *cdev, enum m_can_reg reg) { return cdev->ops->read_reg(cdev, reg); @@ -1622,6 +1628,8 @@ static int m_can_next_echo_skb_occupied(struct net_device *dev, int putidx) static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev) { struct canfd_frame *cf = (struct canfd_frame *)cdev->tx_skb->data; + u8 len_padded = DIV_ROUND_UP(cf->len, 4); + struct m_can_fifo_element fifo_element; struct net_device *dev = cdev->net; struct sk_buff *skb = cdev->tx_skb; struct id_and_dlc fifo_header; @@ -1635,27 +1643,27 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev) /* Generate ID field for TX buffer Element */ /* Common to all supported M_CAN versions */ if (cf->can_id & CAN_EFF_FLAG) { - fifo_header.id = cf->can_id & CAN_EFF_MASK; - fifo_header.id |= TX_BUF_XTD; + fifo_element.id = cf->can_id & CAN_EFF_MASK; + fifo_element.id |= TX_BUF_XTD; } else { - fifo_header.id = ((cf->can_id & CAN_SFF_MASK) << 18); + fifo_element.id = ((cf->can_id & CAN_SFF_MASK) << 18); } if (cf->can_id & CAN_RTR_FLAG) - fifo_header.id |= TX_BUF_RTR; + fifo_element.id |= TX_BUF_RTR; if (cdev->version == 30) { netif_stop_queue(dev); - fifo_header.dlc = can_fd_len2dlc(cf->len) << 16; + fifo_element.dlc = can_fd_len2dlc(cf->len) << 16; /* Write the frame ID, DLC, and payload to the FIFO element. */ - err = m_can_fifo_write(cdev, 0, M_CAN_FIFO_ID, &fifo_header, 2); + err = m_can_fifo_write(cdev, 0, M_CAN_FIFO_ID, &fifo_element, 2); if (err) goto out_fail; err = m_can_fifo_write(cdev, 0, M_CAN_FIFO_DATA, - cf->data, DIV_ROUND_UP(cf->len, 4)); + cf->data, len_padded); if (err) goto out_fail; @@ -1717,15 +1725,15 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev) fdflags |= TX_BUF_BRS; } - fifo_header.dlc = FIELD_PREP(TX_BUF_MM_MASK, putidx) | + fifo_element.dlc = FIELD_PREP(TX_BUF_MM_MASK, putidx) | FIELD_PREP(TX_BUF_DLC_MASK, can_fd_len2dlc(cf->len)) | fdflags | TX_BUF_EFC; - err = m_can_fifo_write(cdev, putidx, M_CAN_FIFO_ID, &fifo_header, 2); - if (err) - goto out_fail; - err = m_can_fifo_write(cdev, putidx, M_CAN_FIFO_DATA, - cf->data, DIV_ROUND_UP(cf->len, 4)); + memcpy_and_pad(fifo_element.data, CANFD_MAX_DLEN, &cf->data, + cf->len, 0); + + err = m_can_fifo_write(cdev, putidx, M_CAN_FIFO_ID, + &fifo_element, 2 + len_padded); if (err) goto out_fail;