libertas sdio: issue CMD_FUNC_INIT call only once the card is running

Otherwise the worker thread won't pick the command up and driver hangs
waiting for completion:

INFO: task insmod:2447 blocked for more than 10 seconds.
"echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
insmod          D c0502248  6196  2447   2418 0x00000000
[<c0502248>] (__schedule+0x610/0x764) from [<bf2e835c>] (__lbs_cmd+0x124/0x214 [libertas])
[<bf2e835c>] (__lbs_cmd+0x124/0x214 [libertas]) from [<bf309610>] (if_sdio_finish_power_on+0x130/0x204 [libertas_sdio])
[<bf309610>] (if_sdio_finish_power_on+0x130/0x204 [libertas_sdio]) from [<bf309998>] (if_sdio_power_on+0x2b4/0x3ec [libertas_sdio])
[<bf309998>] (if_sdio_power_on+0x2b4/0x3ec [libertas_sdio]) from [<bf309d94>] (if_sdio_probe+0x2c4/0x460 [libertas_sdio])
[<bf309d94>] (if_sdio_probe+0x2c4/0x460 [libertas_sdio]) from [<bf01d820>] (sdio_bus_probe+0x94/0xfc [mmc_core])
[<bf01d820>] (sdio_bus_probe+0x94/0xfc [mmc_core]) from [<c02e729c>] (driver_probe_device+0x12c/0x348)
[<c02e729c>] (driver_probe_device+0x12c/0x348) from [<c02e7530>] (__driver_attach+0x78/0x9c)
[<c02e7530>] (__driver_attach+0x78/0x9c) from [<c02e5658>] (bus_for_each_dev+0x50/0x88)
[<c02e5658>] (bus_for_each_dev+0x50/0x88) from [<c02e6810>] (bus_add_driver+0x108/0x268)
[<c02e6810>] (bus_add_driver+0x108/0x268) from [<c02e782c>] (driver_register+0xa4/0x134)
[<c02e782c>] (driver_register+0xa4/0x134) from [<bf30f070>] (if_sdio_init_module+0x70/0x110 [libertas_sdio])
[<bf30f070>] (if_sdio_init_module+0x70/0x110 [libertas_sdio]) from [<c00085b8>] (do_one_initcall+0x98/0x174)
[<c00085b8>] (do_one_initcall+0x98/0x174) from [<c0076504>] (load_module+0x1c5c/0x1f80)
[<c0076504>] (load_module+0x1c5c/0x1f80) from [<c007692c>] (sys_init_module+0x104/0x128)
[<c007692c>] (sys_init_module+0x104/0x128) from [<c0008c40>] (ret_fast_syscall+0x0/0x38)

Verified to work fine on a GuruPlug, btmrvl_sdio still works too:

[root@megalodon kirkwood-linux]# iwlist scan
lo        Interface doesn't support scanning.

eth1      Interface doesn't support scanning.

wlan0     Scan completed :
          Cell 01 - Address: 00:1E:8C:EC:3C:A2
                    Channel:5
                    Frequency:2.432 GHz (Channel 5)
                    Quality=34/70  Signal level=-76 dBm
                    Encryption key:off
                    ESSID:"kurwix"
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s
                              9 Mb/s; 12 Mb/s; 18 Mb/s
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s
                    Mode:Master
                    Extra:tsf=0000000005ebf709
                    Extra: Last beacon: 200ms ago
                    IE: Unknown: 00066B7572776978
                    IE: Unknown: 010882848B960C121824
                    IE: Unknown: 030105
                    IE: Unknown: 2A0107
                    IE: Unknown: 32043048606C
                    IE: Unknown: DD180050F2020101000003A4000027A4000042435E0062322F00

eth0      Interface doesn't support scanning.

[root@megalodon kirkwood-linux]# hcitool scan --flush
Scanning ...
        3F:5B:3D:7C:66:12       GPLUS GH666
[root@megalodon kirkwood-linux]#

