wl12xx: take the mutex before resetting Tx queues

Otherwise we risk contention for private members of our global structure
while op_stop_locked is running.

Reported-by: Ido Yariv <ido@wizery.com>
Signed-off-by: Arik Nemtsov <arik@wizery.com>
wl12xx: change packet retry count

default retry number was 10. we found out that in noisy environment
there were case we were failed to send the packet.
in that case it took time until the upper layer retransmit the
packet which cause degradation in TCP TP.
change the default to 50 in order to solve this problem

Signed-off-by: Yossi Wortzel <yossiw@ti.com>
wl12xx: consolidate free_link and always call it

Make sure free_link is always called when removing an interface. This
ensures all skbs belonging to this interface are returned to mac80211.
Otherwise these dangling skbs might crash the system on the next
call to wl1271_tx_reset_link_queues(). This happens on recovery/stop or
an unsuccessful Tx flush.

Signed-off-by: Ido Yariv <ido@wizery.com>
Signed-off-by: Arik Nemtsov <arik@wizery.com>
wl12xx: restore default channel configuration

wl12xx allocates two static structs wl1271_band_2ghz &
wl1271_band_5ghz which are used/modified by Reg-Domain
e.g. some channel might be marked as passive at some
point. These structs freed only during wl12xx rmmod and
aren't cleared during wl12xx_sdio.ko, this means that
some channel flags might be set regardless reg-domain
rules. Fix this by clearing the channel flags from
the previous usage (before the current wl12xx_sdio.ko
insmod).

Signed-off-by: Victor Goldenshtein <victorg@ti.com>
wl12xx: initialize per-link FW freed blocks correctly

When a link is allocated, sometimes the "freed packets" counter in FW
is non zero, but we always assumed it is. This caused us to incorrectly
account FW allocated blocks in some cases.

When operating in AP mode, this bug caused some stations to never
come back from PSM.

Signed-off-by: Arik Nemtsov <arik@wizery.com>
mac80211: increase channel switch request timeout

In some heavy loaded MR scenarios with enabled debug
prints the channel switch request + channel switch
command can take some time. Increase the channel
switch request timeout to: beacon_int * dtim_period * 10.

Also clear the "ap_cs_channel" in case of completion
timeout/error.

Signed-off-by: Victor Goldenshtein <victorg@ti.com>
wl12xx: block sched scan if p2p client is running

sched scan isn't supported by the FW when there's a p2p
role active so block it if any interface is running
p2p client.

Signed-off-by: Eyal Shapira <eyal@wizery.com>
mac80211: purge all pending ROCs on reconfig

A remain-on-channel work item may be queued, causing interfaces to start
on the wrong channel during reconfig.

Signed-off-by: Arik Nemtsov <arik@wizery.com>
wl12xx: recovery elp_wakeup optimizations

We now do several optimizations related to recovery situations:

  We fail elp_wakeup if we have SDIO errors (otherwise we just waste time)

  We now call elp_wakeup inside the recovery work routine to ensure that
  FW is awake for recovery operations (such as ewading core dump, on-
  demand fwlog etc...). This is done prior to disabling wl-interrupts.

  The call to elp_wakeup was removed from userspace recovery trigger routines
  (such as libnl and debugfs) because it is now redundent

Signed-off-by: Yair Shapira <yair.shapira@ti.com>
wl12xx: fix some line spacing

Remove trailing blanks...

Signed-off-by: Yair Shapira <yair.shapira@ti.com>
wl12xx: triggering FW assert to perform recovery

Driver based FW recovery was modified. It is now trying to trigger
FW assert and waiting for WATCHDOG interrupt before continuing with
recovery.

This is done to allow FW to perform cleanups and halt gracefully
before recovery is performed. This allows for safe reading of
on-demand fwlog, core_dump, etc...

FW assert triggering is done by writing 0xcafecafe to FW address 0x1c
and then triggering PHY_RX_HEADER FW interrupt which is its highest
priority interrupt.

There is a timeout of 100ms waiting for WATCHDOG interrupt.

In case timeout is reached or we get ELP or SDIO errors, we resume
recovery without reading fwlog, core_dump, etc beacuse we assume that
FW is not responding...

Signed-off-by: Yair Shapira <yair.shapira@ti.com>
wl12xx: decrease elp timeout to 20ms

The current elp timeout set to 200 ms is too high.
While its purpose was to avoid going to ELP
during Tx/Rx the problem is that it keeps the
device awake also after issuing commands when there's
no traffic. In Android this is a real problem as
RSSI is polled by the framework every 3 seconds
and keeping the chip out of ELP for 200ms each time
has a significant power consumption effect.

Fix that by changing to 20ms. This prevents excessive
real elp sleeps and wakeups during Rx/Tx with 12xx.
There's no real need any more for setting a hard
coded 5ms while in forced_ps.

The fw won't enter elp anyways before the dynamic-ps
timeout expired as well (and it entered ps
successfully).

(Based on a similar patch by Eliad for wlcore)

Signed-off-by: Eyal Shapira <eyal@wizery.com>
wl12xx: Copy FW log as entire mem block

FW log copy is simplified to copy the entire
memory block as FW logger utility is repsponsible
for parsing of FW log content.
(Similar commit was applied to wl18xx:
wlcore/wl18xx/wl12xx: FW log params per chip arch)

Signed-off-by: Igal Chernobelsky <igalc@ti.com>
mac80211: purge offchannel Tx on reconfig

Offchannel Tx occuring during reconfig can cause us the low level driver
to start various operations on the wrong channel, similar to remain on
channel operations. Purge them before reconfig.

Reported-by: Eyal Shapira <eyal@wizery.com>
Signed-off-by: Arik Nemtsov <arik@wizery.com>
wl12xx: disable elp sleep while in plt mode

We now disable elp sleep during plt mode to allow normal operation of
plt tools such as calibrator.

Having elp_sleep enabled during plt mode is actually not required and
in fact it distupt plt operations such as rx statistics etc...

Signed-off-by: Yair Shapira <yair.shapira@ti.com>
wl12xx: check for required fw change while enable or disable role

In certain scenarios our current hooks for checking required
fw change aren't enough and we could be left in MR even though
we've gone back to a single interface. This is of course not
good as we prefer running with the SR FW which contains goodies
like BTCOEX.

An example scanerio is when running P2P GO + STA and then
removing the P2P GO.

Fix it by adding checks for fw change also while enable or
disable roles.

Signed-off-by: Eyal Shapira <eyal@wizery.com>
wl12xx: mutually exclude PLT and normal power modes

Small fix done to ensure that PLT mode and normal driver power
mode (ifconfig/add_interface) are mutually excluded.

This is partially based on wl18xx (R8) commit 6620ca8fe29d

Signed-off-by: Yair Shapira <yair.shapira@ti.com>
wl12xx: FW recovery trigger assert bug fix

The bug was in the partition mapping. It seems that .mem3 partition that
we used to write 'magic' 0xCAFECAFE to address 0x1C is actually in use (it
contains the struct part of the FW_STATUS). It is in use although the size
of the partition is set to 0

The fix was to save old partition, map a new partition with .mem part set to
address 0x1C and remap previous partition after writing 0xCAFECAFE.

Signed-off-by: Yair Shapira <yair.shapira@ti.com>
wl12xx: fix list_add/list_del

add list_del even if wl in off state

Signed-off-by: Ofir Luzon <ofirluzon@ti.com>
wl12xx: improve some debug logs

These turned out to be useful so add them.

Signed-off-by: Eyal Shapira <eyal@wizery.com>