ipa_nat_drv.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /*
  2. * Copyright (c) 2013-2021 The Linux Foundation. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are
  6. * met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above
  10. * copyright notice, this list of conditions and the following
  11. * disclaimer in the documentation and/or other materials provided
  12. * with the distribution.
  13. * * Neither the name of The Linux Foundation nor the names of its
  14. * contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
  18. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
  21. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  22. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  23. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  24. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  25. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  26. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  27. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #ifndef IPA_NAT_DRV_H
  30. #define IPA_NAT_DRV_H
  31. #include "ipa_nat_utils.h"
  32. #include <stdint.h> /* uint32_t */
  33. #include <stdbool.h>
  34. /**
  35. * ipa_nat_is_sram_supported() - Reports if sram is available for use
  36. */
  37. bool ipa_nat_is_sram_supported(void);
  38. /**
  39. * struct ipa_nat_ipv4_rule - To hold ipv4 nat rule
  40. * @target_ip: destination ip address
  41. * @private_ip: private ip address
  42. * @target_port: destination port
  43. * @private_port: private port
  44. * @protocol: protocol of rule (tcp/udp)
  45. * @pdn_index: PDN index in the PDN config table
  46. * @redirect: used internally by various API calls
  47. * @enable: used internally by various API calls
  48. * @time_stamp: used internally by various API calls
  49. * @uc_activation_index: index pointing to uc activation table
  50. * @s: bit indication to use the system or local (1 or 0) addr for above table
  51. * @ucp: enable uc processing
  52. * @dst_only: construct NAT for DL only
  53. * @src_only: construct NAT for UL only
  54. */
  55. typedef struct {
  56. uint32_t target_ip;
  57. uint32_t private_ip;
  58. uint16_t target_port;
  59. uint16_t private_port;
  60. uint16_t public_port;
  61. uint8_t protocol;
  62. uint8_t pdn_index;
  63. uint8_t redirect;
  64. uint8_t enable;
  65. uint32_t time_stamp;
  66. uint16_t uc_activation_index;
  67. bool s;
  68. bool ucp;
  69. bool dst_only;
  70. bool src_only;
  71. } ipa_nat_ipv4_rule;
  72. static inline char* prep_nat_ipv4_rule_4print(
  73. ipa_nat_ipv4_rule* rule_ptr,
  74. char* buf_ptr,
  75. uint32_t buf_sz )
  76. {
  77. if ( rule_ptr && buf_ptr && buf_sz )
  78. {
  79. snprintf(
  80. buf_ptr, buf_sz,
  81. "IPV4 RULE: "
  82. "protocol(0x%02X) "
  83. "public_port(0x%04X) "
  84. "target_ip(0x%08X) "
  85. "target_port(0x%04X) "
  86. "private_ip(0x%08X) "
  87. "private_port(0x%04X) "
  88. "pdn_index(0x%02X)",
  89. rule_ptr->protocol,
  90. rule_ptr->public_port,
  91. rule_ptr->target_ip,
  92. rule_ptr->target_port,
  93. rule_ptr->private_ip,
  94. rule_ptr->private_port,
  95. rule_ptr->pdn_index);
  96. }
  97. return buf_ptr;
  98. }
  99. /**
  100. * struct ipa_nat_pdn_entry - holds a PDN entry data
  101. * @public_ip: PDN's public ip address
  102. * @src_metadata: metadata to be used for source NAT metadata replacement
  103. * @dst_metadata: metadata to be used for destination NAT metadata replacement
  104. */
  105. typedef struct {
  106. uint32_t public_ip;
  107. uint32_t src_metadata;
  108. uint32_t dst_metadata;
  109. } ipa_nat_pdn_entry;
  110. /**
  111. * ipa_nat_add_ipv4_tbl() - create ipv4 nat table
  112. * @public_ip_addr: [in] public ipv4 address
  113. * @mem_type_ptr: [in] type of memory table is to reside in
  114. * @number_of_entries: [in] number of nat entries
  115. * @table_handle: [out] Handle of new ipv4 nat table
  116. *
  117. * To create new ipv4 nat table
  118. *
  119. * Returns: 0 On Success, negative on failure
  120. */
  121. int ipa_nat_add_ipv4_tbl(
  122. uint32_t public_ip_addr,
  123. const char *mem_type_ptr,
  124. uint16_t number_of_entries,
  125. uint32_t *table_handle);
  126. /**
  127. * ipa_nat_del_ipv4_tbl() - delete ipv4 table
  128. * @table_handle: [in] Handle of ipv4 nat table
  129. *
  130. * To delete given ipv4 nat table
  131. *
  132. * Returns: 0 On Success, negative on failure
  133. */
  134. int ipa_nat_del_ipv4_tbl(uint32_t table_handle);
  135. /**
  136. * ipa_nat_add_ipv4_rule() - to insert new ipv4 rule
  137. * @table_handle: [in] handle of ipv4 nat table
  138. * @rule: [in] Pointer to new rule
  139. * @rule_handle: [out] Return the handle to rule
  140. *
  141. * To insert new ipv4 nat rule into ipv4 nat table
  142. *
  143. * Returns: 0 On Success, negative on failure
  144. */
  145. int ipa_nat_add_ipv4_rule(uint32_t table_handle,
  146. const ipa_nat_ipv4_rule * rule,
  147. uint32_t *rule_handle);
  148. /**
  149. * ipa_nat_del_ipv4_rule() - to delete ipv4 nat rule
  150. * @table_handle: [in] handle of ipv4 nat table
  151. * @rule_handle: [in] ipv4 nat rule handle
  152. *
  153. * To insert new ipv4 nat rule into ipv4 nat table
  154. *
  155. * Returns: 0 On Success, negative on failure
  156. */
  157. int ipa_nat_del_ipv4_rule(uint32_t table_handle,
  158. uint32_t rule_handle);
  159. /**
  160. * ipa_nat_query_timestamp() - to query timestamp
  161. * @table_handle: [in] handle of ipv4 nat table
  162. * @rule_handle: [in] ipv4 nat rule handle
  163. * @time_stamp: [out] time stamp of rule
  164. *
  165. * To retrieve the timestamp that lastly the
  166. * nat rule was accessed
  167. *
  168. * Returns: 0 On Success, negative on failure
  169. */
  170. int ipa_nat_query_timestamp(uint32_t table_handle,
  171. uint32_t rule_handle,
  172. uint32_t *time_stamp);
  173. /**
  174. * ipa_nat_modify_pdn() - modify single PDN entry in the PDN config table
  175. * @table_handle: [in] handle of ipv4 nat table
  176. * @pdn_index : [in] the index of the entry to be modified
  177. * @pdn_info : [in] values for the PDN entry to be changed
  178. *
  179. * Modify a PDN entry
  180. *
  181. * Returns: 0 On Success, negative on failure
  182. */
  183. int ipa_nat_modify_pdn(uint32_t tbl_hdl,
  184. uint8_t pdn_index,
  185. ipa_nat_pdn_entry *pdn_info);
  186. /**
  187. * ipa_nat_get_pdn_index() - get a PDN index for a public ip
  188. * @public_ip : [in] IPv4 address of the PDN entry
  189. * @pdn_index : [out] the index of the requested PDN entry
  190. *
  191. * Get a PDN entry
  192. *
  193. * Returns: 0 On Success, negative on failure
  194. */
  195. int ipa_nat_get_pdn_index(uint32_t public_ip, uint8_t *pdn_index);
  196. /**
  197. * ipa_nat_alloc_pdn() - allocate a PDN for new WAN
  198. * @pdn_info : [in] values for the PDN entry to be created
  199. * @pdn_index : [out] the index of the requested PDN entry
  200. *
  201. * allocate a new PDN entry
  202. *
  203. * Returns: 0 On Success, negative on failure
  204. */
  205. int ipa_nat_alloc_pdn(ipa_nat_pdn_entry *pdn_info,
  206. uint8_t *pdn_index);
  207. /**
  208. * ipa_nat_get_pdn_count() - get the number of allocated PDNs
  209. * @pdn_cnt : [out] the number of allocated PDNs
  210. *
  211. * get the number of allocated PDNs
  212. *
  213. * Returns: 0 On Success, negative on failure
  214. */
  215. int ipa_nat_get_pdn_count(uint8_t *pdn_cnt);
  216. /**
  217. * ipa_nat_dealloc_pdn() - deallocate a PDN entry
  218. * @pdn_index : [in] pdn index to be deallocated
  219. *
  220. * deallocate a PDN in specified index - zero the PDN entry
  221. *
  222. * Returns: 0 On Success, negative on failure
  223. */
  224. int ipa_nat_dealloc_pdn(uint8_t pdn_index);
  225. /**
  226. * ipa_nat_dump_ipv4_table() - dumps IPv4 NAT table
  227. * @table_handle: [in] handle of IPv4 NAT table
  228. */
  229. void ipa_nat_dump_ipv4_table(uint32_t tbl_hdl);
  230. /**
  231. * ipa_nat_vote_clock() - used for voting clock
  232. * @vote_type: [in] desired vote type
  233. */
  234. int ipa_nat_vote_clock(
  235. enum ipa_app_clock_vote_type vote_type );
  236. /**
  237. * ipa_nat_switch_to() - While in HYBRID mode only, used for switching
  238. * from SRAM to DDR or the reverse.
  239. * @nmi: memory type to switch to
  240. * @hold_state: Will the new memory type get locked in (ie. no more
  241. * oscilation between the memory types)
  242. */
  243. int ipa_nat_switch_to(
  244. enum ipa3_nat_mem_in nmi,
  245. bool hold_state );
  246. #endif