Re: [PATCH] usb: gadget: add USB3 support to the printer driver

2014-11-20 Thread Felipe Balbi
On Tue, Nov 18, 2014 at 03:11:54PM -0500, Jorge Ramirez-Ortiz wrote:
 Add SS descriptors to support the capabilities provided by USB3 controller
 drivers; unit tests run using a PLX 3380 [max transfer speed measured of 
 1Gbps]
 
 This driver shall fallback to lower operating modes when the higher ones are
 not available.
 
 Signed-off-by: Jorge Ramirez-Ortiz jorge.ramirez-or...@linaro.org
 ---
  drivers/usb/gadget/legacy/printer.c | 65 
 +
  1 file changed, 59 insertions(+), 6 deletions(-)
 
 diff --git a/drivers/usb/gadget/legacy/printer.c 
 b/drivers/usb/gadget/legacy/printer.c
 index 6474081..456730b 100644
 --- a/drivers/usb/gadget/legacy/printer.c
 +++ b/drivers/usb/gadget/legacy/printer.c
 @@ -208,6 +208,43 @@ static struct usb_descriptor_header 
 *hs_printer_function[] = {
   NULL
  };
  
 +/*
 + * Added endpoint descriptors for 3.0 devices
 + */
 +
 +static struct usb_endpoint_descriptor ss_ep_in_desc = {
 + .bLength =  USB_DT_ENDPOINT_SIZE,
 + .bDescriptorType =  USB_DT_ENDPOINT,
 + .bmAttributes = USB_ENDPOINT_XFER_BULK,
 + .wMaxPacketSize =   cpu_to_le16(1024),
 +};
 +
 +struct usb_ss_ep_comp_descriptor ss_ep_in_comp_desc = {
 + .bLength =  sizeof(ss_ep_in_comp_desc),
 + .bDescriptorType =  USB_DT_SS_ENDPOINT_COMP,
 +};
 +
 +static struct usb_endpoint_descriptor ss_ep_out_desc = {
 + .bLength =  USB_DT_ENDPOINT_SIZE,
 + .bDescriptorType =  USB_DT_ENDPOINT,
 + .bmAttributes = USB_ENDPOINT_XFER_BULK,
 + .wMaxPacketSize =   cpu_to_le16(1024),
 +};
 +
 +struct usb_ss_ep_comp_descriptor ss_ep_out_comp_desc = {
 + .bLength =  sizeof(ss_ep_out_comp_desc),
 + .bDescriptorType =  USB_DT_SS_ENDPOINT_COMP,
 +};
 +
 +static struct usb_descriptor_header *ss_printer_function[] = {
 + (struct usb_descriptor_header *) intf_desc,
 + (struct usb_descriptor_header *) ss_ep_in_desc,
 + (struct usb_descriptor_header *) ss_ep_in_comp_desc,
 + (struct usb_descriptor_header *) ss_ep_out_desc,
 + (struct usb_descriptor_header *) ss_ep_out_comp_desc,
 + NULL
 +};
 +
  static struct usb_otg_descriptor otg_descriptor = {
   .bLength =  sizeof otg_descriptor,
   .bDescriptorType =  USB_DT_OTG,
 @@ -220,7 +257,20 @@ static const struct usb_descriptor_header *otg_desc[] = {
  };
  
  /* maxpacket and other transfer characteristics vary by speed. */
 -#define ep_desc(g, hs, fs) (((g)-speed == USB_SPEED_HIGH)?(hs):(fs))
 +static inline struct usb_endpoint_descriptor *ep_desc(struct usb_gadget 
 *gadget,
 + struct usb_endpoint_descriptor *fs,
 + struct usb_endpoint_descriptor *hs,
 + struct usb_endpoint_descriptor *ss)
 +{
 + switch(gadget-speed) {
 ^^
 missing space here. I'll fix it, but next time run your
 patches through scripts/checkpatch.pl

-- 
balbi


signature.asc
Description: Digital signature


[PATCH] usb: gadget: add USB3 support to the printer driver

2014-11-18 Thread Jorge Ramirez-Ortiz
This patch adds USB3 support to the printer driver.
Tests used two binaries (host/device) to handle the file transfer

[gadget] $ dmesg

 net2280 :02:00.0: usb_reset_338x: Defect 7374 FsmValue 0xf000
 net2280 :02:00.0: usb_reinit_338x: Defect 7374 FsmValue f000
 net2280 :02:00.0: irq 35 for MSI/MSI-X
 net2280 :02:00.0: PLX NET228x/USB338x USB Peripheral Controller
 net2280 :02:00.0: irq 35, pci mem c90005574000, chip rev 00ab
 net2280 :02:00.0: version: 2005 Sept 27/v3.0; dma enabled legacy mode
 printer gadget: Printer Gadget, version: 2007 OCT 06
 printer gadget: printer ready
 net2280 :02:00.0: Operate Defect 7374 workaround soft this time
 net2280 :02:00.0: It will operate on cold-reboot and SS connect
 net2280 :02:00.0: ep0_start_338x: Defect 7374 FsmValue 1000
 net2280 :02:00.0: INFO: Defect 7374 workaround waited about 40uSec for 
Control Read Data Phase ACK
 printer gadget: super-speed config #1: printer
 printer gadget: Using interface 0

[gadget]$ sudo ./usbdevice 
[sudo] password for jramirez: 
Receive file: 
..done  
Transfer rate = 461 Mbits/sec [57MB/sec]
 - file size : 58 MB 
 - time  : 1.15 sec 
Dump file: /tmp/dump.txt 
..done 


[host]$ sudo ./usbhost file.txt
Opening device 0525:A4A8...

Device properties:
bus number: 4
 port path: 2 (from root hub)
 device speed: 5000 Mbit/s (USB SuperSpeed)

Reading device descriptor:
length: 18
  device class: 0
   S/N: 3
   VID:PID: 0525:A4A8
 bcdDevice: 0318
   iMan:iProd:iSer: 1:2:3
  nb confs: 1

Reading BOS descriptor: 2 caps
USB 2.0 extension:
  attributes : 06
USB 3.0 capabilities:
  attributes : 00
  supported speeds   : 000F
  supported functionality: 01

Reading first configuration descriptor:
 nb interfaces: 1
  interface[0]: id = 0
interface[0].altsetting[0]: num endpoints = 2
   Class.SubClass.Protocol: 07.01.02
   endpoint[0].address: 81
   max packet size: 0400
  polling interval: 00
 max burst: 00   (USB 3.0)
bytes per interval:  (USB 3.0)
   endpoint[1].address: 01
   max packet size: 0400
  polling interval: 00
 max burst: 00   (USB 3.0)
bytes per interval:  (USB 3.0)

Claiming interface 0...

Reading string descriptors:
   String (0x01): Linux 3.18.0-rc5+ with net2280
   String (0x02): Printer Gadget
Transfering: endpoint_out 1, size 61387314 
 - number of bulk transfers : 7494 
 - max user transfer size   : 8192 bytes 
 - max usb transfer size: 1024 bytes 

[host]$ lsusb
Bus 002 Device 006: ID 05ac:1303 Apple, Inc. iPod Shuffle 4.Gen
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 009: ID 0525:a4a8 Netchip Technology, Inc. Linux-USB Printer 
Gadget
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 005: ID 0403:6001 Future Technology Devices International, Ltd 
FT232 USB-Serial (UART) IC
Bus 001 Device 003: ID 046d:0990 Logitech, Inc. QuickCam Pro 9000
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
--
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


[PATCH] usb: gadget: add USB3 support to the printer driver

2014-11-18 Thread Jorge Ramirez-Ortiz
Add SS descriptors to support the capabilities provided by USB3 controller
drivers; unit tests run using a PLX 3380 [max transfer speed measured of 1Gbps]

This driver shall fallback to lower operating modes when the higher ones are
not available.

Signed-off-by: Jorge Ramirez-Ortiz jorge.ramirez-or...@linaro.org
---
 drivers/usb/gadget/legacy/printer.c | 65 +
 1 file changed, 59 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/gadget/legacy/printer.c 
b/drivers/usb/gadget/legacy/printer.c
index 6474081..456730b 100644
--- a/drivers/usb/gadget/legacy/printer.c
+++ b/drivers/usb/gadget/legacy/printer.c
@@ -208,6 +208,43 @@ static struct usb_descriptor_header *hs_printer_function[] 
= {
NULL
 };
 
+/*
+ * Added endpoint descriptors for 3.0 devices
+ */
+
+static struct usb_endpoint_descriptor ss_ep_in_desc = {
+   .bLength =  USB_DT_ENDPOINT_SIZE,
+   .bDescriptorType =  USB_DT_ENDPOINT,
+   .bmAttributes = USB_ENDPOINT_XFER_BULK,
+   .wMaxPacketSize =   cpu_to_le16(1024),
+};
+
+struct usb_ss_ep_comp_descriptor ss_ep_in_comp_desc = {
+   .bLength =  sizeof(ss_ep_in_comp_desc),
+   .bDescriptorType =  USB_DT_SS_ENDPOINT_COMP,
+};
+
+static struct usb_endpoint_descriptor ss_ep_out_desc = {
+   .bLength =  USB_DT_ENDPOINT_SIZE,
+   .bDescriptorType =  USB_DT_ENDPOINT,
+   .bmAttributes = USB_ENDPOINT_XFER_BULK,
+   .wMaxPacketSize =   cpu_to_le16(1024),
+};
+
+struct usb_ss_ep_comp_descriptor ss_ep_out_comp_desc = {
+   .bLength =  sizeof(ss_ep_out_comp_desc),
+   .bDescriptorType =  USB_DT_SS_ENDPOINT_COMP,
+};
+
+static struct usb_descriptor_header *ss_printer_function[] = {
+   (struct usb_descriptor_header *) intf_desc,
+   (struct usb_descriptor_header *) ss_ep_in_desc,
+   (struct usb_descriptor_header *) ss_ep_in_comp_desc,
+   (struct usb_descriptor_header *) ss_ep_out_desc,
+   (struct usb_descriptor_header *) ss_ep_out_comp_desc,
+   NULL
+};
+
 static struct usb_otg_descriptor otg_descriptor = {
.bLength =  sizeof otg_descriptor,
.bDescriptorType =  USB_DT_OTG,
@@ -220,7 +257,20 @@ static const struct usb_descriptor_header *otg_desc[] = {
 };
 
 /* maxpacket and other transfer characteristics vary by speed. */
-#define ep_desc(g, hs, fs) (((g)-speed == USB_SPEED_HIGH)?(hs):(fs))
+static inline struct usb_endpoint_descriptor *ep_desc(struct usb_gadget 
*gadget,
+   struct usb_endpoint_descriptor *fs,
+   struct usb_endpoint_descriptor *hs,
+   struct usb_endpoint_descriptor *ss)
+{
+   switch(gadget-speed) {
+   case USB_SPEED_SUPER:
+   return ss;
+   case USB_SPEED_HIGH:
+   return hs;
+   default:
+   return fs;
+   }
+}
 
 /*-*/
 
@@ -793,11 +843,12 @@ set_printer_interface(struct printer_dev *dev)
 {
int result = 0;
 
-   dev-in_ep-desc = ep_desc(dev-gadget, hs_ep_in_desc, fs_ep_in_desc);
+   dev-in_ep-desc = ep_desc(dev-gadget, fs_ep_in_desc, hs_ep_in_desc,
+   ss_ep_in_desc);
dev-in_ep-driver_data = dev;
 
-   dev-out_ep-desc = ep_desc(dev-gadget, hs_ep_out_desc,
-   fs_ep_out_desc);
+   dev-out_ep-desc = ep_desc(dev-gadget, fs_ep_out_desc,
+   hs_ep_out_desc, ss_ep_out_desc);
dev-out_ep-driver_data = dev;
 
result = usb_ep_enable(dev-in_ep);
@@ -1016,9 +1067,11 @@ autoconf_fail:
/* assumes that all endpoints are dual-speed */
hs_ep_in_desc.bEndpointAddress = fs_ep_in_desc.bEndpointAddress;
hs_ep_out_desc.bEndpointAddress = fs_ep_out_desc.bEndpointAddress;
+   ss_ep_in_desc.bEndpointAddress = fs_ep_in_desc.bEndpointAddress;
+   ss_ep_out_desc.bEndpointAddress = fs_ep_out_desc.bEndpointAddress;
 
ret = usb_assign_descriptors(f, fs_printer_function,
-   hs_printer_function, NULL);
+   hs_printer_function, ss_printer_function);
if (ret)
return ret;
 
@@ -1253,7 +1306,7 @@ static __refdata struct usb_composite_driver 
printer_driver = {
.name   = shortname,
.dev= device_desc,
.strings= dev_strings,
-   .max_speed  = USB_SPEED_HIGH,
+   .max_speed  = USB_SPEED_SUPER,
.bind   = printer_bind,
.unbind = printer_unbind,
 };
-- 
1.9.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