Add ioctl USBTMC_IOCTL_AUTO_ABORT to configure auto_abort for
each specific file handle.

Signed-off-by: Guido Kiener <guido.kie...@rohde-schwarz.com>
Reviewed-by: Steve Bayless <steve_bayl...@keysight.com>
---
 drivers/usb/class/usbtmc.c   | 23 ++++++++++++++++-------
 include/uapi/linux/usb/tmc.h |  1 +
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c
index 1e6cecf9e981..9ec03b74035b 100644
--- a/drivers/usb/class/usbtmc.c
+++ b/drivers/usb/class/usbtmc.c
@@ -136,6 +136,7 @@ struct usbtmc_file_data {
        u8             eom_val;
        u8             term_char;
        bool           term_char_enabled;
+       bool           auto_abort;
 
        spinlock_t     err_lock; /* lock for errors */
 
@@ -221,6 +222,7 @@ static int usbtmc_open(struct inode *inode, struct file 
*filp)
        file_data->timeout = USBTMC_TIMEOUT;
        file_data->term_char = data->TermChar;
        file_data->term_char_enabled = data->TermCharEnabled;
+       file_data->auto_abort = data->auto_abort;
        file_data->eom_val = 1;
 
        INIT_LIST_HEAD(&file_data->file_elem);
@@ -1444,7 +1446,7 @@ static ssize_t usbtmc_read(struct file *filp, char __user 
*buf,
        retval = send_request_dev_dep_msg_in(file_data, count);
 
        if (retval < 0) {
-               if (data->auto_abort)
+               if (file_data->auto_abort)
                        usbtmc_ioctl_abort_bulk_out(data);
                goto exit;
        }
@@ -1469,7 +1471,7 @@ static ssize_t usbtmc_read(struct file *filp, char __user 
*buf,
 
                if (retval < 0) {
                        dev_dbg(dev, "Unable to read data, error %d\n", retval);
-                       if (data->auto_abort)
+                       if (file_data->auto_abort)
                                usbtmc_ioctl_abort_bulk_in(data);
                        goto exit;
                }
@@ -1479,21 +1481,21 @@ static ssize_t usbtmc_read(struct file *filp, char 
__user *buf,
                        /* Sanity checks for the header */
                        if (actual < USBTMC_HEADER_SIZE) {
                                dev_err(dev, "Device sent too small first 
packet: %u < %u\n", actual, USBTMC_HEADER_SIZE);
-                               if (data->auto_abort)
+                               if (file_data->auto_abort)
                                        usbtmc_ioctl_abort_bulk_in(data);
                                goto exit;
                        }
 
                        if (buffer[0] != 2) {
                                dev_err(dev, "Device sent reply with wrong 
MsgID: %u != 2\n", buffer[0]);
-                               if (data->auto_abort)
+                               if (file_data->auto_abort)
                                        usbtmc_ioctl_abort_bulk_in(data);
                                goto exit;
                        }
 
                        if (buffer[1] != data->bTag_last_write) {
                                dev_err(dev, "Device sent reply with wrong 
bTag: %u != %u\n", buffer[1], data->bTag_last_write);
-                               if (data->auto_abort)
+                               if (file_data->auto_abort)
                                        usbtmc_ioctl_abort_bulk_in(data);
                                goto exit;
                        }
@@ -1508,7 +1510,7 @@ static ssize_t usbtmc_read(struct file *filp, char __user 
*buf,
 
                        if (n_characters > this_part) {
                                dev_err(dev, "Device wants to return more data 
than requested: %u > %zu\n", n_characters, count);
-                               if (data->auto_abort)
+                               if (file_data->auto_abort)
                                        usbtmc_ioctl_abort_bulk_in(data);
                                goto exit;
                        }
@@ -1650,7 +1652,7 @@ static ssize_t usbtmc_write(struct file *filp, const char 
__user *buf,
                if (retval < 0) {
                        dev_err(&data->intf->dev,
                                "Unable to send data, error %d\n", retval);
-                       if (data->auto_abort)
+                       if (file_data->auto_abort)
                                usbtmc_ioctl_abort_bulk_out(data);
                        goto exit;
                }
@@ -2219,6 +2221,7 @@ static long usbtmc_ioctl(struct file *file, unsigned int 
cmd, unsigned long arg)
        struct usbtmc_file_data *file_data;
        struct usbtmc_device_data *data;
        int retval = -EBADRQC;
+       __u8 tmp_byte;
 
        file_data = file->private_data;
        data = file_data->data;
@@ -2355,6 +2358,12 @@ static long usbtmc_ioctl(struct file *file, unsigned int 
cmd, unsigned long arg)
                                  (__u8 __user *)arg);
                break;
 
+       case USBTMC_IOCTL_AUTO_ABORT:
+               retval = get_user(tmp_byte, (unsigned char __user *)arg);
+               if (retval == 0)
+                       file_data->auto_abort = !!tmp_byte;
+               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 35c115e68775..da0619647fe7 100644
--- a/include/uapi/linux/usb/tmc.h
+++ b/include/uapi/linux/usb/tmc.h
@@ -99,6 +99,7 @@ struct usbtmc_message {
 #define USBTMC488_IOCTL_WAIT_SRQ       _IOW(USBTMC_IOC_NR, 23, __u32)
 
 #define USBTMC_IOCTL_MSG_IN_ATTR       _IOR(USBTMC_IOC_NR, 24, __u8)
+#define USBTMC_IOCTL_AUTO_ABORT                _IOW(USBTMC_IOC_NR, 25, __u8)
 
 /* Cancel and cleanup asynchronous calls */
 #define USBTMC_IOCTL_CANCEL_IO         _IO(USBTMC_IOC_NR, 35)
-- 
2.17.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to