Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2015, The Linux Foundation. All rights reserved. |
| 2 | |
| 3 | Redistribution and use in source and binary forms, with or without |
| 4 | modification, are permitted provided that the following conditions are |
| 5 | met: |
| 6 | * Redistributions of source code must retain the above copyright |
| 7 | notice, this list of conditions and the following disclaimer. |
| 8 | * Redistributions in binary form must reproduce the above |
| 9 | copyright notice, this list of conditions and the following |
| 10 | disclaimer in the documentation and/or other materials provided |
| 11 | with the distribution. |
| 12 | * Neither the name of The Linux Foundation nor the names of its |
| 13 | contributors may be used to endorse or promote products derived |
| 14 | from this software without specific prior written permission. |
| 15 | |
| 16 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 17 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 19 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 20 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 23 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 25 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 26 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | |
| 30 | /*=========================================================================== |
| 31 | INCLUDE FILES |
| 32 | ===========================================================================*/ |
| 33 | #include <glink.h> |
Steven Cahail | 8f9eb17 | 2015-08-21 10:20:08 -0600 | [diff] [blame] | 34 | #include <glink_rpm.h> |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 35 | #include <glink_os_utils.h> |
| 36 | #include <glink_internal.h> |
| 37 | #include <glink_vector.h> |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 38 | |
| 39 | #ifdef FEATURE_TRACER_PACKET |
| 40 | #include "glink_tracer.h" |
| 41 | #endif |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 42 | |
| 43 | #define GLINK_NOT_INITIALIZED 0 |
| 44 | #define GLINK_INITIALIZED 1 |
| 45 | |
| 46 | /*=========================================================================== |
Sridhar Parasuram | 3b05812 | 2015-05-11 16:15:03 -0700 | [diff] [blame] | 47 | GLOBAL DATA DECLARATIONS |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 48 | ===========================================================================*/ |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 49 | /*=========================================================================== |
| 50 | LOCAL FUNCTION DEFINITIONS |
| 51 | ===========================================================================*/ |
Sridhar Parasuram | 3b05812 | 2015-05-11 16:15:03 -0700 | [diff] [blame] | 52 | |
| 53 | /** Default implementation of optional callbacks */ |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 54 | static void glink_default_notify_rx_sigs |
| 55 | ( |
| 56 | glink_handle_type handle, |
| 57 | const void *priv, |
| 58 | uint32 prev, |
| 59 | uint32 curr |
| 60 | ) |
| 61 | { |
Steven Cahail | a136c10 | 2015-08-21 13:29:10 -0600 | [diff] [blame] | 62 | GLINK_OS_UNREFERENCED_PARAM( handle ); |
| 63 | GLINK_OS_UNREFERENCED_PARAM( priv ); |
| 64 | GLINK_OS_UNREFERENCED_PARAM( prev ); |
| 65 | GLINK_OS_UNREFERENCED_PARAM( curr ); |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 66 | return; |
| 67 | } |
| 68 | |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 69 | /*=========================================================================== |
| 70 | EXTERNAL FUNCTION DEFINITIONS |
| 71 | ===========================================================================*/ |
Steven Cahail | e41e9a0 | 2015-08-20 11:10:16 -0600 | [diff] [blame] | 72 | |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 73 | /** |
| 74 | * Opens a logical GLink based on the specified config params |
| 75 | * |
| 76 | * @param[in] cfg_ptr Pointer to the configuration structure for the |
| 77 | * GLink. See glink.h |
| 78 | * @param[out] handle GLink handle associated with the logical channel |
| 79 | * |
| 80 | * @return Standard GLink error codes |
| 81 | * |
| 82 | * @sideeffects Allocates channel resources and informs remote host about |
| 83 | * channel open. |
| 84 | */ |
| 85 | glink_err_type glink_open |
| 86 | ( |
| 87 | glink_open_config_type *cfg_ptr, |
| 88 | glink_handle_type *handle |
| 89 | ) |
| 90 | { |
Steven Cahail | e41e9a0 | 2015-08-20 11:10:16 -0600 | [diff] [blame] | 91 | glink_transport_if_type *if_ptr; |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 92 | glink_channel_ctx_type *ch_ctx; |
| 93 | unsigned int remote_host; |
Steven Cahail | e41e9a0 | 2015-08-20 11:10:16 -0600 | [diff] [blame] | 94 | glink_xport_priority suggested_priority; |
| 95 | glink_channel_ctx_type *allocated_ch_ctx; |
| 96 | glink_err_type status; |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 97 | |
| 98 | /* Param validation */ |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 99 | if(cfg_ptr == NULL || |
| 100 | cfg_ptr->remote_ss == NULL || |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 101 | cfg_ptr->name == NULL || |
| 102 | cfg_ptr->notify_state == NULL) |
| 103 | { |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 104 | GLINK_LOG_ERROR_EVENT( GLINK_EVENT_CH_OPEN, "", "", "", |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 105 | GLINK_STATUS_INVALID_PARAM); |
| 106 | return GLINK_STATUS_INVALID_PARAM; |
| 107 | } |
| 108 | |
| 109 | /* Evaluate the equivalent edge name->enum for future use */ |
| 110 | remote_host = glinki_find_remote_host(cfg_ptr->remote_ss); |
| 111 | |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 112 | if (remote_host == GLINK_NUM_HOSTS) |
| 113 | { |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 114 | /* Unknown transport name trying to register with GLink */ |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 115 | GLINK_LOG_ERROR_EVENT( GLINK_EVENT_REGISTER_XPORT, |
| 116 | cfg_ptr->name, "", |
| 117 | cfg_ptr->remote_ss, |
| 118 | GLINK_STATUS_INVALID_PARAM ); |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 119 | |
| 120 | return GLINK_STATUS_INVALID_PARAM; |
| 121 | } |
| 122 | |
| 123 | /* Allocate and initialize channel info structure */ |
| 124 | ch_ctx = glink_os_calloc(sizeof(glink_channel_ctx_type)); |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 125 | if(ch_ctx == NULL) |
| 126 | { |
| 127 | GLINK_LOG_ERROR_EVENT( GLINK_EVENT_CH_OPEN, |
| 128 | cfg_ptr->name, "", "", |
| 129 | GLINK_STATUS_OUT_OF_RESOURCES ); |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 130 | return GLINK_STATUS_OUT_OF_RESOURCES; |
| 131 | } |
| 132 | |
| 133 | /* Fill in the channel info structure */ |
| 134 | glink_os_string_copy(ch_ctx->name, cfg_ptr->name, sizeof(ch_ctx->name)); |
| 135 | ch_ctx->priv = cfg_ptr->priv; |
| 136 | ch_ctx->notify_rx = cfg_ptr->notify_rx; |
| 137 | ch_ctx->notify_rxv = cfg_ptr->notify_rxv; |
| 138 | ch_ctx->notify_tx_done = cfg_ptr->notify_tx_done; |
| 139 | ch_ctx->notify_state = cfg_ptr->notify_state; |
| 140 | ch_ctx->notify_rx_intent_req = cfg_ptr->notify_rx_intent_req; |
| 141 | ch_ctx->notify_rx_intent = cfg_ptr->notify_rx_intent; |
| 142 | ch_ctx->notify_rx_sigs = cfg_ptr->notify_rx_sigs; |
| 143 | ch_ctx->ch_open_options = cfg_ptr->options; |
| 144 | ch_ctx->notify_rx_abort = cfg_ptr->notify_rx_abort; |
| 145 | ch_ctx->notify_tx_abort = cfg_ptr->notify_tx_abort; |
| 146 | |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 147 | if (ch_ctx->notify_rx_sigs == NULL) |
| 148 | { |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 149 | /* set default callback */ |
| 150 | ch_ctx->notify_rx_sigs = glink_default_notify_rx_sigs; |
| 151 | } |
| 152 | |
Steven Cahail | e41e9a0 | 2015-08-20 11:10:16 -0600 | [diff] [blame] | 153 | if_ptr = glinki_find_requested_xport( cfg_ptr->transport, |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 154 | cfg_ptr->remote_ss, |
Steven Cahail | e41e9a0 | 2015-08-20 11:10:16 -0600 | [diff] [blame] | 155 | cfg_ptr->options, |
| 156 | &suggested_priority ); |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 157 | |
Steven Cahail | e41e9a0 | 2015-08-20 11:10:16 -0600 | [diff] [blame] | 158 | if( !if_ptr ) |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 159 | { |
Steven Cahail | e41e9a0 | 2015-08-20 11:10:16 -0600 | [diff] [blame] | 160 | /* Code gets here if we are not able to find reqeusted transport */ |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 161 | GLINK_LOG_ERROR_EVENT( GLINK_EVENT_CH_OPEN, |
Steven Cahail | e41e9a0 | 2015-08-20 11:10:16 -0600 | [diff] [blame] | 162 | cfg_ptr->name, |
| 163 | cfg_ptr->transport, |
| 164 | cfg_ptr->remote_ss, |
| 165 | GLINK_STATUS_NO_TRANSPORT ); |
| 166 | glink_os_free(ch_ctx); |
| 167 | return GLINK_STATUS_NO_TRANSPORT; |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 168 | } |
Steven Cahail | e41e9a0 | 2015-08-20 11:10:16 -0600 | [diff] [blame] | 169 | |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 170 | status = glinki_add_ch_to_xport( if_ptr, |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 171 | ch_ctx, |
| 172 | &allocated_ch_ctx, |
| 173 | TRUE, |
Steven Cahail | e41e9a0 | 2015-08-20 11:10:16 -0600 | [diff] [blame] | 174 | suggested_priority ); |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 175 | |
Sridhar Parasuram | 3b05812 | 2015-05-11 16:15:03 -0700 | [diff] [blame] | 176 | if( status == GLINK_STATUS_SUCCESS ) |
| 177 | { |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 178 | /* Set the handle and return */ |
| 179 | *handle = allocated_ch_ctx; |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 180 | GLINK_LOG_EVENT( *handle, |
| 181 | GLINK_EVENT_CH_OPEN, |
| 182 | cfg_ptr->name, |
| 183 | cfg_ptr->transport, |
| 184 | cfg_ptr->remote_ss, |
| 185 | status ); |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 186 | } |
Sridhar Parasuram | 3b05812 | 2015-05-11 16:15:03 -0700 | [diff] [blame] | 187 | else |
| 188 | { |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 189 | *handle = NULL; |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 190 | GLINK_LOG_ERROR_EVENT( GLINK_EVENT_CH_OPEN, |
Steven Cahail | e41e9a0 | 2015-08-20 11:10:16 -0600 | [diff] [blame] | 191 | cfg_ptr->name, |
| 192 | cfg_ptr->transport, |
| 193 | cfg_ptr->remote_ss, |
| 194 | status ); |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 198 | |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 199 | return status; |
| 200 | } |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 201 | |
| 202 | /** |
| 203 | * Closes the GLink logical channel specified by the handle. |
| 204 | * |
| 205 | * @param[in] handle GLink handle associated with the logical channel |
| 206 | * |
| 207 | * @return Standard GLink error codes |
| 208 | * |
| 209 | * @sideeffects Closes local end of the channel and informs remote host |
| 210 | */ |
| 211 | glink_err_type glink_close |
| 212 | ( |
| 213 | glink_handle_type handle |
| 214 | ) |
| 215 | { |
| 216 | glink_err_type status; |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 217 | glink_core_xport_ctx_type *xport_ctx; |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 218 | |
Sridhar Parasuram | 3b05812 | 2015-05-11 16:15:03 -0700 | [diff] [blame] | 219 | if(handle == NULL) |
| 220 | { |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 221 | GLINK_LOG_ERROR_EVENT( GLINK_EVENT_CH_CLOSE, "", "", "", |
| 222 | GLINK_STATUS_INVALID_PARAM ); |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 223 | return GLINK_STATUS_INVALID_PARAM; |
| 224 | } |
| 225 | |
Steven Cahail | 895a0da | 2015-08-24 15:26:37 -0600 | [diff] [blame] | 226 | /* get xport context after NULL check */ |
| 227 | xport_ctx = handle->if_ptr->glink_core_priv; |
| 228 | |
| 229 | ASSERT( xport_ctx != NULL ); |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 230 | |
Sridhar Parasuram | 3b05812 | 2015-05-11 16:15:03 -0700 | [diff] [blame] | 231 | /* grab lock to change/check channel state atomically */ |
Steven Cahail | ef08a38 | 2015-08-24 17:11:51 -0600 | [diff] [blame] | 232 | glink_os_cs_acquire( &xport_ctx->channel_q_cs ); |
Sridhar Parasuram | 3b05812 | 2015-05-11 16:15:03 -0700 | [diff] [blame] | 233 | |
| 234 | /* Check to see if closed called again for same channel */ |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 235 | if (handle->local_state != GLINK_LOCAL_CH_OPENED && |
| 236 | handle->local_state != GLINK_LOCAL_CH_OPENING) |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 237 | { |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 238 | GLINK_LOG_ERROR_EVENT( GLINK_EVENT_CH_CLOSE, |
| 239 | handle->name, |
| 240 | xport_ctx->xport, |
| 241 | xport_ctx->remote_ss, |
| 242 | handle->local_state ); |
Sridhar Parasuram | 3b05812 | 2015-05-11 16:15:03 -0700 | [diff] [blame] | 243 | |
Steven Cahail | ef08a38 | 2015-08-24 17:11:51 -0600 | [diff] [blame] | 244 | glink_os_cs_release(&xport_ctx->channel_q_cs); |
Sridhar Parasuram | 3b05812 | 2015-05-11 16:15:03 -0700 | [diff] [blame] | 245 | |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 246 | return GLINK_STATUS_CH_ALREADY_CLOSED; |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 247 | } |
| 248 | |
Sridhar Parasuram | 3b05812 | 2015-05-11 16:15:03 -0700 | [diff] [blame] | 249 | handle->local_state = GLINK_LOCAL_CH_CLOSING; |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 250 | |
Steven Cahail | 895a0da | 2015-08-24 15:26:37 -0600 | [diff] [blame] | 251 | if (handle->remote_state == GLINK_REMOTE_CH_SSR_RESET || |
| 252 | glinki_xport_linkup(handle->if_ptr) == FALSE) |
Sridhar Parasuram | 3b05812 | 2015-05-11 16:15:03 -0700 | [diff] [blame] | 253 | { |
Steven Cahail | 895a0da | 2015-08-24 15:26:37 -0600 | [diff] [blame] | 254 | /* SSR happened on remote-SS OR XPORT link is down. Fake close_ack from here */ |
Steven Cahail | ef08a38 | 2015-08-24 17:11:51 -0600 | [diff] [blame] | 255 | glink_os_cs_release( &xport_ctx->channel_q_cs); |
Sridhar Parasuram | 3b05812 | 2015-05-11 16:15:03 -0700 | [diff] [blame] | 256 | |
| 257 | handle->if_ptr->glink_core_if_ptr->rx_cmd_ch_close_ack( handle->if_ptr, |
| 258 | handle->lcid ); |
| 259 | |
| 260 | status = GLINK_STATUS_SUCCESS; |
| 261 | } |
| 262 | else |
| 263 | { |
Steven Cahail | ef08a38 | 2015-08-24 17:11:51 -0600 | [diff] [blame] | 264 | glink_os_cs_release(&xport_ctx->channel_q_cs); |
Sridhar Parasuram | 3b05812 | 2015-05-11 16:15:03 -0700 | [diff] [blame] | 265 | |
| 266 | status = handle->if_ptr->tx_cmd_ch_close(handle->if_ptr, handle->lcid); |
| 267 | |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 268 | GLINK_LOG_EVENT( handle, |
| 269 | GLINK_EVENT_CH_CLOSE, |
| 270 | handle->name, |
| 271 | xport_ctx->xport, |
| 272 | xport_ctx->remote_ss, |
| 273 | status ); |
Sridhar Parasuram | 3b05812 | 2015-05-11 16:15:03 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 276 | return status; |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | /** |
| 280 | * Transmit the provided buffer over GLink. |
| 281 | * |
| 282 | * @param[in] handle GLink handle associated with the logical channel |
| 283 | * |
| 284 | * @param[in] *pkt_priv Per packet private data |
| 285 | * |
| 286 | * @param[in] *data Pointer to the data buffer to be transmitted |
| 287 | * |
| 288 | * @param[in] size Size of buffer |
| 289 | * |
| 290 | * @param[in] req_intent Whether to block and request for remote rx intent in |
| 291 | * case it is not available for this pkt tx |
| 292 | * |
| 293 | * @return Standard GLink error codes |
| 294 | * |
| 295 | * @sideeffects Causes remote host to wake-up and process rx pkt |
| 296 | */ |
| 297 | glink_err_type glink_tx |
| 298 | ( |
| 299 | glink_handle_type handle, |
| 300 | const void *pkt_priv, |
| 301 | const void *data, |
| 302 | size_t size, |
| 303 | uint32 options |
| 304 | ) |
| 305 | { |
| 306 | return glink_txv(handle, pkt_priv, (void*)data, size, |
| 307 | &glink_dummy_tx_vprovider, NULL, options); |
| 308 | |
| 309 | } |
| 310 | |
| 311 | /** |
| 312 | * Transmit the provided vector buffer over GLink. |
| 313 | * |
| 314 | * @param[in] handle GLink handle associated with the logical channel |
| 315 | * |
| 316 | * @param[in] *pkt_priv Per packet private data |
| 317 | * |
| 318 | * @param[in] *iovec Pointer to the vector buffer to be transmitted |
| 319 | * |
| 320 | * @param[in] size Size of buffer |
| 321 | * |
| 322 | * @param[in] vprovider Buffer provider for virtual space |
| 323 | * |
| 324 | * @param[in] pprovider Buffer provider for physical space |
| 325 | * |
| 326 | * @param[in] req_intent Whether to block and request for remote rx intent in |
| 327 | * case it is not available for this pkt tx |
| 328 | * |
| 329 | * @return Standard GLink error codes |
| 330 | * |
| 331 | * @sideeffects Causes remote host to wake-up and process rx pkt |
| 332 | */ |
| 333 | glink_err_type glink_txv |
| 334 | ( |
| 335 | glink_handle_type handle, |
| 336 | const void *pkt_priv, |
| 337 | void *iovec, |
| 338 | size_t size, |
| 339 | glink_buffer_provider_fn vprovider, |
| 340 | glink_buffer_provider_fn pprovider, |
| 341 | uint32 options |
| 342 | ) |
| 343 | { |
| 344 | glink_err_type status; |
Sridhar Parasuram | 3b05812 | 2015-05-11 16:15:03 -0700 | [diff] [blame] | 345 | glink_core_tx_pkt_type *pctx; |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 346 | boolean req_intent = options & GLINK_TX_REQ_INTENT; |
Sridhar Parasuram | 3b05812 | 2015-05-11 16:15:03 -0700 | [diff] [blame] | 347 | |
| 348 | glink_core_xport_ctx_type *xport_ctx; |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 349 | |
| 350 | /* Input validation */ |
| 351 | if(handle == NULL || iovec == NULL || size == 0 || |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 352 | (vprovider == NULL && pprovider == NULL)) |
| 353 | { |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 354 | GLINK_LOG_ERROR_EVENT( GLINK_EVENT_CH_TX, "", "", "", |
| 355 | GLINK_STATUS_INVALID_PARAM ); |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 356 | return GLINK_STATUS_INVALID_PARAM; |
| 357 | } |
| 358 | |
Sridhar Parasuram | 3b05812 | 2015-05-11 16:15:03 -0700 | [diff] [blame] | 359 | xport_ctx = handle->if_ptr->glink_core_priv; |
| 360 | |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 361 | if (!glinki_channel_fully_opened(handle)) |
Sridhar Parasuram | 3b05812 | 2015-05-11 16:15:03 -0700 | [diff] [blame] | 362 | { |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 363 | GLINK_LOG_ERROR_EVENT( GLINK_EVENT_CH_TX, |
Sridhar Parasuram | 3b05812 | 2015-05-11 16:15:03 -0700 | [diff] [blame] | 364 | handle->name, |
| 365 | xport_ctx->xport, |
| 366 | xport_ctx->remote_ss, |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 367 | GLINK_STATUS_CH_NOT_FULLY_OPENED ); |
| 368 | return GLINK_STATUS_CH_NOT_FULLY_OPENED; |
Sridhar Parasuram | 3b05812 | 2015-05-11 16:15:03 -0700 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | pctx = glink_os_calloc( sizeof( glink_core_tx_pkt_type ) ); |
| 372 | |
| 373 | if (pctx == NULL) |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 374 | { |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 375 | GLINK_LOG_ERROR_EVENT( GLINK_EVENT_CH_TX, |
| 376 | handle->name, |
| 377 | xport_ctx->xport, |
| 378 | xport_ctx->remote_ss, |
| 379 | GLINK_STATUS_OUT_OF_RESOURCES ); |
Sridhar Parasuram | 3b05812 | 2015-05-11 16:15:03 -0700 | [diff] [blame] | 380 | return GLINK_STATUS_OUT_OF_RESOURCES; |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | /* Protect the entire tx operation under a lock as a client may call |
| 384 | tx in different thread context */ |
| 385 | glink_os_cs_acquire(&handle->tx_cs); |
| 386 | |
Sridhar Parasuram | 3b05812 | 2015-05-11 16:15:03 -0700 | [diff] [blame] | 387 | pctx->pkt_priv = pkt_priv; |
| 388 | pctx->size = size; |
| 389 | pctx->size_remaining = size; |
| 390 | pctx->vprovider = vprovider; |
| 391 | pctx->pprovider = pprovider; |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 392 | |
| 393 | if (vprovider == &glink_dummy_tx_vprovider) |
| 394 | { |
Sridhar Parasuram | 3b05812 | 2015-05-11 16:15:03 -0700 | [diff] [blame] | 395 | pctx->data = (void*)iovec; |
| 396 | pctx->iovec = pctx; |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 397 | } |
| 398 | else |
| 399 | { |
Sridhar Parasuram | 3b05812 | 2015-05-11 16:15:03 -0700 | [diff] [blame] | 400 | pctx->data = (void*)iovec; |
| 401 | pctx->iovec = iovec; |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 402 | } |
| 403 | |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 404 | #ifdef FEATURE_TRACER_PACKET |
| 405 | pctx->tracer_pkt = options & GLINK_TX_TRACER_PKT ? TRUE : FALSE; |
| 406 | if( pctx->tracer_pkt ) |
| 407 | { |
| 408 | glink_tracer_packet_log_pctx_pkt( pctx, GLINK_CORE_TX ); |
| 409 | } |
| 410 | #endif |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 411 | |
Sridhar Parasuram | 3b05812 | 2015-05-11 16:15:03 -0700 | [diff] [blame] | 412 | status = xport_ctx->channel_submit_pkt(handle, pctx, req_intent); |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 413 | |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 414 | /*Update the channel stats*/ |
| 415 | GLINK_UPDATE_CHANNEL_STATS( handle->ch_stats, tx_request, size); |
| 416 | |
| 417 | GLINK_LOG_EVENT( handle, |
| 418 | GLINK_EVENT_CH_TX, |
| 419 | handle->name, |
| 420 | xport_ctx->xport, |
| 421 | xport_ctx->remote_ss, |
| 422 | status); |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 423 | |
| 424 | glink_os_cs_release(&handle->tx_cs); |
| 425 | return status; |
| 426 | } |
| 427 | |
| 428 | /** |
| 429 | * Queue one or more Rx intent for the logical GPIC Link channel. |
| 430 | * |
| 431 | * @param[in] handle GLink handle associated with the logical channel |
| 432 | * |
| 433 | * @param[in] *pkt_priv Per packet private data |
| 434 | * |
| 435 | * @param[in] size Size of buffer |
| 436 | * |
| 437 | * @return Standard GLink error codes |
| 438 | * |
| 439 | * @sideeffects GLink XAL allocates rx buffers for receiving packets |
| 440 | */ |
| 441 | glink_err_type glink_queue_rx_intent |
| 442 | ( |
| 443 | glink_handle_type handle, |
| 444 | const void *pkt_priv, |
| 445 | size_t size |
| 446 | ) |
| 447 | { |
| 448 | glink_err_type status; |
| 449 | glink_rx_intent_type *lc_intent; |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 450 | glink_core_xport_ctx_type *xport_ctx; |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 451 | size_t tmp; |
| 452 | |
| 453 | /* Input validation */ |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 454 | if(handle == NULL || size == 0) |
| 455 | { |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 456 | GLINK_LOG_ERROR_EVENT( GLINK_EVENT_CH_Q_RX_INTENT, "", "", "", |
| 457 | GLINK_STATUS_INVALID_PARAM); |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 458 | return GLINK_STATUS_INVALID_PARAM; |
| 459 | } |
| 460 | |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 461 | xport_ctx = handle->if_ptr->glink_core_priv; |
| 462 | |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 463 | /* short circuit for intentless mode */ |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 464 | if(xport_ctx->xport_capabilities & GLINK_CAPABILITY_INTENTLESS) |
| 465 | { |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 466 | return GLINK_STATUS_API_NOT_SUPPORTED; |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 467 | } |
| 468 | |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 469 | if (!glinki_channel_fully_opened(handle)) |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 470 | { |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 471 | GLINK_LOG_ERROR_EVENT( GLINK_EVENT_CH_Q_RX_INTENT, |
Sridhar Parasuram | 3b05812 | 2015-05-11 16:15:03 -0700 | [diff] [blame] | 472 | handle->name, |
| 473 | xport_ctx->xport, |
| 474 | xport_ctx->remote_ss, |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 475 | GLINK_STATUS_CH_NOT_FULLY_OPENED ); |
| 476 | return GLINK_STATUS_CH_NOT_FULLY_OPENED; |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | /* Allocate an intent structure */ |
| 480 | lc_intent = glink_os_calloc(sizeof(glink_rx_intent_type)); |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 481 | if(lc_intent == NULL) |
| 482 | { |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 483 | GLINK_LOG_ERROR_EVENT( GLINK_EVENT_CH_Q_RX_INTENT, |
| 484 | handle->name, |
| 485 | xport_ctx->xport, |
| 486 | xport_ctx->remote_ss, |
| 487 | GLINK_STATUS_OUT_OF_RESOURCES ); |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 488 | return GLINK_STATUS_OUT_OF_RESOURCES; |
| 489 | } |
| 490 | |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 491 | /* Call transport API to allocate rx intent buffer */ |
| 492 | status = handle->if_ptr->allocate_rx_intent(handle->if_ptr, size, lc_intent); |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 493 | if(status != GLINK_STATUS_SUCCESS) |
| 494 | { |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 495 | glink_os_free(lc_intent); |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 496 | GLINK_LOG_ERROR_EVENT( GLINK_EVENT_CH_Q_RX_INTENT, |
| 497 | handle->name, |
| 498 | xport_ctx->xport, |
| 499 | xport_ctx->remote_ss, |
| 500 | status ); |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 501 | return status; |
| 502 | } |
| 503 | |
| 504 | if (handle->notify_rxv == NULL && |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 505 | (lc_intent->vprovider(lc_intent->iovec, 0, &tmp) == NULL || tmp < size)) |
| 506 | { |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 507 | /* Allocate bounce buffer for non-vectored Rx */ |
| 508 | lc_intent->data = glink_os_malloc(size); |
| 509 | |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 510 | if(lc_intent->data == NULL) |
| 511 | { |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 512 | handle->if_ptr->deallocate_rx_intent(handle->if_ptr, lc_intent); |
| 513 | glink_os_free(lc_intent); |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 514 | GLINK_LOG_ERROR_EVENT( GLINK_EVENT_CH_Q_RX_INTENT, |
| 515 | handle->name, |
| 516 | xport_ctx->xport, |
| 517 | xport_ctx->remote_ss, |
| 518 | GLINK_STATUS_OUT_OF_RESOURCES ); |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 519 | return GLINK_STATUS_OUT_OF_RESOURCES; |
| 520 | } |
| 521 | } |
| 522 | |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 523 | glink_os_cs_acquire(&handle->if_ptr->glink_core_priv->liid_cs); |
| 524 | |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 525 | /* push the intent on local queue. Do this before calling tx cmd |
| 526 | as transport may try to read data into the newly queued rx_buffer */ |
| 527 | lc_intent->iid = handle->if_ptr->glink_core_priv->liid; |
| 528 | lc_intent->size = size; |
| 529 | lc_intent->pkt_priv = pkt_priv; |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 530 | glinki_enqueue_item(&handle->pintents->local_intent_q, |
| 531 | lc_intent, |
| 532 | &handle->pintents->intent_q_cs); |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 533 | |
| 534 | /* Call transport API to queue rx intent */ |
| 535 | /* Increment the local intent ID counter associated with this channel */ |
| 536 | handle->if_ptr->glink_core_priv->liid++; |
| 537 | |
| 538 | status = handle->if_ptr->tx_cmd_local_rx_intent(handle->if_ptr, |
| 539 | handle->lcid, size, lc_intent->iid); |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 540 | if(status != GLINK_STATUS_SUCCESS) |
| 541 | { |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 542 | /* Failure */ |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 543 | glinki_dequeue_item(&handle->pintents->local_intent_q, |
| 544 | lc_intent, |
| 545 | &handle->pintents->intent_q_cs); |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 546 | |
| 547 | handle->if_ptr->deallocate_rx_intent(handle->if_ptr, lc_intent); |
| 548 | glink_os_free(lc_intent->data); |
| 549 | glink_os_free(lc_intent); |
| 550 | } |
| 551 | glink_os_cs_release(&handle->if_ptr->glink_core_priv->liid_cs); |
| 552 | |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 553 | GLINK_LOG_EVENT( handle, |
| 554 | GLINK_EVENT_CH_Q_RX_INTENT, |
| 555 | handle->name, |
| 556 | xport_ctx->xport, |
| 557 | xport_ctx->remote_ss, |
| 558 | status ); |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 559 | return status; |
| 560 | } |
| 561 | |
| 562 | /** |
| 563 | * Client uses this to signal to GLink layer that it is done with the received |
| 564 | * data buffer. This API should be called to free up the receive buffer, which, |
| 565 | * in zero-copy mode is actually remote-side's transmit buffer. |
| 566 | * |
| 567 | * @param[in] handle GLink handle associated with the logical channel |
| 568 | * |
| 569 | * @param[in] *ptr Pointer to the received buffer |
| 570 | * |
| 571 | * @param[in] reuse Reuse intent |
| 572 | * |
| 573 | * @return Standard GLink error codes |
| 574 | * |
| 575 | * @sideeffects GLink XAL frees the Rx buffer |
| 576 | */ |
| 577 | glink_err_type glink_rx_done |
| 578 | ( |
| 579 | glink_handle_type handle, |
| 580 | const void *ptr, |
| 581 | boolean reuse |
| 582 | ) |
| 583 | { |
| 584 | glink_rx_intent_type *lc_intent; |
| 585 | glink_core_xport_ctx_type *xport_ctx = handle->if_ptr->glink_core_priv; |
| 586 | |
| 587 | /* Input validation */ |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 588 | if(handle == NULL || ptr == NULL) |
| 589 | { |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 590 | GLINK_LOG_ERROR_EVENT( GLINK_EVENT_CH_RX_DONE, "", "", "", |
| 591 | GLINK_STATUS_INVALID_PARAM ); |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 592 | return GLINK_STATUS_INVALID_PARAM; |
| 593 | } |
| 594 | |
| 595 | /* short circuit for intentless mode */ |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 596 | if (xport_ctx->xport_capabilities & GLINK_CAPABILITY_INTENTLESS) |
| 597 | { |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 598 | return GLINK_STATUS_API_NOT_SUPPORTED; |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 599 | } |
| 600 | |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 601 | if (!glinki_channel_fully_opened(handle)) |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 602 | { |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 603 | GLINK_LOG_ERROR_EVENT( GLINK_EVENT_CH_RX_DONE, |
Sridhar Parasuram | 3b05812 | 2015-05-11 16:15:03 -0700 | [diff] [blame] | 604 | handle->name, |
| 605 | xport_ctx->xport, |
| 606 | xport_ctx->remote_ss, |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 607 | GLINK_STATUS_CH_NOT_FULLY_OPENED ); |
| 608 | return GLINK_STATUS_CH_NOT_FULLY_OPENED; |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | /* Free the intent */ |
| 612 | lc_intent = smem_list_first(&handle->pintents->local_intent_client_q); |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 613 | while(lc_intent != NULL) |
| 614 | { |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 615 | size_t tmp; |
| 616 | |
| 617 | if(lc_intent->iovec == ptr || (handle->notify_rxv == NULL && |
| 618 | (lc_intent->data == ptr || |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 619 | ptr == lc_intent->vprovider(lc_intent->iovec, 0, &tmp)))) |
| 620 | { |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 621 | |
| 622 | uint32 iid; |
| 623 | |
| 624 | /* Found intent, delete it */ |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 625 | glinki_dequeue_item(&handle->pintents->local_intent_client_q, |
| 626 | lc_intent, |
| 627 | &handle->pintents->intent_q_cs); |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 628 | |
| 629 | iid = lc_intent->iid; |
| 630 | |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 631 | GLINK_UPDATE_CHANNEL_STATS( handle->ch_stats, rx_done, lc_intent->pkt_sz); |
| 632 | |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 633 | if (reuse) |
| 634 | { |
| 635 | lc_intent->used = 0; |
| 636 | |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 637 | glinki_enqueue_item(&handle->pintents->local_intent_q, |
| 638 | lc_intent, |
| 639 | &handle->pintents->intent_q_cs); |
| 640 | |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 641 | } |
| 642 | else |
| 643 | { |
| 644 | /* Free the intent */ |
| 645 | handle->if_ptr->deallocate_rx_intent(handle->if_ptr, lc_intent); |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 646 | if(lc_intent->data) |
| 647 | { |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 648 | /* Free the bounce buffer if we had allocated one */ |
| 649 | glink_os_free(lc_intent->data); |
| 650 | } |
| 651 | glink_os_free(lc_intent); |
| 652 | } |
| 653 | |
| 654 | /* Note that the actual buffer, lc_intent->data, was allocated by the |
| 655 | * transport and should be freed by the xport. We should not touch it */ |
| 656 | /* Let the xport know we are done with the buffer */ |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 657 | handle->if_ptr->tx_cmd_local_rx_done(handle->if_ptr, |
| 658 | handle->lcid, |
| 659 | iid, |
| 660 | reuse); |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 661 | |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 662 | GLINK_LOG_EVENT( handle, |
| 663 | GLINK_EVENT_CH_RX_DONE, |
| 664 | handle->name, |
| 665 | xport_ctx->xport, |
| 666 | xport_ctx->remote_ss, |
| 667 | GLINK_STATUS_SUCCESS ); |
| 668 | |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 669 | return GLINK_STATUS_SUCCESS; |
| 670 | } |
| 671 | lc_intent = smem_list_next(lc_intent); |
| 672 | } |
| 673 | |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 674 | GLINK_LOG_ERROR_EVENT( GLINK_EVENT_CH_RX_DONE, |
| 675 | handle->name, |
| 676 | xport_ctx->xport, |
| 677 | xport_ctx->remote_ss, |
| 678 | GLINK_STATUS_INVALID_PARAM ); |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 679 | return GLINK_STATUS_INVALID_PARAM; |
| 680 | } |
| 681 | |
| 682 | /** |
| 683 | * Set the 32 bit control signal field. Depending on the transport, it may |
| 684 | * take appropriate actions on the set bit-mask, or transmit the entire |
| 685 | * 32-bit value to the remote host. |
| 686 | * |
| 687 | * @param[in] handle GLink handle associated with the logical channel |
| 688 | * |
| 689 | * @param[in] sig_value 32 bit signal word |
| 690 | * |
| 691 | * @return Standard GLink error codes |
| 692 | * |
| 693 | * @sideeffects None |
| 694 | */ |
| 695 | glink_err_type glink_sigs_set |
| 696 | ( |
| 697 | glink_handle_type handle, |
| 698 | uint32 sig_value |
| 699 | ) |
| 700 | { |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 701 | glink_core_xport_ctx_type *xport_ctx; |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 702 | glink_err_type status; |
| 703 | |
| 704 | /* Input validation */ |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 705 | if(handle == NULL) |
| 706 | { |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 707 | GLINK_LOG_ERROR_EVENT( GLINK_EVENT_CH_SIG_SET, "", "", "", |
| 708 | GLINK_STATUS_INVALID_PARAM ); |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 709 | return GLINK_STATUS_INVALID_PARAM; |
| 710 | } |
| 711 | |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 712 | xport_ctx = handle->if_ptr->glink_core_priv; |
| 713 | |
| 714 | ASSERT( xport_ctx != NULL ); |
Sridhar Parasuram | 3b05812 | 2015-05-11 16:15:03 -0700 | [diff] [blame] | 715 | |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 716 | if (!glinki_channel_fully_opened(handle)) |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 717 | { |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 718 | GLINK_LOG_ERROR_EVENT( GLINK_EVENT_CH_SIG_SET, |
Sridhar Parasuram | 3b05812 | 2015-05-11 16:15:03 -0700 | [diff] [blame] | 719 | handle->name, |
| 720 | xport_ctx->xport, |
| 721 | xport_ctx->remote_ss, |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 722 | GLINK_STATUS_CH_NOT_FULLY_OPENED ); |
Sridhar Parasuram | 3b05812 | 2015-05-11 16:15:03 -0700 | [diff] [blame] | 723 | |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 724 | return GLINK_STATUS_CH_NOT_FULLY_OPENED; |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 725 | } |
| 726 | |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 727 | status = handle->if_ptr->tx_cmd_set_sigs(handle->if_ptr, |
| 728 | handle->lcid, |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 729 | sig_value); |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 730 | if(GLINK_STATUS_SUCCESS == status) |
| 731 | { |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 732 | /* Update local copy of local control signal state */ |
| 733 | handle->local_sigs = sig_value; |
| 734 | } |
| 735 | |
| 736 | return status; |
| 737 | } |
| 738 | |
| 739 | /** |
| 740 | * Get the local 32 bit control signal bit-field. |
| 741 | * |
| 742 | * @param[in] handle GLink handle associated with the logical channel |
| 743 | * |
| 744 | * @param[out] *sig_value Pointer to a 32 bit signal word to get sig value |
| 745 | * |
| 746 | * @return Standard GLink error codes |
| 747 | * |
| 748 | * @sideeffects None |
| 749 | */ |
| 750 | glink_err_type glink_sigs_local_get |
| 751 | ( |
| 752 | glink_handle_type handle, |
| 753 | uint32 *sig_value |
| 754 | ) |
| 755 | { |
| 756 | /* Input validation */ |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 757 | if(handle == NULL || sig_value == NULL) |
| 758 | { |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 759 | GLINK_LOG_ERROR_EVENT( GLINK_EVENT_CH_SIG_L_GET, "", "", "", |
| 760 | GLINK_STATUS_INVALID_PARAM ); |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 761 | return GLINK_STATUS_INVALID_PARAM; |
| 762 | } |
| 763 | |
| 764 | *sig_value = handle->local_sigs; |
| 765 | |
| 766 | return GLINK_STATUS_SUCCESS; |
| 767 | } |
| 768 | |
| 769 | /** |
| 770 | * Get the remote 32 bit control signal bit-field. |
| 771 | * |
| 772 | * @param[in] handle GLink handle associated with the logical channel |
| 773 | * |
| 774 | * @param[out] *sig_value Pointer to a 32 bit signal word to get sig value |
| 775 | * |
| 776 | * @return Standard GLink error codes |
| 777 | * |
| 778 | * @sideeffects None |
| 779 | */ |
| 780 | glink_err_type glink_sigs_remote_get |
| 781 | ( |
| 782 | glink_handle_type handle, |
| 783 | uint32 *sig_value |
| 784 | ) |
| 785 | { |
| 786 | /* Input validation */ |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 787 | if(handle == NULL || sig_value == NULL) |
| 788 | { |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 789 | GLINK_LOG_ERROR_EVENT( GLINK_EVENT_CH_SIG_R_GET, "", "", "", |
| 790 | GLINK_STATUS_INVALID_PARAM ); |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 791 | return GLINK_STATUS_INVALID_PARAM; |
| 792 | } |
| 793 | |
| 794 | *sig_value = handle->remote_sigs; |
| 795 | |
| 796 | return GLINK_STATUS_SUCCESS; |
| 797 | } |
| 798 | |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 799 | /** |
| 800 | * Regsiters a client specified callback to be invoked when the specified |
| 801 | * transport (link) is up/down. |
| 802 | * |
| 803 | * @param[in] link_id Pointer to the configuration structure for the |
| 804 | * xport(link) to be monitored. See glink.h |
| 805 | * @param[in] priv Callback data returned to client when callback |
| 806 | * is invoked. |
| 807 | * |
| 808 | * @return Standard GLink error codes |
| 809 | * |
| 810 | * @sideeffects Puts the callback in a queue which gets scanned when a |
| 811 | * transport(link) comes up OR an SSR happnes. |
| 812 | */ |
| 813 | glink_err_type glink_register_link_state_cb |
| 814 | ( |
| 815 | glink_link_id_type *link_id, |
| 816 | void* priv |
| 817 | ) |
| 818 | { |
| 819 | glink_link_notif_data_type* link_notif_data; |
| 820 | unsigned int remote_host; |
| 821 | |
| 822 | /* Input validation */ |
| 823 | if (link_id == NULL || |
| 824 | link_id->version != GLINK_LINK_ID_VER || |
| 825 | link_id->link_notifier == NULL) |
| 826 | { |
| 827 | return GLINK_STATUS_INVALID_PARAM; |
| 828 | } |
| 829 | |
| 830 | /* Check for remote_ss validity */ |
| 831 | if (link_id->remote_ss != NULL) |
| 832 | { |
| 833 | remote_host = glinki_find_remote_host(link_id->remote_ss); |
| 834 | if (remote_host == GLINK_NUM_HOSTS) |
| 835 | { |
| 836 | return GLINK_STATUS_INVALID_PARAM; |
| 837 | } |
| 838 | } |
| 839 | |
| 840 | /* Save the callback on the notification list */ |
| 841 | if((link_notif_data = glink_os_calloc(sizeof(glink_link_notif_data_type))) |
| 842 | == NULL) |
| 843 | { |
| 844 | return GLINK_STATUS_OUT_OF_RESOURCES; |
| 845 | } |
| 846 | |
| 847 | link_notif_data->xport = link_id->xport; |
| 848 | link_notif_data->remote_ss = link_id->remote_ss; |
| 849 | link_notif_data->link_notifier = link_id->link_notifier; |
| 850 | link_notif_data->priv = priv; /* private client data */ |
| 851 | |
| 852 | /* Append the request to the list for link UP/DOWN notifications */ |
| 853 | glinki_register_link_notif_data(link_notif_data); |
| 854 | link_id->handle = (glink_link_handle_type)link_notif_data; |
| 855 | |
| 856 | /* Scan the list of available transport to see if this link is already up */ |
| 857 | glinki_scan_xports_and_notify(link_notif_data); |
| 858 | |
| 859 | return GLINK_STATUS_SUCCESS; |
| 860 | } |
| 861 | |
| 862 | /** |
| 863 | * Degsiter the link UP/DOWN notification callback associated with the |
| 864 | * provided handle. |
| 865 | * |
| 866 | * @param[in] handle Callback handler returned by |
| 867 | * glink_register_link_state_cb |
| 868 | * |
| 869 | * @return Standard GLink error codes |
| 870 | * |
| 871 | * @sideeffects Removes the callback in a queue which gets scanned when a |
| 872 | * transport(link) comes up OR an SSR happnes. |
| 873 | */ |
| 874 | glink_err_type glink_deregister_link_state_cb |
| 875 | ( |
| 876 | glink_link_handle_type handle |
| 877 | ) |
| 878 | { |
| 879 | /* check if glink handle is NULL and return appropriate |
| 880 | return code */ |
| 881 | if(handle == NULL) |
| 882 | { |
| 883 | return GLINK_STATUS_INVALID_PARAM; |
| 884 | } |
| 885 | |
| 886 | glinki_deregister_link_notif_data((glink_link_notif_data_type *)handle); |
| 887 | |
| 888 | glink_os_free(handle); |
| 889 | |
| 890 | return GLINK_STATUS_SUCCESS; |
| 891 | } |
| 892 | |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 893 | /*================= RESTRICTED API ==========================*/ |
| 894 | |
| 895 | /** |
| 896 | * This API allows the RPM client to poll the transport for any new data |
| 897 | * that might have come in. It would *usually* be used when incoming interrupts |
| 898 | * are disabled. |
| 899 | * |
| 900 | * @param[in] handle GLink handle associated with the logical channel |
| 901 | * |
| 902 | * @return Standard GLink error codes |
| 903 | * |
| 904 | * @sideeffects None |
| 905 | */ |
| 906 | glink_err_type glink_rpm_rx_poll |
| 907 | ( |
| 908 | glink_handle_type handle |
| 909 | ) |
| 910 | { |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 911 | if (!handle) |
| 912 | { |
| 913 | return GLINK_STATUS_INVALID_PARAM; |
| 914 | } |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 915 | |
| 916 | if(handle->if_ptr->poll) { |
| 917 | return handle->if_ptr->poll(handle->if_ptr); |
| 918 | } |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 919 | return GLINK_STATUS_API_NOT_SUPPORTED; |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | /** |
| 923 | * This API allows the RPM client to mask/unmask rx interrupts |
| 924 | * |
| 925 | * @param[in] handle GLink handle associated with the logical channel |
| 926 | * |
| 927 | * @param[in] mask Whether to mask or un-mask the incoming interrupt |
| 928 | * |
| 929 | * @param[in] platform_struct Any platform specific into that transport may |
| 930 | require |
| 931 | * |
| 932 | * @return Standard GLink error codes |
| 933 | * |
| 934 | * @sideeffects None |
| 935 | */ |
| 936 | glink_err_type glink_rpm_mask_rx_interrupt |
| 937 | ( |
| 938 | glink_handle_type handle, |
| 939 | boolean mask, |
| 940 | void *platform_struct |
| 941 | ) |
| 942 | { |
Steven Cahail | 964ff2f | 2015-08-20 19:01:56 -0600 | [diff] [blame] | 943 | if (!handle) |
| 944 | { |
| 945 | return GLINK_STATUS_INVALID_PARAM; |
| 946 | } |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 947 | |
| 948 | if(handle->if_ptr->mask_rx_irq) { |
| 949 | return handle->if_ptr->mask_rx_irq(handle->if_ptr, mask); |
| 950 | } |
Steven Cahail | b850bb6 | 2015-08-21 14:39:38 -0600 | [diff] [blame] | 951 | return GLINK_STATUS_API_NOT_SUPPORTED; |
Sridhar Parasuram | bf39132 | 2015-01-23 09:29:07 -0800 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | /** |
| 955 | * This API waits until link is down. |
| 956 | * |
| 957 | * @param[in] handle GLink handle associated with the logical channel |
| 958 | * |
| 959 | * @return Standard GLink error codes |
| 960 | * |
| 961 | * @sideeffects None |
| 962 | */ |
| 963 | glink_err_type glink_wait_link_down |
| 964 | ( |
| 965 | glink_handle_type handle |
| 966 | ) |
| 967 | { |
| 968 | ASSERT(handle && handle->if_ptr && handle->if_ptr->wait_link_down); |
| 969 | |
| 970 | return handle->if_ptr->wait_link_down(handle->if_ptr) ? |
| 971 | GLINK_STATUS_SUCCESS : GLINK_STATUS_FAILURE; |
| 972 | } |