From patchwork Tue Jun 7 09:47:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2025 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 90AA03F08A for ; Tue, 7 Jun 2022 11:48:35 +0200 (CEST) Received: by mail-wm1-f70.google.com with SMTP id l34-20020a05600c1d2200b003973a50c1e4sf8626083wms.2 for ; Tue, 07 Jun 2022 02:48:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1654595315; cv=pass; d=google.com; s=arc-20160816; b=JwFH3vYph2IBN0b14o1oitU/DBGU2UMfcBwGkb07iKopmDzZ/TlpT+eTmLWEzeUty6 6WlLCpcCox07ThDiXp1VVBH0xr5JlUxpYln6qywKYmO30xtAYpk2X+Atv2ZV0MMvOQfC LyDbz8TPpMYkfhsWkVrczupxaIhhag0BFteD8mQkzceGR4maovkXLu3VoVRGOs5mY4pZ FIV2oFj4Hc9mWgApACJVpFVQ6ISmEm86heN1L/ZclfxX5jI8M8+lPrdFrZE1hShcm+kb CSCXjOgAyfyPWT2dZoJk9sFrj1nssomYD7EqfEBxmpBPD0ZsYIRBm9Ow22rtkYvdyX9g xZ8g== 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=BhH6RWwxBUzu2YEe4dsnkiUrgxCLwwypFCu76afHHOg=; b=OZ8avXD/vVGw4B22sTvCV7ypaDR4dx9rFs1puPaK5TtsnHCg+XOJYBSV195XKlAGsa N2JneUIuSZsOZnWbp9Op1tocktg0gZm8YOJCLvrfPCiO40P9aAPGW1lzBlH6g2vgxqO7 xQ2e+eLV6LpX7Ck1/6avujgGd7BrDYgwmIwvW75hx3Qr6wUvjfY2OJFAEe0O5qwTlutJ ns/vcSLUrtWs+I1OpfjnjC/h1rz1XszMvHnbmTAcsYFDKpNz7GvrwOiXaYNccxcPmLz3 7Y7iCbn3872cvWmjuwR5UEaVFGO3aLDc0RZtH6yYurAC66mprTLGbx7VrcAIY73JUfVd R7PA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=HMeORKBx; 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=BhH6RWwxBUzu2YEe4dsnkiUrgxCLwwypFCu76afHHOg=; b=hCy9zn+gF3vMkrjHpK+dOeGEIpdr535PpNwHaKE8u8XAN2G9nBOTdaRiNg/3QmD69O gRVUACriZ0jpp0IlQ3k193kqFmtFOc8X3WOH/akebdA6mLnlO+ciQauFGpbjPezqKaBb Q4vKlXJFloMEyZyQvGAO8a8SOgJYqA8iDH4rc= 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=BhH6RWwxBUzu2YEe4dsnkiUrgxCLwwypFCu76afHHOg=; b=z//HY2bibaP2KQkpi56MJb8jcVOte9XgvITV+cjB4N7CEwNgfqzOFyioYzKQZ2Aw7n t04R3wSWCIqHBlvEA8WACK+4mdr9s5qwprgIbHIubnM5c67ky8WZsEViHY02XSLMvcJB jTmXRbWvIWSfpX1LKLwchsTba8hprzWFCHpQ9b9dNIT/0d5YW1RRJ/hmzTrAZizJhDl4 aHusHSJp65klSyEi0WReko1YHryS1j3sjzQlBl5JOv38z/gxtyLbhUqy+SgBZkONbM+i pmZxiFPfQ/ncCw5Un9pyfY9TTrqqNNRe2tHdXXadiFw1Y3KVsjh87ZTr6PZIwupP8bYn l1zA== X-Gm-Message-State: AOAM531/Zc60HCVFx6fE9vnx22KYbDqUNSR8S3vVlxKmBA+sk5ITZ1J5 XSZx+KXvMBHeqxYvrSg8p/CRc9CV X-Google-Smtp-Source: ABdhPJyZ/9gLreA0fLnVCwMGAP9+TXLXHHyp3C8ekc4mlVZQj2WCoQ/bo5prvl1StsbhMG6N3kEkiQ== X-Received: by 2002:a05:6000:1e04:b0:217:88ff:eb86 with SMTP id bj4-20020a0560001e0400b0021788ffeb86mr12687910wrb.351.1654595315365; Tue, 07 Jun 2022 02:48:35 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:600c:3d8c:b0:39c:5b80:3b5c with SMTP id bi12-20020a05600c3d8c00b0039c5b803b5cls393890wmb.2.gmail; Tue, 07 Jun 2022 02:48:34 -0700 (PDT) X-Received: by 2002:a05:600c:3386:b0:39c:5b81:af9e with SMTP id o6-20020a05600c338600b0039c5b81af9emr1206532wmp.2.1654595314315; Tue, 07 Jun 2022 02:48:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654595314; cv=none; d=google.com; s=arc-20160816; b=oP6Mp/S3y+Iu7IInOfqI0a9OMFZmmmKN94s7t7IpX6W5Qe7HyxycJNB1AXxp8YuUJM 5hrIe+8/9bVrOlxtNSjqcls9zfXHfl100OIDilDZifGi1hR2Q8X5B+3RoQJ37vWO8DQv UcrWiuq15dmbWHPa/3mhnIAHn/vN0/z6o1h3is0dqqB7XjwLhKLX1Ag1uLJvr7XifCvw 6PL15sgxUCGc7dYxaYXO8a0K1lEgGPbStBZ4idwfMo+OMVl08zrOlAChGfJWhxE0twig g7BB751NDz0+H4EkT/yS7+pCtBHFoj6XhpHQdtN7d/wAZ+xAA9usSSprC4phYAfcUx58 CwYA== 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=2VLfBpv9snTnPtrFeblfPn0318JEYJPp1U8Dhg0IAiM=; b=EhLAOyGqU3r8724W+RnQadgZmjfNkhGBHidpbJw+P5A3WmXXwL3NXOHOfaCMGcJ0bU xRmmSPPGkmkqERJ3WwjJ8xyhLpVHzz0n1OxJIdZSQFrQMe2Eec3hwYdn3RhR+Vy+c/5Z PAq1t+LxGUgR+u5qoe/zDrdtLefKMbbC0glzabKpfwaBG0Qz3eWvOUDQsaW04Abkkiwh gipFbvRyCaiJCYPhSX2+paAQXFmvHI+SKpv2SyNS24JCl66AWdkvjurKM48i1jUx8zCo lTNWO+x8ZR9t+ApReV5Ncn9SFYxpBxk47QDcvZyRlyxVizkkMT0PJI5/XTuKVdA1bvns 2W2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=HMeORKBx; 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 bd7-20020a05600c1f0700b0039c4a2cf724sor2127209wmb.29.2022.06.07.02.48.34 for (Google Transport Security); Tue, 07 Jun 2022 02:48:34 -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:600c:3d05:b0:398:a78b:6a30 with SMTP id bh5-20020a05600c3d0500b00398a78b6a30mr27816891wmb.175.1654595314137; Tue, 07 Jun 2022 02:48:34 -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.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 02:48:33 -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 12/13] can: slcan: extend the protocol with error info Date: Tue, 7 Jun 2022 11:47:51 +0200 Message-Id: <20220607094752.1029295-13-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=HMeORKBx; 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 communication errors and forward them to the netdev upper levels. Signed-off-by: Dario Binacchi --- drivers/net/can/slcan/slcan-core.c | 104 ++++++++++++++++++++++++++++- 1 file changed, 103 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/slcan/slcan-core.c b/drivers/net/can/slcan/slcan-core.c index b813a59534a3..02e7c14de45c 100644 --- a/drivers/net/can/slcan/slcan-core.c +++ b/drivers/net/can/slcan/slcan-core.c @@ -182,8 +182,92 @@ int slcan_enable_err_rst_on_open(struct net_device *ndev, bool on) * STANDARD SLCAN DECAPSULATION * ************************************************************************/ +static void slc_bump_err(struct slcan *sl) +{ + struct net_device *dev = sl->dev; + struct sk_buff *skb; + struct can_frame *cf; + char *cmd = sl->rbuff; + bool rx_errors = false, tx_errors = false; + int i, len; + + if (*cmd != 'e') + return; + + cmd += SLC_CMD_LEN; + /* get len from sanitized ASCII value */ + len = *cmd++; + if (len >= '0' && len < '9') + len -= '0'; + else + return; + + skb = alloc_can_err_skb(dev, &cf); + if (unlikely(!skb)) + return; + + cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR; + for (i = 0; i < len; i++, cmd++) { + switch (*cmd) { + case 'a': + netdev_dbg(dev, "ACK error\n"); + cf->can_id |= CAN_ERR_ACK; + cf->data[3] = CAN_ERR_PROT_LOC_ACK; + tx_errors = true; + break; + case 'b': + netdev_dbg(dev, "Bit0 error\n"); + cf->data[2] |= CAN_ERR_PROT_BIT0; + tx_errors = true; + break; + case 'B': + netdev_dbg(dev, "Bit1 error\n"); + cf->data[2] |= CAN_ERR_PROT_BIT1; + tx_errors = true; + break; + case 'c': + netdev_dbg(dev, "CRC error\n"); + cf->data[2] |= CAN_ERR_PROT_BIT; + cf->data[3] = CAN_ERR_PROT_LOC_CRC_SEQ; + rx_errors = true; + break; + case 'f': + netdev_dbg(dev, "Form Error\n"); + cf->data[2] |= CAN_ERR_PROT_FORM; + rx_errors = true; + break; + case 'o': + netdev_dbg(dev, "Rx overrun error\n"); + cf->can_id |= CAN_ERR_CRTL; + cf->data[1] = CAN_ERR_CRTL_RX_OVERFLOW; + dev->stats.rx_over_errors++; + dev->stats.rx_errors++; + break; + case 'O': + netdev_dbg(dev, "Tx overrun error\n"); + cf->can_id |= CAN_ERR_CRTL; + cf->data[1] = CAN_ERR_CRTL_TX_OVERFLOW; + dev->stats.tx_errors++; + break; + case 's': + netdev_dbg(dev, "Stuff error\n"); + cf->data[2] |= CAN_ERR_PROT_STUFF; + rx_errors = true; + break; + } + } + + if (rx_errors) + dev->stats.rx_errors++; + + if (tx_errors) + dev->stats.tx_errors++; + + netif_rx(skb); +} + /* Send one completely decapsulated can_frame to the network layer */ -static void slc_bump(struct slcan *sl) +static void slc_bump_frame(struct slcan *sl) { struct sk_buff *skb; struct can_frame cf, *scf; @@ -257,6 +341,24 @@ static void slc_bump(struct slcan *sl) netif_rx(skb); } +static void slc_bump(struct slcan *sl) +{ + switch (sl->rbuff[0]) { + case 'r': + fallthrough; + case 't': + fallthrough; + case 'R': + fallthrough; + case 'T': + return slc_bump_frame(sl); + case 'e': + return slc_bump_err(sl); + default: + return; + } +} + /* parse tty input stream */ static void slcan_unesc(struct slcan *sl, unsigned char s) {