Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2099846iof; Tue, 7 Jun 2022 19:44:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwGkMyTdcqFzVoMlSrTTui922GK0+EjZmyqGiWf/Aw/J00gQmrDT5R5K2+co6xEldy9Ykkj X-Received: by 2002:a17:90a:6747:b0:1e6:6a5b:f040 with SMTP id c7-20020a17090a674700b001e66a5bf040mr37737407pjm.134.1654656250151; Tue, 07 Jun 2022 19:44:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654656250; cv=none; d=google.com; s=arc-20160816; b=dOiA8F9cMIWePsrxBOwq4etkBC/OJXx+cq1S/6zXyectNbyRizT33l8bhyUusjkNF7 dwmcu3KuLAZcQFTU0Xx5x4l9LeoCdHRcStVfTOEU5j1ZI+YECsWCxKEce60dW7G2QpeT rwgH/DqSmB7Qjomxu7/3uGxM58/b6rGJCHkNPZ2ovurTw1OZ1vyt9+utuBuMV4Zqj8Gn e9UnxxoGbMbiO1DOh5ngAw07pNgeh76yq9srlqS43hPnow/r9w6aj/nS94t81X1ig/8H SMRaCwcm4zompXgCPmvasICib23BuEX5svDwj8+Hjqggh8G8opHhPRGN+LmzDirhXr7J ZzWw== 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=2VLfBpv9snTnPtrFeblfPn0318JEYJPp1U8Dhg0IAiM=; b=mGnjSTErDajPaFy5ytwYcJyMkLUB/50UxnmUwnbAdSLUM/3TcDrmyVMpxaD6Ue6O8X Tfn793Qs/hWm0y1jiaCd+ExcDvEX8EP7KjWMXD8wxtQeFf+G+Shu1FT+tF6+Pmm68ysP Iy7f617uQdP/435RQ3GUnVIVQUQKnn1NcpPQLWd6lKRUgrd/34kZZmS1igvzCrshx5Um wbPqEMFJREGYkDMnd/PNFZKHSL/W22IY4Q9UiWik6SAaa+n1KoWxklYjGxQ8QFdh6mQ5 A3pBYRfj47+p+ZF/+gNqZTAOu2nJVLLNIA7AhoOICew+UCKEPrugHHI6oEqekljUZKmT hCmQ== 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 linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id u3-20020a17090341c300b0015d21512abfsi30899770ple.527.2022.06.07.19.44.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 19:44:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=HMeORKBx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A6495250E70; Tue, 7 Jun 2022 18:10:07 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240094AbiFGJur (ORCPT + 99 others); Tue, 7 Jun 2022 05:50:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240175AbiFGJtE (ORCPT ); Tue, 7 Jun 2022 05:49:04 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D1C1E8B9F for ; Tue, 7 Jun 2022 02:48:34 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id v4-20020a1cac04000000b00397001398c0so11384881wme.5 for ; Tue, 07 Jun 2022 02:48:34 -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=2VLfBpv9snTnPtrFeblfPn0318JEYJPp1U8Dhg0IAiM=; b=HMeORKBxetV4QI2ugUhV+SAFIaXv8HHxDgkUH6QeuVHCf9v7Ri67vG6l4/TKkI7Bat HO0rixGSw1GsvjQisUutl6Qnma4ggDLfNm64iaaHEcfW00w5/9fRFJkRk3C+pezT20W6 NXeHFtQDrlGzyiLuXu+SAj4JelCzvlNlM/Urc= 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=2VLfBpv9snTnPtrFeblfPn0318JEYJPp1U8Dhg0IAiM=; b=HXZsUIJs8nQWUdzyqHUO4E0BUrwwhY6AR+hNHVXEiJqZHveCZALoU7wMiPSv7yMUjA Y7cOQqT9IWV4uKfEVZAn46ZYeKW/pX4fiBLnsDCjFpOeZz5bifJOFPZPwbmQ5fXqbQvM +VvQMywLIj5ZBjx3cp221WEVwlEhEvDpFXeYZBTU3MeLDmXcFu0hYUJ33n5KC229gb91 auako+8tb2nVtsMP5GM7EKLaGswkXKSwLRmXH+ebSe67gjrCoMg97zLvgH5Vkk2IStxM nw0OAgfBtrvLX1N85UtKp7C3/7tsy5Joq4lSRuvsbqDhil+w66FPzyOlBj1UBpEvWNBZ bfnA== X-Gm-Message-State: AOAM5326fZ9C/wOHyiN8whl7mWpvwN6h7iHZ6yA/1+7Z2/tC8ZaSF/1c ZxCNYQ2jcr3cfkH1pfyu0vKcGXZQEftiAA== 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 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) { -- 2.32.0