Re: [PATCH] WHENCE: Fix typo Version v3

2018-07-06 Thread Luciano Coelho
Hi,

On Thu, 2018-05-17 at 17:20 +0200, Sedat Dilek wrote:
> I have seen that in the WHENCE file there is "Version" with and
> without ":", mostly iwlwifi ucodes.
> 
> As an example:
> 
>  File: iwlwifi-8265-36.ucode
> -Version 36.e91976c0.0
> +Version: 36.e91976c0.0
> 
> The usual case is "Version:".
> 
> This patch is against iwlwifi.git#linux-firmware.
> 
> Signed-off-by: Sedat Dilek 
> ---

Looks fine, but I guess you should base this on linux-firmware.git and
send it to linux-firmw...@vger.kernel.org.

--
Cheers,
Luca.


Re: [PATCH] brcmfmac: specify some features per firmware version

2018-07-06 Thread Arend van Spriel

resending without HTML...

On 7/4/2018 10:31 PM, Rafał Miłecki wrote:

From: Rafał Miłecki 

Some features supported by firmware aren't advertised and there is no
way for a driver to query them. This includes e.g. monitor mode details.

Most firmwares support monitor interface but only the latest ones
/announce/ it with a "monitor" flag in the "cap" iovar. There isn't any
reliable detection method for older firmwares (BRCMF_C_MONITOR was tried
but "it only indicates the core part of the stack supports").

Similarly support for tagging monitor frames and building radiotap
headers can't be reliably detected for all firmwares.

This commit adds table that allows mapping features to firmware version.
It adds mappings for 43602a1 and 4366b1 firmwares from
linux-firmware.git. Both were confirmed to be passing monitor frames.


Reviewed-by: Arend van Spriel 

Signed-off-by: Rafał Miłecki 
---
  .../wireless/broadcom/brcm80211/brcmfmac/feature.c | 38 ++
  1 file changed, 38 insertions(+)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c 
b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c
index 4db4d07a..ab1d9eb1e9dc 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c
@@ -93,6 +93,42 @@ static int brcmf_feat_debugfs_read(struct seq_file *seq, 
void *data)
  }
  #endif /* DEBUG */

+struct brcmf_feat_fwfeat {
+   const char * const fwid;
+   u32 feat_flags;
+};
+
+static const struct brcmf_feat_fwfeat brcmf_feat_fwfeat_map[] = {
+   /* brcmfmac43602-pcie.ap.bin from linux-firmware.git ea1178515b88 */
+   { "01-6cb8e269", BIT(BRCMF_FEAT_MONITOR) },
+   /* brcmfmac4366b-pcie.bin from linux-firmware.git 52442afee990 */
+   { "01-c47a91a4", BIT(BRCMF_FEAT_MONITOR) },
+};


Not sure if people will realize what the sha1 implies here. Can we just 
drop the comments here?


Regards,
Arend


Re: [PATCH v2 12/12] mt76: Kconfig and Makefile for mt76x0 driver

2018-07-06 Thread kbuild test robot
Hi Stanislaw,

I love your patch! Perhaps something to improve:

[auto build test WARNING on wireless-drivers-next/master]
[also build test WARNING on v4.18-rc3 next-20180706]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Stanislaw-Gruszka/mt76-add-more-states/20180706-200412
base:   
https://git.kernel.org/pub/scm/linux/kernel/git/kvalo/wireless-drivers-next.git 
master
reproduce:
# apt-get install sparse
make ARCH=x86_64 allmodconfig
make C=1 CF=-D__CHECK_ENDIAN__


sparse warnings: (new ones prefixed by >>)

>> drivers/net/wireless/mediatek/mt76/mt76x0/mcu.c:253:15: sparse: expression 
>> using sizeof(void)
>> drivers/net/wireless/mediatek/mt76/mt76x0/mcu.c:253:15: sparse: expression 
>> using sizeof(void)
   drivers/net/wireless/mediatek/mt76/mt76x0/mcu.c:282:15: sparse: expression 
using sizeof(void)
   drivers/net/wireless/mediatek/mt76/mt76x0/mcu.c:282:15: sparse: expression 
using sizeof(void)
   drivers/net/wireless/mediatek/mt76/mt76x0/mcu.c:325:15: sparse: expression 
using sizeof(void)
   drivers/net/wireless/mediatek/mt76/mt76x0/mcu.c:325:15: sparse: expression 
using sizeof(void)
   drivers/net/wireless/mediatek/mt76/mt76x0/mcu.c:354:15: sparse: expression 
using sizeof(void)
   drivers/net/wireless/mediatek/mt76/mt76x0/mcu.c:354:15: sparse: expression 
using sizeof(void)
>> drivers/net/wireless/mediatek/mt76/mt76x0/mcu.c:344:5: sparse: symbol 
>> 'mt76x0_burst_read_regs' was not declared. Should it be static?
   drivers/net/wireless/mediatek/mt76/mt76x0/mcu.c:463:13: sparse: expression 
using sizeof(void)
--
>> drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c:88:27: sparse: Variable 
>> length array is used.
--
>> drivers/net/wireless/mediatek/mt76/mt76x0/phy.c:969:34: sparse: expression 
>> using sizeof(void)
>> drivers/net/wireless/mediatek/mt76/mt76x0/phy.c:989:6: sparse: symbol 
>> 'mt76x0_ant_select' was not declared. Should it be static?
--
>> drivers/net/wireless/mediatek/mt76/mt76x0/mac.c:88:21: sparse: expression 
>> using sizeof(void)
   drivers/net/wireless/mediatek/mt76/mt76x0/mac.c:97:31: sparse: expression 
using sizeof(void)
>> drivers/net/wireless/mediatek/mt76/mt76x0/mac.c:166:16: sparse: incorrect 
>> type in return expression (different base types) @@expected unsigned 
>> short @@got restricted __leunsigned short @@
   drivers/net/wireless/mediatek/mt76/mt76x0/mac.c:166:16:expected unsigned 
short
   drivers/net/wireless/mediatek/mt76/mt76x0/mac.c:166:16:got restricted 
__le16 [usertype] 
>> drivers/net/wireless/mediatek/mt76/mt76x0/mac.c:175:23: sparse: incorrect 
>> type in assignment (different base types) @@expected restricted __le16 
>> [usertype] tx_rate @@got 16 [usertype] tx_rate @@
   drivers/net/wireless/mediatek/mt76/mt76x0/mac.c:175:23:expected 
restricted __le16 [usertype] tx_rate
   drivers/net/wireless/mediatek/mt76/mt76x0/mac.c:175:23:got unsigned short
   drivers/net/wireless/mediatek/mt76/mt76x0/mac.c:438:30: sparse: expression 
using sizeof(void)
   drivers/net/wireless/mediatek/mt76/mt76x0/mac.c:438:30: sparse: expression 
using sizeof(void)
--
>> drivers/net/wireless/mediatek/mt76/mt76x0/tx.c:93:26: sparse: incorrect type 
>> in assignment (different base types) @@expected unsigned short 
>> [unsigned] [usertype] rate_ctl @@got  short [unsigned] [usertype] 
>> rate_ctl @@
   drivers/net/wireless/mediatek/mt76/mt76x0/tx.c:93:26:expected unsigned 
short [unsigned] [usertype] rate_ctl
   drivers/net/wireless/mediatek/mt76/mt76x0/tx.c:93:26:got restricted 
__le16 [usertype] tx_rate
>> drivers/net/wireless/mediatek/mt76/mt76x0/tx.c:126:27: sparse: expression 
>> using sizeof(void)

Please review and possibly fold the followup patch.

vim +253 drivers/net/wireless/mediatek/mt76/mt76x0/mcu.c

