From patchwork Thu Jun 2 16:04:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 1990 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 3962F3F06D for ; Thu, 2 Jun 2022 18:04:46 +0200 (CEST) Received: by mail-ed1-f70.google.com with SMTP id eh10-20020a0564020f8a00b0042dd9bf7c57sf3765277edb.17 for ; Thu, 02 Jun 2022 09:04:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1654185886; cv=pass; d=google.com; s=arc-20160816; b=eIzvz/tqoqnVdwOEDuVTDqjGJyZ6KXjJup7jUR0RMzBE2Gg6SUZxPrZ388BHfenzHP UMQCiXnIhCm1H61FpDigIkM8G/MfbaZXSCgDA6/Fg7zZamOVtGdabUoD2eJId1Lr5wvh 9XfmJzRAyrPcNLZWljZt5iNYgDIohvkeBQ5Fhr/DmeefgDXyGOcahi6TovQM60sBzYv1 +7B7CuUXv6luGHlLfdSZW8g8PiWYGFYRa6P7DtkhwvU+AqIEexnryXhKnSUZcW9YwDyi 4/+vGD/pWnROKgFresT6I2kh3AIsnSSEchAKKiBz8nvtvVUbp/wofz/5RUqOEvH166PF oVpA== 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=NPHJ0uvh1gW7ErYwjw+elHhXp4CUxSNj+j2BQYMETK4=; b=c8d6N3eN2JZNk6t8zw5St2sNhnRTVIDa3YH7rtEp6vdGywFx3ZuHZzjxy5D7W/pLum o37Fj2MOhsIUlF1Es29Ti9Rp+Wfp3MeDQ8fhlCKwOQc3cWGJ5ehgMtu7MTwqqgVp36BY XMJgS3FkRLDgTkhgCx4Br4W7Ld87r0O6UDhJGszEqn7NnlqOcWLamkXDyuJ0jWioiAT5 KIgC6TXU3EVeuU7hmclqlRIcwTtE0tAnAxSxqkdWReFrvA9tE6HVRMK3jr78CY0qUS3t Z4kLOfGdO8q4wGtf7Brec3KD1QLBhWisdjO1Uuf9gAfLJaNm0K/f1CYgIrY9mF+MfCrv 3Wjg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=d27QEBWe; 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=NPHJ0uvh1gW7ErYwjw+elHhXp4CUxSNj+j2BQYMETK4=; b=qqbcK3fTC+SlF6/SDmdEZoYVKvZjFCyA5TZgQBIvlK8aHm9UOiUCO0HWIUNFMLUM9d Dri/v09KjfmZ9k0PNvQfjl8qGRtUB/vSrAgNs9R9RzehMRX5/iP81TbZ2zheA+N69lU3 PQ6mXwasKRjaNVOZ7UqrPsEcA2h6TcN5sj50g= 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=NPHJ0uvh1gW7ErYwjw+elHhXp4CUxSNj+j2BQYMETK4=; b=MyIJQCt2jHFg1bgUcp20cRxlFKHf9zVD2Ro0ghk/q2jDYeGxLEEkljQmB+iral9X98 Dq8QGqvoHL6oHLoRlJZXBWYFN2FX7EtzCEE1A2xb/yRC9Eo/NdBN4LELX1PAiSyu7sQT fDIJr18I6GA86EgllEEouVJ4g2RJ1S476HOlPapHDNkjjmizgaxQ3nDLIckTmpSGmEss 0f6t/1wv786ZMn0y9EpNiXG4ocKXl7c6zfu4ClzBikUOH5XS9J23WNd3ZeNtJPssHO21 p4nNNgv8geBOjr9l6kwQT9y7mIWBr4zO8twlRiGJvRLXJa3L3P3r07IfTtPpKZTTlKHT INjw== X-Gm-Message-State: AOAM530DUtm8ReEsCqQYOay4I48DN3pDwjN6fmWQJVnCku9juTl5qpFw BSp3kILyMsZ3NdGI7Vnu66fUb0EN X-Google-Smtp-Source: ABdhPJwPlt9qFeDv634Fd/iMsFyMR+Ds8ok7tVA60kj4h495l0H1ylRa5SM2lNSDDysUvvWwlLIsww== X-Received: by 2002:a17:907:7b8a:b0:707:59d4:14a3 with SMTP id ne10-20020a1709077b8a00b0070759d414a3mr4906621ejc.51.1654185885971; Thu, 02 Jun 2022 09:04:45 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:906:6a26:b0:70a:1088:57d1 with SMTP id qw38-20020a1709066a2600b0070a108857d1ls1684122ejc.3.gmail; Thu, 02 Jun 2022 09:04:45 -0700 (PDT) X-Received: by 2002:a17:907:72d2:b0:703:9177:7d1f with SMTP id du18-20020a17090772d200b0070391777d1fmr4845528ejc.144.1654185884859; Thu, 02 Jun 2022 09:04:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654185884; cv=none; d=google.com; s=arc-20160816; b=npdXIz21IJvBWdBzRVsmfoVrxUbFPAvLafbxUDjFxiYMcxrvOgUD9Gck6n3C0Nf8Ac GS5bVxZxi3GIaacTLBPCWKBwF4FcSb2+QnrHOsz/lff0MWX20y4OSj6AaBbCnismMp3y 6I1yAiz2DoBdMS5Blje19R65+wf7lL3pKT3TMPof3Qmarna3LTdMn/WLyUzSNcLBim7k RDRprj4JNDJI4G0Ic+zBDYPDl98+UbgUJ7EKiTgz8nxGueAozilya2tO6xsNdgvit16j k+0Bbt2JYrdZj13Rswd2IBAR8Cg3VnPHPgoGmYmgO9wX+CoUFUWuXVQXOK1Rd8CDfPMs 07ug== 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=UtQBA2r2SSLSOGc5ftt/ugZMK3Is2I3sXhmi4Ilvb5o=; b=MC7iYfL1DNsWfxurTW+43XP+jEVRzaTFD3HxyqFQSAL0gWiX1mI4xFc3bzoX25scy+ WCbnUQGXnZdVmeUpm7CWNx58tfwaFiiGWYww3DiMUIFnyNDo3oDl6YTljdVlYLjWnkEH cAglQlSNSyYyZ/QwHyHyXOJGqCepudXdyZaXmKP7su1bKJ32SST6TfE25blbswP0ScT7 CAuZUVWSf/4GEgQP3J92zAiu5sOjv3C/Se/xQm5jxLASkXpAGeoXO+S73eTfYYlLpGBT QeiUjGnKGTg8YEY9HolWnd657pPYkzotVIQvu0/QOznY2I+hzo+MZLFrHJ/U59BbNWhI HPcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=d27QEBWe; 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 g1-20020a170906954100b006e04f1efcb8sor2559850ejy.41.2022.06.02.09.04.44 for (Google Transport Security); Thu, 02 Jun 2022 09:04:44 -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:a0c8:b0:6fe:b73c:193f with SMTP id hw8-20020a170907a0c800b006feb73c193fmr5131058ejc.11.1654185884317; Thu, 02 Jun 2022 09:04:44 -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 f3-20020a056402150300b0042dd3bf1403sm2637095edw.54.2022.06.02.09.04.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jun 2022 09:04:43 -0700 (PDT) From: Dario Binacchi To: linux-amarula@amarulasolutions.com Cc: dario.binacchi@amarulasolutions.com, michael@amarulasolutions.com, tommaso.merciai@amarulasolutions.com Subject: [RFC PATCH v2 06/13] can: slcan: allow to send commands to the adapter Date: Thu, 2 Jun 2022 18:04:27 +0200 Message-Id: <20220602160434.225417-7-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220602160434.225417-1-dario.binacchi@amarulasolutions.com> References: <20220602160434.225417-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=d27QEBWe; 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. 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 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;