| 1 |
// SPDX-License-Identifier: BSD-3-Clause-Clear |
| 2 |
/* |
| 3 |
* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. |
| 4 |
* Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. |
| 5 |
*/ |
| 6 |
|
| 7 |
#include <linux/ieee80211.h> |
| 8 |
#include <linux/kernel.h> |
| 9 |
#include <linux/skbuff.h> |
| 10 |
#include <crypto/hash.h> |
| 11 |
#include "core.h" |
| 12 |
#include "debug.h" |
| 13 |
#include "debugfs_htt_stats.h" |
| 14 |
#include "debugfs_sta.h" |
| 15 |
#include "hal_desc.h" |
| 16 |
#include "hw.h" |
| 17 |
#include "dp_rx.h" |
| 18 |
#include "hal_rx.h" |
| 19 |
#include "dp_tx.h" |
| 20 |
#include "peer.h" |
| 21 |
|
| 22 |
#define ATH11K_DP_RX_FRAGMENT_TIMEOUT_MS (2 * HZ) |
| 23 |
|
| 24 |
static inline |
| 25 |
u8 *ath11k_dp_rx_h_80211_hdr(struct ath11k_base *ab, struct hal_rx_desc *desc) |
| 26 |
{ |
| 27 |
return ab->hw_params.hw_ops->rx_desc_get_hdr_status(desc); |
| 28 |
} |
| 29 |
|
| 30 |
static inline |
| 31 |
enum hal_encrypt_type ath11k_dp_rx_h_mpdu_start_enctype(struct ath11k_base *ab, |
| 32 |
struct hal_rx_desc *desc) |
| 33 |
{ |
| 34 |
if (!ab->hw_params.hw_ops->rx_desc_encrypt_valid(desc)) |
| 35 |
return HAL_ENCRYPT_TYPE_OPEN; |
| 36 |
|
| 37 |
return ab->hw_params.hw_ops->rx_desc_get_encrypt_type(desc); |
| 38 |
} |
| 39 |
|
| 40 |
static inline u8 ath11k_dp_rx_h_msdu_start_decap_type(struct ath11k_base *ab, |
| 41 |
struct hal_rx_desc *desc) |
| 42 |
{ |
| 43 |
return ab->hw_params.hw_ops->rx_desc_get_decap_type(desc); |
| 44 |
} |
| 45 |
|
| 46 |
static inline |
| 47 |
bool ath11k_dp_rx_h_msdu_start_ldpc_support(struct ath11k_base *ab, |
| 48 |
struct hal_rx_desc *desc) |
| 49 |
{ |
| 50 |
return ab->hw_params.hw_ops->rx_desc_get_ldpc_support(desc); |
| 51 |
} |
| 52 |
|
| 53 |
static inline |
| 54 |
u8 ath11k_dp_rx_h_msdu_start_mesh_ctl_present(struct ath11k_base *ab, |
| 55 |
struct hal_rx_desc *desc) |
| 56 |
{ |
| 57 |
return ab->hw_params.hw_ops->rx_desc_get_mesh_ctl(desc); |
| 58 |
} |
| 59 |
|
| 60 |
static inline |
| 61 |
bool ath11k_dp_rx_h_mpdu_start_seq_ctrl_valid(struct ath11k_base *ab, |
| 62 |
struct hal_rx_desc *desc) |
| 63 |
{ |
| 64 |
return ab->hw_params.hw_ops->rx_desc_get_mpdu_seq_ctl_vld(desc); |
| 65 |
} |
| 66 |
|
| 67 |
static inline bool ath11k_dp_rx_h_mpdu_start_fc_valid(struct ath11k_base *ab, |
| 68 |
struct hal_rx_desc *desc) |
| 69 |
{ |
| 70 |
return ab->hw_params.hw_ops->rx_desc_get_mpdu_fc_valid(desc); |
| 71 |
} |
| 72 |
|
| 73 |
static inline bool ath11k_dp_rx_h_mpdu_start_more_frags(struct ath11k_base *ab, |
| 74 |
struct sk_buff *skb) |
| 75 |
{ |
| 76 |
struct ieee80211_hdr *hdr; |
| 77 |
|
| 78 |
hdr = (struct ieee80211_hdr *)(skb->data + ab->hw_params.hal_desc_sz); |
| 79 |
return ieee80211_has_morefrags(hdr->frame_control); |
| 80 |
} |
| 81 |
|
| 82 |
static inline u16 ath11k_dp_rx_h_mpdu_start_frag_no(struct ath11k_base *ab, |
| 83 |
struct sk_buff *skb) |
| 84 |
{ |
| 85 |
struct ieee80211_hdr *hdr; |
| 86 |
|
| 87 |
hdr = (struct ieee80211_hdr *)(skb->data + ab->hw_params.hal_desc_sz); |
| 88 |
return le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG; |
| 89 |
} |
| 90 |
|
| 91 |
static inline u16 ath11k_dp_rx_h_mpdu_start_seq_no(struct ath11k_base *ab, |
| 92 |
struct hal_rx_desc *desc) |
| 93 |
{ |
| 94 |
return ab->hw_params.hw_ops->rx_desc_get_mpdu_start_seq_no(desc); |
| 95 |
} |
| 96 |
|
| 97 |
static inline void *ath11k_dp_rx_get_attention(struct ath11k_base *ab, |
| 98 |
struct hal_rx_desc *desc) |
| 99 |
{ |
| 100 |
return ab->hw_params.hw_ops->rx_desc_get_attention(desc); |
| 101 |
} |
| 102 |
|
| 103 |
static inline bool ath11k_dp_rx_h_attn_msdu_done(struct rx_attention *attn) |
| 104 |
{ |
| 105 |
return !!FIELD_GET(RX_ATTENTION_INFO2_MSDU_DONE, |
| 106 |
__le32_to_cpu(attn->info2)); |
| 107 |
} |
| 108 |
|
| 109 |
static inline bool ath11k_dp_rx_h_attn_l4_cksum_fail(struct rx_attention *attn) |
| 110 |
{ |
| 111 |
return !!FIELD_GET(RX_ATTENTION_INFO1_TCP_UDP_CKSUM_FAIL, |
| 112 |
__le32_to_cpu(attn->info1)); |
| 113 |
} |
| 114 |
|
| 115 |
static inline bool ath11k_dp_rx_h_attn_ip_cksum_fail(struct rx_attention *attn) |
| 116 |
{ |
| 117 |
return !!FIELD_GET(RX_ATTENTION_INFO1_IP_CKSUM_FAIL, |
| 118 |
__le32_to_cpu(attn->info1)); |
| 119 |
} |
| 120 |
|
| 121 |
static inline bool ath11k_dp_rx_h_attn_is_decrypted(struct rx_attention *attn) |
| 122 |
{ |
| 123 |
return (FIELD_GET(RX_ATTENTION_INFO2_DCRYPT_STATUS_CODE, |
| 124 |
__le32_to_cpu(attn->info2)) == |
| 125 |
RX_DESC_DECRYPT_STATUS_CODE_OK); |
| 126 |
} |
| 127 |
|
| 128 |
static u32 ath11k_dp_rx_h_attn_mpdu_err(struct rx_attention *attn) |
| 129 |
{ |
| 130 |
u32 info = __le32_to_cpu(attn->info1); |
| 131 |
u32 errmap = 0; |
| 132 |
|
| 133 |
if (info & RX_ATTENTION_INFO1_FCS_ERR) |
| 134 |
errmap |= DP_RX_MPDU_ERR_FCS; |
| 135 |
|
| 136 |
if (info & RX_ATTENTION_INFO1_DECRYPT_ERR) |
| 137 |
errmap |= DP_RX_MPDU_ERR_DECRYPT; |
| 138 |
|
| 139 |
if (info & RX_ATTENTION_INFO1_TKIP_MIC_ERR) |
| 140 |
errmap |= DP_RX_MPDU_ERR_TKIP_MIC; |
| 141 |
|
| 142 |
if (info & RX_ATTENTION_INFO1_A_MSDU_ERROR) |
| 143 |
errmap |= DP_RX_MPDU_ERR_AMSDU_ERR; |
| 144 |
|
| 145 |
if (info & RX_ATTENTION_INFO1_OVERFLOW_ERR) |
| 146 |
errmap |= DP_RX_MPDU_ERR_OVERFLOW; |
| 147 |
|
| 148 |
if (info & RX_ATTENTION_INFO1_MSDU_LEN_ERR) |
| 149 |
errmap |= DP_RX_MPDU_ERR_MSDU_LEN; |
| 150 |
|
| 151 |
if (info & RX_ATTENTION_INFO1_MPDU_LEN_ERR) |
| 152 |
errmap |= DP_RX_MPDU_ERR_MPDU_LEN; |
| 153 |
|
| 154 |
return errmap; |
| 155 |
} |
| 156 |
|
| 157 |
static bool ath11k_dp_rx_h_attn_msdu_len_err(struct ath11k_base *ab, |
| 158 |
struct hal_rx_desc *desc) |
| 159 |
{ |
| 160 |
struct rx_attention *rx_attention; |
| 161 |
u32 errmap; |
| 162 |
|
| 163 |
rx_attention = ath11k_dp_rx_get_attention(ab, desc); |
| 164 |
errmap = ath11k_dp_rx_h_attn_mpdu_err(rx_attention); |
| 165 |
|
| 166 |
return errmap & DP_RX_MPDU_ERR_MSDU_LEN; |
| 167 |
} |
| 168 |
|
| 169 |
static inline u16 ath11k_dp_rx_h_msdu_start_msdu_len(struct ath11k_base *ab, |
| 170 |
struct hal_rx_desc *desc) |
| 171 |
{ |
| 172 |
return ab->hw_params.hw_ops->rx_desc_get_msdu_len(desc); |
| 173 |
} |
| 174 |
|
| 175 |
static inline u8 ath11k_dp_rx_h_msdu_start_sgi(struct ath11k_base *ab, |
| 176 |
struct hal_rx_desc *desc) |
| 177 |
{ |
| 178 |
return ab->hw_params.hw_ops->rx_desc_get_msdu_sgi(desc); |
| 179 |
} |
| 180 |
|
| 181 |
static inline u8 ath11k_dp_rx_h_msdu_start_rate_mcs(struct ath11k_base *ab, |
| 182 |
struct hal_rx_desc *desc) |
| 183 |
{ |
| 184 |
return ab->hw_params.hw_ops->rx_desc_get_msdu_rate_mcs(desc); |
| 185 |
} |
| 186 |
|
| 187 |
static inline u8 ath11k_dp_rx_h_msdu_start_rx_bw(struct ath11k_base *ab, |
| 188 |
struct hal_rx_desc *desc) |
| 189 |
{ |
| 190 |
return ab->hw_params.hw_ops->rx_desc_get_msdu_rx_bw(desc); |
| 191 |
} |
| 192 |
|
| 193 |
static inline u32 ath11k_dp_rx_h_msdu_start_freq(struct ath11k_base *ab, |
| 194 |
struct hal_rx_desc *desc) |
| 195 |
{ |
| 196 |
return ab->hw_params.hw_ops->rx_desc_get_msdu_freq(desc); |
| 197 |
} |
| 198 |
|
| 199 |
static inline u8 ath11k_dp_rx_h_msdu_start_pkt_type(struct ath11k_base *ab, |
| 200 |
struct hal_rx_desc *desc) |
| 201 |
{ |
| 202 |
return ab->hw_params.hw_ops->rx_desc_get_msdu_pkt_type(desc); |
| 203 |
} |
| 204 |
|
| 205 |
static inline u8 ath11k_dp_rx_h_msdu_start_nss(struct ath11k_base *ab, |
| 206 |
struct hal_rx_desc *desc) |
| 207 |
{ |
| 208 |
return hweight8(ab->hw_params.hw_ops->rx_desc_get_msdu_nss(desc)); |
| 209 |
} |
| 210 |
|
| 211 |
static inline u8 ath11k_dp_rx_h_mpdu_start_tid(struct ath11k_base *ab, |
| 212 |
struct hal_rx_desc *desc) |
| 213 |
{ |
| 214 |
return ab->hw_params.hw_ops->rx_desc_get_mpdu_tid(desc); |
| 215 |
} |
| 216 |
|
| 217 |
static inline u16 ath11k_dp_rx_h_mpdu_start_peer_id(struct ath11k_base *ab, |
| 218 |
struct hal_rx_desc *desc) |
| 219 |
{ |
| 220 |
return ab->hw_params.hw_ops->rx_desc_get_mpdu_peer_id(desc); |
| 221 |
} |
| 222 |
|
| 223 |
static inline u8 ath11k_dp_rx_h_msdu_end_l3pad(struct ath11k_base *ab, |
| 224 |
struct hal_rx_desc *desc) |
| 225 |
{ |
| 226 |
return ab->hw_params.hw_ops->rx_desc_get_l3_pad_bytes(desc); |
| 227 |
} |
| 228 |
|
| 229 |
static inline bool ath11k_dp_rx_h_msdu_end_first_msdu(struct ath11k_base *ab, |
| 230 |
struct hal_rx_desc *desc) |
| 231 |
{ |
| 232 |
return ab->hw_params.hw_ops->rx_desc_get_first_msdu(desc); |
| 233 |
} |
| 234 |
|
| 235 |
static bool ath11k_dp_rx_h_msdu_end_last_msdu(struct ath11k_base *ab, |
| 236 |
struct hal_rx_desc *desc) |
| 237 |
{ |
| 238 |
return ab->hw_params.hw_ops->rx_desc_get_last_msdu(desc); |
| 239 |
} |
| 240 |
|
| 241 |
static void ath11k_dp_rx_desc_end_tlv_copy(struct ath11k_base *ab, |
| 242 |
struct hal_rx_desc *fdesc, |
| 243 |
struct hal_rx_desc *ldesc) |
| 244 |
{ |
| 245 |
ab->hw_params.hw_ops->rx_desc_copy_attn_end_tlv(fdesc, ldesc); |
| 246 |
} |
| 247 |
|
| 248 |
static inline u32 ath11k_dp_rxdesc_get_mpdulen_err(struct rx_attention *attn) |
| 249 |
{ |
| 250 |
return FIELD_GET(RX_ATTENTION_INFO1_MPDU_LEN_ERR, |
| 251 |
__le32_to_cpu(attn->info1)); |
| 252 |
} |
| 253 |
|
| 254 |
static inline u8 *ath11k_dp_rxdesc_get_80211hdr(struct ath11k_base *ab, |
| 255 |
struct hal_rx_desc *rx_desc) |
| 256 |
{ |
| 257 |
u8 *rx_pkt_hdr; |
| 258 |
|
| 259 |
rx_pkt_hdr = ab->hw_params.hw_ops->rx_desc_get_msdu_payload(rx_desc); |
| 260 |
|
| 261 |
return rx_pkt_hdr; |
| 262 |
} |
| 263 |
|
| 264 |
static inline bool ath11k_dp_rxdesc_mpdu_valid(struct ath11k_base *ab, |
| 265 |
struct hal_rx_desc *rx_desc) |
| 266 |
{ |
| 267 |
u32 tlv_tag; |
| 268 |
|
| 269 |
tlv_tag = ab->hw_params.hw_ops->rx_desc_get_mpdu_start_tag(rx_desc); |
| 270 |
|
| 271 |
return tlv_tag == HAL_RX_MPDU_START; |
| 272 |
} |
| 273 |
|
| 274 |
static inline u32 ath11k_dp_rxdesc_get_ppduid(struct ath11k_base *ab, |
| 275 |
struct hal_rx_desc *rx_desc) |
| 276 |
{ |
| 277 |
return ab->hw_params.hw_ops->rx_desc_get_mpdu_ppdu_id(rx_desc); |
| 278 |
} |
| 279 |
|
| 280 |
static inline void ath11k_dp_rxdesc_set_msdu_len(struct ath11k_base *ab, |
| 281 |
struct hal_rx_desc *desc, |
| 282 |
u16 len) |
| 283 |
{ |
| 284 |
ab->hw_params.hw_ops->rx_desc_set_msdu_len(desc, len); |
| 285 |
} |
| 286 |
|
| 287 |
static bool ath11k_dp_rx_h_attn_is_mcbc(struct ath11k_base *ab, |
| 288 |
struct hal_rx_desc *desc) |
| 289 |
{ |
| 290 |
struct rx_attention *attn = ath11k_dp_rx_get_attention(ab, desc); |
| 291 |
|
| 292 |
return ath11k_dp_rx_h_msdu_end_first_msdu(ab, desc) && |
| 293 |
(!!FIELD_GET(RX_ATTENTION_INFO1_MCAST_BCAST, |
| 294 |
__le32_to_cpu(attn->info1))); |
| 295 |
} |
| 296 |
|
| 297 |
static bool ath11k_dp_rxdesc_mac_addr2_valid(struct ath11k_base *ab, |
| 298 |
struct hal_rx_desc *desc) |
| 299 |
{ |
| 300 |
return ab->hw_params.hw_ops->rx_desc_mac_addr2_valid(desc); |
| 301 |
} |
| 302 |
|
| 303 |
static u8 *ath11k_dp_rxdesc_mpdu_start_addr2(struct ath11k_base *ab, |
| 304 |
struct hal_rx_desc *desc) |
| 305 |
{ |
| 306 |
return ab->hw_params.hw_ops->rx_desc_mpdu_start_addr2(desc); |
| 307 |
} |
| 308 |
|
| 309 |
static void ath11k_dp_service_mon_ring(struct timer_list *t) |
| 310 |
{ |
| 311 |
struct ath11k_base *ab = timer_container_of(ab, t, mon_reap_timer); |
| 312 |
int i; |
| 313 |
|
| 314 |
for (i = 0; i < ab->hw_params.num_rxdma_per_pdev; i++) |
| 315 |
ath11k_dp_rx_process_mon_rings(ab, i, NULL, DP_MON_SERVICE_BUDGET); |
| 316 |
|
| 317 |
mod_timer(&ab->mon_reap_timer, jiffies + |
| 318 |
msecs_to_jiffies(ATH11K_MON_TIMER_INTERVAL)); |
| 319 |
} |
| 320 |
|
| 321 |
static int ath11k_dp_purge_mon_ring(struct ath11k_base *ab) |
| 322 |
{ |
| 323 |
int i, reaped = 0; |
| 324 |
unsigned long timeout = jiffies + msecs_to_jiffies(DP_MON_PURGE_TIMEOUT_MS); |
| 325 |
|
| 326 |
do { |
| 327 |
for (i = 0; i < ab->hw_params.num_rxdma_per_pdev; i++) |
| 328 |
reaped += ath11k_dp_rx_process_mon_rings(ab, i, |
| 329 |
NULL, |
| 330 |
DP_MON_SERVICE_BUDGET); |
| 331 |
|
| 332 |
/* nothing more to reap */ |
| 333 |
if (reaped < DP_MON_SERVICE_BUDGET) |
| 334 |
return 0; |
| 335 |
|
| 336 |
} while (time_before(jiffies, timeout)); |
| 337 |
|
| 338 |
ath11k_warn(ab, "dp mon ring purge timeout"); |
| 339 |
|
| 340 |
return -ETIMEDOUT; |
| 341 |
} |
| 342 |
|
| 343 |
/* Returns number of Rx buffers replenished */ |
| 344 |
int ath11k_dp_rxbufs_replenish(struct ath11k_base *ab, int mac_id, |
| 345 |
struct dp_rxdma_ring *rx_ring, |
| 346 |
int req_entries, |
| 347 |
enum hal_rx_buf_return_buf_manager mgr) |
| 348 |
{ |
| 349 |
struct hal_srng *srng; |
| 350 |
u32 *desc; |
| 351 |
struct sk_buff *skb; |
| 352 |
int num_free; |
| 353 |
int num_remain; |
| 354 |
int buf_id; |
| 355 |
u32 cookie; |
| 356 |
dma_addr_t paddr; |
| 357 |
|
| 358 |
req_entries = min(req_entries, rx_ring->bufs_max); |
| 359 |
|
| 360 |
srng = &ab->hal.srng_list[rx_ring->refill_buf_ring.ring_id]; |
| 361 |
|
| 362 |
spin_lock_bh(&srng->lock); |
| 363 |
|
| 364 |
ath11k_hal_srng_access_begin(ab, srng); |
| 365 |
|
| 366 |
num_free = ath11k_hal_srng_src_num_free(ab, srng, true); |
| 367 |
if (!req_entries && (num_free > (rx_ring->bufs_max * 3) / 4)) |
| 368 |
req_entries = num_free; |
| 369 |
|
| 370 |
req_entries = min(num_free, req_entries); |
| 371 |
num_remain = req_entries; |
| 372 |
|
| 373 |
while (num_remain > 0) { |
| 374 |
skb = dev_alloc_skb(DP_RX_BUFFER_SIZE + |
| 375 |
DP_RX_BUFFER_ALIGN_SIZE); |
| 376 |
if (!skb) |
| 377 |
break; |
| 378 |
|
| 379 |
if (!IS_ALIGNED((unsigned long)skb->data, |
| 380 |
DP_RX_BUFFER_ALIGN_SIZE)) { |
| 381 |
skb_pull(skb, |
| 382 |
PTR_ALIGN(skb->data, DP_RX_BUFFER_ALIGN_SIZE) - |
| 383 |
skb->data); |
| 384 |
} |
| 385 |
|
| 386 |
paddr = dma_map_single(ab->dev, skb->data, |
| 387 |
skb->len + skb_tailroom(skb), |
| 388 |
DMA_FROM_DEVICE); |
| 389 |
if (dma_mapping_error(ab->dev, paddr)) |
| 390 |
goto fail_free_skb; |
| 391 |
|
| 392 |
spin_lock_bh(&rx_ring->idr_lock); |
| 393 |
buf_id = idr_alloc(&rx_ring->bufs_idr, skb, 1, |
| 394 |
(rx_ring->bufs_max * 3) + 1, GFP_ATOMIC); |
| 395 |
spin_unlock_bh(&rx_ring->idr_lock); |
| 396 |
if (buf_id <= 0) |
| 397 |
goto fail_dma_unmap; |
| 398 |
|
| 399 |
desc = ath11k_hal_srng_src_get_next_entry(ab, srng); |
| 400 |
if (!desc) |
| 401 |
goto fail_idr_remove; |
| 402 |
|
| 403 |
ATH11K_SKB_RXCB(skb)->paddr = paddr; |
| 404 |
|
| 405 |
cookie = FIELD_PREP(DP_RXDMA_BUF_COOKIE_PDEV_ID, mac_id) | |
| 406 |
FIELD_PREP(DP_RXDMA_BUF_COOKIE_BUF_ID, buf_id); |
| 407 |
|
| 408 |
num_remain--; |
| 409 |
|
| 410 |
ath11k_hal_rx_buf_addr_info_set(desc, paddr, cookie, mgr); |
| 411 |
} |
| 412 |
|
| 413 |
ath11k_hal_srng_access_end(ab, srng); |
| 414 |
|
| 415 |
spin_unlock_bh(&srng->lock); |
| 416 |
|
| 417 |
return req_entries - num_remain; |
| 418 |
|
| 419 |
fail_idr_remove: |
| 420 |
spin_lock_bh(&rx_ring->idr_lock); |
| 421 |
idr_remove(&rx_ring->bufs_idr, buf_id); |
| 422 |
spin_unlock_bh(&rx_ring->idr_lock); |
| 423 |
fail_dma_unmap: |
| 424 |
dma_unmap_single(ab->dev, paddr, skb->len + skb_tailroom(skb), |
| 425 |
DMA_FROM_DEVICE); |
| 426 |
fail_free_skb: |
| 427 |
dev_kfree_skb_any(skb); |
| 428 |
|
| 429 |
ath11k_hal_srng_access_end(ab, srng); |
| 430 |
|
| 431 |
spin_unlock_bh(&srng->lock); |
| 432 |
|
| 433 |
return req_entries - num_remain; |
| 434 |
} |
| 435 |
|
| 436 |
static int ath11k_dp_rxdma_buf_ring_free(struct ath11k *ar, |
| 437 |
struct dp_rxdma_ring *rx_ring) |
| 438 |
{ |
| 439 |
struct sk_buff *skb; |
| 440 |
int buf_id; |
| 441 |
|
| 442 |
spin_lock_bh(&rx_ring->idr_lock); |
| 443 |
idr_for_each_entry(&rx_ring->bufs_idr, skb, buf_id) { |
| 444 |
idr_remove(&rx_ring->bufs_idr, buf_id); |
| 445 |
/* TODO: Understand where internal driver does this dma_unmap |
| 446 |
* of rxdma_buffer. |
| 447 |
*/ |
| 448 |
dma_unmap_single(ar->ab->dev, ATH11K_SKB_RXCB(skb)->paddr, |
| 449 |
skb->len + skb_tailroom(skb), DMA_FROM_DEVICE); |
| 450 |
dev_kfree_skb_any(skb); |
| 451 |
} |
| 452 |
|
| 453 |
idr_destroy(&rx_ring->bufs_idr); |
| 454 |
spin_unlock_bh(&rx_ring->idr_lock); |
| 455 |
|
| 456 |
return 0; |
| 457 |
} |
| 458 |
|
| 459 |
static int ath11k_dp_rxdma_pdev_buf_free(struct ath11k *ar) |
| 460 |
{ |
| 461 |
struct ath11k_pdev_dp *dp = &ar->dp; |
| 462 |
struct ath11k_base *ab = ar->ab; |
| 463 |
struct dp_rxdma_ring *rx_ring = &dp->rx_refill_buf_ring; |
| 464 |
int i; |
| 465 |
|
| 466 |
ath11k_dp_rxdma_buf_ring_free(ar, rx_ring); |
| 467 |
|
| 468 |
rx_ring = &dp->rxdma_mon_buf_ring; |
| 469 |
ath11k_dp_rxdma_buf_ring_free(ar, rx_ring); |
| 470 |
|
| 471 |
for (i = 0; i < ab->hw_params.num_rxdma_per_pdev; i++) { |
| 472 |
rx_ring = &dp->rx_mon_status_refill_ring[i]; |
| 473 |
ath11k_dp_rxdma_buf_ring_free(ar, rx_ring); |
| 474 |
} |
| 475 |
|
| 476 |
return 0; |
| 477 |
} |
| 478 |
|
| 479 |
static int ath11k_dp_rxdma_ring_buf_setup(struct ath11k *ar, |
| 480 |
struct dp_rxdma_ring *rx_ring, |
| 481 |
u32 ringtype) |
| 482 |
{ |
| 483 |
struct ath11k_pdev_dp *dp = &ar->dp; |
| 484 |
int num_entries; |
| 485 |
|
| 486 |
num_entries = rx_ring->refill_buf_ring.size / |
| 487 |
ath11k_hal_srng_get_entrysize(ar->ab, ringtype); |
| 488 |
|
| 489 |
rx_ring->bufs_max = num_entries; |
| 490 |
ath11k_dp_rxbufs_replenish(ar->ab, dp->mac_id, rx_ring, num_entries, |
| 491 |
ar->ab->hw_params.hal_params->rx_buf_rbm); |
| 492 |
return 0; |
| 493 |
} |
| 494 |
|
| 495 |
static int ath11k_dp_rxdma_pdev_buf_setup(struct ath11k *ar) |
| 496 |
{ |
| 497 |
struct ath11k_pdev_dp *dp = &ar->dp; |
| 498 |
struct ath11k_base *ab = ar->ab; |
| 499 |
struct dp_rxdma_ring *rx_ring = &dp->rx_refill_buf_ring; |
| 500 |
int i; |
| 501 |
|
| 502 |
ath11k_dp_rxdma_ring_buf_setup(ar, rx_ring, HAL_RXDMA_BUF); |
| 503 |
|
| 504 |
if (ar->ab->hw_params.rxdma1_enable) { |
| 505 |
rx_ring = &dp->rxdma_mon_buf_ring; |
| 506 |
ath11k_dp_rxdma_ring_buf_setup(ar, rx_ring, HAL_RXDMA_MONITOR_BUF); |
| 507 |
} |
| 508 |
|
| 509 |
for (i = 0; i < ab->hw_params.num_rxdma_per_pdev; i++) { |
| 510 |
rx_ring = &dp->rx_mon_status_refill_ring[i]; |
| 511 |
ath11k_dp_rxdma_ring_buf_setup(ar, rx_ring, HAL_RXDMA_MONITOR_STATUS); |
| 512 |
} |
| 513 |
|
| 514 |
return 0; |
| 515 |
} |
| 516 |
|
| 517 |
static void ath11k_dp_rx_pdev_srng_free(struct ath11k *ar) |
| 518 |
{ |
| 519 |
struct ath11k_pdev_dp *dp = &ar->dp; |
| 520 |
struct ath11k_base *ab = ar->ab; |
| 521 |
int i; |
| 522 |
|
| 523 |
ath11k_dp_srng_cleanup(ab, &dp->rx_refill_buf_ring.refill_buf_ring); |
| 524 |
|
| 525 |
for (i = 0; i < ab->hw_params.num_rxdma_per_pdev; i++) { |
| 526 |
if (ab->hw_params.rx_mac_buf_ring) |
| 527 |
ath11k_dp_srng_cleanup(ab, &dp->rx_mac_buf_ring[i]); |
| 528 |
|
| 529 |
ath11k_dp_srng_cleanup(ab, &dp->rxdma_err_dst_ring[i]); |
| 530 |
ath11k_dp_srng_cleanup(ab, |
| 531 |
&dp->rx_mon_status_refill_ring[i].refill_buf_ring); |
| 532 |
} |
| 533 |
|
| 534 |
ath11k_dp_srng_cleanup(ab, &dp->rxdma_mon_buf_ring.refill_buf_ring); |
| 535 |
} |
| 536 |
|
| 537 |
void ath11k_dp_pdev_reo_cleanup(struct ath11k_base *ab) |
| 538 |
{ |
| 539 |
struct ath11k_dp *dp = &ab->dp; |
| 540 |
int i; |
| 541 |
|
| 542 |
for (i = 0; i < DP_REO_DST_RING_MAX; i++) |
| 543 |
ath11k_dp_srng_cleanup(ab, &dp->reo_dst_ring[i]); |
| 544 |
} |
| 545 |
|
| 546 |
int ath11k_dp_pdev_reo_setup(struct ath11k_base *ab) |
| 547 |
{ |
| 548 |
struct ath11k_dp *dp = &ab->dp; |
| 549 |
int ret; |
| 550 |
int i; |
| 551 |
|
| 552 |
for (i = 0; i < DP_REO_DST_RING_MAX; i++) { |
| 553 |
ret = ath11k_dp_srng_setup(ab, &dp->reo_dst_ring[i], |
| 554 |
HAL_REO_DST, i, 0, |
| 555 |
DP_REO_DST_RING_SIZE); |
| 556 |
if (ret) { |
| 557 |
ath11k_warn(ab, "failed to setup reo_dst_ring\n"); |
| 558 |
goto err_reo_cleanup; |
| 559 |
} |
| 560 |
} |
| 561 |
|
| 562 |
return 0; |
| 563 |
|
| 564 |
err_reo_cleanup: |
| 565 |
ath11k_dp_pdev_reo_cleanup(ab); |
| 566 |
|
| 567 |
return ret; |
| 568 |
} |
| 569 |
|
| 570 |
static int ath11k_dp_rx_pdev_srng_alloc(struct ath11k *ar) |
| 571 |
{ |
| 572 |
struct ath11k_pdev_dp *dp = &ar->dp; |
| 573 |
struct ath11k_base *ab = ar->ab; |
| 574 |
struct dp_srng *srng = NULL; |
| 575 |
int i; |
| 576 |
int ret; |
| 577 |
|
| 578 |
ret = ath11k_dp_srng_setup(ar->ab, |
| 579 |
&dp->rx_refill_buf_ring.refill_buf_ring, |
| 580 |
HAL_RXDMA_BUF, 0, |
| 581 |
dp->mac_id, DP_RXDMA_BUF_RING_SIZE); |
| 582 |
if (ret) { |
| 583 |
ath11k_warn(ar->ab, "failed to setup rx_refill_buf_ring\n"); |
| 584 |
return ret; |
| 585 |
} |
| 586 |
|
| 587 |
if (ar->ab->hw_params.rx_mac_buf_ring) { |
| 588 |
for (i = 0; i < ab->hw_params.num_rxdma_per_pdev; i++) { |
| 589 |
ret = ath11k_dp_srng_setup(ar->ab, |
| 590 |
&dp->rx_mac_buf_ring[i], |
| 591 |
HAL_RXDMA_BUF, 1, |
| 592 |
dp->mac_id + i, 1024); |
| 593 |
if (ret) { |
| 594 |
ath11k_warn(ar->ab, "failed to setup rx_mac_buf_ring %d\n", |
| 595 |
i); |
| 596 |
return ret; |
| 597 |
} |
| 598 |
} |
| 599 |
} |
| 600 |
|
| 601 |
for (i = 0; i < ab->hw_params.num_rxdma_per_pdev; i++) { |
| 602 |
ret = ath11k_dp_srng_setup(ar->ab, &dp->rxdma_err_dst_ring[i], |
| 603 |
HAL_RXDMA_DST, 0, dp->mac_id + i, |
| 604 |
DP_RXDMA_ERR_DST_RING_SIZE); |
| 605 |
if (ret) { |
| 606 |
ath11k_warn(ar->ab, "failed to setup rxdma_err_dst_ring %d\n", i); |
| 607 |
return ret; |
| 608 |
} |
| 609 |
} |
| 610 |
|
| 611 |
for (i = 0; i < ab->hw_params.num_rxdma_per_pdev; i++) { |
| 612 |
srng = &dp->rx_mon_status_refill_ring[i].refill_buf_ring; |
| 613 |
ret = ath11k_dp_srng_setup(ar->ab, |
| 614 |
srng, |
| 615 |
HAL_RXDMA_MONITOR_STATUS, 0, dp->mac_id + i, |
| 616 |
DP_RXDMA_MON_STATUS_RING_SIZE); |
| 617 |
if (ret) { |
| 618 |
ath11k_warn(ar->ab, |
| 619 |
"failed to setup rx_mon_status_refill_ring %d\n", i); |
| 620 |
return ret; |
| 621 |
} |
| 622 |
} |
| 623 |
|
| 624 |
/* if rxdma1_enable is false, then it doesn't need |
| 625 |
* to setup rxdam_mon_buf_ring, rxdma_mon_dst_ring |
| 626 |
* and rxdma_mon_desc_ring. |
| 627 |
* init reap timer for QCA6390. |
| 628 |
*/ |
| 629 |
if (!ar->ab->hw_params.rxdma1_enable) { |
| 630 |
//init mon status buffer reap timer |
| 631 |
timer_setup(&ar->ab->mon_reap_timer, |
| 632 |
ath11k_dp_service_mon_ring, 0); |
| 633 |
return 0; |
| 634 |
} |
| 635 |
|
| 636 |
ret = ath11k_dp_srng_setup(ar->ab, |
| 637 |
&dp->rxdma_mon_buf_ring.refill_buf_ring, |
| 638 |
HAL_RXDMA_MONITOR_BUF, 0, dp->mac_id, |
| 639 |
DP_RXDMA_MONITOR_BUF_RING_SIZE); |
| 640 |
if (ret) { |
| 641 |
ath11k_warn(ar->ab, |
| 642 |
"failed to setup HAL_RXDMA_MONITOR_BUF\n"); |
| 643 |
return ret; |
| 644 |
} |
| 645 |
|
| 646 |
ret = ath11k_dp_srng_setup(ar->ab, &dp->rxdma_mon_dst_ring, |
| 647 |
HAL_RXDMA_MONITOR_DST, 0, dp->mac_id, |
| 648 |
DP_RXDMA_MONITOR_DST_RING_SIZE); |
| 649 |
if (ret) { |
| 650 |
ath11k_warn(ar->ab, |
| 651 |
"failed to setup HAL_RXDMA_MONITOR_DST\n"); |
| 652 |
return ret; |
| 653 |
} |
| 654 |
|
| 655 |
ret = ath11k_dp_srng_setup(ar->ab, &dp->rxdma_mon_desc_ring, |
| 656 |
HAL_RXDMA_MONITOR_DESC, 0, dp->mac_id, |
| 657 |
DP_RXDMA_MONITOR_DESC_RING_SIZE); |
| 658 |
if (ret) { |
| 659 |
ath11k_warn(ar->ab, |
| 660 |
"failed to setup HAL_RXDMA_MONITOR_DESC\n"); |
| 661 |
return ret; |
| 662 |
} |
| 663 |
|
| 664 |
return 0; |
| 665 |
} |
| 666 |
|
| 667 |
void ath11k_dp_reo_cmd_list_cleanup(struct ath11k_base *ab) |
| 668 |
{ |
| 669 |
struct ath11k_dp *dp = &ab->dp; |
| 670 |
struct dp_reo_cmd *cmd, *tmp; |
| 671 |
struct dp_reo_cache_flush_elem *cmd_cache, *tmp_cache; |
| 672 |
struct dp_rx_tid *rx_tid; |
| 673 |
|
| 674 |
spin_lock_bh(&dp->reo_cmd_lock); |
| 675 |
list_for_each_entry_safe(cmd, tmp, &dp->reo_cmd_list, list) { |
| 676 |
list_del(&cmd->list); |
| 677 |
rx_tid = &cmd->data; |
| 678 |
if (rx_tid->vaddr_unaligned) { |
| 679 |
dma_free_noncoherent(ab->dev, rx_tid->unaligned_size, |
| 680 |
rx_tid->vaddr_unaligned, |
| 681 |
rx_tid->paddr_unaligned, DMA_BIDIRECTIONAL); |
| 682 |
rx_tid->vaddr_unaligned = NULL; |
| 683 |
} |
| 684 |
kfree(cmd); |
| 685 |
} |
| 686 |
|
| 687 |
list_for_each_entry_safe(cmd_cache, tmp_cache, |
| 688 |
&dp->reo_cmd_cache_flush_list, list) { |
| 689 |
list_del(&cmd_cache->list); |
| 690 |
dp->reo_cmd_cache_flush_count--; |
| 691 |
rx_tid = &cmd_cache->data; |
| 692 |
if (rx_tid->vaddr_unaligned) { |
| 693 |
dma_free_noncoherent(ab->dev, rx_tid->unaligned_size, |
| 694 |
rx_tid->vaddr_unaligned, |
| 695 |
rx_tid->paddr_unaligned, DMA_BIDIRECTIONAL); |
| 696 |
rx_tid->vaddr_unaligned = NULL; |
| 697 |
} |
| 698 |
kfree(cmd_cache); |
| 699 |
} |
| 700 |
spin_unlock_bh(&dp->reo_cmd_lock); |
| 701 |
} |
| 702 |
|
| 703 |
static void ath11k_dp_reo_cmd_free(struct ath11k_dp *dp, void *ctx, |
| 704 |
enum hal_reo_cmd_status status) |
| 705 |
{ |
| 706 |
struct dp_rx_tid *rx_tid = ctx; |
| 707 |
|
| 708 |
if (status != HAL_REO_CMD_SUCCESS) |
| 709 |
ath11k_warn(dp->ab, "failed to flush rx tid hw desc, tid %d status %d\n", |
| 710 |
rx_tid->tid, status); |
| 711 |
if (rx_tid->vaddr_unaligned) { |
| 712 |
dma_free_noncoherent(dp->ab->dev, rx_tid->unaligned_size, |
| 713 |
rx_tid->vaddr_unaligned, |
| 714 |
rx_tid->paddr_unaligned, DMA_BIDIRECTIONAL); |
| 715 |
rx_tid->vaddr_unaligned = NULL; |
| 716 |
} |
| 717 |
} |
| 718 |
|
| 719 |
static void ath11k_dp_reo_cache_flush(struct ath11k_base *ab, |
| 720 |
struct dp_rx_tid *rx_tid) |
| 721 |
{ |
| 722 |
struct ath11k_hal_reo_cmd cmd = {}; |
| 723 |
unsigned long tot_desc_sz, desc_sz; |
| 724 |
int ret; |
| 725 |
|
| 726 |
tot_desc_sz = rx_tid->size; |
| 727 |
desc_sz = ath11k_hal_reo_qdesc_size(0, HAL_DESC_REO_NON_QOS_TID); |
| 728 |
|
| 729 |
while (tot_desc_sz > desc_sz) { |
| 730 |
tot_desc_sz -= desc_sz; |
| 731 |
cmd.addr_lo = lower_32_bits(rx_tid->paddr + tot_desc_sz); |
| 732 |
cmd.addr_hi = upper_32_bits(rx_tid->paddr); |
| 733 |
ret = ath11k_dp_tx_send_reo_cmd(ab, rx_tid, |
| 734 |
HAL_REO_CMD_FLUSH_CACHE, &cmd, |
| 735 |
NULL); |
| 736 |
if (ret) |
| 737 |
ath11k_warn(ab, |
| 738 |
"failed to send HAL_REO_CMD_FLUSH_CACHE, tid %d (%d)\n", |
| 739 |
rx_tid->tid, ret); |
| 740 |
} |
| 741 |
|
| 742 |
memset(&cmd, 0, sizeof(cmd)); |
| 743 |
cmd.addr_lo = lower_32_bits(rx_tid->paddr); |
| 744 |
cmd.addr_hi = upper_32_bits(rx_tid->paddr); |
| 745 |
cmd.flag |= HAL_REO_CMD_FLG_NEED_STATUS; |
| 746 |
ret = ath11k_dp_tx_send_reo_cmd(ab, rx_tid, |
| 747 |
HAL_REO_CMD_FLUSH_CACHE, |
| 748 |
&cmd, ath11k_dp_reo_cmd_free); |
| 749 |
if (ret) { |
| 750 |
ath11k_err(ab, "failed to send HAL_REO_CMD_FLUSH_CACHE cmd, tid %d (%d)\n", |
| 751 |
rx_tid->tid, ret); |
| 752 |
dma_free_noncoherent(ab->dev, rx_tid->unaligned_size, |
| 753 |
rx_tid->vaddr_unaligned, |
| 754 |
rx_tid->paddr_unaligned, DMA_BIDIRECTIONAL); |
| 755 |
rx_tid->vaddr_unaligned = NULL; |
| 756 |
} |
| 757 |
} |
| 758 |
|
| 759 |
static void ath11k_dp_rx_tid_del_func(struct ath11k_dp *dp, void *ctx, |
| 760 |
enum hal_reo_cmd_status status) |
| 761 |
{ |
| 762 |
struct ath11k_base *ab = dp->ab; |
| 763 |
struct dp_rx_tid *rx_tid = ctx; |
| 764 |
struct dp_reo_cache_flush_elem *elem, *tmp; |
| 765 |
|
| 766 |
if (status == HAL_REO_CMD_DRAIN) { |
| 767 |
goto free_desc; |
| 768 |
} else if (status != HAL_REO_CMD_SUCCESS) { |
| 769 |
/* Shouldn't happen! Cleanup in case of other failure? */ |
| 770 |
ath11k_warn(ab, "failed to delete rx tid %d hw descriptor %d\n", |
| 771 |
rx_tid->tid, status); |
| 772 |
return; |
| 773 |
} |
| 774 |
|
| 775 |
elem = kzalloc_obj(*elem, GFP_ATOMIC); |
| 776 |
if (!elem) |
| 777 |
goto free_desc; |
| 778 |
|
| 779 |
elem->ts = jiffies; |
| 780 |
memcpy(&elem->data, rx_tid, sizeof(*rx_tid)); |
| 781 |
|
| 782 |
spin_lock_bh(&dp->reo_cmd_lock); |
| 783 |
list_add_tail(&elem->list, &dp->reo_cmd_cache_flush_list); |
| 784 |
dp->reo_cmd_cache_flush_count++; |
| 785 |
|
| 786 |
/* Flush and invalidate aged REO desc from HW cache */ |
| 787 |
list_for_each_entry_safe(elem, tmp, &dp->reo_cmd_cache_flush_list, |
| 788 |
list) { |
| 789 |
if (dp->reo_cmd_cache_flush_count > DP_REO_DESC_FREE_THRESHOLD || |
| 790 |
time_after(jiffies, elem->ts + |
| 791 |
msecs_to_jiffies(DP_REO_DESC_FREE_TIMEOUT_MS))) { |
| 792 |
list_del(&elem->list); |
| 793 |
dp->reo_cmd_cache_flush_count--; |
| 794 |
spin_unlock_bh(&dp->reo_cmd_lock); |
| 795 |
|
| 796 |
ath11k_dp_reo_cache_flush(ab, &elem->data); |
| 797 |
kfree(elem); |
| 798 |
spin_lock_bh(&dp->reo_cmd_lock); |
| 799 |
} |
| 800 |
} |
| 801 |
spin_unlock_bh(&dp->reo_cmd_lock); |
| 802 |
|
| 803 |
return; |
| 804 |
free_desc: |
| 805 |
dma_free_noncoherent(ab->dev, rx_tid->unaligned_size, |
| 806 |
rx_tid->vaddr_unaligned, |
| 807 |
rx_tid->paddr_unaligned, DMA_BIDIRECTIONAL); |
| 808 |
rx_tid->vaddr_unaligned = NULL; |
| 809 |
} |
| 810 |
|
| 811 |
void ath11k_peer_rx_tid_delete(struct ath11k *ar, |
| 812 |
struct ath11k_peer *peer, u8 tid) |
| 813 |
{ |
| 814 |
struct ath11k_hal_reo_cmd cmd = {}; |
| 815 |
struct dp_rx_tid *rx_tid = &peer->rx_tid[tid]; |
| 816 |
int ret; |
| 817 |
|
| 818 |
if (!rx_tid->active) |
| 819 |
return; |
| 820 |
|
| 821 |
rx_tid->active = false; |
| 822 |
|
| 823 |
cmd.flag = HAL_REO_CMD_FLG_NEED_STATUS; |
| 824 |
cmd.addr_lo = lower_32_bits(rx_tid->paddr); |
| 825 |
cmd.addr_hi = upper_32_bits(rx_tid->paddr); |
| 826 |
cmd.upd0 |= HAL_REO_CMD_UPD0_VLD; |
| 827 |
ret = ath11k_dp_tx_send_reo_cmd(ar->ab, rx_tid, |
| 828 |
HAL_REO_CMD_UPDATE_RX_QUEUE, &cmd, |
| 829 |
ath11k_dp_rx_tid_del_func); |
| 830 |
if (ret) { |
| 831 |
if (ret != -ESHUTDOWN) |
| 832 |
ath11k_err(ar->ab, "failed to send HAL_REO_CMD_UPDATE_RX_QUEUE cmd, tid %d (%d)\n", |
| 833 |
tid, ret); |
| 834 |
dma_free_noncoherent(ar->ab->dev, rx_tid->unaligned_size, |
| 835 |
rx_tid->vaddr_unaligned, |
| 836 |
rx_tid->paddr_unaligned, DMA_BIDIRECTIONAL); |
| 837 |
rx_tid->vaddr_unaligned = NULL; |
| 838 |
} |
| 839 |
|
| 840 |
rx_tid->paddr = 0; |
| 841 |
rx_tid->paddr_unaligned = 0; |
| 842 |
rx_tid->size = 0; |
| 843 |
rx_tid->unaligned_size = 0; |
| 844 |
} |
| 845 |
|
| 846 |
static int ath11k_dp_rx_link_desc_return(struct ath11k_base *ab, |
| 847 |
u32 *link_desc, |
| 848 |
enum hal_wbm_rel_bm_act action) |
| 849 |
{ |
| 850 |
struct ath11k_dp *dp = &ab->dp; |
| 851 |
struct hal_srng *srng; |
| 852 |
u32 *desc; |
| 853 |
int ret = 0; |
| 854 |
|
| 855 |
srng = &ab->hal.srng_list[dp->wbm_desc_rel_ring.ring_id]; |
| 856 |
|
| 857 |
spin_lock_bh(&srng->lock); |
| 858 |
|
| 859 |
ath11k_hal_srng_access_begin(ab, srng); |
| 860 |
|
| 861 |
desc = ath11k_hal_srng_src_get_next_entry(ab, srng); |
| 862 |
if (!desc) { |
| 863 |
ret = -ENOBUFS; |
| 864 |
goto exit; |
| 865 |
} |
| 866 |
|
| 867 |
ath11k_hal_rx_msdu_link_desc_set(ab, (void *)desc, (void *)link_desc, |
| 868 |
action); |
| 869 |
|
| 870 |
exit: |
| 871 |
ath11k_hal_srng_access_end(ab, srng); |
| 872 |
|
| 873 |
spin_unlock_bh(&srng->lock); |
| 874 |
|
| 875 |
return ret; |
| 876 |
} |
| 877 |
|
| 878 |
static void ath11k_dp_rx_frags_cleanup(struct dp_rx_tid *rx_tid, bool rel_link_desc) |
| 879 |
{ |
| 880 |
struct ath11k_base *ab = rx_tid->ab; |
| 881 |
|
| 882 |
lockdep_assert_held(&ab->base_lock); |
| 883 |
|
| 884 |
if (rx_tid->dst_ring_desc) { |
| 885 |
if (rel_link_desc) |
| 886 |
ath11k_dp_rx_link_desc_return(ab, (u32 *)rx_tid->dst_ring_desc, |
| 887 |
HAL_WBM_REL_BM_ACT_PUT_IN_IDLE); |
| 888 |
kfree(rx_tid->dst_ring_desc); |
| 889 |
rx_tid->dst_ring_desc = NULL; |
| 890 |
} |
| 891 |
|
| 892 |
rx_tid->cur_sn = 0; |
| 893 |
rx_tid->last_frag_no = 0; |
| 894 |
rx_tid->rx_frag_bitmap = 0; |
| 895 |
__skb_queue_purge(&rx_tid->rx_frags); |
| 896 |
} |
| 897 |
|
| 898 |
void ath11k_peer_frags_flush(struct ath11k *ar, struct ath11k_peer *peer) |
| 899 |
{ |
| 900 |
struct dp_rx_tid *rx_tid; |
| 901 |
int i; |
| 902 |
|
| 903 |
lockdep_assert_held(&ar->ab->base_lock); |
| 904 |
|
| 905 |
for (i = 0; i <= IEEE80211_NUM_TIDS; i++) { |
| 906 |
rx_tid = &peer->rx_tid[i]; |
| 907 |
|
| 908 |
spin_unlock_bh(&ar->ab->base_lock); |
| 909 |
timer_delete_sync(&rx_tid->frag_timer); |
| 910 |
spin_lock_bh(&ar->ab->base_lock); |
| 911 |
|
| 912 |
ath11k_dp_rx_frags_cleanup(rx_tid, true); |
| 913 |
} |
| 914 |
} |
| 915 |
|
| 916 |
void ath11k_peer_rx_tid_cleanup(struct ath11k *ar, struct ath11k_peer *peer) |
| 917 |
{ |
| 918 |
struct dp_rx_tid *rx_tid; |
| 919 |
int i; |
| 920 |
|
| 921 |
lockdep_assert_held(&ar->ab->base_lock); |
| 922 |
|
| 923 |
for (i = 0; i <= IEEE80211_NUM_TIDS; i++) { |
| 924 |
rx_tid = &peer->rx_tid[i]; |
| 925 |
|
| 926 |
ath11k_peer_rx_tid_delete(ar, peer, i); |
| 927 |
ath11k_dp_rx_frags_cleanup(rx_tid, true); |
| 928 |
|
| 929 |
spin_unlock_bh(&ar->ab->base_lock); |
| 930 |
timer_delete_sync(&rx_tid->frag_timer); |
| 931 |
spin_lock_bh(&ar->ab->base_lock); |
| 932 |
} |
| 933 |
} |
| 934 |
|
| 935 |
static int ath11k_peer_rx_tid_reo_update(struct ath11k *ar, |
| 936 |
struct ath11k_peer *peer, |
| 937 |
struct dp_rx_tid *rx_tid, |
| 938 |
u32 ba_win_sz, u16 ssn, |
| 939 |
bool update_ssn) |
| 940 |
{ |
| 941 |
struct ath11k_hal_reo_cmd cmd = {}; |
| 942 |
int ret; |
| 943 |
|
| 944 |
cmd.addr_lo = lower_32_bits(rx_tid->paddr); |
| 945 |
cmd.addr_hi = upper_32_bits(rx_tid->paddr); |
| 946 |
cmd.flag = HAL_REO_CMD_FLG_NEED_STATUS; |
| 947 |
cmd.upd0 = HAL_REO_CMD_UPD0_BA_WINDOW_SIZE; |
| 948 |
cmd.ba_window_size = ba_win_sz; |
| 949 |
|
| 950 |
if (update_ssn) { |
| 951 |
cmd.upd0 |= HAL_REO_CMD_UPD0_SSN; |
| 952 |
cmd.upd2 = FIELD_PREP(HAL_REO_CMD_UPD2_SSN, ssn); |
| 953 |
} |
| 954 |
|
| 955 |
ret = ath11k_dp_tx_send_reo_cmd(ar->ab, rx_tid, |
| 956 |
HAL_REO_CMD_UPDATE_RX_QUEUE, &cmd, |
| 957 |
NULL); |
| 958 |
if (ret) { |
| 959 |
ath11k_warn(ar->ab, "failed to update rx tid queue, tid %d (%d)\n", |
| 960 |
rx_tid->tid, ret); |
| 961 |
return ret; |
| 962 |
} |
| 963 |
|
| 964 |
rx_tid->ba_win_sz = ba_win_sz; |
| 965 |
|
| 966 |
return 0; |
| 967 |
} |
| 968 |
|
| 969 |
static void ath11k_dp_rx_tid_mem_free(struct ath11k_base *ab, |
| 970 |
const u8 *peer_mac, int vdev_id, u8 tid) |
| 971 |
{ |
| 972 |
struct ath11k_peer *peer; |
| 973 |
struct dp_rx_tid *rx_tid; |
| 974 |
|
| 975 |
spin_lock_bh(&ab->base_lock); |
| 976 |
|
| 977 |
peer = ath11k_peer_find(ab, vdev_id, peer_mac); |
| 978 |
if (!peer) { |
| 979 |
ath11k_warn(ab, "failed to find the peer to free up rx tid mem\n"); |
| 980 |
goto unlock_exit; |
| 981 |
} |
| 982 |
|
| 983 |
rx_tid = &peer->rx_tid[tid]; |
| 984 |
if (!rx_tid->active) |
| 985 |
goto unlock_exit; |
| 986 |
|
| 987 |
dma_free_noncoherent(ab->dev, rx_tid->unaligned_size, rx_tid->vaddr_unaligned, |
| 988 |
rx_tid->paddr_unaligned, DMA_BIDIRECTIONAL); |
| 989 |
rx_tid->vaddr_unaligned = NULL; |
| 990 |
|
| 991 |
rx_tid->active = false; |
| 992 |
|
| 993 |
unlock_exit: |
| 994 |
spin_unlock_bh(&ab->base_lock); |
| 995 |
} |
| 996 |
|
| 997 |
int ath11k_peer_rx_tid_setup(struct ath11k *ar, const u8 *peer_mac, int vdev_id, |
| 998 |
u8 tid, u32 ba_win_sz, u16 ssn, |
| 999 |
enum hal_pn_type pn_type) |
| 1000 |
{ |
| 1001 |
struct ath11k_base *ab = ar->ab; |
| 1002 |
struct ath11k_peer *peer; |
| 1003 |
struct dp_rx_tid *rx_tid; |
| 1004 |
u32 hw_desc_sz, *vaddr; |
| 1005 |
void *vaddr_unaligned; |
| 1006 |
dma_addr_t paddr; |
| 1007 |
int ret; |
| 1008 |
|
| 1009 |
spin_lock_bh(&ab->base_lock); |
| 1010 |
|
| 1011 |
peer = ath11k_peer_find(ab, vdev_id, peer_mac); |
| 1012 |
if (!peer) { |
| 1013 |
ath11k_warn(ab, "failed to find the peer %pM to set up rx tid\n", |
| 1014 |
peer_mac); |
| 1015 |
spin_unlock_bh(&ab->base_lock); |
| 1016 |
return -ENOENT; |
| 1017 |
} |
| 1018 |
|
| 1019 |
rx_tid = &peer->rx_tid[tid]; |
| 1020 |
/* Update the tid queue if it is already setup */ |
| 1021 |
if (rx_tid->active) { |
| 1022 |
paddr = rx_tid->paddr; |
| 1023 |
ret = ath11k_peer_rx_tid_reo_update(ar, peer, rx_tid, |
| 1024 |
ba_win_sz, ssn, true); |
| 1025 |
spin_unlock_bh(&ab->base_lock); |
| 1026 |
if (ret) { |
| 1027 |
ath11k_warn(ab, "failed to update reo for peer %pM rx tid %d\n: %d", |
| 1028 |
peer_mac, tid, ret); |
| 1029 |
return ret; |
| 1030 |
} |
| 1031 |
|
| 1032 |
ret = ath11k_wmi_peer_rx_reorder_queue_setup(ar, vdev_id, |
| 1033 |
peer_mac, paddr, |
| 1034 |
tid, 1, ba_win_sz); |
| 1035 |
if (ret) |
| 1036 |
ath11k_warn(ab, "failed to send wmi rx reorder queue for peer %pM tid %d: %d\n", |
| 1037 |
peer_mac, tid, ret); |
| 1038 |
return ret; |
| 1039 |
} |
| 1040 |
|
| 1041 |
rx_tid->tid = tid; |
| 1042 |
|
| 1043 |
rx_tid->ba_win_sz = ba_win_sz; |
| 1044 |
|
| 1045 |
/* TODO: Optimize the memory allocation for qos tid based on |
| 1046 |
* the actual BA window size in REO tid update path. |
| 1047 |
*/ |
| 1048 |
if (tid == HAL_DESC_REO_NON_QOS_TID) |
| 1049 |
hw_desc_sz = ath11k_hal_reo_qdesc_size(ba_win_sz, tid); |
| 1050 |
else |
| 1051 |
hw_desc_sz = ath11k_hal_reo_qdesc_size(DP_BA_WIN_SZ_MAX, tid); |
| 1052 |
|
| 1053 |
rx_tid->unaligned_size = hw_desc_sz + HAL_LINK_DESC_ALIGN - 1; |
| 1054 |
vaddr_unaligned = dma_alloc_noncoherent(ab->dev, rx_tid->unaligned_size, &paddr, |
| 1055 |
DMA_BIDIRECTIONAL, GFP_ATOMIC); |
| 1056 |
if (!vaddr_unaligned) { |
| 1057 |
spin_unlock_bh(&ab->base_lock); |
| 1058 |
return -ENOMEM; |
| 1059 |
} |
| 1060 |
|
| 1061 |
rx_tid->vaddr_unaligned = vaddr_unaligned; |
| 1062 |
vaddr = PTR_ALIGN(vaddr_unaligned, HAL_LINK_DESC_ALIGN); |
| 1063 |
rx_tid->paddr_unaligned = paddr; |
| 1064 |
rx_tid->paddr = rx_tid->paddr_unaligned + ((unsigned long)vaddr - |
| 1065 |
(unsigned long)rx_tid->vaddr_unaligned); |
| 1066 |
ath11k_hal_reo_qdesc_setup(vaddr, tid, ba_win_sz, ssn, pn_type); |
| 1067 |
rx_tid->size = hw_desc_sz; |
| 1068 |
rx_tid->active = true; |
| 1069 |
|
| 1070 |
/* After dma_alloc_noncoherent, vaddr is being modified for reo qdesc setup. |
| 1071 |
* Since these changes are not reflected in the device, driver now needs to |
| 1072 |
* explicitly call dma_sync_single_for_device. |
| 1073 |
*/ |
| 1074 |
dma_sync_single_for_device(ab->dev, rx_tid->paddr, |
| 1075 |
rx_tid->size, |
| 1076 |
DMA_TO_DEVICE); |
| 1077 |
spin_unlock_bh(&ab->base_lock); |
| 1078 |
|
| 1079 |
ret = ath11k_wmi_peer_rx_reorder_queue_setup(ar, vdev_id, peer_mac, rx_tid->paddr, |
| 1080 |
tid, 1, ba_win_sz); |
| 1081 |
if (ret) { |
| 1082 |
ath11k_warn(ar->ab, "failed to setup rx reorder queue for peer %pM tid %d: %d\n", |
| 1083 |
peer_mac, tid, ret); |
| 1084 |
ath11k_dp_rx_tid_mem_free(ab, peer_mac, vdev_id, tid); |
| 1085 |
} |
| 1086 |
|
| 1087 |
return ret; |
| 1088 |
} |
| 1089 |
|
| 1090 |
int ath11k_dp_rx_ampdu_start(struct ath11k *ar, |
| 1091 |
struct ieee80211_ampdu_params *params) |
| 1092 |
{ |
| 1093 |
struct ath11k_base *ab = ar->ab; |
| 1094 |
struct ath11k_sta *arsta = ath11k_sta_to_arsta(params->sta); |
| 1095 |
int vdev_id = arsta->arvif->vdev_id; |
| 1096 |
int ret; |
| 1097 |
|
| 1098 |
ret = ath11k_peer_rx_tid_setup(ar, params->sta->addr, vdev_id, |
| 1099 |
params->tid, params->buf_size, |
| 1100 |
params->ssn, arsta->pn_type); |
| 1101 |
if (ret) |
| 1102 |
ath11k_warn(ab, "failed to setup rx tid %d\n", ret); |
| 1103 |
|
| 1104 |
return ret; |
| 1105 |
} |
| 1106 |
|
| 1107 |
int ath11k_dp_rx_ampdu_stop(struct ath11k *ar, |
| 1108 |
struct ieee80211_ampdu_params *params) |
| 1109 |
{ |
| 1110 |
struct ath11k_base *ab = ar->ab; |
| 1111 |
struct ath11k_peer *peer; |
| 1112 |
struct ath11k_sta *arsta = ath11k_sta_to_arsta(params->sta); |
| 1113 |
struct dp_rx_tid *rx_tid; |
| 1114 |
int vdev_id = arsta->arvif->vdev_id; |
| 1115 |
int ret; |
| 1116 |
|
| 1117 |
spin_lock_bh(&ab->base_lock); |
| 1118 |
|
| 1119 |
peer = ath11k_peer_find(ab, vdev_id, params->sta->addr); |
| 1120 |
if (!peer) { |
| 1121 |
ath11k_warn(ab, "failed to find the peer to stop rx aggregation\n"); |
| 1122 |
spin_unlock_bh(&ab->base_lock); |
| 1123 |
return -ENOENT; |
| 1124 |
} |
| 1125 |
|
| 1126 |
rx_tid = &peer->rx_tid[params->tid]; |
| 1127 |
|
| 1128 |
if (!rx_tid->active) { |
| 1129 |
spin_unlock_bh(&ab->base_lock); |
| 1130 |
return 0; |
| 1131 |
} |
| 1132 |
|
| 1133 |
ret = ath11k_peer_rx_tid_reo_update(ar, peer, rx_tid, 1, 0, false); |
| 1134 |
spin_unlock_bh(&ab->base_lock); |
| 1135 |
if (ret) { |
| 1136 |
ath11k_warn(ab, "failed to update reo for rx tid %d: %d\n", |
| 1137 |
params->tid, ret); |
| 1138 |
return ret; |
| 1139 |
} |
| 1140 |
|
| 1141 |
ret = ath11k_wmi_peer_rx_reorder_queue_setup(ar, vdev_id, |
| 1142 |
params->sta->addr, |
| 1143 |
rx_tid->paddr, |
| 1144 |
params->tid, 1, 1); |
| 1145 |
if (ret) |
| 1146 |
ath11k_warn(ab, "failed to send wmi to delete rx tid %d\n", |
| 1147 |
ret); |
| 1148 |
|
| 1149 |
return ret; |
| 1150 |
} |
| 1151 |
|
| 1152 |
int ath11k_dp_peer_rx_pn_replay_config(struct ath11k_vif *arvif, |
| 1153 |
const u8 *peer_addr, |
| 1154 |
enum set_key_cmd key_cmd, |
| 1155 |
struct ieee80211_key_conf *key) |
| 1156 |
{ |
| 1157 |
struct ath11k *ar = arvif->ar; |
| 1158 |
struct ath11k_base *ab = ar->ab; |
| 1159 |
struct ath11k_hal_reo_cmd cmd = {}; |
| 1160 |
struct ath11k_peer *peer; |
| 1161 |
struct dp_rx_tid *rx_tid; |
| 1162 |
u8 tid; |
| 1163 |
int ret = 0; |
| 1164 |
|
| 1165 |
/* NOTE: Enable PN/TSC replay check offload only for unicast frames. |
| 1166 |
* We use mac80211 PN/TSC replay check functionality for bcast/mcast |
| 1167 |
* for now. |
| 1168 |
*/ |
| 1169 |
if (!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) |
| 1170 |
return 0; |
| 1171 |
|
| 1172 |
cmd.flag |= HAL_REO_CMD_FLG_NEED_STATUS; |
| 1173 |
cmd.upd0 |= HAL_REO_CMD_UPD0_PN | |
| 1174 |
HAL_REO_CMD_UPD0_PN_SIZE | |
| 1175 |
HAL_REO_CMD_UPD0_PN_VALID | |
| 1176 |
HAL_REO_CMD_UPD0_PN_CHECK | |
| 1177 |
HAL_REO_CMD_UPD0_SVLD; |
| 1178 |
|
| 1179 |
switch (key->cipher) { |
| 1180 |
case WLAN_CIPHER_SUITE_TKIP: |
| 1181 |
case WLAN_CIPHER_SUITE_CCMP: |
| 1182 |
case WLAN_CIPHER_SUITE_CCMP_256: |
| 1183 |
case WLAN_CIPHER_SUITE_GCMP: |
| 1184 |
case WLAN_CIPHER_SUITE_GCMP_256: |
| 1185 |
if (key_cmd == SET_KEY) { |
| 1186 |
cmd.upd1 |= HAL_REO_CMD_UPD1_PN_CHECK; |
| 1187 |
cmd.pn_size = 48; |
| 1188 |
} |
| 1189 |
break; |
| 1190 |
default: |
| 1191 |
break; |
| 1192 |
} |
| 1193 |
|
| 1194 |
spin_lock_bh(&ab->base_lock); |
| 1195 |
|
| 1196 |
peer = ath11k_peer_find(ab, arvif->vdev_id, peer_addr); |
| 1197 |
if (!peer) { |
| 1198 |
ath11k_warn(ab, "failed to find the peer to configure pn replay detection\n"); |
| 1199 |
spin_unlock_bh(&ab->base_lock); |
| 1200 |
return -ENOENT; |
| 1201 |
} |
| 1202 |
|
| 1203 |
for (tid = 0; tid <= IEEE80211_NUM_TIDS; tid++) { |
| 1204 |
rx_tid = &peer->rx_tid[tid]; |
| 1205 |
if (!rx_tid->active) |
| 1206 |
continue; |
| 1207 |
cmd.addr_lo = lower_32_bits(rx_tid->paddr); |
| 1208 |
cmd.addr_hi = upper_32_bits(rx_tid->paddr); |
| 1209 |
ret = ath11k_dp_tx_send_reo_cmd(ab, rx_tid, |
| 1210 |
HAL_REO_CMD_UPDATE_RX_QUEUE, |
| 1211 |
&cmd, NULL); |
| 1212 |
if (ret) { |
| 1213 |
ath11k_warn(ab, "failed to configure rx tid %d queue for pn replay detection %d\n", |
| 1214 |
tid, ret); |
| 1215 |
break; |
| 1216 |
} |
| 1217 |
} |
| 1218 |
|
| 1219 |
spin_unlock_bh(&ab->base_lock); |
| 1220 |
|
| 1221 |
return ret; |
| 1222 |
} |
| 1223 |
|
| 1224 |
static inline int ath11k_get_ppdu_user_index(struct htt_ppdu_stats *ppdu_stats, |
| 1225 |
u16 peer_id) |
| 1226 |
{ |
| 1227 |
int i; |
| 1228 |
|
| 1229 |
for (i = 0; i < HTT_PPDU_STATS_MAX_USERS - 1; i++) { |
| 1230 |
if (ppdu_stats->user_stats[i].is_valid_peer_id) { |
| 1231 |
if (peer_id == ppdu_stats->user_stats[i].peer_id) |
| 1232 |
return i; |
| 1233 |
} else { |
| 1234 |
return i; |
| 1235 |
} |
| 1236 |
} |
| 1237 |
|
| 1238 |
return -EINVAL; |
| 1239 |
} |
| 1240 |
|
| 1241 |
static int ath11k_htt_tlv_ppdu_stats_parse(struct ath11k_base *ab, |
| 1242 |
u16 tag, u16 len, const void *ptr, |
| 1243 |
void *data) |
| 1244 |
{ |
| 1245 |
struct htt_ppdu_stats_info *ppdu_info; |
| 1246 |
struct htt_ppdu_user_stats *user_stats; |
| 1247 |
int cur_user; |
| 1248 |
u16 peer_id; |
| 1249 |
|
| 1250 |
ppdu_info = data; |
| 1251 |
|
| 1252 |
switch (tag) { |
| 1253 |
case HTT_PPDU_STATS_TAG_COMMON: |
| 1254 |
if (len < sizeof(struct htt_ppdu_stats_common)) { |
| 1255 |
ath11k_warn(ab, "Invalid len %d for the tag 0x%x\n", |
| 1256 |
len, tag); |
| 1257 |
return -EINVAL; |
| 1258 |
} |
| 1259 |
memcpy((void *)&ppdu_info->ppdu_stats.common, ptr, |
| 1260 |
sizeof(struct htt_ppdu_stats_common)); |
| 1261 |
break; |
| 1262 |
case HTT_PPDU_STATS_TAG_USR_RATE: |
| 1263 |
if (len < sizeof(struct htt_ppdu_stats_user_rate)) { |
| 1264 |
ath11k_warn(ab, "Invalid len %d for the tag 0x%x\n", |
| 1265 |
len, tag); |
| 1266 |
return -EINVAL; |
| 1267 |
} |
| 1268 |
|
| 1269 |
peer_id = ((struct htt_ppdu_stats_user_rate *)ptr)->sw_peer_id; |
| 1270 |
cur_user = ath11k_get_ppdu_user_index(&ppdu_info->ppdu_stats, |
| 1271 |
peer_id); |
| 1272 |
if (cur_user < 0) |
| 1273 |
return -EINVAL; |
| 1274 |
user_stats = &ppdu_info->ppdu_stats.user_stats[cur_user]; |
| 1275 |
user_stats->peer_id = peer_id; |
| 1276 |
user_stats->is_valid_peer_id = true; |
| 1277 |
memcpy((void *)&user_stats->rate, ptr, |
| 1278 |
sizeof(struct htt_ppdu_stats_user_rate)); |
| 1279 |
user_stats->tlv_flags |= BIT(tag); |
| 1280 |
break; |
| 1281 |
case HTT_PPDU_STATS_TAG_USR_COMPLTN_COMMON: |
| 1282 |
if (len < sizeof(struct htt_ppdu_stats_usr_cmpltn_cmn)) { |
| 1283 |
ath11k_warn(ab, "Invalid len %d for the tag 0x%x\n", |
| 1284 |
len, tag); |
| 1285 |
return -EINVAL; |
| 1286 |
} |
| 1287 |
|
| 1288 |
peer_id = ((struct htt_ppdu_stats_usr_cmpltn_cmn *)ptr)->sw_peer_id; |
| 1289 |
cur_user = ath11k_get_ppdu_user_index(&ppdu_info->ppdu_stats, |
| 1290 |
peer_id); |
| 1291 |
if (cur_user < 0) |
| 1292 |
return -EINVAL; |
| 1293 |
user_stats = &ppdu_info->ppdu_stats.user_stats[cur_user]; |
| 1294 |
user_stats->peer_id = peer_id; |
| 1295 |
user_stats->is_valid_peer_id = true; |
| 1296 |
memcpy((void *)&user_stats->cmpltn_cmn, ptr, |
| 1297 |
sizeof(struct htt_ppdu_stats_usr_cmpltn_cmn)); |
| 1298 |
user_stats->tlv_flags |= BIT(tag); |
| 1299 |
break; |
| 1300 |
case HTT_PPDU_STATS_TAG_USR_COMPLTN_ACK_BA_STATUS: |
| 1301 |
if (len < |
| 1302 |
sizeof(struct htt_ppdu_stats_usr_cmpltn_ack_ba_status)) { |
| 1303 |
ath11k_warn(ab, "Invalid len %d for the tag 0x%x\n", |
| 1304 |
len, tag); |
| 1305 |
return -EINVAL; |
| 1306 |
} |
| 1307 |
|
| 1308 |
peer_id = |
| 1309 |
((struct htt_ppdu_stats_usr_cmpltn_ack_ba_status *)ptr)->sw_peer_id; |
| 1310 |
cur_user = ath11k_get_ppdu_user_index(&ppdu_info->ppdu_stats, |
| 1311 |
peer_id); |
| 1312 |
if (cur_user < 0) |
| 1313 |
return -EINVAL; |
| 1314 |
user_stats = &ppdu_info->ppdu_stats.user_stats[cur_user]; |
| 1315 |
user_stats->peer_id = peer_id; |
| 1316 |
user_stats->is_valid_peer_id = true; |
| 1317 |
memcpy((void *)&user_stats->ack_ba, ptr, |
| 1318 |
sizeof(struct htt_ppdu_stats_usr_cmpltn_ack_ba_status)); |
| 1319 |
user_stats->tlv_flags |= BIT(tag); |
| 1320 |
break; |
| 1321 |
} |
| 1322 |
return 0; |
| 1323 |
} |
| 1324 |
|
| 1325 |
int ath11k_dp_htt_tlv_iter(struct ath11k_base *ab, const void *ptr, size_t len, |
| 1326 |
int (*iter)(struct ath11k_base *ar, u16 tag, u16 len, |
| 1327 |
const void *ptr, void *data), |
| 1328 |
void *data) |
| 1329 |
{ |
| 1330 |
const struct htt_tlv *tlv; |
| 1331 |
const void *begin = ptr; |
| 1332 |
u16 tlv_tag, tlv_len; |
| 1333 |
int ret = -EINVAL; |
| 1334 |
|
| 1335 |
while (len > 0) { |
| 1336 |
if (len < sizeof(*tlv)) { |
| 1337 |
ath11k_err(ab, "htt tlv parse failure at byte %zd (%zu bytes left, %zu expected)\n", |
| 1338 |
ptr - begin, len, sizeof(*tlv)); |
| 1339 |
return -EINVAL; |
| 1340 |
} |
| 1341 |
tlv = (struct htt_tlv *)ptr; |
| 1342 |
tlv_tag = FIELD_GET(HTT_TLV_TAG, tlv->header); |
| 1343 |
tlv_len = FIELD_GET(HTT_TLV_LEN, tlv->header); |
| 1344 |
ptr += sizeof(*tlv); |
| 1345 |
len -= sizeof(*tlv); |
| 1346 |
|
| 1347 |
if (tlv_len > len) { |
| 1348 |
ath11k_err(ab, "htt tlv parse failure of tag %u at byte %zd (%zu bytes left, %u expected)\n", |
| 1349 |
tlv_tag, ptr - begin, len, tlv_len); |
| 1350 |
return -EINVAL; |
| 1351 |
} |
| 1352 |
ret = iter(ab, tlv_tag, tlv_len, ptr, data); |
| 1353 |
if (ret == -ENOMEM) |
| 1354 |
return ret; |
| 1355 |
|
| 1356 |
ptr += tlv_len; |
| 1357 |
len -= tlv_len; |
| 1358 |
} |
| 1359 |
return 0; |
| 1360 |
} |
| 1361 |
|
| 1362 |
static void |
| 1363 |
ath11k_update_per_peer_tx_stats(struct ath11k *ar, |
| 1364 |
struct htt_ppdu_stats *ppdu_stats, u8 user) |
| 1365 |
{ |
| 1366 |
struct ath11k_base *ab = ar->ab; |
| 1367 |
struct ath11k_peer *peer; |
| 1368 |
struct ieee80211_sta *sta; |
| 1369 |
struct ath11k_sta *arsta; |
| 1370 |
struct htt_ppdu_stats_user_rate *user_rate; |
| 1371 |
struct ath11k_per_peer_tx_stats *peer_stats = &ar->peer_tx_stats; |
| 1372 |
struct htt_ppdu_user_stats *usr_stats = &ppdu_stats->user_stats[user]; |
| 1373 |
struct htt_ppdu_stats_common *common = &ppdu_stats->common; |
| 1374 |
int ret; |
| 1375 |
u8 flags, mcs, nss, bw, sgi, dcm, rate_idx = 0; |
| 1376 |
u32 succ_bytes = 0; |
| 1377 |
u16 rate = 0, succ_pkts = 0; |
| 1378 |
u32 tx_duration = 0; |
| 1379 |
u8 tid = HTT_PPDU_STATS_NON_QOS_TID; |
| 1380 |
bool is_ampdu = false; |
| 1381 |
|
| 1382 |
if (!(usr_stats->tlv_flags & BIT(HTT_PPDU_STATS_TAG_USR_RATE))) |
| 1383 |
return; |
| 1384 |
|
| 1385 |
if (usr_stats->tlv_flags & BIT(HTT_PPDU_STATS_TAG_USR_COMPLTN_COMMON)) |
| 1386 |
is_ampdu = |
| 1387 |
HTT_USR_CMPLTN_IS_AMPDU(usr_stats->cmpltn_cmn.flags); |
| 1388 |
|
| 1389 |
if (usr_stats->tlv_flags & |
| 1390 |
BIT(HTT_PPDU_STATS_TAG_USR_COMPLTN_ACK_BA_STATUS)) { |
| 1391 |
succ_bytes = usr_stats->ack_ba.success_bytes; |
| 1392 |
succ_pkts = FIELD_GET(HTT_PPDU_STATS_ACK_BA_INFO_NUM_MSDU_M, |
| 1393 |
usr_stats->ack_ba.info); |
| 1394 |
tid = FIELD_GET(HTT_PPDU_STATS_ACK_BA_INFO_TID_NUM, |
| 1395 |
usr_stats->ack_ba.info); |
| 1396 |
} |
| 1397 |
|
| 1398 |
if (common->fes_duration_us) |
| 1399 |
tx_duration = common->fes_duration_us; |
| 1400 |
|
| 1401 |
user_rate = &usr_stats->rate; |
| 1402 |
flags = HTT_USR_RATE_PREAMBLE(user_rate->rate_flags); |
| 1403 |
bw = HTT_USR_RATE_BW(user_rate->rate_flags) - 2; |
| 1404 |
nss = HTT_USR_RATE_NSS(user_rate->rate_flags) + 1; |
| 1405 |
mcs = HTT_USR_RATE_MCS(user_rate->rate_flags); |
| 1406 |
sgi = HTT_USR_RATE_GI(user_rate->rate_flags); |
| 1407 |
dcm = HTT_USR_RATE_DCM(user_rate->rate_flags); |
| 1408 |
|
| 1409 |
/* Note: If host configured fixed rates and in some other special |
| 1410 |
* cases, the broadcast/management frames are sent in different rates. |
| 1411 |
* Firmware rate's control to be skipped for this? |
| 1412 |
*/ |
| 1413 |
|
| 1414 |
if (flags == WMI_RATE_PREAMBLE_HE && mcs > ATH11K_HE_MCS_MAX) { |
| 1415 |
ath11k_warn(ab, "Invalid HE mcs %d peer stats", mcs); |
| 1416 |
return; |
| 1417 |
} |
| 1418 |
|
| 1419 |
if (flags == WMI_RATE_PREAMBLE_VHT && mcs > ATH11K_VHT_MCS_MAX) { |
| 1420 |
ath11k_warn(ab, "Invalid VHT mcs %d peer stats", mcs); |
| 1421 |
return; |
| 1422 |
} |
| 1423 |
|
| 1424 |
if (flags == WMI_RATE_PREAMBLE_HT && (mcs > ATH11K_HT_MCS_MAX || nss < 1)) { |
| 1425 |
ath11k_warn(ab, "Invalid HT mcs %d nss %d peer stats", |
| 1426 |
mcs, nss); |
| 1427 |
return; |
| 1428 |
} |
| 1429 |
|
| 1430 |
if (flags == WMI_RATE_PREAMBLE_CCK || flags == WMI_RATE_PREAMBLE_OFDM) { |
| 1431 |
ret = ath11k_mac_hw_ratecode_to_legacy_rate(mcs, |
| 1432 |
flags, |
| 1433 |
&rate_idx, |
| 1434 |
&rate); |
| 1435 |
if (ret < 0) |
| 1436 |
return; |
| 1437 |
} |
| 1438 |
|
| 1439 |
rcu_read_lock(); |
| 1440 |
spin_lock_bh(&ab->base_lock); |
| 1441 |
peer = ath11k_peer_find_by_id(ab, usr_stats->peer_id); |
| 1442 |
|
| 1443 |
if (!peer || !peer->sta) { |
| 1444 |
spin_unlock_bh(&ab->base_lock); |
| 1445 |
rcu_read_unlock(); |
| 1446 |
return; |
| 1447 |
} |
| 1448 |
|
| 1449 |
sta = peer->sta; |
| 1450 |
arsta = ath11k_sta_to_arsta(sta); |
| 1451 |
|
| 1452 |
memset(&arsta->txrate, 0, sizeof(arsta->txrate)); |
| 1453 |
|
| 1454 |
switch (flags) { |
| 1455 |
case WMI_RATE_PREAMBLE_OFDM: |
| 1456 |
arsta->txrate.legacy = rate; |
| 1457 |
break; |
| 1458 |
case WMI_RATE_PREAMBLE_CCK: |
| 1459 |
arsta->txrate.legacy = rate; |
| 1460 |
break; |
| 1461 |
case WMI_RATE_PREAMBLE_HT: |
| 1462 |
arsta->txrate.mcs = mcs + 8 * (nss - 1); |
| 1463 |
arsta->txrate.flags = RATE_INFO_FLAGS_MCS; |
| 1464 |
if (sgi) |
| 1465 |
arsta->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI; |
| 1466 |
break; |
| 1467 |
case WMI_RATE_PREAMBLE_VHT: |
| 1468 |
arsta->txrate.mcs = mcs; |
| 1469 |
arsta->txrate.flags = RATE_INFO_FLAGS_VHT_MCS; |
| 1470 |
if (sgi) |
| 1471 |
arsta->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI; |
| 1472 |
break; |
| 1473 |
case WMI_RATE_PREAMBLE_HE: |
| 1474 |
arsta->txrate.mcs = mcs; |
| 1475 |
arsta->txrate.flags = RATE_INFO_FLAGS_HE_MCS; |
| 1476 |
arsta->txrate.he_dcm = dcm; |
| 1477 |
arsta->txrate.he_gi = ath11k_mac_he_gi_to_nl80211_he_gi(sgi); |
| 1478 |
arsta->txrate.he_ru_alloc = ath11k_mac_phy_he_ru_to_nl80211_he_ru_alloc |
| 1479 |
((user_rate->ru_end - |
| 1480 |
user_rate->ru_start) + 1); |
| 1481 |
break; |
| 1482 |
} |
| 1483 |
|
| 1484 |
arsta->txrate.nss = nss; |
| 1485 |
|
| 1486 |
arsta->txrate.bw = ath11k_mac_bw_to_mac80211_bw(bw); |
| 1487 |
arsta->tx_duration += tx_duration; |
| 1488 |
memcpy(&arsta->last_txrate, &arsta->txrate, sizeof(struct rate_info)); |
| 1489 |
|
| 1490 |
/* PPDU stats reported for mgmt packet doesn't have valid tx bytes. |
| 1491 |
* So skip peer stats update for mgmt packets. |
| 1492 |
*/ |
| 1493 |
if (tid < HTT_PPDU_STATS_NON_QOS_TID) { |
| 1494 |
memset(peer_stats, 0, sizeof(*peer_stats)); |
| 1495 |
peer_stats->succ_pkts = succ_pkts; |
| 1496 |
peer_stats->succ_bytes = succ_bytes; |
| 1497 |
peer_stats->is_ampdu = is_ampdu; |
| 1498 |
peer_stats->duration = tx_duration; |
| 1499 |
peer_stats->ba_fails = |
| 1500 |
HTT_USR_CMPLTN_LONG_RETRY(usr_stats->cmpltn_cmn.flags) + |
| 1501 |
HTT_USR_CMPLTN_SHORT_RETRY(usr_stats->cmpltn_cmn.flags); |
| 1502 |
|
| 1503 |
if (ath11k_debugfs_is_extd_tx_stats_enabled(ar)) |
| 1504 |
ath11k_debugfs_sta_add_tx_stats(arsta, peer_stats, rate_idx); |
| 1505 |
} |
| 1506 |
|
| 1507 |
spin_unlock_bh(&ab->base_lock); |
| 1508 |
rcu_read_unlock(); |
| 1509 |
} |
| 1510 |
|
| 1511 |
static void ath11k_htt_update_ppdu_stats(struct ath11k *ar, |
| 1512 |
struct htt_ppdu_stats *ppdu_stats) |
| 1513 |
{ |
| 1514 |
u8 user; |
| 1515 |
|
| 1516 |
for (user = 0; user < HTT_PPDU_STATS_MAX_USERS - 1; user++) |
| 1517 |
ath11k_update_per_peer_tx_stats(ar, ppdu_stats, user); |
| 1518 |
} |
| 1519 |
|
| 1520 |
static |
| 1521 |
struct htt_ppdu_stats_info *ath11k_dp_htt_get_ppdu_desc(struct ath11k *ar, |
| 1522 |
u32 ppdu_id) |
| 1523 |
{ |
| 1524 |
struct htt_ppdu_stats_info *ppdu_info; |
| 1525 |
|
| 1526 |
lockdep_assert_held(&ar->data_lock); |
| 1527 |
|
| 1528 |
if (!list_empty(&ar->ppdu_stats_info)) { |
| 1529 |
list_for_each_entry(ppdu_info, &ar->ppdu_stats_info, list) { |
| 1530 |
if (ppdu_info->ppdu_id == ppdu_id) |
| 1531 |
return ppdu_info; |
| 1532 |
} |
| 1533 |
|
| 1534 |
if (ar->ppdu_stat_list_depth > HTT_PPDU_DESC_MAX_DEPTH) { |
| 1535 |
ppdu_info = list_first_entry(&ar->ppdu_stats_info, |
| 1536 |
typeof(*ppdu_info), list); |
| 1537 |
list_del(&ppdu_info->list); |
| 1538 |
ar->ppdu_stat_list_depth--; |
| 1539 |
ath11k_htt_update_ppdu_stats(ar, &ppdu_info->ppdu_stats); |
| 1540 |
kfree(ppdu_info); |
| 1541 |
} |
| 1542 |
} |
| 1543 |
|
| 1544 |
ppdu_info = kzalloc_obj(*ppdu_info, GFP_ATOMIC); |
| 1545 |
if (!ppdu_info) |
| 1546 |
return NULL; |
| 1547 |
|
| 1548 |
list_add_tail(&ppdu_info->list, &ar->ppdu_stats_info); |
| 1549 |
ar->ppdu_stat_list_depth++; |
| 1550 |
|
| 1551 |
return ppdu_info; |
| 1552 |
} |
| 1553 |
|
| 1554 |
static int ath11k_htt_pull_ppdu_stats(struct ath11k_base *ab, |
| 1555 |
struct sk_buff *skb) |
| 1556 |
{ |
| 1557 |
struct ath11k_htt_ppdu_stats_msg *msg; |
| 1558 |
struct htt_ppdu_stats_info *ppdu_info; |
| 1559 |
struct ath11k *ar; |
| 1560 |
int ret; |
| 1561 |
u8 pdev_id; |
| 1562 |
u32 ppdu_id, len; |
| 1563 |
|
| 1564 |
msg = (struct ath11k_htt_ppdu_stats_msg *)skb->data; |
| 1565 |
len = FIELD_GET(HTT_T2H_PPDU_STATS_INFO_PAYLOAD_SIZE, msg->info); |
| 1566 |
pdev_id = FIELD_GET(HTT_T2H_PPDU_STATS_INFO_PDEV_ID, msg->info); |
| 1567 |
ppdu_id = msg->ppdu_id; |
| 1568 |
|
| 1569 |
rcu_read_lock(); |
| 1570 |
ar = ath11k_mac_get_ar_by_pdev_id(ab, pdev_id); |
| 1571 |
if (!ar) { |
| 1572 |
ret = -EINVAL; |
| 1573 |
goto out; |
| 1574 |
} |
| 1575 |
|
| 1576 |
if (ath11k_debugfs_is_pktlog_lite_mode_enabled(ar)) |
| 1577 |
trace_ath11k_htt_ppdu_stats(ar, skb->data, len); |
| 1578 |
|
| 1579 |
spin_lock_bh(&ar->data_lock); |
| 1580 |
ppdu_info = ath11k_dp_htt_get_ppdu_desc(ar, ppdu_id); |
| 1581 |
if (!ppdu_info) { |
| 1582 |
ret = -EINVAL; |
| 1583 |
goto out_unlock_data; |
| 1584 |
} |
| 1585 |
|
| 1586 |
ppdu_info->ppdu_id = ppdu_id; |
| 1587 |
ret = ath11k_dp_htt_tlv_iter(ab, msg->data, len, |
| 1588 |
ath11k_htt_tlv_ppdu_stats_parse, |
| 1589 |
(void *)ppdu_info); |
| 1590 |
if (ret) { |
| 1591 |
ath11k_warn(ab, "Failed to parse tlv %d\n", ret); |
| 1592 |
goto out_unlock_data; |
| 1593 |
} |
| 1594 |
|
| 1595 |
out_unlock_data: |
| 1596 |
spin_unlock_bh(&ar->data_lock); |
| 1597 |
|
| 1598 |
out: |
| 1599 |
rcu_read_unlock(); |
| 1600 |
|
| 1601 |
return ret; |
| 1602 |
} |
| 1603 |
|
| 1604 |
static void ath11k_htt_pktlog(struct ath11k_base *ab, struct sk_buff *skb) |
| 1605 |
{ |
| 1606 |
struct htt_pktlog_msg *data = (struct htt_pktlog_msg *)skb->data; |
| 1607 |
struct ath_pktlog_hdr *hdr = (struct ath_pktlog_hdr *)data; |
| 1608 |
struct ath11k *ar; |
| 1609 |
u8 pdev_id; |
| 1610 |
|
| 1611 |
pdev_id = FIELD_GET(HTT_T2H_PPDU_STATS_INFO_PDEV_ID, data->hdr); |
| 1612 |
|
| 1613 |
rcu_read_lock(); |
| 1614 |
|
| 1615 |
ar = ath11k_mac_get_ar_by_pdev_id(ab, pdev_id); |
| 1616 |
if (!ar) { |
| 1617 |
ath11k_warn(ab, "invalid pdev id %d on htt pktlog\n", pdev_id); |
| 1618 |
goto out; |
| 1619 |
} |
| 1620 |
|
| 1621 |
trace_ath11k_htt_pktlog(ar, data->payload, hdr->size, |
| 1622 |
ar->ab->pktlog_defs_checksum); |
| 1623 |
|
| 1624 |
out: |
| 1625 |
rcu_read_unlock(); |
| 1626 |
} |
| 1627 |
|
| 1628 |
static void ath11k_htt_backpressure_event_handler(struct ath11k_base *ab, |
| 1629 |
struct sk_buff *skb) |
| 1630 |
{ |
| 1631 |
u32 *data = (u32 *)skb->data; |
| 1632 |
u8 pdev_id, ring_type, ring_id, pdev_idx; |
| 1633 |
u16 hp, tp; |
| 1634 |
u32 backpressure_time; |
| 1635 |
struct ath11k_bp_stats *bp_stats; |
| 1636 |
|
| 1637 |
pdev_id = FIELD_GET(HTT_BACKPRESSURE_EVENT_PDEV_ID_M, *data); |
| 1638 |
ring_type = FIELD_GET(HTT_BACKPRESSURE_EVENT_RING_TYPE_M, *data); |
| 1639 |
ring_id = FIELD_GET(HTT_BACKPRESSURE_EVENT_RING_ID_M, *data); |
| 1640 |
++data; |
| 1641 |
|
| 1642 |
hp = FIELD_GET(HTT_BACKPRESSURE_EVENT_HP_M, *data); |
| 1643 |
tp = FIELD_GET(HTT_BACKPRESSURE_EVENT_TP_M, *data); |
| 1644 |
++data; |
| 1645 |
|
| 1646 |
backpressure_time = *data; |
| 1647 |
|
| 1648 |
ath11k_dbg(ab, ATH11K_DBG_DP_HTT, "backpressure event, pdev %d, ring type %d,ring id %d, hp %d tp %d, backpressure time %d\n", |
| 1649 |
pdev_id, ring_type, ring_id, hp, tp, backpressure_time); |
| 1650 |
|
| 1651 |
if (ring_type == HTT_BACKPRESSURE_UMAC_RING_TYPE) { |
| 1652 |
if (ring_id >= HTT_SW_UMAC_RING_IDX_MAX) |
| 1653 |
return; |
| 1654 |
|
| 1655 |
bp_stats = &ab->soc_stats.bp_stats.umac_ring_bp_stats[ring_id]; |
| 1656 |
} else if (ring_type == HTT_BACKPRESSURE_LMAC_RING_TYPE) { |
| 1657 |
pdev_idx = DP_HW2SW_MACID(pdev_id); |
| 1658 |
|
| 1659 |
if (ring_id >= HTT_SW_LMAC_RING_IDX_MAX || pdev_idx >= MAX_RADIOS) |
| 1660 |
return; |
| 1661 |
|
| 1662 |
bp_stats = &ab->soc_stats.bp_stats.lmac_ring_bp_stats[ring_id][pdev_idx]; |
| 1663 |
} else { |
| 1664 |
ath11k_warn(ab, "unknown ring type received in htt bp event %d\n", |
| 1665 |
ring_type); |
| 1666 |
return; |
| 1667 |
} |
| 1668 |
|
| 1669 |
spin_lock_bh(&ab->base_lock); |
| 1670 |
bp_stats->hp = hp; |
| 1671 |
bp_stats->tp = tp; |
| 1672 |
bp_stats->count++; |
| 1673 |
bp_stats->jiffies = jiffies; |
| 1674 |
spin_unlock_bh(&ab->base_lock); |
| 1675 |
} |
| 1676 |
|
| 1677 |
void ath11k_dp_htt_htc_t2h_msg_handler(struct ath11k_base *ab, |
| 1678 |
struct sk_buff *skb) |
| 1679 |
{ |
| 1680 |
struct ath11k_dp *dp = &ab->dp; |
| 1681 |
struct htt_resp_msg *resp = (struct htt_resp_msg *)skb->data; |
| 1682 |
enum htt_t2h_msg_type type = FIELD_GET(HTT_T2H_MSG_TYPE, *(u32 *)resp); |
| 1683 |
u16 peer_id; |
| 1684 |
u8 vdev_id; |
| 1685 |
u8 mac_addr[ETH_ALEN]; |
| 1686 |
u16 peer_mac_h16; |
| 1687 |
u16 ast_hash; |
| 1688 |
u16 hw_peer_id; |
| 1689 |
|
| 1690 |
ath11k_dbg(ab, ATH11K_DBG_DP_HTT, "dp_htt rx msg type :0x%0x\n", type); |
| 1691 |
|
| 1692 |
switch (type) { |
| 1693 |
case HTT_T2H_MSG_TYPE_VERSION_CONF: |
| 1694 |
dp->htt_tgt_ver_major = FIELD_GET(HTT_T2H_VERSION_CONF_MAJOR, |
| 1695 |
resp->version_msg.version); |
| 1696 |
dp->htt_tgt_ver_minor = FIELD_GET(HTT_T2H_VERSION_CONF_MINOR, |
| 1697 |
resp->version_msg.version); |
| 1698 |
complete(&dp->htt_tgt_version_received); |
| 1699 |
break; |
| 1700 |
case HTT_T2H_MSG_TYPE_PEER_MAP: |
| 1701 |
vdev_id = FIELD_GET(HTT_T2H_PEER_MAP_INFO_VDEV_ID, |
| 1702 |
resp->peer_map_ev.info); |
| 1703 |
peer_id = FIELD_GET(HTT_T2H_PEER_MAP_INFO_PEER_ID, |
| 1704 |
resp->peer_map_ev.info); |
| 1705 |
peer_mac_h16 = FIELD_GET(HTT_T2H_PEER_MAP_INFO1_MAC_ADDR_H16, |
| 1706 |
resp->peer_map_ev.info1); |
| 1707 |
ath11k_dp_get_mac_addr(resp->peer_map_ev.mac_addr_l32, |
| 1708 |
peer_mac_h16, mac_addr); |
| 1709 |
ath11k_peer_map_event(ab, vdev_id, peer_id, mac_addr, 0, 0); |
| 1710 |
break; |
| 1711 |
case HTT_T2H_MSG_TYPE_PEER_MAP2: |
| 1712 |
vdev_id = FIELD_GET(HTT_T2H_PEER_MAP_INFO_VDEV_ID, |
| 1713 |
resp->peer_map_ev.info); |
| 1714 |
peer_id = FIELD_GET(HTT_T2H_PEER_MAP_INFO_PEER_ID, |
| 1715 |
resp->peer_map_ev.info); |
| 1716 |
peer_mac_h16 = FIELD_GET(HTT_T2H_PEER_MAP_INFO1_MAC_ADDR_H16, |
| 1717 |
resp->peer_map_ev.info1); |
| 1718 |
ath11k_dp_get_mac_addr(resp->peer_map_ev.mac_addr_l32, |
| 1719 |
peer_mac_h16, mac_addr); |
| 1720 |
ast_hash = FIELD_GET(HTT_T2H_PEER_MAP_INFO2_AST_HASH_VAL, |
| 1721 |
resp->peer_map_ev.info2); |
| 1722 |
hw_peer_id = FIELD_GET(HTT_T2H_PEER_MAP_INFO1_HW_PEER_ID, |
| 1723 |
resp->peer_map_ev.info1); |
| 1724 |
ath11k_peer_map_event(ab, vdev_id, peer_id, mac_addr, ast_hash, |
| 1725 |
hw_peer_id); |
| 1726 |
break; |
| 1727 |
case HTT_T2H_MSG_TYPE_PEER_UNMAP: |
| 1728 |
case HTT_T2H_MSG_TYPE_PEER_UNMAP2: |
| 1729 |
peer_id = FIELD_GET(HTT_T2H_PEER_UNMAP_INFO_PEER_ID, |
| 1730 |
resp->peer_unmap_ev.info); |
| 1731 |
ath11k_peer_unmap_event(ab, peer_id); |
| 1732 |
break; |
| 1733 |
case HTT_T2H_MSG_TYPE_PPDU_STATS_IND: |
| 1734 |
ath11k_htt_pull_ppdu_stats(ab, skb); |
| 1735 |
break; |
| 1736 |
case HTT_T2H_MSG_TYPE_EXT_STATS_CONF: |
| 1737 |
ath11k_debugfs_htt_ext_stats_handler(ab, skb); |
| 1738 |
break; |
| 1739 |
case HTT_T2H_MSG_TYPE_PKTLOG: |
| 1740 |
ath11k_htt_pktlog(ab, skb); |
| 1741 |
break; |
| 1742 |
case HTT_T2H_MSG_TYPE_BKPRESSURE_EVENT_IND: |
| 1743 |
ath11k_htt_backpressure_event_handler(ab, skb); |
| 1744 |
break; |
| 1745 |
default: |
| 1746 |
ath11k_warn(ab, "htt event %d not handled\n", type); |
| 1747 |
break; |
| 1748 |
} |
| 1749 |
|
| 1750 |
dev_kfree_skb_any(skb); |
| 1751 |
} |
| 1752 |
|
| 1753 |
static int ath11k_dp_rx_msdu_coalesce(struct ath11k *ar, |
| 1754 |
struct sk_buff_head *msdu_list, |
| 1755 |
struct sk_buff *first, struct sk_buff *last, |
| 1756 |
u8 l3pad_bytes, int msdu_len) |
| 1757 |
{ |
| 1758 |
struct ath11k_base *ab = ar->ab; |
| 1759 |
struct sk_buff *skb; |
| 1760 |
struct ath11k_skb_rxcb *rxcb = ATH11K_SKB_RXCB(first); |
| 1761 |
int buf_first_hdr_len, buf_first_len; |
| 1762 |
struct hal_rx_desc *ldesc; |
| 1763 |
int space_extra, rem_len, buf_len; |
| 1764 |
u32 hal_rx_desc_sz = ar->ab->hw_params.hal_desc_sz; |
| 1765 |
|
| 1766 |
/* As the msdu is spread across multiple rx buffers, |
| 1767 |
* find the offset to the start of msdu for computing |
| 1768 |
* the length of the msdu in the first buffer. |
| 1769 |
*/ |
| 1770 |
buf_first_hdr_len = hal_rx_desc_sz + l3pad_bytes; |
| 1771 |
buf_first_len = DP_RX_BUFFER_SIZE - buf_first_hdr_len; |
| 1772 |
|
| 1773 |
if (WARN_ON_ONCE(msdu_len <= buf_first_len)) { |
| 1774 |
skb_put(first, buf_first_hdr_len + msdu_len); |
| 1775 |
skb_pull(first, buf_first_hdr_len); |
| 1776 |
return 0; |
| 1777 |
} |
| 1778 |
|
| 1779 |
ldesc = (struct hal_rx_desc *)last->data; |
| 1780 |
rxcb->is_first_msdu = ath11k_dp_rx_h_msdu_end_first_msdu(ab, ldesc); |
| 1781 |
rxcb->is_last_msdu = ath11k_dp_rx_h_msdu_end_last_msdu(ab, ldesc); |
| 1782 |
|
| 1783 |
/* MSDU spans over multiple buffers because the length of the MSDU |
| 1784 |
* exceeds DP_RX_BUFFER_SIZE - HAL_RX_DESC_SIZE. So assume the data |
| 1785 |
* in the first buf is of length DP_RX_BUFFER_SIZE - HAL_RX_DESC_SIZE. |
| 1786 |
*/ |
| 1787 |
skb_put(first, DP_RX_BUFFER_SIZE); |
| 1788 |
skb_pull(first, buf_first_hdr_len); |
| 1789 |
|
| 1790 |
/* When an MSDU spread over multiple buffers attention, MSDU_END and |
| 1791 |
* MPDU_END tlvs are valid only in the last buffer. Copy those tlvs. |
| 1792 |
*/ |
| 1793 |
ath11k_dp_rx_desc_end_tlv_copy(ab, rxcb->rx_desc, ldesc); |
| 1794 |
|
| 1795 |
space_extra = msdu_len - (buf_first_len + skb_tailroom(first)); |
| 1796 |
if (space_extra > 0 && |
| 1797 |
(pskb_expand_head(first, 0, space_extra, GFP_ATOMIC) < 0)) { |
| 1798 |
/* Free up all buffers of the MSDU */ |
| 1799 |
while ((skb = __skb_dequeue(msdu_list)) != NULL) { |
| 1800 |
rxcb = ATH11K_SKB_RXCB(skb); |
| 1801 |
if (!rxcb->is_continuation) { |
| 1802 |
dev_kfree_skb_any(skb); |
| 1803 |
break; |
| 1804 |
} |
| 1805 |
dev_kfree_skb_any(skb); |
| 1806 |
} |
| 1807 |
return -ENOMEM; |
| 1808 |
} |
| 1809 |
|
| 1810 |
rem_len = msdu_len - buf_first_len; |
| 1811 |
while ((skb = __skb_dequeue(msdu_list)) != NULL && rem_len > 0) { |
| 1812 |
rxcb = ATH11K_SKB_RXCB(skb); |
| 1813 |
if (rxcb->is_continuation) |
| 1814 |
buf_len = DP_RX_BUFFER_SIZE - hal_rx_desc_sz; |
| 1815 |
else |
| 1816 |
buf_len = rem_len; |
| 1817 |
|
| 1818 |
if (buf_len > (DP_RX_BUFFER_SIZE - hal_rx_desc_sz)) { |
| 1819 |
WARN_ON_ONCE(1); |
| 1820 |
dev_kfree_skb_any(skb); |
| 1821 |
return -EINVAL; |
| 1822 |
} |
| 1823 |
|
| 1824 |
skb_put(skb, buf_len + hal_rx_desc_sz); |
| 1825 |
skb_pull(skb, hal_rx_desc_sz); |
| 1826 |
skb_copy_from_linear_data(skb, skb_put(first, buf_len), |
| 1827 |
buf_len); |
| 1828 |
dev_kfree_skb_any(skb); |
| 1829 |
|
| 1830 |
rem_len -= buf_len; |
| 1831 |
if (!rxcb->is_continuation) |
| 1832 |
break; |
| 1833 |
} |
| 1834 |
|
| 1835 |
return 0; |
| 1836 |
} |
| 1837 |
|
| 1838 |
static struct sk_buff *ath11k_dp_rx_get_msdu_last_buf(struct sk_buff_head *msdu_list, |
| 1839 |
struct sk_buff *first) |
| 1840 |
{ |
| 1841 |
struct sk_buff *skb; |
| 1842 |
struct ath11k_skb_rxcb *rxcb = ATH11K_SKB_RXCB(first); |
| 1843 |
|
| 1844 |
if (!rxcb->is_continuation) |
| 1845 |
return first; |
| 1846 |
|
| 1847 |
skb_queue_walk(msdu_list, skb) { |
| 1848 |
rxcb = ATH11K_SKB_RXCB(skb); |
| 1849 |
if (!rxcb->is_continuation) |
| 1850 |
return skb; |
| 1851 |
} |
| 1852 |
|
| 1853 |
return NULL; |
| 1854 |
} |
| 1855 |
|
| 1856 |
static void ath11k_dp_rx_h_csum_offload(struct ath11k *ar, struct sk_buff *msdu) |
| 1857 |
{ |
| 1858 |
struct ath11k_skb_rxcb *rxcb = ATH11K_SKB_RXCB(msdu); |
| 1859 |
struct rx_attention *rx_attention; |
| 1860 |
bool ip_csum_fail, l4_csum_fail; |
| 1861 |
|
| 1862 |
rx_attention = ath11k_dp_rx_get_attention(ar->ab, rxcb->rx_desc); |
| 1863 |
ip_csum_fail = ath11k_dp_rx_h_attn_ip_cksum_fail(rx_attention); |
| 1864 |
l4_csum_fail = ath11k_dp_rx_h_attn_l4_cksum_fail(rx_attention); |
| 1865 |
|
| 1866 |
msdu->ip_summed = (ip_csum_fail || l4_csum_fail) ? |
| 1867 |
CHECKSUM_NONE : CHECKSUM_UNNECESSARY; |
| 1868 |
} |
| 1869 |
|
| 1870 |
int ath11k_dp_rx_crypto_mic_len(struct ath11k *ar, enum hal_encrypt_type enctype) |
| 1871 |
{ |
| 1872 |
switch (enctype) { |
| 1873 |
case HAL_ENCRYPT_TYPE_OPEN: |
| 1874 |
case HAL_ENCRYPT_TYPE_TKIP_NO_MIC: |
| 1875 |
case HAL_ENCRYPT_TYPE_TKIP_MIC: |
| 1876 |
return 0; |
| 1877 |
case HAL_ENCRYPT_TYPE_CCMP_128: |
| 1878 |
return IEEE80211_CCMP_MIC_LEN; |
| 1879 |
case HAL_ENCRYPT_TYPE_CCMP_256: |
| 1880 |
return IEEE80211_CCMP_256_MIC_LEN; |
| 1881 |
case HAL_ENCRYPT_TYPE_GCMP_128: |
| 1882 |
case HAL_ENCRYPT_TYPE_AES_GCMP_256: |
| 1883 |
return IEEE80211_GCMP_MIC_LEN; |
| 1884 |
case HAL_ENCRYPT_TYPE_WEP_40: |
| 1885 |
case HAL_ENCRYPT_TYPE_WEP_104: |
| 1886 |
case HAL_ENCRYPT_TYPE_WEP_128: |
| 1887 |
case HAL_ENCRYPT_TYPE_WAPI_GCM_SM4: |
| 1888 |
case HAL_ENCRYPT_TYPE_WAPI: |
| 1889 |
break; |
| 1890 |
} |
| 1891 |
|
| 1892 |
ath11k_warn(ar->ab, "unsupported encryption type %d for mic len\n", enctype); |
| 1893 |
return 0; |
| 1894 |
} |
| 1895 |
|
| 1896 |
static int ath11k_dp_rx_crypto_param_len(struct ath11k *ar, |
| 1897 |
enum hal_encrypt_type enctype) |
| 1898 |
{ |
| 1899 |
switch (enctype) { |
| 1900 |
case HAL_ENCRYPT_TYPE_OPEN: |
| 1901 |
return 0; |
| 1902 |
case HAL_ENCRYPT_TYPE_TKIP_NO_MIC: |
| 1903 |
case HAL_ENCRYPT_TYPE_TKIP_MIC: |
| 1904 |
return IEEE80211_TKIP_IV_LEN; |
| 1905 |
case HAL_ENCRYPT_TYPE_CCMP_128: |
| 1906 |
return IEEE80211_CCMP_HDR_LEN; |
| 1907 |
case HAL_ENCRYPT_TYPE_CCMP_256: |
| 1908 |
return IEEE80211_CCMP_256_HDR_LEN; |
| 1909 |
case HAL_ENCRYPT_TYPE_GCMP_128: |
| 1910 |
case HAL_ENCRYPT_TYPE_AES_GCMP_256: |
| 1911 |
return IEEE80211_GCMP_HDR_LEN; |
| 1912 |
case HAL_ENCRYPT_TYPE_WEP_40: |
| 1913 |
case HAL_ENCRYPT_TYPE_WEP_104: |
| 1914 |
case HAL_ENCRYPT_TYPE_WEP_128: |
| 1915 |
case HAL_ENCRYPT_TYPE_WAPI_GCM_SM4: |
| 1916 |
case HAL_ENCRYPT_TYPE_WAPI: |
| 1917 |
break; |
| 1918 |
} |
| 1919 |
|
| 1920 |
ath11k_warn(ar->ab, "unsupported encryption type %d\n", enctype); |
| 1921 |
return 0; |
| 1922 |
} |
| 1923 |
|
| 1924 |
static int ath11k_dp_rx_crypto_icv_len(struct ath11k *ar, |
| 1925 |
enum hal_encrypt_type enctype) |
| 1926 |
{ |
| 1927 |
switch (enctype) { |
| 1928 |
case HAL_ENCRYPT_TYPE_OPEN: |
| 1929 |
case HAL_ENCRYPT_TYPE_CCMP_128: |
| 1930 |
case HAL_ENCRYPT_TYPE_CCMP_256: |
| 1931 |
case HAL_ENCRYPT_TYPE_GCMP_128: |
| 1932 |
case HAL_ENCRYPT_TYPE_AES_GCMP_256: |
| 1933 |
return 0; |
| 1934 |
case HAL_ENCRYPT_TYPE_TKIP_NO_MIC: |
| 1935 |
case HAL_ENCRYPT_TYPE_TKIP_MIC: |
| 1936 |
return IEEE80211_TKIP_ICV_LEN; |
| 1937 |
case HAL_ENCRYPT_TYPE_WEP_40: |
| 1938 |
case HAL_ENCRYPT_TYPE_WEP_104: |
| 1939 |
case HAL_ENCRYPT_TYPE_WEP_128: |
| 1940 |
case HAL_ENCRYPT_TYPE_WAPI_GCM_SM4: |
| 1941 |
case HAL_ENCRYPT_TYPE_WAPI: |
| 1942 |
break; |
| 1943 |
} |
| 1944 |
|
| 1945 |
ath11k_warn(ar->ab, "unsupported encryption type %d\n", enctype); |
| 1946 |
return 0; |
| 1947 |
} |
| 1948 |
|
| 1949 |
static void ath11k_dp_rx_h_undecap_nwifi(struct ath11k *ar, |
| 1950 |
struct sk_buff *msdu, |
| 1951 |
u8 *first_hdr, |
| 1952 |
enum hal_encrypt_type enctype, |
| 1953 |
struct ieee80211_rx_status *status) |
| 1954 |
{ |
| 1955 |
struct ath11k_skb_rxcb *rxcb = ATH11K_SKB_RXCB(msdu); |
| 1956 |
u8 decap_hdr[DP_MAX_NWIFI_HDR_LEN]; |
| 1957 |
struct ieee80211_hdr *hdr; |
| 1958 |
size_t hdr_len; |
| 1959 |
u8 da[ETH_ALEN]; |
| 1960 |
u8 sa[ETH_ALEN]; |
| 1961 |
u16 qos_ctl = 0; |
| 1962 |
u8 *qos; |
| 1963 |
|
| 1964 |
/* copy SA & DA and pull decapped header */ |
| 1965 |
hdr = (struct ieee80211_hdr *)msdu->data; |
| 1966 |
hdr_len = ieee80211_hdrlen(hdr->frame_control); |
| 1967 |
ether_addr_copy(da, ieee80211_get_DA(hdr)); |
| 1968 |
ether_addr_copy(sa, ieee80211_get_SA(hdr)); |
| 1969 |
skb_pull(msdu, ieee80211_hdrlen(hdr->frame_control)); |
| 1970 |
|
| 1971 |
if (rxcb->is_first_msdu) { |
| 1972 |
/* original 802.11 header is valid for the first msdu |
| 1973 |
* hence we can reuse the same header |
| 1974 |
*/ |
| 1975 |
hdr = (struct ieee80211_hdr *)first_hdr; |
| 1976 |
hdr_len = ieee80211_hdrlen(hdr->frame_control); |
| 1977 |
|
| 1978 |
/* Each A-MSDU subframe will be reported as a separate MSDU, |
| 1979 |
* so strip the A-MSDU bit from QoS Ctl. |
| 1980 |
*/ |
| 1981 |
if (ieee80211_is_data_qos(hdr->frame_control)) { |
| 1982 |
qos = ieee80211_get_qos_ctl(hdr); |
| 1983 |
qos[0] &= ~IEEE80211_QOS_CTL_A_MSDU_PRESENT; |
| 1984 |
} |
| 1985 |
} else { |
| 1986 |
/* Rebuild qos header if this is a middle/last msdu */ |
| 1987 |
hdr->frame_control |= __cpu_to_le16(IEEE80211_STYPE_QOS_DATA); |
| 1988 |
|
| 1989 |
/* Reset the order bit as the HT_Control header is stripped */ |
| 1990 |
hdr->frame_control &= ~(__cpu_to_le16(IEEE80211_FCTL_ORDER)); |
| 1991 |
|
| 1992 |
qos_ctl = rxcb->tid; |
| 1993 |
|
| 1994 |
if (ath11k_dp_rx_h_msdu_start_mesh_ctl_present(ar->ab, rxcb->rx_desc)) |
| 1995 |
qos_ctl |= IEEE80211_QOS_CTL_MESH_CONTROL_PRESENT; |
| 1996 |
|
| 1997 |
/* TODO Add other QoS ctl fields when required */ |
| 1998 |
|
| 1999 |
/* copy decap header before overwriting for reuse below */ |
| 2000 |
memcpy(decap_hdr, (uint8_t *)hdr, hdr_len); |
| 2001 |
} |
| 2002 |
|
| 2003 |
if (!(status->flag & RX_FLAG_IV_STRIPPED)) { |
| 2004 |
memcpy(skb_push(msdu, |
| 2005 |
ath11k_dp_rx_crypto_param_len(ar, enctype)), |
| 2006 |
(void *)hdr + hdr_len, |
| 2007 |
ath11k_dp_rx_crypto_param_len(ar, enctype)); |
| 2008 |
} |
| 2009 |
|
| 2010 |
if (!rxcb->is_first_msdu) { |
| 2011 |
memcpy(skb_push(msdu, |
| 2012 |
IEEE80211_QOS_CTL_LEN), &qos_ctl, |
| 2013 |
IEEE80211_QOS_CTL_LEN); |
| 2014 |
memcpy(skb_push(msdu, hdr_len), decap_hdr, hdr_len); |
| 2015 |
return; |
| 2016 |
} |
| 2017 |
|
| 2018 |
memcpy(skb_push(msdu, hdr_len), hdr, hdr_len); |
| 2019 |
|
| 2020 |
/* original 802.11 header has a different DA and in |
| 2021 |
* case of 4addr it may also have different SA |
| 2022 |
*/ |
| 2023 |
hdr = (struct ieee80211_hdr *)msdu->data; |
| 2024 |
ether_addr_copy(ieee80211_get_DA(hdr), da); |
| 2025 |
ether_addr_copy(ieee80211_get_SA(hdr), sa); |
| 2026 |
} |
| 2027 |
|
| 2028 |
static void ath11k_dp_rx_h_undecap_raw(struct ath11k *ar, struct sk_buff *msdu, |
| 2029 |
enum hal_encrypt_type enctype, |
| 2030 |
struct ieee80211_rx_status *status, |
| 2031 |
bool decrypted) |
| 2032 |
{ |
| 2033 |
struct ath11k_skb_rxcb *rxcb = ATH11K_SKB_RXCB(msdu); |
| 2034 |
struct ieee80211_hdr *hdr; |
| 2035 |
size_t hdr_len; |
| 2036 |
size_t crypto_len; |
| 2037 |
|
| 2038 |
if (!rxcb->is_first_msdu || |
| 2039 |
!(rxcb->is_first_msdu && rxcb->is_last_msdu)) { |
| 2040 |
WARN_ON_ONCE(1); |
| 2041 |
return; |
| 2042 |
} |
| 2043 |
|
| 2044 |
skb_trim(msdu, msdu->len - FCS_LEN); |
| 2045 |
|
| 2046 |
if (!decrypted) |
| 2047 |
return; |
| 2048 |
|
| 2049 |
hdr = (void *)msdu->data; |
| 2050 |
|
| 2051 |
/* Tail */ |
| 2052 |
if (status->flag & RX_FLAG_IV_STRIPPED) { |
| 2053 |
skb_trim(msdu, msdu->len - |
| 2054 |
ath11k_dp_rx_crypto_mic_len(ar, enctype)); |
| 2055 |
|
| 2056 |
skb_trim(msdu, msdu->len - |
| 2057 |
ath11k_dp_rx_crypto_icv_len(ar, enctype)); |
| 2058 |
} else { |
| 2059 |
/* MIC */ |
| 2060 |
if (status->flag & RX_FLAG_MIC_STRIPPED) |
| 2061 |
skb_trim(msdu, msdu->len - |
| 2062 |
ath11k_dp_rx_crypto_mic_len(ar, enctype)); |
| 2063 |
|
| 2064 |
/* ICV */ |
| 2065 |
if (status->flag & RX_FLAG_ICV_STRIPPED) |
| 2066 |
skb_trim(msdu, msdu->len - |
| 2067 |
ath11k_dp_rx_crypto_icv_len(ar, enctype)); |
| 2068 |
} |
| 2069 |
|
| 2070 |
/* MMIC */ |
| 2071 |
if ((status->flag & RX_FLAG_MMIC_STRIPPED) && |
| 2072 |
!ieee80211_has_morefrags(hdr->frame_control) && |
| 2073 |
enctype == HAL_ENCRYPT_TYPE_TKIP_MIC) |
| 2074 |
skb_trim(msdu, msdu->len - IEEE80211_CCMP_MIC_LEN); |
| 2075 |
|
| 2076 |
/* Head */ |
| 2077 |
if (status->flag & RX_FLAG_IV_STRIPPED) { |
| 2078 |
hdr_len = ieee80211_hdrlen(hdr->frame_control); |
| 2079 |
crypto_len = ath11k_dp_rx_crypto_param_len(ar, enctype); |
| 2080 |
|
| 2081 |
memmove((void *)msdu->data + crypto_len, |
| 2082 |
(void *)msdu->data, hdr_len); |
| 2083 |
skb_pull(msdu, crypto_len); |
| 2084 |
} |
| 2085 |
} |
| 2086 |
|
| 2087 |
static void *ath11k_dp_rx_h_find_rfc1042(struct ath11k *ar, |
| 2088 |
struct sk_buff *msdu, |
| 2089 |
enum hal_encrypt_type enctype) |
| 2090 |
{ |
| 2091 |
struct ath11k_skb_rxcb *rxcb = ATH11K_SKB_RXCB(msdu); |
| 2092 |
struct ieee80211_hdr *hdr; |
| 2093 |
size_t hdr_len, crypto_len; |
| 2094 |
void *rfc1042; |
| 2095 |
bool is_amsdu; |
| 2096 |
|
| 2097 |
is_amsdu = !(rxcb->is_first_msdu && rxcb->is_last_msdu); |
| 2098 |
hdr = (struct ieee80211_hdr *)ath11k_dp_rx_h_80211_hdr(ar->ab, rxcb->rx_desc); |
| 2099 |
rfc1042 = hdr; |
| 2100 |
|
| 2101 |
if (rxcb->is_first_msdu) { |
| 2102 |
hdr_len = ieee80211_hdrlen(hdr->frame_control); |
| 2103 |
crypto_len = ath11k_dp_rx_crypto_param_len(ar, enctype); |
| 2104 |
|
| 2105 |
rfc1042 += hdr_len + crypto_len; |
| 2106 |
} |
| 2107 |
|
| 2108 |
if (is_amsdu) |
| 2109 |
rfc1042 += sizeof(struct ath11k_dp_amsdu_subframe_hdr); |
| 2110 |
|
| 2111 |
return rfc1042; |
| 2112 |
} |
| 2113 |
|
| 2114 |
static void ath11k_dp_rx_h_undecap_eth(struct ath11k *ar, |
| 2115 |
struct sk_buff *msdu, |
| 2116 |
u8 *first_hdr, |
| 2117 |
enum hal_encrypt_type enctype, |
| 2118 |
struct ieee80211_rx_status *status) |
| 2119 |
{ |
| 2120 |
struct ieee80211_hdr *hdr; |
| 2121 |
struct ethhdr *eth; |
| 2122 |
size_t hdr_len; |
| 2123 |
u8 da[ETH_ALEN]; |
| 2124 |
u8 sa[ETH_ALEN]; |
| 2125 |
void *rfc1042; |
| 2126 |
|
| 2127 |
rfc1042 = ath11k_dp_rx_h_find_rfc1042(ar, msdu, enctype); |
| 2128 |
if (WARN_ON_ONCE(!rfc1042)) |
| 2129 |
return; |
| 2130 |
|
| 2131 |
/* pull decapped header and copy SA & DA */ |
| 2132 |
eth = (struct ethhdr *)msdu->data; |
| 2133 |
ether_addr_copy(da, eth->h_dest); |
| 2134 |
ether_addr_copy(sa, eth->h_source); |
| 2135 |
skb_pull(msdu, sizeof(struct ethhdr)); |
| 2136 |
|
| 2137 |
/* push rfc1042/llc/snap */ |
| 2138 |
memcpy(skb_push(msdu, sizeof(struct ath11k_dp_rfc1042_hdr)), rfc1042, |
| 2139 |
sizeof(struct ath11k_dp_rfc1042_hdr)); |
| 2140 |
|
| 2141 |
/* push original 802.11 header */ |
| 2142 |
hdr = (struct ieee80211_hdr *)first_hdr; |
| 2143 |
hdr_len = ieee80211_hdrlen(hdr->frame_control); |
| 2144 |
|
| 2145 |
if (!(status->flag & RX_FLAG_IV_STRIPPED)) { |
| 2146 |
memcpy(skb_push(msdu, |
| 2147 |
ath11k_dp_rx_crypto_param_len(ar, enctype)), |
| 2148 |
(void *)hdr + hdr_len, |
| 2149 |
ath11k_dp_rx_crypto_param_len(ar, enctype)); |
| 2150 |
} |
| 2151 |
|
| 2152 |
memcpy(skb_push(msdu, hdr_len), hdr, hdr_len); |
| 2153 |
|
| 2154 |
/* original 802.11 header has a different DA and in |
| 2155 |
* case of 4addr it may also have different SA |
| 2156 |
*/ |
| 2157 |
hdr = (struct ieee80211_hdr *)msdu->data; |
| 2158 |
ether_addr_copy(ieee80211_get_DA(hdr), da); |
| 2159 |
ether_addr_copy(ieee80211_get_SA(hdr), sa); |
| 2160 |
} |
| 2161 |
|
| 2162 |
static void ath11k_dp_rx_h_undecap(struct ath11k *ar, struct sk_buff *msdu, |
| 2163 |
struct hal_rx_desc *rx_desc, |
| 2164 |
enum hal_encrypt_type enctype, |
| 2165 |
struct ieee80211_rx_status *status, |
| 2166 |
bool decrypted) |
| 2167 |
{ |
| 2168 |
u8 *first_hdr; |
| 2169 |
u8 decap; |
| 2170 |
struct ethhdr *ehdr; |
| 2171 |
|
| 2172 |
first_hdr = ath11k_dp_rx_h_80211_hdr(ar->ab, rx_desc); |
| 2173 |
decap = ath11k_dp_rx_h_msdu_start_decap_type(ar->ab, rx_desc); |
| 2174 |
|
| 2175 |
switch (decap) { |
| 2176 |
case DP_RX_DECAP_TYPE_NATIVE_WIFI: |
| 2177 |
ath11k_dp_rx_h_undecap_nwifi(ar, msdu, first_hdr, |
| 2178 |
enctype, status); |
| 2179 |
break; |
| 2180 |
case DP_RX_DECAP_TYPE_RAW: |
| 2181 |
ath11k_dp_rx_h_undecap_raw(ar, msdu, enctype, status, |
| 2182 |
decrypted); |
| 2183 |
break; |
| 2184 |
case DP_RX_DECAP_TYPE_ETHERNET2_DIX: |
| 2185 |
ehdr = (struct ethhdr *)msdu->data; |
| 2186 |
|
| 2187 |
/* mac80211 allows fast path only for authorized STA */ |
| 2188 |
if (ehdr->h_proto == cpu_to_be16(ETH_P_PAE)) { |
| 2189 |
ATH11K_SKB_RXCB(msdu)->is_eapol = true; |
| 2190 |
ath11k_dp_rx_h_undecap_eth(ar, msdu, first_hdr, |
| 2191 |
enctype, status); |
| 2192 |
break; |
| 2193 |
} |
| 2194 |
|
| 2195 |
/* PN for mcast packets will be validated in mac80211; |
| 2196 |
* remove eth header and add 802.11 header. |
| 2197 |
*/ |
| 2198 |
if (ATH11K_SKB_RXCB(msdu)->is_mcbc && decrypted) |
| 2199 |
ath11k_dp_rx_h_undecap_eth(ar, msdu, first_hdr, |
| 2200 |
enctype, status); |
| 2201 |
break; |
| 2202 |
case DP_RX_DECAP_TYPE_8023: |
| 2203 |
/* TODO: Handle undecap for these formats */ |
| 2204 |
break; |
| 2205 |
} |
| 2206 |
} |
| 2207 |
|
| 2208 |
static struct ath11k_peer * |
| 2209 |
ath11k_dp_rx_h_find_peer(struct ath11k_base *ab, struct sk_buff *msdu) |
| 2210 |
{ |
| 2211 |
struct ath11k_skb_rxcb *rxcb = ATH11K_SKB_RXCB(msdu); |
| 2212 |
struct hal_rx_desc *rx_desc = rxcb->rx_desc; |
| 2213 |
struct ath11k_peer *peer = NULL; |
| 2214 |
|
| 2215 |
lockdep_assert_held(&ab->base_lock); |
| 2216 |
|
| 2217 |
peer = ath11k_peer_find_by_id(ab, rxcb->peer_id); |
| 2218 |
|
| 2219 |
if (peer) |
| 2220 |
return peer; |
| 2221 |
|
| 2222 |
if (!rx_desc || !(ath11k_dp_rxdesc_mac_addr2_valid(ab, rx_desc))) |
| 2223 |
return NULL; |
| 2224 |
|
| 2225 |
peer = ath11k_peer_find_by_addr(ab, |
| 2226 |
ath11k_dp_rxdesc_mpdu_start_addr2(ab, rx_desc)); |
| 2227 |
return peer; |
| 2228 |
} |
| 2229 |
|
| 2230 |
static void ath11k_dp_rx_h_mpdu(struct ath11k *ar, |
| 2231 |
struct sk_buff *msdu, |
| 2232 |
struct hal_rx_desc *rx_desc, |
| 2233 |
struct ieee80211_rx_status *rx_status) |
| 2234 |
{ |
| 2235 |
bool fill_crypto_hdr; |
| 2236 |
enum hal_encrypt_type enctype; |
| 2237 |
bool is_decrypted = false; |
| 2238 |
struct ath11k_skb_rxcb *rxcb; |
| 2239 |
struct ieee80211_hdr *hdr; |
| 2240 |
struct ath11k_peer *peer; |
| 2241 |
struct rx_attention *rx_attention; |
| 2242 |
u32 err_bitmap; |
| 2243 |
|
| 2244 |
/* PN for multicast packets will be checked in mac80211 */ |
| 2245 |
rxcb = ATH11K_SKB_RXCB(msdu); |
| 2246 |
fill_crypto_hdr = ath11k_dp_rx_h_attn_is_mcbc(ar->ab, rx_desc); |
| 2247 |
rxcb->is_mcbc = fill_crypto_hdr; |
| 2248 |
|
| 2249 |
if (rxcb->is_mcbc) { |
| 2250 |
rxcb->peer_id = ath11k_dp_rx_h_mpdu_start_peer_id(ar->ab, rx_desc); |
| 2251 |
rxcb->seq_no = ath11k_dp_rx_h_mpdu_start_seq_no(ar->ab, rx_desc); |
| 2252 |
} |
| 2253 |
|
| 2254 |
spin_lock_bh(&ar->ab->base_lock); |
| 2255 |
peer = ath11k_dp_rx_h_find_peer(ar->ab, msdu); |
| 2256 |
if (peer) { |
| 2257 |
if (rxcb->is_mcbc) |
| 2258 |
enctype = peer->sec_type_grp; |
| 2259 |
else |
| 2260 |
enctype = peer->sec_type; |
| 2261 |
} else { |
| 2262 |
enctype = ath11k_dp_rx_h_mpdu_start_enctype(ar->ab, rx_desc); |
| 2263 |
} |
| 2264 |
spin_unlock_bh(&ar->ab->base_lock); |
| 2265 |
|
| 2266 |
rx_attention = ath11k_dp_rx_get_attention(ar->ab, rx_desc); |
| 2267 |
err_bitmap = ath11k_dp_rx_h_attn_mpdu_err(rx_attention); |
| 2268 |
if (enctype != HAL_ENCRYPT_TYPE_OPEN && !err_bitmap) |
| 2269 |
is_decrypted = ath11k_dp_rx_h_attn_is_decrypted(rx_attention); |
| 2270 |
|
| 2271 |
/* Clear per-MPDU flags while leaving per-PPDU flags intact */ |
| 2272 |
rx_status->flag &= ~(RX_FLAG_FAILED_FCS_CRC | |
| 2273 |
RX_FLAG_MMIC_ERROR | |
| 2274 |
RX_FLAG_DECRYPTED | |
| 2275 |
RX_FLAG_IV_STRIPPED | |
| 2276 |
RX_FLAG_MMIC_STRIPPED); |
| 2277 |
|
| 2278 |
if (err_bitmap & DP_RX_MPDU_ERR_FCS) |
| 2279 |
rx_status->flag |= RX_FLAG_FAILED_FCS_CRC; |
| 2280 |
if (err_bitmap & DP_RX_MPDU_ERR_TKIP_MIC) |
| 2281 |
rx_status->flag |= RX_FLAG_MMIC_ERROR; |
| 2282 |
|
| 2283 |
if (is_decrypted) { |
| 2284 |
rx_status->flag |= RX_FLAG_DECRYPTED | RX_FLAG_MMIC_STRIPPED; |
| 2285 |
|
| 2286 |
if (fill_crypto_hdr) |
| 2287 |
rx_status->flag |= RX_FLAG_MIC_STRIPPED | |
| 2288 |
RX_FLAG_ICV_STRIPPED; |
| 2289 |
else |
| 2290 |
rx_status->flag |= RX_FLAG_IV_STRIPPED | |
| 2291 |
RX_FLAG_PN_VALIDATED; |
| 2292 |
} |
| 2293 |
|
| 2294 |
ath11k_dp_rx_h_csum_offload(ar, msdu); |
| 2295 |
ath11k_dp_rx_h_undecap(ar, msdu, rx_desc, |
| 2296 |
enctype, rx_status, is_decrypted); |
| 2297 |
|
| 2298 |
if (!is_decrypted || fill_crypto_hdr) |
| 2299 |
return; |
| 2300 |
|
| 2301 |
if (ath11k_dp_rx_h_msdu_start_decap_type(ar->ab, rx_desc) != |
| 2302 |
DP_RX_DECAP_TYPE_ETHERNET2_DIX) { |
| 2303 |
hdr = (void *)msdu->data; |
| 2304 |
hdr->frame_control &= ~__cpu_to_le16(IEEE80211_FCTL_PROTECTED); |
| 2305 |
} |
| 2306 |
} |
| 2307 |
|
| 2308 |
static void ath11k_dp_rx_h_rate(struct ath11k *ar, struct hal_rx_desc *rx_desc, |
| 2309 |
struct ieee80211_rx_status *rx_status) |
| 2310 |
{ |
| 2311 |
struct ieee80211_supported_band *sband; |
| 2312 |
enum rx_msdu_start_pkt_type pkt_type; |
| 2313 |
u8 bw; |
| 2314 |
u8 rate_mcs, nss; |
| 2315 |
u8 sgi; |
| 2316 |
bool is_cck, is_ldpc; |
| 2317 |
|
| 2318 |
pkt_type = ath11k_dp_rx_h_msdu_start_pkt_type(ar->ab, rx_desc); |
| 2319 |
bw = ath11k_dp_rx_h_msdu_start_rx_bw(ar->ab, rx_desc); |
| 2320 |
rate_mcs = ath11k_dp_rx_h_msdu_start_rate_mcs(ar->ab, rx_desc); |
| 2321 |
nss = ath11k_dp_rx_h_msdu_start_nss(ar->ab, rx_desc); |
| 2322 |
sgi = ath11k_dp_rx_h_msdu_start_sgi(ar->ab, rx_desc); |
| 2323 |
|
| 2324 |
switch (pkt_type) { |
| 2325 |
case RX_MSDU_START_PKT_TYPE_11A: |
| 2326 |
case RX_MSDU_START_PKT_TYPE_11B: |
| 2327 |
is_cck = (pkt_type == RX_MSDU_START_PKT_TYPE_11B); |
| 2328 |
sband = &ar->mac.sbands[rx_status->band]; |
| 2329 |
rx_status->rate_idx = ath11k_mac_hw_rate_to_idx(sband, rate_mcs, |
| 2330 |
is_cck); |
| 2331 |
break; |
| 2332 |
case RX_MSDU_START_PKT_TYPE_11N: |
| 2333 |
rx_status->encoding = RX_ENC_HT; |
| 2334 |
if (rate_mcs > ATH11K_HT_MCS_MAX) { |
| 2335 |
ath11k_warn(ar->ab, |
| 2336 |
"Received with invalid mcs in HT mode %d\n", |
| 2337 |
rate_mcs); |
| 2338 |
break; |
| 2339 |
} |
| 2340 |
rx_status->rate_idx = rate_mcs + (8 * (nss - 1)); |
| 2341 |
if (sgi) |
| 2342 |
rx_status->enc_flags |= RX_ENC_FLAG_SHORT_GI; |
| 2343 |
rx_status->bw = ath11k_mac_bw_to_mac80211_bw(bw); |
| 2344 |
break; |
| 2345 |
case RX_MSDU_START_PKT_TYPE_11AC: |
| 2346 |
rx_status->encoding = RX_ENC_VHT; |
| 2347 |
rx_status->rate_idx = rate_mcs; |
| 2348 |
if (rate_mcs > ATH11K_VHT_MCS_MAX) { |
| 2349 |
ath11k_warn(ar->ab, |
| 2350 |
"Received with invalid mcs in VHT mode %d\n", |
| 2351 |
rate_mcs); |
| 2352 |
break; |
| 2353 |
} |
| 2354 |
rx_status->nss = nss; |
| 2355 |
if (sgi) |
| 2356 |
rx_status->enc_flags |= RX_ENC_FLAG_SHORT_GI; |
| 2357 |
rx_status->bw = ath11k_mac_bw_to_mac80211_bw(bw); |
| 2358 |
is_ldpc = ath11k_dp_rx_h_msdu_start_ldpc_support(ar->ab, rx_desc); |
| 2359 |
if (is_ldpc) |
| 2360 |
rx_status->enc_flags |= RX_ENC_FLAG_LDPC; |
| 2361 |
break; |
| 2362 |
case RX_MSDU_START_PKT_TYPE_11AX: |
| 2363 |
rx_status->rate_idx = rate_mcs; |
| 2364 |
if (rate_mcs > ATH11K_HE_MCS_MAX) { |
| 2365 |
ath11k_warn(ar->ab, |
| 2366 |
"Received with invalid mcs in HE mode %d\n", |
| 2367 |
rate_mcs); |
| 2368 |
break; |
| 2369 |
} |
| 2370 |
rx_status->encoding = RX_ENC_HE; |
| 2371 |
rx_status->nss = nss; |
| 2372 |
rx_status->he_gi = ath11k_mac_he_gi_to_nl80211_he_gi(sgi); |
| 2373 |
rx_status->bw = ath11k_mac_bw_to_mac80211_bw(bw); |
| 2374 |
break; |
| 2375 |
} |
| 2376 |
} |
| 2377 |
|
| 2378 |
static void ath11k_dp_rx_h_ppdu(struct ath11k *ar, struct hal_rx_desc *rx_desc, |
| 2379 |
struct ieee80211_rx_status *rx_status) |
| 2380 |
{ |
| 2381 |
u8 channel_num; |
| 2382 |
u32 center_freq, meta_data; |
| 2383 |
struct ieee80211_channel *channel; |
| 2384 |
|
| 2385 |
rx_status->freq = 0; |
| 2386 |
rx_status->rate_idx = 0; |
| 2387 |
rx_status->nss = 0; |
| 2388 |
rx_status->encoding = RX_ENC_LEGACY; |
| 2389 |
rx_status->bw = RATE_INFO_BW_20; |
| 2390 |
|
| 2391 |
rx_status->flag |= RX_FLAG_NO_SIGNAL_VAL; |
| 2392 |
|
| 2393 |
meta_data = ath11k_dp_rx_h_msdu_start_freq(ar->ab, rx_desc); |
| 2394 |
channel_num = meta_data; |
| 2395 |
center_freq = meta_data >> 16; |
| 2396 |
|
| 2397 |
if (center_freq >= ATH11K_MIN_6G_FREQ && |
| 2398 |
center_freq <= ATH11K_MAX_6G_FREQ) { |
| 2399 |
rx_status->band = NL80211_BAND_6GHZ; |
| 2400 |
rx_status->freq = center_freq; |
| 2401 |
} else if (channel_num >= 1 && channel_num <= 14) { |
| 2402 |
rx_status->band = NL80211_BAND_2GHZ; |
| 2403 |
} else if (channel_num >= 36 && channel_num <= 177) { |
| 2404 |
rx_status->band = NL80211_BAND_5GHZ; |
| 2405 |
} else { |
| 2406 |
spin_lock_bh(&ar->data_lock); |
| 2407 |
channel = ar->rx_channel; |
| 2408 |
if (channel) { |
| 2409 |
rx_status->band = channel->band; |
| 2410 |
channel_num = |
| 2411 |
ieee80211_frequency_to_channel(channel->center_freq); |
| 2412 |
} |
| 2413 |
spin_unlock_bh(&ar->data_lock); |
| 2414 |
ath11k_dbg_dump(ar->ab, ATH11K_DBG_DATA, NULL, "rx_desc: ", |
| 2415 |
rx_desc, sizeof(struct hal_rx_desc)); |
| 2416 |
} |
| 2417 |
|
| 2418 |
if (rx_status->band != NL80211_BAND_6GHZ) |
| 2419 |
rx_status->freq = ieee80211_channel_to_frequency(channel_num, |
| 2420 |
rx_status->band); |
| 2421 |
|
| 2422 |
ath11k_dp_rx_h_rate(ar, rx_desc, rx_status); |
| 2423 |
} |
| 2424 |
|
| 2425 |
static void ath11k_dp_rx_deliver_msdu(struct ath11k *ar, struct napi_struct *napi, |
| 2426 |
struct sk_buff *msdu, |
| 2427 |
struct ieee80211_rx_status *status) |
| 2428 |
{ |
| 2429 |
static const struct ieee80211_radiotap_he known = { |
| 2430 |
.data1 = cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_DATA_MCS_KNOWN | |
| 2431 |
IEEE80211_RADIOTAP_HE_DATA1_BW_RU_ALLOC_KNOWN), |
| 2432 |
.data2 = cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_GI_KNOWN), |
| 2433 |
}; |
| 2434 |
struct ieee80211_rx_status *rx_status; |
| 2435 |
struct ieee80211_radiotap_he *he = NULL; |
| 2436 |
struct ieee80211_sta *pubsta = NULL; |
| 2437 |
struct ath11k_peer *peer; |
| 2438 |
struct ath11k_skb_rxcb *rxcb = ATH11K_SKB_RXCB(msdu); |
| 2439 |
u8 decap = DP_RX_DECAP_TYPE_RAW; |
| 2440 |
bool is_mcbc = rxcb->is_mcbc; |
| 2441 |
bool is_eapol = rxcb->is_eapol; |
| 2442 |
|
| 2443 |
if (status->encoding == RX_ENC_HE && |
| 2444 |
!(status->flag & RX_FLAG_RADIOTAP_HE) && |
| 2445 |
!(status->flag & RX_FLAG_SKIP_MONITOR)) { |
| 2446 |
he = skb_push(msdu, sizeof(known)); |
| 2447 |
memcpy(he, &known, sizeof(known)); |
| 2448 |
status->flag |= RX_FLAG_RADIOTAP_HE; |
| 2449 |
} |
| 2450 |
|
| 2451 |
if (!(status->flag & RX_FLAG_ONLY_MONITOR)) |
| 2452 |
decap = ath11k_dp_rx_h_msdu_start_decap_type(ar->ab, rxcb->rx_desc); |
| 2453 |
|
| 2454 |
spin_lock_bh(&ar->ab->base_lock); |
| 2455 |
peer = ath11k_dp_rx_h_find_peer(ar->ab, msdu); |
| 2456 |
if (peer && peer->sta) |
| 2457 |
pubsta = peer->sta; |
| 2458 |
spin_unlock_bh(&ar->ab->base_lock); |
| 2459 |
|
| 2460 |
ath11k_dbg(ar->ab, ATH11K_DBG_DATA, |
| 2461 |
"rx skb %p len %u peer %pM %d %s sn %u %s%s%s%s%s%s%s %srate_idx %u vht_nss %u freq %u band %u flag 0x%x fcs-err %i mic-err %i amsdu-more %i\n", |
| 2462 |
msdu, |
| 2463 |
msdu->len, |
| 2464 |
peer ? peer->addr : NULL, |
| 2465 |
rxcb->tid, |
| 2466 |
is_mcbc ? "mcast" : "ucast", |
| 2467 |
rxcb->seq_no, |
| 2468 |
(status->encoding == RX_ENC_LEGACY) ? "legacy" : "", |
| 2469 |
(status->encoding == RX_ENC_HT) ? "ht" : "", |
| 2470 |
(status->encoding == RX_ENC_VHT) ? "vht" : "", |
| 2471 |
(status->encoding == RX_ENC_HE) ? "he" : "", |
| 2472 |
(status->bw == RATE_INFO_BW_40) ? "40" : "", |
| 2473 |
(status->bw == RATE_INFO_BW_80) ? "80" : "", |
| 2474 |
(status->bw == RATE_INFO_BW_160) ? "160" : "", |
| 2475 |
status->enc_flags & RX_ENC_FLAG_SHORT_GI ? "sgi " : "", |
| 2476 |
status->rate_idx, |
| 2477 |
status->nss, |
| 2478 |
status->freq, |
| 2479 |
status->band, status->flag, |
| 2480 |
!!(status->flag & RX_FLAG_FAILED_FCS_CRC), |
| 2481 |
!!(status->flag & RX_FLAG_MMIC_ERROR), |
| 2482 |
!!(status->flag & RX_FLAG_AMSDU_MORE)); |
| 2483 |
|
| 2484 |
ath11k_dbg_dump(ar->ab, ATH11K_DBG_DP_RX, NULL, "dp rx msdu: ", |
| 2485 |
msdu->data, msdu->len); |
| 2486 |
|
| 2487 |
rx_status = IEEE80211_SKB_RXCB(msdu); |
| 2488 |
*rx_status = *status; |
| 2489 |
|
| 2490 |
/* TODO: trace rx packet */ |
| 2491 |
|
| 2492 |
/* PN for multicast packets are not validate in HW, |
| 2493 |
* so skip 802.3 rx path |
| 2494 |
* Also, fast_rx expects the STA to be authorized, hence |
| 2495 |
* eapol packets are sent in slow path. |
| 2496 |
*/ |
| 2497 |
if (decap == DP_RX_DECAP_TYPE_ETHERNET2_DIX && !is_eapol && |
| 2498 |
!(is_mcbc && rx_status->flag & RX_FLAG_DECRYPTED)) |
| 2499 |
rx_status->flag |= RX_FLAG_8023; |
| 2500 |
|
| 2501 |
ieee80211_rx_napi(ar->hw, pubsta, msdu, napi); |
| 2502 |
} |
| 2503 |
|
| 2504 |
static int ath11k_dp_rx_process_msdu(struct ath11k *ar, |
| 2505 |
struct sk_buff *msdu, |
| 2506 |
struct sk_buff_head *msdu_list, |
| 2507 |
struct ieee80211_rx_status *rx_status) |
| 2508 |
{ |
| 2509 |
struct ath11k_base *ab = ar->ab; |
| 2510 |
struct hal_rx_desc *rx_desc, *lrx_desc; |
| 2511 |
struct rx_attention *rx_attention; |
| 2512 |
struct ath11k_skb_rxcb *rxcb; |
| 2513 |
struct sk_buff *last_buf; |
| 2514 |
u8 l3_pad_bytes; |
| 2515 |
u8 *hdr_status; |
| 2516 |
u16 msdu_len; |
| 2517 |
int ret; |
| 2518 |
u32 hal_rx_desc_sz = ar->ab->hw_params.hal_desc_sz; |
| 2519 |
|
| 2520 |
last_buf = ath11k_dp_rx_get_msdu_last_buf(msdu_list, msdu); |
| 2521 |
if (!last_buf) { |
| 2522 |
ath11k_warn(ab, |
| 2523 |
"No valid Rx buffer to access Atten/MSDU_END/MPDU_END tlvs\n"); |
| 2524 |
ret = -EIO; |
| 2525 |
goto free_out; |
| 2526 |
} |
| 2527 |
|
| 2528 |
rx_desc = (struct hal_rx_desc *)msdu->data; |
| 2529 |
if (ath11k_dp_rx_h_attn_msdu_len_err(ab, rx_desc)) { |
| 2530 |
ath11k_warn(ar->ab, "msdu len not valid\n"); |
| 2531 |
ret = -EIO; |
| 2532 |
goto free_out; |
| 2533 |
} |
| 2534 |
|
| 2535 |
lrx_desc = (struct hal_rx_desc *)last_buf->data; |
| 2536 |
rx_attention = ath11k_dp_rx_get_attention(ab, lrx_desc); |
| 2537 |
if (!ath11k_dp_rx_h_attn_msdu_done(rx_attention)) { |
| 2538 |
ath11k_warn(ab, "msdu_done bit in attention is not set\n"); |
| 2539 |
ret = -EIO; |
| 2540 |
goto free_out; |
| 2541 |
} |
| 2542 |
|
| 2543 |
rxcb = ATH11K_SKB_RXCB(msdu); |
| 2544 |
rxcb->rx_desc = rx_desc; |
| 2545 |
msdu_len = ath11k_dp_rx_h_msdu_start_msdu_len(ab, rx_desc); |
| 2546 |
l3_pad_bytes = ath11k_dp_rx_h_msdu_end_l3pad(ab, lrx_desc); |
| 2547 |
|
| 2548 |
if (rxcb->is_frag) { |
| 2549 |
skb_pull(msdu, hal_rx_desc_sz); |
| 2550 |
} else if (!rxcb->is_continuation) { |
| 2551 |
if ((msdu_len + hal_rx_desc_sz) > DP_RX_BUFFER_SIZE) { |
| 2552 |
hdr_status = ath11k_dp_rx_h_80211_hdr(ab, rx_desc); |
| 2553 |
ret = -EINVAL; |
| 2554 |
ath11k_warn(ab, "invalid msdu len %u\n", msdu_len); |
| 2555 |
ath11k_dbg_dump(ab, ATH11K_DBG_DATA, NULL, "", hdr_status, |
| 2556 |
sizeof(struct ieee80211_hdr)); |
| 2557 |
ath11k_dbg_dump(ab, ATH11K_DBG_DATA, NULL, "", rx_desc, |
| 2558 |
sizeof(struct hal_rx_desc)); |
| 2559 |
goto free_out; |
| 2560 |
} |
| 2561 |
skb_put(msdu, hal_rx_desc_sz + l3_pad_bytes + msdu_len); |
| 2562 |
skb_pull(msdu, hal_rx_desc_sz + l3_pad_bytes); |
| 2563 |
} else { |
| 2564 |
ret = ath11k_dp_rx_msdu_coalesce(ar, msdu_list, |
| 2565 |
msdu, last_buf, |
| 2566 |
l3_pad_bytes, msdu_len); |
| 2567 |
if (ret) { |
| 2568 |
ath11k_warn(ab, |
| 2569 |
"failed to coalesce msdu rx buffer%d\n", ret); |
| 2570 |
goto free_out; |
| 2571 |
} |
| 2572 |
} |
| 2573 |
|
| 2574 |
ath11k_dp_rx_h_ppdu(ar, rx_desc, rx_status); |
| 2575 |
ath11k_dp_rx_h_mpdu(ar, msdu, rx_desc, rx_status); |
| 2576 |
|
| 2577 |
rx_status->flag |= RX_FLAG_SKIP_MONITOR | RX_FLAG_DUP_VALIDATED; |
| 2578 |
|
| 2579 |
return 0; |
| 2580 |
|
| 2581 |
free_out: |
| 2582 |
return ret; |
| 2583 |
} |
| 2584 |
|
| 2585 |
static void ath11k_dp_rx_process_received_packets(struct ath11k_base *ab, |
| 2586 |
struct napi_struct *napi, |
| 2587 |
struct sk_buff_head *msdu_list, |
| 2588 |
int mac_id) |
| 2589 |
{ |
| 2590 |
struct sk_buff *msdu; |
| 2591 |
struct ath11k *ar; |
| 2592 |
struct ieee80211_rx_status rx_status = {}; |
| 2593 |
int ret; |
| 2594 |
|
| 2595 |
if (skb_queue_empty(msdu_list)) |
| 2596 |
return; |
| 2597 |
|
| 2598 |
if (unlikely(!rcu_access_pointer(ab->pdevs_active[mac_id]))) { |
| 2599 |
__skb_queue_purge(msdu_list); |
| 2600 |
return; |
| 2601 |
} |
| 2602 |
|
| 2603 |
ar = ab->pdevs[mac_id].ar; |
| 2604 |
if (unlikely(test_bit(ATH11K_CAC_RUNNING, &ar->dev_flags))) { |
| 2605 |
__skb_queue_purge(msdu_list); |
| 2606 |
return; |
| 2607 |
} |
| 2608 |
|
| 2609 |
while ((msdu = __skb_dequeue(msdu_list))) { |
| 2610 |
ret = ath11k_dp_rx_process_msdu(ar, msdu, msdu_list, &rx_status); |
| 2611 |
if (unlikely(ret)) { |
| 2612 |
ath11k_dbg(ab, ATH11K_DBG_DATA, |
| 2613 |
"Unable to process msdu %d", ret); |
| 2614 |
dev_kfree_skb_any(msdu); |
| 2615 |
continue; |
| 2616 |
} |
| 2617 |
|
| 2618 |
ath11k_dp_rx_deliver_msdu(ar, napi, msdu, &rx_status); |
| 2619 |
} |
| 2620 |
} |
| 2621 |
|
| 2622 |
int ath11k_dp_process_rx(struct ath11k_base *ab, int ring_id, |
| 2623 |
struct napi_struct *napi, int budget) |
| 2624 |
{ |
| 2625 |
struct ath11k_dp *dp = &ab->dp; |
| 2626 |
struct dp_rxdma_ring *rx_ring; |
| 2627 |
int num_buffs_reaped[MAX_RADIOS] = {}; |
| 2628 |
struct sk_buff_head msdu_list[MAX_RADIOS]; |
| 2629 |
struct ath11k_skb_rxcb *rxcb; |
| 2630 |
int total_msdu_reaped = 0; |
| 2631 |
struct hal_srng *srng; |
| 2632 |
struct sk_buff *msdu; |
| 2633 |
bool done = false; |
| 2634 |
int buf_id, mac_id; |
| 2635 |
struct ath11k *ar; |
| 2636 |
struct hal_reo_dest_ring *desc; |
| 2637 |
enum hal_reo_dest_ring_push_reason push_reason; |
| 2638 |
u32 cookie; |
| 2639 |
int i; |
| 2640 |
|
| 2641 |
for (i = 0; i < MAX_RADIOS; i++) |
| 2642 |
__skb_queue_head_init(&msdu_list[i]); |
| 2643 |
|
| 2644 |
srng = &ab->hal.srng_list[dp->reo_dst_ring[ring_id].ring_id]; |
| 2645 |
|
| 2646 |
spin_lock_bh(&srng->lock); |
| 2647 |
|
| 2648 |
try_again: |
| 2649 |
ath11k_hal_srng_access_begin(ab, srng); |
| 2650 |
|
| 2651 |
while (likely(desc = |
| 2652 |
(struct hal_reo_dest_ring *)ath11k_hal_srng_dst_get_next_entry(ab, |
| 2653 |
srng))) { |
| 2654 |
cookie = FIELD_GET(BUFFER_ADDR_INFO1_SW_COOKIE, |
| 2655 |
desc->buf_addr_info.info1); |
| 2656 |
buf_id = FIELD_GET(DP_RXDMA_BUF_COOKIE_BUF_ID, |
| 2657 |
cookie); |
| 2658 |
mac_id = FIELD_GET(DP_RXDMA_BUF_COOKIE_PDEV_ID, cookie); |
| 2659 |
|
| 2660 |
if (unlikely(buf_id == 0)) |
| 2661 |
continue; |
| 2662 |
|
| 2663 |
ar = ab->pdevs[mac_id].ar; |
| 2664 |
rx_ring = &ar->dp.rx_refill_buf_ring; |
| 2665 |
spin_lock_bh(&rx_ring->idr_lock); |
| 2666 |
msdu = idr_find(&rx_ring->bufs_idr, buf_id); |
| 2667 |
if (unlikely(!msdu)) { |
| 2668 |
ath11k_warn(ab, "frame rx with invalid buf_id %d\n", |
| 2669 |
buf_id); |
| 2670 |
spin_unlock_bh(&rx_ring->idr_lock); |
| 2671 |
continue; |
| 2672 |
} |
| 2673 |
|
| 2674 |
idr_remove(&rx_ring->bufs_idr, buf_id); |
| 2675 |
spin_unlock_bh(&rx_ring->idr_lock); |
| 2676 |
|
| 2677 |
rxcb = ATH11K_SKB_RXCB(msdu); |
| 2678 |
dma_unmap_single(ab->dev, rxcb->paddr, |
| 2679 |
msdu->len + skb_tailroom(msdu), |
| 2680 |
DMA_FROM_DEVICE); |
| 2681 |
|
| 2682 |
num_buffs_reaped[mac_id]++; |
| 2683 |
|
| 2684 |
push_reason = FIELD_GET(HAL_REO_DEST_RING_INFO0_PUSH_REASON, |
| 2685 |
desc->info0); |
| 2686 |
if (unlikely(push_reason != |
| 2687 |
HAL_REO_DEST_RING_PUSH_REASON_ROUTING_INSTRUCTION)) { |
| 2688 |
dev_kfree_skb_any(msdu); |
| 2689 |
ab->soc_stats.hal_reo_error[ring_id]++; |
| 2690 |
continue; |
| 2691 |
} |
| 2692 |
|
| 2693 |
rxcb->is_first_msdu = !!(desc->rx_msdu_info.info0 & |
| 2694 |
RX_MSDU_DESC_INFO0_FIRST_MSDU_IN_MPDU); |
| 2695 |
rxcb->is_last_msdu = !!(desc->rx_msdu_info.info0 & |
| 2696 |
RX_MSDU_DESC_INFO0_LAST_MSDU_IN_MPDU); |
| 2697 |
rxcb->is_continuation = !!(desc->rx_msdu_info.info0 & |
| 2698 |
RX_MSDU_DESC_INFO0_MSDU_CONTINUATION); |
| 2699 |
rxcb->peer_id = FIELD_GET(RX_MPDU_DESC_META_DATA_PEER_ID, |
| 2700 |
desc->rx_mpdu_info.meta_data); |
| 2701 |
rxcb->seq_no = FIELD_GET(RX_MPDU_DESC_INFO0_SEQ_NUM, |
| 2702 |
desc->rx_mpdu_info.info0); |
| 2703 |
rxcb->tid = FIELD_GET(HAL_REO_DEST_RING_INFO0_RX_QUEUE_NUM, |
| 2704 |
desc->info0); |
| 2705 |
|
| 2706 |
rxcb->mac_id = mac_id; |
| 2707 |
__skb_queue_tail(&msdu_list[mac_id], msdu); |
| 2708 |
|
| 2709 |
if (rxcb->is_continuation) { |
| 2710 |
done = false; |
| 2711 |
} else { |
| 2712 |
total_msdu_reaped++; |
| 2713 |
done = true; |
| 2714 |
} |
| 2715 |
|
| 2716 |
if (total_msdu_reaped >= budget) |
| 2717 |
break; |
| 2718 |
} |
| 2719 |
|
| 2720 |
/* Hw might have updated the head pointer after we cached it. |
| 2721 |
* In this case, even though there are entries in the ring we'll |
| 2722 |
* get rx_desc NULL. Give the read another try with updated cached |
| 2723 |
* head pointer so that we can reap complete MPDU in the current |
| 2724 |
* rx processing. |
| 2725 |
*/ |
| 2726 |
if (unlikely(!done && ath11k_hal_srng_dst_num_free(ab, srng, true))) { |
| 2727 |
ath11k_hal_srng_access_end(ab, srng); |
| 2728 |
goto try_again; |
| 2729 |
} |
| 2730 |
|
| 2731 |
ath11k_hal_srng_access_end(ab, srng); |
| 2732 |
|
| 2733 |
spin_unlock_bh(&srng->lock); |
| 2734 |
|
| 2735 |
if (unlikely(!total_msdu_reaped)) |
| 2736 |
goto exit; |
| 2737 |
|
| 2738 |
for (i = 0; i < ab->num_radios; i++) { |
| 2739 |
if (!num_buffs_reaped[i]) |
| 2740 |
continue; |
| 2741 |
|
| 2742 |
ath11k_dp_rx_process_received_packets(ab, napi, &msdu_list[i], i); |
| 2743 |
|
| 2744 |
ar = ab->pdevs[i].ar; |
| 2745 |
rx_ring = &ar->dp.rx_refill_buf_ring; |
| 2746 |
|
| 2747 |
ath11k_dp_rxbufs_replenish(ab, i, rx_ring, num_buffs_reaped[i], |
| 2748 |
ab->hw_params.hal_params->rx_buf_rbm); |
| 2749 |
} |
| 2750 |
exit: |
| 2751 |
return total_msdu_reaped; |
| 2752 |
} |
| 2753 |
|
| 2754 |
static void ath11k_dp_rx_update_peer_stats(struct ath11k_sta *arsta, |
| 2755 |
struct hal_rx_mon_ppdu_info *ppdu_info) |
| 2756 |
{ |
| 2757 |
struct ath11k_rx_peer_stats *rx_stats = arsta->rx_stats; |
| 2758 |
u32 num_msdu; |
| 2759 |
int i; |
| 2760 |
|
| 2761 |
if (!rx_stats) |
| 2762 |
return; |
| 2763 |
|
| 2764 |
arsta->rssi_comb = ppdu_info->rssi_comb; |
| 2765 |
ewma_avg_rssi_add(&arsta->avg_rssi, ppdu_info->rssi_comb); |
| 2766 |
|
| 2767 |
num_msdu = ppdu_info->tcp_msdu_count + ppdu_info->tcp_ack_msdu_count + |
| 2768 |
ppdu_info->udp_msdu_count + ppdu_info->other_msdu_count; |
| 2769 |
|
| 2770 |
rx_stats->num_msdu += num_msdu; |
| 2771 |
rx_stats->tcp_msdu_count += ppdu_info->tcp_msdu_count + |
| 2772 |
ppdu_info->tcp_ack_msdu_count; |
| 2773 |
rx_stats->udp_msdu_count += ppdu_info->udp_msdu_count; |
| 2774 |
rx_stats->other_msdu_count += ppdu_info->other_msdu_count; |
| 2775 |
|
| 2776 |
if (ppdu_info->preamble_type == HAL_RX_PREAMBLE_11A || |
| 2777 |
ppdu_info->preamble_type == HAL_RX_PREAMBLE_11B) { |
| 2778 |
ppdu_info->nss = 1; |
| 2779 |
ppdu_info->mcs = HAL_RX_MAX_MCS; |
| 2780 |
ppdu_info->tid = IEEE80211_NUM_TIDS; |
| 2781 |
} |
| 2782 |
|
| 2783 |
if (ppdu_info->nss > 0 && ppdu_info->nss <= HAL_RX_MAX_NSS) |
| 2784 |
rx_stats->nss_count[ppdu_info->nss - 1] += num_msdu; |
| 2785 |
|
| 2786 |
if (ppdu_info->mcs <= HAL_RX_MAX_MCS) |
| 2787 |
rx_stats->mcs_count[ppdu_info->mcs] += num_msdu; |
| 2788 |
|
| 2789 |
if (ppdu_info->gi < HAL_RX_GI_MAX) |
| 2790 |
rx_stats->gi_count[ppdu_info->gi] += num_msdu; |
| 2791 |
|
| 2792 |
if (ppdu_info->bw < HAL_RX_BW_MAX) |
| 2793 |
rx_stats->bw_count[ppdu_info->bw] += num_msdu; |
| 2794 |
|
| 2795 |
if (ppdu_info->ldpc < HAL_RX_SU_MU_CODING_MAX) |
| 2796 |
rx_stats->coding_count[ppdu_info->ldpc] += num_msdu; |
| 2797 |
|
| 2798 |
if (ppdu_info->tid <= IEEE80211_NUM_TIDS) |
| 2799 |
rx_stats->tid_count[ppdu_info->tid] += num_msdu; |
| 2800 |
|
| 2801 |
if (ppdu_info->preamble_type < HAL_RX_PREAMBLE_MAX) |
| 2802 |
rx_stats->pream_cnt[ppdu_info->preamble_type] += num_msdu; |
| 2803 |
|
| 2804 |
if (ppdu_info->reception_type < HAL_RX_RECEPTION_TYPE_MAX) |
| 2805 |
rx_stats->reception_type[ppdu_info->reception_type] += num_msdu; |
| 2806 |
|
| 2807 |
if (ppdu_info->is_stbc) |
| 2808 |
rx_stats->stbc_count += num_msdu; |
| 2809 |
|
| 2810 |
if (ppdu_info->beamformed) |
| 2811 |
rx_stats->beamformed_count += num_msdu; |
| 2812 |
|
| 2813 |
if (ppdu_info->num_mpdu_fcs_ok > 1) |
| 2814 |
rx_stats->ampdu_msdu_count += num_msdu; |
| 2815 |
else |
| 2816 |
rx_stats->non_ampdu_msdu_count += num_msdu; |
| 2817 |
|
| 2818 |
rx_stats->num_mpdu_fcs_ok += ppdu_info->num_mpdu_fcs_ok; |
| 2819 |
rx_stats->num_mpdu_fcs_err += ppdu_info->num_mpdu_fcs_err; |
| 2820 |
rx_stats->dcm_count += ppdu_info->dcm; |
| 2821 |
rx_stats->ru_alloc_cnt[ppdu_info->ru_alloc] += num_msdu; |
| 2822 |
|
| 2823 |
BUILD_BUG_ON(ARRAY_SIZE(arsta->chain_signal) > |
| 2824 |
ARRAY_SIZE(ppdu_info->rssi_chain_pri20)); |
| 2825 |
|
| 2826 |
for (i = 0; i < ARRAY_SIZE(arsta->chain_signal); i++) |
| 2827 |
arsta->chain_signal[i] = ppdu_info->rssi_chain_pri20[i]; |
| 2828 |
|
| 2829 |
rx_stats->rx_duration += ppdu_info->rx_duration; |
| 2830 |
arsta->rx_duration = rx_stats->rx_duration; |
| 2831 |
} |
| 2832 |
|
| 2833 |
static struct sk_buff *ath11k_dp_rx_alloc_mon_status_buf(struct ath11k_base *ab, |
| 2834 |
struct dp_rxdma_ring *rx_ring, |
| 2835 |
int *buf_id) |
| 2836 |
{ |
| 2837 |
struct sk_buff *skb; |
| 2838 |
dma_addr_t paddr; |
| 2839 |
|
| 2840 |
skb = dev_alloc_skb(DP_RX_BUFFER_SIZE + |
| 2841 |
DP_RX_BUFFER_ALIGN_SIZE); |
| 2842 |
|
| 2843 |
if (!skb) |
| 2844 |
goto fail_alloc_skb; |
| 2845 |
|
| 2846 |
if (!IS_ALIGNED((unsigned long)skb->data, |
| 2847 |
DP_RX_BUFFER_ALIGN_SIZE)) { |
| 2848 |
skb_pull(skb, PTR_ALIGN(skb->data, DP_RX_BUFFER_ALIGN_SIZE) - |
| 2849 |
skb->data); |
| 2850 |
} |
| 2851 |
|
| 2852 |
paddr = dma_map_single(ab->dev, skb->data, |
| 2853 |
skb->len + skb_tailroom(skb), |
| 2854 |
DMA_FROM_DEVICE); |
| 2855 |
if (unlikely(dma_mapping_error(ab->dev, paddr))) |
| 2856 |
goto fail_free_skb; |
| 2857 |
|
| 2858 |
spin_lock_bh(&rx_ring->idr_lock); |
| 2859 |
*buf_id = idr_alloc(&rx_ring->bufs_idr, skb, 0, |
| 2860 |
rx_ring->bufs_max, GFP_ATOMIC); |
| 2861 |
spin_unlock_bh(&rx_ring->idr_lock); |
| 2862 |
if (*buf_id < 0) |
| 2863 |
goto fail_dma_unmap; |
| 2864 |
|
| 2865 |
ATH11K_SKB_RXCB(skb)->paddr = paddr; |
| 2866 |
return skb; |
| 2867 |
|
| 2868 |
fail_dma_unmap: |
| 2869 |
dma_unmap_single(ab->dev, paddr, skb->len + skb_tailroom(skb), |
| 2870 |
DMA_FROM_DEVICE); |
| 2871 |
fail_free_skb: |
| 2872 |
dev_kfree_skb_any(skb); |
| 2873 |
fail_alloc_skb: |
| 2874 |
return NULL; |
| 2875 |
} |
| 2876 |
|
| 2877 |
int ath11k_dp_rx_mon_status_bufs_replenish(struct ath11k_base *ab, int mac_id, |
| 2878 |
struct dp_rxdma_ring *rx_ring, |
| 2879 |
int req_entries, |
| 2880 |
enum hal_rx_buf_return_buf_manager mgr) |
| 2881 |
{ |
| 2882 |
struct hal_srng *srng; |
| 2883 |
u32 *desc; |
| 2884 |
struct sk_buff *skb; |
| 2885 |
int num_free; |
| 2886 |
int num_remain; |
| 2887 |
int buf_id; |
| 2888 |
u32 cookie; |
| 2889 |
dma_addr_t paddr; |
| 2890 |
|
| 2891 |
req_entries = min(req_entries, rx_ring->bufs_max); |
| 2892 |
|
| 2893 |
srng = &ab->hal.srng_list[rx_ring->refill_buf_ring.ring_id]; |
| 2894 |
|
| 2895 |
spin_lock_bh(&srng->lock); |
| 2896 |
|
| 2897 |
ath11k_hal_srng_access_begin(ab, srng); |
| 2898 |
|
| 2899 |
num_free = ath11k_hal_srng_src_num_free(ab, srng, true); |
| 2900 |
|
| 2901 |
req_entries = min(num_free, req_entries); |
| 2902 |
num_remain = req_entries; |
| 2903 |
|
| 2904 |
while (num_remain > 0) { |
| 2905 |
skb = ath11k_dp_rx_alloc_mon_status_buf(ab, rx_ring, |
| 2906 |
&buf_id); |
| 2907 |
if (!skb) |
| 2908 |
break; |
| 2909 |
paddr = ATH11K_SKB_RXCB(skb)->paddr; |
| 2910 |
|
| 2911 |
desc = ath11k_hal_srng_src_get_next_entry(ab, srng); |
| 2912 |
if (!desc) |
| 2913 |
goto fail_desc_get; |
| 2914 |
|
| 2915 |
cookie = FIELD_PREP(DP_RXDMA_BUF_COOKIE_PDEV_ID, mac_id) | |
| 2916 |
FIELD_PREP(DP_RXDMA_BUF_COOKIE_BUF_ID, buf_id); |
| 2917 |
|
| 2918 |
num_remain--; |
| 2919 |
|
| 2920 |
ath11k_hal_rx_buf_addr_info_set(desc, paddr, cookie, mgr); |
| 2921 |
} |
| 2922 |
|
| 2923 |
ath11k_hal_srng_access_end(ab, srng); |
| 2924 |
|
| 2925 |
spin_unlock_bh(&srng->lock); |
| 2926 |
|
| 2927 |
return req_entries - num_remain; |
| 2928 |
|
| 2929 |
fail_desc_get: |
| 2930 |
spin_lock_bh(&rx_ring->idr_lock); |
| 2931 |
idr_remove(&rx_ring->bufs_idr, buf_id); |
| 2932 |
spin_unlock_bh(&rx_ring->idr_lock); |
| 2933 |
dma_unmap_single(ab->dev, paddr, skb->len + skb_tailroom(skb), |
| 2934 |
DMA_FROM_DEVICE); |
| 2935 |
dev_kfree_skb_any(skb); |
| 2936 |
ath11k_hal_srng_access_end(ab, srng); |
| 2937 |
spin_unlock_bh(&srng->lock); |
| 2938 |
|
| 2939 |
return req_entries - num_remain; |
| 2940 |
} |
| 2941 |
|
| 2942 |
#define ATH11K_DP_RX_FULL_MON_PPDU_ID_WRAP 32535 |
| 2943 |
|
| 2944 |
static void |
| 2945 |
ath11k_dp_rx_mon_update_status_buf_state(struct ath11k_mon_data *pmon, |
| 2946 |
struct hal_tlv_hdr *tlv) |
| 2947 |
{ |
| 2948 |
struct hal_rx_ppdu_start *ppdu_start; |
| 2949 |
u16 ppdu_id_diff, ppdu_id, tlv_len; |
| 2950 |
u8 *ptr; |
| 2951 |
|
| 2952 |
/* PPDU id is part of second tlv, move ptr to second tlv */ |
| 2953 |
tlv_len = FIELD_GET(HAL_TLV_HDR_LEN, tlv->tl); |
| 2954 |
ptr = (u8 *)tlv; |
| 2955 |
ptr += sizeof(*tlv) + tlv_len; |
| 2956 |
tlv = (struct hal_tlv_hdr *)ptr; |
| 2957 |
|
| 2958 |
if (FIELD_GET(HAL_TLV_HDR_TAG, tlv->tl) != HAL_RX_PPDU_START) |
| 2959 |
return; |
| 2960 |
|
| 2961 |
ptr += sizeof(*tlv); |
| 2962 |
ppdu_start = (struct hal_rx_ppdu_start *)ptr; |
| 2963 |
ppdu_id = FIELD_GET(HAL_RX_PPDU_START_INFO0_PPDU_ID, |
| 2964 |
__le32_to_cpu(ppdu_start->info0)); |
| 2965 |
|
| 2966 |
if (pmon->sw_mon_entries.ppdu_id < ppdu_id) { |
| 2967 |
pmon->buf_state = DP_MON_STATUS_LEAD; |
| 2968 |
ppdu_id_diff = ppdu_id - pmon->sw_mon_entries.ppdu_id; |
| 2969 |
if (ppdu_id_diff > ATH11K_DP_RX_FULL_MON_PPDU_ID_WRAP) |
| 2970 |
pmon->buf_state = DP_MON_STATUS_LAG; |
| 2971 |
} else if (pmon->sw_mon_entries.ppdu_id > ppdu_id) { |
| 2972 |
pmon->buf_state = DP_MON_STATUS_LAG; |
| 2973 |
ppdu_id_diff = pmon->sw_mon_entries.ppdu_id - ppdu_id; |
| 2974 |
if (ppdu_id_diff > ATH11K_DP_RX_FULL_MON_PPDU_ID_WRAP) |
| 2975 |
pmon->buf_state = DP_MON_STATUS_LEAD; |
| 2976 |
} |
| 2977 |
} |
| 2978 |
|
| 2979 |
static enum dp_mon_status_buf_state |
| 2980 |
ath11k_dp_rx_mon_buf_done(struct ath11k_base *ab, struct hal_srng *srng, |
| 2981 |
struct dp_rxdma_ring *rx_ring) |
| 2982 |
{ |
| 2983 |
struct ath11k_skb_rxcb *rxcb; |
| 2984 |
struct hal_tlv_hdr *tlv; |
| 2985 |
struct sk_buff *skb; |
| 2986 |
void *status_desc; |
| 2987 |
dma_addr_t paddr; |
| 2988 |
u32 cookie; |
| 2989 |
int buf_id; |
| 2990 |
u8 rbm; |
| 2991 |
|
| 2992 |
status_desc = ath11k_hal_srng_src_next_peek(ab, srng); |
| 2993 |
if (!status_desc) |
| 2994 |
return DP_MON_STATUS_NO_DMA; |
| 2995 |
|
| 2996 |
ath11k_hal_rx_buf_addr_info_get(status_desc, &paddr, &cookie, &rbm); |
| 2997 |
|
| 2998 |
buf_id = FIELD_GET(DP_RXDMA_BUF_COOKIE_BUF_ID, cookie); |
| 2999 |
|
| 3000 |
spin_lock_bh(&rx_ring->idr_lock); |
| 3001 |
skb = idr_find(&rx_ring->bufs_idr, buf_id); |
| 3002 |
spin_unlock_bh(&rx_ring->idr_lock); |
| 3003 |
|
| 3004 |
if (!skb) |
| 3005 |
return DP_MON_STATUS_NO_DMA; |
| 3006 |
|
| 3007 |
rxcb = ATH11K_SKB_RXCB(skb); |
| 3008 |
dma_sync_single_for_cpu(ab->dev, rxcb->paddr, |
| 3009 |
skb->len + skb_tailroom(skb), |
| 3010 |
DMA_FROM_DEVICE); |
| 3011 |
|
| 3012 |
tlv = (struct hal_tlv_hdr *)skb->data; |
| 3013 |
if (FIELD_GET(HAL_TLV_HDR_TAG, tlv->tl) != HAL_RX_STATUS_BUFFER_DONE) |
| 3014 |
return DP_MON_STATUS_NO_DMA; |
| 3015 |
|
| 3016 |
return DP_MON_STATUS_REPLINISH; |
| 3017 |
} |
| 3018 |
|
| 3019 |
static int ath11k_dp_rx_reap_mon_status_ring(struct ath11k_base *ab, int mac_id, |
| 3020 |
int *budget, struct sk_buff_head *skb_list) |
| 3021 |
{ |
| 3022 |
struct ath11k *ar; |
| 3023 |
const struct ath11k_hw_hal_params *hal_params; |
| 3024 |
enum dp_mon_status_buf_state reap_status; |
| 3025 |
struct ath11k_pdev_dp *dp; |
| 3026 |
struct dp_rxdma_ring *rx_ring; |
| 3027 |
struct ath11k_mon_data *pmon; |
| 3028 |
struct hal_srng *srng; |
| 3029 |
void *rx_mon_status_desc; |
| 3030 |
struct sk_buff *skb; |
| 3031 |
struct ath11k_skb_rxcb *rxcb; |
| 3032 |
struct hal_tlv_hdr *tlv; |
| 3033 |
u32 cookie; |
| 3034 |
int buf_id, srng_id; |
| 3035 |
dma_addr_t paddr; |
| 3036 |
u8 rbm; |
| 3037 |
int num_buffs_reaped = 0; |
| 3038 |
|
| 3039 |
ar = ab->pdevs[ath11k_hw_mac_id_to_pdev_id(&ab->hw_params, mac_id)].ar; |
| 3040 |
dp = &ar->dp; |
| 3041 |
pmon = &dp->mon_data; |
| 3042 |
srng_id = ath11k_hw_mac_id_to_srng_id(&ab->hw_params, mac_id); |
| 3043 |
rx_ring = &dp->rx_mon_status_refill_ring[srng_id]; |
| 3044 |
|
| 3045 |
srng = &ab->hal.srng_list[rx_ring->refill_buf_ring.ring_id]; |
| 3046 |
|
| 3047 |
spin_lock_bh(&srng->lock); |
| 3048 |
|
| 3049 |
ath11k_hal_srng_access_begin(ab, srng); |
| 3050 |
while (*budget) { |
| 3051 |
*budget -= 1; |
| 3052 |
rx_mon_status_desc = |
| 3053 |
ath11k_hal_srng_src_peek(ab, srng); |
| 3054 |
if (!rx_mon_status_desc) { |
| 3055 |
pmon->buf_state = DP_MON_STATUS_REPLINISH; |
| 3056 |
break; |
| 3057 |
} |
| 3058 |
|
| 3059 |
ath11k_hal_rx_buf_addr_info_get(rx_mon_status_desc, &paddr, |
| 3060 |
&cookie, &rbm); |
| 3061 |
if (paddr) { |
| 3062 |
buf_id = FIELD_GET(DP_RXDMA_BUF_COOKIE_BUF_ID, cookie); |
| 3063 |
|
| 3064 |
spin_lock_bh(&rx_ring->idr_lock); |
| 3065 |
skb = idr_find(&rx_ring->bufs_idr, buf_id); |
| 3066 |
spin_unlock_bh(&rx_ring->idr_lock); |
| 3067 |
|
| 3068 |
if (!skb) { |
| 3069 |
ath11k_warn(ab, "rx monitor status with invalid buf_id %d\n", |
| 3070 |
buf_id); |
| 3071 |
pmon->buf_state = DP_MON_STATUS_REPLINISH; |
| 3072 |
goto move_next; |
| 3073 |
} |
| 3074 |
|
| 3075 |
rxcb = ATH11K_SKB_RXCB(skb); |
| 3076 |
|
| 3077 |
dma_sync_single_for_cpu(ab->dev, rxcb->paddr, |
| 3078 |
skb->len + skb_tailroom(skb), |
| 3079 |
DMA_FROM_DEVICE); |
| 3080 |
|
| 3081 |
tlv = (struct hal_tlv_hdr *)skb->data; |
| 3082 |
if (FIELD_GET(HAL_TLV_HDR_TAG, tlv->tl) != |
| 3083 |
HAL_RX_STATUS_BUFFER_DONE) { |
| 3084 |
ath11k_warn(ab, "mon status DONE not set %lx, buf_id %d\n", |
| 3085 |
FIELD_GET(HAL_TLV_HDR_TAG, |
| 3086 |
tlv->tl), buf_id); |
| 3087 |
/* RxDMA status done bit might not be set even |
| 3088 |
* though tp is moved by HW. |
| 3089 |
*/ |
| 3090 |
|
| 3091 |
/* If done status is missing: |
| 3092 |
* 1. As per MAC team's suggestion, |
| 3093 |
* when HP + 1 entry is peeked and if DMA |
| 3094 |
* is not done and if HP + 2 entry's DMA done |
| 3095 |
* is set. skip HP + 1 entry and |
| 3096 |
* start processing in next interrupt. |
| 3097 |
* 2. If HP + 2 entry's DMA done is not set, |
| 3098 |
* poll onto HP + 1 entry DMA done to be set. |
| 3099 |
* Check status for same buffer for next time |
| 3100 |
* dp_rx_mon_status_srng_process |
| 3101 |
*/ |
| 3102 |
|
| 3103 |
reap_status = ath11k_dp_rx_mon_buf_done(ab, srng, |
| 3104 |
rx_ring); |
| 3105 |
if (reap_status == DP_MON_STATUS_NO_DMA) |
| 3106 |
continue; |
| 3107 |
|
| 3108 |
spin_lock_bh(&rx_ring->idr_lock); |
| 3109 |
idr_remove(&rx_ring->bufs_idr, buf_id); |
| 3110 |
spin_unlock_bh(&rx_ring->idr_lock); |
| 3111 |
|
| 3112 |
dma_unmap_single(ab->dev, rxcb->paddr, |
| 3113 |
skb->len + skb_tailroom(skb), |
| 3114 |
DMA_FROM_DEVICE); |
| 3115 |
|
| 3116 |
dev_kfree_skb_any(skb); |
| 3117 |
pmon->buf_state = DP_MON_STATUS_REPLINISH; |
| 3118 |
goto move_next; |
| 3119 |
} |
| 3120 |
|
| 3121 |
spin_lock_bh(&rx_ring->idr_lock); |
| 3122 |
idr_remove(&rx_ring->bufs_idr, buf_id); |
| 3123 |
spin_unlock_bh(&rx_ring->idr_lock); |
| 3124 |
if (ab->hw_params.full_monitor_mode) { |
| 3125 |
ath11k_dp_rx_mon_update_status_buf_state(pmon, tlv); |
| 3126 |
if (paddr == pmon->mon_status_paddr) |
| 3127 |
pmon->buf_state = DP_MON_STATUS_MATCH; |
| 3128 |
} |
| 3129 |
|
| 3130 |
dma_unmap_single(ab->dev, rxcb->paddr, |
| 3131 |
skb->len + skb_tailroom(skb), |
| 3132 |
DMA_FROM_DEVICE); |
| 3133 |
|
| 3134 |
__skb_queue_tail(skb_list, skb); |
| 3135 |
} else { |
| 3136 |
pmon->buf_state = DP_MON_STATUS_REPLINISH; |
| 3137 |
} |
| 3138 |
move_next: |
| 3139 |
skb = ath11k_dp_rx_alloc_mon_status_buf(ab, rx_ring, |
| 3140 |
&buf_id); |
| 3141 |
|
| 3142 |
if (!skb) { |
| 3143 |
hal_params = ab->hw_params.hal_params; |
| 3144 |
ath11k_hal_rx_buf_addr_info_set(rx_mon_status_desc, 0, 0, |
| 3145 |
hal_params->rx_buf_rbm); |
| 3146 |
num_buffs_reaped++; |
| 3147 |
break; |
| 3148 |
} |
| 3149 |
rxcb = ATH11K_SKB_RXCB(skb); |
| 3150 |
|
| 3151 |
cookie = FIELD_PREP(DP_RXDMA_BUF_COOKIE_PDEV_ID, mac_id) | |
| 3152 |
FIELD_PREP(DP_RXDMA_BUF_COOKIE_BUF_ID, buf_id); |
| 3153 |
|
| 3154 |
ath11k_hal_rx_buf_addr_info_set(rx_mon_status_desc, rxcb->paddr, |
| 3155 |
cookie, |
| 3156 |
ab->hw_params.hal_params->rx_buf_rbm); |
| 3157 |
ath11k_hal_srng_src_get_next_entry(ab, srng); |
| 3158 |
num_buffs_reaped++; |
| 3159 |
} |
| 3160 |
ath11k_hal_srng_access_end(ab, srng); |
| 3161 |
spin_unlock_bh(&srng->lock); |
| 3162 |
|
| 3163 |
return num_buffs_reaped; |
| 3164 |
} |
| 3165 |
|
| 3166 |
static void ath11k_dp_rx_frag_timer(struct timer_list *timer) |
| 3167 |
{ |
| 3168 |
struct dp_rx_tid *rx_tid = timer_container_of(rx_tid, timer, |
| 3169 |
frag_timer); |
| 3170 |
|
| 3171 |
spin_lock_bh(&rx_tid->ab->base_lock); |
| 3172 |
if (rx_tid->last_frag_no && |
| 3173 |
rx_tid->rx_frag_bitmap == GENMASK(rx_tid->last_frag_no, 0)) { |
| 3174 |
spin_unlock_bh(&rx_tid->ab->base_lock); |
| 3175 |
return; |
| 3176 |
} |
| 3177 |
ath11k_dp_rx_frags_cleanup(rx_tid, true); |
| 3178 |
spin_unlock_bh(&rx_tid->ab->base_lock); |
| 3179 |
} |
| 3180 |
|
| 3181 |
int ath11k_peer_rx_frag_setup(struct ath11k *ar, const u8 *peer_mac, int vdev_id) |
| 3182 |
{ |
| 3183 |
struct ath11k_base *ab = ar->ab; |
| 3184 |
struct crypto_shash *tfm; |
| 3185 |
struct ath11k_peer *peer; |
| 3186 |
struct dp_rx_tid *rx_tid; |
| 3187 |
int i; |
| 3188 |
|
| 3189 |
tfm = crypto_alloc_shash("michael_mic", 0, 0); |
| 3190 |
if (IS_ERR(tfm)) { |
| 3191 |
ath11k_warn(ab, "failed to allocate michael_mic shash: %ld\n", |
| 3192 |
PTR_ERR(tfm)); |
| 3193 |
return PTR_ERR(tfm); |
| 3194 |
} |
| 3195 |
|
| 3196 |
spin_lock_bh(&ab->base_lock); |
| 3197 |
|
| 3198 |
peer = ath11k_peer_find(ab, vdev_id, peer_mac); |
| 3199 |
if (!peer) { |
| 3200 |
ath11k_warn(ab, "failed to find the peer to set up fragment info\n"); |
| 3201 |
spin_unlock_bh(&ab->base_lock); |
| 3202 |
crypto_free_shash(tfm); |
| 3203 |
return -ENOENT; |
| 3204 |
} |
| 3205 |
|
| 3206 |
for (i = 0; i <= IEEE80211_NUM_TIDS; i++) { |
| 3207 |
rx_tid = &peer->rx_tid[i]; |
| 3208 |
rx_tid->ab = ab; |
| 3209 |
timer_setup(&rx_tid->frag_timer, ath11k_dp_rx_frag_timer, 0); |
| 3210 |
skb_queue_head_init(&rx_tid->rx_frags); |
| 3211 |
} |
| 3212 |
|
| 3213 |
peer->tfm_mmic = tfm; |
| 3214 |
peer->dp_setup_done = true; |
| 3215 |
spin_unlock_bh(&ab->base_lock); |
| 3216 |
|
| 3217 |
return 0; |
| 3218 |
} |
| 3219 |
|
| 3220 |
static int ath11k_dp_rx_h_michael_mic(struct crypto_shash *tfm, u8 *key, |
| 3221 |
struct ieee80211_hdr *hdr, u8 *data, |
| 3222 |
size_t data_len, u8 *mic) |
| 3223 |
{ |
| 3224 |
SHASH_DESC_ON_STACK(desc, tfm); |
| 3225 |
u8 mic_hdr[16] = {}; |
| 3226 |
u8 tid = 0; |
| 3227 |
int ret; |
| 3228 |
|
| 3229 |
if (!tfm) |
| 3230 |
return -EINVAL; |
| 3231 |
|
| 3232 |
desc->tfm = tfm; |
| 3233 |
|
| 3234 |
ret = crypto_shash_setkey(tfm, key, 8); |
| 3235 |
if (ret) |
| 3236 |
goto out; |
| 3237 |
|
| 3238 |
ret = crypto_shash_init(desc); |
| 3239 |
if (ret) |
| 3240 |
goto out; |
| 3241 |
|
| 3242 |
/* TKIP MIC header */ |
| 3243 |
memcpy(mic_hdr, ieee80211_get_DA(hdr), ETH_ALEN); |
| 3244 |
memcpy(mic_hdr + ETH_ALEN, ieee80211_get_SA(hdr), ETH_ALEN); |
| 3245 |
if (ieee80211_is_data_qos(hdr->frame_control)) |
| 3246 |
tid = ieee80211_get_tid(hdr); |
| 3247 |
mic_hdr[12] = tid; |
| 3248 |
|
| 3249 |
ret = crypto_shash_update(desc, mic_hdr, 16); |
| 3250 |
if (ret) |
| 3251 |
goto out; |
| 3252 |
ret = crypto_shash_update(desc, data, data_len); |
| 3253 |
if (ret) |
| 3254 |
goto out; |
| 3255 |
ret = crypto_shash_final(desc, mic); |
| 3256 |
out: |
| 3257 |
shash_desc_zero(desc); |
| 3258 |
return ret; |
| 3259 |
} |
| 3260 |
|
| 3261 |
static int ath11k_dp_rx_h_verify_tkip_mic(struct ath11k *ar, struct ath11k_peer *peer, |
| 3262 |
struct sk_buff *msdu) |
| 3263 |
{ |
| 3264 |
struct hal_rx_desc *rx_desc = (struct hal_rx_desc *)msdu->data; |
| 3265 |
struct ieee80211_rx_status *rxs = IEEE80211_SKB_RXCB(msdu); |
| 3266 |
struct ieee80211_key_conf *key_conf; |
| 3267 |
struct ieee80211_hdr *hdr; |
| 3268 |
u8 mic[IEEE80211_CCMP_MIC_LEN]; |
| 3269 |
int head_len, tail_len, ret; |
| 3270 |
size_t data_len; |
| 3271 |
u32 hdr_len, hal_rx_desc_sz = ar->ab->hw_params.hal_desc_sz; |
| 3272 |
u8 *key, *data; |
| 3273 |
u8 key_idx; |
| 3274 |
|
| 3275 |
if (ath11k_dp_rx_h_mpdu_start_enctype(ar->ab, rx_desc) != |
| 3276 |
HAL_ENCRYPT_TYPE_TKIP_MIC) |
| 3277 |
return 0; |
| 3278 |
|
| 3279 |
hdr = (struct ieee80211_hdr *)(msdu->data + hal_rx_desc_sz); |
| 3280 |
hdr_len = ieee80211_hdrlen(hdr->frame_control); |
| 3281 |
head_len = hdr_len + hal_rx_desc_sz + IEEE80211_TKIP_IV_LEN; |
| 3282 |
tail_len = IEEE80211_CCMP_MIC_LEN + IEEE80211_TKIP_ICV_LEN + FCS_LEN; |
| 3283 |
|
| 3284 |
if (!is_multicast_ether_addr(hdr->addr1)) |
| 3285 |
key_idx = peer->ucast_keyidx; |
| 3286 |
else |
| 3287 |
key_idx = peer->mcast_keyidx; |
| 3288 |
|
| 3289 |
key_conf = peer->keys[key_idx]; |
| 3290 |
|
| 3291 |
data = msdu->data + head_len; |
| 3292 |
data_len = msdu->len - head_len - tail_len; |
| 3293 |
key = &key_conf->key[NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY]; |
| 3294 |
|
| 3295 |
ret = ath11k_dp_rx_h_michael_mic(peer->tfm_mmic, key, hdr, data, data_len, mic); |
| 3296 |
if (ret || memcmp(mic, data + data_len, IEEE80211_CCMP_MIC_LEN)) |
| 3297 |
goto mic_fail; |
| 3298 |
|
| 3299 |
return 0; |
| 3300 |
|
| 3301 |
mic_fail: |
| 3302 |
(ATH11K_SKB_RXCB(msdu))->is_first_msdu = true; |
| 3303 |
(ATH11K_SKB_RXCB(msdu))->is_last_msdu = true; |
| 3304 |
|
| 3305 |
rxs->flag |= RX_FLAG_MMIC_ERROR | RX_FLAG_MMIC_STRIPPED | |
| 3306 |
RX_FLAG_IV_STRIPPED | RX_FLAG_DECRYPTED; |
| 3307 |
skb_pull(msdu, hal_rx_desc_sz); |
| 3308 |
|
| 3309 |
ath11k_dp_rx_h_ppdu(ar, rx_desc, rxs); |
| 3310 |
ath11k_dp_rx_h_undecap(ar, msdu, rx_desc, |
| 3311 |
HAL_ENCRYPT_TYPE_TKIP_MIC, rxs, true); |
| 3312 |
ieee80211_rx(ar->hw, msdu); |
| 3313 |
return -EINVAL; |
| 3314 |
} |
| 3315 |
|
| 3316 |
static void ath11k_dp_rx_h_undecap_frag(struct ath11k *ar, struct sk_buff *msdu, |
| 3317 |
enum hal_encrypt_type enctype, u32 flags) |
| 3318 |
{ |
| 3319 |
struct ieee80211_hdr *hdr; |
| 3320 |
size_t hdr_len; |
| 3321 |
size_t crypto_len; |
| 3322 |
u32 hal_rx_desc_sz = ar->ab->hw_params.hal_desc_sz; |
| 3323 |
|
| 3324 |
if (!flags) |
| 3325 |
return; |
| 3326 |
|
| 3327 |
hdr = (struct ieee80211_hdr *)(msdu->data + hal_rx_desc_sz); |
| 3328 |
|
| 3329 |
if (flags & RX_FLAG_MIC_STRIPPED) |
| 3330 |
skb_trim(msdu, msdu->len - |
| 3331 |
ath11k_dp_rx_crypto_mic_len(ar, enctype)); |
| 3332 |
|
| 3333 |
if (flags & RX_FLAG_ICV_STRIPPED) |
| 3334 |
skb_trim(msdu, msdu->len - |
| 3335 |
ath11k_dp_rx_crypto_icv_len(ar, enctype)); |
| 3336 |
|
| 3337 |
if (flags & RX_FLAG_IV_STRIPPED) { |
| 3338 |
hdr_len = ieee80211_hdrlen(hdr->frame_control); |
| 3339 |
crypto_len = ath11k_dp_rx_crypto_param_len(ar, enctype); |
| 3340 |
|
| 3341 |
memmove((void *)msdu->data + hal_rx_desc_sz + crypto_len, |
| 3342 |
(void *)msdu->data + hal_rx_desc_sz, hdr_len); |
| 3343 |
skb_pull(msdu, crypto_len); |
| 3344 |
} |
| 3345 |
} |
| 3346 |
|
| 3347 |
static int ath11k_dp_rx_h_defrag(struct ath11k *ar, |
| 3348 |
struct ath11k_peer *peer, |
| 3349 |
struct dp_rx_tid *rx_tid, |
| 3350 |
struct sk_buff **defrag_skb) |
| 3351 |
{ |
| 3352 |
struct hal_rx_desc *rx_desc; |
| 3353 |
struct sk_buff *skb, *first_frag, *last_frag; |
| 3354 |
struct ieee80211_hdr *hdr; |
| 3355 |
struct rx_attention *rx_attention; |
| 3356 |
enum hal_encrypt_type enctype; |
| 3357 |
bool is_decrypted = false; |
| 3358 |
int msdu_len = 0; |
| 3359 |
int extra_space; |
| 3360 |
u32 flags, hal_rx_desc_sz = ar->ab->hw_params.hal_desc_sz; |
| 3361 |
|
| 3362 |
first_frag = skb_peek(&rx_tid->rx_frags); |
| 3363 |
last_frag = skb_peek_tail(&rx_tid->rx_frags); |
| 3364 |
|
| 3365 |
skb_queue_walk(&rx_tid->rx_frags, skb) { |
| 3366 |
flags = 0; |
| 3367 |
rx_desc = (struct hal_rx_desc *)skb->data; |
| 3368 |
hdr = (struct ieee80211_hdr *)(skb->data + hal_rx_desc_sz); |
| 3369 |
|
| 3370 |
enctype = ath11k_dp_rx_h_mpdu_start_enctype(ar->ab, rx_desc); |
| 3371 |
if (enctype != HAL_ENCRYPT_TYPE_OPEN) { |
| 3372 |
rx_attention = ath11k_dp_rx_get_attention(ar->ab, rx_desc); |
| 3373 |
is_decrypted = ath11k_dp_rx_h_attn_is_decrypted(rx_attention); |
| 3374 |
} |
| 3375 |
|
| 3376 |
if (is_decrypted) { |
| 3377 |
if (skb != first_frag) |
| 3378 |
flags |= RX_FLAG_IV_STRIPPED; |
| 3379 |
if (skb != last_frag) |
| 3380 |
flags |= RX_FLAG_ICV_STRIPPED | |
| 3381 |
RX_FLAG_MIC_STRIPPED; |
| 3382 |
} |
| 3383 |
|
| 3384 |
/* RX fragments are always raw packets */ |
| 3385 |
if (skb != last_frag) |
| 3386 |
skb_trim(skb, skb->len - FCS_LEN); |
| 3387 |
ath11k_dp_rx_h_undecap_frag(ar, skb, enctype, flags); |
| 3388 |
|
| 3389 |
if (skb != first_frag) |
| 3390 |
skb_pull(skb, hal_rx_desc_sz + |
| 3391 |
ieee80211_hdrlen(hdr->frame_control)); |
| 3392 |
msdu_len += skb->len; |
| 3393 |
} |
| 3394 |
|
| 3395 |
extra_space = msdu_len - (DP_RX_BUFFER_SIZE + skb_tailroom(first_frag)); |
| 3396 |
if (extra_space > 0 && |
| 3397 |
(pskb_expand_head(first_frag, 0, extra_space, GFP_ATOMIC) < 0)) |
| 3398 |
return -ENOMEM; |
| 3399 |
|
| 3400 |
__skb_unlink(first_frag, &rx_tid->rx_frags); |
| 3401 |
while ((skb = __skb_dequeue(&rx_tid->rx_frags))) { |
| 3402 |
skb_put_data(first_frag, skb->data, skb->len); |
| 3403 |
dev_kfree_skb_any(skb); |
| 3404 |
} |
| 3405 |
|
| 3406 |
hdr = (struct ieee80211_hdr *)(first_frag->data + hal_rx_desc_sz); |
| 3407 |
hdr->frame_control &= ~__cpu_to_le16(IEEE80211_FCTL_MOREFRAGS); |
| 3408 |
ATH11K_SKB_RXCB(first_frag)->is_frag = 1; |
| 3409 |
|
| 3410 |
if (ath11k_dp_rx_h_verify_tkip_mic(ar, peer, first_frag)) |
| 3411 |
first_frag = NULL; |
| 3412 |
|
| 3413 |
*defrag_skb = first_frag; |
| 3414 |
return 0; |
| 3415 |
} |
| 3416 |
|
| 3417 |
static int ath11k_dp_rx_h_defrag_reo_reinject(struct ath11k *ar, struct dp_rx_tid *rx_tid, |
| 3418 |
struct sk_buff *defrag_skb) |
| 3419 |
{ |
| 3420 |
struct ath11k_base *ab = ar->ab; |
| 3421 |
struct ath11k_pdev_dp *dp = &ar->dp; |
| 3422 |
struct dp_rxdma_ring *rx_refill_ring = &dp->rx_refill_buf_ring; |
| 3423 |
struct hal_rx_desc *rx_desc = (struct hal_rx_desc *)defrag_skb->data; |
| 3424 |
struct hal_reo_entrance_ring *reo_ent_ring; |
| 3425 |
struct hal_reo_dest_ring *reo_dest_ring; |
| 3426 |
struct dp_link_desc_bank *link_desc_banks; |
| 3427 |
struct hal_rx_msdu_link *msdu_link; |
| 3428 |
struct hal_rx_msdu_details *msdu0; |
| 3429 |
struct hal_srng *srng; |
| 3430 |
dma_addr_t paddr; |
| 3431 |
u32 desc_bank, msdu_info, mpdu_info; |
| 3432 |
u32 dst_idx, cookie, hal_rx_desc_sz; |
| 3433 |
int ret, buf_id; |
| 3434 |
|
| 3435 |
hal_rx_desc_sz = ab->hw_params.hal_desc_sz; |
| 3436 |
link_desc_banks = ab->dp.link_desc_banks; |
| 3437 |
reo_dest_ring = rx_tid->dst_ring_desc; |
| 3438 |
|
| 3439 |
ath11k_hal_rx_reo_ent_paddr_get(ab, reo_dest_ring, &paddr, &desc_bank); |
| 3440 |
msdu_link = (struct hal_rx_msdu_link *)(link_desc_banks[desc_bank].vaddr + |
| 3441 |
(paddr - link_desc_banks[desc_bank].paddr)); |
| 3442 |
msdu0 = &msdu_link->msdu_link[0]; |
| 3443 |
dst_idx = FIELD_GET(RX_MSDU_DESC_INFO0_REO_DEST_IND, msdu0->rx_msdu_info.info0); |
| 3444 |
memset(msdu0, 0, sizeof(*msdu0)); |
| 3445 |
|
| 3446 |
msdu_info = FIELD_PREP(RX_MSDU_DESC_INFO0_FIRST_MSDU_IN_MPDU, 1) | |
| 3447 |
FIELD_PREP(RX_MSDU_DESC_INFO0_LAST_MSDU_IN_MPDU, 1) | |
| 3448 |
FIELD_PREP(RX_MSDU_DESC_INFO0_MSDU_CONTINUATION, 0) | |
| 3449 |
FIELD_PREP(RX_MSDU_DESC_INFO0_MSDU_LENGTH, |
| 3450 |
defrag_skb->len - hal_rx_desc_sz) | |
| 3451 |
FIELD_PREP(RX_MSDU_DESC_INFO0_REO_DEST_IND, dst_idx) | |
| 3452 |
FIELD_PREP(RX_MSDU_DESC_INFO0_VALID_SA, 1) | |
| 3453 |
FIELD_PREP(RX_MSDU_DESC_INFO0_VALID_DA, 1); |
| 3454 |
msdu0->rx_msdu_info.info0 = msdu_info; |
| 3455 |
|
| 3456 |
/* change msdu len in hal rx desc */ |
| 3457 |
ath11k_dp_rxdesc_set_msdu_len(ab, rx_desc, defrag_skb->len - hal_rx_desc_sz); |
| 3458 |
|
| 3459 |
paddr = dma_map_single(ab->dev, defrag_skb->data, |
| 3460 |
defrag_skb->len + skb_tailroom(defrag_skb), |
| 3461 |
DMA_TO_DEVICE); |
| 3462 |
if (dma_mapping_error(ab->dev, paddr)) |
| 3463 |
return -ENOMEM; |
| 3464 |
|
| 3465 |
spin_lock_bh(&rx_refill_ring->idr_lock); |
| 3466 |
buf_id = idr_alloc(&rx_refill_ring->bufs_idr, defrag_skb, 0, |
| 3467 |
rx_refill_ring->bufs_max * 3, GFP_ATOMIC); |
| 3468 |
spin_unlock_bh(&rx_refill_ring->idr_lock); |
| 3469 |
if (buf_id < 0) { |
| 3470 |
ret = -ENOMEM; |
| 3471 |
goto err_unmap_dma; |
| 3472 |
} |
| 3473 |
|
| 3474 |
ATH11K_SKB_RXCB(defrag_skb)->paddr = paddr; |
| 3475 |
cookie = FIELD_PREP(DP_RXDMA_BUF_COOKIE_PDEV_ID, dp->mac_id) | |
| 3476 |
FIELD_PREP(DP_RXDMA_BUF_COOKIE_BUF_ID, buf_id); |
| 3477 |
|
| 3478 |
ath11k_hal_rx_buf_addr_info_set(msdu0, paddr, cookie, |
| 3479 |
ab->hw_params.hal_params->rx_buf_rbm); |
| 3480 |
|
| 3481 |
/* Fill mpdu details into reo entrance ring */ |
| 3482 |
srng = &ab->hal.srng_list[ab->dp.reo_reinject_ring.ring_id]; |
| 3483 |
|
| 3484 |
spin_lock_bh(&srng->lock); |
| 3485 |
ath11k_hal_srng_access_begin(ab, srng); |
| 3486 |
|
| 3487 |
reo_ent_ring = (struct hal_reo_entrance_ring *) |
| 3488 |
ath11k_hal_srng_src_get_next_entry(ab, srng); |
| 3489 |
if (!reo_ent_ring) { |
| 3490 |
ath11k_hal_srng_access_end(ab, srng); |
| 3491 |
spin_unlock_bh(&srng->lock); |
| 3492 |
ret = -ENOSPC; |
| 3493 |
goto err_free_idr; |
| 3494 |
} |
| 3495 |
memset(reo_ent_ring, 0, sizeof(*reo_ent_ring)); |
| 3496 |
|
| 3497 |
ath11k_hal_rx_reo_ent_paddr_get(ab, reo_dest_ring, &paddr, &desc_bank); |
| 3498 |
ath11k_hal_rx_buf_addr_info_set(reo_ent_ring, paddr, desc_bank, |
| 3499 |
HAL_RX_BUF_RBM_WBM_IDLE_DESC_LIST); |
| 3500 |
|
| 3501 |
mpdu_info = FIELD_PREP(RX_MPDU_DESC_INFO0_MSDU_COUNT, 1) | |
| 3502 |
FIELD_PREP(RX_MPDU_DESC_INFO0_SEQ_NUM, rx_tid->cur_sn) | |
| 3503 |
FIELD_PREP(RX_MPDU_DESC_INFO0_FRAG_FLAG, 0) | |
| 3504 |
FIELD_PREP(RX_MPDU_DESC_INFO0_VALID_SA, 1) | |
| 3505 |
FIELD_PREP(RX_MPDU_DESC_INFO0_VALID_DA, 1) | |
| 3506 |
FIELD_PREP(RX_MPDU_DESC_INFO0_RAW_MPDU, 1) | |
| 3507 |
FIELD_PREP(RX_MPDU_DESC_INFO0_VALID_PN, 1); |
| 3508 |
|
| 3509 |
reo_ent_ring->rx_mpdu_info.info0 = mpdu_info; |
| 3510 |
reo_ent_ring->rx_mpdu_info.meta_data = reo_dest_ring->rx_mpdu_info.meta_data; |
| 3511 |
reo_ent_ring->queue_addr_lo = reo_dest_ring->queue_addr_lo; |
| 3512 |
reo_ent_ring->info0 = FIELD_PREP(HAL_REO_ENTR_RING_INFO0_QUEUE_ADDR_HI, |
| 3513 |
FIELD_GET(HAL_REO_DEST_RING_INFO0_QUEUE_ADDR_HI, |
| 3514 |
reo_dest_ring->info0)) | |
| 3515 |
FIELD_PREP(HAL_REO_ENTR_RING_INFO0_DEST_IND, dst_idx); |
| 3516 |
ath11k_hal_srng_access_end(ab, srng); |
| 3517 |
spin_unlock_bh(&srng->lock); |
| 3518 |
|
| 3519 |
return 0; |
| 3520 |
|
| 3521 |
err_free_idr: |
| 3522 |
spin_lock_bh(&rx_refill_ring->idr_lock); |
| 3523 |
idr_remove(&rx_refill_ring->bufs_idr, buf_id); |
| 3524 |
spin_unlock_bh(&rx_refill_ring->idr_lock); |
| 3525 |
err_unmap_dma: |
| 3526 |
dma_unmap_single(ab->dev, paddr, defrag_skb->len + skb_tailroom(defrag_skb), |
| 3527 |
DMA_TO_DEVICE); |
| 3528 |
return ret; |
| 3529 |
} |
| 3530 |
|
| 3531 |
static int ath11k_dp_rx_h_cmp_frags(struct ath11k *ar, |
| 3532 |
struct sk_buff *a, struct sk_buff *b) |
| 3533 |
{ |
| 3534 |
int frag1, frag2; |
| 3535 |
|
| 3536 |
frag1 = ath11k_dp_rx_h_mpdu_start_frag_no(ar->ab, a); |
| 3537 |
frag2 = ath11k_dp_rx_h_mpdu_start_frag_no(ar->ab, b); |
| 3538 |
|
| 3539 |
return frag1 - frag2; |
| 3540 |
} |
| 3541 |
|
| 3542 |
static void ath11k_dp_rx_h_sort_frags(struct ath11k *ar, |
| 3543 |
struct sk_buff_head *frag_list, |
| 3544 |
struct sk_buff *cur_frag) |
| 3545 |
{ |
| 3546 |
struct sk_buff *skb; |
| 3547 |
int cmp; |
| 3548 |
|
| 3549 |
skb_queue_walk(frag_list, skb) { |
| 3550 |
cmp = ath11k_dp_rx_h_cmp_frags(ar, skb, cur_frag); |
| 3551 |
if (cmp < 0) |
| 3552 |
continue; |
| 3553 |
__skb_queue_before(frag_list, skb, cur_frag); |
| 3554 |
return; |
| 3555 |
} |
| 3556 |
__skb_queue_tail(frag_list, cur_frag); |
| 3557 |
} |
| 3558 |
|
| 3559 |
static u64 ath11k_dp_rx_h_get_pn(struct ath11k *ar, struct sk_buff *skb) |
| 3560 |
{ |
| 3561 |
struct ieee80211_hdr *hdr; |
| 3562 |
u64 pn = 0; |
| 3563 |
u8 *ehdr; |
| 3564 |
u32 hal_rx_desc_sz = ar->ab->hw_params.hal_desc_sz; |
| 3565 |
|
| 3566 |
hdr = (struct ieee80211_hdr *)(skb->data + hal_rx_desc_sz); |
| 3567 |
ehdr = skb->data + hal_rx_desc_sz + ieee80211_hdrlen(hdr->frame_control); |
| 3568 |
|
| 3569 |
pn = ehdr[0]; |
| 3570 |
pn |= (u64)ehdr[1] << 8; |
| 3571 |
pn |= (u64)ehdr[4] << 16; |
| 3572 |
pn |= (u64)ehdr[5] << 24; |
| 3573 |
pn |= (u64)ehdr[6] << 32; |
| 3574 |
pn |= (u64)ehdr[7] << 40; |
| 3575 |
|
| 3576 |
return pn; |
| 3577 |
} |
| 3578 |
|
| 3579 |
static bool |
| 3580 |
ath11k_dp_rx_h_defrag_validate_incr_pn(struct ath11k *ar, struct dp_rx_tid *rx_tid) |
| 3581 |
{ |
| 3582 |
enum hal_encrypt_type encrypt_type; |
| 3583 |
struct sk_buff *first_frag, *skb; |
| 3584 |
struct hal_rx_desc *desc; |
| 3585 |
u64 last_pn; |
| 3586 |
u64 cur_pn; |
| 3587 |
|
| 3588 |
first_frag = skb_peek(&rx_tid->rx_frags); |
| 3589 |
desc = (struct hal_rx_desc *)first_frag->data; |
| 3590 |
|
| 3591 |
encrypt_type = ath11k_dp_rx_h_mpdu_start_enctype(ar->ab, desc); |
| 3592 |
if (encrypt_type != HAL_ENCRYPT_TYPE_CCMP_128 && |
| 3593 |
encrypt_type != HAL_ENCRYPT_TYPE_CCMP_256 && |
| 3594 |
encrypt_type != HAL_ENCRYPT_TYPE_GCMP_128 && |
| 3595 |
encrypt_type != HAL_ENCRYPT_TYPE_AES_GCMP_256) |
| 3596 |
return true; |
| 3597 |
|
| 3598 |
last_pn = ath11k_dp_rx_h_get_pn(ar, first_frag); |
| 3599 |
skb_queue_walk(&rx_tid->rx_frags, skb) { |
| 3600 |
if (skb == first_frag) |
| 3601 |
continue; |
| 3602 |
|
| 3603 |
cur_pn = ath11k_dp_rx_h_get_pn(ar, skb); |
| 3604 |
if (cur_pn != last_pn + 1) |
| 3605 |
return false; |
| 3606 |
last_pn = cur_pn; |
| 3607 |
} |
| 3608 |
return true; |
| 3609 |
} |
| 3610 |
|
| 3611 |
static int ath11k_dp_rx_frag_h_mpdu(struct ath11k *ar, |
| 3612 |
struct sk_buff *msdu, |
| 3613 |
u32 *ring_desc) |
| 3614 |
{ |
| 3615 |
struct ath11k_base *ab = ar->ab; |
| 3616 |
struct hal_rx_desc *rx_desc; |
| 3617 |
struct ath11k_peer *peer; |
| 3618 |
struct dp_rx_tid *rx_tid; |
| 3619 |
struct sk_buff *defrag_skb = NULL; |
| 3620 |
u32 peer_id; |
| 3621 |
u16 seqno, frag_no; |
| 3622 |
u8 tid; |
| 3623 |
int ret = 0; |
| 3624 |
bool more_frags; |
| 3625 |
bool is_mcbc; |
| 3626 |
|
| 3627 |
rx_desc = (struct hal_rx_desc *)msdu->data; |
| 3628 |
peer_id = ath11k_dp_rx_h_mpdu_start_peer_id(ar->ab, rx_desc); |
| 3629 |
tid = ath11k_dp_rx_h_mpdu_start_tid(ar->ab, rx_desc); |
| 3630 |
seqno = ath11k_dp_rx_h_mpdu_start_seq_no(ar->ab, rx_desc); |
| 3631 |
frag_no = ath11k_dp_rx_h_mpdu_start_frag_no(ar->ab, msdu); |
| 3632 |
more_frags = ath11k_dp_rx_h_mpdu_start_more_frags(ar->ab, msdu); |
| 3633 |
is_mcbc = ath11k_dp_rx_h_attn_is_mcbc(ar->ab, rx_desc); |
| 3634 |
|
| 3635 |
/* Multicast/Broadcast fragments are not expected */ |
| 3636 |
if (is_mcbc) |
| 3637 |
return -EINVAL; |
| 3638 |
|
| 3639 |
if (!ath11k_dp_rx_h_mpdu_start_seq_ctrl_valid(ar->ab, rx_desc) || |
| 3640 |
!ath11k_dp_rx_h_mpdu_start_fc_valid(ar->ab, rx_desc) || |
| 3641 |
tid > IEEE80211_NUM_TIDS) |
| 3642 |
return -EINVAL; |
| 3643 |
|
| 3644 |
/* received unfragmented packet in reo |
| 3645 |
* exception ring, this shouldn't happen |
| 3646 |
* as these packets typically come from |
| 3647 |
* reo2sw srngs. |
| 3648 |
*/ |
| 3649 |
if (WARN_ON_ONCE(!frag_no && !more_frags)) |
| 3650 |
return -EINVAL; |
| 3651 |
|
| 3652 |
spin_lock_bh(&ab->base_lock); |
| 3653 |
peer = ath11k_peer_find_by_id(ab, peer_id); |
| 3654 |
if (!peer) { |
| 3655 |
ath11k_warn(ab, "failed to find the peer to de-fragment received fragment peer_id %d\n", |
| 3656 |
peer_id); |
| 3657 |
ret = -ENOENT; |
| 3658 |
goto out_unlock; |
| 3659 |
} |
| 3660 |
if (!peer->dp_setup_done) { |
| 3661 |
ath11k_warn(ab, "The peer %pM [%d] has uninitialized datapath\n", |
| 3662 |
peer->addr, peer_id); |
| 3663 |
ret = -ENOENT; |
| 3664 |
goto out_unlock; |
| 3665 |
} |
| 3666 |
|
| 3667 |
rx_tid = &peer->rx_tid[tid]; |
| 3668 |
|
| 3669 |
if ((!skb_queue_empty(&rx_tid->rx_frags) && seqno != rx_tid->cur_sn) || |
| 3670 |
skb_queue_empty(&rx_tid->rx_frags)) { |
| 3671 |
/* Flush stored fragments and start a new sequence */ |
| 3672 |
ath11k_dp_rx_frags_cleanup(rx_tid, true); |
| 3673 |
rx_tid->cur_sn = seqno; |
| 3674 |
} |
| 3675 |
|
| 3676 |
if (rx_tid->rx_frag_bitmap & BIT(frag_no)) { |
| 3677 |
/* Fragment already present */ |
| 3678 |
ret = -EINVAL; |
| 3679 |
goto out_unlock; |
| 3680 |
} |
| 3681 |
|
| 3682 |
if (!rx_tid->rx_frag_bitmap || (frag_no > __fls(rx_tid->rx_frag_bitmap))) |
| 3683 |
__skb_queue_tail(&rx_tid->rx_frags, msdu); |
| 3684 |
else |
| 3685 |
ath11k_dp_rx_h_sort_frags(ar, &rx_tid->rx_frags, msdu); |
| 3686 |
|
| 3687 |
rx_tid->rx_frag_bitmap |= BIT(frag_no); |
| 3688 |
if (!more_frags) |
| 3689 |
rx_tid->last_frag_no = frag_no; |
| 3690 |
|
| 3691 |
if (frag_no == 0) { |
| 3692 |
rx_tid->dst_ring_desc = kmemdup(ring_desc, |
| 3693 |
sizeof(*rx_tid->dst_ring_desc), |
| 3694 |
GFP_ATOMIC); |
| 3695 |
if (!rx_tid->dst_ring_desc) { |
| 3696 |
ret = -ENOMEM; |
| 3697 |
goto out_unlock; |
| 3698 |
} |
| 3699 |
} else { |
| 3700 |
ath11k_dp_rx_link_desc_return(ab, ring_desc, |
| 3701 |
HAL_WBM_REL_BM_ACT_PUT_IN_IDLE); |
| 3702 |
} |
| 3703 |
|
| 3704 |
if (!rx_tid->last_frag_no || |
| 3705 |
rx_tid->rx_frag_bitmap != GENMASK(rx_tid->last_frag_no, 0)) { |
| 3706 |
mod_timer(&rx_tid->frag_timer, jiffies + |
| 3707 |
ATH11K_DP_RX_FRAGMENT_TIMEOUT_MS); |
| 3708 |
goto out_unlock; |
| 3709 |
} |
| 3710 |
|
| 3711 |
spin_unlock_bh(&ab->base_lock); |
| 3712 |
timer_delete_sync(&rx_tid->frag_timer); |
| 3713 |
spin_lock_bh(&ab->base_lock); |
| 3714 |
|
| 3715 |
peer = ath11k_peer_find_by_id(ab, peer_id); |
| 3716 |
if (!peer) |
| 3717 |
goto err_frags_cleanup; |
| 3718 |
|
| 3719 |
if (!ath11k_dp_rx_h_defrag_validate_incr_pn(ar, rx_tid)) |
| 3720 |
goto err_frags_cleanup; |
| 3721 |
|
| 3722 |
if (ath11k_dp_rx_h_defrag(ar, peer, rx_tid, &defrag_skb)) |
| 3723 |
goto err_frags_cleanup; |
| 3724 |
|
| 3725 |
if (!defrag_skb) |
| 3726 |
goto err_frags_cleanup; |
| 3727 |
|
| 3728 |
if (ath11k_dp_rx_h_defrag_reo_reinject(ar, rx_tid, defrag_skb)) |
| 3729 |
goto err_frags_cleanup; |
| 3730 |
|
| 3731 |
ath11k_dp_rx_frags_cleanup(rx_tid, false); |
| 3732 |
goto out_unlock; |
| 3733 |
|
| 3734 |
err_frags_cleanup: |
| 3735 |
dev_kfree_skb_any(defrag_skb); |
| 3736 |
ath11k_dp_rx_frags_cleanup(rx_tid, true); |
| 3737 |
out_unlock: |
| 3738 |
spin_unlock_bh(&ab->base_lock); |
| 3739 |
return ret; |
| 3740 |
} |
| 3741 |
|
| 3742 |
static int |
| 3743 |
ath11k_dp_process_rx_err_buf(struct ath11k *ar, u32 *ring_desc, int buf_id, bool drop) |
| 3744 |
{ |
| 3745 |
struct ath11k_pdev_dp *dp = &ar->dp; |
| 3746 |
struct dp_rxdma_ring *rx_ring = &dp->rx_refill_buf_ring; |
| 3747 |
struct sk_buff *msdu; |
| 3748 |
struct ath11k_skb_rxcb *rxcb; |
| 3749 |
struct hal_rx_desc *rx_desc; |
| 3750 |
u8 *hdr_status; |
| 3751 |
u16 msdu_len; |
| 3752 |
u32 hal_rx_desc_sz = ar->ab->hw_params.hal_desc_sz; |
| 3753 |
|
| 3754 |
spin_lock_bh(&rx_ring->idr_lock); |
| 3755 |
msdu = idr_find(&rx_ring->bufs_idr, buf_id); |
| 3756 |
if (!msdu) { |
| 3757 |
ath11k_warn(ar->ab, "rx err buf with invalid buf_id %d\n", |
| 3758 |
buf_id); |
| 3759 |
spin_unlock_bh(&rx_ring->idr_lock); |
| 3760 |
return -EINVAL; |
| 3761 |
} |
| 3762 |
|
| 3763 |
idr_remove(&rx_ring->bufs_idr, buf_id); |
| 3764 |
spin_unlock_bh(&rx_ring->idr_lock); |
| 3765 |
|
| 3766 |
rxcb = ATH11K_SKB_RXCB(msdu); |
| 3767 |
dma_unmap_single(ar->ab->dev, rxcb->paddr, |
| 3768 |
msdu->len + skb_tailroom(msdu), |
| 3769 |
DMA_FROM_DEVICE); |
| 3770 |
|
| 3771 |
if (drop) { |
| 3772 |
dev_kfree_skb_any(msdu); |
| 3773 |
return 0; |
| 3774 |
} |
| 3775 |
|
| 3776 |
rcu_read_lock(); |
| 3777 |
if (!rcu_dereference(ar->ab->pdevs_active[ar->pdev_idx])) { |
| 3778 |
dev_kfree_skb_any(msdu); |
| 3779 |
goto exit; |
| 3780 |
} |
| 3781 |
|
| 3782 |
if (test_bit(ATH11K_CAC_RUNNING, &ar->dev_flags)) { |
| 3783 |
dev_kfree_skb_any(msdu); |
| 3784 |
goto exit; |
| 3785 |
} |
| 3786 |
|
| 3787 |
rx_desc = (struct hal_rx_desc *)msdu->data; |
| 3788 |
msdu_len = ath11k_dp_rx_h_msdu_start_msdu_len(ar->ab, rx_desc); |
| 3789 |
if ((msdu_len + hal_rx_desc_sz) > DP_RX_BUFFER_SIZE) { |
| 3790 |
hdr_status = ath11k_dp_rx_h_80211_hdr(ar->ab, rx_desc); |
| 3791 |
ath11k_warn(ar->ab, "invalid msdu leng %u", msdu_len); |
| 3792 |
ath11k_dbg_dump(ar->ab, ATH11K_DBG_DATA, NULL, "", hdr_status, |
| 3793 |
sizeof(struct ieee80211_hdr)); |
| 3794 |
ath11k_dbg_dump(ar->ab, ATH11K_DBG_DATA, NULL, "", rx_desc, |
| 3795 |
sizeof(struct hal_rx_desc)); |
| 3796 |
dev_kfree_skb_any(msdu); |
| 3797 |
goto exit; |
| 3798 |
} |
| 3799 |
|
| 3800 |
skb_put(msdu, hal_rx_desc_sz + msdu_len); |
| 3801 |
|
| 3802 |
if (ath11k_dp_rx_frag_h_mpdu(ar, msdu, ring_desc)) { |
| 3803 |
dev_kfree_skb_any(msdu); |
| 3804 |
ath11k_dp_rx_link_desc_return(ar->ab, ring_desc, |
| 3805 |
HAL_WBM_REL_BM_ACT_PUT_IN_IDLE); |
| 3806 |
} |
| 3807 |
exit: |
| 3808 |
rcu_read_unlock(); |
| 3809 |
return 0; |
| 3810 |
} |
| 3811 |
|
| 3812 |
int ath11k_dp_process_rx_err(struct ath11k_base *ab, struct napi_struct *napi, |
| 3813 |
int budget) |
| 3814 |
{ |
| 3815 |
u32 msdu_cookies[HAL_NUM_RX_MSDUS_PER_LINK_DESC]; |
| 3816 |
struct dp_link_desc_bank *link_desc_banks; |
| 3817 |
enum hal_rx_buf_return_buf_manager rbm; |
| 3818 |
int tot_n_bufs_reaped, quota, ret, i; |
| 3819 |
int n_bufs_reaped[MAX_RADIOS] = {}; |
| 3820 |
struct dp_rxdma_ring *rx_ring; |
| 3821 |
struct dp_srng *reo_except; |
| 3822 |
u32 desc_bank, num_msdus; |
| 3823 |
struct hal_srng *srng; |
| 3824 |
struct ath11k_dp *dp; |
| 3825 |
void *link_desc_va; |
| 3826 |
int buf_id, mac_id; |
| 3827 |
struct ath11k *ar; |
| 3828 |
dma_addr_t paddr; |
| 3829 |
u32 *desc; |
| 3830 |
bool is_frag; |
| 3831 |
u8 drop = 0; |
| 3832 |
|
| 3833 |
tot_n_bufs_reaped = 0; |
| 3834 |
quota = budget; |
| 3835 |
|
| 3836 |
dp = &ab->dp; |
| 3837 |
reo_except = &dp->reo_except_ring; |
| 3838 |
link_desc_banks = dp->link_desc_banks; |
| 3839 |
|
| 3840 |
srng = &ab->hal.srng_list[reo_except->ring_id]; |
| 3841 |
|
| 3842 |
spin_lock_bh(&srng->lock); |
| 3843 |
|
| 3844 |
ath11k_hal_srng_access_begin(ab, srng); |
| 3845 |
|
| 3846 |
while (budget && |
| 3847 |
(desc = ath11k_hal_srng_dst_get_next_entry(ab, srng))) { |
| 3848 |
struct hal_reo_dest_ring *reo_desc = (struct hal_reo_dest_ring *)desc; |
| 3849 |
|
| 3850 |
ab->soc_stats.err_ring_pkts++; |
| 3851 |
ret = ath11k_hal_desc_reo_parse_err(ab, desc, &paddr, |
| 3852 |
&desc_bank); |
| 3853 |
if (ret) { |
| 3854 |
ath11k_warn(ab, "failed to parse error reo desc %d\n", |
| 3855 |
ret); |
| 3856 |
continue; |
| 3857 |
} |
| 3858 |
link_desc_va = link_desc_banks[desc_bank].vaddr + |
| 3859 |
(paddr - link_desc_banks[desc_bank].paddr); |
| 3860 |
ath11k_hal_rx_msdu_link_info_get(link_desc_va, &num_msdus, msdu_cookies, |
| 3861 |
&rbm); |
| 3862 |
if (rbm != HAL_RX_BUF_RBM_WBM_IDLE_DESC_LIST && |
| 3863 |
rbm != HAL_RX_BUF_RBM_SW1_BM && |
| 3864 |
rbm != HAL_RX_BUF_RBM_SW3_BM) { |
| 3865 |
ab->soc_stats.invalid_rbm++; |
| 3866 |
ath11k_warn(ab, "invalid return buffer manager %d\n", rbm); |
| 3867 |
ath11k_dp_rx_link_desc_return(ab, desc, |
| 3868 |
HAL_WBM_REL_BM_ACT_REL_MSDU); |
| 3869 |
continue; |
| 3870 |
} |
| 3871 |
|
| 3872 |
is_frag = !!(reo_desc->rx_mpdu_info.info0 & RX_MPDU_DESC_INFO0_FRAG_FLAG); |
| 3873 |
|
| 3874 |
/* Process only rx fragments with one msdu per link desc below, and drop |
| 3875 |
* msdu's indicated due to error reasons. |
| 3876 |
*/ |
| 3877 |
if (!is_frag || num_msdus > 1) { |
| 3878 |
drop = 1; |
| 3879 |
/* Return the link desc back to wbm idle list */ |
| 3880 |
ath11k_dp_rx_link_desc_return(ab, desc, |
| 3881 |
HAL_WBM_REL_BM_ACT_PUT_IN_IDLE); |
| 3882 |
} |
| 3883 |
|
| 3884 |
for (i = 0; i < num_msdus; i++) { |
| 3885 |
buf_id = FIELD_GET(DP_RXDMA_BUF_COOKIE_BUF_ID, |
| 3886 |
msdu_cookies[i]); |
| 3887 |
|
| 3888 |
mac_id = FIELD_GET(DP_RXDMA_BUF_COOKIE_PDEV_ID, |
| 3889 |
msdu_cookies[i]); |
| 3890 |
|
| 3891 |
ar = ab->pdevs[mac_id].ar; |
| 3892 |
|
| 3893 |
if (!ath11k_dp_process_rx_err_buf(ar, desc, buf_id, drop)) { |
| 3894 |
n_bufs_reaped[mac_id]++; |
| 3895 |
tot_n_bufs_reaped++; |
| 3896 |
} |
| 3897 |
} |
| 3898 |
|
| 3899 |
if (tot_n_bufs_reaped >= quota) { |
| 3900 |
tot_n_bufs_reaped = quota; |
| 3901 |
goto exit; |
| 3902 |
} |
| 3903 |
|
| 3904 |
budget = quota - tot_n_bufs_reaped; |
| 3905 |
} |
| 3906 |
|
| 3907 |
exit: |
| 3908 |
ath11k_hal_srng_access_end(ab, srng); |
| 3909 |
|
| 3910 |
spin_unlock_bh(&srng->lock); |
| 3911 |
|
| 3912 |
for (i = 0; i < ab->num_radios; i++) { |
| 3913 |
if (!n_bufs_reaped[i]) |
| 3914 |
continue; |
| 3915 |
|
| 3916 |
ar = ab->pdevs[i].ar; |
| 3917 |
rx_ring = &ar->dp.rx_refill_buf_ring; |
| 3918 |
|
| 3919 |
ath11k_dp_rxbufs_replenish(ab, i, rx_ring, n_bufs_reaped[i], |
| 3920 |
ab->hw_params.hal_params->rx_buf_rbm); |
| 3921 |
} |
| 3922 |
|
| 3923 |
return tot_n_bufs_reaped; |
| 3924 |
} |
| 3925 |
|
| 3926 |
static void ath11k_dp_rx_null_q_desc_sg_drop(struct ath11k *ar, |
| 3927 |
int msdu_len, |
| 3928 |
struct sk_buff_head *msdu_list) |
| 3929 |
{ |
| 3930 |
struct sk_buff *skb, *tmp; |
| 3931 |
struct ath11k_skb_rxcb *rxcb; |
| 3932 |
int n_buffs; |
| 3933 |
|
| 3934 |
n_buffs = DIV_ROUND_UP(msdu_len, |
| 3935 |
(DP_RX_BUFFER_SIZE - ar->ab->hw_params.hal_desc_sz)); |
| 3936 |
|
| 3937 |
skb_queue_walk_safe(msdu_list, skb, tmp) { |
| 3938 |
rxcb = ATH11K_SKB_RXCB(skb); |
| 3939 |
if (rxcb->err_rel_src == HAL_WBM_REL_SRC_MODULE_REO && |
| 3940 |
rxcb->err_code == HAL_REO_DEST_RING_ERROR_CODE_DESC_ADDR_ZERO) { |
| 3941 |
if (!n_buffs) |
| 3942 |
break; |
| 3943 |
__skb_unlink(skb, msdu_list); |
| 3944 |
dev_kfree_skb_any(skb); |
| 3945 |
n_buffs--; |
| 3946 |
} |
| 3947 |
} |
| 3948 |
} |
| 3949 |
|
| 3950 |
static int ath11k_dp_rx_h_null_q_desc(struct ath11k *ar, struct sk_buff *msdu, |
| 3951 |
struct ieee80211_rx_status *status, |
| 3952 |
struct sk_buff_head *msdu_list) |
| 3953 |
{ |
| 3954 |
u16 msdu_len; |
| 3955 |
struct hal_rx_desc *desc = (struct hal_rx_desc *)msdu->data; |
| 3956 |
struct rx_attention *rx_attention; |
| 3957 |
u8 l3pad_bytes; |
| 3958 |
struct ath11k_skb_rxcb *rxcb = ATH11K_SKB_RXCB(msdu); |
| 3959 |
u32 hal_rx_desc_sz = ar->ab->hw_params.hal_desc_sz; |
| 3960 |
|
| 3961 |
msdu_len = ath11k_dp_rx_h_msdu_start_msdu_len(ar->ab, desc); |
| 3962 |
|
| 3963 |
if (!rxcb->is_frag && ((msdu_len + hal_rx_desc_sz) > DP_RX_BUFFER_SIZE)) { |
| 3964 |
/* First buffer will be freed by the caller, so deduct it's length */ |
| 3965 |
msdu_len = msdu_len - (DP_RX_BUFFER_SIZE - hal_rx_desc_sz); |
| 3966 |
ath11k_dp_rx_null_q_desc_sg_drop(ar, msdu_len, msdu_list); |
| 3967 |
return -EINVAL; |
| 3968 |
} |
| 3969 |
|
| 3970 |
rx_attention = ath11k_dp_rx_get_attention(ar->ab, desc); |
| 3971 |
if (!ath11k_dp_rx_h_attn_msdu_done(rx_attention)) { |
| 3972 |
ath11k_warn(ar->ab, |
| 3973 |
"msdu_done bit not set in null_q_des processing\n"); |
| 3974 |
__skb_queue_purge(msdu_list); |
| 3975 |
return -EIO; |
| 3976 |
} |
| 3977 |
|
| 3978 |
/* Handle NULL queue descriptor violations arising out a missing |
| 3979 |
* REO queue for a given peer or a given TID. This typically |
| 3980 |
* may happen if a packet is received on a QOS enabled TID before the |
| 3981 |
* ADDBA negotiation for that TID, when the TID queue is setup. Or |
| 3982 |
* it may also happen for MC/BC frames if they are not routed to the |
| 3983 |
* non-QOS TID queue, in the absence of any other default TID queue. |
| 3984 |
* This error can show up both in a REO destination or WBM release ring. |
| 3985 |
*/ |
| 3986 |
|
| 3987 |
rxcb->is_first_msdu = ath11k_dp_rx_h_msdu_end_first_msdu(ar->ab, desc); |
| 3988 |
rxcb->is_last_msdu = ath11k_dp_rx_h_msdu_end_last_msdu(ar->ab, desc); |
| 3989 |
|
| 3990 |
if (rxcb->is_frag) { |
| 3991 |
skb_pull(msdu, hal_rx_desc_sz); |
| 3992 |
} else { |
| 3993 |
l3pad_bytes = ath11k_dp_rx_h_msdu_end_l3pad(ar->ab, desc); |
| 3994 |
|
| 3995 |
if ((hal_rx_desc_sz + l3pad_bytes + msdu_len) > DP_RX_BUFFER_SIZE) |
| 3996 |
return -EINVAL; |
| 3997 |
|
| 3998 |
skb_put(msdu, hal_rx_desc_sz + l3pad_bytes + msdu_len); |
| 3999 |
skb_pull(msdu, hal_rx_desc_sz + l3pad_bytes); |
| 4000 |
} |
| 4001 |
ath11k_dp_rx_h_ppdu(ar, desc, status); |
| 4002 |
|
| 4003 |
ath11k_dp_rx_h_mpdu(ar, msdu, desc, status); |
| 4004 |
|
| 4005 |
rxcb->tid = ath11k_dp_rx_h_mpdu_start_tid(ar->ab, desc); |
| 4006 |
|
| 4007 |
/* Please note that caller will having the access to msdu and completing |
| 4008 |
* rx with mac80211. Need not worry about cleaning up amsdu_list. |
| 4009 |
*/ |
| 4010 |
|
| 4011 |
return 0; |
| 4012 |
} |
| 4013 |
|
| 4014 |
static bool ath11k_dp_rx_h_reo_err(struct ath11k *ar, struct sk_buff *msdu, |
| 4015 |
struct ieee80211_rx_status *status, |
| 4016 |
struct sk_buff_head *msdu_list) |
| 4017 |
{ |
| 4018 |
struct ath11k_skb_rxcb *rxcb = ATH11K_SKB_RXCB(msdu); |
| 4019 |
bool drop = false; |
| 4020 |
|
| 4021 |
ar->ab->soc_stats.reo_error[rxcb->err_code]++; |
| 4022 |
|
| 4023 |
switch (rxcb->err_code) { |
| 4024 |
case HAL_REO_DEST_RING_ERROR_CODE_DESC_ADDR_ZERO: |
| 4025 |
if (ath11k_dp_rx_h_null_q_desc(ar, msdu, status, msdu_list)) |
| 4026 |
drop = true; |
| 4027 |
break; |
| 4028 |
case HAL_REO_DEST_RING_ERROR_CODE_PN_CHECK_FAILED: |
| 4029 |
/* TODO: Do not drop PN failed packets in the driver; |
| 4030 |
* instead, it is good to drop such packets in mac80211 |
| 4031 |
* after incrementing the replay counters. |
| 4032 |
*/ |
| 4033 |
fallthrough; |
| 4034 |
default: |
| 4035 |
/* TODO: Review other errors and process them to mac80211 |
| 4036 |
* as appropriate. |
| 4037 |
*/ |
| 4038 |
drop = true; |
| 4039 |
break; |
| 4040 |
} |
| 4041 |
|
| 4042 |
return drop; |
| 4043 |
} |
| 4044 |
|
| 4045 |
static void ath11k_dp_rx_h_tkip_mic_err(struct ath11k *ar, struct sk_buff *msdu, |
| 4046 |
struct ieee80211_rx_status *status) |
| 4047 |
{ |
| 4048 |
u16 msdu_len; |
| 4049 |
struct hal_rx_desc *desc = (struct hal_rx_desc *)msdu->data; |
| 4050 |
u8 l3pad_bytes; |
| 4051 |
struct ath11k_skb_rxcb *rxcb = ATH11K_SKB_RXCB(msdu); |
| 4052 |
u32 hal_rx_desc_sz = ar->ab->hw_params.hal_desc_sz; |
| 4053 |
|
| 4054 |
rxcb->is_first_msdu = ath11k_dp_rx_h_msdu_end_first_msdu(ar->ab, desc); |
| 4055 |
rxcb->is_last_msdu = ath11k_dp_rx_h_msdu_end_last_msdu(ar->ab, desc); |
| 4056 |
|
| 4057 |
l3pad_bytes = ath11k_dp_rx_h_msdu_end_l3pad(ar->ab, desc); |
| 4058 |
msdu_len = ath11k_dp_rx_h_msdu_start_msdu_len(ar->ab, desc); |
| 4059 |
skb_put(msdu, hal_rx_desc_sz + l3pad_bytes + msdu_len); |
| 4060 |
skb_pull(msdu, hal_rx_desc_sz + l3pad_bytes); |
| 4061 |
|
| 4062 |
ath11k_dp_rx_h_ppdu(ar, desc, status); |
| 4063 |
|
| 4064 |
status->flag |= (RX_FLAG_MMIC_STRIPPED | RX_FLAG_MMIC_ERROR | |
| 4065 |
RX_FLAG_DECRYPTED); |
| 4066 |
|
| 4067 |
ath11k_dp_rx_h_undecap(ar, msdu, desc, |
| 4068 |
HAL_ENCRYPT_TYPE_TKIP_MIC, status, false); |
| 4069 |
} |
| 4070 |
|
| 4071 |
static bool ath11k_dp_rx_h_rxdma_err(struct ath11k *ar, struct sk_buff *msdu, |
| 4072 |
struct ieee80211_rx_status *status) |
| 4073 |
{ |
| 4074 |
struct ath11k_skb_rxcb *rxcb = ATH11K_SKB_RXCB(msdu); |
| 4075 |
bool drop = false; |
| 4076 |
|
| 4077 |
ar->ab->soc_stats.rxdma_error[rxcb->err_code]++; |
| 4078 |
|
| 4079 |
switch (rxcb->err_code) { |
| 4080 |
case HAL_REO_ENTR_RING_RXDMA_ECODE_TKIP_MIC_ERR: |
| 4081 |
ath11k_dp_rx_h_tkip_mic_err(ar, msdu, status); |
| 4082 |
break; |
| 4083 |
default: |
| 4084 |
/* TODO: Review other rxdma error code to check if anything is |
| 4085 |
* worth reporting to mac80211 |
| 4086 |
*/ |
| 4087 |
drop = true; |
| 4088 |
break; |
| 4089 |
} |
| 4090 |
|
| 4091 |
return drop; |
| 4092 |
} |
| 4093 |
|
| 4094 |
static void ath11k_dp_rx_wbm_err(struct ath11k *ar, |
| 4095 |
struct napi_struct *napi, |
| 4096 |
struct sk_buff *msdu, |
| 4097 |
struct sk_buff_head *msdu_list) |
| 4098 |
{ |
| 4099 |
struct ath11k_skb_rxcb *rxcb = ATH11K_SKB_RXCB(msdu); |
| 4100 |
struct ieee80211_rx_status rxs = {}; |
| 4101 |
bool drop = true; |
| 4102 |
|
| 4103 |
switch (rxcb->err_rel_src) { |
| 4104 |
case HAL_WBM_REL_SRC_MODULE_REO: |
| 4105 |
drop = ath11k_dp_rx_h_reo_err(ar, msdu, &rxs, msdu_list); |
| 4106 |
break; |
| 4107 |
case HAL_WBM_REL_SRC_MODULE_RXDMA: |
| 4108 |
drop = ath11k_dp_rx_h_rxdma_err(ar, msdu, &rxs); |
| 4109 |
break; |
| 4110 |
default: |
| 4111 |
/* msdu will get freed */ |
| 4112 |
break; |
| 4113 |
} |
| 4114 |
|
| 4115 |
if (drop) { |
| 4116 |
dev_kfree_skb_any(msdu); |
| 4117 |
return; |
| 4118 |
} |
| 4119 |
|
| 4120 |
ath11k_dp_rx_deliver_msdu(ar, napi, msdu, &rxs); |
| 4121 |
} |
| 4122 |
|
| 4123 |
int ath11k_dp_rx_process_wbm_err(struct ath11k_base *ab, |
| 4124 |
struct napi_struct *napi, int budget) |
| 4125 |
{ |
| 4126 |
struct ath11k *ar; |
| 4127 |
struct ath11k_dp *dp = &ab->dp; |
| 4128 |
struct dp_rxdma_ring *rx_ring; |
| 4129 |
struct hal_rx_wbm_rel_info err_info; |
| 4130 |
struct hal_srng *srng; |
| 4131 |
struct sk_buff *msdu; |
| 4132 |
struct sk_buff_head msdu_list[MAX_RADIOS]; |
| 4133 |
struct ath11k_skb_rxcb *rxcb; |
| 4134 |
u32 *rx_desc; |
| 4135 |
int buf_id, mac_id; |
| 4136 |
int num_buffs_reaped[MAX_RADIOS] = {}; |
| 4137 |
int total_num_buffs_reaped = 0; |
| 4138 |
int ret, i; |
| 4139 |
|
| 4140 |
for (i = 0; i < ab->num_radios; i++) |
| 4141 |
__skb_queue_head_init(&msdu_list[i]); |
| 4142 |
|
| 4143 |
srng = &ab->hal.srng_list[dp->rx_rel_ring.ring_id]; |
| 4144 |
|
| 4145 |
spin_lock_bh(&srng->lock); |
| 4146 |
|
| 4147 |
ath11k_hal_srng_access_begin(ab, srng); |
| 4148 |
|
| 4149 |
while (budget) { |
| 4150 |
rx_desc = ath11k_hal_srng_dst_get_next_entry(ab, srng); |
| 4151 |
if (!rx_desc) |
| 4152 |
break; |
| 4153 |
|
| 4154 |
ret = ath11k_hal_wbm_desc_parse_err(ab, rx_desc, &err_info); |
| 4155 |
if (ret) { |
| 4156 |
ath11k_warn(ab, |
| 4157 |
"failed to parse rx error in wbm_rel ring desc %d\n", |
| 4158 |
ret); |
| 4159 |
continue; |
| 4160 |
} |
| 4161 |
|
| 4162 |
buf_id = FIELD_GET(DP_RXDMA_BUF_COOKIE_BUF_ID, err_info.cookie); |
| 4163 |
mac_id = FIELD_GET(DP_RXDMA_BUF_COOKIE_PDEV_ID, err_info.cookie); |
| 4164 |
|
| 4165 |
ar = ab->pdevs[mac_id].ar; |
| 4166 |
rx_ring = &ar->dp.rx_refill_buf_ring; |
| 4167 |
|
| 4168 |
spin_lock_bh(&rx_ring->idr_lock); |
| 4169 |
msdu = idr_find(&rx_ring->bufs_idr, buf_id); |
| 4170 |
if (!msdu) { |
| 4171 |
ath11k_warn(ab, "frame rx with invalid buf_id %d pdev %d\n", |
| 4172 |
buf_id, mac_id); |
| 4173 |
spin_unlock_bh(&rx_ring->idr_lock); |
| 4174 |
continue; |
| 4175 |
} |
| 4176 |
|
| 4177 |
idr_remove(&rx_ring->bufs_idr, buf_id); |
| 4178 |
spin_unlock_bh(&rx_ring->idr_lock); |
| 4179 |
|
| 4180 |
rxcb = ATH11K_SKB_RXCB(msdu); |
| 4181 |
dma_unmap_single(ab->dev, rxcb->paddr, |
| 4182 |
msdu->len + skb_tailroom(msdu), |
| 4183 |
DMA_FROM_DEVICE); |
| 4184 |
|
| 4185 |
num_buffs_reaped[mac_id]++; |
| 4186 |
total_num_buffs_reaped++; |
| 4187 |
budget--; |
| 4188 |
|
| 4189 |
if (err_info.push_reason != |
| 4190 |
HAL_REO_DEST_RING_PUSH_REASON_ERR_DETECTED) { |
| 4191 |
dev_kfree_skb_any(msdu); |
| 4192 |
continue; |
| 4193 |
} |
| 4194 |
|
| 4195 |
rxcb->err_rel_src = err_info.err_rel_src; |
| 4196 |
rxcb->err_code = err_info.err_code; |
| 4197 |
rxcb->rx_desc = (struct hal_rx_desc *)msdu->data; |
| 4198 |
__skb_queue_tail(&msdu_list[mac_id], msdu); |
| 4199 |
} |
| 4200 |
|
| 4201 |
ath11k_hal_srng_access_end(ab, srng); |
| 4202 |
|
| 4203 |
spin_unlock_bh(&srng->lock); |
| 4204 |
|
| 4205 |
if (!total_num_buffs_reaped) |
| 4206 |
goto done; |
| 4207 |
|
| 4208 |
for (i = 0; i < ab->num_radios; i++) { |
| 4209 |
if (!num_buffs_reaped[i]) |
| 4210 |
continue; |
| 4211 |
|
| 4212 |
ar = ab->pdevs[i].ar; |
| 4213 |
rx_ring = &ar->dp.rx_refill_buf_ring; |
| 4214 |
|
| 4215 |
ath11k_dp_rxbufs_replenish(ab, i, rx_ring, num_buffs_reaped[i], |
| 4216 |
ab->hw_params.hal_params->rx_buf_rbm); |
| 4217 |
} |
| 4218 |
|
| 4219 |
rcu_read_lock(); |
| 4220 |
for (i = 0; i < ab->num_radios; i++) { |
| 4221 |
if (!rcu_dereference(ab->pdevs_active[i])) { |
| 4222 |
__skb_queue_purge(&msdu_list[i]); |
| 4223 |
continue; |
| 4224 |
} |
| 4225 |
|
| 4226 |
ar = ab->pdevs[i].ar; |
| 4227 |
|
| 4228 |
if (test_bit(ATH11K_CAC_RUNNING, &ar->dev_flags)) { |
| 4229 |
__skb_queue_purge(&msdu_list[i]); |
| 4230 |
continue; |
| 4231 |
} |
| 4232 |
|
| 4233 |
while ((msdu = __skb_dequeue(&msdu_list[i])) != NULL) |
| 4234 |
ath11k_dp_rx_wbm_err(ar, napi, msdu, &msdu_list[i]); |
| 4235 |
} |
| 4236 |
rcu_read_unlock(); |
| 4237 |
done: |
| 4238 |
return total_num_buffs_reaped; |
| 4239 |
} |
| 4240 |
|
| 4241 |
int ath11k_dp_process_rxdma_err(struct ath11k_base *ab, int mac_id, int budget) |
| 4242 |
{ |
| 4243 |
struct ath11k *ar; |
| 4244 |
struct dp_srng *err_ring; |
| 4245 |
struct dp_rxdma_ring *rx_ring; |
| 4246 |
struct dp_link_desc_bank *link_desc_banks = ab->dp.link_desc_banks; |
| 4247 |
struct hal_srng *srng; |
| 4248 |
u32 msdu_cookies[HAL_NUM_RX_MSDUS_PER_LINK_DESC]; |
| 4249 |
enum hal_rx_buf_return_buf_manager rbm; |
| 4250 |
enum hal_reo_entr_rxdma_ecode rxdma_err_code; |
| 4251 |
struct ath11k_skb_rxcb *rxcb; |
| 4252 |
struct sk_buff *skb; |
| 4253 |
struct hal_reo_entrance_ring *entr_ring; |
| 4254 |
void *desc; |
| 4255 |
int num_buf_freed = 0; |
| 4256 |
int quota = budget; |
| 4257 |
dma_addr_t paddr; |
| 4258 |
u32 desc_bank; |
| 4259 |
void *link_desc_va; |
| 4260 |
int num_msdus; |
| 4261 |
int i; |
| 4262 |
int buf_id; |
| 4263 |
|
| 4264 |
ar = ab->pdevs[ath11k_hw_mac_id_to_pdev_id(&ab->hw_params, mac_id)].ar; |
| 4265 |
err_ring = &ar->dp.rxdma_err_dst_ring[ath11k_hw_mac_id_to_srng_id(&ab->hw_params, |
| 4266 |
mac_id)]; |
| 4267 |
rx_ring = &ar->dp.rx_refill_buf_ring; |
| 4268 |
|
| 4269 |
srng = &ab->hal.srng_list[err_ring->ring_id]; |
| 4270 |
|
| 4271 |
spin_lock_bh(&srng->lock); |
| 4272 |
|
| 4273 |
ath11k_hal_srng_access_begin(ab, srng); |
| 4274 |
|
| 4275 |
while (quota-- && |
| 4276 |
(desc = ath11k_hal_srng_dst_get_next_entry(ab, srng))) { |
| 4277 |
ath11k_hal_rx_reo_ent_paddr_get(ab, desc, &paddr, &desc_bank); |
| 4278 |
|
| 4279 |
entr_ring = (struct hal_reo_entrance_ring *)desc; |
| 4280 |
rxdma_err_code = |
| 4281 |
FIELD_GET(HAL_REO_ENTR_RING_INFO1_RXDMA_ERROR_CODE, |
| 4282 |
entr_ring->info1); |
| 4283 |
ab->soc_stats.rxdma_error[rxdma_err_code]++; |
| 4284 |
|
| 4285 |
link_desc_va = link_desc_banks[desc_bank].vaddr + |
| 4286 |
(paddr - link_desc_banks[desc_bank].paddr); |
| 4287 |
ath11k_hal_rx_msdu_link_info_get(link_desc_va, &num_msdus, |
| 4288 |
msdu_cookies, &rbm); |
| 4289 |
|
| 4290 |
for (i = 0; i < num_msdus; i++) { |
| 4291 |
buf_id = FIELD_GET(DP_RXDMA_BUF_COOKIE_BUF_ID, |
| 4292 |
msdu_cookies[i]); |
| 4293 |
|
| 4294 |
spin_lock_bh(&rx_ring->idr_lock); |
| 4295 |
skb = idr_find(&rx_ring->bufs_idr, buf_id); |
| 4296 |
if (!skb) { |
| 4297 |
ath11k_warn(ab, "rxdma error with invalid buf_id %d\n", |
| 4298 |
buf_id); |
| 4299 |
spin_unlock_bh(&rx_ring->idr_lock); |
| 4300 |
continue; |
| 4301 |
} |
| 4302 |
|
| 4303 |
idr_remove(&rx_ring->bufs_idr, buf_id); |
| 4304 |
spin_unlock_bh(&rx_ring->idr_lock); |
| 4305 |
|
| 4306 |
rxcb = ATH11K_SKB_RXCB(skb); |
| 4307 |
dma_unmap_single(ab->dev, rxcb->paddr, |
| 4308 |
skb->len + skb_tailroom(skb), |
| 4309 |
DMA_FROM_DEVICE); |
| 4310 |
dev_kfree_skb_any(skb); |
| 4311 |
|
| 4312 |
num_buf_freed++; |
| 4313 |
} |
| 4314 |
|
| 4315 |
ath11k_dp_rx_link_desc_return(ab, desc, |
| 4316 |
HAL_WBM_REL_BM_ACT_PUT_IN_IDLE); |
| 4317 |
} |
| 4318 |
|
| 4319 |
ath11k_hal_srng_access_end(ab, srng); |
| 4320 |
|
| 4321 |
spin_unlock_bh(&srng->lock); |
| 4322 |
|
| 4323 |
if (num_buf_freed) |
| 4324 |
ath11k_dp_rxbufs_replenish(ab, mac_id, rx_ring, num_buf_freed, |
| 4325 |
ab->hw_params.hal_params->rx_buf_rbm); |
| 4326 |
|
| 4327 |
return budget - quota; |
| 4328 |
} |
| 4329 |
|
| 4330 |
void ath11k_dp_process_reo_status(struct ath11k_base *ab) |
| 4331 |
{ |
| 4332 |
struct ath11k_dp *dp = &ab->dp; |
| 4333 |
struct hal_srng *srng; |
| 4334 |
struct dp_reo_cmd *cmd, *tmp; |
| 4335 |
bool found = false; |
| 4336 |
u32 *reo_desc; |
| 4337 |
u16 tag; |
| 4338 |
struct hal_reo_status reo_status; |
| 4339 |
|
| 4340 |
srng = &ab->hal.srng_list[dp->reo_status_ring.ring_id]; |
| 4341 |
|
| 4342 |
memset(&reo_status, 0, sizeof(reo_status)); |
| 4343 |
|
| 4344 |
spin_lock_bh(&srng->lock); |
| 4345 |
|
| 4346 |
ath11k_hal_srng_access_begin(ab, srng); |
| 4347 |
|
| 4348 |
while ((reo_desc = ath11k_hal_srng_dst_get_next_entry(ab, srng))) { |
| 4349 |
tag = FIELD_GET(HAL_SRNG_TLV_HDR_TAG, *reo_desc); |
| 4350 |
|
| 4351 |
switch (tag) { |
| 4352 |
case HAL_REO_GET_QUEUE_STATS_STATUS: |
| 4353 |
ath11k_hal_reo_status_queue_stats(ab, reo_desc, |
| 4354 |
&reo_status); |
| 4355 |
break; |
| 4356 |
case HAL_REO_FLUSH_QUEUE_STATUS: |
| 4357 |
ath11k_hal_reo_flush_queue_status(ab, reo_desc, |
| 4358 |
&reo_status); |
| 4359 |
break; |
| 4360 |
case HAL_REO_FLUSH_CACHE_STATUS: |
| 4361 |
ath11k_hal_reo_flush_cache_status(ab, reo_desc, |
| 4362 |
&reo_status); |
| 4363 |
break; |
| 4364 |
case HAL_REO_UNBLOCK_CACHE_STATUS: |
| 4365 |
ath11k_hal_reo_unblk_cache_status(ab, reo_desc, |
| 4366 |
&reo_status); |
| 4367 |
break; |
| 4368 |
case HAL_REO_FLUSH_TIMEOUT_LIST_STATUS: |
| 4369 |
ath11k_hal_reo_flush_timeout_list_status(ab, reo_desc, |
| 4370 |
&reo_status); |
| 4371 |
break; |
| 4372 |
case HAL_REO_DESCRIPTOR_THRESHOLD_REACHED_STATUS: |
| 4373 |
ath11k_hal_reo_desc_thresh_reached_status(ab, reo_desc, |
| 4374 |
&reo_status); |
| 4375 |
break; |
| 4376 |
case HAL_REO_UPDATE_RX_REO_QUEUE_STATUS: |
| 4377 |
ath11k_hal_reo_update_rx_reo_queue_status(ab, reo_desc, |
| 4378 |
&reo_status); |
| 4379 |
break; |
| 4380 |
default: |
| 4381 |
ath11k_warn(ab, "Unknown reo status type %d\n", tag); |
| 4382 |
continue; |
| 4383 |
} |
| 4384 |
|
| 4385 |
spin_lock_bh(&dp->reo_cmd_lock); |
| 4386 |
list_for_each_entry_safe(cmd, tmp, &dp->reo_cmd_list, list) { |
| 4387 |
if (reo_status.uniform_hdr.cmd_num == cmd->cmd_num) { |
| 4388 |
found = true; |
| 4389 |
list_del(&cmd->list); |
| 4390 |
break; |
| 4391 |
} |
| 4392 |
} |
| 4393 |
spin_unlock_bh(&dp->reo_cmd_lock); |
| 4394 |
|
| 4395 |
if (found) { |
| 4396 |
cmd->handler(dp, (void *)&cmd->data, |
| 4397 |
reo_status.uniform_hdr.cmd_status); |
| 4398 |
kfree(cmd); |
| 4399 |
} |
| 4400 |
|
| 4401 |
found = false; |
| 4402 |
} |
| 4403 |
|
| 4404 |
ath11k_hal_srng_access_end(ab, srng); |
| 4405 |
|
| 4406 |
spin_unlock_bh(&srng->lock); |
| 4407 |
} |
| 4408 |
|
| 4409 |
void ath11k_dp_rx_pdev_free(struct ath11k_base *ab, int mac_id) |
| 4410 |
{ |
| 4411 |
struct ath11k *ar = ab->pdevs[mac_id].ar; |
| 4412 |
|
| 4413 |
ath11k_dp_rx_pdev_srng_free(ar); |
| 4414 |
ath11k_dp_rxdma_pdev_buf_free(ar); |
| 4415 |
} |
| 4416 |
|
| 4417 |
int ath11k_dp_rx_pdev_alloc(struct ath11k_base *ab, int mac_id) |
| 4418 |
{ |
| 4419 |
struct ath11k *ar = ab->pdevs[mac_id].ar; |
| 4420 |
struct ath11k_pdev_dp *dp = &ar->dp; |
| 4421 |
u32 ring_id; |
| 4422 |
int i; |
| 4423 |
int ret; |
| 4424 |
|
| 4425 |
ret = ath11k_dp_rx_pdev_srng_alloc(ar); |
| 4426 |
if (ret) { |
| 4427 |
ath11k_warn(ab, "failed to setup rx srngs\n"); |
| 4428 |
return ret; |
| 4429 |
} |
| 4430 |
|
| 4431 |
ret = ath11k_dp_rxdma_pdev_buf_setup(ar); |
| 4432 |
if (ret) { |
| 4433 |
ath11k_warn(ab, "failed to setup rxdma ring\n"); |
| 4434 |
return ret; |
| 4435 |
} |
| 4436 |
|
| 4437 |
ring_id = dp->rx_refill_buf_ring.refill_buf_ring.ring_id; |
| 4438 |
ret = ath11k_dp_tx_htt_srng_setup(ab, ring_id, mac_id, HAL_RXDMA_BUF); |
| 4439 |
if (ret) { |
| 4440 |
ath11k_warn(ab, "failed to configure rx_refill_buf_ring %d\n", |
| 4441 |
ret); |
| 4442 |
return ret; |
| 4443 |
} |
| 4444 |
|
| 4445 |
if (ab->hw_params.rx_mac_buf_ring) { |
| 4446 |
for (i = 0; i < ab->hw_params.num_rxdma_per_pdev; i++) { |
| 4447 |
ring_id = dp->rx_mac_buf_ring[i].ring_id; |
| 4448 |
ret = ath11k_dp_tx_htt_srng_setup(ab, ring_id, |
| 4449 |
mac_id + i, HAL_RXDMA_BUF); |
| 4450 |
if (ret) { |
| 4451 |
ath11k_warn(ab, "failed to configure rx_mac_buf_ring%d %d\n", |
| 4452 |
i, ret); |
| 4453 |
return ret; |
| 4454 |
} |
| 4455 |
} |
| 4456 |
} |
| 4457 |
|
| 4458 |
for (i = 0; i < ab->hw_params.num_rxdma_per_pdev; i++) { |
| 4459 |
ring_id = dp->rxdma_err_dst_ring[i].ring_id; |
| 4460 |
ret = ath11k_dp_tx_htt_srng_setup(ab, ring_id, |
| 4461 |
mac_id + i, HAL_RXDMA_DST); |
| 4462 |
if (ret) { |
| 4463 |
ath11k_warn(ab, "failed to configure rxdma_err_dest_ring%d %d\n", |
| 4464 |
i, ret); |
| 4465 |
return ret; |
| 4466 |
} |
| 4467 |
} |
| 4468 |
|
| 4469 |
if (!ab->hw_params.rxdma1_enable) |
| 4470 |
goto config_refill_ring; |
| 4471 |
|
| 4472 |
ring_id = dp->rxdma_mon_buf_ring.refill_buf_ring.ring_id; |
| 4473 |
ret = ath11k_dp_tx_htt_srng_setup(ab, ring_id, |
| 4474 |
mac_id, HAL_RXDMA_MONITOR_BUF); |
| 4475 |
if (ret) { |
| 4476 |
ath11k_warn(ab, "failed to configure rxdma_mon_buf_ring %d\n", |
| 4477 |
ret); |
| 4478 |
return ret; |
| 4479 |
} |
| 4480 |
ret = ath11k_dp_tx_htt_srng_setup(ab, |
| 4481 |
dp->rxdma_mon_dst_ring.ring_id, |
| 4482 |
mac_id, HAL_RXDMA_MONITOR_DST); |
| 4483 |
if (ret) { |
| 4484 |
ath11k_warn(ab, "failed to configure rxdma_mon_dst_ring %d\n", |
| 4485 |
ret); |
| 4486 |
return ret; |
| 4487 |
} |
| 4488 |
ret = ath11k_dp_tx_htt_srng_setup(ab, |
| 4489 |
dp->rxdma_mon_desc_ring.ring_id, |
| 4490 |
mac_id, HAL_RXDMA_MONITOR_DESC); |
| 4491 |
if (ret) { |
| 4492 |
ath11k_warn(ab, "failed to configure rxdma_mon_dst_ring %d\n", |
| 4493 |
ret); |
| 4494 |
return ret; |
| 4495 |
} |
| 4496 |
|
| 4497 |
config_refill_ring: |
| 4498 |
for (i = 0; i < ab->hw_params.num_rxdma_per_pdev; i++) { |
| 4499 |
ring_id = dp->rx_mon_status_refill_ring[i].refill_buf_ring.ring_id; |
| 4500 |
ret = ath11k_dp_tx_htt_srng_setup(ab, ring_id, mac_id + i, |
| 4501 |
HAL_RXDMA_MONITOR_STATUS); |
| 4502 |
if (ret) { |
| 4503 |
ath11k_warn(ab, |
| 4504 |
"failed to configure mon_status_refill_ring%d %d\n", |
| 4505 |
i, ret); |
| 4506 |
return ret; |
| 4507 |
} |
| 4508 |
} |
| 4509 |
|
| 4510 |
return 0; |
| 4511 |
} |
| 4512 |
|
| 4513 |
static void ath11k_dp_mon_set_frag_len(u32 *total_len, u32 *frag_len) |
| 4514 |
{ |
| 4515 |
if (*total_len >= (DP_RX_BUFFER_SIZE - sizeof(struct hal_rx_desc))) { |
| 4516 |
*frag_len = DP_RX_BUFFER_SIZE - sizeof(struct hal_rx_desc); |
| 4517 |
*total_len -= *frag_len; |
| 4518 |
} else { |
| 4519 |
*frag_len = *total_len; |
| 4520 |
*total_len = 0; |
| 4521 |
} |
| 4522 |
} |
| 4523 |
|
| 4524 |
static |
| 4525 |
int ath11k_dp_rx_monitor_link_desc_return(struct ath11k *ar, |
| 4526 |
void *p_last_buf_addr_info, |
| 4527 |
u8 mac_id) |
| 4528 |
{ |
| 4529 |
struct ath11k_pdev_dp *dp = &ar->dp; |
| 4530 |
struct dp_srng *dp_srng; |
| 4531 |
void *hal_srng; |
| 4532 |
void *src_srng_desc; |
| 4533 |
int ret = 0; |
| 4534 |
|
| 4535 |
if (ar->ab->hw_params.rxdma1_enable) { |
| 4536 |
dp_srng = &dp->rxdma_mon_desc_ring; |
| 4537 |
hal_srng = &ar->ab->hal.srng_list[dp_srng->ring_id]; |
| 4538 |
} else { |
| 4539 |
dp_srng = &ar->ab->dp.wbm_desc_rel_ring; |
| 4540 |
hal_srng = &ar->ab->hal.srng_list[dp_srng->ring_id]; |
| 4541 |
} |
| 4542 |
|
| 4543 |
ath11k_hal_srng_access_begin(ar->ab, hal_srng); |
| 4544 |
|
| 4545 |
src_srng_desc = ath11k_hal_srng_src_get_next_entry(ar->ab, hal_srng); |
| 4546 |
|
| 4547 |
if (src_srng_desc) { |
| 4548 |
struct ath11k_buffer_addr *src_desc = src_srng_desc; |
| 4549 |
|
| 4550 |
*src_desc = *((struct ath11k_buffer_addr *)p_last_buf_addr_info); |
| 4551 |
} else { |
| 4552 |
ath11k_dbg(ar->ab, ATH11K_DBG_DATA, |
| 4553 |
"Monitor Link Desc Ring %d Full", mac_id); |
| 4554 |
ret = -ENOMEM; |
| 4555 |
} |
| 4556 |
|
| 4557 |
ath11k_hal_srng_access_end(ar->ab, hal_srng); |
| 4558 |
return ret; |
| 4559 |
} |
| 4560 |
|
| 4561 |
static |
| 4562 |
void ath11k_dp_rx_mon_next_link_desc_get(void *rx_msdu_link_desc, |
| 4563 |
dma_addr_t *paddr, u32 *sw_cookie, |
| 4564 |
u8 *rbm, |
| 4565 |
void **pp_buf_addr_info) |
| 4566 |
{ |
| 4567 |
struct hal_rx_msdu_link *msdu_link = rx_msdu_link_desc; |
| 4568 |
struct ath11k_buffer_addr *buf_addr_info; |
| 4569 |
|
| 4570 |
buf_addr_info = (struct ath11k_buffer_addr *)&msdu_link->buf_addr_info; |
| 4571 |
|
| 4572 |
ath11k_hal_rx_buf_addr_info_get(buf_addr_info, paddr, sw_cookie, rbm); |
| 4573 |
|
| 4574 |
*pp_buf_addr_info = (void *)buf_addr_info; |
| 4575 |
} |
| 4576 |
|
| 4577 |
static int ath11k_dp_pkt_set_pktlen(struct sk_buff *skb, u32 len) |
| 4578 |
{ |
| 4579 |
if (skb->len > len) { |
| 4580 |
skb_trim(skb, len); |
| 4581 |
} else { |
| 4582 |
if (skb_tailroom(skb) < len - skb->len) { |
| 4583 |
if ((pskb_expand_head(skb, 0, |
| 4584 |
len - skb->len - skb_tailroom(skb), |
| 4585 |
GFP_ATOMIC))) { |
| 4586 |
dev_kfree_skb_any(skb); |
| 4587 |
return -ENOMEM; |
| 4588 |
} |
| 4589 |
} |
| 4590 |
skb_put(skb, (len - skb->len)); |
| 4591 |
} |
| 4592 |
return 0; |
| 4593 |
} |
| 4594 |
|
| 4595 |
static void ath11k_hal_rx_msdu_list_get(struct ath11k *ar, |
| 4596 |
void *msdu_link_desc, |
| 4597 |
struct hal_rx_msdu_list *msdu_list, |
| 4598 |
u16 *num_msdus) |
| 4599 |
{ |
| 4600 |
struct hal_rx_msdu_details *msdu_details = NULL; |
| 4601 |
struct rx_msdu_desc *msdu_desc_info = NULL; |
| 4602 |
struct hal_rx_msdu_link *msdu_link = NULL; |
| 4603 |
int i; |
| 4604 |
u32 last = FIELD_PREP(RX_MSDU_DESC_INFO0_LAST_MSDU_IN_MPDU, 1); |
| 4605 |
u32 first = FIELD_PREP(RX_MSDU_DESC_INFO0_FIRST_MSDU_IN_MPDU, 1); |
| 4606 |
u8 tmp = 0; |
| 4607 |
|
| 4608 |
msdu_link = msdu_link_desc; |
| 4609 |
msdu_details = &msdu_link->msdu_link[0]; |
| 4610 |
|
| 4611 |
for (i = 0; i < HAL_RX_NUM_MSDU_DESC; i++) { |
| 4612 |
if (FIELD_GET(BUFFER_ADDR_INFO0_ADDR, |
| 4613 |
msdu_details[i].buf_addr_info.info0) == 0) { |
| 4614 |
msdu_desc_info = &msdu_details[i - 1].rx_msdu_info; |
| 4615 |
msdu_desc_info->info0 |= last; |
| 4616 |
break; |
| 4617 |
} |
| 4618 |
msdu_desc_info = &msdu_details[i].rx_msdu_info; |
| 4619 |
|
| 4620 |
if (!i) |
| 4621 |
msdu_desc_info->info0 |= first; |
| 4622 |
else if (i == (HAL_RX_NUM_MSDU_DESC - 1)) |
| 4623 |
msdu_desc_info->info0 |= last; |
| 4624 |
msdu_list->msdu_info[i].msdu_flags = msdu_desc_info->info0; |
| 4625 |
msdu_list->msdu_info[i].msdu_len = |
| 4626 |
HAL_RX_MSDU_PKT_LENGTH_GET(msdu_desc_info->info0); |
| 4627 |
msdu_list->sw_cookie[i] = |
| 4628 |
FIELD_GET(BUFFER_ADDR_INFO1_SW_COOKIE, |
| 4629 |
msdu_details[i].buf_addr_info.info1); |
| 4630 |
tmp = FIELD_GET(BUFFER_ADDR_INFO1_RET_BUF_MGR, |
| 4631 |
msdu_details[i].buf_addr_info.info1); |
| 4632 |
msdu_list->rbm[i] = tmp; |
| 4633 |
} |
| 4634 |
*num_msdus = i; |
| 4635 |
} |
| 4636 |
|
| 4637 |
static u32 ath11k_dp_rx_mon_comp_ppduid(u32 msdu_ppdu_id, u32 *ppdu_id, |
| 4638 |
u32 *rx_bufs_used) |
| 4639 |
{ |
| 4640 |
u32 ret = 0; |
| 4641 |
|
| 4642 |
if ((*ppdu_id < msdu_ppdu_id) && |
| 4643 |
((msdu_ppdu_id - *ppdu_id) < DP_NOT_PPDU_ID_WRAP_AROUND)) { |
| 4644 |
*ppdu_id = msdu_ppdu_id; |
| 4645 |
ret = msdu_ppdu_id; |
| 4646 |
} else if ((*ppdu_id > msdu_ppdu_id) && |
| 4647 |
((*ppdu_id - msdu_ppdu_id) > DP_NOT_PPDU_ID_WRAP_AROUND)) { |
| 4648 |
/* mon_dst is behind than mon_status |
| 4649 |
* skip dst_ring and free it |
| 4650 |
*/ |
| 4651 |
*rx_bufs_used += 1; |
| 4652 |
*ppdu_id = msdu_ppdu_id; |
| 4653 |
ret = msdu_ppdu_id; |
| 4654 |
} |
| 4655 |
return ret; |
| 4656 |
} |
| 4657 |
|
| 4658 |
static void ath11k_dp_mon_get_buf_len(struct hal_rx_msdu_desc_info *info, |
| 4659 |
bool *is_frag, u32 *total_len, |
| 4660 |
u32 *frag_len, u32 *msdu_cnt) |
| 4661 |
{ |
| 4662 |
if (info->msdu_flags & RX_MSDU_DESC_INFO0_MSDU_CONTINUATION) { |
| 4663 |
if (!*is_frag) { |
| 4664 |
*total_len = info->msdu_len; |
| 4665 |
*is_frag = true; |
| 4666 |
} |
| 4667 |
ath11k_dp_mon_set_frag_len(total_len, |
| 4668 |
frag_len); |
| 4669 |
} else { |
| 4670 |
if (*is_frag) { |
| 4671 |
ath11k_dp_mon_set_frag_len(total_len, |
| 4672 |
frag_len); |
| 4673 |
} else { |
| 4674 |
*frag_len = info->msdu_len; |
| 4675 |
} |
| 4676 |
*is_frag = false; |
| 4677 |
*msdu_cnt -= 1; |
| 4678 |
} |
| 4679 |
} |
| 4680 |
|
| 4681 |
/* clang stack usage explodes if this is inlined */ |
| 4682 |
static noinline_for_stack |
| 4683 |
u32 ath11k_dp_rx_mon_mpdu_pop(struct ath11k *ar, int mac_id, |
| 4684 |
void *ring_entry, struct sk_buff **head_msdu, |
| 4685 |
struct sk_buff **tail_msdu, u32 *npackets, |
| 4686 |
u32 *ppdu_id) |
| 4687 |
{ |
| 4688 |
struct ath11k_pdev_dp *dp = &ar->dp; |
| 4689 |
struct ath11k_mon_data *pmon = (struct ath11k_mon_data *)&dp->mon_data; |
| 4690 |
struct dp_rxdma_ring *rx_ring = &dp->rxdma_mon_buf_ring; |
| 4691 |
struct sk_buff *msdu = NULL, *last = NULL; |
| 4692 |
struct hal_rx_msdu_list msdu_list; |
| 4693 |
void *p_buf_addr_info, *p_last_buf_addr_info; |
| 4694 |
struct hal_rx_desc *rx_desc; |
| 4695 |
void *rx_msdu_link_desc; |
| 4696 |
dma_addr_t paddr; |
| 4697 |
u16 num_msdus = 0; |
| 4698 |
u32 rx_buf_size, rx_pkt_offset, sw_cookie; |
| 4699 |
u32 rx_bufs_used = 0, i = 0; |
| 4700 |
u32 msdu_ppdu_id = 0, msdu_cnt = 0; |
| 4701 |
u32 total_len = 0, frag_len = 0; |
| 4702 |
bool is_frag, is_first_msdu; |
| 4703 |
bool drop_mpdu = false; |
| 4704 |
struct ath11k_skb_rxcb *rxcb; |
| 4705 |
struct hal_reo_entrance_ring *ent_desc = ring_entry; |
| 4706 |
int buf_id; |
| 4707 |
u32 rx_link_buf_info[2]; |
| 4708 |
u8 rbm; |
| 4709 |
|
| 4710 |
if (!ar->ab->hw_params.rxdma1_enable) |
| 4711 |
rx_ring = &dp->rx_refill_buf_ring; |
| 4712 |
|
| 4713 |
ath11k_hal_rx_reo_ent_buf_paddr_get(ring_entry, &paddr, |
| 4714 |
&sw_cookie, |
| 4715 |
&p_last_buf_addr_info, &rbm, |
| 4716 |
&msdu_cnt); |
| 4717 |
|
| 4718 |
if (FIELD_GET(HAL_REO_ENTR_RING_INFO1_RXDMA_PUSH_REASON, |
| 4719 |
ent_desc->info1) == |
| 4720 |
HAL_REO_DEST_RING_PUSH_REASON_ERR_DETECTED) { |
| 4721 |
u8 rxdma_err = |
| 4722 |
FIELD_GET(HAL_REO_ENTR_RING_INFO1_RXDMA_ERROR_CODE, |
| 4723 |
ent_desc->info1); |
| 4724 |
if (rxdma_err == HAL_REO_ENTR_RING_RXDMA_ECODE_FLUSH_REQUEST_ERR || |
| 4725 |
rxdma_err == HAL_REO_ENTR_RING_RXDMA_ECODE_MPDU_LEN_ERR || |
| 4726 |
rxdma_err == HAL_REO_ENTR_RING_RXDMA_ECODE_OVERFLOW_ERR) { |
| 4727 |
drop_mpdu = true; |
| 4728 |
pmon->rx_mon_stats.dest_mpdu_drop++; |
| 4729 |
} |
| 4730 |
} |
| 4731 |
|
| 4732 |
is_frag = false; |
| 4733 |
is_first_msdu = true; |
| 4734 |
|
| 4735 |
do { |
| 4736 |
if (pmon->mon_last_linkdesc_paddr == paddr) { |
| 4737 |
pmon->rx_mon_stats.dup_mon_linkdesc_cnt++; |
| 4738 |
return rx_bufs_used; |
| 4739 |
} |
| 4740 |
|
| 4741 |
if (ar->ab->hw_params.rxdma1_enable) |
| 4742 |
rx_msdu_link_desc = |
| 4743 |
(void *)pmon->link_desc_banks[sw_cookie].vaddr + |
| 4744 |
(paddr - pmon->link_desc_banks[sw_cookie].paddr); |
| 4745 |
else |
| 4746 |
rx_msdu_link_desc = |
| 4747 |
(void *)ar->ab->dp.link_desc_banks[sw_cookie].vaddr + |
| 4748 |
(paddr - ar->ab->dp.link_desc_banks[sw_cookie].paddr); |
| 4749 |
|
| 4750 |
ath11k_hal_rx_msdu_list_get(ar, rx_msdu_link_desc, &msdu_list, |
| 4751 |
&num_msdus); |
| 4752 |
|
| 4753 |
for (i = 0; i < num_msdus; i++) { |
| 4754 |
u32 l2_hdr_offset; |
| 4755 |
|
| 4756 |
if (pmon->mon_last_buf_cookie == msdu_list.sw_cookie[i]) { |
| 4757 |
ath11k_dbg(ar->ab, ATH11K_DBG_DATA, |
| 4758 |
"i %d last_cookie %d is same\n", |
| 4759 |
i, pmon->mon_last_buf_cookie); |
| 4760 |
drop_mpdu = true; |
| 4761 |
pmon->rx_mon_stats.dup_mon_buf_cnt++; |
| 4762 |
continue; |
| 4763 |
} |
| 4764 |
buf_id = FIELD_GET(DP_RXDMA_BUF_COOKIE_BUF_ID, |
| 4765 |
msdu_list.sw_cookie[i]); |
| 4766 |
|
| 4767 |
spin_lock_bh(&rx_ring->idr_lock); |
| 4768 |
msdu = idr_find(&rx_ring->bufs_idr, buf_id); |
| 4769 |
spin_unlock_bh(&rx_ring->idr_lock); |
| 4770 |
if (!msdu) { |
| 4771 |
ath11k_dbg(ar->ab, ATH11K_DBG_DATA, |
| 4772 |
"msdu_pop: invalid buf_id %d\n", buf_id); |
| 4773 |
goto next_msdu; |
| 4774 |
} |
| 4775 |
rxcb = ATH11K_SKB_RXCB(msdu); |
| 4776 |
if (!rxcb->unmapped) { |
| 4777 |
dma_unmap_single(ar->ab->dev, rxcb->paddr, |
| 4778 |
msdu->len + |
| 4779 |
skb_tailroom(msdu), |
| 4780 |
DMA_FROM_DEVICE); |
| 4781 |
rxcb->unmapped = 1; |
| 4782 |
} |
| 4783 |
if (drop_mpdu) { |
| 4784 |
ath11k_dbg(ar->ab, ATH11K_DBG_DATA, |
| 4785 |
"i %d drop msdu %p *ppdu_id %x\n", |
| 4786 |
i, msdu, *ppdu_id); |
| 4787 |
dev_kfree_skb_any(msdu); |
| 4788 |
msdu = NULL; |
| 4789 |
goto next_msdu; |
| 4790 |
} |
| 4791 |
|
| 4792 |
rx_desc = (struct hal_rx_desc *)msdu->data; |
| 4793 |
|
| 4794 |
rx_pkt_offset = sizeof(struct hal_rx_desc); |
| 4795 |
l2_hdr_offset = ath11k_dp_rx_h_msdu_end_l3pad(ar->ab, rx_desc); |
| 4796 |
|
| 4797 |
if (is_first_msdu) { |
| 4798 |
if (!ath11k_dp_rxdesc_mpdu_valid(ar->ab, rx_desc)) { |
| 4799 |
drop_mpdu = true; |
| 4800 |
dev_kfree_skb_any(msdu); |
| 4801 |
msdu = NULL; |
| 4802 |
pmon->mon_last_linkdesc_paddr = paddr; |
| 4803 |
goto next_msdu; |
| 4804 |
} |
| 4805 |
|
| 4806 |
msdu_ppdu_id = |
| 4807 |
ath11k_dp_rxdesc_get_ppduid(ar->ab, rx_desc); |
| 4808 |
|
| 4809 |
if (ath11k_dp_rx_mon_comp_ppduid(msdu_ppdu_id, |
| 4810 |
ppdu_id, |
| 4811 |
&rx_bufs_used)) { |
| 4812 |
if (rx_bufs_used) { |
| 4813 |
drop_mpdu = true; |
| 4814 |
dev_kfree_skb_any(msdu); |
| 4815 |
msdu = NULL; |
| 4816 |
goto next_msdu; |
| 4817 |
} |
| 4818 |
return rx_bufs_used; |
| 4819 |
} |
| 4820 |
pmon->mon_last_linkdesc_paddr = paddr; |
| 4821 |
is_first_msdu = false; |
| 4822 |
} |
| 4823 |
ath11k_dp_mon_get_buf_len(&msdu_list.msdu_info[i], |
| 4824 |
&is_frag, &total_len, |
| 4825 |
&frag_len, &msdu_cnt); |
| 4826 |
rx_buf_size = rx_pkt_offset + l2_hdr_offset + frag_len; |
| 4827 |
|
| 4828 |
ath11k_dp_pkt_set_pktlen(msdu, rx_buf_size); |
| 4829 |
|
| 4830 |
if (!(*head_msdu)) |
| 4831 |
*head_msdu = msdu; |
| 4832 |
else if (last) |
| 4833 |
last->next = msdu; |
| 4834 |
|
| 4835 |
last = msdu; |
| 4836 |
next_msdu: |
| 4837 |
pmon->mon_last_buf_cookie = msdu_list.sw_cookie[i]; |
| 4838 |
rx_bufs_used++; |
| 4839 |
spin_lock_bh(&rx_ring->idr_lock); |
| 4840 |
idr_remove(&rx_ring->bufs_idr, buf_id); |
| 4841 |
spin_unlock_bh(&rx_ring->idr_lock); |
| 4842 |
} |
| 4843 |
|
| 4844 |
ath11k_hal_rx_buf_addr_info_set(rx_link_buf_info, paddr, sw_cookie, rbm); |
| 4845 |
|
| 4846 |
ath11k_dp_rx_mon_next_link_desc_get(rx_msdu_link_desc, &paddr, |
| 4847 |
&sw_cookie, &rbm, |
| 4848 |
&p_buf_addr_info); |
| 4849 |
|
| 4850 |
if (ar->ab->hw_params.rxdma1_enable) { |
| 4851 |
if (ath11k_dp_rx_monitor_link_desc_return(ar, |
| 4852 |
p_last_buf_addr_info, |
| 4853 |
dp->mac_id)) |
| 4854 |
ath11k_dbg(ar->ab, ATH11K_DBG_DATA, |
| 4855 |
"dp_rx_monitor_link_desc_return failed"); |
| 4856 |
} else { |
| 4857 |
ath11k_dp_rx_link_desc_return(ar->ab, rx_link_buf_info, |
| 4858 |
HAL_WBM_REL_BM_ACT_PUT_IN_IDLE); |
| 4859 |
} |
| 4860 |
|
| 4861 |
p_last_buf_addr_info = p_buf_addr_info; |
| 4862 |
|
| 4863 |
} while (paddr && msdu_cnt); |
| 4864 |
|
| 4865 |
if (last) |
| 4866 |
last->next = NULL; |
| 4867 |
|
| 4868 |
*tail_msdu = msdu; |
| 4869 |
|
| 4870 |
if (msdu_cnt == 0) |
| 4871 |
*npackets = 1; |
| 4872 |
|
| 4873 |
return rx_bufs_used; |
| 4874 |
} |
| 4875 |
|
| 4876 |
static void ath11k_dp_rx_msdus_set_payload(struct ath11k *ar, struct sk_buff *msdu) |
| 4877 |
{ |
| 4878 |
u32 rx_pkt_offset, l2_hdr_offset; |
| 4879 |
|
| 4880 |
rx_pkt_offset = ar->ab->hw_params.hal_desc_sz; |
| 4881 |
l2_hdr_offset = ath11k_dp_rx_h_msdu_end_l3pad(ar->ab, |
| 4882 |
(struct hal_rx_desc *)msdu->data); |
| 4883 |
skb_pull(msdu, rx_pkt_offset + l2_hdr_offset); |
| 4884 |
} |
| 4885 |
|
| 4886 |
static struct sk_buff * |
| 4887 |
ath11k_dp_rx_mon_merg_msdus(struct ath11k *ar, |
| 4888 |
u32 mac_id, struct sk_buff *head_msdu, |
| 4889 |
struct sk_buff *last_msdu, |
| 4890 |
struct ieee80211_rx_status *rxs, bool *fcs_err) |
| 4891 |
{ |
| 4892 |
struct ath11k_base *ab = ar->ab; |
| 4893 |
struct sk_buff *msdu, *prev_buf; |
| 4894 |
struct hal_rx_desc *rx_desc; |
| 4895 |
char *hdr_desc; |
| 4896 |
u8 *dest, decap_format; |
| 4897 |
struct ieee80211_hdr_3addr *wh; |
| 4898 |
struct rx_attention *rx_attention; |
| 4899 |
u32 err_bitmap; |
| 4900 |
|
| 4901 |
if (!head_msdu) |
| 4902 |
goto err_merge_fail; |
| 4903 |
|
| 4904 |
rx_desc = (struct hal_rx_desc *)head_msdu->data; |
| 4905 |
rx_attention = ath11k_dp_rx_get_attention(ab, rx_desc); |
| 4906 |
err_bitmap = ath11k_dp_rx_h_attn_mpdu_err(rx_attention); |
| 4907 |
|
| 4908 |
if (err_bitmap & DP_RX_MPDU_ERR_FCS) |
| 4909 |
*fcs_err = true; |
| 4910 |
|
| 4911 |
if (ath11k_dp_rxdesc_get_mpdulen_err(rx_attention)) |
| 4912 |
return NULL; |
| 4913 |
|
| 4914 |
decap_format = ath11k_dp_rx_h_msdu_start_decap_type(ab, rx_desc); |
| 4915 |
|
| 4916 |
ath11k_dp_rx_h_ppdu(ar, rx_desc, rxs); |
| 4917 |
|
| 4918 |
if (decap_format == DP_RX_DECAP_TYPE_RAW) { |
| 4919 |
ath11k_dp_rx_msdus_set_payload(ar, head_msdu); |
| 4920 |
|
| 4921 |
prev_buf = head_msdu; |
| 4922 |
msdu = head_msdu->next; |
| 4923 |
|
| 4924 |
while (msdu) { |
| 4925 |
ath11k_dp_rx_msdus_set_payload(ar, msdu); |
| 4926 |
|
| 4927 |
prev_buf = msdu; |
| 4928 |
msdu = msdu->next; |
| 4929 |
} |
| 4930 |
|
| 4931 |
prev_buf->next = NULL; |
| 4932 |
|
| 4933 |
skb_trim(prev_buf, prev_buf->len - HAL_RX_FCS_LEN); |
| 4934 |
} else if (decap_format == DP_RX_DECAP_TYPE_NATIVE_WIFI) { |
| 4935 |
u8 qos_pkt = 0; |
| 4936 |
|
| 4937 |
rx_desc = (struct hal_rx_desc *)head_msdu->data; |
| 4938 |
hdr_desc = ath11k_dp_rxdesc_get_80211hdr(ab, rx_desc); |
| 4939 |
|
| 4940 |
/* Base size */ |
| 4941 |
wh = (struct ieee80211_hdr_3addr *)hdr_desc; |
| 4942 |
|
| 4943 |
if (ieee80211_is_data_qos(wh->frame_control)) |
| 4944 |
qos_pkt = 1; |
| 4945 |
|
| 4946 |
msdu = head_msdu; |
| 4947 |
|
| 4948 |
while (msdu) { |
| 4949 |
ath11k_dp_rx_msdus_set_payload(ar, msdu); |
| 4950 |
if (qos_pkt) { |
| 4951 |
dest = skb_push(msdu, sizeof(__le16)); |
| 4952 |
if (!dest) |
| 4953 |
goto err_merge_fail; |
| 4954 |
memcpy(dest, hdr_desc, sizeof(struct ieee80211_qos_hdr)); |
| 4955 |
} |
| 4956 |
prev_buf = msdu; |
| 4957 |
msdu = msdu->next; |
| 4958 |
} |
| 4959 |
dest = skb_put(prev_buf, HAL_RX_FCS_LEN); |
| 4960 |
if (!dest) |
| 4961 |
goto err_merge_fail; |
| 4962 |
|
| 4963 |
ath11k_dbg(ab, ATH11K_DBG_DATA, |
| 4964 |
"mpdu_buf %p mpdu_buf->len %u", |
| 4965 |
prev_buf, prev_buf->len); |
| 4966 |
} else { |
| 4967 |
ath11k_dbg(ab, ATH11K_DBG_DATA, |
| 4968 |
"decap format %d is not supported!\n", |
| 4969 |
decap_format); |
| 4970 |
goto err_merge_fail; |
| 4971 |
} |
| 4972 |
|
| 4973 |
return head_msdu; |
| 4974 |
|
| 4975 |
err_merge_fail: |
| 4976 |
return NULL; |
| 4977 |
} |
| 4978 |
|
| 4979 |
static void |
| 4980 |
ath11k_dp_rx_update_radiotap_he(struct hal_rx_mon_ppdu_info *rx_status, |
| 4981 |
u8 *rtap_buf) |
| 4982 |
{ |
| 4983 |
u32 rtap_len = 0; |
| 4984 |
|
| 4985 |
put_unaligned_le16(rx_status->he_data1, &rtap_buf[rtap_len]); |
| 4986 |
rtap_len += 2; |
| 4987 |
|
| 4988 |
put_unaligned_le16(rx_status->he_data2, &rtap_buf[rtap_len]); |
| 4989 |
rtap_len += 2; |
| 4990 |
|
| 4991 |
put_unaligned_le16(rx_status->he_data3, &rtap_buf[rtap_len]); |
| 4992 |
rtap_len += 2; |
| 4993 |
|
| 4994 |
put_unaligned_le16(rx_status->he_data4, &rtap_buf[rtap_len]); |
| 4995 |
rtap_len += 2; |
| 4996 |
|
| 4997 |
put_unaligned_le16(rx_status->he_data5, &rtap_buf[rtap_len]); |
| 4998 |
rtap_len += 2; |
| 4999 |
|
| 5000 |
put_unaligned_le16(rx_status->he_data6, &rtap_buf[rtap_len]); |
| 5001 |
} |
| 5002 |
|
| 5003 |
static void |
| 5004 |
ath11k_dp_rx_update_radiotap_he_mu(struct hal_rx_mon_ppdu_info *rx_status, |
| 5005 |
u8 *rtap_buf) |
| 5006 |
{ |
| 5007 |
u32 rtap_len = 0; |
| 5008 |
|
| 5009 |
put_unaligned_le16(rx_status->he_flags1, &rtap_buf[rtap_len]); |
| 5010 |
rtap_len += 2; |
| 5011 |
|
| 5012 |
put_unaligned_le16(rx_status->he_flags2, &rtap_buf[rtap_len]); |
| 5013 |
rtap_len += 2; |
| 5014 |
|
| 5015 |
rtap_buf[rtap_len] = rx_status->he_RU[0]; |
| 5016 |
rtap_len += 1; |
| 5017 |
|
| 5018 |
rtap_buf[rtap_len] = rx_status->he_RU[1]; |
| 5019 |
rtap_len += 1; |
| 5020 |
|
| 5021 |
rtap_buf[rtap_len] = rx_status->he_RU[2]; |
| 5022 |
rtap_len += 1; |
| 5023 |
|
| 5024 |
rtap_buf[rtap_len] = rx_status->he_RU[3]; |
| 5025 |
} |
| 5026 |
|
| 5027 |
static void ath11k_update_radiotap(struct ath11k *ar, |
| 5028 |
struct hal_rx_mon_ppdu_info *ppduinfo, |
| 5029 |
struct sk_buff *mon_skb, |
| 5030 |
struct ieee80211_rx_status *rxs) |
| 5031 |
{ |
| 5032 |
struct ieee80211_supported_band *sband; |
| 5033 |
u8 *ptr = NULL; |
| 5034 |
|
| 5035 |
rxs->flag |= RX_FLAG_MACTIME_START; |
| 5036 |
rxs->signal = ppduinfo->rssi_comb + ATH11K_DEFAULT_NOISE_FLOOR; |
| 5037 |
|
| 5038 |
if (ppduinfo->nss) |
| 5039 |
rxs->nss = ppduinfo->nss; |
| 5040 |
|
| 5041 |
if (ppduinfo->he_mu_flags) { |
| 5042 |
rxs->flag |= RX_FLAG_RADIOTAP_HE_MU; |
| 5043 |
rxs->encoding = RX_ENC_HE; |
| 5044 |
ptr = skb_push(mon_skb, sizeof(struct ieee80211_radiotap_he_mu)); |
| 5045 |
ath11k_dp_rx_update_radiotap_he_mu(ppduinfo, ptr); |
| 5046 |
} else if (ppduinfo->he_flags) { |
| 5047 |
rxs->flag |= RX_FLAG_RADIOTAP_HE; |
| 5048 |
rxs->encoding = RX_ENC_HE; |
| 5049 |
ptr = skb_push(mon_skb, sizeof(struct ieee80211_radiotap_he)); |
| 5050 |
ath11k_dp_rx_update_radiotap_he(ppduinfo, ptr); |
| 5051 |
rxs->rate_idx = ppduinfo->rate; |
| 5052 |
} else if (ppduinfo->vht_flags) { |
| 5053 |
rxs->encoding = RX_ENC_VHT; |
| 5054 |
rxs->rate_idx = ppduinfo->rate; |
| 5055 |
} else if (ppduinfo->ht_flags) { |
| 5056 |
rxs->encoding = RX_ENC_HT; |
| 5057 |
rxs->rate_idx = ppduinfo->rate; |
| 5058 |
} else { |
| 5059 |
rxs->encoding = RX_ENC_LEGACY; |
| 5060 |
sband = &ar->mac.sbands[rxs->band]; |
| 5061 |
rxs->rate_idx = ath11k_mac_hw_rate_to_idx(sband, ppduinfo->rate, |
| 5062 |
ppduinfo->cck_flag); |
| 5063 |
} |
| 5064 |
|
| 5065 |
rxs->mactime = ppduinfo->tsft; |
| 5066 |
} |
| 5067 |
|
| 5068 |
static int ath11k_dp_rx_mon_deliver(struct ath11k *ar, u32 mac_id, |
| 5069 |
struct sk_buff *head_msdu, |
| 5070 |
struct hal_rx_mon_ppdu_info *ppduinfo, |
| 5071 |
struct sk_buff *tail_msdu, |
| 5072 |
struct napi_struct *napi) |
| 5073 |
{ |
| 5074 |
struct ath11k_pdev_dp *dp = &ar->dp; |
| 5075 |
struct sk_buff *mon_skb, *skb_next, *header; |
| 5076 |
struct ieee80211_rx_status *rxs = &dp->rx_status; |
| 5077 |
bool fcs_err = false; |
| 5078 |
|
| 5079 |
mon_skb = ath11k_dp_rx_mon_merg_msdus(ar, mac_id, head_msdu, |
| 5080 |
tail_msdu, rxs, &fcs_err); |
| 5081 |
|
| 5082 |
if (!mon_skb) |
| 5083 |
goto mon_deliver_fail; |
| 5084 |
|
| 5085 |
header = mon_skb; |
| 5086 |
|
| 5087 |
rxs->flag = 0; |
| 5088 |
|
| 5089 |
if (fcs_err) |
| 5090 |
rxs->flag = RX_FLAG_FAILED_FCS_CRC; |
| 5091 |
|
| 5092 |
do { |
| 5093 |
skb_next = mon_skb->next; |
| 5094 |
if (!skb_next) |
| 5095 |
rxs->flag &= ~RX_FLAG_AMSDU_MORE; |
| 5096 |
else |
| 5097 |
rxs->flag |= RX_FLAG_AMSDU_MORE; |
| 5098 |
|
| 5099 |
if (mon_skb == header) { |
| 5100 |
header = NULL; |
| 5101 |
rxs->flag &= ~RX_FLAG_ALLOW_SAME_PN; |
| 5102 |
} else { |
| 5103 |
rxs->flag |= RX_FLAG_ALLOW_SAME_PN; |
| 5104 |
} |
| 5105 |
rxs->flag |= RX_FLAG_ONLY_MONITOR; |
| 5106 |
ath11k_update_radiotap(ar, ppduinfo, mon_skb, rxs); |
| 5107 |
|
| 5108 |
ath11k_dp_rx_deliver_msdu(ar, napi, mon_skb, rxs); |
| 5109 |
mon_skb = skb_next; |
| 5110 |
} while (mon_skb); |
| 5111 |
rxs->flag = 0; |
| 5112 |
|
| 5113 |
return 0; |
| 5114 |
|
| 5115 |
mon_deliver_fail: |
| 5116 |
mon_skb = head_msdu; |
| 5117 |
while (mon_skb) { |
| 5118 |
skb_next = mon_skb->next; |
| 5119 |
dev_kfree_skb_any(mon_skb); |
| 5120 |
mon_skb = skb_next; |
| 5121 |
} |
| 5122 |
return -EINVAL; |
| 5123 |
} |
| 5124 |
|
| 5125 |
/* The destination ring processing is stuck if the destination is not |
| 5126 |
* moving while status ring moves 16 PPDU. The destination ring processing |
| 5127 |
* skips this destination ring PPDU as a workaround. |
| 5128 |
*/ |
| 5129 |
#define MON_DEST_RING_STUCK_MAX_CNT 16 |
| 5130 |
|
| 5131 |
static void ath11k_dp_rx_mon_dest_process(struct ath11k *ar, int mac_id, |
| 5132 |
u32 quota, struct napi_struct *napi) |
| 5133 |
{ |
| 5134 |
struct ath11k_pdev_dp *dp = &ar->dp; |
| 5135 |
struct ath11k_mon_data *pmon = (struct ath11k_mon_data *)&dp->mon_data; |
| 5136 |
const struct ath11k_hw_hal_params *hal_params; |
| 5137 |
void *ring_entry; |
| 5138 |
struct hal_srng *mon_dst_srng; |
| 5139 |
u32 ppdu_id; |
| 5140 |
u32 rx_bufs_used; |
| 5141 |
u32 ring_id; |
| 5142 |
struct ath11k_pdev_mon_stats *rx_mon_stats; |
| 5143 |
u32 npackets = 0; |
| 5144 |
u32 mpdu_rx_bufs_used; |
| 5145 |
|
| 5146 |
if (ar->ab->hw_params.rxdma1_enable) |
| 5147 |
ring_id = dp->rxdma_mon_dst_ring.ring_id; |
| 5148 |
else |
| 5149 |
ring_id = dp->rxdma_err_dst_ring[mac_id].ring_id; |
| 5150 |
|
| 5151 |
mon_dst_srng = &ar->ab->hal.srng_list[ring_id]; |
| 5152 |
|
| 5153 |
spin_lock_bh(&pmon->mon_lock); |
| 5154 |
|
| 5155 |
spin_lock_bh(&mon_dst_srng->lock); |
| 5156 |
ath11k_hal_srng_access_begin(ar->ab, mon_dst_srng); |
| 5157 |
|
| 5158 |
ppdu_id = pmon->mon_ppdu_info.ppdu_id; |
| 5159 |
rx_bufs_used = 0; |
| 5160 |
rx_mon_stats = &pmon->rx_mon_stats; |
| 5161 |
|
| 5162 |
while ((ring_entry = ath11k_hal_srng_dst_peek(ar->ab, mon_dst_srng))) { |
| 5163 |
struct sk_buff *head_msdu, *tail_msdu; |
| 5164 |
|
| 5165 |
head_msdu = NULL; |
| 5166 |
tail_msdu = NULL; |
| 5167 |
|
| 5168 |
mpdu_rx_bufs_used = ath11k_dp_rx_mon_mpdu_pop(ar, mac_id, ring_entry, |
| 5169 |
&head_msdu, |
| 5170 |
&tail_msdu, |
| 5171 |
&npackets, &ppdu_id); |
| 5172 |
|
| 5173 |
rx_bufs_used += mpdu_rx_bufs_used; |
| 5174 |
|
| 5175 |
if (mpdu_rx_bufs_used) { |
| 5176 |
dp->mon_dest_ring_stuck_cnt = 0; |
| 5177 |
} else { |
| 5178 |
dp->mon_dest_ring_stuck_cnt++; |
| 5179 |
rx_mon_stats->dest_mon_not_reaped++; |
| 5180 |
} |
| 5181 |
|
| 5182 |
if (dp->mon_dest_ring_stuck_cnt > MON_DEST_RING_STUCK_MAX_CNT) { |
| 5183 |
rx_mon_stats->dest_mon_stuck++; |
| 5184 |
ath11k_dbg(ar->ab, ATH11K_DBG_DATA, |
| 5185 |
"status ring ppdu_id=%d dest ring ppdu_id=%d mon_dest_ring_stuck_cnt=%d dest_mon_not_reaped=%u dest_mon_stuck=%u\n", |
| 5186 |
pmon->mon_ppdu_info.ppdu_id, ppdu_id, |
| 5187 |
dp->mon_dest_ring_stuck_cnt, |
| 5188 |
rx_mon_stats->dest_mon_not_reaped, |
| 5189 |
rx_mon_stats->dest_mon_stuck); |
| 5190 |
pmon->mon_ppdu_info.ppdu_id = ppdu_id; |
| 5191 |
continue; |
| 5192 |
} |
| 5193 |
|
| 5194 |
if (ppdu_id != pmon->mon_ppdu_info.ppdu_id) { |
| 5195 |
pmon->mon_ppdu_status = DP_PPDU_STATUS_START; |
| 5196 |
ath11k_dbg(ar->ab, ATH11K_DBG_DATA, |
| 5197 |
"dest_rx: new ppdu_id %x != status ppdu_id %x dest_mon_not_reaped = %u dest_mon_stuck = %u\n", |
| 5198 |
ppdu_id, pmon->mon_ppdu_info.ppdu_id, |
| 5199 |
rx_mon_stats->dest_mon_not_reaped, |
| 5200 |
rx_mon_stats->dest_mon_stuck); |
| 5201 |
break; |
| 5202 |
} |
| 5203 |
if (head_msdu && tail_msdu) { |
| 5204 |
ath11k_dp_rx_mon_deliver(ar, dp->mac_id, head_msdu, |
| 5205 |
&pmon->mon_ppdu_info, |
| 5206 |
tail_msdu, napi); |
| 5207 |
rx_mon_stats->dest_mpdu_done++; |
| 5208 |
} |
| 5209 |
|
| 5210 |
ring_entry = ath11k_hal_srng_dst_get_next_entry(ar->ab, |
| 5211 |
mon_dst_srng); |
| 5212 |
} |
| 5213 |
ath11k_hal_srng_access_end(ar->ab, mon_dst_srng); |
| 5214 |
spin_unlock_bh(&mon_dst_srng->lock); |
| 5215 |
|
| 5216 |
spin_unlock_bh(&pmon->mon_lock); |
| 5217 |
|
| 5218 |
if (rx_bufs_used) { |
| 5219 |
rx_mon_stats->dest_ppdu_done++; |
| 5220 |
hal_params = ar->ab->hw_params.hal_params; |
| 5221 |
|
| 5222 |
if (ar->ab->hw_params.rxdma1_enable) |
| 5223 |
ath11k_dp_rxbufs_replenish(ar->ab, dp->mac_id, |
| 5224 |
&dp->rxdma_mon_buf_ring, |
| 5225 |
rx_bufs_used, |
| 5226 |
hal_params->rx_buf_rbm); |
| 5227 |
else |
| 5228 |
ath11k_dp_rxbufs_replenish(ar->ab, dp->mac_id, |
| 5229 |
&dp->rx_refill_buf_ring, |
| 5230 |
rx_bufs_used, |
| 5231 |
hal_params->rx_buf_rbm); |
| 5232 |
} |
| 5233 |
} |
| 5234 |
|
| 5235 |
int ath11k_dp_rx_process_mon_status(struct ath11k_base *ab, int mac_id, |
| 5236 |
struct napi_struct *napi, int budget) |
| 5237 |
{ |
| 5238 |
struct ath11k *ar = ath11k_ab_to_ar(ab, mac_id); |
| 5239 |
enum hal_rx_mon_status hal_status; |
| 5240 |
struct sk_buff *skb; |
| 5241 |
struct sk_buff_head skb_list; |
| 5242 |
struct ath11k_peer *peer; |
| 5243 |
struct ath11k_sta *arsta; |
| 5244 |
int num_buffs_reaped = 0; |
| 5245 |
u32 rx_buf_sz; |
| 5246 |
u16 log_type; |
| 5247 |
struct ath11k_mon_data *pmon = (struct ath11k_mon_data *)&ar->dp.mon_data; |
| 5248 |
struct ath11k_pdev_mon_stats *rx_mon_stats = &pmon->rx_mon_stats; |
| 5249 |
struct hal_rx_mon_ppdu_info *ppdu_info = &pmon->mon_ppdu_info; |
| 5250 |
|
| 5251 |
__skb_queue_head_init(&skb_list); |
| 5252 |
|
| 5253 |
num_buffs_reaped = ath11k_dp_rx_reap_mon_status_ring(ab, mac_id, &budget, |
| 5254 |
&skb_list); |
| 5255 |
if (!num_buffs_reaped) |
| 5256 |
goto exit; |
| 5257 |
|
| 5258 |
memset(ppdu_info, 0, sizeof(*ppdu_info)); |
| 5259 |
ppdu_info->peer_id = HAL_INVALID_PEERID; |
| 5260 |
|
| 5261 |
while ((skb = __skb_dequeue(&skb_list))) { |
| 5262 |
if (ath11k_debugfs_is_pktlog_lite_mode_enabled(ar)) { |
| 5263 |
log_type = ATH11K_PKTLOG_TYPE_LITE_RX; |
| 5264 |
rx_buf_sz = DP_RX_BUFFER_SIZE_LITE; |
| 5265 |
} else if (ath11k_debugfs_is_pktlog_rx_stats_enabled(ar)) { |
| 5266 |
log_type = ATH11K_PKTLOG_TYPE_RX_STATBUF; |
| 5267 |
rx_buf_sz = DP_RX_BUFFER_SIZE; |
| 5268 |
} else { |
| 5269 |
log_type = ATH11K_PKTLOG_TYPE_INVALID; |
| 5270 |
rx_buf_sz = 0; |
| 5271 |
} |
| 5272 |
|
| 5273 |
if (log_type != ATH11K_PKTLOG_TYPE_INVALID) |
| 5274 |
trace_ath11k_htt_rxdesc(ar, skb->data, log_type, rx_buf_sz); |
| 5275 |
|
| 5276 |
memset(ppdu_info, 0, sizeof(*ppdu_info)); |
| 5277 |
ppdu_info->peer_id = HAL_INVALID_PEERID; |
| 5278 |
hal_status = ath11k_hal_rx_parse_mon_status(ab, ppdu_info, skb); |
| 5279 |
|
| 5280 |
if (test_bit(ATH11K_FLAG_MONITOR_STARTED, &ar->monitor_flags) && |
| 5281 |
pmon->mon_ppdu_status == DP_PPDU_STATUS_START && |
| 5282 |
hal_status == HAL_TLV_STATUS_PPDU_DONE) { |
| 5283 |
rx_mon_stats->status_ppdu_done++; |
| 5284 |
pmon->mon_ppdu_status = DP_PPDU_STATUS_DONE; |
| 5285 |
if (!ab->hw_params.full_monitor_mode) { |
| 5286 |
ath11k_dp_rx_mon_dest_process(ar, mac_id, |
| 5287 |
budget, napi); |
| 5288 |
pmon->mon_ppdu_status = DP_PPDU_STATUS_START; |
| 5289 |
} |
| 5290 |
} |
| 5291 |
|
| 5292 |
if (ppdu_info->peer_id == HAL_INVALID_PEERID || |
| 5293 |
hal_status != HAL_RX_MON_STATUS_PPDU_DONE) { |
| 5294 |
dev_kfree_skb_any(skb); |
| 5295 |
continue; |
| 5296 |
} |
| 5297 |
|
| 5298 |
rcu_read_lock(); |
| 5299 |
spin_lock_bh(&ab->base_lock); |
| 5300 |
peer = ath11k_peer_find_by_id(ab, ppdu_info->peer_id); |
| 5301 |
|
| 5302 |
if (!peer || !peer->sta) { |
| 5303 |
ath11k_dbg(ab, ATH11K_DBG_DATA, |
| 5304 |
"failed to find the peer with peer_id %d\n", |
| 5305 |
ppdu_info->peer_id); |
| 5306 |
goto next_skb; |
| 5307 |
} |
| 5308 |
|
| 5309 |
arsta = ath11k_sta_to_arsta(peer->sta); |
| 5310 |
ath11k_dp_rx_update_peer_stats(arsta, ppdu_info); |
| 5311 |
|
| 5312 |
if (ath11k_debugfs_is_pktlog_peer_valid(ar, peer->addr)) |
| 5313 |
trace_ath11k_htt_rxdesc(ar, skb->data, log_type, rx_buf_sz); |
| 5314 |
|
| 5315 |
next_skb: |
| 5316 |
spin_unlock_bh(&ab->base_lock); |
| 5317 |
rcu_read_unlock(); |
| 5318 |
|
| 5319 |
dev_kfree_skb_any(skb); |
| 5320 |
memset(ppdu_info, 0, sizeof(*ppdu_info)); |
| 5321 |
ppdu_info->peer_id = HAL_INVALID_PEERID; |
| 5322 |
} |
| 5323 |
exit: |
| 5324 |
return num_buffs_reaped; |
| 5325 |
} |
| 5326 |
|
| 5327 |
static u32 |
| 5328 |
ath11k_dp_rx_full_mon_mpdu_pop(struct ath11k *ar, |
| 5329 |
void *ring_entry, struct sk_buff **head_msdu, |
| 5330 |
struct sk_buff **tail_msdu, |
| 5331 |
struct hal_sw_mon_ring_entries *sw_mon_entries) |
| 5332 |
{ |
| 5333 |
struct ath11k_pdev_dp *dp = &ar->dp; |
| 5334 |
struct ath11k_mon_data *pmon = &dp->mon_data; |
| 5335 |
struct dp_rxdma_ring *rx_ring = &dp->rxdma_mon_buf_ring; |
| 5336 |
struct sk_buff *msdu = NULL, *last = NULL; |
| 5337 |
struct hal_sw_monitor_ring *sw_desc = ring_entry; |
| 5338 |
struct hal_rx_msdu_list msdu_list; |
| 5339 |
struct hal_rx_desc *rx_desc; |
| 5340 |
struct ath11k_skb_rxcb *rxcb; |
| 5341 |
void *rx_msdu_link_desc; |
| 5342 |
void *p_buf_addr_info, *p_last_buf_addr_info; |
| 5343 |
int buf_id, i = 0; |
| 5344 |
u32 rx_buf_size, rx_pkt_offset, l2_hdr_offset; |
| 5345 |
u32 rx_bufs_used = 0, msdu_cnt = 0; |
| 5346 |
u32 total_len = 0, frag_len = 0, sw_cookie; |
| 5347 |
u16 num_msdus = 0; |
| 5348 |
u8 rxdma_err, rbm; |
| 5349 |
bool is_frag, is_first_msdu; |
| 5350 |
bool drop_mpdu = false; |
| 5351 |
|
| 5352 |
ath11k_hal_rx_sw_mon_ring_buf_paddr_get(ring_entry, sw_mon_entries); |
| 5353 |
|
| 5354 |
sw_cookie = sw_mon_entries->mon_dst_sw_cookie; |
| 5355 |
sw_mon_entries->end_of_ppdu = false; |
| 5356 |
sw_mon_entries->drop_ppdu = false; |
| 5357 |
p_last_buf_addr_info = sw_mon_entries->dst_buf_addr_info; |
| 5358 |
msdu_cnt = sw_mon_entries->msdu_cnt; |
| 5359 |
|
| 5360 |
sw_mon_entries->end_of_ppdu = |
| 5361 |
FIELD_GET(HAL_SW_MON_RING_INFO0_END_OF_PPDU, sw_desc->info0); |
| 5362 |
if (sw_mon_entries->end_of_ppdu) |
| 5363 |
return rx_bufs_used; |
| 5364 |
|
| 5365 |
if (FIELD_GET(HAL_SW_MON_RING_INFO0_RXDMA_PUSH_REASON, |
| 5366 |
sw_desc->info0) == |
| 5367 |
HAL_REO_DEST_RING_PUSH_REASON_ERR_DETECTED) { |
| 5368 |
rxdma_err = |
| 5369 |
FIELD_GET(HAL_SW_MON_RING_INFO0_RXDMA_ERROR_CODE, |
| 5370 |
sw_desc->info0); |
| 5371 |
if (rxdma_err == HAL_REO_ENTR_RING_RXDMA_ECODE_FLUSH_REQUEST_ERR || |
| 5372 |
rxdma_err == HAL_REO_ENTR_RING_RXDMA_ECODE_MPDU_LEN_ERR || |
| 5373 |
rxdma_err == HAL_REO_ENTR_RING_RXDMA_ECODE_OVERFLOW_ERR) { |
| 5374 |
pmon->rx_mon_stats.dest_mpdu_drop++; |
| 5375 |
drop_mpdu = true; |
| 5376 |
} |
| 5377 |
} |
| 5378 |
|
| 5379 |
is_frag = false; |
| 5380 |
is_first_msdu = true; |
| 5381 |
|
| 5382 |
do { |
| 5383 |
rx_msdu_link_desc = |
| 5384 |
(u8 *)pmon->link_desc_banks[sw_cookie].vaddr + |
| 5385 |
(sw_mon_entries->mon_dst_paddr - |
| 5386 |
pmon->link_desc_banks[sw_cookie].paddr); |
| 5387 |
|
| 5388 |
ath11k_hal_rx_msdu_list_get(ar, rx_msdu_link_desc, &msdu_list, |
| 5389 |
&num_msdus); |
| 5390 |
|
| 5391 |
for (i = 0; i < num_msdus; i++) { |
| 5392 |
buf_id = FIELD_GET(DP_RXDMA_BUF_COOKIE_BUF_ID, |
| 5393 |
msdu_list.sw_cookie[i]); |
| 5394 |
|
| 5395 |
spin_lock_bh(&rx_ring->idr_lock); |
| 5396 |
msdu = idr_find(&rx_ring->bufs_idr, buf_id); |
| 5397 |
if (!msdu) { |
| 5398 |
ath11k_dbg(ar->ab, ATH11K_DBG_DATA, |
| 5399 |
"full mon msdu_pop: invalid buf_id %d\n", |
| 5400 |
buf_id); |
| 5401 |
spin_unlock_bh(&rx_ring->idr_lock); |
| 5402 |
goto next_msdu; |
| 5403 |
} |
| 5404 |
idr_remove(&rx_ring->bufs_idr, buf_id); |
| 5405 |
spin_unlock_bh(&rx_ring->idr_lock); |
| 5406 |
|
| 5407 |
rxcb = ATH11K_SKB_RXCB(msdu); |
| 5408 |
if (!rxcb->unmapped) { |
| 5409 |
dma_unmap_single(ar->ab->dev, rxcb->paddr, |
| 5410 |
msdu->len + |
| 5411 |
skb_tailroom(msdu), |
| 5412 |
DMA_FROM_DEVICE); |
| 5413 |
rxcb->unmapped = 1; |
| 5414 |
} |
| 5415 |
if (drop_mpdu) { |
| 5416 |
ath11k_dbg(ar->ab, ATH11K_DBG_DATA, |
| 5417 |
"full mon: i %d drop msdu %p *ppdu_id %x\n", |
| 5418 |
i, msdu, sw_mon_entries->ppdu_id); |
| 5419 |
dev_kfree_skb_any(msdu); |
| 5420 |
msdu_cnt--; |
| 5421 |
goto next_msdu; |
| 5422 |
} |
| 5423 |
|
| 5424 |
rx_desc = (struct hal_rx_desc *)msdu->data; |
| 5425 |
|
| 5426 |
rx_pkt_offset = sizeof(struct hal_rx_desc); |
| 5427 |
l2_hdr_offset = ath11k_dp_rx_h_msdu_end_l3pad(ar->ab, rx_desc); |
| 5428 |
|
| 5429 |
if (is_first_msdu) { |
| 5430 |
if (!ath11k_dp_rxdesc_mpdu_valid(ar->ab, rx_desc)) { |
| 5431 |
drop_mpdu = true; |
| 5432 |
dev_kfree_skb_any(msdu); |
| 5433 |
msdu = NULL; |
| 5434 |
goto next_msdu; |
| 5435 |
} |
| 5436 |
is_first_msdu = false; |
| 5437 |
} |
| 5438 |
|
| 5439 |
ath11k_dp_mon_get_buf_len(&msdu_list.msdu_info[i], |
| 5440 |
&is_frag, &total_len, |
| 5441 |
&frag_len, &msdu_cnt); |
| 5442 |
|
| 5443 |
rx_buf_size = rx_pkt_offset + l2_hdr_offset + frag_len; |
| 5444 |
|
| 5445 |
ath11k_dp_pkt_set_pktlen(msdu, rx_buf_size); |
| 5446 |
|
| 5447 |
if (!(*head_msdu)) |
| 5448 |
*head_msdu = msdu; |
| 5449 |
else if (last) |
| 5450 |
last->next = msdu; |
| 5451 |
|
| 5452 |
last = msdu; |
| 5453 |
next_msdu: |
| 5454 |
rx_bufs_used++; |
| 5455 |
} |
| 5456 |
|
| 5457 |
ath11k_dp_rx_mon_next_link_desc_get(rx_msdu_link_desc, |
| 5458 |
&sw_mon_entries->mon_dst_paddr, |
| 5459 |
&sw_mon_entries->mon_dst_sw_cookie, |
| 5460 |
&rbm, |
| 5461 |
&p_buf_addr_info); |
| 5462 |
|
| 5463 |
if (ath11k_dp_rx_monitor_link_desc_return(ar, |
| 5464 |
p_last_buf_addr_info, |
| 5465 |
dp->mac_id)) |
| 5466 |
ath11k_dbg(ar->ab, ATH11K_DBG_DATA, |
| 5467 |
"full mon: dp_rx_monitor_link_desc_return failed\n"); |
| 5468 |
|
| 5469 |
p_last_buf_addr_info = p_buf_addr_info; |
| 5470 |
|
| 5471 |
} while (sw_mon_entries->mon_dst_paddr && msdu_cnt); |
| 5472 |
|
| 5473 |
if (last) |
| 5474 |
last->next = NULL; |
| 5475 |
|
| 5476 |
*tail_msdu = msdu; |
| 5477 |
|
| 5478 |
return rx_bufs_used; |
| 5479 |
} |
| 5480 |
|
| 5481 |
static int ath11k_dp_rx_full_mon_prepare_mpdu(struct ath11k_dp *dp, |
| 5482 |
struct dp_full_mon_mpdu *mon_mpdu, |
| 5483 |
struct sk_buff *head, |
| 5484 |
struct sk_buff *tail) |
| 5485 |
{ |
| 5486 |
mon_mpdu = kzalloc_obj(*mon_mpdu, GFP_ATOMIC); |
| 5487 |
if (!mon_mpdu) |
| 5488 |
return -ENOMEM; |
| 5489 |
|
| 5490 |
list_add_tail(&mon_mpdu->list, &dp->dp_full_mon_mpdu_list); |
| 5491 |
mon_mpdu->head = head; |
| 5492 |
mon_mpdu->tail = tail; |
| 5493 |
|
| 5494 |
return 0; |
| 5495 |
} |
| 5496 |
|
| 5497 |
static void ath11k_dp_rx_full_mon_drop_ppdu(struct ath11k_dp *dp, |
| 5498 |
struct dp_full_mon_mpdu *mon_mpdu) |
| 5499 |
{ |
| 5500 |
struct dp_full_mon_mpdu *tmp; |
| 5501 |
struct sk_buff *tmp_msdu, *skb_next; |
| 5502 |
|
| 5503 |
if (list_empty(&dp->dp_full_mon_mpdu_list)) |
| 5504 |
return; |
| 5505 |
|
| 5506 |
list_for_each_entry_safe(mon_mpdu, tmp, &dp->dp_full_mon_mpdu_list, list) { |
| 5507 |
list_del(&mon_mpdu->list); |
| 5508 |
|
| 5509 |
tmp_msdu = mon_mpdu->head; |
| 5510 |
while (tmp_msdu) { |
| 5511 |
skb_next = tmp_msdu->next; |
| 5512 |
dev_kfree_skb_any(tmp_msdu); |
| 5513 |
tmp_msdu = skb_next; |
| 5514 |
} |
| 5515 |
|
| 5516 |
kfree(mon_mpdu); |
| 5517 |
} |
| 5518 |
} |
| 5519 |
|
| 5520 |
static int ath11k_dp_rx_full_mon_deliver_ppdu(struct ath11k *ar, |
| 5521 |
int mac_id, |
| 5522 |
struct ath11k_mon_data *pmon, |
| 5523 |
struct napi_struct *napi) |
| 5524 |
{ |
| 5525 |
struct ath11k_pdev_mon_stats *rx_mon_stats; |
| 5526 |
struct dp_full_mon_mpdu *tmp; |
| 5527 |
struct dp_full_mon_mpdu *mon_mpdu = pmon->mon_mpdu; |
| 5528 |
struct sk_buff *head_msdu, *tail_msdu; |
| 5529 |
struct ath11k_base *ab = ar->ab; |
| 5530 |
struct ath11k_dp *dp = &ab->dp; |
| 5531 |
int ret; |
| 5532 |
|
| 5533 |
rx_mon_stats = &pmon->rx_mon_stats; |
| 5534 |
|
| 5535 |
list_for_each_entry_safe(mon_mpdu, tmp, &dp->dp_full_mon_mpdu_list, list) { |
| 5536 |
list_del(&mon_mpdu->list); |
| 5537 |
head_msdu = mon_mpdu->head; |
| 5538 |
tail_msdu = mon_mpdu->tail; |
| 5539 |
if (head_msdu && tail_msdu) { |
| 5540 |
ret = ath11k_dp_rx_mon_deliver(ar, mac_id, head_msdu, |
| 5541 |
&pmon->mon_ppdu_info, |
| 5542 |
tail_msdu, napi); |
| 5543 |
rx_mon_stats->dest_mpdu_done++; |
| 5544 |
ath11k_dbg(ar->ab, ATH11K_DBG_DATA, "full mon: deliver ppdu\n"); |
| 5545 |
} |
| 5546 |
kfree(mon_mpdu); |
| 5547 |
} |
| 5548 |
|
| 5549 |
return ret; |
| 5550 |
} |
| 5551 |
|
| 5552 |
static int |
| 5553 |
ath11k_dp_rx_process_full_mon_status_ring(struct ath11k_base *ab, int mac_id, |
| 5554 |
struct napi_struct *napi, int budget) |
| 5555 |
{ |
| 5556 |
struct ath11k *ar = ab->pdevs[mac_id].ar; |
| 5557 |
struct ath11k_pdev_dp *dp = &ar->dp; |
| 5558 |
struct ath11k_mon_data *pmon = &dp->mon_data; |
| 5559 |
struct hal_sw_mon_ring_entries *sw_mon_entries; |
| 5560 |
int quota = 0, work = 0, count; |
| 5561 |
|
| 5562 |
sw_mon_entries = &pmon->sw_mon_entries; |
| 5563 |
|
| 5564 |
while (pmon->hold_mon_dst_ring) { |
| 5565 |
quota = ath11k_dp_rx_process_mon_status(ab, mac_id, |
| 5566 |
napi, 1); |
| 5567 |
if (pmon->buf_state == DP_MON_STATUS_MATCH) { |
| 5568 |
count = sw_mon_entries->status_buf_count; |
| 5569 |
if (count > 1) { |
| 5570 |
quota += ath11k_dp_rx_process_mon_status(ab, mac_id, |
| 5571 |
napi, count); |
| 5572 |
} |
| 5573 |
|
| 5574 |
ath11k_dp_rx_full_mon_deliver_ppdu(ar, dp->mac_id, |
| 5575 |
pmon, napi); |
| 5576 |
pmon->hold_mon_dst_ring = false; |
| 5577 |
} else if (!pmon->mon_status_paddr || |
| 5578 |
pmon->buf_state == DP_MON_STATUS_LEAD) { |
| 5579 |
sw_mon_entries->drop_ppdu = true; |
| 5580 |
pmon->hold_mon_dst_ring = false; |
| 5581 |
} |
| 5582 |
|
| 5583 |
if (!quota) |
| 5584 |
break; |
| 5585 |
|
| 5586 |
work += quota; |
| 5587 |
} |
| 5588 |
|
| 5589 |
if (sw_mon_entries->drop_ppdu) |
| 5590 |
ath11k_dp_rx_full_mon_drop_ppdu(&ab->dp, pmon->mon_mpdu); |
| 5591 |
|
| 5592 |
return work; |
| 5593 |
} |
| 5594 |
|
| 5595 |
static int ath11k_dp_full_mon_process_rx(struct ath11k_base *ab, int mac_id, |
| 5596 |
struct napi_struct *napi, int budget) |
| 5597 |
{ |
| 5598 |
struct ath11k *ar = ab->pdevs[mac_id].ar; |
| 5599 |
struct ath11k_pdev_dp *dp = &ar->dp; |
| 5600 |
struct ath11k_mon_data *pmon = &dp->mon_data; |
| 5601 |
struct hal_sw_mon_ring_entries *sw_mon_entries; |
| 5602 |
struct ath11k_pdev_mon_stats *rx_mon_stats; |
| 5603 |
struct sk_buff *head_msdu, *tail_msdu; |
| 5604 |
struct hal_srng *mon_dst_srng; |
| 5605 |
void *ring_entry; |
| 5606 |
u32 rx_bufs_used = 0, mpdu_rx_bufs_used; |
| 5607 |
int quota = 0, ret; |
| 5608 |
bool break_dst_ring = false; |
| 5609 |
|
| 5610 |
spin_lock_bh(&pmon->mon_lock); |
| 5611 |
|
| 5612 |
sw_mon_entries = &pmon->sw_mon_entries; |
| 5613 |
rx_mon_stats = &pmon->rx_mon_stats; |
| 5614 |
|
| 5615 |
if (pmon->hold_mon_dst_ring) { |
| 5616 |
spin_unlock_bh(&pmon->mon_lock); |
| 5617 |
goto reap_status_ring; |
| 5618 |
} |
| 5619 |
|
| 5620 |
mon_dst_srng = &ar->ab->hal.srng_list[dp->rxdma_mon_dst_ring.ring_id]; |
| 5621 |
spin_lock_bh(&mon_dst_srng->lock); |
| 5622 |
|
| 5623 |
ath11k_hal_srng_access_begin(ar->ab, mon_dst_srng); |
| 5624 |
while ((ring_entry = ath11k_hal_srng_dst_peek(ar->ab, mon_dst_srng))) { |
| 5625 |
head_msdu = NULL; |
| 5626 |
tail_msdu = NULL; |
| 5627 |
|
| 5628 |
mpdu_rx_bufs_used = ath11k_dp_rx_full_mon_mpdu_pop(ar, ring_entry, |
| 5629 |
&head_msdu, |
| 5630 |
&tail_msdu, |
| 5631 |
sw_mon_entries); |
| 5632 |
rx_bufs_used += mpdu_rx_bufs_used; |
| 5633 |
|
| 5634 |
if (!sw_mon_entries->end_of_ppdu) { |
| 5635 |
if (head_msdu) { |
| 5636 |
ret = ath11k_dp_rx_full_mon_prepare_mpdu(&ab->dp, |
| 5637 |
pmon->mon_mpdu, |
| 5638 |
head_msdu, |
| 5639 |
tail_msdu); |
| 5640 |
if (ret) |
| 5641 |
break_dst_ring = true; |
| 5642 |
} |
| 5643 |
|
| 5644 |
goto next_entry; |
| 5645 |
} else { |
| 5646 |
if (!sw_mon_entries->ppdu_id && |
| 5647 |
!sw_mon_entries->mon_status_paddr) { |
| 5648 |
break_dst_ring = true; |
| 5649 |
goto next_entry; |
| 5650 |
} |
| 5651 |
} |
| 5652 |
|
| 5653 |
rx_mon_stats->dest_ppdu_done++; |
| 5654 |
pmon->mon_ppdu_status = DP_PPDU_STATUS_START; |
| 5655 |
pmon->buf_state = DP_MON_STATUS_LAG; |
| 5656 |
pmon->mon_status_paddr = sw_mon_entries->mon_status_paddr; |
| 5657 |
pmon->hold_mon_dst_ring = true; |
| 5658 |
next_entry: |
| 5659 |
ring_entry = ath11k_hal_srng_dst_get_next_entry(ar->ab, |
| 5660 |
mon_dst_srng); |
| 5661 |
if (break_dst_ring) |
| 5662 |
break; |
| 5663 |
} |
| 5664 |
|
| 5665 |
ath11k_hal_srng_access_end(ar->ab, mon_dst_srng); |
| 5666 |
spin_unlock_bh(&mon_dst_srng->lock); |
| 5667 |
spin_unlock_bh(&pmon->mon_lock); |
| 5668 |
|
| 5669 |
if (rx_bufs_used) { |
| 5670 |
ath11k_dp_rxbufs_replenish(ar->ab, dp->mac_id, |
| 5671 |
&dp->rxdma_mon_buf_ring, |
| 5672 |
rx_bufs_used, |
| 5673 |
HAL_RX_BUF_RBM_SW3_BM); |
| 5674 |
} |
| 5675 |
|
| 5676 |
reap_status_ring: |
| 5677 |
quota = ath11k_dp_rx_process_full_mon_status_ring(ab, mac_id, |
| 5678 |
napi, budget); |
| 5679 |
|
| 5680 |
return quota; |
| 5681 |
} |
| 5682 |
|
| 5683 |
int ath11k_dp_rx_process_mon_rings(struct ath11k_base *ab, int mac_id, |
| 5684 |
struct napi_struct *napi, int budget) |
| 5685 |
{ |
| 5686 |
struct ath11k *ar = ath11k_ab_to_ar(ab, mac_id); |
| 5687 |
int ret = 0; |
| 5688 |
|
| 5689 |
if (test_bit(ATH11K_FLAG_MONITOR_STARTED, &ar->monitor_flags) && |
| 5690 |
ab->hw_params.full_monitor_mode) |
| 5691 |
ret = ath11k_dp_full_mon_process_rx(ab, mac_id, napi, budget); |
| 5692 |
else |
| 5693 |
ret = ath11k_dp_rx_process_mon_status(ab, mac_id, napi, budget); |
| 5694 |
|
| 5695 |
return ret; |
| 5696 |
} |
| 5697 |
|
| 5698 |
static int ath11k_dp_rx_pdev_mon_status_attach(struct ath11k *ar) |
| 5699 |
{ |
| 5700 |
struct ath11k_pdev_dp *dp = &ar->dp; |
| 5701 |
struct ath11k_mon_data *pmon = (struct ath11k_mon_data *)&dp->mon_data; |
| 5702 |
|
| 5703 |
pmon->mon_ppdu_status = DP_PPDU_STATUS_START; |
| 5704 |
|
| 5705 |
memset(&pmon->rx_mon_stats, 0, |
| 5706 |
sizeof(pmon->rx_mon_stats)); |
| 5707 |
return 0; |
| 5708 |
} |
| 5709 |
|
| 5710 |
int ath11k_dp_rx_pdev_mon_attach(struct ath11k *ar) |
| 5711 |
{ |
| 5712 |
struct ath11k_pdev_dp *dp = &ar->dp; |
| 5713 |
struct ath11k_mon_data *pmon = &dp->mon_data; |
| 5714 |
struct hal_srng *mon_desc_srng = NULL; |
| 5715 |
struct dp_srng *dp_srng; |
| 5716 |
int ret = 0; |
| 5717 |
u32 n_link_desc = 0; |
| 5718 |
|
| 5719 |
ret = ath11k_dp_rx_pdev_mon_status_attach(ar); |
| 5720 |
if (ret) { |
| 5721 |
ath11k_warn(ar->ab, "pdev_mon_status_attach() failed"); |
| 5722 |
return ret; |
| 5723 |
} |
| 5724 |
|
| 5725 |
/* if rxdma1_enable is false, no need to setup |
| 5726 |
* rxdma_mon_desc_ring. |
| 5727 |
*/ |
| 5728 |
if (!ar->ab->hw_params.rxdma1_enable) |
| 5729 |
return 0; |
| 5730 |
|
| 5731 |
dp_srng = &dp->rxdma_mon_desc_ring; |
| 5732 |
n_link_desc = dp_srng->size / |
| 5733 |
ath11k_hal_srng_get_entrysize(ar->ab, HAL_RXDMA_MONITOR_DESC); |
| 5734 |
mon_desc_srng = |
| 5735 |
&ar->ab->hal.srng_list[dp->rxdma_mon_desc_ring.ring_id]; |
| 5736 |
|
| 5737 |
ret = ath11k_dp_link_desc_setup(ar->ab, pmon->link_desc_banks, |
| 5738 |
HAL_RXDMA_MONITOR_DESC, mon_desc_srng, |
| 5739 |
n_link_desc); |
| 5740 |
if (ret) { |
| 5741 |
ath11k_warn(ar->ab, "mon_link_desc_pool_setup() failed"); |
| 5742 |
return ret; |
| 5743 |
} |
| 5744 |
pmon->mon_last_linkdesc_paddr = 0; |
| 5745 |
pmon->mon_last_buf_cookie = DP_RX_DESC_COOKIE_MAX + 1; |
| 5746 |
spin_lock_init(&pmon->mon_lock); |
| 5747 |
|
| 5748 |
return 0; |
| 5749 |
} |
| 5750 |
|
| 5751 |
static int ath11k_dp_mon_link_free(struct ath11k *ar) |
| 5752 |
{ |
| 5753 |
struct ath11k_pdev_dp *dp = &ar->dp; |
| 5754 |
struct ath11k_mon_data *pmon = &dp->mon_data; |
| 5755 |
|
| 5756 |
ath11k_dp_link_desc_cleanup(ar->ab, pmon->link_desc_banks, |
| 5757 |
HAL_RXDMA_MONITOR_DESC, |
| 5758 |
&dp->rxdma_mon_desc_ring); |
| 5759 |
return 0; |
| 5760 |
} |
| 5761 |
|
| 5762 |
int ath11k_dp_rx_pdev_mon_detach(struct ath11k *ar) |
| 5763 |
{ |
| 5764 |
ath11k_dp_mon_link_free(ar); |
| 5765 |
return 0; |
| 5766 |
} |
| 5767 |
|
| 5768 |
int ath11k_dp_rx_pktlog_start(struct ath11k_base *ab) |
| 5769 |
{ |
| 5770 |
/* start reap timer */ |
| 5771 |
mod_timer(&ab->mon_reap_timer, |
| 5772 |
jiffies + msecs_to_jiffies(ATH11K_MON_TIMER_INTERVAL)); |
| 5773 |
|
| 5774 |
return 0; |
| 5775 |
} |
| 5776 |
|
| 5777 |
int ath11k_dp_rx_pktlog_stop(struct ath11k_base *ab, bool stop_timer) |
| 5778 |
{ |
| 5779 |
int ret; |
| 5780 |
|
| 5781 |
if (stop_timer) |
| 5782 |
timer_delete_sync(&ab->mon_reap_timer); |
| 5783 |
|
| 5784 |
/* reap all the monitor related rings */ |
| 5785 |
ret = ath11k_dp_purge_mon_ring(ab); |
| 5786 |
if (ret) { |
| 5787 |
ath11k_warn(ab, "failed to purge dp mon ring: %d\n", ret); |
| 5788 |
return ret; |
| 5789 |
} |
| 5790 |
|
| 5791 |
return 0; |
| 5792 |
} |