Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 3 | * Copyright (c) 2014 - 2015, 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 | |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 23 | int nss_ipv6_conn_cfg __read_mostly = NSS_DEFAULT_NUM_CONN; |
| 24 | static struct nss_conn_cfg_pvt i6cfgp; |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 25 | |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 26 | /* |
Gareth Williams | 958aa82 | 2015-02-04 19:36:39 +0000 | [diff] [blame] | 27 | * nss_ipv6_max_conn_count() |
| 28 | * Return the maximum number of IPv6 connections that the NSS acceleration engine supports. |
| 29 | */ |
| 30 | int nss_ipv6_max_conn_count(void) |
| 31 | { |
| 32 | return nss_ipv6_conn_cfg; |
| 33 | } |
| 34 | EXPORT_SYMBOL(nss_ipv6_max_conn_count); |
| 35 | |
| 36 | /* |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 37 | * nss_ipv6_driver_conn_sync_update() |
| 38 | * Update driver specific information from the messsage. |
| 39 | */ |
| 40 | static void nss_ipv6_driver_conn_sync_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_conn_sync *nics) |
| 41 | { |
| 42 | struct nss_top_instance *nss_top = nss_ctx->nss_top; |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 43 | |
| 44 | /* |
| 45 | * Update statistics maintained by NSS driver |
| 46 | */ |
| 47 | spin_lock_bh(&nss_top->stats_lock); |
| 48 | nss_top->stats_ipv6[NSS_STATS_IPV6_ACCELERATED_RX_PKTS] += nics->flow_rx_packet_count + nics->return_rx_packet_count; |
| 49 | nss_top->stats_ipv6[NSS_STATS_IPV6_ACCELERATED_RX_BYTES] += nics->flow_rx_byte_count + nics->return_rx_byte_count; |
| 50 | nss_top->stats_ipv6[NSS_STATS_IPV6_ACCELERATED_TX_PKTS] += nics->flow_tx_packet_count + nics->return_tx_packet_count; |
| 51 | 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] | 52 | spin_unlock_bh(&nss_top->stats_lock); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | /* |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 56 | * nss_ipv6_driver_conn_sync_many_update() |
| 57 | * Update driver specific information from the conn_sync_many messsage. |
| 58 | */ |
| 59 | static void nss_ipv6_driver_conn_sync_many_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_conn_sync_many_msg *nicsm) |
| 60 | { |
| 61 | uint32_t i; |
| 62 | |
| 63 | /* |
| 64 | * Sanity check for the stats count |
| 65 | */ |
| 66 | if (nicsm->count * sizeof(struct nss_ipv6_conn_sync) >= nicsm->size) { |
| 67 | nss_warning("%p: stats sync count %u exceeds the size of this msg %u", nss_ctx, nicsm->count, nicsm->size); |
| 68 | return; |
| 69 | } |
| 70 | |
| 71 | for (i = 0; i < nicsm->count; i++) { |
| 72 | nss_ipv6_driver_conn_sync_update(nss_ctx, &nicsm->conn_sync[i]); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | /* |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 77 | * nss_ipv6_driver_node_sync_update) |
| 78 | * Update driver specific information from the messsage. |
| 79 | */ |
| 80 | static void nss_ipv6_driver_node_sync_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_node_sync *nins) |
| 81 | { |
| 82 | struct nss_top_instance *nss_top = nss_ctx->nss_top; |
| 83 | uint32_t i; |
| 84 | |
| 85 | /* |
| 86 | * Update statistics maintained by NSS driver |
| 87 | */ |
| 88 | spin_lock_bh(&nss_top->stats_lock); |
| 89 | nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_RX_PKTS] += nins->node_stats.rx_packets; |
| 90 | nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_RX_BYTES] += nins->node_stats.rx_bytes; |
| 91 | nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_RX_DROPPED] += nins->node_stats.rx_dropped; |
| 92 | nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_TX_PKTS] += nins->node_stats.tx_packets; |
| 93 | nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_TX_BYTES] += nins->node_stats.tx_bytes; |
| 94 | |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 95 | nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_CREATE_REQUESTS] += nins->ipv6_connection_create_requests; |
| 96 | nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_CREATE_COLLISIONS] += nins->ipv6_connection_create_collisions; |
| 97 | nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_CREATE_INVALID_INTERFACE] += nins->ipv6_connection_create_invalid_interface; |
| 98 | nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_DESTROY_REQUESTS] += nins->ipv6_connection_destroy_requests; |
| 99 | nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_DESTROY_MISSES] += nins->ipv6_connection_destroy_misses; |
| 100 | nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_HASH_HITS] += nins->ipv6_connection_hash_hits; |
| 101 | nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_HASH_REORDERS] += nins->ipv6_connection_hash_reorders; |
| 102 | nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_FLUSHES] += nins->ipv6_connection_flushes; |
| 103 | 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] | 104 | nss_top->stats_ipv6[NSS_STATS_IPV6_FRAGMENTATIONS] += nins->ipv6_fragmentations; |
| 105 | nss_top->stats_ipv6[NSS_STATS_IPV6_FRAG_FAILS] += nins->ipv6_frag_fails; |
Kiran Kumar C.S.K | fadf92d | 2015-06-26 12:48:33 +0530 | [diff] [blame] | 106 | nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_CREATE_REQUESTS] += nins->ipv6_mc_connection_create_requests; |
| 107 | nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_UPDATE_REQUESTS] += nins->ipv6_mc_connection_update_requests; |
| 108 | nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_CREATE_INVALID_INTERFACE] += nins->ipv6_mc_connection_create_invalid_interface; |
| 109 | nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_DESTROY_REQUESTS] += nins->ipv6_mc_connection_destroy_requests; |
| 110 | nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_DESTROY_MISSES] += nins->ipv6_mc_connection_destroy_misses; |
| 111 | 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] | 112 | |
| 113 | for (i = 0; i < NSS_EXCEPTION_EVENT_IPV6_MAX; i++) { |
| 114 | nss_top->stats_if_exception_ipv6[i] += nins->exception_events[i]; |
| 115 | } |
| 116 | spin_unlock_bh(&nss_top->stats_lock); |
| 117 | } |
| 118 | |
| 119 | /* |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 120 | * nss_ipv6_rx_msg_handler() |
| 121 | * Handle NSS -> HLOS messages for IPv6 bridge/route |
| 122 | */ |
| 123 | static void nss_ipv6_rx_msg_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data) |
| 124 | { |
| 125 | struct nss_ipv6_msg *nim = (struct nss_ipv6_msg *)ncm; |
| 126 | nss_ipv6_msg_callback_t cb; |
| 127 | |
| 128 | BUG_ON(ncm->interface != NSS_IPV6_RX_INTERFACE); |
| 129 | |
| 130 | /* |
| 131 | * Is this a valid request/response packet? |
| 132 | */ |
Murat Sezgin | 5c8c736 | 2014-09-02 17:58:21 -0700 | [diff] [blame] | 133 | if (ncm->type >= NSS_IPV6_MAX_MSG_TYPES) { |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 134 | nss_warning("%p: received invalid message %d for IPv6 interface", nss_ctx, nim->cm.type); |
| 135 | return; |
| 136 | } |
| 137 | |
| 138 | if (ncm->len > sizeof(struct nss_ipv6_msg)) { |
| 139 | nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface); |
| 140 | return; |
| 141 | } |
| 142 | |
| 143 | /* |
| 144 | * Log failures |
| 145 | */ |
| 146 | nss_core_log_msg_failures(nss_ctx, ncm); |
| 147 | |
| 148 | /* |
| 149 | * Handle deprecated messages. Eventually these messages should be removed. |
| 150 | */ |
| 151 | switch (nim->cm.type) { |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 152 | case NSS_IPV6_RX_NODE_STATS_SYNC_MSG: |
| 153 | /* |
| 154 | * Update driver statistics on node sync. |
| 155 | */ |
| 156 | nss_ipv6_driver_node_sync_update(nss_ctx, &nim->msg.node_stats); |
| 157 | break; |
| 158 | |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 159 | case NSS_IPV6_RX_CONN_STATS_SYNC_MSG: |
| 160 | /* |
| 161 | * Update driver statistics on connection sync. |
| 162 | */ |
| 163 | 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] | 164 | break; |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 165 | |
| 166 | case NSS_IPV6_TX_CONN_STATS_SYNC_MANY_MSG: |
| 167 | /* |
| 168 | * Update driver statistics on connection sync many. |
| 169 | */ |
| 170 | nss_ipv6_driver_conn_sync_many_update(nss_ctx, &nim->msg.conn_stats_many); |
| 171 | break; |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 172 | } |
Abhishek Rastogi | 55f3945 | 2014-05-08 19:23:29 +0530 | [diff] [blame] | 173 | |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 174 | /* |
| 175 | * Update the callback and app_data for NOTIFY messages, IPv6 sends all notify messages |
| 176 | * to the same callback/app_data. |
| 177 | */ |
| 178 | if (nim->cm.response == NSS_CMM_RESPONSE_NOTIFY) { |
| 179 | ncm->cb = (uint32_t)nss_ctx->nss_top->ipv6_callback; |
| 180 | ncm->app_data = (uint32_t)nss_ctx->nss_top->ipv6_ctx; |
| 181 | } |
| 182 | |
| 183 | /* |
| 184 | * Do we have a callback? |
| 185 | */ |
| 186 | if (!ncm->cb) { |
| 187 | return; |
| 188 | } |
| 189 | |
| 190 | /* |
| 191 | * Callback |
| 192 | */ |
| 193 | cb = (nss_ipv6_msg_callback_t)ncm->cb; |
| 194 | cb((void *)ncm->app_data, nim); |
| 195 | } |
| 196 | |
| 197 | /* |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 198 | * nss_ipv6_tx_with_size() |
| 199 | * Transmit an ipv6 message to the FW with a specified size. |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 200 | */ |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 201 | 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] | 202 | { |
| 203 | struct nss_ipv6_msg *nim2; |
| 204 | struct nss_cmn_msg *ncm = &nim->cm; |
| 205 | struct sk_buff *nbuf; |
| 206 | int32_t status; |
| 207 | |
| 208 | NSS_VERIFY_CTX_MAGIC(nss_ctx); |
| 209 | if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) { |
| 210 | nss_warning("%p: ipv6 msg dropped as core not ready", nss_ctx); |
| 211 | return NSS_TX_FAILURE_NOT_READY; |
| 212 | } |
| 213 | |
| 214 | /* |
| 215 | * Sanity check the message |
| 216 | */ |
| 217 | if (ncm->interface != NSS_IPV6_RX_INTERFACE) { |
| 218 | nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface); |
| 219 | return NSS_TX_FAILURE; |
| 220 | } |
| 221 | |
Murat Sezgin | 5c8c736 | 2014-09-02 17:58:21 -0700 | [diff] [blame] | 222 | if (ncm->type >= NSS_IPV6_MAX_MSG_TYPES) { |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 223 | nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type); |
| 224 | return NSS_TX_FAILURE; |
| 225 | } |
| 226 | |
| 227 | if (ncm->len > sizeof(struct nss_ipv6_msg)) { |
| 228 | nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface); |
| 229 | return NSS_TX_FAILURE; |
| 230 | } |
| 231 | |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 232 | if(size > PAGE_SIZE) { |
| 233 | nss_warning("%p: tx request size too large: %u", nss_ctx, size); |
| 234 | return NSS_TX_FAILURE; |
| 235 | } |
| 236 | |
| 237 | nbuf = dev_alloc_skb(size); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 238 | if (unlikely(!nbuf)) { |
Sundarajan Srinivasan | 62fee7e | 2015-01-22 11:13:10 -0800 | [diff] [blame] | 239 | 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] | 240 | nss_warning("%p: msg dropped as command allocation failed", nss_ctx); |
| 241 | return NSS_TX_FAILURE; |
| 242 | } |
| 243 | |
| 244 | /* |
| 245 | * Copy the message to our skb. |
| 246 | */ |
| 247 | nim2 = (struct nss_ipv6_msg *)skb_put(nbuf, sizeof(struct nss_ipv6_msg)); |
| 248 | memcpy(nim2, nim, sizeof(struct nss_ipv6_msg)); |
| 249 | |
| 250 | status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0); |
| 251 | if (status != NSS_CORE_STATUS_SUCCESS) { |
Pamidipati, Vijay | b6e3884 | 2014-09-16 10:26:05 +0530 | [diff] [blame] | 252 | dev_kfree_skb_any(nbuf); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 253 | nss_warning("%p: Unable to enqueue 'Destroy IPv6' rule\n", nss_ctx); |
| 254 | return NSS_TX_FAILURE; |
| 255 | } |
| 256 | |
| 257 | nss_hal_send_interrupt(nss_ctx->nmap, nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit, |
| 258 | NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE); |
| 259 | |
| 260 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]); |
| 261 | return NSS_TX_SUCCESS; |
| 262 | } |
| 263 | |
| 264 | /* |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 265 | * nss_ipv6_tx() |
| 266 | * Transmit an ipv4 message to the FW. |
| 267 | */ |
| 268 | nss_tx_status_t nss_ipv6_tx(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_msg *nim) |
| 269 | { |
| 270 | return nss_ipv6_tx_with_size(nss_ctx, nim, NSS_NBUF_PAYLOAD_SIZE); |
| 271 | } |
| 272 | |
| 273 | /* |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 274 | ********************************** |
| 275 | Register/Unregister/Miscellaneous APIs |
| 276 | ********************************** |
| 277 | */ |
| 278 | |
| 279 | /* |
| 280 | * nss_ipv6_notify_register() |
| 281 | * Register to received IPv6 events. |
| 282 | * |
| 283 | * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv6 on any core? |
| 284 | */ |
| 285 | struct nss_ctx_instance *nss_ipv6_notify_register(nss_ipv6_msg_callback_t cb, void *app_data) |
| 286 | { |
| 287 | /* |
| 288 | * TODO: We need to have a new array in support of the new API |
| 289 | * TODO: If we use a per-context array, we would move the array into nss_ctx based. |
| 290 | */ |
| 291 | nss_top_main.ipv6_callback = cb; |
| 292 | nss_top_main.ipv6_ctx = app_data; |
| 293 | return &nss_top_main.nss[nss_top_main.ipv6_handler_id]; |
| 294 | } |
| 295 | |
| 296 | /* |
| 297 | * nss_ipv6_notify_unregister() |
| 298 | * Unregister to received IPv6 events. |
| 299 | * |
| 300 | * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv6 on any core? |
| 301 | */ |
| 302 | void nss_ipv6_notify_unregister(void) |
| 303 | { |
| 304 | nss_top_main.ipv6_callback = NULL; |
| 305 | } |
| 306 | |
| 307 | /* |
| 308 | * nss_ipv6_get_mgr() |
| 309 | * |
| 310 | * TODO: This only suppports a single ipv6, do we ever want to support more? |
| 311 | */ |
| 312 | struct nss_ctx_instance *nss_ipv6_get_mgr(void) |
| 313 | { |
| 314 | return (void *)&nss_top_main.nss[nss_top_main.ipv6_handler_id]; |
| 315 | } |
| 316 | |
| 317 | /* |
| 318 | * nss_ipv6_register_handler() |
| 319 | * Register our handler to receive messages for this interface |
| 320 | */ |
| 321 | void nss_ipv6_register_handler() |
| 322 | { |
| 323 | if (nss_core_register_handler(NSS_IPV6_RX_INTERFACE, nss_ipv6_rx_msg_handler, NULL) != NSS_CORE_STATUS_SUCCESS) { |
| 324 | nss_warning("IPv6 handler failed to register"); |
| 325 | } |
| 326 | } |
| 327 | |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 328 | /* |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame^] | 329 | * nss_ipv6_conn_cfg_process() |
| 330 | * Process request to configure number of ipv6 connections |
| 331 | */ |
| 332 | static int nss_ipv6_conn_cfg_process(struct nss_ctx_instance *nss_ctx, int conn, |
| 333 | void (*cfg_cb)(void *app_data, struct nss_ipv6_msg *nim)) |
| 334 | { |
| 335 | struct nss_ipv6_msg nim; |
| 336 | struct nss_ipv6_rule_conn_cfg_msg *nirccm; |
| 337 | nss_tx_status_t nss_tx_status; |
| 338 | uint32_t sum_of_conn; |
| 339 | |
| 340 | /* |
| 341 | * Specifications for input |
| 342 | * 1) The input should be power of 2. |
| 343 | * 2) Input for ipv4 and ipv6 sum togther should not exceed 8k |
| 344 | * 3) Min. value should be at leat 256 connections. This is the |
| 345 | * minimum connections we will support for each of them. |
| 346 | */ |
| 347 | sum_of_conn = nss_ipv4_conn_cfg + conn; |
| 348 | if ((conn & NSS_NUM_CONN_QUANTA_MASK) || |
| 349 | (sum_of_conn > NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6) || |
| 350 | (conn < NSS_MIN_NUM_CONN)) { |
| 351 | nss_warning("%p: input supported connections (%d) does not adhere\ |
| 352 | specifications\n1) not power of 2,\n2) is less than \ |
| 353 | min val: %d, OR\n IPv4/6 total exceeds %d\n", |
| 354 | nss_ctx, |
| 355 | conn, |
| 356 | NSS_MIN_NUM_CONN, |
| 357 | NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6); |
| 358 | return -EINVAL; |
| 359 | } |
| 360 | |
| 361 | nss_info("%p: IPv6 supported connections: %d\n", nss_ctx, conn); |
| 362 | |
| 363 | memset(&nim, 0, sizeof(struct nss_ipv6_msg)); |
| 364 | nss_ipv6_msg_init(&nim, NSS_IPV6_RX_INTERFACE, NSS_IPV6_TX_CONN_CFG_RULE_MSG, |
| 365 | sizeof(struct nss_ipv6_rule_conn_cfg_msg), cfg_cb, NULL); |
| 366 | |
| 367 | nirccm = &nim.msg.rule_conn_cfg; |
| 368 | nirccm->num_conn = htonl(conn); |
| 369 | nss_tx_status = nss_ipv6_tx(nss_ctx, &nim); |
| 370 | |
| 371 | if (nss_tx_status != NSS_TX_SUCCESS) { |
| 372 | nss_warning("%p: nss_tx error setting IPv6 Connections: %d\n", |
| 373 | nss_ctx, |
| 374 | conn); |
| 375 | return -EIO; |
| 376 | } |
| 377 | |
| 378 | return 0; |
| 379 | } |
| 380 | |
| 381 | /* |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 382 | * nss_ipv6_conn_cfg_callback() |
| 383 | * call back function for the ipv6 connection configuration handler |
| 384 | */ |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 385 | static void nss_ipv6_conn_cfg_callback(void *app_data, struct nss_ipv6_msg *nim) |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 386 | { |
| 387 | if (nim->cm.response != NSS_CMN_RESPONSE_ACK) { |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 388 | /* |
Kiran Kumar C.S.K | fadf92d | 2015-06-26 12:48:33 +0530 | [diff] [blame] | 389 | * Error, hence we are not updating the nss_ipv6_conn_cfg |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 390 | * Restore the current_value to its previous state |
| 391 | */ |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 392 | i6cfgp.response = NSS_FAILURE; |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 393 | complete(&i6cfgp.complete); |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 394 | return; |
| 395 | } |
| 396 | |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 397 | /* |
Kiran Kumar C.S.K | fadf92d | 2015-06-26 12:48:33 +0530 | [diff] [blame] | 398 | * Sucess at NSS FW, hence updating nss_ipv6_conn_cfg, with the valid value |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 399 | * saved at the sysctl handler. |
| 400 | */ |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 401 | nss_info("IPv6 connection configuration success: %d\n", nim->cm.error); |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 402 | i6cfgp.response = NSS_SUCCESS; |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 403 | complete(&i6cfgp.complete); |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | |
| 407 | /* |
| 408 | * nss_ipv6_conn_cfg_handler() |
| 409 | * Sets the number of connections for IPv6 |
| 410 | */ |
| 411 | static int nss_ipv6_conn_cfg_handler(ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos) |
| 412 | { |
| 413 | struct nss_top_instance *nss_top = &nss_top_main; |
| 414 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[0]; |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 415 | int ret = NSS_FAILURE; |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 416 | |
| 417 | /* |
| 418 | * Acquiring semaphore |
| 419 | */ |
| 420 | down(&i6cfgp.sem); |
| 421 | |
| 422 | /* |
| 423 | * Take a snapshot of the current value |
| 424 | */ |
| 425 | i6cfgp.current_value = nss_ipv6_conn_cfg; |
| 426 | |
| 427 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 428 | if (ret || (!write)) { |
| 429 | up(&i6cfgp.sem); |
| 430 | return ret; |
| 431 | } |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 432 | |
| 433 | /* |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame^] | 434 | * Process request to change number of IPv6 connections |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 435 | */ |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame^] | 436 | ret = nss_ipv6_conn_cfg_process(nss_ctx, nss_ipv6_conn_cfg, nss_ipv6_conn_cfg_callback); |
| 437 | if (ret != 0) { |
Stephen Wang | 0676102 | 2015-03-03 16:38:42 -0800 | [diff] [blame] | 438 | goto failure; |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 439 | } |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 440 | |
| 441 | /* |
| 442 | * Blocking call, wait till we get ACK for this msg. |
| 443 | */ |
| 444 | ret = wait_for_completion_timeout(&i6cfgp.complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT)); |
| 445 | if (ret == 0) { |
| 446 | nss_warning("%p: Waiting for ack timed out\n", nss_ctx); |
Stephen Wang | 0676102 | 2015-03-03 16:38:42 -0800 | [diff] [blame] | 447 | goto failure; |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | /* |
| 451 | * ACK/NACK received from NSS FW |
Kiran Kumar C.S.K | fadf92d | 2015-06-26 12:48:33 +0530 | [diff] [blame] | 452 | * If ACK: Callback function will update nss_ipv6_conn_cfg with |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 453 | * i6cfgp.num_conn_valid, which holds the user input |
| 454 | */ |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 455 | if (NSS_FAILURE == i6cfgp.response) { |
Stephen Wang | 0676102 | 2015-03-03 16:38:42 -0800 | [diff] [blame] | 456 | goto failure; |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | up(&i6cfgp.sem); |
Thomas Wu | 651b390 | 2015-05-12 11:21:09 -0700 | [diff] [blame] | 460 | return 0; |
Stephen Wang | 0676102 | 2015-03-03 16:38:42 -0800 | [diff] [blame] | 461 | |
| 462 | failure: |
| 463 | /* |
| 464 | * Restore the current_value to its previous state |
| 465 | */ |
| 466 | nss_ipv6_conn_cfg = i6cfgp.current_value; |
| 467 | up(&i6cfgp.sem); |
Thomas Wu | 651b390 | 2015-05-12 11:21:09 -0700 | [diff] [blame] | 468 | return -EINVAL; |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 469 | } |
| 470 | |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame^] | 471 | /* |
| 472 | * nss_ipv6_update_conn_count_cb() |
| 473 | * call back function for the ipv6 connection count update handler |
| 474 | */ |
| 475 | static void nss_ipv6_update_conn_count_cb(void *app_data, struct nss_ipv6_msg *nim) |
| 476 | { |
| 477 | if (nim->cm.response != NSS_CMN_RESPONSE_ACK) { |
| 478 | nss_warning("IPv6 connection count update failed with error: %d\n", nim->cm.error); |
| 479 | return; |
| 480 | } |
| 481 | |
| 482 | nss_warning("IPv6 connection count update success: %d\n", nim->cm.error); |
| 483 | } |
| 484 | |
| 485 | /* |
| 486 | * nss_ipv6_update_conn_count() |
| 487 | * Sets the maximum number of connections for IPv6 |
| 488 | */ |
| 489 | int nss_ipv6_update_conn_count(int ipv6_num_conn) |
| 490 | { |
| 491 | struct nss_top_instance *nss_top = &nss_top_main; |
| 492 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[0]; |
| 493 | int saved_nss_ipv6_conn_cfg = nss_ipv6_conn_cfg; |
| 494 | int ret = 0; |
| 495 | |
| 496 | nss_ipv6_conn_cfg = ipv6_num_conn; |
| 497 | |
| 498 | /* |
| 499 | * Process request to change number of IPv6 connections |
| 500 | */ |
| 501 | ret = nss_ipv6_conn_cfg_process(nss_ctx, nss_ipv6_conn_cfg, nss_ipv6_update_conn_count_cb); |
| 502 | if (ret != 0) { |
| 503 | goto failure; |
| 504 | } |
| 505 | |
| 506 | return 0; |
| 507 | |
| 508 | failure: |
| 509 | nss_ipv6_conn_cfg = saved_nss_ipv6_conn_cfg; |
| 510 | return -EINVAL; |
| 511 | } |
| 512 | |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 513 | static ctl_table nss_ipv6_table[] = { |
| 514 | { |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 515 | .procname = "ipv6_conn", |
| 516 | .data = &nss_ipv6_conn_cfg, |
| 517 | .maxlen = sizeof(int), |
| 518 | .mode = 0644, |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 519 | .proc_handler = &nss_ipv6_conn_cfg_handler, |
| 520 | }, |
| 521 | { } |
| 522 | }; |
| 523 | |
| 524 | static ctl_table nss_ipv6_dir[] = { |
| 525 | { |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 526 | .procname = "ipv6cfg", |
| 527 | .mode = 0555, |
| 528 | .child = nss_ipv6_table, |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 529 | }, |
| 530 | { } |
| 531 | }; |
| 532 | |
| 533 | static ctl_table nss_ipv6_root_dir[] = { |
| 534 | { |
| 535 | .procname = "nss", |
| 536 | .mode = 0555, |
| 537 | .child = nss_ipv6_dir, |
| 538 | }, |
| 539 | { } |
| 540 | }; |
| 541 | |
| 542 | static ctl_table nss_ipv6_root[] = { |
| 543 | { |
| 544 | .procname = "dev", |
| 545 | .mode = 0555, |
| 546 | .child = nss_ipv6_root_dir, |
| 547 | }, |
| 548 | { } |
| 549 | }; |
| 550 | |
| 551 | static struct ctl_table_header *nss_ipv6_header; |
| 552 | |
| 553 | /* |
| 554 | * nss_ipv6_register_sysctl() |
Kiran Kumar C.S.K | fadf92d | 2015-06-26 12:48:33 +0530 | [diff] [blame] | 555 | * Register sysctl specific to ipv6 |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 556 | */ |
| 557 | void nss_ipv6_register_sysctl(void) |
| 558 | { |
| 559 | /* |
| 560 | * Register sysctl table. |
| 561 | */ |
| 562 | nss_ipv6_header = register_sysctl_table(nss_ipv6_root); |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 563 | sema_init(&i6cfgp.sem, 1); |
| 564 | init_completion(&i6cfgp.complete); |
| 565 | i6cfgp.current_value = nss_ipv6_conn_cfg; |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | /* |
| 569 | * nss_ipv6_unregister_sysctl() |
Kiran Kumar C.S.K | fadf92d | 2015-06-26 12:48:33 +0530 | [diff] [blame] | 570 | * Unregister sysctl specific to ipv6 |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 571 | */ |
| 572 | void nss_ipv6_unregister_sysctl(void) |
| 573 | { |
| 574 | /* |
| 575 | * Unregister sysctl table. |
| 576 | */ |
| 577 | if (nss_ipv6_header) { |
| 578 | unregister_sysctl_table(nss_ipv6_header); |
| 579 | } |
| 580 | } |
| 581 | |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 582 | /* |
| 583 | * nss_ipv6_msg_init() |
| 584 | * Initialize IPv6 message. |
| 585 | */ |
| 586 | 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] | 587 | nss_ipv6_msg_callback_t cb, void *app_data) |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 588 | { |
| 589 | nss_cmn_msg_init(&nim->cm, if_num, type, len, (void *)cb, app_data); |
| 590 | } |
| 591 | |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 592 | EXPORT_SYMBOL(nss_ipv6_tx); |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 593 | EXPORT_SYMBOL(nss_ipv6_tx_with_size); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 594 | EXPORT_SYMBOL(nss_ipv6_notify_register); |
| 595 | EXPORT_SYMBOL(nss_ipv6_notify_unregister); |
| 596 | EXPORT_SYMBOL(nss_ipv6_get_mgr); |
| 597 | EXPORT_SYMBOL(nss_ipv6_register_handler); |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 598 | EXPORT_SYMBOL(nss_ipv6_register_sysctl); |
| 599 | EXPORT_SYMBOL(nss_ipv6_unregister_sysctl); |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 600 | EXPORT_SYMBOL(nss_ipv6_msg_init); |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame^] | 601 | EXPORT_SYMBOL(nss_ipv6_update_conn_count); |