Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1664083 > unrolled thread

[PATCH 6/8] usb: gadget: f_acm: add an ioctl to get the current line coding

Started byTal Shorer <tal.shorer@gmail.com>
First post2017-06-12 19:30 +0200
Last post2017-06-14 03:20 +0200
Articles 4 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 6/8] usb: gadget: f_acm: add an ioctl to get the current line coding Tal Shorer <tal.shorer@gmail.com> - 2017-06-12 19:30 +0200
    Re: [PATCH 6/8] usb: gadget: f_acm: add an ioctl to get the current line coding Tal Shorer <tal.shorer@gmail.com> - 2017-06-12 20:10 +0200
      Re: [PATCH 6/8] usb: gadget: f_acm: add an ioctl to get the current line coding Tal Shorer <tal.shorer@gmail.com> - 2017-06-12 20:20 +0200
    Re: [PATCH 6/8] usb: gadget: f_acm: add an ioctl to get the current  line coding Alan Cox <gnomes@lxorguk.ukuu.org.uk> - 2017-06-14 03:20 +0200

#1664083 — [PATCH 6/8] usb: gadget: f_acm: add an ioctl to get the current line coding

FromTal Shorer <tal.shorer@gmail.com>
Date2017-06-12 19:30 +0200
Subject[PATCH 6/8] usb: gadget: f_acm: add an ioctl to get the current line coding
Message-ID<tRBk6-52r-27@gated-at.bofh.it>
The user can issue USB_F_GET_LINE_CODING to get the current line coding
as set by the host (or the default if unset yet).

Signed-off-by: Tal Shorer <tal.shorer@gmail.com>
---
 Documentation/ioctl/ioctl-number.txt |  1 +
 drivers/usb/gadget/function/f_acm.c  | 27 +++++++++++++++++++++++----
 include/uapi/linux/usb/f_acm.h       | 12 ++++++++++++
 3 files changed, 36 insertions(+), 4 deletions(-)
 create mode 100644 include/uapi/linux/usb/f_acm.h

diff --git a/Documentation/ioctl/ioctl-number.txt b/Documentation/ioctl/ioctl-number.txt
index 1e9fcb4..3d70680 100644
--- a/Documentation/ioctl/ioctl-number.txt
+++ b/Documentation/ioctl/ioctl-number.txt
@@ -329,6 +329,7 @@ Code  Seq#(hex)	Include File		Comments
 0xCA	80-8F	uapi/scsi/cxlflash_ioctl.h
 0xCB	00-1F	CBM serial IEC bus	in development:
 					<mailto:michael.klein@puffin.lb.shuttle.de>
+0xCD	10-1F	linux/usb/f_acm.h
 0xCD	01	linux/reiserfs_fs.h
 0xCF	02	fs/cifs/ioctl.c
 0xDB	00-0F	drivers/char/mwave/mwavepub.h
diff --git a/drivers/usb/gadget/function/f_acm.c b/drivers/usb/gadget/function/f_acm.c
index b7a1466..5feea7c 100644
--- a/drivers/usb/gadget/function/f_acm.c
+++ b/drivers/usb/gadget/function/f_acm.c
@@ -19,6 +19,7 @@
 #include <linux/module.h>
 #include <linux/device.h>
 #include <linux/err.h>
+#include <uapi/linux/usb/f_acm.h>
 
 #include "u_serial.h"
 
@@ -611,6 +612,23 @@ static int acm_send_break(struct gserial *port, int duration)
 	return acm_notify_serial_state(acm);
 }
 
+static int acm_ioctl(struct gserial *port, unsigned int cmd, unsigned long arg)
+{
+	struct f_acm	*acm = port_to_acm(port);
+	int 		ret = -ENOIOCTLCMD;
+
+	switch (cmd) {
+	case USB_F_ACM_GET_LINE_CODING:
+		if (copy_to_user((__user void *)arg, &acm->port_line_coding,
+				sizeof(acm->port_line_coding)))
+			ret = -EFAULT;
+		else
+			ret = 0;
+		break;
+	}
+	return ret;
+}
+
 /*-------------------------------------------------------------------------*/
 
 /* ACM function driver setup/binding */
