Message ID | 20221219212717.1298282-1-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 c7csp2624570wrn; Mon, 19 Dec 2022 13:29:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf5feYxw8sK3HnmCDDJ7YWgCth5wA35Dn0tFRLlJod4BoF66u3Ouizf03+K00dGGF/xHFhd4 X-Received: by 2002:a17:902:ab0c:b0:189:d8fb:1523 with SMTP id ik12-20020a170902ab0c00b00189d8fb1523mr47185745plb.36.1671485382333; Mon, 19 Dec 2022 13:29:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1671485382; cv=pass; d=google.com; s=arc-20160816; b=ayg1lJgXUuXUXyQb5ghcjYsaOwkM2jpx6y4ZMh6KV0Eo2bDWG2ZyU7z1vUrWLaSyav lHghKlnhKDT4OMkuPcHYiCi1SJNyoXpKD21ux9UBP/+a8/3hq3QA02F2adH8cs/Q22+w lbkFCPt5BoRZRg6La77hsuRRRNxu60ML5I96+Plai/cYQdrazD2TNPJGE1HK5UX1zHaW FvGRJQ7ZFVq1635sVEg+9TUrpLvmuvUr51oBebMY/YwWfqe1NMAsi3Hu0ZIIZmjuAmpG nqroq14Z9LM8Ra/PTu5AJhizaKlXvZ6DXdfubWGt4GcAGH/AEtfvesfZWNi6w9f3yw1+ NhYA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=CLCrW5mNwfs26NWA4N8ao2qXw+YqsWSEuJb20hNJhys=; b=q3f3Ld1yri+sW3zQhbSJUTJzBidPD0zZDBgOVqFOcdIl0y8kWiBbUJjRBLopuVc2i9 RVpfawK2qHcqA4dYXliW0pTOieTwDZp31me8YX6cu0H05yAlq9bAwf5DRqqNas6+kSVz nUlH34EgUP9pg2n/6jVRUAooiJK7XYpmCU62yaeaYokwA3Db7nUuPEe4/zGJGJIAFdJK 1zPuiASt97Ezxy7+TAjyDhEWLtvyJERK0pHd0AZC2loWSCtJV0lq1b+MZ/52SwSTamjw 01BbkOPzA6f+okzBAerIwa3DXILPGZf1MgkFCZpprGnoVKUhALOHQlZyEX+1n8QIQAvo q9mw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@esdhannover.onmicrosoft.com header.s=selector1-esdhannover-onmicrosoft-com header.b=C5RMAIC4; 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 u5-20020a170903124500b00181dc40f516si5053609plh.146.2022.12.19.13.29.29; Mon, 19 Dec 2022 13:29:42 -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=C5RMAIC4; 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 S232840AbiLSV1y (ORCPT <rfc822;abdi.embedded@gmail.com> + 99 others); Mon, 19 Dec 2022 16:27:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232777AbiLSV1i (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 19 Dec 2022 16:27:38 -0500 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on2121.outbound.protection.outlook.com [40.107.6.121]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 538BD13F09; Mon, 19 Dec 2022 13:27:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Na5J3SSkgqF1zrDNToJiSUQb8jusCRIniW2SVDT54vTIWgwimZ0RQJsp4nZHBSjp9k8IqeZ93YYTvikfyXP7/6LisryH2zRU0m7X/pLOCCCpSuccj9Wb4GiKrbKKVSQnSusykvFNkMMx8sW9iF0Psg7YcJyk/26Wa4rLiEN95Il9B8C5Kx2q26UVMwYJZK0KLwMWsJfShdjxmIJGEXEzWS5Gj/2RtgeztY43KQanc+ZmkHl4UnMH2EUeBA+5CO/imrfoAfMi1643JN0Cff8M+/snc7XdG5eOPV/3G+6qPp241LnuFIwbuNxjnVudbjXnfGQQgLuZDyP8jQjFgfs2RA== 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=CLCrW5mNwfs26NWA4N8ao2qXw+YqsWSEuJb20hNJhys=; b=G00eFTZVIABnoR9jLYtA//K7D9S/VIuQ66+/0tdZykaEAP0x3+Okka2eS6SDhBjAo7tY76Vc+uj3Bkl7+wdJ6vX2AlProh6bMlAHM4AeIUCyrhv3AxgQEdkA1Iu3vhEblOnn8iSJIUPjK+Cio3A5u7jgKbtNXdEeLCvCm+OkI1HNFmwPi1S4r80xnW3r+m6H6c4zSUQzH1fcb/LBR2gfGrgGD3OJDks8iBcbXh+S0C2harl8Qbc8+eTqKPn3vhUlYbDPJ0C9d/bCIerTBxJVnVBljG+0IuQA3j+LFpWpuR4K/P8FJEEGYFov5bTz1DK6v1QemB/e85zkrypqj8EPGw== 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=CLCrW5mNwfs26NWA4N8ao2qXw+YqsWSEuJb20hNJhys=; b=C5RMAIC4AjU4X0huCwI9A4TS7XGYzZqekXwCVOOyRo3bH9nOhGwYPdtGJcKlGh+8uE6Z5Mw6ZucOjKPZApLgVqHDLpv+pZgOIG2cM7oB9KlVqg2+1jqLPJoEbNCmISqLxYs/KoKRW++d8SXHyTrOSxQssgVnIl771IIUtZvRBY0= Received: from DB6PR07CA0187.eurprd07.prod.outlook.com (2603:10a6:6:42::17) by GV1PR03MB8710.eurprd03.prod.outlook.com (2603:10a6:150:92::6) 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 DB8EUR06FT007.eop-eur06.prod.protection.outlook.com (2603:10a6:6:42:cafe::ec) by DB6PR07CA0187.outlook.office365.com (2603:10a6:6:42::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.9 via Frontend Transport; Mon, 19 Dec 2022 21:27:29 +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 DB8EUR06FT007.mail.protection.outlook.com (10.233.252.171) with Microsoft SMTP Server id 15.20.5924.16 via Frontend Transport; Mon, 19 Dec 2022 21:27:28 +0000 Received: from esd-s20.esd.local (debby [10.0.0.190]) by esd-s7.esd (Postfix) with ESMTPS id 64E347C16C8; Mon, 19 Dec 2022 22:27:28 +0100 (CET) Received: by esd-s20.esd.local (Postfix, from userid 2046) id 5564B2E1DC1; Mon, 19 Dec 2022 22:27:28 +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 2/3] can: esd_usb: Improved behavior on esd CAN_ERROR_EXT event (2) Date: Mon, 19 Dec 2022 22:27:16 +0100 Message-Id: <20221219212717.1298282-1-frank.jungclaus@esd.eu> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB8EUR06FT007:EE_|GV1PR03MB8710:EE_ Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: a0c61598-c893-4a4d-59fa-08dae207d4e6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XpH2NmUmxbnpq67w3jmJUI5hKE3/OBt+8V5iROGekzJbq0krA6t8NFVQ//S8nzFa+QSYnnh+liz/n4TcDA76ySFEugRtJcLH8NoIulubrJuzCufoVbKUlqwC6rPBTB4ui+yeTs180eHJqHpkdyWXeJ8kujFQqnZ6PtlSqGbEv4KYmXPGPqF9tJMLzgXQZ37O9L6u9lSJuTGFMcaPyOh4AV4Kjv4qKQq/AZiWhUw86a7Rte+Gvj0tFORN2BkZmDH7Z1WLrjm/mosCj5TGLSw41HibUZKjuUzjMWtZFjLXFB9R1oI7KGJ+MhmzSw8ZFkbHZtuIJxlECKG5vHXjkIJts28G2Cw2NnVr7b0ckJpV5DwyDLZPydRQJxR03zKqZd0avEi52AhzM6WpC+BwPEDvcakIWery9q/s5ZjMONr5jWLusgntXlIlhvnSamfjgMlFy1z771PpmYVeQEA0Mk3vYjYOZsyj0dyuA7Up6Lt+06hRgtlby856fzvYD8WqCnmXa7H6ghO+Pf1wX5+peJfsdCFDNL63gPb8diO9BjTEUdvRg+Lwplzm79UNxojVmaWwzwarefWi+WOrhAObFPvDoEiZugL2PJMk2l8k50DuuR3ZnC7I1XMzIeePanmXsrOIz/QUBoU/2wAAqTF6v+k9dDXUu+ZRrqNfcibfHmm13cbzhed0exF4frZPOSVmXdBVohymZdDH9aO68qaAXOJnrg== 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)(396003)(346002)(39840400004)(376002)(136003)(451199015)(46966006)(36840700001)(70586007)(70206006)(86362001)(4326008)(8676002)(42186006)(316002)(36756003)(8936002)(5660300002)(2616005)(41300700001)(1076003)(82310400005)(6666004)(186003)(36860700001)(26005)(336012)(6266002)(47076005)(356005)(83380400001)(54906003)(40480700001)(81166007)(110136005)(478600001)(966005)(44832011)(2906002);DIR:OUT;SFP:1102; X-OriginatorOrg: esd.eu X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Dec 2022 21:27:28.9767 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a0c61598-c893-4a4d-59fa-08dae207d4e6 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: DB8EUR06FT007.eop-eur06.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR03MB8710 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?1752679456136986156?= X-GMAIL-MSGID: =?utf-8?q?1752679456136986156?= |
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
Started a rework initiated by Vincents remarks "You should not report
the greatest of txerr and rxerr but the one which actually increased."
[1] and "As far as I understand, those flags should be set only when
the threshold is *reached*" [2] .
Now setting the flags for CAN_ERR_CRTL_[RT]X_WARNING and
CAN_ERR_CRTL_[RT]X_PASSIVE regarding REC and TEC, when the
appropriate threshold is reached.
Fixes: 96d8e90382dc ("can: Add driver for esd CAN-USB/2 device")
Signed-off-by: Frank Jungclaus <frank.jungclaus@esd.eu>
Link: [1] https://lore.kernel.org/all/CAMZ6RqKGBWe15aMkf8-QLf-cOQg99GQBebSm+1wEzTqHgvmNuw@mail.gmail.com/
Link: [2] https://lore.kernel.org/all/CAMZ6Rq+QBO1yTX_o6GV0yhdBj-RzZSRGWDZBS0fs7zbSTy4hmA@mail.gmail.com/
---
drivers/net/can/usb/esd_usb.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
Comments
On Tue. 20 Dec. 2022 at 06:29, Frank Jungclaus <frank.jungclaus@esd.eu> wrote: > Started a rework initiated by Vincents remarks "You should not report > the greatest of txerr and rxerr but the one which actually increased." > [1] I do not see this comment being addressed. You are still assigning the flags depending on the highest value, not the one which actually changed. > and "As far as I understand, those flags should be set only when > the threshold is *reached*" [2] . > > Now setting the flags for CAN_ERR_CRTL_[RT]X_WARNING and > CAN_ERR_CRTL_[RT]X_PASSIVE regarding REC and TEC, when the > appropriate threshold is reached. > > Fixes: 96d8e90382dc ("can: Add driver for esd CAN-USB/2 device") > Signed-off-by: Frank Jungclaus <frank.jungclaus@esd.eu> > Link: [1] https://lore.kernel.org/all/CAMZ6RqKGBWe15aMkf8-QLf-cOQg99GQBebSm+1wEzTqHgvmNuw@mail.gmail.com/ > Link: [2] https://lore.kernel.org/all/CAMZ6Rq+QBO1yTX_o6GV0yhdBj-RzZSRGWDZBS0fs7zbSTy4hmA@mail.gmail.com/ > --- > drivers/net/can/usb/esd_usb.c | 14 ++++++++------ > 1 file changed, 8 insertions(+), 6 deletions(-) > > diff --git a/drivers/net/can/usb/esd_usb.c b/drivers/net/can/usb/esd_usb.c > index 5e182fadd875..09745751f168 100644 > --- a/drivers/net/can/usb/esd_usb.c > +++ b/drivers/net/can/usb/esd_usb.c > @@ -255,10 +255,18 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv, > can_bus_off(priv->netdev); > break; > case ESD_BUSSTATE_WARN: > + cf->can_id |= CAN_ERR_CRTL; > + cf->data[1] = (txerr > rxerr) ? > + CAN_ERR_CRTL_TX_WARNING : > + CAN_ERR_CRTL_RX_WARNING; Nitpick: when a ternary operator is too long to fit on one line, prefer an if/else. > priv->can.state = CAN_STATE_ERROR_WARNING; > priv->can.can_stats.error_warning++; > break; > case ESD_BUSSTATE_ERRPASSIVE: > + cf->can_id |= CAN_ERR_CRTL; > + cf->data[1] = (txerr > rxerr) ? > + CAN_ERR_CRTL_TX_PASSIVE : > + CAN_ERR_CRTL_RX_PASSIVE; Same. > priv->can.state = CAN_STATE_ERROR_PASSIVE; > priv->can.can_stats.error_passive++; > break; > @@ -296,12 +304,6 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv, > /* Bit stream position in CAN frame as the error was detected */ > cf->data[3] = ecc & SJA1000_ECC_SEG; > > - if (priv->can.state == CAN_STATE_ERROR_WARNING || > - priv->can.state == CAN_STATE_ERROR_PASSIVE) { > - cf->data[1] = (txerr > rxerr) ? > - CAN_ERR_CRTL_TX_PASSIVE : > - CAN_ERR_CRTL_RX_PASSIVE; > - } > cf->data[6] = txerr; > cf->data[7] = rxerr; > } Yours sincerely, Vincent Mailhol
On Tue, 2022-12-20 at 14:49 +0900, Vincent MAILHOL wrote: > On Tue. 20 Dec. 2022 at 06:29, Frank Jungclaus <frank.jungclaus@esd.eu> wrote: > > Started a rework initiated by Vincents remarks "You should not report > > the greatest of txerr and rxerr but the one which actually increased." > > [1] > > I do not see this comment being addressed. You are still assigning the > flags depending on the highest value, not the one which actually > changed. Yes, I'm assigning depending on the highest value, but from my point of view doing so is analogue to what is done by can_change_state(). And it should be fine, because e.g. my "case ESD_BUSSTATE_WARN:" is reached exactly once while the transition from ERROR_ACTIVE to ERROR_WARN. Than one of rec or tec is responsible for this transition. There is no second pass for "case ESD_BUSSTATE_WARN:" when e.g. rec is already on WARN (or above) and now tec also reaches WARN. Man, this is even difficult to explain in German language ;) > > > and "As far as I understand, those flags should be set only when > > the threshold is *reached*" [2] . > > > > Now setting the flags for CAN_ERR_CRTL_[RT]X_WARNING and > > CAN_ERR_CRTL_[RT]X_PASSIVE regarding REC and TEC, when the > > appropriate threshold is reached. > > > > Fixes: 96d8e90382dc ("can: Add driver for esd CAN-USB/2 device") > > Signed-off-by: Frank Jungclaus <frank.jungclaus@esd.eu> > > Link: [1] https://lore.kernel.org/all/CAMZ6RqKGBWe15aMkf8-QLf-cOQg99GQBebSm+1wEzTqHgvmNuw@mail.gmail.com/ > > Link: [2] https://lore.kernel.org/all/CAMZ6Rq+QBO1yTX_o6GV0yhdBj-RzZSRGWDZBS0fs7zbSTy4hmA@mail.gmail.com/ > > --- > > drivers/net/can/usb/esd_usb.c | 14 ++++++++------ > > 1 file changed, 8 insertions(+), 6 deletions(-) > > > > diff --git a/drivers/net/can/usb/esd_usb.c b/drivers/net/can/usb/esd_usb.c > > index 5e182fadd875..09745751f168 100644 > > --- a/drivers/net/can/usb/esd_usb.c > > +++ b/drivers/net/can/usb/esd_usb.c > > @@ -255,10 +255,18 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv, > > can_bus_off(priv->netdev); > > break; > > case ESD_BUSSTATE_WARN: > > + cf->can_id |= CAN_ERR_CRTL; > > + cf->data[1] = (txerr > rxerr) ? > > + CAN_ERR_CRTL_TX_WARNING : > > + CAN_ERR_CRTL_RX_WARNING; > > Nitpick: when a ternary operator is too long to fit on one line, > prefer an if/else. AFAIR line length up to 120 chars is tolerated nowadays. So putting this on a single line might also be an option!(?) How will this be handled in the CAN sub tree? > > > priv->can.state = CAN_STATE_ERROR_WARNING; > > priv->can.can_stats.error_warning++; > > break; > > case ESD_BUSSTATE_ERRPASSIVE: > > + cf->can_id |= CAN_ERR_CRTL; > > + cf->data[1] = (txerr > rxerr) ? > > + CAN_ERR_CRTL_TX_PASSIVE : > > + CAN_ERR_CRTL_RX_PASSIVE; > > Same. > > > priv->can.state = CAN_STATE_ERROR_PASSIVE; > > priv->can.can_stats.error_passive++; > > break; > > @@ -296,12 +304,6 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv, > > /* Bit stream position in CAN frame as the error was detected */ > > cf->data[3] = ecc & SJA1000_ECC_SEG; > > > > - if (priv->can.state == CAN_STATE_ERROR_WARNING || > > - priv->can.state == CAN_STATE_ERROR_PASSIVE) { > > - cf->data[1] = (txerr > rxerr) ? > > - CAN_ERR_CRTL_TX_PASSIVE : > > - CAN_ERR_CRTL_RX_PASSIVE; > > - } > > cf->data[6] = txerr; > > cf->data[7] = rxerr; > > } > > Yours sincerely, > Vincent Mailhol
On Thu. 22 Dec. 2022 at 03:42, Frank Jungclaus <Frank.Jungclaus@esd.eu> wrote: > On Tue, 2022-12-20 at 14:49 +0900, Vincent MAILHOL wrote: > > On Tue. 20 Dec. 2022 at 06:29, Frank Jungclaus <frank.jungclaus@esd.eu> wrote: > > > Started a rework initiated by Vincents remarks "You should not report > > > the greatest of txerr and rxerr but the one which actually increased." > > > [1] > > > > I do not see this comment being addressed. You are still assigning the > > flags depending on the highest value, not the one which actually > > changed. > > > Yes, I'm assigning depending on the highest value, but from my point of > view doing so is analogue to what is done by can_change_state(). On the surface, it may look similar. But if you look into details, can_change_state() is only called when there is a change on enum can_state. enum can_state is the global state and does not differentiate the RX and TX. I will give an example. Imagine that: - txerr is 128 (ERROR_PASSIVE) - rxerr is 95 (ERROR_ACTIVE) Imagine that rxerr then increases to 96. If you call can_change_state() under this condition, the old state: can_priv->state is still equal to the new one: max(tx_state, rx_state) and you would get the oops message: https://elixir.bootlin.com/linux/latest/source/drivers/net/can/dev/dev.c#L100 So can_change_state() is indeed correct because it excludes the case when the smallest err counter changed. > And > it should be fine, because e.g. my "case ESD_BUSSTATE_WARN:" is reached > exactly once while the transition from ERROR_ACTIVE to > ERROR_WARN. Than one of rec or tec is responsible for this > transition. > There is no second pass for "case ESD_BUSSTATE_WARN:" > when e.g. rec is already on WARN (or above) and now tec also reaches > WARN. > Man, this is even difficult to explain in German language ;) OK. This is new information. I agree that it should work. But I am still puzzled because the code doesn't make this limitation apparent. Also, as long as you have the rxerr and txerr value, you should still be able to set the correct flag by comparing the err counters instead of relying on your device events. I am thinking of something like this: enum can_state can_get_state_from_err_cnt(u16 berr_counter) { if (berr_counter >= CAN_BUS_OFF_THRESHOLD) return CAN_STATE_BUS_OFF; if (berr_counter >= CAN_ERROR_PASSIVE_THRESHOLD) return CAN_STATE_ERROR_PASSIVE; if (berr_counter >= CAN_ERROR_WARNING_THRESHOLD) return CAN_STATE_ERROR_WARNING; return CAN_STATE_ERROR_ACTIVE; } EXPORT_SYMBOL_GPL(can_get_state_from_err_cnt); void can_frame_set_error_status(struct net_device *dev, struct can_frame *cf, struct can_berr_counter *old_ctr, struct can_berr_counter *new_ctr) { enum can_state old_state, new_state; /* TX err cnt */ old_state = can_get_state_from_err_cnt(old_ctr->txerr); new_state = can_get_state_from_err_cnt(new_ctr->txerr); if (old_state != new_state) cf->data[1] |= can_tx_state_to_frame(dev, new_state); /* RX err cnt */ old_state = can_get_state_from_err_cnt(old_ctr->rxerr); new_state = can_get_state_from_err_cnt(new_ctr->rxerr); if (old_state != new_state) cf->data[1] |= can_rx_state_to_frame(dev, new_state); } EXPORT_SYMBOL_GPL(can_set_error_status); If this looks good to you, I can put this in a patch (N.B. code not tested! But should be enough for you to get the idea). > > > > > and "As far as I understand, those flags should be set only when > > > the threshold is *reached*" [2] . > > > > > > Now setting the flags for CAN_ERR_CRTL_[RT]X_WARNING and > > > CAN_ERR_CRTL_[RT]X_PASSIVE regarding REC and TEC, when the > > > appropriate threshold is reached. > > > > > > Fixes: 96d8e90382dc ("can: Add driver for esd CAN-USB/2 device") > > > Signed-off-by: Frank Jungclaus <frank.jungclaus@esd.eu> > > > Link: [1] https://lore.kernel.org/all/CAMZ6RqKGBWe15aMkf8-QLf-cOQg99GQBebSm+1wEzTqHgvmNuw@mail.gmail.com/ > > > Link: [2] https://lore.kernel.org/all/CAMZ6Rq+QBO1yTX_o6GV0yhdBj-RzZSRGWDZBS0fs7zbSTy4hmA@mail.gmail.com/ > > > --- > > > drivers/net/can/usb/esd_usb.c | 14 ++++++++------ > > > 1 file changed, 8 insertions(+), 6 deletions(-) > > > > > > diff --git a/drivers/net/can/usb/esd_usb.c b/drivers/net/can/usb/esd_usb.c > > > index 5e182fadd875..09745751f168 100644 > > > --- a/drivers/net/can/usb/esd_usb.c > > > +++ b/drivers/net/can/usb/esd_usb.c > > > @@ -255,10 +255,18 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv, > > > can_bus_off(priv->netdev); > > > break; > > > case ESD_BUSSTATE_WARN: > > > + cf->can_id |= CAN_ERR_CRTL; > > > + cf->data[1] = (txerr > rxerr) ? > > > + CAN_ERR_CRTL_TX_WARNING : > > > + CAN_ERR_CRTL_RX_WARNING; > > > > Nitpick: when a ternary operator is too long to fit on one line, > > prefer an if/else. > > AFAIR line length up to 120 chars is tolerated nowadays. So putting > this on a single line might also be an option!(?) > How will this be handled in the CAN sub tree? Correct. The 120 is tolerated but the recommendation remains the 80 characters. I am not supportive of squeezing things and making this a ~120 characters line. Also, this is a nitpick. I will not fight for you to change it. Just be aware that there are often comments on the mailing list asking not to use ternary operators (and I will not do an archivist job to find such messages). > > > > > priv->can.state = CAN_STATE_ERROR_WARNING; > > > priv->can.can_stats.error_warning++; > > > break; > > > case ESD_BUSSTATE_ERRPASSIVE: > > > + cf->can_id |= CAN_ERR_CRTL; > > > + cf->data[1] = (txerr > rxerr) ? > > > + CAN_ERR_CRTL_TX_PASSIVE : > > > + CAN_ERR_CRTL_RX_PASSIVE; > > > > Same. > > > > > priv->can.state = CAN_STATE_ERROR_PASSIVE; > > > priv->can.can_stats.error_passive++; > > > break; > > > @@ -296,12 +304,6 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv, > > > /* Bit stream position in CAN frame as the error was detected */ > > > cf->data[3] = ecc & SJA1000_ECC_SEG; > > > > > > - if (priv->can.state == CAN_STATE_ERROR_WARNING || > > > - priv->can.state == CAN_STATE_ERROR_PASSIVE) { > > > - cf->data[1] = (txerr > rxerr) ? > > > - CAN_ERR_CRTL_TX_PASSIVE : > > > - CAN_ERR_CRTL_RX_PASSIVE; > > > - } > > > cf->data[6] = txerr; > > > cf->data[7] = rxerr; > > > } > > > > Yours sincerely, > > Vincent Mailhol
On Thu, 2022-12-22 at 11:21 +0900, Vincent MAILHOL wrote: > On Thu. 22 Dec. 2022 at 03:42, Frank Jungclaus <Frank.Jungclaus@esd.eu> wrote: > > On Tue, 2022-12-20 at 14:49 +0900, Vincent MAILHOL wrote: > > > On Tue. 20 Dec. 2022 at 06:29, Frank Jungclaus <frank.jungclaus@esd.eu> wrote: > > > > Started a rework initiated by Vincents remarks "You should not report > > > > the greatest of txerr and rxerr but the one which actually increased." > > > > [1] > > > > > > I do not see this comment being addressed. You are still assigning the > > > flags depending on the highest value, not the one which actually > > > changed. > > > > > > Yes, I'm assigning depending on the highest value, but from my point of > > view doing so is analogue to what is done by can_change_state(). > > On the surface, it may look similar. But if you look into details, > can_change_state() is only called when there is a change on enum > can_state. enum can_state is the global state and does not > differentiate the RX and TX. > > I will give an example. Imagine that: > > - txerr is 128 (ERROR_PASSIVE) > - rxerr is 95 (ERROR_ACTIVE) > > Imagine that rxerr then increases to 96. If you call > can_change_state() under this condition, the old state: > can_priv->state is still equal to the new one: max(tx_state, rx_state) > and you would get the oops message: > > https://elixir.bootlin.com/linux/latest/source/drivers/net/can/dev/dev.c#L100 > > So can_change_state() is indeed correct because it excludes the case > when the smallest err counter changed. > > > And > > it should be fine, because e.g. my "case ESD_BUSSTATE_WARN:" is reached > > exactly once while the transition from ERROR_ACTIVE to > > ERROR_WARN. Than one of rec or tec is responsible for this > > transition. > > There is no second pass for "case ESD_BUSSTATE_WARN:" > > when e.g. rec is already on WARN (or above) and now tec also reaches > > WARN. > > Man, this is even difficult to explain in German language ;) > > OK. This is new information. I agree that it should work. But I am > still puzzled because the code doesn't make this limitation apparent. > > Also, as long as you have the rxerr and txerr value, you should still > be able to set the correct flag by comparing the err counters instead > of relying on your device events. > I agree, this would be an option. But I dislike the fact that then - beside the USB firmware - there is a second instance which decides on the bus state. I'll send a reworked patch which makes use of can_change_state(). Hopefully that will address your concerns ;) This also will fix the imperfection, that our current code e.g. does an error_warning++ when going back in direction of ERROR_ACTIVE ... > I am thinking of something like this: > > > enum can_state can_get_state_from_err_cnt(u16 berr_counter) > { > if (berr_counter >= CAN_BUS_OFF_THRESHOLD) > return CAN_STATE_BUS_OFF; > > if (berr_counter >= CAN_ERROR_PASSIVE_THRESHOLD) > return CAN_STATE_ERROR_PASSIVE; > > if (berr_counter >= CAN_ERROR_WARNING_THRESHOLD) > return CAN_STATE_ERROR_WARNING; > > return CAN_STATE_ERROR_ACTIVE; > } > EXPORT_SYMBOL_GPL(can_get_state_from_err_cnt); > > void can_frame_set_error_status(struct net_device *dev, struct can_frame *cf, > struct can_berr_counter *old_ctr, > struct can_berr_counter *new_ctr) > { > enum can_state old_state, new_state; > > /* TX err cnt */ > old_state = can_get_state_from_err_cnt(old_ctr->txerr); > new_state = can_get_state_from_err_cnt(new_ctr->txerr); > if (old_state != new_state) > cf->data[1] |= can_tx_state_to_frame(dev, new_state); > > /* RX err cnt */ > old_state = can_get_state_from_err_cnt(old_ctr->rxerr); > new_state = can_get_state_from_err_cnt(new_ctr->rxerr); > if (old_state != new_state) > cf->data[1] |= can_rx_state_to_frame(dev, new_state); > } > EXPORT_SYMBOL_GPL(can_set_error_status); > > > If this looks good to you, I can put this in a patch (N.B. code not > tested! But should be enough for you to get the idea). > > > > > > > > and "As far as I understand, those flags should be set only when > > > > the threshold is *reached*" [2] . > > > > > > > > Now setting the flags for CAN_ERR_CRTL_[RT]X_WARNING and > > > > CAN_ERR_CRTL_[RT]X_PASSIVE regarding REC and TEC, when the > > > > appropriate threshold is reached. > > > > > > > > Fixes: 96d8e90382dc ("can: Add driver for esd CAN-USB/2 device") > > > > Signed-off-by: Frank Jungclaus <frank.jungclaus@esd.eu> > > > > Link: [1] https://lore.kernel.org/all/CAMZ6RqKGBWe15aMkf8-QLf-cOQg99GQBebSm+1wEzTqHgvmNuw@mail.gmail.com/ > > > > Link: [2] https://lore.kernel.org/all/CAMZ6Rq+QBO1yTX_o6GV0yhdBj-RzZSRGWDZBS0fs7zbSTy4hmA@mail.gmail.com/ > > > > --- > > > > drivers/net/can/usb/esd_usb.c | 14 ++++++++------ > > > > 1 file changed, 8 insertions(+), 6 deletions(-) > > > > > > > > diff --git a/drivers/net/can/usb/esd_usb.c b/drivers/net/can/usb/esd_usb.c > > > > index 5e182fadd875..09745751f168 100644 > > > > --- a/drivers/net/can/usb/esd_usb.c > > > > +++ b/drivers/net/can/usb/esd_usb.c > > > > @@ -255,10 +255,18 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv, > > > > can_bus_off(priv->netdev); > > > > break; > > > > case ESD_BUSSTATE_WARN: > > > > + cf->can_id |= CAN_ERR_CRTL; > > > > + cf->data[1] = (txerr > rxerr) ? > > > > + CAN_ERR_CRTL_TX_WARNING : > > > > + CAN_ERR_CRTL_RX_WARNING; > > > > > > Nitpick: when a ternary operator is too long to fit on one line, > > > prefer an if/else. > > > > AFAIR line length up to 120 chars is tolerated nowadays. So putting > > this on a single line might also be an option!(?) > > How will this be handled in the CAN sub tree? > > Correct. The 120 is tolerated but the recommendation remains the 80 > characters. I am not supportive of squeezing things and making this a > ~120 characters line. > > Also, this is a nitpick. I will not fight for you to change it. Just > be aware that there are often comments on the mailing list asking not > to use ternary operators (and I will not do an archivist job to find > such messages). > > > > > > > > priv->can.state = CAN_STATE_ERROR_WARNING; > > > > priv->can.can_stats.error_warning++; > > > > break; > > > > case ESD_BUSSTATE_ERRPASSIVE: > > > > + cf->can_id |= CAN_ERR_CRTL; > > > > + cf->data[1] = (txerr > rxerr) ? > > > > + CAN_ERR_CRTL_TX_PASSIVE : > > > > + CAN_ERR_CRTL_RX_PASSIVE; > > > > > > Same. > > > > > > > priv->can.state = CAN_STATE_ERROR_PASSIVE; > > > > priv->can.can_stats.error_passive++; > > > > break; > > > > @@ -296,12 +304,6 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv, > > > > /* Bit stream position in CAN frame as the error was detected */ > > > > cf->data[3] = ecc & SJA1000_ECC_SEG; > > > > > > > > - if (priv->can.state == CAN_STATE_ERROR_WARNING || > > > > - priv->can.state == CAN_STATE_ERROR_PASSIVE) { > > > > - cf->data[1] = (txerr > rxerr) ? > > > > - CAN_ERR_CRTL_TX_PASSIVE : > > > > - CAN_ERR_CRTL_RX_PASSIVE; > > > > - } > > > > cf->data[6] = txerr; > > > > cf->data[7] = rxerr; > > > > } > > > > > > Yours sincerely, > > > Vincent Mailhol
On 23.01.2023 15:47:22, Frank Jungclaus wrote: > On Thu, 2022-12-22 at 11:21 +0900, Vincent MAILHOL wrote: > > On Thu. 22 Dec. 2022 at 03:42, Frank Jungclaus <Frank.Jungclaus@esd.eu> wrote: > > > On Tue, 2022-12-20 at 14:49 +0900, Vincent MAILHOL wrote: > > > > On Tue. 20 Dec. 2022 at 06:29, Frank Jungclaus <frank.jungclaus@esd.eu> wrote: > > > > > Started a rework initiated by Vincents remarks "You should not report > > > > > the greatest of txerr and rxerr but the one which actually increased." > > > > > [1] > > > > > > > > I do not see this comment being addressed. You are still assigning the > > > > flags depending on the highest value, not the one which actually > > > > changed. > > > > > > > > > Yes, I'm assigning depending on the highest value, but from my point of > > > view doing so is analogue to what is done by can_change_state(). > > > > On the surface, it may look similar. But if you look into details, > > can_change_state() is only called when there is a change on enum > > can_state. enum can_state is the global state and does not > > differentiate the RX and TX. > > > > I will give an example. Imagine that: > > > > - txerr is 128 (ERROR_PASSIVE) > > - rxerr is 95 (ERROR_ACTIVE) > > > > Imagine that rxerr then increases to 96. If you call > > can_change_state() under this condition, the old state: > > can_priv->state is still equal to the new one: max(tx_state, rx_state) > > and you would get the oops message: > > > > https://elixir.bootlin.com/linux/latest/source/drivers/net/can/dev/dev.c#L100 > > > > So can_change_state() is indeed correct because it excludes the case > > when the smallest err counter changed. > > > > > And > > > it should be fine, because e.g. my "case ESD_BUSSTATE_WARN:" is reached > > > exactly once while the transition from ERROR_ACTIVE to > > > ERROR_WARN. Than one of rec or tec is responsible for this > > > transition. > > > There is no second pass for "case ESD_BUSSTATE_WARN:" > > > when e.g. rec is already on WARN (or above) and now tec also reaches > > > WARN. > > > Man, this is even difficult to explain in German language ;) > > > > OK. This is new information. I agree that it should work. But I am > > still puzzled because the code doesn't make this limitation apparent. > > > > Also, as long as you have the rxerr and txerr value, you should still > > be able to set the correct flag by comparing the err counters instead > > of relying on your device events. > > > > I agree, this would be an option. But I dislike the fact that then > - beside the USB firmware - there is a second instance which decides on > the bus state. I'll send a reworked patch which makes use of ^^^^^^^^^^^^^^^^^^^^^ > can_change_state(). Hopefully that will address your concerns ;) > This also will fix the imperfection, that our current code e.g. does > an error_warning++ when going back in direction of ERROR_ACTIVE ... Not taking this series, waiting for the reworked version. Marc
On Thu, 2023-02-02 at 16:22 +0100, Marc Kleine-Budde wrote: > On 23.01.2023 15:47:22, Frank Jungclaus wrote: > > On Thu, 2022-12-22 at 11:21 +0900, Vincent MAILHOL wrote: > > > On Thu. 22 Dec. 2022 at 03:42, Frank Jungclaus <Frank.Jungclaus@esd.eu> wrote: > > > > On Tue, 2022-12-20 at 14:49 +0900, Vincent MAILHOL wrote: > > > > > On Tue. 20 Dec. 2022 at 06:29, Frank Jungclaus <frank.jungclaus@esd.eu> wrote: > > > > > > Started a rework initiated by Vincents remarks "You should not report > > > > > > the greatest of txerr and rxerr but the one which actually increased." > > > > > > [1] > > > > > > > > > > I do not see this comment being addressed. You are still assigning the > > > > > flags depending on the highest value, not the one which actually > > > > > changed. > > > > > > > > > > > > Yes, I'm assigning depending on the highest value, but from my point of > > > > view doing so is analogue to what is done by can_change_state(). > > > > > > On the surface, it may look similar. But if you look into details, > > > can_change_state() is only called when there is a change on enum > > > can_state. enum can_state is the global state and does not > > > differentiate the RX and TX. > > > > > > I will give an example. Imagine that: > > > > > > - txerr is 128 (ERROR_PASSIVE) > > > - rxerr is 95 (ERROR_ACTIVE) > > > > > > Imagine that rxerr then increases to 96. If you call > > > can_change_state() under this condition, the old state: > > > can_priv->state is still equal to the new one: max(tx_state, rx_state) > > > and you would get the oops message: > > > > > > https://elixir.bootlin.com/linux/latest/source/drivers/net/can/dev/dev.c#L100 > > > > > > So can_change_state() is indeed correct because it excludes the case > > > when the smallest err counter changed. > > > > > > > And > > > > it should be fine, because e.g. my "case ESD_BUSSTATE_WARN:" is reached > > > > exactly once while the transition from ERROR_ACTIVE to > > > > ERROR_WARN. Than one of rec or tec is responsible for this > > > > transition. > > > > There is no second pass for "case ESD_BUSSTATE_WARN:" > > > > when e.g. rec is already on WARN (or above) and now tec also reaches > > > > WARN. > > > > Man, this is even difficult to explain in German language ;) > > > > > > OK. This is new information. I agree that it should work. But I am > > > still puzzled because the code doesn't make this limitation apparent. > > > > > > Also, as long as you have the rxerr and txerr value, you should still > > > be able to set the correct flag by comparing the err counters instead > > > of relying on your device events. > > > > > > > I agree, this would be an option. But I dislike the fact that then > > - beside the USB firmware - there is a second instance which decides on > > the bus state. I'll send a reworked patch which makes use of > ^^^^^^^^^^^^^^^^^^^^^ > > can_change_state(). Hopefully that will address your concerns ;) > > This also will fix the imperfection, that our current code e.g. does > > an error_warning++ when going back in direction of ERROR_ACTIVE ... > > Not taking this series, waiting for the reworked version. > > Marc > Marc, can I just send a reworked patch of [PATCH 2/3], let's say with subject [PATCH v2 2/3] as a reply to this thread or should I better resend the complete patch series as [PATCH v2 0/3] up to [PATCH v2 3/3]? Regards Frank
On 09.02.2023 19:00:54, Frank Jungclaus wrote: > > Not taking this series, waiting for the reworked version. > > > > Marc > > > Marc, can I just send a reworked patch of [PATCH 2/3], let's say > with subject [PATCH v2 2/3] as a reply to this thread or should I > better resend the complete patch series as [PATCH v2 0/3] up to > [PATCH v2 3/3]? Just re-post the whole series. Complete series are easier to handle. Marc
diff --git a/drivers/net/can/usb/esd_usb.c b/drivers/net/can/usb/esd_usb.c index 5e182fadd875..09745751f168 100644 --- a/drivers/net/can/usb/esd_usb.c +++ b/drivers/net/can/usb/esd_usb.c @@ -255,10 +255,18 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv, can_bus_off(priv->netdev); break; case ESD_BUSSTATE_WARN: + cf->can_id |= CAN_ERR_CRTL; + cf->data[1] = (txerr > rxerr) ? + CAN_ERR_CRTL_TX_WARNING : + CAN_ERR_CRTL_RX_WARNING; priv->can.state = CAN_STATE_ERROR_WARNING; priv->can.can_stats.error_warning++; break; case ESD_BUSSTATE_ERRPASSIVE: + cf->can_id |= CAN_ERR_CRTL; + cf->data[1] = (txerr > rxerr) ? + CAN_ERR_CRTL_TX_PASSIVE : + CAN_ERR_CRTL_RX_PASSIVE; priv->can.state = CAN_STATE_ERROR_PASSIVE; priv->can.can_stats.error_passive++; break; @@ -296,12 +304,6 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv, /* Bit stream position in CAN frame as the error was detected */ cf->data[3] = ecc & SJA1000_ECC_SEG; - if (priv->can.state == CAN_STATE_ERROR_WARNING || - priv->can.state == CAN_STATE_ERROR_PASSIVE) { - cf->data[1] = (txerr > rxerr) ? - CAN_ERR_CRTL_TX_PASSIVE : - CAN_ERR_CRTL_RX_PASSIVE; - } cf->data[6] = txerr; cf->data[7] = rxerr; }