[PATCH] ath9k: remove useless variable assignment in ath_mci_intr()

2017-06-26 Thread Gustavo A. R. Silva
Value assigned to variable offset at line 551 is overwritten at line 562,
before it can be used. This makes such variable assignment useless.

Addresses-Coverity-ID: 1226941
Signed-off-by: Gustavo A. R. Silva 
---
 drivers/net/wireless/ath/ath9k/mci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/wireless/ath/ath9k/mci.c 
b/drivers/net/wireless/ath/ath9k/mci.c
index 66596b9..cf23fd8 100644
--- a/drivers/net/wireless/ath/ath9k/mci.c
+++ b/drivers/net/wireless/ath/ath9k/mci.c
@@ -548,7 +548,7 @@ void ath_mci_intr(struct ath_softc *sc)
 
if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_SCHD_INFO) {
mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_SCHD_INFO;
-   offset = ar9003_mci_state(ah, MCI_STATE_LAST_SCHD_MSG_OFFSET);
+   ar9003_mci_state(ah, MCI_STATE_LAST_SCHD_MSG_OFFSET);
}
 
if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_GPM) {
-- 
2.5.0



[PATCH] ti: wl18xx: add checks on wl18xx_top_reg_write() return value

2017-06-26 Thread Gustavo A. R. Silva
Check return value from call to wl18xx_top_reg_write(),
so in case of error jump to goto label out and return.

Also, remove unnecessary value check before goto label out.

Addresses-Coverity-ID: 1226938
Signed-off-by: Gustavo A. R. Silva 
---
 drivers/net/wireless/ti/wl18xx/main.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/ti/wl18xx/main.c 
b/drivers/net/wireless/ti/wl18xx/main.c
index d1aa3ee..0cf3b40 100644
--- a/drivers/net/wireless/ti/wl18xx/main.c
+++ b/drivers/net/wireless/ti/wl18xx/main.c
@@ -793,9 +793,13 @@ static int wl18xx_set_clk(struct wl1271 *wl)
ret = wl18xx_top_reg_write(wl, PLLSH_WCS_PLL_P_FACTOR_CFG_2,
(wl18xx_clk_table[clk_freq].p >> 16) &
PLLSH_WCS_PLL_P_FACTOR_CFG_2_MASK);
+   if (ret < 0)
+   goto out;
} else {
ret = wl18xx_top_reg_write(wl, PLLSH_WCS_PLL_SWALLOW_EN,
   PLLSH_WCS_PLL_SWALLOW_EN_VAL2);
+   if (ret < 0)
+   goto out;
}
 
/* choose WCS PLL */
@@ -819,8 +823,6 @@ static int wl18xx_set_clk(struct wl1271 *wl)
/* reset the swallowing logic */
ret = wl18xx_top_reg_write(wl, PLLSH_COEX_PLL_SWALLOW_EN,
   PLLSH_COEX_PLL_SWALLOW_EN_VAL2);
-   if (ret < 0)
-   goto out;
 
 out:
return ret;
-- 
2.5.0



Re: [PATCH 6/7] staging: wilc1000: Change ac based on acm status

2017-06-26 Thread kbuild test robot
Hi Aditya,

[auto build test ERROR on staging/staging-testing]
[also build test ERROR on v4.12-rc7 next-20170626]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Aditya-Shankar/staging-wilc1000-Add-support-for-AC-classification/20170627-015835
config: sparc64-allyesconfig (attached as .config)
compiler: sparc64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
wget 
https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=sparc64 

All errors (new ones prefixed by >>):

   drivers/staging/wilc1000/wilc_wlan.c: In function 'ac_change':
>> drivers/staging/wilc1000/wilc_wlan.c:457:11: error: 'struct wilc' has no 
>> member named 'txq'
  if (wilc->txq[*ac].acm == 0)
  ^~

vim +457 drivers/staging/wilc1000/wilc_wlan.c

   451  pkt_count[AC_VO_Q] = (reg & 0xfe00) >> VO_AC_COUNT_POS;
   452  }
   453  
   454  static inline u8 ac_change(struct wilc *wilc, u8 *ac)
   455  {
   456  do {
 > 457  if (wilc->txq[*ac].acm == 0)
   458  return 0;
   459  (*ac)++;
   460  } while (*ac < NQUEUES);

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: application/gzip


Re: brcmfmac: don't warn user if requested nvram fails

2017-06-26 Thread Rafał Miłecki
On 8 April 2017 at 11:53, Hans de Goede  wrote:
> On 07-04-17 23:43, Arend Van Spriel wrote:
>> On 6-4-2017 14:14, Hans de Goede wrote:
>>> I noticed your patch-series on the lwn.net kernel page,
>>> and I took a peek :)
>>>
>>> I don't think that this patch:
>>>
>>>
>>> https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux-next.git/commit/?h=20170329-driver-data-v2-try3&id=3968dd3031d1ff7e7be4acfb810948c70c2d4490
>>>
>>>
>>> Is a good idea, specifically the "do not warn" part,
>>> although the brcmfmac driver will indeed try to continue
>>> without a nvram file, in my experience it almost all
>>> the time will not work properly without the nvram file.
>>
>>
>> Actually, brcmfmac will only continue without nvram for PCIe devices.
>> For SDIO it is a different story, which may be the kind of devices you
>> have experienced.
>
>
> Ah, no I've experience with both now, and the device I've
> with a PCIE which needs nvram:
>
> http://www.gpd.hk/gpdwin.asp
>
> Will not work without the nvram file, so I really think
> we should at least keep a warning msg here.

This is a late reply, I know...

I think you misunderstood my patch. It didn't completely remove the
warning. It just removed first try warning, where there is still a
chance of getting NVRAM from the platform data (special partition used
by bootloader & accessible by the operating system).

When both methods would fail, the warning would still appear.


[PATCH v2] nl80211: Don't verify owner_nlportid on NAN commands

2017-06-26 Thread Luca Coelho
From: Andrei Otcheretianski 

