Re: [PATCH 02/10] mt76: move mt76x02_rx_get_sta and mt76x02_rx_get_sta_wcid in mt76x02_util.c

2018-10-01 Thread Felix Fietkau
On 2018-10-02 00:19, Lorenzo Bianconi wrote:
> Move mt76x02_rx_get_sta and mt76x02_rx_get_sta_wcid utility routines in
> mt76x02-lib module since it will be used by mt76x0 driver in order to
> unify rxwi parsing
> 
> Signed-off-by: Lorenzo Bianconi 
> ---
>  .../net/wireless/mediatek/mt76/mt76x02_util.c | 29 +
>  .../net/wireless/mediatek/mt76/mt76x02_util.h |  3 ++
>  .../net/wireless/mediatek/mt76/mt76x2/mac.c   | 32 ++-
>  3 files changed, 34 insertions(+), 30 deletions(-)
> 
> diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_util.c 
> b/drivers/net/wireless/mediatek/mt76/mt76x02_util.c
> index b12db0a108d3..496be05e59a6 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt76x02_util.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_util.c
> @@ -531,4 +531,33 @@ void mt76x02_set_beacon_offsets(struct mt76_dev *dev)
>  }
>  EXPORT_SYMBOL_GPL(mt76x02_set_beacon_offsets);
>  
> +struct mt76x02_sta *
> +mt76x02_rx_get_sta(struct mt76_dev *dev, u8 idx)
> +{
> + struct mt76_wcid *wcid;
> +
> + if (idx >= ARRAY_SIZE(dev->wcid))
> + return NULL;
> +
> + wcid = rcu_dereference(dev->wcid[idx]);
> + if (!wcid)
> + return NULL;
> +
> + return container_of(wcid, struct mt76x02_sta, wcid);
> +}
> +EXPORT_SYMBOL_GPL(mt76x02_rx_get_sta);
> +
> +struct mt76_wcid *
> +mt76x02_rx_get_sta_wcid(struct mt76x02_sta *sta, bool unicast)
> +{
> + if (!sta)
> + return NULL;
> +
> + if (unicast)
> + return >wcid;
> + else
> + return >vif->group_wcid;
> +}
> +EXPORT_SYMBOL_GPL(mt76x02_rx_get_sta_wcid);
Both of these functions are trivial and should be inline.

- Felix


Re: [PATCH] ath9k: add back support for using active monitor interfaces for tx99

2018-10-01 Thread Kalle Valo
Felix Fietkau  wrote:

> Various documented examples on how to set up tx99 with ath9k rely
> on setting up a regular monitor interface for setting the channel.
> My previous patch "ath9k: fix tx99 with monitor mode interface" made
> it possible to set it up this way again. However, it was removing support
> for using an active monitor interface, which is required for controlling
> the bitrate as well, since the bitrate is not passed down with a regular
> monitor interface.
> 
> This patch partially reverts the previous one, but keeps support for using
> a regular monitor interface to keep documented steps working in cases
> where the bitrate does not matter
> 
> Fixes: d9c52fd17cb48 ("ath9k: fix tx99 with monitor mode interface")
> Signed-off-by: Felix Fietkau 
> Signed-off-by: Kalle Valo 

Patch applied to ath-next branch of ath.git, thanks.

6df0580be8bc ath9k: add back support for using active monitor interfaces for 
tx99

-- 
https://patchwork.kernel.org/patch/10612069/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches



Re: [PATCH 1/5] ath9k: add counters for good and errorneous FFT/spectral frames

2018-10-01 Thread Kalle Valo
Simon Wunderlich  wrote:

> This is helpful to see whether spectral samples get discarded.
> 
> Signed-off-by: Simon Wunderlich 
> Signed-off-by: Kalle Valo 

5 patches applied to ath-next branch of ath.git, thanks.

03224678c013 ath9k: add counters for good and errorneous FFT/spectral frames
b796a6c04e65 ath9k: return when short FFT frame was handled
2f85786b8a57 ath9k: fix and simplify FFT max index retrieval
4e7a3fa5394e ath9k: FFT magnitude check: don't consider lower 3 data bits
4fb5837ac2bd ath9k: fix reporting calculated new FFT upper max

-- 
https://patchwork.kernel.org/patch/10605607/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches



[PATCH 2/3] mt76: rename mt76x02_util.h in mt76x02.h

2018-10-01 Thread Lorenzo Bianconi
Rename mt76x02_util.h header file in mt76x02.h since now contains
all mt76x02 related definitions and not just utility routines
declarations

Signed-off-by: Lorenzo Bianconi 
---
 drivers/net/wireless/mediatek/mt76/mt76x0/init.c | 3 ---
 drivers/net/wireless/mediatek/mt76/mt76x0/mac.c  | 4 ++--
 drivers/net/wireless/mediatek/mt76/mt76x0/main.c | 3 +--
 drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h   | 5 +
 drivers/net/wireless/mediatek/mt76/mt76x0/pci.c  | 2 --
 drivers/net/wireless/mediatek/mt76/mt76x0/usb.c  | 1 -
 .../net/wireless/mediatek/mt76/{mt76x02_util.h => mt76x02.h} | 3 +++
 drivers/net/wireless/mediatek/mt76/mt76x02_mac.c | 5 +
 drivers/net/wireless/mediatek/mt76/mt76x02_mmio.c| 5 +
 drivers/net/wireless/mediatek/mt76/mt76x02_txrx.c| 5 +
 drivers/net/wireless/mediatek/mt76/mt76x02_usb_core.c| 5 +
 drivers/net/wireless/mediatek/mt76/mt76x02_util.c| 5 +
 drivers/net/wireless/mediatek/mt76/mt76x2/mac.c  | 1 -
 drivers/net/wireless/mediatek/mt76/mt76x2/mac.h  | 3 +--
 drivers/net/wireless/mediatek/mt76/mt76x2/mcu.c  | 1 -
 drivers/net/wireless/mediatek/mt76/mt76x2/mt76x2.h   | 4 +---
 drivers/net/wireless/mediatek/mt76/mt76x2/mt76x2u.h  | 1 -
 drivers/net/wireless/mediatek/mt76/mt76x2/pci_core.c | 1 -
 drivers/net/wireless/mediatek/mt76/mt76x2/pci_dfs.c  | 1 -
 drivers/net/wireless/mediatek/mt76/mt76x2/pci_dma.c  | 2 --
 drivers/net/wireless/mediatek/mt76/mt76x2/pci_init.c | 2 --
 drivers/net/wireless/mediatek/mt76/mt76x2/pci_mac.c  | 1 -
 drivers/net/wireless/mediatek/mt76/mt76x2/pci_main.c | 1 -
 drivers/net/wireless/mediatek/mt76/mt76x2/pci_mcu.c  | 1 -
 drivers/net/wireless/mediatek/mt76/mt76x2/pci_tx.c   | 2 --
 drivers/net/wireless/mediatek/mt76/mt76x2/usb_init.c | 3 +--
 drivers/net/wireless/mediatek/mt76/mt76x2/usb_main.c | 1 -
 27 files changed, 15 insertions(+), 56 deletions(-)
 rename drivers/net/wireless/mediatek/mt76/{mt76x02_util.h => mt76x02.h} (98%)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/init.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/init.c
index d0f2ee6d7040..ee2b8e885608 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/init.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/init.c
@@ -18,9 +18,6 @@
 #include "eeprom.h"
 #include "trace.h"
 #include "mcu.h"
-#include "../mt76x02_util.h"
-#include "../mt76x02_dma.h"
-
 #include "initvals.h"
 
 static void mt76x0_vht_cap_mask(struct ieee80211_supported_band *sband)
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/mac.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/mac.c
index 793297cd6bf1..7a422c590211 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/mac.c
@@ -13,10 +13,10 @@
  * GNU General Public License for more details.
  */
 
+#include 
+
 #include "mt76x0.h"
 #include "trace.h"
-#include "../mt76x02_util.h"
-#include 
 
 void mt76x0_mac_set_protection(struct mt76x02_dev *dev, bool legacy_prot,
   int ht_mode)
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/main.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/main.c
index 7803aa00491e..c9cd0254a979 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/main.c
@@ -13,9 +13,8 @@
  * GNU General Public License for more details.
  */
 
-#include "mt76x0.h"
-#include "../mt76x02_util.h"
 #include 
+#include "mt76x0.h"
 
 int mt76x0_config(struct ieee80211_hw *hw, u32 changed)
 {
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h 
b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h
index 237407200908..1bff2be45a13 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h
@@ -25,10 +25,7 @@
 #include 
 #include 
 
-#include "../mt76.h"
-#include "../mt76x02_regs.h"
-#include "../mt76x02_mac.h"
-#include "../mt76x02_util.h"
+#include "../mt76x02.h"
 #include "eeprom.h"
 
 #define MT_CALIBRATE_INTERVAL  (4 * HZ)
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c
index 80c6b1ca9065..55c62e40499b 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c
@@ -20,8 +20,6 @@
 
 #include "mt76x0.h"
 #include "mcu.h"
-#include "../mt76x02_dma.h"
-#include "../mt76x02_util.h"
 
 static int mt76x0e_start(struct ieee80211_hw *hw)
 {
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c
index d77de5f43920..2080933efa2e 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c
@@ -18,7 +18,6 @@
 #include "mt76x0.h"
 #include 

[PATCH 1/3] mt76: move txrx shared routines in mt76x02_txrx.c

2018-10-01 Thread Lorenzo Bianconi
Add mt76x02_txrx.c source file in order to contain tx/rx shared
routines for mt76x0 and mt76x2 drivers

Signed-off-by: Lorenzo Bianconi 
---
 drivers/net/wireless/mediatek/mt76/Makefile   |   3 +-
 .../net/wireless/mediatek/mt76/mt76x02_txrx.c | 162 ++
 .../net/wireless/mediatek/mt76/mt76x02_util.c | 140 ---
 3 files changed, 164 insertions(+), 141 deletions(-)
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x02_txrx.c

diff --git a/drivers/net/wireless/mediatek/mt76/Makefile 
b/drivers/net/wireless/mediatek/mt76/Makefile
index 907b9e2d7044..09c90eef61a4 100644
--- a/drivers/net/wireless/mediatek/mt76/Makefile
+++ b/drivers/net/wireless/mediatek/mt76/Makefile
@@ -12,7 +12,8 @@ CFLAGS_trace.o := -I$(src)
 CFLAGS_usb_trace.o := -I$(src)
 
 mt76x02-lib-y := mt76x02_util.o mt76x02_mac.o mt76x02_mcu.o \
-mt76x02_eeprom.o mt76x02_phy.o mt76x02_mmio.o
+mt76x02_eeprom.o mt76x02_phy.o mt76x02_mmio.o \
+mt76x02_txrx.o
 
 mt76x02-usb-y := mt76x02_usb_mcu.o mt76x02_usb_core.o
 
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_txrx.c 
b/drivers/net/wireless/mediatek/mt76/mt76x02_txrx.c
new file mode 100644
index ..caa9bb107e68
--- /dev/null
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_txrx.c
@@ -0,0 +1,162 @@
+/*
+ * Copyright (C) 2016 Felix Fietkau 
+ * Copyright (C) 2018 Lorenzo Bianconi 
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include 
+
+#include "mt76.h"
+#include "mt76x02_regs.h"
+#include "mt76x02_dma.h"
+#include "mt76x02_util.h"
+
+void mt76x02_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control,
+   struct sk_buff *skb)
+{
+   struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
+   struct mt76x02_dev *dev = hw->priv;
+   struct ieee80211_vif *vif = info->control.vif;
+   struct mt76_wcid *wcid = >mt76.global_wcid;
+
+   if (control->sta) {
+   struct mt76x02_sta *msta;
+
+   msta = (struct mt76x02_sta *)control->sta->drv_priv;
+   wcid = >wcid;
+   /* sw encrypted frames */
+   if (!info->control.hw_key && wcid->hw_key_idx != 0xff)
+   control->sta = NULL;
+   }
+
+   if (vif && !control->sta) {
+   struct mt76x02_vif *mvif;
+
+   mvif = (struct mt76x02_vif *)vif->drv_priv;
+   wcid = >group_wcid;
+   }
+
+   mt76_tx(>mt76, control->sta, wcid, skb);
+}
+EXPORT_SYMBOL_GPL(mt76x02_tx);
+
+void mt76x02_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q,
+ struct sk_buff *skb)
+{
+   struct mt76x02_dev *dev = container_of(mdev, struct mt76x02_dev, mt76);
+   void *rxwi = skb->data;
+
+   if (q == MT_RXQ_MCU) {
+   /* this is used just by mmio code */
+   skb_queue_tail(>mmio.mcu.res_q, skb);
+   wake_up(>mmio.mcu.wait);
+   return;
+   }
+
+   skb_pull(skb, sizeof(struct mt76x02_rxwi));
+   if (mt76x02_mac_process_rx(dev, skb, rxwi)) {
+   dev_kfree_skb(skb);
+   return;
+   }
+
+   mt76_rx(mdev, q, skb);
+}
+EXPORT_SYMBOL_GPL(mt76x02_queue_rx_skb);
+
+s8 mt76x02_tx_get_max_txpwr_adj(struct mt76_dev *dev,
+   const struct ieee80211_tx_rate *rate)
+{
+   s8 max_txpwr;
+
+   if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
+   u8 mcs = ieee80211_rate_get_vht_mcs(rate);
+
+   if (mcs == 8 || mcs == 9) {
+   max_txpwr = dev->rate_power.vht[8];
+   } else {
+   u8 nss, idx;
+
+   nss = ieee80211_rate_get_vht_nss(rate);
+   idx = ((nss - 1) << 3) + mcs;
+   max_txpwr = dev->rate_power.ht[idx & 0xf];
+   }
+   } else if (rate->flags & IEEE80211_TX_RC_MCS) {
+   max_txpwr = dev->rate_power.ht[rate->idx & 0xf];
+   } else {
+   enum nl80211_band band = dev->chandef.chan->band;
+
+   if (band == NL80211_BAND_2GHZ) {
+   const struct ieee80211_rate *r;
+   struct wiphy *wiphy = dev->hw->wiphy;
+   struct mt76_rate_power *rp = 

[PATCH 3/3] mt76x2: remove leftover function declatarions

2018-10-01 Thread Lorenzo Bianconi
Remove following function declarations since they have been moved
to mt76x02-lib module:
- mt76x2_sta_add
- mt76x2_sta_remove
- mt76x2_remove_interface
- mt76x2_conf_tx
- mt76x2_txq_init

Signed-off-by: Lorenzo Bianconi 
---
 drivers/net/wireless/mediatek/mt76/mt76x2/mt76x2.h | 10 --
 1 file changed, 10 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/mt76x2.h 
b/drivers/net/wireless/mediatek/mt76/mt76x2/mt76x2.h
index 62a211563056..c4d1e5d8cea2 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x2/mt76x2.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76x2/mt76x2.h
@@ -111,16 +111,6 @@ void mt76x2_init_txpower(struct mt76x02_dev *dev,
 struct ieee80211_supported_band *sband);
 void mt76_write_mac_initvals(struct mt76x02_dev *dev);
 
-int mt76x2_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
-  struct ieee80211_sta *sta);
-int mt76x2_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
- struct ieee80211_sta *sta);
-void mt76x2_remove_interface(struct ieee80211_hw *hw,
-struct ieee80211_vif *vif);
-int mt76x2_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
-  u16 queue, const struct ieee80211_tx_queue_params *params);
-void mt76x2_txq_init(struct mt76x02_dev *dev, struct ieee80211_txq *txq);
-
 void mt76x2_phy_tssi_compensate(struct mt76x02_dev *dev, bool wait);
 void mt76x2_phy_set_txpower_regs(struct mt76x02_dev *dev,
 enum nl80211_band band);
-- 
2.19.0



[PATCH 0/3] split code in mt76x02_util.{c,h}

2018-10-01 Thread Lorenzo Bianconi
Move shared tx/rx code in mt76x02_txrx.c. Moreover rename
mt76x02_util.h in mt76x02.h since now it contains most
relevant mt76x02 data structures

Lorenzo Bianconi (3):
  mt76: move txrx shared routines in mt76x02_txrx.c
  mt76: rename mt76x02_util.h in mt76x02.h
  mt76x2: remove leftover function declatarions

 drivers/net/wireless/mediatek/mt76/Makefile   |   3 +-
 .../net/wireless/mediatek/mt76/mt76x0/init.c  |   3 -
 .../net/wireless/mediatek/mt76/mt76x0/mac.c   |   4 +-
 .../net/wireless/mediatek/mt76/mt76x0/main.c  |   3 +-
 .../wireless/mediatek/mt76/mt76x0/mt76x0.h|   5 +-
 .../net/wireless/mediatek/mt76/mt76x0/pci.c   |   2 -
 .../net/wireless/mediatek/mt76/mt76x0/usb.c   |   1 -
 .../mt76/{mt76x02_util.h => mt76x02.h}|   3 +
 .../net/wireless/mediatek/mt76/mt76x02_mac.c  |   5 +-
 .../net/wireless/mediatek/mt76/mt76x02_mmio.c |   5 +-
 .../net/wireless/mediatek/mt76/mt76x02_txrx.c | 159 ++
 .../wireless/mediatek/mt76/mt76x02_usb_core.c |   5 +-
 .../net/wireless/mediatek/mt76/mt76x02_util.c | 145 +---
 .../net/wireless/mediatek/mt76/mt76x2/mac.c   |   1 -
 .../net/wireless/mediatek/mt76/mt76x2/mac.h   |   3 +-
 .../net/wireless/mediatek/mt76/mt76x2/mcu.c   |   1 -
 .../wireless/mediatek/mt76/mt76x2/mt76x2.h|  14 +-
 .../wireless/mediatek/mt76/mt76x2/mt76x2u.h   |   1 -
 .../wireless/mediatek/mt76/mt76x2/pci_core.c  |   1 -
 .../wireless/mediatek/mt76/mt76x2/pci_dfs.c   |   1 -
 .../wireless/mediatek/mt76/mt76x2/pci_dma.c   |   2 -
 .../wireless/mediatek/mt76/mt76x2/pci_init.c  |   2 -
 .../wireless/mediatek/mt76/mt76x2/pci_mac.c   |   1 -
 .../wireless/mediatek/mt76/mt76x2/pci_main.c  |   1 -
 .../wireless/mediatek/mt76/mt76x2/pci_mcu.c   |   1 -
 .../wireless/mediatek/mt76/mt76x2/pci_tx.c|   2 -
 .../wireless/mediatek/mt76/mt76x2/usb_init.c  |   3 +-
 .../wireless/mediatek/mt76/mt76x2/usb_main.c  |   1 -
 28 files changed, 175 insertions(+), 203 deletions(-)
 rename drivers/net/wireless/mediatek/mt76/{mt76x02_util.h => mt76x02.h} (98%)
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x02_txrx.c

-- 
2.19.0



[PATCH 07/10] mt76x0: merge mt76x0_dev in mt76x02_dev

2018-10-01 Thread Lorenzo Bianconi
Merge mt76x0_dev data structure in mt76x02_dev one and remove
duplicated code. Remove unused definition in mt76x0.h.
Moreover merge mt76x0_caldata and mt76x02_rx_freq_cal data structures.
This is a preliminary patch for rxwi unification.

Signed-off-by: Lorenzo Bianconi 
---
 .../wireless/mediatek/mt76/mt76x0/debugfs.c   |   4 +-
 .../wireless/mediatek/mt76/mt76x0/eeprom.c|  28 ++---
 .../wireless/mediatek/mt76/mt76x0/eeprom.h|  18 +---
 .../net/wireless/mediatek/mt76/mt76x0/init.c  |  34 +++---
 .../net/wireless/mediatek/mt76/mt76x0/mac.c   |  16 +--
 .../net/wireless/mediatek/mt76/mt76x0/mac.h   |   4 +-
 .../net/wireless/mediatek/mt76/mt76x0/main.c  |  12 +--
 .../net/wireless/mediatek/mt76/mt76x0/mcu.h   |   8 +-
 .../wireless/mediatek/mt76/mt76x0/mt76x0.h| 102 --
 .../net/wireless/mediatek/mt76/mt76x0/pci.c   |  16 +--
 .../wireless/mediatek/mt76/mt76x0/pci_mcu.c   |   4 +-
 .../net/wireless/mediatek/mt76/mt76x0/phy.c   |  74 +++--
 .../net/wireless/mediatek/mt76/mt76x0/tx.c|   4 +-
 .../net/wireless/mediatek/mt76/mt76x0/usb.c   |  20 ++--
 .../wireless/mediatek/mt76/mt76x0/usb_mcu.c   |   6 +-
 .../net/wireless/mediatek/mt76/mt76x02_util.h |  17 +++
 16 files changed, 157 insertions(+), 210 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c
