Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Stephen Wang | 1f6ad49 | 2016-01-27 23:42:06 -0800 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, The Linux Foundation. All rights reserved. |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 4 | * Permission to use, copy, modify, and/or distribute this software for |
| 5 | * any purpose with or without fee is hereby granted, provided that the |
| 6 | * above copyright notice and this permission notice appear in all copies. |
| 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 10 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 12 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 13 | * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 14 | ************************************************************************** |
| 15 | */ |
| 16 | |
| 17 | /* |
| 18 | * nss_capwap.h |
| 19 | * NSS CAPWAP driver interface APIs |
| 20 | */ |
| 21 | #include "nss_core.h" |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 22 | #include "nss_capwap.h" |
Stephen Wang | 1f6ad49 | 2016-01-27 23:42:06 -0800 | [diff] [blame] | 23 | #include "nss_cmn.h" |
| 24 | #include "nss_tx_rx_common.h" |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 25 | |
| 26 | /* |
| 27 | * Spinlock for protecting tunnel operations colliding with a tunnel destroy |
| 28 | */ |
| 29 | DEFINE_SPINLOCK(nss_capwap_spinlock); |
| 30 | |
| 31 | /* |
| 32 | * Array of pointer for NSS CAPWAP handles. Each handle has per-tunnel |
| 33 | * stats based on the if_num which is an index. |
| 34 | * |
| 35 | * Per CAPWAP tunnel/interface number instance. |
| 36 | */ |
| 37 | struct nss_capwap_handle { |
| 38 | atomic_t refcnt; /**< Reference count on the tunnel */ |
Saurabh Misra | f4a0563 | 2015-02-27 17:49:41 -0800 | [diff] [blame] | 39 | uint32_t if_num; /**< Interface number */ |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 40 | uint32_t tunnel_status; /**< 0=disable, 1=enabled */ |
| 41 | struct nss_ctx_instance *ctx; /**< Pointer to context */ |
| 42 | nss_capwap_msg_callback_t msg_callback; /**< Msg callback */ |
| 43 | void *app_data; /**< App data (argument) */ |
| 44 | struct nss_capwap_tunnel_stats stats; /**< Stats per-interface number */ |
| 45 | }; |
| 46 | static struct nss_capwap_handle *nss_capwap_hdl[NSS_MAX_DYNAMIC_INTERFACES]; |
| 47 | |
| 48 | /* |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 49 | * nss_capwap_verify_if_num() |
| 50 | * Verify if_num passed to us. |
| 51 | */ |
| 52 | static bool nss_capwap_verify_if_num(uint32_t if_num) |
| 53 | { |
| 54 | if (nss_is_dynamic_interface(if_num) == false) { |
| 55 | return false; |
| 56 | } |
| 57 | |
| 58 | if (nss_dynamic_interface_get_type(if_num) != NSS_DYNAMIC_INTERFACE_TYPE_CAPWAP) { |
| 59 | return false; |
| 60 | } |
| 61 | |
| 62 | return true; |
| 63 | } |
| 64 | |
| 65 | /* |
| 66 | * nss_capwap_refcnt_inc() |
| 67 | * Increments refcnt on the tunnel. |
| 68 | */ |
| 69 | static void nss_capwap_refcnt_inc(int32_t if_num) |
| 70 | { |
| 71 | if_num = if_num - NSS_DYNAMIC_IF_START; |
| 72 | atomic_inc(&nss_capwap_hdl[if_num]->refcnt); |
| 73 | nss_assert(atomic_read(&nss_capwap_hdl[if_num]->refcnt) > 0); |
| 74 | } |
| 75 | |
| 76 | /* |
| 77 | * nss_capwap_refcnt_dec() |
| 78 | * Decrements refcnt on the tunnel. |
| 79 | */ |
| 80 | static void nss_capwap_refcnt_dec(int32_t if_num) |
| 81 | { |
| 82 | if_num = if_num - NSS_DYNAMIC_IF_START; |
| 83 | nss_assert(atomic_read(&nss_capwap_hdl[if_num]->refcnt) > 0); |
| 84 | atomic_dec(&nss_capwap_hdl[if_num]->refcnt); |
| 85 | } |
| 86 | |
| 87 | /* |
Saurabh Misra | f4a0563 | 2015-02-27 17:49:41 -0800 | [diff] [blame] | 88 | * nss_capwap_refcnt() |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 89 | * Get refcnt on the tunnel. |
| 90 | */ |
Saurabh Misra | f4a0563 | 2015-02-27 17:49:41 -0800 | [diff] [blame] | 91 | static uint32_t nss_capwap_refcnt(int32_t if_num) |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 92 | { |
| 93 | if_num = if_num - NSS_DYNAMIC_IF_START; |
| 94 | return atomic_read(&nss_capwap_hdl[if_num]->refcnt); |
| 95 | } |
| 96 | |
| 97 | /* |
| 98 | * nss_capwap_set_msg_callback() |
| 99 | * This sets the message callback handler and its associated context |
| 100 | */ |
| 101 | static void nss_capwap_set_msg_callback(int32_t if_num, nss_capwap_msg_callback_t cb, void *app_data) |
| 102 | { |
| 103 | struct nss_capwap_handle *h; |
| 104 | |
| 105 | h = nss_capwap_hdl[if_num - NSS_DYNAMIC_IF_START]; |
| 106 | if (!h) { |
| 107 | return; |
| 108 | } |
| 109 | |
| 110 | h->app_data = app_data; |
| 111 | h->msg_callback = cb; |
| 112 | } |
| 113 | |
| 114 | /* |
Saurabh Misra | 3e9f8b0 | 2015-03-16 13:30:57 -0700 | [diff] [blame] | 115 | * nss_capwap_get_msg_callback() |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 116 | * This gets the message callback handler and its associated context |
| 117 | */ |
Saurabh Misra | 3e9f8b0 | 2015-03-16 13:30:57 -0700 | [diff] [blame] | 118 | static nss_capwap_msg_callback_t nss_capwap_get_msg_callback(int32_t if_num, void **app_data) |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 119 | { |
| 120 | struct nss_capwap_handle *h; |
| 121 | |
| 122 | h = nss_capwap_hdl[if_num - NSS_DYNAMIC_IF_START]; |
| 123 | if (!h) { |
| 124 | *app_data = NULL; |
| 125 | return NULL; |
| 126 | } |
| 127 | |
| 128 | *app_data = h->app_data; |
| 129 | return h->msg_callback; |
| 130 | } |
| 131 | |
| 132 | /* |
| 133 | * nss_capwapmgr_update_stats() |
| 134 | * Update per-tunnel stats for each CAPWAP interface. |
| 135 | */ |
| 136 | static void nss_capwapmgr_update_stats(struct nss_capwap_handle *handle, struct nss_capwap_stats_msg *fstats) |
| 137 | { |
| 138 | struct nss_capwap_tunnel_stats *stats; |
| 139 | |
| 140 | stats = &handle->stats; |
| 141 | |
| 142 | stats->rx_segments += fstats->rx_segments; |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 143 | stats->dtls_pkts += fstats->dtls_pkts; |
Saurabh Misra | 6db99b5 | 2014-12-08 10:33:08 -0800 | [diff] [blame] | 144 | |
| 145 | stats->rx_dup_frag += fstats->rx_dup_frag; |
Saurabh Misra | 3f66e87 | 2015-04-03 11:30:42 -0700 | [diff] [blame] | 146 | stats->rx_oversize_drops += fstats->rx_oversize_drops; |
| 147 | stats->rx_frag_timeout_drops += fstats->rx_frag_timeout_drops; |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 148 | stats->rx_queue_full_drops += fstats->rx_queue_full_drops; |
| 149 | stats->rx_n2h_queue_full_drops += fstats->rx_n2h_queue_full_drops; |
| 150 | stats->rx_mem_failure_drops += fstats->rx_mem_failure_drops; |
Saurabh Misra | 3f66e87 | 2015-04-03 11:30:42 -0700 | [diff] [blame] | 151 | stats->rx_csum_drops += fstats->rx_csum_drops; |
| 152 | stats->rx_malformed += fstats->rx_malformed; |
| 153 | stats->rx_frag_gap_drops += fstats->rx_frag_gap_drops; |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 154 | |
Saurabh Misra | 3f66e87 | 2015-04-03 11:30:42 -0700 | [diff] [blame] | 155 | stats->tx_segments += fstats->tx_segments; |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 156 | stats->tx_queue_full_drops += fstats->tx_queue_full_drops; |
| 157 | stats->tx_mem_failure_drops += fstats->tx_mem_failure_drops; |
Saurabh Misra | 3f66e87 | 2015-04-03 11:30:42 -0700 | [diff] [blame] | 158 | stats->tx_dropped_sg_ref += fstats->tx_dropped_sg_ref; |
| 159 | stats->tx_dropped_ver_mis += fstats->tx_dropped_ver_mis; |
| 160 | stats->tx_dropped_hroom += fstats->tx_dropped_hroom; |
| 161 | stats->tx_dropped_dtls += fstats->tx_dropped_dtls; |
| 162 | stats->tx_dropped_nwireless += fstats->tx_dropped_nwireless; |
| 163 | stats->tx_dropped_unalign += fstats->tx_dropped_unalign; |
Saurabh Misra | 6db99b5 | 2014-12-08 10:33:08 -0800 | [diff] [blame] | 164 | |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 165 | /* |
| 166 | * add pnode stats now. |
| 167 | */ |
| 168 | stats->pnode_stats.rx_packets += fstats->pnode_stats.rx_packets; |
| 169 | stats->pnode_stats.rx_bytes += fstats->pnode_stats.rx_bytes; |
| 170 | stats->pnode_stats.rx_dropped += fstats->pnode_stats.rx_dropped; |
| 171 | stats->pnode_stats.tx_packets += fstats->pnode_stats.tx_packets; |
| 172 | stats->pnode_stats.tx_bytes += fstats->pnode_stats.tx_bytes; |
| 173 | } |
| 174 | |
| 175 | /* |
| 176 | * nss_capwap_handler() |
| 177 | * Handle NSS -> HLOS messages for CAPWAP |
| 178 | */ |
Saurabh Misra | 3e9f8b0 | 2015-03-16 13:30:57 -0700 | [diff] [blame] | 179 | static void nss_capwap_msg_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data) |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 180 | { |
| 181 | struct nss_capwap_msg *ntm = (struct nss_capwap_msg *)ncm; |
| 182 | nss_capwap_msg_callback_t cb; |
| 183 | |
| 184 | /* |
| 185 | * Is this a valid request/response packet? |
| 186 | */ |
| 187 | if (ncm->type > NSS_CAPWAP_MSG_TYPE_MAX) { |
| 188 | nss_warning("%p: received invalid message %d for CAPWAP interface", nss_ctx, ncm->type); |
| 189 | return; |
| 190 | } |
| 191 | |
Suruchi Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 192 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_capwap_msg)) { |
| 193 | nss_warning("%p: Length of message is greater than required: %d", nss_ctx, nss_cmn_get_msg_len(ncm)); |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 194 | return; |
| 195 | } |
| 196 | |
| 197 | nss_core_log_msg_failures(nss_ctx, ncm); |
| 198 | |
| 199 | switch (ntm->cm.type) { |
| 200 | case NSS_CAPWAP_MSG_TYPE_SYNC_STATS: { |
| 201 | uint32_t if_num; |
| 202 | |
| 203 | if_num = ncm->interface - NSS_DYNAMIC_IF_START; |
| 204 | if (nss_capwap_hdl[if_num] != NULL) { |
| 205 | nss_capwapmgr_update_stats(nss_capwap_hdl[if_num], &ntm->msg.stats); |
| 206 | } |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | /* |
| 211 | * Update the callback and app_data for NOTIFY messages. |
| 212 | */ |
| 213 | if (ncm->response == NSS_CMM_RESPONSE_NOTIFY) { |
Saurabh Misra | 3e9f8b0 | 2015-03-16 13:30:57 -0700 | [diff] [blame] | 214 | ncm->cb = (uint32_t)nss_capwap_get_msg_callback(ncm->interface, (void **)&ncm->app_data); |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | /* |
| 218 | * Do we have a callback |
| 219 | */ |
| 220 | if (!ncm->cb) { |
| 221 | nss_trace("%p: cb is null for interface %d", nss_ctx, ncm->interface); |
| 222 | return; |
| 223 | } |
| 224 | |
| 225 | cb = (nss_capwap_msg_callback_t)ncm->cb; |
Saurabh Misra | 3e9f8b0 | 2015-03-16 13:30:57 -0700 | [diff] [blame] | 226 | cb((void *)ncm->app_data, ntm); |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | /* |
| 230 | * nss_capwap_instance_alloc() |
| 231 | * Allocate CAPWAP tunnel instance |
| 232 | */ |
| 233 | static bool nss_capwap_instance_alloc(struct nss_ctx_instance *nss_ctx, uint32_t if_num) |
| 234 | { |
| 235 | struct nss_capwap_handle *h; |
| 236 | |
| 237 | /* |
| 238 | * Allocate a handle |
| 239 | */ |
| 240 | h = kmalloc(sizeof(struct nss_capwap_handle), GFP_ATOMIC); |
| 241 | if (h == NULL) { |
| 242 | nss_warning("%p: no memory for allocating CAPWAP instance for interface : %d", nss_ctx, if_num); |
| 243 | return false; |
| 244 | } |
Saurabh Misra | f4a0563 | 2015-02-27 17:49:41 -0800 | [diff] [blame] | 245 | |
| 246 | memset(h, 0, sizeof(struct nss_capwap_handle)); |
| 247 | h->if_num = if_num; |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 248 | |
| 249 | spin_lock(&nss_capwap_spinlock); |
| 250 | if (nss_capwap_hdl[if_num - NSS_DYNAMIC_IF_START] != NULL) { |
| 251 | spin_unlock(&nss_capwap_spinlock); |
| 252 | kfree(h); |
| 253 | nss_warning("%p: Another thread is already allocated instance for :%d", nss_ctx, if_num); |
| 254 | return false; |
| 255 | } |
| 256 | |
| 257 | nss_capwap_hdl[if_num - NSS_DYNAMIC_IF_START] = h; |
| 258 | spin_unlock(&nss_capwap_spinlock); |
| 259 | |
| 260 | return true; |
| 261 | } |
| 262 | |
| 263 | /* |
| 264 | * nss_capwap_tx_msg() |
| 265 | * Transmit a CAPWAP message to NSS FW. Don't call this from softirq/interrupts. |
| 266 | */ |
| 267 | nss_tx_status_t nss_capwap_tx_msg(struct nss_ctx_instance *nss_ctx, struct nss_capwap_msg *msg) |
| 268 | { |
| 269 | struct nss_capwap_msg *nm; |
| 270 | struct nss_cmn_msg *ncm = &msg->cm; |
| 271 | struct sk_buff *nbuf; |
| 272 | int32_t status; |
| 273 | int32_t if_num; |
| 274 | |
| 275 | BUG_ON(in_interrupt()); |
| 276 | BUG_ON(in_softirq()); |
| 277 | BUG_ON(in_serving_softirq()); |
| 278 | |
| 279 | if (nss_capwap_verify_if_num(msg->cm.interface) == false) { |
| 280 | return NSS_TX_FAILURE_BAD_PARAM; |
| 281 | } |
| 282 | |
| 283 | if (ncm->type >= NSS_CAPWAP_MSG_TYPE_MAX) { |
| 284 | return NSS_TX_FAILURE_BAD_PARAM; |
| 285 | } |
| 286 | |
| 287 | if_num = msg->cm.interface - NSS_DYNAMIC_IF_START; |
| 288 | spin_lock(&nss_capwap_spinlock); |
| 289 | if (!nss_capwap_hdl[if_num]) { |
| 290 | spin_unlock(&nss_capwap_spinlock); |
| 291 | nss_warning("%p: capwap tunnel if_num is not there: %d", nss_ctx, msg->cm.interface); |
| 292 | return NSS_TX_FAILURE_BAD_PARAM; |
| 293 | } |
| 294 | nss_capwap_refcnt_inc(msg->cm.interface); |
| 295 | spin_unlock(&nss_capwap_spinlock); |
| 296 | |
| 297 | if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) { |
| 298 | nss_warning("%p: capwap msg dropped as core not ready", nss_ctx); |
| 299 | status = NSS_TX_FAILURE_NOT_READY; |
| 300 | goto out; |
| 301 | } |
| 302 | |
Suruchi Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 303 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_capwap_msg)) { |
| 304 | nss_warning("%p: message length is invalid: %d", nss_ctx, nss_cmn_get_msg_len(ncm)); |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 305 | status = NSS_TX_FAILURE_BAD_PARAM; |
| 306 | goto out; |
| 307 | } |
| 308 | |
| 309 | nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE); |
| 310 | if (unlikely(!nbuf)) { |
Sundarajan Srinivasan | 62fee7e | 2015-01-22 11:13:10 -0800 | [diff] [blame] | 311 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]); |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 312 | nss_warning("%p: msg dropped as command allocation failed", nss_ctx); |
| 313 | status = NSS_TX_FAILURE; |
| 314 | goto out; |
| 315 | } |
| 316 | |
| 317 | /* |
| 318 | * Copy the message to our skb |
| 319 | */ |
| 320 | nm = (struct nss_capwap_msg *)skb_put(nbuf, sizeof(struct nss_capwap_msg)); |
| 321 | memcpy(nm, msg, sizeof(struct nss_capwap_msg)); |
| 322 | |
| 323 | status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0); |
| 324 | if (status != NSS_CORE_STATUS_SUCCESS) { |
| 325 | dev_kfree_skb_any(nbuf); |
| 326 | nss_warning("%p: Unable to enqueue 'capwap message' \n", nss_ctx); |
| 327 | goto out; |
| 328 | } |
| 329 | |
| 330 | nss_hal_send_interrupt(nss_ctx->nmap, nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit, |
| 331 | NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE); |
| 332 | |
| 333 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]); |
| 334 | |
| 335 | out: |
| 336 | nss_capwap_refcnt_dec(msg->cm.interface); |
| 337 | return status; |
| 338 | } |
| 339 | EXPORT_SYMBOL(nss_capwap_tx_msg); |
| 340 | |
| 341 | /* |
Stephen Wang | cf9c21c | 2016-02-18 17:54:16 -0800 | [diff] [blame] | 342 | * nss_capwap_tx_buf() |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 343 | * Transmit data buffer (skb) to a NSS interface number |
| 344 | */ |
Stephen Wang | cf9c21c | 2016-02-18 17:54:16 -0800 | [diff] [blame] | 345 | nss_tx_status_t nss_capwap_tx_buf(struct nss_ctx_instance *nss_ctx, struct sk_buff *os_buf, uint32_t if_num) |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 346 | { |
Stephen Wang | cf9c21c | 2016-02-18 17:54:16 -0800 | [diff] [blame] | 347 | int32_t status; |
| 348 | uint16_t int_bit = 0; |
| 349 | |
| 350 | NSS_VERIFY_CTX_MAGIC(nss_ctx); |
| 351 | |
| 352 | if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) { |
| 353 | nss_warning("%p: NSS core is not ready", nss_ctx); |
| 354 | return NSS_TX_FAILURE_NOT_READY; |
| 355 | } |
| 356 | |
| 357 | BUG_ON(!nss_capwap_verify_if_num(if_num)); |
| 358 | |
| 359 | int_bit = nss_ctx->h2n_desc_rings[NSS_IF_DATA_QUEUE_0].desc_ring.int_bit; |
| 360 | status = nss_core_send_buffer(nss_ctx, if_num, os_buf, NSS_IF_DATA_QUEUE_0, H2N_BUFFER_PACKET, H2N_BIT_FLAG_VIRTUAL_BUFFER); |
| 361 | if (unlikely(status != NSS_CORE_STATUS_SUCCESS)) { |
| 362 | nss_warning("%p: Unable to enqueue capwap packet\n", nss_ctx); |
| 363 | if (status == NSS_CORE_STATUS_FAILURE_QUEUE) { |
| 364 | return NSS_TX_FAILURE_QUEUE; |
| 365 | } |
| 366 | return NSS_TX_FAILURE; |
| 367 | } |
| 368 | |
| 369 | nss_hal_send_interrupt(nss_ctx->nmap, int_bit, NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE); |
| 370 | |
| 371 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_PACKET]); |
| 372 | return NSS_TX_SUCCESS; |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 373 | } |
Stephen Wang | cf9c21c | 2016-02-18 17:54:16 -0800 | [diff] [blame] | 374 | EXPORT_SYMBOL(nss_capwap_tx_buf); |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 375 | |
| 376 | /* |
| 377 | *********************************** |
| 378 | * Register/Unregister/Miscellaneous APIs |
| 379 | *********************************** |
| 380 | */ |
| 381 | |
| 382 | /* |
| 383 | * nss_capwap_get_stats() |
| 384 | * API for getting stats from a CAPWAP tunnel interface stats |
| 385 | */ |
| 386 | bool nss_capwap_get_stats(uint32_t if_num, struct nss_capwap_tunnel_stats *stats) |
| 387 | { |
| 388 | if (nss_capwap_verify_if_num(if_num) == false) { |
| 389 | return false; |
| 390 | } |
| 391 | |
| 392 | if_num = if_num - NSS_DYNAMIC_IF_START; |
| 393 | spin_lock(&nss_capwap_spinlock); |
| 394 | if (nss_capwap_hdl[if_num] == NULL) { |
| 395 | spin_unlock(&nss_capwap_spinlock); |
| 396 | return false; |
| 397 | } |
| 398 | |
| 399 | memcpy(stats, &nss_capwap_hdl[if_num]->stats, sizeof(struct nss_capwap_tunnel_stats)); |
| 400 | spin_unlock(&nss_capwap_spinlock); |
| 401 | return true; |
| 402 | } |
| 403 | EXPORT_SYMBOL(nss_capwap_get_stats); |
| 404 | |
| 405 | /* |
| 406 | * nss_capwap_notify_register() |
| 407 | * Registers a message notifier with NSS FW. It should not be called from |
| 408 | * softirq or interrupts. |
| 409 | */ |
| 410 | struct nss_ctx_instance *nss_capwap_notify_register(uint32_t if_num, nss_capwap_msg_callback_t cb, void *app_data) |
| 411 | { |
| 412 | struct nss_ctx_instance *nss_ctx; |
| 413 | |
| 414 | nss_ctx = &nss_top_main.nss[nss_top_main.capwap_handler_id]; |
| 415 | |
| 416 | if (nss_capwap_verify_if_num(if_num) == false) { |
| 417 | nss_warning("%p: notfiy register received for invalid interface %d", nss_ctx, if_num); |
| 418 | return NULL; |
| 419 | } |
| 420 | |
| 421 | spin_lock(&nss_capwap_spinlock); |
| 422 | if (nss_capwap_hdl[if_num - NSS_DYNAMIC_IF_START] != NULL) { |
| 423 | spin_unlock(&nss_capwap_spinlock); |
| 424 | nss_warning("%p: notfiy register tunnel already exists for interface %d", nss_ctx, if_num); |
| 425 | return NULL; |
| 426 | } |
| 427 | spin_unlock(&nss_capwap_spinlock); |
| 428 | |
| 429 | return nss_ctx; |
| 430 | } |
| 431 | EXPORT_SYMBOL(nss_capwap_notify_register); |
| 432 | |
| 433 | /* |
| 434 | * nss_capwap_notify_unregister() |
| 435 | * unregister the CAPWAP notifier for the given interface number (if_num). |
| 436 | * It shouldn't be called from softirq or interrupts. |
| 437 | */ |
| 438 | nss_tx_status_t nss_capwap_notify_unregister(struct nss_ctx_instance *nss_ctx, uint32_t if_num) |
| 439 | { |
| 440 | struct nss_top_instance *nss_top; |
| 441 | int index; |
| 442 | |
| 443 | if (nss_capwap_verify_if_num(if_num) == false) { |
| 444 | nss_warning("%p: notify unregister received for invalid interface %d", nss_ctx, if_num); |
| 445 | return NSS_TX_FAILURE_BAD_PARAM; |
| 446 | } |
| 447 | |
| 448 | nss_top = nss_ctx->nss_top; |
| 449 | if (nss_top == NULL) { |
| 450 | nss_warning("%p: notify unregister received for invalid nss_top %d", nss_ctx, if_num); |
| 451 | return NSS_TX_FAILURE_BAD_PARAM; |
| 452 | } |
| 453 | |
| 454 | index = if_num - NSS_DYNAMIC_IF_START; |
| 455 | spin_lock(&nss_capwap_spinlock); |
| 456 | if (nss_capwap_hdl[index] == NULL) { |
| 457 | spin_unlock(&nss_capwap_spinlock); |
| 458 | nss_warning("%p: notify unregister received for unallocated if_num: %d", nss_ctx, if_num); |
| 459 | return NSS_TX_FAILURE_BAD_PARAM; |
| 460 | } |
| 461 | |
| 462 | /* |
| 463 | * It's the responsibility of caller to wait and call us again. We return failure saying |
| 464 | * that we can't remove msg handler now. |
| 465 | */ |
Saurabh Misra | f4a0563 | 2015-02-27 17:49:41 -0800 | [diff] [blame] | 466 | if (nss_capwap_refcnt(if_num) != 0) { |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 467 | spin_unlock(&nss_capwap_spinlock); |
| 468 | nss_warning("%p: notify unregister tunnel %d: has reference", nss_ctx, if_num); |
| 469 | return NSS_TX_FAILURE_QUEUE; |
| 470 | } |
| 471 | |
| 472 | nss_capwap_set_msg_callback(if_num, NULL, NULL); |
| 473 | spin_unlock(&nss_capwap_spinlock); |
| 474 | |
| 475 | return NSS_TX_SUCCESS; |
| 476 | } |
| 477 | EXPORT_SYMBOL(nss_capwap_notify_unregister); |
| 478 | |
| 479 | /* |
| 480 | * nss_capwap_data_register() |
| 481 | * Registers a data packet notifier with NSS FW. |
| 482 | */ |
Sundarajan Srinivasan | 7037484 | 2014-11-19 15:22:52 -0800 | [diff] [blame] | 483 | struct nss_ctx_instance *nss_capwap_data_register(uint32_t if_num, nss_capwap_buf_callback_t cb, struct net_device *netdev, uint32_t features) |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 484 | { |
| 485 | struct nss_ctx_instance *nss_ctx; |
| 486 | int core_status; |
| 487 | |
| 488 | nss_ctx = nss_capwap_get_ctx(); |
| 489 | if (nss_capwap_verify_if_num(if_num) == false) { |
| 490 | nss_warning("%p: data register received for invalid interface %d", nss_ctx, if_num); |
| 491 | return NULL; |
| 492 | } |
| 493 | |
| 494 | spin_lock(&nss_capwap_spinlock); |
Sundarajan Srinivasan | 7037484 | 2014-11-19 15:22:52 -0800 | [diff] [blame] | 495 | if (nss_ctx->nss_top->subsys_dp_register[if_num].ndev != NULL) { |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 496 | spin_unlock(&nss_capwap_spinlock); |
| 497 | return NULL; |
| 498 | } |
| 499 | spin_unlock(&nss_capwap_spinlock); |
| 500 | |
| 501 | core_status = nss_core_register_handler(if_num, nss_capwap_msg_handler, NULL); |
| 502 | if (core_status != NSS_CORE_STATUS_SUCCESS) { |
| 503 | nss_warning("%p: nss core register handler failed for if_num:%d with error :%d", nss_ctx, if_num, core_status); |
| 504 | return NULL; |
| 505 | } |
| 506 | |
| 507 | if (nss_capwap_instance_alloc(nss_ctx, if_num) == false) { |
| 508 | nss_warning("%p: couldn't allocate tunnel instance for if_num:%d", nss_ctx, if_num); |
| 509 | return NULL; |
| 510 | } |
| 511 | |
Sundarajan Srinivasan | 7037484 | 2014-11-19 15:22:52 -0800 | [diff] [blame] | 512 | nss_ctx->nss_top->subsys_dp_register[if_num].cb = cb; |
| 513 | nss_ctx->nss_top->subsys_dp_register[if_num].app_data = NULL; |
| 514 | nss_ctx->nss_top->subsys_dp_register[if_num].ndev = netdev; |
| 515 | nss_ctx->nss_top->subsys_dp_register[if_num].features = features; |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 516 | |
| 517 | return nss_ctx; |
| 518 | } |
| 519 | EXPORT_SYMBOL(nss_capwap_data_register); |
| 520 | |
| 521 | /* |
| 522 | * nss_capwap_data_unregister() |
| 523 | * Unregister a data packet notifier with NSS FW |
| 524 | */ |
| 525 | bool nss_capwap_data_unregister(uint32_t if_num) |
| 526 | { |
| 527 | struct nss_ctx_instance *nss_ctx; |
| 528 | struct nss_capwap_handle *h; |
| 529 | |
| 530 | nss_ctx = nss_capwap_get_ctx(); |
| 531 | if (nss_capwap_verify_if_num(if_num) == false) { |
| 532 | nss_warning("%p: data unregister received for invalid interface %d", nss_ctx, if_num); |
| 533 | return false; |
| 534 | } |
| 535 | |
| 536 | spin_lock(&nss_capwap_spinlock); |
| 537 | /* |
| 538 | * It's the responsibility of caller to wait and call us again. |
| 539 | */ |
Saurabh Misra | f4a0563 | 2015-02-27 17:49:41 -0800 | [diff] [blame] | 540 | if (nss_capwap_refcnt(if_num) != 0) { |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 541 | spin_unlock(&nss_capwap_spinlock); |
| 542 | nss_warning("%p: notify unregister tunnel %d: has reference", nss_ctx, if_num); |
| 543 | return false; |
| 544 | } |
| 545 | h = nss_capwap_hdl[if_num - NSS_DYNAMIC_IF_START]; |
| 546 | nss_capwap_hdl[if_num - NSS_DYNAMIC_IF_START] = NULL; |
| 547 | spin_unlock(&nss_capwap_spinlock); |
| 548 | |
| 549 | (void) nss_core_unregister_handler(if_num); |
| 550 | |
Sundarajan Srinivasan | 7037484 | 2014-11-19 15:22:52 -0800 | [diff] [blame] | 551 | nss_ctx->nss_top->subsys_dp_register[if_num].cb = NULL; |
| 552 | nss_ctx->nss_top->subsys_dp_register[if_num].app_data = NULL; |
| 553 | nss_ctx->nss_top->subsys_dp_register[if_num].ndev = NULL; |
| 554 | nss_ctx->nss_top->subsys_dp_register[if_num].features = 0; |
| 555 | |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 556 | kfree(h); |
| 557 | return true; |
| 558 | } |
| 559 | EXPORT_SYMBOL(nss_capwap_data_unregister); |
| 560 | |
| 561 | /* |
| 562 | * nss_capwap_get_ctx() |
| 563 | * Return a CAPWAP NSS context. |
| 564 | */ |
| 565 | struct nss_ctx_instance *nss_capwap_get_ctx() |
| 566 | { |
| 567 | struct nss_ctx_instance *nss_ctx; |
| 568 | |
| 569 | nss_ctx = &nss_top_main.nss[nss_top_main.capwap_handler_id]; |
| 570 | return nss_ctx; |
| 571 | } |
| 572 | EXPORT_SYMBOL(nss_capwap_get_ctx); |
| 573 | |
| 574 | /* |
Stephen Wang | 1f6ad49 | 2016-01-27 23:42:06 -0800 | [diff] [blame] | 575 | * nss_capwap_ifnum_with_core_id() |
| 576 | * Append core id to capwap interface num |
| 577 | */ |
| 578 | int nss_capwap_ifnum_with_core_id(int if_num) |
| 579 | { |
| 580 | struct nss_ctx_instance *nss_ctx = nss_capwap_get_ctx(); |
| 581 | |
| 582 | NSS_VERIFY_CTX_MAGIC(nss_ctx); |
| 583 | if (nss_is_dynamic_interface(if_num) == false) { |
| 584 | nss_info("%p: Invalid if_num: %d, must be a dynamic interface\n", nss_ctx, if_num); |
| 585 | return 0; |
| 586 | } |
| 587 | return NSS_INTERFACE_NUM_APPEND_COREID(nss_ctx, if_num); |
| 588 | } |
| 589 | EXPORT_SYMBOL(nss_capwap_ifnum_with_core_id); |
| 590 | |
| 591 | /* |
Sundarajan Srinivasan | 40bea95 | 2014-12-02 13:19:34 -0800 | [diff] [blame] | 592 | * nss_capwap_get_max_buf_size() |
| 593 | * Return a CAPWAP NSS max_buf_size. |
| 594 | */ |
| 595 | uint32_t nss_capwap_get_max_buf_size(struct nss_ctx_instance *nss_ctx) |
| 596 | { |
| 597 | return nss_core_get_max_buf_size(nss_ctx); |
| 598 | } |
| 599 | EXPORT_SYMBOL(nss_capwap_get_max_buf_size); |
| 600 | |
| 601 | /* |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 602 | * nss_capwap_init() |
| 603 | * Initializes CAPWAP. Gets called from nss_init.c |
| 604 | */ |
| 605 | void nss_capwap_init() |
| 606 | { |
| 607 | memset(&nss_capwap_hdl, 0, sizeof(nss_capwap_hdl)); |
| 608 | } |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 609 | |
| 610 | /* |
| 611 | * nss_capwap_msg_init() |
| 612 | * Initialize capwap message. |
| 613 | */ |
| 614 | void nss_capwap_msg_init(struct nss_capwap_msg *ncm, uint16_t if_num, uint32_t type, uint32_t len, |
Sundarajan Srinivasan | 30a53d4 | 2015-01-30 10:52:08 -0800 | [diff] [blame] | 615 | nss_capwap_msg_callback_t cb, void *app_data) |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 616 | { |
| 617 | nss_cmn_msg_init(&ncm->cm, if_num, type, len, (void*)cb, app_data); |
| 618 | } |
| 619 | EXPORT_SYMBOL(nss_capwap_msg_init); |