2 * Copyright (c) 2013 Eugene Krasnikov <k.eugene.e@gmail.com>
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21 static inline int get_rssi0(struct wcn36xx_rx_bd
*bd
)
23 return 100 - ((bd
->phy_stat0
>> 24) & 0xff);
26 int wcn36xx_rx_skb(struct wcn36xx
*wcn
, struct sk_buff
*skb
)
28 struct ieee80211_rx_status status
;
29 struct ieee80211_hdr
*hdr
;
30 struct wcn36xx_rx_bd
*bd
;
34 * All fields must be 0, otherwise it can lead to
35 * unexpected consequences.
37 memset(&status
, 0, sizeof(status
));
39 bd
= (struct wcn36xx_rx_bd
*)skb
->data
;
40 buff_to_be((u32
*)bd
, sizeof(*bd
)/sizeof(u32
));
41 wcn36xx_dbg_dump(WCN36XX_DBG_RX_DUMP
,
42 "BD <<< ", (char *)bd
,
43 sizeof(struct wcn36xx_rx_bd
));
45 skb_put(skb
, bd
->pdu
.mpdu_header_off
+ bd
->pdu
.mpdu_len
);
46 skb_pull(skb
, bd
->pdu
.mpdu_header_off
);
48 hdr
= (struct ieee80211_hdr
*) skb
->data
;
49 fc
= __le16_to_cpu(hdr
->frame_control
);
50 sn
= IEEE80211_SEQ_TO_SN(__le16_to_cpu(hdr
->seq_ctrl
));
52 /* When scanning associate beacons to this */
53 if (ieee80211_is_beacon(hdr
->frame_control
) && wcn
->scan_freq
) {
54 status
.freq
= wcn
->scan_freq
;
55 status
.band
= wcn
->scan_band
;
57 status
.freq
= WCN36XX_CENTER_FREQ(wcn
);
58 status
.band
= WCN36XX_BAND(wcn
);
62 status
.signal
= -get_rssi0(bd
);
67 status
.flag
|= RX_FLAG_IV_STRIPPED
|
68 RX_FLAG_MMIC_STRIPPED
|
71 wcn36xx_dbg(WCN36XX_DBG_RX
, "status.flags=%x\n", status
.flag
);
73 memcpy(IEEE80211_SKB_RXCB(skb
), &status
, sizeof(status
));
75 if (ieee80211_is_beacon(hdr
->frame_control
)) {
76 wcn36xx_dbg(WCN36XX_DBG_BEACON
, "beacon skb %p len %d fc %04x sn %d\n",
77 skb
, skb
->len
, fc
, sn
);
78 wcn36xx_dbg_dump(WCN36XX_DBG_BEACON_DUMP
, "SKB <<< ",
79 (char *)skb
->data
, skb
->len
);
81 wcn36xx_dbg(WCN36XX_DBG_RX
, "rx skb %p len %d fc %04x sn %d\n",
82 skb
, skb
->len
, fc
, sn
);
83 wcn36xx_dbg_dump(WCN36XX_DBG_RX_DUMP
, "SKB <<< ",
84 (char *)skb
->data
, skb
->len
);
87 ieee80211_rx_irqsafe(wcn
->hw
, skb
);
92 static void wcn36xx_set_tx_pdu(struct wcn36xx_tx_bd
*bd
,
97 bd
->pdu
.mpdu_header_len
= mpdu_header_len
;
98 bd
->pdu
.mpdu_header_off
= sizeof(*bd
);
99 bd
->pdu
.mpdu_data_off
= bd
->pdu
.mpdu_header_len
+
100 bd
->pdu
.mpdu_header_off
;
101 bd
->pdu
.mpdu_len
= len
;
103 bd
->pdu
.bd_ssn
= WCN36XX_TXBD_SSN_FILL_DPU_QOS
;
106 static inline struct wcn36xx_vif
*get_vif_by_addr(struct wcn36xx
*wcn
,
109 struct wcn36xx_vif
*vif_priv
= NULL
;
110 struct ieee80211_vif
*vif
= NULL
;
111 list_for_each_entry(vif_priv
, &wcn
->vif_list
, list
) {
112 vif
= wcn36xx_priv_to_vif(vif_priv
);
113 if (memcmp(vif
->addr
, addr
, ETH_ALEN
) == 0)
116 wcn36xx_warn("vif %pM not found\n", addr
);
120 static void wcn36xx_tx_start_ampdu(struct wcn36xx
*wcn
,
121 struct wcn36xx_sta
*sta_priv
,
124 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
125 struct ieee80211_sta
*sta
;
128 if (!conf_is_ht(&wcn
->hw
->conf
))
131 sta
= wcn36xx_priv_to_sta(sta_priv
);
133 if (WARN_ON(!ieee80211_is_data_qos(hdr
->frame_control
)))
136 if (skb_get_queue_mapping(skb
) == IEEE80211_AC_VO
)
139 qc
= ieee80211_get_qos_ctl(hdr
);
140 tid
= qc
[0] & IEEE80211_QOS_CTL_TID_MASK
;
142 spin_lock(&sta_priv
->ampdu_lock
);
143 if (sta_priv
->ampdu_state
[tid
] != WCN36XX_AMPDU_NONE
)
146 if (sta_priv
->non_agg_frame_ct
++ >= WCN36XX_AMPDU_START_THRESH
) {
147 sta_priv
->ampdu_state
[tid
] = WCN36XX_AMPDU_START
;
148 sta_priv
->non_agg_frame_ct
= 0;
149 ieee80211_start_tx_ba_session(sta
, tid
, 0);
152 spin_unlock(&sta_priv
->ampdu_lock
);
155 static void wcn36xx_set_tx_data(struct wcn36xx_tx_bd
*bd
,
157 struct wcn36xx_vif
**vif_priv
,
158 struct wcn36xx_sta
*sta_priv
,
162 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
163 struct ieee80211_vif
*vif
= NULL
;
164 struct wcn36xx_vif
*__vif_priv
= NULL
;
167 bd
->bd_rate
= WCN36XX_BD_RATE_DATA
;
170 * For not unicast frames mac80211 will not set sta pointer so use
171 * self_sta_index instead.
174 __vif_priv
= sta_priv
->vif
;
175 vif
= wcn36xx_priv_to_vif(__vif_priv
);
177 bd
->dpu_sign
= sta_priv
->ucast_dpu_sign
;
178 if (vif
->type
== NL80211_IFTYPE_STATION
) {
179 bd
->sta_index
= sta_priv
->bss_sta_index
;
180 bd
->dpu_desc_idx
= sta_priv
->bss_dpu_desc_index
;
181 } else if (vif
->type
== NL80211_IFTYPE_AP
||
182 vif
->type
== NL80211_IFTYPE_ADHOC
||
183 vif
->type
== NL80211_IFTYPE_MESH_POINT
) {
184 bd
->sta_index
= sta_priv
->sta_index
;
185 bd
->dpu_desc_idx
= sta_priv
->dpu_desc_index
;
188 __vif_priv
= get_vif_by_addr(wcn
, hdr
->addr2
);
189 bd
->sta_index
= __vif_priv
->self_sta_index
;
190 bd
->dpu_desc_idx
= __vif_priv
->self_dpu_desc_index
;
191 bd
->dpu_sign
= __vif_priv
->self_ucast_dpu_sign
;
194 if (ieee80211_is_nullfunc(hdr
->frame_control
) ||
195 (sta_priv
&& !sta_priv
->is_data_encrypted
))
202 *vif_priv
= __vif_priv
;
204 is_data_qos
= ieee80211_is_data_qos(hdr
->frame_control
);
206 wcn36xx_set_tx_pdu(bd
,
208 sizeof(struct ieee80211_qos_hdr
) :
209 sizeof(struct ieee80211_hdr_3addr
),
210 skb
->len
, sta_priv
? sta_priv
->tid
: 0);
212 if (sta_priv
&& is_data_qos
)
213 wcn36xx_tx_start_ampdu(wcn
, sta_priv
, skb
);
216 static void wcn36xx_set_tx_mgmt(struct wcn36xx_tx_bd
*bd
,
218 struct wcn36xx_vif
**vif_priv
,
222 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
223 struct wcn36xx_vif
*__vif_priv
=
224 get_vif_by_addr(wcn
, hdr
->addr2
);
225 bd
->sta_index
= __vif_priv
->self_sta_index
;
226 bd
->dpu_desc_idx
= __vif_priv
->self_dpu_desc_index
;
229 /* default rate for unicast */
230 if (ieee80211_is_mgmt(hdr
->frame_control
))
231 bd
->bd_rate
= (WCN36XX_BAND(wcn
) == NL80211_BAND_5GHZ
) ?
232 WCN36XX_BD_RATE_CTRL
:
233 WCN36XX_BD_RATE_MGMT
;
234 else if (ieee80211_is_ctl(hdr
->frame_control
))
235 bd
->bd_rate
= WCN36XX_BD_RATE_CTRL
;
237 wcn36xx_warn("frame control type unknown\n");
240 * In joining state trick hardware that probe is sent as
241 * unicast even if address is broadcast.
243 if (__vif_priv
->is_joining
&&
244 ieee80211_is_probe_req(hdr
->frame_control
))
250 /* No ack needed not unicast */
252 bd
->queue_id
= WCN36XX_TX_B_WQ_ID
;
254 bd
->queue_id
= WCN36XX_TX_U_WQ_ID
;
255 *vif_priv
= __vif_priv
;
257 wcn36xx_set_tx_pdu(bd
,
258 ieee80211_is_data_qos(hdr
->frame_control
) ?
259 sizeof(struct ieee80211_qos_hdr
) :
260 sizeof(struct ieee80211_hdr_3addr
),
261 skb
->len
, WCN36XX_TID
);
264 int wcn36xx_start_tx(struct wcn36xx
*wcn
,
265 struct wcn36xx_sta
*sta_priv
,
268 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
269 struct wcn36xx_vif
*vif_priv
= NULL
;
270 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
272 bool is_low
= ieee80211_is_data(hdr
->frame_control
);
273 bool bcast
= is_broadcast_ether_addr(hdr
->addr1
) ||
274 is_multicast_ether_addr(hdr
->addr1
);
275 struct wcn36xx_tx_bd
*bd
= wcn36xx_dxe_get_next_bd(wcn
, is_low
);
279 * TX DXE are used in pairs. One for the BD and one for the
280 * actual frame. The BD DXE's has a preallocated buffer while
281 * the skb ones does not. If this isn't true something is really
282 * wierd. TODO: Recover from this situation
285 wcn36xx_err("bd address may not be NULL for BD DXE\n");
289 memset(bd
, 0, sizeof(*bd
));
291 wcn36xx_dbg(WCN36XX_DBG_TX
,
292 "tx skb %p len %d fc %04x sn %d %s %s\n",
293 skb
, skb
->len
, __le16_to_cpu(hdr
->frame_control
),
294 IEEE80211_SEQ_TO_SN(__le16_to_cpu(hdr
->seq_ctrl
)),
295 is_low
? "low" : "high", bcast
? "bcast" : "ucast");
297 wcn36xx_dbg_dump(WCN36XX_DBG_TX_DUMP
, "", skb
->data
, skb
->len
);
299 bd
->dpu_rf
= WCN36XX_BMU_WQ_TX
;
301 bd
->tx_comp
= !!(info
->flags
& IEEE80211_TX_CTL_REQ_TX_STATUS
);
303 wcn36xx_dbg(WCN36XX_DBG_DXE
, "TX_ACK status requested\n");
304 spin_lock_irqsave(&wcn
->dxe_lock
, flags
);
305 if (wcn
->tx_ack_skb
) {
306 spin_unlock_irqrestore(&wcn
->dxe_lock
, flags
);
307 wcn36xx_warn("tx_ack_skb already set\n");
311 wcn
->tx_ack_skb
= skb
;
312 spin_unlock_irqrestore(&wcn
->dxe_lock
, flags
);
314 /* Only one at a time is supported by fw. Stop the TX queues
315 * until the ack status gets back.
317 * TODO: Add watchdog in case FW does not answer
319 ieee80211_stop_queues(wcn
->hw
);
322 /* Data frames served first*/
324 wcn36xx_set_tx_data(bd
, wcn
, &vif_priv
, sta_priv
, skb
, bcast
);
326 /* MGMT and CTRL frames are handeld here*/
327 wcn36xx_set_tx_mgmt(bd
, wcn
, &vif_priv
, skb
, bcast
);
329 buff_to_be((u32
*)bd
, sizeof(*bd
)/sizeof(u32
));
330 bd
->tx_bd_sign
= 0xbdbdbdbd;
332 return wcn36xx_dxe_tx_frame(wcn
, vif_priv
, skb
, is_low
);