htt_tx.c 48.6 KB
Newer Older
1
// SPDX-License-Identifier: ISC
2 3
/*
 * Copyright (c) 2005-2011 Atheros Communications Inc.
K
Kalle Valo 已提交
4
 * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
5 6 7 8 9 10 11 12 13
 */

#include <linux/etherdevice.h>
#include "htt.h"
#include "mac.h"
#include "hif.h"
#include "txrx.h"
#include "debug.h"

14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
static u8 ath10k_htt_tx_txq_calc_size(size_t count)
{
	int exp;
	int factor;

	exp = 0;
	factor = count >> 7;

	while (factor >= 64 && exp < 4) {
		factor >>= 3;
		exp++;
	}

	if (exp == 4)
		return 0xff;

	if (count > 0)
		factor = max(1, factor);

	return SM(exp, HTT_TX_Q_STATE_ENTRY_EXP) |
	       SM(factor, HTT_TX_Q_STATE_ENTRY_FACTOR);
}

static void __ath10k_htt_tx_txq_recalc(struct ieee80211_hw *hw,
				       struct ieee80211_txq *txq)
{
	struct ath10k *ar = hw->priv;
41
	struct ath10k_sta *arsta;
42 43 44 45 46 47 48 49 50 51 52 53 54 55
	struct ath10k_vif *arvif = (void *)txq->vif->drv_priv;
	unsigned long frame_cnt;
	unsigned long byte_cnt;
	int idx;
	u32 bit;
	u16 peer_id;
	u8 tid;
	u8 count;

	lockdep_assert_held(&ar->htt.tx_lock);

	if (!ar->htt.tx_q_state.enabled)
		return;

M
Michal Kazior 已提交
56 57 58
	if (ar->htt.tx_q_state.mode != HTT_TX_MODE_SWITCH_PUSH_PULL)
		return;

59 60
	if (txq->sta) {
		arsta = (void *)txq->sta->drv_priv;
61
		peer_id = arsta->peer_id;
62
	} else {
63
		peer_id = arvif->peer_id;
64
	}
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97

	tid = txq->tid;
	bit = BIT(peer_id % 32);
	idx = peer_id / 32;

	ieee80211_txq_get_depth(txq, &frame_cnt, &byte_cnt);
	count = ath10k_htt_tx_txq_calc_size(byte_cnt);

	if (unlikely(peer_id >= ar->htt.tx_q_state.num_peers) ||
	    unlikely(tid >= ar->htt.tx_q_state.num_tids)) {
		ath10k_warn(ar, "refusing to update txq for peer_id %hu tid %hhu due to out of bounds\n",
			    peer_id, tid);
		return;
	}

	ar->htt.tx_q_state.vaddr->count[tid][peer_id] = count;
	ar->htt.tx_q_state.vaddr->map[tid][idx] &= ~bit;
	ar->htt.tx_q_state.vaddr->map[tid][idx] |= count ? bit : 0;

	ath10k_dbg(ar, ATH10K_DBG_HTT, "htt tx txq state update peer_id %hu tid %hhu count %hhu\n",
		   peer_id, tid, count);
}

static void __ath10k_htt_tx_txq_sync(struct ath10k *ar)
{
	u32 seq;
	size_t size;

	lockdep_assert_held(&ar->htt.tx_lock);

	if (!ar->htt.tx_q_state.enabled)
		return;

M
Michal Kazior 已提交
98 99 100
	if (ar->htt.tx_q_state.mode != HTT_TX_MODE_SWITCH_PUSH_PULL)
		return;

101 102 103 104 105 106 107 108 109 110 111 112 113 114
	seq = le32_to_cpu(ar->htt.tx_q_state.vaddr->seq);
	seq++;
	ar->htt.tx_q_state.vaddr->seq = cpu_to_le32(seq);

	ath10k_dbg(ar, ATH10K_DBG_HTT, "htt tx txq state update commit seq %u\n",
		   seq);

	size = sizeof(*ar->htt.tx_q_state.vaddr);
	dma_sync_single_for_device(ar->dev,
				   ar->htt.tx_q_state.paddr,
				   size,
				   DMA_TO_DEVICE);
}

M
Michal Kazior 已提交
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
void ath10k_htt_tx_txq_recalc(struct ieee80211_hw *hw,
			      struct ieee80211_txq *txq)
{
	struct ath10k *ar = hw->priv;

	spin_lock_bh(&ar->htt.tx_lock);
	__ath10k_htt_tx_txq_recalc(hw, txq);
	spin_unlock_bh(&ar->htt.tx_lock);
}

void ath10k_htt_tx_txq_sync(struct ath10k *ar)
{
	spin_lock_bh(&ar->htt.tx_lock);
	__ath10k_htt_tx_txq_sync(ar);
	spin_unlock_bh(&ar->htt.tx_lock);
}

132 133 134 135 136 137 138 139 140 141 142
void ath10k_htt_tx_txq_update(struct ieee80211_hw *hw,
			      struct ieee80211_txq *txq)
{
	struct ath10k *ar = hw->priv;

	spin_lock_bh(&ar->htt.tx_lock);
	__ath10k_htt_tx_txq_recalc(hw, txq);
	__ath10k_htt_tx_txq_sync(ar);
	spin_unlock_bh(&ar->htt.tx_lock);
}

143
void ath10k_htt_tx_dec_pending(struct ath10k_htt *htt)
144
{
145 146
	lockdep_assert_held(&htt->tx_lock);

147 148
	htt->num_pending_tx--;
	if (htt->num_pending_tx == htt->max_num_pending_tx - 1)
M
Michal Kazior 已提交
149
		ath10k_mac_tx_unlock(htt->ar, ATH10K_TX_PAUSE_Q_FULL);
150 151
}

152
int ath10k_htt_tx_inc_pending(struct ath10k_htt *htt)
153
{
154
	lockdep_assert_held(&htt->tx_lock);
155

156 157
	if (htt->num_pending_tx >= htt->max_num_pending_tx)
		return -EBUSY;
158 159 160

	htt->num_pending_tx++;
	if (htt->num_pending_tx == htt->max_num_pending_tx)
M
Michal Kazior 已提交
161
		ath10k_mac_tx_lock(htt->ar, ATH10K_TX_PAUSE_Q_FULL);
162

163
	return 0;
164 165
}

166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
int ath10k_htt_tx_mgmt_inc_pending(struct ath10k_htt *htt, bool is_mgmt,
				   bool is_presp)
{
	struct ath10k *ar = htt->ar;

	lockdep_assert_held(&htt->tx_lock);

	if (!is_mgmt || !ar->hw_params.max_probe_resp_desc_thres)
		return 0;

	if (is_presp &&
	    ar->hw_params.max_probe_resp_desc_thres < htt->num_pending_mgmt_tx)
		return -EBUSY;

	htt->num_pending_mgmt_tx++;

	return 0;
}

void ath10k_htt_tx_mgmt_dec_pending(struct ath10k_htt *htt)
{
	lockdep_assert_held(&htt->tx_lock);

	if (!htt->ar->hw_params.max_probe_resp_desc_thres)
		return;

	htt->num_pending_mgmt_tx--;
}

M
Michal Kazior 已提交
195
int ath10k_htt_tx_alloc_msdu_id(struct ath10k_htt *htt, struct sk_buff *skb)
196
{
197
	struct ath10k *ar = htt->ar;
M
Michal Kazior 已提交
198
	int ret;
199

200
	spin_lock_bh(&htt->tx_lock);
201 202
	ret = idr_alloc(&htt->pending_tx, skb, 0,
			htt->max_num_pending_tx, GFP_ATOMIC);
203
	spin_unlock_bh(&htt->tx_lock);
M
Michal Kazior 已提交
204 205

	ath10k_dbg(ar, ATH10K_DBG_HTT, "htt tx alloc msdu_id %d\n", ret);
206

M
Michal Kazior 已提交
207
	return ret;
208 209 210 211
}

void ath10k_htt_tx_free_msdu_id(struct ath10k_htt *htt, u16 msdu_id)
{
212 213
	struct ath10k *ar = htt->ar;

214 215
	lockdep_assert_held(&htt->tx_lock);

216
	ath10k_dbg(ar, ATH10K_DBG_HTT, "htt tx free msdu_id %hu\n", msdu_id);
M
Michal Kazior 已提交
217 218

	idr_remove(&htt->pending_tx, msdu_id);
219 220
}

221
static void ath10k_htt_tx_free_cont_txbuf_32(struct ath10k_htt *htt)
222 223 224 225
{
	struct ath10k *ar = htt->ar;
	size_t size;

226
	if (!htt->txbuf.vaddr_txbuff_32)
227 228
		return;

229 230 231 232
	size = htt->txbuf.size;
	dma_free_coherent(ar->dev, size, htt->txbuf.vaddr_txbuff_32,
			  htt->txbuf.paddr);
	htt->txbuf.vaddr_txbuff_32 = NULL;
233 234
}

235
static int ath10k_htt_tx_alloc_cont_txbuf_32(struct ath10k_htt *htt)
236 237 238 239
{
	struct ath10k *ar = htt->ar;
	size_t size;

240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
	size = htt->max_num_pending_tx *
			sizeof(struct ath10k_htt_txbuf_32);

	htt->txbuf.vaddr_txbuff_32 = dma_alloc_coherent(ar->dev, size,
							&htt->txbuf.paddr,
							GFP_KERNEL);
	if (!htt->txbuf.vaddr_txbuff_32)
		return -ENOMEM;

	htt->txbuf.size = size;

	return 0;
}

static void ath10k_htt_tx_free_cont_txbuf_64(struct ath10k_htt *htt)
{
	struct ath10k *ar = htt->ar;
	size_t size;

	if (!htt->txbuf.vaddr_txbuff_64)
		return;

	size = htt->txbuf.size;
	dma_free_coherent(ar->dev, size, htt->txbuf.vaddr_txbuff_64,
			  htt->txbuf.paddr);
	htt->txbuf.vaddr_txbuff_64 = NULL;
}

