Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved. |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -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 | /* |
Murat Sezgin | 5c8c736 | 2014-09-02 17:58:21 -0700 | [diff] [blame] | 18 | * nss_ipv4.c |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 19 | * NSS IPv4 APIs |
| 20 | */ |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 21 | #include <linux/sysctl.h> |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 22 | #include "nss_tx_rx_common.h" |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 23 | |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 24 | int nss_ipv4_conn_cfg __read_mostly = NSS_DEFAULT_NUM_CONN; |
| 25 | static struct nss_conn_cfg_pvt i4cfgp; |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 26 | |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 27 | /* |
Gareth Williams | 958aa82 | 2015-02-04 19:36:39 +0000 | [diff] [blame] | 28 | * nss_ipv4_max_conn_count() |
| 29 | * Return the maximum number of IPv4 connections that the NSS acceleration engine supports. |
| 30 | */ |
| 31 | int nss_ipv4_max_conn_count(void) |
| 32 | { |
| 33 | return nss_ipv4_conn_cfg; |
| 34 | } |
| 35 | EXPORT_SYMBOL(nss_ipv4_max_conn_count); |
| 36 | |
| 37 | /* |
Sol Kavy | 57d24b4 | 2014-04-05 13:45:36 -0700 | [diff] [blame] | 38 | * nss_ipv4_driver_conn_sync_update() |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 39 | * Update driver specific information from the messsage. |
| 40 | */ |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 41 | static void nss_ipv4_driver_conn_sync_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv4_conn_sync *nirs) |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 42 | { |
Sol Kavy | 57d24b4 | 2014-04-05 13:45:36 -0700 | [diff] [blame] | 43 | struct nss_top_instance *nss_top = nss_ctx->nss_top; |
Sol Kavy | 57d24b4 | 2014-04-05 13:45:36 -0700 | [diff] [blame] | 44 | |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 45 | /* |
| 46 | * Update statistics maintained by NSS driver |
| 47 | */ |
| 48 | spin_lock_bh(&nss_top->stats_lock); |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 49 | nss_top->stats_ipv4[NSS_STATS_IPV4_ACCELERATED_RX_PKTS] += nirs->flow_rx_packet_count + nirs->return_rx_packet_count; |
| 50 | nss_top->stats_ipv4[NSS_STATS_IPV4_ACCELERATED_RX_BYTES] += nirs->flow_rx_byte_count + nirs->return_rx_byte_count; |
| 51 | nss_top->stats_ipv4[NSS_STATS_IPV4_ACCELERATED_TX_PKTS] += nirs->flow_tx_packet_count + nirs->return_tx_packet_count; |
| 52 | nss_top->stats_ipv4[NSS_STATS_IPV4_ACCELERATED_TX_BYTES] += nirs->flow_tx_byte_count + nirs->return_tx_byte_count; |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 53 | spin_unlock_bh(&nss_top->stats_lock); |
| 54 | } |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 55 | |
| 56 | /* |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 57 | * nss_ipv4_driver_node_sync_update) |
| 58 | * Update driver specific information from the messsage. |
| 59 | */ |
| 60 | static void nss_ipv4_driver_node_sync_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv4_node_sync *nins) |
| 61 | { |
| 62 | struct nss_top_instance *nss_top = nss_ctx->nss_top; |
| 63 | uint32_t i; |
| 64 | |
| 65 | /* |
| 66 | * Update statistics maintained by NSS driver |
| 67 | */ |
| 68 | spin_lock_bh(&nss_top->stats_lock); |
| 69 | nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_RX_PKTS] += nins->node_stats.rx_packets; |
| 70 | nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_RX_BYTES] += nins->node_stats.rx_bytes; |
| 71 | nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_RX_DROPPED] += nins->node_stats.rx_dropped; |
| 72 | nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_TX_PKTS] += nins->node_stats.tx_packets; |
| 73 | nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_TX_BYTES] += nins->node_stats.tx_bytes; |
| 74 | |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 75 | nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_CREATE_REQUESTS] += nins->ipv4_connection_create_requests; |
| 76 | nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_CREATE_COLLISIONS] += nins->ipv4_connection_create_collisions; |
| 77 | nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_CREATE_INVALID_INTERFACE] += nins->ipv4_connection_create_invalid_interface; |
| 78 | nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_DESTROY_REQUESTS] += nins->ipv4_connection_destroy_requests; |
| 79 | nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_DESTROY_MISSES] += nins->ipv4_connection_destroy_misses; |
| 80 | nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_HASH_HITS] += nins->ipv4_connection_hash_hits; |
| 81 | nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_HASH_REORDERS] += nins->ipv4_connection_hash_reorders; |
| 82 | nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_FLUSHES] += nins->ipv4_connection_flushes; |
| 83 | nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_EVICTIONS] += nins->ipv4_connection_evictions; |
Selin Dag | 60ea2b2 | 2014-11-05 09:36:22 -0800 | [diff] [blame] | 84 | nss_top->stats_ipv4[NSS_STATS_IPV4_FRAGMENTATIONS] += nins->ipv4_fragmentations; |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 85 | |
| 86 | for (i = 0; i < NSS_EXCEPTION_EVENT_IPV4_MAX; i++) { |
| 87 | nss_top->stats_if_exception_ipv4[i] += nins->exception_events[i]; |
| 88 | } |
| 89 | spin_unlock_bh(&nss_top->stats_lock); |
| 90 | } |
| 91 | |
| 92 | /* |
Sol Kavy | 2783c07 | 2014-04-05 12:53:13 -0700 | [diff] [blame] | 93 | * nss_ipv4_rx_msg_handler() |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 94 | * Handle NSS -> HLOS messages for IPv4 bridge/route |
| 95 | */ |
Sol Kavy | 2783c07 | 2014-04-05 12:53:13 -0700 | [diff] [blame] | 96 | static void nss_ipv4_rx_msg_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data) |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 97 | { |
| 98 | struct nss_ipv4_msg *nim = (struct nss_ipv4_msg *)ncm; |
Sol Kavy | 57d24b4 | 2014-04-05 13:45:36 -0700 | [diff] [blame] | 99 | nss_ipv4_msg_callback_t cb; |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 100 | |
| 101 | BUG_ON(ncm->interface != NSS_IPV4_RX_INTERFACE); |
| 102 | |
| 103 | /* |
| 104 | * Sanity check the message type |
| 105 | */ |
Murat Sezgin | 5c8c736 | 2014-09-02 17:58:21 -0700 | [diff] [blame] | 106 | if (ncm->type >= NSS_IPV4_MAX_MSG_TYPES) { |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 107 | nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type); |
| 108 | return; |
| 109 | } |
| 110 | |
| 111 | if (ncm->len > sizeof(struct nss_ipv4_msg)) { |
| 112 | nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface); |
| 113 | return; |
| 114 | } |
| 115 | |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 116 | /* |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 117 | * Log failures |
| 118 | */ |
| 119 | nss_core_log_msg_failures(nss_ctx, ncm); |
| 120 | |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 121 | switch (nim->cm.type) { |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 122 | case NSS_IPV4_RX_NODE_STATS_SYNC_MSG: |
| 123 | /* |
| 124 | * Update driver statistics on node sync. |
| 125 | */ |
| 126 | nss_ipv4_driver_node_sync_update(nss_ctx, &nim->msg.node_stats); |
| 127 | break; |
| 128 | |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 129 | case NSS_IPV4_RX_CONN_STATS_SYNC_MSG: |
Sol Kavy | 57d24b4 | 2014-04-05 13:45:36 -0700 | [diff] [blame] | 130 | /* |
| 131 | * Update driver statistics on connection sync. |
| 132 | */ |
| 133 | nss_ipv4_driver_conn_sync_update(nss_ctx, &nim->msg.conn_stats); |
Sakthi Vignesh Radhakrishnan | 515f8c2 | 2014-06-21 15:04:19 -0700 | [diff] [blame] | 134 | break; |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | /* |
Sol Kavy | 57d24b4 | 2014-04-05 13:45:36 -0700 | [diff] [blame] | 138 | * Update the callback and app_data for NOTIFY messages, IPv4 sends all notify messages |
| 139 | * to the same callback/app_data. |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 140 | */ |
Sol Kavy | 57d24b4 | 2014-04-05 13:45:36 -0700 | [diff] [blame] | 141 | if (nim->cm.response == NSS_CMM_RESPONSE_NOTIFY) { |
| 142 | ncm->cb = (uint32_t)nss_ctx->nss_top->ipv4_callback; |
| 143 | ncm->app_data = (uint32_t)nss_ctx->nss_top->ipv4_ctx; |
| 144 | } |
Sol Kavy | 2783c07 | 2014-04-05 12:53:13 -0700 | [diff] [blame] | 145 | |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 146 | /* |
| 147 | * Do we have a callback? |
| 148 | */ |
| 149 | if (!ncm->cb) { |
| 150 | return; |
| 151 | } |
| 152 | |
| 153 | /* |
| 154 | * Callback |
| 155 | */ |
Sol Kavy | 57d24b4 | 2014-04-05 13:45:36 -0700 | [diff] [blame] | 156 | cb = (nss_ipv4_msg_callback_t)ncm->cb; |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 157 | cb((void *)ncm->app_data, nim); |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | /* |
| 161 | * nss_ipv4_tx() |
| 162 | * Transmit an ipv4 message to the FW. |
| 163 | */ |
| 164 | nss_tx_status_t nss_ipv4_tx(struct nss_ctx_instance *nss_ctx, struct nss_ipv4_msg *nim) |
| 165 | { |
| 166 | struct nss_ipv4_msg *nim2; |
| 167 | struct nss_cmn_msg *ncm = &nim->cm; |
| 168 | struct sk_buff *nbuf; |
| 169 | int32_t status; |
| 170 | |
| 171 | NSS_VERIFY_CTX_MAGIC(nss_ctx); |
| 172 | if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) { |
| 173 | nss_warning("%p: ipv4 msg dropped as core not ready", nss_ctx); |
| 174 | return NSS_TX_FAILURE_NOT_READY; |
| 175 | } |
| 176 | |
| 177 | /* |
| 178 | * Sanity check the message |
| 179 | */ |
| 180 | if (ncm->interface != NSS_IPV4_RX_INTERFACE) { |
| 181 | nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface); |
| 182 | return NSS_TX_FAILURE; |
| 183 | } |
| 184 | |
Murat Sezgin | 5c8c736 | 2014-09-02 17:58:21 -0700 | [diff] [blame] | 185 | if (ncm->type >= NSS_IPV4_MAX_MSG_TYPES) { |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 186 | nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type); |
| 187 | return NSS_TX_FAILURE; |
| 188 | } |
| 189 | |
| 190 | if (ncm->len > sizeof(struct nss_ipv4_msg)) { |
| 191 | nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface); |
| 192 | return NSS_TX_FAILURE; |
| 193 | } |
| 194 | |
Pamidipati, Vijay | b6e3884 | 2014-09-16 10:26:05 +0530 | [diff] [blame] | 195 | nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE); |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 196 | if (unlikely(!nbuf)) { |
| 197 | spin_lock_bh(&nss_ctx->nss_top->stats_lock); |
| 198 | nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]++; |
| 199 | spin_unlock_bh(&nss_ctx->nss_top->stats_lock); |
| 200 | nss_warning("%p: msg dropped as command allocation failed", nss_ctx); |
| 201 | return NSS_TX_FAILURE; |
| 202 | } |
| 203 | |
| 204 | /* |
| 205 | * Copy the message to our skb. |
| 206 | */ |
| 207 | nim2 = (struct nss_ipv4_msg *)skb_put(nbuf, sizeof(struct nss_ipv4_msg)); |
| 208 | memcpy(nim2, nim, sizeof(struct nss_ipv4_msg)); |
| 209 | |
| 210 | status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0); |
| 211 | if (status != NSS_CORE_STATUS_SUCCESS) { |
Pamidipati, Vijay | b6e3884 | 2014-09-16 10:26:05 +0530 | [diff] [blame] | 212 | dev_kfree_skb_any(nbuf); |
Sol Kavy | cd1bd5c | 2014-04-04 11:09:44 -0700 | [diff] [blame] | 213 | nss_warning("%p: unable to enqueue IPv4 msg\n", nss_ctx); |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 214 | return NSS_TX_FAILURE; |
| 215 | } |
| 216 | |
| 217 | nss_hal_send_interrupt(nss_ctx->nmap, nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit, |
| 218 | NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE); |
| 219 | |
| 220 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]); |
| 221 | return NSS_TX_SUCCESS; |
| 222 | } |
| 223 | |
| 224 | /* |
| 225 | ********************************** |
| 226 | Register/Unregister/Miscellaneous APIs |
| 227 | ********************************** |
| 228 | */ |
| 229 | |
| 230 | /* |
| 231 | * nss_ipv4_notify_register() |
| 232 | * Register to received IPv4 events. |
| 233 | * |
| 234 | * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv4 on any core? |
| 235 | */ |
| 236 | struct nss_ctx_instance *nss_ipv4_notify_register(nss_ipv4_msg_callback_t cb, void *app_data) |
| 237 | { |
| 238 | /* |
| 239 | * TODO: We need to have a new array in support of the new API |
| 240 | * TODO: If we use a per-context array, we would move the array into nss_ctx based. |
| 241 | */ |
| 242 | nss_top_main.ipv4_callback = cb; |
Abhishek Rastogi | e11f47b | 2014-04-04 18:43:32 +0530 | [diff] [blame] | 243 | nss_top_main.ipv4_ctx = app_data; |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 244 | return &nss_top_main.nss[nss_top_main.ipv4_handler_id]; |
| 245 | } |
| 246 | |
| 247 | /* |
| 248 | * nss_ipv4_notify_unregister() |
| 249 | * Unregister to received IPv4 events. |
| 250 | * |
| 251 | * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv4 on any core? |
| 252 | */ |
| 253 | void nss_ipv4_notify_unregister(void) |
| 254 | { |
| 255 | nss_top_main.ipv4_callback = NULL; |
| 256 | } |
| 257 | |
| 258 | /* |
| 259 | * nss_ipv4_get_mgr() |
| 260 | * |
| 261 | * TODO: This only suppports a single ipv4, do we ever want to support more? |
| 262 | */ |
| 263 | struct nss_ctx_instance *nss_ipv4_get_mgr(void) |
| 264 | { |
| 265 | return (void *)&nss_top_main.nss[nss_top_main.ipv4_handler_id]; |
| 266 | } |
| 267 | |
| 268 | /* |
| 269 | * nss_ipv4_register_handler() |
| 270 | * Register our handler to receive messages for this interface |
| 271 | */ |
Sol Kavy | 2783c07 | 2014-04-05 12:53:13 -0700 | [diff] [blame] | 272 | void nss_ipv4_register_handler(void) |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 273 | { |
Sol Kavy | 2783c07 | 2014-04-05 12:53:13 -0700 | [diff] [blame] | 274 | if (nss_core_register_handler(NSS_IPV4_RX_INTERFACE, nss_ipv4_rx_msg_handler, NULL) != NSS_CORE_STATUS_SUCCESS) { |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 275 | nss_warning("IPv4 handler failed to register"); |
| 276 | } |
| 277 | } |
| 278 | |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 279 | /* |
| 280 | * nss_ipv4_conn_cfg_callback() |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 281 | * call back function for the ipv4 connection configuration handler |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 282 | */ |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 283 | static void nss_ipv4_conn_cfg_callback(void *app_data, struct nss_ipv4_msg *nim) |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 284 | { |
| 285 | |
| 286 | if (nim->cm.response != NSS_CMN_RESPONSE_ACK) { |
| 287 | nss_warning("IPv4 connection configuration failed with error: %d\n", nim->cm.error); |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 288 | /* |
| 289 | * Error, hence we are not updating the nss_ipv4_conn_cfg |
| 290 | * Restore the current_value to its previous state |
| 291 | */ |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 292 | i4cfgp.response = NSS_FAILURE; |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 293 | complete(&i4cfgp.complete); |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 294 | return; |
| 295 | } |
| 296 | |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 297 | /* |
| 298 | * Sucess at NSS FW, hence updating nss_ipv4_conn_cfg, with the valid value |
| 299 | * saved at the sysctl handler. |
| 300 | */ |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 301 | nss_info("IPv4 connection configuration success: %d\n", nim->cm.error); |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 302 | i4cfgp.response = NSS_SUCCESS; |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 303 | complete(&i4cfgp.complete); |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | /* |
| 307 | * nss_ipv4_conn_cfg_handler() |
| 308 | * Sets the number of connections for IPv4 |
| 309 | */ |
| 310 | static int nss_ipv4_conn_cfg_handler(ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos) |
| 311 | { |
| 312 | struct nss_top_instance *nss_top = &nss_top_main; |
| 313 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[0]; |
| 314 | struct nss_ipv4_msg nim; |
| 315 | struct nss_ipv4_rule_conn_cfg_msg *nirccm; |
| 316 | nss_tx_status_t nss_tx_status; |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 317 | int ret = NSS_FAILURE; |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 318 | uint32_t sum_of_conn; |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 319 | |
| 320 | /* |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 321 | * Acquiring semaphore |
| 322 | */ |
| 323 | down(&i4cfgp.sem); |
| 324 | |
| 325 | /* |
| 326 | * Take snap shot of current value |
| 327 | */ |
| 328 | i4cfgp.current_value = nss_ipv4_conn_cfg; |
| 329 | |
| 330 | /* |
| 331 | * Write the variable with user input |
| 332 | */ |
| 333 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 334 | if (ret || (!write)) { |
| 335 | up(&i4cfgp.sem); |
| 336 | return ret; |
| 337 | } |
| 338 | |
| 339 | /* |
| 340 | * The input should be multiple of 1024. |
| 341 | * Input for ipv4 and ipv6 sum together should not exceed 8k |
| 342 | * Min. value should be at least 256 connections. This is the |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 343 | * minimum connections we will support for each of them. |
| 344 | */ |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 345 | sum_of_conn = nss_ipv4_conn_cfg + nss_ipv6_conn_cfg; |
| 346 | if ((nss_ipv4_conn_cfg & NSS_NUM_CONN_QUANTA_MASK) || |
| 347 | (sum_of_conn > NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6) || |
| 348 | (nss_ipv4_conn_cfg < NSS_MIN_NUM_CONN)) { |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 349 | nss_warning("%p: input supported connections (%d) does not adhere\ |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 350 | specifications\n1) not multiple of 1024,\n2) is less than \ |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 351 | min val: %d, OR\n IPv4/6 total exceeds %d\n", |
| 352 | nss_ctx, |
| 353 | nss_ipv4_conn_cfg, |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 354 | NSS_MIN_NUM_CONN, |
| 355 | NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6); |
Stephen Wang | 0676102 | 2015-03-03 16:38:42 -0800 | [diff] [blame] | 356 | goto failure; |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 357 | } |
| 358 | |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 359 | nss_info("%p: IPv4 supported connections: %d\n", nss_ctx, nss_ipv4_conn_cfg); |
| 360 | |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 361 | nss_ipv4_msg_init(&nim, NSS_IPV4_RX_INTERFACE, NSS_IPV4_TX_CONN_CFG_RULE_MSG, |
Stephen Wang | 0676102 | 2015-03-03 16:38:42 -0800 | [diff] [blame] | 362 | sizeof(struct nss_ipv4_rule_conn_cfg_msg), |
| 363 | (nss_ipv4_msg_callback_t *)nss_ipv4_conn_cfg_callback, NULL); |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 364 | |
| 365 | nirccm = &nim.msg.rule_conn_cfg; |
| 366 | nirccm->num_conn = htonl(nss_ipv4_conn_cfg); |
| 367 | nss_tx_status = nss_ipv4_tx(nss_ctx, &nim); |
| 368 | |
| 369 | if (nss_tx_status != NSS_TX_SUCCESS) { |
| 370 | nss_warning("%p: nss_tx error setting IPv4 Connections: %d\n", |
| 371 | nss_ctx, |
| 372 | nss_ipv4_conn_cfg); |
Stephen Wang | 0676102 | 2015-03-03 16:38:42 -0800 | [diff] [blame] | 373 | goto failure; |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 374 | } |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 375 | |
| 376 | /* |
| 377 | * Blocking call, wait till we get ACK for this msg. |
| 378 | */ |
| 379 | ret = wait_for_completion_timeout(&i4cfgp.complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT)); |
| 380 | if (ret == 0) { |
| 381 | nss_warning("%p: Waiting for ack timed out\n", nss_ctx); |
Stephen Wang | 0676102 | 2015-03-03 16:38:42 -0800 | [diff] [blame] | 382 | goto failure; |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | /* |
| 386 | * ACK/NACK received from NSS FW |
| 387 | * If ACK: Callback function will update nss_ipv4_conn_cfg with |
| 388 | * i4cfgp.num_conn_valid, which holds the user input |
| 389 | */ |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 390 | if (NSS_FAILURE == i4cfgp.response) { |
Stephen Wang | 0676102 | 2015-03-03 16:38:42 -0800 | [diff] [blame] | 391 | goto failure; |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | up(&i4cfgp.sem); |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 395 | return NSS_SUCCESS; |
Stephen Wang | 0676102 | 2015-03-03 16:38:42 -0800 | [diff] [blame] | 396 | |
| 397 | failure: |
| 398 | /* |
| 399 | * Restore the current_value to its previous state |
| 400 | */ |
| 401 | nss_ipv4_conn_cfg = i4cfgp.current_value; |
| 402 | up(&i4cfgp.sem); |
| 403 | return NSS_FAILURE; |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | static ctl_table nss_ipv4_table[] = { |
| 407 | { |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 408 | .procname = "ipv4_conn", |
| 409 | .data = &nss_ipv4_conn_cfg, |
| 410 | .maxlen = sizeof(int), |
| 411 | .mode = 0644, |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 412 | .proc_handler = &nss_ipv4_conn_cfg_handler, |
| 413 | }, |
| 414 | { } |
| 415 | }; |
| 416 | |
| 417 | static ctl_table nss_ipv4_dir[] = { |
| 418 | { |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 419 | .procname = "ipv4cfg", |
| 420 | .mode = 0555, |
| 421 | .child = nss_ipv4_table, |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 422 | }, |
| 423 | { } |
| 424 | }; |
| 425 | |
| 426 | |
| 427 | static ctl_table nss_ipv4_root_dir[] = { |
| 428 | { |
| 429 | .procname = "nss", |
| 430 | .mode = 0555, |
| 431 | .child = nss_ipv4_dir, |
| 432 | }, |
| 433 | { } |
| 434 | }; |
| 435 | |
| 436 | static ctl_table nss_ipv4_root[] = { |
| 437 | { |
| 438 | .procname = "dev", |
| 439 | .mode = 0555, |
| 440 | .child = nss_ipv4_root_dir, |
| 441 | }, |
| 442 | { } |
| 443 | }; |
| 444 | |
| 445 | static struct ctl_table_header *nss_ipv4_header; |
| 446 | |
| 447 | /* |
| 448 | * nss_ipv4_register_sysctl() |
| 449 | * Register sysctl specific to ipv4 |
| 450 | */ |
| 451 | void nss_ipv4_register_sysctl(void) |
| 452 | { |
| 453 | /* |
| 454 | * Register sysctl table. |
| 455 | */ |
| 456 | nss_ipv4_header = register_sysctl_table(nss_ipv4_root); |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 457 | sema_init(&i4cfgp.sem, 1); |
| 458 | init_completion(&i4cfgp.complete); |
| 459 | i4cfgp.current_value = nss_ipv4_conn_cfg; |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | /* |
| 463 | * nss_ipv4_unregister_sysctl() |
| 464 | * Unregister sysctl specific to ipv4 |
| 465 | */ |
| 466 | void nss_ipv4_unregister_sysctl(void) |
| 467 | { |
| 468 | /* |
| 469 | * Unregister sysctl table. |
| 470 | */ |
| 471 | if (nss_ipv4_header) { |
| 472 | unregister_sysctl_table(nss_ipv4_header); |
| 473 | } |
| 474 | } |
| 475 | |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 476 | /* |
| 477 | * nss_ipv4_msg_init() |
| 478 | * Initialize IPv4 message. |
| 479 | */ |
| 480 | void nss_ipv4_msg_init(struct nss_ipv4_msg *nim, uint16_t if_num, uint32_t type, uint32_t len, |
| 481 | nss_ipv4_msg_callback_t *cb, void *app_data) |
| 482 | { |
| 483 | nss_cmn_msg_init(&nim->cm, if_num, type, len, (void *)cb, app_data); |
| 484 | } |
| 485 | |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 486 | EXPORT_SYMBOL(nss_ipv4_tx); |
| 487 | EXPORT_SYMBOL(nss_ipv4_notify_register); |
| 488 | EXPORT_SYMBOL(nss_ipv4_notify_unregister); |
| 489 | EXPORT_SYMBOL(nss_ipv4_get_mgr); |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 490 | EXPORT_SYMBOL(nss_ipv4_register_sysctl); |
| 491 | EXPORT_SYMBOL(nss_ipv4_unregister_sysctl); |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 492 | EXPORT_SYMBOL(nss_ipv4_msg_init); |