From patchwork Tue Jun 14 12:28:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2071 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 911A23F03E for ; Tue, 14 Jun 2022 14:28:35 +0200 (CEST) Received: by mail-ej1-f71.google.com with SMTP id x2-20020a1709065ac200b006d9b316257fsf2805435ejs.12 for ; Tue, 14 Jun 2022 05:28:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1655209715; cv=pass; d=google.com; s=arc-20160816; b=Xx7UqZQ6RcnPZLb6asoUrxsFzs0aKhv4Pnk7rHt26sLRQek3lVNbplv2T04r7cHi+H pe1oT6cAa4otq+luZRI4T4OwVeax7TrRWi27ZbCqvWgdTs6lvfuFGARhSBlwMFpipc+u QITtJbrGCpBYHxSVgEwo2VOSkPCyyvTLgfPYzDShvCcjL50fHZaASJvinwGhv8Jixdfb MQZNXDXiF/znD49KWBUKi71UoKm4IAmwkkmjwyta+MZvaCzQTtlx5D21eY31wHgr8oxu J5bnfgFWHII4yzW/XSdbFdTSVvdrSUEurUNcdDAqfwUsFyQJNDncZY5Tl+zK9OAybEbh BJWw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=omEyssBrLXDOJdJzNKW3I94rHXX8brLbFXHRgTAuWWk=; b=UFQp3Fi2aVGiq66uda+KPvDOarjIpvUtpq+mf8G8HCk6+eaj+MNf/sJoZXGEinOn9M 374KtPN6sYqRCaWrbHUC5RbszQYob/9LuZw11cyats/6aa1vDYYeoBOd8KT5E/anbxEZ XNx2hVz3DPR+lXUYJMKtOcUApUJZg1BJYalh1fg/5s7G60EwyBMZN4ra5VbOq9YE7X7+ PXtTqvayM6dzDjI2cz/WtkjHZD4ypDg0cF9qlVuBW9ljsI/4ljjkByCV8vG/QgknpnJK yQt05x8qGDW1uKlc74SPncWx5TnNPC8PvqIk1SK9F7+UjSLbgfyQ7xMVGqa+B2LAd2tW 6zvQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=XSAUyZOW; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=omEyssBrLXDOJdJzNKW3I94rHXX8brLbFXHRgTAuWWk=; b=Ql4wSxNJTSl4Q2ZZuO72nPwBqYJ2TvuSIWyvNs3UsI3SuHC2lr6bAxF7TVFHiB3Y5e GzjR5J7xoq1718rVyBTl6mG5O/h5kmVYhzpH2Zp7yzivRJzJZ5VIn2aaH6KnyopboqA/ QvVy41tf1oRDQ9S9yjuOB8u4Nikk+0dfd6qcQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=omEyssBrLXDOJdJzNKW3I94rHXX8brLbFXHRgTAuWWk=; b=5RB3bvru+aLM//posq9cnj+oFgmnZqv+Xukl4rKka5eH6XWHFAvDXgMt/Qq56VW9VQ hiv6y0TcpIcR/6gzgIeXRXleUEt6DWDJ0Asjc3yGij61whlwjP1LLEIuWOPgP/v65qc2 TlQEHDb6APTuMPzWpcoH/8EVEXHRnlYJU7AtetoGawJc7JePGk6W67pOpjOJb7RmztU7 vvfAQksvkShnoXzt4qqOT62seRJoOx6tmcvv2EpA1Rdn7gpLuAjN98Xr5IC/sOsCFPHD YsInEhyWOQw89SI+Iu1sjdWsrTrfDPpwUuQbzZHJpJ9xB20VzvyFywFOkjPQoXuz8+OF KR2Q== X-Gm-Message-State: AOAM532whjfb7dFRFaBoNXxcvp7wD7F08WPe8/c9u3sK/Yr6PmSorMsh 1IB9MIvA0HQIryulXBI0s7d1kd1o X-Google-Smtp-Source: ABdhPJyeipC+m9dwhfZIvuivDMwdSSFfgLpbRFTXp8bfUyINBOgNPFbCBkVS2vrzn2GgunHkB4xEIw== X-Received: by 2002:a05:6402:90d:b0:428:bda9:3e6b with SMTP id g13-20020a056402090d00b00428bda93e6bmr5772713edz.132.1655209715424; Tue, 14 Jun 2022 05:28:35 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:907:16a7:b0:718:c04a:5161 with SMTP id hc39-20020a17090716a700b00718c04a5161ls991656ejc.11.gmail; Tue, 14 Jun 2022 05:28:34 -0700 (PDT) X-Received: by 2002:a17:906:72de:b0:711:f8c8:ba00 with SMTP id m30-20020a17090672de00b00711f8c8ba00mr4290408ejl.586.1655209714418; Tue, 14 Jun 2022 05:28:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655209714; cv=none; d=google.com; s=arc-20160816; b=0F6x5Gtj4FN7xLN2tZYevUpSH3Xq7vsRide/p9YYDew9Lkhvtd8QzsmbUwdLr91lu3 n/blVkzgHreTPXSOeNIPM9CU0vSpUBbAMc4VhwgucMqG3GtFfTVEJw8rTjgbuu6NvdUG vjSqfm9RLyEySq/slZGZEMR5atq6EEo/YMrLovMtvl2GgkGFWkeY1NjyTmzKTsKbEWnZ jgOTBqv2JLBTy1urrYGE0FEc5wFLiP7LRwzlkPu221tXz1FWuAkyr0U0Rdocb7TawcuV 6og3BD+aiZGbiDvodwEx7vkF91JBi6OGdUXPdy9N3FO43soPZ9Rrw9je5kWMtWWClsrI e/qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=J7cAHYzHeqO4eieQ7T7B38pR/xwLeH3ndQgGNnjLG/E=; b=vi2UUjZjJRru37iQNkVN+tRwz+XwhKNUF9ob3juD1iZW76xt3rgn5SZBC2YQSKCTSc SpSdiE3szAAuFbomS5JLQLVUA9q0ouijoclboXruJ+yoLvlpWk20c7NYjhRNfBY9fE1S m9Lev4ZMWGaQ4ZPfvsdFFEXto8tLRFz+3Qs6eBxCb0d0XLuIvbbo+txm11snW+asNcdC 8Poj7hLC4ANqb3y2UAM2c5JaFd5k2XY9ZDBaRzz2qYv4c3za5z8OgdmqYCIEpQSW47+J OxJl0DMdazW6xy4mKk//+zYEWTWSb1cYujbpXYpFIpYCQdpJuaMBPleBFRWZPeyQob/U szDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=XSAUyZOW; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id z24-20020a1709063ad800b006fed069d000sor3320132ejd.43.2022.06.14.05.28.34 for (Google Transport Security); Tue, 14 Jun 2022 05:28:34 -0700 (PDT) Received-SPF: pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Received: by 2002:a17:906:7254:b0:6fe:5637:cbe6 with SMTP id n20-20020a170906725400b006fe5637cbe6mr4030190ejk.612.1655209714188; Tue, 14 Jun 2022 05:28:34 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.amarulasolutions.com (host-80-116-90-174.pool80116.interbusiness.it. [80.116.90.174]) by smtp.gmail.com with ESMTPSA id z22-20020a17090655d600b006f3ef214e2csm5087043ejp.146.2022.06.14.05.28.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jun 2022 05:28:33 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: Amarula patchwork , Oliver Hartkopp , michael@amarulasolutions.com, Dario Binacchi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Marc Kleine-Budde , Paolo Abeni , Wolfgang Grandegger , linux-can@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v4 06/12] can: slcan: allow to send commands to the adapter Date: Tue, 14 Jun 2022 14:28:15 +0200 Message-Id: <20220614122821.3646071-7-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220614122821.3646071-1-dario.binacchi@amarulasolutions.com> References: <20220614122821.3646071-1-dario.binacchi@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: dario.binacchi@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=XSAUyZOW; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This is a preparation patch for the upcoming support to change the bitrate via ip tool, reset the adapter error states via the ethtool API and, more generally, send commands to the adapter. Since the close command (i. e. "C\r") will be sent in the ndo_stop() where netif_running() returns false, a new flag bit (i. e. SLF_XCMD) for serial transmission has to be added. Signed-off-by: Dario Binacchi --- Changes in v4: - Replace `sl->tty == NULL' with `!sl->tty'. Changes in v3: - Update the commit description. drivers/net/can/slcan.c | 46 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/slcan.c b/drivers/net/can/slcan.c index c7ff11dd2278..2afddaf62586 100644 --- a/drivers/net/can/slcan.c +++ b/drivers/net/can/slcan.c @@ -97,6 +97,9 @@ struct slcan { unsigned long flags; /* Flag values/ mode etc */ #define SLF_INUSE 0 /* Channel in use */ #define SLF_ERROR 1 /* Parity, etc. error */ +#define SLF_XCMD 2 /* Command transmission */ + wait_queue_head_t xcmd_wait; /* Wait queue for commands */ + /* transmission */ }; static struct net_device **slcan_devs; @@ -315,12 +318,22 @@ static void slcan_transmit(struct work_struct *work) spin_lock_bh(&sl->lock); /* First make sure we're connected. */ - if (!sl->tty || sl->magic != SLCAN_MAGIC || !netif_running(sl->dev)) { + if (!sl->tty || sl->magic != SLCAN_MAGIC || + (unlikely(!netif_running(sl->dev)) && + likely(!test_bit(SLF_XCMD, &sl->flags)))) { spin_unlock_bh(&sl->lock); return; } if (sl->xleft <= 0) { + if (unlikely(test_bit(SLF_XCMD, &sl->flags))) { + clear_bit(SLF_XCMD, &sl->flags); + clear_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags); + spin_unlock_bh(&sl->lock); + wake_up(&sl->xcmd_wait); + return; + } + /* Now serial buffer is almost free & we can start * transmission of another packet */ sl->dev->stats.tx_packets++; @@ -384,6 +397,36 @@ static netdev_tx_t slc_xmit(struct sk_buff *skb, struct net_device *dev) * Routines looking at netdevice side. ******************************************/ +static int slcan_transmit_cmd(struct slcan *sl, const unsigned char *cmd) +{ + int ret, actual, n; + + spin_lock(&sl->lock); + if (!sl->tty) { + spin_unlock(&sl->lock); + return -ENODEV; + } + + n = snprintf(sl->xbuff, sizeof(sl->xbuff), "%s", cmd); + set_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags); + actual = sl->tty->ops->write(sl->tty, sl->xbuff, n); + sl->xleft = n - actual; + sl->xhead = sl->xbuff + actual; + set_bit(SLF_XCMD, &sl->flags); + spin_unlock(&sl->lock); + ret = wait_event_interruptible_timeout(sl->xcmd_wait, + !test_bit(SLF_XCMD, &sl->flags), + HZ); + clear_bit(SLF_XCMD, &sl->flags); + if (ret == -ERESTARTSYS) + return ret; + + if (ret == 0) + return -ETIMEDOUT; + + return 0; +} + /* Netdevice UP -> DOWN routine */ static int slc_close(struct net_device *dev) { @@ -541,6 +584,7 @@ static struct slcan *slc_alloc(void) sl->dev = dev; spin_lock_init(&sl->lock); INIT_WORK(&sl->tx_work, slcan_transmit); + init_waitqueue_head(&sl->xcmd_wait); slcan_devs[i] = dev; return sl;