static int ath10k_htt_tx_alloc_cont_txbuf_64(struct ath10k_htt *htt)
{
	struct ath10k *ar = htt->ar;
	size_t size;

	size = htt->max_num_pending_tx *
			sizeof(struct ath10k_htt_txbuf_64);

	htt->txbuf.vaddr_txbuff_64 = dma_alloc_coherent(ar->dev, size,
							&htt->txbuf.paddr,
							GFP_KERNEL);
	if (!htt->txbuf.vaddr_txbuff_64)
280 281
		return -ENOMEM;

282 283
	htt->txbuf.size = size;

284 285 286
	return 0;
}

287
static void ath10k_htt_tx_free_cont_frag_desc_32(struct ath10k_htt *htt)
288 289 290
{
	size_t size;

291
	if (!htt->frag_desc.vaddr_desc_32)
292 293
		return;

294 295
	size = htt->max_num_pending_tx *
			sizeof(struct htt_msdu_ext_desc);
296 297 298

	dma_free_coherent(htt->ar->dev,
			  size,
299
			  htt->frag_desc.vaddr_desc_32,
300
			  htt->frag_desc.paddr);
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342

	htt->frag_desc.vaddr_desc_32 = NULL;
}

static int ath10k_htt_tx_alloc_cont_frag_desc_32(struct ath10k_htt *htt)
{
	struct ath10k *ar = htt->ar;
	size_t size;

	if (!ar->hw_params.continuous_frag_desc)
		return 0;

	size = htt->max_num_pending_tx *
			sizeof(struct htt_msdu_ext_desc);
	htt->frag_desc.vaddr_desc_32 = dma_alloc_coherent(ar->dev, size,
							  &htt->frag_desc.paddr,
							  GFP_KERNEL);
	if (!htt->frag_desc.vaddr_desc_32) {
		ath10k_err(ar, "failed to alloc fragment desc memory\n");
		return -ENOMEM;
	}
	htt->frag_desc.size = size;

	return 0;
}

static void ath10k_htt_tx_free_cont_frag_desc_64(struct ath10k_htt *htt)
{
	size_t size;

	if (!htt->frag_desc.vaddr_desc_64)
		return;

	size = htt->max_num_pending_tx *
			sizeof(struct htt_msdu_ext_desc_64);

	dma_free_coherent(htt->ar->dev,
			  size,
			  htt->frag_desc.vaddr_desc_64,
			  htt->frag_desc.paddr);

	htt->frag_desc.vaddr_desc_64 = NULL;
343 344
}

345
static int ath10k_htt_tx_alloc_cont_frag_desc_64(struct ath10k_htt *htt)
346 347 348 349 350 351 352
{
	struct ath10k *ar = htt->ar;
	size_t size;

	if (!ar->hw_params.continuous_frag_desc)
		return 0;

353 354 355 356 357 358 359 360
	size = htt->max_num_pending_tx *
			sizeof(struct htt_msdu_ext_desc_64);

	htt->frag_desc.vaddr_desc_64 = dma_alloc_coherent(ar->dev, size,
							  &htt->frag_desc.paddr,
							  GFP_KERNEL);
	if (!htt->frag_desc.vaddr_desc_64) {
		ath10k_err(ar, "failed to alloc fragment desc memory\n");
361
		return -ENOMEM;
362 363
	}
	htt->frag_desc.size = size;
364 365 366 367

	return 0;
}

368 369 370 371 372
static void ath10k_htt_tx_free_txq(struct ath10k_htt *htt)
{
	struct ath10k *ar = htt->ar;
	size_t size;

373 374
	if (!test_bit(ATH10K_FW_FEATURE_PEER_FLOW_CONTROL,
		      ar->running_fw->fw_file.fw_features))
375 376 377 378 379 380 381 382 383 384 385 386 387 388
		return;

	size = sizeof(*htt->tx_q_state.vaddr);

	dma_unmap_single(ar->dev, htt->tx_q_state.paddr, size, DMA_TO_DEVICE);
	kfree(htt->tx_q_state.vaddr);
}

static int ath10k_htt_tx_alloc_txq(struct ath10k_htt *htt)
{
	struct ath10k *ar = htt->ar;
	size_t size;
	int ret;

389 390
	if (!test_bit(ATH10K_FW_FEATURE_PEER_FLOW_CONTROL,
		      ar->running_fw->fw_file.fw_features))
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413
		return 0;

	htt->tx_q_state.num_peers = HTT_TX_Q_STATE_NUM_PEERS;
	htt->tx_q_state.num_tids = HTT_TX_Q_STATE_NUM_TIDS;
	htt->tx_q_state.type = HTT_Q_DEPTH_TYPE_BYTES;

	size = sizeof(*htt->tx_q_state.vaddr);
	htt->tx_q_state.vaddr = kzalloc(size, GFP_KERNEL);
	if (!htt->tx_q_state.vaddr)
		return -ENOMEM;

	htt->tx_q_state.paddr = dma_map_single(ar->dev, htt->tx_q_state.vaddr,
					       size, DMA_TO_DEVICE);
	ret = dma_mapping_error(ar->dev, htt->tx_q_state.paddr);
	if (ret) {
		ath10k_warn(ar, "failed to dma map tx_q_state: %d\n", ret);
		kfree(htt->tx_q_state.vaddr);
		return -EIO;
	}

	return 0;
}

414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429
static void ath10k_htt_tx_free_txdone_fifo(struct ath10k_htt *htt)
{
	WARN_ON(!kfifo_is_empty(&htt->txdone_fifo));
	kfifo_free(&htt->txdone_fifo);
}

static int ath10k_htt_tx_alloc_txdone_fifo(struct ath10k_htt *htt)
{
	int ret;
	size_t size;

	size = roundup_pow_of_two(htt->max_num_pending_tx);
	ret = kfifo_alloc(&htt->txdone_fifo, size, GFP_KERNEL);
	return ret;
}

430
static int ath10k_htt_tx_alloc_buf(struct ath10k_htt *htt)
431
{
432
	struct ath10k *ar = htt->ar;
433
	int ret;
434

435
	ret = ath10k_htt_alloc_txbuff(htt);
436 437
	if (ret) {
		ath10k_err(ar, "failed to alloc cont tx buffer: %d\n", ret);
438
		return ret;
439 440
	}

441
	ret = ath10k_htt_alloc_frag_desc(htt);
442 443
	if (ret) {
		ath10k_err(ar, "failed to alloc cont frag desc: %d\n", ret);
444
		goto free_txbuf;
445 446
	}

447 448 449 450 451 452
	ret = ath10k_htt_tx_alloc_txq(htt);
	if (ret) {
		ath10k_err(ar, "failed to alloc txq: %d\n", ret);
		goto free_frag_desc;
	}

453
	ret = ath10k_htt_tx_alloc_txdone_fifo(htt);
454 455 456 457 458
	if (ret) {
		ath10k_err(ar, "failed to alloc txdone fifo: %d\n", ret);
		goto free_txq;
	}

459
	return 0;
460

461 462 463
free_txq:
	ath10k_htt_tx_free_txq(htt);

464
free_frag_desc:
465
	ath10k_htt_free_frag_desc(htt);
466

467
free_txbuf:
468
	ath10k_htt_free_txbuff(htt);
469

470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486
	return ret;
}

int ath10k_htt_tx_start(struct ath10k_htt *htt)
{
	struct ath10k *ar = htt->ar;
	int ret;

	ath10k_dbg(ar, ATH10K_DBG_BOOT, "htt tx max num pending tx %d\n",
		   htt->max_num_pending_tx);

	spin_lock_init(&htt->tx_lock);
	idr_init(&htt->pending_tx);

	if (htt->tx_mem_allocated)
		return 0;

487
	if (ar->bus_param.dev_type == ATH10K_DEV_TYPE_HL)
488 489
		return 0;

490 491 492 493 494 495 496 497
	ret = ath10k_htt_tx_alloc_buf(htt);
	if (ret)
		goto free_idr_pending_tx;

	htt->tx_mem_allocated = true;

	return 0;

498 499
free_idr_pending_tx:
	idr_destroy(&htt->pending_tx);
500

501
	return ret;
502 503
}

M
Michal Kazior 已提交
504
static int ath10k_htt_tx_clean_up_pending(int msdu_id, void *skb, void *ctx)
505
{
M
Michal Kazior 已提交
506 507
	struct ath10k *ar = ctx;
	struct ath10k_htt *htt = &ar->htt;
508
	struct htt_tx_done tx_done = {0};
509

M
Michal Kazior 已提交
510
	ath10k_dbg(ar, ATH10K_DBG_HTT, "force cleanup msdu_id %hu\n", msdu_id);
511

M
Michal Kazior 已提交
512
	tx_done.msdu_id = msdu_id;
513
	tx_done.status = HTT_TX_COMPL_STATE_DISCARD;
514

M
Michal Kazior 已提交
515 516 517
	ath10k_txrx_tx_unref(htt, &tx_done);

	return 0;
518 519
}

520
void ath10k_htt_tx_destroy(struct ath10k_htt *htt)
521
{
522 523
	if (!htt->tx_mem_allocated)
		return;
524

525
	ath10k_htt_free_txbuff(htt);
526
	ath10k_htt_tx_free_txq(htt);
527
	ath10k_htt_free_frag_desc(htt);
528
	ath10k_htt_tx_free_txdone_fifo(htt);
529 530 531 532 533 534 535 536 537 538 539 540 541
	htt->tx_mem_allocated = false;
}

void ath10k_htt_tx_stop(struct ath10k_htt *htt)
{
	idr_for_each(&htt->pending_tx, ath10k_htt_tx_clean_up_pending, htt->ar);
	idr_destroy(&htt->pending_tx);
}

void ath10k_htt_tx_free(struct ath10k_htt *htt)
{
	ath10k_htt_tx_stop(htt);
	ath10k_htt_tx_destroy(htt);
542 543 544 545
}

void ath10k_htt_htc_tx_complete(struct ath10k *ar, struct sk_buff *skb)
{
546
	dev_kfree_skb_any(skb);
547 548
}

549 550 551 552 553 554
void ath10k_htt_hif_tx_complete(struct ath10k *ar, struct sk_buff *skb)
{
	dev_kfree_skb_any(skb);
}
EXPORT_SYMBOL(ath10k_htt_hif_tx_complete);

