/* SPDX-License-Identifier: GPL-2.0-only */


#ifndef _IPA_WDI3_H_
#define _IPA_WDI3_H_

#include <linux/ipa.h>

#define IPA_HW_WDI3_TCL_DATA_CMD_ER_DESC_SIZE 32
#define IPA_HW_WDI3_IPA2FW_ER_DESC_SIZE 8

#define IPA_HW_WDI3_MAX_ER_DESC_SIZE \
	(((IPA_HW_WDI3_TCL_DATA_CMD_ER_DESC_SIZE) > \
	(IPA_HW_WDI3_IPA2FW_ER_DESC_SIZE)) ?  \
	(IPA_HW_WDI3_TCL_DATA_CMD_ER_DESC_SIZE) : \
	(IPA_HW_WDI3_IPA2FW_ER_DESC_SIZE))

#define IPA_WDI_MAX_SUPPORTED_SYS_PIPE 3
#define IPA_WDI_MAX_FILTER_INFO_COUNT 5

typedef u32 ipa_wdi_hdl_t;

enum ipa_wdi_version {
	IPA_WDI_1,
	IPA_WDI_2,
	IPA_WDI_3,
	IPA_WDI_3_V2,
	IPA_WDI_4,
	IPA_WDI_VER_MAX
};

#define IPA_WDI3_TX_DIR 1
#define IPA_WDI3_TX1_DIR 2
#define IPA_WDI3_RX_DIR 3
#define IPA_WDI_INST_MAX (3)


struct ipa_wdi_init_in_params {
	enum ipa_wdi_version wdi_version;
	ipa_uc_ready_cb notify;
	void *priv;
#ifdef IPA_WAN_MSG_IPv6_ADDR_GW_LEN
	ipa_wdi_meter_notifier_cb wdi_notify;
#endif
	int inst_id;
};


struct ipa_wdi_init_out_params {
	bool is_uC_ready;
	bool is_smmu_enabled;
	bool is_over_gsi;
	ipa_wdi_hdl_t hdl;
	bool opt_wdi_dpath;
};


struct filter_tuple_info {
	u8 version;
	union {
		struct {
			__be32 ipv4_saddr;
			__be32 ipv4_daddr;
		} ipv4_addr;
		struct {
			__be32 ipv6_saddr[4];
			__be32 ipv6_daddr[4];
		} ipv6_addr;
	};
	u8 protocol;
	__be16 sport;
	__be16 dport;
	u32 out_hdl;
};


struct ipa_wdi_opt_dpath_flt_add_cb_params {
	u8 num_tuples;
	struct filter_tuple_info flt_info[IPA_WDI_MAX_FILTER_INFO_COUNT];
};


struct ipa_wdi_opt_dpath_flt_rem_cb_params {
	u8 num_tuples;
	u32 hdl_info[IPA_WDI_MAX_FILTER_INFO_COUNT];
};


struct ipa_wdi_opt_dpath_flt_rsrv_cb_params {
	u8 num_filters;
	u32 rsrv_timeout;
};

typedef int (*ipa_wdi_opt_dpath_flt_rsrv_cb)
	(void *priv, struct ipa_wdi_opt_dpath_flt_rsrv_cb_params *in);

typedef int (*ipa_wdi_opt_dpath_flt_rsrv_rel_cb)
	(void *priv);

typedef int (*ipa_wdi_opt_dpath_flt_add_cb)
	(void *priv, struct ipa_wdi_opt_dpath_flt_add_cb_params *in_out);

typedef int (*ipa_wdi_opt_dpath_flt_rem_cb)
	(void *priv, struct ipa_wdi_opt_dpath_flt_rem_cb_params *in);


struct ipa_wdi_hdr_info {
	u8 *hdr;
	u8 hdr_len;
	u8 dst_mac_addr_offset;
	enum ipa_hdr_l2_type hdr_type;
};


struct ipa_wdi_reg_intf_in_params {
	const char *netdev_name;
	struct ipa_wdi_hdr_info hdr_info[IPA_IP_MAX];
	enum ipa_client_type alt_dst_pipe;
	u8 is_meta_data_valid;
	u32 meta_data;
	u32 meta_data_mask;
	u8 is_tx1_used;
	ipa_wdi_hdl_t hdl;
};


struct ipa_wdi_pipe_setup_info {
	struct ipa_ep_cfg ipa_ep_cfg;
	enum ipa_client_type client;
	phys_addr_t  transfer_ring_base_pa;
	u32  transfer_ring_size;
	phys_addr_t  transfer_ring_doorbell_pa;
	bool is_txr_rn_db_pcie_addr;

