hal_rx_flow.c 17 KB

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