mac80211: count started vifs

count the started roles by simply counting the non-idle vifs.

this method also takes care of counting non-associated
stations (when device role is started)

[Arik - backport usage of rcu here]

Signed-off-by: Eliad Peller <eliad@wizery.com>
Signed-off-by: Arik Nemtsov <arik@wizery.com>
wl12xx: delay fw switch to start/stop_role_sta/ap

do the fw switch only when the role was started/stopped

Signed-off-by: Eliad Peller <eliad@wizery.com>
wl12xx: add grace period when changing MR -> SR fw

This improves user experience when performing p2p_find for instance.

[Changed grace period to 30 seconds]

Signed-off-by: Eliad Peller <eliad@wizery.com>
Signed-off-by: Arik Nemtsov <arik@wizery.com>
wl12xx: change recovery on start/stop device role

since the recovery itself will usually stop the offchannel
operation, on fw boot we will use SR fw again, which will
result in endless recoveries... avoid it by forcing MR fw
for some grace period after it was needed.

Signed-off-by: Eliad Peller <eliad@wizery.com>
Signed-off-by: Arik Nemtsov <arik@wizery.com>
wl12xx: increase WL12XX_MAX_ROLES

when working with AP + 2*STA we have more than
4 active roles. increase WL12XX_MAX_ROLES to 6.

Signed-off-by: Eliad Peller <eliad@wizery.com>
mac80211: check sdata_running on ieee80211_set_bitrate_mask

Otherwise, we might call the driver callback before
the interface was uploaded.

Solves the following warning:
WARNING: at net/mac80211/driver-ops.h:12 ieee80211_set_bitrate_mask+0xbc/0x18c [mac80211]()
wlan0:  Failed check-sdata-in-driver check, flags: 0x0
Modules linked in: wlcore_sdio wl12xx wl18xx wlcore mac80211 cfg80211 [last unloaded: cfg80211]
[<c001b964>] (unwind_backtrace+0x0/0x12c) from [<c0495550>] (dump_stack+0x20/0x24)
[<c0495550>] (dump_stack+0x20/0x24) from [<c003ee28>] (warn_slowpath_common+0x5c/0x74)
[<c003ee28>] (warn_slowpath_common+0x5c/0x74) from [<c003eefc>] (warn_slowpath_fmt+0x40/0x48)
[<c003eefc>] (warn_slowpath_fmt+0x40/0x48) from [<bf5c1ad0>] (ieee80211_set_bitrate_mask+0xbc/0x18c [mac80211])
[<bf5c1ad0>] (ieee80211_set_bitrate_mask+0xbc/0x18c [mac80211]) from [<bf575960>] (nl80211_set_tx_bitrate_mask+0x350/0x358 [cfg80211])
[<bf575960>] (nl80211_set_tx_bitrate_mask+0x350/0x358 [cfg80211]) from [<c03e9e94>] (genl_rcv_msg+0x1a8/0x1e8)
[<c03e9e94>] (genl_rcv_msg+0x1a8/0x1e8) from [<c03e9164>] (netlink_rcv_skb+0x5c/0xc0)
[<c03e9164>] (netlink_rcv_skb+0x5c/0xc0) from [<c03e9ce0>] (genl_rcv+0x28/0x34)
[<c03e9ce0>] (genl_rcv+0x28/0x34) from [<c03e8e74>] (netlink_unicast+0x158/0x234)
[<c03e8e74>] (netlink_unicast+0x158/0x234) from [<c03e93e0>] (netlink_sendmsg+0x218/0x298)
[<c03e93e0>] (netlink_sendmsg+0x218/0x298) from [<c03b4e5c>] (sock_sendmsg+0xa4/0xc0)
[<c03b4e5c>] (sock_sendmsg+0xa4/0xc0) from [<c03b5af4>] (__sys_sendmsg+0x1d8/0x254)
[<c03b5af4>] (__sys_sendmsg+0x1d8/0x254) from [<c03b5ca8>] (sys_sendmsg+0x4c/0x70)
[<c03b5ca8>] (sys_sendmsg+0x4c/0x70) from [<c0013980>] (ret_fast_syscall+0x0/0x3c)

Note that calling the driver can also result
in undefined behaviour since it doesn't have
to deal with calls while down.

Signed-off-by: Eliad Peller <eliad@wizery.com>
[removed timestamps, added note - Johannes]
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
wlcore: send EAPOLs using minimum basic rate for all roles

Send EAPOLs using minimum basic rate for AP, STA, p2p GO and Client.
The patch fixes p2p connection issue with Realtek device in p2p
certification test 5.1.13 (DEVUT reinvokes Persistent Group).

Signed-off-by: Igal Chernobelsky <igalc@ti.com>
wlcore: use basic rates for non-data packets

After the latest mac80211 changes, the sta has
the ap's sta pointer even before association.

This cause the auth and assoc frames to be sent
with the standard ap's rates, rather than the
basic rates.