	phys_addr_t  event_ring_base_pa;
	u32  event_ring_size;
	phys_addr_t  event_ring_doorbell_pa;
	bool is_evt_rn_db_pcie_addr;
	u16  num_pkt_buffers;

	u16 pkt_offset;

	u32  desc_format_template[IPA_HW_WDI3_MAX_ER_DESC_SIZE];
	u8 rx_bank_id;
	u8 rx_pmac_id;
	u8 mlo_chip_id;
};


struct ipa_wdi_pipe_setup_info_smmu {
	struct ipa_ep_cfg ipa_ep_cfg;
	enum ipa_client_type client;
	struct sg_table  transfer_ring_base;
	u32  transfer_ring_size;
	phys_addr_t  transfer_ring_doorbell_pa;
	bool is_txr_rn_db_pcie_addr;

	struct sg_table  event_ring_base;
	u32  event_ring_size;
	phys_addr_t  event_ring_doorbell_pa;
	bool is_evt_rn_db_pcie_addr;
	u16  num_pkt_buffers;

	u16 pkt_offset;

	u32  desc_format_template[IPA_HW_WDI3_MAX_ER_DESC_SIZE];
	u8 rx_bank_id;
	u8 rx_pmac_id;
	u8 mlo_chip_id;
};


struct ipa_wdi_conn_in_params {
	ipa_notify_cb notify;
	void *priv;
	bool is_smmu_enabled;
	u8 num_sys_pipe_needed;
	struct ipa_sys_connect_params sys_in[IPA_WDI_MAX_SUPPORTED_SYS_PIPE];
	union {
		struct ipa_wdi_pipe_setup_info tx;
		struct ipa_wdi_pipe_setup_info_smmu tx_smmu;
	} u_tx;
	union {
		struct ipa_wdi_pipe_setup_info rx;
		struct ipa_wdi_pipe_setup_info_smmu rx_smmu;
	} u_rx;
	bool is_tx1_used;
	union {
		struct ipa_wdi_pipe_setup_info tx;
		struct ipa_wdi_pipe_setup_info_smmu tx_smmu;
	} u_tx1;
	ipa_wdi_hdl_t hdl;
};


struct ipa_wdi_conn_out_params {
	phys_addr_t tx_uc_db_pa;
	phys_addr_t rx_uc_db_pa;
	phys_addr_t tx1_uc_db_pa;
	bool is_ddr_mapped;
};


struct ipa_wdi_perf_profile {
	enum ipa_client_type client;
	u32 max_supported_bw_mbps;
};



struct ipa_wdi_capabilities_out_params {
	u8 num_of_instances;
};

#if IS_ENABLED(CONFIG_IPA3)


int ipa_wdi_get_capabilities(
	struct ipa_wdi_capabilities_out_params *out);


int ipa_wdi_init(struct ipa_wdi_init_in_params *in,
	struct ipa_wdi_init_out_params *out);


int ipa_wdi_opt_dpath_register_flt_cb_per_inst(
	ipa_wdi_hdl_t hdl,
	ipa_wdi_opt_dpath_flt_rsrv_cb flt_rsrv_cb,
	ipa_wdi_opt_dpath_flt_rsrv_rel_cb flt_rsrv_rel_cb,
	ipa_wdi_opt_dpath_flt_add_cb flt_add_cb,
	ipa_wdi_opt_dpath_flt_rem_cb flt_rem_cb);


int ipa_wdi_opt_dpath_notify_flt_rsvd_per_inst(ipa_wdi_hdl_t hdl,
	bool is_success);

int ipa_wdi_opt_dpath_notify_flt_rlsd_per_inst(ipa_wdi_hdl_t hdl,
	bool is_success);


int ipa_wdi_opt_dpath_rsrv_filter_req(
	struct ipa_wlan_opt_dp_rsrv_filter_req_msg_v01 *req,
	struct ipa_wlan_opt_dp_rsrv_filter_resp_msg_v01 *resp);


int ipa_wdi_opt_dpath_add_filter_req(
	struct ipa_wlan_opt_dp_add_filter_req_msg_v01 *req,
	struct ipa_wlan_opt_dp_add_filter_complt_ind_msg_v01 *ind);


int ipa_wdi_opt_dpath_remove_filter_req(
		struct ipa_wlan_opt_dp_remove_filter_req_msg_v01 *req,
		struct ipa_wlan_opt_dp_remove_filter_complt_ind_msg_v01 *ind);


