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