driver: usb: add CSW Hack feature

squashed commit of:

Implementing the csw hack feature & increasing the number of
buffers used in mass storage to 4.

As per the mass storage protocol, csw is sent from the device
after successfully writing the data on to storage media, where
there is a time factor involved. With this csw hack, csw is sent
just after receiving the data & before writing the data on the
storage media. By, any chance, if the write fails, the corresponding
lun is removed to indicate the user of write failure.

Buffers has been increased to 4, so that there is enough space for
the incoming data, which is usually 64KB per CBW.

User has the option of selecting/deselecting this feature from
the kernel config.

Signed-off-by: Velempati Chiranjeevi <c_cvelem@qualcomm.com>

----

USB: function: mass_storage: Fix in the CSW Hack feature

Before sending the csw to the host, need to cross check,
whether we have received the complete intended data from
the host.

CRs-Fixed: 182952
CRs-Fixed: 182411

Signed-off-by: Velempati, Chiranjeevi <c_cvelem@qualcomm.com>

----

USB: f_mass_storage: Fix multiple enumeration, if media removed abruptly

As part of CSW HACK feature, sending the CSW before actually writing the
data on to the media. If the media is removed after sending the CSW and
before the data is actually written, then the host will not know the
write failure. Hence send the write failure info in the next CSW, so
that host knows about the write failure and throw the right message to
the user.

CRs-fixed: 267925
Change-Id: Ie3d58fb33f26e2f563ecb4560b3fd1249377b091
Signed-off-by: Chiranjeevi Velempati <cvelempa@codeaurora.org>

----

USB: f_mass_storage: Fix sending of CSW if the WRITE command fails

With CSW_HACK feature, CSW is returned immediately for WRITE commands
without waiting for data to be written to the media. There are some
scenarios where because of some error while processing of WRITE command
(e.g unmounting of media during data transfer), CSW is not sent.
Handle all such corner cases.

Change-Id: Id795b7ec7afc10e67a3309e6b650dfc5b7867c9e
CRs-fixed: 281801
Signed-off-by: Manu Gautam <mgautam@codeaurora.org>
USB: gadget: Add 10 microsec delay before fetching

 setup_data

USB hardware sometimes generate interrupt before 8 bytes of
SETUP packet are written to system memory.
This results in wrong setup_data when tried to read immediately
after receiving an interrupt.
Add a delay of 10 microsec before fetching setup packet to allow
writes from hardware to system memory to complete.

CRs-Fixed: 291466
Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>
Signed-off-by: Manu Gautam <mgautam@codeaurora.org>
(cherry picked from commit f89bec0737c0b824495ca85868c949ed0bd1258b)

Change-Id: I154e0bc07661ac8c7d0ca18bb15a38b06d12e207
Signed-off-by: Shruthi Krishna <skrish@codeaurora.org>
USB: gadget: android: Call gether_setup early for tethering to work

Android userspace expects usb0 interface to be present for USB
Tethering UI option to take effect. Hence, move the gether_setup
call to init time rather then calling it at bind_config. Also,
revert the rndis network interface name to usb0 from rndis0.

Signed-off-by: Manu Gautam <mgautam@codeaurora.org>
USB: f_mass_storage: Add support for performance recording

This patch adds support for populating the read/write performance values
for debugging the Mass storage performance numbers at VFS level.

To check the read/write values, user needs to invoke below command

cat /sys/devices/platform/usb_mass_storage/lunX/perf

To reset the read/write values to zero

echo 0 > /sys/devices/platform/usb_mass_storage/lunX/perf

Signed-off-by: Chiranjeevi Velempati <cvelempa@codeaurora.org>
Signed-off-by: Rajkumar Raghupathy <raghup@codeaurora.org>

Conflicts:

	drivers/usb/gadget/Kconfig

Change-Id: Ib89ebdc1fe90c221dd6b75e3ae4f345d4e2fff95
USB: Kconfig: Add USB_MSC_PROFILING macro

Add the config USB_MSC_PROFILING in Kconfig as it was missed due to
merge conflicts.

The USB_MSC_PROFILING adds support for populating the read/write
performance values for debugging the Mass storage performance numbers
at VFS level.

Change-Id: I153e2087081e218dc10fb13047d8aa98d9c2e80e
Signed-off-by: Rajkumar Raghupathy <raghup@codeaurora.org>
USB: gadget: android: Call gether_setup when RNDIS is selected

Userspace code can rely on RNDIS network interface to added
or removed at runtime when a composition with RNDIS is selected.
Allow this by moving the gether_setup call to bind_config.
Also change the name of network device to rndis0 from usb0.

