blob: 87ed1526d7b0009796ea1e234409dffefa1a7175 [file] [log] [blame]
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +05301/*
2 **************************************************************************
Stephen Wangaed46332016-12-12 17:29:03 -08003 * Copyright (c) 2013-2017, The Linux Foundation. All rights reserved.
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +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/*
18 * nss_ipsec.c
19 * NSS IPsec APIs
20 */
21
22#include "nss_tx_rx_common.h"
Murat Sezginea1a4352014-04-15 19:09:51 -070023#include "nss_ipsec.h"
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +053024
Sourav Poddarbf8b50c2017-02-15 12:44:44 +053025#if defined(NSS_HAL_IPQ806X_SUPPORT)
26#define NSS_IPSEC_ENCAP_INTERFACE_NUM NSS_IPSEC_ENCAP_IF_NUMBER
27#define NSS_IPSEC_DECAP_INTERFACE_NUM NSS_IPSEC_DECAP_IF_NUMBER
28#define NSS_IPSEC_DATA_INTERFACE_NUM NSS_C2C_TX_INTERFACE
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +053029
Sourav Poddarbf8b50c2017-02-15 12:44:44 +053030#elif defined(NSS_HAL_FSM9010_SUPPORT)
31#define NSS_IPSEC_ENCAP_INTERFACE_NUM NSS_IPSEC_ENCAP_IF_NUMBER
32#define NSS_IPSEC_DECAP_INTERFACE_NUM NSS_IPSEC_DECAP_IF_NUMBER
33#define NSS_IPSEC_DATA_INTERFACE_NUM NSS_IPSEC_RULE_INTERFACE
34
35#elif defined(NSS_HAL_IPQ807x_SUPPORT)
36#define NSS_IPSEC_ENCAP_INTERFACE_NUM NSS_IPSEC_RULE_INTERFACE
37#define NSS_IPSEC_DECAP_INTERFACE_NUM NSS_IPSEC_RULE_INTERFACE
38#define NSS_IPSEC_DATA_INTERFACE_NUM NSS_IPSEC_RULE_INTERFACE
39
40#else
41#define NSS_IPSEC_ENCAP_INTERFACE_NUM -1
42#define NSS_IPSEC_DECAP_INTERFACE_NUM -1
43#define NSS_IPSEC_DATA_INTERFACE_NUM -1
44
45#endif
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +053046
47/*
Sourav Poddarbf8b50c2017-02-15 12:44:44 +053048 * nss_ipsec_get_msg_ctx()
49 * return ipsec message context assoicated with the callback
50 *
51 * Note: certain SOC the decap interface specially programmed
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +053052 */
Sourav Poddarbf8b50c2017-02-15 12:44:44 +053053static inline nss_ptr_t nss_ipsec_get_msg_ctx(struct nss_ctx_instance *nss_ctx, uint32_t interface_num)
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +053054{
Sourav Poddarbf8b50c2017-02-15 12:44:44 +053055 struct nss_top_instance *nss_top = nss_ctx->nss_top;
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +053056
Sourav Poddarbf8b50c2017-02-15 12:44:44 +053057 /*
58 * the encap is primary interface
59 */
Sourav Poddareb8cb652017-05-18 12:02:18 +053060 if (interface_num == NSS_IPSEC_ENCAP_INTERFACE_NUM)
Sourav Poddarbf8b50c2017-02-15 12:44:44 +053061 return (nss_ptr_t)nss_top->ipsec_encap_ctx;
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +053062
Sourav Poddarbf8b50c2017-02-15 12:44:44 +053063 return (nss_ptr_t)nss_top->ipsec_decap_ctx;
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +053064}
65
66/*
67 * nss_ipsec_get_msg_callback()
Sourav Poddarbf8b50c2017-02-15 12:44:44 +053068 * this gets the message callback handler
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +053069 */
Sourav Poddarbf8b50c2017-02-15 12:44:44 +053070static inline nss_ptr_t nss_ipsec_get_msg_callback(struct nss_ctx_instance *nss_ctx, uint32_t interface_num)
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +053071{
Sourav Poddarbf8b50c2017-02-15 12:44:44 +053072 struct nss_top_instance *nss_top = nss_ctx->nss_top;
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +053073
Sourav Poddarbf8b50c2017-02-15 12:44:44 +053074 /*
75 * the encap is primary interface
76 */
Sourav Poddareb8cb652017-05-18 12:02:18 +053077 if (interface_num == NSS_IPSEC_ENCAP_INTERFACE_NUM)
Sourav Poddarbf8b50c2017-02-15 12:44:44 +053078 return (nss_ptr_t)nss_top->ipsec_encap_callback;
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +053079
Sourav Poddarbf8b50c2017-02-15 12:44:44 +053080 return (nss_ptr_t)nss_top->ipsec_decap_callback;
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +053081}
82
83/*
84 **********************************
85 Rx APIs
86 **********************************
87 */
88
89/*
90 * nss_ipsec_msg_handler()
91 * this handles all the IPsec events and responses
92 */
93static void nss_ipsec_msg_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, void *app_data __attribute((unused)))
94{
95 struct nss_ipsec_msg *nim = (struct nss_ipsec_msg *)ncm;
96 nss_ipsec_msg_callback_t cb = NULL;
97 uint32_t if_num = ncm->interface;
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +053098
99 /*
100 * Sanity check the message type
101 */
102 if (ncm->type > NSS_IPSEC_MSG_TYPE_MAX) {
Sourav Poddarbf8b50c2017-02-15 12:44:44 +0530103 nss_warning("%p: rx message type out of range: %d", nss_ctx, ncm->type);
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530104 return;
105 }
106
Suruchi Agarwalef8a8702016-01-08 12:40:08 -0800107 if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_ipsec_msg)) {
Sourav Poddarbf8b50c2017-02-15 12:44:44 +0530108 nss_warning("%p: rx message length is invalid: %d", nss_ctx, nss_cmn_get_msg_len(ncm));
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530109 return;
110 }
111
Sourav Poddarbf8b50c2017-02-15 12:44:44 +0530112 BUG_ON((if_num != NSS_IPSEC_ENCAP_INTERFACE_NUM) && (if_num != NSS_IPSEC_DECAP_INTERFACE_NUM));
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530113
114 if (ncm->response == NSS_CMN_RESPONSE_LAST) {
Sourav Poddarbf8b50c2017-02-15 12:44:44 +0530115 nss_warning("%p: rx message response for if %d, type %d, is invalid: %d", nss_ctx, ncm->interface,
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530116 ncm->type, ncm->response);
117 return;
118 }
119
120 /*
121 * Is this a notification? if, yes then fill up the callback and app_data from
122 * locally stored state
123 */
124 if (ncm->response == NSS_CMM_RESPONSE_NOTIFY) {
Sourav Poddarbf8b50c2017-02-15 12:44:44 +0530125 ncm->cb = nss_ipsec_get_msg_callback(nss_ctx, if_num);
126 ncm->app_data = nss_ipsec_get_msg_ctx(nss_ctx, if_num);
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530127 }
128
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530129 nss_core_log_msg_failures(nss_ctx, ncm);
130
131 /*
132 * load, test & call
133 */
134 cb = (nss_ipsec_msg_callback_t)ncm->cb;
135 if (unlikely(!cb)) {
Sourav Poddarbf8b50c2017-02-15 12:44:44 +0530136 nss_trace("%p: rx handler has been unregistered for i/f: %d", nss_ctx, ncm->interface);
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530137 return;
138 }
Sourav Poddarbf8b50c2017-02-15 12:44:44 +0530139
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530140 cb((void *)ncm->app_data, nim);
141}
142
143/*
144 **********************************
145 Tx APIs
146 **********************************
147 */
148
149/*
150 * nss_ipsec_tx_msg
151 * Send ipsec rule to NSS.
152 */
153nss_tx_status_t nss_ipsec_tx_msg(struct nss_ctx_instance *nss_ctx, struct nss_ipsec_msg *msg)
154{
155 struct nss_cmn_msg *ncm = &msg->cm;
156 struct nss_ipsec_msg *nim;
157 struct sk_buff *nbuf;
158 int32_t status;
159
Sourav Poddarbf8b50c2017-02-15 12:44:44 +0530160 nss_info("%p: message %d for if %d\n", nss_ctx, ncm->type, ncm->interface);
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530161
162 NSS_VERIFY_CTX_MAGIC(nss_ctx);
163
164 if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
Sourav Poddarbf8b50c2017-02-15 12:44:44 +0530165 nss_warning("%p: tx message dropped as core not ready", nss_ctx);
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530166 return NSS_TX_FAILURE_NOT_READY;
167 }
168
Tanmay V Jagdalef6b2bce2017-03-03 14:31:07 +0530169 BUILD_BUG_ON(NSS_NBUF_PAYLOAD_SIZE < sizeof(struct nss_ipsec_msg));
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530170
Sourav Poddarbf8b50c2017-02-15 12:44:44 +0530171 if ((ncm->interface != NSS_IPSEC_ENCAP_INTERFACE_NUM) && (ncm->interface != NSS_IPSEC_DECAP_INTERFACE_NUM)) {
172 nss_warning("%p: tx message request for another interface: %d", nss_ctx, ncm->interface);
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530173 return NSS_TX_FAILURE;
174 }
175
176 if (ncm->type > NSS_IPSEC_MSG_TYPE_MAX) {
Sourav Poddarbf8b50c2017-02-15 12:44:44 +0530177 nss_warning("%p: tx message type out of range: %d", nss_ctx, ncm->type);
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530178 return NSS_TX_FAILURE;
179 }
180
Suruchi Agarwalef8a8702016-01-08 12:40:08 -0800181 if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_ipsec_msg)) {
Sourav Poddarbf8b50c2017-02-15 12:44:44 +0530182 nss_warning("%p: tx message request len for if %d, is bad: %d", nss_ctx, ncm->interface, nss_cmn_get_msg_len(ncm));
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530183 return NSS_TX_FAILURE_BAD_PARAM;
184 }
185
Pamidipati, Vijayb6e38842014-09-16 10:26:05 +0530186 nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE);
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530187 if (unlikely(!nbuf)) {
Sundarajan Srinivasan62fee7e2015-01-22 11:13:10 -0800188 NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]);
Sourav Poddarbf8b50c2017-02-15 12:44:44 +0530189 nss_warning("%p: tx rule dropped as command allocation failed", nss_ctx);
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530190 return NSS_TX_FAILURE;
191 }
192
Sourav Poddarbf8b50c2017-02-15 12:44:44 +0530193 nss_info("msg params version:%d, interface:%d, type:%d, cb:%p, app_data:%p, len:%d\n",
Stephen Wangaed46332016-12-12 17:29:03 -0800194 ncm->version, ncm->interface, ncm->type, (void *)ncm->cb, (void *)ncm->app_data, ncm->len);
Samarjeet Banerjee7bce8c52014-05-02 15:32:13 +0530195
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530196 nim = (struct nss_ipsec_msg *)skb_put(nbuf, sizeof(struct nss_ipsec_msg));
197 memcpy(nim, msg, sizeof(struct nss_ipsec_msg));
198
199 status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0);
200 if (status != NSS_CORE_STATUS_SUCCESS) {
Pamidipati, Vijayb6e38842014-09-16 10:26:05 +0530201 dev_kfree_skb_any(nbuf);
Sourav Poddarbf8b50c2017-02-15 12:44:44 +0530202 nss_warning("%p: tx Unable to enqueue message \n", nss_ctx);
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530203 return NSS_TX_FAILURE;
204 }
205
Stephen Wang90c67de2016-04-26 15:15:59 -0700206 nss_hal_send_interrupt(nss_ctx, NSS_H2N_INTR_DATA_COMMAND_QUEUE);
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530207
208 return NSS_TX_SUCCESS;
209}
Samarjeet Banerjee77332312014-08-07 14:48:22 +0530210EXPORT_SYMBOL(nss_ipsec_tx_msg);
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530211
212/*
Radha krishna Simha Jigurud36b1e22014-09-12 15:14:52 +0530213 * nss_ipsec_tx_buf
214 * Send data packet for ipsec processing
215 */
Stephen Wang83e48752015-03-03 18:41:40 -0800216nss_tx_status_t nss_ipsec_tx_buf(struct sk_buff *skb, uint32_t if_num)
Radha krishna Simha Jigurud36b1e22014-09-12 15:14:52 +0530217{
Radha krishna Simha Jigurud36b1e22014-09-12 15:14:52 +0530218 struct nss_ctx_instance *nss_ctx = &nss_top_main.nss[nss_top_main.ipsec_handler_id];
Sourav Poddarbf8b50c2017-02-15 12:44:44 +0530219 int32_t status;
Radha krishna Simha Jigurud36b1e22014-09-12 15:14:52 +0530220
Stephen Wang83e48752015-03-03 18:41:40 -0800221 nss_trace("%p: IPsec If Tx packet, id:%d, data=%p", nss_ctx, if_num, skb->data);
Radha krishna Simha Jigurud36b1e22014-09-12 15:14:52 +0530222
223 NSS_VERIFY_CTX_MAGIC(nss_ctx);
224 if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
225 nss_warning("%p: 'IPsec If Tx' packet dropped as core not ready", nss_ctx);
226 return NSS_TX_FAILURE_NOT_READY;
227 }
228
Stephen Wang83e48752015-03-03 18:41:40 -0800229 status = nss_core_send_buffer(nss_ctx, if_num, skb, NSS_IF_DATA_QUEUE_0, H2N_BUFFER_PACKET, 0);
Radha krishna Simha Jigurud36b1e22014-09-12 15:14:52 +0530230 if (unlikely(status != NSS_CORE_STATUS_SUCCESS)) {
231 nss_warning("%p: Unable to enqueue 'IPsec If Tx' packet\n", nss_ctx);
232 if (status == NSS_CORE_STATUS_FAILURE_QUEUE) {
233 return NSS_TX_FAILURE_QUEUE;
234 }
235
236 return NSS_TX_FAILURE;
237 }
238
239 /*
240 * Kick the NSS awake so it can process our new entry.
241 */
Stephen Wang90c67de2016-04-26 15:15:59 -0700242 nss_hal_send_interrupt(nss_ctx, NSS_H2N_INTR_DATA_COMMAND_QUEUE);
Radha krishna Simha Jigurud36b1e22014-09-12 15:14:52 +0530243 NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_PACKET]);
244 return NSS_TX_SUCCESS;
245}
246EXPORT_SYMBOL(nss_ipsec_tx_buf);
247
248/*
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530249 **********************************
250 Register APIs
251 **********************************
252 */
253
254/*
Ankit Dhanukaa0e4cae2014-05-26 16:33:10 +0530255 * nss_ipsec_notify_register()
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530256 * register message notifier for the given interface (if_num)
257 */
258struct nss_ctx_instance *nss_ipsec_notify_register(uint32_t if_num, nss_ipsec_msg_callback_t cb, void *app_data)
259{
Sourav Poddarbf8b50c2017-02-15 12:44:44 +0530260 struct nss_top_instance *nss_top = &nss_top_main;
261 uint8_t core_id = nss_top->ipsec_handler_id;
262 struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_id];
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530263
264 if (if_num >= NSS_MAX_NET_INTERFACES) {
Sourav Poddarbf8b50c2017-02-15 12:44:44 +0530265 nss_warning("%p: notfiy register received for invalid interface %d", nss_ctx, if_num);
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530266 return NULL;
267 }
268
Samarjeet Banerjee940e91b2016-03-29 19:23:17 +0530269 /*
Sourav Poddarbf8b50c2017-02-15 12:44:44 +0530270 * the encap is primary interface
Samarjeet Banerjee940e91b2016-03-29 19:23:17 +0530271 */
Sourav Poddarbf8b50c2017-02-15 12:44:44 +0530272 if (if_num == NSS_IPSEC_ENCAP_INTERFACE_NUM) {
273 nss_top->ipsec_encap_callback = cb;
274 nss_top->ipsec_encap_ctx = app_data;
Samarjeet Banerjee940e91b2016-03-29 19:23:17 +0530275 return nss_ctx;
276 }
277
Sourav Poddarbf8b50c2017-02-15 12:44:44 +0530278 nss_top->ipsec_decap_callback = cb;
279 nss_top->ipsec_decap_ctx = app_data;
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530280 return nss_ctx;
281}
Samarjeet Banerjee77332312014-08-07 14:48:22 +0530282EXPORT_SYMBOL(nss_ipsec_notify_register);
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530283
284/*
Ankit Dhanukaa0e4cae2014-05-26 16:33:10 +0530285 * nss_ipsec_notify_unregister()
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530286 * unregister the IPsec notifier for the given interface number (if_num)
287 */
288void nss_ipsec_notify_unregister(struct nss_ctx_instance *nss_ctx, uint32_t if_num)
289{
Sourav Poddarbf8b50c2017-02-15 12:44:44 +0530290 struct nss_top_instance *nss_top = nss_ctx->nss_top;
291
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530292 if (if_num >= NSS_MAX_NET_INTERFACES) {
Sourav Poddarbf8b50c2017-02-15 12:44:44 +0530293 nss_warning("%p: notify unregister received for invalid interface %d", nss_ctx, if_num);
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530294 return;
295 }
296
Sourav Poddarbf8b50c2017-02-15 12:44:44 +0530297 /*
298 * the encap is primary interface
299 */
300 if (if_num == NSS_IPSEC_ENCAP_INTERFACE_NUM) {
301 nss_top->ipsec_encap_callback = NULL;
302 nss_top->ipsec_encap_ctx = NULL;
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530303 return;
304 }
Sourav Poddarbf8b50c2017-02-15 12:44:44 +0530305
306 nss_top->ipsec_decap_callback = NULL;
307 nss_top->ipsec_decap_ctx = NULL;
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530308}
Samarjeet Banerjee77332312014-08-07 14:48:22 +0530309EXPORT_SYMBOL(nss_ipsec_notify_unregister);
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530310
311/*
Ankit Dhanukaa0e4cae2014-05-26 16:33:10 +0530312 * nss_ipsec_data_register()
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530313 * register a data callback routine
314 */
Sundarajan Srinivasan70374842014-11-19 15:22:52 -0800315struct nss_ctx_instance *nss_ipsec_data_register(uint32_t if_num, nss_ipsec_buf_callback_t cb, struct net_device *netdev, uint32_t features)
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530316{
Arunkumar T657c4062016-09-21 18:06:48 +0530317 struct nss_ctx_instance *nss_ctx, *nss_ctx0;
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530318
319 nss_ctx = &nss_top_main.nss[nss_top_main.ipsec_handler_id];
320
321 if ((if_num >= NSS_MAX_NET_INTERFACES) && (if_num < NSS_MAX_PHYSICAL_INTERFACES)){
Sourav Poddarbf8b50c2017-02-15 12:44:44 +0530322 nss_warning("%p: data register received for invalid interface %d", nss_ctx, if_num);
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530323 return NULL;
324 }
325
Samarjeet Banerjee940e91b2016-03-29 19:23:17 +0530326 /*
327 * avoid multiple registeration for multiple tunnels
328 */
Stephen Wang84e0e992016-09-07 12:31:40 -0700329 if (nss_ctx->subsys_dp_register[if_num].cb) {
Samarjeet Banerjee940e91b2016-03-29 19:23:17 +0530330 return nss_ctx;
331 }
332
Stephen Wang84e0e992016-09-07 12:31:40 -0700333 nss_ctx->subsys_dp_register[if_num].cb = cb;
334 nss_ctx->subsys_dp_register[if_num].app_data = NULL;
335 nss_ctx->subsys_dp_register[if_num].ndev = netdev;
336 nss_ctx->subsys_dp_register[if_num].features = features;
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530337
Arunkumar T657c4062016-09-21 18:06:48 +0530338 if (nss_top_main.ipsec_handler_id == 1) {
339 nss_ctx0 = &nss_top_main.nss[0];
340
341 nss_ctx0->subsys_dp_register[if_num].cb = cb;
342 nss_ctx0->subsys_dp_register[if_num].app_data = NULL;
343 nss_ctx0->subsys_dp_register[if_num].ndev = netdev;
344 nss_ctx0->subsys_dp_register[if_num].features = features;
345 }
346
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530347 return nss_ctx;
348}
Samarjeet Banerjee77332312014-08-07 14:48:22 +0530349EXPORT_SYMBOL(nss_ipsec_data_register);
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530350
351/*
Ankit Dhanukaa0e4cae2014-05-26 16:33:10 +0530352 * nss_ipsec_data_unregister()
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530353 * unregister a data callback routine
354 */
355void nss_ipsec_data_unregister(struct nss_ctx_instance *nss_ctx, uint32_t if_num)
356{
Arunkumar T657c4062016-09-21 18:06:48 +0530357 struct nss_ctx_instance *nss_ctx0;
358
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530359 if ((if_num >= NSS_MAX_NET_INTERFACES) && (if_num < NSS_MAX_PHYSICAL_INTERFACES)){
Sourav Poddarbf8b50c2017-02-15 12:44:44 +0530360 nss_warning("%p: data unregister received for invalid interface %d", nss_ctx, if_num);
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530361 return;
362 }
363
Arunkumar T657c4062016-09-21 18:06:48 +0530364 if (nss_top_main.ipsec_handler_id == 1) {
365 nss_ctx0 = &nss_top_main.nss[0];
366
367 nss_ctx0->subsys_dp_register[if_num].cb = NULL;
368 nss_ctx0->subsys_dp_register[if_num].app_data = NULL;
369 nss_ctx0->subsys_dp_register[if_num].ndev = NULL;
370 nss_ctx0->subsys_dp_register[if_num].features = 0;
371 }
372
Stephen Wang84e0e992016-09-07 12:31:40 -0700373 nss_ctx->subsys_dp_register[if_num].cb = NULL;
374 nss_ctx->subsys_dp_register[if_num].app_data = NULL;
375 nss_ctx->subsys_dp_register[if_num].ndev = NULL;
376 nss_ctx->subsys_dp_register[if_num].features = 0;
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530377}
Samarjeet Banerjee77332312014-08-07 14:48:22 +0530378EXPORT_SYMBOL(nss_ipsec_data_unregister);
379
380/*
Sourav Poddarbf8b50c2017-02-15 12:44:44 +0530381 * nss_ipsec_get_encap_interface()
382 * Get the NSS interface number for encap message
Radha krishna Simha Jigurudb7ad242014-11-19 16:02:23 +0530383 */
Sourav Poddarbf8b50c2017-02-15 12:44:44 +0530384int32_t nss_ipsec_get_encap_interface(void)
Radha krishna Simha Jigurudb7ad242014-11-19 16:02:23 +0530385{
Sourav Poddarbf8b50c2017-02-15 12:44:44 +0530386 return NSS_IPSEC_ENCAP_INTERFACE_NUM;
Radha krishna Simha Jigurudb7ad242014-11-19 16:02:23 +0530387}
Sourav Poddarbf8b50c2017-02-15 12:44:44 +0530388EXPORT_SYMBOL(nss_ipsec_get_encap_interface);
389
390/*
391 * nss_ipsec_get_decap_interface()
392 * Get the NSS interface number for decap message
393 */
394int32_t nss_ipsec_get_decap_interface(void)
395{
396 return NSS_IPSEC_DECAP_INTERFACE_NUM;
397}
398EXPORT_SYMBOL(nss_ipsec_get_decap_interface);
399
400/*
401 * nss_ipsec_get_data_interface()
402 * Get the NSS interface number used for data path
403 */
404int32_t nss_ipsec_get_data_interface(void)
405{
406 return NSS_IPSEC_DATA_INTERFACE_NUM;
407}
408EXPORT_SYMBOL(nss_ipsec_get_data_interface);
Radha krishna Simha Jigurudb7ad242014-11-19 16:02:23 +0530409
410/*
Thomas Wu91f4bdf2017-06-09 12:03:02 -0700411 * nss_ipsec_get_context()
Samarjeet Banerjee77332312014-08-07 14:48:22 +0530412 * get NSS context instance for IPsec handle
413 */
414struct nss_ctx_instance *nss_ipsec_get_context(void)
415{
416 return &nss_top_main.nss[nss_top_main.ipsec_handler_id];
417}
418EXPORT_SYMBOL(nss_ipsec_get_context);
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530419
420/*
421 * nss_ipsec_register_handler()
422 */
423void nss_ipsec_register_handler()
424{
425 struct nss_ctx_instance *nss_ctx = &nss_top_main.nss[nss_top_main.ipsec_handler_id];
426
Sourav Poddarbf8b50c2017-02-15 12:44:44 +0530427 BUILD_BUG_ON(NSS_IPSEC_ENCAP_INTERFACE_NUM < 0);
428 BUILD_BUG_ON(NSS_IPSEC_DECAP_INTERFACE_NUM < 0);
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530429
Sourav Poddarbf8b50c2017-02-15 12:44:44 +0530430 nss_ctx->nss_top->ipsec_encap_callback = NULL;
431 nss_ctx->nss_top->ipsec_decap_callback = NULL;
432
433 nss_ctx->nss_top->ipsec_encap_ctx = NULL;
434 nss_ctx->nss_top->ipsec_decap_ctx = NULL;
435
Thomas Wu91f4bdf2017-06-09 12:03:02 -0700436 nss_core_register_handler(nss_ctx, NSS_IPSEC_ENCAP_INTERFACE_NUM, nss_ipsec_msg_handler, NULL);
437 nss_core_register_handler(nss_ctx, NSS_IPSEC_DECAP_INTERFACE_NUM, nss_ipsec_msg_handler, NULL);
Samarjeet Banerjeed99d9d02014-04-08 18:51:00 +0530438}
439
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700440/*
441 * nss_ipsec_msg_init()
442 * Initialize ipsec message.
443 */
444void nss_ipsec_msg_init(struct nss_ipsec_msg *nim, uint16_t if_num, uint32_t type, uint32_t len,
Sundarajan Srinivasan30a53d42015-01-30 10:52:08 -0800445 nss_ipsec_msg_callback_t cb, void *app_data)
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700446{
447 nss_cmn_msg_init(&nim->cm, if_num, type, len, (void *)cb, app_data);
448}
449EXPORT_SYMBOL(nss_ipsec_msg_init);