Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1406887iog; Tue, 14 Jun 2022 05:34:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxnxTo0T7JPBcNP74Lb09fHHEmZqdUlgyKAqYFQUL05TdhrLJXrwBBGzKMMxjoj+13biv3R X-Received: by 2002:a17:907:7f06:b0:6fe:b81f:f885 with SMTP id qf6-20020a1709077f0600b006feb81ff885mr4121727ejc.621.1655210094436; Tue, 14 Jun 2022 05:34:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655210094; cv=none; d=google.com; s=arc-20160816; b=aY6VkPik23W1X0IdfmLWZen0ogJitjR9ZDs364YoXpemYKZjtLn1B6KuVaITA2NaWB 3ZSi3SRkEQBZvVO6PKvvKr6djshgK6Lx5oL5IZmXfE/M5nw0HjWlfYyVxi0yG1BC8t2h vJxEMjDf4R9tjn2LhqGGq/m1/BpQx4KF/WVCR9r/xCLLtKs0DOU4PhmWcIU20e9q6fbE AE9widNO2OiKp3akpFGScW5kkg/WOPEU7uBcqFJ0l8eNNm6SjrSh1h19Ldu9/JVWq1VX 1rye1zmUNDp9xuer8dd1TiflJtMxWfDsYQpFme4QE2Aez0P2vYfhQN6JSzlOJOadU+RS bjpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4Ikx/I3Y696YQQvJOfJvkR+b8+rk3mrxAawgjIDEUZ0=; b=Bj8muyGW+EMa4V71APHMTvYZ7ojxKQNb4/Kfp/+o4zzrDzU6Z8VYwiV+dWc8UV9LMt 2WE5e2e1scr7P8BiqI0NqTkvkfXEdIm7ZlkxhsOIdzvkym+Vt0AtRbXRZCRr97kNmyP5 J+FfrC+3nd7D4YlALPYN6t5KHH/TOdmZwpjIoXE718bh+jYB4JoIunUfAu80+vv4pzwA CmSIS084X6jHcxvyCLUVAuwlxuQgC0CjoM0fHa8uhZMtwB5UWYdjEBVIL3w6A5bJp2j9 fy2kkQq2qWRN0W46lPPKJRuj+0NIDWtNonEop0PC7P1LSo39WmMVp2KFy6hM1fPDCNYn 706A== 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 linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sa17-20020a1709076d1100b0071076a14dbcsi11875344ejc.772.2022.06.14.05.34.28; Tue, 14 Jun 2022 05:34:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=fcozqSg6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243335AbiFNM3d (ORCPT + 99 others); Tue, 14 Jun 2022 08:29:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243885AbiFNM2k (ORCPT ); Tue, 14 Jun 2022 08:28:40 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9ED4123148 for ; Tue, 14 Jun 2022 05:28:38 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id s12so16869140ejx.3 for ; Tue, 14 Jun 2022 05:28:38 -0700 (PDT) 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:content-transfer-encoding; bh=4Ikx/I3Y696YQQvJOfJvkR+b8+rk3mrxAawgjIDEUZ0=; b=fcozqSg6IKoKg9kPzNk4vgpeYJBfA6sRK6QUNqlE5NGhEPGgKBho033KaqjRspCizB SqJWccoggeLwKFyCo25eeFXDvXO1lQoxQGi/uhEkA0etpMW/1iDdWvYlaWea8rr6SYjB ASpWjX2+Vw4TGE6xjCOUb4HdAumC/gkcubYVs= 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:content-transfer-encoding; bh=4Ikx/I3Y696YQQvJOfJvkR+b8+rk3mrxAawgjIDEUZ0=; b=XpMJRlIW1DwFAyvaq6nzGDKoPC6DDGzbou/bv/AY1omtvvw0hL4I1rfGGBmIdQf5mv NTA4K8BOL2n9TpGSkJW0mUDvVstjweGnJ9ogLvozOejTx7zs3orFMI+fgyICjUSFyZyD 241212BbQpLdOhOmuVuFFrnNMubgmjSICP1wIAYKzA1s1RedUVR+9vRaFEUP2d2Tk0W3 pKHsLe19X9462voINtWPGWJNuHMzQhQZfV49j1f7fSYVfS3DEfs/iWNX7MTLwelOknY2 EPcGCd7OWLq9MHXkC19gVW28ijPURVAv8GzfJ7oeXAdGmKBUK1tWcu7AOlHvhiy24DOA rshg== X-Gm-Message-State: AOAM5334TGOapXo+9ew2UpvzVP59LG4FjAHTTZ++u40h3AptY7JG5GDh cDAmgEZFZTLTbvEGonZwt+tGe90AqhUkXw== 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) -- 2.32.0