Change-Id: Id2ef849ca9738f3c34e3e4543b95f3468f15f159
Signed-off-by: Manu Gautam <mgautam@codeaurora.org>
Revert "USB: gadget: android: Call gether_setup when RNDIS is selected"

This reverts commit 8d1e540036ee535d4b2cff13929424f052115bc2.
Revert "USB: gadget: android: Call gether_setup early for tethering to work"

This reverts commit 405c095ded8922bcc2cf0d3bcd6a56a1ad62429d.
USB: android: Provide sysfs file for enabling remote wakeup capability

USB device can specify remote wakeup capability in the configuration
descriptor.  Host may select remote wakeup feature before suspending
the device.  Remote wakeup capability is disabled by default in
android gadget.  Provide sysfs file for enabling remote wakeup capability.
User space can enable/disable this capability based on the selected
composition.  This will also allow testing suspend/resume chapter 9 tests
with remote wakeup enabled.

Change-Id: Ib24aa6c05ace697564ebe5940e62e8f65db4d7c3
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
USB: f_mtp: Fix corner cases in MTP driver while syncing

Currently if USB composition switch happens while file transfer is
happening either from/to device, ep_queue fails and sets device state
to ERROR even if device state is already set to OFFLINE in function
disable call.

As part of ioctl call, if the state is not offline, moving the device
state to READY and returning the error. Since the device state is marked
as READY, the next write call tries to queue the request to hardware and
is blocked and due to this, userspace is not calling the release function.
Hence next mtp open fails even after cable reconnection.

CRs-Fixed: 360409
Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>
Change-Id: Ia8cbd1cd8c81b90389900b83744b2bed89068db5
Revert "cpufreq code backported from 3.0 kernel"

This reverts commit ed8b09fa194ea46451e2343498604e6807bf8f07.
unexport (un)lock_policy_rwsem* functions

lock_policy_rwsem_* and unlock_policy_rwsem_* functions are scheduled
to be unexported when 2.6.33. Now there are no other callers of them
out of cpufreq.c, unexport them and make them static.

Signed-off-by: WANG Cong <amwang@redhat.com>
Cc: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
Signed-off-by: Dave Jones <davej@redhat.com>
fix build

Change-Id: I013067677980cfd67f5a31bcf3256af8d8838e38
[CPUFREQ] x86 cpufreq: Make trace_power_frequency cpufreq
 driver independent

and fix the broken case if a core's frequency depends on others.

trace_power_frequency was only implemented in a rather ungeneric way
in acpi-cpufreq driver's target() function only.
-> Move the call to trace_power_frequency to
   cpufreq.c:cpufreq_notify_transition() where CPUFREQ_POSTCHANGE
   notifier is triggered.
   This will support power frequency tracing by all cpufreq drivers

trace_power_frequency did not trace frequency changes correctly when
the userspace governor was used or when CPU cores' frequency depend
on each other.
-> Moving this into the CPUFREQ_POSTCHANGE notifier and pass the cpu
   which gets switched automatically fixes this.

Robert Schoene provided some important fixes on top of my initial
quick shot version which are integrated in this patch:
- Forgot some changes in power_end trace (TP_printk/variable names)
- Variable dummy in power_end must now be cpu_id
- Use static 64 bit variable instead of unsigned int for cpu_id

Change-Id: I3a7cb2ac94636f54946b2fdeacdca2330f9bad50
Signed-off-by: Thomas Renninger <trenn@suse.de>
CC: davej@redhat.com
CC: arjan@infradead.org
CC: linux-kernel@vger.kernel.org
CC: robert.schoene@tu-dresden.de
Tested-by: robert.schoene@tu-dresden.de
Signed-off-by: Dave Jones <davej@redhat.com>
fix brace coding style issue.

This patch fixes up a brace warning found by the checkpatch.pl tool

Signed-off-by: Neal Buckendahl <nealb001@tbcnet.com>
Signed-off-by: Dave Jones <davej@redhat.com>
drivers/cpufreq: Adjust confusing if indentation

Indent the body of for_each_cpu.

The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@r disable braces4@
position p1,p2;
statement S1,S2;
@@

(
if (...) { ... }
|
if (...) S1@p1 S2@p2
)

@script:python@
p1 << r.p1;
p2 << r.p2;
@@

if (p1[0].column == p2[0].column):
  cocci.print_main("branch",p1)
  cocci.print_secs("after",p2)
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>
Signed-off-by: Dave Jones <davej@redhat.com>
add sampling_down_factor tunable to improve ondemand performance

Adds a new global tunable, sampling_down_factor.  Set to 1 it makes no
changes from existing behavior, but set to greater than 1 (e.g. 100)
it acts as a multiplier for the scheduling interval for reevaluating
load when the CPU is at its top speed due to high load.  This improves
performance by reducing the overhead of load evaluation and helping
the CPU stay at its top speed when truly busy, rather than shifting
back and forth in speed.  This tunable has no effect on behavior at
lower speeds/lower CPU loads.