If NAN interface is created with NL80211_ATTR_SOCKET_OWNER, the socket
that is used to create the interface is used for all NAN operations and
reporting NAN events.
However, it turns out that sending commands and receiving events on
the same socket is not possible in a completely race-free way:
If the socket buffer is overflowed by the events, the command response
will not be sent. In that case the caller will block forever on recv.
Using non-blocking socket for commands is more complicated and still
the command response or ack may not be received.
So, keep unicasting NAN events to the interface creator, but allow
using a different socket for commands.

Signed-off-by: Andrei Otcheretianski 
Signed-off-by: Luca Coelho 
---

In v2:
   * Andrei fixed the documentation.

include/uapi/linux/nl80211.h | 9 -
 net/wireless/nl80211.c   | 8 
 2 files changed, 4 insertions(+), 13 deletions(-)

diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h
index 828aa4703e22..51626b4175c0 100644
--- a/include/uapi/linux/nl80211.h
+++ b/include/uapi/linux/nl80211.h
@@ -1909,11 +1909,10 @@ enum nl80211_commands {
  * that configured the indoor setting, and the indoor operation would be
  * cleared when the socket is closed.
  * If set during NAN interface creation, the interface will be destroyed
- * if the socket is closed just like any other interface. Moreover, only
- * the netlink socket that created the interface will be allowed to add
- * and remove functions. NAN notifications will be sent in unicast to that
- * socket. Without this attribute, any socket can add functions and the
- * notifications will be sent to the %NL80211_MCGRP_NAN multicast group.
+ * if the socket is closed just like any other interface. Moreover, NAN
+ * notifications will be sent in unicast to that socket. Without this
+ * attribute, the notifications will be sent to the %NL80211_MCGRP_NAN
+ * multicast group.
  * If set during %NL80211_CMD_ASSOCIATE or %NL80211_CMD_CONNECT the
  * station will deauthenticate when the socket is closed.
  *
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 5487cd775b6f..45ba3d0872cc 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -11206,10 +11206,6 @@ static int nl80211_nan_add_func(struct sk_buff *skb,
if (!info->attrs[NL80211_ATTR_NAN_FUNC])
return -EINVAL;
 
-   if (wdev->owner_nlportid &&
-   wdev->owner_nlportid != info->snd_portid)
-   return -ENOTCONN;
-
err = nla_parse_nested(tb, NL80211_NAN_FUNC_ATTR_MAX,
   info->attrs[NL80211_ATTR_NAN_FUNC],
   nl80211_nan_func_policy, info->extack);
@@ -11441,10 +11437,6 @@ static int nl80211_nan_del_func(struct sk_buff *skb,
if (!info->attrs[NL80211_ATTR_COOKIE])
return -EINVAL;
 
-   if (wdev->owner_nlportid &&
-   wdev->owner_nlportid != info->snd_portid)
-   return -ENOTCONN;
-
cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
 
rdev_del_nan_func(rdev, wdev, cookie);
-- 
2.11.0



Re: [RFC 3/6] mac80211: add a TXQ for other powersave-buffered frames

2017-06-26 Thread Johannes Berg
On Mon, 2017-06-26 at 07:15 -0700, Ben Greear wrote:

> > This *can* be solved, even in this piece of code I inserted here,
> > but it'd have to keep state about the queues and then insert some
> > hooks elsewhere. I'm pretty sure I can solve that, but don't have
> > the time (or even hardware) to test this (easily, I have ath10k in
> > a few routers, but ...).
> 
> What/how is it relying on buffering?

So with the TXQs, I thought we were only buffering in mac80211 on the
TXQs themselves. This isn't true though!

We still have the local->pending queues, and the drivers will still
rely on this for all the frames that are *not* going through a TXQ,
which currently is:
 * all non-data frames
 * multicast data frames if they need to be sent after DTIM
   (not sure why this is - doesn't make much sense to me to
differentiate immediate and after-DTIM transmissions)
 * data frames to stations the driver doesn't know about (yet)

In this case, the driver can still call ieee80211_stop_queue() or
similar, and expect frames to be buffered. I completely failed to take
that into account in this patchset; the dequeue logic I added to ath9k
and ath10k would have to take that into account and not dequeue if the
corresponding queue was stopped.

I think we'll probably have to put this logic into the current
driver(s); I was planning to put it into mac80211 for non-TXQ drivers,
but the ones already using TXQs would have to deal with it, since it'd
be really hard to make mac80211 logic kick in only partially for some
TXQs and not for others.

However, due to all the different levels of buffering we need more TXQs
than I introduced in this patchset (except I really don't want to
introduce one for per-vif-multicast-dtim-buffered-data ...)

> I'd be happy to send you plenty of ath10k mini-pcie NICs if that
> would help.

No need; I have no doubt that I could obtain them, but now I'll be
going on sabbatical for 2 months anyway :-)

johannes


Re: [RFC 3/6] mac80211: add a TXQ for other powersave-buffered frames

2017-06-26 Thread Ben Greear



On 06/26/2017 04:00 AM, Johannes Berg wrote:

On Fri, 2017-06-23 at 05:27 -0700, Ben Greear wrote:


I don't understand the code well enough to know if this matters or
not, but the ath10k wave-2 stuff has some txq prefetch logic in the
firmware (and support in the driver).  But, it doesn't prefetch for
the mgt tid as far as I can tell.  It somehow all mostly works
anyway, but possibly this would have some effect on your
changes.  wave-1 (QCA 9880, etc) doesn't do txq prefetch at all.  Any
tricky changes to this logic would need to test with both chipsets.


I don't think this matters. The issue at hand is that the driver still
relies on mac80211 buffering.

This *can* be solved, even in this piece of code I inserted here, but
it'd have to keep state about the queues and then insert some hooks
elsewhere. I'm pretty sure I can solve that, but don't have the time
(or even hardware) to test this (easily, I have ath10k in a few
routers, but ...).


What/how is it relying on buffering?

I'd be happy to send you plenty of ath10k mini-pcie NICs if that would help.

Just let me know.

Thanks,
Ben

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


[PATCH v2] drivers: staging: wilc1000/host_interface.c Fix sparse warning: right shift by bigger than source value

2017-06-26 Thread Guillermo O. Freschi
Shifting by equal to or bigger than the width of a type results in
undefined behavior. By using a wide enough temporary variable the issue
can be avoided.

Signed-off-by: Guillermo O. Freschi 
---
 drivers/staging/wilc1000/host_interface.c | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/wilc1000/host_interface.c 
b/drivers/staging/wilc1000/host_interface.c
index f7c22d7b28d1..4591b1452df4 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -2407,6 +2407,7 @@ static void Handle_SetMulticastFilter(struct wilc_vif 
*vif,
s32 result = 0;
struct wid wid;
u8 *pu8CurrByte;
+   u32 enabled;
 
wid.id = (u16)WID_SETUP_MULTICAST_FILTER;
wid.type = WID_BIN;
@@ -2416,10 +2417,12 @@ static void Handle_SetMulticastFilter(struct wilc_vif 
*vif,
goto ERRORHANDLER;
 
pu8CurrByte = wid.val;
-   *pu8CurrByte++ = (strHostIfSetMulti->enabled & 0xFF);
-   *pu8CurrByte++ = ((strHostIfSetMulti->enabled >> 8) & 0xFF);
-   *pu8CurrByte++ = ((strHostIfSetMulti->enabled >> 16) & 0xFF);
-   *pu8CurrByte++ = ((strHostIfSetMulti->enabled >> 24) & 0xFF);
+
+   enabled = strHostIfSetMulti->enabled;
+   *pu8CurrByte++ = (enabled & 0xFF);
+   *pu8CurrByte++ = ((enabled >> 8) & 0xFF);
+   *pu8CurrByte++ = ((enabled >> 16) & 0xFF);
+   *pu8CurrByte++ = ((enabled >> 24) & 0xFF);
 
*pu8CurrByte++ = (strHostIfSetMulti->cnt & 0xFF);
*pu8CurrByte++ = ((strHostIfSetMulti->cnt >> 8) & 0xFF);
-- 
2.11.0



[PATCH v2 6/8] staging: wilc1000: Get packet count from firmware

2017-06-26 Thread Aditya Shankar
Add a new function to get packet count from the firmware.

31:25   24  23:17   16  15:98   7:2 1   0
VO CNT  VO ACM  VI CNT  VI ACM  BE CNT  BE ACM  BK CNT  BK ACM  VMM ready

Signed-off-by: Aditya Shankar 
---
 drivers/staging/wilc1000/wilc_wlan.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/staging/wilc1000/wilc_wlan.c 
b/drivers/staging/wilc1000/wilc_wlan.c
index 655f229..b3e1136 100644
--- a/drivers/staging/wilc1000/wilc_wlan.c
+++ b/drivers/staging/wilc1000/wilc_wlan.c
@@ -443,6 +443,14 @@ static inline int ac_balance(u8 *count, u8 *ratio)
return 0;
 }
 
+static inline void ac_pkt_count(u32 reg, u8 *pkt_count)
+{
+   pkt_count[AC_BK_Q] = (reg & 0x00fa) >> BK_AC_COUNT_POS;
+   pkt_count[AC_BE_Q] = (reg & 0xfe00) >> BE_AC_COUNT_POS;
+   pkt_count[AC_VI_Q] = (reg & 0x00fe) >> VI_AC_COUNT_POS;
+   pkt_count[AC_VO_Q] = (reg & 0xfe00) >> VO_AC_COUNT_POS;
+}
+
 int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer,
  u32 buffer_size, wilc_tx_complete_func_t func)
 {
-- 
2.7.4




[PATCH v2 7/8] staging: wilc1000: Change ac based on acm status

2017-06-26 Thread Aditya Shankar
Add a new function to check and alter the ac if needed
based on the acm status for a particular queue.

Signed-off-by: Aditya Shankar 
---
 drivers/staging/wilc1000/wilc_wlan.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/drivers/staging/wilc1000/wilc_wlan.c 
b/drivers/staging/wilc1000/wilc_wlan.c
index b3e1136..e323fd4 100644
--- a/drivers/staging/wilc1000/wilc_wlan.c
+++ b/drivers/staging/wilc1000/wilc_wlan.c
@@ -451,6 +451,16 @@ static inline void ac_pkt_count(u32 reg, u8 *pkt_count)
pkt_count[AC_VO_Q] = (reg & 0xfe00) >> VO_AC_COUNT_POS;
 }
 
+static inline u8 ac_change(struct wilc *wilc, u8 *ac)
+{
+   do {
+   if (wilc->txq[*ac].acm == 0)
+   return 0;
+   (*ac)++;
+   } while (*ac < NQUEUES);
+   return 1;
+}
+
 int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer,
  u32 buffer_size, wilc_tx_complete_func_t func)
 {
-- 
2.7.4




[PATCH v2 3/8] staging: wilc1000: WMM classification of data

2017-06-26 Thread Aditya Shankar
This patch adds a new function to classify data to available
WMM access categories based on the DSCP value in the header.

Signed-off-by: Aditya Shankar 
---
 drivers/staging/wilc1000/wilc_wlan.c | 51 
 1 file changed, 51 insertions(+)

diff --git a/drivers/staging/wilc1000/wilc_wlan.c 
b/drivers/staging/wilc1000/wilc_wlan.c
index 8c997ba..d1ed3ba8 100644
--- a/drivers/staging/wilc1000/wilc_wlan.c
+++ b/drivers/staging/wilc1000/wilc_wlan.c
@@ -375,6 +375,57 @@ static inline void ac_q_limit(u8 ac, u16 *q_limit)
  sum) + 1;
 }
 
