From patchwork Wed Jun 8 16:51:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2029 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 B6F533F1F7 for ; Wed, 8 Jun 2022 18:51:26 +0200 (CEST) Received: by mail-ed1-f71.google.com with SMTP id a4-20020a056402168400b0042dc5b94da6sf15280584edv.10 for ; Wed, 08 Jun 2022 09:51:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1654707086; cv=pass; d=google.com; s=arc-20160816; b=z+xwexMhDFiGkXEK3mTOu6TijwUIfRAU2hfS+EBZVVDIu3ucg2G1YfqaOFSrSR17Eb TQYUl9TL2lr+Hci+mfAFgWQj2J6ICDd22Bpm56mWxB2Jiy/66I1htyTAMrNj4P7TCGTm TuZ20bJYmPKt7PtHzZU5ZG6sPqN7plAOyKD45g2EF+JHW6hkQeaevF724djMoSSdDhn2 MiAelfKkK8URT0orUz5NE4VQX0Al+gxX1ioeAjLHlMWvwp6TNHgt6sUZupx61RME8nzO /cu6WIXTLhlRlLEwgxV/MxvitjY64UICPJbmOoTEgfSAchuHbWwzSyq2JDiXkZNXEnFN QP/A== 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=Uxe8wepVgRFxBMI+X5zVNaWXYQVfQcaZ8ViwPhP9RFry0FKSIqzk3wTx6r8oa1NHU5 pduXKQHmM624D2+G20pS+tKpy8ZIDsGXQeo3TfenWm6nAMSMyJgXyo31MHHtxMPHnX9C F1sde1oFmcRAT9+MnwOLwUQe3pQc+sZlwZNh5Z8lz0D1GETdwnoYbAwwIb5OZjyk6n7h ObBmAWpAVw/FDHf6gc2ry4zr2eXkaVA5HOge1CwlB7CsQ7E4mGCkD/FkN5k7zrtxQJgC I9osDdinGyYrjmBV0YaNTyJssU6OaNFmkWXbd0JQpq8jPh2BDVEtW2KYTswZ7s7Fi1C5 z7oQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="f/RB/AAD"; 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=d/sv/OQLuTx3vlfpCg2WRDBskAJC6KEGweJMAiSvtvQg7CzxmWr5v6NUI5mYjEosYh RyI8qq2U+D3Og7btA4mCEVDHWw8y/sEt7vlivtSN7wdy0iQm2xTMqDI3IA+NOyySHZwx H529wTaz91sdPurePXRkZbRHCVQv/zRZxocDE= 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=KelB/KHr5VqzDeOdFVdw1qlVvgEX/sFNR54TDCSEA6q3AsCTdT7GqI6FXPYxZJGfCA WK3i1x3bbqlGOcEPIBIZ4UN1sJu+0VJo0H67QBy187RkSOPCH0/p8gbDsnzoiIbQYAEf xkuBR/peTYISk021eTxi4X1gq1dZXw/08TnP/gDyWr3FK8yq4QYP5XGvK2ziDb0tqWrP /Ld59oqJWYAET7LYLjdd1zSwRDbzqP8bAnuQNk2fwcEmHVYs5k5RXXJwU1SH4nyPryKV wV6ICiXQ+gwT6vb6fcgvBjtsFr2edG+AciutV+7BX2lXyp0Lqtri3oafnXyvwySb2yA9 ALMw== X-Gm-Message-State: AOAM5300U5a8xPcxg4JxMKhCiOSOSzTa7PcROh0v7aMvB2+JNDdHO9l3 9yzHnfGZzKXaX0rFfpc3hpOhCExI X-Google-Smtp-Source: ABdhPJzBMhZZTWkBrk+uVErqeLZ9NVTwg/8pMHM/Bdd7qy7oDkkZL1FZpcal9PexpGmFdpY0S3wnEQ== X-Received: by 2002:a05:6402:b03:b0:42d:ce84:387a with SMTP id bm3-20020a0564020b0300b0042dce84387amr41246027edb.3.1654707086569; Wed, 08 Jun 2022 09:51:26 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:5414:b0:431:6a31:654d with SMTP id ev20-20020a056402541400b004316a31654dls189383edb.0.gmail; Wed, 08 Jun 2022 09:51:25 -0700 (PDT) X-Received: by 2002:aa7:cb05:0:b0:431:95b9:6d31 with SMTP id s5-20020aa7cb05000000b0043195b96d31mr9466015edt.56.1654707085554; Wed, 08 Jun 2022 09:51:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654707085; cv=none; d=google.com; s=arc-20160816; b=H0lUc+9gweZBKilkoMtDBu38VIMrywf+9U8WInktLGyxn17Q6cGBJVqiO4sfvT6HHs fRaZzxSYHOYUxi2lgeX7Z+HX2xGPZuizqP4Avsvco8wdCGdEHf+xHktLAatigU/TM4iH 5oQOPP9b4zHdDlMuqtzbQPd22vqrnwYaSiXFsZYtIJSfXuN0jI9iTQJeeGvtuielhkwW lUzv6hgOdo1g8Cw6u8/ULlDJuCfo/lHFF7jKmdqB90fwJjO1/mgEe/Ibb5z/H7O92OjS B5I7QIT6R6Zq5NUT4z3muubVlTm1R4pxZAddJs4SPRAQwQMf9jVal+rDX65caGmZ3fdR Iwiw== 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=tabjBUe1rJ2jkXAiyIASPG7d6WoExNvYZw2hXPjCzhnf6ZutmL3MrwkXUk5/+mlAdR RplHGGjAFtGrQxrspJcUcSUbK1WZXvRBsxGyKBCE4Kirg33sN1OyVRYnve9QTJLsXMxX PJwnrxZekEGB+UFffKi+spg8Atqcr6gGvcUQGzPohGEdwexIiO3AG9vtPbeaR+mR4M/r crP7aoKasQ7q3aSWnNGja/veqr9RC85eo4ynJ1sfofI8txoSnfreaqHC20JJjKVg3gtT N9GdNju2K9gBqdFAjK4iR/4QiYT/CqkjyjcboSPQx/BGdc0YfLN6mLbNzEL5Hv+YHKPt 3d0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="f/RB/AAD"; 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 e3-20020a1709067e0300b006f42a32ebc9sor9564249ejr.87.2022.06.08.09.51.25 for (Google Transport Security); Wed, 08 Jun 2022 09:51:25 -0700 (PDT) Received-SPF: pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Received: by 2002:a17:907:3d8a:b0:70e:6b1:b004 with SMTP id he10-20020a1709073d8a00b0070e06b1b004mr27556484ejc.61.1654707085258; Wed, 08 Jun 2022 09:51:25 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.homenet.telecomitalia.it (host-80-116-90-174.pool80116.interbusiness.it. [80.116.90.174]) by smtp.gmail.com with ESMTPSA id c22-20020a17090654d600b0070587f81bcfsm9569071ejp.19.2022.06.08.09.51.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 09:51:24 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: Amarula patchwork , 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 v2 01/13] can: slcan: use the BIT() helper Date: Wed, 8 Jun 2022 18:51:04 +0200 Message-Id: <20220608165116.1575390-2-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220608165116.1575390-1-dario.binacchi@amarulasolutions.com> References: <20220608165116.1575390-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="f/RB/AAD"; 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 Wed Jun 8 16:51:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2030 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 377703F1F7 for ; Wed, 8 Jun 2022 18:51:28 +0200 (CEST) Received: by mail-ed1-f69.google.com with SMTP id o17-20020a50fd91000000b0042dbded81desf15233463edt.0 for ; Wed, 08 Jun 2022 09:51:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1654707088; cv=pass; d=google.com; s=arc-20160816; b=Epadek6o2noE1Y85pFa3jzBz1gZFmzhoAm/gHOHjN/Klix79ZuzQ5dHQo4wrVbrvn0 zrcXG0zGMT2uJjbOmpK9wBmUNWFstzeTsFmaIFKF8eIPMC6MZaZ3mQ8Y7uHY8fo64Z7/ CqPNZXrnw8Yo4K8f+q/hiaDcd9v6TNHrPYoxj6pOkt2PySIwgohGTz7ffvner1RfvHPn HwfZV5852kG7Clj2WUh28sX2+vkCgkvOqCvBxHPVxcGyU0ODGAF6AS+0O9wAy5jpmgx/ sLPB02kFRxHT+zWFbmF6lcAbDPm7gP2/2jaQMFyUVpEW89JExKMItcJOQ30jqye1VdoC +mLg== 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=VTKN34xZUKDbYp5cHZVHsw36NbrcErrFV1/T4/ZMeXrhVDHxTj9zodKuC4VIXSUQhF l7juAXwWImHl4RmJSANSe0qyO3gZqzjAVCRZPtY58+LEzC4HKOdDZ2Ipfw84dxuvqV5a wezj9Z8Hl9TTB4gCcPIPXmzYrs+W0hedI2mz20VnOgXQQzccuWxipTCydwGHXbdzUPbo QCDBdHpTaec3GcjmPHoRTZDPboZsKDY7/l6OPFQQH5yNQv+K+QnAVk1Qk09/K8mZ608V fzESa0xMSRwxzUcV9ppCusr7x4uf7K65k0KFUcxuCkuaPqBhg1ZI4Ycsanjq1LuQw0Gk xVJQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=ofPeQ4nO; 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=J9ZMWR7zZLWfJbcs+rcBS5EsL4RzhcatoCyu1LA62qKDw/Acw/K7cQcyrALi2AB75q p7MUQTlF6ljoi9tBrucU/6Fdv99ywr/oV1B1Myx3ZeqbaGLWjawIRD+7Lvm486gAsb/l LepxQhCcHUkGP4iz7FuLjGAeNIti9aa5vjqGU= 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=MPoiFXUXoni7UDIVRHSzJHG318/UJh6QUBs0KsdqsU7ZEt66Rx6TALq+euhdRTcaVb WvY+eCGBddAKNpDuOx2KYzSERRGSswY/yibRQH/cfoza4MyeYYP9/2DiK+HFifChelUn Js1iuaP80s0/6rJ9/iW1pgON45w5P1R3Kftx91G6W3Z3EBybsYYLBlMalXpoZ0f09RWm uIRy16DtCVrhMDNTT0hnjVFXLQu9CLMQgwum/fnxoPDZjbJ5VS+Yo09yl1UEi8nTUdat dsEE47rC+7rYj2kUoadXMpNHWCYZUDe2mibf+zhWEuqwzdV50lo2eZvRLzWudV5HWhNh ELBw== X-Gm-Message-State: AOAM533eivln45L+PORwO2fDyRYJPB41FooMGC/eJoRzP43b0sEWTCaM Cyr7dy5iXxSdaaWG3gGKxA6PhwYW X-Google-Smtp-Source: ABdhPJxz3+HMXCWOhtsjpZ8Jr+r7Q6CY48Pz046yR1EW4VnUqK3FmPtezHEUvEVQwNb33ZqWC2Ajdg== X-Received: by 2002:a17:907:6e01:b0:704:8c0e:872f with SMTP id sd1-20020a1709076e0100b007048c0e872fmr32568625ejc.387.1654707087766; Wed, 08 Jun 2022 09:51:27 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:907:7f91:b0:704:cf38:c76b with SMTP id qk17-20020a1709077f9100b00704cf38c76bls1238946ejc.11.gmail; Wed, 08 Jun 2022 09:51:26 -0700 (PDT) X-Received: by 2002:a17:906:4fc9:b0:70f:8970:dda2 with SMTP id i9-20020a1709064fc900b0070f8970dda2mr24260353ejw.324.1654707086634; Wed, 08 Jun 2022 09:51:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654707086; cv=none; d=google.com; s=arc-20160816; b=IqzA2zZzV+Mf1iHR4kGYObQBbCvI0P7+OpZVRnomGANIY3lTqaJ5dh3cL5XkW8MHbT Z0AWHoM61gwYSKlhnbykpQNk1Cd+Yu9E0ojJTJImjt7rvulZmvqcSLuMCkICY/thZViG 07espZtWYRmoryObHXG0F21nFDYO6TErcH+YUkhRcJvOfwYzPSPOENBrYLTI+wz+tDoS F92aqFV/CvUN8a1C9iMJxAZ8D2Y5mGcvdKpGuVc8tqZTlJB/RXd2ryuYQc+WqBaJuuP4 Gebp15aS93Sj7lU7usLOhu9tGaBjLrqe+atfFeygt+tGM01XQM1udU+GFBJAlsxLvB2d Dhjg== 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=XwmkbsNqtkItMYxHYYHIm6uF+r70qm6mnxFwN+s1+8ErZjot7oKLD+Dy4ulalKbzxj bpOqnlqEekfb2e7tW66aICbmmJijSZ81FKlDy+z2ZaFmNYuFul5nSSKg62mnZFfMmkQv 9L0KooNON+SIHATdRsaHhW372X57CYd0QBGNBixr2wLKb77+zpdrakzjO6QekTQj/oti vg8RRTqwnEzLF4roFQU1f92mz+OymbeD2J95OT6vjWOn9ZejFRpLn4DVHt5J8ooVEqPy NCBxorWi7RIJMkWr2y3iWpE1Lb7ADzkN91iv/KurnKOQFDLsCdaiEejYODK8FXye4lWk XL+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=ofPeQ4nO; 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 m19-20020a056402511300b0042de1ae31a6sor12170807edd.65.2022.06.08.09.51.26 for (Google Transport Security); Wed, 08 Jun 2022 09:51:26 -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:1cb5:b0:42d:ddda:7459 with SMTP id cz21-20020a0564021cb500b0042dddda7459mr41312011edb.16.1654707086472; Wed, 08 Jun 2022 09:51:26 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.homenet.telecomitalia.it (host-80-116-90-174.pool80116.interbusiness.it. [80.116.90.174]) by smtp.gmail.com with ESMTPSA id c22-20020a17090654d600b0070587f81bcfsm9569071ejp.19.2022.06.08.09.51.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 09:51:26 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: Amarula patchwork , 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 v2 02/13] can: slcan: use netdev helpers to print out messages Date: Wed, 8 Jun 2022 18:51:05 +0200 Message-Id: <20220608165116.1575390-3-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220608165116.1575390-1-dario.binacchi@amarulasolutions.com> References: <20220608165116.1575390-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=ofPeQ4nO; 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 Wed Jun 8 16:51:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2031 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id A14053F1F7 for ; Wed, 8 Jun 2022 18:51:29 +0200 (CEST) Received: by mail-ej1-f70.google.com with SMTP id fp4-20020a1709069e0400b00711911cecf9sf4638548ejc.3 for ; Wed, 08 Jun 2022 09:51:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1654707089; cv=pass; d=google.com; s=arc-20160816; b=R/e001wjgun/wQXXamD5afqLDQNfcKYHyAnRbH4llXy0+wa3qRNoXd3xmeW6h1ngzv lJX80S0Onh93DGMtux5W1GI0BQWKNZby+r0z2S70ZfophBbh2dh4S+fz5kWVDl5GpEpV ozhNLUF9srPE6il4i1tKv7amcd8f0Tk5AgCuJTt/Nch2e4uNhjNS0oXiJw87JNJniCHc cVrO5o/NyVTGNddM0u3RjmkErc5yW3vVPVSWyLh7xs6Tl4od7TniksnD2rDVQjcLQ8PL bcfsOWdPcUhr/bnVyND6Onw620m1vCv75Kq70HF5P0sxrwtUod/Au/4vYdxq/1FzBDx8 jODA== 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=/UVqq1ExqN7CuSGkTFqGLAoJq1pVmGTN1oEi1z8Bgsw=; b=jNtv2izXCASydJXCWqw0706FqkhiTExvlE3lbQCYFAZa+rI7zbS5oCDaLaNwMkcDoj nV2yy8fkIZvnZHIi4mP/+1dBavG9z2aCMfnPFRcpSHD1tRAaCZyQcriULUeeXcvirwe6 +bD5OLTL7PlBhWbom/0hu/q7B04G+xJAYVj/n0uo+XnuXzDIQb2COBq/qLUl1t4BMpar gu/6GnESCX3dnMohe9rqvZePtjCvgdIYNfgFrCuU/RQ+LB6ixt3SJieo1y/tZXqGfNek oxdETOuGbuthvho5H/oaYFmCUc2flvxzr0TS7q2qq3lQTeRW+ZgsTjITlWTVHrpYsXHC rkfQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="GL2/5+TA"; 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=/UVqq1ExqN7CuSGkTFqGLAoJq1pVmGTN1oEi1z8Bgsw=; b=Oxmtcg9hVRp76n9QpWSKNYWLD8ij6u3v5YkSqp6I5Rk2GbvLtNUf8LyiiuNUpmW8ge QyEJ5cg3Df35pBjULkJu3WcSiSMoJ2FxZoltossjKH35x3bf7zPY2LNWtwFdkAh3zk6C zRg5ur32j5eblgRU2lkyjllm+aFiHY8PaWIUg= 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=/UVqq1ExqN7CuSGkTFqGLAoJq1pVmGTN1oEi1z8Bgsw=; b=SKt20TbVIWVlD20xUlndehALrF7Op2WD7ESfwfbqaCtZDMExZMr1DP0dbD2VrQpRbX X5CysLNoU1o8SK9DAjcqppnNfpIS34uVqQ6SFWoYSowTS/kE8lbAb0bGoGzjpMFbSQs9 lOFiUa16skpB/FmnuxrKRfIKyB8xfHYQ5+PRYIrJG/O+V1zUH/A5yUcTVHfSCqogUJ6d HLcRel53PMEENNYn2IQCKJBGmjbYwNVH9kx7lECgjjq/tpJ//Kr7/59vgzur9Ji2BZ6V cQVJQUbwkoeB2+rAnt/1YdbcNiIZ89BPLTLCpVsR5KjCE/48sfo8CfDUh6Y/vLQ2Ijgz bPwg== X-Gm-Message-State: AOAM530D1Kw6fCoeCGHmUUiKEjjy66bKbp5pp4GOIx1jFO3y5vaKhfjh AjWaT6OeyMoNJvZ5zgWzRbd8/Jrh X-Google-Smtp-Source: ABdhPJzgjvFyarfZntg1063MNZsYPj0J9B/s+2Ej9lOxwmAQdnxRCzxPBxY+j3QreFTXnzu/g1odKQ== X-Received: by 2002:a05:6402:3907:b0:431:6776:64e7 with SMTP id fe7-20020a056402390700b00431677664e7mr17915649edb.0.1654707089348; Wed, 08 Jun 2022 09:51:29 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:906:6a26:b0:70a:1088:57d1 with SMTP id qw38-20020a1709066a2600b0070a108857d1ls1236856ejc.3.gmail; Wed, 08 Jun 2022 09:51:28 -0700 (PDT) X-Received: by 2002:a17:906:d54e:b0:6f6:3ea:8e7b with SMTP id cr14-20020a170906d54e00b006f603ea8e7bmr32847518ejc.292.1654707088182; Wed, 08 Jun 2022 09:51:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654707088; cv=none; d=google.com; s=arc-20160816; b=QwqEWS9yUjrSWsc6w3McJ3AaMIufNKsrcaQZNJwpnATEQb4PbDtyyc4APPdYVdPg4c 72guqTqU+shGuAhOTCu/tsgg64GeXEMerOL2Yf39/oFsg+nApRIL4TMyVfx9Kj7ul9g1 Z1LY6zEev2NEdpuqvbbiBVthp2KSxcfB/c/ipxc1XMczZwuv6/bqyNhtGeMt/QOQjE4V LqdzXhqs27SciLcTRj4tcwo0fE9FJ01FX7AQdr4PneUzwnDpwz6OPNrMf0iJRcOYao3z OAWw8p25MzdOUheOCcuxCHqAP6JVTKKlmQVQrqXbo4RzxtrWmE9lEVbN1Kv1jyUy2Fms Arbw== 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=I5VTRziMnkGl4xU+BjwtCkmgql6hb+Z7QIN+Rj1ilOY=; b=lSqT6PoGgvW+ACDgK5yIYoPBVmBi0Ml2YmFhWG6V36lDsGh+VJUu2k5s8doEeq6EqR uF3yjfd4rsNoQyAhdEueggtQxZ/SeVYitXR/hhsnUp/HaDvtHslAHCMnJeiZabjgolZL VIVrrOTtqrdQDoDiQYQdLSaCk2XxOXgsELgiACsuz9F9mqtrPnPqwnOgDM3nX0LkTW/9 9HSalv4/m6SRj4YpzXU2herLttPPbr+++jTlkGKFZu71tY+9owpEJry3D3ywDJlFySfB NQD3Aya9vLzmdJd7yCdvUrI2KmatG81DkjH/Gd1iNNKTAv7DUZyjY+tdcKXcFdOsPd8J Sv1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="GL2/5+TA"; 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 d18-20020a1709061f5200b006feece1e047sor5404261ejk.133.2022.06.08.09.51.28 for (Google Transport Security); Wed, 08 Jun 2022 09:51:28 -0700 (PDT) Received-SPF: pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Received: by 2002:a17:906:9f1c:b0:711:cdda:a01f with SMTP id fy28-20020a1709069f1c00b00711cddaa01fmr16104703ejc.372.1654707087890; Wed, 08 Jun 2022 09:51:27 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.homenet.telecomitalia.it (host-80-116-90-174.pool80116.interbusiness.it. [80.116.90.174]) by smtp.gmail.com with ESMTPSA id c22-20020a17090654d600b0070587f81bcfsm9569071ejp.19.2022.06.08.09.51.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 09:51:27 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: Amarula patchwork , 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 v2 03/13] can: slcan: use the alloc_can_skb() helper Date: Wed, 8 Jun 2022 18:51:06 +0200 Message-Id: <20220608165116.1575390-4-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220608165116.1575390-1-dario.binacchi@amarulasolutions.com> References: <20220608165116.1575390-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="GL2/5+TA"; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , It is used successfully by most (if not all) CAN device drivers. It allows to remove replicated code. Signed-off-by: Dario Binacchi --- Changes in 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 | 69 +++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 37 deletions(-) diff --git a/drivers/net/can/slcan.c b/drivers/net/can/slcan.c index 6162a9c21672..5d87e25e2285 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,79 @@ 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: + dev_kfree_skb(skb); } /* parse tty input stream */ From patchwork Wed Jun 8 16:51:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2032 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 0CE6D3F1F7 for ; Wed, 8 Jun 2022 18:51:31 +0200 (CEST) Received: by mail-ed1-f72.google.com with SMTP id i20-20020a50fd14000000b0042dd305d0f7sf15316356eds.18 for ; Wed, 08 Jun 2022 09:51:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1654707090; cv=pass; d=google.com; s=arc-20160816; b=lGqr3cCQg5ArVuchsdocFRCE7uAIwEjZofn4MXqKCXYSRvZ2NUzuTH/jOKTTLeLMUd 6DbsEkPx9AT+ezDaawxrfg8fbObrxrp6XeVCcQ8GU1XIKa1hvO9aur1kLXMMn9iQbf0K tNyG7QDiep4FTt2xjfACt1Lb+1Tyfd1R+o7sbRccf+sp1WQ3SPnvme8ghw7O9r9VDTTf CoZqLfQMW9iNktjrLqJFGtcocmXtUzKeBICn/M8kkyYiZ1E1xOThey2SpKjMUZbTyPtD U3UVfprFYITKm+slaZYbTywHiT0NJQ/ZmYTaifQNyHXM+2EZdFAzcNWLC7pjTOSMOmoM uWpg== 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=VEO1kbAD6OlbMklH5DCwJ723M4x1NPceIGRug1ouxwc=; b=U+eyeGtmqH5NTAhttl8iZJnBjBWl4N+kmrj4cvUx/jsJ9K0c9Xk5WVPGEncMKMvOw8 aJ4bl5ouES/p846RbhAo1BLrEcwwqLSHdKrseHQj6Kg1jBrYeGJpt40UlTKYqdTvMLOK AijuEryNqa0o72uD4e3C40jX3S0Y+yP1oG0KWJ4PrfX4BLA1/HEV/D1K1HXWRsZwqxwJ knLKnNTdcTEYG8mk37mkR0dBxANirzOp+64kwuCpH8817GltOBmOVbK8s4hfuJCNd3dU 2GXSo9vAMFmUPy2BHnaKP9gHRFxWrMf+LNMOonMJMNdV0hC2mWLyz/gxRydp6tf8XxZN ljIQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=e2zOSGbK; 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=VEO1kbAD6OlbMklH5DCwJ723M4x1NPceIGRug1ouxwc=; b=M+cWE7/RJIM2CGzSK8bPeGInACCP6XMzAeBEooOZ0jqVeTmOWYRPoNWKRJXMp+PA0y gBm4A8tR137zyAQl8dk8Yob03LOTH4kW+M0Mc44J9Xag5TUBnyzOUTPg8kEMheA/fAXp u0mVibHDxWueC0JsikPd85gg8ZEwlHBWyrqeg= 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=VEO1kbAD6OlbMklH5DCwJ723M4x1NPceIGRug1ouxwc=; b=Krnl3qC43DBk3CEAnH511kr9IKhnkih5ifRJYEnJ0As1XzM7LdSW5jX8Vfc1ZqIIUH 8P2qeYUA7E/aV3a4pwSGHJjUFv+9CPgs9h83AdjkVK9hjNeBKddgwMFX72IC9L4olqhJ uUxSb3Es6+jc+RbqZG+zaa6NiFpF0oO1ZnRhungmYrtWmNVch1gt2iR5MN1UKKZCaRrX AXJ+nRs6bBe4Sc4gt7LE2RMy/fVxO3Cqzn6u2A1WeYsyqq1Wh+mY2j4/0njKvUdUWSyZ wBSt+QQuyiGCu9CNJCOYTbveuj1A9+WxvcYN4rBhiNqAxXIFSOzdv4WvuGk+l8uuTa1l NDUQ== X-Gm-Message-State: AOAM5314vP5+vsepE+HnIZajyopFKCpEP89yywJpF1UAEPzS+NMaq3dj EPohtT3rrZEG4/0QQX4BRf1C3+iW X-Google-Smtp-Source: ABdhPJyp6xzI8o4cKBpRvgD8RDYWvFVQlcJF10zsMfOxZ6vfsrugw60lCt212qJ2N1EUciZEbH5ELA== X-Received: by 2002:a17:907:930:b0:711:da36:62f7 with SMTP id au16-20020a170907093000b00711da3662f7mr12023738ejc.468.1654707090811; Wed, 08 Jun 2022 09:51:30 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:5414:b0:431:6a31:654d with SMTP id ev20-20020a056402541400b004316a31654dls189605edb.0.gmail; Wed, 08 Jun 2022 09:51:29 -0700 (PDT) X-Received: by 2002:a05:6402:528f:b0:42a:c778:469e with SMTP id en15-20020a056402528f00b0042ac778469emr39799978edb.404.1654707089684; Wed, 08 Jun 2022 09:51:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654707089; cv=none; d=google.com; s=arc-20160816; b=UP2NkACMe8Leuz5qEpRargWSHR+O/5Kgt80OBpwHEqBpy6Ek4eTUSMDKe69xsTTb/I noSqjmIHSNpmf2MaOOYV24k+aoPz8WXp3ZRxo41IYVXls16Q5Rhw6bzjfgKf6eWf0Bla Ww2N3EiCFK3K0Jnuo/AOBlsWeH4eSie2BmUHTMjsoX0srUtUXdpH7H3B3HgsaYlOCfgV 0B3zNEazg1MuKWn8rkrfFj6W5bzGS2hrHg+C1Pyi2KmDPx34wKY4rA1UmDyiWxjs6DJf 1meKIPx0j2JnXIRpzqmamZ4djyhfySy4jJF+4Pv3gGCfy4VMttWCwFsnEczP7K8mRx+R YCmA== 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=c+3GCirlvyznBBrVu6oPXaX+KYWRV3Xhpy2k9G10VWo=; b=Cx5BtvHO/mwR/BPzulJVTqkV/1vxDtf2wc5PEI/6ebpZdSEPoc29xMUJqZN27jVXRw BexxV6WKI+RYz/brXV6QwoX5a3bUE4Ww+kF+XU+bKIqD90A5+ukRBSIUv+yVJbGbTln9 EmgU1L04SYvcGzln0Q5rZmsb1pR6ZSnuK1JXoF+5f2IXBkAjJYUF5Ql3i7t98gh261wR 3cv7pzmLSFXtv/5cYNIIfMZdiUavMclyPltekzlgRNiAEcSjWblZzyBuqeobv18uSUvt YAfwa7E1EaGWh/wWUCetqKwDv+/CUGCL8cLDxQ8eDYTaGKAFn5Qhgt+QSkCrTFRlNZAd ztOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=e2zOSGbK; 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 y3-20020a17090614c300b006fe220ad732sor10107832ejc.81.2022.06.08.09.51.29 for (Google Transport Security); Wed, 08 Jun 2022 09:51: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:a17:907:1b25:b0:6da:8206:fc56 with SMTP id mp37-20020a1709071b2500b006da8206fc56mr32386194ejc.81.1654707089355; Wed, 08 Jun 2022 09:51:29 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.homenet.telecomitalia.it (host-80-116-90-174.pool80116.interbusiness.it. [80.116.90.174]) by smtp.gmail.com with ESMTPSA id c22-20020a17090654d600b0070587f81bcfsm9569071ejp.19.2022.06.08.09.51.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 09:51:28 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: Amarula patchwork , 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 v2 04/13] can: slcan: use CAN network device driver API Date: Wed, 8 Jun 2022 18:51:07 +0200 Message-Id: <20220608165116.1575390-5-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220608165116.1575390-1-dario.binacchi@amarulasolutions.com> References: <20220608165116.1575390-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=e2zOSGbK; 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 (-1) before it is called. [1] 39549eef3587f ("can: CAN Network device driver and Netlink interface") Signed-off-by: Dario Binacchi --- Changes in v2: - Move CAN_SLCAN Kconfig option inside CAN_DEV scope. - Improve the commit message. drivers/net/can/Kconfig | 40 +++++++------- drivers/net/can/slcan.c | 112 ++++++++++++++++++++-------------------- 2 files changed, 77 insertions(+), 75 deletions(-) diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig index b2dcc1e5a388..45997d39621c 100644 --- a/drivers/net/can/Kconfig +++ b/drivers/net/can/Kconfig @@ -28,26 +28,6 @@ config CAN_VXCAN This driver can also be built as a module. If so, the module will be called vxcan. -config CAN_SLCAN - tristate "Serial / USB serial CAN Adaptors (slcan)" - depends on TTY - help - CAN driver for several 'low cost' CAN interfaces that are attached - via serial lines or via USB-to-serial adapters using the LAWICEL - ASCII protocol. The driver implements the tty linediscipline N_SLCAN. - - As only the sending and receiving of CAN frames is implemented, this - driver should work with the (serial/USB) CAN hardware from: - www.canusb.com / www.can232.com / www.mictronics.de / www.canhack.de - - Userspace tools to attach the SLCAN line discipline (slcan_attach, - slcand) can be found in the can-utils at the linux-can project, see - https://github.com/linux-can/can-utils for details. - - The slcan driver supports up to 10 CAN netdevices by default which - can be changed by the 'maxdev=xx' module option. This driver can - also be built as a module. If so, the module will be called slcan. - config CAN_DEV tristate "Platform CAN drivers with Netlink support" default y @@ -118,6 +98,26 @@ config CAN_KVASER_PCIEFD Kvaser Mini PCI Express HS v2 Kvaser Mini PCI Express 2xHS v2 +config CAN_SLCAN + tristate "Serial / USB serial CAN Adaptors (slcan)" + depends on TTY + help + CAN driver for several 'low cost' CAN interfaces that are attached + via serial lines or via USB-to-serial adapters using the LAWICEL + ASCII protocol. The driver implements the tty linediscipline N_SLCAN. + + As only the sending and receiving of CAN frames is implemented, this + driver should work with the (serial/USB) CAN hardware from: + www.canusb.com / www.can232.com / www.mictronics.de / www.canhack.de + + Userspace tools to attach the SLCAN line discipline (slcan_attach, + slcand) can be found in the can-utils at the linux-can project, see + https://github.com/linux-can/can-utils for details. + + The slcan driver supports up to 10 CAN netdevices by default which + can be changed by the 'maxdev=xx' module option. This driver can + also be built as a module. If so, the module will be called slcan. + config CAN_SUN4I tristate "Allwinner A10 CAN controller" depends on MACH_SUN4I || MACH_SUN7I || COMPILE_TEST diff --git a/drivers/net/can/slcan.c b/drivers/net/can/slcan.c index 5d87e25e2285..929cb55e08af 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 * @@ -373,7 +374,7 @@ static netdev_tx_t slc_xmit(struct sk_buff *skb, struct net_device *dev) spin_unlock(&sl->lock); out: - kfree_skb(skb); + can_put_echo_skb(skb, dev, 0, 0); return NETDEV_TX_OK; } @@ -393,6 +394,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); @@ -404,21 +407,36 @@ static int slc_close(struct net_device *dev) static int slc_open(struct net_device *dev) { struct slcan *sl = netdev_priv(dev); + int err; if (sl->tty == NULL) return -ENODEV; + /* The baud rate is not set with the command + * `ip link set type can bitrate ' and therefore + * can.bittiming.bitrate is 0, causing open_candev() to fail. + * So let's set to a fake value. + */ + sl->can.bittiming.bitrate = -1; + err = open_candev(dev); + if (err) { + netdev_err(dev, "failed to open can device\n"); + return err; + } + + sl->can.state = CAN_STATE_ERROR_ACTIVE; sl->flags &= BIT(SLF_INUSE); netif_start_queue(dev); return 0; } -/* Hook the destructor so we can free slcan devs at the right point in time */ -static void slc_free_netdev(struct net_device *dev) +static void slc_dealloc(struct slcan *sl) { - int i = dev->base_addr; + int i = sl->dev->base_addr; - slcan_devs[i] = NULL; + free_candev(sl->dev); + if (slcan_devs) + slcan_devs[i] = NULL; } static int slcan_change_mtu(struct net_device *dev, int new_mtu) @@ -433,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. ******************************************/ @@ -513,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]; @@ -530,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; @@ -572,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(); @@ -604,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 */ @@ -620,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; @@ -657,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) @@ -767,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 Wed Jun 8 16:51:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2033 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 475863F1F7 for ; Wed, 8 Jun 2022 18:51:32 +0200 (CEST) Received: by mail-ej1-f72.google.com with SMTP id kf3-20020a17090776c300b0070d149300e9sf7261529ejc.15 for ; Wed, 08 Jun 2022 09:51:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1654707092; cv=pass; d=google.com; s=arc-20160816; b=PCqvguRS0J5+XuUw0y09NrRdDA7XGqWro1EWjA1BKKqY+sPQs4gge9MjibAjbocaSI pJQAVNGDOx6x3WNNzHcuiOUl15vytOElnWZLkAXHncAZvCgNL5tcz6FTEVmLIAU2B4CM YF5F2a9mRS/GowB1P63m6CnqnOmc0e0eYhzJeR+YKv1nqBLl4PjLJSgwFRR0NPBm+fkN RkJMtZpl1g6o/LWyWUapijMghMn9syz77b48PWerUNVkZvbi97IbPFNuB38EjOUmrpqE kM+EJ/ExOaYEha8wc7pkFApRo3K06ujkZJvIdVQZIgi39f6RRJwrSXjY34cW5cJ0Sb5h cVAg== 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=dnCzPY6STum6y3H4fySaIlCLaVvsqQN2RRnZjH91iy4=; b=P8ZhUhw6Omd+dPqzp4pqpCei5+ghTSMLtFuHyIRHMycjWMjBwJujkJTZ8oKCeCnoIZ UWwoQJLoRqAAJTbRkMVU9vC5bLSxGtevwKjnE+x/5t0YJoc1iOZ4CQQowaX8orWN0D+2 Fz3hWJ+66x1Hq5oop/HP6uDTnA+/FuDdznT2bFCoFimMaHvUWQpq/BVaGrJ5zG7CDzPW iztxOkzVd2mL6hYWU37j/1rsk7DyOBQjqRpp+dAQOU6zZ9n35dSOqiXJOmB2MgyFSdLi SdV+NzCvRs6J8yPq95DV5VnZ87vg/7VAWB2vBACERgTmIIGv0J1TPcdZ3toYmv+xorTb RU3A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=EbNQlONL; 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=dnCzPY6STum6y3H4fySaIlCLaVvsqQN2RRnZjH91iy4=; b=j8z6mmC8d4aJS1QclK/Sx5PtG/x2mIgJ4naklo57mlCe6TvGbAhOQjv/dDMKNJKvuV VApxILYcCa5jSQLDLTRa7u1xYYHhl9wIGy5Vdw7XspMnLVE8VYKn4LdOJALjDojNhol+ aBoWVtrukmrf700IJv2ZEQh0KKOft/zB6Eolw= 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=dnCzPY6STum6y3H4fySaIlCLaVvsqQN2RRnZjH91iy4=; b=lG4CVS26T992wWnsKy/cLMSi5xK/fE5U4J+ce7G0FqLGwkLJkYT1wCeiWR96KJ4CLw kRTBucDFBtqh3cpUmpnlpi6pGenKdeYIEcRTTkBJwPxBJmyVgwwDDehvOt1cmHzJYvLO /CW9aeUghDIJMrETKeVXygyE23+Rq7pSeWTB9ATCQJuhM8IOIjj3/6FQ3ZJ2jIfYuZ2q imLpWGi/SmjI1m6JZffNmO7ZVd9jSSaWVwKmBPtrrkSe060fiz4MjYMC5VDbyJL0Jj2S kJYfHeDT7jDfdqK3Vxt8xuEkkGlAKyJOrcw9oTLVBRe3ES/RsNBWoBeAUPre5IZ2oRKV 2OiQ== X-Gm-Message-State: AOAM533wS0mercnRKdFmihBnmIbU/d4OfNhGUadJnnzm1XNQJ4C0tWpr eRxSdM7JlR9vUCS+fdNpPo7Ejpbk X-Google-Smtp-Source: ABdhPJw7Ksl7qNx7zNMvX7F+gs7UKG1BowxMIPIiiHYeBJllnk19hLx7xV2Y1RJnT8rh2u7nNnEScg== X-Received: by 2002:a17:907:72ca:b0:6f9:8675:6a2a with SMTP id du10-20020a17090772ca00b006f986756a2amr32650902ejc.98.1654707092100; Wed, 08 Jun 2022 09:51:32 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:906:6a26:b0:70a:1088:57d1 with SMTP id qw38-20020a1709066a2600b0070a108857d1ls1236926ejc.3.gmail; Wed, 08 Jun 2022 09:51:31 -0700 (PDT) X-Received: by 2002:a17:906:52c7:b0:6ce:a880:50a3 with SMTP id w7-20020a17090652c700b006cea88050a3mr32466555ejn.437.1654707091023; Wed, 08 Jun 2022 09:51:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654707091; cv=none; d=google.com; s=arc-20160816; b=e3flWMP8wKCbE6mO9Wnk8MCTy4gPyiwiD5LwlmGKaliDKi53f+ecsohk1At3JmcHsa yBbkPgWXMPmu3W9ujoL6DhYYPANIhoQSYLuQp66NmfEdqhm1BNV4WgqEmzQtg+XiuTKI DUV+AEaPNbDpawsjy7qzyTAYahHfvdQS7Qx4d5Suv7Aqy/wF5ILeLB+wMYfwqWD4nvQ0 GDQadWtlaA0+PwbVnWMY8aKc/+W+q5pyT8Wo1vQBLjbI5HYW3iMP6NlvjgQhyFTIJDHw Yphv2dDxD7D+KvdBLibZA0RoXClB3Ovo46ZmmWuZRIhVF7I5J6O6eh9RcMhz07MrLCFw kPKw== 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=nVyQpX+Yrz3qKt1Nh+jQPIqCDb+sgmjzafkew5xQQck=; b=VQxBBSI4DsEWCToXyNYyxaqZqdDkJnRZ9Mvh3Zp4GxLxv2AmxsljWbR4P+/YgsICAd qjP78Db/1P9sKPgm/U0372LctTIfT148YqhK71az8hgZIn74BphIUD52bbGSR0DMn6Sl 9BAPpoXjQqOf+GPdDcA9xClC9TQSiz8N6wkQeE5Xdes5Zxe2rLsAt3rbxQy2nq4a3zwJ uxZqZ24EWnlc1EC8rlVIQ3rDR2U5dijW5AByfrd8sYTvaUTK2OZJD2Hlok9829L6HAPO GYotz6KHyhCozlKKGNDzCXdb19KeMR5sMWLJSRspwnwC2j/yP+lj0lhpXHQaLAKOGwSB fzsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=EbNQlONL; 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 p23-20020a170907911700b00711eea1f458sor1707183ejq.30.2022.06.08.09.51.31 for (Google Transport Security); Wed, 08 Jun 2022 09:51: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:a17:907:6e13:b0:711:c722:4fc with SMTP id sd19-20020a1709076e1300b00711c72204fcmr18014645ejc.253.1654707090839; Wed, 08 Jun 2022 09:51:30 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.homenet.telecomitalia.it (host-80-116-90-174.pool80116.interbusiness.it. [80.116.90.174]) by smtp.gmail.com with ESMTPSA id c22-20020a17090654d600b0070587f81bcfsm9569071ejp.19.2022.06.08.09.51.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 09:51:30 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: Amarula patchwork , 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 v2 05/13] can: slcan: simplify the device de-allocation Date: Wed, 8 Jun 2022 18:51:08 +0200 Message-Id: <20220608165116.1575390-6-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220608165116.1575390-1-dario.binacchi@amarulasolutions.com> References: <20220608165116.1575390-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=EbNQlONL; 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: , Since slcan_devs array contains the addresses of the created devices, I think it is more natural to use its address to remove it from the list. It is not necessary to store the index of the array that points to the device in the driver's private data. Signed-off-by: Dario Binacchi --- (no changes since v1) drivers/net/can/slcan.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/net/can/slcan.c b/drivers/net/can/slcan.c index 929cb55e08af..cf05c30b8da5 100644 --- a/drivers/net/can/slcan.c +++ b/drivers/net/can/slcan.c @@ -432,11 +432,17 @@ static int slc_open(struct net_device *dev) static void slc_dealloc(struct slcan *sl) { - int i = sl->dev->base_addr; + unsigned int i; - free_candev(sl->dev); - if (slcan_devs) - slcan_devs[i] = NULL; + for (i = 0; i < maxdev; i++) { + if (sl->dev == slcan_devs[i]) { + free_candev(sl->dev); + slcan_devs[i] = NULL; + return; + } + } + + pr_err("slcan: can't free %s resources\n", sl->dev->name); } static int slcan_change_mtu(struct net_device *dev, int new_mtu) @@ -533,7 +539,6 @@ 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; sl = netdev_priv(dev); /* Initialize channel control data */ From patchwork Wed Jun 8 16:51:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2041 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 5AD953F330 for ; Wed, 8 Jun 2022 18:51:44 +0200 (CEST) Received: by mail-ed1-f69.google.com with SMTP id co13-20020a0564020c0d00b0042dc9ef4f01sf15262071edb.16 for ; Wed, 08 Jun 2022 09:51:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1654707104; cv=pass; d=google.com; s=arc-20160816; b=CHa5m9TNVR9PWSPn678TcWcUJr/HQa+nVPMYER/8UczIGJGXYxuA3hjq8Feci5qP/m 46DuMqYyvfIu/2vOjk2DA8g7HzfgzUYRThGdJ9jWFRuFU0DwYTakPnC4nCSpO6gcQBjn KxO4kyjnucOt10PO9m+m2ITVvJTuJi0v2FgCENsrqE2rxhiGBWZA0kbq5fLcI9haYP8h OFfpT15j+NUJ+zQz7Bz0lD9DOzyts44IHI1aFD/A7gpPtWWGl0DbhdOFWGpiiGL8jBcE d8k9WyJtcSpAt+6RsdDBQVsbzKR4BitEzv2SGpGLF5vyQrPpYxwCMUEkh74vGTlHYL54 J0hQ== 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=FIjJKTRgTKgrU4ee4BbFoa1Hl/2Qbs8t5OrC6rfoY9k=; b=kp1IqwAUGFN2hHAbqFdDEMflPNdqFb3K9DEgXPZ8RPUJXzvU+Whl7DDi7RHhvD/gzI 5I8fT0qqMLsOexSIL2W19ymjdj1qWafzZx66ggCJasTIouWKrU6bA/qOI1mOdHrimzs0 vbY0I0eHVAm8ajS3mL1SPMXHLdHwGEvm+LEF5Nq+mbAJy7v6Ariz8BuhCdqAZgME4ohr OQ4gcCQ0DxlfEDGHmxzpvhI+ONurTZzwUiIW+fQgKBZT8Kuuke/WWHyMuo6g5jW1Z+fC I7crHETiwgvDrbYCLU044DUtkdXDY//UActdAtH4Klj3RwOED9GdC3f25YpjykyVqiNh NK3A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=OSyMEpVo; 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=FIjJKTRgTKgrU4ee4BbFoa1Hl/2Qbs8t5OrC6rfoY9k=; b=iNa9D/Jo45KT+Leyr8kU8zTMfR0BKc/F3KDLH3GgGfDrQoZHY66kQK9O0d6l4G3aqZ 7+QeNwGInpsiMQqlptF70Y8rbqKdKpbJ59fzltvAS54GLS6vMKX0PSpE0jtT548Z1nMu oJU5xln0HLpHN1pyC+bZ1y5BMTxRhJk4mDCKQ= 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=FIjJKTRgTKgrU4ee4BbFoa1Hl/2Qbs8t5OrC6rfoY9k=; b=aOqmoA+yHKp1eVesbwDTjm/IKKblSGq1bww7/qkSb1zatV+nmrac4EaQm4OgohLJA0 7efpVFdfOgLzAwGMpLdanWMrJp6cVgKit1o7B15gBcvS4B+gf1aBL1uctqXhIQm5BfvM qQEnfcb11SRmB/9rtclx3I9kVAUNh8Z7Lb4ucwMlepnjDYUk7KHilr/+atT5L5n8At0d lrTOFqwKSICMjOv6isj2FDIA2agekOzCg744I4ecIaUMlIPoPhXG/p2D3S8mNQ9by+1s V7eB6ExnTDMa8X6Pt/0FTnGNZ4pZwfFQn9+DMZU2ja9mWRAGvIanFrD42VL7KrE4NuVv NLtQ== X-Gm-Message-State: AOAM532p2wO8fyFSCjuapfyOHjIn2eehrouaIKaOgT7VaKDPm8XrKVj1 Um8E1rmjfa+Z3RXRKYXWXWFrePDG X-Google-Smtp-Source: ABdhPJwT6AvKQI2iT1SmwVfpxyfUcMKPtXWtmSw2CZqdvbnfU8xmZ7oh677pOCH03zLzlLFAYPAKrg== X-Received: by 2002:a05:6402:f05:b0:42d:d709:b497 with SMTP id i5-20020a0564020f0500b0042dd709b497mr40085575eda.231.1654707104197; Wed, 08 Jun 2022 09:51:44 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:907:7f91:b0:704:cf38:c76b with SMTP id qk17-20020a1709077f9100b00704cf38c76bls1239308ejc.11.gmail; Wed, 08 Jun 2022 09:51:43 -0700 (PDT) X-Received: by 2002:a17:906:d512:b0:707:bdab:ffa2 with SMTP id cq18-20020a170906d51200b00707bdabffa2mr31937513ejc.766.1654707103138; Wed, 08 Jun 2022 09:51:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654707103; cv=none; d=google.com; s=arc-20160816; b=XvFr19KwQcy6IcbL1G1PYitxYgclq2SiQXZpxko48OPGsoRH6jgP0ozg5Nsw686RMH Lo1sC7zmT0LS6UvA+mXYnLm1igKIyuFditc8YdxpLb1wuVpZRTK83vdCFBY0ckFQAjqo MJ8Y+9EX/Ag5nvS656C1rULQ2+oPJ8Qq/IT3oZPOBBasC9kAPs+0yuE5J0wkZ3zuSU3z +j3M/M3iKihKnC22atjVFP2ZFmkhVn6m7cKIcHgMX4e4E/6DdDt4X4jPqUwpp8qTDwwI HM4TrY102BIFRpTdZ1jgFpJVAhDjn96KvnWwHGYxDAlYkyK3yXs918BteVSSXq4v9+sa +RLA== 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=MTTwzX/aiA/HRTscWPld7sV0y4pSfK/bYOnDrdN63VI=; b=EUFr0eEsUBT5y64WmDtp9kQ2y/tqYwnMalKgZb3+3ssHnfEFi41IEoGVV1RaJOv86e bxr84JCRPYaLHw799fxixeiptkjlOqII6iVLPFBciEqB2CTxwr4wDFTKGX9MDOXBab60 GOLJXrz5CRa8Skrh4Y9gdfM0n82Om4T3Og6lMg/rF+eX4HaxVmhexHqQ7ua+rjeRnJrR wH0D62EQOcrMGr+2xtNyN22Ppd92SPuP9UaqiQuxW9lgOXcqvgVUKRKxThlWRRn8GQz9 Kzowg33HyzugMKCQ+HEDvgQCt4cSRun9dHfntz4qNtC2rI3n8d9f+VhelLCxFXkGBypq /VCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=OSyMEpVo; 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 o11-20020a170906600b00b006ff8320841dsor10162280ejj.92.2022.06.08.09.51.43 for (Google Transport Security); Wed, 08 Jun 2022 09:51:43 -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:f97:b0:431:8d1d:397d with SMTP id eh23-20020a0564020f9700b004318d1d397dmr11248102edb.423.1654707092277; Wed, 08 Jun 2022 09:51:32 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.homenet.telecomitalia.it (host-80-116-90-174.pool80116.interbusiness.it. [80.116.90.174]) by smtp.gmail.com with ESMTPSA id c22-20020a17090654d600b0070587f81bcfsm9569071ejp.19.2022.06.08.09.51.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 09:51:31 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: Amarula patchwork , 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 v2 06/13] can: slcan: allow to send commands to the adapter Date: Wed, 8 Jun 2022 18:51:09 +0200 Message-Id: <20220608165116.1575390-7-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220608165116.1575390-1-dario.binacchi@amarulasolutions.com> References: <20220608165116.1575390-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=OSyMEpVo; 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 some commands (e. g. setting the bitrate) will be sent before calling the open_candev(), the netif_running() will return false and so a new flag bit (i. e. SLF_XCMD) for serial transmission has to be added. Signed-off-by: Dario Binacchi --- (no changes since v1) 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 cf05c30b8da5..cab0a2a8c84c 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; @@ -314,12 +317,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++; @@ -383,6 +396,36 @@ static netdev_tx_t slc_xmit(struct sk_buff *skb, struct net_device *dev) * Routines looking at netdevice side. ******************************************/ +static int slcan_transmit_cmd(struct slcan *sl, const unsigned char *cmd) +{ + int ret, actual, n; + + spin_lock(&sl->lock); + if (sl->tty == NULL) { + spin_unlock(&sl->lock); + return -ENODEV; + } + + n = snprintf(sl->xbuff, sizeof(sl->xbuff), "%s", cmd); + set_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags); + actual = sl->tty->ops->write(sl->tty, sl->xbuff, n); + sl->xleft = n - actual; + sl->xhead = sl->xbuff + actual; + set_bit(SLF_XCMD, &sl->flags); + spin_unlock(&sl->lock); + ret = wait_event_interruptible_timeout(sl->xcmd_wait, + !test_bit(SLF_XCMD, &sl->flags), + HZ); + clear_bit(SLF_XCMD, &sl->flags); + if (ret == -ERESTARTSYS) + return ret; + + if (ret == 0) + return -ETIMEDOUT; + + return 0; +} + /* Netdevice UP -> DOWN routine */ static int slc_close(struct net_device *dev) { @@ -546,6 +589,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 Wed Jun 8 16:51: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: 2034 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 31E893F1F7 for ; Wed, 8 Jun 2022 18:51:35 +0200 (CEST) Received: by mail-ej1-f69.google.com with SMTP id v13-20020a170906b00d00b006f51e289f7csf9613150ejy.19 for ; Wed, 08 Jun 2022 09:51:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1654707095; cv=pass; d=google.com; s=arc-20160816; b=0BRAf402UGC/2imTAQoyE/wffUotN67oMlfP3hnb/mgSy14R4H2e/2JX28zZ3fD2CV g+uLtx5VL0axAZ/hfscmJMTVmcvjs0SLCDEZQm3ge+XozCE+/INm7arlrMqARdKTJ+zj m62iarKYkdu9Cmh1RUaSvXsWbjxcFtLjTTF/lTaLihuDBt1HWeaweMkx8ylEGMU/zHyn wq5HOGdNgjFmVmF0CgsIvTupg89Mf0N4xfffVKXCdd4DMWKX9DM7GJhQUqnRjvumNQnn DLEwqEDLiHKfld/w32J5JkJCJvluMep/lkKw/lLG2P2KrGVPJgg/7HShqQ3KKAkyVx6W 7SeQ== 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=msNajhLG122r6fMwXF5Zs4lvJK/uokjV5NpX/8Te3jo=; b=siNZX9+/o7uN7KwhHnNrX90Cnw4XCeDQpUDy7sBPRTejkiPbzI0cAmAlefZmEsVnHF 7lpO1NEOFqOSBG/YB6l+J3XRc2JQG18ozyoi4WfMfO0C9NcVpzfJTUBPgKSIK8HPHTNx 0BC9HbVDeN2bjshg9ph3QHFMYrRjHLtvZkUAeyXfGkBxmONn4zVIE5ohzMXhYPlMwGqI ZVlWMhvvJF9mTzWRIj7/9qJ+PF+KRgLClNz2ewQUv9fDFwEVEDMeqF9GOe+TPFGJkKpQ d2uvgfEphC6wY2rNSKjqj+nqn2hxuAR45X6EVLgR2H3DR/I1F3aFKEiH0CFfnrazJSgt UAgw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=orhsCgXR; 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=msNajhLG122r6fMwXF5Zs4lvJK/uokjV5NpX/8Te3jo=; b=mvo5yZllA+d+6XHMp7VIk/6Acouztm0PaaZSMp7k8lrRsgAahPTR5DRY2PDEsHHOBi ROhDOoSx7oGhMURkexrb8KwTMXyWmWSJh+w4J/cdpHLnms1/Lqr7hwzFoUmQ7JWPe6SU fQGH8mcpl/NOTuOkAhIFoPCoYiQlB0xRpfmM4= 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=msNajhLG122r6fMwXF5Zs4lvJK/uokjV5NpX/8Te3jo=; b=2fozzpQa+QxBxCLZEEiX9NvdaxgAYZMqtSgSD4H7FlbUAt8jtt5A1wTdqz/6mGsQmk /wkMK6MC73B+g7wrIGrewxCYeHyaQRXLafmzHhgVrK01zOIE6TysOF4uBOld8RFv/M5D jPYspJgTOz7/zSPcg5eKVaf4r/pu52Ljd95SEhLcyzLIjpUWQ0QbJD/hrxNPN9ZlDUau amcuI10NR+VpWRXf5VLyg6U314rRjk5CaEdHn49lsQuMe96C/+lF9LeF1gJBlhgYtZBQ WeE1Lyq9H4T6bzZGsp5jRT1tIyZ7m9s6KX86yCqVcHDPNDXyuQYgEAxzezNucfvNqNYt kN/A== X-Gm-Message-State: AOAM532c9ZmVL6SYtVvd1a0JIe4igOesRuo+S7dCRXuf9/gY5VFy7G5a HEK9OK6xL2Hij5rditsvbsDCVX4j X-Google-Smtp-Source: ABdhPJyesX0KA7NvuOSJjzyOG6b2lk7eJ3hdriKNqXnK2oCJQ6wnw3jlQNAxMsXEWYyIisdaB0rxeg== X-Received: by 2002:a17:907:3e1b:b0:6fe:e1a4:a331 with SMTP id hp27-20020a1709073e1b00b006fee1a4a331mr31957957ejc.72.1654707095010; Wed, 08 Jun 2022 09:51:35 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:2741:b0:41f:7eee:e393 with SMTP id z1-20020a056402274100b0041f7eeee393ls188932edd.3.gmail; Wed, 08 Jun 2022 09:51:34 -0700 (PDT) X-Received: by 2002:a05:6402:c1:b0:42a:b8a5:8d5e with SMTP id i1-20020a05640200c100b0042ab8a58d5emr40657030edu.266.1654707093866; Wed, 08 Jun 2022 09:51:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654707093; cv=none; d=google.com; s=arc-20160816; b=Ji73G0Olb9MgLkyk6sXHzezBNLKIxkaEK6vF4xgqMVq/dZhXTRgcW3zKXwCcPt+9q/ O+DX2wphLUfj8Xy+MYM4AhEmWzL0/MYNOw1SyU+08ao5fwFG0OFdaYbQUBW3GU7Zsbtx QvKRnVIqolHVB+xFUVRtIEmWq8FLHrtjhpGEqW+1YiZWybd14AhMbwLtvMdH/1SE04Gj Z1H/muMXnnjbvoyJzmnfGjXA51QKGvsifYwNlgu5RiITGEOhlh22X8N1vc0xms9PUwse cK7Xc33HokZEnZyBiAbbR2kRMIQHGBpULa3QKIgrni8xUJrclqMyqo15HQvxstrA7RDF xyNQ== 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=5gQL+PBjKdFRbWGXqCko2W4l6SNrb34I5/OqJqVjfAw=; b=mTWEYiws28QbLxWKMpd7xVnNYvRzIL6gfwWUGftn4wrOJPf0dpBenZft+Dq1j4Zc99 BEEEZ4dGKC6O/Y//7FMr9gV7aQDJKoQOvElnttDx/8R3uPnbWqj9XkHiBSMoB6EyqmYh Hi9q8t9zk991LRtqsmfIIcG121WrktS6xEXCSEdVnNDDMXfE6AB2KW2YXUVLj3Z/Znbx OhdUq7B8Ds92OtX2AwUhn9o3KlvVeYmRfPm6PZmZUKhZJKdUyI5BdswEzV8BqcO2QWCa FB/vKFBYrNRlmkbJOneEj46s8Dt1KNChq8QPfF0HPsqmbHrc8ehl0izqYcsG/mz0xX02 i0jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=orhsCgXR; 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 f14-20020a1709067f8e00b006fa8e1e0684sor9725462ejr.37.2022.06.08.09.51.33 for (Google Transport Security); Wed, 08 Jun 2022 09:51:33 -0700 (PDT) Received-SPF: pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Received: by 2002:a17:907:6d9b:b0:711:d26b:f5ba with SMTP id sb27-20020a1709076d9b00b00711d26bf5bamr13923231ejc.135.1654707093625; Wed, 08 Jun 2022 09:51:33 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.homenet.telecomitalia.it (host-80-116-90-174.pool80116.interbusiness.it. [80.116.90.174]) by smtp.gmail.com with ESMTPSA id c22-20020a17090654d600b0070587f81bcfsm9569071ejp.19.2022.06.08.09.51.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 09:51:33 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: Amarula patchwork , 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 v2 07/13] can: slcan: set bitrate by CAN device driver API Date: Wed, 8 Jun 2022 18:51:10 +0200 Message-Id: <20220608165116.1575390-8-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220608165116.1575390-1-dario.binacchi@amarulasolutions.com> References: <20220608165116.1575390-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=orhsCgXR; 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 v2: - Use the CAN framework support for setting fixed bit rates. drivers/net/can/slcan.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/slcan.c b/drivers/net/can/slcan.c index cab0a2a8c84c..8561bcee81ba 100644 --- a/drivers/net/can/slcan.c +++ b/drivers/net/can/slcan.c @@ -439,6 +439,7 @@ static int slc_close(struct net_device *dev) netif_stop_queue(dev); close_candev(dev); sl->can.state = CAN_STATE_STOPPED; + sl->can.bittiming.bitrate = 0; sl->rcount = 0; sl->xleft = 0; spin_unlock_bh(&sl->lock); @@ -460,7 +461,9 @@ static int slc_open(struct net_device *dev) * can.bittiming.bitrate is 0, causing open_candev() to fail. * So let's set to a fake value. */ - sl->can.bittiming.bitrate = -1; + if (sl->can.bittiming.bitrate == 0) + sl->can.bittiming.bitrate = -1UL; + err = open_candev(dev); if (err) { netdev_err(dev, "failed to open can device\n"); @@ -558,6 +561,37 @@ static void slc_sync(void) } } +static const u32 slcan_bitrate_const[] = { + 10000, 20000, 50000, 100000, 125000, + 250000, 500000, 800000, 1000000 +}; + +static int slc_do_set_bittiming(struct net_device *dev) +{ + struct slcan *sl = netdev_priv(dev); + unsigned char cmd[SLC_MTU]; + int s, err; + + 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) { + sl->can.bittiming.bitrate = 0; + netdev_err(sl->dev, + "failed to send bitrate command 'C\\rS%d\\r'\n", s); + } + + return err; +} + /* Find a free SLCAN channel, and link in this `tty' line. */ static struct slcan *slc_alloc(void) { @@ -587,6 +621,9 @@ 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); + sl->can.do_set_bittiming = slc_do_set_bittiming; spin_lock_init(&sl->lock); INIT_WORK(&sl->tx_work, slcan_transmit); init_waitqueue_head(&sl->xcmd_wait); From patchwork Wed Jun 8 16:51: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: 2035 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 758CA3F1F7 for ; Wed, 8 Jun 2022 18:51:36 +0200 (CEST) Received: by mail-ed1-f71.google.com with SMTP id k21-20020aa7d2d5000000b0042dcac48313sf15341547edr.8 for ; Wed, 08 Jun 2022 09:51:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1654707096; cv=pass; d=google.com; s=arc-20160816; b=b2rZSXMHu5cNMrAlHgEpdNYnX+czg3B5NFqgQm4+gJoB2fGe0FiQqPN4wTfV+cTl6n K20JDvdZxCrNw19i3X5Nr9jXNaAc4aEyPB0hQjcOhl2OaxkrGVQMjev6/b+0GOBkAbYb xlm2hYCa06MGAn0/e+reoRqBiWC4upzC77PbP1Yflx4qmVUSpWU+O0rnwe02ZcnjlVTl Ba/KkZC6ojJ8VEiYBtP/wC/hx59eoGkc85UGsjkYAKHsBuNNO/2ZPBe1j34gbiFkqjV7 iBjPZSTNlCgFB7m9AxB6XNkoRcaxUMl0UTZ+iD4Z8KqrNVxNIcU42q+MM7uzFlUxdOS9 6ZWg== 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=X6ymUjLhFwGvdk+Dpc68mkS4dqByCGPE7VoI8tna6dY=; b=xnPvnlHdLnAdOG0qvweaYujFy5ecO6xyToWiAu10oKPJucs33yBkgq4aIEbVLtEoEg Y/OtzQBsjtYxGC5CN2b/0YPykiwfDAF3TdhbXXWACBx1kzlNQ/lkzwvF4+EP9Z86Y/AD evVpq8et0Lf7it1GGWtGg/c7A69xCQeQO6UMhpCahIGCzPJkyJ0W62ZxlWzufBuQlF44 g35p+eqOLpVvFYaNessExqkMG6FNZOBX9+4+nuXTr9no9Z7ck1zzqb94wOzhsifSL0H5 gJ2kA6F60yMPfs/Z59cYfIv8K6PlE1ELpmBKU91FkHJ4Kd4ob3DrCcAkjYePavRTIIqu rzCg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=MZKbWtEN; 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=X6ymUjLhFwGvdk+Dpc68mkS4dqByCGPE7VoI8tna6dY=; b=jtrJN1yb7f5ym1qcLrAELzHnBvPti2PArl7ViylDjAjDSALENZlSpi74NM8AULu9V0 pQ3AhOvgADOpZU++kjkmHZ1ne48hH4roKCMXD8vfTmIXNWNSUb3mfiv3ctuRr6qk4WRi 0VErk1YTch326CDgmsawtDInAeiivqIkTE/iI= 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=X6ymUjLhFwGvdk+Dpc68mkS4dqByCGPE7VoI8tna6dY=; b=Xe9XzBn28M8JxVf+HYWDIykVQTrJeI+QrFGItzOdesWDR2j/glLoS1++UyjdcnmXVR SE70YNiNG/tXn5P7mml/iESybSeE0XjgU+oCOU7IHdflt2ov55wxzcw1iw2JK2v8KAko S2CwQaUwdPff8VIXJGuCDH6fCXpSYnm82Wh4yp7zKenF6vuo+G6r3GbNo8N/D8PZkgNT oISEBxqx4WTwk3FBahpFNvlUnd5V4qtOzFbeH5D0aeZ8QSBiMLXXYBhI0IPPeBWvf6fH jt0UarazWEITi3z6eNMlAcu2lkdWKvpHGGkNvhOPQ+slAmsxS0YO9Mk6pbYF5qrM9ms6 +jbw== X-Gm-Message-State: AOAM531XM1KjI6OscXmZPQLg54KHNuqTc8B9HWNs2L5QxrBRioqxLyaE gVlDQarv0XbQ2E9BNO8fMp3Y4k01 X-Google-Smtp-Source: ABdhPJx4RnvqWKUubTO1oNeid/vkFB91WlQjd8lVYcpbZIap/q0dSvSc9t+Ou5CLitfgks/d6MyeNg== X-Received: by 2002:a17:906:4356:b0:711:cd0d:b205 with SMTP id z22-20020a170906435600b00711cd0db205mr16361226ejm.240.1654707096315; Wed, 08 Jun 2022 09:51:36 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:907:7f91:b0:704:cf38:c76b with SMTP id qk17-20020a1709077f9100b00704cf38c76bls1239134ejc.11.gmail; Wed, 08 Jun 2022 09:51:35 -0700 (PDT) X-Received: by 2002:a17:906:dc8f:b0:70e:5e7a:cc59 with SMTP id cs15-20020a170906dc8f00b0070e5e7acc59mr26540203ejc.423.1654707095330; Wed, 08 Jun 2022 09:51:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654707095; cv=none; d=google.com; s=arc-20160816; b=VPhhkuWVkPhIakzf4WnNlDly1YKnR2j5fIA513ed/aLH6WK9ts3v15j16XDTKaJKUP Y+Wm4oOmo2VRSl2JWw/EXpllIMra/239MFH76B78VkjpA0xO+mWJ41bcuRFg30bxyc+x 7eU0QKMzpiqrPF37N/6ojQoLVEfN+jWMIBb+yo4K3ADXRN5R/jfW2JJOGXc4O2UPK88j swsS5QzToLbCFeF8mdbwKYIJ7ywYeUtICf5nluIQIQE9JTlDyY3tOgnC5RcEDJm+4S16 rg4JC9cHkEBCsNWYKBTVLCcT9JFDxyrGlouwmqx5zh2vJOh0YmprwMz94A5guv2ehaLQ z4rA== 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=IHEZAJdjR8GiF2rcZjyRDsrMR8WF0LYSErHxMnZ6s20=; b=TMb8Ulwdlmn6+dkqDAzo1wSUJJbx46XgEQ9qqhZDzmIlK+sVo+aEGQt6a+MxCdxOs4 SN0ip9v5RVScyq9S9s0SKRk3yAckZYyyzjtleSDKN0a/4Cfgcn+bhOjVAg3Vgdadamq+ MFPuTic2a7UBczvmU1L0oPdfwe/dC+7F6lm+dMNKIByfEOJ2nSZN1ClPxf0EEiWFEnUJ 8KW497R/c880pcON7XnjyvfoFam3dAlKdeJQRIgSoWZ98Uz4L/gfRHQ6AG7v9v3D4/ov LEzmrsa6BPEtnhEKlFF5M4iZDqp3CKnPsYK3UX408EY/idWZ5BZZYnEYf8WCvOh5ZU/P MOOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=MZKbWtEN; 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 m23-20020a1709060d9700b006f3afcd1b7bsor9484383eji.115.2022.06.08.09.51.35 for (Google Transport Security); Wed, 08 Jun 2022 09:51: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:a17:906:4a83:b0:70b:156f:9098 with SMTP id x3-20020a1709064a8300b0070b156f9098mr31951137eju.109.1654707095099; Wed, 08 Jun 2022 09:51:35 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.homenet.telecomitalia.it (host-80-116-90-174.pool80116.interbusiness.it. [80.116.90.174]) by smtp.gmail.com with ESMTPSA id c22-20020a17090654d600b0070587f81bcfsm9569071ejp.19.2022.06.08.09.51.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 09:51:34 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: Amarula patchwork , 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 v2 08/13] can: slcan: send the open command to the adapter Date: Wed, 8 Jun 2022 18:51:11 +0200 Message-Id: <20220608165116.1575390-9-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220608165116.1575390-1-dario.binacchi@amarulasolutions.com> References: <20220608165116.1575390-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=MZKbWtEN; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , In case the bitrate has been set via ip tool, this patch changes the driver to send the open command ("O\r") to the adapter. Signed-off-by: Dario Binacchi --- Changes in v2: - Improve the commit message. drivers/net/can/slcan.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/slcan.c b/drivers/net/can/slcan.c index 8561bcee81ba..ec682715ce99 100644 --- a/drivers/net/can/slcan.c +++ b/drivers/net/can/slcan.c @@ -461,8 +461,15 @@ static int slc_open(struct net_device *dev) * can.bittiming.bitrate is 0, causing open_candev() to fail. * So let's set to a fake value. */ - if (sl->can.bittiming.bitrate == 0) + if (sl->can.bittiming.bitrate == 0) { sl->can.bittiming.bitrate = -1UL; + } else { + err = slcan_transmit_cmd(sl, "O\r"); + if (err) { + netdev_err(dev, "failed to send open command 'O\\r'\n"); + return err; + } + } err = open_candev(dev); if (err) { From patchwork Wed Jun 8 16:51: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: 2036 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 01B823F1F7 for ; Wed, 8 Jun 2022 18:51:38 +0200 (CEST) Received: by mail-ej1-f69.google.com with SMTP id l2-20020a170906078200b006fed42bfeacsf9690124ejc.16 for ; Wed, 08 Jun 2022 09:51:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1654707097; cv=pass; d=google.com; s=arc-20160816; b=mkc1l3WZ2FKgOTzZOa8t+ZBLUaoQ9ZAKLOJ+dU5yohXvGyu6eFURe6dkrjrJuhJTfr Vg82HAR/DdVf4/QGoSREGU+DKwmrpagnZc+qGnHSTbLP27FTvqN5MgDFC74ODkPV/NmX hH6OHDT3qOY/D01jS3zC9JAsjvPkB/aWgHUT9e4bBgnVS/UT6VKcbZmUzVON8+xe7qSf 0LRGdTnOnOEuqcJVfp6P7f+S/l0zPnXmOZpTMt+DlopKP4+N6hXxRXvV8Hos+6TxAalE N1ai3bkW1kibvVK0tA/pIRHzeFpf/H7CFBM3EnEbER98HS+ELpn/bzMMDE2qdbBMBM4g 1OFg== 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=NZckKQgRWBj2aLv1TdJHYF16HYCrqmTfZBzE04G/H2s=; b=Ouqx1cCyFXqIUqQf645SytGWC3nommNiv1KOO273W82EPZaypGSvkPrC6oX4zsw2I8 ShI8NESHnspfvOJNuUbjSvNqSCl00CRoRlkRn/XwmnlVk6Zqe6sgP4ecafQwIqadwljv 3BiaVvhIXO8euFfiNX9hSaQTE/Akv6s7vvcb4GEIe8Rx8Yex3NN6ZydHeziggMf7sHC/ PBExNxUeQiu41QWxEtgHSJOFl6tb5PRaeSmhKGrlgLvl8Gy4Et/KZrK0ZHf7e1AzrgAv y2igcLyBn+fCRZhSwpuQP3VyLymaMW1d8pu0l6dbpXKjcwwa1ypZd4zGW0KC79gLh5hz aUfQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="nl01/m/i"; 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=NZckKQgRWBj2aLv1TdJHYF16HYCrqmTfZBzE04G/H2s=; b=TN8B/aUfeOPawj/CsUVXW5kKHb1cdQoCIMXIikhPgMrbj99MG4AbvTxB6OTxui8+Gv QTX13kSD9HorBVnCGJsO/ZjO4wqNlVtuzyTkZ29inxGW06BUf8pDQnZzhqxotdgzkRho j69zYrymkEB3k9KRaCreC9YFYRdQzOOzzKOiw= 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=NZckKQgRWBj2aLv1TdJHYF16HYCrqmTfZBzE04G/H2s=; b=OIUl+fXYzLB/Re/2cXQ3/cF7lRNoLwYKYzsgMqmbEbKXK8FiWu6ze1PDW8Xy5wO/Sx vW7B+8QEzMKJCrgg9UwsNQb4drQI13AhY7a1lBpvprg4IQ7eNSm/+ML4CsQ8gaIfEMNv 1UU2xfk1WVfDQ84gNW+gH8ReHFMnxwtXYHNF59hR1K/0esmYokPBqev1khYwjYZEqx7W WVlCmmQS6/0aaH4h1tyWgefaRYFGBKlLcXJ7t5GtKvkJOQOn4jo+9ybcAwsPFJk5m/kM jopMBfqseSqPktPRDJyZ0DqK/4EwoaYAXgToAyzX5LyDmS/KEHeH6bsG6MaHooFuqHa8 1mZw== X-Gm-Message-State: AOAM530zLEn2WvrRbBPb9Q3D9etPbOgNRtBQMukEA1Jsr7pvaAAOCPU0 i4uSRm9RkkhO3k8S6KGQqCm5mJwr X-Google-Smtp-Source: ABdhPJwFUySkoaKDeVVlVovy0G0wJCHdgesDIShuR1NcTo83yon3NE7c41dEA5RykpZykefkXKfmvw== X-Received: by 2002:a05:6402:1e92:b0:42d:dc34:e233 with SMTP id f18-20020a0564021e9200b0042ddc34e233mr40738028edf.386.1654707097795; Wed, 08 Jun 2022 09:51:37 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:2741:b0:41f:7eee:e393 with SMTP id z1-20020a056402274100b0041f7eeee393ls189042edd.3.gmail; Wed, 08 Jun 2022 09:51:36 -0700 (PDT) X-Received: by 2002:aa7:c4d4:0:b0:42d:ed8b:3dd with SMTP id p20-20020aa7c4d4000000b0042ded8b03ddmr39483744edr.322.1654707096725; Wed, 08 Jun 2022 09:51:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654707096; cv=none; d=google.com; s=arc-20160816; b=e+ceepWg0mdB5MIAYuu5LRxV6MoOYwNgOhqly5ONqOX3T5h7E7uWt0C68GDfVCEIPu nP0YDv3Pa34DTzmWUx3XKL8+4HYm2tCo4Ispo/7BQ+C31z5DpN6R5SukGaYPvCjsioDn 3dSKtikouJaVxBHNSj2qkeNkW/HvolFioK+p3WfYjiabfXRNiGg6k4HQhXbhFf21oz8n 0kU37ZUmxuWCEONgBLYM8zBB6C7cXUpf+WdYK+++/11dTJ0lmmg85dkgcC9qLtiI1D5i H9nsD2x+WEz679jE9RYjzGIgmc5EV1mBpD99itPer/CsDFzjm/fA73KL7d1KaHxCmxxO zC4Q== 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=1tzR7s1CZMuNvxGPj/IhGD4aqO3yLek4cvJPPvYidL8=; b=lVNQNDalkTb8yeeOg2Jk1zgoGeqqFWhXe9o51vjM004gHsddeGGmNRXSGLecBVdY89 IMkgjVcx1WgKmN9v0foqxJXbLXfEW5YGtBX99TgHbz+Vv8JfdcapRAN1HYmZJYyF7X47 gMY16wvc2ILCXL8wpws/KZqajESECgt6zijOF9qAmOwZqpTrZ1qXSf7iD7khxO4VnyP8 ZQ4TAwkrI3d03Sm1HBa0u8py3mX687ygKjKh+jdR3o/YgK32Rzpe7czPgKwEQVkSCoyl jEqEauK4XXC3n+7GZVoshafU5+unKDJWTxtGLKgAsXsRRlQ69EXMLXe74X2UXjRPZSjA TBjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="nl01/m/i"; 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 f1-20020a1709067f8100b007062189d85dsor9632847ejr.79.2022.06.08.09.51.36 for (Google Transport Security); Wed, 08 Jun 2022 09:51:36 -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:79ca:b0:705:111f:12dc with SMTP id m10-20020a17090679ca00b00705111f12dcmr32096475ejo.602.1654707096469; Wed, 08 Jun 2022 09:51:36 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.homenet.telecomitalia.it (host-80-116-90-174.pool80116.interbusiness.it. [80.116.90.174]) by smtp.gmail.com with ESMTPSA id c22-20020a17090654d600b0070587f81bcfsm9569071ejp.19.2022.06.08.09.51.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 09:51:36 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: Amarula patchwork , 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 v2 09/13] can: slcan: send the close command to the adapter Date: Wed, 8 Jun 2022 18:51:12 +0200 Message-Id: <20220608165116.1575390-10-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220608165116.1575390-1-dario.binacchi@amarulasolutions.com> References: <20220608165116.1575390-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="nl01/m/i"; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , In case the bitrate has been set via ip tool, this patch changes the driver to send the close command ("C\r") to the adapter. Signed-off-by: Dario Binacchi --- Changes in v2: - Improve the commit message. drivers/net/can/slcan.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/net/can/slcan.c b/drivers/net/can/slcan.c index ec682715ce99..0722e7820564 100644 --- a/drivers/net/can/slcan.c +++ b/drivers/net/can/slcan.c @@ -430,9 +430,20 @@ static int slcan_transmit_cmd(struct slcan *sl, const unsigned char *cmd) static int slc_close(struct net_device *dev) { struct slcan *sl = netdev_priv(dev); + int err; spin_lock_bh(&sl->lock); if (sl->tty) { + if (sl->can.bittiming.bitrate && + sl->can.bittiming.bitrate != -1) { + spin_unlock_bh(&sl->lock); + err = slcan_transmit_cmd(sl, "C\r"); + spin_lock_bh(&sl->lock); + if (err) + netdev_warn(dev, + "failed to send close command 'C\\r'\n"); + } + /* TTY discipline is running. */ clear_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags); } From patchwork Wed Jun 8 16:51: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: 2037 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 5A4D23F1F7 for ; Wed, 8 Jun 2022 18:51:39 +0200 (CEST) Received: by mail-ed1-f72.google.com with SMTP id eh10-20020a0564020f8a00b0042dd9bf7c57sf15313857edb.17 for ; Wed, 08 Jun 2022 09:51:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1654707099; cv=pass; d=google.com; s=arc-20160816; b=HYgp/C50TQVaLsrtJHRKpRzPr2N6iXjQ3vHoQwacUuZfvlfzKYibkHMI8Rd5OBkXmI gRNG0p7ndMcJhW68pc7CQwkayXPxOJNlrpW1M0bGhFAiQB7Y+HQLgeYj9HdOUaDGAAri EkmAEa7Y5Ge52ihYoMD9s2CVTKgaBsFlOKYdXM5rP/kN5R48/tYrhCig4SauEQGtJC87 4teiVkXaB7lgB7srlsjrp3pM40oLEv566TQrOJSyYJqoakJd1huhapooVJ3cYkKGwWoZ gbghQA6ByxcrCJM3yqt1XSKqUGXBHMXK16v/4Gwf0XWtiBRM+0m1ducB2K8oSs+CBIZw iqqw== 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=twhaGH9dYnUFBeFVv67l8YXUK5583uiSpZw8Kj0U7Io+JElDvbmqGEeikeV9tMnY7B tk85kZcVB0ztffk051MYAdLvi2/J+0IJhluFkHF4PYVWm6wRCUjIDRQnBtYUIZCUa4k8 FN1we8eoyx7fcizC4yZPESZF0E4XcAro1o238CNub6yOmWRkEC6DoJS5YLShOXNpyq2O aji9kDfrJHS2zNmCnMzQvBY09h13C4D/J8PumpHeP40ZZTuhAtjBheKiRTrPbT+iRvHT 5Akx2KhBwrr6Xu29ArbFBQk2E3G43lhcGUZPL/WTRh6/6kfvFvWpbIDqvoQe7IuZz+gf N/1g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=PkT9jSzS; 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=naEGz0t8Tt7XVuA8A2/+0FF3j6OoSM7vxQhpw8pEF5NNDpergNW7zmArbS48qOmwiL VfOrJXGFOFuJrJPIE12YnPXELFznugEHcvztnEVwwfn7bAlcbfocFGfmujhnKvV6LXZi u+IClKMpxkvJEr/JxmKjaoFEl6jvxU6Yl6FOw= 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=dRGNVSR4SxvrhBQ0SGRy8/0CVWloz1HkCB57WMrgQVsIKmzIZyJRfsTjgkmflhsjMq RuvEH/kiH8xaUvGBX3NeUBUVCfqSx0LcW5rQ9KjulnPgN9RPc2wlKiIlzsmMMT4peoSh Bb9BHhEMeLTDU3GAenEGa9J3YGJcsptUfAQF4KySchhAFNwiTr/BkUrM4DVSVziOcks2 TxhLNBUnQoJFwE4wFthDBMKUARe1Xu1nP+hh24GqMSZSrV/LKXKe1QNoG1bR9nylZZjH FRPo2qeXOF0mBsuCpXHjD9lTOK162PEaiguxrMhOSrR7p4RSRakswtHIRq1Vj7EFehQj CJkg== X-Gm-Message-State: AOAM5328YeS8jF3Ur+HEfrb2sH8i7P+LTXfGxffUFnKq9R4N2vY2Eh3C CNiFCbMYpctvY5QkUCs1pqnb7Lo8 X-Google-Smtp-Source: ABdhPJzGFEtDV6anEBz1884OH2P6U1WiDLQpNRMJGiFkleF1mbofsqH+ktfvXksLn/DLrUUgDfSxkA== X-Received: by 2002:a05:6402:b03:b0:42d:ce84:387a with SMTP id bm3-20020a0564020b0300b0042dce84387amr41246984edb.3.1654707099170; Wed, 08 Jun 2022 09:51:39 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:5414:b0:431:6a31:654d with SMTP id ev20-20020a056402541400b004316a31654dls189960edb.0.gmail; Wed, 08 Jun 2022 09:51:38 -0700 (PDT) X-Received: by 2002:a05:6402:2409:b0:431:5c52:8128 with SMTP id t9-20020a056402240900b004315c528128mr19327446eda.290.1654707098224; Wed, 08 Jun 2022 09:51:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654707098; cv=none; d=google.com; s=arc-20160816; b=WR1GfkCz4xqonBYUtfPI85cABwfSmOPaT3AUmvooSizphF75YeD6fql0+lvm10U9Qn o5jE/ZhvML0hktWeMaMRYGqdhVirZYLkO2lP1EvxyRATUNf4tE1bvB7rDds59o1VaW6N 0iEiouOXhs6FSjcsz/TfyJ1/efszlgTs4455YXQvhq9FR/WWvroAi6YXR/GBbsMIGXpl AgXXyNIsg8HkxOO7ra/IUKhtDXb0g1BJmOd2US+zXnQGlBMm33himtCYTh/42G7ZO8Dx cIxRl1gonpWivFR6NYiZSiTGIImdxxCrBi0lfuPjIZ3M6JyIzrGZ5grfXn8GrdwZn0Ku e3tA== 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=PGmXV0sMVgkJGvxptSRAHnhhSMaS60Qy/8xGpcVP74dnhWNLqdp4Up9ZKvlD99JDA0 aewDDoI/IxDEHuXFvVRB0+GhDVyDGBxUWphIY4i701+WGjXZI6ocV6awSHK+AO/MUEei fyBlyc0m/mggjSWcGXjadFLR28jYqtNHrDBaxy4UP9mss/t1p0en3ub4w65xEJpOs1dG KUgS97Zynn/0MNzMqDHnHCZGBceRjrJjZv+J6tdj42UPDgxOujxdZtk4/95VNgGbbZiC ZS1MYqxUkHX6SzLo2PSinEHqfv4Llxo/8BpX3WepOVAzN97pa5hWpVVnaSMfILOmosX/ ITyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=PkT9jSzS; 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 p7-20020a170906604700b007033fef81a4sor9779603ejj.56.2022.06.08.09.51.38 for (Google Transport Security); Wed, 08 Jun 2022 09:51: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:907:9482:b0:6f5:171d:f7f5 with SMTP id dm2-20020a170907948200b006f5171df7f5mr33336054ejc.68.1654707098018; Wed, 08 Jun 2022 09:51:38 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.homenet.telecomitalia.it (host-80-116-90-174.pool80116.interbusiness.it. [80.116.90.174]) by smtp.gmail.com with ESMTPSA id c22-20020a17090654d600b0070587f81bcfsm9569071ejp.19.2022.06.08.09.51.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 09:51:37 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: Amarula patchwork , 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 v2 10/13] can: slcan: move driver into separate sub directory Date: Wed, 8 Jun 2022 18:51:13 +0200 Message-Id: <20220608165116.1575390-11-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220608165116.1575390-1-dario.binacchi@amarulasolutions.com> References: <20220608165116.1575390-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=PkT9jSzS; 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 Wed Jun 8 16:51: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: 2038 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 1403A3F1F7 for ; Wed, 8 Jun 2022 18:51:41 +0200 (CEST) Received: by mail-ed1-f72.google.com with SMTP id x15-20020a05640226cf00b004318eab9feasf3995564edd.12 for ; Wed, 08 Jun 2022 09:51:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1654707101; cv=pass; d=google.com; s=arc-20160816; b=r0SFP3L0fULC0oqOgL8VbqFyfkjNwKYWamHiUDTVaif3jP5kw94oatjvO/9/hz4uTS hNbf9MGKLS2me3SftgJf5MFW4N7Ymn5wPaMH4tGRSzhBFQOz8kq6UPaK2JYQ2u/mFr64 2iMctmFj98gRfftQbkD0wob67GSqSGpW8x0/CCIC7ZjmGK7eA/prNj8A1GWuSchU+goe DLii02GxZZXT99ZmGShf3fHxTwYjHf2dcEqnI3Be40q0l4Z1spy/S2pfTRBLZ0B5iM14 L6L0FPAj/DtfR46s2bhXEZOjLdYfiDcXVUw0E9jk7oC0g2IU7MKi7U1rLzYNKZSaAx/d h5iA== 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=Ot/rAEftvwCpvOTALQIAtnw9leN+HTOd2dvkSZstnOk=; b=mv3vyWmla8wF3ruVTiHZGQNWSIQ97B4444wE7bxyXB0LyLzEGaIzMI6xjfZGNTF6Eh XexHYV4DIsFNq6p+xTArMSO1mdsZctBoZfzhunzoo1mmMOEjuZJ470zWtJ2Pr5xRw7vP v99BoiPm411CyURlkmn/BfQRurdtro5XpfgFjcb2QQ0uyuWfvcQXNupRulLASzrM+ewS L+FspVy+sYd2VlWKePsJgGKru3ymYQAVdVYbQvrFYOimPhW3tJD62VitptUywsK3AjPV 2U4+fyUaZsx8q2RvZrb76dJBN+M8eBBo85b2XAeg9vaIpA+uHclBzZuHFXgsx2PmLlk9 Hx+A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=G6FtfoTZ; 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=Ot/rAEftvwCpvOTALQIAtnw9leN+HTOd2dvkSZstnOk=; b=Qtfnzz/lIyL+HHTWCc2cM8aw940gQMJGybXFZSvKEYrbSBiZDUZxNSMS/baANM8B3M JCwFue03XlRu7BDgtgeQpkWOK59Eh+rjAzAgqlWLZKlzSVoywXscE+1gQsvVHx55u4pj 3NLTw9LC3+y1wFrhaPpuMqHjnV1pmXfQAub7Y= 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=Ot/rAEftvwCpvOTALQIAtnw9leN+HTOd2dvkSZstnOk=; b=jyMoeKIqGNwMDiIY5claHoJTZBswbDpNd04GkYqlrb/dUCj3GfOZHiTIHLlSGpyaIf SccllpFbE/K/K7/LIQEmJ4R5fZUjTjW4iJ0Sij2Ss4n9mj7C6anQQLSrMeJqkBP5SrTD H0v7hTY/YuwZ6AHVwhK/dMeYt3PD5wOeuIDo68EZnfSqEfNkFtisdm17xrw8ZPJZ18lh /+d15KqbV+FvbjTpBC3cSgHiJ/kTKhtnubV/9ccvTs/RijeV0vyfAwcjjHW63Z49NWC6 Ta+YoTpfJXxEkSsm0v0ZaaZLU/o9acfO9UqWIXFKd9i2zWHcFDMLa1Rg5QxixWQo9aMy QCbQ== X-Gm-Message-State: AOAM532JaRXoHz8LAqlbAbSaucG5mNeoFZnJ/NiOay5zi8KTe9MYrZco C276PPBmiobHfQsSlK6ExKD9nssO X-Google-Smtp-Source: ABdhPJymN/0ppay7nVgZu3i1PSK8GJlaNNwFi7540vemwnnaBF02C1IxhmLzvCow4oqyVUBSeJAnIQ== X-Received: by 2002:a05:6402:2804:b0:431:7dde:6fb5 with SMTP id h4-20020a056402280400b004317dde6fb5mr13082731ede.379.1654707100896; Wed, 08 Jun 2022 09:51:40 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:294a:b0:42b:31b9:2087 with SMTP id ed10-20020a056402294a00b0042b31b92087ls189616edb.2.gmail; Wed, 08 Jun 2022 09:51:39 -0700 (PDT) X-Received: by 2002:a05:6402:31ec:b0:432:dd71:c7 with SMTP id dy12-20020a05640231ec00b00432dd7100c7mr4020842edb.118.1654707099724; Wed, 08 Jun 2022 09:51:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654707099; cv=none; d=google.com; s=arc-20160816; b=g/He4+0Me5L0X6H7+EOz92xXivSMtlh6Oss+riYPGF2dt1dRvowb+rfBMx0kSKr8hT UTfmegTA1bLoZ36knipr7uvat8vZW6ZI1sP32wIG0zxGPVSbdotb8OE42R9BFvkzJ8uM LhuF+qLGcDQ7EGEy2IpnQxt4W/8rBcQGvgDaBWwVs8QMJ8LT9eWy5HqUWKwWbKkuPcgu 6PBlREaVnyS4GR6oC6mat/aEE8TwOGlzANro/MAOCjIYKNAYOF6iopFVFD71WtRafD1m E10DwLNAWqj2TlncOXLnHEElL2p+i2sgkfXb+U/iWp2za9LTqIwSTeEV1AkhVdZ3J5ad YNjg== 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=D347QqdRdrFNo4P9Em/ayvZ1ba87O9qPIqi6sUOPlwQ=; b=T+0i4+QMihNgKOY48FRXiFXecp3zRsLlU7xnBNvhN/kkkE/81ZKuorrRpritQy7dEz irFcmPZO9L7dh/BFbF9+tADJsaNa2+9s1BeSEs1U+mv+ngJRmR0K/sDjnHhtkzbFK7Zp Scwv6TRaQZpnP1PYlhlC2MgQqsELnpxa2a1HC4OwEv9syGLMl0hQjfv+h5sJx66iBXOD 88ad97bbEgwAfWiLLsdGok+c/vOH3iRda3yqHCdmQ8PogD/6sjuLn+EjKArKCmy/9ZW0 0WPDMw2jGMKg4wAkxSbU3LL2m/sNpr7E++i5Kb5+QZhuBuD+2kBUSkUJaThj3JkTMuKB cJWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=G6FtfoTZ; 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 a17-20020a170906245100b00707ab1f34ccsor9717977ejb.111.2022.06.08.09.51.39 for (Google Transport Security); Wed, 08 Jun 2022 09:51:39 -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:2cc7:b0:709:f1e1:7b17 with SMTP id hg7-20020a1709072cc700b00709f1e17b17mr31394072ejc.498.1654707099497; Wed, 08 Jun 2022 09:51:39 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.homenet.telecomitalia.it (host-80-116-90-174.pool80116.interbusiness.it. [80.116.90.174]) by smtp.gmail.com with ESMTPSA id c22-20020a17090654d600b0070587f81bcfsm9569071ejp.19.2022.06.08.09.51.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 09:51:39 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: Amarula patchwork , 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 v2 11/13] can: slcan: add ethtool support to reset adapter errors Date: Wed, 8 Jun 2022 18:51:14 +0200 Message-Id: <20220608165116.1575390-12-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220608165116.1575390-1-dario.binacchi@amarulasolutions.com> References: <20220608165116.1575390-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=G6FtfoTZ; 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 0722e7820564..038ce7c25d42 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 */ }; @@ -105,6 +109,28 @@ struct slcan { static struct net_device **slcan_devs; static DEFINE_SPINLOCK(slcan_lock); +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 * ************************************************************************/ @@ -475,6 +501,15 @@ static int slc_open(struct net_device *dev) if (sl->can.bittiming.bitrate == 0) { sl->can.bittiming.bitrate = -1UL; } else { + if (test_bit(CF_ERR_RST, &sl->cmd_flags)) { + err = slcan_transmit_cmd(sl, "F\r"); + if (err) { + netdev_err(sl->dev, + "failed to send error command 'F\\r'\n"); + return err; + } + } + err = slcan_transmit_cmd(sl, "O\r"); if (err) { netdev_err(dev, "failed to send open command 'O\\r'\n"); @@ -634,6 +669,7 @@ static struct slcan *slc_alloc(void) snprintf(dev->name, sizeof(dev->name), "slcan%d", i); dev->netdev_ops = &slc_netdev_ops; + 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 Wed Jun 8 16:51: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: 2039 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 58B053F1F7 for ; Wed, 8 Jun 2022 18:51:42 +0200 (CEST) Received: by mail-ed1-f69.google.com with SMTP id g7-20020a056402424700b0042dee9d11d0sf15189787edb.3 for ; Wed, 08 Jun 2022 09:51:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1654707102; cv=pass; d=google.com; s=arc-20160816; b=M+CZdsoZp1gNqX/v9izSuKqqvYba5uKv9HcDPAzHJG9X0U2aCoe8cUbDAGp7zwmb1q 77QPVBs+16a93BkWYT5gtbS5qbX+lutY9N9dt1PAJ2HknDIB/hQs+lN3LoY8YjvkdhNp s7FnBxossQAAOk4sV3Hpp3G/ELuDLJdFSbwX3Q1PL3eaMBTMjv/giexMPObvPA0X0ATo RJs6IdaqBw7X/UbR88WcLTEmO23rb/ov2Bj/ruR5gkuOsPPkAIGxzoh9uxSlUxjcpPci yCCwYFSlZBs8wZw2nEDh8yNmXeKAIOukcU4Sv78I9qiex5tQ5nPvFkNDSn7v02ABEU/Q LsNg== 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=YkjfI++M2oDDaasBMbam6jaJWdzMx8GTQRiAh0yswE0=; b=QFEjrmmLwcrCVd/8P6n3VoLg13IeYQRTLgFrUzP+xWaWgCstTZ0tnSzXfx4FX5x9oc dQ1dOF6EnFd3Pl7bwgoHRFppZ4ZC4mU0WQ53ihKpazdjV1LOeOKaMWGFsxzEkX6Ar4un AXH9kxF9+LgX8JqyYh0TTNkdxSYApel44q01C9dEsxOr2xMys/dxd6pubOnYoD8o6/Yy VEl8SBZn6wBVJL61NK15E0XsCren1DbnqwgPRS+SVIPbLwV/LZtkAu1UxW3fIusyOzK0 xvLR8/juU3rw+oE0fQ4t5xfk59Hjfe2tpoUpq4wFFT7cXxSrG+ILleXIvz4oCU3vlaDv 8Vdw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=fOek92UJ; 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=YkjfI++M2oDDaasBMbam6jaJWdzMx8GTQRiAh0yswE0=; b=SDuqiUZ0T5QJRsMAyfHm70sPM73oAhTcyCwGAHFCpp8wt9iGKaQem8+q71Mu0k4eKr x7taDp9uIEjYcLRmcuSH93iInr3a9JFuPxSobkUp/hUxg0GIl48MAdAgaqDmfCFeuaiT grSQK2SGoHaJ8XU7heaE6fCWkzsAO46+2P3cM= 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=YkjfI++M2oDDaasBMbam6jaJWdzMx8GTQRiAh0yswE0=; b=h6mhuxNSxYD1Fygc9lxS2kNdgljU1tZYrAgzihi+nntZlk0Ywg1mTXQbRaR8mXbG6b sxr9nYFFAq0TbJee8NDRzkZlVGRcFOkJ/c/BfkwhqUjFZXHH8OZOe84+dgw9tf9HcRNY g54e/iQQS2VeB/Y+LJ4KsI1qr7DMNlBadS/o6qvf4naM3AK6A/tAovF0qS73IyF2mMUh bVc+76QdA9m5FdYMnaUQYf7tgu6lL9D7qRkQMW/h59s0KWoGZi8ejor24rio/uJTQKIN h/rQMxd+JPNvWVb5CaZfYBQnA8mJBJGkwsRKCjG3XOpqDpaYe4lOcSIiBdQg3lWHk9GA f7uA== X-Gm-Message-State: AOAM5324iDChrR6Z5Ke1eYzDl5xmolZGPzrn8Vgk1Ub1Qzi4wOltx/17 fyisqUeiKyPS3i77Ui01JSMOenlF X-Google-Smtp-Source: ABdhPJwRC1GxHavOy2HdGMSeU00X+oiweyGET42r6EmHmaxasVniIqir0k/cxlMwhE909ScGc1lDUQ== X-Received: by 2002:a05:6402:1756:b0:432:dd5f:ec38 with SMTP id v22-20020a056402175600b00432dd5fec38mr3967345edx.307.1654707102180; Wed, 08 Jun 2022 09:51:42 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:2741:b0:41f:7eee:e393 with SMTP id z1-20020a056402274100b0041f7eeee393ls189239edd.3.gmail; Wed, 08 Jun 2022 09:51:41 -0700 (PDT) X-Received: by 2002:a05:6402:50d4:b0:42e:686:df55 with SMTP id h20-20020a05640250d400b0042e0686df55mr40348666edb.403.1654707101116; Wed, 08 Jun 2022 09:51:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654707101; cv=none; d=google.com; s=arc-20160816; b=j8i8vUysVTejuQ3Ts95I0xX1ctQqs57oSV6U3ggpgiQ6Q6CGeoFosY+OX4zb99BODM rdnonyoSGtig9IEWxxFKK6PEF9dJimhjU7IoXCDj0v+BGgIBykItXDZZrEUV+w7C2vTy Y1yGwBog+77s9YQIy7vZviZoosW5tX9bX0XhipLKBstmmbVLH7UsQU8vYYkK36PVgXKb m8wVTxNDb6IQK4AqdXloDNZGSlw7qW14u7RnMIz6oJhm3a/9Ebzqtj3hHPhfP6MHFLH9 16Nac9NBwhj+KjmrMQwj7rbEw4jiEQcO8OjleXWJQF75kP2GHEbQ+99bdxRHHDj9gPgT Y5ow== 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=r56OkRGS+scgiov9hraSbcrm1/dO+C0ISd2zgdsHS2U=; b=Qvg/yTJCFnzKSuchGP69Zb0VMkTIE8Dl++bPOfFcBCau2dNn0SSSAK39zFlzPdIHzo U/zG5nG9hxPSj/cFxpVZQzvxvi1dcKSSxXcFbQj0RPx+WMHPzWk/dP3PScfPaqTmRx8K WX7h9Gwo7EMkjGb9GtJnl6PdX+Fd0hRCm+PeJmtEHm7cSlY0XVZ/DfDeRJsdQ3Rj0+Dv eyHGT1qn2x78/J2ryZsDvul8idfi5jseTgA9cIQPYCqvXfZA51fFKLzhcUGjJE6w3ZAa TOIM1LcaO/yUaVrbb9kJ+ze6zjGfQikPpzg9FU+YR1sccHFGiH2fTBvDUqM0Le3t8CFQ +RBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=fOek92UJ; 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 t19-20020a170906269300b006fef55785d9sor9712200ejc.96.2022.06.08.09.51.41 for (Google Transport Security); Wed, 08 Jun 2022 09:51: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:51c5:b0:711:f4ee:6574 with SMTP id v5-20020a17090651c500b00711f4ee6574mr3748661ejk.509.1654707100906; Wed, 08 Jun 2022 09:51:40 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.homenet.telecomitalia.it (host-80-116-90-174.pool80116.interbusiness.it. [80.116.90.174]) by smtp.gmail.com with ESMTPSA id c22-20020a17090654d600b0070587f81bcfsm9569071ejp.19.2022.06.08.09.51.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 09:51:40 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: Amarula patchwork , 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 v2 12/13] can: slcan: extend the protocol with error info Date: Wed, 8 Jun 2022 18:51:15 +0200 Message-Id: <20220608165116.1575390-13-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220608165116.1575390-1-dario.binacchi@amarulasolutions.com> References: <20220608165116.1575390-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=fOek92UJ; 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 v2: - Protect decoding against the case the len value is longer than the received data. - Continue error handling even if no skb can be allocated. drivers/net/can/slcan/slcan-core.c | 130 ++++++++++++++++++++++++++++- 1 file changed, 129 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/slcan/slcan-core.c b/drivers/net/can/slcan/slcan-core.c index 038ce7c25d42..aba42e284274 100644 --- a/drivers/net/can/slcan/slcan-core.c +++ b/drivers/net/can/slcan/slcan-core.c @@ -170,8 +170,118 @@ int slcan_enable_err_rst_on_open(struct net_device *ndev, bool on) * STANDARD SLCAN DECAPSULATION * ************************************************************************/ +static void slc_bump_err(struct slcan *sl) +{ + struct net_device *dev = sl->dev; + struct sk_buff *skb; + struct can_frame *cf; + char *cmd = sl->rbuff; + bool rx_errors = false, tx_errors = false; + int i, len; + + if (*cmd != 'e') + return; + + cmd += SLC_CMD_LEN; + /* get len from sanitized ASCII value */ + len = *cmd++; + if (len >= '0' && len < '9') + len -= '0'; + else + return; + + skb = alloc_can_err_skb(dev, &cf); + + if (skb) + cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR; + + for (i = 0; i < len; i++, cmd++) { + switch (*cmd) { + case 'a': + netdev_dbg(dev, "ACK error\n"); + tx_errors = true; + if (skb) { + cf->can_id |= CAN_ERR_ACK; + cf->data[3] = CAN_ERR_PROT_LOC_ACK; + } + + break; + case 'b': + netdev_dbg(dev, "Bit0 error\n"); + tx_errors = true; + if (skb) + cf->data[2] |= CAN_ERR_PROT_BIT0; + + break; + case 'B': + netdev_dbg(dev, "Bit1 error\n"); + tx_errors = true; + if (skb) + cf->data[2] |= CAN_ERR_PROT_BIT1; + + break; + case 'c': + netdev_dbg(dev, "CRC error\n"); + rx_errors = true; + if (skb) { + cf->data[2] |= CAN_ERR_PROT_BIT; + cf->data[3] = CAN_ERR_PROT_LOC_CRC_SEQ; + } + + break; + case 'f': + netdev_dbg(dev, "Form Error\n"); + rx_errors = true; + if (skb) + cf->data[2] |= CAN_ERR_PROT_FORM; + + break; + case 'o': + netdev_dbg(dev, "Rx overrun error\n"); + dev->stats.rx_over_errors++; + dev->stats.rx_errors++; + if (skb) { + cf->can_id |= CAN_ERR_CRTL; + cf->data[1] = CAN_ERR_CRTL_RX_OVERFLOW; + } + + break; + case 'O': + netdev_dbg(dev, "Tx overrun error\n"); + dev->stats.tx_errors++; + if (skb) { + cf->can_id |= CAN_ERR_CRTL; + cf->data[1] = CAN_ERR_CRTL_TX_OVERFLOW; + } + + break; + case 's': + netdev_dbg(dev, "Stuff error\n"); + rx_errors = true; + if (skb) + cf->data[2] |= CAN_ERR_PROT_STUFF; + + break; + default: + if (skb) + dev_kfree_skb(skb); + + return; + } + } + + if (rx_errors) + dev->stats.rx_errors++; + + if (tx_errors) + dev->stats.tx_errors++; + + if (skb) + netif_rx(skb); +} + /* Send one completely decapsulated can_frame to the network layer */ -static void slc_bump(struct slcan *sl) +static void slc_bump_frame(struct slcan *sl) { struct sk_buff *skb; struct can_frame *cf; @@ -249,6 +359,24 @@ static void slc_bump(struct slcan *sl) dev_kfree_skb(skb); } +static void slc_bump(struct slcan *sl) +{ + switch (sl->rbuff[0]) { + case 'r': + fallthrough; + case 't': + fallthrough; + case 'R': + fallthrough; + case 'T': + return slc_bump_frame(sl); + case 'e': + return slc_bump_err(sl); + default: + return; + } +} + /* parse tty input stream */ static void slcan_unesc(struct slcan *sl, unsigned char s) { From patchwork Wed Jun 8 16:51: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: 2040 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 C97F23F1F7 for ; Wed, 8 Jun 2022 18:51:43 +0200 (CEST) Received: by mail-ed1-f70.google.com with SMTP id z20-20020a05640235d400b0042dfc1c0e80sf14844872edc.21 for ; Wed, 08 Jun 2022 09:51:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1654707103; cv=pass; d=google.com; s=arc-20160816; b=wQluX+axLCxr9NELO9GPgsDp3vSdFW8CZ1JlZRvZyzl7AmgLb5IpygMU7yA6cqDlet undeXxQ5FxI+nX13KxJMKJeL1y8LmBXRAS57wqL0aOJbjdW35xQjFiDghSesRLW5byK3 uWgSjaF1MOvlTZCrykk/Xvq7EfHrfAf17u5Ve5sqvMdxj3RG/Soxy0eAHPG3Kvy8kmjw cSl+DGRMR/I9JvOGsMTP63ymBk/Ftn0LMB2kqT7Ha/kntE3Y7aUvgsey8BQxkxS+toR2 zZ1jUTo+juhEMgLGrmpDl5FXhNm1f6rlM4BpIY8m1t8GnkDaMSbUaKkCV7k1ArKd1Dqa SeYg== 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=f4gHt9DFSEiZAYAxIa+iwA7d4a7VD9Q8ibrcD13ebhs=; b=dv5ZMpsyVIseuwEFuRdPmKYbNUfphyggKVIwOqiD7W8iwrLJ8OV6//Mr2KP3ahPl/M mEmcjt//eFAAWrse3/IABeyQmvfASFXoTI0UHW8kXkzYH2x//0lWxVOJwla0BtcrGnk8 TLbBQelG7xXNSpH0wg2KZDuKtqNgfGfk+6lo7IuMwJQElPD9Xy3K5muDWp//HnjNYdDJ evoGgr5G/ZLTosN0D2WjnWjV0PHQT8ikPtGasN5oQbh/jRqwGOtGg7iCjSbwj0QJ8ESn YfLJuo80ZWsau4M5/9kneZwkXCRtBhpUoD5LE+6pBlVmMHTZaLDcsN2kvYWznmayT4z6 CwPg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Rxct20Wg; 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=f4gHt9DFSEiZAYAxIa+iwA7d4a7VD9Q8ibrcD13ebhs=; b=qOkWMI529wx3Ldxz/0hFCEFjEJsy4X5iyCHdbfSIUJKlVHCoXC38Rt87JrJigqWPRJ xetqOlb9q5YDjYYLdsiQBRu7S+zGS5+w9mvXfaBd9a1njhe2QLRw0v465fgTTS9LJ1jQ 8Ck0d+1ryypW3+iCFhnqWasMmO117pVobhGhs= 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=f4gHt9DFSEiZAYAxIa+iwA7d4a7VD9Q8ibrcD13ebhs=; b=Mmr7niEpber9skrry+pPBmZxOil2GL0Fsda1HL7iC9fEi3aMpZjd6GUwUultp7gZRt R/1GI7nRmT4qU65cxvCtoXV3+ZOr5WDgHpfu+egN5jikx5whhFaZj2dlVp39zvXLVlO7 QmTHZfQxzZPTitfWHVm5fC2anDVMOAoRwIqilHALJo2zmL0QdCVd1tEZQYq640bP6XoT 3BwjkmkMmRkjEytw/CFroD3Fgftm4CJWqJUTpfNp6L0SF4haSO9GTDSduar9rtYhcoNV ytxDK6vc7ezyEk7E11E1R+t0uNFpqn+RmyhZWc9udLld+uhJpVmyV+WPCe5mxKXoOcpc Tkrw== X-Gm-Message-State: AOAM533X11dKk1917WMj+uzOGzQMzVFxYYt3Sk7GQR9JRsNnsy7u94c7 SgztzJ/0RxiatW5nhES5NghMK3pO X-Google-Smtp-Source: ABdhPJxsuQ1ii2WOlDHCw9sRytSR2xJ4T0IAARxE6yVlFR174J3gMo+frpoltEBsvw67/tnFA98Xsg== X-Received: by 2002:a17:906:a0ce:b0:6d1:cb30:3b3b with SMTP id bh14-20020a170906a0ce00b006d1cb303b3bmr32160102ejb.582.1654707103605; Wed, 08 Jun 2022 09:51:43 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:5414:b0:431:6a31:654d with SMTP id ev20-20020a056402541400b004316a31654dls190149edb.0.gmail; Wed, 08 Jun 2022 09:51:42 -0700 (PDT) X-Received: by 2002:a05:6402:27d0:b0:42d:fbe2:57d9 with SMTP id c16-20020a05640227d000b0042dfbe257d9mr41374625ede.47.1654707102613; Wed, 08 Jun 2022 09:51:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654707102; cv=none; d=google.com; s=arc-20160816; b=uyMJlpD919Ba5kNyDEZlHcqL+UxNlEieOmbg71VscvRUIuFi7QzQo1eEEFptit8A6s bkzuxCbdYlMemtURT/b3Sdi2tB7afvLGjTiukZnoWzuObSXD2FM56CvBMPSK7GdSs/Sp xsuouCXibrBeU41w8nhjEmMFrRv5P+m+6eBQGqwDpk4lOYvFdoiqE9aLUzxVxo63JC7B 2yXzgqePusssR374TUkOJ9YTv/mwNtl8nTvcbGwso9IDdVBiUx4TWEZxokS0xFgbaLW6 ek1wGgw1+tc4GoT7MnUt1++hr+X+X9ibriOxeaN45Vuf7I2kFeZANOCdU3toyV4+KKhY w5Vg== 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=bwNtXSOCw0XDwGW95Gh6yPmxJxefcbSMC7JInqj3ttk=; b=fao/Xv2HSNfvje8rlhUix3zoqd6OjVIX+uRNznncvfS8YJK2ZFDOWbHN/NU6E29/UO Wuk0PN/siLTCrR5Hqjqbux9Gu16tSrGMygq8UwD9uizBWqL3jUWtbNBkCVCLIpCR1xAU ds4jEcYEx1n2ziXgPpaXbO6XFm6UgKwudd5ir9ZlLg6vaQylNjhIAx7H5MC+uxlpBydf Onoc1HbHd8cNJPqLeQ7XdeoIO6nAxE2cu7Nkqhu+3jKjXh3J6rsdNgNwR9Ze93kB2sj1 XnEj7KZXIOAexbfw9RkbB38Emi5tPoVqOtZX7WuRxEVvu7DHPFZ9vT3Y/Lc4yC1nBdz0 L2Tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Rxct20Wg; 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 q20-20020a170906541400b00711e504e9b2sor2317833ejo.113.2022.06.08.09.51.42 for (Google Transport Security); Wed, 08 Jun 2022 09:51:42 -0700 (PDT) Received-SPF: pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Received: by 2002:a17:907:90c4:b0:710:456a:6981 with SMTP id gk4-20020a17090790c400b00710456a6981mr23907500ejb.484.1654707102377; Wed, 08 Jun 2022 09:51:42 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.homenet.telecomitalia.it (host-80-116-90-174.pool80116.interbusiness.it. [80.116.90.174]) by smtp.gmail.com with ESMTPSA id c22-20020a17090654d600b0070587f81bcfsm9569071ejp.19.2022.06.08.09.51.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 09:51:41 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: Amarula patchwork , 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 v2 13/13] can: slcan: extend the protocol with CAN state info Date: Wed, 8 Jun 2022 18:51:16 +0200 Message-Id: <20220608165116.1575390-14-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220608165116.1575390-1-dario.binacchi@amarulasolutions.com> References: <20220608165116.1575390-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=Rxct20Wg; 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 v2: - Continue error handling even if no skb can be allocated. drivers/net/can/slcan/slcan-core.c | 66 ++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/drivers/net/can/slcan/slcan-core.c b/drivers/net/can/slcan/slcan-core.c index aba42e284274..22a261f2477c 100644 --- a/drivers/net/can/slcan/slcan-core.c +++ b/drivers/net/can/slcan/slcan-core.c @@ -78,6 +78,9 @@ MODULE_PARM_DESC(maxdev, "Maximum number of slcan interfaces"); #define SLC_CMD_LEN 1 #define SLC_SFF_ID_LEN 3 #define SLC_EFF_ID_LEN 8 +#define SLC_STATE_LEN 1 +#define SLC_STATE_BE_RXCNT_LEN 3 +#define SLC_STATE_BE_TXCNT_LEN 3 struct slcan { struct can_priv can; @@ -170,6 +173,67 @@ int slcan_enable_err_rst_on_open(struct net_device *ndev, bool on) * STANDARD SLCAN DECAPSULATION * ************************************************************************/ +static void slc_bump_state(struct slcan *sl) +{ + struct net_device *dev = sl->dev; + struct sk_buff *skb; + struct can_frame *cf; + char *cmd = sl->rbuff; + u32 rxerr, txerr; + enum can_state state, rx_state, tx_state; + + if (*cmd != 's') + return; + + cmd += SLC_CMD_LEN; + switch (*cmd) { + case 'a': + state = CAN_STATE_ERROR_ACTIVE; + break; + case 'w': + state = CAN_STATE_ERROR_WARNING; + break; + case 'p': + state = CAN_STATE_ERROR_PASSIVE; + break; + case 'f': + state = CAN_STATE_BUS_OFF; + break; + default: + return; + } + + if (state == sl->can.state) + return; + + cmd += SLC_STATE_BE_RXCNT_LEN + 1; + cmd[SLC_STATE_BE_TXCNT_LEN] = 0; + if (kstrtou32(cmd, 10, &txerr)) + return; + + *cmd = 0; + cmd -= SLC_STATE_BE_RXCNT_LEN; + if (kstrtou32(cmd, 10, &rxerr)) + return; + + skb = alloc_can_err_skb(dev, &cf); + + if (skb) { + cf->data[6] = txerr; + cf->data[7] = rxerr; + } + + tx_state = txerr >= rxerr ? state : 0; + rx_state = txerr <= rxerr ? state : 0; + can_change_state(dev, skb ? cf : NULL, tx_state, rx_state); + + if (state == CAN_STATE_BUS_OFF) + can_bus_off(dev); + + if (skb) + netif_rx(skb); +} + static void slc_bump_err(struct slcan *sl) { struct net_device *dev = sl->dev; @@ -372,6 +436,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; }