blob: 5422bef9e499b9b5d95d2cc6a6b22359f5c24636 [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Komal Seelam7fde14c2016-02-02 13:05:57 +05302 * Copyright (c) 2011-2016 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003 *
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/* OS abstraction libraries */
Nirav Shahcbc6d722016-03-01 16:24:53 +053029#include <qdf_nbuf.h> /* qdf_nbuf_t, etc. */
Anurag Chouhan8e0ccd32016-02-19 15:30:20 +053030#include <qdf_atomic.h> /* qdf_atomic_read, etc. */
Anurag Chouhanc5548422016-02-24 18:33:27 +053031#include <qdf_util.h> /* qdf_unlikely */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080032
33/* APIs for other modules */
34#include <htt.h> /* HTT_TX_EXT_TID_MGMT */
35#include <ol_htt_tx_api.h> /* htt_tx_desc_tid */
36#include <ol_txrx_api.h> /* ol_txrx_vdev_handle */
37#include <ol_txrx_ctrl_api.h> /* ol_txrx_sync */
38
39/* internal header files relevant for all systems */
40#include <ol_txrx_internal.h> /* TXRX_ASSERT1 */
41#include <ol_txrx_types.h> /* pdev stats */
42#include <ol_tx_desc.h> /* ol_tx_desc */
43#include <ol_tx_send.h> /* ol_tx_send */
44#include <ol_txrx.h>
45
46/* internal header files relevant only for HL systems */
47#include <ol_tx_queue.h> /* ol_tx_enqueue */
48
49/* internal header files relevant only for specific systems (Pronto) */
50#include <ol_txrx_encap.h> /* OL_TX_ENCAP, etc */
51#include <ol_tx.h>
52
53#ifdef WLAN_FEATURE_FASTPATH
54#include <hif.h> /* HIF_DEVICE */
55#include <htc_api.h> /* Layering violation, but required for fast path */
56#include <htt_internal.h>
57#include <htt_types.h> /* htc_endpoint */
58
Nirav Shahcbc6d722016-03-01 16:24:53 +053059int ce_send_fast(struct CE_handle *copyeng, qdf_nbuf_t *msdus,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080060 unsigned int num_msdus, unsigned int transfer_id);
61#endif /* WLAN_FEATURE_FASTPATH */
62
63/*
64 * The TXRX module doesn't accept tx frames unless the target has
65 * enough descriptors for them.
66 * For LL, the TXRX descriptor pool is sized to match the target's
67 * descriptor pool. Hence, if the descriptor allocation in TXRX
68 * succeeds, that guarantees that the target has room to accept
69 * the new tx frame.
70 */
71#define ol_tx_prepare_ll(tx_desc, vdev, msdu, msdu_info) \
72 do { \
73 struct ol_txrx_pdev_t *pdev = vdev->pdev; \
74 (msdu_info)->htt.info.frame_type = pdev->htt_pkt_type; \
75 tx_desc = ol_tx_desc_ll(pdev, vdev, msdu, msdu_info); \
Anurag Chouhanc5548422016-02-24 18:33:27 +053076 if (qdf_unlikely(!tx_desc)) { \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080077 TXRX_STATS_MSDU_LIST_INCR( \
78 pdev, tx.dropped.host_reject, msdu); \
79 return msdu; /* the list of unaccepted MSDUs */ \
80 } \
81 } while (0)
82
Dhanashri Atre83d373d2015-07-28 16:45:59 -070083#if defined(FEATURE_TSO)
84/**
85 * ol_tx_prepare_tso() - Given a jumbo msdu, prepare the TSO
86 * related information in the msdu_info meta data
87 * @vdev: virtual device handle
88 * @msdu: network buffer
89 * @msdu_info: meta data associated with the msdu
90 *
91 * Return: 0 - success, >0 - error
92 */
93static inline uint8_t ol_tx_prepare_tso(ol_txrx_vdev_handle vdev,
Nirav Shahcbc6d722016-03-01 16:24:53 +053094 qdf_nbuf_t msdu, struct ol_txrx_msdu_info_t *msdu_info)
Dhanashri Atre83d373d2015-07-28 16:45:59 -070095{
96 msdu_info->tso_info.curr_seg = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +053097 if (qdf_nbuf_is_tso(msdu)) {
98 int num_seg = qdf_nbuf_get_tso_num_seg(msdu);
Dhanashri Atre83d373d2015-07-28 16:45:59 -070099 msdu_info->tso_info.tso_seg_list = NULL;
100 msdu_info->tso_info.num_segs = num_seg;
101 while (num_seg) {
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530102 struct qdf_tso_seg_elem_t *tso_seg =
Dhanashri Atre83d373d2015-07-28 16:45:59 -0700103 ol_tso_alloc_segment(vdev->pdev);
104 if (tso_seg) {
105 tso_seg->next =
106 msdu_info->tso_info.tso_seg_list;
107 msdu_info->tso_info.tso_seg_list
108 = tso_seg;
109 num_seg--;
110 } else {
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530111 struct qdf_tso_seg_elem_t *next_seg;
112 struct qdf_tso_seg_elem_t *free_seg =
Dhanashri Atre83d373d2015-07-28 16:45:59 -0700113 msdu_info->tso_info.tso_seg_list;
Anurag Chouhan6d760662016-02-20 16:05:43 +0530114 qdf_print("TSO seg alloc failed!\n");
Dhanashri Atre83d373d2015-07-28 16:45:59 -0700115 while (free_seg) {
116 next_seg = free_seg->next;
117 ol_tso_free_segment(vdev->pdev,
118 free_seg);
119 free_seg = next_seg;
120 }
121 return 1;
122 }
123 }
Nirav Shahcbc6d722016-03-01 16:24:53 +0530124 qdf_nbuf_get_tso_info(vdev->pdev->osdev,
Dhanashri Atre83d373d2015-07-28 16:45:59 -0700125 msdu, &(msdu_info->tso_info));
126 msdu_info->tso_info.curr_seg =
127 msdu_info->tso_info.tso_seg_list;
128 num_seg = msdu_info->tso_info.num_segs;
129 } else {
130 msdu_info->tso_info.is_tso = 0;
131 msdu_info->tso_info.num_segs = 1;
132 }
133 return 0;
134}
135#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800136
137/**
138 * ol_tx_send_data_frame() - send data frame
139 * @sta_id: sta id
140 * @skb: skb
141 * @proto_type: proto type
142 *
143 * Return: skb/NULL for success
144 */
Nirav Shahcbc6d722016-03-01 16:24:53 +0530145qdf_nbuf_t ol_tx_send_data_frame(uint8_t sta_id, qdf_nbuf_t skb,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800146 uint8_t proto_type)
147{
Anurag Chouhandf2b2682016-02-29 14:15:27 +0530148 void *qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
Anurag Chouhan6d760662016-02-20 16:05:43 +0530149 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800150 struct ol_txrx_peer_t *peer;
Nirav Shahcbc6d722016-03-01 16:24:53 +0530151 qdf_nbuf_t ret;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530152 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800153
Anurag Chouhanc5548422016-02-24 18:33:27 +0530154 if (qdf_unlikely(!pdev)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530155 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_WARN,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800156 "%s:pdev is null", __func__);
157 return skb;
158 }
Anurag Chouhandf2b2682016-02-29 14:15:27 +0530159 if (qdf_unlikely(!qdf_ctx)) {
Orhan K AKYILDIZc4094612015-11-11 18:01:15 -0800160 TXRX_PRINT(TXRX_PRINT_LEVEL_ERR,
Anurag Chouhandf2b2682016-02-29 14:15:27 +0530161 "%s:qdf_ctx is null", __func__);
Orhan K AKYILDIZc4094612015-11-11 18:01:15 -0800162 return skb;
163 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800164
165 if (sta_id >= WLAN_MAX_STA_COUNT) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530166 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_WARN,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800167 "%s:Invalid sta id", __func__);
168 return skb;
169 }
170
171 peer = ol_txrx_peer_find_by_local_id(pdev, sta_id);
172 if (!peer) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530173 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_WARN,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800174 "%s:Invalid peer", __func__);
175 return skb;
176 }
177
178 if (peer->state < ol_txrx_peer_state_conn) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530179 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_WARN,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800180 "%s: station to be yet registered..dropping pkt", __func__);
181 return skb;
182 }
183
Nirav Shahcbc6d722016-03-01 16:24:53 +0530184 status = qdf_nbuf_map_single(qdf_ctx, skb, QDF_DMA_TO_DEVICE);
Anurag Chouhanc5548422016-02-24 18:33:27 +0530185 if (qdf_unlikely(status != QDF_STATUS_SUCCESS)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530186 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_WARN,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800187 "%s: nbuf map failed", __func__);
188 return skb;
189 }
190
Nirav Shahcbc6d722016-03-01 16:24:53 +0530191 qdf_nbuf_trace_set_proto_type(skb, proto_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800192
193 if ((ol_cfg_is_ip_tcp_udp_checksum_offload_enabled(pdev->ctrl_pdev))
Nirav Shahcbc6d722016-03-01 16:24:53 +0530194 && (qdf_nbuf_get_protocol(skb) == htons(ETH_P_IP))
195 && (qdf_nbuf_get_ip_summed(skb) == CHECKSUM_PARTIAL))
196 qdf_nbuf_set_ip_summed(skb, CHECKSUM_COMPLETE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800197
198 /* Terminate the (single-element) list of tx frames */
Nirav Shahcbc6d722016-03-01 16:24:53 +0530199 qdf_nbuf_set_next(skb, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800200 ret = OL_TX_LL(peer->vdev, skb);
201 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530202 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_WARN,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800203 "%s: Failed to tx", __func__);
Nirav Shahcbc6d722016-03-01 16:24:53 +0530204 qdf_nbuf_unmap_single(qdf_ctx, ret, QDF_DMA_TO_DEVICE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800205 return ret;
206 }
207
208 return NULL;
209}
210
211#ifdef IPA_OFFLOAD
212/**
213 * ol_tx_send_ipa_data_frame() - send IPA data frame
214 * @vdev: vdev
215 * @skb: skb
216 *
217 * Return: skb/ NULL is for success
218 */
Nirav Shahcbc6d722016-03-01 16:24:53 +0530219qdf_nbuf_t ol_tx_send_ipa_data_frame(void *vdev,
220 qdf_nbuf_t skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800221{
Anurag Chouhan6d760662016-02-20 16:05:43 +0530222 ol_txrx_pdev_handle pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Nirav Shahcbc6d722016-03-01 16:24:53 +0530223 qdf_nbuf_t ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800224
Anurag Chouhanc5548422016-02-24 18:33:27 +0530225 if (qdf_unlikely(!pdev)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800226 TXRX_PRINT(TXRX_PRINT_LEVEL_ERR,
227 "%s: pdev is NULL", __func__);
228 return skb;
229 }
230
231 if ((ol_cfg_is_ip_tcp_udp_checksum_offload_enabled(pdev->ctrl_pdev))
Nirav Shahcbc6d722016-03-01 16:24:53 +0530232 && (qdf_nbuf_get_protocol(skb) == htons(ETH_P_IP))
233 && (qdf_nbuf_get_ip_summed(skb) == CHECKSUM_PARTIAL))
234 qdf_nbuf_set_ip_summed(skb, CHECKSUM_COMPLETE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800235
236 /* Terminate the (single-element) list of tx frames */
Nirav Shahcbc6d722016-03-01 16:24:53 +0530237 qdf_nbuf_set_next(skb, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800238 ret = OL_TX_LL((struct ol_txrx_vdev_t *)vdev, skb);
239 if (ret) {
240 TXRX_PRINT(TXRX_PRINT_LEVEL_WARN,
241 "%s: Failed to tx", __func__);
242 return ret;
243 }
244
245 return NULL;
246}
247#endif
248
249
250#if defined(FEATURE_TSO)
Nirav Shahcbc6d722016-03-01 16:24:53 +0530251qdf_nbuf_t ol_tx_ll(ol_txrx_vdev_handle vdev, qdf_nbuf_t msdu_list)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800252{
Nirav Shahcbc6d722016-03-01 16:24:53 +0530253 qdf_nbuf_t msdu = msdu_list;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800254 struct ol_txrx_msdu_info_t msdu_info;
255
256 msdu_info.htt.info.l2_hdr_type = vdev->pdev->htt_pkt_type;
257 msdu_info.htt.action.tx_comp_req = 0;
258 /*
259 * The msdu_list variable could be used instead of the msdu var,
260 * but just to clarify which operations are done on a single MSDU
261 * vs. a list of MSDUs, use a distinct variable for single MSDUs
262 * within the list.
263 */
264 while (msdu) {
Nirav Shahcbc6d722016-03-01 16:24:53 +0530265 qdf_nbuf_t next;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800266 struct ol_tx_desc_t *tx_desc;
267 int segments = 1;
268
Nirav Shahcbc6d722016-03-01 16:24:53 +0530269 msdu_info.htt.info.ext_tid = qdf_nbuf_get_tid(msdu);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800270 msdu_info.peer = NULL;
271
Anurag Chouhanc5548422016-02-24 18:33:27 +0530272 if (qdf_unlikely(ol_tx_prepare_tso(vdev, msdu, &msdu_info))) {
Anurag Chouhan6d760662016-02-20 16:05:43 +0530273 qdf_print("ol_tx_prepare_tso failed\n");
Dhanashri Atre83d373d2015-07-28 16:45:59 -0700274 TXRX_STATS_MSDU_LIST_INCR(vdev->pdev,
275 tx.dropped.host_reject, msdu);
276 return msdu;
277 }
278
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800279 segments = msdu_info.tso_info.num_segs;
280
281 /*
282 * The netbuf may get linked into a different list inside the
283 * ol_tx_send function, so store the next pointer before the
284 * tx_send call.
285 */
Nirav Shahcbc6d722016-03-01 16:24:53 +0530286 next = qdf_nbuf_next(msdu);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800287 /* init the current segment to the 1st segment in the list */
288 while (segments) {
289
290 if (msdu_info.tso_info.curr_seg)
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530291 QDF_NBUF_CB_PADDR(msdu) =
Houston Hoffman43d47fa2016-02-24 16:34:30 -0800292 msdu_info.tso_info.curr_seg->
293 seg.tso_frags[0].paddr_low_32;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800294
295 segments--;
296
297 /**
298 * if this is a jumbo nbuf, then increment the number
299 * of nbuf users for each additional segment of the msdu.
300 * This will ensure that the skb is freed only after
301 * receiving tx completion for all segments of an nbuf
302 */
303 if (segments)
Nirav Shahcbc6d722016-03-01 16:24:53 +0530304 qdf_nbuf_inc_users(msdu);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800305
306 ol_tx_prepare_ll(tx_desc, vdev, msdu, &msdu_info);
307
308 /*
309 * If debug display is enabled, show the meta-data being
310 * downloaded to the target via the HTT tx descriptor.
311 */
312 htt_tx_desc_display(tx_desc->htt_tx_desc);
313
314 ol_tx_send(vdev->pdev, tx_desc, msdu);
315
316 if (msdu_info.tso_info.curr_seg) {
317 msdu_info.tso_info.curr_seg =
318 msdu_info.tso_info.curr_seg->next;
319 }
320
Nirav Shahcbc6d722016-03-01 16:24:53 +0530321 qdf_nbuf_reset_num_frags(msdu);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800322
323 if (msdu_info.tso_info.is_tso) {
324 TXRX_STATS_TSO_INC_SEG(vdev->pdev);
325 TXRX_STATS_TSO_INC_SEG_IDX(vdev->pdev);
326 }
327 } /* while segments */
328
329 msdu = next;
330 if (msdu_info.tso_info.is_tso) {
331 TXRX_STATS_TSO_INC_MSDU_IDX(vdev->pdev);
332 TXRX_STATS_TSO_RESET_MSDU(vdev->pdev);
333 }
334 } /* while msdus */
335 return NULL; /* all MSDUs were accepted */
336}
337#else /* TSO */
338
Nirav Shahcbc6d722016-03-01 16:24:53 +0530339qdf_nbuf_t ol_tx_ll(ol_txrx_vdev_handle vdev, qdf_nbuf_t msdu_list)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800340{
Nirav Shahcbc6d722016-03-01 16:24:53 +0530341 qdf_nbuf_t msdu = msdu_list;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800342 struct ol_txrx_msdu_info_t msdu_info;
343
344 msdu_info.htt.info.l2_hdr_type = vdev->pdev->htt_pkt_type;
345 msdu_info.htt.action.tx_comp_req = 0;
346 msdu_info.tso_info.is_tso = 0;
347 /*
348 * The msdu_list variable could be used instead of the msdu var,
349 * but just to clarify which operations are done on a single MSDU
350 * vs. a list of MSDUs, use a distinct variable for single MSDUs
351 * within the list.
352 */
353 while (msdu) {
Nirav Shahcbc6d722016-03-01 16:24:53 +0530354 qdf_nbuf_t next;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800355 struct ol_tx_desc_t *tx_desc;
356
Nirav Shahcbc6d722016-03-01 16:24:53 +0530357 msdu_info.htt.info.ext_tid = qdf_nbuf_get_tid(msdu);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800358 msdu_info.peer = NULL;
359 ol_tx_prepare_ll(tx_desc, vdev, msdu, &msdu_info);
360
361 /*
362 * If debug display is enabled, show the meta-data being
363 * downloaded to the target via the HTT tx descriptor.
364 */
365 htt_tx_desc_display(tx_desc->htt_tx_desc);
366 /*
367 * The netbuf may get linked into a different list inside the
368 * ol_tx_send function, so store the next pointer before the
369 * tx_send call.
370 */
Nirav Shahcbc6d722016-03-01 16:24:53 +0530371 next = qdf_nbuf_next(msdu);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800372 ol_tx_send(vdev->pdev, tx_desc, msdu);
373 msdu = next;
374 }
375 return NULL; /* all MSDUs were accepted */
376}
377#endif /* TSO */
378
379#ifdef WLAN_FEATURE_FASTPATH
380/**
381 * ol_tx_prepare_ll_fast() Alloc and prepare Tx descriptor
382 *
383 * Allocate and prepare Tx descriptor with msdu and fragment descritor
384 * inforamtion.
385 *
386 * @pdev: pointer to ol pdev handle
387 * @vdev: pointer to ol vdev handle
388 * @msdu: linked list of msdu packets
389 * @pkt_download_len: packet download length
390 * @ep_id: endpoint ID
391 * @msdu_info: Handle to msdu_info
392 *
393 * Return: Pointer to Tx descriptor
394 */
395static inline struct ol_tx_desc_t *
396ol_tx_prepare_ll_fast(struct ol_txrx_pdev_t *pdev,
Nirav Shahcbc6d722016-03-01 16:24:53 +0530397 ol_txrx_vdev_handle vdev, qdf_nbuf_t msdu,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800398 uint32_t pkt_download_len, uint32_t ep_id,
399 struct ol_txrx_msdu_info_t *msdu_info)
400{
401 struct ol_tx_desc_t *tx_desc = NULL;
402 uint32_t *htt_tx_desc;
403 void *htc_hdr_vaddr;
404 u_int32_t num_frags, i;
405
406 tx_desc = ol_tx_desc_alloc_wrapper(pdev, vdev, msdu_info);
Anurag Chouhanc5548422016-02-24 18:33:27 +0530407 if (qdf_unlikely(!tx_desc))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800408 return NULL;
409
410 tx_desc->netbuf = msdu;
411 if (msdu_info->tso_info.is_tso) {
412 tx_desc->tso_desc = msdu_info->tso_info.curr_seg;
413 tx_desc->pkt_type = ol_tx_frm_tso;
414 TXRX_STATS_MSDU_INCR(pdev, tx.tso.tso_pkts, msdu);
415 } else {
416 tx_desc->pkt_type = ol_tx_frm_std;
417 }
418
419 htt_tx_desc = tx_desc->htt_tx_desc;
420
421 /* Make sure frags num is set to 0 */
422 /*
423 * Do this here rather than in hardstart, so
424 * that we can hopefully take only one cache-miss while
425 * accessing skb->cb.
426 */
427
428 /* HTT Header */
429 /* TODO : Take care of multiple fragments */
430
431 /* TODO: Precompute and store paddr in ol_tx_desc_t */
432 /* Virtual address of the HTT/HTC header, added by driver */
433 htc_hdr_vaddr = (char *)htt_tx_desc - HTC_HEADER_LEN;
434 htt_tx_desc_init(pdev->htt_pdev, htt_tx_desc,
435 tx_desc->htt_tx_desc_paddr, tx_desc->id, msdu,
436 &msdu_info->htt, &msdu_info->tso_info,
437 NULL, vdev->opmode == wlan_op_mode_ocb);
438
Nirav Shahcbc6d722016-03-01 16:24:53 +0530439 num_frags = qdf_nbuf_get_num_frags(msdu);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800440 /* num_frags are expected to be 2 max */
Nirav Shahcbc6d722016-03-01 16:24:53 +0530441 num_frags = (num_frags > QDF_NBUF_CB_TX_MAX_EXTRA_FRAGS)
442 ? QDF_NBUF_CB_TX_MAX_EXTRA_FRAGS
Houston Hoffman43d47fa2016-02-24 16:34:30 -0800443 : num_frags;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800444#if defined(HELIUMPLUS_PADDR64)
445 /*
446 * Use num_frags - 1, since 1 frag is used to store
447 * the HTT/HTC descriptor
448 * Refer to htt_tx_desc_init()
449 */
450 htt_tx_desc_num_frags(pdev->htt_pdev, tx_desc->htt_frag_desc,
451 num_frags - 1);
452#else /* ! defined(HELIUMPLUSPADDR64) */
453 htt_tx_desc_num_frags(pdev->htt_pdev, tx_desc->htt_tx_desc,
454 num_frags-1);
455#endif /* defined(HELIUMPLUS_PADDR64) */
456 if (msdu_info->tso_info.is_tso) {
457 htt_tx_desc_fill_tso_info(pdev->htt_pdev,
458 tx_desc->htt_frag_desc, &msdu_info->tso_info);
459 TXRX_STATS_TSO_SEG_UPDATE(pdev,
460 msdu_info->tso_info.curr_seg->seg);
461 } else {
462 for (i = 1; i < num_frags; i++) {
Anurag Chouhan6d760662016-02-20 16:05:43 +0530463 qdf_size_t frag_len;
Anurag Chouhandf2b2682016-02-29 14:15:27 +0530464 qdf_dma_addr_t frag_paddr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800465
Nirav Shahcbc6d722016-03-01 16:24:53 +0530466 frag_len = qdf_nbuf_get_frag_len(msdu, i);
467 frag_paddr = qdf_nbuf_get_frag_paddr(msdu, i);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800468#if defined(HELIUMPLUS_PADDR64)
469 htt_tx_desc_frag(pdev->htt_pdev, tx_desc->htt_frag_desc,
470 i - 1, frag_paddr, frag_len);
471#if defined(HELIUMPLUS_DEBUG)
Anurag Chouhan6d760662016-02-20 16:05:43 +0530472 qdf_print("%s:%d: htt_fdesc=%p frag=%d frag_paddr=0x%0llx len=%zu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800473 __func__, __LINE__, tx_desc->htt_frag_desc,
Houston Hoffman43d47fa2016-02-24 16:34:30 -0800474 i-1, frag_paddr, frag_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800475 dump_pkt(netbuf, frag_paddr, 64);
476#endif /* HELIUMPLUS_DEBUG */
477#else /* ! defined(HELIUMPLUSPADDR64) */
478 htt_tx_desc_frag(pdev->htt_pdev, tx_desc->htt_tx_desc,
479 i - 1, frag_paddr, frag_len);
480#endif /* defined(HELIUMPLUS_PADDR64) */
481 }
482 }
483
484 /*
485 * Do we want to turn on word_stream bit-map here ? For linux, non-TSO
486 * this is not required. We still have to mark the swap bit correctly,
487 * when posting to the ring
488 */
489 /* Check to make sure, data download length is correct */
490
491 /*
492 * TODO : Can we remove this check and always download a fixed length ?
493 * */
Nirav Shahcbc6d722016-03-01 16:24:53 +0530494 if (qdf_unlikely(qdf_nbuf_len(msdu) < pkt_download_len))
495 pkt_download_len = qdf_nbuf_len(msdu);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800496
497 /* Fill the HTC header information */
498 /*
499 * Passing 0 as the seq_no field, we can probably get away
500 * with it for the time being, since this is not checked in f/w
501 */
502 /* TODO : Prefill this, look at multi-fragment case */
503 HTC_TX_DESC_FILL(htc_hdr_vaddr, pkt_download_len, ep_id, 0);
504
505 return tx_desc;
506}
507#if defined(FEATURE_TSO)
508/**
509 * ol_tx_ll_fast() Update metadata information and send msdu to HIF/CE
510 *
511 * @vdev: handle to ol_txrx_vdev_t
512 * @msdu_list: msdu list to be sent out.
513 *
514 * Return: on success return NULL, pointer to nbuf when it fails to send.
515 */
Nirav Shahcbc6d722016-03-01 16:24:53 +0530516qdf_nbuf_t
517ol_tx_ll_fast(ol_txrx_vdev_handle vdev, qdf_nbuf_t msdu_list)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800518{
Nirav Shahcbc6d722016-03-01 16:24:53 +0530519 qdf_nbuf_t msdu = msdu_list;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800520 struct ol_txrx_pdev_t *pdev = vdev->pdev;
521 uint32_t pkt_download_len =
522 ((struct htt_pdev_t *)(pdev->htt_pdev))->download_len;
523 uint32_t ep_id = HTT_EPID_GET(pdev->htt_pdev);
524 struct ol_txrx_msdu_info_t msdu_info;
525
526 msdu_info.htt.info.l2_hdr_type = vdev->pdev->htt_pkt_type;
527 msdu_info.htt.action.tx_comp_req = 0;
528 /*
529 * The msdu_list variable could be used instead of the msdu var,
530 * but just to clarify which operations are done on a single MSDU
531 * vs. a list of MSDUs, use a distinct variable for single MSDUs
532 * within the list.
533 */
534 while (msdu) {
Nirav Shahcbc6d722016-03-01 16:24:53 +0530535 qdf_nbuf_t next;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800536 struct ol_tx_desc_t *tx_desc;
537 int segments = 1;
538
Nirav Shahcbc6d722016-03-01 16:24:53 +0530539 msdu_info.htt.info.ext_tid = qdf_nbuf_get_tid(msdu);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800540 msdu_info.peer = NULL;
541
Anurag Chouhanc5548422016-02-24 18:33:27 +0530542 if (qdf_unlikely(ol_tx_prepare_tso(vdev, msdu, &msdu_info))) {
Anurag Chouhan6d760662016-02-20 16:05:43 +0530543 qdf_print("ol_tx_prepare_tso failed\n");
Dhanashri Atre83d373d2015-07-28 16:45:59 -0700544 TXRX_STATS_MSDU_LIST_INCR(vdev->pdev,
545 tx.dropped.host_reject, msdu);
546 return msdu;
547 }
548
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800549 segments = msdu_info.tso_info.num_segs;
550
551 /*
552 * The netbuf may get linked into a different list
553 * inside the ce_send_fast function, so store the next
554 * pointer before the ce_send call.
555 */
Nirav Shahcbc6d722016-03-01 16:24:53 +0530556 next = qdf_nbuf_next(msdu);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800557 /* init the current segment to the 1st segment in the list */
558 while (segments) {
559
560 if (msdu_info.tso_info.curr_seg)
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530561 QDF_NBUF_CB_PADDR(msdu) = msdu_info.tso_info.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800562 curr_seg->seg.tso_frags[0].paddr_low_32;
563
564 segments--;
565
566 /**
567 * if this is a jumbo nbuf, then increment the number
568 * of nbuf users for each additional segment of the msdu.
569 * This will ensure that the skb is freed only after
570 * receiving tx completion for all segments of an nbuf
571 */
572 if (segments)
Nirav Shahcbc6d722016-03-01 16:24:53 +0530573 qdf_nbuf_inc_users(msdu);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800574
575 msdu_info.htt.info.frame_type = pdev->htt_pkt_type;
576 msdu_info.htt.info.vdev_id = vdev->vdev_id;
577 msdu_info.htt.action.cksum_offload =
Nirav Shahcbc6d722016-03-01 16:24:53 +0530578 qdf_nbuf_get_tx_cksum(msdu);
579 switch (qdf_nbuf_get_exemption_type(msdu)) {
Anurag Chouhanc73697b2016-02-21 15:05:43 +0530580 case QDF_NBUF_EXEMPT_NO_EXEMPTION:
581 case QDF_NBUF_EXEMPT_ON_KEY_MAPPING_KEY_UNAVAILABLE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800582 /* We want to encrypt this frame */
583 msdu_info.htt.action.do_encrypt = 1;
584 break;
Anurag Chouhanc73697b2016-02-21 15:05:43 +0530585 case QDF_NBUF_EXEMPT_ALWAYS:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800586 /* We don't want to encrypt this frame */
587 msdu_info.htt.action.do_encrypt = 0;
588 break;
589 default:
590 msdu_info.htt.action.do_encrypt = 1;
Anurag Chouhanc5548422016-02-24 18:33:27 +0530591 qdf_assert(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800592 break;
593 }
594
595 tx_desc = ol_tx_prepare_ll_fast(pdev, vdev, msdu,
596 pkt_download_len, ep_id,
597 &msdu_info);
598
Anurag Chouhanc5548422016-02-24 18:33:27 +0530599 if (qdf_likely(tx_desc)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800600 /*
601 * If debug display is enabled, show the meta
602 * data being downloaded to the target via the
603 * HTT tx descriptor.
604 */
605 htt_tx_desc_display(tx_desc->htt_tx_desc);
606 if ((0 == ce_send_fast(pdev->ce_tx_hdl, &msdu,
607 1, ep_id))) {
608 /*
609 * The packet could not be sent.
610 * Free the descriptor, return the
611 * packet to the caller.
612 */
613 ol_tx_desc_free(pdev, tx_desc);
614 return msdu;
615 }
616 if (msdu_info.tso_info.curr_seg) {
617 msdu_info.tso_info.curr_seg =
618 msdu_info.tso_info.curr_seg->next;
619 }
620
621 if (msdu_info.tso_info.is_tso) {
Nirav Shahcbc6d722016-03-01 16:24:53 +0530622 qdf_nbuf_reset_num_frags(msdu);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800623 TXRX_STATS_TSO_INC_SEG(vdev->pdev);
624 TXRX_STATS_TSO_INC_SEG_IDX(vdev->pdev);
625 }
626 } else {
627 TXRX_STATS_MSDU_LIST_INCR(
628 pdev, tx.dropped.host_reject, msdu);
629 /* the list of unaccepted MSDUs */
630 return msdu;
631 }
632 } /* while segments */
633
634 msdu = next;
635 if (msdu_info.tso_info.is_tso) {
636 TXRX_STATS_TSO_INC_MSDU_IDX(vdev->pdev);
637 TXRX_STATS_TSO_RESET_MSDU(vdev->pdev);
638 }
639 } /* while msdus */
640 return NULL; /* all MSDUs were accepted */
641}
642#else
Nirav Shahcbc6d722016-03-01 16:24:53 +0530643qdf_nbuf_t
644ol_tx_ll_fast(ol_txrx_vdev_handle vdev, qdf_nbuf_t msdu_list)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800645{
Nirav Shahcbc6d722016-03-01 16:24:53 +0530646 qdf_nbuf_t msdu = msdu_list;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800647 struct ol_txrx_pdev_t *pdev = vdev->pdev;
648 uint32_t pkt_download_len =
649 ((struct htt_pdev_t *)(pdev->htt_pdev))->download_len;
650 uint32_t ep_id = HTT_EPID_GET(pdev->htt_pdev);
651 struct ol_txrx_msdu_info_t msdu_info;
652
653 msdu_info.htt.info.l2_hdr_type = vdev->pdev->htt_pkt_type;
654 msdu_info.htt.action.tx_comp_req = 0;
655 msdu_info.tso_info.is_tso = 0;
656 /*
657 * The msdu_list variable could be used instead of the msdu var,
658 * but just to clarify which operations are done on a single MSDU
659 * vs. a list of MSDUs, use a distinct variable for single MSDUs
660 * within the list.
661 */
662 while (msdu) {
Nirav Shahcbc6d722016-03-01 16:24:53 +0530663 qdf_nbuf_t next;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800664 struct ol_tx_desc_t *tx_desc;
665
Nirav Shahcbc6d722016-03-01 16:24:53 +0530666 msdu_info.htt.info.ext_tid = qdf_nbuf_get_tid(msdu);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800667 msdu_info.peer = NULL;
668
669 msdu_info.htt.info.frame_type = pdev->htt_pkt_type;
670 msdu_info.htt.info.vdev_id = vdev->vdev_id;
671 msdu_info.htt.action.cksum_offload =
Nirav Shahcbc6d722016-03-01 16:24:53 +0530672 qdf_nbuf_get_tx_cksum(msdu);
673 switch (qdf_nbuf_get_exemption_type(msdu)) {
Anurag Chouhanc73697b2016-02-21 15:05:43 +0530674 case QDF_NBUF_EXEMPT_NO_EXEMPTION:
675 case QDF_NBUF_EXEMPT_ON_KEY_MAPPING_KEY_UNAVAILABLE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800676 /* We want to encrypt this frame */
677 msdu_info.htt.action.do_encrypt = 1;
678 break;
Anurag Chouhanc73697b2016-02-21 15:05:43 +0530679 case QDF_NBUF_EXEMPT_ALWAYS:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800680 /* We don't want to encrypt this frame */
681 msdu_info.htt.action.do_encrypt = 0;
682 break;
683 default:
684 msdu_info.htt.action.do_encrypt = 1;
Anurag Chouhanc5548422016-02-24 18:33:27 +0530685 qdf_assert(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800686 break;
687 }
688
689 tx_desc = ol_tx_prepare_ll_fast(pdev, vdev, msdu,
690 pkt_download_len, ep_id,
691 &msdu_info);
692
Anurag Chouhanc5548422016-02-24 18:33:27 +0530693 if (qdf_likely(tx_desc)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800694 /*
695 * If debug display is enabled, show the meta-data being
696 * downloaded to the target via the HTT tx descriptor.
697 */
698 htt_tx_desc_display(tx_desc->htt_tx_desc);
699 /*
700 * The netbuf may get linked into a different list
701 * inside the ce_send_fast function, so store the next
702 * pointer before the ce_send call.
703 */
Nirav Shahcbc6d722016-03-01 16:24:53 +0530704 next = qdf_nbuf_next(msdu);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800705 if ((0 == ce_send_fast(pdev->ce_tx_hdl, &msdu, 1,
706 ep_id))) {
707 /* The packet could not be sent */
708 /* Free the descriptor, return the packet to the
709 * caller */
710 ol_tx_desc_free(pdev, tx_desc);
711 return msdu;
712 }
713 msdu = next;
714 } else {
715 TXRX_STATS_MSDU_LIST_INCR(
716 pdev, tx.dropped.host_reject, msdu);
717 return msdu; /* the list of unaccepted MSDUs */
718 }
719 }
720
721 return NULL; /* all MSDUs were accepted */
722}
723#endif /* FEATURE_TSO */
724#endif /* WLAN_FEATURE_FASTPATH */
725
726#ifdef WLAN_FEATURE_FASTPATH
727/**
728 * ol_tx_ll_wrapper() wrapper to ol_tx_ll
729 *
730 */
Nirav Shahcbc6d722016-03-01 16:24:53 +0530731static inline qdf_nbuf_t
732ol_tx_ll_wrapper(ol_txrx_vdev_handle vdev, qdf_nbuf_t msdu_list)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800733{
Komal Seelam3d202862016-02-24 18:43:24 +0530734 struct hif_opaque_softc *hif_device =
Anurag Chouhan6d760662016-02-20 16:05:43 +0530735 (struct hif_opaque_softc *)cds_get_context(QDF_MODULE_ID_HIF);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800736
Anurag Chouhanc5548422016-02-24 18:33:27 +0530737 if (qdf_likely(hif_device && hif_is_fastpath_mode_enabled(hif_device)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800738 msdu_list = ol_tx_ll_fast(vdev, msdu_list);
739 else
740 msdu_list = ol_tx_ll(vdev, msdu_list);
741
742 return msdu_list;
743}
744#else
Nirav Shahcbc6d722016-03-01 16:24:53 +0530745static inline qdf_nbuf_t
746ol_tx_ll_wrapper(ol_txrx_vdev_handle vdev, qdf_nbuf_t msdu_list)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800747{
748 return ol_tx_ll(vdev, msdu_list);
749}
750#endif /* WLAN_FEATURE_FASTPATH */
751
752#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
753
754#define OL_TX_VDEV_PAUSE_QUEUE_SEND_MARGIN 400
755#define OL_TX_VDEV_PAUSE_QUEUE_SEND_PERIOD_MS 5
756static void ol_tx_vdev_ll_pause_queue_send_base(struct ol_txrx_vdev_t *vdev)
757{
758 int max_to_accept;
759
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530760 qdf_spin_lock_bh(&vdev->ll_pause.mutex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800761 if (vdev->ll_pause.paused_reason) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530762 qdf_spin_unlock_bh(&vdev->ll_pause.mutex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800763 return;
764 }
765
766 /*
767 * Send as much of the backlog as possible, but leave some margin
768 * of unallocated tx descriptors that can be used for new frames
769 * being transmitted by other vdevs.
770 * Ideally there would be a scheduler, which would not only leave
771 * some margin for new frames for other vdevs, but also would
772 * fairly apportion the tx descriptors between multiple vdevs that
773 * have backlogs in their pause queues.
774 * However, the fairness benefit of having a scheduler for frames
775 * from multiple vdev's pause queues is not sufficient to outweigh
776 * the extra complexity.
777 */
778 max_to_accept = vdev->pdev->tx_desc.num_free -
779 OL_TX_VDEV_PAUSE_QUEUE_SEND_MARGIN;
780 while (max_to_accept > 0 && vdev->ll_pause.txq.depth) {
Nirav Shahcbc6d722016-03-01 16:24:53 +0530781 qdf_nbuf_t tx_msdu;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800782 max_to_accept--;
783 vdev->ll_pause.txq.depth--;
784 tx_msdu = vdev->ll_pause.txq.head;
785 if (tx_msdu) {
Nirav Shahcbc6d722016-03-01 16:24:53 +0530786 vdev->ll_pause.txq.head = qdf_nbuf_next(tx_msdu);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800787 if (NULL == vdev->ll_pause.txq.head)
788 vdev->ll_pause.txq.tail = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +0530789 qdf_nbuf_set_next(tx_msdu, NULL);
790 QDF_NBUF_UPDATE_TX_PKT_COUNT(tx_msdu,
791 QDF_NBUF_TX_PKT_TXRX_DEQUEUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800792 tx_msdu = ol_tx_ll_wrapper(vdev, tx_msdu);
793 /*
794 * It is unexpected that ol_tx_ll would reject the frame
795 * since we checked that there's room for it, though
796 * there's an infinitesimal possibility that between the
797 * time we checked the room available and now, a
798 * concurrent batch of tx frames used up all the room.
799 * For simplicity, just drop the frame.
800 */
801 if (tx_msdu) {
Nirav Shahcbc6d722016-03-01 16:24:53 +0530802 qdf_nbuf_unmap(vdev->pdev->osdev, tx_msdu,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530803 QDF_DMA_TO_DEVICE);
Nirav Shahcbc6d722016-03-01 16:24:53 +0530804 qdf_nbuf_tx_free(tx_msdu, QDF_NBUF_PKT_ERROR);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800805 }
806 }
807 }
808 if (vdev->ll_pause.txq.depth) {
Anurag Chouhan754fbd82016-02-19 17:00:08 +0530809 qdf_timer_stop(&vdev->ll_pause.timer);
810 qdf_timer_start(&vdev->ll_pause.timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800811 OL_TX_VDEV_PAUSE_QUEUE_SEND_PERIOD_MS);
812 vdev->ll_pause.is_q_timer_on = true;
813 if (vdev->ll_pause.txq.depth >= vdev->ll_pause.max_q_depth)
814 vdev->ll_pause.q_overflow_cnt++;
815 }
816
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530817 qdf_spin_unlock_bh(&vdev->ll_pause.mutex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800818}
819
Nirav Shahcbc6d722016-03-01 16:24:53 +0530820static qdf_nbuf_t
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800821ol_tx_vdev_pause_queue_append(struct ol_txrx_vdev_t *vdev,
Nirav Shahcbc6d722016-03-01 16:24:53 +0530822 qdf_nbuf_t msdu_list, uint8_t start_timer)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800823{
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530824 qdf_spin_lock_bh(&vdev->ll_pause.mutex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800825 while (msdu_list &&
826 vdev->ll_pause.txq.depth < vdev->ll_pause.max_q_depth) {
Nirav Shahcbc6d722016-03-01 16:24:53 +0530827 qdf_nbuf_t next = qdf_nbuf_next(msdu_list);
828 QDF_NBUF_UPDATE_TX_PKT_COUNT(msdu_list,
829 QDF_NBUF_TX_PKT_TXRX_ENQUEUE);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530830 DPTRACE(qdf_dp_trace(msdu_list,
831 QDF_DP_TRACE_TXRX_QUEUE_PACKET_PTR_RECORD,
Nirav Shahcbc6d722016-03-01 16:24:53 +0530832 (uint8_t *)(qdf_nbuf_data(msdu_list)),
833 sizeof(qdf_nbuf_data(msdu_list))));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800834
835 vdev->ll_pause.txq.depth++;
836 if (!vdev->ll_pause.txq.head) {
837 vdev->ll_pause.txq.head = msdu_list;
838 vdev->ll_pause.txq.tail = msdu_list;
839 } else {
Nirav Shahcbc6d722016-03-01 16:24:53 +0530840 qdf_nbuf_set_next(vdev->ll_pause.txq.tail, msdu_list);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800841 }
842 vdev->ll_pause.txq.tail = msdu_list;
843
844 msdu_list = next;
845 }
846 if (vdev->ll_pause.txq.tail)
Nirav Shahcbc6d722016-03-01 16:24:53 +0530847 qdf_nbuf_set_next(vdev->ll_pause.txq.tail, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800848
849 if (start_timer) {
Anurag Chouhan754fbd82016-02-19 17:00:08 +0530850 qdf_timer_stop(&vdev->ll_pause.timer);
851 qdf_timer_start(&vdev->ll_pause.timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800852 OL_TX_VDEV_PAUSE_QUEUE_SEND_PERIOD_MS);
853 vdev->ll_pause.is_q_timer_on = true;
854 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530855 qdf_spin_unlock_bh(&vdev->ll_pause.mutex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800856
857 return msdu_list;
858}
859
860/*
861 * Store up the tx frame in the vdev's tx queue if the vdev is paused.
862 * If there are too many frames in the tx queue, reject it.
863 */
Nirav Shahcbc6d722016-03-01 16:24:53 +0530864qdf_nbuf_t ol_tx_ll_queue(ol_txrx_vdev_handle vdev, qdf_nbuf_t msdu_list)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800865{
866 uint16_t eth_type;
867 uint32_t paused_reason;
868
869 if (msdu_list == NULL)
870 return NULL;
871
872 paused_reason = vdev->ll_pause.paused_reason;
873 if (paused_reason) {
Anurag Chouhanc5548422016-02-24 18:33:27 +0530874 if (qdf_unlikely((paused_reason &
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800875 OL_TXQ_PAUSE_REASON_PEER_UNAUTHORIZED) ==
876 paused_reason)) {
877 eth_type = (((struct ethernet_hdr_t *)
Nirav Shahcbc6d722016-03-01 16:24:53 +0530878 qdf_nbuf_data(msdu_list))->
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800879 ethertype[0] << 8) |
880 (((struct ethernet_hdr_t *)
Nirav Shahcbc6d722016-03-01 16:24:53 +0530881 qdf_nbuf_data(msdu_list))->ethertype[1]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800882 if (ETHERTYPE_IS_EAPOL_WAPI(eth_type)) {
883 msdu_list = ol_tx_ll_wrapper(vdev, msdu_list);
884 return msdu_list;
885 }
886 }
887 msdu_list = ol_tx_vdev_pause_queue_append(vdev, msdu_list, 1);
888 } else {
889 if (vdev->ll_pause.txq.depth > 0 ||
890 vdev->pdev->tx_throttle.current_throttle_level !=
891 THROTTLE_LEVEL_0) {
892 /* not paused, but there is a backlog of frms
893 from a prior pause or throttle off phase */
894 msdu_list = ol_tx_vdev_pause_queue_append(
895 vdev, msdu_list, 0);
896 /* if throttle is disabled or phase is "on",
897 send the frame */
898 if (vdev->pdev->tx_throttle.current_throttle_level ==
899 THROTTLE_LEVEL_0 ||
900 vdev->pdev->tx_throttle.current_throttle_phase ==
901 THROTTLE_PHASE_ON) {
902 /* send as many frames as possible
903 from the vdevs backlog */
904 ol_tx_vdev_ll_pause_queue_send_base(vdev);
905 }
906 } else {
907 /* not paused, no throttle and no backlog -
908 send the new frames */
909 msdu_list = ol_tx_ll_wrapper(vdev, msdu_list);
910 }
911 }
912 return msdu_list;
913}
914
915/*
916 * Run through the transmit queues for all the vdevs and
917 * send the pending frames
918 */
919void ol_tx_pdev_ll_pause_queue_send_all(struct ol_txrx_pdev_t *pdev)
920{
921 int max_to_send; /* tracks how many frames have been sent */
Nirav Shahcbc6d722016-03-01 16:24:53 +0530922 qdf_nbuf_t tx_msdu;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800923 struct ol_txrx_vdev_t *vdev = NULL;
924 uint8_t more;
925
926 if (NULL == pdev)
927 return;
928
929 if (pdev->tx_throttle.current_throttle_phase == THROTTLE_PHASE_OFF)
930 return;
931
932 /* ensure that we send no more than tx_threshold frames at once */
933 max_to_send = pdev->tx_throttle.tx_threshold;
934
935 /* round robin through the vdev queues for the given pdev */
936
937 /* Potential improvement: download several frames from the same vdev
938 at a time, since it is more likely that those frames could be
939 aggregated together, remember which vdev was serviced last,
940 so the next call this function can resume the round-robin
941 traversing where the current invocation left off */
942 do {
943 more = 0;
944 TAILQ_FOREACH(vdev, &pdev->vdev_list, vdev_list_elem) {
945
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530946 qdf_spin_lock_bh(&vdev->ll_pause.mutex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800947 if (vdev->ll_pause.txq.depth) {
948 if (vdev->ll_pause.paused_reason) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530949 qdf_spin_unlock_bh(&vdev->ll_pause.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800950 mutex);
951 continue;
952 }
953
954 tx_msdu = vdev->ll_pause.txq.head;
955 if (NULL == tx_msdu) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530956 qdf_spin_unlock_bh(&vdev->ll_pause.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800957 mutex);
958 continue;
959 }
960
961 max_to_send--;
962 vdev->ll_pause.txq.depth--;
963
964 vdev->ll_pause.txq.head =
Nirav Shahcbc6d722016-03-01 16:24:53 +0530965 qdf_nbuf_next(tx_msdu);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800966
967 if (NULL == vdev->ll_pause.txq.head)
968 vdev->ll_pause.txq.tail = NULL;
969
Nirav Shahcbc6d722016-03-01 16:24:53 +0530970 qdf_nbuf_set_next(tx_msdu, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800971 tx_msdu = ol_tx_ll_wrapper(vdev, tx_msdu);
972 /*
973 * It is unexpected that ol_tx_ll would reject
974 * the frame, since we checked that there's
975 * room for it, though there's an infinitesimal
976 * possibility that between the time we checked
977 * the room available and now, a concurrent
978 * batch of tx frames used up all the room.
979 * For simplicity, just drop the frame.
980 */
981 if (tx_msdu) {
Nirav Shahcbc6d722016-03-01 16:24:53 +0530982 qdf_nbuf_unmap(pdev->osdev, tx_msdu,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530983 QDF_DMA_TO_DEVICE);
Nirav Shahcbc6d722016-03-01 16:24:53 +0530984 qdf_nbuf_tx_free(tx_msdu,
985 QDF_NBUF_PKT_ERROR);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800986 }
987 }
988 /*check if there are more msdus to transmit */
989 if (vdev->ll_pause.txq.depth)
990 more = 1;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530991 qdf_spin_unlock_bh(&vdev->ll_pause.mutex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800992 }
993 } while (more && max_to_send);
994
995 vdev = NULL;
996 TAILQ_FOREACH(vdev, &pdev->vdev_list, vdev_list_elem) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530997 qdf_spin_lock_bh(&vdev->ll_pause.mutex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800998 if (vdev->ll_pause.txq.depth) {
Anurag Chouhan754fbd82016-02-19 17:00:08 +0530999 qdf_timer_stop(&pdev->tx_throttle.tx_timer);
1000 qdf_timer_start(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001001 &pdev->tx_throttle.tx_timer,
1002 OL_TX_VDEV_PAUSE_QUEUE_SEND_PERIOD_MS);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301003 qdf_spin_unlock_bh(&vdev->ll_pause.mutex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001004 return;
1005 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301006 qdf_spin_unlock_bh(&vdev->ll_pause.mutex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001007 }
1008}
1009
1010void ol_tx_vdev_ll_pause_queue_send(void *context)
1011{
1012 struct ol_txrx_vdev_t *vdev = (struct ol_txrx_vdev_t *)context;
1013 struct ol_txrx_pdev_t *pdev = vdev->pdev;
1014
1015 if (pdev->tx_throttle.current_throttle_level != THROTTLE_LEVEL_0 &&
1016 pdev->tx_throttle.current_throttle_phase == THROTTLE_PHASE_OFF)
1017 return;
1018 ol_tx_vdev_ll_pause_queue_send_base(vdev);
1019}
1020#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1021
1022static inline int ol_txrx_tx_is_raw(enum ol_tx_spec tx_spec)
1023{
1024 return
1025 tx_spec &
1026 (ol_tx_spec_raw | ol_tx_spec_no_aggr | ol_tx_spec_no_encrypt);
1027}
1028
1029static inline uint8_t ol_txrx_tx_raw_subtype(enum ol_tx_spec tx_spec)
1030{
1031 uint8_t sub_type = 0x1; /* 802.11 MAC header present */
1032
1033 if (tx_spec & ol_tx_spec_no_aggr)
1034 sub_type |= 0x1 << HTT_TX_MSDU_DESC_RAW_SUBTYPE_NO_AGGR_S;
1035 if (tx_spec & ol_tx_spec_no_encrypt)
1036 sub_type |= 0x1 << HTT_TX_MSDU_DESC_RAW_SUBTYPE_NO_ENCRYPT_S;
1037 if (tx_spec & ol_tx_spec_nwifi_no_encrypt)
1038 sub_type |= 0x1 << HTT_TX_MSDU_DESC_RAW_SUBTYPE_NO_ENCRYPT_S;
1039 return sub_type;
1040}
1041
Nirav Shahcbc6d722016-03-01 16:24:53 +05301042qdf_nbuf_t
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001043ol_tx_non_std_ll(ol_txrx_vdev_handle vdev,
Nirav Shahcbc6d722016-03-01 16:24:53 +05301044 enum ol_tx_spec tx_spec, qdf_nbuf_t msdu_list)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001045{
Nirav Shahcbc6d722016-03-01 16:24:53 +05301046 qdf_nbuf_t msdu = msdu_list;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001047 htt_pdev_handle htt_pdev = vdev->pdev->htt_pdev;
1048 struct ol_txrx_msdu_info_t msdu_info;
1049
1050 msdu_info.htt.info.l2_hdr_type = vdev->pdev->htt_pkt_type;
1051 msdu_info.htt.action.tx_comp_req = 0;
1052
1053 /*
1054 * The msdu_list variable could be used instead of the msdu var,
1055 * but just to clarify which operations are done on a single MSDU
1056 * vs. a list of MSDUs, use a distinct variable for single MSDUs
1057 * within the list.
1058 */
1059 while (msdu) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05301060 qdf_nbuf_t next;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001061 struct ol_tx_desc_t *tx_desc;
1062
Nirav Shahcbc6d722016-03-01 16:24:53 +05301063 msdu_info.htt.info.ext_tid = qdf_nbuf_get_tid(msdu);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001064 msdu_info.peer = NULL;
1065 msdu_info.tso_info.is_tso = 0;
1066
1067 ol_tx_prepare_ll(tx_desc, vdev, msdu, &msdu_info);
1068
1069 /*
1070 * The netbuf may get linked into a different list inside the
1071 * ol_tx_send function, so store the next pointer before the
1072 * tx_send call.
1073 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05301074 next = qdf_nbuf_next(msdu);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001075
1076 if (tx_spec != ol_tx_spec_std) {
1077 if (tx_spec & ol_tx_spec_no_free) {
1078 tx_desc->pkt_type = ol_tx_frm_no_free;
1079 } else if (tx_spec & ol_tx_spec_tso) {
1080 tx_desc->pkt_type = ol_tx_frm_tso;
1081 } else if (tx_spec & ol_tx_spec_nwifi_no_encrypt) {
1082 uint8_t sub_type =
1083 ol_txrx_tx_raw_subtype(tx_spec);
1084 htt_tx_desc_type(htt_pdev, tx_desc->htt_tx_desc,
1085 htt_pkt_type_native_wifi,
1086 sub_type);
1087 } else if (ol_txrx_tx_is_raw(tx_spec)) {
1088 /* different types of raw frames */
1089 uint8_t sub_type =
1090 ol_txrx_tx_raw_subtype(tx_spec);
1091 htt_tx_desc_type(htt_pdev, tx_desc->htt_tx_desc,
1092 htt_pkt_type_raw, sub_type);
1093 }
1094 }
1095 /*
1096 * If debug display is enabled, show the meta-data being
1097 * downloaded to the target via the HTT tx descriptor.
1098 */
1099 htt_tx_desc_display(tx_desc->htt_tx_desc);
1100 ol_tx_send(vdev->pdev, tx_desc, msdu);
1101 msdu = next;
1102 }
1103 return NULL; /* all MSDUs were accepted */
1104}
1105
1106#ifdef QCA_SUPPORT_SW_TXRX_ENCAP
1107#define OL_TX_ENCAP_WRAPPER(pdev, vdev, tx_desc, msdu, tx_msdu_info) \
1108 do { \
1109 if (OL_TX_ENCAP(vdev, tx_desc, msdu, &tx_msdu_info) != A_OK) { \
Anurag Chouhan8e0ccd32016-02-19 15:30:20 +05301110 qdf_atomic_inc(&pdev->tx_queue.rsrc_cnt); \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001111 ol_tx_desc_frame_free_nonstd(pdev, tx_desc, 1); \
1112 if (tx_msdu_info.peer) { \
1113 /* remove the peer reference added above */ \
1114 ol_txrx_peer_unref_delete(tx_msdu_info.peer); \
1115 } \
1116 goto MSDU_LOOP_BOTTOM; \
1117 } \
1118 } while (0)
1119#else
1120#define OL_TX_ENCAP_WRAPPER(pdev, vdev, tx_desc, msdu, tx_msdu_info) /* no-op */
1121#endif
1122
1123/* tx filtering is handled within the target FW */
1124#define TX_FILTER_CHECK(tx_msdu_info) 0 /* don't filter */
1125
1126/**
1127 * parse_ocb_tx_header() - Function to check for OCB
1128 * TX control header on a packet and extract it if present
1129 *
Nirav Shahcbc6d722016-03-01 16:24:53 +05301130 * @msdu: Pointer to OS packet (qdf_nbuf_t)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001131 */
1132#define OCB_HEADER_VERSION 1
Nirav Shahcbc6d722016-03-01 16:24:53 +05301133bool parse_ocb_tx_header(qdf_nbuf_t msdu,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001134 struct ocb_tx_ctrl_hdr_t *tx_ctrl)
1135{
1136 struct ether_header *eth_hdr_p;
1137 struct ocb_tx_ctrl_hdr_t *tx_ctrl_hdr;
1138
1139 /* Check if TX control header is present */
Nirav Shahcbc6d722016-03-01 16:24:53 +05301140 eth_hdr_p = (struct ether_header *) qdf_nbuf_data(msdu);
Anurag Chouhan6d760662016-02-20 16:05:43 +05301141 if (eth_hdr_p->ether_type != QDF_SWAP_U16(ETHERTYPE_OCB_TX))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001142 /* TX control header is not present. Nothing to do.. */
1143 return true;
1144
1145 /* Remove the ethernet header */
Nirav Shahcbc6d722016-03-01 16:24:53 +05301146 qdf_nbuf_pull_head(msdu, sizeof(struct ether_header));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001147
1148 /* Parse the TX control header */
Nirav Shahcbc6d722016-03-01 16:24:53 +05301149 tx_ctrl_hdr = (struct ocb_tx_ctrl_hdr_t *) qdf_nbuf_data(msdu);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001150
1151 if (tx_ctrl_hdr->version == OCB_HEADER_VERSION) {
1152 if (tx_ctrl)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301153 qdf_mem_copy(tx_ctrl, tx_ctrl_hdr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001154 sizeof(*tx_ctrl_hdr));
1155 } else {
1156 /* The TX control header is invalid. */
1157 return false;
1158 }
1159
1160 /* Remove the TX control header */
Nirav Shahcbc6d722016-03-01 16:24:53 +05301161 qdf_nbuf_pull_head(msdu, tx_ctrl_hdr->length);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001162 return true;
1163}
1164
Nirav Shahcbc6d722016-03-01 16:24:53 +05301165qdf_nbuf_t
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001166ol_tx_non_std(ol_txrx_vdev_handle vdev,
Nirav Shahcbc6d722016-03-01 16:24:53 +05301167 enum ol_tx_spec tx_spec, qdf_nbuf_t msdu_list)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001168{
1169 return ol_tx_non_std_ll(vdev, tx_spec, msdu_list);
1170}
1171
1172void
1173ol_txrx_data_tx_cb_set(ol_txrx_vdev_handle vdev,
1174 ol_txrx_data_tx_cb callback, void *ctxt)
1175{
1176 struct ol_txrx_pdev_t *pdev = vdev->pdev;
1177 pdev->tx_data_callback.func = callback;
1178 pdev->tx_data_callback.ctxt = ctxt;
1179}
1180
1181void
1182ol_txrx_mgmt_tx_cb_set(ol_txrx_pdev_handle pdev,
1183 uint8_t type,
1184 ol_txrx_mgmt_tx_cb download_cb,
1185 ol_txrx_mgmt_tx_cb ota_ack_cb, void *ctxt)
1186{
1187 TXRX_ASSERT1(type < OL_TXRX_MGMT_NUM_TYPES);
1188 pdev->tx_mgmt.callbacks[type].download_cb = download_cb;
1189 pdev->tx_mgmt.callbacks[type].ota_ack_cb = ota_ack_cb;
1190 pdev->tx_mgmt.callbacks[type].ctxt = ctxt;
1191}
1192
1193#if defined(HELIUMPLUS_PADDR64)
1194void dump_frag_desc(char *msg, struct ol_tx_desc_t *tx_desc)
1195{
1196 uint32_t *frag_ptr_i_p;
1197 int i;
1198
Anurag Chouhan6d760662016-02-20 16:05:43 +05301199 qdf_print("OL TX Descriptor 0x%p msdu_id %d\n",
Leo Chang376398b2015-10-23 14:19:02 -07001200 tx_desc, tx_desc->id);
Anurag Chouhan6d760662016-02-20 16:05:43 +05301201 qdf_print("HTT TX Descriptor vaddr: 0x%p paddr: 0x%llx",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001202 tx_desc->htt_tx_desc, tx_desc->htt_tx_desc_paddr);
Anurag Chouhan6d760662016-02-20 16:05:43 +05301203 qdf_print("%s %d: Fragment Descriptor 0x%p (paddr=0x%llx)",
Houston Hoffman43d47fa2016-02-24 16:34:30 -08001204 __func__, __LINE__, tx_desc->htt_frag_desc, tx_desc->htt_frag_desc_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001205
1206 /* it looks from htt_tx_desc_frag() that tx_desc->htt_frag_desc
1207 is already de-referrable (=> in virtual address space) */
1208 frag_ptr_i_p = tx_desc->htt_frag_desc;
1209
1210 /* Dump 6 words of TSO flags */
1211 print_hex_dump(KERN_DEBUG, "MLE Desc:TSO Flags: ",
1212 DUMP_PREFIX_NONE, 8, 4,
1213 frag_ptr_i_p, 24, true);
1214
1215 frag_ptr_i_p += 6; /* Skip 6 words of TSO flags */
1216
1217 i = 0;
1218 while (*frag_ptr_i_p) {
1219 print_hex_dump(KERN_DEBUG, "MLE Desc:Frag Ptr: ",
1220 DUMP_PREFIX_NONE, 8, 4,
1221 frag_ptr_i_p, 8, true);
1222 i++;
1223 if (i > 5) /* max 6 times: frag_ptr0 to frag_ptr5 */
1224 break;
1225 else /* jump to next pointer - skip length */
1226 frag_ptr_i_p += 2;
1227 }
1228 return;
1229}
1230#endif /* HELIUMPLUS_PADDR64 */
1231
1232int
1233ol_txrx_mgmt_send(ol_txrx_vdev_handle vdev,
Nirav Shahcbc6d722016-03-01 16:24:53 +05301234 qdf_nbuf_t tx_mgmt_frm,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001235 uint8_t type, uint8_t use_6mbps, uint16_t chanfreq)
1236{
1237 struct ol_txrx_pdev_t *pdev = vdev->pdev;
1238 struct ol_tx_desc_t *tx_desc;
1239 struct ol_txrx_msdu_info_t tx_msdu_info;
1240
1241 tx_msdu_info.tso_info.is_tso = 0;
1242
1243 tx_msdu_info.htt.action.use_6mbps = use_6mbps;
1244 tx_msdu_info.htt.info.ext_tid = HTT_TX_EXT_TID_MGMT;
1245 tx_msdu_info.htt.info.vdev_id = vdev->vdev_id;
1246 tx_msdu_info.htt.action.do_tx_complete =
1247 pdev->tx_mgmt.callbacks[type].ota_ack_cb ? 1 : 0;
1248
1249 /*
1250 * FIX THIS: l2_hdr_type should only specify L2 header type
1251 * The Peregrine/Rome HTT layer provides the FW with a "pkt type"
1252 * that is a combination of L2 header type and 802.11 frame type.
1253 * If the 802.11 frame type is "mgmt", then the HTT pkt type is "mgmt".
1254 * But if the 802.11 frame type is "data", then the HTT pkt type is
1255 * the L2 header type (more or less): 802.3 vs. Native WiFi
1256 * (basic 802.11).
1257 * (Or the header type can be "raw", which is any version of the 802.11
1258 * header, and also implies that some of the offloaded tx data
1259 * processing steps may not apply.)
1260 * For efficiency, the Peregrine/Rome HTT uses the msdu_info's
1261 * l2_hdr_type field to program the HTT pkt type. Thus, this txrx SW
1262 * needs to overload the l2_hdr_type to indicate whether the frame is
1263 * data vs. mgmt, as well as 802.3 L2 header vs. 802.11 L2 header.
1264 * To fix this, the msdu_info's l2_hdr_type should be left specifying
1265 * just the L2 header type. For mgmt frames, there should be a
1266 * separate function to patch the HTT pkt type to store a "mgmt" value
1267 * rather than the L2 header type. Then the HTT pkt type can be
1268 * programmed efficiently for data frames, and the msdu_info's
1269 * l2_hdr_type field won't be confusingly overloaded to hold the 802.11
1270 * frame type rather than the L2 header type.
1271 */
1272 /*
1273 * FIX THIS: remove duplication of htt_frm_type_mgmt and
1274 * htt_pkt_type_mgmt
1275 * The htt module expects a "enum htt_pkt_type" value.
1276 * The htt_dxe module expects a "enum htt_frm_type" value.
1277 * This needs to be cleaned up, so both versions of htt use a
1278 * consistent method of specifying the frame type.
1279 */
1280#ifdef QCA_SUPPORT_INTEGRATED_SOC
1281 /* tx mgmt frames always come with a 802.11 header */
1282 tx_msdu_info.htt.info.l2_hdr_type = htt_pkt_type_native_wifi;
1283 tx_msdu_info.htt.info.frame_type = htt_frm_type_mgmt;
1284#else
1285 tx_msdu_info.htt.info.l2_hdr_type = htt_pkt_type_mgmt;
1286 tx_msdu_info.htt.info.frame_type = htt_pkt_type_mgmt;
1287#endif
1288
1289 tx_msdu_info.peer = NULL;
1290
Nirav Shahcbc6d722016-03-01 16:24:53 +05301291 qdf_nbuf_map_single(pdev->osdev, tx_mgmt_frm, QDF_DMA_TO_DEVICE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001292 /* For LL tx_comp_req is not used so initialized to 0 */
1293 tx_msdu_info.htt.action.tx_comp_req = 0;
1294 tx_desc = ol_tx_desc_ll(pdev, vdev, tx_mgmt_frm, &tx_msdu_info);
1295 /* FIX THIS -
1296 * The FW currently has trouble using the host's fragments table
1297 * for management frames. Until this is fixed, rather than
1298 * specifying the fragment table to the FW, specify just the
1299 * address of the initial fragment.
1300 */
1301#if defined(HELIUMPLUS_PADDR64)
1302 /* dump_frag_desc("ol_txrx_mgmt_send(): after ol_tx_desc_ll",
1303 tx_desc); */
1304#endif /* defined(HELIUMPLUS_PADDR64) */
1305 if (tx_desc) {
1306 /*
1307 * Following the call to ol_tx_desc_ll, frag 0 is the
1308 * HTT tx HW descriptor, and the frame payload is in
1309 * frag 1.
1310 */
1311 htt_tx_desc_frags_table_set(
1312 pdev->htt_pdev,
1313 tx_desc->htt_tx_desc,
Nirav Shahcbc6d722016-03-01 16:24:53 +05301314 qdf_nbuf_get_frag_paddr(tx_mgmt_frm, 1),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001315 0, 0);
1316#if defined(HELIUMPLUS_PADDR64) && defined(HELIUMPLUS_DEBUG)
1317 dump_frag_desc(
1318 "after htt_tx_desc_frags_table_set",
1319 tx_desc);
1320#endif /* defined(HELIUMPLUS_PADDR64) */
1321 }
1322 if (!tx_desc) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05301323 qdf_nbuf_unmap_single(pdev->osdev, tx_mgmt_frm,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301324 QDF_DMA_TO_DEVICE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001325 return -EINVAL; /* can't accept the tx mgmt frame */
1326 }
1327 TXRX_STATS_MSDU_INCR(pdev, tx.mgmt, tx_mgmt_frm);
1328 TXRX_ASSERT1(type < OL_TXRX_MGMT_NUM_TYPES);
1329 tx_desc->pkt_type = type + OL_TXRX_MGMT_TYPE_BASE;
1330
1331 htt_tx_desc_set_chanfreq(tx_desc->htt_tx_desc, chanfreq);
Nirav Shahcbc6d722016-03-01 16:24:53 +05301332 QDF_NBUF_CB_TX_PACKET_TRACK(tx_desc->netbuf) =
1333 QDF_NBUF_TX_PKT_MGMT_TRACK;
1334 ol_tx_send_nonstd(pdev, tx_desc, tx_mgmt_frm,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001335 htt_pkt_type_mgmt);
1336
1337 return 0; /* accepted the tx mgmt frame */
1338}
1339
1340void ol_txrx_sync(ol_txrx_pdev_handle pdev, uint8_t sync_cnt)
1341{
1342 htt_h2t_sync_msg(pdev->htt_pdev, sync_cnt);
1343}
1344
Nirav Shahcbc6d722016-03-01 16:24:53 +05301345qdf_nbuf_t ol_tx_reinject(struct ol_txrx_vdev_t *vdev,
1346 qdf_nbuf_t msdu, uint16_t peer_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001347{
1348 struct ol_tx_desc_t *tx_desc;
1349 struct ol_txrx_msdu_info_t msdu_info;
1350
1351 msdu_info.htt.info.l2_hdr_type = vdev->pdev->htt_pkt_type;
1352 msdu_info.htt.info.ext_tid = HTT_TX_EXT_TID_INVALID;
1353 msdu_info.peer = NULL;
1354 msdu_info.htt.action.tx_comp_req = 0;
1355 msdu_info.tso_info.is_tso = 0;
1356
1357 ol_tx_prepare_ll(tx_desc, vdev, msdu, &msdu_info);
1358 HTT_TX_DESC_POSTPONED_SET(*((uint32_t *) (tx_desc->htt_tx_desc)), true);
1359
1360 htt_tx_desc_set_peer_id(tx_desc->htt_tx_desc, peer_id);
1361
1362 ol_tx_send(vdev->pdev, tx_desc, msdu);
1363
1364 return NULL;
1365}
1366
1367#if defined(FEATURE_TSO)
1368void ol_tso_seg_list_init(struct ol_txrx_pdev_t *pdev, uint32_t num_seg)
1369{
1370 int i;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05301371 struct qdf_tso_seg_elem_t *c_element;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001372
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05301373 c_element = qdf_mem_malloc(sizeof(struct qdf_tso_seg_elem_t));
Leo Chang376398b2015-10-23 14:19:02 -07001374 pdev->tso_seg_pool.freelist = c_element;
1375 for (i = 0; i < (num_seg - 1); i++) {
1376 c_element->next =
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05301377 qdf_mem_malloc(sizeof(struct qdf_tso_seg_elem_t));
Leo Chang376398b2015-10-23 14:19:02 -07001378 c_element = c_element->next;
1379 c_element->next = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001380 }
Leo Chang376398b2015-10-23 14:19:02 -07001381 pdev->tso_seg_pool.pool_size = num_seg;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301382 qdf_spinlock_create(&pdev->tso_seg_pool.tso_mutex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001383}
1384
1385void ol_tso_seg_list_deinit(struct ol_txrx_pdev_t *pdev)
1386{
Leo Chang376398b2015-10-23 14:19:02 -07001387 int i;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05301388 struct qdf_tso_seg_elem_t *c_element;
1389 struct qdf_tso_seg_elem_t *temp;
Leo Chang376398b2015-10-23 14:19:02 -07001390
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301391 qdf_spin_lock_bh(&pdev->tso_seg_pool.tso_mutex);
Leo Chang376398b2015-10-23 14:19:02 -07001392 c_element = pdev->tso_seg_pool.freelist;
1393 for (i = 0; i < pdev->tso_seg_pool.pool_size; i++) {
1394 temp = c_element->next;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301395 qdf_mem_free(c_element);
Leo Chang376398b2015-10-23 14:19:02 -07001396 c_element = temp;
1397 if (!c_element)
1398 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001399 }
1400
1401 pdev->tso_seg_pool.freelist = NULL;
1402 pdev->tso_seg_pool.num_free = 0;
1403 pdev->tso_seg_pool.pool_size = 0;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301404 qdf_spin_unlock_bh(&pdev->tso_seg_pool.tso_mutex);
1405 qdf_spinlock_destroy(&pdev->tso_seg_pool.tso_mutex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001406}
1407#endif /* FEATURE_TSO */