From patchwork Tue Jun 14 12:28:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2073 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 88A193F03E for ; Tue, 14 Jun 2022 14:28:38 +0200 (CEST) Received: by mail-ed1-f69.google.com with SMTP id o2-20020a056402438200b00434ec3efc03sf4018096edc.9 for ; Tue, 14 Jun 2022 05:28:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1655209718; cv=pass; d=google.com; s=arc-20160816; b=BV42Suv+YpCWwyXkPsRuuAanqvpPHETlOrlVs1w78TzNj7X1ntrqnQS183y85YOllp U4YhnMlwilT//81a4kQFTX6iJ22vKg/Qg0mNv++qayXgZ3Kd7FNMVXsmF6M+QlsNVony wiiPVOzqLAO4Cmu/XEelJ2Et9fhQUADiPRBuYvYHnUHjc+2J5DiAUVvdK63TwVU/pLCE N+s78VyVsKxYRyRokq+NoyQ3ZFgzwNdKY+gfX683/E/+gaRNSak5IH9IFz5CZ6WUFvh9 m2EbYy6hJH6k0HbPqDdHBaZZUjyR090GMpK1tJrf2xZ/gVEkkn7dm/iuKkESWCmVtAZz vT9g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=HO+8scD1DlOZyLa1IxKsgZRmMYiqE+Q2KeuEA3+aBQ0=; b=xOrv5lhYe8wfxwH/mLKvxkyPWXnVov2myJY+UowXbRvJCGQgHgHTL8WUEkSRwiyQcB PVeQb6NqC0TyLsuo8xi28Wa002ot4fM20Ac2PPqo8TCUwsULg7siuau0BPqrFS/OfYhn dCb8zfyTY44wb6NgEhMmD5IzCBh2OfHhGzpfqYQbjIq3H0nnr6oly9FZzTrC8GcZ4S1S OIkPEd6AfzWaaLcWaMuM5dmdactXEa38hbKuZnbLj5huT78HkyzA7Qm1bw0uI62lFw/x lc4ORDYeMrSBh84L+9YjBHYseBO40VPLplN01n0fvhX0oCzE1nqpC/IKgzbKbBCfBHl/ wk1g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=fcozqSg6; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=HO+8scD1DlOZyLa1IxKsgZRmMYiqE+Q2KeuEA3+aBQ0=; b=rp3kOUq0m5Mk4Hy4eDUgIOD/CW+5A1YBMKWUEzhBehkyOzkquV/NB3+N3qlkvUrNse bn97TfveVNuv71K4m/xFzzYv4m3TEJ6WXm1WQzauSuFXSligerE5iydeSarZg7ZW6YLh lhIODtBwh0K7Lfrue+UXnnk54ScZCJygQfTCY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=HO+8scD1DlOZyLa1IxKsgZRmMYiqE+Q2KeuEA3+aBQ0=; b=FF08gWyrhXKVBVJTy2QqMEoA0iKGoCTkq7Ug/Rc7MtRq3QR/HDc85I3vzhFVLCP0o8 fql2YBBzCnsfvWr3skL52ml9bcRwc4/AU713omgg4hiffwAMTl9/DkHcAD7dKl21Ieg2 Q3xrA4fzQama0Zo9nW6+NJtsqkuXLWWHKD3Ogfw+kaZf9a46HPtofQCDwoFGIN5Cfzm5 42UybdBbFXUtK4/ZWIAZqptelUM23ptiLjAYsvXRq2jiiP/Rm2/QcKcq/H/x/hsTwT9z uZYtWAt1yoknFedZ8KTjJZD17/gyJHTMyCYjNsfX1ZXCfecjABA34Tk/YbGFSxqyqZed P0wg== X-Gm-Message-State: AJIora8zGJyw0P0QeS8BMbDtZRnCEl5ZOnuhwZ9toPH0O/+EYYyvIqHi 9txo4IuNzHndrzMNxFSx3UtZeWnA X-Google-Smtp-Source: ABdhPJwYRWQmk/Brd3dS2FthmSE2i72pZ3kRdDnqUd7QZIYpf3LHuMgwZYaWq1ywGOum5BbfalTO5g== X-Received: by 2002:a17:906:eb54:b0:708:99d6:83e with SMTP id mc20-20020a170906eb5400b0070899d6083emr3880419ejb.745.1655209718383; Tue, 14 Jun 2022 05:28:38 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:907:97c4:b0:711:d2c2:9fa4 with SMTP id js4-20020a17090797c400b00711d2c29fa4ls992225ejc.9.gmail; Tue, 14 Jun 2022 05:28:37 -0700 (PDT) X-Received: by 2002:a17:907:3e91:b0:711:ea5e:2d4 with SMTP id hs17-20020a1709073e9100b00711ea5e02d4mr3954752ejc.52.1655209717200; Tue, 14 Jun 2022 05:28:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655209717; cv=none; d=google.com; s=arc-20160816; b=OQDoCsjm7MGUjHISVA1KkPdpxLw+k5Q6u/ss59C8orIPK9gjcg3CDbawWOuK2MVGJn put1rh2e92hJNqTGFLfqR14XVMPobxNURE1yoN6i0RNeOu7T1/wDP5BeSIfR7GdPxRHE DuDp6rxUhReoS06wMeHdletet8h+HHvRwTFbumL3zHj2TSzkugQs4rFaTUP9dnJClhvx TCwW0R5IivRt7C5vVpfSr8KJvZl2Pd34i3ccZMzG9claixq3BTw5GADRGTT0Cv4HQAhM bcGSpni44AEJRBGj/7dRv4falY6EiRWpi64pRRrzRQHNiOrJNR3HlREeQWwq8AbSEezW FmkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=4Ikx/I3Y696YQQvJOfJvkR+b8+rk3mrxAawgjIDEUZ0=; b=mbHgFrNRIskZYt+e2sj5fWLVHGje+4hgiirUG1qdniGZyC/TLri8/JJeciOlS/aK/k wtbAY29WSyWCGq8Wa6vzgtyjVRXZx8XObRyn2Zw0N7tiFtjIXxhn1jT1WnCO15d6jCcu zg9/8xJayg3NI5XASvPZXzniI3o+bCMLT68bbZ3iuy+aXsgGs9cuSoByJJSmj9ZeZyUI zGL9ylcQ1XkBH60b/mpA96zjh2zjVtuQB++2Vh7xAQVxsq6O86hkCJVBx17xwVg4xy3r qDv9finnemwf6XUYbbKXgC9oK/zYLcF+v3Pvg2zwHU40n1ZP3+Eu1e7SbyzMbVYZuQZW SEnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=fcozqSg6; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id yz2-20020a170906dc4200b006fa8e1e0684sor3241790ejb.37.2022.06.14.05.28.37 for (Google Transport Security); Tue, 14 Jun 2022 05:28:37 -0700 (PDT) Received-SPF: pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Received: by 2002:a17:906:73d4:b0:715:701c:ae96 with SMTP id n20-20020a17090673d400b00715701cae96mr4033479ejl.50.1655209716999; Tue, 14 Jun 2022 05:28:36 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.amarulasolutions.com (host-80-116-90-174.pool80116.interbusiness.it. [80.116.90.174]) by smtp.gmail.com with ESMTPSA id z22-20020a17090655d600b006f3ef214e2csm5087043ejp.146.2022.06.14.05.28.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jun 2022 05:28:36 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: Amarula patchwork , Oliver Hartkopp , michael@amarulasolutions.com, Dario Binacchi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Marc Kleine-Budde , Paolo Abeni , Wolfgang Grandegger , linux-can@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v4 08/12] can: slcan: send the open/close commands to the adapter Date: Tue, 14 Jun 2022 14:28:17 +0200 Message-Id: <20220614122821.3646071-9-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220614122821.3646071-1-dario.binacchi@amarulasolutions.com> References: <20220614122821.3646071-1-dario.binacchi@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: dario.binacchi@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=fcozqSg6; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , In case the bitrate has been set via ip tool, this patch changes the driver to send the open ("O\r") and close ("C\r) commands to the adapter. Signed-off-by: Dario Binacchi --- Changes in v4: - Squashed to the patch [v3,09/13] can: slcan: send the close command to the adapter. - Use the CAN_BITRATE_UNKNOWN macro. Changes in v2: - Improve the commit message. drivers/net/can/slcan.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/drivers/net/can/slcan.c b/drivers/net/can/slcan.c index bd3cf53246c7..b08e63f59b8e 100644 --- a/drivers/net/can/slcan.c +++ b/drivers/net/can/slcan.c @@ -436,9 +436,20 @@ static int slcan_transmit_cmd(struct slcan *sl, const unsigned char *cmd) static int slc_close(struct net_device *dev) { struct slcan *sl = netdev_priv(dev); + int err; spin_lock_bh(&sl->lock); if (sl->tty) { + if (sl->can.bittiming.bitrate && + sl->can.bittiming.bitrate != CAN_BITRATE_UNKNOWN) { + spin_unlock_bh(&sl->lock); + err = slcan_transmit_cmd(sl, "C\r"); + spin_lock_bh(&sl->lock); + if (err) + netdev_warn(dev, + "failed to send close command 'C\\r'\n"); + } + /* TTY discipline is running. */ clear_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags); } @@ -497,14 +508,23 @@ static int slc_open(struct net_device *dev) netdev_err(dev, "failed to send bitrate command 'C\\rS%d\\r'\n", s); - close_candev(dev); - return err; + goto cmd_transmit_failed; + } + + err = slcan_transmit_cmd(sl, "O\r"); + if (err) { + netdev_err(dev, "failed to send open command 'O\\r'\n"); + goto cmd_transmit_failed; } } sl->can.state = CAN_STATE_ERROR_ACTIVE; netif_start_queue(dev); return 0; + +cmd_transmit_failed: + close_candev(dev); + return err; } static void slc_dealloc(struct slcan *sl)