blob: 92d847285c0201081d212b5cbc84c3b91b6b5a77 [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
2 * Copyright (c) 2011-2015 The Linux Foundation. All rights reserved.
3 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28/**
29 * @file htt_t2h.c
30 * @brief Provide functions to process target->host HTT messages.
31 * @details
32 * This file contains functions related to target->host HTT messages.
33 * There are two categories of functions:
34 * 1. A function that receives a HTT message from HTC, and dispatches it
35 * based on the HTT message type.
36 * 2. functions that provide the info elements from specific HTT messages.
37 */
38
39#include <htc_api.h> /* HTC_PACKET */
40#include <htt.h> /* HTT_T2H_MSG_TYPE, etc. */
41#include <cdf_nbuf.h> /* cdf_nbuf_t */
42
43#include <ol_htt_rx_api.h>
44#include <ol_htt_tx_api.h>
45#include <ol_txrx_htt_api.h> /* htt_tx_status */
46
47#include <htt_internal.h> /* HTT_TX_SCHED, etc. */
48#include <pktlog_ac_fmt.h>
49#include <wdi_event.h>
50#include <ol_htt_tx_api.h>
51#include <ol_txrx_types.h>
52/*--- target->host HTT message dispatch function ----------------------------*/
53
54#ifndef DEBUG_CREDIT
55#define DEBUG_CREDIT 0
56#endif
57
58static uint8_t *htt_t2h_mac_addr_deswizzle(uint8_t *tgt_mac_addr,
59 uint8_t *buffer)
60{
61#ifdef BIG_ENDIAN_HOST
62 /*
63 * The host endianness is opposite of the target endianness.
64 * To make uint32_t elements come out correctly, the target->host
65 * upload has swizzled the bytes in each uint32_t element of the
66 * message.
67 * For byte-array message fields like the MAC address, this
68 * upload swizzling puts the bytes in the wrong order, and needs
69 * to be undone.
70 */
71 buffer[0] = tgt_mac_addr[3];
72 buffer[1] = tgt_mac_addr[2];
73 buffer[2] = tgt_mac_addr[1];
74 buffer[3] = tgt_mac_addr[0];
75 buffer[4] = tgt_mac_addr[7];
76 buffer[5] = tgt_mac_addr[6];
77 return buffer;
78#else
79 /*
80 * The host endianness matches the target endianness -
81 * we can use the mac addr directly from the message buffer.
82 */
83 return tgt_mac_addr;
84#endif
85}
86
87static void htt_rx_frag_set_last_msdu(struct htt_pdev_t *pdev, cdf_nbuf_t msg)
88{
89 uint32_t *msg_word;
90 unsigned num_msdu_bytes;
91 cdf_nbuf_t msdu;
92 struct htt_host_rx_desc_base *rx_desc;
93 int start_idx;
94 uint8_t *p_fw_msdu_rx_desc = 0;
95
96 msg_word = (uint32_t *) cdf_nbuf_data(msg);
97 num_msdu_bytes = HTT_RX_FRAG_IND_FW_RX_DESC_BYTES_GET(
98 *(msg_word + HTT_RX_FRAG_IND_HDR_PREFIX_SIZE32));
99 /*
100 * 1 word for the message header,
101 * 1 word to specify the number of MSDU bytes,
102 * 1 word for every 4 MSDU bytes (round up),
103 * 1 word for the MPDU range header
104 */
105 pdev->rx_mpdu_range_offset_words = 3 + ((num_msdu_bytes + 3) >> 2);
106 pdev->rx_ind_msdu_byte_idx = 0;
107
108 p_fw_msdu_rx_desc = ((uint8_t *) (msg_word) +
109 HTT_ENDIAN_BYTE_IDX_SWAP
110 (HTT_RX_FRAG_IND_FW_DESC_BYTE_OFFSET));
111
112 /*
113 * Fix for EV126710, in which BSOD occurs due to last_msdu bit
114 * not set while the next pointer is deliberately set to NULL
115 * before calling ol_rx_pn_check_base()
116 *
117 * For fragment frames, the HW may not have set the last_msdu bit
118 * in the rx descriptor, but the SW expects this flag to be set,
119 * since each fragment is in a separate MPDU. Thus, set the flag here,
120 * just in case the HW didn't.
121 */
122 start_idx = pdev->rx_ring.sw_rd_idx.msdu_payld;
123 msdu = pdev->rx_ring.buf.netbufs_ring[start_idx];
124 cdf_nbuf_set_pktlen(msdu, HTT_RX_BUF_SIZE);
125 cdf_nbuf_unmap(pdev->osdev, msdu, CDF_DMA_FROM_DEVICE);
126 rx_desc = htt_rx_desc(msdu);
127 *((uint8_t *) &rx_desc->fw_desc.u.val) = *p_fw_msdu_rx_desc;
128 rx_desc->msdu_end.last_msdu = 1;
129 cdf_nbuf_map(pdev->osdev, msdu, CDF_DMA_FROM_DEVICE);
130}
131
132/* Target to host Msg/event handler for low priority messages*/
133void htt_t2h_lp_msg_handler(void *context, cdf_nbuf_t htt_t2h_msg)
134{
135 struct htt_pdev_t *pdev = (struct htt_pdev_t *)context;
136 uint32_t *msg_word;
137 enum htt_t2h_msg_type msg_type;
138
139 msg_word = (uint32_t *) cdf_nbuf_data(htt_t2h_msg);
140 msg_type = HTT_T2H_MSG_TYPE_GET(*msg_word);
141 switch (msg_type) {
142 case HTT_T2H_MSG_TYPE_VERSION_CONF:
143 {
144 pdev->tgt_ver.major = HTT_VER_CONF_MAJOR_GET(*msg_word);
145 pdev->tgt_ver.minor = HTT_VER_CONF_MINOR_GET(*msg_word);
146 cdf_print
147 ("target uses HTT version %d.%d; host uses %d.%d\n",
148 pdev->tgt_ver.major, pdev->tgt_ver.minor,
149 HTT_CURRENT_VERSION_MAJOR,
150 HTT_CURRENT_VERSION_MINOR);
151 if (pdev->tgt_ver.major != HTT_CURRENT_VERSION_MAJOR)
152 cdf_print
153 ("*** Incompatible host/target HTT versions!\n");
154 /* abort if the target is incompatible with the host */
155 cdf_assert(pdev->tgt_ver.major ==
156 HTT_CURRENT_VERSION_MAJOR);
157 if (pdev->tgt_ver.minor != HTT_CURRENT_VERSION_MINOR) {
158 cdf_print("*** Warning: host/target HTT versions are ");
159 cdf_print(" different, though compatible!\n");
160 }
161 break;
162 }
163 case HTT_T2H_MSG_TYPE_RX_FLUSH:
164 {
165 uint16_t peer_id;
166 uint8_t tid;
167 int seq_num_start, seq_num_end;
168 enum htt_rx_flush_action action;
169
170 peer_id = HTT_RX_FLUSH_PEER_ID_GET(*msg_word);
171 tid = HTT_RX_FLUSH_TID_GET(*msg_word);
172 seq_num_start =
173 HTT_RX_FLUSH_SEQ_NUM_START_GET(*(msg_word + 1));
174 seq_num_end =
175 HTT_RX_FLUSH_SEQ_NUM_END_GET(*(msg_word + 1));
176 action =
177 HTT_RX_FLUSH_MPDU_STATUS_GET(*(msg_word + 1)) ==
178 1 ? htt_rx_flush_release : htt_rx_flush_discard;
179 ol_rx_flush_handler(pdev->txrx_pdev, peer_id, tid,
180 seq_num_start, seq_num_end, action);
181 break;
182 }
183 case HTT_T2H_MSG_TYPE_RX_OFFLOAD_DELIVER_IND:
184 {
185 int msdu_cnt;
186 msdu_cnt =
187 HTT_RX_OFFLOAD_DELIVER_IND_MSDU_CNT_GET(*msg_word);
188 ol_rx_offload_deliver_ind_handler(pdev->txrx_pdev,
189 htt_t2h_msg,
190 msdu_cnt);
191 break;
192 }
193 case HTT_T2H_MSG_TYPE_RX_FRAG_IND:
194 {
195 uint16_t peer_id;
196 uint8_t tid;
197
198 peer_id = HTT_RX_FRAG_IND_PEER_ID_GET(*msg_word);
199 tid = HTT_RX_FRAG_IND_EXT_TID_GET(*msg_word);
200 htt_rx_frag_set_last_msdu(pdev, htt_t2h_msg);
201
202 ol_rx_frag_indication_handler(pdev->txrx_pdev,
203 htt_t2h_msg,
204 peer_id, tid);
205 break;
206 }
207 case HTT_T2H_MSG_TYPE_RX_ADDBA:
208 {
209 uint16_t peer_id;
210 uint8_t tid;
211 uint8_t win_sz;
212 uint16_t start_seq_num;
213
214 /*
215 * FOR NOW, the host doesn't need to know the initial
216 * sequence number for rx aggregation.
217 * Thus, any value will do - specify 0.
218 */
219 start_seq_num = 0;
220 peer_id = HTT_RX_ADDBA_PEER_ID_GET(*msg_word);
221 tid = HTT_RX_ADDBA_TID_GET(*msg_word);
222 win_sz = HTT_RX_ADDBA_WIN_SIZE_GET(*msg_word);
223 ol_rx_addba_handler(pdev->txrx_pdev, peer_id, tid,
224 win_sz, start_seq_num,
225 0 /* success */);
226 break;
227 }
228 case HTT_T2H_MSG_TYPE_RX_DELBA:
229 {
230 uint16_t peer_id;
231 uint8_t tid;
232
233 peer_id = HTT_RX_DELBA_PEER_ID_GET(*msg_word);
234 tid = HTT_RX_DELBA_TID_GET(*msg_word);
235 ol_rx_delba_handler(pdev->txrx_pdev, peer_id, tid);
236 break;
237 }
238 case HTT_T2H_MSG_TYPE_PEER_MAP:
239 {
240 uint8_t mac_addr_deswizzle_buf[HTT_MAC_ADDR_LEN];
241 uint8_t *peer_mac_addr;
242 uint16_t peer_id;
243 uint8_t vdev_id;
244
245 peer_id = HTT_RX_PEER_MAP_PEER_ID_GET(*msg_word);
246 vdev_id = HTT_RX_PEER_MAP_VDEV_ID_GET(*msg_word);
247 peer_mac_addr = htt_t2h_mac_addr_deswizzle(
248 (uint8_t *) (msg_word + 1),
249 &mac_addr_deswizzle_buf[0]);
250
251 ol_rx_peer_map_handler(pdev->txrx_pdev, peer_id,
252 vdev_id, peer_mac_addr,
253 1 /*can tx */);
254 break;
255 }
256 case HTT_T2H_MSG_TYPE_PEER_UNMAP:
257 {
258 uint16_t peer_id;
259 peer_id = HTT_RX_PEER_UNMAP_PEER_ID_GET(*msg_word);
260
261 ol_rx_peer_unmap_handler(pdev->txrx_pdev, peer_id);
262 break;
263 }
264 case HTT_T2H_MSG_TYPE_SEC_IND:
265 {
266 uint16_t peer_id;
267 enum htt_sec_type sec_type;
268 int is_unicast;
269
270 peer_id = HTT_SEC_IND_PEER_ID_GET(*msg_word);
271 sec_type = HTT_SEC_IND_SEC_TYPE_GET(*msg_word);
272 is_unicast = HTT_SEC_IND_UNICAST_GET(*msg_word);
273 msg_word++; /* point to the first part of the Michael key */
274 ol_rx_sec_ind_handler(pdev->txrx_pdev, peer_id,
275 sec_type, is_unicast, msg_word,
276 msg_word + 2);
277 break;
278 }
279 case HTT_T2H_MSG_TYPE_MGMT_TX_COMPL_IND:
280 {
281 struct htt_mgmt_tx_compl_ind *compl_msg;
282
283 compl_msg =
284 (struct htt_mgmt_tx_compl_ind *)(msg_word + 1);
285
286 ol_tx_single_completion_handler(pdev->txrx_pdev,
287 compl_msg->status,
288 compl_msg->desc_id);
289 HTT_TX_SCHED(pdev);
290 break;
291 }
292 case HTT_T2H_MSG_TYPE_STATS_CONF:
293 {
294 uint64_t cookie;
295 uint8_t *stats_info_list;
296
297 cookie = *(msg_word + 1);
298 cookie |= ((uint64_t) (*(msg_word + 2))) << 32;
299
300 stats_info_list = (uint8_t *) (msg_word + 3);
301 ol_txrx_fw_stats_handler(pdev->txrx_pdev, cookie,
302 stats_info_list);
303 break;
304 }
305#ifndef REMOVE_PKT_LOG
306 case HTT_T2H_MSG_TYPE_PKTLOG:
307 {
308 uint32_t *pl_hdr;
309 uint32_t log_type;
310 pl_hdr = (msg_word + 1);
311 log_type =
312 (*(pl_hdr + 1) & ATH_PKTLOG_HDR_LOG_TYPE_MASK) >>
313 ATH_PKTLOG_HDR_LOG_TYPE_SHIFT;
314 if ((log_type == PKTLOG_TYPE_TX_CTRL)
315 || (log_type == PKTLOG_TYPE_TX_STAT)
316 || (log_type == PKTLOG_TYPE_TX_MSDU_ID)
317 || (log_type == PKTLOG_TYPE_TX_FRM_HDR)
318 || (log_type == PKTLOG_TYPE_TX_VIRT_ADDR))
319 wdi_event_handler(WDI_EVENT_TX_STATUS,
320 pdev->txrx_pdev, pl_hdr);
321 else if (log_type == PKTLOG_TYPE_RC_FIND)
322 wdi_event_handler(WDI_EVENT_RATE_FIND,
323 pdev->txrx_pdev, pl_hdr);
324 else if (log_type == PKTLOG_TYPE_RC_UPDATE)
325 wdi_event_handler(WDI_EVENT_RATE_UPDATE,
326 pdev->txrx_pdev, pl_hdr);
327 else if (log_type == PKTLOG_TYPE_RX_STAT)
328 wdi_event_handler(WDI_EVENT_RX_DESC,
329 pdev->txrx_pdev, pl_hdr);
330
331 break;
332 }
333#endif
334 case HTT_T2H_MSG_TYPE_TX_CREDIT_UPDATE_IND:
335 {
336 uint32_t htt_credit_delta_abs;
337 int32_t htt_credit_delta;
338 int sign;
339
340 htt_credit_delta_abs =
341 HTT_TX_CREDIT_DELTA_ABS_GET(*msg_word);
342 sign = HTT_TX_CREDIT_SIGN_BIT_GET(*msg_word) ? -1 : 1;
343 htt_credit_delta = sign * htt_credit_delta_abs;
344 ol_tx_credit_completion_handler(pdev->txrx_pdev,
345 htt_credit_delta);
346 break;
347 }
348
349 case HTT_T2H_MSG_TYPE_WDI_IPA_OP_RESPONSE:
350 {
351 uint8_t op_code;
352 uint16_t len;
353 uint8_t *op_msg_buffer;
354 uint8_t *msg_start_ptr;
355
356 msg_start_ptr = (uint8_t *) msg_word;
357 op_code =
358 HTT_WDI_IPA_OP_RESPONSE_OP_CODE_GET(*msg_word);
359 msg_word++;
360 len = HTT_WDI_IPA_OP_RESPONSE_RSP_LEN_GET(*msg_word);
361
362 op_msg_buffer =
363 cdf_mem_malloc(sizeof
364 (struct htt_wdi_ipa_op_response_t) +
365 len);
366 if (!op_msg_buffer) {
367 cdf_print("OPCODE messsage buffer alloc fail");
368 break;
369 }
370 cdf_mem_copy(op_msg_buffer,
371 msg_start_ptr,
372 sizeof(struct htt_wdi_ipa_op_response_t) +
373 len);
374 ol_txrx_ipa_uc_op_response(pdev->txrx_pdev,
375 op_msg_buffer);
376 break;
377 }
378
379 case HTT_T2H_MSG_TYPE_FLOW_POOL_MAP:
380 {
381 uint8_t num_flows;
382 struct htt_flow_pool_map_payload_t *pool_map_payoad;
383
384 num_flows = HTT_FLOW_POOL_MAP_NUM_FLOWS_GET(*msg_word);
385
386 msg_word++;
387 while (num_flows) {
388 pool_map_payoad = (struct htt_flow_pool_map_payload_t *)
389 msg_word;
390 ol_tx_flow_pool_map_handler(pool_map_payoad->flow_id,
391 pool_map_payoad->flow_type,
392 pool_map_payoad->flow_pool_id,
393 pool_map_payoad->flow_pool_size);
394
395 msg_word += (HTT_FLOW_POOL_MAP_PAYLOAD_SZ /
396 HTT_FLOW_POOL_MAP_HEADER_SZ);
397 num_flows--;
398 }
399 break;
400 }
401
402 case HTT_T2H_MSG_TYPE_FLOW_POOL_UNMAP:
403 {
404 struct htt_flow_pool_unmap_t *pool_numap_payload;
405
406 pool_numap_payload = (struct htt_flow_pool_unmap_t *)msg_word;
407 ol_tx_flow_pool_unmap_handler(pool_numap_payload->flow_id,
408 pool_numap_payload->flow_type,
409 pool_numap_payload->flow_pool_id);
410 break;
411 }
412
413 default:
414 break;
415 };
416 /* Free the indication buffer */
417 cdf_nbuf_free(htt_t2h_msg);
418}
419
420/* Generic Target to host Msg/event handler for low priority messages
421 Low priority message are handler in a different handler called from
422 this function . So that the most likely succes path like Rx and
423 Tx comp has little code foot print
424 */
425void htt_t2h_msg_handler(void *context, HTC_PACKET *pkt)
426{
427 struct htt_pdev_t *pdev = (struct htt_pdev_t *)context;
428 cdf_nbuf_t htt_t2h_msg = (cdf_nbuf_t) pkt->pPktContext;
429 uint32_t *msg_word;
430 enum htt_t2h_msg_type msg_type;
431
432 /* check for successful message reception */
433 if (pkt->Status != A_OK) {
434 if (pkt->Status != A_ECANCELED)
435 pdev->stats.htc_err_cnt++;
436 cdf_nbuf_free(htt_t2h_msg);
437 return;
438 }
439#ifdef HTT_RX_RESTORE
440 if (cdf_unlikely(pdev->rx_ring.rx_reset)) {
441 cdf_print("rx restore ..\n");
442 cdf_nbuf_free(htt_t2h_msg);
443 return;
444 }
445#endif
446
447 /* confirm alignment */
448 HTT_ASSERT3((((unsigned long)cdf_nbuf_data(htt_t2h_msg)) & 0x3) == 0);
449
450 msg_word = (uint32_t *) cdf_nbuf_data(htt_t2h_msg);
451 msg_type = HTT_T2H_MSG_TYPE_GET(*msg_word);
452
453#if defined(HELIUMPLUS_DEBUG)
454 cdf_print("%s %d: msg_word 0x%x msg_type %d\n",
455 __func__, __LINE__, *msg_word, msg_type);
456#endif
457
458 switch (msg_type) {
459 case HTT_T2H_MSG_TYPE_RX_IND:
460 {
461 unsigned num_mpdu_ranges;
462 unsigned num_msdu_bytes;
463 uint16_t peer_id;
464 uint8_t tid;
465
466 if (cdf_unlikely(pdev->cfg.is_full_reorder_offload)) {
467 cdf_print("HTT_T2H_MSG_TYPE_RX_IND not supported ");
468 cdf_print("with full reorder offload\n");
469 break;
470 }
471 peer_id = HTT_RX_IND_PEER_ID_GET(*msg_word);
472 tid = HTT_RX_IND_EXT_TID_GET(*msg_word);
473
474 num_msdu_bytes =
475 HTT_RX_IND_FW_RX_DESC_BYTES_GET(
476 *(msg_word + 2 + HTT_RX_PPDU_DESC_SIZE32));
477 /*
478 * 1 word for the message header,
479 * HTT_RX_PPDU_DESC_SIZE32 words for the FW rx PPDU desc
480 * 1 word to specify the number of MSDU bytes,
481 * 1 word for every 4 MSDU bytes (round up),
482 * 1 word for the MPDU range header
483 */
484 pdev->rx_mpdu_range_offset_words =
485 (HTT_RX_IND_HDR_BYTES + num_msdu_bytes + 3) >> 2;
486 num_mpdu_ranges =
487 HTT_RX_IND_NUM_MPDU_RANGES_GET(*(msg_word + 1));
488 pdev->rx_ind_msdu_byte_idx = 0;
489
490 ol_rx_indication_handler(pdev->txrx_pdev,
491 htt_t2h_msg, peer_id,
492 tid, num_mpdu_ranges);
493 break;
494 }
495 case HTT_T2H_MSG_TYPE_TX_COMPL_IND:
496 {
497 int num_msdus;
498 enum htt_tx_status status;
499
500 /* status - no enum translation needed */
501 status = HTT_TX_COMPL_IND_STATUS_GET(*msg_word);
502 num_msdus = HTT_TX_COMPL_IND_NUM_GET(*msg_word);
503 if (num_msdus & 0x1) {
504 struct htt_tx_compl_ind_base *compl =
505 (void *)msg_word;
506
507 /*
508 * Host CPU endianness can be different from FW CPU.
509 * This can result in even and odd MSDU IDs being
510 * switched. If this happens, copy the switched final
511 * odd MSDU ID from location payload[size], to
512 * location payload[size-1], where the message
513 * handler function expects to find it
514 */
515 if (compl->payload[num_msdus] !=
516 HTT_TX_COMPL_INV_MSDU_ID) {
517 compl->payload[num_msdus - 1] =
518 compl->payload[num_msdus];
519 }
520 }
521 ol_tx_completion_handler(pdev->txrx_pdev, num_msdus,
522 status, msg_word + 1);
523 HTT_TX_SCHED(pdev);
524 break;
525 }
526 case HTT_T2H_MSG_TYPE_RX_PN_IND:
527 {
528 uint16_t peer_id;
529 uint8_t tid, pn_ie_cnt, *pn_ie = NULL;
530 int seq_num_start, seq_num_end;
531
532 /*First dword */
533 peer_id = HTT_RX_PN_IND_PEER_ID_GET(*msg_word);
534 tid = HTT_RX_PN_IND_EXT_TID_GET(*msg_word);
535
536 msg_word++;
537 /*Second dword */
538 seq_num_start =
539 HTT_RX_PN_IND_SEQ_NUM_START_GET(*msg_word);
540 seq_num_end = HTT_RX_PN_IND_SEQ_NUM_END_GET(*msg_word);
541 pn_ie_cnt = HTT_RX_PN_IND_PN_IE_CNT_GET(*msg_word);
542
543 msg_word++;
544 /*Third dword */
545 if (pn_ie_cnt)
546 pn_ie = (uint8_t *) msg_word;
547
548 ol_rx_pn_ind_handler(pdev->txrx_pdev, peer_id, tid,
549 seq_num_start, seq_num_end,
550 pn_ie_cnt, pn_ie);
551
552 break;
553 }
554 case HTT_T2H_MSG_TYPE_TX_INSPECT_IND:
555 {
556 int num_msdus;
557
558 num_msdus = HTT_TX_COMPL_IND_NUM_GET(*msg_word);
559 if (num_msdus & 0x1) {
560 struct htt_tx_compl_ind_base *compl =
561 (void *)msg_word;
562
563 /*
564 * Host CPU endianness can be different from FW CPU.
565 * This can result in even and odd MSDU IDs being
566 * switched. If this happens, copy the switched final
567 * odd MSDU ID from location payload[size], to
568 * location payload[size-1], where the message handler
569 * function expects to find it
570 */
571 if (compl->payload[num_msdus] !=
572 HTT_TX_COMPL_INV_MSDU_ID) {
573 compl->payload[num_msdus - 1] =
574 compl->payload[num_msdus];
575 }
576 }
577 ol_tx_inspect_handler(pdev->txrx_pdev, num_msdus,
578 msg_word + 1);
579 HTT_TX_SCHED(pdev);
580 break;
581 }
582 case HTT_T2H_MSG_TYPE_RX_IN_ORD_PADDR_IND:
583 {
584 uint16_t peer_id;
585 uint8_t tid;
586 uint8_t offload_ind, frag_ind;
587
588 if (cdf_unlikely(!pdev->cfg.is_full_reorder_offload)) {
589 cdf_print("HTT_T2H_MSG_TYPE_RX_IN_ORD_PADDR_IND not ");
590 cdf_print("supported when full reorder offload is ");
591 cdf_print("disabled in the configuration.\n");
592 break;
593 }
594
595 peer_id = HTT_RX_IN_ORD_PADDR_IND_PEER_ID_GET(*msg_word);
596 tid = HTT_RX_IN_ORD_PADDR_IND_EXT_TID_GET(*msg_word);
597 offload_ind = HTT_RX_IN_ORD_PADDR_IND_OFFLOAD_GET(*msg_word);
598 frag_ind = HTT_RX_IN_ORD_PADDR_IND_FRAG_GET(*msg_word);
599
600#if defined(HELIUMPLUS_DEBUG)
601 cdf_print("%s %d: peerid %d tid %d offloadind %d fragind %d\n",
602 __func__, __LINE__, peer_id, tid, offload_ind,
603 frag_ind);
604#endif
605 if (cdf_unlikely(frag_ind)) {
606 ol_rx_frag_indication_handler(pdev->txrx_pdev,
607 htt_t2h_msg,
608 peer_id, tid);
609 break;
610 }
611
612 ol_rx_in_order_indication_handler(pdev->txrx_pdev,
613 htt_t2h_msg, peer_id,
614 tid, offload_ind);
615 break;
616 }
617
618 default:
619 htt_t2h_lp_msg_handler(context, htt_t2h_msg);
620 return;
621
622 };
623
624 /* Free the indication buffer */
625 cdf_nbuf_free(htt_t2h_msg);
626}
627
628/*--- target->host HTT message Info Element access methods ------------------*/
629
630/*--- tx completion message ---*/
631
632uint16_t htt_tx_compl_desc_id(void *iterator, int num)
633{
634 /*
635 * The MSDU IDs are packed , 2 per 32-bit word.
636 * Iterate on them as an array of 16-bit elements.
637 * This will work fine if the host endianness matches
638 * the target endianness.
639 * If the host endianness is opposite of the target's,
640 * this iterator will produce descriptor IDs in a different
641 * order than the target inserted them into the message -
642 * if the target puts in [0, 1, 2, 3, ...] the host will
643 * put out [1, 0, 3, 2, ...].
644 * This is fine, except for the last ID if there are an
645 * odd number of IDs. But the TX_COMPL_IND handling code
646 * in the htt_t2h_msg_handler already added a duplicate
647 * of the final ID, if there were an odd number of IDs,
648 * so this function can safely treat the IDs as an array
649 * of 16-bit elements.
650 */
651 return *(((uint16_t *) iterator) + num);
652}
653
654/*--- rx indication message ---*/
655
656int htt_rx_ind_flush(htt_pdev_handle pdev, cdf_nbuf_t rx_ind_msg)
657{
658 uint32_t *msg_word;
659
660 msg_word = (uint32_t *) cdf_nbuf_data(rx_ind_msg);
661 return HTT_RX_IND_FLUSH_VALID_GET(*msg_word);
662}
663
664void
665htt_rx_ind_flush_seq_num_range(htt_pdev_handle pdev,
666 cdf_nbuf_t rx_ind_msg,
667 unsigned *seq_num_start, unsigned *seq_num_end)
668{
669 uint32_t *msg_word;
670
671 msg_word = (uint32_t *) cdf_nbuf_data(rx_ind_msg);
672 msg_word++;
673 *seq_num_start = HTT_RX_IND_FLUSH_SEQ_NUM_START_GET(*msg_word);
674 *seq_num_end = HTT_RX_IND_FLUSH_SEQ_NUM_END_GET(*msg_word);
675}
676
677int htt_rx_ind_release(htt_pdev_handle pdev, cdf_nbuf_t rx_ind_msg)
678{
679 uint32_t *msg_word;
680
681 msg_word = (uint32_t *) cdf_nbuf_data(rx_ind_msg);
682 return HTT_RX_IND_REL_VALID_GET(*msg_word);
683}
684
685void
686htt_rx_ind_release_seq_num_range(htt_pdev_handle pdev,
687 cdf_nbuf_t rx_ind_msg,
688 unsigned *seq_num_start, unsigned *seq_num_end)
689{
690 uint32_t *msg_word;
691
692 msg_word = (uint32_t *) cdf_nbuf_data(rx_ind_msg);
693 msg_word++;
694 *seq_num_start = HTT_RX_IND_REL_SEQ_NUM_START_GET(*msg_word);
695 *seq_num_end = HTT_RX_IND_REL_SEQ_NUM_END_GET(*msg_word);
696}
697
698void
699htt_rx_ind_mpdu_range_info(struct htt_pdev_t *pdev,
700 cdf_nbuf_t rx_ind_msg,
701 int mpdu_range_num,
702 enum htt_rx_status *status, int *mpdu_count)
703{
704 uint32_t *msg_word;
705
706 msg_word = (uint32_t *) cdf_nbuf_data(rx_ind_msg);
707 msg_word += pdev->rx_mpdu_range_offset_words + mpdu_range_num;
708 *status = HTT_RX_IND_MPDU_STATUS_GET(*msg_word);
709 *mpdu_count = HTT_RX_IND_MPDU_COUNT_GET(*msg_word);
710}
711
712/**
713 * htt_rx_ind_rssi_dbm() - Return the RSSI provided in a rx indication message.
714 *
715 * @pdev: the HTT instance the rx data was received on
716 * @rx_ind_msg: the netbuf containing the rx indication message
717 *
718 * Return the RSSI from an rx indication message, in dBm units.
719 *
720 * Return: RSSI in dBm, or HTT_INVALID_RSSI
721 */
722int16_t htt_rx_ind_rssi_dbm(htt_pdev_handle pdev, cdf_nbuf_t rx_ind_msg)
723{
724 int8_t rssi;
725 uint32_t *msg_word;
726
727 msg_word = (uint32_t *)
728 (cdf_nbuf_data(rx_ind_msg) +
729 HTT_RX_IND_FW_RX_PPDU_DESC_BYTE_OFFSET);
730
731 /* check if the RX_IND message contains valid rx PPDU start info */
732 if (!HTT_RX_IND_START_VALID_GET(*msg_word))
733 return HTT_RSSI_INVALID;
734
735 rssi = HTT_RX_IND_RSSI_CMB_GET(*msg_word);
736 return (HTT_TGT_RSSI_INVALID == rssi) ?
737 HTT_RSSI_INVALID : rssi;
738}
739
740/**
741 * htt_rx_ind_rssi_dbm_chain() - Return the RSSI for a chain provided in a rx
742 * indication message.
743 * @pdev: the HTT instance the rx data was received on
744 * @rx_ind_msg: the netbuf containing the rx indication message
745 * @chain: the index of the chain (0-4)
746 *
747 * Return the RSSI for a chain from an rx indication message, in dBm units.
748 *
749 * Return: RSSI, or HTT_INVALID_RSSI
750 */
751int16_t
752htt_rx_ind_rssi_dbm_chain(htt_pdev_handle pdev, cdf_nbuf_t rx_ind_msg,
753 int8_t chain)
754{
755 int8_t rssi;
756 uint32_t *msg_word;
757
758 if (chain < 0 || chain > 3)
759 return HTT_RSSI_INVALID;
760
761 msg_word = (uint32_t *)
762 (cdf_nbuf_data(rx_ind_msg) +
763 HTT_RX_IND_FW_RX_PPDU_DESC_BYTE_OFFSET);
764
765 /* check if the RX_IND message contains valid rx PPDU start info */
766 if (!HTT_RX_IND_START_VALID_GET(*msg_word))
767 return HTT_RSSI_INVALID;
768
769 msg_word += 1 + chain;
770
771 rssi = HTT_RX_IND_RSSI_PRI20_GET(*msg_word);
772 return (HTT_TGT_RSSI_INVALID == rssi) ?
773 HTT_RSSI_INVALID :
774 rssi;
775}
776
777/**
778 * htt_rx_ind_legacy_rate() - Return the data rate
779 * @pdev: the HTT instance the rx data was received on
780 * @rx_ind_msg: the netbuf containing the rx indication message
781 * @legacy_rate: (output) the data rate
782 * The legacy_rate parameter's value depends on the
783 * legacy_rate_sel value.
784 * If legacy_rate_sel is 0:
785 * 0x8: OFDM 48 Mbps
786 * 0x9: OFDM 24 Mbps
787 * 0xA: OFDM 12 Mbps
788 * 0xB: OFDM 6 Mbps
789 * 0xC: OFDM 54 Mbps
790 * 0xD: OFDM 36 Mbps
791 * 0xE: OFDM 18 Mbps
792 * 0xF: OFDM 9 Mbps
793 * If legacy_rate_sel is 1:
794 * 0x8: CCK 11 Mbps long preamble
795 * 0x9: CCK 5.5 Mbps long preamble
796 * 0xA: CCK 2 Mbps long preamble
797 * 0xB: CCK 1 Mbps long preamble
798 * 0xC: CCK 11 Mbps short preamble
799 * 0xD: CCK 5.5 Mbps short preamble
800 * 0xE: CCK 2 Mbps short preamble
801 * -1 on error.
802 * @legacy_rate_sel: (output) 0 to indicate OFDM, 1 to indicate CCK.
803 * -1 on error.
804 *
805 * Return the data rate provided in a rx indication message.
806 */
807void
808htt_rx_ind_legacy_rate(htt_pdev_handle pdev, cdf_nbuf_t rx_ind_msg,
809 uint8_t *legacy_rate, uint8_t *legacy_rate_sel)
810{
811 uint32_t *msg_word;
812
813 msg_word = (uint32_t *)
814 (cdf_nbuf_data(rx_ind_msg) +
815 HTT_RX_IND_FW_RX_PPDU_DESC_BYTE_OFFSET);
816
817 /* check if the RX_IND message contains valid rx PPDU start info */
818 if (!HTT_RX_IND_START_VALID_GET(*msg_word)) {
819 *legacy_rate = -1;
820 *legacy_rate_sel = -1;
821 return;
822 }
823
824 *legacy_rate = HTT_RX_IND_LEGACY_RATE_GET(*msg_word);
825 *legacy_rate_sel = HTT_RX_IND_LEGACY_RATE_SEL_GET(*msg_word);
826}
827
828/**
829 * htt_rx_ind_timestamp() - Return the timestamp
830 * @pdev: the HTT instance the rx data was received on
831 * @rx_ind_msg: the netbuf containing the rx indication message
832 * @timestamp_microsec: (output) the timestamp to microsecond resolution.
833 * -1 on error.
834 * @timestamp_submicrosec: the submicrosecond portion of the
835 * timestamp. -1 on error.
836 *
837 * Return the timestamp provided in a rx indication message.
838 */
839void
840htt_rx_ind_timestamp(htt_pdev_handle pdev, cdf_nbuf_t rx_ind_msg,
841 uint32_t *timestamp_microsec,
842 uint8_t *timestamp_submicrosec)
843{
844 uint32_t *msg_word;
845
846 msg_word = (uint32_t *)
847 (cdf_nbuf_data(rx_ind_msg) +
848 HTT_RX_IND_FW_RX_PPDU_DESC_BYTE_OFFSET);
849
850 /* check if the RX_IND message contains valid rx PPDU start info */
851 if (!HTT_RX_IND_END_VALID_GET(*msg_word)) {
852 *timestamp_microsec = -1;
853 *timestamp_submicrosec = -1;
854 return;
855 }
856
857 *timestamp_microsec = *(msg_word + 6);
858 *timestamp_submicrosec =
859 HTT_RX_IND_TIMESTAMP_SUBMICROSEC_GET(*msg_word);
860}
861
862#define INVALID_TSF -1
863/**
864 * htt_rx_ind_tsf32() - Return the TSF timestamp
865 * @pdev: the HTT instance the rx data was received on
866 * @rx_ind_msg: the netbuf containing the rx indication message
867 *
868 * Return the TSF timestamp provided in a rx indication message.
869 *
870 * Return: TSF timestamp
871 */
872uint32_t
873htt_rx_ind_tsf32(htt_pdev_handle pdev, cdf_nbuf_t rx_ind_msg)
874{
875 uint32_t *msg_word;
876
877 msg_word = (uint32_t *)
878 (cdf_nbuf_data(rx_ind_msg) +
879 HTT_RX_IND_FW_RX_PPDU_DESC_BYTE_OFFSET);
880
881 /* check if the RX_IND message contains valid rx PPDU start info */
882 if (!HTT_RX_IND_END_VALID_GET(*msg_word))
883 return INVALID_TSF;
884
885 return *(msg_word + 5);
886}
887
888/**
889 * htt_rx_ind_ext_tid() - Return the extended traffic ID provided in a rx indication message.
890 * @pdev: the HTT instance the rx data was received on
891 * @rx_ind_msg: the netbuf containing the rx indication message
892 *
893 * Return the extended traffic ID in a rx indication message.
894 *
895 * Return: Extended TID
896 */
897uint8_t
898htt_rx_ind_ext_tid(htt_pdev_handle pdev, cdf_nbuf_t rx_ind_msg)
899{
900 uint32_t *msg_word;
901
902 msg_word = (uint32_t *)
903 (cdf_nbuf_data(rx_ind_msg));
904
905 return HTT_RX_IND_EXT_TID_GET(*msg_word);
906}
907
908/*--- stats confirmation message ---*/
909
910void
911htt_t2h_dbg_stats_hdr_parse(uint8_t *stats_info_list,
912 enum htt_dbg_stats_type *type,
913 enum htt_dbg_stats_status *status,
914 int *length, uint8_t **stats_data)
915{
916 uint32_t *msg_word = (uint32_t *) stats_info_list;
917 *type = HTT_T2H_STATS_CONF_TLV_TYPE_GET(*msg_word);
918 *status = HTT_T2H_STATS_CONF_TLV_STATUS_GET(*msg_word);
919 *length = HTT_T2H_STATS_CONF_TLV_HDR_SIZE + /* header length */
920 HTT_T2H_STATS_CONF_TLV_LENGTH_GET(*msg_word); /* data len */
921 *stats_data = stats_info_list + HTT_T2H_STATS_CONF_TLV_HDR_SIZE;
922}
923
924void
925htt_rx_frag_ind_flush_seq_num_range(htt_pdev_handle pdev,
926 cdf_nbuf_t rx_frag_ind_msg,
927 int *seq_num_start, int *seq_num_end)
928{
929 uint32_t *msg_word;
930
931 msg_word = (uint32_t *) cdf_nbuf_data(rx_frag_ind_msg);
932 msg_word++;
933 *seq_num_start = HTT_RX_FRAG_IND_FLUSH_SEQ_NUM_START_GET(*msg_word);
934 *seq_num_end = HTT_RX_FRAG_IND_FLUSH_SEQ_NUM_END_GET(*msg_word);
935}