Debugging output from prior to the change:

libertas sdio: firmware already loaded
libertas sdio: send function INIT command
libertas enter: __lbs_cmd()
libertas enter: __lbs_cmd_async()
libertas enter: lbs_get_free_cmd_node()
libertas leave: lbs_get_free_cmd_node()
libertas host: PREP_CMD: command 0x00a9
libertas enter: lbs_queue_cmd()
libertas host: QUEUE_CMD: inserted command 0x00a9 into cmdpendingq
libertas leave: lbs_queue_cmd()
libertas leave: __lbs_cmd_async(), ret de0b7900
libertas thread: 2: currenttxskb   (null), dnld_send 0
libertas thread: 3: currenttxskb   (null), dnld_sent 0
libertas thread: 4: currenttxskb   (null), dnld_sent 0
libertas thread: 1: currenttxskb   (null), dnld_sent 0
libertas thread: sleeping, connect_status 1, psmode 0, psstate 0
INFO: task insmod:2447 blocked for more than 10 seconds.

Debugging output with patch applied:

libertas sdio: firmware already loaded
libertas sdio: send function INIT command
libertas enter: __lbs_cmd()
libertas enter: __lbs_cmd_async()
libertas enter: lbs_get_free_cmd_node()
libertas leave: lbs_get_free_cmd_node()
libertas host: PREP_CMD: command 0x00a9
libertas enter: lbs_queue_cmd()
libertas host: QUEUE_CMD: inserted command 0x00a9 into cmdpendingq
libertas leave: lbs_queue_cmd()
libertas leave: __lbs_cmd_async(), ret de3767c8
libertas thread: 2: currenttxskb   (null), dnld_send 0
libertas thread: 3: currenttxskb   (null), dnld_sent 0
libertas thread: 4: currenttxskb   (null), dnld_sent 0
libertas enter: lbs_execute_next_command()
libertas host: EXEC_NEXT_CMD: sending command 0x00a9
libertas enter: lbs_submit_command()
libertas cmd: DNLD_CMD: command 0x00a9, seq 6, size 8
libertas DNLD_CMD: a9 00 08 00 06 00 00 00
libertas enter: if_sdio_host_to_card(type 1, bytes 8)
libertas leave: if_sdio_host_to_card(), ret 0
libertas leave: lbs_submit_command()
libertas leave: lbs_execute_next_command()
libertas thread: 1: currenttxskb   (null), dnld_sent 2
libertas thread: sleeping, connect_status 1, psmode 0, psstate 0
libertas enter: if_sdio_host_to_card_worker()
libertas leave: if_sdio_host_to_card_worker()
libertas enter: if_sdio_interrupt()
libertas sdio: interrupt: 0x3
libertas enter: lbs_host_to_card_done()
libertas leave: lbs_host_to_card_done()
libertas enter: if_sdio_card_to_host()
libertas sdio: packet of type 1 and size 12 bytes
libertas sdio: packet fragment (12 < 32)
libertas enter: if_sdio_handle_cmd()
libertas enter: lbs_notify_command_response()
libertas leave: lbs_notify_command_response()
libertas leave: if_sdio_handle_cmd(), ret 0
libertas leave: if_sdio_card_to_host(), ret 0
libertas leave: if_sdio_interrupt(), ret 0
libertas thread: 2: currenttxskb   (null), dnld_send 0
libertas thread: 3: currenttxskb   (null), dnld_sent 0
libertas thread: 4: currenttxskb   (null), dnld_sent 0
libertas enter: lbs_process_command_response()
libertas cmd: CMD_RESP: response 0x80a9, seq 6, size 8
libertas CMD_RESP: a9 80 08 00 06 00 00 00
LR: dma: mv_xor: test for small transfers
LR: dma: mv_xor: remove minimal offload length threshold

