hal_rx_flow.c 23 KB

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