From patchwork Wed Jun 8 16:51:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2040 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id C97F23F1F7 for ; Wed, 8 Jun 2022 18:51:43 +0200 (CEST) Received: by mail-ed1-f70.google.com with SMTP id z20-20020a05640235d400b0042dfc1c0e80sf14844872edc.21 for ; Wed, 08 Jun 2022 09:51:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1654707103; cv=pass; d=google.com; s=arc-20160816; b=wQluX+axLCxr9NELO9GPgsDp3vSdFW8CZ1JlZRvZyzl7AmgLb5IpygMU7yA6cqDlet undeXxQ5FxI+nX13KxJMKJeL1y8LmBXRAS57wqL0aOJbjdW35xQjFiDghSesRLW5byK3 uWgSjaF1MOvlTZCrykk/Xvq7EfHrfAf17u5Ve5sqvMdxj3RG/Soxy0eAHPG3Kvy8kmjw cSl+DGRMR/I9JvOGsMTP63ymBk/Ftn0LMB2kqT7Ha/kntE3Y7aUvgsey8BQxkxS+toR2 zZ1jUTo+juhEMgLGrmpDl5FXhNm1f6rlM4BpIY8m1t8GnkDaMSbUaKkCV7k1ArKd1Dqa SeYg== 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=f4gHt9DFSEiZAYAxIa+iwA7d4a7VD9Q8ibrcD13ebhs=; b=dv5ZMpsyVIseuwEFuRdPmKYbNUfphyggKVIwOqiD7W8iwrLJ8OV6//Mr2KP3ahPl/M mEmcjt//eFAAWrse3/IABeyQmvfASFXoTI0UHW8kXkzYH2x//0lWxVOJwla0BtcrGnk8 TLbBQelG7xXNSpH0wg2KZDuKtqNgfGfk+6lo7IuMwJQElPD9Xy3K5muDWp//HnjNYdDJ evoGgr5G/ZLTosN0D2WjnWjV0PHQT8ikPtGasN5oQbh/jRqwGOtGg7iCjSbwj0QJ8ESn YfLJuo80ZWsau4M5/9kneZwkXCRtBhpUoD5LE+6pBlVmMHTZaLDcsN2kvYWznmayT4z6 CwPg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Rxct20Wg; 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=f4gHt9DFSEiZAYAxIa+iwA7d4a7VD9Q8ibrcD13ebhs=; b=qOkWMI529wx3Ldxz/0hFCEFjEJsy4X5iyCHdbfSIUJKlVHCoXC38Rt87JrJigqWPRJ xetqOlb9q5YDjYYLdsiQBRu7S+zGS5+w9mvXfaBd9a1njhe2QLRw0v465fgTTS9LJ1jQ 8Ck0d+1ryypW3+iCFhnqWasMmO117pVobhGhs= 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=f4gHt9DFSEiZAYAxIa+iwA7d4a7VD9Q8ibrcD13ebhs=; b=Mmr7niEpber9skrry+pPBmZxOil2GL0Fsda1HL7iC9fEi3aMpZjd6GUwUultp7gZRt R/1GI7nRmT4qU65cxvCtoXV3+ZOr5WDgHpfu+egN5jikx5whhFaZj2dlVp39zvXLVlO7 QmTHZfQxzZPTitfWHVm5fC2anDVMOAoRwIqilHALJo2zmL0QdCVd1tEZQYq640bP6XoT 3BwjkmkMmRkjEytw/CFroD3Fgftm4CJWqJUTpfNp6L0SF4haSO9GTDSduar9rtYhcoNV ytxDK6vc7ezyEk7E11E1R+t0uNFpqn+RmyhZWc9udLld+uhJpVmyV+WPCe5mxKXoOcpc Tkrw== X-Gm-Message-State: AOAM533X11dKk1917WMj+uzOGzQMzVFxYYt3Sk7GQR9JRsNnsy7u94c7 SgztzJ/0RxiatW5nhES5NghMK3pO X-Google-Smtp-Source: ABdhPJxsuQ1ii2WOlDHCw9sRytSR2xJ4T0IAARxE6yVlFR174J3gMo+frpoltEBsvw67/tnFA98Xsg== X-Received: by 2002:a17:906:a0ce:b0:6d1:cb30:3b3b with SMTP id bh14-20020a170906a0ce00b006d1cb303b3bmr32160102ejb.582.1654707103605; Wed, 08 Jun 2022 09:51:43 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:5414:b0:431:6a31:654d with SMTP id ev20-20020a056402541400b004316a31654dls190149edb.0.gmail; Wed, 08 Jun 2022 09:51:42 -0700 (PDT) X-Received: by 2002:a05:6402:27d0:b0:42d:fbe2:57d9 with SMTP id c16-20020a05640227d000b0042dfbe257d9mr41374625ede.47.1654707102613; Wed, 08 Jun 2022 09:51:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654707102; cv=none; d=google.com; s=arc-20160816; b=uyMJlpD919Ba5kNyDEZlHcqL+UxNlEieOmbg71VscvRUIuFi7QzQo1eEEFptit8A6s bkzuxCbdYlMemtURT/b3Sdi2tB7afvLGjTiukZnoWzuObSXD2FM56CvBMPSK7GdSs/Sp xsuouCXibrBeU41w8nhjEmMFrRv5P+m+6eBQGqwDpk4lOYvFdoiqE9aLUzxVxo63JC7B 2yXzgqePusssR374TUkOJ9YTv/mwNtl8nTvcbGwso9IDdVBiUx4TWEZxokS0xFgbaLW6 ek1wGgw1+tc4GoT7MnUt1++hr+X+X9ibriOxeaN45Vuf7I2kFeZANOCdU3toyV4+KKhY w5Vg== 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=bwNtXSOCw0XDwGW95Gh6yPmxJxefcbSMC7JInqj3ttk=; b=fao/Xv2HSNfvje8rlhUix3zoqd6OjVIX+uRNznncvfS8YJK2ZFDOWbHN/NU6E29/UO Wuk0PN/siLTCrR5Hqjqbux9Gu16tSrGMygq8UwD9uizBWqL3jUWtbNBkCVCLIpCR1xAU ds4jEcYEx1n2ziXgPpaXbO6XFm6UgKwudd5ir9ZlLg6vaQylNjhIAx7H5MC+uxlpBydf Onoc1HbHd8cNJPqLeQ7XdeoIO6nAxE2cu7Nkqhu+3jKjXh3J6rsdNgNwR9Ze93kB2sj1 XnEj7KZXIOAexbfw9RkbB38Emi5tPoVqOtZX7WuRxEVvu7DHPFZ9vT3Y/Lc4yC1nBdz0 L2Tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Rxct20Wg; 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 q20-20020a170906541400b00711e504e9b2sor2317833ejo.113.2022.06.08.09.51.42 for (Google Transport Security); Wed, 08 Jun 2022 09:51:42 -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:90c4:b0:710:456a:6981 with SMTP id gk4-20020a17090790c400b00710456a6981mr23907500ejb.484.1654707102377; Wed, 08 Jun 2022 09:51:42 -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.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 09:51:41 -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 13/13] can: slcan: extend the protocol with CAN state info Date: Wed, 8 Jun 2022 18:51:16 +0200 Message-Id: <20220608165116.1575390-14-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=Rxct20Wg; 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 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 aba42e284274..22a261f2477c 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; @@ -170,6 +173,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; @@ -372,6 +436,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; }