Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp1796488iof; Tue, 7 Jun 2022 11:30:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJws74sJMGTWriHwDOtbZAEoN0yaEqt1mL5gyLCiWFA9lMmSyj1sLkkQ782HztkxcclvsMPA X-Received: by 2002:a17:907:2d2a:b0:710:7ea6:2b9e with SMTP id gs42-20020a1709072d2a00b007107ea62b9emr17930361ejc.371.1654626506034; Tue, 07 Jun 2022 11:28:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654626506; cv=none; d=google.com; s=arc-20160816; b=kbj7qnLUxbtVJo5/nQCPA0SZ4mCUFyoOVGxcE7WdGMCAOdT2QbNvxiOswXy/Hj8SEC LcGsfmLTaA8eine/j14GvmhvRJ+3lgMZqOypLB0DatF4C202+ifX68ECKaajnB/yUrl6 84wGriXIL56wMB1SmdR+fiw8OUrZT+2DxAW4acK9pxQ4gymmIx0D84dPhsXBqIprEVPk 0BF2XV5KAc42CvSZcLoNEVxpZL6ONE7a4DKmj+QjmZ+FjE5Hjox9l0LUEdP4uXOUXstW l5Du+13OTLuBF8gj1x5hoXUiKCuMwyBQv1yjzsUNF1nquzx+OvdD//s81804hL87B5Vj ucMA== 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=52GScXsc3r0EaHze1UuoV0GZvaNkVo4y3j7sOuEIJJg=; b=L7prVwCsC98h+fDgeQjhn8Z+FiAD00P3T58xXUHdk0HaAlE6X3qZ2aa9pJ40t+aGkc SM9bXpgGoEjVQE2b7l9KMViwjZPJSeCs8wuEGDFq+PkyQKIAEgwQ1K1T6g62ww7WwCff JWbS7ynsa5wGNIr0cCYB/o2VMha0SEVdwTvlzE31s7niZl/wDjhRNJTqUUUd9Cf5uk/j uYgL3H0QXLc6jdbTpQahTYYmwy58WLmoAQJ8s/HGB5kxKAePQPUuOKpMzqsjv84vHD1X qfqRqiA151t7VLnG92Jx1UTNWhLaNrYUrZlXbh7/l+TWEIrEu8IsBntsfWkcOW0x+fAF xI2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=rfbDySEI; 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 w9-20020a17090649c900b00711ca15cd48si8273999ejv.939.2022.06.07.11.27.57; Tue, 07 Jun 2022 11:28:26 -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=rfbDySEI; 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 S240092AbiFGJu4 (ORCPT + 99 others); Tue, 7 Jun 2022 05:50:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240185AbiFGJtF (ORCPT ); Tue, 7 Jun 2022 05:49:05 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0137E8BAB for ; Tue, 7 Jun 2022 02:48:36 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id k16so23357733wrg.7 for ; Tue, 07 Jun 2022 02:48:36 -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=52GScXsc3r0EaHze1UuoV0GZvaNkVo4y3j7sOuEIJJg=; b=rfbDySEIkeXsxScHE6waneBGxdkvnI60ZQfnEp5JSr5QC4sE+srEselhgT+QjckgqO 6tCrd7AKmTQclOZuFHLyLrBrhuVMroHqP0zmUx+MieYmNYGug4n4s+Ur9luZ71tpZFrp 1Nt+YEH1E8xe4mGJq11zLGFiK3mudUMFxMgpU= 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=52GScXsc3r0EaHze1UuoV0GZvaNkVo4y3j7sOuEIJJg=; b=oVq2dTW438723apHoFmsl3zSc9EcltdkjVJ0hokOQNa9GRxTGSaxwfCH4I/ERkWV52 JvjLvJnerQrTyI63hsiRuv/o6kHWWXxIRuYpSPVqFgVi0aZLgbi621x5Ot0CJbsn09Wj GiBTplL1zSaWZ9rBHGLoWE88N1/YfFSbyqugIwUAMfxepx2nWpXNjAsB8pntL66VkXc1 hX3R7sYWIjyfhBLOz3IPwNxbJYI0QPKi33z3wrTvVcz92YDOKoqKO8MljXrxSYMyjAN2 oONcFqVz9wIadGz5pq7dBXzrLhePLOYmZ6PV6dBemxTRFjsoOU4YA3vRe3rSI3SEO5v4 R4Uw== X-Gm-Message-State: AOAM533xdqfArqYRDUR/XtPAII1GojxnN8oUF4oHztZm6nUce0lLVqoX 3m5LZUQOVp+J8HaKRjSaRxwWTpOH+on/Qg== X-Received: by 2002:a05:6000:1acc:b0:20f:e35e:450 with SMTP id i12-20020a0560001acc00b0020fe35e0450mr25901221wry.531.1654595316197; Tue, 07 Jun 2022 02:48:36 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.pdxnet.pdxeng.ch (mob-5-90-137-51.net.vodafone.it. [5.90.137.51]) by smtp.gmail.com with ESMTPSA id o4-20020a05600c510400b0039748be12dbsm23200547wms.47.2022.06.07.02.48.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 02:48:35 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: Amarula patchwork , michael@amarulasolutions.com, 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: [RFC PATCH 13/13] can: slcan: extend the protocol with CAN state info Date: Tue, 7 Jun 2022 11:47:52 +0200 Message-Id: <20220607094752.1029295-14-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220607094752.1029295-1-dario.binacchi@amarulasolutions.com> References: <20220607094752.1029295-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 --- drivers/net/can/slcan/slcan-core.c | 65 ++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/drivers/net/can/slcan/slcan-core.c b/drivers/net/can/slcan/slcan-core.c index 02e7c14de45c..ab4c08a7dc81 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; @@ -182,6 +185,66 @@ 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 (unlikely(!skb)) + return; + + cf->data[6] = txerr; + cf->data[7] = rxerr; + + tx_state = txerr >= rxerr ? state : 0; + rx_state = txerr <= rxerr ? state : 0; + can_change_state(dev, cf, tx_state, rx_state); + + if (state == CAN_STATE_BUS_OFF) + can_bus_off(dev); + + netif_rx(skb); +} + static void slc_bump_err(struct slcan *sl) { struct net_device *dev = sl->dev; @@ -354,6 +417,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