9b00fd07 Stanislaw Gruszka 2018-07-06  242  
9b00fd07 Stanislaw Gruszka 2018-07-06  243  int mt76x0_write_reg_pairs(struct 
mt76x0_dev *dev, u32 base,
9b00fd07 Stanislaw Gruszka 2018-07-06  244 const struct 
mt76_reg_pair *data, int n)
9b00fd07 Stanislaw Gruszka 2018-07-06  245  {
9b00fd07 Stanislaw Gruszka 2018-07-06  246  const int max_vals_per_cmd = 
INBAND_PACKET_MAX_LEN / 8;
9b00fd07 Stanislaw Gruszka 2018-07-06  247  struct sk_buff *skb;
9b00fd07 Stanislaw Gruszka 2018-07-06  248  int cnt, i, ret;
9b00fd07 Stanislaw Gruszka 2018-07-06  249  
9b00fd07 Stanislaw Gruszka 2018-07-06  250  if (!n)
9b00fd07 Stanislaw Gruszka 2018-07-06  251  return 0;
9b00fd07 Stanislaw Gruszka 2018-07-06  252  
9b00fd07 Stanislaw Gruszka 2018-07-06 @253  cnt = min(max_vals_per_cmd, n);
9b00fd07 Stanislaw Gruszka 2018-07-06  254  
9b00fd07 Stanislaw Gruszka 2018-07-06  255  skb = alloc_skb(cn

[RFC PATCH] mt76: mt76x0_burst_read_regs() can be static

2018-07-06 Thread kbuild test robot


Fixes: c1f1ff1a3d63 ("mt76: Kconfig and Makefile for mt76x0 driver")
Signed-off-by: kbuild test robot 
---
 mcu.c |4 ++--
 phy.c |2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/mcu.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/mcu.c
index aafa3f3..0c9da79 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/mcu.c
@@ -341,8 +341,8 @@ int mt76x0_burst_write_regs(struct mt76x0_dev *dev, u32 
offset,
data + cnt, n - cnt);
 }
 
-int mt76x0_burst_read_regs(struct mt76x0_dev *dev, u32 base,
-  struct mt76_reg_pair *data, int n)
+static int mt76x0_burst_read_regs(struct mt76x0_dev *dev, u32 base,
+ struct mt76_reg_pair *data, int n)
 {
const int max_vals_per_cmd = INBAND_PACKET_MAX_LEN / 4 - 1;
struct sk_buff *skb;
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
index 0830280..e52a506 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
@@ -986,7 +986,7 @@ mt76x0_rf_init(struct mt76x0_dev *dev)
rf_set(dev, MT_RF(0, 4), 0x80);
 }
 
-void mt76x0_ant_select(struct mt76x0_dev *dev)
+static void mt76x0_ant_select(struct mt76x0_dev *dev)
 {
/* Single antenna mode. */
mt76_rmw(dev, MT_WLAN_FUN_CTRL, BIT(5), BIT(6));


Re: [PATCH 00/27] mtd: rawnand: Improve compile-test coverage

2018-07-06 Thread Richard Weinberger
Am Donnerstag, 5. Juli 2018, 12:25:42 CEST schrieb Geert Uytterhoeven:
> Hi Boris,
> 
> On Thu, Jul 5, 2018 at 12:09 PM Boris Brezillon
>  wrote:
> > This is an attempt at adding "depends || COMPILE_TEST" to all NAND
> > drivers that have no compile-time dependencies on arch
> > features/headers.
> >
> > This will hopefully help us (NAND/MTD maintainers) in detecting build
> > issues earlier. Unfortunately we still have a few drivers that can't
> > easily be modified to be arch independent.
> >
> > I tried to put all patches that only touch the NAND subsystem first,
> > so that they can be applied even if other patches are being discussed.
> >
> > Don't hesitate to point any missing dependencies when compiled with
> > COMPILE_TEST. I didn't have any problem when compiling, but that might
> > be because the dependencies were already selected.
> >
> > I have Question for Geert. I know you worked on HAS_DMA removal when
> > combined with COMPILE_TEST, do you plan to do something similar with
> > HAS_IOMEM?
> 
> No plans for that.
> 
> NO_IOMEM is Richard's itch, now s390 has gained PCI support.

Since COMPILE_TEST depends on !UML not so much anymore :-)

> NO_DMA matters for UML and Sun-3.

Yeah.

Thanks,
//richard


Re: [PATCH 21/27] bcma: Allow selection of this driver when COMPILE_TEST=y

2018-07-06 Thread Boris Brezillon
On Fri, 06 Jul 2018 17:32:50 +0300
Kalle Valo  wrote:

> Boris Brezillon  writes:
> 
> > This allows us to increase compile-test coverage without having to build
> > a kernel for MIPS.  That's particularly interesting for subsystem
> > maintainers that want to test as many drivers as possible in a single
> > build.
> >
> > We also add a dependency on HAS_IOMEM in BCMA_HOST_SOC to make sure the
> > driver is not selected when the arch does not implement IO accessors.
> >
> > Signed-off-by: Boris Brezillon 
> > ---
> >  drivers/bcma/Kconfig | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)  
> 
> Acked-by: Kalle Valo 
> 
> I assume this patch will go via some other tree and I can drop it.
> 

Yep. We can create an immutable tag if needed.


Re: [PATCH 21/27] bcma: Allow selection of this driver when COMPILE_TEST=y

2018-07-06 Thread Kalle Valo
Boris Brezillon  writes:

> This allows us to increase compile-test coverage without having to build
> a kernel for MIPS.  That's particularly interesting for subsystem
> maintainers that want to test as many drivers as possible in a single
> build.
>
> We also add a dependency on HAS_IOMEM in BCMA_HOST_SOC to make sure the
> driver is not selected when the arch does not implement IO accessors.
>
> Signed-off-by: Boris Brezillon 
> ---
>  drivers/bcma/Kconfig | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

Acked-by: Kalle Valo 

I assume this patch will go via some other tree and I can drop it.

-- 
Kalle Valo


iwlwifi is not working after doing the reboot by pressing RESET button

2018-07-06 Thread Palanisamy, Rameshbabu
Hi Team,


I am using intel 8265 NGW wifi card in intel leafhill board.

We have enabled the Intel -wifi card in the Leaf_hill platform. After powering 
on the device, the wifi module is working fine but it doesn't work when we do 
the reboot by pressing RESET button.
We have debug the issue and found that  when we do the hard reboot by pressing 
the RESET key, the wifi module doesn't detected.
We have given the  lspci command before and after the hard reboot and the 
module is not listing in the lspci after hard reboot so we are suspecting that 
wifi module is not in the proper state due to the hard reboot.
Could you please help to know what might be the issue.


Thanks,
Ramesh


Re: [PATCH] cfg80211: inspect off channel operation only when off channel given

