162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci
362306a36Sopenharmony_ci/* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
462306a36Sopenharmony_ci * Copyright (C) 2019-2022 Linaro Ltd.
562306a36Sopenharmony_ci */
662306a36Sopenharmony_ci#ifndef _IPA_CMD_H_
762306a36Sopenharmony_ci#define _IPA_CMD_H_
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#include <linux/types.h>
1062306a36Sopenharmony_ci#include <linux/dma-direction.h>
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_cistruct sk_buff;
1362306a36Sopenharmony_cistruct scatterlist;
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_cistruct ipa;
1662306a36Sopenharmony_cistruct ipa_mem;
1762306a36Sopenharmony_cistruct gsi_trans;
1862306a36Sopenharmony_cistruct gsi_channel;
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci/**
2162306a36Sopenharmony_ci * enum ipa_cmd_opcode:	IPA immediate commands
2262306a36Sopenharmony_ci *
2362306a36Sopenharmony_ci * @IPA_CMD_IP_V4_FILTER_INIT:	Initialize IPv4 filter table
2462306a36Sopenharmony_ci * @IPA_CMD_IP_V6_FILTER_INIT:	Initialize IPv6 filter table
2562306a36Sopenharmony_ci * @IPA_CMD_IP_V4_ROUTING_INIT:	Initialize IPv4 routing table
2662306a36Sopenharmony_ci * @IPA_CMD_IP_V6_ROUTING_INIT:	Initialize IPv6 routing table
2762306a36Sopenharmony_ci * @IPA_CMD_HDR_INIT_LOCAL:	Initialize IPA-local header memory
2862306a36Sopenharmony_ci * @IPA_CMD_REGISTER_WRITE:	Register write performed by IPA
2962306a36Sopenharmony_ci * @IPA_CMD_IP_PACKET_INIT:	Set up next packet's destination endpoint
3062306a36Sopenharmony_ci * @IPA_CMD_DMA_SHARED_MEM:	DMA command performed by IPA
3162306a36Sopenharmony_ci * @IPA_CMD_IP_PACKET_TAG_STATUS: Have next packet generate tag * status
3262306a36Sopenharmony_ci * @IPA_CMD_NONE:		Special (invalid) "not a command" value
3362306a36Sopenharmony_ci *
3462306a36Sopenharmony_ci * All immediate commands are issued using the AP command TX endpoint.
3562306a36Sopenharmony_ci */
3662306a36Sopenharmony_cienum ipa_cmd_opcode {
3762306a36Sopenharmony_ci	IPA_CMD_NONE			= 0x0,
3862306a36Sopenharmony_ci	IPA_CMD_IP_V4_FILTER_INIT	= 0x3,
3962306a36Sopenharmony_ci	IPA_CMD_IP_V6_FILTER_INIT	= 0x4,
4062306a36Sopenharmony_ci	IPA_CMD_IP_V4_ROUTING_INIT	= 0x7,
4162306a36Sopenharmony_ci	IPA_CMD_IP_V6_ROUTING_INIT	= 0x8,
4262306a36Sopenharmony_ci	IPA_CMD_HDR_INIT_LOCAL		= 0x9,
4362306a36Sopenharmony_ci	IPA_CMD_REGISTER_WRITE		= 0xc,
4462306a36Sopenharmony_ci	IPA_CMD_IP_PACKET_INIT		= 0x10,
4562306a36Sopenharmony_ci	IPA_CMD_DMA_SHARED_MEM		= 0x13,
4662306a36Sopenharmony_ci	IPA_CMD_IP_PACKET_TAG_STATUS	= 0x14,
4762306a36Sopenharmony_ci};
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci/**
5062306a36Sopenharmony_ci * ipa_cmd_table_init_valid() - Validate a memory region holding a table
5162306a36Sopenharmony_ci * @ipa:	- IPA pointer
5262306a36Sopenharmony_ci * @mem:	- IPA memory region descriptor
5362306a36Sopenharmony_ci * @route:	- Whether the region holds a route or filter table
5462306a36Sopenharmony_ci *
5562306a36Sopenharmony_ci * Return:	true if region is valid, false otherwise
5662306a36Sopenharmony_ci */
5762306a36Sopenharmony_cibool ipa_cmd_table_init_valid(struct ipa *ipa, const struct ipa_mem *mem,
5862306a36Sopenharmony_ci			      bool route);
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci/**
6162306a36Sopenharmony_ci * ipa_cmd_data_valid() - Validate command-realted configuration is valid
6262306a36Sopenharmony_ci * @ipa:	- IPA pointer
6362306a36Sopenharmony_ci *
6462306a36Sopenharmony_ci * Return:	true if assumptions required for command are valid
6562306a36Sopenharmony_ci */
6662306a36Sopenharmony_cibool ipa_cmd_data_valid(struct ipa *ipa);
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci/**
6962306a36Sopenharmony_ci * ipa_cmd_pool_init() - initialize command channel pools
7062306a36Sopenharmony_ci * @channel:	AP->IPA command TX GSI channel pointer
7162306a36Sopenharmony_ci * @tre_count:	Number of pool elements to allocate
7262306a36Sopenharmony_ci *
7362306a36Sopenharmony_ci * Return:	0 if successful, or a negative error code
7462306a36Sopenharmony_ci */
7562306a36Sopenharmony_ciint ipa_cmd_pool_init(struct gsi_channel *channel, u32 tre_count);
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_ci/**
7862306a36Sopenharmony_ci * ipa_cmd_pool_exit() - Inverse of ipa_cmd_pool_init()
7962306a36Sopenharmony_ci * @channel:	AP->IPA command TX GSI channel pointer
8062306a36Sopenharmony_ci */
8162306a36Sopenharmony_civoid ipa_cmd_pool_exit(struct gsi_channel *channel);
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ci/**
8462306a36Sopenharmony_ci * ipa_cmd_table_init_add() - Add table init command to a transaction
8562306a36Sopenharmony_ci * @trans:	GSI transaction
8662306a36Sopenharmony_ci * @opcode:	IPA immediate command opcode
8762306a36Sopenharmony_ci * @size:	Size of non-hashed routing table memory
8862306a36Sopenharmony_ci * @offset:	Offset in IPA shared memory of non-hashed routing table memory
8962306a36Sopenharmony_ci * @addr:	DMA address of non-hashed table data to write
9062306a36Sopenharmony_ci * @hash_size:	Size of hashed routing table memory
9162306a36Sopenharmony_ci * @hash_offset: Offset in IPA shared memory of hashed routing table memory
9262306a36Sopenharmony_ci * @hash_addr:	DMA address of hashed table data to write
9362306a36Sopenharmony_ci *
9462306a36Sopenharmony_ci * If hash_size is 0, hash_offset and hash_addr are ignored.
9562306a36Sopenharmony_ci */
9662306a36Sopenharmony_civoid ipa_cmd_table_init_add(struct gsi_trans *trans, enum ipa_cmd_opcode opcode,
9762306a36Sopenharmony_ci			    u16 size, u32 offset, dma_addr_t addr,
9862306a36Sopenharmony_ci			    u16 hash_size, u32 hash_offset,
9962306a36Sopenharmony_ci			    dma_addr_t hash_addr);
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ci/**
10262306a36Sopenharmony_ci * ipa_cmd_hdr_init_local_add() - Add a header init command to a transaction
10362306a36Sopenharmony_ci * @trans:	GSI transaction
10462306a36Sopenharmony_ci * @offset:	Offset of header memory in IPA local space
10562306a36Sopenharmony_ci * @size:	Size of header memory
10662306a36Sopenharmony_ci * @addr:	DMA address of buffer to be written from
10762306a36Sopenharmony_ci *
10862306a36Sopenharmony_ci * Defines and fills the location in IPA memory to use for headers.
10962306a36Sopenharmony_ci */
11062306a36Sopenharmony_civoid ipa_cmd_hdr_init_local_add(struct gsi_trans *trans, u32 offset, u16 size,
11162306a36Sopenharmony_ci				dma_addr_t addr);
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_ci/**
11462306a36Sopenharmony_ci * ipa_cmd_register_write_add() - Add a register write command to a transaction
11562306a36Sopenharmony_ci * @trans:	GSI transaction
11662306a36Sopenharmony_ci * @offset:	Offset of register to be written
11762306a36Sopenharmony_ci * @value:	Value to be written
11862306a36Sopenharmony_ci * @mask:	Mask of bits in register to update with bits from value
11962306a36Sopenharmony_ci * @clear_full: Pipeline clear option; true means full pipeline clear
12062306a36Sopenharmony_ci */
12162306a36Sopenharmony_civoid ipa_cmd_register_write_add(struct gsi_trans *trans, u32 offset, u32 value,
12262306a36Sopenharmony_ci				u32 mask, bool clear_full);
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_ci/**
12562306a36Sopenharmony_ci * ipa_cmd_dma_shared_mem_add() - Add a DMA memory command to a transaction
12662306a36Sopenharmony_ci * @trans:	GSI transaction
12762306a36Sopenharmony_ci * @offset:	Offset of IPA memory to be read or written
12862306a36Sopenharmony_ci * @size:	Number of bytes of memory to be transferred
12962306a36Sopenharmony_ci * @addr:	DMA address of buffer to be read into or written from
13062306a36Sopenharmony_ci * @toward_ipa:	true means write to IPA memory; false means read
13162306a36Sopenharmony_ci */
13262306a36Sopenharmony_civoid ipa_cmd_dma_shared_mem_add(struct gsi_trans *trans, u32 offset,
13362306a36Sopenharmony_ci				u16 size, dma_addr_t addr, bool toward_ipa);
13462306a36Sopenharmony_ci
13562306a36Sopenharmony_ci/**
13662306a36Sopenharmony_ci * ipa_cmd_pipeline_clear_add() - Add pipeline clear commands to a transaction
13762306a36Sopenharmony_ci * @trans:	GSI transaction
13862306a36Sopenharmony_ci */
13962306a36Sopenharmony_civoid ipa_cmd_pipeline_clear_add(struct gsi_trans *trans);
14062306a36Sopenharmony_ci
14162306a36Sopenharmony_ci/**
14262306a36Sopenharmony_ci * ipa_cmd_pipeline_clear_count() - # commands required to clear pipeline
14362306a36Sopenharmony_ci *
14462306a36Sopenharmony_ci * Return:	The number of elements to allocate in a transaction
14562306a36Sopenharmony_ci *		to hold commands to clear the pipeline
14662306a36Sopenharmony_ci */
14762306a36Sopenharmony_ciu32 ipa_cmd_pipeline_clear_count(void);
14862306a36Sopenharmony_ci
14962306a36Sopenharmony_ci/**
15062306a36Sopenharmony_ci * ipa_cmd_pipeline_clear_wait() - Wait pipeline clear to complete
15162306a36Sopenharmony_ci * @ipa:	- IPA pointer
15262306a36Sopenharmony_ci */
15362306a36Sopenharmony_civoid ipa_cmd_pipeline_clear_wait(struct ipa *ipa);
15462306a36Sopenharmony_ci
15562306a36Sopenharmony_ci/**
15662306a36Sopenharmony_ci * ipa_cmd_trans_alloc() - Allocate a transaction for the command TX endpoint
15762306a36Sopenharmony_ci * @ipa:	IPA pointer
15862306a36Sopenharmony_ci * @tre_count:	Number of elements in the transaction
15962306a36Sopenharmony_ci *
16062306a36Sopenharmony_ci * Return:	A GSI transaction structure, or a null pointer if all
16162306a36Sopenharmony_ci *		available transactions are in use
16262306a36Sopenharmony_ci */
16362306a36Sopenharmony_cistruct gsi_trans *ipa_cmd_trans_alloc(struct ipa *ipa, u32 tre_count);
16462306a36Sopenharmony_ci
16562306a36Sopenharmony_ci/**
16662306a36Sopenharmony_ci * ipa_cmd_init() - Initialize IPA immediate commands
16762306a36Sopenharmony_ci * @ipa:	- IPA pointer
16862306a36Sopenharmony_ci *
16962306a36Sopenharmony_ci * Return:	0 if successful, or a negative error code
17062306a36Sopenharmony_ci *
17162306a36Sopenharmony_ci * There is no need for a matching ipa_cmd_exit() function.
17262306a36Sopenharmony_ci */
17362306a36Sopenharmony_ciint ipa_cmd_init(struct ipa *ipa);
17462306a36Sopenharmony_ci
17562306a36Sopenharmony_ci#endif /* _IPA_CMD_H_ */
176