hal_rx_flow.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  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 any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include "qdf_module.h"
  17. #include "dp_types.h"
  18. #include "hal_rx_flow.h"
  19. #if defined(WLAN_SUPPORT_RX_FISA)
  20. void hal_rx_dump_fse_table(struct hal_rx_fst *fst)
  21. {
  22. int i = 0;
  23. struct rx_flow_search_entry *fse =
  24. (struct rx_flow_search_entry *)fst->base_vaddr;
  25. dp_info("Number flow table entries %d", fst->add_flow_count);
  26. for (i = 0; i < fst->max_entries; i++) {
  27. if (fse[i].valid) {
  28. dp_info("index %d:"
  29. " src_ip_127_96 0x%x"
  30. " src_ip_95_640 0x%x"
  31. " src_ip_63_32 0x%x"
  32. " src_ip_31_0 0x%x"
  33. " dest_ip_127_96 0x%x"
  34. " dest_ip_95_64 0x%x"
  35. " dest_ip_63_32 0x%x"
  36. " dest_ip_31_0 0x%x"
  37. " src_port 0x%x"
  38. " dest_port 0x%x"
  39. " l4_protocol 0x%x"
  40. " valid 0x%x"
  41. " reo_destination_indication 0x%x"
  42. " msdu_drop 0x%x"
  43. " reo_destination_handler 0x%x"
  44. " metadata 0x%x"
  45. " aggregation_count0x%x"
  46. " lro_eligible 0x%x"
  47. " msdu_count 0x%x"
  48. " msdu_byte_count 0x%x"
  49. " timestamp 0x%x"
  50. " cumulative_l4_checksum 0x%x"
  51. " cumulative_ip_length 0x%x"
  52. " tcp_sequence_number 0x%x",
  53. i,
  54. fse[i].src_ip_127_96,
  55. fse[i].src_ip_95_64,
  56. fse[i].src_ip_63_32,
  57. fse[i].src_ip_31_0,
  58. fse[i].dest_ip_127_96,
  59. fse[i].dest_ip_95_64,
  60. fse[i].dest_ip_63_32,
  61. fse[i].dest_ip_31_0,
  62. fse[i].src_port,
  63. fse[i].dest_port,
  64. fse[i].l4_protocol,
  65. fse[i].valid,
  66. fse[i].reo_destination_indication,
  67. fse[i].msdu_drop,
  68. fse[i].reo_destination_handler,
  69. fse[i].metadata,
  70. fse[i].aggregation_count,
  71. fse[i].lro_eligible,
  72. fse[i].msdu_count,
  73. fse[i].msdu_byte_count,
  74. fse[i].timestamp,
  75. fse[i].cumulative_l4_checksum,
  76. fse[i].cumulative_ip_length,
  77. fse[i].tcp_sequence_number);
  78. }
  79. }
  80. }
  81. #else
  82. void hal_rx_dump_fse_table(struct hal_rx_fst *fst)
  83. {
  84. }
  85. #endif
  86. /**
  87. * hal_rx_flow_setup_fse() - Setup a flow search entry in HW FST
  88. * @fst: Pointer to the Rx Flow Search Table
  89. * @table_offset: offset into the table where the flow is to be setup
  90. * @flow: Flow Parameters
  91. *
  92. * Return: Success/Failure
  93. */
  94. void *
  95. hal_rx_flow_setup_fse(hal_soc_handle_t hal_soc_hdl,
  96. struct hal_rx_fst *fst, uint32_t table_offset,
  97. struct hal_rx_flow *flow)
  98. {
  99. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  100. if (hal_soc->ops->hal_rx_flow_setup_fse) {
  101. return hal_soc->ops->hal_rx_flow_setup_fse((uint8_t *)fst,
  102. table_offset,
  103. (uint8_t *)flow);
  104. }
  105. return NULL;
  106. }
  107. qdf_export_symbol(hal_rx_flow_setup_fse);
  108. /**
  109. * hal_rx_flow_delete_entry() - Delete a flow from the Rx Flow Search Table
  110. * @fst: Pointer to the Rx Flow Search Table
  111. * @hal_rx_fse: Pointer to the Rx Flow that is to be deleted from the FST
  112. *
  113. * Return: Success/Failure
  114. */
  115. inline QDF_STATUS
  116. hal_rx_flow_delete_entry(struct hal_rx_fst *fst, void *hal_rx_fse)
  117. {
  118. uint8_t *fse = (uint8_t *)hal_rx_fse;
  119. if (!HAL_GET_FLD(fse, RX_FLOW_SEARCH_ENTRY_9, VALID))
  120. return QDF_STATUS_E_NOENT;
  121. HAL_CLR_FLD(fse, RX_FLOW_SEARCH_ENTRY_9, VALID);
  122. return QDF_STATUS_SUCCESS;
  123. }
  124. qdf_export_symbol(hal_rx_flow_delete_entry);
  125. #ifndef WLAN_SUPPORT_RX_FISA
  126. /**
  127. * hal_rx_fst_key_configure() - Configure the Toeplitz key in the FST
  128. * @fst: Pointer to the Rx Flow Search Table
  129. *
  130. * Return: Success/Failure
  131. */
  132. static void hal_rx_fst_key_configure(struct hal_rx_fst *fst)
  133. {
  134. uint8_t key_bytes[HAL_FST_HASH_KEY_SIZE_BYTES];
  135. qdf_mem_copy(key_bytes, fst->key, HAL_FST_HASH_KEY_SIZE_BYTES);
  136. /**
  137. * The Toeplitz algorithm as per the Microsoft spec works in a
  138. * “big-endian” manner, using the MSBs of the key to hash the
  139. * initial bytes of the input going on to use up the lower order bits
  140. * of the key to hash further bytes of the input until the LSBs of the
  141. * key are used finally.
  142. *
  143. * So first, rightshift 320-bit input key 5 times to get 315 MS bits
  144. */
  145. key_bitwise_shift_left(key_bytes, HAL_FST_HASH_KEY_SIZE_BYTES, 5);
  146. key_reverse(fst->shifted_key, key_bytes, HAL_FST_HASH_KEY_SIZE_BYTES);
  147. }
  148. #else
  149. static void hal_rx_fst_key_configure(struct hal_rx_fst *fst)
  150. {
  151. }
  152. #endif
  153. /**
  154. * hal_rx_fst_get_base() - Retrieve the virtual base address of the Rx FST
  155. * @fst: Pointer to the Rx Flow Search Table
  156. *
  157. * Return: Success/Failure
  158. */
  159. static inline void *hal_rx_fst_get_base(struct hal_rx_fst *fst)
  160. {
  161. return fst->base_vaddr;
  162. }
  163. /**
  164. * hal_rx_fst_get_fse_size() - Retrieve the size of each entry(flow) in Rx FST
  165. *
  166. * Return: size of each entry/flow in Rx FST
  167. */
  168. static inline uint32_t hal_rx_fst_get_fse_size(void)
  169. {
  170. return HAL_RX_FST_ENTRY_SIZE;
  171. }
  172. /**
  173. * hal_rx_flow_get_tuple_info() - Retrieve the 5-tuple flow info for an entry
  174. * @hal_fse: Pointer to the Flow in Rx FST
  175. * @tuple_info: 5-tuple info of the flow returned to the caller
  176. *
  177. * Return: Success/Failure
  178. */
  179. QDF_STATUS hal_rx_flow_get_tuple_info(void *hal_fse,
  180. struct hal_flow_tuple_info *tuple_info)
  181. {
  182. if (!hal_fse || !tuple_info)
  183. return QDF_STATUS_E_INVAL;
  184. if (!HAL_GET_FLD(hal_fse, RX_FLOW_SEARCH_ENTRY_9, VALID))
  185. return QDF_STATUS_E_NOENT;
  186. tuple_info->src_ip_127_96 =
  187. qdf_ntohl(HAL_GET_FLD(hal_fse,
  188. RX_FLOW_SEARCH_ENTRY_0,
  189. SRC_IP_127_96));
  190. tuple_info->src_ip_95_64 =
  191. qdf_ntohl(HAL_GET_FLD(hal_fse,
  192. RX_FLOW_SEARCH_ENTRY_1,
  193. SRC_IP_95_64));
  194. tuple_info->src_ip_63_32 =
  195. qdf_ntohl(HAL_GET_FLD(hal_fse,
  196. RX_FLOW_SEARCH_ENTRY_2,
  197. SRC_IP_63_32));
  198. tuple_info->src_ip_31_0 =
  199. qdf_ntohl(HAL_GET_FLD(hal_fse,
  200. RX_FLOW_SEARCH_ENTRY_3,
  201. SRC_IP_31_0));
  202. tuple_info->dest_ip_127_96 =
  203. qdf_ntohl(HAL_GET_FLD(hal_fse,
  204. RX_FLOW_SEARCH_ENTRY_4,
  205. DEST_IP_127_96));
  206. tuple_info->dest_ip_95_64 =
  207. qdf_ntohl(HAL_GET_FLD(hal_fse,
  208. RX_FLOW_SEARCH_ENTRY_5,
  209. DEST_IP_95_64));
  210. tuple_info->dest_ip_63_32 =
  211. qdf_ntohl(HAL_GET_FLD(hal_fse,
  212. RX_FLOW_SEARCH_ENTRY_6,
  213. DEST_IP_63_32));
  214. tuple_info->dest_ip_31_0 =
  215. qdf_ntohl(HAL_GET_FLD(hal_fse,
  216. RX_FLOW_SEARCH_ENTRY_7,
  217. DEST_IP_31_0));
  218. tuple_info->dest_port = HAL_GET_FLD(hal_fse,
  219. RX_FLOW_SEARCH_ENTRY_8,
  220. DEST_PORT);
  221. tuple_info->src_port = HAL_GET_FLD(hal_fse,
  222. RX_FLOW_SEARCH_ENTRY_8,
  223. SRC_PORT);
  224. tuple_info->l4_protocol = HAL_GET_FLD(hal_fse,
  225. RX_FLOW_SEARCH_ENTRY_9,
  226. L4_PROTOCOL);
  227. return QDF_STATUS_SUCCESS;
  228. }
  229. #ifndef WLAN_SUPPORT_RX_FISA
  230. /**
  231. * hal_flow_toeplitz_create_cache() - Calculate hashes for each possible
  232. * byte value with the key taken as is
  233. *
  234. * @fst: FST Handle
  235. * @key: Hash Key
  236. *
  237. * Return: Success/Failure
  238. */
  239. static void hal_flow_toeplitz_create_cache(struct hal_rx_fst *fst)
  240. {
  241. int bit;
  242. int val;
  243. int i;
  244. uint8_t *key = fst->shifted_key;
  245. /*
  246. * Initialise to first 32 bits of the key; shift in further key material
  247. * through the loop
  248. */
  249. uint32_t cur_key = (key[0] << 24) | (key[1] << 16) | (key[2] << 8) |
  250. key[3];
  251. for (i = 0; i < HAL_FST_HASH_KEY_SIZE_BYTES; i++) {
  252. uint8_t new_key_byte;
  253. uint32_t shifted_key[8];
  254. if (i + 4 < HAL_FST_HASH_KEY_SIZE_BYTES)
  255. new_key_byte = key[i + 4];
  256. else
  257. new_key_byte = 0;
  258. shifted_key[0] = cur_key;
  259. for (bit = 1; bit < 8; bit++) {
  260. /*
  261. * For each iteration, shift out one more bit of the
  262. * current key and shift in one more bit of the new key
  263. * material
  264. */
  265. shifted_key[bit] = cur_key << bit |
  266. new_key_byte >> (8 - bit);
  267. }
  268. for (val = 0; val < (1 << 8); val++) {
  269. uint32_t hash = 0;
  270. int mask;
  271. /*
  272. * For each bit set in the input, XOR in
  273. * the appropriately shifted key
  274. */
  275. for (bit = 0, mask = 1 << 7; bit < 8; bit++, mask >>= 1)
  276. if ((val & mask))
  277. hash ^= shifted_key[bit];
  278. fst->key_cache[i][val] = hash;
  279. }
  280. cur_key = cur_key << 8 | new_key_byte;
  281. }
  282. }
  283. #else
  284. static void hal_flow_toeplitz_create_cache(struct hal_rx_fst *fst)
  285. {
  286. }
  287. #endif
  288. /**
  289. * hal_rx_fst_attach() - Initialize Rx flow search table in HW FST
  290. *
  291. * @qdf_dev: QDF device handle
  292. * @hal_fst_base_paddr: Pointer to the physical base address of the Rx FST
  293. * @max_entries: Max number of flows allowed in the FST
  294. * @max_search: Number of collisions allowed in the hash-based FST
  295. * @hash_key: Toeplitz key used for the hash FST
  296. *
  297. * Return:
  298. */
  299. struct hal_rx_fst *
  300. hal_rx_fst_attach(qdf_device_t qdf_dev,
  301. uint64_t *hal_fst_base_paddr, uint16_t max_entries,
  302. uint16_t max_search, uint8_t *hash_key)
  303. {
  304. struct hal_rx_fst *fst = qdf_mem_malloc(sizeof(struct hal_rx_fst));
  305. if (!fst) {
  306. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  307. FL("hal fst allocation failed,"));
  308. return NULL;
  309. }
  310. qdf_mem_set(fst, 0, sizeof(struct hal_rx_fst));
  311. fst->key = hash_key;
  312. fst->max_skid_length = max_search;
  313. fst->max_entries = max_entries;
  314. fst->hash_mask = max_entries - 1;
  315. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_DEBUG,
  316. "HAL FST allocation %pK %d * %d\n", fst,
  317. fst->max_entries, HAL_RX_FST_ENTRY_SIZE);
  318. fst->base_vaddr = (uint8_t *)qdf_mem_alloc_consistent(qdf_dev,
  319. qdf_dev->dev,
  320. (fst->max_entries * HAL_RX_FST_ENTRY_SIZE),
  321. &fst->base_paddr);
  322. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO,
  323. "hal_rx_fst base address 0x%pK", (void *)fst->base_paddr);
  324. if (!fst->base_vaddr) {
  325. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  326. FL("hal fst->base_vaddr allocation failed"));
  327. qdf_mem_free(fst);
  328. return NULL;
  329. }
  330. QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_ANY, QDF_TRACE_LEVEL_DEBUG,
  331. (void *)fst->key, HAL_FST_HASH_KEY_SIZE_BYTES);
  332. qdf_mem_set((uint8_t *)fst->base_vaddr, 0,
  333. (fst->max_entries * HAL_RX_FST_ENTRY_SIZE));
  334. hal_rx_fst_key_configure(fst);
  335. hal_flow_toeplitz_create_cache(fst);
  336. *hal_fst_base_paddr = (uint64_t)fst->base_paddr;
  337. return fst;
  338. }
  339. qdf_export_symbol(hal_rx_fst_attach);
  340. /**
  341. * hal_rx_fst_detach() - De-init the Rx flow search table from HW
  342. *
  343. * @rx_fst: Pointer to the Rx FST
  344. * @qdf_dev: QDF device handle
  345. *
  346. * Return:
  347. */
  348. void hal_rx_fst_detach(struct hal_rx_fst *rx_fst,
  349. qdf_device_t qdf_dev)
  350. {
  351. if (!rx_fst || !qdf_dev)
  352. return;
  353. qdf_mem_free_consistent(qdf_dev, qdf_dev->dev,
  354. rx_fst->max_entries * HAL_RX_FST_ENTRY_SIZE,
  355. rx_fst->base_vaddr, rx_fst->base_paddr, 0);
  356. qdf_mem_free(rx_fst);
  357. }
  358. qdf_export_symbol(hal_rx_fst_detach);
  359. #ifndef WLAN_SUPPORT_RX_FISA
  360. /**
  361. * hal_flow_toeplitz_hash() - Calculate Toeplitz hash by using the cached key
  362. *
  363. * @hal_fst: FST Handle
  364. * @flow: Flow Parameters
  365. *
  366. * Return: Success/Failure
  367. */
  368. uint32_t
  369. hal_flow_toeplitz_hash(void *hal_fst, struct hal_rx_flow *flow)
  370. {
  371. int i, j;
  372. uint32_t hash = 0;
  373. struct hal_rx_fst *fst = (struct hal_rx_fst *)hal_fst;
  374. uint32_t input[HAL_FST_HASH_KEY_SIZE_WORDS];
  375. uint8_t *tuple;
  376. qdf_mem_zero(input, HAL_FST_HASH_KEY_SIZE_BYTES);
  377. *(uint32_t *)&input[0] = qdf_htonl(flow->tuple_info.src_ip_127_96);
  378. *(uint32_t *)&input[1] = qdf_htonl(flow->tuple_info.src_ip_95_64);
  379. *(uint32_t *)&input[2] = qdf_htonl(flow->tuple_info.src_ip_63_32);
  380. *(uint32_t *)&input[3] = qdf_htonl(flow->tuple_info.src_ip_31_0);
  381. *(uint32_t *)&input[4] = qdf_htonl(flow->tuple_info.dest_ip_127_96);
  382. *(uint32_t *)&input[5] = qdf_htonl(flow->tuple_info.dest_ip_95_64);
  383. *(uint32_t *)&input[6] = qdf_htonl(flow->tuple_info.dest_ip_63_32);
  384. *(uint32_t *)&input[7] = qdf_htonl(flow->tuple_info.dest_ip_31_0);
  385. *(uint32_t *)&input[8] = (flow->tuple_info.dest_port << 16) |
  386. (flow->tuple_info.src_port);
  387. *(uint32_t *)&input[9] = flow->tuple_info.l4_protocol;
  388. tuple = (uint8_t *)input;
  389. QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  390. tuple, sizeof(input));
  391. for (i = 0, j = HAL_FST_HASH_DATA_SIZE - 1;
  392. i < HAL_FST_HASH_KEY_SIZE_BYTES && j >= 0; i++, j--) {
  393. hash ^= fst->key_cache[i][tuple[j]];
  394. }
  395. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_LOW,
  396. "Hash value %u %u truncated hash %u\n", hash,
  397. (hash >> 12), (hash >> 12) % (fst->max_entries));
  398. hash >>= 12;
  399. hash &= (fst->max_entries - 1);
  400. return hash;
  401. }
  402. #else
  403. uint32_t
  404. hal_flow_toeplitz_hash(void *hal_fst, struct hal_rx_flow *flow)
  405. {
  406. return 0;
  407. }
  408. #endif
  409. qdf_export_symbol(hal_flow_toeplitz_hash);
  410. /**
  411. * hal_rx_get_hal_hash() - Retrieve hash index of a flow in the FST table
  412. *
  413. * @hal_fst: HAL Rx FST Handle
  414. * @flow_hash: Flow hash computed from flow tuple
  415. *
  416. * Return: hash index truncated to the size of the hash table
  417. */
  418. uint32_t hal_rx_get_hal_hash(struct hal_rx_fst *hal_fst, uint32_t flow_hash)
  419. {
  420. uint32_t trunc_hash = flow_hash;
  421. /* Take care of hash wrap around scenario */
  422. if (flow_hash >= hal_fst->max_entries)
  423. trunc_hash &= hal_fst->hash_mask;
  424. return trunc_hash;
  425. }
  426. qdf_export_symbol(hal_rx_get_hal_hash);
  427. /**
  428. * hal_rx_insert_flow_entry() - Add a flow into the FST table
  429. *
  430. * @hal_fst: HAL Rx FST Handle
  431. * @flow_hash: Flow hash computed from flow tuple
  432. * @flow_tuple_info: Flow tuple used to compute the hash
  433. * @flow_index: Hash index of the flow in the table when inserted successfully
  434. *
  435. * Return: Success if flow is inserted into the table, error otherwise
  436. */
  437. QDF_STATUS
  438. hal_rx_insert_flow_entry(struct hal_rx_fst *fst, uint32_t flow_hash,
  439. void *flow_tuple_info, uint32_t *flow_idx)
  440. {
  441. int i;
  442. void *hal_fse = NULL;
  443. uint32_t hal_hash = 0;
  444. struct hal_flow_tuple_info hal_tuple_info = { 0 };
  445. QDF_STATUS status;
  446. for (i = 0; i < fst->max_skid_length; i++) {
  447. hal_hash = hal_rx_get_hal_hash(fst, (flow_hash + i));
  448. hal_fse = (uint8_t *)fst->base_vaddr +
  449. (hal_hash * HAL_RX_FST_ENTRY_SIZE);
  450. status = hal_rx_flow_get_tuple_info(hal_fse, &hal_tuple_info);
  451. if (status == QDF_STATUS_E_NOENT)
  452. break;
  453. /* Find the matching flow entry in HW FST */
  454. if (!qdf_mem_cmp(&hal_tuple_info,
  455. flow_tuple_info,
  456. sizeof(struct hal_flow_tuple_info))) {
  457. dp_err("Duplicate flow entry in FST %u at skid %u ",
  458. hal_hash, i);
  459. return QDF_STATUS_E_EXISTS;
  460. }
  461. }
  462. if (i == fst->max_skid_length) {
  463. dp_err("Max skid length reached for hash %u", flow_hash);
  464. return QDF_STATUS_E_RANGE;
  465. }
  466. *flow_idx = hal_hash;
  467. dp_info("flow_hash = %u, skid_entry = %d, flow_addr = %pK flow_idx = %d",
  468. flow_hash, i, hal_fse, *flow_idx);
  469. return QDF_STATUS_SUCCESS;
  470. }
  471. qdf_export_symbol(hal_rx_insert_flow_entry);
  472. /**
  473. * hal_rx_find_flow_from_tuple() - Find a flow in the FST table
  474. *
  475. * @fst: HAL Rx FST Handle
  476. * @flow_hash: Flow hash computed from flow tuple
  477. * @flow_tuple_info: Flow tuple used to compute the hash
  478. * @flow_index: Hash index of the flow in the table when found
  479. *
  480. * Return: Success if matching flow is found in the table, error otherwise
  481. */
  482. QDF_STATUS
  483. hal_rx_find_flow_from_tuple(struct hal_rx_fst *fst, uint32_t flow_hash,
  484. void *flow_tuple_info, uint32_t *flow_idx)
  485. {
  486. int i;
  487. void *hal_fse = NULL;
  488. uint32_t hal_hash = 0;
  489. struct hal_flow_tuple_info hal_tuple_info = { 0 };
  490. QDF_STATUS status;
  491. for (i = 0; i < fst->max_skid_length; i++) {
  492. hal_hash = hal_rx_get_hal_hash(fst, (flow_hash + i));
  493. hal_fse = (uint8_t *)fst->base_vaddr +
  494. (hal_hash * HAL_RX_FST_ENTRY_SIZE);
  495. status = hal_rx_flow_get_tuple_info(hal_fse, &hal_tuple_info);
  496. if (status != QDF_STATUS_SUCCESS)
  497. continue;
  498. /* Find the matching flow entry in HW FST */
  499. if (!qdf_mem_cmp(&hal_tuple_info,
  500. flow_tuple_info,
  501. sizeof(struct hal_flow_tuple_info))) {
  502. break;
  503. }
  504. }
  505. if (i == fst->max_skid_length) {
  506. dp_err("Max skid length reached for hash %u", flow_hash);
  507. return QDF_STATUS_E_RANGE;
  508. }
  509. *flow_idx = hal_hash;
  510. dp_info("flow_hash = %u, skid_entry = %d, flow_addr = %pK flow_idx = %d",
  511. flow_hash, i, hal_fse, *flow_idx);
  512. return QDF_STATUS_SUCCESS;
  513. }
  514. qdf_export_symbol(hal_rx_find_flow_from_tuple);