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 | |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 25 | #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 Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 29 | |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 30 | #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 Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 46 | |
| 47 | /* |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 48 | * 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 Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 52 | */ |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 53 | static inline nss_ptr_t nss_ipsec_get_msg_ctx(struct nss_ctx_instance *nss_ctx, uint32_t interface_num) |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 54 | { |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 55 | struct nss_top_instance *nss_top = nss_ctx->nss_top; |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 56 | |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 57 | /* |
| 58 | * the encap is primary interface |
| 59 | */ |
| 60 | if (interface_num == NSS_IPSEC_ENCAP_IF_NUMBER) |
| 61 | return (nss_ptr_t)nss_top->ipsec_encap_ctx; |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 62 | |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 63 | return (nss_ptr_t)nss_top->ipsec_decap_ctx; |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | /* |
| 67 | * nss_ipsec_get_msg_callback() |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 68 | * this gets the message callback handler |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 69 | */ |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 70 | static inline nss_ptr_t nss_ipsec_get_msg_callback(struct nss_ctx_instance *nss_ctx, uint32_t interface_num) |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 71 | { |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 72 | struct nss_top_instance *nss_top = nss_ctx->nss_top; |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 73 | |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 74 | /* |
| 75 | * the encap is primary interface |
| 76 | */ |
| 77 | if (interface_num == NSS_IPSEC_ENCAP_IF_NUMBER) |
| 78 | return (nss_ptr_t)nss_top->ipsec_encap_callback; |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 79 | |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 80 | return (nss_ptr_t)nss_top->ipsec_decap_callback; |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 81 | } |
| 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 | */ |
| 93 | static 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 Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 98 | |
| 99 | /* |
| 100 | * Sanity check the message type |
| 101 | */ |
| 102 | if (ncm->type > NSS_IPSEC_MSG_TYPE_MAX) { |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 103 | nss_warning("%p: rx message type out of range: %d", nss_ctx, ncm->type); |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 104 | return; |
| 105 | } |
| 106 | |
Suruchi Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 107 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_ipsec_msg)) { |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 108 | nss_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] | 109 | return; |
| 110 | } |
| 111 | |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 112 | BUG_ON((if_num != NSS_IPSEC_ENCAP_INTERFACE_NUM) && (if_num != NSS_IPSEC_DECAP_INTERFACE_NUM)); |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 113 | |
| 114 | if (ncm->response == NSS_CMN_RESPONSE_LAST) { |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 115 | nss_warning("%p: rx message response for if %d, type %d, is invalid: %d", nss_ctx, ncm->interface, |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 116 | 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 Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 125 | 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 Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 127 | } |
| 128 | |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 129 | 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 Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 136 | nss_trace("%p: rx handler has been unregistered for i/f: %d", nss_ctx, ncm->interface); |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 137 | return; |
| 138 | } |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 139 | |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 140 | 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 | */ |
| 153 | nss_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 Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 160 | nss_info("%p: message %d for if %d\n", nss_ctx, ncm->type, ncm->interface); |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 161 | |
| 162 | NSS_VERIFY_CTX_MAGIC(nss_ctx); |
| 163 | |
| 164 | if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) { |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 165 | nss_warning("%p: tx message dropped as core not ready", nss_ctx); |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 166 | return NSS_TX_FAILURE_NOT_READY; |
| 167 | } |
| 168 | |
Tanmay V Jagdale | f6b2bce | 2017-03-03 14:31:07 +0530 | [diff] [blame] | 169 | BUILD_BUG_ON(NSS_NBUF_PAYLOAD_SIZE < sizeof(struct nss_ipsec_msg)); |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 170 | |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 171 | 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 Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 173 | return NSS_TX_FAILURE; |
| 174 | } |
| 175 | |
| 176 | if (ncm->type > NSS_IPSEC_MSG_TYPE_MAX) { |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 177 | nss_warning("%p: tx message type out of range: %d", nss_ctx, ncm->type); |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 178 | return NSS_TX_FAILURE; |
| 179 | } |
| 180 | |
Suruchi Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 181 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_ipsec_msg)) { |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 182 | nss_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] | 183 | return NSS_TX_FAILURE_BAD_PARAM; |
| 184 | } |
| 185 | |
Pamidipati, Vijay | b6e3884 | 2014-09-16 10:26:05 +0530 | [diff] [blame] | 186 | nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE); |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 187 | if (unlikely(!nbuf)) { |
Sundarajan Srinivasan | 62fee7e | 2015-01-22 11:13:10 -0800 | [diff] [blame] | 188 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]); |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 189 | nss_warning("%p: tx rule dropped as command allocation failed", nss_ctx); |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 190 | return NSS_TX_FAILURE; |
| 191 | } |
| 192 | |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 193 | nss_info("msg params version:%d, interface:%d, type:%d, cb:%p, app_data:%p, len:%d\n", |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 194 | 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] | 195 | |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 196 | 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, Vijay | b6e3884 | 2014-09-16 10:26:05 +0530 | [diff] [blame] | 201 | dev_kfree_skb_any(nbuf); |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 202 | nss_warning("%p: tx Unable to enqueue message \n", nss_ctx); |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 203 | return NSS_TX_FAILURE; |
| 204 | } |
| 205 | |
Stephen Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 206 | nss_hal_send_interrupt(nss_ctx, NSS_H2N_INTR_DATA_COMMAND_QUEUE); |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 207 | |
| 208 | return NSS_TX_SUCCESS; |
| 209 | } |
Samarjeet Banerjee | 7733231 | 2014-08-07 14:48:22 +0530 | [diff] [blame] | 210 | EXPORT_SYMBOL(nss_ipsec_tx_msg); |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 211 | |
| 212 | /* |
Radha krishna Simha Jiguru | d36b1e2 | 2014-09-12 15:14:52 +0530 | [diff] [blame] | 213 | * nss_ipsec_tx_buf |
| 214 | * Send data packet for ipsec processing |
| 215 | */ |
Stephen Wang | 83e4875 | 2015-03-03 18:41:40 -0800 | [diff] [blame] | 216 | 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] | 217 | { |
Radha krishna Simha Jiguru | d36b1e2 | 2014-09-12 15:14:52 +0530 | [diff] [blame] | 218 | struct nss_ctx_instance *nss_ctx = &nss_top_main.nss[nss_top_main.ipsec_handler_id]; |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 219 | int32_t status; |
Radha krishna Simha Jiguru | d36b1e2 | 2014-09-12 15:14:52 +0530 | [diff] [blame] | 220 | |
Stephen Wang | 83e4875 | 2015-03-03 18:41:40 -0800 | [diff] [blame] | 221 | 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] | 222 | |
| 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 Wang | 83e4875 | 2015-03-03 18:41:40 -0800 | [diff] [blame] | 229 | 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] | 230 | 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 Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 242 | 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] | 243 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_PACKET]); |
| 244 | return NSS_TX_SUCCESS; |
| 245 | } |
| 246 | EXPORT_SYMBOL(nss_ipsec_tx_buf); |
| 247 | |
| 248 | /* |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 249 | ********************************** |
| 250 | Register APIs |
| 251 | ********************************** |
| 252 | */ |
| 253 | |
| 254 | /* |
Ankit Dhanuka | a0e4cae | 2014-05-26 16:33:10 +0530 | [diff] [blame] | 255 | * nss_ipsec_notify_register() |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 256 | * register message notifier for the given interface (if_num) |
| 257 | */ |
| 258 | struct nss_ctx_instance *nss_ipsec_notify_register(uint32_t if_num, nss_ipsec_msg_callback_t cb, void *app_data) |
| 259 | { |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 260 | 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 Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 263 | |
| 264 | if (if_num >= NSS_MAX_NET_INTERFACES) { |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 265 | nss_warning("%p: notfiy register received for invalid interface %d", nss_ctx, if_num); |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 266 | return NULL; |
| 267 | } |
| 268 | |
Samarjeet Banerjee | 940e91b | 2016-03-29 19:23:17 +0530 | [diff] [blame] | 269 | /* |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 270 | * the encap is primary interface |
Samarjeet Banerjee | 940e91b | 2016-03-29 19:23:17 +0530 | [diff] [blame] | 271 | */ |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 272 | if (if_num == NSS_IPSEC_ENCAP_INTERFACE_NUM) { |
| 273 | nss_top->ipsec_encap_callback = cb; |
| 274 | nss_top->ipsec_encap_ctx = app_data; |
Samarjeet Banerjee | 940e91b | 2016-03-29 19:23:17 +0530 | [diff] [blame] | 275 | return nss_ctx; |
| 276 | } |
| 277 | |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 278 | nss_top->ipsec_decap_callback = cb; |
| 279 | nss_top->ipsec_decap_ctx = app_data; |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 280 | return nss_ctx; |
| 281 | } |
Samarjeet Banerjee | 7733231 | 2014-08-07 14:48:22 +0530 | [diff] [blame] | 282 | EXPORT_SYMBOL(nss_ipsec_notify_register); |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 283 | |
| 284 | /* |
Ankit Dhanuka | a0e4cae | 2014-05-26 16:33:10 +0530 | [diff] [blame] | 285 | * nss_ipsec_notify_unregister() |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 286 | * unregister the IPsec notifier for the given interface number (if_num) |
| 287 | */ |
| 288 | void nss_ipsec_notify_unregister(struct nss_ctx_instance *nss_ctx, uint32_t if_num) |
| 289 | { |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 290 | struct nss_top_instance *nss_top = nss_ctx->nss_top; |
| 291 | |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 292 | if (if_num >= NSS_MAX_NET_INTERFACES) { |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 293 | nss_warning("%p: notify unregister received for invalid interface %d", nss_ctx, if_num); |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 294 | return; |
| 295 | } |
| 296 | |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 297 | /* |
| 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 Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 303 | return; |
| 304 | } |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 305 | |
| 306 | nss_top->ipsec_decap_callback = NULL; |
| 307 | nss_top->ipsec_decap_ctx = NULL; |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 308 | } |
Samarjeet Banerjee | 7733231 | 2014-08-07 14:48:22 +0530 | [diff] [blame] | 309 | EXPORT_SYMBOL(nss_ipsec_notify_unregister); |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 310 | |
| 311 | /* |
Ankit Dhanuka | a0e4cae | 2014-05-26 16:33:10 +0530 | [diff] [blame] | 312 | * nss_ipsec_data_register() |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 313 | * register a data callback routine |
| 314 | */ |
Sundarajan Srinivasan | 7037484 | 2014-11-19 15:22:52 -0800 | [diff] [blame] | 315 | 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] | 316 | { |
Arunkumar T | 657c406 | 2016-09-21 18:06:48 +0530 | [diff] [blame] | 317 | struct nss_ctx_instance *nss_ctx, *nss_ctx0; |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 318 | |
| 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 Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 322 | nss_warning("%p: data register received for invalid interface %d", nss_ctx, if_num); |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 323 | return NULL; |
| 324 | } |
| 325 | |
Samarjeet Banerjee | 940e91b | 2016-03-29 19:23:17 +0530 | [diff] [blame] | 326 | /* |
| 327 | * avoid multiple registeration for multiple tunnels |
| 328 | */ |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 329 | if (nss_ctx->subsys_dp_register[if_num].cb) { |
Samarjeet Banerjee | 940e91b | 2016-03-29 19:23:17 +0530 | [diff] [blame] | 330 | return nss_ctx; |
| 331 | } |
| 332 | |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 333 | 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 Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 337 | |
Arunkumar T | 657c406 | 2016-09-21 18:06:48 +0530 | [diff] [blame] | 338 | 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 Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 347 | return nss_ctx; |
| 348 | } |
Samarjeet Banerjee | 7733231 | 2014-08-07 14:48:22 +0530 | [diff] [blame] | 349 | EXPORT_SYMBOL(nss_ipsec_data_register); |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 350 | |
| 351 | /* |
Ankit Dhanuka | a0e4cae | 2014-05-26 16:33:10 +0530 | [diff] [blame] | 352 | * nss_ipsec_data_unregister() |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 353 | * unregister a data callback routine |
| 354 | */ |
| 355 | void nss_ipsec_data_unregister(struct nss_ctx_instance *nss_ctx, uint32_t if_num) |
| 356 | { |
Arunkumar T | 657c406 | 2016-09-21 18:06:48 +0530 | [diff] [blame] | 357 | struct nss_ctx_instance *nss_ctx0; |
| 358 | |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 359 | if ((if_num >= NSS_MAX_NET_INTERFACES) && (if_num < NSS_MAX_PHYSICAL_INTERFACES)){ |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 360 | nss_warning("%p: data unregister received for invalid interface %d", nss_ctx, if_num); |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 361 | return; |
| 362 | } |
| 363 | |
Arunkumar T | 657c406 | 2016-09-21 18:06:48 +0530 | [diff] [blame] | 364 | 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 Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 373 | 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 Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 377 | } |
Samarjeet Banerjee | 7733231 | 2014-08-07 14:48:22 +0530 | [diff] [blame] | 378 | EXPORT_SYMBOL(nss_ipsec_data_unregister); |
| 379 | |
| 380 | /* |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 381 | * nss_ipsec_get_encap_interface() |
| 382 | * Get the NSS interface number for encap message |
Radha krishna Simha Jiguru | db7ad24 | 2014-11-19 16:02:23 +0530 | [diff] [blame] | 383 | */ |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 384 | int32_t nss_ipsec_get_encap_interface(void) |
Radha krishna Simha Jiguru | db7ad24 | 2014-11-19 16:02:23 +0530 | [diff] [blame] | 385 | { |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 386 | return NSS_IPSEC_ENCAP_INTERFACE_NUM; |
Radha krishna Simha Jiguru | db7ad24 | 2014-11-19 16:02:23 +0530 | [diff] [blame] | 387 | } |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 388 | EXPORT_SYMBOL(nss_ipsec_get_encap_interface); |
| 389 | |
| 390 | /* |
| 391 | * nss_ipsec_get_decap_interface() |
| 392 | * Get the NSS interface number for decap message |
| 393 | */ |
| 394 | int32_t nss_ipsec_get_decap_interface(void) |
| 395 | { |
| 396 | return NSS_IPSEC_DECAP_INTERFACE_NUM; |
| 397 | } |
| 398 | EXPORT_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 | */ |
| 404 | int32_t nss_ipsec_get_data_interface(void) |
| 405 | { |
| 406 | return NSS_IPSEC_DATA_INTERFACE_NUM; |
| 407 | } |
| 408 | EXPORT_SYMBOL(nss_ipsec_get_data_interface); |
Radha krishna Simha Jiguru | db7ad24 | 2014-11-19 16:02:23 +0530 | [diff] [blame] | 409 | |
| 410 | /* |
Samarjeet Banerjee | 7733231 | 2014-08-07 14:48:22 +0530 | [diff] [blame] | 411 | * nss_ipsec_get_ctx() |
| 412 | * get NSS context instance for IPsec handle |
| 413 | */ |
| 414 | struct nss_ctx_instance *nss_ipsec_get_context(void) |
| 415 | { |
| 416 | return &nss_top_main.nss[nss_top_main.ipsec_handler_id]; |
| 417 | } |
| 418 | EXPORT_SYMBOL(nss_ipsec_get_context); |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 419 | |
| 420 | /* |
| 421 | * nss_ipsec_register_handler() |
| 422 | */ |
| 423 | void nss_ipsec_register_handler() |
| 424 | { |
| 425 | struct nss_ctx_instance *nss_ctx = &nss_top_main.nss[nss_top_main.ipsec_handler_id]; |
| 426 | |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 427 | BUILD_BUG_ON(NSS_IPSEC_ENCAP_INTERFACE_NUM < 0); |
| 428 | BUILD_BUG_ON(NSS_IPSEC_DECAP_INTERFACE_NUM < 0); |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 429 | |
Sourav Poddar | bf8b50c | 2017-02-15 12:44:44 +0530 | [diff] [blame] | 430 | 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 | |
| 436 | nss_core_register_handler(NSS_IPSEC_ENCAP_INTERFACE_NUM, nss_ipsec_msg_handler, NULL); |
| 437 | nss_core_register_handler(NSS_IPSEC_DECAP_INTERFACE_NUM, nss_ipsec_msg_handler, NULL); |
Samarjeet Banerjee | d99d9d0 | 2014-04-08 18:51:00 +0530 | [diff] [blame] | 438 | } |
| 439 | |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 440 | /* |
| 441 | * nss_ipsec_msg_init() |
| 442 | * Initialize ipsec message. |
| 443 | */ |
| 444 | 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] | 445 | nss_ipsec_msg_callback_t cb, void *app_data) |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 446 | { |
| 447 | nss_cmn_msg_init(&nim->cm, if_num, type, len, (void *)cb, app_data); |
| 448 | } |
| 449 | EXPORT_SYMBOL(nss_ipsec_msg_init); |