hal_rx_flow.c 23 KB

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