From patchwork Wed Feb 7 09:32:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Schneider-Pargmann X-Patchwork-Id: 197812 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2110720dyb; Wed, 7 Feb 2024 01:33:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IGGopnBTejpBdBDf4SxAxvnKRzXnG7BIhQGrCvRUsHUkvgpgSa9j0lbr0D1VrqXqnq8Nmqh X-Received: by 2002:a05:620a:3727:b0:785:9ed9:b430 with SMTP id de39-20020a05620a372700b007859ed9b430mr654143qkb.52.1707298422193; Wed, 07 Feb 2024 01:33:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707298422; cv=pass; d=google.com; s=arc-20160816; b=D9nNE5VNfld4ip278iVN67PPYY5idE9b7nXRIPCGhjRkx6AtKHkDS1eX8UlE23LqsD 9HwmCHYfZ6KyZ++s/SDrjFMYkE4S/eruVCu7xwwV1IalogLm8C+uf0o0pwGCiCjbE0BH 0xVZBNkFeaeneeNmHprCiKIsBkzFkbfcS0+23cvMhrSeySpdkNXMdbfPCRMZz2Uwyx3C vk3XGf4iWDhAGwvXwPdTShWvb0NbSlPda42WAlhwWUWkavQ8/HqLKFfks0US8tU55q88 M0TfHakxKy342KPKhGVIdxmQjZkkxs7rRK1KkfbjCCjUCV9g5F7+6ytZlKqtAy6up9w+ VU4A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=gMSC3a9LZoI/QoYVZa72EO+oYUfJG09wFtMJdz3hQvY=; fh=4mUEf33DePTCV9+BlPjy2HGXv664JxTCkI0X9ZNTdHg=; b=NJeIG8ydXmeOcB2m+xc5xlU19xHg2LZWEsTlU7KKrzkw50R0sooh7Tfgm9E2P8BWW6 WkIgo3PRmTsNnfnDUApRZUJz5+fMUhKLC8JfV04COTK12LfkSaDA0sWMlAzCc40GEqMg GWVnHvp2SYn7UHNP4DWckleSLCBRVOLE6dUig7xrgIOSpIYylK0r/A6QZvn4xlsevE7W Q3xFtHv8SppyUNkcQZKnxV7vuwCXte+npG9JfH6FbFveULr6gdh5GeFFh0m3QZLa9FYw kByENwPuuNBPC69e6CyUhQBO2nPvKruOUCUbYI+d7Hc6IXfALT+KOhPF++kWmzkZGK3x m0zg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=F84pdEGf; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-56211-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56211-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCWFDf0WZvVbYFuuHg1zFwJigVlIXS9ZSQWZmVnOJkhHGPB8YhmgJcx0btoYn/vAyGg1SlNKKV/UfWUuuyRXHfBan/B4Bw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id m17-20020a05620a24d100b00785601ff8a5si781656qkn.544.2024.02.07.01.33.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 01:33:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56211-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=F84pdEGf; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-56211-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56211-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id D3A1D1C229C3 for ; Wed, 7 Feb 2024 09:33:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2A64825613; Wed, 7 Feb 2024 09:32:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="F84pdEGf" Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B94D121112 for ; Wed, 7 Feb 2024 09:32:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707298359; cv=none; b=tPpQ4LHgV0rKHiTQQryqwVwQUWspUYEYp/tEyXrUXcJ2qBBvq5vYfGruRlJ08aJupf6QsSVpQKOlDtCZ8TEhzGQxuJI6azKRkdZxX2xe7zTbyvcg51mUb6dACSyz0Ue4CJ1GnetvKASgzdA+jbpTESGzFA6vvoUsQJyY7xrHJU4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707298359; c=relaxed/simple; bh=kdLifE5+vi9NVE1VnFjcL8NvUd7d6otTYHIc5P8vu/0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qH7a1OQNXVdjE/cXwP7W1do1JX8rlZ00538fnBTdA64d12GOH9BaERZPYJBhoKln7CbxuRQtiidUf0ntv/3r+xCNVC69jGXMSwwC23Jn9YkQL3Lmc+PhFuT8pVvnqwzqYxmw8nZ1kg1BDKvgsPvNX4uCilY3R3faR4JXIDk61LU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=F84pdEGf; arc=none smtp.client-ip=209.85.218.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a372a3773a5so44500366b.3 for ; Wed, 07 Feb 2024 01:32:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1707298356; x=1707903156; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gMSC3a9LZoI/QoYVZa72EO+oYUfJG09wFtMJdz3hQvY=; b=F84pdEGfbJmbDdoFJGX7ypCRXY2fRH0IfcsW4L05LfKeZS6TDHS8R+FeixKixmg/M8 Vg4h9SAjcmyrgHwubf9SPtnpYaR7Vm/Ili97hWdxKI7iqda6Z+fzyfv6+mPNcdqtYLO6 MGkssrR66uzVYGv7zibfmkj1RVq8iBDMjC27/Z5jfNzNISwMgys81D84UbyiquoIvShY Mc5Lb04BPN6/vY7/MDDGu7PoBaUr54rbd781r9lERws3xtup2prDA5TUYqA27Yqw/0W6 9U1TZGtqmzz5oSMTrtB/bBzUoqBRz+ntRCDompc1BT36S7BAkHXtCB8leWumz/LpPW4e eJ9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707298356; x=1707903156; 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=gMSC3a9LZoI/QoYVZa72EO+oYUfJG09wFtMJdz3hQvY=; b=PMZv9gL0ofbgxptc11TL+eYSyV/NWEGxfT8pQUh0ZDP9lukfD3qTsrPbaJ778tH4Vs pwsjwCEC9WY2UiyB54krlUkPMkcwRLwoWnUroBloi4swladXNECKrxc6Ek3gwnASVCq0 OBNnUd39YwA0zHBKHM+1stgoL3HV1Q+1PAPFHGbzjaR53yaXxB3puhGJWqNx55DPcy7A lf6wlslc3YYcg1KZmQf0E+o6BtniNLUSL2kpjyIRojyHBmRY2mBBBRfvAKol83+NJiEo uk6hbK0SzRGhdx2/w4pg4MX22zl8NlOV6IOtlFZKuLdThDf4q6ZDv8EtWQmsKxWnPCyZ KCHg== X-Gm-Message-State: AOJu0Ywt+KdL7y9rRIrhJYJSMObB/3MyKVP4k1kCSyWtNI1mXvu1p+yM DIUAbtfWed8vQ2bBrcNkt1VhJps439wFdAZdvrY/BiGD4AYA+yE9JmNN5E0FO4A= X-Received: by 2002:a17:906:34cf:b0:a30:2690:5c48 with SMTP id h15-20020a17090634cf00b00a3026905c48mr4088620ejb.8.1707298356082; Wed, 07 Feb 2024 01:32:36 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXhwaVRY5NtaqW5h+0TlVDeFkmaR0rwgTV19WqVeLA1lfQSr0AXEvTdQ4sfhCyMIPZYzLByLipXXB2LWQrB9wWRpy1nIeRNBWHnfVr3SP3I613BeSEVH+10MKW9oF+SFim7/y2rwWZCQAHYjt56o44m5bTgM/tiY5Z/4tqvArlSJMXhbZ+oq4h3Rdwqu20vbKcjjwdzYrg5OVCO7bHCwrAKa2bZjil/aXL8P2tG8xJi/YQAd9ScHZmhxT2PJZV8nO8T/ooULIcyf0atsifuPIdvOkhNGrt0qnmPVD0ZnMua8clG0QmCHwE6EsR/JF1//JedoQCexXhQqteH6pnjo4K5WrcPqQFP2s5LtL4adwhBtkiWKnh2dcDnXXLn/0rNduujHX0jZ8Yh4EMInnIvsmPEB5vd1yTSVl4jyBA1Wo160kz1OvyxOGtXGOEK Received: from blmsp.fritz.box ([2001:4091:a246:821e:6f3b:6b50:4762:8343]) by smtp.gmail.com with ESMTPSA id qo9-20020a170907874900b00a388e24f533sm122336ejc.148.2024.02.07.01.32.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 01:32:35 -0800 (PST) From: Markus Schneider-Pargmann To: Marc Kleine-Budde , Chandrasekar Ramakrishnan , Wolfgang Grandegger , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Tony Lindgren , Judith Mendez Cc: Vincent MAILHOL , Simon Horman , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Julien Panis , Markus Schneider-Pargmann Subject: [PATCH 01/14] can: m_can: Start/Cancel polling timer together with interrupts Date: Wed, 7 Feb 2024 10:32:07 +0100 Message-ID: <20240207093220.2681425-2-msp@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240207093220.2681425-1-msp@baylibre.com> References: <20240207093220.2681425-1-msp@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790232150119467510 X-GMAIL-MSGID: 1790232150119467510 Interrupts are enabled/disabled in more places than just m_can_start() and m_can_stop(). Couple the polling timer with enabling/disabling of all interrupts to achieve equivalent behavior. Cc: Judith Mendez Fixes: b382380c0d2d ("can: m_can: Add hrtimer to generate software interrupt") Signed-off-by: Markus Schneider-Pargmann --- drivers/net/can/m_can/m_can.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index 16ecc11c7f62..2395b1225cc8 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -418,6 +418,13 @@ static void m_can_config_endisable(struct m_can_classdev *cdev, bool enable) static inline void m_can_enable_all_interrupts(struct m_can_classdev *cdev) { + if (!cdev->net->irq) { + dev_dbg(cdev->dev, "Start hrtimer\n"); + hrtimer_start(&cdev->hrtimer, + ms_to_ktime(HRTIMER_POLL_INTERVAL_MS), + HRTIMER_MODE_REL_PINNED); + } + /* Only interrupt line 0 is used in this driver */ m_can_write(cdev, M_CAN_ILE, ILE_EINT0); } @@ -425,6 +432,11 @@ 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_write(cdev, M_CAN_ILE, 0x0); + + if (!cdev->net->irq) { + dev_dbg(cdev->dev, "Stop hrtimer\n"); + hrtimer_cancel(&cdev->hrtimer); + } } /* Retrieve internal timestamp counter from TSCV.TSC, and shift it to 32-bit @@ -1417,12 +1429,6 @@ static int m_can_start(struct net_device *dev) m_can_enable_all_interrupts(cdev); - if (!dev->irq) { - dev_dbg(cdev->dev, "Start hrtimer\n"); - hrtimer_start(&cdev->hrtimer, ms_to_ktime(HRTIMER_POLL_INTERVAL_MS), - HRTIMER_MODE_REL_PINNED); - } - return 0; } @@ -1577,11 +1583,6 @@ static void m_can_stop(struct net_device *dev) { struct m_can_classdev *cdev = netdev_priv(dev); - if (!dev->irq) { - dev_dbg(cdev->dev, "Stop hrtimer\n"); - hrtimer_cancel(&cdev->hrtimer); - } - /* disable all interrupts */ m_can_disable_all_interrupts(cdev); From patchwork Wed Feb 7 09:32:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Schneider-Pargmann X-Patchwork-Id: 197820 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2114214dyb; Wed, 7 Feb 2024 01:41:21 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXhz65R1ZkEmFf+Eb/JwMg7Doo8sJVraUpgFNBsckVbGuEnbnpu650HChvxlz4Htfw11Bn/xWrmSGW3J+5H/LGyFHQqBw== X-Google-Smtp-Source: AGHT+IHqno/N2J3qBArfFY2kcUnPsPznwAFtcJEYVxv34zdd9tO1XWH4a1H4y3+br59Ab5JUVDjV X-Received: by 2002:aa7:d902:0:b0:560:9277:80e5 with SMTP id a2-20020aa7d902000000b00560927780e5mr3552234edr.21.1707298881426; Wed, 07 Feb 2024 01:41:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707298881; cv=pass; d=google.com; s=arc-20160816; b=S0/QMNNgnTtUpGBJToopIdE3GKIvOaDQ7eKu1ZOdEYHqbMQlLAkiVJSi4v3IkiSNZ/ yzUmp3Ox+PincetyCrXBOoVj4f0eoODq8w31J4duHjWGUalQ3l7s/puxgICd93a3wNM2 GP1J5dSCNtOmp3JN5UWe22xNr3sDmowxzqUggM7JPc0AHi+5eKMLuz9B3QNeCd2EA/WY Dnqi8S4aemVjWNFSmekSRuc/bLInrPCahHEeZzZH0yGj2OQkL3MWUua+US6Dhbtua1/6 X9wtxfhCJENB90huWPruNY1F5+s0Df/ukne5QbpHvEx8bXtNrj6u2ME576hwmmSS750j 3Xmw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=9LasvPwar56cmUGpfIKyPUkfrzO6sViDcJ1By12B3aI=; fh=ZUx92O5usljYPa9Pl9Vb2bBuJM1F3irbcRCLw95cqqg=; b=JUHlHtW525+nbKL53ZERaW65vQ0ypgzvqj9TecTAc1XD+sn2YuBd6yk2hA0/BH+zIg 2kQAOvM3EaxFFgKgewb6E4OE0PDqmIZ0CxbPliM4HSQqkpEyFZpa/CwCtIIIyv6vkXJx azd7+0jfINjEKpjCfBrZLhuaJIYBemvyHo+7fNK1kPeb6BFsm7dt/cK0kr1BKB6Q18hE 0omYM88rqG+gSrrC7BOPE3qjx7u2GGqDy2DELme2VUizC9RSa1Mqs3jEaE8TskFJXluP VvlMgibwVwaBPTXZmJRhK/FQUSw2BW4zwvSz8omXYDaNLVbo17wCI+vyjTJ169RDDbcJ ssGw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=TdrbNqjo; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-56212-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56212-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCVV0d4D03jWVGi8INGCiWcYdcvHOTRUb6R7zMyIPHuGKEt1L4HgK3duf14Wcyvee9V7ZILcpr+rDdBAL5Fe+3JaEmAecw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id j12-20020aa7ca4c000000b0055f01c4b079si658091edt.260.2024.02.07.01.41.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 01:41:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56212-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=TdrbNqjo; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-56212-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56212-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D72641F27E76 for ; Wed, 7 Feb 2024 09:34:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3A0DE25635; Wed, 7 Feb 2024 09:32:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="TdrbNqjo" Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E53FE21A02 for ; Wed, 7 Feb 2024 09:32:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707298360; cv=none; b=FBzNLQBOcIE7vPlkXGL7JHfwyvdVZcNtaaC/N3vllRjTVugPUc8ggWHsOx4RO6FBMieqsNkPdFZGeqTlxR9tlTHLaqNZl+k/ePqkmtWqc3sPz/F8vQmDhS9Wj7yRpotZO4u8ErwRRaUpMq40tuKuUIY1La1MIzHqYFDmPZbWN04= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707298360; c=relaxed/simple; bh=xKm31x/RdzKjtmNCaQqPULxnB/TjUDs1QrTh8HGx5EY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UKredWALZEIVf6C7P2QH2okkeKiWIu4EAGqbvpy8W098YJiJtYmVD+OFCjojG4+x4sLv9kyQmKLAS/OZKA0zuHfVWvPzK88zPn76Ycp9d0xqB9/jKUmsVflAevKaCUkoFp1qe9C0SV+HsKRVLmZODJDWdudeYVt3TlzhBj9Zkes= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=TdrbNqjo; arc=none smtp.client-ip=209.85.218.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a38392b9917so53008066b.1 for ; Wed, 07 Feb 2024 01:32:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1707298357; x=1707903157; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9LasvPwar56cmUGpfIKyPUkfrzO6sViDcJ1By12B3aI=; b=TdrbNqjoU8Yir8KxBgsArNv812ClYWoEpIDK23B/C1otESJlUk0xFXAiHoo9jq8tpE nwSgYICUqETyzL9Qba3+f0golCnAm4JN4zKzmOAj3SOTgfJ7iH7x93r6phKs+UmcSzlL pWWC4Pz/S1Hnmmqm319Rv9sbydx0/U0Zp15xparAUcBiOqX2r+cb6sF9TRYsvIxQPEjU wg1838KOI9oDdl+KqxQdE3uaDmb74D98L4NkLCIora6b2Bv1zVXksaeL29yFRhZVnEYm w02PAtF6y7mumpdbPW5WbwVjo5QcO6TW3znapHb/fNnKjJC9JzFF6hlmjpZrR5zWSJNK l1RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707298357; x=1707903157; 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=9LasvPwar56cmUGpfIKyPUkfrzO6sViDcJ1By12B3aI=; b=f4tMEFyXYpE+xFH2gNVDujaNLHqUVjPUtmawNyt5ms6ck5VjY2BVi2YbiscLc0Wgrb ErfAS8lNIWqRVTwRrtoOAPNVn+i1nsQfDCCq8aUc78nuzP0yyGiKQaPEZvz33aOV6Tnf cCOeSNyfrO8eXJLC+QPNvnPVk1i60tRnAgJpR0gHh3IRUHEiTjO3UlRjfT3azjRzhagG 7XYv+HfTnc1lL8ZlGZ0xvNuM9WmnwOVJrbyQtLrwJWOs8UGKwS7tPRNxlgzNZ42TN3Kb QdB7nM0u9lH1gEuHVD0g9p9J0XWaUItQHRYNlXjhyXXVUuitjNhRjfeTFiyjCYKD6lr3 39Fw== X-Forwarded-Encrypted: i=1; AJvYcCVXhOXrRXJtJxV6cPVEryfn2L5Ns01yNgm+ZcPTiW5Nln/WOgwiySccWkyIIpPUjsybwKjjTWLnRwlh5NLxat4poOE+jJOaUqOOuSNI X-Gm-Message-State: AOJu0YzLGXfVt3u8lTkVDtUjI9/2H9EV9QSnBTYngtwCzYc4JtD0zq2s tHN1jRdBPAu1cWP1X07QKpdNdUer72gpqYZoMZ1wWVydhKWKjGZ3cnrOVVlG/mQ= X-Received: by 2002:a17:906:acd:b0:a37:adee:509f with SMTP id z13-20020a1709060acd00b00a37adee509fmr4053526ejf.12.1707298357175; Wed, 07 Feb 2024 01:32:37 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVV6M49yfwmeZao0z9NZWCWgW1TbgNa9mmQo6YeMWH9S0oRB9l+W1LMKezrhQ/zib0uQlUqM+EJvPKLgwl62uSN0iQv1PIOSm+FeRGbIl7byM379mIHHy257MhqVjBVCBWSjLFYK+PBQK0NuxSLnJOHeur/CoWcQgOJ/04UB70kG8RnIW/Lp5XA06XAquEt/vTR4LUClb178PP0kmttpBvAQ59veDHJcvyUMZR7BIv5esU3HyGrT93W/UjaTvMvhVZjklUirn8GVjraVcRZNUVFapW+K1z7s5+8YdOd5uU1yxgZx8OIL2kn7wPRA9tIWyozB3xeXuN5QG7Rfg+71oxuNimp1e+y/ZzGQBqK0iW5QwfQcfcUxaNv9ZLxuanTum/C1w6ZD9vbiqz66rFdVxkbGXFUuvzqXIi7jujxutIXsghjXnzNc7T2w8IK Received: from blmsp.fritz.box ([2001:4091:a246:821e:6f3b:6b50:4762:8343]) by smtp.gmail.com with ESMTPSA id qo9-20020a170907874900b00a388e24f533sm122336ejc.148.2024.02.07.01.32.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 01:32:36 -0800 (PST) From: Markus Schneider-Pargmann To: Marc Kleine-Budde , Chandrasekar Ramakrishnan , Wolfgang Grandegger , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Tony Lindgren , Judith Mendez Cc: Vincent MAILHOL , Simon Horman , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Julien Panis , Markus Schneider-Pargmann Subject: [PATCH 02/14] can: m_can: Move hrtimer init to m_can_class_register Date: Wed, 7 Feb 2024 10:32:08 +0100 Message-ID: <20240207093220.2681425-3-msp@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240207093220.2681425-1-msp@baylibre.com> References: <20240207093220.2681425-1-msp@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790232631503233367 X-GMAIL-MSGID: 1790232631503233367 The hrtimer_init() is called in m_can_plat_probe() and the hrtimer function is set in m_can_class_register(). For readability it is better to keep these two together in m_can_class_register(). Cc: Judith Mendez Signed-off-by: Markus Schneider-Pargmann --- drivers/net/can/m_can/m_can.c | 6 +++++- drivers/net/can/m_can/m_can_platform.c | 4 ---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index 2395b1225cc8..45391492339e 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -2070,8 +2070,12 @@ int m_can_class_register(struct m_can_classdev *cdev) goto clk_disable; } - if (!cdev->net->irq) + if (!cdev->net->irq) { + dev_dbg(cdev->dev, "Polling enabled, initialize hrtimer"); + hrtimer_init(&cdev->hrtimer, CLOCK_MONOTONIC, + HRTIMER_MODE_REL_PINNED); cdev->hrtimer.function = &hrtimer_callback; + } ret = m_can_dev_setup(cdev); if (ret) diff --git a/drivers/net/can/m_can/m_can_platform.c b/drivers/net/can/m_can/m_can_platform.c index cdb28d6a092c..ab1b8211a61c 100644 --- a/drivers/net/can/m_can/m_can_platform.c +++ b/drivers/net/can/m_can/m_can_platform.c @@ -109,10 +109,6 @@ static int m_can_plat_probe(struct platform_device *pdev) ret = irq; goto probe_fail; } - } else { - dev_dbg(mcan_class->dev, "Polling enabled, initialize hrtimer"); - hrtimer_init(&mcan_class->hrtimer, CLOCK_MONOTONIC, - HRTIMER_MODE_REL_PINNED); } /* message ram could be shared */ From patchwork Wed Feb 7 09:32:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Schneider-Pargmann X-Patchwork-Id: 197813 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2111132dyb; Wed, 7 Feb 2024 01:34:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IFhwXyJim+yAj+D9rL3UzCIcxR25FjwP3Gau06V4URJ5P0cOf+XNg7OhdXyf4ic7LTIvJND X-Received: by 2002:a17:902:cecf:b0:1d8:e64d:cd62 with SMTP id d15-20020a170902cecf00b001d8e64dcd62mr4962484plg.4.1707298476513; Wed, 07 Feb 2024 01:34:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707298476; cv=pass; d=google.com; s=arc-20160816; b=iGSclBvx4Sne/wcHOW/DSxi6ElFMgFr/A/4YZVzzjki2QRIe0FP5Tu/k+RpeKfwkII AKt5KfswLnGge9TiBkQcSfXy/OENL8KAJB2baRXbxLlWK1K+cDCuZIVRxj6cVeDDfMO0 wqeDi9DKaJyUQmD4f/ODedPejdgYBJ8zc6FpOCgredcVYK2YJKUYZ1JRluj8eklGrRjw Ntwu+KrA/9a58VdoLfEe6L7LFEdT9ImGwdX6T2d7SJudyFGa+szm1HVBz3OCMgNdUvVJ h944FO7qDpXsMbuLi24JI5Zfp5bmGEQf9EaaBhUxfDmENlkC/qQx3bNhS4/tnilirHYg LpGQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=VqIx4YPebbDa42PI5lR3HpT5nBD0XB/qzFpDRiRKWz4=; fh=pKkPYO7YEnazCMbohQemCqPtSCdIk47f5eB/Fo2ZkXg=; b=DPsmoPxR+y5t63Vb8FFXypnDqNzzHUwyglQlFI4mz3WiC5jXjWEHxjK+c5kdXkonoS rVO1MZ3j+9BvZt5ZvpBZgMqV7GcbRTEoTsVhAmtL1/FaLb12LdkraRa3HzvPhvCnIbaM iEAkLbY8HdHOxBSOf9ksSPM+TseHlbeZmoIKCWCyowOD6pk3Ff/ukdAKR2IqfD1ziRW1 9PnNzst7A1tvCsI1AsnhDyakfSZoWK9PsF0+jqM1OnLTO4mQe8pgpJLcVVl3+O8A0mGZ asm4f2jXZxEHeiEK5rVDS0wZgVRsLEkDf0+KtyudFjxO4yvDnyi9bEjIRB4u+xuRiFPS 8Z8w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b="STwuEo/g"; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-56213-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56213-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCXYJDKwf7qWcZDHqojrS8FdTMN0vMyc0nyihZ4Uh42WgdY77rt2s4//owR5/mUJz7U5WGsXh3I2RKSiP1SgLMjcUssgSg== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id c11-20020a170902d48b00b001d940b83792si1283123plg.574.2024.02.07.01.34.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 01:34:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56213-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b="STwuEo/g"; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-56213-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56213-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id AF9812843B0 for ; Wed, 7 Feb 2024 09:34:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 25A6C2C1A6; Wed, 7 Feb 2024 09:32:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="STwuEo/g" Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E21B21107 for ; Wed, 7 Feb 2024 09:32:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707298362; cv=none; b=XEoETOP542u8z6WpCVOWjSsEUVlWUvwpTtL3d5baDzZMGq73vdBbkjPt8oEm+voHagUpmrPLqLTqoAywLfQ4CKN1/QIteLP/dIW0gmNTz1a6B6LP2Daa1d+nH6MC4y19RvjCEmcURqx6jz3KlngsqxXE9uLJM1yMqqm6bW7rp2s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707298362; c=relaxed/simple; bh=7bSdXgQdUcY0VNdr3J/s8h/nUNIriTpRiX0a0S7PH1g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YyAynuE2vjBLFTZQEE+AipRImuZwL4RcUhw2Yu8cNBawIVJ+0qAQRNQsmvXE9x7k5OBD7ztpdxj2cgihNQVpiSfIucLFdpbgPzUMupdmEe9Jvsncc7O4ux2mmtE+qPTRzGnbBdVaFrDPBFstf+l8aCn+W9ccvA0fsSmNsuyqty4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=STwuEo/g; arc=none smtp.client-ip=209.85.167.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-5114c05806eso604055e87.1 for ; Wed, 07 Feb 2024 01:32:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1707298358; x=1707903158; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VqIx4YPebbDa42PI5lR3HpT5nBD0XB/qzFpDRiRKWz4=; b=STwuEo/grSQuSHWuzhkPooX5IL9eq/y+39QuZcgyKbJ+N7Y4qWh7Ahw5O0nJYpa8JX X/zuomR98iFCU+acS/+EG37WEwSNvBdsMFNCvMkGSNZJWNLt61hWjsGrwiPLQ4QmwjTz hn9JN5Mz1afRnRy1ObI71KAhFPltQ+lwSExrif2RJOjOjC6paPZuOno0MH7zWiw+ZjXK 3Ssd0F0r3ewOr9rffFtY+SsXc0C0kq7Dmv2ilbCtNTxeih46XLcs+BIVAAymqHwXYrnp kerhcINjG2jR3DGzlMF2q1P9hHiyO6uCgIq2l9xW/nhYbgMfYClEij0VwrriEEh/psRW rsmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707298358; x=1707903158; 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=VqIx4YPebbDa42PI5lR3HpT5nBD0XB/qzFpDRiRKWz4=; b=SGxp/7XYc+/HhpaFZRYkxHCgEzZC08Wm0V8tTBjLB3mJWtwZkGd+oJH2MVOShgfMsp R44zLSofOYyD3PJLPS3kyh9CkhyyQND3TeYkuthqYCU9/pOAfWdiTm/vtzkatXbu5oHh CnpS26hup+mw1jOGNOs2rWvFhX91DWYN+g7gbZRQQMFt/Oi0icqt4UEI8/Myt4ah8V56 f0EulpW7afriTSeG61+fW7WRV+0VDG532z5JXxYD8/da0heNwJ/kfOOK600JwkNayhBh BGwh5hTFGrCMaiOjOYoVtDU7WHjG9AGNBxxEAuZM/t12FSeRSp66cqH3yv2z1fDCY+EW w82g== X-Gm-Message-State: AOJu0YzbQiWrias9uHpN7bjAV9aF5mbYIUN7j/NJVBKgXO+tAcF22xg7 Uqf1TgbFqo5gCNaetKWT9HdbPR1YhmRDriJg8RiT2JwpOnDcQD5YFxUR55sRZNg= X-Received: by 2002:a19:5f57:0:b0:511:51a9:7759 with SMTP id a23-20020a195f57000000b0051151a97759mr3912294lfj.64.1707298358354; Wed, 07 Feb 2024 01:32:38 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCViyuYpZSFAh9YXyT4xbYF9rpB2bg7/qwN83vxYPI3PqTLT9mTjDBWutcVFxx25llRWCWp7eWSiimanYiJqfwKA4atnLCP4aiFHGIJ9vLYG8e20DKQf6O4goKx7sEd9FOj/LQ0xvua0CNl2Bu9Osf1BWQTY3PFJpl+IQIDjU3hanQRFyoN50k3UYismIncBA6kTWD+M8IjZt82VER0h04OwTgRUpWhM5MhnH1p73JxumCIwjAkKIsukzwmKxWwAblouOCxtDaRcMDfHUb/MYTjTNVZv2SZYJ++UF1CGUoLnvrXHwU1lhL6D1BIcy1zYrH09RzfgPuh5VZ9rt7cY9LOEB4E3OZRXlHqS/pJiys/aGVvzoljPQ4oE30bWgbCy4jQI2sz9cHOVEffVojoyo+pwc9T96lWiskNgYhFZ3MEA/saChNvW0tpRWa2A/q24PZh2YhKDIZEShyYN4I2S+Oq80zqPSi2i Received: from blmsp.fritz.box ([2001:4091:a246:821e:6f3b:6b50:4762:8343]) by smtp.gmail.com with ESMTPSA id qo9-20020a170907874900b00a388e24f533sm122336ejc.148.2024.02.07.01.32.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 01:32:37 -0800 (PST) From: Markus Schneider-Pargmann To: Marc Kleine-Budde , Chandrasekar Ramakrishnan , Wolfgang Grandegger , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Tony Lindgren , Judith Mendez Cc: Vincent MAILHOL , Simon Horman , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Julien Panis , Markus Schneider-Pargmann , Simon Horman Subject: [PATCH 03/14] can: m_can: Write transmit header and data in one transaction Date: Wed, 7 Feb 2024 10:32:09 +0100 Message-ID: <20240207093220.2681425-4-msp@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240207093220.2681425-1-msp@baylibre.com> References: <20240207093220.2681425-1-msp@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790232207324044200 X-GMAIL-MSGID: 1790232207324044200 Combine header and data before writing to the transmit fifo to reduce the overhead for peripheral chips. Signed-off-by: Markus Schneider-Pargmann Reviewed-by: Simon Horman --- drivers/net/can/m_can/m_can.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index 45391492339e..a01c9261331d 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -320,6 +320,12 @@ struct id_and_dlc { u32 dlc; }; +struct m_can_fifo_element { + u32 id; + u32 dlc; + u8 data[CANFD_MAX_DLEN]; +}; + static inline u32 m_can_read(struct m_can_classdev *cdev, enum m_can_reg reg) { return cdev->ops->read_reg(cdev, reg); @@ -1637,9 +1643,10 @@ static int m_can_next_echo_skb_occupied(struct net_device *dev, int putidx) static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev) { struct canfd_frame *cf = (struct canfd_frame *)cdev->tx_skb->data; + u8 len_padded = DIV_ROUND_UP(cf->len, 4); + struct m_can_fifo_element fifo_element; struct net_device *dev = cdev->net; struct sk_buff *skb = cdev->tx_skb; - struct id_and_dlc fifo_header; u32 cccr, fdflags; u32 txfqs; int err; @@ -1650,27 +1657,27 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev) /* Generate ID field for TX buffer Element */ /* Common to all supported M_CAN versions */ if (cf->can_id & CAN_EFF_FLAG) { - fifo_header.id = cf->can_id & CAN_EFF_MASK; - fifo_header.id |= TX_BUF_XTD; + fifo_element.id = cf->can_id & CAN_EFF_MASK; + fifo_element.id |= TX_BUF_XTD; } else { - fifo_header.id = ((cf->can_id & CAN_SFF_MASK) << 18); + fifo_element.id = ((cf->can_id & CAN_SFF_MASK) << 18); } if (cf->can_id & CAN_RTR_FLAG) - fifo_header.id |= TX_BUF_RTR; + fifo_element.id |= TX_BUF_RTR; if (cdev->version == 30) { netif_stop_queue(dev); - fifo_header.dlc = can_fd_len2dlc(cf->len) << 16; + fifo_element.dlc = can_fd_len2dlc(cf->len) << 16; /* Write the frame ID, DLC, and payload to the FIFO element. */ - err = m_can_fifo_write(cdev, 0, M_CAN_FIFO_ID, &fifo_header, 2); + err = m_can_fifo_write(cdev, 0, M_CAN_FIFO_ID, &fifo_element, 2); if (err) goto out_fail; err = m_can_fifo_write(cdev, 0, M_CAN_FIFO_DATA, - cf->data, DIV_ROUND_UP(cf->len, 4)); + cf->data, len_padded); if (err) goto out_fail; @@ -1732,15 +1739,15 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev) fdflags |= TX_BUF_BRS; } - fifo_header.dlc = FIELD_PREP(TX_BUF_MM_MASK, putidx) | + fifo_element.dlc = FIELD_PREP(TX_BUF_MM_MASK, putidx) | FIELD_PREP(TX_BUF_DLC_MASK, can_fd_len2dlc(cf->len)) | fdflags | TX_BUF_EFC; - err = m_can_fifo_write(cdev, putidx, M_CAN_FIFO_ID, &fifo_header, 2); - if (err) - goto out_fail; - err = m_can_fifo_write(cdev, putidx, M_CAN_FIFO_DATA, - cf->data, DIV_ROUND_UP(cf->len, 4)); + memcpy_and_pad(fifo_element.data, CANFD_MAX_DLEN, &cf->data, + cf->len, 0); + + err = m_can_fifo_write(cdev, putidx, M_CAN_FIFO_ID, + &fifo_element, 2 + len_padded); if (err) goto out_fail; From patchwork Wed Feb 7 09:32:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Schneider-Pargmann X-Patchwork-Id: 197814 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2111453dyb; Wed, 7 Feb 2024 01:35:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IE9pPruiIZlS5JERIUL4GtRtAbzFK2F+BGg33lyBO/6kJuSshxSqbZkA2bJdh6tympcBeVr X-Received: by 2002:a05:620a:8008:b0:785:9281:1d06 with SMTP id ee8-20020a05620a800800b0078592811d06mr4415459qkb.33.1707298522160; Wed, 07 Feb 2024 01:35:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707298522; cv=pass; d=google.com; s=arc-20160816; b=Kz7mUwu5bL7v7L6EqNP3UofR6HlKh3LXuCOou8I9AbVWLwIAvfZ32xV1fupB9ry8WY I9+QzMEeNsene4eNtBAeYvcpkMoxXM8oRpP6IZN+oZwb7cRPsv3OqYbtNXVTEQVWncZZ oUW1vAPQba5c/RvNXjPkFoSxHRFCuNfdVwg9MpYsPXs/W98q8NzRd+E/l/4s9c4uwKhr Zohn18o/DpmpodYnAfSbCh3jvcy17Xojpj/t9h7q6VH64nRC1P2NRtrT4Xo1TLwJut/f Mi4+h+vkbG4ljbCdamHcYj15O/DKAlG+McbE6ySvNqszC292fg2felP6HAa6AI4esyvR PkTQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=2PJ1TfDECCRhl9e8NnkkRK2OxbkQuy+WkqaiUJY4FUE=; fh=Y9h26DWo0XZbWvXvnPgPIA5R/vh/dPhP4Op33w3NTQw=; b=SbQgw+XOoK9J/vThzjZZ08HibhT+9mRUOKuE7kDPFlTNbWvOpLT1tWnxGYBruEOMSO +r0VOpl208B6+PskyBY0B6rdnlviysaA8Ujx9WricZg3xKx1A91cXssxdnEOvqEQEDS0 zYo19kIY7THjeKdrry2qBrb9GoHeZlfSxVMCaDtLKMDrH1Bv87AgrcVuY6KOuyqEHhgB 5pr+KMUblJsqwtXvihhnhyH9gnsxlnrkd5iIyH0qxFPCbzOD++jN254sIbMI3xX6abRs sHIWmxKX1mn2sghYo02dkGcR4P7WM7G56aFyC/31M8/WGLO4MQob+yZh9KwI/IZKQdBF c02A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=jRxkLwph; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-56214-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56214-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCVZDTTgUa1zxl3nnmw2xkPEC9bfMuEjyruwW7lDNiraKuLdKZGEYwaX897n66o6Re4K4b8aM4xUsueVqmCvbV/vpbUrOg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 8-20020a05620a04c800b007859f20b51bsi314280qks.508.2024.02.07.01.35.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 01:35:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56214-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=jRxkLwph; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-56214-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56214-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id D59DA1C2172C for ; Wed, 7 Feb 2024 09:35:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E41392E633; Wed, 7 Feb 2024 09:32:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="jRxkLwph" Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A73E23775 for ; Wed, 7 Feb 2024 09:32:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707298363; cv=none; b=Fg95kezSrXeKH6ksiwN4d0DhA71Q5bxeTFozCQlXg0NApQ4GGzNe2Rz9CXwoZ547SvDYgqokEjICcO4a78Hf1tnZeSsdnjPwVIzXYC0ZFvfNsG2p0t+EdIokf9lVbPezFD8gEKMBswo1DN+zaAh/gm06qA/V8aTod4XjxK8x7o4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707298363; c=relaxed/simple; bh=Wxakw6fE1DMMi9exThr7nrt0kqXTsan4pdOnvja2w8I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EePHSnDzaqO1zkYijOPOsoVxAuBWBivLx5ZZW+Q1dMN+EGqWlEjet1vWRX9unZq5o/pzPLB0NZIOiL5NTShY0iQeuSwgzddLlU37fjFL0eld0btT/wUAnZls//ySj2fVv1lpmjVUF1wjNmZzDxEp23mv3eBonrdNTw9+UzvKQvM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=jRxkLwph; arc=none smtp.client-ip=209.85.208.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-560037b6975so341447a12.2 for ; Wed, 07 Feb 2024 01:32:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1707298359; x=1707903159; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2PJ1TfDECCRhl9e8NnkkRK2OxbkQuy+WkqaiUJY4FUE=; b=jRxkLwphErvBaHdBnj+XW4SC2jfRs/EHjrQzKH+yfEAwWGB84kHW+4HrG0vP6okS05 89LWwfmWn1L9B8vhMBslNI8EUSnBFP6okWS8tZNtDbogrYOuQ9mCgUoBWhsTxZg4miya WbUvkGsG7N0Bl5FPpYEMUkDxT7KmrHqDfLvn6JSnD0U2Z3TKErqyDRGwibr789ScfvIs hhXAnRaZvkEVjsuNCpsAg4wEUaDgs/Z56dCEDSWkXVXlWnZNAHU8hUkwInjeOpd7AcOc TktL8iB0oZ4dB0tgQViGELA39s6HqO3bQNNeEfvmudBH5qbZF03crJSyJaCFvmEub8Kc P1kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707298359; x=1707903159; 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=2PJ1TfDECCRhl9e8NnkkRK2OxbkQuy+WkqaiUJY4FUE=; b=LF+hCmyVZukVIFbQtcN0rAjI9W+jd6Lgjlgt54mDvuKtlSLh+O99CJl7nTA+v1b/pX NLx5B5vut+d+T0KAs4sxCoJk4DhbNpgsgKwzxNF+9DqcDHKJIbTssliNOzxnEeVFehrr 8vdPXRdJcmfm/kmmdMQWDLBqkZ1GbjjihZey47A0QdWfuiyQL0NhIdk4u1KD9saf5DO9 qs1UXcsvtfE6tkH+Je0zU8zDao8kmIZ7UgoKiEug+QVDZPkXvUCls5IIR2h7ks6yXYHQ Sr5U2jV7mvqKDZ3xAYOEWhmMilf7BnasNxqaNWLO0o05YrwJMS4Lug8K2JGWctqxMmN+ W/cw== X-Gm-Message-State: AOJu0YyHHw5KlvkDP9I8WOGIXKgiIESY2PTNnQyUcAUCb3XB974LWa8b g1YoxtJN6iW0jDw4AJhFj/T0SgvHKeA4UpHXWrf/GRJptxavlwkFXOSiW1FhotE= X-Received: by 2002:a17:907:b92:b0:a38:7fe2:bc71 with SMTP id ey18-20020a1709070b9200b00a387fe2bc71mr535864ejc.1.1707298359537; Wed, 07 Feb 2024 01:32:39 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCULePGS3+yA40vb5tJpegr7p3qAqnjVQYdvGFb9ypSVLWytfnb8WZ9lhZx35PamQBZj9GqNw+bjDHC33Hr7hEptq6sOQq2yMojFJpy4YH2KABIjwqs5IM8pwKNHgzpaMRD1weiVZkJPMNyQ9mS5gHmihTXRiwhB7Af6F0vUJ18j1QivOx/5wtgbhpKbChHXE+tvlCnxf/zQn0GaVnUbWYqrJoC2uGGk6LUmIAQqlqIG6CT403lkM0lCRSlu7JFKT9/DpG7ZCvIvc3XxaQHzgiJQtsSQnQsAThfpDReomgXbWzSIiGBAqiTSrlDMEgq3JKTSgHN4oGnPumAaZ9u6Z1TA/ztXOwBYVYmtosg9N/NTByXplVGsDALbR/d0WfQy1dL02WCbGRy4s2W/Pz+SmAKZqSA3tag6IRIDE1nubfSm8iwpqPjke0UjniBo Received: from blmsp.fritz.box ([2001:4091:a246:821e:6f3b:6b50:4762:8343]) by smtp.gmail.com with ESMTPSA id qo9-20020a170907874900b00a388e24f533sm122336ejc.148.2024.02.07.01.32.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 01:32:39 -0800 (PST) From: Markus Schneider-Pargmann To: Marc Kleine-Budde , Chandrasekar Ramakrishnan , Wolfgang Grandegger , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Tony Lindgren , Judith Mendez Cc: Vincent MAILHOL , Simon Horman , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Julien Panis , Markus Schneider-Pargmann Subject: [PATCH 04/14] can: m_can: Implement receive coalescing Date: Wed, 7 Feb 2024 10:32:10 +0100 Message-ID: <20240207093220.2681425-5-msp@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240207093220.2681425-1-msp@baylibre.com> References: <20240207093220.2681425-1-msp@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790232255170430392 X-GMAIL-MSGID: 1790232255170430392 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 --- drivers/net/can/m_can/m_can.c | 77 ++++++++++++++++++++++++++++++++--- drivers/net/can/m_can/m_can.h | 5 +++ 2 files changed, 76 insertions(+), 6 deletions(-) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index a01c9261331d..b76fcf5f3889 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -422,6 +422,25 @@ 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; + + if (!cdev->net->irq) + return; + + hrtimer_cancel(&cdev->hrtimer); + m_can_interrupt_enable(cdev, new_interrupts); +} + static inline void m_can_enable_all_interrupts(struct m_can_classdev *cdev) { if (!cdev->net->irq) { @@ -437,7 +456,9 @@ 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); + cdev->active_interrupts = 0x0; if (!cdev->net->irq) { dev_dbg(cdev->dev, "Stop hrtimer\n"); @@ -1091,15 +1112,42 @@ 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->net->irq) + return; + + if (cdev->rx_coalesce_usecs_irq > 0 && (ir & (IR_RF0N | IR_RF0W))) { + enable_timer = true; + new_interrupts &= ~IR_RF0N; + } else if (!hrtimer_active(&cdev->hrtimer)) { + new_interrupts |= IR_RF0N; + } + + m_can_interrupt_enable(cdev, new_interrupts); + if (enable_timer) { + hrtimer_start(&cdev->hrtimer, + 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; @@ -1114,13 +1162,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; } } @@ -1156,6 +1208,15 @@ static irqreturn_t m_can_isr(int irq, void *dev_id) return IRQ_HANDLED; } +static enum hrtimer_restart m_can_coalescing_timer(struct hrtimer *timer) +{ + struct m_can_classdev *cdev = container_of(timer, struct m_can_classdev, hrtimer); + + 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 */ @@ -1296,7 +1357,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); @@ -1340,6 +1401,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); @@ -1398,7 +1460,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); @@ -2082,6 +2144,9 @@ int m_can_class_register(struct m_can_classdev *cdev) hrtimer_init(&cdev->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_PINNED); cdev->hrtimer.function = &hrtimer_callback; + } else { + hrtimer_init(&cdev->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); + cdev->hrtimer.function = m_can_coalescing_timer; } ret = m_can_dev_setup(cdev); diff --git a/drivers/net/can/m_can/m_can.h b/drivers/net/can/m_can/m_can.h index 520e14277dff..b916206199f1 100644 --- a/drivers/net/can/m_can/m_can.h +++ b/drivers/net/can/m_can/m_can.h @@ -92,6 +92,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]; struct hrtimer hrtimer; From patchwork Wed Feb 7 09:32:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Schneider-Pargmann X-Patchwork-Id: 197823 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2115726dyb; Wed, 7 Feb 2024 01:44:22 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVrUDpB1wKB33Ep0Xq/AQNcQ8DfJP00XicFNi/k/u7cL7wApRxlz9ZN7WMZ2RCMUJlO7bnWWihv9VlJ9P8Z1Hzgwo7n6g== X-Google-Smtp-Source: AGHT+IE2MhkvR5Xwbe8yqtsveXtwyb8nvlBKEslKIgSzONpQ6G1zUxzaRZBHV7tMiG7/y8LqifMj X-Received: by 2002:a05:6a00:939c:b0:6d9:9613:cb9e with SMTP id ka28-20020a056a00939c00b006d99613cb9emr2164912pfb.29.1707299062271; Wed, 07 Feb 2024 01:44:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707299062; cv=pass; d=google.com; s=arc-20160816; b=AGVyn/p7OIlK7H11LgeNeKzdR/aCCQM+bUQcQoepk2+1xqTAFm1Uv63wuDRdC5yTMO loZ1dlfbsRuZR3HK8kI8lajkEu5sjHhSAU5nWU+TFwQhsdv9/6/UPWQ5WjFMr3jXLnRf a9uUtuUFjD/o20rxfZt+hB/mzuj2qn1iLVzgPC9iN/Fwp738YBTG1aof0S1V98yPrpqL PdASAzHn6mBRc/9AX2jjDdP3KK2gNtCDXic2VeP81p4jEvVFjuCQVriW8ckvmIj3+miw ab9GCGd0jelPSNGMoVCdlRUqB/3iMTN6ggH3b9Jv2UuikHs5VB3k013lPIfu+qH5X6jn WFwg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=EwhCN6py93M7HXamLiAm11RCgKXR81T+J+TrhTuD/Bc=; fh=aBeQqDb8i7ByT4aP6jd7GZxQRf3rNhWUqdffiPrSyEU=; b=SPuRo7VJvlNY1mbvf55Fi8MJnOJwymzr032wobsA0tuFhMoKOw7sWYFV4Y/ArN7Ltm VDyITMH3uOndQ6RsluMmAoZe0GYapuq+wbgvU13kjx6H+MUWJZNMaeG/lQp3L0Yl7tK1 ZnFpZK2sxuAOHOuUE0weF4h+SzorMoKTv4VEFfvfnl2mT4mPBoN/wM3PSLS84buHsK+o IBSeWcM4917CWLgqONqddGoAjK5X84/fDqtVPRCxlw0kvS7JoUzGLvNSRLml/k/I8rp5 6/fleOfH1+W2rxkqrix3qcoNxVxVPbpHKBtNGg01oafXmCiCkoMZ6O2bBKNmIlwX6gPX YiMQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=boEf44Zi; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-56215-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56215-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCUKWlgOuU7S7m7DKnEjjVL1RRkEMtc2Ysla1aKFF4JglSmICd8lWLI370EID0DnvjECI9N8c2RkfeMaQoKPnI2T22hArg== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id y17-20020a056a00191100b006dde04e1839si1264008pfi.63.2024.02.07.01.44.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 01:44:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56215-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=boEf44Zi; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-56215-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56215-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 57C30286291 for ; Wed, 7 Feb 2024 09:35:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1028A31A73; Wed, 7 Feb 2024 09:32:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="boEf44Zi" Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C07C2555B for ; Wed, 7 Feb 2024 09:32:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707298364; cv=none; b=mHjxHDpF+IhnHzOsiZenJLI6jlh5SeXdZkEYqRlxm+TjrZVPV6OmrQTvPLkfhoqmzU+YHwWotrAFXnprD0tRpFgAawDRRAZug8FETrLbm1TAjC7IshzTBRidSn4kPCnnOWGoF0W3RhL9V1kn+3ngTfi+dg+0qQSKMGCcAnIzrPE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707298364; c=relaxed/simple; bh=5VZ7dGu/fwlCWqyr+EDaPjpuqBWXjgLnu5FVMH00+7Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J/PAU75oexXRXpllH0d4+6sl3b/YsU2tNJ8/y2JUwbZ6Z4U+L2aINaNZaMLoYi6qtbfOvu/QBH0Yq++3cE9+gvuhVdrlL0Yv6AwJmUD6gvAs3TJPjf0Pl8fwwPIRcKgXrOPAqDij+mq/hAS4WmsQkujeao7p4JvJ6SJr7YFSN24= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=boEf44Zi; arc=none smtp.client-ip=209.85.218.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-a38291dbe65so41867066b.3 for ; Wed, 07 Feb 2024 01:32:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1707298360; x=1707903160; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EwhCN6py93M7HXamLiAm11RCgKXR81T+J+TrhTuD/Bc=; b=boEf44ZitufQVvYPTYXqizTK5N8Xv+lbh8I9jop+SiMr59mrza7WkxHaWZS5xmNDwu JNf3YN9ExaA5IKCFSrxRm03ffurJZz5UK+N/DjO9t66T8CDI493r6ffmEs0YVUtF9A6L f6k6QrsUabL0grXEhCNX5L2t+k7OXN+vp6eu0n4q34y6N9+Tf1IWdlr630kZ8JOoYwWy YuKGOLKWuxidY72W1aUxFRj63kCaREzLxBbs40kSpE6K0ld3s183BKiAKikO2pvTudij Sr3NNW+g3m7yN8fvqyRQL48HGzqKF9wKuOm8Py/oNcXi+JFVhLbY/JLRma8v3dy31hcD YsGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707298360; x=1707903160; 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=EwhCN6py93M7HXamLiAm11RCgKXR81T+J+TrhTuD/Bc=; b=LtOMyJu3BhKxKekpY+ploW7oWb01M9aUZlOJOKjjaboTqAwfy76mqPOgK0n/EET5QM qHGeEapOF2MnlUQ5NV8eeB+gY2Y+DqcTAYERf3Cm2KjHus3alYDj9jD3h2fIj+uEfD3X aiuLMQ3uj/tVupcWiUsE+y5JiBT6ZwMqLNp0jrCi2TjlPqht/eev8Iwy56BBDQdky0Ug p9rp7CDpPvDT8Ao6Lc+gSFXJ4UjyKA6zJ7tZ8jd22SsX3vxRnhVIJH4DVoS2RfDrmG2e CD0qMNQ577sXaH1OoByzOZiWY0r931rH6+fMPF+gGC1G9D7hvN+SASDkrAf2Mbg9YoQy JLcQ== X-Forwarded-Encrypted: i=1; AJvYcCXfSIhcSZ+PLIdEH3RGC358Nx/8gEAxJ78iW2N/7k+BH2qsAkdsCVOJjidhtmvjgRn7BIgUSUAjM0nv4bHUbP+Dh9v6QyillbJFLcW+ X-Gm-Message-State: AOJu0Ywu/rIoyBa37zbN92BKi+HE/aHl0UoFw8ty8eUGjoTPVwEN9yWO 0kiiMkXfONC2hqOT3Nbnb6qe1GkXmuhrvAY2/mqZI+RGqGR6bIQeEohLSj3aBoU= X-Received: by 2002:a17:907:7676:b0:a35:e22a:9d15 with SMTP id kk22-20020a170907767600b00a35e22a9d15mr3388506ejc.8.1707298360575; Wed, 07 Feb 2024 01:32:40 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUuh8Iv5sowmr1IHugcOdOW9Ou3IC606WKoRi4e3STMov1s940meOKOROCj3PPJ97UxTfIbtTvWMVvzVyZsS81zOJMPTdQaWvgJBMNrrW1Mv/32KCB7UL8Ha2xwHgWOcp4YHfbH6Rl/Lhyt+nh+OykHytm1fBllYXRH9rFJWhvIHolhtlDwXmZkvjH+OnaEiewMCXHJUnQHk+s8yoYsEBiiAW10f6mj2qmTWVD7XtYHyFvtZfdNY0bhNgGtB9YScHU8X+1QkBza4cdyfTQz8AnPtonAZ2tWGN2bbIiYEx2LQn7EJ3cloTYZ6vX6NPXrakEg/LESPT6mpR2sHv1K+b2ArVHnxGpGdHGoLfe2D6jKXPoCX52okWyxqm47nau6OgND5Jk94jdNCWdD0CthRi/hKMxRycGnEaUwi++6+KDlj1B0VnGZ0G18RrTm Received: from blmsp.fritz.box ([2001:4091:a246:821e:6f3b:6b50:4762:8343]) by smtp.gmail.com with ESMTPSA id qo9-20020a170907874900b00a388e24f533sm122336ejc.148.2024.02.07.01.32.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 01:32:40 -0800 (PST) From: Markus Schneider-Pargmann To: Marc Kleine-Budde , Chandrasekar Ramakrishnan , Wolfgang Grandegger , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Tony Lindgren , Judith Mendez Cc: Vincent MAILHOL , Simon Horman , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Julien Panis , Markus Schneider-Pargmann Subject: [PATCH 05/14] can: m_can: Implement transmit coalescing Date: Wed, 7 Feb 2024 10:32:11 +0100 Message-ID: <20240207093220.2681425-6-msp@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240207093220.2681425-1-msp@baylibre.com> References: <20240207093220.2681425-1-msp@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790232821498242422 X-GMAIL-MSGID: 1790232821498242422 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 --- drivers/net/can/m_can/m_can.c | 33 ++++++++++++++++++++------------- drivers/net/can/m_can/m_can.h | 4 ++++ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index b76fcf5f3889..9b3e8e09f3aa 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) */ @@ -432,7 +433,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; if (!cdev->net->irq) return; @@ -1115,24 +1116,29 @@ 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->net->irq) return; 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->hrtimer)) { - 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->hrtimer)) + new_interrupts |= IR_RF0N; + if (!enable_tx_timer && !hrtimer_active(&cdev->hrtimer)) + new_interrupts |= IR_TEFN; m_can_interrupt_enable(cdev, new_interrupts); - if (enable_timer) { - hrtimer_start(&cdev->hrtimer, - ns_to_ktime(cdev->rx_coalesce_usecs_irq * NSEC_PER_USEC), + if (enable_rx_timer | enable_tx_timer) + hrtimer_start(&cdev->hrtimer, cdev->irq_timer_wait, HRTIMER_MODE_REL); - } } static irqreturn_t m_can_isr(int irq, void *dev_id) @@ -1187,7 +1193,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; @@ -1355,9 +1361,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); @@ -1394,6 +1399,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 b916206199f1..1e461d305bce 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; + ktime_t irq_timer_wait; + struct m_can_ops *ops; int version; @@ -96,6 +98,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 Feb 7 09:32:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Schneider-Pargmann X-Patchwork-Id: 197822 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2115634dyb; Wed, 7 Feb 2024 01:44:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IGYzIq0BmMJNMjAMOetKESnjceuq7TEEpf4bmMNspTjBYS1hvj6f2NURXt7kvXE30WOACzY X-Received: by 2002:a05:6358:1914:b0:178:f482:6e56 with SMTP id w20-20020a056358191400b00178f4826e56mr2226677rwm.12.1707299048390; Wed, 07 Feb 2024 01:44:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707299048; cv=pass; d=google.com; s=arc-20160816; b=vwtADOw/Smv8MOyqJME9a4C/T+8nP0pCAR/k5vryUClaGcCQ3zPCtKu61wNNUk7n+q 0q638jlIiybmwbmmil41H5zcCY5wsJd13eRQMoBHurseetCnJbsSQXixWzXCvZS7meVC yh5oFPX6PgZS44TxlNQ2f0w9NWPWSH2/EVy9mwDCMIF0J9G1TQEfejGxzjnrXdGLFWtw YQgq6McTIZjyIrz0ZhhP7mfwiCVoE7jRZrv6ikAOp2WG3tzHnEo+1F39A336S/r0q6gr EdULe+6isuv/q1Mkp8WwkW+otyaVubD729QHXMuGS+9GFQxUFQa3dgzIp9dYCW0aKP7i F+Gw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ecHvachtVAv6sW84z8AsSsUI9BS/8T7kEDPcbDUA3lM=; fh=4TOGZSSF2YEs3q/nB7MfVwfOulhDz/x35VlRGNr/l4o=; b=RYRAH3AyiUWU+gYcOp5gE2GxGjW3U6ZGXecQtnfEHlwnb9RVTSTknK3ByojRpirYkS +HZeP2Zbi+2vH6TCE05ECzJ0GClF2jAYjvYPGf8cfIN4T8/Blqc8j3POvxL2PyRXUzHJ zq3D1Bt1JKfWkTt9TG4WThn2mmQ61V40vjXGaXcPsoMfqAvpxwNuL9uaLxQbLI58GWt3 7coAYrlSw1vQkZHySMiollHu0sDFh1NhlyOBOLt3J0dueXqLYF7HEeqqFzIttvRSZAH5 tci4qK4SiS1YtwSp7hbLvCd12IGYuOeRCwxq6uCPPtH4cyk2700PFm+QvoDe9JFXBZ8a mmcQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=sCHo6hr4; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-56216-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56216-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCVzJaVL0X4YenVSy8fad4QroGi+Sn8v3bPKS25I1Z/tQjcYYV1IPk+nXd71qIdSAouf7P8n4FFq2L6Dgperu7d7HdTEjg== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id y17-20020a056a00191100b006dde04e1839si1264008pfi.63.2024.02.07.01.44.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 01:44:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56216-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=sCHo6hr4; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-56216-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56216-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id D2A5928919C for ; Wed, 7 Feb 2024 09:35:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 851AB3BB5E; Wed, 7 Feb 2024 09:32:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="sCHo6hr4" Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 74C1525772 for ; Wed, 7 Feb 2024 09:32:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707298366; cv=none; b=i4DY8oO/TuYOSB4WoA3Lmnoq44zBWgmaUe6H7QxAMvT07QlryKTaoi4aMFnhn9h9qM10wWAA0pCdZ4MGs/DJNMBVSaOvadY9UKt9UMIid4OKkB+hfeIvikcxYVQGExE1qxZccY54BEf+ojio3UOqBqY6T/7qyT2Ymn+RcigId8M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707298366; c=relaxed/simple; bh=JRTeU/WQ3xKHyIzAInVb+YB994geyTmL8GEhny2GOLo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZKoO36VgK5t/GMyTQVLQevyaucUaCc9FUELOi0KZpVhKXMmMnKLLN/Y+I+HWsflWLzrYX8Nzfu7k91wUQ7BhQl4LI70JvqFLO0l4DQgmH8BOcClGzJSiMw6GO8gA6br9PmZFmp11LyjCXukK4OetiF7L0cAIM/7aABS5K+x7/a0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=sCHo6hr4; arc=none smtp.client-ip=209.85.167.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-511234430a4so759546e87.3 for ; Wed, 07 Feb 2024 01:32:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1707298362; x=1707903162; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ecHvachtVAv6sW84z8AsSsUI9BS/8T7kEDPcbDUA3lM=; b=sCHo6hr4gpfyvdu6NAPW/86TDVtWjC3OvdBvwHZ5gIQZ40omJLYxlP76kc4hRgT2BS cBNBKaQdCsNcicm69t1PgOzNB92ax1OJMtowTRKH1TwCxLQ7Qa+TI//X4t3tOPiddj1D 72EWN8VtdjiDFnmPSTrm55XRezSGInSg9EdnkQl70/olZllxEOdDO+CMgnb69ZQdJK0u SqvwfgRsDqrv7l24tWDjiwrVjK7FW9+XQrzZSxmRSx3Ja2JbtiDKUzmU75Yf4/29gMO5 KpRzNzWxDeOikR7TyM9lm2XE3L0nIB6oYwKgmAUc2W2+xpzU1wyf7hsnssbHDoAk+Kfe F4Tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707298362; x=1707903162; 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=ecHvachtVAv6sW84z8AsSsUI9BS/8T7kEDPcbDUA3lM=; b=jh9aRKM+uI4ikMPz5SpYxeoHCIWhUhQdJk/Hxqn0VJjbbwNrDWathQLQwC6IgB6XM3 jzkTnD3GRGRYtezmEMJmXGVRlnmFUTGCYsORP7PYuDclr/spg+RojWFUNurWtsJDKUbY pByZAe6rgldWy1NlvjRbbrWvXp5gOkv0oSe8oCuW5Yi/rPWnj5S0af7Uln9s9XgSzv0R jDcc3wIDHPAnzptHb/V4xCTVDYV58NlevOKq1vyaAWcNqCGio4d7FjHHg5B5stC/qPzA lltipdPRt7FzGks88rDt39Aw/CiRAc2byPfE5YGMtwy0z7C8RZLZOldhcpeW0M8yeaY3 g6VA== X-Gm-Message-State: AOJu0Yyiamoq5knY9d2F8+ebrUunCs099kTxr/7A02OKvJBGy7YS5vni IZ8sC5tcIGXVrgI+z6MIyGl/E0rcD6JKWipRSTOcW6pu+17GPKhgdQyRch7VGpY= X-Received: by 2002:a2e:a273:0:b0:2d0:9322:8d0f with SMTP id k19-20020a2ea273000000b002d093228d0fmr2829069ljm.26.1707298362563; Wed, 07 Feb 2024 01:32:42 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXe/gF7sBIbzhAK8HMgggca/Dyc7ERgBXVfAucw/KnZW92CbTCvyUBIm/Rpa0lEveRXoBszuehhJqGLz31rjS4qu/qhN6XpUlgw/pNE8QfPeG7eA+lwHAA1wWmS3A9f8ug8HSQ6DKF2EJ0jcjj/xBTAUEkWwCMRAmLow4eElvKkwUnztU0ialSBVhTsfK71umwzASMR33wTiZgN/ClKbPskxxVuzdbRzWA19pX6X0wT9fmxsLcjaN9S/fZzxUB6SdCpsugyRZFlnaWqJgDildZXwc5XbcllM4KlPqVDi9WhRBiMn0ohFneW4AWY8hG0etb5GQ0KpIrYQ9oLwN5OfvLF3T2WnDQSHdy92v1uyb8LfpXu8EslEIe+78s/WNclItuAS/SYkIpjgGzK0w4rA5YzuwIV4ICx+bPvj2RLTg8myyuDJgYPAJRcP17U Received: from blmsp.fritz.box ([2001:4091:a246:821e:6f3b:6b50:4762:8343]) by smtp.gmail.com with ESMTPSA id qo9-20020a170907874900b00a388e24f533sm122336ejc.148.2024.02.07.01.32.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 01:32:41 -0800 (PST) From: Markus Schneider-Pargmann To: Marc Kleine-Budde , Chandrasekar Ramakrishnan , Wolfgang Grandegger , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Tony Lindgren , Judith Mendez Cc: Vincent MAILHOL , Simon Horman , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Julien Panis , Markus Schneider-Pargmann Subject: [PATCH 06/14] can: m_can: Add rx coalescing ethtool support Date: Wed, 7 Feb 2024 10:32:12 +0100 Message-ID: <20240207093220.2681425-7-msp@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240207093220.2681425-1-msp@baylibre.com> References: <20240207093220.2681425-1-msp@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790232806541132372 X-GMAIL-MSGID: 1790232806541132372 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. Polling is excluded from irq coalescing support. Signed-off-by: Markus Schneider-Pargmann --- drivers/net/can/m_can/m_can.c | 55 ++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index 9b3e8e09f3aa..6dad1f569f82 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -1977,7 +1977,57 @@ 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 const struct ethtool_ops m_can_ethtool_ops_polling = { .get_ts_info = ethtool_op_get_ts_info, }; @@ -1985,7 +2035,10 @@ static int register_m_can_dev(struct net_device *dev) { dev->flags |= IFF_ECHO; /* we support local echo */ dev->netdev_ops = &m_can_netdev_ops; - dev->ethtool_ops = &m_can_ethtool_ops; + if (dev->irq) + dev->ethtool_ops = &m_can_ethtool_ops; + else + dev->ethtool_ops = &m_can_ethtool_ops_polling; return register_candev(dev); } From patchwork Wed Feb 7 09:32:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Schneider-Pargmann X-Patchwork-Id: 197829 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2118555dyb; Wed, 7 Feb 2024 01:52:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IG84ufHzTCBXcNao0orvw97OCwjqf3x1OLmbBu6DhR5wUKny6idEN3hvwqjxGJqUKGma6qn X-Received: by 2002:a17:906:af85:b0:a38:22d:7cce with SMTP id mj5-20020a170906af8500b00a38022d7ccemr5927964ejb.22.1707299544640; Wed, 07 Feb 2024 01:52:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707299544; cv=pass; d=google.com; s=arc-20160816; b=HTVSYbcj6HwAz7FY+BSNg0YIfwY5Zg1c1dRYMC3njrRfp4HRYRjQX98qI2yE7thnd8 MwR0dwm/hwcHVDxfD3avwrVN+56toC9CgYzE9Bqz2Iowl8fWHJQw/wZAyWEc9EyZKEj9 R2o2X/Fqvi2eGsURVypQvrfGvuGBL6Drt2ORn4mC+LtfaVShlGliAjUS+yOWNIjdwK9/ oS4vWdkVEPlXth5zeJf6p0bpdulQYNB10OeSemamrQGkjZL62VPpnXPi1na4Tdu1F7Kz h3pMHEypvcxTWDJWPY4AOxtousUL8Hhl9EoONYgMatdn+Lhek0ySFLQwknZ1ir23lWhI nJBA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Z6gvVLaAJJ5SpKKyjtFK2dGPARZlV56P68Im7wENaso=; fh=MEr78bVjZ6a+SIOlgQ/7uWBteNP+RzW57aWkYSyD1qU=; b=oNI2Kph7pTmfg6RMx5R8O0vW/fAlbztu15xnMm/ZqTB5UeXTHnFmUiAIPnFMFcwJmZ C2ZxBOfrOt56mRsiO5jqRoDQZTwXDd3CYNwV2jm84L4iOSu/0NDwh7WtnB9UBCrXrmZD FMBbooeQkqQ0MvnLbeXLJSDVVYxrJwSsiXQ6fE+Vvar0xvtMxP8rMMpULv6S6+RtRBRY Sn1qdtmayyXizo8Sjz+m1OTOtrgbtUQxhkBbVpNGfU+wBpocc0v43vNGGPb6YWlTtN8k DZV47UDQkR4Uc0n963lew2wGv6XbqFg4w7BTpD9/wVfrTw1c922DCJG6D2lcgVAnRr3v gd6g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=ElNcL92z; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-56217-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56217-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCVLzis+LiqEoZyjslvTiCc3jfa0jgCvVoy4tZw/wZ68y/k2i5hL65yF8h/dGQYyPjRe3KaCQqLtMYywuuSCE7KYdQLCtw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id lf6-20020a170907174600b00a3737c479ebsi678867ejc.459.2024.02.07.01.52.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 01:52:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56217-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=ElNcL92z; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-56217-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56217-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 55CD51F23349 for ; Wed, 7 Feb 2024 09:36:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AA4B63C48C; Wed, 7 Feb 2024 09:32:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="ElNcL92z" Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6589128DCA for ; Wed, 7 Feb 2024 09:32:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707298367; cv=none; b=hr2f4/kee3+zKyEfTLSBN+D7195CYY8q33FsxCJXNlFfKlM5RcuAerl9OX3SzrBUvuOf8r9aJr39hVuQUdRQY21au8qKPbfc5vvPmdEy/30bw1G1TPAROmOTyYBJcN8BvDSxIeJh8chDSkrVqLNPjffqin9koCkbg1opRml0k4o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707298367; c=relaxed/simple; bh=seS2mYXKgOsaStLXlO6Hn49jlysXxgYFKeFnkw5vJfY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QtKjLcE1xELcGMGXZloM3ydn6BmCwzmt4wDLMv8RH9nRXDtmaNKtpeRLgFrb2IjBL+f6HC/WlUCHUQo43FNbtxSPzYZclsDwSFO0sDDWZ5cKrJ/k/Ta0yzfG7opMIgRILj9TEJIhqukztg3H0wI8bfx0cGxyvwk6KNbtSmjVROg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=ElNcL92z; arc=none smtp.client-ip=209.85.218.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-a3864258438so85013166b.0 for ; Wed, 07 Feb 2024 01:32:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1707298363; x=1707903163; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Z6gvVLaAJJ5SpKKyjtFK2dGPARZlV56P68Im7wENaso=; b=ElNcL92zZytcCLqFP1+TVlCj8Yovx4+m24BMXj1d58bgaxq0Qc0OezZ045zKoSb07g OnvXQoL1ENdLa4OVtGc2bwtpqYqnJ6mqDWAaJimF/e9xvmTmbFhDbC+SDCcaHX7vClT2 V2bbHR8XU0M4faxIbli7xslXLz9dU2WbdhjzUZxb/mgrEc138v1x8PS1AnUoOJW3z6TV hbLruAJ7Fpw0yeEhWe0R/KC9QCCSvu/7Qu6hl2eJlgeEcN92JHYaazweJfp7/3cWlzfQ 3qGTb7TOKYLKyVHKwAZBgx0UJ9xwnlKm3yy1M1zShowbQfCl88MuFnvBlzKxHMhrUhCS hSUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707298363; x=1707903163; 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=Z6gvVLaAJJ5SpKKyjtFK2dGPARZlV56P68Im7wENaso=; b=SKT9cX9h0WIKmaITKgqlO7jmNGFBwsw258HwewfifX+5l7T9m7YjdoxdxY9C5gv+4e qU3VRKRzyInyALLRGohWYVehOG+77rNqA2lozxQTVf/NLPRq9+j8XzBfIcEfm16h5zEu w5NHV1/VK3l/ZN4BATVtrWuP8GVVaieiG4EwEBtAo1wWhRKiqanKbTbBmRTwx3YU6u9p 6A9nftVREvGTPFCbiXfOppiaTgl7YZ+y7gVhHbG6w38PtfGBBk4sLLlctteTxpGvxngI IKbok/zYdTuOy8CXzIYdTZu1v8FHV2vugyXkT8GSD0LQxU+aY0c0kS4qYGstGRon+H86 Y6hg== X-Gm-Message-State: AOJu0YzkAWLYek82R00yuYQR0m8tzqsovvydixzGimP0XtrNprw/3shJ lQX3YwKr9Q5VBJjWHfPaQQ+uxrVV90NWXuI59Sv+KeZ1UXlDDZYYUTgXoePzktE= X-Received: by 2002:a17:906:44:b0:a38:3e90:e1ed with SMTP id 4-20020a170906004400b00a383e90e1edmr3509955ejg.7.1707298363662; Wed, 07 Feb 2024 01:32:43 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCU7xANWpOEcVoy0cWd1FA3d7ebTG317SnEhRB7lk6E7hkiAm5/6uwcW/39kazc+PLqt/PycVuIndwdXlbvHklivYovFU0XLCRZolNboHaIrA+inwYWFahk3rhFF814b/f/FfsQcecFwhKMQqNpTvs0ElMJRwYC18K3nh+0NwRJOLby27hHiIHAwIKn3jTppClv9Kt8buQhwqyu+N7NhRIjKk46jsnlv5eDDrkh5H3a7F6oKNqpcSzUPwu3Zt6qx28AKc1kW7nd8tdwL0hBxPNbY/5TQOvvQqf5tBjHDTwrr7U+OoXS/Up3rNS2evgdY/iSLZtAIM6NYSg92Yr13AZvtyQ4f+t2JgzH6gIe33oitODQbP1vqNvONyuk9pI8N/8H51lk156oIVFqEaK9vdivsuKZWL02jVWzYuG6qWUCFC5V/tkQH2k5FCDBR Received: from blmsp.fritz.box ([2001:4091:a246:821e:6f3b:6b50:4762:8343]) by smtp.gmail.com with ESMTPSA id qo9-20020a170907874900b00a388e24f533sm122336ejc.148.2024.02.07.01.32.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 01:32:43 -0800 (PST) From: Markus Schneider-Pargmann To: Marc Kleine-Budde , Chandrasekar Ramakrishnan , Wolfgang Grandegger , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Tony Lindgren , Judith Mendez Cc: Vincent MAILHOL , Simon Horman , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Julien Panis , Markus Schneider-Pargmann Subject: [PATCH 07/14] can: m_can: Add tx coalescing ethtool support Date: Wed, 7 Feb 2024 10:32:13 +0100 Message-ID: <20240207093220.2681425-8-msp@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240207093220.2681425-1-msp@baylibre.com> References: <20240207093220.2681425-1-msp@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790233327743628182 X-GMAIL-MSGID: 1790233327743628182 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. Polling is excluded from TX irq coalescing. Signed-off-by: Markus Schneider-Pargmann --- 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 6dad1f569f82..b31df3e3ceeb 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -1986,6 +1986,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; } @@ -2012,16 +2014,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 Feb 7 09:32:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Schneider-Pargmann X-Patchwork-Id: 197825 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2115857dyb; Wed, 7 Feb 2024 01:44:47 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWeO56+yPeXhHcUk7Ebx3LdsuAgsAVB/QMzXzbkRu8i/6BoEOmYIM/pegWEVGKroxbI1qMo2yDUvYxmUKZ9UC0qf5bd5g== X-Google-Smtp-Source: AGHT+IHhNxOxRfAZJzHgV5WxAjmhmaZjfRNVJ2lSKjAaqaOcwmEJbXx33IZlFluGBQKpqZgu/Zap X-Received: by 2002:a17:902:e802:b0:1d9:3edf:1e2 with SMTP id u2-20020a170902e80200b001d93edf01e2mr7302026plg.3.1707299087739; Wed, 07 Feb 2024 01:44:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707299087; cv=pass; d=google.com; s=arc-20160816; b=U5EvegrbBSMd/4CfRtj0FPOxqJb4FPfFI7wvZvI/joy8Hxo8enFb3ynv//dTKtyUYv HSZL/z9O20B1kJCUuGur964mfmDICWsjGbpJsK8sOKD305tSkUmOwsQndQTOPiFz7YJs KbeqhAYCtD5xptYPSlkCaaXHXWpOAvsc6ck87DcN9HKc7egI1A04S+x23Kv8Sukim8vN jWVO3aLqtQln2lrFx2v5Dg+/60DVLhgOgUqiXD/rBck+TDUpD+wb9+2DUd3y8Fm6Uyux vrzRNz4mhJY+smPcv6G7GzT8P91Fwe8qXguMEOj+kC276S9xcwh/MDh+3xS4vUauBnvI a32w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=yUP/ICSTgUrZXFT7bioEQjzIDbumAO5zjpvQT5yRgD4=; fh=uym1eUrpil8LTMw70FyylECWDdfTHStYuMq4rdVrNZ4=; b=oRpYxjz+pxcBxwKbqVd7eJD4vfww2A/qYk5lqU+SzjloD+VT4OmuGspqPpDA0verJZ cwV5TXQnbenDX4qXxzF3UQDZ9Wl22Ki9mplJAlm1TN2IJ443nKzhFfDM41qLgSpnDi4V W2U8sHsaj24OyZQpDhQYSAmd+OWFxDKpkYDWKxzAQ5mkDYG3bU0nlLhHpNHQGHprB6HT bvhWfYDWrzC8e8007TQwCp5eCTZcMA9b0geW+lLmIxy55jegZCB7JGulodPYiUEUz/vv lnPJv1M9Fpc62T6X2NKzYftDevT5qBd4GeJfYu88KrGTETkXbIV2XbWzGD6CpOI64wEK dhuA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=GLQ8EsSm; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-56218-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56218-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCUXWJ1FXTWxz9lKqlCt9MRMjRtQ2rFHXzVVZCOdT2b4ALtWvZJYu3SZ18y+lQUVt1XEmWmVxZckdhZrbUPR8uaJMcv+dw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 80-20020a630153000000b005d8bc1d9b5esi1079826pgb.313.2024.02.07.01.44.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 01:44:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56218-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=GLQ8EsSm; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-56218-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56218-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id A8FDE289C3C for ; Wed, 7 Feb 2024 09:36:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 734BE3D3AC; Wed, 7 Feb 2024 09:32:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="GLQ8EsSm" Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 685BF2C6B0 for ; Wed, 7 Feb 2024 09:32:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707298368; cv=none; b=TgdpqYqwtV1E05NaXayIMtENeRP8+RsFAz50zmwHeIO4fXii7AzqS6i3zI17yYqk4XKiXhEOZmluX7XUR9dvV62MJQsshxJT0SS/JcdhEsRaNkXBHmGRwlrIZLxuImy5GbX6os7C/QmrKu/6vEcJr7Ll12ytICpQh+o58OfDF/o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707298368; c=relaxed/simple; bh=3bOx6w0LTuN8pcOfYHhxFGJ5/H17MO4GBppv0GaUmBI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sY5lv+18Yp6trSryaD/W7ivVi7RHwNCicfVn1lMjKKpu1SnAyeFPjhNCAaVy+LYnbV4qbMtA5fwjQWmyLUicaE82ZIEEuHVfTLTIxogq59EJn0yxAAqpHCkuIlqvwlXOiQ1f3LfAFuRTwQpIyDsVRs1oYB/9Qt8arMgI106j4vA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=GLQ8EsSm; arc=none smtp.client-ip=209.85.218.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a3566c0309fso49215966b.1 for ; Wed, 07 Feb 2024 01:32:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1707298364; x=1707903164; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yUP/ICSTgUrZXFT7bioEQjzIDbumAO5zjpvQT5yRgD4=; b=GLQ8EsSmvQ/wXg0UiyD9zmWuiUYlHG4GHWFuQF/JhV7s/04ACU2A168Gf8t2GAM7JT UclpxqvN9GK1cHyFK0yirJxqYr/30e8bXM0h/eUaltW2vkRSVibTC58XimLuK/WBtP0z r8vUAAI0J5t2dsRy9vBwBFecGH5rERL7yQFLUZsBxMCzi57YZ8Gb8uUuHjMyMFJmOLRH WBiEUsEEB+fjlfie64jfyd9D2SiPRvZIpop09MEq7TDjhUsiFWnMcUPYmROOP4cJJQat OieqKYgPTEdPL8DJBycgMcXmb9fHPIhDdvk0Ylf0gq11iCKvYdw7g2zwlrWtIL7SN6Cp zG1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707298364; x=1707903164; 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=yUP/ICSTgUrZXFT7bioEQjzIDbumAO5zjpvQT5yRgD4=; b=M7gkwEt4WP+DVNTYoG3ibEF8wSK+ODZjW5RH7Mv0PtXXz6veNkHYs+i/UquvGbeDxZ txyHQ/BakJ6juGjN3fiRdodEqPUG4+AthLgpw8Wn0GaMr8pZHxSb+5qOvoWCK2p/SZbx uV0MQIPjP5SVSeEJVD768S9r4pRjbNiNs6Zmz6iGcnjjQ//Mpl66c/ahV2K+Z2h7sL5j 7A9RtcTLRThIdfmfeq+JzkHfNz11mK4emX4KdlQHlYHJRpv8DNuKjdOCWabJbRolGnNy 2PUkD/7/K5Il47FsgFJfI8haJQBdgjFF4m0M9hWaESR9L3wzCapR2kv7GJSRn+zmsJMC v96g== X-Forwarded-Encrypted: i=1; AJvYcCUbA22NAH5Kl8rLwaRg0D1dArx93Xxc/rTeCa7Rix/pPoN2NHs3D++/vlf3hrRIYNGyCftvB3Ff5EtD8/vJSg67iMLmm1zGrFKm+RVs X-Gm-Message-State: AOJu0Yz3fWnt2nNznPiTGiUH4DgoZqVTVf+be7LzmXCxhp7mceuYiQQ0 92JSCps1et8KR5huvDEmZ9PljhZy2hkX7z5yerOjADcw3Ralgk5JC4LRzOlP5Jk4tDBd3In4AxN 8 X-Received: by 2002:a17:906:7d83:b0:a37:a66b:b361 with SMTP id v3-20020a1709067d8300b00a37a66bb361mr3524242ejo.21.1707298364738; Wed, 07 Feb 2024 01:32:44 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUD0fnBBAqOWKl54sKKfHDzSLNwOsuRXN4OB4P5dEQHf2+fkGuifRlm/VbppuuKAWM9Vt8pq1b/xiw+HQBKCk7yaC5en261Y/cGMsWD/PnGQae1i7il6L/81aeE44FYoTZxk2cVNpaKsxqQkRzxEaEYaBZMYAnXVfJaP9bMRabavuOiIoEy1vMMTP4daU3OGXyu9HNEqgMyrDRtN86cCKi1CR56tTCZUqHEk6sqV6UUrYuALKKnvq5HXg89NpwkSublj2cLEIVHfOk5upTf9WPhJ/S1Olt0LIJFMZDgh/srQYwyAjlI42L+OWcEk6ic4nsLoi/D/QX0pedbGjy8was/yc4gXI46JpdF/kiCLSRILLAOMtqM3nJvAsHRHars5ZsWJ6PVtw/WcDDYxNACyqmqaBnbFJy57qUbNl2N+x67sX/HBfFnhNeUh4Pd10NT6SqakjaY9PPhAHDBRMbQhVi7Qg/ilO90 Received: from blmsp.fritz.box ([2001:4091:a246:821e:6f3b:6b50:4762:8343]) by smtp.gmail.com with ESMTPSA id qo9-20020a170907874900b00a388e24f533sm122336ejc.148.2024.02.07.01.32.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 01:32:44 -0800 (PST) From: Markus Schneider-Pargmann To: Marc Kleine-Budde , Chandrasekar Ramakrishnan , Wolfgang Grandegger , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Tony Lindgren , Judith Mendez Cc: Vincent MAILHOL , Simon Horman , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Julien Panis , Markus Schneider-Pargmann , Simon Horman Subject: [PATCH 08/14] can: m_can: Use u32 for putidx Date: Wed, 7 Feb 2024 10:32:14 +0100 Message-ID: <20240207093220.2681425-9-msp@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240207093220.2681425-1-msp@baylibre.com> References: <20240207093220.2681425-1-msp@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790232848120125653 X-GMAIL-MSGID: 1790232848120125653 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 Reviewed-by: Simon Horman --- 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 b31df3e3ceeb..1b62613f195c 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -486,7 +486,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) @@ -1695,12 +1695,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); @@ -1719,7 +1719,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 Feb 7 09:32:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Schneider-Pargmann X-Patchwork-Id: 197826 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2115901dyb; Wed, 7 Feb 2024 01:44:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IG2sQP1pfgugh85qBTNAx4rkaBJ5nQOnp4eYJn6gbayhUBrT6F0Bz9B9HLVx6RUXkDzbs6u X-Received: by 2002:a25:b291:0:b0:dc6:bde1:3e33 with SMTP id k17-20020a25b291000000b00dc6bde13e33mr4231679ybj.33.1707299093521; Wed, 07 Feb 2024 01:44:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707299093; cv=pass; d=google.com; s=arc-20160816; b=EDVBCWGuMRR/QZp/pi1J4few+dE0gTpkE9mq/gh7ZpcbcEL3nGybX7uo0fYAAKDpEc LVhSsCI0KMcwUJwRMZYj5PYQ1AWGLrtsZ2HehG0/s797crmnSgbUKdUznkliDtlZGVd+ LB2GTQ69r5d0eEYnj93HuZT8GuvXt2/BlUwrgsAno25Sgq+JYx6gZRv5yGNWjaTPzqQj cc6X3257VpofVUsd/jyFPWVP1+NYXDVQ1DKmS7K0QeI749X2xMbZUCaCUy6vUJ+v4EH+ x6e0JYlku3im9K331qD4LOzkn5vqpjht+mJMPGmtSrFHKFObaYC0KnTNzIzR18jUXJ4g XRDQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=8wnVAPfyJw/OWLzF0KC9/8j6EFFYXdSKnHtbnBIj0M4=; fh=/CqUYW5XR31BVSe0n6pWwnjlom5xfRsgXlY9HycBFDg=; b=WWMn/oNteXr5DmMyPnjAF35QH5PxfGPHRlAUMgZcklDrIDQFVqVU07wI7XXDT2LVvk pceSThbXdZEkWiRtqHFl1HMgPoH2dBOFZm21R/poW7U4Sp1X9z5ryh7ns1NTS7/TqqBl Y8td9+HSOLa3yw/jGrSF3FKQo2eeYIjc02QeLY9XVwXKHxQKwjdRd4WNmAFK6UXP/pLu 3ssG/ZamOi2uDXHPJilLPo64/Gu8ZEXzfjTVl//OXzBUBoSiaFCqcoydcXsiDMDMG6ss 2PR2MaL4Ai55jnt7RoqFg2td3jaANQ/fqbMRN8FT3ikgcTT7yMETL1/2vv+KfVyKrPU/ n9dg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=yr52eb1m; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-56219-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56219-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCUg2VDJNZPZodynnCZx+fvpZYW6kMC9ZY5BMtFDDsmY6O2/WIpjpNt4u/G/WhsvB84hJD/cn9fYODDraDsUpBDNq4cfnQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id q21-20020a637515000000b005ce087e004dsi1135724pgc.799.2024.02.07.01.44.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 01:44:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56219-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=yr52eb1m; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-56219-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56219-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id AE3C128A501 for ; Wed, 7 Feb 2024 09:37:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4757A3FE44; Wed, 7 Feb 2024 09:32:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="yr52eb1m" Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C40D2DF92 for ; Wed, 7 Feb 2024 09:32:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707298370; cv=none; b=e0Jr6ok6PwnLLQOF+ecdtsyk/1g74yQqI++3kvbDQqNi48oCumWHKymp0nz8UXp+gr+6Q68kDwL9CPvL0TJildNhep98iw8VLPLSIO3ZGx8wKTTKbKoaw7QjdXomrYsitcvEu31Zs5Zf+6t6Yz/dteK5gC+rZ5FsYFLFebsg+jg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707298370; c=relaxed/simple; bh=aKBUlv2DFPCwVWl5pJMCuyW+k9TrqdFHUb5U5vXcunk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AI9mNb1yoheasA1TNnN0Nfj2m5M86Tj1iJ4NU33kYj8LNP+yCvB7/3BEoi64WD1yVLKoqztioqk2Q3fnU3I+otR92QVhsqEWdFpdu26FoDYs2xWzG7CAmfOOVO/5gq5Eqa9wCEIaG6Su9/V7nJ0vrwl5Imx0qfKCb7xjUPvEEYg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=yr52eb1m; arc=none smtp.client-ip=209.85.218.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-a30e445602cso313746266b.0 for ; Wed, 07 Feb 2024 01:32:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1707298366; x=1707903166; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8wnVAPfyJw/OWLzF0KC9/8j6EFFYXdSKnHtbnBIj0M4=; b=yr52eb1mW125jCltaBGmDjWa/s//g6OqeZgJm5+0jg99pU05Hq3lxheaasPtXu2Fmv Kxsv/KykeFvUskDsHI0d6U8F7W9TtzLdMiN45+7V4v8YOP1lVwIojtt0+m67IYtKOfId a1coJOe+p5R3ie1HGHqZfN9f+EfQF84wZLQdd5uL1w0KG4EYHKO84kMTMrxdpmtZ+Ek9 miQ5qO4jupNeKC+Hj/l6SfamsDnOIVl6/je1uKNqNx4tzoFJvve8b2qlF9l62+JEMwyI dXRj5hzv5WxM0p84joxOE5Vlnt9y1M3v+87qni+xZJ/FogbV13aqIWsqFQ0LM5LYQvHt kYEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707298366; x=1707903166; 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=8wnVAPfyJw/OWLzF0KC9/8j6EFFYXdSKnHtbnBIj0M4=; b=kOYH2kjn94j1Q93Dmp/IsVNaqZXwHgTVFhEiUtPIH03MXJtOIorukz1sOQh01ea46n nMJ6f2rPTN1VCbs4iV35gr2U1KUiS8J/g385BGpcTaZYExlRZZfSy3kjVX6DP4t0f37U z2nCShyK2Kf7GfGADk3IBaOJnMTcemM5IpikS/eFlqjFSxN4EWTh4GcCVc0uP776Klim HvTHcEAMj5ZqReVgjDPFoGGSpqhxfVb1ysCRfgGVXcS9OhZ2CuaUHbrFSker4ucwHMyz Jsqy23NN9O2giN/rnTjTP8RS00jsY16c8vqG9hluVLxTkgOIo9ag1B8j2Mv7cDOfPQBO BnIg== X-Gm-Message-State: AOJu0YzwhH6HgSFRGE0JfB+6BtIfYeGC540uyln9dkt4HbQunyemDK7I iAuWeZ+lnYMNkmRY+xTY/E2J6/b387NC0XX8EYxw6LjCnpa5U7bg8PiikbifKPI= X-Received: by 2002:a17:906:4a55:b0:a29:b31d:1dc6 with SMTP id a21-20020a1709064a5500b00a29b31d1dc6mr6433899ejv.6.1707298365844; Wed, 07 Feb 2024 01:32:45 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWyB+sEDgwVroEEABf/EC8CBwKYStKI1pDrhDVBp+wYYsW4z0rBIht3GoJpe1ZZTp/K+ai0i4RUed/8k/inlZRsbRhPDmbz3gJziXnSv0jqDCMReuRfCEczWtF+zhjLDTBgI+LIOzdbOxRLYhEMIsUXEWp7MvDvFTF2u6ufwunQn0pxxCxKyL5WPNGtEscZwe6wpspeFo3MZWDn4n5YHlOM7GvEQ5UXs+NTmmCSTtJT7A52yYwhr+YVNjBl5snpno56dRb02mTzj31OO5UlCbJj0F3jw9Vy8f8fQ2A/EI2lxOoMmC4HvIInNfUKzKh1ZQ0N1v+CTkaOYR9X4RanHuIwNuMGYodxcc9CTwMXobhGL9VPODR8Ge/RTdzyM4JPch8qARgg81F9K18vp0GqQxwuATlYxYqTtXSlYcAtjs1Yop6sInKLSBUtX88hx/NfVYUImd2obnrdNkRmn34Rt8eGf4FUa2oK Received: from blmsp.fritz.box ([2001:4091:a246:821e:6f3b:6b50:4762:8343]) by smtp.gmail.com with ESMTPSA id qo9-20020a170907874900b00a388e24f533sm122336ejc.148.2024.02.07.01.32.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 01:32:45 -0800 (PST) From: Markus Schneider-Pargmann To: Marc Kleine-Budde , Chandrasekar Ramakrishnan , Wolfgang Grandegger , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Tony Lindgren , Judith Mendez Cc: Vincent MAILHOL , Simon Horman , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Julien Panis , Markus Schneider-Pargmann , Simon Horman Subject: [PATCH 09/14] can: m_can: Cache tx putidx Date: Wed, 7 Feb 2024 10:32:15 +0100 Message-ID: <20240207093220.2681425-10-msp@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240207093220.2681425-1-msp@baylibre.com> References: <20240207093220.2681425-1-msp@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790232853973762651 X-GMAIL-MSGID: 1790232853973762651 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 1b62613f195c..a8e7b910ef81 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -1504,6 +1504,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; } @@ -1793,7 +1797,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, @@ -1827,6 +1831,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 1e461d305bce..0de42fc5ef1e 100644 --- a/drivers/net/can/m_can/m_can.h +++ b/drivers/net/can/m_can/m_can.h @@ -101,6 +101,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]; struct hrtimer hrtimer; From patchwork Wed Feb 7 09:32:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Schneider-Pargmann X-Patchwork-Id: 197815 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2112688dyb; Wed, 7 Feb 2024 01:38:18 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU7iASotyst/odioqLd205rAD6/xEN/r6sDIN08nWqoULIdewVm7VQuir1nHUJHBzRV+hnhh/3MaZUJkLgEuA5RY9AnPw== X-Google-Smtp-Source: AGHT+IGPOvpOGutcrrdhf9TDJ2Eb7VpSB8SVvI65HYcJTFePPrUYXHfzXHhvcjGruaSC1bk5/Q8w X-Received: by 2002:a17:906:1b4f:b0:a37:b5c2:d9a3 with SMTP id p15-20020a1709061b4f00b00a37b5c2d9a3mr2992069ejg.4.1707298698148; Wed, 07 Feb 2024 01:38:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707298698; cv=pass; d=google.com; s=arc-20160816; b=Nw/pFDn5Bg2yCgDA67qtyPNjhOFvlhOx+oHA8pvgirNZ/6fsYcrerb7gEw3lezxooP eRjYPSRYRKGNBd+SuLNlgwhvsEwula7PWfrtp9mXZPJJkcli2emKOc3aiN/XPg4PKMOK ItgdiA9QvpPrgsFp8dvs6mu21n/cqM+fcr6+eHsBHT4DTXCECOiZlr4iJ0+1OVftdUN2 lqr4yEy+LnZ64YsUIscxl+cIOjoqQf1ik09FNGIut0VjHQiJ5rrUv7p3vUHlz5rv0stg 3N2aQu9kUc0YV9s+wiuKwJMkboIpliN5BTHlFf/Wi5yXBafB2BlAAotsmeZ2ZMOR4hjT QVBQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=uKZ3BPJz8PAmJCZaBIlEGMQvKGyQYSxuujjqsIx4zUk=; fh=fiNkDYTWMmMt/AjSXUyYIn9GomUdRT10ImMhuraNvB8=; b=dg+pLNxcUw4OgCTAYXSqABjwj9Ig5u45OexgSN10o26zVuapOwLCwKXKPBscAJCFG5 +FXjWzew7bOEKtClnNoPTiVs0Xk0mbRSQUVeMTcLPQUN2FZrXUjKRClg+uydz7O/s3je 3czfExU9Y8Ec+gxZE1pA+UB4pPMwnR4ptp4NbT0sgMlXVX1+YS9R93AFHuRu4HJxKSd/ BMQ0xHSreMEBZCQQJRJGexu11zRVkxOj0P9JHzNXLRnV0T2GhFATML/g1TJbv3UCnK+1 e384WhISeKV1rSL8WefL6D3anEakjqDn2SlHQGkrszE9XtbSP4/s/qJKK3XDRe3jun9d L2Mw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b="3beO/wrM"; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-56221-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56221-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCWtZqX70LbOsutEimUApKsdoNeeQTFiZJzJOv063Sjdlo8X14q1to7PTyQZcIjcgFCSVOORHcJ4q/xOuId6puXYhrEVwg== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id ce25-20020a170906b25900b00a3612401eb0si666126ejb.484.2024.02.07.01.38.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 01:38:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56221-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b="3beO/wrM"; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-56221-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56221-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 8CC4F1F2990B for ; Wed, 7 Feb 2024 09:38:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E2D1C4C60C; Wed, 7 Feb 2024 09:32:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="3beO/wrM" Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9439C2E859 for ; Wed, 7 Feb 2024 09:32:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707298372; cv=none; b=OxVxrXbyu8sZzygd1S007W7/V2ysEbmjmC5D7ATjFf8EJt0z8gzhHvhQ/zGqcSjaW6SoAlTTtjz36F0UduIqvjadQ1QM1cqROd3mpQxJ1KraIgMZXh8TvVq2BG7ap1mIuzJ0wp5y7wKAl8K+wDM6MGD8GnAPcPHkh3FOXI9lcHs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707298372; c=relaxed/simple; bh=NYJ3A2y67U2m+v+KhNwTl8S8kTZvtCbeohEtdOffeYU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sGh9DLYDaGUJ2xAydl5UWQYDkMxaXMM0FpEyrhgubwvMHmiBuhis0WbecCplx/xcJOTemOx97XO7CNdg3w/btKbzsYxemFdvGa773+fuzOlXNyC46EdXwNK++isrzxcDWKpbQNJLC1ISt8uxR+N1ihgUJ2qBFSyxv8RnwCQPbNA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=3beO/wrM; arc=none smtp.client-ip=209.85.218.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-a38291dbe65so41880566b.3 for ; Wed, 07 Feb 2024 01:32:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1707298367; x=1707903167; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uKZ3BPJz8PAmJCZaBIlEGMQvKGyQYSxuujjqsIx4zUk=; b=3beO/wrM/AGU7WHQzOQTbJg3rY2s8VeDh8wu2h5e/n2hRfS9i3FRRDJcxeQrGmxEQB 0vAS1WBqu9yDqrJOBMrGHxHUCC19kEhx/mwY6TBFdPvQEhUqXBboSn6EE88yjTXqYAeZ e32bszNa+L9vd1yGGpxtcMB2BoSo5YQRgEKK+eeJ2zOCbCpJdyjRlUdlh1+UsJtA3PU9 XgBW3F/Z9ZhKwxGAOfhjY7H7Tirzw75VDjTd4tat2pVL3xC/UBxVY/B0C7rmaEfD9blg H3LWaBxHc8m1cXBM4iyJo5uKpvUzVn5vSVhXgkphGzPQModd1n1u+d/AIqRKTa/ksGwh blJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707298367; x=1707903167; 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=uKZ3BPJz8PAmJCZaBIlEGMQvKGyQYSxuujjqsIx4zUk=; b=UR5jkIGUAPIBqq1PGnsW8m00s7YPwdh/xGqDF5zazLLdtTy+PMLBlE3F6Icq44n6fb /c5M0t2gEEoujf8PhjDrKiyKkA1vQSEXUMsx17yfKYAANMsqm8mWXi7vAYRsdrg7Xbus Qf2GM71RRjHY5nu+fVf8EvPMO+Y7Sgee6ooz9b6Xg8Totpi209fYeLuzI2mJE5qlaZfC lvrxw93cKsJwCFqAIWSpBFhEWGgrS2iZKt/a6YlWq4Vbh3xe64SFMs+B0pjL+gMl3Yj8 bi2Kl86ezKXrbjoV2jk0AELsTA8NNdGqqzyaxVr3YClKFQ4eB3kgZIKMMnL/lNJ1zcwF +hDQ== X-Forwarded-Encrypted: i=1; AJvYcCVekOA69uEWmgm/eCPkRwkMyKxIv5SvVtU8enw4Bvuq308EGX9eVseeGBuQWBYTYl15wzET5M+/CRXApEmbEfsKJiBmDnHte2BsvfdY X-Gm-Message-State: AOJu0YwLkhn5VLI57X+GvTGo4OO88ihbJx9j7A3UfhE02xhu96mRqpuZ mv4sK/stxRUTqyC8fcSte6lr9HdHHdUroXSZ/b8YMzrtXeSI/acPzb+B/4hykGE= X-Received: by 2002:a17:906:a457:b0:a37:2576:79f9 with SMTP id cb23-20020a170906a45700b00a37257679f9mr3564299ejb.2.1707298366961; Wed, 07 Feb 2024 01:32:46 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCV4ckXwS1ua8BB7mYK2JuX5RpJt2C8XTl7t0RACFE848UlmDKjd9snlaT9UnYsORUElPYx67iN4wONI+sK5+0xXSWr/30eyo6fnQluvljRKGMo3IP8yChLBlmNRRYAiW0jU/kq2htZCyrLRwxoTnXjg4DxH1q4oYeUofgtUBZEb/0OaabGwFPNGK1m9gQx/56Jo+d5+jOKVn2yvqLzawy4mWxZj/hrhaCjul9uDYt6dojxHH0xqS07/jN1Eg7zQlZ8DCBESqRVnTvtfTB0PY8htI5pxxt33K80OVlsD9mqy1a2AfX0yemM5ZNDFl+reX7deKlbY+Sp9/OIrKQ91BrQODHbjouRiR6ERVlnrWcRWqxiWzJxLNuIqQu+h8l/Dn4l9Tb+OdMs8leSvGCRQRVVogr4HSohNewEsX64u69vj4DpPHZEix7ofLmR7 Received: from blmsp.fritz.box ([2001:4091:a246:821e:6f3b:6b50:4762:8343]) by smtp.gmail.com with ESMTPSA id qo9-20020a170907874900b00a388e24f533sm122336ejc.148.2024.02.07.01.32.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 01:32:46 -0800 (PST) From: Markus Schneider-Pargmann To: Marc Kleine-Budde , Chandrasekar Ramakrishnan , Wolfgang Grandegger , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Tony Lindgren , Judith Mendez Cc: Vincent MAILHOL , Simon Horman , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Julien Panis , Markus Schneider-Pargmann Subject: [PATCH 10/14] can: m_can: Use the workqueue as queue Date: Wed, 7 Feb 2024 10:32:16 +0100 Message-ID: <20240207093220.2681425-11-msp@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240207093220.2681425-1-msp@baylibre.com> References: <20240207093220.2681425-1-msp@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790232439777773422 X-GMAIL-MSGID: 1790232439777773422 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 --- drivers/net/can/m_can/m_can.c | 109 ++++++++++++++++++++-------------- drivers/net/can/m_can/m_can.h | 14 ++++- 2 files changed, 76 insertions(+), 47 deletions(-) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index a8e7b910ef81..8d7dbf2eb46c 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -485,17 +485,18 @@ static void m_can_clean(struct net_device *net) { struct m_can_classdev *cdev = netdev_priv(net); - if (cdev->tx_skb) { - u32 putidx = 0; + if (cdev->tx_ops) { + 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; + net->stats.tx_errors++; + 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 @@ -1685,8 +1686,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); @@ -1713,20 +1715,18 @@ 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; 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) { @@ -1850,10 +1850,31 @@ 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) +{ + 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, @@ -1864,30 +1885,15 @@ 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); + if (cdev->can.state == CAN_STATE_BUS_OFF) { + m_can_clean(cdev->net); + return NETDEV_TX_OK; } - 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 enum hrtimer_restart hrtimer_callback(struct hrtimer *timer) @@ -1927,15 +1933,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, @@ -2228,6 +2236,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 0de42fc5ef1e..be1d2119bd53 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; ktime_t irq_timer_wait; @@ -102,7 +106,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 Feb 7 09:32:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Schneider-Pargmann X-Patchwork-Id: 197824 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2115755dyb; Wed, 7 Feb 2024 01:44:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IFSMb0bIaRlEcmx8KNSZcnWFqX4dx0Ay6lj2/XwljRROWn7juIdsfMLchlu9RBRvpk5HR5v X-Received: by 2002:a05:6a20:be93:b0:19e:533b:2b52 with SMTP id gf19-20020a056a20be9300b0019e533b2b52mr3405393pzb.35.1707299067053; Wed, 07 Feb 2024 01:44:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707299067; cv=pass; d=google.com; s=arc-20160816; b=V569A3xO9/hKHxZGO9XKRKhQdwJVvHQl0HuJ4fCXH9FP9uZWCGzgGKU7JZcztayqo+ OyRHFYiC2+I2AzBbE50QE6zATwoqQ3uK8b5AKhQ4RYK9h09QU0pdW8ndw7SRXrL9F34L euEgbD8Gtgdvy6YqHG/2gg8UH2wHX0Y8sAqHLd2Mk56lEhDE8Rmg3M2IhBzykleSOE0K kewasGOX3XUm4iLR9+JyLZBFJ2lMLyU8EVtlokv7XMfNy7UiOrS7qyRLb9L89nUtO18B 9G5ShzUBQCBB90Ry3HwNV2e8Vt+ezhPoVv7lZd0v5ylv1KI66sl3l3EBE1qAnTBgqCSm ZoOw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=kgfTbtmUbbSiqLPaZ9cB5Jd0ck+MgVbfxN1Z2T3vuQg=; fh=cu+/Ipw2zH3Q/g7LCR5r2ZS+1JMxX6nPxDUmvDlAeZc=; b=qvKj4+lXAjOU33zABngt5GAj5NR2TpkeCj2O+kCm92v8GprXD/sdgKACME/O7AAiXQ R0rqVA8dILAUchpLYChOTq5W0ChwzlwIIaJQ1GrDdzRGBLW0XZtOcGAw0oYgCKxUnb4W VSIQC4kUQkuZZugV1YDaLOY1j2lrvycgluy6iDk217NfzsYc1MqF6mesJnQb1nGC5890 YL0N6tg++wQTJGQ82D9AOlqDqHYdC0gKdeOdN8wCme+9WE5DetYMySVJ6bfdytZ1V6WP x7zLae/2gQ/gqVqkS2/ejbP420Q/9q9NFaI6gbpV0/cKSqXVTIfYr6/kPeNklGUHygi3 hz/Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b="aFvKLN/k"; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-56220-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56220-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCVv7T8D1SmxcIMr6ua0dZLvOUvLocoIzEkRdXPqvapdoweu3zURB4zwMnCJIXdxE5mCdjMJASee3DAsdpC12yIFz+al9w== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id y11-20020a17090322cb00b001d4b1ddc8e0si1314618plg.67.2024.02.07.01.44.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 01:44:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56220-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b="aFvKLN/k"; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-56220-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56220-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 9B6C728B041 for ; Wed, 7 Feb 2024 09:37:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D49F8482C1; Wed, 7 Feb 2024 09:32:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="aFvKLN/k" Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C09A235280 for ; Wed, 7 Feb 2024 09:32:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707298371; cv=none; b=YanQAFqqG8bZrunHJwVnjoq0PX63GbctJA/vsUV3gCF2O1RTG6+9uou+wSgyb5/GiIsZ6Kqa+Ade/pjgX6yJHigV31glwJfq2MA7uU7LpCTxND7nQ/om9uJC2IZ2MT4HUJUIAeuqiK1JR5uPbKckGFf8TwNnmDEpH/jE2HRl1EQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707298371; c=relaxed/simple; bh=1vAOyna1EO+SthqMMMmklPvKJ+2Y2FePYt6xRWUzh90=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sTV/+XQmQtTjnOFEVZekSfRkoMIlEbwZUD2R1mjQe/a4pqpPsVCt0kJbE3NEMadSdJhTfV1wzv9BvrNnU5ACk/XWMmDreeUbu44EPkga3buDlBoqOlVLEB/I/luoHw5WqHJHaYbxkZdB0ZruViuBBTgMXk7s6J1ZsrVgGFWB67Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=aFvKLN/k; arc=none smtp.client-ip=209.85.218.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-a36126ee41eso54047666b.2 for ; Wed, 07 Feb 2024 01:32:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1707298368; x=1707903168; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kgfTbtmUbbSiqLPaZ9cB5Jd0ck+MgVbfxN1Z2T3vuQg=; b=aFvKLN/k8R7+1T4S8NRug8ib6meDyJ60bvA6tGBNz8/jIJ97bqSHKkqsBh3QFsSjFi HDKziktF43PDIy1/d2J9Pr77ZRTyOAT0wPXE887mE8s/r95b9yHf8vJbd4glcsqC27pn WWLZIC3MpFPg6n5ghKJWiCmKA7AFhBJVYfTdOwlRK9Fy957OjI9TKTvluXbl1vLoHZbp 4hmwaMRZm8GoUASUO0Mj2YZ30Jc/SLgEYbJA8adwHACAO4uVoUvRct9/dZWMzUESSold CZZ3lLO7rV8V9ckrDM7VrdXcVlMHylkGUaYy7FReR860b5PFFKZrAQj2N3kAv07107t7 39Ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707298368; x=1707903168; 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=kgfTbtmUbbSiqLPaZ9cB5Jd0ck+MgVbfxN1Z2T3vuQg=; b=ACTRFJL65IYsXQizRXkMRnh4KYrt8MgaNYJ81+dVBMoK8d9NaGZRT5GvjLWqQEq754 VPIYq38I1+vy1WKx5arFXDdd5KKwyZSj9dxlLlf/CiIRps5Ych4HpwNl67FjQQPOLK9f QI4c2bfpqAiI6CkyRFmT/Tnh8k/85hC4TwMf7YHlOGn7DhhCO5g7ThHOvQbZSW/+XUBv Sk0TuoDQKRtTHKusFZn06qWKhcIcZoHrhOKZJXnsptyQeLPJkpdhki9pyNrtIz/UjJMR OcvzymhuX52q/G4tCVPTWUAF2NXuS6s+gmbIEbilxkCEElOK0YKVT3hzZ+GgQvg15HPW UbsA== X-Gm-Message-State: AOJu0Yw6/Dy6yhowm2xQ+E7lyrfLqAwsLoDv3bqwXPSfwnUaLubDxHEB XpeFgOhKWZi4LgUhrra0myu2wsVOJAYQRXH0huGGfHfmw9FXyLYeklSwT4s8bp4= X-Received: by 2002:a17:906:63d1:b0:a38:107a:94f2 with SMTP id u17-20020a17090663d100b00a38107a94f2mr3595455ejk.6.1707298368037; Wed, 07 Feb 2024 01:32:48 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUybHMDI6k2TSZskJ9jJiusRBOrylhZEhUgnPMOqXaODknCH4bHlQZ92JnbKVif6A0ySqbnujdbSE62kiSau4iw+gYi68wUO7zdQZgJhiKioSiZPTakhvzWRcBsowzWxIgw0+/g/DIGjV1VZNXtSnvaKH04hdOkVlC7p20s8+7QJgGw/GBHQ+ld3ac0rV+q3d90lhuGuEeNbCS8MJd6l+4/S+NQs78xfsecU4i7J6Wpzi7SsyQuwCSVa+AXBXmh+SUYlLOcUnYL/8AbrtVbO0w0MByuWU09erynOue+25XsFfghjGXTPHqBSEFUwRxAcHB1U7LOwh4AG1lE6+YAC4urP5C3Qwc/GzlEpVX9Aa99QZEsei6ROk1WmD0O7SMaKyiNYQAVcb+4JmiqmrGnQ409efkLZDhoAnk/jlab4nDRQVndIqynvx1Lz9U8 Received: from blmsp.fritz.box ([2001:4091:a246:821e:6f3b:6b50:4762:8343]) by smtp.gmail.com with ESMTPSA id qo9-20020a170907874900b00a388e24f533sm122336ejc.148.2024.02.07.01.32.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 01:32:47 -0800 (PST) From: Markus Schneider-Pargmann To: Marc Kleine-Budde , Chandrasekar Ramakrishnan , Wolfgang Grandegger , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Tony Lindgren , Judith Mendez Cc: Vincent MAILHOL , Simon Horman , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Julien Panis , Markus Schneider-Pargmann Subject: [PATCH 11/14] can: m_can: Introduce a tx_fifo_in_flight counter Date: Wed, 7 Feb 2024 10:32:17 +0100 Message-ID: <20240207093220.2681425-12-msp@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240207093220.2681425-1-msp@baylibre.com> References: <20240207093220.2681425-1-msp@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790232826392147174 X-GMAIL-MSGID: 1790232826392147174 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 --- drivers/net/can/m_can/m_can.c | 30 ++++++++++++++++++++++++++++++ drivers/net/can/m_can/m_can.h | 4 ++++ 2 files changed, 34 insertions(+) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index 8d7dbf2eb46c..2c68b1a60887 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -484,6 +484,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; if (cdev->tx_ops) { for (int i = 0; i != cdev->tx_fifo_size; ++i) { @@ -497,6 +498,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 @@ -1067,6 +1072,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; @@ -1076,6 +1099,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); @@ -1105,12 +1129,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; } @@ -1192,6 +1219,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)) { @@ -1890,6 +1918,8 @@ static netdev_tx_t m_can_start_xmit(struct sk_buff *skb, return NETDEV_TX_OK; } + m_can_start_tx(cdev); + if (cdev->is_peripheral) return m_can_start_peripheral_xmit(cdev, skb); else diff --git a/drivers/net/can/m_can/m_can.h b/drivers/net/can/m_can/m_can.h index be1d2119bd53..76b1ce1b7c1b 100644 --- a/drivers/net/can/m_can/m_can.h +++ b/drivers/net/can/m_can/m_can.h @@ -108,6 +108,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 Feb 7 09:32:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Schneider-Pargmann X-Patchwork-Id: 197816 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2112695dyb; Wed, 7 Feb 2024 01:38:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IFpuyKW2FlmfACPFfZmov11tqw/Zc9VX2OI/+jfwSwUFQiW6GsHjb/uy3XXxdS4uCDsxJ1a X-Received: by 2002:a17:906:4bcc:b0:a37:478c:6021 with SMTP id x12-20020a1709064bcc00b00a37478c6021mr3745054ejv.76.1707298699710; Wed, 07 Feb 2024 01:38:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707298699; cv=pass; d=google.com; s=arc-20160816; b=Nhj5RJ60croaoutbUvxiPqiIQ6/TwQ0vNlVlxb/bVXfxN448637Jza6wfveR6cVPQn MXo8U1CNjsP6tdY8R5L/8XTI7wbMJqMqk/hi8WVfdO3nbvVY5DKZDG/p/2l/imqnYAA5 YXgH+i5QKVk/4/P9abpzweZW0BY3JX/5d+lOHeKQ9XNhwcTGaiprJ5g+P5m1PoXtJviv E+1v7GOA8TAE+Q/WHrabhl+ZtQuput458cFPYxxnUmhBEOvgzDNR6WCbfF/gHOY9DHw1 l5maD6T/Q+M/vwxWafqd4pdAA1CmbXkyIcAvmYAhE/o83M1R/jZogrkiRZaaGMe43Nbd hDmA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ynzFBSzm0QvP5B3lSznm7RC+RbgARBCvd8XcXKtTV40=; fh=yYV35EvKUAv/2SOtPy0bR7jutTwsWO0Ndc70AuSgrns=; b=0cIi25nSWXbpiwFsw37tK/oDLmXOG1u+ccl3ti+zQosi/xV+3zyz5ARuhHO6r1CIJN 4O0m4dnhHwpG1fUWxsFljVuCjcitk8XSQDYNP8ii7swTPyinAw0wPtTvATUQaxek03ey Uf09VuUg+mHPBgjVXk1Iz6F1Dq7r+bWbZPhE8rKoqqluMeCFjVnT6VvVWGAlhspSWcPu AONU7AWsNSTJnwfJsDnbVtVYi3aRT+55b5Bt8mpfnJuApF5DuJSpj68WUEagJbIsmGXQ K8byuPRuOznO1QsAqVz/pzJXdfCgHWq0DWaJYtpO4NMxxnL6rQB0mCsm8kqDDig78beF qwfA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=nS3F3EZt; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-56222-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56222-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCWMCv/kCkB2eyjvt4TDDRhKClru2FXgU+ZkyuuGKLc/98XH48jwXptqkl2oN1uFmLesQLubKvSp8OBtoO1aULPbdTBgEQ== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id d11-20020a17090648cb00b00a3741771f3dsi707566ejt.418.2024.02.07.01.38.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 01:38:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56222-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=nS3F3EZt; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-56222-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56222-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 210671F2A253 for ; Wed, 7 Feb 2024 09:38:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1DE214C615; Wed, 7 Feb 2024 09:32:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="nS3F3EZt" Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BCCDE3C08A for ; Wed, 7 Feb 2024 09:32:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707298372; cv=none; b=WdIaFK1F6xFkLMyDA2ehqw029yPZRyiE8OMc8HhTgpLULOQn104GS4+TXGAtJqM3QK5Ju/ddj/TG+Yr+pwNvABSbMUqd2UqLgWm1ELwBlDJucNMybLtWgfJSkR9rxVsf5vc6uPWbs7pIfpJrJtiFCWYIO+lMYQ7Mo5O8QzKzke0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707298372; c=relaxed/simple; bh=NRByXN9LnRS5cAdFV4z6JTwvY5Y0C/+5VK35Zq9oZ80=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SC9lH1ditRgnV4Uh8yWvfJb05BDDAQgd2xkSw7YUJpf0yGmTGycGTiUwMdizhwcknUcYqEZFPHyXCMBxEGs5M+U56GCCjAwu04BzXyhYQ1v/FxhGDKjW1yKFd6byDF7pXFEq9NIGsVCPxbSCNp1zfCFuF0qrlg0wDth2N7Lipmk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=nS3F3EZt; arc=none smtp.client-ip=209.85.218.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a359e6fde44so42770866b.3 for ; Wed, 07 Feb 2024 01:32:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1707298369; x=1707903169; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ynzFBSzm0QvP5B3lSznm7RC+RbgARBCvd8XcXKtTV40=; b=nS3F3EZthrVdBv2au03f/S7RUe2YVFi1AQjkC77ZRURAER6T2SmzTGt3FvRVZTQLTE aVlfDFWTLJAwOL2haL9bIc4oGh8h9t7q/SaTcaD7F7RArhsSYB6xIS5tViwh6Tgc25bj TQXBfawoaKS7r9NM6RerUJs6qA4U/H89/sonw1Te2+NpXbTL1HFIxAY9Noi4ap2qFUS7 WjiNt7bp2PPr+SLRUrtnOmK9rr1/PrwWjEnsibLqYcjTk690fVstt+T7/caAS1HqKfec mZzrkRkR7pBXWJnLwnGskRMRkE6h05NSuBu1v6eJNPqk12My5yqbIxgGa8tuoUVx7de1 1OqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707298369; x=1707903169; 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=ynzFBSzm0QvP5B3lSznm7RC+RbgARBCvd8XcXKtTV40=; b=w5rHHwxcuRXfUax3E0VJpT6ngY6q9Gnx3NUK3GNGerEJ2Djl7OR9mQoONk+XZ7r+FG AszgZmr8rdy252uB3lpEyBpZuNc66q1I4nmHTIxOngEVSxbBJd8T8lWxgjsdVcV2P/wz XNkPAdplcbA5HgxKsEemjxxffCbHwP1WOaxXQ1CijI+J4Pc1oo5bRgihXxdzK+bWRjpe jvscltTAJEpFI7PouZrgXJ8oU0d8GYHMDj7D7DTewajRKd6HoPZvyHDpSvr1QrEmFvJ9 wPUUX7gBIzeITv39hyRlJt/2S7S2AAizWWJQAS24VySBEDfvCmkmYIeqtfHaUXMSQ3Tg GVbg== X-Gm-Message-State: AOJu0YwLjmj2l2T4R++NxY0qVpJ4eTxszmgXurya0tj9JzzwUS/DXaO9 /KXXRmx4jaD3CbNIjPFdXCz/IP+a27bSdK8LjeppHCcqhmYjQlI2Ug+JJShWy48= X-Received: by 2002:a17:907:910a:b0:a38:4abd:11de with SMTP id p10-20020a170907910a00b00a384abd11demr2055689ejq.54.1707298369107; Wed, 07 Feb 2024 01:32:49 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUilOPFwOWmkvBGlW1fZLG5e6i5sbtXa18cNTiMIXK2A6vcA4pm2LvGoFDX8jwKNEk25iTDc1jHDfev4bLZzVd/U/F0C9e5HCP1DY1QwzE5XfUwTd8SawueVBndggoYgqiG+8hsEKFQ+81bVdDmSO6JbQrhW8lRyhYxCKZHbZt4DU1lOOTHtx04Fun2AjCjMUzrILxUenfiAMoZaDVMvo+KUbUn7La3GOACLGxhZDXhETqbTgQjpXIwK+qkaP/1+irXBbwOEv8BSRXb0AmwRU0mseI18W9GV3vD0EheIPqAWIfUFNUm2FVRvMeDJk5nEPVK3ca9ctw8uRbkMdYuka1Psza0B2n7X4RPO9VhPhpQVvQ9BwsXIMMVcFqZp+fqMQGBUkG1ATutOJn1etq7HsKhhFZIK/2ytv8460hqkMBqh/CxGwX0vchPGuER Received: from blmsp.fritz.box ([2001:4091:a246:821e:6f3b:6b50:4762:8343]) by smtp.gmail.com with ESMTPSA id qo9-20020a170907874900b00a388e24f533sm122336ejc.148.2024.02.07.01.32.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 01:32:48 -0800 (PST) From: Markus Schneider-Pargmann To: Marc Kleine-Budde , Chandrasekar Ramakrishnan , Wolfgang Grandegger , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Tony Lindgren , Judith Mendez Cc: Vincent MAILHOL , Simon Horman , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Julien Panis , Markus Schneider-Pargmann Subject: [PATCH 12/14] can: m_can: Use tx_fifo_in_flight for netif_queue control Date: Wed, 7 Feb 2024 10:32:18 +0100 Message-ID: <20240207093220.2681425-13-msp@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240207093220.2681425-1-msp@baylibre.com> References: <20240207093220.2681425-1-msp@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790232440927703091 X-GMAIL-MSGID: 1790232440927703091 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 | 77 +++++++++-------------------------- 1 file changed, 20 insertions(+), 57 deletions(-) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index 2c68b1a60887..20595b7141af 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -379,16 +379,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); @@ -1077,17 +1067,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) @@ -1218,7 +1222,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 { @@ -1226,10 +1229,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); } } @@ -1729,20 +1728,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) { @@ -1751,7 +1736,6 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev, struct m_can_fifo_element fifo_element; struct net_device *dev = cdev->net; u32 cccr, fdflags; - u32 txfqs; int err; u32 putidx; @@ -1806,24 +1790,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; @@ -1861,11 +1827,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; @@ -1899,7 +1860,6 @@ 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) { - netif_stop_queue(cdev->net); m_can_tx_queue_skb(cdev, skb); return NETDEV_TX_OK; @@ -1909,6 +1869,7 @@ 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; if (can_dev_dropped_skb(dev, skb)) return NETDEV_TX_OK; @@ -1918,7 +1879,9 @@ static netdev_tx_t m_can_start_xmit(struct sk_buff *skb, return NETDEV_TX_OK; } - m_can_start_tx(cdev); + ret = m_can_start_tx(cdev); + if (ret != NETDEV_TX_OK) + return ret; if (cdev->is_peripheral) return m_can_start_peripheral_xmit(cdev, skb); From patchwork Wed Feb 7 09:32:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Schneider-Pargmann X-Patchwork-Id: 197817 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2112758dyb; Wed, 7 Feb 2024 01:38:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IHSlehsCavsnXc3TQu6clJUCywWWrfrA3rAUrtQj4adjqdfGphZ+IFSJYf0PIm0b8AIjOrA X-Received: by 2002:ac8:57cf:0:b0:42c:44d0:470b with SMTP id w15-20020ac857cf000000b0042c44d0470bmr30052qta.5.1707298709737; Wed, 07 Feb 2024 01:38:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707298709; cv=pass; d=google.com; s=arc-20160816; b=WPTw26zm1Hsju7ltObbxkYy+aGKYqKc8QzJ6S6NhdWX5Qx7EZ4ysFs5/Z9ES2BHJIO e832+zY6ZszYjqHwU810RfVoXne2UBPP1kst40ukopvvJ2UtaJiSnafZMtlP7GFdUg+8 zmcgNOT4103UMD5sl5NcgXHm9SVS3ijJ6gDme65HiyXHGlO7eDuEZKR992dvoV6w5Gk3 FrGb0EZ8FOZc4+gjDuNp/Iw9eQ+YOXM0q8eyTrIGWQ3M36D8aCDYZAzMvu2Puany8fnw jdwqYPoF5PreR0XQVtOV5/8/J+Xm24aplCHRh0mJPqKujWAwEcJooeL5yFV23YYq77Cf 1Teg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=nVaBe1cRQbyg0PtGOEKAuifBPU0qmKGXvSAvyPB81Co=; fh=XF607u8DfZy0Nju4mUogiXt7ADX7eQ7N3HTY5xNkmuM=; b=lZDHr3yVRqK1QjOCnUs5Hom3m9BgZpJH90Eq2EY+nWl7r5jdH2OsQgNlWGZkAJ/l+o 5SzUXI/bay+x1KTHNn27FQIyIuLr9PrrWApchei85cCtvJuBfdmo40S7+5OkwUCcom7a SEMAx1OLJGghvfZDSqQrcp1f9DU0fW6w6IX8q2geh9i4jxzd51v5ModurzIcaxy0vFjP dchBjkQ/9l7Rat8X9/p2yvX+Vf3EJRCCF2c+M2J1VEzV/O+YsnI3hto6asmuBzFhFLNC qqFF1wfHwlt2IjX8qbK6t5K16ZmNSdxQxB96PVTOY3HNgpcIX7e3t/Yqwt6cY2lo5d2x aWzg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=XVhEHqRo; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-56223-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56223-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCWvCLXSBjDw1v9DXpbdfvKnuXQQ+YgyJUXQHA1hRmA+dp9BnzDAcAV1cWANDK72bAQpSmNVK8pTCh3yemiTxMSwrTTeFQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id b13-20020a05622a020d00b0042c3e5b11e1si762251qtx.365.2024.02.07.01.38.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 01:38:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56223-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=XVhEHqRo; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-56223-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56223-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 7A6F41C2408D for ; Wed, 7 Feb 2024 09:38:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3436F4CB2B; Wed, 7 Feb 2024 09:32:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="XVhEHqRo" Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D37DB3C49C for ; Wed, 7 Feb 2024 09:32:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707298374; cv=none; b=GfkZyD+ioobK54JKl/AIVhNZ8XJpUJP0Ow7VHfYuetQuhtcJQ2w71/FKh7M9kqqriGuviRaYtWCVRbr+u7k8RvoD6/BLL7mgn3mjYpFt0267nJkzSsnWz0NUMbp1uTVT3ZiitTTpxsrFZDAQ9eoh6ALQcMkB3M3fikRYB3Z2isY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707298374; c=relaxed/simple; bh=Q9lUXRT+YgSevzYrqV6NxERHNWcO3poNT0QEvQN9im4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gPLrtOAngiFaR8KIMJ1c25TgYtKIXykt6TMauF7JDFtmjTf9TIG8Rsmh1/f9YiH+ptPurnxaTMgXjHR7yypB0/rsg8uqCF7mAx4Wp8Kt3t2hiKCNPJkp5CY7gR8eNPYauS1Q6bZMh/pKsNFB2gMRHwr5bb/kXqnd4eonigRGISI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=XVhEHqRo; arc=none smtp.client-ip=209.85.218.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-a385fa34c66so51426566b.1 for ; Wed, 07 Feb 2024 01:32:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1707298370; x=1707903170; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nVaBe1cRQbyg0PtGOEKAuifBPU0qmKGXvSAvyPB81Co=; b=XVhEHqRokFGhyazZjpl8sYN3PnhS2Arz5dq40ibfcPysE5uXtFdQ1xio7KIPL+V5HT YhUC/0D7Xe/XEpA7NwUwniVc5ZsXJgLygWr5uBN9GhfjVbdAz+IDzaf9WfUPVPkwP/t0 IbP+c0khhuyNSaNHIUczjo9hzWl63d2hD0f2TTtBcdSufJJQsJqUBWlAZvRZUVp/bJJA Uh+M81UtoaVmTa2Sfetl1t/WZGZeg0OAj0yTTY+SfLsDBqKoGFOdmp9AXHcGyoO3kMJn wjLhRU+cfGeZtQDoZ5uiH5fUXM9+Y0QUJ8UtTjTt3+6ev0hnsYXNTU3EMdy0LciT+3+Y aiQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707298370; x=1707903170; 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=nVaBe1cRQbyg0PtGOEKAuifBPU0qmKGXvSAvyPB81Co=; b=oPES1CQn0LgWQSQYTNSA3PpGHUP5LLAB6QAKjk2cX/du3wRv3hCsORjOHg9MbrQLhX w76vpd1XB52rrNrplBaCENdAXJXzeKgghw2M03rhPVSGGeECKAtiLR1W6VwuWaA6Oufx NIZlQuyuErMpY3CE4g5mQI1RV68gcKZWjkBwv/ZOt8xtT5y5R7mcuUVDnsh+pQ424ydP lqzhLzROnxxzTGS6TjH1/xB0gM7rd52hyg0Liz5xYcTfhm6PF9ho9jX4VpXR4IHCegVO f9VS8NxXTAeXX2BM2p39e8zAC6EczZ90nrywq5XKhne2QEUG84vKExHKq7TrtwBaTih6 5nEA== X-Gm-Message-State: AOJu0YxAboOdo7eVoTTiKKimvT4jaWd2IlatInH1cpsu5BS9zsNbgmAR A5jvucTBUmJ0A1JbQJnScl7l4UzxX9Mq6wLPgeYJeXmRn5KbHLWmMDY8Uja68ZQ= X-Received: by 2002:a17:906:23e9:b0:a31:4e96:f40a with SMTP id j9-20020a17090623e900b00a314e96f40amr3507030ejg.26.1707298370257; Wed, 07 Feb 2024 01:32:50 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVONeauiJEfez5+TTvMZMiSlpAkGE4X/BdInaA2Rg4XFNQencIUAmJM9l1Xj6jpMZjbRyXouXjSK3iJzZPb4d/6HUVavCh87c7bZaoj5rH19mCxyzMM6b4ksVRhrSvaBjVyke2UxAO/M/OIP57Xj7ppTStGtAZLoMIRf3Afae5hOvkHhMs8EvOrloda+vw2QyfIldZYsStBy7kBf9zhYRfBcn4kMHJgLnccKRDSlX7Kvvcxa6Gen4vIBlutkfI1OCDOkf9PIKrc+gsTX4cPO2rgoAqGcVyZLwIXSvdM+xx3wNOTvHrVT2D1PXN6ll2DIcrs6ncTvCIF7oQfB0IAAJ4ApMdrn/RdgEvn2QRgtwkDxwndQygy4CjLzFDi5qxi0zO8FXZ59vMZ9C+5ODJWN+Aeh4TsQEoNl6iVMdmrMvcpLTRA/JWmCcJ8kzNB Received: from blmsp.fritz.box ([2001:4091:a246:821e:6f3b:6b50:4762:8343]) by smtp.gmail.com with ESMTPSA id qo9-20020a170907874900b00a388e24f533sm122336ejc.148.2024.02.07.01.32.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 01:32:49 -0800 (PST) From: Markus Schneider-Pargmann To: Marc Kleine-Budde , Chandrasekar Ramakrishnan , Wolfgang Grandegger , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Tony Lindgren , Judith Mendez Cc: Vincent MAILHOL , Simon Horman , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Julien Panis , Markus Schneider-Pargmann Subject: [PATCH 13/14] can: m_can: Implement BQL Date: Wed, 7 Feb 2024 10:32:19 +0100 Message-ID: <20240207093220.2681425-14-msp@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240207093220.2681425-1-msp@baylibre.com> References: <20240207093220.2681425-1-msp@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790232452045318149 X-GMAIL-MSGID: 1790232452045318149 Implement byte queue limiting in preparation for the use of xmit_more(). Signed-off-by: Markus Schneider-Pargmann --- drivers/net/can/m_can/m_can.c | 50 +++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index 20595b7141af..48968da69ae9 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -489,6 +489,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); @@ -1043,29 +1045,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_queue_timestamp(&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); @@ -1104,6 +1111,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); @@ -1132,7 +1140,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; } @@ -1140,7 +1150,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; } @@ -1218,11 +1228,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)) { @@ -1738,6 +1749,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 */ @@ -1783,7 +1795,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 */ @@ -1821,7 +1833,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,11 +1881,14 @@ static netdev_tx_t m_can_start_xmit(struct sk_buff *skb, struct net_device *dev) { struct m_can_classdev *cdev = netdev_priv(dev); + unsigned int frame_len; netdev_tx_t ret; if (can_dev_dropped_skb(dev, skb)) return NETDEV_TX_OK; + frame_len = can_skb_get_frame_len(skb); + if (cdev->can.state == CAN_STATE_BUS_OFF) { m_can_clean(cdev->net); return NETDEV_TX_OK; @@ -1883,10 +1898,17 @@ static netdev_tx_t m_can_start_xmit(struct sk_buff *skb, if (ret != NETDEV_TX_OK) return ret; + netdev_sent_queue(dev, frame_len); + if (cdev->is_peripheral) - return m_can_start_peripheral_xmit(cdev, skb); + ret = m_can_start_peripheral_xmit(cdev, skb); else - return m_can_tx_handler(cdev, skb); + ret = m_can_tx_handler(cdev, skb); + + if (ret != NETDEV_TX_OK) + netdev_completed_queue(dev, 1, frame_len); + + return ret; } static enum hrtimer_restart hrtimer_callback(struct hrtimer *timer) From patchwork Wed Feb 7 09:32:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Schneider-Pargmann X-Patchwork-Id: 197818 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2112815dyb; Wed, 7 Feb 2024 01:38:37 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU5J0S4YFce39QNn0ETBPdgqn+b9Eg5CzPwhXxbi9suNkX8yu9GIJCKoIJySh+b9i/BAhqog40X9VYCQkcjs/d0l1PcJw== X-Google-Smtp-Source: AGHT+IFD11VWpH0FZgI0njXTPYlDJUeFY3pTXMmrhr4hfoIdFZgBqT26zyEFK/XFGZzUvJJb5mfk X-Received: by 2002:a05:620a:1aa9:b0:785:98a6:a197 with SMTP id bl41-20020a05620a1aa900b0078598a6a197mr2168911qkb.62.1707298717150; Wed, 07 Feb 2024 01:38:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707298717; cv=pass; d=google.com; s=arc-20160816; b=0/eBui1eu0DUizkF0qZgPJeud1PF1WVaknELGAw23tiiQmU1VHA9aMT3Gl5gSAaZRJ YSXDAZz+gbwKdRf5Ssl9htP6XXvueAb5lY05icMM/aK2CyT3LxJRKYcBUJNb807S7sIx jD5b5UDjXUIduesrpGW9pOUhr5TkuZ2UsYN1AvtmeCeLN1m2lmCFHnzbvBwAlri7MIKi v6ZnNF3do96DRmXrpco0oht5q6Ko+LEsv6opLlGCDUwKQStbZmXB0pmZEy6C0Y/4RU12 hdis0NVLSVPUH7SKZIEAEoEJpfFDbUWtEQlXnGdvBqf0/VjE2MdFUfTyn3iGCbW6KSpp tqLw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=vyrMc5jTp9SVMayJr+6E15Cmf/hoA9mjpzLhtoAYUfo=; fh=Vl/NL/vlq8q671C0NdA5kFzikGbku5qe2iT1sphvFUg=; b=A1HFlRJSxdOpgl9iUokMyYcoitLxpCbgqyVUNi5gsQ9XGgNwOjDi3Okgf8+xpQZVlS lBLbNZNjj9jDLid2ueIze4tEWxMzBburlcMp9DT/yHsAlGa4XAVRDkyjg9BdoyVrYyH1 UI8mb70k7l3YfKVpFa3fdj3TN8wMfK6S+XjeT0ZJLsD2zQScMsorY2LQYfOkvdIdNFrZ 8gSEyVFF2dzyXk4AkuD8s5XMFbQek6Ep/W6sgA1Gpg4qDjdMS/mQ5LkEXjKMu1InxnM2 07CAXJc6p2Ahu4L8iuys9L3wQhZ9VB1A3AZBkRAxWCtU52q1IHH5MICgfZFA1UUq7dqU ivRw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=P+wfLnhe; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-56225-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56225-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCUHiBLIYr2jTE8+vr6UThr6C+pWhenUw6xt1Ay9f7qXYWDMg5GX4gtW12TZH4u0bhQXJAPCMrFicIl9Pqz8aIzIOxIpiA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id t17-20020a05620a005100b0078407cfac22si727230qkt.376.2024.02.07.01.38.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 01:38:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56225-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=P+wfLnhe; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-56225-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56225-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id DD2531C22AE2 for ; Wed, 7 Feb 2024 09:38:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AE1B24CB5B; Wed, 7 Feb 2024 09:32:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="P+wfLnhe" Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 76D523F9D6 for ; Wed, 7 Feb 2024 09:32:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707298375; cv=none; b=hwRs1cwTWGGyX8lvx4b0RASJ+asmyCb6FlIXA/mk0iysMDDsFqe3J3BPwTxnZZyRxrjUKKh4dzgZA9KfFdpMJRDF03Uq+rso7L3boJI9KhM1cumDjcmbnLHfVs/AgrcZ3yxiXyMEp1/D5Klmpuqoh3H2XrFvS4PPnqX0OL9SV8s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707298375; c=relaxed/simple; bh=IrjB9D7I+eQ6XxmJDoPLbOhDTNkYMgIUTaS/CiFBq2Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eb+kL0kjL50t2XiAzcWOAiSSQumajAUvcWPkLSF/hhAOlZvVbYRIdxibDJmQE1+4pC+3rWOxtzSQG7q6WeGyuvEPc67CT/2M60gj2MTLd8aaYHsB1ILgnKOUA3BxTjV6JFoeY0kZTU9Du0lUFO1EyX+1KYj5cKRwsp15ztzkZUU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=P+wfLnhe; arc=none smtp.client-ip=209.85.167.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-51124d86022so661960e87.0 for ; Wed, 07 Feb 2024 01:32:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1707298371; x=1707903171; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vyrMc5jTp9SVMayJr+6E15Cmf/hoA9mjpzLhtoAYUfo=; b=P+wfLnhebTEVJE9V4wRL4x856FoM9eLNlJ/mTzOyJbRZuzDBqiQIcYQtOmv5wERqeU bzAWc2t0E+AHpW+7fl6CyGIOg+WdA6QfmdIAUw9iR3nFvOrzdRwZByMOKzt18YlWCEiD XejWl5EhssTxklQsAS1TQuGGANBMgeswg+vcea7KSvOVPXXOxz6J9rWKyOKbaNMXbIfX PqdcpcE4fJoNLV5bgLE7WqFSnT5UBlu/Dq+b6ZNAJIk8rRZ3StwBHAoO/rUER9vquylQ uj2KEyIFp87Xq3xf8twaZlYnPP0ud1YVJRAcZ9cA9rVBIpJSlPv/8KMLMgw1CNLTmXzJ U4KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707298371; x=1707903171; 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=vyrMc5jTp9SVMayJr+6E15Cmf/hoA9mjpzLhtoAYUfo=; b=AZ2wuZ8dpy/8l6MgWfhKUwmmj1Z9MIcfjydxqaNza6dT3D2JjOd5BJtazhI2Gf+rUE StM9CDPsdIHjik0oB0lqzU2ZD09RADAqkBp+4zjCwaSB2bJSfccQvsMzmNa9pM1xdaYt ftVwWJ70ko7r01OmkkN/J96spE8rUqplC1BJBeC3bqRIvbzJfDiSb4NBDjkLuAIY7bPr 3O1wamuHwB5oj7syELT7HQgbRt4Iz1DxXv4ndB3w6wI8435KRm/32+MKKX9ejWRa77Rc /bsVmUV9ge9d8+ScmNSh6DJRrPoPVn7yVZT+1s1Es8AFJYFS77DZCpUdkhNxrh6mDPpe lrOA== X-Forwarded-Encrypted: i=1; AJvYcCVTj53pb5v8sWV/eoogYLSOZ9D/7wRjsiY9ZWCJzDZd0lL+22FdHGoPKFcl5iqGZWGxFKqCHepIg1l/Dtx9KjynYLrsH1ZCNMQG0wRS X-Gm-Message-State: AOJu0YwTw3LiznQdW9LFvcs/F80ZIjqYHkkvOGxL/4X9uZYINpATLwYO KfzR3C3ArMojnlzgsHeoHEcaJ42gsivBbhJ+A/H5wvtg7RPfxMjoAqcyiO+RvKI= X-Received: by 2002:a05:6512:370f:b0:511:6263:408d with SMTP id z15-20020a056512370f00b005116263408dmr1649723lfr.8.1707298371575; Wed, 07 Feb 2024 01:32:51 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWOWcLOLQ9J24dPnoaG8IbJC8shp1vr4lGFMt2PWDagdz+m4NS4yWhB8snlw+CumAifFUDVrlUoZQ0Q4+v/UP8wiJ6vbRLHuHPZvpoKBiPo7MLcZwoYW/a8xXdRQPbBICXOLhHiDhjAKDcNhAYomPtmipfq0dp0x9lQsHUhw03WjeaN+twKE65+wW/cfKwFDEcvgkv7x+5NmYuerBB8W/4TQxB4mvQOjIbNqje/tX5CwShlEm60Trmie5idaae4N0K9/ORgEmZNgkWFPmOPiZVpQuulZXxE9HFO8P/xxfpt+03JWR/b4wsqM6PttqvDeLX/c1+CQ+3yuMESoZ6sxSdQGO11NTGeRppTUUFU5/+UYIjVL3SMg/hWxm8nZstXMw78Y11jXsQRmFQiwEPP8pwZdCLvXjCbBXMYvEFxCq47A4Bq6jvPqjBzBUvw Received: from blmsp.fritz.box ([2001:4091:a246:821e:6f3b:6b50:4762:8343]) by smtp.gmail.com with ESMTPSA id qo9-20020a170907874900b00a388e24f533sm122336ejc.148.2024.02.07.01.32.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 01:32:51 -0800 (PST) From: Markus Schneider-Pargmann To: Marc Kleine-Budde , Chandrasekar Ramakrishnan , Wolfgang Grandegger , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Tony Lindgren , Judith Mendez Cc: Vincent MAILHOL , Simon Horman , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Julien Panis , Markus Schneider-Pargmann Subject: [PATCH 14/14] can: m_can: Implement transmit submission coalescing Date: Wed, 7 Feb 2024 10:32:20 +0100 Message-ID: <20240207093220.2681425-15-msp@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240207093220.2681425-1-msp@baylibre.com> References: <20240207093220.2681425-1-msp@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790232459135088759 X-GMAIL-MSGID: 1790232459135088759 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 --- drivers/net/can/m_can/m_can.c | 56 ++++++++++++++++++++++++++++++++--- drivers/net/can/m_can/m_can.h | 6 ++++ 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index 48968da69ae9..b7dbce4c342a 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -1539,6 +1539,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); @@ -1835,8 +1838,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); } @@ -1849,6 +1857,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); @@ -1857,11 +1876,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; @@ -1872,7 +1895,17 @@ 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) { - m_can_tx_queue_skb(cdev, skb); + bool submit; + + ++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; } @@ -2015,6 +2048,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; @@ -2059,6 +2093,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", @@ -2069,6 +2115,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; @@ -2086,6 +2133,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 76b1ce1b7c1b..2986c4ce0b2f 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 { @@ -102,6 +103,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; @@ -116,6 +118,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]; struct hrtimer hrtimer;