From patchwork Sun Jun 12 21:39:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2048 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 E3BDD3F1DD for ; Sun, 12 Jun 2022 23:39:43 +0200 (CEST) Received: by mail-ed1-f72.google.com with SMTP id j4-20020aa7ca44000000b0042dd12a7bc5sf2920016edt.13 for ; Sun, 12 Jun 2022 14:39:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1655069983; cv=pass; d=google.com; s=arc-20160816; b=i8lgnQypvc7Zit0RcJBSyNJfmLXT/0qE314zzmE4DWOAZaBeiTwYi0fJQJPvFgCudE B0Ay4HfS+A3/bBXZslTFJTIAdyJlse24bX6MY+EiymWBvD/CHXBNHB2ANpQt8pD/EmYB gvEU9DeNWSIOB1rOZ34U2OBkhKD1e3sIXUV+Bywnr/SKapK2H1D1P9CQ+6JKXMbP3FEP vYV9iEjt8UQdg1oGo7dTYtxhtG7MuYfy2Fzi9doPsjJlAthixQaJ3iuOimm7ve+JQt5q /NMZCCRVWEwwDZ7aW1mxwgL7w9jLerCcdK3fNkBgbbGFlvA+AKoOFAdMs83GVY1A7Ofx bdCg== 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=yctEy2Nq3M85nscL7bqITb5xeA3Kbd7u0kNVkdTNk3g=; b=Xk1iESCjq7+VlaabFr20V5KOH5i4wPD4H8Nc4BX16KbSbk63cmyMBOJj9IYeQhFxw7 NHEIoAlymTD5W9fhBPt398+9Dob8XaJflPrYKLXHiHO81iFSWimXhYFdgda8bGOtj0Wl NYUvVYK/6t5/DcRsAF6J6X0XoVNNc4gU1LqqV+mb6jAIsubSSLRHmphUeo+0JpmCF6vK Gpmx/jfdF3xiGwMdZFbMnZX9saaPLWGcR/R48lA/WfETmu6WanPXUCLFls5aCYVic4su ZQvbrXFpHljD62EAs7kCYgPv/aPJ4sodCDg4UXjJrI6moWWOS/d9bt2Xl/BG+AVGK2Km 3KRw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=OUYQfEQr; 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=yctEy2Nq3M85nscL7bqITb5xeA3Kbd7u0kNVkdTNk3g=; b=UjM6sjxcVsI3Ka4YLa85XOY7E5zWeg2fTdpwrLKrQwXmM6FHmJazejboMefBB1DK9q xxyaB18mIxihUVu6JycVqv8jPp3UGhfY3Ww9dY9+FdRNzevXwc3+oV8Ft3pT35e+XadR Y5OdIVhWCDbvPalQADd70OkrLBehrCnnNwis0= 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=yctEy2Nq3M85nscL7bqITb5xeA3Kbd7u0kNVkdTNk3g=; b=RAHOsbiOrQS9c31u7GGVwy4oJCKDWh+5HCz5bAauosYe3mn9TNGg9NeOqwQKgwKYzt lNYHLEgqKxaePe12Y7A2hllmKWIdrXKvfksJBel14+zjoHaMcG6WoptbUHos8A3tbIWA GSeJ25eQ4NcLvP2jgkZca6hwE7RWpb85Nar7Glim6K+6eL9w/WmykPyxA5d1mWu7B9ao AII5yvD3Ueli9gSsQf24JiUtbt5WKhLtRGq/uFXl+tYCp/j0meO1FtgEzfq0DXI8zrSj /fu7Q3NVSU84wFG7R7s/MmYPPhzAIGfSKIkLDIQ9iP8QnIwmpzOahTjDdtDJ2YcSA6el igdQ== X-Gm-Message-State: AOAM530Akt4h8nBrch1wf26JvT1oPLJTunSk/2GKeyrxrntITa8nB8Vd WALD+UpDOLc8xZxSH/mA2mr30kD7 X-Google-Smtp-Source: ABdhPJyiSrCQtvq1rzFfRO06ZkAY2OqKZBFptMVeXPoSAu1t1q6kS++3kIDuPSqWpm5pDnGTvJB0Wg== X-Received: by 2002:a05:6402:42d4:b0:416:5cac:a9a0 with SMTP id i20-20020a05640242d400b004165caca9a0mr61594542edc.86.1655069983620; Sun, 12 Jun 2022 14:39:43 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:2741:b0:41f:7eee:e393 with SMTP id z1-20020a056402274100b0041f7eeee393ls1835879edd.3.gmail; Sun, 12 Jun 2022 14:39:42 -0700 (PDT) X-Received: by 2002:aa7:d14c:0:b0:42d:bbab:43d6 with SMTP id r12-20020aa7d14c000000b0042dbbab43d6mr62956091edo.15.1655069982576; Sun, 12 Jun 2022 14:39:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655069982; cv=none; d=google.com; s=arc-20160816; b=bB4bA4sWeFOqMOR44Q76MmFApD9Va1SW4kPny6SOQWdgIOtE+QGbAmNVCe8PjtAR28 AK4smRfOlptlQ/8tTtJLXr7/u6XmpBuyb6idBzkIAF0PPtC+xsNEQDTkTfuPGsL7zClD VGbeCuxtvv/yZJOoq6Pj6RCg4To7ViczBQfIvmds5nh6lQP4JRGHg5Qt+U7u6xQPtYNv 1TmM0tNNF/OgvuGxmlbd0SrUKcOTP3wpJ1v13rOulsbmo+5ynnSUm0T2lz9OoumL8CpJ SYSaaRdoR70FUfwV9L/5DLQHxI3utuEALE9HonqWEgojVxIk7p/h+c0MYfJV22VJ/A8E /vTQ== 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=bs1pDxoqSwxHo6PhPuLte63s3qeUlbVxYb0CgUg+DU4=; b=i8tA0rvlZzyDkz17jilhGBV4z2rnosffQZAzRmYBlXpNV9vFeIp+NdwO/Tnu3gTX12 7STU1/G0/1QpwzLar/FxcOPeHxLAc6fNBlQ7MQ7XLc9syIumu5DzuI4u4UhdYO5gUh8n BYuHCTv6Keq03qNQGsToaE0SfovX55Zoko7RKJ8BPbImkAwxjtY9EJhKqs/T5CWmHT83 dKNZDwhZtIvuc6/tdJZT+dNOiMHGlDXeGNpeUMcbMya7p8PjAXvH+otJXkDhvHhn1IJr dkhQSFdbQcgcaq1ARGXzFLh/92RLhLMTfRbVNSWe8ziWxcN6WSkJ6fEO9VNJOctQyMsE LqNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=OUYQfEQr; 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 jz8-20020a17090775e800b006d531251449sor1331867ejc.66.2022.06.12.14.39.42 for (Google Transport Security); Sun, 12 Jun 2022 14:39: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:1b1e:b0:6d7:31b0:e821 with SMTP id mp30-20020a1709071b1e00b006d731b0e821mr49755379ejc.334.1655069982282; Sun, 12 Jun 2022 14:39: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 u10-20020a1709061daa00b00711d546f8a8sm2909398ejh.139.2022.06.12.14.39.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jun 2022 14:39:41 -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 , Jakub Kicinski , Marc Kleine-Budde , Paolo Abeni , Wolfgang Grandegger , linux-can@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v3 01/13] can: slcan: use the BIT() helper Date: Sun, 12 Jun 2022 23:39:15 +0200 Message-Id: <20220612213927.3004444-2-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=OUYQfEQr; 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: , Use the BIT() helper instead of an explicit shift. Signed-off-by: Dario Binacchi --- (no changes since v1) drivers/net/can/slcan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/can/slcan.c b/drivers/net/can/slcan.c index 64a3aee8a7da..b37d35c2a23a 100644 --- a/drivers/net/can/slcan.c +++ b/drivers/net/can/slcan.c @@ -413,7 +413,7 @@ static int slc_open(struct net_device *dev) if (sl->tty == NULL) return -ENODEV; - sl->flags &= (1 << SLF_INUSE); + sl->flags &= BIT(SLF_INUSE); netif_start_queue(dev); return 0; } From patchwork Sun Jun 12 21:39: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: 2049 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 6E2C53F1DD for ; Sun, 12 Jun 2022 23:39:47 +0200 (CEST) Received: by mail-ed1-f70.google.com with SMTP id o2-20020a056402438200b00434ec3efc03sf920736edc.9 for ; Sun, 12 Jun 2022 14:39:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1655069987; cv=pass; d=google.com; s=arc-20160816; b=makY5qnQH3jG3atrSVp6hS5r+TPfpVsgN9lZUg9IhPWE3yCyZAXy8/bpp5YNpwnVt0 6NQ0l28yvoVtzBAUH1hX76n4nhJwHFEWjoauIn64XqrP2grwbltfzEW7J//JY0mKas5a GQ74i0i/B7xbD2RTBaAxWqNB5w/siKv3SJ0+o4IwJ2x+cfSI4YWthhUQKgtMyJFdcpYV AXSmbhHbEjCBZjItUQ5maugIkdlKYCTlrL1WGXHEmptrzI6hI8+8lWWMQEv0hUnJ6KMA giLtqgpd6uH0ooC37WW/1wfBKopIqIzKyk24d/pT5GNQWlmYwdCbB8Ir2mR3FVIgmTzC kEiQ== 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=SrWu90v7RwVVGIyj3J1NJ4lNaOE9C3PTcBPEpqAGb3Y=; b=lFtcINy08wnAmo5n1zyxYw1mJrOf9fXAVGI6vmWBZH/N0VfIRsJ58YQXfdzUp40NyR KfvZZz/hx1ZrfhNMW11P7/hv+5YXIanYDgQDYYvdBGfHCKzaJIc6+xHuuFnv7CyFFoHz TR9DVgWGaTVMKQidNdwQzPbgU4H7aOJV6j2RLo22PD9WDxDWFfs1Or/VYtJCknomc/hG r+Lf1RkF4j6DPrX+d6gfa8agQq/PtY0vgSM1aW92BZFle7W3aruzCSgvX+Uv80iFIlOT 49Tah6XNhpyPEN7LxpxGC4xVGEe1DW/G+4WqzHZMq1xD1twZ09N42xSWleDXCOp+wOG2 wvdA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=FIZh5UTr; 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=SrWu90v7RwVVGIyj3J1NJ4lNaOE9C3PTcBPEpqAGb3Y=; b=H7boND/ciLNfpIzWXXEy1SJ5dwzseUuDhCQN2Oye1RAFYgh9mZHzLPFXSBbrctjGf7 gwR8Ih04HWgCgvwa0DkovjCXXSIBBFvaV+27Ihy4+pXKEApSC5RA2QCeeyTPswAG/50c PzwXC7XPkbaCDYqTOo5USiNv2yyUrt/V4pmIg= 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=SrWu90v7RwVVGIyj3J1NJ4lNaOE9C3PTcBPEpqAGb3Y=; b=40va4tRlT/rsxQufh8CRwlW9XmYwZ2kkFlKo6MtZRcQrkTcJdZ/fDhq6BlLCtZFOoa MbeGB3KjXJeObjlqvVp9F902radT72g+XB2l/ABkn1IqwuwSmjGE6Fe/lDdr7LcDTCkm V/q9noRcBN94unBjtjoDAIqddN1cTsN4vOrGzEpV8mlnvUCN/SFF0xmNPP2iHOO1JDJW yeGGmUUIq4RNuZ2GqG7Grg1Ulq4ES2RdKfp069I+2E6LmjPQtVuMC7OPW8rVDdhddawH izbmsZbwXhSPoD5Vj+fhmCcq3j9rUZ1KJppK6WrHGgqk71MLAoqG8lnj6fx7NjNaq0ep scog== X-Gm-Message-State: AOAM533uoNetJS5hMhNVhHZW8Ip1bzAoSJIFpyvcZTvZcBS1CFSErDET iC5B+nUPsaEBE5rztvvEmuqPl75s X-Google-Smtp-Source: ABdhPJwX+CU/6ayGyLW/y5LFzYQ3RNiCiRMKcdmGqjUNh8ZFn03dOxLwwOthzBM18ix4f7BhTvQMkg== X-Received: by 2002:a17:907:8c1a:b0:715:73d2:df36 with SMTP id ta26-20020a1709078c1a00b0071573d2df36mr2957596ejc.256.1655069987246; Sun, 12 Jun 2022 14:39:47 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:906:6a26:b0:70a:1088:57d1 with SMTP id qw38-20020a1709066a2600b0070a108857d1ls1009638ejc.3.gmail; Sun, 12 Jun 2022 14:39:46 -0700 (PDT) X-Received: by 2002:a17:906:891:b0:70b:c30e:c1f1 with SMTP id n17-20020a170906089100b0070bc30ec1f1mr46761819eje.733.1655069986187; Sun, 12 Jun 2022 14:39:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655069986; cv=none; d=google.com; s=arc-20160816; b=d1BjNgCtIOgXTveMsQoKcQJK4t/GuPPyZl18g0cJz030r43SBGqYFCyufgkvCRL3A7 qqWV2WdTnhLKa6FUo7rRcbTkFAK+KApiASZpFp7aZNc4U2GsifAv0HrO4x2em/ijqRwM U97+Q/fUJui0jOqnvkDI2ju/7gBwugGb9bYn6aBJAh+UhhleGLC8Qhj+Yg3fM1Apu2ex K4lh3jIQ+txJDbqdxK2ji22Kl3iqcTu26h2XpNiqxVIl1kg8SJXvUSojW0yoTDGYmzeC ga6itWlc2xslGCX5BPk5GR9L+toTItS1DyMKuff0K7fm6gE+vZYILgaBp0+SfPPH4xFr V36A== 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=El3W9x0OB1VE70B0Lt3SBVyO+pC/HDeoL5aPqYtLRdg=; b=NJl5AqJjvNvObiOMiGbbVhhZm4kJ2ggLzZdgZ82RI7BeVPws30YJkdLa7AHV74qkEu Z2RpYiVXWSI/p5irF9TueMqsRm87BYsg9wFhatSpy4/s6UTKH0w/U6GbI+mlYcX7yTg7 oWFnaIv8EaLNANfEkZeth7l4Gdcw3DkxkO3nYLeTAmyjR19JZpVOeNe8Cqv82/ZOxYIN Z4dXCLCaNIrTptsGEc4wX6voRh2d2UdrpY00Mv1hsmHR/wKty0P2sz+1MfXhKVD6HtFH qocePWY9DDiULKsXdkYywvpxGLvycJ0eIQGpQ5sNMc7BAuI5Ug6bFIIJkFvgI+s+3Ynq A+0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=FIZh5UTr; 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 ee4-20020a056402290400b0042dcafc4527sor1584698edb.50.2022.06.12.14.39.46 for (Google Transport Security); Sun, 12 Jun 2022 14:39:46 -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:aa7:c306:0:b0:42d:d4cc:c606 with SMTP id l6-20020aa7c306000000b0042dd4ccc606mr62413182edq.341.1655069986039; Sun, 12 Jun 2022 14:39:46 -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.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jun 2022 14:39:45 -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 , Jakub Kicinski , Marc Kleine-Budde , Paolo Abeni , Wolfgang Grandegger , linux-can@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v3 02/13] can: slcan: use netdev helpers to print out messages Date: Sun, 12 Jun 2022 23:39:16 +0200 Message-Id: <20220612213927.3004444-3-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=FIZh5UTr; 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: , Replace printk() calls with corresponding netdev helpers. Signed-off-by: Dario Binacchi --- (no changes since v1) drivers/net/can/slcan.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/net/can/slcan.c b/drivers/net/can/slcan.c index b37d35c2a23a..6162a9c21672 100644 --- a/drivers/net/can/slcan.c +++ b/drivers/net/can/slcan.c @@ -365,7 +365,7 @@ static netdev_tx_t slc_xmit(struct sk_buff *skb, struct net_device *dev) spin_lock(&sl->lock); if (!netif_running(dev)) { spin_unlock(&sl->lock); - printk(KERN_WARNING "%s: xmit: iface is down\n", dev->name); + netdev_warn(dev, "xmit: iface is down\n"); goto out; } if (sl->tty == NULL) { @@ -776,8 +776,7 @@ static void __exit slcan_exit(void) sl = netdev_priv(dev); if (sl->tty) { - printk(KERN_ERR "%s: tty discipline still running\n", - dev->name); + netdev_err(dev, "tty discipline still running\n"); } unregister_netdev(dev); From patchwork Sun Jun 12 21:39:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2050 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 1FE433F1DD for ; Sun, 12 Jun 2022 23:39:51 +0200 (CEST) Received: by mail-ed1-f69.google.com with SMTP id y13-20020a056402358d00b0042dfb820070sf2958430edc.6 for ; Sun, 12 Jun 2022 14:39:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1655069991; cv=pass; d=google.com; s=arc-20160816; b=g4HCikg8bK3uYxG690qWoTt8FScIpOv3aqaKVmO7Y8r4zErbCnNGaWnZ5OO5RppYmN bEmdL+0YFzGf8i/7pKy7Qztj+EmSfP2tkQ4LsfeEcmeX2c90me5mgeE4EGWX4irnteGB iJcbKueYkeCPkDt7QPircszvFGzC5DRZK5R+b9eZE8Iup0nn2NIhagsQ/HYghLfR9nL5 QlZDmdsvmYdnKdRCIDoyj/6JIOh6nBugvvkL12ihq6mcFO/iw21zOeWb0l0e3HjupSSi ocYsri97EJQSZaFlomq7+kwNR1iWEsAtvklAR0JUE5KV62kyCdaH3SYqd5wW5ijnDB42 wXvg== 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=Q4JaH70kvnHa+iEhSPHtUN64xuZCzRoDcU6PXVQeckQ=; b=yE/w/hXfT8z0Ksrc3savKD4CYVhsp2kiYFZ+S/QVDDhwZXgRrSqEOvHYPgE2gC1LXU e1UnSAG8uKE6fqUHdRwQhgexgcKmDCtEYL6PHoYaQ8SLQs1ynZRs9UdCJNUGje5r4ZB+ Z5n3qk9GJdXZhKrkGbPya/i9KTlRmVeBiVWGYOLt3u7HVKrS93WXXbmWk6ATRHeoRTlx fX+MHscjWeGQpVf93g0zVmAl/qpOumjKXZI+RSNHlvbYKhVLBvNNReNjCd61vbjgtMjj Ekdon3eZJee/kcdPBN6rYMc/tvfTO/gLxm9yXX3DEXD9+VEw94+DTX0VI0Mv3Gm4I9IK efqw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=I9pBc0a6; 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=Q4JaH70kvnHa+iEhSPHtUN64xuZCzRoDcU6PXVQeckQ=; b=OznYUaMEDq8ax9aEGc2RyAFxyKbb367E1IY8pn+soeZEmlVLBg1hmQYCTCkdRH8N6h 6u+LW27RI/J7gw+eLDdK0J8FFF7/qU+WUCEFcJN4tHefcWk6XbUhK2YjD2M6pP3pOj0I vdZD+nY2bGjV13zJ5g6l2Zc27x7iqpCsgRufw= 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=Q4JaH70kvnHa+iEhSPHtUN64xuZCzRoDcU6PXVQeckQ=; b=W4TaPrdhoyO/fR1ypRmed4niIcwwb8+6D9XYgq3hBReJwWKAuZdrQ8G2iG+a8KXwKA zO5Txm2WVA541azhtbGgko/Z546PcFRKzLz36RCdlrq3fSHMFsp8wYGlNn1kdtCCHink PkiNF+kkx9dMBzXa1Hg96EAvW0zyvBirzbcKS5NPSHBOOxxhqU15Ak//5dMsL7MTFufM lEJSNIasQcIklYvhHtSkN5GIS4MtlIoKZoVJRDyPQ2cqTcwi0oyndWW4VpLU2XyebfNB LvaM1V0vFAhBLhAgRs3ok3xKMI22SnviTu/t/it6jZ1V22vwXs+LYH3neF29OupWQoD0 hySg== X-Gm-Message-State: AOAM533HtGHI2RERYsNN679SnFOVF0HvlEP/C2yJ932DXOq76jGuzi27 Xcf1Lld0rs2NkXiqsssb/Riav0I9 X-Google-Smtp-Source: ABdhPJwqaUotkBxlMXWyiZngtmM+3qvRfuw6AUYo2Oc+nTceym4pPnu/bay9RxztSPo0Lrl+B0O8iQ== X-Received: by 2002:a17:906:6d91:b0:715:7d4e:84a2 with SMTP id h17-20020a1709066d9100b007157d4e84a2mr4643460ejt.504.1655069990973; Sun, 12 Jun 2022 14:39:50 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:907:97c4:b0:711:d2c2:9fa4 with SMTP id js4-20020a17090797c400b00711d2c29fa4ls1010946ejc.9.gmail; Sun, 12 Jun 2022 14:39:50 -0700 (PDT) X-Received: by 2002:a17:906:6086:b0:716:a658:d8b4 with SMTP id t6-20020a170906608600b00716a658d8b4mr3221566ejj.672.1655069989853; Sun, 12 Jun 2022 14:39:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655069989; cv=none; d=google.com; s=arc-20160816; b=aushjBRWDo26WkdpHhtlZDYq07VuObb9TteXMpNK62bEB09U/uV0ZNpEJ8IxWLnJhb DZ96a/p8AuKg1h96m4cObqZn041dBE+r4HMCAXUpNWX23g0eWUoF5JlL0GaNsbEzQV3G s/cZUOmwcOPcF4a+pj50SR5SnwcKvzQMO7f+HIDx84yDcLUgwsNxQW2eBbn2HwQJCZMN juxYIYNsyaRji+/7hvTHLbXBSzeKxIpEqB5vvpo6IQ6OuLozpxdHPImhcln5yAWEQpHz QupbnSpcp0LsI+9BwhRTyfZ0s7R84UJB3/NB1TNeARf/q84IO1fXqHTDqBsZnOnQhCZx et8w== 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=K0omjWVAQknKh80VLWsQETRXyxuJ8wx+RydBE1BQOZE=; b=pi5DHiCClUqQ1v/D9tXLuXqNJ7sVjvyfvS+DrR11jO3ol4w1uUGAZb6ybCMXPo2sKr I6uUe4ScQN/seWu0wYQjXZZvtc5Dby/iCPRjS1B5g21EW+z3atCN64Kq6Eed80OSJzHS 2vPmhYLVDsW7IEEntKlckKsuYZ+jp/WI6uHFRZTIFZ5nEWezaZd67yMZ5G+p0thRhNfU 7lf/+G+3kKzTBykxZGq8qiTBr/3auk8WlUaEa7d+33B3U//cIEsIT82ZP0kuMlH09ajr yscYg9BfjnapDaXF2ZKFt838JrP21+Hvf3jrqOlzuFu7NKWjRxc1UjTFXNx+fOn08e53 Scpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=I9pBc0a6; 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 kk25-20020a170907767900b00708ae482facsor1269498ejc.77.2022.06.12.14.39.49 for (Google Transport Security); Sun, 12 Jun 2022 14:39:49 -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:1b07:b0:6fe:2cbc:15c5 with SMTP id mp7-20020a1709071b0700b006fe2cbc15c5mr49898642ejc.677.1655069989671; Sun, 12 Jun 2022 14:39:49 -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.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jun 2022 14:39:49 -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 , Jakub Kicinski , Marc Kleine-Budde , Paolo Abeni , Wolfgang Grandegger , linux-can@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v3 03/13] can: slcan: use the alloc_can_skb() helper Date: Sun, 12 Jun 2022 23:39:17 +0200 Message-Id: <20220612213927.3004444-4-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=I9pBc0a6; 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 is used successfully by most (if not all) CAN device drivers. It allows to remove replicated code. Signed-off-by: Dario Binacchi --- Changes in v3: - Increment the error counter in case of decoding failure. 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(). drivers/net/can/slcan.c | 70 +++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 37 deletions(-) diff --git a/drivers/net/can/slcan.c b/drivers/net/can/slcan.c index 6162a9c21672..c39580b142e0 100644 --- a/drivers/net/can/slcan.c +++ b/drivers/net/can/slcan.c @@ -54,6 +54,7 @@ #include #include #include +#include #include #include @@ -143,85 +144,80 @@ static struct net_device **slcan_devs; static void slc_bump(struct slcan *sl) { struct sk_buff *skb; - struct can_frame cf; + struct can_frame *cf; int i, tmp; u32 tmpid; char *cmd = sl->rbuff; - memset(&cf, 0, sizeof(cf)); + skb = alloc_can_skb(sl->dev, &cf); + if (unlikely(!skb)) { + sl->dev->stats.rx_dropped++; + return; + } switch (*cmd) { case 'r': - cf.can_id = CAN_RTR_FLAG; + cf->can_id = CAN_RTR_FLAG; fallthrough; case 't': /* store dlc ASCII value and terminate SFF CAN ID string */ - cf.len = sl->rbuff[SLC_CMD_LEN + SLC_SFF_ID_LEN]; + cf->len = sl->rbuff[SLC_CMD_LEN + SLC_SFF_ID_LEN]; sl->rbuff[SLC_CMD_LEN + SLC_SFF_ID_LEN] = 0; /* point to payload data behind the dlc */ cmd += SLC_CMD_LEN + SLC_SFF_ID_LEN + 1; break; case 'R': - cf.can_id = CAN_RTR_FLAG; + cf->can_id = CAN_RTR_FLAG; fallthrough; case 'T': - cf.can_id |= CAN_EFF_FLAG; + cf->can_id |= CAN_EFF_FLAG; /* store dlc ASCII value and terminate EFF CAN ID string */ - cf.len = sl->rbuff[SLC_CMD_LEN + SLC_EFF_ID_LEN]; + cf->len = sl->rbuff[SLC_CMD_LEN + SLC_EFF_ID_LEN]; sl->rbuff[SLC_CMD_LEN + SLC_EFF_ID_LEN] = 0; /* point to payload data behind the dlc */ cmd += SLC_CMD_LEN + SLC_EFF_ID_LEN + 1; break; default: - return; + goto decode_failed; } if (kstrtou32(sl->rbuff + SLC_CMD_LEN, 16, &tmpid)) - return; + goto decode_failed; - cf.can_id |= tmpid; + cf->can_id |= tmpid; /* get len from sanitized ASCII value */ - if (cf.len >= '0' && cf.len < '9') - cf.len -= '0'; + if (cf->len >= '0' && cf->len < '9') + cf->len -= '0'; else - return; + goto decode_failed; /* RTR frames may have a dlc > 0 but they never have any data bytes */ - if (!(cf.can_id & CAN_RTR_FLAG)) { - for (i = 0; i < cf.len; i++) { + if (!(cf->can_id & CAN_RTR_FLAG)) { + for (i = 0; i < cf->len; i++) { tmp = hex_to_bin(*cmd++); if (tmp < 0) - return; - cf.data[i] = (tmp << 4); + goto decode_failed; + + cf->data[i] = (tmp << 4); tmp = hex_to_bin(*cmd++); if (tmp < 0) - return; - cf.data[i] |= tmp; + goto decode_failed; + + cf->data[i] |= tmp; } } - skb = dev_alloc_skb(sizeof(struct can_frame) + - sizeof(struct can_skb_priv)); - if (!skb) - return; - - skb->dev = sl->dev; - skb->protocol = htons(ETH_P_CAN); - skb->pkt_type = PACKET_BROADCAST; - skb->ip_summed = CHECKSUM_UNNECESSARY; - - can_skb_reserve(skb); - can_skb_prv(skb)->ifindex = sl->dev->ifindex; - can_skb_prv(skb)->skbcnt = 0; - - skb_put_data(skb, &cf, sizeof(struct can_frame)); - sl->dev->stats.rx_packets++; - if (!(cf.can_id & CAN_RTR_FLAG)) - sl->dev->stats.rx_bytes += cf.len; + if (!(cf->can_id & CAN_RTR_FLAG)) + sl->dev->stats.rx_bytes += cf->len; netif_rx(skb); + return; + +decode_failed: + sl->dev->stats.rx_errors++; + dev_kfree_skb(skb); } /* parse tty input stream */ From patchwork Sun Jun 12 21:39:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2051 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id E4C4C3F1DD for ; Sun, 12 Jun 2022 23:39:55 +0200 (CEST) Received: by mail-ed1-f71.google.com with SMTP id ee46-20020a056402292e00b0042dd4d6054dsf2953683edb.2 for ; Sun, 12 Jun 2022 14:39:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1655069995; cv=pass; d=google.com; s=arc-20160816; b=tdKskC8MU7sp1JRI8SSApsas6c7frFYVz/YY4m+vfKHtSVZsDXy2wTG0mrLUTpM4LC 3c9GPXrLJXQBjwTuhluMLT6eu6+C5vSW3fdw7OVTKwgDpkfsuffyxGiOdivqthIrwhtL oS7udYUP1wGAFuXH7AdiA9jZNaIjJs+cxBdLzZl2PYk4QgGCBg24yjh+rp6BaZr/+vqc uP+qaALl9UnKNtWnAgqBu8H964opVNAUXR2kvMrt6rbOJJHa8W/rVPZO3rYzCo7r/vJS RpUYbTeeSHHaeKbmIH96nk1Cnm7ljWElWb4VP0nrVNfHO3EZ0wLLPTMZO78cc0AvfvS2 6DRg== 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=muhXYdOxpMXGdr4uLLtJlhx1I/8/lCx3mNszZhPV5ww=; b=piKS5v3adotcQlRTlhhgrd6AqS6STO57kn6hja79x+bC9Ke45ubWkyjlBvVALpf77a FCO2DNZj2cYAcpm6YsHTYyYs9MDclDAXNl98VkkbBWNumzxuNM5elVlJ+4t2MlXspF0m NJ85T6Hg7XnOQ8cHGxV3p38b0sM+RfAtegT8HrFUY7NhKRdHeMkZA/ODCJUdHzSq7fB9 /7hotFhlIdk89pNfD1KUtY3MdKRtQt4YWnEwuxR0NVfufAgyFIvc9YkHWdTauJ9cjKjd eKhkNfCu78SmCGeNBfeRbmIh2/joGnR4wecmUKhUjtblG0x2wBOF6MztGph9lsTQlqTl wPgw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=cq+XUFlb; 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=muhXYdOxpMXGdr4uLLtJlhx1I/8/lCx3mNszZhPV5ww=; b=Fan1X6OSLrey6LZnKD1bx7mv3bcCjuF5gfh9LGZwDJ0EtD7L9YpBm6XZi+Q1nVhLkB 9UEGE4EQTMisji+C5uxDX/KpmsWYdGOFvDK38GFZ4vLALvbu7jPu4qT2pTdM+oathvJh R063FZVYQ5zkJsnSmWXv+h9rQpozcGNTgqP88= 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=muhXYdOxpMXGdr4uLLtJlhx1I/8/lCx3mNszZhPV5ww=; b=M0f02VtzgWfd0gS1u4n/U2Xu1+BnuJPd+ZStOkk+GW1fmFp8TiEg0jRxuEBrZcMLDC Ce4U4MnQqUSOn/rZR1MskzppGpvJifBveASPtZyBWQmzHDa/G7NQ5RkszLinypYSSItD 3h9IVpGMof2o+NprSqQfnpiLPACwtgAFr5ZYFGW85c+d91GUMN7eyFgLFLrB2NUcljzk FYCCw4JOwfR8WARTyus7W7B5XSxTtSVJk+8+co1VzdgsugFdtMtT6Wf+IKTmqNci+r4Q Wt3oQN5LCcLN5PR6+8DpuZPwdeDHmfafDCjnvjAm8eYXE80z4TPrrcr7w0ygiQvbbNvE R1rg== X-Gm-Message-State: AOAM530aWgQ3JjbJd5dYljmAnkIYR5IKV8+40cOktjXpGYEJXkkBcHAu 6RGkl/Sj++pteRfpJ+Q+52dHbZsz X-Google-Smtp-Source: ABdhPJyQJn2AJuZAgjWPCAPD1RQrHPbdDJwQnzTEYGMazP8d8MCsYx5tLWZKXMjjCSxXhwRH2mDnkA== X-Received: by 2002:a17:906:7a47:b0:713:a267:5962 with SMTP id i7-20020a1709067a4700b00713a2675962mr8194981ejo.585.1655069995560; Sun, 12 Jun 2022 14:39:55 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:906:3fc5:b0:6fe:fc5b:a579 with SMTP id k5-20020a1709063fc500b006fefc5ba579ls1009737ejj.10.gmail; Sun, 12 Jun 2022 14:39:54 -0700 (PDT) X-Received: by 2002:a17:907:d19:b0:711:d10e:411 with SMTP id gn25-20020a1709070d1900b00711d10e0411mr33276247ejc.216.1655069994413; Sun, 12 Jun 2022 14:39:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655069994; cv=none; d=google.com; s=arc-20160816; b=GVdxjUU/w5cdCqjyhANdBVdFC9sBSTOpBmsZ+DhpsEwdx1QCcFBgXMDk2uXqH1sFMi iIhpkaBdcCfLklHZSfSMrMJV+YAZjZT59XTjKVXIlDIVIl82j1w6CPdixlEufGKo73Ka ZvFEJ2z2qwUlhTIFrCySFSoNzW2Ny1WL6Lx+mab3kKAHppm3c2TmF8ZiGxxTu6XC5Ie/ kyfQU4V2CIlKiMssQbfUEelcUIMGF1+wxykvmI40d+I1aWkhvfzCLJ9MKpQMPMdpFQWN anL+nWFUENPIVRhoUprKdg9UYJwO5WyvsiV5LKiQ0HZQDa3eA/ZfSoO4xkaOOr1suhjT tA4Q== 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=N02g9fJIqVK0hxkx5EqbV+5LJaIebbxeDuMD7HdwVFw=; b=AS6LDnGlv6U/fwXnwQeBIEzfuEmaXJMjxI67XHoZDqqIEW6dWeOCfOl7a9ZpaHBvnO 7Zih2UjDZLSPgKVacqk2zo0s9bhiT3iiAAui6gcC5eGRKcl0Vdbf4bTf7VRLj7FV+yEI F/4Xc6u0IgSdZDZp+0qwVruA2W3FsadhdbaUWQFtJGqDcvu4TS9b73RRcTrkc7wN9E/k dVvy0XEzjRbxl/uyedSGy5ytIDK8ixEUO2Ccvy9Mxd3EHJJeG2pUoClcKpGPPIL3Pqar RJx2ja90EKLgAxqqwEKG3eMubyGatPa9Ls6l849LMlDNJ4mJ9dJhvc4UZwuElAE9ldji +WLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=cq+XUFlb; 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 b13-20020a170906194d00b007157411e055sor926408eje.120.2022.06.12.14.39.54 for (Google Transport Security); Sun, 12 Jun 2022 14:39:54 -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:9493:b0:70c:4ddf:5d5d with SMTP id t19-20020a170906949300b0070c4ddf5d5dmr44705737ejx.73.1655069994042; Sun, 12 Jun 2022 14:39:54 -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.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jun 2022 14:39:53 -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 , Jakub Kicinski , Marc Kleine-Budde , Paolo Abeni , Wolfgang Grandegger , linux-can@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v3 04/13] can: slcan: use CAN network device driver API Date: Sun, 12 Jun 2022 23:39:18 +0200 Message-Id: <20220612213927.3004444-5-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=cq+XUFlb; 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: , As suggested by commit [1], now the driver uses the functions and the data structures provided by the CAN network device driver interface. Currently the driver doesn't implement a way to set bitrate for SLCAN based devices via ip tool, so you'll have to do this by slcand or slcan_attach invocation through the -sX parameter: - slcan_attach -f -s6 -o /dev/ttyACM0 - slcand -f -s8 -o /dev/ttyUSB0 where -s6 in will set adapter's bitrate to 500 Kbit/s and -s8 to 1Mbit/s. See the table below for further CAN bitrates: - s0 -> 10 Kbit/s - s1 -> 20 Kbit/s - s2 -> 50 Kbit/s - s3 -> 100 Kbit/s - s4 -> 125 Kbit/s - s5 -> 250 Kbit/s - s6 -> 500 Kbit/s - s7 -> 800 Kbit/s - s8 -> 1000 Kbit/s In doing so, the struct can_priv::bittiming.bitrate of the driver is not set and since the open_candev() checks that the bitrate has been set, it must be a non-zero value, the bitrate is set to a fake value (-1U) before it is called. [1] 39549eef3587f ("can: CAN Network device driver and Netlink interface") Signed-off-by: Dario Binacchi --- Changes in v3: - Replace (-1) with (-1U) in the commit description. Changes in v2: - Move CAN_SLCAN Kconfig option inside CAN_DEV scope. - Improve the commit message. drivers/net/can/Kconfig | 40 +++++++------- drivers/net/can/slcan.c | 112 ++++++++++++++++++++-------------------- 2 files changed, 77 insertions(+), 75 deletions(-) diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig index b2dcc1e5a388..45997d39621c 100644 --- a/drivers/net/can/Kconfig +++ b/drivers/net/can/Kconfig @@ -28,26 +28,6 @@ config CAN_VXCAN This driver can also be built as a module. If so, the module will be called vxcan. -config CAN_SLCAN - tristate "Serial / USB serial CAN Adaptors (slcan)" - depends on TTY - help - CAN driver for several 'low cost' CAN interfaces that are attached - via serial lines or via USB-to-serial adapters using the LAWICEL - ASCII protocol. The driver implements the tty linediscipline N_SLCAN. - - As only the sending and receiving of CAN frames is implemented, this - driver should work with the (serial/USB) CAN hardware from: - www.canusb.com / www.can232.com / www.mictronics.de / www.canhack.de - - Userspace tools to attach the SLCAN line discipline (slcan_attach, - slcand) can be found in the can-utils at the linux-can project, see - https://github.com/linux-can/can-utils for details. - - The slcan driver supports up to 10 CAN netdevices by default which - can be changed by the 'maxdev=xx' module option. This driver can - also be built as a module. If so, the module will be called slcan. - config CAN_DEV tristate "Platform CAN drivers with Netlink support" default y @@ -118,6 +98,26 @@ config CAN_KVASER_PCIEFD Kvaser Mini PCI Express HS v2 Kvaser Mini PCI Express 2xHS v2 +config CAN_SLCAN + tristate "Serial / USB serial CAN Adaptors (slcan)" + depends on TTY + help + CAN driver for several 'low cost' CAN interfaces that are attached + via serial lines or via USB-to-serial adapters using the LAWICEL + ASCII protocol. The driver implements the tty linediscipline N_SLCAN. + + As only the sending and receiving of CAN frames is implemented, this + driver should work with the (serial/USB) CAN hardware from: + www.canusb.com / www.can232.com / www.mictronics.de / www.canhack.de + + Userspace tools to attach the SLCAN line discipline (slcan_attach, + slcand) can be found in the can-utils at the linux-can project, see + https://github.com/linux-can/can-utils for details. + + The slcan driver supports up to 10 CAN netdevices by default which + can be changed by the 'maxdev=xx' module option. This driver can + also be built as a module. If so, the module will be called slcan. + config CAN_SUN4I tristate "Allwinner A10 CAN controller" depends on MACH_SUN4I || MACH_SUN7I || COMPILE_TEST diff --git a/drivers/net/can/slcan.c b/drivers/net/can/slcan.c index c39580b142e0..a70f930b7c3a 100644 --- a/drivers/net/can/slcan.c +++ b/drivers/net/can/slcan.c @@ -56,7 +56,6 @@ #include #include #include -#include MODULE_ALIAS_LDISC(N_SLCAN); MODULE_DESCRIPTION("serial line CAN interface"); @@ -79,6 +78,7 @@ MODULE_PARM_DESC(maxdev, "Maximum number of slcan interfaces"); #define SLC_EFF_ID_LEN 8 struct slcan { + struct can_priv can; int magic; /* Various fields. */ @@ -100,6 +100,7 @@ struct slcan { }; static struct net_device **slcan_devs; +static DEFINE_SPINLOCK(slcan_lock); /************************************************************************ * SLCAN ENCAPSULATION FORMAT * @@ -374,7 +375,7 @@ static netdev_tx_t slc_xmit(struct sk_buff *skb, struct net_device *dev) spin_unlock(&sl->lock); out: - kfree_skb(skb); + can_put_echo_skb(skb, dev, 0, 0); return NETDEV_TX_OK; } @@ -394,6 +395,8 @@ static int slc_close(struct net_device *dev) clear_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags); } netif_stop_queue(dev); + close_candev(dev); + sl->can.state = CAN_STATE_STOPPED; sl->rcount = 0; sl->xleft = 0; spin_unlock_bh(&sl->lock); @@ -405,21 +408,36 @@ static int slc_close(struct net_device *dev) static int slc_open(struct net_device *dev) { struct slcan *sl = netdev_priv(dev); + int err; if (sl->tty == NULL) return -ENODEV; + /* The baud rate is not set with the command + * `ip link set type can bitrate ' and therefore + * can.bittiming.bitrate is 0, causing open_candev() to fail. + * So let's set to a fake value. + */ + sl->can.bittiming.bitrate = -1; + err = open_candev(dev); + if (err) { + netdev_err(dev, "failed to open can device\n"); + return err; + } + + sl->can.state = CAN_STATE_ERROR_ACTIVE; sl->flags &= BIT(SLF_INUSE); netif_start_queue(dev); return 0; } -/* Hook the destructor so we can free slcan devs at the right point in time */ -static void slc_free_netdev(struct net_device *dev) +static void slc_dealloc(struct slcan *sl) { - int i = dev->base_addr; + int i = sl->dev->base_addr; - slcan_devs[i] = NULL; + free_candev(sl->dev); + if (slcan_devs) + slcan_devs[i] = NULL; } static int slcan_change_mtu(struct net_device *dev, int new_mtu) @@ -434,24 +452,6 @@ static const struct net_device_ops slc_netdev_ops = { .ndo_change_mtu = slcan_change_mtu, }; -static void slc_setup(struct net_device *dev) -{ - dev->netdev_ops = &slc_netdev_ops; - dev->needs_free_netdev = true; - dev->priv_destructor = slc_free_netdev; - - dev->hard_header_len = 0; - dev->addr_len = 0; - dev->tx_queue_len = 10; - - dev->mtu = CAN_MTU; - dev->type = ARPHRD_CAN; - - /* New-style flags. */ - dev->flags = IFF_NOARP; - dev->features = NETIF_F_HW_CSUM; -} - /****************************************** Routines looking at TTY side. ******************************************/ @@ -514,11 +514,8 @@ static void slc_sync(void) static struct slcan *slc_alloc(void) { int i; - char name[IFNAMSIZ]; struct net_device *dev = NULL; - struct can_ml_priv *can_ml; struct slcan *sl; - int size; for (i = 0; i < maxdev; i++) { dev = slcan_devs[i]; @@ -531,16 +528,14 @@ static struct slcan *slc_alloc(void) if (i >= maxdev) return NULL; - sprintf(name, "slcan%d", i); - size = ALIGN(sizeof(*sl), NETDEV_ALIGN) + sizeof(struct can_ml_priv); - dev = alloc_netdev(size, name, NET_NAME_UNKNOWN, slc_setup); + dev = alloc_candev(sizeof(*sl), 1); if (!dev) return NULL; + snprintf(dev->name, sizeof(dev->name), "slcan%d", i); + dev->netdev_ops = &slc_netdev_ops; dev->base_addr = i; sl = netdev_priv(dev); - can_ml = (void *)sl + ALIGN(sizeof(*sl), NETDEV_ALIGN); - can_set_ml_priv(dev, can_ml); /* Initialize channel control data */ sl->magic = SLCAN_MAGIC; @@ -573,11 +568,7 @@ static int slcan_open(struct tty_struct *tty) if (tty->ops->write == NULL) return -EOPNOTSUPP; - /* RTnetlink lock is misused here to serialize concurrent - opens of slcan channels. There are better ways, but it is - the simplest one. - */ - rtnl_lock(); + spin_lock(&slcan_lock); /* Collect hanged up channels. */ slc_sync(); @@ -605,13 +596,15 @@ static int slcan_open(struct tty_struct *tty) set_bit(SLF_INUSE, &sl->flags); - err = register_netdevice(sl->dev); - if (err) + err = register_candev(sl->dev); + if (err) { + pr_err("slcan: can't register candev\n"); goto err_free_chan; + } } /* Done. We have linked the TTY line to a channel. */ - rtnl_unlock(); + spin_unlock(&slcan_lock); tty->receive_room = 65536; /* We don't flow control */ /* TTY layer expects 0 on success */ @@ -621,14 +614,10 @@ static int slcan_open(struct tty_struct *tty) sl->tty = NULL; tty->disc_data = NULL; clear_bit(SLF_INUSE, &sl->flags); - slc_free_netdev(sl->dev); - /* do not call free_netdev before rtnl_unlock */ - rtnl_unlock(); - free_netdev(sl->dev); - return err; + slc_dealloc(sl); err_exit: - rtnl_unlock(); + spin_unlock(&slcan_lock); /* Count references from TTY module */ return err; @@ -658,9 +647,11 @@ static void slcan_close(struct tty_struct *tty) synchronize_rcu(); flush_work(&sl->tx_work); - /* Flush network side */ - unregister_netdev(sl->dev); - /* This will complete via sl_free_netdev */ + slc_close(sl->dev); + unregister_candev(sl->dev); + spin_lock(&slcan_lock); + slc_dealloc(sl); + spin_unlock(&slcan_lock); } static void slcan_hangup(struct tty_struct *tty) @@ -768,18 +759,29 @@ static void __exit slcan_exit(void) dev = slcan_devs[i]; if (!dev) continue; - slcan_devs[i] = NULL; - sl = netdev_priv(dev); - if (sl->tty) { - netdev_err(dev, "tty discipline still running\n"); - } + spin_lock(&slcan_lock); + dev = slcan_devs[i]; + if (dev) { + slcan_devs[i] = NULL; + spin_unlock(&slcan_lock); + sl = netdev_priv(dev); + if (sl->tty) { + netdev_err(dev, + "tty discipline still running\n"); + } - unregister_netdev(dev); + slc_close(dev); + unregister_candev(dev); + } else { + spin_unlock(&slcan_lock); + } } + spin_lock(&slcan_lock); kfree(slcan_devs); slcan_devs = NULL; + spin_unlock(&slcan_lock); tty_unregister_ldisc(&slc_ldisc); } From patchwork Sun Jun 12 21:39:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2052 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 114753F1DD for ; Sun, 12 Jun 2022 23:39:59 +0200 (CEST) Received: by mail-ed1-f69.google.com with SMTP id y13-20020a056402358d00b0042dfb820070sf2958430edc.6 for ; Sun, 12 Jun 2022 14:39:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1655069999; cv=pass; d=google.com; s=arc-20160816; b=e1xWXhEZAxdaiyBl/i/b+aqPi+bvrXYGb/p4MMqruz+nqnQWl+T+9OgvIQfai3lXLu OxAUlUfUi4cd96tBvZKQ/kG01vrkU26YyDF7JjFEmh3gt8/6GUs5CE6FWWC8XSz3UfYS wWZOur+AQSG7JnsLQ1WFa+Xr7+7/VlG5YHX10hXP7ym2w9XY/Ji0jszD/HbqYBqblz2L PgGDqEtoxS0ZXhgHwW+/awq9zsPmMJCT4OQurdXF9go7Lhrx3f2UWvzhiHSlBj9cxe/0 zNBJl2oimsqh8vol8IhQoNMJvCCt0XRK7Cg6hgI25I4KNA6z+hx4oBMum/bYhVL7Hl1+ CkAQ== 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=4pFUQVeSzv4I39s6qZHjrQ2J1fyJgKsC98s6f7ej8R8=; b=N0XfR3XqfOiTIDdiRE4PKviirsOxRVvske2K8r8pp9xQ7qNPVKSmy1/bWoveFoVfN5 mAXMNCl9xab0mR34h7hwKj5mk30seyyUQ637E/oXy263OwMwH41Uw0ylLw1s4EwpTpE1 YaL/76+EE1Rn4NySAjZyncRz5TS7td8iFGhaPwG9iZOEXMJ0wbBLHXqeeFQif0ik5Eg2 kWAUpM2EWZbM4lAyyh2iOgemGqpXmT+0be8A2TQC8/7zLEc3BwQ1j+W9ZTV7uSZk7Jry FuGDwPCmWUv94r/THFHM2Z9TZXm1d3DiOBj1MZONWBW+o8VvZabWNc2TtD7ymtTFtbd1 Xudw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=d9VwXs1I; 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=4pFUQVeSzv4I39s6qZHjrQ2J1fyJgKsC98s6f7ej8R8=; b=HGEK7X80d8ygqi8xa1m/rMCPlE9Xfw6cTWIF2lkggIV+4/TX2jQyVDKn56MIj4S9kO UWnHVi5FLMu0rRZAnVHH9rp5dpYsocheXijOB8XtuaJL1+UwkJRv1u++je2Lf6bdHzT+ nJ9At1wbsmW0ICRkLNtL14lzKoZ8jw15KOOxs= 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=4pFUQVeSzv4I39s6qZHjrQ2J1fyJgKsC98s6f7ej8R8=; b=CfakY+zS26XnR+7SOswRMp+Yv9IlW+76ZgDFyMssabvpy+2aikRSO+LF/f74YOitEw DbB8uw+oI40pKQVPdp31hfpC6tdXIsTxyxAOHxPLoJ7YbauTq0/0gcrGZpM0F3QoC2KF sKSOAMiHRmO31nbFsj78Y2JN4yR5cVimR5sMLjteRNz/583PRWTGygLk9Jsmm0TakTGs J2EcRCnCAhdwYKcJ+xJwu2gjTMNyZtjbAloVg4iJvFpm1gZr/FTw6xemcuV4d05SH1rK svYPHFMEBoCJ1SZw08zOphwvXnMUr3W3vioz0CA/eppurOwmfrfgqFV47Ce65Gs1LpYF JyLw== X-Gm-Message-State: AOAM531IbjePaf4+eBwMKFb45kTKfkVqHnLgN9iMbsDspl39cLJ8ZWk5 zs3JCCnNCPQwGO4TBoqf9OUdhYvq X-Google-Smtp-Source: ABdhPJw/n6yLTl+hB3OOI7cWllnKW1CpD5xXjNw7h7OQHsJZp3WqVdMj9FhuRccCSKLbhgvccR9K3Q== X-Received: by 2002:a05:6402:4408:b0:42d:dc8d:a081 with SMTP id y8-20020a056402440800b0042ddc8da081mr62399883eda.69.1655069998954; Sun, 12 Jun 2022 14:39:58 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:424b:b0:433:426d:7e15 with SMTP id g11-20020a056402424b00b00433426d7e15ls1835703edb.0.gmail; Sun, 12 Jun 2022 14:39:58 -0700 (PDT) X-Received: by 2002:a05:6402:c8b:b0:42f:ac38:9c07 with SMTP id cm11-20020a0564020c8b00b0042fac389c07mr53802572edb.292.1655069997901; Sun, 12 Jun 2022 14:39:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655069997; cv=none; d=google.com; s=arc-20160816; b=eWPSlv1D3OjlG7zhEps1tX+gz3M1wSCBsODeOFCHq0+Q/6oA97Bwyl2FVZbQ8tJcSP ttbqT2UxzkRQSPa1kSImfc8uU7wy5m+zLjxEVoNElyAP+5Z3Ume6wIxzr3hpWUSSC4Sv ajsak2BmX97G6bxHCOS/gjwlxH4m8BJRpNVHVO44RJY4FiAmn/dFY4owmouqCISAlE8q DV7hxEEpO1sN1GXpl5fJm3lxSNw6VIhH8H7p5aknyY8/x1pEe0Vjv0RPLlyI2FxLUL2+ 7FOzmFN98hiTTuVVhRDz9axY3LglIFEJ90L57UEPE5exe9Jk5k/vzlqQudkQbRwzPdU1 7Tjw== 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=Hx0NO2HP0dNrW23jq3KzvYzEwbT+EuqW3kfxDZENRj0=; b=mBUJtyg43roMgRKRTjc2fVFomjKo/EjWVQOTZ4bkpWHLF5ZIIg4D74VJs8+xwePfR1 yvlBjIbPVfm542SrShR+QNSxVAAuPQDMANtQ0oIUKROlBUcDBXjmI9Mi7dzhRCYsQCIl bSN7nwavoGTulkrlrLGEvOW8onOOVUi3CX25nQy8wna9LZ3H/tVXRiWfx4fPrU+JhEIL IBuN4HcFyHFRTTQQJ4nAFvFRJcBFlqJLoUVW1OhMBsIQN6KVyoCdppMpLr5mevD2o6DD jY2TKQZgX6scuI3wdRLtwn34a1zAInv54RzvaVXtgM4AsPeGLPBVe3wba31nPRCyHtCA 1Qwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=d9VwXs1I; 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 g17-20020a1709064e5100b0070b273756c3sor1273955ejw.127.2022.06.12.14.39.57 for (Google Transport Security); Sun, 12 Jun 2022 14:39:57 -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:7a57:b0:711:faf1:587d with SMTP id i23-20020a1709067a5700b00711faf1587dmr20191424ejo.581.1655069997739; Sun, 12 Jun 2022 14:39:57 -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.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jun 2022 14:39:57 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: michael@amarulasolutions.com, Amarula patchwork , Oliver Hartkopp , Dario Binacchi , Marc Kleine-Budde , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Vincent Mailhol , Wolfgang Grandegger , linux-can@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v3 05/13] can: netlink: dump bitrate 0 if can_priv::bittiming.bitrate is -1U Date: Sun, 12 Jun 2022 23:39:19 +0200 Message-Id: <20220612213927.3004444-6-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=d9VwXs1I; 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: , Adding Netlink support to the slcan driver made it necessary to set the bitrate to a fake value (-1U) to prevent open_candev() from failing. In this case the command `ip --details -s -s link show' would print 4294967295 as the bitrate value. The patch change this value in 0. Suggested-by: Marc Kleine-Budde Signed-off-by: Dario Binacchi --- (no changes since v1) drivers/net/can/dev/netlink.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/net/can/dev/netlink.c b/drivers/net/can/dev/netlink.c index 7633d98e3912..788a6752fcc7 100644 --- a/drivers/net/can/dev/netlink.c +++ b/drivers/net/can/dev/netlink.c @@ -505,11 +505,16 @@ static int can_fill_info(struct sk_buff *skb, const struct net_device *dev) struct can_ctrlmode cm = {.flags = priv->ctrlmode}; struct can_berr_counter bec = { }; enum can_state state = priv->state; + __u32 bitrate = priv->bittiming.bitrate; + int ret = 0; if (priv->do_get_state) priv->do_get_state(dev, &state); - if ((priv->bittiming.bitrate && + if (bitrate == -1U) + priv->bittiming.bitrate = 0; + + if ((bitrate && nla_put(skb, IFLA_CAN_BITTIMING, sizeof(priv->bittiming), &priv->bittiming)) || @@ -563,9 +568,10 @@ static int can_fill_info(struct sk_buff *skb, const struct net_device *dev) can_ctrlmode_ext_fill_info(skb, priv) ) - return -EMSGSIZE; + ret = -EMSGSIZE; - return 0; + priv->bittiming.bitrate = bitrate; + return ret; } static size_t can_get_xstats_size(const struct net_device *dev) From patchwork Sun Jun 12 21:39:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2053 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id CC2013F1DD for ; Sun, 12 Jun 2022 23:40:03 +0200 (CEST) Received: by mail-ed1-f69.google.com with SMTP id f9-20020a056402354900b0042ded146259sf2938451edd.20 for ; Sun, 12 Jun 2022 14:40:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1655070003; cv=pass; d=google.com; s=arc-20160816; b=wrC4pnbVeeey6MN4NKujo929cpYjEAZooHdv+MhGY6Uwa/bcRGU2XFmJi6EAnJEWxg AT/zZdcP3dW4SmDmj6owrgPSghaIMNgZZKO38dfjfuN+hXtPMHlZS8VamMaROVH06aYX ZM1LT05klHra6OT8dMgF4/5jInovPxFiq7CCe+azYXf/I8FvuaNl7AoDwib6M3p6tIX2 m3K0bjtF//vFYMtAYIKHSZit8cUft35JLEsB0+xl47FFNhoUHp5GCYqF7qEP+1TuRlyd cccIlaA/tcqtwxrBIdukSXKRUT4VpZaznw5iUkjfNvJwFE623bHlq0QNC/vWFowlVUOV WaGA== 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=NKvohrWFE4+aBEVFDkU1FsOEKjvjK3ZcY2D91IJZfDU=; b=a1EKb5fuUN/kLb1PdKu43x/goBCFBP3pg4hrOI/V2zBVBUFKZT7FwgC+e1t3rQiOnS 2TDy5bu62QtXaWwa0WR+xvihVxOvZ7OxzhcaEhkRhYFVZD+pIPof279YryHbbZKG2LLI 7L7+XnpgTczA601OUghWcTyUzfD/EZ2mkmX28liIXogD/7oEaA/xeMg8/FSxFevY5f31 bqeGscJKp9HxhHOeOo6lGGCmdN/TP9klwv1CuQ2Obu0+Gky3EzaDU8n6R3OcuDyQQeph dw9QjTE3DdYYKuodPaGcD2g81IoB7Hjy3jxaQt9e7YivsiFBAqiXXqV7qkwSDPoXRFDh +vCQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=iySTg+7g; 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=NKvohrWFE4+aBEVFDkU1FsOEKjvjK3ZcY2D91IJZfDU=; b=RX5B+9nxd7yFBO4dYROWXzgMqnAMTvxmPuzY7CvDehNbRMOW9OlO3x/MTOKXnDtipA +qcTUPdZ+0CZ5plfyK7H27uLvIzOZeVgpm8ZMvBDeFOT7sCUCGjw6iuBmLVt1sZ1XqIM OgEBgWNo6wyrVYfRIOkzh6PSj6xcJcYQogpl0= 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=NKvohrWFE4+aBEVFDkU1FsOEKjvjK3ZcY2D91IJZfDU=; b=cW7rhOOfucwVCfTIqlaxWS4W8UHZEI+UEC1VBQl6CnOy8vDmD4j6P5zdRsJH9uq8La m7ydL9OjaVEhYp59bU+F4baiXpZ5wrrPmFt0G5Q0stD8hPFWkZz+99cb46q/YtEHj3wx QhFVPKlCLO674hMbnyv0i+XOC3FVnRcGnAPW1iW0y0xpuMJ98LkJb9G5VRsVJSfr5QiA JBxLxky1IWvN4sMslZTvimsqEom/ommh2qiPS5/NYNqYAprYh76s6zuedsCMq+7tAjKK 5UDpHbwZch8k7BuWlDGAi7Lor33/SWtsiPg9+YPxERwlyR+dBVzKMsyXODVM4NEtAQup htBg== X-Gm-Message-State: AOAM533DNUAYRRPR1faLrlkTZ3yXU7c4W5TgqqOPoqIV3yXZeAMs9njg W22KYlZElgm4M+UABSRa6HpMWHY3 X-Google-Smtp-Source: ABdhPJySKCsvBc4ddo4lBGjFg7F8TXeueQF3lUiy1rF27XOFmZ+az7SdsJUbY6TH3NAGZrW2K+9aJw== X-Received: by 2002:a17:907:1620:b0:711:da21:d836 with SMTP id hb32-20020a170907162000b00711da21d836mr30912139ejc.427.1655070003618; Sun, 12 Jun 2022 14:40:03 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:424b:b0:433:426d:7e15 with SMTP id g11-20020a056402424b00b00433426d7e15ls1835779edb.0.gmail; Sun, 12 Jun 2022 14:40:02 -0700 (PDT) X-Received: by 2002:a05:6402:35c4:b0:42f:b0f8:6a69 with SMTP id z4-20020a05640235c400b0042fb0f86a69mr52343390edc.180.1655070002686; Sun, 12 Jun 2022 14:40:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655070002; cv=none; d=google.com; s=arc-20160816; b=LnxuH2jz2jJLdZFxkabv7w8UW2Z/76embbJg3o0QS9hpLKgOpKSEUfIFKdsfWJcvl5 oD/QqBO6gq4yi4mXXvl9tiACCAh3V/VYGtzxupNJpgqz8x2XRP9liB5I3ZiL9aVQK0va ocoOQNyE2Um2XJVBGOmDiVROxXqzpKvfHC86bG9qfsqcjFheyPFWdGrP6WeQCT4TCtbx mL4OjpEyxuBZ43f+PqtFdjXDWPNMXfGTkGX1Y84tuPrzRFfPTsQb/gH+XzDnqNDt8kIA XQumXU2UMy51wcH/DYnKzZ7lWXduZKxeZI/+piMohzk/wHphD7giRDmwUmF3CE0Nq8EG AwOQ== 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=UpyKa7+uiIpxrunvBDbFWo+0Nybf0w4Bu0XA6EFem0M=; b=Jz9OI82S/zSvbFASKzDN4J/7YO5Omfza0wwFwvSBsDXEUzF28y7scrq8YNvlU4o9wA BmlSYS1YaWuHAac7R3+kk2bidnRrLbeiCAmGXLzd9tgvst9e5rhIufpwCq62n5AwVuYi lv4znYBzTC511cjPMvRojZnzwxbvjdsnYtIy6eSRp0YxIZNz/Gy3dnfcfRgFPnllBczt mdfQsjxtfr49mNm2xtuOb5SxuTVCPLYPt/zPjC4a8oBdKID36+zzQdLAVfo4AspbJREH Xg1MbnObvU/DyjwDK3oaKCFzYX1vxLj2njM2Yw24+qDmR2Dfu3U4SYRhRhmNh4rNVqhi F86w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=iySTg+7g; 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 jy7-20020a170907762700b007107e67fe56sor1305719ejc.105.2022.06.12.14.40.02 for (Google Transport Security); Sun, 12 Jun 2022 14:40:02 -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:8195:b0:710:b40:95d2 with SMTP id iy21-20020a170907819500b007100b4095d2mr41307282ejc.604.1655070002462; Sun, 12 Jun 2022 14:40:02 -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.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jun 2022 14:40:02 -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 , Jakub Kicinski , Marc Kleine-Budde , Paolo Abeni , Wolfgang Grandegger , linux-can@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v3 06/13] can: slcan: allow to send commands to the adapter Date: Sun, 12 Jun 2022 23:39:20 +0200 Message-Id: <20220612213927.3004444-7-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=iySTg+7g; 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 is a preparation patch for the upcoming support to change the bitrate via ip tool, reset the adapter error states via the ethtool API and, more generally, send commands to the adapter. Since the close command (i. e. "C\r") will be sent in the ndo_stop() where netif_running() returns false, a new flag bit (i. e. SLF_XCMD) for serial transmission has to be added. Signed-off-by: Dario Binacchi --- Changes in v3: - Update the commit description. drivers/net/can/slcan.c | 46 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/slcan.c b/drivers/net/can/slcan.c index a70f930b7c3a..4639a63c3af8 100644 --- a/drivers/net/can/slcan.c +++ b/drivers/net/can/slcan.c @@ -97,6 +97,9 @@ struct slcan { unsigned long flags; /* Flag values/ mode etc */ #define SLF_INUSE 0 /* Channel in use */ #define SLF_ERROR 1 /* Parity, etc. error */ +#define SLF_XCMD 2 /* Command transmission */ + wait_queue_head_t xcmd_wait; /* Wait queue for commands */ + /* transmission */ }; static struct net_device **slcan_devs; @@ -315,12 +318,22 @@ static void slcan_transmit(struct work_struct *work) spin_lock_bh(&sl->lock); /* First make sure we're connected. */ - if (!sl->tty || sl->magic != SLCAN_MAGIC || !netif_running(sl->dev)) { + if (!sl->tty || sl->magic != SLCAN_MAGIC || + (unlikely(!netif_running(sl->dev)) && + likely(!test_bit(SLF_XCMD, &sl->flags)))) { spin_unlock_bh(&sl->lock); return; } if (sl->xleft <= 0) { + if (unlikely(test_bit(SLF_XCMD, &sl->flags))) { + clear_bit(SLF_XCMD, &sl->flags); + clear_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags); + spin_unlock_bh(&sl->lock); + wake_up(&sl->xcmd_wait); + return; + } + /* Now serial buffer is almost free & we can start * transmission of another packet */ sl->dev->stats.tx_packets++; @@ -384,6 +397,36 @@ static netdev_tx_t slc_xmit(struct sk_buff *skb, struct net_device *dev) * Routines looking at netdevice side. ******************************************/ +static int slcan_transmit_cmd(struct slcan *sl, const unsigned char *cmd) +{ + int ret, actual, n; + + spin_lock(&sl->lock); + if (sl->tty == NULL) { + spin_unlock(&sl->lock); + return -ENODEV; + } + + n = snprintf(sl->xbuff, sizeof(sl->xbuff), "%s", cmd); + set_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags); + actual = sl->tty->ops->write(sl->tty, sl->xbuff, n); + sl->xleft = n - actual; + sl->xhead = sl->xbuff + actual; + set_bit(SLF_XCMD, &sl->flags); + spin_unlock(&sl->lock); + ret = wait_event_interruptible_timeout(sl->xcmd_wait, + !test_bit(SLF_XCMD, &sl->flags), + HZ); + clear_bit(SLF_XCMD, &sl->flags); + if (ret == -ERESTARTSYS) + return ret; + + if (ret == 0) + return -ETIMEDOUT; + + return 0; +} + /* Netdevice UP -> DOWN routine */ static int slc_close(struct net_device *dev) { @@ -542,6 +585,7 @@ static struct slcan *slc_alloc(void) sl->dev = dev; spin_lock_init(&sl->lock); INIT_WORK(&sl->tx_work, slcan_transmit); + init_waitqueue_head(&sl->xcmd_wait); slcan_devs[i] = dev; return sl; From patchwork Sun Jun 12 21:39:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2054 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 55F843F1DD for ; Sun, 12 Jun 2022 23:40:08 +0200 (CEST) Received: by mail-ed1-f69.google.com with SMTP id a4-20020a056402168400b0042dc5b94da6sf2947373edv.10 for ; Sun, 12 Jun 2022 14:40:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1655070008; cv=pass; d=google.com; s=arc-20160816; b=PH89L38BAzqggnpjw8FspxcgOOZuZSpoizrmuMX2ynLhwi1ID0HnDRkg1kN2ZW65T5 /lUti5sjg6+ExtCytfSgcuh4IYikfS2IsbwuXE686XIUSBTR017LwF3idL5W6rtfaWMa 30K/E1AQf1Lt5WTmku7Fc6zRHxqvtDiD8uCWqStzeUgjobhqopOToWZrb2usnwC9FmS+ z4W7Avl/tl1F8K/VeXTuT85xJ1IQQkC48S8E6UkWgMEmOeWOoBFtUV83+86OYsGxq3PY V16icwIoEBAClBhtMoCf61zK18UTUpCvnH9BgX0Iy9UJZ0z5AeWlisIzT9EmNn6xkpgi YZTw== 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=dOJUY+m3CETPRn4+2lIDxKcqcjE2dJofYG50D3QlEWU=; b=VlPiuLLLIvBoabnzT9ybDkWI/VeiNzD9wtz9Rj1HNvzAl+VvCI7I7qBbEpQvVKUawc s2vgP8gMI5JSBQKTm1T5eWDe354mt9YbPHgAPgYJtWTnVgh3nRhozrchA+Hmvp3HheB7 L/9Er19GaPNklbewrVAdvBOQSdyx/sNkIdPZ02bWUXH0Pg5nGM7sAILHFJICwrHsM+05 1TyteKiZggLQ/bWh3nCMF6InC2O9BKSII1kgUq77kANYsiiuLfRnf49UXabT6fi+uz29 NGj31GYKm9a6VJE/CnDIkoXlBEGBZH5ZSKeZgX2p5uBJllUshUSeHzKwleMFX/XSeaeI 1XOw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=ekzn2Eu7; 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=dOJUY+m3CETPRn4+2lIDxKcqcjE2dJofYG50D3QlEWU=; b=Y2kQu7hTjnRpP8ly7b/bQl8jfi9OEQUoaldRfugszmyuWWv+VCyInj0Bde9fi4w8wY Ifn58KkuMk419n+mIknfGgPmZQ7CX40Yp57iCfnULYMY7YUWRZQ2896BaVkO6QzxLDHf +lPUjxBPBhXeeXbeybY/+c3J5y3+w8Un85JEA= 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=dOJUY+m3CETPRn4+2lIDxKcqcjE2dJofYG50D3QlEWU=; b=JdS9UmQQrAomZEB7cChilIslnfIe0di8c+xHXVyzbQVDY6yHXRPy9Zdc+TQsPZVvzY 8SOtLHfUqWvzmU3W6w/XOJogAev3JDWKyRFPJnejjDrKMcohukBLzm64SbiU5lJoG+pu Ie3lu23QrgPrvd6Mxfsn70A2t5IsGBfWaZvql0DJy9ramXxqJRL/z0c+G8xJyIO8fv6V JBwma8X7zUXZpzOKd6lrs/VmIUyZaX7s3vJKRh1VfobqDGEs15aYtxtmZe3I6CtJzT9F b+RTVp7V55/xnpFtSSffQztxITaRa/L/uHngBzGboHLeWqekZB/0I+ltIFtWZi9paM45 3+aA== X-Gm-Message-State: AOAM531Zek0BA/pv3jHmsxTF/6xfMK3YWJ0i35/8dZQM3zompx5hylYG sJfm6jS6bgWo1/S7ybWCGLaB+meL X-Google-Smtp-Source: ABdhPJz7dPVQsd2o1Q59ApUwF/Izt0OZt/BL0OsWEPnW936h9BQMz3p4NGpkO7bLitLmn3/JCzqa4g== X-Received: by 2002:a17:906:d82:b0:70d:84d3:b6df with SMTP id m2-20020a1709060d8200b0070d84d3b6dfmr46190506eji.464.1655070008165; Sun, 12 Jun 2022 14:40:08 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:907:c19:b0:704:582e:9858 with SMTP id ga25-20020a1709070c1900b00704582e9858ls1010627ejc.1.gmail; Sun, 12 Jun 2022 14:40:07 -0700 (PDT) X-Received: by 2002:a17:906:2dd:b0:712:1293:3dd8 with SMTP id 29-20020a17090602dd00b0071212933dd8mr15463307ejk.448.1655070007110; Sun, 12 Jun 2022 14:40:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655070007; cv=none; d=google.com; s=arc-20160816; b=aJuRxlDRQgLv6UpC4SpiPdFuKGUNC3Fzq4V0Jix6aC7sgzaSZBfMD1s8aw7hJ1IVNj DDgjAwL33Oeh6MAfidg9Ttte3fBsNT+iHV/XntAmUG3rKrsHYx1S+S/AhWd9ovahebQB wkD6yg+hgfZC5NO9PniUH3MgAqTazJGuTzovmXmj13n0r8uLT2CCJEP67DSbro9MQFna 7GtC5TU6Gn24xh9D1Pucb5gQlgIidSDH3rBegJWqgGkI3IO4tddHHMNpnYahKkMoJoi0 UsD8qF2QwkFoOWUgTlU8wNiBh+XEGkhW9n8p1Tr7sLXAR7+vchzTnPNdM1W0RxlGxj3a LG2g== 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=+67b1tOoWpv+tJyn4Sl0UQj6SwsqWBdWszhIl7nE8ec=; b=cMypCVnWcIuSn1o4XHn+OkKrzFjI0Z+YzRkxeSo6mfOE0x+mu0zGSpR86Nyxxez5J0 YqNeEJbfqcjZ/kS5yZDp6wHnA1tdTh3tuN7H4j10DFCrJQEunCLC7biWOWqLxsgt6sLH X9rUjxO9Di9aXA7qu+eFaqyuy9G8yyq+1Lmk09GhqZdLV5Tj6YztdKbaq/X7tJdYM2oJ VcuIW9yfiKFFeffIxmF6cQI+bVYuu/7lvVV5Z5o8LDShVoUX8FCqFh2wdR9GGePa5XUs ORAZgQEgcyXtE1wdfeLS3hfRIBCZWstk1M0elCqr3g9WBiKkz3tc750j9PeiKVt1ssoa V5Ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=ekzn2Eu7; 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-20020a1709063a0400b00712134cb9d5sor1286944eje.69.2022.06.12.14.40.07 for (Google Transport Security); Sun, 12 Jun 2022 14:40:07 -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:8a1d:b0:711:d86e:cc5 with SMTP id sc29-20020a1709078a1d00b00711d86e0cc5mr31921307ejc.237.1655070006888; Sun, 12 Jun 2022 14:40:06 -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.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jun 2022 14:40:06 -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 , Jakub Kicinski , Marc Kleine-Budde , Paolo Abeni , Wolfgang Grandegger , linux-can@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v3 07/13] can: slcan: set bitrate by CAN device driver API Date: Sun, 12 Jun 2022 23:39:21 +0200 Message-Id: <20220612213927.3004444-8-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=ekzn2Eu7; 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 allows to set the bitrate via ip tool, as it happens for the other CAN device drivers. It still remains possible to set the bitrate via slcand or slcan_attach utilities. In case the ip tool is used, the driver will send the serial command to the adapter. Signed-off-by: Dario Binacchi --- Changes in v3: - 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. Changes in v2: - Use the CAN framework support for setting fixed bit rates. drivers/net/can/slcan.c | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/drivers/net/can/slcan.c b/drivers/net/can/slcan.c index 4639a63c3af8..be3f7e5c685b 100644 --- a/drivers/net/can/slcan.c +++ b/drivers/net/can/slcan.c @@ -105,6 +105,11 @@ struct slcan { static struct net_device **slcan_devs; static DEFINE_SPINLOCK(slcan_lock); +static const u32 slcan_bitrate_const[] = { + 10000, 20000, 50000, 100000, 125000, + 250000, 500000, 800000, 1000000 +}; + /************************************************************************ * SLCAN ENCAPSULATION FORMAT * ************************************************************************/ @@ -440,6 +445,7 @@ static int slc_close(struct net_device *dev) netif_stop_queue(dev); close_candev(dev); sl->can.state = CAN_STATE_STOPPED; + sl->can.bittiming.bitrate = 0; sl->rcount = 0; sl->xleft = 0; spin_unlock_bh(&sl->lock); @@ -451,7 +457,8 @@ static int slc_close(struct net_device *dev) static int slc_open(struct net_device *dev) { struct slcan *sl = netdev_priv(dev); - int err; + unsigned char cmd[SLC_MTU]; + int err, s; if (sl->tty == NULL) return -ENODEV; @@ -461,15 +468,39 @@ static int slc_open(struct net_device *dev) * can.bittiming.bitrate is 0, causing open_candev() to fail. * So let's set to a fake value. */ - sl->can.bittiming.bitrate = -1; + if (sl->can.bittiming.bitrate == 0) + sl->can.bittiming.bitrate = -1U; + err = open_candev(dev); if (err) { netdev_err(dev, "failed to open can device\n"); return err; } - sl->can.state = CAN_STATE_ERROR_ACTIVE; sl->flags &= BIT(SLF_INUSE); + + if (sl->can.bittiming.bitrate != -1U) { + for (s = 0; s < ARRAY_SIZE(slcan_bitrate_const); s++) { + if (sl->can.bittiming.bitrate == slcan_bitrate_const[s]) + break; + } + + /* The CAN framework has already validate the bitrate value, + * so we can avoid to check if `s' has been properly set. + */ + + snprintf(cmd, sizeof(cmd), "C\rS%d\r", s); + err = slcan_transmit_cmd(sl, cmd); + if (err) { + netdev_err(dev, + "failed to send bitrate command 'C\\rS%d\\r'\n", + s); + close_candev(dev); + return err; + } + } + + sl->can.state = CAN_STATE_ERROR_ACTIVE; netif_start_queue(dev); return 0; } @@ -583,6 +614,8 @@ static struct slcan *slc_alloc(void) /* Initialize channel control data */ sl->magic = SLCAN_MAGIC; sl->dev = dev; + sl->can.bitrate_const = slcan_bitrate_const; + sl->can.bitrate_const_cnt = ARRAY_SIZE(slcan_bitrate_const); spin_lock_init(&sl->lock); INIT_WORK(&sl->tx_work, slcan_transmit); init_waitqueue_head(&sl->xcmd_wait); From patchwork Sun Jun 12 21:39:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2055 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 7A0EB3F1DD for ; Sun, 12 Jun 2022 23:40:11 +0200 (CEST) Received: by mail-ed1-f69.google.com with SMTP id g7-20020a056402424700b0042dee9d11d0sf2939276edb.3 for ; Sun, 12 Jun 2022 14:40:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1655070011; cv=pass; d=google.com; s=arc-20160816; b=tHvD6gOvknlb9wEiyyhMm/yh8pCab/qeybWrkULavGDMlpGlxEs56oKREZ9X+ZVCLY xPhu2BAu17mboX6AkoSadqAcnP/teY6SCFHZR/l+/rZCKyLr4mHc4gktEOqaBKXs4jjV CtQAa+C5JWdZ5HBbfJ7l7vm03JfoSI+O50Ju8ZjYrW2UrfSErl5Xt+TQDx1MvRYGqUNu r44Kz9dPqHkqGA7S3XueZqq9/KsIJ/XJGBLoS+D4FReYDMfzdk/3t8LiwvvnL90bFZ+T LspGwQca+6Dnr5rbxTeLDlNimFmHw5Ib3mKlMxmqOw+08EZQzPhV2WJHelmiX7nuDfNy fdzQ== 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=kdWAnxchTQLmIuV/UbAYWm2G8/u7Sjiwq3f/19nOh+s=; b=mZ7BZOfOueDKO2Lbs7xlIlz09coG7Ctiv/i/oFiaW2mhgDncz9TVNeQNtchGwb0oYL syD3VdKXmLeEzSOkfVXMkyJVGwaE5zwjOtIa4QltSyY+C50QUvWInNV5+Bmzh5oIf3eN VN4517toU29XcAMXoksza5NPJUc8U5g6vAT+YtWW/+IV12tcXO3TuxBW53r4Xbr04d3O MvCC4FSPnzOY+DbAgSbEkCe9IO4OPGQIhVuCkfdmMrykGleUZxV50NW2+osX+rn7DG79 LHWMbR42tBJQf0lByJL5pyjOZqq/nFl0/wBH8A1G4pq0Vw6vzYM+1AJb0PICvoRtK9vx Mesw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="Qr//VDTJ"; 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=kdWAnxchTQLmIuV/UbAYWm2G8/u7Sjiwq3f/19nOh+s=; b=ZxWk/xlKJqr/3DRs1ONHAL6RTxEln6wOo6QwztKIXqailIkR9W91DPWs74BgJ/GBwm gnFjNhIwLujpGjHbVq+ny4P0cu4njS2SZ2OjrmKaKBcir9etFRJM3bJeciTI7lRYDCgz HxJUNtovv7JxyGd5kmk7viGa+gkB4kIRWpZX4= 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=kdWAnxchTQLmIuV/UbAYWm2G8/u7Sjiwq3f/19nOh+s=; b=61aGIDpqHcL5ca0Q3efAyEYWn0UKfVmo5TG+sq+dUE24IsGnupp30mZGuzLkEJRotK 0hySAznM80drZidImMq72nf9i8LDBonRNZN1NbZxZHdSwVb5X7nwk4iXxxw/CopUaKyW rMBHUYL562aLf42k23GwXdNloqHATlFKuR5WiAPLh2VGwcUqBS3iULYdOESoWQ+2sSoV 3yYbjVRgai4OuOmtqHLcM5rwJOjnPl2LOLlv4/kdjwPa1oNPxWb2o4bJ1qEm5jFNjTTg 3ICbGuJii6bFavJhPTxccuJn12PsDmy3JDAUnj8SaQmZLzUcgGj+4z+dvD1bDL33iwte bvmw== X-Gm-Message-State: AOAM530hLdJ/PWahPSDj9I+avUB1w1vSGNTP++yNQTI04SVtJNB9DLSY Lh72QqyQMUGfzBdMb0YGevavtGde X-Google-Smtp-Source: ABdhPJzQU7k3J/eEZ4wbM5JKhrSGrQWN+8DEvnF9Ujt1QKedom/K754xxrZZ7cw6biBNgNi/LQfpIQ== X-Received: by 2002:a17:906:5253:b0:711:ee52:764e with SMTP id y19-20020a170906525300b00711ee52764emr23124697ejm.171.1655070011367; Sun, 12 Jun 2022 14:40:11 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:907:9705:b0:70d:ff46:7086 with SMTP id jg5-20020a170907970500b0070dff467086ls1009757ejc.4.gmail; Sun, 12 Jun 2022 14:40:10 -0700 (PDT) X-Received: by 2002:a17:906:72d7:b0:711:f778:113b with SMTP id m23-20020a17090672d700b00711f778113bmr21182127ejl.625.1655070010280; Sun, 12 Jun 2022 14:40:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655070010; cv=none; d=google.com; s=arc-20160816; b=XBDFvCuqgYbAfniWwjKvGqN6QyFnGrb/nHPlmVA1jwJ4Z5Qw1Ykb0bxaBjVBjUgxrp JmMe255VgQLGTpkwiS+6cWgilWFTW9pZgC0RgjpeXeD2tT2kCRZGXP8Wny//IiDqznS+ mV14yPzw5wG/n1fE6/Af3/+/dnVcGb7ofk2u/u9xiwXecY4NiVMHUdp5TBTrNgt509sO /Y6nygOhSr7lpCioVzclg/l65CvV4HFUkinGL6HvHiMd8XWzPrEvxAvf1wxj4HHmKKuc yWGeSek9fE1tmvEpTxkDdN73+P1iLWDIqQMX/ea3qyuUVa/BIPBGcdKGQn9aDzjfeq9m BP2w== 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=AAKaIth+G/AmEuzfr70Dsvzk4FxXYLQFFVrvRHhl0zE=; b=cq+BEzSFVpzO3H0TP0TzivBi4cL2PWaODZNxPJIPk3oOxLPAZtvbdvrTW7hC7w/upJ 3C6cdfEykMpueijFtAbpZTPqknpm97NgJaLht13LYnuWKgFBqmTePXodEA+V8wL8acyJ L74ffYZJjH0+ahdkM9jYPL9Iy+oQEoyDiOGS9d/rpMwuxHtIPVEY2ToI93LRHFrpjSaV cdrZ4+dwLSs7ryX2+X90/86CaBCPxKyKNiycQ6jT3gCSmY4UFsDgD9p33VaMeCGVglxj JrcIxFVo21CApKzOKbf5BBTleMENJe64JhKHs8J7ymZAJBwGNfIJLG/HKYeRVGV9Km6H C63g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="Qr//VDTJ"; 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 y19-20020a1709063a9300b006e89145b218sor1314899ejd.46.2022.06.12.14.40.10 for (Google Transport Security); Sun, 12 Jun 2022 14:40:10 -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:1c9:b0:712:1115:42a5 with SMTP id 9-20020a17090601c900b00712111542a5mr15154695ejj.662.1655070010102; Sun, 12 Jun 2022 14:40:10 -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.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jun 2022 14:40:09 -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 , Jakub Kicinski , Marc Kleine-Budde , Paolo Abeni , Wolfgang Grandegger , linux-can@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v3 08/13] can: slcan: send the open command to the adapter Date: Sun, 12 Jun 2022 23:39:22 +0200 Message-Id: <20220612213927.3004444-9-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="Qr//VDTJ"; 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: , In case the bitrate has been set via ip tool, this patch changes the driver to send the open command ("O\r") to the adapter. Signed-off-by: Dario Binacchi --- (no changes since v2) Changes in v2: - Improve the commit message. drivers/net/can/slcan.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/net/can/slcan.c b/drivers/net/can/slcan.c index be3f7e5c685b..9bbf8f363f58 100644 --- a/drivers/net/can/slcan.c +++ b/drivers/net/can/slcan.c @@ -495,14 +495,23 @@ static int slc_open(struct net_device *dev) netdev_err(dev, "failed to send bitrate command 'C\\rS%d\\r'\n", s); - close_candev(dev); - return err; + goto cmd_transmit_failed; + } + + err = slcan_transmit_cmd(sl, "O\r"); + if (err) { + netdev_err(dev, "failed to send open command 'O\\r'\n"); + goto cmd_transmit_failed; } } sl->can.state = CAN_STATE_ERROR_ACTIVE; netif_start_queue(dev); return 0; + +cmd_transmit_failed: + close_candev(dev); + return err; } static void slc_dealloc(struct slcan *sl) From patchwork Sun Jun 12 21:39:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2056 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 07C803F1DD for ; Sun, 12 Jun 2022 23:40:16 +0200 (CEST) Received: by mail-ed1-f72.google.com with SMTP id s15-20020a056402520f00b004327f126170sf2961896edd.7 for ; Sun, 12 Jun 2022 14:40:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1655070015; cv=pass; d=google.com; s=arc-20160816; b=B0gvoCxQr4gvqIirLti9Css786nnMY270bSV/WIvvNhWCjoAt3fWWhBgqxLVo1mUSA an0zb4D+ksE226a44zF+EDDhfI8MjBTNBddr6TjAVVFiBro1ABY+eT85K1AzoiT32bd8 ptO9A+s+txSy2vwjsHdmgLMCC1Z+Uo+0rYcJMm35O2Cc1Xwra9t+g57xZY6ZX4KaC+Xd QZkwAYSDUsJYkYSdtdkPEfLqJJeWGIHJt6Hj09MKmA+LtA/2jOlmfPRo+/QzuMh1vauf 5SWNDdWa9pfbZtwXn5BPCp14Cpht1OcdJnxk5FKPVydXG/6cgOVBP8ghuiYCc3gLgv2O yqJg== 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=Bk35j8bZnTVquX4v82VtOEK7U7HzburEvhwFE//XSUE=; b=ELrerfhsXtKAUh0dYi0mVkX7GzqBAaQBnl8dPw2HEbMJ2m6lR1623hi/jY0OsxBUFN J0mbxPOH4bp8C3jhKC2+7j0ljGHdqa3I4iCYhY/L45gk9KYMXlKVt8ATOIOGToGWNZtJ P8aEgi1+lMfZDXle7V8flrvNzKj2xfBMNawOGR6Ejb/xSwAo1IM1Ow+po4PkT/47TKII RmkTH9O1CZGbqubi9xk8KWgZ2qEGuJphwbPe7QtYh3BKCD59P8H1ydpTRigS1dbxjcpx RjbTNW3ovagtPQkiw26qTDxYGwxwgrvrHU0XJn0HN+/auycOIuW3heiVGUxkzZr07iet ggHg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=gKCrFNo3; 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=Bk35j8bZnTVquX4v82VtOEK7U7HzburEvhwFE//XSUE=; b=PrOVi0p3CZvzRml2Or4ZAhPwFuCp5pPm4efa86su9jJ5KwPYv6VbutLjxHIg3TMCBI hz1PUG6BYTzk2/oueRFGEpRoZInQH/2qyZ36xWgoq/RoPVyl1NNOU/Zf865k6XDdx+pW i7FeHIZKlV2RTl7/iOkXu4+P7IC/y2O4lv9wM= 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=Bk35j8bZnTVquX4v82VtOEK7U7HzburEvhwFE//XSUE=; b=s2auB2K6nQLtRfCVK82FwoPvenzk/LrJ37fIgQRC2mOmRFhYRf8wOHy7DoItrAvzRL g/VdxWpWSI9tVWBcH5frIa6J3Ul7gz6FIrRELV7GuEzyUi3hh4orrFs0H62B80psJLry FAh/9khudpIB+7WFw3xT4y7fYvJ92H6SbwtENmL6LpT4BwvDfDIQKkv1g8hLkAgxWTZI YNgGrJeZWG1aN4pY0cdiADtBBKICJpnWULTaGhapgHB8bnVn13x763ZFH92VWD6KOck0 IoGxBaqMPGQiUQyuBfabVP+Zdib1ZtsuUwx9BLLCDrmifZcpIrzcvA3+fzKVVMNkOpZz g8kQ== X-Gm-Message-State: AOAM530U2hNu1eJjmSyIe+Q4XoKnAp3y+9Fr/0KBQGSQ4Y5o0b4iWZ8Q ODLeV/qQrp0Sb40J/kj2BiBZUXs3 X-Google-Smtp-Source: ABdhPJzUhaboUOinCH3VdQDqz9qFq5J/ezXgkMY9e9vhfMHiwohhPL7YoLKcF+ReVHx6sJgp/ZA4YA== X-Received: by 2002:a17:906:c347:b0:718:ca61:e7b7 with SMTP id ci7-20020a170906c34700b00718ca61e7b7mr342831ejb.746.1655070015831; Sun, 12 Jun 2022 14:40:15 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:709:b0:431:3a5e:75b3 with SMTP id w9-20020a056402070900b004313a5e75b3ls1836056edx.1.gmail; Sun, 12 Jun 2022 14:40:14 -0700 (PDT) X-Received: by 2002:a05:6402:3325:b0:42d:e1d8:99e9 with SMTP id e37-20020a056402332500b0042de1d899e9mr60650742eda.87.1655070014794; Sun, 12 Jun 2022 14:40:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655070014; cv=none; d=google.com; s=arc-20160816; b=ibMx8cXhnoHwVK2mxXsMPa/T3Mv4546JM3OSamAwKg1CCUZUp5/lifD1X062aZT/XR zeWrIyJg3zZWw1VRusdltko67cKuLj4SJMPtKD1tZr2jaruK/j4P37eeqK3P6natp+Jx AQoXRHT4+rr476NUAs4ko3W1pmaj+TNmpBb36o4HBS/owiEt8KVnKCYLBB7SNVgmFk+d ICutjHbEmM3pQhN3SyecxcyCcX4nVsZmuOJWwIQV51R8Xq9n8v6pf967K9zUMw94VyKr CsPRV4mzMDfOMnqGYO2J9zuFqEgDuOV8k5z4x1l5lJssU7H8jKYVPcjXQlb3z1GORaWu cQyA== 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=O0zVHGTWOUK0yHY7/MxDgofJ+b/Xb1B9oJbEk1RTZ7Q=; b=io+x7U/afpgDFmxfZRDpXo5AV8K/Ld4/CXa/DFNt27Ij917Oy5yStdkLcwQjZhg+TV 6s6lX1IxfvfKf7q9j+KbQwKd21a3OJd6UTeBYEcNbmMeWqYU+09x5SfvsiQuM74qoxmM F+UAmh3KMkop0GPAEQHvxWBd/bW102I49fUKrUi1rd6TLUgNqxU+c1zfJBDaRk027kiB Bj7e9bLbYx5kfCR7dxINjVO0G/RxOb8Mxn/cB/EML2CPyeAibWszWQ0oF8B1eVtsqCcp V2rpaPXAJR5wFMH+nI0dqCH/UYDXm6WfDr0y6yifXp2k/dNqJxzF7YcyR5Whb3jcD0yO 32+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=gKCrFNo3; 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 b6-20020a05640202c600b0042b65394344sor1571834edx.55.2022.06.12.14.40.14 for (Google Transport Security); Sun, 12 Jun 2022 14:40:14 -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:a05:6402:1543:b0:431:9d90:49f7 with SMTP id p3-20020a056402154300b004319d9049f7mr28466532edx.397.1655070014591; Sun, 12 Jun 2022 14:40:14 -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.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jun 2022 14:40:14 -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 , Jakub Kicinski , Marc Kleine-Budde , Paolo Abeni , Wolfgang Grandegger , linux-can@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v3 09/13] can: slcan: send the close command to the adapter Date: Sun, 12 Jun 2022 23:39:23 +0200 Message-Id: <20220612213927.3004444-10-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=gKCrFNo3; 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: , In case the bitrate has been set via ip tool, this patch changes the driver to send the close command ("C\r") to the adapter. Signed-off-by: Dario Binacchi --- (no changes since v2) Changes in v2: - Improve the commit message. drivers/net/can/slcan.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/net/can/slcan.c b/drivers/net/can/slcan.c index 9bbf8f363f58..82a42cec52d3 100644 --- a/drivers/net/can/slcan.c +++ b/drivers/net/can/slcan.c @@ -436,9 +436,20 @@ static int slcan_transmit_cmd(struct slcan *sl, const unsigned char *cmd) static int slc_close(struct net_device *dev) { struct slcan *sl = netdev_priv(dev); + int err; spin_lock_bh(&sl->lock); if (sl->tty) { + if (sl->can.bittiming.bitrate && + sl->can.bittiming.bitrate != -1) { + spin_unlock_bh(&sl->lock); + err = slcan_transmit_cmd(sl, "C\r"); + spin_lock_bh(&sl->lock); + if (err) + netdev_warn(dev, + "failed to send close command 'C\\r'\n"); + } + /* TTY discipline is running. */ clear_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags); } From patchwork Sun Jun 12 21:39:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2057 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 166D83F1DD for ; Sun, 12 Jun 2022 23:40:20 +0200 (CEST) Received: by mail-ed1-f72.google.com with SMTP id g8-20020a056402090800b00433940d207esf2981461edz.1 for ; Sun, 12 Jun 2022 14:40:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1655070020; cv=pass; d=google.com; s=arc-20160816; b=q8+A/977rc1tgBBfgRzKFgJiulol/zsnB2G3KypNLfjMRNpYJH+EPwP0Pc/DVvjuWM om2A71wXkC0fSlHTf6Lg2liW3KPXyTX32+cW/HJWn535HCr2AuSviQJGTORYYv1AFkWr G1QyqVA8WkYMb+utE28mDNDuKQhhMs5n8IarC2dWQZw2y1fmQmBIJoeKaxrfKA7fDYMy Oo0GcrAC9fEYnuxk4k6ehuBOQTWkBNsdwLvAVCzv1Wj3E0w41RVpCTSIiaux3MH2C/2C mjoRqNKYKotgGKB7n4chCx4aTOxsiFjFxFxhjBG17w3BsxnCD25nbz7CatOp0Zfne+cM k54A== 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=KkTio8KY8smKadcZAD04312fpzVr7gEcjG/2tHvlbTA=; b=064Ujt3yyooB2SXAx+uvxqaojvtFhQV4Y9FQKJpbDXXf3eyWLUKughiiXT6/6EFweQ CNlLosGPgKyAO0+xyuXTqI0PSMewbECKcydqljjtkfU3JREWT2zOtgElEwcuNKs+rfze hwyE6UwlKNwrgRGvMUZPzFrcjZ+sgvmzxPq/5MQmX6rqGt/b5ndNau0KimVNVXU9TZZG BLQL1OIB2puBW6ipwicIXMdAA1WHfETp/OZaResmsXl7h/M4CR2f72HGz2dTo1V5CC2b YvTn7jnhz35arjcYhWoepjhdrgbLFriMzX+huG0xaUsd9HSGcjjnqRnQeDToFi5TpCpx BJDg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=j683Ofaq; 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=KkTio8KY8smKadcZAD04312fpzVr7gEcjG/2tHvlbTA=; b=Ln1jPf2SpUn9e4gUVJNZbUYYNSr6rBYwCMXSctLjgbFBDnVto/Sde3h9pWwNX5628/ s8dscGrLj51tZ8gtRoyNnWOmV1SZ9QXsLOxjM5D2ADWCVSylgwu/sXNXcClEjeBFpI1F A3mNkPnnHfvca9glOX5vLIiGQk1bYWVgQRUjw= 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=KkTio8KY8smKadcZAD04312fpzVr7gEcjG/2tHvlbTA=; b=BgIBK0bUjeAUig1HPqNOx1RLTIyF3YRj69w3HjMfSUID/UfnJCBG4jZl3e66STdgCS 4PLP6RE/2OB70QMhnELrYFN8hVLrAiTNAon9Shol+rHFCk09YQsrOKpM+3oEbTHREAZ1 dzZ0WBqIDN0qPj556Y4nGjfMjRFYXM1zDa/etxZU1HRCXA7hEn8GYf2ASV4AK5MKyUMh 5FiAULNtXIP6U0uuQzsW3w/0bSHUwQbQkXIC3gNjuetvsQTMGJa3wQRMNqSdJTwaO8TF yOV+kjcVEL1UbDHI8XJTZpClzFChCf19Gbjd/qtnKP8Nuzz5dC24hPi8zGZ+GeVExmGP 8eIQ== X-Gm-Message-State: AOAM532SbRqdlg0kQgU5UyToPdMiYu2r1f1DrZWyBmZPLLExv4QBWPYU cFzdGXdCbG/9sHuv0maWt8SvqBDb X-Google-Smtp-Source: ABdhPJyGyv+ybdo8aAyOX1HRZJb6CBRzjMY7hAu/IuU8U/tw2IizJHA9234g8sDrESmtJ6o6+6QMqA== X-Received: by 2002:a05:6402:1386:b0:431:6911:a151 with SMTP id b6-20020a056402138600b004316911a151mr39285652edv.105.1655070019955; Sun, 12 Jun 2022 14:40:19 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:906:70cf:b0:6fe:d027:3c1f with SMTP id g15-20020a17090670cf00b006fed0273c1fls1009711ejk.2.gmail; Sun, 12 Jun 2022 14:40:19 -0700 (PDT) X-Received: by 2002:a17:906:804a:b0:70c:1dac:9bb8 with SMTP id x10-20020a170906804a00b0070c1dac9bb8mr47670120ejw.92.1655070018882; Sun, 12 Jun 2022 14:40:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655070018; cv=none; d=google.com; s=arc-20160816; b=FOE2PCZH8yNeIcoJhDlJdcKI1qzs22BIezlie79m2xIr2mOoqo/kzGL7toA/XaOG2x 9bewIGUbRdXlS2izF8EulTTLkq8Bda6bR6iIWhnVSAJ/I8+gl29ZD0M2xmrB+rqb2pPJ RALtt1mIueKunv+sr/qGbrp4mgZSD508bAHJfQF6IBG/1npiCWFQfwxgmeU8eVSfoFHT YOMr52mW4q0dy2wDFMyEJUbNWzDzhWF/QQDX6clnUhQDb7b13+gp+s09MV/3krqQ/fBF caIAyzadEivk3qm+qPhzJ7zzxJbXO4lB4pyZ17blg7rvb0+Mx4A1UkLqPJG8I6UbvrAd PpkA== 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=s1QllzXGCUo8JTE+hOZVBSnNVj6x3XTlbwu5/oui3J8=; b=pAR9IdlIQ2exqkGD14QLOo4MZbXmzPlTXN9DY6TlgV7o7SAoLMALJ9ckskmRAEkQEh +04QGfWOVJmpQyWfrolmF+teD6tSQkkv7xrVfY/AhPWlVZBWuNWi/JsZXwCUApLIXQzq eOE8Y+lxkS4mhgzKy3iKG6ZAQLdjIAYyYlBr/fbwk/95SuXdL90e8mGf18pntJ4vSKqs fCUSApwBB+fMuP1YPInrWSN2hX2rhwtrLl45s7bRvfzgQJENQaOX8CufiVzvsFkwi2tT D2sXkN6h7vQYh87XMdu2W+3IhLvG4hpkgzkfdOqJMFkT0tHzJE3DG49E4GgQZ2Gzxur0 jncg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=j683Ofaq; 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 v18-20020aa7d652000000b0042bcb9b1149sor1626329edr.6.2022.06.12.14.40.18 for (Google Transport Security); Sun, 12 Jun 2022 14:40:18 -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:aa7:c34d:0:b0:42d:ce57:5df2 with SMTP id j13-20020aa7c34d000000b0042dce575df2mr61797916edr.315.1655070018727; Sun, 12 Jun 2022 14:40:18 -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.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jun 2022 14:40:18 -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 10/13] can: slcan: move driver into separate sub directory Date: Sun, 12 Jun 2022 23:39:24 +0200 Message-Id: <20220612213927.3004444-11-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=j683Ofaq; 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 patch moves the slcan driver into a separate directory, a later patch will add more files. Signed-off-by: Dario Binacchi --- (no changes since v1) drivers/net/can/Makefile | 2 +- drivers/net/can/slcan/Makefile | 6 ++++++ drivers/net/can/{slcan.c => slcan/slcan-core.c} | 0 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 drivers/net/can/slcan/Makefile rename drivers/net/can/{slcan.c => slcan/slcan-core.c} (100%) diff --git a/drivers/net/can/Makefile b/drivers/net/can/Makefile index 0af85983634c..210354df273c 100644 --- a/drivers/net/can/Makefile +++ b/drivers/net/can/Makefile @@ -5,7 +5,7 @@ obj-$(CONFIG_CAN_VCAN) += vcan.o obj-$(CONFIG_CAN_VXCAN) += vxcan.o -obj-$(CONFIG_CAN_SLCAN) += slcan.o +obj-$(CONFIG_CAN_SLCAN) += slcan/ obj-y += dev/ obj-y += rcar/ diff --git a/drivers/net/can/slcan/Makefile b/drivers/net/can/slcan/Makefile new file mode 100644 index 000000000000..2e84f7bf7617 --- /dev/null +++ b/drivers/net/can/slcan/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_CAN_SLCAN) += slcan.o + +slcan-objs := +slcan-objs += slcan-core.o diff --git a/drivers/net/can/slcan.c b/drivers/net/can/slcan/slcan-core.c similarity index 100% rename from drivers/net/can/slcan.c rename to drivers/net/can/slcan/slcan-core.c From patchwork Sun Jun 12 21:39:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2058 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id CBE0D3F1DD for ; Sun, 12 Jun 2022 23:40:24 +0200 (CEST) Received: by mail-ed1-f69.google.com with SMTP id o2-20020a056402438200b00434ec3efc03sf921293edc.9 for ; Sun, 12 Jun 2022 14:40:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1655070024; cv=pass; d=google.com; s=arc-20160816; b=FTtQ/vKPDgAxgY/AgAclcE3xmm8/36jVDm/9nsBB/imklz12Ly14S9mebgwPexRNJn nZqcdK7naaq2Ze6ru3zrfMNms/YpLiBhrxQMrObgrndcnnI/bSdonb+Utdt5kxtsFa30 Zoth+rjcWvl8HLM5P5soGooj7jI33W8l2Z/2Z9kglvCu72IppsikX7RVbKZ6Vlg1A9rj Ezcijz+bFrKtvPmKxc00AorXZ2ETfj3MTXhSGv970mMrfwEIXJQp57LTWQee/EB42WhD ZUe7VWcFcHfuK/icJxFM/tISByN9uUWiK5IRKSfZcfUGF8jzszkb2qu1kDQu3gsriWwX yYWw== 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=8uOt1GeGNeWpFgZjq1jnARH8+Q5D0ILWmIf0yrCExAg=; b=vcwfIua+37YBUfFbM57XT8pHEj43rpoiTX6Bh5mnSVhVoO9s8m2xM6oQiHTmYnNQVG tmzjxDVQ0d//vCSc+pi7bZlNbt1YjZUmkteyNNKfGyIhCbqG/JUO7djP6BaDbKNoxfIm lYaPDZ6i7V/vDeLmBD8sS0qqAGbWuDqxf8DfW3n8G/v5NjjDmHsmj4N2/5w2n1wrJ+AW I5wlwf2pOxw/37IKfleIO9DadOuAr1S4BeQyoGFYnH3CZQbIQ5767waEPF9D5CC53jmv kbQ649WTqaHa/tD4HErp43EKoMV8qzYf1BRNMYY7s+B4fzudvO1OLAtj0ulwgsi9cNPh 84nw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=ZHd42I9X; 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=8uOt1GeGNeWpFgZjq1jnARH8+Q5D0ILWmIf0yrCExAg=; b=WFHnKfKU0C4lIP0siBY9H0syY013TI848OcDni039axkVQH6jz/3qgfcf5ZerBo9pV iLWj3uBJseHa5iE+qe89ryeV3Z0ncqTDcGpGh8thv9uVy/m2ex8Aihl0N113PaKuL6ni 42rJhbNqSNz7+6FS4KabACQd4W5OHPdVZ3cJw= 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=8uOt1GeGNeWpFgZjq1jnARH8+Q5D0ILWmIf0yrCExAg=; b=NwNUcmoZS6tJMvKKhUKI3qUHS0umJBP5orBqZgG4zWMwnkBM4GOgBYy7L0PLaBT7/F iOb5s/JOddrEXMGx5FUDhZI5UKCpN6fOpjXhF1LGl/72KcWOkerksebpPT7OvER5YjEX qHjVtAOeciYs1d0DVxugQcxaHvQNdJw/nxB37sv8wfnJG9bAdxLDdRuS31KIpKZ5jrxb Opuht7g2TyBeHU3qssI28zro+Hi9lxatRnrQASHPQozn9tWCKZk9Dni1obEkhMCby7f4 kG6PVRlAnQwIU1//pgrAMmMk1xIbtHTw193nlzHSXDoLX/Ne+XEbDAntgVyBZB/kiXfJ Xx8A== X-Gm-Message-State: AOAM532OKX+16krqff8G50yLRF92OLPq5c38CUk+shpY0cNDgYBYOyct c/2PdmckJgAKFtKFPOUTp443FoZ0 X-Google-Smtp-Source: ABdhPJzIRu1WjZhV52bGfF43IpHG9AMbcz0GKkMCB0vJ7+3nh8DC76aV8vJBGSUqXTbvTrAP+g+dlw== X-Received: by 2002:a05:6402:61a:b0:433:406a:8d25 with SMTP id n26-20020a056402061a00b00433406a8d25mr20056109edv.276.1655070024678; Sun, 12 Jun 2022 14:40:24 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:907:97c4:b0:711:d2c2:9fa4 with SMTP id js4-20020a17090797c400b00711d2c29fa4ls1011135ejc.9.gmail; Sun, 12 Jun 2022 14:40:23 -0700 (PDT) X-Received: by 2002:a17:907:2161:b0:70f:5db6:1ff2 with SMTP id rl1-20020a170907216100b0070f5db61ff2mr40894216ejb.249.1655070023714; Sun, 12 Jun 2022 14:40:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655070023; cv=none; d=google.com; s=arc-20160816; b=jjeC/EzWDN5xVhX+3Tnd04Zy5b+x948j/gf4CrSr0HP807BnPSfHXy3rjkK2lNKxDQ hSnX7hgLCDyg9/tUete4dnDiaCeBTioEsZQH1UmRd68qpooEhm7T2JIn5LxGNVdruFcS Un1b8a4v4bvJYCweSKiGSc3mRRjUB0MdjU6vCA0s6nhzoPVhBPE/h+UqynmyLMIXvIRQ ErmpJaQpYByp9LAdNQeCTPxMAzfq5FlLmtRkkJJRoLjwAx++LzBsXN0N8HFVsy6Rfrm3 Qlly5b8rn8c2M8uTrn++FlKMZqyQFkDnBOAxfIgKv//UUPYv2BCZVbdPGglCpLgDT66H pbZw== 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=z9lGb6dxRaekyRJ4swSwg3PwLJAGarCfZ2Xmy0z62Lo=; b=fM9/ghzX0FU8z5JP2sXIByLn6/GjbwHCTrZaXfrx6RSMeSCts/j42g28SWz7qgtH1+ dhsyg92x32a6cNJUL/ROlSzRCYB72DqMpTT87HkcVpSD66rHNcBd9e4I2hY0lVaguXsK yA+3pkxVGPYSKi1MUTdoPmtRFIMammcnYKWSYQZiyOBCfmMCdu8GWL+0lv/XGoftCBYy JIMibQFa1+5BChCHKyWuKAejPcUKLgnZdcq2iKmcfeXzuZJtaTP2VjQ5aicZtpBX7aH6 h/UqbXCwsU4i+ngLkaokL1Dx8P0A57ydLbgMokpzZR5TptKQemT9DaPqWiyLagZQR1G5 N2uA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=ZHd42I9X; 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 r5-20020a508d85000000b00425e6e44fe7sor1620847edh.2.2022.06.12.14.40.23 for (Google Transport Security); Sun, 12 Jun 2022 14:40:23 -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:a05:6402:51d4:b0:42f:b38d:dbb9 with SMTP id r20-20020a05640251d400b0042fb38ddbb9mr51327514edd.255.1655070023483; Sun, 12 Jun 2022 14:40:23 -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.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jun 2022 14:40:23 -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 11/13] can: slcan: add ethtool support to reset adapter errors Date: Sun, 12 Jun 2022 23:39:25 +0200 Message-Id: <20220612213927.3004444-12-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=ZHd42I9X; 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 patch adds a private flag to the slcan driver to switch the "err-rst-on-open" setting on and off. "err-rst-on-open" on - Reset error states on opening command "err-rst-on-open" off - Don't reset error states on opening command (default) The setting can only be changed if the interface is down: ip link set dev can0 down ethtool --set-priv-flags can0 err-rst-on-open {off|on} ip link set dev can0 up Signed-off-by: Dario Binacchi --- (no changes since v1) drivers/net/can/slcan/Makefile | 1 + drivers/net/can/slcan/slcan-core.c | 36 +++++++++++++++ drivers/net/can/slcan/slcan-ethtool.c | 65 +++++++++++++++++++++++++++ drivers/net/can/slcan/slcan.h | 18 ++++++++ 4 files changed, 120 insertions(+) create mode 100644 drivers/net/can/slcan/slcan-ethtool.c create mode 100644 drivers/net/can/slcan/slcan.h diff --git a/drivers/net/can/slcan/Makefile b/drivers/net/can/slcan/Makefile index 2e84f7bf7617..8a88e484ee21 100644 --- a/drivers/net/can/slcan/Makefile +++ b/drivers/net/can/slcan/Makefile @@ -4,3 +4,4 @@ obj-$(CONFIG_CAN_SLCAN) += slcan.o slcan-objs := slcan-objs += slcan-core.o +slcan-objs += slcan-ethtool.o diff --git a/drivers/net/can/slcan/slcan-core.c b/drivers/net/can/slcan/slcan-core.c index 82a42cec52d3..3df35ae8f040 100644 --- a/drivers/net/can/slcan/slcan-core.c +++ b/drivers/net/can/slcan/slcan-core.c @@ -57,6 +57,8 @@ #include #include +#include "slcan.h" + MODULE_ALIAS_LDISC(N_SLCAN); MODULE_DESCRIPTION("serial line CAN interface"); MODULE_LICENSE("GPL"); @@ -98,6 +100,8 @@ struct slcan { #define SLF_INUSE 0 /* Channel in use */ #define SLF_ERROR 1 /* Parity, etc. error */ #define SLF_XCMD 2 /* Command transmission */ + unsigned long cmd_flags; /* Command flags */ +#define CF_ERR_RST 0 /* Reset errors on open */ wait_queue_head_t xcmd_wait; /* Wait queue for commands */ /* transmission */ }; @@ -110,6 +114,28 @@ static const u32 slcan_bitrate_const[] = { 250000, 500000, 800000, 1000000 }; +bool slcan_err_rst_on_open(struct net_device *ndev) +{ + struct slcan *sl = netdev_priv(ndev); + + return !!test_bit(CF_ERR_RST, &sl->cmd_flags); +} + +int slcan_enable_err_rst_on_open(struct net_device *ndev, bool on) +{ + struct slcan *sl = netdev_priv(ndev); + + if (netif_running(ndev)) + return -EBUSY; + + if (on) + set_bit(CF_ERR_RST, &sl->cmd_flags); + else + clear_bit(CF_ERR_RST, &sl->cmd_flags); + + return 0; +} + /************************************************************************ * SLCAN ENCAPSULATION FORMAT * ************************************************************************/ @@ -509,6 +535,15 @@ static int slc_open(struct net_device *dev) goto cmd_transmit_failed; } + if (test_bit(CF_ERR_RST, &sl->cmd_flags)) { + err = slcan_transmit_cmd(sl, "F\r"); + if (err) { + netdev_err(dev, + "failed to send error command 'F\\r'\n"); + goto cmd_transmit_failed; + } + } + err = slcan_transmit_cmd(sl, "O\r"); if (err) { netdev_err(dev, "failed to send open command 'O\\r'\n"); @@ -629,6 +664,7 @@ static struct slcan *slc_alloc(void) snprintf(dev->name, sizeof(dev->name), "slcan%d", i); dev->netdev_ops = &slc_netdev_ops; dev->base_addr = i; + slcan_set_ethtool_ops(dev); sl = netdev_priv(dev); /* Initialize channel control data */ diff --git a/drivers/net/can/slcan/slcan-ethtool.c b/drivers/net/can/slcan/slcan-ethtool.c new file mode 100644 index 000000000000..bf0afdc4e49d --- /dev/null +++ b/drivers/net/can/slcan/slcan-ethtool.c @@ -0,0 +1,65 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* Copyright (c) 2022 Amarula Solutions, Dario Binacchi + * + */ + +#include +#include +#include +#include +#include + +#include "slcan.h" + +static const char slcan_priv_flags_strings[][ETH_GSTRING_LEN] = { +#define SLCAN_PRIV_FLAGS_ERR_RST_ON_OPEN BIT(0) + "err-rst-on-open", +}; + +static void slcan_get_strings(struct net_device *ndev, u32 stringset, u8 *data) +{ + switch (stringset) { + case ETH_SS_PRIV_FLAGS: + memcpy(data, slcan_priv_flags_strings, + sizeof(slcan_priv_flags_strings)); + } +} + +static u32 slcan_get_priv_flags(struct net_device *ndev) +{ + u32 flags = 0; + + if (slcan_err_rst_on_open(ndev)) + flags |= SLCAN_PRIV_FLAGS_ERR_RST_ON_OPEN; + + return flags; +} + +static int slcan_set_priv_flags(struct net_device *ndev, u32 flags) +{ + bool err_rst_op_open = !!(flags & SLCAN_PRIV_FLAGS_ERR_RST_ON_OPEN); + + return slcan_enable_err_rst_on_open(ndev, err_rst_op_open); +} + +static int slcan_get_sset_count(struct net_device *netdev, int sset) +{ + switch (sset) { + case ETH_SS_PRIV_FLAGS: + return ARRAY_SIZE(slcan_priv_flags_strings); + default: + return -EOPNOTSUPP; + } +} + +static const struct ethtool_ops slcan_ethtool_ops = { + .get_strings = slcan_get_strings, + .get_priv_flags = slcan_get_priv_flags, + .set_priv_flags = slcan_set_priv_flags, + .get_sset_count = slcan_get_sset_count, +}; + +void slcan_set_ethtool_ops(struct net_device *netdev) +{ + netdev->ethtool_ops = &slcan_ethtool_ops; +} diff --git a/drivers/net/can/slcan/slcan.h b/drivers/net/can/slcan/slcan.h new file mode 100644 index 000000000000..d463c8d99e22 --- /dev/null +++ b/drivers/net/can/slcan/slcan.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 + * slcan.h - serial line CAN interface driver + * + * Copyright (C) Laurence Culhane + * Copyright (C) Fred N. van Kempen + * Copyright (C) Oliver Hartkopp + * Copyright (C) 2022 Amarula Solutions, Dario Binacchi + * + */ + +#ifndef _SLCAN_H +#define _SLCAN_H + +bool slcan_err_rst_on_open(struct net_device *ndev); +int slcan_enable_err_rst_on_open(struct net_device *ndev, bool on); +void slcan_set_ethtool_ops(struct net_device *ndev); + +#endif /* _SLCAN_H */ From patchwork Sun Jun 12 21:39:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2059 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id B0E0B3F1DD for ; Sun, 12 Jun 2022 23:40:29 +0200 (CEST) Received: by mail-ed1-f71.google.com with SMTP id y4-20020aa7ccc4000000b0042df06d83bcsf2923436edt.22 for ; Sun, 12 Jun 2022 14:40:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1655070029; cv=pass; d=google.com; s=arc-20160816; b=sWUVDaOx/wTqREkQFrMXWMioXQQn9Kg2r0tcYTwZFYwSvTUjbJYyEE5hbZ5YtsMPS8 sOZ4Q1Q+Y7ljYT1SpOMLsIxujzPzFvtWULUvq+qDvMxmolGwfh209LEThZ27IUv1KbiY ujPjYQIDHJhHYx9kkjmcoh8XC0nWPJwd1+Io/71U1aoJ3ZJQdXdNGAMsjwzzUMeZCmCh jPDTLPVpwHPNogYX94Np0nTnlWlzpIQXAR6Vflzmq+7wA+Cn+QX5NAe9UkaT2dx/j9jW FPOxGXJsKAlD7bSvnkew+WCfbw8rs+3vx0vHqtcu+QFo+CFMzA7q+5HGInQSk9V4KbZu 1H5w== 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=gA0itNrtugfzLr6oO/Oe+F6wnAcraRj5HkG6Jbfjo0o=; b=W6KGxZeFN3OmZRcKaSYKO/8YOma177WiZZ5pAls1Pq224Vz+4t3cik/G9cko+fVMrE xLXzPe/W+FPSw/vRuN5BOO2G834q45GiLTb3O3wDeiyT8cIR63EQPOmfHy+3DG9CHpem 1mpFSHdyEOO1t/DmhK5N6Oh7qmpSfvxBtMQAYbQU+jDpVxKes8FtOwyMKICHLmGiUOsN nhp4Gf6Y/BIQBsic/ntIYDL6fGSVnX3m2fos+rDDfauMap1nG5Ub83Y2ZI7eMmESLlKk xnrqnZCrJ2z62wW/2bnetS8PvzQRm0eLDpN/w3EE/yPiNFFFD9Dr3Jatl0c9Ol5yFSK9 rhPw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=qYQO15I8; 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=gA0itNrtugfzLr6oO/Oe+F6wnAcraRj5HkG6Jbfjo0o=; b=VbeQalqaujUkCqEej6OueAO/48hBZnCnBuAltxSlkJifQtOPKEhmS/p2eXmNRR1f9h laHrnNqH99JV1xL3jB98K8MVXFATA2iFsaMVsBTN1obPPtPtJR/tQsRXp8xMOtb0UfXk srG4sN6whdyOoQEqVb6NGkgTLd1uV0sGO2EnQ= 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=gA0itNrtugfzLr6oO/Oe+F6wnAcraRj5HkG6Jbfjo0o=; b=Qwi5o5hlvRRovg1TpWi3jX1yZNahERx7m9mDhuUnBCUdncbh2GXZuPg6cC+Ddkki6/ H7sJUMY4GboS0oqkb0g5aa3zerI5g0vVHm+jmLd+c192rja/yCOIGgCpMobp59tlM1v3 kUQ9a5k1g4hVNfNwFfo4cM8m32GjdX4aH5i53lxnE3OAZq4hd8oVyPHPnmGwokGGoOoo /JGbdR0SCFdM9dB6djBzNBaXExQZ8dNaHl0Pt35/mtMiC8IMR1RV+p97loX+FDVS+Aoc DUQGJJl1Q7vWugIGXX344mBZqjcfcR0LA2+nB3pdB0zGgANBxXB4dvZIT66O+8OjWDAK 4Siw== X-Gm-Message-State: AOAM530oL9EIk91oEB+X7nxY4AO6ONIgq3Z8wFlILXmzevVw6JPtR4a6 0wF4fLJ6u+pLGYlqn1a1DhDZm0XL X-Google-Smtp-Source: ABdhPJxU3YmCRaO9/siU/fAib1rPqhZB1MkmH2A0cdXz67su+QyioJNrU/1//a9AOQ9N7QUMtLKsBA== X-Received: by 2002:a05:6402:518b:b0:42d:fe74:98f9 with SMTP id q11-20020a056402518b00b0042dfe7498f9mr62299253edd.371.1655070029583; Sun, 12 Jun 2022 14:40:29 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:907:d1c:b0:70e:611f:3585 with SMTP id gn28-20020a1709070d1c00b0070e611f3585ls1010213ejc.8.gmail; Sun, 12 Jun 2022 14:40:28 -0700 (PDT) X-Received: by 2002:a17:906:7742:b0:708:ad9f:8e88 with SMTP id o2-20020a170906774200b00708ad9f8e88mr28058576ejn.735.1655070028487; Sun, 12 Jun 2022 14:40:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655070028; cv=none; d=google.com; s=arc-20160816; b=y8Vqeq3Poo5XzEwHWvQ6QygpvvW7CzmK7ioJyx6iOuVZ8lPSEHM8lf7uI/NVilcDJ/ j0R+36noagO0YIpwptVuw9vJTnL79aE/Hfvky0ptb8mj7/D+w7LpE5MfHvkNWGgje+Mv TwsXLB0OZ5zx0EjmpQLai0tfL39Z+4S8JxwQ8GSDM+wJgrNBunAx2Se+OUF8kfe7aalO a5iMWRGnQETcsh3LzOgtrZGNfWdt5cH7uI+bf6A5W5zMo4RsSNMso4UsgdaYC852H4pO 1cM6PLWFubecWvU70Inb7r207DA68bFLAtuxQNb1KS3V8rvOFxX26sajYtTJHUNViiVA 0+0A== 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=P8N6mZ+VdIxDHB3ERFZNuvKgcE/qcXFBtcxLWjsi6yU=; b=yWFjQQGMXBzNx9M5+zwZxBLl22oz8QXMUCVXiiYQhqNisV5MarCdd9QjRnKGm//Xw0 ZWCOWsx7yl3IXWSjd/JTer6H2p5EWtG1FbxMym/KZ0ixMUkza0EunpxkttnTYX34Ef+f EKYJH+PUX/D/RNvA0WIQp0NZ4d7+yXzsdlTyJ0eimrmjYuv4JKIwv++iaF5LQoAvgEYa IswCii3nwg21tNdVnmlYa5DmsId42z6RR+eo//pRQ+8py0dnRSN7s5OKmTUpcyE5Q/Qa mZb5+USENtIBAUXDC5HPyIeF3L+t2JSIDdvh4Fx3U3m9c+txqwD9SS1voOwc0X6Iybee Jhlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=qYQO15I8; 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 w13-20020a1709061f0d00b006ff8320841dsor1351331ejj.92.2022.06.12.14.40.28 for (Google Transport Security); Sun, 12 Jun 2022 14:40:28 -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:6947:b0:711:a86b:6780 with SMTP id c7-20020a170906694700b00711a86b6780mr37988734ejs.686.1655070028311; Sun, 12 Jun 2022 14:40:28 -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.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jun 2022 14:40:27 -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 12/13] can: slcan: extend the protocol with error info Date: Sun, 12 Jun 2022 23:39:26 +0200 Message-Id: <20220612213927.3004444-13-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=qYQO15I8; 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 communication errors and forward them to the netdev upper levels. Signed-off-by: Dario Binacchi --- (no changes since v2) Changes in v2: - Protect decoding against the case the len value is longer than the received data. - Continue error handling even if no skb can be allocated. drivers/net/can/slcan/slcan-core.c | 130 ++++++++++++++++++++++++++++- 1 file changed, 129 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/slcan/slcan-core.c b/drivers/net/can/slcan/slcan-core.c index 3df35ae8f040..48077edb9497 100644 --- a/drivers/net/can/slcan/slcan-core.c +++ b/drivers/net/can/slcan/slcan-core.c @@ -175,8 +175,118 @@ int slcan_enable_err_rst_on_open(struct net_device *ndev, bool on) * STANDARD SLCAN DECAPSULATION * ************************************************************************/ +static void slc_bump_err(struct slcan *sl) +{ + struct net_device *dev = sl->dev; + struct sk_buff *skb; + struct can_frame *cf; + char *cmd = sl->rbuff; + bool rx_errors = false, tx_errors = false; + int i, len; + + if (*cmd != 'e') + return; + + cmd += SLC_CMD_LEN; + /* get len from sanitized ASCII value */ + len = *cmd++; + if (len >= '0' && len < '9') + len -= '0'; + else + return; + + skb = alloc_can_err_skb(dev, &cf); + + if (skb) + cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR; + + for (i = 0; i < len; i++, cmd++) { + switch (*cmd) { + case 'a': + netdev_dbg(dev, "ACK error\n"); + tx_errors = true; + if (skb) { + cf->can_id |= CAN_ERR_ACK; + cf->data[3] = CAN_ERR_PROT_LOC_ACK; + } + + break; + case 'b': + netdev_dbg(dev, "Bit0 error\n"); + tx_errors = true; + if (skb) + cf->data[2] |= CAN_ERR_PROT_BIT0; + + break; + case 'B': + netdev_dbg(dev, "Bit1 error\n"); + tx_errors = true; + if (skb) + cf->data[2] |= CAN_ERR_PROT_BIT1; + + break; + case 'c': + netdev_dbg(dev, "CRC error\n"); + rx_errors = true; + if (skb) { + cf->data[2] |= CAN_ERR_PROT_BIT; + cf->data[3] = CAN_ERR_PROT_LOC_CRC_SEQ; + } + + break; + case 'f': + netdev_dbg(dev, "Form Error\n"); + rx_errors = true; + if (skb) + cf->data[2] |= CAN_ERR_PROT_FORM; + + break; + case 'o': + netdev_dbg(dev, "Rx overrun error\n"); + dev->stats.rx_over_errors++; + dev->stats.rx_errors++; + if (skb) { + cf->can_id |= CAN_ERR_CRTL; + cf->data[1] = CAN_ERR_CRTL_RX_OVERFLOW; + } + + break; + case 'O': + netdev_dbg(dev, "Tx overrun error\n"); + dev->stats.tx_errors++; + if (skb) { + cf->can_id |= CAN_ERR_CRTL; + cf->data[1] = CAN_ERR_CRTL_TX_OVERFLOW; + } + + break; + case 's': + netdev_dbg(dev, "Stuff error\n"); + rx_errors = true; + if (skb) + cf->data[2] |= CAN_ERR_PROT_STUFF; + + break; + default: + if (skb) + dev_kfree_skb(skb); + + return; + } + } + + if (rx_errors) + dev->stats.rx_errors++; + + if (tx_errors) + dev->stats.tx_errors++; + + if (skb) + netif_rx(skb); +} + /* Send one completely decapsulated can_frame to the network layer */ -static void slc_bump(struct slcan *sl) +static void slc_bump_frame(struct slcan *sl) { struct sk_buff *skb; struct can_frame *cf; @@ -255,6 +365,24 @@ static void slc_bump(struct slcan *sl) dev_kfree_skb(skb); } +static void slc_bump(struct slcan *sl) +{ + switch (sl->rbuff[0]) { + case 'r': + fallthrough; + case 't': + fallthrough; + case 'R': + fallthrough; + case 'T': + return slc_bump_frame(sl); + case 'e': + return slc_bump_err(sl); + default: + return; + } +} + /* parse tty input stream */ static void slcan_unesc(struct slcan *sl, unsigned char s) { 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; }