hal_rx_flow.c 18 KB

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