Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, The Linux Foundation. All rights reserved. |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [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_ipv6.c |
| 19 | * NSS IPv6 APIs |
| 20 | */ |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 21 | #include "nss_tx_rx_common.h" |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 22 | |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 23 | #define NSS_IPV6_TX_MSG_TIMEOUT 1000 /* 1 sec timeout for IPv4 messages */ |
| 24 | |
| 25 | /* |
| 26 | * Private data structure for ipv6 configure messages |
| 27 | */ |
| 28 | struct nss_ipv6_cfg_pvt { |
| 29 | struct semaphore sem; /* Semaphore structure */ |
| 30 | struct completion complete; /* completion structure */ |
| 31 | int current_value; /* valid entry */ |
| 32 | int response; /* Response from FW */ |
| 33 | }; |
| 34 | |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 35 | /* |
| 36 | * Private data structure for ipv4 connection information. |
| 37 | */ |
| 38 | struct nss_ipv6_conn_table_info { |
| 39 | uint32_t ce_table_size; /* Size of connection entry table in NSS FW */ |
| 40 | uint32_t cme_table_size; /* Size of connection match entry table in NSS FW */ |
| 41 | unsigned long ce_mem; /* Start address for connection entry table */ |
| 42 | unsigned long cme_mem; /* Start address for connection match entry table */ |
| 43 | } nss_ipv6_ct_info; |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 44 | |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 45 | int nss_ipv6_conn_cfg = NSS_DEFAULT_NUM_CONN; |
Stephen Wang | f6a9acb | 2017-08-23 10:35:39 -0700 | [diff] [blame] | 46 | int nss_ipv6_accel_mode_cfg __read_mostly = 1; |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 47 | |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 48 | static struct nss_ipv6_cfg_pvt i6_accel_mode_cfgp; |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 49 | |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 50 | /* |
Suruchi Agarwal | 611ecd0 | 2016-08-04 15:54:35 -0700 | [diff] [blame] | 51 | * Callback for conn_sync_many request message. |
| 52 | */ |
| 53 | nss_ipv6_msg_callback_t nss_ipv6_conn_sync_many_msg_cb = NULL; |
| 54 | |
| 55 | /* |
Gareth Williams | 958aa82 | 2015-02-04 19:36:39 +0000 | [diff] [blame] | 56 | * nss_ipv6_max_conn_count() |
| 57 | * Return the maximum number of IPv6 connections that the NSS acceleration engine supports. |
| 58 | */ |
| 59 | int nss_ipv6_max_conn_count(void) |
| 60 | { |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 61 | return nss_ipv6_conn_cfg; |
Gareth Williams | 958aa82 | 2015-02-04 19:36:39 +0000 | [diff] [blame] | 62 | } |
| 63 | EXPORT_SYMBOL(nss_ipv6_max_conn_count); |
| 64 | |
| 65 | /* |
Guojun Jin | 9a1cb28 | 2017-07-13 17:32:07 -0700 | [diff] [blame] | 66 | * nss_ipv6_conn_inquiry() |
| 67 | * Inquiry if a connection has been established in NSS FW |
| 68 | */ |
| 69 | nss_tx_status_t nss_ipv6_conn_inquiry(struct nss_ipv6_5tuple *ipv6_5t_p, |
| 70 | nss_ipv6_msg_callback_t cb) |
| 71 | { |
| 72 | nss_tx_status_t nss_tx_status; |
| 73 | struct nss_ipv6_msg nim; |
| 74 | struct nss_ctx_instance *nss_ctx = &nss_top_main.nss[0]; |
| 75 | |
| 76 | /* |
| 77 | * Initialize inquiry message structure. |
| 78 | * This is async message and the result will be returned |
| 79 | * to the caller by the msg_callback passed in. |
| 80 | */ |
| 81 | memset(&nim, 0, sizeof(nim)); |
| 82 | nss_ipv6_msg_init(&nim, NSS_IPV6_RX_INTERFACE, |
| 83 | NSS_IPV6_TX_CONN_CFG_INQUIRY_MSG, |
| 84 | sizeof(struct nss_ipv6_inquiry_msg), |
| 85 | cb, NULL); |
| 86 | nim.msg.inquiry.rr.tuple = *ipv6_5t_p; |
| 87 | nss_tx_status = nss_ipv6_tx(nss_ctx, &nim); |
| 88 | if (nss_tx_status != NSS_TX_SUCCESS) { |
| 89 | nss_warning("%p: Send inquiry message failed\n", ipv6_5t_p); |
| 90 | } |
| 91 | |
| 92 | return nss_tx_status; |
| 93 | } |
| 94 | EXPORT_SYMBOL(nss_ipv6_conn_inquiry); |
| 95 | |
| 96 | /* |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 97 | * nss_ipv6_driver_conn_sync_update() |
| 98 | * Update driver specific information from the messsage. |
| 99 | */ |
| 100 | static void nss_ipv6_driver_conn_sync_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_conn_sync *nics) |
| 101 | { |
| 102 | struct nss_top_instance *nss_top = nss_ctx->nss_top; |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 103 | |
| 104 | /* |
| 105 | * Update statistics maintained by NSS driver |
| 106 | */ |
| 107 | spin_lock_bh(&nss_top->stats_lock); |
| 108 | nss_top->stats_ipv6[NSS_STATS_IPV6_ACCELERATED_RX_PKTS] += nics->flow_rx_packet_count + nics->return_rx_packet_count; |
| 109 | nss_top->stats_ipv6[NSS_STATS_IPV6_ACCELERATED_RX_BYTES] += nics->flow_rx_byte_count + nics->return_rx_byte_count; |
| 110 | nss_top->stats_ipv6[NSS_STATS_IPV6_ACCELERATED_TX_PKTS] += nics->flow_tx_packet_count + nics->return_tx_packet_count; |
| 111 | nss_top->stats_ipv6[NSS_STATS_IPV6_ACCELERATED_TX_BYTES] += nics->flow_tx_byte_count + nics->return_tx_byte_count; |
Abhishek Rastogi | 55f3945 | 2014-05-08 19:23:29 +0530 | [diff] [blame] | 112 | spin_unlock_bh(&nss_top->stats_lock); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | /* |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 116 | * nss_ipv6_driver_conn_sync_many_update() |
| 117 | * Update driver specific information from the conn_sync_many messsage. |
| 118 | */ |
| 119 | static void nss_ipv6_driver_conn_sync_many_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_conn_sync_many_msg *nicsm) |
| 120 | { |
| 121 | uint32_t i; |
| 122 | |
| 123 | /* |
| 124 | * Sanity check for the stats count |
| 125 | */ |
| 126 | if (nicsm->count * sizeof(struct nss_ipv6_conn_sync) >= nicsm->size) { |
| 127 | nss_warning("%p: stats sync count %u exceeds the size of this msg %u", nss_ctx, nicsm->count, nicsm->size); |
| 128 | return; |
| 129 | } |
| 130 | |
| 131 | for (i = 0; i < nicsm->count; i++) { |
| 132 | nss_ipv6_driver_conn_sync_update(nss_ctx, &nicsm->conn_sync[i]); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | /* |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 137 | * nss_ipv6_driver_node_sync_update) |
| 138 | * Update driver specific information from the messsage. |
| 139 | */ |
| 140 | static void nss_ipv6_driver_node_sync_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_node_sync *nins) |
| 141 | { |
| 142 | struct nss_top_instance *nss_top = nss_ctx->nss_top; |
ratheesh kannoth | 93ba95c | 2017-07-13 15:52:52 +0530 | [diff] [blame^] | 143 | int i; |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 144 | |
| 145 | /* |
| 146 | * Update statistics maintained by NSS driver |
| 147 | */ |
| 148 | spin_lock_bh(&nss_top->stats_lock); |
| 149 | nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_RX_PKTS] += nins->node_stats.rx_packets; |
| 150 | nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_RX_BYTES] += nins->node_stats.rx_bytes; |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 151 | nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_TX_PKTS] += nins->node_stats.tx_packets; |
| 152 | nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_TX_BYTES] += nins->node_stats.tx_bytes; |
| 153 | |
ratheesh kannoth | 93ba95c | 2017-07-13 15:52:52 +0530 | [diff] [blame^] | 154 | for (i = 0; i < NSS_MAX_NUM_PRI; i++) { |
| 155 | nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_RX_QUEUE_0_DROPPED + i] += nins->node_stats.rx_dropped[i]; |
| 156 | } |
| 157 | |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 158 | nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_CREATE_REQUESTS] += nins->ipv6_connection_create_requests; |
| 159 | nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_CREATE_COLLISIONS] += nins->ipv6_connection_create_collisions; |
| 160 | nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_CREATE_INVALID_INTERFACE] += nins->ipv6_connection_create_invalid_interface; |
| 161 | nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_DESTROY_REQUESTS] += nins->ipv6_connection_destroy_requests; |
| 162 | nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_DESTROY_MISSES] += nins->ipv6_connection_destroy_misses; |
| 163 | nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_HASH_HITS] += nins->ipv6_connection_hash_hits; |
| 164 | nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_HASH_REORDERS] += nins->ipv6_connection_hash_reorders; |
| 165 | nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_FLUSHES] += nins->ipv6_connection_flushes; |
| 166 | nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_EVICTIONS] += nins->ipv6_connection_evictions; |
Selin Dag | 5d68caa | 2015-05-12 13:23:33 -0700 | [diff] [blame] | 167 | nss_top->stats_ipv6[NSS_STATS_IPV6_FRAGMENTATIONS] += nins->ipv6_fragmentations; |
| 168 | nss_top->stats_ipv6[NSS_STATS_IPV6_FRAG_FAILS] += nins->ipv6_frag_fails; |
Jackson Bockus | 140d2b2 | 2017-08-10 13:56:44 -0700 | [diff] [blame] | 169 | nss_top->stats_ipv6[NSS_STATS_IPV6_DROPPED_BY_RULE] += nins->ipv6_dropped_by_rule; |
Kiran Kumar C.S.K | fadf92d | 2015-06-26 12:48:33 +0530 | [diff] [blame] | 170 | nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_CREATE_REQUESTS] += nins->ipv6_mc_connection_create_requests; |
| 171 | nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_UPDATE_REQUESTS] += nins->ipv6_mc_connection_update_requests; |
| 172 | nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_CREATE_INVALID_INTERFACE] += nins->ipv6_mc_connection_create_invalid_interface; |
| 173 | nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_DESTROY_REQUESTS] += nins->ipv6_mc_connection_destroy_requests; |
| 174 | nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_DESTROY_MISSES] += nins->ipv6_mc_connection_destroy_misses; |
| 175 | nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_FLUSHES] += nins->ipv6_mc_connection_flushes; |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 176 | |
| 177 | for (i = 0; i < NSS_EXCEPTION_EVENT_IPV6_MAX; i++) { |
| 178 | nss_top->stats_if_exception_ipv6[i] += nins->exception_events[i]; |
| 179 | } |
| 180 | spin_unlock_bh(&nss_top->stats_lock); |
| 181 | } |
| 182 | |
| 183 | /* |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 184 | * nss_ipv6_rx_msg_handler() |
| 185 | * Handle NSS -> HLOS messages for IPv6 bridge/route |
| 186 | */ |
| 187 | static void nss_ipv6_rx_msg_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data) |
| 188 | { |
| 189 | struct nss_ipv6_msg *nim = (struct nss_ipv6_msg *)ncm; |
| 190 | nss_ipv6_msg_callback_t cb; |
| 191 | |
| 192 | BUG_ON(ncm->interface != NSS_IPV6_RX_INTERFACE); |
| 193 | |
| 194 | /* |
| 195 | * Is this a valid request/response packet? |
| 196 | */ |
Murat Sezgin | 5c8c736 | 2014-09-02 17:58:21 -0700 | [diff] [blame] | 197 | if (ncm->type >= NSS_IPV6_MAX_MSG_TYPES) { |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 198 | nss_warning("%p: received invalid message %d for IPv6 interface", nss_ctx, nim->cm.type); |
| 199 | return; |
| 200 | } |
| 201 | |
Suruchi Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 202 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_ipv6_msg)) { |
| 203 | nss_warning("%p: message length is invalid: %d", nss_ctx, nss_cmn_get_msg_len(ncm)); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 204 | return; |
| 205 | } |
| 206 | |
| 207 | /* |
Suruchi Agarwal | e3940e7 | 2016-07-06 15:56:51 -0700 | [diff] [blame] | 208 | * Trace messages. |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 209 | */ |
Suruchi Agarwal | e3940e7 | 2016-07-06 15:56:51 -0700 | [diff] [blame] | 210 | nss_ipv6_log_rx_msg(nim); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 211 | |
| 212 | /* |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 213 | * Handle deprecated messages. Eventually these messages should be removed. |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 214 | */ |
| 215 | switch (nim->cm.type) { |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 216 | case NSS_IPV6_RX_NODE_STATS_SYNC_MSG: |
| 217 | /* |
| 218 | * Update driver statistics on node sync. |
| 219 | */ |
| 220 | nss_ipv6_driver_node_sync_update(nss_ctx, &nim->msg.node_stats); |
| 221 | break; |
| 222 | |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 223 | case NSS_IPV6_RX_CONN_STATS_SYNC_MSG: |
| 224 | /* |
| 225 | * Update driver statistics on connection sync. |
| 226 | */ |
| 227 | nss_ipv6_driver_conn_sync_update(nss_ctx, &nim->msg.conn_stats); |
Sakthi Vignesh Radhakrishnan | 515f8c2 | 2014-06-21 15:04:19 -0700 | [diff] [blame] | 228 | break; |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 229 | |
| 230 | case NSS_IPV6_TX_CONN_STATS_SYNC_MANY_MSG: |
| 231 | /* |
| 232 | * Update driver statistics on connection sync many. |
| 233 | */ |
| 234 | nss_ipv6_driver_conn_sync_many_update(nss_ctx, &nim->msg.conn_stats_many); |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 235 | ncm->cb = (nss_ptr_t)nss_ipv6_conn_sync_many_msg_cb; |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 236 | break; |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 237 | } |
Abhishek Rastogi | 55f3945 | 2014-05-08 19:23:29 +0530 | [diff] [blame] | 238 | |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 239 | /* |
| 240 | * Update the callback and app_data for NOTIFY messages, IPv6 sends all notify messages |
| 241 | * to the same callback/app_data. |
| 242 | */ |
| 243 | if (nim->cm.response == NSS_CMM_RESPONSE_NOTIFY) { |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 244 | ncm->cb = (nss_ptr_t)nss_ctx->nss_top->ipv6_callback; |
| 245 | ncm->app_data = (nss_ptr_t)nss_ctx->nss_top->ipv6_ctx; |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | /* |
| 249 | * Do we have a callback? |
| 250 | */ |
| 251 | if (!ncm->cb) { |
| 252 | return; |
| 253 | } |
| 254 | |
| 255 | /* |
| 256 | * Callback |
| 257 | */ |
| 258 | cb = (nss_ipv6_msg_callback_t)ncm->cb; |
| 259 | cb((void *)ncm->app_data, nim); |
| 260 | } |
| 261 | |
| 262 | /* |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 263 | * nss_ipv6_tx_with_size() |
| 264 | * Transmit an ipv6 message to the FW with a specified size. |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 265 | */ |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 266 | nss_tx_status_t nss_ipv6_tx_with_size(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_msg *nim, uint32_t size) |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 267 | { |
| 268 | struct nss_ipv6_msg *nim2; |
| 269 | struct nss_cmn_msg *ncm = &nim->cm; |
| 270 | struct sk_buff *nbuf; |
| 271 | int32_t status; |
| 272 | |
| 273 | NSS_VERIFY_CTX_MAGIC(nss_ctx); |
| 274 | if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) { |
| 275 | nss_warning("%p: ipv6 msg dropped as core not ready", nss_ctx); |
| 276 | return NSS_TX_FAILURE_NOT_READY; |
| 277 | } |
| 278 | |
| 279 | /* |
| 280 | * Sanity check the message |
| 281 | */ |
| 282 | if (ncm->interface != NSS_IPV6_RX_INTERFACE) { |
| 283 | nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface); |
| 284 | return NSS_TX_FAILURE; |
| 285 | } |
| 286 | |
Murat Sezgin | 5c8c736 | 2014-09-02 17:58:21 -0700 | [diff] [blame] | 287 | if (ncm->type >= NSS_IPV6_MAX_MSG_TYPES) { |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 288 | nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type); |
| 289 | return NSS_TX_FAILURE; |
| 290 | } |
| 291 | |
Suruchi Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 292 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_ipv6_msg)) { |
| 293 | nss_warning("%p: message length is invalid: %d", nss_ctx, nss_cmn_get_msg_len(ncm)); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 294 | return NSS_TX_FAILURE; |
| 295 | } |
| 296 | |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 297 | if(size > PAGE_SIZE) { |
| 298 | nss_warning("%p: tx request size too large: %u", nss_ctx, size); |
| 299 | return NSS_TX_FAILURE; |
| 300 | } |
| 301 | |
| 302 | nbuf = dev_alloc_skb(size); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 303 | if (unlikely(!nbuf)) { |
Sundarajan Srinivasan | 62fee7e | 2015-01-22 11:13:10 -0800 | [diff] [blame] | 304 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 305 | nss_warning("%p: msg dropped as command allocation failed", nss_ctx); |
| 306 | return NSS_TX_FAILURE; |
| 307 | } |
| 308 | |
| 309 | /* |
| 310 | * Copy the message to our skb. |
| 311 | */ |
Suruchi Agarwal | ea2e523 | 2016-09-14 10:32:08 -0700 | [diff] [blame] | 312 | nim2 = (struct nss_ipv6_msg *)skb_put(nbuf, size); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 313 | memcpy(nim2, nim, sizeof(struct nss_ipv6_msg)); |
| 314 | |
Suruchi Agarwal | e3940e7 | 2016-07-06 15:56:51 -0700 | [diff] [blame] | 315 | /* |
| 316 | * Trace messages. |
| 317 | */ |
| 318 | nss_ipv6_log_tx_msg(nim); |
| 319 | |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 320 | status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0); |
| 321 | if (status != NSS_CORE_STATUS_SUCCESS) { |
Pamidipati, Vijay | b6e3884 | 2014-09-16 10:26:05 +0530 | [diff] [blame] | 322 | dev_kfree_skb_any(nbuf); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 323 | nss_warning("%p: Unable to enqueue 'Destroy IPv6' rule\n", nss_ctx); |
| 324 | return NSS_TX_FAILURE; |
| 325 | } |
| 326 | |
Stephen Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 327 | nss_hal_send_interrupt(nss_ctx, NSS_H2N_INTR_DATA_COMMAND_QUEUE); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 328 | |
| 329 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]); |
| 330 | return NSS_TX_SUCCESS; |
| 331 | } |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 332 | EXPORT_SYMBOL(nss_ipv6_tx_with_size); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 333 | |
| 334 | /* |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 335 | * nss_ipv6_tx() |
Suruchi Agarwal | 611ecd0 | 2016-08-04 15:54:35 -0700 | [diff] [blame] | 336 | * Transmit an ipv6 message to the FW. |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 337 | */ |
| 338 | nss_tx_status_t nss_ipv6_tx(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_msg *nim) |
| 339 | { |
| 340 | return nss_ipv6_tx_with_size(nss_ctx, nim, NSS_NBUF_PAYLOAD_SIZE); |
| 341 | } |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 342 | EXPORT_SYMBOL(nss_ipv6_tx); |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 343 | |
| 344 | /* |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 345 | ********************************** |
| 346 | Register/Unregister/Miscellaneous APIs |
| 347 | ********************************** |
| 348 | */ |
| 349 | |
| 350 | /* |
| 351 | * nss_ipv6_notify_register() |
| 352 | * Register to received IPv6 events. |
| 353 | * |
| 354 | * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv6 on any core? |
| 355 | */ |
| 356 | struct nss_ctx_instance *nss_ipv6_notify_register(nss_ipv6_msg_callback_t cb, void *app_data) |
| 357 | { |
| 358 | /* |
| 359 | * TODO: We need to have a new array in support of the new API |
| 360 | * TODO: If we use a per-context array, we would move the array into nss_ctx based. |
| 361 | */ |
| 362 | nss_top_main.ipv6_callback = cb; |
| 363 | nss_top_main.ipv6_ctx = app_data; |
| 364 | return &nss_top_main.nss[nss_top_main.ipv6_handler_id]; |
| 365 | } |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 366 | EXPORT_SYMBOL(nss_ipv6_notify_register); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 367 | |
| 368 | /* |
| 369 | * nss_ipv6_notify_unregister() |
| 370 | * Unregister to received IPv6 events. |
| 371 | * |
| 372 | * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv6 on any core? |
| 373 | */ |
| 374 | void nss_ipv6_notify_unregister(void) |
| 375 | { |
| 376 | nss_top_main.ipv6_callback = NULL; |
| 377 | } |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 378 | EXPORT_SYMBOL(nss_ipv6_notify_unregister); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 379 | |
| 380 | /* |
Suruchi Agarwal | 611ecd0 | 2016-08-04 15:54:35 -0700 | [diff] [blame] | 381 | * nss_ipv6_conn_sync_many_notify_register() |
| 382 | * Register to receive IPv6 conn_sync_many message response. |
| 383 | */ |
| 384 | void nss_ipv6_conn_sync_many_notify_register(nss_ipv6_msg_callback_t cb) |
| 385 | { |
| 386 | nss_ipv6_conn_sync_many_msg_cb = cb; |
| 387 | } |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 388 | EXPORT_SYMBOL(nss_ipv6_conn_sync_many_notify_register); |
Suruchi Agarwal | 611ecd0 | 2016-08-04 15:54:35 -0700 | [diff] [blame] | 389 | |
| 390 | /* |
| 391 | * nss_ipv6_conn_sync_many_notify_unregister() |
| 392 | * Unregister to receive IPv6 conn_sync_many message response. |
| 393 | */ |
| 394 | void nss_ipv6_conn_sync_many_notify_unregister(void) |
| 395 | { |
| 396 | nss_ipv6_conn_sync_many_msg_cb = NULL; |
| 397 | } |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 398 | EXPORT_SYMBOL(nss_ipv6_conn_sync_many_notify_unregister); |
Suruchi Agarwal | 611ecd0 | 2016-08-04 15:54:35 -0700 | [diff] [blame] | 399 | |
| 400 | /* |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 401 | * nss_ipv6_get_mgr() |
| 402 | * |
| 403 | * TODO: This only suppports a single ipv6, do we ever want to support more? |
| 404 | */ |
| 405 | struct nss_ctx_instance *nss_ipv6_get_mgr(void) |
| 406 | { |
| 407 | return (void *)&nss_top_main.nss[nss_top_main.ipv6_handler_id]; |
| 408 | } |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 409 | EXPORT_SYMBOL(nss_ipv6_get_mgr); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 410 | |
| 411 | /* |
| 412 | * nss_ipv6_register_handler() |
| 413 | * Register our handler to receive messages for this interface |
| 414 | */ |
| 415 | void nss_ipv6_register_handler() |
| 416 | { |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 417 | struct nss_ctx_instance *nss_ctx = nss_ipv6_get_mgr(); |
| 418 | |
| 419 | if (nss_core_register_handler(nss_ctx, NSS_IPV6_RX_INTERFACE, nss_ipv6_rx_msg_handler, NULL) != NSS_CORE_STATUS_SUCCESS) { |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 420 | nss_warning("IPv6 handler failed to register"); |
| 421 | } |
| 422 | } |
| 423 | |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 424 | /* |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 425 | * nss_ipv6_conn_cfg_process_callback() |
| 426 | * Call back function for the ipv6 connection configuration process. |
| 427 | */ |
| 428 | static void nss_ipv6_conn_cfg_process_callback(void *app_data, struct nss_ipv6_msg *nim) |
| 429 | { |
| 430 | struct nss_ipv6_rule_conn_cfg_msg *nirccm = &nim->msg.rule_conn_cfg; |
| 431 | struct nss_ctx_instance *nss_ctx __maybe_unused = nss_ipv6_get_mgr(); |
| 432 | |
| 433 | if (nim->cm.response != NSS_CMN_RESPONSE_ACK) { |
| 434 | nss_warning("%p: IPv6 connection configuration failed with error: %d\n", nss_ctx, nim->cm.error); |
| 435 | nss_core_update_max_ipv6_conn(NSS_DEFAULT_NUM_CONN); |
| 436 | nss_ipv6_free_conn_tables(); |
| 437 | return; |
| 438 | } |
| 439 | |
| 440 | nss_ipv6_conn_cfg = ntohl(nirccm->num_conn); |
| 441 | |
| 442 | nss_warning("%p: IPv6 connection configuration success: %d\n", nss_ctx, nim->cm.error); |
| 443 | } |
| 444 | |
| 445 | /* |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 446 | * nss_ipv6_conn_cfg_process() |
| 447 | * Process request to configure number of ipv6 connections |
| 448 | */ |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 449 | static int nss_ipv6_conn_cfg_process(struct nss_ctx_instance *nss_ctx, int conn) |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 450 | { |
| 451 | struct nss_ipv6_msg nim; |
| 452 | struct nss_ipv6_rule_conn_cfg_msg *nirccm; |
| 453 | nss_tx_status_t nss_tx_status; |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 454 | |
| 455 | if ((!nss_ipv6_ct_info.ce_table_size) || (!nss_ipv6_ct_info.cme_table_size)) { |
| 456 | nss_warning("%p: connection entry or connection match entry table size not available\n", |
| 457 | nss_ctx); |
| 458 | return -EINVAL; |
| 459 | } |
| 460 | |
| 461 | nss_info("%p: IPv6 supported connections: %d\n", nss_ctx, conn); |
| 462 | |
| 463 | nss_ipv6_ct_info.ce_mem = __get_free_pages(GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO, |
| 464 | get_order(nss_ipv6_ct_info.ce_table_size)); |
| 465 | if (!nss_ipv6_ct_info.ce_mem) { |
| 466 | nss_warning("%p: Memory allocation failed for IPv6 Connections: %d\n", |
| 467 | nss_ctx, |
| 468 | conn); |
| 469 | goto fail; |
| 470 | } |
| 471 | nss_warning("%p: CE Memory allocated for IPv6 Connections: %d\n", |
| 472 | nss_ctx, |
| 473 | conn); |
| 474 | |
| 475 | nss_ipv6_ct_info.cme_mem = __get_free_pages(GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO, |
| 476 | get_order(nss_ipv6_ct_info.cme_table_size)); |
| 477 | if (!nss_ipv6_ct_info.cme_mem) { |
| 478 | nss_warning("%p: Memory allocation failed for IPv6 Connections: %d\n", |
| 479 | nss_ctx, |
| 480 | conn); |
| 481 | goto fail; |
| 482 | } |
| 483 | nss_warning("%p: CME Memory allocated for IPv6 Connections: %d\n", |
| 484 | nss_ctx, |
| 485 | conn); |
| 486 | |
| 487 | memset(&nim, 0, sizeof(struct nss_ipv6_msg)); |
| 488 | nss_ipv6_msg_init(&nim, NSS_IPV6_RX_INTERFACE, NSS_IPV6_TX_CONN_CFG_RULE_MSG, |
| 489 | sizeof(struct nss_ipv6_rule_conn_cfg_msg), nss_ipv6_conn_cfg_process_callback, NULL); |
| 490 | |
| 491 | nirccm = &nim.msg.rule_conn_cfg; |
| 492 | nirccm->num_conn = htonl(conn); |
Suruchi Agarwal | 8c9e716 | 2017-08-17 15:58:40 -0700 | [diff] [blame] | 493 | nirccm->ce_mem = dma_map_single(nss_ctx->dev, (void *)nss_ipv6_ct_info.ce_mem, nss_ipv6_ct_info.ce_table_size, DMA_TO_DEVICE); |
| 494 | if (unlikely(dma_mapping_error(nss_ctx->dev, nirccm->ce_mem))) { |
| 495 | nss_warning("%p: DMA mapping failed for virtual address = %p", nss_ctx, (void *)nss_ipv6_ct_info.ce_mem); |
| 496 | goto fail; |
| 497 | } |
| 498 | |
| 499 | nirccm->cme_mem = dma_map_single(nss_ctx->dev, (void *)nss_ipv6_ct_info.cme_mem, nss_ipv6_ct_info.cme_table_size, DMA_TO_DEVICE); |
| 500 | if (unlikely(dma_mapping_error(nss_ctx->dev, nirccm->cme_mem))) { |
| 501 | nss_warning("%p: DMA mapping failed for virtual address = %p", nss_ctx, (void *)nss_ipv6_ct_info.cme_mem); |
| 502 | goto fail; |
| 503 | } |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 504 | |
| 505 | nss_tx_status = nss_ipv6_tx(nss_ctx, &nim); |
| 506 | if (nss_tx_status != NSS_TX_SUCCESS) { |
| 507 | nss_warning("%p: nss_tx error setting IPv6 Connections: %d\n", |
| 508 | nss_ctx, |
| 509 | conn); |
| 510 | goto fail; |
| 511 | } |
| 512 | |
| 513 | return 0; |
| 514 | |
| 515 | fail: |
| 516 | nss_ipv6_free_conn_tables(); |
| 517 | return -EINVAL; |
| 518 | } |
| 519 | |
| 520 | /* |
| 521 | * nss_ipv6_update_conn_count_callback() |
| 522 | * Call back function for the ipv6 get connection info message. |
| 523 | */ |
| 524 | static void nss_ipv6_update_conn_count_callback(void *app_data, struct nss_ipv6_msg *nim) |
| 525 | { |
| 526 | struct nss_ipv6_rule_conn_get_table_size_msg *nircgts = &nim->msg.size; |
| 527 | struct nss_ctx_instance *nss_ctx = nss_ipv6_get_mgr(); |
| 528 | |
| 529 | if (nim->cm.response != NSS_CMN_RESPONSE_ACK) { |
| 530 | nss_warning("%p: IPv6 fetch connection info failed with error: %d\n", nss_ctx, nim->cm.error); |
| 531 | nss_core_update_max_ipv6_conn(NSS_DEFAULT_NUM_CONN); |
| 532 | return; |
| 533 | } |
| 534 | |
| 535 | nss_info("IPv6 get connection info success\n"); |
| 536 | |
| 537 | nss_ipv6_ct_info.ce_table_size = ntohl(nircgts->ce_table_size); |
| 538 | nss_ipv6_ct_info.cme_table_size = ntohl(nircgts->cme_table_size); |
| 539 | |
| 540 | if (nss_ipv6_conn_cfg_process(nss_ctx, ntohl(nircgts->num_conn)) != 0) { |
| 541 | nss_warning("%p: IPv6 connection entry or connection match entry table size\ |
| 542 | not available\n", nss_ctx); |
| 543 | } |
| 544 | |
| 545 | return; |
| 546 | } |
| 547 | |
| 548 | /* |
| 549 | * nss_ipv6_update_conn_count() |
| 550 | * Sets the maximum number of IPv6 connections. |
| 551 | * |
| 552 | * It first gets the connection tables size information from NSS FW |
| 553 | * and then configures the connections in NSS FW. |
| 554 | */ |
| 555 | int nss_ipv6_update_conn_count(int ipv6_num_conn) |
| 556 | { |
| 557 | struct nss_ctx_instance *nss_ctx = nss_ipv6_get_mgr(); |
| 558 | struct nss_ipv6_msg nim; |
| 559 | struct nss_ipv6_rule_conn_get_table_size_msg *nircgts; |
| 560 | nss_tx_status_t nss_tx_status; |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 561 | uint32_t sum_of_conn; |
| 562 | |
| 563 | /* |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 564 | * By default, NSS FW is configured with default number of connections. |
| 565 | */ |
| 566 | if (ipv6_num_conn == NSS_DEFAULT_NUM_CONN) { |
| 567 | nss_info("%p: Default number of connections (%d) already configured\n", nss_ctx, ipv6_num_conn); |
| 568 | return 0; |
| 569 | } |
| 570 | |
| 571 | /* |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 572 | * Specifications for input |
| 573 | * 1) The input should be power of 2. |
| 574 | * 2) Input for ipv4 and ipv6 sum togther should not exceed 8k |
| 575 | * 3) Min. value should be at leat 256 connections. This is the |
| 576 | * minimum connections we will support for each of them. |
| 577 | */ |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 578 | sum_of_conn = nss_ipv4_conn_cfg + ipv6_num_conn; |
| 579 | if ((ipv6_num_conn & NSS_NUM_CONN_QUANTA_MASK) || |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 580 | (sum_of_conn > NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6) || |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 581 | (ipv6_num_conn < NSS_MIN_NUM_CONN)) { |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 582 | nss_warning("%p: input supported connections (%d) does not adhere\ |
| 583 | specifications\n1) not power of 2,\n2) is less than \ |
| 584 | min val: %d, OR\n IPv4/6 total exceeds %d\n", |
| 585 | nss_ctx, |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 586 | ipv6_num_conn, |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 587 | NSS_MIN_NUM_CONN, |
| 588 | NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6); |
| 589 | return -EINVAL; |
| 590 | } |
| 591 | |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 592 | memset(&nim, 0, sizeof(struct nss_ipv6_msg)); |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 593 | nss_ipv6_msg_init(&nim, NSS_IPV6_RX_INTERFACE, NSS_IPV6_TX_CONN_TABLE_SIZE_MSG, |
| 594 | sizeof(struct nss_ipv6_rule_conn_get_table_size_msg), nss_ipv6_update_conn_count_callback, NULL); |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 595 | |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 596 | nircgts = &nim.msg.size; |
| 597 | nircgts->num_conn = htonl(ipv6_num_conn); |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 598 | nss_tx_status = nss_ipv6_tx(nss_ctx, &nim); |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 599 | if (nss_tx_status != NSS_TX_SUCCESS) { |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 600 | nss_warning("%p: Send acceleration mode message failed\n", nss_ctx); |
| 601 | return -EINVAL; |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | return 0; |
| 605 | } |
| 606 | |
| 607 | /* |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 608 | * nss_ipv6_free_conn_tables() |
| 609 | * Frees memory allocated for connection tables |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 610 | */ |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 611 | void nss_ipv6_free_conn_tables(void) |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 612 | { |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 613 | if (nss_ipv6_ct_info.ce_mem) { |
| 614 | free_pages(nss_ipv6_ct_info.ce_mem, get_order(nss_ipv6_ct_info.ce_table_size)); |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 615 | } |
| 616 | |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 617 | if (nss_ipv6_ct_info.cme_mem) { |
| 618 | free_pages(nss_ipv6_ct_info.cme_mem, get_order(nss_ipv6_ct_info.cme_table_size)); |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 619 | } |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 620 | |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 621 | memset(&nss_ipv6_ct_info, 0, sizeof(struct nss_ipv6_conn_table_info)); |
| 622 | return; |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 623 | } |
| 624 | |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 625 | /* |
| 626 | * nss_ipv6_accel_mode_cfg_callback() |
| 627 | * call back function for the ipv6 acceleration mode configurate handler |
| 628 | */ |
| 629 | static void nss_ipv6_accel_mode_cfg_callback(void *app_data, struct nss_ipv6_msg *nim) |
| 630 | { |
| 631 | if (nim->cm.response != NSS_CMN_RESPONSE_ACK) { |
| 632 | nss_warning("IPv6 acceleration mode configuration failed with error: %d\n", nim->cm.error); |
| 633 | i6_accel_mode_cfgp.response = NSS_FAILURE; |
| 634 | complete(&i6_accel_mode_cfgp.complete); |
| 635 | return; |
| 636 | } |
| 637 | |
| 638 | nss_info("IPv6 acceleration mode configuration success\n"); |
| 639 | i6_accel_mode_cfgp.response = NSS_SUCCESS; |
| 640 | complete(&i6_accel_mode_cfgp.complete); |
| 641 | } |
| 642 | |
| 643 | /* |
| 644 | * nss_ipv6_accel_mode_cfg_handler() |
| 645 | * Configure acceleration mode for IPv6 |
| 646 | */ |
| 647 | static int nss_ipv6_accel_mode_cfg_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos) |
| 648 | { |
| 649 | struct nss_top_instance *nss_top = &nss_top_main; |
| 650 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[0]; |
| 651 | struct nss_ipv6_msg nim; |
| 652 | struct nss_ipv6_accel_mode_cfg_msg *nipcm; |
| 653 | nss_tx_status_t nss_tx_status; |
| 654 | int ret = NSS_FAILURE; |
| 655 | |
| 656 | /* |
| 657 | * Acquiring semaphore |
| 658 | */ |
| 659 | down(&i6_accel_mode_cfgp.sem); |
| 660 | |
| 661 | /* |
| 662 | * Take snap shot of current value |
| 663 | */ |
| 664 | i6_accel_mode_cfgp.current_value = nss_ipv6_accel_mode_cfg; |
| 665 | |
| 666 | /* |
| 667 | * Write the variable with user input |
| 668 | */ |
| 669 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 670 | if (ret || (!write)) { |
| 671 | up(&i6_accel_mode_cfgp.sem); |
| 672 | return ret; |
| 673 | } |
| 674 | |
| 675 | memset(&nim, 0, sizeof(struct nss_ipv6_msg)); |
| 676 | nss_ipv6_msg_init(&nim, NSS_IPV6_RX_INTERFACE, NSS_IPV6_TX_ACCEL_MODE_CFG_MSG, |
| 677 | sizeof(struct nss_ipv6_accel_mode_cfg_msg), nss_ipv6_accel_mode_cfg_callback, NULL); |
| 678 | |
| 679 | nipcm = &nim.msg.accel_mode_cfg; |
| 680 | nipcm->mode = htonl(nss_ipv6_accel_mode_cfg); |
| 681 | nss_tx_status = nss_ipv6_tx(nss_ctx, &nim); |
| 682 | |
| 683 | if (nss_tx_status != NSS_TX_SUCCESS) { |
| 684 | nss_warning("%p: Send acceleration mode message failed\n", nss_ctx); |
| 685 | goto fail; |
| 686 | } |
| 687 | |
| 688 | /* |
| 689 | * Blocking call, wait till we get ACK for this msg. |
| 690 | */ |
| 691 | ret = wait_for_completion_timeout(&i6_accel_mode_cfgp.complete, msecs_to_jiffies(NSS_IPV6_TX_MSG_TIMEOUT)); |
| 692 | if (ret == 0) { |
| 693 | nss_warning("%p: Waiting for ack timed out\n", nss_ctx); |
| 694 | goto fail; |
| 695 | } |
| 696 | |
| 697 | if (NSS_FAILURE == i6_accel_mode_cfgp.response) { |
| 698 | nss_warning("%p: accel mode configure failed\n", nss_ctx); |
| 699 | goto fail; |
| 700 | } |
| 701 | |
| 702 | up(&i6_accel_mode_cfgp.sem); |
| 703 | return 0; |
| 704 | |
| 705 | fail: |
| 706 | nss_ipv6_accel_mode_cfg = i6_accel_mode_cfgp.current_value; |
| 707 | up(&i6_accel_mode_cfgp.sem); |
| 708 | return -EIO; |
| 709 | } |
| 710 | |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 711 | static struct ctl_table nss_ipv6_table[] = { |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 712 | { |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 713 | .procname = "ipv6_accel_mode", |
| 714 | .data = &nss_ipv6_accel_mode_cfg, |
| 715 | .maxlen = sizeof(int), |
| 716 | .mode = 0644, |
| 717 | .proc_handler = &nss_ipv6_accel_mode_cfg_handler, |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 718 | }, |
| 719 | { } |
| 720 | }; |
| 721 | |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 722 | static struct ctl_table nss_ipv6_dir[] = { |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 723 | { |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 724 | .procname = "ipv6cfg", |
| 725 | .mode = 0555, |
| 726 | .child = nss_ipv6_table, |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 727 | }, |
| 728 | { } |
| 729 | }; |
| 730 | |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 731 | static struct ctl_table nss_ipv6_root_dir[] = { |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 732 | { |
| 733 | .procname = "nss", |
| 734 | .mode = 0555, |
| 735 | .child = nss_ipv6_dir, |
| 736 | }, |
| 737 | { } |
| 738 | }; |
| 739 | |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 740 | static struct ctl_table nss_ipv6_root[] = { |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 741 | { |
| 742 | .procname = "dev", |
| 743 | .mode = 0555, |
| 744 | .child = nss_ipv6_root_dir, |
| 745 | }, |
| 746 | { } |
| 747 | }; |
| 748 | |
| 749 | static struct ctl_table_header *nss_ipv6_header; |
| 750 | |
| 751 | /* |
| 752 | * nss_ipv6_register_sysctl() |
Kiran Kumar C.S.K | fadf92d | 2015-06-26 12:48:33 +0530 | [diff] [blame] | 753 | * Register sysctl specific to ipv6 |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 754 | */ |
| 755 | void nss_ipv6_register_sysctl(void) |
| 756 | { |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 757 | sema_init(&i6_accel_mode_cfgp.sem, 1); |
| 758 | init_completion(&i6_accel_mode_cfgp.complete); |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 759 | |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 760 | /* |
| 761 | * Register sysctl table. |
| 762 | */ |
| 763 | nss_ipv6_header = register_sysctl_table(nss_ipv6_root); |
| 764 | } |
| 765 | |
| 766 | /* |
| 767 | * nss_ipv6_unregister_sysctl() |
Kiran Kumar C.S.K | fadf92d | 2015-06-26 12:48:33 +0530 | [diff] [blame] | 768 | * Unregister sysctl specific to ipv6 |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 769 | */ |
| 770 | void nss_ipv6_unregister_sysctl(void) |
| 771 | { |
| 772 | /* |
| 773 | * Unregister sysctl table. |
| 774 | */ |
| 775 | if (nss_ipv6_header) { |
| 776 | unregister_sysctl_table(nss_ipv6_header); |
| 777 | } |
| 778 | } |
| 779 | |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 780 | /* |
| 781 | * nss_ipv6_msg_init() |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 782 | * Initialize IPv6 message. |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 783 | */ |
| 784 | void nss_ipv6_msg_init(struct nss_ipv6_msg *nim, uint16_t if_num, uint32_t type, uint32_t len, |
Sundarajan Srinivasan | 30a53d4 | 2015-01-30 10:52:08 -0800 | [diff] [blame] | 785 | nss_ipv6_msg_callback_t cb, void *app_data) |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 786 | { |
| 787 | nss_cmn_msg_init(&nim->cm, if_num, type, len, (void *)cb, app_data); |
| 788 | } |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 789 | EXPORT_SYMBOL(nss_ipv6_msg_init); |