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 BCMTR_INTERNAL_H_ |
| 31 | #define BCMTR_INTERNAL_H_ |
| 32 | |
| 33 | #include <bcmos_system.h> |
| 34 | #include <bcmolt_buf.h> |
| 35 | #include <bcmolt_msg_pack.h> |
| 36 | #include <bcmtr_interface.h> |
| 37 | #include <bcmtr_plugin.h> |
| 38 | #include <bcm_config.h> |
| 39 | |
| 40 | #include "bcmtr_header.h" |
| 41 | |
| 42 | /** Transport configuration parameters */ |
| 43 | typedef struct |
| 44 | { |
| 45 | bcmtr_plugin_cfg plugin_cfg; /**< Transport plugin configuration parameters */ |
| 46 | |
| 47 | /** Limits and timeouts. |
| 48 | * If not set, the appropriate BCM_TR_default defined in bcmConfig.h is used |
| 49 | */ |
| 50 | uint32_t max_retries; /**< Max number of request retransmissions */ |
| 51 | uint32_t msg_timeout; /**< Max time to wait for response or next message part (ms) */ |
| 52 | uint32_t max_requests; /**< Max number of outstanding requests */ |
| 53 | uint32_t max_autos; /**< Max number of multi-part autonomous messages */ |
| 54 | uint32_t max_fragments; /**< Max number of multi-part message fragments */ |
| 55 | uint32_t msg_wait_timeout; /**< Message waiting timeout (ms) */ |
| 56 | uint32_t msg_ready_timeout; /**< Time that transaction is kept after notifying application that it finished (ms) */ |
| 57 | uint32_t max_mtu; /**< Max MTU size (bytes) */ |
| 58 | |
| 59 | int rx_thread_priority; /**< Receive thread priority. If set -1, Rx thread is NOT created */ |
| 60 | } bcmtr_cfg; |
| 61 | |
| 62 | /** Transport connection control block */ |
| 63 | typedef struct bcmtr_conn bcmtr_conn; |
| 64 | |
| 65 | /** Reassemble block */ |
| 66 | typedef struct bcmtr_reass |
| 67 | { |
| 68 | bcmolt_buf *fragments; /** Array of bcmtr_cfg.max_fragments */ |
| 69 | uint32_t num_fragments; /** Number of fragments filled in fragments array */ |
| 70 | uint32_t max_fragment; /** Max fragment number. Set when last fragment is received */ |
| 71 | uint32_t total_size; /** Total size of received fragments */ |
| 72 | } bcmtr_reass; |
| 73 | |
| 74 | /** Transport header list head */ |
| 75 | typedef TAILQ_HEAD(bcmtr_msg_list, bcmtr_msg) bcmtr_msg_list; |
| 76 | |
| 77 | /** Transport transaction control block */ |
| 78 | struct bcmtr_msg |
| 79 | { |
| 80 | bcmolt_buf tx_buf; /**< Transmit buffer info (request only) */ |
| 81 | bcmolt_buf rx_buf; /**< Receive buffer info (response or autonomous) */ |
| 82 | uint32_t timestamp; /**< Message timestamp. Tx or last Rx */ |
| 83 | uint16_t tx_count; /**< Number of times message was transmitted */ |
| 84 | bcmtr_hdr hdr; /**< Transport header */ |
| 85 | TAILQ_ENTRY(bcmtr_msg) l; /**< Transport message list entry */ |
| 86 | bcmtr_reass *segm; /**< Segmentation block */ |
| 87 | bcmtr_reass *reass; /**< Reassemble block */ |
| 88 | bcmolt_msg *msg; /**< Message reference */ |
| 89 | bcmolt_subchannel subch; /**< Sub-channel via which message was received */ |
| 90 | bcmos_errno err; /**< Transport status */ |
| 91 | |
| 92 | /* Transport header is cleared up to this point when released. |
| 93 | * "err" field is the last in the section that gets cleared. |
| 94 | * Do not move fields below above "err"! |
| 95 | */ |
| 96 | #define BCMTR_HDR_CLEAR_SIZE (offsetof(bcmtr_msg, err) + sizeof(bcmos_errno)) |
| 97 | bcmtr_msg_list *free_list; /**< Free list head reference */ |
| 98 | bcmtr_conn *conn; /**< Connection back reference */ |
| 99 | bcmos_sem sem; /**< "wait for response" semaphore */ |
| 100 | bcmos_msg ipc_hdr; /**< IPC message header */ |
| 101 | }; |
| 102 | |
| 103 | /** Message handler context */ |
| 104 | typedef struct bcmtr_handler |
| 105 | { |
| 106 | f_bcmolt_msg_handler app_cb; /**< Application callback function */ |
| 107 | bcmolt_auto_flags flags; /**< Registration flag: call in context of transport rx thread or app module */ |
| 108 | bcmos_module_id module; /**< Optional module to dispatch received message to */ |
| 109 | } bcmtr_handler; |
| 110 | |
| 111 | /** Transport connection control block */ |
| 112 | struct bcmtr_conn |
| 113 | { |
| 114 | char name[16]; /**< Transport name */ |
| 115 | bcmolt_devid device; /**< Device index */ |
| 116 | bcmtr_channel_id channel; /**< Channels served by this transport */ |
| 117 | bcmtr_cfg cfg; /**< Transport configuration parameters */ |
| 118 | bcmtr_driver driver; /**< Transport driver */ |
| 119 | bcmtr_plugin_channel drv_priv; /**< Plugin driver private data */ |
| 120 | bcmos_task rx_thread; /**< RX thread handle */ |
| 121 | bcmos_mutex mutex; /**< Mutex protecting the transport structure */ |
| 122 | uint32_t last_timeout_check; /**< Last timeout check timestamp */ |
| 123 | uint32_t timeout_check_period; /**< Time-out check period */ |
| 124 | bcmtr_msg_list msg_list; /**< Message list head */ |
| 125 | bcmtr_msg_list free_req_list; /**< Free request block list */ |
| 126 | bcmtr_msg_list free_auto_list; /**< Free autonomous block list */ |
| 127 | bcmtr_msg *tmsg_array; /**< Pre-allocated array of transport headers */ |
| 128 | bcmtr_stat stat; /**< Statistics */ |
| 129 | bcmos_bool connected; /**< Transport state */ |
| 130 | uint16_t num_requests; /**< Number of outstanding requests */ |
| 131 | uint16_t num_auto; /**< Number of autonomous messages being reassembled */ |
| 132 | uint16_t corr_tag; /**< Last used correlation tag */ |
| 133 | bcmos_bool rx_thread_created; /**< TRUE=RX thread was created */ |
| 134 | int kill_request; /**< Transport thread is commanded to die */ |
| 135 | int kill_done; /**< Transport thread is dead */ |
| 136 | }; |
| 137 | |
| 138 | |
| 139 | #ifdef __cplusplus |
| 140 | extern "C" { |
| 141 | #endif |
| 142 | |
| 143 | bcmos_errno bcmtr_cfg_get(bcmolt_devid device, bcmtr_cfg *cfg, bcmtr_driver *driver); |
| 144 | |
| 145 | bcmos_errno _bcmtr_conn_get(bcmolt_devid device, bcmtr_conn **conn); |
| 146 | |
| 147 | #ifdef __cplusplus |
| 148 | } |
| 149 | #endif |
| 150 | |
| 151 | #endif /* BCMTR_INTERNAL_H_ */ |