Change the tx rate policy logic to use the regular
ap rates only for data packets (so control and mgmt
packets will be sent with basic rates)

Signed-off-by: Eliad Peller <eliad@wizery.com>
wlcore: define number of supported bands internally

Avoid using the IEEE80211_NUM_BANDS constant for arrays sizes etc, as
this can contain bands unsupported by the driver (e.g. 60Ghz). Use an
internal constant to determine the number of bands.

Signed-off-by: Arik Nemtsov <arik@wizery.com>
mac80211: fix invalid band deref building preq IEs

The function building probe-request IEs does not validate the band is
supported before dereferencing it. This can result in a panic when
all bands are traversed, as done during sched-scan start.

Warn when this happens and return an empty probe request. Also fix
sched-scan to not waste memory on unsupported bands.

Signed-off-by: Arik Nemtsov <arik@wizery.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
cfg80211/nl80211/wl12xx: align to new nl80211.h ABI

This includes some minor changes:
- change NL80211_CQM_RSSI_BEACON_LOSS to
  NL80211_CQM_RSSI_BEACON_LOSS_EVENT
- remove all features concerning advertisement of intermediate scan
  capabilities. These are currently unused.

Signed-off-by: Arik Nemtsov <arik@wizery.com>
wl12xx: change verbose debug print

This print_info might be too verbose in some p2p
scenarios so change the wl1271_info() to
wl1271_debug() in wl12xx_need_fw_change().

Signed-off-by: Victor Goldenshtein <victorg@ti.com>
mac80211: skip the ps count of idle STAs

To be able to enter ps on a SR FW with more than one
interface up, while only one interface is connected
and others are idle.

Signed-off-by: Victor Goldenshtein <victorg@ti.com>
wl12xx: AP mode - send non-data packets with basic rates

This solves interoperability issues with peer that don't seem to "hear"
management packets transmitted in higher rates. Based on a previous
patch by Igal Chernobelsky.

Cc: Igal Chernobelsky <igalc@ti.com>
Signed-off-by: Arik Nemtsov <arik@wizery.com>
wl12xx: allow only the lowest OFDM rate for p2p setup frames

The IEEE80211_TX_CTL_NO_CCK_RATE flag is only set for mgmt packets
transmitted during p2p connection setup. Make sure to use the lowest
OFDM rate guarantee the peer always hears us.
Change the p2p rate policy to contain only the 6mpbs rate to acheive
this effect.

Signed-off-by: Arik Nemtsov <arik@wizery.com>
wl12xx: make Tx flush timings more verbose

Print how much time a flush took. This will help debug the time it takes
to switch between channels.

Signed-off-by: Arik Nemtsov <arik@wizery.com>
wlcore: add stop reason bitmap for waking/starting queues

Allow the driver to wake/stop the queues for multiple reasons. A queue
is started when no stop-reasons exist.

Convert all wake/stop queue calls to use the new API.

Before, a stopped queue was almost synonymous a high-watermark on Tx.
Remove a bit of code in wl12xx_tx_reset() that relied on it.

Internal packets arriving from mac80211 are also discarded when a queue
is stopped. A notable exception to this is the watermark reason, which
is a "soft"-stop reason. We allow traffic to gradually come to a halt,
but we don't mind spurious packets here and there. This is merely a flow
regulation mechanism.

Based on a similar patch by Eliad Peller <eliadWizery.com>.

Signed-off-by: Arik Nemtsov <arik@wizery.com>
Signed-off-by: Luciano Coelho <coelho@ti.com>
wlcore: stop queues on Tx flush

Stop network queues during Tx flush, and also drop other internal
mac80211 packets (mgmt) that may arrive when the queues are stopped.

When flush is done all driver queues are clear, forcefully if needed.

Protect the Tx flush operation with a new mutex, to prevent concurrency
that can mess us queue state.

Based on a patch by Eliad Peller <eliad@wizery.com>

Signed-off-by: Arik Nemtsov <arik@wizery.com>
Signed-off-by: Luciano Coelho <coelho@ti.com>
wlcore: don't stop tx queue via watermark if already stopped

If a Tx queue is currently stopped because of our Tx watermark flow
control, don't stop it again. This causes a warning to appear.

Signed-off-by: Arik Nemtsov <arik@wizery.com>
Signed-off-by: Luciano Coelho <coelho@ti.com>
mac80211: avoid using synchronize_rcu in ieee80211_config_beacon

This was causing a very long delay (>200ms) which would
delay sending assoc resp in cases of an AP with WPS (where
the beacon gets updated after assoc req is received).
Some devices like Galaxy Nexus don't accept the assoc resp
if it's delayed for too long. This is causing connection issues
in AP mode with WPS and in P2P GO.

Switch instead to using kfree_rcu which wouldn't block here
but is still safe.

(This is based on upstream changes by Johannes)

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