index ddc1af626b3b..3224e5b1a1e5 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c
@@ -21,7 +21,7 @@
 static int
 mt76x0_ampdu_stat_read(struct seq_file *file, void *data)
 {
-   struct mt76x0_dev *dev = file->private;
+   struct mt76x02_dev *dev = file->private;
int i, j;
 
 #define stat_printf(grp, off, name)\
@@ -75,7 +75,7 @@ static const struct file_operations fops_ampdu_stat = {
.release = single_release,
 };
 
-void mt76x0_init_debugfs(struct mt76x0_dev *dev)
+void mt76x0_init_debugfs(struct mt76x02_dev *dev)
 {
struct dentry *dir;
 
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c
index 166a1fd8644e..5735038c0e2d 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c
@@ -25,7 +25,7 @@
 
 #define MT_MAP_READS   DIV_ROUND_UP(MT_EFUSE_USAGE_MAP_SIZE, 16)
 static int
-mt76x0_efuse_physical_size_check(struct mt76x0_dev *dev)
+mt76x0_efuse_physical_size_check(struct mt76x02_dev *dev)
 {
u8 data[MT_MAP_READS * 16];
int ret, i;
@@ -53,7 +53,7 @@ mt76x0_efuse_physical_size_check(struct mt76x0_dev *dev)
return 0;
 }
 
-static void mt76x0_set_chip_cap(struct mt76x0_dev *dev)
+static void mt76x0_set_chip_cap(struct mt76x02_dev *dev)
 {
u16 nic_conf0 = mt76x02_eeprom_get(>mt76, MT_EE_NIC_CONF_0);
u16 nic_conf1 = mt76x02_eeprom_get(>mt76, MT_EE_NIC_CONF_1);
@@ -82,20 +82,20 @@ static void mt76x0_set_chip_cap(struct mt76x0_dev *dev)
dev_err(dev->mt76.dev, "invalid tx-rx stream\n");
 }
 
-static void mt76x0_set_temp_offset(struct mt76x0_dev *dev)
+static void mt76x0_set_temp_offset(struct mt76x02_dev *dev)
 {
u8 val;
 
val = mt76x02_eeprom_get(>mt76, MT_EE_2G_TARGET_POWER) >> 8;
if (mt76x02_field_valid(val))
-   dev->caldata.temp_offset = mt76x02_sign_extend(val, 8);
+   dev->cal.rx.temp_offset = mt76x02_sign_extend(val, 8);
else
-   dev->caldata.temp_offset = -10;
+   dev->cal.rx.temp_offset = -10;
 }
 
-static void mt76x0_set_freq_offset(struct mt76x0_dev *dev)
+static void mt76x0_set_freq_offset(struct mt76x02_dev *dev)
 {
-   struct mt76x0_caldata *caldata = >caldata;
+   struct mt76x02_rx_freq_cal *caldata = >cal.rx;
u8 val;
 
val = mt76x02_eeprom_get(>mt76, MT_EE_FREQ_OFFSET);
@@ -110,10 +110,10 @@ static void mt76x0_set_freq_offset(struct mt76x0_dev *dev)
caldata->freq_offset -= mt76x02_sign_extend(val, 8);
 }
 
-void mt76x0_read_rx_gain(struct mt76x0_dev *dev)
+void mt76x0_read_rx_gain(struct mt76x02_dev *dev)
 {
struct ieee80211_channel *chan = dev->mt76.chandef.chan;
-   struct mt76x0_caldata *caldata = >caldata;
+   struct mt76x02_rx_freq_cal *caldata = >cal.rx;
s8 val, lna_5g[3], lna_2g;
u16 rssi_offset;
int i;
@@ -157,7 +157,7 @@ static s8 mt76x0_get_delta(struct mt76_dev *dev)
return mt76x02_rate_power_val(val);
 }
 
-void mt76x0_get_tx_power_per_rate(struct mt76x0_dev *dev)
+void mt76x0_get_tx_power_per_rate(struct mt76x02_dev *dev)
 {
struct ieee80211_channel *chan = dev->mt76.chandef.chan;
bool is_2ghz = chan->band == NL80211_BAND_2GHZ;
@@ -216,7 +216,7 @@ void mt76x0_get_tx_power_per_rate(struct mt76x0_dev *dev)
mt76x02_add_rate_power_offset(t, delta);
 }
 
-void mt76x0_get_power_info(struct mt76x0_dev *dev, u8 *info)
+void 

[PATCH 10/10] mt76: move mt76x02_tx in mt76x02-lib module

2018-10-01 Thread Lorenzo Bianconi
Move mt76x02_tx shared routine in mt76x02-lib module and remove
duplicated code. Moreover remove mt76x0/tx.c since it is an empty
file

Signed-off-by: Lorenzo Bianconi 
---
 .../wireless/mediatek/mt76/mt76x0/Makefile|  2 +-
 .../wireless/mediatek/mt76/mt76x0/mt76x0.h|  4 --
 .../net/wireless/mediatek/mt76/mt76x0/pci.c   |  2 +-
 .../net/wireless/mediatek/mt76/mt76x0/tx.c| 47 ---
 .../net/wireless/mediatek/mt76/mt76x0/usb.c   |  2 +-
 .../net/wireless/mediatek/mt76/mt76x02_util.c | 29 
 .../net/wireless/mediatek/mt76/mt76x02_util.h |  2 +
 .../wireless/mediatek/mt76/mt76x2/mt76x2.h|  2 -
 .../wireless/mediatek/mt76/mt76x2/pci_main.c  |  2 +-
 .../net/wireless/mediatek/mt76/mt76x2/tx.c| 29 
 .../wireless/mediatek/mt76/mt76x2/usb_main.c  |  2 +-
 11 files changed, 36 insertions(+), 87 deletions(-)
 delete mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/tx.c

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/Makefile 
b/drivers/net/wireless/mediatek/mt76/mt76x0/Makefile
index 254d94efd24d..20672978dceb 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/Makefile
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/Makefile
@@ -4,7 +4,7 @@ obj-$(CONFIG_MT76x0_COMMON) += mt76x0-common.o
 
 mt76x0-common-y := \
init.o main.o trace.o eeprom.o phy.o \
-   mac.o debugfs.o tx.o
+   mac.o debugfs.o
 mt76x0u-y := usb.o usb_mcu.o
 mt76x0e-y := pci.o pci_mcu.o
 
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h 
b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h
index 640f6cd6ef1c..237407200908 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h
@@ -84,8 +84,4 @@ void mt76x0_mac_set_short_preamble(struct mt76x02_dev *dev, 
bool short_preamb);
 void mt76x0_mac_config_tsf(struct mt76x02_dev *dev, bool enable, int interval);
 void mt76x0_mac_set_ampdu_factor(struct mt76x02_dev *dev);
 
-/* TX */
-void mt76x0_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control,
-   struct sk_buff *skb);
-
 #endif
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c
index f6f54cac0326..80c6b1ca9065 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c
@@ -70,7 +70,7 @@ static void mt76x0e_stop(struct ieee80211_hw *hw)
 }
 
 static const struct ieee80211_ops mt76x0e_ops = {
-   .tx = mt76x0_tx,
+   .tx = mt76x02_tx,
.start = mt76x0e_start,
.stop = mt76x0e_stop,
.config = mt76x0_config,
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/tx.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/tx.c
deleted file mode 100644
index 34d115be3447..
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/tx.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2014 Felix Fietkau 
- * Copyright (C) 2015 Jakub Kicinski 
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2
- * as published by the Free Software Foundation
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- */
-
-#include "mt76x0.h"
-#include "trace.h"
-#include "../mt76x02_util.h"
-#include "../mt76x02_usb.h"
-
-void mt76x0_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control,
-  struct sk_buff *skb)
-{
-   struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
-   struct mt76x02_dev *dev = hw->priv;
-   struct ieee80211_vif *vif = info->control.vif;
-   struct mt76_wcid *wcid = >mt76.global_wcid;
-
-   if (control->sta) {
-   struct mt76x02_sta *msta;
-
-   msta = (struct mt76x02_sta *)control->sta->drv_priv;
-   wcid = >wcid;
-   /* sw encrypted frames */
-   if (!info->control.hw_key && wcid->hw_key_idx != 0xff)
-   control->sta = NULL;
-   }
-
-   if (vif && !control->sta) {
-   struct mt76x02_vif *mvif;
-
-   mvif = (struct mt76x02_vif *)vif->drv_priv;
-   wcid = >group_wcid;
-   }
-
-   mt76_tx(>mt76, control->sta, wcid, skb);
-}
-EXPORT_SYMBOL_GPL(mt76x0_tx);
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c
index 1a23dd1491b6..d77de5f43920 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c
@@ -139,7 +139,7 @@ static void mt76x0u_stop(struct ieee80211_hw *hw)
 }
 
 static const struct ieee80211_ops mt76x0u_ops = {
-   .tx = mt76x0_tx,
+   .tx = mt76x02_tx,
.start = mt76x0u_start,
.stop = mt76x0u_stop,
.add_interface = 

[PATCH 05/10] mt76x0: remove hw_atomic_mutex mutex in mt76x0_dev

2018-10-01 Thread Lorenzo Bianconi
Remove hw_atomic_mutex mutex in mt76x0_dev data structure
since mt76x0_phy_set_channel is already protected by mt76_dev
mutex while mt76x0_chip_onoff is used just at device probe or
cleanup

Signed-off-by: Lorenzo Bianconi 
---
 .../net/wireless/mediatek/mt76/mt76x0/init.c|  5 -
 .../net/wireless/mediatek/mt76/mt76x0/mt76x0.h  |  3 ---
 drivers/net/wireless/mediatek/mt76/mt76x0/phy.c | 17 ++---
 3 files changed, 2 insertions(+), 23 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/init.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/init.c
index c4ea89e61c40..eb41e247a801 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/init.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/init.c
@@ -73,8 +73,6 @@ void mt76x0_chip_onoff(struct mt76x0_dev *dev, bool enable, 
bool reset)
 {
u32 val;
 
-   mutex_lock(>hw_atomic_mutex);
-
val = mt76_rr(dev, MT_WLAN_FUN_CTRL);
 
if (reset) {
@@ -96,8 +94,6 @@ void mt76x0_chip_onoff(struct mt76x0_dev *dev, bool enable, 
bool reset)
udelay(20);
 
mt76x0_set_wlan_state(dev, val, enable);
-
-   mutex_unlock(>hw_atomic_mutex);
 }
 EXPORT_SYMBOL_GPL(mt76x0_chip_onoff);
 
@@ -346,7 +342,6 @@ mt76x0_alloc_device(struct device *pdev,
 
dev = container_of(mdev, struct mt76x0_dev, mt76);
mutex_init(>reg_atomic_mutex);
-   mutex_init(>hw_atomic_mutex);
atomic_set(>avg_ampdu_len, 1);
 
return dev;
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h 
b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h
index 178fb4f085c5..66b5986d78d3 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h
@@ -72,8 +72,6 @@ enum mt_bw {
  * @mutex: ensures exclusive access from mac80211 callbacks.
  * @reg_atomic_mutex:  ensures atomicity of indirect register accesses
  * (accesses to RF and BBP).
- * @hw_atomic_mutex:   ensures exclusive access to HW during critical
- * operations (power management, channel switch).
  */
 struct mt76x0_dev {
struct mt76_dev mt76; /* must be first */
@@ -84,7 +82,6 @@ struct mt76x0_dev {
struct mt76x0_caldata caldata;
 
struct mutex reg_atomic_mutex;
-   struct mutex hw_atomic_mutex;
 
atomic_t avg_ampdu_len;
 
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
index ee7f071a96f8..661333243052 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
@@ -614,9 +614,8 @@ void mt76x0_phy_set_txpower(struct mt76x0_dev *dev)
mt76x02_phy_set_txpower(>mt76, info[0], info[1]);
 }
 
-static int
-__mt76x0_phy_set_channel(struct mt76x0_dev *dev,
-  struct cfg80211_chan_def *chandef)
+int mt76x0_phy_set_channel(struct mt76x0_dev *dev,
+  struct cfg80211_chan_def *chandef)
 {
u32 ext_cca_chan[4] = {
[0] = FIELD_PREP(MT_EXT_CCA_CFG_CCA0, 0) |
@@ -713,18 +712,6 @@ __mt76x0_phy_set_channel(struct mt76x0_dev *dev,
return 0;
 }
 
-int mt76x0_phy_set_channel(struct mt76x0_dev *dev,
-  struct cfg80211_chan_def *chandef)
-{
-   int ret;
-
-   mutex_lock(>hw_atomic_mutex);
-   ret = __mt76x0_phy_set_channel(dev, chandef);
-   mutex_unlock(>hw_atomic_mutex);
-
-   return ret;
-}
-
 void mt76x0_phy_recalibrate_after_assoc(struct mt76x0_dev *dev)
 {
u32 tx_alc, reg_val;
-- 
2.19.0



[PATCH 06/10] mt76x2: move mt76x2_dev in mt76x02_util.h

2018-10-01 Thread Lorenzo Bianconi
Move mt76x2_dev in mt76x02_util.h and rename it in mt76x02_dev
in order to be shared between mt76x2 and mt76x0 driver

Signed-off-by: Lorenzo Bianconi 
---
 .../net/wireless/mediatek/mt76/mt76x02_dfs.h  | 140 +
 .../net/wireless/mediatek/mt76/mt76x02_util.h |  71 +
 .../wireless/mediatek/mt76/mt76x2/common.c|   2 +-
 .../wireless/mediatek/mt76/mt76x2/debugfs.c   |  12 +-
 .../net/wireless/mediatek/mt76/mt76x2/dfs.h   | 134 +
 .../wireless/mediatek/mt76/mt76x2/eeprom.c|  40 ++---
 .../wireless/mediatek/mt76/mt76x2/eeprom.h|  10 +-
 .../net/wireless/mediatek/mt76/mt76x2/init.c  |  10 +-
 .../net/wireless/mediatek/mt76/mt76x2/mac.c   |   8 +-
 .../net/wireless/mediatek/mt76/mt76x2/mac.h   |  20 +--
 .../net/wireless/mediatek/mt76/mt76x2/mcu.c   |   8 +-
 .../net/wireless/mediatek/mt76/mt76x2/mcu.h   |   4 +-
 .../wireless/mediatek/mt76/mt76x2/mt76x2.h| 141 +-
 .../wireless/mediatek/mt76/mt76x2/mt76x2u.h   |  38 ++---
 .../net/wireless/mediatek/mt76/mt76x2/pci.c   |   4 +-
 .../wireless/mediatek/mt76/mt76x2/pci_core.c  |   2 +-
 .../wireless/mediatek/mt76/mt76x2/pci_dfs.c   | 139 -
 .../wireless/mediatek/mt76/mt76x2/pci_dma.c   |   4 +-
 .../wireless/mediatek/mt76/mt76x2/pci_init.c  |  38 ++---
 .../wireless/mediatek/mt76/mt76x2/pci_mac.c   |  27 ++--
 .../wireless/mediatek/mt76/mt76x2/pci_main.c  |  26 ++--
 .../wireless/mediatek/mt76/mt76x2/pci_mcu.c   |   6 +-
 .../wireless/mediatek/mt76/mt76x2/pci_phy.c   |  28 ++--
 .../wireless/mediatek/mt76/mt76x2/pci_tx.c|  12 +-
 .../net/wireless/mediatek/mt76/mt76x2/phy.c   |  18 +--
 .../net/wireless/mediatek/mt76/mt76x2/trace.h |  12 +-
 .../net/wireless/mediatek/mt76/mt76x2/tx.c|   6 +-
 .../net/wireless/mediatek/mt76/mt76x2/usb.c   |   8 +-
 .../wireless/mediatek/mt76/mt76x2/usb_init.c  |  26 ++--
 .../wireless/mediatek/mt76/mt76x2/usb_mac.c   |  12 +-
 .../wireless/mediatek/mt76/mt76x2/usb_main.c  |  16 +-
 .../wireless/mediatek/mt76/mt76x2/usb_mcu.c   |  16 +-
 .../wireless/mediatek/mt76/mt76x2/usb_phy.c   |  10 +-
 33 files changed, 539 insertions(+), 509 deletions(-)
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x02_dfs.h

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_dfs.h 
b/drivers/net/wireless/mediatek/mt76/mt76x02_dfs.h
new file mode 100644
index ..7e177c934592
--- /dev/null
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_dfs.h
@@ -0,0 +1,140 @@
+/*
+ * Copyright (C) 2016 Lorenzo Bianconi 
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef __MT76x02_DFS_H
+#define __MT76x02_DFS_H
+
+#include 
+#include 
+
+#define MT_DFS_GP_INTERVAL (10 << 4) /* 64 us unit */
+#define MT_DFS_NUM_ENGINES 4
+
+/* bbp params */
+#define MT_DFS_SYM_ROUND   0
+#define MT_DFS_DELTA_DELAY 2
+#define MT_DFS_VGA_MASK0
+#define MT_DFS_PWR_GAIN_OFFSET 3
+#define MT_DFS_PWR_DOWN_TIME   0xf
+#define MT_DFS_RX_PE_MASK  0xff
+#define MT_DFS_PKT_END_MASK0
+#define MT_DFS_CH_EN   0xf
+
+/* sw detector params */
+#define MT_DFS_EVENT_LOOP  64
+#define MT_DFS_SW_TIMEOUT  (HZ / 20)
+#define MT_DFS_EVENT_WINDOW(HZ / 5)
+#define MT_DFS_SEQUENCE_WINDOW (200 * (1 << 20))
+#define MT_DFS_EVENT_TIME_MARGIN   2000
+#define MT_DFS_PRI_MARGIN  4
+#define MT_DFS_SEQUENCE_TH 6
+
+#define MT_DFS_FCC_MAX_PRI ((28570 << 1) + 1000)
+#define MT_DFS_FCC_MIN_PRI (3000 - 2)
+#define MT_DFS_JP_MAX_PRI  ((8 << 1) + 1000)
+#define MT_DFS_JP_MIN_PRI  (28500 - 2)
+#define MT_DFS_ETSI_MAX_PRI(13 + 125000 + 117647 + 1000)
+#define MT_DFS_ETSI_MIN_PRI(4500 - 20)
+
+struct mt76x02_radar_specs {
+   u8 mode;
+   u16 avg_len;
+   u16 e_low;
+   u16 e_high;
+   u16 w_low;
+   u16 w_high;
+   u16 w_margin;
+   u32 t_low;
+   u32 t_high;
+   u16 t_margin;
+   u32 b_low;
+   u32 b_high;
+   u32 event_expiration;
+   u16 pwr_jmp;
+};
+
+#define MT_DFS_CHECK_EVENT(x)  ((x) != GENMASK(31, 0))
+#define MT_DFS_EVENT_ENGINE(x) (((x) & BIT(31)) ? 2 : 0)

[PATCH 04/10] mt76x0: remove unused variable in mt76x0_dev

2018-10-01 Thread Lorenzo Bianconi
Remove no longer used mac_lock spinlock and data array
in mt76x0_dev data structure

Signed-off-by: Lorenzo Bianconi 
---
 drivers/net/wireless/mediatek/mt76/mt76x0/init.c   | 1 -
 drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h | 5 -
 2 files changed, 6 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/init.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/init.c
index a2c38aea486e..c4ea89e61c40 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/init.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/init.c
@@ -347,7 +347,6 @@ mt76x0_alloc_device(struct device *pdev,
dev = container_of(mdev, struct mt76x0_dev, mt76);
mutex_init(>reg_atomic_mutex);
mutex_init(>hw_atomic_mutex);
-   spin_lock_init(>mac_lock);
atomic_set(>avg_ampdu_len, 1);
 
return dev;
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h 
b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h
index 9060be6b071e..178fb4f085c5 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h
@@ -69,7 +69,6 @@ enum mt_bw {
 /**
  * struct mt76x0_dev - adapter structure
  * @lock:  protects @wcid->tx_rate.
- * @mac_lock:  locks out mac80211's tx status and rx paths.
  * @mutex: ensures exclusive access from mac80211 callbacks.
  * @reg_atomic_mutex:  ensures atomicity of indirect register accesses
  * (accesses to RF and BBP).
@@ -79,13 +78,9 @@ enum mt_bw {
 struct mt76x0_dev {
struct mt76_dev mt76; /* must be first */
 
-   u8 data[32];
-
struct delayed_work cal_work;
struct delayed_work mac_work;
 
-   spinlock_t mac_lock;
-
struct mt76x0_caldata caldata;
 
struct mutex reg_atomic_mutex;
-- 
2.19.0



[PATCH 09/10] mt76: unify rxwi parsing between mt76x2 and mt76x0 drivers

2018-10-01 Thread Lorenzo Bianconi
Unify rxwi parsing between mt76x2 and mt76x0. Remove the following
routines:
- mt76x0_phy_get_rssi
- mt76x0_queue_rx_skb
- mt76x0_mac_process_rx
Moreover remove mt76x2/common.c and mt76x0/mac.h since are empty files
Enable CCMP PN sw validation

Signed-off-by: Lorenzo Bianconi 
---
 .../wireless/mediatek/mt76/mt76x0/initvals.h  |  3 +-
 .../net/wireless/mediatek/mt76/mt76x0/mac.c   | 43 ---
 .../net/wireless/mediatek/mt76/mt76x0/mac.h   | 20 -
 .../net/wireless/mediatek/mt76/mt76x0/main.c  |  1 -
 .../wireless/mediatek/mt76/mt76x0/mt76x0.h|  3 --
 .../net/wireless/mediatek/mt76/mt76x0/phy.c   |  7 ---
 .../net/wireless/mediatek/mt76/mt76x0/trace.h |  1 -
 .../net/wireless/mediatek/mt76/mt76x0/tx.c| 16 ---
 .../net/wireless/mediatek/mt76/mt76x0/usb.c   |  2 +-
 .../net/wireless/mediatek/mt76/mt76x02_mac.c  |  1 -
 .../net/wireless/mediatek/mt76/mt76x02_util.c | 26 ++-
 .../net/wireless/mediatek/mt76/mt76x02_util.h |  2 +
 .../wireless/mediatek/mt76/mt76x2/Makefile|  3 +-
 .../wireless/mediatek/mt76/mt76x2/common.c| 42 --
 .../wireless/mediatek/mt76/mt76x2/mt76x2.h|  2 -
 .../wireless/mediatek/mt76/mt76x2/pci_init.c  |  2 +-
 .../wireless/mediatek/mt76/mt76x2/usb_init.c  |  2 +-
 17 files changed, 32 insertions(+), 144 deletions(-)
 delete mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/mac.h
 delete mode 100644 drivers/net/wireless/mediatek/mt76/mt76x2/common.c

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/initvals.h 
b/drivers/net/wireless/mediatek/mt76/mt76x0/initvals.h
index 6f26dc6dabde..236dce6860b4 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/initvals.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/initvals.h
@@ -83,7 +83,8 @@ static const struct mt76_reg_pair mt76x0_mac_reg_table[] = {
{ MT_LDO_CTRL_1,0x6B006464 },
{ MT_HT_BASIC_RATE, 0x4003 },
{ MT_HT_CTRL_CFG,   0x01FF },
-   { MT_TXOP_HLDR_ET,  0x }
+   { MT_TXOP_HLDR_ET,  0x },
+   { MT_PN_PAD_MODE,   0x0003 },
 };
 
 static const struct mt76_reg_pair mt76x0_bbp_init_tab[] = {
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/mac.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/mac.c
index 5fe035323762..793297cd6bf1 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/mac.c
@@ -195,46 +195,3 @@ void mt76x0_mac_set_ampdu_factor(struct mt76x02_dev *dev)
mt76_wr(dev, MT_MAX_LEN_CFG, 0xa0fff |
   FIELD_PREP(MT_MAX_LEN_CFG_AMPDU, min_factor));
 }
-
-u32 mt76x0_mac_process_rx(struct mt76x02_dev *dev, struct sk_buff *skb,
- void *rxi)
-{
-   struct mt76_rx_status *status = (struct mt76_rx_status *) skb->cb;
-   struct mt76x02_rxwi *rxwi = rxi;
-   u32 len, ctl = le32_to_cpu(rxwi->ctl);
-   u16 rate = le16_to_cpu(rxwi->rate);
-   struct mt76x02_sta *sta;
-   int rssi, pad_len = 0;
-   u8 wcid;
-
-   len = FIELD_GET(MT_RXWI_CTL_MPDU_LEN, ctl);
-   if (WARN_ON(len < 10))
-   return 0;
-
-   if (rxwi->rxinfo & cpu_to_le32(MT_RXINFO_DECRYPT)) {
-   status->flag |= RX_FLAG_DECRYPTED;
-   status->flag |= RX_FLAG_IV_STRIPPED | RX_FLAG_MMIC_STRIPPED;
-   }
-
-   if (rxwi->rxinfo & MT_RXINFO_L2PAD)
-   pad_len += 2;
-
-   wcid = FIELD_GET(MT_RXWI_CTL_WCID, ctl);
-   sta = mt76x02_rx_get_sta(>mt76, wcid);
-
-   mt76x02_remove_hdr_pad(skb, pad_len);
-
-   pskb_trim(skb, len);
-   status->chains = BIT(0);
-   rssi = mt76x0_phy_get_rssi(dev, rxwi);
-   status->chain_signal[0] = status->signal = rssi;
-   status->freq = dev->mt76.chandef.chan->center_freq;
-   status->band = dev->mt76.chandef.chan->band;
-
-   if (sta) {
-   ewma_signal_add(>rssi, status->signal);
-   sta->inactive_count = 0;
-   }
-
-   return mt76x02_mac_process_rate(status, rate);
-}
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/mac.h 
b/drivers/net/wireless/mediatek/mt76/mt76x0/mac.h
deleted file mode 100644
index c02228413e13..
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/mac.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright (C) 2014 Felix Fietkau 
- * Copyright (C) 2015 Jakub Kicinski 
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2
- * as published by the Free Software Foundation
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- */
-
-#ifndef __MT76_MAC_H
-#define __MT76_MAC_H
-
-u32 mt76x0_mac_process_rx(struct mt76x02_dev *dev, struct sk_buff *skb,
- 

[PATCH 08/10] mt76: move mt76x02_mac_process_rx in mt76x02-lib module

2018-10-01 Thread Lorenzo Bianconi
Move mt76x02_mac_process_rx utility routine in mt76x02-lib
in order to by reused by mt76x0 driver for rxwi parsing.
Add stream number check in mt76x02_mac_process_rx since mt76x0
chipsets are 1x1:1

Signed-off-by: Lorenzo Bianconi 
---
 .../net/wireless/mediatek/mt76/mt76x02_mac.c  | 105 ++
 .../net/wireless/mediatek/mt76/mt76x02_mac.h  |   4 +
 .../wireless/mediatek/mt76/mt76x2/common.c|   2 +-
 .../net/wireless/mediatek/mt76/mt76x2/mac.c   |  96 
 .../net/wireless/mediatek/mt76/mt76x2/mac.h   |   3 -
 .../wireless/mediatek/mt76/mt76x2/mt76x2.h|   1 -
 6 files changed, 110 insertions(+), 101 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c 
b/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c
index a02e97665463..859b6c5c4117 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c
@@ -582,3 +582,108 @@ void mt76x02_mac_setaddr(struct mt76_dev *dev, u8 *addr)
  FIELD_PREP(MT_MAC_ADDR_DW1_U2ME_MASK, 0xff));
 }
 EXPORT_SYMBOL_GPL(mt76x02_mac_setaddr);
+
+static int
+mt76x02_mac_get_rssi(struct mt76x02_dev *dev, s8 rssi, int chain)
+{
+   struct mt76x02_rx_freq_cal *cal = >cal.rx;
+
+   rssi += cal->rssi_offset[chain];
+   rssi -= cal->lna_gain;
+
+   return rssi;
+}
+
+int mt76x02_mac_process_rx(struct mt76x02_dev *dev, struct sk_buff *skb,
+  void *rxi)
+{
+   struct mt76_rx_status *status = (struct mt76_rx_status *) skb->cb;
+   struct mt76x02_rxwi *rxwi = rxi;
+   struct mt76x02_sta *sta;
+   u32 rxinfo = le32_to_cpu(rxwi->rxinfo);
+   u32 ctl = le32_to_cpu(rxwi->ctl);
+   u16 rate = le16_to_cpu(rxwi->rate);
+   u16 tid_sn = le16_to_cpu(rxwi->tid_sn);
+   bool unicast = rxwi->rxinfo & cpu_to_le32(MT_RXINFO_UNICAST);
+   int i, pad_len = 0, nstreams = dev->mt76.chainmask & 0xf;
+   s8 signal;
+   u8 pn_len;
+   u8 wcid;
+   int len;
+
+   if (!test_bit(MT76_STATE_RUNNING, >mt76.state))
+   return -EINVAL;
+
+   if (rxinfo & MT_RXINFO_L2PAD)
+   pad_len += 2;
+
+   if (rxinfo & MT_RXINFO_DECRYPT) {
+   status->flag |= RX_FLAG_DECRYPTED;
+   status->flag |= RX_FLAG_MMIC_STRIPPED;
+   status->flag |= RX_FLAG_MIC_STRIPPED;
+   status->flag |= RX_FLAG_IV_STRIPPED;
+   }
+
+   wcid = FIELD_GET(MT_RXWI_CTL_WCID, ctl);
+   sta = mt76x02_rx_get_sta(>mt76, wcid);
+   status->wcid = mt76x02_rx_get_sta_wcid(sta, unicast);
+
+   len = FIELD_GET(MT_RXWI_CTL_MPDU_LEN, ctl);
+   pn_len = FIELD_GET(MT_RXINFO_PN_LEN, rxinfo);
+   if (pn_len) {
+   int offset = ieee80211_get_hdrlen_from_skb(skb) + pad_len;
+   u8 *data = skb->data + offset;
+
+   status->iv[0] = data[7];
+   status->iv[1] = data[6];
+   status->iv[2] = data[5];
+   status->iv[3] = data[4];
+   status->iv[4] = data[1];
+   status->iv[5] = data[0];
+
+   /*
+* Driver CCMP validation can't deal with fragments.
+* Let mac80211 take care of it.
+*/
+   if (rxinfo & MT_RXINFO_FRAG) {
+   status->flag &= ~RX_FLAG_IV_STRIPPED;
+   } else {
+   pad_len += pn_len << 2;
+   len -= pn_len << 2;
+   }
+   }
+
+   mt76x02_remove_hdr_pad(skb, pad_len);
+
+   if ((rxinfo & MT_RXINFO_BA) && !(rxinfo & MT_RXINFO_NULL))
+   status->aggr = true;
+
+   if (WARN_ON_ONCE(len > skb->len))
+   return -EINVAL;
+
+   pskb_trim(skb, len);
+
+   status->chains = BIT(0);
+   signal = mt76x02_mac_get_rssi(dev, rxwi->rssi[0], 0);
+   for (i = 1; i < nstreams; i++) {
+   status->chains |= BIT(i);
+   status->chain_signal[i] = mt76x02_mac_get_rssi(dev,
+  rxwi->rssi[i],
+  i);
+   signal = max_t(s8, signal, status->chain_signal[i]);
+   }
+   status->signal = signal;
+   status->freq = dev->mt76.chandef.chan->center_freq;
+   status->band = dev->mt76.chandef.chan->band;
+
+   status->tid = FIELD_GET(MT_RXWI_TID, tid_sn);
+   status->seqno = FIELD_GET(MT_RXWI_SN, tid_sn);
+
+   if (sta) {
+   ewma_signal_add(>rssi, status->signal);
+   sta->inactive_count = 0;
+   }
+
+   return mt76x02_mac_process_rate(status, rate);
+}
+EXPORT_SYMBOL_GPL(mt76x02_mac_process_rx);
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_mac.h 
b/drivers/net/wireless/mediatek/mt76/mt76x02_mac.h
index 8788c54c6c3d..857ab2308e8b 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02_mac.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_mac.h
@@ -20,6 +20,8 

[PATCH 03/10] mt76x0: mac: use sta ewma estimation for rssi tracking

2018-10-01 Thread Lorenzo Bianconi
Use shared mt76x02 utility routines for rssi tracking.
Moreover remove no longer used con_mon_lock spinlock
and following variable:
- ap_bssid
- bcn_freq_off
- bcn_phy_mode
- avg_rssi

Signed-off-by: Lorenzo Bianconi 
---
 .../net/wireless/mediatek/mt76/mt76x0/init.c  |  1 -
 .../net/wireless/mediatek/mt76/mt76x0/mac.c   | 41 +--
 .../net/wireless/mediatek/mt76/mt76x0/main.c  |  3 --
 .../wireless/mediatek/mt76/mt76x0/mt76x0.h| 12 --
 .../net/wireless/mediatek/mt76/mt76x0/phy.c   | 20 +++--
 .../net/wireless/mediatek/mt76/mt76x0/tx.c|  2 +-
 6 files changed, 17 insertions(+), 62 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/init.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/init.c
index d64594205491..a2c38aea486e 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/init.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/init.c
@@ -348,7 +348,6 @@ mt76x0_alloc_device(struct device *pdev,
mutex_init(>reg_atomic_mutex);
mutex_init(>hw_atomic_mutex);
spin_lock_init(>mac_lock);
-   spin_lock_init(>con_mon_lock);
atomic_set(>avg_ampdu_len, 1);
 
return dev;
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/mac.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/mac.c
index f55734a922aa..eccb9451273f 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/mac.c
@@ -196,31 +196,16 @@ void mt76x0_mac_set_ampdu_factor(struct mt76x0_dev *dev)
   FIELD_PREP(MT_MAX_LEN_CFG_AMPDU, min_factor));
 }
 
-static void
-mt76x0_rx_monitor_beacon(struct mt76x0_dev *dev, struct mt76x02_rxwi *rxwi,
- u16 rate, int rssi)
-{
-   dev->bcn_phy_mode = FIELD_GET(MT_RXWI_RATE_PHY, rate);
-   dev->avg_rssi = ((dev->avg_rssi * 15) / 16 + (rssi << 8)) / 256;
-}
-
-static int
-mt76x0_rx_is_our_beacon(struct mt76x0_dev *dev, u8 *data)
-{
-   struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)data;
-
-   return ieee80211_is_beacon(hdr->frame_control) &&
-   ether_addr_equal(hdr->addr2, dev->ap_bssid);
-}
-
 u32 mt76x0_mac_process_rx(struct mt76x0_dev *dev, struct sk_buff *skb,
-   void *rxi)
+ void *rxi)
 {
struct mt76_rx_status *status = (struct mt76_rx_status *) skb->cb;
struct mt76x02_rxwi *rxwi = rxi;
u32 len, ctl = le32_to_cpu(rxwi->ctl);
u16 rate = le16_to_cpu(rxwi->rate);
+   struct mt76x02_sta *sta;
int rssi, pad_len = 0;
+   u8 wcid;
 
len = FIELD_GET(MT_RXWI_CTL_MPDU_LEN, ctl);
if (WARN_ON(len < 10))
@@ -234,6 +219,9 @@ u32 mt76x0_mac_process_rx(struct mt76x0_dev *dev, struct 
sk_buff *skb,
if (rxwi->rxinfo & MT_RXINFO_L2PAD)
pad_len += 2;
 
+   wcid = FIELD_GET(MT_RXWI_CTL_WCID, ctl);
+   sta = mt76x02_rx_get_sta(>mt76, wcid);
+
mt76x02_remove_hdr_pad(skb, pad_len);
 
pskb_trim(skb, len);
@@ -243,19 +231,10 @@ u32 mt76x0_mac_process_rx(struct mt76x0_dev *dev, struct 
sk_buff *skb,
status->freq = dev->mt76.chandef.chan->center_freq;
status->band = dev->mt76.chandef.chan->band;
 
-   mt76x02_mac_process_rate(status, rate);
-
-   spin_lock_bh(>con_mon_lock);
-   if (mt76x0_rx_is_our_beacon(dev, skb->data)) {
-   mt76x0_rx_monitor_beacon(dev, rxwi, rate, rssi);
-   } else if (rxwi->rxinfo & cpu_to_le32(MT_RXINFO_UNICAST)) {
-   if (dev->avg_rssi == 0)
-   dev->avg_rssi = rssi;
-   else
-   dev->avg_rssi = (dev->avg_rssi * 15) / 16 + rssi / 16;
-
+   if (sta) {
+   ewma_signal_add(>rssi, status->signal);
+   sta->inactive_count = 0;
}
-   spin_unlock_bh(>con_mon_lock);
 
-   return len;
+   return mt76x02_mac_process_rate(status, rate);
 }
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/main.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/main.c
index c3cea52ec0dc..ca6cde7a2f90 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/main.c
@@ -68,9 +68,6 @@ void mt76x0_bss_info_changed(struct ieee80211_hw *hw,
 
mutex_lock(>mt76.mutex);
 
-   if (changed & BSS_CHANGED_ASSOC)
-   mt76x0_phy_con_cal_onoff(dev, info);
-
if (changed & BSS_CHANGED_BSSID) {
mt76x0_addr_wr(dev, MT_MAC_BSSID_DW0, info->bssid);
 
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h 
b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h
index e54468af6ba7..9060be6b071e 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h
@@ -70,7 +70,6 @@ enum mt_bw {
  * struct mt76x0_dev - adapter structure
  * @lock:  protects @wcid->tx_rate.
  * @mac_lock:  locks out mac80211's tx status and rx paths.
- * @con_mon_lock:  protects @ap_bssid, 

[PATCH 01/10] mt76: move mt76x02_phy_get_min_avg_rssi in mt76x02_phy.c

2018-10-01 Thread Lorenzo Bianconi
Move mt76x02_phy_get_min_avg_rssi in mt76x02-lib module since
it will be used by mt76x0 driver in order to unify rxwi parsing

Signed-off-by: Lorenzo Bianconi 
---
 .../net/wireless/mediatek/mt76/mt76x02_phy.c  | 48 +++
 .../net/wireless/mediatek/mt76/mt76x02_phy.h  |  1 +
 .../wireless/mediatek/mt76/mt76x2/mt76x2.h|  1 -
 .../wireless/mediatek/mt76/mt76x2/pci_phy.c   |  3 +-
 .../net/wireless/mediatek/mt76/mt76x2/phy.c   | 47 --
 .../wireless/mediatek/mt76/mt76x2/usb_phy.c   |  3 +-
 6 files changed, 53 insertions(+), 50 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_phy.c 
b/drivers/net/wireless/mediatek/mt76/mt76x02_phy.c
index e29914d78b72..d31ce1d7b689 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02_phy.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_phy.c
@@ -19,6 +19,7 @@
 
 #include "mt76.h"
 #include "mt76x02_phy.h"
+#include "mt76x02_mac.h"
 
 void mt76x02_phy_set_rxpath(struct mt76_dev *dev)
 {
@@ -133,3 +134,50 @@ void mt76x02_phy_set_txpower(struct mt76_dev *dev, int 
txp_0, int txp_1)
  mt76x02_tx_power_mask(t->ht[7], 0, t->stbc[8], t->stbc[9]));
 }
 EXPORT_SYMBOL_GPL(mt76x02_phy_set_txpower);
+
+int mt76x02_phy_get_min_avg_rssi(struct mt76_dev *dev)
+{
+   struct mt76x02_sta *sta;
+   struct mt76_wcid *wcid;
+   int i, j, min_rssi = 0;
+   s8 cur_rssi;
+
+   local_bh_disable();
+   rcu_read_lock();
+
+   for (i = 0; i < ARRAY_SIZE(dev->wcid_mask); i++) {
+   unsigned long mask = dev->wcid_mask[i];
+
+   if (!mask)
+   continue;
+
+   for (j = i * BITS_PER_LONG; mask; j++, mask >>= 1) {
+   if (!(mask & 1))
+   continue;
+
+   wcid = rcu_dereference(dev->wcid[j]);
+   if (!wcid)
+   continue;
+
+   sta = container_of(wcid, struct mt76x02_sta, wcid);
+   spin_lock(>rx_lock);
+   if (sta->inactive_count++ < 5)
+   cur_rssi = ewma_signal_read(>rssi);
+   else
+   cur_rssi = 0;
+   spin_unlock(>rx_lock);
+
+   if (cur_rssi < min_rssi)
+   min_rssi = cur_rssi;
+   }
+   }
+
+   rcu_read_unlock();
+   local_bh_enable();
+
+   if (!min_rssi)
+   return -75;
+
+   return min_rssi;
+}
+EXPORT_SYMBOL_GPL(mt76x02_phy_get_min_avg_rssi);
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_phy.h 
b/drivers/net/wireless/mediatek/mt76/mt76x02_phy.h
index df69f8fade75..e70ea6eeb077 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02_phy.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_phy.h
@@ -25,5 +25,6 @@ void mt76x02_limit_rate_power(struct mt76_rate_power *r, int 
limit);
 int mt76x02_get_max_rate_power(struct mt76_rate_power *r);
 void mt76x02_phy_set_rxpath(struct mt76_dev *dev);
 void mt76x02_phy_set_txdac(struct mt76_dev *dev);
+int mt76x02_phy_get_min_avg_rssi(struct mt76_dev *dev);
 
 #endif /* __MT76x02_PHY_H */
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/mt76x2.h 
b/drivers/net/wireless/mediatek/mt76/mt76x2/mt76x2.h
index 5c3425507adf..f9ca93ad91cd 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x2/mt76x2.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76x2/mt76x2.h
@@ -202,7 +202,6 @@ void mt76x2_configure_tx_delay(struct mt76x2_dev *dev,
   enum nl80211_band band, u8 bw);
 void mt76x2_phy_set_bw(struct mt76x2_dev *dev, int width, u8 ctrl);
 void mt76x2_phy_set_band(struct mt76x2_dev *dev, int band, bool primary_upper);
-int mt76x2_phy_get_min_avg_rssi(struct mt76x2_dev *dev);
 void mt76x2_apply_gain_adj(struct mt76x2_dev *dev);
 
 #endif
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/pci_phy.c 
b/drivers/net/wireless/mediatek/mt76/mt76x2/pci_phy.c
index 392601310e39..2ac0cc6c7126 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x2/pci_phy.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x2/pci_phy.c
@@ -18,6 +18,7 @@
 #include "mt76x2.h"
 #include "mcu.h"
 #include "eeprom.h"
+#include "../mt76x02_phy.h"
 
 static bool
 mt76x2_phy_tssi_init_cal(struct mt76x2_dev *dev)
@@ -209,7 +210,7 @@ mt76x2_phy_update_channel_gain(struct mt76x2_dev *dev)
int low_gain;
u32 val;
 
-   dev->cal.avg_rssi_all = mt76x2_phy_get_min_avg_rssi(dev);
+   dev->cal.avg_rssi_all = mt76x02_phy_get_min_avg_rssi(>mt76);
 
low_gain = (dev->cal.avg_rssi_all > mt76x2_get_rssi_gain_thresh(dev)) +
   (dev->cal.avg_rssi_all > 
mt76x2_get_low_rssi_gain_thresh(dev));
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/phy.c 
b/drivers/net/wireless/mediatek/mt76/mt76x2/phy.c
index b3ecb80340b5..06ef2c4a5c11 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x2/phy.c
+++ 

[PATCH 02/10] mt76: move mt76x02_rx_get_sta and mt76x02_rx_get_sta_wcid in mt76x02_util.c

2018-10-01 Thread Lorenzo Bianconi
Move mt76x02_rx_get_sta and mt76x02_rx_get_sta_wcid utility routines in
mt76x02-lib module since it will be used by mt76x0 driver in order to
unify rxwi parsing

Signed-off-by: Lorenzo Bianconi 
---
 .../net/wireless/mediatek/mt76/mt76x02_util.c | 29 +
 .../net/wireless/mediatek/mt76/mt76x02_util.h |  3 ++
 .../net/wireless/mediatek/mt76/mt76x2/mac.c   | 32 ++-
 3 files changed, 34 insertions(+), 30 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_util.c 
b/drivers/net/wireless/mediatek/mt76/mt76x02_util.c
index b12db0a108d3..496be05e59a6 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02_util.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_util.c
@@ -531,4 +531,33 @@ void mt76x02_set_beacon_offsets(struct mt76_dev *dev)
 }
 EXPORT_SYMBOL_GPL(mt76x02_set_beacon_offsets);
 
+struct mt76x02_sta *
+mt76x02_rx_get_sta(struct mt76_dev *dev, u8 idx)
+{
+   struct mt76_wcid *wcid;
+
+   if (idx >= ARRAY_SIZE(dev->wcid))
+   return NULL;
+
+   wcid = rcu_dereference(dev->wcid[idx]);
+   if (!wcid)
+   return NULL;
+
+   return container_of(wcid, struct mt76x02_sta, wcid);
+}
+EXPORT_SYMBOL_GPL(mt76x02_rx_get_sta);
+
+struct mt76_wcid *
+mt76x02_rx_get_sta_wcid(struct mt76x02_sta *sta, bool unicast)
+{
+   if (!sta)
+   return NULL;
+
+   if (unicast)
+   return >wcid;
+   else
+   return >vif->group_wcid;
+}
+EXPORT_SYMBOL_GPL(mt76x02_rx_get_sta_wcid);
+
 MODULE_LICENSE("Dual BSD/GPL");
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_util.h 
b/drivers/net/wireless/mediatek/mt76/mt76x02_util.h
index 54cec0cbf645..5ad8f5c458c4 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02_util.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_util.h
@@ -53,6 +53,9 @@ void mt76x02_tx_complete(struct mt76_dev *dev, struct sk_buff 
*skb);
 void mt76x02_tx_complete_skb(struct mt76_dev *mdev, struct mt76_queue *q,
struct mt76_queue_entry *e, bool flush);
 bool mt76x02_tx_status_data(struct mt76_dev *dev, u8 *update);
+struct mt76x02_sta *mt76x02_rx_get_sta(struct mt76_dev *dev, u8 idx);
+struct mt76_wcid *
+mt76x02_rx_get_sta_wcid(struct mt76x02_sta *sta, bool unicast);
 
 extern const u16 mt76x02_beacon_offsets[16];
 void mt76x02_set_beacon_offsets(struct mt76_dev *dev);
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/mac.c 
b/drivers/net/wireless/mediatek/mt76/mt76x2/mac.c
index c98ce1582aec..93bf8a9404b1 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x2/mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x2/mac.c
@@ -64,34 +64,6 @@ int mt76x2_mac_get_rssi(struct mt76x2_dev *dev, s8 rssi, int 
chain)
return rssi;
 }
 
-static struct mt76x02_sta *
-mt76x2_rx_get_sta(struct mt76x2_dev *dev, u8 idx)
-{
-   struct mt76_wcid *wcid;
-
-   if (idx >= ARRAY_SIZE(dev->mt76.wcid))
-   return NULL;
-
-   wcid = rcu_dereference(dev->mt76.wcid[idx]);
-   if (!wcid)
-   return NULL;
-
-   return container_of(wcid, struct mt76x02_sta, wcid);
-}
-
-static struct mt76_wcid *
-mt76x2_rx_get_sta_wcid(struct mt76x2_dev *dev, struct mt76x02_sta *sta,
-  bool unicast)
-{
-   if (!sta)
-   return NULL;
-
-   if (unicast)
-   return >wcid;
-   else
-   return >vif->group_wcid;
-}
-
 int mt76x2_mac_process_rx(struct mt76x2_dev *dev, struct sk_buff *skb,
  void *rxi)
 {
@@ -122,8 +94,8 @@ int mt76x2_mac_process_rx(struct mt76x2_dev *dev, struct 
sk_buff *skb,
}
 
wcid = FIELD_GET(MT_RXWI_CTL_WCID, ctl);
-   sta = mt76x2_rx_get_sta(dev, wcid);
-   status->wcid = mt76x2_rx_get_sta_wcid(dev, sta, unicast);
+   sta = mt76x02_rx_get_sta(>mt76, wcid);
+   status->wcid = mt76x02_rx_get_sta_wcid(sta, unicast);
 
len = FIELD_GET(MT_RXWI_CTL_MPDU_LEN, ctl);
pn_len = FIELD_GET(MT_RXINFO_PN_LEN, rxinfo);
-- 
2.19.0



[PATCH 00/10] unify rxwi parsing between mt76x0 and mt76x2 drivers

2018-10-01 Thread Lorenzo Bianconi
Merge mt76x0_dev and mt76x2_dev in mt76x02_dev and remove duplicated code.
Move mt76x02_mac_process_rx routine in mt76x02-lib module in order to
unify rxwi parsing between mt76x0 and mt76x2 drivers.
Move mt76x02_tx in mt76x02-lib module and remove duplicated code

Lorenzo Bianconi (10):
  mt76: move mt76x02_phy_get_min_avg_rssi in mt76x02_phy.c
  mt76: move mt76x02_rx_get_sta and mt76x02_rx_get_sta_wcid in
mt76x02_util.c
  mt76x0: mac: use sta ewma estimation for rssi tracking
  mt76x0: remove unused variable in mt76x0_dev
  mt76x0: remove hw_atomic_mutex mutex in mt76x0_dev
  mt76x2: move mt76x2_dev in mt76x02_util.h
  mt76x0: merge mt76x0_dev in mt76x02_dev
  mt76: move mt76x02_mac_process_rx in mt76x02-lib module
  mt76: unify rxwi parsing between mt76x2 and mt76x0 drivers
  mt76: move mt76x02_tx in mt76x02-lib module

 .../wireless/mediatek/mt76/mt76x0/Makefile|   2 +-
 .../wireless/mediatek/mt76/mt76x0/debugfs.c   |   4 +-
 .../wireless/mediatek/mt76/mt76x0/eeprom.c|  28 ++--
 .../wireless/mediatek/mt76/mt76x0/eeprom.h|  18 +--
 .../net/wireless/mediatek/mt76/mt76x0/init.c  |  41 ++---
 .../wireless/mediatek/mt76/mt76x0/initvals.h  |   3 +-
 .../net/wireless/mediatek/mt76/mt76x0/mac.c   |  78 +-
 .../net/wireless/mediatek/mt76/mt76x0/mac.h   |  20 ---
 .../net/wireless/mediatek/mt76/mt76x0/main.c  |  16 +-
 .../net/wireless/mediatek/mt76/mt76x0/mcu.h   |   8 +-
 .../wireless/mediatek/mt76/mt76x0/mt76x0.h| 127 +++
 .../net/wireless/mediatek/mt76/mt76x0/pci.c   |  18 +--
 .../wireless/mediatek/mt76/mt76x0/pci_mcu.c   |   4 +-
 .../net/wireless/mediatek/mt76/mt76x0/phy.c   | 112 +-
 .../net/wireless/mediatek/mt76/mt76x0/trace.h |   1 -
 .../net/wireless/mediatek/mt76/mt76x0/tx.c|  63 
 .../net/wireless/mediatek/mt76/mt76x0/usb.c   |  24 +--
 .../wireless/mediatek/mt76/mt76x0/usb_mcu.c   |   6 +-
 .../net/wireless/mediatek/mt76/mt76x02_dfs.h  | 140 +
 .../net/wireless/mediatek/mt76/mt76x02_mac.c  | 104 +
 .../net/wireless/mediatek/mt76/mt76x02_mac.h  |   4 +
 .../net/wireless/mediatek/mt76/mt76x02_phy.c  |  48 ++
 .../net/wireless/mediatek/mt76/mt76x02_phy.h  |   1 +
 .../net/wireless/mediatek/mt76/mt76x02_util.c |  80 ++
 .../net/wireless/mediatek/mt76/mt76x02_util.h |  95 
 .../wireless/mediatek/mt76/mt76x2/Makefile|   3 +-
 .../wireless/mediatek/mt76/mt76x2/common.c|  42 -
 .../wireless/mediatek/mt76/mt76x2/debugfs.c   |  12 +-
 .../net/wireless/mediatek/mt76/mt76x2/dfs.h   | 134 +---
 .../wireless/mediatek/mt76/mt76x2/eeprom.c|  40 ++---
 .../wireless/mediatek/mt76/mt76x2/eeprom.h|  10 +-
 .../net/wireless/mediatek/mt76/mt76x2/init.c  |  10 +-
 .../net/wireless/mediatek/mt76/mt76x2/mac.c   | 126 +--
 .../net/wireless/mediatek/mt76/mt76x2/mac.h   |  21 ++-
 .../net/wireless/mediatek/mt76/mt76x2/mcu.c   |   8 +-
 .../net/wireless/mediatek/mt76/mt76x2/mcu.h   |   4 +-
 .../wireless/mediatek/mt76/mt76x2/mt76x2.h| 145 +-
 .../wireless/mediatek/mt76/mt76x2/mt76x2u.h   |  38 ++---
 .../net/wireless/mediatek/mt76/mt76x2/pci.c   |   4 +-
 .../wireless/mediatek/mt76/mt76x2/pci_core.c  |   2 +-
 .../wireless/mediatek/mt76/mt76x2/pci_dfs.c   | 139 -
 .../wireless/mediatek/mt76/mt76x2/pci_dma.c   |   4 +-
 .../wireless/mediatek/mt76/mt76x2/pci_init.c  |  40 ++---
 .../wireless/mediatek/mt76/mt76x2/pci_mac.c   |  27 ++--
 .../wireless/mediatek/mt76/mt76x2/pci_main.c  |  28 ++--
 .../wireless/mediatek/mt76/mt76x2/pci_mcu.c   |   6 +-
 .../wireless/mediatek/mt76/mt76x2/pci_phy.c   |  31 ++--
 .../wireless/mediatek/mt76/mt76x2/pci_tx.c|  12 +-
 .../net/wireless/mediatek/mt76/mt76x2/phy.c   |  65 ++--
 .../net/wireless/mediatek/mt76/mt76x2/trace.h |  12 +-
 .../net/wireless/mediatek/mt76/mt76x2/tx.c|  33 +---
 .../net/wireless/mediatek/mt76/mt76x2/usb.c   |   8 +-
 .../wireless/mediatek/mt76/mt76x2/usb_init.c  |  28 ++--
 .../wireless/mediatek/mt76/mt76x2/usb_mac.c   |  12 +-
 .../wireless/mediatek/mt76/mt76x2/usb_main.c  |  18 +--
 .../wireless/mediatek/mt76/mt76x2/usb_mcu.c   |  16 +-
 .../wireless/mediatek/mt76/mt76x2/usb_phy.c   |  13 +-
 57 files changed, 947 insertions(+), 1189 deletions(-)
 delete mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/mac.h
 delete mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/tx.c
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x02_dfs.h
 delete mode 100644 drivers/net/wireless/mediatek/mt76/mt76x2/common.c

-- 
2.19.0



[PATCH] wlcore: Add support for optional wakeirq

2018-10-01 Thread Tony Lindgren
Now with wlcore using PM runtime, we can also add support for Linux
generic wakeirq handling for it if configured in the dts file.

The wakeirq can be configured as the second interrupt in the dts file
with interrupts-extended property where it is the padconf irq of the OOB
GPIO pin used for wlcore interrupt.

Note that eventually we should also allow configuring wlcore to use the
SDIO dat1 IRQ for wake-up, and in that case the the wakeirq should be
configured to be the padconf interrupt of the dat1 pin and not the
padconf interrupt of the OOB GPIO pin.

Cc: Eyal Reizer 
Signed-off-by: Tony Lindgren 
---
 drivers/net/wireless/ti/wlcore/main.c   | 30 +
 drivers/net/wireless/ti/wlcore/sdio.c   | 17 +-
 drivers/net/wireless/ti/wlcore/wlcore.h |  2 ++
 3 files changed, 40 insertions(+), 9 deletions(-)

diff --git a/drivers/net/wireless/ti/wlcore/main.c 
b/drivers/net/wireless/ti/wlcore/main.c
--- a/drivers/net/wireless/ti/wlcore/main.c
+++ b/drivers/net/wireless/ti/wlcore/main.c
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "wlcore.h"
 #include "debug.h"
@@ -6627,13 +6628,25 @@ static void wlcore_nvs_cb(const struct firmware *fw, 
void *context)
}
 
 #ifdef CONFIG_PM
+   device_init_wakeup(wl->dev, true);
+
ret = enable_irq_wake(wl->irq);
if (!ret) {
wl->irq_wake_enabled = true;
-   device_init_wakeup(wl->dev, 1);
if (pdev_data->pwr_in_suspend)
wl->hw->wiphy->wowlan = _wowlan_support;
}
+
+   res = platform_get_resource(pdev, IORESOURCE_IRQ, 1);
+   if (res) {
+   wl->wakeirq = res->start;
+   wl->wakeirq_flags = res->flags & IRQF_TRIGGER_MASK;
+   ret = dev_pm_set_dedicated_wake_irq(wl->dev, wl->wakeirq);
+   if (ret)
+   wl->wakeirq = -ENODEV;
+   } else {
+   wl->wakeirq = -ENODEV;
+   }
 #endif
disable_irq(wl->irq);
wl1271_power_off(wl);
@@ -6661,6 +6674,9 @@ static void wlcore_nvs_cb(const struct firmware *fw, void 
*context)
wl1271_unregister_hw(wl);
 
 out_irq:
+   if (wl->wakeirq >= 0)
+   dev_pm_clear_wake_irq(wl->dev);
+   device_init_wakeup(wl->dev, false);
free_irq(wl->irq, wl);
 
 out_free_nvs:
@@ -6825,10 +6841,16 @@ int wlcore_remove(struct platform_device *pdev)
if (!wl->initialized)
return 0;
 
-   if (wl->irq_wake_enabled) {
-   device_init_wakeup(wl->dev, 0);
-   disable_irq_wake(wl->irq);
+   if (wl->wakeirq >= 0) {
+   dev_pm_clear_wake_irq(wl->dev);
+   wl->wakeirq = -ENODEV;
}
+
+   device_init_wakeup(wl->dev, false);
+
+   if (wl->irq_wake_enabled)
+   disable_irq_wake(wl->irq);
+
wl1271_unregister_hw(wl);
 
pm_runtime_put_sync(wl->dev);
diff --git a/drivers/net/wireless/ti/wlcore/sdio.c 
b/drivers/net/wireless/ti/wlcore/sdio.c
--- a/drivers/net/wireless/ti/wlcore/sdio.c
+++ b/drivers/net/wireless/ti/wlcore/sdio.c
@@ -241,7 +241,7 @@ static const struct of_device_id 
wlcore_sdio_of_match_table[] = {
{ }
 };
 
-static int wlcore_probe_of(struct device *dev, int *irq,
+static int wlcore_probe_of(struct device *dev, int *irq, int *wakeirq,
   struct wlcore_platdev_data *pdev_data)
 {
struct device_node *np = dev->of_node;
@@ -259,6 +259,8 @@ static int wlcore_probe_of(struct device *dev, int *irq,
return -EINVAL;
}
 
+   *wakeirq = irq_of_parse_and_map(np, 1);
+
/* optional clock frequency params */
of_property_read_u32(np, "ref-clock-frequency",
 _data->ref_clock_freq);
@@ -268,7 +270,7 @@ static int wlcore_probe_of(struct device *dev, int *irq,
return 0;
 }
 #else
-static int wlcore_probe_of(struct device *dev, int *irq,
+static int wlcore_probe_of(struct device *dev, int *irq, int *wakeirq,
   struct wlcore_platdev_data *pdev_data)
 {
return -ENODATA;
@@ -280,10 +282,10 @@ static int wl1271_probe(struct sdio_func *func,
 {
struct wlcore_platdev_data *pdev_data;
struct wl12xx_sdio_glue *glue;
-   struct resource res[1];
+   struct resource res[2];
mmc_pm_flag_t mmcflags;
int ret = -ENOMEM;
-   int irq;
+   int irq, wakeirq;
const char *chip_family;
 
/* We are only able to handle the wlan function */
@@ -308,7 +310,7 @@ static int wl1271_probe(struct sdio_func *func,
/* Use block mode for transferring over one block size of data */
func->card->quirks |= MMC_QUIRK_BLKSZ_FOR_BYTE_MODE;
 
-   ret = wlcore_probe_of(>dev, , pdev_data);
+   ret = wlcore_probe_of(>dev, , , pdev_data);
if (ret)
goto out;
 
@@ -351,6 +353,11 @@ static int wl1271_probe(struct sdio_func *func,
   

[PATCH] wlcore: Fix BUG with clear completion on timeout

2018-10-01 Thread Tony Lindgren
We do not currently clear wl->elp_compl on ELP timeout and we have bogus
lingering pointer that wlcore_irq then will try to access after recovery
is done:

BUG: spinlock bad magic on CPU#1, irq/255-wl12xx/580
...
(spin_dump) from [] (do_raw_spin_lock+0xc8/0x124)
(do_raw_spin_lock) from [] (_raw_spin_lock_irqsave+0x68/0x74)
(_raw_spin_lock_irqsave) from [] (complete+0x24/0x58)
(complete) from [] (wlcore_irq+0x48/0x17c [wlcore])
(wlcore_irq [wlcore]) from [] (irq_thread_fn+0x2c/0x64)
(irq_thread_fn) from [] (irq_thread+0x148/0x290)
(irq_thread) from [] (kthread+0x160/0x17c)
(kthread) from [] (ret_from_fork+0x14/0x20)
...

After that the system will hang. Let's fix this by adding a flag for
recovery and moving the recovery work call to to the error handling
section.

And we want to set WL1271_FLAG_INTENDED_FW_RECOVERY and actually clear
it too in wl1271_recovery_work() and just downgrade the error to a
warning to prevent overly verbose output.

Cc: Eyal Reizer 
Signed-off-by: Tony Lindgren 
---
 drivers/net/wireless/ti/wlcore/main.c | 18 ++
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/net/wireless/ti/wlcore/main.c 
b/drivers/net/wireless/ti/wlcore/main.c
--- a/drivers/net/wireless/ti/wlcore/main.c
+++ b/drivers/net/wireless/ti/wlcore/main.c
@@ -957,6 +957,8 @@ static void wl1271_recovery_work(struct work_struct *work)
BUG_ON(wl->conf.recovery.bug_on_recovery &&
   !test_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, >flags));
 
+   clear_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, >flags);
+
if (wl->conf.recovery.no_recovery) {
wl1271_info("No recovery (chosen on module load). Fw will 
remain stuck.");
goto out_unlock;
@@ -6710,6 +6712,7 @@ static int __maybe_unused wlcore_runtime_resume(struct 
device *dev)
int ret;
unsigned long start_time = jiffies;
bool pending = false;
+   bool recovery = false;
 
/* Nothing to do if no ELP mode requested */
if (!test_bit(WL1271_FLAG_IN_ELP, >flags))
@@ -6726,7 +6729,7 @@ static int __maybe_unused wlcore_runtime_resume(struct 
device *dev)
 
ret = wlcore_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG, ELPCTRL_WAKE_UP);
if (ret < 0) {
-   wl12xx_queue_recovery_work(wl);
+   recovery = true;
goto err;
}
 
@@ -6734,11 +6737,12 @@ static int __maybe_unused wlcore_runtime_resume(struct 
device *dev)
ret = wait_for_completion_timeout(,
msecs_to_jiffies(WL1271_WAKEUP_TIMEOUT));
if (ret == 0) {
-   wl1271_error("ELP wakeup timeout!");
-   wl12xx_queue_recovery_work(wl);
+   wl1271_warning("ELP wakeup timeout!");
 
/* Return no error for runtime PM for recovery */
-   return 0;
+   ret = 0;
+   recovery = true;
+   goto err;
}
}
 
@@ -6753,6 +6757,12 @@ static int __maybe_unused wlcore_runtime_resume(struct 
device *dev)
spin_lock_irqsave(>wl_lock, flags);
wl->elp_compl = NULL;
spin_unlock_irqrestore(>wl_lock, flags);
+
+   if (recovery) {
+   set_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, >flags);
+   wl12xx_queue_recovery_work(wl);
+   }
+
return ret;
 }
 
-- 
2.19.0


[PATCH 1/4] mt76: move mt76x02_tx_get_max_txpwr_adj in mt76x02_util.c

2018-10-01 Thread Lorenzo Bianconi
Move mt76x02_tx_get_max_txpwr_adj routine in mt76x02-lib module
since now both mt76x0 and mt76x2 drivers read rate tx power gain from
rate_power data structure. Moreover remove get_max_txpwr_adj function
pointer from mt76_driver_ops data structure

Signed-off-by: Lorenzo Bianconi 
---
 drivers/net/wireless/mediatek/mt76/mt76.h |  2 -
 .../net/wireless/mediatek/mt76/mt76x02_util.c | 45 +--
 .../net/wireless/mediatek/mt76/mt76x02_util.h |  2 +
 .../net/wireless/mediatek/mt76/mt76x2/mac.c   |  2 +-
 .../wireless/mediatek/mt76/mt76x2/mt76x2.h|  2 -
 .../wireless/mediatek/mt76/mt76x2/pci_init.c  |  1 -
 .../net/wireless/mediatek/mt76/mt76x2/tx.c| 42 -
 7 files changed, 45 insertions(+), 51 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h 
b/drivers/net/wireless/mediatek/mt76/mt76.h
index f2dd4d87e355..c47ad67ce2ff 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76.h
@@ -262,8 +262,6 @@ struct mt76_driver_ops {
 
void (*sta_ps)(struct mt76_dev *dev, struct ieee80211_sta *sta,
   bool ps);
-   s8 (*get_max_txpwr_adj)(struct mt76_dev *dev,
-   const struct ieee80211_tx_rate *rate);
 };
 
 struct mt76_channel_state {
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_util.c 
b/drivers/net/wireless/mediatek/mt76/mt76x02_util.c
index ec422c3980e8..b12db0a108d3 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02_util.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_util.c
@@ -358,6 +358,47 @@ int mt76x02_conf_tx(struct ieee80211_hw *hw, struct 
ieee80211_vif *vif,
 }
 EXPORT_SYMBOL_GPL(mt76x02_conf_tx);
 
+s8 mt76x02_tx_get_max_txpwr_adj(struct mt76_dev *dev,
+   const struct ieee80211_tx_rate *rate)
+{
+   s8 max_txpwr;
+
+   if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
+   u8 mcs = ieee80211_rate_get_vht_mcs(rate);
+
+   if (mcs == 8 || mcs == 9) {
+   max_txpwr = dev->rate_power.vht[8];
+   } else {
+   u8 nss, idx;
+
+   nss = ieee80211_rate_get_vht_nss(rate);
+   idx = ((nss - 1) << 3) + mcs;
+   max_txpwr = dev->rate_power.ht[idx & 0xf];
+   }
+   } else if (rate->flags & IEEE80211_TX_RC_MCS) {
+   max_txpwr = dev->rate_power.ht[rate->idx & 0xf];
+   } else {
+   enum nl80211_band band = dev->chandef.chan->band;
+
+   if (band == NL80211_BAND_2GHZ) {
+   const struct ieee80211_rate *r;
+   struct wiphy *wiphy = dev->hw->wiphy;
+   struct mt76_rate_power *rp = >rate_power;
+
+   r = >bands[band]->bitrates[rate->idx];
+   if (r->flags & IEEE80211_RATE_SHORT_PREAMBLE)
+   max_txpwr = rp->cck[r->hw_value & 0x3];
+   else
+   max_txpwr = rp->ofdm[r->hw_value & 0x7];
+   } else {
+   max_txpwr = dev->rate_power.ofdm[rate->idx & 0x7];
+   }
+   }
+
+   return max_txpwr;
+}
+EXPORT_SYMBOL_GPL(mt76x02_tx_get_max_txpwr_adj);
+
 void mt76x02_sta_rate_tbl_update(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
struct ieee80211_sta *sta)
@@ -373,9 +414,7 @@ void mt76x02_sta_rate_tbl_update(struct ieee80211_hw *hw,
rate.idx = rates->rate[0].idx;
rate.flags = rates->rate[0].flags;
mt76x02_mac_wcid_set_rate(dev, >wcid, );
-
-   if (dev->drv && dev->drv->get_max_txpwr_adj)
-   msta->wcid.max_txpwr_adj = dev->drv->get_max_txpwr_adj(dev, 
);
+   msta->wcid.max_txpwr_adj = mt76x02_tx_get_max_txpwr_adj(dev, );
 }
 EXPORT_SYMBOL_GPL(mt76x02_sta_rate_tbl_update);
 
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_util.h 
b/drivers/net/wireless/mediatek/mt76/mt76x02_util.h
index ff4cab5ca038..54cec0cbf645 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02_util.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_util.h
@@ -45,6 +45,8 @@ int mt76x02_conf_tx(struct ieee80211_hw *hw, struct 
ieee80211_vif *vif,
 void mt76x02_sta_rate_tbl_update(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
struct ieee80211_sta *sta);
+s8 mt76x02_tx_get_max_txpwr_adj(struct mt76_dev *dev,
+   const struct ieee80211_tx_rate *rate);
 int mt76x02_insert_hdr_pad(struct sk_buff *skb);
 void mt76x02_remove_hdr_pad(struct sk_buff *skb, int len);
 void mt76x02_tx_complete(struct mt76_dev *dev, struct sk_buff *skb);
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/mac.c 
b/drivers/net/wireless/mediatek/mt76/mt76x2/mac.c
index 568bac76097c..a396a56dcfe0 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x2/mac.c

[PATCH 3/4] mt76: move mt76x02_mac_write_txwi in mt76x02-lib module

2018-10-01 Thread Lorenzo Bianconi
Move mt76x02_mac_write_txwi in mt76x02_mac.c since it is shared between
mt76x0 and mt76x2 drivers. This is a preliminary patch to unify txwi
configuration between mt76x0 and mt76x2 drivers

Signed-off-by: Lorenzo Bianconi 
---
 .../net/wireless/mediatek/mt76/mt76x02_mac.c  | 63 +++
 .../net/wireless/mediatek/mt76/mt76x02_mac.h  |  3 +
 .../net/wireless/mediatek/mt76/mt76x2/mac.c   | 60 --
 .../net/wireless/mediatek/mt76/mt76x2/mac.h   |  3 -
 .../wireless/mediatek/mt76/mt76x2/pci_mac.c   |  2 +-
 .../wireless/mediatek/mt76/mt76x2/pci_tx.c|  2 +-
 .../wireless/mediatek/mt76/mt76x2/usb_core.c  |  3 +-
 7 files changed, 69 insertions(+), 67 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c 
b/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c
index df4366a702c9..71d677a6b88a 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c
@@ -18,6 +18,7 @@
 #include "mt76.h"
 #include "mt76x02_regs.h"
 #include "mt76x02_mac.h"
+#include "mt76x02_util.h"
 
 enum mt76x02_cipher_type
 mt76x02_mac_get_key_info(struct ieee80211_key_conf *key, u8 *key_data)
@@ -341,6 +342,68 @@ mt76x02_mac_process_tx_rate(struct ieee80211_tx_rate 
*txrate, u16 rate,
return 0;
 }
 
+void mt76x02_mac_write_txwi(struct mt76_dev *dev, struct mt76x02_txwi *txwi,
+   struct sk_buff *skb, struct mt76_wcid *wcid,
+   struct ieee80211_sta *sta, int len)
+{
+   struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
+   struct ieee80211_tx_rate *rate = >control.rates[0];
+   struct ieee80211_key_conf *key = info->control.hw_key;
+   u16 rate_ht_mask = FIELD_PREP(MT_RXWI_RATE_PHY, BIT(1) | BIT(2));
+   u8 nss;
+   s8 txpwr_adj, max_txpwr_adj;
+   u8 ccmp_pn[8], nstreams = dev->chainmask & 0xf;
+
+   memset(txwi, 0, sizeof(*txwi));
+
+   if (wcid)
+   txwi->wcid = wcid->idx;
+   else
+   txwi->wcid = 0xff;
+
+   txwi->pktid = 1;
+
+   if (wcid && wcid->sw_iv && key) {
+   u64 pn = atomic64_inc_return(>tx_pn);
+   ccmp_pn[0] = pn;
+   ccmp_pn[1] = pn >> 8;
+   ccmp_pn[2] = 0;
+   ccmp_pn[3] = 0x20 | (key->keyidx << 6);
+   ccmp_pn[4] = pn >> 16;
+   ccmp_pn[5] = pn >> 24;
+   ccmp_pn[6] = pn >> 32;
+   ccmp_pn[7] = pn >> 40;
+   txwi->iv = *((__le32 *)_pn[0]);
+   txwi->eiv = *((__le32 *)_pn[1]);
+   }
+
+   spin_lock_bh(>lock);
+   if (wcid && (rate->idx < 0 || !rate->count)) {
+   txwi->rate = wcid->tx_rate;
+   max_txpwr_adj = wcid->max_txpwr_adj;
+   nss = wcid->tx_rate_nss;
+   } else {
+   txwi->rate = mt76x02_mac_tx_rate_val(dev, rate, );
+   max_txpwr_adj = mt76x02_tx_get_max_txpwr_adj(dev, rate);
+   }
+   spin_unlock_bh(>lock);
+
+   if (dev->drv->get_tx_txpwr_adj) {
+   txpwr_adj = dev->drv->get_tx_txpwr_adj(dev, dev->txpower_conf,
+  max_txpwr_adj);
+   txwi->ctl2 = FIELD_PREP(MT_TX_PWR_ADJ, txpwr_adj);
+   }
+
+   if (nstreams > 1 && mt76_rev(dev) >= MT76XX_REV_E4)
+   txwi->txstream = 0x13;
+   else if (nstreams > 1 && mt76_rev(dev) >= MT76XX_REV_E3 &&
+!(txwi->rate & cpu_to_le16(rate_ht_mask)))
+   txwi->txstream = 0x93;
+
+   mt76x02_mac_fill_txwi(txwi, skb, sta, len, nss);
+}
+EXPORT_SYMBOL_GPL(mt76x02_mac_write_txwi);
+
 static void
 mt76x02_mac_fill_tx_status(struct mt76_dev *dev,
  struct ieee80211_tx_info *info,
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_mac.h 
b/drivers/net/wireless/mediatek/mt76/mt76x02_mac.h
index 62072291e416..ddc8057fbbab 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02_mac.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_mac.h
@@ -203,4 +203,7 @@ void mt76x02_send_tx_status(struct mt76_dev *dev,
 int
 mt76x02_mac_process_rate(struct mt76_rx_status *status, u16 rate);
 void mt76x02_mac_setaddr(struct mt76_dev *dev, u8 *addr);
+void mt76x02_mac_write_txwi(struct mt76_dev *dev, struct mt76x02_txwi *txwi,
+   struct sk_buff *skb, struct mt76_wcid *wcid,
+   struct ieee80211_sta *sta, int len);
 #endif
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/mac.c 
b/drivers/net/wireless/mediatek/mt76/mt76x2/mac.c
index 0791fa11875c..c98ce1582aec 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x2/mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x2/mac.c
@@ -54,66 +54,6 @@ void mt76x2_mac_stop(struct mt76x2_dev *dev, bool force)
 }
 EXPORT_SYMBOL_GPL(mt76x2_mac_stop);
 
-void mt76x2_mac_write_txwi(struct mt76x2_dev *dev, struct mt76x02_txwi *txwi,
-  struct sk_buff *skb, struct mt76_wcid *wcid,
-   

[PATCH 2/4] mt76: add get_tx_txpwr_adj function pointer to mt76_driver_ops

2018-10-01 Thread Lorenzo Bianconi
Add get_tx_txpwr_adj function pointer to mt76_driver_ops data structure
as a preliminary patch to unify txwi configuration between mt76x0 and
mt76x2 drivers since tpc is currently supported just by mt76x2 driver

Signed-off-by: Lorenzo Bianconi 
---
 drivers/net/wireless/mediatek/mt76/mt76.h| 2 ++
 drivers/net/wireless/mediatek/mt76/mt76x2/mac.c  | 2 +-
 drivers/net/wireless/mediatek/mt76/mt76x2/mt76x2.h   | 2 +-
 drivers/net/wireless/mediatek/mt76/mt76x2/pci_init.c | 1 +
 drivers/net/wireless/mediatek/mt76/mt76x2/tx.c   | 6 --
 5 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h 
b/drivers/net/wireless/mediatek/mt76/mt76.h
index c47ad67ce2ff..422b09a42bf6 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76.h
@@ -262,6 +262,8 @@ struct mt76_driver_ops {
 
void (*sta_ps)(struct mt76_dev *dev, struct ieee80211_sta *sta,
   bool ps);
+   s8 (*get_tx_txpwr_adj)(struct mt76_dev *dev, s8 txpwr,
+  s8 max_txpwr_adj);
 };
 
 struct mt76_channel_state {
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/mac.c 
b/drivers/net/wireless/mediatek/mt76/mt76x2/mac.c
index a396a56dcfe0..0791fa11875c 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x2/mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x2/mac.c
@@ -100,7 +100,7 @@ void mt76x2_mac_write_txwi(struct mt76x2_dev *dev, struct 
mt76x02_txwi *txwi,
}
spin_unlock_bh(>mt76.lock);
 
-   txpwr_adj = mt76x2_tx_get_txpwr_adj(dev, dev->mt76.txpower_conf,
+   txpwr_adj = mt76x2_tx_get_txpwr_adj(>mt76, dev->mt76.txpower_conf,
max_txpwr_adj);
txwi->ctl2 = FIELD_PREP(MT_TX_PWR_ADJ, txpwr_adj);
 
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/mt76x2.h 
b/drivers/net/wireless/mediatek/mt76/mt76x2/mt76x2.h
index 50490c75a1e2..5c3425507adf 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x2/mt76x2.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76x2/mt76x2.h
@@ -176,7 +176,7 @@ void mt76x2_sta_ps(struct mt76_dev *dev, struct 
ieee80211_sta *sta, bool ps);
 
 void mt76x2_update_channel(struct mt76_dev *mdev);
 
-s8 mt76x2_tx_get_txpwr_adj(struct mt76x2_dev *dev, s8 txpwr, s8 max_txpwr_adj);
+s8 mt76x2_tx_get_txpwr_adj(struct mt76_dev *mdev, s8 txpwr, s8 max_txpwr_adj);
 void mt76x2_tx_set_txpwr_auto(struct mt76x2_dev *dev, s8 txpwr);
 
 
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/pci_init.c 
b/drivers/net/wireless/mediatek/mt76/mt76x2/pci_init.c
index d9fb06e34dbf..a6c66bf08ded 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x2/pci_init.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x2/pci_init.c
@@ -362,6 +362,7 @@ struct mt76x2_dev *mt76x2_alloc_device(struct device *pdev)
.rx_skb = mt76x2_queue_rx_skb,
.rx_poll_complete = mt76x2_rx_poll_complete,
.sta_ps = mt76x2_sta_ps,
+   .get_tx_txpwr_adj = mt76x2_tx_get_txpwr_adj,
};
struct mt76x2_dev *dev;
struct mt76_dev *mdev;
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/tx.c 
b/drivers/net/wireless/mediatek/mt76/mt76x2/tx.c
index 0c878c9eb33d..c8203e49560c 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x2/tx.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x2/tx.c
@@ -47,8 +47,10 @@ void mt76x2_tx(struct ieee80211_hw *hw, struct 
ieee80211_tx_control *control,
 }
 EXPORT_SYMBOL_GPL(mt76x2_tx);
 
-s8 mt76x2_tx_get_txpwr_adj(struct mt76x2_dev *dev, s8 txpwr, s8 max_txpwr_adj)
+s8 mt76x2_tx_get_txpwr_adj(struct mt76_dev *mdev, s8 txpwr, s8 max_txpwr_adj)
 {
+   struct mt76x2_dev  *dev = container_of(mdev, struct mt76x2_dev, mt76);
+
txpwr = min_t(s8, txpwr, dev->mt76.txpower_conf);
txpwr -= (dev->target_power + dev->target_power_delta[0]);
txpwr = min_t(s8, txpwr, max_txpwr_adj);
@@ -66,7 +68,7 @@ void mt76x2_tx_set_txpwr_auto(struct mt76x2_dev *dev, s8 
txpwr)
 {
s8 txpwr_adj;
 
-   txpwr_adj = mt76x2_tx_get_txpwr_adj(dev, txpwr,
+   txpwr_adj = mt76x2_tx_get_txpwr_adj(>mt76, txpwr,
dev->mt76.rate_power.ofdm[4]);
mt76_rmw_field(dev, MT_PROT_AUTO_TX_CFG,
   MT_PROT_AUTO_TX_CFG_PROT_PADJ, txpwr_adj);
-- 
2.17.1



[PATCH 4/4] mt76: usb: use mt76x02u_tx_prepare_skb to fill txwi

2018-10-01 Thread Lorenzo Bianconi
Use mt76x02u_tx_prepare_skb routine to fill txwi in mt76x2u and
mt76x0u driver and remove duplicated code. Moreover add static
qualifier to mt76x02_mac_tx_rate_val and mt76x02_mac_fill_txwi
routines

Signed-off-by: Lorenzo Bianconi 
---
 .../wireless/mediatek/mt76/mt76x0/mt76x0.h|  5 --
 .../net/wireless/mediatek/mt76/mt76x0/tx.c| 38 --
 .../net/wireless/mediatek/mt76/mt76x0/usb.c   | 17 +-
 .../net/wireless/mediatek/mt76/mt76x02_mac.c  |  9 ++--
 .../net/wireless/mediatek/mt76/mt76x02_mac.h  |  5 --
 .../net/wireless/mediatek/mt76/mt76x02_usb.h  |  5 +-
 .../wireless/mediatek/mt76/mt76x02_usb_core.c | 38 +-
 .../wireless/mediatek/mt76/mt76x2/Makefile|  2 +-
 .../wireless/mediatek/mt76/mt76x2/mt76x2u.h   |  4 --
 .../wireless/mediatek/mt76/mt76x2/usb_core.c  | 52 ---
 .../wireless/mediatek/mt76/mt76x2/usb_init.c  |  3 +-
 11 files changed, 48 insertions(+), 130 deletions(-)
 delete mode 100644 drivers/net/wireless/mediatek/mt76/mt76x2/usb_core.c

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h 
b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h
index a37dbf944b15..e54468af6ba7 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h
@@ -168,11 +168,6 @@ void mt76x0_mac_set_ampdu_factor(struct mt76x0_dev *dev);
 /* TX */
 void mt76x0_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control,
struct sk_buff *skb);
-struct mt76x02_txwi *
-mt76x0_push_txwi(struct mt76x0_dev *dev, struct sk_buff *skb,
-struct ieee80211_sta *sta, struct mt76_wcid *wcid,
-int pkt_len);
-
 void mt76x0_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q,
 struct sk_buff *skb);
 
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/tx.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/tx.c
index b3c5dc2ffeb1..79c0b3ba1ccb 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/tx.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/tx.c
@@ -17,44 +17,6 @@
 #include "../mt76x02_util.h"
 #include "../mt76x02_usb.h"
 
-struct mt76x02_txwi *
-mt76x0_push_txwi(struct mt76x0_dev *dev, struct sk_buff *skb,
-struct ieee80211_sta *sta, struct mt76_wcid *wcid,
-int pkt_len)
-{
-   struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
-   struct ieee80211_tx_rate *rate = >control.rates[0];
-   struct mt76x02_txwi *txwi;
-   unsigned long flags;
-   u16 rate_ctl;
-   u8 nss;
-
-   txwi = (struct mt76x02_txwi *)skb_push(skb, sizeof(struct 
mt76x02_txwi));
-   memset(txwi, 0, sizeof(*txwi));
-
-   if (!wcid->tx_rate_set)
-   ieee80211_get_tx_rates(info->control.vif, sta, skb,
-  info->control.rates, 1);
-
-   spin_lock_irqsave(>mt76.lock, flags);
-   if (rate->idx < 0 || !rate->count) {
-   rate_ctl = wcid->tx_rate;
-   nss = wcid->tx_rate_nss;
-   } else {
-   rate_ctl = mt76x02_mac_tx_rate_val(>mt76, rate, );
-   }
-   spin_unlock_irqrestore(>mt76.lock, flags);
-
-   txwi->wcid = wcid->idx;
-   txwi->rate = cpu_to_le16(rate_ctl);
-   txwi->pktid = (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) ? 1 : 0;
-
-   mt76x02_mac_fill_txwi(txwi, skb, sta, pkt_len, nss);
-
-   return txwi;
-}
-EXPORT_SYMBOL_GPL(mt76x0_push_txwi);
-
 void mt76x0_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control,
   struct sk_buff *skb)
 {
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c
index a76043213f55..42c996067d9e 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c
@@ -159,21 +159,6 @@ static const struct ieee80211_ops mt76x0u_ops = {
.wake_tx_queue = mt76_wake_tx_queue,
 };
 
-static int mt76x0u_tx_prepare_skb(struct mt76_dev *mdev, void *data,
- struct sk_buff *skb, struct mt76_queue *q,
- struct mt76_wcid *wcid, struct ieee80211_sta 
*sta,
- u32 *tx_info)
-{
-   struct mt76x0_dev *dev = container_of(mdev, struct mt76x0_dev, mt76);
-   struct mt76x02_txwi *txwi;
-   int len = skb->len;
-
-   mt76x02_insert_hdr_pad(skb);
-   txwi = mt76x0_push_txwi(dev, skb, sta, wcid, len);
-
-   return mt76x02u_set_txinfo(skb, wcid, q2ep(q->hw_idx));
-}
-
 static int mt76x0u_register_device(struct mt76x0_dev *dev)
 {
struct ieee80211_hw *hw = dev->mt76.hw;
@@ -230,7 +215,7 @@ static int mt76x0u_probe(struct usb_interface *usb_intf,
 const struct usb_device_id *id)
 {
static const struct mt76_driver_ops drv_ops = {
-   .tx_prepare_skb = mt76x0u_tx_prepare_skb,
+   .tx_prepare_skb = mt76x02u_tx_prepare_skb,
.tx_complete_skb = 

[PATCH 0/4] unify txwi parsing between mt76x0 and mt76x2 drivers

2018-10-01 Thread Lorenzo Bianconi
Move mt76x02_mac_write_txwi routine in mt76x02-lib module in order to
unify txwi parsing between mt76x0 and mt76x2 drivers.
For rxwi unification we need to merge mt76x2_dev and mt76x0_dev in
mt76x02_dev and remove duplicated code

Changes since RFC:
- drop patch 1/5 ("mt76: introduce is_mt76x2 routine")
- use chainmask in mt76x02_mac_write_txwi instead of is_mt76x2
  routine

Lorenzo Bianconi (4):
  mt76: move mt76x02_tx_get_max_txpwr_adj in mt76x02_util.c
  mt76: add get_tx_txpwr_adj function pointer to mt76_driver_ops
  mt76: move mt76x02_mac_write_txwi in mt76x02-lib module
  mt76: usb: use mt76x02u_tx_prepare_skb to fill txwi

 drivers/net/wireless/mediatek/mt76/mt76.h |  4 +-
 .../wireless/mediatek/mt76/mt76x0/mt76x0.h|  5 --
 .../net/wireless/mediatek/mt76/mt76x0/tx.c| 38 --
 .../net/wireless/mediatek/mt76/mt76x0/usb.c   | 17 +
 .../net/wireless/mediatek/mt76/mt76x02_mac.c  | 72 +--
 .../net/wireless/mediatek/mt76/mt76x02_mac.h  |  8 +--
 .../net/wireless/mediatek/mt76/mt76x02_usb.h  |  5 +-
 .../wireless/mediatek/mt76/mt76x02_usb_core.c | 38 +-
 .../net/wireless/mediatek/mt76/mt76x02_util.c | 45 +++-
 .../net/wireless/mediatek/mt76/mt76x02_util.h |  2 +
 .../wireless/mediatek/mt76/mt76x2/Makefile|  2 +-
 .../net/wireless/mediatek/mt76/mt76x2/mac.c   | 60 
 .../net/wireless/mediatek/mt76/mt76x2/mac.h   |  3 -
 .../wireless/mediatek/mt76/mt76x2/mt76x2.h|  4 +-
 .../wireless/mediatek/mt76/mt76x2/mt76x2u.h   |  4 --
 .../wireless/mediatek/mt76/mt76x2/pci_init.c  |  2 +-
 .../wireless/mediatek/mt76/mt76x2/pci_mac.c   |  2 +-
 .../wireless/mediatek/mt76/mt76x2/pci_tx.c|  2 +-
 .../net/wireless/mediatek/mt76/mt76x2/tx.c| 46 +---
 .../wireless/mediatek/mt76/mt76x2/usb_core.c  | 53 --
 .../wireless/mediatek/mt76/mt76x2/usb_init.c  |  3 +-
 21 files changed, 167 insertions(+), 248 deletions(-)
 delete mode 100644 drivers/net/wireless/mediatek/mt76/mt76x2/usb_core.c

-- 
2.17.1



Re: [RFC 4/5] mt76: move mt76x02_mac_write_txwi in mt76x02-lib module

2018-10-01 Thread Stanislaw Gruszka
On Mon, Oct 01, 2018 at 12:06:56PM +0200, Lorenzo Bianconi wrote:
> > All above looks mt76x2 specific, maybe would be beter to place this in 
> > in setup_txwi() calback i.e:
> > 
> > if (dev->drv->setup_txwi)
> > drv->drv->setup_txwi(...)
> > 
> > or maybe you plan to implement get_tx_txpwr_adj() for mt76x0 as well,
> > is this feature supported by the MT76x0 chips ?
> 
> For the moment tpc is supported just for mt76x2 chipsets but tx power subfield
> is present in mt76x0_txwi as well. Moreover merging mt76x2_dev and mt76x0_dev
> in mt76x02_dev allows us to move mt76x2_get_tx_txpwr_adj() in mt76x02-lib
> module, remove get_tx_txpwr_adj callback and just make tpc disabled for mt76x0
> for the moment.
> As suggested by Felix, we can take into account chainmask for txstream
> configuration and remove is_mt76x2() check.
> Agree?

Yes, sounds reasonable.

Regards
Stanislaw


Re: pull-request: iwlwifi-next 2018-09-28

2018-10-01 Thread Kalle Valo
Luca Coelho  writes:

> This is the second batch of patches intended for v4.20.  This includes
> the last 2 patchsets I sent.  Usual development work, with some
> improvements on HE, HW support, bugfixes, and some other small
> improvements.  More details about the contents in the tag description.
>
> I have sent this out before and kbuildbot reported success.
>
> Please let me know if there are any issues.
>
> Cheers,
> Luca.
>
>
> The following changes since commit 93ed990e3a6e722b7b1e1d59b3ceb8d91e36e682:
>
>   qtnfmac: remove set but not used variable 'vif' (2018-09-20 15:12:13 +0300)
>
> are available in the Git repository at:
>
>   git://git.kernel.org/pub/scm/linux/kernel/git/iwlwifi/iwlwifi-next.git 
> tags/iwlwifi-next-for-kalle-2018-09-28
>
> for you to fetch changes up to 6f3df8c1192c873a6ad9a76328920f6f85af90a8:
>
>   iwlwifi: mvm: Allow TKIP for AP mode (2018-09-28 08:57:30 +0300)
>
> 
> Second set of iwlwifi patches for 4.20
>
> * TKIP implementation in new devices;
> * Fix for the shared antenna setting in 22000 series;
> * Report that we set the RU offset in HE code;
> * Fix some register addresses in 22000 series;
> * Fix one FW feature TLV that had a conflict with another value;
> * A couple of fixes for SoftAP mode;
> * Work continues for new 22560 hardware;
> * Some fixes in the datapath;
> * Some debugging and other general fixes;
> * Some cleanups, small improvements and other general fixes;
>
> 

Pulled, thanks.

-- 
Kalle Valo


Re: [PATCH V2 01/11] qtnfmac_pcie: do not store FW name in driver state structure

2018-10-01 Thread Kalle Valo
Igor Mitsyanko  wrote:

> Firmware name is only needed at probe stage, no point in keeping it in
> driver state structure.
> 
> Signed-off-by: Igor Mitsyanko 

11 patches applied to wireless-drivers-next.git, thanks.

4059afc6bd17 qtnfmac_pcie: do not store FW name in driver state structure
2ef0ecd71700 qtnfmac_pcie: move Pearl pcie sources to pcie-specific directory
91dcecece019 qtnfmac_pcie: rename private Pearl PCIe state structure
d0b95bfa1178 qtnfmac_pcie: indicate pearl-specific structures by their names
21077d09b4a6 qtnfmac_pcie: pearl: rename spinlock tx0_lock to tx_lock
c9ff6c9157c2 qtnfmac_pcie: separate platform-independent PCIe structure
789763b683eb qtnfmac_pcie: rename platform-specific functions
5163309e9a4d qtnfmac: add missing header includes to bus.h
addc7540708f qtnfmac_pcie: extract platform-independent PCIe code
86ca238cf1e9 qtnfmac: wait for FW load work to finish at PCIe remove
033a759921d1 qtnfmac_pcie: check for correct CHIP ID at pcie probe

-- 
https://patchwork.kernel.org/patch/10612935/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches



Re: [PATCH 1/5] rt2800: move usb specific txdone/txstatus routines to rt2800lib

2018-10-01 Thread Kalle Valo
Stanislaw Gruszka  wrote:

> In order to reuse usb txdone/txstatus routines for mmio, move them
> to common rt2800lib.c file.
> 
> Signed-off-by: Stanislaw Gruszka 

5 patches applied to wireless-drivers-next.git, thanks.

5c656c71b1bf rt2800: move usb specific txdone/txstatus routines to rt2800lib
0b0d556e0ebb rt2800mmio: use txdone/txstatus routines from lib
5022efb50f62 rt2x00: do not check for txstatus timeout every time on tasklet
adf26a356f13 rt2x00: use different txstatus timeouts when flushing
0240564430c0 rt2800: flush and txstatus rework for rt2800mmio

-- 
https://patchwork.kernel.org/patch/10615575/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches



Re: [PATCH 5/5] ath9k: fix reporting calculated new FFT upper max

2018-10-01 Thread Simon Wunderlich
On Monday, October 1, 2018 5:31:42 PM CEST Kalle Valo wrote:
> Simon Wunderlich  writes:
> > On Monday, October 1, 2018 2:07:55 PM CEST Kalle Valo wrote:
> >> Simon Wunderlich  wrote:
> >> > Cc: Nick Kossifidis 
> >> > Signed-off-by: Simon Wunderlich 
> >> > Signed-off-by: Kalle Valo 
> >> 
> >> No empty commit logs, please. But I can add that, just tell me what to
> >> add.
> > 
> > How about:
> > 
> > Since the debug print code is outside of the loop, it shouldn't use the
> > loop iterator anymore but instead print the found maximum index.
> 
> Perfect, thanks.
> 
> > Let me know if you need me to resend or anything else.
> 
> No need, I added this to the patch in the (not yet pushed) pending
> branch.

Awesome, thank you!

Cheers,
 Simon

signature.asc
Description: This is a digitally signed message part.


Re: [PATCH 5/5] ath9k: fix reporting calculated new FFT upper max

2018-10-01 Thread Kalle Valo
Simon Wunderlich  writes:

> On Monday, October 1, 2018 2:07:55 PM CEST Kalle Valo wrote:
>> Simon Wunderlich  wrote:
>> > Cc: Nick Kossifidis 
>> > Signed-off-by: Simon Wunderlich 
>> > Signed-off-by: Kalle Valo 
>> 
>> No empty commit logs, please. But I can add that, just tell me what to add.
>
> How about:
>
> Since the debug print code is outside of the loop, it shouldn't use the loop 
> iterator anymore but instead print the found maximum index.

Perfect, thanks.

> Let me know if you need me to resend or anything else.

No need, I added this to the patch in the (not yet pushed) pending
branch.

-- 
Kalle Valo


Re: [PATCH 5/5] ath9k: fix reporting calculated new FFT upper max

2018-10-01 Thread Simon Wunderlich
On Monday, October 1, 2018 2:07:55 PM CEST Kalle Valo wrote:
> Simon Wunderlich  wrote:
> > Cc: Nick Kossifidis 
> > Signed-off-by: Simon Wunderlich 
> > Signed-off-by: Kalle Valo 
> 
> No empty commit logs, please. But I can add that, just tell me what to add.

How about:

Since the debug print code is outside of the loop, it shouldn't use the loop 
iterator anymore but instead print the found maximum index.





Let me know if you need me to resend or anything else.

Thank you,
  Simon


signature.asc
Description: This is a digitally signed message part.


[PATCH v2] mt76x0: init: remove unnecessary configurations

2018-10-01 Thread Lorenzo Bianconi
Remove leftover configuration for legacy devices in
mt76x0_init_mac_registers routine. Moreover remove
unnecessary msleep delay

Signed-off-by: Lorenzo Bianconi 
---
Changes since v1
- remove msleep delay
---
 drivers/net/wireless/mediatek/mt76/mt76x0/init.c | 6 --
 1 file changed, 6 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/init.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/init.c
index edfd5d94d197..d64594205491 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/init.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/init.c
@@ -172,12 +172,6 @@ static void mt76x0_init_mac_registers(struct mt76x0_dev 
*dev)
reg &= ~0x03FF;
reg |= 0x0201;
mt76_wr(dev, MT_WMM_CTRL, reg);
-
-   /* TODO: Probably not needed */
-   mt76_wr(dev, 0x7028, 0);
-   mt76_wr(dev, 0x7010, 0);
-   mt76_wr(dev, 0x7024, 0);
-   msleep(10);
 }
 
 static int mt76x0_init_wcid_mem(struct mt76x0_dev *dev)
-- 
2.17.1



Re: [PATCH 5/5] ath9k: fix reporting calculated new FFT upper max

2018-10-01 Thread Kalle Valo
Simon Wunderlich  wrote:

> Cc: Nick Kossifidis 
> Signed-off-by: Simon Wunderlich 
> Signed-off-by: Kalle Valo 

No empty commit logs, please. But I can add that, just tell me what to add.

-- 
https://patchwork.kernel.org/patch/10605615/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches



Re: pull-request mwifiex-firmware 2018-09-26

2018-10-01 Thread Josh Boyer
On Wed, Sep 26, 2018 at 12:07 PM Ganapathi Bhat  wrote:
>
> The following changes since commit 0ced724f6ed564a5e1602808163db7cfa4697f39:
>
>   linux-firmware: update Marvell USB8801 B0 firmware image (2018-07-20 
> 11:00:29 +0530)
>
> are available in the git repository at:
>
>   git://git.marvell.com/mwifiex-firmware.git
>
> for you to fetch changes up to 52b23a9326fd8bb468b1b9e4c1816bf08bc2bc3c:
>
>   linux-firmware: add Marvell SD8997 firmware image (2018-09-26 21:25:40 
> +0530)
>
> 
> Ganapathi Bhat (1):
>   linux-firmware: add Marvell SD8997 firmware image
>
>  WHENCE |   3 +++
>  mrvl/sdsd8997_combo_v4.bin | Bin 0 -> 621896 bytes
>  2 files changed, 3 insertions(+)
>  create mode 100644 mrvl/sdsd8997_combo_v4.bin

Pulled and pushed out.  Thanks.

josh


[RFC v2] cfg80211: add peer measurement with FTM API

2018-10-01 Thread Johannes Berg
From: Johannes Berg 

Add a new "peer measurement" API, that can be used to measure
certain things related to a peer. Right now, only implement
FTM (flight time measurement) over it, but the idea is that
it'll be extensible to also support measuring the necessary
things to calculate e.g. angle-of-arrival for WiGig.

The API is structured to have a generic list of peers and
channels to measure with/on, and then for each of those a
set of measurements (again, only FTM right now) to perform.

Results availability is multicast on a new "peer-measurement"
multicast group, and results can be retrieved by dumping the
data given the measurement cookie. Note that dumping it from
the netlink socket that started the measurement will delete
data, to allow not hanging on to measurement data forever when
the measurement is long-running and only updates periodically.

Similarly, closing the controlling netlink socket will abort
a running measurement automatically.

Signed-off-by: Johannes Berg 
---
 include/net/cfg80211.h   | 243 
 include/uapi/linux/nl80211.h | 411 ++
 net/wireless/Makefile|   1 +
 net/wireless/core.c  |  33 +++
 net/wireless/core.h  |   4 +
 net/wireless/nl80211.c   | 202 ++---
 net/wireless/nl80211.h   |  42 +++
 net/wireless/pmsr.c  | 678 +++
 net/wireless/rdev-ops.h  |  25 ++
 net/wireless/trace.h |  70 +
 10 files changed, 1675 insertions(+), 34 deletions(-)
 create mode 100644 net/wireless/pmsr.c

diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index 8f5ee2c2da04..f9d4872e5123 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -2841,6 +2841,178 @@ struct cfg80211_ftm_responder_stats {
u32 out_of_window_triggers_num;
 };
 
+/**
+ * struct cfg80211_pmsr_ftm_result - FTM result
+ * @failure_reason: if this measurement failed (PMSR status is
+ * %NL80211_PMSR_STATUS_FAILURE), this gives a more precise
+ * reason than just "failure"
+ * @burst_index: if reporting partial results, this is the index
+ * in [0 .. num_bursts-1] of the burst that's being reported
+ * @num_ftmr_attempts: number of FTM request frames transmitted
+ * @num_ftmr_successes: number of FTM request frames acked
+ * @busy_retry_time: if failure_reason is %NL80211_PMSR_FTM_FAILURE_PEER_BUSY,
+ * fill this to indicate in how many seconds a retry is deemed possible
+ * by the responder
+ * @num_bursts_exp: actual number of bursts exponent negotiated
+ * @burst_duration: actual burst duration negotiated
+ * @frames_per_burst: actual frames per burst negotiated
+ * @lci_len: length of LCI information (if present)
+ * @civicloc_len: length of civic location information (if present)
+ * @lci: LCI data (may be %NULL)
+ * @civicloc: civic location data (may be %NULL)
+ * @rssi_avg: average RSSI over FTM action frames reported
+ * @rssi_spread: spread of the RSSI over FTM action frames reported
+ * @tx_rate: bitrate for transmitted FTM action frame response
+ * @rx_rate: bitrate of received FTM action frame
+ * @rtt_avg: average of RTTs measured (must have either this or @dist_avg)
+ * @rtt_variance: variance of RTTs measured (note that standard deviation is
+ * the square root of the variance)
+ * @rtt_spread: spread of the RTTs measured
+ * @dist_avg: average of distances (mm) measured
+ * (must have either this or @rtt_avg)
+ * @dist_variance: variance of distances measured (see also @rtt_variance)
+ * @dist_spread: spread of distances measured (see also @rtt_spread)
+ * @num_ftmr_attempts_valid: @num_ftmr_attempts is valid
+ * @num_ftmr_successes_valid: @num_ftmr_successes is valid
+ * @rssi_avg_valid: @rssi_avg is valid
+ * @rssi_spread_valid: @rssi_spread is valid
+ * @tx_rate_valid: @tx_rate is valid
+ * @rx_rate_valid: @rx_rate is valid
+ * @rtt_avg_valid: @rtt_avg is valid
+ * @rtt_variance_valid: @rtt_variance is valid
+ * @rtt_spread_valid: @rtt_spread is valid
+ * @dist_avg_valid: @dist_avg is valid
+ * @dist_variance_valid: @dist_variance is valid
+ * @dist_spread_valid: @dist_spread is valid
+ */
+struct cfg80211_pmsr_ftm_result {
+   const u8 *lci;
+   const u8 *civicloc;
+   unsigned int lci_len;
+   unsigned int civicloc_len;
+   enum nl80211_peer_measurement_ftm_failure_reasons failure_reason;
+   u32 num_ftmr_attempts, num_ftmr_successes;
+   s16 burst_index;
+   u8 busy_retry_time;
+   u8 num_bursts_exp;
+   u8 burst_duration;
+   u8 frames_per_burst;
+   s32 rssi_avg;
+   s32 rssi_spread;
+   struct rate_info tx_rate, rx_rate;
+   s64 rtt_avg;
+   s64 rtt_variance;
+   s64 rtt_spread;
+   s64 dist_avg;
+   s64 dist_variance;
+   s64 dist_spread;
+
+   u16 num_ftmr_attempts_valid:1,
+   num_ftmr_successes_valid:1,
+   rssi_avg_valid:1,
+   rssi_spread_valid:1,
+   tx_rate_valid:1,
+   

[PATCH] cfg80211: sort tracing properly

2018-10-01 Thread Johannes Berg
From: Johannes Berg 

There were supposed to be two blocks - one for each direction
cfg80211 <-> driver, clean up the code to restore that.

Signed-off-by: Johannes Berg 
---
 net/wireless/trace.h | 268 +--
 1 file changed, 134 insertions(+), 134 deletions(-)

diff --git a/net/wireless/trace.h b/net/wireless/trace.h
index 7e0380192445..c6a9446b4e6b 100644
--- a/net/wireless/trace.h
+++ b/net/wireless/trace.h
@@ -2368,6 +2368,140 @@ TRACE_EVENT(rdev_external_auth,
  __entry->bssid, __entry->ssid, __entry->status)
 );
 
+TRACE_EVENT(rdev_start_radar_detection,
+   TP_PROTO(struct wiphy *wiphy, struct net_device *netdev,
+struct cfg80211_chan_def *chandef,
+u32 cac_time_ms),
+   TP_ARGS(wiphy, netdev, chandef, cac_time_ms),
+   TP_STRUCT__entry(
+   WIPHY_ENTRY
+   NETDEV_ENTRY
+   CHAN_DEF_ENTRY
+   __field(u32, cac_time_ms)
+   ),
+   TP_fast_assign(
+   WIPHY_ASSIGN;
+   NETDEV_ASSIGN;
+   CHAN_DEF_ASSIGN(chandef);
+   __entry->cac_time_ms = cac_time_ms;
+   ),
+   TP_printk(WIPHY_PR_FMT ", " NETDEV_PR_FMT ", " CHAN_DEF_PR_FMT
+ ", cac_time_ms=%u",
+ WIPHY_PR_ARG, NETDEV_PR_ARG, CHAN_DEF_PR_ARG,
+ __entry->cac_time_ms)
+);
+
+TRACE_EVENT(rdev_set_mcast_rate,
+   TP_PROTO(struct wiphy *wiphy, struct net_device *netdev,
+int *mcast_rate),
+   TP_ARGS(wiphy, netdev, mcast_rate),
+   TP_STRUCT__entry(
+   WIPHY_ENTRY
+   NETDEV_ENTRY
+   __array(int, mcast_rate, NUM_NL80211_BANDS)
+   ),
+   TP_fast_assign(
+   WIPHY_ASSIGN;
+   NETDEV_ASSIGN;
+   memcpy(__entry->mcast_rate, mcast_rate,
+  sizeof(int) * NUM_NL80211_BANDS);
+   ),
+   TP_printk(WIPHY_PR_FMT ", " NETDEV_PR_FMT ", "
+ "mcast_rates [2.4GHz=0x%x, 5.2GHz=0x%x, 60GHz=0x%x]",
+ WIPHY_PR_ARG, NETDEV_PR_ARG,
+ __entry->mcast_rate[NL80211_BAND_2GHZ],
+ __entry->mcast_rate[NL80211_BAND_5GHZ],
+ __entry->mcast_rate[NL80211_BAND_60GHZ])
+);
+
+TRACE_EVENT(rdev_set_coalesce,
+   TP_PROTO(struct wiphy *wiphy, struct cfg80211_coalesce *coalesce),
+   TP_ARGS(wiphy, coalesce),
+   TP_STRUCT__entry(
+   WIPHY_ENTRY
+   __field(int, n_rules)
+   ),
+   TP_fast_assign(
+   WIPHY_ASSIGN;
+   __entry->n_rules = coalesce ? coalesce->n_rules : 0;
+   ),
+   TP_printk(WIPHY_PR_FMT ", n_rules=%d",
+ WIPHY_PR_ARG, __entry->n_rules)
+);
+
+DEFINE_EVENT(wiphy_wdev_evt, rdev_abort_scan,
+   TP_PROTO(struct wiphy *wiphy, struct wireless_dev *wdev),
+   TP_ARGS(wiphy, wdev)
+);
+
+TRACE_EVENT(rdev_set_multicast_to_unicast,
+   TP_PROTO(struct wiphy *wiphy, struct net_device *netdev,
+const bool enabled),
+   TP_ARGS(wiphy, netdev, enabled),
+   TP_STRUCT__entry(
+   WIPHY_ENTRY
+   NETDEV_ENTRY
+   __field(bool, enabled)
+   ),
+   TP_fast_assign(
+   WIPHY_ASSIGN;
+   NETDEV_ASSIGN;
+   __entry->enabled = enabled;
+   ),
+   TP_printk(WIPHY_PR_FMT ", " NETDEV_PR_FMT ", unicast: %s",
+ WIPHY_PR_ARG, NETDEV_PR_ARG,
+ BOOL_TO_STR(__entry->enabled))
+);
+
+DEFINE_EVENT(wiphy_wdev_evt, rdev_get_txq_stats,
+   TP_PROTO(struct wiphy *wiphy, struct wireless_dev *wdev),
+   TP_ARGS(wiphy, wdev)
+);
+
+TRACE_EVENT(rdev_get_ftm_responder_stats,
+   TP_PROTO(struct wiphy *wiphy, struct net_device *netdev,
+struct cfg80211_ftm_responder_stats *ftm_stats),
+
+   TP_ARGS(wiphy, netdev, ftm_stats),
+
+   TP_STRUCT__entry(
+   WIPHY_ENTRY
+   NETDEV_ENTRY
+   __field(u64, timestamp)
+   __field(u32, success_num)
+   __field(u32, partial_num)
+   __field(u32, failed_num)
+   __field(u32, asap_num)
+   __field(u32, non_asap_num)
+   __field(u64, duration)
+   __field(u32, unknown_triggers)
+   __field(u32, reschedule)
+   __field(u32, out_of_window)
+   ),
+
+   TP_fast_assign(
+   WIPHY_ASSIGN;
+   NETDEV_ASSIGN;
+   __entry->success_num = ftm_stats->success_num;
+   __entry->partial_num = ftm_stats->partial_num;
+   __entry->failed_num = ftm_stats->failed_num;
+   __entry->asap_num = ftm_stats->asap_num;
+   __entry->non_asap_num = ftm_stats->non_asap_num;
+   __entry->duration = ftm_stats->total_duration_ms;
+   __entry->unknown_triggers = ftm_stats->unknown_triggers_num;
+ 

[PATCH] cfg80211: unify sending NL80211_CMD_NEW_INTERFACE

2018-10-01 Thread Johannes Berg
From: Johannes Berg 

There isn't really any need for us to be sending this from
two different places - move cfg80211_init_wdev() later and
send the notification from there, removing it from the non-
netdev case.

Signed-off-by: Johannes Berg 
---
 net/wireless/core.c| 5 +++--
 net/wireless/nl80211.c | 9 -
 2 files changed, 3 insertions(+), 11 deletions(-)

diff --git a/net/wireless/core.c b/net/wireless/core.c
index ba6363db1f31..5bd01058b9e6 100644
--- a/net/wireless/core.c
+++ b/net/wireless/core.c
@@ -1186,6 +1186,8 @@ void cfg80211_init_wdev(struct cfg80211_registered_device 
*rdev,
wdev->identifier = ++rdev->wdev_id;
list_add_rcu(>list, >wiphy.wdev_list);
rdev->devlist_generation++;
+
+   nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE);
 }
 
 static int cfg80211_netdev_notifier_call(struct notifier_block *nb,
@@ -1213,7 +1215,6 @@ static int cfg80211_netdev_notifier_call(struct 
notifier_block *nb,
 * called within code protected by it when interfaces
 * are added with nl80211.
 */
-   cfg80211_init_wdev(rdev, wdev);
/* can only change netns with wiphy */
dev->features |= NETIF_F_NETNS_LOCAL;
 
@@ -1242,7 +1243,7 @@ static int cfg80211_netdev_notifier_call(struct 
notifier_block *nb,
 
INIT_WORK(>disconnect_wk, cfg80211_autodisconnect_wk);
 
-   nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE);
+   cfg80211_init_wdev(rdev, wdev);
break;
case NETDEV_GOING_DOWN:
cfg80211_leave(rdev, wdev);
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 616927f70cc3..36e26ac20638 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -3303,15 +3303,6 @@ static int nl80211_new_interface(struct sk_buff *skb, 
struct genl_info *info)
return -ENOBUFS;
}
 
-   /*
-* For wdevs which have no associated netdev object (e.g. of type
-* NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here.
-* For all other types, the event will be generated from the
-* netdev notifier
-*/
-   if (!wdev->netdev)
-   nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE);
-
return genlmsg_reply(msg, info);
 }
 
-- 
2.14.4



[PATCH 15/16] iwlwifi: dbg: decrement occurrences for all triggers

2018-10-01 Thread Luca Coelho
From: Sara Sharon 

iwl_fw_dbg_collect can be called by any function that already
has the error string ready. iwl_fw_dbg_collect_trig, on the
other hand, does string formatting. The occurrences decrement
is at iwl_fw_dbg_collect_trig, instead of iwl_fw_dbg_collect,
which causes it to sometimes be skipped. Move it to the right
location.

Signed-off-by: Sara Sharon 
Signed-off-by: Luca Coelho 
---
 drivers/net/wireless/intel/iwlwifi/fw/dbg.c | 16 ++--
 drivers/net/wireless/intel/iwlwifi/fw/dbg.h |  2 +-
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/drivers/net/wireless/intel/iwlwifi/fw/dbg.c 
b/drivers/net/wireless/intel/iwlwifi/fw/dbg.c
index a049367ac08a..1ae04577aed3 100644
--- a/drivers/net/wireless/intel/iwlwifi/fw/dbg.c
+++ b/drivers/net/wireless/intel/iwlwifi/fw/dbg.c
@@ -1044,10 +1044,13 @@ IWL_EXPORT_SYMBOL(iwl_fw_dbg_collect_desc);
 int iwl_fw_dbg_collect(struct iwl_fw_runtime *fwrt,
   enum iwl_fw_dbg_trigger trig,
   const char *str, size_t len,
-  const struct iwl_fw_dbg_trigger_tlv *trigger)
+  struct iwl_fw_dbg_trigger_tlv *trigger)
 {
struct iwl_fw_dump_desc *desc;
 
+   if (trigger && !le16_to_cpu(trigger->occurrences))
+   return 0;
+
if (trigger && trigger->flags & IWL_FW_DBG_FORCE_RESTART) {
IWL_WARN(fwrt, "Force restart: trigger %d fired.\n", trig);
iwl_force_nmi(fwrt->trans);
@@ -1058,6 +1061,12 @@ int iwl_fw_dbg_collect(struct iwl_fw_runtime *fwrt,
if (!desc)
return -ENOMEM;
 
+   if (trigger) {
+   u16 occurrences = le16_to_cpu(trigger->occurrences) - 1;
+
+   trigger->occurrences = cpu_to_le16(occurrences);
+   }
+
desc->len = len;
desc->trig_desc.type = cpu_to_le32(trig);
memcpy(desc->trig_desc.data, str, len);
@@ -1070,13 +1079,9 @@ int iwl_fw_dbg_collect_trig(struct iwl_fw_runtime *fwrt,
struct iwl_fw_dbg_trigger_tlv *trigger,
const char *fmt, ...)
 {
-   u16 occurrences = le16_to_cpu(trigger->occurrences);
int ret, len = 0;
char buf[64];
 
-   if (!occurrences)
-   return 0;
-
if (fmt) {
va_list ap;
 
@@ -1099,7 +1104,6 @@ int iwl_fw_dbg_collect_trig(struct iwl_fw_runtime *fwrt,
if (ret)
return ret;
 
-   trigger->occurrences = cpu_to_le16(occurrences - 1);
return 0;
 }
 IWL_EXPORT_SYMBOL(iwl_fw_dbg_collect_trig);
diff --git a/drivers/net/wireless/intel/iwlwifi/fw/dbg.h 
b/drivers/net/wireless/intel/iwlwifi/fw/dbg.h
index bee7a938a721..701bac1aba4d 100644
--- a/drivers/net/wireless/intel/iwlwifi/fw/dbg.h
+++ b/drivers/net/wireless/intel/iwlwifi/fw/dbg.h
@@ -111,7 +111,7 @@ int iwl_fw_dbg_collect_desc(struct iwl_fw_runtime *fwrt,
 int iwl_fw_dbg_collect(struct iwl_fw_runtime *fwrt,
   enum iwl_fw_dbg_trigger trig,
   const char *str, size_t len,
-  const struct iwl_fw_dbg_trigger_tlv *trigger);
+  struct iwl_fw_dbg_trigger_tlv *trigger);
 int iwl_fw_dbg_collect_trig(struct iwl_fw_runtime *fwrt,
struct iwl_fw_dbg_trigger_tlv *trigger,
const char *fmt, ...) __printf(3, 4);
-- 
2.19.0



[PATCH 12/16] iwlwifi: mvm: show more HE radiotap data for TB PPDUs

2018-10-01 Thread Luca Coelho
From: Johannes Berg 

For trigger-based PPDUs, most values aren't part of the HE-SIG-A
because they're preconfigured by the trigger frame. However, we
still have this information since we used the trigger frame to
configure the hardware, so we can (and do) read it back out and
can thus show it in radiotap.

Signed-off-by: Johannes Berg 
Signed-off-by: Luca Coelho 
---
 drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c | 67 +--
 1 file changed, 31 insertions(+), 36 deletions(-)

diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c 
b/drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c
index a63a073e8562..26ac9402568d 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c
@@ -1005,16 +1005,41 @@ static void iwl_mvm_decode_he_phy_data(struct iwl_mvm 
*mvm,
 {
u32 he_type = rate_n_flags & RATE_MCS_HE_TYPE_MSK;
bool sigb_data;
-
-   he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_BSS_COLOR_KNOWN);
+   u16 d1known = IEEE80211_RADIOTAP_HE_DATA1_LDPC_XSYMSEG_KNOWN |
+ IEEE80211_RADIOTAP_HE_DATA1_UL_DL_KNOWN |
+ IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE_KNOWN |
+ IEEE80211_RADIOTAP_HE_DATA1_DOPPLER_KNOWN |
+ IEEE80211_RADIOTAP_HE_DATA1_BSS_COLOR_KNOWN;
+   u16 d2known = IEEE80211_RADIOTAP_HE_DATA2_PRE_FEC_PAD_KNOWN |
+ IEEE80211_RADIOTAP_HE_DATA2_PE_DISAMBIG_KNOWN |
+ IEEE80211_RADIOTAP_HE_DATA2_TXOP_KNOWN;
+
+   he->data1 |= cpu_to_le16(d1known);
+   he->data2 |= cpu_to_le16(d2known);
he->data3 |= le16_encode_bits(FIELD_GET(IWL_RX_HE_PHY_BSS_COLOR_MASK,
he_phy_data),
  IEEE80211_RADIOTAP_HE_DATA3_BSS_COLOR);
-
-   he->data2 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_TXOP_KNOWN);
+   he->data3 |= le16_encode_bits(FIELD_GET(IWL_RX_HE_PHY_UPLINK,
+   he_phy_data),
+ IEEE80211_RADIOTAP_HE_DATA3_UL_DL);
+   he->data3 |= le16_encode_bits(FIELD_GET(IWL_RX_HE_PHY_LDPC_EXT_SYM,
+   he_phy_data),
+ IEEE80211_RADIOTAP_HE_DATA3_LDPC_XSYMSEG);
+   he->data4 |= 
le16_encode_bits(FIELD_GET(IWL_RX_HE_PHY_SPATIAL_REUSE_MASK,
+   he_phy_data),
+ 
IEEE80211_RADIOTAP_HE_DATA4_SU_MU_SPTL_REUSE);
+   he->data5 |= le16_encode_bits(FIELD_GET(IWL_RX_HE_PHY_PRE_FEC_PAD_MASK,
+   he_phy_data),
+ IEEE80211_RADIOTAP_HE_DATA5_PRE_FEC_PAD);
+   he->data5 |= le16_encode_bits(FIELD_GET(IWL_RX_HE_PHY_PE_DISAMBIG,
+   he_phy_data),
+ IEEE80211_RADIOTAP_HE_DATA5_PE_DISAMBIG);
he->data6 |= le16_encode_bits(FIELD_GET(IWL_RX_HE_PHY_TXOP_DUR_MASK,
he_phy_data),
  IEEE80211_RADIOTAP_HE_DATA6_TXOP);
+   he->data6 |= le16_encode_bits(FIELD_GET(IWL_RX_HE_PHY_DOPPLER,
+   he_phy_data),
+ IEEE80211_RADIOTAP_HE_DATA6_DOPPLER);
 
switch (he_type) {
case RATE_MCS_HE_TYPE_MU:
@@ -1044,7 +1069,8 @@ static void iwl_mvm_decode_he_phy_data(struct iwl_mvm 
*mvm,
IWL_RX_HE_PHY_INFO_TYPE_MU_EXT_INFO;
if (sigb_data)
iwl_mvm_decode_he_sigb(mvm, desc, rate_n_flags, he_mu);
-
+   /* fall through */
+   case RATE_MCS_HE_TYPE_TRIG:
he->data2 |=

cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_NUM_LTF_SYMS_KNOWN);
he->data5 |=
@@ -1063,37 +1089,6 @@ static void iwl_mvm_decode_he_phy_data(struct iwl_mvm 
*mvm,
break;
}
 
-   if (he_type != RATE_MCS_HE_TYPE_TRIG) {
-   u16 d1known = IEEE80211_RADIOTAP_HE_DATA1_LDPC_XSYMSEG_KNOWN |
- IEEE80211_RADIOTAP_HE_DATA1_UL_DL_KNOWN |
- IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE_KNOWN |
- IEEE80211_RADIOTAP_HE_DATA1_DOPPLER_KNOWN;
-   u16 d2known = IEEE80211_RADIOTAP_HE_DATA2_PRE_FEC_PAD_KNOWN |
- IEEE80211_RADIOTAP_HE_DATA2_PE_DISAMBIG_KNOWN;
-
-   he->data1 |= cpu_to_le16(d1known);
-   he->data2 |= cpu_to_le16(d2known);
-
-   he->data3 |= le16_encode_bits(FIELD_GET(IWL_RX_HE_PHY_UPLINK,
-   he_phy_data),
- 
IEEE80211_RADIOTAP_HE_DATA3_UL_DL);
-   he->data3 |= 

[PATCH 07/16] iwlwifi: mvm Support new MCC update response

2018-10-01 Thread Luca Coelho
From: Haim Dreyfuss 

Change MCC update response API to be compatible with new FW API.
While at it change v2 which is not in use anymore to v3 and cleanup
mcc_update v1 command and response which is obsolete.

Signed-off-by: Haim Dreyfuss 
Signed-off-by: Luca Coelho 
---
 .../wireless/intel/iwlwifi/fw/api/nvm-reg.h   | 67 ---
 drivers/net/wireless/intel/iwlwifi/fw/file.h  |  7 +-
 drivers/net/wireless/intel/iwlwifi/mvm/nvm.c  | 25 ---
 3 files changed, 45 insertions(+), 54 deletions(-)

diff --git a/drivers/net/wireless/intel/iwlwifi/fw/api/nvm-reg.h 
b/drivers/net/wireless/intel/iwlwifi/fw/api/nvm-reg.h
index d22c1eefba6a..93b392f0c6a4 100644
--- a/drivers/net/wireless/intel/iwlwifi/fw/api/nvm-reg.h
+++ b/drivers/net/wireless/intel/iwlwifi/fw/api/nvm-reg.h
@@ -269,22 +269,6 @@ struct iwl_nvm_access_complete_cmd {
__le32 reserved;
 } __packed; /* NVM_ACCESS_COMPLETE_CMD_API_S_VER_1 */
 
-/**
- * struct iwl_mcc_update_cmd_v1 - Request the device to update geographic
- * regulatory profile according to the given MCC (Mobile Country Code).
- * The MCC is two letter-code, ascii upper case[A-Z] or '00' for world domain.
- * 'ZZ' MCC will be used to switch to NVM default profile; in this case, the
- * MCC in the cmd response will be the relevant MCC in the NVM.
- * @mcc: given mobile country code
- * @source_id: the source from where we got the MCC, see iwl_mcc_source
- * @reserved: reserved for alignment
- */
-struct iwl_mcc_update_cmd_v1 {
-   __le16 mcc;
-   u8 source_id;
-   u8 reserved;
-} __packed; /* LAR_UPDATE_MCC_CMD_API_S_VER_1 */
-
 /**
  * struct iwl_mcc_update_cmd - Request the device to update geographic
  * regulatory profile according to the given MCC (Mobile Country Code).
@@ -306,7 +290,18 @@ struct iwl_mcc_update_cmd {
 } __packed; /* LAR_UPDATE_MCC_CMD_API_S_VER_2 */
 
 /**
- * struct iwl_mcc_update_resp_v1  - response to MCC_UPDATE_CMD.
+ * enum iwl_geo_information - geographic information.
+ * @GEO_NO_INFO: no special info for this geo profile.
+ * @GEO_WMM_ETSI_5GHZ_INFO: this geo profile limits the WMM params
+ * for the 5 GHz band.
+ */
+enum iwl_geo_information {
+   GEO_NO_INFO =   0,
+   GEO_WMM_ETSI_5GHZ_INFO =BIT(0),
+};
+
+/**
+ * struct iwl_mcc_update_resp_v3 - response to MCC_UPDATE_CMD.
  * Contains the new channel control profile map, if changed, and the new MCC
  * (mobile country code).
  * The new MCC may be different than what was requested in MCC_UPDATE_CMD.
@@ -314,30 +309,23 @@ struct iwl_mcc_update_cmd {
  * @mcc: the new applied MCC
  * @cap: capabilities for all channels which matches the MCC
  * @source_id: the MCC source, see iwl_mcc_source
- * @n_channels: number of channels in @channels_data (may be 14, 39, 50 or 51
- * channels, depending on platform)
+ * @time: time elapsed from the MCC test start (in units of 30 seconds)
+ * @geo_info: geographic specific profile information
+ * see  iwl_geo_information.
+ * @n_channels: number of channels in @channels_data.
  * @channels: channel control data map, DWORD for each channel. Only the first
  * 16bits are used.
  */
-struct iwl_mcc_update_resp_v1  {
+struct iwl_mcc_update_resp_v3 {
__le32 status;
__le16 mcc;
u8 cap;
u8 source_id;
+   __le16 time;
+   __le16 geo_info;
__le32 n_channels;
__le32 channels[0];
-} __packed; /* LAR_UPDATE_MCC_CMD_RESP_S_VER_1 */
-
-/**
- * enum iwl_geo_information - geographic information.
- * @GEO_NO_INFO: no special info for this geo profile.
- * @GEO_WMM_ETSI_5GHZ_INFO: this geo profile limits the WMM params
- * for the 5 GHz band.
- */
-enum iwl_geo_information {
-   GEO_NO_INFO =   0,
-   GEO_WMM_ETSI_5GHZ_INFO =BIT(0),
-};
+} __packed; /* LAR_UPDATE_MCC_CMD_RESP_S_VER_3 */
 
 /**
  * struct iwl_mcc_update_resp - response to MCC_UPDATE_CMD.
@@ -347,25 +335,26 @@ enum iwl_geo_information {
  * @status: see  iwl_mcc_update_status
  * @mcc: the new applied MCC
  * @cap: capabilities for all channels which matches the MCC
- * @source_id: the MCC source, see iwl_mcc_source
- * @time: time elapsed from the MCC test start (in 30 seconds TU)
+ * @time: time elapsed from the MCC test start (in units of 30 seconds)
  * @geo_info: geographic specific profile information
  * see  iwl_geo_information.
- * @n_channels: number of channels in @channels_data (may be 14, 39, 50 or 51
- * channels, depending on platform)
+ * @source_id: the MCC source, see iwl_mcc_source
+ * @reserved: for four bytes alignment.
+ * @n_channels: number of channels in @channels_data.
  * @channels: channel control data map, DWORD for each channel. Only the first
  * 16bits are used.
  */
 struct iwl_mcc_update_resp {
__le32 status;
__le16 mcc;
-   u8 cap;
-   u8 source_id;
+   __le16 cap;
__le16 time;
__le16 geo_info;
+   u8 source_id;
+   u8 reserved[3];

[PATCH 14/16] iwlwifi: mvm: use match_string() helper

2018-10-01 Thread Luca Coelho
From: Yisheng Xie 

match_string() returns the index of an array for a matching string,
which can be used intead of open coded variant.

Reviewed-by: Andy Shevchenko 
Signed-off-by: Yisheng Xie 
Signed-off-by: Luca Coelho 
---
 drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c | 13 -
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c 
b/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c
index de40752aa67e..3b6b3d8fb961 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c
@@ -666,16 +666,11 @@ iwl_dbgfs_bt_force_ant_write(struct iwl_mvm *mvm, char 
*buf,
};
int ret, bt_force_ant_mode;
 
-   for (bt_force_ant_mode = 0;
-bt_force_ant_mode < ARRAY_SIZE(modes_str);
-bt_force_ant_mode++) {
-   if (!strcmp(buf, modes_str[bt_force_ant_mode]))
-   break;
-   }
-
-   if (bt_force_ant_mode >= ARRAY_SIZE(modes_str))
-   return -EINVAL;
+   ret = match_string(modes_str, ARRAY_SIZE(modes_str), buf);
+   if (ret < 0)
+   return ret;
 
+   bt_force_ant_mode = ret;
ret = 0;
mutex_lock(>mutex);
if (mvm->bt_force_ant_mode == bt_force_ant_mode)
-- 
2.19.0



[PATCH 09/16] iwlwifi: runtime: add send host command op to firmware runtime op struct

2018-10-01 Thread Luca Coelho
From: Shahar S Matityahu 

Add send host command op to firmware runtime op struct to allow sending
host commands to the op mode from the fw runtime context.

Signed-off-by: Shahar S Matityahu 
Signed-off-by: Luca Coelho 
---
 drivers/net/wireless/intel/iwlwifi/fw/runtime.h |  1 +
 drivers/net/wireless/intel/iwlwifi/mvm/ops.c| 13 +
 2 files changed, 14 insertions(+)

diff --git a/drivers/net/wireless/intel/iwlwifi/fw/runtime.h 
b/drivers/net/wireless/intel/iwlwifi/fw/runtime.h
index ac6db5e2b3d0..6b95d0e75889 100644
--- a/drivers/net/wireless/intel/iwlwifi/fw/runtime.h
+++ b/drivers/net/wireless/intel/iwlwifi/fw/runtime.h
@@ -71,6 +71,7 @@ struct iwl_fw_runtime_ops {
int (*dump_start)(void *ctx);
void (*dump_end)(void *ctx);
bool (*fw_running)(void *ctx);
+   int (*send_hcmd)(void *ctx, struct iwl_host_cmd *host_cmd);
 };
 
 #define MAX_NUM_LMAC 2
diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/ops.c 
b/drivers/net/wireless/intel/iwlwifi/mvm/ops.c
index c388e0e758e7..3acf512bad47 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/ops.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/ops.c
@@ -565,10 +565,23 @@ static bool iwl_mvm_fwrt_fw_running(void *ctx)
return iwl_mvm_firmware_running(ctx);
 }
 
+static int iwl_mvm_fwrt_send_hcmd(void *ctx, struct iwl_host_cmd *host_cmd)
+{
+   struct iwl_mvm *mvm = (struct iwl_mvm *)ctx;
+   int ret;
+
+   mutex_lock(>mutex);
+   ret = iwl_mvm_send_cmd(mvm, host_cmd);
+   mutex_unlock(>mutex);
+
+   return ret;
+}
+
 static const struct iwl_fw_runtime_ops iwl_mvm_fwrt_ops = {
.dump_start = iwl_mvm_fwrt_dump_start,
.dump_end = iwl_mvm_fwrt_dump_end,
.fw_running = iwl_mvm_fwrt_fw_running,
+   .send_hcmd = iwl_mvm_fwrt_send_hcmd,
 };
 
 static struct iwl_op_mode *
-- 
2.19.0



[PATCH 06/16] iwlwifi: pcie: check iwl_pcie_txq_build_tfd() return value

2018-10-01 Thread Luca Coelho
From: Johannes Berg 

If we use the iwl_pcie_txq_build_tfd() return value for BIT(),
we should validate that it's not going to be negative, so do
the check and bail out if we hit an error. We shouldn't, as
we check if it'll fit beforehand, but better be safe.

Signed-off-by: Johannes Berg 
Signed-off-by: Luca Coelho 
---
 drivers/net/wireless/intel/iwlwifi/pcie/tx.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/tx.c 
b/drivers/net/wireless/intel/iwlwifi/pcie/tx.c
index 67820bfaba64..f227b91098c9 100644
--- a/drivers/net/wireless/intel/iwlwifi/pcie/tx.c
+++ b/drivers/net/wireless/intel/iwlwifi/pcie/tx.c
@@ -2013,6 +2013,8 @@ static int iwl_fill_data_tbs(struct iwl_trans *trans, 
struct sk_buff *skb,
return -EINVAL;
tb_idx = iwl_pcie_txq_build_tfd(trans, txq, tb_phys,
skb_frag_size(frag), false);
+   if (tb_idx < 0)
+   return tb_idx;
 
out_meta->tbs |= BIT(tb_idx);
}
-- 
2.19.0



[PATCH 11/16] iwlwifi: mvm: decode HE information for MU (without ext info)

2018-10-01 Thread Luca Coelho
From: Johannes Berg 

When the info type is MU, we still have the data from the TSF
overload words, so should decode that. When it's MU_EXT_INFO
we additionally have the SIG-B common 0/1/2 fields.

Also document the validity depending on the info type and fix
the name of the regular TB PPDU info type accordingly.

Signed-off-by: Johannes Berg 
Signed-off-by: Luca Coelho 
---
 drivers/net/wireless/intel/iwlwifi/fw/api/rx.h | 8 
 drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c  | 3 ++-
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/net/wireless/intel/iwlwifi/fw/api/rx.h 
b/drivers/net/wireless/intel/iwlwifi/fw/api/rx.h
index 415b8842b426..0537496b6eb1 100644
--- a/drivers/net/wireless/intel/iwlwifi/fw/api/rx.h
+++ b/drivers/net/wireless/intel/iwlwifi/fw/api/rx.h
@@ -368,10 +368,10 @@ enum iwl_rx_he_phy {
/* trigger encoded */
IWL_RX_HE_PHY_RU_ALLOC_MASK = 0xfe00ULL,
IWL_RX_HE_PHY_INFO_TYPE_MASK= 0xf000ULL,
-   IWL_RX_HE_PHY_INFO_TYPE_SU  = 0x0,
-   IWL_RX_HE_PHY_INFO_TYPE_MU  = 0x1,
-   IWL_RX_HE_PHY_INFO_TYPE_MU_EXT_INFO = 0x2,
-   IWL_RX_HE_PHY_INFO_TYPE_TB_EXT_INFO = 0x3,
+   IWL_RX_HE_PHY_INFO_TYPE_SU  = 0x0, /* TSF low valid (first 
DW) */
+   IWL_RX_HE_PHY_INFO_TYPE_MU  = 0x1, /* TSF low/high valid 
(both DWs) */
+   IWL_RX_HE_PHY_INFO_TYPE_MU_EXT_INFO = 0x2, /* same + 
SIGB-common0/1/2 valid */
+   IWL_RX_HE_PHY_INFO_TYPE_TB  = 0x3, /* TSF low/high valid 
(both DWs) */
 
/* second dword - MU data */
IWL_RX_HE_PHY_MU_SIGB_COMPRESSION   = BIT_ULL(32 + 0),
diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c 
b/drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c
index 61916f39bac2..a63a073e8562 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c
@@ -1095,8 +1095,9 @@ static void iwl_mvm_decode_he_phy_data(struct iwl_mvm 
*mvm,
}
 
switch (FIELD_GET(IWL_RX_HE_PHY_INFO_TYPE_MASK, he_phy_data)) {
+   case IWL_RX_HE_PHY_INFO_TYPE_MU:
case IWL_RX_HE_PHY_INFO_TYPE_MU_EXT_INFO:
-   case IWL_RX_HE_PHY_INFO_TYPE_TB_EXT_INFO:
+   case IWL_RX_HE_PHY_INFO_TYPE_TB:
iwl_mvm_decode_he_phy_ru_alloc(he_phy_data, rate_n_flags,
   he, he_mu, rx_status);
break;
-- 
2.19.0



[PATCH 13/16] iwlwifi: dbg: make iwl_fw_dbg_no_trig_window trigger agnostic

2018-10-01 Thread Luca Coelho
From: Sara Sharon 

As preparation for new trigger format, make the function
agnostic to the trigger fomat. Instead it gets the relevant
parameters - id and delay.

Signed-off-by: Sara Sharon 
Signed-off-by: Luca Coelho 
---
 drivers/net/wireless/intel/iwlwifi/fw/dbg.h | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/net/wireless/intel/iwlwifi/fw/dbg.h 
b/drivers/net/wireless/intel/iwlwifi/fw/dbg.h
index 0f09a2128ad2..bee7a938a721 100644
--- a/drivers/net/wireless/intel/iwlwifi/fw/dbg.h
+++ b/drivers/net/wireless/intel/iwlwifi/fw/dbg.h
@@ -154,12 +154,9 @@ iwl_fw_dbg_trigger_stop_conf_match(struct iwl_fw_runtime 
*fwrt,
 }
 
 static inline bool
-iwl_fw_dbg_no_trig_window(struct iwl_fw_runtime *fwrt,
- struct iwl_fw_dbg_trigger_tlv *trig)
+iwl_fw_dbg_no_trig_window(struct iwl_fw_runtime *fwrt, u32 id, u32 dis_ms)
 {
-   unsigned long wind_jiff =
-   msecs_to_jiffies(le16_to_cpu(trig->trig_dis_ms));
-   u32 id = le32_to_cpu(trig->id);
+   unsigned long wind_jiff = msecs_to_jiffies(dis_ms);
 
/* If this is the first event checked, jump to update start ts */
if (fwrt->dump.non_collect_ts_start[id] &&
@@ -179,7 +176,8 @@ iwl_fw_dbg_trigger_check_stop(struct iwl_fw_runtime *fwrt,
if (wdev && !iwl_fw_dbg_trigger_vif_match(trig, wdev))
return false;
 
-   if (iwl_fw_dbg_no_trig_window(fwrt, trig)) {
+   if (iwl_fw_dbg_no_trig_window(fwrt, le32_to_cpu(trig->id),
+ le16_to_cpu(trig->trig_dis_ms))) {
IWL_WARN(fwrt, "Trigger %d occurred while no-collect window.\n",
 trig->id);
return false;
-- 
2.19.0



[PATCH 02/16] iwlwifi: add dump collection in case alive flow fails

2018-10-01 Thread Luca Coelho
From: Shahar S Matityahu 

Trigger dump collection if the alive flow fails, regardless of the
reason.

Signed-off-by: Shahar S Matityahu 
Signed-off-by: Luca Coelho 
---
 drivers/net/wireless/intel/iwlwifi/fw/dbg.c   | 27 ++-
 drivers/net/wireless/intel/iwlwifi/fw/dbg.h   |  1 +
 .../wireless/intel/iwlwifi/fw/error-dump.h|  2 ++
 .../net/wireless/intel/iwlwifi/fw/runtime.h   |  1 +
 drivers/net/wireless/intel/iwlwifi/mvm/fw.c   |  2 ++
 drivers/net/wireless/intel/iwlwifi/mvm/ops.c  |  2 ++
 6 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireless/intel/iwlwifi/fw/dbg.c 
b/drivers/net/wireless/intel/iwlwifi/fw/dbg.c
index 146ec5065825..a049367ac08a 100644
--- a/drivers/net/wireless/intel/iwlwifi/fw/dbg.c
+++ b/drivers/net/wireless/intel/iwlwifi/fw/dbg.c
@@ -973,6 +973,30 @@ const struct iwl_fw_dump_desc iwl_dump_desc_assert = {
 };
 IWL_EXPORT_SYMBOL(iwl_dump_desc_assert);
 
+void iwl_fw_alive_error_dump(struct iwl_fw_runtime *fwrt)
+{
+   struct iwl_fw_dump_desc *iwl_dump_desc_no_alive =
+   kmalloc(sizeof(*iwl_dump_desc_no_alive), GFP_KERNEL);
+
+   if (!iwl_dump_desc_no_alive)
+   return;
+
+   iwl_dump_desc_no_alive->trig_desc.type =
+   cpu_to_le32(FW_DBG_TRIGGER_NO_ALIVE);
+   iwl_dump_desc_no_alive->len = 0;
+
+   if (WARN_ON(fwrt->dump.desc))
+   iwl_fw_free_dump_desc(fwrt);
+
+   IWL_WARN(fwrt, "Collecting data: trigger %d fired.\n",
+FW_DBG_TRIGGER_NO_ALIVE);
+
+   fwrt->dump.desc = iwl_dump_desc_no_alive;
+   iwl_fw_error_dump(fwrt);
+   clear_bit(IWL_FWRT_STATUS_WAIT_ALIVE, >status);
+}
+IWL_EXPORT_SYMBOL(iwl_fw_alive_error_dump);
+
 int iwl_fw_dbg_collect_desc(struct iwl_fw_runtime *fwrt,
const struct iwl_fw_dump_desc *desc,
const struct iwl_fw_dbg_trigger_tlv *trigger)
@@ -998,7 +1022,8 @@ int iwl_fw_dbg_collect_desc(struct iwl_fw_runtime *fwrt,
fwrt->smem_cfg.num_lmacs)
return -EIO;
 
-   if (test_and_set_bit(IWL_FWRT_STATUS_DUMPING, >status))
+   if (test_and_set_bit(IWL_FWRT_STATUS_DUMPING, >status) ||
+   test_bit(IWL_FWRT_STATUS_WAIT_ALIVE, >status))
return -EBUSY;
 
if (WARN_ON(fwrt->dump.desc))
diff --git a/drivers/net/wireless/intel/iwlwifi/fw/dbg.h 
b/drivers/net/wireless/intel/iwlwifi/fw/dbg.h
index 5b087fc4f380..0f09a2128ad2 100644
--- a/drivers/net/wireless/intel/iwlwifi/fw/dbg.h
+++ b/drivers/net/wireless/intel/iwlwifi/fw/dbg.h
@@ -368,4 +368,5 @@ static inline void iwl_fw_resume_timestamp(struct 
iwl_fw_runtime *fwrt) {}
 
 #endif /* CONFIG_IWLWIFI_DEBUGFS */
 
+void iwl_fw_alive_error_dump(struct iwl_fw_runtime *fwrt);
 #endif  /* __iwl_fw_dbg_h__ */
diff --git a/drivers/net/wireless/intel/iwlwifi/fw/error-dump.h 
b/drivers/net/wireless/intel/iwlwifi/fw/error-dump.h
index 6d3ef331b7d5..6fede174c664 100644
--- a/drivers/net/wireless/intel/iwlwifi/fw/error-dump.h
+++ b/drivers/net/wireless/intel/iwlwifi/fw/error-dump.h
@@ -328,6 +328,7 @@ iwl_fw_error_next_data(struct iwl_fw_error_dump_data *data)
  * @FW_DBG_TDLS: trigger log collection upon TDLS related events.
  * @FW_DBG_TRIGGER_TX_STATUS: trigger log collection upon tx status when
  *  the firmware sends a tx reply.
+ * @FW_DBG_TRIGGER_NO_ALIVE: trigger log collection if alive flow fails
  */
 enum iwl_fw_dbg_trigger {
FW_DBG_TRIGGER_INVALID = 0,
@@ -345,6 +346,7 @@ enum iwl_fw_dbg_trigger {
FW_DBG_TRIGGER_TX_LATENCY,
FW_DBG_TRIGGER_TDLS,
FW_DBG_TRIGGER_TX_STATUS,
+   FW_DBG_TRIGGER_NO_ALIVE,
 
/* must be last */
FW_DBG_TRIGGER_MAX,
diff --git a/drivers/net/wireless/intel/iwlwifi/fw/runtime.h 
b/drivers/net/wireless/intel/iwlwifi/fw/runtime.h
index 9ed5819defaf..ac6db5e2b3d0 100644
--- a/drivers/net/wireless/intel/iwlwifi/fw/runtime.h
+++ b/drivers/net/wireless/intel/iwlwifi/fw/runtime.h
@@ -88,6 +88,7 @@ struct iwl_fwrt_shared_mem_cfg {
 
 enum iwl_fw_runtime_status {
IWL_FWRT_STATUS_DUMPING = 0,
+   IWL_FWRT_STATUS_WAIT_ALIVE,
 };
 
 /**
diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/fw.c 
b/drivers/net/wireless/intel/iwlwifi/mvm/fw.c
index 3fee304cddbb..c5df73231ba3 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/fw.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/fw.c
@@ -299,6 +299,7 @@ static int iwl_mvm_load_ucode_wait_alive(struct iwl_mvm 
*mvm,
enum iwl_ucode_type old_type = mvm->fwrt.cur_fw_img;
static const u16 alive_cmd[] = { MVM_ALIVE };
 
+   set_bit(IWL_FWRT_STATUS_WAIT_ALIVE, >fwrt.status);
if (ucode_type == IWL_UCODE_REGULAR &&
iwl_fw_dbg_conf_usniffer(mvm->fw, FW_DBG_START_FROM_ALIVE) &&
!(fw_has_capa(>fw->ucode_capa,
@@ -369,6 +370,7 @@ static int iwl_mvm_load_ucode_wait_alive(struct iwl_mvm 
*mvm,
atomic_set(>mac80211_queue_stop_count[i], 0);
 
set_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, >status);

[PATCH 08/16] iwlwifi: bump firmware API version for 9000 and 22000 series devices

2018-10-01 Thread Luca Coelho
From: Johannes Berg 

Bump the firmware API version to 41.

Signed-off-by: Johannes Berg 
Signed-off-by: Luca Coelho 
---
 drivers/net/wireless/intel/iwlwifi/cfg/22000.c | 2 +-
 drivers/net/wireless/intel/iwlwifi/cfg/9000.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/intel/iwlwifi/cfg/22000.c 
b/drivers/net/wireless/intel/iwlwifi/cfg/22000.c
index a8acc755a02c..da5d5f9b2573 100644
--- a/drivers/net/wireless/intel/iwlwifi/cfg/22000.c
+++ b/drivers/net/wireless/intel/iwlwifi/cfg/22000.c
@@ -56,7 +56,7 @@
 #include "iwl-config.h"
 
 /* Highest firmware API version supported */
-#define IWL_22000_UCODE_API_MAX38
+#define IWL_22000_UCODE_API_MAX41
 
 /* Lowest firmware API version supported */
 #define IWL_22000_UCODE_API_MIN39
diff --git a/drivers/net/wireless/intel/iwlwifi/cfg/9000.c 
b/drivers/net/wireless/intel/iwlwifi/cfg/9000.c
index 37deaf4fd7b3..d55fd23cafe6 100644
--- a/drivers/net/wireless/intel/iwlwifi/cfg/9000.c
+++ b/drivers/net/wireless/intel/iwlwifi/cfg/9000.c
@@ -57,7 +57,7 @@
 #include "fw/file.h"
 
 /* Highest firmware API version supported */
-#define IWL9000_UCODE_API_MAX  38
+#define IWL9000_UCODE_API_MAX  41
 
 /* Lowest firmware API version supported */
 #define IWL9000_UCODE_API_MIN  30
-- 
2.19.0



[PATCH 05/16] iwlwifi: add fall through comment

2018-10-01 Thread Luca Coelho
From: Johannes Berg 

The fall-through to the MVM case is intended as we have to do
*something* to continue, and can't easily clean up. So we'll
just fail in mvm later, if this does happen.

Signed-off-by: Johannes Berg 
Signed-off-by: Luca Coelho 
---
 drivers/net/wireless/intel/iwlwifi/iwl-drv.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-drv.c 
b/drivers/net/wireless/intel/iwlwifi/iwl-drv.c
index 809f8daa5c10..ba41d23b4211 100644
--- a/drivers/net/wireless/intel/iwlwifi/iwl-drv.c
+++ b/drivers/net/wireless/intel/iwlwifi/iwl-drv.c
@@ -1471,6 +1471,7 @@ static void iwl_req_fw_callback(const struct firmware 
*ucode_raw, void *context)
break;
default:
WARN(1, "Invalid fw type %d\n", fw->type);
+   /* fall through */
case IWL_FW_MVM:
op = _opmode_table[MVM_OP_MODE];
break;
-- 
2.19.0



[PATCH 04/16] iwlwifi: pcie gen2: check iwl_pcie_gen2_set_tb() return value

2018-10-01 Thread Luca Coelho
From: Johannes Berg 

If we use the iwl_pcie_gen2_set_tb() return value for BIT(),
we should validate that it's not going to be negative, so do
the check and bail out if we hit an error. We shouldn't, as
we check if it'll fit beforehand, but better be safe.

Fixes: ab6c644539e9 ("iwlwifi: pcie: copy TX functions to new transport")
Signed-off-by: Johannes Berg 
Signed-off-by: Luca Coelho 
---
 drivers/net/wireless/intel/iwlwifi/pcie/tx-gen2.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/tx-gen2.c 
b/drivers/net/wireless/intel/iwlwifi/pcie/tx-gen2.c
index ba9d37bed4c2..b71cf55480fc 100644
--- a/drivers/net/wireless/intel/iwlwifi/pcie/tx-gen2.c
+++ b/drivers/net/wireless/intel/iwlwifi/pcie/tx-gen2.c
@@ -438,6 +438,8 @@ static int iwl_pcie_gen2_tx_add_frags(struct iwl_trans 
*trans,
return -ENOMEM;
tb_idx = iwl_pcie_gen2_set_tb(trans, tfd, tb_phys,
  skb_frag_size(frag));
+   if (tb_idx < 0)
+   return tb_idx;
 
out_meta->tbs |= BIT(tb_idx);
}
-- 
2.19.0



[PATCH 10/16] iwlwifi: add debugfs to send host command

2018-10-01 Thread Luca Coelho
From: Shahar S Matityahu 

Add debugfs to send host command in mvm and fmac op modes.
Allows to send host command at runtime via send_hcmd debugfs file.
The command is received as a string that represents hex values.

The struct of the command is as follows:
[cmd_id][flags][length][data]
cmd_id and flags are 8 chars long each.
length is 4 chars long.
data is length * 2 chars long.

Signed-off-by: Shahar S Matityahu 
Signed-off-by: Luca Coelho 
---
 .../net/wireless/intel/iwlwifi/fw/debugfs.c   | 64 +++
 1 file changed, 64 insertions(+)

diff --git a/drivers/net/wireless/intel/iwlwifi/fw/debugfs.c 
b/drivers/net/wireless/intel/iwlwifi/fw/debugfs.c
index 1049bdfe1e69..3e120dd47305 100644
--- a/drivers/net/wireless/intel/iwlwifi/fw/debugfs.c
+++ b/drivers/net/wireless/intel/iwlwifi/fw/debugfs.c
@@ -258,11 +258,75 @@ static ssize_t iwl_dbgfs_timestamp_marker_read(struct 
iwl_fw_runtime *fwrt,
 
 FWRT_DEBUGFS_READ_WRITE_FILE_OPS(timestamp_marker, 16);
 
+struct hcmd_write_data {
+   __be32 cmd_id;
+   __be32 flags;
+   __be16 length;
+   u8 data[0];
+} __packed;
+
+static ssize_t iwl_dbgfs_send_hcmd_write(struct iwl_fw_runtime *fwrt, char 
*buf,
+size_t count)
+{
+   size_t header_size = (sizeof(u32) * 2 + sizeof(u16)) * 2;
+   size_t data_size = (count - 1) / 2;
+   int ret;
+   struct hcmd_write_data *data;
+   struct iwl_host_cmd hcmd = {
+   .len = { 0, },
+   .data = { NULL, },
+   };
+
+   if (fwrt->ops && fwrt->ops->fw_running &&
+   !fwrt->ops->fw_running(fwrt->ops_ctx))
+   return -EIO;
+
+   if (count < header_size + 1 || count > 1024 * 4)
+   return -EINVAL;
+
+   data = kmalloc(data_size, GFP_KERNEL);
+   if (!data)
+   return -ENOMEM;
+
+   ret = hex2bin((u8 *)data, buf, data_size);
+   if (ret)
+   goto out;
+
+   hcmd.id = be32_to_cpu(data->cmd_id);
+   hcmd.flags = be32_to_cpu(data->flags);
+   hcmd.len[0] = be16_to_cpu(data->length);
+   hcmd.data[0] = data->data;
+
+   if (count != header_size + hcmd.len[0] * 2 + 1) {
+   IWL_ERR(fwrt,
+   "host command data size does not match header 
length\n");
+   ret = -EINVAL;
+   goto out;
+   }
+
+   if (fwrt->ops && fwrt->ops->send_hcmd)
+   ret = fwrt->ops->send_hcmd(fwrt->ops_ctx, );
+   else
+   ret = -EPERM;
+
+   if (ret < 0)
+   goto out;
+
+   if (hcmd.flags & CMD_WANT_SKB)
+   iwl_free_resp();
+out:
+   kfree(data);
+   return ret ?: count;
+}
+
+FWRT_DEBUGFS_WRITE_FILE_OPS(send_hcmd, 512);
+
 int iwl_fwrt_dbgfs_register(struct iwl_fw_runtime *fwrt,
struct dentry *dbgfs_dir)
 {
INIT_DELAYED_WORK(>timestamp.wk, iwl_fw_timestamp_marker_wk);
FWRT_DEBUGFS_ADD_FILE(timestamp_marker, dbgfs_dir, 0200);
+   FWRT_DEBUGFS_ADD_FILE(send_hcmd, dbgfs_dir, 0200);
return 0;
 err:
IWL_ERR(fwrt, "Can't create the fwrt debugfs directory\n");
-- 
2.19.0



[PATCH 01/16] iwlwifi: pcie: avoid empty free RB queue

2018-10-01 Thread Luca Coelho
From: Shaul Triebitz 

If all free RB queues are empty, the driver will never restock the
free RB queue.  That's because the restocking happens in the Rx flow,
and if the free queue is empty there will be no Rx.

Although there's a background worker (a.k.a. allocator) allocating
memory for RBs so that the Rx handler can restock them, the worker may
run only after the free queue has become empty (and then it is too
late for restocking as explained above).

There is a solution for that called 'emergency': If the number of used
RB's reaches half the amount of all RB's, the Rx handler will not wait
for the allocator but immediately allocate memory for the used RB's
and restock the free queue.

But, since the used RB's is per queue, it may happen that the used
RB's are spread between the queues such that the emergency check will
fail for each of the queues
(and still run out of RBs, causing the above symptom).

To fix it, move to emergency mode if the sum of *all* used RBs (for
all Rx queues) reaches half the amount of all RB's

Signed-off-by: Shaul Triebitz 
Signed-off-by: Luca Coelho 
---
 drivers/net/wireless/intel/iwlwifi/pcie/rx.c | 32 +---
 1 file changed, 21 insertions(+), 11 deletions(-)

diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/rx.c 
b/drivers/net/wireless/intel/iwlwifi/pcie/rx.c
index d519e7ebdbe8..e965cc588850 100644
--- a/drivers/net/wireless/intel/iwlwifi/pcie/rx.c
+++ b/drivers/net/wireless/intel/iwlwifi/pcie/rx.c
@@ -1144,6 +1144,14 @@ void iwl_pcie_rx_free(struct iwl_trans *trans)
kfree(trans_pcie->rxq);
 }
 
+static void iwl_pcie_rx_move_to_allocator(struct iwl_rxq *rxq,
+ struct iwl_rb_allocator *rba)
+{
+   spin_lock(>lock);
+   list_splice_tail_init(>rx_used, >rbd_empty);
+   spin_unlock(>lock);
+}
+
 /*
  * iwl_pcie_rx_reuse_rbd - Recycle used RBDs
  *
@@ -1175,9 +1183,7 @@ static void iwl_pcie_rx_reuse_rbd(struct iwl_trans *trans,
if ((rxq->used_count % RX_CLAIM_REQ_ALLOC) == RX_POST_REQ_ALLOC) {
/* Move the 2 RBDs to the allocator ownership.
 Allocator has another 6 from pool for the request completion*/
-   spin_lock(>lock);
-   list_splice_tail_init(>rx_used, >rbd_empty);
-   spin_unlock(>lock);
+   iwl_pcie_rx_move_to_allocator(rxq, rba);
 
atomic_inc(>req_pending);
queue_work(rba->alloc_wq, >rx_alloc);
@@ -1400,10 +1406,18 @@ static void iwl_pcie_rx_handle(struct iwl_trans *trans, 
int queue)
IWL_DEBUG_RX(trans, "Q %d: HW = SW = %d\n", rxq->id, r);
 
while (i != r) {
+   struct iwl_rb_allocator *rba = _pcie->rba;
struct iwl_rx_mem_buffer *rxb;
-
-   if (unlikely(rxq->used_count == rxq->queue_size / 2))
+   /* number of RBDs still waiting for page allocation */
+   u32 rb_pending_alloc =
+   atomic_read(_pcie->rba.req_pending) *
+   RX_CLAIM_REQ_ALLOC;
+
+   if (unlikely(rb_pending_alloc >= rxq->queue_size / 2 &&
+!emergency)) {
+   iwl_pcie_rx_move_to_allocator(rxq, rba);
emergency = true;
+   }
 
rxb = iwl_pcie_get_rxb(trans, rxq, i);
if (!rxb)
@@ -1425,17 +1439,13 @@ static void iwl_pcie_rx_handle(struct iwl_trans *trans, 
int queue)
iwl_pcie_rx_allocator_get(trans, rxq);
 
if (rxq->used_count % RX_CLAIM_REQ_ALLOC == 0 && !emergency) {
-   struct iwl_rb_allocator *rba = _pcie->rba;
-
/* Add the remaining empty RBDs for allocator use */
-   spin_lock(>lock);
-   list_splice_tail_init(>rx_used, >rbd_empty);
-   spin_unlock(>lock);
+   iwl_pcie_rx_move_to_allocator(rxq, rba);
} else if (emergency) {
count++;
if (count == 8) {
count = 0;
-   if (rxq->used_count < rxq->queue_size / 3)
+   if (rb_pending_alloc < rxq->queue_size / 3)
emergency = false;
 
rxq->read = i;
-- 
2.19.0



[PATCH 03/16] iwlwifi: nvm: get num of hw addresses from firmware

2018-10-01 Thread Luca Coelho
From: Naftali Goldstein 

With NICs that don't read the NVM directly and instead rely on getting
the relevant data from the firmware, the number of reserved MAC
addresses was not added to the API. This caused the driver to assume
there is only one address which results in all interfaces getting the
same address. Update the API to fix this.

While at it, fix-up the comments with firmware api names to actually
match what we have in the firmware.

Fixes: e9e1ba3dbf00 ("iwlwifi: mvm: support getting nvm data from firmware")
Signed-off-by: Naftali Goldstein 
Signed-off-by: Luca Coelho 
---
 .../net/wireless/intel/iwlwifi/fw/api/nvm-reg.h| 14 +++---
 drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c | 10 +-
 2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/drivers/net/wireless/intel/iwlwifi/fw/api/nvm-reg.h 
b/drivers/net/wireless/intel/iwlwifi/fw/api/nvm-reg.h
index 6c5338364794..d22c1eefba6a 100644
--- a/drivers/net/wireless/intel/iwlwifi/fw/api/nvm-reg.h
+++ b/drivers/net/wireless/intel/iwlwifi/fw/api/nvm-reg.h
@@ -165,7 +165,7 @@ struct iwl_nvm_access_resp {
  */
 struct iwl_nvm_get_info {
__le32 reserved;
-} __packed; /* GRP_REGULATORY_NVM_GET_INFO_CMD_S_VER_1 */
+} __packed; /* REGULATORY_NVM_GET_INFO_CMD_API_S_VER_1 */
 
 /**
  * enum iwl_nvm_info_general_flags - flags in NVM_GET_INFO resp
@@ -180,14 +180,14 @@ enum iwl_nvm_info_general_flags {
  * @flags: bit 0: 1 - empty, 0 - non-empty
  * @nvm_version: nvm version
  * @board_type: board type
- * @reserved: reserved
+ * @n_hw_addrs: number of reserved MAC addresses
  */
 struct iwl_nvm_get_info_general {
__le32 flags;
__le16 nvm_version;
u8 board_type;
-   u8 reserved;
-} __packed; /* GRP_REGULATORY_NVM_GET_INFO_GENERAL_S_VER_1 */
+   u8 n_hw_addrs;
+} __packed; /* REGULATORY_NVM_GET_INFO_GENERAL_S_VER_2 */
 
 /**
  * enum iwl_nvm_mac_sku_flags - flags in _nvm_get_info_sku
@@ -231,7 +231,7 @@ struct iwl_nvm_get_info_sku {
 struct iwl_nvm_get_info_phy {
__le32 tx_chains;
__le32 rx_chains;
-} __packed; /* GRP_REGULATORY_NVM_GET_INFO_PHY_SKU_SECTION_S_VER_1 */
+} __packed; /* REGULATORY_NVM_GET_INFO_PHY_SKU_SECTION_S_VER_1 */
 
 #define IWL_NUM_CHANNELS (51)
 
@@ -245,7 +245,7 @@ struct iwl_nvm_get_info_regulatory {
__le32 lar_enabled;
__le16 channel_profile[IWL_NUM_CHANNELS];
__le16 reserved;
-} __packed; /* GRP_REGULATORY_NVM_GET_INFO_REGULATORY_S_VER_1 */
+} __packed; /* REGULATORY_NVM_GET_INFO_REGULATORY_S_VER_1 */
 
 /**
  * struct iwl_nvm_get_info_rsp - response to get NVM data
@@ -259,7 +259,7 @@ struct iwl_nvm_get_info_rsp {
struct iwl_nvm_get_info_sku mac_sku;
struct iwl_nvm_get_info_phy phy_sku;
struct iwl_nvm_get_info_regulatory regulatory;
-} __packed; /* GRP_REGULATORY_NVM_GET_INFO_CMD_RSP_S_VER_2 */
+} __packed; /* REGULATORY_NVM_GET_INFO_RSP_API_S_VER_3 */
 
 /**
  * struct iwl_nvm_access_complete_cmd - NVM_ACCESS commands are completed
diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c 
b/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c
index 137dedc844ad..4ed8fb49a091 100644
--- a/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c
+++ b/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c
@@ -1350,6 +1350,7 @@ struct iwl_nvm_data *iwl_get_nvm(struct iwl_trans *trans,
bool lar_fw_supported = !iwlwifi_mod_params.lar_disable &&
fw_has_capa(>ucode_capa,
IWL_UCODE_TLV_CAPA_LAR_SUPPORT);
+   bool empty_otp;
u32 mac_flags;
u32 sbands_flags = 0;
 
@@ -1365,7 +1366,9 @@ struct iwl_nvm_data *iwl_get_nvm(struct iwl_trans *trans,
}
 
rsp = (void *)hcmd.resp_pkt->data;
-   if (le32_to_cpu(rsp->general.flags) & NVM_GENERAL_FLAGS_EMPTY_OTP)
+   empty_otp = !!(le32_to_cpu(rsp->general.flags) &
+  NVM_GENERAL_FLAGS_EMPTY_OTP);
+   if (empty_otp)
IWL_INFO(trans, "OTP is empty\n");
 
nvm = kzalloc(sizeof(*nvm) +
@@ -1389,6 +1392,11 @@ struct iwl_nvm_data *iwl_get_nvm(struct iwl_trans *trans,
 
/* Initialize general data */
nvm->nvm_version = le16_to_cpu(rsp->general.nvm_version);
+   nvm->n_hw_addrs = rsp->general.n_hw_addrs;
+   if (nvm->n_hw_addrs == 0)
+   IWL_WARN(trans,
+"Firmware declares no reserved mac addresses. OTP is 
empty: %d\n",
+empty_otp);
 
/* Initialize MAC sku data */
mac_flags = le32_to_cpu(rsp->mac_sku.mac_sku_flags);
-- 
2.19.0



[PATCH 16/16] iwlwifi: dbg: make trigger functions type agnostic

2018-10-01 Thread Luca Coelho
From: Sara Sharon 

As preparation for new trigger type, make iwl_fw_dbg_collect_desc
agnostic to the trigger structure.

Signed-off-by: Sara Sharon 
Signed-off-by: Luca Coelho 
---
 drivers/net/wireless/intel/iwlwifi/fw/dbg.c  | 37 ++--
 drivers/net/wireless/intel/iwlwifi/fw/dbg.h  |  2 +-
 drivers/net/wireless/intel/iwlwifi/mvm/ops.c |  2 +-
 3 files changed, 20 insertions(+), 21 deletions(-)

diff --git a/drivers/net/wireless/intel/iwlwifi/fw/dbg.c 
b/drivers/net/wireless/intel/iwlwifi/fw/dbg.c
index 1ae04577aed3..f44c716b1130 100644
--- a/drivers/net/wireless/intel/iwlwifi/fw/dbg.c
+++ b/drivers/net/wireless/intel/iwlwifi/fw/dbg.c
@@ -998,14 +998,9 @@ void iwl_fw_alive_error_dump(struct iwl_fw_runtime *fwrt)
 IWL_EXPORT_SYMBOL(iwl_fw_alive_error_dump);
 
 int iwl_fw_dbg_collect_desc(struct iwl_fw_runtime *fwrt,
-   const struct iwl_fw_dump_desc *desc,
-   const struct iwl_fw_dbg_trigger_tlv *trigger)
+   const struct iwl_fw_dump_desc *desc, void *trigger,
+   unsigned int delay)
 {
-   unsigned int delay = 0;
-
-   if (trigger)
-   delay = msecs_to_jiffies(le32_to_cpu(trigger->stop_delay));
-
/*
 * If the loading of the FW completed successfully, the next step is to
 * get the SMEM config data. Thus, if fwrt->smem_cfg.num_lmacs is non
@@ -1047,31 +1042,35 @@ int iwl_fw_dbg_collect(struct iwl_fw_runtime *fwrt,
   struct iwl_fw_dbg_trigger_tlv *trigger)
 {
struct iwl_fw_dump_desc *desc;
+   unsigned int delay = 0;
 
-   if (trigger && !le16_to_cpu(trigger->occurrences))
-   return 0;
+   if (trigger) {
+   u16 occurrences = le16_to_cpu(trigger->occurrences) - 1;
 
-   if (trigger && trigger->flags & IWL_FW_DBG_FORCE_RESTART) {
-   IWL_WARN(fwrt, "Force restart: trigger %d fired.\n", trig);
-   iwl_force_nmi(fwrt->trans);
-   return 0;
+   if (!le16_to_cpu(trigger->occurrences))
+   return 0;
+
+   if (trigger->flags & IWL_FW_DBG_FORCE_RESTART) {
+   IWL_WARN(fwrt, "Force restart: trigger %d fired.\n",
+trig);
+   iwl_force_nmi(fwrt->trans);
+   return 0;
+   }
+
+   trigger->occurrences = cpu_to_le16(occurrences);
+   delay = le16_to_cpu(trigger->trig_dis_ms);
}
 
desc = kzalloc(sizeof(*desc) + len, GFP_ATOMIC);
if (!desc)
return -ENOMEM;
 
-   if (trigger) {
-   u16 occurrences = le16_to_cpu(trigger->occurrences) - 1;
-
-   trigger->occurrences = cpu_to_le16(occurrences);
-   }
 
desc->len = len;
desc->trig_desc.type = cpu_to_le32(trig);
memcpy(desc->trig_desc.data, str, len);
 
-   return iwl_fw_dbg_collect_desc(fwrt, desc, trigger);
+   return iwl_fw_dbg_collect_desc(fwrt, desc, trigger, delay);
 }
 IWL_EXPORT_SYMBOL(iwl_fw_dbg_collect);
 
diff --git a/drivers/net/wireless/intel/iwlwifi/fw/dbg.h 
b/drivers/net/wireless/intel/iwlwifi/fw/dbg.h
index 701bac1aba4d..d9578dcec24c 100644
--- a/drivers/net/wireless/intel/iwlwifi/fw/dbg.h
+++ b/drivers/net/wireless/intel/iwlwifi/fw/dbg.h
@@ -107,7 +107,7 @@ static inline void iwl_fw_free_dump_desc(struct 
iwl_fw_runtime *fwrt)
 void iwl_fw_error_dump(struct iwl_fw_runtime *fwrt);
 int iwl_fw_dbg_collect_desc(struct iwl_fw_runtime *fwrt,
const struct iwl_fw_dump_desc *desc,
-   const struct iwl_fw_dbg_trigger_tlv *trigger);
+   void *trigger, unsigned int delay);
 int iwl_fw_dbg_collect(struct iwl_fw_runtime *fwrt,
   enum iwl_fw_dbg_trigger trig,
   const char *str, size_t len,
diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/ops.c 
b/drivers/net/wireless/intel/iwlwifi/mvm/ops.c
index 3acf512bad47..0e2092526fae 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/ops.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/ops.c
@@ -1240,7 +1240,7 @@ void iwl_mvm_nic_restart(struct iwl_mvm *mvm, bool 
fw_error)
 */
if (!mvm->fw_restart && fw_error) {
iwl_fw_dbg_collect_desc(>fwrt, _dump_desc_assert,
-   NULL);
+   NULL, 0);
} else if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, >status)) {
struct iwl_mvm_reprobe *reprobe;
 
-- 
2.19.0



[PATCH 00/16] iwlwifi: updates intended for v4.20 2018-10-01

2018-10-01 Thread Luca Coelho
From: Luca Coelho 

Hi,

Here's the sixth set of patches intended for v4.20.  It's the usual
development, some improvements, debugging and bugfixes.

The changes are:

* Bumped the FW API version supported after the last API change for
  this release;
* Debugging improvements;
* A few bug fixes;
* Other small improvements, cleanups and fixes.

As usual, I'm pushing this to a pending branch, for kbuild bot, and
will send a pull-request later.

Please review.

Cheers,
Luca.



Haim Dreyfuss (1):
  iwlwifi: mvm Support new MCC update response

Johannes Berg (6):
  iwlwifi: pcie gen2: check iwl_pcie_gen2_set_tb() return value
  iwlwifi: add fall through comment
  iwlwifi: pcie: check iwl_pcie_txq_build_tfd() return value
  iwlwifi: bump firmware API version for 9000 and 22000 series devices
  iwlwifi: mvm: decode HE information for MU (without ext info)
  iwlwifi: mvm: show more HE radiotap data for TB PPDUs

Naftali Goldstein (1):
  iwlwifi: nvm: get num of hw addresses from firmware

Sara Sharon (3):
  iwlwifi: dbg: make iwl_fw_dbg_no_trig_window trigger agnostic
  iwlwifi: dbg: decrement occurrences for all triggers
  iwlwifi: dbg: make trigger functions type agnostic

Shahar S Matityahu (3):
  iwlwifi: add dump collection in case alive flow fails
  iwlwifi: runtime: add send host command op to firmware runtime op
struct
  iwlwifi: add debugfs to send host command

Shaul Triebitz (1):
  iwlwifi: pcie: avoid empty free RB queue

Yisheng Xie (1):
  iwlwifi: mvm: use match_string() helper

 .../net/wireless/intel/iwlwifi/cfg/22000.c|  2 +-
 drivers/net/wireless/intel/iwlwifi/cfg/9000.c |  2 +-
 .../wireless/intel/iwlwifi/fw/api/nvm-reg.h   | 81 ---
 .../net/wireless/intel/iwlwifi/fw/api/rx.h|  8 +-
 drivers/net/wireless/intel/iwlwifi/fw/dbg.c   | 64 ++-
 drivers/net/wireless/intel/iwlwifi/fw/dbg.h   | 15 ++--
 .../net/wireless/intel/iwlwifi/fw/debugfs.c   | 64 +++
 .../wireless/intel/iwlwifi/fw/error-dump.h|  2 +
 drivers/net/wireless/intel/iwlwifi/fw/file.h  |  7 +-
 .../net/wireless/intel/iwlwifi/fw/runtime.h   |  2 +
 drivers/net/wireless/intel/iwlwifi/iwl-drv.c  |  1 +
 .../wireless/intel/iwlwifi/iwl-nvm-parse.c| 10 ++-
 .../net/wireless/intel/iwlwifi/mvm/debugfs.c  | 13 +--
 drivers/net/wireless/intel/iwlwifi/mvm/fw.c   |  2 +
 drivers/net/wireless/intel/iwlwifi/mvm/nvm.c  | 25 +++---
 drivers/net/wireless/intel/iwlwifi/mvm/ops.c  | 17 +++-
 drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c | 70 
 drivers/net/wireless/intel/iwlwifi/pcie/rx.c  | 32 +---
 .../net/wireless/intel/iwlwifi/pcie/tx-gen2.c |  2 +
 drivers/net/wireless/intel/iwlwifi/pcie/tx.c  |  2 +
 20 files changed, 269 insertions(+), 152 deletions(-)

-- 
2.19.0



[PATCH] cfg80211: combine wdev/netdev unregister code

2018-10-01 Thread Johannes Berg
From: Johannes Berg 

We currently have two places that do similar things, depending
on whether it's a wdev with or without netdev.

Combine the code to avoid having to duplicate all new additions.

Signed-off-by: Johannes Berg 
---
 net/wireless/core.c | 38 +-
 1 file changed, 21 insertions(+), 17 deletions(-)

diff --git a/net/wireless/core.c b/net/wireless/core.c
index 52dba3976803..fffb35010c52 100644
--- a/net/wireless/core.c
+++ b/net/wireless/core.c
@@ -1047,36 +1047,49 @@ void cfg80211_cqm_config_free(struct wireless_dev *wdev)
wdev->cqm_config = NULL;
 }
 
-void cfg80211_unregister_wdev(struct wireless_dev *wdev)
+static void __cfg80211_unregister_wdev(struct wireless_dev *wdev, bool sync)
 {
struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
 
ASSERT_RTNL();
 
-   if (WARN_ON(wdev->netdev))
-   return;
-
nl80211_notify_iface(rdev, wdev, NL80211_CMD_DEL_INTERFACE);
 
list_del_rcu(>list);
-   synchronize_rcu();
+   if (sync)
+   synchronize_rcu();
rdev->devlist_generation++;
 
+   cfg80211_mlme_purge_registrations(wdev);
+
switch (wdev->iftype) {
case NL80211_IFTYPE_P2P_DEVICE:
-   cfg80211_mlme_purge_registrations(wdev);
cfg80211_stop_p2p_device(rdev, wdev);
break;
case NL80211_IFTYPE_NAN:
cfg80211_stop_nan(rdev, wdev);
break;
default:
-   WARN_ON_ONCE(1);
break;
}
 
+#ifdef CONFIG_CFG80211_WEXT
+   kzfree(wdev->wext.keys);
+#endif
+   /* only initialized if we have a netdev */
+   if (wdev->netdev)
+   flush_work(>disconnect_wk);
+
cfg80211_cqm_config_free(wdev);
 }
+
+void cfg80211_unregister_wdev(struct wireless_dev *wdev)
+{
+   if (WARN_ON(wdev->netdev))
+   return;
+
+   __cfg80211_unregister_wdev(wdev, true);
+}
 EXPORT_SYMBOL(cfg80211_unregister_wdev);
 
 static const struct device_type wiphy_type = {
@@ -1337,17 +1350,8 @@ static int cfg80211_netdev_notifier_call(struct 
notifier_block *nb,
 * remove and clean it up.
 */
if (!list_empty(>list)) {
-   nl80211_notify_iface(rdev, wdev,
-NL80211_CMD_DEL_INTERFACE);
+   __cfg80211_unregister_wdev(wdev, false);
sysfs_remove_link(>dev.kobj, "phy80211");
-   list_del_rcu(>list);
-   rdev->devlist_generation++;
-   cfg80211_mlme_purge_registrations(wdev);
-#ifdef CONFIG_CFG80211_WEXT
-   kzfree(wdev->wext.keys);
-#endif
-   flush_work(>disconnect_wk);
-   cfg80211_cqm_config_free(wdev);
}
/*
 * synchronise (so that we won't find this netdev
-- 
2.14.4



Re: [PATCH] mt76x2: move mt76x2 source files to mt76x2 folder

2018-10-01 Thread Felix Fietkau
On 2018-10-01 10:18, Lorenzo Bianconi wrote:
> Move mt76x2 and mt76x2u drivers to mt76x2 subfolder and
> leave just shared code in mt76 root folder
> 
> Acked-by: Stanislaw Gruszka 
> Signed-off-by: Lorenzo Bianconi 
Merged, thanks.

- Felix


[PATCH] mt76x0: init: remove unnecessary configurations

2018-10-01 Thread Lorenzo Bianconi
Remove leftover configuration for legacy devices in
mt76x0_init_mac_registers routine. Moreover substitute
msleep function with usleep_range routine

Signed-off-by: Lorenzo Bianconi 
---
 drivers/net/wireless/mediatek/mt76/mt76x0/init.c | 7 +--
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/init.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/init.c
index edfd5d94d197..f59363f12c0a 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/init.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/init.c
@@ -172,12 +172,7 @@ static void mt76x0_init_mac_registers(struct mt76x0_dev 
*dev)
reg &= ~0x03FF;
reg |= 0x0201;
mt76_wr(dev, MT_WMM_CTRL, reg);
-
-   /* TODO: Probably not needed */
-   mt76_wr(dev, 0x7028, 0);
-   mt76_wr(dev, 0x7010, 0);
-   mt76_wr(dev, 0x7024, 0);
-   msleep(10);
+   usleep_range(1, 2);
 }
 
 static int mt76x0_init_wcid_mem(struct mt76x0_dev *dev)
-- 
2.17.1



Re: [PATCH v2] mt76x0: pci: add mt76x0e_cleanup routine

2018-10-01 Thread Felix Fietkau
On 2018-10-01 10:55, Lorenzo Bianconi wrote:
> Add mt76x0e_cleanup routine to tidy up the device
> during device removal
> 
> Signed-off-by: Lorenzo Bianconi 
Merged, thanks.

- Felix


pull request: mt76 2018-10-01

2018-10-01 Thread Felix Fietkau
Hi Kalle,

Here's another large batch of mt76 code cleanup / deduplication / fixes

- Felix

The following changes since commit 93ed990e3a6e722b7b1e1d59b3ceb8d91e36e682:

  qtnfmac: remove set but not used variable 'vif' (2018-09-20 15:12:13 +0300)

are available in the Git repository at:

  https://github.com/nbd168/wireless tags/mt76-for-kvalo-2018-10-01

for you to fetch changes up to 5289976ad887deb07c76df7eecf553c264aeebed:

  mt76: mt76x2: fix multi-interface beacon configuration (2018-10-01 13:26:21 
+0200)


mt76 patches for 4.20

* unify code between mt76x0, mt76x2
* mt76x0 fixes
* tx power configuration fix for 76x2
* more progress on mt76x0e support
* support for getting firmware version via ethtool
* fix for rx buffer allocation regression on usb
* fix for handling powersave responses
* fix for mt76x2 beacon transmission


Davide Caratti (1):
  mt76: report firmware version using ethtool

Felix Fietkau (6):
  mt76: add stbc entries to mt76_rate_power
  mt76: include linux/module.h in files using MODULE_*
  mt76x2: disable WLAN core before probe
  mt76: fix handling ps-poll frames
  mt76: check aggregation sequence number for frames sent via drv_tx
  mt76: mt76x2: fix multi-interface beacon configuration

Hauke Mehrtens (1):
  mt76: use skb_pad() instead of __skb_pad()

Lorenzo Bianconi (54):
  mt76x2: fix tx power configuration for VHT mcs 9
  mt76x0: pci: add mt7650 PCI ID
  mt76x0: pci: add fw uploading routine
  mt76: move seq_put_array in mt76-core module
  mt76: move common eeprom definitions in mt76x02-lib module
  mt76: move eeprom utility routines in mt76x02_eeprom.h
  mt76: move mt76x2_eeprom_get in mt76x02_eeprom.h
  mt76: move mt76x02_mac_setaddr in mt76x02-lib module
  mt76: move mt76x2_get_efuse_data in mt76x02-lib module
  mt76: move mt76x2_ext_pa_enabled routine in mt76x02_eeprom.c
  mt76x0: remove mt76x0_set_country_reg routine
  mt76: add mt76x02_get_rx_gain and mt76x02_get_lna_gain utility routines
  mt76x0: unify lna_gain parsing
  mt76x0: unify rssi_offset parsing
  mt76x0: unify temperature offset parsing
  mt76x0: unify freq offset parsing
  mt76: move mt76x02_eeprom_parse_hw_cap in mt76x02-lib module
  mt76x0: unify parse hw capabilities
  mt76: move mt76x2_tssi_enabled in mt76x02_eeprom.h
  mt76: usb: remove WARN_ON in mt76u_get_rx_entry_len
  mt76: move mt76_rate_power in mt76_dev
  mt76: add mt76x02_phy_set_txpower utility routine
  mt76: move rate_txpower handler in mt76 debugfs
  mt76: move mt76x02_rate_power_val in mt76x02-lib module
  mt76x0: remove mt76x0_phy_set_tx_power and mt76x0_extra_power_over_mac
  mt76x0: remove eeprom dependency from mt76x0_set_tx_power_per_rate
  mt76x0: remove eeprom dependency from mt76x0_get_power_info
  mt76x0: use shared debugfs implementation
  mt76x0: phy: introduce mt76x0_phy_set_txpower routine
  mt76: usb: make rx page_frag_cache access atomic
  mt76x0: use mt76_poll in mt76x0_set_wlan_state
  mt76: move wait_for_wpdma in mt76x02_dma.h
  mt76: add mt76x02_dma_enable/mt76x02_dma_disable utility routines
  mt76: move mt76x02_set_irq_mask in mt76x02_mmio.c
  mt76: move queue initialization in mt76x02_mmio.c
  mt76: move mt76x02_beacon_offset in mt76x02_util.c
  mt76: mmio: add implementation of wr_rp and rd_rp
  mt76: move mt76x2_wait_for_bbp in mt76x02-lib module
  mt76x0: update initvals to latest version of vendor driver
  mt76x0: pci: move mcu code in pci_mcu.c
  mt76x0: usb: move mcu code in usb_mcu.c
  mt76x0: use mt76x02 utility routines in mt76x0 init code
  mt76x0: init: remove duplicated initialization
  mt76x0: init: remove MT_PBF_SYS_CTRL configuration in mt76x0_reset_csr_bbp
  mt76x0: init rx filter in mt76x0_init_hardware
  mt76: add mt76x02_mac_start routine
  mt76x0: usb: move initialization code in usb.c
  mt76x0: pci: add hw initialization at bootstrap
  mt76x0: phy: set antenna parameter according to wireless band
  mt76: move set_{tx,rx}_path routines in mt76x02-lib module
  mt76x0: add ieee80211_ops ops pointer to mt76x0_alloc_device signature
  mt76x0: pci: add mt76x0e_{start/stop} callbacks
  mt76x0: eeprom: load eeprom data from mtd by default
  mt76x0: usb: move mt76x0u_tx_prepare_skb in usb.c

Stanislaw Gruszka (2):
  mt76: fix return value of mt76x02_wait_for_mac
  mt76x0: add quirk to disable 2.4GHz band for Archer T1U

 drivers/net/wireless/mediatek/mt76/Makefile |   3 +-
 drivers/net/wireless/mediatek/mt76/debugfs.c|  31 ++
 drivers/net/wireless/mediatek/mt76/mac80211.c   |   6 +
 drivers/net/wireless/mediatek/mt76/mmio.c   |  27 +
 

[PATCH] mt76: mt76x2: fix multi-interface beacon configuration

2018-10-01 Thread Felix Fietkau
If the first virtual interface is a station (or an AP with beacons
temporarily disabled), the beacon of the second interface needs to
occupy hardware beacon slot 0.
For some reason the beacon index was incorrectly masked with the
virtual interface beacon mask, which prevents the secondary
interface from sending beacons unless the first one also does.

Cc: sta...@vger.kernel.org
Signed-off-by: Felix Fietkau 
---
 drivers/net/wireless/mediatek/mt76/mt76x2_mac.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2_mac.c 
b/drivers/net/wireless/mediatek/mt76/mt76x2_mac.c
index 25ce8fcbb873..bb9c0a059a6e 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x2_mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x2_mac.c
@@ -129,8 +129,7 @@ __mt76x2_mac_set_beacon(struct mt76x2_dev *dev, u8 bcn_idx, 
struct sk_buff *skb)
if (skb) {
ret = mt76_write_beacon(dev, beacon_addr, skb);
if (!ret)
-   dev->beacon_data_mask |= BIT(bcn_idx) &
-dev->beacon_mask;
+   dev->beacon_data_mask |= BIT(bcn_idx);
} else {
dev->beacon_data_mask &= ~BIT(bcn_idx);
for (i = 0; i < beacon_len; i += 4)
-- 
2.17.0



[PATCH v2 2/4] dts: arm64/sdm845: Add WCN3990 WLAN module device node

2018-10-01 Thread Govind Singh
Add device node for the ath10k SNOC platform driver probe
and add resources required for WCN3990 on SDM845 soc.

Signed-off-by: Govind Singh 
---
 arch/arm64/boot/dts/qcom/sdm845-mtp.dts |  7 +++
 arch/arm64/boot/dts/qcom/sdm845.dtsi| 26 +
 2 files changed, 33 insertions(+)

diff --git a/arch/arm64/boot/dts/qcom/sdm845-mtp.dts 
b/arch/arm64/boot/dts/qcom/sdm845-mtp.dts
index eedfaf8922e2..4de57f7df93c 100644
--- a/arch/arm64/boot/dts/qcom/sdm845-mtp.dts
+++ b/arch/arm64/boot/dts/qcom/sdm845-mtp.dts
@@ -440,3 +440,10 @@
bias-pull-up;
};
 };
+
+ {
+   vdd-0.8-cx-mx-supply = <_l5a_0p8>;
+   vdd-1.8-xo-supply = <_l7a_1p8>;
+   vdd-1.3-rfa-supply = <_l17a_1p3>;
+   vdd-3.3-ch0-supply = <_l25a_3p3>;
+};
diff --git a/arch/arm64/boot/dts/qcom/sdm845.dtsi 
b/arch/arm64/boot/dts/qcom/sdm845.dtsi
index e080072cdfdb..36c716cf3a0c 100644
--- a/arch/arm64/boot/dts/qcom/sdm845.dtsi
+++ b/arch/arm64/boot/dts/qcom/sdm845.dtsi
@@ -86,6 +86,11 @@
reg = <0 0x8620 0 0x2d0>;
no-map;
};
+
+   wlan_msa_mem: reserved-memory@9670 {
+   no-map;
+   reg = <0 0x9670 0 0x10>;
+   };
};
 
cpus {
@@ -1200,5 +1205,26 @@
status = "disabled";
};
};
+
+   wifi: wifi@1880 {
+   compatible = "qcom,wcn3990-wifi";
+   status = "disabled";
+   reg = <0x1880 0x80>;
+   reg-names = "membase";
+   memory-region = <_msa_mem>;
+   interrupts =
+   <0 413 0 /* CE0 */ >,
+   <0 414 0 /* CE1 */ >,
+   <0 415 0 /* CE2 */ >,
+   <0 416 0 /* CE3 */ >,
+   <0 417 0 /* CE4 */ >,
+   <0 418 0 /* CE5 */ >,
+   <0 420 0 /* CE6 */ >,
+   <0 421 0 /* CE7 */ >,
+   <0 422 0 /* CE8 */ >,
+   <0 423 0 /* CE9 */ >,
+   <0 424 0 /* CE10 */ >,
+   <0 425 0 /* CE11 */ >;
+   };
};
 };
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v2 1/4] dt: bindings: add missing dt properties for WCN3990 wifi node

2018-10-01 Thread Govind Singh
Add missing optional properties in WCN3990 wifi node.

Signed-off-by: Govind Singh 
---
 .../bindings/net/wireless/qcom,ath10k.txt | 28 ++-
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/wireless/qcom,ath10k.txt 
b/Documentation/devicetree/bindings/net/wireless/qcom,ath10k.txt
index 7fd4e8ce4149..f831bb1c5952 100644
--- a/Documentation/devicetree/bindings/net/wireless/qcom,ath10k.txt
+++ b/Documentation/devicetree/bindings/net/wireless/qcom,ath10k.txt
@@ -37,12 +37,20 @@ Optional properties:
 - clocks: List of clock specifiers, must contain an entry for each required
   entry in clock-names.
 - clock-names: Should contain the clock names "wifi_wcss_cmd", "wifi_wcss_ref",
-   "wifi_wcss_rtc".
-- interrupts: List of interrupt lines. Must contain an entry
- for each entry in the interrupt-names property.
+  "wifi_wcss_rtc" for "qcom,ipq4019-wifi" compatible target and
+  "cxo_ref_clk_pin", "smmu_aggre2_noc_clk" for "qcom,wcn3990-wifi"
+  compatible target.
+- interrupts: reference to the list of 17 interrupt no's for 
"qcom,ipq4019-wifi"
+ compatible target.
+ reference to the list of 12 interrupt no's for "qcom,wcn3990-wifi"
+ compatible target.
+ Must contain interrupt-names property per entry for
+ "qcom,ath10k", "qcom,ipq4019-wifi" compatible targets.
+
 - interrupt-names: Must include the entries for MSI interrupt
   names ("msi0" to "msi15") and legacy interrupt
-  name ("legacy"),
+  name ("legacy") for "qcom,ath10k", "qcom,ipq4019-wifi"
+  compatible targets.
 - qcom,msi_addr: MSI interrupt address.
 - qcom,msi_base: Base value to add before writing MSI data into
MSI address register.
@@ -55,7 +63,8 @@ Optional properties:
 - qcom,ath10k-pre-calibration-data : pre calibration data as an array,
 the length can vary between hw versions.
 - -supply: handle to the regulator device tree node
-  optional "supply-name" is "vdd-0.8-cx-mx".
+  optional "supply-name" are "vdd-0.8-cx-mx",
+  "vdd-1.8-xo", "vdd-1.3-rfa" and "vdd-3.3-ch0".
 
 Example (to supply the calibration data alone):
 
@@ -133,8 +142,10 @@ wifi@1800 {
compatible = "qcom,wcn3990-wifi";
reg = <0x1880 0x80>;
reg-names = "membase";
-   clocks = <_gcc clk_aggre2_noc_clk>;
-   clock-names = "smmu_aggre2_noc_clk"
+   clocks = <_gcc clk_aggre2_noc_clk>,
+<_gcc clk_rf_clk2_pin>;
+   clock-names = "smmu_aggre2_noc_clk",
+ "cxo_ref_clk_pin";
interrupts =
   <0 130 0 /* CE0 */ >,
   <0 131 0 /* CE1 */ >,
@@ -149,4 +160,7 @@ wifi@1800 {
   <0 140 0 /* CE10 */ >,
   <0 141 0 /* CE11 */ >;
vdd-0.8-cx-mx-supply = <_l5>;
+   vdd-1.8-xo-supply = <_l7a_1p8>;
+   vdd-1.3-rfa-supply = <_l17a_1p3>;
+   vdd-3.3-ch0-supply = <_l25a_3p3>;
 };
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



Re: [PATCH] New functionality for aborting ongoing CAC.

2018-10-01 Thread Enrique Giraldo
You are right, it is possible to do it as you comment
(NL80211_CMD_STOP_AP and then NL80211_CMD_START_AP). It is therefore
not necessary a specific command to abort the CAC.
Thank you very much for the clarification and the time spent.

PS: If you use OpenWRT you have to control the STOP and the START, the
command "wifi" does not work properly.
El mié., 26 sept. 2018 a las 11:26, Johannes Berg
() escribió:
>
> On Tue, 2018-09-25 at 10:19 +0200, Enrique Giraldo wrote:
> > Add NL80211_CMD_ABORT_CAC to the nl80211 interface.
>
> As Arend pointed out, this really needs a much better commit message.
>
> Please also adjust the subject to have a proper prefix etc. See
> https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
> for some help with that.
>
> > @@ -3227,6 +3228,7 @@ struct cfg80211_ops {
> >   int (*scan)(struct wiphy *wiphy,
> >   struct cfg80211_scan_request *request);
> >   void(*abort_scan)(struct wiphy *wiphy, struct wireless_dev *wdev);
> > + void(*abort_cac)(struct wiphy *wiphy, struct wireless_dev *wdev);
>
> This is fine, you can add in the middle of the struct.
>
> >
> > @@ -1220,6 +1223,7 @@ enum nl80211_commands {
> >   NL80211_CMD_WIPHY_REG_CHANGE,
> >
> >   NL80211_CMD_ABORT_SCAN,
> > + NL80211_CMD_ABORT_CAC,
> >
> >   NL80211_CMD_START_NAN,
>
> This is *not* OK, as the comments here indicate, we must never add
> anything in the middle of this enum, doing so breaks userspace ABI.
>
> johannes


Re: [PATCH] nl80211: Add per peer statistics to compute FCS error rate

2018-10-01 Thread Johannes Berg
On Thu, 2018-09-27 at 18:01 +0300, Jouni Malinen wrote:
> From: Ankita Bajaj 
> 
> Add support for drivers to report the total number of MPDUs received
> and the number of MPDUs received with an FCS error from a specific
> peer. These counters will be incremented only when the TA of the
> frame matches the MAC address of the peer irrespective of FCS
> error.

Hmm. The error one seems mostly reasonable, I guess, but do we really
not having anything that's the total number of MPDUs already?

And then, I guess, what exactly would you want there? We might not
always even be able to provide that?

I'm also left wondering what the application here is - perhaps another
thing we could just implement in BPF with the hooks I previously posted
(but admittedly never finished)?

johannes


Re: [RFC 4/5] mt76: move mt76x02_mac_write_txwi in mt76x02-lib module

2018-10-01 Thread Lorenzo Bianconi
> On Sat, Sep 29, 2018 at 07:44:55PM +0200, Lorenzo Bianconi wrote:
> > +   if (dev->drv->get_tx_txpwr_adj) {
> > +   txpwr_adj = dev->drv->get_tx_txpwr_adj(dev, dev->txpower_conf,
> > +  max_txpwr_adj);
> > +   txwi->ctl2 = FIELD_PREP(MT_TX_PWR_ADJ, txpwr_adj);
> > +   }
> > +
> > +   if (is_mt76x2(dev) && mt76_rev(dev) >= MT76XX_REV_E4)
> > +   txwi->txstream = 0x13;
> > +   else if (is_mt76x2(dev) && mt76_rev(dev) >= MT76XX_REV_E3 &&
> > +!(txwi->rate & cpu_to_le16(rate_ht_mask)))
> > +   txwi->txstream = 0x93;
> 
> All above looks mt76x2 specific, maybe would be beter to place this in 
> in setup_txwi() calback i.e:
> 
>   if (dev->drv->setup_txwi)
>   drv->drv->setup_txwi(...)
> 
> or maybe you plan to implement get_tx_txpwr_adj() for mt76x0 as well,
> is this feature supported by the MT76x0 chips ?

For the moment tpc is supported just for mt76x2 chipsets but tx power subfield
is present in mt76x0_txwi as well. Moreover merging mt76x2_dev and mt76x0_dev
in mt76x02_dev allows us to move mt76x2_get_tx_txpwr_adj() in mt76x02-lib
module, remove get_tx_txpwr_adj callback and just make tpc disabled for mt76x0
for the moment.
As suggested by Felix, we can take into account chainmask for txstream
configuration and remove is_mt76x2() check.
Agree?

Regards,
Lorenzo

> 
> Thanks
> Stanislaw


Re: [RFC 4/5] mt76: move mt76x02_mac_write_txwi in mt76x02-lib module

2018-10-01 Thread Felix Fietkau
On 2018-10-01 07:48, Stanislaw Gruszka wrote:
> On Sat, Sep 29, 2018 at 07:44:55PM +0200, Lorenzo Bianconi wrote:
>> +spin_lock_bh(>lock);
>> +if (wcid && (rate->idx < 0 || !rate->count)) {
>> +txwi->rate = wcid->tx_rate;
>> +max_txpwr_adj = wcid->max_txpwr_adj;
>> +nss = wcid->tx_rate_nss;
>> +} else {
>> +txwi->rate = mt76x02_mac_tx_rate_val(dev, rate, );
>> +max_txpwr_adj = mt76x02_tx_get_max_txpwr_adj(dev, rate);
>> +}
>> +spin_unlock_bh(>lock);
>> +
>> +if (dev->drv->get_tx_txpwr_adj) {
>> +txpwr_adj = dev->drv->get_tx_txpwr_adj(dev, dev->txpower_conf,
>> +   max_txpwr_adj);
>> +txwi->ctl2 = FIELD_PREP(MT_TX_PWR_ADJ, txpwr_adj);
>> +}
>> +
>> +if (is_mt76x2(dev) && mt76_rev(dev) >= MT76XX_REV_E4)
>> +txwi->txstream = 0x13;
>> +else if (is_mt76x2(dev) && mt76_rev(dev) >= MT76XX_REV_E3 &&
>> + !(txwi->rate & cpu_to_le16(rate_ht_mask)))
>> +txwi->txstream = 0x93;
> 
> All above looks mt76x2 specific, maybe would be beter to place this in 
> in setup_txwi() calback i.e:
> 
>   if (dev->drv->setup_txwi)
>   drv->drv->setup_txwi(...)
> 
> or maybe you plan to implement get_tx_txpwr_adj() for mt76x0 as well,
> is this feature supported by the MT76x0 chips ?
I think get_tx_txpwr_adj should be implemented for mt76x0 as well. I
don't think we need a setup_txwi callback here.

- Felix


[PATCH] nl80211: add error messages to nl80211_parse_chandef()

2018-10-01 Thread Johannes Berg
From: Johannes Berg 

Add some error messages to nl80211_parse_chandef() to make
failures here - especially with disabled channels - easier
to diagnose.

Signed-off-by: Johannes Berg 
---
 net/wireless/nl80211.c | 62 --
 1 file changed, 40 insertions(+), 22 deletions(-)

diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 0b8896dca65e..fb7f07b0e123 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -2292,12 +2292,14 @@ static int nl80211_parse_chandef(struct 
cfg80211_registered_device *rdev,
 struct genl_info *info,
 struct cfg80211_chan_def *chandef)
 {
+   struct netlink_ext_ack *extack = info->extack;
+   struct nlattr **attrs = info->attrs;
u32 control_freq;
 
-   if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
+   if (!attrs[NL80211_ATTR_WIPHY_FREQ])
return -EINVAL;
 
-   control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
+   control_freq = nla_get_u32(attrs[NL80211_ATTR_WIPHY_FREQ]);
 
chandef->chan = ieee80211_get_channel(>wiphy, control_freq);
chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
@@ -2305,14 +2307,16 @@ static int nl80211_parse_chandef(struct 
cfg80211_registered_device *rdev,
chandef->center_freq2 = 0;
 
/* Primary channel not allowed */
-   if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
+   if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) {
+   NL_SET_ERR_MSG_ATTR(extack, attrs[NL80211_ATTR_WIPHY_FREQ],
+   "Channel is disabled");
return -EINVAL;
+   }
 
-   if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
+   if (attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
enum nl80211_channel_type chantype;
 
-   chantype = nla_get_u32(
-   info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
+   chantype = nla_get_u32(attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
 
switch (chantype) {
case NL80211_CHAN_NO_HT:
@@ -2322,42 +2326,56 @@ static int nl80211_parse_chandef(struct 
cfg80211_registered_device *rdev,
cfg80211_chandef_create(chandef, chandef->chan,
chantype);
/* user input for center_freq is incorrect */
-   if (info->attrs[NL80211_ATTR_CENTER_FREQ1] &&
-   chandef->center_freq1 != nla_get_u32(
-   info->attrs[NL80211_ATTR_CENTER_FREQ1]))
+   if (attrs[NL80211_ATTR_CENTER_FREQ1] &&
+   chandef->center_freq1 != 
nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1])) {
+   NL_SET_ERR_MSG_ATTR(extack,
+   
attrs[NL80211_ATTR_CENTER_FREQ1],
+   "bad center frequency 1");
return -EINVAL;
+   }
/* center_freq2 must be zero */
-   if (info->attrs[NL80211_ATTR_CENTER_FREQ2] &&
-   nla_get_u32(info->attrs[NL80211_ATTR_CENTER_FREQ2]))
+   if (attrs[NL80211_ATTR_CENTER_FREQ2] &&
+   nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2])) {
+   NL_SET_ERR_MSG_ATTR(extack,
+   
attrs[NL80211_ATTR_CENTER_FREQ2],
+   "center frequency 2 can't 
be used");
return -EINVAL;
+   }
break;
default:
+   NL_SET_ERR_MSG_ATTR(extack,
+   
attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE],
+   "invalid channel type");
return -EINVAL;
}
-   } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
+   } else if (attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
chandef->width =
-   nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
-   if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
+   nla_get_u32(attrs[NL80211_ATTR_CHANNEL_WIDTH]);
+   if (attrs[NL80211_ATTR_CENTER_FREQ1])
chandef->center_freq1 =
-   nla_get_u32(
-   info->attrs[NL80211_ATTR_CENTER_FREQ1]);
-   if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
+   nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1]);
+   if (attrs[NL80211_ATTR_CENTER_FREQ2])
chandef->center_freq2 =
- 

[PATCH] cfg80211: move cookie_counter out of wiphy

2018-10-01 Thread Johannes Berg
From: Johannes Berg 

There's no reason for drivers to be able to access the
cfg80211 internal cookie counter; move it out of the
wiphy into the rdev structure.

While at it, also make it never assign 0 as a cookie
(we consider that invalid in some places), and warn if
we manage to do that for some reason (wrapping is not
likely to happen with a u64.)

Signed-off-by: Johannes Berg 
---
 include/net/cfg80211.h |  3 ---
 net/wireless/core.h| 11 +++
 net/wireless/nl80211.c |  4 ++--
 3 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index 9f3ed79c39d7..b74ab3a545ab 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -3960,7 +3960,6 @@ struct wiphy_iftype_ext_capab {
  * by the driver in the .connect() callback. The bit position maps to the
  * attribute indices defined in  nl80211_bss_select_attr.
  *
- * @cookie_counter: unique generic cookie counter, used to identify objects.
  * @nan_supported_bands: bands supported by the device in NAN mode, a
  * bitmap of  nl80211_band values.  For instance, for
  * NL80211_BAND_2GHZ, bit 0 would be set
@@ -4099,8 +4098,6 @@ struct wiphy {
 
u32 bss_select_support;
 
-   u64 cookie_counter;
-
u8 nan_supported_bands;
 
u32 txq_limit;
diff --git a/net/wireless/core.h b/net/wireless/core.h
index 45fd4e21dbda..c61dbba8bf47 100644
--- a/net/wireless/core.h
+++ b/net/wireless/core.h
@@ -66,6 +66,7 @@ struct cfg80211_registered_device {
/* protected by RTNL only */
int num_running_ifaces;
int num_running_monitor_ifaces;
+   u64 cookie_counter;
 
/* BSSes/scanning */
spinlock_t bss_lock;
@@ -133,6 +134,16 @@ cfg80211_rdev_free_wowlan(struct 
cfg80211_registered_device *rdev)
 #endif
 }
 
+static inline u64 cfg80211_assign_cookie(struct cfg80211_registered_device 
*rdev)
+{
+   u64 r = ++rdev->cookie_counter;
+
+   if (WARN_ON(r == 0))
+   r = ++rdev->cookie_counter;
+
+   return r;
+}
+
 extern struct workqueue_struct *cfg80211_wq;
 extern struct list_head cfg80211_rdev_list;
 extern int cfg80211_rdev_list_generation;
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 52086f71103a..35d2947a2af5 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -7759,7 +7759,7 @@ static int nl80211_start_sched_scan(struct sk_buff *skb,
 */
if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1) {
while (!sched_scan_req->reqid)
-   sched_scan_req->reqid = rdev->wiphy.cookie_counter++;
+   sched_scan_req->reqid = cfg80211_assign_cookie(rdev);
}
 
err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
@@ -11755,7 +11755,7 @@ static int nl80211_nan_add_func(struct sk_buff *skb,
if (!func)
return -ENOMEM;
 
-   func->cookie = wdev->wiphy->cookie_counter++;
+   func->cookie = cfg80211_assign_cookie(rdev);
 
if (!tb[NL80211_NAN_FUNC_TYPE] ||
nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) {
-- 
2.14.4



[PATCH] cfg80211: regulatory: make initialization more robust

2018-10-01 Thread Johannes Berg
From: Johannes Berg 

Since my change to split out the regulatory init to occur later,
any issues during earlier cfg80211_init() or errors during the
platform device allocation would lead to crashes later. Make this
more robust by checking that the earlier initialization succeeded.

Fixes: d7be102f2945 ("cfg80211: initialize regulatory keys/database later")
Signed-off-by: Johannes Berg 
---
 net/wireless/reg.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index 56be68a27bb9..d7b93a772edc 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -3829,6 +3829,15 @@ static int __init regulatory_init_db(void)
 {
int err;
 
+   /*
+* It's possible that - due to other bugs/issues - cfg80211
+* never called regulatory_init() below, or that it failed;
+* in that case, don't try to do any further work here as
+* it's doomed to lead to crashes.
+*/
+   if (IS_ERR_OR_NULL(reg_pdev))
+   return -EINVAL;
+
err = load_builtin_regdb_keys();
if (err)
return err;
-- 
2.14.4



[PATCH v2] rtlwifi: Removed unused define and code efuse_re_pg* from wifi.h

2018-10-01 Thread pkshih
From: Ping-Ke Shih 

The following:
 bool efuse_re_pg_sec1flag;
 u8 efuse_re_pg_data[8];
are not referenced anywhere in the rtlwifi code.

This patch is originally created by Rick Veens ,
and Joe Perches  reminded to apply it to rtlwifi.

Signed-off-by: Ping-Ke Shih 
---
v2: change author to me
---
 drivers/net/wireless/realtek/rtlwifi/wifi.h | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/wifi.h 
b/drivers/net/wireless/realtek/rtlwifi/wifi.h
index 0f3b98c5227f..87bc21bb5e8b 100644
--- a/drivers/net/wireless/realtek/rtlwifi/wifi.h
+++ b/drivers/net/wireless/realtek/rtlwifi/wifi.h
@@ -1905,10 +1905,6 @@ struct rtl_efuse {
u8 efuse_map[2][EFUSE_MAX_LOGICAL_SIZE];
u16 efuse_usedbytes;
u8 efuse_usedpercentage;
-#ifdef EFUSE_REPG_WORKAROUND
-   bool efuse_re_pg_sec1flag;
-   u8 efuse_re_pg_data[8];
-#endif
 
u8 autoload_failflag;
u8 autoload_status;
-- 
2.15.1



Re: [PATCH] rtlwifi: Removed unused define and code efuse_re_pg* from wifi.h

2018-10-01 Thread Pkshih
On Mon, 2018-10-01 at 12:10 +0300, Kalle Valo wrote:
>  writes:
> 
> > From: Rick Veens 
> >
> > The following:
> >  bool efuse_re_pg_sec1flag;
> >  u8 efuse_re_pg_data[8];
> > are not referenced anywhere in the rtlwifi code.
> >
> > This patch is originally created by Rick Veens ,
> > and Joe Perches  reminded to apply it to rtlwifi.
> >
> > Signed-off-by: Ping-Ke Shih 
> 
> Rick's Signed-off-by is missing. Ping, either you need to mark yourself
> as author (which IMHO is correct as you wrote this patch anyway, Rick
> wrote it for the other driver) or Rick needs to give his s-o-b.
> 

Will send v2.
Thanks

--
PK



Re: [PATCH] mt76x0: init: intrduce MT_H2M_* definitions

2018-10-01 Thread Lorenzo Bianconi
> On Sat, Sep 29, 2018 at 07:30:32PM +0200, Lorenzo Bianconi wrote:
> > Add MT_H2M_BBP_AGENT, MT_H2M_MAILBOX_CSR and MT_H2M_INT_SRC and
> > remove magic numbers
> > 
> >  
> > /* TODO: Probably not needed */
> > -   mt76_wr(dev, 0x7028, 0);
> > -   mt76_wr(dev, 0x7010, 0);
> > -   mt76_wr(dev, 0x7024, 0);
> > -   msleep(10);
> > +   mt76_wr(dev, MT_H2M_BBP_AGENT, 0);
> > +   mt76_wr(dev, MT_H2M_MAILBOX_CSR, 0);
> > +   mt76_wr(dev, MT_H2M_INT_SRC, 0);
> 
> The same here, I think this should be just removed.

ack, will send a patch to remove them

> 
> > +   usleep_range(1, 2);
> 
> Why this change ?

afaik for sleeping less than 20ms it is better to use usleep_range
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/timers/timers-howto.txt

Regards,
Lorenzo

> 
> Thanks
> Stanislaw


Re: [PATCH] rtlwifi: Removed unused define and code efuse_re_pg* from wifi.h

2018-10-01 Thread Kalle Valo
 writes:

> From: Rick Veens 
>
> The following:
>  bool efuse_re_pg_sec1flag;
>  u8 efuse_re_pg_data[8];
> are not referenced anywhere in the rtlwifi code.
>
> This patch is originally created by Rick Veens ,
> and Joe Perches  reminded to apply it to rtlwifi.
>
> Signed-off-by: Ping-Ke Shih 

Rick's Signed-off-by is missing. Ping, either you need to mark yourself
as author (which IMHO is correct as you wrote this patch anyway, Rick
wrote it for the other driver) or Rick needs to give his s-o-b.

-- 
Kalle Valo


[PATCH] rtlwifi: Removed unused define and code efuse_re_pg* from wifi.h

2018-10-01 Thread pkshih
From: Rick Veens 

The following:
 bool efuse_re_pg_sec1flag;
 u8 efuse_re_pg_data[8];
are not referenced anywhere in the rtlwifi code.

This patch is originally created by Rick Veens ,
and Joe Perches  reminded to apply it to rtlwifi.

Signed-off-by: Ping-Ke Shih 
---
 drivers/net/wireless/realtek/rtlwifi/wifi.h | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/wifi.h 
b/drivers/net/wireless/realtek/rtlwifi/wifi.h
index 0f3b98c5227f..87bc21bb5e8b 100644
--- a/drivers/net/wireless/realtek/rtlwifi/wifi.h
+++ b/drivers/net/wireless/realtek/rtlwifi/wifi.h
@@ -1905,10 +1905,6 @@ struct rtl_efuse {
u8 efuse_map[2][EFUSE_MAX_LOGICAL_SIZE];
u16 efuse_usedbytes;
u8 efuse_usedpercentage;
-#ifdef EFUSE_REPG_WORKAROUND
-   bool efuse_re_pg_sec1flag;
-   u8 efuse_re_pg_data[8];
-#endif
 
u8 autoload_failflag;
u8 autoload_status;
-- 
2.15.1



Re: [PATCH v3 00/29] staging: wilc1000: avoid static variables and cleanup changes

2018-10-01 Thread Ajay Singh
Hi Dan,

On Mon, 1 Oct 2018 10:47:34 +0300
Dan Carpenter  wrote:

> On Tue, Sep 25, 2018 at 11:53:15AM +0530, Ajay Singh wrote:
> > This patch series contains changes to avoid the use of static
> > variables. Cleanup changes to fix some checkpatch issues and return
> > void for function if their return value is not used.
> > Also deleted 'wilc_debugfs.c' file as it's not used.
> > 
> > Changes since v2:
> >Included Joe's suggestion for patch#28
> > - replaced previous patch with an improved version(refactor
> > code)
> > 
> > Changes since v1:
> >Address Dan's comment for patch#29
> > - return the correct error for failure in the second iteration  
> 
> Btw, I hate re-reviewing patches and I know everyone hates sending
> them. If someone complains about a 28/29 or a 29/29, then you can
> just ask Greg to apply the first 27 and redo the others in a follow
> on patchset.
> 
Sure, I will keep this point in mind while sending the series updates.

Regards
Ajay



[PATCH v2] mt76x0: pci: add mt76x0e_cleanup routine

2018-10-01 Thread Lorenzo Bianconi
Add mt76x0e_cleanup routine to tidy up the device
during device removal

Signed-off-by: Lorenzo Bianconi 
---
Changes since v1:
- remove H2M_MAILBOX_* configurations
---
 .../net/wireless/mediatek/mt76/mt76x0/pci.c   | 26 ++-
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c
index 876291dd3c1e..97bf8634b06d 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c
@@ -41,13 +41,8 @@ static int mt76x0e_start(struct ieee80211_hw *hw)
return 0;
 }
 
-static void mt76x0e_stop(struct ieee80211_hw *hw)
+static void mt76x0e_stop_hw(struct mt76x0_dev *dev)
 {
-   struct mt76x0_dev *dev = hw->priv;
-
-   mutex_lock(>mt76.mutex);
-
-   clear_bit(MT76_STATE_RUNNING, >mt76.state);
cancel_delayed_work_sync(>cal_work);
cancel_delayed_work_sync(>mac_work);
 
@@ -62,7 +57,15 @@ static void mt76x0e_stop(struct ieee80211_hw *hw)
   0, 1000))
dev_warn(dev->mt76.dev, "TX DMA did not stop\n");
mt76_clear(dev, MT_WPDMA_GLO_CFG, MT_WPDMA_GLO_CFG_RX_DMA_EN);
+}
+
+static void mt76x0e_stop(struct ieee80211_hw *hw)
+{
+   struct mt76x0_dev *dev = hw->priv;
 
+   mutex_lock(>mt76.mutex);
+   clear_bit(MT76_STATE_RUNNING, >mt76.state);
+   mt76x0e_stop_hw(dev);
mutex_unlock(>mt76.mutex);
 }
 
@@ -160,12 +163,23 @@ mt76x0e_probe(struct pci_dev *pdev, const struct 
pci_device_id *id)
return ret;
 }
 
+static void mt76x0e_cleanup(struct mt76x0_dev *dev)
+{
+   clear_bit(MT76_STATE_INITIALIZED, >mt76.state);
+   mt76x0_chip_onoff(dev, false, false);
+   mt76x0e_stop_hw(dev);
+   mt76_dma_cleanup(>mt76);
+   mt76x02_mcu_cleanup(>mt76);
+}
+
 static void
 mt76x0e_remove(struct pci_dev *pdev)
 {
struct mt76_dev *mdev = pci_get_drvdata(pdev);
+   struct mt76x0_dev *dev = container_of(mdev, struct mt76x0_dev, mt76);
 
mt76_unregister_device(mdev);
+   mt76x0e_cleanup(dev);
ieee80211_free_hw(mdev->hw);
 }
 
-- 
2.17.1



Re: [PATCH] mt76x0: pci: add mt76x0e_cleanup routine

2018-10-01 Thread Lorenzo Bianconi
On Oct 01, Stanislaw Gruszka wrote:
> Hi
> 
> On Sat, Sep 29, 2018 at 07:26:41PM +0200, Lorenzo Bianconi wrote:
> > Add mt76x0e_cleanup routine to tidy up the device
> > during netdevice removal
> > 
> > Signed-off-by: Lorenzo Bianconi 
> > +   mt76_wr(dev, MT_H2M_MAILBOX_CID, ~0);
> > +   mt76_wr(dev, MT_H2M_MAILBOX_STATUS, ~0);
> 
> I don't think this is needed. Those are legacy communication registers,
> most likely not used in new chips and stay in vendor driver, because
> it wasn't cleaned up.

Ack, I will remove them in v2.
Regards,

Lorenzo

> 
> Regards
> Stanislaw
> 


[PATCH] mt76x2: move mt76x2 source files to mt76x2 folder

2018-10-01 Thread Lorenzo Bianconi
Move mt76x2 and mt76x2u drivers to mt76x2 subfolder and
leave just shared code in mt76 root folder

Acked-by: Stanislaw Gruszka 
Signed-off-by: Lorenzo Bianconi 
---
 drivers/net/wireless/mediatek/mt76/Kconfig| 43 +--
 drivers/net/wireless/mediatek/mt76/Makefile   | 22 +-
 .../net/wireless/mediatek/mt76/mt76x0/Kconfig | 20 +
 .../net/wireless/mediatek/mt76/mt76x2/Kconfig | 20 +
 .../wireless/mediatek/mt76/mt76x2/Makefile| 18 
 .../mt76/{mt76x2_common.c => mt76x2/common.c} |  2 +-
 .../{mt76x2_debugfs.c => mt76x2/debugfs.c}|  0
 .../mt76/{mt76x2_dfs.h => mt76x2/dfs.h}   |  0
 .../mt76/{mt76x2_eeprom.c => mt76x2/eeprom.c} |  2 +-
 .../mt76/{mt76x2_eeprom.h => mt76x2/eeprom.h} |  2 +-
 .../{mt76x2_init_common.c => mt76x2/init.c}   |  4 +-
 .../{mt76x2_mac_common.c => mt76x2/mac.c} |  2 +-
 .../mt76/{mt76x2_mac.h => mt76x2/mac.h}   |  4 +-
 .../{mt76x2_mcu_common.c => mt76x2/mcu.c} |  6 +--
 .../mt76/{mt76x2_mcu.h => mt76x2/mcu.h}   |  2 +-
 .../mediatek/mt76/{ => mt76x2}/mt76x2.h   |  8 ++--
 .../mediatek/mt76/{ => mt76x2}/mt76x2u.h  |  4 +-
 .../mt76/{mt76x2_pci.c => mt76x2/pci.c}   |  2 +-
 .../mt76/{mt76x2_core.c => mt76x2/pci_core.c} |  4 +-
 .../mt76/{mt76x2_dfs.c => mt76x2/pci_dfs.c}   |  2 +-
 .../mt76/{mt76x2_dma.c => mt76x2/pci_dma.c}   |  4 +-
 .../mt76/{mt76x2_init.c => mt76x2/pci_init.c} |  8 ++--
 .../mt76/{mt76x2_mac.c => mt76x2/pci_mac.c}   |  8 ++--
 .../mt76/{mt76x2_main.c => mt76x2/pci_main.c} |  2 +-
 .../mt76/{mt76x2_mcu.c => mt76x2/pci_mcu.c}   |  6 +--
 .../mt76/{mt76x2_phy.c => mt76x2/pci_phy.c}   |  4 +-
 .../{mt76x2_trace.c => mt76x2/pci_trace.c}|  2 +-
 .../mt76/{mt76x2_tx.c => mt76x2/pci_tx.c} |  4 +-
 .../{mt76x2_phy_common.c => mt76x2/phy.c} |  6 +--
 .../mt76/{mt76x2_trace.h => mt76x2/trace.h}   |  2 +-
 .../mt76/{mt76x2_tx_common.c => mt76x2/tx.c}  |  2 +-
 .../mt76/{mt76x2_usb.c => mt76x2/usb.c}   |  2 +-
 .../{mt76x2u_core.c => mt76x2/usb_core.c} |  6 +--
 .../{mt76x2u_init.c => mt76x2/usb_init.c} |  6 +--
 .../mt76/{mt76x2u_mac.c => mt76x2/usb_mac.c}  |  2 +-
 .../{mt76x2u_main.c => mt76x2/usb_main.c} |  2 +-
 .../mt76/{mt76x2u_mcu.c => mt76x2/usb_mcu.c}  |  4 +-
 .../mt76/{mt76x2u_phy.c => mt76x2/usb_phy.c}  |  2 +-
 38 files changed, 120 insertions(+), 119 deletions(-)
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/Kconfig
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x2/Kconfig
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x2/Makefile
 rename drivers/net/wireless/mediatek/mt76/{mt76x2_common.c => mt76x2/common.c} 
(98%)
 rename drivers/net/wireless/mediatek/mt76/{mt76x2_debugfs.c => 
mt76x2/debugfs.c} (100%)
 rename drivers/net/wireless/mediatek/mt76/{mt76x2_dfs.h => mt76x2/dfs.h} (100%)
 rename drivers/net/wireless/mediatek/mt76/{mt76x2_eeprom.c => mt76x2/eeprom.c} 
(99%)
 rename drivers/net/wireless/mediatek/mt76/{mt76x2_eeprom.h => mt76x2/eeprom.h} 
(98%)
 rename drivers/net/wireless/mediatek/mt76/{mt76x2_init_common.c => 
mt76x2/init.c} (99%)
 rename drivers/net/wireless/mediatek/mt76/{mt76x2_mac_common.c => 
mt76x2/mac.c} (99%)
 rename drivers/net/wireless/mediatek/mt76/{mt76x2_mac.h => mt76x2/mac.h} (97%)
 rename drivers/net/wireless/mediatek/mt76/{mt76x2_mcu_common.c => 
mt76x2/mcu.c} (97%)
 rename drivers/net/wireless/mediatek/mt76/{mt76x2_mcu.h => mt76x2/mcu.h} (99%)
 rename drivers/net/wireless/mediatek/mt76/{ => mt76x2}/mt76x2.h (98%)
 rename drivers/net/wireless/mediatek/mt76/{ => mt76x2}/mt76x2u.h (98%)
 rename drivers/net/wireless/mediatek/mt76/{mt76x2_pci.c => mt76x2/pci.c} (99%)
 rename drivers/net/wireless/mediatek/mt76/{mt76x2_core.c => mt76x2/pci_core.c} 
(97%)
 rename drivers/net/wireless/mediatek/mt76/{mt76x2_dfs.c => mt76x2/pci_dfs.c} 
(99%)
 rename drivers/net/wireless/mediatek/mt76/{mt76x2_dma.c => mt76x2/pci_dma.c} 
(95%)
 rename drivers/net/wireless/mediatek/mt76/{mt76x2_init.c => mt76x2/pci_init.c} 
(99%)
 rename drivers/net/wireless/mediatek/mt76/{mt76x2_mac.c => mt76x2/pci_mac.c} 
(98%)
 rename drivers/net/wireless/mediatek/mt76/{mt76x2_main.c => mt76x2/pci_main.c} 
(99%)
 rename drivers/net/wireless/mediatek/mt76/{mt76x2_mcu.c => mt76x2/pci_mcu.c} 
(98%)
 rename drivers/net/wireless/mediatek/mt76/{mt76x2_phy.c => mt76x2/pci_phy.c} 
(99%)
 rename drivers/net/wireless/mediatek/mt76/{mt76x2_trace.c => 
mt76x2/pci_trace.c} (97%)
 rename drivers/net/wireless/mediatek/mt76/{mt76x2_tx.c => mt76x2/pci_tx.c} 
(98%)
 rename drivers/net/wireless/mediatek/mt76/{mt76x2_phy_common.c => 
mt76x2/phy.c} (99%)
 rename drivers/net/wireless/mediatek/mt76/{mt76x2_trace.h => mt76x2/trace.h} 
(98%)
 rename drivers/net/wireless/mediatek/mt76/{mt76x2_tx_common.c => mt76x2/tx.c} 
(99%)
 rename drivers/net/wireless/mediatek/mt76/{mt76x2_usb.c => mt76x2/usb.c} (99%)
 rename drivers/net/wireless/mediatek/mt76/{mt76x2u_core.c => 
mt76x2/usb_core.c} (95%)
 rename drivers/net/wireless/mediatek/mt76/{mt76x2u_init.c 

Re: [PATCH v3 00/29] staging: wilc1000: avoid static variables and cleanup changes

2018-10-01 Thread Dan Carpenter
On Tue, Sep 25, 2018 at 11:53:15AM +0530, Ajay Singh wrote:
> This patch series contains changes to avoid the use of static variables.
> Cleanup changes to fix some checkpatch issues and return void for
> function if their return value is not used.
> Also deleted 'wilc_debugfs.c' file as it's not used.
> 
> Changes since v2:
>Included Joe's suggestion for patch#28
> - replaced previous patch with an improved version(refactor code)
> 
> Changes since v1:
>Address Dan's comment for patch#29
> - return the correct error for failure in the second iteration

Btw, I hate re-reviewing patches and I know everyone hates sending them.
If someone complains about a 28/29 or a 29/29, then you can just ask
Greg to apply the first 27 and redo the others in a follow on patchset.

regards,
dan carpenter




[PATCH] lib80211: don't use skcipher

2018-10-01 Thread Johannes Berg
From: Johannes Berg 

Using skcipher just makes the code longer, and mac80211
also "open-codes" the WEP encrypt/decrypt.

Signed-off-by: Johannes Berg 
---
 net/wireless/lib80211_crypt_tkip.c | 59 +-
 net/wireless/lib80211_crypt_wep.c  | 52 +
 2 files changed, 40 insertions(+), 71 deletions(-)

diff --git a/net/wireless/lib80211_crypt_tkip.c 
b/net/wireless/lib80211_crypt_tkip.c
index e6bce1f130c9..b5e235573c8a 100644
--- a/net/wireless/lib80211_crypt_tkip.c
+++ b/net/wireless/lib80211_crypt_tkip.c
@@ -30,7 +30,7 @@
 #include 
 
 #include 
-#include 
+#include 
 #include 
 
 #include 
@@ -64,9 +64,9 @@ struct lib80211_tkip_data {
 
int key_idx;
 
-   struct crypto_skcipher *rx_tfm_arc4;
+   struct crypto_cipher *rx_tfm_arc4;
struct crypto_shash *rx_tfm_michael;
-   struct crypto_skcipher *tx_tfm_arc4;
+   struct crypto_cipher *tx_tfm_arc4;
struct crypto_shash *tx_tfm_michael;
 
/* scratch buffers for virt_to_page() (crypto API) */
@@ -99,8 +99,7 @@ static void *lib80211_tkip_init(int key_idx)
 
priv->key_idx = key_idx;
 
-   priv->tx_tfm_arc4 = crypto_alloc_skcipher("ecb(arc4)", 0,
- CRYPTO_ALG_ASYNC);
+   priv->tx_tfm_arc4 = crypto_alloc_cipher("arc4", 0, CRYPTO_ALG_ASYNC);
if (IS_ERR(priv->tx_tfm_arc4)) {
priv->tx_tfm_arc4 = NULL;
goto fail;
@@ -112,8 +111,7 @@ static void *lib80211_tkip_init(int key_idx)
goto fail;
}
 
-   priv->rx_tfm_arc4 = crypto_alloc_skcipher("ecb(arc4)", 0,
- CRYPTO_ALG_ASYNC);
+   priv->rx_tfm_arc4 = crypto_alloc_cipher("arc4", 0, CRYPTO_ALG_ASYNC);
if (IS_ERR(priv->rx_tfm_arc4)) {
priv->rx_tfm_arc4 = NULL;
goto fail;
@@ -130,9 +128,9 @@ static void *lib80211_tkip_init(int key_idx)
   fail:
if (priv) {
crypto_free_shash(priv->tx_tfm_michael);
-   crypto_free_skcipher(priv->tx_tfm_arc4);
+   crypto_free_cipher(priv->tx_tfm_arc4);
crypto_free_shash(priv->rx_tfm_michael);
-   crypto_free_skcipher(priv->rx_tfm_arc4);
+   crypto_free_cipher(priv->rx_tfm_arc4);
kfree(priv);
}
 
@@ -144,9 +142,9 @@ static void lib80211_tkip_deinit(void *priv)
struct lib80211_tkip_data *_priv = priv;
if (_priv) {
crypto_free_shash(_priv->tx_tfm_michael);
-   crypto_free_skcipher(_priv->tx_tfm_arc4);
+   crypto_free_cipher(_priv->tx_tfm_arc4);
crypto_free_shash(_priv->rx_tfm_michael);
-   crypto_free_skcipher(_priv->rx_tfm_arc4);
+   crypto_free_cipher(_priv->rx_tfm_arc4);
}
kfree(priv);
 }
@@ -344,12 +342,10 @@ static int lib80211_tkip_hdr(struct sk_buff *skb, int 
hdr_len,
 static int lib80211_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
 {
struct lib80211_tkip_data *tkey = priv;
-   SKCIPHER_REQUEST_ON_STACK(req, tkey->tx_tfm_arc4);
int len;
u8 rc4key[16], *pos, *icv;
u32 crc;
-   struct scatterlist sg;
-   int err;
+   int i;
 
if (tkey->flags & IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) {
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
@@ -374,14 +370,10 @@ static int lib80211_tkip_encrypt(struct sk_buff *skb, int 
hdr_len, void *priv)
icv[2] = crc >> 16;
icv[3] = crc >> 24;
 
-   crypto_skcipher_setkey(tkey->tx_tfm_arc4, rc4key, 16);
-   sg_init_one(, pos, len + 4);
-   skcipher_request_set_tfm(req, tkey->tx_tfm_arc4);
-   skcipher_request_set_callback(req, 0, NULL, NULL);
-   skcipher_request_set_crypt(req, , , len + 4, NULL);
-   err = crypto_skcipher_encrypt(req);
-   skcipher_request_zero(req);
-   return err;
+   crypto_cipher_setkey(tkey->tx_tfm_arc4, rc4key, 16);
+   for (i = 0; i < len + 4; i++)
+   crypto_cipher_encrypt_one(tkey->tx_tfm_arc4, pos + i, pos + i);
+   return 0;
 }
 
 /*
@@ -400,7 +392,6 @@ static inline int tkip_replay_check(u32 iv32_n, u16 iv16_n,
 static int lib80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
 {
struct lib80211_tkip_data *tkey = priv;
-   SKCIPHER_REQUEST_ON_STACK(req, tkey->rx_tfm_arc4);
u8 rc4key[16];
u8 keyidx, *pos;
u32 iv32;
@@ -408,9 +399,8 @@ static int lib80211_tkip_decrypt(struct sk_buff *skb, int 
hdr_len, void *priv)
struct ieee80211_hdr *hdr;
u8 icv[4];
u32 crc;
-   struct scatterlist sg;
int plen;
-   int err;
+   int i;
 
hdr = (struct ieee80211_hdr *)skb->data;
 
@@ -463,18 +453,9 @@ static int lib80211_tkip_decrypt(struct sk_buff *skb, int 
hdr_len, void *priv)
 
plen = skb->len - hdr_len - 12;
 
-