2018-07-06 Thread Johannes Berg
On Tue, 2018-07-03 at 16:04 -0700, peter...@bowerswilkins.com wrote:
> From: Peter Oh 
> 
> NL80211_ATTR_OFFCHANNEL_TX_OK does not mean given channel is always
> off channel, but it means the channel given could be off channel.
> Hence it should not block the given channel to be used if given
> channel does not require off channel mgmt tx although regulatory
> domain is non-ETSI.
> 
> Signed-off-by: Peter Oh 
> ---
>  net/wireless/nl80211.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
> index 4eece06..991042b 100644
> --- a/net/wireless/nl80211.c
> +++ b/net/wireless/nl80211.c
> @@ -9915,7 +9915,9 @@ static int nl80211_tx_mgmt(struct sk_buff *skb, struct 
> genl_info *info)
>   return -EINVAL;
>  
>   wdev_lock(wdev);
> - if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) {
> + if (params.offchan &&
> + !cfg80211_chandef_identical(, >chandef) &&
> + !cfg80211_off_channel_oper_allowed(wdev)) {
>   wdev_unlock(wdev);

Hmm. That seems fine, but can we be sure that wdev->chandef is always
valid? ISTR that it isn't necessarily updated all the time, but I can't
really say right now.

johannes


[[PATCH v2]] mac80211_hwsim: Add support for HE

2018-07-06 Thread Luca Coelho
From: Ilan Peer 

Add support for HE in mac8011_hwsim, conforming with P802.11ax_D2.0.

Signed-off-by: Liad Kaufman 
Signed-off-by: Ilan Peer 
Signed-off-by: Luca Coelho 
---

In V2:

I fixed compilation issues with the symbols I changed in
mac80211's patches, namely:

* s/_msc_/_mcs_/
* s/types/types_mask/

 drivers/net/wireless/mac80211_hwsim.c | 123 ++
 1 file changed, 123 insertions(+)

diff --git a/drivers/net/wireless/mac80211_hwsim.c 
b/drivers/net/wireless/mac80211_hwsim.c
index 9825bfd42abc..6126d5ce25ad 100644
--- a/drivers/net/wireless/mac80211_hwsim.c
+++ b/drivers/net/wireless/mac80211_hwsim.c
@@ -2,6 +2,7 @@
  * mac80211_hwsim - software simulator of 802.11 radio(s) for mac80211
  * Copyright (c) 2008, Jouni Malinen 
  * Copyright (c) 2011, Javier Lopez 
+ * Copyright (c) 2016 - 2017 Intel Deutschland GmbH
  *
  * 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
@@ -2517,6 +2518,123 @@ static void hwsim_mcast_new_radio(int id, struct 
genl_info *info,
nlmsg_free(mcast_skb);
 }
 
+static const struct ieee80211_sband_iftype_data he_capa_2ghz = {
+   /* TODO: should we support other types, e.g., P2P?*/
+   .types_mask = BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP),
+   .he_cap = {
+   .has_he = true,
+   .he_cap_elem = {
+   .mac_cap_info[0] =
+   IEEE80211_HE_MAC_CAP0_HTC_HE,
+   .mac_cap_info[1] =
+   IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US |
+   IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_QOS_8,
+   .mac_cap_info[2] =
+   IEEE80211_HE_MAC_CAP2_BSR |
+   IEEE80211_HE_MAC_CAP2_MU_CASCADING |
+   IEEE80211_HE_MAC_CAP2_ACK_EN,
+   .mac_cap_info[3] =
+   
IEEE80211_HE_MAC_CAP3_GRP_ADDR_MULTI_STA_BA_DL_MU |
+   IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
+   IEEE80211_HE_MAC_CAP3_MAX_A_AMPDU_LEN_EXP_VHT_2,
+   .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMDSU_IN_AMPDU,
+   .phy_cap_info[0] =
+   IEEE80211_HE_PHY_CAP0_DUAL_BAND,
+   .phy_cap_info[1] =
+   IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK |
+   IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
+   IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD |
+   IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_MAX_NSTS,
+   .phy_cap_info[2] =
+   IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US |
+   IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ |
+   IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ |
+   IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO |
+   IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO,
+
+   /* Leave all the other PHY capability bytes unset, as
+* DCM, beam forming, RU and PPE threshold information
+* are not supported
+*/
+   },
+   .he_mcs_nss_supp = {
+   .rx_mcs_80 = cpu_to_le16(0xfffa),
+   .tx_mcs_80 = cpu_to_le16(0xfffa),
+   .rx_mcs_160 = cpu_to_le16(0x),
+   .tx_mcs_160 = cpu_to_le16(0x),
+   .rx_mcs_80p80 = cpu_to_le16(0x),
+   .tx_mcs_80p80 = cpu_to_le16(0x),
+   },
+   },
+};
+
+static const struct ieee80211_sband_iftype_data he_capa_5ghz = {
+   /* TODO: should we support other types, e.g., P2P?*/
+   .types_mask = BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP),
+   .he_cap = {
+   .has_he = true,
+   .he_cap_elem = {
+   .mac_cap_info[0] =
+   IEEE80211_HE_MAC_CAP0_HTC_HE,
+   .mac_cap_info[1] =
+   IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US |
+   IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_QOS_8,
+   .mac_cap_info[2] =
+   IEEE80211_HE_MAC_CAP2_BSR |
+   IEEE80211_HE_MAC_CAP2_MU_CASCADING |
+   IEEE80211_HE_MAC_CAP2_ACK_EN,
+   .mac_cap_info[3] =
+   
IEEE80211_HE_MAC_CAP3_GRP_ADDR_MULTI_STA_BA_DL_MU |
+   IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
+   IEEE80211_HE_MAC_CAP3_MAX_A_AMPDU_LEN_EXP_VHT_2,
+   

Re: Proper SET_KEY usage?

2018-07-06 Thread Johannes Berg
Hi,

> > Yeah. This stuff grew out of WEXT mostly, and what things wpa_s did at
> > the time...
> 
> Right.  My main intent with this was to see if I could understand things 
> enough to actually start fixing some of the docs, see if we need to 
> deprecate some things and/or maybe fix bits inside nl80211.

:-)
That'd be very welcome!

> So it sounds like SET_KEY is completely unnecessary for a unicast key in 
> an RSN/WPA association for an STA.  Should we update mac80211 (and 
> possibly nl80211, though likely it doesn't have enough info) to issue a 
> warning when someone tries to use set_key on such a key?

I'm not sure I see much point, since we'll have to deal with older wpa_s
basically forever?

> What about AP/IBSS?  Aren't unicast keys also per-station in this case? 
> It sounds like SET_KEY isn't useful in this context either, right?

Yes, same situation really.

> What about WEP?

WEP is a special case, you typically use the same key for all traffic,
and may switch around between them.

In theory though, and I think this API allows you to do it, you can have
multiple WEP keys and use different ones for unicast/multicast TX. Or
the same. Or switch them around as you like.

> Put another way, should we deprecate the whole 
> NL80211_KEY_DEFAULT_TYPE_UNICAST attribute?

Perhaps. I'm not sure I see much point in it. The WEP case above is
pretty fringe, and wext didn't support it, so ... probably not needed?

> And since you went off on a tangent (maybe this needs a separate 
> discussion?) but... Can you elaborate about PTK rekeying with a non-zero 
> key index?  Are you saying that in IBSS/AP mode we can't support PTK rekey?

We can't properly support PTK rekeying in any mode, see Alexander
Wetzel's patch and the whole discussion on the different versions I had
with him. I'll merge his patch soon I think, but it doesn't really work
properly.

Some time relatively recently (802.11-2016 I think) the spec has
introduced a method to indicate that you support what was previously not
allowed at all: using non-zero key index for a PTK. This way, you can do
transparent PTK rekeying like you do with GTK now, by switching to a new
key index when you rekey.

We don't - currently - support this in mac80211 or even wpa_supplicant,
and I expect many devices would have issues with this with hardware
offload. I'm also not aware of any certification program for it, but I
also haven't followed the WPA3 efforts (but I don't think they're
focused here, they're focused on algorithms and higher layers IIRC.)

> > (The difference between them is that in IBSS you will have per-station
> > GTKs, but that's also irrelevant because those are only used for RX -
> > your own GTK on the netdev/wdev/sdata/vif level is used for TX.)
> 
> Okay, so for GTKs we would have a per-station RX GTK and a 'default' TX 
> GTK.  So in this case a SET_KEY would be needed only on the 'default' TX 
> GTK index.
> 
> Okay, maybe a tangent, but this brings up a question: Why do we have 
> separate steps for this operation?  Can't we just issue a NEW_KEY and 
> have the kernel figure this out?

I think the only case would be WEP?

> Well, that's what I was pointing out earlier, the whole Multicast 
> attribute is ignored and should not be sent in the first place:
> 
>  >>   Key Default Types: len 4
>  >>   Multicast: true
> 
> The proof :) follows:

:)

> So while nl80211_new_key actually parses this information (stored in 
> struct key_parse) it never forwards any of it to the driver.  The group 
> key vs pairwise key determination seems to be predicated on presence of 
> NL80211_ATTR_KEY_TYPE and the following fallback:
> 
>  if (key.type == -1) {
>  if (mac_addr)
>  key.type = NL80211_KEYTYPE_PAIRWISE;
>  else
>  key.type = NL80211_KEYTYPE_GROUP;
>  }

Yeah.

> Okay, so the drivers are expected to distinguish between a GTK and IGTK 
> based on the cipher type, right?

Not needed, IGTK also uses key index 4/5, while GTK uses 0-3.

> So do we need a driver feature bit for NL80211_ATTR_KEY_DEFAULT_MGMT?

I don't see why, the driver should support it if it has support for IGTK
in the first place? And for AP mode, since otherwise it doesn't matter
(IGTK like GTK is RX-only for the client)

> Okay, so to summarize, SET_KEY should only be called on GTK/IGTK keys 
> which are not per-MAC.  So in IBSS/AP mode we set this for our transmit 
> GTK/IGTK key.

I suspect you don't even *need* SET_KEY on GTK/IGTK since they're set to
be TX when installed, I think?

> In IBSS mode, SET_KEY on peer's GTK shouldn't be issued.  In fact it may 
> even be an error to do so since we might be messing with the wrong key 
> unintentionally.

I don't think we would mess with the wrong key, since we need to give
the station MAC address and then it's not our TX key. But certainly
doing SET_KEY for a GTK that you expect to *receive* with isn't useful.

> So I'd like 

Re: [linuxwifi] iwlwifi is not working after doing the reboot by pressing RESET button

2018-07-06 Thread Luciano Coelho
HTML emails don't go through to the mailing lists at vger.kernel.org,
so please don't use HTML.

On Fri, 2018-07-06 at 08:40 +, Palanisamy, Rameshbabu wrote:
> Hi Team,
>  
>  
> I am using intel 8265 NGW wifi card in intel leafhill board.
>  
> We have enabled the Intel -wifi card in the Leaf_hill platform. After
> powering on the device, the wifi module is working fine but it
> doesn’t work when we do the reboot by pressing RESET button.
> We have debug the issue and found that  when we do the hard reboot by
> pressing the RESET key, the wifi module doesn’t detected.
> We have given the  lspci command before and after the hard reboot and
> the module is not listing in the lspci after hard reboot so we are
> suspecting that wifi module is not in the proper state due to the
> hard reboot.
> Could you please help to know what might be the issue.

This really sounds like a platform issue and not an iwlwifi/pci issue. 
For some reason your reset is leaving the NIC in a bad state.  Please
take it with whoever is providing this platform to you.

--
Cheers,
Luca.


Re: [PATCH 1/7] wireless: Change single cqm_config to rssi config list

2018-07-06 Thread Johannes Berg
On Wed, 2018-07-04 at 23:46 +0530, Tamizh chelvam wrote:

> > > - struct cfg80211_cqm_config *cqm_config;
> > > + struct cfg80211_rssi_config *rssi_config;
> > > + struct list_head rssi_config_list;
> > 
> > Why do you need both now? Perhaps instead you should allow a NULL/all-
> > ones MAC address for where you have the direct pointer now, and remove
> > that? You anyway need to pass something to the peer argument in
> > 
> 
> In the current cqm/sta_mon implementation the range_config will be 
> updated before notify event posted to userspace.
> To update the range config for a specific station we need to have this 
> peer addr based configuration list which holds the thresholds info
> to choose the next rssi range.
> Or do you want me to handle and store the rssi_config structure in 
> mac80211 and update it in mac80211 itself ? And simply pass the 
> notification event to userspace application ?

I don't have any issues with storing it in mac80211 - could attach it to
the station entry there?

Come to think of it, that might also clarify the lifetime rules. As it
is now, what if the station is removed? What are the lifetime rules for
a per-station configuration?

It would almost look like it stays here (or maybe I missed when you
remove it from the list when a station is removed), but that doesn't
seem like a good idea.

Please document the lifetime rules also in the API, and make sure you
implement them properly.

> > What's the locking scheme for this? It's way more complex now so 
> > perhaps stick ASSERT_RTNL() in there or so?
> > 
> 
> Isn't wdev_lock enough ?

I guess it should be :-) Maybe assert on that, also to document the
locking rules.

> > >   /* RSSI reporting disabled? */
> > > - if (!wdev->cqm_config)
> > > + if (!wdev->rssi_config)
> > >   return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0);
> > 
> > 
> > So I guess the wdev->rssi_config is used for the case of "always use
> > this config for any AP you're connected to" or so - but maybe it'd be
> > better to track the AP as a station? Then again, I guess we can't force
> > userspace to change that.

> Sorry I didn't get your point:( I didn't change anything in the station 
> mode. Functionality remains same for the station mode.

Right, that sort of goes back to my thoughts about lifetime rules too.
The rule for stations would be to have it deleted when the station is
deleted, but I guess the rule for client-mode is to keep the config
active even when roaming?

I was just thinking that you don't need to *store* it like that, you
could still - in client mode - store the configuration treating the AP
as a (peer) station, perhaps with an ff:ff:ff:ff:ff:ff MAC address or
something (instead of using the BSSID, to get lifetime rules adjusted
right).

But now that I'm thinking about how the lifetime rules differ ... that's
probably not worth it.

