From patchwork Tue Jun 14 12:28:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2066 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 432593F03E for ; Tue, 14 Jun 2022 14:28:29 +0200 (CEST) Received: by mail-ej1-f69.google.com with SMTP id kf3-20020a17090776c300b0070d149300e9sf2800675ejc.15 for ; Tue, 14 Jun 2022 05:28:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1655209709; cv=pass; d=google.com; s=arc-20160816; b=dGTRz2mnmJYMLzWBF5YGkVElcFRa+p6SdUpuH0Y7xK/ygC4Cy95ZhUH1uN1EkLm7Ux BGnhlh2HbNcW//8nIe6hWRWEXu5HEvwebRvUqf2FiRR6UegJPZxAz50K6uZ2BpOUTSzd sDKJ07VQ0jbCFFPsRouEdxR2kga58LdypFcfYk+ZrP5yf2rxnElyFDtgjn6zg+5NKcJX O4LLkjsQv+jNvaF0Fuia6FpSUkDmSTnz6xxx5qbzJqVP67VRTs5s/zJKFzmarWYtFR+f pp7288GOuRzAbgE7NaYCR+IyQVDM9UjsOJtcZGteMbw+F/JRe2hj9+Vb+IU8sqeJ/E9u n+mw== 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=i2YBhgUxS8rVIZ61klw0YFRA2WlryU3s2v0tkfVh9hc8JWl3QY+Xeh0hlqjFI2efFJ 4Yqjl3xt7SbRhKqKyMt4uTM32V0XkzSLHrrKco5/1Pw1ZkO/bf9FPz5E9JUlZDaWzE8w h/FbQO2GkcTjb8zURFAHbgi8MYwcozGsHSoxSiOWpiP7eMG5dbKW37wnt6fFOTIBWIDo 9JAbiF3SBKQ+EhPhYw5PP160iLydsZhnmbgg6Gc2yGouo2KPyJNjMiYnwiqyfueRQoRR pxLE2Ijfezd6IdJr6nhP/8iPDcrNtXbj9zOqhKQ+l4gcPjoto0MqYGAy/orjEJJRID/1 xUZw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=c010hK3+; 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=L6KLRtaGWTC3VLHb/fRlRcZcPTLK4LYzb+t+30bNVwAnDBZPO7NNGzJ81e9uuZs3uw pBTmrz89hxTGZ0WyJopdCqUYLlu1s8emQ5LeReNyksnDdur3+OuwrFv+UqTst7CwviBP C5x2Fmj/dn+5ERn9mXCOSRg2YlsLx7VQDE8tc= 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=dLoh5d+3TYAw2YMleNNvIfOj3B82Tk1lcRjRN7Au2su9+t6ChxlXD3ebVE6Qq1mhOW igoMasbCFJ4GjCr2PByTcNJrucGNzoaw/M3iFfyABpEsEMAx+X+kLmcJORE5N+tg3Okh x9YtiC6Nawk7zcUKvn73CKkRJx0jSPRq2vmHeV1IR84nw8Y8vmG934BeYofRLeBOWVFg NJulNLBSVcjFomaJfK/oGrbUjeMEf6nVXHMFvZiL8AjmWtmdASClNDsYlQTnP67DonYw 9KbICT1GVhfQ2nFDSYsK2nl7/dzkWufXXvPybdGlYE2GoDUtOvtRQ2c5QL766zKEeFMp hLOw== X-Gm-Message-State: AOAM530klE0aJI0Ug8BK/pg4hgzwdeFSw934bnOCFabQdthn4EftMCVf 0mMN8FcsaHmLLcDcSMg1WYNIRdmA X-Google-Smtp-Source: ABdhPJzMEXjhQzP29AOeWVMjOdT115zUtWDRBl9anGlpfdUL4TtiWN779zbjMyCkBtcmIgUY0/BN5A== X-Received: by 2002:aa7:d295:0:b0:42d:e371:ded2 with SMTP id w21-20020aa7d295000000b0042de371ded2mr5853223edq.336.1655209708971; Tue, 14 Jun 2022 05:28:28 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:51d1:b0:434:ff40:ca1f with SMTP id r17-20020a05640251d100b00434ff40ca1fls2367997edd.2.gmail; Tue, 14 Jun 2022 05:28:28 -0700 (PDT) X-Received: by 2002:aa7:da10:0:b0:42d:d47e:87ad with SMTP id r16-20020aa7da10000000b0042dd47e87admr6008286eds.161.1655209707838; Tue, 14 Jun 2022 05:28:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655209707; cv=none; d=google.com; s=arc-20160816; b=sdoxDgODx9cZ/8igeaRsjnq7jiDnrcWycNqMclrKNkJ4BHdwKECXhIbcx9RKasVk8g 3aNhipluHqaPukP2UnyuwKu70AAarbBX5oTZ79OwTI59s1RV9Nc01DxZRh4L8d1vqKyz 1LVtTx//U9WEU9eDDP9Ynp362ePeLRJD0KD/GBN6M6dcxCXLRg9RRdNB4vYQ4FYkJxzu HFBqU/EUVQ4O20tQ/sk/fBXuESMNfaGxwSyi227Y9q5dOP32/o7dopyFHBQ3UeW9w9AF XDu15+GPYEe/J4INGtGss/JvFoa9rf7y1pOa5giFXLFwixZK0dClKB8mNPhexC2UPkjY 1rOg== 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=uYCWsnnK+hcPLrod2XVXcqDWjeYYcRRDxzSUAKNkgs/1e217y8kE2PUm4s5QIhFEFU oTcCzLqSoOUg3TBxYgROCTZBburzwGrUALl09/F8zYjpy7cvVbwg8Kaa3KjL5H1Ir9M7 mIN1gFLmMI8pLxbJh8B8wc/El0YoKVK5ORrEYPg2Ain/djoGHI5pFEChxTDL3Hy3k+Oe NNvNznhuOnFA7EFmZ6YPirzNy6Jimr1+nyOleDvvgO5JAwwpJjJ48JVBfpvYsYHXMp3N D3qlU/cs2I/4GGVjy0EnksGaDH4xGerq12UK3fPmj19Hkh1gx9cBuiRGHZ0NJQgedmX7 SWDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=c010hK3+; 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 25-20020a170906319900b00707ab1f34ccsor3246224ejy.111.2022.06.14.05.28.27 for (Google Transport Security); Tue, 14 Jun 2022 05:28:27 -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:1c07:b0:711:c966:f02e with SMTP id nc7-20020a1709071c0700b00711c966f02emr4194683ejc.221.1655209707627; Tue, 14 Jun 2022 05:28:27 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.amarulasolutions.com (host-80-116-90-174.pool80116.interbusiness.it. [80.116.90.174]) by smtp.gmail.com with ESMTPSA id z22-20020a17090655d600b006f3ef214e2csm5087043ejp.146.2022.06.14.05.28.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jun 2022 05:28:27 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: Amarula patchwork , Oliver Hartkopp , michael@amarulasolutions.com, Dario Binacchi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Marc Kleine-Budde , Paolo Abeni , Wolfgang Grandegger , linux-can@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v4 01/12] can: slcan: use the BIT() helper Date: Tue, 14 Jun 2022 14:28:10 +0200 Message-Id: <20220614122821.3646071-2-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220614122821.3646071-1-dario.binacchi@amarulasolutions.com> References: <20220614122821.3646071-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=c010hK3+; 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 Tue Jun 14 12:28:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2067 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 5C9F83F03E for ; Tue, 14 Jun 2022 14:28:30 +0200 (CEST) Received: by mail-ed1-f72.google.com with SMTP id y13-20020a056402358d00b0042dfb820070sf6075154edc.6 for ; Tue, 14 Jun 2022 05:28:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1655209710; cv=pass; d=google.com; s=arc-20160816; b=nxtwBwi8ukMey56ibou8QT5Lk+/WVBvY0evIgaQBHSJyk7/4U3Nc/Evn0Tie2ZcGT3 4z5DHqD3QpJIXB4eOIrry5v+o7indv1rJFsZf4CFUO9hhwsG3YosJSloJ6V5oQcv5XWw G+AjnnHgmtK4Uit3j3v30e+PE+Bx0JZC+7BZkbswmfZqPeqYl2yyaIuIjQqtKUd9M8Th PD0asH6TQWmdI9JjVRDQCzkthtLQN3s/7yNRgYHIvXYc8h8Rx7mM0GOBwfayhpkvfz6y hVGuIaggavUiRTcz3ql1VbAeuOEf7JgzHZr/fcAjCDzxIXva9Mh3Pm6v0gB4ylObQza6 /QYQ== 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=gB9I0tDTSM6eNBjUaEXtPTvkVfqAf14xGEeLnDLQujQY9ffDdn7QmbC5DcsSF1FtO+ vSI7KqyYGHSMAyItIhmXeKsHiSDirFnqtw9t9+hNOU1JT23l0f02TlafhsQkO2g3TS6M DW4pZrYEJG+UTW78i2OHWt3wAQjw7gjhbUIVNfM02JcwpGARkh0tlgT0pxGMOeQitQYv D/BBr2NYvzwITtEM7DaekNb2qPdjItN+Q+xn5cPF2PBX3Fuj9p7q1cRlDlqeRI/TyyDa oVacqB4NE8WgeDI3cngHMYzguvmU6TA9eVyji4n4ViHY79HagVJrD60toUss6BAk2dUS JkRg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="BiAOyZ/X"; 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=GIooCdkJOkSiwjLX9XO4u+iCNMhqMdEAOn+ZI7mlikRoRopOnsLJospjF72AN4h4uU DkvnyEVhavVKUGUUlo94zjLsVdHPEyG0/PMBRZDf+56B8syqfNa5wRI6ZfuNpsPXV7vi nNTJVmh8U5QAl3AbvvEnNyW8l+OxOeN8BtrsE= 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=SlytFMBLu0TE4vn54CP//aRiMlhkTePnGMP3v0S8I8jX1zCw2K6wVcUwny/gGMDkVY iozfS6inIAihEqgROxL99xjPtvT3H/MEto7bO8GhfL2C1nrDgDX0ApBDiFMZcOsB8yc4 zQAgdfBBK1H1wB7Kzvn7iLHIpAonHkYM+n0VheS2A1rxMXYmCDqNyqaj78kLH6pXDGrN qfd7T/luhXb9uH+qoF9t4bCXlav7YR/pOY3qLuaW9bi1HgdWFoqNGle6Mlj+A0hAPO6v 6wzX47klOOJ+KLZO4S27kaWf4aBvqc+rr/8ZMp7xG1yslrH4TufJGrdlSNRvV052VQiE uzcA== X-Gm-Message-State: AJIora+HWVo7QwsxiOfxK76v6bxJOlRKn4g1busQInH7pqF7jdMZfkgm 6ygb8DXzdtUdVcBSaMwq8fCcqYuO X-Google-Smtp-Source: ABdhPJw2BTr3czZyNZ+NNRRvsBQai8EAWALzYY45u9bmAxuuIf8g9cUKvlx6iftnPKS7cQ/4Zhdl3g== X-Received: by 2002:a17:907:2da6:b0:711:d86d:ccab with SMTP id gt38-20020a1709072da600b00711d86dccabmr4087720ejc.356.1655209710159; Tue, 14 Jun 2022 05:28:30 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:907:9705:b0:70d:ff46:7086 with SMTP id jg5-20020a170907970500b0070dff467086ls991852ejc.4.gmail; Tue, 14 Jun 2022 05:28:29 -0700 (PDT) X-Received: by 2002:a17:906:1501:b0:715:76d0:862a with SMTP id b1-20020a170906150100b0071576d0862amr4046052ejd.681.1655209709184; Tue, 14 Jun 2022 05:28:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655209709; cv=none; d=google.com; s=arc-20160816; b=VHXMwnpaArs4LVOj9zuDBU1NUACwg6nWKOymAYxljWyOLciFyTDgJ9cnijPq+hIK5w McPuZ70WmCHZX0pU8XPPP8QGN/15UKaWhb2guxjmz3VqnHfZyFbBd+av7n6mCiqVQfTq kJymi1SchPdUpR+r9KNOLhOCYapaMj2t/yGNowpABnaz4sqDLcOKcLNcPVYOHc0D+8tI H44AG55Xr0yfCEfP4W/mfhsLHmG2TzKhWnF4dvo6WsYa/fICsh0iMqwmR81BhVQcWa71 CIlyH/tYGdzJvzI5DA2wggz7oJtNzsayEnbLnX7gkTBYFe7lT1I71dbdrPyCKqwi+MIQ pbhA== 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=XQs67j0S9JB22pYA+kqSYhy8Bk7BMoptfaJaG5ngEuOZpdSWWdJanLsa7plfUW6VAw kxJomYGY+GW9NdTlODJCFQJ+FbbnfFQGmQpUJWCIaTt3+Xf6V2bFRMNPqVooZoUirltH tgu1juIpxIfiKSlucsImNlhzk+EzxFhSJwwSnpEgSvRjs0kBwdqhbo98CPyLdVyYEXlC yPdVKvUJ/nEIRveefAtjXbdNg3JGNuh35ybeHyaWYDKqRLPEpwLceuEZqAyvga0NdGa+ UW9Nuz1qAhqasez0JXSMxX/GNzE17okOKeiO6Zz3zNtTMU6UVwNCmPY++p9m+fGpkjX3 XZ/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="BiAOyZ/X"; 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 ev13-20020a056402540d00b00434f082ea97sor2944953edb.36.2022.06.14.05.28.29 for (Google Transport Security); Tue, 14 Jun 2022 05:28:29 -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:100c:b0:42d:f407:b050 with SMTP id c12-20020a056402100c00b0042df407b050mr5652088edu.39.1655209708968; Tue, 14 Jun 2022 05:28:28 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.amarulasolutions.com (host-80-116-90-174.pool80116.interbusiness.it. [80.116.90.174]) by smtp.gmail.com with ESMTPSA id z22-20020a17090655d600b006f3ef214e2csm5087043ejp.146.2022.06.14.05.28.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jun 2022 05:28:28 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: Amarula patchwork , Oliver Hartkopp , michael@amarulasolutions.com, Dario Binacchi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Marc Kleine-Budde , Paolo Abeni , Wolfgang Grandegger , linux-can@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v4 02/12] can: slcan: use netdev helpers to print out messages Date: Tue, 14 Jun 2022 14:28:11 +0200 Message-Id: <20220614122821.3646071-3-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220614122821.3646071-1-dario.binacchi@amarulasolutions.com> References: <20220614122821.3646071-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="BiAOyZ/X"; 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 Tue Jun 14 12:28:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2068 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 CF3233F03E for ; Tue, 14 Jun 2022 14:28:31 +0200 (CEST) Received: by mail-ed1-f71.google.com with SMTP id a4-20020a056402168400b0042dc5b94da6sf6063992edv.10 for ; Tue, 14 Jun 2022 05:28:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1655209711; cv=pass; d=google.com; s=arc-20160816; b=pSr3pTbrBGHhQJBCJleJGbcq/6nXV1zgaTQzE1ImMXx+oyXnQ2tFg33B/ldGEBCZIS pBYwo8A449RZ64m3fMC8xiPcoeWI7dNH2racqM+wgjironxZxyfCsM9vOtNYAOKP8kc8 4aqq1VX3uG26hIFqntDMXuUVXGQQCYlzu72xHFwUKMkUwv6d5o2qUXuoR9mSgdoF/JPL QZFsVtZQW84tUamTa9F4Es6hZ3OtSmTPFCt/AwVi33Ssoivs7fZL9RiXgFMFlAtqErft 3F9xv0TFlZDy9DirOXNTeV3RMR0ixarGAj+FdwF2DicddIg9eVKBYn8OjuVz6uLoXaWn zTqQ== 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=B5BRL75Rqq/QsX4g5ZP6nUrszmkaYEUGj4R6g8/lDX0=; b=yH9kSPFKLs1FsxzSioDDIt7i3UfQfsCn3AAuHusPf5nDduvAm9pqkZcOHL8ERvvs2L Bn9LTX3Sreg0LhluNTjtthlVDHlH8fsIKucDeXrz/q3khZXD8tdaLCM38HmYC9TZ82FU TQOfsbLNpX/MbwMCVNP/J0G5qS7iD2OrWqB74vT8qX4pdezpq6riixo6vyTjv48wlZ47 8nIc3sYEaxOlToX5Z7cgcjGOBh4Fs/QEzeWiGWa4SAGd4Ly50qMGVPc3ykzmRb1ZeWPh PZuPPtbS2auHXFwHoj86x7dracGP43brkPML+F0gj3UcQ1C0NQP4Kiz+yauOh6SiAdr2 S5tw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=lA8lImzu; 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=B5BRL75Rqq/QsX4g5ZP6nUrszmkaYEUGj4R6g8/lDX0=; b=XbH+cqODDKafVs1gooWbWPGPUDrB6gl2ptG3hA4xcMc7ziqcJ4mWkhaG2HsAyf/+0J RfpJMzUlsnOB6rFK3aUHxGYyQz82oo5r5lRqKepPS1+N6FV1ZziD3+8mF2kd6uVWnuQS jyEj56B9dXJA9s/E6uWzQm+KyS8c4TGeQHYew= 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=B5BRL75Rqq/QsX4g5ZP6nUrszmkaYEUGj4R6g8/lDX0=; b=BbtwV2NWKp8c328cPq/fToavpknQyFoV6Vl8IRXnYejARPsBh7BJjJKHM/Jbc4HRFa Q6TBBuJ/RC0HXu+FiXF7QJ4Hjbm+3AD7GHApJWz1L9TiDikY+8TxbKMKCg5eVseZ6U1V 65YFBwo7jBmvRi+iSp7S68qBs5Cp2TMhvXimPsdSiZ89cR88sn5TIJwKVLBaBNi72xEB pezRUgWzLLR59z7qlvtFkhUjw84IKdL3IreQue2p7pKQE4UwTJiaWBQ1UbMvCI65YN/f mU64N2WZ6HXTRgqodNnkEbqhCGq6d3t8duwYHsjY4Xv6E3maLj0e5k6tm/hABn/BEjjP Kcag== X-Gm-Message-State: AOAM532FydbRcQSXqUj8spVS9L2bXwDvU6dNfAJfe7GJOB3XPBZs5n5X bf9vsqGSe7XFeGY+r37pU0yj5pVC X-Google-Smtp-Source: AGRyM1uQgeBHOk8hAEHLRuDM4GsCOuwIg0HpKV1x4pBTc9ZqK+J6wjCK0BqFPoYH8oMtz/pXBcuS5g== X-Received: by 2002:a17:907:1c91:b0:711:c834:754c with SMTP id nb17-20020a1709071c9100b00711c834754cmr4106346ejc.85.1655209711505; Tue, 14 Jun 2022 05:28:31 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:907:16a7:b0:718:c04a:5161 with SMTP id hc39-20020a17090716a700b00718c04a5161ls991587ejc.11.gmail; Tue, 14 Jun 2022 05:28:30 -0700 (PDT) X-Received: by 2002:a17:906:c7c1:b0:711:d2e9:99d0 with SMTP id dc1-20020a170906c7c100b00711d2e999d0mr4078171ejb.639.1655209710412; Tue, 14 Jun 2022 05:28:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655209710; cv=none; d=google.com; s=arc-20160816; b=q1zb+SGU72gJINnkkz92nnL0CYdNNApmV3QFZNmeHQGcDL0/LUDarkpgB+zgVYt6Ez eyaF8AruG1pM1ImuW79gk4DTCk1c6F1P+7RiGeSM35zBMccVUTbPpkhhgZ5WwFaMju3R P5sxhOsIEGXd2mnN4fejw9iGs2ZeBNUYu9nKIpcJZ75sjVYIeLzivj1tDVW3nor4i6X0 5WqAi/ManMnWF+tJYc9MsFALmDEGHF8oKL++tUfMawcg8r4GHBR1nXer43hSQcQ6XpH+ Gj9H8NbmJv0k/k83knzq2JfGUOm9Ns4lL/KqHrHZMTwlBO0cJIcTf6RCMh5uHMfyOUEw tTGw== 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=lfqn0geMWlo2m+epnZ6MFo0Gce8D/c5YwbUMrCOB20U=; b=Qyf9tRJQFKlYf1FLycZrZ0UmQMy5jzW+GcwWko0CcH8urs8cr+fXGP3f5DdYdWq9hh yqjVWis2dD8svO3O8WR6tSRLGA4hnCAvCWJotI2xt6CUICxcsycPMo2WZ2SZ2WAqTOTG EBH6nREajqqmWx0Xr58mbzzqirthgZhJCGY7DZlcsKQ/hSzN/7wF4S6j0QNoGfTqZoAs pe/CdgYMKyjSgBzThegw16htDaD9bpa7zGObEi4X0z6fV7q7aNrfa8ryB8o3KHC1ZMsk gGplwtWVtfixVjr5hwQJmsTXHiiTwSoewqMys+EMFe3nzUXmLvkA7r3SwsfW1gway7Hu 9xeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=lA8lImzu; 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 r24-20020aa7cfd8000000b0042bd1b53284sor4211814edy.60.2022.06.14.05.28.30 for (Google Transport Security); Tue, 14 Jun 2022 05:28:30 -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:21a:b0:431:5c52:82bb with SMTP id t26-20020a056402021a00b004315c5282bbmr5877909edv.70.1655209710212; Tue, 14 Jun 2022 05:28:30 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.amarulasolutions.com (host-80-116-90-174.pool80116.interbusiness.it. [80.116.90.174]) by smtp.gmail.com with ESMTPSA id z22-20020a17090655d600b006f3ef214e2csm5087043ejp.146.2022.06.14.05.28.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jun 2022 05:28:29 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: Amarula patchwork , Oliver Hartkopp , michael@amarulasolutions.com, Dario Binacchi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Marc Kleine-Budde , Paolo Abeni , Wolfgang Grandegger , linux-can@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v4 03/12] can: slcan: use the alloc_can_skb() helper Date: Tue, 14 Jun 2022 14:28:12 +0200 Message-Id: <20220614122821.3646071-4-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220614122821.3646071-1-dario.binacchi@amarulasolutions.com> References: <20220614122821.3646071-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=lA8lImzu; 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 --- (no changes since v3) 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 Tue Jun 14 12:28:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2069 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 4F67A3F03E for ; Tue, 14 Jun 2022 14:28:33 +0200 (CEST) Received: by mail-ed1-f70.google.com with SMTP id m5-20020a056402430500b004319d8ba8afsf6105227edc.5 for ; Tue, 14 Jun 2022 05:28:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1655209713; cv=pass; d=google.com; s=arc-20160816; b=zPX9VD/qSIFCys5bbYK1Rcczu4rnd9Jdsb2fCZ3I/UtGXSIIfDBQtVger3Xnu5ZLZ8 QQEu1xz6gVy9OFf9Z9jlVm7HrU8KllVtKLPfflatKZzyDb5py5X00WOvuhb69oiiacDT napvRB9AuwtfiTwwzp7WXZ8GsWZ2Zenpy2jTlEE6ifIxcbI4lto5t7IE7cpdtxBQsmZY FCUaXukf/i5AWYeCZGvTtzv4c9vvqySYM5fkjJZe2a3mXOW0EDtifvpt8krLTbv/gQgh bcH618VA92pFQBuWQ4Me+gbaH9rXSpiLW+XeD/U8pG9cImN/cNcxsk1TY8S6s6Kek9Sk SuMg== 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=zltaCgYn0pFDvvKg9qXSKa2p0qb7ICqlNMJT5AC9b+k=; b=Atrm6YyjhQwgvmnWPYUCxP/1mDq4QV38uUCc/nkys4fxVc9LW7wU5oUzW0sdLBI82F QtpePwEU9MgWTfdM5LT07cuA46ccytEMwRQzBI3jTkWEnamIxb2fSUeDCBpWbVs05tTn CIteZ/IqksQa+iUbDuQ5CXLerZ4jDra9rkNPX0k5Sx0VIcKRx5oV2jDZjKBdKqi8Q1kN Y1C9VPkGB883xQYfsmBPzPfw2hXpOwhlJBw4Wh0vJD0fPtEkCp7v70m4RArKwAKyC/95 onZMg/Nvyn/REQxhawYN2lSy9nSeelCIo8ezgnXVJwcbEOgiX1wzMTS3OQV8ShUz16uz WmVA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=oyKoCpe6; 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=zltaCgYn0pFDvvKg9qXSKa2p0qb7ICqlNMJT5AC9b+k=; b=n7fmRuGGPciv+z9pl6e5Eni3UXvNRkAnyHgPYSLjPzJ/RpviI0zevd7W+KMSKj18ZR E+DSDxIXjk666xDLbT/ZItiW2rd/BMva7Q3iY8BvyDFvtHEPt1EWoqNcw3g+WL1RJGCq mY3JDCHuNtDSp6C140z7BryUrtsTHwOiRkHIY= 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=zltaCgYn0pFDvvKg9qXSKa2p0qb7ICqlNMJT5AC9b+k=; b=Y8KDIUPjCpnOl19IxBQx0COQEDroMFXiS7w11PR92sSw20tdzuAXbhFDcQyO8SBZKr qcZWQbWvEFMQHi90IlcUcMaG2Apd+XfQzqnCUlaAT74NTCr13W9/YhcHJp1QeCipkYo5 XwTTnyV12BXQOFRII4GCc5d/r+YqSJKMF4o6fxEPiSduO+hseqjn/zBiCcGhyv94Xm5t UNTzL/plM71G59Q8XvjIJgQuvHrzdzkil4SjJRUTG6rUpzp4XZvq3U37p7EtKEKSZMw4 1/rxQr2K7IUQggZ0hblvzHzmjPk8Tteaah+4qffcTGgMEY0rD9ucgncFGiHtXYsSJIHz t1hQ== X-Gm-Message-State: AOAM532j8SOKj/f88V6/LYrx+Ubwl382qsn+Typ2WGnE0GR8HmEb587G KVjpB1hpbZiaEgEZiyk4CzF3uIJP X-Google-Smtp-Source: AGRyM1tJqixu9UrN+h7tWjzqNLr9xudLKmO7Dr/dO+IcShtLnVcUFa2euV3XoFeaOvDvsEQUpSwMZw== X-Received: by 2002:a17:907:6287:b0:6e1:6ac:c769 with SMTP id nd7-20020a170907628700b006e106acc769mr4091059ejc.388.1655209712988; Tue, 14 Jun 2022 05:28:32 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:906:5ac1:b0:6ff:ab8:e8f with SMTP id x1-20020a1709065ac100b006ff0ab80e8fls991810ejs.6.gmail; Tue, 14 Jun 2022 05:28:32 -0700 (PDT) X-Received: by 2002:a17:907:7da2:b0:711:f36e:b855 with SMTP id oz34-20020a1709077da200b00711f36eb855mr4216190ejc.308.1655209711815; Tue, 14 Jun 2022 05:28:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655209711; cv=none; d=google.com; s=arc-20160816; b=G1m5yMyvlrz1Vw1ipoMJyFM0aGhDbh8pSFhwkVphNW53qNmVUdCxI3M0AkWQ0dIt69 S+3GnUs4Brfbt6iiO5ERsHQP095WbvJDwcg8O6G/3FbNXia9plCA2tymWYDECCVXWCMJ 65kr4gCOR7mZ0OIx/tE07EBt6FlVBoHQdNqzJwqMvqROphYndrZyx1sO6oDnT84frgtl 7NNcedrHN3qLz/B2wr80TPUq+H831Z/XqhqruOplmmwm+ah6q2zXaHW2+QlS3oPyBw6R HjSck09jH7H34X4zNAJq3xvdEv+WTiZkmdbPRRiNG4U/7LqZ6ScO1EGgdIFAM/er+dph oUHw== 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=R7Zmyhhovdg7jA4sbkGr15373g5fZzWXwn/PzaeWDng=; b=W4SuqiqwxADmyFLaL9ubj2QBclmC21O2W2EI0fLDBTLI4AWFq5SCd4Wg/8CyPW2f8f d3HHsXDRA1j/b7jR2y6BKM2YgPi/WjseUPEKocUX35ZBmcYC2SvZuZcY18JHBM83z+OX 1O9mHCl51s3GV7eJXptk1cBp4raIeR9ujJxHvFEvFNLI4iKRQf3yyMu3v9u8QzuWy0CN K8D8JmCZK+pyyhG5WHvkMbyPKjLATQMSML3cK+0Q4BRMuUCiCpZpjv4b/2wZCeuvHQ6H q79VnUqD0llElrzIgpaVXUMcKV6abctV631Wk3fY5HdToZXinV8Rgk/Teb8ShEO5PGiB opoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=oyKoCpe6; 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 w12-20020a056402128c00b0042e0057500esor4109829edv.48.2022.06.14.05.28.31 for (Google Transport Security); Tue, 14 Jun 2022 05:28:31 -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:25c3:b0:434:dfbd:913e with SMTP id x3-20020a05640225c300b00434dfbd913emr5808884edb.27.1655209711597; Tue, 14 Jun 2022 05:28:31 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.amarulasolutions.com (host-80-116-90-174.pool80116.interbusiness.it. [80.116.90.174]) by smtp.gmail.com with ESMTPSA id z22-20020a17090655d600b006f3ef214e2csm5087043ejp.146.2022.06.14.05.28.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jun 2022 05:28:31 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: Amarula patchwork , Oliver Hartkopp , michael@amarulasolutions.com, 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 v4 04/12] can: netlink: dump bitrate 0 if can_priv::bittiming.bitrate is -1U Date: Tue, 14 Jun 2022 14:28:13 +0200 Message-Id: <20220614122821.3646071-5-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220614122821.3646071-1-dario.binacchi@amarulasolutions.com> References: <20220614122821.3646071-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=oyKoCpe6; 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: , Upcoming changes on slcan driver will require you to specify a bitrate of value -1 to prevent the open_candev() from failing but at the same time highlighting that it is a fake value. 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 --- Changes in v4: - Move the patch in front of the patch "[v3,04/13] can: slcan: use CAN network device driver API". - Add the CAN_BITRATE_UNSET (0) and CAN_BITRATE_UNKNOWN (-1U) macros. - Simplify the bitrate check to dump it. - Update the commit description. drivers/net/can/dev/netlink.c | 3 ++- include/linux/can/bittiming.h | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/dev/netlink.c b/drivers/net/can/dev/netlink.c index 7633d98e3912..5427712fcf80 100644 --- a/drivers/net/can/dev/netlink.c +++ b/drivers/net/can/dev/netlink.c @@ -509,7 +509,8 @@ static int can_fill_info(struct sk_buff *skb, const struct net_device *dev) if (priv->do_get_state) priv->do_get_state(dev, &state); - if ((priv->bittiming.bitrate && + if ((priv->bittiming.bitrate != CAN_BITRATE_UNSET && + priv->bittiming.bitrate != CAN_BITRATE_UNKNOWN && nla_put(skb, IFLA_CAN_BITTIMING, sizeof(priv->bittiming), &priv->bittiming)) || diff --git a/include/linux/can/bittiming.h b/include/linux/can/bittiming.h index 7ae21c0f7f23..ef0a77173e3c 100644 --- a/include/linux/can/bittiming.h +++ b/include/linux/can/bittiming.h @@ -11,6 +11,8 @@ #define CAN_SYNC_SEG 1 +#define CAN_BITRATE_UNSET 0 +#define CAN_BITRATE_UNKNOWN (-1U) #define CAN_CTRLMODE_TDC_MASK \ (CAN_CTRLMODE_TDC_AUTO | CAN_CTRLMODE_TDC_MANUAL) From patchwork Tue Jun 14 12:28:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2070 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 B326A3F03E for ; Tue, 14 Jun 2022 14:28:34 +0200 (CEST) Received: by mail-ed1-f72.google.com with SMTP id ee46-20020a056402292e00b0042dd4d6054dsf6059317edb.2 for ; Tue, 14 Jun 2022 05:28:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1655209714; cv=pass; d=google.com; s=arc-20160816; b=kBG6K3O4yZWElxNRcaYFB5PjV+LNI/cMCd2ynJ34emOHbwBbmg11hPzp0hNFt0nerI QVh1/h6ChiDrewNwOBIAu322dQeV6uju9TgyrubOXTGPLoExttb0OaGiy82jvSthE7uj c4gpSixsyY4HOTkFWTgAwYthiHZTDU7pzk25xKsmO+9LbgAJSD/Rxa+Td4m4/TZrqLHk jusm9Xo5YYH6i3lk5pENpiJKCqI4mkAJEqGpn7ACEk6w9kUyGXlUuZXpBevYy/CAlOU7 XN0zrVU2nlpl7OH1XRwt8TSvcsS8d/EHWjFOyMSpVgmlmoMGlx1t75BYFLNFJ+E6opaJ e2Jw== 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=t5I5qbosvJfKzun7OEVkfCHdHvEFIiHEzeHRxxj4iRw=; b=KMDQjSGFV5nvxoCSQp/kg/kzvoCe5HuVV/FR0Ds28LqtgPz8zdKwTC3SsAECkvgGO2 QlRAXneWgoqjlC6uDZj2MTgf7YLNDYu/6FThB0FU5TbeqON4LITjiqeaBgF+yDBA80JD 89u84w16RbaVVtCKdUq5x48FWNajvVYhWD5oZNuEtit1StQ/MBy5MBPi+YjQka8j1keQ nKXQXb8XUEwyHj7DSUbElDFFDmK9pwsxKXFIZEUXH2F5MljORILZP53Q2CgnphWOVwFc mKp+DUj3KqlQIpBynCqb4sGCZg0mksXOCXqDKe8EaT6IPpZTETrS8WmhjkT2E0A1iFJH GD6Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=p11hVCXe; 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=t5I5qbosvJfKzun7OEVkfCHdHvEFIiHEzeHRxxj4iRw=; b=p90kvoAH/5snaFVzeyjpuNv7gqSQF5S2eEUHbswR8hI6//4BRhXMISKNGgDNRdn1aY rcJTGHEauz4HSfPTgymTZDipqGEVBl2AKw1yTIVeLGZAaCzuoM1qfmjOC4xGmI1HKnfr E92Ngh6GXnwbH3BDQ3kqGS0eM8Ksj6ltWZEJU= 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=t5I5qbosvJfKzun7OEVkfCHdHvEFIiHEzeHRxxj4iRw=; b=8O6iIvrQqpwQcnNXqVPZ1orfwJruoAR7Dlr8DQR5GIu+Dej3a69l7gdSOWB8iyMg7z ZMWMyfCLRzUeMmpqdAWrecElhhhbRjGLMW8d+taFXuqPEXqcs10UHN7z1KT0HDxcFspO Gx/x1V8j9ku4b9LD5U8Nou6maq6TJdYWw+qnyKJeAbJjrCQrHl/ZT0yz4s/GbOt+HGPh BJSD7C1HPyQiBVZH7AgUIyJQ/zQg2AblwKNXVeUH0fNF3GVr6JETHLUi7f7C9oRodTZh sraIKkdaiLP18HHlCqgTljSf5s1Q85ygsHEXkfwrKrNmMhobpYnbr80xD+o1LlrqPQOs z65A== X-Gm-Message-State: AJIora+D/hB7U0y0roQBrLUKbpia0PPjBPYpdpEtgNw9AUQ55dORmeZd MazKocNAOq/6Kg7hiYv9+zc8a3w9 X-Google-Smtp-Source: AGRyM1sPopCbEXeWVPQzDdHGMkq6Ff+vEVM2GrSUjJz7nJzJkpbB1fJVcm7X/jHmHde3sjYbYmTOCg== X-Received: by 2002:a17:907:9496:b0:711:f459:664 with SMTP id dm22-20020a170907949600b00711f4590664mr4032784ejc.704.1655209714489; Tue, 14 Jun 2022 05:28:34 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:35d0:b0:434:fe11:7447 with SMTP id z16-20020a05640235d000b00434fe117447ls2365541edc.3.gmail; Tue, 14 Jun 2022 05:28:33 -0700 (PDT) X-Received: by 2002:a05:6402:34c:b0:42d:be29:23f9 with SMTP id r12-20020a056402034c00b0042dbe2923f9mr5868015edw.304.1655209713294; Tue, 14 Jun 2022 05:28:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655209713; cv=none; d=google.com; s=arc-20160816; b=EG2pe4dJuXx4MhehY/p7/AWESHef6r1bUAavxAo8BWqxPeNBeywdEUxJBuox/XO7TP pxMRihTwMZVaG6pl8kgvEBmohDtnXpED7H7YfIGhStLY0vT8submv0btzcHxU+HhlVxb ECfwuAOroN1kNewnhLniKlqQxI1Bexl2KPQy6ZsJSneXQd1JO91TYGk2wC48uwX1vID7 Nb7m9yTjay8wDmmSIBt5sFYxG0w3IbGN+zk+/lAGTaZ2KqWe2d90tLehHO/4P6qH2UAI yhySAfG2AaU2FWVDq9cpftR6d0uVTIASUEzTE8ip7xjt1uSwmWubTiU2ao6NL9PRL9Bu qS6g== 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=PCpFnoF0UtSjQMBZCRUGNujFKva7GVFTMHpSRjoSZYI=; b=UYfKRgFmd9ZS5tUDAt2hX/bCJEjOipuEtDzFQqCh8tXJKrCbq0o8xNT39+4JUFj8jp T4+N6CVVicmr61JTsAVu5KKD7G8oRbTBTZB7povKUsNyrx8tcvpomFoL6MkI27Tt0Ob0 ASQVXjHUqOi5U12kIGpWth7B+X3PuLq+Fddv6BKMFzFgEe3d9n0mJvUb1tMV+2SxBXzC Qvg1gtF4R3GUxBx9VFDTs+NiD1O7gbd63R7gIbP0zvF+aMXlKnxU9sqV8tmYzNbwSXP5 UPCwkBLWRDRuInLq08kTqzeaWlhCZSz9iW6V1ILL/wv2DZhnXFPTQk0dIK5lr3vF+rkP CKpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=p11hVCXe; 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 ej12-20020a056402368c00b0042dc8dd59d0sor4097419edb.34.2022.06.14.05.28.33 for (Google Transport Security); Tue, 14 Jun 2022 05:28: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:a05:6402:254e:b0:431:35df:5e38 with SMTP id l14-20020a056402254e00b0043135df5e38mr5790736edb.385.1655209712935; Tue, 14 Jun 2022 05:28:32 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.amarulasolutions.com (host-80-116-90-174.pool80116.interbusiness.it. [80.116.90.174]) by smtp.gmail.com with ESMTPSA id z22-20020a17090655d600b006f3ef214e2csm5087043ejp.146.2022.06.14.05.28.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jun 2022 05:28:32 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: Amarula patchwork , Oliver Hartkopp , michael@amarulasolutions.com, Dario Binacchi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Marc Kleine-Budde , Paolo Abeni , Wolfgang Grandegger , linux-can@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v4 05/12] can: slcan: use CAN network device driver API Date: Tue, 14 Jun 2022 14:28:14 +0200 Message-Id: <20220614122821.3646071-6-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220614122821.3646071-1-dario.binacchi@amarulasolutions.com> References: <20220614122821.3646071-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=p11hVCXe; 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. The patch also changes the slcan_devs locking from rtnl to spin_lock. The change was tested with a kernel with the CONFIG_PROVE_LOCKING option enabled that did not show any errors. [1] commit 39549eef3587f ("can: CAN Network device driver and Netlink interface") Signed-off-by: Dario Binacchi --- Changes in v4: - Update the commit description. - Use the CAN_BITRATE_UNKNOWN macro. - Use kfree_skb() instead of can_put_echo_skb() in the slc_xmit(). - Remove the `if (slcan_devs)' check in the slc_dealloc(). 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 | 107 ++++++++++++++++++++-------------------- 2 files changed, 74 insertions(+), 73 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..c7ff11dd2278 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 * @@ -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,20 +408,34 @@ 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 CAN_BITRATE_UNSET (0), causing + * open_candev() to fail. So let's set to a fake value. + */ + sl->can.bittiming.bitrate = CAN_BITRATE_UNKNOWN; + 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; + free_candev(sl->dev); slcan_devs[i] = NULL; } @@ -434,24 +451,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 +513,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 +527,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 +567,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 +595,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 +613,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 +646,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 +758,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 Tue Jun 14 12:28: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: 2071 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 911A23F03E for ; Tue, 14 Jun 2022 14:28:35 +0200 (CEST) Received: by mail-ej1-f71.google.com with SMTP id x2-20020a1709065ac200b006d9b316257fsf2805435ejs.12 for ; Tue, 14 Jun 2022 05:28:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1655209715; cv=pass; d=google.com; s=arc-20160816; b=Xx7UqZQ6RcnPZLb6asoUrxsFzs0aKhv4Pnk7rHt26sLRQek3lVNbplv2T04r7cHi+H pe1oT6cAa4otq+luZRI4T4OwVeax7TrRWi27ZbCqvWgdTs6lvfuFGARhSBlwMFpipc+u QITtJbrGCpBYHxSVgEwo2VOSkPCyyvTLgfPYzDShvCcjL50fHZaASJvinwGhv8Jixdfb MQZNXDXiF/znD49KWBUKi71UoKm4IAmwkkmjwyta+MZvaCzQTtlx5D21eY31wHgr8oxu J5bnfgFWHII4yzW/XSdbFdTSVvdrSUEurUNcdDAqfwUsFyQJNDncZY5Tl+zK9OAybEbh BJWw== 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=omEyssBrLXDOJdJzNKW3I94rHXX8brLbFXHRgTAuWWk=; b=UFQp3Fi2aVGiq66uda+KPvDOarjIpvUtpq+mf8G8HCk6+eaj+MNf/sJoZXGEinOn9M 374KtPN6sYqRCaWrbHUC5RbszQYob/9LuZw11cyats/6aa1vDYYeoBOd8KT5E/anbxEZ XNx2hVz3DPR+lXUYJMKtOcUApUJZg1BJYalh1fg/5s7G60EwyBMZN4ra5VbOq9YE7X7+ PXtTqvayM6dzDjI2cz/WtkjHZD4ypDg0cF9qlVuBW9ljsI/4ljjkByCV8vG/QgknpnJK yQt05x8qGDW1uKlc74SPncWx5TnNPC8PvqIk1SK9F7+UjSLbgfyQ7xMVGqa+B2LAd2tW 6zvQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=XSAUyZOW; 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=omEyssBrLXDOJdJzNKW3I94rHXX8brLbFXHRgTAuWWk=; b=Ql4wSxNJTSl4Q2ZZuO72nPwBqYJ2TvuSIWyvNs3UsI3SuHC2lr6bAxF7TVFHiB3Y5e GzjR5J7xoq1718rVyBTl6mG5O/h5kmVYhzpH2Zp7yzivRJzJZ5VIn2aaH6KnyopboqA/ QvVy41tf1oRDQ9S9yjuOB8u4Nikk+0dfd6qcQ= 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=omEyssBrLXDOJdJzNKW3I94rHXX8brLbFXHRgTAuWWk=; b=5RB3bvru+aLM//posq9cnj+oFgmnZqv+Xukl4rKka5eH6XWHFAvDXgMt/Qq56VW9VQ hiv6y0TcpIcR/6gzgIeXRXleUEt6DWDJ0Asjc3yGij61whlwjP1LLEIuWOPgP/v65qc2 TlQEHDb6APTuMPzWpcoH/8EVEXHRnlYJU7AtetoGawJc7JePGk6W67pOpjOJb7RmztU7 vvfAQksvkShnoXzt4qqOT62seRJoOx6tmcvv2EpA1Rdn7gpLuAjN98Xr5IC/sOsCFPHD YsInEhyWOQw89SI+Iu1sjdWsrTrfDPpwUuQbzZHJpJ9xB20VzvyFywFOkjPQoXuz8+OF KR2Q== X-Gm-Message-State: AOAM532whjfb7dFRFaBoNXxcvp7wD7F08WPe8/c9u3sK/Yr6PmSorMsh 1IB9MIvA0HQIryulXBI0s7d1kd1o X-Google-Smtp-Source: ABdhPJyeipC+m9dwhfZIvuivDMwdSSFfgLpbRFTXp8bfUyINBOgNPFbCBkVS2vrzn2GgunHkB4xEIw== X-Received: by 2002:a05:6402:90d:b0:428:bda9:3e6b with SMTP id g13-20020a056402090d00b00428bda93e6bmr5772713edz.132.1655209715424; Tue, 14 Jun 2022 05:28:35 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:907:16a7:b0:718:c04a:5161 with SMTP id hc39-20020a17090716a700b00718c04a5161ls991656ejc.11.gmail; Tue, 14 Jun 2022 05:28:34 -0700 (PDT) X-Received: by 2002:a17:906:72de:b0:711:f8c8:ba00 with SMTP id m30-20020a17090672de00b00711f8c8ba00mr4290408ejl.586.1655209714418; Tue, 14 Jun 2022 05:28:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655209714; cv=none; d=google.com; s=arc-20160816; b=0F6x5Gtj4FN7xLN2tZYevUpSH3Xq7vsRide/p9YYDew9Lkhvtd8QzsmbUwdLr91lu3 n/blVkzgHreTPXSOeNIPM9CU0vSpUBbAMc4VhwgucMqG3GtFfTVEJw8rTjgbuu6NvdUG vjSqfm9RLyEySq/slZGZEMR5atq6EEo/YMrLovMtvl2GgkGFWkeY1NjyTmzKTsKbEWnZ jgOTBqv2JLBTy1urrYGE0FEc5wFLiP7LRwzlkPu221tXz1FWuAkyr0U0Rdocb7TawcuV 6og3BD+aiZGbiDvodwEx7vkF91JBi6OGdUXPdy9N3FO43soPZ9Rrw9je5kWMtWWClsrI e/qw== 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=J7cAHYzHeqO4eieQ7T7B38pR/xwLeH3ndQgGNnjLG/E=; b=vi2UUjZjJRru37iQNkVN+tRwz+XwhKNUF9ob3juD1iZW76xt3rgn5SZBC2YQSKCTSc SpSdiE3szAAuFbomS5JLQLVUA9q0ouijoclboXruJ+yoLvlpWk20c7NYjhRNfBY9fE1S m9Lev4ZMWGaQ4ZPfvsdFFEXto8tLRFz+3Qs6eBxCb0d0XLuIvbbo+txm11snW+asNcdC 8Poj7hLC4ANqb3y2UAM2c5JaFd5k2XY9ZDBaRzz2qYv4c3za5z8OgdmqYCIEpQSW47+J OxJl0DMdazW6xy4mKk//+zYEWTWSb1cYujbpXYpFIpYCQdpJuaMBPleBFRWZPeyQob/U szDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=XSAUyZOW; 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 z24-20020a1709063ad800b006fed069d000sor3320132ejd.43.2022.06.14.05.28.34 for (Google Transport Security); Tue, 14 Jun 2022 05:28:34 -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:7254:b0:6fe:5637:cbe6 with SMTP id n20-20020a170906725400b006fe5637cbe6mr4030190ejk.612.1655209714188; Tue, 14 Jun 2022 05:28:34 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.amarulasolutions.com (host-80-116-90-174.pool80116.interbusiness.it. [80.116.90.174]) by smtp.gmail.com with ESMTPSA id z22-20020a17090655d600b006f3ef214e2csm5087043ejp.146.2022.06.14.05.28.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jun 2022 05:28:33 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: Amarula patchwork , Oliver Hartkopp , michael@amarulasolutions.com, Dario Binacchi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Marc Kleine-Budde , Paolo Abeni , Wolfgang Grandegger , linux-can@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v4 06/12] can: slcan: allow to send commands to the adapter Date: Tue, 14 Jun 2022 14:28:15 +0200 Message-Id: <20220614122821.3646071-7-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220614122821.3646071-1-dario.binacchi@amarulasolutions.com> References: <20220614122821.3646071-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=XSAUyZOW; 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 v4: - Replace `sl->tty == NULL' with `!sl->tty'. 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 c7ff11dd2278..2afddaf62586 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) { + 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) { @@ -541,6 +584,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 Tue Jun 14 12:28: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: 2072 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 3B9323F03E for ; Tue, 14 Jun 2022 14:28:37 +0200 (CEST) Received: by mail-ej1-f69.google.com with SMTP id mh24-20020a170906eb9800b0070947edf692sf2799124ejb.10 for ; Tue, 14 Jun 2022 05:28:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1655209717; cv=pass; d=google.com; s=arc-20160816; b=bVMVyH9NFs6D1LFU91tATkCiyeMkc9u5fAxCoryk8wdw76QxD4U4OcEdXAlANWRU5v r+8SP8HcyREPkMOCEBbJtDaWMC0aYNqTW0UmPYfuUs5yEtaNuBDhUNwaJEF4fZnKKc9O v7iSBouSN013raXXwLp0xqLGHum/fwJGIqlJIpj3snvyRiT6s0Cs26ZLgcNs3DEOTR4D jcmrzME6o0oYk7Hc99sKYcov8Lag0+Bf/FtDcuWrKuYZvYCPNZ2GitJ84umvgK2Uh0tz yh+f1Pxf01CxYO4UfPl0hJkKAuGaiBhioMnNcUh/vShs0yihmVqY6RVVAJv4FhIuUAoQ Hqtw== 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=t9RT6ixxSf0NDAxLWRPJgx2sCubF8xu0QISo5KlAUg8=; b=ZCGXVnsUGM8cy0n2Kf/oI30DdFF3bM/PbqwkSwaHPILt8vjjhtXC26MxkR3GXNX+tA J6nm3JC4qxPo3bqAQ9ZrCypqWDO7q9HGXbsrZCNt3BZ6fkOiPfF2Z9MkdeDIIsrnTvSX OwZSd7Cpd1zjVQA6snZMTpLPGOusaRWNDnELTCwCKxiaCAt+9YZtoEP0qpmAW/ftTqH5 GQ3RHKvWe83JEK8+bjYPUIw2a6AErJZW5HJpdmPG05kTnKQEZEHgsZD8PzyDZQEbHPPy 4HKp4mMh3zAQHqkgc5ssEshjL8qk3hKFxV5VRVWharGCy794rpXXmVnvzQCah4Y8vxw/ MPYg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="Z/JIYpot"; 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=t9RT6ixxSf0NDAxLWRPJgx2sCubF8xu0QISo5KlAUg8=; b=K3cbZF+I46KaziBRGzSLo2jsrw7/2EzdaWFAVVp+10tbRGhvF3hTtxqXR2iA1dTcDT 73n/QzTaOk+NETY46yBAiCEMXWaZlzLGeXDDLljk1zq0086qUaRlrhqrTwCbdWXiHEew ccgekHEQZ4Pcb11Zraad4GrsGC8YWFZ2GOe5U= 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=t9RT6ixxSf0NDAxLWRPJgx2sCubF8xu0QISo5KlAUg8=; b=rmh4TnBMWJhj8nEoRVpfBwKhQSoYTx0bsU2IFnqis9i+j3PEgd0EcXPbkPICfhCY/Y xVvKJYtUDeHB496AgqWeEiNCwDYoLToTGVew9uKt/AyMCZvueu35faUzuSOh78eklS+f Svz2KtxlBjpnLfWCisiN5s0myzmLOtQemT2h9U73axdOw6/uMnTSXWvBZCbtgAqSf1X0 /RH6Com86NAmn/f9QO6qFowRPjjDW8m4O8HV9MmBiP7zeamJ82t8h6UeGdgEpcUOg58r ESIUziT4OuNsiSWF5a1jS764NDj+PUHt81uxq/KwB+5laow+f80Gyy00p/1WOxV8Ncgg bTLA== X-Gm-Message-State: AOAM531I1Yb1w+dIlcTkdr4nHGvfv5rKnZiI11h/D1hXIix7YYnqos2l AeBvsupikHrrBJAlUNtzUp+cBK+1 X-Google-Smtp-Source: ABdhPJwgsGJz3o0/AXTX9+QG7ds31k8XGC3m7FN/RGP23IgQ58yOO0kEszqXnLRKIILMGB8wWga2zg== X-Received: by 2002:a17:907:8a1f:b0:711:da32:8410 with SMTP id sc31-20020a1709078a1f00b00711da328410mr4358936ejc.298.1655209717006; Tue, 14 Jun 2022 05:28:37 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:709:b0:431:3a5e:75b3 with SMTP id w9-20020a056402070900b004313a5e75b3ls2366507edx.1.gmail; Tue, 14 Jun 2022 05:28:36 -0700 (PDT) X-Received: by 2002:a05:6402:25c2:b0:431:932e:eb6f with SMTP id x2-20020a05640225c200b00431932eeb6fmr5725395edb.296.1655209715952; Tue, 14 Jun 2022 05:28:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655209715; cv=none; d=google.com; s=arc-20160816; b=HrJhbPjXnKUM8rgsG7IVDNHsgFwHQN2YsCgPCPaxvAmJHB1MZSTsLH3BnTcY+klzhX H+9L3Oc/Ggb6ThwC0XzEE3W/XR/gDHVH8s2m39BOimfet0KthLc3WAr93NRo2UJ3pAH4 uJ34tTek24cvBOITMecmrtsoitKrkbl1M1QGWjpMsjk1CpVO4ZeRC1M8JC/dS+Bdukk0 gAMx6Ab42GLYQWHOt80j4GE0dfFEp3JQMVDJ8VJiZsuGObYB9ExoD1K1b5yivSSNHL1s W+Wav/V/14NyV1dHFfztNAdIHLlAvMBZkU+zm6iq/RGgUmPdfevCLGYvdmgTLvI2TKOp QI3Q== 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=AbbDKExzTnDRI7gbQZlSxolycHVQn9x05Wxw1nhoVAE=; b=Ki1DhcycUJ6eSCEWu2TTgJq7HJ1eAIZCjBxe84pf8pSbWMoidc99xuBBo46HOkIP2b jsEEUCGfZYQnjXU83mq4lJmNLGzmfeItl81Vt+y88w3deZ37BRnpjXS9xwCh/IB5YbTM N9mA1sLcDXQjI0vIRI/KHKV8+7kUnGws4k50Gm6Zmtk9TNRN51T78FOSBbKJw5zuXLiX BcIl28DP6DQsJW7dfVKG9j0vDPTycU6mr1OvN7bbYlbdPzvYI7dPauoFv51+reaR6bSP qhe1VflbkNyqT+FJGb+M4iwYhWZJxmii5DSPuSmWGU781EJHskwTS0//aMNw71j2XUbX YXxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="Z/JIYpot"; 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 c11-20020aa7c74b000000b00425d72fcb73sor4218530eds.19.2022.06.14.05.28.35 for (Google Transport Security); Tue, 14 Jun 2022 05:28:35 -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:5193:b0:42e:2569:652c with SMTP id q19-20020a056402519300b0042e2569652cmr5733602edd.73.1655209715758; Tue, 14 Jun 2022 05:28:35 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.amarulasolutions.com (host-80-116-90-174.pool80116.interbusiness.it. [80.116.90.174]) by smtp.gmail.com with ESMTPSA id z22-20020a17090655d600b006f3ef214e2csm5087043ejp.146.2022.06.14.05.28.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jun 2022 05:28:35 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: Amarula patchwork , Oliver Hartkopp , michael@amarulasolutions.com, Dario Binacchi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Marc Kleine-Budde , Paolo Abeni , Wolfgang Grandegger , linux-can@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v4 07/12] can: slcan: set bitrate by CAN device driver API Date: Tue, 14 Jun 2022 14:28:16 +0200 Message-Id: <20220614122821.3646071-8-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220614122821.3646071-1-dario.binacchi@amarulasolutions.com> References: <20220614122821.3646071-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="Z/JIYpot"; 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 v4: - Use CAN_BITRATE_UNSET (0) and CAN_BITRATE_UNKNOWN (-1U) macros. - Don't reset the bitrate in ndo_stop() if it has been configured. 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 | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/drivers/net/can/slcan.c b/drivers/net/can/slcan.c index 2afddaf62586..bd3cf53246c7 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,9 @@ static int slc_close(struct net_device *dev) netif_stop_queue(dev); close_candev(dev); sl->can.state = CAN_STATE_STOPPED; + if (sl->can.bittiming.bitrate == CAN_BITRATE_UNKNOWN) + sl->can.bittiming.bitrate = CAN_BITRATE_UNSET; + sl->rcount = 0; sl->xleft = 0; spin_unlock_bh(&sl->lock); @@ -451,7 +459,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 +470,39 @@ static int slc_open(struct net_device *dev) * can.bittiming.bitrate is CAN_BITRATE_UNSET (0), causing * open_candev() to fail. So let's set to a fake value. */ - sl->can.bittiming.bitrate = CAN_BITRATE_UNKNOWN; + if (sl->can.bittiming.bitrate == CAN_BITRATE_UNSET) + sl->can.bittiming.bitrate = CAN_BITRATE_UNKNOWN; + 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 != CAN_BITRATE_UNKNOWN) { + 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; } @@ -582,6 +615,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 Tue Jun 14 12:28: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: 2073 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 88A193F03E for ; Tue, 14 Jun 2022 14:28:38 +0200 (CEST) Received: by mail-ed1-f69.google.com with SMTP id o2-20020a056402438200b00434ec3efc03sf4018096edc.9 for ; Tue, 14 Jun 2022 05:28:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1655209718; cv=pass; d=google.com; s=arc-20160816; b=BV42Suv+YpCWwyXkPsRuuAanqvpPHETlOrlVs1w78TzNj7X1ntrqnQS183y85YOllp U4YhnMlwilT//81a4kQFTX6iJ22vKg/Qg0mNv++qayXgZ3Kd7FNMVXsmF6M+QlsNVony wiiPVOzqLAO4Cmu/XEelJ2Et9fhQUADiPRBuYvYHnUHjc+2J5DiAUVvdK63TwVU/pLCE N+s78VyVsKxYRyRokq+NoyQ3ZFgzwNdKY+gfX683/E/+gaRNSak5IH9IFz5CZ6WUFvh9 m2EbYy6hJH6k0HbPqDdHBaZZUjyR090GMpK1tJrf2xZ/gVEkkn7dm/iuKkESWCmVtAZz vT9g== 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=HO+8scD1DlOZyLa1IxKsgZRmMYiqE+Q2KeuEA3+aBQ0=; b=xOrv5lhYe8wfxwH/mLKvxkyPWXnVov2myJY+UowXbRvJCGQgHgHTL8WUEkSRwiyQcB PVeQb6NqC0TyLsuo8xi28Wa002ot4fM20Ac2PPqo8TCUwsULg7siuau0BPqrFS/OfYhn dCb8zfyTY44wb6NgEhMmD5IzCBh2OfHhGzpfqYQbjIq3H0nnr6oly9FZzTrC8GcZ4S1S OIkPEd6AfzWaaLcWaMuM5dmdactXEa38hbKuZnbLj5huT78HkyzA7Qm1bw0uI62lFw/x lc4ORDYeMrSBh84L+9YjBHYseBO40VPLplN01n0fvhX0oCzE1nqpC/IKgzbKbBCfBHl/ wk1g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=fcozqSg6; 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=HO+8scD1DlOZyLa1IxKsgZRmMYiqE+Q2KeuEA3+aBQ0=; b=rp3kOUq0m5Mk4Hy4eDUgIOD/CW+5A1YBMKWUEzhBehkyOzkquV/NB3+N3qlkvUrNse bn97TfveVNuv71K4m/xFzzYv4m3TEJ6WXm1WQzauSuFXSligerE5iydeSarZg7ZW6YLh lhIODtBwh0K7Lfrue+UXnnk54ScZCJygQfTCY= 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=HO+8scD1DlOZyLa1IxKsgZRmMYiqE+Q2KeuEA3+aBQ0=; b=FF08gWyrhXKVBVJTy2QqMEoA0iKGoCTkq7Ug/Rc7MtRq3QR/HDc85I3vzhFVLCP0o8 fql2YBBzCnsfvWr3skL52ml9bcRwc4/AU713omgg4hiffwAMTl9/DkHcAD7dKl21Ieg2 Q3xrA4fzQama0Zo9nW6+NJtsqkuXLWWHKD3Ogfw+kaZf9a46HPtofQCDwoFGIN5Cfzm5 42UybdBbFXUtK4/ZWIAZqptelUM23ptiLjAYsvXRq2jiiP/Rm2/QcKcq/H/x/hsTwT9z uZYtWAt1yoknFedZ8KTjJZD17/gyJHTMyCYjNsfX1ZXCfecjABA34Tk/YbGFSxqyqZed P0wg== X-Gm-Message-State: AJIora8zGJyw0P0QeS8BMbDtZRnCEl5ZOnuhwZ9toPH0O/+EYYyvIqHi 9txo4IuNzHndrzMNxFSx3UtZeWnA X-Google-Smtp-Source: ABdhPJwYRWQmk/Brd3dS2FthmSE2i72pZ3kRdDnqUd7QZIYpf3LHuMgwZYaWq1ywGOum5BbfalTO5g== X-Received: by 2002:a17:906:eb54:b0:708:99d6:83e with SMTP id mc20-20020a170906eb5400b0070899d6083emr3880419ejb.745.1655209718383; Tue, 14 Jun 2022 05:28:38 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:907:97c4:b0:711:d2c2:9fa4 with SMTP id js4-20020a17090797c400b00711d2c29fa4ls992225ejc.9.gmail; Tue, 14 Jun 2022 05:28:37 -0700 (PDT) X-Received: by 2002:a17:907:3e91:b0:711:ea5e:2d4 with SMTP id hs17-20020a1709073e9100b00711ea5e02d4mr3954752ejc.52.1655209717200; Tue, 14 Jun 2022 05:28:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655209717; cv=none; d=google.com; s=arc-20160816; b=OQDoCsjm7MGUjHISVA1KkPdpxLw+k5Q6u/ss59C8orIPK9gjcg3CDbawWOuK2MVGJn put1rh2e92hJNqTGFLfqR14XVMPobxNURE1yoN6i0RNeOu7T1/wDP5BeSIfR7GdPxRHE DuDp6rxUhReoS06wMeHdletet8h+HHvRwTFbumL3zHj2TSzkugQs4rFaTUP9dnJClhvx TCwW0R5IivRt7C5vVpfSr8KJvZl2Pd34i3ccZMzG9claixq3BTw5GADRGTT0Cv4HQAhM bcGSpni44AEJRBGj/7dRv4falY6EiRWpi64pRRrzRQHNiOrJNR3HlREeQWwq8AbSEezW FmkQ== 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=4Ikx/I3Y696YQQvJOfJvkR+b8+rk3mrxAawgjIDEUZ0=; b=mbHgFrNRIskZYt+e2sj5fWLVHGje+4hgiirUG1qdniGZyC/TLri8/JJeciOlS/aK/k wtbAY29WSyWCGq8Wa6vzgtyjVRXZx8XObRyn2Zw0N7tiFtjIXxhn1jT1WnCO15d6jCcu zg9/8xJayg3NI5XASvPZXzniI3o+bCMLT68bbZ3iuy+aXsgGs9cuSoByJJSmj9ZeZyUI zGL9ylcQ1XkBH60b/mpA96zjh2zjVtuQB++2Vh7xAQVxsq6O86hkCJVBx17xwVg4xy3r qDv9finnemwf6XUYbbKXgC9oK/zYLcF+v3Pvg2zwHU40n1ZP3+Eu1e7SbyzMbVYZuQZW SEnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=fcozqSg6; 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 yz2-20020a170906dc4200b006fa8e1e0684sor3241790ejb.37.2022.06.14.05.28.37 for (Google Transport Security); Tue, 14 Jun 2022 05:28:37 -0700 (PDT) Received-SPF: pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Received: by 2002:a17:906:73d4:b0:715:701c:ae96 with SMTP id n20-20020a17090673d400b00715701cae96mr4033479ejl.50.1655209716999; Tue, 14 Jun 2022 05:28:36 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.amarulasolutions.com (host-80-116-90-174.pool80116.interbusiness.it. [80.116.90.174]) by smtp.gmail.com with ESMTPSA id z22-20020a17090655d600b006f3ef214e2csm5087043ejp.146.2022.06.14.05.28.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jun 2022 05:28:36 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: Amarula patchwork , Oliver Hartkopp , michael@amarulasolutions.com, Dario Binacchi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Marc Kleine-Budde , Paolo Abeni , Wolfgang Grandegger , linux-can@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v4 08/12] can: slcan: send the open/close commands to the adapter Date: Tue, 14 Jun 2022 14:28:17 +0200 Message-Id: <20220614122821.3646071-9-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220614122821.3646071-1-dario.binacchi@amarulasolutions.com> References: <20220614122821.3646071-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=fcozqSg6; 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 ("O\r") and close ("C\r) commands to the adapter. Signed-off-by: Dario Binacchi --- Changes in v4: - Squashed to the patch [v3,09/13] can: slcan: send the close command to the adapter. - Use the CAN_BITRATE_UNKNOWN macro. Changes in v2: - Improve the commit message. drivers/net/can/slcan.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/drivers/net/can/slcan.c b/drivers/net/can/slcan.c index bd3cf53246c7..b08e63f59b8e 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 != CAN_BITRATE_UNKNOWN) { + 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); } @@ -497,14 +508,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 Tue Jun 14 12:28: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: 2074 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id F02D73F03E for ; Tue, 14 Jun 2022 14:28:39 +0200 (CEST) Received: by mail-ej1-f69.google.com with SMTP id q5-20020a17090676c500b00704ffb95131sf2812945ejn.8 for ; Tue, 14 Jun 2022 05:28:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1655209719; cv=pass; d=google.com; s=arc-20160816; b=hwMj3dGAo7kuBAzwdy+c/8tArGehhWY0u/4n2d2fiWVxLfuf84s04/zqSko9zkKGyv 9ehcXlJ3wlGpbpdFXSDMt1ajAVhTJeC3nQEnz9dJy9Dgyxrukkz7J1K35/ihjXtXwRpi UQGOdtlido+j3rTTiyWoMZuWS5VRYV7QBrmzoFCX2pcjabRZdDgi7baqIblQSeaoPjA+ qL9QnmCJYMooXwx2BIN+TI/1QMVikW5M1ozNIq3UwlmDUhLtYS/DN8vqilH59rHPHf/o yIzhOy9il98ALnDKULa36VaxXzdhzDL0QY4JLee0Ku5Z4tA15qOo9DhgvMzRYmjBfory DG9g== 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=YANPbUjkX/aBZvCw9F/0TwRjl3XhKrnACFYudZCtbBcaTPp0RVxsJ/ozRWTT0wt6Dc JyThQZM6j7E4R7uJE0zJeLkx0ke3HBNReD5B4TlDjapJW8ZBVJpagn6bcpqGHqIQbXMM s0d9tvsBc2XSjT6FCGyXmYE4AIATpLGlVNAqsqEfbNi5HxHSrEFV2FbtnKr36l3I2jKe WbeHWmonWeQlDX10OTYTyhaRY5mEJomHz2GopFLTN/J6MUtDylLwFBzE4Y3GsT3RCNjF kEdB24vjcXU/RhzsynDv3ci/s6fb2yFOi5XUonugsl+KTi6c34gKh2tFP3aBR+Qkp5nV /SfA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=UeS+soY0; 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=ETJOQyRc4FMNIFQD+CoBMLmFYG92T6fv9ka2ZWiGZxR1+FzHQfQroZp4vTsaRaGGbC HGVsHt6VYlX1Ki+z9nencIFID6YK7lKnw41lO75WMsYf+DwnDFpxE4Cie/181LMkNqh9 /r7yD9vw4QK+BEjvre8zZreZnzUhDt3j8sg2Q= 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=TRxSMS1mzSPEtOk3vSJD5PHysSpvDCMQKPzIJ9Xx8akTFeVMrNGGjMbi123hBB49dv GiW8QNFiLU7joGmmLJy6ESyafEaQm+dASSWfVg+yS4x2RXipsJZTLllW5ewsXcH6x7ag AtqFSBSswVg+WUcNGHp7/5iH1BHFAT6/+7XoIHUVLvoMDuHvUiQJ8bWydcOOUQSZml8f m56i2IcZA7Y5O8s76V3GNgJLdagMBXy76wY0Pc924jcP2Ey+dwI56SFfqHW7JADZjInH fhPRzKPw+kKZCfZKYuflnP+j+BXwmb3IMJvZNw7v00wbsReLUOuUDzVOh9clunzlobsd 3d0w== X-Gm-Message-State: AOAM532QFeNUAQlkwiqTlJO6nF7MVxBeiy3Jn8h5MTIJ6RunNXY27sFY U43iHdlCYcUwvOg5EKR5HtzYIQr1 X-Google-Smtp-Source: ABdhPJwj4nSwDKlXVCr/6wod1qiCy3OR4iX94YLC5ffyG9raSDwnLMqyu8hYSb4aLBLiBHqSw4SoEw== X-Received: by 2002:a05:6402:358a:b0:431:20d5:f4ad with SMTP id y10-20020a056402358a00b0043120d5f4admr5765448edc.375.1655209719803; Tue, 14 Jun 2022 05:28:39 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:906:6a26:b0:70a:1088:57d1 with SMTP id qw38-20020a1709066a2600b0070a108857d1ls992544ejc.3.gmail; Tue, 14 Jun 2022 05:28:38 -0700 (PDT) X-Received: by 2002:a17:907:e93:b0:711:ca66:6d06 with SMTP id ho19-20020a1709070e9300b00711ca666d06mr3941058ejc.477.1655209718631; Tue, 14 Jun 2022 05:28:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655209718; cv=none; d=google.com; s=arc-20160816; b=u2GyZwRUAj08SREcC05YFdxuOjh7ARcQ2b6U1oMl1tBQlD9dAOnJp6/bpeQjlbiGZ6 aEuwwEZXlPxFsCI8lVoFEcYo1NEkymgEKX8HFCfjWA+/0pVOTj2A3PCZUvwgyzoQDxdU lNAQS2oCCqW4FGYkK7uAV+2lIXNyxhz5md6TUiRNzp3ziuLIXzoZ6teMJsNqaa3EGHce Hp9y8SeDiz8zMUgCNjaYO6E5w+LkKZ0FrDW+Pq2+BxruL698ickGBQ1eIvfoeWmw3cow 3FRdJNhuDKiT+G5dMOma4Fo0KvKaSeSOVnrdJO5edDdlfX3wJzyQTMEZksxyGL9cotne n48w== 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=QESU9k2Otj4TsIUk398WqEz9IA7UhoSPnvNbpY+mZyYg3Y+xTW8AoOsV+q5tpPwwd8 4QE3Pu+1r5WtTACLuSHh2pSNVVUBkzPTRQPZoJNmph9UpB8hGozgAyBVowUo2GJeBg8E 0rJ9XPg3O3oKOEoaYn9hBaWEumLlJROZDDqNx1FJrCdT3Y5zyYVlCN+Scv7aXpzHUoiI Q8cpoRq0Ql9INNy4RJP/gV9da6gWnXZOnxv8I2GiTQ+cxWKb+H0Tv8uKtz5xRVoNWiWC /Isf23sk7aISAYVYPhqPw+wN9FBIgovTpPpwFR5gkQi1Cuo65kE4U8ptm4AH4iAnMId4 9xnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=UeS+soY0; 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 ja10-20020a170907988a00b006fe88301d74sor3160236ejc.110.2022.06.14.05.28.38 for (Google Transport Security); Tue, 14 Jun 2022 05:28:38 -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:74cc:b0:712:381:9c5a with SMTP id z12-20020a17090674cc00b0071203819c5amr4079949ejl.466.1655209718386; Tue, 14 Jun 2022 05:28:38 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.amarulasolutions.com (host-80-116-90-174.pool80116.interbusiness.it. [80.116.90.174]) by smtp.gmail.com with ESMTPSA id z22-20020a17090655d600b006f3ef214e2csm5087043ejp.146.2022.06.14.05.28.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jun 2022 05:28:37 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: Amarula patchwork , Oliver Hartkopp , michael@amarulasolutions.com, Dario Binacchi , "David S. Miller" , Eric Dumazet , Greg Kroah-Hartman , Jakub Kicinski , Jiri Slaby , Marc Kleine-Budde , Paolo Abeni , Sebastian Andrzej Siewior , Vincent Mailhol , Wolfgang Grandegger , linux-can@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v4 09/12] can: slcan: move driver into separate sub directory Date: Tue, 14 Jun 2022 14:28:18 +0200 Message-Id: <20220614122821.3646071-10-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220614122821.3646071-1-dario.binacchi@amarulasolutions.com> References: <20220614122821.3646071-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=UeS+soY0; 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 Tue Jun 14 12:28: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: 2075 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 432013F03E for ; Tue, 14 Jun 2022 14:28:41 +0200 (CEST) Received: by mail-ed1-f72.google.com with SMTP id co13-20020a0564020c0d00b0042dc9ef4f01sf6048882edb.16 for ; Tue, 14 Jun 2022 05:28:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1655209721; cv=pass; d=google.com; s=arc-20160816; b=eYYR8L5oclPiTRr8JlhT6xAOPNxauWGGEtElABC9GkG3smM5wrnq5oQiqsTVHQ5J+8 Yf01tkDI4Y8g+u2i+Sob3JAHaDWS9tuXcqNTBFGMdj52jatKIKVGdhhmxJPPFBaLLYwD adafEomJ/MaROH8VSnxhQ9FGTDMcAYgTJhosldJfXrcIdWmWVIj2wFcMwCU86z60RUC6 KHNRZj8hQhMfIvbhqzgbLfhsbEspsKUfZIqrChHumsv8LOjagWzgUWc/fvriE3mP43tq xwEnE8M9dBaDOSe466FJhxh+LYtbqB9NZMG1iN+xuSXen+FJ801Ro9pKRB752ChgJvSP 4p3w== 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=WPNEkxN/F2yauhVGaLTV5FrYDPxneebui4vcuPuYET4=; b=Z5jDqXt4VWGCpTcZm4ktD/JsDaI1vmFeISLB4JzQ5iXHIXqLB4OxJyDmrmltXE8Y8P EyXv3wVT0hroLigZc514eHA6drvphYJWUU7nPbczContupqiydxYgrr7nxRPr4G9P7RX GmXr6PQ8kSgf2Lb8SY53Oqqnz4fPRSHQIEyd/9Bld/4dDC8ikEhEwo5XhNGxQGxTlukJ kvz9taArmK3CIcMoCBE31XOsd+8DHm7ty9w0kIDekmT0Jvbb08C0KcWXDDxgyAXn+YVy 6/zJwD2yB1Oy4OagEyjQi0ghoucRFSMTRCyQ1eEcu7eQASmM7BcrfgCrgf2ONWO34DhF VBKA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="JNHe/Rd3"; 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=WPNEkxN/F2yauhVGaLTV5FrYDPxneebui4vcuPuYET4=; b=m6BPGAXGxTfpYWTmN3CNZE3/+U3DaYpt2mQPTYWisqqysWQyudF8gJaf9JB90Kz8aL 2SdWKB2BbTDPoIxo+MNuYMc8R7HOi0vQIaJXEBN4eu4HC1+8eieOZ5qlxYBCCzEhZerf WMFxlBD4AjBz+nMjKz8Zw/ucSpAyTzDfSD/2w= 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=WPNEkxN/F2yauhVGaLTV5FrYDPxneebui4vcuPuYET4=; b=beRt13kUVPhiaBLPuqxKGlUJFYVTYYrkwhCT3wFpgfaQZMKCAebpor4vILH+O92hFt /ZT6LbBg+FQHMSAd/gHfl92NG3GAEOXreYFUKSwlnDOtOLDw+YPdCJlnHK1ROn8EDKwd eJv3Oa/O1a2nRdiyhtwP2BGajRIHA76wjs8RnGwueZhzbaS4urKlY5Wu2Nvq7Pq1EyA5 ydjd97ME9LTfQ49XNS9RofB5w9hiblVbEBIy1y0V2C7wqs1g7jLkFU6UdBGb26E8TaOy Nd6kv3p5xAbeL+wiwrikDMuYtClxjMc416Bcyg4+1kN9IpnTE0MQdOcexjD3ALT+cOTt xD2A== X-Gm-Message-State: AJIora/de4j/8rnSW1FgC1FskS1WQAU6vADe1Qc+Lg2Xbp3WlfAGF1tJ /S00/k92WY6XfUtArAjaun8mw8jF X-Google-Smtp-Source: ABdhPJyZAFWD5QdGTgMsf/Ub04krXQUCIGEJ38gDWTtzyLHxTncmaqoC8fWdJT+KzqMc5ciiTrZNwA== X-Received: by 2002:a05:6402:1e8b:b0:41c:59f6:2c26 with SMTP id f11-20020a0564021e8b00b0041c59f62c26mr5865657edf.156.1655209721071; Tue, 14 Jun 2022 05:28:41 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:709:b0:431:3a5e:75b3 with SMTP id w9-20020a056402070900b004313a5e75b3ls2366696edx.1.gmail; Tue, 14 Jun 2022 05:28:40 -0700 (PDT) X-Received: by 2002:aa7:c55a:0:b0:42a:adfa:9150 with SMTP id s26-20020aa7c55a000000b0042aadfa9150mr5825976edr.57.1655209720094; Tue, 14 Jun 2022 05:28:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655209720; cv=none; d=google.com; s=arc-20160816; b=khD7GRolXlDsf1oDQ4IPaYbQh6moLGqT+tbHSic7H+X0m/GZBeTBu49XTCrtuY1QVy MGOitp9f6r3IBawuok0WpjIs7JqJ5eImrE9pIAydzin/k/WDmPnkLCjN34aT8KPwmvfO ucFjOwwgFa2hh5oa7bqDqqy1wi2f47LTf8KDKcQBCSw2QwkjINvaWa8mxBcHKFMMmGM/ HaQEZlVZiSausKORfJjsfI/lKDv96TfOnF76lb7zGKRUpdK4/F7SJRU6jcEs+Z41igcM tTSgMpsVBrXUU42rk7mP79WsHg38cvO0CoEq8hr3EQ/brK4313Wvey2u4B1xmFE+IPK3 1F8Q== 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=XeYjdn9a4I+7ASW7s8Y7GsWrvaBO3fcqP0UZzQUkPdo=; b=CGK+VFmQGlzHRKDsH8SVsEsugRQgIjeNONs7lx11FRMPf34jMYRy1SRsckIww/eTIK bKWhdxHU8Mf1hTSDAmDF/9S7vF57SLbLjOWQi6SorEDTlxLagMOaIaAEpXtQ/tcqfX/L VqcZJyul+h+wdFFv+0ZMDNFyKEjic27Rbt5AgS0gYzN0c9GI3lmsCTzd4encvd9CvhYv g7rDQVBM1eRQ7C4nFhwYIsBXSDMNQT9P+fZX/FLp4gr1J9Zq+eo9JpEDRnYcMSL+BUDW hZ76Gnb1+TEA4i3PDFYX2+jPHcyGDkVdb1zPa0y5WtWxwzZAZI8RIXk6KoconcLlrtRg Vang== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="JNHe/Rd3"; 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 i14-20020a056402054e00b0042a628e69a2sor4216050edx.61.2022.06.14.05.28.40 for (Google Transport Security); Tue, 14 Jun 2022 05:28:40 -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:2381:b0:42d:c8fe:d7fe with SMTP id j1-20020a056402238100b0042dc8fed7femr5766685eda.248.1655209719900; Tue, 14 Jun 2022 05:28:39 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.amarulasolutions.com (host-80-116-90-174.pool80116.interbusiness.it. [80.116.90.174]) by smtp.gmail.com with ESMTPSA id z22-20020a17090655d600b006f3ef214e2csm5087043ejp.146.2022.06.14.05.28.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jun 2022 05:28:39 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: Amarula patchwork , Oliver Hartkopp , michael@amarulasolutions.com, Dario Binacchi , "David S. Miller" , Eric Dumazet , Greg Kroah-Hartman , Jakub Kicinski , Jiri Slaby , Marc Kleine-Budde , Paolo Abeni , Sebastian Andrzej Siewior , Vincent Mailhol , Wolfgang Grandegger , linux-can@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v4 10/12] can: slcan: add ethtool support to reset adapter errors Date: Tue, 14 Jun 2022 14:28:19 +0200 Message-Id: <20220614122821.3646071-11-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220614122821.3646071-1-dario.binacchi@amarulasolutions.com> References: <20220614122821.3646071-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="JNHe/Rd3"; 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 b08e63f59b8e..b4f29ab2ab72 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 * ************************************************************************/ @@ -511,6 +537,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"); @@ -630,6 +665,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 Tue Jun 14 12:28: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: 2076 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 CB8D33F03E for ; Tue, 14 Jun 2022 14:28:42 +0200 (CEST) Received: by mail-ed1-f71.google.com with SMTP id x15-20020a05640226cf00b004318eab9feasf6085988edd.12 for ; Tue, 14 Jun 2022 05:28:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1655209722; cv=pass; d=google.com; s=arc-20160816; b=cs/j2IHBtq4A3PULKXTK4Pq3M3m3VFCaGtsaEzMH8seRqykSIskRSD64pTHW2R7cOa gcmd3/Pvydwa+sSFZhPhSwF2w1XaC043vxp04sMG+4qak/WWtls1wrPZW813HHCsaEYR 3L0PvbXyRAlNA1YelLb/6T+HiwoZrAod4tXVjUjn0VHEXw1k8X1b27x7gWYHVvpbE1P7 LOn9Vx26M4sLmWxUD7miG2Bx8qJCnlypbsws70ZXfct7CDS1LkmIHbnVIEVEwr94bcl3 c8N7jEwBMX0Z1hEp7eFsLYFOI5HDEbvh/0OgjhPAuMagqvdpoNW2bqlZ8ENGw1xhk0o7 rc9Q== 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=t2UJ3SIHapnxFaVjLnUf0CORoPSHZsRIqeBr5mz0wZA=; b=oKs/D+TULA0h5TQ7YwEonVcDiGSXGnEotLsRzW9DDXkCL9PmVgfB6F5e2QBkAgfDs2 rlSkcus4rJMjI3METUzzIG8yt+3B+JCjuLUYn1BXNL6OUyZSseXJ3kpULyWiAnBtiJiK 28R+q1cNgvS9b6JWfz4e7MuyK658kip08YAekVm5yOLgYn1lOUTroAswMVRW/ml7MoHC 03+s/sAsrOH7JAN49lnT3aVbrfZnYEs95N+l03hr+YGAx1MT2MUZyei/ta5ChcM8nlBI DsqgCs/QjytYLFocc5eLtUDNW8la5uASqjFURV0Ik98qSRkPUNSKMmz0mP4IlGdu+arK NzeQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Ja543dMn; 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=t2UJ3SIHapnxFaVjLnUf0CORoPSHZsRIqeBr5mz0wZA=; b=CqXFN286WE0x0bzZbRaiEXY7fuKNjNCrfVgA9MgSfjc4Yy1rhrZoW1xhOk1Kg6tIl3 +L2L16DCs+bpQJtLW9bTI1jDWtQgJRmP981KaDRH7suoKN7psDXwNrA+XdcfUYf6wDAi Jqq/83SH2tmiW3xEp/jZ/9cW48wGk4N99sx5g= 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=t2UJ3SIHapnxFaVjLnUf0CORoPSHZsRIqeBr5mz0wZA=; b=vSHAHt7WSCnHqvMKwnUFu8v5PVfhTtoG2DyPXpE5vaUcsHjGkRGI1NywGLvOEXYcHz fgWlVzdGMsH21VhmDnWMrL9p+4+avXVRYmySqegVJoEYPZ6NhKJsEHmrzAPhrx93LKkq Dh6knuO+6wjG/m6y/6C0UVyaWypOKKwHQs4tXr+03OlfIIyt2EUESHJxeUGVO6y4b8Te bKBIjA5vIT60kD+6d7IgPTC1yWwSqcdPwZjarUkK+DJBTPsNUs/3E44P58zwX/vXOa21 OP5p0ya4v1+b5VFuctc6LC1WCJor3zemdqm2zZuL5uujPrXjL2hx/vhR6XWZeMjPVhvv +bcg== X-Gm-Message-State: AOAM533LZ6qFJ2DGNji9tNKlDbMDKzwK/bmHXRbC59vjuBuR4ROziMxE hWXldJK6MYE6g/V1WmnlHxb6Us4n X-Google-Smtp-Source: ABdhPJwEW265FGIV4SlH5ALiHujUr6sNNyGErTLQTKRJJUYAjF5Eh5S+/nY7Jot61/UCqNovFk8SbA== X-Received: by 2002:a17:907:c302:b0:711:cb4b:1382 with SMTP id tl2-20020a170907c30200b00711cb4b1382mr4073565ejc.476.1655209722567; Tue, 14 Jun 2022 05:28:42 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:907:9705:b0:70d:ff46:7086 with SMTP id jg5-20020a170907970500b0070dff467086ls992104ejc.4.gmail; Tue, 14 Jun 2022 05:28:41 -0700 (PDT) X-Received: by 2002:a17:906:1084:b0:712:2989:b630 with SMTP id u4-20020a170906108400b007122989b630mr4065822eju.344.1655209721519; Tue, 14 Jun 2022 05:28:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655209721; cv=none; d=google.com; s=arc-20160816; b=SE2Hf5LTgzQEATPXMUZSgZ6NwzUyKNzLFcyCwatYN227dd6LH9N6uO098goiPUdXUJ veXlNBcdkyzAfnz2+UQQSscFbvKqFUMgnpVMRa3yefRX+WoqL2Rp266OK353/puCaAZY mAt/nI0JRztmtjXQYX32zjrA30+WvWQgOFolyXWYoE8177L+05XbS0MEaUlPNpdCLxOD X+nfzc7qypqVMIOk4rl3YUd6POJtVAPbmxiWVKRu2bcP6de2VZE+Mop/awuwftb4yeFj n6GqYy6+WTJKfsk6hyXFmndUYE4XFLPQ8CFksfUI8V+XhcY+wqUCv3gkeKZDx1T0r0XC hu+g== 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=UY9xGJVeCuDiPWb4quL1k0Um37OolG5UZs6VBw/8AE4=; b=jLhZt1swnODHaaW1tO62AxcOH1PbobHtwygUG6FRcyFKX6Cp0cCBQDfQ00/b88DwrY 2iUhyIJC8KFGTBbdOvUQuEky/gqfffqeZw4x4TgnHuCv7WnJLvhjw+he2Q9vaOV1Ssui NNoKFanenikoTGIbP9pZLSLAvhJWuijVDprenQbJcYVRYe/04yHQI3ucEC1ZggtOJLXJ nOeNW8PB3lQHibv9Aw3GKxihoE7PH4iSh/UbJph8Qv5b0nMmygKTGS4gA/ptBE9HiP3I ekzf+3QezVsqv+KhY1qhqNXSA4jNZ0VUCfEY4XvXU0sK7W46Q6H2mO3C0bbROfTCZWPL 2qeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Ja543dMn; 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 k26-20020a1709063e1a00b0070afac782cesor3222727eji.5.2022.06.14.05.28.41 for (Google Transport Security); Tue, 14 Jun 2022 05:28:41 -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:4482:b0:70a:19e3:d18a with SMTP id y2-20020a170906448200b0070a19e3d18amr3911625ejo.510.1655209721319; Tue, 14 Jun 2022 05:28:41 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.amarulasolutions.com (host-80-116-90-174.pool80116.interbusiness.it. [80.116.90.174]) by smtp.gmail.com with ESMTPSA id z22-20020a17090655d600b006f3ef214e2csm5087043ejp.146.2022.06.14.05.28.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jun 2022 05:28:40 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: Amarula patchwork , Oliver Hartkopp , michael@amarulasolutions.com, Dario Binacchi , "David S. Miller" , Eric Dumazet , Greg Kroah-Hartman , Jakub Kicinski , Jiri Slaby , Marc Kleine-Budde , Paolo Abeni , Sebastian Andrzej Siewior , Vincent Mailhol , Wolfgang Grandegger , linux-can@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v4 11/12] can: slcan: extend the protocol with error info Date: Tue, 14 Jun 2022 14:28:20 +0200 Message-Id: <20220614122821.3646071-12-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220614122821.3646071-1-dario.binacchi@amarulasolutions.com> References: <20220614122821.3646071-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=Ja543dMn; 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 --- Changes in v4: - Add description of slc_bump_err() function. - Remove check for the 'e' character at the beggining of the function. It was already checked by the caller function. - Protect decoding against the case the len value is longer than the received data. - Some small changes to make the decoding more readable. - Increment all the error counters at the end of the function. 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 | 140 ++++++++++++++++++++++++++++- 1 file changed, 139 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/slcan/slcan-core.c b/drivers/net/can/slcan/slcan-core.c index b4f29ab2ab72..6c7c815eaf45 100644 --- a/drivers/net/can/slcan/slcan-core.c +++ b/drivers/net/can/slcan/slcan-core.c @@ -176,7 +176,7 @@ int slcan_enable_err_rst_on_open(struct net_device *ndev, bool on) ************************************************************************/ /* 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 +255,144 @@ static void slc_bump(struct slcan *sl) dev_kfree_skb(skb); } +/* An error frame can contain more than one type of error. + * + * Examples: + * + * e1a : len 1, errors: ACK error + * e3bcO: len 3, errors: Bit0 error, CRC error, Tx overrun error + */ +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, rx_over_errors = false; + int i, len; + + /* get len from sanitized ASCII value */ + len = cmd[1]; + if (len >= '0' && len < '9') + len -= '0'; + else + return; + + if ((len + SLC_CMD_LEN + 1) > sl->rcount) + return; + + skb = alloc_can_err_skb(dev, &cf); + + if (skb) + cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR; + + cmd += SLC_CMD_LEN + 1; + 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"); + rx_over_errors = true; + rx_errors = true; + 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"); + tx_errors = true; + 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 (rx_over_errors) + dev->stats.rx_over_errors++; + + if (tx_errors) + dev->stats.tx_errors++; + + if (skb) + netif_rx(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 Tue Jun 14 12:28: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: 2077 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 3A8F43F03E for ; Tue, 14 Jun 2022 14:28:44 +0200 (CEST) Received: by mail-ej1-f71.google.com with SMTP id a9-20020a17090682c900b0070b513b9dc4sf2798069ejy.4 for ; Tue, 14 Jun 2022 05:28:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1655209724; cv=pass; d=google.com; s=arc-20160816; b=lY79aJYqcrdoKoQn0i0Or/AovNU1Hxy7DX1wiiD1VVfhnT5NEmXzg9rSxs5PQ6065d CT1PYwXQxsiLMG9WWZZU8VtaIIiu4Z06lKSw47R2HqEppDsYRUeoutyy1NBKA0TC4HmP jt+tNIhOIIQ9A+daNOuW5FnIJ06lEFnA8Go5DGtDtOdKyb09jCaX2dZVj0BQ3mTL9ma9 j7YCtfQbSiHeUbKaO5NzTg/BIua2SZ1EcMP9ez2qt66+W/K8jPtFyCI34NEhCiYy+CG4 t4BL2RIlhSm89iWraKR4OLt+VlHof0oNgNKHv0bL63SPeFAF5uNhNo7sUhpylgMLoKIe gpJQ== 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=+s/fanNaBH5QndgQhqaRG+5D14HOzuR3zU++YQx1cSc=; b=vY6MnjL9VvxNJSFXgW64zolgcxMyR807NGXV1R5z9SciGIu2zImckRsVAzBEFNktZ1 KAgfzrQhcK/Iv5m1auVJUObHyESPi8OaXxG2Tbly8YNiIwP5Mrrbu9Cri9kTjzRXMUxN pS9K39lxitIofF34KjPpgovJVxZwFfU9KDlYm7yuyJyrlZcXh+sVqMS09pml0mckpb1V VysC/89dXhzWu9RcmakGj/V5rcpM2V8DFmXXvDgEqF/m3unbT6S6crR9b4OsVGij8xgj hJ9agfxP5YnXQ6Wgj+fZcX4rm4mztAp4U+7TPFm4Q7BWdSPiFicdDMNRIjJpZMkEPpJl AfDw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Imdk9ZoA; 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=+s/fanNaBH5QndgQhqaRG+5D14HOzuR3zU++YQx1cSc=; b=a185V9fy/QqVDWfuUAxngsGuj66ynI17NsH4Ertj/BzyPbGT79NKz6hn36x0olCqpn lMm2E49YV2SQtdHwDwiWPi8bbpAavprmcs2IR3m4jz8xjOOVS7zr6D36OiZHvyoF2efn RhHL7y5oesP8mffG+jrH0MVV9v7uzeh+iPXS4= 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=+s/fanNaBH5QndgQhqaRG+5D14HOzuR3zU++YQx1cSc=; b=qHN1+QAv3yW/gxyiFGhX9F/FSQwbCbwWac5QCisoodJJy/Ilqy3zv7Ek7Y9uvj0eg6 895Lm33HT7kYpw1riFgaSyiXOv012+Tbtux87vsY4+FqtTJLDW9jcA0n7lNjkU3x0AXw kkZtOtjhVA1RsgvY86dLaGPcCDpEIkjKZ5yv/7m3aFerc0si+uhLaZ+49ZumMt3sPsrj rT8ITVy3G9qviTd/TDxSmKfnlQLBXCnZdJPiLUF2MqiXG3Xek/QDn6fAs1UMiQw6Evlx 8nN4ogafSJKMMw7P8kHthAwjozkNrK+CNfywTAQGfIIO4c3EimPNfGwyAdijxRHeN9Mh YI4w== X-Gm-Message-State: AJIora9WXfGxAQBSR9ZMzYmnXNfvb2G3zmHNcwO+aFubqkvg82G/Hd51 /8lV85qWEj5wMhN6lWF5LsHTxuoj X-Google-Smtp-Source: AGRyM1t5pUFzvwBxU+SKbRF2jMyDTAD6SFwFJ5Wm6dsT9cU07zt9SiGvHqNbJe9AcVZI36aRtFKTNQ== X-Received: by 2002:a17:906:7b82:b0:6f3:ee8d:b959 with SMTP id s2-20020a1709067b8200b006f3ee8db959mr4266243ejo.458.1655209724056; Tue, 14 Jun 2022 05:28:44 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:906:2ad6:b0:6fe:976a:7a5 with SMTP id m22-20020a1709062ad600b006fe976a07a5ls992602eje.7.gmail; Tue, 14 Jun 2022 05:28:43 -0700 (PDT) X-Received: by 2002:a17:906:4f87:b0:718:c7ce:bd64 with SMTP id o7-20020a1709064f8700b00718c7cebd64mr4039148eju.507.1655209722979; Tue, 14 Jun 2022 05:28:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655209722; cv=none; d=google.com; s=arc-20160816; b=GDCfnVOH7vsmPPSyma0zhpSC+2nEBfEJMIofEsmcrS6Kt0VNz7+ADE11pZIKRjUBLw KGP+I7S1duR3gVG2RGvkdYqBooee+eoEVQUoaZvsaOh4F9EUmo4D6bkz1w2OJLZdSJPn 9ut11kw1u4xpWCjC4hHScHJNX3Js9Kc8OMtgZE4ykTKXILRy5QMySkyJfqP9TjckbYzO C1GDQwolZrzY7oWzsGtJOmv+Nz3eFDifXsZIV/uTTFaDLqvRrAd0P2/PsKT/j8qLXUR7 TO2+xSMub2zSMXolQ88ldMuVyA9JsmQqj9n4aMhji2Jb/DRiUrvx/IxuZCkgrlD4IOIh ebSQ== 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=jYzinqDMpP0ikE9sweLWXVziLbiFyEvA5RI0XjmyrwA=; b=mQtEuiDryWCyvMf8MeqhNvuPUYHwCxHjwXBSupTG1+YWnlEK2VTUdwFQ/rbUN7VozW mJeAm1fPkKkPVEFq5+8PZhFRx/4nYuffV5HjeuQo8CLl/XlsEkmj0VSAyOuz0vLoPvGl YXCeCJjHIqWn+Do6TSuC19vx327fc4QcMXpfJ2mB2G8gzsH00yb3zjZFDkkazRccqHi0 aTqlisby6PnUpihQKpVlmTy6S0HS+p3hd1+/IgIzDtu1M6Sa3+VXKtXd6oDnJimMnGD2 9W5YTCJc/uHBbhge9brb7n+xXePKt6T3hrFwna03W3KEKYE1tPLxDbgykeXrOdBAEXDh MJ4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Imdk9ZoA; 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 o9-20020aa7d3c9000000b0042dceef26c2sor4185809edr.51.2022.06.14.05.28.42 for (Google Transport Security); Tue, 14 Jun 2022 05:28: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:aa7:c604:0:b0:42d:cffb:f4dc with SMTP id h4-20020aa7c604000000b0042dcffbf4dcmr5869600edq.270.1655209722774; Tue, 14 Jun 2022 05:28:42 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.amarulasolutions.com (host-80-116-90-174.pool80116.interbusiness.it. [80.116.90.174]) by smtp.gmail.com with ESMTPSA id z22-20020a17090655d600b006f3ef214e2csm5087043ejp.146.2022.06.14.05.28.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jun 2022 05:28:42 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: Amarula patchwork , Oliver Hartkopp , michael@amarulasolutions.com, Dario Binacchi , "David S. Miller" , Eric Dumazet , Greg Kroah-Hartman , Jakub Kicinski , Jiri Slaby , Marc Kleine-Budde , Paolo Abeni , Sebastian Andrzej Siewior , Vincent Mailhol , Wolfgang Grandegger , linux-can@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v4 12/12] can: slcan: extend the protocol with CAN state info Date: Tue, 14 Jun 2022 14:28:21 +0200 Message-Id: <20220614122821.3646071-13-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220614122821.3646071-1-dario.binacchi@amarulasolutions.com> References: <20220614122821.3646071-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=Imdk9ZoA; 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 v4: - Add description of slc_bump_state() function. - Remove check for the 's' character at the beggining of the function. It was already checked by the caller function. - Protect decoding against the case the frame len is longer than the received data (add SLC_STATE_FRAME_LEN macro). - Set cf to NULL in case of alloc_can_err_skb() failure. - Some small changes to make the decoding more readable. - Use the character 'b' instead of 'f' for bus-off state. Changes in v3: - 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 | 74 +++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/slcan/slcan-core.c b/drivers/net/can/slcan/slcan-core.c index 6c7c815eaf45..e2d7645ff8d2 100644 --- a/drivers/net/can/slcan/slcan-core.c +++ b/drivers/net/can/slcan/slcan-core.c @@ -78,7 +78,11 @@ 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 +#define SLC_STATE_FRAME_LEN (1 + SLC_CMD_LEN + SLC_STATE_BE_RXCNT_LEN + \ + SLC_STATE_BE_TXCNT_LEN) struct slcan { struct can_priv can; int magic; @@ -255,6 +259,72 @@ static void slc_bump_frame(struct slcan *sl) dev_kfree_skb(skb); } +/* A change state frame must contain state info and receive and transmit + * error counters. + * + * Examples: + * + * sb256256 : state bus-off: rx counter 256, tx counter 256 + * sa057033 : state active, rx counter 57, tx counter 33 + */ +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; + + switch (cmd[1]) { + 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 'b': + state = CAN_STATE_BUS_OFF; + break; + default: + return; + } + + if (state == sl->can.state || sl->rcount < SLC_STATE_FRAME_LEN) + return; + + cmd += SLC_STATE_BE_RXCNT_LEN + SLC_CMD_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; + } else { + cf = NULL; + } + + tx_state = txerr >= rxerr ? state : 0; + rx_state = txerr <= rxerr ? state : 0; + can_change_state(dev, cf, tx_state, rx_state); + + if (state == CAN_STATE_BUS_OFF) + can_bus_off(dev); + + if (skb) + netif_rx(skb); +} + /* An error frame can contain more than one type of error. * * Examples: @@ -388,6 +458,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; }