Re: feedback on mainlining wilc1000 staging driver

2018-10-04 Thread Kalle Valo
Ajay Singh  writes:

>> > I have submitted a patch series for wilc1000 driver, single file
>> > per patch and its based on wireless-drivers-next. 
>> > I hope its done correctly, please provide inputs so we can
>> > address and make this driver ready for mainline.
>> 
>> Thanks, I see it in patchwork:
>> 
>> https://patchwork.kernel.org/project/linux-wireless/list/?series=23251=*=date
>> 
>> Do note that we have also another new driver (rtwlan/rtw88) under
>> review so review from the wireless folks might take some time.
>> 
>
> Thanks for the update.
> Btw I could see our driver was added to the pending branch. Just
> curious, could you please share details about how the pending branch is
> used ?

I use pending branch mainly for testing bigger patches with kbuild bot,
though I think the bot is offline this week. (Or was it next week? Can't
remember)

-- 
Kalle Valo


Re: feedback on mainlining wilc1000 staging driver

2018-10-04 Thread Ajay Singh
Hi Kalle,

On Thu, 4 Oct 2018 15:27:57 +0300
Kalle Valo  wrote:

> Ajay Singh  writes:
> 
> > Hi Kalle,
> >
> > On Thu, 23 Aug 2018 16:37:45 +0530
> > Kalle Valo  wrote:
> >
> >> Ajay Singh  writes:
> >> 
> >> >> >>> We need help to review and identify if there are any pending
> >> >> >>> items for wilc1000 driver, so we can address those issues
> >> >> >>> and make it ready to move to the wireless subsystem.
> >> >> >>
> >> >> >> I think the best way to get that forward is to submit a patch
> >> >> >> (or patchset) to linux-wireless, that's the easiest for
> >> >> >> reviewers.
> >> >> >
> >> >> > For brcm80211 drivers we used a single patch introducing it
> >> >> > under the wireless drivers folder. Because it was quite a
> >> >> > sizable patch we parked it on the wireless wiki page. Had a
> >> >> > few iterations doing it like that.
> >> >> 
> >> >> Another option is to split it so that there's one patch per
> >> >> file, should be even pretty easy to automate that. It's just so
> >> >> much easier to comment on a patch submitted by email compared
> >> >> to the reviewer manually copying code and then commenting it,
> >> >> yuck. 
> >> >
> >> > Sure. I will prepare a patch per file send for review as its
> >> > easy to review.
> >> >
> >> > As Greg suggested, I will wait for the merge window to close and
> >> > after completing pending patches to staging, I will start the
> >> > review.
> >> >
> >> > For my understanding, the patches for review will be based on
> >> > wireless-testing branch.  
> >> 
> >> In this case I think wireless-drivers-next is the safest choise,
> >> wireless-testing also has other trees which might cause conflicts
> >> etc.
> >
> > I have submitted a patch series for wilc1000 driver, single file
> > per patch and its based on wireless-drivers-next. 
> > I hope its done correctly, please provide inputs so we can
> > address and make this driver ready for mainline.
> 
> Thanks, I see it in patchwork:
> 
> https://patchwork.kernel.org/project/linux-wireless/list/?series=23251=*=date
> 
> Do note that we have also another new driver (rtwlan/rtw88) under
> review so review from the wireless folks might take some time.
> 

Thanks for the update.
Btw I could see our driver was added to the pending branch. Just
curious, could you please share details about how the pending branch is
used ?

Regards,
Ajay


Re: [PATCH 0/5] rt2800mmio txdone/interrupts/flush rework

2018-10-04 Thread Tomislav Požega
Hi

As suspected this changeset causes throughput regression.

Below screenshots show iperf test from MS150N (RF5370) device connected to 
RT3070 adapter running AP mode:

This is with standard openwrt build without any rt2x00 changes:

[url=https://postimg.cc/BtYQLf6r][img]https://i.postimg.cc/BtYQLf6r/shot-2018-10-04_17-23-56.jpg[/img][/url]

And this printscreen show iperf test with your changes:

[url=https://postimg.cc/D8Sf1p48][img]https://i.postimg.cc/D8Sf1p48/shot-2018-10-04_17-42-09.jpg[/img][/url]

Atheros card connected to RT3070 iperf test difference was negligible (1Mbps or 
less) on bodhi system, but
it started to throw out reorder messages on my standard ubuntu after your 
changes:

[url=https://postimg.cc/SjJbP2SP][img]https://i.postimg.cc/SjJbP2SP/Screenshot.png[/img][/url]

My advice: stop sending low-quality patches and do some testing before 
submission.


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

2018-10-04 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 | 24 +++
 .../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(+), 142 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 v2 08/10] mt76: move mt76x02_mac_process_rx in mt76x02-lib module

2018-10-04 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 v2 06/10] mt76x2: move mt76x2_dev in mt76x02_util.h

2018-10-04 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 |  69 +
 .../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, 537 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 v2 03/10] mt76x0: mac: use sta ewma estimation for rssi tracking

2018-10-04 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 v2 07/10] mt76x0: merge mt76x0_dev in mt76x02_dev

2018-10-04 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 v2 04/10] mt76x0: remove unused variable in mt76x0_dev

2018-10-04 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 v2 10/10] mt76: move mt76x02_tx in mt76x02-lib module

2018-10-04 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 7bcdaf9fe0a9..1a9450e6703f 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 v2 01/10] mt76: move mt76x02_phy_get_min_avg_rssi in mt76x02_phy.c

2018-10-04 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 v2 00/10] unify rxwi parsing between mt76x0 and mt76x2 drivers

2018-10-04 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

Changes since v1:
- make mt76x02_rx_get_sta and mt76x02_rx_get_sta_wcid inline

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.h
  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 |  53 +++
 .../net/wireless/mediatek/mt76/mt76x02_util.h | 119 ++
 .../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, 944 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 v2 05/10] mt76x0: remove hw_atomic_mutex mutex in mt76x0_dev

2018-10-04 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 v2 02/10] mt76: move mt76x02_rx_get_sta and mt76x02_rx_get_sta_wcid in mt76x02_util.h

2018-10-04 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.h | 29 +
 .../net/wireless/mediatek/mt76/mt76x2/mac.c   | 32 ++-
 2 files changed, 31 insertions(+), 30 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_util.h 
b/drivers/net/wireless/mediatek/mt76/mt76x02_util.h
index 54cec0cbf645..f78526fcf423 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02_util.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_util.h
@@ -18,6 +18,8 @@
 #ifndef __MT76X02_UTIL_H
 #define __MT76X02_UTIL_H
 
+#include "mt76x02_mac.h"
+
 extern struct ieee80211_rate mt76x02_rates[12];
 
 void mt76x02_configure_filter(struct ieee80211_hw *hw,
@@ -77,4 +79,31 @@ mt76x02_wait_for_txrx_idle(struct mt76_dev *dev)
0, 100);
 }
 
+static inline 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);
+}
+
+static inline 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;
+}
+
 #endif
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



Flag for detecting 802.11r Fast BSS Transition support

2018-10-04 Thread Matthew Wang
Hi,

I'm wondering if there is a flag for detecting firmware/driver support
for FT. It seems like checking for SME support is a pretty good proxy
for this, but there is a non-mac80211 driver that can do FT as well
(ath/wil6210). It would be great if anyone knows of a feature flag
specifically for FT.

Thanks,
Matthew


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

2018-10-04 Thread bankita

On 2018-10-01 15:49, Johannes Berg wrote:

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.


We do have rx_packets field but it is for MMPDUs and MSDUs which might 
not reflect the number of MPDUs in all cases. Hence we introduced new 
field for MPDU count.



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 -


These two fields together will help to find bad rx link with a specific 
peer. This information can be used for example to steer the client to a 
different BSS.


Ankita


Re: ath9k and 16 VAP interfaces?

2018-10-04 Thread Ben Greear

Hello,

I'm finally getting around to trying this.

One thing, the second patch won't compile due to missing ath9k_set_moredata 
method.

I see it is implemented here:

http://git.fem.tu-ilmenau.de/?p=fem-wlan.git;a=blob;f=package/kernel/mac80211/patches/310-ath9k-fix-moredata-bit-in-PS-buffered-frame-release.patch;h=b2a74ccbacb29115bede4806006f3265f54cb31c;hb=refs/heads/femwlan_stage2.kernel4.9

I guess I should apply this one...maybe more?

Any idea if any of these patches should be submitted upstream?

Thanks,
Ben

On 08/05/2018 11:18 AM, michael-dev wrote:

Hi,

I'm using [1]. I was seeing some trouble with powersave + broadcasts, so I 
added [2], so that the queue would get empty faster.

Regards,
M. Braun


[1]
http://git.fem.tu-ilmenau.de/?p=fem-wlan.git;a=blob;f=package/kernel/mac80211/patches/911-more-ap-interfaces.patch;h=873a6cb7bdb8a7462ffd07c1a50fc87c580f223d;hb=refs/heads/femwlan_stage2.kernel4.9

[2]
http://git.fem.tu-ilmenau.de/?p=fem-wlan.git;a=blob;f=package/kernel/mac80211/patches/915-use-more-time-for-multicast.patch;h=05d7fb6c2567e1abdef63a4d01f02df7f8501630;hb=refs/heads/femwlan_stage2.kernel4.9

Am 30.07.2018 16:34, schrieb Ben Greear:

On 07/30/2018 04:13 AM, Matthias May wrote:

On 30/07/18 11:40, michael-...@fami-braun.de wrote:

Do you mean AP interfaces as required for multiple BSS/SSIDs?

I'm running a patched ath9k to have hostapd run >8 BSS on a single radio.
It works fine since years.


Yes, I'd love to see any patches you can share on this as well.

Thanks,
Ben



Regards,
M. Braun


Am 27. Juli 2018 15:35:28 MESZ schrieb Ben Greear :

Hello,

Has anyone tried making ath9k able to support 16 vAP interfaces on a
single
radio?  I seem to recall that there were limitations regarding beacon
timers and such, and that is why the current limit is 8?

Thanks,
Ben

--
Ben Greear 
Candela Technologies Inc  http://www.candelatech.com




Are these patches available somewhere?
I'm interested to play with them :)

BR
Matthias






--
Ben Greear 
Candela Technologies Inc  http://www.candelatech.com



Re: [PATCH 01/12] rtwlan: main files

2018-10-04 Thread Larry Finger

On 10/4/18 8:42 AM, Stanislaw Gruszka wrote:

On Thu, Oct 04, 2018 at 03:39:55PM +0300, Kalle Valo wrote:

Can we put the configuration file in the firmware directory?
Should we package them into binary files? Or just put the raw data.

We can test the performance for it. After we got the result, we will make a 
decision
about it. And if we decide to put them in the firmware directory, will send a 
patch.
For now, I think we can just leave them in the .c.


Yes, you could put the configuration files in the firmware directory.
I would put them in binary form, not as text files. That way the size
would be smaller, and it would not be possible to alter them,
particularly if the binary file is checksummed.

It would likely be OK if only the agc table was stored in this way.
That would take away about half of the lines in the 8822b table file.


So what's the worry here? The lines of source code, binary size or what?

  .../net/wireless/realtek/rtw88/rtw8822b_table.c| 20783 +++

Looking at the diffstat rtw8822b_table.c seems to be 20 kLOC, IMHO it's
not that bad as it's just data. But of course I might be missing
something as I haven't checked patches yet.


My concern was it's plenty of redundant data, for example:

 0x81C, 0xFF03,
 0x81C, 0xFE03,
 0x81C, 0xFD020003,
 0x81C, 0xFC040003,
 0x81C, 0xFB060003,
 0x81C, 0xFA080003,
 0x81C, 0xF90A0003,
 0x81C, 0xF80C0003,
 0x81C, 0xF70E0003,
 0x81C, 0xF613,

Approx 1 lines like this, braked by lines like this

 0x9012, 0x, 0x4000, 0x,

in more or less regular way.

Not big deal, but perhaps this could be coded in much more compact way.


What should be the tradeoff between large tables of redundant data and 
complicated generation and interpretation? I think this table should be 
converted to binary in its present form and added to the "firmware", the way 
that is done for b43. That way the source is smaller, and the loading will be 
only a bit more time consuming.


Larry



Re: [RFC v3 09/12] rtw88: chip files

