USB: dwc3: core: Add module parameter for TX fifo resize

Setting tx fifo resize flag is leading to discrepancy in
read throughputs for MTP function driver. Hence disable
this tx fifo resize flag and add a module parameter for
enabling/disabling this tx fifo resize at run time.

CRs-Fixed: 496921
Change-Id: Ie222cf437f6e1457b48d4dd3d6b4bfc016a241e9
Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>
usb: mdm_bridge: Fix race between disconnect and I/O completion handler

There is a possibility of race between device disconnect and I/O
completion handler. In this case disconnect frees bridge device
memory in thread context and I/O completion handler uses already
freed bridge device memory in interrupt context. Hence allocate
bridge device memory at the time of driver load and free it
during unload. Also, do not anchor interrupt and read urb and
unlink them synchronously to avoid accessing transfer buffers
associated to these urbs when driver disconnect frees them.

Guard the race condition by:-
1) Adding check for usb device disconnect state in the I/O
completion handler to avoid further processing I/O completion.

2) Unlinking tx urbs synchronously since asynchronous unlinking
results in the same race condition.

CRs-Fixed: 447591
Change-Id: Iae4c2a1920c16fcf3e1728144a7cfe6ca66c7705
Signed-off-by: Hemant Kumar <hemantk@codeaurora.org>
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
usb: gadget: Support multiple HSIC transport instances for dun and rmnet

Instead of using integer-based IDs to couple bridge instances to the
corresponding gadget ports, assign transport name strings (passed by
userspace) describing the port instance, and match strings to identify
the correct instance when bridge_open() called. This allows multiple
dun and rmnet ports to be assigned without having dependecy of
one-to-one mapping between gadget port instance and bridge driver
instance.

Change-Id: Ia87bd6e9c72d5e98f47dbc2a1cf0b71b48daa1a8
Signed-off-by: Hemant Kumar <hemantk@codeaurora.org>
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
usb: mdm_bridge: Add support for multiple instance of dun and rmnet driver

mdm bridge driver needs to get loaded for two mdm9x15 devices enumeration
for PID 0x9048 and 0x9079. In this case driver probe and disconnect can
happen in parallel on two different cores. Hence identify the available
bridge device instance and mark is as claimed by acquiring a global mutex.
Unclaime the device instance upon device disconnect.

Change-Id: I8f0f8fb7d76e8a4f1a68b3fad288782ff571c653
Signed-off-by: Hemant Kumar <hemantk@codeaurora.org>
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
USB: mdm_bridge: Simplify data bridge suspend/resume path

Synchronous runtime PM API is used to increment the PM usage counter
in Tx path.  It means Tx data path will not race with interface suspend.
Remove "delayed" anchor which is meant for Tx requests, that are arrived
during suspend.  There is no point in distinguishing auto suspend and
system wide suspend.  Abort suspend when we have pending Tx URBs.

CRs-Fixed: 451414
Change-Id: I302b120ccecfe30db1ebd2b1fcd9945a3675cf83
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
USB: mdm_bridge: Fix control bridge suspend

The current code does not abort suspend when there are pending URBs.
They are simply killed during suspend. This may lead to QMI stall.
Add proper checks to ensure that there is no pending Tx/Rx data
during suspend.  Clear the "SUSPENDED" flag in resume only after
taking out all the URBs from "tx_deferred" anchor.

CRs-Fixed: 451414
Change-Id: Icc48afc5eeedcc126d0ab1bec951bde4a53ac165
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
USB: mdm_bridge: Fix probe error path

The platform device is not unregistered in probe error path.  The
platform device is added again during next probe and it fails.  But
the return value is not checked.  Kernel panic happens when platform
device is removed during disconnect.

CRs-Fixed: 465508
Change-Id: I4db613e72d8b405f10cde0d1335d231cf5079e64
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
usb: gadget: u_data_hsic: Cancel pending MDM write work during remove