@@ -749,6 +767,7 @@ static struct usb_function *acm_alloc_func(struct usb_function_instance *fi)
 	acm->port.connect = acm_connect;
 	acm->port.disconnect = acm_disconnect;
 	acm->port.send_break = acm_send_break;
+	acm->port.ioctl = acm_ioctl;
 
 	acm->port.func.name = "acm";
 	acm->port.func.strings = acm_strings;
@@ -764,10 +783,10 @@ static struct usb_function *acm_alloc_func(struct usb_function_instance *fi)
 	acm->port.func.free_func = acm_free_func;
 
 	/* initialize port_line_coding with something that makes sense */
-	coding.dwDTERate = cpu_to_le32(9600);
-	coding.bCharFormat = USB_CDC_1_STOP_BITS;
-	coding.bParityType = USB_CDC_NO_PARITY;
-	coding.bDataBits = 8;
+	acm->port_line_coding.dwDTERate = cpu_to_le32(9600);
+	acm->port_line_coding.bCharFormat = USB_CDC_1_STOP_BITS;
+	acm->port_line_coding.bParityType = USB_CDC_NO_PARITY;
+	acm->port_line_coding.bDataBits = 8;
 
 	return &acm->port.func;
 }
diff --git a/include/uapi/linux/usb/f_acm.h b/include/uapi/linux/usb/f_acm.h
new file mode 100644
index 0000000..51f96f0
--- /dev/null
+++ b/include/uapi/linux/usb/f_acm.h
@@ -0,0 +1,12 @@
+/* f_acm.h -- Header file for USB CDC-ACM gadget function */
+
+#ifndef __UAPI_LINUX_USB_F_ACM_H
+#define __UAPI_LINUX_USB_F_ACM_H
+
+#include <linux/usb/cdc.h>
+#include <linux/ioctl.h>
+
+/* The 0xCD code is also used by reiserfs. we use 0x10-0x1F range */
+#define USB_F_ACM_GET_LINE_CODING _IOR(0xCD, 0x10, struct usb_cdc_line_coding)
+
+#endif /* __UAPI_LINUX_USB_F_ACM_H */
-- 
2.7.4

[toc] | [next] | [standalone]


#1664144

FromTal Shorer <tal.shorer@gmail.com>
Date2017-06-12 20:10 +0200
Message-ID<tRBWO-5Ex-19@gated-at.bofh.it>
In reply to#1664083
On Mon, Jun 12, 2017 at 8:26 PM, Tal Shorer <tal.shorer@gmail.com> wrote:
> The user can issue USB_F_GET_LINE_CODING to get the current line coding
> as set by the host (or the default if unset yet).
>
> Signed-off-by: Tal Shorer <tal.shorer@gmail.com>
> ---

> @@ -764,10 +783,10 @@ static struct usb_function *acm_alloc_func(struct usb_function_instance *fi)
>         acm->port.func.free_func = acm_free_func;
>
>         /* initialize port_line_coding with something that makes sense */
> -       coding.dwDTERate = cpu_to_le32(9600);
> -       coding.bCharFormat = USB_CDC_1_STOP_BITS;
> -       coding.bParityType = USB_CDC_NO_PARITY;
> -       coding.bDataBits = 8;
> +       acm->port_line_coding.dwDTERate = cpu_to_le32(9600);
> +       acm->port_line_coding.bCharFormat = USB_CDC_1_STOP_BITS;
> +       acm->port_line_coding.bParityType = USB_CDC_NO_PARITY;
> +       acm->port_line_coding.bDataBits = 8;
>
>         return &acm->port.func;
>  }
This hunk was messed up somehow and will not apply. I can resend a v2 if necessary, but the correct patch is as follows:

From: Tal Shorer <tal.shorer@gmail.com>
Subject: [PATCH 6/8] usb: gadget: f_acm: add an ioctl to get the current line
 coding