> > >   wdev_lock(wdev);
> > >   if (n_thresholds) {
> > > - struct cfg80211_cqm_config *cqm_config;
> > > -
> > > - cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) +
> > > -  n_thresholds * sizeof(s32), GFP_KERNEL);
> > > - if (!cqm_config) {
> > > + wdev->rssi_config = cfg80211_get_rssi_config(
> > > + wdev, thresholds,
> > > + n_thresholds, hysteresis,
> > > + wdev->current_bss->pub.bssid);
> > 
> > Here you link it to the BSSID anyway, but do we always have a
> > current_bss at this point?
> > 
> 
> Oops! I didn't think about that condition. I'll fix that in the next 
> version.

Again though - see above. I'm not sure it's even correct to link it to
the BSSID since until now, I think the configuration would remain across
roaming?

johannes


Re: [PATCH 2/7] cfg80211: Add new NL command to configure peer specific rssi threshold

2018-07-06 Thread Johannes Berg
On Wed, 2018-07-04 at 11:39 +0530, Tamizh chelvam wrote:
> On 2018-06-29 14:59, Johannes Berg wrote:
> > On Wed, 2018-06-13 at 16:15 +0530, Tamizh chelvam wrote:
> > > 
> > > + * @NL80211_ATTR_STA_MON: Station's connection monitor configuration 
> > > in a
> > > + *   nested attribute with %NL80211_ATTR_STA_MON_* sub-attributes.
> > 
> > Can't we reuse the existing attributes in this nesting?
> 
> This new attributes introduced as per the previous discussion.
> https://patchwork.kernel.org/patch/10240697/
> Is my understanding correct ?

Yeah ok ... I'm thinking perhaps we could share some part of it, but
it's not really worth making it more complex due to that.

> > Wait, you went to all this effort in the first patch and now you don't
> > add this to the list?
> > 
> No, the list and the rssi_config structure is for multi threshold value 
> and not for single threshold.

Yeah, though I'm still not sure why we need the single threshold thing
at all. List should always be a superset.

johannes


Re: [PATCH 4/7] cfg80211: Add support to notify station's rssi level crossing

2018-07-06 Thread Johannes Berg
On Wed, 2018-07-04 at 11:43 +0530, Tamizh chelvam wrote:

> > > --- a/include/uapi/linux/nl80211.h
> > > +++ b/include/uapi/linux/nl80211.h
> > > @@ -1249,6 +1249,7 @@ enum nl80211_commands {
> > >   NL80211_CMD_CONTROL_PORT_FRAME,
> > > 
> > >   NL80211_CMD_SET_STA_MON,
> > > + NL80211_CMD_NOTIFY_STA_MON,
> > 
> > Missing documentation - but again, why not unify it with the existing
> > event? Or can't we because that might confuse older applications?
> > Perhaps anyway we should unicast these notifications? Not sure though,
> > perhaps one app could set them up and the other might care?
> > 
> 
> This new command introduced as per the previous discussion
> https://patchwork.kernel.org/patch/10168685/
> https://patchwork.kernel.org/patch/10240697/
> 
> Is my understanding correct ?

I guess you're right. To my defense, this was like almost half a year
ago :)

> I just referred this code from cfg80211_prepare_cqm. Do you want me to 
> change this to struct based?

Please, I guess we can fix up cqm too later.

johannes


Re: [PATCH 6/7] cfg80211: Accept multiple RSSI threholds for STA_MON command

2018-07-06 Thread Johannes Berg
On Thu, 2018-07-05 at 13:07 +0530, Tamizh chelvam wrote:

> First I've done patch to have single threshold value for AP mode and as 
> per the previous discussion extended to multiple thresholds also. Here 
> the intention is to accept one or more than one RSSI thresholds to 
> monitor. Any thought ?

Is there any point in even offering the API for a single one though? I
mean - we only implement it in mac80211 now, and there we clearly
implement multiple, so single would never be used.

Like I said:

> > Or do you expect somebody to actually really need the single threshold
> > in the near future?

johannes


Re: [PATCH 00/11] Add mt76x0 driver

2018-07-06 Thread Lorenzo Bianconi
On Jul 06, Stanislaw Gruszka wrote:
> On Thu, Jul 05, 2018 at 05:32:17PM +0200, Lorenzo Bianconi wrote:
> > > My integration efforts can be traced here:
> > > https://github.com/sgruszka/wireless-drivers-next/commits/mt76x0-draft
> > > 
> > 
> > I just had a brief review of the code and I compiled the driver since at
> > the moment I had no adapter for that chipset.
> > As a remainder for future improvements/integration most of the code in 
> > dma.c, usb.c (except probe/disconnect functions) and tx.c can use the 
> > related
> > routines in the mt76-usb layer (we need to fill function pointer for chipset
> > related stuff if there are differences with mt76x2u, not looked yet).
> > Moreover mcu code can use utility routines in usb-mcu.c
> > I have not looked at mt76x2 common code yet.
> 
> That's my plan. So far I started to unify common mac/wcid code. If
> someone want to work on some area i.e. dma/tx, usb or mcu, please
> let me know to do not duplicate work.  

I can work on dma/tx/usb stuff since I did it for mt76x2u.
I have just a mt7601u adapter for the moment but I guess
I can use it that tasks.

Regards,
Lorenzo

> 
> Thanks for review!
> Stanislaw


[PATCH v2 01/12] mt76: add more states

2018-07-06 Thread Stanislaw Gruszka
Add states needed for mt76x0 driver.

Signed-off-by: Stanislaw Gruszka 
---
 drivers/net/wireless/mediatek/mt76/mt76.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h 
b/drivers/net/wireless/mediatek/mt76/mt76.h
index 96e9798bb8a0..7b50d4b7f40e 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76.h
@@ -187,9 +187,13 @@ struct mt76_rx_tid {
 enum {
MT76_STATE_INITIALIZED,
MT76_STATE_RUNNING,
+   MT76_STATE_MCU_RUNNING,
MT76_SCANNING,
MT76_RESET,
MT76_OFFCHANNEL,
+   MT76_REMOVED,
+   MT76_READING_STATS,
+   MT76_MORE_STATS,
 };
 
 struct mt76_hw_cap {
-- 
1.9.3



[PATCH v2 07/12] mt76x0: init files

2018-07-06 Thread Stanislaw Gruszka
Add init files of mt76x0 driver.

Signed-off-by: Stanislaw Gruszka 
---
 drivers/net/wireless/mediatek/mt76/mt76x0/init.c   | 720 +
 .../net/wireless/mediatek/mt76/mt76x0/initvals.h   | 282 
 2 files changed, 1002 insertions(+)
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/init.c
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/initvals.h

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/init.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/init.c
new file mode 100644
index ..b65b76d80906
--- /dev/null
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/init.c
@@ -0,0 +1,720 @@
+/*
+ * (c) Copyright 2002-2010, Ralink Technology, Inc.
+ * Copyright (C) 2014 Felix Fietkau 
+ * Copyright (C) 2015 Jakub Kicinski 
+ * Copyright (C) 2018 Stanislaw Gruszka 
+ *
+ * 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 "eeprom.h"
+#include "trace.h"
+#include "mcu.h"
+#include "usb.h"
+
+#include "initvals.h"
+
+static void
+mt76x0_set_wlan_state(struct mt76x0_dev *dev, u32 val, bool enable)
+{
+   int i;
+
+   /* Note: we don't turn off WLAN_CLK because that makes the device
+*   not respond properly on the probe path.
+*   In case anyone (PSM?) wants to use this function we can
+*   bring the clock stuff back and fixup the probe path.
+*/
+
+   if (enable)
+   val |= (MT_WLAN_FUN_CTRL_WLAN_EN |
+   MT_WLAN_FUN_CTRL_WLAN_CLK_EN);
+   else
+   val &= ~(MT_WLAN_FUN_CTRL_WLAN_EN);
+
+   mt76_wr(dev, MT_WLAN_FUN_CTRL, val);
+   udelay(20);
+
+   if (!enable)
+   return;
+
+   for (i = 200; i; i--) {
+   val = mt76_rr(dev, MT_CMB_CTRL);
+
+   if (val & MT_CMB_CTRL_XTAL_RDY && val & MT_CMB_CTRL_PLL_LD)
+   break;
+
+   udelay(20);
+   }
+
+   /* Note: vendor driver tries to disable/enable wlan here and retry
+*   but the code which does it is so buggy it must have never
+*   triggered, so don't bother.
+*/
+   if (!i)
+   dev_err(dev->mt76.dev, "Error: PLL and XTAL check failed!\n");
+}
+
+static 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) {
+   val |= MT_WLAN_FUN_CTRL_GPIO_OUT_EN;
+   val &= ~MT_WLAN_FUN_CTRL_FRC_WL_ANT_SEL;
+
+   if (val & MT_WLAN_FUN_CTRL_WLAN_EN) {
+   val |= (MT_WLAN_FUN_CTRL_WLAN_RESET |
+   MT_WLAN_FUN_CTRL_WLAN_RESET_RF);
+   mt76_wr(dev, MT_WLAN_FUN_CTRL, val);
+   udelay(20);
+
+   val &= ~(MT_WLAN_FUN_CTRL_WLAN_RESET |
+MT_WLAN_FUN_CTRL_WLAN_RESET_RF);
+   }
+   }
+
+   mt76_wr(dev, MT_WLAN_FUN_CTRL, val);
+   udelay(20);
+
+   mt76x0_set_wlan_state(dev, val, enable);
+
+   mutex_unlock(>hw_atomic_mutex);
+}
+
+static void mt76x0_reset_csr_bbp(struct mt76x0_dev *dev)
+{
+   u32 val;
+
+   val = mt76_rr(dev, MT_PBF_SYS_CTRL);
+   val &= ~0x2000;
+   mt76_wr(dev, MT_PBF_SYS_CTRL, val);
+
+   mt76_wr(dev, MT_MAC_SYS_CTRL, MT_MAC_SYS_CTRL_RESET_CSR |
+MT_MAC_SYS_CTRL_RESET_BBP);
+
+   msleep(200);
+}
+
+static void mt76x0_init_usb_dma(struct mt76x0_dev *dev)
+{
+   u32 val;
+
+   val = mt76_rr(dev, MT_USB_DMA_CFG);
+
+   val |= FIELD_PREP(MT_USB_DMA_CFG_RX_BULK_AGG_TOUT, MT_USB_AGGR_TIMEOUT) 
|
+  FIELD_PREP(MT_USB_DMA_CFG_RX_BULK_AGG_LMT, 
MT_USB_AGGR_SIZE_LIMIT) |
+  MT_USB_DMA_CFG_RX_BULK_EN |
+  MT_USB_DMA_CFG_TX_BULK_EN;
+   if (dev->in_max_packet == 512)
+   val |= MT_USB_DMA_CFG_RX_BULK_AGG_EN;
+   mt76_wr(dev, MT_USB_DMA_CFG, val);
+
+   val = mt76_rr(dev, MT_COM_REG0);
+   if (val & 1)
+   dev_dbg(dev->mt76.dev, "MCU not ready\n");
+
+   val = mt76_rr(dev, MT_USB_DMA_CFG);
+
+   val |= MT_USB_DMA_CFG_RX_DROP_OR_PADDING;
+   mt76_wr(dev, MT_USB_DMA_CFG, val);
+   val &= ~MT_USB_DMA_CFG_RX_DROP_OR_PADDING;
+   mt76_wr(dev, MT_USB_DMA_CFG, val);
+}
+
+#define RANDOM_WRITE(dev, tab) \
+   mt76x0_write_reg_pairs(dev, MT_MCU_MEMMAP_WLAN, tab, ARRAY_SIZE(tab));
+
+static int mt76x0_init_bbp(struct mt76x0_dev *dev)
+{
+   int ret, i;
+
+ 

[PATCH v2 11/12] mt76x0: main file

2018-07-06 Thread Stanislaw Gruszka
Add main file of mt76x0 driver.

Signed-off-by: Stanislaw Gruszka 
---
 drivers/net/wireless/mediatek/mt76/mt76x0/main.c | 403 +++
 1 file changed, 403 insertions(+)
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/main.c

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/main.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/main.c
new file mode 100644
index ..0c521f3485c9
--- /dev/null
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/main.c
@@ -0,0 +1,403 @@
+/*
+ * Copyright (C) 2014 Felix Fietkau 
+ * Copyright (C) 2015 Jakub Kicinski 
+ * Copyright (C) 2018 Stanislaw Gruszka 
+ *
+ * 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 "mac.h"
+#include 
+
+static int mt76x0_start(struct ieee80211_hw *hw)
+{
+   struct mt76x0_dev *dev = hw->priv;
+   int ret;
+
+   mutex_lock(>mutex);
+
+   ret = mt76x0_mac_start(dev);
+   if (ret)
+   goto out;
+
+   ieee80211_queue_delayed_work(dev->mt76.hw, >mac_work,
+MT_CALIBRATE_INTERVAL);
+   ieee80211_queue_delayed_work(dev->mt76.hw, >cal_work,
+MT_CALIBRATE_INTERVAL);
+out:
+   mutex_unlock(>mutex);
+   return ret;
+}
+
+static void mt76x0_stop(struct ieee80211_hw *hw)
+{
+   struct mt76x0_dev *dev = hw->priv;
+
+   mutex_lock(>mutex);
+
+   cancel_delayed_work_sync(>cal_work);
+   cancel_delayed_work_sync(>mac_work);
+   mt76x0_mac_stop(dev);
+
+   mutex_unlock(>mutex);
+}
+
+
+static int mt76x0_add_interface(struct ieee80211_hw *hw,
+struct ieee80211_vif *vif)
+{
+   struct mt76x0_dev *dev = hw->priv;
+   struct mt76_vif *mvif = (struct mt76_vif *) vif->drv_priv;
+   unsigned int idx;
+
+   idx = ffs(~dev->vif_mask);
+   if (!idx || idx > 8)
+   return -ENOSPC;
+
+   idx--;
+   dev->vif_mask |= BIT(idx);
+
+   mvif->idx = idx;
+   mvif->group_wcid.idx = GROUP_WCID(idx);
+   mvif->group_wcid.hw_key_idx = -1;
+
+   return 0;
+}
+
+static void mt76x0_remove_interface(struct ieee80211_hw *hw,
+struct ieee80211_vif *vif)
+{
+   struct mt76x0_dev *dev = hw->priv;
+   struct mt76_vif *mvif = (struct mt76_vif *) vif->drv_priv;
+   unsigned int wcid = mvif->group_wcid.idx;
+
+   dev->wcid_mask[wcid / BITS_PER_LONG] &= ~BIT(wcid % BITS_PER_LONG);
+}
+
+static int mt76x0_config(struct ieee80211_hw *hw, u32 changed)
+{
+   struct mt76x0_dev *dev = hw->priv;
+   int ret = 0;
+
+   mutex_lock(>mutex);
+
+   if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
+   if (!(hw->conf.flags & IEEE80211_CONF_MONITOR))
+   dev->rxfilter |= MT_RX_FILTR_CFG_PROMISC;
+   else
+   dev->rxfilter &= ~MT_RX_FILTR_CFG_PROMISC;
+
+   mt76_wr(dev, MT_RX_FILTR_CFG, dev->rxfilter);
+   }
+
+   if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
+   ieee80211_stop_queues(hw);
+   ret = mt76x0_phy_set_channel(dev, >conf.chandef);
+   ieee80211_wake_queues(hw);
+   }
+
+   mutex_unlock(>mutex);
+
+   return ret;
+}
+
+static void
+mt76_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags,
+ unsigned int *total_flags, u64 multicast)
+{
+   struct mt76x0_dev *dev = hw->priv;
+   u32 flags = 0;
+
+#define MT76_FILTER(_flag, _hw) do { \
+   flags |= *total_flags & FIF_##_flag;\
+   dev->rxfilter &= ~(_hw);\
+   dev->rxfilter |= !(flags & FIF_##_flag) * (_hw);\
+   } while (0)
+
+   mutex_lock(>mutex);
+
+   dev->rxfilter &= ~MT_RX_FILTR_CFG_OTHER_BSS;
+
+   MT76_FILTER(FCSFAIL, MT_RX_FILTR_CFG_CRC_ERR);
+   MT76_FILTER(PLCPFAIL, MT_RX_FILTR_CFG_PHY_ERR);
+   MT76_FILTER(CONTROL, MT_RX_FILTR_CFG_ACK |
+MT_RX_FILTR_CFG_CTS |
+MT_RX_FILTR_CFG_CFEND |
+MT_RX_FILTR_CFG_CFACK |
+MT_RX_FILTR_CFG_BA |
+MT_RX_FILTR_CFG_CTRL_RSV);
+   MT76_FILTER(PSPOLL, MT_RX_FILTR_CFG_PSPOLL);
+
+   *total_flags = flags;
+   mt76_wr(dev, MT_RX_FILTR_CFG, dev->rxfilter);
+
+   mutex_unlock(>mutex);
+}
+
+static void
+mt76x0_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+struct 

[PATCH v2 09/12] mt76x0: trace and debugfs files

2018-07-06 Thread Stanislaw Gruszka
Add trace and debugfs files of mt76x0 driver.

Signed-off-by: Stanislaw Gruszka 
---
 .../net/wireless/mediatek/mt76/mt76x0/debugfs.c| 166 ++
 drivers/net/wireless/mediatek/mt76/mt76x0/trace.c  |  21 ++
 drivers/net/wireless/mediatek/mt76/mt76x0/trace.h  | 366 +
 3 files changed, 553 insertions(+)
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/trace.c
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/trace.h

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c
new file mode 100644
index ..e7a77a886068
--- /dev/null
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c
@@ -0,0 +1,166 @@
+/*
+ * Copyright (C) 2014 Felix Fietkau 
+ * Copyright (C) 2015 Jakub Kicinski 
+ * Copyright (C) 2018 Stanislaw Gruszka 
+ *
+ * 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 
+
+#include "mt76x0.h"
+#include "eeprom.h"
+
+static int
+mt76_reg_set(void *data, u64 val)
+{
+   struct mt76x0_dev *dev = data;
+
+   mt76_wr(dev, dev->debugfs_reg, val);
+   return 0;
+}
+
+static int
+mt76_reg_get(void *data, u64 *val)
+{
+   struct mt76x0_dev *dev = data;
+
+   *val = mt76_rr(dev, dev->debugfs_reg);
+   return 0;
+}
+
+DEFINE_SIMPLE_ATTRIBUTE(fops_regval, mt76_reg_get, mt76_reg_set, "0x%08llx\n");
+
+static int
+mt76x0_ampdu_stat_read(struct seq_file *file, void *data)
+{
+   struct mt76x0_dev *dev = file->private;
+   int i, j;
+
+#define stat_printf(grp, off, name)\
+   seq_printf(file, #name ":\t%llu\n", dev->stats.grp[off])
+
+   stat_printf(rx_stat, 0, rx_crc_err);
+   stat_printf(rx_stat, 1, rx_phy_err);
+   stat_printf(rx_stat, 2, rx_false_cca);
+   stat_printf(rx_stat, 3, rx_plcp_err);
+   stat_printf(rx_stat, 4, rx_fifo_overflow);
+   stat_printf(rx_stat, 5, rx_duplicate);
+
+   stat_printf(tx_stat, 0, tx_fail_cnt);
+   stat_printf(tx_stat, 1, tx_bcn_cnt);
+   stat_printf(tx_stat, 2, tx_success);
+   stat_printf(tx_stat, 3, tx_retransmit);
+   stat_printf(tx_stat, 4, tx_zero_len);
+   stat_printf(tx_stat, 5, tx_underflow);
+
+   stat_printf(aggr_stat, 0, non_aggr_tx);
+   stat_printf(aggr_stat, 1, aggr_tx);
+
+   stat_printf(zero_len_del, 0, tx_zero_len_del);
+   stat_printf(zero_len_del, 1, rx_zero_len_del);
+#undef stat_printf
+
+   seq_puts(file, "Aggregations stats:\n");
+   for (i = 0; i < 4; i++) {
+   for (j = 0; j < 8; j++)
+   seq_printf(file, "%08llx ",
+  dev->stats.aggr_n[i * 8 + j]);
+   seq_putc(file, '\n');
+   }
+
+   seq_printf(file, "recent average AMPDU len: %d\n",
+  atomic_read(>avg_ampdu_len));
+
+   return 0;
+}
+
+static int
+mt76x0_ampdu_stat_open(struct inode *inode, struct file *f)
+{
+   return single_open(f, mt76x0_ampdu_stat_read, inode->i_private);
+}
+
+static const struct file_operations fops_ampdu_stat = {
+   .open = mt76x0_ampdu_stat_open,
+   .read = seq_read,
+   .llseek = seq_lseek,
+   .release = single_release,
+};
+
+static int
+mt76x0_eeprom_param_read(struct seq_file *file, void *data)
+{
+   struct mt76x0_dev *dev = file->private;
+   int i;
+
+   seq_printf(file, "RF freq offset: %hhx\n", dev->ee->rf_freq_off);
+   seq_printf(file, "RSSI offset 2GHz: %hhx %hhx\n",
+  dev->ee->rssi_offset_2ghz[0], dev->ee->rssi_offset_2ghz[1]);
+   seq_printf(file, "RSSI offset 5GHz: %hhx %hhx %hhx\n",
+  dev->ee->rssi_offset_5ghz[0], dev->ee->rssi_offset_5ghz[1],
+  dev->ee->rssi_offset_5ghz[2]);
+   seq_printf(file, "Temperature offset: %hhx\n", dev->ee->temp_off);
+   seq_printf(file, "LNA gain 2Ghz: %hhx\n", dev->ee->lna_gain_2ghz);
+   seq_printf(file, "LNA gain 5Ghz: %hhx %hhx %hhx\n",
+  dev->ee->lna_gain_5ghz[0], dev->ee->lna_gain_5ghz[1],
+  dev->ee->lna_gain_5ghz[2]);
+   seq_printf(file, "Power Amplifier type %hhx\n", dev->ee->pa_type);
+   seq_printf(file, "Reg channels: %hhu-%hhu\n", dev->ee->reg.start,
+  dev->ee->reg.start + dev->ee->reg.num - 1);
+
+   seq_puts(file, "Per channel power:\n");
+   for (i = 0; i < 58; i++)
+   seq_printf(file, "\t%d chan:%d pwr:%d\n", i, i,
+  dev->ee->tx_pwr_per_chan[i]);
+
+   

[PATCH v2 10/12] mt76x0: dma and tx files

2018-07-06 Thread Stanislaw Gruszka
Add dma and tx files of mt76x0 driver.

Signed-off-by: Stanislaw Gruszka 
---
 drivers/net/wireless/mediatek/mt76/mt76x0/dma.c | 522 
 drivers/net/wireless/mediatek/mt76/mt76x0/dma.h | 126 ++
 drivers/net/wireless/mediatek/mt76/mt76x0/tx.c  | 270 
 3 files changed, 918 insertions(+)
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/dma.c
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/dma.h
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/tx.c

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/dma.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/dma.c
new file mode 100644
index ..2cf71283de3f
--- /dev/null
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/dma.c
@@ -0,0 +1,522 @@
+/*
+ * Copyright (C) 2015 Jakub Kicinski 
+ * Copyright (C) 2018 Stanislaw Gruszka 
+ *
+ * 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 "dma.h"
+#include "usb.h"
+#include "trace.h"
+
+static int mt76x0_submit_rx_buf(struct mt76x0_dev *dev,
+struct mt76x0_dma_buf_rx *e, gfp_t gfp);
+
+static unsigned int ieee80211_get_hdrlen_from_buf(const u8 *data, unsigned len)
+{
+   const struct ieee80211_hdr *hdr = (const struct ieee80211_hdr *)data;
+   unsigned int hdrlen;
+
+   if (unlikely(len < 10))
+   return 0;
+   hdrlen = ieee80211_hdrlen(hdr->frame_control);
+   if (unlikely(hdrlen > len))
+   return 0;
+   return hdrlen;
+}
+
+static struct sk_buff *
+mt76x0_rx_skb_from_seg(struct mt76x0_dev *dev, struct mt76x0_rxwi *rxwi,
+   void *data, u32 seg_len, u32 truesize, struct page *p)
+{
+   struct sk_buff *skb;
+   u32 true_len, hdr_len = 0, copy, frag;
+
+   skb = alloc_skb(p ? 128 : seg_len, GFP_ATOMIC);
+   if (!skb)
+   return NULL;
+
+   true_len = mt76_mac_process_rx(dev, skb, data, rxwi);
+   if (!true_len || true_len > seg_len)
+   goto bad_frame;
+
+   hdr_len = ieee80211_get_hdrlen_from_buf(data, true_len);
+   if (!hdr_len)
+   goto bad_frame;
+
+   if (rxwi->rxinfo & cpu_to_le32(MT_RXINFO_L2PAD)) {
+   memcpy(skb_put(skb, hdr_len), data, hdr_len);
+
+   data += hdr_len + 2;
+   true_len -= hdr_len;
+   hdr_len = 0;
+   }
+
+   /* If not doing paged RX allocated skb will always have enough space */
+   copy = (true_len <= skb_tailroom(skb)) ? true_len : hdr_len + 8;
+   frag = true_len - copy;
+
+   memcpy(skb_put(skb, copy), data, copy);
+   data += copy;
+
+   if (frag) {
+   skb_add_rx_frag(skb, 0, p, data - page_address(p),
+   frag, truesize);
+   get_page(p);
+   }
+
+   return skb;
+
+bad_frame:
+   dev_err_ratelimited(dev->mt76.dev, "Error: incorrect frame len:%u 
hdr:%u\n",
+   true_len, hdr_len);
+   dev_kfree_skb(skb);
+   return NULL;
+}
+
+static void mt76x0_rx_process_seg(struct mt76x0_dev *dev, u8 *data,
+  u32 seg_len, struct page *p)
+{
+   struct sk_buff *skb;
+   struct mt76x0_rxwi *rxwi;
+   u32 fce_info, truesize = seg_len;
+
+   /* DMA_INFO field at the beginning of the segment contains only some of
+* the information, we need to read the FCE descriptor from the end.
+*/
+   fce_info = get_unaligned_le32(data + seg_len - MT_FCE_INFO_LEN);
+   seg_len -= MT_FCE_INFO_LEN;
+
+   data += MT_DMA_HDR_LEN;
+   seg_len -= MT_DMA_HDR_LEN;
+
+   rxwi = (struct mt76x0_rxwi *) data;
+   data += sizeof(struct mt76x0_rxwi);
+   seg_len -= sizeof(struct mt76x0_rxwi);
+
+   if (unlikely(FIELD_GET(MT_RXD_INFO_TYPE, fce_info)))
+   dev_err_once(dev->mt76.dev, "Error: RX path seen a non-pkt 
urb\n");
+
+   trace_mt_rx(>mt76, rxwi, fce_info);
+
+   skb = mt76x0_rx_skb_from_seg(dev, rxwi, data, seg_len, truesize, p);
+   if (!skb)
+   return;
+
+   spin_lock(>mac_lock);
+   ieee80211_rx(dev->mt76.hw, skb);
+   spin_unlock(>mac_lock);
+}
+
+static u16 mt76x0_rx_next_seg_len(u8 *data, u32 data_len)
+{
+   u32 min_seg_len = MT_DMA_HDR_LEN + MT_RX_INFO_LEN +
+   sizeof(struct mt76x0_rxwi) + MT_FCE_INFO_LEN;
+   u16 dma_len = get_unaligned_le16(data);
+
+   if (data_len < min_seg_len ||
+   WARN_ON(!dma_len) ||
+   WARN_ON(dma_len + MT_DMA_HDRS > data_len) ||
+   WARN_ON(dma_len & 0x3))

[PATCH v2 03/12] mt76x0: mac files

2018-07-06 Thread Stanislaw Gruszka
Add mac files of mt76x0 driver.

Signed-off-by: Stanislaw Gruszka 
---
 drivers/net/wireless/mediatek/mt76/mt76x0/mac.c | 660 
 drivers/net/wireless/mediatek/mt76/mt76x0/mac.h | 154 ++
 2 files changed, 814 insertions(+)
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/mac.c
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/mac.h

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/mac.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/mac.c
new file mode 100644
index ..7b32777c06e9
--- /dev/null
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/mac.c
@@ -0,0 +1,660 @@
+/*
+ * Copyright (C) 2014 Felix Fietkau 
+ * Copyright (C) 2015 Jakub Kicinski 
+ * Copyright (C) 2018 Stanislaw Gruszka 
+ *
+ * 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 
+
+static void
+mt76_mac_process_tx_rate(struct ieee80211_tx_rate *txrate, u16 rate,
+enum nl80211_band band)
+{
+   u8 idx = FIELD_GET(MT_RXWI_RATE_INDEX, rate);
+
+   txrate->idx = 0;
+   txrate->flags = 0;
+   txrate->count = 1;
+
+   switch (FIELD_GET(MT_RXWI_RATE_PHY, rate)) {
+   case MT_PHY_TYPE_OFDM:
+   if (band == NL80211_BAND_2GHZ)
+   idx += 4;
+
+   txrate->idx = idx;
+   return;
+   case MT_PHY_TYPE_CCK:
+   if (idx >= 8)
+   idx -= 8;
+
+   txrate->idx = idx;
+   return;
+   case MT_PHY_TYPE_HT_GF:
+   txrate->flags |= IEEE80211_TX_RC_GREEN_FIELD;
+   /* fall through */
+   case MT_PHY_TYPE_HT:
+   txrate->flags |= IEEE80211_TX_RC_MCS;
+   txrate->idx = idx;
+   break;
+   case MT_PHY_TYPE_VHT:
+   txrate->flags |= IEEE80211_TX_RC_VHT_MCS;
+   txrate->idx = idx;
+   break;
+   default:
+   WARN_ON(1);
+   return;
+   }
+
+   switch (FIELD_GET(MT_RXWI_RATE_BW, rate)) {
+   case MT_PHY_BW_20:
+   break;
+   case MT_PHY_BW_40:
+   txrate->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
+   break;
+   case MT_PHY_BW_80:
+   txrate->flags |= IEEE80211_TX_RC_80_MHZ_WIDTH;
+   break;
+   default:
+   WARN_ON(1);
+   return;
+   }
+
+   if (rate & MT_RXWI_RATE_SGI)
+   txrate->flags |= IEEE80211_TX_RC_SHORT_GI;
+}
+
+static void
+mt76_mac_fill_tx_status(struct mt76x0_dev *dev, struct ieee80211_tx_info *info,
+   struct mt76_tx_status *st, int n_frames)
+{
+   struct ieee80211_tx_rate *rate = info->status.rates;
+   int cur_idx, last_rate;
+   int i;
+
+   if (!n_frames)
+   return;
+
+   last_rate = min_t(int, st->retry, IEEE80211_TX_MAX_RATES - 1);
+   mt76_mac_process_tx_rate([last_rate], st->rate,
+dev->mt76.chandef.chan->band);
+   if (last_rate < IEEE80211_TX_MAX_RATES - 1)
+   rate[last_rate + 1].idx = -1;
+
+   cur_idx = rate[last_rate].idx + last_rate;
+   for (i = 0; i <= last_rate; i++) {
+   rate[i].flags = rate[last_rate].flags;
+   rate[i].idx = max_t(int, 0, cur_idx - i);
+   rate[i].count = 1;
+   }
+
+   rate[last_rate - 1].count = st->retry + 1 - last_rate;
+
+   info->status.ampdu_len = n_frames;
+   info->status.ampdu_ack_len = st->success ? n_frames : 0;
+
+   if (st->pktid & MT_TXWI_PKTID_PROBE)
+   info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE;
+
+   if (st->aggr)
+   info->flags |= IEEE80211_TX_CTL_AMPDU |
+  IEEE80211_TX_STAT_AMPDU;
+
+   if (!st->ack_req)
+   info->flags |= IEEE80211_TX_CTL_NO_ACK;
+   else if (st->success)
+   info->flags |= IEEE80211_TX_STAT_ACK;
+}
+
+u16 mt76_mac_tx_rate_val(struct mt76x0_dev *dev,
+const struct ieee80211_tx_rate *rate, u8 *nss_val)
+{
+   u16 rateval;
+   u8 phy, rate_idx;
+   u8 nss = 1;
+   u8 bw = 0;
+
+   if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
+   rate_idx = rate->idx;
+   nss = 1 + (rate->idx >> 4);
+   phy = MT_PHY_TYPE_VHT;
+   if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
+   bw = 2;
+   else if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
+   bw = 1;
+   } else if 

