Re: [PATCH v2 1/1] xhci: add USB2 test mode support

2017-02-08 Thread Alexander Stein
On Wednesday 08 February 2017 16:17:45, Mathias Nyman wrote:
> On 08.02.2017 15:44, Alexander Stein wrote:
> > This patch adds support for USB2 test mode (Test_J, Test_K,
> > Test_SE0_NAK and Test_Packet) per XHCI spec 4.19.6.
> > 
> > USB2 test mode is a required hardware feature for system integrators
> > validating their hardware according to USB spec, regarding signal
> > strength and stuff. It is purely a hardware test feature.
> > 
> > Usually you need an oscilloscope and have to enable those test modes on
> > the hardware. This will send some specific test patterns on D+/D-. There
> > is no report available (in Linux itself) as it is purely externally
> > visible. Regular USB usage is not possible at that time.
> > Anyone (well access to e.g. /dev/bus/usb/001/001 provided) can use it by
> > sending appropriate USB_PORT_FEAT_TEST requests to the hub.
> > The same feature for ehci based hosts is already available at
> > https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drive
> > rs/usb/host/ehci-hub.c#n1267
> > 
> > Signed-off-by: "Wang, Yu" 
> > Signed-off-by: "Li, Guanglei" 
> > Signed-off-by: "Wu, Hao" 
> > Signed-off-by: Alexander Stein 
> > ---
> 
> I think there's a reworked series of this feature already posted at:
> 
> http://marc.info/?l=linux-usb=148050258916147=2
> 
> But this change log is now better
> I was thinking about adding that to 4.12

Interesting, I was not aware of that. This patchset seems better and cleaner 
than my patch. It even powers off all USB3 _and_ USB2 ports. In my patch only 
USB3 ports are powered off. Also TEST_FORCE_EN seems to be supported.
Feel free to take that series and use my commit message as appropriate.

Best regards,
Alexader
-- 
Dipl.-Inf. Alexander Stein
SYS TEC electronic GmbH
alexander.st...@systec-electronic.com

Legal and Commercial Address:
Am Windrad 2
08468 Heinsdorfergrund
Germany

Office: +49 (0) 3765 38600-0
Fax:+49 (0) 3765 38600-4100
 
Managing Directors:
Director Technology/CEO: Dipl.-Phys. Siegmar Schmidt;
Director Commercial Affairs/COO: Dipl. Ing. (FH) Armin von Collrepp
Commercial Registry:
Amtsgericht Chemnitz, HRB 28082; USt.-Id Nr. DE150534010



Re: [PATCH v2 1/1] xhci: add USB2 test mode support

2017-02-08 Thread Alexander Stein
On Wednesday 08 February 2017 16:17:45, Mathias Nyman wrote:
> On 08.02.2017 15:44, Alexander Stein wrote:
> > This patch adds support for USB2 test mode (Test_J, Test_K,
> > Test_SE0_NAK and Test_Packet) per XHCI spec 4.19.6.
> > 
> > USB2 test mode is a required hardware feature for system integrators
> > validating their hardware according to USB spec, regarding signal
> > strength and stuff. It is purely a hardware test feature.
> > 
> > Usually you need an oscilloscope and have to enable those test modes on
> > the hardware. This will send some specific test patterns on D+/D-. There
> > is no report available (in Linux itself) as it is purely externally
> > visible. Regular USB usage is not possible at that time.
> > Anyone (well access to e.g. /dev/bus/usb/001/001 provided) can use it by
> > sending appropriate USB_PORT_FEAT_TEST requests to the hub.
> > The same feature for ehci based hosts is already available at
> > https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drive
> > rs/usb/host/ehci-hub.c#n1267
> > 
> > Signed-off-by: "Wang, Yu" 
> > Signed-off-by: "Li, Guanglei" 
> > Signed-off-by: "Wu, Hao" 
> > Signed-off-by: Alexander Stein 
> > ---
> 
> I think there's a reworked series of this feature already posted at:
> 
> http://marc.info/?l=linux-usb=148050258916147=2
> 
> But this change log is now better
> I was thinking about adding that to 4.12

Interesting, I was not aware of that. This patchset seems better and cleaner 
than my patch. It even powers off all USB3 _and_ USB2 ports. In my patch only 
USB3 ports are powered off. Also TEST_FORCE_EN seems to be supported.
Feel free to take that series and use my commit message as appropriate.

Best regards,
Alexader
-- 
Dipl.-Inf. Alexander Stein
SYS TEC electronic GmbH
alexander.st...@systec-electronic.com

Legal and Commercial Address:
Am Windrad 2
08468 Heinsdorfergrund
Germany

Office: +49 (0) 3765 38600-0
Fax:+49 (0) 3765 38600-4100
 
