1 /*
2 * Copyright (c) 2011, 2014-2019-2020 The Linux Foundation. All rights reserved.
3 * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for
6 * any purpose with or without fee is hereby granted, provided that the
7 * above copyright notice and this permission notice appear in all
8 * copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
18 */
19
20 /**
21 * @file htt.c
22 * @brief Provide functions to create+init and destroy a HTT instance.
23 * @details
24 * This file contains functions for creating a HTT instance; initializing
25 * the HTT instance, e.g. by allocating a pool of HTT tx descriptors and
26 * connecting the HTT service with HTC; and deleting a HTT instance.
27 */
28
29 #include <qdf_mem.h> /* qdf_mem_malloc */
30 #include <qdf_types.h> /* qdf_device_t, qdf_print */
31
32 #include <htt.h> /* htt_tx_msdu_desc_t */
33 #include <ol_cfg.h>
34 #include <ol_txrx_htt_api.h> /* ol_tx_dowload_done_ll, etc. */
35 #include <ol_htt_api.h>
36
37 #include <htt_internal.h>
38 #include <ol_htt_tx_api.h>
39 #include <cds_api.h>
40 #include "hif.h"
41 #include <cdp_txrx_handle.h>
42 #include <ol_txrx_peer_find.h>
43
44 #define HTT_HTC_PKT_POOL_INIT_SIZE 100 /* enough for a large A-MPDU */
45
46 QDF_STATUS(*htt_h2t_rx_ring_cfg_msg)(struct htt_pdev_t *pdev);
47 QDF_STATUS(*htt_h2t_rx_ring_rfs_cfg_msg)(struct htt_pdev_t *pdev);
48
49 #ifdef IPA_OFFLOAD
htt_ipa_config(htt_pdev_handle pdev,QDF_STATUS status)50 static QDF_STATUS htt_ipa_config(htt_pdev_handle pdev, QDF_STATUS status)
51 {
52 if ((QDF_STATUS_SUCCESS == status) &&
53 ol_cfg_ipa_uc_offload_enabled(pdev->ctrl_pdev))
54 status = htt_h2t_ipa_uc_rsc_cfg_msg(pdev);
55 return status;
56 }
57
58 #define HTT_IPA_CONFIG htt_ipa_config
59 #else
60 #define HTT_IPA_CONFIG(pdev, status) status /* no-op */
61 #endif /* IPA_OFFLOAD */
62
htt_htc_pkt_alloc(struct htt_pdev_t * pdev)63 struct htt_htc_pkt *htt_htc_pkt_alloc(struct htt_pdev_t *pdev)
64 {
65 struct htt_htc_pkt_union *pkt = NULL;
66
67 HTT_TX_MUTEX_ACQUIRE(&pdev->htt_tx_mutex);
68 if (pdev->htt_htc_pkt_freelist) {
69 pkt = pdev->htt_htc_pkt_freelist;
70 pdev->htt_htc_pkt_freelist = pdev->htt_htc_pkt_freelist->u.next;
71 }
72 HTT_TX_MUTEX_RELEASE(&pdev->htt_tx_mutex);
73
74 if (!pkt)
75 pkt = qdf_mem_malloc(sizeof(*pkt));
76
77 if (!pkt)
78 return NULL;
79
80 htc_packet_set_magic_cookie(&(pkt->u.pkt.htc_pkt), 0);
81 return &pkt->u.pkt; /* not actually a dereference */
82 }
83
htt_htc_pkt_free(struct htt_pdev_t * pdev,struct htt_htc_pkt * pkt)84 void htt_htc_pkt_free(struct htt_pdev_t *pdev, struct htt_htc_pkt *pkt)
85 {
86 struct htt_htc_pkt_union *u_pkt = (struct htt_htc_pkt_union *)pkt;
87
88 if (!u_pkt) {
89 qdf_print("HTC packet is NULL");
90 return;
91 }
92
93 HTT_TX_MUTEX_ACQUIRE(&pdev->htt_tx_mutex);
94 htc_packet_set_magic_cookie(&(u_pkt->u.pkt.htc_pkt), 0);
95 u_pkt->u.next = pdev->htt_htc_pkt_freelist;
96 pdev->htt_htc_pkt_freelist = u_pkt;
97 HTT_TX_MUTEX_RELEASE(&pdev->htt_tx_mutex);
98 }
99
htt_htc_pkt_pool_free(struct htt_pdev_t * pdev)100 void htt_htc_pkt_pool_free(struct htt_pdev_t *pdev)
101 {
102 struct htt_htc_pkt_union *pkt, *next;
103
104 HTT_TX_MUTEX_ACQUIRE(&pdev->htt_tx_mutex);
105 pkt = pdev->htt_htc_pkt_freelist;
106 pdev->htt_htc_pkt_freelist = NULL;
107 HTT_TX_MUTEX_RELEASE(&pdev->htt_tx_mutex);
108
109 while (pkt) {
110 next = pkt->u.next;
111 qdf_mem_free(pkt);
112 pkt = next;
113 }
114 }
115
116 #ifdef ATH_11AC_TXCOMPACT
117
118 void
htt_htc_misc_pkt_list_trim(struct htt_pdev_t * pdev,int level)119 htt_htc_misc_pkt_list_trim(struct htt_pdev_t *pdev, int level)
120 {
121 struct htt_htc_pkt_union *pkt, *next, *prev = NULL;
122 int i = 0;
123 qdf_nbuf_t netbuf;
124
125 HTT_TX_MUTEX_ACQUIRE(&pdev->htt_tx_mutex);
126 pkt = pdev->htt_htc_pkt_misclist;
127 while (pkt) {
128 next = pkt->u.next;
129 /* trim the out grown list*/
130 if (++i > level) {
131 netbuf =
132 (qdf_nbuf_t)(pkt->u.pkt.htc_pkt.pNetBufContext);
133 qdf_nbuf_unmap(pdev->osdev, netbuf, QDF_DMA_TO_DEVICE);
134 qdf_nbuf_free(netbuf);
135 qdf_mem_free(pkt);
136 pkt = NULL;
137 if (prev)
138 prev->u.next = NULL;
139 }
140 prev = pkt;
141 pkt = next;
142 }
143 HTT_TX_MUTEX_RELEASE(&pdev->htt_tx_mutex);
144 }
145
htt_htc_misc_pkt_list_add(struct htt_pdev_t * pdev,struct htt_htc_pkt * pkt)146 void htt_htc_misc_pkt_list_add(struct htt_pdev_t *pdev, struct htt_htc_pkt *pkt)
147 {
148 struct htt_htc_pkt_union *u_pkt = (struct htt_htc_pkt_union *)pkt;
149 int misclist_trim_level = htc_get_tx_queue_depth(pdev->htc_pdev,
150 pkt->htc_pkt.Endpoint)
151 + HTT_HTC_PKT_MISCLIST_SIZE;
152
153 HTT_TX_MUTEX_ACQUIRE(&pdev->htt_tx_mutex);
154 if (pdev->htt_htc_pkt_misclist) {
155 u_pkt->u.next = pdev->htt_htc_pkt_misclist;
156 pdev->htt_htc_pkt_misclist = u_pkt;
157 } else {
158 pdev->htt_htc_pkt_misclist = u_pkt;
159 }
160 HTT_TX_MUTEX_RELEASE(&pdev->htt_tx_mutex);
161
162 /* only ce pipe size + tx_queue_depth could possibly be in use
163 * free older packets in the msiclist
164 */
165 htt_htc_misc_pkt_list_trim(pdev, misclist_trim_level);
166 }
167
htt_htc_misc_pkt_pool_free(struct htt_pdev_t * pdev)168 void htt_htc_misc_pkt_pool_free(struct htt_pdev_t *pdev)
169 {
170 struct htt_htc_pkt_union *pkt, *next;
171 qdf_nbuf_t netbuf;
172
173 HTT_TX_MUTEX_ACQUIRE(&pdev->htt_tx_mutex);
174 pkt = pdev->htt_htc_pkt_misclist;
175 pdev->htt_htc_pkt_misclist = NULL;
176 HTT_TX_MUTEX_RELEASE(&pdev->htt_tx_mutex);
177
178 while (pkt) {
179 next = pkt->u.next;
180 if (htc_packet_get_magic_cookie(&(pkt->u.pkt.htc_pkt)) !=
181 HTC_PACKET_MAGIC_COOKIE) {
182 QDF_ASSERT(0);
183 pkt = next;
184 continue;
185 }
186
187 netbuf = (qdf_nbuf_t) (pkt->u.pkt.htc_pkt.pNetBufContext);
188 qdf_nbuf_unmap(pdev->osdev, netbuf, QDF_DMA_TO_DEVICE);
189 qdf_nbuf_free(netbuf);
190 qdf_mem_free(pkt);
191 pkt = next;
192 }
193 }
194 #endif
195
196
197 /* AR6004 don't need HTT layer. */
198 #ifdef AR6004_HW
199 #define NO_HTT_NEEDED true
200 #else
201 #define NO_HTT_NEEDED false
202 #endif
203
204 #if defined(QCA_TX_HTT2_SUPPORT) && defined(CONFIG_HL_SUPPORT)
205
206 /**
207 * htt_htc_tx_htt2_service_start() - Start TX HTT2 service
208 *
209 * @pdev: pointer to htt device.
210 * @connect_req: pointer to service connection request information
211 * @connect_resp: pointer to service connection response information
212 *
213 *
214 * Return: None
215 */
216 static void
htt_htc_tx_htt2_service_start(struct htt_pdev_t * pdev,struct htc_service_connect_req * connect_req,struct htc_service_connect_resp * connect_resp)217 htt_htc_tx_htt2_service_start(struct htt_pdev_t *pdev,
218 struct htc_service_connect_req *connect_req,
219 struct htc_service_connect_resp *connect_resp)
220 {
221 QDF_STATUS status;
222
223 qdf_mem_zero(connect_req, sizeof(struct htc_service_connect_req));
224 qdf_mem_zero(connect_resp, sizeof(struct htc_service_connect_resp));
225
226 /* The same as HTT service but no RX. */
227 connect_req->EpCallbacks.pContext = pdev;
228 connect_req->EpCallbacks.EpTxComplete = htt_h2t_send_complete;
229 connect_req->EpCallbacks.EpSendFull = htt_h2t_full;
230 connect_req->MaxSendQueueDepth = HTT_MAX_SEND_QUEUE_DEPTH;
231 /* Should NOT support credit flow control. */
232 connect_req->ConnectionFlags |=
233 HTC_CONNECT_FLAGS_DISABLE_CREDIT_FLOW_CTRL;
234 /* Enable HTC schedule mechanism for TX HTT2 service. */
235 connect_req->ConnectionFlags |= HTC_CONNECT_FLAGS_ENABLE_HTC_SCHEDULE;
236
237 connect_req->service_id = HTT_DATA2_MSG_SVC;
238
239 status = htc_connect_service(pdev->htc_pdev, connect_req, connect_resp);
240
241 if (status != QDF_STATUS_SUCCESS) {
242 pdev->htc_tx_htt2_endpoint = ENDPOINT_UNUSED;
243 pdev->htc_tx_htt2_max_size = 0;
244 } else {
245 pdev->htc_tx_htt2_endpoint = connect_resp->Endpoint;
246 pdev->htc_tx_htt2_max_size = HTC_TX_HTT2_MAX_SIZE;
247 }
248
249 qdf_print("TX HTT %s, ep %d size %d\n",
250 (status == QDF_STATUS_SUCCESS ? "ON" : "OFF"),
251 pdev->htc_tx_htt2_endpoint,
252 pdev->htc_tx_htt2_max_size);
253 }
254 #else
255
256 static inline void
htt_htc_tx_htt2_service_start(struct htt_pdev_t * pdev,struct htc_service_connect_req * connect_req,struct htc_service_connect_resp * connect_resp)257 htt_htc_tx_htt2_service_start(struct htt_pdev_t *pdev,
258 struct htc_service_connect_req *connect_req,
259 struct htc_service_connect_resp *connect_resp)
260 {
261 }
262 #endif
263
264 /**
265 * htt_htc_credit_flow_disable() - disable flow control for
266 * HTT data message service
267 *
268 * @pdev: pointer to htt device.
269 * @connect_req: pointer to service connection request information
270 *
271 * HTC Credit mechanism is disabled based on
272 * default_tx_comp_req as throughput will be lower
273 * if we disable htc credit mechanism with default_tx_comp_req
274 * set since txrx download packet will be limited by ota
275 * completion.
276 *
277 * Return: None
278 */
279 static
htt_htc_credit_flow_disable(struct htt_pdev_t * pdev,struct htc_service_connect_req * connect_req)280 void htt_htc_credit_flow_disable(struct htt_pdev_t *pdev,
281 struct htc_service_connect_req *connect_req)
282 {
283 if (pdev->osdev->bus_type == QDF_BUS_TYPE_SDIO) {
284 /*
285 * TODO:Conditional disabling will be removed once firmware
286 * with reduced tx completion is pushed into release builds.
287 */
288 if (!pdev->cfg.default_tx_comp_req)
289 connect_req->ConnectionFlags |=
290 HTC_CONNECT_FLAGS_DISABLE_CREDIT_FLOW_CTRL;
291 } else {
292 connect_req->ConnectionFlags |=
293 HTC_CONNECT_FLAGS_DISABLE_CREDIT_FLOW_CTRL;
294 }
295 }
296
297 #if defined(DEBUG_HL_LOGGING) && defined(CONFIG_HL_SUPPORT)
298
299 /**
300 * htt_dump_bundle_stats() - dump wlan stats
301 * @pdev: handle to the HTT instance
302 *
303 * Return: None
304 */
htt_dump_bundle_stats(htt_pdev_handle pdev)305 void htt_dump_bundle_stats(htt_pdev_handle pdev)
306 {
307 htc_dump_bundle_stats(pdev->htc_pdev);
308 }
309
310 /**
311 * htt_clear_bundle_stats() - clear wlan stats
312 * @pdev: handle to the HTT instance
313 *
314 * Return: None
315 */
htt_clear_bundle_stats(htt_pdev_handle pdev)316 void htt_clear_bundle_stats(htt_pdev_handle pdev)
317 {
318 htc_clear_bundle_stats(pdev->htc_pdev);
319 }
320 #endif
321
322 #if defined(QCA_WIFI_3_0_ADRASTEA)
323 /**
324 * htt_htc_attach_all() - Connect to HTC service for HTT
325 * @pdev: pdev ptr
326 *
327 * Return: 0 for success or error code.
328 */
329
330 #if defined(QCN7605_SUPPORT) && defined(IPA_OFFLOAD)
331
332 /* In case of QCN7605 with IPA offload only 2 CE
333 * are used for RFS
334 */
335 static int
htt_htc_attach_all(struct htt_pdev_t * pdev)336 htt_htc_attach_all(struct htt_pdev_t *pdev)
337 {
338 if (htt_htc_attach(pdev, HTT_DATA_MSG_SVC))
339 goto flush_endpoint;
340
341 if (htt_htc_attach(pdev, HTT_DATA2_MSG_SVC))
342 goto flush_endpoint;
343
344 return 0;
345
346 flush_endpoint:
347 htc_flush_endpoint(pdev->htc_pdev, ENDPOINT_0, HTC_TX_PACKET_TAG_ALL);
348
349 return -EIO;
350 }
351
352 #else
353
354 static int
htt_htc_attach_all(struct htt_pdev_t * pdev)355 htt_htc_attach_all(struct htt_pdev_t *pdev)
356 {
357 if (htt_htc_attach(pdev, HTT_DATA_MSG_SVC))
358 goto flush_endpoint;
359
360 if (htt_htc_attach(pdev, HTT_DATA2_MSG_SVC))
361 goto flush_endpoint;
362
363 if (htt_htc_attach(pdev, HTT_DATA3_MSG_SVC))
364 goto flush_endpoint;
365
366 return 0;
367
368 flush_endpoint:
369 htc_flush_endpoint(pdev->htc_pdev, ENDPOINT_0, HTC_TX_PACKET_TAG_ALL);
370
371 return -EIO;
372 }
373
374 #endif
375
376 #else
377 /**
378 * htt_htc_attach_all() - Connect to HTC service for HTT
379 * @pdev: pdev ptr
380 *
381 * Return: 0 for success or error code.
382 */
383 static int
htt_htc_attach_all(struct htt_pdev_t * pdev)384 htt_htc_attach_all(struct htt_pdev_t *pdev)
385 {
386 return htt_htc_attach(pdev, HTT_DATA_MSG_SVC);
387 }
388 #endif
389
390 /**
391 * htt_pdev_alloc() - allocate HTT pdev
392 * @txrx_pdev: txrx pdev
393 * @ctrl_pdev: cfg pdev
394 * @htc_pdev: HTC pdev
395 * @osdev: os device
396 *
397 * Return: HTT pdev handle
398 */
399 htt_pdev_handle
htt_pdev_alloc(ol_txrx_pdev_handle txrx_pdev,struct cdp_cfg * ctrl_pdev,HTC_HANDLE htc_pdev,qdf_device_t osdev)400 htt_pdev_alloc(ol_txrx_pdev_handle txrx_pdev,
401 struct cdp_cfg *ctrl_pdev,
402 HTC_HANDLE htc_pdev, qdf_device_t osdev)
403 {
404 struct htt_pdev_t *pdev;
405 struct hif_opaque_softc *osc = cds_get_context(QDF_MODULE_ID_HIF);
406
407 if (!osc)
408 goto fail1;
409
410 pdev = qdf_mem_malloc(sizeof(*pdev));
411 if (!pdev)
412 goto fail1;
413
414 pdev->osdev = osdev;
415 pdev->ctrl_pdev = ctrl_pdev;
416 pdev->txrx_pdev = txrx_pdev;
417 pdev->htc_pdev = htc_pdev;
418
419 pdev->htt_htc_pkt_freelist = NULL;
420 #ifdef ATH_11AC_TXCOMPACT
421 pdev->htt_htc_pkt_misclist = NULL;
422 #endif
423
424 /* for efficiency, store a local copy of the is_high_latency flag */
425 pdev->cfg.is_high_latency = ol_cfg_is_high_latency(pdev->ctrl_pdev);
426 /*
427 * Credit reporting through HTT_T2H_MSG_TYPE_TX_CREDIT_UPDATE_IND
428 * enabled or not.
429 */
430 pdev->cfg.credit_update_enabled =
431 ol_cfg_is_credit_update_enabled(pdev->ctrl_pdev);
432
433 pdev->cfg.request_tx_comp = cds_is_ptp_rx_opt_enabled() ||
434 cds_is_packet_log_enabled();
435
436 pdev->cfg.default_tx_comp_req =
437 !ol_cfg_tx_free_at_download(pdev->ctrl_pdev);
438
439 pdev->cfg.is_full_reorder_offload =
440 ol_cfg_is_full_reorder_offload(pdev->ctrl_pdev);
441 QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_INFO_LOW,
442 "full_reorder_offloaded %d",
443 (int)pdev->cfg.is_full_reorder_offload);
444
445 pdev->cfg.ce_classify_enabled =
446 ol_cfg_is_ce_classify_enabled(ctrl_pdev);
447 QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_INFO_LOW,
448 "ce_classify %d",
449 pdev->cfg.ce_classify_enabled);
450
451 if (pdev->cfg.is_high_latency) {
452 qdf_atomic_init(&pdev->htt_tx_credit.target_delta);
453 qdf_atomic_init(&pdev->htt_tx_credit.bus_delta);
454 qdf_atomic_add(HTT_MAX_BUS_CREDIT,
455 &pdev->htt_tx_credit.bus_delta);
456 }
457
458 pdev->targetdef = htc_get_targetdef(htc_pdev);
459 #if defined(HELIUMPLUS)
460 HTT_SET_WIFI_IP(pdev, 2, 0);
461 #endif /* defined(HELIUMPLUS) */
462
463 if (NO_HTT_NEEDED)
464 goto success;
465 /*
466 * Connect to HTC service.
467 * This has to be done before calling htt_rx_attach,
468 * since htt_rx_attach involves sending a rx ring configure
469 * message to the target.
470 */
471 HTT_TX_MUTEX_INIT(&pdev->htt_tx_mutex);
472 HTT_TX_NBUF_QUEUE_MUTEX_INIT(pdev);
473 HTT_TX_MUTEX_INIT(&pdev->credit_mutex);
474 if (htt_htc_attach_all(pdev))
475 goto htt_htc_attach_fail;
476 if (hif_ce_fastpath_cb_register(osc, htt_t2h_msg_handler_fast, pdev))
477 qdf_print("failed to register fastpath callback\n");
478
479 success:
480 return pdev;
481
482 htt_htc_attach_fail:
483 HTT_TX_MUTEX_DESTROY(&pdev->credit_mutex);
484 HTT_TX_MUTEX_DESTROY(&pdev->htt_tx_mutex);
485 HTT_TX_NBUF_QUEUE_MUTEX_DESTROY(pdev);
486 qdf_mem_free(pdev);
487
488 fail1:
489 return NULL;
490
491 }
492
493 /**
494 * htt_attach() - Allocate and setup HTT TX/RX descriptors
495 * @pdev: pdev ptr
496 * @desc_pool_size: size of tx descriptors
497 *
498 * Return: 0 for success or error code.
499 */
500 int
htt_attach(struct htt_pdev_t * pdev,int desc_pool_size)501 htt_attach(struct htt_pdev_t *pdev, int desc_pool_size)
502 {
503 int i;
504 int ret = 0;
505
506 pdev->is_ipa_uc_enabled = false;
507 if (ol_cfg_ipa_uc_offload_enabled(pdev->ctrl_pdev))
508 pdev->is_ipa_uc_enabled = true;
509
510 pdev->new_htt_format_enabled = false;
511 if (ol_cfg_is_htt_new_format_enabled(pdev->ctrl_pdev))
512 pdev->new_htt_format_enabled = true;
513
514 htc_enable_hdr_length_check(pdev->htc_pdev,
515 pdev->new_htt_format_enabled);
516
517 ret = htt_tx_attach(pdev, desc_pool_size);
518 if (ret)
519 goto fail1;
520
521 ret = htt_rx_attach(pdev);
522 if (ret)
523 goto fail2;
524
525 /* pre-allocate some HTC_PACKET objects */
526 for (i = 0; i < HTT_HTC_PKT_POOL_INIT_SIZE; i++) {
527 struct htt_htc_pkt_union *pkt;
528
529 pkt = qdf_mem_malloc(sizeof(*pkt));
530 if (!pkt)
531 break;
532 htt_htc_pkt_free(pdev, &pkt->u.pkt);
533 }
534
535 if (pdev->cfg.is_high_latency) {
536 /*
537 * HL - download the whole frame.
538 * Specify a download length greater than the max MSDU size,
539 * so the downloads will be limited by the actual frame sizes.
540 */
541 pdev->download_len = 5000;
542
543 if (ol_cfg_tx_free_at_download(pdev->ctrl_pdev) &&
544 !pdev->cfg.request_tx_comp)
545 pdev->tx_send_complete_part2 =
546 ol_tx_download_done_hl_free;
547 else
548 pdev->tx_send_complete_part2 =
549 ol_tx_download_done_hl_retain;
550
551 /*
552 * CHECK THIS LATER: does the HL HTT version of
553 * htt_rx_mpdu_desc_list_next
554 * (which is not currently implemented) present the
555 * adf_nbuf_data(rx_ind_msg)
556 * as the abstract rx descriptor?
557 * If not, the rx_fw_desc_offset initialization
558 * here will have to be adjusted accordingly.
559 * NOTE: for HL, because fw rx desc is in ind msg,
560 * not in rx desc, so the
561 * offset should be negative value
562 */
563 pdev->rx_fw_desc_offset =
564 HTT_ENDIAN_BYTE_IDX_SWAP(
565 HTT_RX_IND_FW_RX_DESC_BYTE_OFFSET
566 - HTT_RX_IND_HL_BYTES);
567
568 htt_h2t_rx_ring_cfg_msg = htt_h2t_rx_ring_cfg_msg_hl;
569 htt_h2t_rx_ring_rfs_cfg_msg = htt_h2t_rx_ring_rfs_cfg_msg_hl;
570
571 /* initialize the txrx credit count */
572 ol_tx_target_credit_update(
573 pdev->txrx_pdev, ol_cfg_target_tx_credit(
574 pdev->ctrl_pdev));
575 DPTRACE(qdf_dp_trace_credit_record(QDF_HTT_ATTACH,
576 QDF_CREDIT_INC,
577 ol_cfg_target_tx_credit(pdev->ctrl_pdev),
578 qdf_atomic_read(&pdev->txrx_pdev->target_tx_credit),
579 qdf_atomic_read(&pdev->txrx_pdev->txq_grps[0].credit),
580 qdf_atomic_read(&pdev->txrx_pdev->txq_grps[1].credit)));
581
582 } else {
583 enum wlan_frm_fmt frm_type;
584
585 /*
586 * LL - download just the initial portion of the frame.
587 * Download enough to cover the encapsulation headers checked
588 * by the target's tx classification descriptor engine.
589 *
590 * For LL, the FW rx desc directly referenced at its location
591 * inside the rx indication message.
592 */
593
594 /* account for the 802.3 or 802.11 header */
595 frm_type = ol_cfg_frame_type(pdev->ctrl_pdev);
596
597 if (frm_type == wlan_frm_fmt_native_wifi) {
598 pdev->download_len = HTT_TX_HDR_SIZE_NATIVE_WIFI;
599 } else if (frm_type == wlan_frm_fmt_802_3) {
600 pdev->download_len = HTT_TX_HDR_SIZE_ETHERNET;
601 } else {
602 QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
603 "Unexpected frame type spec: %d", frm_type);
604 HTT_ASSERT0(0);
605 }
606
607 /*
608 * Account for the optional L2 / ethernet header fields:
609 * 802.1Q, LLC/SNAP
610 */
611 pdev->download_len +=
612 HTT_TX_HDR_SIZE_802_1Q + HTT_TX_HDR_SIZE_LLC_SNAP;
613
614 /*
615 * Account for the portion of the L3 (IP) payload that the
616 * target needs for its tx classification.
617 */
618 pdev->download_len += ol_cfg_tx_download_size(pdev->ctrl_pdev);
619
620 /*
621 * Account for the HTT tx descriptor, including the
622 * HTC header + alignment padding.
623 */
624 pdev->download_len += sizeof(struct htt_host_tx_desc_t);
625
626 /*
627 * The TXCOMPACT htt_tx_sched function uses pdev->download_len
628 * to apply for all requeued tx frames. Thus,
629 * pdev->download_len has to be the largest download length of
630 * any tx frame that will be downloaded.
631 * This maximum download length is for management tx frames,
632 * which have an 802.11 header.
633 */
634 #ifdef ATH_11AC_TXCOMPACT
635 pdev->download_len = sizeof(struct htt_host_tx_desc_t)
636 + HTT_TX_HDR_SIZE_OUTER_HDR_MAX /* worst case */
637 + HTT_TX_HDR_SIZE_802_1Q
638 + HTT_TX_HDR_SIZE_LLC_SNAP
639 + ol_cfg_tx_download_size(pdev->ctrl_pdev);
640 #endif
641 pdev->tx_send_complete_part2 = ol_tx_download_done_ll;
642
643 /*
644 * For LL, the FW rx desc is alongside the HW rx desc fields in
645 * the htt_host_rx_desc_base struct/.
646 */
647 pdev->rx_fw_desc_offset = RX_STD_DESC_FW_MSDU_OFFSET;
648
649 htt_h2t_rx_ring_cfg_msg = htt_h2t_rx_ring_cfg_msg_ll;
650 htt_h2t_rx_ring_rfs_cfg_msg = htt_h2t_rx_ring_rfs_cfg_msg_ll;
651 }
652
653 return 0;
654
655 fail2:
656 htt_tx_detach(pdev);
657
658 fail1:
659 return ret;
660 }
661
htt_attach_target(htt_pdev_handle pdev)662 QDF_STATUS htt_attach_target(htt_pdev_handle pdev)
663 {
664 QDF_STATUS status;
665
666 status = htt_h2t_ver_req_msg(pdev);
667 if (status != QDF_STATUS_SUCCESS) {
668 QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
669 "%s:%d: could not send h2t_ver_req msg",
670 __func__, __LINE__);
671 return status;
672 }
673 #if defined(HELIUMPLUS)
674 /*
675 * Send the frag_desc info to target.
676 */
677 status = htt_h2t_frag_desc_bank_cfg_msg(pdev);
678 if (status != QDF_STATUS_SUCCESS) {
679 QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
680 "%s:%d: could not send h2t_frag_desc_bank_cfg msg",
681 __func__, __LINE__);
682 return status;
683 }
684 #endif /* defined(HELIUMPLUS) */
685
686
687 /*
688 * If applicable, send the rx ring config message to the target.
689 * The host could wait for the HTT version number confirmation message
690 * from the target before sending any further HTT messages, but it's
691 * reasonable to assume that the host and target HTT version numbers
692 * match, and proceed immediately with the remaining configuration
693 * handshaking.
694 */
695
696 status = htt_h2t_rx_ring_rfs_cfg_msg(pdev);
697 if (status != QDF_STATUS_SUCCESS) {
698 QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
699 "%s:%d: could not send h2t_rx_ring_rfs_cfg msg",
700 __func__, __LINE__);
701 return status;
702 }
703
704 status = htt_h2t_rx_ring_cfg_msg(pdev);
705 if (status != QDF_STATUS_SUCCESS) {
706 QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
707 "%s:%d: could not send h2t_rx_ring_cfg msg",
708 __func__, __LINE__);
709 return status;
710 }
711
712 status = HTT_IPA_CONFIG(pdev, status);
713 if (status != QDF_STATUS_SUCCESS) {
714 QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
715 "%s:%d: could not send h2t_ipa_uc_rsc_cfg msg",
716 __func__, __LINE__);
717 return status;
718 }
719
720 return status;
721 }
722
htt_detach(htt_pdev_handle pdev)723 void htt_detach(htt_pdev_handle pdev)
724 {
725 htt_rx_detach(pdev);
726 htt_tx_detach(pdev);
727 htt_htc_pkt_pool_free(pdev);
728 #ifdef ATH_11AC_TXCOMPACT
729 htt_htc_misc_pkt_pool_free(pdev);
730 #endif
731 HTT_TX_MUTEX_DESTROY(&pdev->credit_mutex);
732 HTT_TX_MUTEX_DESTROY(&pdev->htt_tx_mutex);
733 HTT_TX_NBUF_QUEUE_MUTEX_DESTROY(pdev);
734 }
735
736 /**
737 * htt_pdev_free() - Free HTT pdev
738 * @pdev: htt pdev
739 *
740 * Return: none
741 */
htt_pdev_free(htt_pdev_handle pdev)742 void htt_pdev_free(htt_pdev_handle pdev)
743 {
744 qdf_mem_free(pdev);
745 }
746
htt_detach_target(htt_pdev_handle pdev)747 void htt_detach_target(htt_pdev_handle pdev)
748 {
749 }
750
751 static inline
htt_update_endpoint(struct htt_pdev_t * pdev,uint16_t service_id,HTC_ENDPOINT_ID ep)752 int htt_update_endpoint(struct htt_pdev_t *pdev,
753 uint16_t service_id, HTC_ENDPOINT_ID ep)
754 {
755 struct hif_opaque_softc *hif_ctx;
756 uint8_t ul = 0xff, dl = 0xff;
757 int ul_polled, dl_polled;
758 int tx_service = 0;
759 int rc = 0;
760
761 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
762 if (qdf_unlikely(!hif_ctx)) {
763 QDF_ASSERT(hif_ctx);
764 QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
765 "%s:%d: assuming non-tx service.",
766 __func__, __LINE__);
767 } else {
768 ul = dl = 0xff;
769 if (QDF_STATUS_SUCCESS !=
770 hif_map_service_to_pipe(hif_ctx, service_id,
771 &ul, &dl,
772 &ul_polled, &dl_polled))
773 QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_INFO,
774 "%s:%d: assuming non-tx srv.",
775 __func__, __LINE__);
776 else
777 tx_service = (ul != 0xff);
778 }
779 if (tx_service) {
780 /* currently we have only one OUT htt tx service */
781 QDF_BUG(service_id == HTT_DATA_MSG_SVC);
782
783 pdev->htc_tx_endpoint = ep;
784 hif_save_htc_htt_config_endpoint(hif_ctx, ep);
785 rc = 1;
786 }
787 return rc;
788 }
789
htt_htc_attach(struct htt_pdev_t * pdev,uint16_t service_id)790 int htt_htc_attach(struct htt_pdev_t *pdev, uint16_t service_id)
791 {
792 struct htc_service_connect_req connect;
793 struct htc_service_connect_resp response;
794 QDF_STATUS status;
795
796 qdf_mem_zero(&connect, sizeof(connect));
797 qdf_mem_zero(&response, sizeof(response));
798
799 connect.pMetaData = NULL;
800 connect.MetaDataLength = 0;
801 connect.EpCallbacks.pContext = pdev;
802 connect.EpCallbacks.EpTxComplete = htt_h2t_send_complete;
803 connect.EpCallbacks.EpTxCompleteMultiple = NULL;
804 connect.EpCallbacks.EpRecv = htt_t2h_msg_handler;
805 connect.EpCallbacks.ep_resume_tx_queue = htt_tx_resume_handler;
806 connect.EpCallbacks.ep_padding_credit_update =
807 htt_tx_padding_credit_update_handler;
808
809 /* rx buffers currently are provided by HIF, not by EpRecvRefill */
810 connect.EpCallbacks.EpRecvRefill = NULL;
811 connect.EpCallbacks.RecvRefillWaterMark = 1;
812 /* N/A, fill is done by HIF */
813
814 connect.EpCallbacks.EpSendFull = htt_h2t_full;
815 /*
816 * Specify how deep to let a queue get before htc_send_pkt will
817 * call the EpSendFull function due to excessive send queue depth.
818 */
819 connect.MaxSendQueueDepth = HTT_MAX_SEND_QUEUE_DEPTH;
820
821 /* disable flow control for HTT data message service */
822 htt_htc_credit_flow_disable(pdev, &connect);
823
824 /* connect to control service */
825 connect.service_id = service_id;
826
827 status = htc_connect_service(pdev->htc_pdev, &connect, &response);
828
829 if (status != QDF_STATUS_SUCCESS) {
830 if (cds_is_fw_down())
831 return -EIO;
832
833 if (status == QDF_STATUS_E_NOMEM ||
834 cds_is_self_recovery_enabled())
835 return qdf_status_to_os_return(status);
836
837 QDF_BUG(0);
838 }
839
840 htt_update_endpoint(pdev, service_id, response.Endpoint);
841
842 /* Start TX HTT2 service if the target support it. */
843 htt_htc_tx_htt2_service_start(pdev, &connect, &response);
844
845 return 0; /* success */
846 }
847
htt_log_rx_ring_info(htt_pdev_handle pdev)848 void htt_log_rx_ring_info(htt_pdev_handle pdev)
849 {
850 if (!pdev) {
851 QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
852 "%s: htt pdev is NULL", __func__);
853 return;
854 }
855 QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_DEBUG,
856 "%s: Data Stall Detected with reason 4 (=FW_RX_REFILL_FAILED)."
857 "src htt rx ring: space for %d elements, filled with %d buffers, buffers in the ring %d, refill debt %d",
858 __func__, pdev->rx_ring.size, pdev->rx_ring.fill_level,
859 qdf_atomic_read(&pdev->rx_ring.fill_cnt),
860 qdf_atomic_read(&pdev->rx_ring.refill_debt));
861 }
862
htt_rx_refill_failure(htt_pdev_handle pdev)863 void htt_rx_refill_failure(htt_pdev_handle pdev)
864 {
865 QDF_BUG(qdf_atomic_read(&pdev->rx_ring.refill_debt));
866 }
867
868 #if HTT_DEBUG_LEVEL > 5
htt_display(htt_pdev_handle pdev,int indent)869 void htt_display(htt_pdev_handle pdev, int indent)
870 {
871 qdf_print("%*s%s:\n", indent, " ", "HTT");
872 qdf_print("%*stx desc pool: %d elems of %d bytes, %d allocated\n",
873 indent + 4, " ",
874 pdev->tx_descs.pool_elems,
875 pdev->tx_descs.size, pdev->tx_descs.alloc_cnt);
876 qdf_print("%*srx ring: space for %d elems, filled with %d buffers\n",
877 indent + 4, " ",
878 pdev->rx_ring.size, pdev->rx_ring.fill_level);
879 qdf_print("%*sat %pK (%llx paddr)\n", indent + 8, " ",
880 pdev->rx_ring.buf.paddrs_ring,
881 (unsigned long long)pdev->rx_ring.base_paddr);
882 qdf_print("%*snetbuf ring @ %pK\n", indent + 8, " ",
883 pdev->rx_ring.buf.netbufs_ring);
884 qdf_print("%*sFW_IDX shadow register: vaddr = %pK, paddr = %llx\n",
885 indent + 8, " ",
886 pdev->rx_ring.alloc_idx.vaddr,
887 (unsigned long long)pdev->rx_ring.alloc_idx.paddr);
888 qdf_print("%*sSW enqueue idx= %d, SW dequeue idx: desc= %d, buf= %d\n",
889 indent + 8, " ", *pdev->rx_ring.alloc_idx.vaddr,
890 pdev->rx_ring.sw_rd_idx.msdu_desc,
891 pdev->rx_ring.sw_rd_idx.msdu_payld);
892 }
893 #endif
894
895 #ifdef IPA_OFFLOAD
896 /**
897 * htt_ipa_uc_attach() - Allocate UC data path resources
898 * @pdev: handle to the HTT instance
899 *
900 * Return: 0 success
901 * none 0 fail
902 */
htt_ipa_uc_attach(struct htt_pdev_t * pdev)903 int htt_ipa_uc_attach(struct htt_pdev_t *pdev)
904 {
905 int error;
906
907 QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_DEBUG, "%s: enter",
908 __func__);
909
910 /* TX resource attach */
911 error = htt_tx_ipa_uc_attach(
912 pdev,
913 ol_cfg_ipa_uc_tx_buf_size(pdev->ctrl_pdev),
914 ol_cfg_ipa_uc_tx_max_buf_cnt(pdev->ctrl_pdev),
915 ol_cfg_ipa_uc_tx_partition_base(pdev->ctrl_pdev));
916 if (error) {
917 QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
918 "HTT IPA UC TX attach fail code %d", error);
919 HTT_ASSERT0(0);
920 return error;
921 }
922
923 /* RX resource attach */
924 error = htt_rx_ipa_uc_attach(
925 pdev, qdf_get_pwr2(pdev->rx_ring.fill_level));
926 if (error) {
927 QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
928 "HTT IPA UC RX attach fail code %d", error);
929 htt_tx_ipa_uc_detach(pdev);
930 HTT_ASSERT0(0);
931 return error;
932 }
933
934 QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_DEBUG, "%s: exit",
935 __func__);
936 return 0; /* success */
937 }
938
939 /**
940 * htt_ipa_uc_attach() - Remove UC data path resources
941 * @pdev: handle to the HTT instance
942 *
943 * Return: None
944 */
htt_ipa_uc_detach(struct htt_pdev_t * pdev)945 void htt_ipa_uc_detach(struct htt_pdev_t *pdev)
946 {
947 QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_DEBUG, "%s: enter",
948 __func__);
949
950 /* TX IPA micro controller detach */
951 htt_tx_ipa_uc_detach(pdev);
952
953 /* RX IPA micro controller detach */
954 htt_rx_ipa_uc_detach(pdev);
955
956 QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_DEBUG, "%s: exit",
957 __func__);
958 }
959
960 int
htt_ipa_uc_get_resource(htt_pdev_handle pdev,qdf_shared_mem_t ** ce_sr,qdf_shared_mem_t ** tx_comp_ring,qdf_shared_mem_t ** rx_rdy_ring,qdf_shared_mem_t ** rx2_rdy_ring,qdf_shared_mem_t ** rx_proc_done_idx,qdf_shared_mem_t ** rx2_proc_done_idx,uint32_t * ce_sr_ring_size,qdf_dma_addr_t * ce_reg_paddr,uint32_t * tx_num_alloc_buffer)961 htt_ipa_uc_get_resource(htt_pdev_handle pdev,
962 qdf_shared_mem_t **ce_sr,
963 qdf_shared_mem_t **tx_comp_ring,
964 qdf_shared_mem_t **rx_rdy_ring,
965 qdf_shared_mem_t **rx2_rdy_ring,
966 qdf_shared_mem_t **rx_proc_done_idx,
967 qdf_shared_mem_t **rx2_proc_done_idx,
968 uint32_t *ce_sr_ring_size,
969 qdf_dma_addr_t *ce_reg_paddr,
970 uint32_t *tx_num_alloc_buffer)
971 {
972 /* Release allocated resource to client */
973 *tx_comp_ring = pdev->ipa_uc_tx_rsc.tx_comp_ring;
974 *rx_rdy_ring = pdev->ipa_uc_rx_rsc.rx_ind_ring;
975 *rx2_rdy_ring = pdev->ipa_uc_rx_rsc.rx2_ind_ring;
976 *rx_proc_done_idx = pdev->ipa_uc_rx_rsc.rx_ipa_prc_done_idx;
977 *rx2_proc_done_idx = pdev->ipa_uc_rx_rsc.rx2_ipa_prc_done_idx;
978 *tx_num_alloc_buffer = (uint32_t)pdev->ipa_uc_tx_rsc.alloc_tx_buf_cnt;
979
980 /* Get copy engine, bus resource */
981 htc_ipa_get_ce_resource(pdev->htc_pdev, ce_sr,
982 ce_sr_ring_size, ce_reg_paddr);
983
984 return 0;
985 }
986
987 /**
988 * htt_ipa_uc_set_doorbell_paddr() - Propagate IPA doorbell address
989 * @pdev: handle to the HTT instance
990 * @ipa_uc_tx_doorbell_paddr: TX doorbell base physical address
991 * @ipa_uc_rx_doorbell_paddr: RX doorbell base physical address
992 *
993 * Return: 0 success
994 */
995 int
htt_ipa_uc_set_doorbell_paddr(htt_pdev_handle pdev,qdf_dma_addr_t ipa_uc_tx_doorbell_paddr,qdf_dma_addr_t ipa_uc_rx_doorbell_paddr)996 htt_ipa_uc_set_doorbell_paddr(htt_pdev_handle pdev,
997 qdf_dma_addr_t ipa_uc_tx_doorbell_paddr,
998 qdf_dma_addr_t ipa_uc_rx_doorbell_paddr)
999 {
1000 pdev->ipa_uc_tx_rsc.tx_comp_idx_paddr = ipa_uc_tx_doorbell_paddr;
1001 pdev->ipa_uc_rx_rsc.rx_rdy_idx_paddr = ipa_uc_rx_doorbell_paddr;
1002 return 0;
1003 }
1004 #endif /* IPA_OFFLOAD */
1005
1006 /**
1007 * htt_mark_first_wakeup_packet() - set flag to indicate that
1008 * fw is compatible for marking first packet after wow wakeup
1009 * @pdev: pointer to htt pdev
1010 * @value: 1 for enabled/ 0 for disabled
1011 *
1012 * Return: None
1013 */
htt_mark_first_wakeup_packet(htt_pdev_handle pdev,uint8_t value)1014 void htt_mark_first_wakeup_packet(htt_pdev_handle pdev,
1015 uint8_t value)
1016 {
1017 if (!pdev) {
1018 QDF_TRACE(QDF_MODULE_ID_HTT, QDF_TRACE_LEVEL_ERROR,
1019 "%s: htt pdev is NULL", __func__);
1020 return;
1021 }
1022
1023 pdev->cfg.is_first_wakeup_packet = value;
1024 }
1025
1026