[PATCH v2 02/12] mt76x0: core files

2018-07-06 Thread Stanislaw Gruszka
Core files of mt76x0 driver.

mt76x0 driver adds support for Mediatek MT7610U based
USB Wi-Fi dongles.

Signed-off-by: Stanislaw Gruszka 
---
 drivers/net/wireless/mediatek/mt76/mt76x0/core.c   |  34 ++
 drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h | 376 
 drivers/net/wireless/mediatek/mt76/mt76x0/regs.h   | 651 +
 drivers/net/wireless/mediatek/mt76/mt76x0/util.c   |  42 ++
 4 files changed, 1103 insertions(+)
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/core.c
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/regs.h
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/util.c

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/core.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/core.c
new file mode 100644
index ..892803fce842
--- /dev/null
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/core.c
@@ -0,0 +1,34 @@
+/*
+ * 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"
+
+int mt76x0_wait_asic_ready(struct mt76x0_dev *dev)
+{
+   int i = 100;
+   u32 val;
+
+   do {
+   if (test_bit(MT76_REMOVED, >mt76.state))
+   return -EIO;
+
+   val = mt76_rr(dev, MT_MAC_CSR0);
+   if (val && ~val)
+   return 0;
+
+   udelay(10);
+   } while (i--);
+
+   return -EIO;
+}
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h 
b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h
new file mode 100644
index ..069392a70606
--- /dev/null
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h
@@ -0,0 +1,376 @@
+/*
+ * Copyright (C) 2014 Felix Fietkau 
+ * Copyright (C) 2015 Jakub Kicinski 
+ * Copyright (C) 2018 Stanislaw Gruszka 
+ *
+ * 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 MT76X0U_H
+#define MT76X0U_H
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "../mt76.h"
+#include "regs.h"
+
+#define MT_CALIBRATE_INTERVAL  (4 * HZ)
+
+#define MT_FREQ_CAL_INIT_DELAY (30 * HZ)
+#define MT_FREQ_CAL_CHECK_INTERVAL (10 * HZ)
+#define MT_FREQ_CAL_ADJ_INTERVAL   (HZ / 2)
+
+#define MT_BBP_REG_VERSION 0x00
+
+#define MT_USB_AGGR_SIZE_LIMIT 21 /* * 1024B */
+#define MT_USB_AGGR_TIMEOUT0x80 /* * 33ns */
+#define MT_RX_ORDER3
+#define MT_RX_URB_SIZE (PAGE_SIZE << MT_RX_ORDER)
+
+struct mt76x0_dma_buf {
+   struct urb *urb;
+   void *buf;
+   dma_addr_t dma;
+   size_t len;
+};
+
+struct mt76x0_mcu {
+   struct mutex mutex;
+
+   u8 msg_seq;
+
+   struct mt76x0_dma_buf resp;
+   struct completion resp_cmpl;
+
+   struct mt76_reg_pair *reg_pairs;
+   unsigned int reg_pairs_len;
+   u32 reg_base;
+   bool burst_read;
+};
+
+struct mac_stats {
+   u64 rx_stat[6];
+   u64 tx_stat[6];
+   u64 aggr_stat[2];
+   u64 aggr_n[32];
+   u64 zero_len_del[2];
+};
+
+#define N_RX_ENTRIES   16
+struct mt76x0_rx_queue {
+   struct mt76x0_dev *dev;
+
+   struct mt76x0_dma_buf_rx {
+   struct urb *urb;
+   struct page *p;
+   } e[N_RX_ENTRIES];
+
+   unsigned int start;
+   unsigned int end;
+   unsigned int entries;
+   unsigned int pending;
+};
+
+#define N_TX_ENTRIES   64
+
+struct mt76x0_tx_queue {
+   struct mt76x0_dev *dev;
+
+   struct mt76x0_dma_buf_tx {
+   struct urb *urb;
+   struct sk_buff *skb;
+   } e[N_TX_ENTRIES];
+
+   unsigned int start;
+   unsigned int end;
+   unsigned int entries;
+   unsigned int used;
+   unsigned int fifo_seq;
+};
+
+/* WCID allocation:
+ * 0: mcast wcid
+ * 1: bssid wcid
+ *  1...: STAs
+ * ...7e: group wcids
+ *7f: reserved
+ */
+#define N_WCIDS128
+#define GROUP_WCID(idx)(254 - idx)
+
+struct mt76x0_eeprom_params;
+
+#define MT_EE_TEMPERATURE_SLOPE39
+#define 