2018-10-04 Thread Stanislaw Gruszka
On Wed, Oct 03, 2018 at 07:20:56PM +0800, yhchu...@realtek.com wrote:
> +static int rtw8822b_mac_init(struct rtw_dev *rtwdev)
> +{
> + u32 value32;
> +
> + rtw_write8(rtwdev, REG_SLOT, WLAN_SLOT_TIME);
> + rtw_write8(rtwdev, REG_PIFS, WLAN_PIFS_TIME);
> + rtw_write32(rtwdev, REG_SIFS, WLAN_SIFS_CFG);

Should this be changed depending on protocol/band i.e. diffrent 
for 11n : 11g and 2.4GHz : 5GHz?

Thanks
Stanislaw


Re: [RFC v3 08/12] rtw88: debug files

2018-10-04 Thread Stanislaw Gruszka
On Wed, Oct 03, 2018 at 07:20:55PM +0800, yhchu...@realtek.com wrote:
> +static int rtw_debugfs_get_rsvd_page(struct seq_file *m, void *v)
> +{
> + struct rtw_debugfs_priv *debugfs_priv = m->private;
> + struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
> + u8 page_size = rtwdev->chip->page_size;
> + u32 buf_size = debugfs_priv->rsvd_page.page_num * page_size;
> + u32 offset = debugfs_priv->rsvd_page.page_offset * page_size;
> + u8 *buf = vzalloc(buf_size);
Error check.

> +void rtw_debugfs_init(struct rtw_dev *rtwdev)
> +{
> + debugfs_topdir = debugfs_create_dir("rtw88", NULL);

You should use rtwdev->hw->wiphy->debugfsdir like other drivers.

Thanks
Stanislaw


Re: [RFC v3 07/12] rtw88: phy files

2018-10-04 Thread Stanislaw Gruszka
On Wed, Oct 03, 2018 at 07:20:54PM +0800, yhchu...@realtek.com wrote:
> +void rtw_phy_cfg_bb(struct rtw_dev *rtwdev, const struct rtw_table *tbl,
> + u32 addr, u32 data)
> +{
> + if (addr == 0xfe)
> + msleep(50);
> + else if (addr == 0xfd)
> + mdelay(5);
> + else if (addr == 0xfc)
> + mdelay(1);
> + else if (addr == 0xfb)
> + usleep_range(50, 60);
> + else if (addr == 0xfa)
> + udelay(5);
> + else if (addr == 0xf9)
> + udelay(1);
> + else
> + rtw_write32(rtwdev, addr, data);

This mix of mdelay(), msleep(), udelay() and usleep_range() looks strange.
You should eigher use atomic versions *delay or non-atomic *sleep
versions .

> +#define bcd_to_dec_pwr_by_rate(val, i) \
> + ({ \
> + typeof(val) __val_ = val; \
> + typeof(i) __i_ = i; \
> + ((s8)__val_ >> (__i_ * 8 + 4)) & 0xF)) * 10 + \
> +((__val_ >> (__i_ * 8)) & 0xF))); \
> +  })

Can use bcd2bin from include/linux/bcd.h instead ?


Thanks
Stanislaw 


Re: [RFC v2 02/12] rtw88: core files

