From patchwork Tue Jul 18 07:56:57 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: 121841 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp1578012vqt; Tue, 18 Jul 2023 01:01:50 -0700 (PDT) X-Google-Smtp-Source: APBJJlEEd63L26yMxoNPl04rBYPxbtiBq4sj1ep6jvgUJEFrmLeQuWGjfmsVO+Qa0MNGim6EVVUO X-Received: by 2002:a17:906:dfee:b0:991:e7c3:5712 with SMTP id lc14-20020a170906dfee00b00991e7c35712mr11463028ejc.30.1689667309681; Tue, 18 Jul 2023 01:01:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689667309; cv=none; d=google.com; s=arc-20160816; b=QFH/cvM09hVXVxNrfwU6sdqc9Kxgt4m9q07SOMC91vqRwiuIKbwumffTLQUX+95Hvl Y4SNVat5pNbVUDFC42d0li1mc3N3vGDiYDX34m+i5slvGz7l1P8wVETqsTIsQFQPCxUy ZQ5GtbkL1puWSLZdFaCji8cgaKSdluZgPIk+sBCYGrAYm4+PcMUY0RAknbEpNQi+9AeS mWvUDLjJ1sVaTSCTLglHUWI6Gn3jVcwbfcr36snwtTMAXy5L5sQ+ZMc4RNZdA1ShyFLH EWL7urdn2TMs6rgMHhZt1vrlWox9ngIK8BAqZQxi5rhatKLzxUrPzfeciznisVOzAo/+ sAPw== 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=Ow0KD5sZWSRWo56RZ6bdbR/6fl1YYZAbnlt0NuXgAUU=; fh=HEvpsrq2tYe3N9GuSJCCr6vVuOqDDDbQ2hrVJYmjlns=; b=v/oZdzkFjQGY53zN2ZaRWaqIk7lvZZaijch87SEKJbmqxdV2GO9sB47T1AlgXPt3ai soiz+6fqNF2fXG1W+zVhVmQp8xdV5FT1/7yzqW8vDQckdNltnbWCY7hzSm7r+SKV+5d5 zGHpHebTIPDL7UYSCFJSQFU5djzJWazsgM0fg2t7ZWblMhgTsVkkFU8mhPWPTcNbiA4T C9etHFOiEtQszf9TuuMDatNupN+bH0cfvV0fO7L8F0pkFxrtjlI40pambeaNghEt4D9l i3R7lSNL5wgRXJ1YHh5PY4CgZIx+56MX5avSdwAPx5CI5Jhrdwq2qcIhFEPuyL9cC1Ji di0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20221208.gappssmtp.com header.s=20221208 header.b=Dr6uZBsW; 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 lv19-20020a170906bc9300b00991d54db2afsi789305ejb.702.2023.07.18.01.01.24; Tue, 18 Jul 2023 01:01:49 -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=Dr6uZBsW; 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 S231804AbjGRH5r (ORCPT + 99 others); Tue, 18 Jul 2023 03:57:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231667AbjGRH5m (ORCPT ); Tue, 18 Jul 2023 03:57:42 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 442D61988 for ; Tue, 18 Jul 2023 00:57:15 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-317009c0f9aso1987866f8f.0 for ; Tue, 18 Jul 2023 00:57:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20221208.gappssmtp.com; s=20221208; t=1689667033; x=1690271833; 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=Ow0KD5sZWSRWo56RZ6bdbR/6fl1YYZAbnlt0NuXgAUU=; b=Dr6uZBsWOW5xzIal3C1gWSsSF3hXGn/01ZqnqhiOT3glIWr69J+wehas+wZdf79Q8z R4MxreQ4C4Ij+Lnxe+en7E46th/3IOLl1wlRD/UN0m015lsVdEf6u1ApyXkIp8Af8jIL rNqP+Bg5osfj+iATiTjgfurqIIKaUqdSEC/WCCdonQbcIKF5pLv4AN1U4+CHZdZzyHc9 7g7vUfcK3sgMy9v3uBRJs6rQF4Yk6x2rrLRVEkzP45nGm6cW30/S4XWZiKX7ha5haxLU pzBoBaiMuCq9Qkbx4K5ZQ3as5lcIQ6VT/VmvFrQO/HyV78ZXt/uDEdnaFCTf68Fjr/io RgBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689667033; x=1690271833; 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=Ow0KD5sZWSRWo56RZ6bdbR/6fl1YYZAbnlt0NuXgAUU=; b=HvmIrxl6kusvvLybH+PGNq4FqCIDGU4xMSaJfoU7fFh7SYCkg8WICoYdrVKpjVDzs+ XXaviTsE6+h4Z9p7o99akZWhuwHIFOQ9DbF9HzkJaiEzQ4WCI72vg3uZaScZVTnw5+6O GHIpRslid0hZ8qigGBuC/JkrVKeompjmU5ueGx2ySou/VlfJQ10QIrjRkF5+vLQnFDuq bAYtGyrasQC0sA1DtWajI/vwCufCTfdycyRAZA7b5+oDULs5AVC4gyxVJOEywoQjZDGz CNvwN98g78kWARVGOSPlqEby7lQLks6HLPQPea2QQhSlyuTP07gmBQw6/EpDobzxePw+ 5JmA== X-Gm-Message-State: ABy/qLZ9I2wHmZK6q6S38HgZNsMyxeARwltuEWP15NX2dyRvTP9kIBfe TPT6B2dXIVGKzF8MaF8Z1SWoSw== X-Received: by 2002:a5d:670e:0:b0:314:12c:4322 with SMTP id o14-20020a5d670e000000b00314012c4322mr12924963wru.4.1689667033188; Tue, 18 Jul 2023 00:57:13 -0700 (PDT) Received: from blmsp.fritz.box ([2001:4091:a247:82fa:b762:4f68:e1ed:5041]) by smtp.gmail.com with ESMTPSA id x4-20020a5d54c4000000b003142439c7bcsm1585959wrv.80.2023.07.18.00.57.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jul 2023 00:57:12 -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 v5 01/12] can: m_can: Write transmit header and data in one transaction Date: Tue, 18 Jul 2023 09:56:57 +0200 Message-Id: <20230718075708.958094-2-msp@baylibre.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230718075708.958094-1-msp@baylibre.com> References: <20230718075708.958094-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_BLOCKED,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: INBOX X-GMAIL-THRID: 1771744589131087657 X-GMAIL-MSGID: 1771744589131087657 Combine header and data before writing to the transmit fifo to reduce the overhead for peripheral chips. Signed-off-by: Markus Schneider-Pargmann Reviewed-by: Simon Horman --- drivers/net/can/m_can/m_can.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index c5af92bcc9c9..478e0670f0d1 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,9 +1628,10 @@ 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; u32 cccr, fdflags; u32 txfqs; int err; @@ -1635,27 +1642,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 +1724,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;