The user can issue USB_F_GET_LINE_CODING to get the current line coding
as set by the host (or the default if unset yet).

Signed-off-by: Tal Shorer <tal.shorer@gmail.com>
---
 Documentation/ioctl/ioctl-number.txt |  1 +
 drivers/usb/gadget/function/f_acm.c  | 27 +++++++++++++++++++++++----
 include/uapi/linux/usb/f_acm.h       | 12 ++++++++++++
 3 files changed, 36 insertions(+), 4 deletions(-)
 create mode 100644 include/uapi/linux/usb/f_acm.h

diff --git a/Documentation/ioctl/ioctl-number.txt b/Documentation/ioctl/ioctl-number.txt
index 1e9fcb4..3d70680 100644
--- a/Documentation/ioctl/ioctl-number.txt
+++ b/Documentation/ioctl/ioctl-number.txt
@@ -329,6 +329,7 @@ Code  Seq#(hex)	Include File		Comments
 0xCA	80-8F	uapi/scsi/cxlflash_ioctl.h
 0xCB	00-1F	CBM serial IEC bus	in development:
 					<mailto:michael.klein@puffin.lb.shuttle.de>
+0xCD	10-1F	linux/usb/f_acm.h
 0xCD	01	linux/reiserfs_fs.h
 0xCF	02	fs/cifs/ioctl.c
 0xDB	00-0F	drivers/char/mwave/mwavepub.h
diff --git a/drivers/usb/gadget/function/f_acm.c b/drivers/usb/gadget/function/f_acm.c
index b7a1466..5feea7c 100644
--- a/drivers/usb/gadget/function/f_acm.c
+++ b/drivers/usb/gadget/function/f_acm.c
@@ -19,6 +19,7 @@
 #include <linux/module.h>
 #include <linux/device.h>
 #include <linux/err.h>
+#include <uapi/linux/usb/f_acm.h>

 #include "u_serial.h"

@@ -611,6 +612,23 @@ static int acm_send_break(struct gserial *port, int duration)
 	return acm_notify_serial_state(acm);
 }

+static int acm_ioctl(struct gserial *port, unsigned int cmd, unsigned long arg)
+{
+	struct f_acm	*acm = port_to_acm(port);
+	int 		ret = -ENOIOCTLCMD;
+
+	switch (cmd) {
+	case USB_F_ACM_GET_LINE_CODING:
+		if (copy_to_user((__user void *)arg, &acm->port_line_coding,
+				sizeof(acm->port_line_coding)))
+			ret = -EFAULT;
+		else
+			ret = 0;
+		break;
+	}
+	return ret;
+}
+
 /*-------------------------------------------------------------------------*/

 /* ACM function driver setup/binding */
@@ -749,6 +767,7 @@ static struct usb_function *acm_alloc_func(struct usb_function_instance *fi)
 	acm->port.connect = acm_connect;
 	acm->port.disconnect = acm_disconnect;
 	acm->port.send_break = acm_send_break;
+	acm->port.ioctl = acm_ioctl;

 	acm->port.func.name = "acm";
 	acm->port.func.strings = acm_strings;
@@ -763,6 +763,12 @@ static struct usb_function *acm_alloc_func(struct usb_function_instance *fi)
 	acm->port.func.unbind = acm_unbind;
 	acm->port.func.free_func = acm_free_func;

+	/* initialize port_line_coding with something that makes sense */
+	coding.dwDTERate = cpu_to_le32(9600);
+	coding.bCharFormat = USB_CDC_1_STOP_BITS;
+	coding.bParityType = USB_CDC_NO_PARITY;
+	coding.bDataBits = 8;
+
 	return &acm->port.func;
 }