555 556
int ath10k_htt_h2t_ver_req_msg(struct ath10k_htt *htt)
{
557
	struct ath10k *ar = htt->ar;
558 559 560 561 562 563 564 565
	struct sk_buff *skb;
	struct htt_cmd *cmd;
	int len = 0;
	int ret;

	len += sizeof(cmd->hdr);
	len += sizeof(cmd->ver_req);

566
	skb = ath10k_htc_alloc_skb(ar, len);
567 568 569 570 571 572 573
	if (!skb)
		return -ENOMEM;

	skb_put(skb, len);
	cmd = (struct htt_cmd *)skb->data;
	cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_VERSION_REQ;

574
	ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb);
575 576 577 578 579 580 581 582
	if (ret) {
		dev_kfree_skb_any(skb);
		return ret;
	}

	return 0;
}

583 584
int ath10k_htt_h2t_stats_req(struct ath10k_htt *htt, u32 mask, u32 reset_mask,
			     u64 cookie)
585
{
586
	struct ath10k *ar = htt->ar;
587 588 589 590 591 592 593 594
	struct htt_stats_req *req;
	struct sk_buff *skb;
	struct htt_cmd *cmd;
	int len = 0, ret;

	len += sizeof(cmd->hdr);
	len += sizeof(cmd->stats_req);

595
	skb = ath10k_htc_alloc_skb(ar, len);
596 597 598 599 600 601 602 603 604 605 606
	if (!skb)
		return -ENOMEM;

	skb_put(skb, len);
	cmd = (struct htt_cmd *)skb->data;
	cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_STATS_REQ;

	req = &cmd->stats_req;

	memset(req, 0, sizeof(*req));

607
	/* currently we support only max 24 bit masks so no need to worry
608 609
	 * about endian support
	 */
610
	memcpy(req->upload_types, &mask, 3);
611
	memcpy(req->reset_types, &reset_mask, 3);
612 613 614 615 616 617
	req->stat_type = HTT_STATS_REQ_CFG_STAT_TYPE_INVALID;
	req->cookie_lsb = cpu_to_le32(cookie & 0xffffffff);
	req->cookie_msb = cpu_to_le32((cookie & 0xffffffff00000000ULL) >> 32);

	ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb);
	if (ret) {
618 619
		ath10k_warn(ar, "failed to send htt type stats request: %d",
			    ret);
620 621 622 623 624 625 626
		dev_kfree_skb_any(skb);
		return ret;
	}

	return 0;
}

627
static int ath10k_htt_send_frag_desc_bank_cfg_32(struct ath10k_htt *htt)
628 629 630 631
{
	struct ath10k *ar = htt->ar;
	struct sk_buff *skb;
	struct htt_cmd *cmd;
632
	struct htt_frag_desc_bank_cfg32 *cfg;
633
	int ret, size;
634
	u8 info;
635 636 637 638 639 640 641 642 643

	if (!ar->hw_params.continuous_frag_desc)
		return 0;

	if (!htt->frag_desc.paddr) {
		ath10k_warn(ar, "invalid frag desc memory\n");
		return -EINVAL;
	}

644
	size = sizeof(cmd->hdr) + sizeof(cmd->frag_desc_bank_cfg32);
645 646 647 648 649 650 651
	skb = ath10k_htc_alloc_skb(ar, size);
	if (!skb)
		return -ENOMEM;

	skb_put(skb, size);
	cmd = (struct htt_cmd *)skb->data;
	cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_FRAG_DESC_BANK_CFG;
652 653 654 655 656

	info = 0;
	info |= SM(htt->tx_q_state.type,
		   HTT_FRAG_DESC_BANK_CFG_INFO_Q_STATE_DEPTH_TYPE);

657 658
	if (test_bit(ATH10K_FW_FEATURE_PEER_FLOW_CONTROL,
		     ar->running_fw->fw_file.fw_features))
659 660
		info |= HTT_FRAG_DESC_BANK_CFG_INFO_Q_STATE_VALID;

661
	cfg = &cmd->frag_desc_bank_cfg32;
662 663 664 665 666 667 668 669 670 671 672 673 674 675 676
	cfg->info = info;
	cfg->num_banks = 1;
	cfg->desc_size = sizeof(struct htt_msdu_ext_desc);
	cfg->bank_base_addrs[0] = __cpu_to_le32(htt->frag_desc.paddr);
	cfg->bank_id[0].bank_min_id = 0;
	cfg->bank_id[0].bank_max_id = __cpu_to_le16(htt->max_num_pending_tx -
						    1);

	cfg->q_state.paddr = cpu_to_le32(htt->tx_q_state.paddr);
	cfg->q_state.num_peers = cpu_to_le16(htt->tx_q_state.num_peers);
	cfg->q_state.num_tids = cpu_to_le16(htt->tx_q_state.num_tids);
	cfg->q_state.record_size = HTT_TX_Q_STATE_ENTRY_SIZE;
	cfg->q_state.record_multiplier = HTT_TX_Q_STATE_ENTRY_MULTIPLIER;

	ath10k_dbg(ar, ATH10K_DBG_HTT, "htt frag desc bank cmd\n");
677 678 679 680 681 682 683 684 685 686 687 688

	ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb);
	if (ret) {
		ath10k_warn(ar, "failed to send frag desc bank cfg request: %d\n",
			    ret);
		dev_kfree_skb_any(skb);
		return ret;
	}

	return 0;
}

689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750
static int ath10k_htt_send_frag_desc_bank_cfg_64(struct ath10k_htt *htt)
{
	struct ath10k *ar = htt->ar;
	struct sk_buff *skb;
	struct htt_cmd *cmd;
	struct htt_frag_desc_bank_cfg64 *cfg;
	int ret, size;
	u8 info;

	if (!ar->hw_params.continuous_frag_desc)
		return 0;

	if (!htt->frag_desc.paddr) {
		ath10k_warn(ar, "invalid frag desc memory\n");
		return -EINVAL;
	}

	size = sizeof(cmd->hdr) + sizeof(cmd->frag_desc_bank_cfg64);
	skb = ath10k_htc_alloc_skb(ar, size);
	if (!skb)
		return -ENOMEM;

	skb_put(skb, size);
	cmd = (struct htt_cmd *)skb->data;
	cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_FRAG_DESC_BANK_CFG;

	info = 0;
	info |= SM(htt->tx_q_state.type,
		   HTT_FRAG_DESC_BANK_CFG_INFO_Q_STATE_DEPTH_TYPE);

	if (test_bit(ATH10K_FW_FEATURE_PEER_FLOW_CONTROL,
		     ar->running_fw->fw_file.fw_features))
		info |= HTT_FRAG_DESC_BANK_CFG_INFO_Q_STATE_VALID;

	cfg = &cmd->frag_desc_bank_cfg64;
	cfg->info = info;
	cfg->num_banks = 1;
	cfg->desc_size = sizeof(struct htt_msdu_ext_desc_64);
	cfg->bank_base_addrs[0] =  __cpu_to_le64(htt->frag_desc.paddr);
	cfg->bank_id[0].bank_min_id = 0;
	cfg->bank_id[0].bank_max_id = __cpu_to_le16(htt->max_num_pending_tx -
						    1);

	cfg->q_state.paddr = cpu_to_le32(htt->tx_q_state.paddr);
	cfg->q_state.num_peers = cpu_to_le16(htt->tx_q_state.num_peers);
	cfg->q_state.num_tids = cpu_to_le16(htt->tx_q_state.num_tids);
	cfg->q_state.record_size = HTT_TX_Q_STATE_ENTRY_SIZE;
	cfg->q_state.record_multiplier = HTT_TX_Q_STATE_ENTRY_MULTIPLIER;

	ath10k_dbg(ar, ATH10K_DBG_HTT, "htt frag desc bank cmd\n");

	ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb);
	if (ret) {
		ath10k_warn(ar, "failed to send frag desc bank cfg request: %d\n",
			    ret);
		dev_kfree_skb_any(skb);
		return ret;
	}

	return 0;
}

751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789
static void ath10k_htt_fill_rx_desc_offset_32(void *rx_ring)
{
	struct htt_rx_ring_setup_ring32 *ring =
			(struct htt_rx_ring_setup_ring32 *)rx_ring;

#define desc_offset(x) (offsetof(struct htt_rx_desc, x) / 4)
	ring->mac80211_hdr_offset = __cpu_to_le16(desc_offset(rx_hdr_status));
	ring->msdu_payload_offset = __cpu_to_le16(desc_offset(msdu_payload));
	ring->ppdu_start_offset = __cpu_to_le16(desc_offset(ppdu_start));
	ring->ppdu_end_offset = __cpu_to_le16(desc_offset(ppdu_end));
	ring->mpdu_start_offset = __cpu_to_le16(desc_offset(mpdu_start));
	ring->mpdu_end_offset = __cpu_to_le16(desc_offset(mpdu_end));
	ring->msdu_start_offset = __cpu_to_le16(desc_offset(msdu_start));
	ring->msdu_end_offset = __cpu_to_le16(desc_offset(msdu_end));
	ring->rx_attention_offset = __cpu_to_le16(desc_offset(attention));
	ring->frag_info_offset = __cpu_to_le16(desc_offset(frag_info));
#undef desc_offset
}

static void ath10k_htt_fill_rx_desc_offset_64(void *rx_ring)
{
	struct htt_rx_ring_setup_ring64 *ring =
			(struct htt_rx_ring_setup_ring64 *)rx_ring;

#define desc_offset(x) (offsetof(struct htt_rx_desc, x) / 4)
	ring->mac80211_hdr_offset = __cpu_to_le16(desc_offset(rx_hdr_status));
	ring->msdu_payload_offset = __cpu_to_le16(desc_offset(msdu_payload));
	ring->ppdu_start_offset = __cpu_to_le16(desc_offset(ppdu_start));
	ring->ppdu_end_offset = __cpu_to_le16(desc_offset(ppdu_end));
	ring->mpdu_start_offset = __cpu_to_le16(desc_offset(mpdu_start));
	ring->mpdu_end_offset = __cpu_to_le16(desc_offset(mpdu_end));
	ring->msdu_start_offset = __cpu_to_le16(desc_offset(msdu_start));
	ring->msdu_end_offset = __cpu_to_le16(desc_offset(msdu_end));
	ring->rx_attention_offset = __cpu_to_le16(desc_offset(attention));
	ring->frag_info_offset = __cpu_to_le16(desc_offset(frag_info));
#undef desc_offset
}

