From patchwork Wed Jun 8 16:51:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2039 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 58B053F1F7 for ; Wed, 8 Jun 2022 18:51:42 +0200 (CEST) Received: by mail-ed1-f69.google.com with SMTP id g7-20020a056402424700b0042dee9d11d0sf15189787edb.3 for ; Wed, 08 Jun 2022 09:51:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1654707102; cv=pass; d=google.com; s=arc-20160816; b=M+CZdsoZp1gNqX/v9izSuKqqvYba5uKv9HcDPAzHJG9X0U2aCoe8cUbDAGp7zwmb1q 77QPVBs+16a93BkWYT5gtbS5qbX+lutY9N9dt1PAJ2HknDIB/hQs+lN3LoY8YjvkdhNp s7FnBxossQAAOk4sV3Hpp3G/ELuDLJdFSbwX3Q1PL3eaMBTMjv/giexMPObvPA0X0ATo RJs6IdaqBw7X/UbR88WcLTEmO23rb/ov2Bj/ruR5gkuOsPPkAIGxzoh9uxSlUxjcpPci yCCwYFSlZBs8wZw2nEDh8yNmXeKAIOukcU4Sv78I9qiex5tQ5nPvFkNDSn7v02ABEU/Q LsNg== 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=YkjfI++M2oDDaasBMbam6jaJWdzMx8GTQRiAh0yswE0=; b=QFEjrmmLwcrCVd/8P6n3VoLg13IeYQRTLgFrUzP+xWaWgCstTZ0tnSzXfx4FX5x9oc dQ1dOF6EnFd3Pl7bwgoHRFppZ4ZC4mU0WQ53ihKpazdjV1LOeOKaMWGFsxzEkX6Ar4un AXH9kxF9+LgX8JqyYh0TTNkdxSYApel44q01C9dEsxOr2xMys/dxd6pubOnYoD8o6/Yy VEl8SBZn6wBVJL61NK15E0XsCren1DbnqwgPRS+SVIPbLwV/LZtkAu1UxW3fIusyOzK0 xvLR8/juU3rw+oE0fQ4t5xfk59Hjfe2tpoUpq4wFFT7cXxSrG+ILleXIvz4oCU3vlaDv 8Vdw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=fOek92UJ; 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=YkjfI++M2oDDaasBMbam6jaJWdzMx8GTQRiAh0yswE0=; b=SDuqiUZ0T5QJRsMAyfHm70sPM73oAhTcyCwGAHFCpp8wt9iGKaQem8+q71Mu0k4eKr x7taDp9uIEjYcLRmcuSH93iInr3a9JFuPxSobkUp/hUxg0GIl48MAdAgaqDmfCFeuaiT grSQK2SGoHaJ8XU7heaE6fCWkzsAO46+2P3cM= 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=YkjfI++M2oDDaasBMbam6jaJWdzMx8GTQRiAh0yswE0=; b=h6mhuxNSxYD1Fygc9lxS2kNdgljU1tZYrAgzihi+nntZlk0Ywg1mTXQbRaR8mXbG6b sxr9nYFFAq0TbJee8NDRzkZlVGRcFOkJ/c/BfkwhqUjFZXHH8OZOe84+dgw9tf9HcRNY g54e/iQQS2VeB/Y+LJ4KsI1qr7DMNlBadS/o6qvf4naM3AK6A/tAovF0qS73IyF2mMUh bVc+76QdA9m5FdYMnaUQYf7tgu6lL9D7qRkQMW/h59s0KWoGZi8ejor24rio/uJTQKIN h/rQMxd+JPNvWVb5CaZfYBQnA8mJBJGkwsRKCjG3XOpqDpaYe4lOcSIiBdQg3lWHk9GA f7uA== X-Gm-Message-State: AOAM5324iDChrR6Z5Ke1eYzDl5xmolZGPzrn8Vgk1Ub1Qzi4wOltx/17 fyisqUeiKyPS3i77Ui01JSMOenlF X-Google-Smtp-Source: ABdhPJwRC1GxHavOy2HdGMSeU00X+oiweyGET42r6EmHmaxasVniIqir0k/cxlMwhE909ScGc1lDUQ== X-Received: by 2002:a05:6402:1756:b0:432:dd5f:ec38 with SMTP id v22-20020a056402175600b00432dd5fec38mr3967345edx.307.1654707102180; Wed, 08 Jun 2022 09:51:42 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:2741:b0:41f:7eee:e393 with SMTP id z1-20020a056402274100b0041f7eeee393ls189239edd.3.gmail; Wed, 08 Jun 2022 09:51:41 -0700 (PDT) X-Received: by 2002:a05:6402:50d4:b0:42e:686:df55 with SMTP id h20-20020a05640250d400b0042e0686df55mr40348666edb.403.1654707101116; Wed, 08 Jun 2022 09:51:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654707101; cv=none; d=google.com; s=arc-20160816; b=j8i8vUysVTejuQ3Ts95I0xX1ctQqs57oSV6U3ggpgiQ6Q6CGeoFosY+OX4zb99BODM rdnonyoSGtig9IEWxxFKK6PEF9dJimhjU7IoXCDj0v+BGgIBykItXDZZrEUV+w7C2vTy Y1yGwBog+77s9YQIy7vZviZoosW5tX9bX0XhipLKBstmmbVLH7UsQU8vYYkK36PVgXKb m8wVTxNDb6IQK4AqdXloDNZGSlw7qW14u7RnMIz6oJhm3a/9Ebzqtj3hHPhfP6MHFLH9 16Nac9NBwhj+KjmrMQwj7rbEw4jiEQcO8OjleXWJQF75kP2GHEbQ+99bdxRHHDj9gPgT Y5ow== 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=r56OkRGS+scgiov9hraSbcrm1/dO+C0ISd2zgdsHS2U=; b=Qvg/yTJCFnzKSuchGP69Zb0VMkTIE8Dl++bPOfFcBCau2dNn0SSSAK39zFlzPdIHzo U/zG5nG9hxPSj/cFxpVZQzvxvi1dcKSSxXcFbQj0RPx+WMHPzWk/dP3PScfPaqTmRx8K WX7h9Gwo7EMkjGb9GtJnl6PdX+Fd0hRCm+PeJmtEHm7cSlY0XVZ/DfDeRJsdQ3Rj0+Dv eyHGT1qn2x78/J2ryZsDvul8idfi5jseTgA9cIQPYCqvXfZA51fFKLzhcUGjJE6w3ZAa TOIM1LcaO/yUaVrbb9kJ+ze6zjGfQikPpzg9FU+YR1sccHFGiH2fTBvDUqM0Le3t8CFQ +RBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=fOek92UJ; 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 t19-20020a170906269300b006fef55785d9sor9712200ejc.96.2022.06.08.09.51.41 for (Google Transport Security); Wed, 08 Jun 2022 09:51:41 -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:a17:906:51c5:b0:711:f4ee:6574 with SMTP id v5-20020a17090651c500b00711f4ee6574mr3748661ejk.509.1654707100906; Wed, 08 Jun 2022 09:51:40 -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 c22-20020a17090654d600b0070587f81bcfsm9569071ejp.19.2022.06.08.09.51.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 09:51:40 -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: [PATCH v2 12/13] can: slcan: extend the protocol with error info Date: Wed, 8 Jun 2022 18:51:15 +0200 Message-Id: <20220608165116.1575390-13-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220608165116.1575390-1-dario.binacchi@amarulasolutions.com> References: <20220608165116.1575390-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=fOek92UJ; 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 --- Changes in v2: - Protect decoding against the case the len value is longer than the received data. - Continue error handling even if no skb can be allocated. drivers/net/can/slcan/slcan-core.c | 130 ++++++++++++++++++++++++++++- 1 file changed, 129 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/slcan/slcan-core.c b/drivers/net/can/slcan/slcan-core.c index 038ce7c25d42..aba42e284274 100644 --- a/drivers/net/can/slcan/slcan-core.c +++ b/drivers/net/can/slcan/slcan-core.c @@ -170,8 +170,118 @@ 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 (skb) + 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"); + tx_errors = true; + if (skb) { + cf->can_id |= CAN_ERR_ACK; + cf->data[3] = CAN_ERR_PROT_LOC_ACK; + } + + break; + case 'b': + netdev_dbg(dev, "Bit0 error\n"); + tx_errors = true; + if (skb) + cf->data[2] |= CAN_ERR_PROT_BIT0; + + break; + case 'B': + netdev_dbg(dev, "Bit1 error\n"); + tx_errors = true; + if (skb) + cf->data[2] |= CAN_ERR_PROT_BIT1; + + break; + case 'c': + netdev_dbg(dev, "CRC error\n"); + rx_errors = true; + if (skb) { + cf->data[2] |= CAN_ERR_PROT_BIT; + cf->data[3] = CAN_ERR_PROT_LOC_CRC_SEQ; + } + + break; + case 'f': + netdev_dbg(dev, "Form Error\n"); + rx_errors = true; + if (skb) + cf->data[2] |= CAN_ERR_PROT_FORM; + + break; + case 'o': + netdev_dbg(dev, "Rx overrun error\n"); + dev->stats.rx_over_errors++; + dev->stats.rx_errors++; + if (skb) { + cf->can_id |= CAN_ERR_CRTL; + cf->data[1] = CAN_ERR_CRTL_RX_OVERFLOW; + } + + break; + case 'O': + netdev_dbg(dev, "Tx overrun error\n"); + dev->stats.tx_errors++; + if (skb) { + cf->can_id |= CAN_ERR_CRTL; + cf->data[1] = CAN_ERR_CRTL_TX_OVERFLOW; + } + + break; + case 's': + netdev_dbg(dev, "Stuff error\n"); + rx_errors = true; + if (skb) + cf->data[2] |= CAN_ERR_PROT_STUFF; + + break; + default: + if (skb) + dev_kfree_skb(skb); + + return; + } + } + + if (rx_errors) + dev->stats.rx_errors++; + + if (tx_errors) + dev->stats.tx_errors++; + + if (skb) + 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; @@ -249,6 +359,24 @@ static void slc_bump(struct slcan *sl) dev_kfree_skb(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) {