diff --git a/include/uapi/linux/usb/f_acm.h b/include/uapi/linux/usb/f_acm.h
new file mode 100644
index 0000000..51f96f0
--- /dev/null
+++ b/include/uapi/linux/usb/f_acm.h
@@ -0,0 +1,12 @@
+/* f_acm.h -- Header file for USB CDC-ACM gadget function */
+
+#ifndef __UAPI_LINUX_USB_F_ACM_H
+#define __UAPI_LINUX_USB_F_ACM_H
+
+#include <linux/usb/cdc.h>
+#include <linux/ioctl.h>
+
+/* The 0xCD code is also used by reiserfs. we use 0x10-0x1F range */
+#define USB_F_ACM_GET_LINE_CODING _IOR(0xCD, 0x10, struct usb_cdc_line_coding)
+
+#endif /* __UAPI_LINUX_USB_F_ACM_H */
--
2.7.4

[toc] | [prev] | [next] | [standalone]


#1664148

FromTal Shorer <tal.shorer@gmail.com>
Date2017-06-12 20:20 +0200
Message-ID<tRC6u-5IS-11@gated-at.bofh.it>
In reply to#1664144

On Mon, Jun 12, 2017 at 9:02 PM, Tal Shorer <tal.shorer@gmail.com> wrote:
> On Mon, Jun 12, 2017 at 8:26 PM, Tal Shorer <tal.shorer@gmail.com> wrote:
>> The user can issue USB_F_GET_LINE_CODING to get the current line coding
>> as set by the host (or the default if unset yet).
>>
>> Signed-off-by: Tal Shorer <tal.shorer@gmail.com>
>> ---
>
>> @@ -764,10 +783,10 @@ static struct usb_function *acm_alloc_func(struct usb_function_instance *fi)
>>         acm->port.func.free_func = acm_free_func;
>>
>>         /* initialize port_line_coding with something that makes sense */
>> -       coding.dwDTERate = cpu_to_le32(9600);
>> -       coding.bCharFormat = USB_CDC_1_STOP_BITS;
>> -       coding.bParityType = USB_CDC_NO_PARITY;
>> -       coding.bDataBits = 8;
>> +       acm->port_line_coding.dwDTERate = cpu_to_le32(9600);
>> +       acm->port_line_coding.bCharFormat = USB_CDC_1_STOP_BITS;
>> +       acm->port_line_coding.bParityType = USB_CDC_NO_PARITY;
>> +       acm->port_line_coding.bDataBits = 8;
>>
>>         return &acm->port.func;
>>  }
> This hunk was messed up somehow and will not apply. I can resend a v2 if necessary, but the correct patch is as follows:
Actually, it shouldn't even be in this patch. I somehow meshed 5 and 6 together.
The correct PATCH 6/8 is as follows:

From d7d56ceb8020f10623a04b4634f93e4cc678454d Mon Sep 17 00:00:00 2001
From: Tal Shorer <tal.shorer@gmail.com>
Date: Mon, 12 Jun 2017 19:40:56 +0300
Subject: [PATCH 6/8] usb: gadget: f_acm: add an ioctl to get the current line
 coding

The user can issue USB_F_GET_LINE_CODING to get the current line coding
as set by the host (or the default if unset yet).

Signed-off-by: Tal Shorer <tal.shorer@gmail.com>
---
 Documentation/ioctl/ioctl-number.txt |  1 +
 drivers/usb/gadget/function/f_acm.c  | 27 +++++++++++++++++++++++----
 include/uapi/linux/usb/f_acm.h       | 12 ++++++++++++
 3 files changed, 36 insertions(+), 4 deletions(-)
 create mode 100644 include/uapi/linux/usb/f_acm.h

diff --git a/Documentation/ioctl/ioctl-number.txt b/Documentation/ioctl/ioctl-number.txt
index 1e9fcb4..3d70680 100644
--- a/Documentation/ioctl/ioctl-number.txt
+++ b/Documentation/ioctl/ioctl-number.txt
@@ -329,6 +329,7 @@ Code  Seq#(hex)	Include File		Comments
 0xCA	80-8F	uapi/scsi/cxlflash_ioctl.h
 0xCB	00-1F	CBM serial IEC bus	in development:
 					<mailto:michael.klein@puffin.lb.shuttle.de>