int ipa_wdi_opt_dpath_remove_all_filter_req(
		struct ipa_wlan_opt_dp_remove_all_filter_req_msg_v01 *req,
		struct ipa_wlan_opt_dp_remove_all_filter_resp_msg_v01 *resp);


int ipa_get_wdi_version(void);


bool ipa_wdi_is_tx1_used(void);


int ipa_wdi_init_per_inst(struct ipa_wdi_init_in_params *in,
	struct ipa_wdi_init_out_params *out);


int ipa_wdi_cleanup(void);


int ipa_wdi_cleanup_per_inst(ipa_wdi_hdl_t hdl);



int ipa_wdi_reg_intf(
	struct ipa_wdi_reg_intf_in_params *in);


int ipa_wdi_reg_intf_per_inst(
	struct ipa_wdi_reg_intf_in_params *in);


int ipa_wdi_dereg_intf(const char *netdev_name);


int ipa_wdi_dereg_intf_per_inst(const char *netdev_name, ipa_wdi_hdl_t hdl);


int ipa_wdi_conn_pipes(struct ipa_wdi_conn_in_params *in,
	struct ipa_wdi_conn_out_params *out);


int ipa_wdi_conn_pipes_per_inst(struct ipa_wdi_conn_in_params *in,
	struct ipa_wdi_conn_out_params *out);


int ipa_wdi_disconn_pipes(void);


int ipa_wdi_disconn_pipes_per_inst(ipa_wdi_hdl_t hdl);


int ipa_wdi_enable_pipes(void);


int ipa_wdi_enable_pipes_per_inst(ipa_wdi_hdl_t hdl);


int ipa_wdi_disable_pipes(void);


int ipa_wdi_disable_pipes_per_inst(ipa_wdi_hdl_t hdl);


int ipa_wdi_set_perf_profile(struct ipa_wdi_perf_profile *profile);


int ipa_wdi_set_perf_profile_per_inst(ipa_wdi_hdl_t hdl,
	struct ipa_wdi_perf_profile *profile);


int ipa_wdi_create_smmu_mapping(u32 num_buffers,
	struct ipa_wdi_buffer_info *info);


int ipa_wdi_create_smmu_mapping_per_inst(ipa_wdi_hdl_t hdl,
	u32 num_buffers,
	struct ipa_wdi_buffer_info *info);


int ipa_wdi_release_smmu_mapping(u32 num_buffers,
	struct ipa_wdi_buffer_info *info);


int ipa_wdi_release_smmu_mapping_per_inst(ipa_wdi_hdl_t hdl,
	u32 num_buffers,
	struct ipa_wdi_buffer_info *info);


int ipa_wdi_get_stats(struct IpaHwStatsWDIInfoData_t *stats);



int ipa_wdi_bw_monitor(struct ipa_wdi_bw_info *info);


int ipa_wdi_sw_stats(struct ipa_wdi_tx_info *info);

#else 


int ipa_wdi_get_capabilities(
	struct ipa_wdi_capabilities_out_params *out)
{
	return -EPERM;
}

static inline int ipa_wdi_init(struct ipa_wdi_init_in_params *in,
	struct ipa_wdi_init_out_params *out)
{
	return -EPERM;
}

static inline int ipa_wdi_init_per_inst(
	struct ipa_wdi_init_in_params *in,
	struct ipa_wdi_init_out_params *out)
{
	return -EPERM;
}

static inline int ipa_get_wdi_version(void)
{
	return -EPERM;
}

static inline int ipa_wdi_is_tx1_used(void)
{
	return -EPERM;
}

static inline int ipa_wdi_cleanup(void)
{
	return -EPERM;
}

static inline int ipa_wdi_cleanup_per_inst(ipa_wdi_hdl_t hdl)
{
	return -EPERM;
}

static inline int ipa_wdi_reg_intf(
	struct ipa_wdi_reg_intf_in_params *in)
{
	return -EPERM;
}

static inline int ipa_wdi_reg_intf_per_inst(
	struct ipa_wdi_reg_intf_in_params *in)
{
	return -EPERM;
}

static inline int ipa_wdi_dereg_intf(const char *netdev_name)
{
	return -EPERM;
}

static inline int ipa_wdi_dereg_intf_per_inst(const char *netdev_name,
	ipa_wdi_hdl_t hdl)
{
	return -EPERM;
}

static inline int ipa_wdi_conn_pipes(struct ipa_wdi_conn_in_params *in,
	struct ipa_wdi_conn_out_params *out)
{
	return -EPERM;
}