The HSIC bridge driver removes the data bridge platform device
during subsystem restart.  If gadget driver does not cancel pending
MDM write work, we end up accessing interface structure after it
is unbounded.

CRs-Fixed: 465383
Change-Id: I05fe3e2b625e87137681477aaaf1082ba1b81bae
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
usb: gadget: u_data_hsic: Use GFP_KERNEL where ever possible

The USB requests are allocated using dma pool API.  The dma pool has
limited memory for non-sleeping use case.  The current code does not
free USB requests during subsystem restart.  The requests are freed
only after cable is disconnected.  If subsystem restart happens
multiple  times without disconnecting cable, system may run out of the
dma pool memory.  This is leading to URB submission failures.  Use
GFP_KERNEL where ever possible.

CRs-Fixed: 463423
Change-Id: I0fca533e460e7b4234fe771e048e0e50494cb1da
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
usb: gadget: composite: Fix a bug in delayed status handling

The SET_CONFIGURATION control request's status phase is delayed
till the new config change is handled by the file-storage thread.
If the cable is disconnected or the bus is reset before the
previous config is handled, then composite driver is not notified
about the delayed status.  As a result of which, the delayed_status
field of composite device structure remains non-zero.  The status
phase of next SET_CONFIGURATION control request is not sent.
This makes the gadget unusable.

Calling usb_composite_setup_continue() after the disconnect or reset
does not make any sense.  If the host sends another control request
before the status phase of the previous control request is sent, the
delayed_status must be reset to zero.  This is not straight forward
as the UDC handles some control requests without delegating them to
the composite driver.  A simple fix would be resetting the delayed
status value after the disconnect/reset.

CRs-Fixed: 501527
Change-Id: I67c832afc88c9e7d025247e539b7223fd83644d7
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
usb: msm_otg: add charger detection for floated D+ and D-

Floated charger means "D+/D- floated charger". According batt
charging spec 1.2, during primary detection, the DP voltage
is VDP_SRC, DM voltage may not exceed VDAT_REF, it's same to
standard downstream port(SDP). Introducing data contact
detection(DCD) here to distinguish between SDP and floated
charger. If DCD detected, it's SDP, otherwise floated charger
is detected.

Change-Id: Id7655f7209408092da84a09e3ab6f5c5a764ef78
Signed-off-by: zhenhuah <zhenhuah@codeaurora.org>
USB: host: ehci-msm2: Add debugfs entry to access phy registers

Add a debugfs entry to write and read ULPI PHY registers, using the
below commands:
Debugfs location: <debugfs>/msm_ehci_host.1/

echo 0xADDR > phy_reg_addr

To write value to the register 0xADDR:
echo 0xVALUE > phy_reg_data

To read from the register 0xADDR:
cat phy_reg_data

CRs-Fixed: 491755
Change-Id: I3529fc257d107cec8b0525d6b344a1e51153f053
Signed-off-by: Rajkumar Raghupathy <raghup@codeaurora.org>
USB: msm_otg: Allow platforms to vote for BUS bw on cable connect

Some platforms require voting for NOC bandwidth (and PNOC clocks)
when enabling/disabling USB clocks. It is also recommended to have
NOC running when USB is active or in session.
Hence, allow such platforms to specify MIN BUS vote along with NONE
(or inactive) and MAX USB votes. If MIN vote is not specified then
driver treats NONE vote as MIN vote.
Overall platforms should be passing these votes based on that:
NO vote is used when USB cable is not connected or there is no USB
session. MAX vote is used when USB is operating in peripheral mode
and MIN vote is used for any other scenario e.g. host mode or when
turning off USB clocks as part of putting USB in low power state.
MIN vote shouldn't be a significant value to avoid increase in power
numbers.

CRs-Fixed: 494654
Change-Id: Ia4498356b026963f7a6fda8a30ecbd9c1cd98924
Signed-off-by: Manu Gautam <mgautam@codeaurora.org>
usb: gadget: Fix datastall upon USB cable disconnect

