sunxi-usb: Fix stack corruption in sw_hcd0.c

Enlarge aInfo array to fit all text added to it.
Fixes stack corruption, and solves ERR: request_irq 38 failed! error.
sunxi_usb-sw_hcd0: Fix overwriting struct sw_hcd memory

When running the latest sunxi-3.0 on my gooseberry, sw_hcd0 would fail
to init and on plugging in a otg-host cable to enable, because of request_irq
failing. The reason for this failure is that sw_hcd->isr was set to NULL,
as it had been overwritten from ep_config_from_table().

The sw_hcd endpoints array has SW_HCD_C_NUM_EPS entries, and before this
patch that equaled USBC_MAX_EP_NUM. But USBC_MAX_EP_NUM gives the maximum
ep address, and per ep address we've 2 sw_hcd.endpoints entries!

This patch both adds a check for not going out of bounds wrt sw_hcd.endpoints
to ep_config_from_table(), and it fixes SW_HCD_C_NUM_EPS to be
2 * USBC_MAX_EP_NUM. Thus fixing the sw_hcd0 registration / enable and making
the otg port usable in host mode again.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
sunxi_usb: sw_hcd_core_init: Fix a buffer overflow

While looking for the bufferoverflow which was setting sw_hcd->isr to NULL,
I found that if all features are enabled, the aInfo string in sw_hcd_core_init
will overflow. This patch fixes this, and while at it also:
- removes some other unused local variables
- actually prints the carefully build aInfo string
- fixes some glaring coding style issues

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Revert "sunxi_usb-sw_hcd0: Fix overwriting struct sw_hcd memory"

This reverts commit a051008352a0eab3ef24594783de0fe74c0d5759 by
request of the author.

Thanks for merging, your comment made me double check and I'm afraid
my patch titled: "sun4i_usb-sw_hcd0: Fix overwriting struct sw_hcd memory"
is based on me misreading the code. There are n entries in the
mode_4_cfg array, but sw_hcd->endpoints is not addressed by the
i which is iterating over the mode_4_cfg, but instead by
mode_4_cfg[i].hw_ep_num.

This means that fifo_setup and through it USBC_ConfigFifo gets called twice for
each endpoint. But if you trace things further down the call stack, then
USBC_ConfigFifo is a multiplexer function calling USBC_ConfigFifoTx and
USBC_ConfigFifoRx which each set a different set of registers for each function.
so although it seems each ep gets configured twice, it only gets configured once
in a bi-directional manner.

I thought this meant there were separate in/out endpoints per ep address, as that
is how the rest of the world deals with USB endpoints... Anyways.

Conclusion:
1) Floris was completely right, and the stack corruption he found was
   also indirectly corrupting the sw_hcd struct.
2) sw_hcd->endpoints was fine as is.
3) The old ep_config_from_table code was fine wrt its out of bounds checking
   for sw_hcd->endpoints, the only wrong thing in there is this very confusing
   debug print:
     DMSG_DBG_HCD("ep_config_from_table: %s: %d/%d max ep, %d/%d memory\n",
                 sw_hcd_driver_name,
                 n + 1, sw_hcd->config->num_eps * 2 - 1,
                 offset, sw_hcd->config->ram_size);

Which talks about n + 1 versus sw_hcd->config->num_eps * 2 - 1 as endpoint array
usage versus size, which seems wrong to me.

Alejandro, can you please revert my patch titled:
"sun4i_usb-sw_hcd0: Fix overwriting struct sw_hcd memory"

On both 3.0 and 3.4, feel free to use the above as commit message, and to add:

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
ata:sw_achi_platform: fix memory corruption when "sata_used" is 0 in script.bin
sun4i_csi: Fixes kernel bug during camera init, v4l field must be set from camera driver response

Just a one line patch that fixes the camera initialization on the
tablets.  I realize the rest of the driver code from allwinner is ugly
as sin, I'll try and submit a style patch later.

Signed-off-by: Neal Peacock <neal@nic-stix.com>
usb: sunxi: register OTG port as 2.0 instead of 1.1
net sun4i_wmac: Drop obsolete poll_controller assignment.

Failed to compile with netconsole enabled. poll_controller is now
only set in the netdeviceops, not in the netdevice itself.
arch:arm:configs:a13_nuclear_defconfig: Fix missing symbols
ERROR: "ve_start" [drivers/media/video/videobuf-dma-contig.ko] undefined!
ERROR: "ve_size" [drivers/media/video/videobuf-dma-contig.ko] undefined!
sun4i-usb: allow USB1.1 devices on OTG USB 2.0 port

When OTG port is USB2.0 type, USB1.1 devices do not work:

