From patchwork Sun Jun 12 21:39:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2060 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 53E433F1DD for ; Sun, 12 Jun 2022 23:40:34 +0200 (CEST) Received: by mail-ed1-f72.google.com with SMTP id m6-20020aa7c2c6000000b0042dc237d9e7sf2951202edp.15 for ; Sun, 12 Jun 2022 14:40:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1655070034; cv=pass; d=google.com; s=arc-20160816; b=nzVboKdW2pYzN9dPS2cDXK25T2enrAsrwL2yBPwfRwfOY6MxpCxanxA4r82BiD5LUF 4kj+IF0x2WMTDhWICP62ChPAZDMglV8qcWX11TWRv9Wej79pKVydwLqZBvhPvIOH/8of IATBu2mdf9jfgRuoYRdNNJaK4EvpXGjwHC5FN2UTRwnAKy4k5wIlUWPR/ZUs7FYSivgO +3/A33Qe6MHimTlQ6b6IGOaneGaJREm+cH1QoeaYDnmZGyR2rqw5k116v/4SDq2SW706 hoNzGtZtsNGYLoOfT6ZIm+1wtXHFMQayCZXDvsnahuCDyiWyeHY0gOOgEy60Gxu6RpGQ Mtbw== 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=2peosJwm+KCw43syIALFHUkYq+2jYtSoSjaW1aTSBWA=; b=kppZ9auxJmiwBQFAxeSPAshm2nGfbojs7J1i80V2qM33BJDlc2Q+cEPCAKPBasotrV PTP7h3oWHpShCHE5cA501MgoKEPDYkJ/qSSicEUpaAc2a/CpJIMlLncj0zF1hyaBj8B0 EjT59/0CbH/7BHWJjHEH41+tZZiWtUVLte27UcghIPxZs59J6UxWqrLZ/KDK4WPrUihx 7NXdstQC/V8LGcSmicQTQ2BeqnTuDwgrSXJzGSlTeyubREimpSUb/61AwppZsQ6LfhQd Jj5QPUFi10HyNPrQicCpPRpERhelLJAxEQVChtAOuIS8Lv185gVeYx7ISn7fFPHB8Vpk 8uPQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=gkAi7IMO; 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=2peosJwm+KCw43syIALFHUkYq+2jYtSoSjaW1aTSBWA=; b=mxSgl3d1xbRzmgMQKz4K37Ds+Ckak3hiB2vjEAsDaJighrd0dnb2HbDFOLpGx2KrMP eKwPfDQ8WsBbfy7XTkUv8OGZ+BXNkksKxz9IHP5SN1AJYDHwMbDEovyGXLw74wJzOTjg plxGuw5kBcFyzUiPtJUHatZZurN9QjMxtW3TQ= 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=2peosJwm+KCw43syIALFHUkYq+2jYtSoSjaW1aTSBWA=; b=e/1E6G4paVLOOSTEI1TDP2zwDQMm8nJOBNf0yyDlcc2XjWFq/L8pFD1Zr7E/z6qNeN GYhK8QqUXSDHSRT0iBfN/YfG3qkVWQIEgeKVN7fFwv12ZoOQJafL3ykx1qV0Ai0DN5lw lREhZbIgmA4czShn81aGzzmWYs8OHky9ps5MZ7uSoMT/No3Rv6zI8NRiJiRY2kDRhmeS DO8TuwXOAOntfVhCbvyFk1kIG0sY1DVvBgafv+YxoPrLkS/tKRObHSZIxfyVG+z0wXhu Q4ZC8pL8fUONpnxT96HQ0/6rB8MXi+zV6EAPkYDd9kpanKe/OyG04gfi9PDCTp/cQkgv UWyw== X-Gm-Message-State: AOAM530agLAGgWbpYF4Kg1K0X+f82skIMCDm/jOcRKvotc6z+n9z1zu9 rtdXD+rFZtEmu9H2Kker+Gu21EUT X-Google-Smtp-Source: ABdhPJzRMPN8Lup3jPVW0fCGo99qV0RVQCOdVMXg6J70zUUpmbXlA2OMEHC488VagD5Aelb026HRRQ== X-Received: by 2002:a17:906:49d4:b0:6d6:e5ec:9a23 with SMTP id w20-20020a17090649d400b006d6e5ec9a23mr51448279ejv.79.1655070034155; Sun, 12 Jun 2022 14:40:34 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:906:5ac1:b0:6ff:ab8:e8f with SMTP id x1-20020a1709065ac100b006ff0ab80e8fls1010610ejs.6.gmail; Sun, 12 Jun 2022 14:40:33 -0700 (PDT) X-Received: by 2002:a17:907:7d91:b0:6fe:efb8:8f97 with SMTP id oz17-20020a1709077d9100b006feefb88f97mr50409604ejc.717.1655070033113; Sun, 12 Jun 2022 14:40:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655070033; cv=none; d=google.com; s=arc-20160816; b=uJGlFzQ8LVv2sdXhiXG18DhK3UuUJGIkWTOK/xRPDyp+PezlLwIfvd+IBwZl9pinVf T+XQcQSiF74WAxxwv/H479MI/JyHhvkaOSQ+QeG1PpzXYAZKNn7b9a/ZEr05Ot7kS4H8 z5t05xAHQKWpU5Ek6VyE22BIXNblJ2+hE5YCCRwuKEtb8SgYzum37FLOjEp94+4vMbNf K0V4iqCQTNwxdFfdF7WD+hr3H+EFgsuaO2lX+9zIfXKOEikO67tUncy2ac0HzYzpmz4P BzuTCkDrw6V4+1NpQ7dfb2ieNtVC4CSezynjjQSYD45zqS5kfDUbiCf9ieEXmhQz1CKk R5gw== 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=6efkiC5TQ5d8cecscsrXOmD2HlmxuShBu5gYbYTpObM=; b=zZe5KCetrnBc5MYR3/8XP9pSg1HmM5wPwjef2+w5Gsv/KUCttLttmcIEaH8J2Bxw0h EITE4Oh5f8WneXYcBIDSc4PE29Q7tpf2FcAfelMFrLyvkzhHtWoCuLpvQVYc+0k0D6g+ Ax7e6EfvmgAMAv8UQsKo/OH20/fm2ljK0KGQ2ufSyXTqwxMJhUVS0OAIXn3YExJ5Ep7A clHexbMMV4HUP9NCAcLWf7HGRC2nVxmCczRcE6ooFQ/xbzbQ4NHjINJ0BwpkaCf1eaqx WGF4QWolPxvOMVoujRDEbNvsmdZ/1bx8ca8Ab59IRUucHrN8o5xP85voGzTn1J2B7qVt Uybg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=gkAi7IMO; 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 z4-20020a1709063a0400b00712134cb9d5sor1287103eje.69.2022.06.12.14.40.33 for (Google Transport Security); Sun, 12 Jun 2022 14:40:33 -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:907:9605:b0:6f5:c66:7c13 with SMTP id gb5-20020a170907960500b006f50c667c13mr49390538ejc.66.1655070032889; Sun, 12 Jun 2022 14:40:32 -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.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jun 2022 14:40:32 -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 13/13] can: slcan: extend the protocol with CAN state info Date: Sun, 12 Jun 2022 23:39:27 +0200 Message-Id: <20220612213927.3004444-14-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=gkAi7IMO; 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 state changes (warning, busoff, etc.) and forward them to the netdev upper levels. Signed-off-by: Dario Binacchi --- Changes in v3: - Drop the patch "can: slcan: simplify the device de-allocation". - Add the patch "can: netlink: dump bitrate 0 if can_priv::bittiming.bitrate is -1U". Changes in v2: - Continue error handling even if no skb can be allocated. drivers/net/can/slcan/slcan-core.c | 66 ++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/drivers/net/can/slcan/slcan-core.c b/drivers/net/can/slcan/slcan-core.c index 48077edb9497..5ba1c141f942 100644 --- a/drivers/net/can/slcan/slcan-core.c +++ b/drivers/net/can/slcan/slcan-core.c @@ -78,6 +78,9 @@ MODULE_PARM_DESC(maxdev, "Maximum number of slcan interfaces"); #define SLC_CMD_LEN 1 #define SLC_SFF_ID_LEN 3 #define SLC_EFF_ID_LEN 8 +#define SLC_STATE_LEN 1 +#define SLC_STATE_BE_RXCNT_LEN 3 +#define SLC_STATE_BE_TXCNT_LEN 3 struct slcan { struct can_priv can; @@ -175,6 +178,67 @@ int slcan_enable_err_rst_on_open(struct net_device *ndev, bool on) * STANDARD SLCAN DECAPSULATION * ************************************************************************/ +static void slc_bump_state(struct slcan *sl) +{ + struct net_device *dev = sl->dev; + struct sk_buff *skb; + struct can_frame *cf; + char *cmd = sl->rbuff; + u32 rxerr, txerr; + enum can_state state, rx_state, tx_state; + + if (*cmd != 's') + return; + + cmd += SLC_CMD_LEN; + switch (*cmd) { + case 'a': + state = CAN_STATE_ERROR_ACTIVE; + break; + case 'w': + state = CAN_STATE_ERROR_WARNING; + break; + case 'p': + state = CAN_STATE_ERROR_PASSIVE; + break; + case 'f': + state = CAN_STATE_BUS_OFF; + break; + default: + return; + } + + if (state == sl->can.state) + return; + + cmd += SLC_STATE_BE_RXCNT_LEN + 1; + cmd[SLC_STATE_BE_TXCNT_LEN] = 0; + if (kstrtou32(cmd, 10, &txerr)) + return; + + *cmd = 0; + cmd -= SLC_STATE_BE_RXCNT_LEN; + if (kstrtou32(cmd, 10, &rxerr)) + return; + + skb = alloc_can_err_skb(dev, &cf); + + if (skb) { + cf->data[6] = txerr; + cf->data[7] = rxerr; + } + + tx_state = txerr >= rxerr ? state : 0; + rx_state = txerr <= rxerr ? state : 0; + can_change_state(dev, skb ? cf : NULL, tx_state, rx_state); + + if (state == CAN_STATE_BUS_OFF) + can_bus_off(dev); + + if (skb) + netif_rx(skb); +} + static void slc_bump_err(struct slcan *sl) { struct net_device *dev = sl->dev; @@ -378,6 +442,8 @@ static void slc_bump(struct slcan *sl) return slc_bump_frame(sl); case 'e': return slc_bump_err(sl); + case 's': + return slc_bump_state(sl); default: return; }