ipa_cmd.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
  3. * Copyright (C) 2019-2024 Linaro Ltd.
  4. */
  5. #ifndef _IPA_CMD_H_
  6. #define _IPA_CMD_H_
  7. #include <linux/types.h>
  8. struct gsi_channel;
  9. struct gsi_trans;
  10. struct ipa;
  11. struct ipa_mem;
  12. /**
  13. * enum ipa_cmd_opcode: IPA immediate commands
  14. *
  15. * @IPA_CMD_IP_V4_FILTER_INIT: Initialize IPv4 filter table
  16. * @IPA_CMD_IP_V6_FILTER_INIT: Initialize IPv6 filter table
  17. * @IPA_CMD_IP_V4_ROUTING_INIT: Initialize IPv4 routing table
  18. * @IPA_CMD_IP_V6_ROUTING_INIT: Initialize IPv6 routing table
  19. * @IPA_CMD_HDR_INIT_LOCAL: Initialize IPA-local header memory
  20. * @IPA_CMD_REGISTER_WRITE: Register write performed by IPA
  21. * @IPA_CMD_IP_PACKET_INIT: Set up next packet's destination endpoint
  22. * @IPA_CMD_DMA_SHARED_MEM: DMA command performed by IPA
  23. * @IPA_CMD_IP_PACKET_TAG_STATUS: Have next packet generate tag * status
  24. * @IPA_CMD_NONE: Special (invalid) "not a command" value
  25. *
  26. * All immediate commands are issued using the AP command TX endpoint.
  27. */
  28. enum ipa_cmd_opcode {
  29. IPA_CMD_NONE = 0x0,
  30. IPA_CMD_IP_V4_FILTER_INIT = 0x3,
  31. IPA_CMD_IP_V6_FILTER_INIT = 0x4,
  32. IPA_CMD_IP_V4_ROUTING_INIT = 0x7,
  33. IPA_CMD_IP_V6_ROUTING_INIT = 0x8,
  34. IPA_CMD_HDR_INIT_LOCAL = 0x9,
  35. IPA_CMD_REGISTER_WRITE = 0xc,
  36. IPA_CMD_IP_PACKET_INIT = 0x10,
  37. IPA_CMD_DMA_SHARED_MEM = 0x13,
  38. IPA_CMD_IP_PACKET_TAG_STATUS = 0x14,
  39. };
  40. /**
  41. * ipa_cmd_table_init_valid() - Validate a memory region holding a table
  42. * @ipa: - IPA pointer
  43. * @mem: - IPA memory region descriptor
  44. * @route: - Whether the region holds a route or filter table
  45. *
  46. * Return: true if region is valid, false otherwise
  47. */
  48. bool ipa_cmd_table_init_valid(struct ipa *ipa, const struct ipa_mem *mem,
  49. bool route);
  50. /**
  51. * ipa_cmd_pool_init() - initialize command channel pools
  52. * @channel: AP->IPA command TX GSI channel pointer
  53. * @tre_count: Number of pool elements to allocate
  54. *
  55. * Return: 0 if successful, or a negative error code
  56. */
  57. int ipa_cmd_pool_init(struct gsi_channel *channel, u32 tre_count);
  58. /**
  59. * ipa_cmd_pool_exit() - Inverse of ipa_cmd_pool_init()
  60. * @channel: AP->IPA command TX GSI channel pointer
  61. */
  62. void ipa_cmd_pool_exit(struct gsi_channel *channel);
  63. /**
  64. * ipa_cmd_table_init_add() - Add table init command to a transaction
  65. * @trans: GSI transaction
  66. * @opcode: IPA immediate command opcode
  67. * @size: Size of non-hashed routing table memory
  68. * @offset: Offset in IPA shared memory of non-hashed routing table memory
  69. * @addr: DMA address of non-hashed table data to write
  70. * @hash_size: Size of hashed routing table memory
  71. * @hash_offset: Offset in IPA shared memory of hashed routing table memory
  72. * @hash_addr: DMA address of hashed table data to write
  73. *
  74. * If hash_size is 0, hash_offset and hash_addr are ignored.
  75. */
  76. void ipa_cmd_table_init_add(struct gsi_trans *trans, enum ipa_cmd_opcode opcode,
  77. u16 size, u32 offset, dma_addr_t addr,
  78. u16 hash_size, u32 hash_offset,
  79. dma_addr_t hash_addr);
  80. /**
  81. * ipa_cmd_hdr_init_local_add() - Add a header init command to a transaction
  82. * @trans: GSI transaction
  83. * @offset: Offset of header memory in IPA local space
  84. * @size: Size of header memory
  85. * @addr: DMA address of buffer to be written from
  86. *
  87. * Defines and fills the location in IPA memory to use for headers.
  88. */
  89. void ipa_cmd_hdr_init_local_add(struct gsi_trans *trans, u32 offset, u16 size,
  90. dma_addr_t addr);
  91. /**
  92. * ipa_cmd_register_write_add() - Add a register write command to a transaction
  93. * @trans: GSI transaction
  94. * @offset: Offset of register to be written
  95. * @value: Value to be written
  96. * @mask: Mask of bits in register to update with bits from value
  97. * @clear_full: Pipeline clear option; true means full pipeline clear
  98. */
  99. void ipa_cmd_register_write_add(struct gsi_trans *trans, u32 offset, u32 value,
  100. u32 mask, bool clear_full);
  101. /**
  102. * ipa_cmd_dma_shared_mem_add() - Add a DMA memory command to a transaction
  103. * @trans: GSI transaction
  104. * @offset: Offset of IPA memory to be read or written
  105. * @size: Number of bytes of memory to be transferred
  106. * @addr: DMA address of buffer to be read into or written from
  107. * @toward_ipa: true means write to IPA memory; false means read
  108. */
  109. void ipa_cmd_dma_shared_mem_add(struct gsi_trans *trans, u32 offset,
  110. u16 size, dma_addr_t addr, bool toward_ipa);
  111. /**
  112. * ipa_cmd_pipeline_clear_add() - Add pipeline clear commands to a transaction
  113. * @trans: GSI transaction
  114. */
  115. void ipa_cmd_pipeline_clear_add(struct gsi_trans *trans);
  116. /**
  117. * ipa_cmd_pipeline_clear_count() - # commands required to clear pipeline
  118. *
  119. * Return: The number of elements to allocate in a transaction
  120. * to hold commands to clear the pipeline
  121. */
  122. u32 ipa_cmd_pipeline_clear_count(void);
  123. /**
  124. * ipa_cmd_pipeline_clear_wait() - Wait pipeline clear to complete
  125. * @ipa: - IPA pointer
  126. */
  127. void ipa_cmd_pipeline_clear_wait(struct ipa *ipa);
  128. /**
  129. * ipa_cmd_trans_alloc() - Allocate a transaction for the command TX endpoint
  130. * @ipa: IPA pointer
  131. * @tre_count: Number of elements in the transaction
  132. *
  133. * Return: A GSI transaction structure, or a null pointer if all
  134. * available transactions are in use
  135. */
  136. struct gsi_trans *ipa_cmd_trans_alloc(struct ipa *ipa, u32 tre_count);
  137. /**
  138. * ipa_cmd_init() - Initialize IPA immediate commands
  139. * @ipa: - IPA pointer
  140. *
  141. * Return: 0 if successful, or a negative error code
  142. *
  143. * There is no need for a matching ipa_cmd_exit() function.
  144. */
  145. int ipa_cmd_init(struct ipa *ipa);
  146. #endif /* _IPA_CMD_H_ */