From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D6243016F7; Mon, 13 Oct 2025 11:02:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760353340; cv=none; b=ZUf55+8zc6Qog3J6Vy3EAPTEwzCs5TmtMro5aOM8xQqRHr5AWa4/HDYLCNAbH/wY1ucm8qkV7lfRsa+eMNAznXMSO8IiHRZ4waFAIBdCeWg8+CDn+ehuesk+yv2oGZqeprC0/asP5cJLe7PA1yIEldd5RW/nnJIJvG0UJketxxY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760353340; c=relaxed/simple; bh=JBExfb/2NKcoTW/v346rWFedtWA74TYLoMtfsRfq+Go=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ILISEU3t8jZ7bZvQPdd7VTMIfKk47OPOHSOfv1uE5vsjgmajHGQAUQB7XjiHHDQE93QccOAEAOGe1hQZoDDHHtIK5rXrcW0kp5cV0iKFYVoTxn5ZiLSjD8M8AS6NYKrbKdTxaVzTTNDTH5/6Gu8ou/gA56iAzB8sAHNYPYr9G3U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=L2DlN4zn; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="L2DlN4zn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05DB0C116C6; Mon, 13 Oct 2025 11:02:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1760353340; bh=JBExfb/2NKcoTW/v346rWFedtWA74TYLoMtfsRfq+Go=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=L2DlN4zn1GjG/EpfJhA9aEKljDl5o4IC22khkMz4HE9YyAiAbie1J5mshZHyj7px/ 8PxnWAw5o0cs1Hq0ArqUCOU4A4Op+dBtgZ7sR7ZEzjJXmtM/M5Jrt1G25ZMydPz3vM /Vo9KRKWgzEyqBGSs9vRRmIv7g75tb+DTf7UyNcHlXNlMHtM7FsdJXnxCCMXV0WEBc EFAMqqRPOtdRtLHmdCLxYWh7EbW7qZpv+EO8KcAnA8ku+WR360Q0MsfVuEz357j3gF tX2q7a0yZ/NygwXrHNdBO3V2Wg/k9OnrV5v6qjARP/uIZ/s6n1ccvHgukTIugQjyz1 474Z90mMUAS6g== From: Vincent Mailhol Date: Mon, 13 Oct 2025 20:01:24 +0900 Subject: [PATCH 2/9] can: netlink: add CAN_CTRLMODE_RESTRICTED Precedence: bulk X-Mailing-List: linux-can@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20251013-canxl-netlink-v1-2-f422b7e2729f@kernel.org> References: <20251013-canxl-netlink-v1-0-f422b7e2729f@kernel.org> In-Reply-To: <20251013-canxl-netlink-v1-0-f422b7e2729f@kernel.org> To: Marc Kleine-Budde , Oliver Hartkopp Cc: Vincent Mailhol , =?utf-8?q?St=C3=A9phane_Grosjean?= , Robert Nawrath , Minh Le , Duy Nguyen , linux-can@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=5265; i=mailhol@kernel.org; h=from:subject:message-id; bh=JBExfb/2NKcoTW/v346rWFedtWA74TYLoMtfsRfq+Go=; b=owGbwMvMwCV2McXO4Xp97WbG02pJDBlv7shvz5vgqH7xw+1zfUsV3e8LLNKN2vhw1sbaaM0Ky Zz6vhkKHaUsDGJcDLJiiizLyjm5FToKvcMO/bWEmcPKBDKEgYtTACZyv5zhv4+AmsZ0oXUKBw/y 10ws/Pp5jXTv+hMr6w+v+Peaa5pBGwMjw8eFP14W7hVcK7hn28PVux/J/26Z53JvmcWsnVdehi1 fcosPAA== X-Developer-Key: i=mailhol@kernel.org; a=openpgp; fpr=ED8F700574E67F20E574E8E2AB5FEB886DBB99C2 ISO 11898-1:2024 adds a new restricted operation mode. This mode is added as a mandatory feature for nodes which support CAN XL and is retrofitted as optional for legacy nodes (i.e. the ones which only support Classical CAN and CAN FD). The restricted operation mode is nearly the same as the listen only mode: the node can not send data frames or remote frames and can not send dominant bits if an error occurs. The only exception is that the node shall still send the acknowledgment bit. A second niche exception is that the node may still send a data frame containing a time reference message if the node is a primary time provider, but because the time provider feature is not yet implemented in the kernel, this second exception is not relevant to us at the moment. Add the CAN_CTRLMODE_RESTRICTED control mode flag and update the can_dev_dropped_skb() helper function accordingly. Finally, bail out if both CAN_CTRLMODE_LISTENONLY and CAN_CTRLMODE_RESTRICTED are provided. Signed-off-by: Vincent Mailhol --- drivers/net/can/dev/dev.c | 2 ++ drivers/net/can/dev/netlink.c | 7 ++++++ include/linux/can/dev.h | 50 +++++++++++++++++++++------------------- include/uapi/linux/can/netlink.h | 1 + 4 files changed, 36 insertions(+), 24 deletions(-) diff --git a/drivers/net/can/dev/dev.c b/drivers/net/can/dev/dev.c index 0cc3d008adb3..3377afb6f1c4 100644 --- a/drivers/net/can/dev/dev.c +++ b/drivers/net/can/dev/dev.c @@ -115,6 +115,8 @@ const char *can_get_ctrlmode_str(u32 ctrlmode) return "fd-tdc-auto"; case CAN_CTRLMODE_TDC_MANUAL: return "fd-tdc-manual"; + case CAN_CTRLMODE_RESTRICTED: + return "restricted-operation"; default: return ""; } diff --git a/drivers/net/can/dev/netlink.c b/drivers/net/can/dev/netlink.c index 0591406b6f32..f44b5dffa176 100644 --- a/drivers/net/can/dev/netlink.c +++ b/drivers/net/can/dev/netlink.c @@ -188,6 +188,13 @@ static int can_validate(struct nlattr *tb[], struct nlattr *data[], struct can_ctrlmode *cm = nla_data(data[IFLA_CAN_CTRLMODE]); flags = cm->flags & cm->mask; + + if ((flags & CAN_CTRLMODE_LISTENONLY) && + (flags & CAN_CTRLMODE_RESTRICTED)) { + NL_SET_ERR_MSG(extack, + "Listen-only and restricted modes are mutually exclusive"); + return -EOPNOTSUPP; + } } err = can_validate_bittiming(data, extack, IFLA_CAN_BITTIMING); diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h index d59b283c981a..9de8fde3ec9d 100644 --- a/include/linux/can/dev.h +++ b/include/linux/can/dev.h @@ -95,30 +95,6 @@ static inline bool can_is_canxl_dev_mtu(unsigned int mtu) return (mtu >= CANXL_MIN_MTU && mtu <= CANXL_MAX_MTU); } -/* drop skb if it does not contain a valid CAN frame for sending */ -static inline bool can_dev_dropped_skb(struct net_device *dev, struct sk_buff *skb) -{ - struct can_priv *priv = netdev_priv(dev); - - if (priv->ctrlmode & CAN_CTRLMODE_LISTENONLY) { - netdev_info_once(dev, - "interface in listen only mode, dropping skb\n"); - goto invalid_skb; - } - - if (!(priv->ctrlmode & CAN_CTRLMODE_FD) && can_is_canfd_skb(skb)) { - netdev_info_once(dev, "CAN FD is disabled, dropping skb\n"); - goto invalid_skb; - } - - return can_dropped_invalid_skb(dev, skb); - -invalid_skb: - kfree_skb(skb); - dev->stats.tx_dropped++; - return true; -} - void can_setup(struct net_device *dev); struct net_device *alloc_candev_mqs(int sizeof_priv, unsigned int echo_skb_max, @@ -150,6 +126,32 @@ void can_bus_off(struct net_device *dev); const char *can_get_state_str(const enum can_state state); const char *can_get_ctrlmode_str(u32 ctrlmode); +/* drop skb if it does not contain a valid CAN frame for sending */ +static inline bool can_dev_dropped_skb(struct net_device *dev, struct sk_buff *skb) +{ + struct can_priv *priv = netdev_priv(dev); + u32 silent_mode = priv->ctrlmode & (CAN_CTRLMODE_LISTENONLY | + CAN_CTRLMODE_RESTRICTED); + + if (silent_mode) { + netdev_info_once(dev, "interface in %s mode, dropping skb\n", + can_get_ctrlmode_str(silent_mode)); + goto invalid_skb; + } + + if (!(priv->ctrlmode & CAN_CTRLMODE_FD) && can_is_canfd_skb(skb)) { + netdev_info_once(dev, "CAN FD is disabled, dropping skb\n"); + goto invalid_skb; + } + + return can_dropped_invalid_skb(dev, skb); + +invalid_skb: + kfree_skb(skb); + dev->stats.tx_dropped++; + return true; +} + void can_state_get_by_berr_counter(const struct net_device *dev, const struct can_berr_counter *bec, enum can_state *tx_state, diff --git a/include/uapi/linux/can/netlink.h b/include/uapi/linux/can/netlink.h index ef62f56eaaef..fafd1cce4798 100644 --- a/include/uapi/linux/can/netlink.h +++ b/include/uapi/linux/can/netlink.h @@ -103,6 +103,7 @@ struct can_ctrlmode { #define CAN_CTRLMODE_CC_LEN8_DLC 0x100 /* Classic CAN DLC option */ #define CAN_CTRLMODE_TDC_AUTO 0x200 /* FD transceiver automatically calculates TDCV */ #define CAN_CTRLMODE_TDC_MANUAL 0x400 /* FD TDCV is manually set up by user */ +#define CAN_CTRLMODE_RESTRICTED 0x800 /* Restricted operation mode */ /* * CAN device statistics -- 2.49.1