/*
 * Copyright (c) 2016 The Linux Foundation. All rights reserved.
 *
 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
 *
 *
 * Permission to use, copy, modify, and/or distribute this software for
 * any purpose with or without fee is hereby granted, provided that the
 * above copyright notice and this permission notice appear in all
 * copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

/*
 * This file was originally distributed by Qualcomm Atheros, Inc.
 * under proprietary terms before Copyright ownership was assigned
 * to the Linux Foundation.
 */
 /**
 * @file cdp_txrx_cfg.h
 * @brief Define the host data path configuration API functions
 */
#ifndef _CDP_TXRX_CFG_H_
#define _CDP_TXRX_CFG_H_

/**
 * cdp_cfg_set_rx_fwd_disabled() - enable/disable rx forwarding
 * @soc - data path soc handle
 * @pdev - data path device instance
 * @disable_rx_fwd - enable or disable rx forwarding
 *
 * enable/disable rx forwarding
 *
 * return NONE
 */
static inline void
cdp_cfg_set_rx_fwd_disabled(ol_txrx_soc_handle soc, void *pdev,
		uint8_t disable_rx_fwd)
{
	if (!soc || !soc->ops || !soc->ops->cfg_ops) {
		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
			"%s invalid instance", __func__);
		return;
	}

	if (soc->ops->cfg_ops->set_cfg_rx_fwd_disabled)
		return soc->ops->cfg_ops->set_cfg_rx_fwd_disabled(pdev,
			disable_rx_fwd);
}

/**
 * cdp_cfg_set_packet_log_enabled() - enable/disable packet log
 * @soc - data path soc handle
 * @pdev - data path device instance
 * @val - enable or disable packet log
 *
 * packet log enable or disable
 *
 * return NONE
 */
static inline void
cdp_cfg_set_packet_log_enabled(ol_txrx_soc_handle soc,
		void *pdev, uint8_t val)
{
	if (!soc || !soc->ops || !soc->ops->cfg_ops) {
		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
			"%s invalid instance", __func__);
		return;
	}

	if (soc->ops->cfg_ops->set_cfg_packet_log_enabled)
		return soc->ops->cfg_ops->set_cfg_packet_log_enabled(pdev,
				val);
}

/**
 * cdp_cfg_attach() - attach config module
 * @soc - data path soc handle
 * @osdev - os instance
 * @cfg_param - configuration parameter should be propagated
 *
 * Allocate configuration module instance, and propagate configuration values
 *
 * return soc configuration module instance
 */
static inline void
*cdp_cfg_attach(ol_txrx_soc_handle soc,
		qdf_device_t osdev, void *cfg_param)
{
	if (!soc || !soc->ops || !soc->ops->cfg_ops) {
		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
			"%s invalid instance", __func__);
		return NULL;
	}

	if (soc->ops->cfg_ops->cfg_attach)
		return soc->ops->cfg_ops->cfg_attach(osdev, cfg_param);

	return NULL;
}

/**
 * cdp_cfg_vdev_rx_set_intrabss_fwd() - enable/disable intra bass forwarding
 * @soc - data path soc handle
 * @vdev - virtual interface instance
 * @val - enable or disable intra bss forwarding
 *
 * ap isolate, do not forward intra bss traffic
 *
 * return NONE
 */
static inline void
cdp_cfg_vdev_rx_set_intrabss_fwd(ol_txrx_soc_handle soc, void *vdev, bool val)
{
	if (!soc || !soc->ops || !soc->ops->cfg_ops) {
		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
			"%s invalid instance", __func__);
		return;
	}

	if (soc->ops->cfg_ops->vdev_rx_set_intrabss_fwd)
		return soc->ops->cfg_ops->vdev_rx_set_intrabss_fwd(vdev, val);
}

/**
 * cdp_cfg_is_rx_fwd_disabled() - get vdev rx forward
 * @soc - data path soc handle
 * @vdev - virtual interface instance
 *
 * Return rx forward feature enable status
 *
 * return 1 enabled
 *        0 disabled
 */
static inline uint8_t
cdp_cfg_is_rx_fwd_disabled(ol_txrx_soc_handle soc, void *vdev)
{
	if (!soc || !soc->ops || !soc->ops->cfg_ops) {
		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
			"%s invalid instance", __func__);
		return 0;
	}

	if (soc->ops->cfg_ops->is_rx_fwd_disabled)
		return soc->ops->cfg_ops->is_rx_fwd_disabled(vdev);
	return 0;
}

/**
 * cdp_cfg_tx_set_is_mgmt_over_wmi_enabled() - mgmt tx over wmi enable/disable
 * @soc - data path soc handle
 * @value - feature enable or disable
 *
 * Enable or disable management packet TX over WMI feature
 *
 * return None
 */
static inline void
cdp_cfg_tx_set_is_mgmt_over_wmi_enabled(ol_txrx_soc_handle soc,
		uint8_t value)
{
	if (!soc || !soc->ops || !soc->ops->cfg_ops) {
		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
			"%s invalid instance", __func__);
		return;
	}

	if (soc->ops->cfg_ops->tx_set_is_mgmt_over_wmi_enabled)
		return soc->ops->cfg_ops->tx_set_is_mgmt_over_wmi_enabled(
			value);
}

/**
 * cdp_cfg_is_high_latency() - query data path is in high or low latency
 * @soc - data path soc handle
 * @pdev - data path device instance
 *
 * query data path is in high or low latency
 *
 * return 1 high latency data path, usb or sdio
 *        0 low latency data path
 */
static inline int
cdp_cfg_is_high_latency(ol_txrx_soc_handle soc, void *pdev)
{
	if (!soc || !soc->ops || !soc->ops->cfg_ops) {
		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
			"%s invalid instance", __func__);
		return 0;
	}

	if (soc->ops->cfg_ops->is_high_latency)
		return soc->ops->cfg_ops->is_high_latency(pdev);

	return 0;
}

/**
 * cdp_cfg_set_flow_control_parameters() - set flow control params
 * @soc - data path soc handle
 * @cfg - dp config module instance
 * @param - parameters should set
 *
 * set flow control params
 *
 * return None
 */
static inline void
cdp_cfg_set_flow_control_parameters(ol_txrx_soc_handle soc,
		void *cfg, void *param)
{
	if (!soc || !soc->ops || !soc->ops->cfg_ops) {
		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
			"%s invalid instance", __func__);
		return;
	}

	if (soc->ops->cfg_ops->set_flow_control_parameters)
		return soc->ops->cfg_ops->set_flow_control_parameters(cfg,
				param);

	return;
}

/**
 * cdp_cfg_set_flow_steering - Set Rx flow steering config based on CFG ini
 *			config.
 *
 * @pdev - handle to the physical device
 * @val - 0 - disable, 1 - enable
 *
 * Return: None
 */
static inline void cdp_cfg_set_flow_steering(ol_txrx_soc_handle soc,
		void *pdev, uint8_t val)
{
	if (!soc || !soc->ops || !soc->ops->cfg_ops) {
		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
			"%s invalid instance", __func__);
		return;
	}

	if (soc->ops->cfg_ops->set_flow_steering)
		return soc->ops->cfg_ops->set_flow_steering(pdev, val);

	return;
}
#endif /* _CDP_TXRX_CFG_H_ */