From patchwork Fri Jun 3 10:28:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Mailhol X-Patchwork-Id: 12868955 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47D3AC433EF for ; Fri, 3 Jun 2022 10:29:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243688AbiFCK32 (ORCPT ); Fri, 3 Jun 2022 06:29:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243662AbiFCK31 (ORCPT ); Fri, 3 Jun 2022 06:29:27 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 999893BA47; Fri, 3 Jun 2022 03:29:24 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id d12-20020a17090abf8c00b001e2eb431ce4so6912090pjs.1; Fri, 03 Jun 2022 03:29:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OAzqFSeGawzZvXT7dH0M+6XyxMAQAoLYxatmC4o6MuM=; b=Vtt3oW12TJSpEmc6BbX1Q7Sgg9gXtFxTD9WRloXBEdty3tE6s6hGpEHJEmN1kGRpz7 O5ErQkkpI7wIoflk1XJcYTqnmjUYvY7rYG6hsDGozUCSVDjemUHQoReimfPbUSw0DXqi KtG5vRg9yQDGcZXnViCAJNaGRuVhTGxi57epBzGlav83NCOnwqOHC7Fdxnh09EgXV3Cq YXz1oDorIMirgl/2GgExha5UbFl8Fh6xLSJQAFzZrqEenJ5tP+f9o6dIri+bGBWyoj2o zmvGvN294uGDu1wP8vdnSAvI/XEgWpZaSMMqsFKVxbocc7oxjePka2N9NYscNJFtmRa1 CF3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=OAzqFSeGawzZvXT7dH0M+6XyxMAQAoLYxatmC4o6MuM=; b=yiOgqrDwWszSznEa9A65Y/83C5eGqT+TSiLziNHdDi/7qD5jy70Lnk+TUVF36SlYRf 7qbviCzs/VdD75DZlW/fpM4nJ2Za0dihHNERm7d9rHijeYPyh6jpatqy5fPJRP1uhqQg rg4zvdxHmxEsMEjvicCIV3pepvuyD/JWbFJ4xNjwakXl/ZXTbewc712LJl9q/b1fGH/l 5AxXyDkq6Z174P9nEIXOSaiYUX/Wg9U3e4srCEYEJEVIhjYw5rqyzWIPt2nWX0gIlFxm L+JAXWMx5GGwD6wvyaXbT2qW0inkA4jctPuhlX143hFAiHz5GdmxlcvJBDNqk3xiQ6td ekLg== X-Gm-Message-State: AOAM531vhCnIabRQyIlOEE1I8WTvcKisYSjFCD3IQTLR/SNCrFpiJ+p5 O1bYdyq1J65wK0VtLFYPS9bjHOA8TmwLpw== X-Google-Smtp-Source: ABdhPJxhWYYsNGHaQ21EEPYsG1lnZNam/n4ZLV6wvAgjz6qLUxrlWMrSiOm9wwuivXMTxNm2NUt7ew== X-Received: by 2002:a17:902:f815:b0:163:c524:e475 with SMTP id ix21-20020a170902f81500b00163c524e475mr9663297plb.37.1654252163965; Fri, 03 Jun 2022 03:29:23 -0700 (PDT) Received: from localhost.localdomain (124x33x176x97.ap124.ftth.ucom.ne.jp. [124.33.176.97]) by smtp.gmail.com with ESMTPSA id b22-20020a056a0002d600b0050dc7628182sm3041676pft.92.2022.06.03.03.29.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 03:29:23 -0700 (PDT) Sender: Vincent Mailhol From: Vincent Mailhol To: Marc Kleine-Budde Cc: linux-can@vger.kernel.org, linux-kernel@vger.kernel.org, Max Staudt , Oliver Hartkopp , netdev@vger.kernel.org, Vincent Mailhol Subject: [PATCH v4 1/7] can: Kbuild: rename config symbol CAN_DEV into CAN_NETLINK Date: Fri, 3 Jun 2022 19:28:42 +0900 Message-Id: <20220603102848.17907-2-mailhol.vincent@wanadoo.fr> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220603102848.17907-1-mailhol.vincent@wanadoo.fr> References: <20220513142355.250389-1-mailhol.vincent@wanadoo.fr> <20220603102848.17907-1-mailhol.vincent@wanadoo.fr> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org In the next patches, the scope of the can_dev module will grow to engloble the software/virtual drivers (slcan, v(x)can). To this extent, release CAN_DEV by renaming it into CAN_NETLINK. The config symbol CAN_DEV will be reused to cover this extended scope. The rationale for the name CAN_NETLINK is that netlink is the predominant feature added here. The current description only mentions platform drivers despite the fact that this symbol is also required by "normal" devices (e.g. USB or PCI) which do not fall under the platform devices category. The description is updated accordingly to fix this gap. Signed-off-by: Vincent Mailhol --- Please share if you have any suggestion on the name. I hesitated a lot between CAN_NETLINK or CAN_DEV_NETLINK (because netlink is the predominant feature) and CAN_DEV_HW (because this targets the non-software only drivers, i.e. the hardware ones). --- drivers/net/can/Kconfig | 18 +++++++++++------- drivers/net/can/dev/Makefile | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig index b2dcc1e5a388..99f189ad35ad 100644 --- a/drivers/net/can/Kconfig +++ b/drivers/net/can/Kconfig @@ -48,15 +48,19 @@ config CAN_SLCAN can be changed by the 'maxdev=xx' module option. This driver can also be built as a module. If so, the module will be called slcan. -config CAN_DEV - tristate "Platform CAN drivers with Netlink support" +config CAN_NETLINK + tristate "CAN device drivers with Netlink support" default y help - Enables the common framework for platform CAN drivers with Netlink - support. This is the standard library for CAN drivers. - If unsure, say Y. + Enables the common framework for CAN device drivers. This is the + standard library and provides features for the Netlink interface such + as bittiming validation, support of CAN error states, device restart + and others. + + This is required by all platform and hardware CAN drivers. If you + plan to use such devices or if unsure, say Y. -if CAN_DEV +if CAN_NETLINK config CAN_CALC_BITTIMING bool "CAN bit-timing calculation" @@ -164,7 +168,7 @@ source "drivers/net/can/softing/Kconfig" source "drivers/net/can/spi/Kconfig" source "drivers/net/can/usb/Kconfig" -endif +endif #CAN_NETLINK config CAN_DEBUG_DEVICES bool "CAN devices debugging messages" diff --git a/drivers/net/can/dev/Makefile b/drivers/net/can/dev/Makefile index af2901db473c..5b4c813c6222 100644 --- a/drivers/net/can/dev/Makefile +++ b/drivers/net/can/dev/Makefile @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 -obj-$(CONFIG_CAN_DEV) += can-dev.o +obj-$(CONFIG_CAN_NETLINK) += can-dev.o can-dev-y += bittiming.o can-dev-y += dev.o can-dev-y += length.o From patchwork Fri Jun 3 10:28:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Mailhol X-Patchwork-Id: 12868956 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 576C5C43334 for ; Fri, 3 Jun 2022 10:29:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243714AbiFCK3p (ORCPT ); Fri, 3 Jun 2022 06:29:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243703AbiFCK3e (ORCPT ); Fri, 3 Jun 2022 06:29:34 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74C913B563; Fri, 3 Jun 2022 03:29:30 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id 15so6893995pfy.3; Fri, 03 Jun 2022 03:29:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6A3iu3rNJWzBkutodRRieEYgk6pwGMMZT+XJ2wM+6eA=; b=fhosUP+l3BU/qFj8oHGlC2pTDy/MwsvcIj+aMHQIY67yLhDlnMo8hi1YBn6t1qJuzn 6W/AlKo63G3a5wsEn/FnlFyMyIlkz2UPro6Te/MY876SpJaXbfd71q+i3cHEva4eZYhG t5neDRTOtI2Xvx8xV54lzs7sRbWXWgE1YVZdlg5sucKsb604n367+EaMDp3RnprWeipd 7u7/iIvdUzqIs9VSdUXBdd3ksIgy8RY8afWoej9hs0W82mujm/s00Sa6KAsjhQHnEZiv dHUv3ClRoHJv5LCauv0IHdXtfathokMu/s3h93W/rpfIjjp55Sm5+VnaG754P9Awo01B gt0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=6A3iu3rNJWzBkutodRRieEYgk6pwGMMZT+XJ2wM+6eA=; b=SE01ciwqLfcZsz05FGhLb8ZmBhESXMG7XvcQhCleUdu7eAyVpo3NDdAT+IFgU2unMd eyWTx6oBDhyDGd3hfJVICdVg/oqEQG6EzX6RDtSlmbqkFgZcOeVfoLNaspIQM1wPebu9 mqnj/xFqbWIJEyAXQg1pqgprQi8nl+OlHKwU1JceJ4E27OZHNpHYIYD7T+C7MNybdsFq o6MBpjBH+9NrsLlEpVsg61fmDyquNcsoOuxQ4nTae9cx4335nKr69MrbXzpU09+RHzm3 SUrJ2Jp7ay78/5IFfJnHx4lWk6iwxw+JGWhUW3LsFRZIZkZ+9AQ2VVAUrjwfU5XaQnkd wRyA== X-Gm-Message-State: AOAM530Lqnwy0r4nf1GEsExzHHU5GU/ATjB3EoTpW8dLr8F1e+yKOOIP 6KTY67pU34tPQMjOZOuooAvDahB1Sf/E1Q== X-Google-Smtp-Source: ABdhPJz0sP7Z3VZSZtL3qu64mERQ95OJxW1/Q6a92GAwgpNRrenV9xEYqx/yV4tPHLDh4sKUkdJzuw== X-Received: by 2002:a63:cc53:0:b0:372:7d69:49fb with SMTP id q19-20020a63cc53000000b003727d6949fbmr8391718pgi.21.1654252169895; Fri, 03 Jun 2022 03:29:29 -0700 (PDT) Received: from localhost.localdomain (124x33x176x97.ap124.ftth.ucom.ne.jp. [124.33.176.97]) by smtp.gmail.com with ESMTPSA id b22-20020a056a0002d600b0050dc7628182sm3041676pft.92.2022.06.03.03.29.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 03:29:29 -0700 (PDT) Sender: Vincent Mailhol From: Vincent Mailhol To: Marc Kleine-Budde Cc: linux-can@vger.kernel.org, linux-kernel@vger.kernel.org, Max Staudt , Oliver Hartkopp , netdev@vger.kernel.org, Vincent Mailhol Subject: [PATCH v4 2/7] can: Kconfig: turn menu "CAN Device Drivers" into a menuconfig using CAN_DEV Date: Fri, 3 Jun 2022 19:28:43 +0900 Message-Id: <20220603102848.17907-3-mailhol.vincent@wanadoo.fr> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220603102848.17907-1-mailhol.vincent@wanadoo.fr> References: <20220513142355.250389-1-mailhol.vincent@wanadoo.fr> <20220603102848.17907-1-mailhol.vincent@wanadoo.fr> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org In the next patches, the software/virtual drivers (slcan, v(x)can) will depend on drivers/net/can/dev/skb.o. This patch changes the scope of the can-dev module to include the above mentioned drivers. To do so, we reuse the menu "CAN Device Drivers" and turn it into a configmenu using the config symbol CAN_DEV (which we released in previous patch). Also, add a description to this new CAN_DEV menuconfig. The symbol CAN_DEV now only triggers the build of skb.o. For this reasons, all the macros from linux/module.h are deported from drivers/net/can/dev/dev.c to drivers/net/can/dev/skb.c. Finally, drivers/net/can/dev/Makefile is adjusted accordingly. Suggested-by: Oliver Hartkopp Signed-off-by: Vincent Mailhol --- drivers/net/can/Kconfig | 29 ++++++++++++++++++++++++++--- drivers/net/can/dev/Makefile | 16 +++++++++------- drivers/net/can/dev/dev.c | 9 +-------- drivers/net/can/dev/skb.c | 7 +++++++ 4 files changed, 43 insertions(+), 18 deletions(-) diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig index 99f189ad35ad..b1e47f6c5586 100644 --- a/drivers/net/can/Kconfig +++ b/drivers/net/can/Kconfig @@ -1,5 +1,25 @@ # SPDX-License-Identifier: GPL-2.0-only -menu "CAN Device Drivers" + +menuconfig CAN_DEV + tristate "CAN Device Drivers" + default y + help + Controller Area Network (CAN) is serial communications protocol up to + 1Mbit/s for its original release (now known as Classical CAN) and up + to 8Mbit/s for the more recent CAN with Flexible Data-Rate + (CAN-FD). The CAN bus was originally mainly for automotive, but is now + widely used in marine (NMEA2000), industrial, and medical + applications. More information on the CAN network protocol family + PF_CAN is contained in . + + This section contains all the CAN(-FD) device drivers including the + virtual ones. If you own such devices or plan to use the virtual CAN + interface to develop applications, say Y here. + + To compile as a module, choose M here: the module will be called + can-dev. + +if CAN_DEV config CAN_VCAN tristate "Virtual Local CAN Interface (vcan)" @@ -49,7 +69,7 @@ config CAN_SLCAN also be built as a module. If so, the module will be called slcan. config CAN_NETLINK - tristate "CAN device drivers with Netlink support" + bool "CAN device drivers with Netlink support" default y help Enables the common framework for CAN device drivers. This is the @@ -57,6 +77,9 @@ config CAN_NETLINK as bittiming validation, support of CAN error states, device restart and others. + The additional features selected by this option will be added to the + can-dev module. + This is required by all platform and hardware CAN drivers. If you plan to use such devices or if unsure, say Y. @@ -178,4 +201,4 @@ config CAN_DEBUG_DEVICES a problem with CAN support and want to see more of what is going on. -endmenu +endif #CAN_DEV diff --git a/drivers/net/can/dev/Makefile b/drivers/net/can/dev/Makefile index 5b4c813c6222..919f87e36eed 100644 --- a/drivers/net/can/dev/Makefile +++ b/drivers/net/can/dev/Makefile @@ -1,9 +1,11 @@ # SPDX-License-Identifier: GPL-2.0 -obj-$(CONFIG_CAN_NETLINK) += can-dev.o -can-dev-y += bittiming.o -can-dev-y += dev.o -can-dev-y += length.o -can-dev-y += netlink.o -can-dev-y += rx-offload.o -can-dev-y += skb.o +obj-$(CONFIG_CAN_DEV) += can-dev.o + +can-dev-$(CONFIG_CAN_DEV) += skb.o + +can-dev-$(CONFIG_CAN_NETLINK) += bittiming.o +can-dev-$(CONFIG_CAN_NETLINK) += dev.o +can-dev-$(CONFIG_CAN_NETLINK) += length.o +can-dev-$(CONFIG_CAN_NETLINK) += netlink.o +can-dev-$(CONFIG_CAN_NETLINK) += rx-offload.o diff --git a/drivers/net/can/dev/dev.c b/drivers/net/can/dev/dev.c index 96c9d9db00cf..523eaacfe29e 100644 --- a/drivers/net/can/dev/dev.c +++ b/drivers/net/can/dev/dev.c @@ -4,7 +4,6 @@ * Copyright (C) 2008-2009 Wolfgang Grandegger */ -#include #include #include #include @@ -17,12 +16,6 @@ #include #include -#define MOD_DESC "CAN device driver interface" - -MODULE_DESCRIPTION(MOD_DESC); -MODULE_LICENSE("GPL v2"); -MODULE_AUTHOR("Wolfgang Grandegger "); - static void can_update_state_error_stats(struct net_device *dev, enum can_state new_state) { @@ -513,7 +506,7 @@ static __init int can_dev_init(void) err = can_netlink_register(); if (!err) - pr_info(MOD_DESC "\n"); + pr_info("CAN device driver interface\n"); return err; } diff --git a/drivers/net/can/dev/skb.c b/drivers/net/can/dev/skb.c index 61660248c69e..a4208f125b76 100644 --- a/drivers/net/can/dev/skb.c +++ b/drivers/net/can/dev/skb.c @@ -5,6 +5,13 @@ */ #include +#include + +#define MOD_DESC "CAN device driver interface" + +MODULE_DESCRIPTION(MOD_DESC); +MODULE_LICENSE("GPL v2"); +MODULE_AUTHOR("Wolfgang Grandegger "); /* Local echo of CAN messages * From patchwork Fri Jun 3 10:28:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Mailhol X-Patchwork-Id: 12868960 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 520CECCA47D for ; Fri, 3 Jun 2022 10:30:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243773AbiFCKaO (ORCPT ); Fri, 3 Jun 2022 06:30:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243708AbiFCK3k (ORCPT ); Fri, 3 Jun 2022 06:29:40 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B3CA3BA49; Fri, 3 Jun 2022 03:29:38 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id p8so6882837pfh.8; Fri, 03 Jun 2022 03:29:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=seZ/vK2Paun+AFa3HY/XstatmRSNKp7fqezm8OsWy2A=; b=aTtkg8sRqpzOGMBpXloLNWTeTKYeNNNEtjSIue4k8wkRzu/FlBmCyIGL6y7B7hYtB/ tsRjA3oUoRsw9twoSqFAFU4vZFLLaY7AtVBNEE1NTRaXLLkSq3E385dWYDhSotiTma+r TUe0XAqI8+XICUeBjMwbEJxcT6IW3SJMULLdMee00fYorUCc3x3+6e4YU/G0Kb2Jgcwn BoYu+3AdczbAjE30GiDD28TG/1Gm0C8RNA/YOiEN3vH6b5C5LDw+MQBLvYatpPuwj1K8 tL4Y53j4FOytIWv/dqocrSS17XsQbXa7aX9rq2M5mpFw1rWFBZAXFcI8xJZn8BAqtJ0f uOCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=seZ/vK2Paun+AFa3HY/XstatmRSNKp7fqezm8OsWy2A=; b=JP0pHgZtCXHdo0VrGkxBCxFbWwWSqe0zv6HhFJS1HIXrsYDUABAl+29kkeIyI1+TQi qDYFXN9nAuTNE6/w/aZLUqIK4lhLV8itmXw8mO8yWud8SJlqdTCcIgFwm+fs2X7GOvw0 M/m07H19Z3bkHTmO/xC9vYi8XjGTvp/4PsdBhA3qeEjYqorn+5IdL4iBPBdUqmvllQQA v0rpsyGbg7tbmU2dpB+6PJN7BGKVObd/EZA8wLatZ+rQPBipPteADzxgCD4NiP//Cbdc rI3gkGLGgJ9Rp7fxRKsoWZYUL8z2iMj4ZdBXznOnz0LSCevM7PTqwueOlYl5k/nykc/R q6Cg== X-Gm-Message-State: AOAM530BL0Y3FRs2ENMRk7Y44aVOb22Paq3TfyKopGC7aAXKRr2PRZBl 17jKhX+SsvA/3zT35N3vIX7kxrwuYsTkBg== X-Google-Smtp-Source: ABdhPJw/xdFPGg65QluGEXvLCYfFxjR5ld0hwlSykJupV0e5gWhUVA6YsqtZlDNzxgEFfwfUhKcgjw== X-Received: by 2002:a05:6a00:2311:b0:4e1:52bf:e466 with SMTP id h17-20020a056a00231100b004e152bfe466mr19352930pfh.77.1654252178379; Fri, 03 Jun 2022 03:29:38 -0700 (PDT) Received: from localhost.localdomain (124x33x176x97.ap124.ftth.ucom.ne.jp. [124.33.176.97]) by smtp.gmail.com with ESMTPSA id b22-20020a056a0002d600b0050dc7628182sm3041676pft.92.2022.06.03.03.29.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 03:29:38 -0700 (PDT) Sender: Vincent Mailhol From: Vincent Mailhol To: Marc Kleine-Budde Cc: linux-can@vger.kernel.org, linux-kernel@vger.kernel.org, Max Staudt , Oliver Hartkopp , netdev@vger.kernel.org, Vincent Mailhol Subject: [PATCH v4 3/7] can: bittiming: move bittiming calculation functions to calc_bittiming.c Date: Fri, 3 Jun 2022 19:28:44 +0900 Message-Id: <20220603102848.17907-4-mailhol.vincent@wanadoo.fr> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220603102848.17907-1-mailhol.vincent@wanadoo.fr> References: <20220513142355.250389-1-mailhol.vincent@wanadoo.fr> <20220603102848.17907-1-mailhol.vincent@wanadoo.fr> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The canonical way to select or deselect an object during compilation is to use this pattern in the relevant Makefile: bar-$(CONFIG_FOO) := foo.o bittiming.c instead uses some #ifdef CONFIG_CAN_CALC_BITTIMG. Create a new file named calc_bittiming.c with all the functions which are conditionally compiled with CONFIG_CAN_CALC_BITTIMG and modify the Makefile according to above pattern. Signed-off-by: Vincent Mailhol --- drivers/net/can/Kconfig | 4 + drivers/net/can/dev/Makefile | 2 + drivers/net/can/dev/bittiming.c | 197 -------------------------- drivers/net/can/dev/calc_bittiming.c | 202 +++++++++++++++++++++++++++ 4 files changed, 208 insertions(+), 197 deletions(-) create mode 100644 drivers/net/can/dev/calc_bittiming.c diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig index b1e47f6c5586..8f3b97aea638 100644 --- a/drivers/net/can/Kconfig +++ b/drivers/net/can/Kconfig @@ -96,6 +96,10 @@ config CAN_CALC_BITTIMING source clock frequencies. Disabling saves some space, but then the bit-timing parameters must be specified directly using the Netlink arguments "tq", "prop_seg", "phase_seg1", "phase_seg2" and "sjw". + + The additional features selected by this option will be added to the + can-dev module. + If unsure, say Y. config CAN_AT91 diff --git a/drivers/net/can/dev/Makefile b/drivers/net/can/dev/Makefile index 919f87e36eed..b8a55b1d90cd 100644 --- a/drivers/net/can/dev/Makefile +++ b/drivers/net/can/dev/Makefile @@ -9,3 +9,5 @@ can-dev-$(CONFIG_CAN_NETLINK) += dev.o can-dev-$(CONFIG_CAN_NETLINK) += length.o can-dev-$(CONFIG_CAN_NETLINK) += netlink.o can-dev-$(CONFIG_CAN_NETLINK) += rx-offload.o + +can-dev-$(CONFIG_CAN_CALC_BITTIMING) += calc_bittiming.o diff --git a/drivers/net/can/dev/bittiming.c b/drivers/net/can/dev/bittiming.c index c1e76f0a5064..7ae80763c960 100644 --- a/drivers/net/can/dev/bittiming.c +++ b/drivers/net/can/dev/bittiming.c @@ -4,205 +4,8 @@ * Copyright (C) 2008-2009 Wolfgang Grandegger */ -#include #include -#ifdef CONFIG_CAN_CALC_BITTIMING -#define CAN_CALC_MAX_ERROR 50 /* in one-tenth of a percent */ - -/* Bit-timing calculation derived from: - * - * Code based on LinCAN sources and H8S2638 project - * Copyright 2004-2006 Pavel Pisa - DCE FELK CVUT cz - * Copyright 2005 Stanislav Marek - * email: pisa@cmp.felk.cvut.cz - * - * Calculates proper bit-timing parameters for a specified bit-rate - * and sample-point, which can then be used to set the bit-timing - * registers of the CAN controller. You can find more information - * in the header file linux/can/netlink.h. - */ -static int -can_update_sample_point(const struct can_bittiming_const *btc, - const unsigned int sample_point_nominal, const unsigned int tseg, - unsigned int *tseg1_ptr, unsigned int *tseg2_ptr, - unsigned int *sample_point_error_ptr) -{ - unsigned int sample_point_error, best_sample_point_error = UINT_MAX; - unsigned int sample_point, best_sample_point = 0; - unsigned int tseg1, tseg2; - int i; - - for (i = 0; i <= 1; i++) { - tseg2 = tseg + CAN_SYNC_SEG - - (sample_point_nominal * (tseg + CAN_SYNC_SEG)) / - 1000 - i; - tseg2 = clamp(tseg2, btc->tseg2_min, btc->tseg2_max); - tseg1 = tseg - tseg2; - if (tseg1 > btc->tseg1_max) { - tseg1 = btc->tseg1_max; - tseg2 = tseg - tseg1; - } - - sample_point = 1000 * (tseg + CAN_SYNC_SEG - tseg2) / - (tseg + CAN_SYNC_SEG); - sample_point_error = abs(sample_point_nominal - sample_point); - - if (sample_point <= sample_point_nominal && - sample_point_error < best_sample_point_error) { - best_sample_point = sample_point; - best_sample_point_error = sample_point_error; - *tseg1_ptr = tseg1; - *tseg2_ptr = tseg2; - } - } - - if (sample_point_error_ptr) - *sample_point_error_ptr = best_sample_point_error; - - return best_sample_point; -} - -int can_calc_bittiming(const struct net_device *dev, struct can_bittiming *bt, - const struct can_bittiming_const *btc) -{ - struct can_priv *priv = netdev_priv(dev); - unsigned int bitrate; /* current bitrate */ - unsigned int bitrate_error; /* difference between current and nominal value */ - unsigned int best_bitrate_error = UINT_MAX; - unsigned int sample_point_error; /* difference between current and nominal value */ - unsigned int best_sample_point_error = UINT_MAX; - unsigned int sample_point_nominal; /* nominal sample point */ - unsigned int best_tseg = 0; /* current best value for tseg */ - unsigned int best_brp = 0; /* current best value for brp */ - unsigned int brp, tsegall, tseg, tseg1 = 0, tseg2 = 0; - u64 v64; - - /* Use CiA recommended sample points */ - if (bt->sample_point) { - sample_point_nominal = bt->sample_point; - } else { - if (bt->bitrate > 800 * KILO /* BPS */) - sample_point_nominal = 750; - else if (bt->bitrate > 500 * KILO /* BPS */) - sample_point_nominal = 800; - else - sample_point_nominal = 875; - } - - /* tseg even = round down, odd = round up */ - for (tseg = (btc->tseg1_max + btc->tseg2_max) * 2 + 1; - tseg >= (btc->tseg1_min + btc->tseg2_min) * 2; tseg--) { - tsegall = CAN_SYNC_SEG + tseg / 2; - - /* Compute all possible tseg choices (tseg=tseg1+tseg2) */ - brp = priv->clock.freq / (tsegall * bt->bitrate) + tseg % 2; - - /* choose brp step which is possible in system */ - brp = (brp / btc->brp_inc) * btc->brp_inc; - if (brp < btc->brp_min || brp > btc->brp_max) - continue; - - bitrate = priv->clock.freq / (brp * tsegall); - bitrate_error = abs(bt->bitrate - bitrate); - - /* tseg brp biterror */ - if (bitrate_error > best_bitrate_error) - continue; - - /* reset sample point error if we have a better bitrate */ - if (bitrate_error < best_bitrate_error) - best_sample_point_error = UINT_MAX; - - can_update_sample_point(btc, sample_point_nominal, tseg / 2, - &tseg1, &tseg2, &sample_point_error); - if (sample_point_error >= best_sample_point_error) - continue; - - best_sample_point_error = sample_point_error; - best_bitrate_error = bitrate_error; - best_tseg = tseg / 2; - best_brp = brp; - - if (bitrate_error == 0 && sample_point_error == 0) - break; - } - - if (best_bitrate_error) { - /* Error in one-tenth of a percent */ - v64 = (u64)best_bitrate_error * 1000; - do_div(v64, bt->bitrate); - bitrate_error = (u32)v64; - if (bitrate_error > CAN_CALC_MAX_ERROR) { - netdev_err(dev, - "bitrate error %d.%d%% too high\n", - bitrate_error / 10, bitrate_error % 10); - return -EDOM; - } - netdev_warn(dev, "bitrate error %d.%d%%\n", - bitrate_error / 10, bitrate_error % 10); - } - - /* real sample point */ - bt->sample_point = can_update_sample_point(btc, sample_point_nominal, - best_tseg, &tseg1, &tseg2, - NULL); - - v64 = (u64)best_brp * 1000 * 1000 * 1000; - do_div(v64, priv->clock.freq); - bt->tq = (u32)v64; - bt->prop_seg = tseg1 / 2; - bt->phase_seg1 = tseg1 - bt->prop_seg; - bt->phase_seg2 = tseg2; - - /* check for sjw user settings */ - if (!bt->sjw || !btc->sjw_max) { - bt->sjw = 1; - } else { - /* bt->sjw is at least 1 -> sanitize upper bound to sjw_max */ - if (bt->sjw > btc->sjw_max) - bt->sjw = btc->sjw_max; - /* bt->sjw must not be higher than tseg2 */ - if (tseg2 < bt->sjw) - bt->sjw = tseg2; - } - - bt->brp = best_brp; - - /* real bitrate */ - bt->bitrate = priv->clock.freq / - (bt->brp * (CAN_SYNC_SEG + tseg1 + tseg2)); - - return 0; -} - -void can_calc_tdco(struct can_tdc *tdc, const struct can_tdc_const *tdc_const, - const struct can_bittiming *dbt, - u32 *ctrlmode, u32 ctrlmode_supported) - -{ - if (!tdc_const || !(ctrlmode_supported & CAN_CTRLMODE_TDC_AUTO)) - return; - - *ctrlmode &= ~CAN_CTRLMODE_TDC_MASK; - - /* As specified in ISO 11898-1 section 11.3.3 "Transmitter - * delay compensation" (TDC) is only applicable if data BRP is - * one or two. - */ - if (dbt->brp == 1 || dbt->brp == 2) { - /* Sample point in clock periods */ - u32 sample_point_in_tc = (CAN_SYNC_SEG + dbt->prop_seg + - dbt->phase_seg1) * dbt->brp; - - if (sample_point_in_tc < tdc_const->tdco_min) - return; - tdc->tdco = min(sample_point_in_tc, tdc_const->tdco_max); - *ctrlmode |= CAN_CTRLMODE_TDC_AUTO; - } -} -#endif /* CONFIG_CAN_CALC_BITTIMING */ - /* Checks the validity of the specified bit-timing parameters prop_seg, * phase_seg1, phase_seg2 and sjw and tries to determine the bitrate * prescaler value brp. You can find more information in the header diff --git a/drivers/net/can/dev/calc_bittiming.c b/drivers/net/can/dev/calc_bittiming.c new file mode 100644 index 000000000000..d3caa040614d --- /dev/null +++ b/drivers/net/can/dev/calc_bittiming.c @@ -0,0 +1,202 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (C) 2005 Marc Kleine-Budde, Pengutronix + * Copyright (C) 2006 Andrey Volkov, Varma Electronics + * Copyright (C) 2008-2009 Wolfgang Grandegger + */ + +#include +#include + +#define CAN_CALC_MAX_ERROR 50 /* in one-tenth of a percent */ + +/* Bit-timing calculation derived from: + * + * Code based on LinCAN sources and H8S2638 project + * Copyright 2004-2006 Pavel Pisa - DCE FELK CVUT cz + * Copyright 2005 Stanislav Marek + * email: pisa@cmp.felk.cvut.cz + * + * Calculates proper bit-timing parameters for a specified bit-rate + * and sample-point, which can then be used to set the bit-timing + * registers of the CAN controller. You can find more information + * in the header file linux/can/netlink.h. + */ +static int +can_update_sample_point(const struct can_bittiming_const *btc, + const unsigned int sample_point_nominal, const unsigned int tseg, + unsigned int *tseg1_ptr, unsigned int *tseg2_ptr, + unsigned int *sample_point_error_ptr) +{ + unsigned int sample_point_error, best_sample_point_error = UINT_MAX; + unsigned int sample_point, best_sample_point = 0; + unsigned int tseg1, tseg2; + int i; + + for (i = 0; i <= 1; i++) { + tseg2 = tseg + CAN_SYNC_SEG - + (sample_point_nominal * (tseg + CAN_SYNC_SEG)) / + 1000 - i; + tseg2 = clamp(tseg2, btc->tseg2_min, btc->tseg2_max); + tseg1 = tseg - tseg2; + if (tseg1 > btc->tseg1_max) { + tseg1 = btc->tseg1_max; + tseg2 = tseg - tseg1; + } + + sample_point = 1000 * (tseg + CAN_SYNC_SEG - tseg2) / + (tseg + CAN_SYNC_SEG); + sample_point_error = abs(sample_point_nominal - sample_point); + + if (sample_point <= sample_point_nominal && + sample_point_error < best_sample_point_error) { + best_sample_point = sample_point; + best_sample_point_error = sample_point_error; + *tseg1_ptr = tseg1; + *tseg2_ptr = tseg2; + } + } + + if (sample_point_error_ptr) + *sample_point_error_ptr = best_sample_point_error; + + return best_sample_point; +} + +int can_calc_bittiming(const struct net_device *dev, struct can_bittiming *bt, + const struct can_bittiming_const *btc) +{ + struct can_priv *priv = netdev_priv(dev); + unsigned int bitrate; /* current bitrate */ + unsigned int bitrate_error; /* difference between current and nominal value */ + unsigned int best_bitrate_error = UINT_MAX; + unsigned int sample_point_error; /* difference between current and nominal value */ + unsigned int best_sample_point_error = UINT_MAX; + unsigned int sample_point_nominal; /* nominal sample point */ + unsigned int best_tseg = 0; /* current best value for tseg */ + unsigned int best_brp = 0; /* current best value for brp */ + unsigned int brp, tsegall, tseg, tseg1 = 0, tseg2 = 0; + u64 v64; + + /* Use CiA recommended sample points */ + if (bt->sample_point) { + sample_point_nominal = bt->sample_point; + } else { + if (bt->bitrate > 800 * KILO /* BPS */) + sample_point_nominal = 750; + else if (bt->bitrate > 500 * KILO /* BPS */) + sample_point_nominal = 800; + else + sample_point_nominal = 875; + } + + /* tseg even = round down, odd = round up */ + for (tseg = (btc->tseg1_max + btc->tseg2_max) * 2 + 1; + tseg >= (btc->tseg1_min + btc->tseg2_min) * 2; tseg--) { + tsegall = CAN_SYNC_SEG + tseg / 2; + + /* Compute all possible tseg choices (tseg=tseg1+tseg2) */ + brp = priv->clock.freq / (tsegall * bt->bitrate) + tseg % 2; + + /* choose brp step which is possible in system */ + brp = (brp / btc->brp_inc) * btc->brp_inc; + if (brp < btc->brp_min || brp > btc->brp_max) + continue; + + bitrate = priv->clock.freq / (brp * tsegall); + bitrate_error = abs(bt->bitrate - bitrate); + + /* tseg brp biterror */ + if (bitrate_error > best_bitrate_error) + continue; + + /* reset sample point error if we have a better bitrate */ + if (bitrate_error < best_bitrate_error) + best_sample_point_error = UINT_MAX; + + can_update_sample_point(btc, sample_point_nominal, tseg / 2, + &tseg1, &tseg2, &sample_point_error); + if (sample_point_error >= best_sample_point_error) + continue; + + best_sample_point_error = sample_point_error; + best_bitrate_error = bitrate_error; + best_tseg = tseg / 2; + best_brp = brp; + + if (bitrate_error == 0 && sample_point_error == 0) + break; + } + + if (best_bitrate_error) { + /* Error in one-tenth of a percent */ + v64 = (u64)best_bitrate_error * 1000; + do_div(v64, bt->bitrate); + bitrate_error = (u32)v64; + if (bitrate_error > CAN_CALC_MAX_ERROR) { + netdev_err(dev, + "bitrate error %d.%d%% too high\n", + bitrate_error / 10, bitrate_error % 10); + return -EDOM; + } + netdev_warn(dev, "bitrate error %d.%d%%\n", + bitrate_error / 10, bitrate_error % 10); + } + + /* real sample point */ + bt->sample_point = can_update_sample_point(btc, sample_point_nominal, + best_tseg, &tseg1, &tseg2, + NULL); + + v64 = (u64)best_brp * 1000 * 1000 * 1000; + do_div(v64, priv->clock.freq); + bt->tq = (u32)v64; + bt->prop_seg = tseg1 / 2; + bt->phase_seg1 = tseg1 - bt->prop_seg; + bt->phase_seg2 = tseg2; + + /* check for sjw user settings */ + if (!bt->sjw || !btc->sjw_max) { + bt->sjw = 1; + } else { + /* bt->sjw is at least 1 -> sanitize upper bound to sjw_max */ + if (bt->sjw > btc->sjw_max) + bt->sjw = btc->sjw_max; + /* bt->sjw must not be higher than tseg2 */ + if (tseg2 < bt->sjw) + bt->sjw = tseg2; + } + + bt->brp = best_brp; + + /* real bitrate */ + bt->bitrate = priv->clock.freq / + (bt->brp * (CAN_SYNC_SEG + tseg1 + tseg2)); + + return 0; +} + +void can_calc_tdco(struct can_tdc *tdc, const struct can_tdc_const *tdc_const, + const struct can_bittiming *dbt, + u32 *ctrlmode, u32 ctrlmode_supported) + +{ + if (!tdc_const || !(ctrlmode_supported & CAN_CTRLMODE_TDC_AUTO)) + return; + + *ctrlmode &= ~CAN_CTRLMODE_TDC_MASK; + + /* As specified in ISO 11898-1 section 11.3.3 "Transmitter + * delay compensation" (TDC) is only applicable if data BRP is + * one or two. + */ + if (dbt->brp == 1 || dbt->brp == 2) { + /* Sample point in clock periods */ + u32 sample_point_in_tc = (CAN_SYNC_SEG + dbt->prop_seg + + dbt->phase_seg1) * dbt->brp; + + if (sample_point_in_tc < tdc_const->tdco_min) + return; + tdc->tdco = min(sample_point_in_tc, tdc_const->tdco_max); + *ctrlmode |= CAN_CTRLMODE_TDC_AUTO; + } +} From patchwork Fri Jun 3 10:28:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Mailhol X-Patchwork-Id: 12868957 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B379C43334 for ; Fri, 3 Jun 2022 10:30:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243704AbiFCKaI (ORCPT ); Fri, 3 Jun 2022 06:30:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243662AbiFCK3w (ORCPT ); Fri, 3 Jun 2022 06:29:52 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6DEC3BA48; Fri, 3 Jun 2022 03:29:50 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id c196so6904246pfb.1; Fri, 03 Jun 2022 03:29:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JfOXhlCk1wDpEvOOv4BaJTA7xSnTCyIJZTqst+9NdFc=; b=R//XEZ0n3L62QgxG5CxntfyT6wiYLXj6NeK9h9hGIAVh/wdxVfyB2YKwR6kW1NjYwO MD3CAsT4O9BzZBGdzqydxE1WwXNiVa3YVe7/og4oDyoedRkBBqYgaNlXzppzexmasaXo XDZMDnWNGyDJE6xXsteOAfr6utyW6lsk7NypnFAAD9ASH7vEeu6u0qRrK9S21vLRZDxX YyuVk701mHs8DS1ghEyNatCKEoc215x1DHNdewX/amPpNA7+J34kk+JPOLEUD/SXdzk+ SoZElLw9UCb94wiIZQZm0PfJaChlsmhWwN+b4BMEaIwkl8ohetawIbwoqP6Awaw/giGC 9rlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=JfOXhlCk1wDpEvOOv4BaJTA7xSnTCyIJZTqst+9NdFc=; b=FQzSuW3U3OjHbSWc4zG5jWECW6oB2BJxE6KAWkoLdF4PH5PXVxcbbQc4nn8UnDBOl0 egmCP9vB2CQ0Wz4xgboeBqpFAPENpU2y8qpFw7gna4P4cyYIStFLXR+qgKuRDI4+JYoD +a7I0jm2UjY2eCKnPhj+ab14PPy8X54++Rh66T+e/MN4E2LJbsFs+uVWUxOIbnze2Z5S k3oX43oDnv4FkIvdZ93Rn3kTqtH1J1YOvyz91hlFNJiGJf22tJJz7kBOmDHJIm25NVDY tUzy8zMs09pJOWw3uTQco+xo1cTL+9uu0vsn06cy+aLYRHHDH1I0MwsGu5rbFlV4dqz+ MNVQ== X-Gm-Message-State: AOAM533TsGRpjKw9+dZHln3cVwX1Gx0U1R1nVqhZxIuaZy8ZMuZSrmT/ oDrK/EslBTVhhGJ6b1ni/JA= X-Google-Smtp-Source: ABdhPJw26b1830Lj+1FQek2f5WIhVINc26oWfi+u3qZ/GkdCdBOcY2KY1SxFSjJYjU5jukykHbjx4g== X-Received: by 2002:a62:be14:0:b0:505:a43b:cf6e with SMTP id l20-20020a62be14000000b00505a43bcf6emr76935857pff.33.1654252190417; Fri, 03 Jun 2022 03:29:50 -0700 (PDT) Received: from localhost.localdomain (124x33x176x97.ap124.ftth.ucom.ne.jp. [124.33.176.97]) by smtp.gmail.com with ESMTPSA id b22-20020a056a0002d600b0050dc7628182sm3041676pft.92.2022.06.03.03.29.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 03:29:50 -0700 (PDT) Sender: Vincent Mailhol From: Vincent Mailhol To: Marc Kleine-Budde Cc: linux-can@vger.kernel.org, linux-kernel@vger.kernel.org, Max Staudt , Oliver Hartkopp , netdev@vger.kernel.org, Vincent Mailhol Subject: [PATCH v4 4/7] can: Kconfig: add CONFIG_CAN_RX_OFFLOAD Date: Fri, 3 Jun 2022 19:28:45 +0900 Message-Id: <20220603102848.17907-5-mailhol.vincent@wanadoo.fr> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220603102848.17907-1-mailhol.vincent@wanadoo.fr> References: <20220513142355.250389-1-mailhol.vincent@wanadoo.fr> <20220603102848.17907-1-mailhol.vincent@wanadoo.fr> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Only a few drivers rely on the CAN rx offload framework (as of the writing of this patch, only three: flexcan, ti_hecc and mcp251xfd). Give the option to the user to deselect this features during compilation. The drivers relying on CAN rx offload are in different sub folders. All of these drivers get tagged with "select CAN_RX_OFFLOAD" so that the option is automatically enabled whenever one of those driver is chosen. Signed-off-by: Vincent Mailhol --- drivers/net/can/Kconfig | 16 ++++++++++++++++ drivers/net/can/dev/Makefile | 2 ++ drivers/net/can/spi/mcp251xfd/Kconfig | 1 + 3 files changed, 19 insertions(+) diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig index 8f3b97aea638..1f1d81da1c8c 100644 --- a/drivers/net/can/Kconfig +++ b/drivers/net/can/Kconfig @@ -102,6 +102,20 @@ config CAN_CALC_BITTIMING If unsure, say Y. +config CAN_RX_OFFLOAD + bool "CAN RX offload" + default y + help + Framework to offload the controller's RX FIFO during one + interrupt. The CAN frames of the FIFO are read and put into a skb + queue during that interrupt and transmitted afterwards in a NAPI + context. + + The additional features selected by this option will be added to the + can-dev module. + + If unsure, say Y. + config CAN_AT91 tristate "Atmel AT91 onchip CAN controller" depends on (ARCH_AT91 || COMPILE_TEST) && HAS_IOMEM @@ -113,6 +127,7 @@ config CAN_FLEXCAN tristate "Support for Freescale FLEXCAN based chips" depends on OF || COLDFIRE || COMPILE_TEST depends on HAS_IOMEM + select CAN_RX_OFFLOAD help Say Y here if you want to support for Freescale FlexCAN. @@ -162,6 +177,7 @@ config CAN_SUN4I config CAN_TI_HECC depends on ARM tristate "TI High End CAN Controller" + select CAN_RX_OFFLOAD help Driver for TI HECC (High End CAN Controller) module found on many TI devices. The device specifications are available from www.ti.com diff --git a/drivers/net/can/dev/Makefile b/drivers/net/can/dev/Makefile index b8a55b1d90cd..5081d8a3be57 100644 --- a/drivers/net/can/dev/Makefile +++ b/drivers/net/can/dev/Makefile @@ -11,3 +11,5 @@ can-dev-$(CONFIG_CAN_NETLINK) += netlink.o can-dev-$(CONFIG_CAN_NETLINK) += rx-offload.o can-dev-$(CONFIG_CAN_CALC_BITTIMING) += calc_bittiming.o + +can-dev-$(CONFIG_CAN_RX_OFFLOAD) += rx-offload.o diff --git a/drivers/net/can/spi/mcp251xfd/Kconfig b/drivers/net/can/spi/mcp251xfd/Kconfig index dd0fc0a54be1..877e4356010d 100644 --- a/drivers/net/can/spi/mcp251xfd/Kconfig +++ b/drivers/net/can/spi/mcp251xfd/Kconfig @@ -2,6 +2,7 @@ config CAN_MCP251XFD tristate "Microchip MCP251xFD SPI CAN controllers" + select CAN_RX_OFFLOAD select REGMAP select WANT_DEV_COREDUMP help From patchwork Fri Jun 3 10:28:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Mailhol X-Patchwork-Id: 12868959 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03484CCA473 for ; Fri, 3 Jun 2022 10:30:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243769AbiFCKaL (ORCPT ); Fri, 3 Jun 2022 06:30:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243719AbiFCK35 (ORCPT ); Fri, 3 Jun 2022 06:29:57 -0400 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FDBD3BA43; Fri, 3 Jun 2022 03:29:56 -0700 (PDT) Received: by mail-pg1-x533.google.com with SMTP id c14so6870614pgu.13; Fri, 03 Jun 2022 03:29:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0Xl6xu0Aw25nnxFjpI/ytCht+0ZMiXtWlwE+X5IO8Rw=; b=cH0fbl6gjR8G2h0T06PeQ48eHX+R4+HoCrYF+3y4VdM3+ZoYizHOh9iBwlijNo4EKo L3gXnroQWbHI/nTFzDDulkL3VccduQ8TtEWA0hDF25/Nf1ujpySz+0agM8TB2v/Ksh9R lLqlyiUjUjNvNpfxXzoQdLeOi3S1zjB4UwMUilRxPUQnKr1Ge26ctDuk8dd3k6ms2pGX L9o9OpEjVHMlkQaI/3Ryyr9EQc4ah3PFUdPf9K4fjILPr+HX9UmauQuVl5vCq4uPBJnw /6eIBnw2LCBJEM8jIQwIZRoQWL6hsMyjmFK2NNbiAVfaZuS49RWqSDDYg7eUAPAP6in5 2FvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=0Xl6xu0Aw25nnxFjpI/ytCht+0ZMiXtWlwE+X5IO8Rw=; b=inoObU1yMeisw7nkkr/aPXhQMA1TZxYmgN8Di36Wxx0xl0rEtJa4LW5E/96xUoADmI 99WjoiN7hagCNFObl8DMaN9NcyA31cAxVV+WN/XBQ6Bqj6ZRSDIxHLiTFGjZJFNhD/ih rqc8M3/L89FufuC+t+nn2+j8V/lMwuB/rtUzDQ2t1U0BzGlwoUi9rVzDEOWkzDRiG3bN sdSSOGgB+eYoj56Kbbkk/ySwd4mFAWMzZ3SIPi9gQTjdlxc2DMPSrqVo2FUjBPyKSVpg k09P3gNfI7/r1nHlxXBAjFAlgmw5wkxje7IfBIWJp98JjpjooZ+YFDFNaxFRSwklpSSs /I0A== X-Gm-Message-State: AOAM5314ClbxxAABzx1AA9qXfEZzmAPHNiGk/LhLXOI0u3RIn7oFEpmE 1P/bYZTIXCMuHJmo2z4GVTY= X-Google-Smtp-Source: ABdhPJyqR9UwyNCCAVCui8LXCFOIVVG40hhX79nLDfF9eT69veYyiVFukEK2JlvpAFncfA8+zQ+pcA== X-Received: by 2002:a63:1c7:0:b0:3fb:cff3:f327 with SMTP id 190-20020a6301c7000000b003fbcff3f327mr8225710pgb.571.1654252195996; Fri, 03 Jun 2022 03:29:55 -0700 (PDT) Received: from localhost.localdomain (124x33x176x97.ap124.ftth.ucom.ne.jp. [124.33.176.97]) by smtp.gmail.com with ESMTPSA id b22-20020a056a0002d600b0050dc7628182sm3041676pft.92.2022.06.03.03.29.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 03:29:55 -0700 (PDT) Sender: Vincent Mailhol From: Vincent Mailhol To: Marc Kleine-Budde Cc: linux-can@vger.kernel.org, linux-kernel@vger.kernel.org, Max Staudt , Oliver Hartkopp , netdev@vger.kernel.org, Vincent Mailhol Subject: [PATCH v4 5/7] net: Kconfig: move the CAN device menu to the "Device Drivers" section Date: Fri, 3 Jun 2022 19:28:46 +0900 Message-Id: <20220603102848.17907-6-mailhol.vincent@wanadoo.fr> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220603102848.17907-1-mailhol.vincent@wanadoo.fr> References: <20220513142355.250389-1-mailhol.vincent@wanadoo.fr> <20220603102848.17907-1-mailhol.vincent@wanadoo.fr> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The devices are meant to be under the "Device Drivers" category of the menuconfig. The CAN subsystem is currently one of the rare exception with all of its devices under the "Networking support" category. The CAN_DEV menuentry gets moved to fix this discrepancy. The CAN menu is added just before MCTP in order to be consistent with the current order under the "Networking support" menu. A dependency on CAN is added to CAN_DEV so that the CAN devices only show up if the CAN subsystem is enabled. Signed-off-by: Vincent Mailhol --- drivers/net/Kconfig | 2 ++ drivers/net/can/Kconfig | 1 + net/can/Kconfig | 5 ++--- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index b2a4f998c180..5de243899de8 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig @@ -499,6 +499,8 @@ config NET_SB1000 source "drivers/net/phy/Kconfig" +source "drivers/net/can/Kconfig" + source "drivers/net/mctp/Kconfig" source "drivers/net/mdio/Kconfig" diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig index 1f1d81da1c8c..4ab80507c353 100644 --- a/drivers/net/can/Kconfig +++ b/drivers/net/can/Kconfig @@ -3,6 +3,7 @@ menuconfig CAN_DEV tristate "CAN Device Drivers" default y + depends on CAN help Controller Area Network (CAN) is serial communications protocol up to 1Mbit/s for its original release (now known as Classical CAN) and up diff --git a/net/can/Kconfig b/net/can/Kconfig index a9ac5ffab286..cb56be8e3862 100644 --- a/net/can/Kconfig +++ b/net/can/Kconfig @@ -15,7 +15,8 @@ menuconfig CAN PF_CAN is contained in . If you want CAN support you should say Y here and also to the - specific driver for your controller(s) below. + specific driver for your controller(s) under the Network device + support section. if CAN @@ -69,6 +70,4 @@ config CAN_ISOTP If you want to perform automotive vehicle diagnostic services (UDS), say 'y'. -source "drivers/net/can/Kconfig" - endif From patchwork Fri Jun 3 10:28:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Mailhol X-Patchwork-Id: 12868958 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3ACDEC433EF for ; Fri, 3 Jun 2022 10:30:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243717AbiFCKaK (ORCPT ); Fri, 3 Jun 2022 06:30:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243754AbiFCKaC (ORCPT ); Fri, 3 Jun 2022 06:30:02 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D64373B3F8; Fri, 3 Jun 2022 03:30:01 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id v5-20020a17090a7c0500b001df84fa82f8so6879204pjf.5; Fri, 03 Jun 2022 03:30:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DtyJJKEsghPLjxhbcwewtXs5m8PoND73ufSOi5mUhFM=; b=JjthMgwC8pCsQxgG0JIVoJwNJkUWb+BSKkF0O0f9wo8O5Hr3koHaeEXGddHZTdSwp2 cb9QAE9sZd5DGNpahvcc+mIXNmAOdicHgxdEzVbkuJXQIFRIqtCsMIXzqSe42pIXRZQe Kb0WUAQBCv/CM3bClty1fb1VrKxHBCnTqziKlFV9ga5+swB/KEV4u1uce+5/SEEiI3Rk LT1NhBzVdCzDXRALiK5stzqWno8TbR+ZUFWCeNDt08dYKXKA9D6q4/DQR6FpP5dFu/PN UI4E3EY9Bl6Oj/z2+gl6vYCnfqBmN/NXjnJ6QNs6M8pkcRHnYN+RGcNqGTKhIqacsrIy gmKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=DtyJJKEsghPLjxhbcwewtXs5m8PoND73ufSOi5mUhFM=; b=Igg9zlBuPidEZQXO2osRfWdtu7w386bNEJHSu7tE0MKtSbPEosgX2kB00BZ6JAuX5N m154hW8WrCJYUvKJ+QMKP+1Qkucn7yjddUZUtXDyIMcCDo6jxxDXquuORmu0BI/1R44e TrMR4KKnPmp97UqJLEZbmnOhUExHYZWwPDTqA2cn4Qnz6V62CaOV8gU8Lvbyg7239pTX 7C3ZL5mye5eHZGo9eniA7VsCUNxawQKrlZHMh0YvjKyFMAhGb3taFaJ+SykDTAR/RmLl 0pI9WC0P0WYTxEtS8+ENvqk2oKXKygmZQSJPIcFP2EI0FumpoaW1mJi5d7XCnc0f+JAa X9wQ== X-Gm-Message-State: AOAM532lmiHxTm8Jyzlk6L770iUFeYgHU0ORn4Ye0Wermv5VmDQ8bgp3 1lLGKQs3M86PdEU0Ud5bbhk1Rmx4mzFApg== X-Google-Smtp-Source: ABdhPJy9qLAKWYgZ8H7P/5rcMVD8IxY3JJDy1d9bMAaJic6xgN8+E+XqjIyx7q/9QHMPYBly4OUd9w== X-Received: by 2002:a17:903:244f:b0:162:4daf:f8bb with SMTP id l15-20020a170903244f00b001624daff8bbmr9780689pls.20.1654252201329; Fri, 03 Jun 2022 03:30:01 -0700 (PDT) Received: from localhost.localdomain (124x33x176x97.ap124.ftth.ucom.ne.jp. [124.33.176.97]) by smtp.gmail.com with ESMTPSA id b22-20020a056a0002d600b0050dc7628182sm3041676pft.92.2022.06.03.03.29.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 03:30:01 -0700 (PDT) Sender: Vincent Mailhol From: Vincent Mailhol To: Marc Kleine-Budde Cc: linux-can@vger.kernel.org, linux-kernel@vger.kernel.org, Max Staudt , Oliver Hartkopp , netdev@vger.kernel.org, Vincent Mailhol Subject: [PATCH v4 6/7] can: skb: move can_dropped_invalid_skb() and can_skb_headroom_valid() to skb.c Date: Fri, 3 Jun 2022 19:28:47 +0900 Message-Id: <20220603102848.17907-7-mailhol.vincent@wanadoo.fr> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220603102848.17907-1-mailhol.vincent@wanadoo.fr> References: <20220513142355.250389-1-mailhol.vincent@wanadoo.fr> <20220603102848.17907-1-mailhol.vincent@wanadoo.fr> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The functions can_dropped_invalid_skb() and can_skb_headroom_valid() grew a lot over the years to a point which it does not make much sense to have them defined as static inline in header files. Move those two functions to the .c counterpart of skb.h. can_skb_headroom_valid() only caller being can_dropped_invalid_skb(), the declaration is removed from the header. Only can_dropped_invalid_skb() gets its symbol exported. While doing so, do a small cleanup: add brackets around the else block in can_dropped_invalid_skb(). Signed-off-by: Vincent Mailhol --- drivers/net/can/dev/skb.c | 58 ++++++++++++++++++++++++++++++++++++++ include/linux/can/skb.h | 59 +-------------------------------------- 2 files changed, 59 insertions(+), 58 deletions(-) diff --git a/drivers/net/can/dev/skb.c b/drivers/net/can/dev/skb.c index a4208f125b76..dc9da76c0470 100644 --- a/drivers/net/can/dev/skb.c +++ b/drivers/net/can/dev/skb.c @@ -259,3 +259,61 @@ struct sk_buff *alloc_can_err_skb(struct net_device *dev, struct can_frame **cf) return skb; } EXPORT_SYMBOL_GPL(alloc_can_err_skb); + +/* Check for outgoing skbs that have not been created by the CAN subsystem */ +static bool can_skb_headroom_valid(struct net_device *dev, struct sk_buff *skb) +{ + /* af_packet creates a headroom of HH_DATA_MOD bytes which is fine */ + if (WARN_ON_ONCE(skb_headroom(skb) < sizeof(struct can_skb_priv))) + return false; + + /* af_packet does not apply CAN skb specific settings */ + if (skb->ip_summed == CHECKSUM_NONE) { + /* init headroom */ + can_skb_prv(skb)->ifindex = dev->ifindex; + can_skb_prv(skb)->skbcnt = 0; + + skb->ip_summed = CHECKSUM_UNNECESSARY; + + /* perform proper loopback on capable devices */ + if (dev->flags & IFF_ECHO) + skb->pkt_type = PACKET_LOOPBACK; + else + skb->pkt_type = PACKET_HOST; + + skb_reset_mac_header(skb); + skb_reset_network_header(skb); + skb_reset_transport_header(skb); + } + + return true; +} + +/* Drop a given socketbuffer if it does not contain a valid CAN frame. */ +bool can_dropped_invalid_skb(struct net_device *dev, struct sk_buff *skb) +{ + const struct canfd_frame *cfd = (struct canfd_frame *)skb->data; + + if (skb->protocol == htons(ETH_P_CAN)) { + if (unlikely(skb->len != CAN_MTU || + cfd->len > CAN_MAX_DLEN)) + goto inval_skb; + } else if (skb->protocol == htons(ETH_P_CANFD)) { + if (unlikely(skb->len != CANFD_MTU || + cfd->len > CANFD_MAX_DLEN)) + goto inval_skb; + } else { + goto inval_skb; + } + + if (!can_skb_headroom_valid(dev, skb)) + goto inval_skb; + + return false; + +inval_skb: + kfree_skb(skb); + dev->stats.tx_dropped++; + return true; +} +EXPORT_SYMBOL_GPL(can_dropped_invalid_skb); diff --git a/include/linux/can/skb.h b/include/linux/can/skb.h index fdb22b00674a..182749e858b3 100644 --- a/include/linux/can/skb.h +++ b/include/linux/can/skb.h @@ -31,6 +31,7 @@ struct sk_buff *alloc_canfd_skb(struct net_device *dev, struct canfd_frame **cfd); struct sk_buff *alloc_can_err_skb(struct net_device *dev, struct can_frame **cf); +bool can_dropped_invalid_skb(struct net_device *dev, struct sk_buff *skb); /* * The struct can_skb_priv is used to transport additional information along @@ -96,64 +97,6 @@ static inline struct sk_buff *can_create_echo_skb(struct sk_buff *skb) return nskb; } -/* Check for outgoing skbs that have not been created by the CAN subsystem */ -static inline bool can_skb_headroom_valid(struct net_device *dev, - struct sk_buff *skb) -{ - /* af_packet creates a headroom of HH_DATA_MOD bytes which is fine */ - if (WARN_ON_ONCE(skb_headroom(skb) < sizeof(struct can_skb_priv))) - return false; - - /* af_packet does not apply CAN skb specific settings */ - if (skb->ip_summed == CHECKSUM_NONE) { - /* init headroom */ - can_skb_prv(skb)->ifindex = dev->ifindex; - can_skb_prv(skb)->skbcnt = 0; - - skb->ip_summed = CHECKSUM_UNNECESSARY; - - /* perform proper loopback on capable devices */ - if (dev->flags & IFF_ECHO) - skb->pkt_type = PACKET_LOOPBACK; - else - skb->pkt_type = PACKET_HOST; - - skb_reset_mac_header(skb); - skb_reset_network_header(skb); - skb_reset_transport_header(skb); - } - - return true; -} - -/* Drop a given socketbuffer if it does not contain a valid CAN frame. */ -static inline bool can_dropped_invalid_skb(struct net_device *dev, - struct sk_buff *skb) -{ - const struct canfd_frame *cfd = (struct canfd_frame *)skb->data; - - if (skb->protocol == htons(ETH_P_CAN)) { - if (unlikely(skb->len != CAN_MTU || - cfd->len > CAN_MAX_DLEN)) - goto inval_skb; - } else if (skb->protocol == htons(ETH_P_CANFD)) { - if (unlikely(skb->len != CANFD_MTU || - cfd->len > CANFD_MAX_DLEN)) - goto inval_skb; - } else - goto inval_skb; - - if (!can_skb_headroom_valid(dev, skb)) - goto inval_skb; - - return false; - -inval_skb: - kfree_skb(skb); - dev->stats.tx_dropped++; - return true; -} - static inline bool can_is_canfd_skb(const struct sk_buff *skb) { /* the CAN specific type of skb is identified by its data length */ From patchwork Fri Jun 3 10:28:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Mailhol X-Patchwork-Id: 12868961 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D087C43334 for ; Fri, 3 Jun 2022 10:31:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243737AbiFCKat (ORCPT ); Fri, 3 Jun 2022 06:30:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243703AbiFCKaH (ORCPT ); Fri, 3 Jun 2022 06:30:07 -0400 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A3283B3F8; Fri, 3 Jun 2022 03:30:06 -0700 (PDT) Received: by mail-pg1-x52b.google.com with SMTP id g184so6924325pgc.1; Fri, 03 Jun 2022 03:30:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wPNc3YvhAKuZLbvOFj+YsMRBSINjKQKB6Tw7aOecxnY=; b=fjr/YLTf3JpqKnGPXEQKWeEulEUL8Cbj+DXC0/q/+SmEvIEwQN+MSO/KtRcHNn0rJk eUSFlvhs5UgDYRyVN6rLyBer6rEPqmDE2tWw0YhIlwI3hJF5s4IjVSjWuKp1DyE6Qz5B y3VUQgTdrgZeU1+9bWiD3+4oWVieffOuFQe3azHhxy7kbM/UeatWVzSobWW8fspD4xSE lipg7a4myWbMi/MShhgm8UgYmzPZs3TZkXW9bsqyygYlEkwQlOkjUejz/VhjO+8eJ3ET 7WHn+dgANiC/saQ2YKliXM6bmBHpSH16MpatSgt4+vh+jwuZyRyekz6kP5htvHuvbj6x fSIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=wPNc3YvhAKuZLbvOFj+YsMRBSINjKQKB6Tw7aOecxnY=; b=BuKQltO/EsD8CWvtXvzwTcvPBYGMR7UO9NhLVYbIZ7rCDSw1B1fgFl68KVyzLnujvL wRUWJQ4pgaD6NartZWr5S7UuqpvSBTVG6g6tExGW5L5NFCiSXzO3v7UbgOsLpkgEJg7U x9WxEs4T49FPEZv+E+9g7o4jeefjBIDz5lBciCcOgFUr7StTDbQHHQxXNOSuE5A69CAy UJd5eIK5cmAYejQX1X4n6EIkPtYN/5vPtGu5ukYmzahI3SZNbCfTtiMAkSOYgvNnQ8+C yXx8h4J9UPWM7x7R2sa49JXKT3X2htvrck16yQ/d5jlpswwILb6Z+6xiSqvGYgCmHCct zpwA== X-Gm-Message-State: AOAM530XAQGGCw1laRJLv/7Y+fL3K/DET3rneZVGyNTbVckUJtrFEy/E DeKLwM3htbCBZb0GS/7IZoQ= X-Google-Smtp-Source: ABdhPJxRZSY2Y41lUKakBuNRWE1suXBEeYOsiKYabI9XVLbzYny3MxFQlKEPpazCvwmDmlnK5iF7ZA== X-Received: by 2002:a05:6a00:1c4e:b0:51b:ebf1:53c4 with SMTP id s14-20020a056a001c4e00b0051bebf153c4mr492238pfw.49.1654252205674; Fri, 03 Jun 2022 03:30:05 -0700 (PDT) Received: from localhost.localdomain (124x33x176x97.ap124.ftth.ucom.ne.jp. [124.33.176.97]) by smtp.gmail.com with ESMTPSA id b22-20020a056a0002d600b0050dc7628182sm3041676pft.92.2022.06.03.03.30.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 03:30:05 -0700 (PDT) Sender: Vincent Mailhol From: Vincent Mailhol To: Marc Kleine-Budde Cc: linux-can@vger.kernel.org, linux-kernel@vger.kernel.org, Max Staudt , Oliver Hartkopp , netdev@vger.kernel.org, Vincent Mailhol Subject: [PATCH v4 7/7] can: skb: drop tx skb if in listen only mode Date: Fri, 3 Jun 2022 19:28:48 +0900 Message-Id: <20220603102848.17907-8-mailhol.vincent@wanadoo.fr> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220603102848.17907-1-mailhol.vincent@wanadoo.fr> References: <20220513142355.250389-1-mailhol.vincent@wanadoo.fr> <20220603102848.17907-1-mailhol.vincent@wanadoo.fr> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Frames can be directly injected to a can driver via the packet socket. By doing so, it is possible to reach the net_device_ops::ndo_start_xmit function even if the driver is configured in listen only mode. Add a check in can_dropped_invalid_skb() to discard the skb if CAN_CTRLMODE_LISTENONLY is set. Signed-off-by: Vincent Mailhol --- drivers/net/can/dev/skb.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/dev/skb.c b/drivers/net/can/dev/skb.c index dc9da76c0470..8bb62dd864c8 100644 --- a/drivers/net/can/dev/skb.c +++ b/drivers/net/can/dev/skb.c @@ -5,6 +5,7 @@ */ #include +#include #include #define MOD_DESC "CAN device driver interface" @@ -293,6 +294,7 @@ static bool can_skb_headroom_valid(struct net_device *dev, struct sk_buff *skb) bool can_dropped_invalid_skb(struct net_device *dev, struct sk_buff *skb) { const struct canfd_frame *cfd = (struct canfd_frame *)skb->data; + struct can_priv *priv = netdev_priv(dev); if (skb->protocol == htons(ETH_P_CAN)) { if (unlikely(skb->len != CAN_MTU || @@ -306,8 +308,13 @@ bool can_dropped_invalid_skb(struct net_device *dev, struct sk_buff *skb) goto inval_skb; } - if (!can_skb_headroom_valid(dev, skb)) + if (!can_skb_headroom_valid(dev, skb)) { + goto inval_skb; + } else if (priv->ctrlmode & CAN_CTRLMODE_LISTENONLY) { + netdev_info_once(dev, + "interface in listen only mode, dropping skb\n"); goto inval_skb; + } return false;