static int ath10k_htt_send_rx_ring_cfg_32(struct ath10k_htt *htt)
790
{
791
	struct ath10k *ar = htt->ar;
792 793
	struct sk_buff *skb;
	struct htt_cmd *cmd;
794
	struct htt_rx_ring_setup_ring32 *ring;
795 796 797 798 799 800 801 802 803 804 805 806 807
	const int num_rx_ring = 1;
	u16 flags;
	u32 fw_idx;
	int len;
	int ret;

	/*
	 * the HW expects the buffer to be an integral number of 4-byte
	 * "words"
	 */
	BUILD_BUG_ON(!IS_ALIGNED(HTT_RX_BUF_SIZE, 4));
	BUILD_BUG_ON((HTT_RX_BUF_SIZE & HTT_MAX_CACHE_LINE_SIZE_MASK) != 0);

808
	len = sizeof(cmd->hdr) + sizeof(cmd->rx_setup_32.hdr)
809
	    + (sizeof(*ring) * num_rx_ring);
810
	skb = ath10k_htc_alloc_skb(ar, len);
811 812 813 814 815 816
	if (!skb)
		return -ENOMEM;

	skb_put(skb, len);

	cmd = (struct htt_cmd *)skb->data;
817
	ring = &cmd->rx_setup_32.rings[0];
818 819

	cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_RX_RING_CFG;
820
	cmd->rx_setup_32.hdr.num_rings = 1;
821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850

	/* FIXME: do we need all of this? */
	flags = 0;
	flags |= HTT_RX_RING_FLAGS_MAC80211_HDR;
	flags |= HTT_RX_RING_FLAGS_MSDU_PAYLOAD;
	flags |= HTT_RX_RING_FLAGS_PPDU_START;
	flags |= HTT_RX_RING_FLAGS_PPDU_END;
	flags |= HTT_RX_RING_FLAGS_MPDU_START;
	flags |= HTT_RX_RING_FLAGS_MPDU_END;
	flags |= HTT_RX_RING_FLAGS_MSDU_START;
	flags |= HTT_RX_RING_FLAGS_MSDU_END;
	flags |= HTT_RX_RING_FLAGS_RX_ATTENTION;
	flags |= HTT_RX_RING_FLAGS_FRAG_INFO;
	flags |= HTT_RX_RING_FLAGS_UNICAST_RX;
	flags |= HTT_RX_RING_FLAGS_MULTICAST_RX;
	flags |= HTT_RX_RING_FLAGS_CTRL_RX;
	flags |= HTT_RX_RING_FLAGS_MGMT_RX;
	flags |= HTT_RX_RING_FLAGS_NULL_RX;
	flags |= HTT_RX_RING_FLAGS_PHY_DATA_RX;

	fw_idx = __le32_to_cpu(*htt->rx_ring.alloc_idx.vaddr);

	ring->fw_idx_shadow_reg_paddr =
		__cpu_to_le32(htt->rx_ring.alloc_idx.paddr);
	ring->rx_ring_base_paddr = __cpu_to_le32(htt->rx_ring.base_paddr);
	ring->rx_ring_len = __cpu_to_le16(htt->rx_ring.size);
	ring->rx_ring_bufsize = __cpu_to_le16(HTT_RX_BUF_SIZE);
	ring->flags = __cpu_to_le16(flags);
	ring->fw_idx_init_val = __cpu_to_le16(fw_idx);

851 852 853 854 855 856
	ath10k_htt_fill_rx_desc_offset_32(ring);
	ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb);
	if (ret) {
		dev_kfree_skb_any(skb);
		return ret;
	}
857

858 859
	return 0;
}
860

861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911
static int ath10k_htt_send_rx_ring_cfg_64(struct ath10k_htt *htt)
{
	struct ath10k *ar = htt->ar;
	struct sk_buff *skb;
	struct htt_cmd *cmd;
	struct htt_rx_ring_setup_ring64 *ring;
	const int num_rx_ring = 1;
	u16 flags;
	u32 fw_idx;
	int len;
	int ret;

	/* HW expects the buffer to be an integral number of 4-byte
	 * "words"
	 */
	BUILD_BUG_ON(!IS_ALIGNED(HTT_RX_BUF_SIZE, 4));
	BUILD_BUG_ON((HTT_RX_BUF_SIZE & HTT_MAX_CACHE_LINE_SIZE_MASK) != 0);

	len = sizeof(cmd->hdr) + sizeof(cmd->rx_setup_64.hdr)
	    + (sizeof(*ring) * num_rx_ring);
	skb = ath10k_htc_alloc_skb(ar, len);
	if (!skb)
		return -ENOMEM;

	skb_put(skb, len);

	cmd = (struct htt_cmd *)skb->data;
	ring = &cmd->rx_setup_64.rings[0];

	cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_RX_RING_CFG;
	cmd->rx_setup_64.hdr.num_rings = 1;

	flags = 0;
	flags |= HTT_RX_RING_FLAGS_MAC80211_HDR;
	flags |= HTT_RX_RING_FLAGS_MSDU_PAYLOAD;
	flags |= HTT_RX_RING_FLAGS_PPDU_START;
	flags |= HTT_RX_RING_FLAGS_PPDU_END;
	flags |= HTT_RX_RING_FLAGS_MPDU_START;
	flags |= HTT_RX_RING_FLAGS_MPDU_END;
	flags |= HTT_RX_RING_FLAGS_MSDU_START;
	flags |= HTT_RX_RING_FLAGS_MSDU_END;
	flags |= HTT_RX_RING_FLAGS_RX_ATTENTION;
	flags |= HTT_RX_RING_FLAGS_FRAG_INFO;
	flags |= HTT_RX_RING_FLAGS_UNICAST_RX;
	flags |= HTT_RX_RING_FLAGS_MULTICAST_RX;
	flags |= HTT_RX_RING_FLAGS_CTRL_RX;
	flags |= HTT_RX_RING_FLAGS_MGMT_RX;
	flags |= HTT_RX_RING_FLAGS_NULL_RX;
	flags |= HTT_RX_RING_FLAGS_PHY_DATA_RX;

	fw_idx = __le32_to_cpu(*htt->rx_ring.alloc_idx.vaddr);
912

913 914 915 916 917 918 919 920
	ring->fw_idx_shadow_reg_paddr = __cpu_to_le64(htt->rx_ring.alloc_idx.paddr);
	ring->rx_ring_base_paddr = __cpu_to_le64(htt->rx_ring.base_paddr);
	ring->rx_ring_len = __cpu_to_le16(htt->rx_ring.size);
	ring->rx_ring_bufsize = __cpu_to_le16(HTT_RX_BUF_SIZE);
	ring->flags = __cpu_to_le16(flags);
	ring->fw_idx_init_val = __cpu_to_le16(fw_idx);

	ath10k_htt_fill_rx_desc_offset_64(ring);
921
	ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb);
922 923 924 925 926 927 928 929
	if (ret) {
		dev_kfree_skb_any(skb);
		return ret;
	}

	return 0;
}

930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980
static int ath10k_htt_send_rx_ring_cfg_hl(struct ath10k_htt *htt)
{
	struct ath10k *ar = htt->ar;
	struct sk_buff *skb;
	struct htt_cmd *cmd;
	struct htt_rx_ring_setup_ring32 *ring;
	const int num_rx_ring = 1;
	u16 flags;
	int len;
	int ret;

	/*
	 * the HW expects the buffer to be an integral number of 4-byte
	 * "words"
	 */
	BUILD_BUG_ON(!IS_ALIGNED(HTT_RX_BUF_SIZE, 4));
	BUILD_BUG_ON((HTT_RX_BUF_SIZE & HTT_MAX_CACHE_LINE_SIZE_MASK) != 0);

	len = sizeof(cmd->hdr) + sizeof(cmd->rx_setup_32.hdr)
	    + (sizeof(*ring) * num_rx_ring);
	skb = ath10k_htc_alloc_skb(ar, len);
	if (!skb)
		return -ENOMEM;

	skb_put(skb, len);

	cmd = (struct htt_cmd *)skb->data;
	ring = &cmd->rx_setup_32.rings[0];

	cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_RX_RING_CFG;
	cmd->rx_setup_32.hdr.num_rings = 1;

	flags = 0;
	flags |= HTT_RX_RING_FLAGS_MSDU_PAYLOAD;
	flags |= HTT_RX_RING_FLAGS_UNICAST_RX;
	flags |= HTT_RX_RING_FLAGS_MULTICAST_RX;

	memset(ring, 0, sizeof(*ring));
	ring->rx_ring_len = __cpu_to_le16(HTT_RX_RING_SIZE_MIN);
	ring->rx_ring_bufsize = __cpu_to_le16(HTT_RX_BUF_SIZE);
	ring->flags = __cpu_to_le16(flags);

	ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb);
	if (ret) {
		dev_kfree_skb_any(skb);
		return ret;
	}

	return 0;
}

981 982 983
static int ath10k_htt_h2t_aggr_cfg_msg_32(struct ath10k_htt *htt,
					  u8 max_subfrms_ampdu,
					  u8 max_subfrms_amsdu)
