From patchwork Tue Jun 7 09:47:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2019 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 0C0233F08A for ; Tue, 7 Jun 2022 11:48:23 +0200 (CEST) Received: by mail-wm1-f71.google.com with SMTP id k5-20020a05600c0b4500b003941ca130f9sf5595120wmr.0 for ; Tue, 07 Jun 2022 02:48:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1654595302; cv=pass; d=google.com; s=arc-20160816; b=Eet7Psr9l1e/Y5UH7eFMub0ijUqj8N5/DHXsQRdcABC2+Jbd1ve0PVpp2Rt6X1zpQ+ P0EvMYC0BL5EP0Wth9ZNxW3Cj96HdU+i382db6ZT759z7G7/cSu6mPkvBlffAaoug3Bw LSJlUgDGPkdjjOdLzbNLiwW4cjSySnPxmlH6i88z9v2z4TYFquzVxzzJCB/vTQNPhUOn oT+U5T+xmuKFoPfTjlw3zHrWIhRx8hfIns0V18ckbrTjYC+JAINNX683v6InpaXcnW1t Ah6rmH29PzdhmoL/OsAZKTKGYQ7QaFrzI3S7tlWlKCHwTXvRDS3rKZVIPaezF8Dpkgke Yf5g== 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=na9RjzBj2O3XOcAQsf/UObvj4bI+rIZ1Je36SvNQj3I=; b=jwi90f5h3fbVBvntTuKETAMI6XZlKVoejgSjnmmrqO3zQYyfpZsOsqT56SqnkUgbq4 rd3mxtYEd4lEZBHstCwMekh4NiivLuJItw6QIdmM990f5MO+L8bkXwoK+VJuK8QOLca7 AotiURygwNnQXiIVRZ67P22MkTRlMMCdCXYN6gwxjaDCX+Ste7xvpF7YlB0O4GoeCjBe vf5wNv54FeWN2GKecAB8z7gQkf75rShOj5OVk1ix3sAtZ6Wp6gzqmnHHt39O1OjZb43W fVZEL9+MBm4r0r+t1tuHdSDLoatQ9ZDkDdk3/z4+lUxUQkDy7DX6a4BT7X9beEuy1Hdy ZHTQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="jnJyM9v/"; 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=na9RjzBj2O3XOcAQsf/UObvj4bI+rIZ1Je36SvNQj3I=; b=gXhHRxg6ue2FgDStsRvul9MRIwk41OWzfzmnpKNQGTO6S9FCJ6vTeiwQ/CDG1RgDtZ GNBgD8uxowYrjq9ZvCJ3fSzuZqvy67EAtDHGvSt/RiRHlqYfWrP1AyPS5RCPrjiOxaQ+ s9ObMVk2aeas/3sIsbQU6J55gnORLp4x60wqM= 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=na9RjzBj2O3XOcAQsf/UObvj4bI+rIZ1Je36SvNQj3I=; b=Wz2f2Ois1kbV7129BbbA3JXOu3SUAqbpGVpuENp17VJh4Z72rTLE6pr3vklEVi1Xbb 8tm7I9ndY7KBrqICLe/RyiH+Qhyc5rcnygqgXLOrI0LyBPEQHGDFB1vZp7k1CtgHycJr 0f5Aa/9sC3ih7Oylq1E+y5U5kfEg6Itx4R7HZFPcMaEnGSI6UUAPUTvvxOZyDop+p61s FEavAsFkWVre7sa2/vJFCr30AIOd/8MPIwgBGL5WMDzv5fcA1zaEhStSPR8zQ9jw5c1d IHsEy5MybtgImM1Didh0p5OU87mgP2fRjvhAS5LItDKEU72LzFO/2KnaS6Z2zg1vvGcv E3NQ== X-Gm-Message-State: AOAM533Am3jpY0ZeP0Vj4D+c6RCyP2XYRZTjb2zrq5SzYCZBPnG71hGI hFT5LDpKIKkdnFaGuzy9mqNeBUCH X-Google-Smtp-Source: ABdhPJyUJsQ202Gmm9GmfLjKpwun8SbcUscu1G0qxQbeHIkIu0Pp3wLTAlH5xFy5yggPkes6iyyPlg== X-Received: by 2002:adf:b358:0:b0:216:508c:e0bf with SMTP id k24-20020adfb358000000b00216508ce0bfmr15628790wrd.204.1654595302852; Tue, 07 Jun 2022 02:48:22 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a5d:648e:0:b0:217:c8b4:52e3 with SMTP id o14-20020a5d648e000000b00217c8b452e3ls4145147wri.1.gmail; Tue, 07 Jun 2022 02:48:22 -0700 (PDT) X-Received: by 2002:a05:6000:1568:b0:20f:d416:e5ac with SMTP id 8-20020a056000156800b0020fd416e5acmr27039639wrz.190.1654595301847; Tue, 07 Jun 2022 02:48:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654595301; cv=none; d=google.com; s=arc-20160816; b=h841I6SQtuj5bvU1INd1f/mORf8MZKL85dxcy1U8ePiju71QmKd1CekMwn84kfNkUV 8FGphL4XbB0+oxcczVc4A38kQSo6iDXWUSrQoGEvmCGsVl3leqYImmpkMTWzmcEqpaM8 UPbOl8kxu4iI+ZNJyXdOJF2u3OxPvL2QvauNSS39sssWW8XDFXIa3y43BW193ShT7Vln mcNyUZ9gSWp+3QfcpsyAlXmrhisR1KTsiecSVkY8Aw3bxeCE/t2L4J7Fg5ZFdiYHqZi8 NO3zNCMXQFxi1FNtxapapDgjnhnY2yp53hzpq0ZPAETROfi0b2mGJotGS3G0RkgoleBN B/ew== 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=4002ZoQbfZgD0XX9YDZ6wPiQ9rsbL1Ku9Z7hWp9EhXQ=; b=oftWV2AnSg5zCHOvZGPHsuO/b5r/bZZlDdK++Qu7Fa1lKmebwcr5DSlQzWHxJrtapl Y3srSVUswwT9xMbw+UIIJpXNfzdM2+aC1Nt3X7Uw797xd2bXrqyPIwfz+VscUewjMBUx o+UT1fWchE7DYh2rM29lJoX3b9dRAiOwmLNdVFy49dDYcq6ZBxanP8J+Prg8107AodbU jBLS1dYHWjOsNGMMlUqasvYAPgxjKyzDS+7YdWllLIXD0TK+z7lpudDDtVOepnuOMcrY lIK26FKMcT4YG7J0gBA+Was9A1YSiOyV1NZS3nRAnTYAW08S6Q3GsiNu1sG2sW0nJCEx DMwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="jnJyM9v/"; 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 f8-20020adfdb48000000b00213b49a9fb8sor7268595wrj.35.2022.06.07.02.48.21 for (Google Transport Security); Tue, 07 Jun 2022 02:48:21 -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:adf:fb05:0:b0:20a:e113:8f3f with SMTP id c5-20020adffb05000000b0020ae1138f3fmr26424039wrr.534.1654595301578; Tue, 07 Jun 2022 02:48:21 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.pdxnet.pdxeng.ch (mob-5-90-137-51.net.vodafone.it. [5.90.137.51]) by smtp.gmail.com with ESMTPSA id o4-20020a05600c510400b0039748be12dbsm23200547wms.47.2022.06.07.02.48.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 02:48:20 -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: [RFC PATCH 06/13] can: slcan: allow to send commands to the adapter Date: Tue, 7 Jun 2022 11:47:45 +0200 Message-Id: <20220607094752.1029295-7-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220607094752.1029295-1-dario.binacchi@amarulasolutions.com> References: <20220607094752.1029295-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="jnJyM9v/"; 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 --- 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 4df0455e11a2..dbd4ebdfa024 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; @@ -310,12 +313,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++; @@ -379,6 +392,36 @@ static netdev_tx_t slc_xmit(struct sk_buff *skb, struct net_device *dev) * Routines looking at netdevice side. ******************************************/ +static int slcan_transmit_cmd(struct slcan *sl, const unsigned char *cmd) +{ + int ret, actual, n; + + spin_lock(&sl->lock); + if (sl->tty == NULL) { + spin_unlock(&sl->lock); + return -ENODEV; + } + + n = snprintf(sl->xbuff, sizeof(sl->xbuff), "%s", cmd); + set_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags); + actual = sl->tty->ops->write(sl->tty, sl->xbuff, n); + sl->xleft = n - actual; + sl->xhead = sl->xbuff + actual; + set_bit(SLF_XCMD, &sl->flags); + spin_unlock(&sl->lock); + ret = wait_event_interruptible_timeout(sl->xcmd_wait, + !test_bit(SLF_XCMD, &sl->flags), + HZ); + clear_bit(SLF_XCMD, &sl->flags); + if (ret == -ERESTARTSYS) + return ret; + + if (ret == 0) + return -ETIMEDOUT; + + return 0; +} + /* Netdevice UP -> DOWN routine */ static int slc_close(struct net_device *dev) { @@ -542,6 +585,7 @@ static struct slcan *slc_alloc(void) sl->dev = dev; spin_lock_init(&sl->lock); INIT_WORK(&sl->tx_work, slcan_transmit); + init_waitqueue_head(&sl->xcmd_wait); slcan_devs[i] = dev; return sl;