Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 3 | * Copyright (c) 2015-2017, The Linux Foundation. All rights reserved. |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [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 | #include <net/sock.h> |
| 18 | #include "nss_tx_rx_common.h" |
| 19 | |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 20 | #define NSS_PPTP_TX_TIMEOUT 3000 /* 3 Seconds */ |
| 21 | |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 22 | /* |
| 23 | * Data structures to store pptp nss debug stats |
| 24 | */ |
| 25 | static DEFINE_SPINLOCK(nss_pptp_session_debug_stats_lock); |
| 26 | static struct nss_stats_pptp_session_debug nss_pptp_session_debug_stats[NSS_MAX_PPTP_DYNAMIC_INTERFACES]; |
| 27 | |
| 28 | /* |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 29 | * Private data structure |
| 30 | */ |
| 31 | static struct nss_pptp_pvt { |
| 32 | struct semaphore sem; |
| 33 | struct completion complete; |
| 34 | int response; |
| 35 | void *cb; |
| 36 | void *app_data; |
| 37 | } pptp_pvt; |
| 38 | |
| 39 | /* |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 40 | * nss_pptp_session_debug_stats_sync |
| 41 | * Per session debug stats for pptp |
| 42 | */ |
| 43 | void nss_pptp_session_debug_stats_sync(struct nss_ctx_instance *nss_ctx, struct nss_pptp_sync_session_stats_msg *stats_msg, uint16_t if_num) |
| 44 | { |
ratheesh kannoth | 93ba95c | 2017-07-13 15:52:52 +0530 | [diff] [blame^] | 45 | int i, j; |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 46 | spin_lock_bh(&nss_pptp_session_debug_stats_lock); |
| 47 | for (i = 0; i < NSS_MAX_PPTP_DYNAMIC_INTERFACES; i++) { |
| 48 | if (nss_pptp_session_debug_stats[i].if_num == if_num) { |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 49 | nss_pptp_session_debug_stats[i].stats[NSS_STATS_PPTP_ENCAP_RX_PACKETS] += stats_msg->encap_stats.rx_packets; |
| 50 | nss_pptp_session_debug_stats[i].stats[NSS_STATS_PPTP_ENCAP_RX_BYTES] += stats_msg->encap_stats.rx_bytes; |
| 51 | nss_pptp_session_debug_stats[i].stats[NSS_STATS_PPTP_ENCAP_TX_PACKETS] += stats_msg->encap_stats.tx_packets; |
| 52 | nss_pptp_session_debug_stats[i].stats[NSS_STATS_PPTP_ENCAP_TX_BYTES] += stats_msg->encap_stats.tx_bytes; |
ratheesh kannoth | 93ba95c | 2017-07-13 15:52:52 +0530 | [diff] [blame^] | 53 | for (j = 0; j < NSS_MAX_NUM_PRI; j++) { |
| 54 | nss_pptp_session_debug_stats[i].stats[NSS_STATS_PPTP_ENCAP_RX_QUEUE_0_DROP + j] += stats_msg->encap_stats.rx_dropped[j]; |
| 55 | } |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 56 | nss_pptp_session_debug_stats[i].stats[NSS_STATS_PPTP_DECAP_RX_PACKETS] += stats_msg->decap_stats.rx_packets; |
| 57 | nss_pptp_session_debug_stats[i].stats[NSS_STATS_PPTP_DECAP_RX_BYTES] += stats_msg->decap_stats.rx_bytes; |
| 58 | nss_pptp_session_debug_stats[i].stats[NSS_STATS_PPTP_DECAP_TX_PACKETS] += stats_msg->decap_stats.tx_packets; |
| 59 | nss_pptp_session_debug_stats[i].stats[NSS_STATS_PPTP_DECAP_TX_BYTES] += stats_msg->decap_stats.tx_bytes; |
ratheesh kannoth | 93ba95c | 2017-07-13 15:52:52 +0530 | [diff] [blame^] | 60 | for (j = 0; j < NSS_MAX_NUM_PRI; j++) { |
| 61 | nss_pptp_session_debug_stats[i].stats[NSS_STATS_PPTP_DECAP_RX_QUEUE_0_DROP + j] += stats_msg->decap_stats.rx_dropped[j]; |
| 62 | } |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 63 | nss_pptp_session_debug_stats[i].stats[NSS_STATS_PPTP_SESSION_ENCAP_HEADROOM_ERR] += stats_msg->exception_events[PPTP_EXCEPTION_EVENT_ENCAP_HEADROOM_ERR]; |
| 64 | nss_pptp_session_debug_stats[i].stats[NSS_STATS_PPTP_SESSION_ENCAP_SMALL_SIZE] += stats_msg->exception_events[PPTP_EXCEPTION_EVENT_ENCAP_SMALL_SIZE]; |
| 65 | nss_pptp_session_debug_stats[i].stats[NSS_STATS_PPTP_SESSION_ENCAP_PNODE_ENQUEUE_FAIL] += stats_msg->exception_events[PPTP_EXCEPTION_EVENT_ENCAP_PNODE_ENQUEUE_FAIL]; |
| 66 | nss_pptp_session_debug_stats[i].stats[NSS_STATS_PPTP_SESSION_DECAP_NO_SEQ_NOR_ACK] += stats_msg->exception_events[PPTP_EXCEPTION_EVENT_DECAP_NO_SEQ_NOR_ACK]; |
| 67 | nss_pptp_session_debug_stats[i].stats[NSS_STATS_PPTP_SESSION_DECAP_INVAL_GRE_FLAGS] += stats_msg->exception_events[PPTP_EXCEPTION_EVENT_DECAP_INVAL_GRE_FLAGS]; |
| 68 | nss_pptp_session_debug_stats[i].stats[NSS_STATS_PPTP_SESSION_DECAP_INVAL_GRE_PROTO] += stats_msg->exception_events[PPTP_EXCEPTION_EVENT_DECAP_INVAL_GRE_PROTO]; |
| 69 | nss_pptp_session_debug_stats[i].stats[NSS_STATS_PPTP_SESSION_DECAP_WRONG_SEQ] += stats_msg->exception_events[PPTP_EXCEPTION_EVENT_DECAP_WRONG_SEQ]; |
| 70 | nss_pptp_session_debug_stats[i].stats[NSS_STATS_PPTP_SESSION_DECAP_INVAL_PPP_HDR] += stats_msg->exception_events[PPTP_EXCEPTION_EVENT_DECAP_INVAL_PPP_HDR]; |
| 71 | nss_pptp_session_debug_stats[i].stats[NSS_STATS_PPTP_SESSION_DECAP_PPP_LCP] += stats_msg->exception_events[PPTP_EXCEPTION_EVENT_DECAP_PPP_LCP]; |
| 72 | nss_pptp_session_debug_stats[i].stats[NSS_STATS_PPTP_SESSION_DECAP_UNSUPPORTED_PPP_PROTO] += stats_msg->exception_events[PPTP_EXCEPTION_EVENT_DECAP_UNSUPPORTED_PPP_PROTO]; |
| 73 | nss_pptp_session_debug_stats[i].stats[NSS_STATS_PPTP_SESSION_DECAP_PNODE_ENQUEUE_FAIL] += stats_msg->exception_events[PPTP_EXCEPTION_EVENT_DECAP_PNODE_ENQUEUE_FAIL]; |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 74 | break; |
| 75 | } |
| 76 | } |
| 77 | spin_unlock_bh(&nss_pptp_session_debug_stats_lock); |
| 78 | } |
| 79 | |
| 80 | /* |
| 81 | * nss_pptp_global_session_stats_get() |
| 82 | * Get session pptp statitics. |
| 83 | */ |
| 84 | void nss_pptp_session_debug_stats_get(void *stats_mem) |
| 85 | { |
| 86 | struct nss_stats_pptp_session_debug *stats = (struct nss_stats_pptp_session_debug *)stats_mem; |
| 87 | int i; |
| 88 | |
| 89 | if (!stats) { |
| 90 | nss_warning("No memory to copy pptp session stats"); |
| 91 | return; |
| 92 | } |
| 93 | |
| 94 | spin_lock_bh(&nss_pptp_session_debug_stats_lock); |
| 95 | for (i = 0; i < NSS_MAX_PPTP_DYNAMIC_INTERFACES; i++) { |
| 96 | if (nss_pptp_session_debug_stats[i].valid) { |
| 97 | memcpy(stats, &nss_pptp_session_debug_stats[i], sizeof(struct nss_stats_pptp_session_debug)); |
| 98 | stats++; |
| 99 | } |
| 100 | } |
| 101 | spin_unlock_bh(&nss_pptp_session_debug_stats_lock); |
| 102 | } |
| 103 | |
| 104 | /* |
| 105 | * nss_pptp_handler() |
| 106 | * Handle NSS -> HLOS messages for pptp tunnel |
| 107 | */ |
| 108 | static void nss_pptp_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data) |
| 109 | { |
| 110 | struct nss_pptp_msg *ntm = (struct nss_pptp_msg *)ncm; |
| 111 | void *ctx; |
| 112 | |
| 113 | nss_pptp_msg_callback_t cb; |
| 114 | |
| 115 | BUG_ON(!(nss_is_dynamic_interface(ncm->interface) || ncm->interface == NSS_PPTP_INTERFACE)); |
| 116 | |
| 117 | /* |
| 118 | * Is this a valid request/response packet? |
| 119 | */ |
| 120 | if (ncm->type >= NSS_PPTP_MSG_MAX) { |
| 121 | nss_warning("%p: received invalid message %d for PPTP interface", nss_ctx, ncm->type); |
| 122 | return; |
| 123 | } |
| 124 | |
Suruchi Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 125 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_pptp_msg)) { |
| 126 | nss_warning("%p: Length of message is greater than required: %d", nss_ctx, nss_cmn_get_msg_len(ncm)); |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 127 | return; |
| 128 | } |
| 129 | |
| 130 | switch (ntm->cm.type) { |
| 131 | |
| 132 | case NSS_PPTP_MSG_SYNC_STATS: |
| 133 | /* |
| 134 | * session debug stats embeded in session stats msg |
| 135 | */ |
| 136 | nss_pptp_session_debug_stats_sync(nss_ctx, &ntm->msg.stats, ncm->interface); |
| 137 | break; |
| 138 | } |
| 139 | |
| 140 | /* |
| 141 | * Update the callback and app_data for NOTIFY messages, pptp sends all notify messages |
| 142 | * to the same callback/app_data. |
| 143 | */ |
| 144 | if (ncm->response == NSS_CMM_RESPONSE_NOTIFY) { |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 145 | ncm->cb = (nss_ptr_t)nss_ctx->nss_top->pptp_msg_callback; |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 146 | ncm->app_data = (nss_ptr_t)nss_ctx->subsys_dp_register[ncm->interface].app_data; |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | /* |
| 150 | * Log failures |
| 151 | */ |
| 152 | nss_core_log_msg_failures(nss_ctx, ncm); |
| 153 | |
| 154 | /* |
| 155 | * Do we have a call back |
| 156 | */ |
| 157 | if (!ncm->cb) { |
| 158 | return; |
| 159 | } |
| 160 | |
| 161 | /* |
| 162 | * callback |
| 163 | */ |
| 164 | cb = (nss_pptp_msg_callback_t)ncm->cb; |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 165 | ctx = (void *)ncm->app_data; |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 166 | |
| 167 | /* |
| 168 | * call pptp tunnel callback |
| 169 | */ |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 170 | if (!cb) { |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 171 | nss_warning("%p: Event received for pptp tunnel interface %d before registration", nss_ctx, ncm->interface); |
| 172 | return; |
| 173 | } |
| 174 | |
| 175 | cb(ctx, ntm); |
| 176 | } |
| 177 | |
| 178 | /* |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 179 | * nss_pptp_tx_msg() |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 180 | * Transmit a pptp message to NSS firmware |
| 181 | */ |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 182 | static nss_tx_status_t nss_pptp_tx_msg(struct nss_ctx_instance *nss_ctx, struct nss_pptp_msg *msg) |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 183 | { |
| 184 | struct nss_pptp_msg *nm; |
| 185 | struct nss_cmn_msg *ncm = &msg->cm; |
| 186 | struct sk_buff *nbuf; |
| 187 | int32_t status; |
| 188 | |
| 189 | NSS_VERIFY_CTX_MAGIC(nss_ctx); |
| 190 | if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) { |
| 191 | nss_warning("%p: pptp msg dropped as core not ready", nss_ctx); |
| 192 | return NSS_TX_FAILURE_NOT_READY; |
| 193 | } |
| 194 | |
| 195 | /* |
| 196 | * Sanity check the message |
| 197 | */ |
| 198 | if (!nss_is_dynamic_interface(ncm->interface)) { |
| 199 | nss_warning("%p: tx request for non dynamic interface: %d", nss_ctx, ncm->interface); |
| 200 | return NSS_TX_FAILURE; |
| 201 | } |
| 202 | |
| 203 | if (ncm->type > NSS_PPTP_MSG_MAX) { |
| 204 | nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type); |
| 205 | return NSS_TX_FAILURE; |
| 206 | } |
| 207 | |
Suruchi Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 208 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_pptp_msg)) { |
| 209 | nss_warning("%p: message length is invalid: %d", nss_ctx, nss_cmn_get_msg_len(ncm)); |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 210 | return NSS_TX_FAILURE; |
| 211 | } |
| 212 | |
| 213 | nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE); |
| 214 | if (unlikely(!nbuf)) { |
| 215 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]); |
| 216 | nss_warning("%p: msg dropped as command allocation failed", nss_ctx); |
| 217 | return NSS_TX_FAILURE; |
| 218 | } |
| 219 | |
| 220 | /* |
| 221 | * Copy the message to our skb |
| 222 | */ |
| 223 | nm = (struct nss_pptp_msg *)skb_put(nbuf, sizeof(struct nss_pptp_msg)); |
| 224 | memcpy(nm, msg, sizeof(struct nss_pptp_msg)); |
| 225 | |
| 226 | status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0); |
| 227 | if (status != NSS_CORE_STATUS_SUCCESS) { |
| 228 | dev_kfree_skb_any(nbuf); |
| 229 | nss_warning("%p: Unable to enqueue 'pptp message'\n", nss_ctx); |
| 230 | if (status == NSS_CORE_STATUS_FAILURE_QUEUE) { |
| 231 | return NSS_TX_FAILURE_QUEUE; |
| 232 | } |
| 233 | return NSS_TX_FAILURE; |
| 234 | } |
| 235 | |
Stephen Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 236 | nss_hal_send_interrupt(nss_ctx, NSS_H2N_INTR_DATA_COMMAND_QUEUE); |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 237 | |
| 238 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]); |
| 239 | return NSS_TX_SUCCESS; |
| 240 | } |
| 241 | |
| 242 | /* |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 243 | * nss_pptp_sync_msg_callback() |
| 244 | * Callback to handle the completion of NSS->HLOS messages. |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 245 | */ |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 246 | static void nss_pptp_sync_msg_callback(void *app_data, struct nss_pptp_msg *nim) |
| 247 | { |
| 248 | nss_pptp_msg_callback_t callback = (nss_pptp_msg_callback_t)pptp_pvt.cb; |
| 249 | void *data = pptp_pvt.app_data; |
| 250 | |
| 251 | pptp_pvt.cb = NULL; |
| 252 | pptp_pvt.app_data = NULL; |
| 253 | |
| 254 | if (nim->cm.response != NSS_CMN_RESPONSE_ACK) { |
| 255 | nss_warning("pptp Error response %d\n", nim->cm.response); |
| 256 | |
| 257 | pptp_pvt.response = NSS_TX_FAILURE; |
| 258 | if (callback) { |
| 259 | callback(data, nim); |
| 260 | } |
| 261 | |
| 262 | complete(&pptp_pvt.complete); |
| 263 | return; |
| 264 | } |
| 265 | |
| 266 | pptp_pvt.response = NSS_TX_SUCCESS; |
| 267 | if (callback) { |
| 268 | callback(data, nim); |
| 269 | } |
| 270 | |
| 271 | complete(&pptp_pvt.complete); |
| 272 | } |
| 273 | |
| 274 | /* |
| 275 | * nss_pptp_tx_msg() |
| 276 | * Transmit a pptp message to NSS firmware synchronously. |
| 277 | */ |
| 278 | nss_tx_status_t nss_pptp_tx_msg_sync(struct nss_ctx_instance *nss_ctx, struct nss_pptp_msg *msg) |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 279 | { |
| 280 | |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 281 | nss_tx_status_t status; |
| 282 | int ret = 0; |
| 283 | |
| 284 | down(&pptp_pvt.sem); |
| 285 | pptp_pvt.cb = (void *)msg->cm.cb; |
| 286 | pptp_pvt.app_data = (void *)msg->cm.app_data; |
| 287 | |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 288 | msg->cm.cb = (nss_ptr_t)nss_pptp_sync_msg_callback; |
| 289 | msg->cm.app_data = (nss_ptr_t)NULL; |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 290 | |
| 291 | status = nss_pptp_tx_msg(nss_ctx, msg); |
| 292 | if (status != NSS_TX_SUCCESS) { |
| 293 | nss_warning("%p: pptp_tx_msg failed\n", nss_ctx); |
| 294 | up(&pptp_pvt.sem); |
| 295 | return status; |
| 296 | } |
| 297 | |
| 298 | ret = wait_for_completion_timeout(&pptp_pvt.complete, msecs_to_jiffies(NSS_PPTP_TX_TIMEOUT)); |
| 299 | |
| 300 | if (!ret) { |
| 301 | nss_warning("%p: PPTP msg tx failed due to timeout\n", nss_ctx); |
| 302 | pptp_pvt.response = NSS_TX_FAILURE; |
| 303 | } |
| 304 | |
| 305 | status = pptp_pvt.response; |
| 306 | up(&pptp_pvt.sem); |
| 307 | return status; |
| 308 | } |
| 309 | |
| 310 | /* |
| 311 | * nss_pptp_tx_buf() |
| 312 | * Send packet to pptp interface owned by NSS |
| 313 | */ |
| 314 | nss_tx_status_t nss_pptp_tx_buf(struct nss_ctx_instance *nss_ctx, uint32_t if_num, struct sk_buff *skb) |
| 315 | { |
| 316 | int32_t status; |
| 317 | |
| 318 | nss_trace("%p: pptp If Tx packet, id:%d, data=%p", nss_ctx, if_num, skb->data); |
| 319 | |
| 320 | NSS_VERIFY_CTX_MAGIC(nss_ctx); |
| 321 | if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) { |
| 322 | nss_warning("%p: 'PPTP' packet dropped as core not ready", nss_ctx); |
| 323 | return NSS_TX_FAILURE_NOT_READY; |
| 324 | } |
| 325 | |
| 326 | status = nss_core_send_buffer(nss_ctx, if_num, skb, NSS_IF_DATA_QUEUE_0, H2N_BUFFER_PACKET, H2N_BIT_FLAG_VIRTUAL_BUFFER); |
| 327 | if (unlikely(status != NSS_CORE_STATUS_SUCCESS)) { |
| 328 | nss_warning("%p: Unable to enqueue 'PPTP' packet\n", nss_ctx); |
| 329 | return NSS_TX_FAILURE_QUEUE; |
| 330 | } |
| 331 | |
| 332 | /* |
| 333 | * Kick the NSS awake so it can process our new entry. |
| 334 | */ |
Stephen Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 335 | nss_hal_send_interrupt(nss_ctx, NSS_H2N_INTR_DATA_COMMAND_QUEUE); |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 336 | |
| 337 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_PACKET]); |
| 338 | return NSS_TX_SUCCESS; |
| 339 | } |
| 340 | |
| 341 | /* |
| 342 | * nss_register_pptp_if() |
| 343 | */ |
| 344 | struct nss_ctx_instance *nss_register_pptp_if(uint32_t if_num, |
| 345 | nss_pptp_callback_t pptp_data_callback, |
| 346 | nss_pptp_msg_callback_t notification_callback, |
| 347 | struct net_device *netdev, |
| 348 | uint32_t features, |
| 349 | void *app_ctx) |
| 350 | { |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 351 | struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.pptp_handler_id]; |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 352 | int i = 0; |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 353 | |
| 354 | nss_assert(nss_ctx); |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 355 | nss_assert(nss_is_dynamic_interface(if_num)); |
| 356 | |
Jackson Bockus | 7ca70ec | 2017-07-17 13:47:29 -0700 | [diff] [blame] | 357 | nss_core_register_subsys_dp(nss_ctx, if_num, pptp_data_callback, NULL, app_ctx, netdev, features); |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 358 | |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 359 | nss_top_main.pptp_msg_callback = notification_callback; |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 360 | |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 361 | nss_core_register_handler(nss_ctx, if_num, nss_pptp_handler, NULL); |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 362 | |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 363 | spin_lock_bh(&nss_pptp_session_debug_stats_lock); |
| 364 | for (i = 0; i < NSS_MAX_PPTP_DYNAMIC_INTERFACES; i++) { |
| 365 | if (!nss_pptp_session_debug_stats[i].valid) { |
| 366 | nss_pptp_session_debug_stats[i].valid = true; |
| 367 | nss_pptp_session_debug_stats[i].if_num = if_num; |
| 368 | nss_pptp_session_debug_stats[i].if_index = netdev->ifindex; |
| 369 | break; |
| 370 | } |
| 371 | } |
| 372 | spin_unlock_bh(&nss_pptp_session_debug_stats_lock); |
| 373 | |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 374 | return nss_ctx; |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | /* |
| 378 | * nss_unregister_pptp_if() |
| 379 | */ |
| 380 | void nss_unregister_pptp_if(uint32_t if_num) |
| 381 | { |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 382 | struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.pptp_handler_id]; |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 383 | int i; |
| 384 | |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 385 | nss_assert(nss_ctx); |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 386 | nss_assert(nss_is_dynamic_interface(if_num)); |
| 387 | |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 388 | spin_lock_bh(&nss_pptp_session_debug_stats_lock); |
| 389 | for (i = 0; i < NSS_MAX_PPTP_DYNAMIC_INTERFACES; i++) { |
| 390 | nss_pptp_session_debug_stats[i].valid = false; |
| 391 | nss_pptp_session_debug_stats[i].if_num = 0; |
| 392 | nss_pptp_session_debug_stats[i].if_index = 0; |
| 393 | } |
| 394 | spin_unlock_bh(&nss_pptp_session_debug_stats_lock); |
| 395 | |
Jackson Bockus | 7ca70ec | 2017-07-17 13:47:29 -0700 | [diff] [blame] | 396 | nss_core_unregister_subsys_dp(nss_ctx, if_num); |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 397 | |
| 398 | nss_top_main.pptp_msg_callback = NULL; |
| 399 | |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 400 | nss_core_unregister_handler(nss_ctx, if_num); |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | /* |
| 404 | * nss_get_pptp_context() |
| 405 | */ |
| 406 | struct nss_ctx_instance *nss_pptp_get_context() |
| 407 | { |
| 408 | return (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.pptp_handler_id]; |
| 409 | } |
| 410 | |
| 411 | /* |
| 412 | * nss_pptp_msg_init() |
| 413 | * Initialize nss_pptp msg. |
| 414 | */ |
| 415 | void nss_pptp_msg_init(struct nss_pptp_msg *ncm, uint16_t if_num, uint32_t type, uint32_t len, void *cb, void *app_data) |
| 416 | { |
| 417 | nss_cmn_msg_init(&ncm->cm, if_num, type, len, cb, app_data); |
| 418 | } |
| 419 | |
| 420 | /* nss_pptp_register_handler() |
| 421 | * debugfs stats msg handler received on static pptp interface |
| 422 | */ |
| 423 | void nss_pptp_register_handler(void) |
| 424 | { |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 425 | int i; |
| 426 | |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 427 | nss_info("nss_pptp_register_handler"); |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 428 | nss_core_register_handler(nss_pptp_get_context(), NSS_PPTP_INTERFACE, nss_pptp_handler, NULL); |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 429 | |
| 430 | spin_lock_bh(&nss_pptp_session_debug_stats_lock); |
| 431 | for (i = 0; i < NSS_MAX_PPTP_DYNAMIC_INTERFACES; i++) { |
| 432 | nss_pptp_session_debug_stats[i].valid = false; |
| 433 | nss_pptp_session_debug_stats[i].if_num = 0; |
| 434 | nss_pptp_session_debug_stats[i].if_index = 0; |
| 435 | } |
| 436 | spin_unlock_bh(&nss_pptp_session_debug_stats_lock); |
| 437 | |
| 438 | sema_init(&pptp_pvt.sem, 1); |
| 439 | init_completion(&pptp_pvt.complete); |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | EXPORT_SYMBOL(nss_pptp_get_context); |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 443 | EXPORT_SYMBOL(nss_pptp_tx_msg_sync); |
| 444 | EXPORT_SYMBOL(nss_pptp_tx_buf); |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 445 | EXPORT_SYMBOL(nss_unregister_pptp_if); |
| 446 | EXPORT_SYMBOL(nss_pptp_msg_init); |
| 447 | EXPORT_SYMBOL(nss_register_pptp_if); |