This patch is against 2.6.36-rc6.

This patch should help solve kernel bug 19672 "ondemand is slow".

Signed-off-by: David Niemi <dniemi@verisign.com>
Acked-by: Venkatesh Pallipadi <venki@google.com>
CC: Daniel Hollocher <danielhollocher@gmail.com>
CC: <cpufreq-list@vger.kernel.org>
CC: <linux-kernel@vger.kernel.org>
Signed-off-by: Dave Jones <davej@redhat.com>
perf: Clean up power events by introducing new, more generic
 ones

Add these new power trace events:

 power:cpu_idle
 power:cpu_frequency
 power:machine_suspend

The old C-state/idle accounting events:

  power:power_start
  power:power_end

Have now a replacement (but we are still keeping the old
tracepoints for compatibility):

  power:cpu_idle

and
  power:power_frequency

is replaced with:
  power:cpu_frequency

power:machine_suspend is newly introduced.

Jean Pihet has a patch integrated into the generic layer
(kernel/power/suspend.c) which will make use of it.

the type= field got removed from both, it was never
used and the type is differed by the event type itself.

perf timechart userspace tool gets adjusted in a separate patch.

Change-Id: Ifaf669efe4f910efcb9e43f86130892eac2dbe88
Signed-off-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Acked-by: Arjan van de Ven <arjan@linux.intel.com>
Acked-by: Jean Pihet <jean.pihet@newoldbits.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: rjw@sisk.pl
LKML-Reference: <1294073445-14812-3-git-send-email-trenn@suse.de>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
LKML-Reference: <1290072314-31155-2-git-send-email-trenn@suse.de>
cpufreq: Prevent memory leak in cpufreq_stats on hotplug

Ensures that cpufreq_stats_free_table is called before
__cpufreq_remove_dev on cpu hotplug (which also occurs during
suspend on SMP systems) to make sure that sysfs_remove_group
can get called before the cpufreq kobj is freed.  Otherwise,
the sysfs file structures are leaked.

Change-Id: I87e55277272f5cfad47e9e7c92630e990bb90069
Signed-off-by: Colin Cross <ccross@android.com>
fix BUG on cpufreq policy init failure

cpufreq_register_driver sets cpufreq_driver to a structure owned (and
placed) in the caller's memory. If cpufreq policy fails in its ->init
function, sysdev_driver_register returns nonzero in
cpufreq_register_driver. Now, cpufreq_register_driver returns an error
without setting cpufreq_driver back to NULL.

Usually cpufreq policy modules are unloaded because they propagate the
error to the module init function and return that.

So a later access to any member of cpufreq_driver causes bugs like:
BUG: unable to handle kernel paging request at ffffffffa00270a0
IP: [<ffffffff8145eca3>] cpufreq_cpu_get+0x53/0xe0
PGD 1805067 PUD 1809063 PMD 1c3f90067 PTE 0
Oops: 0000 [#1] SMP
last sysfs file: /sys/devices/virtual/net/tun0/statistics/collisions
CPU 0
Modules linked in: ...
Pid: 5677, comm: thunderbird-bin Tainted: G        W   2.6.38-rc4-mm1_64+ #1389 To be filled by O.E.M./To Be Filled By O.E.M.
RIP: 0010:[<ffffffff8145eca3>]  [<ffffffff8145eca3>] cpufreq_cpu_get+0x53/0xe0
RSP: 0018:ffff8801aec37d98  EFLAGS: 00010086
RAX: 0000000000000202 RBX: 0000000000000000 RCX: 0000000000000001
RDX: ffffffffa00270a0 RSI: 0000000000001000 RDI: ffffffff8199ece8
...
Call Trace:
 [<ffffffff8145f490>] cpufreq_quick_get+0x10/0x30
 [<ffffffff8103f12b>] show_cpuinfo+0x2ab/0x300
 [<ffffffff81136292>] seq_read+0xf2/0x3f0
 [<ffffffff8126c5d3>] ? __strncpy_from_user+0x33/0x60
 [<ffffffff8116850d>] proc_reg_read+0x6d/0xa0
 [<ffffffff81116e53>] vfs_read+0xc3/0x180
 [<ffffffff81116f5c>] sys_read+0x4c/0x90
 [<ffffffff81030dbb>] system_call_fastpath+0x16/0x1b
...

It's all cause by weird fail path handling in cpufreq_register_driver.
To fix that, shuffle the code to do proper handling with gotos.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Signed-off-by: Dave Jones <davej@redhat.com>