Madan Mohan Koyyalamudi | e32d219 | 2013-09-28 23:54:37 -0700 | [diff] [blame] | 1 | /* |
jiad | 1f228be | 2017-04-18 18:57:04 +0800 | [diff] [blame] | 2 | * Copyright (c) 2011, 2017 The Linux Foundation. All rights reserved. |
Madan Mohan Koyyalamudi | e32d219 | 2013-09-28 23:54:37 -0700 | [diff] [blame] | 3 | * |
| 4 | * Previously licensed under the ISC license by Qualcomm Atheros, Inc. |
| 5 | * |
| 6 | * |
| 7 | * Permission to use, copy, modify, and/or distribute this software for |
| 8 | * any purpose with or without fee is hereby granted, provided that the |
| 9 | * above copyright notice and this permission notice appear in all |
| 10 | * copies. |
| 11 | * |
| 12 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL |
| 13 | * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED |
| 14 | * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE |
| 15 | * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL |
| 16 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 17 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 18 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 19 | * PERFORMANCE OF THIS SOFTWARE. |
| 20 | */ |
| 21 | |
| 22 | /* |
| 23 | * This file was originally distributed by Qualcomm Atheros, Inc. |
| 24 | * under proprietary terms before Copyright ownership was assigned |
| 25 | * to the Linux Foundation. |
| 26 | */ |
Prakash Dhavali | 7410fac | 2014-02-05 21:27:47 -0800 | [diff] [blame] | 27 | |
Madan Mohan Koyyalamudi | e32d219 | 2013-09-28 23:54:37 -0700 | [diff] [blame] | 28 | /** |
| 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 | */ |
| 58 | struct ol_tx_desc_t * |
| 59 | ol_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 | */ |
| 81 | struct ol_tx_desc_t * |
| 82 | ol_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 Agarwal | ed07f23 | 2016-06-29 17:00:11 +0530 | [diff] [blame] | 95 | static inline struct ol_tx_desc_t * |
| 96 | ol_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 Koyyalamudi | e32d219 | 2013-09-28 23:54:37 -0700 | [diff] [blame] | 105 | |
| 106 | /** |
Bian Guolei | 741f9b6 | 2016-10-26 14:42:15 +0800 | [diff] [blame] | 107 | * @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 |
| 117 | static inline struct ol_tx_desc_t * |
| 118 | ol_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 Yu | d46fc49 | 2017-12-25 17:03:51 +0800 | [diff] [blame] | 122 | if (tx_desc_id >= pdev->tx_desc.pool_size) |
| 123 | return NULL; |
| 124 | |
Bian Guolei | 741f9b6 | 2016-10-26 14:42:15 +0800 | [diff] [blame] | 125 | 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 | |
| 136 | static inline struct ol_tx_desc_t * |
| 137 | ol_tx_desc_find_check(struct ol_txrx_pdev_t *pdev, u_int16_t tx_desc_id) |
| 138 | { |
jiad | 1f228be | 2017-04-18 18:57:04 +0800 | [diff] [blame] | 139 | struct ol_tx_desc_t *tx_desc; |
| 140 | |
Tiger Yu | d46fc49 | 2017-12-25 17:03:51 +0800 | [diff] [blame] | 141 | if (tx_desc_id >= pdev->tx_desc.pool_size) |
| 142 | return NULL; |
| 143 | |
jiad | 1f228be | 2017-04-18 18:57:04 +0800 | [diff] [blame] | 144 | 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 Guolei | 741f9b6 | 2016-10-26 14:42:15 +0800 | [diff] [blame] | 151 | } |
| 152 | #endif |
| 153 | |
| 154 | /** |
Madan Mohan Koyyalamudi | e32d219 | 2013-09-28 23:54:37 -0700 | [diff] [blame] | 155 | * @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 Johnson | db1718e | 2014-02-18 15:56:58 -0800 | [diff] [blame] | 163 | * |
Madan Mohan Koyyalamudi | e32d219 | 2013-09-28 23:54:37 -0700 | [diff] [blame] | 164 | * @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 | */ |
| 170 | void 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 Johnson | db1718e | 2014-02-18 15:56:58 -0800 | [diff] [blame] | 185 | * |
Madan Mohan Koyyalamudi | e32d219 | 2013-09-28 23:54:37 -0700 | [diff] [blame] | 186 | * @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 | */ |
| 192 | void 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 | */ |
| 204 | static inline u_int16_t |
| 205 | ol_tx_desc_id(struct ol_txrx_pdev_t *pdev, struct ol_tx_desc_t *tx_desc) |
| 206 | { |
Leo Chang | c574beb | 2015-09-18 11:07:46 -0700 | [diff] [blame] | 207 | TXRX_ASSERT2(tx_desc->id < pdev->tx_desc.pool_size); |
| 208 | return tx_desc->id; |
Madan Mohan Koyyalamudi | e32d219 | 2013-09-28 23:54:37 -0700 | [diff] [blame] | 209 | } |
| 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 | |
| 217 | void * |
| 218 | ol_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 | */ |
| 230 | void |
| 231 | ol_tx_desc_free(struct ol_txrx_pdev_t *pdev, struct ol_tx_desc_t *tx_desc); |
| 232 | |
| 233 | #endif /* _OL_TX_DESC__H_ */ |