From patchwork Sun Jun 12 21:39:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2059 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id B0E0B3F1DD for ; Sun, 12 Jun 2022 23:40:29 +0200 (CEST) Received: by mail-ed1-f71.google.com with SMTP id y4-20020aa7ccc4000000b0042df06d83bcsf2923436edt.22 for ; Sun, 12 Jun 2022 14:40:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1655070029; cv=pass; d=google.com; s=arc-20160816; b=sWUVDaOx/wTqREkQFrMXWMioXQQn9Kg2r0tcYTwZFYwSvTUjbJYyEE5hbZ5YtsMPS8 sOZ4Q1Q+Y7ljYT1SpOMLsIxujzPzFvtWULUvq+qDvMxmolGwfh209LEThZ27IUv1KbiY ujPjYQIDHJhHYx9kkjmcoh8XC0nWPJwd1+Io/71U1aoJ3ZJQdXdNGAMsjwzzUMeZCmCh jPDTLPVpwHPNogYX94Np0nTnlWlzpIQXAR6Vflzmq+7wA+Cn+QX5NAe9UkaT2dx/j9jW FPOxGXJsKAlD7bSvnkew+WCfbw8rs+3vx0vHqtcu+QFo+CFMzA7q+5HGInQSk9V4KbZu 1H5w== 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=gA0itNrtugfzLr6oO/Oe+F6wnAcraRj5HkG6Jbfjo0o=; b=W6KGxZeFN3OmZRcKaSYKO/8YOma177WiZZ5pAls1Pq224Vz+4t3cik/G9cko+fVMrE xLXzPe/W+FPSw/vRuN5BOO2G834q45GiLTb3O3wDeiyT8cIR63EQPOmfHy+3DG9CHpem 1mpFSHdyEOO1t/DmhK5N6Oh7qmpSfvxBtMQAYbQU+jDpVxKes8FtOwyMKICHLmGiUOsN nhp4Gf6Y/BIQBsic/ntIYDL6fGSVnX3m2fos+rDDfauMap1nG5Ub83Y2ZI7eMmESLlKk xnrqnZCrJ2z62wW/2bnetS8PvzQRm0eLDpN/w3EE/yPiNFFFD9Dr3Jatl0c9Ol5yFSK9 rhPw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=qYQO15I8; 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=gA0itNrtugfzLr6oO/Oe+F6wnAcraRj5HkG6Jbfjo0o=; b=VbeQalqaujUkCqEej6OueAO/48hBZnCnBuAltxSlkJifQtOPKEhmS/p2eXmNRR1f9h laHrnNqH99JV1xL3jB98K8MVXFATA2iFsaMVsBTN1obPPtPtJR/tQsRXp8xMOtb0UfXk srG4sN6whdyOoQEqVb6NGkgTLd1uV0sGO2EnQ= 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=gA0itNrtugfzLr6oO/Oe+F6wnAcraRj5HkG6Jbfjo0o=; b=Qwi5o5hlvRRovg1TpWi3jX1yZNahERx7m9mDhuUnBCUdncbh2GXZuPg6cC+Ddkki6/ H7sJUMY4GboS0oqkb0g5aa3zerI5g0vVHm+jmLd+c192rja/yCOIGgCpMobp59tlM1v3 kUQ9a5k1g4hVNfNwFfo4cM8m32GjdX4aH5i53lxnE3OAZq4hd8oVyPHPnmGwokGGoOoo /JGbdR0SCFdM9dB6djBzNBaXExQZ8dNaHl0Pt35/mtMiC8IMR1RV+p97loX+FDVS+Aoc DUQGJJl1Q7vWugIGXX344mBZqjcfcR0LA2+nB3pdB0zGgANBxXB4dvZIT66O+8OjWDAK 4Siw== X-Gm-Message-State: AOAM530oL9EIk91oEB+X7nxY4AO6ONIgq3Z8wFlILXmzevVw6JPtR4a6 0wF4fLJ6u+pLGYlqn1a1DhDZm0XL X-Google-Smtp-Source: ABdhPJxU3YmCRaO9/siU/fAib1rPqhZB1MkmH2A0cdXz67su+QyioJNrU/1//a9AOQ9N7QUMtLKsBA== X-Received: by 2002:a05:6402:518b:b0:42d:fe74:98f9 with SMTP id q11-20020a056402518b00b0042dfe7498f9mr62299253edd.371.1655070029583; Sun, 12 Jun 2022 14:40:29 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:907:d1c:b0:70e:611f:3585 with SMTP id gn28-20020a1709070d1c00b0070e611f3585ls1010213ejc.8.gmail; Sun, 12 Jun 2022 14:40:28 -0700 (PDT) X-Received: by 2002:a17:906:7742:b0:708:ad9f:8e88 with SMTP id o2-20020a170906774200b00708ad9f8e88mr28058576ejn.735.1655070028487; Sun, 12 Jun 2022 14:40:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655070028; cv=none; d=google.com; s=arc-20160816; b=y8Vqeq3Poo5XzEwHWvQ6QygpvvW7CzmK7ioJyx6iOuVZ8lPSEHM8lf7uI/NVilcDJ/ j0R+36noagO0YIpwptVuw9vJTnL79aE/Hfvky0ptb8mj7/D+w7LpE5MfHvkNWGgje+Mv TwsXLB0OZ5zx0EjmpQLai0tfL39Z+4S8JxwQ8GSDM+wJgrNBunAx2Se+OUF8kfe7aalO a5iMWRGnQETcsh3LzOgtrZGNfWdt5cH7uI+bf6A5W5zMo4RsSNMso4UsgdaYC852H4pO 1cM6PLWFubecWvU70Inb7r207DA68bFLAtuxQNb1KS3V8rvOFxX26sajYtTJHUNViiVA 0+0A== 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=P8N6mZ+VdIxDHB3ERFZNuvKgcE/qcXFBtcxLWjsi6yU=; b=yWFjQQGMXBzNx9M5+zwZxBLl22oz8QXMUCVXiiYQhqNisV5MarCdd9QjRnKGm//Xw0 ZWCOWsx7yl3IXWSjd/JTer6H2p5EWtG1FbxMym/KZ0ixMUkza0EunpxkttnTYX34Ef+f EKYJH+PUX/D/RNvA0WIQp0NZ4d7+yXzsdlTyJ0eimrmjYuv4JKIwv++iaF5LQoAvgEYa IswCii3nwg21tNdVnmlYa5DmsId42z6RR+eo//pRQ+8py0dnRSN7s5OKmTUpcyE5Q/Qa mZb5+USENtIBAUXDC5HPyIeF3L+t2JSIDdvh4Fx3U3m9c+txqwD9SS1voOwc0X6Iybee Jhlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=qYQO15I8; 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 w13-20020a1709061f0d00b006ff8320841dsor1351331ejj.92.2022.06.12.14.40.28 for (Google Transport Security); Sun, 12 Jun 2022 14:40:28 -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:6947:b0:711:a86b:6780 with SMTP id c7-20020a170906694700b00711a86b6780mr37988734ejs.686.1655070028311; Sun, 12 Jun 2022 14:40:28 -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.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jun 2022 14:40:27 -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 12/13] can: slcan: extend the protocol with error info Date: Sun, 12 Jun 2022 23:39:26 +0200 Message-Id: <20220612213927.3004444-13-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 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=qYQO15I8; 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 --- (no changes since v2) 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 3df35ae8f040..48077edb9497 100644 --- a/drivers/net/can/slcan/slcan-core.c +++ b/drivers/net/can/slcan/slcan-core.c @@ -175,8 +175,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; @@ -255,6 +365,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) {