hal_rx_flow.c 18 KB

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