Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Aniruddha Paul | 38d72f4 | 2019-08-20 16:51:31 +0530 | [diff] [blame] | 3 | * Copyright (c) 2015-2019, 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" |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 19 | #include "nss_pptp_stats.h" |
Sachin Shashidhar | 94beadf | 2018-08-08 11:43:54 -0700 | [diff] [blame] | 20 | #include "nss_pptp_log.h" |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 21 | |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 22 | #define NSS_PPTP_TX_TIMEOUT 3000 /* 3 Seconds */ |
| 23 | |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 24 | /* |
| 25 | * Data structures to store pptp nss debug stats |
| 26 | */ |
| 27 | static DEFINE_SPINLOCK(nss_pptp_session_debug_stats_lock); |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 28 | static struct nss_pptp_stats_session_debug nss_pptp_session_debug_stats[NSS_MAX_PPTP_DYNAMIC_INTERFACES]; |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 29 | |
| 30 | /* |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 31 | * Private data structure |
| 32 | */ |
| 33 | static struct nss_pptp_pvt { |
| 34 | struct semaphore sem; |
| 35 | struct completion complete; |
| 36 | int response; |
| 37 | void *cb; |
| 38 | void *app_data; |
| 39 | } pptp_pvt; |
| 40 | |
| 41 | /* |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 42 | * nss_pptp_session_debug_stats_sync |
| 43 | * Per session debug stats for pptp |
| 44 | */ |
Swaraj Sha | 11f9e7c | 2018-08-21 17:53:49 +0530 | [diff] [blame] | 45 | void nss_pptp_session_debug_stats_sync(struct nss_ctx_instance *nss_ctx, |
| 46 | struct nss_pptp_sync_session_stats_msg *stats_msg, uint16_t if_num) |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 47 | { |
Swaraj Sha | 11f9e7c | 2018-08-21 17:53:49 +0530 | [diff] [blame] | 48 | int i, j, if_type; |
| 49 | |
| 50 | if_type = nss_dynamic_interface_get_type(nss_pptp_get_context(), if_num); |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 51 | spin_lock_bh(&nss_pptp_session_debug_stats_lock); |
| 52 | for (i = 0; i < NSS_MAX_PPTP_DYNAMIC_INTERFACES; i++) { |
| 53 | if (nss_pptp_session_debug_stats[i].if_num == if_num) { |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 54 | break; |
| 55 | } |
| 56 | } |
Swaraj Sha | 11f9e7c | 2018-08-21 17:53:49 +0530 | [diff] [blame] | 57 | |
| 58 | if (i == NSS_MAX_PPTP_DYNAMIC_INTERFACES) { |
| 59 | spin_unlock_bh(&nss_pptp_session_debug_stats_lock); |
| 60 | return; |
| 61 | } |
| 62 | |
| 63 | if (if_type == NSS_DYNAMIC_INTERFACE_TYPE_PPTP_OUTER) { |
| 64 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_DECAP_RX_PACKETS] += |
| 65 | stats_msg->node_stats.rx_packets; |
| 66 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_DECAP_RX_BYTES] += |
| 67 | stats_msg->node_stats.rx_bytes; |
| 68 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_DECAP_TX_PACKETS] += |
| 69 | stats_msg->node_stats.tx_packets; |
| 70 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_DECAP_TX_BYTES] += |
| 71 | stats_msg->node_stats.tx_bytes; |
| 72 | for (j = 0; j < NSS_MAX_NUM_PRI; j++) { |
| 73 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_DECAP_RX_QUEUE_0_DROP + j] += |
| 74 | stats_msg->node_stats.rx_dropped[j]; |
| 75 | } |
| 76 | } else { |
| 77 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_ENCAP_RX_PACKETS] += |
| 78 | stats_msg->node_stats.rx_packets; |
| 79 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_ENCAP_RX_BYTES] += |
| 80 | stats_msg->node_stats.rx_bytes; |
| 81 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_ENCAP_TX_PACKETS] += |
| 82 | stats_msg->node_stats.tx_packets; |
| 83 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_ENCAP_TX_BYTES] += |
| 84 | stats_msg->node_stats.tx_bytes; |
| 85 | for (j = 0; j < NSS_MAX_NUM_PRI; j++) { |
| 86 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_ENCAP_RX_QUEUE_0_DROP + j] += |
| 87 | stats_msg->node_stats.rx_dropped[j]; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_SESSION_ENCAP_HEADROOM_ERR] += |
| 92 | stats_msg->exception_events[PPTP_EXCEPTION_EVENT_ENCAP_HEADROOM_ERR]; |
| 93 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_SESSION_ENCAP_SMALL_SIZE] += |
| 94 | stats_msg->exception_events[PPTP_EXCEPTION_EVENT_ENCAP_SMALL_SIZE]; |
| 95 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_SESSION_ENCAP_PNODE_ENQUEUE_FAIL] += |
| 96 | stats_msg->exception_events[PPTP_EXCEPTION_EVENT_ENCAP_PNODE_ENQUEUE_FAIL]; |
| 97 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_SESSION_DECAP_NO_SEQ_NOR_ACK] += |
| 98 | stats_msg->exception_events[PPTP_EXCEPTION_EVENT_DECAP_NO_SEQ_NOR_ACK]; |
| 99 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_SESSION_DECAP_INVAL_GRE_FLAGS] += |
| 100 | stats_msg->exception_events[PPTP_EXCEPTION_EVENT_DECAP_INVAL_GRE_FLAGS]; |
| 101 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_SESSION_DECAP_INVAL_GRE_PROTO] += |
| 102 | stats_msg->exception_events[PPTP_EXCEPTION_EVENT_DECAP_INVAL_GRE_PROTO]; |
| 103 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_SESSION_DECAP_WRONG_SEQ] += |
| 104 | stats_msg->exception_events[PPTP_EXCEPTION_EVENT_DECAP_WRONG_SEQ]; |
| 105 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_SESSION_DECAP_INVAL_PPP_HDR] += |
| 106 | stats_msg->exception_events[PPTP_EXCEPTION_EVENT_DECAP_INVAL_PPP_HDR]; |
| 107 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_SESSION_DECAP_PPP_LCP] += |
| 108 | stats_msg->exception_events[PPTP_EXCEPTION_EVENT_DECAP_PPP_LCP]; |
| 109 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_SESSION_DECAP_UNSUPPORTED_PPP_PROTO] += |
| 110 | stats_msg->exception_events[PPTP_EXCEPTION_EVENT_DECAP_UNSUPPORTED_PPP_PROTO]; |
| 111 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_SESSION_DECAP_PNODE_ENQUEUE_FAIL] += |
| 112 | stats_msg->exception_events[PPTP_EXCEPTION_EVENT_DECAP_PNODE_ENQUEUE_FAIL]; |
| 113 | |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 114 | spin_unlock_bh(&nss_pptp_session_debug_stats_lock); |
| 115 | } |
| 116 | |
| 117 | /* |
| 118 | * nss_pptp_global_session_stats_get() |
| 119 | * Get session pptp statitics. |
| 120 | */ |
| 121 | void nss_pptp_session_debug_stats_get(void *stats_mem) |
| 122 | { |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 123 | struct nss_pptp_stats_session_debug *stats = (struct nss_pptp_stats_session_debug *)stats_mem; |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 124 | int i; |
| 125 | |
| 126 | if (!stats) { |
| 127 | nss_warning("No memory to copy pptp session stats"); |
| 128 | return; |
| 129 | } |
| 130 | |
| 131 | spin_lock_bh(&nss_pptp_session_debug_stats_lock); |
| 132 | for (i = 0; i < NSS_MAX_PPTP_DYNAMIC_INTERFACES; i++) { |
| 133 | if (nss_pptp_session_debug_stats[i].valid) { |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 134 | memcpy(stats, &nss_pptp_session_debug_stats[i], sizeof(struct nss_pptp_stats_session_debug)); |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 135 | stats++; |
| 136 | } |
| 137 | } |
| 138 | spin_unlock_bh(&nss_pptp_session_debug_stats_lock); |
| 139 | } |
| 140 | |
| 141 | /* |
Swaraj Sha | 11f9e7c | 2018-08-21 17:53:49 +0530 | [diff] [blame] | 142 | * nss_pptp_verify_if_num() |
| 143 | * Verify if_num passed to us. |
| 144 | */ |
| 145 | static bool nss_pptp_verify_if_num(uint32_t if_num) |
| 146 | { |
| 147 | uint32_t if_type; |
| 148 | |
| 149 | if (nss_is_dynamic_interface(if_num) == false) { |
| 150 | return false; |
| 151 | } |
| 152 | |
| 153 | if_type = nss_dynamic_interface_get_type(nss_pptp_get_context(), if_num); |
| 154 | switch(if_type) { |
| 155 | case NSS_DYNAMIC_INTERFACE_TYPE_PPTP_INNER: |
| 156 | case NSS_DYNAMIC_INTERFACE_TYPE_PPTP_OUTER: |
| 157 | case NSS_DYNAMIC_INTERFACE_TYPE_PPTP_HOST_INNER: |
| 158 | return true; |
| 159 | } |
| 160 | |
| 161 | return false; |
| 162 | } |
| 163 | |
| 164 | /* |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 165 | * nss_pptp_handler() |
| 166 | * Handle NSS -> HLOS messages for pptp tunnel |
| 167 | */ |
| 168 | static void nss_pptp_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data) |
| 169 | { |
| 170 | struct nss_pptp_msg *ntm = (struct nss_pptp_msg *)ncm; |
| 171 | void *ctx; |
| 172 | |
| 173 | nss_pptp_msg_callback_t cb; |
| 174 | |
Swaraj Sha | 11f9e7c | 2018-08-21 17:53:49 +0530 | [diff] [blame] | 175 | BUG_ON(!nss_pptp_verify_if_num(ncm->interface)); |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 176 | |
| 177 | /* |
Sachin Shashidhar | 94beadf | 2018-08-08 11:43:54 -0700 | [diff] [blame] | 178 | * Trace Messages |
| 179 | */ |
| 180 | nss_pptp_log_rx_msg(ntm); |
| 181 | |
| 182 | /* |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 183 | * Is this a valid request/response packet? |
| 184 | */ |
| 185 | if (ncm->type >= NSS_PPTP_MSG_MAX) { |
| 186 | nss_warning("%p: received invalid message %d for PPTP interface", nss_ctx, ncm->type); |
| 187 | return; |
| 188 | } |
| 189 | |
Suruchi Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 190 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_pptp_msg)) { |
| 191 | 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] | 192 | return; |
| 193 | } |
| 194 | |
| 195 | switch (ntm->cm.type) { |
| 196 | |
| 197 | case NSS_PPTP_MSG_SYNC_STATS: |
| 198 | /* |
| 199 | * session debug stats embeded in session stats msg |
| 200 | */ |
| 201 | nss_pptp_session_debug_stats_sync(nss_ctx, &ntm->msg.stats, ncm->interface); |
| 202 | break; |
| 203 | } |
| 204 | |
| 205 | /* |
| 206 | * Update the callback and app_data for NOTIFY messages, pptp sends all notify messages |
| 207 | * to the same callback/app_data. |
| 208 | */ |
Suruchi Agarwal | e4ad24a | 2018-06-11 12:03:46 +0530 | [diff] [blame] | 209 | if (ncm->response == NSS_CMN_RESPONSE_NOTIFY) { |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 210 | ncm->cb = (nss_ptr_t)nss_ctx->nss_top->pptp_msg_callback; |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 211 | 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] | 212 | } |
| 213 | |
| 214 | /* |
| 215 | * Log failures |
| 216 | */ |
| 217 | nss_core_log_msg_failures(nss_ctx, ncm); |
| 218 | |
| 219 | /* |
| 220 | * Do we have a call back |
| 221 | */ |
| 222 | if (!ncm->cb) { |
| 223 | return; |
| 224 | } |
| 225 | |
| 226 | /* |
| 227 | * callback |
| 228 | */ |
| 229 | cb = (nss_pptp_msg_callback_t)ncm->cb; |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 230 | ctx = (void *)ncm->app_data; |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 231 | |
| 232 | /* |
| 233 | * call pptp tunnel callback |
| 234 | */ |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 235 | if (!cb) { |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 236 | nss_warning("%p: Event received for pptp tunnel interface %d before registration", nss_ctx, ncm->interface); |
| 237 | return; |
| 238 | } |
| 239 | |
| 240 | cb(ctx, ntm); |
| 241 | } |
| 242 | |
| 243 | /* |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 244 | * nss_pptp_tx_msg() |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 245 | * Transmit a pptp message to NSS firmware |
| 246 | */ |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 247 | 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] | 248 | { |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 249 | struct nss_cmn_msg *ncm = &msg->cm; |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 250 | |
| 251 | /* |
Sachin Shashidhar | 94beadf | 2018-08-08 11:43:54 -0700 | [diff] [blame] | 252 | * Trace Messages |
| 253 | */ |
| 254 | nss_pptp_log_tx_msg(msg); |
| 255 | |
| 256 | /* |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 257 | * Sanity check the message |
| 258 | */ |
| 259 | if (!nss_is_dynamic_interface(ncm->interface)) { |
| 260 | nss_warning("%p: tx request for non dynamic interface: %d", nss_ctx, ncm->interface); |
| 261 | return NSS_TX_FAILURE; |
| 262 | } |
| 263 | |
| 264 | if (ncm->type > NSS_PPTP_MSG_MAX) { |
| 265 | nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type); |
| 266 | return NSS_TX_FAILURE; |
| 267 | } |
| 268 | |
Stephen Wang | 3e2dbd1 | 2018-03-14 17:28:17 -0700 | [diff] [blame] | 269 | return nss_core_send_cmd(nss_ctx, msg, sizeof(*msg), NSS_NBUF_PAYLOAD_SIZE); |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | /* |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 273 | * nss_pptp_sync_msg_callback() |
| 274 | * Callback to handle the completion of NSS->HLOS messages. |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 275 | */ |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 276 | static void nss_pptp_sync_msg_callback(void *app_data, struct nss_pptp_msg *nim) |
| 277 | { |
| 278 | nss_pptp_msg_callback_t callback = (nss_pptp_msg_callback_t)pptp_pvt.cb; |
| 279 | void *data = pptp_pvt.app_data; |
| 280 | |
| 281 | pptp_pvt.cb = NULL; |
| 282 | pptp_pvt.app_data = NULL; |
| 283 | |
| 284 | if (nim->cm.response != NSS_CMN_RESPONSE_ACK) { |
| 285 | nss_warning("pptp Error response %d\n", nim->cm.response); |
| 286 | |
| 287 | pptp_pvt.response = NSS_TX_FAILURE; |
| 288 | if (callback) { |
| 289 | callback(data, nim); |
| 290 | } |
| 291 | |
| 292 | complete(&pptp_pvt.complete); |
| 293 | return; |
| 294 | } |
| 295 | |
| 296 | pptp_pvt.response = NSS_TX_SUCCESS; |
| 297 | if (callback) { |
| 298 | callback(data, nim); |
| 299 | } |
| 300 | |
| 301 | complete(&pptp_pvt.complete); |
| 302 | } |
| 303 | |
| 304 | /* |
| 305 | * nss_pptp_tx_msg() |
| 306 | * Transmit a pptp message to NSS firmware synchronously. |
| 307 | */ |
| 308 | 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] | 309 | { |
| 310 | |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 311 | nss_tx_status_t status; |
| 312 | int ret = 0; |
| 313 | |
| 314 | down(&pptp_pvt.sem); |
| 315 | pptp_pvt.cb = (void *)msg->cm.cb; |
| 316 | pptp_pvt.app_data = (void *)msg->cm.app_data; |
| 317 | |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 318 | msg->cm.cb = (nss_ptr_t)nss_pptp_sync_msg_callback; |
| 319 | msg->cm.app_data = (nss_ptr_t)NULL; |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 320 | |
| 321 | status = nss_pptp_tx_msg(nss_ctx, msg); |
| 322 | if (status != NSS_TX_SUCCESS) { |
| 323 | nss_warning("%p: pptp_tx_msg failed\n", nss_ctx); |
| 324 | up(&pptp_pvt.sem); |
| 325 | return status; |
| 326 | } |
| 327 | |
| 328 | ret = wait_for_completion_timeout(&pptp_pvt.complete, msecs_to_jiffies(NSS_PPTP_TX_TIMEOUT)); |
| 329 | |
| 330 | if (!ret) { |
| 331 | nss_warning("%p: PPTP msg tx failed due to timeout\n", nss_ctx); |
| 332 | pptp_pvt.response = NSS_TX_FAILURE; |
| 333 | } |
| 334 | |
| 335 | status = pptp_pvt.response; |
| 336 | up(&pptp_pvt.sem); |
| 337 | return status; |
| 338 | } |
| 339 | |
| 340 | /* |
| 341 | * nss_pptp_tx_buf() |
| 342 | * Send packet to pptp interface owned by NSS |
| 343 | */ |
| 344 | nss_tx_status_t nss_pptp_tx_buf(struct nss_ctx_instance *nss_ctx, uint32_t if_num, struct sk_buff *skb) |
| 345 | { |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 346 | nss_trace("%p: pptp If Tx packet, id:%d, data=%p", nss_ctx, if_num, skb->data); |
| 347 | |
Aniruddha Paul | 38d72f4 | 2019-08-20 16:51:31 +0530 | [diff] [blame] | 348 | return nss_core_send_packet(nss_ctx, skb, if_num, H2N_BIT_FLAG_BUFFER_REUSABLE); |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | /* |
| 352 | * nss_register_pptp_if() |
| 353 | */ |
| 354 | struct nss_ctx_instance *nss_register_pptp_if(uint32_t if_num, |
Swaraj Sha | 11f9e7c | 2018-08-21 17:53:49 +0530 | [diff] [blame] | 355 | uint32_t type, |
| 356 | nss_pptp_callback_t pptp_data_callback, |
| 357 | nss_pptp_msg_callback_t notification_callback, |
| 358 | struct net_device *netdev, |
| 359 | uint32_t features, |
| 360 | void *app_ctx) |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 361 | { |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 362 | 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] | 363 | int i = 0; |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 364 | |
| 365 | nss_assert(nss_ctx); |
Swaraj Sha | 11f9e7c | 2018-08-21 17:53:49 +0530 | [diff] [blame] | 366 | nss_assert(nss_pptp_verify_if_num()); |
| 367 | |
| 368 | nss_ctx->subsys_dp_register[if_num].type = type; |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 369 | |
Jackson Bockus | 7ca70ec | 2017-07-17 13:47:29 -0700 | [diff] [blame] | 370 | 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] | 371 | |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 372 | nss_top_main.pptp_msg_callback = notification_callback; |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 373 | |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 374 | nss_core_register_handler(nss_ctx, if_num, nss_pptp_handler, NULL); |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 375 | |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 376 | spin_lock_bh(&nss_pptp_session_debug_stats_lock); |
| 377 | for (i = 0; i < NSS_MAX_PPTP_DYNAMIC_INTERFACES; i++) { |
| 378 | if (!nss_pptp_session_debug_stats[i].valid) { |
| 379 | nss_pptp_session_debug_stats[i].valid = true; |
| 380 | nss_pptp_session_debug_stats[i].if_num = if_num; |
| 381 | nss_pptp_session_debug_stats[i].if_index = netdev->ifindex; |
| 382 | break; |
| 383 | } |
| 384 | } |
| 385 | spin_unlock_bh(&nss_pptp_session_debug_stats_lock); |
| 386 | |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 387 | return nss_ctx; |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | /* |
| 391 | * nss_unregister_pptp_if() |
| 392 | */ |
| 393 | void nss_unregister_pptp_if(uint32_t if_num) |
| 394 | { |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 395 | 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] | 396 | int i; |
adil irfan | b9a45f0 | 2018-04-09 19:13:53 +0530 | [diff] [blame] | 397 | int j; |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 398 | |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 399 | nss_assert(nss_ctx); |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 400 | nss_assert(nss_is_dynamic_interface(if_num)); |
| 401 | |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 402 | spin_lock_bh(&nss_pptp_session_debug_stats_lock); |
| 403 | for (i = 0; i < NSS_MAX_PPTP_DYNAMIC_INTERFACES; i++) { |
adil irfan | b9a45f0 | 2018-04-09 19:13:53 +0530 | [diff] [blame] | 404 | if (nss_pptp_session_debug_stats[i].valid == true && |
| 405 | nss_pptp_session_debug_stats[i].if_num == if_num) { |
| 406 | nss_pptp_session_debug_stats[i].valid = false; |
| 407 | nss_pptp_session_debug_stats[i].if_num = 0; |
| 408 | nss_pptp_session_debug_stats[i].if_index = 0; |
| 409 | for (j = 0; j < NSS_PPTP_STATS_SESSION_MAX; j++) |
| 410 | nss_pptp_session_debug_stats[i].stats[j] = 0; |
| 411 | break; |
| 412 | } |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 413 | } |
| 414 | spin_unlock_bh(&nss_pptp_session_debug_stats_lock); |
| 415 | |
Jackson Bockus | 7ca70ec | 2017-07-17 13:47:29 -0700 | [diff] [blame] | 416 | nss_core_unregister_subsys_dp(nss_ctx, if_num); |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 417 | |
| 418 | nss_top_main.pptp_msg_callback = NULL; |
| 419 | |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 420 | nss_core_unregister_handler(nss_ctx, if_num); |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | /* |
| 424 | * nss_get_pptp_context() |
| 425 | */ |
| 426 | struct nss_ctx_instance *nss_pptp_get_context() |
| 427 | { |
| 428 | return (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.pptp_handler_id]; |
| 429 | } |
| 430 | |
| 431 | /* |
| 432 | * nss_pptp_msg_init() |
| 433 | * Initialize nss_pptp msg. |
| 434 | */ |
| 435 | 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) |
| 436 | { |
| 437 | nss_cmn_msg_init(&ncm->cm, if_num, type, len, cb, app_data); |
| 438 | } |
| 439 | |
| 440 | /* nss_pptp_register_handler() |
| 441 | * debugfs stats msg handler received on static pptp interface |
| 442 | */ |
| 443 | void nss_pptp_register_handler(void) |
| 444 | { |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 445 | int i; |
| 446 | |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 447 | nss_info("nss_pptp_register_handler"); |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 448 | 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] | 449 | |
| 450 | spin_lock_bh(&nss_pptp_session_debug_stats_lock); |
| 451 | for (i = 0; i < NSS_MAX_PPTP_DYNAMIC_INTERFACES; i++) { |
| 452 | nss_pptp_session_debug_stats[i].valid = false; |
| 453 | nss_pptp_session_debug_stats[i].if_num = 0; |
| 454 | nss_pptp_session_debug_stats[i].if_index = 0; |
| 455 | } |
| 456 | spin_unlock_bh(&nss_pptp_session_debug_stats_lock); |
| 457 | |
| 458 | sema_init(&pptp_pvt.sem, 1); |
| 459 | init_completion(&pptp_pvt.complete); |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 460 | |
| 461 | nss_pptp_stats_dentry_create(); |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | EXPORT_SYMBOL(nss_pptp_get_context); |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 465 | EXPORT_SYMBOL(nss_pptp_tx_msg_sync); |
| 466 | EXPORT_SYMBOL(nss_pptp_tx_buf); |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 467 | EXPORT_SYMBOL(nss_unregister_pptp_if); |
| 468 | EXPORT_SYMBOL(nss_pptp_msg_init); |
| 469 | EXPORT_SYMBOL(nss_register_pptp_if); |