Managing Directors:
Director Technology/CEO: Dipl.-Phys. Siegmar Schmidt;
Director Commercial Affairs/COO: Dipl. Ing. (FH) Armin von Collrepp
Commercial Registry:
Amtsgericht Chemnitz, HRB 28082; USt.-Id Nr. DE150534010



[PATCH v2 1/1] xhci: add USB2 test mode support

2017-02-08 Thread Alexander Stein
This patch adds support for USB2 test mode (Test_J, Test_K,
Test_SE0_NAK and Test_Packet) per XHCI spec 4.19.6.

USB2 test mode is a required hardware feature for system integrators
validating their hardware according to USB spec, regarding signal
strength and stuff. It is purely a hardware test feature.

Usually you need an oscilloscope and have to enable those test modes on
the hardware. This will send some specific test patterns on D+/D-. There
is no report available (in Linux itself) as it is purely externally
visible. Regular USB usage is not possible at that time.
Anyone (well access to e.g. /dev/bus/usb/001/001 provided) can use it by
sending appropriate USB_PORT_FEAT_TEST requests to the hub.
The same feature for ehci based hosts is already available at
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/usb/host/ehci-hub.c#n1267

Signed-off-by: "Wang, Yu" 
Signed-off-by: "Li, Guanglei" 
Signed-off-by: "Wu, Hao" 
Signed-off-by: Alexander Stein 
---
Changes in v2:
* Added additional info about USB2 test modes itself into commit message
* Add URL for same test mode feature on ehci hosts.

 drivers/usb/host/xhci-hub.c | 63 -
 1 file changed, 62 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 0ef1690..cd561f1 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -879,13 +879,14 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, 
u16 wValue,
int max_ports;
unsigned long flags;
u32 temp, status;
-   int retval = 0;
+   int i, retval = 0;
__le32 __iomem **port_array;
int slot_id;
struct xhci_bus_state *bus_state;
u16 link_state = 0;
u16 wake_mask = 0;
u16 timeout = 0;
+   u16 selector = 0;
 
max_ports = xhci_get_ports(hcd, _array);
bus_state = >bus_state[hcd_index(hcd)];
@@ -959,6 +960,8 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 
wValue,
link_state = (wIndex & 0xff00) >> 3;
if (wValue == USB_PORT_FEAT_REMOTE_WAKE_MASK)
wake_mask = wIndex & 0xff00;
+   if (wValue == USB_PORT_FEAT_TEST)
+   selector = (wIndex & 0xff00) >> 8;
/* The MSB of wIndex is the U1/U2 timeout */
timeout = (wIndex & 0xff00) >> 8;
wIndex &= 0xff;
@@ -1134,6 +1137,64 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, 
u16 wValue,
temp |= PORT_U2_TIMEOUT(timeout);
writel(temp, port_array[wIndex] + PORTPMSC);
break;
+   case USB_PORT_FEAT_TEST:
+   /* 4.19.6 Port Test Modes (USB2 Test Mode) */
+   if (hcd->speed != HCD_USB2)
+   goto error;
+
+   /* FIXME: Test_Force_Enable case to be implemented */
+   if (selector < TEST_J || selector > TEST_PACKET)
+   goto error;
+
+   /* Disable all Device Slots */
+   for (i = 0; i < MAX_HC_SLOTS; i++) {
+   struct xhci_command *command;
+
+   if (!xhci->dcbaa->dev_context_ptrs[i])
+   continue;
+   command = xhci_alloc_command(xhci, false,
+   false, GFP_ATOMIC);
+   if (!command)
+   return -ENOMEM;
+   if (xhci_queue_slot_control(xhci, command,
+   TRB_DISABLE_SLOT, i)) {
+   xhci_err(xhci,
+   "Disable slot[%d] fail!\n", i);
+   goto error;
+   }
+   xhci_dbg(xhci, "Disable Slot[%d].\n", i);
+   }
+
+   /* Put all ports to the Disable state by clear PP */
+   xhci_dbg(xhci, "Disable all port (PP = 0)\n");
+   for (i = 0; i < max_ports; i++) {
+   temp = readl(port_array[i]);
+   temp &= ~PORT_POWER;
+   writel(temp, port_array[i]);
+   }
+
+   /* Stop the controller */
+   xhci_dbg(xhci, "Stop controller\n");
+   temp = readl(>op_regs->command);
+   temp &= ~CMD_RUN;
+   writel(temp, >op_regs->command);
+
+   if 

[PATCH v2 1/1] xhci: add USB2 test mode support

2017-02-08 Thread Alexander Stein
This patch adds support for USB2 test mode (Test_J, Test_K,
Test_SE0_NAK and Test_Packet) per XHCI spec 4.19.6.