984
{
985
	struct ath10k *ar = htt->ar;
986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002
	struct htt_aggr_conf *aggr_conf;
	struct sk_buff *skb;
	struct htt_cmd *cmd;
	int len;
	int ret;

	/* Firmware defaults are: amsdu = 3 and ampdu = 64 */

	if (max_subfrms_ampdu == 0 || max_subfrms_ampdu > 64)
		return -EINVAL;

	if (max_subfrms_amsdu == 0 || max_subfrms_amsdu > 31)
		return -EINVAL;

	len = sizeof(cmd->hdr);
	len += sizeof(cmd->aggr_conf);

1003
	skb = ath10k_htc_alloc_skb(ar, len);
1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014
	if (!skb)
		return -ENOMEM;

	skb_put(skb, len);
	cmd = (struct htt_cmd *)skb->data;
	cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_AGGR_CFG;

	aggr_conf = &cmd->aggr_conf;
	aggr_conf->max_num_ampdu_subframes = max_subfrms_ampdu;
	aggr_conf->max_num_amsdu_subframes = max_subfrms_amsdu;

1015
	ath10k_dbg(ar, ATH10K_DBG_HTT, "htt h2t aggr cfg msg amsdu %d ampdu %d",
1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027
		   aggr_conf->max_num_amsdu_subframes,
		   aggr_conf->max_num_ampdu_subframes);

	ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb);
	if (ret) {
		dev_kfree_skb_any(skb);
		return ret;
	}

	return 0;
}

1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074
static int ath10k_htt_h2t_aggr_cfg_msg_v2(struct ath10k_htt *htt,
					  u8 max_subfrms_ampdu,
					  u8 max_subfrms_amsdu)
{
	struct ath10k *ar = htt->ar;
	struct htt_aggr_conf_v2 *aggr_conf;
	struct sk_buff *skb;
	struct htt_cmd *cmd;
	int len;
	int ret;

	/* Firmware defaults are: amsdu = 3 and ampdu = 64 */

	if (max_subfrms_ampdu == 0 || max_subfrms_ampdu > 64)
		return -EINVAL;

	if (max_subfrms_amsdu == 0 || max_subfrms_amsdu > 31)
		return -EINVAL;

	len = sizeof(cmd->hdr);
	len += sizeof(cmd->aggr_conf_v2);

	skb = ath10k_htc_alloc_skb(ar, len);
	if (!skb)
		return -ENOMEM;

	skb_put(skb, len);
	cmd = (struct htt_cmd *)skb->data;
	cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_AGGR_CFG;

	aggr_conf = &cmd->aggr_conf_v2;
	aggr_conf->max_num_ampdu_subframes = max_subfrms_ampdu;
	aggr_conf->max_num_amsdu_subframes = max_subfrms_amsdu;

	ath10k_dbg(ar, ATH10K_DBG_HTT, "htt h2t aggr cfg msg amsdu %d ampdu %d",
		   aggr_conf->max_num_amsdu_subframes,
		   aggr_conf->max_num_ampdu_subframes);

	ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb);
	if (ret) {
		dev_kfree_skb_any(skb);
		return ret;
	}

	return 0;
}

1075 1076 1077 1078 1079 1080 1081 1082
int ath10k_htt_tx_fetch_resp(struct ath10k *ar,
			     __le32 token,
			     __le16 fetch_seq_num,
			     struct htt_tx_fetch_record *records,
			     size_t num_records)
{
	struct sk_buff *skb;
	struct htt_cmd *cmd;
M
Michal Kazior 已提交
1083
	const u16 resp_id = 0;
1084 1085 1086
	int len = 0;
	int ret;

M
Michal Kazior 已提交
1087 1088 1089 1090
	/* Response IDs are echo-ed back only for host driver convienence
	 * purposes. They aren't used for anything in the driver yet so use 0.
	 */

1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112
	len += sizeof(cmd->hdr);
	len += sizeof(cmd->tx_fetch_resp);
	len += sizeof(cmd->tx_fetch_resp.records[0]) * num_records;

	skb = ath10k_htc_alloc_skb(ar, len);
	if (!skb)
		return -ENOMEM;

	skb_put(skb, len);
	cmd = (struct htt_cmd *)skb->data;
	cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_TX_FETCH_RESP;
	cmd->tx_fetch_resp.resp_id = cpu_to_le16(resp_id);
	cmd->tx_fetch_resp.fetch_seq_num = fetch_seq_num;
	cmd->tx_fetch_resp.num_records = cpu_to_le16(num_records);
	cmd->tx_fetch_resp.token = token;

	memcpy(cmd->tx_fetch_resp.records, records,
	       sizeof(records[0]) * num_records);

	ret = ath10k_htc_send(&ar->htc, ar->htt.eid, skb);
	if (ret) {
		ath10k_warn(ar, "failed to submit htc command: %d\n", ret);
M
Michal Kazior 已提交
1113
		goto err_free_skb;
1114 1115 1116 1117 1118 1119 1120 1121 1122 1123
	}

	return 0;

err_free_skb:
	dev_kfree_skb_any(skb);

	return ret;
}

1124 1125 1126 1127
static u8 ath10k_htt_tx_get_vdev_id(struct ath10k *ar, struct sk_buff *skb)
{
	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
	struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
1128
	struct ath10k_vif *arvif;
1129

1130
	if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
1131
		return ar->scan.vdev_id;
1132 1133
	} else if (cb->vif) {
		arvif = (void *)cb->vif->drv_priv;
1134
		return arvif->vdev_id;
1135
	} else if (ar->monitor_started) {
1136
		return ar->monitor_vdev_id;
1137
	} else {
1138
		return 0;
1139
	}
1140 1141 1142 1143 1144 1145 1146 1147 1148 1149
}

static u8 ath10k_htt_tx_get_tid(struct sk_buff *skb, bool is_eth)
{
	struct ieee80211_hdr *hdr = (void *)skb->data;
	struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);

	if (!is_eth && ieee80211_is_mgmt(hdr->frame_control))
		return HTT_DATA_TX_EXT_TID_MGMT;
	else if (cb->flags & ATH10K_SKB_F_QOS)
1150
		return skb->priority & IEEE80211_QOS_CTL_TID_MASK;
1151 1152 1153 1154
	else
		return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
}

1155 1156
int ath10k_htt_mgmt_tx(struct ath10k_htt *htt, struct sk_buff *msdu)
{
1157 1158
	struct ath10k *ar = htt->ar;
	struct device *dev = ar->dev;
1159 1160
	struct sk_buff *txdesc = NULL;
	struct htt_cmd *cmd;
1161
	struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(msdu);
1162
	u8 vdev_id = ath10k_htt_tx_get_vdev_id(ar, msdu);
1163 1164 1165
	int len = 0;
	int msdu_id = -1;
	int res;
1166
	const u8 *peer_addr;
1167
	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)msdu->data;
1168 1169 1170 1171

	len += sizeof(cmd->hdr);
	len += sizeof(cmd->mgmt_tx);

M
Michal Kazior 已提交
1172
	res = ath10k_htt_tx_alloc_msdu_id(htt, msdu);
K
Kalle Valo 已提交
1173
	if (res < 0)
1174
		goto err;
K
Kalle Valo 已提交
1175

M
Michal Kazior 已提交
1176
	msdu_id = res;
1177

1178 1179 1180 1181
	if ((ieee80211_is_action(hdr->frame_control) ||
	     ieee80211_is_deauth(hdr->frame_control) ||
	     ieee80211_is_disassoc(hdr->frame_control)) &&
	     ieee80211_has_protected(hdr->frame_control)) {
1182 1183 1184 1185 1186 1187 1188 1189 1190 1191
		peer_addr = hdr->addr1;
		if (is_multicast_ether_addr(peer_addr)) {
			skb_put(msdu, sizeof(struct ieee80211_mmie_16));
		} else {
			if (skb_cb->ucast_cipher == WLAN_CIPHER_SUITE_GCMP ||
			    skb_cb->ucast_cipher == WLAN_CIPHER_SUITE_GCMP_256)
				skb_put(msdu, IEEE80211_GCMP_MIC_LEN);
			else
				skb_put(msdu, IEEE80211_CCMP_MIC_LEN);
		}
1192 1193
	}

1194
	txdesc = ath10k_htc_alloc_skb(ar, len);
M
Michal Kazior 已提交
1195 1196 1197 1198 1199
	if (!txdesc) {
		res = -ENOMEM;
		goto err_free_msdu_id;
	}

1200 1201 1202
	skb_cb->paddr = dma_map_single(dev, msdu->data, msdu->len,
				       DMA_TO_DEVICE);
	res = dma_mapping_error(dev, skb_cb->paddr);
1203 1204
	if (res) {
		res = -EIO;
M
Michal Kazior 已提交
1205
		goto err_free_txdesc;
1206
	}
1207 1208 1209

	skb_put(txdesc, len);
	cmd = (struct htt_cmd *)txdesc->data;
1210 1211
	memset(cmd, 0, len);

1212 1213 1214 1215 1216 1217 1218 1219
	cmd->hdr.msg_type         = HTT_H2T_MSG_TYPE_MGMT_TX;
	cmd->mgmt_tx.msdu_paddr = __cpu_to_le32(ATH10K_SKB_CB(msdu)->paddr);
	cmd->mgmt_tx.len        = __cpu_to_le32(msdu->len);
	cmd->mgmt_tx.desc_id    = __cpu_to_le32(msdu_id);
	cmd->mgmt_tx.vdev_id    = __cpu_to_le32(vdev_id);
	memcpy(cmd->mgmt_tx.hdr, msdu->data,
	       min_t(int, msdu->len, HTT_MGMT_FRM_HDR_DOWNLOAD_LEN));

1220
	res = ath10k_htc_send(&htt->ar->htc, htt->eid, txdesc);
1221
	if (res)
M
Michal Kazior 已提交
1222
		goto err_unmap_msdu;
1223 1224 1225

	return 0;

M
Michal Kazior 已提交
1226
err_unmap_msdu:
1227
	if (ar->bus_param.dev_type != ATH10K_DEV_TYPE_HL)
1228
		dma_unmap_single(dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE);
M
Michal Kazior 已提交
1229 1230 1231 1232 1233 1234 1235
err_free_txdesc:
	dev_kfree_skb_any(txdesc);
err_free_msdu_id:
	spin_lock_bh(&htt->tx_lock);
	ath10k_htt_tx_free_msdu_id(htt, msdu_id);
	spin_unlock_bh(&htt->tx_lock);
err:
1236 1237 1238
	return res;
}

1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249
#define HTT_TX_HL_NEEDED_HEADROOM \
	(unsigned int)(sizeof(struct htt_cmd_hdr) + \
	sizeof(struct htt_data_tx_desc) + \
	sizeof(struct ath10k_htc_hdr))