+static inline u8 ac_classify(struct wilc *wilc, struct txq_entry_t *tqe)
+{
+   u8 *eth_hdr_ptr;
+   u8 *buffer = tqe->buffer;
+   u8 ac;
+   u16 h_proto;
+
+   spin_lock_irqsave(&wilc->txq_spinlock, wilc->txq_spinlock_flags);
+
+   eth_hdr_ptr = &buffer[0];
+   h_proto = ntohs(*((unsigned short *)ð_hdr_ptr[12]));
+   if (h_proto == ETH_P_IP) {
+   u8 *ip_hdr_ptr;
+   u32 IHL, DSCP;
+
+   ip_hdr_ptr = &buffer[ETHERNET_HDR_LEN];
+   IHL = (ip_hdr_ptr[0] & 0xf) << 2;
+   DSCP = (ip_hdr_ptr[1] & 0xfc);
+
+   switch (DSCP) {
+   case 0x20:
+   case 0x40:
+   case 0x08:
+   ac = AC_BK_Q;
+   break;
+   case 0x80:
+   case 0xA0:
+   case 0x28:
+   ac = AC_VI_Q;
+   break;
+   case 0xC0:
+   case 0xd0:
+   case 0xE0:
+   case 0x88:
+   case 0xB8:
+   ac = AC_VO_Q;
+   break;
+   default:
+   ac = AC_BE_Q;
+   break;
+   }
+   } else {
+   ac  = AC_BE_Q;
+   }
+
+   tqe->q_num = ac;
+   spin_unlock_irqrestore(&wilc->txq_spinlock, wilc->txq_spinlock_flags);
+
+   return ac;
+}
+
 int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer,
  u32 buffer_size, wilc_tx_complete_func_t func)
 {
-- 
2.7.4




[PATCH v2 8/8] staging: wilc1000: Update ACM bit status

2017-06-26 Thread Aditya Shankar
Add a new function to update ACM bit status for a queue
for all access categories.

Signed-off-by: Aditya Shankar 
---
 drivers/staging/wilc1000/wilc_wlan.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/staging/wilc1000/wilc_wlan.c 
b/drivers/staging/wilc1000/wilc_wlan.c
index e323fd4..929166a 100644
--- a/drivers/staging/wilc1000/wilc_wlan.c
+++ b/drivers/staging/wilc1000/wilc_wlan.c
@@ -461,6 +461,14 @@ static inline u8 ac_change(struct wilc *wilc, u8 *ac)
return 1;
 }
 