[   56.790000] ------------IRQ CONNECT-------------
[   56.790000]
[   56.960000] [sw_hcd]: reset port.
[   57.020000] [sw_hcd]: reset port stopped.
[   57.080000] usb 1-1: new full-speed USB device number 3 using sw_hcd_host0
[   57.080000] usb 1-1: parent hub has no TT
[   57.090000] [sw_hcd]: sw_hcd_h_disable, epnum = 0
[   57.100000] [sw_hcd]: sw_hcd_h_disable, epnum = 0
[   57.110000] [sw_hcd]: reset port.
[   57.170000] [sw_hcd]: reset port stopped.
[   57.230000] usb 1-1: new full-speed USB device number 4 using sw_hcd_host0
[   57.230000] usb 1-1: parent hub has no TT
[   57.240000] [sw_hcd]: sw_hcd_h_disable, epnum = 0
[   57.250000] [sw_hcd]: sw_hcd_h_disable, epnum = 0
[   57.250000] [sw_hcd]: reset port.
[   57.320000] [sw_hcd]: reset port stopped.
[   57.380000] usb 1-1: new full-speed USB device number 5 using sw_hcd_host0
[   57.380000] usb 1-1: parent hub has no TT
[   57.390000] [sw_hcd]: sw_hcd_h_disable, epnum = 0
[   57.400000] [sw_hcd]: sw_hcd_h_disable, epnum = 0
[   57.400000] [sw_hcd]: reset port.
[   57.470000] [sw_hcd]: reset port stopped.
[   57.530000] usb 1-1: new full-speed USB device number 6 using sw_hcd_host0
[   57.530000] usb 1-1: parent hub has no TT
[   57.540000] [sw_hcd]: sw_hcd_h_disable, epnum = 0
[   57.540000] [sw_hcd]: sw_hcd_h_disable, epnum = 0
[   57.550000] hub 1-0:1.0: unable to enumerate USB device on port 1

Enabling .has_tt flag on HCD appears to fix or at least workaround the issue:

[   20.960000] ------------IRQ CONNECT-------------
[   20.960000]
[   21.120000] [sw_hcd]: reset port.
[   21.180000] [sw_hcd]: reset port stopped.
[   21.180000] spurious?
[   21.240000] usb 1-1: new full-speed USB device number 2 using sw_hcd_host0
[   21.240000] [sw_hcd]: reset port.
[   21.300000] [sw_hcd]: reset port stopped.
[   21.360000] [sw_hcd]: sw_hcd_h_disable, epnum = 0
[   21.360000] [sw_hcd]: sw_hcd_h_disable, epnum = 0
[   21.380000] WRN:L1722(drivers/usb/sun4i_usb/hcd/core/sw_hcd_host.c):ERR: sw_hcd_h_ep0_irq, STALLING ENDPOINT
[   21.380000] WRN:L1741(drivers/usb/sun4i_usb/hcd/core/sw_hcd_host.c):ERR: sw_hcd_h_ep0_irq, ep aborting
[   21.390000] WRN:L1722(drivers/usb/sun4i_usb/hcd/core/sw_hcd_host.c):ERR: sw_hcd_h_ep0_irq, STALLING ENDPOINT
[   21.390000] WRN:L1741(drivers/usb/sun4i_usb/hcd/core/sw_hcd_host.c):ERR: sw_hcd_h_ep0_irq, ep aborting
[   21.400000] WRN:L1722(drivers/usb/sun4i_usb/hcd/core/sw_hcd_host.c):ERR: sw_hcd_h_ep0_irq, STALLING ENDPOINT
[   21.400000] WRN:L1741(drivers/usb/sun4i_usb/hcd/core/sw_hcd_host.c):ERR: sw_hcd_h_ep0_irq, ep aborting
[   21.410000] usb 1-1: New USB device found, idVendor=045e, idProduct=0745
[   21.420000] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[   21.420000] usb 1-1: Product: Microsoft\xffffffc2\xffffffae\xffffffae 2.4GHz Transceiver v6.0
[   21.430000] usb 1-1: Manufacturer: Microsoft

Not sure if this is correct or complete fix, as with .has_tt kernel log shows
some warnings. On the other hand, musb uses same flag.

Tested over linux-sunxi-3.4 (+ otg-usb-2.0 patch), compile tested on
linux-sunxi-3.0.

Signed-off-by: Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
Merge remote-tracking branch 'upstream/sunxi-3.0' into allwinner-v3.0-android-v2
Merge branch 'allwinner-v3.0-android-v2' of https://github.com/maxnet/linux-allwinner-aufs into allwinner-v3.0-android-v2

Conflicts:
	drivers/usb/sun4i_usb/hcd/hcd0/sw_hcd0.c