/* SPDX-License-Identifier: LGPL-2.1-only OR BSD-3-Clause */
/******************************************************************************
 *
 * This file is provided under a dual license.  When you use or
 * distribute this software, you may choose to be licensed under
 * version 2.1 of the GNU Lesser General Public License
 * ("LGPLv2.1 License") or BSD License.
 *
 * LGPLv2.1 License
 *
 * Copyright(C) 2019 MediaTek Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2.1 of the GNU Lesser General Public
 * License as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html for more
 * details.
 *
 * BSD LICENSE
 *
 * Copyright(C) 2019 MediaTek Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *  * Neither the name of the copyright holder nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *****************************************************************************/

/*-----------------------------------------------------------------------------
 *
 * $Author: xhui.xie $
 * $Date: 2018/06/24 $
 * $RCSfile: atsc30_drvif.h,v $
 * $Revision: #1 $
 *
 *---------------------------------------------------------------------------*/

/** @file atsc30_drvif.h
 *  Demux alp driver - atsc30_drvif.h
 */

#ifndef ATSC30_DRIVER_INTERFACE_H
#define ATSC30_DRIVER_INTERFACE_H

#include "atsc30_drvif_alp_lls.h"
#include "atsc30_drvif_packet_upload.h"
#include "atsc30_hal_ptp.h"
#include "dmx.h"

enum ATSC30_PACKET_UPLOAD_TYPE_MASK
{
    eATSC30_UPLOAD_TYPE_IP      = 0x00000001,
    eATSC30_UPLOAD_TYPE_ALP_RAW = 0x00000002,
    eATSC30_UPLOAD_TYPE_LMT     = 0x00000004,
    eATSC30_UPLOAD_TYPE_MAX
};

enum ATSC30_DRIVER_WORK_MODE
{
    eATSC30_DRIVER_BYPASS_MODE  = 0,
    eATSC30_DRIVER_NORMAL_MODE  = 1,
    eATSC30_DRIVER_NORMAL_MODE_MAX,
};

enum ATSC30_FW_WORK_MODE
{
    eATSC30_FW_NORMAL_MODE  = 0,
    eATSC30_FW_BYPASS_MODE  = 1,
    eATSC30_FW_NORMAL_MODE_MAX,
};

enum ATSC30_LMT_CB_CONSUME_MODE
{
    eATSC30_LMT_CB_SYNC_NO_NEED_CONSUME_DONE = 0,
    eATSC30_LMT_CB_ASYNC_WAIT_CONSUME_DONE   = 1,
    eATSC30_LMT_CB_CONSUME_MAX,
};

enum ATSC30_PACKET_BUFFER_OVERFLOW_TYPE
{
    eATSC30_IP_PAYLOAD_BUF_OVERFLOW  = 0x0,
    eATSC30_ALP_PAYLOAD_BUF_OVERFLOW = 0x1,
    eATSC30_LMT_PAYLOAD_BUF_OVERFLOW = 0x2,
    eATSC30_IP_DESC_BUF_OVERFLOW     = 0x10,
    eATSC30_ALP_DESC_BUF_OVERFLOW    = 0x11,
    eATSC30_ATSC30_BUFFER_OFLW_TYPE_MAX,
};

enum ATSC30_BACH_FETCH_MODE
{
    eATSC30_BATCH_FETCH_SYNC_MODE        = 0x00000001,
    eATSC30_BATCH_FETCH_ASYNC_MODE       = 0x00000002,
    eATSC30_BATCH_FETCH_MAX,
};

typedef enum
{
    ATSC30_DRVIF_SET_TYPE_HW_ROHC_DEADAPT           = 0,
    ATSC30_DRVIF_SET_TYPE_HW_MODE                   = 1,
    ATSC30_DRVIF_SET_TYPE_FW_BY_PASS_ALL            = 2,
    ATSC30_DRVIF_SET_TYPE_FW_SEND_PTP               = 3,
    ATSC30_DRVIF_SET_TYPE_FW_SEND_PLP_ID            = 4,
    ATSC30_DRVIF_SET_TYPE_FW_TRIG_INT_PKT_NUM       = 5,
    ATSC30_DRVIF_SET_TYPE_FE_INPUT_PKT_FORMAT       = 6,
    ATSC30_DRVIF_SET_TYPE_HW_CONFIG_FLAGS           = 7,
    ATSC30_DRVIF_SET_TYPE_HW_FE_TYPE                = 8,
    ATSC30_DRVIF_SET_TYPE_LMT_CB_WAIT_CONSUME_DONE  = 9,
    ATSC30_DRVIF_SET_TYPE_PACKET_UPLOAD_MASK        = 10,
    ATSC30_DRVIF_SET_TYPE_BATCH_MASK                 = 11,
    ATSC30_DRVIF_SET_TYPE_MAX,
}atsc30_driver_set_type_t;

