aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/mwifiex
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-02-20 21:58:50 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-02-20 21:58:50 -0500
commita0b1c42951dd06ec83cc1bc2c9788131d9fefcd8 (patch)
treea572f1523cf904c93020c9cdb32f3bc84ec3ac16 /drivers/net/wireless/mwifiex
parent8ec4942212a6d337982967778a3dc3b60aea782e (diff)
parentecd9883724b78cc72ed92c98bcb1a46c764fff21 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next
Pull networking update from David Miller: 1) Checkpoint/restarted TCP sockets now can properly propagate the TCP timestamp offset. From Andrey Vagin. 2) VMWARE VM VSOCK layer, from Andy King. 3) Much improved support for virtual functions and SR-IOV in bnx2x, from Ariel ELior. 4) All protocols on ipv4 and ipv6 are now network namespace aware, and all the compatability checks for initial-namespace-only protocols is removed. Thanks to Tom Parkin for helping deal with the last major holdout, L2TP. 5) IPV6 support in netpoll and network namespace support in pktgen, from Cong Wang. 6) Multiple Registration Protocol (MRP) and Multiple VLAN Registration Protocol (MVRP) support, from David Ward. 7) Compute packet lengths more accurately in the packet scheduler, from Eric Dumazet. 8) Use per-task page fragment allocator in skb_append_datato_frags(), also from Eric Dumazet. 9) Add support for connection tracking labels in netfilter, from Florian Westphal. 10) Fix default multicast group joining on ipv6, and add anti-spoofing checks to 6to4 and 6rd. From Hannes Frederic Sowa. 11) Make ipv4/ipv6 fragmentation memory limits more reasonable in modern times, rearrange inet frag datastructures for better cacheline locality, and move more operations outside of locking. From Jesper Dangaard Brouer. 12) Instead of strict master <--> slave relationships, allow arbitrary scenerios with "upper device lists". From Jiri Pirko. 13) Improve rate limiting accuracy in TBF and act_police, also from Jiri Pirko. 14) Add a BPF filter netfilter match target, from Willem de Bruijn. 15) Orphan and delete a bunch of pre-historic networking drivers from Paul Gortmaker. 16) Add TSO support for GRE tunnels, from Pravin B SHelar. Although this still needs some minor bug fixing before it's %100 correct in all cases. 17) Handle unresolved IPSEC states like ARP, with a resolution packet queue. From Steffen Klassert. 18) Remove TCP Appropriate Byte Count support (ABC), from Stephen Hemminger. This was long overdue. 19) Support SO_REUSEPORT, from Tom Herbert. 20) Allow locking a socket BPF filter, so that it cannot change after a process drops capabilities. 21) Add VLAN filtering to bridge, from Vlad Yasevich. 22) Bring ipv6 on-par with ipv4 and do not cache neighbour entries in the ipv6 routes, from YOSHIFUJI Hideaki. * git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next: (1538 commits) ipv6: fix race condition regarding dst->expires and dst->from. net: fix a wrong assignment in skb_split() ip_gre: remove an extra dst_release() ppp: set qdisc_tx_busylock to avoid LOCKDEP splat atl1c: restore buffer state net: fix a build failure when !CONFIG_PROC_FS net: ipv4: fix waring -Wunused-variable net: proc: fix build failed when procfs is not configured Revert "xen: netback: remove redundant xenvif_put" net: move procfs code to net/core/net-procfs.c qmi_wwan, cdc-ether: add ADU960S bonding: set sysfs device_type to 'bond' bonding: fix bond_release_all inconsistencies b44: use netdev_alloc_skb_ip_align() xen: netback: remove redundant xenvif_put net: fec: Do a sanity check on the gpio number ip_gre: propogate target device GSO capability to the tunnel device ip_gre: allow CSUM capable devices to handle packets bonding: Fix initialize after use for 3ad machine state spinlock bonding: Fix race condition between bond_enslave() and bond_3ad_update_lacp_rate() ...
Diffstat (limited to 'drivers/net/wireless/mwifiex')
-rw-r--r--drivers/net/wireless/mwifiex/11ac.c261
-rw-r--r--drivers/net/wireless/mwifiex/11ac.h26
-rw-r--r--drivers/net/wireless/mwifiex/11n.c55
-rw-r--r--drivers/net/wireless/mwifiex/11n.h6
-rw-r--r--drivers/net/wireless/mwifiex/11n_aggr.c6
-rw-r--r--drivers/net/wireless/mwifiex/11n_rxreorder.c5
-rw-r--r--drivers/net/wireless/mwifiex/Kconfig4
-rw-r--r--drivers/net/wireless/mwifiex/Makefile1
-rw-r--r--drivers/net/wireless/mwifiex/README1
-rw-r--r--drivers/net/wireless/mwifiex/cfg80211.c192
-rw-r--r--drivers/net/wireless/mwifiex/cfp.c159
-rw-r--r--drivers/net/wireless/mwifiex/cmdevt.c30
-rw-r--r--drivers/net/wireless/mwifiex/debugfs.c2
-rw-r--r--drivers/net/wireless/mwifiex/decl.h18
-rw-r--r--drivers/net/wireless/mwifiex/fw.h141
-rw-r--r--drivers/net/wireless/mwifiex/init.c12
-rw-r--r--drivers/net/wireless/mwifiex/ioctl.h8
-rw-r--r--drivers/net/wireless/mwifiex/join.c44
-rw-r--r--drivers/net/wireless/mwifiex/main.h30
-rw-r--r--drivers/net/wireless/mwifiex/pcie.c1262
-rw-r--r--drivers/net/wireless/mwifiex/pcie.h228
-rw-r--r--drivers/net/wireless/mwifiex/scan.c92
-rw-r--r--drivers/net/wireless/mwifiex/sdio.c21
-rw-r--r--drivers/net/wireless/mwifiex/sta_cmd.c12
-rw-r--r--drivers/net/wireless/mwifiex/sta_cmdresp.c6
-rw-r--r--drivers/net/wireless/mwifiex/sta_ioctl.c27
-rw-r--r--drivers/net/wireless/mwifiex/txrx.c6
-rw-r--r--drivers/net/wireless/mwifiex/uap_cmd.c44
-rw-r--r--drivers/net/wireless/mwifiex/usb.c34
-rw-r--r--drivers/net/wireless/mwifiex/util.c2
-rw-r--r--drivers/net/wireless/mwifiex/util.h8
-rw-r--r--drivers/net/wireless/mwifiex/wmm.c15
32 files changed, 2088 insertions, 670 deletions
diff --git a/drivers/net/wireless/mwifiex/11ac.c b/drivers/net/wireless/mwifiex/11ac.c
new file mode 100644
index 000000000000..cf43b3c29250
--- /dev/null
+++ b/drivers/net/wireless/mwifiex/11ac.c
@@ -0,0 +1,261 @@
1/*
2 * Marvell Wireless LAN device driver: 802.11ac
3 *
4 * Copyright (C) 2013, Marvell International Ltd.
5 *
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
13 *
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
18 */
19
20#include "decl.h"
21#include "ioctl.h"
22#include "fw.h"
23#include "main.h"
24#include "11ac.h"
25
26/* This function converts the 2-bit MCS map to the highest long GI
27 * VHT data rate.
28 */
29static u16
30mwifiex_convert_mcsmap_to_maxrate(struct mwifiex_private *priv,
31 u8 bands, u16 mcs_map)
32{
33 u8 i, nss, max_mcs;
34 u16 max_rate = 0;
35 u32 usr_vht_cap_info = 0;
36 struct mwifiex_adapter *adapter = priv->adapter;
37 /* tables of the MCS map to the highest data rate (in Mbps)
38 * supported for long GI
39 */
40 u16 max_rate_lgi_80MHZ[8][3] = {
41 {0x124, 0x15F, 0x186}, /* NSS = 1 */
42 {0x249, 0x2BE, 0x30C}, /* NSS = 2 */
43 {0x36D, 0x41D, 0x492}, /* NSS = 3 */
44 {0x492, 0x57C, 0x618}, /* NSS = 4 */
45 {0x5B6, 0x6DB, 0x79E}, /* NSS = 5 */
46 {0x6DB, 0x83A, 0x0}, /* NSS = 6 */
47 {0x7FF, 0x999, 0xAAA}, /* NSS = 7 */
48 {0x924, 0xAF8, 0xC30} /* NSS = 8 */
49 };
50 u16 max_rate_lgi_160MHZ[8][3] = {
51 {0x249, 0x2BE, 0x30C}, /* NSS = 1 */
52 {0x492, 0x57C, 0x618}, /* NSS = 2 */
53 {0x6DB, 0x83A, 0x0}, /* NSS = 3 */
54 {0x924, 0xAF8, 0xC30}, /* NSS = 4 */
55 {0xB6D, 0xDB6, 0xF3C}, /* NSS = 5 */
56 {0xDB6, 0x1074, 0x1248}, /* NSS = 6 */
57 {0xFFF, 0x1332, 0x1554}, /* NSS = 7 */
58 {0x1248, 0x15F0, 0x1860} /* NSS = 8 */
59 };
60
61 if (bands & BAND_AAC)
62 usr_vht_cap_info = adapter->usr_dot_11ac_dev_cap_a;
63 else
64 usr_vht_cap_info = adapter->usr_dot_11ac_dev_cap_bg;
65
66 /* find the max NSS supported */
67 nss = 0;
68 for (i = 0; i < 8; i++) {
69 max_mcs = (mcs_map >> (2 * i)) & 0x3;
70 if (max_mcs < 3)
71 nss = i;
72 }
73 max_mcs = (mcs_map >> (2 * nss)) & 0x3;
74
75 /* if max_mcs is 3, nss must be 0 (SS = 1). Thus, max mcs is MCS 9 */
76 if (max_mcs >= 3)
77 max_mcs = 2;
78
79 if (GET_VHTCAP_CHWDSET(usr_vht_cap_info)) {
80 /* support 160 MHz */
81 max_rate = max_rate_lgi_160MHZ[nss][max_mcs];
82 if (!max_rate)
83 /* MCS9 is not supported in NSS6 */
84 max_rate = max_rate_lgi_160MHZ[nss][max_mcs - 1];
85 } else {
86 max_rate = max_rate_lgi_80MHZ[nss][max_mcs];
87 if (!max_rate)
88 /* MCS9 is not supported in NSS3 */
89 max_rate = max_rate_lgi_80MHZ[nss][max_mcs - 1];
90 }
91
92 return max_rate;
93}
94
95static void
96mwifiex_fill_vht_cap_info(struct mwifiex_private *priv,
97 struct mwifiex_ie_types_vhtcap *vht_cap, u8 bands)
98{
99 struct mwifiex_adapter *adapter = priv->adapter;
100
101 if (bands & BAND_A)
102 vht_cap->vht_cap.vht_cap_info =
103 cpu_to_le32(adapter->usr_dot_11ac_dev_cap_a);
104 else
105 vht_cap->vht_cap.vht_cap_info =
106 cpu_to_le32(adapter->usr_dot_11ac_dev_cap_bg);
107}
108
109static void
110mwifiex_fill_vht_cap_tlv(struct mwifiex_private *priv,
111 struct mwifiex_ie_types_vhtcap *vht_cap, u8 bands)
112{
113 struct mwifiex_adapter *adapter = priv->adapter;
114 u16 mcs_map_user, mcs_map_resp, mcs_map_result;
115 u16 mcs_user, mcs_resp, nss, tmp;
116
117 /* Fill VHT cap info */
118 mwifiex_fill_vht_cap_info(priv, vht_cap, bands);
119
120 /* rx MCS Set: find the minimum of the user rx mcs and ap rx mcs */
121 mcs_map_user = GET_DEVRXMCSMAP(adapter->usr_dot_11ac_mcs_support);
122 mcs_map_resp = le16_to_cpu(vht_cap->vht_cap.supp_mcs.rx_mcs_map);
123 mcs_map_result = 0;
124
125 for (nss = 1; nss <= 8; nss++) {
126 mcs_user = GET_VHTNSSMCS(mcs_map_user, nss);
127 mcs_resp = GET_VHTNSSMCS(mcs_map_resp, nss);
128
129 if ((mcs_user == NO_NSS_SUPPORT) ||
130 (mcs_resp == NO_NSS_SUPPORT))
131 SET_VHTNSSMCS(mcs_map_result, nss, NO_NSS_SUPPORT);
132 else
133 SET_VHTNSSMCS(mcs_map_result, nss,
134 min(mcs_user, mcs_resp));
135 }
136
137 vht_cap->vht_cap.supp_mcs.rx_mcs_map = cpu_to_le16(mcs_map_result);
138
139 tmp = mwifiex_convert_mcsmap_to_maxrate(priv, bands, mcs_map_result);
140 vht_cap->vht_cap.supp_mcs.rx_highest = cpu_to_le16(tmp);
141
142 /* tx MCS Set: find the minimum of the user tx mcs and ap tx mcs */
143 mcs_map_user = GET_DEVTXMCSMAP(adapter->usr_dot_11ac_mcs_support);
144 mcs_map_resp = le16_to_cpu(vht_cap->vht_cap.supp_mcs.tx_mcs_map);
145 mcs_map_result = 0;
146
147 for (nss = 1; nss <= 8; nss++) {
148 mcs_user = GET_VHTNSSMCS(mcs_map_user, nss);
149 mcs_resp = GET_VHTNSSMCS(mcs_map_resp, nss);
150 if ((mcs_user == NO_NSS_SUPPORT) ||
151 (mcs_resp == NO_NSS_SUPPORT))
152 SET_VHTNSSMCS(mcs_map_result, nss, NO_NSS_SUPPORT);
153 else
154 SET_VHTNSSMCS(mcs_map_result, nss,
155 min(mcs_user, mcs_resp));
156 }
157
158 vht_cap->vht_cap.supp_mcs.tx_mcs_map = cpu_to_le16(mcs_map_result);
159
160 tmp = mwifiex_convert_mcsmap_to_maxrate(priv, bands, mcs_map_result);
161 vht_cap->vht_cap.supp_mcs.tx_highest = cpu_to_le16(tmp);
162
163 return;
164}
165
166int mwifiex_cmd_append_11ac_tlv(struct mwifiex_private *priv,
167 struct mwifiex_bssdescriptor *bss_desc,
168 u8 **buffer)
169{
170 struct mwifiex_ie_types_vhtcap *vht_cap;
171 struct mwifiex_ie_types_oper_mode_ntf *oper_ntf;
172 struct ieee_types_oper_mode_ntf *ieee_oper_ntf;
173 struct mwifiex_ie_types_vht_oper *vht_op;
174 struct mwifiex_adapter *adapter = priv->adapter;
175 u8 supp_chwd_set;
176 u32 usr_vht_cap_info;
177 int ret_len = 0;
178
179 if (bss_desc->bss_band & BAND_A)
180 usr_vht_cap_info = adapter->usr_dot_11ac_dev_cap_a;
181 else
182 usr_vht_cap_info = adapter->usr_dot_11ac_dev_cap_bg;
183
184 /* VHT Capabilities IE */
185 if (bss_desc->bcn_vht_cap) {
186 vht_cap = (struct mwifiex_ie_types_vhtcap *)*buffer;
187 memset(vht_cap, 0, sizeof(*vht_cap));
188 vht_cap->header.type = cpu_to_le16(WLAN_EID_VHT_CAPABILITY);
189 vht_cap->header.len =
190 cpu_to_le16(sizeof(struct ieee80211_vht_cap));
191 memcpy((u8 *)vht_cap + sizeof(struct mwifiex_ie_types_header),
192 (u8 *)bss_desc->bcn_vht_cap +
193 sizeof(struct ieee_types_header),
194 le16_to_cpu(vht_cap->header.len));
195
196 mwifiex_fill_vht_cap_tlv(priv, vht_cap, bss_desc->bss_band);
197 *buffer += sizeof(*vht_cap);
198 ret_len += sizeof(*vht_cap);
199 }
200
201 /* VHT Operation IE */
202 if (bss_desc->bcn_vht_oper) {
203 if (priv->bss_mode == HostCmd_BSS_MODE_IBSS) {
204 vht_op = (struct mwifiex_ie_types_vht_oper *)*buffer;
205 memset(vht_op, 0, sizeof(*vht_op));
206 vht_op->header.type =
207 cpu_to_le16(WLAN_EID_VHT_OPERATION);
208 vht_op->header.len = cpu_to_le16(sizeof(*vht_op) -
209 sizeof(struct mwifiex_ie_types_header));
210 memcpy((u8 *)vht_op +
211 sizeof(struct mwifiex_ie_types_header),
212 (u8 *)bss_desc->bcn_vht_oper +
213 sizeof(struct ieee_types_header),
214 le16_to_cpu(vht_op->header.len));
215
216 /* negotiate the channel width and central freq
217 * and keep the central freq as the peer suggests
218 */
219 supp_chwd_set = GET_VHTCAP_CHWDSET(usr_vht_cap_info);
220
221 switch (supp_chwd_set) {
222 case 0:
223 vht_op->chan_width =
224 min_t(u8, IEEE80211_VHT_CHANWIDTH_80MHZ,
225 bss_desc->bcn_vht_oper->chan_width);
226 break;
227 case 1:
228 vht_op->chan_width =
229 min_t(u8, IEEE80211_VHT_CHANWIDTH_160MHZ,
230 bss_desc->bcn_vht_oper->chan_width);
231 break;
232 case 2:
233 vht_op->chan_width =
234 min_t(u8, IEEE80211_VHT_CHANWIDTH_80P80MHZ,
235 bss_desc->bcn_vht_oper->chan_width);
236 break;
237 default:
238 vht_op->chan_width =
239 IEEE80211_VHT_CHANWIDTH_USE_HT;
240 break;
241 }
242
243 *buffer += sizeof(*vht_op);
244 ret_len += sizeof(*vht_op);
245 }
246 }
247
248 /* Operating Mode Notification IE */
249 if (bss_desc->oper_mode) {
250 ieee_oper_ntf = bss_desc->oper_mode;
251 oper_ntf = (void *)*buffer;
252 memset(oper_ntf, 0, sizeof(*oper_ntf));
253 oper_ntf->header.type = cpu_to_le16(WLAN_EID_OPMODE_NOTIF);
254 oper_ntf->header.len = cpu_to_le16(sizeof(u8));
255 oper_ntf->oper_mode = ieee_oper_ntf->oper_mode;
256 *buffer += sizeof(*oper_ntf);
257 ret_len += sizeof(*oper_ntf);
258 }
259
260 return ret_len;
261}
diff --git a/drivers/net/wireless/mwifiex/11ac.h b/drivers/net/wireless/mwifiex/11ac.h
new file mode 100644
index 000000000000..80fd1ba46200
--- /dev/null
+++ b/drivers/net/wireless/mwifiex/11ac.h
@@ -0,0 +1,26 @@
1/*
2 * Marvell Wireless LAN device driver: 802.11ac
3 *
4 * Copyright (C) 2013, Marvell International Ltd.
5 *
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
13 *
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
18 */
19
20#ifndef _MWIFIEX_11AC_H_
21#define _MWIFIEX_11AC_H_
22
23int mwifiex_cmd_append_11ac_tlv(struct mwifiex_private *priv,
24 struct mwifiex_bssdescriptor *bss_desc,
25 u8 **buffer);
26#endif /* _MWIFIEX_11AC_H_ */
diff --git a/drivers/net/wireless/mwifiex/11n.c b/drivers/net/wireless/mwifiex/11n.c
index 245a371f1a43..45f19716687e 100644
--- a/drivers/net/wireless/mwifiex/11n.c
+++ b/drivers/net/wireless/mwifiex/11n.c
@@ -53,7 +53,9 @@ mwifiex_fill_cap_info(struct mwifiex_private *priv, u8 radio_type,
53 sizeof(sband->ht_cap.mcs)); 53 sizeof(sband->ht_cap.mcs));
54 54
55 if (priv->bss_mode == NL80211_IFTYPE_STATION || 55 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
56 sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) 56 (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
57 (priv->adapter->sec_chan_offset !=
58 IEEE80211_HT_PARAM_CHA_SEC_NONE)))
57 /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */ 59 /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */
58 SETHT_MCS32(ht_cap->ht_cap.mcs.rx_mask); 60 SETHT_MCS32(ht_cap->ht_cap.mcs.rx_mask);
59 61
@@ -248,7 +250,8 @@ int mwifiex_cmd_amsdu_aggr_ctrl(struct host_cmd_ds_command *cmd,
248 * - Setting HT Tx capability and HT Tx information fields 250 * - Setting HT Tx capability and HT Tx information fields
249 * - Ensuring correct endian-ness 251 * - Ensuring correct endian-ness
250 */ 252 */
251int mwifiex_cmd_11n_cfg(struct host_cmd_ds_command *cmd, u16 cmd_action, 253int mwifiex_cmd_11n_cfg(struct mwifiex_private *priv,
254 struct host_cmd_ds_command *cmd, u16 cmd_action,
252 struct mwifiex_ds_11n_tx_cfg *txcfg) 255 struct mwifiex_ds_11n_tx_cfg *txcfg)
253{ 256{
254 struct host_cmd_ds_11n_cfg *htcfg = &cmd->params.htcfg; 257 struct host_cmd_ds_11n_cfg *htcfg = &cmd->params.htcfg;
@@ -258,6 +261,10 @@ int mwifiex_cmd_11n_cfg(struct host_cmd_ds_command *cmd, u16 cmd_action,
258 htcfg->action = cpu_to_le16(cmd_action); 261 htcfg->action = cpu_to_le16(cmd_action);
259 htcfg->ht_tx_cap = cpu_to_le16(txcfg->tx_htcap); 262 htcfg->ht_tx_cap = cpu_to_le16(txcfg->tx_htcap);
260 htcfg->ht_tx_info = cpu_to_le16(txcfg->tx_htinfo); 263 htcfg->ht_tx_info = cpu_to_le16(txcfg->tx_htinfo);
264
265 if (priv->adapter->is_hw_11ac_capable)
266 htcfg->misc_config = cpu_to_le16(txcfg->misc_config);
267
261 return 0; 268 return 0;
262} 269}
263 270
@@ -398,45 +405,6 @@ mwifiex_cmd_append_11n_tlv(struct mwifiex_private *priv,
398} 405}
399 406
400/* 407/*
401 * This function reconfigures the Tx buffer size in firmware.
402 *
403 * This function prepares a firmware command and issues it, if
404 * the current Tx buffer size is different from the one requested.
405 * Maximum configurable Tx buffer size is limited by the HT capability
406 * field value.
407 */
408void
409mwifiex_cfg_tx_buf(struct mwifiex_private *priv,
410 struct mwifiex_bssdescriptor *bss_desc)
411{
412 u16 max_amsdu = MWIFIEX_TX_DATA_BUF_SIZE_2K;
413 u16 tx_buf, curr_tx_buf_size = 0;
414
415 if (bss_desc->bcn_ht_cap) {
416 if (le16_to_cpu(bss_desc->bcn_ht_cap->cap_info) &
417 IEEE80211_HT_CAP_MAX_AMSDU)
418 max_amsdu = MWIFIEX_TX_DATA_BUF_SIZE_8K;
419 else
420 max_amsdu = MWIFIEX_TX_DATA_BUF_SIZE_4K;
421 }
422
423 tx_buf = min(priv->adapter->max_tx_buf_size, max_amsdu);
424
425 dev_dbg(priv->adapter->dev, "info: max_amsdu=%d, max_tx_buf=%d\n",
426 max_amsdu, priv->adapter->max_tx_buf_size);
427
428 if (priv->adapter->curr_tx_buf_size <= MWIFIEX_TX_DATA_BUF_SIZE_2K)
429 curr_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;
430 else if (priv->adapter->curr_tx_buf_size <= MWIFIEX_TX_DATA_BUF_SIZE_4K)
431 curr_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_4K;
432 else if (priv->adapter->curr_tx_buf_size <= MWIFIEX_TX_DATA_BUF_SIZE_8K)
433 curr_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_8K;
434 if (curr_tx_buf_size != tx_buf)
435 mwifiex_send_cmd_async(priv, HostCmd_CMD_RECONFIGURE_TX_BUFF,
436 HostCmd_ACT_GEN_SET, 0, &tx_buf);
437}
438
439/*
440 * This function checks if the given pointer is valid entry of 408 * This function checks if the given pointer is valid entry of
441 * Tx BA Stream table. 409 * Tx BA Stream table.
442 */ 410 */
@@ -531,11 +499,8 @@ void mwifiex_create_ba_tbl(struct mwifiex_private *priv, u8 *ra, int tid,
531 if (!mwifiex_get_ba_tbl(priv, tid, ra)) { 499 if (!mwifiex_get_ba_tbl(priv, tid, ra)) {
532 new_node = kzalloc(sizeof(struct mwifiex_tx_ba_stream_tbl), 500 new_node = kzalloc(sizeof(struct mwifiex_tx_ba_stream_tbl),
533 GFP_ATOMIC); 501 GFP_ATOMIC);
534 if (!new_node) { 502 if (!new_node)
535 dev_err(priv->adapter->dev,
536 "%s: failed to alloc new_node\n", __func__);
537 return; 503 return;
538 }
539 504
540 INIT_LIST_HEAD(&new_node->list); 505 INIT_LIST_HEAD(&new_node->list);
541 506
diff --git a/drivers/net/wireless/mwifiex/11n.h b/drivers/net/wireless/mwifiex/11n.h
index 46006a54a656..375db01442bf 100644
--- a/drivers/net/wireless/mwifiex/11n.h
+++ b/drivers/net/wireless/mwifiex/11n.h
@@ -28,14 +28,12 @@ int mwifiex_ret_11n_delba(struct mwifiex_private *priv,
28 struct host_cmd_ds_command *resp); 28 struct host_cmd_ds_command *resp);
29int mwifiex_ret_11n_addba_req(struct mwifiex_private *priv, 29int mwifiex_ret_11n_addba_req(struct mwifiex_private *priv,
30 struct host_cmd_ds_command *resp); 30 struct host_cmd_ds_command *resp);
31int mwifiex_cmd_11n_cfg(struct host_cmd_ds_command *cmd, u16 cmd_action, 31int mwifiex_cmd_11n_cfg(struct mwifiex_private *priv,
32 struct host_cmd_ds_command *cmd, u16 cmd_action,
32 struct mwifiex_ds_11n_tx_cfg *txcfg); 33 struct mwifiex_ds_11n_tx_cfg *txcfg);
33
34int mwifiex_cmd_append_11n_tlv(struct mwifiex_private *priv, 34int mwifiex_cmd_append_11n_tlv(struct mwifiex_private *priv,
35 struct mwifiex_bssdescriptor *bss_desc, 35 struct mwifiex_bssdescriptor *bss_desc,
36 u8 **buffer); 36 u8 **buffer);
37void mwifiex_cfg_tx_buf(struct mwifiex_private *priv,
38 struct mwifiex_bssdescriptor *bss_desc);
39void mwifiex_fill_cap_info(struct mwifiex_private *, u8 radio_type, 37void mwifiex_fill_cap_info(struct mwifiex_private *, u8 radio_type,
40 struct mwifiex_ie_types_htcap *); 38 struct mwifiex_ie_types_htcap *);
41int mwifiex_set_get_11n_htcap_cfg(struct mwifiex_private *priv, 39int mwifiex_set_get_11n_htcap_cfg(struct mwifiex_private *priv,
diff --git a/drivers/net/wireless/mwifiex/11n_aggr.c b/drivers/net/wireless/mwifiex/11n_aggr.c
index 68d52cfc1ebd..af8fe6352eed 100644
--- a/drivers/net/wireless/mwifiex/11n_aggr.c
+++ b/drivers/net/wireless/mwifiex/11n_aggr.c
@@ -278,14 +278,16 @@ mwifiex_11n_aggregate_pkt(struct mwifiex_private *priv,
278 dev_dbg(adapter->dev, "data: -EBUSY is returned\n"); 278 dev_dbg(adapter->dev, "data: -EBUSY is returned\n");
279 break; 279 break;
280 case -1: 280 case -1:
281 adapter->data_sent = false; 281 if (adapter->iface_type != MWIFIEX_PCIE)
282 adapter->data_sent = false;
282 dev_err(adapter->dev, "%s: host_to_card failed: %#x\n", 283 dev_err(adapter->dev, "%s: host_to_card failed: %#x\n",
283 __func__, ret); 284 __func__, ret);
284 adapter->dbg.num_tx_host_to_card_failure++; 285 adapter->dbg.num_tx_host_to_card_failure++;
285 mwifiex_write_data_complete(adapter, skb_aggr, 1, ret); 286 mwifiex_write_data_complete(adapter, skb_aggr, 1, ret);
286 return 0; 287 return 0;
287 case -EINPROGRESS: 288 case -EINPROGRESS:
288 adapter->data_sent = false; 289 if (adapter->iface_type != MWIFIEX_PCIE)
290 adapter->data_sent = false;
289 break; 291 break;
290 case 0: 292 case 0:
291 mwifiex_write_data_complete(adapter, skb_aggr, 1, ret); 293 mwifiex_write_data_complete(adapter, skb_aggr, 1, ret);
diff --git a/drivers/net/wireless/mwifiex/11n_rxreorder.c b/drivers/net/wireless/mwifiex/11n_rxreorder.c
index 4a97acd170f7..5e796f847088 100644
--- a/drivers/net/wireless/mwifiex/11n_rxreorder.c
+++ b/drivers/net/wireless/mwifiex/11n_rxreorder.c
@@ -272,11 +272,8 @@ mwifiex_11n_create_rx_reorder_tbl(struct mwifiex_private *priv, u8 *ta,
272 } 272 }
273 /* if !tbl then create one */ 273 /* if !tbl then create one */
274 new_node = kzalloc(sizeof(struct mwifiex_rx_reorder_tbl), GFP_KERNEL); 274 new_node = kzalloc(sizeof(struct mwifiex_rx_reorder_tbl), GFP_KERNEL);
275 if (!new_node) { 275 if (!new_node)
276 dev_err(priv->adapter->dev, "%s: failed to alloc new_node\n",
277 __func__);
278 return; 276 return;
279 }
280 277
281 INIT_LIST_HEAD(&new_node->list); 278 INIT_LIST_HEAD(&new_node->list);
282 new_node->tid = tid; 279 new_node->tid = tid;
diff --git a/drivers/net/wireless/mwifiex/Kconfig b/drivers/net/wireless/mwifiex/Kconfig
index b2e27723f801..4f614aad9ded 100644
--- a/drivers/net/wireless/mwifiex/Kconfig
+++ b/drivers/net/wireless/mwifiex/Kconfig
@@ -20,12 +20,12 @@ config MWIFIEX_SDIO
20 mwifiex_sdio. 20 mwifiex_sdio.
21 21
22config MWIFIEX_PCIE 22config MWIFIEX_PCIE
23 tristate "Marvell WiFi-Ex Driver for PCIE 8766" 23 tristate "Marvell WiFi-Ex Driver for PCIE 8766/8897"
24 depends on MWIFIEX && PCI 24 depends on MWIFIEX && PCI
25 select FW_LOADER 25 select FW_LOADER
26 ---help--- 26 ---help---
27 This adds support for wireless adapters based on Marvell 27 This adds support for wireless adapters based on Marvell
28 8766 chipset with PCIe interface. 28 8766/8897 chipsets with PCIe interface.
29 29
30 If you choose to build it as a module, it will be called 30 If you choose to build it as a module, it will be called
31 mwifiex_pcie. 31 mwifiex_pcie.
diff --git a/drivers/net/wireless/mwifiex/Makefile b/drivers/net/wireless/mwifiex/Makefile
index dd0410d2d465..97b245cbafd8 100644
--- a/drivers/net/wireless/mwifiex/Makefile
+++ b/drivers/net/wireless/mwifiex/Makefile
@@ -23,6 +23,7 @@ mwifiex-y += util.o
23mwifiex-y += txrx.o 23mwifiex-y += txrx.o
24mwifiex-y += wmm.o 24mwifiex-y += wmm.o
25mwifiex-y += 11n.o 25mwifiex-y += 11n.o
26mwifiex-y += 11ac.o
26mwifiex-y += 11n_aggr.o 27mwifiex-y += 11n_aggr.o
27mwifiex-y += 11n_rxreorder.o 28mwifiex-y += 11n_rxreorder.o
28mwifiex-y += scan.o 29mwifiex-y += scan.o
diff --git a/drivers/net/wireless/mwifiex/README b/drivers/net/wireless/mwifiex/README
index b55badef4660..3d64613ebb29 100644
--- a/drivers/net/wireless/mwifiex/README
+++ b/drivers/net/wireless/mwifiex/README
@@ -121,7 +121,6 @@ info
121 wmm_ac_vi = <number of packets sent to device from WMM AcVi queue> 121 wmm_ac_vi = <number of packets sent to device from WMM AcVi queue>
122 wmm_ac_be = <number of packets sent to device from WMM AcBE queue> 122 wmm_ac_be = <number of packets sent to device from WMM AcBE queue>
123 wmm_ac_bk = <number of packets sent to device from WMM AcBK queue> 123 wmm_ac_bk = <number of packets sent to device from WMM AcBK queue>
124 max_tx_buf_size = <maximum Tx buffer size>
125 tx_buf_size = <current Tx buffer size> 124 tx_buf_size = <current Tx buffer size>
126 curr_tx_buf_size = <current Tx buffer size> 125 curr_tx_buf_size = <current Tx buffer size>
127 ps_mode = <0/1, CAM mode/PS mode> 126 ps_mode = <0/1, CAM mode/PS mode>
diff --git a/drivers/net/wireless/mwifiex/cfg80211.c b/drivers/net/wireless/mwifiex/cfg80211.c
index cdb11b3964e2..a44023a7bd57 100644
--- a/drivers/net/wireless/mwifiex/cfg80211.c
+++ b/drivers/net/wireless/mwifiex/cfg80211.c
@@ -519,8 +519,8 @@ static int mwifiex_send_domain_info_cmd_fw(struct wiphy *wiphy)
519 * - Set by user 519 * - Set by user
520 * - Set bt Country IE 520 * - Set bt Country IE
521 */ 521 */
522static int mwifiex_reg_notifier(struct wiphy *wiphy, 522static void mwifiex_reg_notifier(struct wiphy *wiphy,
523 struct regulatory_request *request) 523 struct regulatory_request *request)
524{ 524{
525 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy); 525 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
526 526
@@ -540,8 +540,6 @@ static int mwifiex_reg_notifier(struct wiphy *wiphy,
540 break; 540 break;
541 } 541 }
542 mwifiex_send_domain_info_cmd_fw(wiphy); 542 mwifiex_send_domain_info_cmd_fw(wiphy);
543
544 return 0;
545} 543}
546 544
547/* 545/*
@@ -836,6 +834,66 @@ mwifiex_cfg80211_change_virtual_intf(struct wiphy *wiphy,
836 return ret; 834 return ret;
837} 835}
838 836
837static void
838mwifiex_parse_htinfo(struct mwifiex_private *priv, u8 tx_htinfo,
839 struct rate_info *rate)
840{
841 struct mwifiex_adapter *adapter = priv->adapter;
842
843 if (adapter->is_hw_11ac_capable) {
844 /* bit[1-0]: 00=LG 01=HT 10=VHT */
845 if (tx_htinfo & BIT(0)) {
846 /* HT */
847 rate->mcs = priv->tx_rate;
848 rate->flags |= RATE_INFO_FLAGS_MCS;
849 }
850 if (tx_htinfo & BIT(1)) {
851 /* VHT */
852 rate->mcs = priv->tx_rate & 0x0F;
853 rate->flags |= RATE_INFO_FLAGS_VHT_MCS;
854 }
855
856 if (tx_htinfo & (BIT(1) | BIT(0))) {
857 /* HT or VHT */
858 switch (tx_htinfo & (BIT(3) | BIT(2))) {
859 case 0:
860 /* This will be 20MHz */
861 break;
862 case (BIT(2)):
863 rate->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
864 break;
865 case (BIT(3)):
866 rate->flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
867 break;
868 case (BIT(3) | BIT(2)):
869 rate->flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
870 break;
871 }
872
873 if (tx_htinfo & BIT(4))
874 rate->flags |= RATE_INFO_FLAGS_SHORT_GI;
875
876 if ((priv->tx_rate >> 4) == 1)
877 rate->nss = 2;
878 else
879 rate->nss = 1;
880 }
881 } else {
882 /*
883 * Bit 0 in tx_htinfo indicates that current Tx rate
884 * is 11n rate. Valid MCS index values for us are 0 to 15.
885 */
886 if ((tx_htinfo & BIT(0)) && (priv->tx_rate < 16)) {
887 rate->mcs = priv->tx_rate;
888 rate->flags |= RATE_INFO_FLAGS_MCS;
889 if (tx_htinfo & BIT(1))
890 rate->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
891 if (tx_htinfo & BIT(2))
892 rate->flags |= RATE_INFO_FLAGS_SHORT_GI;
893 }
894 }
895}
896
839/* 897/*
840 * This function dumps the station information on a buffer. 898 * This function dumps the station information on a buffer.
841 * 899 *
@@ -875,20 +933,7 @@ mwifiex_dump_station_info(struct mwifiex_private *priv,
875 HostCmd_ACT_GEN_GET, DTIM_PERIOD_I, 933 HostCmd_ACT_GEN_GET, DTIM_PERIOD_I,
876 &priv->dtim_period); 934 &priv->dtim_period);
877 935
878 /* 936 mwifiex_parse_htinfo(priv, priv->tx_htinfo, &sinfo->txrate);
879 * Bit 0 in tx_htinfo indicates that current Tx rate is 11n rate. Valid
880 * MCS index values for us are 0 to 15.
881 */
882 if ((priv->tx_htinfo & BIT(0)) && (priv->tx_rate < 16)) {
883 sinfo->txrate.mcs = priv->tx_rate;
884 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
885 /* 40MHz rate */
886 if (priv->tx_htinfo & BIT(1))
887 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
888 /* SGI enabled */
889 if (priv->tx_htinfo & BIT(2))
890 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
891 }
892 937
893 sinfo->signal_avg = priv->bcn_rssi_avg; 938 sinfo->signal_avg = priv->bcn_rssi_avg;
894 sinfo->rx_bytes = priv->stats.rx_bytes; 939 sinfo->rx_bytes = priv->stats.rx_bytes;
@@ -1297,20 +1342,22 @@ static int mwifiex_cfg80211_start_ap(struct wiphy *wiphy,
1297 /* Set appropriate bands */ 1342 /* Set appropriate bands */
1298 if (params->chandef.chan->band == IEEE80211_BAND_2GHZ) { 1343 if (params->chandef.chan->band == IEEE80211_BAND_2GHZ) {
1299 bss_cfg->band_cfg = BAND_CONFIG_BG; 1344 bss_cfg->band_cfg = BAND_CONFIG_BG;
1345 config_bands = BAND_B | BAND_G;
1300 1346
1301 if (cfg80211_get_chandef_type(&params->chandef) == 1347 if (params->chandef.width > NL80211_CHAN_WIDTH_20_NOHT)
1302 NL80211_CHAN_NO_HT) 1348 config_bands |= BAND_GN;
1303 config_bands = BAND_B | BAND_G; 1349
1304 else 1350 if (params->chandef.width > NL80211_CHAN_WIDTH_40)
1305 config_bands = BAND_B | BAND_G | BAND_GN; 1351 config_bands |= BAND_GAC;
1306 } else { 1352 } else {
1307 bss_cfg->band_cfg = BAND_CONFIG_A; 1353 bss_cfg->band_cfg = BAND_CONFIG_A;
1354 config_bands = BAND_A;
1308 1355
1309 if (cfg80211_get_chandef_type(&params->chandef) == 1356 if (params->chandef.width > NL80211_CHAN_WIDTH_20_NOHT)
1310 NL80211_CHAN_NO_HT) 1357 config_bands |= BAND_AN;
1311 config_bands = BAND_A; 1358
1312 else 1359 if (params->chandef.width > NL80211_CHAN_WIDTH_40)
1313 config_bands = BAND_AN | BAND_A; 1360 config_bands |= BAND_AAC;
1314 } 1361 }
1315 1362
1316 if (!((config_bands | priv->adapter->fw_bands) & 1363 if (!((config_bands | priv->adapter->fw_bands) &
@@ -1327,6 +1374,7 @@ static int mwifiex_cfg80211_start_ap(struct wiphy *wiphy,
1327 } 1374 }
1328 1375
1329 mwifiex_set_ht_params(priv, bss_cfg, params); 1376 mwifiex_set_ht_params(priv, bss_cfg, params);
1377 mwifiex_set_wmm_params(priv, bss_cfg, params);
1330 1378
1331 if (params->inactivity_timeout > 0) { 1379 if (params->inactivity_timeout > 0) {
1332 /* sta_ao_timer/ps_sta_ao_timer is in unit of 100ms */ 1380 /* sta_ao_timer/ps_sta_ao_timer is in unit of 100ms */
@@ -1431,7 +1479,7 @@ static int mwifiex_cfg80211_inform_ibss_bss(struct mwifiex_private *priv)
1431 bss = cfg80211_inform_bss(priv->wdev->wiphy, chan, 1479 bss = cfg80211_inform_bss(priv->wdev->wiphy, chan,
1432 bss_info.bssid, 0, WLAN_CAPABILITY_IBSS, 1480 bss_info.bssid, 0, WLAN_CAPABILITY_IBSS,
1433 0, ie_buf, ie_len, 0, GFP_KERNEL); 1481 0, ie_buf, ie_len, 0, GFP_KERNEL);
1434 cfg80211_put_bss(bss); 1482 cfg80211_put_bss(priv->wdev->wiphy, bss);
1435 memcpy(priv->cfg_bssid, bss_info.bssid, ETH_ALEN); 1483 memcpy(priv->cfg_bssid, bss_info.bssid, ETH_ALEN);
1436 1484
1437 return 0; 1485 return 0;
@@ -1821,10 +1869,8 @@ mwifiex_cfg80211_scan(struct wiphy *wiphy,
1821 1869
1822 priv->user_scan_cfg = kzalloc(sizeof(struct mwifiex_user_scan_cfg), 1870 priv->user_scan_cfg = kzalloc(sizeof(struct mwifiex_user_scan_cfg),
1823 GFP_KERNEL); 1871 GFP_KERNEL);
1824 if (!priv->user_scan_cfg) { 1872 if (!priv->user_scan_cfg)
1825 dev_err(priv->adapter->dev, "failed to alloc scan_req\n");
1826 return -ENOMEM; 1873 return -ENOMEM;
1827 }
1828 1874
1829 priv->scan_request = request; 1875 priv->scan_request = request;
1830 1876
@@ -1882,6 +1928,79 @@ mwifiex_cfg80211_scan(struct wiphy *wiphy,
1882 return 0; 1928 return 0;
1883} 1929}
1884 1930
1931static void mwifiex_setup_vht_caps(struct ieee80211_sta_vht_cap *vht_info,
1932 struct mwifiex_private *priv)
1933{
1934 struct mwifiex_adapter *adapter = priv->adapter;
1935 u32 vht_cap = 0, cap = adapter->hw_dot_11ac_dev_cap;
1936
1937 vht_info->vht_supported = true;
1938
1939 switch (GET_VHTCAP_MAXMPDULEN(cap)) {
1940 case 0x00:
1941 vht_cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1942 break;
1943 case 0x01:
1944 vht_cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1945 break;
1946 case 0x10:
1947 vht_cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1948 break;
1949 default:
1950 dev_err(adapter->dev, "unsupported MAX MPDU len\n");
1951 break;
1952 }
1953
1954 if (ISSUPP_11ACVHTHTCVHT(cap))
1955 vht_cap |= IEEE80211_VHT_CAP_HTC_VHT;
1956
1957 if (ISSUPP_11ACVHTTXOPPS(cap))
1958 vht_cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1959
1960 if (ISSUPP_11ACMURXBEAMFORMEE(cap))
1961 vht_cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1962
1963 if (ISSUPP_11ACMUTXBEAMFORMEE(cap))
1964 vht_cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1965
1966 if (ISSUPP_11ACSUBEAMFORMER(cap))
1967 vht_cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1968
1969 if (ISSUPP_11ACSUBEAMFORMEE(cap))
1970 vht_cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1971
1972 if (ISSUPP_11ACRXSTBC(cap))
1973 vht_cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1974
1975 if (ISSUPP_11ACTXSTBC(cap))
1976 vht_cap |= IEEE80211_VHT_CAP_TXSTBC;
1977
1978 if (ISSUPP_11ACSGI160(cap))
1979 vht_cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1980
1981 if (ISSUPP_11ACSGI80(cap))
1982 vht_cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1983
1984 if (ISSUPP_11ACLDPC(cap))
1985 vht_cap |= IEEE80211_VHT_CAP_RXLDPC;
1986
1987 if (ISSUPP_11ACBW8080(cap))
1988 vht_cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
1989
1990 if (ISSUPP_11ACBW160(cap))
1991 vht_cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
1992
1993 vht_info->cap = vht_cap;
1994
1995 /* Update MCS support for VHT */
1996 vht_info->vht_mcs.rx_mcs_map = cpu_to_le16(
1997 adapter->hw_dot_11ac_mcs_support & 0xFFFF);
1998 vht_info->vht_mcs.rx_highest = 0;
1999 vht_info->vht_mcs.tx_mcs_map = cpu_to_le16(
2000 adapter->hw_dot_11ac_mcs_support >> 16);
2001 vht_info->vht_mcs.tx_highest = 0;
2002}
2003
1885/* 2004/*
1886 * This function sets up the CFG802.11 specific HT capability fields 2005 * This function sets up the CFG802.11 specific HT capability fields
1887 * with default values. 2006 * with default values.
@@ -2095,16 +2214,22 @@ struct wireless_dev *mwifiex_add_virtual_intf(struct wiphy *wiphy,
2095 priv->netdev = dev; 2214 priv->netdev = dev;
2096 2215
2097 mwifiex_setup_ht_caps(&wiphy->bands[IEEE80211_BAND_2GHZ]->ht_cap, priv); 2216 mwifiex_setup_ht_caps(&wiphy->bands[IEEE80211_BAND_2GHZ]->ht_cap, priv);
2217 if (adapter->is_hw_11ac_capable)
2218 mwifiex_setup_vht_caps(
2219 &wiphy->bands[IEEE80211_BAND_2GHZ]->vht_cap, priv);
2098 2220
2099 if (adapter->config_bands & BAND_A) 2221 if (adapter->config_bands & BAND_A)
2100 mwifiex_setup_ht_caps( 2222 mwifiex_setup_ht_caps(
2101 &wiphy->bands[IEEE80211_BAND_5GHZ]->ht_cap, priv); 2223 &wiphy->bands[IEEE80211_BAND_5GHZ]->ht_cap, priv);
2102 2224
2225 if ((adapter->config_bands & BAND_A) && adapter->is_hw_11ac_capable)
2226 mwifiex_setup_vht_caps(
2227 &wiphy->bands[IEEE80211_BAND_5GHZ]->vht_cap, priv);
2228
2103 dev_net_set(dev, wiphy_net(wiphy)); 2229 dev_net_set(dev, wiphy_net(wiphy));
2104 dev->ieee80211_ptr = priv->wdev; 2230 dev->ieee80211_ptr = priv->wdev;
2105 dev->ieee80211_ptr->iftype = priv->bss_mode; 2231 dev->ieee80211_ptr->iftype = priv->bss_mode;
2106 memcpy(dev->dev_addr, wiphy->perm_addr, ETH_ALEN); 2232 memcpy(dev->dev_addr, wiphy->perm_addr, ETH_ALEN);
2107 memcpy(dev->perm_addr, wiphy->perm_addr, ETH_ALEN);
2108 SET_NETDEV_DEV(dev, wiphy_dev(wiphy)); 2233 SET_NETDEV_DEV(dev, wiphy_dev(wiphy));
2109 2234
2110 dev->flags |= IFF_BROADCAST | IFF_MULTICAST; 2235 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
@@ -2248,6 +2373,7 @@ int mwifiex_register_cfg80211(struct mwifiex_adapter *adapter)
2248 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM; 2373 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
2249 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME | 2374 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
2250 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD | 2375 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD |
2376 WIPHY_FLAG_AP_UAPSD |
2251 WIPHY_FLAG_CUSTOM_REGULATORY | 2377 WIPHY_FLAG_CUSTOM_REGULATORY |
2252 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; 2378 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
2253 2379
diff --git a/drivers/net/wireless/mwifiex/cfp.c b/drivers/net/wireless/mwifiex/cfp.c
index f69300f93f42..988552dece75 100644
--- a/drivers/net/wireless/mwifiex/cfp.c
+++ b/drivers/net/wireless/mwifiex/cfp.c
@@ -106,8 +106,8 @@ u8 *mwifiex_11d_code_2_region(u8 code)
106 * This function maps an index in supported rates table into 106 * This function maps an index in supported rates table into
107 * the corresponding data rate. 107 * the corresponding data rate.
108 */ 108 */
109u32 mwifiex_index_to_data_rate(struct mwifiex_private *priv, u8 index, 109u32 mwifiex_index_to_acs_data_rate(struct mwifiex_private *priv,
110 u8 ht_info) 110 u8 index, u8 ht_info)
111{ 111{
112 /* 112 /*
113 * For every mcs_rate line, the first 8 bytes are for stream 1x1, 113 * For every mcs_rate line, the first 8 bytes are for stream 1x1,
@@ -130,10 +130,155 @@ u32 mwifiex_index_to_data_rate(struct mwifiex_private *priv, u8 index,
130 { 0x0e, 0x1c, 0x2b, 0x39, 0x56, 0x73, 0x82, 0x90, 130 { 0x0e, 0x1c, 0x2b, 0x39, 0x56, 0x73, 0x82, 0x90,
131 0x1c, 0x39, 0x56, 0x73, 0xad, 0xe7, 0x104, 0x120 } 131 0x1c, 0x39, 0x56, 0x73, 0xad, 0xe7, 0x104, 0x120 }
132 }; 132 };
133 /* AC rates */
134 u16 ac_mcs_rate_nss1[8][10] = {
135 /* LG 160M */
136 { 0x75, 0xEA, 0x15F, 0x1D4, 0x2BE, 0x3A8, 0x41D,
137 0x492, 0x57C, 0x618 },
138
139 /* SG 160M */
140 { 0x82, 0x104, 0x186, 0x208, 0x30C, 0x410, 0x492,
141 0x514, 0x618, 0x6C6 },
142
143 /* LG 80M */
144 { 0x3B, 0x75, 0xB0, 0xEA, 0x15F, 0x1D4, 0x20F,
145 0x249, 0x2BE, 0x30C },
146
147 /* SG 80M */
148 { 0x41, 0x82, 0xC3, 0x104, 0x186, 0x208, 0x249,
149 0x28A, 0x30C, 0x363 },
150
151 /* LG 40M */
152 { 0x1B, 0x36, 0x51, 0x6C, 0xA2, 0xD8, 0xF3,
153 0x10E, 0x144, 0x168 },
154
155 /* SG 40M */
156 { 0x1E, 0x3C, 0x5A, 0x78, 0xB4, 0xF0, 0x10E,
157 0x12C, 0x168, 0x190 },
158
159 /* LG 20M */
160 { 0xD, 0x1A, 0x27, 0x34, 0x4E, 0x68, 0x75, 0x82, 0x9C, 0x00 },
161
162 /* SG 20M */
163 { 0xF, 0x1D, 0x2C, 0x3A, 0x57, 0x74, 0x82, 0x91, 0xAE, 0x00 },
164 };
165 /* NSS2 note: the value in the table is 2 multiplier of the actual
166 * rate
167 */
168 u16 ac_mcs_rate_nss2[8][10] = {
169 /* LG 160M */
170 { 0xEA, 0x1D4, 0x2BE, 0x3A8, 0x57C, 0x750, 0x83A,
171 0x924, 0xAF8, 0xC30 },
172
173 /* SG 160M */
174 { 0x104, 0x208, 0x30C, 0x410, 0x618, 0x820, 0x924,
175 0xA28, 0xC30, 0xD8B },
176
177 /* LG 80M */
178 { 0x75, 0xEA, 0x15F, 0x1D4, 0x2BE, 0x3A8, 0x41D,
179 0x492, 0x57C, 0x618 },
180
181 /* SG 80M */
182 { 0x82, 0x104, 0x186, 0x208, 0x30C, 0x410, 0x492,
183 0x514, 0x618, 0x6C6 },
184
185 /* LG 40M */
186 { 0x36, 0x6C, 0xA2, 0xD8, 0x144, 0x1B0, 0x1E6,
187 0x21C, 0x288, 0x2D0 },
188
189 /* SG 40M */
190 { 0x3C, 0x78, 0xB4, 0xF0, 0x168, 0x1E0, 0x21C,
191 0x258, 0x2D0, 0x320 },
192
193 /* LG 20M */
194 { 0x1A, 0x34, 0x4A, 0x68, 0x9C, 0xD0, 0xEA, 0x104,
195 0x138, 0x00 },
196
197 /* SG 20M */
198 { 0x1D, 0x3A, 0x57, 0x74, 0xAE, 0xE6, 0x104, 0x121,
199 0x15B, 0x00 },
200 };
201 u32 rate = 0;
202 u8 mcs_index = 0;
203 u8 bw = 0;
204 u8 gi = 0;
205
206 if ((ht_info & 0x3) == MWIFIEX_RATE_FORMAT_VHT) {
207 mcs_index = min(index & 0xF, 9);
208
209 /* 20M: bw=0, 40M: bw=1, 80M: bw=2, 160M: bw=3 */
210 bw = (ht_info & 0xC) >> 2;
211
212 /* LGI: gi =0, SGI: gi = 1 */
213 gi = (ht_info & 0x10) >> 4;
214
215 if ((index >> 4) == 1) /* NSS = 2 */
216 rate = ac_mcs_rate_nss2[2 * (3 - bw) + gi][mcs_index];
217 else /* NSS = 1 */
218 rate = ac_mcs_rate_nss1[2 * (3 - bw) + gi][mcs_index];
219 } else if ((ht_info & 0x3) == MWIFIEX_RATE_FORMAT_HT) {
220 /* 20M: bw=0, 40M: bw=1 */
221 bw = (ht_info & 0xC) >> 2;
222
223 /* LGI: gi =0, SGI: gi = 1 */
224 gi = (ht_info & 0x10) >> 4;
225
226 if (index == MWIFIEX_RATE_BITMAP_MCS0) {
227 if (gi == 1)
228 rate = 0x0D; /* MCS 32 SGI rate */
229 else
230 rate = 0x0C; /* MCS 32 LGI rate */
231 } else if (index < 16) {
232 if ((bw == 1) || (bw == 0))
233 rate = mcs_rate[2 * (1 - bw) + gi][index];
234 else
235 rate = mwifiex_data_rates[0];
236 } else {
237 rate = mwifiex_data_rates[0];
238 }
239 } else {
240 /* 11n non-HT rates */
241 if (index >= MWIFIEX_SUPPORTED_RATES_EXT)
242 index = 0;
243 rate = mwifiex_data_rates[index];
244 }
245
246 return rate;
247}
248
249/* This function maps an index in supported rates table into
250 * the corresponding data rate.
251 */
252u32 mwifiex_index_to_data_rate(struct mwifiex_private *priv,
253 u8 index, u8 ht_info)
254{
255 /* For every mcs_rate line, the first 8 bytes are for stream 1x1,
256 * and all 16 bytes are for stream 2x2.
257 */
258 u16 mcs_rate[4][16] = {
259 /* LGI 40M */
260 { 0x1b, 0x36, 0x51, 0x6c, 0xa2, 0xd8, 0xf3, 0x10e,
261 0x36, 0x6c, 0xa2, 0xd8, 0x144, 0x1b0, 0x1e6, 0x21c },
262
263 /* SGI 40M */
264 { 0x1e, 0x3c, 0x5a, 0x78, 0xb4, 0xf0, 0x10e, 0x12c,
265 0x3c, 0x78, 0xb4, 0xf0, 0x168, 0x1e0, 0x21c, 0x258 },
266
267 /* LGI 20M */
268 { 0x0d, 0x1a, 0x27, 0x34, 0x4e, 0x68, 0x75, 0x82,
269 0x1a, 0x34, 0x4e, 0x68, 0x9c, 0xd0, 0xea, 0x104 },
270
271 /* SGI 20M */
272 { 0x0e, 0x1c, 0x2b, 0x39, 0x56, 0x73, 0x82, 0x90,
273 0x1c, 0x39, 0x56, 0x73, 0xad, 0xe7, 0x104, 0x120 }
274 };
133 u32 mcs_num_supp = 275 u32 mcs_num_supp =
134 (priv->adapter->hw_dev_mcs_support == HT_STREAM_2X2) ? 16 : 8; 276 (priv->adapter->hw_dev_mcs_support == HT_STREAM_2X2) ? 16 : 8;
135 u32 rate; 277 u32 rate;
136 278
279 if (priv->adapter->is_hw_11ac_capable)
280 return mwifiex_index_to_acs_data_rate(priv, index, ht_info);
281
137 if (ht_info & BIT(0)) { 282 if (ht_info & BIT(0)) {
138 if (index == MWIFIEX_RATE_BITMAP_MCS0) { 283 if (index == MWIFIEX_RATE_BITMAP_MCS0) {
139 if (ht_info & BIT(2)) 284 if (ht_info & BIT(2))
@@ -269,6 +414,7 @@ u32 mwifiex_get_supported_rates(struct mwifiex_private *priv, u8 *rates)
269{ 414{
270 u32 k = 0; 415 u32 k = 0;
271 struct mwifiex_adapter *adapter = priv->adapter; 416 struct mwifiex_adapter *adapter = priv->adapter;
417
272 if (priv->bss_mode == NL80211_IFTYPE_STATION) { 418 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
273 switch (adapter->config_bands) { 419 switch (adapter->config_bands) {
274 case BAND_B: 420 case BAND_B:
@@ -279,6 +425,7 @@ u32 mwifiex_get_supported_rates(struct mwifiex_private *priv, u8 *rates)
279 break; 425 break;
280 case BAND_G: 426 case BAND_G:
281 case BAND_G | BAND_GN: 427 case BAND_G | BAND_GN:
428 case BAND_G | BAND_GN | BAND_GAC:
282 dev_dbg(adapter->dev, "info: infra band=%d " 429 dev_dbg(adapter->dev, "info: infra band=%d "
283 "supported_rates_g\n", adapter->config_bands); 430 "supported_rates_g\n", adapter->config_bands);
284 k = mwifiex_copy_rates(rates, k, supported_rates_g, 431 k = mwifiex_copy_rates(rates, k, supported_rates_g,
@@ -288,7 +435,11 @@ u32 mwifiex_get_supported_rates(struct mwifiex_private *priv, u8 *rates)
288 case BAND_A | BAND_B | BAND_G: 435 case BAND_A | BAND_B | BAND_G:
289 case BAND_A | BAND_B: 436 case BAND_A | BAND_B:
290 case BAND_A | BAND_B | BAND_G | BAND_GN | BAND_AN: 437 case BAND_A | BAND_B | BAND_G | BAND_GN | BAND_AN:
438 case BAND_A | BAND_B | BAND_G | BAND_GN | BAND_AN | BAND_AAC:
439 case BAND_A | BAND_B | BAND_G | BAND_GN | BAND_AN |
440 BAND_AAC | BAND_GAC:
291 case BAND_B | BAND_G | BAND_GN: 441 case BAND_B | BAND_G | BAND_GN:
442 case BAND_B | BAND_G | BAND_GN | BAND_GAC:
292 dev_dbg(adapter->dev, "info: infra band=%d " 443 dev_dbg(adapter->dev, "info: infra band=%d "
293 "supported_rates_bg\n", adapter->config_bands); 444 "supported_rates_bg\n", adapter->config_bands);
294 k = mwifiex_copy_rates(rates, k, supported_rates_bg, 445 k = mwifiex_copy_rates(rates, k, supported_rates_bg,
@@ -301,14 +452,18 @@ u32 mwifiex_get_supported_rates(struct mwifiex_private *priv, u8 *rates)
301 k = mwifiex_copy_rates(rates, k, supported_rates_a, 452 k = mwifiex_copy_rates(rates, k, supported_rates_a,
302 sizeof(supported_rates_a)); 453 sizeof(supported_rates_a));
303 break; 454 break;
455 case BAND_AN:
304 case BAND_A | BAND_AN: 456 case BAND_A | BAND_AN:
457 case BAND_A | BAND_AN | BAND_AAC:
305 case BAND_A | BAND_G | BAND_AN | BAND_GN: 458 case BAND_A | BAND_G | BAND_AN | BAND_GN:
459 case BAND_A | BAND_G | BAND_AN | BAND_GN | BAND_AAC:
306 dev_dbg(adapter->dev, "info: infra band=%d " 460 dev_dbg(adapter->dev, "info: infra band=%d "
307 "supported_rates_a\n", adapter->config_bands); 461 "supported_rates_a\n", adapter->config_bands);
308 k = mwifiex_copy_rates(rates, k, supported_rates_a, 462 k = mwifiex_copy_rates(rates, k, supported_rates_a,
309 sizeof(supported_rates_a)); 463 sizeof(supported_rates_a));
310 break; 464 break;
311 case BAND_GN: 465 case BAND_GN:
466 case BAND_GN | BAND_GAC:
312 dev_dbg(adapter->dev, "info: infra band=%d " 467 dev_dbg(adapter->dev, "info: infra band=%d "
313 "supported_rates_n\n", adapter->config_bands); 468 "supported_rates_n\n", adapter->config_bands);
314 k = mwifiex_copy_rates(rates, k, supported_rates_n, 469 k = mwifiex_copy_rates(rates, k, supported_rates_n,
diff --git a/drivers/net/wireless/mwifiex/cmdevt.c b/drivers/net/wireless/mwifiex/cmdevt.c
index 5f438e6c2155..20a6c5555873 100644
--- a/drivers/net/wireless/mwifiex/cmdevt.c
+++ b/drivers/net/wireless/mwifiex/cmdevt.c
@@ -24,6 +24,7 @@
24#include "main.h" 24#include "main.h"
25#include "wmm.h" 25#include "wmm.h"
26#include "11n.h" 26#include "11n.h"
27#include "11ac.h"
27 28
28/* 29/*
29 * This function initializes a command node. 30 * This function initializes a command node.
@@ -334,20 +335,15 @@ static int mwifiex_dnld_sleep_confirm_cmd(struct mwifiex_adapter *adapter)
334int mwifiex_alloc_cmd_buffer(struct mwifiex_adapter *adapter) 335int mwifiex_alloc_cmd_buffer(struct mwifiex_adapter *adapter)
335{ 336{
336 struct cmd_ctrl_node *cmd_array; 337 struct cmd_ctrl_node *cmd_array;
337 u32 buf_size;
338 u32 i; 338 u32 i;
339 339
340 /* Allocate and initialize struct cmd_ctrl_node */ 340 /* Allocate and initialize struct cmd_ctrl_node */
341 buf_size = sizeof(struct cmd_ctrl_node) * MWIFIEX_NUM_OF_CMD_BUFFER; 341 cmd_array = kcalloc(MWIFIEX_NUM_OF_CMD_BUFFER,
342 cmd_array = kzalloc(buf_size, GFP_KERNEL); 342 sizeof(struct cmd_ctrl_node), GFP_KERNEL);
343 if (!cmd_array) { 343 if (!cmd_array)
344 dev_err(adapter->dev, "%s: failed to alloc cmd_array\n",
345 __func__);
346 return -ENOMEM; 344 return -ENOMEM;
347 }
348 345
349 adapter->cmd_pool = cmd_array; 346 adapter->cmd_pool = cmd_array;
350 memset(adapter->cmd_pool, 0, buf_size);
351 347
352 /* Allocate and initialize command buffers */ 348 /* Allocate and initialize command buffers */
353 for (i = 0; i < MWIFIEX_NUM_OF_CMD_BUFFER; i++) { 349 for (i = 0; i < MWIFIEX_NUM_OF_CMD_BUFFER; i++) {
@@ -1470,6 +1466,24 @@ int mwifiex_ret_get_hw_spec(struct mwifiex_private *priv,
1470 adapter->fw_release_number = le32_to_cpu(hw_spec->fw_release_number); 1466 adapter->fw_release_number = le32_to_cpu(hw_spec->fw_release_number);
1471 adapter->number_of_antenna = le16_to_cpu(hw_spec->number_of_antenna); 1467 adapter->number_of_antenna = le16_to_cpu(hw_spec->number_of_antenna);
1472 1468
1469 if (le32_to_cpu(hw_spec->dot_11ac_dev_cap)) {
1470 adapter->is_hw_11ac_capable = true;
1471
1472 /* Copy 11AC cap */
1473 adapter->hw_dot_11ac_dev_cap =
1474 le32_to_cpu(hw_spec->dot_11ac_dev_cap);
1475 adapter->usr_dot_11ac_dev_cap_bg = adapter->hw_dot_11ac_dev_cap;
1476 adapter->usr_dot_11ac_dev_cap_a = adapter->hw_dot_11ac_dev_cap;
1477
1478 /* Copy 11AC mcs */
1479 adapter->hw_dot_11ac_mcs_support =
1480 le32_to_cpu(hw_spec->dot_11ac_mcs_support);
1481 adapter->usr_dot_11ac_mcs_support =
1482 adapter->hw_dot_11ac_mcs_support;
1483 } else {
1484 adapter->is_hw_11ac_capable = false;
1485 }
1486
1473 dev_dbg(adapter->dev, "info: GET_HW_SPEC: fw_release_number- %#x\n", 1487 dev_dbg(adapter->dev, "info: GET_HW_SPEC: fw_release_number- %#x\n",
1474 adapter->fw_release_number); 1488 adapter->fw_release_number);
1475 dev_dbg(adapter->dev, "info: GET_HW_SPEC: permanent addr: %pM\n", 1489 dev_dbg(adapter->dev, "info: GET_HW_SPEC: permanent addr: %pM\n",
diff --git a/drivers/net/wireless/mwifiex/debugfs.c b/drivers/net/wireless/mwifiex/debugfs.c
index 46e34aa65d1c..753b5682d53f 100644
--- a/drivers/net/wireless/mwifiex/debugfs.c
+++ b/drivers/net/wireless/mwifiex/debugfs.c
@@ -58,8 +58,6 @@ static struct mwifiex_debug_data items[] = {
58 item_addr(packets_out[WMM_AC_BE]), 1}, 58 item_addr(packets_out[WMM_AC_BE]), 1},
59 {"wmm_ac_bk", item_size(packets_out[WMM_AC_BK]), 59 {"wmm_ac_bk", item_size(packets_out[WMM_AC_BK]),
60 item_addr(packets_out[WMM_AC_BK]), 1}, 60 item_addr(packets_out[WMM_AC_BK]), 1},
61 {"max_tx_buf_size", item_size(max_tx_buf_size),
62 item_addr(max_tx_buf_size), 1},
63 {"tx_buf_size", item_size(tx_buf_size), 61 {"tx_buf_size", item_size(tx_buf_size),
64 item_addr(tx_buf_size), 1}, 62 item_addr(tx_buf_size), 1},
65 {"curr_tx_buf_size", item_size(curr_tx_buf_size), 63 {"curr_tx_buf_size", item_size(curr_tx_buf_size),
diff --git a/drivers/net/wireless/mwifiex/decl.h b/drivers/net/wireless/mwifiex/decl.h
index e9357d87d327..e8a569aaa2e8 100644
--- a/drivers/net/wireless/mwifiex/decl.h
+++ b/drivers/net/wireless/mwifiex/decl.h
@@ -26,6 +26,7 @@
26#include <linux/wait.h> 26#include <linux/wait.h>
27#include <linux/timer.h> 27#include <linux/timer.h>
28#include <linux/ieee80211.h> 28#include <linux/ieee80211.h>
29#include <net/mac80211.h>
29 30
30 31
31#define MWIFIEX_MAX_BSS_NUM (3) 32#define MWIFIEX_MAX_BSS_NUM (3)
@@ -58,6 +59,8 @@
58#define MWIFIEX_RTS_MAX_VALUE (2347) 59#define MWIFIEX_RTS_MAX_VALUE (2347)
59#define MWIFIEX_FRAG_MIN_VALUE (256) 60#define MWIFIEX_FRAG_MIN_VALUE (256)
60#define MWIFIEX_FRAG_MAX_VALUE (2346) 61#define MWIFIEX_FRAG_MAX_VALUE (2346)
62#define MWIFIEX_WMM_VERSION 0x01
63#define MWIFIEX_WMM_SUBTYPE 0x01
61 64
62#define MWIFIEX_RETRY_LIMIT 14 65#define MWIFIEX_RETRY_LIMIT 14
63#define MWIFIEX_SDIO_BLOCK_SIZE 256 66#define MWIFIEX_SDIO_BLOCK_SIZE 256
@@ -126,4 +129,19 @@ enum mwifiex_wmm_ac_e {
126 WMM_AC_VI, 129 WMM_AC_VI,
127 WMM_AC_VO 130 WMM_AC_VO
128} __packed; 131} __packed;
132
133struct ieee_types_wmm_ac_parameters {
134 u8 aci_aifsn_bitmap;
135 u8 ecw_bitmap;
136 __le16 tx_op_limit;
137} __packed;
138
139struct mwifiex_types_wmm_info {
140 u8 oui[4];
141 u8 subtype;
142 u8 version;
143 u8 qos_info;
144 u8 reserved;
145 struct ieee_types_wmm_ac_parameters ac_params[IEEE80211_NUM_ACS];
146} __packed;
129#endif /* !_MWIFIEX_DECL_H_ */ 147#endif /* !_MWIFIEX_DECL_H_ */
diff --git a/drivers/net/wireless/mwifiex/fw.h b/drivers/net/wireless/mwifiex/fw.h
index 4dc8e2e9a889..25acb0682c56 100644
--- a/drivers/net/wireless/mwifiex/fw.h
+++ b/drivers/net/wireless/mwifiex/fw.h
@@ -49,13 +49,23 @@ struct tx_packet_hdr {
49#define A_SUPPORTED_RATES 9 49#define A_SUPPORTED_RATES 9
50#define HOSTCMD_SUPPORTED_RATES 14 50#define HOSTCMD_SUPPORTED_RATES 14
51#define N_SUPPORTED_RATES 3 51#define N_SUPPORTED_RATES 3
52#define ALL_802_11_BANDS (BAND_A | BAND_B | BAND_G | BAND_GN) 52#define ALL_802_11_BANDS (BAND_A | BAND_B | BAND_G | BAND_GN | \
53 BAND_AN | BAND_GAC | BAND_AAC)
53 54
54#define FW_MULTI_BANDS_SUPPORT (BIT(8) | BIT(9) | BIT(10) | BIT(11)) 55#define FW_MULTI_BANDS_SUPPORT (BIT(8) | BIT(9) | BIT(10) | BIT(11) | \
56 BIT(12) | BIT(13))
55#define IS_SUPPORT_MULTI_BANDS(adapter) \ 57#define IS_SUPPORT_MULTI_BANDS(adapter) \
56 (adapter->fw_cap_info & FW_MULTI_BANDS_SUPPORT) 58 (adapter->fw_cap_info & FW_MULTI_BANDS_SUPPORT)
59
60/* shift bit 12 and bit 13 in fw_cap_info from the firmware to bit 13 and 14
61 * for 11ac so that bit 11 is for GN, bit 12 for AN, bit 13 for GAC, and bit
62 * bit 14 for AAC, in order to be compatible with the band capability
63 * defined in the driver after right shift of 8 bits.
64 */
57#define GET_FW_DEFAULT_BANDS(adapter) \ 65#define GET_FW_DEFAULT_BANDS(adapter) \
58 ((adapter->fw_cap_info >> 8) & ALL_802_11_BANDS) 66 (((((adapter->fw_cap_info & 0x3000) << 1) | \
67 (adapter->fw_cap_info & ~0xF000)) >> 8) & \
68 ALL_802_11_BANDS)
59 69
60#define HostCmd_WEP_KEY_INDEX_MASK 0x3fff 70#define HostCmd_WEP_KEY_INDEX_MASK 0x3fff
61 71
@@ -216,6 +226,47 @@ enum MWIFIEX_802_11_PRIVACY_FILTER {
216 226
217#define LLC_SNAP_LEN 8 227#define LLC_SNAP_LEN 8
218 228
229/* HW_SPEC fw_cap_info */
230
231#define ISSUPP_11ACENABLED(fw_cap_info) (fw_cap_info & (BIT(13)|BIT(14)))
232
233#define GET_VHTCAP_MAXMPDULEN(vht_cap_info) (vht_cap_info & 0x3)
234#define GET_VHTCAP_CHWDSET(vht_cap_info) ((vht_cap_info >> 2) & 0x3)
235#define GET_VHTNSSMCS(mcs_mapset, nss) ((mcs_mapset >> (2 * (nss - 1))) & 0x3)
236#define SET_VHTNSSMCS(mcs_mapset, nss, value) (mcs_mapset |= (value & 0x3) << \
237 (2 * (nss - 1)))
238#define NO_NSS_SUPPORT 0x3
239
240/* HW_SPEC: HTC-VHT supported */
241#define ISSUPP_11ACVHTHTCVHT(Dot11acDevCap) (Dot11acDevCap & BIT(22))
242/* HW_SPEC: VHT TXOP PS support */
243#define ISSUPP_11ACVHTTXOPPS(Dot11acDevCap) (Dot11acDevCap & BIT(21))
244/* HW_SPEC: MU RX beamformee support */
245#define ISSUPP_11ACMURXBEAMFORMEE(Dot11acDevCap) (Dot11acDevCap & BIT(20))
246/* HW_SPEC: MU TX beamformee support */
247#define ISSUPP_11ACMUTXBEAMFORMEE(Dot11acDevCap) (Dot11acDevCap & BIT(19))
248/* HW_SPEC: SU Beamformee support */
249#define ISSUPP_11ACSUBEAMFORMEE(Dot11acDevCap) (Dot11acDevCap & BIT(10))
250/* HW_SPEC: SU Beamformer support */
251#define ISSUPP_11ACSUBEAMFORMER(Dot11acDevCap) (Dot11acDevCap & BIT(9))
252/* HW_SPEC: Rx STBC support */
253#define ISSUPP_11ACRXSTBC(Dot11acDevCap) (Dot11acDevCap & BIT(8))
254/* HW_SPEC: Tx STBC support */
255#define ISSUPP_11ACTXSTBC(Dot11acDevCap) (Dot11acDevCap & BIT(7))
256/* HW_SPEC: Short GI support for 160MHz BW */
257#define ISSUPP_11ACSGI160(Dot11acDevCap) (Dot11acDevCap & BIT(6))
258/* HW_SPEC: Short GI support for 80MHz BW */
259#define ISSUPP_11ACSGI80(Dot11acDevCap) (Dot11acDevCap & BIT(5))
260/* HW_SPEC: LDPC coding support */
261#define ISSUPP_11ACLDPC(Dot11acDevCap) (Dot11acDevCap & BIT(4))
262/* HW_SPEC: Channel BW 20/40/80/160/80+80 MHz support */
263#define ISSUPP_11ACBW8080(Dot11acDevCap) (Dot11acDevCap & BIT(3))
264/* HW_SPEC: Channel BW 20/40/80/160 MHz support */
265#define ISSUPP_11ACBW160(Dot11acDevCap) (Dot11acDevCap & BIT(2))
266
267#define GET_DEVTXMCSMAP(dev_mcs_map) (dev_mcs_map >> 16)
268#define GET_DEVRXMCSMAP(dev_mcs_map) (dev_mcs_map & 0xFFFF)
269
219#define MOD_CLASS_HR_DSSS 0x03 270#define MOD_CLASS_HR_DSSS 0x03
220#define MOD_CLASS_OFDM 0x07 271#define MOD_CLASS_OFDM 0x07
221#define MOD_CLASS_HT 0x08 272#define MOD_CLASS_HT 0x08
@@ -330,6 +381,9 @@ enum P2P_MODES {
330#define HOST_SLEEP_CFG_GPIO_DEF 0xff 381#define HOST_SLEEP_CFG_GPIO_DEF 0xff
331#define HOST_SLEEP_CFG_GAP_DEF 0 382#define HOST_SLEEP_CFG_GAP_DEF 0
332 383
384#define MWIFIEX_TIMEOUT_FOR_AP_RESP 0xfffc
385#define MWIFIEX_STATUS_CODE_AUTH_TIMEOUT 2
386
333#define CMD_F_HOSTCMD (1 << 0) 387#define CMD_F_HOSTCMD (1 << 0)
334#define CMD_F_CANCELED (1 << 1) 388#define CMD_F_CANCELED (1 << 1)
335 389
@@ -452,9 +506,22 @@ struct rxpd {
452 u8 rx_rate; 506 u8 rx_rate;
453 s8 snr; 507 s8 snr;
454 s8 nf; 508 s8 nf;
455 /* Ht Info [Bit 0] RxRate format: LG=0, HT=1 509
510 /* For: Non-802.11 AC cards
511 *
512 * Ht Info [Bit 0] RxRate format: LG=0, HT=1
456 * [Bit 1] HT Bandwidth: BW20 = 0, BW40 = 1 513 * [Bit 1] HT Bandwidth: BW20 = 0, BW40 = 1
457 * [Bit 2] HT Guard Interval: LGI = 0, SGI = 1 */ 514 * [Bit 2] HT Guard Interval: LGI = 0, SGI = 1
515 *
516 * For: 802.11 AC cards
517 * [Bit 1] [Bit 0] RxRate format: legacy rate = 00 HT = 01 VHT = 10
518 * [Bit 3] [Bit 2] HT/VHT Bandwidth BW20 = 00 BW40 = 01
519 * BW80 = 10 BW160 = 11
520 * [Bit 4] HT/VHT Guard interval LGI = 0 SGI = 1
521 * [Bit 5] STBC support Enabled = 1
522 * [Bit 6] LDPC support Enabled = 1
523 * [Bit 7] Reserved
524 */
458 u8 ht_info; 525 u8 ht_info;
459 u8 reserved; 526 u8 reserved;
460} __packed; 527} __packed;
@@ -677,7 +744,11 @@ struct host_cmd_ds_get_hw_spec {
677 __le32 dot_11n_dev_cap; 744 __le32 dot_11n_dev_cap;
678 u8 dev_mcs_support; 745 u8 dev_mcs_support;
679 __le16 mp_end_port; /* SDIO only, reserved for other interfacces */ 746 __le16 mp_end_port; /* SDIO only, reserved for other interfacces */
680 __le16 reserved_4; 747 __le16 mgmt_buf_count; /* mgmt IE buffer count */
748 __le32 reserved_5;
749 __le32 reserved_6;
750 __le32 dot_11ac_dev_cap;
751 __le32 dot_11ac_mcs_support;
681} __packed; 752} __packed;
682 753
683struct host_cmd_ds_802_11_rssi_info { 754struct host_cmd_ds_802_11_rssi_info {
@@ -783,6 +854,12 @@ union ieee_types_phy_param_set {
783 struct ieee_types_ds_param_set ds_param_set; 854 struct ieee_types_ds_param_set ds_param_set;
784} __packed; 855} __packed;
785 856
857struct ieee_types_oper_mode_ntf {
858 u8 element_id;
859 u8 len;
860 u8 oper_mode;
861} __packed;
862
786struct host_cmd_ds_802_11_ad_hoc_start { 863struct host_cmd_ds_802_11_ad_hoc_start {
787 u8 ssid[IEEE80211_MAX_SSID_LEN]; 864 u8 ssid[IEEE80211_MAX_SSID_LEN];
788 u8 bss_mode; 865 u8 bss_mode;
@@ -843,11 +920,27 @@ struct host_cmd_ds_802_11_get_log {
843 __le32 wep_icv_err_cnt[4]; 920 __le32 wep_icv_err_cnt[4];
844}; 921};
845 922
923/* Enumeration for rate format */
924enum _mwifiex_rate_format {
925 MWIFIEX_RATE_FORMAT_LG = 0,
926 MWIFIEX_RATE_FORMAT_HT,
927 MWIFIEX_RATE_FORMAT_VHT,
928 MWIFIEX_RATE_FORMAT_AUTO = 0xFF,
929};
930
846struct host_cmd_ds_tx_rate_query { 931struct host_cmd_ds_tx_rate_query {
847 u8 tx_rate; 932 u8 tx_rate;
848 /* Ht Info [Bit 0] RxRate format: LG=0, HT=1 933 /* Tx Rate Info: For 802.11 AC cards
934 *
935 * [Bit 0-1] tx rate formate: LG = 0, HT = 1, VHT = 2
936 * [Bit 2-3] HT/VHT Bandwidth: BW20 = 0, BW40 = 1, BW80 = 2, BW160 = 3
937 * [Bit 4] HT/VHT Guard Interval: LGI = 0, SGI = 1
938 *
939 * For non-802.11 AC cards
940 * Ht Info [Bit 0] RxRate format: LG=0, HT=1
849 * [Bit 1] HT Bandwidth: BW20 = 0, BW40 = 1 941 * [Bit 1] HT Bandwidth: BW20 = 0, BW40 = 1
850 * [Bit 2] HT Guard Interval: LGI = 0, SGI = 1 */ 942 * [Bit 2] HT Guard Interval: LGI = 0, SGI = 1
943 */
851 u8 ht_info; 944 u8 ht_info;
852} __packed; 945} __packed;
853 946
@@ -1093,6 +1186,7 @@ struct host_cmd_ds_11n_cfg {
1093 __le16 action; 1186 __le16 action;
1094 __le16 ht_tx_cap; 1187 __le16 ht_tx_cap;
1095 __le16 ht_tx_info; 1188 __le16 ht_tx_info;
1189 __le16 misc_config; /* Needed for 802.11AC cards only */
1096} __packed; 1190} __packed;
1097 1191
1098struct host_cmd_ds_txbuf_cfg { 1192struct host_cmd_ds_txbuf_cfg {
@@ -1131,12 +1225,6 @@ struct ieee_types_vendor_header {
1131 u8 version; 1225 u8 version;
1132} __packed; 1226} __packed;
1133 1227
1134struct ieee_types_wmm_ac_parameters {
1135 u8 aci_aifsn_bitmap;
1136 u8 ecw_bitmap;
1137 __le16 tx_op_limit;
1138} __packed;
1139
1140struct ieee_types_wmm_parameter { 1228struct ieee_types_wmm_parameter {
1141 /* 1229 /*
1142 * WMM Parameter IE - Vendor Specific Header: 1230 * WMM Parameter IE - Vendor Specific Header:
@@ -1186,6 +1274,31 @@ struct mwifiex_ie_types_htcap {
1186 struct ieee80211_ht_cap ht_cap; 1274 struct ieee80211_ht_cap ht_cap;
1187} __packed; 1275} __packed;
1188 1276
1277struct mwifiex_ie_types_vhtcap {
1278 struct mwifiex_ie_types_header header;
1279 struct ieee80211_vht_cap vht_cap;
1280} __packed;
1281
1282struct mwifiex_ie_types_oper_mode_ntf {
1283 struct mwifiex_ie_types_header header;
1284 u8 oper_mode;
1285} __packed;
1286
1287/* VHT Operations IE */
1288struct mwifiex_ie_types_vht_oper {
1289 struct mwifiex_ie_types_header header;
1290 u8 chan_width;
1291 u8 chan_center_freq_1;
1292 u8 chan_center_freq_2;
1293 /* Basic MCS set map, each 2 bits stands for a NSS */
1294 u16 basic_mcs_map;
1295} __packed;
1296
1297struct mwifiex_ie_types_wmmcap {
1298 struct mwifiex_ie_types_header header;
1299 struct mwifiex_types_wmm_info wmm_info;
1300} __packed;
1301
1189struct mwifiex_ie_types_htinfo { 1302struct mwifiex_ie_types_htinfo {
1190 struct mwifiex_ie_types_header header; 1303 struct mwifiex_ie_types_header header;
1191 struct ieee80211_ht_operation ht_oper; 1304 struct ieee80211_ht_operation ht_oper;
diff --git a/drivers/net/wireless/mwifiex/init.c b/drivers/net/wireless/mwifiex/init.c
index 39f03ce5a5b1..e38aa9b3663d 100644
--- a/drivers/net/wireless/mwifiex/init.c
+++ b/drivers/net/wireless/mwifiex/init.c
@@ -39,11 +39,8 @@ static int mwifiex_add_bss_prio_tbl(struct mwifiex_private *priv)
39 unsigned long flags; 39 unsigned long flags;
40 40
41 bss_prio = kzalloc(sizeof(struct mwifiex_bss_prio_node), GFP_KERNEL); 41 bss_prio = kzalloc(sizeof(struct mwifiex_bss_prio_node), GFP_KERNEL);
42 if (!bss_prio) { 42 if (!bss_prio)
43 dev_err(adapter->dev, "%s: failed to alloc bss_prio\n",
44 __func__);
45 return -ENOMEM; 43 return -ENOMEM;
46 }
47 44
48 bss_prio->priv = priv; 45 bss_prio->priv = priv;
49 INIT_LIST_HEAD(&bss_prio->list); 46 INIT_LIST_HEAD(&bss_prio->list);
@@ -317,7 +314,6 @@ static void mwifiex_init_adapter(struct mwifiex_adapter *adapter)
317 314
318 adapter->pm_wakeup_fw_try = false; 315 adapter->pm_wakeup_fw_try = false;
319 316
320 adapter->max_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;
321 adapter->tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K; 317 adapter->tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;
322 adapter->curr_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K; 318 adapter->curr_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;
323 319
@@ -591,6 +587,12 @@ int mwifiex_init_fw(struct mwifiex_adapter *adapter)
591 return -1; 587 return -1;
592 } 588 }
593 } 589 }
590
591 if (adapter->if_ops.init_fw_port) {
592 if (adapter->if_ops.init_fw_port(adapter))
593 return -1;
594 }
595
594 for (i = 0; i < adapter->priv_num; i++) { 596 for (i = 0; i < adapter->priv_num; i++) {
595 if (adapter->priv[i]) { 597 if (adapter->priv[i]) {
596 ret = mwifiex_sta_init_cmd(adapter->priv[i], first_sta); 598 ret = mwifiex_sta_init_cmd(adapter->priv[i], first_sta);
diff --git a/drivers/net/wireless/mwifiex/ioctl.h b/drivers/net/wireless/mwifiex/ioctl.h
index 4e31c6013ebe..d85e6eb1f58a 100644
--- a/drivers/net/wireless/mwifiex/ioctl.h
+++ b/drivers/net/wireless/mwifiex/ioctl.h
@@ -20,7 +20,6 @@
20#ifndef _MWIFIEX_IOCTL_H_ 20#ifndef _MWIFIEX_IOCTL_H_
21#define _MWIFIEX_IOCTL_H_ 21#define _MWIFIEX_IOCTL_H_
22 22
23#include <net/mac80211.h>
24#include <net/lib80211.h> 23#include <net/lib80211.h>
25 24
26enum { 25enum {
@@ -61,6 +60,8 @@ enum {
61 BAND_A = 4, 60 BAND_A = 4,
62 BAND_GN = 8, 61 BAND_GN = 8,
63 BAND_AN = 16, 62 BAND_AN = 16,
63 BAND_GAC = 32,
64 BAND_AAC = 64,
64}; 65};
65 66
66#define MWIFIEX_WPA_PASSHPHRASE_LEN 64 67#define MWIFIEX_WPA_PASSHPHRASE_LEN 64
@@ -104,9 +105,12 @@ struct mwifiex_uap_bss_param {
104 struct wpa_param wpa_cfg; 105 struct wpa_param wpa_cfg;
105 struct wep_key wep_cfg[NUM_WEP_KEYS]; 106 struct wep_key wep_cfg[NUM_WEP_KEYS];
106 struct ieee80211_ht_cap ht_cap; 107 struct ieee80211_ht_cap ht_cap;
108 struct ieee80211_vht_cap vht_cap;
107 u8 rates[MWIFIEX_SUPPORTED_RATES]; 109 u8 rates[MWIFIEX_SUPPORTED_RATES];
108 u32 sta_ao_timer; 110 u32 sta_ao_timer;
109 u32 ps_sta_ao_timer; 111 u32 ps_sta_ao_timer;
112 u8 qos_info;
113 struct mwifiex_types_wmm_info wmm_info;
110}; 114};
111 115
112enum { 116enum {
@@ -177,7 +181,6 @@ struct mwifiex_ds_tx_ba_stream_tbl {
177struct mwifiex_debug_info { 181struct mwifiex_debug_info {
178 u32 int_counter; 182 u32 int_counter;
179 u32 packets_out[MAX_NUM_TID]; 183 u32 packets_out[MAX_NUM_TID];
180 u32 max_tx_buf_size;
181 u32 tx_buf_size; 184 u32 tx_buf_size;
182 u32 curr_tx_buf_size; 185 u32 curr_tx_buf_size;
183 u32 tx_tbl_num; 186 u32 tx_tbl_num;
@@ -272,6 +275,7 @@ struct mwifiex_ds_pm_cfg {
272struct mwifiex_ds_11n_tx_cfg { 275struct mwifiex_ds_11n_tx_cfg {
273 u16 tx_htcap; 276 u16 tx_htcap;
274 u16 tx_htinfo; 277 u16 tx_htinfo;
278 u16 misc_config; /* Needed for 802.11AC cards only */
275}; 279};
276 280
277struct mwifiex_ds_11n_amsdu_aggr_ctrl { 281struct mwifiex_ds_11n_amsdu_aggr_ctrl {
diff --git a/drivers/net/wireless/mwifiex/join.c b/drivers/net/wireless/mwifiex/join.c
index 88664ae667ba..246aa62a4817 100644
--- a/drivers/net/wireless/mwifiex/join.c
+++ b/drivers/net/wireless/mwifiex/join.c
@@ -24,6 +24,7 @@
24#include "main.h" 24#include "main.h"
25#include "wmm.h" 25#include "wmm.h"
26#include "11n.h" 26#include "11n.h"
27#include "11ac.h"
27 28
28#define CAPINFO_MASK (~(BIT(15) | BIT(14) | BIT(12) | BIT(11) | BIT(9))) 29#define CAPINFO_MASK (~(BIT(15) | BIT(14) | BIT(12) | BIT(11) | BIT(9)))
29 30
@@ -157,8 +158,8 @@ static int mwifiex_get_common_rates(struct mwifiex_private *priv, u8 *rate1,
157 158
158 memset(rate1, 0, rate1_size); 159 memset(rate1, 0, rate1_size);
159 160
160 for (i = 0; rate2[i] && i < rate2_size; i++) { 161 for (i = 0; i < rate2_size && rate2[i]; i++) {
161 for (j = 0; tmp[j] && j < rate1_size; j++) { 162 for (j = 0; j < rate1_size && tmp[j]; j++) {
162 /* Check common rate, excluding the bit for 163 /* Check common rate, excluding the bit for
163 basic rate */ 164 basic rate */
164 if ((rate2[i] & 0x7F) == (tmp[j] & 0x7F)) { 165 if ((rate2[i] & 0x7F) == (tmp[j] & 0x7F)) {
@@ -398,8 +399,6 @@ int mwifiex_cmd_802_11_associate(struct mwifiex_private *priv,
398 399
399 pos = (u8 *) assoc; 400 pos = (u8 *) assoc;
400 401
401 mwifiex_cfg_tx_buf(priv, bss_desc);
402
403 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_ASSOCIATE); 402 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_ASSOCIATE);
404 403
405 /* Save so we know which BSS Desc to use in the response handler */ 404 /* Save so we know which BSS Desc to use in the response handler */
@@ -514,6 +513,12 @@ int mwifiex_cmd_802_11_associate(struct mwifiex_private *priv,
514 priv->adapter->config_bands & BAND_AN)) 513 priv->adapter->config_bands & BAND_AN))
515 mwifiex_cmd_append_11n_tlv(priv, bss_desc, &pos); 514 mwifiex_cmd_append_11n_tlv(priv, bss_desc, &pos);
516 515
516 if (ISSUPP_11ACENABLED(priv->adapter->fw_cap_info) &&
517 !bss_desc->disable_11n && !bss_desc->disable_11ac &&
518 (priv->adapter->config_bands & BAND_GAC ||
519 priv->adapter->config_bands & BAND_AAC))
520 mwifiex_cmd_append_11ac_tlv(priv, bss_desc, &pos);
521
517 /* Append vendor specific IE TLV */ 522 /* Append vendor specific IE TLV */
518 mwifiex_cmd_append_vsie_tlv(priv, MWIFIEX_VSIE_MASK_ASSOC, &pos); 523 mwifiex_cmd_append_vsie_tlv(priv, MWIFIEX_VSIE_MASK_ASSOC, &pos);
519 524
@@ -615,23 +620,33 @@ int mwifiex_ret_802_11_associate(struct mwifiex_private *priv,
615 struct ieee_types_assoc_rsp *assoc_rsp; 620 struct ieee_types_assoc_rsp *assoc_rsp;
616 struct mwifiex_bssdescriptor *bss_desc; 621 struct mwifiex_bssdescriptor *bss_desc;
617 u8 enable_data = true; 622 u8 enable_data = true;
623 u16 cap_info, status_code;
618 624
619 assoc_rsp = (struct ieee_types_assoc_rsp *) &resp->params; 625 assoc_rsp = (struct ieee_types_assoc_rsp *) &resp->params;
620 626
627 cap_info = le16_to_cpu(assoc_rsp->cap_info_bitmap);
628 status_code = le16_to_cpu(assoc_rsp->status_code);
629
621 priv->assoc_rsp_size = min(le16_to_cpu(resp->size) - S_DS_GEN, 630 priv->assoc_rsp_size = min(le16_to_cpu(resp->size) - S_DS_GEN,
622 sizeof(priv->assoc_rsp_buf)); 631 sizeof(priv->assoc_rsp_buf));
623 632
624 memcpy(priv->assoc_rsp_buf, &resp->params, priv->assoc_rsp_size); 633 memcpy(priv->assoc_rsp_buf, &resp->params, priv->assoc_rsp_size);
625 634
626 if (le16_to_cpu(assoc_rsp->status_code)) { 635 if (status_code) {
627 priv->adapter->dbg.num_cmd_assoc_failure++; 636 priv->adapter->dbg.num_cmd_assoc_failure++;
628 dev_err(priv->adapter->dev, 637 dev_err(priv->adapter->dev,
629 "ASSOC_RESP: failed, status code=%d err=%#x a_id=%#x\n", 638 "ASSOC_RESP: failed, status code=%d err=%#x a_id=%#x\n",
630 le16_to_cpu(assoc_rsp->status_code), 639 status_code, cap_info, le16_to_cpu(assoc_rsp->a_id));
631 le16_to_cpu(assoc_rsp->cap_info_bitmap), 640
632 le16_to_cpu(assoc_rsp->a_id)); 641 if (cap_info == MWIFIEX_TIMEOUT_FOR_AP_RESP) {
642 if (status_code == MWIFIEX_STATUS_CODE_AUTH_TIMEOUT)
643 ret = WLAN_STATUS_AUTH_TIMEOUT;
644 else
645 ret = WLAN_STATUS_UNSPECIFIED_FAILURE;
646 } else {
647 ret = status_code;
648 }
633 649
634 ret = le16_to_cpu(assoc_rsp->status_code);
635 goto done; 650 goto done;
636 } 651 }
637 652
@@ -969,6 +984,16 @@ mwifiex_cmd_802_11_ad_hoc_start(struct mwifiex_private *priv,
969 priv->adapter->config_bands); 984 priv->adapter->config_bands);
970 mwifiex_fill_cap_info(priv, radio_type, ht_cap); 985 mwifiex_fill_cap_info(priv, radio_type, ht_cap);
971 986
987 if (adapter->sec_chan_offset ==
988 IEEE80211_HT_PARAM_CHA_SEC_NONE) {
989 u16 tmp_ht_cap;
990
991 tmp_ht_cap = le16_to_cpu(ht_cap->ht_cap.cap_info);
992 tmp_ht_cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
993 tmp_ht_cap &= ~IEEE80211_HT_CAP_SGI_40;
994 ht_cap->ht_cap.cap_info = cpu_to_le16(tmp_ht_cap);
995 }
996
972 pos += sizeof(struct mwifiex_ie_types_htcap); 997 pos += sizeof(struct mwifiex_ie_types_htcap);
973 cmd_append_size += sizeof(struct mwifiex_ie_types_htcap); 998 cmd_append_size += sizeof(struct mwifiex_ie_types_htcap);
974 999
@@ -1403,6 +1428,7 @@ mwifiex_band_to_radio_type(u8 band)
1403 case BAND_A: 1428 case BAND_A:
1404 case BAND_AN: 1429 case BAND_AN:
1405 case BAND_A | BAND_AN: 1430 case BAND_A | BAND_AN:
1431 case BAND_A | BAND_AN | BAND_AAC:
1406 return HostCmd_SCAN_RADIO_TYPE_A; 1432 return HostCmd_SCAN_RADIO_TYPE_A;
1407 case BAND_B: 1433 case BAND_B:
1408 case BAND_G: 1434 case BAND_G:
diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
index 1b3cfc821940..553adfb0aa81 100644
--- a/drivers/net/wireless/mwifiex/main.h
+++ b/drivers/net/wireless/mwifiex/main.h
@@ -295,6 +295,13 @@ struct mwifiex_bssdescriptor {
295 u16 bss_co_2040_offset; 295 u16 bss_co_2040_offset;
296 u8 *bcn_ext_cap; 296 u8 *bcn_ext_cap;
297 u16 ext_cap_offset; 297 u16 ext_cap_offset;
298 struct ieee80211_vht_cap *bcn_vht_cap;
299 u16 vht_cap_offset;
300 struct ieee80211_vht_operation *bcn_vht_oper;
301 u16 vht_info_offset;
302 struct ieee_types_oper_mode_ntf *oper_mode;
303 u16 oper_mode_offset;
304 u8 disable_11ac;
298 struct ieee_types_vendor_specific *bcn_wpa_ie; 305 struct ieee_types_vendor_specific *bcn_wpa_ie;
299 u16 wpa_offset; 306 u16 wpa_offset;
300 struct ieee_types_generic *bcn_rsn_ie; 307 struct ieee_types_generic *bcn_rsn_ie;
@@ -499,6 +506,7 @@ struct mwifiex_private {
499 u16 rsn_idx; 506 u16 rsn_idx;
500 struct timer_list scan_delay_timer; 507 struct timer_list scan_delay_timer;
501 u8 ap_11n_enabled; 508 u8 ap_11n_enabled;
509 u8 ap_11ac_enabled;
502 u32 mgmt_frame_mask; 510 u32 mgmt_frame_mask;
503 struct mwifiex_roc_cfg roc_cfg; 511 struct mwifiex_roc_cfg roc_cfg;
504}; 512};
@@ -599,8 +607,10 @@ struct mwifiex_if_ops {
599 int (*cmdrsp_complete) (struct mwifiex_adapter *, struct sk_buff *); 607 int (*cmdrsp_complete) (struct mwifiex_adapter *, struct sk_buff *);
600 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *); 608 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
601 int (*data_complete) (struct mwifiex_adapter *, struct sk_buff *); 609 int (*data_complete) (struct mwifiex_adapter *, struct sk_buff *);
610 int (*init_fw_port) (struct mwifiex_adapter *);
602 int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *); 611 int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
603 void (*card_reset) (struct mwifiex_adapter *); 612 void (*card_reset) (struct mwifiex_adapter *);
613 int (*clean_pcie_ring) (struct mwifiex_adapter *adapter);
604}; 614};
605 615
606struct mwifiex_adapter { 616struct mwifiex_adapter {
@@ -629,7 +639,6 @@ struct mwifiex_adapter {
629 /* spin lock for main process */ 639 /* spin lock for main process */
630 spinlock_t main_proc_lock; 640 spinlock_t main_proc_lock;
631 u32 mwifiex_processing; 641 u32 mwifiex_processing;
632 u16 max_tx_buf_size;
633 u16 tx_buf_size; 642 u16 tx_buf_size;
634 u16 curr_tx_buf_size; 643 u16 curr_tx_buf_size;
635 u32 ioport; 644 u32 ioport;
@@ -721,6 +730,15 @@ struct mwifiex_adapter {
721 u16 max_mgmt_ie_index; 730 u16 max_mgmt_ie_index;
722 u8 scan_delay_cnt; 731 u8 scan_delay_cnt;
723 u8 empty_tx_q_cnt; 732 u8 empty_tx_q_cnt;
733
734 /* 11AC */
735 u32 is_hw_11ac_capable;
736 u32 hw_dot_11ac_dev_cap;
737 u32 hw_dot_11ac_mcs_support;
738 u32 usr_dot_11ac_dev_cap_bg;
739 u32 usr_dot_11ac_dev_cap_a;
740 u32 usr_dot_11ac_mcs_support;
741
724 atomic_t is_tx_received; 742 atomic_t is_tx_received;
725 atomic_t pending_bridged_pkts; 743 atomic_t pending_bridged_pkts;
726}; 744};
@@ -863,8 +881,10 @@ int mwifiex_ret_802_11_ad_hoc(struct mwifiex_private *priv,
863int mwifiex_cmd_802_11_bg_scan_query(struct host_cmd_ds_command *cmd); 881int mwifiex_cmd_802_11_bg_scan_query(struct host_cmd_ds_command *cmd);
864struct mwifiex_chan_freq_power *mwifiex_get_cfp(struct mwifiex_private *priv, 882struct mwifiex_chan_freq_power *mwifiex_get_cfp(struct mwifiex_private *priv,
865 u8 band, u16 channel, u32 freq); 883 u8 band, u16 channel, u32 freq);
866u32 mwifiex_index_to_data_rate(struct mwifiex_private *priv, u8 index, 884u32 mwifiex_index_to_data_rate(struct mwifiex_private *priv,
867 u8 ht_info); 885 u8 index, u8 ht_info);
886u32 mwifiex_index_to_acs_data_rate(struct mwifiex_private *priv,
887 u8 index, u8 ht_info);
868u32 mwifiex_find_freq_from_band_chan(u8, u8); 888u32 mwifiex_find_freq_from_band_chan(u8, u8);
869int mwifiex_cmd_append_vsie_tlv(struct mwifiex_private *priv, u16 vsie_mask, 889int mwifiex_cmd_append_vsie_tlv(struct mwifiex_private *priv, u16 vsie_mask,
870 u8 **buffer); 890 u8 **buffer);
@@ -890,6 +910,10 @@ void mwifiex_set_ht_params(struct mwifiex_private *priv,
890 struct cfg80211_ap_settings *params); 910 struct cfg80211_ap_settings *params);
891void mwifiex_set_uap_rates(struct mwifiex_uap_bss_param *bss_cfg, 911void mwifiex_set_uap_rates(struct mwifiex_uap_bss_param *bss_cfg,
892 struct cfg80211_ap_settings *params); 912 struct cfg80211_ap_settings *params);
913void
914mwifiex_set_wmm_params(struct mwifiex_private *priv,
915 struct mwifiex_uap_bss_param *bss_cfg,
916 struct cfg80211_ap_settings *params);
893 917
894/* 918/*
895 * This function checks if the queuing is RA based or not. 919 * This function checks if the queuing is RA based or not.
diff --git a/drivers/net/wireless/mwifiex/pcie.c b/drivers/net/wireless/mwifiex/pcie.c
index b879e1338a54..4b54bcf382f3 100644
--- a/drivers/net/wireless/mwifiex/pcie.c
+++ b/drivers/net/wireless/mwifiex/pcie.c
@@ -39,17 +39,20 @@ static struct semaphore add_remove_card_sem;
39static int mwifiex_pcie_enable_host_int(struct mwifiex_adapter *adapter); 39static int mwifiex_pcie_enable_host_int(struct mwifiex_adapter *adapter);
40static int mwifiex_pcie_resume(struct pci_dev *pdev); 40static int mwifiex_pcie_resume(struct pci_dev *pdev);
41 41
42/* 42static int
43 * This function is called after skb allocation to update 43mwifiex_map_pci_memory(struct mwifiex_adapter *adapter, struct sk_buff *skb,
44 * "skb->cb" with physical address of data pointer. 44 int size, int flags)
45 */
46static phys_addr_t *mwifiex_update_sk_buff_pa(struct sk_buff *skb)
47{ 45{
48 phys_addr_t *buf_pa = MWIFIEX_SKB_PACB(skb); 46 struct pcie_service_card *card = adapter->card;
49 47 dma_addr_t buf_pa;
50 *buf_pa = (phys_addr_t)virt_to_phys(skb->data);
51 48
52 return buf_pa; 49 buf_pa = pci_map_single(card->dev, skb->data, size, flags);
50 if (pci_dma_mapping_error(card->dev, buf_pa)) {
51 dev_err(adapter->dev, "failed to map pci memory!\n");
52 return -1;
53 }
54 memcpy(skb->cb, &buf_pa, sizeof(dma_addr_t));
55 return 0;
53} 56}
54 57
55/* 58/*
@@ -59,9 +62,13 @@ static bool mwifiex_pcie_ok_to_access_hw(struct mwifiex_adapter *adapter)
59{ 62{
60 u32 *cookie_addr; 63 u32 *cookie_addr;
61 struct pcie_service_card *card = adapter->card; 64 struct pcie_service_card *card = adapter->card;
65 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
66
67 if (!reg->sleep_cookie)
68 return true;
62 69
63 if (card->sleep_cookie) { 70 if (card->sleep_cookie_vbase) {
64 cookie_addr = (u32 *)card->sleep_cookie->data; 71 cookie_addr = (u32 *)card->sleep_cookie_vbase;
65 dev_dbg(adapter->dev, "info: ACCESS_HW: sleep cookie=0x%x\n", 72 dev_dbg(adapter->dev, "info: ACCESS_HW: sleep cookie=0x%x\n",
66 *cookie_addr); 73 *cookie_addr);
67 if (*cookie_addr == FW_AWAKE_COOKIE) 74 if (*cookie_addr == FW_AWAKE_COOKIE)
@@ -91,6 +98,13 @@ static int mwifiex_pcie_probe(struct pci_dev *pdev,
91 98
92 card->dev = pdev; 99 card->dev = pdev;
93 100
101 if (ent->driver_data) {
102 struct mwifiex_pcie_device *data = (void *)ent->driver_data;
103 card->pcie.firmware = data->firmware;
104 card->pcie.reg = data->reg;
105 card->pcie.blksz_fw_dl = data->blksz_fw_dl;
106 }
107
94 if (mwifiex_add_card(card, &add_remove_card_sem, &pcie_ops, 108 if (mwifiex_add_card(card, &add_remove_card_sem, &pcie_ops,
95 MWIFIEX_PCIE)) { 109 MWIFIEX_PCIE)) {
96 pr_err("%s failed\n", __func__); 110 pr_err("%s failed\n", __func__);
@@ -227,13 +241,16 @@ static int mwifiex_pcie_resume(struct pci_dev *pdev)
227 return 0; 241 return 0;
228} 242}
229 243
230#define PCIE_VENDOR_ID_MARVELL (0x11ab)
231#define PCIE_DEVICE_ID_MARVELL_88W8766P (0x2b30)
232
233static DEFINE_PCI_DEVICE_TABLE(mwifiex_ids) = { 244static DEFINE_PCI_DEVICE_TABLE(mwifiex_ids) = {
234 { 245 {
235 PCIE_VENDOR_ID_MARVELL, PCIE_DEVICE_ID_MARVELL_88W8766P, 246 PCIE_VENDOR_ID_MARVELL, PCIE_DEVICE_ID_MARVELL_88W8766P,
236 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 247 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
248 .driver_data = (unsigned long) &mwifiex_pcie8766,
249 },
250 {
251 PCIE_VENDOR_ID_MARVELL, PCIE_DEVICE_ID_MARVELL_88W8897,
252 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
253 .driver_data = (unsigned long) &mwifiex_pcie8897,
237 }, 254 },
238 {}, 255 {},
239}; 256};
@@ -286,8 +303,10 @@ static int mwifiex_read_reg(struct mwifiex_adapter *adapter, int reg, u32 *data)
286static int mwifiex_pm_wakeup_card(struct mwifiex_adapter *adapter) 303static int mwifiex_pm_wakeup_card(struct mwifiex_adapter *adapter)
287{ 304{
288 int i = 0; 305 int i = 0;
306 struct pcie_service_card *card = adapter->card;
307 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
289 308
290 while (mwifiex_pcie_ok_to_access_hw(adapter)) { 309 while (reg->sleep_cookie && mwifiex_pcie_ok_to_access_hw(adapter)) {
291 i++; 310 i++;
292 usleep_range(10, 20); 311 usleep_range(10, 20);
293 /* 50ms max wait */ 312 /* 50ms max wait */
@@ -361,14 +380,246 @@ static int mwifiex_pcie_enable_host_int(struct mwifiex_adapter *adapter)
361} 380}
362 381
363/* 382/*
364 * This function creates buffer descriptor ring for TX 383 * This function initializes TX buffer ring descriptors
365 */ 384 */
366static int mwifiex_pcie_create_txbd_ring(struct mwifiex_adapter *adapter) 385static int mwifiex_init_txq_ring(struct mwifiex_adapter *adapter)
386{
387 struct pcie_service_card *card = adapter->card;
388 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
389 struct mwifiex_pcie_buf_desc *desc;
390 struct mwifiex_pfu_buf_desc *desc2;
391 int i;
392
393 for (i = 0; i < MWIFIEX_MAX_TXRX_BD; i++) {
394 card->tx_buf_list[i] = NULL;
395 if (reg->pfu_enabled) {
396 card->txbd_ring[i] = (void *)card->txbd_ring_vbase +
397 (sizeof(*desc2) * i);
398 desc2 = card->txbd_ring[i];
399 memset(desc2, 0, sizeof(*desc2));
400 } else {
401 card->txbd_ring[i] = (void *)card->txbd_ring_vbase +
402 (sizeof(*desc) * i);
403 desc = card->txbd_ring[i];
404 memset(desc, 0, sizeof(*desc));
405 }
406 }
407
408 return 0;
409}
410
411/* This function initializes RX buffer ring descriptors. Each SKB is allocated
412 * here and after mapping PCI memory, its physical address is assigned to
413 * PCIE Rx buffer descriptor's physical address.
414 */
415static int mwifiex_init_rxq_ring(struct mwifiex_adapter *adapter)
416{
417 struct pcie_service_card *card = adapter->card;
418 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
419 struct sk_buff *skb;
420 struct mwifiex_pcie_buf_desc *desc;
421 struct mwifiex_pfu_buf_desc *desc2;
422 dma_addr_t buf_pa;
423 int i;
424
425 for (i = 0; i < MWIFIEX_MAX_TXRX_BD; i++) {
426 /* Allocate skb here so that firmware can DMA data from it */
427 skb = dev_alloc_skb(MWIFIEX_RX_DATA_BUF_SIZE);
428 if (!skb) {
429 dev_err(adapter->dev,
430 "Unable to allocate skb for RX ring.\n");
431 kfree(card->rxbd_ring_vbase);
432 return -ENOMEM;
433 }
434
435 if (mwifiex_map_pci_memory(adapter, skb,
436 MWIFIEX_RX_DATA_BUF_SIZE,
437 PCI_DMA_FROMDEVICE))
438 return -1;
439
440 MWIFIEX_SKB_PACB(skb, &buf_pa);
441
442 dev_dbg(adapter->dev,
443 "info: RX ring: skb=%p len=%d data=%p buf_pa=%#x:%x\n",
444 skb, skb->len, skb->data, (u32)buf_pa,
445 (u32)((u64)buf_pa >> 32));
446
447 card->rx_buf_list[i] = skb;
448 if (reg->pfu_enabled) {
449 card->rxbd_ring[i] = (void *)card->rxbd_ring_vbase +
450 (sizeof(*desc2) * i);
451 desc2 = card->rxbd_ring[i];
452 desc2->paddr = buf_pa;
453 desc2->len = (u16)skb->len;
454 desc2->frag_len = (u16)skb->len;
455 desc2->flags = reg->ring_flag_eop | reg->ring_flag_sop;
456 desc2->offset = 0;
457 } else {
458 card->rxbd_ring[i] = (void *)(card->rxbd_ring_vbase +
459 (sizeof(*desc) * i));
460 desc = card->rxbd_ring[i];
461 desc->paddr = buf_pa;
462 desc->len = (u16)skb->len;
463 desc->flags = 0;
464 }
465 }
466
467 return 0;
468}
469
470/* This function initializes event buffer ring descriptors. Each SKB is
471 * allocated here and after mapping PCI memory, its physical address is assigned
472 * to PCIE Rx buffer descriptor's physical address
473 */
474static int mwifiex_pcie_init_evt_ring(struct mwifiex_adapter *adapter)
475{
476 struct pcie_service_card *card = adapter->card;
477 struct mwifiex_evt_buf_desc *desc;
478 struct sk_buff *skb;
479 dma_addr_t buf_pa;
480 int i;
481
482 for (i = 0; i < MWIFIEX_MAX_EVT_BD; i++) {
483 /* Allocate skb here so that firmware can DMA data from it */
484 skb = dev_alloc_skb(MAX_EVENT_SIZE);
485 if (!skb) {
486 dev_err(adapter->dev,
487 "Unable to allocate skb for EVENT buf.\n");
488 kfree(card->evtbd_ring_vbase);
489 return -ENOMEM;
490 }
491 skb_put(skb, MAX_EVENT_SIZE);
492
493 if (mwifiex_map_pci_memory(adapter, skb, MAX_EVENT_SIZE,
494 PCI_DMA_FROMDEVICE))
495 return -1;
496
497 MWIFIEX_SKB_PACB(skb, &buf_pa);
498
499 dev_dbg(adapter->dev,
500 "info: EVT ring: skb=%p len=%d data=%p buf_pa=%#x:%x\n",
501 skb, skb->len, skb->data, (u32)buf_pa,
502 (u32)((u64)buf_pa >> 32));
503
504 card->evt_buf_list[i] = skb;
505 card->evtbd_ring[i] = (void *)(card->evtbd_ring_vbase +
506 (sizeof(*desc) * i));
507 desc = card->evtbd_ring[i];
508 desc->paddr = buf_pa;
509 desc->len = (u16)skb->len;
510 desc->flags = 0;
511 }
512
513 return 0;
514}
515
516/* This function cleans up TX buffer rings. If any of the buffer list has valid
517 * SKB address, associated SKB is freed.
518 */
519static void mwifiex_cleanup_txq_ring(struct mwifiex_adapter *adapter)
520{
521 struct pcie_service_card *card = adapter->card;
522 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
523 struct sk_buff *skb;
524 struct mwifiex_pcie_buf_desc *desc;
525 struct mwifiex_pfu_buf_desc *desc2;
526 int i;
527
528 for (i = 0; i < MWIFIEX_MAX_TXRX_BD; i++) {
529 if (reg->pfu_enabled) {
530 desc2 = card->txbd_ring[i];
531 if (card->tx_buf_list[i]) {
532 skb = card->tx_buf_list[i];
533 pci_unmap_single(card->dev, desc2->paddr,
534 skb->len, PCI_DMA_TODEVICE);
535 dev_kfree_skb_any(skb);
536 }
537 memset(desc2, 0, sizeof(*desc2));
538 } else {
539 desc = card->txbd_ring[i];
540 if (card->tx_buf_list[i]) {
541 skb = card->tx_buf_list[i];
542 pci_unmap_single(card->dev, desc->paddr,
543 skb->len, PCI_DMA_TODEVICE);
544 dev_kfree_skb_any(skb);
545 }
546 memset(desc, 0, sizeof(*desc));
547 }
548 card->tx_buf_list[i] = NULL;
549 }
550
551 return;
552}
553
554/* This function cleans up RX buffer rings. If any of the buffer list has valid
555 * SKB address, associated SKB is freed.
556 */
557static void mwifiex_cleanup_rxq_ring(struct mwifiex_adapter *adapter)
367{ 558{
368 struct pcie_service_card *card = adapter->card; 559 struct pcie_service_card *card = adapter->card;
560 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
561 struct mwifiex_pcie_buf_desc *desc;
562 struct mwifiex_pfu_buf_desc *desc2;
369 struct sk_buff *skb; 563 struct sk_buff *skb;
370 int i; 564 int i;
371 phys_addr_t *buf_pa; 565
566 for (i = 0; i < MWIFIEX_MAX_TXRX_BD; i++) {
567 if (reg->pfu_enabled) {
568 desc2 = card->rxbd_ring[i];
569 if (card->rx_buf_list[i]) {
570 skb = card->rx_buf_list[i];
571 pci_unmap_single(card->dev, desc2->paddr,
572 skb->len, PCI_DMA_TODEVICE);
573 dev_kfree_skb_any(skb);
574 }
575 memset(desc2, 0, sizeof(*desc2));
576 } else {
577 desc = card->rxbd_ring[i];
578 if (card->rx_buf_list[i]) {
579 skb = card->rx_buf_list[i];
580 pci_unmap_single(card->dev, desc->paddr,
581 skb->len, PCI_DMA_TODEVICE);
582 dev_kfree_skb_any(skb);
583 }
584 memset(desc, 0, sizeof(*desc));
585 }
586 card->rx_buf_list[i] = NULL;
587 }
588
589 return;
590}
591
592/* This function cleans up event buffer rings. If any of the buffer list has
593 * valid SKB address, associated SKB is freed.
594 */
595static void mwifiex_cleanup_evt_ring(struct mwifiex_adapter *adapter)
596{
597 struct pcie_service_card *card = adapter->card;
598 struct mwifiex_evt_buf_desc *desc;
599 struct sk_buff *skb;
600 int i;
601
602 for (i = 0; i < MWIFIEX_MAX_EVT_BD; i++) {
603 desc = card->evtbd_ring[i];
604 if (card->evt_buf_list[i]) {
605 skb = card->evt_buf_list[i];
606 pci_unmap_single(card->dev, desc->paddr, MAX_EVENT_SIZE,
607 PCI_DMA_FROMDEVICE);
608 dev_kfree_skb_any(skb);
609 }
610 card->evt_buf_list[i] = NULL;
611 memset(desc, 0, sizeof(*desc));
612 }
613
614 return;
615}
616
617/* This function creates buffer descriptor ring for TX
618 */
619static int mwifiex_pcie_create_txbd_ring(struct mwifiex_adapter *adapter)
620{
621 struct pcie_service_card *card = adapter->card;
622 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
372 623
373 /* 624 /*
374 * driver maintaines the write pointer and firmware maintaines the read 625 * driver maintaines the write pointer and firmware maintaines the read
@@ -376,76 +627,56 @@ static int mwifiex_pcie_create_txbd_ring(struct mwifiex_adapter *adapter)
376 * starts at zero with rollover bit set 627 * starts at zero with rollover bit set
377 */ 628 */
378 card->txbd_wrptr = 0; 629 card->txbd_wrptr = 0;
379 card->txbd_rdptr |= MWIFIEX_BD_FLAG_ROLLOVER_IND; 630
631 if (reg->pfu_enabled)
632 card->txbd_rdptr = 0;
633 else
634 card->txbd_rdptr |= reg->tx_rollover_ind;
380 635
381 /* allocate shared memory for the BD ring and divide the same in to 636 /* allocate shared memory for the BD ring and divide the same in to
382 several descriptors */ 637 several descriptors */
383 card->txbd_ring_size = sizeof(struct mwifiex_pcie_buf_desc) * 638 if (reg->pfu_enabled)
384 MWIFIEX_MAX_TXRX_BD; 639 card->txbd_ring_size = sizeof(struct mwifiex_pfu_buf_desc) *
640 MWIFIEX_MAX_TXRX_BD;
641 else
642 card->txbd_ring_size = sizeof(struct mwifiex_pcie_buf_desc) *
643 MWIFIEX_MAX_TXRX_BD;
644
385 dev_dbg(adapter->dev, "info: txbd_ring: Allocating %d bytes\n", 645 dev_dbg(adapter->dev, "info: txbd_ring: Allocating %d bytes\n",
386 card->txbd_ring_size); 646 card->txbd_ring_size);
387 card->txbd_ring_vbase = kzalloc(card->txbd_ring_size, GFP_KERNEL); 647 card->txbd_ring_vbase = pci_alloc_consistent(card->dev,
648 card->txbd_ring_size,
649 &card->txbd_ring_pbase);
388 if (!card->txbd_ring_vbase) { 650 if (!card->txbd_ring_vbase) {
389 dev_err(adapter->dev, "Unable to alloc buffer for txbd ring\n"); 651 dev_err(adapter->dev,
652 "allocate consistent memory (%d bytes) failed!\n",
653 card->txbd_ring_size);
390 return -ENOMEM; 654 return -ENOMEM;
391 } 655 }
392 card->txbd_ring_pbase = virt_to_phys(card->txbd_ring_vbase);
393
394 dev_dbg(adapter->dev, 656 dev_dbg(adapter->dev,
395 "info: txbd_ring - base: %p, pbase: %#x:%x, len: %x\n", 657 "info: txbd_ring - base: %p, pbase: %#x:%x, len: %x\n",
396 card->txbd_ring_vbase, (u32)card->txbd_ring_pbase, 658 card->txbd_ring_vbase, (unsigned int)card->txbd_ring_pbase,
397 (u32)((u64)card->txbd_ring_pbase >> 32), card->txbd_ring_size); 659 (u32)((u64)card->txbd_ring_pbase >> 32), card->txbd_ring_size);
398 660
399 for (i = 0; i < MWIFIEX_MAX_TXRX_BD; i++) { 661 return mwifiex_init_txq_ring(adapter);
400 card->txbd_ring[i] = (struct mwifiex_pcie_buf_desc *)
401 (card->txbd_ring_vbase +
402 (sizeof(struct mwifiex_pcie_buf_desc)
403 * i));
404
405 /* Allocate buffer here so that firmware can DMA data from it */
406 skb = dev_alloc_skb(MWIFIEX_RX_DATA_BUF_SIZE);
407 if (!skb) {
408 dev_err(adapter->dev, "Unable to allocate skb for TX ring.\n");
409 kfree(card->txbd_ring_vbase);
410 return -ENOMEM;
411 }
412 buf_pa = mwifiex_update_sk_buff_pa(skb);
413
414 skb_put(skb, MWIFIEX_RX_DATA_BUF_SIZE);
415 dev_dbg(adapter->dev, "info: TX ring: add new skb base: %p, "
416 "buf_base: %p, buf_pbase: %#x:%x, buf_len: %#x\n",
417 skb, skb->data, (u32)*buf_pa,
418 (u32)(((u64)*buf_pa >> 32)), skb->len);
419
420 card->tx_buf_list[i] = skb;
421 card->txbd_ring[i]->paddr = *buf_pa;
422 card->txbd_ring[i]->len = (u16)skb->len;
423 card->txbd_ring[i]->flags = 0;
424 }
425
426 return 0;
427} 662}
428 663
429static int mwifiex_pcie_delete_txbd_ring(struct mwifiex_adapter *adapter) 664static int mwifiex_pcie_delete_txbd_ring(struct mwifiex_adapter *adapter)
430{ 665{
431 struct pcie_service_card *card = adapter->card; 666 struct pcie_service_card *card = adapter->card;
432 int i; 667 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
433 668
434 for (i = 0; i < MWIFIEX_MAX_TXRX_BD; i++) { 669 mwifiex_cleanup_txq_ring(adapter);
435 if (card->tx_buf_list[i])
436 dev_kfree_skb_any(card->tx_buf_list[i]);
437 card->tx_buf_list[i] = NULL;
438 card->txbd_ring[i]->paddr = 0;
439 card->txbd_ring[i]->len = 0;
440 card->txbd_ring[i]->flags = 0;
441 card->txbd_ring[i] = NULL;
442 }
443 670
444 kfree(card->txbd_ring_vbase); 671 if (card->txbd_ring_vbase)
672 pci_free_consistent(card->dev, card->txbd_ring_size,
673 card->txbd_ring_vbase,
674 card->txbd_ring_pbase);
445 card->txbd_ring_size = 0; 675 card->txbd_ring_size = 0;
446 card->txbd_wrptr = 0; 676 card->txbd_wrptr = 0;
447 card->txbd_rdptr = 0 | MWIFIEX_BD_FLAG_ROLLOVER_IND; 677 card->txbd_rdptr = 0 | reg->tx_rollover_ind;
448 card->txbd_ring_vbase = NULL; 678 card->txbd_ring_vbase = NULL;
679 card->txbd_ring_pbase = 0;
449 680
450 return 0; 681 return 0;
451} 682}
@@ -456,9 +687,7 @@ static int mwifiex_pcie_delete_txbd_ring(struct mwifiex_adapter *adapter)
456static int mwifiex_pcie_create_rxbd_ring(struct mwifiex_adapter *adapter) 687static int mwifiex_pcie_create_rxbd_ring(struct mwifiex_adapter *adapter)
457{ 688{
458 struct pcie_service_card *card = adapter->card; 689 struct pcie_service_card *card = adapter->card;
459 struct sk_buff *skb; 690 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
460 int i;
461 phys_addr_t *buf_pa;
462 691
463 /* 692 /*
464 * driver maintaines the read pointer and firmware maintaines the write 693 * driver maintaines the read pointer and firmware maintaines the write
@@ -466,19 +695,26 @@ static int mwifiex_pcie_create_rxbd_ring(struct mwifiex_adapter *adapter)
466 * starts at zero with rollover bit set 695 * starts at zero with rollover bit set
467 */ 696 */
468 card->rxbd_wrptr = 0; 697 card->rxbd_wrptr = 0;
469 card->rxbd_rdptr |= MWIFIEX_BD_FLAG_ROLLOVER_IND; 698 card->rxbd_rdptr = reg->rx_rollover_ind;
699
700 if (reg->pfu_enabled)
701 card->rxbd_ring_size = sizeof(struct mwifiex_pfu_buf_desc) *
702 MWIFIEX_MAX_TXRX_BD;
703 else
704 card->rxbd_ring_size = sizeof(struct mwifiex_pcie_buf_desc) *
705 MWIFIEX_MAX_TXRX_BD;
470 706
471 card->rxbd_ring_size = sizeof(struct mwifiex_pcie_buf_desc) *
472 MWIFIEX_MAX_TXRX_BD;
473 dev_dbg(adapter->dev, "info: rxbd_ring: Allocating %d bytes\n", 707 dev_dbg(adapter->dev, "info: rxbd_ring: Allocating %d bytes\n",
474 card->rxbd_ring_size); 708 card->rxbd_ring_size);
475 card->rxbd_ring_vbase = kzalloc(card->rxbd_ring_size, GFP_KERNEL); 709 card->rxbd_ring_vbase = pci_alloc_consistent(card->dev,
710 card->rxbd_ring_size,
711 &card->rxbd_ring_pbase);
476 if (!card->rxbd_ring_vbase) { 712 if (!card->rxbd_ring_vbase) {
477 dev_err(adapter->dev, "Unable to allocate buffer for " 713 dev_err(adapter->dev,
478 "rxbd_ring.\n"); 714 "allocate consistent memory (%d bytes) failed!\n",
715 card->rxbd_ring_size);
479 return -ENOMEM; 716 return -ENOMEM;
480 } 717 }
481 card->rxbd_ring_pbase = virt_to_phys(card->rxbd_ring_vbase);
482 718
483 dev_dbg(adapter->dev, 719 dev_dbg(adapter->dev,
484 "info: rxbd_ring - base: %p, pbase: %#x:%x, len: %#x\n", 720 "info: rxbd_ring - base: %p, pbase: %#x:%x, len: %#x\n",
@@ -486,35 +722,7 @@ static int mwifiex_pcie_create_rxbd_ring(struct mwifiex_adapter *adapter)
486 (u32)((u64)card->rxbd_ring_pbase >> 32), 722 (u32)((u64)card->rxbd_ring_pbase >> 32),
487 card->rxbd_ring_size); 723 card->rxbd_ring_size);
488 724
489 for (i = 0; i < MWIFIEX_MAX_TXRX_BD; i++) { 725 return mwifiex_init_rxq_ring(adapter);
490 card->rxbd_ring[i] = (struct mwifiex_pcie_buf_desc *)
491 (card->rxbd_ring_vbase +
492 (sizeof(struct mwifiex_pcie_buf_desc)
493 * i));
494
495 /* Allocate skb here so that firmware can DMA data from it */
496 skb = dev_alloc_skb(MWIFIEX_RX_DATA_BUF_SIZE);
497 if (!skb) {
498 dev_err(adapter->dev,
499 "Unable to allocate skb for RX ring.\n");
500 kfree(card->rxbd_ring_vbase);
501 return -ENOMEM;
502 }
503 buf_pa = mwifiex_update_sk_buff_pa(skb);
504 skb_put(skb, MWIFIEX_RX_DATA_BUF_SIZE);
505
506 dev_dbg(adapter->dev, "info: RX ring: add new skb base: %p, "
507 "buf_base: %p, buf_pbase: %#x:%x, buf_len: %#x\n",
508 skb, skb->data, (u32)*buf_pa, (u32)((u64)*buf_pa >> 32),
509 skb->len);
510
511 card->rx_buf_list[i] = skb;
512 card->rxbd_ring[i]->paddr = *buf_pa;
513 card->rxbd_ring[i]->len = (u16)skb->len;
514 card->rxbd_ring[i]->flags = 0;
515 }
516
517 return 0;
518} 726}
519 727
520/* 728/*
@@ -523,23 +731,19 @@ static int mwifiex_pcie_create_rxbd_ring(struct mwifiex_adapter *adapter)
523static int mwifiex_pcie_delete_rxbd_ring(struct mwifiex_adapter *adapter) 731static int mwifiex_pcie_delete_rxbd_ring(struct mwifiex_adapter *adapter)
524{ 732{
525 struct pcie_service_card *card = adapter->card; 733 struct pcie_service_card *card = adapter->card;
526 int i; 734 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
527 735
528 for (i = 0; i < MWIFIEX_MAX_TXRX_BD; i++) { 736 mwifiex_cleanup_rxq_ring(adapter);
529 if (card->rx_buf_list[i])
530 dev_kfree_skb_any(card->rx_buf_list[i]);
531 card->rx_buf_list[i] = NULL;
532 card->rxbd_ring[i]->paddr = 0;
533 card->rxbd_ring[i]->len = 0;
534 card->rxbd_ring[i]->flags = 0;
535 card->rxbd_ring[i] = NULL;
536 }
537 737
538 kfree(card->rxbd_ring_vbase); 738 if (card->rxbd_ring_vbase)
739 pci_free_consistent(card->dev, card->rxbd_ring_size,
740 card->rxbd_ring_vbase,
741 card->rxbd_ring_pbase);
539 card->rxbd_ring_size = 0; 742 card->rxbd_ring_size = 0;
540 card->rxbd_wrptr = 0; 743 card->rxbd_wrptr = 0;
541 card->rxbd_rdptr = 0 | MWIFIEX_BD_FLAG_ROLLOVER_IND; 744 card->rxbd_rdptr = 0 | reg->rx_rollover_ind;
542 card->rxbd_ring_vbase = NULL; 745 card->rxbd_ring_vbase = NULL;
746 card->rxbd_ring_pbase = 0;
543 747
544 return 0; 748 return 0;
545} 749}
@@ -550,9 +754,7 @@ static int mwifiex_pcie_delete_rxbd_ring(struct mwifiex_adapter *adapter)
550static int mwifiex_pcie_create_evtbd_ring(struct mwifiex_adapter *adapter) 754static int mwifiex_pcie_create_evtbd_ring(struct mwifiex_adapter *adapter)
551{ 755{
552 struct pcie_service_card *card = adapter->card; 756 struct pcie_service_card *card = adapter->card;
553 struct sk_buff *skb; 757 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
554 int i;
555 phys_addr_t *buf_pa;
556 758
557 /* 759 /*
558 * driver maintaines the read pointer and firmware maintaines the write 760 * driver maintaines the read pointer and firmware maintaines the write
@@ -560,19 +762,22 @@ static int mwifiex_pcie_create_evtbd_ring(struct mwifiex_adapter *adapter)
560 * starts at zero with rollover bit set 762 * starts at zero with rollover bit set
561 */ 763 */
562 card->evtbd_wrptr = 0; 764 card->evtbd_wrptr = 0;
563 card->evtbd_rdptr |= MWIFIEX_BD_FLAG_ROLLOVER_IND; 765 card->evtbd_rdptr = reg->evt_rollover_ind;
766
767 card->evtbd_ring_size = sizeof(struct mwifiex_evt_buf_desc) *
768 MWIFIEX_MAX_EVT_BD;
564 769
565 card->evtbd_ring_size = sizeof(struct mwifiex_pcie_buf_desc) *
566 MWIFIEX_MAX_EVT_BD;
567 dev_dbg(adapter->dev, "info: evtbd_ring: Allocating %d bytes\n", 770 dev_dbg(adapter->dev, "info: evtbd_ring: Allocating %d bytes\n",
568 card->evtbd_ring_size); 771 card->evtbd_ring_size);
569 card->evtbd_ring_vbase = kzalloc(card->evtbd_ring_size, GFP_KERNEL); 772 card->evtbd_ring_vbase = pci_alloc_consistent(card->dev,
773 card->evtbd_ring_size,
774 &card->evtbd_ring_pbase);
570 if (!card->evtbd_ring_vbase) { 775 if (!card->evtbd_ring_vbase) {
571 dev_err(adapter->dev, 776 dev_err(adapter->dev,
572 "Unable to allocate buffer. Terminating download\n"); 777 "allocate consistent memory (%d bytes) failed!\n",
778 card->evtbd_ring_size);
573 return -ENOMEM; 779 return -ENOMEM;
574 } 780 }
575 card->evtbd_ring_pbase = virt_to_phys(card->evtbd_ring_vbase);
576 781
577 dev_dbg(adapter->dev, 782 dev_dbg(adapter->dev,
578 "info: CMDRSP/EVT bd_ring - base: %p pbase: %#x:%x len: %#x\n", 783 "info: CMDRSP/EVT bd_ring - base: %p pbase: %#x:%x len: %#x\n",
@@ -580,35 +785,7 @@ static int mwifiex_pcie_create_evtbd_ring(struct mwifiex_adapter *adapter)
580 (u32)((u64)card->evtbd_ring_pbase >> 32), 785 (u32)((u64)card->evtbd_ring_pbase >> 32),
581 card->evtbd_ring_size); 786 card->evtbd_ring_size);
582 787
583 for (i = 0; i < MWIFIEX_MAX_EVT_BD; i++) { 788 return mwifiex_pcie_init_evt_ring(adapter);
584 card->evtbd_ring[i] = (struct mwifiex_pcie_buf_desc *)
585 (card->evtbd_ring_vbase +
586 (sizeof(struct mwifiex_pcie_buf_desc)
587 * i));
588
589 /* Allocate skb here so that firmware can DMA data from it */
590 skb = dev_alloc_skb(MAX_EVENT_SIZE);
591 if (!skb) {
592 dev_err(adapter->dev,
593 "Unable to allocate skb for EVENT buf.\n");
594 kfree(card->evtbd_ring_vbase);
595 return -ENOMEM;
596 }
597 buf_pa = mwifiex_update_sk_buff_pa(skb);
598 skb_put(skb, MAX_EVENT_SIZE);
599
600 dev_dbg(adapter->dev, "info: Evt ring: add new skb. base: %p, "
601 "buf_base: %p, buf_pbase: %#x:%x, buf_len: %#x\n",
602 skb, skb->data, (u32)*buf_pa, (u32)((u64)*buf_pa >> 32),
603 skb->len);
604
605 card->evt_buf_list[i] = skb;
606 card->evtbd_ring[i]->paddr = *buf_pa;
607 card->evtbd_ring[i]->len = (u16)skb->len;
608 card->evtbd_ring[i]->flags = 0;
609 }
610
611 return 0;
612} 789}
613 790
614/* 791/*
@@ -617,23 +794,19 @@ static int mwifiex_pcie_create_evtbd_ring(struct mwifiex_adapter *adapter)
617static int mwifiex_pcie_delete_evtbd_ring(struct mwifiex_adapter *adapter) 794static int mwifiex_pcie_delete_evtbd_ring(struct mwifiex_adapter *adapter)
618{ 795{
619 struct pcie_service_card *card = adapter->card; 796 struct pcie_service_card *card = adapter->card;
620 int i; 797 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
621 798
622 for (i = 0; i < MWIFIEX_MAX_EVT_BD; i++) { 799 mwifiex_cleanup_evt_ring(adapter);
623 if (card->evt_buf_list[i])
624 dev_kfree_skb_any(card->evt_buf_list[i]);
625 card->evt_buf_list[i] = NULL;
626 card->evtbd_ring[i]->paddr = 0;
627 card->evtbd_ring[i]->len = 0;
628 card->evtbd_ring[i]->flags = 0;
629 card->evtbd_ring[i] = NULL;
630 }
631 800
632 kfree(card->evtbd_ring_vbase); 801 if (card->evtbd_ring_vbase)
802 pci_free_consistent(card->dev, card->evtbd_ring_size,
803 card->evtbd_ring_vbase,
804 card->evtbd_ring_pbase);
633 card->evtbd_wrptr = 0; 805 card->evtbd_wrptr = 0;
634 card->evtbd_rdptr = 0 | MWIFIEX_BD_FLAG_ROLLOVER_IND; 806 card->evtbd_rdptr = 0 | reg->evt_rollover_ind;
635 card->evtbd_ring_size = 0; 807 card->evtbd_ring_size = 0;
636 card->evtbd_ring_vbase = NULL; 808 card->evtbd_ring_vbase = NULL;
809 card->evtbd_ring_pbase = 0;
637 810
638 return 0; 811 return 0;
639} 812}
@@ -653,21 +826,12 @@ static int mwifiex_pcie_alloc_cmdrsp_buf(struct mwifiex_adapter *adapter)
653 "Unable to allocate skb for command response data.\n"); 826 "Unable to allocate skb for command response data.\n");
654 return -ENOMEM; 827 return -ENOMEM;
655 } 828 }
656 mwifiex_update_sk_buff_pa(skb);
657 skb_put(skb, MWIFIEX_UPLD_SIZE); 829 skb_put(skb, MWIFIEX_UPLD_SIZE);
658 card->cmdrsp_buf = skb; 830 if (mwifiex_map_pci_memory(adapter, skb, MWIFIEX_UPLD_SIZE,
831 PCI_DMA_FROMDEVICE))
832 return -1;
659 833
660 skb = NULL; 834 card->cmdrsp_buf = skb;
661 /* Allocate memory for sending command to firmware */
662 skb = dev_alloc_skb(MWIFIEX_SIZE_OF_CMD_BUFFER);
663 if (!skb) {
664 dev_err(adapter->dev,
665 "Unable to allocate skb for command data.\n");
666 return -ENOMEM;
667 }
668 mwifiex_update_sk_buff_pa(skb);
669 skb_put(skb, MWIFIEX_SIZE_OF_CMD_BUFFER);
670 card->cmd_buf = skb;
671 835
672 return 0; 836 return 0;
673} 837}
@@ -678,18 +842,26 @@ static int mwifiex_pcie_alloc_cmdrsp_buf(struct mwifiex_adapter *adapter)
678static int mwifiex_pcie_delete_cmdrsp_buf(struct mwifiex_adapter *adapter) 842static int mwifiex_pcie_delete_cmdrsp_buf(struct mwifiex_adapter *adapter)
679{ 843{
680 struct pcie_service_card *card; 844 struct pcie_service_card *card;
845 dma_addr_t buf_pa;
681 846
682 if (!adapter) 847 if (!adapter)
683 return 0; 848 return 0;
684 849
685 card = adapter->card; 850 card = adapter->card;
686 851
687 if (card && card->cmdrsp_buf) 852 if (card && card->cmdrsp_buf) {
853 MWIFIEX_SKB_PACB(card->cmdrsp_buf, &buf_pa);
854 pci_unmap_single(card->dev, buf_pa, MWIFIEX_UPLD_SIZE,
855 PCI_DMA_FROMDEVICE);
688 dev_kfree_skb_any(card->cmdrsp_buf); 856 dev_kfree_skb_any(card->cmdrsp_buf);
857 }
689 858
690 if (card && card->cmd_buf) 859 if (card && card->cmd_buf) {
860 MWIFIEX_SKB_PACB(card->cmd_buf, &buf_pa);
861 pci_unmap_single(card->dev, buf_pa, MWIFIEX_SIZE_OF_CMD_BUFFER,
862 PCI_DMA_TODEVICE);
691 dev_kfree_skb_any(card->cmd_buf); 863 dev_kfree_skb_any(card->cmd_buf);
692 864 }
693 return 0; 865 return 0;
694} 866}
695 867
@@ -698,27 +870,19 @@ static int mwifiex_pcie_delete_cmdrsp_buf(struct mwifiex_adapter *adapter)
698 */ 870 */
699static int mwifiex_pcie_alloc_sleep_cookie_buf(struct mwifiex_adapter *adapter) 871static int mwifiex_pcie_alloc_sleep_cookie_buf(struct mwifiex_adapter *adapter)
700{ 872{
701 struct sk_buff *skb;
702 struct pcie_service_card *card = adapter->card; 873 struct pcie_service_card *card = adapter->card;
703 874
704 /* Allocate memory for sleep cookie */ 875 card->sleep_cookie_vbase = pci_alloc_consistent(card->dev, sizeof(u32),
705 skb = dev_alloc_skb(sizeof(u32)); 876 &card->sleep_cookie_pbase);
706 if (!skb) { 877 if (!card->sleep_cookie_vbase) {
707 dev_err(adapter->dev, 878 dev_err(adapter->dev, "pci_alloc_consistent failed!\n");
708 "Unable to allocate skb for sleep cookie!\n");
709 return -ENOMEM; 879 return -ENOMEM;
710 } 880 }
711 mwifiex_update_sk_buff_pa(skb);
712 skb_put(skb, sizeof(u32));
713
714 /* Init val of Sleep Cookie */ 881 /* Init val of Sleep Cookie */
715 *(u32 *)skb->data = FW_AWAKE_COOKIE; 882 *(u32 *)card->sleep_cookie_vbase = FW_AWAKE_COOKIE;
716 883
717 dev_dbg(adapter->dev, "alloc_scook: sleep cookie=0x%x\n", 884 dev_dbg(adapter->dev, "alloc_scook: sleep cookie=0x%x\n",
718 *((u32 *)skb->data)); 885 *((u32 *)card->sleep_cookie_vbase));
719
720 /* Save the sleep cookie */
721 card->sleep_cookie = skb;
722 886
723 return 0; 887 return 0;
724} 888}
@@ -735,86 +899,246 @@ static int mwifiex_pcie_delete_sleep_cookie_buf(struct mwifiex_adapter *adapter)
735 899
736 card = adapter->card; 900 card = adapter->card;
737 901
738 if (card && card->sleep_cookie) { 902 if (card && card->sleep_cookie_vbase) {
739 dev_kfree_skb_any(card->sleep_cookie); 903 pci_free_consistent(card->dev, sizeof(u32),
740 card->sleep_cookie = NULL; 904 card->sleep_cookie_vbase,
905 card->sleep_cookie_pbase);
906 card->sleep_cookie_vbase = NULL;
741 } 907 }
742 908
743 return 0; 909 return 0;
744} 910}
745 911
912/* This function flushes the TX buffer descriptor ring
913 * This function defined as handler is also called while cleaning TXRX
914 * during disconnect/ bss stop.
915 */
916static int mwifiex_clean_pcie_ring_buf(struct mwifiex_adapter *adapter)
917{
918 struct pcie_service_card *card = adapter->card;
919 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
920 u32 rdptr;
921
922 /* Read the TX ring read pointer set by firmware */
923 if (mwifiex_read_reg(adapter, reg->tx_rdptr, &rdptr)) {
924 dev_err(adapter->dev,
925 "Flush TXBD: failed to read reg->tx_rdptr\n");
926 return -1;
927 }
928
929 if (!mwifiex_pcie_txbd_empty(card, rdptr)) {
930 card->txbd_flush = 1;
931 /* write pointer already set at last send
932 * send dnld-rdy intr again, wait for completion.
933 */
934 if (mwifiex_write_reg(adapter, PCIE_CPU_INT_EVENT,
935 CPU_INTR_DNLD_RDY)) {
936 dev_err(adapter->dev,
937 "failed to assert dnld-rdy interrupt.\n");
938 return -1;
939 }
940 }
941 return 0;
942}
943
746/* 944/*
747 * This function sends data buffer to device 945 * This function unmaps and frees downloaded data buffer
748 */ 946 */
749static int 947static int mwifiex_pcie_send_data_complete(struct mwifiex_adapter *adapter)
750mwifiex_pcie_send_data(struct mwifiex_adapter *adapter, struct sk_buff *skb)
751{ 948{
949 struct sk_buff *skb;
950 dma_addr_t buf_pa;
951 u32 wrdoneidx, rdptr, num_tx_buffs, unmap_count = 0;
952 struct mwifiex_pcie_buf_desc *desc;
953 struct mwifiex_pfu_buf_desc *desc2;
752 struct pcie_service_card *card = adapter->card; 954 struct pcie_service_card *card = adapter->card;
753 u32 wrindx, rdptr; 955 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
754 phys_addr_t *buf_pa;
755 __le16 *tmp;
756 956
757 if (!mwifiex_pcie_ok_to_access_hw(adapter)) 957 if (!mwifiex_pcie_ok_to_access_hw(adapter))
758 mwifiex_pm_wakeup_card(adapter); 958 mwifiex_pm_wakeup_card(adapter);
759 959
760 /* Read the TX ring read pointer set by firmware */ 960 /* Read the TX ring read pointer set by firmware */
761 if (mwifiex_read_reg(adapter, REG_TXBD_RDPTR, &rdptr)) { 961 if (mwifiex_read_reg(adapter, reg->tx_rdptr, &rdptr)) {
762 dev_err(adapter->dev, 962 dev_err(adapter->dev,
763 "SEND DATA: failed to read REG_TXBD_RDPTR\n"); 963 "SEND COMP: failed to read reg->tx_rdptr\n");
764 return -1; 964 return -1;
765 } 965 }
766 966
767 wrindx = card->txbd_wrptr & MWIFIEX_TXBD_MASK; 967 dev_dbg(adapter->dev, "SEND COMP: rdptr_prev=0x%x, rdptr=0x%x\n",
968 card->txbd_rdptr, rdptr);
768 969
769 dev_dbg(adapter->dev, "info: SEND DATA: <Rd: %#x, Wr: %#x>\n", rdptr, 970 num_tx_buffs = MWIFIEX_MAX_TXRX_BD << reg->tx_start_ptr;
770 card->txbd_wrptr); 971 /* free from previous txbd_rdptr to current txbd_rdptr */
771 if (((card->txbd_wrptr & MWIFIEX_TXBD_MASK) != 972 while (((card->txbd_rdptr & reg->tx_mask) !=
772 (rdptr & MWIFIEX_TXBD_MASK)) || 973 (rdptr & reg->tx_mask)) ||
773 ((card->txbd_wrptr & MWIFIEX_BD_FLAG_ROLLOVER_IND) != 974 ((card->txbd_rdptr & reg->tx_rollover_ind) !=
774 (rdptr & MWIFIEX_BD_FLAG_ROLLOVER_IND))) { 975 (rdptr & reg->tx_rollover_ind))) {
775 struct sk_buff *skb_data; 976 wrdoneidx = (card->txbd_rdptr & reg->tx_mask) >>
977 reg->tx_start_ptr;
978
979 skb = card->tx_buf_list[wrdoneidx];
980 if (skb) {
981 dev_dbg(adapter->dev,
982 "SEND COMP: Detach skb %p at txbd_rdidx=%d\n",
983 skb, wrdoneidx);
984 MWIFIEX_SKB_PACB(skb, &buf_pa);
985 pci_unmap_single(card->dev, buf_pa, skb->len,
986 PCI_DMA_TODEVICE);
987
988 unmap_count++;
989
990 if (card->txbd_flush)
991 mwifiex_write_data_complete(adapter, skb, 0,
992 -1);
993 else
994 mwifiex_write_data_complete(adapter, skb, 0, 0);
995 }
996
997 card->tx_buf_list[wrdoneidx] = NULL;
998
999 if (reg->pfu_enabled) {
1000 desc2 = (void *)card->txbd_ring[wrdoneidx];
1001 memset(desc2, 0, sizeof(*desc2));
1002 } else {
1003 desc = card->txbd_ring[wrdoneidx];
1004 memset(desc, 0, sizeof(*desc));
1005 }
1006 switch (card->dev->device) {
1007 case PCIE_DEVICE_ID_MARVELL_88W8766P:
1008 card->txbd_rdptr++;
1009 break;
1010 case PCIE_DEVICE_ID_MARVELL_88W8897:
1011 card->txbd_rdptr += reg->ring_tx_start_ptr;
1012 break;
1013 }
1014
1015
1016 if ((card->txbd_rdptr & reg->tx_mask) == num_tx_buffs)
1017 card->txbd_rdptr = ((card->txbd_rdptr &
1018 reg->tx_rollover_ind) ^
1019 reg->tx_rollover_ind);
1020 }
1021
1022 if (unmap_count)
1023 adapter->data_sent = false;
1024
1025 if (card->txbd_flush) {
1026 if (mwifiex_pcie_txbd_empty(card, card->txbd_rdptr))
1027 card->txbd_flush = 0;
1028 else
1029 mwifiex_clean_pcie_ring_buf(adapter);
1030 }
1031
1032 return 0;
1033}
1034
1035/* This function sends data buffer to device. First 4 bytes of payload
1036 * are filled with payload length and payload type. Then this payload
1037 * is mapped to PCI device memory. Tx ring pointers are advanced accordingly.
1038 * Download ready interrupt to FW is deffered if Tx ring is not full and
1039 * additional payload can be accomodated.
1040 */
1041static int
1042mwifiex_pcie_send_data(struct mwifiex_adapter *adapter, struct sk_buff *skb,
1043 struct mwifiex_tx_param *tx_param)
1044{
1045 struct pcie_service_card *card = adapter->card;
1046 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
1047 u32 wrindx, num_tx_buffs, rx_val;
1048 int ret;
1049 dma_addr_t buf_pa;
1050 struct mwifiex_pcie_buf_desc *desc;
1051 struct mwifiex_pfu_buf_desc *desc2;
1052 __le16 *tmp;
1053
1054 if (!(skb->data && skb->len)) {
1055 dev_err(adapter->dev, "%s(): invalid parameter <%p, %#x>\n",
1056 __func__, skb->data, skb->len);
1057 return -1;
1058 }
1059
1060 if (!mwifiex_pcie_ok_to_access_hw(adapter))
1061 mwifiex_pm_wakeup_card(adapter);
1062
1063 num_tx_buffs = MWIFIEX_MAX_TXRX_BD << reg->tx_start_ptr;
1064 dev_dbg(adapter->dev, "info: SEND DATA: <Rd: %#x, Wr: %#x>\n",
1065 card->txbd_rdptr, card->txbd_wrptr);
1066 if (mwifiex_pcie_txbd_not_full(card)) {
776 u8 *payload; 1067 u8 *payload;
777 1068
778 adapter->data_sent = true; 1069 adapter->data_sent = true;
779 skb_data = card->tx_buf_list[wrindx]; 1070 payload = skb->data;
780 memcpy(skb_data->data, skb->data, skb->len);
781 payload = skb_data->data;
782 tmp = (__le16 *)&payload[0]; 1071 tmp = (__le16 *)&payload[0];
783 *tmp = cpu_to_le16((u16)skb->len); 1072 *tmp = cpu_to_le16((u16)skb->len);
784 tmp = (__le16 *)&payload[2]; 1073 tmp = (__le16 *)&payload[2];
785 *tmp = cpu_to_le16(MWIFIEX_TYPE_DATA); 1074 *tmp = cpu_to_le16(MWIFIEX_TYPE_DATA);
786 skb_put(skb_data, MWIFIEX_RX_DATA_BUF_SIZE - skb_data->len);
787 skb_trim(skb_data, skb->len);
788 buf_pa = MWIFIEX_SKB_PACB(skb_data);
789 card->txbd_ring[wrindx]->paddr = *buf_pa;
790 card->txbd_ring[wrindx]->len = (u16)skb_data->len;
791 card->txbd_ring[wrindx]->flags = MWIFIEX_BD_FLAG_FIRST_DESC |
792 MWIFIEX_BD_FLAG_LAST_DESC;
793
794 if ((++card->txbd_wrptr & MWIFIEX_TXBD_MASK) ==
795 MWIFIEX_MAX_TXRX_BD)
796 card->txbd_wrptr = ((card->txbd_wrptr &
797 MWIFIEX_BD_FLAG_ROLLOVER_IND) ^
798 MWIFIEX_BD_FLAG_ROLLOVER_IND);
799 1075
800 /* Write the TX ring write pointer in to REG_TXBD_WRPTR */ 1076 if (mwifiex_map_pci_memory(adapter, skb, skb->len ,
801 if (mwifiex_write_reg(adapter, REG_TXBD_WRPTR, 1077 PCI_DMA_TODEVICE))
802 card->txbd_wrptr)) { 1078 return -1;
803 dev_err(adapter->dev, 1079
804 "SEND DATA: failed to write REG_TXBD_WRPTR\n"); 1080 wrindx = (card->txbd_wrptr & reg->tx_mask) >> reg->tx_start_ptr;
805 return 0; 1081 MWIFIEX_SKB_PACB(skb, &buf_pa);
1082 card->tx_buf_list[wrindx] = skb;
1083
1084 if (reg->pfu_enabled) {
1085 desc2 = (void *)card->txbd_ring[wrindx];
1086 desc2->paddr = buf_pa;
1087 desc2->len = (u16)skb->len;
1088 desc2->frag_len = (u16)skb->len;
1089 desc2->offset = 0;
1090 desc2->flags = MWIFIEX_BD_FLAG_FIRST_DESC |
1091 MWIFIEX_BD_FLAG_LAST_DESC;
1092 } else {
1093 desc = card->txbd_ring[wrindx];
1094 desc->paddr = buf_pa;
1095 desc->len = (u16)skb->len;
1096 desc->flags = MWIFIEX_BD_FLAG_FIRST_DESC |
1097 MWIFIEX_BD_FLAG_LAST_DESC;
806 } 1098 }
807 1099
808 /* Send the TX ready interrupt */ 1100 switch (card->dev->device) {
809 if (mwifiex_write_reg(adapter, PCIE_CPU_INT_EVENT, 1101 case PCIE_DEVICE_ID_MARVELL_88W8766P:
810 CPU_INTR_DNLD_RDY)) { 1102 card->txbd_wrptr++;
1103 break;
1104 case PCIE_DEVICE_ID_MARVELL_88W8897:
1105 card->txbd_wrptr += reg->ring_tx_start_ptr;
1106 break;
1107 }
1108
1109 if ((card->txbd_wrptr & reg->tx_mask) == num_tx_buffs)
1110 card->txbd_wrptr = ((card->txbd_wrptr &
1111 reg->tx_rollover_ind) ^
1112 reg->tx_rollover_ind);
1113
1114 rx_val = card->rxbd_rdptr & reg->rx_wrap_mask;
1115 /* Write the TX ring write pointer in to reg->tx_wrptr */
1116 if (mwifiex_write_reg(adapter, reg->tx_wrptr,
1117 card->txbd_wrptr | rx_val)) {
811 dev_err(adapter->dev, 1118 dev_err(adapter->dev,
812 "SEND DATA: failed to assert door-bell intr\n"); 1119 "SEND DATA: failed to write reg->tx_wrptr\n");
813 return -1; 1120 ret = -1;
1121 goto done_unmap;
1122 }
1123 if ((mwifiex_pcie_txbd_not_full(card)) &&
1124 tx_param->next_pkt_len) {
1125 /* have more packets and TxBD still can hold more */
1126 dev_dbg(adapter->dev,
1127 "SEND DATA: delay dnld-rdy interrupt.\n");
1128 adapter->data_sent = false;
1129 } else {
1130 /* Send the TX ready interrupt */
1131 if (mwifiex_write_reg(adapter, PCIE_CPU_INT_EVENT,
1132 CPU_INTR_DNLD_RDY)) {
1133 dev_err(adapter->dev,
1134 "SEND DATA: failed to assert dnld-rdy interrupt.\n");
1135 ret = -1;
1136 goto done_unmap;
1137 }
814 } 1138 }
815 dev_dbg(adapter->dev, "info: SEND DATA: Updated <Rd: %#x, Wr: " 1139 dev_dbg(adapter->dev, "info: SEND DATA: Updated <Rd: %#x, Wr: "
816 "%#x> and sent packet to firmware successfully\n", 1140 "%#x> and sent packet to firmware successfully\n",
817 rdptr, card->txbd_wrptr); 1141 card->txbd_rdptr, card->txbd_wrptr);
818 } else { 1142 } else {
819 dev_dbg(adapter->dev, 1143 dev_dbg(adapter->dev,
820 "info: TX Ring full, can't send packets to fw\n"); 1144 "info: TX Ring full, can't send packets to fw\n");
@@ -827,7 +1151,17 @@ mwifiex_pcie_send_data(struct mwifiex_adapter *adapter, struct sk_buff *skb)
827 return -EBUSY; 1151 return -EBUSY;
828 } 1152 }
829 1153
830 return 0; 1154 return -EINPROGRESS;
1155done_unmap:
1156 MWIFIEX_SKB_PACB(skb, &buf_pa);
1157 pci_unmap_single(card->dev, buf_pa, skb->len, PCI_DMA_TODEVICE);
1158 card->tx_buf_list[wrindx] = NULL;
1159 if (reg->pfu_enabled)
1160 memset(desc2, 0, sizeof(*desc2));
1161 else
1162 memset(desc, 0, sizeof(*desc));
1163
1164 return ret;
831} 1165}
832 1166
833/* 1167/*
@@ -837,78 +1171,119 @@ mwifiex_pcie_send_data(struct mwifiex_adapter *adapter, struct sk_buff *skb)
837static int mwifiex_pcie_process_recv_data(struct mwifiex_adapter *adapter) 1171static int mwifiex_pcie_process_recv_data(struct mwifiex_adapter *adapter)
838{ 1172{
839 struct pcie_service_card *card = adapter->card; 1173 struct pcie_service_card *card = adapter->card;
840 u32 wrptr, rd_index; 1174 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
1175 u32 wrptr, rd_index, tx_val;
1176 dma_addr_t buf_pa;
841 int ret = 0; 1177 int ret = 0;
842 struct sk_buff *skb_tmp = NULL; 1178 struct sk_buff *skb_tmp = NULL;
1179 struct mwifiex_pcie_buf_desc *desc;
1180 struct mwifiex_pfu_buf_desc *desc2;
1181
1182 if (!mwifiex_pcie_ok_to_access_hw(adapter))
1183 mwifiex_pm_wakeup_card(adapter);
843 1184
844 /* Read the RX ring Write pointer set by firmware */ 1185 /* Read the RX ring Write pointer set by firmware */
845 if (mwifiex_read_reg(adapter, REG_RXBD_WRPTR, &wrptr)) { 1186 if (mwifiex_read_reg(adapter, reg->rx_wrptr, &wrptr)) {
846 dev_err(adapter->dev, 1187 dev_err(adapter->dev,
847 "RECV DATA: failed to read REG_TXBD_RDPTR\n"); 1188 "RECV DATA: failed to read reg->rx_wrptr\n");
848 ret = -1; 1189 ret = -1;
849 goto done; 1190 goto done;
850 } 1191 }
1192 card->rxbd_wrptr = wrptr;
851 1193
852 while (((wrptr & MWIFIEX_RXBD_MASK) != 1194 while (((wrptr & reg->rx_mask) !=
853 (card->rxbd_rdptr & MWIFIEX_RXBD_MASK)) || 1195 (card->rxbd_rdptr & reg->rx_mask)) ||
854 ((wrptr & MWIFIEX_BD_FLAG_ROLLOVER_IND) == 1196 ((wrptr & reg->rx_rollover_ind) ==
855 (card->rxbd_rdptr & MWIFIEX_BD_FLAG_ROLLOVER_IND))) { 1197 (card->rxbd_rdptr & reg->rx_rollover_ind))) {
856 struct sk_buff *skb_data; 1198 struct sk_buff *skb_data;
857 u16 rx_len; 1199 u16 rx_len;
1200 __le16 pkt_len;
858 1201
859 rd_index = card->rxbd_rdptr & MWIFIEX_RXBD_MASK; 1202 rd_index = card->rxbd_rdptr & reg->rx_mask;
860 skb_data = card->rx_buf_list[rd_index]; 1203 skb_data = card->rx_buf_list[rd_index];
861 1204
1205 MWIFIEX_SKB_PACB(skb_data, &buf_pa);
1206 pci_unmap_single(card->dev, buf_pa, MWIFIEX_RX_DATA_BUF_SIZE,
1207 PCI_DMA_FROMDEVICE);
1208 card->rx_buf_list[rd_index] = NULL;
1209
862 /* Get data length from interface header - 1210 /* Get data length from interface header -
863 first byte is len, second byte is type */ 1211 * first 2 bytes for len, next 2 bytes is for type
864 rx_len = *((u16 *)skb_data->data); 1212 */
1213 pkt_len = *((__le16 *)skb_data->data);
1214 rx_len = le16_to_cpu(pkt_len);
1215 skb_put(skb_data, rx_len);
865 dev_dbg(adapter->dev, 1216 dev_dbg(adapter->dev,
866 "info: RECV DATA: Rd=%#x, Wr=%#x, Len=%d\n", 1217 "info: RECV DATA: Rd=%#x, Wr=%#x, Len=%d\n",
867 card->rxbd_rdptr, wrptr, rx_len); 1218 card->rxbd_rdptr, wrptr, rx_len);
868 skb_tmp = dev_alloc_skb(rx_len); 1219 skb_pull(skb_data, INTF_HEADER_LEN);
1220 mwifiex_handle_rx_packet(adapter, skb_data);
1221
1222 skb_tmp = dev_alloc_skb(MWIFIEX_RX_DATA_BUF_SIZE);
869 if (!skb_tmp) { 1223 if (!skb_tmp) {
870 dev_dbg(adapter->dev, 1224 dev_err(adapter->dev,
871 "info: Failed to alloc skb for RX\n"); 1225 "Unable to allocate skb.\n");
872 ret = -EBUSY; 1226 return -ENOMEM;
873 goto done;
874 } 1227 }
875 1228
876 skb_put(skb_tmp, rx_len); 1229 if (mwifiex_map_pci_memory(adapter, skb_tmp,
1230 MWIFIEX_RX_DATA_BUF_SIZE,
1231 PCI_DMA_FROMDEVICE))
1232 return -1;
1233
1234 MWIFIEX_SKB_PACB(skb_tmp, &buf_pa);
1235
1236 dev_dbg(adapter->dev,
1237 "RECV DATA: Attach new sk_buff %p at rxbd_rdidx=%d\n",
1238 skb_tmp, rd_index);
1239 card->rx_buf_list[rd_index] = skb_tmp;
1240
1241 if (reg->pfu_enabled) {
1242 desc2 = (void *)card->rxbd_ring[rd_index];
1243 desc2->paddr = buf_pa;
1244 desc2->len = skb_tmp->len;
1245 desc2->frag_len = skb_tmp->len;
1246 desc2->offset = 0;
1247 desc2->flags = reg->ring_flag_sop | reg->ring_flag_eop;
1248 } else {
1249 desc = card->rxbd_ring[rd_index];
1250 desc->paddr = buf_pa;
1251 desc->len = skb_tmp->len;
1252 desc->flags = 0;
1253 }
877 1254
878 memcpy(skb_tmp->data, skb_data->data + INTF_HEADER_LEN, rx_len); 1255 if ((++card->rxbd_rdptr & reg->rx_mask) ==
879 if ((++card->rxbd_rdptr & MWIFIEX_RXBD_MASK) ==
880 MWIFIEX_MAX_TXRX_BD) { 1256 MWIFIEX_MAX_TXRX_BD) {
881 card->rxbd_rdptr = ((card->rxbd_rdptr & 1257 card->rxbd_rdptr = ((card->rxbd_rdptr &
882 MWIFIEX_BD_FLAG_ROLLOVER_IND) ^ 1258 reg->rx_rollover_ind) ^
883 MWIFIEX_BD_FLAG_ROLLOVER_IND); 1259 reg->rx_rollover_ind);
884 } 1260 }
885 dev_dbg(adapter->dev, "info: RECV DATA: <Rd: %#x, Wr: %#x>\n", 1261 dev_dbg(adapter->dev, "info: RECV DATA: <Rd: %#x, Wr: %#x>\n",
886 card->rxbd_rdptr, wrptr); 1262 card->rxbd_rdptr, wrptr);
887 1263
888 /* Write the RX ring read pointer in to REG_RXBD_RDPTR */ 1264 tx_val = card->txbd_wrptr & reg->tx_wrap_mask;
889 if (mwifiex_write_reg(adapter, REG_RXBD_RDPTR, 1265 /* Write the RX ring read pointer in to reg->rx_rdptr */
890 card->rxbd_rdptr)) { 1266 if (mwifiex_write_reg(adapter, reg->rx_rdptr,
1267 card->rxbd_rdptr | tx_val)) {
891 dev_err(adapter->dev, 1268 dev_err(adapter->dev,
892 "RECV DATA: failed to write REG_RXBD_RDPTR\n"); 1269 "RECV DATA: failed to write reg->rx_rdptr\n");
893 ret = -1; 1270 ret = -1;
894 goto done; 1271 goto done;
895 } 1272 }
896 1273
897 /* Read the RX ring Write pointer set by firmware */ 1274 /* Read the RX ring Write pointer set by firmware */
898 if (mwifiex_read_reg(adapter, REG_RXBD_WRPTR, &wrptr)) { 1275 if (mwifiex_read_reg(adapter, reg->rx_wrptr, &wrptr)) {
899 dev_err(adapter->dev, 1276 dev_err(adapter->dev,
900 "RECV DATA: failed to read REG_TXBD_RDPTR\n"); 1277 "RECV DATA: failed to read reg->rx_wrptr\n");
901 ret = -1; 1278 ret = -1;
902 goto done; 1279 goto done;
903 } 1280 }
904 dev_dbg(adapter->dev, 1281 dev_dbg(adapter->dev,
905 "info: RECV DATA: Rcvd packet from fw successfully\n"); 1282 "info: RECV DATA: Rcvd packet from fw successfully\n");
906 mwifiex_handle_rx_packet(adapter, skb_tmp); 1283 card->rxbd_wrptr = wrptr;
907 } 1284 }
908 1285
909done: 1286done:
910 if (ret && skb_tmp)
911 dev_kfree_skb_any(skb_tmp);
912 return ret; 1287 return ret;
913} 1288}
914 1289
@@ -918,40 +1293,54 @@ done:
918static int 1293static int
919mwifiex_pcie_send_boot_cmd(struct mwifiex_adapter *adapter, struct sk_buff *skb) 1294mwifiex_pcie_send_boot_cmd(struct mwifiex_adapter *adapter, struct sk_buff *skb)
920{ 1295{
921 phys_addr_t *buf_pa = MWIFIEX_SKB_PACB(skb); 1296 dma_addr_t buf_pa;
1297 struct pcie_service_card *card = adapter->card;
1298 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
922 1299
923 if (!(skb->data && skb->len && *buf_pa)) { 1300 if (!(skb->data && skb->len)) {
924 dev_err(adapter->dev, 1301 dev_err(adapter->dev,
925 "Invalid parameter in %s <%p, %#x:%x, %x>\n", 1302 "Invalid parameter in %s <%p. len %d>\n",
926 __func__, skb->data, skb->len, 1303 __func__, skb->data, skb->len);
927 (u32)*buf_pa, (u32)((u64)*buf_pa >> 32));
928 return -1; 1304 return -1;
929 } 1305 }
930 1306
931 /* Write the lower 32bits of the physical address to scratch 1307 if (mwifiex_map_pci_memory(adapter, skb, skb->len , PCI_DMA_TODEVICE))
932 * register 0 */ 1308 return -1;
933 if (mwifiex_write_reg(adapter, PCIE_SCRATCH_0_REG, (u32)*buf_pa)) { 1309
1310 MWIFIEX_SKB_PACB(skb, &buf_pa);
1311
1312 /* Write the lower 32bits of the physical address to low command
1313 * address scratch register
1314 */
1315 if (mwifiex_write_reg(adapter, reg->cmd_addr_lo, (u32)buf_pa)) {
934 dev_err(adapter->dev, 1316 dev_err(adapter->dev,
935 "%s: failed to write download command to boot code.\n", 1317 "%s: failed to write download command to boot code.\n",
936 __func__); 1318 __func__);
1319 pci_unmap_single(card->dev, buf_pa, MWIFIEX_UPLD_SIZE,
1320 PCI_DMA_TODEVICE);
937 return -1; 1321 return -1;
938 } 1322 }
939 1323
940 /* Write the upper 32bits of the physical address to scratch 1324 /* Write the upper 32bits of the physical address to high command
941 * register 1 */ 1325 * address scratch register
942 if (mwifiex_write_reg(adapter, PCIE_SCRATCH_1_REG, 1326 */
943 (u32)((u64)*buf_pa >> 32))) { 1327 if (mwifiex_write_reg(adapter, reg->cmd_addr_hi,
1328 (u32)((u64)buf_pa >> 32))) {
944 dev_err(adapter->dev, 1329 dev_err(adapter->dev,
945 "%s: failed to write download command to boot code.\n", 1330 "%s: failed to write download command to boot code.\n",
946 __func__); 1331 __func__);
1332 pci_unmap_single(card->dev, buf_pa, MWIFIEX_UPLD_SIZE,
1333 PCI_DMA_TODEVICE);
947 return -1; 1334 return -1;
948 } 1335 }
949 1336
950 /* Write the command length to scratch register 2 */ 1337 /* Write the command length to cmd_size scratch register */
951 if (mwifiex_write_reg(adapter, PCIE_SCRATCH_2_REG, skb->len)) { 1338 if (mwifiex_write_reg(adapter, reg->cmd_size, skb->len)) {
952 dev_err(adapter->dev, 1339 dev_err(adapter->dev,
953 "%s: failed to write command len to scratch reg 2\n", 1340 "%s: failed to write command len to cmd_size scratch reg\n",
954 __func__); 1341 __func__);
1342 pci_unmap_single(card->dev, buf_pa, MWIFIEX_UPLD_SIZE,
1343 PCI_DMA_TODEVICE);
955 return -1; 1344 return -1;
956 } 1345 }
957 1346
@@ -960,22 +1349,43 @@ mwifiex_pcie_send_boot_cmd(struct mwifiex_adapter *adapter, struct sk_buff *skb)
960 CPU_INTR_DOOR_BELL)) { 1349 CPU_INTR_DOOR_BELL)) {
961 dev_err(adapter->dev, 1350 dev_err(adapter->dev,
962 "%s: failed to assert door-bell intr\n", __func__); 1351 "%s: failed to assert door-bell intr\n", __func__);
1352 pci_unmap_single(card->dev, buf_pa,
1353 MWIFIEX_UPLD_SIZE, PCI_DMA_TODEVICE);
963 return -1; 1354 return -1;
964 } 1355 }
965 1356
966 return 0; 1357 return 0;
967} 1358}
968 1359
969/* 1360/* This function init rx port in firmware which in turn enables to receive data
970 * This function downloads commands to the device 1361 * from device before transmitting any packet.
1362 */
1363static int mwifiex_pcie_init_fw_port(struct mwifiex_adapter *adapter)
1364{
1365 struct pcie_service_card *card = adapter->card;
1366 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
1367 int tx_wrap = card->txbd_wrptr & reg->tx_wrap_mask;
1368
1369 /* Write the RX ring read pointer in to reg->rx_rdptr */
1370 if (mwifiex_write_reg(adapter, reg->rx_rdptr, card->rxbd_rdptr |
1371 tx_wrap)) {
1372 dev_err(adapter->dev,
1373 "RECV DATA: failed to write reg->rx_rdptr\n");
1374 return -1;
1375 }
1376 return 0;
1377}
1378
1379/* This function downloads commands to the device
971 */ 1380 */
972static int 1381static int
973mwifiex_pcie_send_cmd(struct mwifiex_adapter *adapter, struct sk_buff *skb) 1382mwifiex_pcie_send_cmd(struct mwifiex_adapter *adapter, struct sk_buff *skb)
974{ 1383{
975 struct pcie_service_card *card = adapter->card; 1384 struct pcie_service_card *card = adapter->card;
1385 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
976 int ret = 0; 1386 int ret = 0;
977 phys_addr_t *cmd_buf_pa; 1387 dma_addr_t cmd_buf_pa, cmdrsp_buf_pa;
978 phys_addr_t *cmdrsp_buf_pa; 1388 u8 *payload = (u8 *)skb->data;
979 1389
980 if (!(skb->data && skb->len)) { 1390 if (!(skb->data && skb->len)) {
981 dev_err(adapter->dev, "Invalid parameter in %s <%p, %#x>\n", 1391 dev_err(adapter->dev, "Invalid parameter in %s <%p, %#x>\n",
@@ -990,21 +1400,22 @@ mwifiex_pcie_send_cmd(struct mwifiex_adapter *adapter, struct sk_buff *skb)
990 return -EBUSY; 1400 return -EBUSY;
991 } 1401 }
992 1402
993 /* Make sure a command buffer is available */ 1403 if (!mwifiex_pcie_ok_to_access_hw(adapter))
994 if (!card->cmd_buf) { 1404 mwifiex_pm_wakeup_card(adapter);
995 dev_err(adapter->dev, "Command buffer not available\n");
996 return -EBUSY;
997 }
998 1405
999 adapter->cmd_sent = true; 1406 adapter->cmd_sent = true;
1000 /* Copy the given skb in to DMA accessable shared buffer */ 1407
1001 skb_put(card->cmd_buf, MWIFIEX_SIZE_OF_CMD_BUFFER - card->cmd_buf->len); 1408 *(__le16 *)&payload[0] = cpu_to_le16((u16)skb->len);
1002 skb_trim(card->cmd_buf, skb->len); 1409 *(__le16 *)&payload[2] = cpu_to_le16(MWIFIEX_TYPE_CMD);
1003 memcpy(card->cmd_buf->data, skb->data, skb->len); 1410
1411 if (mwifiex_map_pci_memory(adapter, skb, skb->len, PCI_DMA_TODEVICE))
1412 return -1;
1413
1414 card->cmd_buf = skb;
1004 1415
1005 /* To send a command, the driver will: 1416 /* To send a command, the driver will:
1006 1. Write the 64bit physical address of the data buffer to 1417 1. Write the 64bit physical address of the data buffer to
1007 SCRATCH1 + SCRATCH0 1418 cmd response address low + cmd response address high
1008 2. Ring the door bell (i.e. set the door bell interrupt) 1419 2. Ring the door bell (i.e. set the door bell interrupt)
1009 1420
1010 In response to door bell interrupt, the firmware will perform 1421 In response to door bell interrupt, the firmware will perform
@@ -1013,11 +1424,11 @@ mwifiex_pcie_send_cmd(struct mwifiex_adapter *adapter, struct sk_buff *skb)
1013 */ 1424 */
1014 1425
1015 if (card->cmdrsp_buf) { 1426 if (card->cmdrsp_buf) {
1016 cmdrsp_buf_pa = MWIFIEX_SKB_PACB(card->cmdrsp_buf); 1427 MWIFIEX_SKB_PACB(card->cmdrsp_buf, &cmdrsp_buf_pa);
1017 /* Write the lower 32bits of the cmdrsp buffer physical 1428 /* Write the lower 32bits of the cmdrsp buffer physical
1018 address */ 1429 address */
1019 if (mwifiex_write_reg(adapter, REG_CMDRSP_ADDR_LO, 1430 if (mwifiex_write_reg(adapter, reg->cmdrsp_addr_lo,
1020 (u32)*cmdrsp_buf_pa)) { 1431 (u32)cmdrsp_buf_pa)) {
1021 dev_err(adapter->dev, 1432 dev_err(adapter->dev,
1022 "Failed to write download cmd to boot code.\n"); 1433 "Failed to write download cmd to boot code.\n");
1023 ret = -1; 1434 ret = -1;
@@ -1025,8 +1436,8 @@ mwifiex_pcie_send_cmd(struct mwifiex_adapter *adapter, struct sk_buff *skb)
1025 } 1436 }
1026 /* Write the upper 32bits of the cmdrsp buffer physical 1437 /* Write the upper 32bits of the cmdrsp buffer physical
1027 address */ 1438 address */
1028 if (mwifiex_write_reg(adapter, REG_CMDRSP_ADDR_HI, 1439 if (mwifiex_write_reg(adapter, reg->cmdrsp_addr_hi,
1029 (u32)((u64)*cmdrsp_buf_pa >> 32))) { 1440 (u32)((u64)cmdrsp_buf_pa >> 32))) {
1030 dev_err(adapter->dev, 1441 dev_err(adapter->dev,
1031 "Failed to write download cmd to boot code.\n"); 1442 "Failed to write download cmd to boot code.\n");
1032 ret = -1; 1443 ret = -1;
@@ -1034,27 +1445,29 @@ mwifiex_pcie_send_cmd(struct mwifiex_adapter *adapter, struct sk_buff *skb)
1034 } 1445 }
1035 } 1446 }
1036 1447
1037 cmd_buf_pa = MWIFIEX_SKB_PACB(card->cmd_buf); 1448 MWIFIEX_SKB_PACB(card->cmd_buf, &cmd_buf_pa);
1038 /* Write the lower 32bits of the physical address to REG_CMD_ADDR_LO */ 1449 /* Write the lower 32bits of the physical address to reg->cmd_addr_lo */
1039 if (mwifiex_write_reg(adapter, REG_CMD_ADDR_LO, (u32)*cmd_buf_pa)) { 1450 if (mwifiex_write_reg(adapter, reg->cmd_addr_lo,
1451 (u32)cmd_buf_pa)) {
1040 dev_err(adapter->dev, 1452 dev_err(adapter->dev,
1041 "Failed to write download cmd to boot code.\n"); 1453 "Failed to write download cmd to boot code.\n");
1042 ret = -1; 1454 ret = -1;
1043 goto done; 1455 goto done;
1044 } 1456 }
1045 /* Write the upper 32bits of the physical address to REG_CMD_ADDR_HI */ 1457 /* Write the upper 32bits of the physical address to reg->cmd_addr_hi */
1046 if (mwifiex_write_reg(adapter, REG_CMD_ADDR_HI, 1458 if (mwifiex_write_reg(adapter, reg->cmd_addr_hi,
1047 (u32)((u64)*cmd_buf_pa >> 32))) { 1459 (u32)((u64)cmd_buf_pa >> 32))) {
1048 dev_err(adapter->dev, 1460 dev_err(adapter->dev,
1049 "Failed to write download cmd to boot code.\n"); 1461 "Failed to write download cmd to boot code.\n");
1050 ret = -1; 1462 ret = -1;
1051 goto done; 1463 goto done;
1052 } 1464 }
1053 1465
1054 /* Write the command length to REG_CMD_SIZE */ 1466 /* Write the command length to reg->cmd_size */
1055 if (mwifiex_write_reg(adapter, REG_CMD_SIZE, card->cmd_buf->len)) { 1467 if (mwifiex_write_reg(adapter, reg->cmd_size,
1468 card->cmd_buf->len)) {
1056 dev_err(adapter->dev, 1469 dev_err(adapter->dev,
1057 "Failed to write cmd len to REG_CMD_SIZE\n"); 1470 "Failed to write cmd len to reg->cmd_size\n");
1058 ret = -1; 1471 ret = -1;
1059 goto done; 1472 goto done;
1060 } 1473 }
@@ -1081,18 +1494,30 @@ done:
1081static int mwifiex_pcie_process_cmd_complete(struct mwifiex_adapter *adapter) 1494static int mwifiex_pcie_process_cmd_complete(struct mwifiex_adapter *adapter)
1082{ 1495{
1083 struct pcie_service_card *card = adapter->card; 1496 struct pcie_service_card *card = adapter->card;
1497 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
1084 struct sk_buff *skb = card->cmdrsp_buf; 1498 struct sk_buff *skb = card->cmdrsp_buf;
1085 int count = 0; 1499 int count = 0;
1500 u16 rx_len;
1501 __le16 pkt_len;
1502 dma_addr_t buf_pa;
1086 1503
1087 dev_dbg(adapter->dev, "info: Rx CMD Response\n"); 1504 dev_dbg(adapter->dev, "info: Rx CMD Response\n");
1088 1505
1506 MWIFIEX_SKB_PACB(skb, &buf_pa);
1507 pci_unmap_single(card->dev, buf_pa, MWIFIEX_UPLD_SIZE,
1508 PCI_DMA_FROMDEVICE);
1509
1510 pkt_len = *((__le16 *)skb->data);
1511 rx_len = le16_to_cpu(pkt_len);
1512 skb_trim(skb, rx_len);
1513 skb_pull(skb, INTF_HEADER_LEN);
1514
1089 if (!adapter->curr_cmd) { 1515 if (!adapter->curr_cmd) {
1090 skb_pull(skb, INTF_HEADER_LEN);
1091 if (adapter->ps_state == PS_STATE_SLEEP_CFM) { 1516 if (adapter->ps_state == PS_STATE_SLEEP_CFM) {
1092 mwifiex_process_sleep_confirm_resp(adapter, skb->data, 1517 mwifiex_process_sleep_confirm_resp(adapter, skb->data,
1093 skb->len); 1518 skb->len);
1094 while (mwifiex_pcie_ok_to_access_hw(adapter) && 1519 while (reg->sleep_cookie && (count++ < 10) &&
1095 (count++ < 10)) 1520 mwifiex_pcie_ok_to_access_hw(adapter))
1096 usleep_range(50, 60); 1521 usleep_range(50, 60);
1097 } else { 1522 } else {
1098 dev_err(adapter->dev, 1523 dev_err(adapter->dev,
@@ -1100,9 +1525,12 @@ static int mwifiex_pcie_process_cmd_complete(struct mwifiex_adapter *adapter)
1100 } 1525 }
1101 memcpy(adapter->upld_buf, skb->data, 1526 memcpy(adapter->upld_buf, skb->data,
1102 min_t(u32, MWIFIEX_SIZE_OF_CMD_BUFFER, skb->len)); 1527 min_t(u32, MWIFIEX_SIZE_OF_CMD_BUFFER, skb->len));
1103 skb_push(skb, INTF_HEADER_LEN); 1528 if (mwifiex_map_pci_memory(adapter, skb, MWIFIEX_UPLD_SIZE,
1529 PCI_DMA_FROMDEVICE))
1530 return -1;
1531
1532 MWIFIEX_SKB_PACB(skb, &buf_pa);
1104 } else if (mwifiex_pcie_ok_to_access_hw(adapter)) { 1533 } else if (mwifiex_pcie_ok_to_access_hw(adapter)) {
1105 skb_pull(skb, INTF_HEADER_LEN);
1106 adapter->curr_cmd->resp_skb = skb; 1534 adapter->curr_cmd->resp_skb = skb;
1107 adapter->cmd_resp_received = true; 1535 adapter->cmd_resp_received = true;
1108 /* Take the pointer and set it to CMD node and will 1536 /* Take the pointer and set it to CMD node and will
@@ -1112,14 +1540,14 @@ static int mwifiex_pcie_process_cmd_complete(struct mwifiex_adapter *adapter)
1112 /* Clear the cmd-rsp buffer address in scratch registers. This 1540 /* Clear the cmd-rsp buffer address in scratch registers. This
1113 will prevent firmware from writing to the same response 1541 will prevent firmware from writing to the same response
1114 buffer again. */ 1542 buffer again. */
1115 if (mwifiex_write_reg(adapter, REG_CMDRSP_ADDR_LO, 0)) { 1543 if (mwifiex_write_reg(adapter, reg->cmdrsp_addr_lo, 0)) {
1116 dev_err(adapter->dev, 1544 dev_err(adapter->dev,
1117 "cmd_done: failed to clear cmd_rsp_addr_lo\n"); 1545 "cmd_done: failed to clear cmd_rsp_addr_lo\n");
1118 return -1; 1546 return -1;
1119 } 1547 }
1120 /* Write the upper 32bits of the cmdrsp buffer physical 1548 /* Write the upper 32bits of the cmdrsp buffer physical
1121 address */ 1549 address */
1122 if (mwifiex_write_reg(adapter, REG_CMDRSP_ADDR_HI, 0)) { 1550 if (mwifiex_write_reg(adapter, reg->cmdrsp_addr_hi, 0)) {
1123 dev_err(adapter->dev, 1551 dev_err(adapter->dev,
1124 "cmd_done: failed to clear cmd_rsp_addr_hi\n"); 1552 "cmd_done: failed to clear cmd_rsp_addr_hi\n");
1125 return -1; 1553 return -1;
@@ -1136,10 +1564,23 @@ static int mwifiex_pcie_cmdrsp_complete(struct mwifiex_adapter *adapter,
1136 struct sk_buff *skb) 1564 struct sk_buff *skb)
1137{ 1565{
1138 struct pcie_service_card *card = adapter->card; 1566 struct pcie_service_card *card = adapter->card;
1567 dma_addr_t buf_pa;
1568 struct sk_buff *skb_tmp;
1139 1569
1140 if (skb) { 1570 if (skb) {
1141 card->cmdrsp_buf = skb; 1571 card->cmdrsp_buf = skb;
1142 skb_push(card->cmdrsp_buf, INTF_HEADER_LEN); 1572 skb_push(card->cmdrsp_buf, INTF_HEADER_LEN);
1573 if (mwifiex_map_pci_memory(adapter, skb, MWIFIEX_UPLD_SIZE,
1574 PCI_DMA_FROMDEVICE))
1575 return -1;
1576 }
1577
1578 skb_tmp = card->cmd_buf;
1579 if (skb_tmp) {
1580 MWIFIEX_SKB_PACB(skb_tmp, &buf_pa);
1581 pci_unmap_single(card->dev, buf_pa, MWIFIEX_UPLD_SIZE,
1582 PCI_DMA_FROMDEVICE);
1583 card->cmd_buf = NULL;
1143 } 1584 }
1144 1585
1145 return 0; 1586 return 0;
@@ -1151,8 +1592,14 @@ static int mwifiex_pcie_cmdrsp_complete(struct mwifiex_adapter *adapter,
1151static int mwifiex_pcie_process_event_ready(struct mwifiex_adapter *adapter) 1592static int mwifiex_pcie_process_event_ready(struct mwifiex_adapter *adapter)
1152{ 1593{
1153 struct pcie_service_card *card = adapter->card; 1594 struct pcie_service_card *card = adapter->card;
1595 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
1154 u32 rdptr = card->evtbd_rdptr & MWIFIEX_EVTBD_MASK; 1596 u32 rdptr = card->evtbd_rdptr & MWIFIEX_EVTBD_MASK;
1155 u32 wrptr, event; 1597 u32 wrptr, event;
1598 dma_addr_t buf_pa;
1599 struct mwifiex_evt_buf_desc *desc;
1600
1601 if (!mwifiex_pcie_ok_to_access_hw(adapter))
1602 mwifiex_pm_wakeup_card(adapter);
1156 1603
1157 if (adapter->event_received) { 1604 if (adapter->event_received) {
1158 dev_dbg(adapter->dev, "info: Event being processed, " 1605 dev_dbg(adapter->dev, "info: Event being processed, "
@@ -1166,9 +1613,9 @@ static int mwifiex_pcie_process_event_ready(struct mwifiex_adapter *adapter)
1166 } 1613 }
1167 1614
1168 /* Read the event ring write pointer set by firmware */ 1615 /* Read the event ring write pointer set by firmware */
1169 if (mwifiex_read_reg(adapter, REG_EVTBD_WRPTR, &wrptr)) { 1616 if (mwifiex_read_reg(adapter, reg->evt_wrptr, &wrptr)) {
1170 dev_err(adapter->dev, 1617 dev_err(adapter->dev,
1171 "EventReady: failed to read REG_EVTBD_WRPTR\n"); 1618 "EventReady: failed to read reg->evt_wrptr\n");
1172 return -1; 1619 return -1;
1173 } 1620 }
1174 1621
@@ -1176,20 +1623,23 @@ static int mwifiex_pcie_process_event_ready(struct mwifiex_adapter *adapter)
1176 card->evtbd_rdptr, wrptr); 1623 card->evtbd_rdptr, wrptr);
1177 if (((wrptr & MWIFIEX_EVTBD_MASK) != (card->evtbd_rdptr 1624 if (((wrptr & MWIFIEX_EVTBD_MASK) != (card->evtbd_rdptr
1178 & MWIFIEX_EVTBD_MASK)) || 1625 & MWIFIEX_EVTBD_MASK)) ||
1179 ((wrptr & MWIFIEX_BD_FLAG_ROLLOVER_IND) == 1626 ((wrptr & reg->evt_rollover_ind) ==
1180 (card->evtbd_rdptr & MWIFIEX_BD_FLAG_ROLLOVER_IND))) { 1627 (card->evtbd_rdptr & reg->evt_rollover_ind))) {
1181 struct sk_buff *skb_cmd; 1628 struct sk_buff *skb_cmd;
1182 __le16 data_len = 0; 1629 __le16 data_len = 0;
1183 u16 evt_len; 1630 u16 evt_len;
1184 1631
1185 dev_dbg(adapter->dev, "info: Read Index: %d\n", rdptr); 1632 dev_dbg(adapter->dev, "info: Read Index: %d\n", rdptr);
1186 skb_cmd = card->evt_buf_list[rdptr]; 1633 skb_cmd = card->evt_buf_list[rdptr];
1634 MWIFIEX_SKB_PACB(skb_cmd, &buf_pa);
1635 pci_unmap_single(card->dev, buf_pa, MAX_EVENT_SIZE,
1636 PCI_DMA_FROMDEVICE);
1637
1187 /* Take the pointer and set it to event pointer in adapter 1638 /* Take the pointer and set it to event pointer in adapter
1188 and will return back after event handling callback */ 1639 and will return back after event handling callback */
1189 card->evt_buf_list[rdptr] = NULL; 1640 card->evt_buf_list[rdptr] = NULL;
1190 card->evtbd_ring[rdptr]->paddr = 0; 1641 desc = card->evtbd_ring[rdptr];
1191 card->evtbd_ring[rdptr]->len = 0; 1642 memset(desc, 0, sizeof(*desc));
1192 card->evtbd_ring[rdptr]->flags = 0;
1193 1643
1194 event = *(u32 *) &skb_cmd->data[INTF_HEADER_LEN]; 1644 event = *(u32 *) &skb_cmd->data[INTF_HEADER_LEN];
1195 adapter->event_cause = event; 1645 adapter->event_cause = event;
@@ -1225,10 +1675,12 @@ static int mwifiex_pcie_event_complete(struct mwifiex_adapter *adapter,
1225 struct sk_buff *skb) 1675 struct sk_buff *skb)
1226{ 1676{
1227 struct pcie_service_card *card = adapter->card; 1677 struct pcie_service_card *card = adapter->card;
1678 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
1228 int ret = 0; 1679 int ret = 0;
1229 u32 rdptr = card->evtbd_rdptr & MWIFIEX_EVTBD_MASK; 1680 u32 rdptr = card->evtbd_rdptr & MWIFIEX_EVTBD_MASK;
1230 u32 wrptr; 1681 u32 wrptr;
1231 phys_addr_t *buf_pa; 1682 dma_addr_t buf_pa;
1683 struct mwifiex_evt_buf_desc *desc;
1232 1684
1233 if (!skb) 1685 if (!skb)
1234 return 0; 1686 return 0;
@@ -1240,19 +1692,25 @@ static int mwifiex_pcie_event_complete(struct mwifiex_adapter *adapter,
1240 } 1692 }
1241 1693
1242 /* Read the event ring write pointer set by firmware */ 1694 /* Read the event ring write pointer set by firmware */
1243 if (mwifiex_read_reg(adapter, REG_EVTBD_WRPTR, &wrptr)) { 1695 if (mwifiex_read_reg(adapter, reg->evt_wrptr, &wrptr)) {
1244 dev_err(adapter->dev, 1696 dev_err(adapter->dev,
1245 "event_complete: failed to read REG_EVTBD_WRPTR\n"); 1697 "event_complete: failed to read reg->evt_wrptr\n");
1246 return -1; 1698 return -1;
1247 } 1699 }
1248 1700
1249 if (!card->evt_buf_list[rdptr]) { 1701 if (!card->evt_buf_list[rdptr]) {
1250 skb_push(skb, INTF_HEADER_LEN); 1702 skb_push(skb, INTF_HEADER_LEN);
1703 if (mwifiex_map_pci_memory(adapter, skb,
1704 MAX_EVENT_SIZE,
1705 PCI_DMA_FROMDEVICE))
1706 return -1;
1707 MWIFIEX_SKB_PACB(skb, &buf_pa);
1251 card->evt_buf_list[rdptr] = skb; 1708 card->evt_buf_list[rdptr] = skb;
1252 buf_pa = MWIFIEX_SKB_PACB(skb); 1709 MWIFIEX_SKB_PACB(skb, &buf_pa);
1253 card->evtbd_ring[rdptr]->paddr = *buf_pa; 1710 desc = card->evtbd_ring[rdptr];
1254 card->evtbd_ring[rdptr]->len = (u16)skb->len; 1711 desc->paddr = buf_pa;
1255 card->evtbd_ring[rdptr]->flags = 0; 1712 desc->len = (u16)skb->len;
1713 desc->flags = 0;
1256 skb = NULL; 1714 skb = NULL;
1257 } else { 1715 } else {
1258 dev_dbg(adapter->dev, 1716 dev_dbg(adapter->dev,
@@ -1262,17 +1720,18 @@ static int mwifiex_pcie_event_complete(struct mwifiex_adapter *adapter,
1262 1720
1263 if ((++card->evtbd_rdptr & MWIFIEX_EVTBD_MASK) == MWIFIEX_MAX_EVT_BD) { 1721 if ((++card->evtbd_rdptr & MWIFIEX_EVTBD_MASK) == MWIFIEX_MAX_EVT_BD) {
1264 card->evtbd_rdptr = ((card->evtbd_rdptr & 1722 card->evtbd_rdptr = ((card->evtbd_rdptr &
1265 MWIFIEX_BD_FLAG_ROLLOVER_IND) ^ 1723 reg->evt_rollover_ind) ^
1266 MWIFIEX_BD_FLAG_ROLLOVER_IND); 1724 reg->evt_rollover_ind);
1267 } 1725 }
1268 1726
1269 dev_dbg(adapter->dev, "info: Updated <Rd: 0x%x, Wr: 0x%x>", 1727 dev_dbg(adapter->dev, "info: Updated <Rd: 0x%x, Wr: 0x%x>",
1270 card->evtbd_rdptr, wrptr); 1728 card->evtbd_rdptr, wrptr);
1271 1729
1272 /* Write the event ring read pointer in to REG_EVTBD_RDPTR */ 1730 /* Write the event ring read pointer in to reg->evt_rdptr */
1273 if (mwifiex_write_reg(adapter, REG_EVTBD_RDPTR, card->evtbd_rdptr)) { 1731 if (mwifiex_write_reg(adapter, reg->evt_rdptr,
1732 card->evtbd_rdptr)) {
1274 dev_err(adapter->dev, 1733 dev_err(adapter->dev,
1275 "event_complete: failed to read REG_EVTBD_RDPTR\n"); 1734 "event_complete: failed to read reg->evt_rdptr\n");
1276 return -1; 1735 return -1;
1277 } 1736 }
1278 1737
@@ -1299,11 +1758,9 @@ static int mwifiex_prog_fw_w_helper(struct mwifiex_adapter *adapter,
1299 struct sk_buff *skb; 1758 struct sk_buff *skb;
1300 u32 txlen, tx_blocks = 0, tries, len; 1759 u32 txlen, tx_blocks = 0, tries, len;
1301 u32 block_retry_cnt = 0; 1760 u32 block_retry_cnt = 0;
1302 1761 dma_addr_t buf_pa;
1303 if (!adapter) { 1762 struct pcie_service_card *card = adapter->card;
1304 pr_err("adapter structure is not valid\n"); 1763 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
1305 return -1;
1306 }
1307 1764
1308 if (!firmware || !firmware_len) { 1765 if (!firmware || !firmware_len) {
1309 dev_err(adapter->dev, 1766 dev_err(adapter->dev,
@@ -1325,7 +1782,6 @@ static int mwifiex_prog_fw_w_helper(struct mwifiex_adapter *adapter,
1325 ret = -ENOMEM; 1782 ret = -ENOMEM;
1326 goto done; 1783 goto done;
1327 } 1784 }
1328 mwifiex_update_sk_buff_pa(skb);
1329 1785
1330 /* Perform firmware data transfer */ 1786 /* Perform firmware data transfer */
1331 do { 1787 do {
@@ -1336,7 +1792,7 @@ static int mwifiex_prog_fw_w_helper(struct mwifiex_adapter *adapter,
1336 break; 1792 break;
1337 1793
1338 for (tries = 0; tries < MAX_POLL_TRIES; tries++) { 1794 for (tries = 0; tries < MAX_POLL_TRIES; tries++) {
1339 ret = mwifiex_read_reg(adapter, PCIE_SCRATCH_2_REG, 1795 ret = mwifiex_read_reg(adapter, reg->cmd_size,
1340 &len); 1796 &len);
1341 if (ret) { 1797 if (ret) {
1342 dev_warn(adapter->dev, 1798 dev_warn(adapter->dev,
@@ -1382,16 +1838,15 @@ static int mwifiex_prog_fw_w_helper(struct mwifiex_adapter *adapter,
1382 1838
1383 dev_dbg(adapter->dev, "."); 1839 dev_dbg(adapter->dev, ".");
1384 1840
1385 tx_blocks = (txlen + 1841 tx_blocks = (txlen + card->pcie.blksz_fw_dl - 1) /
1386 MWIFIEX_PCIE_BLOCK_SIZE_FW_DNLD - 1) / 1842 card->pcie.blksz_fw_dl;
1387 MWIFIEX_PCIE_BLOCK_SIZE_FW_DNLD;
1388 1843
1389 /* Copy payload to buffer */ 1844 /* Copy payload to buffer */
1390 memmove(skb->data, &firmware[offset], txlen); 1845 memmove(skb->data, &firmware[offset], txlen);
1391 } 1846 }
1392 1847
1393 skb_put(skb, MWIFIEX_UPLD_SIZE - skb->len); 1848 skb_put(skb, MWIFIEX_UPLD_SIZE - skb->len);
1394 skb_trim(skb, tx_blocks * MWIFIEX_PCIE_BLOCK_SIZE_FW_DNLD); 1849 skb_trim(skb, tx_blocks * card->pcie.blksz_fw_dl);
1395 1850
1396 /* Send the boot command to device */ 1851 /* Send the boot command to device */
1397 if (mwifiex_pcie_send_boot_cmd(adapter, skb)) { 1852 if (mwifiex_pcie_send_boot_cmd(adapter, skb)) {
@@ -1400,6 +1855,9 @@ static int mwifiex_prog_fw_w_helper(struct mwifiex_adapter *adapter,
1400 ret = -1; 1855 ret = -1;
1401 goto done; 1856 goto done;
1402 } 1857 }
1858
1859 MWIFIEX_SKB_PACB(skb, &buf_pa);
1860
1403 /* Wait for the command done interrupt */ 1861 /* Wait for the command done interrupt */
1404 do { 1862 do {
1405 if (mwifiex_read_reg(adapter, PCIE_CPU_INT_STATUS, 1863 if (mwifiex_read_reg(adapter, PCIE_CPU_INT_STATUS,
@@ -1407,11 +1865,17 @@ static int mwifiex_prog_fw_w_helper(struct mwifiex_adapter *adapter,
1407 dev_err(adapter->dev, "%s: Failed to read " 1865 dev_err(adapter->dev, "%s: Failed to read "
1408 "interrupt status during fw dnld.\n", 1866 "interrupt status during fw dnld.\n",
1409 __func__); 1867 __func__);
1868 pci_unmap_single(card->dev, buf_pa, skb->len,
1869 PCI_DMA_TODEVICE);
1410 ret = -1; 1870 ret = -1;
1411 goto done; 1871 goto done;
1412 } 1872 }
1413 } while ((ireg_intr & CPU_INTR_DOOR_BELL) == 1873 } while ((ireg_intr & CPU_INTR_DOOR_BELL) ==
1414 CPU_INTR_DOOR_BELL); 1874 CPU_INTR_DOOR_BELL);
1875
1876 pci_unmap_single(card->dev, buf_pa, skb->len,
1877 PCI_DMA_TODEVICE);
1878
1415 offset += txlen; 1879 offset += txlen;
1416 } while (true); 1880 } while (true);
1417 1881
@@ -1435,6 +1899,8 @@ mwifiex_check_fw_status(struct mwifiex_adapter *adapter, u32 poll_num)
1435{ 1899{
1436 int ret = 0; 1900 int ret = 0;
1437 u32 firmware_stat, winner_status; 1901 u32 firmware_stat, winner_status;
1902 struct pcie_service_card *card = adapter->card;
1903 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
1438 u32 tries; 1904 u32 tries;
1439 1905
1440 /* Mask spurios interrupts */ 1906 /* Mask spurios interrupts */
@@ -1445,7 +1911,8 @@ mwifiex_check_fw_status(struct mwifiex_adapter *adapter, u32 poll_num)
1445 } 1911 }
1446 1912
1447 dev_dbg(adapter->dev, "Setting driver ready signature\n"); 1913 dev_dbg(adapter->dev, "Setting driver ready signature\n");
1448 if (mwifiex_write_reg(adapter, REG_DRV_READY, FIRMWARE_READY_PCIE)) { 1914 if (mwifiex_write_reg(adapter, reg->drv_rdy,
1915 FIRMWARE_READY_PCIE)) {
1449 dev_err(adapter->dev, 1916 dev_err(adapter->dev,
1450 "Failed to write driver ready signature\n"); 1917 "Failed to write driver ready signature\n");
1451 return -1; 1918 return -1;
@@ -1453,7 +1920,7 @@ mwifiex_check_fw_status(struct mwifiex_adapter *adapter, u32 poll_num)
1453 1920
1454 /* Wait for firmware initialization event */ 1921 /* Wait for firmware initialization event */
1455 for (tries = 0; tries < poll_num; tries++) { 1922 for (tries = 0; tries < poll_num; tries++) {
1456 if (mwifiex_read_reg(adapter, PCIE_SCRATCH_3_REG, 1923 if (mwifiex_read_reg(adapter, reg->fw_status,
1457 &firmware_stat)) 1924 &firmware_stat))
1458 ret = -1; 1925 ret = -1;
1459 else 1926 else
@@ -1470,7 +1937,7 @@ mwifiex_check_fw_status(struct mwifiex_adapter *adapter, u32 poll_num)
1470 } 1937 }
1471 1938
1472 if (ret) { 1939 if (ret) {
1473 if (mwifiex_read_reg(adapter, PCIE_SCRATCH_3_REG, 1940 if (mwifiex_read_reg(adapter, reg->fw_status,
1474 &winner_status)) 1941 &winner_status))
1475 ret = -1; 1942 ret = -1;
1476 else if (!winner_status) { 1943 else if (!winner_status) {
@@ -1594,39 +2061,40 @@ exit:
1594static int mwifiex_process_int_status(struct mwifiex_adapter *adapter) 2061static int mwifiex_process_int_status(struct mwifiex_adapter *adapter)
1595{ 2062{
1596 int ret; 2063 int ret;
1597 u32 pcie_ireg = 0; 2064 u32 pcie_ireg;
1598 unsigned long flags; 2065 unsigned long flags;
1599 2066
1600 spin_lock_irqsave(&adapter->int_lock, flags); 2067 spin_lock_irqsave(&adapter->int_lock, flags);
1601 /* Clear out unused interrupts */ 2068 /* Clear out unused interrupts */
1602 adapter->int_status &= HOST_INTR_MASK; 2069 pcie_ireg = adapter->int_status;
2070 adapter->int_status = 0;
1603 spin_unlock_irqrestore(&adapter->int_lock, flags); 2071 spin_unlock_irqrestore(&adapter->int_lock, flags);
1604 2072
1605 while (adapter->int_status & HOST_INTR_MASK) { 2073 while (pcie_ireg & HOST_INTR_MASK) {
1606 if (adapter->int_status & HOST_INTR_DNLD_DONE) { 2074 if (pcie_ireg & HOST_INTR_DNLD_DONE) {
1607 adapter->int_status &= ~HOST_INTR_DNLD_DONE; 2075 pcie_ireg &= ~HOST_INTR_DNLD_DONE;
1608 if (adapter->data_sent) { 2076 dev_dbg(adapter->dev, "info: TX DNLD Done\n");
1609 dev_dbg(adapter->dev, "info: DATA sent intr\n"); 2077 ret = mwifiex_pcie_send_data_complete(adapter);
1610 adapter->data_sent = false; 2078 if (ret)
1611 } 2079 return ret;
1612 } 2080 }
1613 if (adapter->int_status & HOST_INTR_UPLD_RDY) { 2081 if (pcie_ireg & HOST_INTR_UPLD_RDY) {
1614 adapter->int_status &= ~HOST_INTR_UPLD_RDY; 2082 pcie_ireg &= ~HOST_INTR_UPLD_RDY;
1615 dev_dbg(adapter->dev, "info: Rx DATA\n"); 2083 dev_dbg(adapter->dev, "info: Rx DATA\n");
1616 ret = mwifiex_pcie_process_recv_data(adapter); 2084 ret = mwifiex_pcie_process_recv_data(adapter);
1617 if (ret) 2085 if (ret)
1618 return ret; 2086 return ret;
1619 } 2087 }
1620 if (adapter->int_status & HOST_INTR_EVENT_RDY) { 2088 if (pcie_ireg & HOST_INTR_EVENT_RDY) {
1621 adapter->int_status &= ~HOST_INTR_EVENT_RDY; 2089 pcie_ireg &= ~HOST_INTR_EVENT_RDY;
1622 dev_dbg(adapter->dev, "info: Rx EVENT\n"); 2090 dev_dbg(adapter->dev, "info: Rx EVENT\n");
1623 ret = mwifiex_pcie_process_event_ready(adapter); 2091 ret = mwifiex_pcie_process_event_ready(adapter);
1624 if (ret) 2092 if (ret)
1625 return ret; 2093 return ret;
1626 } 2094 }
1627 2095
1628 if (adapter->int_status & HOST_INTR_CMD_DONE) { 2096 if (pcie_ireg & HOST_INTR_CMD_DONE) {
1629 adapter->int_status &= ~HOST_INTR_CMD_DONE; 2097 pcie_ireg &= ~HOST_INTR_CMD_DONE;
1630 if (adapter->cmd_sent) { 2098 if (adapter->cmd_sent) {
1631 dev_dbg(adapter->dev, 2099 dev_dbg(adapter->dev,
1632 "info: CMD sent Interrupt\n"); 2100 "info: CMD sent Interrupt\n");
@@ -1654,8 +2122,6 @@ static int mwifiex_process_int_status(struct mwifiex_adapter *adapter)
1654 "Write register failed\n"); 2122 "Write register failed\n");
1655 return -1; 2123 return -1;
1656 } 2124 }
1657 adapter->int_status |= pcie_ireg;
1658 adapter->int_status &= HOST_INTR_MASK;
1659 } 2125 }
1660 2126
1661 } 2127 }
@@ -1687,7 +2153,7 @@ static int mwifiex_pcie_host_to_card(struct mwifiex_adapter *adapter, u8 type,
1687 } 2153 }
1688 2154
1689 if (type == MWIFIEX_TYPE_DATA) 2155 if (type == MWIFIEX_TYPE_DATA)
1690 return mwifiex_pcie_send_data(adapter, skb); 2156 return mwifiex_pcie_send_data(adapter, skb, tx_param);
1691 else if (type == MWIFIEX_TYPE_CMD) 2157 else if (type == MWIFIEX_TYPE_CMD)
1692 return mwifiex_pcie_send_cmd(adapter, skb); 2158 return mwifiex_pcie_send_cmd(adapter, skb);
1693 2159
@@ -1709,6 +2175,7 @@ static int mwifiex_pcie_init(struct mwifiex_adapter *adapter)
1709 struct pcie_service_card *card = adapter->card; 2175 struct pcie_service_card *card = adapter->card;
1710 int ret; 2176 int ret;
1711 struct pci_dev *pdev = card->dev; 2177 struct pci_dev *pdev = card->dev;
2178 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
1712 2179
1713 pci_set_drvdata(pdev, card); 2180 pci_set_drvdata(pdev, card);
1714 2181
@@ -1739,6 +2206,7 @@ static int mwifiex_pcie_init(struct mwifiex_adapter *adapter)
1739 card->pci_mmap = pci_iomap(pdev, 0, 0); 2206 card->pci_mmap = pci_iomap(pdev, 0, 0);
1740 if (!card->pci_mmap) { 2207 if (!card->pci_mmap) {
1741 dev_err(adapter->dev, "iomap(0) error\n"); 2208 dev_err(adapter->dev, "iomap(0) error\n");
2209 ret = -EIO;
1742 goto err_iomap0; 2210 goto err_iomap0;
1743 } 2211 }
1744 ret = pci_request_region(pdev, 2, DRV_NAME); 2212 ret = pci_request_region(pdev, 2, DRV_NAME);
@@ -1749,6 +2217,7 @@ static int mwifiex_pcie_init(struct mwifiex_adapter *adapter)
1749 card->pci_mmap1 = pci_iomap(pdev, 2, 0); 2217 card->pci_mmap1 = pci_iomap(pdev, 2, 0);
1750 if (!card->pci_mmap1) { 2218 if (!card->pci_mmap1) {
1751 dev_err(adapter->dev, "iomap(2) error\n"); 2219 dev_err(adapter->dev, "iomap(2) error\n");
2220 ret = -EIO;
1752 goto err_iomap2; 2221 goto err_iomap2;
1753 } 2222 }
1754 2223
@@ -1769,10 +2238,13 @@ static int mwifiex_pcie_init(struct mwifiex_adapter *adapter)
1769 ret = mwifiex_pcie_alloc_cmdrsp_buf(adapter); 2238 ret = mwifiex_pcie_alloc_cmdrsp_buf(adapter);
1770 if (ret) 2239 if (ret)
1771 goto err_alloc_cmdbuf; 2240 goto err_alloc_cmdbuf;
1772 ret = mwifiex_pcie_alloc_sleep_cookie_buf(adapter); 2241 if (reg->sleep_cookie) {
1773 if (ret) 2242 ret = mwifiex_pcie_alloc_sleep_cookie_buf(adapter);
1774 goto err_alloc_cookie; 2243 if (ret)
1775 2244 goto err_alloc_cookie;
2245 } else {
2246 card->sleep_cookie_vbase = NULL;
2247 }
1776 return ret; 2248 return ret;
1777 2249
1778err_alloc_cookie: 2250err_alloc_cookie:
@@ -1813,17 +2285,11 @@ static void mwifiex_pcie_cleanup(struct mwifiex_adapter *adapter)
1813{ 2285{
1814 struct pcie_service_card *card = adapter->card; 2286 struct pcie_service_card *card = adapter->card;
1815 struct pci_dev *pdev = card->dev; 2287 struct pci_dev *pdev = card->dev;
2288 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
1816 2289
1817 mwifiex_pcie_delete_sleep_cookie_buf(adapter);
1818 mwifiex_pcie_delete_cmdrsp_buf(adapter);
1819 mwifiex_pcie_delete_evtbd_ring(adapter);
1820 mwifiex_pcie_delete_rxbd_ring(adapter);
1821 mwifiex_pcie_delete_txbd_ring(adapter);
1822 card->cmdrsp_buf = NULL;
1823
1824 dev_dbg(adapter->dev, "Clearing driver ready signature\n");
1825 if (user_rmmod) { 2290 if (user_rmmod) {
1826 if (mwifiex_write_reg(adapter, REG_DRV_READY, 0x00000000)) 2291 dev_dbg(adapter->dev, "Clearing driver ready signature\n");
2292 if (mwifiex_write_reg(adapter, reg->drv_rdy, 0x00000000))
1827 dev_err(adapter->dev, 2293 dev_err(adapter->dev,
1828 "Failed to write driver not-ready signature\n"); 2294 "Failed to write driver not-ready signature\n");
1829 } 2295 }
@@ -1861,7 +2327,7 @@ static int mwifiex_register_dev(struct mwifiex_adapter *adapter)
1861 } 2327 }
1862 2328
1863 adapter->dev = &pdev->dev; 2329 adapter->dev = &pdev->dev;
1864 strcpy(adapter->fw_name, PCIE8766_DEFAULT_FW_NAME); 2330 strcpy(adapter->fw_name, card->pcie.firmware);
1865 2331
1866 return 0; 2332 return 0;
1867} 2333}
@@ -1875,10 +2341,21 @@ static int mwifiex_register_dev(struct mwifiex_adapter *adapter)
1875static void mwifiex_unregister_dev(struct mwifiex_adapter *adapter) 2341static void mwifiex_unregister_dev(struct mwifiex_adapter *adapter)
1876{ 2342{
1877 struct pcie_service_card *card = adapter->card; 2343 struct pcie_service_card *card = adapter->card;
2344 const struct mwifiex_pcie_card_reg *reg;
1878 2345
1879 if (card) { 2346 if (card) {
1880 dev_dbg(adapter->dev, "%s(): calling free_irq()\n", __func__); 2347 dev_dbg(adapter->dev, "%s(): calling free_irq()\n", __func__);
1881 free_irq(card->dev->irq, card->dev); 2348 free_irq(card->dev->irq, card->dev);
2349
2350 reg = card->pcie.reg;
2351 if (reg->sleep_cookie)
2352 mwifiex_pcie_delete_sleep_cookie_buf(adapter);
2353
2354 mwifiex_pcie_delete_cmdrsp_buf(adapter);
2355 mwifiex_pcie_delete_evtbd_ring(adapter);
2356 mwifiex_pcie_delete_rxbd_ring(adapter);
2357 mwifiex_pcie_delete_txbd_ring(adapter);
2358 card->cmdrsp_buf = NULL;
1882 } 2359 }
1883} 2360}
1884 2361
@@ -1900,6 +2377,8 @@ static struct mwifiex_if_ops pcie_ops = {
1900 .event_complete = mwifiex_pcie_event_complete, 2377 .event_complete = mwifiex_pcie_event_complete,
1901 .update_mp_end_port = NULL, 2378 .update_mp_end_port = NULL,
1902 .cleanup_mpa_buf = NULL, 2379 .cleanup_mpa_buf = NULL,
2380 .init_fw_port = mwifiex_pcie_init_fw_port,
2381 .clean_pcie_ring = mwifiex_clean_pcie_ring_buf,
1903}; 2382};
1904 2383
1905/* 2384/*
@@ -1912,7 +2391,7 @@ static int mwifiex_pcie_init_module(void)
1912{ 2391{
1913 int ret; 2392 int ret;
1914 2393
1915 pr_debug("Marvell 8766 PCIe Driver\n"); 2394 pr_debug("Marvell PCIe Driver\n");
1916 2395
1917 sema_init(&add_remove_card_sem, 1); 2396 sema_init(&add_remove_card_sem, 1);
1918 2397
@@ -1955,4 +2434,5 @@ MODULE_AUTHOR("Marvell International Ltd.");
1955MODULE_DESCRIPTION("Marvell WiFi-Ex PCI-Express Driver version " PCIE_VERSION); 2434MODULE_DESCRIPTION("Marvell WiFi-Ex PCI-Express Driver version " PCIE_VERSION);
1956MODULE_VERSION(PCIE_VERSION); 2435MODULE_VERSION(PCIE_VERSION);
1957MODULE_LICENSE("GPL v2"); 2436MODULE_LICENSE("GPL v2");
1958MODULE_FIRMWARE("mrvl/pcie8766_uapsta.bin"); 2437MODULE_FIRMWARE(PCIE8766_DEFAULT_FW_NAME);
2438MODULE_FIRMWARE(PCIE8897_DEFAULT_FW_NAME);
diff --git a/drivers/net/wireless/mwifiex/pcie.h b/drivers/net/wireless/mwifiex/pcie.h
index 2f218f9a3fd3..d322ab8604ea 100644
--- a/drivers/net/wireless/mwifiex/pcie.h
+++ b/drivers/net/wireless/mwifiex/pcie.h
@@ -29,6 +29,11 @@
29#include "main.h" 29#include "main.h"
30 30
31#define PCIE8766_DEFAULT_FW_NAME "mrvl/pcie8766_uapsta.bin" 31#define PCIE8766_DEFAULT_FW_NAME "mrvl/pcie8766_uapsta.bin"
32#define PCIE8897_DEFAULT_FW_NAME "mrvl/pcie8897_uapsta.bin"
33
34#define PCIE_VENDOR_ID_MARVELL (0x11ab)
35#define PCIE_DEVICE_ID_MARVELL_88W8766P (0x2b30)
36#define PCIE_DEVICE_ID_MARVELL_88W8897 (0x2b38)
32 37
33/* Constants for Buffer Descriptor (BD) rings */ 38/* Constants for Buffer Descriptor (BD) rings */
34#define MWIFIEX_MAX_TXRX_BD 0x20 39#define MWIFIEX_MAX_TXRX_BD 0x20
@@ -57,6 +62,8 @@
57#define PCIE_SCRATCH_10_REG 0xCE8 62#define PCIE_SCRATCH_10_REG 0xCE8
58#define PCIE_SCRATCH_11_REG 0xCEC 63#define PCIE_SCRATCH_11_REG 0xCEC
59#define PCIE_SCRATCH_12_REG 0xCF0 64#define PCIE_SCRATCH_12_REG 0xCF0
65#define PCIE_RD_DATA_PTR_Q0_Q1 0xC08C
66#define PCIE_WR_DATA_PTR_Q0_Q1 0xC05C
60 67
61#define CPU_INTR_DNLD_RDY BIT(0) 68#define CPU_INTR_DNLD_RDY BIT(0)
62#define CPU_INTR_DOOR_BELL BIT(1) 69#define CPU_INTR_DOOR_BELL BIT(1)
@@ -75,27 +82,14 @@
75#define MWIFIEX_BD_FLAG_ROLLOVER_IND BIT(7) 82#define MWIFIEX_BD_FLAG_ROLLOVER_IND BIT(7)
76#define MWIFIEX_BD_FLAG_FIRST_DESC BIT(0) 83#define MWIFIEX_BD_FLAG_FIRST_DESC BIT(0)
77#define MWIFIEX_BD_FLAG_LAST_DESC BIT(1) 84#define MWIFIEX_BD_FLAG_LAST_DESC BIT(1)
78#define REG_CMD_ADDR_LO PCIE_SCRATCH_0_REG 85#define MWIFIEX_BD_FLAG_SOP BIT(0)
79#define REG_CMD_ADDR_HI PCIE_SCRATCH_1_REG 86#define MWIFIEX_BD_FLAG_EOP BIT(1)
80#define REG_CMD_SIZE PCIE_SCRATCH_2_REG 87#define MWIFIEX_BD_FLAG_XS_SOP BIT(2)
81 88#define MWIFIEX_BD_FLAG_XS_EOP BIT(3)
82#define REG_CMDRSP_ADDR_LO PCIE_SCRATCH_4_REG 89#define MWIFIEX_BD_FLAG_EVT_ROLLOVER_IND BIT(7)
83#define REG_CMDRSP_ADDR_HI PCIE_SCRATCH_5_REG 90#define MWIFIEX_BD_FLAG_RX_ROLLOVER_IND BIT(10)
84 91#define MWIFIEX_BD_FLAG_TX_START_PTR BIT(16)
85/* TX buffer description read pointer */ 92#define MWIFIEX_BD_FLAG_TX_ROLLOVER_IND BIT(26)
86#define REG_TXBD_RDPTR PCIE_SCRATCH_6_REG
87/* TX buffer description write pointer */
88#define REG_TXBD_WRPTR PCIE_SCRATCH_7_REG
89/* RX buffer description read pointer */
90#define REG_RXBD_RDPTR PCIE_SCRATCH_8_REG
91/* RX buffer description write pointer */
92#define REG_RXBD_WRPTR PCIE_SCRATCH_9_REG
93/* Event buffer description read pointer */
94#define REG_EVTBD_RDPTR PCIE_SCRATCH_10_REG
95/* Event buffer description write pointer */
96#define REG_EVTBD_WRPTR PCIE_SCRATCH_11_REG
97/* Driver ready signature write pointer */
98#define REG_DRV_READY PCIE_SCRATCH_12_REG
99 93
100/* Max retry number of command write */ 94/* Max retry number of command write */
101#define MAX_WRITE_IOMEM_RETRY 2 95#define MAX_WRITE_IOMEM_RETRY 2
@@ -104,45 +98,223 @@
104/* FW awake cookie after FW ready */ 98/* FW awake cookie after FW ready */
105#define FW_AWAKE_COOKIE (0xAA55AA55) 99#define FW_AWAKE_COOKIE (0xAA55AA55)
106 100
101struct mwifiex_pcie_card_reg {
102 u16 cmd_addr_lo;
103 u16 cmd_addr_hi;
104 u16 fw_status;
105 u16 cmd_size;
106 u16 cmdrsp_addr_lo;
107 u16 cmdrsp_addr_hi;
108 u16 tx_rdptr;
109 u16 tx_wrptr;
110 u16 rx_rdptr;
111 u16 rx_wrptr;
112 u16 evt_rdptr;
113 u16 evt_wrptr;
114 u16 drv_rdy;
115 u16 tx_start_ptr;
116 u32 tx_mask;
117 u32 tx_wrap_mask;
118 u32 rx_mask;
119 u32 rx_wrap_mask;
120 u32 tx_rollover_ind;
121 u32 rx_rollover_ind;
122 u32 evt_rollover_ind;
123 u8 ring_flag_sop;
124 u8 ring_flag_eop;
125 u8 ring_flag_xs_sop;
126 u8 ring_flag_xs_eop;
127 u32 ring_tx_start_ptr;
128 u8 pfu_enabled;
129 u8 sleep_cookie;
130};
131
132static const struct mwifiex_pcie_card_reg mwifiex_reg_8766 = {
133 .cmd_addr_lo = PCIE_SCRATCH_0_REG,
134 .cmd_addr_hi = PCIE_SCRATCH_1_REG,
135 .cmd_size = PCIE_SCRATCH_2_REG,
136 .fw_status = PCIE_SCRATCH_3_REG,
137 .cmdrsp_addr_lo = PCIE_SCRATCH_4_REG,
138 .cmdrsp_addr_hi = PCIE_SCRATCH_5_REG,
139 .tx_rdptr = PCIE_SCRATCH_6_REG,
140 .tx_wrptr = PCIE_SCRATCH_7_REG,
141 .rx_rdptr = PCIE_SCRATCH_8_REG,
142 .rx_wrptr = PCIE_SCRATCH_9_REG,
143 .evt_rdptr = PCIE_SCRATCH_10_REG,
144 .evt_wrptr = PCIE_SCRATCH_11_REG,
145 .drv_rdy = PCIE_SCRATCH_12_REG,
146 .tx_start_ptr = 0,
147 .tx_mask = MWIFIEX_TXBD_MASK,
148 .tx_wrap_mask = 0,
149 .rx_mask = MWIFIEX_RXBD_MASK,
150 .rx_wrap_mask = 0,
151 .tx_rollover_ind = MWIFIEX_BD_FLAG_ROLLOVER_IND,
152 .rx_rollover_ind = MWIFIEX_BD_FLAG_ROLLOVER_IND,
153 .evt_rollover_ind = MWIFIEX_BD_FLAG_ROLLOVER_IND,
154 .ring_flag_sop = 0,
155 .ring_flag_eop = 0,
156 .ring_flag_xs_sop = 0,
157 .ring_flag_xs_eop = 0,
158 .ring_tx_start_ptr = 0,
159 .pfu_enabled = 0,
160 .sleep_cookie = 1,
161};
162
163static const struct mwifiex_pcie_card_reg mwifiex_reg_8897 = {
164 .cmd_addr_lo = PCIE_SCRATCH_0_REG,
165 .cmd_addr_hi = PCIE_SCRATCH_1_REG,
166 .cmd_size = PCIE_SCRATCH_2_REG,
167 .fw_status = PCIE_SCRATCH_3_REG,
168 .cmdrsp_addr_lo = PCIE_SCRATCH_4_REG,
169 .cmdrsp_addr_hi = PCIE_SCRATCH_5_REG,
170 .tx_rdptr = PCIE_RD_DATA_PTR_Q0_Q1,
171 .tx_wrptr = PCIE_WR_DATA_PTR_Q0_Q1,
172 .rx_rdptr = PCIE_WR_DATA_PTR_Q0_Q1,
173 .rx_wrptr = PCIE_RD_DATA_PTR_Q0_Q1,
174 .evt_rdptr = PCIE_SCRATCH_10_REG,
175 .evt_wrptr = PCIE_SCRATCH_11_REG,
176 .drv_rdy = PCIE_SCRATCH_12_REG,
177 .tx_start_ptr = 16,
178 .tx_mask = 0x03FF0000,
179 .tx_wrap_mask = 0x07FF0000,
180 .rx_mask = 0x000003FF,
181 .rx_wrap_mask = 0x000007FF,
182 .tx_rollover_ind = MWIFIEX_BD_FLAG_TX_ROLLOVER_IND,
183 .rx_rollover_ind = MWIFIEX_BD_FLAG_RX_ROLLOVER_IND,
184 .evt_rollover_ind = MWIFIEX_BD_FLAG_EVT_ROLLOVER_IND,
185 .ring_flag_sop = MWIFIEX_BD_FLAG_SOP,
186 .ring_flag_eop = MWIFIEX_BD_FLAG_EOP,
187 .ring_flag_xs_sop = MWIFIEX_BD_FLAG_XS_SOP,
188 .ring_flag_xs_eop = MWIFIEX_BD_FLAG_XS_EOP,
189 .ring_tx_start_ptr = MWIFIEX_BD_FLAG_TX_START_PTR,
190 .pfu_enabled = 1,
191 .sleep_cookie = 0,
192};
193
194struct mwifiex_pcie_device {
195 const char *firmware;
196 const struct mwifiex_pcie_card_reg *reg;
197 u16 blksz_fw_dl;
198};
199
200static const struct mwifiex_pcie_device mwifiex_pcie8766 = {
201 .firmware = PCIE8766_DEFAULT_FW_NAME,
202 .reg = &mwifiex_reg_8766,
203 .blksz_fw_dl = MWIFIEX_PCIE_BLOCK_SIZE_FW_DNLD,
204};
205
206static const struct mwifiex_pcie_device mwifiex_pcie8897 = {
207 .firmware = PCIE8897_DEFAULT_FW_NAME,
208 .reg = &mwifiex_reg_8897,
209 .blksz_fw_dl = MWIFIEX_PCIE_BLOCK_SIZE_FW_DNLD,
210};
211
212struct mwifiex_evt_buf_desc {
213 u64 paddr;
214 u16 len;
215 u16 flags;
216} __packed;
217
107struct mwifiex_pcie_buf_desc { 218struct mwifiex_pcie_buf_desc {
108 u64 paddr; 219 u64 paddr;
109 u16 len; 220 u16 len;
110 u16 flags; 221 u16 flags;
111} __packed; 222} __packed;
112 223
224struct mwifiex_pfu_buf_desc {
225 u16 flags;
226 u16 offset;
227 u16 frag_len;
228 u16 len;
229 u64 paddr;
230 u32 reserved;
231} __packed;
232
113struct pcie_service_card { 233struct pcie_service_card {
114 struct pci_dev *dev; 234 struct pci_dev *dev;
115 struct mwifiex_adapter *adapter; 235 struct mwifiex_adapter *adapter;
236 struct mwifiex_pcie_device pcie;
116 237
238 u8 txbd_flush;
117 u32 txbd_wrptr; 239 u32 txbd_wrptr;
118 u32 txbd_rdptr; 240 u32 txbd_rdptr;
119 u32 txbd_ring_size; 241 u32 txbd_ring_size;
120 u8 *txbd_ring_vbase; 242 u8 *txbd_ring_vbase;
121 phys_addr_t txbd_ring_pbase; 243 dma_addr_t txbd_ring_pbase;
122 struct mwifiex_pcie_buf_desc *txbd_ring[MWIFIEX_MAX_TXRX_BD]; 244 void *txbd_ring[MWIFIEX_MAX_TXRX_BD];
123 struct sk_buff *tx_buf_list[MWIFIEX_MAX_TXRX_BD]; 245 struct sk_buff *tx_buf_list[MWIFIEX_MAX_TXRX_BD];
124 246
125 u32 rxbd_wrptr; 247 u32 rxbd_wrptr;
126 u32 rxbd_rdptr; 248 u32 rxbd_rdptr;
127 u32 rxbd_ring_size; 249 u32 rxbd_ring_size;
128 u8 *rxbd_ring_vbase; 250 u8 *rxbd_ring_vbase;
129 phys_addr_t rxbd_ring_pbase; 251 dma_addr_t rxbd_ring_pbase;
130 struct mwifiex_pcie_buf_desc *rxbd_ring[MWIFIEX_MAX_TXRX_BD]; 252 void *rxbd_ring[MWIFIEX_MAX_TXRX_BD];
131 struct sk_buff *rx_buf_list[MWIFIEX_MAX_TXRX_BD]; 253 struct sk_buff *rx_buf_list[MWIFIEX_MAX_TXRX_BD];
132 254
133 u32 evtbd_wrptr; 255 u32 evtbd_wrptr;
134 u32 evtbd_rdptr; 256 u32 evtbd_rdptr;
135 u32 evtbd_ring_size; 257 u32 evtbd_ring_size;
136 u8 *evtbd_ring_vbase; 258 u8 *evtbd_ring_vbase;
137 phys_addr_t evtbd_ring_pbase; 259 dma_addr_t evtbd_ring_pbase;
138 struct mwifiex_pcie_buf_desc *evtbd_ring[MWIFIEX_MAX_EVT_BD]; 260 void *evtbd_ring[MWIFIEX_MAX_EVT_BD];
139 struct sk_buff *evt_buf_list[MWIFIEX_MAX_EVT_BD]; 261 struct sk_buff *evt_buf_list[MWIFIEX_MAX_EVT_BD];
140 262
141 struct sk_buff *cmd_buf; 263 struct sk_buff *cmd_buf;
142 struct sk_buff *cmdrsp_buf; 264 struct sk_buff *cmdrsp_buf;
143 struct sk_buff *sleep_cookie; 265 u8 *sleep_cookie_vbase;
266 dma_addr_t sleep_cookie_pbase;
144 void __iomem *pci_mmap; 267 void __iomem *pci_mmap;
145 void __iomem *pci_mmap1; 268 void __iomem *pci_mmap1;
146}; 269};
147 270
271static inline int
272mwifiex_pcie_txbd_empty(struct pcie_service_card *card, u32 rdptr)
273{
274 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
275
276 switch (card->dev->device) {
277 case PCIE_DEVICE_ID_MARVELL_88W8766P:
278 if (((card->txbd_wrptr & reg->tx_mask) ==
279 (rdptr & reg->tx_mask)) &&
280 ((card->txbd_wrptr & reg->tx_rollover_ind) !=
281 (rdptr & reg->tx_rollover_ind)))
282 return 1;
283 break;
284 case PCIE_DEVICE_ID_MARVELL_88W8897:
285 if (((card->txbd_wrptr & reg->tx_mask) ==
286 (rdptr & reg->tx_mask)) &&
287 ((card->txbd_wrptr & reg->tx_rollover_ind) ==
288 (rdptr & reg->tx_rollover_ind)))
289 return 1;
290 break;
291 }
292
293 return 0;
294}
295
296static inline int
297mwifiex_pcie_txbd_not_full(struct pcie_service_card *card)
298{
299 const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
300
301 switch (card->dev->device) {
302 case PCIE_DEVICE_ID_MARVELL_88W8766P:
303 if (((card->txbd_wrptr & reg->tx_mask) !=
304 (card->txbd_rdptr & reg->tx_mask)) ||
305 ((card->txbd_wrptr & reg->tx_rollover_ind) !=
306 (card->txbd_rdptr & reg->tx_rollover_ind)))
307 return 1;
308 break;
309 case PCIE_DEVICE_ID_MARVELL_88W8897:
310 if (((card->txbd_wrptr & reg->tx_mask) !=
311 (card->txbd_rdptr & reg->tx_mask)) ||
312 ((card->txbd_wrptr & reg->tx_rollover_ind) ==
313 (card->txbd_rdptr & reg->tx_rollover_ind)))
314 return 1;
315 break;
316 }
317
318 return 0;
319}
148#endif /* _MWIFIEX_PCIE_H */ 320#endif /* _MWIFIEX_PCIE_H */
diff --git a/drivers/net/wireless/mwifiex/scan.c b/drivers/net/wireless/mwifiex/scan.c
index 973a9d90e9ea..bb60c2754a97 100644
--- a/drivers/net/wireless/mwifiex/scan.c
+++ b/drivers/net/wireless/mwifiex/scan.c
@@ -1250,6 +1250,23 @@ int mwifiex_update_bss_desc_with_ie(struct mwifiex_adapter *adapter,
1250 sizeof(struct ieee_types_header) - 1250 sizeof(struct ieee_types_header) -
1251 bss_entry->beacon_buf); 1251 bss_entry->beacon_buf);
1252 break; 1252 break;
1253 case WLAN_EID_VHT_CAPABILITY:
1254 bss_entry->disable_11ac = false;
1255 bss_entry->bcn_vht_cap =
1256 (void *)(current_ptr +
1257 sizeof(struct ieee_types_header));
1258 bss_entry->vht_cap_offset =
1259 (u16)((u8 *)bss_entry->bcn_vht_cap -
1260 bss_entry->beacon_buf);
1261 break;
1262 case WLAN_EID_VHT_OPERATION:
1263 bss_entry->bcn_vht_oper =
1264 (void *)(current_ptr +
1265 sizeof(struct ieee_types_header));
1266 bss_entry->vht_info_offset =
1267 (u16)((u8 *)bss_entry->bcn_vht_oper -
1268 bss_entry->beacon_buf);
1269 break;
1253 case WLAN_EID_BSS_COEX_2040: 1270 case WLAN_EID_BSS_COEX_2040:
1254 bss_entry->bcn_bss_co_2040 = current_ptr + 1271 bss_entry->bcn_bss_co_2040 = current_ptr +
1255 sizeof(struct ieee_types_header); 1272 sizeof(struct ieee_types_header);
@@ -1264,6 +1281,14 @@ int mwifiex_update_bss_desc_with_ie(struct mwifiex_adapter *adapter,
1264 sizeof(struct ieee_types_header) - 1281 sizeof(struct ieee_types_header) -
1265 bss_entry->beacon_buf); 1282 bss_entry->beacon_buf);
1266 break; 1283 break;
1284 case WLAN_EID_OPMODE_NOTIF:
1285 bss_entry->oper_mode =
1286 (void *)(current_ptr +
1287 sizeof(struct ieee_types_header));
1288 bss_entry->oper_mode_offset =
1289 (u16)((u8 *)bss_entry->oper_mode -
1290 bss_entry->beacon_buf);
1291 break;
1267 default: 1292 default:
1268 break; 1293 break;
1269 } 1294 }
@@ -1309,7 +1334,6 @@ int mwifiex_scan_networks(struct mwifiex_private *priv,
1309 struct cmd_ctrl_node *cmd_node; 1334 struct cmd_ctrl_node *cmd_node;
1310 union mwifiex_scan_cmd_config_tlv *scan_cfg_out; 1335 union mwifiex_scan_cmd_config_tlv *scan_cfg_out;
1311 struct mwifiex_ie_types_chan_list_param_set *chan_list_out; 1336 struct mwifiex_ie_types_chan_list_param_set *chan_list_out;
1312 u32 buf_size;
1313 struct mwifiex_chan_scan_param_set *scan_chan_list; 1337 struct mwifiex_chan_scan_param_set *scan_chan_list;
1314 u8 filtered_scan; 1338 u8 filtered_scan;
1315 u8 scan_current_chan_only; 1339 u8 scan_current_chan_only;
@@ -1332,18 +1356,16 @@ int mwifiex_scan_networks(struct mwifiex_private *priv,
1332 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags); 1356 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
1333 1357
1334 scan_cfg_out = kzalloc(sizeof(union mwifiex_scan_cmd_config_tlv), 1358 scan_cfg_out = kzalloc(sizeof(union mwifiex_scan_cmd_config_tlv),
1335 GFP_KERNEL); 1359 GFP_KERNEL);
1336 if (!scan_cfg_out) { 1360 if (!scan_cfg_out) {
1337 dev_err(adapter->dev, "failed to alloc scan_cfg_out\n");
1338 ret = -ENOMEM; 1361 ret = -ENOMEM;
1339 goto done; 1362 goto done;
1340 } 1363 }
1341 1364
1342 buf_size = sizeof(struct mwifiex_chan_scan_param_set) * 1365 scan_chan_list = kcalloc(MWIFIEX_USER_SCAN_CHAN_MAX,
1343 MWIFIEX_USER_SCAN_CHAN_MAX; 1366 sizeof(struct mwifiex_chan_scan_param_set),
1344 scan_chan_list = kzalloc(buf_size, GFP_KERNEL); 1367 GFP_KERNEL);
1345 if (!scan_chan_list) { 1368 if (!scan_chan_list) {
1346 dev_err(adapter->dev, "failed to alloc scan_chan_list\n");
1347 kfree(scan_cfg_out); 1369 kfree(scan_cfg_out);
1348 ret = -ENOMEM; 1370 ret = -ENOMEM;
1349 goto done; 1371 goto done;
@@ -1461,12 +1483,9 @@ static int mwifiex_update_curr_bss_params(struct mwifiex_private *priv,
1461 unsigned long flags; 1483 unsigned long flags;
1462 1484
1463 /* Allocate and fill new bss descriptor */ 1485 /* Allocate and fill new bss descriptor */
1464 bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor), 1486 bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor), GFP_KERNEL);
1465 GFP_KERNEL); 1487 if (!bss_desc)
1466 if (!bss_desc) {
1467 dev_err(priv->adapter->dev, " failed to alloc bss_desc\n");
1468 return -ENOMEM; 1488 return -ENOMEM;
1469 }
1470 1489
1471 ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc); 1490 ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc);
1472 if (ret) 1491 if (ret)
@@ -1485,20 +1504,26 @@ static int mwifiex_update_curr_bss_params(struct mwifiex_private *priv,
1485 priv->curr_bss_params.bss_descriptor.bcn_wapi_ie = NULL; 1504 priv->curr_bss_params.bss_descriptor.bcn_wapi_ie = NULL;
1486 priv->curr_bss_params.bss_descriptor.wapi_offset = 0; 1505 priv->curr_bss_params.bss_descriptor.wapi_offset = 0;
1487 priv->curr_bss_params.bss_descriptor.bcn_ht_cap = NULL; 1506 priv->curr_bss_params.bss_descriptor.bcn_ht_cap = NULL;
1488 priv->curr_bss_params.bss_descriptor.ht_cap_offset = 1507 priv->curr_bss_params.bss_descriptor.ht_cap_offset = 0;
1489 0;
1490 priv->curr_bss_params.bss_descriptor.bcn_ht_oper = NULL; 1508 priv->curr_bss_params.bss_descriptor.bcn_ht_oper = NULL;
1491 priv->curr_bss_params.bss_descriptor.ht_info_offset = 1509 priv->curr_bss_params.bss_descriptor.ht_info_offset = 0;
1492 0; 1510 priv->curr_bss_params.bss_descriptor.bcn_bss_co_2040 = NULL;
1493 priv->curr_bss_params.bss_descriptor.bcn_bss_co_2040 = 1511 priv->curr_bss_params.bss_descriptor.bss_co_2040_offset = 0;
1494 NULL;
1495 priv->curr_bss_params.bss_descriptor.
1496 bss_co_2040_offset = 0;
1497 priv->curr_bss_params.bss_descriptor.bcn_ext_cap = NULL; 1512 priv->curr_bss_params.bss_descriptor.bcn_ext_cap = NULL;
1498 priv->curr_bss_params.bss_descriptor.ext_cap_offset = 0; 1513 priv->curr_bss_params.bss_descriptor.ext_cap_offset = 0;
1499 priv->curr_bss_params.bss_descriptor.beacon_buf = NULL; 1514 priv->curr_bss_params.bss_descriptor.beacon_buf = NULL;
1500 priv->curr_bss_params.bss_descriptor.beacon_buf_size = 1515 priv->curr_bss_params.bss_descriptor.beacon_buf_size = 0;
1501 0; 1516 priv->curr_bss_params.bss_descriptor.bcn_vht_cap = NULL;
1517 priv->curr_bss_params.bss_descriptor.vht_cap_offset = 0;
1518 priv->curr_bss_params.bss_descriptor.bcn_vht_oper = NULL;
1519 priv->curr_bss_params.bss_descriptor.vht_info_offset = 0;
1520 priv->curr_bss_params.bss_descriptor.oper_mode = NULL;
1521 priv->curr_bss_params.bss_descriptor.oper_mode_offset = 0;
1522
1523 /* Disable 11ac by default. Enable it only where there
1524 * exist VHT_CAP IE in AP beacon
1525 */
1526 priv->curr_bss_params.bss_descriptor.disable_11ac = true;
1502 1527
1503 /* Make a copy of current BSSID descriptor */ 1528 /* Make a copy of current BSSID descriptor */
1504 memcpy(&priv->curr_bss_params.bss_descriptor, bss_desc, 1529 memcpy(&priv->curr_bss_params.bss_descriptor, bss_desc,
@@ -1747,7 +1772,7 @@ int mwifiex_ret_802_11_scan(struct mwifiex_private *priv,
1747 .mac_address, ETH_ALEN)) 1772 .mac_address, ETH_ALEN))
1748 mwifiex_update_curr_bss_params(priv, 1773 mwifiex_update_curr_bss_params(priv,
1749 bss); 1774 bss);
1750 cfg80211_put_bss(bss); 1775 cfg80211_put_bss(priv->wdev->wiphy, bss);
1751 } 1776 }
1752 } else { 1777 } else {
1753 dev_dbg(adapter->dev, "missing BSS channel IE\n"); 1778 dev_dbg(adapter->dev, "missing BSS channel IE\n");
@@ -1880,10 +1905,8 @@ static int mwifiex_scan_specific_ssid(struct mwifiex_private *priv,
1880 } 1905 }
1881 1906
1882 scan_cfg = kzalloc(sizeof(struct mwifiex_user_scan_cfg), GFP_KERNEL); 1907 scan_cfg = kzalloc(sizeof(struct mwifiex_user_scan_cfg), GFP_KERNEL);
1883 if (!scan_cfg) { 1908 if (!scan_cfg)
1884 dev_err(adapter->dev, "failed to alloc scan_cfg\n");
1885 return -ENOMEM; 1909 return -ENOMEM;
1886 }
1887 1910
1888 scan_cfg->ssid_list = req_ssid; 1911 scan_cfg->ssid_list = req_ssid;
1889 scan_cfg->num_ssids = 1; 1912 scan_cfg->num_ssids = 1;
@@ -1997,11 +2020,8 @@ mwifiex_save_curr_bcn(struct mwifiex_private *priv)
1997 kfree(priv->curr_bcn_buf); 2020 kfree(priv->curr_bcn_buf);
1998 priv->curr_bcn_buf = kmalloc(curr_bss->beacon_buf_size, 2021 priv->curr_bcn_buf = kmalloc(curr_bss->beacon_buf_size,
1999 GFP_ATOMIC); 2022 GFP_ATOMIC);
2000 if (!priv->curr_bcn_buf) { 2023 if (!priv->curr_bcn_buf)
2001 dev_err(priv->adapter->dev,
2002 "failed to alloc curr_bcn_buf\n");
2003 return; 2024 return;
2004 }
2005 } 2025 }
2006 2026
2007 memcpy(priv->curr_bcn_buf, curr_bss->beacon_buf, 2027 memcpy(priv->curr_bcn_buf, curr_bss->beacon_buf,
@@ -2033,6 +2053,14 @@ mwifiex_save_curr_bcn(struct mwifiex_private *priv)
2033 (curr_bss->beacon_buf + 2053 (curr_bss->beacon_buf +
2034 curr_bss->ht_info_offset); 2054 curr_bss->ht_info_offset);
2035 2055
2056 if (curr_bss->bcn_vht_cap)
2057 curr_bss->bcn_ht_cap = (void *)(curr_bss->beacon_buf +
2058 curr_bss->vht_cap_offset);
2059
2060 if (curr_bss->bcn_vht_oper)
2061 curr_bss->bcn_ht_oper = (void *)(curr_bss->beacon_buf +
2062 curr_bss->vht_info_offset);
2063
2036 if (curr_bss->bcn_bss_co_2040) 2064 if (curr_bss->bcn_bss_co_2040)
2037 curr_bss->bcn_bss_co_2040 = 2065 curr_bss->bcn_bss_co_2040 =
2038 (curr_bss->beacon_buf + curr_bss->bss_co_2040_offset); 2066 (curr_bss->beacon_buf + curr_bss->bss_co_2040_offset);
@@ -2040,6 +2068,10 @@ mwifiex_save_curr_bcn(struct mwifiex_private *priv)
2040 if (curr_bss->bcn_ext_cap) 2068 if (curr_bss->bcn_ext_cap)
2041 curr_bss->bcn_ext_cap = curr_bss->beacon_buf + 2069 curr_bss->bcn_ext_cap = curr_bss->beacon_buf +
2042 curr_bss->ext_cap_offset; 2070 curr_bss->ext_cap_offset;
2071
2072 if (curr_bss->oper_mode)
2073 curr_bss->oper_mode = (void *)(curr_bss->beacon_buf +
2074 curr_bss->oper_mode_offset);
2043} 2075}
2044 2076
2045/* 2077/*
diff --git a/drivers/net/wireless/mwifiex/sdio.c b/drivers/net/wireless/mwifiex/sdio.c
index f2874c3392b4..e63f646a260e 100644
--- a/drivers/net/wireless/mwifiex/sdio.c
+++ b/drivers/net/wireless/mwifiex/sdio.c
@@ -332,7 +332,7 @@ mwifiex_write_data_sync(struct mwifiex_adapter *adapter,
332 u8 *buffer, u32 pkt_len, u32 port) 332 u8 *buffer, u32 pkt_len, u32 port)
333{ 333{
334 struct sdio_mmc_card *card = adapter->card; 334 struct sdio_mmc_card *card = adapter->card;
335 int ret = -1; 335 int ret;
336 u8 blk_mode = 336 u8 blk_mode =
337 (port & MWIFIEX_SDIO_BYTE_MODE_MASK) ? BYTE_MODE : BLOCK_MODE; 337 (port & MWIFIEX_SDIO_BYTE_MODE_MASK) ? BYTE_MODE : BLOCK_MODE;
338 u32 blk_size = (blk_mode == BLOCK_MODE) ? MWIFIEX_SDIO_BLOCK_SIZE : 1; 338 u32 blk_size = (blk_mode == BLOCK_MODE) ? MWIFIEX_SDIO_BLOCK_SIZE : 1;
@@ -350,8 +350,7 @@ mwifiex_write_data_sync(struct mwifiex_adapter *adapter,
350 350
351 sdio_claim_host(card->func); 351 sdio_claim_host(card->func);
352 352
353 if (!sdio_writesb(card->func, ioport, buffer, blk_cnt * blk_size)) 353 ret = sdio_writesb(card->func, ioport, buffer, blk_cnt * blk_size);
354 ret = 0;
355 354
356 sdio_release_host(card->func); 355 sdio_release_host(card->func);
357 356
@@ -365,7 +364,7 @@ static int mwifiex_read_data_sync(struct mwifiex_adapter *adapter, u8 *buffer,
365 u32 len, u32 port, u8 claim) 364 u32 len, u32 port, u8 claim)
366{ 365{
367 struct sdio_mmc_card *card = adapter->card; 366 struct sdio_mmc_card *card = adapter->card;
368 int ret = -1; 367 int ret;
369 u8 blk_mode = (port & MWIFIEX_SDIO_BYTE_MODE_MASK) ? BYTE_MODE 368 u8 blk_mode = (port & MWIFIEX_SDIO_BYTE_MODE_MASK) ? BYTE_MODE
370 : BLOCK_MODE; 369 : BLOCK_MODE;
371 u32 blk_size = (blk_mode == BLOCK_MODE) ? MWIFIEX_SDIO_BLOCK_SIZE : 1; 370 u32 blk_size = (blk_mode == BLOCK_MODE) ? MWIFIEX_SDIO_BLOCK_SIZE : 1;
@@ -376,8 +375,7 @@ static int mwifiex_read_data_sync(struct mwifiex_adapter *adapter, u8 *buffer,
376 if (claim) 375 if (claim)
377 sdio_claim_host(card->func); 376 sdio_claim_host(card->func);
378 377
379 if (!sdio_readsb(card->func, buffer, ioport, blk_cnt * blk_size)) 378 ret = sdio_readsb(card->func, buffer, ioport, blk_cnt * blk_size);
380 ret = 0;
381 379
382 if (claim) 380 if (claim)
383 sdio_release_host(card->func); 381 sdio_release_host(card->func);
@@ -718,11 +716,8 @@ static int mwifiex_prog_fw_w_helper(struct mwifiex_adapter *adapter,
718 716
719 /* Assume that the allocated buffer is 8-byte aligned */ 717 /* Assume that the allocated buffer is 8-byte aligned */
720 fwbuf = kzalloc(MWIFIEX_UPLD_SIZE, GFP_KERNEL); 718 fwbuf = kzalloc(MWIFIEX_UPLD_SIZE, GFP_KERNEL);
721 if (!fwbuf) { 719 if (!fwbuf)
722 dev_err(adapter->dev,
723 "unable to alloc buffer for FW. Terminating dnld\n");
724 return -ENOMEM; 720 return -ENOMEM;
725 }
726 721
727 /* Perform firmware data transfer */ 722 /* Perform firmware data transfer */
728 do { 723 do {
@@ -1520,7 +1515,6 @@ static int mwifiex_alloc_sdio_mpa_buffers(struct mwifiex_adapter *adapter,
1520 1515
1521 card->mpa_tx.buf = kzalloc(mpa_tx_buf_size, GFP_KERNEL); 1516 card->mpa_tx.buf = kzalloc(mpa_tx_buf_size, GFP_KERNEL);
1522 if (!card->mpa_tx.buf) { 1517 if (!card->mpa_tx.buf) {
1523 dev_err(adapter->dev, "could not alloc buffer for MP-A TX\n");
1524 ret = -1; 1518 ret = -1;
1525 goto error; 1519 goto error;
1526 } 1520 }
@@ -1529,7 +1523,6 @@ static int mwifiex_alloc_sdio_mpa_buffers(struct mwifiex_adapter *adapter,
1529 1523
1530 card->mpa_rx.buf = kzalloc(mpa_rx_buf_size, GFP_KERNEL); 1524 card->mpa_rx.buf = kzalloc(mpa_rx_buf_size, GFP_KERNEL);
1531 if (!card->mpa_rx.buf) { 1525 if (!card->mpa_rx.buf) {
1532 dev_err(adapter->dev, "could not alloc buffer for MP-A RX\n");
1533 ret = -1; 1526 ret = -1;
1534 goto error; 1527 goto error;
1535 } 1528 }
@@ -1682,10 +1675,8 @@ static int mwifiex_init_sdio(struct mwifiex_adapter *adapter)
1682 1675
1683 /* Allocate buffers for SDIO MP-A */ 1676 /* Allocate buffers for SDIO MP-A */
1684 card->mp_regs = kzalloc(MAX_MP_REGS, GFP_KERNEL); 1677 card->mp_regs = kzalloc(MAX_MP_REGS, GFP_KERNEL);
1685 if (!card->mp_regs) { 1678 if (!card->mp_regs)
1686 dev_err(adapter->dev, "failed to alloc mp_regs\n");
1687 return -ENOMEM; 1679 return -ENOMEM;
1688 }
1689 1680
1690 ret = mwifiex_alloc_sdio_mpa_buffers(adapter, 1681 ret = mwifiex_alloc_sdio_mpa_buffers(adapter,
1691 SDIO_MP_TX_AGGR_DEF_BUF_SIZE, 1682 SDIO_MP_TX_AGGR_DEF_BUF_SIZE,
diff --git a/drivers/net/wireless/mwifiex/sta_cmd.c b/drivers/net/wireless/mwifiex/sta_cmd.c
index 5d87195390f8..c55c5bb93134 100644
--- a/drivers/net/wireless/mwifiex/sta_cmd.c
+++ b/drivers/net/wireless/mwifiex/sta_cmd.c
@@ -931,7 +931,6 @@ mwifiex_cmd_pcie_host_spec(struct mwifiex_private *priv,
931 struct host_cmd_ds_pcie_details *host_spec = 931 struct host_cmd_ds_pcie_details *host_spec =
932 &cmd->params.pcie_host_spec; 932 &cmd->params.pcie_host_spec;
933 struct pcie_service_card *card = priv->adapter->card; 933 struct pcie_service_card *card = priv->adapter->card;
934 phys_addr_t *buf_pa;
935 934
936 cmd->command = cpu_to_le16(HostCmd_CMD_PCIE_DESC_DETAILS); 935 cmd->command = cpu_to_le16(HostCmd_CMD_PCIE_DESC_DETAILS);
937 cmd->size = cpu_to_le16(sizeof(struct 936 cmd->size = cpu_to_le16(sizeof(struct
@@ -953,10 +952,11 @@ mwifiex_cmd_pcie_host_spec(struct mwifiex_private *priv,
953 host_spec->evtbd_addr_lo = (u32)(card->evtbd_ring_pbase); 952 host_spec->evtbd_addr_lo = (u32)(card->evtbd_ring_pbase);
954 host_spec->evtbd_addr_hi = (u32)(((u64)card->evtbd_ring_pbase)>>32); 953 host_spec->evtbd_addr_hi = (u32)(((u64)card->evtbd_ring_pbase)>>32);
955 host_spec->evtbd_count = MWIFIEX_MAX_EVT_BD; 954 host_spec->evtbd_count = MWIFIEX_MAX_EVT_BD;
956 if (card->sleep_cookie) { 955 if (card->sleep_cookie_vbase) {
957 buf_pa = MWIFIEX_SKB_PACB(card->sleep_cookie); 956 host_spec->sleep_cookie_addr_lo =
958 host_spec->sleep_cookie_addr_lo = (u32) *buf_pa; 957 (u32)(card->sleep_cookie_pbase);
959 host_spec->sleep_cookie_addr_hi = (u32) (((u64)*buf_pa) >> 32); 958 host_spec->sleep_cookie_addr_hi =
959 (u32)(((u64)(card->sleep_cookie_pbase)) >> 32);
960 dev_dbg(priv->adapter->dev, "sleep_cook_lo phy addr: 0x%x\n", 960 dev_dbg(priv->adapter->dev, "sleep_cook_lo phy addr: 0x%x\n",
961 host_spec->sleep_cookie_addr_lo); 961 host_spec->sleep_cookie_addr_lo);
962 } 962 }
@@ -1230,7 +1230,7 @@ int mwifiex_sta_prepare_cmd(struct mwifiex_private *priv, uint16_t cmd_no,
1230 data_buf); 1230 data_buf);
1231 break; 1231 break;
1232 case HostCmd_CMD_11N_CFG: 1232 case HostCmd_CMD_11N_CFG:
1233 ret = mwifiex_cmd_11n_cfg(cmd_ptr, cmd_action, data_buf); 1233 ret = mwifiex_cmd_11n_cfg(priv, cmd_ptr, cmd_action, data_buf);
1234 break; 1234 break;
1235 case HostCmd_CMD_WMM_GET_STATUS: 1235 case HostCmd_CMD_WMM_GET_STATUS:
1236 dev_dbg(priv->adapter->dev, 1236 dev_dbg(priv->adapter->dev,
diff --git a/drivers/net/wireless/mwifiex/sta_cmdresp.c b/drivers/net/wireless/mwifiex/sta_cmdresp.c
index 65c12eb3e5e7..4669f8d9389f 100644
--- a/drivers/net/wireless/mwifiex/sta_cmdresp.c
+++ b/drivers/net/wireless/mwifiex/sta_cmdresp.c
@@ -24,6 +24,7 @@
24#include "main.h" 24#include "main.h"
25#include "wmm.h" 25#include "wmm.h"
26#include "11n.h" 26#include "11n.h"
27#include "11ac.h"
27 28
28 29
29/* 30/*
@@ -935,9 +936,8 @@ int mwifiex_process_sta_cmdresp(struct mwifiex_private *priv, u16 cmdresp_no,
935 / MWIFIEX_SDIO_BLOCK_SIZE) 936 / MWIFIEX_SDIO_BLOCK_SIZE)
936 * MWIFIEX_SDIO_BLOCK_SIZE; 937 * MWIFIEX_SDIO_BLOCK_SIZE;
937 adapter->curr_tx_buf_size = adapter->tx_buf_size; 938 adapter->curr_tx_buf_size = adapter->tx_buf_size;
938 dev_dbg(adapter->dev, 939 dev_dbg(adapter->dev, "cmd: curr_tx_buf_size=%d\n",
939 "cmd: max_tx_buf_size=%d, tx_buf_size=%d\n", 940 adapter->curr_tx_buf_size);
940 adapter->max_tx_buf_size, adapter->tx_buf_size);
941 941
942 if (adapter->if_ops.update_mp_end_port) 942 if (adapter->if_ops.update_mp_end_port)
943 adapter->if_ops.update_mp_end_port(adapter, 943 adapter->if_ops.update_mp_end_port(adapter,
diff --git a/drivers/net/wireless/mwifiex/sta_ioctl.c b/drivers/net/wireless/mwifiex/sta_ioctl.c
index f542bb8ccbc8..9f33c92c90f5 100644
--- a/drivers/net/wireless/mwifiex/sta_ioctl.c
+++ b/drivers/net/wireless/mwifiex/sta_ioctl.c
@@ -162,13 +162,9 @@ int mwifiex_fill_new_bss_desc(struct mwifiex_private *priv,
162 162
163 rcu_read_lock(); 163 rcu_read_lock();
164 ies = rcu_dereference(bss->ies); 164 ies = rcu_dereference(bss->ies);
165 if (WARN_ON(!ies)) {
166 /* should never happen */
167 rcu_read_unlock();
168 return -EINVAL;
169 }
170 beacon_ie = kmemdup(ies->data, ies->len, GFP_ATOMIC); 165 beacon_ie = kmemdup(ies->data, ies->len, GFP_ATOMIC);
171 beacon_ie_len = ies->len; 166 beacon_ie_len = ies->len;
167 bss_desc->timestamp = ies->tsf;
172 rcu_read_unlock(); 168 rcu_read_unlock();
173 169
174 if (!beacon_ie) { 170 if (!beacon_ie) {
@@ -184,7 +180,6 @@ int mwifiex_fill_new_bss_desc(struct mwifiex_private *priv,
184 bss_desc->cap_info_bitmap = bss->capability; 180 bss_desc->cap_info_bitmap = bss->capability;
185 bss_desc->bss_band = bss_priv->band; 181 bss_desc->bss_band = bss_priv->band;
186 bss_desc->fw_tsf = bss_priv->fw_tsf; 182 bss_desc->fw_tsf = bss_priv->fw_tsf;
187 bss_desc->timestamp = bss->tsf;
188 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_PRIVACY) { 183 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_PRIVACY) {
189 dev_dbg(priv->adapter->dev, "info: InterpretIE: AP WEP enabled\n"); 184 dev_dbg(priv->adapter->dev, "info: InterpretIE: AP WEP enabled\n");
190 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP; 185 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
@@ -266,11 +261,9 @@ int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
266 261
267 /* Allocate and fill new bss descriptor */ 262 /* Allocate and fill new bss descriptor */
268 bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor), 263 bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor),
269 GFP_KERNEL); 264 GFP_KERNEL);
270 if (!bss_desc) { 265 if (!bss_desc)
271 dev_err(priv->adapter->dev, " failed to alloc bss_desc\n");
272 return -ENOMEM; 266 return -ENOMEM;
273 }
274 267
275 ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc); 268 ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc);
276 if (ret) 269 if (ret)
@@ -288,9 +281,10 @@ int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
288 281
289 if (mwifiex_band_to_radio_type((u8) bss_desc->bss_band) 282 if (mwifiex_band_to_radio_type((u8) bss_desc->bss_band)
290 == HostCmd_SCAN_RADIO_TYPE_BG) 283 == HostCmd_SCAN_RADIO_TYPE_BG)
291 config_bands = BAND_B | BAND_G | BAND_GN; 284 config_bands = BAND_B | BAND_G | BAND_GN |
285 BAND_GAC;
292 else 286 else
293 config_bands = BAND_A | BAND_AN; 287 config_bands = BAND_A | BAND_AN | BAND_AAC;
294 288
295 if (!((config_bands | adapter->fw_bands) & 289 if (!((config_bands | adapter->fw_bands) &
296 ~adapter->fw_bands)) 290 ~adapter->fw_bands))
@@ -324,7 +318,7 @@ int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
324 } 318 }
325 319
326 if (bss) 320 if (bss)
327 cfg80211_put_bss(bss); 321 cfg80211_put_bss(priv->adapter->wiphy, bss);
328 } else { 322 } else {
329 /* Adhoc mode */ 323 /* Adhoc mode */
330 /* If the requested SSID matches current SSID, return */ 324 /* If the requested SSID matches current SSID, return */
@@ -354,7 +348,7 @@ int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
354 " list. Joining...\n"); 348 " list. Joining...\n");
355 ret = mwifiex_adhoc_join(priv, bss_desc); 349 ret = mwifiex_adhoc_join(priv, bss_desc);
356 if (bss) 350 if (bss)
357 cfg80211_put_bss(bss); 351 cfg80211_put_bss(priv->adapter->wiphy, bss);
358 } else { 352 } else {
359 dev_dbg(adapter->dev, "info: Network not found in " 353 dev_dbg(adapter->dev, "info: Network not found in "
360 "the list, creating adhoc with ssid = %s\n", 354 "the list, creating adhoc with ssid = %s\n",
@@ -636,11 +630,8 @@ int mwifiex_set_tx_power(struct mwifiex_private *priv,
636 } 630 }
637 } 631 }
638 buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL); 632 buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
639 if (!buf) { 633 if (!buf)
640 dev_err(priv->adapter->dev, "%s: failed to alloc cmd buffer\n",
641 __func__);
642 return -ENOMEM; 634 return -ENOMEM;
643 }
644 635
645 txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf; 636 txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
646 txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET); 637 txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
diff --git a/drivers/net/wireless/mwifiex/txrx.c b/drivers/net/wireless/mwifiex/txrx.c
index 8c80024c30ff..296faec14365 100644
--- a/drivers/net/wireless/mwifiex/txrx.c
+++ b/drivers/net/wireless/mwifiex/txrx.c
@@ -117,14 +117,16 @@ int mwifiex_process_tx(struct mwifiex_private *priv, struct sk_buff *skb,
117 dev_dbg(adapter->dev, "data: -EBUSY is returned\n"); 117 dev_dbg(adapter->dev, "data: -EBUSY is returned\n");
118 break; 118 break;
119 case -1: 119 case -1:
120 adapter->data_sent = false; 120 if (adapter->iface_type != MWIFIEX_PCIE)
121 adapter->data_sent = false;
121 dev_err(adapter->dev, "mwifiex_write_data_async failed: 0x%X\n", 122 dev_err(adapter->dev, "mwifiex_write_data_async failed: 0x%X\n",
122 ret); 123 ret);
123 adapter->dbg.num_tx_host_to_card_failure++; 124 adapter->dbg.num_tx_host_to_card_failure++;
124 mwifiex_write_data_complete(adapter, skb, 0, ret); 125 mwifiex_write_data_complete(adapter, skb, 0, ret);
125 break; 126 break;
126 case -EINPROGRESS: 127 case -EINPROGRESS:
127 adapter->data_sent = false; 128 if (adapter->iface_type != MWIFIEX_PCIE)
129 adapter->data_sent = false;
128 break; 130 break;
129 case 0: 131 case 0:
130 mwifiex_write_data_complete(adapter, skb, 0, ret); 132 mwifiex_write_data_complete(adapter, skb, 0, ret);
diff --git a/drivers/net/wireless/mwifiex/uap_cmd.c b/drivers/net/wireless/mwifiex/uap_cmd.c
index 8dd72240f162..6e76a15a8950 100644
--- a/drivers/net/wireless/mwifiex/uap_cmd.c
+++ b/drivers/net/wireless/mwifiex/uap_cmd.c
@@ -219,6 +219,7 @@ void mwifiex_set_sys_config_invalid_data(struct mwifiex_uap_bss_param *config)
219 config->rts_threshold = 0x7FFF; 219 config->rts_threshold = 0x7FFF;
220 config->frag_threshold = 0x7FFF; 220 config->frag_threshold = 0x7FFF;
221 config->retry_limit = 0x7F; 221 config->retry_limit = 0x7F;
222 config->qos_info = 0xFF;
222} 223}
223 224
224/* This function parses BSS related parameters from structure 225/* This function parses BSS related parameters from structure
@@ -297,6 +298,38 @@ mwifiex_uap_bss_wpa(u8 **tlv_buf, void *cmd_buf, u16 *param_size)
297 return; 298 return;
298} 299}
299 300
301/* This function parses WMM related parameters from cfg80211_ap_settings
302 * structure and updates bss_config structure.
303 */
304void
305mwifiex_set_wmm_params(struct mwifiex_private *priv,
306 struct mwifiex_uap_bss_param *bss_cfg,
307 struct cfg80211_ap_settings *params)
308{
309 const u8 *vendor_ie;
310 struct ieee_types_header *wmm_ie;
311 u8 wmm_oui[] = {0x00, 0x50, 0xf2, 0x02};
312
313 vendor_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
314 WLAN_OUI_TYPE_MICROSOFT_WMM,
315 params->beacon.tail,
316 params->beacon.tail_len);
317 if (vendor_ie) {
318 wmm_ie = (struct ieee_types_header *)vendor_ie;
319 memcpy(&bss_cfg->wmm_info, wmm_ie + 1,
320 sizeof(bss_cfg->wmm_info));
321 priv->wmm_enabled = 1;
322 } else {
323 memset(&bss_cfg->wmm_info, 0, sizeof(bss_cfg->wmm_info));
324 memcpy(&bss_cfg->wmm_info.oui, wmm_oui, sizeof(wmm_oui));
325 bss_cfg->wmm_info.subtype = MWIFIEX_WMM_SUBTYPE;
326 bss_cfg->wmm_info.version = MWIFIEX_WMM_VERSION;
327 priv->wmm_enabled = 0;
328 }
329
330 bss_cfg->qos_info = 0x00;
331 return;
332}
300/* This function parses BSS related parameters from structure 333/* This function parses BSS related parameters from structure
301 * and prepares TLVs specific to WEP encryption. 334 * and prepares TLVs specific to WEP encryption.
302 * These TLVs are appended to command buffer. 335 * These TLVs are appended to command buffer.
@@ -354,6 +387,7 @@ mwifiex_uap_bss_param_prepare(u8 *tlv, void *cmd_buf, u16 *param_size)
354 struct host_cmd_tlv_rates *tlv_rates; 387 struct host_cmd_tlv_rates *tlv_rates;
355 struct host_cmd_tlv_ageout_timer *ao_timer, *ps_ao_timer; 388 struct host_cmd_tlv_ageout_timer *ao_timer, *ps_ao_timer;
356 struct mwifiex_ie_types_htcap *htcap; 389 struct mwifiex_ie_types_htcap *htcap;
390 struct mwifiex_ie_types_wmmcap *wmm_cap;
357 struct mwifiex_uap_bss_param *bss_cfg = cmd_buf; 391 struct mwifiex_uap_bss_param *bss_cfg = cmd_buf;
358 int i; 392 int i;
359 u16 cmd_size = *param_size; 393 u16 cmd_size = *param_size;
@@ -507,6 +541,16 @@ mwifiex_uap_bss_param_prepare(u8 *tlv, void *cmd_buf, u16 *param_size)
507 tlv += sizeof(struct mwifiex_ie_types_htcap); 541 tlv += sizeof(struct mwifiex_ie_types_htcap);
508 } 542 }
509 543
544 if (bss_cfg->wmm_info.qos_info != 0xFF) {
545 wmm_cap = (struct mwifiex_ie_types_wmmcap *)tlv;
546 wmm_cap->header.type = cpu_to_le16(WLAN_EID_VENDOR_SPECIFIC);
547 wmm_cap->header.len = cpu_to_le16(sizeof(wmm_cap->wmm_info));
548 memcpy(&wmm_cap->wmm_info, &bss_cfg->wmm_info,
549 sizeof(wmm_cap->wmm_info));
550 cmd_size += sizeof(struct mwifiex_ie_types_wmmcap);
551 tlv += sizeof(struct mwifiex_ie_types_wmmcap);
552 }
553
510 if (bss_cfg->sta_ao_timer) { 554 if (bss_cfg->sta_ao_timer) {
511 ao_timer = (struct host_cmd_tlv_ageout_timer *)tlv; 555 ao_timer = (struct host_cmd_tlv_ageout_timer *)tlv;
512 ao_timer->tlv.type = cpu_to_le16(TLV_TYPE_UAP_AO_TIMER); 556 ao_timer->tlv.type = cpu_to_le16(TLV_TYPE_UAP_AO_TIMER);
diff --git a/drivers/net/wireless/mwifiex/usb.c b/drivers/net/wireless/mwifiex/usb.c
index 63ac9f2d11ae..f90fe21e5bfd 100644
--- a/drivers/net/wireless/mwifiex/usb.c
+++ b/drivers/net/wireless/mwifiex/usb.c
@@ -672,7 +672,7 @@ static int mwifiex_write_data_sync(struct mwifiex_adapter *adapter, u8 *pbuf,
672 *len, &actual_length, timeout); 672 *len, &actual_length, timeout);
673 if (ret) { 673 if (ret) {
674 dev_err(adapter->dev, "usb_bulk_msg for tx failed: %d\n", ret); 674 dev_err(adapter->dev, "usb_bulk_msg for tx failed: %d\n", ret);
675 ret = -1; 675 return ret;
676 } 676 }
677 677
678 *len = actual_length; 678 *len = actual_length;
@@ -691,7 +691,7 @@ static int mwifiex_read_data_sync(struct mwifiex_adapter *adapter, u8 *pbuf,
691 *len, &actual_length, timeout); 691 *len, &actual_length, timeout);
692 if (ret) { 692 if (ret) {
693 dev_err(adapter->dev, "usb_bulk_msg for rx failed: %d\n", ret); 693 dev_err(adapter->dev, "usb_bulk_msg for rx failed: %d\n", ret);
694 ret = -1; 694 return ret;
695 } 695 }
696 696
697 *len = actual_length; 697 *len = actual_length;
@@ -786,21 +786,6 @@ static int mwifiex_register_dev(struct mwifiex_adapter *adapter)
786 return 0; 786 return 0;
787} 787}
788 788
789/* This function reads one block of firmware data. */
790static int mwifiex_get_fw_data(struct mwifiex_adapter *adapter,
791 u32 offset, u32 len, u8 *buf)
792{
793 if (!buf || !len)
794 return -1;
795
796 if (offset + len > adapter->firmware->size)
797 return -1;
798
799 memcpy(buf, adapter->firmware->data + offset, len);
800
801 return 0;
802}
803
804static int mwifiex_prog_fw_w_helper(struct mwifiex_adapter *adapter, 789static int mwifiex_prog_fw_w_helper(struct mwifiex_adapter *adapter,
805 struct mwifiex_fw_image *fw) 790 struct mwifiex_fw_image *fw)
806{ 791{
@@ -836,23 +821,14 @@ static int mwifiex_prog_fw_w_helper(struct mwifiex_adapter *adapter,
836 dlen = 0; 821 dlen = 0;
837 } else { 822 } else {
838 /* copy the header of the fw_data to get the length */ 823 /* copy the header of the fw_data to get the length */
839 if (firmware) 824 memcpy(&fwdata->fw_hdr, &firmware[tlen],
840 memcpy(&fwdata->fw_hdr, &firmware[tlen], 825 sizeof(struct fw_header));
841 sizeof(struct fw_header));
842 else
843 mwifiex_get_fw_data(adapter, tlen,
844 sizeof(struct fw_header),
845 (u8 *)&fwdata->fw_hdr);
846 826
847 dlen = le32_to_cpu(fwdata->fw_hdr.data_len); 827 dlen = le32_to_cpu(fwdata->fw_hdr.data_len);
848 dnld_cmd = le32_to_cpu(fwdata->fw_hdr.dnld_cmd); 828 dnld_cmd = le32_to_cpu(fwdata->fw_hdr.dnld_cmd);
849 tlen += sizeof(struct fw_header); 829 tlen += sizeof(struct fw_header);
850 830
851 if (firmware) 831 memcpy(fwdata->data, &firmware[tlen], dlen);
852 memcpy(fwdata->data, &firmware[tlen], dlen);
853 else
854 mwifiex_get_fw_data(adapter, tlen, dlen,
855 (u8 *)fwdata->data);
856 832
857 fwdata->seq_num = cpu_to_le32(fw_seqnum); 833 fwdata->seq_num = cpu_to_le32(fw_seqnum);
858 tlen += dlen; 834 tlen += dlen;
diff --git a/drivers/net/wireless/mwifiex/util.c b/drivers/net/wireless/mwifiex/util.c
index 0982375ba3b1..21553976b550 100644
--- a/drivers/net/wireless/mwifiex/util.c
+++ b/drivers/net/wireless/mwifiex/util.c
@@ -91,7 +91,7 @@ int mwifiex_get_debug_info(struct mwifiex_private *priv,
91 memcpy(info->packets_out, 91 memcpy(info->packets_out,
92 priv->wmm.packets_out, 92 priv->wmm.packets_out,
93 sizeof(priv->wmm.packets_out)); 93 sizeof(priv->wmm.packets_out));
94 info->max_tx_buf_size = (u32) adapter->max_tx_buf_size; 94 info->curr_tx_buf_size = (u32) adapter->curr_tx_buf_size;
95 info->tx_buf_size = (u32) adapter->tx_buf_size; 95 info->tx_buf_size = (u32) adapter->tx_buf_size;
96 info->rx_tbl_num = mwifiex_get_rx_reorder_tbl(priv, 96 info->rx_tbl_num = mwifiex_get_rx_reorder_tbl(priv,
97 info->rx_tbl); 97 info->rx_tbl);
diff --git a/drivers/net/wireless/mwifiex/util.h b/drivers/net/wireless/mwifiex/util.h
index f6d36b9654a0..cb2d0582bd36 100644
--- a/drivers/net/wireless/mwifiex/util.h
+++ b/drivers/net/wireless/mwifiex/util.h
@@ -22,16 +22,16 @@
22 22
23static inline struct mwifiex_rxinfo *MWIFIEX_SKB_RXCB(struct sk_buff *skb) 23static inline struct mwifiex_rxinfo *MWIFIEX_SKB_RXCB(struct sk_buff *skb)
24{ 24{
25 return (struct mwifiex_rxinfo *)(skb->cb + sizeof(phys_addr_t)); 25 return (struct mwifiex_rxinfo *)(skb->cb + sizeof(dma_addr_t));
26} 26}
27 27
28static inline struct mwifiex_txinfo *MWIFIEX_SKB_TXCB(struct sk_buff *skb) 28static inline struct mwifiex_txinfo *MWIFIEX_SKB_TXCB(struct sk_buff *skb)
29{ 29{
30 return (struct mwifiex_txinfo *)(skb->cb + sizeof(phys_addr_t)); 30 return (struct mwifiex_txinfo *)(skb->cb + sizeof(dma_addr_t));
31} 31}
32 32
33static inline phys_addr_t *MWIFIEX_SKB_PACB(struct sk_buff *skb) 33static inline void MWIFIEX_SKB_PACB(struct sk_buff *skb, dma_addr_t *buf_pa)
34{ 34{
35 return (phys_addr_t *)skb->cb; 35 memcpy(buf_pa, skb->cb, sizeof(dma_addr_t));
36} 36}
37#endif /* !_MWIFIEX_UTIL_H_ */ 37#endif /* !_MWIFIEX_UTIL_H_ */
diff --git a/drivers/net/wireless/mwifiex/wmm.c b/drivers/net/wireless/mwifiex/wmm.c
index 818f871ae987..32adc878041d 100644
--- a/drivers/net/wireless/mwifiex/wmm.c
+++ b/drivers/net/wireless/mwifiex/wmm.c
@@ -109,12 +109,9 @@ mwifiex_wmm_allocate_ralist_node(struct mwifiex_adapter *adapter, u8 *ra)
109 struct mwifiex_ra_list_tbl *ra_list; 109 struct mwifiex_ra_list_tbl *ra_list;
110 110
111 ra_list = kzalloc(sizeof(struct mwifiex_ra_list_tbl), GFP_ATOMIC); 111 ra_list = kzalloc(sizeof(struct mwifiex_ra_list_tbl), GFP_ATOMIC);
112 112 if (!ra_list)
113 if (!ra_list) {
114 dev_err(adapter->dev, "%s: failed to alloc ra_list\n",
115 __func__);
116 return NULL; 113 return NULL;
117 } 114
118 INIT_LIST_HEAD(&ra_list->list); 115 INIT_LIST_HEAD(&ra_list->list);
119 skb_queue_head_init(&ra_list->skb_head); 116 skb_queue_head_init(&ra_list->skb_head);
120 117
@@ -568,6 +565,8 @@ mwifiex_clean_txrx(struct mwifiex_private *priv)
568 mwifiex_wmm_delete_all_ralist(priv); 565 mwifiex_wmm_delete_all_ralist(priv);
569 memcpy(tos_to_tid, ac_to_tid, sizeof(tos_to_tid)); 566 memcpy(tos_to_tid, ac_to_tid, sizeof(tos_to_tid));
570 567
568 if (priv->adapter->if_ops.clean_pcie_ring)
569 priv->adapter->if_ops.clean_pcie_ring(priv->adapter);
571 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags); 570 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
572} 571}
573 572
@@ -1206,13 +1205,15 @@ mwifiex_send_processed_packet(struct mwifiex_private *priv,
1206 ra_list_flags); 1205 ra_list_flags);
1207 break; 1206 break;
1208 case -1: 1207 case -1:
1209 adapter->data_sent = false; 1208 if (adapter->iface_type != MWIFIEX_PCIE)
1209 adapter->data_sent = false;
1210 dev_err(adapter->dev, "host_to_card failed: %#x\n", ret); 1210 dev_err(adapter->dev, "host_to_card failed: %#x\n", ret);
1211 adapter->dbg.num_tx_host_to_card_failure++; 1211 adapter->dbg.num_tx_host_to_card_failure++;
1212 mwifiex_write_data_complete(adapter, skb, 0, ret); 1212 mwifiex_write_data_complete(adapter, skb, 0, ret);
1213 break; 1213 break;
1214 case -EINPROGRESS: 1214 case -EINPROGRESS:
1215 adapter->data_sent = false; 1215 if (adapter->iface_type != MWIFIEX_PCIE)
1216 adapter->data_sent = false;
1216 default: 1217 default:
1217 break; 1218 break;
1218 } 1219 }