Shad Ansari | 2f7f9be | 2017-06-07 13:34:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | <:copyright-BRCM:2016:DUAL/GPL:standard |
| 3 | |
| 4 | Broadcom Proprietary and Confidential.(c) 2016 Broadcom |
| 5 | All Rights Reserved |
| 6 | |
| 7 | Unless you and Broadcom execute a separate written software license |
| 8 | agreement governing use of this software, this software is licensed |
| 9 | to you under the terms of the GNU General Public License version 2 |
| 10 | (the "GPL"), available at http://www.broadcom.com/licenses/GPLv2.php, |
| 11 | with the following added to such license: |
| 12 | |
| 13 | As a special exception, the copyright holders of this software give |
| 14 | you permission to link this software with independent modules, and |
| 15 | to copy and distribute the resulting executable under terms of your |
| 16 | choice, provided that you also meet, for each linked independent |
| 17 | module, the terms and conditions of the license of that module. |
| 18 | An independent module is a module which is not derived from this |
| 19 | software. The special exception does not apply to any modifications |
| 20 | of the software. |
| 21 | |
| 22 | Not withstanding the above, under no circumstances may you combine |
| 23 | this software in any way with any other Broadcom software provided |
| 24 | under a license other than the GPL, without Broadcom's express prior |
| 25 | written consent. |
| 26 | |
| 27 | :> |
| 28 | */ |
| 29 | |
| 30 | #ifndef _BCMOLT_DEV_CTRL_H_ |
| 31 | #define _BCMOLT_DEV_CTRL_H_ |
| 32 | |
| 33 | #include <bcmos_system.h> |
| 34 | #include <bcmolt_msg.h> |
| 35 | #include <bcmolt_model_types.h> |
| 36 | #include "bcm_keep_alive.h" |
| 37 | #include "bcmolt_fld.h" |
| 38 | #include "bcmolt_sw_error.h" |
| 39 | |
| 40 | typedef int (*bcmolt_dev_ctrl_cb_image_read)( |
| 41 | bcmolt_devid device, |
| 42 | bcmolt_device_image_type image_type, |
| 43 | uint32_t offset, |
| 44 | uint8_t *buf, |
| 45 | uint32_t buf_size); |
| 46 | typedef bcmos_errno (*bcmolt_dev_ctrl_cb_system_mode_validate)(bcmolt_devid device, bcmolt_system_mode system_mode); |
| 47 | typedef bcmos_errno (*bcmolt_dev_ctrl_cb_device_off)(bcmolt_devid device); |
| 48 | typedef bcmos_errno (*bcmolt_dev_ctrl_cb_device_on)(bcmolt_devid device); |
| 49 | typedef bcmos_errno (*bcmolt_dev_ctrl_cb_device_is_running)(bcmolt_devid device, bcmos_bool *is_running); |
| 50 | typedef bcmos_errno (*bcmolt_dev_ctrl_cb_host_reset)(void); |
| 51 | typedef bcmos_errno (*bcmolt_dev_ctrl_cb_pcie_channel_prepare)(bcmolt_devid device); |
| 52 | typedef bcmos_errno (*bcmolt_dev_ctrl_cb_pcie_channel_remove)(bcmolt_devid device); |
| 53 | typedef bcmos_errno (*bcmolt_dev_ctrl_cb_pcie_status_get)(bcmolt_devid device, bcmos_bool *is_prepared); |
| 54 | |
| 55 | typedef struct |
| 56 | { |
| 57 | bcmolt_dev_ctrl_cb_system_mode_validate system_mode_validate_cb; |
| 58 | bcmolt_dev_ctrl_cb_image_read image_read_cb; |
| 59 | bcmolt_dev_ctrl_cb_device_off device_off_cb; |
| 60 | bcmolt_dev_ctrl_cb_device_on device_on_cb; |
| 61 | bcmolt_dev_ctrl_cb_device_is_running device_is_running_cb; |
| 62 | bcmolt_dev_ctrl_cb_host_reset host_reset_cb; |
| 63 | bcmolt_dev_ctrl_cb_pcie_channel_prepare pcie_channel_prepare_cb; |
| 64 | bcmolt_dev_ctrl_cb_pcie_channel_remove pcie_channel_remove_cb; |
| 65 | } bcmolt_dev_ctrl_params; |
| 66 | |
| 67 | #define DEVICE_CONTROL_MSG_QUEUE_SIZE BCMOS_MSG_POOL_DEFAULT_SIZE |
| 68 | #define IMAGE_BUF_SIZE (1 * 1024 * 1024) /* 1MB */ |
| 69 | #define BOOT_SEQ_POLL_INTERVAL_SEC 1 |
| 70 | #define BOOT_SEQ_POLLING_MAX_NUMBER 5 |
| 71 | #define DDR_TEST_POLLING_MAX_NUMBER 20 |
| 72 | #define DEVICE_CONTROL_CONFIG_TIME_US (15 * 1000000) /* 15 seconds */ |
| 73 | #define DEVICE_CONTROL_CONNECT_TIME_US (40 * 1000000) /* 40 seconds */ |
| 74 | #define CONFIG_SEND_MAX_NUMBER 2 |
| 75 | #define FILE_PATH_LEN 128 |
| 76 | #define HOST_DMA_RX_DEFAULT_QUEUE_SIZE 128 |
| 77 | #define HOST_DMA_TX_DEFAULT_QUEUE_SIZE 128 |
| 78 | #define EXCEPTION_LOG_MONITOR_INTERVAL (5 * 1000000) /* 5 second */ |
| 79 | #define DEVICE_RESPONSE_TIMEOUT_LENGTH (2 * 100000) /* 200 milliseconds */ |
| 80 | #define HOST_RESET_DELAY_US 100000 /* how long to wait before resetting the host via callback (100ms) */ |
| 81 | |
| 82 | /* indicates successful connection - used internally, no need to expose this in the host-facing enum */ |
| 83 | #define BCMOLT_HOST_CONNECTION_FAIL_REASON_NONE ((bcmolt_host_connection_fail_reason)0xFF) |
| 84 | |
| 85 | typedef enum |
| 86 | { |
| 87 | DEVICE_CONTROL_EVENT_DEVICE_CLEAR, |
| 88 | DEVICE_CONTROL_EVENT_DEVICE_CONFIG_SET, |
| 89 | DEVICE_CONTROL_EVENT_DEVICE_CONFIG_GET, |
| 90 | DEVICE_CONTROL_EVENT_DEVICE_TIMER_TIMEOUT, |
| 91 | DEVICE_CONTROL_EVENT_DEVICE_RECEIVED_ACK, |
| 92 | DEVICE_CONTROL_EVENT_DEVICE_DISCONNECT, |
| 93 | DEVICE_CONTROL_EVENT_DEVICE_CONNECT, |
| 94 | DEVICE_CONTROL_EVENT_DEVICE_RESET, |
| 95 | DEVICE_CONTROL_EVENT_CONNECTION_FAILURE, |
| 96 | DEVICE_CONTROL_EVENT_CONNECTION_ESTABLISHED, |
| 97 | DEVICE_CONTROL_EVENT_DEVICE_READY, |
| 98 | DEVICE_CONTROL_EVENT_RUN_DDR_TEST, |
| 99 | DEVICE_CONTROL_EVENT_DDR_TEST_COMPLETED, |
| 100 | DEVICE_CONTROL_EVENT_DDR_TEST_TIMEOUT, |
| 101 | |
| 102 | DEVICE_CONTROL_EVENT__NUM_OF, |
| 103 | DEVICE_CONTROL_EVENT_NO_EVENT = DEVICE_CONTROL_EVENT__NUM_OF |
| 104 | } dev_ctrl_event; |
| 105 | |
| 106 | typedef enum |
| 107 | { |
| 108 | DEV_CTRL_CONNECTING_STATE_ESTABLISHING, /* writing software via FLD, waiting for "connection established" */ |
| 109 | DEV_CTRL_CONNECTING_STATE_CONFIGURING, /* connection established, cfg sent, waiting for "device ready" */ |
| 110 | DEV_CTRL_CONNECTING_STATE_STANDALONE, /* connecting to a standalone device, waiting for "device ready" */ |
| 111 | } dev_ctrl_connecting_state; |
| 112 | |
| 113 | typedef struct |
| 114 | { |
| 115 | char name[MAX_TASK_NAME_SIZE]; |
| 116 | bcmos_task task; |
| 117 | } dev_ctrl_task; |
| 118 | |
| 119 | typedef struct |
| 120 | { |
| 121 | char name[MAX_MODULE_NAME_SIZE]; |
| 122 | bcmos_module_id module_id; |
| 123 | } dev_ctrl_module; |
| 124 | |
| 125 | typedef struct |
| 126 | { |
| 127 | char name[MAX_TIMER_NAME_SIZE]; |
| 128 | bcmos_timer timer; |
| 129 | } dev_ctrl_timer; |
| 130 | |
| 131 | typedef struct |
| 132 | { |
| 133 | uint32_t pcie_addr; |
| 134 | } dev_ctrl_pcie; |
| 135 | |
| 136 | typedef struct |
| 137 | { |
| 138 | dev_ctrl_connecting_state state; |
| 139 | uint32_t config_send_counter; |
| 140 | uint32_t config_interval; |
| 141 | dev_ctrl_timer timer; |
| 142 | } dev_ctrl_connection; |
| 143 | |
| 144 | typedef struct |
| 145 | { |
| 146 | uint32_t polling_counter; |
| 147 | uint32_t polling_interval; |
| 148 | dev_ctrl_timer timer; |
| 149 | } dev_ctrl_boot_seq; |
| 150 | |
| 151 | typedef struct |
| 152 | { |
| 153 | dev_ctrl_task task_info; |
| 154 | dev_ctrl_module module_info; |
| 155 | dev_ctrl_connection connection_info; |
| 156 | dev_ctrl_pcie pcie_info; |
| 157 | bcmos_keep_alive_info ka_info; |
| 158 | dev_ctrl_boot_seq boot_seq_info; |
| 159 | bcm_fld_device_info fld_info; |
| 160 | bcmolt_device_cfg_data device_params; |
| 161 | bcmolt_presence_mask device_params_present; |
| 162 | dev_ctrl_timer exception_monitor_timer; |
| 163 | uint16_t corr_tag; |
| 164 | bcmolt_msg * last_message; |
| 165 | dev_ctrl_timer device_response_timer; |
| 166 | dev_ctrl_timer reset_delay_timer; |
| 167 | bcmos_bool is_host_reset_pending; |
| 168 | #ifdef ENABLE_LOG |
| 169 | uint32_t sram_log_offset; |
| 170 | uint32_t msgs_read; |
| 171 | #endif |
| 172 | bcmolt_control_state enable_tod; |
| 173 | #ifndef SIMULATION_BUILD |
| 174 | uint32_t trx_disable_mask; |
| 175 | #endif |
| 176 | dev_ctrl_event last_event; |
| 177 | bcmolt_host_connection_fail_reason conn_fail_reason; |
| 178 | uint32_t sw_error_count; |
| 179 | bcmolt_sw_error sw_errors[30]; |
| 180 | dev_log_id log_id; |
| 181 | } dev_ctrl_database; |
| 182 | |
| 183 | typedef void (*dev_ctrl_sm_cb)(bcmolt_devid device, const bcmolt_msg *msg); |
| 184 | |
| 185 | #define DEVICE_ID_FROM_MODULE_ID(module_id) ((bcmolt_devid)(module_id - BCMOS_MODULE_ID_DEV_CTRL_DEV0)) |
| 186 | #define MODULE_ID_FROM_DEVICE_ID(device) ((bcmos_module_id)(device + BCMOS_MODULE_ID_DEV_CTRL_DEV0)) |
| 187 | |
| 188 | const char *bcm_str_device_state(bcmolt_device_state device_state); |
| 189 | const char *bcm_str_device_event(dev_ctrl_event device_event); |
| 190 | const char *bcm_str_host_connection_fail_reason(bcmolt_host_connection_fail_reason reason); |
| 191 | const char *bcm_str_host_connecting_state(dev_ctrl_connecting_state state); |
| 192 | void dev_ctrl_read_db(bcmolt_devid device, dev_ctrl_database *db); |
| 193 | |
| 194 | bcmos_errno bcmolt_dev_ctrl_host_event_write(uint32_t device, uint32_t event); |
| 195 | |
| 196 | /*Use different function signatures linux kernel device control and other*/ |
| 197 | #if !defined(LINUX_USER_SPACE) |
| 198 | bcmos_errno bcmolt_dev_ctrl_init(bcmolt_dev_ctrl_params *params); |
| 199 | #else |
| 200 | bcmos_errno bcmolt_dev_ctrl_init(void); |
| 201 | #endif |
| 202 | |
| 203 | void bcmolt_dev_ctrl_exit(void); |
| 204 | |
| 205 | #endif |