^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) /* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2019-2020 Linaro Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #ifndef _IPA_CMD_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #define _IPA_CMD_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/dma-direction.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) struct sk_buff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) struct scatterlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) struct ipa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) struct ipa_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) struct gsi_trans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) struct gsi_channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * enum ipa_cmd_opcode: IPA immediate commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * All immediate commands are issued using the AP command TX endpoint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * The numeric values here are the opcodes for IPA v3.5.1 hardware.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * IPA_CMD_NONE is a special (invalid) value that's used to indicate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * a request is *not* an immediate command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) enum ipa_cmd_opcode {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) IPA_CMD_NONE = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) IPA_CMD_IP_V4_FILTER_INIT = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) IPA_CMD_IP_V6_FILTER_INIT = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) IPA_CMD_IP_V4_ROUTING_INIT = 7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) IPA_CMD_IP_V6_ROUTING_INIT = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) IPA_CMD_HDR_INIT_LOCAL = 9,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) IPA_CMD_REGISTER_WRITE = 12,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) IPA_CMD_IP_PACKET_INIT = 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) IPA_CMD_DMA_SHARED_MEM = 19,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) IPA_CMD_IP_PACKET_TAG_STATUS = 20,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * struct ipa_cmd_info - information needed for an IPA immediate command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * @opcode: The command opcode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * @direction: Direction of data transfer for DMA commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct ipa_cmd_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) enum ipa_cmd_opcode opcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) enum dma_data_direction direction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #ifdef IPA_VALIDATE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * ipa_cmd_table_valid() - Validate a memory region holding a table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * @ipa: - IPA pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * @mem: - IPA memory region descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * @route: - Whether the region holds a route or filter table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * @ipv6: - Whether the table is for IPv6 or IPv4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * @hashed: - Whether the table is hashed or non-hashed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * Return: true if region is valid, false otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) bool ipa_cmd_table_valid(struct ipa *ipa, const struct ipa_mem *mem,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) bool route, bool ipv6, bool hashed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * ipa_cmd_data_valid() - Validate command-realted configuration is valid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * @ipa: - IPA pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * Return: true if assumptions required for command are valid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) bool ipa_cmd_data_valid(struct ipa *ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) #else /* !IPA_VALIDATE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) static inline bool ipa_cmd_table_valid(struct ipa *ipa,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) const struct ipa_mem *mem, bool route,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) bool ipv6, bool hashed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) static inline bool ipa_cmd_data_valid(struct ipa *ipa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) #endif /* !IPA_VALIDATE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * ipa_cmd_pool_init() - initialize command channel pools
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * @channel: AP->IPA command TX GSI channel pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * @tre_count: Number of pool elements to allocate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * Return: 0 if successful, or a negative error code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) int ipa_cmd_pool_init(struct gsi_channel *gsi_channel, u32 tre_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * ipa_cmd_pool_exit() - Inverse of ipa_cmd_pool_init()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * @channel: AP->IPA command TX GSI channel pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) void ipa_cmd_pool_exit(struct gsi_channel *channel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * ipa_cmd_table_init_add() - Add table init command to a transaction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * @trans: GSI transaction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * @opcode: IPA immediate command opcode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * @size: Size of non-hashed routing table memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * @offset: Offset in IPA shared memory of non-hashed routing table memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * @addr: DMA address of non-hashed table data to write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * @hash_size: Size of hashed routing table memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * @hash_offset: Offset in IPA shared memory of hashed routing table memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * @hash_addr: DMA address of hashed table data to write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * If hash_size is 0, hash_offset and hash_addr are ignored.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) void ipa_cmd_table_init_add(struct gsi_trans *trans, enum ipa_cmd_opcode opcode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) u16 size, u32 offset, dma_addr_t addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) u16 hash_size, u32 hash_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) dma_addr_t hash_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) * ipa_cmd_hdr_init_local_add() - Add a header init command to a transaction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * @ipa: IPA structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * @offset: Offset of header memory in IPA local space
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * @size: Size of header memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * @addr: DMA address of buffer to be written from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * Defines and fills the location in IPA memory to use for headers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) void ipa_cmd_hdr_init_local_add(struct gsi_trans *trans, u32 offset, u16 size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) dma_addr_t addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) * ipa_cmd_register_write_add() - Add a register write command to a transaction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) * @trans: GSI transaction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) * @offset: Offset of register to be written
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) * @value: Value to be written
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) * @mask: Mask of bits in register to update with bits from value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) * @clear_full: Pipeline clear option; true means full pipeline clear
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) void ipa_cmd_register_write_add(struct gsi_trans *trans, u32 offset, u32 value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) u32 mask, bool clear_full);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) * ipa_cmd_dma_shared_mem_add() - Add a DMA memory command to a transaction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * @trans: GSI transaction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) * @offset: Offset of IPA memory to be read or written
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) * @size: Number of bytes of memory to be transferred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) * @addr: DMA address of buffer to be read into or written from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) * @toward_ipa: true means write to IPA memory; false means read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) void ipa_cmd_dma_shared_mem_add(struct gsi_trans *trans, u32 offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) u16 size, dma_addr_t addr, bool toward_ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) * ipa_cmd_tag_process_add() - Add IPA tag process commands to a transaction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) * @trans: GSI transaction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) void ipa_cmd_tag_process_add(struct gsi_trans *trans);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) * ipa_cmd_tag_process_add_count() - Number of commands in a tag process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) * Return: The number of elements to allocate in a transaction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * to hold tag process commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) u32 ipa_cmd_tag_process_count(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * ipa_cmd_tag_process() - Perform a tag process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * @Return: The number of elements to allocate in a transaction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) * to hold tag process commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) void ipa_cmd_tag_process(struct ipa *ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) * ipa_cmd_trans_alloc() - Allocate a transaction for the command TX endpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) * @ipa: IPA pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) * @tre_count: Number of elements in the transaction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) * Return: A GSI transaction structure, or a null pointer if all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * available transactions are in use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) struct gsi_trans *ipa_cmd_trans_alloc(struct ipa *ipa, u32 tre_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) #endif /* _IPA_CMD_H_ */