[PATCH v2 00/12] Add mt76x0 driver

2018-07-06 Thread Stanislaw Gruszka
Add mt76x0 driver for MT7610U based USB dongles. Currently driver
support only STA mode.

mt76x0 is based on Jakub's mt7601u driver already included
in the kernel. I would like the driver be integrated as part
of mt76 (instead of separate driver in mediatek dir like mt7601u)
to utilize mt76 code for adding support for MT76x0 PCIe devices
in further development.

To do not collide with current mt76x2u work from Lorenzo, I did not
remove some code duplication. This will be done in the future, when
Lorenzo patches will be merged. I plan to do more close integration
with mt76x2u into common mt76 layer and add support for MT76x0 PCIe
devices (i.e. MT7630E). Any help with this work is obviously welcome.
My integration efforts can be traced here:
https://github.com/sgruszka/wireless-drivers-next/commits/mt76x0-draft

For full support mt7610.bin firmware blob is need, hopefully with 
the permission of Mediatek, the blob will be pushed into linux-firmware
git tree.

v1 -> v2:
 - add missed mac.c file!
 - fix uninitialized variables reported by kbuild test
 - fix rate estimation
 - check for skb allocation

Stanislaw Gruszka (12):
  mt76: add more states
  mt76x0: core files
  mt76x0: mac files
  mt76x0: usb files
  mt76x0: mcu files
  mt76x0: phy files
  mt76x0: init files
  mt76x0: eeprom files
  mt76x0: trace and debugfs files
  mt76x0: dma and tx files
  mt76x0: main file
  mt76: Kconfig and Makefile for mt76x0 driver

 drivers/net/wireless/mediatek/mt76/Kconfig |7 +
 drivers/net/wireless/mediatek/mt76/Makefile|1 +
 drivers/net/wireless/mediatek/mt76/mt76.h  |4 +
 drivers/net/wireless/mediatek/mt76/mt76x0/Makefile |7 +
 drivers/net/wireless/mediatek/mt76/mt76x0/core.c   |   34 +
 .../net/wireless/mediatek/mt76/mt76x0/debugfs.c|  166 
 drivers/net/wireless/mediatek/mt76/mt76x0/dma.c|  522 ++
 drivers/net/wireless/mediatek/mt76/mt76x0/dma.h|  126 +++
 drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c |  445 +
 drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h |  149 +++
 drivers/net/wireless/mediatek/mt76/mt76x0/init.c   |  720 ++
 .../net/wireless/mediatek/mt76/mt76x0/initvals.h   |  282 ++
 .../wireless/mediatek/mt76/mt76x0/initvals_phy.h   |  772 +++
 drivers/net/wireless/mediatek/mt76/mt76x0/mac.c|  660 +
 drivers/net/wireless/mediatek/mt76/mt76x0/mac.h|  154 +++
 drivers/net/wireless/mediatek/mt76/mt76x0/main.c   |  403 
 drivers/net/wireless/mediatek/mt76/mt76x0/mcu.c|  655 +
 drivers/net/wireless/mediatek/mt76/mt76x0/mcu.h|  101 ++
 drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h |  376 
 drivers/net/wireless/mediatek/mt76/mt76x0/phy.c| 1008 
 drivers/net/wireless/mediatek/mt76/mt76x0/phy.h|   81 ++
 drivers/net/wireless/mediatek/mt76/mt76x0/regs.h   |  651 +
 drivers/net/wireless/mediatek/mt76/mt76x0/trace.c  |   21 +
 drivers/net/wireless/mediatek/mt76/mt76x0/trace.h  |  366 +++
 drivers/net/wireless/mediatek/mt76/mt76x0/tx.c |  270 ++
 drivers/net/wireless/mediatek/mt76/mt76x0/usb.c|  377 
 drivers/net/wireless/mediatek/mt76/mt76x0/usb.h|   61 ++
 drivers/net/wireless/mediatek/mt76/mt76x0/util.c   |   42 +
 28 files changed, 8461 insertions(+)
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/Makefile
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/core.c
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/dma.c
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/dma.h
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/init.c
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/initvals.h
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/initvals_phy.h
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/mac.c
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/mac.h
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/main.c
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/mcu.c
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/mcu.h
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/phy.h
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/regs.h
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/trace.c
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/trace.h
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/tx.c
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/usb.c
 create mode 100644 