static inline int ipa_wdi_conn_pipes_per_inst(
	struct ipa_wdi_conn_in_params *in,
	struct ipa_wdi_conn_out_params *out)
{
	return -EPERM;
}

static inline int ipa_wdi_disconn_pipes(void)
{
	return -EPERM;
}

static inline int ipa_wdi_disconn_pipes_per_inst(ipa_wdi_hdl_t hdl)
{
	return -EPERM;
}


static inline int ipa_wdi_enable_pipes(void)
{
	return -EPERM;
}

static inline int ipa_wdi_enable_pipes_per_inst(ipa_wdi_hdl_t hdl)
{
	return -EPERM;
}

static inline int ipa_wdi_disable_pipes(void)
{
	return -EPERM;
}

static inline int ipa_wdi_disable_pipes_per_inst(ipa_wdi_hdl_t hdl)
{
	return -EPERM;
}

static inline int ipa_wdi_set_perf_profile(
	struct ipa_wdi_perf_profile *profile)
{
	return -EPERM;
}

static inline int ipa_wdi_set_perf_profile_per_inst(
	ipa_wdi_hdl_t hdl,
	struct ipa_wdi_perf_profile *profile)
{
	return -EPERM;
}

static inline int ipa_wdi_create_smmu_mapping(u32 num_buffers,
	struct ipa_wdi_buffer_info *info)
{
	return -EPERM;
}

static inline int ipa_wdi_create_smmu_mapping_per_inst(
	ipa_wdi_hdl_t hdl,
	u32 num_buffers,
	struct ipa_wdi_buffer_info *info)
{
	return -EPERM;
}

static inline int ipa_wdi_release_smmu_mapping(u32 num_buffers,
	struct ipa_wdi_buffer_info *info)
{
	return -EPERM;
}

static inline int ipa_wdi_release_smmu_mapping_per_inst(
	ipa_wdi_hdl_t hdl,
	u32 num_buffers,
	struct ipa_wdi_buffer_info *info)
{
	return -EPERM;
}

static inline int ipa_wdi_get_stats(struct IpaHwStatsWDIInfoData_t *stats)
{
	return -EPERM;
}

static inline int ipa_wdi_bw_monitor(struct ipa_wdi_bw_info *info)
{
	return -EPERM;
}

static inline int ipa_wdi_sw_stats(struct ipa_wdi_tx_info *info)
{
	return -EPERM;
}

static inline int ipa_wdi_opt_dpath_register_flt_cb_per_inst(
	ipa_wdi_hdl_t hdl,
	ipa_wdi_opt_dpath_flt_rsrv_cb flt_rsrv_cb,
	ipa_wdi_opt_dpath_flt_rsrv_rel_cb flt_rsrv_rel_cb,
	ipa_wdi_opt_dpath_flt_add_cb flt_add_cb,
	ipa_wdi_opt_dpath_flt_rem_cb flt_rem_cb)
{
	return -EPERM;
}

static inline int ipa_wdi_opt_dpath_notify_flt_rsvd_per_inst(ipa_wdi_hdl_t hdl,
	bool is_success)
{
	return -EPERM;
}

static inline int ipa_wdi_opt_dpath_notify_flt_rlsd_per_inst(ipa_wdi_hdl_t hdl,
	bool is_success)
{
	return -EPERM;
}

static int ipa_wdi_opt_dpath_rsrv_filter_req(
	struct ipa_wlan_opt_dp_rsrv_filter_req_msg_v01 *req,
	struct ipa_wlan_opt_dp_rsrv_filter_resp_msg_v01 *resp);
{
	return -EPERM;
}

static int ipa_wdi_opt_dpath_add_filter_req(
	struct ipa_wlan_opt_dp_add_filter_req_msg_v01 *req,
	struct ipa_wlan_opt_dp_add_filter_complt_ind_msg_v01 *ind)
{
	return -EPERM;
}

static int ipa_wdi_opt_dpath_remove_filter_req(
		struct ipa_wlan_opt_dp_remove_filter_req_msg_v01 *req,
		struct ipa_wlan_opt_dp_remove_filter_complt_ind_msg_v01 *ind)
{
	return -EPERM;
}

static int ipa_wdi_opt_dpath_remove_all_filter_req(
		struct ipa_wlan_opt_dp_remove_all_filter_req_msg_v01 *req,
		struct ipa_wlan_opt_dp_remove_all_filter_resp_msg_v01 *resp)
{
	return -EPERM;
}

#endif 

#endif 