+0xCD	10-1F	linux/usb/f_acm.h
 0xCD	01	linux/reiserfs_fs.h
 0xCF	02	fs/cifs/ioctl.c
 0xDB	00-0F	drivers/char/mwave/mwavepub.h
diff --git a/drivers/usb/gadget/function/f_acm.c b/drivers/usb/gadget/function/f_acm.c
index b7a1466..5feea7c 100644
--- a/drivers/usb/gadget/function/f_acm.c
+++ b/drivers/usb/gadget/function/f_acm.c
@@ -19,6 +19,7 @@
 #include <linux/module.h>
 #include <linux/device.h>
 #include <linux/err.h>
+#include <uapi/linux/usb/f_acm.h>

 #include "u_serial.h"

@@ -611,6 +612,23 @@ static int acm_send_break(struct gserial *port, int duration)
 	return acm_notify_serial_state(acm);
 }

+static int acm_ioctl(struct gserial *port, unsigned int cmd, unsigned long arg)
+{
+	struct f_acm	*acm = port_to_acm(port);
+	int 		ret = -ENOIOCTLCMD;
+
+	switch (cmd) {
+	case USB_F_ACM_GET_LINE_CODING:
+		if (copy_to_user((__user void *)arg, &acm->port_line_coding,
+				sizeof(acm->port_line_coding)))
+			ret = -EFAULT;
+		else
+			ret = 0;
+		break;
+	}
+	return ret;
+}
+
 /*-------------------------------------------------------------------------*/

 /* ACM function driver setup/binding */
@@ -749,6 +767,7 @@ static struct usb_function *acm_alloc_func(struct usb_function_instance *fi)
 	acm->port.connect = acm_connect;
 	acm->port.disconnect = acm_disconnect;
 	acm->port.send_break = acm_send_break;
+	acm->port.ioctl = acm_ioctl;

 	acm->port.func.name = "acm";
 	acm->port.func.strings = acm_strings;
diff --git a/include/uapi/linux/usb/f_acm.h b/include/uapi/linux/usb/f_acm.h
new file mode 100644
index 0000000..51f96f0
--- /dev/null
+++ b/include/uapi/linux/usb/f_acm.h
@@ -0,0 +1,12 @@
+/* f_acm.h -- Header file for USB CDC-ACM gadget function */
+
+#ifndef __UAPI_LINUX_USB_F_ACM_H
+#define __UAPI_LINUX_USB_F_ACM_H
+
+#include <linux/usb/cdc.h>
+#include <linux/ioctl.h>
+
+/* The 0xCD code is also used by reiserfs. we use 0x10-0x1F range */
+#define USB_F_ACM_GET_LINE_CODING _IOR(0xCD, 0x10, struct usb_cdc_line_coding)
+
+#endif /* __UAPI_LINUX_USB_F_ACM_H */
--
2.7.4

[toc] | [prev] | [next] | [standalone]


#1665350 — Re: [PATCH 6/8] usb: gadget: f_acm: add an ioctl to get the current line coding

FromAlan Cox <gnomes@lxorguk.ukuu.org.uk>
Date2017-06-14 03:20 +0200
SubjectRe: [PATCH 6/8] usb: gadget: f_acm: add an ioctl to get the current line coding
Message-ID<tS58u-6WS-11@gated-at.bofh.it>
In reply to#1664083
On Mon, 12 Jun 2017 20:26:13 +0300
Tal Shorer <tal.shorer@gmail.com> wrote:

> The user can issue USB_F_GET_LINE_CODING to get the current line coding
> as set by the host (or the default if unset yet).

No this is not how to do it. We don't want weirdass ioctls for each
different tty device type.

There are two ways this can work. The first is actually done by plenty of
real physical hardware and that is to simply update the termios of the
logical channel to reflect the settings negotiated by the link layer
below (in your course USB ACM).

If that isn't sufficient then implement an ioctl that could work for *ALL*
tty devices - for example return a termios structure indicating the
relevant values on top of the current tty termios settings not some USB
ACM magic object.

Alan

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web