From patchwork Thu May 17 17:03:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guido Kiener X-Patchwork-Id: 10407099 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8EFC260353 for ; Thu, 17 May 2018 16:10:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D592285C9 for ; Thu, 17 May 2018 16:10:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 72393285CE; Thu, 17 May 2018 16:10:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 01C7E285C9 for ; Thu, 17 May 2018 16:10:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752595AbeEQQKv (ORCPT ); Thu, 17 May 2018 12:10:51 -0400 Received: from mr01.mx01.tldhost.de ([62.108.36.247]:35299 "EHLO mr01.mx01.tldhost.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752530AbeEQQKd (ORCPT ); Thu, 17 May 2018 12:10:33 -0400 Received: from mx01.tldhost.de (localhost [127.0.0.1]) by mx01.tldhost.de (Postfix) with ESMTP id 2A4A1120E0D for ; Thu, 17 May 2018 18:05:04 +0200 (CEST) Received: by mx01.tldhost.de (Postfix, from userid 1001) id 19776120E01; Thu, 17 May 2018 18:05:04 +0200 (CEST) Received: from server12.tldhost.de (server12.tldhost.de [84.19.26.112]) by mx01.tldhost.de (Postfix) with ESMTPS id A2CDD120D36; Thu, 17 May 2018 18:05:00 +0200 (CEST) From: Guido Kiener To: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, guido.kiener@rohde-schwarz.com, pankaj.adhikari@ni.com, steve_bayless@keysight.com, dpenkler@gmail.com Cc: Guido Kiener Subject: [PATCH 10/12] usb: usbtmc: Add test functions to set HALT Feature (Stall) Date: Thu, 17 May 2018 19:03:34 +0200 Message-Id: <20180517170336.8426-11-guido@kiener-muenchen.de> In-Reply-To: <20180517170336.8426-1-guido@kiener-muenchen.de> References: <20180517170336.8426-1-guido@kiener-muenchen.de> X-PPP-Message-ID: <20180517160501.4426.90334@server12.tldhost.de> X-PPP-Vhost: kiener-muenchen.de X-POWERED-BY: TLDHost.de - AV:CLEAN SPAM:OK Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The ioctls USBTMC_IOCTL_SET_OUT_HALT or USBTMC_IOCTL_SET_IN_HALT send a SET_FEATURE(HALT) request to the corresponding OUT or IN pipe. Useful for testing devices and client applications: The ioctls force the device to simulate the error state at the specified pipe. Signed-off-by: Guido Kiener Reviewed-by: Steve Bayless --- drivers/usb/class/usbtmc.c | 78 ++++++++++++++++++++++++++++++------ include/uapi/linux/usb/tmc.h | 4 ++ 2 files changed, 70 insertions(+), 12 deletions(-) diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c index 165b707991f3..8b464598bee5 100644 --- a/drivers/usb/class/usbtmc.c +++ b/drivers/usb/class/usbtmc.c @@ -1754,34 +1754,80 @@ static int usbtmc_ioctl_clear(struct usbtmc_device_data *data) return rv; } +/* + * set pipe in halt state (stalled) + * Needed for test purpose or workarounds. + */ +static int usbtmc_set_halt(struct usb_device *dev, int pipe) +{ + int rv; + int endp = usb_pipeendpoint(pipe); + + if (usb_pipein(pipe)) + endp |= USB_DIR_IN; + + rv = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), + USB_REQ_SET_FEATURE, USB_RECIP_ENDPOINT, + USB_ENDPOINT_HALT, endp, NULL, 0, + USB_CTRL_SET_TIMEOUT); + + return rv; +} + +static int usbtmc_ioctl_set_out_halt(struct usbtmc_device_data *data) +{ + int rv; + + dev_dbg(&data->intf->dev, "%s - called\n", __func__); + + rv = usbtmc_set_halt(data->usb_dev, + usb_sndbulkpipe(data->usb_dev, data->bulk_out)); + + if (rv < 0) + dev_err(&data->usb_dev->dev, "%s returned %d\n", __func__, rv); + return rv; +} + +static int usbtmc_ioctl_set_in_halt(struct usbtmc_device_data *data) +{ + int rv; + + dev_dbg(&data->intf->dev, "%s - called\n", __func__); + + rv = usbtmc_set_halt(data->usb_dev, + usb_rcvbulkpipe(data->usb_dev, data->bulk_in)); + + if (rv < 0) + dev_err(&data->usb_dev->dev, "%s returned %d\n", __func__, rv); + return rv; +} + static int usbtmc_ioctl_clear_out_halt(struct usbtmc_device_data *data) { int rv; + dev_dbg(&data->intf->dev, "%s - called\n", __func__); + rv = usb_clear_halt(data->usb_dev, usb_sndbulkpipe(data->usb_dev, data->bulk_out)); - if (rv < 0) { - dev_err(&data->usb_dev->dev, "usb_control_msg returned %d\n", - rv); - return rv; - } - return 0; + if (rv < 0) + dev_err(&data->usb_dev->dev, "%s returned %d\n", __func__, rv); + return rv; } static int usbtmc_ioctl_clear_in_halt(struct usbtmc_device_data *data) { int rv; + dev_dbg(&data->intf->dev, "%s - called\n", __func__); + rv = usb_clear_halt(data->usb_dev, usb_rcvbulkpipe(data->usb_dev, data->bulk_in)); - if (rv < 0) { - dev_err(&data->usb_dev->dev, "usb_control_msg returned %d\n", - rv); - return rv; - } - return 0; + if (rv < 0) + dev_err(&data->usb_dev->dev, "%s returned %d\n", __func__, rv); + return rv; } static int usbtmc_ioctl_cancel_io(struct usbtmc_file_data *file_data) @@ -2241,6 +2287,14 @@ static long usbtmc_ioctl(struct file *file, unsigned int cmd, unsigned long arg) file_data->auto_abort = !!tmp_byte; break; + case USBTMC_IOCTL_SET_OUT_HALT: + retval = usbtmc_ioctl_set_out_halt(data); + break; + + case USBTMC_IOCTL_SET_IN_HALT: + retval = usbtmc_ioctl_set_in_halt(data); + 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 e3bdfc1935ed..886fabf5dfea 100644 --- a/include/uapi/linux/usb/tmc.h +++ b/include/uapi/linux/usb/tmc.h @@ -101,6 +101,10 @@ 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) +/* For test purpose only */ +#define USBTMC_IOCTL_SET_OUT_HALT _IO(USBTMC_IOC_NR, 30) +#define USBTMC_IOCTL_SET_IN_HALT _IO(USBTMC_IOC_NR, 31) + /* 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)