typedef enum
{
    eATSC30_PACKET_SHARE_MEM_TYPE_ALP            = 0,
    eATSC30_PACKET_SHARE_MEM_TYPE_ALP_DESCRIPTOR = 1,
    eATSC30_PACKET_SHARE_MEM_TYPE_IP_PAYLOAD     = 2,
    eATSC30_PACKET_SHARE_MEM_TYPE_IP_DESCRIPTOR  = 3,
    eATSC30_PACKET_SHARE_MEM_TYPE_LMT_PAYLOAD    = 4,
    eATSC30_PACKET_SHARE_MEM_TYPE_MAX,
}atsc30_drvif_share_mem_cfg_type;

typedef struct
{
    atsc30_drvif_share_mem_cfg_type cfg_type;
    UINT32 buf_size;
    UPTR   buf_start_addr;
}atsc30_driver_share_memory_config_t;

typedef VOID (*pfn_atsc30_drvif_buffer_full_notification)(UINT8, UINT8);

EXTERN BOOL atsc30_drvif_init(pfn_atsc30_lls_packet_notify_cb lls_cb,
                              pfn_atsc30_drvif_buffer_full_notification pfn_oflw_nfy);

EXTERN BOOL atsc30_drvif_config_packet_delivery_info(UINT8 framer_id,
                                                     atsc30_driver_share_memory_config_t share_mem_cfg);
EXTERN BOOL atsc30_drvif_start(UINT8 framer_id);
EXTERN BOOL atsc30_drvif_stop(UINT8 framer_id);

EXTERN alp_stream_ID atsc30_drvif_set_stream(UINT8 framer_id, const alp_stream_t *const alp_strm);
EXTERN BOOL atsc30_drvif_set_plp_id_filter(UINT8 framer_id, const UINT8 *const plp_id_arr, UINT8 plp_cnt);
EXTERN BOOL atsc30_drvif_clear_plp_id_filter(const UINT8 framer_id);
EXTERN BOOL atsc30_drvif_set_info(UINT8 framer_id, atsc30_driver_set_type_t set_type, UPTR set_val);

EXTERN BOOL atsc30_drvif_get_udp_ip_batch(UINT8 framer_id, UINT32* const batch_ofst);
EXTERN BOOL atsc30_drvif_get_alp_batch(UINT8 framer_id, UINT32* const batch_ofst);

EXTERN BOOL atsc30_drvif_ip_batch_consume_done(UINT8 framer_id, UINT32 batch_id);
EXTERN BOOL atsc30_drvif_alp_batch_consume_done(UINT8 framer_id, UINT32 batch_id);
EXTERN BOOL atsc30_drvif_lmt_packet_consume_done(UINT8 framer_id, UINT32 new_rp_ofst);

EXTERN BOOL atsc30_drvif_start_lls(UINT8 framer_id);
EXTERN BOOL atsc30_drvif_stop_lls(UINT8 framer_id);

EXTERN BOOL atsc30_drvif_start_udp_ip(UINT8 framer_id);
EXTERN BOOL atsc30_drvif_stop_udp_ip(UINT8 framer_id);

EXTERN BOOL atsc30_drvif_start_alp_raw(UINT8 framer_id);
EXTERN BOOL atsc30_drvif_stop_alp_raw(UINT8 framer_id);

EXTERN BOOL atsc30_drvif_update_stream_state(const UINT8 framer_id,
                                             alp_stream_ID strm_id,
                                             ALP_STREAM_STATE_T state);

EXTERN BOOL atsc30_drvif_get_dmx_instance_id(UINT8 framer_id);

EXTERN UINT64 atsc30_drvif_get_current_system_time_utc(UINT8 framer_id);
EXTERN UINT64 atsc30_drvif_get_current_system_time_tai(UINT8 framer_id);
EXTERN BOOL atsc30_drvif_update_system_time_fragment(UINT8 framer_id,
                                                     atsc30_lls_system_time_fragment_info_t lls_sys_time_frag);
EXTERN BOOL atsc30_drvif_set_frontend(UINT8 framer_id, DMX_FRONTEND_T fe_type);

EXTERN VOID atsc30_drvif_dump_driver_info(VOID);

EXTERN VOID atsc30_drvif_dump_filter_info(VOID);

EXTERN VOID atsc30_drvif_send_overflow_message(UINT8 framer_id,
                                               enum ATSC30_PACKET_BUFFER_OVERFLOW_TYPE oflw_type);
#endif /* ATSC30_DRIVER_INTERFACE_H */
