Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2017, The Linux Foundation. All rights reserved. |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +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 | /* |
| 18 | * nss_ipsec.c |
| 19 | * NSS IPsec APIs |
| 20 | */ |
| 21 | |
| 22 | #include "nss_tx_rx_common.h" |
Murat Sezgin | ea1a435 | 2014-04-15 19:09:51 -0700 | [diff] [blame] | 23 | #include "nss_ipsec.h" |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 24 | |
| 25 | /* |
| 26 | ********************************** |
| 27 | General APIs |
| 28 | ********************************** |
| 29 | */ |
| 30 | |
| 31 | #define nss_ipsec_warning(fmt, arg...) nss_warning("IPsec:"fmt, ##arg) |
| 32 | #define nss_ipsec_info(fmt, arg...) nss_info("IPsec:"fmt, ##arg) |
| 33 | #define nss_ipsec_trace(fmt, arg...) nss_trace("IPsec:"fmt, ##arg) |
| 34 | |
| 35 | /* |
| 36 | * nss_ipsec_set_msg_callback() |
| 37 | * this sets the message callback handler and its associated context |
| 38 | */ |
| 39 | static inline nss_tx_status_t nss_ipsec_set_msg_callback(struct nss_ctx_instance *nss_ctx, uint32_t if_num, |
| 40 | nss_ipsec_msg_callback_t cb, void *ipsec_ctx) |
| 41 | { |
| 42 | struct nss_top_instance *nss_top; |
| 43 | |
| 44 | nss_top = nss_ctx->nss_top; |
| 45 | |
| 46 | switch (if_num) { |
| 47 | case NSS_IPSEC_ENCAP_IF_NUMBER: |
| 48 | nss_top->ipsec_encap_ctx = ipsec_ctx; |
| 49 | nss_top->ipsec_encap_callback = cb; |
Samarjeet Banerjee | 7bce8c5 | 2014-05-02 15:32:13 +0530 | [diff] [blame] | 50 | break; |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 51 | |
| 52 | case NSS_IPSEC_DECAP_IF_NUMBER: |
| 53 | nss_top->ipsec_decap_ctx = ipsec_ctx; |
| 54 | nss_top->ipsec_decap_callback = cb; |
Samarjeet Banerjee | 7bce8c5 | 2014-05-02 15:32:13 +0530 | [diff] [blame] | 55 | break; |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 56 | |
| 57 | default: |
| 58 | nss_ipsec_warning("%p: cannot 'set' message callback, incorrect I/F: %d", nss_ctx, if_num); |
| 59 | return NSS_TX_FAILURE; |
| 60 | } |
| 61 | |
| 62 | return NSS_TX_SUCCESS; |
| 63 | } |
| 64 | |
| 65 | /* |
| 66 | * nss_ipsec_get_msg_callback() |
| 67 | * this gets the message callback handler and its associated context |
| 68 | */ |
| 69 | static inline nss_ipsec_msg_callback_t nss_ipsec_get_msg_callback(struct nss_ctx_instance *nss_ctx, uint32_t if_num, void **ipsec_ctx) |
| 70 | { |
| 71 | struct nss_top_instance *nss_top; |
| 72 | |
| 73 | nss_top = nss_ctx->nss_top; |
| 74 | |
| 75 | switch (if_num) { |
| 76 | case NSS_IPSEC_ENCAP_IF_NUMBER: |
| 77 | *ipsec_ctx = nss_top->ipsec_encap_ctx; |
| 78 | return nss_top->ipsec_encap_callback; |
| 79 | |
| 80 | case NSS_IPSEC_DECAP_IF_NUMBER: |
| 81 | *ipsec_ctx = nss_top->ipsec_decap_ctx; |
| 82 | return nss_top->ipsec_decap_callback; |
| 83 | |
| 84 | default: |
| 85 | *ipsec_ctx = NULL; |
| 86 | nss_ipsec_warning("%p: cannot 'get' message callback, incorrect I/F: %d", nss_ctx, if_num); |
| 87 | return NULL; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | /* |
| 92 | ********************************** |
| 93 | Rx APIs |
| 94 | ********************************** |
| 95 | */ |
| 96 | |
| 97 | /* |
| 98 | * nss_ipsec_msg_handler() |
| 99 | * this handles all the IPsec events and responses |
| 100 | */ |
| 101 | static void nss_ipsec_msg_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, void *app_data __attribute((unused))) |
| 102 | { |
| 103 | struct nss_ipsec_msg *nim = (struct nss_ipsec_msg *)ncm; |
| 104 | nss_ipsec_msg_callback_t cb = NULL; |
| 105 | uint32_t if_num = ncm->interface; |
| 106 | void *ipsec_ctx; |
| 107 | |
| 108 | /* |
| 109 | * Sanity check the message type |
| 110 | */ |
| 111 | if (ncm->type > NSS_IPSEC_MSG_TYPE_MAX) { |
| 112 | nss_ipsec_warning("%p: rx message type out of range: %d", nss_ctx, ncm->type); |
| 113 | return; |
| 114 | } |
| 115 | |
Suruchi Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 116 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_ipsec_msg)) { |
| 117 | nss_ipsec_warning("%p: rx message length is invalid: %d", nss_ctx, nss_cmn_get_msg_len(ncm)); |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 118 | return; |
| 119 | } |
| 120 | |
| 121 | if ((ncm->interface != NSS_IPSEC_ENCAP_IF_NUMBER) && (ncm->interface != NSS_IPSEC_DECAP_IF_NUMBER)) { |
| 122 | nss_ipsec_warning("%p: rx message request for another interface: %d", nss_ctx, ncm->interface); |
| 123 | return; |
| 124 | } |
| 125 | |
| 126 | if (ncm->response == NSS_CMN_RESPONSE_LAST) { |
| 127 | nss_ipsec_warning("%p: rx message response for if %d, type %d, is invalid: %d", nss_ctx, ncm->interface, |
| 128 | ncm->type, ncm->response); |
| 129 | return; |
| 130 | } |
| 131 | |
| 132 | /* |
| 133 | * Is this a notification? if, yes then fill up the callback and app_data from |
| 134 | * locally stored state |
| 135 | */ |
| 136 | if (ncm->response == NSS_CMM_RESPONSE_NOTIFY) { |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 137 | ncm->cb = (nss_ptr_t)nss_ipsec_get_msg_callback(nss_ctx, if_num, &ipsec_ctx); |
| 138 | ncm->app_data = (nss_ptr_t)ipsec_ctx; |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | |
| 142 | nss_core_log_msg_failures(nss_ctx, ncm); |
| 143 | |
| 144 | /* |
| 145 | * load, test & call |
| 146 | */ |
| 147 | cb = (nss_ipsec_msg_callback_t)ncm->cb; |
| 148 | if (unlikely(!cb)) { |
| 149 | nss_ipsec_trace("%p: rx handler has been unregistered for i/f: %d", nss_ctx, ncm->interface); |
| 150 | return; |
| 151 | } |
| 152 | cb((void *)ncm->app_data, nim); |
| 153 | } |
| 154 | |
| 155 | /* |
| 156 | ********************************** |
| 157 | Tx APIs |
| 158 | ********************************** |
| 159 | */ |
| 160 | |
| 161 | /* |
| 162 | * nss_ipsec_tx_msg |
| 163 | * Send ipsec rule to NSS. |
| 164 | */ |
| 165 | nss_tx_status_t nss_ipsec_tx_msg(struct nss_ctx_instance *nss_ctx, struct nss_ipsec_msg *msg) |
| 166 | { |
| 167 | struct nss_cmn_msg *ncm = &msg->cm; |
| 168 | struct nss_ipsec_msg *nim; |
| 169 | struct sk_buff *nbuf; |
| 170 | int32_t status; |
| 171 | |
| 172 | nss_ipsec_info("%p: message %d for if %d\n", nss_ctx, ncm->type, ncm->interface); |
| 173 | |
| 174 | NSS_VERIFY_CTX_MAGIC(nss_ctx); |
| 175 | |
| 176 | if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) { |
| 177 | nss_ipsec_warning("%p: tx message dropped as core not ready", nss_ctx); |
| 178 | return NSS_TX_FAILURE_NOT_READY; |
| 179 | } |
| 180 | |
Tanmay V Jagdale | f6b2bce | 2017-03-03 14:31:07 +0530 | [diff] [blame^] | 181 | BUILD_BUG_ON(NSS_NBUF_PAYLOAD_SIZE < sizeof(struct nss_ipsec_msg)); |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 182 | |
| 183 | if ((ncm->interface != NSS_IPSEC_ENCAP_IF_NUMBER) && (ncm->interface != NSS_IPSEC_DECAP_IF_NUMBER)) { |
| 184 | nss_ipsec_warning("%p: tx message request for another interface: %d", nss_ctx, ncm->interface); |
| 185 | return NSS_TX_FAILURE; |
| 186 | } |
| 187 | |
| 188 | if (ncm->type > NSS_IPSEC_MSG_TYPE_MAX) { |
| 189 | nss_ipsec_warning("%p: tx message type out of range: %d", nss_ctx, ncm->type); |
| 190 | return NSS_TX_FAILURE; |
| 191 | } |
| 192 | |
Suruchi Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 193 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_ipsec_msg)) { |
| 194 | nss_ipsec_warning("%p: tx message request len for if %d, is bad: %d", nss_ctx, ncm->interface, nss_cmn_get_msg_len(ncm)); |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 195 | return NSS_TX_FAILURE_BAD_PARAM; |
| 196 | } |
| 197 | |
Pamidipati, Vijay | b6e3884 | 2014-09-16 10:26:05 +0530 | [diff] [blame] | 198 | nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE); |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 199 | if (unlikely(!nbuf)) { |
Sundarajan Srinivasan | 62fee7e | 2015-01-22 11:13:10 -0800 | [diff] [blame] | 200 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]); |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 201 | nss_ipsec_warning("%p: tx rule dropped as command allocation failed", nss_ctx); |
| 202 | return NSS_TX_FAILURE; |
| 203 | } |
| 204 | |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 205 | nss_ipsec_info("msg params version:%d, interface:%d, type:%d, cb:%p, app_data:%p, len:%d\n", |
| 206 | ncm->version, ncm->interface, ncm->type, (void *)ncm->cb, (void *)ncm->app_data, ncm->len); |
Samarjeet Banerjee | 7bce8c5 | 2014-05-02 15:32:13 +0530 | [diff] [blame] | 207 | |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 208 | nim = (struct nss_ipsec_msg *)skb_put(nbuf, sizeof(struct nss_ipsec_msg)); |
| 209 | memcpy(nim, msg, sizeof(struct nss_ipsec_msg)); |
| 210 | |
| 211 | status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0); |
| 212 | if (status != NSS_CORE_STATUS_SUCCESS) { |
Pamidipati, Vijay | b6e3884 | 2014-09-16 10:26:05 +0530 | [diff] [blame] | 213 | dev_kfree_skb_any(nbuf); |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 214 | nss_ipsec_warning("%p: tx Unable to enqueue message \n", nss_ctx); |
| 215 | return NSS_TX_FAILURE; |
| 216 | } |
| 217 | |
Stephen Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 218 | nss_hal_send_interrupt(nss_ctx, NSS_H2N_INTR_DATA_COMMAND_QUEUE); |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 219 | |
| 220 | return NSS_TX_SUCCESS; |
| 221 | } |
Samarjeet Banerjee | 7733231 | 2014-08-07 14:48:22 +0530 | [diff] [blame] | 222 | EXPORT_SYMBOL(nss_ipsec_tx_msg); |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 223 | |
| 224 | /* |
Radha krishna Simha Jiguru | d36b1e2 | 2014-09-12 15:14:52 +0530 | [diff] [blame] | 225 | * nss_ipsec_tx_buf |
| 226 | * Send data packet for ipsec processing |
| 227 | */ |
Stephen Wang | 83e4875 | 2015-03-03 18:41:40 -0800 | [diff] [blame] | 228 | nss_tx_status_t nss_ipsec_tx_buf(struct sk_buff *skb, uint32_t if_num) |
Radha krishna Simha Jiguru | d36b1e2 | 2014-09-12 15:14:52 +0530 | [diff] [blame] | 229 | { |
| 230 | int32_t status; |
| 231 | struct nss_ctx_instance *nss_ctx = &nss_top_main.nss[nss_top_main.ipsec_handler_id]; |
Radha krishna Simha Jiguru | d36b1e2 | 2014-09-12 15:14:52 +0530 | [diff] [blame] | 232 | |
Stephen Wang | 83e4875 | 2015-03-03 18:41:40 -0800 | [diff] [blame] | 233 | nss_trace("%p: IPsec If Tx packet, id:%d, data=%p", nss_ctx, if_num, skb->data); |
Radha krishna Simha Jiguru | d36b1e2 | 2014-09-12 15:14:52 +0530 | [diff] [blame] | 234 | |
| 235 | NSS_VERIFY_CTX_MAGIC(nss_ctx); |
| 236 | if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) { |
| 237 | nss_warning("%p: 'IPsec If Tx' packet dropped as core not ready", nss_ctx); |
| 238 | return NSS_TX_FAILURE_NOT_READY; |
| 239 | } |
| 240 | |
Stephen Wang | 83e4875 | 2015-03-03 18:41:40 -0800 | [diff] [blame] | 241 | status = nss_core_send_buffer(nss_ctx, if_num, skb, NSS_IF_DATA_QUEUE_0, H2N_BUFFER_PACKET, 0); |
Radha krishna Simha Jiguru | d36b1e2 | 2014-09-12 15:14:52 +0530 | [diff] [blame] | 242 | if (unlikely(status != NSS_CORE_STATUS_SUCCESS)) { |
| 243 | nss_warning("%p: Unable to enqueue 'IPsec If Tx' packet\n", nss_ctx); |
| 244 | if (status == NSS_CORE_STATUS_FAILURE_QUEUE) { |
| 245 | return NSS_TX_FAILURE_QUEUE; |
| 246 | } |
| 247 | |
| 248 | return NSS_TX_FAILURE; |
| 249 | } |
| 250 | |
| 251 | /* |
| 252 | * Kick the NSS awake so it can process our new entry. |
| 253 | */ |
Stephen Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 254 | nss_hal_send_interrupt(nss_ctx, NSS_H2N_INTR_DATA_COMMAND_QUEUE); |
Radha krishna Simha Jiguru | d36b1e2 | 2014-09-12 15:14:52 +0530 | [diff] [blame] | 255 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_PACKET]); |
| 256 | return NSS_TX_SUCCESS; |
| 257 | } |
| 258 | EXPORT_SYMBOL(nss_ipsec_tx_buf); |
| 259 | |
| 260 | /* |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 261 | ********************************** |
| 262 | Register APIs |
| 263 | ********************************** |
| 264 | */ |
| 265 | |
| 266 | /* |
Ankit Dhanuka | a0e4cae | 2014-05-26 16:33:10 +0530 | [diff] [blame] | 267 | * nss_ipsec_notify_register() |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 268 | * register message notifier for the given interface (if_num) |
| 269 | */ |
| 270 | struct nss_ctx_instance *nss_ipsec_notify_register(uint32_t if_num, nss_ipsec_msg_callback_t cb, void *app_data) |
| 271 | { |
| 272 | struct nss_ctx_instance *nss_ctx; |
| 273 | |
| 274 | nss_ctx = &nss_top_main.nss[nss_top_main.ipsec_handler_id]; |
| 275 | |
| 276 | if (if_num >= NSS_MAX_NET_INTERFACES) { |
| 277 | nss_ipsec_warning("%p: notfiy register received for invalid interface %d", nss_ctx, if_num); |
| 278 | return NULL; |
| 279 | } |
| 280 | |
Samarjeet Banerjee | 940e91b | 2016-03-29 19:23:17 +0530 | [diff] [blame] | 281 | /* |
| 282 | * avoid multiple registeration for multiple tunnels |
| 283 | */ |
Arunkumar T | b46f27d | 2016-04-05 16:41:32 +0530 | [diff] [blame] | 284 | if (nss_ctx->nss_top->ipsec_encap_callback && nss_ctx->nss_top->ipsec_decap_callback) { |
Samarjeet Banerjee | 940e91b | 2016-03-29 19:23:17 +0530 | [diff] [blame] | 285 | return nss_ctx; |
| 286 | } |
| 287 | |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 288 | if (nss_ipsec_set_msg_callback(nss_ctx, if_num, cb, app_data) != NSS_TX_SUCCESS) { |
| 289 | nss_ipsec_warning("%p: register failed\n", nss_ctx); |
| 290 | return NULL; |
| 291 | } |
| 292 | |
| 293 | return nss_ctx; |
| 294 | } |
Samarjeet Banerjee | 7733231 | 2014-08-07 14:48:22 +0530 | [diff] [blame] | 295 | EXPORT_SYMBOL(nss_ipsec_notify_register); |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 296 | |
| 297 | /* |
Ankit Dhanuka | a0e4cae | 2014-05-26 16:33:10 +0530 | [diff] [blame] | 298 | * nss_ipsec_notify_unregister() |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 299 | * unregister the IPsec notifier for the given interface number (if_num) |
| 300 | */ |
| 301 | void nss_ipsec_notify_unregister(struct nss_ctx_instance *nss_ctx, uint32_t if_num) |
| 302 | { |
| 303 | if (if_num >= NSS_MAX_NET_INTERFACES) { |
| 304 | nss_ipsec_warning("%p: notify unregister received for invalid interface %d", nss_ctx, if_num); |
| 305 | return; |
| 306 | } |
| 307 | |
| 308 | if (nss_ipsec_set_msg_callback(nss_ctx, if_num, NULL, NULL) != NSS_TX_SUCCESS) { |
| 309 | nss_ipsec_warning("%p: unregister failed\n", nss_ctx); |
| 310 | return; |
| 311 | } |
| 312 | } |
Samarjeet Banerjee | 7733231 | 2014-08-07 14:48:22 +0530 | [diff] [blame] | 313 | EXPORT_SYMBOL(nss_ipsec_notify_unregister); |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 314 | |
| 315 | /* |
Ankit Dhanuka | a0e4cae | 2014-05-26 16:33:10 +0530 | [diff] [blame] | 316 | * nss_ipsec_data_register() |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 317 | * register a data callback routine |
| 318 | */ |
Sundarajan Srinivasan | 7037484 | 2014-11-19 15:22:52 -0800 | [diff] [blame] | 319 | struct 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 Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 320 | { |
Arunkumar T | 657c406 | 2016-09-21 18:06:48 +0530 | [diff] [blame] | 321 | struct nss_ctx_instance *nss_ctx, *nss_ctx0; |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 322 | |
| 323 | nss_ctx = &nss_top_main.nss[nss_top_main.ipsec_handler_id]; |
| 324 | |
| 325 | if ((if_num >= NSS_MAX_NET_INTERFACES) && (if_num < NSS_MAX_PHYSICAL_INTERFACES)){ |
| 326 | nss_ipsec_warning("%p: data register received for invalid interface %d", nss_ctx, if_num); |
| 327 | return NULL; |
| 328 | } |
| 329 | |
Samarjeet Banerjee | 940e91b | 2016-03-29 19:23:17 +0530 | [diff] [blame] | 330 | /* |
| 331 | * avoid multiple registeration for multiple tunnels |
| 332 | */ |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 333 | if (nss_ctx->subsys_dp_register[if_num].cb) { |
Samarjeet Banerjee | 940e91b | 2016-03-29 19:23:17 +0530 | [diff] [blame] | 334 | return nss_ctx; |
| 335 | } |
| 336 | |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 337 | nss_ctx->subsys_dp_register[if_num].cb = cb; |
| 338 | nss_ctx->subsys_dp_register[if_num].app_data = NULL; |
| 339 | nss_ctx->subsys_dp_register[if_num].ndev = netdev; |
| 340 | nss_ctx->subsys_dp_register[if_num].features = features; |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 341 | |
Arunkumar T | 657c406 | 2016-09-21 18:06:48 +0530 | [diff] [blame] | 342 | if (nss_top_main.ipsec_handler_id == 1) { |
| 343 | nss_ctx0 = &nss_top_main.nss[0]; |
| 344 | |
| 345 | nss_ctx0->subsys_dp_register[if_num].cb = cb; |
| 346 | nss_ctx0->subsys_dp_register[if_num].app_data = NULL; |
| 347 | nss_ctx0->subsys_dp_register[if_num].ndev = netdev; |
| 348 | nss_ctx0->subsys_dp_register[if_num].features = features; |
| 349 | } |
| 350 | |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 351 | return nss_ctx; |
| 352 | } |
Samarjeet Banerjee | 7733231 | 2014-08-07 14:48:22 +0530 | [diff] [blame] | 353 | EXPORT_SYMBOL(nss_ipsec_data_register); |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 354 | |
| 355 | /* |
Ankit Dhanuka | a0e4cae | 2014-05-26 16:33:10 +0530 | [diff] [blame] | 356 | * nss_ipsec_data_unregister() |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 357 | * unregister a data callback routine |
| 358 | */ |
| 359 | void nss_ipsec_data_unregister(struct nss_ctx_instance *nss_ctx, uint32_t if_num) |
| 360 | { |
Arunkumar T | 657c406 | 2016-09-21 18:06:48 +0530 | [diff] [blame] | 361 | struct nss_ctx_instance *nss_ctx0; |
| 362 | |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 363 | if ((if_num >= NSS_MAX_NET_INTERFACES) && (if_num < NSS_MAX_PHYSICAL_INTERFACES)){ |
| 364 | nss_ipsec_warning("%p: data unregister received for invalid interface %d", nss_ctx, if_num); |
| 365 | return; |
| 366 | } |
| 367 | |
Arunkumar T | 657c406 | 2016-09-21 18:06:48 +0530 | [diff] [blame] | 368 | if (nss_top_main.ipsec_handler_id == 1) { |
| 369 | nss_ctx0 = &nss_top_main.nss[0]; |
| 370 | |
| 371 | nss_ctx0->subsys_dp_register[if_num].cb = NULL; |
| 372 | nss_ctx0->subsys_dp_register[if_num].app_data = NULL; |
| 373 | nss_ctx0->subsys_dp_register[if_num].ndev = NULL; |
| 374 | nss_ctx0->subsys_dp_register[if_num].features = 0; |
| 375 | } |
| 376 | |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 377 | nss_ctx->subsys_dp_register[if_num].cb = NULL; |
| 378 | nss_ctx->subsys_dp_register[if_num].app_data = NULL; |
| 379 | nss_ctx->subsys_dp_register[if_num].ndev = NULL; |
| 380 | nss_ctx->subsys_dp_register[if_num].features = 0; |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 381 | } |
Samarjeet Banerjee | 7733231 | 2014-08-07 14:48:22 +0530 | [diff] [blame] | 382 | EXPORT_SYMBOL(nss_ipsec_data_unregister); |
| 383 | |
| 384 | /* |
Radha krishna Simha Jiguru | db7ad24 | 2014-11-19 16:02:23 +0530 | [diff] [blame] | 385 | * nss_ipsec_get_interface_num() |
| 386 | * Get the NSS interface number on which ipsec user shall register |
| 387 | */ |
| 388 | int32_t nss_ipsec_get_interface(struct nss_ctx_instance *nss_ctx) |
| 389 | { |
| 390 | /* |
| 391 | * Check on which core is ipsec enabled |
| 392 | */ |
| 393 | switch(nss_ctx->id) { |
| 394 | case 0: |
| 395 | return NSS_IPSEC_RULE_INTERFACE; |
| 396 | |
| 397 | case 1: |
| 398 | return NSS_C2C_TX_INTERFACE; |
| 399 | } |
| 400 | |
| 401 | return -1; |
| 402 | } |
| 403 | EXPORT_SYMBOL(nss_ipsec_get_interface); |
| 404 | |
| 405 | /* |
Samarjeet Banerjee | 7733231 | 2014-08-07 14:48:22 +0530 | [diff] [blame] | 406 | * nss_ipsec_get_ctx() |
| 407 | * get NSS context instance for IPsec handle |
| 408 | */ |
| 409 | struct nss_ctx_instance *nss_ipsec_get_context(void) |
| 410 | { |
| 411 | return &nss_top_main.nss[nss_top_main.ipsec_handler_id]; |
| 412 | } |
| 413 | EXPORT_SYMBOL(nss_ipsec_get_context); |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 414 | |
| 415 | /* |
| 416 | * nss_ipsec_register_handler() |
| 417 | */ |
| 418 | void nss_ipsec_register_handler() |
| 419 | { |
| 420 | struct nss_ctx_instance *nss_ctx = &nss_top_main.nss[nss_top_main.ipsec_handler_id]; |
| 421 | |
| 422 | nss_ipsec_set_msg_callback(nss_ctx, NSS_IPSEC_ENCAP_IF_NUMBER, NULL, NULL); |
| 423 | nss_core_register_handler(NSS_IPSEC_ENCAP_IF_NUMBER, nss_ipsec_msg_handler, NULL); |
| 424 | |
| 425 | nss_ipsec_set_msg_callback(nss_ctx, NSS_IPSEC_DECAP_IF_NUMBER, NULL, NULL); |
| 426 | nss_core_register_handler(NSS_IPSEC_DECAP_IF_NUMBER, nss_ipsec_msg_handler, NULL); |
| 427 | } |
| 428 | |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 429 | /* |
| 430 | * nss_ipsec_msg_init() |
| 431 | * Initialize ipsec message. |
| 432 | */ |
| 433 | void nss_ipsec_msg_init(struct nss_ipsec_msg *nim, uint16_t if_num, uint32_t type, uint32_t len, |
Sundarajan Srinivasan | 30a53d4 | 2015-01-30 10:52:08 -0800 | [diff] [blame] | 434 | nss_ipsec_msg_callback_t cb, void *app_data) |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 435 | { |
| 436 | nss_cmn_msg_init(&nim->cm, if_num, type, len, (void *)cb, app_data); |
| 437 | } |
| 438 | EXPORT_SYMBOL(nss_ipsec_msg_init); |