From patchwork Tue Dec 15 15:56:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: dave penkler X-Patchwork-Id: 344280 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A8F8C4361B for ; Tue, 15 Dec 2020 16:02:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 61FC1224F4 for ; Tue, 15 Dec 2020 16:02:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730683AbgLOQBq (ORCPT ); Tue, 15 Dec 2020 11:01:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730483AbgLOP6B (ORCPT ); Tue, 15 Dec 2020 10:58:01 -0500 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28413C0617A7 for ; Tue, 15 Dec 2020 07:57:21 -0800 (PST) Received: by mail-wm1-x341.google.com with SMTP id g25so178461wmh.1 for ; Tue, 15 Dec 2020 07:57:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mpupbpAiHl0Cv1mnbMYjW/iwG3YQylB90NQFwucdsm8=; b=JSvEUtIUXnrz/2Wmqi5jSql/ZAxPn9o7S77Vg2jWo/+tgsJ22H46lm8OYKbZicrNIP mt14h73b0ZhGZLkgnzfwuF+jzUDxRZ3KbAd2LDfWFZmw6OTyC6QZnEeclh4/mwC5P5FB nMo3nYPOcQxGD3mxKf7g7A8wK7VhCa8qb1shpCIL7bWcjPZOerMin9v6Fsp2jDlea657 qdZiHlQA6yoI/whfhhZUP5hPFowUfdzXFcMlE+MrAYvF/PRRetJmR0a1FFtqRYtv71IL Oao+h03eF+ZPTGoz8ZWnFNsC/kTb7JVRJoIFWZqf/2N+WQO7RqyNnmiLwAaA8bYZCcX7 W5qQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mpupbpAiHl0Cv1mnbMYjW/iwG3YQylB90NQFwucdsm8=; b=MYhl5zIhqxNaA0c0ptdRKAuHVqsVrUg0N6Pvumg0p4NcyTndA8XCPXjFPrXGqk+qbJ 88G751zZ2zImWEXLAh0WSCTcItah1YTgPTCr9UikK9Ibfgpcgtc19JpIggV75Sb6T6cf PAIZMLFAazNjXi/5gL9gCMsoxtlVL+F3QQfLagvyK95ealovrveCMtsTKQr7M12Yvon+ 1PYohKDc0VFiyhgmVDgAa4nZjl1Ge0LDXPx0FntFUBb4bh1xIlpbzp962oAnuE3oTxew hqPsyWw8WGKd37utfyq99g0vbzyLtuM8jidOw/jyoHNtoT2iFZk6uG3z5mX3zyju0CvD FeLQ== X-Gm-Message-State: AOAM5305j+XIwkNrh8vjP5T1jW8oElrZTI0InvgEQ3jnHMBmeIQs85vW 7lOdHILQXW+Q4r24r0qvkeE= X-Google-Smtp-Source: ABdhPJy9UgFtQAUDeoPanZMPcoiV1qo+9ROY4Zmg4uRmWWxE3Bn0qdoePdB2oc4zd47aJOhULMhMwA== X-Received: by 2002:a05:600c:218a:: with SMTP id e10mr33322961wme.27.1608047839902; Tue, 15 Dec 2020 07:57:19 -0800 (PST) Received: from egonzo.toto.net.toto.net ([88.123.121.14]) by smtp.gmail.com with ESMTPSA id c10sm38792018wrb.92.2020.12.15.07.57.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Dec 2020 07:57:19 -0800 (PST) From: Dave Penkler To: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org Cc: guido.kiener@rohde-schwarz.com, john.harvey@non.keysight.com, jian-wei_wu@keysight.com, gabe.jones@ni.com, dpenkler@gmail.com Subject: [PATCH 1/4] USB: usbtmc: Fix reading stale status byte Date: Tue, 15 Dec 2020 16:56:18 +0100 Message-Id: <20201215155621.9592-2-dpenkler@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201215155621.9592-1-dpenkler@gmail.com> References: <20201215155621.9592-1-dpenkler@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The ioctl USBTMC488_IOCTL_READ_STB either returns a cached status byte (STB) sent by the device due to a service request (SRQ) condition or the STB obtained from a query to the device with a READ_STATUS_BYTE control message. When the query is interrupted by an SRQ message on the interrupt pipe, the ioctl still returns the requested STB while the STB of the out-of-band SRQ message is cached for the next call of this ioctl. However the cached SRQ STB represents a state that was previous to the last returned STB. Furthermore the cached SRQ STB can be stale and not reflect the current state of the device. The fixed ioctl now always reads the STB from the device and if the associated file descriptor has the srq_asserted bit set it ors in the RQS bit to the returned STB and clears the srq_asserted bit conformant to subclass USB488 devices. Signed-off-by: Dave Penkler Reviewed-by: Guido Kiener Tested-by: Jian-Wei Wu --- drivers/usb/class/usbtmc.c | 46 +++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c index b222b777e6a4..189f06dcb7d3 100644 --- a/drivers/usb/class/usbtmc.c +++ b/drivers/usb/class/usbtmc.c @@ -475,33 +475,17 @@ static int usbtmc_ioctl_abort_bulk_out(struct usbtmc_device_data *data) return usbtmc_ioctl_abort_bulk_out_tag(data, data->bTag_last_write); } -static int usbtmc488_ioctl_read_stb(struct usbtmc_file_data *file_data, - void __user *arg) +static int usbtmc_get_stb(struct usbtmc_file_data *file_data, __u8 *stb) { struct usbtmc_device_data *data = file_data->data; struct device *dev = &data->intf->dev; - int srq_asserted = 0; u8 *buffer; u8 tag; - __u8 stb; int rv; dev_dbg(dev, "Enter ioctl_read_stb iin_ep_present: %d\n", data->iin_ep_present); - spin_lock_irq(&data->dev_lock); - srq_asserted = atomic_xchg(&file_data->srq_asserted, srq_asserted); - if (srq_asserted) { - /* a STB with SRQ is already received */ - stb = file_data->srq_byte; - spin_unlock_irq(&data->dev_lock); - rv = put_user(stb, (__u8 __user *)arg); - dev_dbg(dev, "stb:0x%02x with srq received %d\n", - (unsigned int)stb, rv); - return rv; - } - spin_unlock_irq(&data->dev_lock); - buffer = kmalloc(8, GFP_KERNEL); if (!buffer) return -ENOMEM; @@ -548,13 +532,12 @@ static int usbtmc488_ioctl_read_stb(struct usbtmc_file_data *file_data, data->iin_bTag, tag); } - stb = data->bNotify2; + *stb = data->bNotify2; } else { - stb = buffer[2]; + *stb = buffer[2]; } - rv = put_user(stb, (__u8 __user *)arg); - dev_dbg(dev, "stb:0x%02x received %d\n", (unsigned int)stb, rv); + dev_dbg(dev, "stb:0x%02x received %d\n", (unsigned int)*stb, rv); exit: /* bump interrupt bTag */ @@ -567,6 +550,27 @@ static int usbtmc488_ioctl_read_stb(struct usbtmc_file_data *file_data, return rv; } +static int usbtmc488_ioctl_read_stb(struct usbtmc_file_data *file_data, + void __user *arg) +{ + int srq_asserted = 0; + __u8 stb; + int rv; + + rv = usbtmc_get_stb(file_data, &stb); + + if (rv > 0) { + srq_asserted = atomic_xchg(&file_data->srq_asserted, + srq_asserted); + if (srq_asserted) + stb |= 0x40; /* Set RQS bit */ + + rv = put_user(stb, (__u8 __user *)arg); + } + return rv; + +} + static int usbtmc488_ioctl_wait_srq(struct usbtmc_file_data *file_data, __u32 __user *arg) { From patchwork Tue Dec 15 15:56:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: dave penkler X-Patchwork-Id: 344788 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A09B5C4361B for ; Tue, 15 Dec 2020 16:02:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 76097224F4 for ; Tue, 15 Dec 2020 16:02:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730478AbgLOQBo (ORCPT ); Tue, 15 Dec 2020 11:01:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730709AbgLOP6D (ORCPT ); Tue, 15 Dec 2020 10:58:03 -0500 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A5ADC0617B0 for ; Tue, 15 Dec 2020 07:57:22 -0800 (PST) Received: by mail-wr1-x442.google.com with SMTP id t16so20364183wra.3 for ; Tue, 15 Dec 2020 07:57:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wQ1Nj9fFgzAFnX7YMGZ99IfqwZhx1clfgvERaYbHZJI=; b=OA+2GyVSPZE0QBChP1z2Pinzj9r/61dxBzRzglL+/lvmoVKSWYFWSm2R2cv0rUedm4 teyC7vcpyb+9yuJDFylOFkhM33QCHDks/9xnlkF8+x6AyKf6kdiLyCvNIEQ5+Pr654/R 4GxvUIKluBb9zpTXr02K7oj77duJeVr55oeaWf3hrJvACwpC42aC5lKkoTSP0rqLSOdD cLvHjsfiFmmfb+bxfXEcJSylEomf8gAwTRv9/iaYo8dzAcHgYcr0rv6awK/c6umjyt+X 9CmgetjUjfq34FBPjWAO+kyLsTOltkG+GngmMGUL2juEfd2DHk6XibwB5/dIgt5A3Zre fqFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wQ1Nj9fFgzAFnX7YMGZ99IfqwZhx1clfgvERaYbHZJI=; b=kWtPqXRxGlS51Bac8wQKT8ncv+5zB/XyGn0zGWAI70dz2Kf5GG95sY0DRWnqLcIWO+ YZyd/Sh8JMtO3mFf2IgRLNlEtpg7JZD8Nz/w38kBazzcdp2xuY88eAjj7gqxe3gnng84 z0XtmXmjHigPkD/QsqR8UeaSemaWlrhn3hUBEv96o6KLVg5BvlsQIGJj6WLAiA6cKtOI 1/ZTMvxGQPopaVRdD6TwatY+hnnGsqDCbU5S4FO897Td/lR8tcD0h7uDyTcEcbUENi3Z IhEQVRzh3SokYnkuU1z1E18MzzAxN38uuBEihiPmLkepFKgyhpnJ6qw3vfi/O0iXyRsZ F+IA== X-Gm-Message-State: AOAM533/PREAyfODJrQEuoR3L30x8yinp9giqbBhZBTOy46FY+Hu/vAw 7PtH9LZgIP82mJSJvB5Rkg4= X-Google-Smtp-Source: ABdhPJy2COTvX1vhWgQ5ELN/HHRtMKJtWtKBSjGx3LDqcfn15X2yc4CpptzgE02CdBIP/7wE7xTbSg== X-Received: by 2002:a5d:4a06:: with SMTP id m6mr35858526wrq.189.1608047841180; Tue, 15 Dec 2020 07:57:21 -0800 (PST) Received: from egonzo.toto.net.toto.net ([88.123.121.14]) by smtp.gmail.com with ESMTPSA id c10sm38792018wrb.92.2020.12.15.07.57.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Dec 2020 07:57:20 -0800 (PST) From: Dave Penkler To: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org Cc: guido.kiener@rohde-schwarz.com, john.harvey@non.keysight.com, jian-wei_wu@keysight.com, gabe.jones@ni.com, dpenkler@gmail.com Subject: [PATCH 2/4] USB: usbtmc: Add USBTMC_IOCTL_GET_STB Date: Tue, 15 Dec 2020 16:56:19 +0100 Message-Id: <20201215155621.9592-3-dpenkler@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201215155621.9592-1-dpenkler@gmail.com> References: <20201215155621.9592-1-dpenkler@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org This new ioctl reads the status byte (STB) from the device and returns the STB unmodified to the application. The srq_asserted bit is not taken into account and not changed. This ioctl is useful to support non USBTMC-488 compliant devices. Signed-off-by: Dave Penkler Reviewed-by: Guido Kiener Tested-by: Jian-Wei Wu --- drivers/usb/class/usbtmc.c | 6 ++++++ include/uapi/linux/usb/tmc.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c index 189f06dcb7d3..8918e2182eca 100644 --- a/drivers/usb/class/usbtmc.c +++ b/drivers/usb/class/usbtmc.c @@ -2149,6 +2149,12 @@ static long usbtmc_ioctl(struct file *file, unsigned int cmd, unsigned long arg) file_data->auto_abort = !!tmp_byte; break; + case USBTMC_IOCTL_GET_STB: + retval = usbtmc_get_stb(file_data, &tmp_byte); + if (retval > 0) + retval = put_user(tmp_byte, (__u8 __user *)arg); + break; + case USBTMC_IOCTL_CANCEL_IO: retval = usbtmc_ioctl_cancel_io(file_data); break; diff --git a/include/uapi/linux/usb/tmc.h b/include/uapi/linux/usb/tmc.h index fdd4d88a7b95..1e7878fe591f 100644 --- a/include/uapi/linux/usb/tmc.h +++ b/include/uapi/linux/usb/tmc.h @@ -102,6 +102,8 @@ struct usbtmc_message { #define USBTMC_IOCTL_MSG_IN_ATTR _IOR(USBTMC_IOC_NR, 24, __u8) #define USBTMC_IOCTL_AUTO_ABORT _IOW(USBTMC_IOC_NR, 25, __u8) +#define USBTMC_IOCTL_GET_STB _IOR(USBTMC_IOC_NR, 26, __u8) + /* Cancel and cleanup asynchronous calls */ #define USBTMC_IOCTL_CANCEL_IO _IO(USBTMC_IOC_NR, 35) #define USBTMC_IOCTL_CLEANUP_IO _IO(USBTMC_IOC_NR, 36) From patchwork Tue Dec 15 15:56:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: dave penkler X-Patchwork-Id: 344281 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE24FC2BB9A for ; Tue, 15 Dec 2020 16:02:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8B5B52255F for ; Tue, 15 Dec 2020 16:02:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730510AbgLOQBp (ORCPT ); Tue, 15 Dec 2020 11:01:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730711AbgLOP6E (ORCPT ); Tue, 15 Dec 2020 10:58:04 -0500 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F623C06138C for ; Tue, 15 Dec 2020 07:57:24 -0800 (PST) Received: by mail-wr1-x442.google.com with SMTP id d13so2112591wrc.13 for ; Tue, 15 Dec 2020 07:57:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=V39UoMYaoTkTDqn5dsE6514lVOSQVxJuzNZrRAktrsU=; b=olomyCo78CGfCdjlS0zLov3C5hitUgEWI6h5uYOGGyTitPtABiQFQyVvCfpcnow2x4 5+nM+l+VJ7STDMCTWtDaTXgESL9EZJ/HPVtwL28uydNIT2hQ8j4n0oJLseNAlT5pxuj6 rhkaJA1FTO7u0nNSy5xZ7zNNcIryY96/giGlOPyACM9u1ugHHH9D/0QadlOPe7cBxU/A TSHGvcAm94q3y6l1tXVj4p8MLFYAh2YehL1s0RFPjfhT3YskU1wnBFWoV4GZXgQNZu+I wZU25IQxtaXH00Sh7/AtOr/C1oeG3BdVxpjaunUBeeEDusNJMhX4hGJFckTcJ7inqAeB juIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=V39UoMYaoTkTDqn5dsE6514lVOSQVxJuzNZrRAktrsU=; b=umWtQWVj0XYCCsVM0wHjB3MoI3AnwW0fE+eRdURnBoIWGn4pIPrVM5H2NYNzQNRFP8 OXrfd/nhI4hdHxKpPUou68UH3vN81wukdKJ/RU+2fd1cLTp3c4jnN/5GAz6luaS1WEId Sq9cdz1XYzVQHKmIX5Ez2xTjW3uBTdBDqfE0K7dig4QJgAY7UeF3JOfkVeTrNm8YS582 HEj8224c8qSwMHyVzu8dBZ5IuYy74/BZYdsmDeLWwRHN8cPLwKz3AmI3rmxxygMdgJwJ KWPt92zlGQR4r06SiPjJAOMKXOChm57/JqnBB0YzC0j+HiM5E9gxINO8nVvrxazs7ip9 KNvg== X-Gm-Message-State: AOAM531DodqaoRE31CvAN5CvcXn7XBLAsm56xR4rBKabeWC9bj6ETh2/ kYkKEuSMeMqefvsVB6uexwc= X-Google-Smtp-Source: ABdhPJy96tltN65Haa2PTWAsWAIUDH6sod/DkQno968BY6LXGS6eioqSQWXWlyav/Zped6O5hh/v4g== X-Received: by 2002:a5d:464b:: with SMTP id j11mr34645678wrs.227.1608047842817; Tue, 15 Dec 2020 07:57:22 -0800 (PST) Received: from egonzo.toto.net.toto.net ([88.123.121.14]) by smtp.gmail.com with ESMTPSA id c10sm38792018wrb.92.2020.12.15.07.57.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Dec 2020 07:57:22 -0800 (PST) From: Dave Penkler To: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org Cc: guido.kiener@rohde-schwarz.com, john.harvey@non.keysight.com, jian-wei_wu@keysight.com, gabe.jones@ni.com, dpenkler@gmail.com Subject: [PATCH 3/4] USB: usbtmc: Add separate USBTMC_IOCTL_GET_SRQ_STB Date: Tue, 15 Dec 2020 16:56:20 +0100 Message-Id: <20201215155621.9592-4-dpenkler@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201215155621.9592-1-dpenkler@gmail.com> References: <20201215155621.9592-1-dpenkler@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org This new ioctl only returns the status byte (STB) that was originally sent by the device due to a service request (SRQ) condition. This ioctl checks the srq_asserted bit of the associated file descriptor. If set, the srq_asserted bit is reset and the cached STB with original SRQ information is returned. Otherwise the ioctl returns the error code ENOMSG. This ioctl is useful to support non USBTMC-488 compliant devices. Time sensitive applications can read the cached STB without incurring the cost of an urb transaction over the bus. Signed-off-by: Dave Penkler Reviewed-by: Guido Kiener Tested-by: Jian-Wei Wu --- drivers/usb/class/usbtmc.c | 31 +++++++++++++++++++++++++++++++ include/uapi/linux/usb/tmc.h | 1 + 2 files changed, 32 insertions(+) diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c index 8918e2182eca..d2fcc698c745 100644 --- a/drivers/usb/class/usbtmc.c +++ b/drivers/usb/class/usbtmc.c @@ -571,6 +571,32 @@ static int usbtmc488_ioctl_read_stb(struct usbtmc_file_data *file_data, } +static int usbtmc_ioctl_get_srq_stb(struct usbtmc_file_data *file_data, + void __user *arg) +{ + struct usbtmc_device_data *data = file_data->data; + struct device *dev = &data->intf->dev; + int srq_asserted = 0; + __u8 stb = 0; + int rv; + + spin_lock_irq(&data->dev_lock); + srq_asserted = atomic_xchg(&file_data->srq_asserted, srq_asserted); + + if (srq_asserted) { + stb = file_data->srq_byte; + spin_unlock_irq(&data->dev_lock); + rv = put_user(stb, (__u8 __user *)arg); + } else { + spin_unlock_irq(&data->dev_lock); + rv = -ENOMSG; + } + + dev_dbg(dev, "stb:0x%02x with srq received %d\n", (unsigned int)stb, rv); + + return rv; +} + static int usbtmc488_ioctl_wait_srq(struct usbtmc_file_data *file_data, __u32 __user *arg) { @@ -2155,6 +2181,11 @@ static long usbtmc_ioctl(struct file *file, unsigned int cmd, unsigned long arg) retval = put_user(tmp_byte, (__u8 __user *)arg); break; + case USBTMC_IOCTL_GET_SRQ_STB: + retval = usbtmc_ioctl_get_srq_stb(file_data, + (void __user *)arg); + break; + case USBTMC_IOCTL_CANCEL_IO: retval = usbtmc_ioctl_cancel_io(file_data); break; diff --git a/include/uapi/linux/usb/tmc.h b/include/uapi/linux/usb/tmc.h index 1e7878fe591f..d791cc58a7f0 100644 --- a/include/uapi/linux/usb/tmc.h +++ b/include/uapi/linux/usb/tmc.h @@ -103,6 +103,7 @@ struct usbtmc_message { #define USBTMC_IOCTL_AUTO_ABORT _IOW(USBTMC_IOC_NR, 25, __u8) #define USBTMC_IOCTL_GET_STB _IOR(USBTMC_IOC_NR, 26, __u8) +#define USBTMC_IOCTL_GET_SRQ_STB _IOR(USBTMC_IOC_NR, 27, __u8) /* Cancel and cleanup asynchronous calls */ #define USBTMC_IOCTL_CANCEL_IO _IO(USBTMC_IOC_NR, 35) From patchwork Tue Dec 15 15:56:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: dave penkler X-Patchwork-Id: 344789 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21838C4361B for ; Tue, 15 Dec 2020 16:00:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E082922509 for ; Tue, 15 Dec 2020 16:00:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730608AbgLOQAY (ORCPT ); Tue, 15 Dec 2020 11:00:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730725AbgLOP6G (ORCPT ); Tue, 15 Dec 2020 10:58:06 -0500 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1094C061282 for ; Tue, 15 Dec 2020 07:57:25 -0800 (PST) Received: by mail-wm1-x344.google.com with SMTP id q75so18984011wme.2 for ; Tue, 15 Dec 2020 07:57:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZqRDZ0GMIRzKaG7rgPryy9HQP9wi6cbXcT4X1fC/8/o=; b=GmmphjG18PQ3QlCbDoIOTXj5O68I+Ch7cR7dctbOqo2c0jyLwSdvCcbv8DjP8RIW5h fggzVon2HsFOx8dVqJJw0OLO5Zrku6VsRIKaEAwYF76+/VnXw6Zew9bu223D2BvLT+mx 781TLJaO5zt0Y0dYT4f7KWErfu+0vFDD0qAzoTLR20e9mdNQvvVwAW+wGP+6+WLev4bv vLTQZPC4c418URWdW47r2eJhzZNpU3e3ZG7RuGi58hU+oQAKk6RgxRGj+gtk/XqOvEgW wOxDFm65JxMwi/Mt8m4fpLC+3fsXWB8oQMiimkZbRUa2n2wOMs38SEYIzt0Tn8HcF0CB ki5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZqRDZ0GMIRzKaG7rgPryy9HQP9wi6cbXcT4X1fC/8/o=; b=p3ruGU+6WNYJbR6GSaKJalllveloWgfhaG8rtQluI+t2IIR8NOdFkEzZxVOszvwt4z FqWWrFuSay07IsQDJmK+/GCD3Jp4Be5jwru/cYpidLAt2kPWzhyRGVGiFKHRYNB2qxaN fFjiX4uowX8TO81l4JMxPMe+heDinoOYr/P7PVljldzef/y+Pa9oAIyU091IXsRs92R0 ux7O322BVFa2oVzVCaflS17bbMK6SWek03XDzoCrRY1WdWkmLygRcxZd1s+gt2RH2HtN aan+PHN88v8Re+BxMHgL8u5EhDCfWNQfBTJX5oQxGFlt/zHyIKrk2jxqqXil28sVwMtC duog== X-Gm-Message-State: AOAM532Yr4yjUhc5Rgn1xmWlnZmHYBLBtgqmVC3yEDzH0gQbsrNmBytb O1wPLBh2zNnciOltUJtfgIA= X-Google-Smtp-Source: ABdhPJyJCiKCokxOFWOwk2TSTF93/kcdz2/zFFuugg6zZrRtiTAbF/9N90wOmV8+kuhhLYYj2AZE5A== X-Received: by 2002:a7b:c406:: with SMTP id k6mr33450128wmi.90.1608047844628; Tue, 15 Dec 2020 07:57:24 -0800 (PST) Received: from egonzo.toto.net.toto.net ([88.123.121.14]) by smtp.gmail.com with ESMTPSA id c10sm38792018wrb.92.2020.12.15.07.57.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Dec 2020 07:57:24 -0800 (PST) From: Dave Penkler To: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org Cc: guido.kiener@rohde-schwarz.com, john.harvey@non.keysight.com, jian-wei_wu@keysight.com, gabe.jones@ni.com, dpenkler@gmail.com Subject: [PATCH 4/4] USB: usbtmc: Bump USBTMC_API_VERSION value Date: Tue, 15 Dec 2020 16:56:21 +0100 Message-Id: <20201215155621.9592-5-dpenkler@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201215155621.9592-1-dpenkler@gmail.com> References: <20201215155621.9592-1-dpenkler@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The previous patches in this series have changed the behaviour of the driver and added new calls. Signed-off-by: Dave Penkler Reviewed-by: Guido Kiener Tested-by: Jian-Wei Wu --- drivers/usb/class/usbtmc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c index d2fcc698c745..74d5a9c5238a 100644 --- a/drivers/usb/class/usbtmc.c +++ b/drivers/usb/class/usbtmc.c @@ -25,7 +25,7 @@ /* Increment API VERSION when changing tmc.h with new flags or ioctls * or when changing a significant behavior of the driver. */ -#define USBTMC_API_VERSION (2) +#define USBTMC_API_VERSION (3) #define USBTMC_HEADER_SIZE 12 #define USBTMC_MINOR_BASE 176