Re: 4.1.2: AUKEY CB-H16 13+2port USB3 hub detection

2015-07-22 Thread Sarah Sharp
Adding Mathias Nyman (new USB 3.0 maintainer) and the USB mailing list.

On Tue, Jul 21, 2015 at 11:21:18PM +0200, Martin MOKREJŠ wrote:
 Hi Sarah and Alan,
   I bought a new toy: 13port USB 3.0 HUB based on VIAlabs 812 chipset with 
 two power-only charging ports: 1x1.5A and 1x2.4A (AUKEY CB-H16, from Amazon).
 
   I see a lot of complaints when I connect the hub. Would you please check 
 the attached usbmon trace, lsusb and dmesg? It is from 4.1.2 kernel but I 
 have bad experience with 3.10.12 as well. ;-) The usbmon captured from 0u 
 file shoudl contain when I enabled power on the external hub, then connected 
 one external USB3 drive, later another one but it was not picked up, then I 
 unplugged it and re-plugged (it was detected). Then I did twice 'lsusb -vv' 
 and stopped capturing.
 
 
   I also could not shutdown the computer as it was still looking for the 
 device (SysCtrl+o just printed PowerOff but nothing happened). But let's 
 bother about that later, eventually.
 
 Thank you for your help,
 Martin


 [0.00] Linux version 4.1.2-default-pciehp (root@vostro) (gcc version 
 4.9.2 (Gentoo 4.9.2 p1.4, pie-0.6.2) ) #2 SMP Tue Jul 14 22:00:22 CEST 2015
 [0.00] Command line: BOOT_IMAGE=/boot/vmlinuz-4.1.2 root=/dev/sda5 ro 
 slub_debug=AFPZ pciehp.pciehp_debug=1 pciehp_debug=1 intel_idle.max_cstate=c3 
 i915.i915_enable_rc6=1 usbcore.autosuspend=-1
 [0.00] e820: BIOS-provided physical RAM map:
 [0.00] BIOS-e820: [mem 0x-0x0009d3ff] usable
 [0.00] BIOS-e820: [mem 0x0009d400-0x0009] reserved
 [0.00] BIOS-e820: [mem 0x000e-0x000f] reserved
 [0.00] BIOS-e820: [mem 0x0010-0x1fff] usable
 [0.00] BIOS-e820: [mem 0x2000-0x201f] reserved
 [0.00] BIOS-e820: [mem 0x2020-0x3fff] usable
 [0.00] BIOS-e820: [mem 0x4000-0x401f] reserved
 [0.00] BIOS-e820: [mem 0x4020-0xda4e4fff] usable
 [0.00] BIOS-e820: [mem 0xda4e5000-0xda527fff] ACPI NVS
 [0.00] BIOS-e820: [mem 0xda528000-0xda792fff] usable
 [0.00] BIOS-e820: [mem 0xda793000-0xda966fff] reserved
 [0.00] BIOS-e820: [mem 0xda967000-0xdaa88fff] usable
 [0.00] BIOS-e820: [mem 0xdaa89000-0xdad67fff] reserved
 [0.00] BIOS-e820: [mem 0xdad68000-0xdafe7fff] ACPI NVS
 [0.00] BIOS-e820: [mem 0xdafe8000-0xdaff] ACPI 
 data
 [0.00] BIOS-e820: [mem 0xdb80-0xdf9f] reserved
 [0.00] BIOS-e820: [mem 0xf800-0xfbff] reserved
 [0.00] BIOS-e820: [mem 0xfec0-0xfec00fff] reserved
 [0.00] BIOS-e820: [mem 0xfed0-0xfed03fff] reserved
 [0.00] BIOS-e820: [mem 0xfed1c000-0xfed1] reserved
 [0.00] BIOS-e820: [mem 0xfee0-0xfee00fff] reserved
 [0.00] BIOS-e820: [mem 0xff00-0x] reserved
 [0.00] BIOS-e820: [mem 0x0001-0x00041fdf] usable
 [0.00] NX (Execute Disable) protection: active
 [0.00] SMBIOS 2.6 present.
 [0.00] DMI: Dell Inc. Vostro 3550/, BIOS A12 02/18/2014
 [0.00] e820: update [mem 0x-0x0fff] usable == reserved
 [0.00] e820: remove [mem 0x000a-0x000f] usable
 [0.00] e820: last_pfn = 0x41fe00 max_arch_pfn = 0x4
 [0.00] MTRR default type: uncachable
 [0.00] MTRR fixed ranges enabled:
 [0.00]   0-9 write-back
 [0.00]   A-B uncachable
 [0.00]   C-C write-protect
 [0.00]   D-E7FFF uncachable
 [0.00]   E8000-F write-protect
 [0.00] MTRR variable ranges enabled:
 [0.00]   0 base 0 mask C write-back
 [0.00]   1 base 4 mask FE000 write-back
 [0.00]   2 base 0DB80 mask FFF80 uncachable
 [0.00]   3 base 0DC00 mask FFC00 uncachable
 [0.00]   4 base 0E000 mask FE000 uncachable
 [0.00]   5 base 41FE0 mask FFFE0 uncachable
 [0.00]   6 disabled
 [0.00]   7 disabled
 [0.00]   8 disabled
 [0.00]   9 disabled
 [0.00] PAT configuration [0-7]: WB  WC  UC- UC  WB  WC  UC- UC  
 [0.00] e820: update [mem 0xdb80-0x] usable == reserved
 [0.00] e820: last_pfn = 0xdaa89 max_arch_pfn = 0x4
 [0.00] Base memory trampoline at [88097000] 97000 size 24576
 [0.00] reserving inaccessible SNB gfx pages
 [0.00] init_memory_mapping: [mem 0x-0x000f]
 [0.00]  [mem 0x-0x000f] page 4k
 [0.00] BRK [0x03179000, 0x03179fff] PGTABLE
 [

Re: [PATCH v7 08/23] usb: chipidea: set usb otg capabilities

2015-07-22 Thread Felipe Balbi
On Mon, Jul 13, 2015 at 09:03:14AM +0800, Peter Chen wrote:
 On Thu, Jul 09, 2015 at 09:22:09PM +0800, Li Jun wrote:
  On Thu, Jul 09, 2015 at 11:57:39AM +0300, Roger Quadros wrote:
   Hi,
   
   On 09/07/15 10:18, Li Jun wrote:
Init and update otg capabilities by DT, set gadget's otg capabilities
accordingly.

Signed-off-by: Li Jun jun...@freescale.com
---
 drivers/usb/chipidea/core.c  | 15 +++
 drivers/usb/chipidea/udc.c   |  7 ++-
 include/linux/usb/chipidea.h |  1 +
 3 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
index 74fea4f..1e6d5f0 100644
--- a/drivers/usb/chipidea/core.c
+++ b/drivers/usb/chipidea/core.c
@@ -560,6 +560,8 @@ static irqreturn_t ci_irq(int irq, void *data)
 static int ci_get_platdata(struct device *dev,
struct ci_hdrc_platform_data *platdata)
 {
+   int ret;
+
if (!platdata-phy_mode)
platdata-phy_mode = of_usb_get_phy_mode(dev-of_node);
 
@@ -588,6 +590,19 @@ static int ci_get_platdata(struct device *dev,
of_usb_host_tpl_support(dev-of_node);
}
 
+   if (platdata-dr_mode == USB_DR_MODE_OTG) {
+   /* We can support HNP and SRP of OTG 2.0 */
+   platdata-ci_otg_caps.otg_rev = 0x0200;
+   platdata-ci_otg_caps.hnp_support = true;
+   platdata-ci_otg_caps.srp_support = true;
+
+   /* Update otg capabilities by DT properties */
+   ret = of_usb_update_otg_caps(dev-of_node,
+   platdata-ci_otg_caps);
+   if (ret)
+   return ret;
+   }
+
if (of_usb_get_maximum_speed(dev-of_node) == USB_SPEED_FULL)
platdata-flags |= CI_HDRC_FORCE_FULLSPEED;
 
diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
index 764f668..b7cca3e 100644
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -1827,6 +1827,7 @@ static irqreturn_t udc_irq(struct ci_hdrc *ci)
 static int udc_start(struct ci_hdrc *ci)
 {
struct device *dev = ci-dev;
+   struct usb_otg_caps *otg_caps = ci-platdata-ci_otg_caps;
int retval = 0;
 
spin_lock_init(ci-lock);
@@ -1834,8 +1835,12 @@ static int udc_start(struct ci_hdrc *ci)
ci-gadget.ops  = usb_gadget_ops;
ci-gadget.speed= USB_SPEED_UNKNOWN;
ci-gadget.max_speed= USB_SPEED_HIGH;
-   ci-gadget.is_otg   = ci-is_otg ? 1 : 0;
ci-gadget.name = ci-platdata-name;
+   ci-gadget.otg_caps = otg_caps;
+
+   if (otg_caps-hnp_support || otg_caps-srp_support ||
+   otg_caps-adp_support)
+   ci-gadget.is_otg = 1;
   
   It seems there are non OTG capable dual-role only ci controllers as well
   looking at ci_get_otg_capable() code.
   
   If so then this should be
 if (ci-is_otg  (otg_caps-hnp_support || otg_caps-srp_support ||
otg_caps-adp_support))
 ci-gadget.is_otg = 1
   
   cheers,
   -roger
   
  Seems it was in my previous version but dropped it by mistake later,
  I will add it.
  
 
 
 After you adding roger's comments, add my ack.
 
 Acked-by: Peter Chen peter.c...@freescale.com

am I getting a new version for this patch ?

-- 
balbi


signature.asc
Description: Digital signature


Re: [GIT PULL] USB fixes for v4.2-rc4

2015-07-22 Thread Greg KH
On Wed, Jul 22, 2015 at 09:04:44AM -0500, Felipe Balbi wrote:
 Hi Greg,
 
 A second fixes pull request, seems like there won't be any
 more fixes coming through me; either that or I'll be proven
 wrong :-)
 
 cheers
 
 The following changes since commit 52721d9d3334c1cb1f76219a161084094ec634dc:
 
   Linux 4.2-rc3 (2015-07-19 14:45:02 -0700)
 
 are available in the git repository at:
 
   git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git 
 tags/fixes-for-v4.2-rc4

Pulled and pushed out, thanks.

greg k-h
--
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


Re: [PATCH v7 00/23] usb gadget update for OTG 2.0

2015-07-22 Thread Felipe Balbi
On Thu, Jul 09, 2015 at 03:18:37PM +0800, Li Jun wrote:
 Change for v7:
 - Free otg descriptor when failure of bind in patch 21, 22, 23.
   add Roger's Reviewed-by for patch 10~20.
 - Choose the lesser otg-rev if otg-rev has been set before update by DT,
   remove 0x0300 in supported otg-rev list, and add code comments in case
   otg-rev is not passed in DT in patch 7.
 - Fail chipidea usb initilization if DT pass an unsupported otg-rev in patch 
 8.
 
 Change for v6:
 - Change of_usb_set_otg_caps to be of_usb_update_otg_caps, and add
   sanity check of otg-rev.
 - Add chipidea otg-rev ability to be 0x0200, which will be updated
   in DT, if not passed, will be reset to be 0.
 - Remove unnecessary change: move config's descriptor and bmAttributes
   init from xxxi_config() to xxx_bind() in leagcy gadget drivers.
 
 This is a follow-up of Macpaul Lin's previous patchset to resolve usb
 gadget driver working with OTG 2.0, and set otg features by not only
 usb driver config but also usb hardware property in DT, main changes:
 1. Add usb_otg20_descriptor definition for OTG 2.0 which introduces bcdOTG
field for otg revision, bcdOTG can be passed via device tree.
 2. OTG features(SRP/HNP/ADP) can be decided by combination of usb HW
properties and usb driver config.
 3. Change the chipidea usb driver to use the updated mechanism.
 4. Remove static usb otg descriptor definition, but allocate and init it
according to otg capabilities in each gadget driver, if otg capabilities
is not defined for legacy platforms, the usb otg descriptor content is
kept the same as current static definition.
 
 Li Jun (19):
   usb: otg: add usb_otg_caps structure for otg capabilities
   doc: dt-binding: usb: add otg related properties
   usb: common: add API to update usb otg capabilities by device tree
   usb: chipidea: set usb otg capabilities
   usb: chipidea: update ci_otg_is_fsm_mode conditions
   usb: gadget: add usb otg descriptor allocate and init interface
   usb: gadget: configfs: allocate and init otg descriptor by otg
 capabilities
   usb: gadget: ether: allocate and init otg descriptor by otg
 capabilities
   usb: gadget: acm_ms: allocate and init otg descriptor by otg
 capabilities
   usb: gadget: audio: allocate and init otg descriptor by otg
 capabilities
   usb: gadget: cdc2: allocate and init otg descriptor by otg
 capabilities
   usb: gadget: g_ffs: allocate and init otg descriptor by otg
 capabilities
   usb: gadget: hid: allocate and init otg descriptor by otg capabilities
   usb: gadget: mass_storage: allocate and init otg descriptor by otg
 capabilities
   usb: gadget: multi: allocate and init otg descriptor by otg
 capabilities
   usb: gadget: ncm: allocate and init otg descriptor by otg capabilities
   usb: gadget: printer: allocate and init otg descriptor by otg
 capabilities
   usb: gadget: serial: allocate and init otg descriptor by otg
 capabilities
   usb: gadget: zero: allocate and init otg descriptor by otg
 capabilities
 
 Macpaul Lin (4):
   usb: add usb_otg20_descriptor for OTG 2.0 and above
   usb: add USB_OTG_ADP definition
   usb: add usb_otg_caps to usb_gadget structure.
   usb: gadget: composite: add USB_DT_OTG request handling

ok, so how you guys want to handle this series ? Should I take
everything through my tree ? I'd need Acked-by for all chipidea drivers
if that's the case.

-- 
balbi


signature.asc
Description: Digital signature


Re: [PATCH v7 4/4] USB: io_ti: Add heartbeat to keep idle Edgeport ports from disconnecting

2015-07-22 Thread Peter Berger
On Wed, 2015-07-15 at 11:42 +0200, Johan Hovold wrote:
 On Sun, Jun 28, 2015 at 01:28:21PM -0500, Peter E. Berger wrote:
  From: Peter E. Berger pber...@brimson.com
  
  When using newer Edgeport devices such as the EP/416, idle ports are
  automatically bounced (disconnected and then reconnected) approximately
  every 60 seconds.  This breaks programs (e.g: minicom) where idle periods
  are common, normal and expected.
  
  I confirmed with the manufacturer (Digi International) that some Edgeports
  now ship from the factory with firmware that expects periodic heartbeat
  queries from the driver to keep idle ports alive.  This patch implements
  heartbeat support using the mechanism Digi suggested (periodically
  requesting an I2C descriptor address) that appears effective on Edgeports
  running the newer firmware (that require it) and benign on Edgeport
  devices running older firmware.  Since we know that Edgeport firmware
  version 4.80 (the version distributed in /lib/firmware/down3.bin and used
  for Edgeports that are either running still older versions or have no
  onboard non-volatile firmware image) does not require heartbeat support,
  this patch schedules heartbeats only on devices running firmware versions
  newer than 4.80.
 
 Looks good now.
 
 I did a quick test here with an Edgeport/1 and firmware version 4.80 and
 5.32 (from digi's ftp) and do not see any disconnects with either
 version even without this patch.
 
 Is that expected? Is only EP/416 affected or are you seeing these
 disconnects with even newer firmware than 5.32?

I checked again with my Digi contact who looked into this and reported
that the EP/416 models are currently the only ones that require
keepalive heartbeat support and only when running newer firmware such as
5.32 and 5.38.  So I changed the code to only schedule heartbeats for
EP/416 models (there are two flavors with separate product IDs) and
changed the patch subject and text to reflect this change.

Thanks.
 --Peter

 
 Thanks,
 Johan


--
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


Re: [PATCH] Fix data loss in cdc-acm

2015-07-22 Thread Oliver Neukum
On Wed, 2015-07-22 at 10:30 -0400, Peter Hurley wrote:
 3. Pre-allocate space _before_ the data arrives (with
 tty_buffer_request_room());
this is applicable to subsystems which know how much data can be
 in-flight
at any one time. This guarantees that when rx data arrives buffer
 space is
available (since it has already been allocated).
 
 Drivers that use method 2 typically attempt to recopy the buffered
 data
 when either new data arrives or @ unthrottle. I've seen others use
 deferred
 work as well.
 
 AFAIK no driver/subsystem is using method 3 for guaranteed delivery
 of in-flight data, but it seems ideally suited to usb serial.

Indeed. But flow control is still done by throttle/unthrottle, isn't it?

Regards
Oliver


--
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


Re: [PATCH v7 2/4] USB: io_ti: Move request_firmware() calls out of download_fw()

2015-07-22 Thread Peter Berger
On Wed, 2015-07-15 at 11:21 +0200, Johan Hovold wrote:

Hi Johan:

Thanks for another thoughtful and helpful review.  I think I have
addressed all the issues you noted and have a v8 patchset just about
ready to submit. First I'll respond to each of the specific points here
and in your other v7 review emails to make sure I have not missed
anything.


 On Sun, Jun 28, 2015 at 01:28:19PM -0500, Peter E. Berger wrote:
  From: Peter E. Berger pber...@brimson.com
  
  The io_ti driver fails to download firmware to Edgeport
  devices such as the EP/416, even when the on-disk firmware image
  (/lib/firmware/edgeport/down3.bin) is more current than the version
  on the EP/416.  The current download code is broken in a few ways.
  Notably it mis-uses global variables OperationalMajorVersion and
  OperationalMinorVersion (reading their values before they've been
  properly initialized and subsequently initializing them multiple times
  without synchronization).  This patch drops the global variables and
  replaces the redundant calls to request_firmware()/release_firmware()
  in download_fw() with a single call pair in edge_startup(); the firmware
  image pointer is then passed to download_fw() and build_i2c_fw_hdr().
 
 This looks good now apart from one small issue I mention below.

Done (see below).

 
 Could you also please rename the patch summary (Subject) to something
 more descriptive such as
 
   USB: io_ti: fix firmware version handling
 
 or similar?

Done.

 
  Signed-off-by: Peter E. Berger pber...@brimson.com
  ---
   drivers/usb/serial/io_ti.c | 91 
  +-
   1 file changed, 42 insertions(+), 49 deletions(-)
  
  diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
  index 69378a7..4492c17 100644
  --- a/drivers/usb/serial/io_ti.c
  +++ b/drivers/usb/serial/io_ti.c
 
  @@ -943,6 +925,13 @@ static int download_fw(struct edgeport_serial *serial)
  struct usb_interface_descriptor *interface;
  int download_cur_ver;
  int download_new_ver;
  +   u8 fw_major_version;
  +   u8 fw_minor_version;
  +
 
 I think you should add minimal sanity checks on the firmware length here
 as part of this patch. That is, make sure that fw-size = 4, or if you
 prefer, fw-size = FW_HEADER_SIZE (i.e. 8).

Done (using sizeof(struct edgeport_fw_hdr)).

 
  +   fw_major_version = fw-data[0];
  +   fw_minor_version = fw-data[1];
 
 Thanks,
 Johan


--
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


Re: [PATCH v7 1/4] USB: io_ti: Increase insufficient timeout for firmware downloads

2015-07-22 Thread Peter Berger
On Wed, 2015-07-15 at 11:47 +0200, Johan Hovold wrote:
 On Sun, Jun 28, 2015 at 01:28:18PM -0500, Peter E. Berger wrote:
  From: Peter E. Berger pber...@brimson.com
  
  The io_ti driver fails to download firmware to Edgeport devices such as
  the EP/416.  One of the problems is that the default 1 second timeout
  in ti_vsend_sync() is insufficient for download operations.  This patch
  increases the download timeout to 10 seconds.
 
 So only EP/416 appears to affected and this is only needed after fixing
 the firmware version handling as these devices have an e2prom and will
 function anyway?

I found an old EP/421 and discovered that it also demonstrates the
problem, which resolves with the longer timeout.  The EP/416 and EP/421
are the only models I've seen with e2prom.  I think your assertion that
these will work even with the broken firmware downloads is essentially
correct, but there may be some confusing behavior the first time they
are plugged in.

Some details:  If the on-board firmware is already newer than the
version in /lib/firmware/edgeport/down3.bin, then we won't get to this
problematic code at all and the device should work as expected.  If the
on-board firmware is older, the download to e2prom will at least start
and probably more:  at least in one test here, even though the download
timed out and was noted as a failure so no devices were registered at
the time, it appears to have actually succeeded.  This became obvious
when about 60 seconds later the firmware's keepalive timer forced the
devices to reconnect and the driver got another chance to initialize.
From that point forward, the EP/416 was up-to-date, so subsequent uses
(after a power cycle or USB unplug/plugin cycle) no longer activated the
problematic download code and the devices worked properly.

So, if that behavior holds for all Edgeports with e2prom, this may turn
out to be only a minor inconvenience that just requires a couple of
plug/unplug cycles when the devices are used for the first time, and
only if their onboard firmware is older than what's
in /lib/firmware/edgeport/down3.bin.

 
 I'm trying to determine whether we need this one in stable or not. The
 three last patches are too big and intrusive to meet the stable-kernel
 rules (the sanity one isn't even a fix). We could just say that using
 the latest firmware requires a recent kernel for these devices.

That (telling people to use a recent kernel for these devices) sounds
fine to me.

I'm preparing a v8 patchset and hope to submit it very soon.  Thanks.
 --Peter

 
 Thanks,
 Johan


--
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


Re: [PATCH v7 3/4] USB: io_ti: Add firmware image sanity checks

2015-07-22 Thread Peter Berger
On Wed, 2015-07-15 at 11:36 +0200, Johan Hovold wrote:
 On Sun, Jun 28, 2015 at 01:28:20PM -0500, Peter E. Berger wrote:
  From: Peter E. Berger pber...@brimson.com
  
  Do what we can to verify that the driver's firmware image is valid
  (before attempting to download it to the Edgeport) by adding a new
  function, check_fw_sanity(), and a call to it in in download_fw().
  Also add an fw == NULL check in edge_startup().
  
  Note: It looks like some Edgeports (models like the EP/416 with on-board
  E2PROM) may be able to function even if the on-disk firmware image is
  bad or missing, iff their local E2PROM versions are valid.  But most
  Edgeport models (I've tried EP/1 and EP/8) do not appear to have this
  capability and they always rely on the on-disk firmware image.
  
  I tested an implementation that calls the new check_fw_sanity()
  function at the top of download_fw() and, rather than simply returning
  an error if the firmware image is bad or missing, it saves the result
  and defers the decision until later when it may find that it is running
  on a E2PROM-equipped device with a valid image.  But I think this is
  messier than it is worth (adding still more messiness to the already
  very messy download_fw()) for such a marginal possible benefit.  So, at
  least for now, I have chosen the much simpler approach of returning an
  error whenever edge_startup() fails to load an on-disk firmware image, or
  check_fw_sanity() indicates that it is unusable.
  
  Signed-off-by: Peter E. Berger pber...@brimson.com
  ---
   drivers/usb/serial/io_ti.c | 63 
  +-
   1 file changed, 62 insertions(+), 1 deletion(-)
  
  diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
  index 4492c17..7c5f6fd 100644
  --- a/drivers/usb/serial/io_ti.c
  +++ b/drivers/usb/serial/io_ti.c
  @@ -35,6 +35,7 @@
   #include linux/uaccess.h
   #include linux/usb.h
   #include linux/usb/serial.h
  +#include asm/unaligned.h
   
   #include io_16654.h
   #include io_usbvend.h
  @@ -909,6 +910,64 @@ static int ti_cpu_rev(struct edge_ti_manuf_descriptor 
  *desc)
  return TI_GET_CPU_REVISION(desc-CpuRev_BoardRev);
   }
   
  +/*
  + * Edgeport firmware images start with a 7-byte header:
  + *
  + *  u8 major_version;
  + *  u8 minor_version;
  + *  le16 build_number;
  + *  le16 length;
  + *  u8 checksum;
  + *
  + * build_number has been set to 0 in all three of the images I have
  + * seen, and Digi Tech Support suggests that it is safe to ignore it.
  + *
  + * length is the number of bytes of actual data following the header.
  + *
  + * checksum is the low order byte resulting from adding the values of
  + * all the data bytes.
  + *
  + */
  +static int check_fw_sanity(struct edgeport_serial *serial,
  +   const struct firmware *fw)
  +{
  +#define FW_HEADER_SIZE 7
  +#define FW_LENGTH_OFFSET 4
  +#define FW_CHECKSUM_OFFSET 6
 
 Could you move this to the top of the file with the other defines?

I used your next suggestion to create a new struct edgeport_fw_hdr, so I
was able to drop these #defines altogether.

 
 Why not use a struct edgeport_fw_hdr instead? That could be reused when
 parsing the header in download_fw as well.

Great suggestion.  Done.

  +   u16 length_data;
  +   u16 length_total;
  +   u8 checksum;
  +   int checksum_new = 0;
  +   int pos;
  +   struct device *dev = serial-serial-interface-dev;
  +
  +   if (fw-size  FW_HEADER_SIZE) {
  +   dev_err(dev, %s - Incomplete fw header\n, __func__);
 
 You can drop the function name from these error messages that are
 already descriptive enough.

Done.

 
  +   return 1;
 
 return -EINVAL on errors

Done.

 
  +   }
  +
  +   length_data = get_unaligned_le16(fw-data[FW_LENGTH_OFFSET]);
  +   checksum = fw-data[FW_CHECKSUM_OFFSET];
  +   length_total = length_data + FW_HEADER_SIZE;
  +
  +   if (fw-size != length_total) {
  +   dev_err(dev, %s - Bad fw size (Expected:%d, Got:%d)\n,
  +   __func__, length_total, (int)fw-size);
 
 Use %u and %zu and drop the cast.

Done.

 Space after ':'?

Done.

 
  +   return 1;
  +   }
  +
  +   for (pos = FW_HEADER_SIZE; pos  length_total; ++pos)
 
  Use pos  fw-size

Done.

 
  +   checksum_new = (checksum_new + fw-data[pos])  0xFF;
  +
  +   if (checksum_new != checksum) {
  +   dev_err(dev, %s - Bad fw checksum (Expected:0x%x, Got:0x%x)\n,
  +__func__, checksum, checksum_new);
  +   return 1;
  +   }
  +
  +   return 0;
  +}
  +
   /**
* DownloadTIFirmware - Download run-time operating firmware to the TI5052
*
  @@ -928,6 +987,8 @@ static int download_fw(struct edgeport_serial *serial,
  u8 fw_major_version;
  u8 fw_minor_version;
   
  +   if (check_fw_sanity(serial, fw))
  +   return -EINVAL;
 
 I'd add a newline here.

Done.

 
  fw_major_version = fw-data[0];
  fw_minor_version = fw-data[1];
 

Re: [RFC PATCH 1/1] Add a usbredir kernel module to remotely connect USB devices over IP.

2015-07-22 Thread Jeremy White
On 07/22/2015 09:34 AM, Greg KH wrote:
 On Wed, Jul 22, 2015 at 09:03:53AM -0500, Jeremy White wrote:
 On 07/09/2015 05:06 AM, Alex Elsayed wrote:
 Alan Stern wrote:

 On Mon, 6 Jul 2015, Jeremy White wrote:

 Anything else fundamental to usbip that should inform the design of a
 usbredir driver?  usbip appears to be based off a 2004 vintage of
 dummy_hcd.  I'll look thoughtfully at the current dummy_hcd; please let
 me know if there is anything else I should consider.

 One thing that springs to mind is USB-3 streams.  When dummy-hcd was
 expanded to include USB-3, that was the major new ingredient.

 Another thing that comes to mind is that the USB-IF has its own official
 standard for this kind of thing now, called Media-Agnostic USB[1]. In
 November of 2014 a driver[2] was posted, followed by a second version[3],
 and it is apparently being refined inside Intel[4].

 [1]
 http://www.usb.org/developers/docs/devclass_docs/Media_Agnostic_USB_v1.0.zip
 [2] http://thread.gmane.org/gmane.linux.kernel/1820297
 [3] http://thread.gmane.org/gmane.linux.drivers.driver-project.devel/60498
 [4] http://article.gmane.org/gmane.linux.drivers.driver-project.devel/60757

 Thanks for the pointer, Alex.

 I spent some time with the spec and their proposed code.  It does seem
 plausible that XSpice could use a mausb/usbredir protocol converter.  So if
 there was a mausb kernel module, I could potentially implement support in
 XSpice in user space and not need a usbredir module.

 I sent an email to the two developers at Intel to ask if there had been any
 further progress and if I could collaborate with them. I have not heard
 back.

 The MA spec is substantial and seems well thought out.  But the usbredir
 protocol has the virtue of being relatively mature - it's 5 years old, with
 code in daily use.

 At this point it seems the best path forward is to continue work on the
 usbredir kernel module, which I will do unless I get some new information.
 
 Please work with the existing people, or with the existing spec, I don't
 want to be adding multiple versions of this type of protocol to the
 kernel.  As it is, I really don't even want to take your code, given
 that usbip is already there.  Ignoring it isn't ok.

The usbredir spec predates MA-USB by 4 years; it has greater claim to
the title 'existing' than does MA-USB.  I recognize that does not make
it better, and I recognize the value of a spec from a standards body.
But I also respect community standards in production use.

And I did not and am not ignoring the MA-USB patch and spec.

I privately wrote to the Intel authors of that patch a week ago; I've
publicly included them in this thread as well.  As far as I can tell,
they've been silent on this front since November; I fear that they may
have moved on, or that Intel is not actively working on this.  None of
the Intel authors listed on the MA-USB specification are kernel
contributors, so I did not have a way to reach out to them.  If you have
the means to engage others, I would appreciate that.

With no other input, my analysis was that it is better to proceed with
the existing spec.  It has a body of useful code, active users and
developers, and I am certain it will solve my problem.

Also, as for usbip, I'll point out that the existence of MA-USB
corroborates Hans rationale for the need to supplant usbip.

As I said, I will respond to any new information I receive. It would be
great to have a kernel module developed (or at least approved) by
seasoned hands at Intel.

But how long should I wait?

Cheers,

Jeremy
--
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


Re: [PATCH net-next] r8152: support the new RTL8153 chip

2015-07-22 Thread David Miller
From: Hayes Wang hayesw...@realtek.com
Date: Wed, 22 Jul 2015 15:27:41 +0800

 Support the new USB gigabit ethernet.
 
 Signed-off-by: Hayes Wang hayesw...@realtek.com

Applied.
--
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


Re: [PATCH v3 5/5] arm64: dts: mediatek: add xHCI usb phy for mt8173

2015-07-22 Thread Sergei Shtylyov

Hello.

On 07/22/2015 05:05 PM, Chunfeng Yun wrote:


add xHCI and phy drivers for MT8173-EVB



Signed-off-by: Chunfeng Yun chunfeng@mediatek.com
---
  arch/arm64/boot/dts/mediatek/mt8173-evb.dts | 15 ++
  arch/arm64/boot/dts/mediatek/mt8173.dtsi| 31 +
  2 files changed, 46 insertions(+)



diff --git a/arch/arm64/boot/dts/mediatek/mt8173-evb.dts 
b/arch/arm64/boot/dts/mediatek/mt8173-evb.dts
index f433c21..202b2b9 100644
--- a/arch/arm64/boot/dts/mediatek/mt8173-evb.dts
+++ b/arch/arm64/boot/dts/mediatek/mt8173-evb.dts
@@ -13,6 +13,7 @@
   */

  /dts-v1/;
+#include dt-bindings/gpio/gpio.h
  #include mt8173.dtsi

  / {
@@ -32,6 +33,15 @@
};

chosen { };
+
+   usb_p1_vbus: fixedregulator@0 {


   Just regulator@0 please. This is more in line with what ePAPR requires 
from the node names.



+   compatible = regulator-fixed;
+   regulator-name = usb_vbus;
+   regulator-min-microvolt = 500;
+   regulator-max-microvolt = 500;
+   gpio = pio 130 GPIO_ACTIVE_HIGH;
+   enable-active-high;
+   };
  };

  pwrap {

[...]

diff --git a/arch/arm64/boot/dts/mediatek/mt8173.dtsi 
b/arch/arm64/boot/dts/mediatek/mt8173.dtsi
index 0696f8f..aa1ecc7 100644
--- a/arch/arm64/boot/dts/mediatek/mt8173.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt8173.dtsi

[...]

@@ -393,6 +394,36 @@
#size-cells = 0;
status = disabled;
};
+
+   usb: usb30@1127 {


   ePAPR standardizes the name usb for such nodes, please fix.

[...]

MBR, Sergei

--
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


Re: Several races in usbnet module (kernel 4.1.x)

2015-07-22 Thread Eugene Shatokhin

21.07.2015 17:22, Oliver Neukum пишет:

On Mon, 2015-07-20 at 21:13 +0300, Eugene Shatokhin wrote:

And here, the code clears EVENT_RX_KILL bit in dev-flags, which may
execute concurrently with the above operation:
#0 clear_bit (bitops.h:113, inlined)
#1 usbnet_bh (usbnet.c:1475)
 /* restart RX again after disabling due to high error rate */
 clear_bit(EVENT_RX_KILL, dev-flags);

If clear_bit() is atomic w.r.t. setting dev-flags to 0, this race is
not a problem, I guess. Otherwise, it may be.


clear_bit is atomic with respect to other atomic operations.
So how about this:

Regards
Oliver



Thanks for the quick replies!
My comments are below.


From 1c4e685b3a9c183e04c46b661830e5c7ed35b513 Mon Sep 17 00:00:00 2001

From: Oliver Neukum oneu...@suse.com
Date: Tue, 21 Jul 2015 16:19:40 +0200
Subject: [PATCH] usbnet: fix race between usbnet_stop() and the BH

Does this do the job?

Signed-off-by: Oliver Neukum oneu...@suse.com
---
  drivers/net/usb/usbnet.c | 9 ++---
  1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
index 3c86b10..77a9a86 100644
--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -778,7 +778,7 @@ int usbnet_stop (struct net_device *net)
  {
struct usbnet   *dev = netdev_priv(net);
struct driver_info  *info = dev-driver_info;
-   int retval, pm;
+   int retval, pm, mpn;

clear_bit(EVENT_DEV_OPEN, dev-flags);
netif_stop_queue (net);
@@ -813,14 +813,17 @@ int usbnet_stop (struct net_device *net)
 * can't flush_scheduled_work() until we drop rtnl (later),
 * else workers could deadlock; so make workers a NOP.
 */



+   mpn = !test_and_clear_bit(EVENT_NO_RUNTIME_PM, dev-flags);


Right, I missed that. Indeed, if one needs EVENT_NO_RUNTIME_PM bit, one 
should get it before dev-flags is set to 0.



dev-flags = 0;


I suppose usbnet_bh() cannot be re-scheduled at this point. And if it is 
running now, tasklet_kill will wait till it finishes. So, I guess, it 
would be enough to zero dev-flags after tasklet_kill (dev-bh); 
rather than before it, like it is now.


Anyway, if it is needed to clear any particular flags to prevent 
re-scheduling of usbnet_bh(), this can be done here with clear_bit(). 
Not sure if there are such flags, I am by no means an expert in usbnet.



del_timer_sync (dev-delay);
tasklet_kill (dev-bh);


The following part is not necessary, I think. usbnet_bh() does not touch 
EVENT_NO_RUNTIME_PM bit explicitly and these bit operations are atomic 
w.r.t. each other.



+   mpn |= !test_and_clear_bit(EVENT_NO_RUNTIME_PM, dev-flags);
+   /* in case the bh reset a flag */


But zeroing dev-flags here is necessary, I agree.


+   dev-flags = 0;



if (!pm)
usb_autopm_put_interface(dev-intf);

-   if (info-manage_power 
-   !test_and_clear_bit(EVENT_NO_RUNTIME_PM, dev-flags))
+   if (info-manage_power  mpn)
info-manage_power(dev, 0);
else
usb_autopm_put_interface(dev-intf);



Regards,
Eugene
--
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


Re: [RFC PATCH 1/1] Add a usbredir kernel module to remotely connect USB devices over IP.

2015-07-22 Thread Sean O. Stalley
On Wed, Jul 22, 2015 at 11:55:32AM -0500, Jeremy White wrote:
 I privately wrote to the Intel authors of that patch a week ago; I've
 publicly included them in this thread as well.  As far as I can tell,
 they've been silent on this front since November; I fear that they may
 have moved on, or that Intel is not actively working on this.  None of
 the Intel authors listed on the MA-USB specification are kernel
 contributors, so I did not have a way to reach out to them.  If you have
 the means to engage others, I would appreciate that.

Sorry for the delay. The short answer is: Yes, we have been actively working on 
this driver.
Per Greg KH's request, we have been cleaning up the driver internally.
There was a lot to clean up, which is why we have been silent on LKML.

-Sean
--
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


Multiple drives on JMS56x-based sata-usb docking station.

2015-07-22 Thread Giulio Bernardi

Hi everybody,

I just bought an Inateck FD2003 docking station which is based on a JMicron 
JMS56x Series controller (152d:1567).


This docking station can host two sata drives. It works perfectly when one drive 
is inserted (in whathever slot), but if I try to use two drives together, only 
the one placed in slot #1 is seen.


I thought it was a problem of the docking station but then I tried to reboot in 
Windows 7 that came with the laptop and there I could see both drives.


I tried to power up the docking station with both drives in, with one drive and 
then hotplugging the other, and vice versa, but results are the same.
Whenever I plug or unplug a drive, the kernel says the usb device was 
disconnected, and later reconnected. This happens also if I unplug the drive 
that is not detected: if I have both drives inserted the system sees drive #1, 
if then I remove drive 2 the kernel says the device was disconnected, and after 
some seconds it is detected as reconnected.


My laptop has an usb2 controller though the device is usb3, my os is Fedora 22 
with kernel 4.0.8-300.fc22.x86_64.


Here is some information:

Dmesg when the docking station is powered up, with both drives inserted (but 
only sdb is detected)

8---
[ 4664.023187] usb 2-2: new high-speed USB device number 6 using ehci-pci
[ 4664.220239] usb 2-2: New USB device found, idVendor=152d, idProduct=1567
[ 4664.220251] usb 2-2: New USB device strings: Mfr=1, Product=2, SerialNumber=5
[ 4664.220259] usb 2-2: Product: JMS56x Series
[ 4664.220266] usb 2-2: Manufacturer: JMicron
[ 4664.220272] usb 2-2: SerialNumber: DB9876543211166
[ 4664.270949] usbcore: registered new interface driver usb-storage
[ 4664.277420] scsi host9: uas
[ 4664.277586] usbcore: registered new interface driver uas
[ 4664.278759] scsi 9:0:0:0: Direct-Access Inateck   0101 
PQ: 0 ANSI: 6

[ 4664.280601] sd 9:0:0:0: Attached scsi generic sg1 type 0
[ 4664.281232] sd 9:0:0:0: [sdb] 976773168 512-byte logical blocks: (500 GB/465 
GiB)
[ 4664.283730] sd 9:0:0:0: [sdb] Write Protect is off
[ 4664.283739] sd 9:0:0:0: [sdb] Mode Sense: 67 00 10 08
[ 4664.284729] sd 9:0:0:0: [sdb] Write cache: enabled, read cache: enabled, 
supports DPO and FUA

[ 4664.343157]  sdb: sdb1 sdb9
[ 4664.348352] sd 9:0:0:0: [sdb] Attached SCSI disk
8---


This is lsusb -v
8---
Bus 002 Device 006: ID 152d:1567 JMicron Technology Corp. / JMicron USA 
Technology Corp.

Device Descriptor:
  bLength18
  bDescriptorType 1
  bcdUSB   2.10
  bDeviceClass0 (Defined at Interface level)
  bDeviceSubClass 0
  bDeviceProtocol 0
  bMaxPacketSize064
  idVendor   0x152d JMicron Technology Corp. / JMicron USA Technology 
Corp.
  idProduct  0x1567
  bcdDevice1.01
  iManufacturer   1 JMicron
  iProduct2 JMS56x Series
  iSerial 5 DB9876543211166
  bNumConfigurations  1
  Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength   85
bNumInterfaces  1
bConfigurationValue 1
iConfiguration  4 USB Mass Storage
bmAttributes 0xc0
  Self Powered
MaxPower2mA
Interface Descriptor:
  bLength 9
  bDescriptorType 4
  bInterfaceNumber0
  bAlternateSetting   0
  bNumEndpoints   2
  bInterfaceClass 8 Mass Storage
  bInterfaceSubClass  6 SCSI
  bInterfaceProtocol 80 Bulk-Only
  iInterface  6 MSC Bulk-Only Transfer
  Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81  EP 1 IN
bmAttributes2
  Transfer TypeBulk
  Synch Type   None
  Usage Type   Data
wMaxPacketSize 0x0200  1x 512 bytes
bInterval   0
  Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x02  EP 2 OUT
bmAttributes2
  Transfer TypeBulk
  Synch Type   None
  Usage Type   Data
wMaxPacketSize 0x0200  1x 512 bytes
bInterval   0
Interface Descriptor:
  bLength 9
  bDescriptorType 4
  bInterfaceNumber0
  bAlternateSetting   1
  bNumEndpoints   4
  bInterfaceClass 8 Mass Storage
  bInterfaceSubClass  6 SCSI
  bInterfaceProtocol 98
  iInterface 10 MSC BOT/UAS Transfer
  Endpoint Descriptor:
bLength 7
 

[PATCH v8 1/4] USB: io_ti: Increase insufficient timeout for firmware downloads

2015-07-22 Thread Peter E. Berger
From: Peter E. Berger pber...@brimson.com

The io_ti driver fails to download firmware to Edgeport devices such as
the EP/416 and EP/421 (devices with on-board E2PROM).  One of the problems
is that the default 1 second timeout in ti_vsend_sync() is insufficient
for download operations.  This patch increases the download timeout to
10 seconds.

Signed-off-by: Peter E. Berger pber...@brimson.com
---
 drivers/usb/serial/io_ti.c | 38 ++
 1 file changed, 22 insertions(+), 16 deletions(-)

diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
index ddbb8fe..69378a7 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -210,6 +210,10 @@ static int edge_create_sysfs_attrs(struct usb_serial_port 
*port);
 static int edge_remove_sysfs_attrs(struct usb_serial_port *port);
 
 
+/* Timeouts in msecs: firmware downloads take longer */
+#define TI_VSEND_TIMEOUT_DEFAULT 1000
+#define TI_VSEND_TIMEOUT_FW_DOWNLOAD 1
+
 static int ti_vread_sync(struct usb_device *dev, __u8 request,
__u16 value, __u16 index, u8 *data, int size)
 {
@@ -228,14 +232,14 @@ static int ti_vread_sync(struct usb_device *dev, __u8 
request,
return 0;
 }
 
-static int ti_vsend_sync(struct usb_device *dev, __u8 request,
-   __u16 value, __u16 index, u8 *data, int size)
+static int ti_vsend_sync(struct usb_device *dev, u8 request, u16 value,
+   u16 index, u8 *data, int size, int timeout)
 {
int status;
 
status = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), request,
(USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT),
-   value, index, data, size, 1000);
+   value, index, data, size, timeout);
if (status  0)
return status;
if (status != size) {
@@ -250,7 +254,8 @@ static int send_cmd(struct usb_device *dev, __u8 command,
__u8 moduleid, __u16 value, u8 *data,
int size)
 {
-   return ti_vsend_sync(dev, command, value, moduleid, data, size);
+   return ti_vsend_sync(dev, command, value, moduleid, data, size,
+   TI_VSEND_TIMEOUT_DEFAULT);
 }
 
 /* clear tx/rx buffers and fifo in TI UMP */
@@ -378,9 +383,9 @@ static int write_boot_mem(struct edgeport_serial *serial,
}
 
for (i = 0; i  length; ++i) {
-   status = ti_vsend_sync(serial-serial-dev,
-   UMPC_MEMORY_WRITE, buffer[i],
-   (__u16)(i + start_address), NULL, 0);
+   status = ti_vsend_sync(serial-serial-dev, UMPC_MEMORY_WRITE,
+   buffer[i], (u16)(i + start_address), NULL,
+   0, TI_VSEND_TIMEOUT_DEFAULT);
if (status)
return status;
}
@@ -421,10 +426,9 @@ static int write_i2c_mem(struct edgeport_serial *serial,
 *   regardless of host byte order.
 */
be_start_address = swab16((u16)start_address);
-   status = ti_vsend_sync(serial-serial-dev,
-   UMPC_MEMORY_WRITE, (__u16)address_type,
-   be_start_address,
-   buffer, write_length);
+   status = ti_vsend_sync(serial-serial-dev, UMPC_MEMORY_WRITE,
+   (u16)address_type, be_start_address,
+   buffer, write_length, TI_VSEND_TIMEOUT_DEFAULT);
if (status) {
dev_dbg(dev, %s - ERROR %d\n, __func__, status);
return status;
@@ -454,9 +458,8 @@ static int write_i2c_mem(struct edgeport_serial *serial,
 */
be_start_address = swab16((u16)start_address);
status = ti_vsend_sync(serial-serial-dev, UMPC_MEMORY_WRITE,
-   (__u16)address_type,
-   be_start_address,
-   buffer, write_length);
+   (u16)address_type, be_start_address, buffer,
+   write_length, TI_VSEND_TIMEOUT_DEFAULT);
if (status) {
dev_err(dev, %s - ERROR %d\n, __func__, status);
return status;
@@ -1129,7 +1132,8 @@ static int download_fw(struct edgeport_serial *serial)
/* Reset UMP -- Back to BOOT MODE */
status = ti_vsend_sync(serial-serial-dev,
UMPC_HARDWARE_RESET,
-   0, 0, NULL, 0);
+   0, 0, NULL, 0,
+   TI_VSEND_TIMEOUT_DEFAULT);
 
dev_dbg(dev, %s - HARDWARE RESET return %d\n, 
__func__, status);
 
@@ -1229,7 +1233,9 

[PATCH v8 0/4] Fix idle port disconnects and firmware downloading

2015-07-22 Thread Peter E. Berger
From: Peter E. Berger pber...@brimson.com

I found that when using the Edgeport EP/416, idle ports are regularly
bounced (disconnected and then reconnected).  I discussed this with the
manufacturer (Digi International) and learned that EP/416 devices now
ship from the factory running firmware that requires periodic heartbeat
messages from the driver, so I enclose a proposed patch to implement their
suggested mechanism (which works both with old and new firmware).

While developing my heartbeat patch, I discovered that the firmware
download code was not working properly, so I also include three proposed
patches to fix this.

I welcome any comments or suggestions.

Thanks.
 --Peter

Changes since v7 [1]
Addressing Johan's review comments.  Thanks Johan!

 - Another consultation with Digi confirmed that the EP/416 models are
   the only ones that currently require heartbeat support, even with
   newer firmware.  Added code to check the product id and only schedule
   heartbeats for EP/416 models, and only if they are running new
   firmware.
 - Added new struct edgeport_fw_hdr for use both with the firmware
   version decoding and sanity checks.
 - Renamed patch 2/4 to the more descriptive Fix firmware version
   handling.
 - Added minimal sanity check on the firmware length in the Fix
   firmware version handling patch.
 - Improvements to check_fw_sanity():
   - use the new struct edgeport_fw_hdr
   - return -EINVAL on errors
   - replace %d with %u and %zu and drop unneeded cast
   - use fw-size instead of length_total
   - add a newline for better readability
 - drop the unneeded fw == NULL check in edge_startup()

[1]: v7: http://marc.info/?l=linux-usbm=143551612329338w=2
---

Peter E. Berger (4):
  USB: io_ti: Increase insufficient timeout for firmware downloads
  USB: io_ti: Fix firmware version handling
  USB: io_ti: Add firmware image sanity checks
  USB: io_ti: Add heartbeat to keep idle EP/416 ports from disconnecting

 drivers/usb/serial/io_ti.c | 275 ++---
 1 file changed, 209 insertions(+), 66 deletions(-)

-- 
1.8.3.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


[PATCH v8 2/4] USB: io_ti: Fix firmware version handling

2015-07-22 Thread Peter E. Berger
From: Peter E. Berger pber...@brimson.com

The io_ti driver fails to download firmware to Edgeport
devices such as the EP/416, even when the on-disk firmware image
(/lib/firmware/edgeport/down3.bin) is more current than the version
on the EP/416.  The current download code is broken in a few ways.
Notably it mis-uses global variables OperationalMajorVersion and
OperationalMinorVersion (reading their values before they've been
properly initialized and subsequently initializing them multiple times
without synchronization).  This patch drops the global variables and
replaces the redundant calls to request_firmware()/release_firmware()
in download_fw() with a single call pair in edge_startup(); the firmware
image pointer is then passed to download_fw() and build_i2c_fw_hdr().

Signed-off-by: Peter E. Berger pber...@brimson.com
---
 drivers/usb/serial/io_ti.c | 115 ++---
 1 file changed, 66 insertions(+), 49 deletions(-)

diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
index 69378a7..6cff12c 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -71,6 +71,25 @@ struct product_info {
__u8hardware_type;  /* Type of hardware */
 } __attribute__((packed));
 
+/*
+ * Edgeport firmware header
+ *
+ * build_number has been set to 0 in all three of the images I have
+ * seen, and Digi Tech Support suggests that it is safe to ignore it.
+ *
+ * length is the number of bytes of actual data following the header.
+ *
+ * checksum is the low order byte resulting from adding the values of
+ * all the data bytes.
+ */
+struct edgeport_fw_hdr {
+   u8 major_version;
+   u8 minor_version;
+   u16 build_number;
+   u16 length;
+   u8 checksum;
+} __packed;
+
 struct edgeport_port {
__u16 uart_base;
__u16 dma_address;
@@ -101,6 +120,7 @@ struct edgeport_serial {
struct mutex es_lock;
int num_ports_open;
struct usb_serial *serial;
+   int fw_version;
 };
 
 
@@ -187,10 +207,6 @@ static const struct usb_device_id id_table_combined[] = {
 
 MODULE_DEVICE_TABLE(usb, id_table_combined);
 
-static unsigned char OperationalMajorVersion;
-static unsigned char OperationalMinorVersion;
-static unsigned short OperationalBuildNumber;
-
 static int closing_wait = EDGE_CLOSING_WAIT;
 static bool ignore_cpu_rev;
 static int default_uart_mode;  /* RS232 */
@@ -751,18 +767,17 @@ exit:
 }
 
 /* Build firmware header used for firmware update */
-static int build_i2c_fw_hdr(__u8 *header, struct device *dev)
+static int build_i2c_fw_hdr(u8 *header, struct device *dev,
+   const struct firmware *fw)
 {
__u8 *buffer;
int buffer_size;
int i;
-   int err;
__u8 cs = 0;
struct ti_i2c_desc *i2c_header;
struct ti_i2c_image_header *img_header;
struct ti_i2c_firmware_rec *firmware_rec;
-   const struct firmware *fw;
-   const char *fw_name = edgeport/down3.bin;
+   struct edgeport_fw_hdr *fw_hdr = (struct edgeport_fw_hdr *)fw-data;
 
/* In order to update the I2C firmware we must change the type 2 record
 * to type 0xF2.  This will force the UMP to come up in Boot Mode.
@@ -785,24 +800,11 @@ static int build_i2c_fw_hdr(__u8 *header, struct device 
*dev)
// Set entire image of 0xffs
memset(buffer, 0xff, buffer_size);
 
-   err = request_firmware(fw, fw_name, dev);
-   if (err) {
-   dev_err(dev, Failed to load image \%s\ err %d\n,
-   fw_name, err);
-   kfree(buffer);
-   return err;
-   }
-
-   /* Save Download Version Number */
-   OperationalMajorVersion = fw-data[0];
-   OperationalMinorVersion = fw-data[1];
-   OperationalBuildNumber = fw-data[2] | (fw-data[3]  8);
-
/* Copy version number into firmware record */
firmware_rec = (struct ti_i2c_firmware_rec *)buffer;
 
-   firmware_rec-Ver_Major = OperationalMajorVersion;
-   firmware_rec-Ver_Minor = OperationalMinorVersion;
+   firmware_rec-Ver_Major = fw_hdr-major_version;
+   firmware_rec-Ver_Minor = fw_hdr-minor_version;
 
/* Pointer to fw_down memory image */
img_header = (struct ti_i2c_image_header *)fw-data[4];
@@ -811,8 +813,6 @@ static int build_i2c_fw_hdr(__u8 *header, struct device 
*dev)
fw-data[4 + sizeof(struct ti_i2c_image_header)],
le16_to_cpu(img_header-Length));
 
-   release_firmware(fw);
-
for (i=0; i  buffer_size; i++) {
cs = (__u8)(cs + buffer[i]);
}
@@ -826,8 +826,8 @@ static int build_i2c_fw_hdr(__u8 *header, struct device 
*dev)
i2c_header-Type= I2C_DESC_TYPE_FIRMWARE_BLANK;
i2c_header-Size= cpu_to_le16(buffer_size);
i2c_header-CheckSum= cs;
-   firmware_rec-Ver_Major = OperationalMajorVersion;
-   firmware_rec-Ver_Minor = OperationalMinorVersion;
+   

[PATCH v8 4/4] USB: io_ti: Add heartbeat to keep idle EP/416 ports from disconnecting

2015-07-22 Thread Peter E. Berger
From: Peter E. Berger pber...@brimson.com

When using Edgeport/416 models with newer firmware (sometime after
firmware version 4.80.0), idle ports are automatically bounced
(disconnected and then reconnected) approximately every 60 seconds.
This breaks programs (e.g: minicom) where idle periods are common,
normal and expected.

I confirmed with the manufacturer (Digi International) that Edgeport/416
models now ship from the factory with firmware that expects periodic
heartbeat queries from the driver to keep idle ports alive.  This
patch implements heartbeat support using the mechanism Digi suggested
(periodically requesting an I2C descriptor address) that appears effective
on Edgeports running the newer firmware (that require it) and benign on
Edgeport devices running older firmware.  Since we know that Edgeport
firmware version 4.80 (the version distributed in /lib/firmware/down3.bin
and used for Edgeports that are either running still older versions or
have no onboard non-volatile firmware image) does not require heartbeat
support, this patch schedules heartbeats only on Edgeport/416 devices,
and only if they are running firmware versions newer than 4.80.

Signed-off-by: Peter E. Berger pber...@brimson.com
---
 drivers/usb/serial/io_ti.c | 90 +-
 1 file changed, 89 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
index a73d242..093ff71 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -120,6 +120,7 @@ struct edgeport_serial {
struct mutex es_lock;
int num_ports_open;
struct usb_serial *serial;
+   struct delayed_work heartbeat_work;
int fw_version;
 };
 
@@ -225,6 +226,22 @@ static void edge_send(struct usb_serial_port *port, struct 
tty_struct *tty);
 static int edge_create_sysfs_attrs(struct usb_serial_port *port);
 static int edge_remove_sysfs_attrs(struct usb_serial_port *port);
 
+/*
+ * Some release of Edgeport firmware down3.bin after version 4.80
+ * introduced code to automatically disconnect idle devices on some
+ * Edgeport models after periods of inactivity, typically ~60 seconds.
+ * This occurs without regard to whether ports on the device are open
+ * or not.  Digi International Tech Support suggested:
+ *
+ * 1.  Adding driver heartbeat code to reset the firmware timer by
+ * requesting a descriptor record every 15 seconds, which should be
+ * effective with newer firmware versions that require it, and benign
+ * with older versions that do not. In practice 40 seconds seems often
+ * enough.
+ * 2.  The heartbeat code is currently required only on Edgeport/416 models.
+ */
+#define FW_HEARTBEAT_VERSION_CUTOFF ((4  8) + 80)
+#define FW_HEARTBEAT_SECS 40
 
 /* Timeouts in msecs: firmware downloads take longer */
 #define TI_VSEND_TIMEOUT_DEFAULT 1000
@@ -2415,6 +2432,44 @@ static void edge_break(struct tty_struct *tty, int 
break_state)
__func__, status);
 }
 
+static inline void edge_heartbeat_schedule(struct edgeport_serial *edge_serial)
+{
+   u16 product_id = le16_to_cpu(
+   edge_serial-serial-dev-descriptor.idProduct);
+
+   /* Currently only the EP/416 models require heartbeat support */
+   if (product_id != ION_DEVICE_ID_TI_EDGEPORT_416 
+   product_id != ION_DEVICE_ID_TI_EDGEPORT_416B)
+   return;
+
+   if (edge_serial-fw_version = FW_HEARTBEAT_VERSION_CUTOFF)
+   return;
+
+   schedule_delayed_work(edge_serial-heartbeat_work,
+   FW_HEARTBEAT_SECS * HZ);
+}
+
+static void edge_heartbeat_work(struct work_struct *work)
+{
+   struct edgeport_serial *serial;
+   struct ti_i2c_desc *rom_desc;
+
+   serial = container_of(work, struct edgeport_serial,
+   heartbeat_work.work);
+
+   rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL);
+
+   /* Descriptor address request is enough to reset the firmware timer */
+   if (!rom_desc || !get_descriptor_addr(serial, I2C_DESC_TYPE_ION,
+   rom_desc)) {
+   dev_err(serial-serial-interface-dev,
+   %s - Incomplete heartbeat\n, __func__);
+   }
+   kfree(rom_desc);
+
+   edge_heartbeat_schedule(serial);
+}
+
 static int edge_startup(struct usb_serial *serial)
 {
struct edgeport_serial *edge_serial;
@@ -2448,6 +2503,9 @@ static int edge_startup(struct usb_serial *serial)
return status;
}
 
+   INIT_DELAYED_WORK(edge_serial-heartbeat_work, edge_heartbeat_work);
+   edge_heartbeat_schedule(edge_serial);
+
return 0;
 }
 
@@ -2457,7 +2515,10 @@ static void edge_disconnect(struct usb_serial *serial)
 
 static void edge_release(struct usb_serial *serial)
 {
-   kfree(usb_get_serial_data(serial));
+   struct edgeport_serial *edge_serial = usb_get_serial_data(serial);
+
+   

[PATCH v8 3/4] USB: io_ti: Add firmware image sanity checks

2015-07-22 Thread Peter E. Berger
From: Peter E. Berger pber...@brimson.com

Do what we can to verify that the driver's firmware image is valid
(before attempting to download it to the Edgeport) by adding a new
function, check_fw_sanity(), and a call to it in in download_fw().

Note: It looks like some Edgeports (models like the EP/416 with on-board
E2PROM) may be able to function even if the on-disk firmware image is
bad or missing, iff their local E2PROM versions are valid.  But most
Edgeport models (I've tried EP/1 and EP/8) do not appear to have this
capability and they always rely on the on-disk firmware image.

I tested an implementation that calls the new check_fw_sanity()
function at the top of download_fw() and, rather than simply returning
an error if the firmware image is bad or missing, it saves the result
and defers the decision until later when it may find that it is running
on a E2PROM-equipped device with a valid image.  But I think this is
messier than it is worth (adding still more messiness to the already
very messy download_fw()) for such a marginal possible benefit.  So, at
least for now, I have chosen the much simpler approach of returning an
error whenever edge_startup() fails to load an on-disk firmware image, or
check_fw_sanity() indicates that it is unusable.

Signed-off-by: Peter E. Berger pber...@brimson.com
---
 drivers/usb/serial/io_ti.c | 40 
 1 file changed, 36 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
index 6cff12c..a73d242 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -928,6 +928,41 @@ static int ti_cpu_rev(struct edge_ti_manuf_descriptor 
*desc)
return TI_GET_CPU_REVISION(desc-CpuRev_BoardRev);
 }
 
+static int check_fw_sanity(struct edgeport_serial *serial,
+   const struct firmware *fw)
+{
+   u16 length_total;
+   int checksum = 0;
+   int pos;
+   struct device *dev = serial-serial-interface-dev;
+   struct edgeport_fw_hdr *fw_hdr = (struct edgeport_fw_hdr *)fw-data;
+
+   if (fw-size  sizeof(struct edgeport_fw_hdr)) {
+   dev_err(dev, Incomplete fw header\n);
+   return -EINVAL;
+   }
+
+   length_total = le16_to_cpu(fw_hdr-length) +
+   sizeof(struct edgeport_fw_hdr);
+
+   if (fw-size != length_total) {
+   dev_err(dev, Bad fw size (Expected: %u, Got: %zu)\n,
+   length_total, fw-size);
+   return -EINVAL;
+   }
+
+   for (pos = sizeof(struct edgeport_fw_hdr); pos  fw-size; ++pos)
+   checksum = (checksum + fw-data[pos])  0xFF;
+
+   if (checksum != fw_hdr-checksum) {
+   dev_err(dev, Bad fw checksum (Expected: 0x%x, Got: 0x%x)\n,
+   fw_hdr-checksum, checksum);
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
 /**
  * DownloadTIFirmware - Download run-time operating firmware to the TI5052
  *
@@ -946,11 +981,8 @@ static int download_fw(struct edgeport_serial *serial,
int download_new_ver;
struct edgeport_fw_hdr *fw_hdr = (struct edgeport_fw_hdr *)fw-data;
 
-   if (fw-size  sizeof(struct edgeport_fw_hdr)) {
-   dev_err(serial-serial-interface-dev,
-   %s - Incomplete firmware header.\n, __func__);
+   if (check_fw_sanity(serial, fw))
return -EINVAL;
-   }
 
/* If on-board version is newer, fw_version will be updated below. */
serial-fw_version = (fw_hdr-major_version  8) +
-- 
1.8.3.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


[PATCH v2 1/1] usb: gadget: f_uac2: finalize wMaxPacketSize according to bandwidth

2015-07-22 Thread Peter Chen
According to USB Audio Device 2.0 Spec, Ch4.10.1.1:
wMaxPacketSize is defined as follows:
Maximum packet size this endpoint is capable of sending or receiving
when this configuration is selected.
This is determined by the audio bandwidth constraints of the endpoint.

In current code, the wMaxPacketSize is defined as the maximum packet size
for ISO endpoint, and it will let the host reserve much more space than
it really needs, so that we can't let more endpoints work together at
one frame.

We find this issue when we try to let 4 f_uac2 gadgets work together [1]
at FS connection.

[1]http://www.spinics.net/lists/linux-usb/msg123478.html

Cc: andrze...@samsung.com
Cc: zon...@gmail.com
Cc: ti...@suse.de
Cc: sta...@vger.kernel.org #v3.18+
Cc: Alan Stern st...@rowland.harvard.edu
Signed-off-by: Peter Chen peter.c...@freescale.com
---

Changes for v2:
- Using DIV_ROUND_UP to calculate max packet size

 drivers/usb/gadget/function/f_uac2.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/drivers/usb/gadget/function/f_uac2.c 
b/drivers/usb/gadget/function/f_uac2.c
index 6d3eb8b..6eaa4c4 100644
--- a/drivers/usb/gadget/function/f_uac2.c
+++ b/drivers/usb/gadget/function/f_uac2.c
@@ -987,6 +987,7 @@ afunc_bind(struct usb_configuration *cfg, struct 
usb_function *fn)
struct f_uac2_opts *uac2_opts;
struct usb_string *us;
int ret;
+   u16 c_max_packet_size, p_max_packet_size;
 
uac2_opts = container_of(fn-fi, struct f_uac2_opts, func_inst);
 
@@ -1070,6 +1071,19 @@ afunc_bind(struct usb_configuration *cfg, struct 
usb_function *fn)
uac2-p_prm.uac2 = uac2;
uac2-c_prm.uac2 = uac2;
 
+   /* Calculate wMaxPacketSize according to audio bandwidth */
+   c_max_packet_size = uac2_opts-c_chmask * uac2_opts-c_ssize
+   * DIV_ROUND_UP(uac2_opts-c_srate, 1000);
+   p_max_packet_size = uac2_opts-p_chmask * uac2_opts-p_ssize
+   * DIV_ROUND_UP(uac2_opts-p_srate, 1000);
+   if ((c_max_packet_size  fs_epout_desc.wMaxPacketSize) ||
+   (p_max_packet_size  fs_epin_desc.wMaxPacketSize)) {
+   dev_err(dev, parameters are incorrect\n);
+   goto err;
+   }
+   fs_epin_desc.wMaxPacketSize = cpu_to_le16(c_max_packet_size);
+   fs_epout_desc.wMaxPacketSize = cpu_to_le16(p_max_packet_size);
+
hs_epout_desc.bEndpointAddress = fs_epout_desc.bEndpointAddress;
hs_epout_desc.wMaxPacketSize = fs_epout_desc.wMaxPacketSize;
hs_epin_desc.bEndpointAddress = fs_epin_desc.bEndpointAddress;
-- 
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


[PATCH net-next] r8152: support the new RTL8153 chip

2015-07-22 Thread Hayes Wang
Support the new USB gigabit ethernet.

Signed-off-by: Hayes Wang hayesw...@realtek.com
---
 drivers/net/usb/r8152.c | 18 +-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index 7f6419e..57b72ec 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -622,6 +622,7 @@ enum rtl_version {
RTL_VER_03,
RTL_VER_04,
RTL_VER_05,
+   RTL_VER_06,
RTL_VER_MAX
 };
 
@@ -2560,7 +2561,10 @@ static void r8153_hw_phy_cfg(struct r8152 *tp)
u32 ocp_data;
u16 data;
 
-   ocp_reg_write(tp, OCP_ADC_CFG, CKADSEL_L | ADC_EN | EN_EMI_L);
+   if (tp-version == RTL_VER_03 || tp-version == RTL_VER_04 ||
+   tp-version == RTL_VER_05)
+   ocp_reg_write(tp, OCP_ADC_CFG, CKADSEL_L | ADC_EN | EN_EMI_L);
+
data = r8152_mdio_read(tp, MII_BMCR);
if (data  BMCR_PDOWN) {
data = ~BMCR_PDOWN;
@@ -3274,6 +3278,13 @@ static void r8153_init(struct r8152 *tp)
else
ocp_data |= DYNAMIC_BURST;
ocp_write_byte(tp, MCU_TYPE_USB, USB_CSR_DUMMY1, ocp_data);
+   } else if (tp-version == RTL_VER_06) {
+   ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_CSR_DUMMY1);
+   if (ocp_read_word(tp, MCU_TYPE_USB, USB_BURST_SIZE) == 0)
+   ocp_data = ~DYNAMIC_BURST;
+   else
+   ocp_data |= DYNAMIC_BURST;
+   ocp_write_byte(tp, MCU_TYPE_USB, USB_CSR_DUMMY1, ocp_data);
}
 
ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_CSR_DUMMY2);
@@ -3908,6 +3919,10 @@ static void r8152b_get_version(struct r8152 *tp)
tp-version = RTL_VER_05;
tp-mii.supports_gmii = 1;
break;
+   case 0x5c30:
+   tp-version = RTL_VER_06;
+   tp-mii.supports_gmii = 1;
+   break;
default:
netif_info(tp, probe, tp-netdev,
   Unknown version 0x%04x\n, version);
@@ -3953,6 +3968,7 @@ static int rtl_ops_init(struct r8152 *tp)
case RTL_VER_03:
case RTL_VER_04:
case RTL_VER_05:
+   case RTL_VER_06:
ops-init   = r8153_init;
ops-enable = rtl8153_enable;
ops-disable= rtl8153_disable;
-- 
2.4.2

--
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


Re: [PATCH v2 1/1] usb: gadget: f_uac2: finalize wMaxPacketSize according to bandwidth

2015-07-22 Thread Daniel Mack
On 07/22/2015 08:45 AM, Peter Chen wrote:
 According to USB Audio Device 2.0 Spec, Ch4.10.1.1:
 wMaxPacketSize is defined as follows:
 Maximum packet size this endpoint is capable of sending or receiving
 when this configuration is selected.
 This is determined by the audio bandwidth constraints of the endpoint.
 
 In current code, the wMaxPacketSize is defined as the maximum packet size
 for ISO endpoint, and it will let the host reserve much more space than
 it really needs, so that we can't let more endpoints work together at
 one frame.
 
 We find this issue when we try to let 4 f_uac2 gadgets work together [1]
 at FS connection.
 
 [1]http://www.spinics.net/lists/linux-usb/msg123478.html
 
 Cc: andrze...@samsung.com
 Cc: zon...@gmail.com
 Cc: ti...@suse.de
 Cc: sta...@vger.kernel.org #v3.18+
 Cc: Alan Stern st...@rowland.harvard.edu
 Signed-off-by: Peter Chen peter.c...@freescale.com
 ---
 
 Changes for v2:
 - Using DIV_ROUND_UP to calculate max packet size
 
  drivers/usb/gadget/function/f_uac2.c | 14 ++
  1 file changed, 14 insertions(+)
 
 diff --git a/drivers/usb/gadget/function/f_uac2.c 
 b/drivers/usb/gadget/function/f_uac2.c
 index 6d3eb8b..6eaa4c4 100644
 --- a/drivers/usb/gadget/function/f_uac2.c
 +++ b/drivers/usb/gadget/function/f_uac2.c
 @@ -987,6 +987,7 @@ afunc_bind(struct usb_configuration *cfg, struct 
 usb_function *fn)
   struct f_uac2_opts *uac2_opts;
   struct usb_string *us;
   int ret;
 + u16 c_max_packet_size, p_max_packet_size;
  
   uac2_opts = container_of(fn-fi, struct f_uac2_opts, func_inst);
  
 @@ -1070,6 +1071,19 @@ afunc_bind(struct usb_configuration *cfg, struct 
 usb_function *fn)
   uac2-p_prm.uac2 = uac2;
   uac2-c_prm.uac2 = uac2;
  
 + /* Calculate wMaxPacketSize according to audio bandwidth */
 + c_max_packet_size = uac2_opts-c_chmask * uac2_opts-c_ssize
 + * DIV_ROUND_UP(uac2_opts-c_srate, 1000);
 + p_max_packet_size = uac2_opts-p_chmask * uac2_opts-p_ssize
 + * DIV_ROUND_UP(uac2_opts-p_srate, 1000);
 + if ((c_max_packet_size  fs_epout_desc.wMaxPacketSize) ||
 + (p_max_packet_size  fs_epin_desc.wMaxPacketSize)) {
 + dev_err(dev, parameters are incorrect\n);
 + goto err;
 + }
 + fs_epin_desc.wMaxPacketSize = cpu_to_le16(c_max_packet_size);
 + fs_epout_desc.wMaxPacketSize = cpu_to_le16(p_max_packet_size);
 +
   hs_epout_desc.bEndpointAddress = fs_epout_desc.bEndpointAddress;
   hs_epout_desc.wMaxPacketSize = fs_epout_desc.wMaxPacketSize;

Your calculation still doesn't take into account the endpoint's
'bInterval', and for HS, the value is still wrong.


Daniel

--
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


Re: [PATCH v2 1/1] usb: gadget: f_uac2: finalize wMaxPacketSize according to bandwidth

2015-07-22 Thread Peter Chen
On Wed, Jul 22, 2015 at 10:04:30AM +0200, Daniel Mack wrote:
 On 07/22/2015 08:45 AM, Peter Chen wrote:
  According to USB Audio Device 2.0 Spec, Ch4.10.1.1:
  wMaxPacketSize is defined as follows:
  Maximum packet size this endpoint is capable of sending or receiving
  when this configuration is selected.
  This is determined by the audio bandwidth constraints of the endpoint.
  
  In current code, the wMaxPacketSize is defined as the maximum packet size
  for ISO endpoint, and it will let the host reserve much more space than
  it really needs, so that we can't let more endpoints work together at
  one frame.
  
  We find this issue when we try to let 4 f_uac2 gadgets work together [1]
  at FS connection.
  
  [1]http://www.spinics.net/lists/linux-usb/msg123478.html
  
  Cc: andrze...@samsung.com
  Cc: zon...@gmail.com
  Cc: ti...@suse.de
  Cc: sta...@vger.kernel.org #v3.18+
  Cc: Alan Stern st...@rowland.harvard.edu
  Signed-off-by: Peter Chen peter.c...@freescale.com
  ---
  
  Changes for v2:
  - Using DIV_ROUND_UP to calculate max packet size
  
   drivers/usb/gadget/function/f_uac2.c | 14 ++
   1 file changed, 14 insertions(+)
  
  diff --git a/drivers/usb/gadget/function/f_uac2.c 
  b/drivers/usb/gadget/function/f_uac2.c
  index 6d3eb8b..6eaa4c4 100644
  --- a/drivers/usb/gadget/function/f_uac2.c
  +++ b/drivers/usb/gadget/function/f_uac2.c
  @@ -987,6 +987,7 @@ afunc_bind(struct usb_configuration *cfg, struct 
  usb_function *fn)
  struct f_uac2_opts *uac2_opts;
  struct usb_string *us;
  int ret;
  +   u16 c_max_packet_size, p_max_packet_size;
   
  uac2_opts = container_of(fn-fi, struct f_uac2_opts, func_inst);
   
  @@ -1070,6 +1071,19 @@ afunc_bind(struct usb_configuration *cfg, struct 
  usb_function *fn)
  uac2-p_prm.uac2 = uac2;
  uac2-c_prm.uac2 = uac2;
   
  +   /* Calculate wMaxPacketSize according to audio bandwidth */
  +   c_max_packet_size = uac2_opts-c_chmask * uac2_opts-c_ssize
  +   * DIV_ROUND_UP(uac2_opts-c_srate, 1000);
  +   p_max_packet_size = uac2_opts-p_chmask * uac2_opts-p_ssize
  +   * DIV_ROUND_UP(uac2_opts-p_srate, 1000);
  +   if ((c_max_packet_size  fs_epout_desc.wMaxPacketSize) ||
  +   (p_max_packet_size  fs_epin_desc.wMaxPacketSize)) {
  +   dev_err(dev, parameters are incorrect\n);
  +   goto err;
  +   }
  +   fs_epin_desc.wMaxPacketSize = cpu_to_le16(c_max_packet_size);
  +   fs_epout_desc.wMaxPacketSize = cpu_to_le16(p_max_packet_size);
  +
  hs_epout_desc.bEndpointAddress = fs_epout_desc.bEndpointAddress;
  hs_epout_desc.wMaxPacketSize = fs_epout_desc.wMaxPacketSize;
 
 Your calculation still doesn't take into account the endpoint's
 'bInterval', and for HS, the value is still wrong.
 
 

You mean I need to consider high bandwidth ISO transfer (3 packets per
SoF)? 

-- 

Best Regards,
Peter Chen
--
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


Re: [PATCH] Fix data loss in cdc-acm

2015-07-22 Thread Oliver Neukum
On Tue, 2015-07-21 at 12:45 -0400, Peter Hurley wrote:
 Let me know if you need help instrumenting the tty buffers/throttling
 to help figure out what the actual problem is.
 
 Regarding the patch itself, I have no opinion on the suitability of
 simply not resubmitting urbs. However, that is exactly how the
 throttle
 mechanism works, and the tty buffer API is specifically designed to
 allow drivers to manage flow via that interface as well (especially
 for high-throughput drivers).

Could you please expand on how this is supposed to work?
For once how does one learn that room is available again?

Regards
Oliver


--
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


Re: [PATCH v2 1/1] usb: gadget: f_uac2: finalize wMaxPacketSize according to bandwidth

2015-07-22 Thread Daniel Mack
On 07/22/2015 10:23 AM, Peter Chen wrote:
 On Wed, Jul 22, 2015 at 10:04:30AM +0200, Daniel Mack wrote:
 On 07/22/2015 08:45 AM, Peter Chen wrote:
 According to USB Audio Device 2.0 Spec, Ch4.10.1.1:
 wMaxPacketSize is defined as follows:
 Maximum packet size this endpoint is capable of sending or receiving
 when this configuration is selected.
 This is determined by the audio bandwidth constraints of the endpoint.

 In current code, the wMaxPacketSize is defined as the maximum packet size
 for ISO endpoint, and it will let the host reserve much more space than
 it really needs, so that we can't let more endpoints work together at
 one frame.

 We find this issue when we try to let 4 f_uac2 gadgets work together [1]
 at FS connection.

 [1]http://www.spinics.net/lists/linux-usb/msg123478.html

 Cc: andrze...@samsung.com
 Cc: zon...@gmail.com
 Cc: ti...@suse.de
 Cc: sta...@vger.kernel.org #v3.18+
 Cc: Alan Stern st...@rowland.harvard.edu
 Signed-off-by: Peter Chen peter.c...@freescale.com
 ---

 Changes for v2:
 - Using DIV_ROUND_UP to calculate max packet size

  drivers/usb/gadget/function/f_uac2.c | 14 ++
  1 file changed, 14 insertions(+)

 diff --git a/drivers/usb/gadget/function/f_uac2.c 
 b/drivers/usb/gadget/function/f_uac2.c
 index 6d3eb8b..6eaa4c4 100644
 --- a/drivers/usb/gadget/function/f_uac2.c
 +++ b/drivers/usb/gadget/function/f_uac2.c
 @@ -987,6 +987,7 @@ afunc_bind(struct usb_configuration *cfg, struct 
 usb_function *fn)
 struct f_uac2_opts *uac2_opts;
 struct usb_string *us;
 int ret;
 +   u16 c_max_packet_size, p_max_packet_size;
  
 uac2_opts = container_of(fn-fi, struct f_uac2_opts, func_inst);
  
 @@ -1070,6 +1071,19 @@ afunc_bind(struct usb_configuration *cfg, struct 
 usb_function *fn)
 uac2-p_prm.uac2 = uac2;
 uac2-c_prm.uac2 = uac2;
  
 +   /* Calculate wMaxPacketSize according to audio bandwidth */
 +   c_max_packet_size = uac2_opts-c_chmask * uac2_opts-c_ssize
 +   * DIV_ROUND_UP(uac2_opts-c_srate, 1000);
 +   p_max_packet_size = uac2_opts-p_chmask * uac2_opts-p_ssize
 +   * DIV_ROUND_UP(uac2_opts-p_srate, 1000);
 +   if ((c_max_packet_size  fs_epout_desc.wMaxPacketSize) ||
 +   (p_max_packet_size  fs_epin_desc.wMaxPacketSize)) {
 +   dev_err(dev, parameters are incorrect\n);
 +   goto err;
 +   }
 +   fs_epin_desc.wMaxPacketSize = cpu_to_le16(c_max_packet_size);
 +   fs_epout_desc.wMaxPacketSize = cpu_to_le16(p_max_packet_size);
 +
 hs_epout_desc.bEndpointAddress = fs_epout_desc.bEndpointAddress;
 hs_epout_desc.wMaxPacketSize = fs_epout_desc.wMaxPacketSize;

 Your calculation still doesn't take into account the endpoint's
 'bInterval', and for HS, the value is still wrong.

 
 I still not understand why I need to consider 'bInterval' for packet
 size, per my understanding, 'bInterval' is the interval time for sending
 each packet. At current code, it defines wMaxPacketSize as max value
 (1023/1024) for one packet, it may cause problem for audio driver,
 so you have the patch (9bb87f168931 usb: gadget: f_uac2: send reasonably
 sized packets) for reducing packet size according to its 'bInterval', but
 with my change, the wMaxPacketSize will be smaller than its max value,
 do we still need to reduce packet size for each transfer?

That detail is  merely about completeness. The code that calculates the
value of wMaxPacketSize should take into account what is configured in
bInterval of the endpoint, so if users change one thing, they don't have
to tweak the other as well.

bInterval denotes how many packets an endpoint can serve per second, and
wMaxPacketSize defines how large each packet can be. So in an
application that knows how many bytes/s are to be transferred,
wMaxPacketSize depends on bInterval.

On HS endpoints, we have 8 microframes per USB frame, so the divisor is
8000, not 1000. However, I just figured the descriptors in f_uac2 set
.bInterval to 4, which means a period of 8 (2^(4-1)), and that
compensates the factor again.

So, to conclude - your calculation indeed comes up with the correct
value, but it should still take the configured endpoint details into
account so the code makes clear how the numbers are determined.
Something like the following should work:

  /* for FS */
  div = 1000 / (1  (fs_epout_desc-bInterval - 1));

  /* for HS */
  div = 8000 / (1  (hs_epout_desc-bInterval - 1));

  c_max_packet_size = uac2_opts-c_chmask * uac2_opts-c_ssize
  * DIV_ROUND_UP(uac2_opts-c_srate, div);


Makes sense?


Thanks,
Daniel
--
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


Re: [PATCH] usb: dwc3: Reset the transfer resource index on SET_INTERFACE

2015-07-22 Thread Huang Rui
On Tue, Jul 21, 2015 at 09:29:17AM -0500, Felipe Balbi wrote:
 From: John Youn john.y...@synopsys.com
 
 This fixes an issue introduced in commit b23c843992b6 (usb: dwc3:
 gadget: fix DEPSTARTCFG for non-EP0 EPs) that made sure we would
 only use DEPSTARTCFG once per SetConfig.
 
 The trick is that we should use one DEPSTARTCFG per SetConfig *OR*
 SetInterface. SetInterface was completely missed from the original
 patch.
 
 This problem became aparent after commit 76e838c9f776 (usb: dwc3:
 gadget: return error if command sent to DEPCMD register fails)
 added checking of the return status of device endpoint commands.
 
 'Set Endpoint Transfer Resource' command was caught failing
 occasionally. This is because the Transfer Resource
 Index was not getting reset during a SET_INTERFACE request.
 
 Finally, to fix the issue, was we have to do is make sure that
 our start_config_issued flag gets reset whenever we receive a
 SetInterface request.
 
 To verify the problem (and its fix), all we have to do is run
 test 9 from testusb with 'testusb -t 9 -s 2048 -a -c 5000'.
 
 Fixes: b23c843992b6 (usb: dwc3: gadget: fix DEPSTARTCFG for non-EP0 EPs)
 Cc: sta...@vger.kernel.org # v3.2+
 Signed-off-by: John Youn johny...@synopsys.com
 Signed-off-by: Felipe Balbi ba...@ti.com

Felipe, I've verified it in my side. :)

ray@hr-slim:~/linux-usb$ sudo ./tools/usb/testusb -D /dev/bus/usb/002/004 -t 9 
-s 2048 -a -c 5000
unknown speed   /dev/bus/usb/002/0040
/dev/bus/usb/002/004 test 9,   15.300784 secs

Tested-by: Huang Rui ray.hu...@amd.com
--
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 v4] usb: gadget: f_mass_storage: stop thread in bind failure case

2015-07-22 Thread Sanjay Singh Rawat
After the worker thread is launched, bind function is doing further
configuration. In case of failure stop the thread.

Signed-off-by: Sanjay Singh Rawat snjs...@gmail.com
---

history:

v3: - handled Michal's comment; used existing function to change state and
  exit thread.
- tested for f_mass_storage.c only; dropped patches for legacy.

v2: - Handled review comment from Michal.
  - Merged v2 patch-2/3/4 to make patch-2.
- Added acked-by from Michal to patch-1.

v1: - Handled review comments from Michal.
  - updated patch-2 : added thread wake in legacy client of function 
(patch-2).
  - added patch-4 : freeing file-storage thread in configuration error case.
- added patch-3 (needed by patch-4) : moved fsg_common structure to 
header
  file, as code is dereferencing common-thread_task.
---
 drivers/usb/gadget/function/f_mass_storage.c | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/function/f_mass_storage.c 
b/drivers/usb/gadget/function/f_mass_storage.c
index f936268..c5b3db5 100644
--- a/drivers/usb/gadget/function/f_mass_storage.c
+++ b/drivers/usb/gadget/function/f_mass_storage.c
@@ -3080,7 +3080,7 @@ static int fsg_bind(struct usb_configuration *c, struct 
usb_function *f)
/* New interface */
i = usb_interface_id(c, f);
if (i  0)
-   return i;
+   goto fail;
fsg_intf_desc.bInterfaceNumber = i;
fsg-interface_number = i;
 
@@ -3123,7 +3123,14 @@ static int fsg_bind(struct usb_configuration *c, struct 
usb_function *f)
 
 autoconf_fail:
ERROR(fsg, unable to autoconfigure all endpoints\n);
-   return -ENOTSUPP;
+   i = -ENOTSUPP;
+fail:
+   /* terminate the thread */
+   if (fsg-common-state != FSG_STATE_TERMINATED) {
+   raise_exception(fsg-common, FSG_STATE_EXIT);
+   wait_for_completion(fsg-common-thread_notifier);
+   }
+   return i;
 }
 
 /** ALLOCATE FUNCTION */
-- 
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


Re: [PATCH v2 1/1] usb: gadget: f_uac2: finalize wMaxPacketSize according to bandwidth

2015-07-22 Thread Peter Chen
On Wed, Jul 22, 2015 at 10:04:30AM +0200, Daniel Mack wrote:
 On 07/22/2015 08:45 AM, Peter Chen wrote:
  According to USB Audio Device 2.0 Spec, Ch4.10.1.1:
  wMaxPacketSize is defined as follows:
  Maximum packet size this endpoint is capable of sending or receiving
  when this configuration is selected.
  This is determined by the audio bandwidth constraints of the endpoint.
  
  In current code, the wMaxPacketSize is defined as the maximum packet size
  for ISO endpoint, and it will let the host reserve much more space than
  it really needs, so that we can't let more endpoints work together at
  one frame.
  
  We find this issue when we try to let 4 f_uac2 gadgets work together [1]
  at FS connection.
  
  [1]http://www.spinics.net/lists/linux-usb/msg123478.html
  
  Cc: andrze...@samsung.com
  Cc: zon...@gmail.com
  Cc: ti...@suse.de
  Cc: sta...@vger.kernel.org #v3.18+
  Cc: Alan Stern st...@rowland.harvard.edu
  Signed-off-by: Peter Chen peter.c...@freescale.com
  ---
  
  Changes for v2:
  - Using DIV_ROUND_UP to calculate max packet size
  
   drivers/usb/gadget/function/f_uac2.c | 14 ++
   1 file changed, 14 insertions(+)
  
  diff --git a/drivers/usb/gadget/function/f_uac2.c 
  b/drivers/usb/gadget/function/f_uac2.c
  index 6d3eb8b..6eaa4c4 100644
  --- a/drivers/usb/gadget/function/f_uac2.c
  +++ b/drivers/usb/gadget/function/f_uac2.c
  @@ -987,6 +987,7 @@ afunc_bind(struct usb_configuration *cfg, struct 
  usb_function *fn)
  struct f_uac2_opts *uac2_opts;
  struct usb_string *us;
  int ret;
  +   u16 c_max_packet_size, p_max_packet_size;
   
  uac2_opts = container_of(fn-fi, struct f_uac2_opts, func_inst);
   
  @@ -1070,6 +1071,19 @@ afunc_bind(struct usb_configuration *cfg, struct 
  usb_function *fn)
  uac2-p_prm.uac2 = uac2;
  uac2-c_prm.uac2 = uac2;
   
  +   /* Calculate wMaxPacketSize according to audio bandwidth */
  +   c_max_packet_size = uac2_opts-c_chmask * uac2_opts-c_ssize
  +   * DIV_ROUND_UP(uac2_opts-c_srate, 1000);
  +   p_max_packet_size = uac2_opts-p_chmask * uac2_opts-p_ssize
  +   * DIV_ROUND_UP(uac2_opts-p_srate, 1000);
  +   if ((c_max_packet_size  fs_epout_desc.wMaxPacketSize) ||
  +   (p_max_packet_size  fs_epin_desc.wMaxPacketSize)) {
  +   dev_err(dev, parameters are incorrect\n);
  +   goto err;
  +   }
  +   fs_epin_desc.wMaxPacketSize = cpu_to_le16(c_max_packet_size);
  +   fs_epout_desc.wMaxPacketSize = cpu_to_le16(p_max_packet_size);
  +
  hs_epout_desc.bEndpointAddress = fs_epout_desc.bEndpointAddress;
  hs_epout_desc.wMaxPacketSize = fs_epout_desc.wMaxPacketSize;
 
 Your calculation still doesn't take into account the endpoint's
 'bInterval', and for HS, the value is still wrong.
 

I still not understand why I need to consider 'bInterval' for packet
size, per my understanding, 'bInterval' is the interval time for sending
each packet. At current code, it defines wMaxPacketSize as max value
(1023/1024) for one packet, it may cause problem for audio driver,
so you have the patch (9bb87f168931 usb: gadget: f_uac2: send reasonably
sized packets) for reducing packet size according to its 'bInterval', but
with my change, the wMaxPacketSize will be smaller than its max value,
do we still need to reduce packet size for each transfer?

-- 

Best Regards,
Peter Chen
--
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


RE: [PATCH] usb: dwc3: Reset the transfer resource index on SET_INTERFACE

2015-07-22 Thread Subbaraya Sundeep Bhatta
Hi Felipe,

 -Original Message-
 From: Felipe Balbi [mailto:ba...@ti.com]
 Sent: Tuesday, July 21, 2015 7:59 PM
 To: Linux USB Mailing List
 Cc: David Cohen; Subbaraya Sundeep Bhatta; Andy Gross; Kukjin Kim;
 Heikki Krogerus; Huang Rui; John Youn; sta...@vger.kernel.org; John Youn;
 Felipe Balbi
 Subject: [PATCH] usb: dwc3: Reset the transfer resource index on
 SET_INTERFACE
 
 From: John Youn john.y...@synopsys.com
 
 This fixes an issue introduced in commit b23c843992b6 (usb: dwc3:
 gadget: fix DEPSTARTCFG for non-EP0 EPs) that made sure we would only
 use DEPSTARTCFG once per SetConfig.
 
 The trick is that we should use one DEPSTARTCFG per SetConfig *OR*
 SetInterface. SetInterface was completely missed from the original patch.
 
 This problem became aparent after commit 76e838c9f776 (usb: dwc3:
 gadget: return error if command sent to DEPCMD register fails) added
 checking of the return status of device endpoint commands.
 
 'Set Endpoint Transfer Resource' command was caught failing occasionally.
 This is because the Transfer Resource Index was not getting reset during a
 SET_INTERFACE request.
 
 Finally, to fix the issue, was we have to do is make sure that our
 start_config_issued flag gets reset whenever we receive a SetInterface
 request.
 
 To verify the problem (and its fix), all we have to do is run test 9 from
 testusb with 'testusb -t 9 -s 2048 -a -c 5000'.
 
 Fixes: b23c843992b6 (usb: dwc3: gadget: fix DEPSTARTCFG for non-EP0
 EPs)
 Cc: sta...@vger.kernel.org # v3.2+
 Signed-off-by: John Youn johny...@synopsys.com
 Signed-off-by: Felipe Balbi ba...@ti.com
 ---
 
 I have improved commit log and blamed correct commit. Also added stable
 Cc so we have a chance of fixing older kernels.
 
 If you can test on your end, I'd be glad to add Tested-bys, but do so by
 tomorrow because it's extra important that we get this patch in.

unknown speed   /dev/bus/usb/001/008  0
/dev/bus/usb/001/008 test 9, 1213.703994 secs

It works fine at my end. 
As I mentioned earlier, mine is very slow setup and it took  ~1213 secs :)

Thanks,
Sundeep 
 
 This is working fine for me with test.sh/testusb
 
 cheers
 
  drivers/usb/dwc3/ep0.c | 4 
  1 file changed, 4 insertions(+)
 
 diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c index
 2ef3c8d6a9db..69e769c35cf5 100644
 --- a/drivers/usb/dwc3/ep0.c
 +++ b/drivers/usb/dwc3/ep0.c
 @@ -727,6 +727,10 @@ static int dwc3_ep0_std_request(struct dwc3
 *dwc, struct usb_ctrlrequest *ctrl)
   dwc3_trace(trace_dwc3_ep0,
 USB_REQ_SET_ISOCH_DELAY);
   ret = dwc3_ep0_set_isoch_delay(dwc, ctrl);
   break;
 + case USB_REQ_SET_INTERFACE:
 + dwc3_trace(trace_dwc3_ep0, USB_REQ_SET_INTERFACE);
 + dwc-start_config_issued = false;
 + /* Fall through */
   default:
   dwc3_trace(trace_dwc3_ep0, Forwarding to gadget
 driver);
   ret = dwc3_ep0_delegate_req(dwc, ctrl);
 --
 2.4.4

--
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


Re: [PATCH V2 1/4] usb: gadget: udc: bdc: Fix a driver crash on disconnect

2015-07-22 Thread Felipe Balbi
Hi,

On Wed, Jul 22, 2015 at 04:58:07PM -0400, Al Cooper wrote:
 V2 - Fix a compiler bug that happend when the config options
 CONFIG_USB_GADGET_DEBUG and CONFIG_USB_GADGET_VERBOSE
 were enabled.

this sort of version changes should be placed after the tearline so that
when I git am this patch, this doesn't go into the commit log. I'll fix
it up myself this time, but next time I'll have to require a resend.

thanks

-- 
balbi


signature.asc
Description: Digital signature


Re: [PATCH V2 1/4] usb: gadget: udc: bdc: Fix a driver crash on disconnect

2015-07-22 Thread Felipe Balbi
Hi,

On Wed, Jul 22, 2015 at 06:27:29PM -0400, Alan Cooper wrote:
 On Wed, Jul 22, 2015 at 5:29 PM, Felipe Balbi ba...@ti.com wrote:
  On Wed, Jul 22, 2015 at 04:26:57PM -0500, Felipe Balbi wrote:
  On Wed, Jul 22, 2015 at 04:58:07PM -0400, Al Cooper wrote:
   V2 - Fix a compiler bug that happend when the config options
   CONFIG_USB_GADGET_DEBUG and CONFIG_USB_GADGET_VERBOSE
   were enabled.
  
   ep_dequeue() in bdc_ep.c was capturing the hw dequeue pointer
   incorrectly by reading the wrong register for the upper 32 bits.
   The header file defining the registers was incorrect.
 
  btw, the header file was really incorrect as long as you passed 0 to
  the argument :-p
 
  in fact, the minimal fix for this bug would be the one below:
 
  diff --git a/drivers/usb/gadget/udc/bdc/bdc_ep.c 
  b/drivers/usb/gadget/udc/bdc/bdc_ep.c
  index b04980cf6dc4..1efa61265d8d 100644
  --- a/drivers/usb/gadget/udc/bdc/bdc_ep.c
  +++ b/drivers/usb/gadget/udc/bdc/bdc_ep.c
  @@ -779,7 +779,7 @@ static int ep_dequeue(struct bdc_ep *ep, struct bdc_req 
  *req)
  /* The current hw dequeue pointer */
  tmp_32 = bdc_readl(bdc-regs, BDC_EPSTS0(0));
  deq_ptr_64 = tmp_32;
  -   tmp_32 = bdc_readl(bdc-regs, BDC_EPSTS0(1));
  +   tmp_32 = bdc_readl(bdc-regs, BDC_EPSTS1(0));
  deq_ptr_64 |= ((u64)tmp_32  32);
 
  /* we have the dma addr of next bd that will be fetched by hardware 
  */
 
  And $subject becomes a cleanup patch for v4.3. Can you make these
  changes, please ?
 
 Yes, I can make these changes, but first let me explain why I did it this way.
 The 8 End Point Status registers are 32 bit consecutive registers, so
 defining them as:
 #define BDC_EPSTS0(n)  (0x60 + (n * 0x10))
 #define BDC_EPSTS1(n)  (0x64 + (n * 0x10))
 #define BDC_EPSTS2(n)  (0x68 + (n * 0x10))
 #define BDC_EPSTS3(n)  (0x6c + (n * 0x10))
 #define BDC_EPSTS4(n)  (0x70 + (n * 0x10))
 #define BDC_EPSTS5(n)  (0x74 + (n * 0x10))
 #define BDC_EPSTS6(n)  (0x78 + (n * 0x10))
 #define BDC_EPSTS7(n)  (0x7c + (n * 0x10))
 seems misleading, does not reflect the hardware and using anything
 other than (0) would get you to some other unexpected register and
 should be considered a coding error.

it sure is, but the minimal patch for -rc is what I sent above :-) As
long as you pass 0 as parameters, all your offsets are correct, so
removing the parameter (which must be always zero) is, actually,
refactoring happening.

 I think the original hardware spec had each End Point Status as a
 block of registers but the first silicon had them as single registers
 and they are expected to stay that way.

I believe they wanted to have:

#define BDC_EPSTS(n)(0x60 + (n * 0x4))

and that way you can access each EP by passing the correct argument to
that macro.

-- 
balbi


signature.asc
Description: Digital signature


Re: [PATCH] usb: ulpi: call put_device if device_register fails

2015-07-22 Thread Felipe Balbi
On Wed, Jul 22, 2015 at 02:39:34PM -0700, Greg Kroah-Hartman wrote:
 On Tue, Jun 23, 2015 at 01:57:38PM +0300, Heikki Krogerus wrote:
  On Fri, Jun 19, 2015 at 01:12:36AM +0800, ChengYi He wrote:
   put_device is required to release the last reference to the device.
   
   Signed-off-by: ChengYi He chengyihetai...@gmail.com
   ---
drivers/usb/common/ulpi.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
   
   diff --git a/drivers/usb/common/ulpi.c b/drivers/usb/common/ulpi.c
   index 0e6f968..bd25bdb 100644
   --- a/drivers/usb/common/ulpi.c
   +++ b/drivers/usb/common/ulpi.c
   @@ -184,8 +184,10 @@ static int ulpi_register(struct device *dev, struct 
   ulpi *ulpi)
 request_module(ulpi:v%04xp%04x, ulpi-id.vendor, ulpi-id.product);

 ret = device_register(ulpi-dev);
   - if (ret)
   + if (ret) {
   + put_device(ulpi-dev);
  
  If device_register returns failure, put_device has already been
  called. Check device_add in drivers/base/core.c.
 
 Yes, please read the function, which says:
  * NOTE: _Never_ directly free @dev after calling this function, even
  * if it returned an error! Always use put_device() to give up your
  * reference instead.
 
 But, the problem is that the ulpi core doesn't own that struct device.
 It comes from elsewhere.  It comes from somewhere deep down in the dw3
 core, which is where I lost the path.  Something needs to be fixed in
 dwc3_probe() to properly clean up the device if it fails, which is not
 happening right now.
 
 So this patch would actually cause much bigger problems than fixing
 anything, so it's wrong, but for a different reason than you are talking
 about here.
 
 And ugh, the ulpi and dwc code binding together, what a mess, horrid...

any suggestions ? DWC *is* the one implementing the bus. If there's a
better way, we can certainly shuffle code around.

-- 
balbi


signature.asc
Description: Digital signature


Re: [PATCH v7 00/23] usb gadget update for OTG 2.0

2015-07-22 Thread Macpaul Lin
Hi Jun,

2015-07-23 7:57 GMT+08:00 Li Jun b47...@freescale.com:
 On Wed, Jul 22, 2015 at 10:13:08AM -0500, Felipe Balbi wrote:
 On Thu, Jul 09, 2015 at 03:18:37PM +0800, Li Jun wrote:
  Change for v7:
  - Free otg descriptor when failure of bind in patch 21, 22, 23.
add Roger's Reviewed-by for patch 10~20.
  - Choose the lesser otg-rev if otg-rev has been set before update by DT,
remove 0x0300 in supported otg-rev list, and add code comments in case
otg-rev is not passed in DT in patch 7.
  - Fail chipidea usb initilization if DT pass an unsupported otg-rev in 
  patch 8.

[Deleted]

 I will resend the whole series with a small fix and Peter's ACK for
 chipidea part.

 Li Jun


I'm very appreciate the whole work you've done!
While I'm still during business travel and cannot give any help on this task.
Great thanks for yours works and others suggestions to improve the
whole series of pathces.

-- 
Best regards,
Macpaul Lin
--
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


Re: [PATCH v3 0/5] Mediatek xHCI support

2015-07-22 Thread chunfeng yun
Sorry, add a title

On Wed, 2015-07-22 at 22:05 +0800, Chunfeng Yun wrote:
 From ac1e8724bfa47494223bad0af450c1a63cd2fe0c Mon Sep 17 00:00:00 2001
 From: Chunfeng Yun chunfeng@mediatek.com
 Date: Wed, 22 Jul 2015 21:15:15 +0800
 Subject: [PATCH 0/5] *** SUBJECT HERE ***
 
 The patch supports MediaTek's xHCI controller.
 
 There are some differences from xHCI spec:
 1. The interval is specified in 250 * 8ns increments for Interrupt Moderation
 Interval(IMODI) of the Interrupter Moderation(IMOD) register, it is 8 times as
 much as that defined in xHCI spec.
 
 2. For the value of TD Size in Normal TRB, MTK's xHCI controller defines a
 number of packets that remain to be transferred for a TD after processing all
 Max packets in all previous TRBs,that means don't include the current TRB's,
 but in xHCI spec it includes the current ones.
 
 3. To minimize the scheduling effort for synchronous endpoints in xHC, the MTK
 architecture defines some extra SW scheduling parameters for HW. According to
 these parameters provided by SW, the xHC can easily decide whether a
 synchronous endpoint should be scheduled in a specific uFrame. The extra SW
 scheduling parameters are put into reserved DWs in Slot and Endpoint Context.
 And a bandwidth scheduler algorithm is added to support such feature.
 
 A usb3.0 phy driver is also added which used by mt65xx SoCs platform, it
 supports two usb2.0 ports and one usb3.0 port.
 
 Change in v3:
 1. implement generic phy
 2. move opperations for IPPC and wakeup from phy driver to xHCI driver
 3. seperate quirk functions into a single C file to fix up dependence issue
 
 Chunfeng Yun (5):
   dt-bindings: Add usb3.0 phy binding for MT65xx SoCs
   dt-bindings: Add a binding for Mediatek xHCI host controller
   usb: phy: add usb3.0 phy driver for mt65xx SoCs
   xhci: mediatek: support MTK xHCI host controller
   arm64: dts: mediatek: add xHCI  usb phy for mt8173
 
  .../devicetree/bindings/phy/phy-mt65xx-u3.txt  |  21 +
  .../devicetree/bindings/usb/mt8173-xhci.txt|  50 ++
  arch/arm64/boot/dts/mediatek/mt8173-evb.dts|  15 +
  arch/arm64/boot/dts/mediatek/mt8173.dtsi   |  31 +
  drivers/phy/Kconfig|   9 +
  drivers/phy/Makefile   |   1 +
  drivers/phy/phy-mt65xx-usb3.c  | 426 +++
  drivers/usb/host/Kconfig   |   9 +
  drivers/usb/host/Makefile  |   4 +
  drivers/usb/host/xhci-mtk-sch.c| 436 +++
  drivers/usb/host/xhci-mtk.c| 836 
 +
  drivers/usb/host/xhci-mtk.h| 135 
  drivers/usb/host/xhci-ring.c   |  35 +-
  drivers/usb/host/xhci.c|  19 +-
  drivers/usb/host/xhci.h|   1 +
  15 files changed, 2021 insertions(+), 7 deletions(-)
  create mode 100644 Documentation/devicetree/bindings/phy/phy-mt65xx-u3.txt
  create mode 100644 Documentation/devicetree/bindings/usb/mt8173-xhci.txt
  create mode 100644 drivers/phy/phy-mt65xx-usb3.c
  create mode 100644 drivers/usb/host/xhci-mtk-sch.c
  create mode 100644 drivers/usb/host/xhci-mtk.c
  create mode 100644 drivers/usb/host/xhci-mtk.h
 
 --
 1.8.1.1.dirty
 
 In-Reply-To: 
 


--
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


Re: Multiple drives on JMS56x-based sata-usb docking station.

2015-07-22 Thread Alan Stern
On Wed, 22 Jul 2015, Giulio Bernardi wrote:

 Hi everybody,
 
 I just bought an Inateck FD2003 docking station which is based on a JMicron 
 JMS56x Series controller (152d:1567).
 
 This docking station can host two sata drives. It works perfectly when one 
 drive 
 is inserted (in whathever slot), but if I try to use two drives together, 
 only 
 the one placed in slot #1 is seen.
 
 I thought it was a problem of the docking station but then I tried to reboot 
 in 
 Windows 7 that came with the laptop and there I could see both drives.
 
 I tried to power up the docking station with both drives in, with one drive 
 and 
 then hotplugging the other, and vice versa, but results are the same.
 Whenever I plug or unplug a drive, the kernel says the usb device was 
 disconnected, and later reconnected. This happens also if I unplug the drive 
 that is not detected: if I have both drives inserted the system sees drive 
 #1, 
 if then I remove drive 2 the kernel says the device was disconnected, and 
 after 
 some seconds it is detected as reconnected.
 
 My laptop has an usb2 controller though the device is usb3, my os is Fedora 
 22 
 with kernel 4.0.8-300.fc22.x86_64.

...

 Does someone have some hints? I tried to blacklist uas just to see if 
 something 
 changed, but it did not (except that module uas was not being loaded anymore).

Try capturing a usbmon trace showing what happens when you plug in the 
docking station with two drives installed.  Instructions are in the 
kernel source file Documentation/usb/usbmon.txt.

Alan Stern

--
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


Re: [PATCH v2 1/1] usb: gadget: f_uac2: finalize wMaxPacketSize according to bandwidth

2015-07-22 Thread Peter Chen
On Wed, Jul 22, 2015 at 12:11:55PM +0200, Daniel Mack wrote:
 On 07/22/2015 10:23 AM, Peter Chen wrote:
  On Wed, Jul 22, 2015 at 10:04:30AM +0200, Daniel Mack wrote:
  On 07/22/2015 08:45 AM, Peter Chen wrote:
  According to USB Audio Device 2.0 Spec, Ch4.10.1.1:
  wMaxPacketSize is defined as follows:
  Maximum packet size this endpoint is capable of sending or receiving
  when this configuration is selected.
  This is determined by the audio bandwidth constraints of the endpoint.
 
  In current code, the wMaxPacketSize is defined as the maximum packet size
  for ISO endpoint, and it will let the host reserve much more space than
  it really needs, so that we can't let more endpoints work together at
  one frame.
 
  We find this issue when we try to let 4 f_uac2 gadgets work together [1]
  at FS connection.
 
  [1]http://www.spinics.net/lists/linux-usb/msg123478.html
 
  Cc: andrze...@samsung.com
  Cc: zon...@gmail.com
  Cc: ti...@suse.de
  Cc: sta...@vger.kernel.org #v3.18+
  Cc: Alan Stern st...@rowland.harvard.edu
  Signed-off-by: Peter Chen peter.c...@freescale.com
  ---
 
  Changes for v2:
  - Using DIV_ROUND_UP to calculate max packet size
 
   drivers/usb/gadget/function/f_uac2.c | 14 ++
   1 file changed, 14 insertions(+)
 
  diff --git a/drivers/usb/gadget/function/f_uac2.c 
  b/drivers/usb/gadget/function/f_uac2.c
  index 6d3eb8b..6eaa4c4 100644
  --- a/drivers/usb/gadget/function/f_uac2.c
  +++ b/drivers/usb/gadget/function/f_uac2.c
  @@ -987,6 +987,7 @@ afunc_bind(struct usb_configuration *cfg, struct 
  usb_function *fn)
struct f_uac2_opts *uac2_opts;
struct usb_string *us;
int ret;
  + u16 c_max_packet_size, p_max_packet_size;
   
uac2_opts = container_of(fn-fi, struct f_uac2_opts, func_inst);
   
  @@ -1070,6 +1071,19 @@ afunc_bind(struct usb_configuration *cfg, struct 
  usb_function *fn)
uac2-p_prm.uac2 = uac2;
uac2-c_prm.uac2 = uac2;
   
  + /* Calculate wMaxPacketSize according to audio bandwidth */
  + c_max_packet_size = uac2_opts-c_chmask * uac2_opts-c_ssize
  + * DIV_ROUND_UP(uac2_opts-c_srate, 1000);
  + p_max_packet_size = uac2_opts-p_chmask * uac2_opts-p_ssize
  + * DIV_ROUND_UP(uac2_opts-p_srate, 1000);
  + if ((c_max_packet_size  fs_epout_desc.wMaxPacketSize) ||
  + (p_max_packet_size  fs_epin_desc.wMaxPacketSize)) {
  + dev_err(dev, parameters are incorrect\n);
  + goto err;
  + }
  + fs_epin_desc.wMaxPacketSize = cpu_to_le16(c_max_packet_size);
  + fs_epout_desc.wMaxPacketSize = cpu_to_le16(p_max_packet_size);
  +
hs_epout_desc.bEndpointAddress = fs_epout_desc.bEndpointAddress;
hs_epout_desc.wMaxPacketSize = fs_epout_desc.wMaxPacketSize;
 
  Your calculation still doesn't take into account the endpoint's
  'bInterval', and for HS, the value is still wrong.
 
  
  I still not understand why I need to consider 'bInterval' for packet
  size, per my understanding, 'bInterval' is the interval time for sending
  each packet. At current code, it defines wMaxPacketSize as max value
  (1023/1024) for one packet, it may cause problem for audio driver,
  so you have the patch (9bb87f168931 usb: gadget: f_uac2: send reasonably
  sized packets) for reducing packet size according to its 'bInterval', but
  with my change, the wMaxPacketSize will be smaller than its max value,
  do we still need to reduce packet size for each transfer?
 
 That detail is  merely about completeness. The code that calculates the
 value of wMaxPacketSize should take into account what is configured in
 bInterval of the endpoint, so if users change one thing, they don't have
 to tweak the other as well.
 
 bInterval denotes how many packets an endpoint can serve per second, and
 wMaxPacketSize defines how large each packet can be. So in an
 application that knows how many bytes/s are to be transferred,
 wMaxPacketSize depends on bInterval.
 
 On HS endpoints, we have 8 microframes per USB frame, so the divisor is
 8000, not 1000. However, I just figured the descriptors in f_uac2 set
 .bInterval to 4, which means a period of 8 (2^(4-1)), and that
 compensates the factor again.
 
 So, to conclude - your calculation indeed comes up with the correct
 value, but it should still take the configured endpoint details into
 account so the code makes clear how the numbers are determined.
 Something like the following should work:
 
   /* for FS */
   div = 1000 / (1  (fs_epout_desc-bInterval - 1));
 
   /* for HS */
   div = 8000 / (1  (hs_epout_desc-bInterval - 1));
 
   c_max_packet_size = uac2_opts-c_chmask * uac2_opts-c_ssize
   * DIV_ROUND_UP(uac2_opts-c_srate, div);
 
 
 Makes sense?
 

Thanks, it is correct. But looking the code at afunc_set_alt:
the method of calculating uac2-p_pktsize seems incorrect, it
may need to change like below:

@@ -1176,15 +1188,16 @@ afunc_set_alt(struct usb_function *fn, unsigned intf, 
unsigned alt)
factor = 1000;
} else {
 

Re: [PATCH] usb: ulpi: call put_device if device_register fails

2015-07-22 Thread Greg Kroah-Hartman
On Wed, Jul 22, 2015 at 09:04:40PM -0500, Felipe Balbi wrote:
 On Wed, Jul 22, 2015 at 02:39:34PM -0700, Greg Kroah-Hartman wrote:
  On Tue, Jun 23, 2015 at 01:57:38PM +0300, Heikki Krogerus wrote:
   On Fri, Jun 19, 2015 at 01:12:36AM +0800, ChengYi He wrote:
put_device is required to release the last reference to the device.

Signed-off-by: ChengYi He chengyihetai...@gmail.com
---
 drivers/usb/common/ulpi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/common/ulpi.c b/drivers/usb/common/ulpi.c
index 0e6f968..bd25bdb 100644
--- a/drivers/usb/common/ulpi.c
+++ b/drivers/usb/common/ulpi.c
@@ -184,8 +184,10 @@ static int ulpi_register(struct device *dev, 
struct ulpi *ulpi)
request_module(ulpi:v%04xp%04x, ulpi-id.vendor, 
ulpi-id.product);
 
ret = device_register(ulpi-dev);
-   if (ret)
+   if (ret) {
+   put_device(ulpi-dev);
   
   If device_register returns failure, put_device has already been
   called. Check device_add in drivers/base/core.c.
  
  Yes, please read the function, which says:
   * NOTE: _Never_ directly free @dev after calling this function, even
   * if it returned an error! Always use put_device() to give up your
   * reference instead.
  
  But, the problem is that the ulpi core doesn't own that struct device.
  It comes from elsewhere.  It comes from somewhere deep down in the dw3
  core, which is where I lost the path.  Something needs to be fixed in
  dwc3_probe() to properly clean up the device if it fails, which is not
  happening right now.
  
  So this patch would actually cause much bigger problems than fixing
  anything, so it's wrong, but for a different reason than you are talking
  about here.
  
  And ugh, the ulpi and dwc code binding together, what a mess, horrid...
 
 any suggestions ? DWC *is* the one implementing the bus. If there's a
 better way, we can certainly shuffle code around.

As dwc is the only thing using the bus, why is it drivers/usb/core/ ?

And the error path here is broken, the bus should be creating the device
(i.e. no subsystem should ever be registering a device it did not
create), so that it can properly clean things up when stuff goes wrong.

The whole subsys_init() is also a bad feeling that it's not architected
correctly, that shouldn't be needed, which is why I never took that
patch.  Just noticed it came in through yours, I wanted it broken so
it would be fixed properly and not papered over like this.

thanks,

greg k-h
--
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


Re: [Patch V4 1/3] usb: Add Xen pvUSB protocol description

2015-07-22 Thread Juergen Gross

On 07/23/2015 01:46 AM, Greg KH wrote:

On Tue, Jun 23, 2015 at 08:53:23AM +0200, Juergen Gross wrote:

Add the definition of pvUSB protocol used between the pvUSB frontend in
a Xen domU and the pvUSB backend in a Xen driver domain (usually Dom0).

This header was originally provided by Fujitsu for Xen based on Linux
2.6.18.

Changes are:
- adapt to Linux style guide

Signed-off-by: Juergen Gross jgr...@suse.com
---
  include/xen/interface/io/usbif.h | 252 +++


Why is this a different interface than the existing ones we have today
(i.e. usbip?)  Where is it documented?  Do the Xen developers /


The interface definition is living in the Xen git repository for several
years now:

git://xenbits.xen.org/xen.git - xen/include/public/io/usbif.h

It is used e.g. in SUSE's xen kernel since 2.6.18.

The differences between the Xen version and the one I've posted here are
only style and name space related.


maintainers agree with this interface and code?  I need their sign-off
before I can accept such a thing.


Sure.

David, Konrad, Boris, could one of you please comment on the patches?


Juergen
--
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


Re: [Patch V4 1/3] usb: Add Xen pvUSB protocol description

2015-07-22 Thread Greg KH
On Thu, Jul 23, 2015 at 06:04:39AM +0200, Juergen Gross wrote:
 On 07/23/2015 01:46 AM, Greg KH wrote:
 On Tue, Jun 23, 2015 at 08:53:23AM +0200, Juergen Gross wrote:
 Add the definition of pvUSB protocol used between the pvUSB frontend in
 a Xen domU and the pvUSB backend in a Xen driver domain (usually Dom0).
 
 This header was originally provided by Fujitsu for Xen based on Linux
 2.6.18.
 
 Changes are:
 - adapt to Linux style guide
 
 Signed-off-by: Juergen Gross jgr...@suse.com
 ---
   include/xen/interface/io/usbif.h | 252 
  +++
 
 Why is this a different interface than the existing ones we have today
 (i.e. usbip?)  Where is it documented?  Do the Xen developers /
 
 The interface definition is living in the Xen git repository for several
 years now:
 
 git://xenbits.xen.org/xen.git - xen/include/public/io/usbif.h

That's header file, not a document describing the api here.

 It is used e.g. in SUSE's xen kernel since 2.6.18.

I am very aware of the amount of Xen crap in SuSE's kernel, don't use
that as an excuse for me to merge it to mainline :)

thanks,

greg k-h
--
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


Re: [PATCH v3 42/46] usb: gadget: move ep_matches() from epautoconf to udc-core

2015-07-22 Thread Petr Cvek
Hello,

Is this:

case USB_ENDPOINT_XFER_INT:
/* Bulk endpoints handle interrupt transfers,
 * except the toggle-quirky iso-synch kind
 */
if (!ep-caps.type_int  !ep-caps.type_bulk)
return 0;

... or original:

switch (type) {
case USB_ENDPOINT_XFER_INT:
/* bulk endpoints handle interrupt transfers,
 * except the toggle-quirky iso-synch kind
 */
if ('s' == tmp[2])  {// == -iso
return 0;

code still valid? 

It seems that it allows using a BULK endpoint for requested INT endpoint. For 
my PXA27x machine the original code returns BULK EP even with valid INT 
endpoint definition (because BULK EPs are defined earlier than INT EPs).

This part of the code is from pre git era

1da177e4c3f41524e886b7f1b8a0c1fc7321cac2

before pxa27x driver was written and only few chips was supported. Does anyone 
know if the INT endpoints works now?

Petr Cvek
--
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


Re: [PATCH] usb: ulpi: call put_device if device_register fails

2015-07-22 Thread Felipe Balbi
Hi,

On Wed, Jul 22, 2015 at 08:14:46PM -0700, Greg Kroah-Hartman wrote:
 On Wed, Jul 22, 2015 at 09:04:40PM -0500, Felipe Balbi wrote:
  On Wed, Jul 22, 2015 at 02:39:34PM -0700, Greg Kroah-Hartman wrote:
   On Tue, Jun 23, 2015 at 01:57:38PM +0300, Heikki Krogerus wrote:
On Fri, Jun 19, 2015 at 01:12:36AM +0800, ChengYi He wrote:
 put_device is required to release the last reference to the device.
 
 Signed-off-by: ChengYi He chengyihetai...@gmail.com
 ---
  drivers/usb/common/ulpi.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
 
 diff --git a/drivers/usb/common/ulpi.c b/drivers/usb/common/ulpi.c
 index 0e6f968..bd25bdb 100644
 --- a/drivers/usb/common/ulpi.c
 +++ b/drivers/usb/common/ulpi.c
 @@ -184,8 +184,10 @@ static int ulpi_register(struct device *dev, 
 struct ulpi *ulpi)
   request_module(ulpi:v%04xp%04x, ulpi-id.vendor, 
 ulpi-id.product);
  
   ret = device_register(ulpi-dev);
 - if (ret)
 + if (ret) {
 + put_device(ulpi-dev);

If device_register returns failure, put_device has already been
called. Check device_add in drivers/base/core.c.
   
   Yes, please read the function, which says:
* NOTE: _Never_ directly free @dev after calling this function, even
* if it returned an error! Always use put_device() to give up your
* reference instead.
   
   But, the problem is that the ulpi core doesn't own that struct device.
   It comes from elsewhere.  It comes from somewhere deep down in the dw3
   core, which is where I lost the path.  Something needs to be fixed in
   dwc3_probe() to properly clean up the device if it fails, which is not
   happening right now.
   
   So this patch would actually cause much bigger problems than fixing
   anything, so it's wrong, but for a different reason than you are talking
   about here.
   
   And ugh, the ulpi and dwc code binding together, what a mess, horrid...
  
  any suggestions ? DWC *is* the one implementing the bus. If there's a
  better way, we can certainly shuffle code around.
 
 As dwc is the only thing using the bus, why is it drivers/usb/core/ ?

musb also has a SW-accessible ULPI bus. And, IIRC, so does DWC2 ;-)

 And the error path here is broken, the bus should be creating the device
 (i.e. no subsystem should ever be registering a device it did not
 create), so that it can properly clean things up when stuff goes wrong.
 
 The whole subsys_init() is also a bad feeling that it's not architected
 correctly, that shouldn't be needed, which is why I never took that
 patch.  Just noticed it came in through yours, I wanted it broken so
 it would be fixed properly and not papered over like this.

I just felt it would be better to 'fix' it for the -rc until it can be
fixed *properly*. A follow up fix should incur no visible changes to
drivers anyway.

-- 
balbi


signature.asc
Description: Digital signature


[PATCH v8 09/23] usb: chipidea: update ci_otg_is_fsm_mode conditions

2015-07-22 Thread Li Jun
After introduce usb otg properties, update ci_otg_is_fsm_mode conditions
to be depending on both usb hardware properties and usb driver config,
also resolve a compile issue in debug.c after the API change.

Signed-off-by: Li Jun jun...@freescale.com
Acked-by: Peter Chen peter.c...@freescale.com
---
 drivers/usb/chipidea/ci.h| 5 -
 drivers/usb/chipidea/debug.c | 1 +
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h
index df57e49..63393e1 100644
--- a/drivers/usb/chipidea/ci.h
+++ b/drivers/usb/chipidea/ci.h
@@ -407,8 +407,11 @@ static inline u32 hw_test_and_write(struct ci_hdrc *ci, 
enum ci_hw_regs reg,
 static inline bool ci_otg_is_fsm_mode(struct ci_hdrc *ci)
 {
 #ifdef CONFIG_USB_OTG_FSM
+   struct usb_otg_caps *otg_caps = ci-platdata-ci_otg_caps;
+
return ci-is_otg  ci-roles[CI_ROLE_HOST] 
-   ci-roles[CI_ROLE_GADGET];
+   ci-roles[CI_ROLE_GADGET]  (otg_caps-srp_support ||
+   otg_caps-hnp_support || otg_caps-adp_support);
 #else
return false;
 #endif
diff --git a/drivers/usb/chipidea/debug.c b/drivers/usb/chipidea/debug.c
index 5b7061a..3869c6d 100644
--- a/drivers/usb/chipidea/debug.c
+++ b/drivers/usb/chipidea/debug.c
@@ -10,6 +10,7 @@
 #include linux/usb/phy.h
 #include linux/usb/otg.h
 #include linux/usb/otg-fsm.h
+#include linux/usb/chipidea.h
 
 #include ci.h
 #include udc.h
-- 
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


[PATCH v8 12/23] usb: gadget: ether: allocate and init otg descriptor by otg capabilities

2015-07-22 Thread Li Jun
Allocate and initialize usb otg descriptor according to gadget otg
capabilities, add it for each usb configurations, free it while
ether unbind. If otg capability is not defined, keep its otg
descriptor unchanged.

Signed-off-by: Li Jun jun...@freescale.com
Reviewed-by: Roger Quadros rog...@ti.com
---
 drivers/usb/gadget/legacy/ether.c | 36 
 1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/drivers/usb/gadget/legacy/ether.c 
b/drivers/usb/gadget/legacy/ether.c
index a3323dc..31e9160 100644
--- a/drivers/usb/gadget/legacy/ether.c
+++ b/drivers/usb/gadget/legacy/ether.c
@@ -171,20 +171,7 @@ static struct usb_device_descriptor device_desc = {
.bNumConfigurations =   1,
 };
 
-static struct usb_otg_descriptor otg_descriptor = {
-   .bLength =  sizeof otg_descriptor,
-   .bDescriptorType =  USB_DT_OTG,
-
-   /* REVISIT SRP-only hardware is possible, although
-* it would not be called OTG ...
-*/
-   .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
-};
-
-static const struct usb_descriptor_header *otg_desc[] = {
-   (struct usb_descriptor_header *) otg_descriptor,
-   NULL,
-};
+static const struct usb_descriptor_header *otg_desc[2];
 
 static struct usb_string strings_dev[] = {
[USB_GADGET_MANUFACTURER_IDX].s = ,
@@ -416,17 +403,28 @@ static int eth_bind(struct usb_composite_dev *cdev)
device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id;
device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
 
+   if (gadget_is_otg(gadget)  !otg_desc[0]) {
+   struct usb_descriptor_header *usb_desc;
+
+   usb_desc = usb_otg_descriptor_alloc(gadget);
+   if (!usb_desc)
+   goto fail1;
+   usb_otg_descriptor_init(gadget, usb_desc);
+   otg_desc[0] = usb_desc;
+   otg_desc[1] = NULL;
+   }
+
/* register our configuration(s); RNDIS first, if it's used */
if (has_rndis()) {
status = usb_add_config(cdev, rndis_config_driver,
rndis_do_config);
if (status  0)
-   goto fail1;
+   goto fail2;
}
 
status = usb_add_config(cdev, eth_config_driver, eth_do_config);
if (status  0)
-   goto fail1;
+   goto fail2;
 
usb_composite_overwrite_options(cdev, coverwrite);
dev_info(gadget-dev, %s, version:  DRIVER_VERSION \n,
@@ -434,6 +432,9 @@ static int eth_bind(struct usb_composite_dev *cdev)
 
return 0;
 
+fail2:
+   kfree(otg_desc[0]);
+   otg_desc[0] = NULL;
 fail1:
if (has_rndis())
usb_put_function_instance(fi_rndis);
@@ -463,6 +464,9 @@ static int eth_unbind(struct usb_composite_dev *cdev)
usb_put_function(f_geth);
usb_put_function_instance(fi_geth);
}
+   kfree(otg_desc[0]);
+   otg_desc[0] = NULL;
+
return 0;
 }
 
-- 
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


[PATCH v8 04/23] usb: add usb_otg_caps to usb_gadget structure.

2015-07-22 Thread Li Jun
From: Macpaul Lin macp...@gmail.com

Add usb_otg_caps pointer to usb_gadget structure to indicate its
otg capabilities.

Signed-off-by: Macpaul Lin macp...@gmail.com
Signed-off-by: Li Jun jun...@freescale.com
Reviewed-by: Roger Quadros rog...@ti.com
---
 include/linux/usb/gadget.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 4f3dfb7..6b39087 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -511,6 +511,7 @@ struct usb_gadget_ops {
  * @dev: Driver model state for this abstract device.
  * @out_epnum: last used out ep number
  * @in_epnum: last used in ep number
+ * @otg_caps: OTG capabilities of this gadget.
  * @sg_supported: true if we can handle scatter-gather
  * @is_otg: True if the USB device port uses a Mini-AB jack, so that the
  * gadget driver must provide a USB OTG descriptor.
@@ -559,6 +560,7 @@ struct usb_gadget {
struct device   dev;
unsignedout_epnum;
unsignedin_epnum;
+   struct usb_otg_caps *otg_caps;
 
unsignedsg_supported:1;
unsignedis_otg:1;
-- 
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


[PATCH v8 07/23] usb: common: add API to update usb otg capabilities by device tree

2015-07-22 Thread Li Jun
Check property of usb hardware to update otg version and disable SRP, HNP
and ADP if its disable flag is present.

Signed-off-by: Li Jun jun...@freescale.com
Reviewed-by: Roger Quadros rog...@ti.com
---
 drivers/usb/common/common.c | 56 +
 include/linux/usb/of.h  |  7 ++
 2 files changed, 63 insertions(+)

diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c
index b530fd4..9e39286 100644
--- a/drivers/usb/common/common.c
+++ b/drivers/usb/common/common.c
@@ -154,6 +154,62 @@ bool of_usb_host_tpl_support(struct device_node *np)
return false;
 }
 EXPORT_SYMBOL_GPL(of_usb_host_tpl_support);
+
+/**
+ * of_usb_update_otg_caps - to update usb otg capabilities according to
+ * the passed properties in DT.
+ * @np: Pointer to the given device_node
+ * @otg_caps: Pointer to the target usb_otg_caps to be set
+ *
+ * The function updates the otg capabilities
+ */
+int of_usb_update_otg_caps(struct device_node *np,
+   struct usb_otg_caps *otg_caps)
+{
+   u32 otg_rev;
+
+   if (!otg_caps)
+   return -EINVAL;
+
+   if (!of_property_read_u32(np, otg-rev, otg_rev)) {
+   switch (otg_rev) {
+   case 0x0100:
+   case 0x0120:
+   case 0x0130:
+   case 0x0200:
+   /* Choose the lesser one if it's already been set */
+   if (otg_caps-otg_rev)
+   otg_caps-otg_rev = min_t(u16, otg_rev,
+   otg_caps-otg_rev);
+   else
+   otg_caps-otg_rev = otg_rev;
+   break;
+   default:
+   pr_err(%s: unsupported otg-rev: 0x%x\n,
+   np-full_name, otg_rev);
+   return -EINVAL;
+   }
+   } else {
+   /*
+* otg-rev is mandatory for otg properties, if not passed
+* we set it to be 0 and assume it's a legacy otg device.
+* Non-dt platform can set it afterwards.
+*/
+   otg_caps-otg_rev = 0;
+   }
+
+   if (of_find_property(np, hnp-disable, NULL))
+   otg_caps-hnp_support = false;
+   if (of_find_property(np, srp-disable, NULL))
+   otg_caps-srp_support = false;
+   if (of_find_property(np, adp-disable, NULL) ||
+   (otg_caps-otg_rev  0x0200))
+   otg_caps-adp_support = false;
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(of_usb_update_otg_caps);
+
 #endif
 
 MODULE_LICENSE(GPL);
diff --git a/include/linux/usb/of.h b/include/linux/usb/of.h
index cfe0528..8c5a818 100644
--- a/include/linux/usb/of.h
+++ b/include/linux/usb/of.h
@@ -15,6 +15,8 @@
 enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np);
 enum usb_device_speed of_usb_get_maximum_speed(struct device_node *np);
 bool of_usb_host_tpl_support(struct device_node *np);
+int of_usb_update_otg_caps(struct device_node *np,
+   struct usb_otg_caps *otg_caps);
 #else
 static inline enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np)
 {
@@ -30,6 +32,11 @@ static inline bool of_usb_host_tpl_support(struct 
device_node *np)
 {
return false;
 }
+static inline int of_usb_update_otg_caps(struct device_node *np,
+   struct usb_otg_caps *otg_caps)
+{
+   return 0;
+}
 #endif
 
 #if IS_ENABLED(CONFIG_OF)  IS_ENABLED(CONFIG_USB_SUPPORT)
-- 
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


[PATCH v8 08/23] usb: chipidea: set usb otg capabilities

2015-07-22 Thread Li Jun
Init and update otg capabilities by DT, set gadget's otg capabilities
accordingly.

Signed-off-by: Li Jun jun...@freescale.com
Reviewed-by: Roger Quadros rog...@ti.com
Acked-by: Peter Chen peter.c...@freescale.com
---
 drivers/usb/chipidea/core.c  | 15 +++
 drivers/usb/chipidea/udc.c   |  7 ++-
 include/linux/usb/chipidea.h |  1 +
 3 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
index 40cdd5e..d1f462b 100644
--- a/drivers/usb/chipidea/core.c
+++ b/drivers/usb/chipidea/core.c
@@ -562,6 +562,8 @@ static irqreturn_t ci_irq(int irq, void *data)
 static int ci_get_platdata(struct device *dev,
struct ci_hdrc_platform_data *platdata)
 {
+   int ret;
+
if (!platdata-phy_mode)
platdata-phy_mode = of_usb_get_phy_mode(dev-of_node);
 
@@ -590,6 +592,19 @@ static int ci_get_platdata(struct device *dev,
of_usb_host_tpl_support(dev-of_node);
}
 
+   if (platdata-dr_mode == USB_DR_MODE_OTG) {
+   /* We can support HNP and SRP of OTG 2.0 */
+   platdata-ci_otg_caps.otg_rev = 0x0200;
+   platdata-ci_otg_caps.hnp_support = true;
+   platdata-ci_otg_caps.srp_support = true;
+
+   /* Update otg capabilities by DT properties */
+   ret = of_usb_update_otg_caps(dev-of_node,
+   platdata-ci_otg_caps);
+   if (ret)
+   return ret;
+   }
+
if (of_usb_get_maximum_speed(dev-of_node) == USB_SPEED_FULL)
platdata-flags |= CI_HDRC_FORCE_FULLSPEED;
 
diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
index 764f668..f5fbe78 100644
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -1827,6 +1827,7 @@ static irqreturn_t udc_irq(struct ci_hdrc *ci)
 static int udc_start(struct ci_hdrc *ci)
 {
struct device *dev = ci-dev;
+   struct usb_otg_caps *otg_caps = ci-platdata-ci_otg_caps;
int retval = 0;
 
spin_lock_init(ci-lock);
@@ -1834,8 +1835,12 @@ static int udc_start(struct ci_hdrc *ci)
ci-gadget.ops  = usb_gadget_ops;
ci-gadget.speed= USB_SPEED_UNKNOWN;
ci-gadget.max_speed= USB_SPEED_HIGH;
-   ci-gadget.is_otg   = ci-is_otg ? 1 : 0;
ci-gadget.name = ci-platdata-name;
+   ci-gadget.otg_caps = otg_caps;
+
+   if (ci-is_otg  (otg_caps-hnp_support || otg_caps-srp_support ||
+   otg_caps-adp_support))
+   ci-gadget.is_otg = 1;
 
INIT_LIST_HEAD(ci-gadget.ep_list);
 
diff --git a/include/linux/usb/chipidea.h b/include/linux/usb/chipidea.h
index d1e1285..7d4d33c 100644
--- a/include/linux/usb/chipidea.h
+++ b/include/linux/usb/chipidea.h
@@ -35,6 +35,7 @@ struct ci_hdrc_platform_data {
 #define CI_HDRC_CONTROLLER_STOPPED_EVENT   1
void(*notify_event) (struct ci_hdrc *ci, unsigned event);
struct regulator*reg_vbus;
+   struct usb_otg_caps ci_otg_caps;
booltpl_support;
 };
 
-- 
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


[PATCH v8 10/23] usb: gadget: add usb otg descriptor allocate and init interface

2015-07-22 Thread Li Jun
Allocate usb otg descriptor and initialize it according to gadget's otg
capabilities, if usb_otg_caps is not set, keep settings as current gadget
drivers. With this 2 new interfaces, gadget can use usb_otg_descriptor
for OTG 1.x, and usb_otg20_descriptor for OTG 2.0 or above, and otg
features can be decided by the combination of usb hardware property
and driver config.

Signed-off-by: Li Jun jun...@freescale.com
Reviewed-by: Roger Quadros rog...@ti.com
---
 drivers/usb/gadget/config.c | 56 +
 include/linux/usb/gadget.h  |  4 
 2 files changed, 60 insertions(+)

diff --git a/drivers/usb/gadget/config.c b/drivers/usb/gadget/config.c
index 34e12fc..0fafa7a 100644
--- a/drivers/usb/gadget/config.c
+++ b/drivers/usb/gadget/config.c
@@ -20,6 +20,7 @@
 #include linux/usb/ch9.h
 #include linux/usb/gadget.h
 #include linux/usb/composite.h
+#include linux/usb/otg.h
 
 /**
  * usb_descriptor_fillbuf - fill buffer with descriptors
@@ -195,3 +196,58 @@ void usb_free_all_descriptors(struct usb_function *f)
usb_free_descriptors(f-ss_descriptors);
 }
 EXPORT_SYMBOL_GPL(usb_free_all_descriptors);
+
+struct usb_descriptor_header *usb_otg_descriptor_alloc(
+   struct usb_gadget *gadget)
+{
+   struct usb_descriptor_header *otg_desc;
+   unsigned length = 0;
+
+   if (gadget-otg_caps  (gadget-otg_caps-otg_rev = 0x0200))
+   length = sizeof(struct usb_otg20_descriptor);
+   else
+   length = sizeof(struct usb_otg_descriptor);
+
+   otg_desc = kzalloc(length, GFP_KERNEL);
+   return otg_desc;
+}
+EXPORT_SYMBOL_GPL(usb_otg_descriptor_alloc);
+
+int usb_otg_descriptor_init(struct usb_gadget *gadget,
+   struct usb_descriptor_header *otg_desc)
+{
+   struct usb_otg_descriptor *otg1x_desc;
+   struct usb_otg20_descriptor *otg20_desc;
+   struct usb_otg_caps *otg_caps = gadget-otg_caps;
+   u8 otg_attributes = 0;
+
+   if (!otg_desc)
+   return -EINVAL;
+
+   if (otg_caps  otg_caps-otg_rev) {
+   if (otg_caps-hnp_support)
+   otg_attributes |= USB_OTG_HNP;
+   if (otg_caps-srp_support)
+   otg_attributes |= USB_OTG_SRP;
+   if (otg_caps-adp_support  (otg_caps-otg_rev = 0x0200))
+   otg_attributes |= USB_OTG_ADP;
+   } else {
+   otg_attributes = USB_OTG_SRP | USB_OTG_HNP;
+   }
+
+   if (otg_caps  (otg_caps-otg_rev = 0x0200)) {
+   otg20_desc = (struct usb_otg20_descriptor *)otg_desc;
+   otg20_desc-bLength = sizeof(struct usb_otg20_descriptor);
+   otg20_desc-bDescriptorType = USB_DT_OTG;
+   otg20_desc-bmAttributes = otg_attributes;
+   otg20_desc-bcdOTG = cpu_to_le16(otg_caps-otg_rev);
+   } else {
+   otg1x_desc = (struct usb_otg_descriptor *)otg_desc;
+   otg1x_desc-bLength = sizeof(struct usb_otg_descriptor);
+   otg1x_desc-bDescriptorType = USB_DT_OTG;
+   otg1x_desc-bmAttributes = otg_attributes;
+   }
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(usb_otg_descriptor_init);
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 6b39087..5f65bd2 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -1004,6 +1004,10 @@ int usb_assign_descriptors(struct usb_function *f,
struct usb_descriptor_header **ss);
 void usb_free_all_descriptors(struct usb_function *f);
 
+struct usb_descriptor_header *usb_otg_descriptor_alloc(
+   struct usb_gadget *gadget);
+int usb_otg_descriptor_init(struct usb_gadget *gadget,
+   struct usb_descriptor_header *otg_desc);
 /*-*/
 
 /* utility to simplify map/unmap of usb_requests to/from DMA */
-- 
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


[PATCH v8 05/23] usb: gadget: composite: add USB_DT_OTG request handling

2015-07-22 Thread Li Jun
From: Macpaul Lin macp...@gmail.com

Copy usb_otg_descriptor from config's descriptor if host requests
USB_DT_OTG.

Signed-off-by: Macpaul Lin macp...@gmail.com
Signed-off-by: Li Jun jun...@freescale.com
Reviewed-by: Roger Quadros rog...@ti.com
---
 drivers/usb/gadget/composite.c | 27 +++
 1 file changed, 27 insertions(+)

diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 4e3447b..2c1c6eb 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -19,6 +19,7 @@
 #include linux/utsname.h
 
 #include linux/usb/composite.h
+#include linux/usb/otg.h
 #include asm/unaligned.h
 
 #include u_os_desc.h
@@ -1534,6 +1535,32 @@ composite_setup(struct usb_gadget *gadget, const struct 
usb_ctrlrequest *ctrl)
value = min(w_length, (u16) value);
}
break;
+   case USB_DT_OTG:
+   if (gadget_is_otg(gadget)) {
+   struct usb_configuration *config;
+   int otg_desc_len = 0;
+
+   if (cdev-config)
+   config = cdev-config;
+   else
+   config = list_first_entry(
+   cdev-configs,
+   struct usb_configuration, list);
+   if (!config)
+   goto done;
+
+   if (gadget-otg_caps 
+   (gadget-otg_caps-otg_rev = 0x0200))
+   otg_desc_len += sizeof(
+   struct usb_otg20_descriptor);
+   else
+   otg_desc_len += sizeof(
+   struct usb_otg_descriptor);
+
+   value = min_t(int, w_length, otg_desc_len);
+   memcpy(req-buf, config-descriptors[0], value);
+   }
+   break;
}
break;
 
-- 
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


[PATCH v8 03/23] usb: otg: add usb_otg_caps structure for otg capabilities

2015-07-22 Thread Li Jun
This patch adds a structure usb_otg_caps to cover all otg related
capabilities of the device, including otg revision, and if hnp/srp/adp
is supported.

Signed-off-by: Li Jun jun...@freescale.com
Reviewed-by: Roger Quadros rog...@ti.com
---
 include/linux/usb/otg.h | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h
index 52661c5..bd1dcf8 100644
--- a/include/linux/usb/otg.h
+++ b/include/linux/usb/otg.h
@@ -41,6 +41,21 @@ struct usb_otg {
 
 };
 
+/**
+ * struct usb_otg_caps - describes the otg capabilities of the device
+ * @otg_rev: The OTG revision number the device is compliant with, it's
+ * in binary-coded decimal (i.e. 2.0 is 0200H).
+ * @hnp_support: Indicates if the device supports HNP.
+ * @srp_support: Indicates if the device supports SRP.
+ * @adp_support: Indicates if the device supports ADP.
+ */
+struct usb_otg_caps {
+   u16 otg_rev;
+   bool hnp_support;
+   bool srp_support;
+   bool adp_support;
+};
+
 extern const char *usb_otg_state_string(enum usb_otg_state state);
 
 /* Context: can sleep */
-- 
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


[PATCH v8 01/23] usb: add usb_otg20_descriptor for OTG 2.0 and above

2015-07-22 Thread Li Jun
From: Macpaul Lin macp...@gmail.com

OTG 2.0 introduces bcdOTG in otg descriptor to identify the OTG and EH
supplement release number with which the OTG device is compliant, this
patch adds structure usb_otg20_descriptor for OTG 2.0 and above.

Signed-off-by: Macpaul Lin macp...@gmail.com
Signed-off-by: Li Jun jun...@freescale.com
Reviewed-by: Roger Quadros rog...@ti.com
---
 include/uapi/linux/usb/ch9.h | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/include/uapi/linux/usb/ch9.h b/include/uapi/linux/usb/ch9.h
index aa33fd1..aec6899 100644
--- a/include/uapi/linux/usb/ch9.h
+++ b/include/uapi/linux/usb/ch9.h
@@ -674,6 +674,17 @@ struct usb_otg_descriptor {
__u8  bmAttributes; /* support for HNP, SRP, etc */
 } __attribute__ ((packed));
 
+/* USB_DT_OTG (from OTG 2.0 supplement) */
+struct usb_otg20_descriptor {
+   __u8  bLength;
+   __u8  bDescriptorType;
+
+   __u8  bmAttributes; /* support for HNP, SRP and ADP, etc */
+   __le16 bcdOTG;  /* OTG and EH supplement release number
+* in binary-coded decimal(i.e. 2.0 is 0200H)
+*/
+} __attribute__ ((packed));
+
 /* from usb_otg_descriptor.bmAttributes */
 #define USB_OTG_SRP(1  0)
 #define USB_OTG_HNP(1  1)/* swap host/device roles */
-- 
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


[PATCH v8 06/23] doc: dt-binding: usb: add otg related properties

2015-07-22 Thread Li Jun
Add otg version, srp, hnp and adp support for usb OTG port, then those OTG
features don't have to be decided by usb gadget drivers.

Signed-off-by: Li Jun jun...@freescale.com
Reviewed-by: Roger Quadros rog...@ti.com
---
 Documentation/devicetree/bindings/usb/generic.txt | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/Documentation/devicetree/bindings/usb/generic.txt 
b/Documentation/devicetree/bindings/usb/generic.txt
index 477d5bb..bba8257 100644
--- a/Documentation/devicetree/bindings/usb/generic.txt
+++ b/Documentation/devicetree/bindings/usb/generic.txt
@@ -11,6 +11,19 @@ Optional properties:
peripheral and otg. In case this attribute isn't
passed via DT, USB DRD controllers should default to
OTG.
+ - otg-rev: tells usb driver the release number of the OTG and EH supplement
+   with which the device and its descriptors are compliant,
+   in binary-coded decimal (i.e. 2.0 is 0200H). This
+   property is used if any real OTG features(HNP/SRP/ADP)
+   is enabled, if ADP is required, otg-rev should be
+   0x0200 or above.
+ - hnp-disable: tells OTG controllers we want to disable OTG HNP, normally HNP
+   is the basic function of real OTG except you want it
+   to be a srp-capable only B device.
+ - srp-disable: tells OTG controllers we want to disable OTG SRP, SRP is
+   optional for OTG device.
+ - adp-disable: tells OTG controllers we want to disable OTG ADP, ADP is
+   optional for OTG device.
 
 This is an attribute to a USB controller such as:
 
@@ -21,4 +34,6 @@ dwc3@4a03 {
usb-phy = usb2_phy, usb3,phy;
maximum-speed = super-speed;
dr_mode = otg;
+   otg-rev = 0x0200;
+   adp-disable;
 };
-- 
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


[PATCH v8 02/23] usb: add USB_OTG_ADP definition

2015-07-22 Thread Li Jun
From: Macpaul Lin macp...@gmail.com

Add USB_OTG_ADP definition for usb_otg_descriptor.bmAttributes.

Signed-off-by: Macpaul Lin macp...@gmail.com
Signed-off-by: Li Jun jun...@freescale.com
Acked-by: Peter Chen peter.c...@freescale.com
---
 include/uapi/linux/usb/ch9.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/uapi/linux/usb/ch9.h b/include/uapi/linux/usb/ch9.h
index aec6899..f7adc6e 100644
--- a/include/uapi/linux/usb/ch9.h
+++ b/include/uapi/linux/usb/ch9.h
@@ -688,6 +688,7 @@ struct usb_otg20_descriptor {
 /* from usb_otg_descriptor.bmAttributes */
 #define USB_OTG_SRP(1  0)
 #define USB_OTG_HNP(1  1)/* swap host/device roles */
+#define USB_OTG_ADP(1  2)/* support ADP */
 
 /*-*/
 
-- 
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


[PATCH v8 11/23] usb: gadget: configfs: allocate and init otg descriptor by otg capabilities

2015-07-22 Thread Li Jun
Allocate and initialize usb otg descriptor according to gadget otg
capabilities, add it for each usb configurations, free it while
composite unbind. If otg capability is not defined, keep its otg
descriptor unchanged.

Signed-off-by: Li Jun jun...@freescale.com
Reviewed-by: Roger Quadros rog...@ti.com
---
 drivers/usb/gadget/configfs.c | 29 -
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c
index 0495c94..c7b62ef 100644
--- a/drivers/usb/gadget/configfs.c
+++ b/drivers/usb/gadget/configfs.c
@@ -41,6 +41,8 @@ int check_user_usb_string(const char *name,
 #define MAX_NAME_LEN   40
 #define MAX_USB_STRING_LANGS 2
 
+static const struct usb_descriptor_header *otg_desc[2];
+
 struct gadget_info {
struct config_group group;
struct config_group functions_group;
@@ -55,9 +57,6 @@ struct gadget_info {
struct list_head available_func;
 
const char *udc_name;
-#ifdef CONFIG_USB_OTG
-   struct usb_otg_descriptor otg;
-#endif
struct usb_composite_driver composite;
struct usb_composite_dev cdev;
bool use_os_desc;
@@ -1376,6 +1375,19 @@ static int configfs_composite_bind(struct usb_gadget 
*gadget,
memcpy(cdev-qw_sign, gi-qw_sign, OS_STRING_QW_SIGN_LEN);
}
 
+   if (gadget_is_otg(gadget)  !otg_desc[0]) {
+   struct usb_descriptor_header *usb_desc;
+
+   usb_desc = usb_otg_descriptor_alloc(gadget);
+   if (!usb_desc) {
+   ret = -ENOMEM;
+   goto err_comp_cleanup;
+   }
+   usb_otg_descriptor_init(gadget, usb_desc);
+   otg_desc[0] = usb_desc;
+   otg_desc[1] = NULL;
+   }
+
/* Go through all configs, attach all functions */
list_for_each_entry(c, gi-cdev.configs, list) {
struct config_usb_cfg *cfg;
@@ -1383,6 +1395,9 @@ static int configfs_composite_bind(struct usb_gadget 
*gadget,
struct usb_function *tmp;
struct gadget_config_name *cn;
 
+   if (gadget_is_otg(gadget))
+   c-descriptors = otg_desc;
+
cfg = container_of(c, struct config_usb_cfg, c);
if (!list_empty(cfg-string_list)) {
i = 0;
@@ -1437,6 +1452,8 @@ static void configfs_composite_unbind(struct usb_gadget 
*gadget)
cdev = get_gadget_data(gadget);
gi = container_of(cdev, struct gadget_info, cdev);
 
+   kfree(otg_desc[0]);
+   otg_desc[0] = NULL;
purge_configs_funcs(gi);
composite_dev_cleanup(cdev);
usb_ep_autoconfig_reset(cdev-gadget);
@@ -1510,12 +1527,6 @@ static struct config_group *gadgets_make(
if (!gi-composite.gadget_driver.function)
goto err;
 
-#ifdef CONFIG_USB_OTG
-   gi-otg.bLength = sizeof(struct usb_otg_descriptor);
-   gi-otg.bDescriptorType = USB_DT_OTG;
-   gi-otg.bmAttributes = USB_OTG_SRP | USB_OTG_HNP;
-#endif
-
config_group_init_type_name(gi-group, name,
gadget_root_type);
return gi-group;
-- 
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


[PATCH v8 13/23] usb: gadget: acm_ms: allocate and init otg descriptor by otg capabilities

2015-07-22 Thread Li Jun
Allocate and initialize usb otg descriptor according to gadget otg
capabilities, add it for each usb configurations. If otg capability
is not defined, keep its original otg descriptor unchanged.

Signed-off-by: Li Jun jun...@freescale.com
Reviewed-by: Roger Quadros rog...@ti.com
---
 drivers/usb/gadget/legacy/acm_ms.c | 35 +++
 1 file changed, 19 insertions(+), 16 deletions(-)

diff --git a/drivers/usb/gadget/legacy/acm_ms.c 
b/drivers/usb/gadget/legacy/acm_ms.c
index 1194b09..4d8adb4 100644
--- a/drivers/usb/gadget/legacy/acm_ms.c
+++ b/drivers/usb/gadget/legacy/acm_ms.c
@@ -58,21 +58,7 @@ static struct usb_device_descriptor device_desc = {
/*.bNumConfigurations = DYNAMIC*/
 };
 
-static struct usb_otg_descriptor otg_descriptor = {
-   .bLength =  sizeof otg_descriptor,
-   .bDescriptorType =  USB_DT_OTG,
-
-   /*
-* REVISIT SRP-only hardware is possible, although
-* it would not be called OTG ...
-*/
-   .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
-};
-
-static const struct usb_descriptor_header *otg_desc[] = {
-   (struct usb_descriptor_header *) otg_descriptor,
-   NULL,
-};
+static const struct usb_descriptor_header *otg_desc[2];
 
 /* string IDs are assigned dynamically */
 static struct usb_string strings_dev[] = {
@@ -225,10 +211,21 @@ static int acm_ms_bind(struct usb_composite_dev *cdev)
device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id;
device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
 
+   if (gadget_is_otg(gadget)  !otg_desc[0]) {
+   struct usb_descriptor_header *usb_desc;
+
+   usb_desc = usb_otg_descriptor_alloc(gadget);
+   if (!usb_desc)
+   goto fail_string_ids;
+   usb_otg_descriptor_init(gadget, usb_desc);
+   otg_desc[0] = usb_desc;
+   otg_desc[1] = NULL;
+   }
+
/* register our configuration */
status = usb_add_config(cdev, acm_ms_config_driver, acm_ms_do_config);
if (status  0)
-   goto fail_string_ids;
+   goto fail_otg_desc;
 
usb_composite_overwrite_options(cdev, coverwrite);
dev_info(gadget-dev, %s, version:  DRIVER_VERSION \n,
@@ -236,6 +233,9 @@ static int acm_ms_bind(struct usb_composite_dev *cdev)
return 0;
 
/* error recovery */
+fail_otg_desc:
+   kfree(otg_desc[0]);
+   otg_desc[0] = NULL;
 fail_string_ids:
fsg_common_remove_luns(opts-common);
 fail_set_cdev:
@@ -255,6 +255,9 @@ static int acm_ms_unbind(struct usb_composite_dev *cdev)
usb_put_function_instance(fi_msg);
usb_put_function(f_acm);
usb_put_function_instance(f_acm_inst);
+   kfree(otg_desc[0]);
+   otg_desc[0] = NULL;
+
return 0;
 }
 
-- 
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


[PATCH v8 00/23] usb gadget update for OTG 2.0

2015-07-22 Thread Li Jun
Change for v8:
- Add Peter's ACk for chipidea driver; and Roger's Reviewed-by for patch
  07, 21~23.
- Add ci-is_otg condition before enable ci-gadget.is_otg for chipidea
  driver in patch 8.

Change for v7:
- Free otg descriptor when failure of bind in patch 21, 22, 23.
  add Roger's Reviewed-by for patch 10~20.
- Choose the lesser otg-rev if otg-rev has been set before update by DT,
  remove 0x0300 in supported otg-rev list, and add code comments in case
  otg-rev is not passed in DT in patch 7.
- Fail chipidea usb initilization if DT pass an unsupported otg-rev in patch 8.

Li Jun (19):
  usb: otg: add usb_otg_caps structure for otg capabilities
  doc: dt-binding: usb: add otg related properties
  usb: common: add API to update usb otg capabilities by device tree
  usb: chipidea: set usb otg capabilities
  usb: chipidea: update ci_otg_is_fsm_mode conditions
  usb: gadget: add usb otg descriptor allocate and init interface
  usb: gadget: configfs: allocate and init otg descriptor by otg
capabilities
  usb: gadget: ether: allocate and init otg descriptor by otg
capabilities
  usb: gadget: acm_ms: allocate and init otg descriptor by otg
capabilities
  usb: gadget: audio: allocate and init otg descriptor by otg
capabilities
  usb: gadget: cdc2: allocate and init otg descriptor by otg
capabilities
  usb: gadget: g_ffs: allocate and init otg descriptor by otg
capabilities
  usb: gadget: hid: allocate and init otg descriptor by otg capabilities
  usb: gadget: mass_storage: allocate and init otg descriptor by otg
capabilities
  usb: gadget: multi: allocate and init otg descriptor by otg
capabilities
  usb: gadget: ncm: allocate and init otg descriptor by otg capabilities
  usb: gadget: printer: allocate and init otg descriptor by otg
capabilities
  usb: gadget: serial: allocate and init otg descriptor by otg
capabilities
  usb: gadget: zero: allocate and init otg descriptor by otg
capabilities

Macpaul Lin (4):
  usb: add usb_otg20_descriptor for OTG 2.0 and above
  usb: add USB_OTG_ADP definition
  usb: add usb_otg_caps to usb_gadget structure.
  usb: gadget: composite: add USB_DT_OTG request handling

 Documentation/devicetree/bindings/usb/generic.txt | 15 ++
 drivers/usb/chipidea/ci.h |  5 +-
 drivers/usb/chipidea/core.c   | 15 ++
 drivers/usb/chipidea/debug.c  |  1 +
 drivers/usb/chipidea/udc.c|  7 ++-
 drivers/usb/common/common.c   | 56 +++
 drivers/usb/gadget/composite.c| 27 +++
 drivers/usb/gadget/config.c   | 56 +++
 drivers/usb/gadget/configfs.c | 29 
 drivers/usb/gadget/legacy/acm_ms.c| 35 +++---
 drivers/usb/gadget/legacy/audio.c | 34 --
 drivers/usb/gadget/legacy/cdc2.c  | 35 +++---
 drivers/usb/gadget/legacy/ether.c | 36 ---
 drivers/usb/gadget/legacy/g_ffs.c | 32 +++--
 drivers/usb/gadget/legacy/hid.c   | 36 ---
 drivers/usb/gadget/legacy/mass_storage.c  | 35 +++---
 drivers/usb/gadget/legacy/multi.c | 37 ---
 drivers/usb/gadget/legacy/ncm.c   | 34 --
 drivers/usb/gadget/legacy/printer.c   | 49 
 drivers/usb/gadget/legacy/serial.c| 37 ---
 drivers/usb/gadget/legacy/zero.c  | 41 +
 include/linux/usb/chipidea.h  |  1 +
 include/linux/usb/gadget.h|  6 +++
 include/linux/usb/of.h|  7 +++
 include/linux/usb/otg.h   | 15 ++
 include/uapi/linux/usb/ch9.h  | 12 +
 26 files changed, 485 insertions(+), 208 deletions(-)

-- 
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


[PATCH v8 23/23] usb: gadget: zero: allocate and init otg descriptor by otg capabilities

2015-07-22 Thread Li Jun
Allocate and initialize usb otg descriptor according to gadget otg
capabilities, add it for each usb configurations. If otg capability
is not defined, keep its original otg descriptor unchanged.

Signed-off-by: Li Jun jun...@freescale.com
Reviewed-by: Roger Quadros rog...@ti.com
---
 drivers/usb/gadget/legacy/zero.c | 41 
 1 file changed, 21 insertions(+), 20 deletions(-)

diff --git a/drivers/usb/gadget/legacy/zero.c b/drivers/usb/gadget/legacy/zero.c
index c986e8a..37a4100 100644
--- a/drivers/usb/gadget/legacy/zero.c
+++ b/drivers/usb/gadget/legacy/zero.c
@@ -121,24 +121,7 @@ static struct usb_device_descriptor device_desc = {
.bNumConfigurations =   2,
 };
 
-#ifdef CONFIG_USB_OTG
-static struct usb_otg_descriptor otg_descriptor = {
-   .bLength =  sizeof otg_descriptor,
-   .bDescriptorType =  USB_DT_OTG,
-
-   /* REVISIT SRP-only hardware is possible, although
-* it would not be called OTG ...
-*/
-   .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
-};
-
-static const struct usb_descriptor_header *otg_desc[] = {
-   (struct usb_descriptor_header *) otg_descriptor,
-   NULL,
-};
-#else
-#define otg_desc   NULL
-#endif
+static const struct usb_descriptor_header *otg_desc[2];
 
 /* string IDs are assigned dynamically */
 /* default serial number takes at least two packets */
@@ -341,6 +324,18 @@ static int zero_bind(struct usb_composite_dev *cdev)
 
/* support OTG systems */
if (gadget_is_otg(cdev-gadget)) {
+   if (!otg_desc[0]) {
+   struct usb_descriptor_header *usb_desc;
+
+   usb_desc = usb_otg_descriptor_alloc(cdev-gadget);
+   if (!usb_desc) {
+   status = -ENOMEM;
+   goto err_conf_flb;
+   }
+   usb_otg_descriptor_init(cdev-gadget, usb_desc);
+   otg_desc[0] = usb_desc;
+   otg_desc[1] = NULL;
+   }
sourcesink_driver.descriptors = otg_desc;
sourcesink_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
loopback_driver.descriptors = otg_desc;
@@ -359,12 +354,12 @@ static int zero_bind(struct usb_composite_dev *cdev)
}
status = usb_add_function(sourcesink_driver, func_ss);
if (status)
-   goto err_conf_flb;
+   goto err_free_otg_desc;
 
usb_ep_autoconfig_reset(cdev-gadget);
status = usb_add_function(loopback_driver, func_lb);
if (status)
-   goto err_conf_flb;
+   goto err_free_otg_desc;
 
usb_ep_autoconfig_reset(cdev-gadget);
usb_composite_overwrite_options(cdev, coverwrite);
@@ -373,6 +368,9 @@ static int zero_bind(struct usb_composite_dev *cdev)
 
return 0;
 
+err_free_otg_desc:
+   kfree(otg_desc[0]);
+   otg_desc[0] = NULL;
 err_conf_flb:
usb_put_function(func_lb);
func_lb = NULL;
@@ -397,6 +395,9 @@ static int zero_unbind(struct usb_composite_dev *cdev)
if (!IS_ERR_OR_NULL(func_lb))
usb_put_function(func_lb);
usb_put_function_instance(func_inst_lb);
+   kfree(otg_desc[0]);
+   otg_desc[0] = NULL;
+
return 0;
 }
 
-- 
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


[PATCH v8 17/23] usb: gadget: hid: allocate and init otg descriptor by otg capabilities

2015-07-22 Thread Li Jun
Allocate and initialize usb otg descriptor according to gadget otg
capabilities, add it for each usb configurations. If otg capability
is not defined, keep its original otg descriptor unchanged.

Signed-off-by: Li Jun jun...@freescale.com
Reviewed-by: Roger Quadros rog...@ti.com
---
 drivers/usb/gadget/legacy/hid.c | 36 
 1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/drivers/usb/gadget/legacy/hid.c b/drivers/usb/gadget/legacy/hid.c
index 2baa572..e4874d3 100644
--- a/drivers/usb/gadget/legacy/hid.c
+++ b/drivers/usb/gadget/legacy/hid.c
@@ -68,21 +68,7 @@ static struct usb_device_descriptor device_desc = {
.bNumConfigurations =   1,
 };
 
-static struct usb_otg_descriptor otg_descriptor = {
-   .bLength =  sizeof otg_descriptor,
-   .bDescriptorType =  USB_DT_OTG,
-
-   /* REVISIT SRP-only hardware is possible, although
-* it would not be called OTG ...
-*/
-   .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
-};
-
-static const struct usb_descriptor_header *otg_desc[] = {
-   (struct usb_descriptor_header *) otg_descriptor,
-   NULL,
-};
-
+static const struct usb_descriptor_header *otg_desc[2];
 
 /* string IDs are assigned dynamically */
 static struct usb_string strings_dev[] = {
@@ -186,16 +172,30 @@ static int hid_bind(struct usb_composite_dev *cdev)
device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id;
device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
 
+   if (gadget_is_otg(gadget)  !otg_desc[0]) {
+   struct usb_descriptor_header *usb_desc;
+
+   usb_desc = usb_otg_descriptor_alloc(gadget);
+   if (!usb_desc)
+   goto put;
+   usb_otg_descriptor_init(gadget, usb_desc);
+   otg_desc[0] = usb_desc;
+   otg_desc[1] = NULL;
+   }
+
/* register our configuration */
status = usb_add_config(cdev, config_driver, do_config);
if (status  0)
-   goto put;
+   goto free_otg_desc;
 
usb_composite_overwrite_options(cdev, coverwrite);
dev_info(gadget-dev, DRIVER_DESC , version:  DRIVER_VERSION \n);
 
return 0;
 
+free_otg_desc:
+   kfree(otg_desc[0]);
+   otg_desc[0] = NULL;
 put:
list_for_each_entry(m, hidg_func_list, node) {
if (m == n)
@@ -213,6 +213,10 @@ static int hid_unbind(struct usb_composite_dev *cdev)
usb_put_function(n-f);
usb_put_function_instance(n-fi);
}
+
+   kfree(otg_desc[0]);
+   otg_desc[0] = NULL;
+
return 0;
 }
 
-- 
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


[PATCH v8 15/23] usb: gadget: cdc2: allocate and init otg descriptor by otg capabilities

2015-07-22 Thread Li Jun
Allocate and initialize usb otg descriptor according to gadget otg
capabilities, add it for each usb configurations. If otg capability
is not defined, keep its original otg descriptor unchanged.

Signed-off-by: Li Jun jun...@freescale.com
Reviewed-by: Roger Quadros rog...@ti.com
---
 drivers/usb/gadget/legacy/cdc2.c | 35 +++
 1 file changed, 19 insertions(+), 16 deletions(-)

diff --git a/drivers/usb/gadget/legacy/cdc2.c b/drivers/usb/gadget/legacy/cdc2.c
index afd3e37..ecd8c8d 100644
--- a/drivers/usb/gadget/legacy/cdc2.c
+++ b/drivers/usb/gadget/legacy/cdc2.c
@@ -60,21 +60,7 @@ static struct usb_device_descriptor device_desc = {
.bNumConfigurations =   1,
 };
 
-static struct usb_otg_descriptor otg_descriptor = {
-   .bLength =  sizeof otg_descriptor,
-   .bDescriptorType =  USB_DT_OTG,
-
-   /* REVISIT SRP-only hardware is possible, although
-* it would not be called OTG ...
-*/
-   .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
-};
-
-static const struct usb_descriptor_header *otg_desc[] = {
-   (struct usb_descriptor_header *) otg_descriptor,
-   NULL,
-};
-
+static const struct usb_descriptor_header *otg_desc[2];
 
 /* string IDs are assigned dynamically */
 static struct usb_string strings_dev[] = {
@@ -193,10 +179,21 @@ static int cdc_bind(struct usb_composite_dev *cdev)
device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id;
device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
 
+   if (gadget_is_otg(gadget)  !otg_desc[0]) {
+   struct usb_descriptor_header *usb_desc;
+
+   usb_desc = usb_otg_descriptor_alloc(gadget);
+   if (!usb_desc)
+   goto fail1;
+   usb_otg_descriptor_init(gadget, usb_desc);
+   otg_desc[0] = usb_desc;
+   otg_desc[1] = NULL;
+   }
+
/* register our configuration */
status = usb_add_config(cdev, cdc_config_driver, cdc_do_config);
if (status  0)
-   goto fail1;
+   goto fail2;
 
usb_composite_overwrite_options(cdev, coverwrite);
dev_info(gadget-dev, %s, version:  DRIVER_VERSION \n,
@@ -204,6 +201,9 @@ static int cdc_bind(struct usb_composite_dev *cdev)
 
return 0;
 
+fail2:
+   kfree(otg_desc[0]);
+   otg_desc[0] = NULL;
 fail1:
usb_put_function_instance(fi_serial);
 fail:
@@ -219,6 +219,9 @@ static int cdc_unbind(struct usb_composite_dev *cdev)
usb_put_function(f_ecm);
if (!IS_ERR_OR_NULL(fi_ecm))
usb_put_function_instance(fi_ecm);
+   kfree(otg_desc[0]);
+   otg_desc[0] = NULL;
+
return 0;
 }
 
-- 
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


[PATCH v8 16/23] usb: gadget: g_ffs: allocate and init otg descriptor by otg capabilities

2015-07-22 Thread Li Jun
Allocate and initialize usb otg descriptor according to gadget otg
capabilities, add it for each usb configurations. If otg capability
is not defined, keep its original otg descriptor unchanged.

Signed-off-by: Li Jun jun...@freescale.com
Reviewed-by: Roger Quadros rog...@ti.com
---
 drivers/usb/gadget/legacy/g_ffs.c | 32 +---
 1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/gadget/legacy/g_ffs.c 
b/drivers/usb/gadget/legacy/g_ffs.c
index e821931..320a81b 100644
--- a/drivers/usb/gadget/legacy/g_ffs.c
+++ b/drivers/usb/gadget/legacy/g_ffs.c
@@ -88,21 +88,7 @@ MODULE_PARM_DESC(bDeviceProtocol, USB Device protocol);
 module_param_array_named(functions, func_names, charp, func_num, 0);
 MODULE_PARM_DESC(functions, USB Functions list);
 
-static const struct usb_descriptor_header *gfs_otg_desc[] = {
-   (const struct usb_descriptor_header *)
-   (const struct usb_otg_descriptor) {
-   .bLength= sizeof(struct usb_otg_descriptor),
-   .bDescriptorType= USB_DT_OTG,
-
-   /*
-* REVISIT SRP-only hardware is possible, although
-* it would not be called OTG ...
-*/
-   .bmAttributes   = USB_OTG_SRP | USB_OTG_HNP,
-   },
-
-   NULL
-};
+static const struct usb_descriptor_header *gfs_otg_desc[2];
 
 /* String IDs are assigned dynamically */
 static struct usb_string gfs_strings[] = {
@@ -412,6 +398,17 @@ static int gfs_bind(struct usb_composite_dev *cdev)
goto error_rndis;
gfs_dev_desc.iProduct = gfs_strings[USB_GADGET_PRODUCT_IDX].id;
 
+   if (gadget_is_otg(cdev-gadget)  !gfs_otg_desc[0]) {
+   struct usb_descriptor_header *usb_desc;
+
+   usb_desc = usb_otg_descriptor_alloc(cdev-gadget);
+   if (!usb_desc)
+   goto error_rndis;
+   usb_otg_descriptor_init(cdev-gadget, usb_desc);
+   gfs_otg_desc[0] = usb_desc;
+   gfs_otg_desc[1] = NULL;
+   }
+
for (i = 0; i  ARRAY_SIZE(gfs_configurations); ++i) {
struct gfs_configuration *c = gfs_configurations + i;
int sid = USB_GADGET_FIRST_AVAIL_IDX + i;
@@ -432,6 +429,8 @@ static int gfs_bind(struct usb_composite_dev *cdev)
 
 /* TODO */
 error_unbind:
+   kfree(gfs_otg_desc[0]);
+   gfs_otg_desc[0] = NULL;
 error_rndis:
 #ifdef CONFIG_USB_FUNCTIONFS_RNDIS
usb_put_function_instance(fi_rndis);
@@ -473,6 +472,9 @@ static int gfs_unbind(struct usb_composite_dev *cdev)
for (i = 0; i  N_CONF * func_num; ++i)
usb_put_function(*(f_ffs[0] + i));
 
+   kfree(gfs_otg_desc[0]);
+   gfs_otg_desc[0] = NULL;
+
return 0;
 }
 
-- 
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


[PATCH v8 21/23] usb: gadget: printer: allocate and init otg descriptor by otg capabilities

2015-07-22 Thread Li Jun
Allocate and initialize usb otg descriptor according to gadget otg
capabilities, add it for each usb configurations. If otg capability
is not defined, keep its original otg descriptor unchanged.

Signed-off-by: Li Jun jun...@freescale.com
Reviewed-by: Roger Quadros rog...@ti.com
---
 drivers/usb/gadget/legacy/printer.c | 49 +++--
 1 file changed, 30 insertions(+), 19 deletions(-)

diff --git a/drivers/usb/gadget/legacy/printer.c 
b/drivers/usb/gadget/legacy/printer.c
index 1ce7df1..0c1fc06 100644
--- a/drivers/usb/gadget/legacy/printer.c
+++ b/drivers/usb/gadget/legacy/printer.c
@@ -82,16 +82,7 @@ static struct usb_device_descriptor device_desc = {
.bNumConfigurations =   1
 };
 
-static struct usb_otg_descriptor otg_descriptor = {
-   .bLength =  sizeof otg_descriptor,
-   .bDescriptorType =  USB_DT_OTG,
-   .bmAttributes = USB_OTG_SRP,
-};
-
-static const struct usb_descriptor_header *otg_desc[] = {
-   (struct usb_descriptor_header *) otg_descriptor,
-   NULL,
-};
+static const struct usb_descriptor_header *otg_desc[2];
 
 /*-*/
 
@@ -136,7 +127,6 @@ static int printer_do_config(struct usb_configuration *c)
usb_gadget_set_selfpowered(gadget);
 
if (gadget_is_otg(gadget)) {
-   otg_descriptor.bmAttributes |= USB_OTG_HNP;
printer_cfg_driver.descriptors = otg_desc;
printer_cfg_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
}
@@ -174,21 +164,39 @@ static int printer_bind(struct usb_composite_dev *cdev)
opts-q_len = QLEN;
 
ret = usb_string_ids_tab(cdev, strings);
-   if (ret  0) {
-   usb_put_function_instance(fi_printer);
-   return ret;
-   }
+   if (ret  0)
+   goto fail_put_func_inst;
+
device_desc.iManufacturer = strings[USB_GADGET_MANUFACTURER_IDX].id;
device_desc.iProduct = strings[USB_GADGET_PRODUCT_IDX].id;
device_desc.iSerialNumber = strings[USB_GADGET_SERIAL_IDX].id;
 
-   ret = usb_add_config(cdev, printer_cfg_driver, printer_do_config);
-   if (ret) {
-   usb_put_function_instance(fi_printer);
-   return ret;
+   if (gadget_is_otg(cdev-gadget)  !otg_desc[0]) {
+   struct usb_descriptor_header *usb_desc;
+
+   usb_desc = usb_otg_descriptor_alloc(cdev-gadget);
+   if (!usb_desc) {
+   ret = -ENOMEM;
+   goto fail_put_func_inst;
+   }
+   usb_otg_descriptor_init(cdev-gadget, usb_desc);
+   otg_desc[0] = usb_desc;
+   otg_desc[1] = NULL;
}
+
+   ret = usb_add_config(cdev, printer_cfg_driver, printer_do_config);
+   if (ret)
+   goto fail_free_otg_desc;
+
usb_composite_overwrite_options(cdev, coverwrite);
return ret;
+
+fail_free_otg_desc:
+   kfree(otg_desc[0]);
+   otg_desc[0] = NULL;
+fail_put_func_inst:
+   usb_put_function_instance(fi_printer);
+   return ret;
 }
 
 static int printer_unbind(struct usb_composite_dev *cdev)
@@ -196,6 +204,9 @@ static int printer_unbind(struct usb_composite_dev *cdev)
usb_put_function(f_printer);
usb_put_function_instance(fi_printer);
 
+   kfree(otg_desc[0]);
+   otg_desc[0] = NULL;
+
return 0;
 }
 
-- 
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


[PATCH v8 14/23] usb: gadget: audio: allocate and init otg descriptor by otg capabilities

2015-07-22 Thread Li Jun
Allocate and initialize usb otg descriptor according to gadget otg
capabilities, add it for each usb configurations. If otg capability
is not defined, keep its original otg descriptor unchanged.

Signed-off-by: Li Jun jun...@freescale.com
Reviewed-by: Roger Quadros rog...@ti.com
---
 drivers/usb/gadget/legacy/audio.c | 34 +++---
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/gadget/legacy/audio.c 
b/drivers/usb/gadget/legacy/audio.c
index f289caf..51a2380 100644
--- a/drivers/usb/gadget/legacy/audio.c
+++ b/drivers/usb/gadget/legacy/audio.c
@@ -150,20 +150,7 @@ static struct usb_device_descriptor device_desc = {
.bNumConfigurations =   1,
 };
 
-static struct usb_otg_descriptor otg_descriptor = {
-   .bLength =  sizeof otg_descriptor,
-   .bDescriptorType =  USB_DT_OTG,
-
-   /* REVISIT SRP-only hardware is possible, although
-* it would not be called OTG ...
-*/
-   .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
-};
-
-static const struct usb_descriptor_header *otg_desc[] = {
-   (struct usb_descriptor_header *) otg_descriptor,
-   NULL,
-};
+static const struct usb_descriptor_header *otg_desc[2];
 
 /*-*/
 
@@ -259,14 +246,28 @@ static int audio_bind(struct usb_composite_dev *cdev)
device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id;
device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
 
+   if (gadget_is_otg(cdev-gadget)  !otg_desc[0]) {
+   struct usb_descriptor_header *usb_desc;
+
+   usb_desc = usb_otg_descriptor_alloc(cdev-gadget);
+   if (!usb_desc)
+   goto fail;
+   usb_otg_descriptor_init(cdev-gadget, usb_desc);
+   otg_desc[0] = usb_desc;
+   otg_desc[1] = NULL;
+   }
+
status = usb_add_config(cdev, audio_config_driver, audio_do_config);
if (status  0)
-   goto fail;
+   goto fail_otg_desc;
usb_composite_overwrite_options(cdev, coverwrite);
 
INFO(cdev, %s, version: %s\n, DRIVER_DESC, DRIVER_VERSION);
return 0;
 
+fail_otg_desc:
+   kfree(otg_desc[0]);
+   otg_desc[0] = NULL;
 fail:
 #ifndef CONFIG_GADGET_UAC1
usb_put_function_instance(fi_uac2);
@@ -289,6 +290,9 @@ static int audio_unbind(struct usb_composite_dev *cdev)
if (!IS_ERR_OR_NULL(fi_uac2))
usb_put_function_instance(fi_uac2);
 #endif
+   kfree(otg_desc[0]);
+   otg_desc[0] = NULL;
+
return 0;
 }
 
-- 
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


[PATCH v8 19/23] usb: gadget: multi: allocate and init otg descriptor by otg capabilities

2015-07-22 Thread Li Jun
Allocate and initialize usb otg descriptor according to gadget otg
capabilities, add it for each usb configurations. If otg capability
is not defined, keep its original otg descriptor unchanged.

Signed-off-by: Li Jun jun...@freescale.com
Reviewed-by: Roger Quadros rog...@ti.com
---
 drivers/usb/gadget/legacy/multi.c | 37 -
 1 file changed, 20 insertions(+), 17 deletions(-)

diff --git a/drivers/usb/gadget/legacy/multi.c 
b/drivers/usb/gadget/legacy/multi.c
index b21b51f..c38ead1 100644
--- a/drivers/usb/gadget/legacy/multi.c
+++ b/drivers/usb/gadget/legacy/multi.c
@@ -78,21 +78,7 @@ static struct usb_device_descriptor device_desc = {
.idProduct =cpu_to_le16(MULTI_PRODUCT_NUM),
 };
 
-
-static const struct usb_descriptor_header *otg_desc[] = {
-   (struct usb_descriptor_header *) (struct usb_otg_descriptor){
-   .bLength =  sizeof(struct usb_otg_descriptor),
-   .bDescriptorType =  USB_DT_OTG,
-
-   /*
-* REVISIT SRP-only hardware is possible, although
-* it would not be called OTG ...
-*/
-   .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
-   },
-   NULL,
-};
-
+static const struct usb_descriptor_header *otg_desc[2];
 
 enum {
MULTI_STRING_RNDIS_CONFIG_IDX = USB_GADGET_FIRST_AVAIL_IDX,
@@ -429,14 +415,25 @@ static int __ref multi_bind(struct usb_composite_dev 
*cdev)
goto fail_string_ids;
device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
 
+   if (gadget_is_otg(gadget)  !otg_desc[0]) {
+   struct usb_descriptor_header *usb_desc;
+
+   usb_desc = usb_otg_descriptor_alloc(gadget);
+   if (!usb_desc)
+   goto fail_string_ids;
+   usb_otg_descriptor_init(gadget, usb_desc);
+   otg_desc[0] = usb_desc;
+   otg_desc[1] = NULL;
+   }
+
/* register configurations */
status = rndis_config_register(cdev);
if (unlikely(status  0))
-   goto fail_string_ids;
+   goto fail_otg_desc;
 
status = cdc_config_register(cdev);
if (unlikely(status  0))
-   goto fail_string_ids;
+   goto fail_otg_desc;
usb_composite_overwrite_options(cdev, coverwrite);
 
/* we're done */
@@ -445,6 +442,9 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
 
 
/* error recovery */
+fail_otg_desc:
+   kfree(otg_desc[0]);
+   otg_desc[0] = NULL;
 fail_string_ids:
fsg_common_remove_luns(fsg_opts-common);
 fail_set_cdev:
@@ -490,6 +490,9 @@ static int multi_unbind(struct usb_composite_dev *cdev)
usb_put_function(f_ecm);
usb_put_function_instance(fi_ecm);
 #endif
+   kfree(otg_desc[0]);
+   otg_desc[0] = NULL;
+
return 0;
 }
 
-- 
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


[PATCH v8 22/23] usb: gadget: serial: allocate and init otg descriptor by otg capabilities

2015-07-22 Thread Li Jun
Allocate and initialize usb otg descriptor according to gadget otg
capabilities, add it for each usb configurations. If otg capability
is not defined, keep its original otg descriptor unchanged.

Signed-off-by: Li Jun jun...@freescale.com
Reviewed-by: Roger Quadros rog...@ti.com
---
 drivers/usb/gadget/legacy/serial.c | 37 +
 1 file changed, 21 insertions(+), 16 deletions(-)

diff --git a/drivers/usb/gadget/legacy/serial.c 
b/drivers/usb/gadget/legacy/serial.c
index 8b7528f..9836d16 100644
--- a/drivers/usb/gadget/legacy/serial.c
+++ b/drivers/usb/gadget/legacy/serial.c
@@ -79,20 +79,7 @@ static struct usb_device_descriptor device_desc = {
.bNumConfigurations =   1,
 };
 
-static struct usb_otg_descriptor otg_descriptor = {
-   .bLength =  sizeof otg_descriptor,
-   .bDescriptorType =  USB_DT_OTG,
-
-   /* REVISIT SRP-only hardware is possible, although
-* it would not be called OTG ...
-*/
-   .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
-};
-
-static const struct usb_descriptor_header *otg_desc[] = {
-   (struct usb_descriptor_header *) otg_descriptor,
-   NULL,
-};
+static const struct usb_descriptor_header *otg_desc[2];
 
 /*-*/
 
@@ -191,6 +178,18 @@ static int gs_bind(struct usb_composite_dev *cdev)
serial_config_driver.iConfiguration = status;
 
if (gadget_is_otg(cdev-gadget)) {
+   if (!otg_desc[0]) {
+   struct usb_descriptor_header *usb_desc;
+
+   usb_desc = usb_otg_descriptor_alloc(cdev-gadget);
+   if (!usb_desc) {
+   status = -ENOMEM;
+   goto fail;
+   }
+   usb_otg_descriptor_init(cdev-gadget, usb_desc);
+   otg_desc[0] = usb_desc;
+   otg_desc[1] = NULL;
+   }
serial_config_driver.descriptors = otg_desc;
serial_config_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
}
@@ -208,13 +207,15 @@ static int gs_bind(struct usb_composite_dev *cdev)
gser);
}
if (status  0)
-   goto fail;
+   goto fail1;
 
usb_composite_overwrite_options(cdev, coverwrite);
INFO(cdev, %s\n, GS_VERSION_NAME);
 
return 0;
-
+fail1:
+   kfree(otg_desc[0]);
+   otg_desc[0] = NULL;
 fail:
return status;
 }
@@ -227,6 +228,10 @@ static int gs_unbind(struct usb_composite_dev *cdev)
usb_put_function(f_serial[i]);
usb_put_function_instance(fi_serial[i]);
}
+
+   kfree(otg_desc[0]);
+   otg_desc[0] = NULL;
+
return 0;
 }
 
-- 
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


[PATCH v8 18/23] usb: gadget: mass_storage: allocate and init otg descriptor by otg capabilities

2015-07-22 Thread Li Jun
Allocate and initialize usb otg descriptor according to gadget otg
capabilities, add it for each usb configurations. If otg capability
is not defined, keep its original otg descriptor unchanged.

Signed-off-by: Li Jun jun...@freescale.com
Reviewed-by: Roger Quadros rog...@ti.com
---
 drivers/usb/gadget/legacy/mass_storage.c | 35 +---
 1 file changed, 19 insertions(+), 16 deletions(-)

diff --git a/drivers/usb/gadget/legacy/mass_storage.c 
b/drivers/usb/gadget/legacy/mass_storage.c
index e7bfb08..ab1a42c 100644
--- a/drivers/usb/gadget/legacy/mass_storage.c
+++ b/drivers/usb/gadget/legacy/mass_storage.c
@@ -64,21 +64,7 @@ static struct usb_device_descriptor msg_device_desc = {
.bNumConfigurations =   1,
 };
 
-static struct usb_otg_descriptor otg_descriptor = {
-   .bLength =  sizeof otg_descriptor,
-   .bDescriptorType =  USB_DT_OTG,
-
-   /*
-* REVISIT SRP-only hardware is possible, although
-* it would not be called OTG ...
-*/
-   .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
-};
-
-static const struct usb_descriptor_header *otg_desc[] = {
-   (struct usb_descriptor_header *) otg_descriptor,
-   NULL,
-};
+static const struct usb_descriptor_header *otg_desc[2];
 
 static struct usb_string strings_dev[] = {
[USB_GADGET_MANUFACTURER_IDX].s = ,
@@ -214,9 +200,20 @@ static int msg_bind(struct usb_composite_dev *cdev)
goto fail_string_ids;
msg_device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
 
+   if (gadget_is_otg(cdev-gadget)  !otg_desc[0]) {
+   struct usb_descriptor_header *usb_desc;
+
+   usb_desc = usb_otg_descriptor_alloc(cdev-gadget);
+   if (!usb_desc)
+   goto fail_string_ids;
+   usb_otg_descriptor_init(cdev-gadget, usb_desc);
+   otg_desc[0] = usb_desc;
+   otg_desc[1] = NULL;
+   }
+
status = usb_add_config(cdev, msg_config_driver, msg_do_config);
if (status  0)
-   goto fail_string_ids;
+   goto fail_otg_desc;
 
usb_composite_overwrite_options(cdev, coverwrite);
dev_info(cdev-gadget-dev,
@@ -224,6 +221,9 @@ static int msg_bind(struct usb_composite_dev *cdev)
set_bit(0, msg_registered);
return 0;
 
+fail_otg_desc:
+   kfree(otg_desc[0]);
+   otg_desc[0] = NULL;
 fail_string_ids:
fsg_common_remove_luns(opts-common);
 fail_set_cdev:
@@ -243,6 +243,9 @@ static int msg_unbind(struct usb_composite_dev *cdev)
if (!IS_ERR(fi_msg))
usb_put_function_instance(fi_msg);
 
+   kfree(otg_desc[0]);
+   otg_desc[0] = NULL;
+
return 0;
 }
 
-- 
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


[PATCH v8 20/23] usb: gadget: ncm: allocate and init otg descriptor by otg capabilities

2015-07-22 Thread Li Jun
Allocate and initialize usb otg descriptor according to gadget otg
capabilities, add it for each usb configurations. If otg capability
is not defined, keep its original otg descriptor unchanged.

Signed-off-by: Li Jun jun...@freescale.com
Reviewed-by: Roger Quadros rog...@ti.com
---
 drivers/usb/gadget/legacy/ncm.c | 34 +++---
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/gadget/legacy/ncm.c b/drivers/usb/gadget/legacy/ncm.c
index 6ce7421..2bae438 100644
--- a/drivers/usb/gadget/legacy/ncm.c
+++ b/drivers/usb/gadget/legacy/ncm.c
@@ -69,20 +69,7 @@ static struct usb_device_descriptor device_desc = {
.bNumConfigurations =   1,
 };
 
-static struct usb_otg_descriptor otg_descriptor = {
-   .bLength =  sizeof otg_descriptor,
-   .bDescriptorType =  USB_DT_OTG,
-
-   /* REVISIT SRP-only hardware is possible, although
-* it would not be called OTG ...
-*/
-   .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
-};
-
-static const struct usb_descriptor_header *otg_desc[] = {
-   (struct usb_descriptor_header *) otg_descriptor,
-   NULL,
-};
+static const struct usb_descriptor_header *otg_desc[2];
 
 /* string IDs are assigned dynamically */
 static struct usb_string strings_dev[] = {
@@ -171,16 +158,30 @@ static int gncm_bind(struct usb_composite_dev *cdev)
device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id;
device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
 
+   if (gadget_is_otg(gadget)  !otg_desc[0]) {
+   struct usb_descriptor_header *usb_desc;
+
+   usb_desc = usb_otg_descriptor_alloc(gadget);
+   if (!usb_desc)
+   goto fail;
+   usb_otg_descriptor_init(gadget, usb_desc);
+   otg_desc[0] = usb_desc;
+   otg_desc[1] = NULL;
+   }
+
status = usb_add_config(cdev, ncm_config_driver,
ncm_do_config);
if (status  0)
-   goto fail;
+   goto fail1;
 
usb_composite_overwrite_options(cdev, coverwrite);
dev_info(gadget-dev, %s\n, DRIVER_DESC);
 
return 0;
 
+fail1:
+   kfree(otg_desc[0]);
+   otg_desc[0] = NULL;
 fail:
usb_put_function_instance(f_ncm_inst);
return status;
@@ -192,6 +193,9 @@ static int gncm_unbind(struct usb_composite_dev *cdev)
usb_put_function(f_ncm);
if (!IS_ERR_OR_NULL(f_ncm_inst))
usb_put_function_instance(f_ncm_inst);
+   kfree(otg_desc[0]);
+   otg_desc[0] = NULL;
+
return 0;
 }
 
-- 
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


Re: [PATCH V2 1/4] usb: gadget: udc: bdc: Fix a driver crash on disconnect

2015-07-22 Thread Felipe Balbi
On Wed, Jul 22, 2015 at 04:58:07PM -0400, Al Cooper wrote:
 V2 - Fix a compiler bug that happend when the config options
 CONFIG_USB_GADGET_DEBUG and CONFIG_USB_GADGET_VERBOSE
 were enabled.
 
 ep_dequeue() in bdc_ep.c was capturing the hw dequeue pointer
 incorrectly by reading the wrong register for the upper 32 bits.
 The header file defining the registers was incorrect.

btw, the header file was really incorrect as long as you passed 0 to
the argument :-p

-- 
balbi


signature.asc
Description: Digital signature


Re: [PATCH] Fix data loss in cdc-acm

2015-07-22 Thread Peter Hurley
Hi Sven,

On 07/21/2015 08:47 PM, Sven Brauch wrote:
 On 22/07/15 01:34, Peter Hurley wrote:
 I'd like to see that data, if you can, which will help me understand
 at least the timing.
 Sure, please see below for the code which produced the output
 and the actual output. Let me know if you need anything else.
 This was run with the unmodified version of the driver, i.e. without
 my patch.

Thanks for this, which confirms that roughly 10.4ms elapses from
kworker schedule (of input into nearly empty tty buffers) to throttle
notification.

The premature unthrottle actually leads to the data loss but the throttling
with a mere 2K left is _way too late_.

10ms is a _really_ long time for a cpu not to attend to a kworker.
Which raises 2 questions:
1. What are the termios settings of the tty receiving input? Is it 'raw'
   mode or typical terminal mode (icanon, echo, etc.) or something else?
2. Are there RT threads that are hogging cpu time?

Regards,
Peter Hurley
--
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


Re: [PATCH] usb: ulpi: call put_device if device_register fails

2015-07-22 Thread Greg Kroah-Hartman
On Tue, Jun 23, 2015 at 01:57:38PM +0300, Heikki Krogerus wrote:
 On Fri, Jun 19, 2015 at 01:12:36AM +0800, ChengYi He wrote:
  put_device is required to release the last reference to the device.
  
  Signed-off-by: ChengYi He chengyihetai...@gmail.com
  ---
   drivers/usb/common/ulpi.c | 4 +++-
   1 file changed, 3 insertions(+), 1 deletion(-)
  
  diff --git a/drivers/usb/common/ulpi.c b/drivers/usb/common/ulpi.c
  index 0e6f968..bd25bdb 100644
  --- a/drivers/usb/common/ulpi.c
  +++ b/drivers/usb/common/ulpi.c
  @@ -184,8 +184,10 @@ static int ulpi_register(struct device *dev, struct 
  ulpi *ulpi)
  request_module(ulpi:v%04xp%04x, ulpi-id.vendor, ulpi-id.product);
   
  ret = device_register(ulpi-dev);
  -   if (ret)
  +   if (ret) {
  +   put_device(ulpi-dev);
 
 If device_register returns failure, put_device has already been
 called. Check device_add in drivers/base/core.c.

Yes, please read the function, which says:
 * NOTE: _Never_ directly free @dev after calling this function, even
 * if it returned an error! Always use put_device() to give up your
 * reference instead.

But, the problem is that the ulpi core doesn't own that struct device.
It comes from elsewhere.  It comes from somewhere deep down in the dw3
core, which is where I lost the path.  Something needs to be fixed in
dwc3_probe() to properly clean up the device if it fails, which is not
happening right now.

So this patch would actually cause much bigger problems than fixing
anything, so it's wrong, but for a different reason than you are talking
about here.

And ugh, the ulpi and dwc code binding together, what a mess, horrid...

greg k-h
--
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


Re: [PATCH v3]USB:OHCI: BugFix:Proper handling of ed_rm_list to handle race condition between usb_kill_urb() and finish_unlinks()

2015-07-22 Thread Greg KH
On Sat, Jul 11, 2015 at 12:04:26PM +, AMAN DEEP wrote:
 There is a race condition between
  finish_unlinks-finish_urb() function and
  usb_kill_urb() in ohci controller case. The finish_urb
  calls spin_unlock(ohci-lock) before
  usb_hcd_giveback_urb() function call, then if during
  this time, usb_kill_urb is called for another endpoint,
  then new ed will be added to ed_rm_list at beginning
  for unlink. and ed_rm_list will point to newly added
  ed.
 
 When finish_urb() is completed in finish_unlinks() and
 ed-td_list becomes empty as in below code (in finish_unlinks() function)
 if (list_empty(ed-td_list)) {
 *last = ed-ed_next;
 ed-ed_next = NULL;
 } else if (ohci-rh_state == OHCI_RH_RUNNING) {
 *last = ed-ed_next;
 ed-ed_next = NULL;
 ed_schedule(ohci, ed);
 }
 *last = ed-ed_next will make ed_rm_list to point to ed-ed_next and
 previously added ed by usb_kill_urb will be left unreferenced by
 ed_rm_list. This causes usb_kill_urb() hang forever waiting for
 finish_unlink to remove added ed from ed_rm_list.
 
 The main reason for hang in this race condtion is addition and removal
 of ed from ed_rm_list in the beginning during usb_kill_urb and later last*
 is modified in finish_unlinks().
 As suggested by Alan Stern, the solution for proper handling of
 ohci-ed_rm_list is to remove ed from the ed_rm_list before finishing
 any URBs. Then at the end, we can add ed back to the list if necessary.
 This properly handle the updated ohci-ed_rm_list in
 usb_kill_urb().
 
 Fixes: 977dcfdc6031 (USB: OHCI: don't lose track of EDs when a controller 
 dies)
 
 Acked-by: Alan Stern st...@rowland.harvard.edu
 
 Signed-off-by: Aman Deep aman.d...@samsung.com
 CC: sta...@vger.kernel.org
 ---
  drivers/usb/host/ohci-q.c |   17 ++---
  1 file changed, 10 insertions(+), 7 deletions(-)
 
 diff --git a/drivers/usb/host/ohci-q.c b/drivers/usb/host/ohci-q.c
 index f7d561e..496658b 100644
 --- a/drivers/usb/host/ohci-q.c
 +++ b/drivers/usb/host/ohci-q.c
 @@ -1023,6 +1023,8 @@ ed_idle:
* have modified this list.  normally it's just prepending
* entries (which we'd ignore), but paranoia won't hurt.
*/
 + *last = ed-ed_next;
 + ed-ed_next = NULL;
   modified = 0;
  
   /* unlink urbs as requested, but rescan the list after
 @@ -1081,20 +1083,21 @@ rescan_this:
   goto rescan_this;
  
   /*
 -  * If no TDs are queued, take ED off the ed_rm_list.
 +  * If no TDs are queued, ED is now idle.
* Otherwise, if the HC is running, reschedule.
 -  * If not, leave it on the list for further dequeues.
 +  * If the HC isn't running, add ED back to the
 +  * start of the list for later processing.
*/
   if (list_empty(ed-td_list)) {
 - *last = ed-ed_next;
 - ed-ed_next = NULL;
   list_del(ed-in_use_list);
   } else if (ohci-rh_state == OHCI_RH_RUNNING) {
 - *last = ed-ed_next;
 - ed-ed_next = NULL;
   ed_schedule(ohci, ed);
   } else {
 - last = ed-ed_next;
 + ed-ed_next = ohci-ed_rm_list;
 + ohci-ed_rm_list = ed;
 + /* Don't loop on the same ED */
 + if (last == ohci-ed_rm_list)
 + last = ed-ed_next;
   }
  
   if (modified)
 -- 

This patch doesn't apply to my tree, can you please refresh the patch
agasint 4.2-rc3 and resend it so that I can apply it?

Also, please try to fix your email client to not send base64 patches,
that made it really hard for me to try to figure out what was wrong with
it...

thanks,

greg k-h
--
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


Re: [PATCH V2 1/4] usb: gadget: udc: bdc: Fix a driver crash on disconnect

2015-07-22 Thread Alan Cooper
On Wed, Jul 22, 2015 at 5:29 PM, Felipe Balbi ba...@ti.com wrote:
 On Wed, Jul 22, 2015 at 04:26:57PM -0500, Felipe Balbi wrote:
 On Wed, Jul 22, 2015 at 04:58:07PM -0400, Al Cooper wrote:
  V2 - Fix a compiler bug that happend when the config options
  CONFIG_USB_GADGET_DEBUG and CONFIG_USB_GADGET_VERBOSE
  were enabled.
 
  ep_dequeue() in bdc_ep.c was capturing the hw dequeue pointer
  incorrectly by reading the wrong register for the upper 32 bits.
  The header file defining the registers was incorrect.

 btw, the header file was really incorrect as long as you passed 0 to
 the argument :-p

 in fact, the minimal fix for this bug would be the one below:

 diff --git a/drivers/usb/gadget/udc/bdc/bdc_ep.c 
 b/drivers/usb/gadget/udc/bdc/bdc_ep.c
 index b04980cf6dc4..1efa61265d8d 100644
 --- a/drivers/usb/gadget/udc/bdc/bdc_ep.c
 +++ b/drivers/usb/gadget/udc/bdc/bdc_ep.c
 @@ -779,7 +779,7 @@ static int ep_dequeue(struct bdc_ep *ep, struct bdc_req 
 *req)
 /* The current hw dequeue pointer */
 tmp_32 = bdc_readl(bdc-regs, BDC_EPSTS0(0));
 deq_ptr_64 = tmp_32;
 -   tmp_32 = bdc_readl(bdc-regs, BDC_EPSTS0(1));
 +   tmp_32 = bdc_readl(bdc-regs, BDC_EPSTS1(0));
 deq_ptr_64 |= ((u64)tmp_32  32);

 /* we have the dma addr of next bd that will be fetched by hardware */

 And $subject becomes a cleanup patch for v4.3. Can you make these
 changes, please ?

Yes, I can make these changes, but first let me explain why I did it this way.
The 8 End Point Status registers are 32 bit consecutive registers, so
defining them as:
#define BDC_EPSTS0(n)  (0x60 + (n * 0x10))
#define BDC_EPSTS1(n)  (0x64 + (n * 0x10))
#define BDC_EPSTS2(n)  (0x68 + (n * 0x10))
#define BDC_EPSTS3(n)  (0x6c + (n * 0x10))
#define BDC_EPSTS4(n)  (0x70 + (n * 0x10))
#define BDC_EPSTS5(n)  (0x74 + (n * 0x10))
#define BDC_EPSTS6(n)  (0x78 + (n * 0x10))
#define BDC_EPSTS7(n)  (0x7c + (n * 0x10))
seems misleading, does not reflect the hardware and using anything
other than (0) would get you to some other unexpected register and
should be considered a coding error.
I think the original hardware spec had each End Point Status as a
block of registers but the first silicon had them as single registers
and they are expected to stay that way.

Thanks
--
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 V2 1/4] usb: gadget: udc: bdc: Fix a driver crash on disconnect

2015-07-22 Thread Al Cooper
V2 - Fix a compiler bug that happend when the config options
CONFIG_USB_GADGET_DEBUG and CONFIG_USB_GADGET_VERBOSE
were enabled.

ep_dequeue() in bdc_ep.c was capturing the hw dequeue pointer
incorrectly by reading the wrong register for the upper 32 bits.
The header file defining the registers was incorrect.

Signed-off-by: Al Cooper alcoop...@gmail.com
---
 drivers/usb/gadget/udc/bdc/bdc.h | 16 
 drivers/usb/gadget/udc/bdc/bdc_dbg.c | 16 
 drivers/usb/gadget/udc/bdc/bdc_ep.c  |  4 ++--
 3 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/drivers/usb/gadget/udc/bdc/bdc.h b/drivers/usb/gadget/udc/bdc/bdc.h
index dc18a20..56c059f 100644
--- a/drivers/usb/gadget/udc/bdc/bdc.h
+++ b/drivers/usb/gadget/udc/bdc/bdc.h
@@ -83,14 +83,14 @@
 
 #define BDC_DVCSA  0x50
 #define BDC_DVCSB  0x54
-#define BDC_EPSTS0(n)  (0x60 + (n * 0x10))
-#define BDC_EPSTS1(n)  (0x64 + (n * 0x10))
-#define BDC_EPSTS2(n)  (0x68 + (n * 0x10))
-#define BDC_EPSTS3(n)  (0x6c + (n * 0x10))
-#define BDC_EPSTS4(n)  (0x70 + (n * 0x10))
-#define BDC_EPSTS5(n)  (0x74 + (n * 0x10))
-#define BDC_EPSTS6(n)  (0x78 + (n * 0x10))
-#define BDC_EPSTS7(n)  (0x7c + (n * 0x10))
+#define BDC_EPSTS0 0x60
+#define BDC_EPSTS1 0x64
+#define BDC_EPSTS2 0x68
+#define BDC_EPSTS3 0x6c
+#define BDC_EPSTS4 0x70
+#define BDC_EPSTS5 0x74
+#define BDC_EPSTS6 0x78
+#define BDC_EPSTS7 0x7c
 #define BDC_SRRBAL(n)  (0x200 + (n * 0x10))
 #define BDC_SRRBAH(n)  (0x204 + (n * 0x10))
 #define BDC_SRRINT(n)  (0x208 + (n * 0x10))
diff --git a/drivers/usb/gadget/udc/bdc/bdc_dbg.c 
b/drivers/usb/gadget/udc/bdc/bdc_dbg.c
index 5945dbc..ac98f6f 100644
--- a/drivers/usb/gadget/udc/bdc/bdc_dbg.c
+++ b/drivers/usb/gadget/udc/bdc/bdc_dbg.c
@@ -40,28 +40,28 @@ void bdc_dump_epsts(struct bdc *bdc)
 {
u32 temp;
 
-   temp = bdc_readl(bdc-regs, BDC_EPSTS0(0));
+   temp = bdc_readl(bdc-regs, BDC_EPSTS0);
dev_vdbg(bdc-dev, BDC_EPSTS0:0x%08x\n, temp);
 
-   temp = bdc_readl(bdc-regs, BDC_EPSTS1(0));
+   temp = bdc_readl(bdc-regs, BDC_EPSTS1);
dev_vdbg(bdc-dev, BDC_EPSTS1:0x%x\n, temp);
 
-   temp = bdc_readl(bdc-regs, BDC_EPSTS2(0));
+   temp = bdc_readl(bdc-regs, BDC_EPSTS2);
dev_vdbg(bdc-dev, BDC_EPSTS2:0x%08x\n, temp);
 
-   temp = bdc_readl(bdc-regs, BDC_EPSTS3(0));
+   temp = bdc_readl(bdc-regs, BDC_EPSTS3);
dev_vdbg(bdc-dev, BDC_EPSTS3:0x%08x\n, temp);
 
-   temp = bdc_readl(bdc-regs, BDC_EPSTS4(0));
+   temp = bdc_readl(bdc-regs, BDC_EPSTS4);
dev_vdbg(bdc-dev, BDC_EPSTS4:0x%08x\n, temp);
 
-   temp = bdc_readl(bdc-regs, BDC_EPSTS5(0));
+   temp = bdc_readl(bdc-regs, BDC_EPSTS5);
dev_vdbg(bdc-dev, BDC_EPSTS5:0x%08x\n, temp);
 
-   temp = bdc_readl(bdc-regs, BDC_EPSTS6(0));
+   temp = bdc_readl(bdc-regs, BDC_EPSTS6);
dev_vdbg(bdc-dev, BDC_EPSTS6:0x%08x\n, temp);
 
-   temp = bdc_readl(bdc-regs, BDC_EPSTS7(0));
+   temp = bdc_readl(bdc-regs, BDC_EPSTS7);
dev_vdbg(bdc-dev, BDC_EPSTS7:0x%08x\n, temp);
 }
 
diff --git a/drivers/usb/gadget/udc/bdc/bdc_ep.c 
b/drivers/usb/gadget/udc/bdc/bdc_ep.c
index b04980c..e56ccbe 100644
--- a/drivers/usb/gadget/udc/bdc/bdc_ep.c
+++ b/drivers/usb/gadget/udc/bdc/bdc_ep.c
@@ -777,9 +777,9 @@ static int ep_dequeue(struct bdc_ep *ep, struct bdc_req 
*req)
 */
 
/* The current hw dequeue pointer */
-   tmp_32 = bdc_readl(bdc-regs, BDC_EPSTS0(0));
+   tmp_32 = bdc_readl(bdc-regs, BDC_EPSTS0);
deq_ptr_64 = tmp_32;
-   tmp_32 = bdc_readl(bdc-regs, BDC_EPSTS0(1));
+   tmp_32 = bdc_readl(bdc-regs, BDC_EPSTS1);
deq_ptr_64 |= ((u64)tmp_32  32);
 
/* we have the dma addr of next bd that will be fetched by hardware */
-- 
1.9.0.138.g2de3478

--
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


Re: [PATCH V2 1/4] usb: gadget: udc: bdc: Fix a driver crash on disconnect

2015-07-22 Thread Felipe Balbi
On Wed, Jul 22, 2015 at 04:26:57PM -0500, Felipe Balbi wrote:
 On Wed, Jul 22, 2015 at 04:58:07PM -0400, Al Cooper wrote:
  V2 - Fix a compiler bug that happend when the config options
  CONFIG_USB_GADGET_DEBUG and CONFIG_USB_GADGET_VERBOSE
  were enabled.
  
  ep_dequeue() in bdc_ep.c was capturing the hw dequeue pointer
  incorrectly by reading the wrong register for the upper 32 bits.
  The header file defining the registers was incorrect.
 
 btw, the header file was really incorrect as long as you passed 0 to
 the argument :-p

in fact, the minimal fix for this bug would be the one below:

diff --git a/drivers/usb/gadget/udc/bdc/bdc_ep.c 
b/drivers/usb/gadget/udc/bdc/bdc_ep.c
index b04980cf6dc4..1efa61265d8d 100644
--- a/drivers/usb/gadget/udc/bdc/bdc_ep.c
+++ b/drivers/usb/gadget/udc/bdc/bdc_ep.c
@@ -779,7 +779,7 @@ static int ep_dequeue(struct bdc_ep *ep, struct bdc_req 
*req)
/* The current hw dequeue pointer */
tmp_32 = bdc_readl(bdc-regs, BDC_EPSTS0(0));
deq_ptr_64 = tmp_32;
-   tmp_32 = bdc_readl(bdc-regs, BDC_EPSTS0(1));
+   tmp_32 = bdc_readl(bdc-regs, BDC_EPSTS1(0));
deq_ptr_64 |= ((u64)tmp_32  32);
 
/* we have the dma addr of next bd that will be fetched by hardware */

And $subject becomes a cleanup patch for v4.3. Can you make these
changes, please ?

-- 
balbi


signature.asc
Description: Digital signature


Re: [PATCH] Fix data loss in cdc-acm

2015-07-22 Thread Sven Brauch
Hi,

On 23/07/15 00:12, Peter Hurley wrote:
 The premature unthrottle actually leads to the data loss but the throttling
 with a mere 2K left is _way too late_.
Ok, yes, I think so too.

 10ms is a _really_ long time for a cpu not to attend to a kworker.
 Which raises 2 questions:
 1. What are the termios settings of the tty receiving input? Is it 'raw'
mode or typical terminal mode (icanon, echo, etc.) or something else?
In my test code, I open the tty like
  fd = open(/dev/ttyACM0, O_RDWR | O_NOCTTY | O_NONBLOCK);
I don't make any other changes to the default settings. To be honest,
I'm not sure in which mode it is operating then (I was assuming raw, but
I might be wrong?).

 2. Are there RT threads that are hogging cpu time?
I can't see any, I think the only thing which occasionally goes to RT is
pulseaudio (but during at least some of the tests I wasn't even playing
audio, so that sounds very unplausible to me). I also cannot see a
correlation between failure rate and CPU load.

Best regards,
Sven



signature.asc
Description: OpenPGP digital signature


Re: [PATCH v5 4/6] usb: interface authorization: Introduces the USB interface authorization.

2015-07-22 Thread Greg KH
On Thu, Jun 18, 2015 at 07:23:24PM +0200, Stefan Koch wrote:
 The kernel supports the device authorization because of wireless USB.
 These is usable for wired USB devices, too.
 These new interface authorization allows to enable or disable
 individual interfaces instead a whole device.
 
 If a deauthorized interface will be authorized so the driver probing must
 be triggered manually by writing INTERFACE to /sys/bus/usb/drivers_probe
 
 Signed-off-by: Stefan Koch sk...@suse.de
 ---
  drivers/usb/core/message.c | 46 
 ++
  drivers/usb/core/usb.h |  2 ++
  2 files changed, 48 insertions(+)
 
 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
 index 1e85f62..b1b2772 100644
 --- a/drivers/usb/core/message.c
 +++ b/drivers/usb/core/message.c
 @@ -1555,6 +1555,52 @@ static void usb_release_interface(struct device *dev)
   kfree(intf);
  }
  
 +/*
 + * usb_deauthorize_interface - deauthorize an USB interface
 + *
 + * @intf: USB interface structure
 + *
 + * Returns: 0 at success, 0 at failure

This comment isn't true, it only returns 0.  So why have it return
anything?


 + */
 +int usb_deauthorize_interface(struct usb_interface *intf)
 +{
 + struct device *dev = intf-dev;
 +
 + device_lock(dev-parent);
 +
 + if (intf-authorized) {
 + device_lock(dev);
 + intf-authorized = 0;
 + device_unlock(dev);
 +
 + usb_forced_unbind_intf(intf);
 + }
 +
 + device_unlock(dev-parent);
 +
 + return 0;
 +}
 +
 +/*
 + * usb_authorize_interface - authorize an USB interface
 + *
 + * @intf: USB interface structure
 + *
 + * Returns: 0 at success, 0 at failure

Same here, this isn't correct.

thanks,

greg k-h
--
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


Re: [PATCH v5 3/6] usb: interface authorization: Control interface probing and claiming

2015-07-22 Thread Greg KH
On Thu, Jun 18, 2015 at 07:23:23PM +0200, Stefan Koch wrote:
 Driver probings and interface claims get rejected
 if an interface is not authorized.
 
 Signed-off-by: Stefan Koch sk...@suse.de
 ---
  drivers/usb/core/driver.c | 11 +++
  1 file changed, 11 insertions(+)
 
 diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
 index 818369a..3344daf 100644
 --- a/drivers/usb/core/driver.c
 +++ b/drivers/usb/core/driver.c
 @@ -295,6 +295,13 @@ static int usb_probe_interface(struct device *dev)
   if (udev-authorized == 0) {
   dev_err(intf-dev, Device is not authorized for usage\n);
   return error;
 + } else if (intf-authorized == 0) {
 + unsigned intf_num = intf-altsetting-desc.bInterfaceNumber;
 +
 + dev_err(intf-dev, Interface %d is not authorized for 
 usage\n,
 + intf_num);

A temporary variable isn't really needed.
--
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


Re: [Patch V4 1/3] usb: Add Xen pvUSB protocol description

2015-07-22 Thread Greg KH
On Tue, Jun 23, 2015 at 08:53:23AM +0200, Juergen Gross wrote:
 Add the definition of pvUSB protocol used between the pvUSB frontend in
 a Xen domU and the pvUSB backend in a Xen driver domain (usually Dom0).
 
 This header was originally provided by Fujitsu for Xen based on Linux
 2.6.18.
 
 Changes are:
 - adapt to Linux style guide
 
 Signed-off-by: Juergen Gross jgr...@suse.com
 ---
  include/xen/interface/io/usbif.h | 252 
 +++

Why is this a different interface than the existing ones we have today
(i.e. usbip?)  Where is it documented?  Do the Xen developers /
maintainers agree with this interface and code?  I need their sign-off
before I can accept such a thing.

thanks,

greg k-h
--
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


Re: [RFC PATCH 1/1] Add a usbredir kernel module to remotely connect USB devices over IP.

2015-07-22 Thread Jeremy White

On 07/22/2015 12:59 PM, Sean O. Stalley wrote:

On Wed, Jul 22, 2015 at 11:55:32AM -0500, Jeremy White wrote:

I privately wrote to the Intel authors of that patch a week ago; I've
publicly included them in this thread as well.  As far as I can tell,
they've been silent on this front since November; I fear that they may
have moved on, or that Intel is not actively working on this.  None of
the Intel authors listed on the MA-USB specification are kernel
contributors, so I did not have a way to reach out to them.  If you have
the means to engage others, I would appreciate that.


Sorry for the delay. The short answer is: Yes, we have been actively working on 
this driver.
Per Greg KH's request, we have been cleaning up the driver internally.
There was a lot to clean up, which is why we have been silent on LKML.


Great, thanks.  I would appreciate a chance to work with you to make 
sure it will work well for XSpice.  I'm happy to help as much as I can, 
and please don't feel the need to wait for a final version before 
reaching out to me.


Cheers,

Jeremy
--
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


Re: [PATCH v5 1/6] usb: interface authorization: Declare authorized attribute

2015-07-22 Thread Greg KH
On Thu, Jun 18, 2015 at 07:23:21PM +0200, Stefan Koch wrote:
 The attribute authorized shows the authorization state for an interface.
 
 Signed-off-by: Stefan Koch sk...@suse.de
 ---
  include/linux/usb.h | 1 +
  1 file changed, 1 insertion(+)
 
 diff --git a/include/linux/usb.h b/include/linux/usb.h
 index 447fe29..135c50c 100644
 --- a/include/linux/usb.h
 +++ b/include/linux/usb.h
 @@ -178,6 +178,7 @@ struct usb_interface {
   unsigned needs_altsetting0:1;   /* switch to altsetting 0 is pending */
   unsigned needs_binding:1;   /* needs delayed unbind/rebind */
   unsigned resetting_device:1;/* true: bandwidth alloc after reset */
 + unsigned authorized:1;  /* used for interface authorization */

Any reason you didn't line up the comments here?

thanks,

greg k-h
--
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


Re: [PATCH v5 2/6] usb: interface authorization: Introduces the default interface authorization

2015-07-22 Thread Greg KH
On Thu, Jun 18, 2015 at 07:23:22PM +0200, Stefan Koch wrote:
 Interfaces are allowed per default.
 This can disabled or enabled (again) by writing 0 or 1 to
 /sys/bus/usb/devices/usbX/interface_authorized_default
 
 Signed-off-by: Stefan Koch sk...@suse.de
 ---
  drivers/usb/core/hcd.c | 52 
 ++
  drivers/usb/core/message.c |  2 ++
  include/linux/usb/hcd.h|  3 +++
  3 files changed, 57 insertions(+)
 
 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
 index 45a915c..4ceb753 100644
 --- a/drivers/usb/core/hcd.c
 +++ b/drivers/usb/core/hcd.c
 @@ -882,9 +882,58 @@ static ssize_t authorized_default_store(struct device 
 *dev,
  }
  static DEVICE_ATTR_RW(authorized_default);
  
 +/*
 + * interface_authorized_default_show - show default authorization status
 + * for USB interfaces
 + *
 + * note: interface_auhorized_default is the default value
 + *   for initializing the authorized attribute of interfaces
 + */
 +static ssize_t interface_authorized_default_show(struct device *dev,
 + struct device_attribute *attr, char *buf)
 +{
 + struct usb_device *usb_dev = to_usb_device(dev);
 + struct usb_hcd *hcd = bus_to_hcd(usb_dev-bus);
 + unsigned def = HCD_INTERFACE_AUTHORIZED_DEFAULT(hcd) ? 1 : 0;
 +
 + return sprintf(buf, %u\n, def);
 +}
 +
 +/*
 + * interface_authorized_default_store - store default authorization status
 + * for USB interfaces
 + *
 + * note: interface_auhorized_default is the default value
 + *   for initializing the authorized attribute of interfaces
 + */
 +static ssize_t interface_authorized_default_store(struct device *dev,
 + struct device_attribute *attr, const char *buf, size_t count)
 +{
 + struct usb_device *usb_dev = to_usb_device(dev);
 + struct usb_hcd *hcd = bus_to_hcd(usb_dev-bus);
 + int rc = count;
 + bool val;
 +
 + if (strtobool(buf, val) != 0)
 + return -EINVAL;
 +
 + switch (val) {
 + case 0:
 + clear_bit(HCD_FLAG_INTERFACE_AUTHORIZED_DEFAULT, hcd-flags);
 + break;
 + case 1:
 + set_bit(HCD_FLAG_INTERFACE_AUTHORIZED_DEFAULT, hcd-flags);
 + break;
 + }
 +
 + return rc;
 +}
 +static DEVICE_ATTR_RW(interface_authorized_default);
 +
  /* Group all the USB bus attributes */
  static struct attribute *usb_bus_attrs[] = {
   dev_attr_authorized_default.attr,
 + dev_attr_interface_authorized_default.attr,
   NULL,
  };
  
 @@ -2679,6 +2728,9 @@ int usb_add_hcd(struct usb_hcd *hcd,
   hcd-authorized_default = authorized_default;
   set_bit(HCD_FLAG_HW_ACCESSIBLE, hcd-flags);
  
 + /* per default all interfaces are authorized */
 + set_bit(HCD_FLAG_INTERFACE_AUTHORIZED_DEFAULT, hcd-flags);
 +
   /* HC is in reset state, but accessible.  Now do the one-time init,
* bottom up so that hcds can customize the root hubs before hub_wq
* starts talking to them.  (Note, bus id is assigned early too.)
 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
 index f368d20..1e85f62 100644
 --- a/drivers/usb/core/message.c
 +++ b/drivers/usb/core/message.c
 @@ -1807,6 +1807,8 @@ free_interfaces:
   intfc = cp-intf_cache[i];
   intf-altsetting = intfc-altsetting;
   intf-num_altsetting = intfc-num_altsetting;
 + intf-authorized =
 + HCD_INTERFACE_AUTHORIZED_DEFAULT(hcd) ? 1 : 0;
   kref_get(intfc-ref);
  
   alt = usb_altnum_to_altsetting(intf, 0);
 diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h
 index 68b1e83..93c19b2 100644
 --- a/include/linux/usb/hcd.h
 +++ b/include/linux/usb/hcd.h
 @@ -120,6 +120,7 @@ struct usb_hcd {
  #define HCD_FLAG_WAKEUP_PENDING  4   /* root hub is 
 resuming? */
  #define HCD_FLAG_RH_RUNNING  5   /* root hub is running? */
  #define HCD_FLAG_DEAD6   /* controller has died? 
 */
 +#define HCD_FLAG_INTERFACE_AUTHORIZED_DEFAULT8

Why not pick 7?

And that's a huge name, how about 'HCD_FLAG_INTF_AUTHORIZED'?

--
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


Re: [PATCH v5 5/6] usb: interface authorization: SysFS part of USB interface authorization.

2015-07-22 Thread Greg KH
On Thu, Jun 18, 2015 at 07:23:25PM +0200, Stefan Koch wrote:
 This introduces an attribute for each interface to
 authorize (1) or deauthorize (0) it:
 /sys/bus/usb/devices/INTERFACE/authorized
 
 Signed-off-by: Stefan Koch sk...@suse.de
 ---
  drivers/usb/core/sysfs.c | 41 +
  1 file changed, 41 insertions(+)
 
 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
 index d269738..457bff5 100644
 --- a/drivers/usb/core/sysfs.c
 +++ b/drivers/usb/core/sysfs.c
 @@ -926,6 +926,46 @@ static ssize_t supports_autosuspend_show(struct device 
 *dev,
  }
  static DEVICE_ATTR_RO(supports_autosuspend);
  
 +/*
 + * interface_authorized_show - show authorization status of an USB interface
 + * 1 is authorized, 0 is deauthorized
 + */
 +static ssize_t interface_authorized_show(struct device *dev,
 + struct device_attribute *attr, char *buf)
 +{
 + struct usb_interface *intf = to_usb_interface(dev);
 +
 + return sprintf(buf, %u\n, intf-authorized);
 +}
 +
 +/*
 + * interface_authorized_store - authorize or deauthorize an USB interface
 + * 1 is to authorize, 0 is to deauthorize

Not only 1/0, but Y/N, y/n and other combinations that strtobool
handles.
No need to have this comment line at all.


 + */
 +static ssize_t interface_authorized_store(struct device *dev,
 + struct device_attribute *attr, const char *buf, size_t count)
 +{
 + struct usb_interface *intf = to_usb_interface(dev);
 + bool val;
 +
 + if (strtobool(buf, val) != 0)
 + return -EINVAL;
 +
 + switch (val) {
 + case 0:

true and false as this is a boolean?

And because it is, just turn this into a simple if/else statement, it's
less lines.


 + usb_deauthorize_interface(intf);
 + break;
 + case 1:
 + usb_authorize_interface(intf);
 + break;
 + }
 +
 + return count;
 +}
 +static struct device_attribute dev_attr_interface_authorized =
 + __ATTR(authorized, S_IRUGO | S_IWUSR,

__ATTR_RW()?

--
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


Re: [PATCH v7 00/23] usb gadget update for OTG 2.0

2015-07-22 Thread Li Jun
On Wed, Jul 22, 2015 at 10:13:08AM -0500, Felipe Balbi wrote:
 On Thu, Jul 09, 2015 at 03:18:37PM +0800, Li Jun wrote:
  Change for v7:
  - Free otg descriptor when failure of bind in patch 21, 22, 23.
add Roger's Reviewed-by for patch 10~20.
  - Choose the lesser otg-rev if otg-rev has been set before update by DT,
remove 0x0300 in supported otg-rev list, and add code comments in case
otg-rev is not passed in DT in patch 7.
  - Fail chipidea usb initilization if DT pass an unsupported otg-rev in 
  patch 8.
  
  Change for v6:
  - Change of_usb_set_otg_caps to be of_usb_update_otg_caps, and add
sanity check of otg-rev.
  - Add chipidea otg-rev ability to be 0x0200, which will be updated
in DT, if not passed, will be reset to be 0.
  - Remove unnecessary change: move config's descriptor and bmAttributes
init from xxxi_config() to xxx_bind() in leagcy gadget drivers.
  
  This is a follow-up of Macpaul Lin's previous patchset to resolve usb
  gadget driver working with OTG 2.0, and set otg features by not only
  usb driver config but also usb hardware property in DT, main changes:
  1. Add usb_otg20_descriptor definition for OTG 2.0 which introduces bcdOTG
 field for otg revision, bcdOTG can be passed via device tree.
  2. OTG features(SRP/HNP/ADP) can be decided by combination of usb HW
 properties and usb driver config.
  3. Change the chipidea usb driver to use the updated mechanism.
  4. Remove static usb otg descriptor definition, but allocate and init it
 according to otg capabilities in each gadget driver, if otg capabilities
 is not defined for legacy platforms, the usb otg descriptor content is
 kept the same as current static definition.
  
  Li Jun (19):
usb: otg: add usb_otg_caps structure for otg capabilities
doc: dt-binding: usb: add otg related properties
usb: common: add API to update usb otg capabilities by device tree
usb: chipidea: set usb otg capabilities
usb: chipidea: update ci_otg_is_fsm_mode conditions
usb: gadget: add usb otg descriptor allocate and init interface
usb: gadget: configfs: allocate and init otg descriptor by otg
  capabilities
usb: gadget: ether: allocate and init otg descriptor by otg
  capabilities
usb: gadget: acm_ms: allocate and init otg descriptor by otg
  capabilities
usb: gadget: audio: allocate and init otg descriptor by otg
  capabilities
usb: gadget: cdc2: allocate and init otg descriptor by otg
  capabilities
usb: gadget: g_ffs: allocate and init otg descriptor by otg
  capabilities
usb: gadget: hid: allocate and init otg descriptor by otg capabilities
usb: gadget: mass_storage: allocate and init otg descriptor by otg
  capabilities
usb: gadget: multi: allocate and init otg descriptor by otg
  capabilities
usb: gadget: ncm: allocate and init otg descriptor by otg capabilities
usb: gadget: printer: allocate and init otg descriptor by otg
  capabilities
usb: gadget: serial: allocate and init otg descriptor by otg
  capabilities
usb: gadget: zero: allocate and init otg descriptor by otg
  capabilities
  
  Macpaul Lin (4):
usb: add usb_otg20_descriptor for OTG 2.0 and above
usb: add USB_OTG_ADP definition
usb: add usb_otg_caps to usb_gadget structure.
usb: gadget: composite: add USB_DT_OTG request handling
 
 ok, so how you guys want to handle this series ? Should I take
 everything through my tree ? I'd need Acked-by for all chipidea drivers
 if that's the case.
 
 -- 
 balbi

I will resend the whole series with a small fix and Peter's ACK for
chipidea part.

Li Jun


--
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 v3 4/5] xhci: mediatek: support MTK xHCI host controller

2015-07-22 Thread Chunfeng Yun
MTK xhci host controller defines some extra SW scheduling
parameters for HW to minimize the scheduling effort for
synchronous and interrupt endpoints. The parameters are
put into reseved DWs of slot context and endpoint context

Signed-off-by: Chunfeng Yun chunfeng@mediatek.com
---
 drivers/usb/host/Kconfig|   9 +
 drivers/usb/host/Makefile   |   4 +
 drivers/usb/host/xhci-mtk-sch.c | 436 +
 drivers/usb/host/xhci-mtk.c | 836 
 drivers/usb/host/xhci-mtk.h | 135 +++
 drivers/usb/host/xhci-ring.c|  35 +-
 drivers/usb/host/xhci.c |  19 +-
 drivers/usb/host/xhci.h |   1 +
 8 files changed, 1468 insertions(+), 7 deletions(-)
 create mode 100644 drivers/usb/host/xhci-mtk-sch.c
 create mode 100644 drivers/usb/host/xhci-mtk.c
 create mode 100644 drivers/usb/host/xhci-mtk.h

diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 8afc3c1..358ab6d 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -34,6 +34,15 @@ config USB_XHCI_PCI
 config USB_XHCI_PLATFORM
tristate
 
+config USB_XHCI_MTK
+   tristate xHCI support for Mediatek MT65xx
+   select MFD_SYSCON
+   depends on ARCH_MEDIATEK || COMPILE_TEST
+   ---help---
+ Say 'Y' to enable the support for the xHCI host controller
+ found in Mediatek MT65xx SoCs.
+ If unsure, say N.
+
 config USB_XHCI_MVEBU
tristate xHCI support for Marvell Armada 375/38x
select USB_XHCI_PLATFORM
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index 754efaa..00401f9 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -13,6 +13,9 @@ fhci-$(CONFIG_FHCI_DEBUG) += fhci-dbg.o
 xhci-hcd-y := xhci.o xhci-mem.o
 xhci-hcd-y += xhci-ring.o xhci-hub.o xhci-dbg.o
 xhci-hcd-y += xhci-trace.o
+ifneq ($(CONFIG_USB_XHCI_MTK), )
+   xhci-hcd-y += xhci-mtk-sch.o
+endif
 
 xhci-plat-hcd-y := xhci-plat.o
 ifneq ($(CONFIG_USB_XHCI_MVEBU), )
@@ -30,6 +33,7 @@ endif
 
 obj-$(CONFIG_USB_XHCI_PCI) += xhci-pci.o
 obj-$(CONFIG_USB_XHCI_PLATFORM) += xhci-plat-hcd.o
+obj-$(CONFIG_USB_XHCI_MTK) += xhci-mtk.o
 
 obj-$(CONFIG_USB_EHCI_HCD) += ehci-hcd.o
 obj-$(CONFIG_USB_EHCI_PCI) += ehci-pci.o
diff --git a/drivers/usb/host/xhci-mtk-sch.c b/drivers/usb/host/xhci-mtk-sch.c
new file mode 100644
index 000..d4b41a6
--- /dev/null
+++ b/drivers/usb/host/xhci-mtk-sch.c
@@ -0,0 +1,436 @@
+/*
+ * Copyright (c) 2015 MediaTek Inc.
+ * Author:
+ *  Zhigang.Wei zhigang@mediatek.com
+ *  Chunfeng.Yun chunfeng@mediatek.com
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include linux/kernel.h
+#include linux/module.h
+#include linux/slab.h
+
+#include xhci.h
+#include xhci-mtk.h
+
+#define SS_BW_BOUNDARY 51000
+/* table 5-5. High-speed Isoc Transaction Limits in usb_20 spec */
+#define HS_BW_BOUNDARY 6144
+/* usb2 spec section11.18.1: at most 188 FS bytes per microframe */
+#define FS_PAYLOAD_MAX 188
+
+/* mtk scheduler bitmasks */
+#define EP_BPKTS(p)((p)  0x3f)
+#define EP_BCSCOUNT(p) (((p)  0x7)  8)
+#define EP_BBM(p)  ((p)  11)
+#define EP_BOFFSET(p)  ((p)  0x3fff)
+#define EP_BREPEAT(p)  (((p)  0x7fff)  16)
+
+static int is_fs_or_ls(enum usb_device_speed speed)
+{
+   return speed == USB_SPEED_FULL || speed == USB_SPEED_LOW;
+}
+
+static int get_bw_index(struct xhci_hcd *xhci, struct usb_device *udev,
+   struct usb_host_endpoint *ep)
+{
+   int bw_index;
+   int port_id;
+   struct xhci_virt_device *virt_dev;
+
+   virt_dev = xhci-devs[udev-slot_id];
+   port_id = virt_dev-real_port;
+
+   if (udev-speed == USB_SPEED_SUPER) {
+   if (usb_endpoint_dir_out(ep-desc))
+   bw_index = (port_id - 1) * 2;
+   else
+   bw_index = (port_id - 1) * 2 + 1;
+   } else {
+   bw_index = port_id + xhci-num_usb3_ports - 1;
+   }
+
+   return bw_index;
+}
+
+static void setup_sch_info(struct usb_device *udev,
+   struct xhci_ep_ctx *ep_ctx, struct mu3h_sch_ep_info *sch_ep)
+{
+   u32 ep_type;
+   u32 ep_interval;
+   u32 max_packet_size;
+   u32 max_burst;
+   u32 mult;
+   u32 esit_pkts;
+
+   ep_type = CTX_TO_EP_TYPE(le32_to_cpu(ep_ctx-ep_info2));
+   ep_interval = CTX_TO_EP_INTERVAL(le32_to_cpu(ep_ctx-ep_info));
+   max_packet_size = MAX_PACKET_DECODED(le32_to_cpu(ep_ctx-ep_info2));
+   max_burst = CTX_TO_MAX_BURST(le32_to_cpu(ep_ctx-ep_info2));
+   mult = 

[no subject]

2015-07-22 Thread Chunfeng Yun
From ac1e8724bfa47494223bad0af450c1a63cd2fe0c Mon Sep 17 00:00:00 2001
From: Chunfeng Yun chunfeng@mediatek.com
Date: Wed, 22 Jul 2015 21:15:15 +0800
Subject: [PATCH 0/5] *** SUBJECT HERE ***

The patch supports MediaTek's xHCI controller.

There are some differences from xHCI spec:
1. The interval is specified in 250 * 8ns increments for Interrupt Moderation
Interval(IMODI) of the Interrupter Moderation(IMOD) register, it is 8 times as
much as that defined in xHCI spec.

2. For the value of TD Size in Normal TRB, MTK's xHCI controller defines a
number of packets that remain to be transferred for a TD after processing all
Max packets in all previous TRBs,that means don't include the current TRB's,
but in xHCI spec it includes the current ones.

3. To minimize the scheduling effort for synchronous endpoints in xHC, the MTK
architecture defines some extra SW scheduling parameters for HW. According to
these parameters provided by SW, the xHC can easily decide whether a
synchronous endpoint should be scheduled in a specific uFrame. The extra SW
scheduling parameters are put into reserved DWs in Slot and Endpoint Context.
And a bandwidth scheduler algorithm is added to support such feature.

A usb3.0 phy driver is also added which used by mt65xx SoCs platform, it
supports two usb2.0 ports and one usb3.0 port.

Change in v3:
1. implement generic phy
2. move opperations for IPPC and wakeup from phy driver to xHCI driver
3. seperate quirk functions into a single C file to fix up dependence issue

Chunfeng Yun (5):
  dt-bindings: Add usb3.0 phy binding for MT65xx SoCs
  dt-bindings: Add a binding for Mediatek xHCI host controller
  usb: phy: add usb3.0 phy driver for mt65xx SoCs
  xhci: mediatek: support MTK xHCI host controller
  arm64: dts: mediatek: add xHCI  usb phy for mt8173

 .../devicetree/bindings/phy/phy-mt65xx-u3.txt  |  21 +
 .../devicetree/bindings/usb/mt8173-xhci.txt|  50 ++
 arch/arm64/boot/dts/mediatek/mt8173-evb.dts|  15 +
 arch/arm64/boot/dts/mediatek/mt8173.dtsi   |  31 +
 drivers/phy/Kconfig|   9 +
 drivers/phy/Makefile   |   1 +
 drivers/phy/phy-mt65xx-usb3.c  | 426 +++
 drivers/usb/host/Kconfig   |   9 +
 drivers/usb/host/Makefile  |   4 +
 drivers/usb/host/xhci-mtk-sch.c| 436 +++
 drivers/usb/host/xhci-mtk.c| 836 +
 drivers/usb/host/xhci-mtk.h| 135 
 drivers/usb/host/xhci-ring.c   |  35 +-
 drivers/usb/host/xhci.c|  19 +-
 drivers/usb/host/xhci.h|   1 +
 15 files changed, 2021 insertions(+), 7 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/phy/phy-mt65xx-u3.txt
 create mode 100644 Documentation/devicetree/bindings/usb/mt8173-xhci.txt
 create mode 100644 drivers/phy/phy-mt65xx-usb3.c
 create mode 100644 drivers/usb/host/xhci-mtk-sch.c
 create mode 100644 drivers/usb/host/xhci-mtk.c
 create mode 100644 drivers/usb/host/xhci-mtk.h

--
1.8.1.1.dirty

In-Reply-To: 

--
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 v3 5/5] arm64: dts: mediatek: add xHCI usb phy for mt8173

2015-07-22 Thread Chunfeng Yun
add xHCI and phy drivers for MT8173-EVB

Signed-off-by: Chunfeng Yun chunfeng@mediatek.com
---
 arch/arm64/boot/dts/mediatek/mt8173-evb.dts | 15 ++
 arch/arm64/boot/dts/mediatek/mt8173.dtsi| 31 +
 2 files changed, 46 insertions(+)

diff --git a/arch/arm64/boot/dts/mediatek/mt8173-evb.dts 
b/arch/arm64/boot/dts/mediatek/mt8173-evb.dts
index f433c21..202b2b9 100644
--- a/arch/arm64/boot/dts/mediatek/mt8173-evb.dts
+++ b/arch/arm64/boot/dts/mediatek/mt8173-evb.dts
@@ -13,6 +13,7 @@
  */
 
 /dts-v1/;
+#include dt-bindings/gpio/gpio.h
 #include mt8173.dtsi
 
 / {
@@ -32,6 +33,15 @@
};
 
chosen { };
+
+   usb_p1_vbus: fixedregulator@0 {
+   compatible = regulator-fixed;
+   regulator-name = usb_vbus;
+   regulator-min-microvolt = 500;
+   regulator-max-microvolt = 500;
+   gpio = pio 130 GPIO_ACTIVE_HIGH;
+   enable-active-high;
+   };
 };
 
 pwrap {
@@ -211,3 +221,8 @@
 uart0 {
status = okay;
 };
+
+usb {
+   vusb33-supply = mt6397_vusb_reg;
+   vbus-supply = usb_p1_vbus;
+};
diff --git a/arch/arm64/boot/dts/mediatek/mt8173.dtsi 
b/arch/arm64/boot/dts/mediatek/mt8173.dtsi
index 0696f8f..aa1ecc7 100644
--- a/arch/arm64/boot/dts/mediatek/mt8173.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt8173.dtsi
@@ -14,6 +14,7 @@
 #include dt-bindings/clock/mt8173-clk.h
 #include dt-bindings/interrupt-controller/irq.h
 #include dt-bindings/interrupt-controller/arm-gic.h
+#include dt-bindings/power/mt8173-power.h
 #include dt-bindings/reset-controller/mt8173-resets.h
 #include mt8173-pinfunc.h
 
@@ -393,6 +394,36 @@
#size-cells = 0;
status = disabled;
};
+
+   usb: usb30@1127 {
+   compatible = mediatek,mt8173-xhci;
+   reg = 0 0x1127 0 0x4000,
+ 0 0x1128 0 0x0800;
+   interrupts = GIC_SPI 115 IRQ_TYPE_LEVEL_LOW;
+   power-domains = scpsys MT8173_POWER_DOMAIN_USB;
+   clocks = topckgen CLK_TOP_USB30_SEL,
+pericfg CLK_PERI_USB0,
+pericfg CLK_PERI_USB1;
+   clock-names = sys_mac,
+ wakeup_deb_p0,
+ wakeup_deb_p1;
+   phys = u3phy 0, u3phy 1;
+   phy-names = phy-0, phy-1;
+   usb3-lpm-capable;
+   mediatek,usb-wakeup = pericfg;
+   mediatek,wakeup-src = 1;
+   mediatek,u2port-num = 2;
+   status = okay;
+   };
+
+   u3phy: usb-phy@1129 {
+   compatible = mediatek,mt8173-u3phy;
+   reg = 0 0x1129 0 0x3000;
+   clocks = apmixedsys CLK_APMIXED_REF2USB_TX;
+   clock-names = u3phya_ref;
+   #phy-cells = 1;
+   status = okay;
+   };
};
 };
 
-- 
1.8.1.1.dirty

--
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 v3 2/5] dt-bindings: Add a binding for Mediatek xHCI host controller

2015-07-22 Thread Chunfeng Yun
add a DT binding documentation of xHCI host controller for the
MT8173 SoC from Mediatek.

Signed-off-by: Chunfeng Yun chunfeng@mediatek.com
---
 .../devicetree/bindings/usb/mt8173-xhci.txt| 50 ++
 1 file changed, 50 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/mt8173-xhci.txt

diff --git a/Documentation/devicetree/bindings/usb/mt8173-xhci.txt 
b/Documentation/devicetree/bindings/usb/mt8173-xhci.txt
new file mode 100644
index 000..94d
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/mt8173-xhci.txt
@@ -0,0 +1,50 @@
+MT65XX xhci
+
+The device node for Mediatek SOC usb3.0 host controller
+
+Required properties:
+ - compatible : supports mediatek,mt8173-xhci
+ - reg: Offset and length of registers
+ - interrupts : Interrupt mode, number and trigger mode
+ - power-domains: to enable usb's mtcmos
+ - vusb33-supply:  regulator of usb avdd3.3v
+ - clocks : must support all clocks that xhci needs
+ - clock-names: should be sys_mac for sys and mac clocks, and
+   wakeup_deb_p0, wakeup_deb_p1 for wakeup debounce control
+   clocks
+ - phys: the phys that xhci will bind, currently supports up to two
+   phys, so phy index should not greater than one.
+ - phy-names : should be phy-X format, X equals to 0 or 1
+ - usb3-lpm-capable: supports USB3 LPM
+ - mediatek,usb-wakeup: to access usb wakeup control register
+ - mediatek,wakeup-src: 1: ip sleep wakeup mode; 2: line state wakeup
+   mode; others means don't enable wakeup source of usb
+ - mediatek,u2port-num: the number should not greater than the number
+   of phys
+
+Optional properties:
+ - vbus-supply : reference to the VBUS regulator;
+
+Example:
+usb: usb30@1127 {
+   compatible = mediatek,mt8173-xhci;
+   reg = 0 0x1127 0 0x4000,
+ 0 0x1128 0 0x0800;
+   interrupts = GIC_SPI 115 IRQ_TYPE_LEVEL_LOW;
+   power-domains = scpsys MT8173_POWER_DOMAIN_USB;
+   clocks = topckgen CLK_TOP_USB30_SEL,
+pericfg CLK_PERI_USB0,
+pericfg CLK_PERI_USB1;
+   clock-names = sys_mac,
+ wakeup_deb_p0,
+ wakeup_deb_p1;
+   phys = u3phy 0, u3phy 1;
+   phy-names = phy-0, phy-1;
+   vusb33-supply = mt6397_vusb_reg;
+   vbus-supply = usb_p1_vbus;
+   usb3-lpm-capable;
+   mediatek,usb-wakeup = pericfg;
+   mediatek,wakeup-src = 1;
+   mediatek,u2port-num = 2;
+   status = okay;
+};
-- 
1.8.1.1.dirty

--
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


Re: [PATCH v3 2/5] dt-bindings: Add a binding for Mediatek xHCI host controller

2015-07-22 Thread Mark Rutland
On Wed, Jul 22, 2015 at 03:05:42PM +0100, Chunfeng Yun wrote:
 add a DT binding documentation of xHCI host controller for the
 MT8173 SoC from Mediatek.
 
 Signed-off-by: Chunfeng Yun chunfeng@mediatek.com
 ---
  .../devicetree/bindings/usb/mt8173-xhci.txt| 50 
 ++
  1 file changed, 50 insertions(+)
  create mode 100644 Documentation/devicetree/bindings/usb/mt8173-xhci.txt
 
 diff --git a/Documentation/devicetree/bindings/usb/mt8173-xhci.txt 
 b/Documentation/devicetree/bindings/usb/mt8173-xhci.txt
 new file mode 100644
 index 000..94d
 --- /dev/null
 +++ b/Documentation/devicetree/bindings/usb/mt8173-xhci.txt
 @@ -0,0 +1,50 @@
 +MT65XX xhci
 +
 +The device node for Mediatek SOC usb3.0 host controller
 +
 +Required properties:
 + - compatible : supports mediatek,mt8173-xhci
 + - reg: Offset and length of registers

Your example has multiple reg entries.

Please list what each entry is, and the order you expect them in.

 + - interrupts : Interrupt mode, number and trigger mode
 + - power-domains: to enable usb's mtcmos
 + - vusb33-supply:  regulator of usb avdd3.3v
 + - clocks : must support all clocks that xhci needs
 + - clock-names: should be sys_mac for sys and mac clocks, and
 + wakeup_deb_p0, wakeup_deb_p1 for wakeup debounce control
 + clocks
 + - phys  : the phys that xhci will bind, currently supports up to two
 + phys, so phy index should not greater than one.
 + - phy-names : should be phy-X format, X equals to 0 or 1

This seems somewhat pointless.

 + - usb3-lpm-capable: supports USB3 LPM
 + - mediatek,usb-wakeup: to access usb wakeup control register

What exactly does this property imply?

 + - mediatek,wakeup-src: 1: ip sleep wakeup mode; 2: line state wakeup
 + mode; others means don't enable wakeup source of usb

This sounds like configuration rather than a hardware property. Why do
you think this needs to be in the DT?

 + - mediatek,u2port-num: the number should not greater than the number
 + of phys

What exactly does this property imply?

Mark.

 +
 +Optional properties:
 + - vbus-supply : reference to the VBUS regulator;
 +
 +Example:
 +usb: usb30@1127 {
 + compatible = mediatek,mt8173-xhci;
 + reg = 0 0x1127 0 0x4000,
 +   0 0x1128 0 0x0800;
 + interrupts = GIC_SPI 115 IRQ_TYPE_LEVEL_LOW;
 + power-domains = scpsys MT8173_POWER_DOMAIN_USB;
 + clocks = topckgen CLK_TOP_USB30_SEL,
 +  pericfg CLK_PERI_USB0,
 +  pericfg CLK_PERI_USB1;
 + clock-names = sys_mac,
 +   wakeup_deb_p0,
 +   wakeup_deb_p1;
 + phys = u3phy 0, u3phy 1;
 + phy-names = phy-0, phy-1;
 + vusb33-supply = mt6397_vusb_reg;
 + vbus-supply = usb_p1_vbus;
 + usb3-lpm-capable;
 + mediatek,usb-wakeup = pericfg;
 + mediatek,wakeup-src = 1;
 + mediatek,u2port-num = 2;
 + status = okay;
 +};
 -- 
 1.8.1.1.dirty
 
--
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


Re: [PATCH] Fix data loss in cdc-acm

2015-07-22 Thread Peter Hurley
On 07/22/2015 04:40 AM, Oliver Neukum wrote:
 On Tue, 2015-07-21 at 12:45 -0400, Peter Hurley wrote:
 Let me know if you need help instrumenting the tty buffers/throttling
 to help figure out what the actual problem is.

 Regarding the patch itself, I have no opinion on the suitability of
 simply not resubmitting urbs. However, that is exactly how the
 throttle
 mechanism works, and the tty buffer API is specifically designed to
 allow drivers to manage flow via that interface as well (especially
 for high-throughput drivers).
 
 Could you please expand on how this is supposed to work?
 For once how does one learn that room is available again?

There are basically 3 mechanisms for managing rx data:
1. Allocate space when the data arrives; drop data if no space is avail
   and indicate buf_overrun. This is what most drivers do.
2. Allocate space when the data arrives; try to buffer uncopied data
   and resubmit the data later. Some high-throughput drivers (in the wild)
   do this (but less so now that the tty buffer space is configurable).
3. Pre-allocate space _before_ the data arrives (with 
tty_buffer_request_room());
   this is applicable to subsystems which know how much data can be in-flight
   at any one time. This guarantees that when rx data arrives buffer space is
   available (since it has already been allocated).

Drivers that use method 2 typically attempt to recopy the buffered data
when either new data arrives or @ unthrottle. I've seen others use deferred
work as well.

AFAIK no driver/subsystem is using method 3 for guaranteed delivery
of in-flight data, but it seems ideally suited to usb serial.

Regards,
Peter Hurley

--
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


[GIT PULL] USB fixes for v4.2-rc4

2015-07-22 Thread Felipe Balbi
Hi Greg,

A second fixes pull request, seems like there won't be any
more fixes coming through me; either that or I'll be proven
wrong :-)

cheers

The following changes since commit 52721d9d3334c1cb1f76219a161084094ec634dc:

  Linux 4.2-rc3 (2015-07-19 14:45:02 -0700)

are available in the git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git 
tags/fixes-for-v4.2-rc4

for you to fetch changes up to aebda618718157a69c0dc0adb978d69bc2b8723c:

  usb: dwc3: Reset the transfer resource index on SET_INTERFACE (2015-07-22 
08:52:42 -0500)


usb: fixes for v4.2-rc4

Only four fixes this time so I'll describe them all.

We have an iomen resource leak fix in mv_udc_core. This bug
exists since v3.3.

Renesas got a fix for how they use dma_map_single() with IOMMU.

The new ulpi bus got an ordering fix, so drivers don't try to
probe ahead of the bus.

And finally, we have a fix for a really old regression with
dwc3, one which could only be exposed by a recent patch from
Subbaraya. Basically, we were startving the controller of
transfer resources.

Signed-off-by: Felipe Balbi ba...@ti.com


Alexey Khoroshilov (1):
  usb: gadget: mv_udc_core: fix phy_regs I/O memory leak

John Youn (1):
  usb: dwc3: Reset the transfer resource index on SET_INTERFACE

Lu Baolu (1):
  usb: ulpi: ulpi_init should be executed in subsys_initcall

Yoshihiro Shimoda (1):
  usb: gadget: udc: core: Fix argument of dma_map_single for IOMMU

 drivers/usb/common/ulpi.c|  2 +-
 drivers/usb/dwc3/ep0.c   |  4 
 drivers/usb/gadget/udc/mv_udc_core.c |  2 +-
 drivers/usb/gadget/udc/udc-core.c| 14 --
 4 files changed, 14 insertions(+), 8 deletions(-)
--
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


Re: [RFC PATCH 1/1] Add a usbredir kernel module to remotely connect USB devices over IP.

2015-07-22 Thread Jeremy White

On 07/09/2015 05:06 AM, Alex Elsayed wrote:

Alan Stern wrote:


On Mon, 6 Jul 2015, Jeremy White wrote:


Anything else fundamental to usbip that should inform the design of a
usbredir driver?  usbip appears to be based off a 2004 vintage of
dummy_hcd.  I'll look thoughtfully at the current dummy_hcd; please let
me know if there is anything else I should consider.


One thing that springs to mind is USB-3 streams.  When dummy-hcd was
expanded to include USB-3, that was the major new ingredient.


Another thing that comes to mind is that the USB-IF has its own official
standard for this kind of thing now, called Media-Agnostic USB[1]. In
November of 2014 a driver[2] was posted, followed by a second version[3],
and it is apparently being refined inside Intel[4].

[1]
http://www.usb.org/developers/docs/devclass_docs/Media_Agnostic_USB_v1.0.zip
[2] http://thread.gmane.org/gmane.linux.kernel/1820297
[3] http://thread.gmane.org/gmane.linux.drivers.driver-project.devel/60498
[4] http://article.gmane.org/gmane.linux.drivers.driver-project.devel/60757


Thanks for the pointer, Alex.

I spent some time with the spec and their proposed code.  It does seem 
plausible that XSpice could use a mausb/usbredir protocol converter.  So 
if there was a mausb kernel module, I could potentially implement 
support in XSpice in user space and not need a usbredir module.


I sent an email to the two developers at Intel to ask if there had been 
any further progress and if I could collaborate with them. I have not 
heard back.


The MA spec is substantial and seems well thought out.  But the usbredir 
protocol has the virtue of being relatively mature - it's 5 years old, 
with code in daily use.


At this point it seems the best path forward is to continue work on the 
usbredir kernel module, which I will do unless I get some new information.


Cheers,

Jeremy
--
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 v3 3/5] usb: phy: add usb3.0 phy driver for mt65xx SoCs

2015-07-22 Thread Chunfeng Yun
support usb3.0 phy of mt65xx SoCs

Signed-off-by: Chunfeng Yun chunfeng@mediatek.com
---
 drivers/phy/Kconfig   |   9 +
 drivers/phy/Makefile  |   1 +
 drivers/phy/phy-mt65xx-usb3.c | 426 ++
 3 files changed, 436 insertions(+)
 create mode 100644 drivers/phy/phy-mt65xx-usb3.c

diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index c0e6ede..019cf8b 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -193,6 +193,15 @@ config PHY_HIX5HD2_SATA
help
  Support for SATA PHY on Hisilicon hix5hd2 Soc.
 
+config PHY_MT65XX_USB3
+   tristate Mediatek USB3.0 PHY Driver
+   depends on ARCH_MEDIATEK  OF
+   select GENERIC_PHY
+   help
+ Say 'Y' here to add support for Mediatek USB3.0 PHY driver
+ for mt65xx SoCs. it supports two usb2.0 ports and
+ one usb3.0 port.
+
 config PHY_SUN4I_USB
tristate Allwinner sunxi SoC USB PHY driver
depends on ARCH_SUNXI  HAS_IOMEM  OF
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index f344e1b..3ceff2a 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -22,6 +22,7 @@ obj-$(CONFIG_TI_PIPE3)+= 
phy-ti-pipe3.o
 obj-$(CONFIG_TWL4030_USB)  += phy-twl4030-usb.o
 obj-$(CONFIG_PHY_EXYNOS5250_SATA)  += phy-exynos5250-sata.o
 obj-$(CONFIG_PHY_HIX5HD2_SATA) += phy-hix5hd2-sata.o
+obj-$(CONFIG_PHY_MT65XX_USB3)  += phy-mt65xx-usb3.o
 obj-$(CONFIG_PHY_SUN4I_USB)+= phy-sun4i-usb.o
 obj-$(CONFIG_PHY_SUN9I_USB)+= phy-sun9i-usb.o
 obj-$(CONFIG_PHY_SAMSUNG_USB2) += phy-exynos-usb2.o
diff --git a/drivers/phy/phy-mt65xx-usb3.c b/drivers/phy/phy-mt65xx-usb3.c
new file mode 100644
index 000..5da4534
--- /dev/null
+++ b/drivers/phy/phy-mt65xx-usb3.c
@@ -0,0 +1,426 @@
+/*
+ * Copyright (c) 2015 MediaTek Inc.
+ * Author: Chunfeng.Yun chunfeng@mediatek.com
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include linux/clk.h
+#include linux/delay.h
+#include linux/io.h
+#include linux/module.h
+#include linux/of_address.h
+#include linux/of_device.h
+#include linux/of_gpio.h
+#include linux/of.h
+#include linux/phy/phy.h
+#include linux/platform_device.h
+#include linux/pm_runtime.h
+#include linux/regulator/consumer.h
+#include linux/resource.h
+
+/*
+ * for sifslv2 register
+ * relative to USB3_SIF2_BASE base address
+ */
+#define SSUSB_SIFSLV_SPLLC (0x)
+#define SSUSB_SIFSLV_U2PHY_COM_BASE(0x0800)
+#define SSUSB_SIFSLV_U3PHYD_BASE   (0x0900)
+#define SSUSB_USB30_PHYA_SIV_B_BASE(0x0b00)
+#define SSUSB_SIFSLV_U3PHYA_DA_BASE(0x0c00)
+
+/*port1 refs. +0x800(refer to port0)*/
+#define U3P_PORT_INTERVAL (0x800)  /*based on port0 */
+#define U3P_PHY_DELTA(index) ((U3P_PORT_INTERVAL) * (index))
+
+#define U3P_USBPHYACR0 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x)
+#define PA0_RG_U2PLL_FORCE_ON  (0x1  15)
+
+#define U3P_USBPHYACR2 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0008)
+#define PA2_RG_SIF_U2PLL_FORCE_EN  (0x1  18)
+
+#define U3P_USBPHYACR5 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0014)
+#define PA5_RG_U2_HSTX_SRCTRL  (0x7  12)
+#define PA5_RG_U2_HSTX_SRCTRL_VAL(x)   ((0x7  (x))  12)
+#define PA5_RG_U2_HS_100U_U3_EN(0x1  11)
+
+#define U3P_USBPHYACR6 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0018)
+#define PA6_RG_U2_ISO_EN   (0x1  31)
+#define PA6_RG_U2_BC11_SW_EN   (0x1  23)
+#define PA6_RG_U2_OTG_VBUSCMP_EN   (0x1  20)
+
+#define U3P_U2PHYACR4  (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0020)
+#define P2C_RG_USB20_GPIO_CTL  (0x1  9)
+#define P2C_USB20_GPIO_MODE(0x1  8)
+#define P2C_U2_GPIO_CTR_MSK(P2C_RG_USB20_GPIO_CTL | P2C_USB20_GPIO_MODE)
+
+#define U3D_U2PHYDCR0  (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0060)
+#define P2C_RG_SIF_U2PLL_FORCE_ON  (0x1  24)
+
+#define U3P_U2PHYDTM0  (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0068)
+#define P2C_FORCE_UART_EN  (0x1  26)
+#define P2C_FORCE_DATAIN   (0x1  23)
+#define P2C_FORCE_DM_PULLDOWN  (0x1  21)
+#define P2C_FORCE_DP_PULLDOWN  (0x1  20)
+#define P2C_FORCE_XCVRSEL  (0x1  19)
+#define P2C_FORCE_SUSPENDM (0x1  18)
+#define P2C_FORCE_TERMSEL  (0x1  17)
+#define P2C_RG_DATAIN  (0xf  10)
+#define P2C_RG_DATAIN_VAL(x)   ((0xf  (x))  10)
+#define P2C_RG_DMPULLDOWN  (0x1  7)
+#define P2C_RG_DPPULLDOWN  (0x1  6)
+#define P2C_RG_XCVRSEL (0x3  4)
+#define P2C_RG_XCVRSEL_VAL(x)  ((0x3  (x))  4)
+#define P2C_RG_SUSPENDM(0x1  3)
+#define P2C_RG_TERMSEL (0x1  2)
+#define P2C_DTM0_PART_MASK \
+ 

[PATCH v3 1/5] dt-bindings: Add usb3.0 phy binding for MT65xx SoCs

2015-07-22 Thread Chunfeng Yun
add a DT binding documentation of usb3.0 phy for MT65xx
SoCs from Mediatek.

Signed-off-by: Chunfeng Yun chunfeng@mediatek.com
---
 .../devicetree/bindings/phy/phy-mt65xx-u3.txt   | 21 +
 1 file changed, 21 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/phy-mt65xx-u3.txt

diff --git a/Documentation/devicetree/bindings/phy/phy-mt65xx-u3.txt 
b/Documentation/devicetree/bindings/phy/phy-mt65xx-u3.txt
new file mode 100644
index 000..752abc0
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/phy-mt65xx-u3.txt
@@ -0,0 +1,21 @@
+MT65xx USB3.0 PHY
+
+The device node for Mediatek SOC usb3.0 phy
+
+Required properties:
+ - compatible : Should be mediatek,mt8173-u3phy
+ - reg: Offset and length of registers for phy domain
+ - clocks : must support all clocks that phy need
+ - clock-names: should be u3phya_ref for u3phya reference clock.
+ - #phy-cells : must be 1 for the phy
+
+Example:
+
+u3phy: usb-phy@1129 {
+   compatible = mediatek,mt8173-u3phy;
+   reg = 0 0x1129 0 0x3000;
+   clocks = apmixedsys CLK_APMIXED_REF2USB_TX;
+   clock-names = u3phya_ref;
+   #phy-cells = 1;
+   status = okay;
+};
-- 
1.8.1.1.dirty

--
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


Re: xhci_hcd 0000:00:14.0: ERROR Transfer event TRB DMA ptr not part of current TD ep_index 2 comp_code 1

2015-07-22 Thread Arkadiusz Miskiewicz

[sorry, resend from different email - vger postmaster team has stupid filters 
in place]

On Tuesday 21 of July 2015, Mathias Nyman wrote:
 On 20.07.2015 23:13, Arkadiusz Miskiewicz wrote:
  On Saturday 18 of July 2015, Arkadiusz Miskiewicz wrote:
  Hi.
  
  I'm on 4.2.0-rc2-00077-gf760b87 kernel and while trying to copy some
  file from usb storage (sata disk behind sata-usb bridge or pendrive;
  hapens in
  
  both cases) copying process hangs just early after start with:
  Looks like suspend  resume is enough. Reloading bluetooth firmware done
  by kernel triggers problem:
  
  [  106.302783] rtc_cmos 00:02: System wakeup disabled by ACPI
  [  106.313280] PM: resume of devices complete after 3003.032 msecs
  [  106.314079] Restarting tasks ... done.
  [  106.326434] Bluetooth: hci0: read Intel version: 370710018002030d00
  [  106.330422] Bluetooth: hci0: Intel Bluetooth firmware file:
  intel/ibt-hw-37.7.10-fw-1.80.2.3.d.bseq [  106.398223] xhci_hcd
  :00:14.0: ERROR Transfer event TRB DMA ptr not part of current TD
  ep_index 0 comp_code 1
 
 Looks like we get an event for a really old transfer for some reason, it
 should probably be handled already.
 
 I got a patch that adds more paranoid checks for TRB cancel, which has been
 one major reasons for the Transfer event TRB DMA ptr not part of current
 TD Errors. It also adds some logging to show what's went wrong. (patch
 attached, applies on 4.2-rc3) Can you see if it helps?

It doesn't unfortunately. 4.2.0-rc3-00017-gd725e66 + that patch
- dmesg http://sprunge.us/PDIE

around 91s - after resume from ram bluetooth driver reloads

around 754s - tried to copy data from external usb disk


 If it doesn't, then adding xhci debugging could give us some clue:
 echo -n 'module xhci_hcd =p'  /sys/kernel/debug/dynamic_debug/control

Ok, http://sprunge.us/GiHX

mounted fs around 1347s and started copying; TRB problems were still there but 
file was being copied (in bursts)

 You said 3.19.3 works fine, but 4.0.8 and 4.2-rc2 fail, any chance you
 could bisect it?

Unfortunately some kernels around 3.19 don't even boot (grub says it loads 
initrd and no progress from that) - some commit fixed that but no idea which 
one.

 Thanks
 -Mathias

-- 
Arkadiusz Miśkiewicz, arekm / ( maven.pl | pld-linux.org )
--
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


Re: [PATCH v3 3/5] usb: phy: add usb3.0 phy driver for mt65xx SoCs

2015-07-22 Thread Felipe Balbi
Hi,

On Wed, Jul 22, 2015 at 10:05:43PM +0800, Chunfeng Yun wrote:
 support usb3.0 phy of mt65xx SoCs
 
 Signed-off-by: Chunfeng Yun chunfeng@mediatek.com

you missed Kishon here.

 ---
  drivers/phy/Kconfig   |   9 +
  drivers/phy/Makefile  |   1 +
  drivers/phy/phy-mt65xx-usb3.c | 426 
 ++
  3 files changed, 436 insertions(+)
  create mode 100644 drivers/phy/phy-mt65xx-usb3.c
 
 diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
 index c0e6ede..019cf8b 100644
 --- a/drivers/phy/Kconfig
 +++ b/drivers/phy/Kconfig
 @@ -193,6 +193,15 @@ config PHY_HIX5HD2_SATA
   help
 Support for SATA PHY on Hisilicon hix5hd2 Soc.
  
 +config PHY_MT65XX_USB3
 + tristate Mediatek USB3.0 PHY Driver
 + depends on ARCH_MEDIATEK  OF
 + select GENERIC_PHY
 + help
 +   Say 'Y' here to add support for Mediatek USB3.0 PHY driver
 +   for mt65xx SoCs. it supports two usb2.0 ports and
 +   one usb3.0 port.
 +
  config PHY_SUN4I_USB
   tristate Allwinner sunxi SoC USB PHY driver
   depends on ARCH_SUNXI  HAS_IOMEM  OF
 diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
 index f344e1b..3ceff2a 100644
 --- a/drivers/phy/Makefile
 +++ b/drivers/phy/Makefile
 @@ -22,6 +22,7 @@ obj-$(CONFIG_TI_PIPE3)  += 
 phy-ti-pipe3.o
  obj-$(CONFIG_TWL4030_USB)+= phy-twl4030-usb.o
  obj-$(CONFIG_PHY_EXYNOS5250_SATA)+= phy-exynos5250-sata.o
  obj-$(CONFIG_PHY_HIX5HD2_SATA)   += phy-hix5hd2-sata.o
 +obj-$(CONFIG_PHY_MT65XX_USB3)+= phy-mt65xx-usb3.o
  obj-$(CONFIG_PHY_SUN4I_USB)  += phy-sun4i-usb.o
  obj-$(CONFIG_PHY_SUN9I_USB)  += phy-sun9i-usb.o
  obj-$(CONFIG_PHY_SAMSUNG_USB2)   += phy-exynos-usb2.o
 diff --git a/drivers/phy/phy-mt65xx-usb3.c b/drivers/phy/phy-mt65xx-usb3.c
 new file mode 100644
 index 000..5da4534
 --- /dev/null
 +++ b/drivers/phy/phy-mt65xx-usb3.c
 @@ -0,0 +1,426 @@
 +/*
 + * Copyright (c) 2015 MediaTek Inc.
 + * Author: Chunfeng.Yun chunfeng@mediatek.com
 + *
 + * This software is licensed under the terms of the GNU General Public
 + * License version 2, as published by the Free Software Foundation, and
 + * may be copied, distributed, and modified under those terms.
 + *
 + * This program is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 + * GNU General Public License for more details.
 + *
 + */
 +
 +#include linux/clk.h
 +#include linux/delay.h
 +#include linux/io.h
 +#include linux/module.h
 +#include linux/of_address.h
 +#include linux/of_device.h
 +#include linux/of_gpio.h
 +#include linux/of.h
 +#include linux/phy/phy.h
 +#include linux/platform_device.h
 +#include linux/pm_runtime.h
 +#include linux/regulator/consumer.h
 +#include linux/resource.h
 +
 +/*
 + * for sifslv2 register
 + * relative to USB3_SIF2_BASE base address
 + */
 +#define SSUSB_SIFSLV_SPLLC   (0x)
 +#define SSUSB_SIFSLV_U2PHY_COM_BASE  (0x0800)
 +#define SSUSB_SIFSLV_U3PHYD_BASE (0x0900)
 +#define SSUSB_USB30_PHYA_SIV_B_BASE  (0x0b00)
 +#define SSUSB_SIFSLV_U3PHYA_DA_BASE  (0x0c00)
 +
 +/*port1 refs. +0x800(refer to port0)*/
 +#define U3P_PORT_INTERVAL (0x800)/*based on port0 */
 +#define U3P_PHY_DELTA(index) ((U3P_PORT_INTERVAL) * (index))
 +
 +#define U3P_USBPHYACR0   (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x)
 +#define PA0_RG_U2PLL_FORCE_ON(0x1  15)
 +
 +#define U3P_USBPHYACR2   (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0008)
 +#define PA2_RG_SIF_U2PLL_FORCE_EN(0x1  18)
 +
 +#define U3P_USBPHYACR5   (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0014)
 +#define PA5_RG_U2_HSTX_SRCTRL(0x7  12)
 +#define PA5_RG_U2_HSTX_SRCTRL_VAL(x) ((0x7  (x))  12)
 +#define PA5_RG_U2_HS_100U_U3_EN  (0x1  11)
 +
 +#define U3P_USBPHYACR6   (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0018)
 +#define PA6_RG_U2_ISO_EN (0x1  31)
 +#define PA6_RG_U2_BC11_SW_EN (0x1  23)
 +#define PA6_RG_U2_OTG_VBUSCMP_EN (0x1  20)
 +
 +#define U3P_U2PHYACR4(SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0020)
 +#define P2C_RG_USB20_GPIO_CTL(0x1  9)
 +#define P2C_USB20_GPIO_MODE  (0x1  8)
 +#define P2C_U2_GPIO_CTR_MSK  (P2C_RG_USB20_GPIO_CTL | P2C_USB20_GPIO_MODE)
 +
 +#define U3D_U2PHYDCR0(SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0060)
 +#define P2C_RG_SIF_U2PLL_FORCE_ON(0x1  24)
 +
 +#define U3P_U2PHYDTM0(SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0068)
 +#define P2C_FORCE_UART_EN(0x1  26)
 +#define P2C_FORCE_DATAIN (0x1  23)
 +#define P2C_FORCE_DM_PULLDOWN(0x1  21)
 +#define P2C_FORCE_DP_PULLDOWN(0x1  20)
 +#define P2C_FORCE_XCVRSEL(0x1  19)
 +#define P2C_FORCE_SUSPENDM   (0x1  18)
 +#define P2C_FORCE_TERMSEL(0x1  17)
 +#define P2C_RG_DATAIN(0xf  10)
 +#define P2C_RG_DATAIN_VAL(x) ((0xf  (x))  10)
 +#define P2C_RG_DMPULLDOWN(0x1  7)
 +#define 

Re: [RFC PATCH 1/1] Add a usbredir kernel module to remotely connect USB devices over IP.

2015-07-22 Thread Greg KH
On Wed, Jul 22, 2015 at 09:03:53AM -0500, Jeremy White wrote:
 On 07/09/2015 05:06 AM, Alex Elsayed wrote:
 Alan Stern wrote:
 
 On Mon, 6 Jul 2015, Jeremy White wrote:
 
 Anything else fundamental to usbip that should inform the design of a
 usbredir driver?  usbip appears to be based off a 2004 vintage of
 dummy_hcd.  I'll look thoughtfully at the current dummy_hcd; please let
 me know if there is anything else I should consider.
 
 One thing that springs to mind is USB-3 streams.  When dummy-hcd was
 expanded to include USB-3, that was the major new ingredient.
 
 Another thing that comes to mind is that the USB-IF has its own official
 standard for this kind of thing now, called Media-Agnostic USB[1]. In
 November of 2014 a driver[2] was posted, followed by a second version[3],
 and it is apparently being refined inside Intel[4].
 
 [1]
 http://www.usb.org/developers/docs/devclass_docs/Media_Agnostic_USB_v1.0.zip
 [2] http://thread.gmane.org/gmane.linux.kernel/1820297
 [3] http://thread.gmane.org/gmane.linux.drivers.driver-project.devel/60498
 [4] http://article.gmane.org/gmane.linux.drivers.driver-project.devel/60757
 
 Thanks for the pointer, Alex.
 
 I spent some time with the spec and their proposed code.  It does seem
 plausible that XSpice could use a mausb/usbredir protocol converter.  So if
 there was a mausb kernel module, I could potentially implement support in
 XSpice in user space and not need a usbredir module.
 
 I sent an email to the two developers at Intel to ask if there had been any
 further progress and if I could collaborate with them. I have not heard
 back.
 
 The MA spec is substantial and seems well thought out.  But the usbredir
 protocol has the virtue of being relatively mature - it's 5 years old, with
 code in daily use.
 
 At this point it seems the best path forward is to continue work on the
 usbredir kernel module, which I will do unless I get some new information.

Please work with the existing people, or with the existing spec, I don't
want to be adding multiple versions of this type of protocol to the
kernel.  As it is, I really don't even want to take your code, given
that usbip is already there.  Ignoring it isn't ok.

thanks,

greg k-h
--
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