From patchwork Sun Jun 12 21:39:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2047 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 6FA8F3F1DD for ; Sun, 12 Jun 2022 23:39:39 +0200 (CEST) Received: by mail-ed1-f70.google.com with SMTP id g8-20020a056402090800b00433940d207esf2980877edz.1 for ; Sun, 12 Jun 2022 14:39:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1655069979; cv=pass; d=google.com; s=arc-20160816; b=FxSjDKDHEJpnKITzvJiNtwzATuHuYrlp/oEDj9KRcx0vYn0WeSl4hKhCDOcSaM5R51 GBnHFVXUzt9gKZuLPWHegRfntlefvZzJ9FQLr+1MIsTpbWG4A96HWcCObvp+VBpj7Lct 2FxKR9mRTKOMF1U87QRFFXFU3DFGf66ouf0rBH3Cdrhncq3beBoy0OJhvqOOFUhYLck5 3F4/zOIsZI/TkRlH4aU++DpZIhc8ju8+wk715NFhZUXOL1AG+a87iK4uujlUsyDrUV52 E8H2woQShbs8SKjDx0PU4wbgS1G+pAf6JZt0xY0FFQdi+SHSftNNd01hePDSpU4jVZJu pAcQ== 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=UB+V+8zlpjSZ0ppBszuh0XVcoIVeUcbmukku0cAijkU=; b=a1n/CVNXil081cpOMrs2Jd30LhOpVCtV/Y0B+5SKRl/XmC2XwF7nWWjBMUtYrj4LUs M1viBNtrGnEYTd0+73aeW4h5nbZ1wF/B2jNj5UvwdIVm7SXumYwBnWAFQ1ohWILHBIjE NMeqimznyv2nQ3RehB2smrsD/TV0aP3w+Lk0qPUeGWkYnWenv/s/fkggV6Py6zI9eUw4 FB9oG+7iOZvCIHBs6t473VRgBk8RyHLv0vSIh7Z1zrLHw4F/dWIvEhMCtQCt88nN4+KY C+FYEWQtRBuZ78I+eQbgyu3VxdeNZmAHsWEBa/A5m+HHGzHx+CUqoCW0mLbNNUaf2RsU NKXQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=H0jOHpTE; 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=UB+V+8zlpjSZ0ppBszuh0XVcoIVeUcbmukku0cAijkU=; b=OvnNFSp3OP5tnqLptyS+z7XhzpEPhpHPybP0UlkqN+15z9ATO66M+MTd3ON5QPccXf i0+wDjj4C7fK33S6pG4uIrAVk/XVcQvFehh2mp00SDwHOlqDuHnE1tJgb8/dwk3UJGBu Yj99Zv+00FakkKx3xlV9ThfYImQdW2Eyf/kfk= 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=UB+V+8zlpjSZ0ppBszuh0XVcoIVeUcbmukku0cAijkU=; b=tNFC2upWJhZWEkzYb7oxzMz3ZfnLM7H9+pt5RCLTki0PcuYUgvZ87mVXsWT6ebEZPA Req0YlBQwkbPHl7yJrlsY6yxzRyuJwK2w8VAk7rV5RAxtMRHH3IwAbiZH8QzvtMmLY4m lR0aSOn+xf5Nhst07kZj+AtP8DAVCwRsLcmGW9AIteYJiISjllCDybn/Rfh9B70MIu8O 2JomDlzGBfiMg8uBWrrMbrgx6ynpdpxkD1uQiSeIFcjscsC76ypaHTLSdIAm+zOZX8ar VaW4xeMvSxUgANM/yUa+GgcVh6PyB3VD1Lui5oiw0N7oE/aL/PtmZaqD80WLAlnEg2md VDUQ== X-Gm-Message-State: AOAM531/S4y9kDDcHtN4dtABsWNB/ZIUjcrB3py74diGC1KWf4BnkUNv qzuQ8ldQY2UT+lpfHwA68M4t5TwT X-Google-Smtp-Source: ABdhPJy2mrnWuwm8F2S20WUNw7HpwV6FJuhc32p+Pvon6Hc1qu9wJHz21Mgy0aqTkIIDrAVG4F9Izg== X-Received: by 2002:a17:907:7f0e:b0:711:dbfb:868a with SMTP id qf14-20020a1709077f0e00b00711dbfb868amr29654760ejc.532.1655069979095; Sun, 12 Jun 2022 14:39:39 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:907:16a7:b0:718:c04a:5161 with SMTP id hc39-20020a17090716a700b00718c04a5161ls286059ejc.11.gmail; Sun, 12 Jun 2022 14:39:38 -0700 (PDT) X-Received: by 2002:a17:906:4f87:b0:718:c7ce:bd64 with SMTP id o7-20020a1709064f8700b00718c7cebd64mr531796eju.507.1655069977922; Sun, 12 Jun 2022 14:39:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655069977; cv=none; d=google.com; s=arc-20160816; b=P+7/Qg14oV1CYC6u/bsawgGQh3pps0Dsz4NfDml+TSmo+4tEveTFcKhlvcFXEmcxDI I1BEwi49SNIwnFWG9y3qvzy2Dcdx7jQMUyIs3l0wO8lq/73PRt7UcCW9IGfCrgunmFLf UBLijA9TnX/jdQPxu3S8xxkrdRwhe7snAGlep5Nh9NNWBzmMrroh6wntWoidhtOjdXb5 vUAj+TKKVZH+KQdo365A2yTJBmhNc8MQHqwLayvnKYIKUo9nKSmQaTrHyDUr9c2YqQvW RIzNs/i+juoTUblbiJ4QxylU20+8p00CHLWAU93505sk9ZBsGXvJ/2kHpxabRP3m/PtM 7kwA== 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=ZyOL/5w2xsSU/Fg6Gmxyopr+VoCvVAaounzNIX8NZuw=; b=lMQyPtURuXCiLyUdOo/Jh3nGVm0eD6h9Yltqmc3etP8aTNvhnt6Aa1UHoeFYMqpHyl d1oYtwkskZHBl9pj90ut2t8WYsPlYVZImjfTVnDFMwbYR7zed40vuGdYjQg1KTVOJsPJ nuLSfvUoAtYW79PcKhn3+L4rKNjCtNyzKPJk2oG5aCVVQXRo1U7KhZccAQ5tUwh8HM+F 6v1VVe4s7Fo+CXT+/N/LRLB0xGGM5ShLr2/bFvIziObrMqT7Zr6/dNRGR4wAgseLUEXS MTh8LVI3Qi34XiljzY8M2uJ+OKnkjtWY/XAAbvzgf3Exjmy+Fg3pXjVWzx06HnrNoB7K r/nA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=H0jOHpTE; 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 fy22-20020a170906b7d600b007033fef81a4sor1312671ejb.56.2022.06.12.14.39.37 for (Google Transport Security); Sun, 12 Jun 2022 14:39:37 -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:6d24:b0:70c:81d9:d5b9 with SMTP id sa36-20020a1709076d2400b0070c81d9d5b9mr45569744ejc.597.1655069977577; Sun, 12 Jun 2022 14:39:37 -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.39.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jun 2022 14:39:37 -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 00/13] can: slcan: extend supported features Date: Sun, 12 Jun 2022 23:39:14 +0200 Message-Id: <20220612213927.3004444-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=H0jOHpTE; 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 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. - 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 (13): can: slcan: use the BIT() helper can: slcan: use netdev helpers to print out messages can: slcan: use the alloc_can_skb() helper can: slcan: use CAN network device driver API can: netlink: dump bitrate 0 if can_priv::bittiming.bitrate is -1U can: slcan: allow to send commands to the adapter can: slcan: set bitrate by CAN device driver API can: slcan: send the open command to the adapter can: slcan: send the close command 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 | 12 +- drivers/net/can/slcan/Makefile | 7 + .../net/can/{slcan.c => slcan/slcan-core.c} | 518 ++++++++++++++---- drivers/net/can/slcan/slcan-ethtool.c | 65 +++ drivers/net/can/slcan/slcan.h | 18 + 7 files changed, 541 insertions(+), 121 deletions(-) create mode 100644 drivers/net/can/slcan/Makefile rename drivers/net/can/{slcan.c => slcan/slcan-core.c} (65%) create mode 100644 drivers/net/can/slcan/slcan-ethtool.c create mode 100644 drivers/net/can/slcan/slcan.h