This fatally confuses dma_async_memcpy_buf_to_pg which thinks it signals an out
of memory condition and retries indefinitelly, causing a soft lockup. The
threshold does not seem to be enforced by hardware (couldn't find anything like
that in a datasheet) and things seems to work fine without it. If there's a
performance penalty, it probably should be dealt with in dmaengine.

The following crash (with too small skb structure being dma_memcpy()'d) is
reprodcibly triggered by an accept() quickly followed by a read():
http://v3.sk/~lkundrak/so-beautiful/crasher.pl

BUG: soft lockup - CPU#0 stuck for 23s! [perl:715]
Modules linked in:
Pid: 715, comm:                 perl
CPU: 0    Not tainted  (3.6.7-2.fc18.armv5tel.kirkwood #1)
PC is at mv_xor_prep_dma_memcpy+0x14/0x168
LR is at dma_async_memcpy_pg_to_pg+0x100/0x1dc
sp : df197ce0  ip : c023816c  fp : 00000000
r10: c09a6720  r9 : 0000012a  r8 : 115d7000
r7 : ddd4f57c  r6 : ddd4f57c  r5 : ddd4f4a8  r4 : 00000034
r3 : 00000034  r2 : 115d7000  r1 : 116b912a  r0 : ddd4f57c
Flags: nZCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment user
Control: 0005397f  Table: 1f218000  DAC: 00000015
[<c000edac>] (unwind_backtrace+0x0/0x124) from [<c0074ce4>] (watchdog_timer_fn+0xf0/0x144)
[<c0074ce4>] (watchdog_timer_fn+0xf0/0x144) from [<c003aa10>] (__run_hrtimer+0xb0/0x1d4)
[<c003aa10>] (__run_hrtimer+0xb0/0x1d4) from [<c003b224>] (hrtimer_interrupt+0x104/0x250)
[<c003b224>] (hrtimer_interrupt+0x104/0x250) from [<c0016024>] (orion_timer_interrupt+0x24/0x34)
[<c0016024>] (orion_timer_interrupt+0x24/0x34) from [<c0075470>] (handle_irq_event_percpu+0x38/0x23c)
[<c0075470>] (handle_irq_event_percpu+0x38/0x23c) from [<c00756a4>] (handle_irq_event+0x30/0x40)
[<c00756a4>] (handle_irq_event+0x30/0x40) from [<c0077cd4>] (handle_level_irq+0xcc/0xdc)
[<c0077cd4>] (handle_level_irq+0xcc/0xdc) from [<c0074e9c>] (generic_handle_irq+0x28/0x38)
[<c0074e9c>] (generic_handle_irq+0x28/0x38) from [<c0009b64>] (handle_IRQ+0x68/0x8c)
[<c0009b64>] (handle_IRQ+0x68/0x8c) from [<c0444794>] (__irq_svc+0x34/0x78)
[<c0444794>] (__irq_svc+0x34/0x78) from [<c0238180>] (mv_xor_prep_dma_memcpy+0x14/0x168)
[<c0238180>] (mv_xor_prep_dma_memcpy+0x14/0x168) from [<c0236010>] (dma_async_memcpy_pg_to_pg+0x100/0x1dc)
[<c0236010>] (dma_async_memcpy_pg_to_pg+0x100/0x1dc) from [<c0237594>] (dma_memcpy_pg_to_iovec+0xf0/0x180)
[<c0237594>] (dma_memcpy_pg_to_iovec+0xf0/0x180) from [<c03832f8>] (dma_skb_copy_datagram_iovec+0x100/0x1d4)
[<c03832f8>] (dma_skb_copy_datagram_iovec+0x100/0x1d4) from [<c03a9950>] (tcp_recvmsg+0x630/0xac0)
[<c03a9950>] (tcp_recvmsg+0x630/0xac0) from [<c03c8dd8>] (inet_recvmsg+0x48/0x5c)
[<c03c8dd8>] (inet_recvmsg+0x48/0x5c) from [<c035ba54>] (sock_aio_read+0x100/0x120)
[<c035ba54>] (sock_aio_read+0x100/0x120) from [<c00e53e0>] (do_sync_read+0x98/0xd4)
[<c00e53e0>] (do_sync_read+0x98/0xd4) from [<c00e5d54>] (vfs_read+0xb4/0x184)
[<c00e5d54>] (vfs_read+0xb4/0x184) from [<c00e5e60>] (sys_read+0x3c/0x70)
[<c00e5e60>] (sys_read+0x3c/0x70) from [<c0008c60>] (ret_fast_syscall+0x0/0x2c)
Kernel panic - not syncing: softlockup: hung tasks
[<c000edac>] (unwind_backtrace+0x0/0x124) from [<c043e0ac>] (panic+0x80/0x1e0)
[<c043e0ac>] (panic+0x80/0x1e0) from [<c0074d08>] (watchdog_timer_fn+0x114/0x144)
[<c0074d08>] (watchdog_timer_fn+0x114/0x144) from [<c003aa10>] (__run_hrtimer+0xb0/0x1d4)
[<c003aa10>] (__run_hrtimer+0xb0/0x1d4) from [<c003b224>] (hrtimer_interrupt+0x104/0x250)
[<c003b224>] (hrtimer_interrupt+0x104/0x250) from [<c0016024>] (orion_timer_interrupt+0x24/0x34)
[<c0016024>] (orion_timer_interrupt+0x24/0x34) from [<c0075470>] (handle_irq_event_percpu+0x38/0x23c)
[<c0075470>] (handle_irq_event_percpu+0x38/0x23c) from [<c00756a4>] (handle_irq_event+0x30/0x40)
[<c00756a4>] (handle_irq_event+0x30/0x40) from [<c0077cd4>] (handle_level_irq+0xcc/0xdc)
[<c0077cd4>] (handle_level_irq+0xcc/0xdc) from [<c0074e9c>] (generic_handle_irq+0x28/0x38)
[<c0074e9c>] (generic_handle_irq+0x28/0x38) from [<c0009b64>] (handle_IRQ+0x68/0x8c)
[<c0009b64>] (handle_IRQ+0x68/0x8c) from [<c0444794>] (__irq_svc+0x34/0x78)
[<c0444794>] (__irq_svc+0x34/0x78) from [<c0238180>] (mv_xor_prep_dma_memcpy+0x14/0x168)
[<c0238180>] (mv_xor_prep_dma_memcpy+0x14/0x168) from [<c0236010>] (dma_async_memcpy_pg_to_pg+0x100/0x1dc)
[<c0236010>] (dma_async_memcpy_pg_to_pg+0x100/0x1dc) from [<c0237594>] (dma_memcpy_pg_to_iovec+0xf0/0x180)
[<c0237594>] (dma_memcpy_pg_to_iovec+0xf0/0x180) from [<c03832f8>] (dma_skb_copy_datagram_iovec+0x100/0x1d4)
[<c03832f8>] (dma_skb_copy_datagram_iovec+0x100/0x1d4) from [<c03a9950>] (tcp_recvmsg+0x630/0xac0)
[<c03a9950>] (tcp_recvmsg+0x630/0xac0) from [<c03c8dd8>] (inet_recvmsg+0x48/0x5c)
[<c03c8dd8>] (inet_recvmsg+0x48/0x5c) from [<c035ba54>] (sock_aio_read+0x100/0x120)
[<c035ba54>] (sock_aio_read+0x100/0x120) from [<c00e53e0>] (do_sync_read+0x98/0xd4)
[<c00e53e0>] (do_sync_read+0x98/0xd4) from [<c00e5d54>] (vfs_read+0xb4/0x184)
[<c00e5d54>] (vfs_read+0xb4/0x184) from [<c00e5e60>] (sys_read+0x3c/0x70)
[<c00e5e60>] (sys_read+0x3c/0x70) from [<c0008c60>] (ret_fast_syscall+0x0/0x2c)
Rebooting in 1 seconds..

Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>