blob: f6ec614b278693fb88037366659e206c1748c9e1 [file] [log] [blame]
Tushar Mathurff8741b2015-12-02 20:28:59 +05301/*
2 **************************************************************************
Stephen Wangaed46332016-12-12 17:29:03 -08003 * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
Tushar Mathurff8741b2015-12-02 20:28:59 +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 "nss_tx_rx_common.h"
18#include "nss_dtls_stats.h"
19
20#define NSS_DTLS_TX_TIMEOUT 3000 /* 3 Seconds */
21
22/*
23 * Data structures to store DTLS nss debug stats
24 */
Yu Huang8c107082017-07-24 14:58:26 -070025static DEFINE_SPINLOCK(nss_dtls_session_stats_lock);
26static struct nss_dtls_stats_session session_stats[NSS_MAX_DTLS_SESSIONS];
Tushar Mathurff8741b2015-12-02 20:28:59 +053027
28/*
29 * Private data structure
30 */
31static struct nss_dtls_pvt {
32 struct semaphore sem;
33 struct completion complete;
34 int response;
35 void *cb;
36 void *app_data;
37} dtls_pvt;
38
Tushar Mathurff8741b2015-12-02 20:28:59 +053039/*
40 * nss_dtls_verify_if_num()
41 * Verify if_num passed to us.
42 */
43static bool nss_dtls_verify_if_num(uint32_t if_num)
44{
45 if (nss_is_dynamic_interface(if_num) == false)
46 return false;
47
Stephen Wange8b8d0d2017-02-24 17:05:22 -080048 if (nss_dynamic_interface_get_type(nss_dtls_get_context(), if_num)
Tushar Mathurff8741b2015-12-02 20:28:59 +053049 != NSS_DYNAMIC_INTERFACE_TYPE_DTLS)
50 return false;
51
52 return true;
53}
54
55/*
56 * nss_dtls_session_stats_sync
57 * Per DTLS session debug stats
58 */
59static void nss_dtls_session_stats_sync(struct nss_ctx_instance *nss_ctx,
60 struct nss_dtls_session_stats *stats_msg,
61 uint16_t if_num)
62{
63 int i;
Yu Huang8c107082017-07-24 14:58:26 -070064 struct nss_dtls_stats_session *s = NULL;
Tushar Mathurff8741b2015-12-02 20:28:59 +053065
66 NSS_VERIFY_CTX_MAGIC(nss_ctx);
67
Yu Huang8c107082017-07-24 14:58:26 -070068 spin_lock_bh(&nss_dtls_session_stats_lock);
Tushar Mathurff8741b2015-12-02 20:28:59 +053069 for (i = 0; i < NSS_MAX_DTLS_SESSIONS; i++) {
Yu Huang8c107082017-07-24 14:58:26 -070070 if (session_stats[i].if_num != if_num) {
Tushar Mathurff8741b2015-12-02 20:28:59 +053071 continue;
72 }
73
Yu Huang8c107082017-07-24 14:58:26 -070074 s = &session_stats[i];
Tushar Mathurff8741b2015-12-02 20:28:59 +053075 break;
76 }
77
78 if (!s) {
Yu Huang8c107082017-07-24 14:58:26 -070079 spin_unlock_bh(&nss_dtls_session_stats_lock);
Tushar Mathurff8741b2015-12-02 20:28:59 +053080 return;
81 }
82
Yu Huang8c107082017-07-24 14:58:26 -070083 s->stats[NSS_DTLS_STATS_SESSION_RX_PKTS] += stats_msg->node_stats.rx_packets;
84 s->stats[NSS_DTLS_STATS_SESSION_TX_PKTS] += stats_msg->node_stats.tx_packets;
ratheesh kannoth93ba95c2017-07-13 15:52:52 +053085 for (i = 0; i < NSS_MAX_NUM_PRI; i++) {
Yu Huang8c107082017-07-24 14:58:26 -070086 s->stats[NSS_DTLS_STATS_SESSION_RX_QUEUE_0_DROPPED + i] += stats_msg->node_stats.rx_dropped[i];
ratheesh kannoth93ba95c2017-07-13 15:52:52 +053087 }
Yu Huang8c107082017-07-24 14:58:26 -070088 s->stats[NSS_DTLS_STATS_SESSION_RX_AUTH_DONE] += stats_msg->rx_auth_done;
89 s->stats[NSS_DTLS_STATS_SESSION_TX_AUTH_DONE] += stats_msg->tx_auth_done;
90 s->stats[NSS_DTLS_STATS_SESSION_RX_CIPHER_DONE] += stats_msg->rx_cipher_done;
91 s->stats[NSS_DTLS_STATS_SESSION_TX_CIPHER_DONE] += stats_msg->tx_cipher_done;
92 s->stats[NSS_DTLS_STATS_SESSION_RX_CBUF_ALLOC_FAIL] += stats_msg->rx_cbuf_alloc_fail;
93 s->stats[NSS_DTLS_STATS_SESSION_TX_CBUF_ALLOC_FAIL] += stats_msg->tx_cbuf_alloc_fail;
94 s->stats[NSS_DTLS_STATS_SESSION_TX_CENQUEUE_FAIL] += stats_msg->tx_cenqueue_fail;
95 s->stats[NSS_DTLS_STATS_SESSION_RX_CENQUEUE_FAIL] += stats_msg->rx_cenqueue_fail;
96 s->stats[NSS_DTLS_STATS_SESSION_TX_DROPPED_HROOM] += stats_msg->tx_dropped_hroom;
97 s->stats[NSS_DTLS_STATS_SESSION_TX_DROPPED_TROOM] += stats_msg->tx_dropped_troom;
98 s->stats[NSS_DTLS_STATS_SESSION_TX_FORWARD_ENQUEUE_FAIL] += stats_msg->tx_forward_enqueue_fail;
99 s->stats[NSS_DTLS_STATS_SESSION_RX_FORWARD_ENQUEUE_FAIL] += stats_msg->rx_forward_enqueue_fail;
100 s->stats[NSS_DTLS_STATS_SESSION_RX_INVALID_VERSION] += stats_msg->rx_invalid_version;
101 s->stats[NSS_DTLS_STATS_SESSION_RX_INVALID_EPOCH] += stats_msg->rx_invalid_epoch;
102 s->stats[NSS_DTLS_STATS_SESSION_RX_MALFORMED] += stats_msg->rx_malformed;
103 s->stats[NSS_DTLS_STATS_SESSION_RX_CIPHER_FAIL] += stats_msg->rx_cipher_fail;
104 s->stats[NSS_DTLS_STATS_SESSION_RX_AUTH_FAIL] += stats_msg->rx_auth_fail;
105 s->stats[NSS_DTLS_STATS_SESSION_RX_CAPWAP_CLASSIFY_FAIL] += stats_msg->rx_capwap_classify_fail;
106 s->stats[NSS_DTLS_STATS_SESSION_RX_SINGLE_REC_DGRAM] += stats_msg->rx_single_rec_dgram;
107 s->stats[NSS_DTLS_STATS_SESSION_RX_MULTI_REC_DGRAM] += stats_msg->rx_multi_rec_dgram;
108 s->stats[NSS_DTLS_STATS_SESSION_RX_REPLAY_FAIL] += stats_msg->rx_replay_fail;
109 s->stats[NSS_DTLS_STATS_SESSION_RX_REPLAY_DUPLICATE] += stats_msg->rx_replay_duplicate;
110 s->stats[NSS_DTLS_STATS_SESSION_RX_REPLAY_OUT_OF_WINDOW] += stats_msg->rx_replay_out_of_window;
111 s->stats[NSS_DTLS_STATS_SESSION_OUTFLOW_QUEUE_FULL] += stats_msg->outflow_queue_full;
112 s->stats[NSS_DTLS_STATS_SESSION_DECAP_QUEUE_FULL] += stats_msg->decap_queue_full;
113 s->stats[NSS_DTLS_STATS_SESSION_PBUF_ALLOC_FAIL] += stats_msg->pbuf_alloc_fail;
114 s->stats[NSS_DTLS_STATS_SESSION_PBUF_COPY_FAIL] += stats_msg->pbuf_copy_fail;
115 s->stats[NSS_DTLS_STATS_SESSION_EPOCH] = stats_msg->epoch;
116 s->stats[NSS_DTLS_STATS_SESSION_TX_SEQ_HIGH] = stats_msg->tx_seq_high;
117 s->stats[NSS_DTLS_STATS_SESSION_TX_SEQ_LOW] = stats_msg->tx_seq_low;
118 spin_unlock_bh(&nss_dtls_session_stats_lock);
Tushar Mathurff8741b2015-12-02 20:28:59 +0530119}
120
121/*
Yu Huang8c107082017-07-24 14:58:26 -0700122 * nss_dtls_session_stats_get()
Tushar Mathurff8741b2015-12-02 20:28:59 +0530123 * Get session DTLS statitics.
124 */
Yu Huang8c107082017-07-24 14:58:26 -0700125void nss_dtls_session_stats_get(struct nss_dtls_stats_session *stats)
Tushar Mathurff8741b2015-12-02 20:28:59 +0530126{
127 int i;
128
129 if (!stats) {
130 nss_warning("No memory to copy dtls session stats");
131 return;
132 }
133
Yu Huang8c107082017-07-24 14:58:26 -0700134 spin_lock_bh(&nss_dtls_session_stats_lock);
Tushar Mathurff8741b2015-12-02 20:28:59 +0530135 for (i = 0; i < NSS_MAX_DTLS_SESSIONS; i++) {
Yu Huang8c107082017-07-24 14:58:26 -0700136 if (session_stats[i].valid) {
137 memcpy(stats, &session_stats[i],
138 sizeof(struct nss_dtls_stats_session));
Tushar Mathurff8741b2015-12-02 20:28:59 +0530139 stats++;
140 }
141 }
Yu Huang8c107082017-07-24 14:58:26 -0700142 spin_unlock_bh(&nss_dtls_session_stats_lock);
Tushar Mathurff8741b2015-12-02 20:28:59 +0530143}
144
145/*
146 * nss_dtls_handler()
147 * Handle NSS -> HLOS messages for dtls tunnel
148 */
149static void nss_dtls_handler(struct nss_ctx_instance *nss_ctx,
150 struct nss_cmn_msg *ncm,
151 __attribute__((unused))void *app_data)
152{
153 struct nss_dtls_msg *ntm = (struct nss_dtls_msg *)ncm;
154 void *ctx;
155
156 nss_dtls_msg_callback_t cb;
157
158 NSS_VERIFY_CTX_MAGIC(nss_ctx);
159 BUG_ON(!nss_dtls_verify_if_num(ncm->interface));
160
161 /*
162 * Is this a valid request/response packet?
163 */
164 if (ncm->type >= NSS_DTLS_MSG_MAX) {
165 nss_warning("%p: received invalid message %d "
166 "for DTLS interface %d",
167 nss_ctx, ncm->type, ncm->interface);
168 return;
169 }
170
Suruchi Agarwalef8a8702016-01-08 12:40:08 -0800171 if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_dtls_msg)) {
Tushar Mathurff8741b2015-12-02 20:28:59 +0530172 nss_warning("%p: dtls message length is invalid: %d",
173 nss_ctx, ncm->len);
174 return;
175 }
176
177 switch (ntm->cm.type) {
178 case NSS_DTLS_MSG_SESSION_STATS:
179 nss_dtls_session_stats_sync(nss_ctx,
180 &ntm->msg.stats,
181 ncm->interface);
182 break;
183 }
184
185 /*
186 * Update the callback and app_data for NOTIFY messages
187 */
188 if (ncm->response == NSS_CMM_RESPONSE_NOTIFY) {
Stephen Wangaed46332016-12-12 17:29:03 -0800189 ncm->cb = (nss_ptr_t)nss_ctx->nss_top->dtls_msg_callback;
Stephen Wang84e0e992016-09-07 12:31:40 -0700190 ncm->app_data = (nss_ptr_t)nss_ctx->subsys_dp_register[ncm->interface].app_data;
Tushar Mathurff8741b2015-12-02 20:28:59 +0530191 }
192
193 /*
194 * Log failures
195 */
196 nss_core_log_msg_failures(nss_ctx, ncm);
197
198 /*
199 * callback
200 */
201 cb = (nss_dtls_msg_callback_t)ncm->cb;
202 ctx = (void *)ncm->app_data;
203
204 /*
205 * call dtls session callback
206 */
207 if (!cb) {
208 nss_warning("%p: No callback for dtls session interface %d",
209 nss_ctx, ncm->interface);
210 return;
211 }
212
213 cb(ctx, ntm);
214}
215
216/*
217 * nss_dtls_callback()
218 * Callback to handle the completion of NSS->HLOS messages.
219 */
220static void nss_dtls_callback(void *app_data, struct nss_dtls_msg *nim)
221{
222 nss_dtls_msg_callback_t callback = (nss_dtls_msg_callback_t)dtls_pvt.cb;
223 void *data = dtls_pvt.app_data;
224
225 dtls_pvt.cb = NULL;
226 dtls_pvt.app_data = NULL;
227
228 if (nim->cm.response != NSS_CMN_RESPONSE_ACK) {
229 nss_warning("dtls Error response %d\n", nim->cm.response);
230
231 dtls_pvt.response = NSS_TX_FAILURE;
232 if (callback) {
233 callback(data, nim);
234 }
235
236 complete(&dtls_pvt.complete);
237 return;
238 }
239
240 dtls_pvt.response = NSS_TX_SUCCESS;
241 if (callback) {
242 callback(data, nim);
243 }
244
245 complete(&dtls_pvt.complete);
246}
247
248/*
249 * nss_dtls_tx_buf()
250 * Transmit buffer over DTLS interface
251 */
252nss_tx_status_t nss_dtls_tx_buf(struct sk_buff *skb, uint32_t if_num,
253 struct nss_ctx_instance *nss_ctx)
254{
255 int32_t status;
Tushar Mathurff8741b2015-12-02 20:28:59 +0530256
257 NSS_VERIFY_CTX_MAGIC(nss_ctx);
258
259 if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
260 nss_warning("%p: 'DTLS If Tx' core not ready", nss_ctx);
261 return NSS_TX_FAILURE_NOT_READY;
262 }
263
264 BUG_ON(!nss_dtls_verify_if_num(if_num));
265
Tushar Mathurff8741b2015-12-02 20:28:59 +0530266 status = nss_core_send_buffer(nss_ctx, if_num, skb,
267 NSS_IF_DATA_QUEUE_0,
268 H2N_BUFFER_PACKET,
269 H2N_BIT_FLAG_VIRTUAL_BUFFER);
270 if (unlikely(status != NSS_CORE_STATUS_SUCCESS)) {
271 nss_warning("%p: Unable to enqueue 'DTLS If Tx' packet\n", nss_ctx);
272 if (status == NSS_CORE_STATUS_FAILURE_QUEUE) {
273 return NSS_TX_FAILURE_QUEUE;
274 }
275
276 return NSS_TX_FAILURE;
277 }
278
Stephen Wang90c67de2016-04-26 15:15:59 -0700279 nss_hal_send_interrupt(nss_ctx, NSS_H2N_INTR_DATA_COMMAND_QUEUE);
Tushar Mathurff8741b2015-12-02 20:28:59 +0530280
281 NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_PACKET]);
282 return NSS_TX_SUCCESS;
283}
284EXPORT_SYMBOL(nss_dtls_tx_buf);
285
286/*
287 * nss_dtls_tx_msg()
288 * Transmit a DTLS message to NSS firmware
289 */
290nss_tx_status_t nss_dtls_tx_msg(struct nss_ctx_instance *nss_ctx,
291 struct nss_dtls_msg *msg)
292{
293 struct nss_dtls_msg *nm;
294 struct nss_cmn_msg *ncm = &msg->cm;
295 struct sk_buff *nbuf;
Tushar Mathurff8741b2015-12-02 20:28:59 +0530296 int32_t status;
297
298 NSS_VERIFY_CTX_MAGIC(nss_ctx);
299 if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
300 nss_warning("%p: dtls msg dropped as core not ready", nss_ctx);
301 return NSS_TX_FAILURE_NOT_READY;
302 }
303
304 /*
305 * Sanity check the message
306 */
307 BUG_ON(!nss_dtls_verify_if_num(ncm->interface));
308
Tushar Mathurff8741b2015-12-02 20:28:59 +0530309 if (ncm->type > NSS_DTLS_MSG_MAX) {
310 nss_warning("%p: dtls message type out of range: %d",
311 nss_ctx, ncm->type);
312 return NSS_TX_FAILURE;
313 }
314
Suruchi Agarwalef8a8702016-01-08 12:40:08 -0800315 if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_dtls_msg)) {
Tushar Mathurff8741b2015-12-02 20:28:59 +0530316 nss_warning("%p: dtls message length is invalid: %d",
317 nss_ctx, ncm->len);
318 return NSS_TX_FAILURE;
319 }
320
321 nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE);
322 if (unlikely(!nbuf)) {
323 NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]);
324 nss_warning("%p: dtls msg dropped as command "
325 "allocation failed", nss_ctx);
326 return NSS_TX_FAILURE;
327 }
328
329 /*
330 * Copy the message to our skb
331 */
332 nm = (struct nss_dtls_msg *)skb_put(nbuf, sizeof(struct nss_dtls_msg));
333 memcpy(nm, msg, sizeof(struct nss_dtls_msg));
334
335 status = nss_core_send_buffer(nss_ctx, 0, nbuf,
336 NSS_IF_CMD_QUEUE,
337 H2N_BUFFER_CTRL, 0);
338 if (status != NSS_CORE_STATUS_SUCCESS) {
339 dev_kfree_skb_any(nbuf);
340 nss_warning("%p: Unable to enqueue 'dtls message'\n", nss_ctx);
341 if (status == NSS_CORE_STATUS_FAILURE_QUEUE) {
342 return NSS_TX_FAILURE_QUEUE;
343 }
344 return NSS_TX_FAILURE;
345 }
346
Stephen Wang90c67de2016-04-26 15:15:59 -0700347 nss_hal_send_interrupt(nss_ctx, NSS_H2N_INTR_DATA_COMMAND_QUEUE);
Tushar Mathurff8741b2015-12-02 20:28:59 +0530348
349 NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]);
350 return NSS_TX_SUCCESS;
351}
352EXPORT_SYMBOL(nss_dtls_tx_msg);
353
354/*
355 * nss_dtls_tx_msg()
356 * Transmit a DTLS message to NSS firmware synchronously.
357 */
358nss_tx_status_t nss_dtls_tx_msg_sync(struct nss_ctx_instance *nss_ctx, struct nss_dtls_msg *msg)
359{
360
361 nss_tx_status_t status;
362 int ret = 0;
363
364 down(&dtls_pvt.sem);
365 dtls_pvt.cb = (void *)msg->cm.cb;
366 dtls_pvt.app_data = (void *)msg->cm.app_data;
367
Stephen Wangaed46332016-12-12 17:29:03 -0800368 msg->cm.cb = (nss_ptr_t)nss_dtls_callback;
369 msg->cm.app_data = (nss_ptr_t)NULL;
Tushar Mathurff8741b2015-12-02 20:28:59 +0530370
371 status = nss_dtls_tx_msg(nss_ctx, msg);
372 if (status != NSS_TX_SUCCESS) {
373 nss_warning("%p: dtls_tx_msg failed\n", nss_ctx);
374 up(&dtls_pvt.sem);
375 return status;
376 }
377
378 ret = wait_for_completion_timeout(&dtls_pvt.complete, msecs_to_jiffies(NSS_DTLS_TX_TIMEOUT));
379
380 if (!ret) {
381 nss_warning("%p: DTLS msg tx failed due to timeout\n", nss_ctx);
382 dtls_pvt.response = NSS_TX_FAILURE;
383 }
384
385 status = dtls_pvt.response;
386 up(&dtls_pvt.sem);
387 return status;
388}
389EXPORT_SYMBOL(nss_dtls_tx_msg_sync);
390
391/*
392 ***********************************
393 * Register/Unregister/Miscellaneous APIs
394 ***********************************
395 */
396
397/*
398 * nss_dtls_register_if()
399 */
400struct nss_ctx_instance *nss_dtls_register_if(uint32_t if_num,
401 nss_dtls_data_callback_t cb,
402 nss_dtls_msg_callback_t ev_cb,
403 struct net_device *netdev,
404 uint32_t features,
405 void *app_ctx)
406{
407 int32_t i;
408
409 struct nss_ctx_instance *nss_ctx = nss_dtls_get_context();
410
411 BUG_ON(!nss_dtls_verify_if_num(if_num));
412
Yu Huang8c107082017-07-24 14:58:26 -0700413 spin_lock_bh(&nss_dtls_session_stats_lock);
Tushar Mathurff8741b2015-12-02 20:28:59 +0530414 for (i = 0; i < NSS_MAX_DTLS_SESSIONS; i++) {
Yu Huang8c107082017-07-24 14:58:26 -0700415 if (!session_stats[i].valid) {
416 session_stats[i].valid = true;
417 session_stats[i].if_num = if_num;
418 session_stats[i].if_index = netdev->ifindex;
Tushar Mathurff8741b2015-12-02 20:28:59 +0530419 break;
420 }
421 }
Yu Huang8c107082017-07-24 14:58:26 -0700422 spin_unlock_bh(&nss_dtls_session_stats_lock);
Tushar Mathurff8741b2015-12-02 20:28:59 +0530423
424 if (i == NSS_MAX_DTLS_SESSIONS) {
425 nss_warning("%p: Cannot find free slot for "
426 "DTLS session stats, I/F:%u\n", nss_ctx, if_num);
427 return NULL;
428 }
429
Stephen Wang84e0e992016-09-07 12:31:40 -0700430 if (nss_ctx->subsys_dp_register[if_num].ndev) {
Tushar Mathurff8741b2015-12-02 20:28:59 +0530431 nss_warning("%p: Cannot find free slot for "
432 "DTLS NSS I/F:%u\n", nss_ctx, if_num);
433
434 return NULL;
435 }
436
Jackson Bockus7ca70ec2017-07-17 13:47:29 -0700437 nss_core_register_subsys_dp(nss_ctx, if_num, cb, NULL, app_ctx, netdev, features);
Tushar Mathurff8741b2015-12-02 20:28:59 +0530438
439 nss_top_main.dtls_msg_callback = ev_cb;
Thomas Wu91f4bdf2017-06-09 12:03:02 -0700440 nss_core_register_handler(nss_ctx, if_num, nss_dtls_handler, app_ctx);
Tushar Mathurff8741b2015-12-02 20:28:59 +0530441
Stephen Wang90c67de2016-04-26 15:15:59 -0700442 return nss_ctx;
Tushar Mathurff8741b2015-12-02 20:28:59 +0530443}
444EXPORT_SYMBOL(nss_dtls_register_if);
445
446/*
447 * nss_dtls_unregister_if()
448 */
449void nss_dtls_unregister_if(uint32_t if_num)
450{
Stephen Wang84e0e992016-09-07 12:31:40 -0700451 struct nss_ctx_instance *nss_ctx = nss_dtls_get_context();
Tushar Mathurff8741b2015-12-02 20:28:59 +0530452 int32_t i;
453
Tushar Mathurff8741b2015-12-02 20:28:59 +0530454 BUG_ON(!nss_dtls_verify_if_num(if_num));
455
Yu Huang8c107082017-07-24 14:58:26 -0700456 spin_lock_bh(&nss_dtls_session_stats_lock);
Tushar Mathurff8741b2015-12-02 20:28:59 +0530457 for (i = 0; i < NSS_MAX_DTLS_SESSIONS; i++) {
Yu Huang8c107082017-07-24 14:58:26 -0700458 if (session_stats[i].if_num == if_num) {
459 memset(&session_stats[i], 0,
460 sizeof(struct nss_dtls_stats_session));
Tushar Mathurff8741b2015-12-02 20:28:59 +0530461 break;
462 }
463 }
Yu Huang8c107082017-07-24 14:58:26 -0700464 spin_unlock_bh(&nss_dtls_session_stats_lock);
Tushar Mathurff8741b2015-12-02 20:28:59 +0530465
466 if (i == NSS_MAX_DTLS_SESSIONS) {
Stephen Wang84e0e992016-09-07 12:31:40 -0700467 nss_warning("%p: Cannot find debug stats for DTLS session %d\n", nss_ctx, if_num);
Tushar Mathurff8741b2015-12-02 20:28:59 +0530468 return;
469 }
470
Stephen Wang84e0e992016-09-07 12:31:40 -0700471 if (!nss_ctx->subsys_dp_register[if_num].ndev) {
472 nss_warning("%p: Cannot find registered netdev for DTLS NSS I/F:%u\n", nss_ctx, if_num);
Tushar Mathurff8741b2015-12-02 20:28:59 +0530473
474 return;
475 }
476
Jackson Bockus7ca70ec2017-07-17 13:47:29 -0700477 nss_core_unregister_subsys_dp(nss_ctx, if_num);
Tushar Mathurff8741b2015-12-02 20:28:59 +0530478
479 nss_top_main.dtls_msg_callback = NULL;
Thomas Wu91f4bdf2017-06-09 12:03:02 -0700480 nss_core_unregister_handler(nss_ctx, if_num);
Tushar Mathurff8741b2015-12-02 20:28:59 +0530481}
482EXPORT_SYMBOL(nss_dtls_unregister_if);
483
484/*
485 * nss_get_dtls_context()
486 */
487struct nss_ctx_instance *nss_dtls_get_context(void)
488{
489 return (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.dtls_handler_id];
490}
491EXPORT_SYMBOL(nss_dtls_get_context);
492
493/*
494 * nss_dtls_msg_init()
495 * Initialize nss_dtls msg.
496 */
497void nss_dtls_msg_init(struct nss_dtls_msg *ncm, uint16_t if_num,
498 uint32_t type, uint32_t len, void *cb, void *app_data)
499{
500 nss_cmn_msg_init(&ncm->cm, if_num, type, len, cb, app_data);
501}
502EXPORT_SYMBOL(nss_dtls_msg_init);
503
504/*
505 * nss_dtls_get_ifnum_with_coreid()
506 */
507int32_t nss_dtls_get_ifnum_with_coreid(int32_t if_num)
508{
509 struct nss_ctx_instance *nss_ctx = nss_dtls_get_context();
510
511 NSS_VERIFY_CTX_MAGIC(nss_ctx);
512 return NSS_INTERFACE_NUM_APPEND_COREID(nss_ctx, if_num);
513}
514EXPORT_SYMBOL(nss_dtls_get_ifnum_with_coreid);
515
516/*
517 * nss_dtls_register_handler()
518 */
519void nss_dtls_register_handler(void)
520{
521 sema_init(&dtls_pvt.sem, 1);
522 init_completion(&dtls_pvt.complete);
Yu Huang8c107082017-07-24 14:58:26 -0700523
524 nss_dtls_stats_dentry_create();
Tushar Mathurff8741b2015-12-02 20:28:59 +0530525}