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_INTERFACE_H_ |
| 31 | #define BCMTR_INTERFACE_H_ |
| 32 | |
| 33 | #include <bcmos_system.h> |
| 34 | #include <bcmolt_model_types.h> |
| 35 | |
| 36 | #ifdef __cplusplus |
| 37 | extern "C" { |
| 38 | #endif |
| 39 | |
| 40 | /** Transport statistics */ |
| 41 | typedef struct bcmtr_stat |
| 42 | { |
| 43 | uint32_t msg_sent; /**< Messages sent */ |
| 44 | uint32_t msg_resp_received; /**< Valid responses received */ |
| 45 | uint32_t msg_req_auto_received; /**< Request or Autonomous message received */ |
| 46 | uint32_t msg_req_timeout; /**< Number of requests that timed out */ |
| 47 | uint32_t msg_reass_timeout; /**< Number of messages discarded due to reassemble timeout */ |
| 48 | uint32_t msg_no_req; /**< Number of responses discarded because there was no matching request */ |
| 49 | uint32_t msg_no_mem; /**< Number of memory allocation failures */ |
| 50 | uint32_t msg_comm_err; /**< Messages discarded because of communication error */ |
| 51 | uint32_t msg_ready_timeout; /**< Responses that have been reported to application but not peaked up */ |
| 52 | uint32_t msg_too_many_req; /**< Number of requests discarded because there were too many outstanding requests */ |
| 53 | uint32_t msg_too_many_auto; /**< Number of autonomous messages discarded because there were too many being reassembled */ |
| 54 | uint32_t not_connected; /**< Number of TX messages discarded because connection was lost */ |
| 55 | uint32_t frag_received; /**< Valid fragments received */ |
| 56 | uint32_t frag_invalid; /**< Fragments discarded */ |
| 57 | uint32_t pack_errors; /**< Message pack errors */ |
| 58 | uint32_t unpack_errors; /**< Message unpack errors */ |
| 59 | uint32_t no_rx_handler; /**< Message discarded because there was no rx handler */ |
| 60 | } bcmtr_stat; |
| 61 | |
| 62 | /** Transport message control block */ |
| 63 | typedef struct bcmtr_msg bcmtr_msg; |
| 64 | |
| 65 | /** Channel id */ |
| 66 | typedef uint8_t bcmtr_channel_id; |
| 67 | |
| 68 | /** Send flags */ |
| 69 | typedef enum |
| 70 | { |
| 71 | BCMTR_SEND_FLAGS_NONE = 0, /**< None */ |
| 72 | BCMTR_SEND_FLAGS_CALL = 0x0001, /**< Request/Response sequence */ |
| 73 | |
| 74 | BCMTR_SEND_FLAGS_PRI_NORMAL = 0, /**< Normal priority */ |
| 75 | BCMTR_SEND_FLAGS_PRI_HI = 0x0010, /**< High priority */ |
| 76 | |
| 77 | BCMTR_SEND_FLAGS_LONG_WAIT = 0x0100, /**< Enable long wait until there is room in tx queue */ |
| 78 | BCMTR_SEND_FLAGS_SHORT_WAIT = 0x0200, /**< Enable short wait until there is room in tx queue */ |
| 79 | BCMTR_SEND_FLAGS_DO_NOT_WAIT = 0x0400, /**< Drop packet if TX q is full */ |
| 80 | |
| 81 | } bcmtr_send_flags; |
| 82 | |
| 83 | #define BCMTR_SEND_FLAGS_WAIT_MASK (BCMTR_SEND_FLAGS_LONG_WAIT | BCMTR_SEND_FLAGS_SHORT_WAIT | BCMTR_SEND_FLAGS_DO_NOT_WAIT) |
| 84 | |
| 85 | /** Transport handler registration parameters */ |
| 86 | typedef struct bcmtr_handler_parm |
| 87 | { |
| 88 | uint8_t instance; /**< Instance (i.e, link) */ |
| 89 | bcmolt_mgt_group group; /**< Message group */ |
| 90 | bcmolt_obj_id object; /**< Object. Can be BCMOLT_OBJECT_ANY */ |
| 91 | uint16_t subgroup; /**< Message subgroup. Can be BCMOLT_SUBGROUP_ANY */ |
| 92 | f_bcmolt_msg_handler app_cb;/**< Message handler */ |
| 93 | bcmolt_auto_flags flags; /**< Flags. app_cb is called in context of transport task |
| 94 | or app module, depending on the flags */ |
| 95 | bcmos_module_id module; /**< Target module id. Relevant only if flags == BCMOLT_AUTO_FLAGS_DISPATCH. |
| 96 | BCMOS_MODULE_ID_NONE is replaced by the module calling registration function */ |
| 97 | } bcmtr_handler_parm; |
| 98 | |
| 99 | /** Initialize transport library. |
| 100 | * \returns BCM_ERR_OK or error code |
| 101 | */ |
| 102 | bcmos_errno bcmtr_init(void); |
| 103 | |
| 104 | /** Release resources used by transport library. |
| 105 | * \returns BCM_ERR_OK or error code |
| 106 | */ |
| 107 | bcmos_errno bcmtr_exit(void); |
| 108 | |
| 109 | /** Send message. Do not wait for response |
| 110 | * |
| 111 | * Set-up connection if necessary, pack message and send it to the remote side. |
| 112 | * This function is intended for proxy and autonomous messages. |
| 113 | * |
| 114 | * \param[in] device OLT device index |
| 115 | * \param[in] msg Application message to be sent |
| 116 | * \param[in] flags flags (request/auto or reply) |
| 117 | * |
| 118 | * \returns BCM_ERR_OK or error code |
| 119 | */ |
| 120 | bcmos_errno bcmtr_send(bcmolt_devid device, bcmolt_msg *msg, bcmtr_send_flags flags); |
| 121 | |
| 122 | /** Send response message |
| 123 | * |
| 124 | * Set-up connection if necessary, pack message and send it to the remote side. |
| 125 | * This function is intended for proxy and autonomous messages. |
| 126 | * |
| 127 | * \param[in] device OLT device index |
| 128 | * \param[in] msg Application message to be sent |
| 129 | * \param[in] flags flags (request/auto or reply) |
| 130 | * |
| 131 | * \returns BCM_ERR_OK or error code |
| 132 | */ |
| 133 | static inline bcmos_errno bcmtr_send_response(bcmolt_devid device, bcmolt_msg *msg) |
| 134 | { |
| 135 | msg->dir = BCMOLT_MSG_DIR_RESPONSE; |
| 136 | return bcmtr_send(device, msg, BCMTR_SEND_FLAGS_CALL | BCMTR_SEND_FLAGS_SHORT_WAIT); |
| 137 | } |
| 138 | |
| 139 | /** Send request and wait for reply |
| 140 | * |
| 141 | * Set-up connection if necessary, pack message and send it to the remote side. |
| 142 | * Wait for reply or timeout, unpack the reply and return. |
| 143 | * |
| 144 | * \param[in] device OLT device index |
| 145 | * \param[in, out] msg Application message |
| 146 | * \returns BCM_ERR_OK or error code |
| 147 | */ |
| 148 | bcmos_errno bcmtr_call(bcmolt_devid device, bcmolt_msg *msg); |
| 149 | |
| 150 | /** Register message handler |
| 151 | * |
| 152 | * \param[in] device OLT device index |
| 153 | * \param[in] parm Registration parameters |
| 154 | * \returns BCM_ERR_OK or error code |
| 155 | */ |
| 156 | bcmos_errno bcmtr_msg_handler_register(bcmolt_devid device, const bcmtr_handler_parm *parm); |
| 157 | |
| 158 | /** Unregister message handler |
| 159 | * |
| 160 | * \param[in] device OLT device index |
| 161 | * \param[in] parm Registration parameters |
| 162 | * \returns BCM_ERR_OK or error code |
| 163 | */ |
| 164 | bcmos_errno bcmtr_msg_handler_unregister(bcmolt_devid device, const bcmtr_handler_parm *parm); |
| 165 | |
| 166 | /** Get registration info |
| 167 | * |
| 168 | * \param[in] device OLT device index |
| 169 | * \param[in,out] parm Registration parameters. |
| 170 | * instance, group, object, subgroup must be set |
| 171 | * \returns BCM_ERR_OK or error code |
| 172 | */ |
| 173 | bcmos_errno bcmtr_msg_handler_register_get(bcmolt_devid device, bcmtr_handler_parm *parm); |
| 174 | |
| 175 | /** Get transport statistics |
| 176 | * |
| 177 | * \param[in] device OLT device index |
| 178 | * \param[out] stat Statistics |
| 179 | * \returns BCM_ERR_OK or error code |
| 180 | */ |
| 181 | bcmos_errno bcmtr_stat_get(bcmolt_devid device, bcmtr_stat *stat); |
| 182 | |
| 183 | /* Query whether or not the device is currently connected */ |
| 184 | bcmos_errno bcmtr_is_connected(bcmolt_devid device, bcmos_bool *is_connected); |
| 185 | |
| 186 | /* Connect device */ |
| 187 | bcmos_errno bcmtr_connect(bcmolt_devid device); |
| 188 | |
| 189 | /* Disconnect device */ |
| 190 | bcmos_errno bcmtr_disconnect(bcmolt_devid device); |
| 191 | |
| 192 | /* Low-level disconnect that breaks "physical" connection, but doesn't destroy connection structure and registrations */ |
| 193 | bcmos_errno bcmtr_driver_disconnect(bcmolt_devid device); |
| 194 | |
| 195 | /* Repair/reconnect the driver-level connection for an already-connected device */ |
| 196 | bcmos_errno bcmtr_driver_reconnect(bcmolt_devid device); |
| 197 | |
| 198 | /* "dropped because of tx_queue overflow" indication */ |
| 199 | typedef void (*F_bcmtr_tx_overflow)(bcmolt_devid device, bcmtr_send_flags send_flags); |
| 200 | |
| 201 | /* Register for notification that transmit failed because |
| 202 | * tx_queue was full |
| 203 | * \param[in] device OLT device index |
| 204 | * \param[in] cb Callback to be called. NULL=unregister |
| 205 | * \returns 0=OK or error code < 0 |
| 206 | */ |
| 207 | bcmos_errno bcmtr_tx_overflow_cb_register(bcmolt_devid device, F_bcmtr_tx_overflow cb); |
| 208 | |
| 209 | /* |
| 210 | * The following functions are useful for proxy daemon. |
| 211 | * They provide direct interface to transport plugin |
| 212 | */ |
| 213 | |
| 214 | /* Connect device in raw mode |
| 215 | * Receive task is NOT created |
| 216 | * \param[in] device OLT device index |
| 217 | * \parm[out] headroom Headroom that should be reserved in buffer when transmitting |
| 218 | * \returns 0=OK or error code < 0 |
| 219 | */ |
| 220 | bcmos_errno bcmtr_proxy_connect(bcmolt_devid device, uint32_t *headroom); |
| 221 | |
| 222 | /* Send data to device |
| 223 | * \param[in] device OLT device index |
| 224 | * \param[in] txb Transmit buffer |
| 225 | * \returns 0=OK or error code < 0 |
| 226 | */ |
| 227 | bcmos_errno bcmtr_proxy_send(bcmolt_devid device, bcmolt_buf *tx_buf); |
| 228 | |
| 229 | /* Receive data from device |
| 230 | * \param[in] device OLT device index |
| 231 | * \param[in] rxb Receive buffer |
| 232 | * \returns 0=OK, BCM_ERR_TIMEOUT-timeout and no message, other errors <0 |
| 233 | */ |
| 234 | bcmos_errno bcmtr_proxy_receive(bcmolt_devid device, bcmolt_buf *rx_buf); |
| 235 | |
| 236 | |
| 237 | #ifdef __cplusplus |
| 238 | } |
| 239 | #endif |
| 240 | |
| 241 | #endif /* BCMTR_INTERFACE_H_ */ |