Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Stephen Wang | 3e2dbd1 | 2018-03-14 17:28:17 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2018, 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 | /* |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 18 | * nss_capwap.c |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 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" |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 25 | #include "nss_capwap_stats.h" |
Sachin Shashidhar | e6babc5 | 2018-05-29 15:20:40 -0700 | [diff] [blame] | 26 | #include "nss_capwap_log.h" |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 27 | |
| 28 | /* |
| 29 | * Spinlock for protecting tunnel operations colliding with a tunnel destroy |
| 30 | */ |
| 31 | DEFINE_SPINLOCK(nss_capwap_spinlock); |
| 32 | |
| 33 | /* |
| 34 | * Array of pointer for NSS CAPWAP handles. Each handle has per-tunnel |
| 35 | * stats based on the if_num which is an index. |
| 36 | * |
| 37 | * Per CAPWAP tunnel/interface number instance. |
| 38 | */ |
| 39 | struct nss_capwap_handle { |
| 40 | atomic_t refcnt; /**< Reference count on the tunnel */ |
Saurabh Misra | f4a0563 | 2015-02-27 17:49:41 -0800 | [diff] [blame] | 41 | uint32_t if_num; /**< Interface number */ |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 42 | uint32_t tunnel_status; /**< 0=disable, 1=enabled */ |
| 43 | struct nss_ctx_instance *ctx; /**< Pointer to context */ |
| 44 | nss_capwap_msg_callback_t msg_callback; /**< Msg callback */ |
| 45 | void *app_data; /**< App data (argument) */ |
| 46 | struct nss_capwap_tunnel_stats stats; /**< Stats per-interface number */ |
| 47 | }; |
| 48 | static struct nss_capwap_handle *nss_capwap_hdl[NSS_MAX_DYNAMIC_INTERFACES]; |
| 49 | |
| 50 | /* |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 51 | * nss_capwap_verify_if_num() |
| 52 | * Verify if_num passed to us. |
| 53 | */ |
| 54 | static bool nss_capwap_verify_if_num(uint32_t if_num) |
| 55 | { |
| 56 | if (nss_is_dynamic_interface(if_num) == false) { |
| 57 | return false; |
| 58 | } |
| 59 | |
Stephen Wang | e8b8d0d | 2017-02-24 17:05:22 -0800 | [diff] [blame] | 60 | if (nss_dynamic_interface_get_type(nss_capwap_get_ctx(), if_num) != NSS_DYNAMIC_INTERFACE_TYPE_CAPWAP) { |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 61 | return false; |
| 62 | } |
| 63 | |
| 64 | return true; |
| 65 | } |
| 66 | |
| 67 | /* |
| 68 | * nss_capwap_refcnt_inc() |
| 69 | * Increments refcnt on the tunnel. |
| 70 | */ |
| 71 | static void nss_capwap_refcnt_inc(int32_t if_num) |
| 72 | { |
| 73 | if_num = if_num - NSS_DYNAMIC_IF_START; |
| 74 | atomic_inc(&nss_capwap_hdl[if_num]->refcnt); |
| 75 | nss_assert(atomic_read(&nss_capwap_hdl[if_num]->refcnt) > 0); |
| 76 | } |
| 77 | |
| 78 | /* |
| 79 | * nss_capwap_refcnt_dec() |
| 80 | * Decrements refcnt on the tunnel. |
| 81 | */ |
| 82 | static void nss_capwap_refcnt_dec(int32_t if_num) |
| 83 | { |
| 84 | if_num = if_num - NSS_DYNAMIC_IF_START; |
| 85 | nss_assert(atomic_read(&nss_capwap_hdl[if_num]->refcnt) > 0); |
| 86 | atomic_dec(&nss_capwap_hdl[if_num]->refcnt); |
| 87 | } |
| 88 | |
| 89 | /* |
Saurabh Misra | f4a0563 | 2015-02-27 17:49:41 -0800 | [diff] [blame] | 90 | * nss_capwap_refcnt() |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 91 | * Get refcnt on the tunnel. |
| 92 | */ |
Saurabh Misra | f4a0563 | 2015-02-27 17:49:41 -0800 | [diff] [blame] | 93 | static uint32_t nss_capwap_refcnt(int32_t if_num) |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 94 | { |
| 95 | if_num = if_num - NSS_DYNAMIC_IF_START; |
| 96 | return atomic_read(&nss_capwap_hdl[if_num]->refcnt); |
| 97 | } |
| 98 | |
| 99 | /* |
| 100 | * nss_capwap_set_msg_callback() |
| 101 | * This sets the message callback handler and its associated context |
| 102 | */ |
| 103 | static void nss_capwap_set_msg_callback(int32_t if_num, nss_capwap_msg_callback_t cb, void *app_data) |
| 104 | { |
| 105 | struct nss_capwap_handle *h; |
| 106 | |
| 107 | h = nss_capwap_hdl[if_num - NSS_DYNAMIC_IF_START]; |
| 108 | if (!h) { |
| 109 | return; |
| 110 | } |
| 111 | |
| 112 | h->app_data = app_data; |
| 113 | h->msg_callback = cb; |
| 114 | } |
| 115 | |
| 116 | /* |
Saurabh Misra | 3e9f8b0 | 2015-03-16 13:30:57 -0700 | [diff] [blame] | 117 | * nss_capwap_get_msg_callback() |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 118 | * This gets the message callback handler and its associated context |
| 119 | */ |
Saurabh Misra | 3e9f8b0 | 2015-03-16 13:30:57 -0700 | [diff] [blame] | 120 | 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] | 121 | { |
| 122 | struct nss_capwap_handle *h; |
| 123 | |
| 124 | h = nss_capwap_hdl[if_num - NSS_DYNAMIC_IF_START]; |
| 125 | if (!h) { |
| 126 | *app_data = NULL; |
| 127 | return NULL; |
| 128 | } |
| 129 | |
| 130 | *app_data = h->app_data; |
| 131 | return h->msg_callback; |
| 132 | } |
| 133 | |
| 134 | /* |
| 135 | * nss_capwapmgr_update_stats() |
| 136 | * Update per-tunnel stats for each CAPWAP interface. |
| 137 | */ |
| 138 | static void nss_capwapmgr_update_stats(struct nss_capwap_handle *handle, struct nss_capwap_stats_msg *fstats) |
| 139 | { |
| 140 | struct nss_capwap_tunnel_stats *stats; |
| 141 | |
| 142 | stats = &handle->stats; |
| 143 | |
| 144 | stats->rx_segments += fstats->rx_segments; |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 145 | stats->dtls_pkts += fstats->dtls_pkts; |
Saurabh Misra | 6db99b5 | 2014-12-08 10:33:08 -0800 | [diff] [blame] | 146 | |
| 147 | stats->rx_dup_frag += fstats->rx_dup_frag; |
Saurabh Misra | 3f66e87 | 2015-04-03 11:30:42 -0700 | [diff] [blame] | 148 | stats->rx_oversize_drops += fstats->rx_oversize_drops; |
| 149 | stats->rx_frag_timeout_drops += fstats->rx_frag_timeout_drops; |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 150 | stats->rx_queue_full_drops += fstats->rx_queue_full_drops; |
| 151 | stats->rx_n2h_queue_full_drops += fstats->rx_n2h_queue_full_drops; |
| 152 | stats->rx_mem_failure_drops += fstats->rx_mem_failure_drops; |
Saurabh Misra | 3f66e87 | 2015-04-03 11:30:42 -0700 | [diff] [blame] | 153 | stats->rx_csum_drops += fstats->rx_csum_drops; |
| 154 | stats->rx_malformed += fstats->rx_malformed; |
| 155 | stats->rx_frag_gap_drops += fstats->rx_frag_gap_drops; |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 156 | |
Saurabh Misra | 3f66e87 | 2015-04-03 11:30:42 -0700 | [diff] [blame] | 157 | stats->tx_segments += fstats->tx_segments; |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 158 | stats->tx_queue_full_drops += fstats->tx_queue_full_drops; |
| 159 | stats->tx_mem_failure_drops += fstats->tx_mem_failure_drops; |
Saurabh Misra | 3f66e87 | 2015-04-03 11:30:42 -0700 | [diff] [blame] | 160 | stats->tx_dropped_sg_ref += fstats->tx_dropped_sg_ref; |
| 161 | stats->tx_dropped_ver_mis += fstats->tx_dropped_ver_mis; |
| 162 | stats->tx_dropped_hroom += fstats->tx_dropped_hroom; |
| 163 | stats->tx_dropped_dtls += fstats->tx_dropped_dtls; |
| 164 | stats->tx_dropped_nwireless += fstats->tx_dropped_nwireless; |
| 165 | stats->tx_dropped_unalign += fstats->tx_dropped_unalign; |
Saurabh Misra | 6db99b5 | 2014-12-08 10:33:08 -0800 | [diff] [blame] | 166 | |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 167 | /* |
| 168 | * add pnode stats now. |
| 169 | */ |
| 170 | stats->pnode_stats.rx_packets += fstats->pnode_stats.rx_packets; |
| 171 | stats->pnode_stats.rx_bytes += fstats->pnode_stats.rx_bytes; |
ratheesh kannoth | 89948ff | 2017-10-03 08:59:02 +0530 | [diff] [blame] | 172 | stats->pnode_stats.rx_dropped += nss_cmn_rx_dropped_sum(&fstats->pnode_stats); |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 173 | stats->pnode_stats.tx_packets += fstats->pnode_stats.tx_packets; |
| 174 | stats->pnode_stats.tx_bytes += fstats->pnode_stats.tx_bytes; |
| 175 | } |
| 176 | |
| 177 | /* |
| 178 | * nss_capwap_handler() |
| 179 | * Handle NSS -> HLOS messages for CAPWAP |
| 180 | */ |
Saurabh Misra | 3e9f8b0 | 2015-03-16 13:30:57 -0700 | [diff] [blame] | 181 | 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] | 182 | { |
| 183 | struct nss_capwap_msg *ntm = (struct nss_capwap_msg *)ncm; |
| 184 | nss_capwap_msg_callback_t cb; |
| 185 | |
| 186 | /* |
| 187 | * Is this a valid request/response packet? |
| 188 | */ |
| 189 | if (ncm->type > NSS_CAPWAP_MSG_TYPE_MAX) { |
| 190 | nss_warning("%p: received invalid message %d for CAPWAP interface", nss_ctx, ncm->type); |
| 191 | return; |
| 192 | } |
| 193 | |
Suruchi Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 194 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_capwap_msg)) { |
| 195 | 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] | 196 | return; |
| 197 | } |
| 198 | |
| 199 | nss_core_log_msg_failures(nss_ctx, ncm); |
| 200 | |
Sachin Shashidhar | e6babc5 | 2018-05-29 15:20:40 -0700 | [diff] [blame] | 201 | /* |
| 202 | * Trace messages. |
| 203 | */ |
| 204 | nss_capwap_log_rx_msg(ntm); |
| 205 | |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 206 | switch (ntm->cm.type) { |
| 207 | case NSS_CAPWAP_MSG_TYPE_SYNC_STATS: { |
| 208 | uint32_t if_num; |
| 209 | |
| 210 | if_num = ncm->interface - NSS_DYNAMIC_IF_START; |
| 211 | if (nss_capwap_hdl[if_num] != NULL) { |
| 212 | nss_capwapmgr_update_stats(nss_capwap_hdl[if_num], &ntm->msg.stats); |
| 213 | } |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | /* |
| 218 | * Update the callback and app_data for NOTIFY messages. |
| 219 | */ |
Suruchi Agarwal | e4ad24a | 2018-06-11 12:03:46 +0530 | [diff] [blame] | 220 | if (ncm->response == NSS_CMN_RESPONSE_NOTIFY) { |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 221 | ncm->cb = (nss_ptr_t)nss_capwap_get_msg_callback(ncm->interface, (void **)&ncm->app_data); |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | /* |
| 225 | * Do we have a callback |
| 226 | */ |
| 227 | if (!ncm->cb) { |
| 228 | nss_trace("%p: cb is null for interface %d", nss_ctx, ncm->interface); |
| 229 | return; |
| 230 | } |
| 231 | |
| 232 | cb = (nss_capwap_msg_callback_t)ncm->cb; |
Saurabh Misra | 3e9f8b0 | 2015-03-16 13:30:57 -0700 | [diff] [blame] | 233 | cb((void *)ncm->app_data, ntm); |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | /* |
| 237 | * nss_capwap_instance_alloc() |
| 238 | * Allocate CAPWAP tunnel instance |
| 239 | */ |
| 240 | static bool nss_capwap_instance_alloc(struct nss_ctx_instance *nss_ctx, uint32_t if_num) |
| 241 | { |
| 242 | struct nss_capwap_handle *h; |
| 243 | |
| 244 | /* |
| 245 | * Allocate a handle |
| 246 | */ |
| 247 | h = kmalloc(sizeof(struct nss_capwap_handle), GFP_ATOMIC); |
| 248 | if (h == NULL) { |
| 249 | nss_warning("%p: no memory for allocating CAPWAP instance for interface : %d", nss_ctx, if_num); |
| 250 | return false; |
| 251 | } |
Saurabh Misra | f4a0563 | 2015-02-27 17:49:41 -0800 | [diff] [blame] | 252 | |
| 253 | memset(h, 0, sizeof(struct nss_capwap_handle)); |
| 254 | h->if_num = if_num; |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 255 | |
| 256 | spin_lock(&nss_capwap_spinlock); |
| 257 | if (nss_capwap_hdl[if_num - NSS_DYNAMIC_IF_START] != NULL) { |
| 258 | spin_unlock(&nss_capwap_spinlock); |
| 259 | kfree(h); |
| 260 | nss_warning("%p: Another thread is already allocated instance for :%d", nss_ctx, if_num); |
| 261 | return false; |
| 262 | } |
| 263 | |
| 264 | nss_capwap_hdl[if_num - NSS_DYNAMIC_IF_START] = h; |
| 265 | spin_unlock(&nss_capwap_spinlock); |
| 266 | |
| 267 | return true; |
| 268 | } |
| 269 | |
| 270 | /* |
| 271 | * nss_capwap_tx_msg() |
| 272 | * Transmit a CAPWAP message to NSS FW. Don't call this from softirq/interrupts. |
| 273 | */ |
| 274 | nss_tx_status_t nss_capwap_tx_msg(struct nss_ctx_instance *nss_ctx, struct nss_capwap_msg *msg) |
| 275 | { |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 276 | struct nss_cmn_msg *ncm = &msg->cm; |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 277 | int32_t status; |
| 278 | int32_t if_num; |
| 279 | |
| 280 | BUG_ON(in_interrupt()); |
| 281 | BUG_ON(in_softirq()); |
| 282 | BUG_ON(in_serving_softirq()); |
| 283 | |
| 284 | if (nss_capwap_verify_if_num(msg->cm.interface) == false) { |
| 285 | return NSS_TX_FAILURE_BAD_PARAM; |
| 286 | } |
| 287 | |
| 288 | if (ncm->type >= NSS_CAPWAP_MSG_TYPE_MAX) { |
| 289 | return NSS_TX_FAILURE_BAD_PARAM; |
| 290 | } |
| 291 | |
| 292 | if_num = msg->cm.interface - NSS_DYNAMIC_IF_START; |
| 293 | spin_lock(&nss_capwap_spinlock); |
| 294 | if (!nss_capwap_hdl[if_num]) { |
| 295 | spin_unlock(&nss_capwap_spinlock); |
| 296 | nss_warning("%p: capwap tunnel if_num is not there: %d", nss_ctx, msg->cm.interface); |
| 297 | return NSS_TX_FAILURE_BAD_PARAM; |
| 298 | } |
| 299 | nss_capwap_refcnt_inc(msg->cm.interface); |
| 300 | spin_unlock(&nss_capwap_spinlock); |
| 301 | |
Sachin Shashidhar | e6babc5 | 2018-05-29 15:20:40 -0700 | [diff] [blame] | 302 | /* |
| 303 | * Trace messages. |
| 304 | */ |
| 305 | nss_capwap_log_tx_msg(msg); |
| 306 | |
Stephen Wang | 3e2dbd1 | 2018-03-14 17:28:17 -0700 | [diff] [blame] | 307 | status = nss_core_send_cmd(nss_ctx, msg, sizeof(*msg), NSS_NBUF_PAYLOAD_SIZE); |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 308 | nss_capwap_refcnt_dec(msg->cm.interface); |
| 309 | return status; |
| 310 | } |
| 311 | EXPORT_SYMBOL(nss_capwap_tx_msg); |
| 312 | |
| 313 | /* |
Stephen Wang | cf9c21c | 2016-02-18 17:54:16 -0800 | [diff] [blame] | 314 | * nss_capwap_tx_buf() |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 315 | * Transmit data buffer (skb) to a NSS interface number |
| 316 | */ |
Stephen Wang | cf9c21c | 2016-02-18 17:54:16 -0800 | [diff] [blame] | 317 | 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] | 318 | { |
Stephen Wang | cf9c21c | 2016-02-18 17:54:16 -0800 | [diff] [blame] | 319 | BUG_ON(!nss_capwap_verify_if_num(if_num)); |
| 320 | |
Stephen Wang | 3e2dbd1 | 2018-03-14 17:28:17 -0700 | [diff] [blame] | 321 | return nss_core_send_packet(nss_ctx, os_buf, if_num, H2N_BIT_FLAG_VIRTUAL_BUFFER); |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 322 | } |
Stephen Wang | cf9c21c | 2016-02-18 17:54:16 -0800 | [diff] [blame] | 323 | EXPORT_SYMBOL(nss_capwap_tx_buf); |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 324 | |
| 325 | /* |
| 326 | *********************************** |
| 327 | * Register/Unregister/Miscellaneous APIs |
| 328 | *********************************** |
| 329 | */ |
| 330 | |
| 331 | /* |
| 332 | * nss_capwap_get_stats() |
| 333 | * API for getting stats from a CAPWAP tunnel interface stats |
| 334 | */ |
| 335 | bool nss_capwap_get_stats(uint32_t if_num, struct nss_capwap_tunnel_stats *stats) |
| 336 | { |
| 337 | if (nss_capwap_verify_if_num(if_num) == false) { |
| 338 | return false; |
| 339 | } |
| 340 | |
| 341 | if_num = if_num - NSS_DYNAMIC_IF_START; |
| 342 | spin_lock(&nss_capwap_spinlock); |
| 343 | if (nss_capwap_hdl[if_num] == NULL) { |
| 344 | spin_unlock(&nss_capwap_spinlock); |
| 345 | return false; |
| 346 | } |
| 347 | |
| 348 | memcpy(stats, &nss_capwap_hdl[if_num]->stats, sizeof(struct nss_capwap_tunnel_stats)); |
| 349 | spin_unlock(&nss_capwap_spinlock); |
| 350 | return true; |
| 351 | } |
| 352 | EXPORT_SYMBOL(nss_capwap_get_stats); |
| 353 | |
| 354 | /* |
| 355 | * nss_capwap_notify_register() |
| 356 | * Registers a message notifier with NSS FW. It should not be called from |
| 357 | * softirq or interrupts. |
| 358 | */ |
| 359 | struct nss_ctx_instance *nss_capwap_notify_register(uint32_t if_num, nss_capwap_msg_callback_t cb, void *app_data) |
| 360 | { |
| 361 | struct nss_ctx_instance *nss_ctx; |
| 362 | |
| 363 | nss_ctx = &nss_top_main.nss[nss_top_main.capwap_handler_id]; |
| 364 | |
| 365 | if (nss_capwap_verify_if_num(if_num) == false) { |
| 366 | nss_warning("%p: notfiy register received for invalid interface %d", nss_ctx, if_num); |
| 367 | return NULL; |
| 368 | } |
| 369 | |
| 370 | spin_lock(&nss_capwap_spinlock); |
| 371 | if (nss_capwap_hdl[if_num - NSS_DYNAMIC_IF_START] != NULL) { |
| 372 | spin_unlock(&nss_capwap_spinlock); |
| 373 | nss_warning("%p: notfiy register tunnel already exists for interface %d", nss_ctx, if_num); |
| 374 | return NULL; |
| 375 | } |
| 376 | spin_unlock(&nss_capwap_spinlock); |
| 377 | |
| 378 | return nss_ctx; |
| 379 | } |
| 380 | EXPORT_SYMBOL(nss_capwap_notify_register); |
| 381 | |
| 382 | /* |
| 383 | * nss_capwap_notify_unregister() |
| 384 | * unregister the CAPWAP notifier for the given interface number (if_num). |
| 385 | * It shouldn't be called from softirq or interrupts. |
| 386 | */ |
| 387 | nss_tx_status_t nss_capwap_notify_unregister(struct nss_ctx_instance *nss_ctx, uint32_t if_num) |
| 388 | { |
| 389 | struct nss_top_instance *nss_top; |
| 390 | int index; |
| 391 | |
| 392 | if (nss_capwap_verify_if_num(if_num) == false) { |
| 393 | nss_warning("%p: notify unregister received for invalid interface %d", nss_ctx, if_num); |
| 394 | return NSS_TX_FAILURE_BAD_PARAM; |
| 395 | } |
| 396 | |
| 397 | nss_top = nss_ctx->nss_top; |
| 398 | if (nss_top == NULL) { |
| 399 | nss_warning("%p: notify unregister received for invalid nss_top %d", nss_ctx, if_num); |
| 400 | return NSS_TX_FAILURE_BAD_PARAM; |
| 401 | } |
| 402 | |
| 403 | index = if_num - NSS_DYNAMIC_IF_START; |
| 404 | spin_lock(&nss_capwap_spinlock); |
| 405 | if (nss_capwap_hdl[index] == NULL) { |
| 406 | spin_unlock(&nss_capwap_spinlock); |
| 407 | nss_warning("%p: notify unregister received for unallocated if_num: %d", nss_ctx, if_num); |
| 408 | return NSS_TX_FAILURE_BAD_PARAM; |
| 409 | } |
| 410 | |
| 411 | /* |
| 412 | * It's the responsibility of caller to wait and call us again. We return failure saying |
| 413 | * that we can't remove msg handler now. |
| 414 | */ |
Saurabh Misra | f4a0563 | 2015-02-27 17:49:41 -0800 | [diff] [blame] | 415 | if (nss_capwap_refcnt(if_num) != 0) { |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 416 | spin_unlock(&nss_capwap_spinlock); |
| 417 | nss_warning("%p: notify unregister tunnel %d: has reference", nss_ctx, if_num); |
| 418 | return NSS_TX_FAILURE_QUEUE; |
| 419 | } |
| 420 | |
| 421 | nss_capwap_set_msg_callback(if_num, NULL, NULL); |
| 422 | spin_unlock(&nss_capwap_spinlock); |
| 423 | |
| 424 | return NSS_TX_SUCCESS; |
| 425 | } |
| 426 | EXPORT_SYMBOL(nss_capwap_notify_unregister); |
| 427 | |
| 428 | /* |
| 429 | * nss_capwap_data_register() |
| 430 | * Registers a data packet notifier with NSS FW. |
| 431 | */ |
Sundarajan Srinivasan | 7037484 | 2014-11-19 15:22:52 -0800 | [diff] [blame] | 432 | 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] | 433 | { |
| 434 | struct nss_ctx_instance *nss_ctx; |
| 435 | int core_status; |
| 436 | |
| 437 | nss_ctx = nss_capwap_get_ctx(); |
| 438 | if (nss_capwap_verify_if_num(if_num) == false) { |
| 439 | nss_warning("%p: data register received for invalid interface %d", nss_ctx, if_num); |
| 440 | return NULL; |
| 441 | } |
| 442 | |
| 443 | spin_lock(&nss_capwap_spinlock); |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 444 | if (nss_ctx->subsys_dp_register[if_num].ndev != NULL) { |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 445 | spin_unlock(&nss_capwap_spinlock); |
| 446 | return NULL; |
| 447 | } |
| 448 | spin_unlock(&nss_capwap_spinlock); |
| 449 | |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 450 | core_status = nss_core_register_handler(nss_ctx, if_num, nss_capwap_msg_handler, NULL); |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 451 | if (core_status != NSS_CORE_STATUS_SUCCESS) { |
| 452 | nss_warning("%p: nss core register handler failed for if_num:%d with error :%d", nss_ctx, if_num, core_status); |
| 453 | return NULL; |
| 454 | } |
| 455 | |
| 456 | if (nss_capwap_instance_alloc(nss_ctx, if_num) == false) { |
| 457 | nss_warning("%p: couldn't allocate tunnel instance for if_num:%d", nss_ctx, if_num); |
| 458 | return NULL; |
| 459 | } |
| 460 | |
Jackson Bockus | 7ca70ec | 2017-07-17 13:47:29 -0700 | [diff] [blame] | 461 | nss_core_register_subsys_dp(nss_ctx, if_num, cb, NULL, NULL, netdev, features); |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 462 | |
| 463 | return nss_ctx; |
| 464 | } |
| 465 | EXPORT_SYMBOL(nss_capwap_data_register); |
| 466 | |
| 467 | /* |
| 468 | * nss_capwap_data_unregister() |
| 469 | * Unregister a data packet notifier with NSS FW |
| 470 | */ |
| 471 | bool nss_capwap_data_unregister(uint32_t if_num) |
| 472 | { |
| 473 | struct nss_ctx_instance *nss_ctx; |
| 474 | struct nss_capwap_handle *h; |
| 475 | |
| 476 | nss_ctx = nss_capwap_get_ctx(); |
| 477 | if (nss_capwap_verify_if_num(if_num) == false) { |
| 478 | nss_warning("%p: data unregister received for invalid interface %d", nss_ctx, if_num); |
| 479 | return false; |
| 480 | } |
| 481 | |
| 482 | spin_lock(&nss_capwap_spinlock); |
| 483 | /* |
| 484 | * It's the responsibility of caller to wait and call us again. |
| 485 | */ |
Saurabh Misra | f4a0563 | 2015-02-27 17:49:41 -0800 | [diff] [blame] | 486 | if (nss_capwap_refcnt(if_num) != 0) { |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 487 | spin_unlock(&nss_capwap_spinlock); |
| 488 | nss_warning("%p: notify unregister tunnel %d: has reference", nss_ctx, if_num); |
| 489 | return false; |
| 490 | } |
| 491 | h = nss_capwap_hdl[if_num - NSS_DYNAMIC_IF_START]; |
| 492 | nss_capwap_hdl[if_num - NSS_DYNAMIC_IF_START] = NULL; |
| 493 | spin_unlock(&nss_capwap_spinlock); |
| 494 | |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 495 | (void) nss_core_unregister_handler(nss_ctx, if_num); |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 496 | |
Jackson Bockus | 7ca70ec | 2017-07-17 13:47:29 -0700 | [diff] [blame] | 497 | nss_core_unregister_subsys_dp(nss_ctx, if_num); |
Sundarajan Srinivasan | 7037484 | 2014-11-19 15:22:52 -0800 | [diff] [blame] | 498 | |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 499 | kfree(h); |
| 500 | return true; |
| 501 | } |
| 502 | EXPORT_SYMBOL(nss_capwap_data_unregister); |
| 503 | |
| 504 | /* |
| 505 | * nss_capwap_get_ctx() |
| 506 | * Return a CAPWAP NSS context. |
| 507 | */ |
| 508 | struct nss_ctx_instance *nss_capwap_get_ctx() |
| 509 | { |
| 510 | struct nss_ctx_instance *nss_ctx; |
| 511 | |
| 512 | nss_ctx = &nss_top_main.nss[nss_top_main.capwap_handler_id]; |
| 513 | return nss_ctx; |
| 514 | } |
| 515 | EXPORT_SYMBOL(nss_capwap_get_ctx); |
| 516 | |
| 517 | /* |
Stephen Wang | 1f6ad49 | 2016-01-27 23:42:06 -0800 | [diff] [blame] | 518 | * nss_capwap_ifnum_with_core_id() |
| 519 | * Append core id to capwap interface num |
| 520 | */ |
| 521 | int nss_capwap_ifnum_with_core_id(int if_num) |
| 522 | { |
| 523 | struct nss_ctx_instance *nss_ctx = nss_capwap_get_ctx(); |
| 524 | |
| 525 | NSS_VERIFY_CTX_MAGIC(nss_ctx); |
| 526 | if (nss_is_dynamic_interface(if_num) == false) { |
| 527 | nss_info("%p: Invalid if_num: %d, must be a dynamic interface\n", nss_ctx, if_num); |
| 528 | return 0; |
| 529 | } |
| 530 | return NSS_INTERFACE_NUM_APPEND_COREID(nss_ctx, if_num); |
| 531 | } |
| 532 | EXPORT_SYMBOL(nss_capwap_ifnum_with_core_id); |
| 533 | |
| 534 | /* |
Sundarajan Srinivasan | 40bea95 | 2014-12-02 13:19:34 -0800 | [diff] [blame] | 535 | * nss_capwap_get_max_buf_size() |
| 536 | * Return a CAPWAP NSS max_buf_size. |
| 537 | */ |
| 538 | uint32_t nss_capwap_get_max_buf_size(struct nss_ctx_instance *nss_ctx) |
| 539 | { |
| 540 | return nss_core_get_max_buf_size(nss_ctx); |
| 541 | } |
| 542 | EXPORT_SYMBOL(nss_capwap_get_max_buf_size); |
| 543 | |
| 544 | /* |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 545 | * nss_capwap_init() |
| 546 | * Initializes CAPWAP. Gets called from nss_init.c |
| 547 | */ |
| 548 | void nss_capwap_init() |
| 549 | { |
| 550 | memset(&nss_capwap_hdl, 0, sizeof(nss_capwap_hdl)); |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 551 | nss_capwap_stats_dentry_create(); |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 552 | } |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 553 | |
| 554 | /* |
| 555 | * nss_capwap_msg_init() |
| 556 | * Initialize capwap message. |
| 557 | */ |
| 558 | 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] | 559 | nss_capwap_msg_callback_t cb, void *app_data) |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 560 | { |
| 561 | nss_cmn_msg_init(&ncm->cm, if_num, type, len, (void*)cb, app_data); |
| 562 | } |
| 563 | EXPORT_SYMBOL(nss_capwap_msg_init); |