+static inline void ac_acm_bit(struct wilc *wilc, u32 reg)
+{
+   wilc->txq[AC_BK_Q].acm = (reg & 0x0002) >> BK_AC_ACM_STAT_POS;
+   wilc->txq[AC_BE_Q].acm = (reg & 0x0100) >> BE_AC_ACM_STAT_POS;
+   wilc->txq[AC_VI_Q].acm = (reg & 0x0001) >> VI_AC_ACM_STAT_POS;
+   wilc->txq[AC_VO_Q].acm = (reg & 0x0100) >> VO_AC_ACM_STAT_POS;
+}
+
 int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer,
  u32 buffer_size, wilc_tx_complete_func_t func)
 {
-- 
2.7.4




[PATCH v2 5/8] staging: wilc1000: Add new variable for ac queue management

2017-06-26 Thread Aditya Shankar
This patch adds a new variable in the wilc struct to manage
ac queues.

Signed-off-by: Aditya Shankar 
---
 drivers/staging/wilc1000/wilc_wfi_netdevice.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/staging/wilc1000/wilc_wfi_netdevice.h 
b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
index c89bf43..e830bc5 100644
--- a/drivers/staging/wilc1000/wilc_wfi_netdevice.h
+++ b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
@@ -200,6 +200,7 @@ struct wilc {
 
struct txq_entry_t *txq_head;
struct txq_entry_t *txq_tail;
+   struct txq_handle txq[NQUEUES];
int txq_entries;
int txq_exit;
 
-- 
2.7.4




[PATCH v2 2/8] staging: wilc1000: Add function to calculate ac queue limit

2017-06-26 Thread Aditya Shankar
This patch adds a function which calculates the queue limit
for a given access category queue.

Signed-off-by: Aditya Shankar 
---
 drivers/staging/wilc1000/wilc_wlan.c | 42 
 1 file changed, 42 insertions(+)

diff --git a/drivers/staging/wilc1000/wilc_wlan.c 
b/drivers/staging/wilc1000/wilc_wlan.c
index 9addef1..8c997ba 100644
--- a/drivers/staging/wilc1000/wilc_wlan.c
+++ b/drivers/staging/wilc1000/wilc_wlan.c
@@ -333,6 +333,48 @@ static int wilc_wlan_txq_add_cfg_pkt(struct wilc_vif *vif, 
u8 *buffer,
return 1;
 }
 
+static inline void ac_q_limit(u8 ac, u16 *q_limit)
+{
+   static bool initialized;
+   static u8 buffer[AC_BUFFER_SIZE];
+   static u16 cnt[NQUEUES];
+   u8 factors[NQUEUES] = {1, 1, 1, 1};
+   static u16 sum;
+   u16 i;
+   static u16 end_index;
+
+   if (!initialized) {
+   for (i = 0; i < AC_BUFFER_SIZE; i++)
+   buffer[i] = i % NQUEUES;
+
+   for (i = 0; i < NQUEUES; i++) {
+   cnt[i] = AC_BUFFER_SIZE * factors[i] / NQUEUES;
+   sum += cnt[i];
+   }
+   end_index = AC_BUFFER_SIZE - 1;
+   initialized = 1;
+   }
+   if (end_index > AC_BUFFER_SIZE - 1)
+   end_index = AC_BUFFER_SIZE - 1;
+
+   cnt[buffer[end_index]] -= factors[buffer[end_index]];
+   cnt[ac] += factors[ac];
+   sum += (factors[ac] - factors[buffer[end_index]]);
+
+   buffer[end_index] = ac;
+   if (end_index > 0)
+   end_index--;
+   else
+   end_index = AC_BUFFER_SIZE - 1;
+
+   for (i = 0; i < NQUEUES; i++)
+   if (!sum)
+   q_limit[i] = 1;
+   else
+   q_limit[i] = (cnt[i] * FLOW_CONTROL_UPPER_THRESHOLD /
+ sum) + 1;
+}
+
 int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer,
  u32 buffer_size, wilc_tx_complete_func_t func)
 {
-- 
2.7.4




[PATCH v2 0/8] Enable access category classification on Tx path

2017-06-26 Thread Aditya Shankar
This patch series adds changes made to implement access
category based data classification and manages buffers allocation
between different access categories on the Tx path.

Aditya Shankar (8):
  staging: wilc1000: Add support for AC classification.
  staging: wilc1000: Add function to calculate ac queue limit
  staging: wilc1000: WMM classification of data
  staging: wilc1000: Add function to balance packet count
  staging: wilc1000: Add new variable for ac queue management
  staging: wilc1000: Get packet count from firmware
  staging: wilc1000: Change ac based on acm status
  staging: wilc1000: Update ACM bit status

Change in v2:
Add a missing patch in the patchset

 drivers/staging/wilc1000/wilc_wfi_netdevice.h |   1 +
 drivers/staging/wilc1000/wilc_wlan.c  | 136 ++
 drivers/staging/wilc1000/wilc_wlan.h  |  25 +
 3 files changed, 162 insertions(+)

-- 
2.7.4




[PATCH v2 4/8] staging: wilc1000: Add function to balance packet count

2017-06-26 Thread Aditya Shankar
Add a new function to track the cound of packets and
determine the ratio of current number of packets to
maximum count of packets.

Signed-off-by: Aditya Shankar 
---
 drivers/staging/wilc1000/wilc_wlan.c | 17 +
 1 file changed, 17 insertions(+)

diff --git a/drivers/staging/wilc1000/wilc_wlan.c 
b/drivers/staging/wilc1000/wilc_wlan.c
index d1ed3ba8..655f229 100644
--- a/drivers/staging/wilc1000/wilc_wlan.c
+++ b/drivers/staging/wilc1000/wilc_wlan.c
@@ -426,6 +426,23 @@ static inline u8 ac_classify(struct wilc *wilc, struct 
txq_entry_t *tqe)
return ac;
 }
 
+static inline int ac_balance(u8 *count, u8 *ratio)
+{
+   u8 i, max_count = 0;
+
+   if (!count || !ratio)
+   return -1;
+
+   for (i = 0; i < NQUEUES; i++)
+   if (count[i] > max_count)
+   max_count = count[i];
+
+   for (i = 0; i < NQUEUES; i++)
+   ratio[i] = max_count - count[i];
+
+   return 0;
+}
+
 int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer,
  u32 buffer_size, wilc_tx_complete_func_t func)
 {
-- 
2.7.4




[PATCH v2 1/8] staging: wilc1000: Add support for AC classification.

2017-06-26 Thread Aditya Shankar
This patch adds new variables and defines for adding access
category classification

Signed-off-by: Aditya Shankar 
---
 drivers/staging/wilc1000/wilc_wlan.h | 25 +
 1 file changed, 25 insertions(+)

diff --git a/drivers/staging/wilc1000/wilc_wlan.h 
b/drivers/staging/wilc1000/wilc_wlan.h
index 7a5eba9..c97f94a 100644
--- a/drivers/staging/wilc1000/wilc_wlan.h
+++ b/drivers/staging/wilc1000/wilc_wlan.h
@@ -133,6 +133,17 @@
 
 #define MODALIAS   "WILC_SPI"
 #define GPIO_NUM   0x44
+
+#define NQUEUES4
+#define VO_AC_COUNT_POS25
+#define VO_AC_ACM_STAT_POS 24
+#define VI_AC_COUNT_POS17
+#define VI_AC_ACM_STAT_POS 16
+#define BE_AC_COUNT_POS9
+#define BE_AC_ACM_STAT_POS 8
+#define BK_AC_COUNT_POS2
+#define BK_AC_ACM_STAT_POS 1
+#define AC_BUFFER_SIZE 1000
 /***/
 /*E0 and later Interrupt flags.*/
 /***/
@@ -206,11 +217,25 @@ typedef void (*wilc_debug_func)(u32, char *, ...);
  *  Tx/Rx Queue Structure
  *
  /
+struct txq_handle {
+   struct txq_entry_t *txq_head;
+   struct txq_entry_t *txq_tail;
+   u16 count;
+   u8 acm;
+};
+
+enum ip_pkt_priority {
+   AC_VO_Q = 0,
+   AC_VI_Q = 1,
+   AC_BE_Q = 2,
+   AC_BK_Q = 3
+};
 
 struct txq_entry_t {
struct txq_entry_t *next;
struct txq_entry_t *prev;
int type;
+   u8 q_num;
int tcp_pending_ack_idx;
u8 *buffer;
int buffer_size;
-- 
2.7.4




[PATCH v2] drivers: staging: wilc1000/host_interface.c Fix sparse warning: right shift by bigger than source value

2017-06-26 Thread Guillermo O. Freschi
Shifting by equal to or bigger than the width of a type results in
undefined behavior. By using a wide enough temporary variable the issue
can be avoided.

Signed-off-by: Guillermo O. Freschi 
---
 drivers/staging/wilc1000/host_interface.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/wilc1000/host_interface.c 
b/drivers/staging/wilc1000/host_interface.c
index f7c22d7b28d1..ed614698c22c 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -2416,10 +2416,12 @@ static void Handle_SetMulticastFilter(struct wilc_vif 
*vif,
goto ERRORHANDLER;
 
pu8CurrByte = wid.val;
-   *pu8CurrByte++ = (strHostIfSetMulti->enabled & 0xFF);
-   *pu8CurrByte++ = ((strHostIfSetMulti->enabled >> 8) & 0xFF);
-   *pu8CurrByte++ = ((strHostIfSetMulti->enabled >> 16) & 0xFF);
-   *pu8CurrByte++ = ((strHostIfSetMulti->enabled >> 24) & 0xFF);
+
+   u32 enabled = strHostIfSetMulti->enabled;
+   *pu8CurrByte++ = (enabled & 0xFF);
+   *pu8CurrByte++ = ((enabled >> 8) & 0xFF);
+   *pu8CurrByte++ = ((enabled >> 16) & 0xFF);
+   *pu8CurrByte++ = ((enabled >> 24) & 0xFF);
 
*pu8CurrByte++ = (strHostIfSetMulti->cnt & 0xFF);
*pu8CurrByte++ = ((strHostIfSetMulti->cnt >> 8) & 0xFF);
-- 
2.11.0



Re: [PATCH] nl80211: Don't verify owner_nlportid on NAN commands

2017-06-26 Thread Luca Coelho
On Fri, 2017-06-23 at 23:03 +0200, Arend van Spriel wrote:
> On 23-06-17 11:26, Luca Coelho wrote:
> > From: Andrei Otcheretianski 
> > 
> > If NAN interface is created with NL80211_ATTR_SOCKET_OWNER, the socket
> > that is used to create the interface is used for all NAN operations and
> > reporting NAN events.
> > However, it turns out that sending commands and receiving events on
> > the same socket is not possible in a completely race-free way:
> > If the socket buffer is overflowed by the events, the command response
> > will not be sent. In that case the caller will block forever on recv.
> > Using non-blocking socket for commands is more complicated and still
> > the command response or ack may not be received.
> > So, keep unicasting NAN events to the interface creator, but allow
> > using a different socket for commands.
> 
> Sounds like this patch is missing significant changes in the
> documentation of nl80211 API:

Thanks Arend!

Andrei is going to fix the documentation and I'll send v2.


--
Luca.


Re: [RFC 3/6] mac80211: add a TXQ for other powersave-buffered frames

2017-06-26 Thread Johannes Berg
On Fri, 2017-06-23 at 05:27 -0700, Ben Greear wrote:

> I don't understand the code well enough to know if this matters or
> not, but the ath10k wave-2 stuff has some txq prefetch logic in the
> firmware (and support in the driver).  But, it doesn't prefetch for
> the mgt tid as far as I can tell.  It somehow all mostly works
> anyway, but possibly this would have some effect on your
> changes.  wave-1 (QCA 9880, etc) doesn't do txq prefetch at all.  Any
> tricky changes to this logic would need to test with both chipsets.

I don't think this matters. The issue at hand is that the driver still
relies on mac80211 buffering.

This *can* be solved, even in this piece of code I inserted here, but
it'd have to keep state about the queues and then insert some hooks
elsewhere. I'm pretty sure I can solve that, but don't have the time
(or even hardware) to test this (easily, I have ath10k in a few
routers, but ...).

johannes


Re: [PATCH] nl80211: Don't verify owner_nlportid on NAN commands

2017-06-26 Thread Johannes Berg
On Fri, 2017-06-23 at 23:03 +0200, Arend van Spriel wrote:
> 
> Also is this not a more fundamental flaw in netlink socket behavior.
> Should there be some priority imposed on command responses over event
> messages. Just seems like this patch is a workaround.

In a way, but it's not that easy. ACK messages are really just that,
messages, and having them bypass the queue might not be reasonable for
the use case, having them be queued unconditionally would open an
avenue for memory consumption attacks (send lots of dummy commands and
let the ACKs accumulate), and deleting already "delivered" message
could, I think, break semantics because I think delivery can be checked
by the sender?

Either way, I don't really see a good way to solve this problem in
netlink.

johannes


Re: [PATCH] drivers: staging: wilc1000/host_interface.c Fix sparse warning: right shift by bigger than source value

2017-06-26 Thread kbuild test robot
Hi Guillermo,

[auto build test WARNING on staging/staging-testing]
[also build test WARNING on next-20170626]
[cannot apply to v4.12-rc7]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Guillermo-O-Freschi/drivers-staging-wilc1000-host_interface-c-Fix-sparse-warning-right-shift-by-bigger-than-source-value/20170626-173132
config: x86_64-randconfig-x007-201726 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 

All warnings (new ones prefixed by >>):

   drivers/staging/wilc1000/host_interface.c: In function 
'Handle_SetMulticastFilter':
>> drivers/staging/wilc1000/host_interface.c:2420:2: warning: ISO C90 forbids 
>> mixed declarations and code [-Wdeclaration-after-statement]
 u32 enabled = strHostIfSetMulti->enabled;
 ^~~

vim +2420 drivers/staging/wilc1000/host_interface.c

  2404  static void Handle_SetMulticastFilter(struct wilc_vif *vif,
  2405struct set_multicast 
*strHostIfSetMulti)
  2406  {
  2407  s32 result = 0;
  2408  struct wid wid;
  2409  u8 *pu8CurrByte;
  2410  
  2411  wid.id = (u16)WID_SETUP_MULTICAST_FILTER;
  2412  wid.type = WID_BIN;
  2413  wid.size = sizeof(struct set_multicast) + 
((strHostIfSetMulti->cnt) * ETH_ALEN);
  2414  wid.val = kmalloc(wid.size, GFP_KERNEL);
  2415  if (!wid.val)
  2416  goto ERRORHANDLER;
  2417  
  2418  pu8CurrByte = wid.val;
  2419  
> 2420  u32 enabled = strHostIfSetMulti->enabled;
  2421  *pu8CurrByte++ = (enabled & 0xFF);
  2422  *pu8CurrByte++ = ((enabled >> 8) & 0xFF);
  2423  *pu8CurrByte++ = ((enabled >> 16) & 0xFF);
  2424  *pu8CurrByte++ = ((enabled >> 24) & 0xFF);
  2425  
  2426  *pu8CurrByte++ = (strHostIfSetMulti->cnt & 0xFF);
  2427  *pu8CurrByte++ = ((strHostIfSetMulti->cnt >> 8) & 0xFF);
  2428  *pu8CurrByte++ = ((strHostIfSetMulti->cnt >> 16) & 0xFF);

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: application/gzip


[PATCH 7/7] staging: wilc1000: Update ACM bit status

2017-06-26 Thread Aditya Shankar
Add a new function to update ACM bit status for a queue
for all access categories.

Signed-off-by: Aditya Shankar 
---
 drivers/staging/wilc1000/wilc_wlan.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/staging/wilc1000/wilc_wlan.c 
b/drivers/staging/wilc1000/wilc_wlan.c
index e323fd4..929166a 100644
--- a/drivers/staging/wilc1000/wilc_wlan.c
+++ b/drivers/staging/wilc1000/wilc_wlan.c
@@ -461,6 +461,14 @@ static inline u8 ac_change(struct wilc *wilc, u8 *ac)
return 1;
 }
 
+static inline void ac_acm_bit(struct wilc *wilc, u32 reg)
+{
+   wilc->txq[AC_BK_Q].acm = (reg & 0x0002) >> BK_AC_ACM_STAT_POS;
+   wilc->txq[AC_BE_Q].acm = (reg & 0x0100) >> BE_AC_ACM_STAT_POS;
+   wilc->txq[AC_VI_Q].acm = (reg & 0x0001) >> VI_AC_ACM_STAT_POS;
+   wilc->txq[AC_VO_Q].acm = (reg & 0x0100) >> VO_AC_ACM_STAT_POS;
+}
+
 int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer,
  u32 buffer_size, wilc_tx_complete_func_t func)
 {
-- 
2.7.4




[PATCH 6/7] staging: wilc1000: Change ac based on acm status

2017-06-26 Thread Aditya Shankar
Add a new function to check and alter the ac if needed
based on the acm status for a particular queue.

Signed-off-by: Aditya Shankar 
---
 drivers/staging/wilc1000/wilc_wlan.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/drivers/staging/wilc1000/wilc_wlan.c 
b/drivers/staging/wilc1000/wilc_wlan.c
index b3e1136..e323fd4 100644
--- a/drivers/staging/wilc1000/wilc_wlan.c
+++ b/drivers/staging/wilc1000/wilc_wlan.c
@@ -451,6 +451,16 @@ static inline void ac_pkt_count(u32 reg, u8 *pkt_count)
pkt_count[AC_VO_Q] = (reg & 0xfe00) >> VO_AC_COUNT_POS;
 }
 
+static inline u8 ac_change(struct wilc *wilc, u8 *ac)
+{
+   do {
+   if (wilc->txq[*ac].acm == 0)
+   return 0;
+   (*ac)++;
+   } while (*ac < NQUEUES);
+   return 1;
+}
+
 int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer,
  u32 buffer_size, wilc_tx_complete_func_t func)
 {
-- 
2.7.4




[PATCH 1/7] staging: wilc1000: Add support for AC classification.

2017-06-26 Thread Aditya Shankar
This patch adds new variables and defines for adding access
category classification

Signed-off-by: Aditya Shankar 
---
 drivers/staging/wilc1000/wilc_wlan.h | 25 +
 1 file changed, 25 insertions(+)

diff --git a/drivers/staging/wilc1000/wilc_wlan.h 
b/drivers/staging/wilc1000/wilc_wlan.h
index 7a5eba9..c97f94a 100644
--- a/drivers/staging/wilc1000/wilc_wlan.h
+++ b/drivers/staging/wilc1000/wilc_wlan.h
@@ -133,6 +133,17 @@
 
 #define MODALIAS   "WILC_SPI"
 #define GPIO_NUM   0x44
+
+#define NQUEUES4
+#define VO_AC_COUNT_POS25
+#define VO_AC_ACM_STAT_POS 24
+#define VI_AC_COUNT_POS17
+#define VI_AC_ACM_STAT_POS 16
+#define BE_AC_COUNT_POS9
+#define BE_AC_ACM_STAT_POS 8
+#define BK_AC_COUNT_POS2
+#define BK_AC_ACM_STAT_POS 1
+#define AC_BUFFER_SIZE 1000
 /***/
 /*E0 and later Interrupt flags.*/
 /***/
@@ -206,11 +217,25 @@ typedef void (*wilc_debug_func)(u32, char *, ...);
  *  Tx/Rx Queue Structure
  *
  /
+struct txq_handle {
+   struct txq_entry_t *txq_head;
+   struct txq_entry_t *txq_tail;
+   u16 count;
+   u8 acm;
+};
+
+enum ip_pkt_priority {
+   AC_VO_Q = 0,
+   AC_VI_Q = 1,
+   AC_BE_Q = 2,
+   AC_BK_Q = 3
+};
 
 struct txq_entry_t {
struct txq_entry_t *next;
struct txq_entry_t *prev;
int type;
+   u8 q_num;
int tcp_pending_ack_idx;
u8 *buffer;
int buffer_size;
-- 
2.7.4




[PATCH 4/7] staging: wilc1000: Add function to balance packet count

2017-06-26 Thread Aditya Shankar
Add a new function to track the cound of packets and
determine the ratio of current number of packets to
maximum count of packets.

Signed-off-by: Aditya Shankar 
---
 drivers/staging/wilc1000/wilc_wlan.c | 17 +
 1 file changed, 17 insertions(+)

diff --git a/drivers/staging/wilc1000/wilc_wlan.c 
b/drivers/staging/wilc1000/wilc_wlan.c
index d1ed3ba8..655f229 100644
--- a/drivers/staging/wilc1000/wilc_wlan.c
+++ b/drivers/staging/wilc1000/wilc_wlan.c
@@ -426,6 +426,23 @@ static inline u8 ac_classify(struct wilc *wilc, struct 
txq_entry_t *tqe)
return ac;
 }
 
+static inline int ac_balance(u8 *count, u8 *ratio)
+{
+   u8 i, max_count = 0;
+
+   if (!count || !ratio)
+   return -1;
+
+   for (i = 0; i < NQUEUES; i++)
+   if (count[i] > max_count)
+   max_count = count[i];
+
+   for (i = 0; i < NQUEUES; i++)
+   ratio[i] = max_count - count[i];
+
+   return 0;
+}
+
 int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer,
  u32 buffer_size, wilc_tx_complete_func_t func)
 {
-- 
2.7.4




[PATCH 5/7] staging: wilc1000: Get packet count from firmware

2017-06-26 Thread Aditya Shankar
Add a new function to get packet count from the firmware.

31:25   24  23:17   16  15:98   7:2 1   0
VO CNT  VO ACM  VI CNT  VI ACM  BE CNT  BE ACM  BK CNT  BK ACM  VMM ready

Signed-off-by: Aditya Shankar 
---
 drivers/staging/wilc1000/wilc_wlan.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/staging/wilc1000/wilc_wlan.c 
b/drivers/staging/wilc1000/wilc_wlan.c
index 655f229..b3e1136 100644
--- a/drivers/staging/wilc1000/wilc_wlan.c
+++ b/drivers/staging/wilc1000/wilc_wlan.c
@@ -443,6 +443,14 @@ static inline int ac_balance(u8 *count, u8 *ratio)
return 0;
 }
 
+static inline void ac_pkt_count(u32 reg, u8 *pkt_count)
+{
+   pkt_count[AC_BK_Q] = (reg & 0x00fa) >> BK_AC_COUNT_POS;
+   pkt_count[AC_BE_Q] = (reg & 0xfe00) >> BE_AC_COUNT_POS;
+   pkt_count[AC_VI_Q] = (reg & 0x00fe) >> VI_AC_COUNT_POS;
+   pkt_count[AC_VO_Q] = (reg & 0xfe00) >> VO_AC_COUNT_POS;
+}
+
 int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer,
  u32 buffer_size, wilc_tx_complete_func_t func)
 {
-- 
2.7.4




[PATCH 0/7] Enable access category classification on Tx path

2017-06-26 Thread Aditya Shankar
This patch series adds changes made to implement access
category based data classification and manages buffers allocation
between different access categories on the Tx path.

Aditya Shankar (7):
  staging: wilc1000: Add support for AC classification.
  staging: wilc1000: Add function to calculate ac queue limit
  staging: wilc1000: WMM classification of data
  staging: wilc1000: Add function to balance packet count
  staging: wilc1000: Get packet count from firmware
  staging: wilc1000: Change ac based on acm status
  staging: wilc1000: Update ACM bit status

 drivers/staging/wilc1000/wilc_wlan.c | 136 +++
 drivers/staging/wilc1000/wilc_wlan.h |  25 +++
 2 files changed, 161 insertions(+)

-- 
2.7.4




[PATCH 2/7] staging: wilc1000: Add function to calculate ac queue limit

2017-06-26 Thread Aditya Shankar
This patch adds a function which calculates the queue limit
for a given access category queue.

Signed-off-by: Aditya Shankar 
---
 drivers/staging/wilc1000/wilc_wlan.c | 42 
 1 file changed, 42 insertions(+)

diff --git a/drivers/staging/wilc1000/wilc_wlan.c 
b/drivers/staging/wilc1000/wilc_wlan.c
index 9addef1..8c997ba 100644
--- a/drivers/staging/wilc1000/wilc_wlan.c
+++ b/drivers/staging/wilc1000/wilc_wlan.c
@@ -333,6 +333,48 @@ static int wilc_wlan_txq_add_cfg_pkt(struct wilc_vif *vif, 
u8 *buffer,
return 1;
 }
 
+static inline void ac_q_limit(u8 ac, u16 *q_limit)
+{
+   static bool initialized;
+   static u8 buffer[AC_BUFFER_SIZE];
+   static u16 cnt[NQUEUES];
+   u8 factors[NQUEUES] = {1, 1, 1, 1};
+   static u16 sum;
+   u16 i;
+   static u16 end_index;
+
+   if (!initialized) {
+   for (i = 0; i < AC_BUFFER_SIZE; i++)
+   buffer[i] = i % NQUEUES;
+
+   for (i = 0; i < NQUEUES; i++) {
+   cnt[i] = AC_BUFFER_SIZE * factors[i] / NQUEUES;
+   sum += cnt[i];
+   }
+   end_index = AC_BUFFER_SIZE - 1;
+   initialized = 1;
+   }
+   if (end_index > AC_BUFFER_SIZE - 1)
+   end_index = AC_BUFFER_SIZE - 1;
+
+   cnt[buffer[end_index]] -= factors[buffer[end_index]];
+   cnt[ac] += factors[ac];
+   sum += (factors[ac] - factors[buffer[end_index]]);
+
+   buffer[end_index] = ac;
+   if (end_index > 0)
+   end_index--;
+   else
+   end_index = AC_BUFFER_SIZE - 1;
+
+   for (i = 0; i < NQUEUES; i++)
+   if (!sum)
+   q_limit[i] = 1;
+   else
+   q_limit[i] = (cnt[i] * FLOW_CONTROL_UPPER_THRESHOLD /
+ sum) + 1;
+}
+
 int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer,
  u32 buffer_size, wilc_tx_complete_func_t func)
 {
-- 
2.7.4




[PATCH 3/7] staging: wilc1000: WMM classification of data

2017-06-26 Thread Aditya Shankar
This patch adds a new function to classify data to available
WMM access categories based on the DSCP value in the header.

Signed-off-by: Aditya Shankar 
---
 drivers/staging/wilc1000/wilc_wlan.c | 51 
 1 file changed, 51 insertions(+)

diff --git a/drivers/staging/wilc1000/wilc_wlan.c 
b/drivers/staging/wilc1000/wilc_wlan.c
index 8c997ba..d1ed3ba8 100644
--- a/drivers/staging/wilc1000/wilc_wlan.c
+++ b/drivers/staging/wilc1000/wilc_wlan.c
@@ -375,6 +375,57 @@ static inline void ac_q_limit(u8 ac, u16 *q_limit)
  sum) + 1;
 }
 
