blob: 7a6f055102deca19b8db46fe151d9ccd8b7a23cc [file] [log] [blame]
Madan Mohan Koyyalamudie32d2192013-09-28 23:54:37 -07001/*
jiad1f228be2017-04-18 18:57:04 +08002 * Copyright (c) 2011, 2017 The Linux Foundation. All rights reserved.
Madan Mohan Koyyalamudie32d2192013-09-28 23:54:37 -07003 *
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 */
Prakash Dhavali7410fac2014-02-05 21:27:47 -080027
Madan Mohan Koyyalamudie32d2192013-09-28 23:54:37 -070028/**
29 * @file ol_tx_desc.h
30 * @brief API definitions for the tx descriptor module within the data SW.
31 */
32#ifndef _OL_TX_DESC__H_
33#define _OL_TX_DESC__H_
34
35#include <queue.h> /* TAILQ_HEAD */
36#include <adf_nbuf.h> /* adf_nbuf_t */
37#include <ol_txrx_types.h> /* ol_tx_desc_t */
38#include <ol_txrx_internal.h> /*TXRX_ASSERT2 */
39
40/**
41 * @brief Allocate and initialize a tx descriptor for a LL system.
42 * @details
43 * Allocate a tx descriptor pair for a new tx frame - a SW tx descriptor
44 * for private use within the host data SW, and a HTT tx descriptor for
45 * downloading tx meta-data to the target FW/HW.
46 * Fill in the fields of this pair of tx descriptors based on the
47 * information in the netbuf.
48 * For LL, this includes filling in a fragmentation descriptor to
49 * specify to the MAC HW where to find the tx frame's fragments.
50 *
51 * @param pdev - the data physical device sending the data
52 * (for accessing the tx desc pool)
53 * @param vdev - the virtual device sending the data
54 * (for specifying the transmitter address for multicast / broadcast data)
55 * @param netbuf - the tx frame
56 * @param msdu_info - tx meta-data
57 */
58struct ol_tx_desc_t *
59ol_tx_desc_ll(
60 struct ol_txrx_pdev_t *pdev,
61 struct ol_txrx_vdev_t *vdev,
62 adf_nbuf_t netbuf,
63 struct ol_txrx_msdu_info_t *msdu_info);
64
65/**
66 * @brief Allocate and initialize a tx descriptor for a HL system.
67 * @details
68 * Allocate a tx descriptor pair for a new tx frame - a SW tx descriptor
69 * for private use within the host data SW, and a HTT tx descriptor for
70 * downloading tx meta-data to the target FW/HW.
71 * Fill in the fields of this pair of tx descriptors based on the
72 * information in the netbuf.
73 *
74 * @param pdev - the data physical device sending the data
75 * (for accessing the tx desc pool)
76 * @param vdev - the virtual device sending the data
77 * (for specifying the transmitter address for multicast / broadcast data)
78 * @param netbuf - the tx frame
79 * @param msdu_info - tx meta-data
80 */
81struct ol_tx_desc_t *
82ol_tx_desc_hl(
83 struct ol_txrx_pdev_t *pdev,
84 struct ol_txrx_vdev_t *vdev,
85 adf_nbuf_t netbuf,
86 struct ol_txrx_msdu_info_t *msdu_info);
87
88/**
89 * @brief Use a tx descriptor ID to find the corresponding desriptor object.
90 *
91 * @param pdev - the data physical device sending the data
92 * @param tx_desc_id - the ID of the descriptor in question
93 * @return the descriptor object that has the specified ID
94 */
Himanshu Agarwaled07f232016-06-29 17:00:11 +053095static inline struct ol_tx_desc_t *
96ol_tx_desc_find(struct ol_txrx_pdev_t *pdev, u_int16_t tx_desc_id)
97{
98 void **td_base = (void **)pdev->tx_desc.desc_pages.cacheable_pages;
99
100 return &((union ol_tx_desc_list_elem_t *)
101 (td_base[tx_desc_id >> pdev->tx_desc.page_divider] +
102 (pdev->tx_desc.desc_reserved_size *
103 (tx_desc_id & pdev->tx_desc.offset_filter))))->tx_desc;
104}
Madan Mohan Koyyalamudie32d2192013-09-28 23:54:37 -0700105
106/**
Bian Guolei741f9b62016-10-26 14:42:15 +0800107 * @brief Use a tx descriptor ID to find the corresponding desriptor object
108 * and add sanity check.
109 *
110 * @param pdev - the data physical device sending the data
111 * @param tx_desc_id - the ID of the descriptor in question
112 * @return the descriptor object that has the specified ID,
113 * if failure, will return NULL.
114 */
115
116#ifdef QCA_SUPPORT_TXDESC_SANITY_CHECKS
117static inline struct ol_tx_desc_t *
118ol_tx_desc_find_check(struct ol_txrx_pdev_t *pdev, u_int16_t tx_desc_id)
119{
120 struct ol_tx_desc_t *tx_desc;
121
Tiger Yud46fc492017-12-25 17:03:51 +0800122 if (tx_desc_id >= pdev->tx_desc.pool_size)
123 return NULL;
124
Bian Guolei741f9b62016-10-26 14:42:15 +0800125 tx_desc = ol_tx_desc_find(pdev, tx_desc_id);
126
127 if (tx_desc->pkt_type == ol_tx_frm_freed) {
128 return NULL;
129 }
130
131 return tx_desc;
132}
133
134#else
135
136static inline struct ol_tx_desc_t *
137ol_tx_desc_find_check(struct ol_txrx_pdev_t *pdev, u_int16_t tx_desc_id)
138{
jiad1f228be2017-04-18 18:57:04 +0800139 struct ol_tx_desc_t *tx_desc;
140
Tiger Yud46fc492017-12-25 17:03:51 +0800141 if (tx_desc_id >= pdev->tx_desc.pool_size)
142 return NULL;
143
jiad1f228be2017-04-18 18:57:04 +0800144 tx_desc = ol_tx_desc_find(pdev, tx_desc_id);
145
146 /* check against invalid tx_desc_id */
147 if (ol_cfg_is_high_latency(pdev->ctrl_pdev) && !tx_desc->vdev)
148 return NULL;
149
150 return tx_desc;
Bian Guolei741f9b62016-10-26 14:42:15 +0800151}
152#endif
153
154/**
Madan Mohan Koyyalamudie32d2192013-09-28 23:54:37 -0700155 * @brief Free a list of tx descriptors and the tx frames they refer to.
156 * @details
157 * Free a batch of "standard" tx descriptors and their tx frames.
158 * Free each tx descriptor, by returning it to the freelist.
159 * Unmap each netbuf, and free the netbufs as a batch.
160 * Irregular tx frames like TSO or managment frames that require
161 * special handling are processed by the ol_tx_desc_frame_free_nonstd
162 * function rather than this function.
Jeff Johnsondb1718e2014-02-18 15:56:58 -0800163 *
Madan Mohan Koyyalamudie32d2192013-09-28 23:54:37 -0700164 * @param pdev - the data physical device that sent the data
165 * @param tx_descs - a list of SW tx descriptors for the tx frames
166 * @param had_error - boolean indication of whether the transmission failed.
167 * This is provided to callback functions that get notified of
168 * the tx frame completion.
169 */
170void ol_tx_desc_frame_list_free(
171 struct ol_txrx_pdev_t *pdev,
172 ol_tx_desc_list *tx_descs,
173 int had_error);
174
175/**
176 * @brief Free a non-standard tx frame and its tx descriptor.
177 * @details
178 * Check the tx frame type (e.g. TSO vs. management) to determine what
179 * special steps, if any, need to be performed prior to freeing the
180 * tx frame and its tx descriptor.
181 * This function can also be used to free single standard tx frames.
182 * After performing any special steps based on tx frame type, free the
183 * tx descriptor, i.e. return it to the freelist, and unmap and
184 * free the netbuf referenced by the tx descriptor.
Jeff Johnsondb1718e2014-02-18 15:56:58 -0800185 *
Madan Mohan Koyyalamudie32d2192013-09-28 23:54:37 -0700186 * @param pdev - the data physical device that sent the data
187 * @param tx_desc - the SW tx descriptor for the tx frame that was sent
188 * @param had_error - boolean indication of whether the transmission failed.
189 * This is provided to callback functions that get notified of
190 * the tx frame completion.
191 */
192void ol_tx_desc_frame_free_nonstd(
193 struct ol_txrx_pdev_t *pdev,
194 struct ol_tx_desc_t *tx_desc,
195 int had_error);
196
197/*
198 * @brief Determine the ID of a tx descriptor.
199 *
200 * @param pdev - the physical device that is sending the data
201 * @param tx_desc - the descriptor whose ID is being determined
202 * @return numeric ID that uniquely identifies the tx descriptor
203 */
204static inline u_int16_t
205ol_tx_desc_id(struct ol_txrx_pdev_t *pdev, struct ol_tx_desc_t *tx_desc)
206{
Leo Changc574beb2015-09-18 11:07:46 -0700207 TXRX_ASSERT2(tx_desc->id < pdev->tx_desc.pool_size);
208 return tx_desc->id;
Madan Mohan Koyyalamudie32d2192013-09-28 23:54:37 -0700209}
210/*
211 * @brief Retrieves the beacon headr for the vdev
212 * @param pdev - opaque pointe to scn
213 * @param vdevid - vdev id
214 * @return void pointer to the beacon header for the given vdev
215 */
216
217void *
218ol_ath_get_bcn_header(ol_pdev_handle pdev, A_UINT32 vdev_id);
219
220/*
221 * @brief Free a tx descriptor, without freeing the matching frame.
222 * @details
223 * This function is using during the function call that submits tx frames
224 * into the txrx layer, for cases where a tx descriptor is successfully
225 * allocated, but for other reasons the frame could not be accepted.
226 *
227 * @param pdev - the data physical device that is sending the data
228 * @param tx_desc - the descriptor being freed
229 */
230void
231ol_tx_desc_free(struct ol_txrx_pdev_t *pdev, struct ol_tx_desc_t *tx_desc);
232
233#endif /* _OL_TX_DESC__H_ */