From patchwork Wed Jun 21 09:23:39 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: 110895 Return-Path: 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 + 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 ); 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 ; Wed, 21 Jun 2023 02:23:58 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-3f9bff0a543so3543865e9.3 for ; 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 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 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 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?1769303847679326566?= X-GMAIL-MSGID: =?utf-8?q?1769303847679326566?= Combine header and data before writing to the transmit fifo to reduce the overhead for peripheral chips. Signed-off-by: Markus Schneider-Pargmann --- 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; @@ -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; From patchwork Wed Jun 21 09:23:40 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: 110896 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4231727vqr; Wed, 21 Jun 2023 02:27:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5BHyX6ZWt6j8H0XI8OCE95PqQJ8pRtg0lADOzL2rdvVn2S/B7ZubuvsXvUnbsV8iRg4ALv X-Received: by 2002:a17:902:ec85:b0:1b0:f31:a386 with SMTP id x5-20020a170902ec8500b001b00f31a386mr31415823plg.26.1687339650384; Wed, 21 Jun 2023 02:27:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687339650; cv=none; d=google.com; s=arc-20160816; b=An4KuRq/38y9BItazL93QaBsoQiyEn96YEk3WK38rVdpUgy8ThoZlfZ6JKNYcDNuSl 33LPsroZOIeutDDsZ69wz9GVwB1obJkIm80HaiggCKT2F+unDAVD2JBP6Osia6hbZivs pFjVTC6C1E06rD9uhZn0NFLqHP36sVDSkDX0dxNn2/5v2NjsNt9dikV7yLRX+hq/Bv4w qJxC/5CJriEmj3Y6EWmd245PXDJLKVj/tdTHhgGPoKDOAtWDB4S8ifJK5DrG6ACagjnk 5qfKeH2ew/AdyXu906FJJOFnxpHibD0yS/EDmcT+AdFz3o03Q4ZVJ1Toly/f/HG3Rc/N fbQA== 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=YG6xa4Mbl+d0vaAdAyRdBK5qcXVedx+n3F0VVlmxXq4=; b=bnHmkLSRzAHMBFPgLkDmsqKav4lb5FAqWx2kSu+DdZ/a4e0bu9I6+qv5xX5AXZV0rV o/ocBBclKh22Sjg3etKd5q2VpCQLksNAWMB2Ium44ad7ZGzC5gBf+QlGu7p4gPu89dZk xP5Yq/dEPAe8WvTd2VLsCWmpcmjdO0FNB2ZTSyDyNqNUxvrdb3nBfcuF5UnK9K0CSYDI YO9YNutzXJn9EUNcVZ2BJCf1/6E0D/235bg2m5fTK+VKOYlk0xJfosjkPh0RXLF9kEYq dR5QxUFgyEdOBdYot7KimXHti2oaWD04rFRbM5qI+plI8Mes4RLn7n9eYu8uz8LEeq9h MOMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20221208.gappssmtp.com header.s=20221208 header.b=o7gQISJb; 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 n10-20020a170902e54a00b001b53d8f2cd1si4121049plf.29.2023.06.21.02.27.17; Wed, 21 Jun 2023 02:27:30 -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=o7gQISJb; 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 S231622AbjFUJYb (ORCPT + 99 others); Wed, 21 Jun 2023 05:24:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231282AbjFUJYS (ORCPT ); Wed, 21 Jun 2023 05:24:18 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A15919BE for ; Wed, 21 Jun 2023 02:23:59 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-3111cb3dda1so6539000f8f.0 for ; Wed, 21 Jun 2023 02:23:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20221208.gappssmtp.com; s=20221208; t=1687339438; x=1689931438; 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=YG6xa4Mbl+d0vaAdAyRdBK5qcXVedx+n3F0VVlmxXq4=; b=o7gQISJbu5AFv6piaVytdRxRrDk6G7BRNFqjAZYFCSw/ZswAdv+NrzyRHFaIO29+B0 OlSBDO56lBGikCjgmcbj1drM6C/xE3Wu+OAThQIDgIpRCGp+QB0qYXYlZ1ed+xE6ELxO SHdwvleOro53n3sx6iLX2jF+hO5ojaRhOAqrrOKE7OBG0oH6Vt2wH6uPAyE9BBmnTod0 rpsn6Aft1C7vKF+v1qpQX8Yplg132muYNxvZwdM56j8eW0XDd+DNzd894BTKBNbUTymV uV7zE9c+PxzquJb90JYAhFfhNoE1XdEGghe7vVvmuxMAkB87e4EP7fajG3yynP3WtHAk Hpsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687339438; x=1689931438; 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=YG6xa4Mbl+d0vaAdAyRdBK5qcXVedx+n3F0VVlmxXq4=; b=FqVWYOhJF8ZVv3SH22xB2AzLT3Hw0abastlWqqA54BgG5DPrsfrvQgovCy29K7Rtfx avcZ23b1ifsfL6ygWFEuEFq0S7VY5UI83X5/AvWhR/25YMoiJHriCxx5JYXirj8wx77L WhMcLEQSCwTz+iG2LKcOusAN2y3xAb+Wkd4TkG5SNPc0ag6tIpdeqifC2EcKFYVeNPEh aLJHphDsnyk1Cu1SvxtwXbJ2ANJvDOQL97xM2krbmRBWivCGgX9wYrTb3Hl9/a0RLPsq ZsuOG1kFKGknSaa+dUAbnZ3V6JOIsXSVYsTrzOJGInub/Yt2JfC7tLkDIfBHklZL0Euv zjhg== X-Gm-Message-State: AC+VfDz3oNC8AnFEnQSJFK33C8K+X9NyykYBieu/HuBrSskYKWWEAYsC LLeyL1SMqtoSwlKswDUdOyP4Pg== X-Received: by 2002:a5d:4d4e:0:b0:311:d5d:1326 with SMTP id a14-20020a5d4d4e000000b003110d5d1326mr15128365wru.27.1687339438053; Wed, 21 Jun 2023 02:23:58 -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.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jun 2023 02:23:57 -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 02/12] can: m_can: Implement receive coalescing Date: Wed, 21 Jun 2023 11:23:40 +0200 Message-Id: <20230621092350.3130866-3-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?1769303860997284549?= X-GMAIL-MSGID: =?utf-8?q?1769303860997284549?= m_can offers the possibility to set an interrupt on reaching a watermark level in the receive FIFO. This can be used to implement coalescing. Unfortunately there is no hardware timeout available to trigger an interrupt if only a few messages were received within a given time. To solve this I am using a hrtimer to wake up the irq thread after x microseconds. The timer is always started if receive coalescing is enabled and new received frames were available during an interrupt. The timer is stopped if during a interrupt handling no new data was available. If the timer is started the new item interrupt is disabled and the watermark interrupt takes over. If the timer is not started again, the new item interrupt is enabled again, notifying the handler about every new item received. Signed-off-by: Markus Schneider-Pargmann Reviewed-by: Simon Horman --- drivers/net/can/m_can/m_can.c | 70 ++++++++++++++++++++++++++++++++--- drivers/net/can/m_can/m_can.h | 7 ++++ 2 files changed, 71 insertions(+), 6 deletions(-) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index 5251073987ee..02dfb416fbd2 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -419,6 +419,22 @@ static void m_can_config_endisable(struct m_can_classdev *cdev, bool enable) } } +static void m_can_interrupt_enable(struct m_can_classdev *cdev, u32 interrupts) +{ + if (cdev->active_interrupts == interrupts) + return; + cdev->ops->write_reg(cdev, M_CAN_IE, interrupts); + cdev->active_interrupts = interrupts; +} + +static void m_can_coalescing_disable(struct m_can_classdev *cdev) +{ + u32 new_interrupts = cdev->active_interrupts | IR_RF0N; + + hrtimer_cancel(&cdev->irq_timer); + m_can_interrupt_enable(cdev, new_interrupts); +} + static inline void m_can_enable_all_interrupts(struct m_can_classdev *cdev) { /* Only interrupt line 0 is used in this driver */ @@ -427,6 +443,7 @@ static inline void m_can_enable_all_interrupts(struct m_can_classdev *cdev) static inline void m_can_disable_all_interrupts(struct m_can_classdev *cdev) { + m_can_coalescing_disable(cdev); m_can_write(cdev, M_CAN_ILE, 0x0); } @@ -1076,15 +1093,39 @@ static int m_can_echo_tx_event(struct net_device *dev) return err; } +static void m_can_coalescing_update(struct m_can_classdev *cdev, u32 ir) +{ + u32 new_interrupts = cdev->active_interrupts; + bool enable_timer = false; + + if (cdev->rx_coalesce_usecs_irq > 0 && (ir & (IR_RF0N | IR_RF0W))) { + enable_timer = true; + new_interrupts &= ~IR_RF0N; + } else if (!hrtimer_active(&cdev->irq_timer)) { + new_interrupts |= IR_RF0N; + } + + m_can_interrupt_enable(cdev, new_interrupts); + if (enable_timer) { + hrtimer_start(&cdev->irq_timer, + ns_to_ktime(cdev->rx_coalesce_usecs_irq * NSEC_PER_USEC), + HRTIMER_MODE_REL); + } +} + static irqreturn_t m_can_isr(int irq, void *dev_id) { struct net_device *dev = (struct net_device *)dev_id; struct m_can_classdev *cdev = netdev_priv(dev); u32 ir; - if (pm_runtime_suspended(cdev->dev)) + if (pm_runtime_suspended(cdev->dev)) { + m_can_coalescing_disable(cdev); return IRQ_NONE; + } + ir = m_can_read(cdev, M_CAN_IR); + m_can_coalescing_update(cdev, ir); if (!ir) return IRQ_NONE; @@ -1099,13 +1140,17 @@ static irqreturn_t m_can_isr(int irq, void *dev_id) * - state change IRQ * - bus error IRQ and bus error reporting */ - if ((ir & IR_RF0N) || (ir & IR_ERR_ALL_30X)) { + if (ir & (IR_RF0N | IR_RF0W | IR_ERR_ALL_30X)) { cdev->irqstatus = ir; if (!cdev->is_peripheral) { m_can_disable_all_interrupts(cdev); napi_schedule(&cdev->napi); - } else if (m_can_rx_peripheral(dev, ir) < 0) { - goto out_fail; + } else { + int pkts; + + pkts = m_can_rx_peripheral(dev, ir); + if (pkts < 0) + goto out_fail; } } @@ -1141,6 +1186,15 @@ static irqreturn_t m_can_isr(int irq, void *dev_id) return IRQ_HANDLED; } +static enum hrtimer_restart m_can_irq_timer(struct hrtimer *timer) +{ + struct m_can_classdev *cdev = container_of(timer, struct m_can_classdev, irq_timer); + + irq_wake_thread(cdev->net->irq, cdev->net); + + return HRTIMER_NORESTART; +} + static const struct can_bittiming_const m_can_bittiming_const_30X = { .name = KBUILD_MODNAME, .tseg1_min = 2, /* Time segment 1 = prop_seg + phase_seg1 */ @@ -1281,7 +1335,7 @@ static int m_can_chip_config(struct net_device *dev) /* Disable unused interrupts */ interrupts &= ~(IR_ARA | IR_ELO | IR_DRX | IR_TEFF | IR_TEFW | IR_TFE | IR_TCF | IR_HPM | IR_RF1F | IR_RF1W | IR_RF1N | - IR_RF0F | IR_RF0W); + IR_RF0F); m_can_config_endisable(cdev, true); @@ -1325,6 +1379,7 @@ static int m_can_chip_config(struct net_device *dev) /* rx fifo configuration, blocking mode, fifo size 1 */ m_can_write(cdev, M_CAN_RXF0C, + FIELD_PREP(RXFC_FWM_MASK, cdev->rx_max_coalesced_frames_irq) | FIELD_PREP(RXFC_FS_MASK, cdev->mcfg[MRAM_RXF0].num) | cdev->mcfg[MRAM_RXF0].off); @@ -1383,7 +1438,7 @@ static int m_can_chip_config(struct net_device *dev) else interrupts &= ~(IR_ERR_LEC_31X); } - m_can_write(cdev, M_CAN_IE, interrupts); + m_can_interrupt_enable(cdev, interrupts); /* route all interrupts to INT0 */ m_can_write(cdev, M_CAN_ILS, ILS_ALL_INT0); @@ -2048,6 +2103,9 @@ int m_can_class_register(struct m_can_classdev *cdev) of_can_transceiver(cdev->net); + hrtimer_init(&cdev->irq_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); + cdev->irq_timer.function = m_can_irq_timer; + dev_info(cdev->dev, "%s device registered (irq=%d, version=%d)\n", KBUILD_MODNAME, cdev->net->irq, cdev->version); diff --git a/drivers/net/can/m_can/m_can.h b/drivers/net/can/m_can/m_can.h index a839dc71dc9b..c59099d3f5b9 100644 --- a/drivers/net/can/m_can/m_can.h +++ b/drivers/net/can/m_can/m_can.h @@ -84,6 +84,8 @@ struct m_can_classdev { struct sk_buff *tx_skb; struct phy *transceiver; + struct hrtimer irq_timer; + struct m_can_ops *ops; int version; @@ -92,6 +94,11 @@ struct m_can_classdev { int pm_clock_support; int is_peripheral; + // Cached M_CAN_IE register content + u32 active_interrupts; + u32 rx_max_coalesced_frames_irq; + u32 rx_coalesce_usecs_irq; + struct mram_cfg mcfg[MRAM_CFG_NUM]; }; From patchwork Wed Jun 21 09:23:41 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: 110907 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4234392vqr; Wed, 21 Jun 2023 02:33:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6BBNMvgRC+dlO+UDpv2k1W0NxUgOFoxWDpa7uvFUTjgNJH5X2Sf22gFerK9DPIazSy3E72 X-Received: by 2002:a05:6a00:3a23:b0:668:9fb6:b311 with SMTP id fj35-20020a056a003a2300b006689fb6b311mr4309066pfb.32.1687339986231; Wed, 21 Jun 2023 02:33:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687339986; cv=none; d=google.com; s=arc-20160816; b=ttfpSH0MDyp7SWeAYHoSdAWvY7siiLEfCgdQFIeygdWRSAiWWxH31dbwq60aaPKFUc uhwz3AGURY9N0aAfdCabA6jsgKdqr38TkmSNcRyBy3KPDtnNENBn+RWkIGOAOOgsVoUs PjGlRnyGRd/29MWgojVtHpdSqUHBeTMhkdiBERlZBl4mvZP/E2a6TQl0nDRFAofcxVfx NIVZJF/oSziK4yWOq4Cde6JN12+5YMpeqcuFKM7c/gkJJLwZknXcFFqeNA92uqW2bdun C/lSw/t/NW/+zx7ho+m9PW7LeasSrqhUF/OMjZ2uaFksdZySFFJ0C5eXmqFfwICxXv+p z22w== 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=8v5k5o/gMnpilWzbPmb6WUpQE5lj/WdytRr00JhzuWo=; b=sPURncebMG1BTealOcOS0GX6a7wT5UfaJRXNTcDwu3s0ILbxLlgwsYimgcdsLrSkDX 19H6xmJIZ3jyOEaRZ7HOimq99EPKi5nyZ6VMbK5VMykIhKukx/ndzdGRtUtu9JgBQzNY NJGhAnjicaaXnErXecVAU7NsUKyUB+9lT/MEEnqrQO5oeLBVXp4eU4wiIGI26Wpuu18F mcGTeASwa12VD4Qq/bKH250t78uXEX/d7gF/foQ2Lir3W1dMCZW5S3AzaVS9ZRZqo0iV 3ELTHmP0dRMXdSrIxYNVq2e7sB+xyxTwru4hDSvNioIdyoisteSllSM/cEOE5Z3EqfGB cuQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20221208.gappssmtp.com header.s=20221208 header.b=1yoEyFt5; 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 p2-20020aa79e82000000b00668873710d9si3748906pfq.162.2023.06.21.02.32.53; Wed, 21 Jun 2023 02:33:06 -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=1yoEyFt5; 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 S231450AbjFUJYh (ORCPT + 99 others); Wed, 21 Jun 2023 05:24:37 -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 S231352AbjFUJYT (ORCPT ); Wed, 21 Jun 2023 05:24:19 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A30601FC0 for ; Wed, 21 Jun 2023 02:24:00 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-312863a983fso785063f8f.2 for ; Wed, 21 Jun 2023 02:24:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20221208.gappssmtp.com; s=20221208; t=1687339439; x=1689931439; 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=8v5k5o/gMnpilWzbPmb6WUpQE5lj/WdytRr00JhzuWo=; b=1yoEyFt5GM967nuJr28zmMpjw2qA3oiqhf6CIy3w8pbT15KKygG3KPEktVrKijFGpv jj54cY3E0rWzM3U4xGlY+88q4YnZPTIXzO9K28Yqujd+Mvephs5uAKvnCjiKebdHpg9D Ptb0y2cm3Arhxo0rgUABNoe9Cn3qEWPmdIowVDiOLyzViuV3iM6/blucHS8zl0GOQKcn Q7Ja1geYPZE+/Axv0QnDiBNNPHUbvXeoxbGcZWJW1qyjdEAJqaCerkIScCpSZ12jQ4eI dxdb3Qz5o8wLtARdXWmd4OWlLWBIie+xGD1scLZ5DHtycSymIuO7m6h1iLzI3CcIWDrB 4Uig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687339439; x=1689931439; 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=8v5k5o/gMnpilWzbPmb6WUpQE5lj/WdytRr00JhzuWo=; b=Ts0s6WvTBp9xrfkvThhBu/KTaDtQIZXLfv9NRanN/Y3Zi2dHFANRvmEFEPkhInqEe9 7mkd26LlrjLo/3F85FXZpuZSIbxQWSyZ/8aRJSUWDTMNtnFQMI9a2Y2py7BWfo7oQBOy CMRrIUdC/MtV/sqEBh2pfm5uq4uokR7drVDMA09pfDPOR0spYc7NORhLoJEC9JGoNkMH ip+vcN2/WvUBI71Om+QEfRbghe+wbGKdX9NXaueyI9pcsDXVyM2EMHw3F6BBV+fChgyQ CjlwCk5PLkdjIR4Af4Nl+vdzi4hxpSe5HSEDMcNomxN2l6QBPeQ/GhJCMAO3GODrfNnw PQaQ== X-Gm-Message-State: AC+VfDy8jTiSvmQOftEnQPVBYWmnVI6Okxvhoj0ZnJ2K+juSRCIR7+nK 7zixQL3s4GVIlI5pysNnt2yW4w== X-Received: by 2002:adf:dcc3:0:b0:311:1946:fe7d with SMTP id x3-20020adfdcc3000000b003111946fe7dmr11672853wrm.53.1687339439115; Wed, 21 Jun 2023 02:23:59 -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.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jun 2023 02:23:58 -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 03/12] can: m_can: Implement transmit coalescing Date: Wed, 21 Jun 2023 11:23:41 +0200 Message-Id: <20230621092350.3130866-4-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?1769304213603207545?= X-GMAIL-MSGID: =?utf-8?q?1769304213603207545?= Extend the coalescing implementation for transmits. In normal mode the chip raises an interrupt for every finished transmit. This implementation switches to coalescing mode as soon as an interrupt handled a transmit. For coalescing the watermark level interrupt is used to interrupt exactly after x frames were sent. It switches back into normal mode once there was an interrupt with no finished transmit and the timer being inactive. The timer is shared with receive coalescing. The time for receive and transmit coalescing timers have to be the same for that to work. The benefit is to have only a single running timer. Signed-off-by: Markus Schneider-Pargmann Reviewed-by: Simon Horman --- drivers/net/can/m_can/m_can.c | 33 ++++++++++++++++++++------------- drivers/net/can/m_can/m_can.h | 3 +++ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index 02dfb416fbd2..781f287e7ce4 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -255,6 +255,7 @@ enum m_can_reg { #define TXESC_TBDS_64B 0x7 /* Tx Event FIFO Configuration (TXEFC) */ +#define TXEFC_EFWM_MASK GENMASK(29, 24) #define TXEFC_EFS_MASK GENMASK(21, 16) /* Tx Event FIFO Status (TXEFS) */ @@ -429,7 +430,7 @@ static void m_can_interrupt_enable(struct m_can_classdev *cdev, u32 interrupts) static void m_can_coalescing_disable(struct m_can_classdev *cdev) { - u32 new_interrupts = cdev->active_interrupts | IR_RF0N; + u32 new_interrupts = cdev->active_interrupts | IR_RF0N | IR_TEFN; hrtimer_cancel(&cdev->irq_timer); m_can_interrupt_enable(cdev, new_interrupts); @@ -1096,21 +1097,26 @@ static int m_can_echo_tx_event(struct net_device *dev) static void m_can_coalescing_update(struct m_can_classdev *cdev, u32 ir) { u32 new_interrupts = cdev->active_interrupts; - bool enable_timer = false; + bool enable_rx_timer = false; + bool enable_tx_timer = false; if (cdev->rx_coalesce_usecs_irq > 0 && (ir & (IR_RF0N | IR_RF0W))) { - enable_timer = true; + enable_rx_timer = true; new_interrupts &= ~IR_RF0N; - } else if (!hrtimer_active(&cdev->irq_timer)) { - new_interrupts |= IR_RF0N; } + if (cdev->tx_coalesce_usecs_irq > 0 && (ir & (IR_TEFN | IR_TEFW))) { + enable_tx_timer = true; + new_interrupts &= ~IR_TEFN; + } + if (!enable_rx_timer && !hrtimer_active(&cdev->irq_timer)) + new_interrupts |= IR_RF0N; + if (!enable_tx_timer && !hrtimer_active(&cdev->irq_timer)) + new_interrupts |= IR_TEFN; m_can_interrupt_enable(cdev, new_interrupts); - if (enable_timer) { - hrtimer_start(&cdev->irq_timer, - ns_to_ktime(cdev->rx_coalesce_usecs_irq * NSEC_PER_USEC), + if (enable_rx_timer | enable_tx_timer) + hrtimer_start(&cdev->irq_timer, cdev->irq_timer_wait, HRTIMER_MODE_REL); - } } static irqreturn_t m_can_isr(int irq, void *dev_id) @@ -1165,7 +1171,7 @@ static irqreturn_t m_can_isr(int irq, void *dev_id) netif_wake_queue(dev); } } else { - if (ir & IR_TEFN) { + if (ir & (IR_TEFN | IR_TEFW)) { /* New TX FIFO Element arrived */ if (m_can_echo_tx_event(dev) != 0) goto out_fail; @@ -1333,9 +1339,8 @@ static int m_can_chip_config(struct net_device *dev) } /* Disable unused interrupts */ - interrupts &= ~(IR_ARA | IR_ELO | IR_DRX | IR_TEFF | IR_TEFW | IR_TFE | - IR_TCF | IR_HPM | IR_RF1F | IR_RF1W | IR_RF1N | - IR_RF0F); + interrupts &= ~(IR_ARA | IR_ELO | IR_DRX | IR_TEFF | IR_TFE | IR_TCF | + IR_HPM | IR_RF1F | IR_RF1W | IR_RF1N | IR_RF0F); m_can_config_endisable(cdev, true); @@ -1372,6 +1377,8 @@ static int m_can_chip_config(struct net_device *dev) } else { /* Full TX Event FIFO is used */ m_can_write(cdev, M_CAN_TXEFC, + FIELD_PREP(TXEFC_EFWM_MASK, + cdev->tx_max_coalesced_frames_irq) | FIELD_PREP(TXEFC_EFS_MASK, cdev->mcfg[MRAM_TXE].num) | cdev->mcfg[MRAM_TXE].off); diff --git a/drivers/net/can/m_can/m_can.h b/drivers/net/can/m_can/m_can.h index c59099d3f5b9..d0c21eddb6ec 100644 --- a/drivers/net/can/m_can/m_can.h +++ b/drivers/net/can/m_can/m_can.h @@ -85,6 +85,7 @@ struct m_can_classdev { struct phy *transceiver; struct hrtimer irq_timer; + ktime_t irq_timer_wait; struct m_can_ops *ops; @@ -98,6 +99,8 @@ struct m_can_classdev { u32 active_interrupts; u32 rx_max_coalesced_frames_irq; u32 rx_coalesce_usecs_irq; + u32 tx_max_coalesced_frames_irq; + u32 tx_coalesce_usecs_irq; struct mram_cfg mcfg[MRAM_CFG_NUM]; }; From patchwork Wed Jun 21 09:23:42 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: 110898 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4233772vqr; Wed, 21 Jun 2023 02:31:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Xznb+gNwoaWNVhEIXmuapLh/V4AYpRtxeX9cyJMOKqh6DZgj2LldmcUZnugzkJCg7Q2iE X-Received: by 2002:a05:6808:5d3:b0:397:f2bb:b26e with SMTP id d19-20020a05680805d300b00397f2bbb26emr6576617oij.34.1687339902614; Wed, 21 Jun 2023 02:31:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687339902; cv=none; d=google.com; s=arc-20160816; b=gWh2O/jk93UXovcXxpoSR8CbwmB6lvHTSfZ87GGdgdc0YU3YuHTrR2r3RST58mF9bC AT4h2PQaT8eV+3dLWGuYMZd34VxHzvy5lZpW4XQB5EjpvLxtwlRi7OPV1Cs/cRq+Iigu rYUh7S9PykyVDBcWQVb9e20v3nQPETytPb+QD6euDp1ugFKpTrSep2XMs0S6usfIPAI1 sNKLdDKZj/9cQbkjmDs9K6c2lBR+XMMvVYKC/gMA3zVKYBoicU4lXRAjip21mehKSDvf mdGEAMXD31q9Enet1vrT5YYOYljVXySaGBSCNMDG4JzOCNxtshwlw2qa/gvbI21oPBUs ZVSA== 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=hZrlIC4UOKpv9upRfhGvF2jtmIJyO/l6blnJN/Kvfh8=; b=XEMfC27OSiYP+LSekk0Cqy3/Z9eCJFARrJzTjWHsEkNs3of5hjEPUN1vN9ELGTMARK 14dLeQ2A/k5LDWLLmoTHfZD0HTD2++tHhOFrG/A4qRkzfe+G/D8w4Ktti2B4H5nf/44w iHlckta9JREFEZdWn8t7SZ4xwU1KodS+XXXO2JPL0XSwUt8lFEaCjpFl66JQuMuNMj/t hw2TZEMMDL7Y6uOL9P0/PyoP5gYO1s7X5Zi29J/+7opcw2FS30IM2ffEJ/OfM7IUCXej BrCddnnTWRzFsk5zleyOlQfePeBQVVmQ6pezcY7thq2hBmVUHhuO3dQ7OE8rBR+abboT 6j3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20221208.gappssmtp.com header.s=20221208 header.b=5AJVy31q; 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 x17-20020a63b211000000b005538bf65e5bsi37950pge.435.2023.06.21.02.31.28; Wed, 21 Jun 2023 02:31:42 -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=5AJVy31q; 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 S231675AbjFUJYm (ORCPT + 99 others); Wed, 21 Jun 2023 05:24:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230264AbjFUJYU (ORCPT ); Wed, 21 Jun 2023 05:24:20 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A90A61FC6 for ; Wed, 21 Jun 2023 02:24:01 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-31121494630so6561177f8f.3 for ; Wed, 21 Jun 2023 02:24:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20221208.gappssmtp.com; s=20221208; t=1687339440; x=1689931440; 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=hZrlIC4UOKpv9upRfhGvF2jtmIJyO/l6blnJN/Kvfh8=; b=5AJVy31qidMPxttaXsZUnYinlqnN0ERHOCEPlFbpjhFQL0d2YW5FREmg5TuJvUv2zo ecphYqOVzQxJJgvfgN5yoHmX9CrOqcIEYtbUk3uS39swqBrpXxvulFYG5DWRE5729iQZ 3FzNnptBBB/Pk+4DuPLO5YoRsA8Durq9oiW1ETBphaiHhSQ06U2920rL8Lk+SYNOSCzb AUTywM8/yoxyC+wVvrnqoTdv4ldgiiBHmq8zCFWlx+JKvX9lqF+PwhGXTi0lUBtu10PI DXcGyfuzb2tCDlD4yt5Kj29fe+zHBBHvF2aZ45gUwPyHO7hdKqdH1SdhtO1aX8u7wBVT bvHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687339440; x=1689931440; 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=hZrlIC4UOKpv9upRfhGvF2jtmIJyO/l6blnJN/Kvfh8=; b=erNG7kvL6P0i/pqI8Zd8QWNppN/ZDJpbYojffb/a89fpaOrKaRzMHJmHVri4i3W91Z OiGzXqruWa9PaUaMD4zkI19no++fHILrnBBaRuP0MHVIyeiMe8anPmW1s1T97vEpI5yK x/T2nJsYd7x7BKuGgxYUVGNaHPhy1SrKTHZeER1lSj3zKNVb8DyzRdl8O72eIOUg1NMV cE8CDLglytHB+oucMZNnIHOknB8Ql03RIzTNeGZNTkR9uYeYynjqlIUFHpDdFJ6riVWc KYtAcyAz6vWqhqDOxz4AeJmQpJBIVtqV9KShjnhyTrp4izkHNuHbnuYRSwXfB3NJLhp9 W9Cg== X-Gm-Message-State: AC+VfDzjxGBjI/tWasgt2r2f6/YOYyIS80Vu+b/a9HdpOwz+2tf44rju mERPkPeP89yvcnOaQpwCzbIvyA== X-Received: by 2002:adf:fd82:0:b0:30f:ce87:9db3 with SMTP id d2-20020adffd82000000b0030fce879db3mr13025821wrr.23.1687339440208; Wed, 21 Jun 2023 02:24:00 -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.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jun 2023 02:23:59 -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 04/12] can: m_can: Add rx coalescing ethtool support Date: Wed, 21 Jun 2023 11:23:42 +0200 Message-Id: <20230621092350.3130866-5-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?1769304125868187324?= X-GMAIL-MSGID: =?utf-8?q?1769304125868187324?= Add the possibility to set coalescing parameters with ethtool. rx-frames-irq and rx-usecs-irq can only be set and unset together as the implemented mechanism would not work otherwise. rx-frames-irq can't be greater than the RX FIFO size. Also all values can only be changed if the chip is not active. Signed-off-by: Markus Schneider-Pargmann Reviewed-by: Simon Horman --- drivers/net/can/m_can/m_can.c | 46 +++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index 781f287e7ce4..5238a5967971 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -1944,8 +1944,54 @@ static const struct net_device_ops m_can_netdev_ops = { .ndo_change_mtu = can_change_mtu, }; +static int m_can_get_coalesce(struct net_device *dev, + struct ethtool_coalesce *ec, + struct kernel_ethtool_coalesce *kec, + struct netlink_ext_ack *ext_ack) +{ + struct m_can_classdev *cdev = netdev_priv(dev); + + ec->rx_max_coalesced_frames_irq = cdev->rx_max_coalesced_frames_irq; + ec->rx_coalesce_usecs_irq = cdev->rx_coalesce_usecs_irq; + + return 0; +} + +static int m_can_set_coalesce(struct net_device *dev, + struct ethtool_coalesce *ec, + struct kernel_ethtool_coalesce *kec, + struct netlink_ext_ack *ext_ack) +{ + struct m_can_classdev *cdev = netdev_priv(dev); + + if (cdev->can.state != CAN_STATE_STOPPED) { + netdev_err(dev, "Device is in use, please shut it down first\n"); + return -EBUSY; + } + + if (ec->rx_max_coalesced_frames_irq > cdev->mcfg[MRAM_RXF0].num) { + netdev_err(dev, "rx-frames-irq %u greater than the RX FIFO %u\n", + ec->rx_max_coalesced_frames_irq, + cdev->mcfg[MRAM_RXF0].num); + return -EINVAL; + } + if (ec->rx_max_coalesced_frames_irq == 0 != ec->rx_coalesce_usecs_irq == 0) { + netdev_err(dev, "rx-frames-irq and rx-usecs-irq can only be set together\n"); + return -EINVAL; + } + + cdev->rx_max_coalesced_frames_irq = ec->rx_max_coalesced_frames_irq; + cdev->rx_coalesce_usecs_irq = ec->rx_coalesce_usecs_irq; + + return 0; +} + static const struct ethtool_ops m_can_ethtool_ops = { + .supported_coalesce_params = ETHTOOL_COALESCE_RX_USECS_IRQ | + ETHTOOL_COALESCE_RX_MAX_FRAMES_IRQ, .get_ts_info = ethtool_op_get_ts_info, + .get_coalesce = m_can_get_coalesce, + .set_coalesce = m_can_set_coalesce, }; static int register_m_can_dev(struct net_device *dev) From patchwork Wed Jun 21 09:23:43 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: 110897 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4231854vqr; Wed, 21 Jun 2023 02:27:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4SSvY8i+LAj2SBCVoELUOqkUtXPNM10PBkf7AUxaF9DDjZrwoQTyyqw+JL2q/hq36bOLdC X-Received: by 2002:a05:6a00:24cb:b0:668:74e9:8f06 with SMTP id d11-20020a056a0024cb00b0066874e98f06mr6873804pfv.1.1687339666676; Wed, 21 Jun 2023 02:27:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687339666; cv=none; d=google.com; s=arc-20160816; b=BJ+4u+yTsHiPIXGtT3yfnRs+PquxTw9b4RzZnYb2loCJi4lSmKRq6wfCUAnLWfIsEK a5iVRp5HDyDLjbTb+CSr3ZFSAHeDDXZFF+hcwTkT0X/M6HbMP7pVZPTJrq5oHL3QD6UO scc4c8lL0VjpkukEqer308nqpLDJhi1ZunRIFmw3Rxe39vlnOHK44HM7tnMmsR4Ku84S u60yjIEetvPeEBHGqqfU/+PAS2C75F3vOG5tZPQyQLJihpBG0eENB1N7huFs6/UPmRjJ /+NyiKO7l8tzbImQpjmbJeH0RD5AnCl/deAspLW2IHivaQmJ2QJbruiiSwXoNUPIyJWQ 9z+Q== 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=S3yb9swE3xTiKnV49xmW7qQT7kAh84V+/Srm0DQQmxA=; b=h9ljXygCyPTNItEGYJ2TAKt1FLj/KtmFdxVlS+zGP/tCTWyWMIb5yFRPQ2hj1TEUkJ Q2C7WlYeEdSAAGuZu+8iVMFNUIqCa0rgunaE1B7dqB8XETSy0Qd/pmp7KWA6ukCcqgG8 53Sb84McIiYAlJXdf11/IZhNyHQzW/RkHYhR9CdSCWSe6qX1CbtoM51AiN+xIq+T4fWT E6rsSTfZ/eNWTB0qU0S78NFfcs3yT+tbp/X1n0ahDDXkj4XwfmmYzcyyfcN8UDCpAFQp UXXYg4+vZmWAbSlq/fZnv7Cy1R+iXLy1ZkPUY2AWoD/cDaQXzqUqufTzFIUHyBMEZQd6 rw3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20221208.gappssmtp.com header.s=20221208 header.b="x4YWo/dR"; 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 j70-20020a636e49000000b005418b187c59si1410044pgc.633.2023.06.21.02.27.33; Wed, 21 Jun 2023 02:27:46 -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="x4YWo/dR"; 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 S231681AbjFUJYs (ORCPT + 99 others); Wed, 21 Jun 2023 05:24:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231428AbjFUJYW (ORCPT ); Wed, 21 Jun 2023 05:24:22 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECE161FCD for ; Wed, 21 Jun 2023 02:24:02 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-31129591288so3921767f8f.1 for ; Wed, 21 Jun 2023 02:24:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20221208.gappssmtp.com; s=20221208; t=1687339441; x=1689931441; 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=S3yb9swE3xTiKnV49xmW7qQT7kAh84V+/Srm0DQQmxA=; b=x4YWo/dRgd3X1CXi35YBtv7s4YeY0ryc8LBoz5C1znXUZ4qpZmvgbeA75ObRCxYC5M h1XBldnohWKXdZpZtDM3VAU7/kkv5vP0Qho9j1LvleCyUJPglEcq/jPLE9n6DdjU9Qu+ Ng2VjFCleB6NhIxz0uE0YJoAKEExD/0cOZCkerXlzsEELo2fqCTDKUbxx8riLQMtYsb2 89SmXnAjPt81FEv8oatHcckOq2p6JhqAXtfUoUyaB1N5Tku4lKDoUEUHBRKbVWz0Ayt9 BTmqCDy2K13LALirN5MlP02JiisY3IzrSOwagkN2XIEQEovHLnOp2jl+4v4YWGt61wt0 zLpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687339441; x=1689931441; 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=S3yb9swE3xTiKnV49xmW7qQT7kAh84V+/Srm0DQQmxA=; b=PX0W/pQG2SaickjBDxcTZvcMfvJPH6tuDnOCqSf7FSMORGlmBD8pcTtOA/dJhhsw68 P9aiMlVY4pnV4KdX6bCLKvPwcM46TKnZFrPySYLr3awAMWWhbuLiEQLS66gvHj5I8Nr9 5zQST+1YfY53yOBLQoGIBU174uUqM54ldkaWQV3A0836pVJ1muQsVP6uNoYhsXEg+aeR Jln/21wRUjactztxUl9FD5nVtgR+EKOBOdxPu9br/p/kGYP+y44jR6gAz7ZnSCkidVUr ByQgrtO/gSObQSGVIRK44iouFYdwNxSqfYA6obt7QnAj1APX6IZaiig/CpkYkyQOnAsG O2Wg== X-Gm-Message-State: AC+VfDzYqCuyACuAMP9tSOjaHdvQ8qg6RzVrUEufiKAHrOvt7abMiuCv Sgr/85UdSAbL9oaqeHr74IK7FQ== X-Received: by 2002:adf:ffce:0:b0:30f:b045:8b60 with SMTP id x14-20020adfffce000000b0030fb0458b60mr9833679wrs.69.1687339441432; Wed, 21 Jun 2023 02:24:01 -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.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jun 2023 02:24:01 -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 05/12] can: m_can: Add tx coalescing ethtool support Date: Wed, 21 Jun 2023 11:23:43 +0200 Message-Id: <20230621092350.3130866-6-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?1769303878469374075?= X-GMAIL-MSGID: =?utf-8?q?1769303878469374075?= Add TX support to get/set functions for ethtool coalescing. tx-frames-irq and tx-usecs-irq can only be set/unset together. tx-frames-irq needs to be less than TXE and TXB. As rx and tx share the same timer, rx-usecs-irq and tx-usecs-irq can be enabled/disabled individually but they need to have the same value if enabled. Signed-off-by: Markus Schneider-Pargmann Reviewed-by: Simon Horman --- drivers/net/can/m_can/m_can.c | 38 ++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index 5238a5967971..d1435d1466b2 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -1953,6 +1953,8 @@ static int m_can_get_coalesce(struct net_device *dev, ec->rx_max_coalesced_frames_irq = cdev->rx_max_coalesced_frames_irq; ec->rx_coalesce_usecs_irq = cdev->rx_coalesce_usecs_irq; + ec->tx_max_coalesced_frames_irq = cdev->tx_max_coalesced_frames_irq; + ec->tx_coalesce_usecs_irq = cdev->tx_coalesce_usecs_irq; return 0; } @@ -1979,16 +1981,50 @@ static int m_can_set_coalesce(struct net_device *dev, netdev_err(dev, "rx-frames-irq and rx-usecs-irq can only be set together\n"); return -EINVAL; } + if (ec->tx_max_coalesced_frames_irq > cdev->mcfg[MRAM_TXE].num) { + netdev_err(dev, "tx-frames-irq %u greater than the TX event FIFO %u\n", + ec->tx_max_coalesced_frames_irq, + cdev->mcfg[MRAM_TXE].num); + return -EINVAL; + } + if (ec->tx_max_coalesced_frames_irq > cdev->mcfg[MRAM_TXB].num) { + netdev_err(dev, "tx-frames-irq %u greater than the TX FIFO %u\n", + ec->tx_max_coalesced_frames_irq, + cdev->mcfg[MRAM_TXB].num); + return -EINVAL; + } + if (ec->tx_max_coalesced_frames_irq == 0 != ec->tx_coalesce_usecs_irq == 0) { + netdev_err(dev, "tx-frames-irq and tx-usecs-irq can only be set together\n"); + return -EINVAL; + } + if (ec->rx_coalesce_usecs_irq != 0 && ec->tx_coalesce_usecs_irq != 0 && + ec->rx_coalesce_usecs_irq != ec->tx_coalesce_usecs_irq) { + netdev_err(dev, "rx-usecs-irq %u needs to be equal to tx-usecs-irq %u if both are enabled\n", + ec->rx_coalesce_usecs_irq, + ec->tx_coalesce_usecs_irq); + return -EINVAL; + } cdev->rx_max_coalesced_frames_irq = ec->rx_max_coalesced_frames_irq; cdev->rx_coalesce_usecs_irq = ec->rx_coalesce_usecs_irq; + cdev->tx_max_coalesced_frames_irq = ec->tx_max_coalesced_frames_irq; + cdev->tx_coalesce_usecs_irq = ec->tx_coalesce_usecs_irq; + + if (cdev->rx_coalesce_usecs_irq) + cdev->irq_timer_wait = + ns_to_ktime(cdev->rx_coalesce_usecs_irq * NSEC_PER_USEC); + else + cdev->irq_timer_wait = + ns_to_ktime(cdev->tx_coalesce_usecs_irq * NSEC_PER_USEC); return 0; } static const struct ethtool_ops m_can_ethtool_ops = { .supported_coalesce_params = ETHTOOL_COALESCE_RX_USECS_IRQ | - ETHTOOL_COALESCE_RX_MAX_FRAMES_IRQ, + ETHTOOL_COALESCE_RX_MAX_FRAMES_IRQ | + ETHTOOL_COALESCE_TX_USECS_IRQ | + ETHTOOL_COALESCE_TX_MAX_FRAMES_IRQ, .get_ts_info = ethtool_op_get_ts_info, .get_coalesce = m_can_get_coalesce, .set_coalesce = m_can_set_coalesce, From patchwork Wed Jun 21 09:23:44 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: 110902 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4234237vqr; Wed, 21 Jun 2023 02:32:44 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5JkjHkS6zmzvgHzyJMGjKyRbOLN3+oB3+xIGtIXOtRKOs2uqsSrsOooqQn3jC6xt3b1wwe X-Received: by 2002:ac8:5b14:0:b0:3f9:be5a:e8d8 with SMTP id m20-20020ac85b14000000b003f9be5ae8d8mr20170573qtw.8.1687339963978; Wed, 21 Jun 2023 02:32:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687339963; cv=none; d=google.com; s=arc-20160816; b=jhI4pE/HUaOqP1lOi9yMXzwxIzhXbYADfUprSdw3012Vu0fPqRVRv34Sz5GFxIEbk5 FHhhA1+gJhzHw/RbqvNW2ekCblT/5rsnH2Tc90zyOjsKEGshGF7tmsK2xvhGWzMyQV1k MjP5/q95zhymkt6DezTeyF5ya/XsWMc02XbGIfGQ41xuMa/MHM4osCW5aUsXwpmfh0nW bzA/KHWIKfoFFvz9N+9iA+QAhjIhuJO6u4X4FD8ENPpltVsT/ItE3Fy1rbU64qqbGaVz TGO85n1S56Wyf0qRPGnFbzorUBXd8C2Vz3msZodOkO5O96L/U5jU9ZBLgUh+3bACmUfZ UjNw== 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=LE1vT+gVNirEsJxbTiTmA/33w+JDDyn/z8+OkH6Uatg=; b=W2Ulj1xmjzW4OKIK80Ldd9yzPDBsI8ZK3q/63xchsYiI+DMFCKpe1vWu9OKTriMhak 9REHUdloWKn29+KXQwlqXjGcsmOKbsdhy8Jfv95xIWjv8k+P7/zbUQ3TpwlC60eLs77f 30AQxiiVX5Yl9qm0IHLNKvVqVCHfEAF5U0M8modhmSsCHIRRphIrGvd2U5Qr3a4X9NBp 7joQ9T1UhSkuUsl4UEHSzTWv9UGzewLmVepkpMMxKh7VjRSYjCmhKyJ0YDnifQFxZfK9 s7xJdvUIomeS75TLgkA+f3+K4wowDkxrpjp39nDnGaUrDvLf7zpIB1TAW+yDecgGJuUu Gnmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20221208.gappssmtp.com header.s=20221208 header.b="dh/Yscpx"; 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 s22-20020a17090ad49600b0024e4ace1a41si3793124pju.183.2023.06.21.02.32.30; Wed, 21 Jun 2023 02:32:43 -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="dh/Yscpx"; 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 S231752AbjFUJYy (ORCPT + 99 others); Wed, 21 Jun 2023 05:24:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230338AbjFUJYX (ORCPT ); Wed, 21 Jun 2023 05:24:23 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 499B219BF for ; Wed, 21 Jun 2023 02:24:04 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-51a3e6a952aso6851296a12.3 for ; Wed, 21 Jun 2023 02:24:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20221208.gappssmtp.com; s=20221208; t=1687339442; x=1689931442; 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=LE1vT+gVNirEsJxbTiTmA/33w+JDDyn/z8+OkH6Uatg=; b=dh/Yscpx9g50WP8aUQec7esEdqkMVckT3xmVw5qZUmxNn8Lnkpby8IzbVZxOkbudQ1 dR5a6nkp17Pn0vSgWzUsFeApujZpPlq8DvW9F6cn4SoKlOPPHmvyWvXo/XEgH/v1Xjhp d0gzl7pJo4T/8Ea7xeTevcKvSQAm4tg84t6Li6oi2XxrgDKYJKUrU5QO+OJZUmcn/pW8 WgN3lJONfebk19tQqqGWv1PBAFnjqam9Hm3hhUp/V1h9hKt/3nybAv0+65aU0McJ3Sct U+MigjS8Fq7nIP9+sx1pDlBh59lrTSFdqy1cYRhDwwYdcIAfIhrkmUsd1f5G+ApwD6Ex LGTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687339442; x=1689931442; 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=LE1vT+gVNirEsJxbTiTmA/33w+JDDyn/z8+OkH6Uatg=; b=ElxKoKGkairFAG1GIrNRuzHasZfhJwYRKLMJFAbG7R7LkXTWzyRP26bLSPplNJ2cnJ N2u461u1auVEgOzW3z6ZNnd0cG6FsSlOQc6659qQi7Ac353tn4ilH1srPkp/3kuIOgwv Lv7idM7hHZzlZyOFEqNmDWd1uLo0IEUOuoUw868mwCm05dogcG1rSuEGhPaZJcbFk3a0 l4mhXwDu7kgbnvbSkIk/LYJo2ih2KJftm/tCi3T595igCEKDvGLQwEreq/o6ksXo0AHg 0PxwGJX5bxGoQAb4aVvB67Hl8P8YQaBOFMP/xsVc8+/sjjhpjdQND6B9ZD4DbZE+vubU VvrA== X-Gm-Message-State: AC+VfDzE6NkDfqwehK2utcaxTntrrWacjQbSEhs7EBOvdZeO5776ZgBk ThhQDVsuMXkB7PSiLJ7l7v9l8w== X-Received: by 2002:a17:906:58d2:b0:988:8a11:ab88 with SMTP id e18-20020a17090658d200b009888a11ab88mr8539198ejs.33.1687339442703; Wed, 21 Jun 2023 02:24:02 -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.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jun 2023 02:24:02 -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 06/12] can: m_can: Use u32 for putidx Date: Wed, 21 Jun 2023 11:23:44 +0200 Message-Id: <20230621092350.3130866-7-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?1769304190398002159?= X-GMAIL-MSGID: =?utf-8?q?1769304190398002159?= putidx is not an integer normally, it is an unsigned field used in hardware registers. Use a u32 for it. Signed-off-by: Markus Schneider-Pargmann --- drivers/net/can/m_can/m_can.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index d1435d1466b2..6f8043636c54 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -467,7 +467,7 @@ static void m_can_clean(struct net_device *net) struct m_can_classdev *cdev = netdev_priv(net); if (cdev->tx_skb) { - int putidx = 0; + u32 putidx = 0; net->stats.tx_errors++; if (cdev->version > 30) @@ -1673,12 +1673,12 @@ static int m_can_close(struct net_device *dev) return 0; } -static int m_can_next_echo_skb_occupied(struct net_device *dev, int putidx) +static int m_can_next_echo_skb_occupied(struct net_device *dev, u32 putidx) { struct m_can_classdev *cdev = netdev_priv(dev); /*get wrap around for loopback skb index */ unsigned int wrap = cdev->can.echo_skb_max; - int next_idx; + u32 next_idx; /* calculate next index */ next_idx = (++putidx >= wrap ? 0 : putidx); @@ -1698,7 +1698,7 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev) u32 cccr, fdflags; u32 txfqs; int err; - int putidx; + u32 putidx; cdev->tx_skb = NULL; From patchwork Wed Jun 21 09:23:45 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: 110909 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4234428vqr; Wed, 21 Jun 2023 02:33:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ44dmpoaCZ/DJx0uX8cf4ZdrJ/qLRSpjtVDPkJxzXvsMkAGucM/ZlGEo9jlgom7wjSmCodi X-Received: by 2002:a92:506:0:b0:33d:6d9f:b65c with SMTP id q6-20020a920506000000b0033d6d9fb65cmr13214463ile.6.1687339991923; Wed, 21 Jun 2023 02:33:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687339991; cv=none; d=google.com; s=arc-20160816; b=dTxtqduSoWp4+hzAk4ilQG0uGgCTu7oVcJluTiC9Tn/LfsMxLrdg3d9dLinBb3JrAX WyOTf4oW96CUYk1FOflKga+dBRbLtbhjZ4gwonVHeUHMWgd/6JpehYJhVilzT3KUaROn KqO45zUVfhXeBPBWcIRShh+v3b5si62k+DZh0r169vS12Yv/K1ebcPgpP+FpxGL7SS7U DfbEEqipiiraj0q1VRU24TYY4CuzmdnHBAWNJw/dGdmyZ11O/PxhbkriA5Q1akSP+U3s aKhsIE29+l1ke7lEipHhb9G/ZCEzBzu4YRGXVc+8SdLMDuoBZtA3yVqva3Q5bYwC8fBS BImQ== 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=DG8roE6DhQwhU2xd4+PBx8NOhVWjNvN1rf2zoTDzpOE=; b=a/HYQiM4OdmRss8TZRiXOJr+oqePvpeVzCuCeJY5DFv00b4ayGCKAYMGCRLb4KeaMg dXMncWp8UmBh9OtHS5CVF4nMOnrkZFhQUE5D93Iyt6p9ynCY/Ybtdzk+OrshWFMVGmQf tTdRBTH8v+4jf20RI78E0zMHTeSTlJW6K85Q7mhK2Unly3rK7KIzQbuYM1m05EDkISic 3kJsUE13gwhDczwDa9AT/1W7RwS8bB9yZosEbOu2yunIfMPBJ0U4wkJ34U/M0BDt8crQ CKlX+WuFfomAic/CuLu/xlU8yEGpxeBog0eJDeba1eRArUJve0scoe4TqkXV92YYBFu5 AOWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20221208.gappssmtp.com header.s=20221208 header.b="zfMj4yE/"; 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 17-20020a17090a001100b0025b8c6cfc45si10867466pja.80.2023.06.21.02.32.59; Wed, 21 Jun 2023 02:33:11 -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="zfMj4yE/"; 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 S231883AbjFUJZA (ORCPT + 99 others); Wed, 21 Jun 2023 05:25:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231406AbjFUJYY (ORCPT ); Wed, 21 Jun 2023 05:24:24 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B0D319B9 for ; Wed, 21 Jun 2023 02:24:05 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-3112f5ab0b1so3626629f8f.0 for ; Wed, 21 Jun 2023 02:24:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20221208.gappssmtp.com; s=20221208; t=1687339444; x=1689931444; 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=DG8roE6DhQwhU2xd4+PBx8NOhVWjNvN1rf2zoTDzpOE=; b=zfMj4yE/E3JiduSidiDhmkVb1PXwnXSoIAD/BKOKSWThF0Medj9ixH10zxIDtLxPwi 2u5tw1TqtyfHQ1Ctp/9EzjrlTcV6AszrGml9w9YE8qRNS/7YG9GBzZfpbjfBNM8jAHkU +fv7lEHKsdHaCFA0piyEIzF91CNZ64CXXBubRHgGuc1WjKzZDi6tPFhDT7ethE7Zdwsp dVLviscYJfyVQABy9gDorl63pM6C+IWVPjEnyn6YaWUBwLlbJbHDoiv6Olnn9f5k3w81 sSJPU3pitUMYXAiknhVsoqycNSJYPjo0yPokeccIwxfDzqw5JfywxN9sK04wZICKixI6 u3kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687339444; x=1689931444; 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=DG8roE6DhQwhU2xd4+PBx8NOhVWjNvN1rf2zoTDzpOE=; b=N5JQzBqvHQcNVlTyQCgbBWvQq+O1IqUgS8acj4wJEqovQnoOqY+WP3ubCubnHCE5nE B8goXL4VM7P0BQEex19NVDjMbK1NFaL0kpPdsJDZM4bZ981rHlCA6IDN0m4dYHAdIUjm ow4G1db7+86TLLXrmmXTap7EIwzGIJEqZNocKKJ9DrC///CNbIGPItt1at7/Y+NSf66p 1ZSFMZMg0aHn8x5IrguOS3a8fAb+tAPWtzTm1qskT5nA0GEytqfRfvx55vUizfuBBZ75 jUz8d0EmJ1WbhCi+NgcEWKfpmCFtKpjV/9BhzZOEGKt7dqYQtcU3fh0ev1a4zbsm0zvm KgqQ== X-Gm-Message-State: AC+VfDxopNicH9Jhh1TUNL9PLrhQx/SAHxDonCRViBrRViURPJZnKY3P REvb6G3gb0iZwft0nrs0olk9pw== X-Received: by 2002:a5d:628d:0:b0:30d:5cce:3bb5 with SMTP id k13-20020a5d628d000000b0030d5cce3bb5mr10729727wru.60.1687339444004; Wed, 21 Jun 2023 02:24:04 -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.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jun 2023 02:24:03 -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 07/12] can: m_can: Cache tx putidx Date: Wed, 21 Jun 2023 11:23:45 +0200 Message-Id: <20230621092350.3130866-8-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=ham 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?1769304219259471978?= X-GMAIL-MSGID: =?utf-8?q?1769304219259471978?= m_can_tx_handler is the only place where data is written to the tx fifo. We can calculate the putidx in the driver code here to avoid the dependency on the txfqs register. Signed-off-by: Markus Schneider-Pargmann Reviewed-by: Simon Horman --- drivers/net/can/m_can/m_can.c | 8 +++++++- drivers/net/can/m_can/m_can.h | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index 6f8043636c54..40acd78cc0ed 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -1482,6 +1482,10 @@ static int m_can_start(struct net_device *dev) m_can_enable_all_interrupts(cdev); + if (cdev->version > 30) + cdev->tx_fifo_putidx = FIELD_GET(TXFQS_TFQPI_MASK, + m_can_read(cdev, M_CAN_TXFQS)); + return 0; } @@ -1772,7 +1776,7 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev) } /* get put index for frame */ - putidx = FIELD_GET(TXFQS_TFQPI_MASK, txfqs); + putidx = cdev->tx_fifo_putidx; /* Construct DLC Field, with CAN-FD configuration. * Use the put index of the fifo as the message marker, @@ -1806,6 +1810,8 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev) /* Enable TX FIFO element to start transfer */ m_can_write(cdev, M_CAN_TXBAR, (1 << putidx)); + cdev->tx_fifo_putidx = (++cdev->tx_fifo_putidx >= cdev->can.echo_skb_max ? + 0 : cdev->tx_fifo_putidx); /* stop network queue if fifo full */ if (m_can_tx_fifo_full(cdev) || diff --git a/drivers/net/can/m_can/m_can.h b/drivers/net/can/m_can/m_can.h index d0c21eddb6ec..548ae908ac4e 100644 --- a/drivers/net/can/m_can/m_can.h +++ b/drivers/net/can/m_can/m_can.h @@ -102,6 +102,9 @@ struct m_can_classdev { u32 tx_max_coalesced_frames_irq; u32 tx_coalesce_usecs_irq; + // Store this internally to avoid fetch delays on peripheral chips + int tx_fifo_putidx; + struct mram_cfg mcfg[MRAM_CFG_NUM]; }; From patchwork Wed Jun 21 09:23:46 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: 110899 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4233771vqr; Wed, 21 Jun 2023 02:31:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6dzFR6jHEU6yV/8kRmIupJdwPe5P5GMVBRsefw7+GNTo2WOCFcujW9yNN71W6BaOjv9+YQ X-Received: by 2002:a05:622a:491:b0:3eb:1512:91c5 with SMTP id p17-20020a05622a049100b003eb151291c5mr19930324qtx.12.1687339902522; Wed, 21 Jun 2023 02:31:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687339902; cv=none; d=google.com; s=arc-20160816; b=Nzf89vivdh3LJbvmijDOiPvm8sPMpVkLZhMmCyZeMFSGFj99/2ZgE63e5JXYCoOoeT 6aVYTBvbR71+lKgicoXoXvUTiriERk1YSdf//uFk5K7M4G1E81u+45cmxyjM/V4c2Cn+ pj8P/oiRn8m+1g4wZiL2Qxb8Sf7XI2NJIzlvplZeelLAO9ghWYxA+3q3ScaBYc+vRHMl rma7Z4MvtEdLgNSjw234GTOUZOhBF+RLxIdKNOY5/zwsbvhuu3nwDNyzB2+cD41JwJ8q Mpwfv1MhMMg3+l4Uz8WcbNFGzv4aPVrU3HhmTb/AElMcEeKPBNPBVC+YxWoYvzNiZh8M zQGQ== 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=UURWqBUXOBW/vgexjIMqvywbeKsg0EBaKHEuKuyo96o=; b=VhOsoEArAkCC9fKTpdVsay/PWfcNVX+zqiBsngS3+9QpC9XfVuLF+tAXTN7/bir6gG qkEus91vWZN2QyVAX3ZWg7enh2T768T9sjMXdBu1xUrpscUTnHCZ48WfPsTquEazZymH fvyqDQcmfOL1awIPlQqzB8JwBzuMcMZebc6NIBAALBBAuYucGDtzFRZHdBwfU+J3cc87 T2+EJq9lf2ZpV04ifL7QzDzyOy2BGSADUldyf5eXa6EUmITFC0PuPKV69kQGOGYXPfdz CkMUoPZpZsfOXdy+zw33Pvu2MSZcNWqHUanXisayz7GT0Fz13ZILaTcML1hOldyTVmN3 U18Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20221208.gappssmtp.com header.s=20221208 header.b=O4mT4gGy; 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 h23-20020a17090acf1700b0025c1f40f3basi11368616pju.55.2023.06.21.02.31.15; Wed, 21 Jun 2023 02:31:42 -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=O4mT4gGy; 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 S231952AbjFUJZG (ORCPT + 99 others); Wed, 21 Jun 2023 05:25:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231350AbjFUJYZ (ORCPT ); Wed, 21 Jun 2023 05:24:25 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7322B1BC3 for ; Wed, 21 Jun 2023 02:24:06 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-307d20548adso4592124f8f.0 for ; Wed, 21 Jun 2023 02:24:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20221208.gappssmtp.com; s=20221208; t=1687339445; x=1689931445; 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=UURWqBUXOBW/vgexjIMqvywbeKsg0EBaKHEuKuyo96o=; b=O4mT4gGylvPiW0VFn3USiYztPupBUDZj+DJB0DhCa19DiFIOSt+vzlu4yV7TWEh6R0 QfUJMBOlykfgzF17rzLqLM7O3y67yYzI7a275Dzp6BtU6abmDMbHMs4a9yJbruonrlS+ 3yUxVM9fJKBPe8lUV3IVUMiU1e7wkf5bR1n+72DL0fMLmabpq5HNQuzwm0EhSyr7+Epb B75mjtHp8kO0FMFZR7ClCI2XeNYQ11QkIxWOzM5mLCTRkXj2tJM5oLtV3MXiY3mgDcJT +JHVi9fmMzN+5hLKWn5BP3eWC5m4KQThNmRd0o36Wnfwx8dJdAWUfAXmOozQ+8MGiNbq yyeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687339445; x=1689931445; 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=UURWqBUXOBW/vgexjIMqvywbeKsg0EBaKHEuKuyo96o=; b=GW6xE/Bo32WMA6AcT735yO3uEKbBA1nax6qZ/R3rRQgTi/h0PfjsFgpy2Mh1mcIY2/ 52SipF8fEGALQAZSBE2XNh9Qa80IIe3S5J5qhCcockyrytggp1ts5rIoXKHxyiupX2lG mo89CeCWo/EfC+TQq3XjwX/eZ8hUn7wG8SvREsK8eWsIk0x/ydNqTM/kuzyO+tD+kIJF vbvKnaWCQbATYcRPAcVEkg3WTV9QIQFALDn/dWB6RTAJpSqEmsfOKKbGaxbnX6RwKNlG th4E4QWjVu57488dq6anDBlFKXB0EOowIMdqA4mxFd4kRBHqzEf+nsU7C7w3l04zxjKV sBjg== X-Gm-Message-State: AC+VfDx0qKeFvWAZczYx0gvCwIwfrtDdEf3CSNUDvAL1y8Q4aZ3OtLQp jVwn2vfzh/IwV5t1MjXIU5icYQ== X-Received: by 2002:adf:fa06:0:b0:30f:be04:5b5e with SMTP id m6-20020adffa06000000b0030fbe045b5emr9288732wrr.37.1687339444992; Wed, 21 Jun 2023 02:24:04 -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.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jun 2023 02:24:04 -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 08/12] can: m_can: Use the workqueue as queue Date: Wed, 21 Jun 2023 11:23:46 +0200 Message-Id: <20230621092350.3130866-9-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?1769304125605055375?= X-GMAIL-MSGID: =?utf-8?q?1769304125605055375?= The current implementation uses the workqueue for peripheral chips to submit work. Only a single work item is queued and used at any time. To be able to keep more than one transmit in flight at a time, prepare the workqueue to support multiple transmits at the same time. Each work item now has a separate storage for a skb and a pointer to cdev. This assures that each workitem can be processed individually. The workqueue is replaced by an ordered workqueue which makes sure that only a single worker processes the items queued on the workqueue. Also items are ordered by the order they were enqueued. This removes most of the concurrency the workqueue normally offers. It is not necessary for this driver. The cleanup functions have to be adopted a bit to handle this new mechanism. Signed-off-by: Markus Schneider-Pargmann Reviewed-by: Simon Horman --- drivers/net/can/m_can/m_can.c | 109 ++++++++++++++++++++-------------- drivers/net/can/m_can/m_can.h | 14 ++++- 2 files changed, 75 insertions(+), 48 deletions(-) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index 40acd78cc0ed..88c8d6a418f0 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -466,17 +466,16 @@ static void m_can_clean(struct net_device *net) { struct m_can_classdev *cdev = netdev_priv(net); - if (cdev->tx_skb) { - u32 putidx = 0; + for (int i = 0; i != cdev->tx_fifo_size; ++i) { + if (!cdev->tx_ops[i].skb) + continue; net->stats.tx_errors++; - if (cdev->version > 30) - putidx = FIELD_GET(TXFQS_TFQPI_MASK, - m_can_read(cdev, M_CAN_TXFQS)); - - can_free_echo_skb(cdev->net, putidx, NULL); - cdev->tx_skb = NULL; + cdev->tx_ops[i].skb = NULL; } + + for (int i = 0; i != cdev->can.echo_skb_max; ++i) + can_free_echo_skb(cdev->net, i, NULL); } /* For peripherals, pass skb to rx-offload, which will push skb from @@ -1663,8 +1662,9 @@ static int m_can_close(struct net_device *dev) m_can_clk_stop(cdev); free_irq(dev->irq, dev); + m_can_clean(dev); + if (cdev->is_peripheral) { - cdev->tx_skb = NULL; destroy_workqueue(cdev->tx_wq); cdev->tx_wq = NULL; can_rx_offload_disable(&cdev->offload); @@ -1691,21 +1691,19 @@ static int m_can_next_echo_skb_occupied(struct net_device *dev, u32 putidx) return !!cdev->can.echo_skb[next_idx]; } -static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev) +static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev, + struct sk_buff *skb) { - struct canfd_frame *cf = (struct canfd_frame *)cdev->tx_skb->data; + struct canfd_frame *cf = (struct canfd_frame *)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; u32 putidx; - cdev->tx_skb = NULL; - /* Generate ID field for TX buffer Element */ /* Common to all supported M_CAN versions */ if (cf->can_id & CAN_EFF_FLAG) { @@ -1829,10 +1827,36 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev) static void m_can_tx_work_queue(struct work_struct *ws) { - struct m_can_classdev *cdev = container_of(ws, struct m_can_classdev, - tx_work); + struct m_can_tx_op *op = container_of(ws, struct m_can_tx_op, work); + struct m_can_classdev *cdev = op->cdev; + struct sk_buff *skb = op->skb; - m_can_tx_handler(cdev); + op->skb = NULL; + m_can_tx_handler(cdev, skb); +} + +static void m_can_tx_queue_skb(struct m_can_classdev *cdev, struct sk_buff *skb) +{ + cdev->tx_ops[cdev->next_tx_op].skb = skb; + queue_work(cdev->tx_wq, &cdev->tx_ops[cdev->next_tx_op].work); + + ++cdev->next_tx_op; + if (cdev->next_tx_op >= cdev->tx_fifo_size) + cdev->next_tx_op = 0; +} + +static netdev_tx_t m_can_start_peripheral_xmit(struct m_can_classdev *cdev, + struct sk_buff *skb) +{ + if (cdev->can.state == CAN_STATE_BUS_OFF) { + m_can_clean(cdev->net); + return NETDEV_TX_OK; + } + + netif_stop_queue(cdev->net); + m_can_tx_queue_skb(cdev, skb); + + return NETDEV_TX_OK; } static netdev_tx_t m_can_start_xmit(struct sk_buff *skb, @@ -1843,30 +1867,10 @@ static netdev_tx_t m_can_start_xmit(struct sk_buff *skb, if (can_dev_dropped_skb(dev, skb)) return NETDEV_TX_OK; - if (cdev->is_peripheral) { - if (cdev->tx_skb) { - netdev_err(dev, "hard_xmit called while tx busy\n"); - return NETDEV_TX_BUSY; - } - - if (cdev->can.state == CAN_STATE_BUS_OFF) { - m_can_clean(dev); - } else { - /* Need to stop the queue to avoid numerous requests - * from being sent. Suggested improvement is to create - * a queueing mechanism that will queue the skbs and - * process them in order. - */ - cdev->tx_skb = skb; - netif_stop_queue(cdev->net); - queue_work(cdev->tx_wq, &cdev->tx_work); - } - } else { - cdev->tx_skb = skb; - return m_can_tx_handler(cdev); - } - - return NETDEV_TX_OK; + if (cdev->is_peripheral) + return m_can_start_peripheral_xmit(cdev, skb); + else + return m_can_tx_handler(cdev, skb); } static int m_can_open(struct net_device *dev) @@ -1894,15 +1898,17 @@ static int m_can_open(struct net_device *dev) /* register interrupt handler */ if (cdev->is_peripheral) { - cdev->tx_skb = NULL; - cdev->tx_wq = alloc_workqueue("mcan_wq", - WQ_FREEZABLE | WQ_MEM_RECLAIM, 0); + cdev->tx_wq = alloc_ordered_workqueue("mcan_wq", + WQ_FREEZABLE | WQ_MEM_RECLAIM); if (!cdev->tx_wq) { err = -ENOMEM; goto out_wq_fail; } - INIT_WORK(&cdev->tx_work, m_can_tx_work_queue); + for (int i = 0; i != cdev->tx_fifo_size; ++i) { + cdev->tx_ops[i].cdev = cdev; + INIT_WORK(&cdev->tx_ops[i].work, m_can_tx_work_queue); + } err = request_threaded_irq(dev->irq, NULL, m_can_isr, IRQF_ONESHOT, @@ -2172,6 +2178,19 @@ int m_can_class_register(struct m_can_classdev *cdev) { int ret; + cdev->tx_fifo_size = max(1, min(cdev->mcfg[MRAM_TXB].num, + cdev->mcfg[MRAM_TXE].num)); + if (cdev->is_peripheral) { + cdev->tx_ops = + devm_kzalloc(cdev->dev, + cdev->tx_fifo_size * sizeof(*cdev->tx_ops), + GFP_KERNEL); + if (!cdev->tx_ops) { + dev_err(cdev->dev, "Failed to allocate tx_ops for workqueue\n"); + return -ENOMEM; + } + } + if (cdev->pm_clock_support) { ret = m_can_clk_start(cdev); if (ret) diff --git a/drivers/net/can/m_can/m_can.h b/drivers/net/can/m_can/m_can.h index 548ae908ac4e..38b154fea04b 100644 --- a/drivers/net/can/m_can/m_can.h +++ b/drivers/net/can/m_can/m_can.h @@ -70,6 +70,12 @@ struct m_can_ops { int (*init)(struct m_can_classdev *cdev); }; +struct m_can_tx_op { + struct m_can_classdev *cdev; + struct work_struct work; + struct sk_buff *skb; +}; + struct m_can_classdev { struct can_priv can; struct can_rx_offload offload; @@ -80,8 +86,6 @@ struct m_can_classdev { struct clk *cclk; struct workqueue_struct *tx_wq; - struct work_struct tx_work; - struct sk_buff *tx_skb; struct phy *transceiver; struct hrtimer irq_timer; @@ -103,7 +107,11 @@ struct m_can_classdev { u32 tx_coalesce_usecs_irq; // Store this internally to avoid fetch delays on peripheral chips - int tx_fifo_putidx; + u32 tx_fifo_putidx; + + struct m_can_tx_op *tx_ops; + int tx_fifo_size; + int next_tx_op; struct mram_cfg mcfg[MRAM_CFG_NUM]; }; From patchwork Wed Jun 21 09:23:47 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: 110905 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4234354vqr; Wed, 21 Jun 2023 02:32:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6LYtg/CYCc/k5TSZ2OLaxyDh2JFhL9VXAKSEQDfNYuPOiI6QrrsX3T9SoxkiX2HITESFU3 X-Received: by 2002:a17:90b:4fc2:b0:260:d8c0:ae79 with SMTP id qa2-20020a17090b4fc200b00260d8c0ae79mr2254241pjb.35.1687339978660; Wed, 21 Jun 2023 02:32:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687339978; cv=none; d=google.com; s=arc-20160816; b=WvEiOjvKOsHmagEPscMgmA0EEuge51Vw1E7jVsA0JM9H4yYSwJFBhb8WSquQVGMtDM rKbY7RU7sWEcyqTaNHlB2StKKlzNENP9OXx19dd34BahLHvolLKzOgNmiFYgIZ8L0Vk9 IruJkPSNuqIPtKF3H9rdnv4W2GjgkW2S/tyD10gdnW5sy796TYZX+v7AOOpqlatJsr9P K6UoINgfWL9C88oT6u3I+BY7k2myMLBRILIMmYTbRBdBR+UevyksY0UNAIi/xhZVFFUr ec5rp88+lfVZvlkogZg9N3wkEd0DmMaAtO04srMOoLIk9DEagEu6bjFzgJm0KMhyo8dW fTkQ== 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=wgGolVUD4UXN/bgzsidi7fKnE4pGiXRO6QM6WC6v+Ds=; b=EIszp9HjkZYMgQML4awIhXEGYxZKWqCUcQgCmIGTwbiv5qniZDR8th2Gpb93g4dmfp d3AQqxEusZd9kkfA7PovqAQzbgU3qsKJ4cifg2NN0osZeN4QLRLzXgBHxhQ1LkwaKbtz CUpox+tTnxXSyt1nv3hu7YsW+firUN4DfEofD4hRAAYV3HeYpoB8MXrDfEmdsdxfSmsA +Gj2zf6keo27r3Dw11SmFO1NqSpPsNxXDLFJsWkIcTU9Gty6VA8Biw3nCnYmEcD22dVi +gpSFScaaSs5P7LVYjNvHoByTxbneVAHcDc1VOZn0QZU7pdZcyur93Mld0XmOAryRkVH RGlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20221208.gappssmtp.com header.s=20221208 header.b="eeErYS/y"; 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 nh4-20020a17090b364400b0024e37ccb3fesi3768412pjb.68.2023.06.21.02.32.46; Wed, 21 Jun 2023 02:32:58 -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="eeErYS/y"; 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 S231992AbjFUJZL (ORCPT + 99 others); Wed, 21 Jun 2023 05:25:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231453AbjFUJY0 (ORCPT ); Wed, 21 Jun 2023 05:24:26 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9192E1BCA for ; Wed, 21 Jun 2023 02:24:07 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-311367a3e12so4736735f8f.2 for ; Wed, 21 Jun 2023 02:24:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20221208.gappssmtp.com; s=20221208; t=1687339446; x=1689931446; 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=wgGolVUD4UXN/bgzsidi7fKnE4pGiXRO6QM6WC6v+Ds=; b=eeErYS/yb7l1i94wnKW/4Cz9K5CztVnCkeoHKYlRJbv6aKHhjqDbxr5yk1K8Dh6Wyt 40pkE4VoeBGzSSC6tms4qeLrWDSDYvoWGiaBdoxIJHvuwS7uLp52NWnvyo/zAOewXd6U 6I1dUMnevaP8a7cVpGeYHO2M1aQNTM0fmy/8cprYfhLSYhLHqjZim0w0rIcA57DqKmpt 0ZU3Po/sP+qBwzIu+JJym4fqY8wvZJklDDIvXwMGMSbzcAKnGoQT8jorbUbN++Daxi9R XlXoifqwqUqQYfB7+1KUcNiHhBvhdZ1AREav+zvUbRIRJ0Wj7Jo6czmgHUuQzP4x+a/r RCEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687339446; x=1689931446; 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=wgGolVUD4UXN/bgzsidi7fKnE4pGiXRO6QM6WC6v+Ds=; b=ZLCVPfHnoZcQ3QPP+Xt1+qUwNtTCKnQognkz9RmcwpjvMGy/ObyJz2vPv5rr8LRz4B Q6YcvLPChbJTER9PyHliQzwcMKxV4+iicvpGf8kTwFAe2PSjmqF0Nvl7CUka4CLESWJk hbi5q3vtbPB7mVMgSoAHmVnoTdUz7D//I2kkKz9w5AUL2kjOTa21vrsduOB+UueGaoko skrZvk8hoczfOIch5w4V9mhnaxUn88MiMFBj5gJJ5CWzZN9EC2khMa+3qos5XeZsDTcv FKi7wIOfRX37YzrmOvUnpLfes7iLtU9mMKKkWQvQNTVSK4Cblk2jeElxT7YHat6+6Qy9 fSVA== X-Gm-Message-State: AC+VfDzDbE/Xh4I729GhZjo5SyTimZbFQUMtdbdiy9WON9hskgYV/CQD lc0QBriFAZERHOjklauZB0R85g== X-Received: by 2002:a05:6000:11d2:b0:30f:c473:dfd0 with SMTP id i18-20020a05600011d200b0030fc473dfd0mr11415466wrx.12.1687339446086; Wed, 21 Jun 2023 02:24:06 -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.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jun 2023 02:24:05 -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 09/12] can: m_can: Introduce a tx_fifo_in_flight counter Date: Wed, 21 Jun 2023 11:23:47 +0200 Message-Id: <20230621092350.3130866-10-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?1769304205403216136?= X-GMAIL-MSGID: =?utf-8?q?1769304205403216136?= Keep track of the number of transmits in flight. This patch prepares the driver to control the network interface queue based on this counter. By itself this counter be implemented with an atomic, but as we need to do other things in the critical sections later I am using a spinlock instead. Signed-off-by: Markus Schneider-Pargmann Reviewed-by: Simon Horman --- drivers/net/can/m_can/m_can.c | 41 ++++++++++++++++++++++++++++++++++- drivers/net/can/m_can/m_can.h | 4 ++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index 88c8d6a418f0..3353fd9fb3a2 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -465,6 +465,7 @@ static u32 m_can_get_timestamp(struct m_can_classdev *cdev) static void m_can_clean(struct net_device *net) { struct m_can_classdev *cdev = netdev_priv(net); + unsigned long irqflags; for (int i = 0; i != cdev->tx_fifo_size; ++i) { if (!cdev->tx_ops[i].skb) @@ -476,6 +477,10 @@ 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); + + spin_lock_irqsave(&cdev->tx_handling_spinlock, irqflags); + cdev->tx_fifo_in_flight = 0; + spin_unlock_irqrestore(&cdev->tx_handling_spinlock, irqflags); } /* For peripherals, pass skb to rx-offload, which will push skb from @@ -1046,6 +1051,24 @@ static void m_can_tx_update_stats(struct m_can_classdev *cdev, stats->tx_packets++; } +static void m_can_finish_tx(struct m_can_classdev *cdev, int transmitted) +{ + unsigned long irqflags; + + spin_lock_irqsave(&cdev->tx_handling_spinlock, irqflags); + cdev->tx_fifo_in_flight -= transmitted; + spin_unlock_irqrestore(&cdev->tx_handling_spinlock, irqflags); +} + +static void m_can_start_tx(struct m_can_classdev *cdev) +{ + unsigned long irqflags; + + spin_lock_irqsave(&cdev->tx_handling_spinlock, irqflags); + ++cdev->tx_fifo_in_flight; + spin_unlock_irqrestore(&cdev->tx_handling_spinlock, irqflags); +} + static int m_can_echo_tx_event(struct net_device *dev) { u32 txe_count = 0; @@ -1055,6 +1078,7 @@ static int m_can_echo_tx_event(struct net_device *dev) int i = 0; int err = 0; unsigned int msg_mark; + int processed = 0; struct m_can_classdev *cdev = netdev_priv(dev); @@ -1084,12 +1108,15 @@ static int m_can_echo_tx_event(struct net_device *dev) /* update stats */ m_can_tx_update_stats(cdev, msg_mark, timestamp); + ++processed; } if (ack_fgi != -1) m_can_write(cdev, M_CAN_TXEFA, FIELD_PREP(TXEFA_EFAI_MASK, ack_fgi)); + m_can_finish_tx(cdev, processed); + return err; } @@ -1168,6 +1195,7 @@ static irqreturn_t m_can_isr(int irq, void *dev_id) timestamp = m_can_get_timestamp(cdev); m_can_tx_update_stats(cdev, 0, timestamp); netif_wake_queue(dev); + m_can_finish_tx(cdev, 1); } } else { if (ir & (IR_TEFN | IR_TEFW)) { @@ -1854,11 +1882,22 @@ static netdev_tx_t m_can_start_peripheral_xmit(struct m_can_classdev *cdev, } netif_stop_queue(cdev->net); + + m_can_start_tx(cdev); + m_can_tx_queue_skb(cdev, skb); return NETDEV_TX_OK; } +static netdev_tx_t m_can_start_fast_xmit(struct m_can_classdev *cdev, + struct sk_buff *skb) +{ + m_can_start_tx(cdev); + + return m_can_tx_handler(cdev, skb); +} + static netdev_tx_t m_can_start_xmit(struct sk_buff *skb, struct net_device *dev) { @@ -1870,7 +1909,7 @@ static netdev_tx_t m_can_start_xmit(struct sk_buff *skb, if (cdev->is_peripheral) return m_can_start_peripheral_xmit(cdev, skb); else - return m_can_tx_handler(cdev, skb); + return m_can_start_fast_xmit(cdev, skb); } static int m_can_open(struct net_device *dev) diff --git a/drivers/net/can/m_can/m_can.h b/drivers/net/can/m_can/m_can.h index 38b154fea04b..5c182aece15c 100644 --- a/drivers/net/can/m_can/m_can.h +++ b/drivers/net/can/m_can/m_can.h @@ -109,6 +109,10 @@ struct m_can_classdev { // Store this internally to avoid fetch delays on peripheral chips u32 tx_fifo_putidx; + /* Protects shared state between start_xmit and m_can_isr */ + spinlock_t tx_handling_spinlock; + int tx_fifo_in_flight; + struct m_can_tx_op *tx_ops; int tx_fifo_size; int next_tx_op; From patchwork Wed Jun 21 09:23:48 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: 110901 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4233888vqr; Wed, 21 Jun 2023 02:31:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5/h9PuskZl/lHJjQBlXbEAJ6T7uIY/1oa9J95nwNENVifCGBy/2tJdfcjcKRyDlrUTIND8 X-Received: by 2002:a05:6358:1a84:b0:130:e675:3e8c with SMTP id gm4-20020a0563581a8400b00130e6753e8cmr6284606rwb.28.1687339916244; Wed, 21 Jun 2023 02:31:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687339916; cv=none; d=google.com; s=arc-20160816; b=WUAF+O/O0tdbxSFgVpW/w7tx9KcaZm7SjRNRcOYQ83QWecxDuGAbtMCkRIIjAqE/KW +U1fHEKGzZ1fXAVdppY8+jmtXiuQ0IGHB7tLAFmEzWSeL4sON1KBifWrsY5BJUk28bli wE0fGUwR+fT867RFnF+5f6GPYKYF6Ww5gdwxhCGduemyaNq2aQPGJXPHevyVNmWA/0+c oYXCVW817iv0jmmYNTmeSA/bfHUHG0pX9lCt7yf1sgvJE7C+s0u8DzoyRFkli2+HK6Gp J275/mYCwITKXUxt58ctQlx7M1BsadPB29uQwGOSww3pZjjgIKBHrdPa35q2klo11YCC xsoA== 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=P6rWS7bREqVUPkH2+6lOc5shnNXmaz1zo3KIcC701tw=; b=feJXeWVZt+uqQTphpJtV1fUzvkvZdRE5fUhE7Y84aTnXFfTRsTZSVq0LrU+IpRHJlc MxYn+MC3NBJxbT6b9c5930Xf/XOnzu24eGGRptaVfCoVDeLpPiTPkMUzPLFXdMve1Jn4 mIPzvM61q0JoS3aQOkLLFFnIeGAu/kDmecaN8IvVktE7fm1TZVOStcib9zbP3BvTjBB4 tpdr/0SjD8eF4Zo0Vi5//eychxt3zDnIG24ghyAejkqj1QlC0f+Ft8GkFUjiV1aGp70r b437VtCFsy0FGHrP4NjwPeidz9gVm8hXdB3Od1hEYkCqN++kZI28xnOQTX3KKlDJyBIh H84w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20221208.gappssmtp.com header.s=20221208 header.b=IdEDUigz; 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 s124-20020a632c82000000b005533e5cdfe0si3619696pgs.650.2023.06.21.02.31.41; Wed, 21 Jun 2023 02:31:56 -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=IdEDUigz; 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 S232036AbjFUJZP (ORCPT + 99 others); Wed, 21 Jun 2023 05:25:15 -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 S230414AbjFUJY1 (ORCPT ); Wed, 21 Jun 2023 05:24:27 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4AB01BD0 for ; Wed, 21 Jun 2023 02:24:08 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-3110a5f2832so5352495f8f.1 for ; Wed, 21 Jun 2023 02:24:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20221208.gappssmtp.com; s=20221208; t=1687339447; x=1689931447; 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=P6rWS7bREqVUPkH2+6lOc5shnNXmaz1zo3KIcC701tw=; b=IdEDUigz2e/1Ljo91fcbJy4qTNc9c2A1u+FPRbyB8azGWrnWOlz8CI9bAgex0hX5Ji lAYk97/j3J9lMM1ctK9UHR2RWC3j355Hhwpm8vmbM9ZQEBWPuiVzcIkVjSA9gAi6fIYG O8EMOLbEGToTe7G4tBI6j58uRHEIQusPTHaqqKISVYBNirpiJiCylWAGn7MYYkKD+LYA lg7YIDwv9hXrGUcqEWn9z/ER8DCRNlFuLykGE/ScENkQxi32fE7segAodG6Za+A9uxf9 UPbJRYKHPbZ5ByaCIzmM/wKjXLyKB0yo1RwawzcljcSnpmlFhMZJvyD8ydmuzfH8TJyf NQNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687339447; x=1689931447; 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=P6rWS7bREqVUPkH2+6lOc5shnNXmaz1zo3KIcC701tw=; b=ccFByTB9zpuwt1E9b4cqiUBUGOd+5sS1VUZsVZ8cGuKioVJFfHsDRmWxTtTeOCL0BB d7f3H8YlCmlquFEKi+xj657LZ5tjz7xjD6D0OdtvIg7LOTw32QyXzmmeVKAWKUjoV1Kk cW1jh/mG2W4ljdqj3mUcfFM9J9lCwUsXIigOkQ51lXCk8+DgZqYhSt7ipwPLbP4BEG4Q +oE6icnvJ4TezP5nF1IqWrCs1FCkTttk+HSSaEKvQRUmVcO807BCj2gNL0t5f3bFWJ/Y xAJZ+pKEP8gwZ061xL2rnrBn1N3+WzqShFCYCOQDOQbnzUXE51uFGiPNJsI5bCSEpg+l e6Gg== X-Gm-Message-State: AC+VfDyph6OeW3A5yeuWuL8eZgCRByTTQ4c5f5QB0PZZO5MJ/CfJNiRX rh1LwaFPje+pZ3Ko/nnLpahE5Q== X-Received: by 2002:adf:f409:0:b0:311:3eaf:f011 with SMTP id g9-20020adff409000000b003113eaff011mr7583058wro.19.1687339447165; Wed, 21 Jun 2023 02:24:07 -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.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jun 2023 02:24:06 -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 10/12] can: m_can: Use tx_fifo_in_flight for netif_queue control Date: Wed, 21 Jun 2023 11:23:48 +0200 Message-Id: <20230621092350.3130866-11-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?1769304139804940287?= X-GMAIL-MSGID: =?utf-8?q?1769304139804940287?= The network queue is currently always stopped in start_xmit and continued in the interrupt handler. This is not possible anymore if we want to keep multiple transmits in flight in parallel. Use the previously introduced tx_fifo_in_flight counter to control the network queue instead. This has the benefit of not needing to ask the hardware about fifo status. This patch stops the network queue in start_xmit if the number of transmits in flight reaches the size of the fifo and wakes up the queue from the interrupt handler once the transmits in flight drops below the fifo size. This means any skbs over the limit will be rejected immediately in start_xmit (it shouldn't be possible at all to reach that state anyways). The maximum number of transmits in flight is the size of the fifo. Signed-off-by: Markus Schneider-Pargmann --- drivers/net/can/m_can/m_can.c | 85 +++++++++++------------------------ 1 file changed, 26 insertions(+), 59 deletions(-) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index 3353fd9fb3a2..38bdab9b5cd6 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -376,16 +376,6 @@ m_can_txe_fifo_read(struct m_can_classdev *cdev, u32 fgi, u32 offset, u32 *val) return cdev->ops->read_fifo(cdev, addr_offset, val, 1); } -static inline bool _m_can_tx_fifo_full(u32 txfqs) -{ - return !!(txfqs & TXFQS_TFQF); -} - -static inline bool m_can_tx_fifo_full(struct m_can_classdev *cdev) -{ - return _m_can_tx_fifo_full(m_can_read(cdev, M_CAN_TXFQS)); -} - static void m_can_config_endisable(struct m_can_classdev *cdev, bool enable) { u32 cccr = m_can_read(cdev, M_CAN_CCCR); @@ -1056,17 +1046,31 @@ static void m_can_finish_tx(struct m_can_classdev *cdev, int transmitted) unsigned long irqflags; 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); cdev->tx_fifo_in_flight -= transmitted; spin_unlock_irqrestore(&cdev->tx_handling_spinlock, irqflags); } -static void m_can_start_tx(struct m_can_classdev *cdev) +static netdev_tx_t m_can_start_tx(struct m_can_classdev *cdev) { unsigned long irqflags; + int tx_fifo_in_flight; spin_lock_irqsave(&cdev->tx_handling_spinlock, irqflags); - ++cdev->tx_fifo_in_flight; + tx_fifo_in_flight = cdev->tx_fifo_in_flight + 1; + if (tx_fifo_in_flight >= cdev->tx_fifo_size) { + netif_stop_queue(cdev->net); + if (tx_fifo_in_flight > cdev->tx_fifo_size) { + netdev_err_once(cdev->net, "hard_xmit called while TX FIFO full\n"); + spin_unlock_irqrestore(&cdev->tx_handling_spinlock, irqflags); + return NETDEV_TX_BUSY; + } + } + cdev->tx_fifo_in_flight = tx_fifo_in_flight; spin_unlock_irqrestore(&cdev->tx_handling_spinlock, irqflags); + + return NETDEV_TX_OK; } static int m_can_echo_tx_event(struct net_device *dev) @@ -1194,7 +1198,6 @@ static irqreturn_t m_can_isr(int irq, void *dev_id) if (cdev->is_peripheral) timestamp = m_can_get_timestamp(cdev); m_can_tx_update_stats(cdev, 0, timestamp); - netif_wake_queue(dev); m_can_finish_tx(cdev, 1); } } else { @@ -1202,10 +1205,6 @@ static irqreturn_t m_can_isr(int irq, void *dev_id) /* New TX FIFO Element arrived */ if (m_can_echo_tx_event(dev) != 0) goto out_fail; - - if (netif_queue_stopped(dev) && - !m_can_tx_fifo_full(cdev)) - netif_wake_queue(dev); } } @@ -1705,20 +1704,6 @@ static int m_can_close(struct net_device *dev) return 0; } -static int m_can_next_echo_skb_occupied(struct net_device *dev, u32 putidx) -{ - struct m_can_classdev *cdev = netdev_priv(dev); - /*get wrap around for loopback skb index */ - unsigned int wrap = cdev->can.echo_skb_max; - u32 next_idx; - - /* calculate next index */ - next_idx = (++putidx >= wrap ? 0 : putidx); - - /* check if occupied */ - return !!cdev->can.echo_skb[next_idx]; -} - static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev, struct sk_buff *skb) { @@ -1728,7 +1713,6 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev, struct net_device *dev = cdev->net; struct id_and_dlc fifo_header; u32 cccr, fdflags; - u32 txfqs; int err; u32 putidx; @@ -1783,24 +1767,6 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev, } else { /* Transmit routine for version >= v3.1.x */ - txfqs = m_can_read(cdev, M_CAN_TXFQS); - - /* Check if FIFO full */ - if (_m_can_tx_fifo_full(txfqs)) { - /* This shouldn't happen */ - netif_stop_queue(dev); - netdev_warn(dev, - "TX queue active although FIFO is full."); - - if (cdev->is_peripheral) { - kfree_skb(skb); - dev->stats.tx_dropped++; - return NETDEV_TX_OK; - } else { - return NETDEV_TX_BUSY; - } - } - /* get put index for frame */ putidx = cdev->tx_fifo_putidx; @@ -1838,11 +1804,6 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev, m_can_write(cdev, M_CAN_TXBAR, (1 << putidx)); cdev->tx_fifo_putidx = (++cdev->tx_fifo_putidx >= cdev->can.echo_skb_max ? 0 : cdev->tx_fifo_putidx); - - /* stop network queue if fifo full */ - if (m_can_tx_fifo_full(cdev) || - m_can_next_echo_skb_occupied(dev, putidx)) - netif_stop_queue(dev); } return NETDEV_TX_OK; @@ -1876,14 +1837,16 @@ static void m_can_tx_queue_skb(struct m_can_classdev *cdev, struct sk_buff *skb) static netdev_tx_t m_can_start_peripheral_xmit(struct m_can_classdev *cdev, struct sk_buff *skb) { + netdev_tx_t err; + if (cdev->can.state == CAN_STATE_BUS_OFF) { m_can_clean(cdev->net); return NETDEV_TX_OK; } - netif_stop_queue(cdev->net); - - m_can_start_tx(cdev); + err = m_can_start_tx(cdev); + if (err != NETDEV_TX_OK) + return err; m_can_tx_queue_skb(cdev, skb); @@ -1893,7 +1856,11 @@ static netdev_tx_t m_can_start_peripheral_xmit(struct m_can_classdev *cdev, static netdev_tx_t m_can_start_fast_xmit(struct m_can_classdev *cdev, struct sk_buff *skb) { - m_can_start_tx(cdev); + netdev_tx_t err; + + err = m_can_start_tx(cdev); + if (err != NETDEV_TX_OK) + return err; return m_can_tx_handler(cdev, skb); } 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) From patchwork Wed Jun 21 09:23:50 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: 110906 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4234387vqr; Wed, 21 Jun 2023 02:33:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ73lktiPyXbt7pJcRHOu3zvLFfeLndYYk1sGh+RzUPRdv/P7MAbsjbCOsux209b+oH2ZMpp X-Received: by 2002:a17:903:25cf:b0:1b0:499f:7a8d with SMTP id jc15-20020a17090325cf00b001b0499f7a8dmr9164415plb.9.1687339985241; Wed, 21 Jun 2023 02:33:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687339985; cv=none; d=google.com; s=arc-20160816; b=A0g8O/OQxNeZSil8lcOojvYpGUwh1+2yka09bS9UPwJyoS7KRRcRd9CHSNWYGGoa4R SfXncMFwHHz+h7oSfZtEkJmg4PQuxzQ3WUNFq+gbhVaro7onTZvFyHdxoGOXXLFlfnNM tdDZNOQpF+6ioe1l+psgTKnBZEGQVRLW4rct2v7lxO63tXP0J/+k6GQqbNmeR+Ih6LRp PANP0Wwm0PPdEb//5IyMuGYGmm1VzznACVVQOR7VWus4Dq/dWp42E6euppSYlpKafX4H 0kj8y7igSAA6hVSJ5qX/xan9ImanFi/zoGWRMA2BSPGQgpqmO5vr+GWHdQnaovpCz8XN thOw== 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=tSaqA2+LFEta6gdn/o/4wTZ/gzZyVMVxUFSu8tBDIgo=; b=fCP6nLAAZJZATzjapNgZne+C47MdqtrG3r6oAg3NVZjuOGA9/oRUutL7RjypP4+g0H vFC/4mxiLhvh2dp+FCvQlLafT3Z5ZvDq9HL6nG+BddlXRvckUC9oHboYNAMgEO6vjVs2 p6kw5C3bGrKNkwOcxVyknR4AaT5BwcSYER8S0TL9hIGQTydZSIUpR4Cc3lr3S1rgsl/S HKV5uJvFn1iwqGF7mTykXDrz3hUUWIW9Ql9JIppTLbG5gEDFqc/coSUqGucyrZ24EyKv 0HHoubGYOOPB4ZJHjNVIVY+v2Xp0B+HeZUjx7H2zM8Suq5a9fq+b0IAwNzt+dfKyjeWG /lKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20221208.gappssmtp.com header.s=20221208 header.b=PIgwGsjq; 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 k14-20020a170902c40e00b001b03cf17e5dsi4600073plk.12.2023.06.21.02.32.52; Wed, 21 Jun 2023 02:33:05 -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=PIgwGsjq; 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 S232105AbjFUJZW (ORCPT + 99 others); Wed, 21 Jun 2023 05:25:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231519AbjFUJY3 (ORCPT ); Wed, 21 Jun 2023 05:24:29 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 262B81BE2 for ; Wed, 21 Jun 2023 02:24:10 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-3112d202363so4084797f8f.3 for ; Wed, 21 Jun 2023 02:24:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20221208.gappssmtp.com; s=20221208; t=1687339449; x=1689931449; 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=tSaqA2+LFEta6gdn/o/4wTZ/gzZyVMVxUFSu8tBDIgo=; b=PIgwGsjqRRBnD4wUED0zMgDd90izGj+VUDD9EgoqqxSaxj/EA/sixV9j0Puhbj6yvd i1Ac0Rlms2EVdNwTS5h1sPCi/JjPPAK6m66f+HEwmgOh8D8uZMrVbGn/biLYxZI+BECq XpkAWKQlObsxZ/I51tzMmRbncT39WnbXS+8nl9N5uTZhSuuTZfacrHmIfwjzyHlPZsKB aNAtUdSAbjgLFLrTvaE0GMxn4YiN0CZOBqxzkMr3lFGuEwx9aqn/Vg5a3G+9ZUchNjL+ Yk0OrNCbOU/PGc9uO3FRpdu9urD98t0PRfv23kLIMGEvZ9KcdBruuqTU7Y9EsBjTkh72 YvtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687339449; x=1689931449; 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=tSaqA2+LFEta6gdn/o/4wTZ/gzZyVMVxUFSu8tBDIgo=; b=dABOf8LN5Cx2iQe4rLEV8gfL4Ap8fKqoASnEcpq592Wna/pz7UOXOPkpq1X68YX9YK jpipeAJfK1sbw7uRyksoliF6jJqj6AZGZA4DNmMqOeeGpsgV9aC67XHS1ByLZi0TyG/o B+wI1FXWCZmFA++op5edA3DLHxiZS5l/agZBU7KjEyb72YfJCjjbGTxMbmIc9fQCA/0H t0s9P5EDi3jnNt1L1eCa/bI4GG5Wb5C+BV6E/V5IqVMF8k5/BdTL7K2q+KRqNe+WtWka gTH1SgPtXU6nKrPup1O6Si2uFtMOwWvYC+k5EEw9a32+U3ZRDO7Wige3emguTrv8whDg lioA== X-Gm-Message-State: AC+VfDz1aCYqLGaUYWr+N4urb6GUeQQZq18R96J94H+9/BI6qyfiXmNL tpJWkB4yiCy/h6myJEvvPLnPaQ== X-Received: by 2002:adf:f203:0:b0:30f:ca58:39ca with SMTP id p3-20020adff203000000b0030fca5839camr11486248wro.31.1687339449246; Wed, 21 Jun 2023 02:24:09 -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.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jun 2023 02:24:08 -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 12/12] can: m_can: Implement transmit submission coalescing Date: Wed, 21 Jun 2023 11:23:50 +0200 Message-Id: <20230621092350.3130866-13-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=ham 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?1769304212257869223?= X-GMAIL-MSGID: =?utf-8?q?1769304212257869223?= m_can supports submitting multiple transmits with one register write. This is an interesting option to reduce the number of SPI transfers for peripheral chips. The m_can_tx_op is extended with a bool that signals if it is the last transmission and the submit should be executed immediately. The worker then writes the skb to the FIFO and submits it only if the submit bool is set. If it isn't set, the worker will write the next skb which is waiting in the workqueue to the FIFO, etc. Signed-off-by: Markus Schneider-Pargmann --- Notes: Notes: - I ran into lost messages in the receive FIFO when using this implementation. I guess this only shows up with my test setup in loopback mode and maybe not enough CPU power. - I put this behind the tx-frames ethtool coalescing option as we do wait before submitting packages but it is something different than the tx-frames-irq option. I am not sure if this is the correct option, please let me know. drivers/net/can/m_can/m_can.c | 55 ++++++++++++++++++++++++++++++++--- drivers/net/can/m_can/m_can.h | 6 ++++ 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index 62e275c87c29..50909b9c0e7c 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -1515,6 +1515,9 @@ static int m_can_start(struct net_device *dev) if (ret) return ret; + netdev_queue_set_dql_min_limit(netdev_get_tx_queue(cdev->net, 0), + cdev->tx_max_coalesced_frames); + cdev->can.state = CAN_STATE_ERROR_ACTIVE; m_can_enable_all_interrupts(cdev); @@ -1812,8 +1815,13 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev, */ 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)); + if (cdev->is_peripheral) { + /* Delay enabling TX FIFO element */ + cdev->tx_peripheral_submit |= BIT(putidx); + } else { + /* Enable TX FIFO element to start transfer */ + m_can_write(cdev, M_CAN_TXBAR, BIT(putidx)); + } cdev->tx_fifo_putidx = (++cdev->tx_fifo_putidx >= cdev->can.echo_skb_max ? 0 : cdev->tx_fifo_putidx); } @@ -1826,6 +1834,17 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev, return NETDEV_TX_BUSY; } +static void m_can_tx_submit(struct m_can_classdev *cdev) +{ + if (cdev->version == 30) + return; + if (!cdev->is_peripheral) + return; + + m_can_write(cdev, M_CAN_TXBAR, cdev->tx_peripheral_submit); + cdev->tx_peripheral_submit = 0; +} + static void m_can_tx_work_queue(struct work_struct *ws) { struct m_can_tx_op *op = container_of(ws, struct m_can_tx_op, work); @@ -1834,11 +1853,15 @@ static void m_can_tx_work_queue(struct work_struct *ws) op->skb = NULL; m_can_tx_handler(cdev, skb); + if (op->submit) + m_can_tx_submit(cdev); } -static void m_can_tx_queue_skb(struct m_can_classdev *cdev, struct sk_buff *skb) +static void m_can_tx_queue_skb(struct m_can_classdev *cdev, struct sk_buff *skb, + bool submit) { cdev->tx_ops[cdev->next_tx_op].skb = skb; + cdev->tx_ops[cdev->next_tx_op].submit = submit; queue_work(cdev->tx_wq, &cdev->tx_ops[cdev->next_tx_op].work); ++cdev->next_tx_op; @@ -1850,6 +1873,7 @@ static netdev_tx_t m_can_start_peripheral_xmit(struct m_can_classdev *cdev, struct sk_buff *skb) { netdev_tx_t err; + bool submit; if (cdev->can.state == CAN_STATE_BUS_OFF) { m_can_clean(cdev->net); @@ -1860,7 +1884,15 @@ static netdev_tx_t m_can_start_peripheral_xmit(struct m_can_classdev *cdev, if (err != NETDEV_TX_OK) return err; - m_can_tx_queue_skb(cdev, skb); + ++cdev->nr_txs_without_submit; + if (cdev->nr_txs_without_submit >= cdev->tx_max_coalesced_frames || + !netdev_xmit_more()) { + cdev->nr_txs_without_submit = 0; + submit = true; + } else { + submit = false; + } + m_can_tx_queue_skb(cdev, skb, submit); return NETDEV_TX_OK; } @@ -1992,6 +2024,7 @@ static int m_can_get_coalesce(struct net_device *dev, ec->rx_max_coalesced_frames_irq = cdev->rx_max_coalesced_frames_irq; ec->rx_coalesce_usecs_irq = cdev->rx_coalesce_usecs_irq; + ec->tx_max_coalesced_frames = cdev->tx_max_coalesced_frames; ec->tx_max_coalesced_frames_irq = cdev->tx_max_coalesced_frames_irq; ec->tx_coalesce_usecs_irq = cdev->tx_coalesce_usecs_irq; @@ -2036,6 +2069,18 @@ static int m_can_set_coalesce(struct net_device *dev, netdev_err(dev, "tx-frames-irq and tx-usecs-irq can only be set together\n"); return -EINVAL; } + if (ec->tx_max_coalesced_frames > cdev->mcfg[MRAM_TXE].num) { + netdev_err(dev, "tx-frames %u greater than the TX event FIFO %u\n", + ec->tx_max_coalesced_frames, + cdev->mcfg[MRAM_TXE].num); + return -EINVAL; + } + if (ec->tx_max_coalesced_frames > cdev->mcfg[MRAM_TXB].num) { + netdev_err(dev, "tx-frames %u greater than the TX FIFO %u\n", + ec->tx_max_coalesced_frames, + cdev->mcfg[MRAM_TXB].num); + return -EINVAL; + } if (ec->rx_coalesce_usecs_irq != 0 && ec->tx_coalesce_usecs_irq != 0 && ec->rx_coalesce_usecs_irq != ec->tx_coalesce_usecs_irq) { netdev_err(dev, "rx-usecs-irq %u needs to be equal to tx-usecs-irq %u if both are enabled\n", @@ -2046,6 +2091,7 @@ static int m_can_set_coalesce(struct net_device *dev, cdev->rx_max_coalesced_frames_irq = ec->rx_max_coalesced_frames_irq; cdev->rx_coalesce_usecs_irq = ec->rx_coalesce_usecs_irq; + cdev->tx_max_coalesced_frames = ec->tx_max_coalesced_frames; cdev->tx_max_coalesced_frames_irq = ec->tx_max_coalesced_frames_irq; cdev->tx_coalesce_usecs_irq = ec->tx_coalesce_usecs_irq; @@ -2063,6 +2109,7 @@ static const struct ethtool_ops m_can_ethtool_ops = { .supported_coalesce_params = ETHTOOL_COALESCE_RX_USECS_IRQ | ETHTOOL_COALESCE_RX_MAX_FRAMES_IRQ | ETHTOOL_COALESCE_TX_USECS_IRQ | + ETHTOOL_COALESCE_TX_MAX_FRAMES | ETHTOOL_COALESCE_TX_MAX_FRAMES_IRQ, .get_ts_info = ethtool_op_get_ts_info, .get_coalesce = m_can_get_coalesce, diff --git a/drivers/net/can/m_can/m_can.h b/drivers/net/can/m_can/m_can.h index 5c182aece15c..54af26a94042 100644 --- a/drivers/net/can/m_can/m_can.h +++ b/drivers/net/can/m_can/m_can.h @@ -74,6 +74,7 @@ struct m_can_tx_op { struct m_can_classdev *cdev; struct work_struct work; struct sk_buff *skb; + bool submit; }; struct m_can_classdev { @@ -103,6 +104,7 @@ struct m_can_classdev { u32 active_interrupts; u32 rx_max_coalesced_frames_irq; u32 rx_coalesce_usecs_irq; + u32 tx_max_coalesced_frames; u32 tx_max_coalesced_frames_irq; u32 tx_coalesce_usecs_irq; @@ -117,6 +119,10 @@ struct m_can_classdev { int tx_fifo_size; int next_tx_op; + int nr_txs_without_submit; + /* bitfield of fifo elements that will be submitted together */ + u32 tx_peripheral_submit; + struct mram_cfg mcfg[MRAM_CFG_NUM]; };