From patchwork Thu Jun 2 16:04:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 1998 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 88CCD3F1D5 for ; Thu, 2 Jun 2022 18:04:54 +0200 (CEST) Received: by mail-ej1-f71.google.com with SMTP id kf3-20020a17090776c300b0070d149300e9sf235911ejc.15 for ; Thu, 02 Jun 2022 09:04:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1654185894; cv=pass; d=google.com; s=arc-20160816; b=yh4dObG86V58V9+/3MGaOPnhFBCf/VTk/qOMjK79+4c2o8uiNvjql3M3IHQF0vivzH +O4b7bQYkl1cAb1lNnuBhU60yYFHWvNUmBLL72wctGM/mhX0P8F96eg4zYMiEmW9+OY7 Atwqpovl9YSSiurarsvefhX2SQ2bWNAheTlAdzjxft5zK3z9eA4I4RQqk7BTGoaGqzfv pRhA0x3VugMyMqp/QvcETr4LlY+qR1/K2WjgR6DFWTywbKlC10BUnFPOSWtr86bS07dr 0CL8dB7nQwJp8hzWVR6z+hdiUYeFhTrm0rz0wR6hJQqfiY7aoEKg8mX5eJGshunHA67P Gbzw== 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=sd3hIMoTnmD8fwqb6G8FDJDqa/fLQl224jiJHsKvqOs=; b=Bm2l4xea3yiiFFQqk3onxy0rf+SgCz/Pg1RFBsTIJ1EI/yQ1n5KiDdIjx0z1sfJjIC Ns1ZocTyYSgjJxG6L3pg2s44dYxkGCoZwMcKpnX7qffCf5XT9f+6f8a1y1Z5ZG6kmpZ1 Zv44tXxOpoe0PknPEZkVGss5t6bPqZOMHXhXnEbu3YEtaFdEz4jpC5ax0qNBfR+OnkI3 GTwyummL5I2LiUjU+wd/wDYQakjwBEzChIvPINo2ypg919Da5NmDZwEg9Y4+L1YT1HsC uFTkDqi0kGHpi4oz0+NR++MRsg6L40kTidqyJzM8aRYdLaDtx2a16sm2upEjXc2G38XH Rb0w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=pMsGPkxE; 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=sd3hIMoTnmD8fwqb6G8FDJDqa/fLQl224jiJHsKvqOs=; b=c+J3eKfMOsGka49GZILydgALQS/bWB2/XllhUUlQHlh+21Qz+NxSXBTKH79AscA8S9 EidPq2Udia9dvgfkyTJwMDEl6SbA1oJQVHops6wmzP0qWNeLFnY0hTTzVG20FK4WxGp0 VfFLVRSZEeKpeCW1rO0NMJjZz/igT7VEJLX2s= 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=sd3hIMoTnmD8fwqb6G8FDJDqa/fLQl224jiJHsKvqOs=; b=foglIgPo/IU8xP3zpTfRnqz/0tnR8RR2gsgNfhZ0bHNzOit2ayZbb3pXFXX/uOs9af 9Zt+bvFmraPqgSJWP+RC8aucDtVZhTfY6pVTGw8w12u8Csluf52/WVUrEn0S5ZOSm/t6 HzMcrIgR0fEqHIZWT1ulY0d/XOIYP8adnbEVDA9r7tDjE+nFzcOZFLbmEwc6vx5xo96n Uw54x/TgGKIy0Xm8KvdbAIZdLiForY1k+30xOhpNxMWcl4RqCZWw0OroemCzgYnTbOji D/QrYO/dMocdMogFuCPqTIXALujX9FXBq7tsH0hzn2KtewtKMirOH7A2t2hdBm1A7Dfe 8ceg== X-Gm-Message-State: AOAM530CR8l8dfEhytaW0FRH52J3WjSEmI65c1junUv3oxr5861B+NJs K9jj3a5Yx5WmvFsm4QMudQOmBOFa X-Google-Smtp-Source: ABdhPJyc/a3KgRlDzF3EqSsabNvaBt0kdV+8nyLbtw5u2Pa7uRYb8MJ0l1LBkX67dLwByF+nhtLaxQ== X-Received: by 2002:a05:6402:2410:b0:42d:a513:5536 with SMTP id t16-20020a056402241000b0042da5135536mr6327710eda.395.1654185894318; Thu, 02 Jun 2022 09:04:54 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:906:86ce:b0:6fe:c3bd:7a48 with SMTP id j14-20020a17090686ce00b006fec3bd7a48ls2949768ejy.8.gmail; Thu, 02 Jun 2022 09:04:53 -0700 (PDT) X-Received: by 2002:a17:907:c20:b0:6ff:9e32:25d8 with SMTP id ga32-20020a1709070c2000b006ff9e3225d8mr5033364ejc.62.1654185891434; Thu, 02 Jun 2022 09:04:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654185891; cv=none; d=google.com; s=arc-20160816; b=JPP+IsBSGZdx57Aren8O5PUd6WltNJPN1mgGVFM6SjHtddfKNOAyGu+MTrlJZXe4lx R4kzOi+PG9+cdEpq2IAQO9Nnc0cwZLQqjv3j62+ZDgzQn6/x9ZhULYJAdKDNqLBXWfls 4P0NsCuo7u0ATsSqTAgpZg5s49SB1WGjbAVtzI5dWvnQ+s7cxwimmZ+NPTJJ/ugDVodn 0X+NyDMBKPhNGMFLI5oVR5PT7I2KVnXeV1JDJuwTRgrkD16BtuwqwuFkP0GcJIR0mMTx Fj0+UeQUIRiQyNHWVJh3dZdoeDUjqZQlF51768YNrRfD1mjrOGd7zLz5dnrzBh+6HfB2 leDA== 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=tIMw5y3svCAj2C0qGslIPuiNzahiJeK2yVI7G04kUeQ=; b=fRfqEPHNEvjF1A2o1rTY5k5GPaOcKzM1jG50RahZ88uTUn9TzRHfvjNS/do+doVN0e OvtJ2Uy0R5qef7LruKY2NoZpCz6qFeOWZ3kLdk2jv7xY1y4ynu7t4Ip14bMZjWOnDBZ6 ek7APGwjAjcgjekaFVborWIiD3cQxYlKf6a61xApU1AGeCluy4ztLuuluxKn8yODmn/f IKryTKbn4O7jZtXpg6et6Ol0JCq+BHecdW2yKBwcfSk+bUwOu3zyHyvrfh+OpOeUNdzy bjfHV9f1xjhhFelFBTY8Uv/34D07MDatFgcPCPihsBuTHpAfKAxMUPN7so5b9W/m8GIM xH5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=pMsGPkxE; 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 ds14-20020a0564021cce00b0042ddf53fd3asor3204263edb.58.2022.06.02.09.04.51 for (Google Transport Security); Thu, 02 Jun 2022 09:04:51 -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:aa7:c852:0:b0:42d:70d8:2864 with SMTP id g18-20020aa7c852000000b0042d70d82864mr6228330edt.379.1654185891009; Thu, 02 Jun 2022 09:04:51 -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 f3-20020a056402150300b0042dd3bf1403sm2637095edw.54.2022.06.02.09.04.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jun 2022 09:04:50 -0700 (PDT) From: Dario Binacchi To: linux-amarula@amarulasolutions.com Cc: dario.binacchi@amarulasolutions.com, michael@amarulasolutions.com, tommaso.merciai@amarulasolutions.com Subject: [RFC PATCH v2 12/13] can: slcan: extend the protocol with error info Date: Thu, 2 Jun 2022 18:04:33 +0200 Message-Id: <20220602160434.225417-13-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220602160434.225417-1-dario.binacchi@amarulasolutions.com> References: <20220602160434.225417-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=pMsGPkxE; 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 v1) 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) {