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;