Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp112465iog; Sun, 12 Jun 2022 20:52:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzf4jPj2JoV4C2v5mBupkIn3H6QSe6387ND83cEdHl7M253qgTwzwfMhQ49fVjkWpuHGOYe X-Received: by 2002:a17:902:74c3:b0:167:6811:40 with SMTP id f3-20020a17090274c300b0016768110040mr43576996plt.120.1655092341401; Sun, 12 Jun 2022 20:52:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655092341; cv=none; d=google.com; s=arc-20160816; b=kCDkXfmzza3aIAjR9ultX6bThLYw+DcLiKNd4xfvFHu8JOP1PE20W8rzjjXw3iNQHH IZ/Ewmx+gzk8DLRE4Rl21/hbUPNOonQfbWfHbewdXFpW6G5eYTav3iAreEZzCm3C9Igy dbXZhIbzHTif8tXvL2QCDVE20rWGDPT11iOjGfItTxEoo4YQohKjmS+iFVTyVfsPrGpw x4haGDTqQkyDccXSTfeMu89His3jVHBmACFFsBQZTrl0oxYfuYoccoC3U7MRuMSvODAj SsM8NaDlFuNcnVsKyVlhL/tB99fPhehh1nZxZFSnQ9s4GGTpIFWcgRaduYmBvCQSRu9d nU2w== 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 :dkim-signature; bh=6efkiC5TQ5d8cecscsrXOmD2HlmxuShBu5gYbYTpObM=; b=PBLXirnMfC2p7YkVwFha7WvH/4Ihah0C/gTet56CIc6R68CLLqgqw91+VZjKbfWnUJ YPEx+SrH0z5HKKL2lZvqdvH2ur/BNSaaADzSeFCU3o7KEdpb6uo6hYt3LgYj9/vP/ihY TmITRP/4GZytU1aOziXPmgVW7IrYMGVnXWjEBEIDeIAjbNzU86gs6he1AhD961h95f0/ F2eJJn9WwxdDMOrFYX4xsZ1Ns9wFSSKpNUhV9K1CeP74jx4y8s3nzb/aWBKHLj4zcRNz ecpZ2245fdU+onhX0lI3IafmGRxtg3S+Gga/VKo4OQ11HVbbqbG6YnIbDpDshCbgJI4x IvZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=gkAi7IMO; 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 g14-20020a056a0023ce00b0051bfcba3bbbsi8910776pfc.232.2022.06.12.20.52.09; Sun, 12 Jun 2022 20:52:21 -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=gkAi7IMO; 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 S237225AbiFLVlw (ORCPT + 99 others); Sun, 12 Jun 2022 17:41:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237785AbiFLVlY (ORCPT ); Sun, 12 Jun 2022 17:41:24 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D5CB590AB for ; Sun, 12 Jun 2022 14:40:39 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id u12so7674037eja.8 for ; Sun, 12 Jun 2022 14:40:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6efkiC5TQ5d8cecscsrXOmD2HlmxuShBu5gYbYTpObM=; b=gkAi7IMOOIGcRbSgxyuwNuF+yLKH5vQfyxa+wwgE54dvDLD/gkJ65zcvVF3CVDIA99 Nf2msatumXRQ/PinSPOFZacm2A+UMAVMBdKGzFQGE9p68kb8QqPpPoF4ajerF5xIuFYI LUIIi8dzgnhI9dI4kK3MT8SxDdKo1hcgk8qzU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6efkiC5TQ5d8cecscsrXOmD2HlmxuShBu5gYbYTpObM=; b=5Zq60j/uoBvxxPt0Js+0mPbIjfj0P4Fz3eNf1MEVDZBlbaUIeIuBWjMA5mXxDbiqZv FXy8jGcX/TiLiWvzj/ZksRDd5YTvZoraAPA/85lT6htaIJwxI7bamBSg+8v4Uvt3xdDp FwbBoo3svRxx7b/b+Tw4CLV9Y/kAdVONIrOP3kLnHxVHWYeJETbPD5d+qJkpSQ9lfCEA /QIIG3NwfqHKs9BkLXVma8eBwoo4ZPRV2g/46CqsBh/VYHrqzWQovHcRuDKUWrRE+ko+ 5mPYW8RWlZFlI64wreaL4o8AuJ5DRQiEpGKoPzE9fQOlm0PPf3p/8eM22i24qNL49fCY +fHA== X-Gm-Message-State: AOAM532pgdJDFb8H6vn+dcFLkuETcMKoDSZYgsBiKw0jVyhfhz/yTOqh kbfISBZVYUeo61eWEiGKT6TqXg4bINCjyA== X-Received: by 2002:a17:907:9605:b0:6f5:c66:7c13 with SMTP id gb5-20020a170907960500b006f50c667c13mr49390538ejc.66.1655070032889; Sun, 12 Jun 2022 14:40:32 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.homenet.telecomitalia.it (host-80-116-90-174.pool80116.interbusiness.it. [80.116.90.174]) by smtp.gmail.com with ESMTPSA id u10-20020a1709061daa00b00711d546f8a8sm2909398ejh.139.2022.06.12.14.40.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jun 2022 14:40:32 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: michael@amarulasolutions.com, Amarula patchwork , Oliver Hartkopp , Dario Binacchi , "David S. Miller" , Eric Dumazet , Greg Kroah-Hartman , Jakub Kicinski , Jiri Slaby , Marc Kleine-Budde , Paolo Abeni , Sebastian Andrzej Siewior , Vincent Mailhol , Wolfgang Grandegger , linux-can@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v3 13/13] can: slcan: extend the protocol with CAN state info Date: Sun, 12 Jun 2022 23:39:27 +0200 Message-Id: <20220612213927.3004444-14-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220612213927.3004444-1-dario.binacchi@amarulasolutions.com> References: <20220612213927.3004444-1-dario.binacchi@amarulasolutions.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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=unavailable 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 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; + + 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; + 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; + + 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); + + 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