Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3270200pxb; Sat, 9 Oct 2021 06:16:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwjtUHruo8d4cqvp4aSGBF0KJG4n2SSwv/9abDadmuoKgYLfc8QeJZ8Yu6R9DwfEUqwAz8P X-Received: by 2002:a62:30c7:0:b0:44c:1ec3:bc31 with SMTP id w190-20020a6230c7000000b0044c1ec3bc31mr15445319pfw.21.1633785381965; Sat, 09 Oct 2021 06:16:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633785381; cv=none; d=google.com; s=arc-20160816; b=qPbgSi2altcNsp+VJyQQlDFkzKbxHz7W727fFwrsZAFeE7uP4azWw9OCnr7ovAgw9H l3csV6nFYwLUgFzsSg3RHIt224vpgV54ghhApkD2JpFeIKOmsIq6I/usJntSc0nJ/11X 2lVw5F/wJlet/ne2LXGsTvfDKlv5v2gKG95O7LzjwjC8KqOfGNHpVc5FgqScWJBPX+ve Dy5T4b/6DO2j5APuoILnBo4ECxOq5oqaBViuR9S1oWkpGHRMn6F2Nb7M4JhqPwQh+raB 0fiepwdTlSw7j6X7mT7GlWAgVrnREqe3x2LmpdDzD/GIxsHh9riTKNNgNojZa1+dUjIX obaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=SZkPWBHRU6+32bUJYbgnHSSK+tqr17HasmCIGSJtBN8=; b=q5TM5df3FLmd8BdnNuWarvG20kitzy+OikdYIANofL9uWXT1tUNAV+urX8fzqMv7kU T/g9rFWpKNC8huMl0UTPjrNCJLmmn0sdpKDwbmjZvqpMdqzORRJEeEZbrQ+EaQXFdI4d UndSokY9EQj75tOMkFUk0xt1e0oCiNhOX7JcbA4RQKG78TxTTJgSnK06udHEJw6Vnjuh gQ3DdRqK+gZmhDI5/7c1I+5h8URhHpa8pQCPH/eL0O4I+UAObYaSnNTtuFXfNyHAorDm fsAL0pflhSm4guHf0GLcVGVeoUCa+rXlxUsCvW9/EqrscIkGUlImP2IhWMpoVdsh1Mh5 fWRQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r2si2799726pga.96.2021.10.09.06.16.09; Sat, 09 Oct 2021 06:16:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233445AbhJINQV (ORCPT + 99 others); Sat, 9 Oct 2021 09:16:21 -0400 Received: from smtp03.smtpout.orange.fr ([80.12.242.125]:63609 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233674AbhJINPf (ORCPT ); Sat, 9 Oct 2021 09:15:35 -0400 Received: from tomoyo.flets-east.jp ([114.149.34.46]) by smtp.orange.fr with ESMTPA id ZC9zmoEn4UGqlZCARm2ihC; Sat, 09 Oct 2021 15:13:37 +0200 X-ME-Helo: tomoyo.flets-east.jp X-ME-Auth: MDU0YmViZGZmMDIzYiBlMiM2NTczNTRjNWZkZTMwOGRiOGQ4ODf3NWI1ZTMyMzdiODlhOQ== X-ME-Date: Sat, 09 Oct 2021 15:13:37 +0200 X-ME-IP: 114.149.34.46 From: Vincent Mailhol To: Marc Kleine-Budde , linux-can@vger.kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Mailhol Subject: [PATCH v2 3/3] can: netlink: report the CAN controller mode supported flags Date: Sat, 9 Oct 2021 22:13:04 +0900 Message-Id: <20211009131304.19729-4-mailhol.vincent@wanadoo.fr> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211009131304.19729-1-mailhol.vincent@wanadoo.fr> References: <20211009131304.19729-1-mailhol.vincent@wanadoo.fr> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch introduces a method for the user to check both the supported and the static capabilities. The proposed method reuses the existing struct can_ctrlmode and thus do not need a new IFLA_CAN_* entry. Currently, the CAN netlink interface provides no easy ways to check the capabilities of a given controller. The only method from the command line is to try each CAN_CTRLMODE_ individually to check whether the netlink interface returns an -EOPNOTSUPP error or not (alternatively, one may find it easier to directly check the source code of the driver instead...) It appears that, can_ctrlmode::mask is only used in one direction: from the userland to the kernel. So we can just reuse this field in the other direction (from the kernel to userland). But, because the semantic is different, we use a union to give this field a proper name: supported. Below table explains how the two fields can_ctrlmode::supported and can_ctrlmode::flags, when masked with any of the CAN_CTRLMODE_* bit flags, allow us to identify both the supported and the static capabilities: supported & flags & Controller capabilities CAN_CTRLMODE_* CAN_CTRLMODE_* ----------------------------------------------------------------------- false false Feature not supported (always disabled) false true Static feature (always enabled) true false Feature supported but disabled true true Feature supported and enabled Signed-off-by: Vincent Mailhol --- Please refer to below link for the iproute2-next counterpart of this patch: https://lore.kernel.org/linux-can/20211003050147.569044-1-mailhol.vincent@wanadoo.fr/T/#t --- drivers/net/can/dev/netlink.c | 5 ++++- include/uapi/linux/can/netlink.h | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/net/can/dev/netlink.c b/drivers/net/can/dev/netlink.c index 6c9906e8040c..86521836fd6d 100644 --- a/drivers/net/can/dev/netlink.c +++ b/drivers/net/can/dev/netlink.c @@ -264,7 +264,10 @@ static size_t can_get_size(const struct net_device *dev) static int can_fill_info(struct sk_buff *skb, const struct net_device *dev) { struct can_priv *priv = netdev_priv(dev); - struct can_ctrlmode cm = {.flags = priv->ctrlmode}; + struct can_ctrlmode cm = { + .supported = priv->ctrlmode_supported, + .flags = priv->ctrlmode + }; struct can_berr_counter bec = { }; enum can_state state = priv->state; diff --git a/include/uapi/linux/can/netlink.h b/include/uapi/linux/can/netlink.h index f730d443b918..2847ed0dcac3 100644 --- a/include/uapi/linux/can/netlink.h +++ b/include/uapi/linux/can/netlink.h @@ -88,7 +88,10 @@ struct can_berr_counter { * CAN controller mode */ struct can_ctrlmode { - __u32 mask; + union { + __u32 mask; /* Userland to kernel */ + __u32 supported; /* Kernel to userland */ + }; __u32 flags; }; -- 2.32.0