blob: 7187ba358415edd2231c3f061a2dca3feda79332 [file] [log] [blame]
/*
<:copyright-BRCM:2016:DUAL/GPL:standard
Broadcom Proprietary and Confidential.(c) 2016 Broadcom
All Rights Reserved
Unless you and Broadcom execute a separate written software license
agreement governing use of this software, this software is licensed
to you under the terms of the GNU General Public License version 2
(the "GPL"), available at http://www.broadcom.com/licenses/GPLv2.php,
with the following added to such license:
As a special exception, the copyright holders of this software give
you permission to link this software with independent modules, and
to copy and distribute the resulting executable under terms of your
choice, provided that you also meet, for each linked independent
module, the terms and conditions of the license of that module.
An independent module is a module which is not derived from this
software. The special exception does not apply to any modifications
of the software.
Not withstanding the above, under no circumstances may you combine
this software in any way with any other Broadcom software provided
under a license other than the GPL, without Broadcom's express prior
written consent.
:>
*/
#ifndef _BCMOLT_DEV_CTRL_H_
#define _BCMOLT_DEV_CTRL_H_
#include <bcmos_system.h>
#include <bcmolt_msg.h>
#include <bcmolt_model_types.h>
#include "bcm_keep_alive.h"
#include "bcmolt_fld.h"
#include "bcmolt_sw_error.h"
typedef int (*bcmolt_dev_ctrl_cb_image_read)(
bcmolt_devid device,
bcmolt_device_image_type image_type,
uint32_t offset,
uint8_t *buf,
uint32_t buf_size);
typedef bcmos_errno (*bcmolt_dev_ctrl_cb_system_mode_validate)(bcmolt_devid device, bcmolt_system_mode system_mode);
typedef bcmos_errno (*bcmolt_dev_ctrl_cb_device_off)(bcmolt_devid device);
typedef bcmos_errno (*bcmolt_dev_ctrl_cb_device_on)(bcmolt_devid device);
typedef bcmos_errno (*bcmolt_dev_ctrl_cb_device_is_running)(bcmolt_devid device, bcmos_bool *is_running);
typedef bcmos_errno (*bcmolt_dev_ctrl_cb_host_reset)(void);
typedef bcmos_errno (*bcmolt_dev_ctrl_cb_pcie_channel_prepare)(bcmolt_devid device);
typedef bcmos_errno (*bcmolt_dev_ctrl_cb_pcie_channel_remove)(bcmolt_devid device);
typedef bcmos_errno (*bcmolt_dev_ctrl_cb_pcie_status_get)(bcmolt_devid device, bcmos_bool *is_prepared);
typedef struct
{
bcmolt_dev_ctrl_cb_system_mode_validate system_mode_validate_cb;
bcmolt_dev_ctrl_cb_image_read image_read_cb;
bcmolt_dev_ctrl_cb_device_off device_off_cb;
bcmolt_dev_ctrl_cb_device_on device_on_cb;
bcmolt_dev_ctrl_cb_device_is_running device_is_running_cb;
bcmolt_dev_ctrl_cb_host_reset host_reset_cb;
bcmolt_dev_ctrl_cb_pcie_channel_prepare pcie_channel_prepare_cb;
bcmolt_dev_ctrl_cb_pcie_channel_remove pcie_channel_remove_cb;
} bcmolt_dev_ctrl_params;
#define DEVICE_CONTROL_MSG_QUEUE_SIZE BCMOS_MSG_POOL_DEFAULT_SIZE
#define IMAGE_BUF_SIZE (1 * 1024 * 1024) /* 1MB */
#define BOOT_SEQ_POLL_INTERVAL_SEC 1
#define BOOT_SEQ_POLLING_MAX_NUMBER 5
#define DDR_TEST_POLLING_MAX_NUMBER 20
#define DEVICE_CONTROL_CONFIG_TIME_US (15 * 1000000) /* 15 seconds */
#define DEVICE_CONTROL_CONNECT_TIME_US (40 * 1000000) /* 40 seconds */
#define CONFIG_SEND_MAX_NUMBER 2
#define FILE_PATH_LEN 128
#define HOST_DMA_RX_DEFAULT_QUEUE_SIZE 128
#define HOST_DMA_TX_DEFAULT_QUEUE_SIZE 128
#define EXCEPTION_LOG_MONITOR_INTERVAL (5 * 1000000) /* 5 second */
#define DEVICE_RESPONSE_TIMEOUT_LENGTH (2 * 100000) /* 200 milliseconds */
#define HOST_RESET_DELAY_US 100000 /* how long to wait before resetting the host via callback (100ms) */
/* indicates successful connection - used internally, no need to expose this in the host-facing enum */
#define BCMOLT_HOST_CONNECTION_FAIL_REASON_NONE ((bcmolt_host_connection_fail_reason)0xFF)
typedef enum
{
DEVICE_CONTROL_EVENT_DEVICE_CLEAR,
DEVICE_CONTROL_EVENT_DEVICE_CONFIG_SET,
DEVICE_CONTROL_EVENT_DEVICE_CONFIG_GET,
DEVICE_CONTROL_EVENT_DEVICE_TIMER_TIMEOUT,
DEVICE_CONTROL_EVENT_DEVICE_RECEIVED_ACK,
DEVICE_CONTROL_EVENT_DEVICE_DISCONNECT,
DEVICE_CONTROL_EVENT_DEVICE_CONNECT,
DEVICE_CONTROL_EVENT_DEVICE_RESET,
DEVICE_CONTROL_EVENT_CONNECTION_FAILURE,
DEVICE_CONTROL_EVENT_CONNECTION_ESTABLISHED,
DEVICE_CONTROL_EVENT_DEVICE_READY,
DEVICE_CONTROL_EVENT_RUN_DDR_TEST,
DEVICE_CONTROL_EVENT_DDR_TEST_COMPLETED,
DEVICE_CONTROL_EVENT_DDR_TEST_TIMEOUT,
DEVICE_CONTROL_EVENT__NUM_OF,
DEVICE_CONTROL_EVENT_NO_EVENT = DEVICE_CONTROL_EVENT__NUM_OF
} dev_ctrl_event;
typedef enum
{
DEV_CTRL_CONNECTING_STATE_ESTABLISHING, /* writing software via FLD, waiting for "connection established" */
DEV_CTRL_CONNECTING_STATE_CONFIGURING, /* connection established, cfg sent, waiting for "device ready" */
DEV_CTRL_CONNECTING_STATE_STANDALONE, /* connecting to a standalone device, waiting for "device ready" */
} dev_ctrl_connecting_state;
typedef struct
{
char name[MAX_TASK_NAME_SIZE];
bcmos_task task;
} dev_ctrl_task;
typedef struct
{
char name[MAX_MODULE_NAME_SIZE];
bcmos_module_id module_id;
} dev_ctrl_module;
typedef struct
{
char name[MAX_TIMER_NAME_SIZE];
bcmos_timer timer;
} dev_ctrl_timer;
typedef struct
{
uint32_t pcie_addr;
} dev_ctrl_pcie;
typedef struct
{
dev_ctrl_connecting_state state;
uint32_t config_send_counter;
uint32_t config_interval;
dev_ctrl_timer timer;
} dev_ctrl_connection;
typedef struct
{
uint32_t polling_counter;
uint32_t polling_interval;
dev_ctrl_timer timer;
} dev_ctrl_boot_seq;
typedef struct
{
dev_ctrl_task task_info;
dev_ctrl_module module_info;
dev_ctrl_connection connection_info;
dev_ctrl_pcie pcie_info;
bcmos_keep_alive_info ka_info;
dev_ctrl_boot_seq boot_seq_info;
bcm_fld_device_info fld_info;
bcmolt_device_cfg_data device_params;
bcmolt_presence_mask device_params_present;
dev_ctrl_timer exception_monitor_timer;
uint16_t corr_tag;
bcmolt_msg * last_message;
dev_ctrl_timer device_response_timer;
dev_ctrl_timer reset_delay_timer;
bcmos_bool is_host_reset_pending;
#ifdef ENABLE_LOG
uint32_t sram_log_offset;
uint32_t msgs_read;
#endif
bcmolt_control_state enable_tod;
#ifndef SIMULATION_BUILD
uint32_t trx_disable_mask;
#endif
dev_ctrl_event last_event;
bcmolt_host_connection_fail_reason conn_fail_reason;
uint32_t sw_error_count;
bcmolt_sw_error sw_errors[30];
dev_log_id log_id;
} dev_ctrl_database;
typedef void (*dev_ctrl_sm_cb)(bcmolt_devid device, const bcmolt_msg *msg);
#define DEVICE_ID_FROM_MODULE_ID(module_id) ((bcmolt_devid)(module_id - BCMOS_MODULE_ID_DEV_CTRL_DEV0))
#define MODULE_ID_FROM_DEVICE_ID(device) ((bcmos_module_id)(device + BCMOS_MODULE_ID_DEV_CTRL_DEV0))
const char *bcm_str_device_state(bcmolt_device_state device_state);
const char *bcm_str_device_event(dev_ctrl_event device_event);
const char *bcm_str_host_connection_fail_reason(bcmolt_host_connection_fail_reason reason);
const char *bcm_str_host_connecting_state(dev_ctrl_connecting_state state);
void dev_ctrl_read_db(bcmolt_devid device, dev_ctrl_database *db);
bcmos_errno bcmolt_dev_ctrl_host_event_write(uint32_t device, uint32_t event);
/*Use different function signatures linux kernel device control and other*/
#if !defined(LINUX_USER_SPACE)
bcmos_errno bcmolt_dev_ctrl_init(bcmolt_dev_ctrl_params *params);
#else
bcmos_errno bcmolt_dev_ctrl_init(void);
#endif
void bcmolt_dev_ctrl_exit(void);
#endif