static int ath10k_htt_tx_hl(struct ath10k_htt *htt, enum ath10k_hw_txrx_mode txmode,
			    struct sk_buff *msdu)
{
	struct ath10k *ar = htt->ar;
	int res, data_len;
	struct htt_cmd_hdr *cmd_hdr;
1250
	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)msdu->data;
1251 1252 1253 1254 1255 1256 1257 1258
	struct htt_data_tx_desc *tx_desc;
	struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(msdu);
	struct sk_buff *tmp_skb;
	bool is_eth = (txmode == ATH10K_HW_TXRX_ETHERNET);
	u8 vdev_id = ath10k_htt_tx_get_vdev_id(ar, msdu);
	u8 tid = ath10k_htt_tx_get_tid(msdu, is_eth);
	u8 flags0 = 0;
	u16 flags1 = 0;
1259
	u16 msdu_id = 0;
1260

1261 1262 1263 1264 1265 1266 1267
	if ((ieee80211_is_action(hdr->frame_control) ||
	     ieee80211_is_deauth(hdr->frame_control) ||
	     ieee80211_is_disassoc(hdr->frame_control)) &&
	     ieee80211_has_protected(hdr->frame_control)) {
		skb_put(msdu, IEEE80211_CCMP_MIC_LEN);
	}

1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313
	data_len = msdu->len;

	switch (txmode) {
	case ATH10K_HW_TXRX_RAW:
	case ATH10K_HW_TXRX_NATIVE_WIFI:
		flags0 |= HTT_DATA_TX_DESC_FLAGS0_MAC_HDR_PRESENT;
		/* fall through */
	case ATH10K_HW_TXRX_ETHERNET:
		flags0 |= SM(txmode, HTT_DATA_TX_DESC_FLAGS0_PKT_TYPE);
		break;
	case ATH10K_HW_TXRX_MGMT:
		flags0 |= SM(ATH10K_HW_TXRX_MGMT,
			     HTT_DATA_TX_DESC_FLAGS0_PKT_TYPE);
		flags0 |= HTT_DATA_TX_DESC_FLAGS0_MAC_HDR_PRESENT;
		break;
	}

	if (skb_cb->flags & ATH10K_SKB_F_NO_HWCRYPT)
		flags0 |= HTT_DATA_TX_DESC_FLAGS0_NO_ENCRYPT;

	flags1 |= SM((u16)vdev_id, HTT_DATA_TX_DESC_FLAGS1_VDEV_ID);
	flags1 |= SM((u16)tid, HTT_DATA_TX_DESC_FLAGS1_EXT_TID);
	if (msdu->ip_summed == CHECKSUM_PARTIAL &&
	    !test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
		flags1 |= HTT_DATA_TX_DESC_FLAGS1_CKSUM_L3_OFFLOAD;
		flags1 |= HTT_DATA_TX_DESC_FLAGS1_CKSUM_L4_OFFLOAD;
	}

	/* Prepend the HTT header and TX desc struct to the data message
	 * and realloc the skb if it does not have enough headroom.
	 */
	if (skb_headroom(msdu) < HTT_TX_HL_NEEDED_HEADROOM) {
		tmp_skb = msdu;

		ath10k_dbg(htt->ar, ATH10K_DBG_HTT,
			   "Not enough headroom in skb. Current headroom: %u, needed: %u. Reallocating...\n",
			   skb_headroom(msdu), HTT_TX_HL_NEEDED_HEADROOM);
		msdu = skb_realloc_headroom(msdu, HTT_TX_HL_NEEDED_HEADROOM);
		kfree_skb(tmp_skb);
		if (!msdu) {
			ath10k_warn(htt->ar, "htt hl tx: Unable to realloc skb!\n");
			res = -ENOMEM;
			goto out;
		}
	}

1314 1315 1316 1317 1318 1319 1320 1321 1322 1323
	if (ar->bus_param.hl_msdu_ids) {
		flags1 |= HTT_DATA_TX_DESC_FLAGS1_POSTPONED;
		res = ath10k_htt_tx_alloc_msdu_id(htt, msdu);
		if (res < 0) {
			ath10k_err(ar, "msdu_id allocation failed %d\n", res);
			goto out;
		}
		msdu_id = res;
	}

1324 1325 1326 1327 1328 1329 1330
	/* As msdu is freed by mac80211 (in ieee80211_tx_status()) and by
	 * ath10k (in ath10k_htt_htc_tx_complete()) we have to increase
	 * reference by one to avoid a use-after-free case and a double
	 * free.
	 */
	skb_get(msdu);

1331 1332 1333 1334 1335 1336 1337 1338 1339
	skb_push(msdu, sizeof(*cmd_hdr));
	skb_push(msdu, sizeof(*tx_desc));
	cmd_hdr = (struct htt_cmd_hdr *)msdu->data;
	tx_desc = (struct htt_data_tx_desc *)(msdu->data + sizeof(*cmd_hdr));

	cmd_hdr->msg_type = HTT_H2T_MSG_TYPE_TX_FRM;
	tx_desc->flags0 = flags0;
	tx_desc->flags1 = __cpu_to_le16(flags1);
	tx_desc->len = __cpu_to_le16(data_len);
1340
	tx_desc->id = __cpu_to_le16(msdu_id);
1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352
	tx_desc->frags_paddr = 0; /* always zero */
	/* Initialize peer_id to INVALID_PEER because this is NOT
	 * Reinjection path
	 */
	tx_desc->peerid = __cpu_to_le32(HTT_INVALID_PEERID);

	res = ath10k_htc_send(&htt->ar->htc, htt->eid, msdu);

out:
	return res;
}

1353 1354 1355
static int ath10k_htt_tx_32(struct ath10k_htt *htt,
			    enum ath10k_hw_txrx_mode txmode,
			    struct sk_buff *msdu)
1356
{
1357 1358
	struct ath10k *ar = htt->ar;
	struct device *dev = ar->dev;
1359
	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)msdu->data;
M
Michal Kazior 已提交
1360
	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(msdu);
1361
	struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(msdu);
1362
	struct ath10k_hif_sg_item sg_items[2];
1363
	struct ath10k_htt_txbuf_32 *txbuf;
1364
	struct htt_data_tx_desc_frag *frags;
1365 1366 1367
	bool is_eth = (txmode == ATH10K_HW_TXRX_ETHERNET);
	u8 vdev_id = ath10k_htt_tx_get_vdev_id(ar, msdu);
	u8 tid = ath10k_htt_tx_get_tid(msdu, is_eth);
1368
	int prefetch_len;
1369
	int res;
1370 1371
	u8 flags0 = 0;
	u16 msdu_id, flags1 = 0;
M
Michal Kazior 已提交
1372
	u16 freq = 0;
1373
	u32 frags_paddr = 0;
1374
	u32 txbuf_paddr;
1375
	struct htt_msdu_ext_desc *ext_desc = NULL;
1376
	struct htt_msdu_ext_desc *ext_desc_t = NULL;
M
Michal Kazior 已提交
1377

M
Michal Kazior 已提交
1378
	res = ath10k_htt_tx_alloc_msdu_id(htt, msdu);
K
Kalle Valo 已提交
1379
	if (res < 0)
1380
		goto err;
K
Kalle Valo 已提交
1381

M
Michal Kazior 已提交
1382
	msdu_id = res;
1383 1384 1385 1386

	prefetch_len = min(htt->prefetch_len, msdu->len);
	prefetch_len = roundup(prefetch_len, 4);

1387
	txbuf = htt->txbuf.vaddr_txbuff_32 + msdu_id;
1388
	txbuf_paddr = htt->txbuf.paddr +
1389
		      (sizeof(struct ath10k_htt_txbuf_32) * msdu_id);
1390

1391 1392 1393
	if ((ieee80211_is_action(hdr->frame_control) ||
	     ieee80211_is_deauth(hdr->frame_control) ||
	     ieee80211_is_disassoc(hdr->frame_control)) &&
1394
	     ieee80211_has_protected(hdr->frame_control)) {
1395
		skb_put(msdu, IEEE80211_CCMP_MIC_LEN);
M
Michal Kazior 已提交
1396
	} else if (!(skb_cb->flags & ATH10K_SKB_F_NO_HWCRYPT) &&
M
Michal Kazior 已提交
1397
		   txmode == ATH10K_HW_TXRX_RAW &&
1398
		   ieee80211_has_protected(hdr->frame_control)) {
1399 1400
		skb_put(msdu, IEEE80211_CCMP_MIC_LEN);
	}
1401

1402 1403 1404
	skb_cb->paddr = dma_map_single(dev, msdu->data, msdu->len,
				       DMA_TO_DEVICE);
	res = dma_mapping_error(dev, skb_cb->paddr);
1405 1406
	if (res) {
		res = -EIO;
1407
		goto err_free_msdu_id;
1408
	}
1409

M
Michal Kazior 已提交
1410 1411 1412
	if (unlikely(info->flags & IEEE80211_TX_CTL_TX_OFFCHAN))
		freq = ar->scan.roc_freq;