2018-10-04 Thread Stanislaw Gruszka
On Thu, Oct 04, 2018 at 01:42:35PM +0200, Stanislaw Gruszka wrote:
> On Wed, Oct 03, 2018 at 04:02:18PM +0800, yhchu...@realtek.com wrote:
> > +static void rtw_restore_port_cfg(struct rtw_dev *rtwdev)
> > +{
> > +   struct rtw_vif *rtwvif;
> > +   u32 config = ~0;
> > +
> > +   rcu_read_lock();
> > +   list_for_each_entry(rtwvif, >vif_list, list)
> list_for_each_entry_rcu
> 
> > +void rtw_lps_enter_check(struct rtw_dev *rtwdev)
> > +{
> > +   struct rtw_vif *rtwvif, *lps_if;
> > +   u8 assoc_cnt = 0;
> > +
> > +   rcu_read_lock();
> > +   list_for_each_entry(rtwvif, >vif_list, list) {
> list_for_each_entry_rcu

Ok fixed in v3 , I just realized that I'm reviewing v2.



Re: [PATCH 01/12] rtwlan: main files

2018-10-04 Thread Stanislaw Gruszka
On Thu, Oct 04, 2018 at 03:39:55PM +0300, Kalle Valo wrote:
> >> Can we put the configuration file in the firmware directory?
> >> Should we package them into binary files? Or just put the raw data.
> >>
> >> We can test the performance for it. After we got the result, we will make 
> >> a decision
> >> about it. And if we decide to put them in the firmware directory, will 
> >> send a patch.
> >> For now, I think we can just leave them in the .c.
> >
> > Yes, you could put the configuration files in the firmware directory.
> > I would put them in binary form, not as text files. That way the size
> > would be smaller, and it would not be possible to alter them,
> > particularly if the binary file is checksummed.
> >
> > It would likely be OK if only the agc table was stored in this way.
> > That would take away about half of the lines in the 8822b table file.
> 
> So what's the worry here? The lines of source code, binary size or what?
> 
>  .../net/wireless/realtek/rtw88/rtw8822b_table.c| 20783 
> +++
> 
> Looking at the diffstat rtw8822b_table.c seems to be 20 kLOC, IMHO it's
> not that bad as it's just data. But of course I might be missing
> something as I haven't checked patches yet.

My concern was it's plenty of redundant data, for example:

0x81C, 0xFF03,
0x81C, 0xFE03,
0x81C, 0xFD020003,
0x81C, 0xFC040003,
0x81C, 0xFB060003,
0x81C, 0xFA080003,
0x81C, 0xF90A0003,
0x81C, 0xF80C0003,
0x81C, 0xF70E0003,
0x81C, 0xF613,

Approx 1 lines like this, braked by lines like this

0x9012, 0x, 0x4000, 0x,

in more or less regular way.

Not big deal, but perhaps this could be coded in much more compact way.

Regards
Stanislaw



Re: [RFC v2 03/12] rtw88: hci files

2018-10-04 Thread Stanislaw Gruszka
On Thu, Oct 04, 2018 at 03:02:13PM +0200, Stanislaw Gruszka wrote:
> > +   WARN(flag, "DBI write fail");
> We always print WARN, there is other return point in this function.
> 
> > +static void rtw_mdio_write(struct rtw_dev *rtwdev, u8 addr, u16 data, bool 
> > g1)
> 
> > +   WARN(wflag, "MDIO write fail");
> The same.

This is ok, I missed that WARN is printed only conditionally.


Re: [RFC v2 04/12] rtw88: trx files

2018-10-04 Thread Stanislaw Gruszka
On Wed, Oct 03, 2018 at 04:02:20PM +0800, yhchu...@realtek.com wrote:
> +static void rtw_rx_rssi_add(struct rtw_dev *rtwdev,
> + struct rtw_rx_pkt_stat *pkt_stat,
> + struct ieee80211_hdr *hdr)
> +{
> + struct ieee80211_vif *vif;
> + struct rtw_vif *rtwvif;
> + struct rtw_sta_info *si;
> + __le16 fc = hdr->frame_control;
> + u8 *bssid;
> + u8 macid = RTW_BC_MC_MACID;
> + bool match_bssid = false;
> + bool is_packet_match_bssid;
> + bool if_addr_match;
> + bool hw_err;
> + bool ctl;
> +
> + rcu_read_lock();
> +
> + bssid = get_hdr_bssid(hdr);
> + rtwvif = get_hdr_vif(rtwdev, hdr);
> + vif = rtwvif ? rtwvif->vif : NULL;
> + pkt_stat->vif = vif;
> + if (unlikely(is_broadcast_ether_addr(hdr->addr1) ||
> +  is_multicast_ether_addr(hdr->addr1)))
> + match_bssid = get_hdr_match_bssid(rtwdev, hdr, bssid);
> + else if (vif)
> + match_bssid = ether_addr_equal(vif->bss_conf.bssid, bssid);
> + si = get_hdr_sta(rtwdev, vif, hdr);
> + macid = si ? si->mac_id : RTW_BC_MC_MACID;
> + pkt_stat->mac_id = macid;
> + pkt_stat->si = si;
> +
> + if_addr_match = !!vif;
> + hw_err = pkt_stat->crc_err || pkt_stat->icv_err;
> + ctl = ieee80211_is_ctl(fc);
> + is_packet_match_bssid = !hw_err && !ctl && match_bssid;
> +
> + if (((match_bssid && if_addr_match) || ieee80211_is_beacon(fc)) &&
> + (!hw_err && !ctl) && (pkt_stat->phy_status && pkt_stat->si))
> + ewma_rssi_add(_stat->si->avg_rssi, pkt_stat->rssi);
> +
> + rcu_read_unlock();

What for rcu_read_lock/unlock is here ? Maybe is needed,
but perhaps not to protect entire function ?

> +static u8 get_tx_ampdu_factor(struct ieee80211_sta *sta)
> +{
> + u8 exp = sta->ht_cap.ampdu_factor;
> +
> + /* the least ampdu factor is 8K, and the value in the tx desc is the
> +  * max aggregation num, which represents val * 2 packets can be
> +  * aggregated in an AMPDU, so here we should use 8/2=4 as the base
> +  */
> + return (BIT(2) << exp) - 1;
Using 4 whould be much more readable.

> +static void rtw_tx_data_pkt_info_update(struct rtw_dev *rtwdev,
> + struct rtw_tx_pkt_info *pkt_info,
> + struct ieee80211_tx_control *control,
> + struct sk_buff *skb)
> +{

> + if (sta->vht_cap.vht_supported)
> + rate = get_highest_vht_tx_rate(rtwdev, sta);
> + else if (sta->ht_cap.ht_supported)
> + rate = get_highest_ht_tx_rate(rtwdev, sta);
> + else if (sta->supp_rates[0] <= 0xf)
> + rate = DESC_RATE11M;
> + else
> + rate = DESC_RATE54M;
No rate control, just use highest possible rate for each standard ?

> +
> + pkt_info->bmc = bmc;
> + pkt_info->sec_type = sec_type;
> + pkt_info->tx_pkt_size = skb->len;
> + pkt_info->offset = chip->tx_pkt_desc_sz;
> + pkt_info->qsel = skb->priority;

Shouldn't be qsel somehow mapped from skb->priority ?

Thanks
Stanislaw


Re: [RFC v2 03/12] rtw88: hci files

2018-10-04 Thread Stanislaw Gruszka
On Wed, Oct 03, 2018 at 04:02:19PM +0800, yhchu...@realtek.com wrote:
> +static inline u32
> +rtw_read_rf(struct rtw_dev *rtwdev, enum rtw_rf_path rf_path,
> + u32 addr, u32 mask)
> +{
> + unsigned long flags;
> + u32 val;
> +
> + spin_lock_irqsave(>rf_lock, flags);
> + val = rtwdev->chip->ops->read_rf(rtwdev, rf_path, addr, mask);
> + spin_unlock_irqrestore(>rf_lock, flags);

What for is rtwdev->rf_lock lock ? Is possible to call
rtw_read_rf() or rtw_write_rf() in some simultanious way ?

> +static int rtw_pci_reset_rx_desc(struct rtw_dev *rtwdev, struct sk_buff *skb,
> +  struct rtw_pci_rx_ring *rx_ring,
> +  u32 idx, u32 desc_sz)
> +{
> + struct pci_dev *pdev = to_pci_dev(rtwdev->dev);
> + struct rtw_pci_rx_buffer_desc *buf_desc;
> + int buf_sz = RTK_PCI_RX_BUF_SIZE;
> + dma_addr_t dma;
> +
> + if (!skb)
> + return -EINVAL;
Too late, see below.

> +
> + dma = pci_map_single(pdev, skb->data, buf_sz, PCI_DMA_FROMDEVICE);
> + if (pci_dma_mapping_error(pdev, dma))
> + return -EBUSY;
> +
> + *((dma_addr_t *)skb->cb) = dma;
> + buf_desc = (struct rtw_pci_rx_buffer_desc *)(rx_ring->r.head +
> +  idx * desc_sz);
> + memset(buf_desc, 0, sizeof(*buf_desc));
> + buf_desc->buf_size = cpu_to_le16(8216);

Why the difference between RTK_PCI_RX_BUF_SIZE = 9100 and this 8216 ? 

> +static int rtw_pci_init_rx_ring(struct rtw_dev *rtwdev,
> + struct rtw_pci_rx_ring *rx_ring,
> + u8 desc_size, u32 len)
> +{
> + struct pci_dev *pdev = to_pci_dev(rtwdev->dev);
> + struct sk_buff *skb = NULL;
> + dma_addr_t dma;
> + u8 *head;
> + int ring_sz = desc_size * len;
> + int buf_sz = RTK_PCI_RX_BUF_SIZE;
> + int i, allocated;
> + int ret = 0;
> +
> + head = pci_zalloc_consistent(pdev, ring_sz, );
> + if (!head) {
> + rtw_err(rtwdev, "failed to allocate rx ring\n");
> + return -ENOMEM;
> + }
> + rx_ring->r.head = head;
> +
> + for (i = 0; i < len; i++) {
> + skb = dev_alloc_skb(buf_sz);
> + memset(skb->data, 0, buf_sz);
No error check. Also I think you should use different version to 
allow specify GPF_KERNEL flag, this is not atomic context.

> +static void rtw_pci_dma_check(struct rtw_dev *rtwdev,
> +   struct rtw_pci_rx_ring *rx_ring,
> +   u32 idx)
> +{
> + struct rtw_chip_info *chip = rtwdev->chip;
> + struct rtw_pci_rx_buffer_desc *buf_desc;
> + u32 desc_sz = chip->rx_buf_desc_sz;
> + u16 total_pkt_size;
> + int i;
> +
> + buf_desc = (struct rtw_pci_rx_buffer_desc *)(rx_ring->r.head +
> +  idx * desc_sz);
> + for (i = 0; i < 20; i++) {
> + total_pkt_size = le16_to_cpu(buf_desc->total_pkt_size);
> + if (total_pkt_size)
> + return;
> + }
> +
> + if (i >= 20)
> + rtw_warn(rtwdev, "pci bus timeout, drop packet\n");
This is not right, most likely you need to use
dma_sync_single_for_cpu() .

> +static int rtw_pci_tx(struct rtw_dev *rtwdev,
> +   struct rtw_tx_pkt_info *pkt_info,
> +   struct sk_buff *skb)
> +{
> + struct rtw_pci *rtwpci = (struct rtw_pci *)rtwdev->priv;
> + struct rtw_pci_tx_ring *ring;
> + u8 queue = rtw_hw_queue_mapping(skb);
> + int ret;
> +
> + ret = rtw_pci_xmit(rtwdev, pkt_info, skb, queue);
> + if (ret)
> + return ret;
> +
> + ring = >tx_rings[queue];
> + if (avail_desc(ring->r.wp, ring->r.rp, ring->r.len) < 2) {
> + ieee80211_stop_queue(rtwdev->hw, skb_get_queue_mapping(skb));
> + ring->queue_stopped = true;
I think here is race condition with below code that wakes queue...

> + if (ring->queue_stopped &&
> + avail_desc(ring->r.wp, ring->r.rp, ring->r.len) > 4) {
> + q_map = skb_get_queue_mapping(skb);
> + ieee80211_wake_queue(hw, q_map);
> + ring->queue_stopped = false;

... here. This should be somehow synchronized.
> + }
> +
> + info = IEEE80211_SKB_CB(skb);
> + ieee80211_tx_info_clear_status(info);
> + info->flags |= IEEE80211_TX_STAT_ACK;
> + ieee80211_tx_status_irqsafe(hw, skb);

Always report ACK ?
> +
> +static irqreturn_t rtw_pci_interrupt_handler(int irq, void *dev)
> +{
> + struct rtw_dev *rtwdev = dev;
> + struct rtw_pci *rtwpci = (struct rtw_pci *)rtwdev->priv;
> + u32 irq_status[4];
> + unsigned long flags;
> +
> + spin_lock_irqsave(>irq_lock, flags);

flags not needed, interrupts are disabled in IRQ.

> + rtw_pci_disable_interrupt(rtwdev, rtwpci);

This seems to be not needed as well.

> 

Re: [PATCH 01/12] rtwlan: main files

2018-10-04 Thread Kalle Valo
Larry Finger  writes:

> On 10/2/18 9:57 PM, Tony Chuang wrote:
>>
>>
>>> -Original Message-
>>> From: Larry Finger [mailto:larry.fin...@gmail.com] On Behalf Of Larry Finger
>>> Sent: Tuesday, October 02, 2018 11:24 PM
>>> To: Stanislaw Gruszka; Tony Chuang
>>> Cc: kv...@codeaurora.org; linux-wireless@vger.kernel.org; Pkshih; Andy
>>> Huang
>>> Subject: Re: [PATCH 01/12] rtwlan: main files
>>>
>>> On 10/2/18 5:29 AM, Stanislaw Gruszka wrote:
 On Fri, Sep 28, 2018 at 11:32:41AM +, Tony Chuang wrote:
>>  if (rtw_hci_tx(rtwdev, _info, skb))
>>  dev_kfree_skb_any(skb)
>>
>> just to remove 'return;' and out label.
>
>
> OK, but why not use ieee80211_free_txskb, should it be better for
>>> mac80211?

 Yes, it is better as it also do some extra thing for dropped frame.

>>> OK, but I think this is needed, our tables have different forms 
>>
>> Not sure if that is better solution, but could the tables be pre-prarsed
>> by user-space program and then embed in the driver in ready to send
>> to the hardware from ?
>>
>> Also there are lot of redundancy in those tables, for example:
>>
>> +0x81C, 0xFF03,
>> +0x81C, 0xF503,
>> +0x81C, 0xF4020003,
>> +0x81C, 0xF3040003,
>> +0x81C, 0xF2060003,
>> +0x81C, 0xF1080003,
>> +0x81C, 0xF00A0003,
>> +0x81C, 0xEF0C0003,
>> +0x81C, 0xEE0E0003,
>> +0x81C, 0xED13,
>> +0x81C, 0xEC120003,
>> +0x81C, 0xEB140003,
>> +0x81C, 0xEA160003,
>> +0x81C, 0xE9180003,
>> +0x81C, 0xE81A0003,
>> +0x81C, 0xE71C0003,
>> +0x81C, 0xE61E0003,
>> +0x81C, 0xE523,
>>
>> 0x81C and 0003 repeats in many lines.
>>
>> This seems to be parse data, not that we have to write 0x81C
>> register many times. Would be possible to remove the redundancy?
>
>
> No, they cannot be removed, the sequence matters.
> And it is really writing to 0x81C ...
> It is really magic, I cannot believe to this, too.

 This is contradiction for what I asked you before, i.e. doing parsing
 in user space, but since we have this parsing mechanism in the driver
 perhaps the tables can be coded in some more compact way, for example:

 { prefix, suffix, len, {data} }

 { 0x81C, 0x0003, N ,
 { 0xFF02 , 0xF500 ,  , 0xE520 } }

 The rtw8822b_table.c file is quite big.
>>>
>>> You might also consider having these tables as a configuration file read 
>>> from
>>> the firmware directory.
>>>
>>
>> Hi Larry,
>>
>> Can we put the configuration file in the firmware directory?
>> Should we package them into binary files? Or just put the raw data.
>>
>> We can test the performance for it. After we got the result, we will make a 
>> decision
>> about it. And if we decide to put them in the firmware directory, will send 
>> a patch.
>> For now, I think we can just leave them in the .c.
>
> Yes, you could put the configuration files in the firmware directory.
> I would put them in binary form, not as text files. That way the size
> would be smaller, and it would not be possible to alter them,
> particularly if the binary file is checksummed.
>
> It would likely be OK if only the agc table was stored in this way.
> That would take away about half of the lines in the 8822b table file.

So what's the worry here? The lines of source code, binary size or what?

 .../net/wireless/realtek/rtw88/rtw8822b_table.c| 20783 +++

Looking at the diffstat rtw8822b_table.c seems to be 20 kLOC, IMHO it's
not that bad as it's just data. But of course I might be missing
something as I haven't checked patches yet.

-- 
Kalle Valo


Re: [PATCH 01/12] rtwlan: main files

2018-10-04 Thread Kalle Valo
Larry Finger  writes:

> On 10/2/18 5:29 AM, Stanislaw Gruszka wrote:
>> On Fri, Sep 28, 2018 at 11:32:41AM +, Tony Chuang wrote:
if (rtw_hci_tx(rtwdev, _info, skb))
dev_kfree_skb_any(skb)

 just to remove 'return;' and out label.
>>>
>>>
>>> OK, but why not use ieee80211_free_txskb, should it be better for mac80211?
>>
>> Yes, it is better as it also do some extra thing for dropped frame.
>>
> OK, but I think this is needed, our tables have different forms 

 Not sure if that is better solution, but could the tables be pre-prarsed
 by user-space program and then embed in the driver in ready to send
 to the hardware from ?

 Also there are lot of redundancy in those tables, for example:

 +  0x81C, 0xFF03,
 +  0x81C, 0xF503,
 +  0x81C, 0xF4020003,
 +  0x81C, 0xF3040003,
 +  0x81C, 0xF2060003,
 +  0x81C, 0xF1080003,
 +  0x81C, 0xF00A0003,
 +  0x81C, 0xEF0C0003,
 +  0x81C, 0xEE0E0003,
 +  0x81C, 0xED13,
 +  0x81C, 0xEC120003,
 +  0x81C, 0xEB140003,
 +  0x81C, 0xEA160003,
 +  0x81C, 0xE9180003,
 +  0x81C, 0xE81A0003,
 +  0x81C, 0xE71C0003,
 +  0x81C, 0xE61E0003,
 +  0x81C, 0xE523,

 0x81C and 0003 repeats in many lines.

 This seems to be parse data, not that we have to write 0x81C
 register many times. Would be possible to remove the redundancy?
>>>
>>>
>>> No, they cannot be removed, the sequence matters.
>>> And it is really writing to 0x81C ...
>>> It is really magic, I cannot believe to this, too.
>>
>> This is contradiction for what I asked you before, i.e. doing parsing
>> in user space, but since we have this parsing mechanism in the driver
>> perhaps the tables can be coded in some more compact way, for example:
>>
>> { prefix, suffix, len, {data} }
>>
>> { 0x81C, 0x0003, N ,
>>{ 0xFF02 , 0xF500 ,  , 0xE520 } }
>>
>> The rtw8822b_table.c file is quite big.
>
> You might also consider having these tables as a configuration file
> read from the firmware directory.

Configuration files for upstream drivers is something I would like to
avoid until we have a generic solution. That seems to come up now and
then but there does not seem to be any consensus how it should be
implemented.

-- 
Kalle Valo


Re: [PATCH 01/12] rtwlan: main files

2018-10-04 Thread Kalle Valo
Stanislaw Gruszka  writes:

> On Thu, Sep 27, 2018 at 10:40:44AM -0500, Larry Finger wrote:
>> On 9/27/18 8:50 AM, Stanislaw Gruszka wrote:
>> --snip
>> 
>> > 
>> > > +#define BIT_LEN_MASK_32(__bitlen) (0x >> (32 - (__bitlen)))
>> > > +#define BIT_OFFSET_LEN_MASK_32(__bitoffset, __bitlen)   
>> > >\
>> > > +(BIT_LEN_MASK_32(__bitlen) << (__bitoffset))
>> > > +#define LE_P4BYTE_TO_HOST_4BYTE(__start) (le32_to_cpu(*((__le32 
>> > > *)(__start
>> > > +#define LE_BITS_CLEARED_TO_4BYTE(__start, __bitoffset, __bitlen)
>> > >\
>> > > +(LE_P4BYTE_TO_HOST_4BYTE(__start) & 
>> > >\
>> > > + (~BIT_OFFSET_LEN_MASK_32(__bitoffset, __bitlen)))
>> > > +#define LE_BITS_TO_4BYTE(__start, __bitoffset, __bitlen)
>> > >\
>> > > +((LE_P4BYTE_TO_HOST_4BYTE(__start) >> (__bitoffset)) &  
>> > >\
>> > > + BIT_LEN_MASK_32(__bitlen))
>> > > +#define SET_BITS_TO_LE_4BYTE(__start, __bitoffset, __bitlen, __value)   
>> > >\
>> > > +do {
>> > >\
>> > > +*((__le32 *)(__start)) = \
>> > > +cpu_to_le32( \
>> > > +LE_BITS_CLEARED_TO_4BYTE(__start, __bitoffset, 
>> > > __bitlen) | \
>> > > +u32)__value) & BIT_LEN_MASK_32(__bitlen)) << 
>> > > (__bitoffset))\
>> > > +);  
>> > >\
>> > > +} while (0)

This is horrible.

>> Stanislaw,
>> 
>> I have never loved these macros, and it took a lot of time to get them to be
>> endian correct. Could you point me to a method that would overwrite a
>> portion of a 32-bit little-endian word that would be correct for both
>> little- and big-endian machines? Keep in mind that Kalle hates the use of
>> compile tests on __LITTLE_ENDIAN.
>
> Maybe something like this (not tested)
>
> #define SET_LE32(reg, off, len, val) \
>   ((reg & cpu_to_le32(~GENMASK(off + len - 1, off))) | cpu_to_le32(val << 
> off))
>
> ?
>
> There are plenty of bitops and endian primitives in kernel, it's
> very very unlikly you need custom macros for handle that.

Indeed, try avoiding reinventing wheel as much as possible.

-- 
Kalle Valo


Re: [PATCH 01/12] rtwlan: main files

2018-10-04 Thread Kalle Valo
Tony Chuang  writes:

> Hi Kale & Stanislaw,
>
> I am working on the driver code and making some changes that Stanislaw
> have mentioned. And I expected that I will finish them tomorrow, what
> should I do after I finished them?
>
> Should I send an RFCv2, or start a new RFC for it ?

Like Stanislaw said, RFCv2 is the right thing to do and I see that you
did that already.

> Because our driver will be renamed from rtwlan to rtw88 for
> 8822B/8822C

I like rtw88, a good choise.

-- 
Kalle Valo


Re: feedback on mainlining wilc1000 staging driver

2018-10-04 Thread Kalle Valo
Ajay Singh  writes:

> Hi Kalle,
>
> On Thu, 23 Aug 2018 16:37:45 +0530
> Kalle Valo  wrote:
>
>> Ajay Singh  writes:
>> 
>> >> >>> We need help to review and identify if there are any pending
>> >> >>> items for wilc1000 driver, so we can address those issues and
>> >> >>> make it ready to move to the wireless subsystem.
>> >> >>
>> >> >> I think the best way to get that forward is to submit a patch
>> >> >> (or patchset) to linux-wireless, that's the easiest for
>> >> >> reviewers.
>> >> >
>> >> > For brcm80211 drivers we used a single patch introducing it under
>> >> > the wireless drivers folder. Because it was quite a sizable
>> >> > patch we parked it on the wireless wiki page. Had a few
>> >> > iterations doing it like that.
>> >> 
>> >> Another option is to split it so that there's one patch per file,
>> >> should be even pretty easy to automate that. It's just so much
>> >> easier to comment on a patch submitted by email compared to the
>> >> reviewer manually copying code and then commenting it, yuck.
>> >>   
>> >
>> > Sure. I will prepare a patch per file send for review as its easy to
>> > review.
>> >
>> > As Greg suggested, I will wait for the merge window to close and
>> > after completing pending patches to staging, I will start the
>> > review.
>> >
>> > For my understanding, the patches for review will be based on
>> > wireless-testing branch.  
>> 
>> In this case I think wireless-drivers-next is the safest choise,
>> wireless-testing also has other trees which might cause conflicts etc.
>
> I have submitted a patch series for wilc1000 driver, single file
> per patch and its based on wireless-drivers-next. 
> I hope its done correctly, please provide inputs so we can
> address and make this driver ready for mainline.

Thanks, I see it in patchwork:

https://patchwork.kernel.org/project/linux-wireless/list/?series=23251=*=date

Do note that we have also another new driver (rtwlan/rtw88) under review
so review from the wireless folks might take some time.

-- 
Kalle Valo


Re: [PATCH v2] mt76x0: init: remove unnecessary configurations

2018-10-04 Thread Felix Fietkau
On 2018-10-01 16:20, Lorenzo Bianconi wrote:
> Remove leftover configuration for legacy devices in
> mt76x0_init_mac_registers routine. Moreover remove
> unnecessary msleep delay
> 
> Signed-off-by: Lorenzo Bianconi 
Merged, thanks.

- Felix


[RFC 4/7] mt76: use mt76x02_dev instead of mt76_dev in mt76x02_usb_mcu.c

2018-10-04 Thread Lorenzo Bianconi
Use mt76x02_dev data structure as reference in mt76x02_usb_mcu.c
instead of mt76_dev

Signed-off-by: Lorenzo Bianconi 
---
 .../wireless/mediatek/mt76/mt76x0/usb_mcu.c   |  7 +++--
 .../net/wireless/mediatek/mt76/mt76x02_usb.h  |  6 ++---
 .../wireless/mediatek/mt76/mt76x02_usb_mcu.c  | 27 +--
 .../wireless/mediatek/mt76/mt76x2/usb_mcu.c   | 11 
 4 files changed, 24 insertions(+), 27 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/usb_mcu.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/usb_mcu.c
index fb6fa1fa5548..a9f14d5149d1 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/usb_mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/usb_mcu.c
@@ -40,8 +40,7 @@ mt76x0u_upload_firmware(struct mt76x02_dev *dev,
ilm_len = le32_to_cpu(hdr->ilm_len) - MT_MCU_IVB_SIZE;
dev_dbg(dev->mt76.dev, "loading FW - ILM %u + IVB %u\n",
ilm_len, MT_MCU_IVB_SIZE);
-   err = mt76x02u_mcu_fw_send_data(>mt76,
-   fw_payload + MT_MCU_IVB_SIZE,
+   err = mt76x02u_mcu_fw_send_data(dev, fw_payload + MT_MCU_IVB_SIZE,
ilm_len, MCU_FW_URB_MAX_PAYLOAD,
MT_MCU_IVB_SIZE);
if (err)
@@ -49,7 +48,7 @@ mt76x0u_upload_firmware(struct mt76x02_dev *dev,
 
dlm_len = le32_to_cpu(hdr->dlm_len);
dev_dbg(dev->mt76.dev, "loading FW - DLM %u\n", dlm_len);
-   err = mt76x02u_mcu_fw_send_data(>mt76,
+   err = mt76x02u_mcu_fw_send_data(dev,
fw_payload + le32_to_cpu(hdr->ilm_len),
dlm_len, MCU_FW_URB_MAX_PAYLOAD,
MT_MCU_DLM_OFFSET);
@@ -121,7 +120,7 @@ static int mt76x0u_load_firmware(struct mt76x02_dev *dev)
mt76_set(dev, MT_USB_DMA_CFG,
 (MT_USB_DMA_CFG_RX_BULK_EN | MT_USB_DMA_CFG_TX_BULK_EN) |
 FIELD_PREP(MT_USB_DMA_CFG_RX_BULK_AGG_TOUT, 0x20));
-   mt76x02u_mcu_fw_reset(>mt76);
+   mt76x02u_mcu_fw_reset(dev);
usleep_range(5000, 6000);
 /*
mt76x0_rmw(dev, MT_PBF_CFG, 0, (MT_PBF_CFG_TX0Q_EN |
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_usb.h 
b/drivers/net/wireless/mediatek/mt76/mt76x02_usb.h
index 6b2138328eb2..28aabcfd1195 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02_usb.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_usb.h
@@ -17,11 +17,11 @@
 #ifndef __MT76x02_USB_H
 #define __MT76x02_USB_H
 
-#include "mt76.h"
+#include "mt76x02.h"
 
 void mt76x02u_init_mcu(struct mt76_dev *dev);
-void mt76x02u_mcu_fw_reset(struct mt76_dev *dev);
-int mt76x02u_mcu_fw_send_data(struct mt76_dev *dev, const void *data,
+void mt76x02u_mcu_fw_reset(struct mt76x02_dev *dev);
+int mt76x02u_mcu_fw_send_data(struct mt76x02_dev *dev, const void *data,
  int data_len, u32 max_payload, u32 offset);
 
 int mt76x02u_skb_dma_info(struct sk_buff *skb, int port, u32 flags);
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_usb_mcu.c 
b/drivers/net/wireless/mediatek/mt76/mt76x02_usb_mcu.c
index cb5f073f08af..da299b8a1334 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02_usb_mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_usb_mcu.c
@@ -17,8 +17,7 @@
 #include 
 #include 
 
-#include "mt76.h"
-#include "mt76x02_dma.h"
+#include "mt76x02.h"
 #include "mt76x02_mcu.h"
 #include "mt76x02_usb.h"
 
@@ -255,16 +254,16 @@ mt76x02u_mcu_rd_rp(struct mt76_dev *dev, u32 base,
return ret;
 }
 
-void mt76x02u_mcu_fw_reset(struct mt76_dev *dev)
+void mt76x02u_mcu_fw_reset(struct mt76x02_dev *dev)
 {
-   mt76u_vendor_request(dev, MT_VEND_DEV_MODE,
+   mt76u_vendor_request(>mt76, MT_VEND_DEV_MODE,
 USB_DIR_OUT | USB_TYPE_VENDOR,
 0x1, 0, NULL, 0);
 }
 EXPORT_SYMBOL_GPL(mt76x02u_mcu_fw_reset);
 
 static int
-__mt76x02u_mcu_fw_send_data(struct mt76_dev *dev, struct mt76u_buf *buf,
+__mt76x02u_mcu_fw_send_data(struct mt76x02_dev *dev, struct mt76u_buf *buf,
const void *fw_data, int len, u32 dst_addr)
 {
u8 *data = sg_virt(>urb->sg[0]);
@@ -281,14 +280,14 @@ __mt76x02u_mcu_fw_send_data(struct mt76_dev *dev, struct 
mt76u_buf *buf,
memcpy(data + sizeof(info), fw_data, len);
memset(data + sizeof(info) + len, 0, 4);
 
-   mt76u_single_wr(dev, MT_VEND_WRITE_FCE,
+   mt76u_single_wr(>mt76, MT_VEND_WRITE_FCE,
MT_FCE_DMA_ADDR, dst_addr);
len = roundup(len, 4);
-   mt76u_single_wr(dev, MT_VEND_WRITE_FCE,
+   mt76u_single_wr(>mt76, MT_VEND_WRITE_FCE,
MT_FCE_DMA_LEN, len << 16);
 
buf->len = MT_CMD_HDR_LEN + len + sizeof(info);
-   err = mt76u_submit_buf(dev, USB_DIR_OUT,
+   err = mt76u_submit_buf(>mt76, USB_DIR_OUT,
   MT_EP_OUT_INBAND_CMD,
   buf, GFP_KERNEL,
 

[RFC 6/7] mt76: use mt76x02_dev instead of mt76_dev in mt76x02_txrx.c

2018-10-04 Thread Lorenzo Bianconi
Use mt76x02_dev data structure as reference in mt76x02_txrx.c
instead of mt76_dev

Signed-off-by: Lorenzo Bianconi 
---
 drivers/net/wireless/mediatek/mt76/mt76x02.h  |  4 ++--
 .../net/wireless/mediatek/mt76/mt76x02_mac.c  |  5 ++---
 .../net/wireless/mediatek/mt76/mt76x02_txrx.c | 22 +--
 .../net/wireless/mediatek/mt76/mt76x02_util.c |  2 +-
 4 files changed, 15 insertions(+), 18 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02.h 
b/drivers/net/wireless/mediatek/mt76/mt76x02.h
index 17958be68b32..acb5673a838b 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02.h
@@ -136,9 +136,9 @@ 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,
+s8 mt76x02_tx_get_max_txpwr_adj(struct mt76x02_dev *dev,
const struct ieee80211_tx_rate *rate);
-s8 mt76x02_tx_get_txpwr_adj(struct mt76_dev *mdev, s8 txpwr, s8 max_txpwr_adj);
+s8 mt76x02_tx_get_txpwr_adj(struct mt76x02_dev *dev, s8 txpwr, s8 
max_txpwr_adj);
 void mt76x02_tx_set_txpwr_auto(struct mt76x02_dev *dev, s8 txpwr);
 int mt76x02_insert_hdr_pad(struct sk_buff *skb);
 void mt76x02_remove_hdr_pad(struct sk_buff *skb, int len);
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c 
b/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c
index 155106de2e17..c0ebade7ef17 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c
@@ -382,12 +382,11 @@ void mt76x02_mac_write_txwi(struct mt76x02_dev *dev, 
struct mt76x02_txwi *txwi,
nss = wcid->tx_rate_nss;
} else {
txwi->rate = mt76x02_mac_tx_rate_val(dev, rate, );
-   max_txpwr_adj = mt76x02_tx_get_max_txpwr_adj(>mt76, rate);
+   max_txpwr_adj = mt76x02_tx_get_max_txpwr_adj(dev, rate);
}
spin_unlock_bh(>mt76.lock);
 
-   txpwr_adj = mt76x02_tx_get_txpwr_adj(>mt76,
-dev->mt76.txpower_conf,
+   txpwr_adj = mt76x02_tx_get_txpwr_adj(dev, 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/mt76x02_txrx.c 
b/drivers/net/wireless/mediatek/mt76/mt76x02_txrx.c
index 865fa1b84086..d3de08872d6e 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02_txrx.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_txrx.c
@@ -71,7 +71,7 @@ void mt76x02_queue_rx_skb(struct mt76_dev *mdev, enum 
mt76_rxq_id q,
 }
 EXPORT_SYMBOL_GPL(mt76x02_queue_rx_skb);
 
-s8 mt76x02_tx_get_max_txpwr_adj(struct mt76_dev *dev,
+s8 mt76x02_tx_get_max_txpwr_adj(struct mt76x02_dev *dev,
const struct ieee80211_tx_rate *rate)
 {
s8 max_txpwr;
@@ -80,23 +80,23 @@ s8 mt76x02_tx_get_max_txpwr_adj(struct mt76_dev *dev,
u8 mcs = ieee80211_rate_get_vht_mcs(rate);
 
if (mcs == 8 || mcs == 9) {
-   max_txpwr = dev->rate_power.vht[8];
+   max_txpwr = dev->mt76.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];
+   max_txpwr = dev->mt76.rate_power.ht[idx & 0xf];
}
} else if (rate->flags & IEEE80211_TX_RC_MCS) {
-   max_txpwr = dev->rate_power.ht[rate->idx & 0xf];
+   max_txpwr = dev->mt76.rate_power.ht[rate->idx & 0xf];
} else {
-   enum nl80211_band band = dev->chandef.chan->band;
+   enum nl80211_band band = dev->mt76.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;
+   struct wiphy *wiphy = dev->mt76.hw->wiphy;
+   struct mt76_rate_power *rp = >mt76.rate_power;
 
r = >bands[band]->bitrates[rate->idx];
if (r->flags & IEEE80211_RATE_SHORT_PREAMBLE)
@@ -104,7 +104,7 @@ s8 mt76x02_tx_get_max_txpwr_adj(struct mt76_dev *dev,
else
max_txpwr = rp->ofdm[r->hw_value & 0x7];
} else {
-   max_txpwr = dev->rate_power.ofdm[rate->idx & 0x7];
+   max_txpwr = dev->mt76.rate_power.ofdm[rate->idx & 0x7];
}
}
 
@@ -112,10 +112,8 @@ s8 

[RFC 3/7] mt76: use mt76x02_dev instead of mt76_dev in mt76x02_util.c

2018-10-04 Thread Lorenzo Bianconi
Use mt76x02_dev data structure as reference in mt76x02_util.c
instead of mt76_dev

Signed-off-by: Lorenzo Bianconi 
---
 .../net/wireless/mediatek/mt76/mt76x0/init.c  |   2 +-
 drivers/net/wireless/mediatek/mt76/mt76x02.h  |   4 +-
 .../net/wireless/mediatek/mt76/mt76x02_util.c | 137 +-
 .../wireless/mediatek/mt76/mt76x2/pci_init.c  |   2 +-
 .../wireless/mediatek/mt76/mt76x2/usb_main.c  |   2 +-
 5 files changed, 75 insertions(+), 72 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/init.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/init.c
index abd8313f22e7..578f1b34f0f1 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/init.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/init.c
@@ -138,7 +138,7 @@ static void mt76x0_init_mac_registers(struct mt76x02_dev 
*dev)
 
RANDOM_WRITE(dev, common_mac_reg_table);
 
-   mt76x02_set_beacon_offsets(>mt76);
+   mt76x02_set_beacon_offsets(dev);
 
/* Enable PBF and MAC clock SYS_CTRL[11:10] = 0x3 */
RANDOM_WRITE(dev, mt76x0_mac_reg_table);
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02.h 
b/drivers/net/wireless/mediatek/mt76/mt76x02.h
index 65174817ebc4..408b2516f6fa 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02.h
@@ -119,7 +119,7 @@ int mt76x02_sta_add(struct ieee80211_hw *hw, struct 
ieee80211_vif *vif,
 int mt76x02_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  struct ieee80211_sta *sta);
 
-void mt76x02_vif_init(struct mt76_dev *dev, struct ieee80211_vif *vif,
+void mt76x02_vif_init(struct mt76x02_dev *dev, struct ieee80211_vif *vif,
 unsigned int idx);
 int mt76x02_add_interface(struct ieee80211_hw *hw,
 struct ieee80211_vif *vif);
@@ -156,7 +156,7 @@ int mt76x02_tx_prepare_skb(struct mt76_dev *mdev, void 
*txwi,
   u32 *tx_info);
 
 extern const u16 mt76x02_beacon_offsets[16];
-void mt76x02_set_beacon_offsets(struct mt76_dev *dev);
+void mt76x02_set_beacon_offsets(struct mt76x02_dev *dev);
 void mt76x02_set_irq_mask(struct mt76x02_dev *dev, u32 clear, u32 set);
 void mt76x02_mac_start(struct mt76x02_dev *dev);
 
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_util.c 
b/drivers/net/wireless/mediatek/mt76/mt76x02_util.c
index 5851ab6b7e26..04cf89412df3 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02_util.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_util.c
@@ -48,21 +48,21 @@ struct ieee80211_rate mt76x02_rates[] = {
 EXPORT_SYMBOL_GPL(mt76x02_rates);
 
 void mt76x02_configure_filter(struct ieee80211_hw *hw,
-unsigned int changed_flags,
-unsigned int *total_flags, u64 multicast)
+ unsigned int changed_flags,
+ unsigned int *total_flags, u64 multicast)
 {
-   struct mt76_dev *dev = hw->priv;
+   struct mt76x02_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);\
+   dev->mt76.rxfilter &= ~(_hw);   \
+   dev->mt76.rxfilter |= !(flags & FIF_##_flag) * (_hw);   \
} while (0)
 
-   mutex_lock(>mutex);
+   mutex_lock(>mt76.mutex);
 
-   dev->rxfilter &= ~MT_RX_FILTR_CFG_OTHER_BSS;
+   dev->mt76.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);
@@ -75,25 +75,25 @@ void mt76x02_configure_filter(struct ieee80211_hw *hw,
MT76_FILTER(PSPOLL, MT_RX_FILTR_CFG_PSPOLL);
 
*total_flags = flags;
-   dev->bus->wr(dev, MT_RX_FILTR_CFG, dev->rxfilter);
+   mt76_wr(dev, MT_RX_FILTR_CFG, dev->mt76.rxfilter);
 
-   mutex_unlock(>mutex);
+   mutex_unlock(>mt76.mutex);
 }
 EXPORT_SYMBOL_GPL(mt76x02_configure_filter);
 
 int mt76x02_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
-  struct ieee80211_sta *sta)
+   struct ieee80211_sta *sta)
 {
-   struct mt76_dev *dev = hw->priv;
-   struct mt76x02_sta *msta = (struct mt76x02_sta *) sta->drv_priv;
-   struct mt76x02_vif *mvif = (struct mt76x02_vif *) vif->drv_priv;
+   struct mt76x02_dev *dev = hw->priv;
+   struct mt76x02_sta *msta = (struct mt76x02_sta *)sta->drv_priv;
+   struct mt76x02_vif *mvif = (struct mt76x02_vif *)vif->drv_priv;
int ret = 0;
int idx = 0;
int i;
 
-   mutex_lock(>mutex);
+   mutex_lock(>mt76.mutex);
 
-   idx = mt76_wcid_alloc(dev->wcid_mask, ARRAY_SIZE(dev->wcid));
+   idx = mt76_wcid_alloc(dev->mt76.wcid_mask, ARRAY_SIZE(dev->mt76.wcid));
if (idx < 0) {
   

[RFC 5/7] mt76: use mt76x02_dev instead of mt76_dev in mt76x02_mac.c

2018-10-04 Thread Lorenzo Bianconi
Use mt76x02_dev data structure as reference in mt76x02_mac.c
instead of mt76_dev

Signed-off-by: Lorenzo Bianconi 
---
 .../wireless/mediatek/mt76/mt76x0/eeprom.c|   3 +-
 drivers/net/wireless/mediatek/mt76/mt76x02.h  |   2 +-
 .../net/wireless/mediatek/mt76/mt76x02_mac.c  | 124 +-
 .../net/wireless/mediatek/mt76/mt76x02_mac.h  |  24 ++--
 .../net/wireless/mediatek/mt76/mt76x02_mmio.c |   2 +-
 .../net/wireless/mediatek/mt76/mt76x02_txrx.c |   7 +-
 .../net/wireless/mediatek/mt76/mt76x02_usb.h  |   2 +-
 .../wireless/mediatek/mt76/mt76x02_usb_core.c |   3 +-
 .../net/wireless/mediatek/mt76/mt76x02_util.c |  24 ++--
 .../wireless/mediatek/mt76/mt76x2/pci_init.c  |   6 +-
 .../wireless/mediatek/mt76/mt76x2/pci_mac.c   |   2 +-
 .../wireless/mediatek/mt76/mt76x2/pci_main.c  |   2 +-
 .../wireless/mediatek/mt76/mt76x2/usb_init.c  |   3 +-
 .../wireless/mediatek/mt76/mt76x2/usb_main.c  |   2 +-
 14 files changed, 103 insertions(+), 103 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c
index 5735038c0e2d..bea1af7ffa73 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c
@@ -337,8 +337,7 @@ int mt76x0_eeprom_init(struct mt76x02_dev *dev)
dev_info(dev->mt76.dev, "EEPROM ver:%02hhx fae:%02hhx\n",
 version, fae);
 
-   mt76x02_mac_setaddr(>mt76,
-   dev->mt76.eeprom.data + MT_EE_MAC_ADDR);
+   mt76x02_mac_setaddr(dev, dev->mt76.eeprom.data + MT_EE_MAC_ADDR);
mt76x0_set_chip_cap(dev);
mt76x0_set_freq_offset(dev);
mt76x0_set_temp_offset(dev);
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02.h 
b/drivers/net/wireless/mediatek/mt76/mt76x02.h
index 408b2516f6fa..17958be68b32 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02.h
@@ -143,7 +143,7 @@ void mt76x02_tx_set_txpwr_auto(struct mt76x02_dev *dev, s8 
txpwr);
 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);
-bool mt76x02_tx_status_data(struct mt76_dev *dev, u8 *update);
+bool mt76x02_tx_status_data(struct mt76_dev *mdev, u8 *update);
 void mt76x02_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q,
  struct sk_buff *skb);
 void mt76x02_rx_poll_complete(struct mt76_dev *mdev, enum mt76_rxq_id q);
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c 
b/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c
index 244245418ebb..155106de2e17 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c
@@ -45,7 +45,7 @@ mt76x02_mac_get_key_info(struct ieee80211_key_conf *key, u8 
*key_data)
 }
 EXPORT_SYMBOL_GPL(mt76x02_mac_get_key_info);
 
-int mt76x02_mac_shared_key_setup(struct mt76_dev *dev, u8 vif_idx, u8 key_idx,
+int mt76x02_mac_shared_key_setup(struct mt76x02_dev *dev, u8 vif_idx, u8 
key_idx,
struct ieee80211_key_conf *key)
 {
enum mt76x02_cipher_type cipher;
@@ -56,19 +56,19 @@ int mt76x02_mac_shared_key_setup(struct mt76_dev *dev, u8 
vif_idx, u8 key_idx,
if (cipher == MT_CIPHER_NONE && key)
return -EOPNOTSUPP;
 
-   val = __mt76_rr(dev, MT_SKEY_MODE(vif_idx));
+   val = mt76_rr(dev, MT_SKEY_MODE(vif_idx));
val &= ~(MT_SKEY_MODE_MASK << MT_SKEY_MODE_SHIFT(vif_idx, key_idx));
val |= cipher << MT_SKEY_MODE_SHIFT(vif_idx, key_idx);
-   __mt76_wr(dev, MT_SKEY_MODE(vif_idx), val);
+   mt76_wr(dev, MT_SKEY_MODE(vif_idx), val);
 
-   __mt76_wr_copy(dev, MT_SKEY(vif_idx, key_idx), key_data,
-  sizeof(key_data));
+   mt76_wr_copy(dev, MT_SKEY(vif_idx, key_idx), key_data,
+sizeof(key_data));
 
return 0;
 }
 EXPORT_SYMBOL_GPL(mt76x02_mac_shared_key_setup);
 
-int mt76x02_mac_wcid_set_key(struct mt76_dev *dev, u8 idx,
+int mt76x02_mac_wcid_set_key(struct mt76x02_dev *dev, u8 idx,
struct ieee80211_key_conf *key)
 {
enum mt76x02_cipher_type cipher;
@@ -79,25 +79,26 @@ int mt76x02_mac_wcid_set_key(struct mt76_dev *dev, u8 idx,
if (cipher == MT_CIPHER_NONE && key)
return -EOPNOTSUPP;
 
-   __mt76_wr_copy(dev, MT_WCID_KEY(idx), key_data, sizeof(key_data));
-   __mt76_rmw_field(dev, MT_WCID_ATTR(idx), MT_WCID_ATTR_PKEY_MODE, 
cipher);
+   mt76_wr_copy(dev, MT_WCID_KEY(idx), key_data, sizeof(key_data));
+   mt76_rmw_field(dev, MT_WCID_ATTR(idx), MT_WCID_ATTR_PKEY_MODE, cipher);
 
memset(iv_data, 0, sizeof(iv_data));
if (key) {
-   __mt76_rmw_field(dev, MT_WCID_ATTR(idx), MT_WCID_ATTR_PAIRWISE,
-!!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE));
+   mt76_rmw_field(dev, 

[RFC 7/7] mt76: use mt76x02_dev instead of mt76_dev in mt76x02_eeprom.c

2018-10-04 Thread Lorenzo Bianconi
Use mt76x02_dev data structure as reference in mt76x02_eeprom.c
instead of mt76_dev

Signed-off-by: Lorenzo Bianconi 
---
 .../wireless/mediatek/mt76/mt76x0/eeprom.c| 50 ++--
 .../net/wireless/mediatek/mt76/mt76x0/pci.c   |  2 +-
 .../net/wireless/mediatek/mt76/mt76x0/phy.c   |  2 +-
 .../wireless/mediatek/mt76/mt76x02_eeprom.c   | 33 
 .../wireless/mediatek/mt76/mt76x02_eeprom.h   | 20 ++---
 .../wireless/mediatek/mt76/mt76x2/eeprom.c| 80 +--
 .../wireless/mediatek/mt76/mt76x2/eeprom.h|  2 +-
 .../net/wireless/mediatek/mt76/mt76x2/mcu.c   |  5 +-
 .../wireless/mediatek/mt76/mt76x2/pci_init.c  |  6 +-
 .../wireless/mediatek/mt76/mt76x2/pci_mcu.c   |  2 +-
 .../wireless/mediatek/mt76/mt76x2/pci_phy.c   |  8 +-
 .../net/wireless/mediatek/mt76/mt76x2/phy.c   | 12 +--
 .../wireless/mediatek/mt76/mt76x2/usb_init.c  |  2 +-
 .../wireless/mediatek/mt76/mt76x2/usb_mac.c   |  6 +-
 .../wireless/mediatek/mt76/mt76x2/usb_phy.c   |  6 +-
 15 files changed, 112 insertions(+), 124 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c
index bea1af7ffa73..1defb072ccbf 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c
@@ -31,8 +31,8 @@ mt76x0_efuse_physical_size_check(struct mt76x02_dev *dev)
int ret, i;
u32 start = 0, end = 0, cnt_free;
 
-   ret = mt76x02_get_efuse_data(>mt76, MT_EE_USAGE_MAP_START,
-data, sizeof(data), MT_EE_PHYSICAL_READ);
+   ret = mt76x02_get_efuse_data(dev, MT_EE_USAGE_MAP_START, data,
+sizeof(data), MT_EE_PHYSICAL_READ);
if (ret)
return ret;
 
@@ -55,10 +55,10 @@ mt76x0_efuse_physical_size_check(struct mt76x02_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);
+   u16 nic_conf0 = mt76x02_eeprom_get(dev, MT_EE_NIC_CONF_0);
+   u16 nic_conf1 = mt76x02_eeprom_get(dev, MT_EE_NIC_CONF_1);
 
-   mt76x02_eeprom_parse_hw_cap(>mt76);
+   mt76x02_eeprom_parse_hw_cap(dev);
dev_dbg(dev->mt76.dev, "2GHz %d 5GHz %d\n",
dev->mt76.cap.has_2ghz, dev->mt76.cap.has_5ghz);
 
@@ -86,7 +86,7 @@ static void mt76x0_set_temp_offset(struct mt76x02_dev *dev)
 {
u8 val;
 
-   val = mt76x02_eeprom_get(>mt76, MT_EE_2G_TARGET_POWER) >> 8;
+   val = mt76x02_eeprom_get(dev, MT_EE_2G_TARGET_POWER) >> 8;
if (mt76x02_field_valid(val))
dev->cal.rx.temp_offset = mt76x02_sign_extend(val, 8);
else
@@ -98,12 +98,12 @@ static void mt76x0_set_freq_offset(struct mt76x02_dev *dev)
struct mt76x02_rx_freq_cal *caldata = >cal.rx;
u8 val;
 
-   val = mt76x02_eeprom_get(>mt76, MT_EE_FREQ_OFFSET);
+   val = mt76x02_eeprom_get(dev, MT_EE_FREQ_OFFSET);
if (!mt76x02_field_valid(val))
val = 0;
caldata->freq_offset = val;
 
-   val = mt76x02_eeprom_get(>mt76, MT_EE_TSSI_BOUND4) >> 8;
+   val = mt76x02_eeprom_get(dev, MT_EE_TSSI_BOUND4) >> 8;
if (!mt76x02_field_valid(val))
val = 0;
 
@@ -118,10 +118,8 @@ void mt76x0_read_rx_gain(struct mt76x02_dev *dev)
u16 rssi_offset;
int i;
 
-   mt76x02_get_rx_gain(>mt76, chan->band, _offset,
-   _2g, lna_5g);
-   caldata->lna_gain = mt76x02_get_lna_gain(>mt76, _2g,
-lna_5g, chan);
+   mt76x02_get_rx_gain(dev, chan->band, _offset, _2g, lna_5g);
+   caldata->lna_gain = mt76x02_get_lna_gain(dev, _2g, lna_5g, chan);
 
for (i = 0; i < ARRAY_SIZE(caldata->rssi_offset); i++) {
val = rssi_offset >> (8 * i);
@@ -132,9 +130,9 @@ void mt76x0_read_rx_gain(struct mt76x02_dev *dev)
}
 }
 
-static s8 mt76x0_get_delta(struct mt76_dev *dev)
+static s8 mt76x0_get_delta(struct mt76x02_dev *dev)
 {
-   struct cfg80211_chan_def *chandef = >chandef;
+   struct cfg80211_chan_def *chandef = >mt76.chandef;
u8 val;
 
if (mt76x02_tssi_enabled(dev))
@@ -162,54 +160,54 @@ 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;
struct mt76_rate_power *t = >mt76.rate_power;
-   s8 delta = mt76x0_get_delta(>mt76);
+   s8 delta = mt76x0_get_delta(dev);
u16 val, addr;
 
memset(t, 0, sizeof(*t));
 
/* cck 1M, 2M, 5.5M, 11M */
-   val = mt76x02_eeprom_get(>mt76, MT_EE_TX_POWER_BYRATE_BASE);
+   val = mt76x02_eeprom_get(dev, MT_EE_TX_POWER_BYRATE_BASE);
t->cck[0] = t->cck[1] = s6_to_s8(val);
t->cck[2] = t->cck[3] = s6_to_s8(val >> 8);
 
/* ofdm 6M, 9M, 12M, 18M */
  

[RFC 0/7] use mt76x02_dev instead of mt76_dev as reference

2018-10-04 Thread Lorenzo Bianconi
Use mt76x02_dev data structure as reference in mt76x02 code
instead of mt76_dev one

Lorenzo Bianconi (7):
  mt76: use mt76x02_dev instead of mt76_dev in mt76x02_mcu.c
  mt76: use mt76x02_dev instead of mt76_dev in mt76x02_phy.c
  mt76: use mt76x02_dev instead of mt76_dev in mt76x02_util.c
  mt76: use mt76x02_dev instead of mt76_dev in mt76x02_usb_mcu.c
  mt76: use mt76x02_dev instead of mt76_dev in mt76x02_mac.c
  mt76: use mt76x02_dev instead of mt76_dev in mt76x02_txrx.c
  mt76: use mt76x02_dev instead of mt76_dev in mt76x02_eeprom.c

 .../wireless/mediatek/mt76/mt76x0/eeprom.c|  53 
 .../net/wireless/mediatek/mt76/mt76x0/init.c  |   4 +-
 .../net/wireless/mediatek/mt76/mt76x0/pci.c   |   4 +-
 .../net/wireless/mediatek/mt76/mt76x0/phy.c   |  34 +++--
 .../wireless/mediatek/mt76/mt76x0/usb_mcu.c   |   7 +-
 drivers/net/wireless/mediatek/mt76/mt76x02.h  |  10 +-
 .../wireless/mediatek/mt76/mt76x02_eeprom.c   |  33 +++--
 .../wireless/mediatek/mt76/mt76x02_eeprom.h   |  20 +--
 .../net/wireless/mediatek/mt76/mt76x02_mac.c  | 121 +-
 .../net/wireless/mediatek/mt76/mt76x02_mac.h  |  24 ++--
 .../net/wireless/mediatek/mt76/mt76x02_mcu.c  |  74 ++-
 .../net/wireless/mediatek/mt76/mt76x02_mcu.h  |  14 +-
 .../net/wireless/mediatek/mt76/mt76x02_mmio.c |   2 +-
 .../net/wireless/mediatek/mt76/mt76x02_phy.c  |  89 +++--
 .../net/wireless/mediatek/mt76/mt76x02_phy.h  |   8 +-
 .../net/wireless/mediatek/mt76/mt76x02_txrx.c |  29 ++---
 .../net/wireless/mediatek/mt76/mt76x02_usb.h  |   8 +-
 .../wireless/mediatek/mt76/mt76x02_usb_core.c |   3 +-
 .../wireless/mediatek/mt76/mt76x02_usb_mcu.c  |  27 ++--
 .../net/wireless/mediatek/mt76/mt76x02_util.c | 119 -
 .../wireless/mediatek/mt76/mt76x2/eeprom.c|  80 ++--
 .../wireless/mediatek/mt76/mt76x2/eeprom.h|   2 +-
 .../net/wireless/mediatek/mt76/mt76x2/mcu.c   |   5 +-
 .../wireless/mediatek/mt76/mt76x2/pci_init.c  |  18 +--
 .../wireless/mediatek/mt76/mt76x2/pci_mac.c   |   2 +-
 .../wireless/mediatek/mt76/mt76x2/pci_main.c  |   2 +-
 .../wireless/mediatek/mt76/mt76x2/pci_mcu.c   |   6 +-
 .../wireless/mediatek/mt76/mt76x2/pci_phy.c   |  32 ++---
 .../net/wireless/mediatek/mt76/mt76x2/phy.c   |  17 ++-
 .../wireless/mediatek/mt76/mt76x2/usb_init.c  |  11 +-
 .../wireless/mediatek/mt76/mt76x2/usb_mac.c   |   6 +-
 .../wireless/mediatek/mt76/mt76x2/usb_main.c  |   4 +-
 .../wireless/mediatek/mt76/mt76x2/usb_mcu.c   |  18 ++-
 .../wireless/mediatek/mt76/mt76x2/usb_phy.c   |  28 ++--
 34 files changed, 445 insertions(+), 469 deletions(-)

-- 
2.17.1



[RFC 1/7] mt76: use mt76x02_dev instead of mt76_dev in mt76x02_mcu.c

2018-10-04 Thread Lorenzo Bianconi
Use mt76x02_dev data structure as reference in mt76x02_mcu.c
instead of mt76_dev

Signed-off-by: Lorenzo Bianconi 
---
 .../net/wireless/mediatek/mt76/mt76x0/init.c  |  2 +-
 .../net/wireless/mediatek/mt76/mt76x0/pci.c   |  2 +-
 .../net/wireless/mediatek/mt76/mt76x0/phy.c   | 24 +++---
 .../net/wireless/mediatek/mt76/mt76x02_mcu.c  | 74 +--
 .../net/wireless/mediatek/mt76/mt76x02_mcu.h  | 14 ++--
 .../wireless/mediatek/mt76/mt76x2/pci_init.c  |  4 +-
 .../wireless/mediatek/mt76/mt76x2/pci_mcu.c   |  4 +-
 .../wireless/mediatek/mt76/mt76x2/pci_phy.c   | 22 +++---
 .../net/wireless/mediatek/mt76/mt76x2/phy.c   |  3 +-
 .../wireless/mediatek/mt76/mt76x2/usb_init.c  |  2 +-
 .../wireless/mediatek/mt76/mt76x2/usb_mcu.c   |  7 +-
 .../wireless/mediatek/mt76/mt76x2/usb_phy.c   | 20 +++--
 12 files changed, 86 insertions(+), 92 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/init.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/init.c
index ee2b8e885608..abd8313f22e7 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/init.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/init.c
@@ -280,7 +280,7 @@ int mt76x0_init_hardware(struct mt76x02_dev *dev)
return -ETIMEDOUT;
 
mt76x0_reset_csr_bbp(dev);
-   ret = mt76x02_mcu_function_select(>mt76, Q_SELECT, 1, false);
+   ret = mt76x02_mcu_function_select(dev, Q_SELECT, 1, false);
if (ret)
return ret;
 
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c
index 5c1045fbf699..3a5c7cd06265 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c
@@ -185,7 +185,7 @@ static void mt76x0e_cleanup(struct mt76x02_dev *dev)
mt76x0_chip_onoff(dev, false, false);
mt76x0e_stop_hw(dev);
mt76x02_dma_cleanup(dev);
-   mt76x02_mcu_cleanup(>mt76);
+   mt76x02_mcu_cleanup(dev);
 }
 
 static void
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
index 4850a2db18d7..a59e2dcd83f7 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
@@ -587,7 +587,7 @@ mt76x0_bbp_set_bw(struct mt76x02_dev *dev, enum 
nl80211_chan_width width)
return ;
}
 
-   mt76x02_mcu_function_select(>mt76, BW_SETTING, bw, false);
+   mt76x02_mcu_function_select(dev, BW_SETTING, bw, false);
 }
 
 void mt76x0_phy_set_txpower(struct mt76x02_dev *dev)
@@ -697,7 +697,7 @@ int mt76x0_phy_set_channel(struct mt76x02_dev *dev,
 
mt76x0_vco_cal(dev, channel);
if (scan)
-   mt76x02_mcu_calibrate(>mt76, MCU_CAL_RXDCOC, 1, false);
+   mt76x02_mcu_calibrate(dev, MCU_CAL_RXDCOC, 1, false);
 
mt76x0_phy_set_txpower(dev);
 
@@ -710,7 +710,7 @@ void mt76x0_phy_recalibrate_after_assoc(struct mt76x02_dev 
*dev)
u8 channel = dev->mt76.chandef.chan->hw_value;
int is_5ghz = (dev->mt76.chandef.chan->band == NL80211_BAND_5GHZ) ? 1 : 
0;
 
-   mt76x02_mcu_calibrate(>mt76, MCU_CAL_R, 0, false);
+   mt76x02_mcu_calibrate(dev, MCU_CAL_R, 0, false);
 
mt76x0_vco_cal(dev, channel);
 
@@ -722,22 +722,20 @@ void mt76x0_phy_recalibrate_after_assoc(struct 
mt76x02_dev *dev)
reg_val &= 0xff7e;
mt76_wr(dev, 0x2124, reg_val);
 
-   mt76x02_mcu_calibrate(>mt76, MCU_CAL_RXDCOC, 0, false);
+   mt76x02_mcu_calibrate(dev, MCU_CAL_RXDCOC, 0, false);
 
-   mt76x02_mcu_calibrate(>mt76, MCU_CAL_LC, is_5ghz, false);
-   mt76x02_mcu_calibrate(>mt76, MCU_CAL_LOFT, is_5ghz, false);
-   mt76x02_mcu_calibrate(>mt76, MCU_CAL_TXIQ, is_5ghz, false);
-   mt76x02_mcu_calibrate(>mt76, MCU_CAL_TX_GROUP_DELAY,
- is_5ghz, false);
-   mt76x02_mcu_calibrate(>mt76, MCU_CAL_RXIQ, is_5ghz, false);
-   mt76x02_mcu_calibrate(>mt76, MCU_CAL_RX_GROUP_DELAY,
- is_5ghz, false);
+   mt76x02_mcu_calibrate(dev, MCU_CAL_LC, is_5ghz, false);
+   mt76x02_mcu_calibrate(dev, MCU_CAL_LOFT, is_5ghz, false);
+   mt76x02_mcu_calibrate(dev, MCU_CAL_TXIQ, is_5ghz, false);
+   mt76x02_mcu_calibrate(dev, MCU_CAL_TX_GROUP_DELAY, is_5ghz, false);
+   mt76x02_mcu_calibrate(dev, MCU_CAL_RXIQ, is_5ghz, false);
+   mt76x02_mcu_calibrate(dev, MCU_CAL_RX_GROUP_DELAY, is_5ghz, false);
 
mt76_wr(dev, 0x2124, reg_val);
mt76_wr(dev, MT_TX_ALC_CFG_0, tx_alc);
msleep(100);
 
-   mt76x02_mcu_calibrate(>mt76, MCU_CAL_RXDCOC, 1, false);
+   mt76x02_mcu_calibrate(dev, MCU_CAL_RXDCOC, 1, false);
 }
 
 void mt76x0_agc_save(struct mt76x02_dev *dev)
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_mcu.c 
b/drivers/net/wireless/mediatek/mt76/mt76x02_mcu.c
index 6d565133b7af..1b853bb723fb 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02_mcu.c
+++ 

[RFC 2/7] mt76: use mt76x02_dev instead of mt76_dev in mt76x02_phy.c

2018-10-04 Thread Lorenzo Bianconi
Use mt76x02_dev data structure as reference in mt76x02_phy.c
instead of mt76_dev

Signed-off-by: Lorenzo Bianconi 
---
 .../net/wireless/mediatek/mt76/mt76x0/phy.c   |  8 +-
 .../net/wireless/mediatek/mt76/mt76x02_phy.c  | 89 +--
 .../net/wireless/mediatek/mt76/mt76x02_phy.h  |  8 +-
 .../wireless/mediatek/mt76/mt76x2/pci_phy.c   |  2 +-
 .../net/wireless/mediatek/mt76/mt76x2/phy.c   |  2 +-
 .../wireless/mediatek/mt76/mt76x2/usb_init.c  |  4 +-
 .../wireless/mediatek/mt76/mt76x2/usb_phy.c   |  2 +-
 7 files changed, 56 insertions(+), 59 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
index a59e2dcd83f7..376f2dbf013d 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
@@ -603,7 +603,7 @@ void mt76x0_phy_set_txpower(struct mt76x02_dev *dev)
dev->mt76.txpower_cur = mt76x02_get_max_rate_power(t);
mt76x02_add_rate_power_offset(t, -info[0]);
 
-   mt76x02_phy_set_txpower(>mt76, info[0], info[1]);
+   mt76x02_phy_set_txpower(dev, info[0], info[1]);
 }
 
 int mt76x0_phy_set_channel(struct mt76x02_dev *dev,
@@ -800,7 +800,7 @@ static void mt76x0_dynamic_vga_tuning(struct mt76x02_dev 
*dev)
int avg_rssi;
 
init_vga = chandef->chan->band == NL80211_BAND_5GHZ ? 0x54 : 0x4E;
-   avg_rssi = mt76x02_phy_get_min_avg_rssi(>mt76);
+   avg_rssi = mt76x02_phy_get_min_avg_rssi(dev);
if (avg_rssi > -60)
init_vga -= 0x20;
else if (avg_rssi > -70)
@@ -882,6 +882,6 @@ void mt76x0_phy_init(struct mt76x02_dev *dev)
INIT_DELAYED_WORK(>cal_work, mt76x0_phy_calibrate);
 
mt76x0_rf_init(dev);
-   mt76x02_phy_set_rxpath(>mt76);
-   mt76x02_phy_set_txdac(>mt76);
+   mt76x02_phy_set_rxpath(dev);
+   mt76x02_phy_set_txdac(dev);
 }
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_phy.c 
b/drivers/net/wireless/mediatek/mt76/mt76x02_phy.c
index d31ce1d7b689..c398471b6376 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02_phy.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_phy.c
@@ -17,18 +17,17 @@
 
 #include 
 
-#include "mt76.h"
+#include "mt76x02.h"
 #include "mt76x02_phy.h"
-#include "mt76x02_mac.h"
 
-void mt76x02_phy_set_rxpath(struct mt76_dev *dev)
+void mt76x02_phy_set_rxpath(struct mt76x02_dev *dev)
 {
u32 val;
 
-   val = __mt76_rr(dev, MT_BBP(AGC, 0));
+   val = mt76_rr(dev, MT_BBP(AGC, 0));
val &= ~BIT(4);
 
-   switch (dev->chainmask & 0xf) {
+   switch (dev->mt76.chainmask & 0xf) {
case 2:
val |= BIT(3);
break;
@@ -37,23 +36,23 @@ void mt76x02_phy_set_rxpath(struct mt76_dev *dev)
break;
}
 
-   __mt76_wr(dev, MT_BBP(AGC, 0), val);
+   mt76_wr(dev, MT_BBP(AGC, 0), val);
mb();
-   val = __mt76_rr(dev, MT_BBP(AGC, 0));
+   val = mt76_rr(dev, MT_BBP(AGC, 0));
 }
 EXPORT_SYMBOL_GPL(mt76x02_phy_set_rxpath);
 
-void mt76x02_phy_set_txdac(struct mt76_dev *dev)
+void mt76x02_phy_set_txdac(struct mt76x02_dev *dev)
 {
int txpath;
 
-   txpath = (dev->chainmask >> 8) & 0xf;
+   txpath = (dev->mt76.chainmask >> 8) & 0xf;
switch (txpath) {
case 2:
-   __mt76_set(dev, MT_BBP(TXBE, 5), 0x3);
+   mt76_set(dev, MT_BBP(TXBE, 5), 0x3);
break;
default:
-   __mt76_clear(dev, MT_BBP(TXBE, 5), 0x3);
+   mt76_clear(dev, MT_BBP(TXBE, 5), 0x3);
break;
}
 }
@@ -102,40 +101,38 @@ void mt76x02_add_rate_power_offset(struct mt76_rate_power 
*r, int offset)
 }
 EXPORT_SYMBOL_GPL(mt76x02_add_rate_power_offset);
 
-void mt76x02_phy_set_txpower(struct mt76_dev *dev, int txp_0, int txp_1)
+void mt76x02_phy_set_txpower(struct mt76x02_dev *dev, int txp_0, int txp_1)
 {
-   struct mt76_rate_power *t = >rate_power;
-
-   __mt76_rmw_field(dev, MT_TX_ALC_CFG_0, MT_TX_ALC_CFG_0_CH_INIT_0,
-txp_0);
-   __mt76_rmw_field(dev, MT_TX_ALC_CFG_0, MT_TX_ALC_CFG_0_CH_INIT_1,
-txp_1);
-
-   __mt76_wr(dev, MT_TX_PWR_CFG_0,
- mt76x02_tx_power_mask(t->cck[0], t->cck[2], t->ofdm[0],
-   t->ofdm[2]));
-   __mt76_wr(dev, MT_TX_PWR_CFG_1,
- mt76x02_tx_power_mask(t->ofdm[4], t->ofdm[6], t->ht[0],
-   t->ht[2]));
-   __mt76_wr(dev, MT_TX_PWR_CFG_2,
- mt76x02_tx_power_mask(t->ht[4], t->ht[6], t->ht[8],
-   t->ht[10]));
-   __mt76_wr(dev, MT_TX_PWR_CFG_3,
- mt76x02_tx_power_mask(t->ht[12], t->ht[14], t->stbc[0],
-   t->stbc[2]));
-   __mt76_wr(dev, MT_TX_PWR_CFG_4,
- mt76x02_tx_power_mask(t->stbc[4], t->stbc[6], 0, 0));
-   __mt76_wr(dev, MT_TX_PWR_CFG_7,
-

Re: [RFC v2 02/12] rtw88: core files

2018-10-04 Thread Stanislaw Gruszka
On Wed, Oct 03, 2018 at 04:02:18PM +0800, yhchu...@realtek.com wrote:
> +static void rtw_restore_port_cfg(struct rtw_dev *rtwdev)
> +{
> + struct rtw_vif *rtwvif;
> + u32 config = ~0;
> +
> + rcu_read_lock();
> + list_for_each_entry(rtwvif, >vif_list, list)
list_for_each_entry_rcu

> +void rtw_lps_enter_check(struct rtw_dev *rtwdev)
> +{
> + struct rtw_vif *rtwvif, *lps_if;
> + u8 assoc_cnt = 0;
> +
> + rcu_read_lock();
> + list_for_each_entry(rtwvif, >vif_list, list) {
list_for_each_entry_rcu

> +static struct country_code_to_enum_rd all_countries[] = {
> + {COUNTRY_CODE_FCC, "US"},
> + {COUNTRY_CODE_IC, "US"},
> + {COUNTRY_CODE_ETSI, "EC"},
> + {COUNTRY_CODE_SPAIN, "EC"},
> + {COUNTRY_CODE_FRANCE, "EC"},
> + {COUNTRY_CODE_MKK, "JP"},
> + {COUNTRY_CODE_MKK1, "JP"},
> + {COUNTRY_CODE_ISRAEL, "EC"},
> + {COUNTRY_CODE_TELEC, "JP"},
> + {COUNTRY_CODE_MIC, "JP"},
> + {COUNTRY_CODE_GLOBAL_DOMAIN, "JP"},
> + {COUNTRY_CODE_WORLD_WIDE_13, "EC"},
> + {COUNTRY_CODE_TELEC_NETGEAR, "EC"},
> + {COUNTRY_CODE_WORLD_WIDE_13_5G_ALL, "US"},
> +};
> +
> +/* Only these channels allow active
> + * scan on all world regulatory domains
> + */
> +#define RTW_2GHZ_CH01_11 \
> + REG_RULE(2412 - 10, 2462 + 10, 40, 0, 20, 0)

> +static const
> +struct ieee80211_regdomain *rtw_regdomain_select(struct rtw_regulatory *reg)
> +{
> + switch (reg->country_code) {
> + case COUNTRY_CODE_FCC:
> + return _regdom_no_midband;
> + case COUNTRY_CODE_IC:
> + return _regdom_11;
> + case COUNTRY_CODE_TELEC_NETGEAR:
> + return _regdom_60_64;
> + case COUNTRY_CODE_ETSI:
> + case COUNTRY_CODE_SPAIN:
> + case COUNTRY_CODE_FRANCE:
> + case COUNTRY_CODE_ISRAEL:
> + return _regdom_12_13;
> + case COUNTRY_CODE_MKK:
> + case COUNTRY_CODE_MKK1:
> + case COUNTRY_CODE_TELEC:
> + case COUNTRY_CODE_MIC:
> + return _regdom_14_60_64;
> + case COUNTRY_CODE_GLOBAL_DOMAIN:
> + return _regdom_14;
> + case COUNTRY_CODE_WORLD_WIDE_13:
> + case COUNTRY_CODE_WORLD_WIDE_13_5G_ALL:
> + return _regdom_12_13_5g_all;
> + default:
> + return _regdom_no_midband;
> + }

I'm not an expert on this, but I wonder if this is really needed
and standard linux regd stuff can not be used and regulatory
rules read from wireless-regd data-base.

Thanks
Stanislaw


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

2018-10-04 Thread Felix Fietkau
On 2018-10-01 18:58, Lorenzo Bianconi wrote:
> 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
Merged, thanks.

- Felix


Re: [RFC v2 06/12] rtw88: fw and efuse files

2018-10-04 Thread Stanislaw Gruszka
Hi

On Wed, Oct 03, 2018 at 04:02:22PM +0800, yhchu...@realtek.com wrote:
> +void rtw_fw_do_iqk(struct rtw_dev *rtwdev, struct rtw_iqk_para *para)
> +{
> + u8 h2c_pkt[H2C_PKT_SIZE] = {0};

Not sure if '= {0}' work as expected for arrays, you
want to nulify first byte or whole h2c_pkt ?

> +void rtw_add_rsvd_page(struct rtw_dev *rtwdev, enum rtw_rsvd_packet_type 
> type,
> +bool txdesc)
> +{
> + struct rtw_rsvd_page *rsvd_pkt;
> +
> + list_for_each_entry(rsvd_pkt, >rsvd_page_list, list) {
> + if (rsvd_pkt->type == type)
> + return;
> + }
> +
> + rsvd_pkt = kmalloc(sizeof(*rsvd_pkt),
> +in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);

It's never called from interrupt. You have to check kmalloc output value.

> + rsvd_pkt->type = type;
> + rsvd_pkt->add_txdesc = txdesc;
> + list_add_tail(_pkt->list, >rsvd_page_list);

> +
> +void rtw_reset_rsvd_page(struct rtw_dev *rtwdev)
> +{
> + struct rtw_rsvd_page *rsvd_pkt, *tmp;
> +
> + list_for_each_entry_safe(rsvd_pkt, tmp, >rsvd_page_list, list) {
> + if (rsvd_pkt->type == RSVD_BEACON)
> + continue;
> + list_del(_pkt->list);
> + kfree(rsvd_pkt);
> + }

It also not clear how the list is protected agains concurrent access.
However seems like much simpler solution would be use array instead of
the list. For example above code could be replaced by:

for (i = RSVD_BEACON + 1; i <= RSVD_QOS_NULL ; i++) {
kfree(rwdev->rsvd_page_arr[i]));
rsvd_page_arr[i] = NULL;
}

And other operations like adding / removing / checking if present could
be simplified as well.

Also RSVD_PROBE_RESP page is never created.

> + *size = (total_page - 1) * page_size + page_margin;
> + buf = kzalloc(*size, GFP_KERNEL | GFP_ATOMIC);

Those GPF flags contradict to each other :-)
and buf not checked agains NULL.

Thanks
Stanislaw


Re: [PATCH 0/3] fix mt76x0u driver hw stop sequence

2018-10-04 Thread Felix Fietkau
On 2018-10-03 12:52, Lorenzo Bianconi wrote:
> Fix two issue introduced in mt76x0u driver with latest rework to
> share hw initialization between mt760 and mt76x2 drivers
Merged, thanks.

- Felix



[PATCH 4/5] mt76x0: correct RF reg pairs write for PCIe

2018-10-04 Thread Stanislaw Gruszka
We have to use RF CSR method for PCIe.

Signed-off-by: Stanislaw Gruszka 
---
 drivers/net/wireless/mediatek/mt76/mt76x0/phy.c | 19 ---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
index da4569f00794..8e4194e59398 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
@@ -173,9 +173,22 @@ static int mt76x0_rf_csr_rr(struct mt76x02_dev *dev, u32 
offset)
 }
 #endif
 
-#define RF_RANDOM_WRITE(dev, tab)  \
-   mt76_wr_rp(dev, MT_MCU_MEMMAP_RF,   \
-  tab, ARRAY_SIZE(tab))
+static void
+mt76x0_rf_csr_wr_rp(struct mt76x02_dev *dev, const struct mt76_reg_pair *data,
+   int n)
+{
+   while (n-- > 0) {
+   mt76x0_rf_csr_wr(dev, data->reg, data->value);
+   data++;
+   }
+}
+
+#define RF_RANDOM_WRITE(dev, tab) do { \
+   if (mt76_is_mmio(dev))  \
+   mt76x0_rf_csr_wr_rp(dev, tab, ARRAY_SIZE(tab)); \
+   else\
+   mt76_wr_rp(dev, MT_MCU_MEMMAP_RF, tab, ARRAY_SIZE(tab));\
+} while (0)
 
 int mt76x0_wait_bbp_ready(struct mt76x02_dev *dev)
 {
-- 
1.9.3



[PATCH 1/5] mt76x0: print BBP version only for debug

2018-10-04 Thread Stanislaw Gruszka
Use dev_dbg to print BBP version.

Signed-off-by: Stanislaw Gruszka 
---
 drivers/net/wireless/mediatek/mt76/mt76x0/phy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
index ba3b5847af48..cbbfd5193d9c 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
@@ -186,7 +186,6 @@ int mt76x0_wait_bbp_ready(struct mt76x02_dev *dev)
 
do {
val = mt76_rr(dev, MT_BBP(CORE, 0));
-   printk("BBP version %08x\n", val);
if (val && ~val)
break;
} while (--i);
@@ -196,6 +195,7 @@ int mt76x0_wait_bbp_ready(struct mt76x02_dev *dev)
return -EIO;
}
 
+   dev_dbg(dev->mt76.dev, "BBP version %08x\n", val);
return 0;
 }
 
-- 
1.9.3



[PATCH 2/5] mt76x0: correct RF access via RF_CSR regiser.

2018-10-04 Thread Stanislaw Gruszka
PCIe version don't use MCU for RF regsisters access. We need
to correct RF CSR method to support up to 127 RF registers.

Signed-off-by: Stanislaw Gruszka 
---
 drivers/net/wireless/mediatek/mt76/mt76x0/phy.c   | 6 ++
 drivers/net/wireless/mediatek/mt76/mt76x02_regs.h | 4 ++--
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
index cbbfd5193d9c..da4569f00794 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
@@ -37,7 +37,7 @@
bank = MT_RF_BANK(offset);
reg = MT_RF_REG(offset);
 
-   if (WARN_ON_ONCE(reg > 64) || WARN_ON_ONCE(bank) > 8)
+   if (WARN_ON_ONCE(reg > 127) || WARN_ON_ONCE(bank) > 8)
return -EINVAL;
 
mutex_lock(>phy_mutex);
@@ -76,7 +76,7 @@ static int mt76x0_rf_csr_rr(struct mt76x02_dev *dev, u32 
offset)
bank = MT_RF_BANK(offset);
reg = MT_RF_REG(offset);
 
-   if (WARN_ON_ONCE(reg > 64) || WARN_ON_ONCE(bank) > 8)
+   if (WARN_ON_ONCE(reg > 127) || WARN_ON_ONCE(bank) > 8)
return -EINVAL;
 
mutex_lock(>phy_mutex);
@@ -119,7 +119,6 @@ static int mt76x0_rf_csr_rr(struct mt76x02_dev *dev, u32 
offset)
 
return mt76_wr_rp(dev, MT_MCU_MEMMAP_RF, , 1);
} else {
-   WARN_ON_ONCE(1);
return mt76x0_rf_csr_wr(dev, offset, val);
}
 }
@@ -138,7 +137,6 @@ static int mt76x0_rf_csr_rr(struct mt76x02_dev *dev, u32 
offset)
ret = mt76_rd_rp(dev, MT_MCU_MEMMAP_RF, , 1);
val = pair.value;
} else {
-   WARN_ON_ONCE(1);
ret = val = mt76x0_rf_csr_rr(dev, offset);
}
 
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_regs.h 
b/drivers/net/wireless/mediatek/mt76/mt76x02_regs.h
index 24d1e6d747dd..f7de77d09d28 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02_regs.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_regs.h
@@ -205,8 +205,8 @@
 #define MT_TXQ_STA 0x0434
 #defineMT_RF_CSR_CFG   0x0500
 #define MT_RF_CSR_CFG_DATA GENMASK(7, 0)
-#define MT_RF_CSR_CFG_REG_ID   GENMASK(13, 8)
-#define MT_RF_CSR_CFG_REG_BANK GENMASK(17, 14)
+#define MT_RF_CSR_CFG_REG_ID   GENMASK(14, 8)
+#define MT_RF_CSR_CFG_REG_BANK GENMASK(17, 15)
 #define MT_RF_CSR_CFG_WR   BIT(30)
 #define MT_RF_CSR_CFG_KICK BIT(31)
 
-- 
1.9.3



[PATCH 5/5] mt76x0: use bus helper to identify rf access method

2018-10-04 Thread Stanislaw Gruszka
Use mt76_is_usb() to identify RF access method instead of
MT76_STATE_MCU_RUNNING flag and add warning since MCU has
to be initialized before we can access RF registers via MCU.

Signed-off-by: Stanislaw Gruszka 
---
 drivers/net/wireless/mediatek/mt76/mt76x0/phy.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
index 8e4194e59398..202f436eb358 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
@@ -111,12 +111,14 @@ static int mt76x0_rf_csr_rr(struct mt76x02_dev *dev, u32 
offset)
 static int
 rf_wr(struct mt76x02_dev *dev, u32 offset, u8 val)
 {
-   if (test_bit(MT76_STATE_MCU_RUNNING, >mt76.state)) {
+   if (mt76_is_usb(dev)) {
struct mt76_reg_pair pair = {
.reg = offset,
.value = val,
};
 
+   WARN_ON_ONCE(!test_bit(MT76_STATE_MCU_RUNNING,
+>mt76.state));
return mt76_wr_rp(dev, MT_MCU_MEMMAP_RF, , 1);
} else {
return mt76x0_rf_csr_wr(dev, offset, val);
@@ -129,11 +131,13 @@ static int mt76x0_rf_csr_rr(struct mt76x02_dev *dev, u32 
offset)
int ret;
u32 val;
 
-   if (test_bit(MT76_STATE_MCU_RUNNING, >mt76.state)) {
+   if (mt76_is_usb(dev)) {
struct mt76_reg_pair pair = {
.reg = offset,
};
 
+   WARN_ON_ONCE(!test_bit(MT76_STATE_MCU_RUNNING,
+>mt76.state));
ret = mt76_rd_rp(dev, MT_MCU_MEMMAP_RF, , 1);
val = pair.value;
} else {
-- 
1.9.3



[PATCH 3/5] mt76: allow to identify bus

2018-10-04 Thread Stanislaw Gruszka
Add helpers to identify bus type.

Signed-off-by: Stanislaw Gruszka 
---
 drivers/net/wireless/mediatek/mt76/mmio.c | 1 +
 drivers/net/wireless/mediatek/mt76/mt76.h | 9 +
 drivers/net/wireless/mediatek/mt76/usb.c  | 1 +
 3 files changed, 11 insertions(+)

diff --git a/drivers/net/wireless/mediatek/mt76/mmio.c 
b/drivers/net/wireless/mediatek/mt76/mmio.c
index 30a5d928e655..1d6bbce76041 100644
--- a/drivers/net/wireless/mediatek/mt76/mmio.c
+++ b/drivers/net/wireless/mediatek/mt76/mmio.c
@@ -79,6 +79,7 @@ void mt76_mmio_init(struct mt76_dev *dev, void __iomem *regs)
.copy = mt76_mmio_copy,
.wr_rp = mt76_mmio_wr_rp,
.rd_rp = mt76_mmio_rd_rp,
+   .type = MT76_BUS_MMIO,
};
 
dev->bus = _mmio_ops;
diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h 
b/drivers/net/wireless/mediatek/mt76/mt76.h
index f723a07cab29..3bfa7f5e3513 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76.h
@@ -38,6 +38,11 @@ struct mt76_reg_pair {
u32 value;
 };
 
+enum mt76_bus_type {
+   MT76_BUS_MMIO,
+   MT76_BUS_USB,
+};
+
 struct mt76_bus_ops {
u32 (*rr)(struct mt76_dev *dev, u32 offset);
void (*wr)(struct mt76_dev *dev, u32 offset, u32 val);
@@ -48,8 +53,12 @@ struct mt76_bus_ops {
 const struct mt76_reg_pair *rp, int len);
int (*rd_rp)(struct mt76_dev *dev, u32 base,
 struct mt76_reg_pair *rp, int len);
+   enum mt76_bus_type type;
 };
 
+#define mt76_is_usb(dev) ((dev)->mt76.bus->type == MT76_BUS_USB)
+#define mt76_is_mmio(dev) ((dev)->mt76.bus->type == MT76_BUS_MMIO)
+
 enum mt76_txq_id {
MT_TXQ_VO = IEEE80211_AC_VO,
MT_TXQ_VI = IEEE80211_AC_VI,
diff --git a/drivers/net/wireless/mediatek/mt76/usb.c 
b/drivers/net/wireless/mediatek/mt76/usb.c
index 6b643ea701e3..cccb143e57b0 100644
--- a/drivers/net/wireless/mediatek/mt76/usb.c
+++ b/drivers/net/wireless/mediatek/mt76/usb.c
@@ -862,6 +862,7 @@ int mt76u_init(struct mt76_dev *dev,
.copy = mt76u_copy,
.wr_rp = mt76u_wr_rp,
.rd_rp = mt76u_rd_rp,
+   .type = MT76_BUS_USB,
};
struct mt76_usb *usb = >usb;
 
-- 
1.9.3



[PATCH 0/5] mt76x0: phy/rf fixups for PCIe

2018-10-04 Thread Stanislaw Gruszka
Changes since RFC:
- regbase on top of mt76x02_dev change
- add patch to choose single reg RF access via mt76_is_usb()

Stanislaw Gruszka (5):
  mt76x0: print BBP version only for debug
  mt76x0: correct RF access via RF_CSR regiser.
  mt76: allow to identify bus
  mt76x0: correct RF reg pairs write for PCIe
  mt76x0: use bus helper to identify rf access method

 drivers/net/wireless/mediatek/mt76/mmio.c |  1 +
 drivers/net/wireless/mediatek/mt76/mt76.h |  9 ++
 drivers/net/wireless/mediatek/mt76/mt76x0/phy.c   | 35 ---
 drivers/net/wireless/mediatek/mt76/mt76x02_regs.h |  4 +--
 drivers/net/wireless/mediatek/mt76/usb.c  |  1 +
 5 files changed, 38 insertions(+), 12 deletions(-)

-- 
1.9.3



[PATCH] iw: fix the beacon average signal parsing

2018-10-04 Thread Emmanuel Grumbach
NL80211_STA_INFO_BEACON_SIGNAL_AVG is parsed as a u8, but
it should be casted to a int8_t before being printed.

Change-Id: Ieb6fab3b803d8ea82819a450f07cc4b537d8de8b
Signed-off-by: Emmanuel Grumbach 
---
 station.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/station.c b/station.c
index 4885dc0..f4e0093 100644
--- a/station.c
+++ b/station.c
@@ -317,7 +317,7 @@ static int print_sta_handler(struct nl_msg *msg, void *arg)
 
if (sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG])
printf("\n\tbeacon signal avg:\t%d dBm",
-  nla_get_u8(sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]));
+  
(int8_t)nla_get_u8(sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]));
if (sinfo[NL80211_STA_INFO_T_OFFSET])
printf("\n\tToffset:\t%llu us",
   (unsigned long 
long)nla_get_u64(sinfo[NL80211_STA_INFO_T_OFFSET]));
-- 
2.7.4