From patchwork Thu Jun 2 16:04:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 1997 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 3824A3F06D for ; Thu, 2 Jun 2022 18:04:54 +0200 (CEST) Received: by mail-ed1-f70.google.com with SMTP id t5-20020a056402524500b0042deddb84c2sf3797875edd.5 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=IsbcNrDkzbtN99K++jYzH5aZZrj83YyQU+i9O6gLgmhVIEBoM+mHamy/k0dlm2Os8O ktuN1VPhv7GOKiWIODYY/2RXQfF4rfkogyUhhZLksyhVVp0sWKlJn173ZnPdFp5LEIx2 UeNVPX3Ff5EAjh56HHQ3lI5KpltZ78DXNw6hAF46bnaFQleA7LNzjrNofd/Z1tdaaiwg 6Bxg8TWCncnhFBwmfn6rd5Iv6ceCpq5IdQ4QmvNw9MEqO3Cl5kcYhHPgzfUJhky/k4nL Pnw6iFak+VK/suUGjwxBgm39Z+mN0qyUb8tJiurY4UUJa7NcnBSGtC8F6oUBIRkZ3g1K ImxA== 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=FXXGJ8SEbNZz+VbLvdzXVaRHuPhZowf0oL0YX5HxL5c=; b=b4kAr5XXA38aNdRI7/09Grk9QrAepArLQodOh1YVQZ1e8btoFqwLqhDDiLsZvqR8Ne X8DkKNkxmrlSJK612soDyDemP51+Lxkmfe809nZgd2sV87L6Nr0hXdCf5bEeX0yJXgwB DLgXdx363ZBCfCbvmU7Mf/OGFiv1Y2hpIKqcDMCTQFh56842RLbnYGPgB+/nfUw9ymbe CCvnMk0p4g1aRN50wkLZL0wCamm4apC5Xozom/2c7A+MDLa7BNcvvvmoa4ekTk7pZH5O 7p8rxYxN1bX6TUUcrM/TRmGeQ+fKrb9AxqpfWiHT7bX8wFyAmyyxVUUGDqIMtpV6vcMh /uug== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=e3DqoHgH; 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=FXXGJ8SEbNZz+VbLvdzXVaRHuPhZowf0oL0YX5HxL5c=; b=Z6Oy/yhFmJRFrqaGBwgu3wnoZjMATCdzl0DWASf2J7rguvDMekQ4ZRUFqRnZn4sR4g J1yYEjao9KRiIoWMWocQoY7BTXVVWGvKDLeuLXLHued5OpVYDG2eEohIcFWekyV2vNcP N9sLlrJ/8Pwf1WIgWtRNDWO88h1qykA4WEwyk= 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=FXXGJ8SEbNZz+VbLvdzXVaRHuPhZowf0oL0YX5HxL5c=; b=YZIxUVe7CLMFZNwxDD3sHEnih7ha3eN25Ow52+0v0CNvbb7/biqnu69cOcpIlSavLJ FI/VSXlkINCW342dGRzSVUc/iOx6FncNQqO+S+67zlMRrIqBQ3PHuX3AsvdkK+8w8PlV WlyQia4sJjm3hJGzkTsTtnY9h/qVGs8DoUz/D2M3Kkc04pubv5iSOOnO0MZJ9rmFxyrW qpAA8RWwBm2IJOV6E0h39iKQl9zQ0pYU6T9V29iI+3rI7QgfzSY5o3t8WZ5ofTGseDZi Ys2a01AsE9OBz8OtAGZBVP3VoxhjFSor9NP6w6oMDN7/n05NoIsuQq8xreRU3Mge+Hyv g0Uw== X-Gm-Message-State: AOAM5321K0eVSPPz/1SiqihduaOHpPODZGJ6XyGUsavdPAa5pOxtkeVV LabjCag3LHZ2UPb2sczJbx/nXtpB X-Google-Smtp-Source: ABdhPJyyTracrgz84IxZzMl5ZP60lwZdxGioae41q7KL1/Xbmz2AcJajMW6riw1ls+Yt1MTYztrdUQ== X-Received: by 2002:a17:906:c2cb:b0:703:9e51:a3ea with SMTP id ch11-20020a170906c2cb00b007039e51a3eamr4954394ejb.130.1654185894051; Thu, 02 Jun 2022 09:04:54 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:2741:b0:41f:7eee:e393 with SMTP id z1-20020a056402274100b0041f7eeee393ls2361663edd.3.gmail; Thu, 02 Jun 2022 09:04:53 -0700 (PDT) X-Received: by 2002:aa7:c457:0:b0:42d:bd18:4ef with SMTP id n23-20020aa7c457000000b0042dbd1804efmr6449603edr.112.1654185892994; Thu, 02 Jun 2022 09:04:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654185892; cv=none; d=google.com; s=arc-20160816; b=uQe2lTHm1a+4iadCx8PLf4UKacQEAoK0Vow5i5PtVJoeG0+pfSI9NdYnDs0W3Y3fLw OW28nGy438vCyeCdhPDW66c/RV5Um+FS6c1UeQYx8zjj8YNMYDdWn4LZNnBzQoMoxbl9 kG9gM6z1GJepWy8IH/WU6HV2T0cRsjUibcNhfHHizqz6Hg0AR5wO3Z/8UuPcJVXxEjYg EW41l9I7IPC98hZ2SXD/HUoS6KbfN9LxczFJ9SCFzTUl6/ZdunAyengPPjPEcq/O1oSZ O/dmWd/L0XihfWDs3AWWSLsRoG6BnnxxXAUN8zoxezhWvYcSOdtvZYcqcNrG3GN1s9zX X4cg== 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=v6Qqrm//g+VUVMemYpr/urjW2orb6sFKqRMVXIOVGPs=; b=mBNq4/fVacQSxmolHOHsX/NUkxM+xBBI+qSfihsT2tsPhL47kKYJcYZOP9qyKQSbND mPPewPU2buNntkpSPTUkg+2p0MxbJQsZnhMfSWit3brNK7/uxvLFS44HtgK5Zn5RPF4u tbf5dkarPBYKvruCmzZpv9yyquDH5MjS9q12yKcy6xhfvecsXWVu0fpA1xJMxLg7rEC6 JjhD61D/p73wWh2sfkIoXdiIA2z+iOxNITUmjDOKQAvdATc0EmEg2v9j2GrQAfWfON+i 0CEbLb6uf93t8p0qP25HFRfsMcpDqEnb0+3T6pvM0Vf38PziY6yUxIhen256Ya20RceO zCkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=e3DqoHgH; 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 kb2-20020a170907924200b006feb4ab1eedsor2073369ejb.104.2022.06.02.09.04.52 for (Google Transport Security); Thu, 02 Jun 2022 09:04:52 -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:6e88:b0:707:ea6b:5e15 with SMTP id sh8-20020a1709076e8800b00707ea6b5e15mr4870880ejc.57.1654185891908; 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.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jun 2022 09:04:51 -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 13/13] can: slcan: extend the protocol with CAN state info Date: Thu, 2 Jun 2022 18:04:34 +0200 Message-Id: <20220602160434.225417-14-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=e3DqoHgH; 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 --- (no changes since v1) drivers/net/can/slcan/slcan-core.c | 65 ++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/drivers/net/can/slcan/slcan-core.c b/drivers/net/can/slcan/slcan-core.c index 02e7c14de45c..ab4c08a7dc81 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; @@ -182,6 +185,66 @@ 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 (unlikely(!skb)) + return; + + cf->data[6] = txerr; + cf->data[7] = rxerr; + + tx_state = txerr >= rxerr ? state : 0; + rx_state = txerr <= rxerr ? state : 0; + can_change_state(dev, cf, tx_state, rx_state); + + if (state == CAN_STATE_BUS_OFF) + can_bus_off(dev); + + netif_rx(skb); +} + static void slc_bump_err(struct slcan *sl) { struct net_device *dev = sl->dev; @@ -354,6 +417,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; }