From patchwork Tue Jun 7 09:47:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2026 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 9B45A3F08A for ; Tue, 7 Jun 2022 11:48:37 +0200 (CEST) Received: by mail-wr1-f69.google.com with SMTP id p8-20020a5d4588000000b0021033f1f79asf3699489wrq.5 for ; Tue, 07 Jun 2022 02:48:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1654595317; cv=pass; d=google.com; s=arc-20160816; b=ewi1yBTw47oSMx6XpCK7nVe/zGg2EjcUu+bi3XVtLRlwjPvfjb2QMJrRmpGg+/nNP8 TXuMawCMV2DEiuM7JPEsKAqP6o7NLGVCkkfMwxgK+mm01OhKvdcMrtriM8s9PPkbQaox VCohDquiXbY29JBu745UAdFQ+hYSYN9Tqt0A8OAXsyRZeQjzJ6dtwhjGHa4RF/TOGKa3 JV66GsynSyZjSWrG/8CRmaFd3vUa1yD3WB8NFTxBgnNZSSiEIRpWxOovLcykm7BmUDtD Za6+PUESVzim5jqXChEDdSWiyula5pivOg7rjiPP7gzpY5VntgioyXCsmXsvEdz1ChMe 2uFQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=W5BMzNRTTfqwBQe8iFjoq0xhQJUREc01ePItxoKW8kY=; b=aLkl5Cpto+T6fIS+840LZIYN6aDQ7ryxCUFzsr2U7yl0TeFQorlZeT926uf3eLJvVc H0mC5pHGKxKWKm/K/yNnaIyBXtIy9dllRrW4rUeAXhqQ50RujQkgZFw0X6rZLDjvA21q cgY3a12iWpvhLJDrIJgdWiYMDHU2iy1L3ZGzjI0N9oDWlVjicoO6ApBFrICu5O86IsXD ICQRbg3xrsoe6F6i1VeoTPa0lx/7+hiBGefHWRAN+YVwMTy/6STsoEFPTmunpDOOLcNV AYiT6LGErnnjkHjI0Ve5wx+vdjTZKMuU2xFmjx9vqU/6DxBIahmr9Y/Ri2cFeXviXI2n 2zBQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=rfbDySEI; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com 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:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=W5BMzNRTTfqwBQe8iFjoq0xhQJUREc01ePItxoKW8kY=; b=ZgzapmaOaRr9yuUlKA9kyBlY9x8lHKfVUHLKliyHQ4uV8c0OeS2b0f8Yj4YYSpGuJO gVxcdeC8ltleZEzwhOdHSCfoz9n6MwljH8Oh9NpNfMaWV4AwYwaf5b4EGY5hXjO31pgd T+pIdq20de+6o4wQQdHuiCTz8ER3cufN6Y9Jw= 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:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=W5BMzNRTTfqwBQe8iFjoq0xhQJUREc01ePItxoKW8kY=; b=soH7/klCwu/E6unIjoP7uTgufSRK8MwjF1ZUAGkjyf7SU32rxiVGSOV89tWUCjKTiH /TZMR4Hr3Tu6aWa5lyEamgUSpjDl0OkRcXj8QtmySX0LzwWwWCsMBKTY+IYE0xJXF2RT 2tCJKRCDH7a+03CYoBXkG+ex6pZJ5S0RRVm4Z4JYQnONyLon4mQ9pUuJtDQu9WT1CbgZ CYT3NmE14ThDbZajO0puEXsSPJ/r30TRML7RsyWx8MDb/+wqBjkKG00n+RM2mhyVBJJl UEZowySfY+lcK9iYKjFj3MkxjaToYe7O8XtzUUpClFbKPGF4TL1ptnYqbw45yOxzT/1z ziVg== X-Gm-Message-State: AOAM532NzReHS/ij7u8B7UeBZmqh8yuaE/z0tV6H8qTIXnqnrC3eZC12 LwwGwATCoNvFAWDoorahIOBD5EiA X-Google-Smtp-Source: ABdhPJybxYZDKEDt8/SexA8sOrOrydhMY/fBq6USqHGRhbM0HHmM/RuqjjulitOjgqYqDdNgOkQUyg== X-Received: by 2002:a05:600c:4e91:b0:397:8870:a3e9 with SMTP id f17-20020a05600c4e9100b003978870a3e9mr54368496wmq.141.1654595317371; Tue, 07 Jun 2022 02:48:37 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:600c:3d8c:b0:39c:5b80:3b5c with SMTP id bi12-20020a05600c3d8c00b0039c5b803b5cls393931wmb.2.gmail; Tue, 07 Jun 2022 02:48:36 -0700 (PDT) X-Received: by 2002:a05:600c:4e14:b0:397:4f6e:9ce2 with SMTP id b20-20020a05600c4e1400b003974f6e9ce2mr27934928wmq.186.1654595316414; Tue, 07 Jun 2022 02:48:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654595316; cv=none; d=google.com; s=arc-20160816; b=SqoX29JTTCUigEJnld6fv8qnbSsvdhIL9LZArTnVF5Lg7oWYgbLOwi5HUg873FklZ0 eEMDYr0Zb5A403kw+DVJeBb+z8rllOm8eY0V55FXSwJpSvD84HyJ/vVyOWRkUmIQy0Eh u1Q1gaoxJyEsILEByaDSFftidlTDVceAUH0Cx/g2Zh/sKc4IoHZDn2cyzRw5GyK6FPP3 MM2PtWagV2zShdeOBF2qAsQ4e3+iQsnyFdMuMKD0s5bQU2OIkw0zLermwyaN0fYiv15E 3DADUxmOmtxJOifqx3EOlaCkWGgm3HDCJx3lVFtwwKQp6Pmnx14u0j3pcBmyWjlGA5ox V5dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=52GScXsc3r0EaHze1UuoV0GZvaNkVo4y3j7sOuEIJJg=; b=fR5GB9DUZBHRr085/xuosPoT1+sn14agau5R5s82375JdPKo9B2azlj2Ajje67n/QE BceXiY/G7YfPRC84USDgCSugIFqPiy4e2RXp3NTdDkcFQ+2thD5gDXieQPO/TKxVQ0NC sSNui9LJJrVGLmcfkPgEQy1q1DO6uOkWGIpLIrXILhuAP87LaZ+iEoWAzRZVDWy2QUId f4VofIsx1y2QE021e5PqF4HJToHQajPQyvVZjxMVlaVq+myA7aPDpYHLP79WTNGHB5cm 4njeiY3uyZQDKQqmwY9k0kvECmSuuRymv1EnhXsmsEk7ov1Qbv6Ncdy0ximE21ZBkZbT KljA== 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 dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id j8-20020a5d4528000000b0020fc62a0aedsor9817494wra.47.2022.06.07.02.48.36 for (Google Transport Security); Tue, 07 Jun 2022 02:48:36 -0700 (PDT) Received-SPF: pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; 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 X-Original-Sender: dario.binacchi@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=rfbDySEI; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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; }