From patchwork Sun Jun 12 21:39:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2053 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 CC2013F1DD for ; Sun, 12 Jun 2022 23:40:03 +0200 (CEST) Received: by mail-ed1-f69.google.com with SMTP id f9-20020a056402354900b0042ded146259sf2938451edd.20 for ; Sun, 12 Jun 2022 14:40:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1655070003; cv=pass; d=google.com; s=arc-20160816; b=wrC4pnbVeeey6MN4NKujo929cpYjEAZooHdv+MhGY6Uwa/bcRGU2XFmJi6EAnJEWxg AT/zZdcP3dW4SmDmj6owrgPSghaIMNgZZKO38dfjfuN+hXtPMHlZS8VamMaROVH06aYX ZM1LT05klHra6OT8dMgF4/5jInovPxFiq7CCe+azYXf/I8FvuaNl7AoDwib6M3p6tIX2 m3K0bjtF//vFYMtAYIKHSZit8cUft35JLEsB0+xl47FFNhoUHp5GCYqF7qEP+1TuRlyd cccIlaA/tcqtwxrBIdukSXKRUT4VpZaznw5iUkjfNvJwFE623bHlq0QNC/vWFowlVUOV WaGA== 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=NKvohrWFE4+aBEVFDkU1FsOEKjvjK3ZcY2D91IJZfDU=; b=a1EKb5fuUN/kLb1PdKu43x/goBCFBP3pg4hrOI/V2zBVBUFKZT7FwgC+e1t3rQiOnS 2TDy5bu62QtXaWwa0WR+xvihVxOvZ7OxzhcaEhkRhYFVZD+pIPof279YryHbbZKG2LLI 7L7+XnpgTczA601OUghWcTyUzfD/EZ2mkmX28liIXogD/7oEaA/xeMg8/FSxFevY5f31 bqeGscJKp9HxhHOeOo6lGGCmdN/TP9klwv1CuQ2Obu0+Gky3EzaDU8n6R3OcuDyQQeph dw9QjTE3DdYYKuodPaGcD2g81IoB7Hjy3jxaQt9e7YivsiFBAqiXXqV7qkwSDPoXRFDh +vCQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=iySTg+7g; 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=NKvohrWFE4+aBEVFDkU1FsOEKjvjK3ZcY2D91IJZfDU=; b=RX5B+9nxd7yFBO4dYROWXzgMqnAMTvxmPuzY7CvDehNbRMOW9OlO3x/MTOKXnDtipA +qcTUPdZ+0CZ5plfyK7H27uLvIzOZeVgpm8ZMvBDeFOT7sCUCGjw6iuBmLVt1sZ1XqIM OgEBgWNo6wyrVYfRIOkzh6PSj6xcJcYQogpl0= 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=NKvohrWFE4+aBEVFDkU1FsOEKjvjK3ZcY2D91IJZfDU=; b=cW7rhOOfucwVCfTIqlaxWS4W8UHZEI+UEC1VBQl6CnOy8vDmD4j6P5zdRsJH9uq8La m7ydL9OjaVEhYp59bU+F4baiXpZ5wrrPmFt0G5Q0stD8hPFWkZz+99cb46q/YtEHj3wx QhFVPKlCLO674hMbnyv0i+XOC3FVnRcGnAPW1iW0y0xpuMJ98LkJb9G5VRsVJSfr5QiA JBxLxky1IWvN4sMslZTvimsqEom/ommh2qiPS5/NYNqYAprYh76s6zuedsCMq+7tAjKK 5UDpHbwZch8k7BuWlDGAi7Lor33/SWtsiPg9+YPxERwlyR+dBVzKMsyXODVM4NEtAQup htBg== X-Gm-Message-State: AOAM533DNUAYRRPR1faLrlkTZ3yXU7c4W5TgqqOPoqIV3yXZeAMs9njg W22KYlZElgm4M+UABSRa6HpMWHY3 X-Google-Smtp-Source: ABdhPJySKCsvBc4ddo4lBGjFg7F8TXeueQF3lUiy1rF27XOFmZ+az7SdsJUbY6TH3NAGZrW2K+9aJw== X-Received: by 2002:a17:907:1620:b0:711:da21:d836 with SMTP id hb32-20020a170907162000b00711da21d836mr30912139ejc.427.1655070003618; Sun, 12 Jun 2022 14:40:03 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:424b:b0:433:426d:7e15 with SMTP id g11-20020a056402424b00b00433426d7e15ls1835779edb.0.gmail; Sun, 12 Jun 2022 14:40:02 -0700 (PDT) X-Received: by 2002:a05:6402:35c4:b0:42f:b0f8:6a69 with SMTP id z4-20020a05640235c400b0042fb0f86a69mr52343390edc.180.1655070002686; Sun, 12 Jun 2022 14:40:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655070002; cv=none; d=google.com; s=arc-20160816; b=LnxuH2jz2jJLdZFxkabv7w8UW2Z/76embbJg3o0QS9hpLKgOpKSEUfIFKdsfWJcvl5 oD/QqBO6gq4yi4mXXvl9tiACCAh3V/VYGtzxupNJpgqz8x2XRP9liB5I3ZiL9aVQK0va ocoOQNyE2Um2XJVBGOmDiVROxXqzpKvfHC86bG9qfsqcjFheyPFWdGrP6WeQCT4TCtbx mL4OjpEyxuBZ43f+PqtFdjXDWPNMXfGTkGX1Y84tuPrzRFfPTsQb/gH+XzDnqNDt8kIA XQumXU2UMy51wcH/DYnKzZ7lWXduZKxeZI/+piMohzk/wHphD7giRDmwUmF3CE0Nq8EG AwOQ== 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=UpyKa7+uiIpxrunvBDbFWo+0Nybf0w4Bu0XA6EFem0M=; b=Jz9OI82S/zSvbFASKzDN4J/7YO5Omfza0wwFwvSBsDXEUzF28y7scrq8YNvlU4o9wA BmlSYS1YaWuHAac7R3+kk2bidnRrLbeiCAmGXLzd9tgvst9e5rhIufpwCq62n5AwVuYi lv4znYBzTC511cjPMvRojZnzwxbvjdsnYtIy6eSRp0YxIZNz/Gy3dnfcfRgFPnllBczt mdfQsjxtfr49mNm2xtuOb5SxuTVCPLYPt/zPjC4a8oBdKID36+zzQdLAVfo4AspbJREH Xg1MbnObvU/DyjwDK3oaKCFzYX1vxLj2njM2Yw24+qDmR2Dfu3U4SYRhRhmNh4rNVqhi F86w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=iySTg+7g; 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 jy7-20020a170907762700b007107e67fe56sor1305719ejc.105.2022.06.12.14.40.02 for (Google Transport Security); Sun, 12 Jun 2022 14:40:02 -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:907:8195:b0:710:b40:95d2 with SMTP id iy21-20020a170907819500b007100b4095d2mr41307282ejc.604.1655070002462; Sun, 12 Jun 2022 14:40:02 -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 u10-20020a1709061daa00b00711d546f8a8sm2909398ejh.139.2022.06.12.14.39.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jun 2022 14:40:02 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: michael@amarulasolutions.com, Amarula patchwork , Oliver Hartkopp , 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 v3 06/13] can: slcan: allow to send commands to the adapter Date: Sun, 12 Jun 2022 23:39:20 +0200 Message-Id: <20220612213927.3004444-7-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220612213927.3004444-1-dario.binacchi@amarulasolutions.com> References: <20220612213927.3004444-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=iySTg+7g; 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 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 a70f930b7c3a..4639a63c3af8 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 == 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;