USB2 test mode is a required hardware feature for system integrators
validating their hardware according to USB spec, regarding signal
strength and stuff. It is purely a hardware test feature.

Usually you need an oscilloscope and have to enable those test modes on
the hardware. This will send some specific test patterns on D+/D-. There
is no report available (in Linux itself) as it is purely externally
visible. Regular USB usage is not possible at that time.
Anyone (well access to e.g. /dev/bus/usb/001/001 provided) can use it by
sending appropriate USB_PORT_FEAT_TEST requests to the hub.
The same feature for ehci based hosts is already available at
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/usb/host/ehci-hub.c#n1267

Signed-off-by: "Wang, Yu" 
Signed-off-by: "Li, Guanglei" 
Signed-off-by: "Wu, Hao" 
Signed-off-by: Alexander Stein 
---
Changes in v2:
* Added additional info about USB2 test modes itself into commit message
* Add URL for same test mode feature on ehci hosts.

 drivers/usb/host/xhci-hub.c | 63 -
 1 file changed, 62 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 0ef1690..cd561f1 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -879,13 +879,14 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, 
u16 wValue,
int max_ports;
unsigned long flags;
u32 temp, status;
-   int retval = 0;
+   int i, retval = 0;
__le32 __iomem **port_array;
int slot_id;
struct xhci_bus_state *bus_state;
u16 link_state = 0;
u16 wake_mask = 0;
u16 timeout = 0;
+   u16 selector = 0;
 
