xref: /wlan-dirver/qca-wifi-host-cmn/hal/wifi3.0/hal_rx_flow.h (revision 4bda764146764620920bdc6e272e4f376f785372)
1 /*
2  * Copyright (c) 2019-2020 The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all
7  * copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 #ifndef __HAL_RX_FLOW_H
19 #define __HAL_RX_FLOW_H
20 
21 #include "hal_flow.h"
22 #include "wlan_cfg.h"
23 #include "hal_api.h"
24 #include "qdf_mem.h"
25 #include "rx_flow_search_entry.h"
26 
27 #define HAL_FST_HASH_KEY_SIZE_BITS 315
28 #define HAL_FST_HASH_KEY_SIZE_BYTES 40
29 #define HAL_FST_HASH_KEY_SIZE_WORDS 10
30 #define HAL_FST_HASH_DATA_SIZE 37
31 #define HAL_FST_HASH_MASK 0x7ffff
32 #define HAL_RX_FST_ENTRY_SIZE (NUM_OF_DWORDS_RX_FLOW_SEARCH_ENTRY * 4)
33 
34 /**
35  * Four possible options for IP SA/DA prefix, currently use 0x0 which
36  * maps to type 2 in HW spec
37  */
38 #define HAL_FST_IP_DA_SA_PFX_TYPE_IPV4_COMPATIBLE_IPV6 2
39 
40 #define HAL_IP_DA_SA_PREFIX_IPV4_COMPATIBLE_IPV6 0x0
41 
42 /**
43  * REO destination indication is a lower 4-bits of hash value
44  * This should match the REO destination used in Rx hash based routing.
45  */
46 #define HAL_REO_DEST_IND_HASH_MASK	0xF
47 
48 /**
49  * REO destinations are valid from 16-31 for Hawkeye
50  * and 0-15 are not setup for SW
51  */
52 #define HAL_REO_DEST_IND_START_OFFSET 0x10
53 
54 /**
55  * struct hal_rx_flow - Rx Flow parameters to be sent to HW
56  * @tuple_info: Rx Flow 5-tuple (src & dest IP, src & dest ports, L4 protocol)
57  * @reo_destination_handler: REO destination for this flow
58  * @reo_destination_indication: REO indication for this flow
59  * @fse_metadata: Flow metadata or tag passed to HW for marking packets
60  */
61 struct hal_rx_flow {
62 	struct hal_flow_tuple_info tuple_info;
63 	uint8_t reo_destination_handler;
64 	uint8_t reo_destination_indication;
65 	uint32_t fse_metadata;
66 };
67 
68 /**
69  * enum hal_rx_fse_reo_destination_handler
70  * @HAL_RX_FSE_REO_DEST_FT: Use this entry's destination indication
71  * @HAL_RX_FSE_REO_DEST_ASPT: Use Address Search + Peer Table's entry
72  * @HAL_RX_FSE_REO_DEST_FT2: Use FT2's destination indication
73  * @HAL_RX_FSE_REO_DEST_CCE: Use CCE's destination indication for this entry
74  */
75 enum hal_rx_fse_reo_destination_handler {
76 	HAL_RX_FSE_REO_DEST_FT = 0,
77 	HAL_RX_FSE_REO_DEST_ASPT = 1,
78 	HAL_RX_FSE_REO_DEST_FT2 = 2,
79 	HAL_RX_FSE_REO_DEST_CCE = 3,
80 };
81 
82 /**
83  * struct hal_rx_fst - HAL RX Flow search table context
84  * @base_vaddr: Virtual Base address of HW FST
85  * @base_paddr: Physical Base address of HW FST
86  * @key: Pointer to 320-bit Key read from cfg
87  * @shifted_key: Pointer to left-shifted 320-bit Key used for Toeplitz Hash
88  * @max_entries : Max number of entries in flow searchh  table
89  * @max_skid_length : Max search length if there is hash collision
90  * @hash_mask: Hash mask to apply to index into FST
91  * @key_cache: Toepliz Key Cache configured key
92  */
93 struct hal_rx_fst {
94 	uint8_t *base_vaddr;
95 	qdf_dma_addr_t base_paddr;
96 	uint8_t *key;
97 	uint8_t  shifted_key[HAL_FST_HASH_KEY_SIZE_BYTES];
98 	uint16_t max_entries;
99 	uint16_t max_skid_length;
100 	uint16_t hash_mask;
101 	uint32_t key_cache[HAL_FST_HASH_KEY_SIZE_BYTES][1 << 8];
102 	uint32_t add_flow_count;
103 	uint32_t del_flow_count;
104 };
105 
106 /**
107  * hal_rx_flow_setup_fse() - Setup a flow search entry in HW FST
108  * @fst: Pointer to the Rx Flow Search Table
109  * @table_offset: offset into the table where the flow is to be setup
110  * @flow: Flow Parameters
111  *
112  * Return: Success/Failure
113  */
114 void *hal_rx_flow_setup_fse(struct hal_rx_fst *fst,
115 			    uint32_t table_offset,
116 			    struct hal_rx_flow *flow);
117 
118 /**
119  * hal_rx_flow_delete_entry() - Delete a flow from the Rx Flow Search Table
120  * @fst: Pointer to the Rx Flow Search Table
121  * @hal_rx_fse: Pointer to the Rx Flow that is to be deleted from the FST
122  *
123  * Return: Success/Failure
124  */
125 QDF_STATUS
126 hal_rx_flow_delete_entry(struct hal_rx_fst *fst, void *hal_rx_fse);
127 
128 /**
129  * hal_rx_flow_get_tuple_info() - Retrieve the 5-tuple flow info for an entry
130  * @hal_fse: Pointer to the Flow in Rx FST
131  * @tuple_info: 5-tuple info of the flow returned to the caller
132  *
133  * Return: Success/Failure
134  */
135 QDF_STATUS hal_rx_flow_get_tuple_info(void *hal_fse,
136 				      struct hal_flow_tuple_info *tuple_info);
137 
138 /**
139  * hal_rx_fst_attach() - Initialize Rx flow search table in HW FST
140  *
141  * @qdf_dev: QDF device handle
142  * @hal_fst_base_paddr: Pointer to the physical base address of the Rx FST
143  * @max_entries: Max number of flows allowed in the FST
144  * @max_search: Number of collisions allowed in the hash-based FST
145  * @hash_key: Toeplitz key used for the hash FST
146  *
147  * Return:
148  */
149 struct hal_rx_fst *
150 hal_rx_fst_attach(qdf_device_t qdf_dev,
151 		  uint64_t *hal_fst_base_paddr, uint16_t max_entries,
152 		  uint16_t max_search, uint8_t *hash_key);
153 
154 /**
155  * hal_rx_fst_detach() - De-init the Rx flow search table from HW
156  *
157  * @rx_fst: Pointer to the Rx FST
158  * @qdf_dev: QDF device handle
159  *
160  * Return:
161  */
162 void hal_rx_fst_detach(struct hal_rx_fst *rx_fst, qdf_device_t qdf_dev);
163 
164 /**
165  * hal_rx_insert_flow_entry() - Add a flow into the FST table
166  *
167  * @hal_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_index: 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(struct hal_rx_fst *fst, uint32_t flow_hash,
176 			 void *flow_tuple_info, uint32_t *flow_idx);
177 
178 /**
179  * hal_rx_find_flow_from_tuple() - Find a flow in the FST table
180  *
181  * @fst: HAL Rx FST Handle
182  * @flow_hash: Flow hash computed from flow tuple
183  * @flow_tuple_info: Flow tuple used to compute the hash
184  * @flow_index: Hash index of the flow in the table when found
185  *
186  * Return: Success if matching flow is found in the table, error otherwise
187  */
188 QDF_STATUS
189 hal_rx_find_flow_from_tuple(struct hal_rx_fst *fst, uint32_t flow_hash,
190 			    void *flow_tuple_info, uint32_t *flow_idx);
191 
192 /**
193  * hal_rx_get_hal_hash() - Retrieve hash index of a flow in the FST table
194  *
195  * @hal_fst: HAL Rx FST Handle
196  * @flow_hash: Flow hash computed from flow tuple
197  *
198  * Return: hash index truncated to the size of the hash table
199  */
200 uint32_t hal_rx_get_hal_hash(struct hal_rx_fst *hal_fst, uint32_t flow_hash);
201 
202 /**
203  * hal_flow_toeplitz_hash() - Calculate Toeplitz hash by using the cached key
204  *
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 void hal_rx_dump_fse_table(struct hal_rx_fst *fst);
214 #endif /* HAL_RX_FLOW_H */
215