Original bug was a datastall in the IPA upon USB
cable disconnect during high throughput traffic.
It was caused due to IPA continuing sending data to USB
without USB being able to consume the data (disconnected cable),
causing a stall in the IPA hardware.

The solution proposed here is to first disconnect the pipes
and only afterwards disconnect the tethering bridge that deletes
the IPA configuration for the connection.

CRs-fixed: 500370
Change-Id: I6d8524053da593775c75ddc1ef95f377e30aaafd
Signed-off-by: Lena Salman <esalman@codeaurora.org>
usb: ehci-msm2: replace wakelock with wakeup source

wakelock APIs are banned APIs for kernel now. Instead
of wakelocks, use wakeup sources.

Change-Id: I3ae31f875068b14f7282f787b465b8b66f2c5b02
Signed-off-by: Hemant Kumar <hemantk@codeaurora.org>
usb: ehci-msm: Fix unclocked access on system resume

On system resume, host controller driver may try to access
USB registers to update wakeup flags before OTG driver brings
hardware out of low power state and turns ON clocks.
Make sure hardware is out of LPM before accessing registers and
always resume root hub during system resume to allow USB host
bus suspend if system was not resumed due to USB event and PCD
interrupt wouldn't follow.

CRs-Fixed: 502926
Change-Id: Ib1e69211ae35feae509581b73d7b0d1aef9872e9
Signed-off-by: Manu Gautam <mgautam@codeaurora.org>
usb: gadget: u_ether: Fix memory corruption in TX path

When data aggregation is enabled, multiple skb buffers are copied
into a single USB request buffer.  When ever a USB request queue
is failed, make sure that req->length is reset to 0.  Otherwise
when the same request is used again, the stale length field is used
to access the request buffer.  This would lead to memory corruption.

The xmit function keeps the partial request at the beginning of the
queue.  Always put the idle request at the back of the queue.

CRs-Fixed: 469436
Change-Id: Idcd31e667b0bf261ab9a88f4a34464ccdf503e1b
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
USB: xhci: Add RESET delay quirk for DWC3 controller

In Synopsis DWC3 controller, XHCI RESET takes some time complete.
If PIPE RESET is not complete by the time USBCMD.RUN bit is set
then HC fails to carry out SuperSpeed transfers.
Workaround is to give worst case pipe delay ~350us after resetting
DWC3.

Change-Id: I42a6eb69e5718aafd1d8bb0b32f44a4807a7dc3f
CRs-fixed: 490545
Signed-off-by: Manu Gautam <mgautam@codeaurora.org>
USB: dwc3: msm: Read pmic_id_irq line status with interrupts disabled

Ideally pmic_id irq line status should be read with interrupts disabled
in work queue context. Otherwise it might lead to deadlock scenario.
Hence fix this by reading pmic_id irq line status with interrupts
disabled in work queue context.

CRs-Fixed: 504144
Change-Id: I33581427e430ea8788518eaf95d69b4950695d0f
Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>
usb: gadget: ci13xxx: cancel prime timer after disconnect also for ep0

When issue a transfer to the usb hardware core, the prime bit is set
for the desired endpoint. After the hardware finish processing the
transfer it reset the prime bit of that endpoint. In order to debug cases
in which this bit is not reset by the core, a timer was set for 1 second
after issuing the transfer for checking the prime bit status and print
debug messages in case of abnormal state.

However, this mechanism introduced a bug, in which the timer of ep0
was expired after cable disconnect. Therefore the prime bit was checked,
while the hardware is in low power mode, so reading the bit caused a crash.

Fix this by ensuring that the timer will be canceled whenever all the
requests of an endpoint are dequeued, including for the case of ep0.
Also added a warning and protection for such cases when an endpoint
timer expires after core in low power mode.

CRs-Fixed: 505686
Change-Id: I7336ec7372714a4cd04bf94eb31ce230ee0a4241
Signed-off-by: Ido Shayevitz <idos@codeaurora.org>