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