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

#include <linux/kernel.h>
#include <linux/kconfig.h>
#include <avm/pa/avm_pa.h>

/* types to be completed by backend */
enum hwpa_backend_rv;

/* implementations required by backend */
#ifdef AVM_PA_HARDWARE_PA_HAS_PROBE_SESSION
enum hwpa_backend_rv hwpa_backend_probe_session(const struct avm_pa_session *s,
					      unsigned long *handle_out);
#endif
enum hwpa_backend_rv hwpa_backend_add_session(const struct avm_pa_session *s,
					      unsigned long *handle_out);
enum hwpa_backend_rv hwpa_backend_rem_session(unsigned long handle);
enum hwpa_backend_rv hwpa_backend_check_session(unsigned long handle);
enum hwpa_backend_rv hwpa_backend_stats(unsigned long handle,
                                        struct avm_pa_session_stats *stats);
enum hwpa_backend_rv hwpa_backend_init(struct hwpa_backend_config *hw_pa_config);
void hwpa_backend_exit(void);

#if IS_ENABLED(CONFIG_GRX5_AVM_FRITZ_BOX)
#include "hwpa_grx.h"
#elif IS_ENABLED(CONFIG_PRX_AVM_FRITZ_BOX)
#include "hwpa_prx.h"
#elif IS_ENABLED(CONFIG_QCA_NSS_AVM_FRITZ_BOX)
#include "hwpa_nss.h"
#elif IS_ENABLED(CONFIG_QCA_PPE_AVM_FRITZ_BOX)
#include "hwpa_ppe.h"
#else
#error platform unsupported or not recognized
#endif

/* valid match_info defaults */
#ifndef HWPA_VALID_L2
#define HWPA_VALID_L2                                                          \
	{ { .type = AVM_PA_NUM_MATCH_TYPES } },                                \
                                                                               \
	{ { .type = AVM_PA_ETH }, { .type = AVM_PA_NUM_MATCH_TYPES } },        \
                                                                               \
	{ { .type = AVM_PA_ETH },                                              \
	  { .type = AVM_PA_VLAN },                                             \
	  { .type = AVM_PA_NUM_MATCH_TYPES } },                                \
                                                                               \
	{ { .type = AVM_PA_ETH },                                              \
	  { .type = AVM_PA_PPPOE },                                            \
	  { .type = AVM_PA_PPP },                                              \
	  { .type = AVM_PA_NUM_MATCH_TYPES } },                                \
                                                                               \
	{ { .type = AVM_PA_ETH },                                              \
	  { .type = AVM_PA_VLAN },                                             \
	  { .type = AVM_PA_PPPOE },                                            \
	  { .type = AVM_PA_PPP },                                              \
	  { .type = AVM_PA_NUM_MATCH_TYPES } },
#endif
#ifndef HWPA_VALID_L3
#define HWPA_VALID_L3                                                          \
	{ { .type = AVM_PA_IPV4 },                                             \
	  { .type = AVM_PA_PORTS },                                            \
	  { .type = AVM_PA_NUM_MATCH_TYPES } },                                \
                                                                               \
	{ { .type = AVM_PA_IPV6 },                                             \
	  { .type = AVM_PA_PORTS },                                            \
	  { .type = AVM_PA_NUM_MATCH_TYPES } },
#endif
#ifndef HWPA_VALID_L3_L2ENCAP
#define HWPA_VALID_L3_L2ENCAP                                                  \
	{ { .type = AVM_PA_IPV4 },                                             \
	  { .type = AVM_PA_L2TP },                                             \
	  { .type = AVM_PA_NUM_MATCH_TYPES } },
#endif
#ifndef HWPA_VALID_L3_L3ENCAP
#define HWPA_VALID_L3_L3ENCAP                                                  \
	/* dslite */                                                           \
	{ { .type = AVM_PA_IPV6 },                                             \
	  { .type = AVM_PA_IPV4 },                                             \
	  { .type = AVM_PA_PORTS },                                            \
	  { .type = AVM_PA_NUM_MATCH_TYPES } },                                \
                                                                               \
	/* 6rd */                                                              \
	{ { .type = AVM_PA_IPV4 },                                             \
	  { .type = AVM_PA_IPV6 },                                             \
	  { .type = AVM_PA_PORTS },                                            \
	  { .type = AVM_PA_NUM_MATCH_TYPES } },
#endif
#ifndef HWPA_BESSIONS_ALLOWED
#define HWPA_BESSIONS_ALLOWED 0
#endif