From patchwork Fri Sep 29 14:12:53 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: 146784 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6359:6f87:b0:13f:353d:d1ed with SMTP id tl7csp3561871rwb; Fri, 29 Sep 2023 14:25:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFPd4Izv5OkP+V/hqIur9MeoeSzo5GOnzTOog200Qy2M7abjbu1OHpASsKx2M5xhjU1/U46 X-Received: by 2002:a17:90a:5b0c:b0:26d:287f:a545 with SMTP id o12-20020a17090a5b0c00b0026d287fa545mr4813342pji.29.1696022742439; Fri, 29 Sep 2023 14:25:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696022742; cv=none; d=google.com; s=arc-20160816; b=Qkd/nCnDDrRxKpiNzboqEkNbSB2qgW7fN9ZLCGR7oa69Fgf1b3mi0WLk9pC8JtZLl0 XPovLrgmZMKu6VgZegwTdHjfyTwrrQdp8wJNKk5kGpUkOggBSxhjhSH3OXWmuVVxu7s2 cCGjlPMBNAhIibe3PRNTHJRv4huA8M8Z4MlqLqvnlHo9eJ55e6ep0w/DQv5mRWxw3Vqe rGsbrHt0hWhcT9Qbty40NxeyHny05655Wi76J2y/dBbqDL4LEzh50WhWVqME3Ah8PIHY 2Pp+BEuiV0jzZF3vGhvufSPKQMk503o+jeXwr7dKPeJ/pf2UE0YICXbQ+uXKDWSiSRW4 mAuQ== 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=p1ceCWHuA/YvTIAM9KuiB1pW4xq7NApKmNFkwb8cZVs=; fh=EtuWLR14IhIbZM+E+fYn4isj1Y+iLrncbbgmHIVUFEQ=; b=HaGA5OSSjlY0LTzOTTJJbyNHQ6nlIg3w+XhvnDqVGObqGOrsFwh/vRfcIm0BMEc3OX 9+QqavsPnaT72m6YuoL9VlfmRw8+8laUh85UnRo3bxeOVihhsHhF8DkJxl+9Qhcam9ga 6mMeaxjY6s9uvjebMIGePapB2dEBms8saIdz7zVrU9ONAiGZyaM9Q0kvDQHDYw3z2thq HaleJMKb1pTvCYaWP72x1Jcdzc8tefxe3GBnsqTLXtrdfRHUhXcGDRHJEsh8rEs66Oj9 Zww06t1A8l/5RGVsL5/v2KyPFLgb8cmUmvh6lMiB7I3zl5k12zhB/JgibqewxLwrxgv3 eS7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=pGg4FdbI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id g12-20020a17090a578c00b0026d6ad52473si2186932pji.34.2023.09.29.14.25.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 14:25:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=pGg4FdbI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id CF785804A73D; Fri, 29 Sep 2023 07:14:41 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233293AbjI2ONX (ORCPT + 20 others); Fri, 29 Sep 2023 10:13:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233118AbjI2ONR (ORCPT ); Fri, 29 Sep 2023 10:13:17 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CA4D1B3 for ; Fri, 29 Sep 2023 07:13:15 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-4064876e8b8so40016865e9.0 for ; Fri, 29 Sep 2023 07:13:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1695996793; x=1696601593; darn=vger.kernel.org; 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=p1ceCWHuA/YvTIAM9KuiB1pW4xq7NApKmNFkwb8cZVs=; b=pGg4FdbIS4hmPr00Cyy3WjMkna0QGmrLI1NHgLbL/PG+YgTc6EgKPzLLHyd0GoGzj9 OyGEOe+frtm/wi3hFZobXnY/NEYfxFgvcve0C/Vfm0X/IHn0R3SCwQHdu4nVNeNm+mCi dZQjXdFZ1qfrfy+HysonCsoaitUe3PQLaFN0xhLL3kutbDxSl/BKJgVDCjzk6VBHesv5 7HP8PHQ0kroImXa8uJ9pZZieWG+IE2irgGcbHWVeiGwDfpZv34Vv/TyRjlgWEA7Ovvl6 WZrjTl11wh/1arh31AqOSvEDl5m06v0kbT7pJxYwPjY0mnC3c1NrDwlewUsftDHaRejB ADZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695996793; x=1696601593; 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=p1ceCWHuA/YvTIAM9KuiB1pW4xq7NApKmNFkwb8cZVs=; b=tFm8jFL2dAxoypI/CJ3goaHKKQkhEv9/IoA6043IV1eCPfMll/MLOx+/wjby3+icem lGyMaCekW2bsElyD73rZpQEWCivuRuji6GAfP7/FH6RKIBHK8eoQlnWR4xChDmNSCmRQ xAVgPOxpvcYqSKXpRZi5r0nrrDGkL3D4LwC/EnSFE6FWOjgApu6Qigb3FaUvviiT7ReT YxomU4jXqOVMikaUpV/pOTN0G+KUO5DaSYLoHDMKGN+QoahALJdao4JSQSHpnhtStMOb 0395g40E9dI5PYRzYLBDojLEVpsenX1Tu7Lr/OADexi3kKFd37CYlJw0vSiCQkvuUfE2 7hhg== X-Gm-Message-State: AOJu0Yyw+FkMARndeVSyO+DzPAAfm7fnQfT/Vk/OBSX6R9DC9uQeyiH/ m/5tWTbXOUXD00l+vk9BUXASqg== X-Received: by 2002:a7b:c7d5:0:b0:401:c338:ab96 with SMTP id z21-20020a7bc7d5000000b00401c338ab96mr4366326wmk.34.1695996793666; Fri, 29 Sep 2023 07:13:13 -0700 (PDT) Received: from blmsp.fritz.box ([2001:4091:a246:8222:dbda:9cd9:39cc:f174]) by smtp.gmail.com with ESMTPSA id t25-20020a7bc3d9000000b00405391f485fsm1513068wmj.41.2023.09.29.07.13.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 07:13:13 -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 , Judith Mendez , Markus Schneider-Pargmann Subject: [PATCH v6 03/14] can: m_can: Write transmit header and data in one transaction Date: Fri, 29 Sep 2023 16:12:53 +0200 Message-Id: <20230929141304.3934380-4-msp@baylibre.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230929141304.3934380-1-msp@baylibre.com> References: <20230929141304.3934380-1-msp@baylibre.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,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 agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Fri, 29 Sep 2023 07:14:41 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778408743101870313 X-GMAIL-MSGID: 1778408743101870313 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 45391492339e..a01c9261331d 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -320,6 +320,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); @@ -1637,9 +1643,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; @@ -1650,27 +1657,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; @@ -1732,15 +1739,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;