Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1155578iog; Mon, 13 Jun 2022 23:36:22 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tKFdr1WZn+1bMX06m9IGQT/b55Fk5VNZCiEn4w1sz6BVS0BPgfO0QS9BBTY/uwhys6qITv X-Received: by 2002:a17:902:cccc:b0:15a:30ec:2f56 with SMTP id z12-20020a170902cccc00b0015a30ec2f56mr3105789ple.169.1655188582390; Mon, 13 Jun 2022 23:36:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655188582; cv=none; d=google.com; s=arc-20160816; b=p0wPPZWNNSi9GRmC18StUu6Yw8B3jsksuxU0ixU8OYJjMJqFmQkkZtzMZSqyBxOrB6 2TgO3hQFS/fPV8RpbFOb9sLXiavmtOG49eE61r+UTCLPoYatTrxuOJu0ZLsb23esdsQD 5Jmh7YwLZm/d63AqFwFKgSUpbzmtJTKonxTruUbEww61JqoOekXKhFj5bLO75+iVBWrt NO9gKmMf+4B6i0kLCVb5AEKGqAfQ8qy9r7nZODYuukVqZ+uroXy6zbcvfHploJsv//W4 r8kl3r3CfYul4hFsM6k0rYDGqkSBgnEoNaSlCnd/D0UgCreMN3vakTmKkANq/wIhSVWC cOtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=p/NRQuFI8tEQXP2R7fZneo4JlnHTbiMdQlJzFDy5/J8=; b=FRf+A7P0qiRE8uNANM9basANWpGhO+wQKt7dojuY8R9G+DN+sMSKaOhufR77ZeVk7E MxXdn4ShlEas09NIZHmgAGVX+O/Bq+PLSmoIUO9U6XgZ+PTupB4hJAVQ8nHM4SHEhV37 duFRRV3Hun3dQhoMedMrW08H37xd4oZZg3ciqho0t06VrlCSmjQMRn7TikbbEzk+FDSq FVvYsnwg+ZSqIb83zn5QNGjcuciFqZ4/UQ+s1droJb1u8RuCENcKp3GIjaaDf0NlVtKs 1hjJnerYb40pcMzzX67396uetfMQ7RUtHypAtF+Qfbza4vwbZO+6vwFHJcbAHx8Q9E7i xfFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="lrFPz/wx"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h9-20020a17090aea8900b001df6f1c3c04si14426751pjz.44.2022.06.13.23.36.09; Mon, 13 Jun 2022 23:36:22 -0700 (PDT) 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=@amarulasolutions.com header.s=google header.b="lrFPz/wx"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232690AbiFNGaO (ORCPT + 99 others); Tue, 14 Jun 2022 02:30:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234405AbiFNGaM (ORCPT ); Tue, 14 Jun 2022 02:30:12 -0400 Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A71101A053 for ; Mon, 13 Jun 2022 23:30:10 -0700 (PDT) Received: by mail-lj1-x22c.google.com with SMTP id e4so8609832ljl.1 for ; Mon, 13 Jun 2022 23:30:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=p/NRQuFI8tEQXP2R7fZneo4JlnHTbiMdQlJzFDy5/J8=; b=lrFPz/wx6XrLQGNEu8CKre9K0jQFp+dy8jJWh3TUwhh2UVTs3Vp7U+HSRra96066F5 7sp86ZpCsDXLu3zdEVYRFErGjFwESqminOPfQAd7rgdXOEDkwQv+E+gY7/cJQzrvb2/G YMiDBQUrTt6RzIyR5nGUQqa2mxdTBz85+Zgvo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=p/NRQuFI8tEQXP2R7fZneo4JlnHTbiMdQlJzFDy5/J8=; b=5ymEWd345+PxuNw06SNlsw0G1OXZ7DNsj82gFDpXVj8kn0v0nGdB2glYDuaAi4bwma j6AtnPomlRmdxHT3vWv21Emx6V54/a2eG5zrFwrJlFbX02zUqouwnxKVXqQ8Rp/8KYfv Ex9zYHChS7cJ9c/73g0IHp4VY6pO8YhrvgNFv/KKwikMdrNJhV7iBh2xvKCBCT/MiYPv 05wQeo/X5LIVQNORv0zslrxMu7cfJzcjNrvbXkYN0ocONGW0Q8vNRd3leAh0IyP+cxFJ coGd7uLvZ1Ce4qT1tSj1dGKcw5MkPXPMwmN4pWiPxid/aLuVBlhAfps/X8y6S9CIftxM Mc9w== X-Gm-Message-State: AJIora/AQtstKYJCJswS4R/oVP9lj+4RmfImVfXn1u/R6eTkNnmz36j9 f3zMSmtUUPmKTTSNk/pPFi+NTIiQk4tDfu1JIMMX0Q== X-Received: by 2002:a2e:9609:0:b0:255:8364:9fd8 with SMTP id v9-20020a2e9609000000b0025583649fd8mr1611482ljh.132.1655188208918; Mon, 13 Jun 2022 23:30:08 -0700 (PDT) MIME-Version: 1.0 References: <20220612213927.3004444-1-dario.binacchi@amarulasolutions.com> <20220612213927.3004444-14-dario.binacchi@amarulasolutions.com> <20220613073706.rk3bve57zi2p3nnz@pengutronix.de> In-Reply-To: <20220613073706.rk3bve57zi2p3nnz@pengutronix.de> From: Dario Binacchi Date: Tue, 14 Jun 2022 08:29:57 +0200 Message-ID: Subject: Re: [PATCH v3 13/13] can: slcan: extend the protocol with CAN state info To: Marc Kleine-Budde Cc: linux-kernel@vger.kernel.org, michael@amarulasolutions.com, Amarula patchwork , Oliver Hartkopp , "David S. Miller" , Eric Dumazet , Greg Kroah-Hartman , Jakub Kicinski , Jiri Slaby , Paolo Abeni , Sebastian Andrzej Siewior , Vincent Mailhol , Wolfgang Grandegger , linux-can@vger.kernel.org, netdev@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 13, 2022 at 9:37 AM Marc Kleine-Budde wrote: > > On 12.06.2022 23:39:27, Dario Binacchi wrote: > > It extends the protocol to receive the adapter CAN state changes > > (warning, busoff, etc.) and forward them to the netdev upper levels. > > > > Signed-off-by: Dario Binacchi > > > > --- > > > > Changes in v3: > > - Drop the patch "can: slcan: simplify the device de-allocation". > > - Add the patch "can: netlink: dump bitrate 0 if can_priv::bittiming.bitrate is -1U". > > > > Changes in v2: > > - Continue error handling even if no skb can be allocated. > > > > drivers/net/can/slcan/slcan-core.c | 66 ++++++++++++++++++++++++++++++ > > 1 file changed, 66 insertions(+) > > > > diff --git a/drivers/net/can/slcan/slcan-core.c b/drivers/net/can/slcan/slcan-core.c > > index 48077edb9497..5ba1c141f942 100644 > > --- a/drivers/net/can/slcan/slcan-core.c > > +++ b/drivers/net/can/slcan/slcan-core.c > > @@ -78,6 +78,9 @@ MODULE_PARM_DESC(maxdev, "Maximum number of slcan interfaces"); > > #define SLC_CMD_LEN 1 > > #define SLC_SFF_ID_LEN 3 > > #define SLC_EFF_ID_LEN 8 > > +#define SLC_STATE_LEN 1 > > +#define SLC_STATE_BE_RXCNT_LEN 3 > > +#define SLC_STATE_BE_TXCNT_LEN 3 > > > > struct slcan { > > struct can_priv can; > > @@ -175,6 +178,67 @@ int slcan_enable_err_rst_on_open(struct net_device *ndev, bool on) > > * STANDARD SLCAN DECAPSULATION * > > ************************************************************************/ > > > > +static void slc_bump_state(struct slcan *sl) > > +{ > > + struct net_device *dev = sl->dev; > > + struct sk_buff *skb; > > + struct can_frame *cf; > > + char *cmd = sl->rbuff; > > + u32 rxerr, txerr; > > + enum can_state state, rx_state, tx_state; > > + > > + if (*cmd != 's') > > + return; > > Checked by the caller? > > > + > > + cmd += SLC_CMD_LEN; > > + switch (*cmd) { > > + case 'a': > > + state = CAN_STATE_ERROR_ACTIVE; > > + break; > > + case 'w': > > + state = CAN_STATE_ERROR_WARNING; > > + break; > > + case 'p': > > + state = CAN_STATE_ERROR_PASSIVE; > > + break; > > + case 'f': > > + state = CAN_STATE_BUS_OFF; > > + break; > > + default: > > + return; > > + } > > + > > + if (state == sl->can.state) > > + return; > > + > > + cmd += SLC_STATE_BE_RXCNT_LEN + 1; > > Have you checked that you have received that much data? > > > + cmd[SLC_STATE_BE_TXCNT_LEN] = 0; > > + if (kstrtou32(cmd, 10, &txerr)) > > + return; > > + > > + *cmd = 0; > > + cmd -= SLC_STATE_BE_RXCNT_LEN; > > + if (kstrtou32(cmd, 10, &rxerr)) > > + return; > > Why do you parse TX first and then RX? Since adding the end-of-string character to the counter to be decoded invalidates the next one. If I had started from the rx counter, I would have found the transmission counter always at 0. Thanks and regards, Dario > > > + > > + skb = alloc_can_err_skb(dev, &cf); > > + > > + if (skb) { > > + cf->data[6] = txerr; > > + cf->data[7] = rxerr; > > + } > > + > > + tx_state = txerr >= rxerr ? state : 0; > > + rx_state = txerr <= rxerr ? state : 0; > > + can_change_state(dev, skb ? cf : NULL, tx_state, rx_state); > > alloc_can_err_skb() set cf to NULL if no skb can be allocated. > > > + > > + if (state == CAN_STATE_BUS_OFF) > > + can_bus_off(dev); > > + > > + if (skb) > > + netif_rx(skb); > > +} > > + > > static void slc_bump_err(struct slcan *sl) > > { > > struct net_device *dev = sl->dev; > > @@ -378,6 +442,8 @@ static void slc_bump(struct slcan *sl) > > return slc_bump_frame(sl); > > case 'e': > > return slc_bump_err(sl); > > + case 's': > > + return slc_bump_state(sl); > > default: > > return; > > } > > -- > > 2.32.0 > > > > > > Marc > > -- > Pengutronix e.K. | Marc Kleine-Budde | > Embedded Linux | https://www.pengutronix.de | > Vertretung West/Dortmund | Phone: +49-231-2826-924 | > Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | -- Dario Binacchi Embedded Linux Developer dario.binacchi@amarulasolutions.com __________________________________ Amarula Solutions SRL Via Le Canevare 30, 31100 Treviso, Veneto, IT T. +39 042 243 5310 info@amarulasolutions.com www.amarulasolutions.com