Message ID | 20221219212717.1298282-2-frank.jungclaus@esd.eu |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp2624581wrn; Mon, 19 Dec 2022 13:29:44 -0800 (PST) X-Google-Smtp-Source: AA0mqf4PjiHcqeZcG/U9bzwhjlP4t7BZneY843nf8yVebJrvYE4FjWd624+9rTwxOE++/8CHC03i X-Received: by 2002:a17:902:f114:b0:18f:aca1:b0c9 with SMTP id e20-20020a170902f11400b0018faca1b0c9mr27899254plb.53.1671485383752; Mon, 19 Dec 2022 13:29:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1671485383; cv=pass; d=google.com; s=arc-20160816; b=kNXqm67iWGRTTk6qyoVMxYg3Y2UR2jEFEjiH+DeAit8UttyhedbsX1l7aX9IA6dmSE Jet5lIkz5iydQZb3BusHSv+TEkXn+pYPC4a3yuKCw5b/0TPYSKbWu4WskQ7fsC6Sdojb n0xWbG2/P1UF+F405AJt8Pd3Mk9co50yoM9KkPT8qb2x/lFXKFdlRh9XEUrqagP3GzIr LlAFKiEjQS4wtV/sLKYKJRAyGRGe0vqqGpKxLMJgySucM3EzR2woCLWpxsXHy9tDasbA p80yB8WTxRybbfw2ca0+Li0FjGOa1wzqEgkf4jlf8u2TddIoUWd8Ve21+RJ7JklXfcya Kprg== ARC-Message-Signature: i=2; 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 :dkim-signature; bh=PH4Epp4GyGuEC6gorfLFdD6vqnNWemsv/uQaT6+AYik=; b=0/eYHd+vKIxKkEtbdQhImkoZk7rXIjBWabqnhAT9MWb/HoAWGtBgZH6mWeu96J53I6 vkK5V/I6aMJOpQYknzWkfuDS0ScUlGV9X37A0LfZa9OgRl7/eyRkzFX0sPIEPvx9GZLt nI7/niK44h92uDRVx0S3w9FFpQKDzywEjIey94WLt5+Q109vdc21CS6sMNuQ3r7yLfqh Dl5gKoqKxWSEBZDR07NlYhM/GzOM6q+sWJQhdKlH7GlNsYSvSfAs4MgSuH4uXZDvLaLV dxRGtIX1uGUXmqcrZgSaw3clHkKiXTGff1NcLMjr5v5Y9dciSTY2iugH5qenmANSgvj/ qYWw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@esdhannover.onmicrosoft.com header.s=selector1-esdhannover-onmicrosoft-com header.b=CA3IFhpB; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n6-20020a170903110600b001868d5fc29bsi12830331plh.259.2022.12.19.13.29.30; Mon, 19 Dec 2022 13:29:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@esdhannover.onmicrosoft.com header.s=selector1-esdhannover-onmicrosoft-com header.b=CA3IFhpB; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232833AbiLSV1s (ORCPT <rfc822;abdi.embedded@gmail.com> + 99 others); Mon, 19 Dec 2022 16:27:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232772AbiLSV1g (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 19 Dec 2022 16:27:36 -0500 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2098.outbound.protection.outlook.com [40.107.7.98]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68BDF646A; Mon, 19 Dec 2022 13:27:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dFAUZGYVG46C8RhHEWX0IeFCT5fZcfMwZZdVx8VgUKelBUv23NzwiKKtnrlbNRTXDjLG/SvECkIr1WkLw17JEyB2FMPhABc/alVtMuxXbH+1rFCd2tBYcjzCzRaEX/4s4az24NMG5xJilB/Y7WADB1Ruy0ct1T7Bh2oHLLmq65Lh3UINlYf3gfhysx43GIsdDJe7McnuzeCFXiEK1zpFHk/Zzfa/sCTStUh+aKl96vg532n/XuN+MvZWZ4af+FQ8BXsvXW9uRJUUM9OSun/ZPDOTQGLHF0W4hwEyCABjO8VtUhP+gc0tbnMHEwRRlbcx5pk+2O9eXL11IvEBC2i/ZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=PH4Epp4GyGuEC6gorfLFdD6vqnNWemsv/uQaT6+AYik=; b=Oiq6VM3xcn+4BpYYbv6HQgOjFtKc5TknN02f4fB1Vij2JsD6hRvCGkYP3YjETVpXRLmI6LakGGA2z+ujBoC6Zb1KG3cZFuoDMc7TUbNo6FVAgfWCKIDfMC7FCjkhTeFpoZSc9e+4QGRmURrYIX4PyD/vqHrhMGtDQNRNJ8IhAX/hflVFivAMXCWmGeDJLnqrFI2xFI1PSS6h8OI5VFY544yCXv/c+Rhx7pZVwbjPXvdjN2Jgwi4Nb/00p0fAFrodD2i65e4TcAik5aG9t/4X2kU7PUnhduEdlS0jx98Y98KwbdzPGzzxxIj+Wyzggwm3RvU12ATKrlt5WlQs2KxYrg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=softfail (sender ip is 80.151.164.27) smtp.rcpttodomain=esd.eu smtp.mailfrom=esd.eu; dmarc=none action=none header.from=esd.eu; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=esdhannover.onmicrosoft.com; s=selector1-esdhannover-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PH4Epp4GyGuEC6gorfLFdD6vqnNWemsv/uQaT6+AYik=; b=CA3IFhpBTrIr1v0GnQD9G1dr3PwWNYe29FbJn86cdctrwGbSMHM9WNudxpXT3rP7jQwrM/D7eWZweZo5edJNzdLmTkFdynu0tFz2tLOpeDZfhCzcHCXXn3yTiSWEciidtj77pymvKFIUckHOlK5wBlnuDHmJ69lxzlP5o6lJs1M= Received: from AM5PR0402CA0018.eurprd04.prod.outlook.com (2603:10a6:203:90::28) by PAWPR03MB10089.eurprd03.prod.outlook.com (2603:10a6:102:360::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5924.16; Mon, 19 Dec 2022 21:27:30 +0000 Received: from AM7EUR06FT021.eop-eur06.prod.protection.outlook.com (2603:10a6:203:90:cafe::28) by AM5PR0402CA0018.outlook.office365.com (2603:10a6:203:90::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5924.18 via Frontend Transport; Mon, 19 Dec 2022 21:27:30 +0000 X-MS-Exchange-Authentication-Results: spf=softfail (sender IP is 80.151.164.27) smtp.mailfrom=esd.eu; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=esd.eu; Received-SPF: SoftFail (protection.outlook.com: domain of transitioning esd.eu discourages use of 80.151.164.27 as permitted sender) Received: from esd-s7.esd (80.151.164.27) by AM7EUR06FT021.mail.protection.outlook.com (10.233.255.227) with Microsoft SMTP Server id 15.20.5924.16 via Frontend Transport; Mon, 19 Dec 2022 21:27:29 +0000 Received: from esd-s20.esd.local (debby [10.0.0.190]) by esd-s7.esd (Postfix) with ESMTPS id 522427C16C9; Mon, 19 Dec 2022 22:27:29 +0100 (CET) Received: by esd-s20.esd.local (Postfix, from userid 2046) id 482F62E1DC1; Mon, 19 Dec 2022 22:27:29 +0100 (CET) From: Frank Jungclaus <frank.jungclaus@esd.eu> To: linux-can@vger.kernel.org, Marc Kleine-Budde <mkl@pengutronix.de>, Wolfgang Grandegger <wg@grandegger.com>, Vincent Mailhol <mailhol.vincent@wanadoo.fr> Cc: =?utf-8?q?Stefan_M=C3=A4tje?= <stefan.maetje@esd.eu>, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Frank Jungclaus <frank.jungclaus@esd.eu> Subject: [PATCH 3/3] can: esd_usb: Improved decoding for ESD_EV_CAN_ERROR_EXT messages Date: Mon, 19 Dec 2022 22:27:17 +0100 Message-Id: <20221219212717.1298282-2-frank.jungclaus@esd.eu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221219212717.1298282-1-frank.jungclaus@esd.eu> References: <20221219212717.1298282-1-frank.jungclaus@esd.eu> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM7EUR06FT021:EE_|PAWPR03MB10089:EE_ Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: adeb51a5-21de-4151-4296-08dae207d570 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xRlsG70RyeU1m0paW1nmLq597/n1aNfmNJAe0NrLOfXm8xaLaU8HEvb5FAMfiQY5f6854fSHDzp8IfMwF4FbUqMGY/LM5vXsZdacVlGjvL3v5xE6mt1oCSjqOhA2+YIxIM+Vf6mSRb7Z4OJh4MQYE+SRqc4TGh7r7/HrE7+dS1z0x7uXPy9YK/9mIHvRRyWXEC6WjGjhq7WOvyPnHlrkmZBTlkhDdyHbZ8kqUjGGt/01ygvOjgNd8XjSs7kfVWwQZueIwxx4d79UIn9yZStax9JZfaJBtfF8Gn3a6Lyi/PZE1jyLuLWwLJd10CGotpXmEg2kHT8KXR0H94wD3We7leyckvGdkGS8jC7KKljfcxdrRMGPn7Wifn+F2DUmoplsT7Wxq3GFJc3qlUnfBMGC5DeBnosiFwEh4L+KKm64snrzGBqAbZtQ3p1SGiSoNvOgeg4uxFp7bYkhjH0TjgI229d0wdRh56xvbhVW3cYmFO3Mmck9KQxTd8Cp/Jpu5VCyZCy6fk798E6E1UwQ9zzOHYf+U/JR3/ku/1eaLtKQkMcnoQIviboZ49i+RJWLZOdBvsmFgS1WwCUeWmVMa+/PXDal0tNx14w8Ighr6RlTNf3BLk6skvPJYBQBv/GlICRCLqjMM/gMaruMOq0Dw01h0QlAVIKTU5ZoAZRrZ0gIwUXDQgbcxS1gAZKc6j15Uu7gbOzcUvVYp6zwGGK2Ei2hFw== X-Forefront-Antispam-Report: CIP:80.151.164.27;CTRY:DE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:esd-s7.esd;PTR:p5097a41b.dip0.t-ipconnect.de;CAT:NONE;SFS:(13230022)(4636009)(39840400004)(396003)(346002)(136003)(376002)(451199015)(46966006)(36840700001)(36860700001)(86362001)(6666004)(2616005)(26005)(6266002)(2906002)(336012)(81166007)(186003)(966005)(36756003)(478600001)(110136005)(316002)(8936002)(44832011)(15650500001)(356005)(54906003)(40480700001)(70206006)(8676002)(82310400005)(41300700001)(1076003)(42186006)(83380400001)(5660300002)(47076005)(4326008)(70586007);DIR:OUT;SFP:1102; X-OriginatorOrg: esd.eu X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Dec 2022 21:27:29.9117 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: adeb51a5-21de-4151-4296-08dae207d570 X-MS-Exchange-CrossTenant-Id: 5a9c3a1d-52db-4235-b74c-9fd851db2e6b X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5a9c3a1d-52db-4235-b74c-9fd851db2e6b;Ip=[80.151.164.27];Helo=[esd-s7.esd] X-MS-Exchange-CrossTenant-AuthSource: AM7EUR06FT021.eop-eur06.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAWPR03MB10089 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752679457935656783?= X-GMAIL-MSGID: =?utf-8?q?1752679457935656783?= |
Series |
can: esd_usb: Some more preparation for supporting esd CAN-USB/3
|
|
Commit Message
Frank Jungclaus
Dec. 19, 2022, 9:27 p.m. UTC
As suggested by Marc there now is a union plus a struct ev_can_err_ext
for easier decoding of an ESD_EV_CAN_ERROR_EXT event message (which
simply is a rx_msg with some dedicated data).
Suggested-by: Marc Kleine-Budde <mkl@pengutronix.de>
Link: https://lore.kernel.org/linux-can/20220621071152.ggyhrr5sbzvwpkpx@pengutronix.de/
Signed-off-by: Frank Jungclaus <frank.jungclaus@esd.eu>
---
drivers/net/can/usb/esd_usb.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
Comments
Le mar. 20 déc. 2022 à 06:28, Frank Jungclaus <frank.jungclaus@esd.eu> a écrit : > > As suggested by Marc there now is a union plus a struct ev_can_err_ext > for easier decoding of an ESD_EV_CAN_ERROR_EXT event message (which > simply is a rx_msg with some dedicated data). > > Suggested-by: Marc Kleine-Budde <mkl@pengutronix.de> > Link: https://lore.kernel.org/linux-can/20220621071152.ggyhrr5sbzvwpkpx@pengutronix.de/ > Signed-off-by: Frank Jungclaus <frank.jungclaus@esd.eu> > --- > drivers/net/can/usb/esd_usb.c | 18 +++++++++++++----- > 1 file changed, 13 insertions(+), 5 deletions(-) > > diff --git a/drivers/net/can/usb/esd_usb.c b/drivers/net/can/usb/esd_usb.c > index 09745751f168..f90bb2c0ba15 100644 > --- a/drivers/net/can/usb/esd_usb.c > +++ b/drivers/net/can/usb/esd_usb.c > @@ -127,7 +127,15 @@ struct rx_msg { > u8 dlc; > __le32 ts; > __le32 id; /* upper 3 bits contain flags */ > - u8 data[8]; > + union { > + u8 data[8]; > + struct { > + u8 status; /* CAN Controller Status */ > + u8 ecc; /* Error Capture Register */ > + u8 rec; /* RX Error Counter */ > + u8 tec; /* TX Error Counter */ > + } ev_can_err_ext; /* For ESD_EV_CAN_ERROR_EXT */ > + }; > }; > > struct tx_msg { > @@ -229,10 +237,10 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv, > u32 id = le32_to_cpu(msg->msg.rx.id) & ESD_IDMASK; > > if (id == ESD_EV_CAN_ERROR_EXT) { > - u8 state = msg->msg.rx.data[0]; > - u8 ecc = msg->msg.rx.data[1]; > - u8 rxerr = msg->msg.rx.data[2]; > - u8 txerr = msg->msg.rx.data[3]; > + u8 state = msg->msg.rx.ev_can_err_ext.status; > + u8 ecc = msg->msg.rx.ev_can_err_ext.ecc; > + u8 rxerr = msg->msg.rx.ev_can_err_ext.rec; > + u8 txerr = msg->msg.rx.ev_can_err_ext.tec; I do not like how you have to write msg->msg.rx.something. I think it would be better to make the union within struct esd_usb_msg anonymous: https://elixir.bootlin.com/linux/latest/source/drivers/net/can/usb/esd_usb.c#L169 That said, this is not a criticism of this patch but more something to be addressed in a separate clean-up patch. > netdev_dbg(priv->netdev, > "CAN_ERR_EV_EXT: dlc=%#02x state=%02x ecc=%02x rec=%02x tec=%02x\n", > -- > 2.25.1 >
On Tue. 20 Dec. 2022 at 14:27, Vincent MAILHOL <mailhol.vincent@wanadoo.fr> wrote: > Le mar. 20 déc. 2022 à 06:28, Frank Jungclaus <frank.jungclaus@esd.eu> a écrit : > > As suggested by Marc there now is a union plus a struct ev_can_err_ext > > for easier decoding of an ESD_EV_CAN_ERROR_EXT event message (which > > simply is a rx_msg with some dedicated data). > > > > Suggested-by: Marc Kleine-Budde <mkl@pengutronix.de> > > Link: https://lore.kernel.org/linux-can/20220621071152.ggyhrr5sbzvwpkpx@pengutronix.de/ > > Signed-off-by: Frank Jungclaus <frank.jungclaus@esd.eu> > > --- > > drivers/net/can/usb/esd_usb.c | 18 +++++++++++++----- > > 1 file changed, 13 insertions(+), 5 deletions(-) > > > > diff --git a/drivers/net/can/usb/esd_usb.c b/drivers/net/can/usb/esd_usb.c > > index 09745751f168..f90bb2c0ba15 100644 > > --- a/drivers/net/can/usb/esd_usb.c > > +++ b/drivers/net/can/usb/esd_usb.c > > @@ -127,7 +127,15 @@ struct rx_msg { > > u8 dlc; > > __le32 ts; > > __le32 id; /* upper 3 bits contain flags */ > > - u8 data[8]; > > + union { > > + u8 data[8]; > > + struct { > > + u8 status; /* CAN Controller Status */ > > + u8 ecc; /* Error Capture Register */ > > + u8 rec; /* RX Error Counter */ > > + u8 tec; /* TX Error Counter */ > > + } ev_can_err_ext; /* For ESD_EV_CAN_ERROR_EXT */ > > + }; > > }; > > > > struct tx_msg { > > @@ -229,10 +237,10 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv, > > u32 id = le32_to_cpu(msg->msg.rx.id) & ESD_IDMASK; > > > > if (id == ESD_EV_CAN_ERROR_EXT) { > > - u8 state = msg->msg.rx.data[0]; > > - u8 ecc = msg->msg.rx.data[1]; > > - u8 rxerr = msg->msg.rx.data[2]; > > - u8 txerr = msg->msg.rx.data[3]; > > + u8 state = msg->msg.rx.ev_can_err_ext.status; > > + u8 ecc = msg->msg.rx.ev_can_err_ext.ecc; > > + u8 rxerr = msg->msg.rx.ev_can_err_ext.rec; > > + u8 txerr = msg->msg.rx.ev_can_err_ext.tec; > > I do not like how you have to write msg->msg.rx.something. I think it > would be better to make the union within struct esd_usb_msg anonymous: > > https://elixir.bootlin.com/linux/latest/source/drivers/net/can/usb/esd_usb.c#L169 Or maybe just declare esd_usb_msg as an union instead of a struct: union esd_usb_msg { struct header_msg hdr; struct version_msg version; struct version_reply_msg version_reply; struct rx_msg rx; struct tx_msg tx; struct tx_done_msg txdone; struct set_baudrate_msg setbaud; struct id_filter_msg filter; };
On 20.12.2022 17:53:28, Vincent MAILHOL wrote: > > > struct tx_msg { > > > @@ -229,10 +237,10 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv, > > > u32 id = le32_to_cpu(msg->msg.rx.id) & ESD_IDMASK; > > > > > > if (id == ESD_EV_CAN_ERROR_EXT) { > > > - u8 state = msg->msg.rx.data[0]; > > > - u8 ecc = msg->msg.rx.data[1]; > > > - u8 rxerr = msg->msg.rx.data[2]; > > > - u8 txerr = msg->msg.rx.data[3]; > > > + u8 state = msg->msg.rx.ev_can_err_ext.status; > > > + u8 ecc = msg->msg.rx.ev_can_err_ext.ecc; > > > + u8 rxerr = msg->msg.rx.ev_can_err_ext.rec; > > > + u8 txerr = msg->msg.rx.ev_can_err_ext.tec; > > > > I do not like how you have to write msg->msg.rx.something. I think it > > would be better to make the union within struct esd_usb_msg anonymous: > > > > https://elixir.bootlin.com/linux/latest/source/drivers/net/can/usb/esd_usb.c#L169 > > Or maybe just declare esd_usb_msg as an union instead of a struct: +1 > union esd_usb_msg { > struct header_msg hdr; > struct version_msg version; > struct version_reply_msg version_reply; > struct rx_msg rx; > struct tx_msg tx; > struct tx_done_msg txdone; > struct set_baudrate_msg setbaud; > struct id_filter_msg filter; > }; Marc
On Tue, 2022-12-20 at 17:53 +0900, Vincent MAILHOL wrote: > On Tue. 20 Dec. 2022 at 14:27, Vincent MAILHOL > <mailhol.vincent@wanadoo.fr> wrote: > > Le mar. 20 déc. 2022 à 06:28, Frank Jungclaus <frank.jungclaus@esd.eu> a écrit : > > > As suggested by Marc there now is a union plus a struct ev_can_err_ext > > > for easier decoding of an ESD_EV_CAN_ERROR_EXT event message (which > > > simply is a rx_msg with some dedicated data). > > > > > > Suggested-by: Marc Kleine-Budde <mkl@pengutronix.de> > > > Link: https://lore.kernel.org/linux-can/20220621071152.ggyhrr5sbzvwpkpx@pengutronix.de/ > > > Signed-off-by: Frank Jungclaus <frank.jungclaus@esd.eu> > > > --- > > > drivers/net/can/usb/esd_usb.c | 18 +++++++++++++----- > > > 1 file changed, 13 insertions(+), 5 deletions(-) > > > > > > diff --git a/drivers/net/can/usb/esd_usb.c b/drivers/net/can/usb/esd_usb.c > > > index 09745751f168..f90bb2c0ba15 100644 > > > --- a/drivers/net/can/usb/esd_usb.c > > > +++ b/drivers/net/can/usb/esd_usb.c > > > @@ -127,7 +127,15 @@ struct rx_msg { > > > u8 dlc; > > > __le32 ts; > > > __le32 id; /* upper 3 bits contain flags */ > > > - u8 data[8]; > > > + union { > > > + u8 data[8]; > > > + struct { > > > + u8 status; /* CAN Controller Status */ > > > + u8 ecc; /* Error Capture Register */ > > > + u8 rec; /* RX Error Counter */ > > > + u8 tec; /* TX Error Counter */ > > > + } ev_can_err_ext; /* For ESD_EV_CAN_ERROR_EXT */ > > > + }; > > > }; > > > > > > struct tx_msg { > > > @@ -229,10 +237,10 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv, > > > u32 id = le32_to_cpu(msg->msg.rx.id) & ESD_IDMASK; > > > > > > if (id == ESD_EV_CAN_ERROR_EXT) { > > > - u8 state = msg->msg.rx.data[0]; > > > - u8 ecc = msg->msg.rx.data[1]; > > > - u8 rxerr = msg->msg.rx.data[2]; > > > - u8 txerr = msg->msg.rx.data[3]; > > > + u8 state = msg->msg.rx.ev_can_err_ext.status; > > > + u8 ecc = msg->msg.rx.ev_can_err_ext.ecc; > > > + u8 rxerr = msg->msg.rx.ev_can_err_ext.rec; > > > + u8 txerr = msg->msg.rx.ev_can_err_ext.tec; > > > > I do not like how you have to write msg->msg.rx.something. I think it > > would be better to make the union within struct esd_usb_msg anonymous: > > > > https://elixir.bootlin.com/linux/latest/source/drivers/net/can/usb/esd_usb.c#L169 > > Or maybe just declare esd_usb_msg as an union instead of a struct: > > union esd_usb_msg { > struct header_msg hdr; > struct version_msg version; > struct version_reply_msg version_reply; > struct rx_msg rx; > struct tx_msg tx; > struct tx_done_msg txdone; > struct set_baudrate_msg setbaud; > struct id_filter_msg filter; > }; Apart from the fact that this change would probably require several dozen lines of code to be adjusted, I like the idea ;)
On Tue, 2022-12-20 at 10:05 +0100, Marc Kleine-Budde wrote: > On 20.12.2022 17:53:28, Vincent MAILHOL wrote: > > > > struct tx_msg { > > > > @@ -229,10 +237,10 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv, > > > > u32 id = le32_to_cpu(msg->msg.rx.id) & ESD_IDMASK; > > > > > > > > if (id == ESD_EV_CAN_ERROR_EXT) { > > > > - u8 state = msg->msg.rx.data[0]; > > > > - u8 ecc = msg->msg.rx.data[1]; > > > > - u8 rxerr = msg->msg.rx.data[2]; > > > > - u8 txerr = msg->msg.rx.data[3]; > > > > + u8 state = msg->msg.rx.ev_can_err_ext.status; > > > > + u8 ecc = msg->msg.rx.ev_can_err_ext.ecc; > > > > + u8 rxerr = msg->msg.rx.ev_can_err_ext.rec; > > > > + u8 txerr = msg->msg.rx.ev_can_err_ext.tec; > > > > > > I do not like how you have to write msg->msg.rx.something. I think it > > > would be better to make the union within struct esd_usb_msg anonymous: > > > > > > https://elixir.bootlin.com/linux/latest/source/drivers/net/can/usb/esd_usb.c#L169 > > > > Or maybe just declare esd_usb_msg as an union instead of a struct: > > +1 Accepted ;) I'll try to address this in a separate code-clean-up patch. > > > union esd_usb_msg { > > struct header_msg hdr; > > struct version_msg version; > > struct version_reply_msg version_reply; > > struct rx_msg rx; > > struct tx_msg tx; > > struct tx_done_msg txdone; > > struct set_baudrate_msg setbaud; > > struct id_filter_msg filter; > > }; > > Marc >
diff --git a/drivers/net/can/usb/esd_usb.c b/drivers/net/can/usb/esd_usb.c index 09745751f168..f90bb2c0ba15 100644 --- a/drivers/net/can/usb/esd_usb.c +++ b/drivers/net/can/usb/esd_usb.c @@ -127,7 +127,15 @@ struct rx_msg { u8 dlc; __le32 ts; __le32 id; /* upper 3 bits contain flags */ - u8 data[8]; + union { + u8 data[8]; + struct { + u8 status; /* CAN Controller Status */ + u8 ecc; /* Error Capture Register */ + u8 rec; /* RX Error Counter */ + u8 tec; /* TX Error Counter */ + } ev_can_err_ext; /* For ESD_EV_CAN_ERROR_EXT */ + }; }; struct tx_msg { @@ -229,10 +237,10 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv, u32 id = le32_to_cpu(msg->msg.rx.id) & ESD_IDMASK; if (id == ESD_EV_CAN_ERROR_EXT) { - u8 state = msg->msg.rx.data[0]; - u8 ecc = msg->msg.rx.data[1]; - u8 rxerr = msg->msg.rx.data[2]; - u8 txerr = msg->msg.rx.data[3]; + u8 state = msg->msg.rx.ev_can_err_ext.status; + u8 ecc = msg->msg.rx.ev_can_err_ext.ecc; + u8 rxerr = msg->msg.rx.ev_can_err_ext.rec; + u8 txerr = msg->msg.rx.ev_can_err_ext.tec; netdev_dbg(priv->netdev, "CAN_ERR_EV_EXT: dlc=%#02x state=%02x ecc=%02x rec=%02x tec=%02x\n",