[PATCH v2 12/12] mt76: Kconfig and Makefile for mt76x0 driver

2018-07-06 Thread Stanislaw Gruszka
Add Kconfig and Makefiles for mt76x0 driver. Now the driver
can be build.

Signed-off-by: Stanislaw Gruszka 
---
 drivers/net/wireless/mediatek/mt76/Kconfig | 7 +++
 drivers/net/wireless/mediatek/mt76/Makefile| 1 +
 drivers/net/wireless/mediatek/mt76/mt76x0/Makefile | 7 +++
 3 files changed, 15 insertions(+)
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/Makefile

diff --git a/drivers/net/wireless/mediatek/mt76/Kconfig 
b/drivers/net/wireless/mediatek/mt76/Kconfig
index fc05d79c80d0..84854736809a 100644
--- a/drivers/net/wireless/mediatek/mt76/Kconfig
+++ b/drivers/net/wireless/mediatek/mt76/Kconfig
@@ -1,6 +1,13 @@
 config MT76_CORE
tristate
 
+config MT76x0U
+   tristate "MediaTek MT76x0U (USB) support"
+   depends on MAC80211
+   depends on USB
+   help
+ This adds support for MT7610U-based wireless USB dongles.
+
 config MT76x2E
tristate "MediaTek MT76x2E (PCIe) support"
select MT76_CORE
diff --git a/drivers/net/wireless/mediatek/mt76/Makefile 
b/drivers/net/wireless/mediatek/mt76/Makefile
index a0156bc01dea..08f93127e9e7 100644
--- a/drivers/net/wireless/mediatek/mt76/Makefile
+++ b/drivers/net/wireless/mediatek/mt76/Makefile
@@ -1,4 +1,5 @@
 obj-$(CONFIG_MT76_CORE) += mt76.o