max_ports = xhci_get_ports(hcd, _array);
bus_state = >bus_state[hcd_index(hcd)];
@@ -959,6 +960,8 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 
wValue,
link_state = (wIndex & 0xff00) >> 3;
if (wValue == USB_PORT_FEAT_REMOTE_WAKE_MASK)
wake_mask = wIndex & 0xff00;
+   if (wValue == USB_PORT_FEAT_TEST)
+   selector = (wIndex & 0xff00) >> 8;
/* The MSB of wIndex is the U1/U2 timeout */
timeout = (wIndex & 0xff00) >> 8;
wIndex &= 0xff;
@@ -1134,6 +1137,64 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, 
u16 wValue,
temp |= PORT_U2_TIMEOUT(timeout);
writel(temp, port_array[wIndex] + PORTPMSC);
break;
+   case USB_PORT_FEAT_TEST:
+   /* 4.19.6 Port Test Modes (USB2 Test Mode) */
+   if (hcd->speed != HCD_USB2)
+   goto error;
+
+   /* FIXME: Test_Force_Enable case to be implemented */
+   if (selector < TEST_J || selector > TEST_PACKET)
+   goto error;
+
+   /* Disable all Device Slots */
+   for (i = 0; i < MAX_HC_SLOTS; i++) {
+   struct xhci_command *command;
+
+   if (!xhci->dcbaa->dev_context_ptrs[i])
+   continue;
+   command = xhci_alloc_command(xhci, false,
+   false, GFP_ATOMIC);
+   if (!command)
+   return -ENOMEM;
+   if (xhci_queue_slot_control(xhci, command,
+   TRB_DISABLE_SLOT, i)) {
+   xhci_err(xhci,
+   "Disable slot[%d] fail!\n", i);
+   goto error;
+   }
+   xhci_dbg(xhci, "Disable Slot[%d].\n", i);
+   }
+
+   /* Put all ports to the Disable state by clear PP */
+   xhci_dbg(xhci, "Disable all port (PP = 0)\n");
+   for (i = 0; i < max_ports; i++) {
+   temp = readl(port_array[i]);
+   temp &= ~PORT_POWER;
+   writel(temp, port_array[i]);
+   }
+
+   /* Stop the controller */
+   xhci_dbg(xhci, "Stop controller\n");
+   temp = readl(>op_regs->command);
+   temp &= ~CMD_RUN;
+   writel(temp, >op_regs->command);
+
+   if (xhci_handshake(>op_regs->status,
+   STS_HALT, STS_HALT, XHCI_MAX_HALT_USEC)) {
+  

Re: [PATCH v2 1/1] xhci: add USB2 test mode support

2017-02-08 Thread Mathias Nyman

On 08.02.2017 15:44, Alexander Stein wrote:

This patch adds support for USB2 test mode (Test_J, Test_K,
Test_SE0_NAK and Test_Packet) per XHCI spec 4.19.6.

USB2 test mode is a required hardware feature for system integrators
validating their hardware according to USB spec, regarding signal
strength and stuff. It is purely a hardware test feature.

Usually you need an oscilloscope and have to enable those test modes on
the hardware. This will send some specific test patterns on D+/D-. There
is no report available (in Linux itself) as it is purely externally
visible. Regular USB usage is not possible at that time.
Anyone (well access to e.g. /dev/bus/usb/001/001 provided) can use it by
sending appropriate USB_PORT_FEAT_TEST requests to the hub.
The same feature for ehci based hosts is already available at
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/usb/host/ehci-hub.c#n1267

Signed-off-by: "Wang, Yu" 
Signed-off-by: "Li, Guanglei" 
Signed-off-by: "Wu, Hao" 
Signed-off-by: Alexander Stein 
---


I think there's a reworked series of this feature already posted at:

http://marc.info/?l=linux-usb=148050258916147=2

But this change log is now better
I was thinking about adding that to 4.12

-Mathias



Re: [PATCH v2 1/1] xhci: add USB2 test mode support

2017-02-08 Thread Mathias Nyman

On 08.02.2017 15:44, Alexander Stein wrote:

This patch adds support for USB2 test mode (Test_J, Test_K,
Test_SE0_NAK and Test_Packet) per XHCI spec 4.19.6.

USB2 test mode is a required hardware feature for system integrators
validating their hardware according to USB spec, regarding signal
strength and stuff. It is purely a hardware test feature.

Usually you need an oscilloscope and have to enable those test modes on
the hardware. This will send some specific test patterns on D+/D-. There
is no report available (in Linux itself) as it is purely externally
visible. Regular USB usage is not possible at that time.
Anyone (well access to e.g. /dev/bus/usb/001/001 provided) can use it by
sending appropriate USB_PORT_FEAT_TEST requests to the hub.
The same feature for ehci based hosts is already available at
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/usb/host/ehci-hub.c#n1267

Signed-off-by: "Wang, Yu" 
Signed-off-by: "Li, Guanglei" 
Signed-off-by: "Wu, Hao" 
Signed-off-by: Alexander Stein 
---


I think there's a reworked series of this feature already posted at:

http://marc.info/?l=linux-usb=148050258916147=2

But this change log is now better
I was thinking about adding that to 4.12

-Mathias



Re: [PATCH v2 1/1] xhci: add USB2 test mode support

2017-02-08 Thread Greg Kroah-Hartman
On Wed, Feb 08, 2017 at 02:44:44PM +0100, Alexander Stein wrote:
> This patch adds support for USB2 test mode (Test_J, Test_K,
> Test_SE0_NAK and Test_Packet) per XHCI spec 4.19.6.
> 
> USB2 test mode is a required hardware feature for system integrators
> validating their hardware according to USB spec, regarding signal
> strength and stuff. It is purely a hardware test feature.
> 
> Usually you need an oscilloscope and have to enable those test modes on
> the hardware. This will send some specific test patterns on D+/D-. There
> is no report available (in Linux itself) as it is purely externally
> visible. Regular USB usage is not possible at that time.
> Anyone (well access to e.g. /dev/bus/usb/001/001 provided) can use it by
> sending appropriate USB_PORT_FEAT_TEST requests to the hub.
> The same feature for ehci based hosts is already available at
> https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/usb/host/ehci-hub.c#n1267
> 
> Signed-off-by: "Wang, Yu" 
> Signed-off-by: "Li, Guanglei" 
> Signed-off-by: "Wu, Hao" 
> Signed-off-by: Alexander Stein 
> ---
> Changes in v2:
> * Added additional info about USB2 test modes itself into commit message
> * Add URL for same test mode feature on ehci hosts.

Much nicer, thanks.



Re: [PATCH v2 1/1] xhci: add USB2 test mode support

2017-02-08 Thread Greg Kroah-Hartman
On Wed, Feb 08, 2017 at 02:44:44PM +0100, Alexander Stein wrote:
> This patch adds support for USB2 test mode (Test_J, Test_K,
> Test_SE0_NAK and Test_Packet) per XHCI spec 4.19.6.
> 
> USB2 test mode is a required hardware feature for system integrators
> validating their hardware according to USB spec, regarding signal
> strength and stuff. It is purely a hardware test feature.
> 
> Usually you need an oscilloscope and have to enable those test modes on
> the hardware. This will send some specific test patterns on D+/D-. There
> is no report available (in Linux itself) as it is purely externally
> visible. Regular USB usage is not possible at that time.
> Anyone (well access to e.g. /dev/bus/usb/001/001 provided) can use it by
> sending appropriate USB_PORT_FEAT_TEST requests to the hub.
> The same feature for ehci based hosts is already available at
> https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/usb/host/ehci-hub.c#n1267
> 
> Signed-off-by: "Wang, Yu" 
> Signed-off-by: "Li, Guanglei" 
> Signed-off-by: "Wu, Hao" 
> Signed-off-by: Alexander Stein 
> ---
> Changes in v2:
> * Added additional info about USB2 test modes itself into commit message
> * Add URL for same test mode feature on ehci hosts.

Much nicer, thanks.