Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp400609pxb; Mon, 25 Oct 2021 10:27:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJybmyc0h+Cf70FndkZthmWypVu5Kij3FQaS9+hxtCeuWDZcd7efKOt7Knpl4V29LodZPzhN X-Received: by 2002:a05:6402:508:: with SMTP id m8mr28870761edv.364.1635182832947; Mon, 25 Oct 2021 10:27:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635182832; cv=none; d=google.com; s=arc-20160816; b=sUdpxHq78+aXyFB2kERrmLICB4S9AGkS491aXN3lBEfBrfpqi+jAr99hJDguVx+2RS zpu9zctMHeGzRDiJYIb2fnk4YsbAqU18FsMOdttsQsoPXJ+TnAW8mqHL3TdHqNnUjghz VUwHrTNJDApA20BjCcEfsMYneZbLWiHgq0WVJUEc9rhKDzCZV0iRnPO6QVHJMy6nvJYy 2xzgExBHJgWguhZv8XQwtW6lZ713GzBrSEqMEbqXQtt1SNLSOAw7CJEL66jmw+sLiNT+ 1HOedI/hn5JSwYa+nuTfm88FkVS8ZYbIB+XbN+Rj7cuCicTaYYzgbjhYrtNijGpaOBbn Yy4Q== 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=1vkmdenlVQ8mm9+mouwUQU4nZxP4CyHgftBpJdCZOu4=; b=nCfQThvtN2BPz+ze+xgxMunaQ0KIJ1f3XLniPpOcfvt6lF8z038bGW4rjEThs+5N6q UAOZEXELJ30VTL0ria01SPQ8vso9VUa1EIw3SG8e08N87Q6fAwSM77CdkWi1acmxcNhi 2Wr3H+DoijsCxCW6AlS+JnpRVzjLXDnV8T6sS/cjrvlvrYlznAsPjEhGunBilU3T6qRp UWIPC7MxBbHiYn8OWMszAfrE6UvzthakYd/D6EciXa/69IwjOGLBU9ZfrVUKcmsO8ypm PCw/Tzyh/QpLv/w5VMaprhE2dFwPu2R684wlkTBqvOJwvkYL7neXbYekgnngD+LRKFr7 s9cA== 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 f7si14894152edy.290.2021.10.25.10.26.47; Mon, 25 Oct 2021 10:27:12 -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 S234070AbhJYR0U (ORCPT + 99 others); Mon, 25 Oct 2021 13:26:20 -0400 Received: from smtp02.smtpout.orange.fr ([80.12.242.124]:49592 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234073AbhJYR0K (ORCPT ); Mon, 25 Oct 2021 13:26:10 -0400 Received: from tomoyo.flets-east.jp ([114.149.34.46]) by smtp.orange.fr with ESMTPA id f3gYmY0E4niuxf3hImufL8; Mon, 25 Oct 2021 19:23:46 +0200 X-ME-Helo: tomoyo.flets-east.jp X-ME-Auth: MDU0YmViZGZmMDIzYiBlMiM2NTczNTRjNWZkZTMwOGRiOGQ4ODf3NWI1ZTMyMzdiODlhOQ== X-ME-Date: Mon, 25 Oct 2021 19:23:46 +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 v3 4/4] can: netlink: report the CAN controller mode supported flags Date: Tue, 26 Oct 2021 02:22:47 +0900 Message-Id: <20211025172247.1774451-5-mailhol.vincent@wanadoo.fr> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211025172247.1774451-1-mailhol.vincent@wanadoo.fr> References: <20211025172247.1774451-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 26c336808be5..32e1eb63ee7d 100644 --- a/drivers/net/can/dev/netlink.c +++ b/drivers/net/can/dev/netlink.c @@ -475,7 +475,10 @@ static int can_tdc_fill_info(struct sk_buff *skb, 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 75b85c60efb2..b846922ac18f 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