M
Michal Kazior 已提交
1413
	switch (txmode) {
1414 1415 1416
	case ATH10K_HW_TXRX_RAW:
	case ATH10K_HW_TXRX_NATIVE_WIFI:
		flags0 |= HTT_DATA_TX_DESC_FLAGS0_MAC_HDR_PRESENT;
1417
		/* fall through */
1418
	case ATH10K_HW_TXRX_ETHERNET:
1419
		if (ar->hw_params.continuous_frag_desc) {
1420 1421
			ext_desc_t = htt->frag_desc.vaddr_desc_32;
			memset(&ext_desc_t[msdu_id], 0,
1422
			       sizeof(struct htt_msdu_ext_desc));
1423
			frags = (struct htt_data_tx_desc_frag *)
1424 1425
				&ext_desc_t[msdu_id].frags;
			ext_desc = &ext_desc_t[msdu_id];
1426 1427 1428 1429 1430 1431 1432 1433
			frags[0].tword_addr.paddr_lo =
				__cpu_to_le32(skb_cb->paddr);
			frags[0].tword_addr.paddr_hi = 0;
			frags[0].tword_addr.len_16 = __cpu_to_le16(msdu->len);

			frags_paddr =  htt->frag_desc.paddr +
				(sizeof(struct htt_msdu_ext_desc) * msdu_id);
		} else {
1434
			frags = txbuf->frags;
1435 1436 1437 1438 1439 1440
			frags[0].dword_addr.paddr =
				__cpu_to_le32(skb_cb->paddr);
			frags[0].dword_addr.len = __cpu_to_le32(msdu->len);
			frags[1].dword_addr.paddr = 0;
			frags[1].dword_addr.len = 0;

1441
			frags_paddr = txbuf_paddr;
1442
		}
M
Michal Kazior 已提交
1443
		flags0 |= SM(txmode, HTT_DATA_TX_DESC_FLAGS0_PKT_TYPE);
1444 1445
		break;
	case ATH10K_HW_TXRX_MGMT:
1446 1447
		flags0 |= SM(ATH10K_HW_TXRX_MGMT,
			     HTT_DATA_TX_DESC_FLAGS0_PKT_TYPE);
1448
		flags0 |= HTT_DATA_TX_DESC_FLAGS0_MAC_HDR_PRESENT;
1449

1450
		frags_paddr = skb_cb->paddr;
1451
		break;
1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467
	}

	/* Normally all commands go through HTC which manages tx credits for
	 * each endpoint and notifies when tx is completed.
	 *
	 * HTT endpoint is creditless so there's no need to care about HTC
	 * flags. In that case it is trivial to fill the HTC header here.
	 *
	 * MSDU transmission is considered completed upon HTT event. This
	 * implies no relevant resources can be freed until after the event is
	 * received. That's why HTC tx completion handler itself is ignored by
	 * setting NULL to transfer_context for all sg items.
	 *
	 * There is simply no point in pushing HTT TX_FRM through HTC tx path
	 * as it's a waste of resources. By bypassing HTC it is possible to
	 * avoid extra memory allocations, compress data structures and thus
1468 1469
	 * improve performance.
	 */
1470

1471 1472 1473 1474 1475
	txbuf->htc_hdr.eid = htt->eid;
	txbuf->htc_hdr.len = __cpu_to_le16(sizeof(txbuf->cmd_hdr) +
					   sizeof(txbuf->cmd_tx) +
					   prefetch_len);
	txbuf->htc_hdr.flags = 0;
1476

M
Michal Kazior 已提交
1477
	if (skb_cb->flags & ATH10K_SKB_F_NO_HWCRYPT)
1478 1479
		flags0 |= HTT_DATA_TX_DESC_FLAGS0_NO_ENCRYPT;

1480 1481
	flags1 |= SM((u16)vdev_id, HTT_DATA_TX_DESC_FLAGS1_VDEV_ID);
	flags1 |= SM((u16)tid, HTT_DATA_TX_DESC_FLAGS1_EXT_TID);
1482 1483
	if (msdu->ip_summed == CHECKSUM_PARTIAL &&
	    !test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
1484 1485
		flags1 |= HTT_DATA_TX_DESC_FLAGS1_CKSUM_L3_OFFLOAD;
		flags1 |= HTT_DATA_TX_DESC_FLAGS1_CKSUM_L4_OFFLOAD;
1486 1487
		if (ar->hw_params.continuous_frag_desc)
			ext_desc->flags |= HTT_MSDU_CHECKSUM_ENABLE;
1488
	}
1489

1490 1491 1492 1493 1494 1495
	/* Prevent firmware from sending up tx inspection requests. There's
	 * nothing ath10k can do with frames requested for inspection so force
	 * it to simply rely a regular tx completion with discard status.
	 */
	flags1 |= HTT_DATA_TX_DESC_FLAGS1_POSTPONED;

1496 1497 1498 1499 1500 1501
	txbuf->cmd_hdr.msg_type = HTT_H2T_MSG_TYPE_TX_FRM;
	txbuf->cmd_tx.flags0 = flags0;
	txbuf->cmd_tx.flags1 = __cpu_to_le16(flags1);
	txbuf->cmd_tx.len = __cpu_to_le16(msdu->len);
	txbuf->cmd_tx.id = __cpu_to_le16(msdu_id);
	txbuf->cmd_tx.frags_paddr = __cpu_to_le32(frags_paddr);
1502
	if (ath10k_mac_tx_frm_has_freq(ar)) {
1503
		txbuf->cmd_tx.offchan_tx.peerid =
1504
				__cpu_to_le16(HTT_INVALID_PEERID);
1505
		txbuf->cmd_tx.offchan_tx.freq =
M
Michal Kazior 已提交
1506
				__cpu_to_le16(freq);
1507
	} else {
1508
		txbuf->cmd_tx.peerid =
1509 1510
				__cpu_to_le32(HTT_INVALID_PEERID);
	}
1511

1512
	trace_ath10k_htt_tx(ar, msdu_id, msdu->len, vdev_id, tid);
1513
	ath10k_dbg(ar, ATH10K_DBG_HTT,
1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573
		   "htt tx flags0 %hhu flags1 %hu len %d id %hu frags_paddr %pad, msdu_paddr %pad vdev %hhu tid %hhu freq %hu\n",
		   flags0, flags1, msdu->len, msdu_id, &frags_paddr,
		   &skb_cb->paddr, vdev_id, tid, freq);
	ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "htt tx msdu: ",
			msdu->data, msdu->len);
	trace_ath10k_tx_hdr(ar, msdu->data, msdu->len);
	trace_ath10k_tx_payload(ar, msdu->data, msdu->len);

	sg_items[0].transfer_id = 0;
	sg_items[0].transfer_context = NULL;
	sg_items[0].vaddr = &txbuf->htc_hdr;
	sg_items[0].paddr = txbuf_paddr +
			    sizeof(txbuf->frags);
	sg_items[0].len = sizeof(txbuf->htc_hdr) +
			  sizeof(txbuf->cmd_hdr) +
			  sizeof(txbuf->cmd_tx);

	sg_items[1].transfer_id = 0;
	sg_items[1].transfer_context = NULL;
	sg_items[1].vaddr = msdu->data;
	sg_items[1].paddr = skb_cb->paddr;
	sg_items[1].len = prefetch_len;

	res = ath10k_hif_tx_sg(htt->ar,
			       htt->ar->htc.endpoint[htt->eid].ul_pipe_id,
			       sg_items, ARRAY_SIZE(sg_items));
	if (res)
		goto err_unmap_msdu;

	return 0;

err_unmap_msdu:
	dma_unmap_single(dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE);
err_free_msdu_id:
	ath10k_htt_tx_free_msdu_id(htt, msdu_id);
err:
	return res;
}

static int ath10k_htt_tx_64(struct ath10k_htt *htt,
			    enum ath10k_hw_txrx_mode txmode,
			    struct sk_buff *msdu)
{
	struct ath10k *ar = htt->ar;
	struct device *dev = ar->dev;
	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)msdu->data;
	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(msdu);
	struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(msdu);
	struct ath10k_hif_sg_item sg_items[2];
	struct ath10k_htt_txbuf_64 *txbuf;
	struct htt_data_tx_desc_frag *frags;
	bool is_eth = (txmode == ATH10K_HW_TXRX_ETHERNET);
	u8 vdev_id = ath10k_htt_tx_get_vdev_id(ar, msdu);
	u8 tid = ath10k_htt_tx_get_tid(msdu, is_eth);
	int prefetch_len;
	int res;
	u8 flags0 = 0;
	u16 msdu_id, flags1 = 0;
	u16 freq = 0;
	dma_addr_t frags_paddr = 0;
1574
	dma_addr_t txbuf_paddr;
