blob: 1945eb67de52c14113a5ae1ddb33627b021430a4 [file] [log] [blame]
Shyam Sunder66e889d2015-11-02 15:31:20 +05301/*
2 **************************************************************************
adil irfanb9a45f02018-04-09 19:13:53 +05303 * Copyright (c) 2015-2018, 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"
Shyam Sunder66e889d2015-11-02 15:31:20 +053020
Shyam Sundere351f1b2015-12-17 14:11:51 +053021#define NSS_PPTP_TX_TIMEOUT 3000 /* 3 Seconds */
22
Shyam Sunder66e889d2015-11-02 15:31:20 +053023/*
24 * Data structures to store pptp nss debug stats
25 */
26static DEFINE_SPINLOCK(nss_pptp_session_debug_stats_lock);
Yu Huang8c107082017-07-24 14:58:26 -070027static struct nss_pptp_stats_session_debug nss_pptp_session_debug_stats[NSS_MAX_PPTP_DYNAMIC_INTERFACES];
Shyam Sunder66e889d2015-11-02 15:31:20 +053028
29/*
Shyam Sundere351f1b2015-12-17 14:11:51 +053030 * Private data structure
31 */
32static 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 Sunder66e889d2015-11-02 15:31:20 +053041 * nss_pptp_session_debug_stats_sync
42 * Per session debug stats for pptp
43 */
44void 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 kannoth93ba95c2017-07-13 15:52:52 +053046 int i, j;
Shyam Sunder66e889d2015-11-02 15:31:20 +053047 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 Huang8c107082017-07-24 14:58:26 -070050 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 kannoth93ba95c2017-07-13 15:52:52 +053054 for (j = 0; j < NSS_MAX_NUM_PRI; j++) {
Yu Huang8c107082017-07-24 14:58:26 -070055 nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_ENCAP_RX_QUEUE_0_DROP + j] += stats_msg->encap_stats.rx_dropped[j];
ratheesh kannoth93ba95c2017-07-13 15:52:52 +053056 }
Yu Huang8c107082017-07-24 14:58:26 -070057 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 kannoth93ba95c2017-07-13 15:52:52 +053061 for (j = 0; j < NSS_MAX_NUM_PRI; j++) {
Yu Huang8c107082017-07-24 14:58:26 -070062 nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_DECAP_RX_QUEUE_0_DROP + j] += stats_msg->decap_stats.rx_dropped[j];
ratheesh kannoth93ba95c2017-07-13 15:52:52 +053063 }
Yu Huang8c107082017-07-24 14:58:26 -070064 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 Sunder66e889d2015-11-02 15:31:20 +053075 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 */
85void nss_pptp_session_debug_stats_get(void *stats_mem)
86{
Yu Huang8c107082017-07-24 14:58:26 -070087 struct nss_pptp_stats_session_debug *stats = (struct nss_pptp_stats_session_debug *)stats_mem;
Shyam Sunder66e889d2015-11-02 15:31:20 +053088 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 Huang8c107082017-07-24 14:58:26 -070098 memcpy(stats, &nss_pptp_session_debug_stats[i], sizeof(struct nss_pptp_stats_session_debug));
Shyam Sunder66e889d2015-11-02 15:31:20 +053099 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 */
109static 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 Agarwalef8a8702016-01-08 12:40:08 -0800126 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 Sunder66e889d2015-11-02 15:31:20 +0530128 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 Wangaed46332016-12-12 17:29:03 -0800146 ncm->cb = (nss_ptr_t)nss_ctx->nss_top->pptp_msg_callback;
Stephen Wang84e0e992016-09-07 12:31:40 -0700147 ncm->app_data = (nss_ptr_t)nss_ctx->subsys_dp_register[ncm->interface].app_data;
Shyam Sunder66e889d2015-11-02 15:31:20 +0530148 }
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 Sundere351f1b2015-12-17 14:11:51 +0530166 ctx = (void *)ncm->app_data;
Shyam Sunder66e889d2015-11-02 15:31:20 +0530167
168 /*
169 * call pptp tunnel callback
170 */
Shyam Sundere351f1b2015-12-17 14:11:51 +0530171 if (!cb) {
Shyam Sunder66e889d2015-11-02 15:31:20 +0530172 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 Sundere351f1b2015-12-17 14:11:51 +0530180 * nss_pptp_tx_msg()
Shyam Sunder66e889d2015-11-02 15:31:20 +0530181 * Transmit a pptp message to NSS firmware
182 */
Shyam Sundere351f1b2015-12-17 14:11:51 +0530183static 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 +0530184{
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 Agarwalef8a8702016-01-08 12:40:08 -0800209 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 Sunder66e889d2015-11-02 15:31:20 +0530211 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 Wang90c67de2016-04-26 15:15:59 -0700237 nss_hal_send_interrupt(nss_ctx, NSS_H2N_INTR_DATA_COMMAND_QUEUE);
Shyam Sunder66e889d2015-11-02 15:31:20 +0530238
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 Sundere351f1b2015-12-17 14:11:51 +0530244 * nss_pptp_sync_msg_callback()
245 * Callback to handle the completion of NSS->HLOS messages.
Shyam Sunder66e889d2015-11-02 15:31:20 +0530246 */
Shyam Sundere351f1b2015-12-17 14:11:51 +0530247static 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 */
279nss_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 +0530280{
281
Shyam Sundere351f1b2015-12-17 14:11:51 +0530282 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 Wangaed46332016-12-12 17:29:03 -0800289 msg->cm.cb = (nss_ptr_t)nss_pptp_sync_msg_callback;
290 msg->cm.app_data = (nss_ptr_t)NULL;
Shyam Sundere351f1b2015-12-17 14:11:51 +0530291
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 */
315nss_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 Wang90c67de2016-04-26 15:15:59 -0700336 nss_hal_send_interrupt(nss_ctx, NSS_H2N_INTR_DATA_COMMAND_QUEUE);
Shyam Sundere351f1b2015-12-17 14:11:51 +0530337
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 */
345struct 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 Wang84e0e992016-09-07 12:31:40 -0700352 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 +0530353 int i = 0;
Stephen Wang84e0e992016-09-07 12:31:40 -0700354
355 nss_assert(nss_ctx);
Shyam Sunder66e889d2015-11-02 15:31:20 +0530356 nss_assert(nss_is_dynamic_interface(if_num));
357
Jackson Bockus7ca70ec2017-07-17 13:47:29 -0700358 nss_core_register_subsys_dp(nss_ctx, if_num, pptp_data_callback, NULL, app_ctx, netdev, features);
Shyam Sunder66e889d2015-11-02 15:31:20 +0530359
Shyam Sundere351f1b2015-12-17 14:11:51 +0530360 nss_top_main.pptp_msg_callback = notification_callback;
Shyam Sunder66e889d2015-11-02 15:31:20 +0530361
Thomas Wu91f4bdf2017-06-09 12:03:02 -0700362 nss_core_register_handler(nss_ctx, if_num, nss_pptp_handler, NULL);
Shyam Sunder66e889d2015-11-02 15:31:20 +0530363
Shyam Sundere351f1b2015-12-17 14:11:51 +0530364 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 Wang84e0e992016-09-07 12:31:40 -0700375 return nss_ctx;
Shyam Sunder66e889d2015-11-02 15:31:20 +0530376}
377
378/*
379 * nss_unregister_pptp_if()
380 */
381void nss_unregister_pptp_if(uint32_t if_num)
382{
Stephen Wang84e0e992016-09-07 12:31:40 -0700383 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 +0530384 int i;
adil irfanb9a45f02018-04-09 19:13:53 +0530385 int j;
Shyam Sundere351f1b2015-12-17 14:11:51 +0530386
Stephen Wang84e0e992016-09-07 12:31:40 -0700387 nss_assert(nss_ctx);
Shyam Sunder66e889d2015-11-02 15:31:20 +0530388 nss_assert(nss_is_dynamic_interface(if_num));
389
Shyam Sundere351f1b2015-12-17 14:11:51 +0530390 spin_lock_bh(&nss_pptp_session_debug_stats_lock);
391 for (i = 0; i < NSS_MAX_PPTP_DYNAMIC_INTERFACES; i++) {
adil irfanb9a45f02018-04-09 19:13:53 +0530392 if (nss_pptp_session_debug_stats[i].valid == true &&
393 nss_pptp_session_debug_stats[i].if_num == if_num) {
394 nss_pptp_session_debug_stats[i].valid = false;
395 nss_pptp_session_debug_stats[i].if_num = 0;
396 nss_pptp_session_debug_stats[i].if_index = 0;
397 for (j = 0; j < NSS_PPTP_STATS_SESSION_MAX; j++)
398 nss_pptp_session_debug_stats[i].stats[j] = 0;
399 break;
400 }
Shyam Sundere351f1b2015-12-17 14:11:51 +0530401 }
402 spin_unlock_bh(&nss_pptp_session_debug_stats_lock);
403
Jackson Bockus7ca70ec2017-07-17 13:47:29 -0700404 nss_core_unregister_subsys_dp(nss_ctx, if_num);
Shyam Sunder66e889d2015-11-02 15:31:20 +0530405
406 nss_top_main.pptp_msg_callback = NULL;
407
Thomas Wu91f4bdf2017-06-09 12:03:02 -0700408 nss_core_unregister_handler(nss_ctx, if_num);
Shyam Sunder66e889d2015-11-02 15:31:20 +0530409}
410
411/*
412 * nss_get_pptp_context()
413 */
414struct nss_ctx_instance *nss_pptp_get_context()
415{
416 return (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.pptp_handler_id];
417}
418
419/*
420 * nss_pptp_msg_init()
421 * Initialize nss_pptp msg.
422 */
423void nss_pptp_msg_init(struct nss_pptp_msg *ncm, uint16_t if_num, uint32_t type, uint32_t len, void *cb, void *app_data)
424{
425 nss_cmn_msg_init(&ncm->cm, if_num, type, len, cb, app_data);
426}
427
428/* nss_pptp_register_handler()
429 * debugfs stats msg handler received on static pptp interface
430 */
431void nss_pptp_register_handler(void)
432{
Shyam Sundere351f1b2015-12-17 14:11:51 +0530433 int i;
434
Shyam Sunder66e889d2015-11-02 15:31:20 +0530435 nss_info("nss_pptp_register_handler");
Thomas Wu91f4bdf2017-06-09 12:03:02 -0700436 nss_core_register_handler(nss_pptp_get_context(), NSS_PPTP_INTERFACE, nss_pptp_handler, NULL);
Shyam Sundere351f1b2015-12-17 14:11:51 +0530437
438 spin_lock_bh(&nss_pptp_session_debug_stats_lock);
439 for (i = 0; i < NSS_MAX_PPTP_DYNAMIC_INTERFACES; i++) {
440 nss_pptp_session_debug_stats[i].valid = false;
441 nss_pptp_session_debug_stats[i].if_num = 0;
442 nss_pptp_session_debug_stats[i].if_index = 0;
443 }
444 spin_unlock_bh(&nss_pptp_session_debug_stats_lock);
445
446 sema_init(&pptp_pvt.sem, 1);
447 init_completion(&pptp_pvt.complete);
Yu Huang8c107082017-07-24 14:58:26 -0700448
449 nss_pptp_stats_dentry_create();
Shyam Sunder66e889d2015-11-02 15:31:20 +0530450}
451
452EXPORT_SYMBOL(nss_pptp_get_context);
Shyam Sundere351f1b2015-12-17 14:11:51 +0530453EXPORT_SYMBOL(nss_pptp_tx_msg_sync);
454EXPORT_SYMBOL(nss_pptp_tx_buf);
Shyam Sunder66e889d2015-11-02 15:31:20 +0530455EXPORT_SYMBOL(nss_unregister_pptp_if);
456EXPORT_SYMBOL(nss_pptp_msg_init);
457EXPORT_SYMBOL(nss_register_pptp_if);