1 /* 2 * Copyright (c) 2019-2021 The Linux Foundation. All rights reserved. 3 * Copyright (c) 2021-2023 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 #ifndef __HAL_RX_FLOW_H 20 #define __HAL_RX_FLOW_H 21 22 #include "hal_flow.h" 23 #include "wlan_cfg.h" 24 #include "hal_api.h" 25 #include "qdf_mem.h" 26 #include "rx_flow_search_entry.h" 27 #include "hal_rx_flow_info.h" 28 29 #define HAL_FST_HASH_KEY_SIZE_BITS 315 30 #define HAL_FST_HASH_KEY_SIZE_WORDS 10 31 #define HAL_FST_HASH_DATA_SIZE 37 32 #define HAL_FST_HASH_MASK 0x7ffff 33 #define HAL_RX_FST_ENTRY_SIZE (NUM_OF_DWORDS_RX_FLOW_SEARCH_ENTRY * 4) 34 35 /* 36 * Four possible options for IP SA/DA prefix, currently use 0x0 which 37 * maps to type 2 in HW spec 38 */ 39 #define HAL_FST_IP_DA_SA_PFX_TYPE_IPV4_COMPATIBLE_IPV6 2 40 41 #define HAL_IP_DA_SA_PREFIX_IPV4_COMPATIBLE_IPV6 0x0 42 43 /* 44 * REO destination indication is a lower 4-bits of hash value 45 * This should match the REO destination used in Rx hash based routing. 46 */ 47 #define HAL_REO_DEST_IND_HASH_MASK 0xF 48 49 /* 50 * REO destinations are valid from 16-31 for Hawkeye 51 * and 0-15 are not setup for SW 52 */ 53 #define HAL_REO_DEST_IND_START_OFFSET 0x10 54 55 /** 56 * enum hal_rx_fse_reo_destination_handler 57 * @HAL_RX_FSE_REO_DEST_FT: Use this entry's destination indication 58 * @HAL_RX_FSE_REO_DEST_ASPT: Use Address Search + Peer Table's entry 59 * @HAL_RX_FSE_REO_DEST_FT2: Use FT2's destination indication 60 * @HAL_RX_FSE_REO_DEST_CCE: Use CCE's destination indication for this entry 61 */ 62 enum hal_rx_fse_reo_destination_handler { 63 HAL_RX_FSE_REO_DEST_FT = 0, 64 HAL_RX_FSE_REO_DEST_ASPT = 1, 65 HAL_RX_FSE_REO_DEST_FT2 = 2, 66 HAL_RX_FSE_REO_DEST_CCE = 3, 67 }; 68 69 /** 70 * hal_rx_flow_setup_fse() - Setup a flow search entry in HW FST 71 * @hal_soc_hdl: HAL SOC handle 72 * @fst: Pointer to the Rx Flow Search Table 73 * @table_offset: offset into the table where the flow is to be setup 74 * @flow: Flow Parameters 75 * 76 * Return: Success/Failure 77 */ 78 void * 79 hal_rx_flow_setup_fse(hal_soc_handle_t hal_soc_hdl, 80 struct hal_rx_fst *fst, uint32_t table_offset, 81 struct hal_rx_flow *flow); 82 83 /** 84 * hal_rx_flow_setup_cmem_fse() - Setup a flow search entry in HW CMEM FST 85 * @hal_soc_hdl: HAL SOC handle 86 * @cmem_ba: CMEM base address 87 * @table_offset: offset into the table where the flow is to be setup 88 * @flow: Flow Parameters 89 * 90 * Return: Success/Failure 91 */ 92 uint32_t 93 hal_rx_flow_setup_cmem_fse(hal_soc_handle_t hal_soc_hdl, uint32_t cmem_ba, 94 uint32_t table_offset, struct hal_rx_flow *flow); 95 96 /** 97 * hal_rx_flow_get_cmem_fse_timestamp() - Get timestamp field from CMEM FSE 98 * @hal_soc_hdl: HAL SOC handle 99 * @fse_offset: CMEM FSE offset 100 * 101 * Return: Timestamp 102 */ 103 uint32_t hal_rx_flow_get_cmem_fse_timestamp(hal_soc_handle_t hal_soc_hdl, 104 uint32_t fse_offset); 105 106 /** 107 * hal_rx_flow_delete_entry() - Delete a flow from the Rx Flow Search Table 108 * @hal_soc_hdl: HAL SOC handle 109 * @fst: Pointer to the Rx Flow Search Table 110 * @hal_rx_fse: Pointer to the Rx Flow that is to be deleted from the FST 111 * 112 * Return: Success/Failure 113 */ 114 QDF_STATUS 115 hal_rx_flow_delete_entry(hal_soc_handle_t hal_soc_hdl, 116 struct hal_rx_fst *fst, void *hal_rx_fse); 117 118 /** 119 * hal_rx_flow_get_tuple_info() - Retrieve the 5-tuple flow info for an entry 120 * @hal_soc_hdl: HAL SOC handle 121 * @fst: Pointer to the Rx Flow Search Table 122 * @hal_hash: HAL 5 tuple hash 123 * @tuple_info: 5-tuple info of the flow returned to the caller 124 * 125 * Return: 5-tuple flow info 126 */ 127 void * 128 hal_rx_flow_get_tuple_info(hal_soc_handle_t hal_soc_hdl, 129 struct hal_rx_fst *fst, 130 uint32_t hal_hash, 131 struct hal_flow_tuple_info *tuple_info); 132 133 /** 134 * hal_rx_fst_attach() - Initialize Rx flow search table in HW FST 135 * @hal_soc_hdl: HAL SOC handle 136 * @qdf_dev: QDF device handle 137 * @hal_fst_base_paddr: Pointer to the physical base address of the Rx FST 138 * @max_entries: Max number of flows allowed in the FST 139 * @max_search: Number of collisions allowed in the hash-based FST 140 * @hash_key: Toeplitz key used for the hash FST 141 * @fst_cmem_base: FST CMEM base address 142 * 143 * Return: FST object on success, NULL on memory allocation failure 144 */ 145 struct hal_rx_fst * 146 hal_rx_fst_attach(hal_soc_handle_t hal_soc_hdl, 147 qdf_device_t qdf_dev, 148 uint64_t *hal_fst_base_paddr, uint16_t max_entries, 149 uint16_t max_search, uint8_t *hash_key, 150 uint64_t fst_cmem_base); 151 152 /** 153 * hal_rx_fst_detach() - De-init the Rx flow search table from HW 154 * @hal_soc_hdl: HAL SOC handler 155 * @rx_fst: Pointer to the Rx FST 156 * @qdf_dev: QDF device handle 157 * @fst_cmem_base: FST CMEM base address 158 * 159 * Return: 160 */ 161 void hal_rx_fst_detach(hal_soc_handle_t hal_soc_hdl, struct hal_rx_fst *rx_fst, 162 qdf_device_t qdf_dev, uint64_t fst_cmem_base); 163 164 /** 165 * hal_rx_insert_flow_entry() - Add a flow into the FST table 166 * @hal_soc_hdl: HAL SOC handle 167 * @fst: HAL Rx FST Handle 168 * @flow_hash: Flow hash computed from flow tuple 169 * @flow_tuple_info: Flow tuple used to compute the hash 170 * @flow_idx: Hash index of the flow in the table when inserted successfully 171 * 172 * Return: Success if flow is inserted into the table, error otherwise 173 */ 174 QDF_STATUS 175 hal_rx_insert_flow_entry(hal_soc_handle_t hal_soc_hdl, 176 struct hal_rx_fst *fst, uint32_t flow_hash, 177 void *flow_tuple_info, uint32_t *flow_idx); 178 179 /** 180 * hal_rx_find_flow_from_tuple() - Find a flow in the FST table 181 * @hal_soc_hdl: HAL SOC handle 182 * @fst: HAL Rx FST Handle 183 * @flow_hash: Flow hash computed from flow tuple 184 * @flow_tuple_info: Flow tuple used to compute the hash 185 * @flow_idx: Hash index of the flow in the table when found 186 * 187 * Return: Success if matching flow is found in the table, error otherwise 188 */ 189 QDF_STATUS 190 hal_rx_find_flow_from_tuple(hal_soc_handle_t hal_soc_hdl, 191 struct hal_rx_fst *fst, uint32_t flow_hash, 192 void *flow_tuple_info, uint32_t *flow_idx); 193 194 /** 195 * hal_rx_get_hal_hash() - Retrieve hash index of a flow in the FST table 196 * @hal_fst: HAL Rx FST Handle 197 * @flow_hash: Flow hash computed from flow tuple 198 * 199 * Return: hash index truncated to the size of the hash table 200 */ 201 uint32_t hal_rx_get_hal_hash(struct hal_rx_fst *hal_fst, uint32_t flow_hash); 202 203 /** 204 * hal_flow_toeplitz_hash() - Calculate Toeplitz hash by using the cached key 205 * @hal_fst: FST Handle 206 * @flow: Flow Parameters 207 * 208 * Return: Success/Failure 209 */ 210 uint32_t 211 hal_flow_toeplitz_hash(void *hal_fst, struct hal_rx_flow *flow); 212 213 /** 214 * hal_rx_dump_fse_table() - Dump the RX FSE table 215 * @fst: HAL RX FST table to dump 216 */ 217 void hal_rx_dump_fse_table(struct hal_rx_fst *fst); 218 219 /** 220 * hal_rx_dump_cmem_fse() - Dump flow search table entry which is in CMEM 221 * @hal_soc_hdl: HAL SOC handle 222 * @fse_offset: Offset in to the CMEM where FSE is located 223 * @index: FSE index 224 * 225 * Return: None 226 */ 227 void hal_rx_dump_cmem_fse(hal_soc_handle_t hal_soc_hdl, uint32_t fse_offset, 228 int index); 229 #endif /* HAL_RX_FLOW_H */ 230