1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616
	struct htt_msdu_ext_desc_64 *ext_desc = NULL;
	struct htt_msdu_ext_desc_64 *ext_desc_t = NULL;

	res = ath10k_htt_tx_alloc_msdu_id(htt, msdu);
	if (res < 0)
		goto err;

	msdu_id = res;

	prefetch_len = min(htt->prefetch_len, msdu->len);
	prefetch_len = roundup(prefetch_len, 4);

	txbuf = htt->txbuf.vaddr_txbuff_64 + msdu_id;
	txbuf_paddr = htt->txbuf.paddr +
		      (sizeof(struct ath10k_htt_txbuf_64) * msdu_id);

	if ((ieee80211_is_action(hdr->frame_control) ||
	     ieee80211_is_deauth(hdr->frame_control) ||
	     ieee80211_is_disassoc(hdr->frame_control)) &&
	     ieee80211_has_protected(hdr->frame_control)) {
		skb_put(msdu, IEEE80211_CCMP_MIC_LEN);
	} else if (!(skb_cb->flags & ATH10K_SKB_F_NO_HWCRYPT) &&
		   txmode == ATH10K_HW_TXRX_RAW &&
		   ieee80211_has_protected(hdr->frame_control)) {
		skb_put(msdu, IEEE80211_CCMP_MIC_LEN);
	}

	skb_cb->paddr = dma_map_single(dev, msdu->data, msdu->len,
				       DMA_TO_DEVICE);
	res = dma_mapping_error(dev, skb_cb->paddr);
	if (res) {
		res = -EIO;
		goto err_free_msdu_id;
	}

	if (unlikely(info->flags & IEEE80211_TX_CTL_TX_OFFCHAN))
		freq = ar->scan.roc_freq;

	switch (txmode) {
	case ATH10K_HW_TXRX_RAW:
	case ATH10K_HW_TXRX_NATIVE_WIFI:
		flags0 |= HTT_DATA_TX_DESC_FLAGS0_MAC_HDR_PRESENT;
1617
		/* fall through */
1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687
	case ATH10K_HW_TXRX_ETHERNET:
		if (ar->hw_params.continuous_frag_desc) {
			ext_desc_t = htt->frag_desc.vaddr_desc_64;
			memset(&ext_desc_t[msdu_id], 0,
			       sizeof(struct htt_msdu_ext_desc_64));
			frags = (struct htt_data_tx_desc_frag *)
				&ext_desc_t[msdu_id].frags;
			ext_desc = &ext_desc_t[msdu_id];
			frags[0].tword_addr.paddr_lo =
				__cpu_to_le32(skb_cb->paddr);
			frags[0].tword_addr.paddr_hi =
				__cpu_to_le16(upper_32_bits(skb_cb->paddr));
			frags[0].tword_addr.len_16 = __cpu_to_le16(msdu->len);

			frags_paddr =  htt->frag_desc.paddr +
			   (sizeof(struct htt_msdu_ext_desc_64) * msdu_id);
		} else {
			frags = txbuf->frags;
			frags[0].tword_addr.paddr_lo =
						__cpu_to_le32(skb_cb->paddr);
			frags[0].tword_addr.paddr_hi =
				__cpu_to_le16(upper_32_bits(skb_cb->paddr));
			frags[0].tword_addr.len_16 = __cpu_to_le16(msdu->len);
			frags[1].tword_addr.paddr_lo = 0;
			frags[1].tword_addr.paddr_hi = 0;
			frags[1].tword_addr.len_16 = 0;
		}
		flags0 |= SM(txmode, HTT_DATA_TX_DESC_FLAGS0_PKT_TYPE);
		break;
	case ATH10K_HW_TXRX_MGMT:
		flags0 |= SM(ATH10K_HW_TXRX_MGMT,
			     HTT_DATA_TX_DESC_FLAGS0_PKT_TYPE);
		flags0 |= HTT_DATA_TX_DESC_FLAGS0_MAC_HDR_PRESENT;

		frags_paddr = skb_cb->paddr;
		break;
	}

	/* Normally all commands go through HTC which manages tx credits for
	 * each endpoint and notifies when tx is completed.
	 *
	 * HTT endpoint is creditless so there's no need to care about HTC
	 * flags. In that case it is trivial to fill the HTC header here.
	 *
	 * MSDU transmission is considered completed upon HTT event. This
	 * implies no relevant resources can be freed until after the event is
	 * received. That's why HTC tx completion handler itself is ignored by
	 * setting NULL to transfer_context for all sg items.
	 *
	 * There is simply no point in pushing HTT TX_FRM through HTC tx path
	 * as it's a waste of resources. By bypassing HTC it is possible to
	 * avoid extra memory allocations, compress data structures and thus
	 * improve performance.
	 */

	txbuf->htc_hdr.eid = htt->eid;
	txbuf->htc_hdr.len = __cpu_to_le16(sizeof(txbuf->cmd_hdr) +
					   sizeof(txbuf->cmd_tx) +
					   prefetch_len);
	txbuf->htc_hdr.flags = 0;

	if (skb_cb->flags & ATH10K_SKB_F_NO_HWCRYPT)
		flags0 |= HTT_DATA_TX_DESC_FLAGS0_NO_ENCRYPT;

	flags1 |= SM((u16)vdev_id, HTT_DATA_TX_DESC_FLAGS1_VDEV_ID);
	flags1 |= SM((u16)tid, HTT_DATA_TX_DESC_FLAGS1_EXT_TID);
	if (msdu->ip_summed == CHECKSUM_PARTIAL &&
	    !test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
		flags1 |= HTT_DATA_TX_DESC_FLAGS1_CKSUM_L3_OFFLOAD;
		flags1 |= HTT_DATA_TX_DESC_FLAGS1_CKSUM_L4_OFFLOAD;
1688 1689 1690 1691 1692
		if (ar->hw_params.continuous_frag_desc) {
			memset(ext_desc->tso_flag, 0, sizeof(ext_desc->tso_flag));
			ext_desc->tso_flag[3] |=
				__cpu_to_le32(HTT_MSDU_CHECKSUM_ENABLE_64);
		}
1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723
	}

	/* Prevent firmware from sending up tx inspection requests. There's
	 * nothing ath10k can do with frames requested for inspection so force
	 * it to simply rely a regular tx completion with discard status.
	 */
	flags1 |= HTT_DATA_TX_DESC_FLAGS1_POSTPONED;

	txbuf->cmd_hdr.msg_type = HTT_H2T_MSG_TYPE_TX_FRM;
	txbuf->cmd_tx.flags0 = flags0;
	txbuf->cmd_tx.flags1 = __cpu_to_le16(flags1);
	txbuf->cmd_tx.len = __cpu_to_le16(msdu->len);
	txbuf->cmd_tx.id = __cpu_to_le16(msdu_id);

	/* fill fragment descriptor */
	txbuf->cmd_tx.frags_paddr = __cpu_to_le64(frags_paddr);
	if (ath10k_mac_tx_frm_has_freq(ar)) {
		txbuf->cmd_tx.offchan_tx.peerid =
				__cpu_to_le16(HTT_INVALID_PEERID);
		txbuf->cmd_tx.offchan_tx.freq =
				__cpu_to_le16(freq);
	} else {
		txbuf->cmd_tx.peerid =
				__cpu_to_le32(HTT_INVALID_PEERID);
	}

	trace_ath10k_htt_tx(ar, msdu_id, msdu->len, vdev_id, tid);
	ath10k_dbg(ar, ATH10K_DBG_HTT,
		   "htt tx flags0 %hhu flags1 %hu len %d id %hu frags_paddr %pad, msdu_paddr %pad vdev %hhu tid %hhu freq %hu\n",
		   flags0, flags1, msdu->len, msdu_id, &frags_paddr,
		   &skb_cb->paddr, vdev_id, tid, freq);
1724
	ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "htt tx msdu: ",
1725
			msdu->data, msdu->len);
1726 1727
	trace_ath10k_tx_hdr(ar, msdu->data, msdu->len);
	trace_ath10k_tx_payload(ar, msdu->data, msdu->len);
1728

1729 1730
	sg_items[0].transfer_id = 0;
	sg_items[0].transfer_context = NULL;
1731 1732 1733 1734 1735 1736
	sg_items[0].vaddr = &txbuf->htc_hdr;
	sg_items[0].paddr = txbuf_paddr +
			    sizeof(txbuf->frags);
	sg_items[0].len = sizeof(txbuf->htc_hdr) +
			  sizeof(txbuf->cmd_hdr) +
			  sizeof(txbuf->cmd_tx);
1737 1738 1739 1740 1741 1742 1743 1744 1745 1746

	sg_items[1].transfer_id = 0;
	sg_items[1].transfer_context = NULL;
	sg_items[1].vaddr = msdu->data;
	sg_items[1].paddr = skb_cb->paddr;
	sg_items[1].len = prefetch_len;

	res = ath10k_hif_tx_sg(htt->ar,
			       htt->ar->htc.endpoint[htt->eid].ul_pipe_id,
			       sg_items, ARRAY_SIZE(sg_items));
1747
	if (res)
1748
		goto err_unmap_msdu;
1749 1750

	return 0;
M
Michal Kazior 已提交
1751 1752

err_unmap_msdu:
1753
	dma_unmap_single(dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE);
M
Michal Kazior 已提交
1754 1755 1756
err_free_msdu_id:
	ath10k_htt_tx_free_msdu_id(htt, msdu_id);
err:
1757 1758
	return res;
}
1759 1760 1761

static const struct ath10k_htt_tx_ops htt_tx_ops_32 = {
	.htt_send_rx_ring_cfg = ath10k_htt_send_rx_ring_cfg_32,
1762 1763 1764
	.htt_send_frag_desc_bank_cfg = ath10k_htt_send_frag_desc_bank_cfg_32,
	.htt_alloc_frag_desc = ath10k_htt_tx_alloc_cont_frag_desc_32,
	.htt_free_frag_desc = ath10k_htt_tx_free_cont_frag_desc_32,
1765 1766 1767
	.htt_tx = ath10k_htt_tx_32,
	.htt_alloc_txbuff = ath10k_htt_tx_alloc_cont_txbuf_32,
	.htt_free_txbuff = ath10k_htt_tx_free_cont_txbuf_32,
1768
	.htt_h2t_aggr_cfg_msg = ath10k_htt_h2t_aggr_cfg_msg_32,
1769 1770 1771 1772
};

static const struct ath10k_htt_tx_ops htt_tx_ops_64 = {
	.htt_send_rx_ring_cfg = ath10k_htt_send_rx_ring_cfg_64,
1773 1774 1775
	.htt_send_frag_desc_bank_cfg = ath10k_htt_send_frag_desc_bank_cfg_64,
	.htt_alloc_frag_desc = ath10k_htt_tx_alloc_cont_frag_desc_64,
	.htt_free_frag_desc = ath10k_htt_tx_free_cont_frag_desc_64,
1776 1777 1778
	.htt_tx = ath10k_htt_tx_64,
	.htt_alloc_txbuff = ath10k_htt_tx_alloc_cont_txbuf_64,
	.htt_free_txbuff = ath10k_htt_tx_free_cont_txbuf_64,
1779
	.htt_h2t_aggr_cfg_msg = ath10k_htt_h2t_aggr_cfg_msg_v2,
1780 1781
};

E
Erik Stromdahl 已提交
1782
static const struct ath10k_htt_tx_ops htt_tx_ops_hl = {
1783
	.htt_send_rx_ring_cfg = ath10k_htt_send_rx_ring_cfg_hl,
E
Erik Stromdahl 已提交
1784
	.htt_send_frag_desc_bank_cfg = ath10k_htt_send_frag_desc_bank_cfg_32,
1785
	.htt_tx = ath10k_htt_tx_hl,
1786
	.htt_h2t_aggr_cfg_msg = ath10k_htt_h2t_aggr_cfg_msg_32,
E
Erik Stromdahl 已提交
1787 1788
};

1789 1790 1791 1792
void ath10k_htt_set_tx_ops(struct ath10k_htt *htt)
{
	struct ath10k *ar = htt->ar;

1793
	if (ar->bus_param.dev_type == ATH10K_DEV_TYPE_HL)
E
Erik Stromdahl 已提交
1794 1795
		htt->tx_ops = &htt_tx_ops_hl;
	else if (ar->hw_params.target_64bit)
1796 1797 1798 1799
		htt->tx_ops = &htt_tx_ops_64;
	else
		htt->tx_ops = &htt_tx_ops_32;
}