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
);
49 status
.freq
= WCN36XX_CENTER_FREQ(wcn
);
50 status
.band
= WCN36XX_BAND(wcn
);
51 status
.signal
= -get_rssi0(bd
);
56 status
.flag
|= RX_FLAG_IV_STRIPPED
|
57 RX_FLAG_MMIC_STRIPPED
|
60 wcn36xx_dbg(WCN36XX_DBG_RX
, "status.flags=%x status->vendor_radiotap_len=%x\n",
61 status
.flag
, status
.vendor_radiotap_len
);
63 memcpy(IEEE80211_SKB_RXCB(skb
), &status
, sizeof(status
));
65 hdr
= (struct ieee80211_hdr
*) skb
->data
;
66 fc
= __le16_to_cpu(hdr
->frame_control
);
67 sn
= IEEE80211_SEQ_TO_SN(__le16_to_cpu(hdr
->seq_ctrl
));
69 if (ieee80211_is_beacon(hdr
->frame_control
)) {
70 wcn36xx_dbg(WCN36XX_DBG_BEACON
, "beacon skb %p len %d fc %04x sn %d\n",
71 skb
, skb
->len
, fc
, sn
);
72 wcn36xx_dbg_dump(WCN36XX_DBG_BEACON_DUMP
, "SKB <<< ",
73 (char *)skb
->data
, skb
->len
);
75 wcn36xx_dbg(WCN36XX_DBG_RX
, "rx skb %p len %d fc %04x sn %d\n",
76 skb
, skb
->len
, fc
, sn
);
77 wcn36xx_dbg_dump(WCN36XX_DBG_RX_DUMP
, "SKB <<< ",
78 (char *)skb
->data
, skb
->len
);
81 ieee80211_rx_irqsafe(wcn
->hw
, skb
);
86 static void wcn36xx_set_tx_pdu(struct wcn36xx_tx_bd
*bd
,
91 bd
->pdu
.mpdu_header_len
= mpdu_header_len
;
92 bd
->pdu
.mpdu_header_off
= sizeof(*bd
);
93 bd
->pdu
.mpdu_data_off
= bd
->pdu
.mpdu_header_len
+
94 bd
->pdu
.mpdu_header_off
;
95 bd
->pdu
.mpdu_len
= len
;
99 static inline struct wcn36xx_vif
*get_vif_by_addr(struct wcn36xx
*wcn
,
102 struct wcn36xx_vif
*vif_priv
= NULL
;
103 struct ieee80211_vif
*vif
= NULL
;
104 list_for_each_entry(vif_priv
, &wcn
->vif_list
, list
) {
105 vif
= container_of((void *)vif_priv
,
106 struct ieee80211_vif
,
108 if (memcmp(vif
->addr
, addr
, ETH_ALEN
) == 0)
111 wcn36xx_warn("vif %pM not found\n", addr
);
114 static void wcn36xx_set_tx_data(struct wcn36xx_tx_bd
*bd
,
116 struct wcn36xx_vif
**vif_priv
,
117 struct wcn36xx_sta
*sta_priv
,
118 struct ieee80211_hdr
*hdr
,
121 struct ieee80211_vif
*vif
= NULL
;
122 struct wcn36xx_vif
*__vif_priv
= NULL
;
123 bd
->bd_rate
= WCN36XX_BD_RATE_DATA
;
126 * For not unicast frames mac80211 will not set sta pointer so use
127 * self_sta_index instead.
130 __vif_priv
= sta_priv
->vif
;
131 vif
= container_of((void *)__vif_priv
,
132 struct ieee80211_vif
,
135 if (vif
->type
== NL80211_IFTYPE_STATION
) {
136 bd
->sta_index
= sta_priv
->bss_sta_index
;
137 bd
->dpu_desc_idx
= sta_priv
->bss_dpu_desc_index
;
138 } else if (vif
->type
== NL80211_IFTYPE_AP
||
139 vif
->type
== NL80211_IFTYPE_ADHOC
||
140 vif
->type
== NL80211_IFTYPE_MESH_POINT
) {
141 bd
->sta_index
= sta_priv
->sta_index
;
142 bd
->dpu_desc_idx
= sta_priv
->dpu_desc_index
;
145 __vif_priv
= get_vif_by_addr(wcn
, hdr
->addr2
);
146 bd
->sta_index
= __vif_priv
->self_sta_index
;
147 bd
->dpu_desc_idx
= __vif_priv
->self_dpu_desc_index
;
150 bd
->dpu_sign
= __vif_priv
->ucast_dpu_signature
;
152 if (ieee80211_is_nullfunc(hdr
->frame_control
) ||
153 (sta_priv
&& !sta_priv
->is_data_encrypted
))
160 *vif_priv
= __vif_priv
;
163 static void wcn36xx_set_tx_mgmt(struct wcn36xx_tx_bd
*bd
,
165 struct wcn36xx_vif
**vif_priv
,
166 struct ieee80211_hdr
*hdr
,
169 struct wcn36xx_vif
*__vif_priv
=
170 get_vif_by_addr(wcn
, hdr
->addr2
);
171 bd
->sta_index
= __vif_priv
->self_sta_index
;
172 bd
->dpu_desc_idx
= __vif_priv
->self_dpu_desc_index
;
175 /* default rate for unicast */
176 if (ieee80211_is_mgmt(hdr
->frame_control
))
177 bd
->bd_rate
= (WCN36XX_BAND(wcn
) == IEEE80211_BAND_5GHZ
) ?
178 WCN36XX_BD_RATE_CTRL
:
179 WCN36XX_BD_RATE_MGMT
;
180 else if (ieee80211_is_ctl(hdr
->frame_control
))
181 bd
->bd_rate
= WCN36XX_BD_RATE_CTRL
;
183 wcn36xx_warn("frame control type unknown\n");
186 * In joining state trick hardware that probe is sent as
187 * unicast even if address is broadcast.
189 if (__vif_priv
->is_joining
&&
190 ieee80211_is_probe_req(hdr
->frame_control
))
196 /* No ack needed not unicast */
198 bd
->queue_id
= WCN36XX_TX_B_WQ_ID
;
200 bd
->queue_id
= WCN36XX_TX_U_WQ_ID
;
201 *vif_priv
= __vif_priv
;
204 int wcn36xx_start_tx(struct wcn36xx
*wcn
,
205 struct wcn36xx_sta
*sta_priv
,
208 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
209 struct wcn36xx_vif
*vif_priv
= NULL
;
210 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
212 bool is_low
= ieee80211_is_data(hdr
->frame_control
);
213 bool bcast
= is_broadcast_ether_addr(hdr
->addr1
) ||
214 is_multicast_ether_addr(hdr
->addr1
);
215 struct wcn36xx_tx_bd
*bd
= wcn36xx_dxe_get_next_bd(wcn
, is_low
);
219 * TX DXE are used in pairs. One for the BD and one for the
220 * actual frame. The BD DXE's has a preallocated buffer while
221 * the skb ones does not. If this isn't true something is really
222 * wierd. TODO: Recover from this situation
225 wcn36xx_err("bd address may not be NULL for BD DXE\n");
229 memset(bd
, 0, sizeof(*bd
));
231 wcn36xx_dbg(WCN36XX_DBG_TX
,
232 "tx skb %p len %d fc %04x sn %d %s %s\n",
233 skb
, skb
->len
, __le16_to_cpu(hdr
->frame_control
),
234 IEEE80211_SEQ_TO_SN(__le16_to_cpu(hdr
->seq_ctrl
)),
235 is_low
? "low" : "high", bcast
? "bcast" : "ucast");
237 wcn36xx_dbg_dump(WCN36XX_DBG_TX_DUMP
, "", skb
->data
, skb
->len
);
239 bd
->dpu_rf
= WCN36XX_BMU_WQ_TX
;
241 bd
->tx_comp
= info
->flags
& IEEE80211_TX_CTL_REQ_TX_STATUS
;
243 wcn36xx_dbg(WCN36XX_DBG_DXE
, "TX_ACK status requested\n");
244 spin_lock_irqsave(&wcn
->dxe_lock
, flags
);
245 if (wcn
->tx_ack_skb
) {
246 spin_unlock_irqrestore(&wcn
->dxe_lock
, flags
);
247 wcn36xx_warn("tx_ack_skb already set\n");
251 wcn
->tx_ack_skb
= skb
;
252 spin_unlock_irqrestore(&wcn
->dxe_lock
, flags
);
254 /* Only one at a time is supported by fw. Stop the TX queues
255 * until the ack status gets back.
257 * TODO: Add watchdog in case FW does not answer
259 ieee80211_stop_queues(wcn
->hw
);
262 /* Data frames served first*/
264 wcn36xx_set_tx_data(bd
, wcn
, &vif_priv
, sta_priv
, hdr
, bcast
);
265 wcn36xx_set_tx_pdu(bd
,
266 ieee80211_is_data_qos(hdr
->frame_control
) ?
267 sizeof(struct ieee80211_qos_hdr
) :
268 sizeof(struct ieee80211_hdr_3addr
),
269 skb
->len
, sta_priv
? sta_priv
->tid
: 0);
271 /* MGMT and CTRL frames are handeld here*/
272 wcn36xx_set_tx_mgmt(bd
, wcn
, &vif_priv
, hdr
, bcast
);
273 wcn36xx_set_tx_pdu(bd
,
274 ieee80211_is_data_qos(hdr
->frame_control
) ?
275 sizeof(struct ieee80211_qos_hdr
) :
276 sizeof(struct ieee80211_hdr_3addr
),
277 skb
->len
, WCN36XX_TID
);
280 buff_to_be((u32
*)bd
, sizeof(*bd
)/sizeof(u32
));
281 bd
->tx_bd_sign
= 0xbdbdbdbd;
283 return wcn36xx_dxe_tx_frame(wcn
, vif_priv
, skb
, is_low
);