+static inline u8 ac_classify(struct wilc *wilc, struct txq_entry_t *tqe)
+{
+   u8 *eth_hdr_ptr;
+   u8 *buffer = tqe->buffer;
+   u8 ac;
+   u16 h_proto;
+
+   spin_lock_irqsave(&wilc->txq_spinlock, wilc->txq_spinlock_flags);
+
+   eth_hdr_ptr = &buffer[0];
+   h_proto = ntohs(*((unsigned short *)ð_hdr_ptr[12]));
+   if (h_proto == ETH_P_IP) {
+   u8 *ip_hdr_ptr;
+   u32 IHL, DSCP;
+
+   ip_hdr_ptr = &buffer[ETHERNET_HDR_LEN];
+   IHL = (ip_hdr_ptr[0] & 0xf) << 2;
+   DSCP = (ip_hdr_ptr[1] & 0xfc);
+
+   switch (DSCP) {
+   case 0x20:
+   case 0x40:
+   case 0x08:
+   ac = AC_BK_Q;
+   break;
+   case 0x80:
+   case 0xA0:
+   case 0x28:
+   ac = AC_VI_Q;
+   break;
+   case 0xC0:
+   case 0xd0:
+   case 0xE0:
+   case 0x88:
+   case 0xB8:
+   ac = AC_VO_Q;
+   break;
+   default:
+   ac = AC_BE_Q;
+   break;
+   }
+   } else {
+   ac  = AC_BE_Q;
+   }
+
+   tqe->q_num = ac;
+   spin_unlock_irqrestore(&wilc->txq_spinlock, wilc->txq_spinlock_flags);
+
+   return ac;
+}
+
 int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer,
  u32 buffer_size, wilc_tx_complete_func_t func)
 {
-- 
2.7.4