blob: 2129db4a3b052c2f18080876fc8905aed840b576 [file] [log] [blame]
Shyam Sunder66e889d2015-11-02 15:31:20 +05301/*
2 **************************************************************************
Aniruddha Paul38d72f42019-08-20 16:51:31 +05303 * Copyright (c) 2015-2019, The Linux Foundation. All rights reserved.
Shyam Sunder66e889d2015-11-02 15:31:20 +05304 * 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 Huang8c107082017-07-24 14:58:26 -070019#include "nss_pptp_stats.h"
Sachin Shashidhar94beadf2018-08-08 11:43:54 -070020#include "nss_pptp_log.h"
Shyam Sunder66e889d2015-11-02 15:31:20 +053021
Shyam Sundere351f1b2015-12-17 14:11:51 +053022#define NSS_PPTP_TX_TIMEOUT 3000 /* 3 Seconds */
23
Shyam Sunder66e889d2015-11-02 15:31:20 +053024/*
25 * Data structures to store pptp nss debug stats
26 */
27static DEFINE_SPINLOCK(nss_pptp_session_debug_stats_lock);
Yu Huang8c107082017-07-24 14:58:26 -070028static struct nss_pptp_stats_session_debug nss_pptp_session_debug_stats[NSS_MAX_PPTP_DYNAMIC_INTERFACES];
Shyam Sunder66e889d2015-11-02 15:31:20 +053029
30/*
Shyam Sundere351f1b2015-12-17 14:11:51 +053031 * Private data structure
32 */
33static 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 Sunder66e889d2015-11-02 15:31:20 +053042 * nss_pptp_session_debug_stats_sync
43 * Per session debug stats for pptp
44 */
Swaraj Sha11f9e7c2018-08-21 17:53:49 +053045void 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 Sunder66e889d2015-11-02 15:31:20 +053047{
Swaraj Sha11f9e7c2018-08-21 17:53:49 +053048 int i, j, if_type;
49
50 if_type = nss_dynamic_interface_get_type(nss_pptp_get_context(), if_num);
Shyam Sunder66e889d2015-11-02 15:31:20 +053051 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 Sunder66e889d2015-11-02 15:31:20 +053054 break;
55 }
56 }
Swaraj Sha11f9e7c2018-08-21 17:53:49 +053057
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 Sunder66e889d2015-11-02 15:31:20 +0530114 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 */
121void nss_pptp_session_debug_stats_get(void *stats_mem)
122{
Yu Huang8c107082017-07-24 14:58:26 -0700123 struct nss_pptp_stats_session_debug *stats = (struct nss_pptp_stats_session_debug *)stats_mem;
Shyam Sunder66e889d2015-11-02 15:31:20 +0530124 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 Huang8c107082017-07-24 14:58:26 -0700134 memcpy(stats, &nss_pptp_session_debug_stats[i], sizeof(struct nss_pptp_stats_session_debug));
Shyam Sunder66e889d2015-11-02 15:31:20 +0530135 stats++;
136 }
137 }
138 spin_unlock_bh(&nss_pptp_session_debug_stats_lock);
139}
140
141/*
Swaraj Sha11f9e7c2018-08-21 17:53:49 +0530142 * nss_pptp_verify_if_num()
143 * Verify if_num passed to us.
144 */
145static 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 Sunder66e889d2015-11-02 15:31:20 +0530165 * nss_pptp_handler()
166 * Handle NSS -> HLOS messages for pptp tunnel
167 */
168static 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 Sha11f9e7c2018-08-21 17:53:49 +0530175 BUG_ON(!nss_pptp_verify_if_num(ncm->interface));
Shyam Sunder66e889d2015-11-02 15:31:20 +0530176
177 /*
Sachin Shashidhar94beadf2018-08-08 11:43:54 -0700178 * Trace Messages
179 */
180 nss_pptp_log_rx_msg(ntm);
181
182 /*
Shyam Sunder66e889d2015-11-02 15:31:20 +0530183 * 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 Agarwalef8a8702016-01-08 12:40:08 -0800190 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 Sunder66e889d2015-11-02 15:31:20 +0530192 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 Agarwale4ad24a2018-06-11 12:03:46 +0530209 if (ncm->response == NSS_CMN_RESPONSE_NOTIFY) {
Stephen Wangaed46332016-12-12 17:29:03 -0800210 ncm->cb = (nss_ptr_t)nss_ctx->nss_top->pptp_msg_callback;
Stephen Wang84e0e992016-09-07 12:31:40 -0700211 ncm->app_data = (nss_ptr_t)nss_ctx->subsys_dp_register[ncm->interface].app_data;
Shyam Sunder66e889d2015-11-02 15:31:20 +0530212 }
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 Sundere351f1b2015-12-17 14:11:51 +0530230 ctx = (void *)ncm->app_data;
Shyam Sunder66e889d2015-11-02 15:31:20 +0530231
232 /*
233 * call pptp tunnel callback
234 */
Shyam Sundere351f1b2015-12-17 14:11:51 +0530235 if (!cb) {
Shyam Sunder66e889d2015-11-02 15:31:20 +0530236 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 Sundere351f1b2015-12-17 14:11:51 +0530244 * nss_pptp_tx_msg()
Shyam Sunder66e889d2015-11-02 15:31:20 +0530245 * Transmit a pptp message to NSS firmware
246 */
Shyam Sundere351f1b2015-12-17 14:11:51 +0530247static nss_tx_status_t nss_pptp_tx_msg(struct nss_ctx_instance *nss_ctx, struct nss_pptp_msg *msg)
Shyam Sunder66e889d2015-11-02 15:31:20 +0530248{
Shyam Sunder66e889d2015-11-02 15:31:20 +0530249 struct nss_cmn_msg *ncm = &msg->cm;
Shyam Sunder66e889d2015-11-02 15:31:20 +0530250
251 /*
Sachin Shashidhar94beadf2018-08-08 11:43:54 -0700252 * Trace Messages
253 */
254 nss_pptp_log_tx_msg(msg);
255
256 /*
Shyam Sunder66e889d2015-11-02 15:31:20 +0530257 * 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 Wang3e2dbd12018-03-14 17:28:17 -0700269 return nss_core_send_cmd(nss_ctx, msg, sizeof(*msg), NSS_NBUF_PAYLOAD_SIZE);
Shyam Sunder66e889d2015-11-02 15:31:20 +0530270}
271
272/*
Shyam Sundere351f1b2015-12-17 14:11:51 +0530273 * nss_pptp_sync_msg_callback()
274 * Callback to handle the completion of NSS->HLOS messages.
Shyam Sunder66e889d2015-11-02 15:31:20 +0530275 */
Shyam Sundere351f1b2015-12-17 14:11:51 +0530276static 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 */
308nss_tx_status_t nss_pptp_tx_msg_sync(struct nss_ctx_instance *nss_ctx, struct nss_pptp_msg *msg)
Shyam Sunder66e889d2015-11-02 15:31:20 +0530309{
310
Shyam Sundere351f1b2015-12-17 14:11:51 +0530311 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 Wangaed46332016-12-12 17:29:03 -0800318 msg->cm.cb = (nss_ptr_t)nss_pptp_sync_msg_callback;
319 msg->cm.app_data = (nss_ptr_t)NULL;
Shyam Sundere351f1b2015-12-17 14:11:51 +0530320
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 */
344nss_tx_status_t nss_pptp_tx_buf(struct nss_ctx_instance *nss_ctx, uint32_t if_num, struct sk_buff *skb)
345{
Shyam Sundere351f1b2015-12-17 14:11:51 +0530346 nss_trace("%p: pptp If Tx packet, id:%d, data=%p", nss_ctx, if_num, skb->data);
347
Aniruddha Paul38d72f42019-08-20 16:51:31 +0530348 return nss_core_send_packet(nss_ctx, skb, if_num, H2N_BIT_FLAG_BUFFER_REUSABLE);
Shyam Sundere351f1b2015-12-17 14:11:51 +0530349}
350
351/*
352 * nss_register_pptp_if()
353 */
354struct nss_ctx_instance *nss_register_pptp_if(uint32_t if_num,
Swaraj Sha11f9e7c2018-08-21 17:53:49 +0530355 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 Sundere351f1b2015-12-17 14:11:51 +0530361{
Stephen Wang84e0e992016-09-07 12:31:40 -0700362 struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.pptp_handler_id];
Shyam Sundere351f1b2015-12-17 14:11:51 +0530363 int i = 0;
Stephen Wang84e0e992016-09-07 12:31:40 -0700364
365 nss_assert(nss_ctx);
Swaraj Sha11f9e7c2018-08-21 17:53:49 +0530366 nss_assert(nss_pptp_verify_if_num());
367
368 nss_ctx->subsys_dp_register[if_num].type = type;
Shyam Sunder66e889d2015-11-02 15:31:20 +0530369
Jackson Bockus7ca70ec2017-07-17 13:47:29 -0700370 nss_core_register_subsys_dp(nss_ctx, if_num, pptp_data_callback, NULL, app_ctx, netdev, features);
Shyam Sunder66e889d2015-11-02 15:31:20 +0530371
Shyam Sundere351f1b2015-12-17 14:11:51 +0530372 nss_top_main.pptp_msg_callback = notification_callback;
Shyam Sunder66e889d2015-11-02 15:31:20 +0530373
Thomas Wu91f4bdf2017-06-09 12:03:02 -0700374 nss_core_register_handler(nss_ctx, if_num, nss_pptp_handler, NULL);
Shyam Sunder66e889d2015-11-02 15:31:20 +0530375
Shyam Sundere351f1b2015-12-17 14:11:51 +0530376 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 Wang84e0e992016-09-07 12:31:40 -0700387 return nss_ctx;
Shyam Sunder66e889d2015-11-02 15:31:20 +0530388}
389
390/*
391 * nss_unregister_pptp_if()
392 */
393void nss_unregister_pptp_if(uint32_t if_num)
394{
Stephen Wang84e0e992016-09-07 12:31:40 -0700395 struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.pptp_handler_id];
Shyam Sundere351f1b2015-12-17 14:11:51 +0530396 int i;
adil irfanb9a45f02018-04-09 19:13:53 +0530397 int j;
Shyam Sundere351f1b2015-12-17 14:11:51 +0530398
Stephen Wang84e0e992016-09-07 12:31:40 -0700399 nss_assert(nss_ctx);
Shyam Sunder66e889d2015-11-02 15:31:20 +0530400 nss_assert(nss_is_dynamic_interface(if_num));
401
Shyam Sundere351f1b2015-12-17 14:11:51 +0530402 spin_lock_bh(&nss_pptp_session_debug_stats_lock);
403 for (i = 0; i < NSS_MAX_PPTP_DYNAMIC_INTERFACES; i++) {
adil irfanb9a45f02018-04-09 19:13:53 +0530404 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 Sundere351f1b2015-12-17 14:11:51 +0530413 }
414 spin_unlock_bh(&nss_pptp_session_debug_stats_lock);
415
Jackson Bockus7ca70ec2017-07-17 13:47:29 -0700416 nss_core_unregister_subsys_dp(nss_ctx, if_num);
Shyam Sunder66e889d2015-11-02 15:31:20 +0530417
418 nss_top_main.pptp_msg_callback = NULL;
419
Thomas Wu91f4bdf2017-06-09 12:03:02 -0700420 nss_core_unregister_handler(nss_ctx, if_num);
Shyam Sunder66e889d2015-11-02 15:31:20 +0530421}
422
423/*
424 * nss_get_pptp_context()
425 */
426struct 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 */
435void 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 */
443void nss_pptp_register_handler(void)
444{
Shyam Sundere351f1b2015-12-17 14:11:51 +0530445 int i;
446
Shyam Sunder66e889d2015-11-02 15:31:20 +0530447 nss_info("nss_pptp_register_handler");
Thomas Wu91f4bdf2017-06-09 12:03:02 -0700448 nss_core_register_handler(nss_pptp_get_context(), NSS_PPTP_INTERFACE, nss_pptp_handler, NULL);
Shyam Sundere351f1b2015-12-17 14:11:51 +0530449
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 Huang8c107082017-07-24 14:58:26 -0700460
461 nss_pptp_stats_dentry_create();
Shyam Sunder66e889d2015-11-02 15:31:20 +0530462}
463
464EXPORT_SYMBOL(nss_pptp_get_context);
Shyam Sundere351f1b2015-12-17 14:11:51 +0530465EXPORT_SYMBOL(nss_pptp_tx_msg_sync);
466EXPORT_SYMBOL(nss_pptp_tx_buf);
Shyam Sunder66e889d2015-11-02 15:31:20 +0530467EXPORT_SYMBOL(nss_unregister_pptp_if);
468EXPORT_SYMBOL(nss_pptp_msg_init);
469EXPORT_SYMBOL(nss_register_pptp_if);