+obj-$(CONFIG_MT76x0U) += mt76x0/
 obj-$(CONFIG_MT76x2E) += mt76x2e.o
 
 mt76-y := \
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/Makefile 
b/drivers/net/wireless/mediatek/mt76/mt76x0/Makefile
new file mode 100644
index ..7843908261ba
--- /dev/null
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/Makefile
@@ -0,0 +1,7 @@
+obj-$(CONFIG_MT76x0U)+= mt76x0.o
+
+mt76x0-objs= \
+   usb.o init.o main.o mcu.o trace.o dma.o eeprom.o phy.o \
+   mac.o util.o debugfs.o tx.o core.o
+# ccflags-y := -DDEBUG
+CFLAGS_trace.o := -I$(src)
-- 
1.9.3



[PATCH v2 05/12] mt76x0: mcu files

2018-07-06 Thread Stanislaw Gruszka
Add mcu files of mt76x0 driver.

Signed-off-by: Stanislaw Gruszka 
---
 drivers/net/wireless/mediatek/mt76/mt76x0/mcu.c | 655 
 drivers/net/wireless/mediatek/mt76/mt76x0/mcu.h | 101 
 2 files changed, 756 insertions(+)
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/mcu.c
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x0/mcu.h

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/mcu.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/mcu.c
new file mode 100644
index ..aafa3f325ebf
--- /dev/null
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/mcu.c
@@ -0,0 +1,655 @@
+/*
+ * (c) Copyright 2002-2010, Ralink Technology, Inc.
+ * Copyright (C) 2014 Felix Fietkau 
+ * Copyright (C) 2015 Jakub Kicinski 
+ * Copyright (C) 2018 Stanislaw Gruszka 
+ *
+ * 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 
+#include 
+#include 
+#include 
+#include 
+
+#include "mt76x0.h"
+#include "dma.h"
+#include "mcu.h"
+#include "usb.h"
+#include "trace.h"
+
+#define MCU_FW_URB_MAX_PAYLOAD 0x38f8
+#define MCU_FW_URB_SIZE(MCU_FW_URB_MAX_PAYLOAD + 12)
+#define MCU_RESP_URB_SIZE  1024
+
+static inline int firmware_running(struct mt76x0_dev *dev)
+{
+   return mt76_rr(dev, MT_MCU_COM_REG0) == 1;
+}
+
+static inline void skb_put_le32(struct sk_buff *skb, u32 val)
+{
+   put_unaligned_le32(val, skb_put(skb, 4));
+}
+
+static inline void mt76x0_dma_skb_wrap_cmd(struct sk_buff *skb,
+   u8 seq, enum mcu_cmd cmd)
+{
+   WARN_ON(mt76x0_dma_skb_wrap(skb, CPU_TX_PORT, DMA_COMMAND,
+FIELD_PREP(MT_TXD_CMD_SEQ, seq) |
+FIELD_PREP(MT_TXD_CMD_TYPE, cmd)));
+}
+
+static inline void trace_mt_mcu_msg_send_cs(struct mt76_dev *dev,
+   struct sk_buff *skb, bool need_resp)
+{
+   u32 i, csum = 0;
+
+   for (i = 0; i < skb->len / 4; i++)
+   csum ^= get_unaligned_le32(skb->data + i * 4);
+
+   trace_mt_mcu_msg_send(dev, skb, csum, need_resp);
+}
+
+static struct sk_buff *
+mt76x0_mcu_msg_alloc(struct mt76x0_dev *dev, const void *data, int len)
+{
+   struct sk_buff *skb;
+
+   WARN_ON(len % 4); /* if length is not divisible by 4 we need to pad */
+
+   skb = alloc_skb(len + MT_DMA_HDR_LEN + 4, GFP_KERNEL);
+   if (skb) {
+   skb_reserve(skb, MT_DMA_HDR_LEN);
+   memcpy(skb_put(skb, len), data, len);
+   }
+   return skb;
+}
+
+static void mt76x0_read_resp_regs(struct mt76x0_dev *dev, int len)
+{
+   int i;
+   int n = dev->mcu.reg_pairs_len;
+   u8 *buf = dev->mcu.resp.buf;
+
+   buf += 4;
+   len -= 8;
+
+   if (dev->mcu.burst_read) {
+   u32 reg = dev->mcu.reg_pairs[0].reg - dev->mcu.reg_base;
+
+   WARN_ON_ONCE(len/4 != n);
+   for (i = 0; i < n; i++) {
+   u32 val = get_unaligned_le32(buf + 4*i);
+
+   dev->mcu.reg_pairs[i].reg = reg++;
+   dev->mcu.reg_pairs[i].value = val;
+   }
+   } else {
+   WARN_ON_ONCE(len/8 != n);
+   for (i = 0; i < n; i++) {
+   u32 reg = get_unaligned_le32(buf + 8*i) - 
dev->mcu.reg_base;
+   u32 val = get_unaligned_le32(buf + 8*i + 4);
+
+   WARN_ON_ONCE(dev->mcu.reg_pairs[i].reg != reg);
+   dev->mcu.reg_pairs[i].value = val;
+   }
+   }
+}
+
+static int mt76x0_mcu_wait_resp(struct mt76x0_dev *dev, u8 seq)
+{
+   struct urb *urb = dev->mcu.resp.urb;
+   u32 rxfce;
+   int urb_status, ret, try = 5;
+
+   while (try--) {
+   if (!wait_for_completion_timeout(>mcu.resp_cmpl,
+msecs_to_jiffies(300))) {
+   dev_warn(dev->mt76.dev, "Warning: %s retrying\n", 
__func__);
+   continue;
+   }
+
+   /* Make copies of important data before reusing the urb */
+   rxfce = get_unaligned_le32(dev->mcu.resp.buf);
+   urb_status = urb->status * mt76x0_urb_has_error(urb);
+
+   if (urb_status == 0 && dev->mcu.reg_pairs)
+   mt76x0_read_resp_regs(dev, urb->actual_length);
+
+   ret = mt76x0_usb_submit_buf(dev, USB_DIR_IN, MT_EP_IN_CMD_RESP,
+>mcu.resp, GFP_KERNEL,
+