From patchwork Tue Jun 14 12:28:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2065 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 1B5D53F03E for ; Tue, 14 Jun 2022 14:28:27 +0200 (CEST) Received: by mail-ed1-f70.google.com with SMTP id k21-20020aa7d2d5000000b0042dcac48313sf6104157edr.8 for ; Tue, 14 Jun 2022 05:28:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1655209706; cv=pass; d=google.com; s=arc-20160816; b=EZHs7FZ33B0FwZlEI+3DRKg8NmXU9noBD5yA4FB9DD2PocL3PCldxWw/fe9bYarYYS JxO4Q36fvuzOPx97rw7phEUnjghXdwdv5IccXWnciznfyMZ3hiYDkaMjvEjCMZLkwjtq ObXJiVk28G+P+PMHRUqieFMC4gAmKOs1U8+PPMLwpaj9JMhaQx4lH7s4ltThBLx5NQ+R h3wmehx1Q+2JF4ML2eotWcKiwm7jMzjJXZ2DlXzKCdOu22khkuohi/Sb3Zo0r5pIVQ1w vijO0GVBYrwCkpXfRJuN9ZAoCOI3/FaP7vFlnuG7RM43+waVCrU0PgKQGuALFV/zFvbC csGg== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=xAUe0QqPEPStLSCNKwc/bqdh7jyROJahywhoaVEw7rk=; b=oOXmtRvmwG2hAXLfxl3fKAjfzs/VixRuaFjMs0Hy1DkfMQyTHgX6JkP/NrV92VmpCc yvkJTMiPPHKqxQbUD4LXMi6Mjhqn3+JChTz2T9D5SYOF7gdNvUmzItXKNN+xGpr6bnm9 t/A7pfiU4x09oUkkWXC/FmXxjcPZUhqpoMnXv8tdTpND4BliMiMEvc5ibqTT/SkmbbjL /sW2mW87pqqVCt6GV4h8pUNY6CjcaHJ/mHq8O+dM6pKZ7hjsSQfJf6SyZO/vNXM7u7hc sE5+YvEV9SuZMSkymdtOdXYzVaOIN3maqf0w6o+4RBn5yrs0wPbnK226oRGtdLZ6oQHY llQg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=fXAyHR6w; 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:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=xAUe0QqPEPStLSCNKwc/bqdh7jyROJahywhoaVEw7rk=; b=VmfBYf07aOKRTYdIJncFIwcY1hxyDBMs7gXAaIdNQwHrQa+mp0Pp4AIiZfBOi6fLU7 M7n/FVQFbMx0jjUn1dThzB0cHG0sDjhQai2X9T8skljzF/nATWFdRSQjNsMDv84lQx19 DpLij4N/JDX8s9i0gW7wFW6A1ArKT993Ipwb4= 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: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=xAUe0QqPEPStLSCNKwc/bqdh7jyROJahywhoaVEw7rk=; b=c8rOKfULUQdxnkYWHwx82c8RP/JNbxGLwbLdGc4jl/n37ncbQ+LBIBexDgUnDx+Vns 8YOKwcj7dgzj4A/yUCzUu+3ElAjshcdqdDsUffR4F1ulS+qreRtkI4rix6Q+BZRXk9zH O27k/mY61pce33He+8odorRJiDUwM/EbM2a7W0IO/+CjbbPPrm0sAEqrZlM/Z4cpMYJQ FfwSN7yLm3Ps8zqEc+LAY1Ci4Lw7x0OwXkUiUF9vbOUSFcaGLqzzsnsiK1JW05iYelXh 0aQ3BztYl9DrQ8u98imV8LJetarHrxuNLWt4LVFicsqrC3tqhaJyCSmkomlPgLAhm01Z RN5w== X-Gm-Message-State: AOAM530SUwEENvtdEwOtA1GYWbRrgi4ABRcIQ3IAzy1NufS4LnT+Gfzl XkYmlq8Q11S1c3ddOliWA7RxXmzZ X-Google-Smtp-Source: ABdhPJwm0xoYxI5HKdhSUtXw9y7ASvsnxLBz9UzTHrL8zz7uYOdbMRe9rcacqBj+o3p5vXVwNFg3eg== X-Received: by 2002:a05:6402:cab:b0:42d:c842:8369 with SMTP id cn11-20020a0564020cab00b0042dc8428369mr5764179edb.181.1655209706866; Tue, 14 Jun 2022 05:28:26 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:907:9705:b0:70d:ff46:7086 with SMTP id jg5-20020a170907970500b0070dff467086ls991790ejc.4.gmail; Tue, 14 Jun 2022 05:28:25 -0700 (PDT) X-Received: by 2002:a17:907:1c18:b0:711:c83b:8a14 with SMTP id nc24-20020a1709071c1800b00711c83b8a14mr3909644ejc.379.1655209705675; Tue, 14 Jun 2022 05:28:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655209705; cv=none; d=google.com; s=arc-20160816; b=vADBhYh9/G4lSKh/G9W5lHG1yBYvfv3DU0zxOLfWAeN5uCjyZPWzwYaZ+qVSles4J7 OfWvEkm/kq6WLtQBcvajCpmDp2Chlg7gye7oTnuSLv+Rzz87+TenDST1Je2MigzJ+ROV O+OIXF/2UB+wNc7kGEKwO8xW4oSq9szost0q7qNdA8cSZlhYOwWuhT1f4X8I+xNj/TT+ yDQESPF/RtcAYiJpqeB8HHAbnir1MI4CUXp18MTs/ZHXltyUHGwjK5npNoAq3NXxMdGL M5pDu/QxeJ/cRE1AOOS/1WXnRu3AvOqj2FSYQLP958Q2f3BlF+7u/5NaQH5VA9BgX6/L I4Og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=bhHRX/oRi5clzdn2dE/EY8/wgTCSEE9g8vSH+WhoX2I=; b=TafpVcdzsU6XIbHfhLZjclgX+RgwuDW5lex0RSL0crDR+fVQeHIQCyxUe1xkvPmD4T ZbAuDin4bJ7B3FTcwqyTxCFTXQKQTeo4P6KW+/0oiI0fNNwCbCsfOlEJWGc6AdEMdAAc SGn0L0JdjpYt7c4u4yngThna7wiYYuaDV4CH+jq29XA81K99uWD15PxHkYQ8eONv26Lj 6tsDM0cYXbvUyvj+2WDTjwfmFteHBlH8/pp+E2eQmFbfTDeuRaIOnVBoy4xfHA4IhVRL otMRgKKTF8BiSDrAzKDmkOiL8V9Iq2kJGBtZFxlL37T72b4MgJn5XXVwk/2UzBo1bw5U t9CA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=fXAyHR6w; 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 q23-20020a1709066ad700b00711fe7179a2sor3275375ejs.13.2022.06.14.05.28.25 for (Google Transport Security); Tue, 14 Jun 2022 05:28:25 -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:906:6a27:b0:708:1282:cbe9 with SMTP id qw39-20020a1709066a2700b007081282cbe9mr4290023ejc.186.1655209705333; Tue, 14 Jun 2022 05:28:25 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.amarulasolutions.com (host-80-116-90-174.pool80116.interbusiness.it. [80.116.90.174]) by smtp.gmail.com with ESMTPSA id z22-20020a17090655d600b006f3ef214e2csm5087043ejp.146.2022.06.14.05.28.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jun 2022 05:28:24 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: Amarula patchwork , Oliver Hartkopp , 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 v4 00/12] can: slcan: extend supported features Date: Tue, 14 Jun 2022 14:28:09 +0200 Message-Id: <20220614122821.3646071-1-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 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=fXAyHR6w; 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: , This series originated as a result of CAN communication tests for an application using the USBtin adapter (https://www.fischl.de/usbtin/). The tests showed some errors but for the driver everything was ok. Also, being the first time I used the slcan driver, I was amazed that it was not possible to configure the bitrate via the ip tool. For these two reasons, I started looking at the driver code and realized that it didn't use the CAN network device driver interface. Starting from these assumptions, I tried to: - Use the CAN network device driver interface. - Set the bitrate via the ip tool. - Send the open/close command to the adapter from the driver. - Add ethtool support to reset the adapter errors. - Extend the protocol to forward the adapter CAN communication errors and the CAN state changes to the netdev upper layers. Except for the protocol extension patches (i. e. forward the adapter CAN communication errors and the CAN state changes to the netdev upper layers), the whole series has been tested under QEMU with Linux 4.19.208 using the USBtin adapter. Testing the extension protocol patches requires updating the adapter firmware. Before modifying the firmware I think it makes sense to know if these extensions can be considered useful. Before applying the series I used these commands: slcan_attach -f -s6 -o /dev/ttyACM0 slcand ttyACM0 can0 ip link set can0 up After applying the series I am using these commands: slcan_attach /dev/ttyACM0 slcand ttyACM0 can0 ip link set dev can0 down ip link set can0 type can bitrate 500000 ethtool --set-priv-flags can0 err-rst-on-open on ip link set dev can0 up Now there is a clearer separation between serial line and CAN, but above all, it is possible to use the ip and ethtool commands as it happens for any CAN device driver. The changes are backward compatible, you can continue to use the slcand and slcan_attach command options. Changes in v4: - Move the patch in front of the patch "[v3,04/13] can: slcan: use CAN network device driver API". - Add the CAN_BITRATE_UNSET (0) and CAN_BITRATE_UNKNOWN (-1U) macros. - Simplify the bitrate check to dump it. - Update the commit description. - Update the commit description. - Use the CAN_BITRATE_UNKNOWN macro. - Use kfree_skb() instead of can_put_echo_skb() in the slc_xmit(). - Remove the `if (slcan_devs)' check in the slc_dealloc(). - Replace `sl->tty == NULL' with `!sl->tty'. - Use CAN_BITRATE_UNSET (0) and CAN_BITRATE_UNKNOWN (-1U) macros. - Don't reset the bitrate in ndo_stop() if it has been configured. - Squashed to the patch [v3,09/13] can: slcan: send the close command to the adapter. - Use the CAN_BITRATE_UNKNOWN macro. - Add description of slc_bump_err() function. - Remove check for the 'e' character at the beggining of the function. It was already checked by the caller function. - Protect decoding against the case the len value is longer than the received data. - Some small changes to make the decoding more readable. - Increment all the error counters at the end of the function. - Add description of slc_bump_state() function. - Remove check for the 's' character at the beggining of the function. It was already checked by the caller function. - Protect decoding against the case the frame len is longer than the received data (add SLC_STATE_FRAME_LEN macro). - Set cf to NULL in case of alloc_can_err_skb() failure. - Some small changes to make the decoding more readable. - Use the character 'b' instead of 'f' for bus-off state. Changes in v3: - Increment the error counter in case of decoding failure. - Replace (-1) with (-1U) in the commit description. - Update the commit description. - Remove the slc_do_set_bittiming(). - Set the bitrate in the ndo_open(). - Replace -1UL with -1U in setting a fake value for the bitrate. - 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: - Put the data into the allocated skb directly instead of first filling the "cf" on the stack and then doing a memcpy(). - Move CAN_SLCAN Kconfig option inside CAN_DEV scope. - Improve the commit message. - Use the CAN framework support for setting fixed bit rates. - Improve the commit message. - Protect decoding against the case the len value is longer than the received data. - Continue error handling even if no skb can be allocated. - Continue error handling even if no skb can be allocated. Dario Binacchi (12): can: slcan: use the BIT() helper can: slcan: use netdev helpers to print out messages can: slcan: use the alloc_can_skb() helper can: netlink: dump bitrate 0 if can_priv::bittiming.bitrate is -1U can: slcan: use CAN network device driver API can: slcan: allow to send commands to the adapter can: slcan: set bitrate by CAN device driver API can: slcan: send the open/close commands to the adapter can: slcan: move driver into separate sub directory can: slcan: add ethtool support to reset adapter errors can: slcan: extend the protocol with error info can: slcan: extend the protocol with CAN state info drivers/net/can/Kconfig | 40 +- drivers/net/can/Makefile | 2 +- drivers/net/can/dev/netlink.c | 3 +- drivers/net/can/slcan/Makefile | 7 + .../net/can/{slcan.c => slcan/slcan-core.c} | 527 ++++++++++++++---- drivers/net/can/slcan/slcan-ethtool.c | 65 +++ drivers/net/can/slcan/slcan.h | 18 + include/linux/can/bittiming.h | 2 + 8 files changed, 549 insertions(+), 115 deletions(-) create mode 100644 drivers/net/can/slcan/Makefile rename drivers/net/can/{slcan.c => slcan/slcan-core.c} (64%) create mode 100644 drivers/net/can/slcan/slcan-ethtool.c create mode 100644 drivers/net/can/slcan/slcan.h