Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Suruchi Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2016, 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 | |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame^] | 24 | #define NSS_IPV4_TX_MSG_TIMEOUT 1000 /* 1 sec timeout for IPv4 messages */ |
| 25 | |
| 26 | /* |
| 27 | * Private data structure for ipv4 configure messages |
| 28 | */ |
| 29 | struct nss_ipv4_cfg_pvt { |
| 30 | struct semaphore sem; /* Semaphore structure */ |
| 31 | struct completion complete; /* completion structure */ |
| 32 | int current_value; /* valid entry */ |
| 33 | int response; /* Response from FW */ |
| 34 | }; |
| 35 | |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 36 | int nss_ipv4_conn_cfg __read_mostly = NSS_DEFAULT_NUM_CONN; |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame^] | 37 | int nss_ipv4_accel_mode_cfg __read_mostly = 1; |
| 38 | |
| 39 | static struct nss_ipv4_cfg_pvt i4_conn_cfgp; |
| 40 | static struct nss_ipv4_cfg_pvt i4_accel_mode_cfgp; |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 41 | |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 42 | /* |
Suruchi Agarwal | 611ecd0 | 2016-08-04 15:54:35 -0700 | [diff] [blame] | 43 | * Callback for conn_sync_many request message. |
| 44 | */ |
| 45 | nss_ipv4_msg_callback_t nss_ipv4_conn_sync_many_msg_cb = NULL; |
| 46 | |
| 47 | /* |
Gareth Williams | 958aa82 | 2015-02-04 19:36:39 +0000 | [diff] [blame] | 48 | * nss_ipv4_max_conn_count() |
| 49 | * Return the maximum number of IPv4 connections that the NSS acceleration engine supports. |
| 50 | */ |
| 51 | int nss_ipv4_max_conn_count(void) |
| 52 | { |
Tushar Mathur | 55ba130 | 2015-09-08 13:14:48 +0530 | [diff] [blame] | 53 | return nss_core_max_ipv4_conn_get(); |
Gareth Williams | 958aa82 | 2015-02-04 19:36:39 +0000 | [diff] [blame] | 54 | } |
| 55 | EXPORT_SYMBOL(nss_ipv4_max_conn_count); |
| 56 | |
| 57 | /* |
Sol Kavy | 57d24b4 | 2014-04-05 13:45:36 -0700 | [diff] [blame] | 58 | * nss_ipv4_driver_conn_sync_update() |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 59 | * Update driver specific information from the messsage. |
| 60 | */ |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 61 | 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] | 62 | { |
Sol Kavy | 57d24b4 | 2014-04-05 13:45:36 -0700 | [diff] [blame] | 63 | struct nss_top_instance *nss_top = nss_ctx->nss_top; |
Sol Kavy | 57d24b4 | 2014-04-05 13:45:36 -0700 | [diff] [blame] | 64 | |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 65 | /* |
| 66 | * Update statistics maintained by NSS driver |
| 67 | */ |
| 68 | spin_lock_bh(&nss_top->stats_lock); |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 69 | nss_top->stats_ipv4[NSS_STATS_IPV4_ACCELERATED_RX_PKTS] += nirs->flow_rx_packet_count + nirs->return_rx_packet_count; |
| 70 | nss_top->stats_ipv4[NSS_STATS_IPV4_ACCELERATED_RX_BYTES] += nirs->flow_rx_byte_count + nirs->return_rx_byte_count; |
| 71 | nss_top->stats_ipv4[NSS_STATS_IPV4_ACCELERATED_TX_PKTS] += nirs->flow_tx_packet_count + nirs->return_tx_packet_count; |
| 72 | 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] | 73 | spin_unlock_bh(&nss_top->stats_lock); |
| 74 | } |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 75 | |
| 76 | /* |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 77 | * nss_ipv4_driver_conn_sync_many_update() |
| 78 | * Update driver specific information from the conn_sync_many messsage. |
| 79 | */ |
| 80 | static void nss_ipv4_driver_conn_sync_many_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv4_conn_sync_many_msg *nicsm) |
| 81 | { |
| 82 | int i; |
| 83 | |
| 84 | /* |
| 85 | * Sanity check for the stats count |
| 86 | */ |
| 87 | if (nicsm->count * sizeof(struct nss_ipv4_conn_sync) >= nicsm->size) { |
| 88 | nss_warning("%p: stats sync count %u exceeds the size of this msg %u", nss_ctx, nicsm->count, nicsm->size); |
| 89 | return; |
| 90 | } |
| 91 | |
| 92 | for (i = 0; i < nicsm->count; i++) { |
| 93 | nss_ipv4_driver_conn_sync_update(nss_ctx, &nicsm->conn_sync[i]); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | /* |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 98 | * nss_ipv4_driver_node_sync_update) |
| 99 | * Update driver specific information from the messsage. |
| 100 | */ |
| 101 | static void nss_ipv4_driver_node_sync_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv4_node_sync *nins) |
| 102 | { |
| 103 | struct nss_top_instance *nss_top = nss_ctx->nss_top; |
| 104 | uint32_t i; |
| 105 | |
| 106 | /* |
| 107 | * Update statistics maintained by NSS driver |
| 108 | */ |
| 109 | spin_lock_bh(&nss_top->stats_lock); |
| 110 | nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_RX_PKTS] += nins->node_stats.rx_packets; |
| 111 | nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_RX_BYTES] += nins->node_stats.rx_bytes; |
| 112 | nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_RX_DROPPED] += nins->node_stats.rx_dropped; |
| 113 | nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_TX_PKTS] += nins->node_stats.tx_packets; |
| 114 | nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_TX_BYTES] += nins->node_stats.tx_bytes; |
| 115 | |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 116 | nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_CREATE_REQUESTS] += nins->ipv4_connection_create_requests; |
| 117 | nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_CREATE_COLLISIONS] += nins->ipv4_connection_create_collisions; |
| 118 | nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_CREATE_INVALID_INTERFACE] += nins->ipv4_connection_create_invalid_interface; |
| 119 | nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_DESTROY_REQUESTS] += nins->ipv4_connection_destroy_requests; |
| 120 | nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_DESTROY_MISSES] += nins->ipv4_connection_destroy_misses; |
| 121 | nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_HASH_HITS] += nins->ipv4_connection_hash_hits; |
| 122 | nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_HASH_REORDERS] += nins->ipv4_connection_hash_reorders; |
| 123 | nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_FLUSHES] += nins->ipv4_connection_flushes; |
| 124 | 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] | 125 | nss_top->stats_ipv4[NSS_STATS_IPV4_FRAGMENTATIONS] += nins->ipv4_fragmentations; |
Kiran Kumar C.S.K | fadf92d | 2015-06-26 12:48:33 +0530 | [diff] [blame] | 126 | nss_top->stats_ipv4[NSS_STATS_IPV4_MC_CONNECTION_CREATE_REQUESTS] += nins->ipv4_mc_connection_create_requests; |
| 127 | nss_top->stats_ipv4[NSS_STATS_IPV4_MC_CONNECTION_UPDATE_REQUESTS] += nins->ipv4_mc_connection_update_requests; |
| 128 | nss_top->stats_ipv4[NSS_STATS_IPV4_MC_CONNECTION_CREATE_INVALID_INTERFACE] += nins->ipv4_mc_connection_create_invalid_interface; |
| 129 | nss_top->stats_ipv4[NSS_STATS_IPV4_MC_CONNECTION_DESTROY_REQUESTS] += nins->ipv4_mc_connection_destroy_requests; |
| 130 | nss_top->stats_ipv4[NSS_STATS_IPV4_MC_CONNECTION_DESTROY_MISSES] += nins->ipv4_mc_connection_destroy_misses; |
| 131 | nss_top->stats_ipv4[NSS_STATS_IPV4_MC_CONNECTION_FLUSHES] += nins->ipv4_mc_connection_flushes; |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 132 | |
| 133 | for (i = 0; i < NSS_EXCEPTION_EVENT_IPV4_MAX; i++) { |
| 134 | nss_top->stats_if_exception_ipv4[i] += nins->exception_events[i]; |
| 135 | } |
| 136 | spin_unlock_bh(&nss_top->stats_lock); |
| 137 | } |
| 138 | |
| 139 | /* |
Sol Kavy | 2783c07 | 2014-04-05 12:53:13 -0700 | [diff] [blame] | 140 | * nss_ipv4_rx_msg_handler() |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 141 | * Handle NSS -> HLOS messages for IPv4 bridge/route |
| 142 | */ |
Sol Kavy | 2783c07 | 2014-04-05 12:53:13 -0700 | [diff] [blame] | 143 | 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] | 144 | { |
| 145 | struct nss_ipv4_msg *nim = (struct nss_ipv4_msg *)ncm; |
Sol Kavy | 57d24b4 | 2014-04-05 13:45:36 -0700 | [diff] [blame] | 146 | nss_ipv4_msg_callback_t cb; |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 147 | |
| 148 | BUG_ON(ncm->interface != NSS_IPV4_RX_INTERFACE); |
| 149 | |
| 150 | /* |
| 151 | * Sanity check the message type |
| 152 | */ |
Murat Sezgin | 5c8c736 | 2014-09-02 17:58:21 -0700 | [diff] [blame] | 153 | if (ncm->type >= NSS_IPV4_MAX_MSG_TYPES) { |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 154 | nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type); |
| 155 | return; |
| 156 | } |
| 157 | |
Suruchi Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 158 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_ipv4_msg)) { |
| 159 | nss_warning("%p: message length is invalid: %d", nss_ctx, nss_cmn_get_msg_len(ncm)); |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 160 | return; |
| 161 | } |
| 162 | |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 163 | /* |
Suruchi Agarwal | e3940e7 | 2016-07-06 15:56:51 -0700 | [diff] [blame] | 164 | * Trace messages. |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 165 | */ |
Suruchi Agarwal | e3940e7 | 2016-07-06 15:56:51 -0700 | [diff] [blame] | 166 | nss_ipv4_log_rx_msg(nim); |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 167 | |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 168 | switch (nim->cm.type) { |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 169 | case NSS_IPV4_RX_NODE_STATS_SYNC_MSG: |
| 170 | /* |
| 171 | * Update driver statistics on node sync. |
| 172 | */ |
| 173 | nss_ipv4_driver_node_sync_update(nss_ctx, &nim->msg.node_stats); |
| 174 | break; |
| 175 | |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 176 | case NSS_IPV4_RX_CONN_STATS_SYNC_MSG: |
Sol Kavy | 57d24b4 | 2014-04-05 13:45:36 -0700 | [diff] [blame] | 177 | /* |
| 178 | * Update driver statistics on connection sync. |
| 179 | */ |
| 180 | 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] | 181 | break; |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 182 | |
| 183 | case NSS_IPV4_TX_CONN_STATS_SYNC_MANY_MSG: |
| 184 | /* |
| 185 | * Update driver statistics on connection sync many. |
| 186 | */ |
| 187 | nss_ipv4_driver_conn_sync_many_update(nss_ctx, &nim->msg.conn_stats_many); |
Suruchi Agarwal | 611ecd0 | 2016-08-04 15:54:35 -0700 | [diff] [blame] | 188 | ncm->cb = (uint32_t)nss_ipv4_conn_sync_many_msg_cb; |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 189 | break; |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | /* |
Sol Kavy | 57d24b4 | 2014-04-05 13:45:36 -0700 | [diff] [blame] | 193 | * Update the callback and app_data for NOTIFY messages, IPv4 sends all notify messages |
| 194 | * to the same callback/app_data. |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 195 | */ |
Sol Kavy | 57d24b4 | 2014-04-05 13:45:36 -0700 | [diff] [blame] | 196 | if (nim->cm.response == NSS_CMM_RESPONSE_NOTIFY) { |
| 197 | ncm->cb = (uint32_t)nss_ctx->nss_top->ipv4_callback; |
| 198 | ncm->app_data = (uint32_t)nss_ctx->nss_top->ipv4_ctx; |
| 199 | } |
Sol Kavy | 2783c07 | 2014-04-05 12:53:13 -0700 | [diff] [blame] | 200 | |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 201 | /* |
| 202 | * Do we have a callback? |
| 203 | */ |
| 204 | if (!ncm->cb) { |
| 205 | return; |
| 206 | } |
| 207 | |
| 208 | /* |
| 209 | * Callback |
| 210 | */ |
Sol Kavy | 57d24b4 | 2014-04-05 13:45:36 -0700 | [diff] [blame] | 211 | cb = (nss_ipv4_msg_callback_t)ncm->cb; |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 212 | cb((void *)ncm->app_data, nim); |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | /* |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 216 | * nss_ipv4_tx_with_size() |
| 217 | * Transmit an ipv4 message to the FW with a specified size. |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 218 | */ |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 219 | nss_tx_status_t nss_ipv4_tx_with_size(struct nss_ctx_instance *nss_ctx, struct nss_ipv4_msg *nim, uint32_t size) |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 220 | { |
| 221 | struct nss_ipv4_msg *nim2; |
| 222 | struct nss_cmn_msg *ncm = &nim->cm; |
| 223 | struct sk_buff *nbuf; |
| 224 | int32_t status; |
| 225 | |
| 226 | NSS_VERIFY_CTX_MAGIC(nss_ctx); |
| 227 | if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) { |
| 228 | nss_warning("%p: ipv4 msg dropped as core not ready", nss_ctx); |
| 229 | return NSS_TX_FAILURE_NOT_READY; |
| 230 | } |
| 231 | |
| 232 | /* |
| 233 | * Sanity check the message |
| 234 | */ |
| 235 | if (ncm->interface != NSS_IPV4_RX_INTERFACE) { |
| 236 | nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface); |
| 237 | return NSS_TX_FAILURE; |
| 238 | } |
| 239 | |
Murat Sezgin | 5c8c736 | 2014-09-02 17:58:21 -0700 | [diff] [blame] | 240 | if (ncm->type >= NSS_IPV4_MAX_MSG_TYPES) { |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 241 | nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type); |
| 242 | return NSS_TX_FAILURE; |
| 243 | } |
| 244 | |
Suruchi Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 245 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_ipv4_msg)) { |
| 246 | nss_warning("%p: message length is invalid: %d", nss_ctx, nss_cmn_get_msg_len(ncm)); |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 247 | return NSS_TX_FAILURE; |
| 248 | } |
| 249 | |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 250 | if(size > PAGE_SIZE) { |
| 251 | nss_warning("%p: tx request size too large: %u", nss_ctx, size); |
| 252 | return NSS_TX_FAILURE; |
| 253 | } |
| 254 | |
| 255 | nbuf = dev_alloc_skb(size); |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 256 | if (unlikely(!nbuf)) { |
Sundarajan Srinivasan | 62fee7e | 2015-01-22 11:13:10 -0800 | [diff] [blame] | 257 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]); |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 258 | nss_warning("%p: msg dropped as command allocation failed", nss_ctx); |
| 259 | return NSS_TX_FAILURE; |
| 260 | } |
| 261 | |
| 262 | /* |
| 263 | * Copy the message to our skb. |
| 264 | */ |
| 265 | nim2 = (struct nss_ipv4_msg *)skb_put(nbuf, sizeof(struct nss_ipv4_msg)); |
| 266 | memcpy(nim2, nim, sizeof(struct nss_ipv4_msg)); |
| 267 | |
Suruchi Agarwal | e3940e7 | 2016-07-06 15:56:51 -0700 | [diff] [blame] | 268 | /* |
| 269 | * Trace messages. |
| 270 | */ |
| 271 | nss_ipv4_log_tx_msg(nim); |
| 272 | |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 273 | status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0); |
| 274 | if (status != NSS_CORE_STATUS_SUCCESS) { |
Pamidipati, Vijay | b6e3884 | 2014-09-16 10:26:05 +0530 | [diff] [blame] | 275 | dev_kfree_skb_any(nbuf); |
Sol Kavy | cd1bd5c | 2014-04-04 11:09:44 -0700 | [diff] [blame] | 276 | nss_warning("%p: unable to enqueue IPv4 msg\n", nss_ctx); |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 277 | return NSS_TX_FAILURE; |
| 278 | } |
| 279 | |
Stephen Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 280 | nss_hal_send_interrupt(nss_ctx, NSS_H2N_INTR_DATA_COMMAND_QUEUE); |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 281 | |
| 282 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]); |
| 283 | return NSS_TX_SUCCESS; |
| 284 | } |
| 285 | |
| 286 | /* |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 287 | * nss_ipv4_tx() |
| 288 | * Transmit an ipv4 message to the FW. |
| 289 | */ |
| 290 | nss_tx_status_t nss_ipv4_tx(struct nss_ctx_instance *nss_ctx, struct nss_ipv4_msg *nim) |
| 291 | { |
| 292 | return nss_ipv4_tx_with_size(nss_ctx, nim, NSS_NBUF_PAYLOAD_SIZE); |
| 293 | } |
| 294 | |
| 295 | /* |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 296 | ********************************** |
| 297 | Register/Unregister/Miscellaneous APIs |
| 298 | ********************************** |
| 299 | */ |
| 300 | |
| 301 | /* |
| 302 | * nss_ipv4_notify_register() |
| 303 | * Register to received IPv4 events. |
| 304 | * |
| 305 | * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv4 on any core? |
| 306 | */ |
| 307 | struct nss_ctx_instance *nss_ipv4_notify_register(nss_ipv4_msg_callback_t cb, void *app_data) |
| 308 | { |
| 309 | /* |
| 310 | * TODO: We need to have a new array in support of the new API |
| 311 | * TODO: If we use a per-context array, we would move the array into nss_ctx based. |
| 312 | */ |
| 313 | nss_top_main.ipv4_callback = cb; |
Abhishek Rastogi | e11f47b | 2014-04-04 18:43:32 +0530 | [diff] [blame] | 314 | nss_top_main.ipv4_ctx = app_data; |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 315 | return &nss_top_main.nss[nss_top_main.ipv4_handler_id]; |
| 316 | } |
| 317 | |
| 318 | /* |
| 319 | * nss_ipv4_notify_unregister() |
| 320 | * Unregister to received IPv4 events. |
| 321 | * |
| 322 | * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv4 on any core? |
| 323 | */ |
| 324 | void nss_ipv4_notify_unregister(void) |
| 325 | { |
| 326 | nss_top_main.ipv4_callback = NULL; |
| 327 | } |
| 328 | |
| 329 | /* |
Suruchi Agarwal | 611ecd0 | 2016-08-04 15:54:35 -0700 | [diff] [blame] | 330 | * nss_ipv4_conn_sync_many_notify_register() |
| 331 | * Register to receive IPv4 conn_sync_many message response. |
| 332 | */ |
| 333 | void nss_ipv4_conn_sync_many_notify_register(nss_ipv4_msg_callback_t cb) |
| 334 | { |
| 335 | nss_ipv4_conn_sync_many_msg_cb = cb; |
| 336 | } |
| 337 | |
| 338 | /* |
| 339 | * nss_ipv4_conn_sync_many_notify_unregister() |
| 340 | * Unregister to receive IPv4 conn_sync_many message response. |
| 341 | */ |
| 342 | void nss_ipv4_conn_sync_many_notify_unregister(void) |
| 343 | { |
| 344 | nss_ipv4_conn_sync_many_msg_cb = NULL; |
| 345 | } |
| 346 | |
| 347 | /* |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 348 | * nss_ipv4_get_mgr() |
| 349 | * |
| 350 | * TODO: This only suppports a single ipv4, do we ever want to support more? |
| 351 | */ |
| 352 | struct nss_ctx_instance *nss_ipv4_get_mgr(void) |
| 353 | { |
| 354 | return (void *)&nss_top_main.nss[nss_top_main.ipv4_handler_id]; |
| 355 | } |
| 356 | |
| 357 | /* |
| 358 | * nss_ipv4_register_handler() |
| 359 | * Register our handler to receive messages for this interface |
| 360 | */ |
Sol Kavy | 2783c07 | 2014-04-05 12:53:13 -0700 | [diff] [blame] | 361 | void nss_ipv4_register_handler(void) |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 362 | { |
Sol Kavy | 2783c07 | 2014-04-05 12:53:13 -0700 | [diff] [blame] | 363 | 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] | 364 | nss_warning("IPv4 handler failed to register"); |
| 365 | } |
| 366 | } |
| 367 | |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 368 | /* |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 369 | * nss_ipv4_conn_cfg_process() |
| 370 | * Process request to configure number of ipv4 connections |
| 371 | */ |
| 372 | static int nss_ipv4_conn_cfg_process(struct nss_ctx_instance *nss_ctx, int conn, |
| 373 | void (*cfg_cb)(void *app_data, struct nss_ipv4_msg *nim)) |
| 374 | { |
| 375 | struct nss_ipv4_msg nim; |
| 376 | struct nss_ipv4_rule_conn_cfg_msg *nirccm; |
| 377 | nss_tx_status_t nss_tx_status; |
| 378 | uint32_t sum_of_conn; |
| 379 | |
| 380 | /* |
| 381 | * The input should be multiple of 1024. |
| 382 | * Input for ipv4 and ipv6 sum together should not exceed 8k |
| 383 | * Min. value should be at least 256 connections. This is the |
| 384 | * minimum connections we will support for each of them. |
| 385 | */ |
| 386 | sum_of_conn = conn + nss_ipv6_conn_cfg; |
| 387 | if ((conn & NSS_NUM_CONN_QUANTA_MASK) || |
| 388 | (sum_of_conn > NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6) || |
| 389 | (conn < NSS_MIN_NUM_CONN)) { |
| 390 | nss_warning("%p: input supported connections (%d) does not adhere\ |
| 391 | specifications\n1) not multiple of 1024,\n2) is less than \ |
| 392 | min val: %d, OR\n IPv4/6 total exceeds %d\n", |
| 393 | nss_ctx, |
| 394 | conn, |
| 395 | NSS_MIN_NUM_CONN, |
| 396 | NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6); |
| 397 | return -EINVAL; |
| 398 | } |
| 399 | |
| 400 | nss_info("%p: IPv4 supported connections: %d\n", nss_ctx, conn); |
| 401 | |
| 402 | memset(&nim, 0, sizeof(struct nss_ipv4_msg)); |
| 403 | nss_ipv4_msg_init(&nim, NSS_IPV4_RX_INTERFACE, NSS_IPV4_TX_CONN_CFG_RULE_MSG, |
| 404 | sizeof(struct nss_ipv4_rule_conn_cfg_msg), cfg_cb, NULL); |
| 405 | |
| 406 | nirccm = &nim.msg.rule_conn_cfg; |
| 407 | nirccm->num_conn = htonl(conn); |
| 408 | nss_tx_status = nss_ipv4_tx(nss_ctx, &nim); |
| 409 | |
| 410 | if (nss_tx_status != NSS_TX_SUCCESS) { |
| 411 | nss_warning("%p: nss_tx error setting IPv4 Connections: %d\n", |
| 412 | nss_ctx, |
| 413 | conn); |
| 414 | return -EIO; |
| 415 | } |
| 416 | |
| 417 | return 0; |
| 418 | } |
| 419 | |
| 420 | /* |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 421 | * nss_ipv4_conn_cfg_callback() |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 422 | * call back function for the ipv4 connection configuration handler |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 423 | */ |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 424 | 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] | 425 | { |
| 426 | |
| 427 | if (nim->cm.response != NSS_CMN_RESPONSE_ACK) { |
| 428 | 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] | 429 | /* |
| 430 | * Error, hence we are not updating the nss_ipv4_conn_cfg |
| 431 | * Restore the current_value to its previous state |
| 432 | */ |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame^] | 433 | i4_conn_cfgp.response = NSS_FAILURE; |
| 434 | complete(&i4_conn_cfgp.complete); |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 435 | return; |
| 436 | } |
| 437 | |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 438 | /* |
| 439 | * Sucess at NSS FW, hence updating nss_ipv4_conn_cfg, with the valid value |
| 440 | * saved at the sysctl handler. |
| 441 | */ |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 442 | nss_info("IPv4 connection configuration success: %d\n", nim->cm.error); |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame^] | 443 | i4_conn_cfgp.response = NSS_SUCCESS; |
| 444 | complete(&i4_conn_cfgp.complete); |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | /* |
| 448 | * nss_ipv4_conn_cfg_handler() |
| 449 | * Sets the number of connections for IPv4 |
| 450 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 451 | static int nss_ipv4_conn_cfg_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos) |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 452 | { |
| 453 | struct nss_top_instance *nss_top = &nss_top_main; |
| 454 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[0]; |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 455 | int ret = NSS_FAILURE; |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 456 | |
| 457 | /* |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 458 | * Acquiring semaphore |
| 459 | */ |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame^] | 460 | down(&i4_conn_cfgp.sem); |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 461 | |
| 462 | /* |
| 463 | * Take snap shot of current value |
| 464 | */ |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame^] | 465 | i4_conn_cfgp.current_value = nss_ipv4_conn_cfg; |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 466 | |
| 467 | /* |
| 468 | * Write the variable with user input |
| 469 | */ |
| 470 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 471 | if (ret || (!write)) { |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame^] | 472 | up(&i4_conn_cfgp.sem); |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 473 | return ret; |
| 474 | } |
| 475 | |
| 476 | /* |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 477 | * Process request to change number of IPv4 connections |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 478 | */ |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 479 | ret = nss_ipv4_conn_cfg_process(nss_ctx, nss_ipv4_conn_cfg, nss_ipv4_conn_cfg_callback); |
| 480 | if (ret != 0) { |
Stephen Wang | 0676102 | 2015-03-03 16:38:42 -0800 | [diff] [blame] | 481 | goto failure; |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 482 | } |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 483 | |
| 484 | /* |
| 485 | * Blocking call, wait till we get ACK for this msg. |
| 486 | */ |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame^] | 487 | ret = wait_for_completion_timeout(&i4_conn_cfgp.complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT)); |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 488 | if (ret == 0) { |
| 489 | nss_warning("%p: Waiting for ack timed out\n", nss_ctx); |
Stephen Wang | 0676102 | 2015-03-03 16:38:42 -0800 | [diff] [blame] | 490 | goto failure; |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | /* |
| 494 | * ACK/NACK received from NSS FW |
| 495 | * If ACK: Callback function will update nss_ipv4_conn_cfg with |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame^] | 496 | * i4_conn_cfgp.num_conn_valid, which holds the user input |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 497 | */ |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame^] | 498 | if (NSS_FAILURE == i4_conn_cfgp.response) { |
Stephen Wang | 0676102 | 2015-03-03 16:38:42 -0800 | [diff] [blame] | 499 | goto failure; |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 500 | } |
| 501 | |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame^] | 502 | up(&i4_conn_cfgp.sem); |
Thomas Wu | 651b390 | 2015-05-12 11:21:09 -0700 | [diff] [blame] | 503 | return 0; |
Stephen Wang | 0676102 | 2015-03-03 16:38:42 -0800 | [diff] [blame] | 504 | |
| 505 | failure: |
| 506 | /* |
| 507 | * Restore the current_value to its previous state |
| 508 | */ |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame^] | 509 | nss_ipv4_conn_cfg = i4_conn_cfgp.current_value; |
| 510 | up(&i4_conn_cfgp.sem); |
Thomas Wu | 651b390 | 2015-05-12 11:21:09 -0700 | [diff] [blame] | 511 | return -EINVAL; |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 512 | } |
| 513 | |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 514 | /* |
| 515 | * nss_ipv4_update_conn_count_cb() |
| 516 | * call back function for the ipv4 connection count update handler |
| 517 | */ |
| 518 | static void nss_ipv4_update_conn_count_cb(void *app_data, struct nss_ipv4_msg *nim) |
| 519 | { |
| 520 | if (nim->cm.response != NSS_CMN_RESPONSE_ACK) { |
| 521 | nss_warning("IPv4 connection count update failed with error: %d\n", nim->cm.error); |
| 522 | return; |
| 523 | } |
| 524 | |
| 525 | nss_warning("IPv4 connection count update success: %d\n", nim->cm.error); |
| 526 | } |
| 527 | |
| 528 | /* |
| 529 | * nss_ipv4_update_conn_count() |
| 530 | * Sets the maximum number of connections for IPv4 |
| 531 | */ |
| 532 | int nss_ipv4_update_conn_count(int ipv4_num_conn) |
| 533 | { |
| 534 | struct nss_top_instance *nss_top = &nss_top_main; |
| 535 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[0]; |
| 536 | int saved_nss_ipv4_conn_cfg = nss_ipv4_conn_cfg; |
| 537 | int ret = 0; |
| 538 | |
| 539 | nss_ipv4_conn_cfg = ipv4_num_conn; |
| 540 | |
| 541 | /* |
| 542 | * Process request to change number of IPv4 connections |
| 543 | */ |
| 544 | ret = nss_ipv4_conn_cfg_process(nss_ctx, nss_ipv4_conn_cfg, |
| 545 | nss_ipv4_update_conn_count_cb); |
| 546 | if (ret != 0) { |
| 547 | nss_ipv4_conn_cfg = saved_nss_ipv4_conn_cfg; |
| 548 | return ret; |
| 549 | } |
| 550 | |
| 551 | return 0; |
| 552 | } |
| 553 | |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame^] | 554 | /* |
| 555 | * nss_ipv4_accel_mode_cfg_callback() |
| 556 | * call back function for the ipv4 acceleration mode configurate handler |
| 557 | */ |
| 558 | static void nss_ipv4_accel_mode_cfg_callback(void *app_data, struct nss_ipv4_msg *nim) |
| 559 | { |
| 560 | if (nim->cm.response != NSS_CMN_RESPONSE_ACK) { |
| 561 | nss_warning("IPv4 acceleration mode configuration failed with error: %d\n", nim->cm.error); |
| 562 | i4_accel_mode_cfgp.response = NSS_FAILURE; |
| 563 | complete(&i4_accel_mode_cfgp.complete); |
| 564 | return; |
| 565 | } |
| 566 | |
| 567 | nss_info("IPv4 acceleration mode configuration success\n"); |
| 568 | i4_accel_mode_cfgp.response = NSS_SUCCESS; |
| 569 | complete(&i4_accel_mode_cfgp.complete); |
| 570 | } |
| 571 | |
| 572 | /* |
| 573 | * nss_ipv4_accel_mode_cfg_handler() |
| 574 | * Configure acceleration mode for IPv4 |
| 575 | */ |
| 576 | static int nss_ipv4_accel_mode_cfg_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos) |
| 577 | { |
| 578 | struct nss_top_instance *nss_top = &nss_top_main; |
| 579 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[0]; |
| 580 | struct nss_ipv4_msg nim; |
| 581 | struct nss_ipv4_accel_mode_cfg_msg *nipcm; |
| 582 | nss_tx_status_t nss_tx_status; |
| 583 | int ret = NSS_FAILURE; |
| 584 | |
| 585 | /* |
| 586 | * Acquiring semaphore |
| 587 | */ |
| 588 | down(&i4_accel_mode_cfgp.sem); |
| 589 | |
| 590 | /* |
| 591 | * Take snap shot of current value |
| 592 | */ |
| 593 | i4_accel_mode_cfgp.current_value = nss_ipv4_accel_mode_cfg; |
| 594 | |
| 595 | /* |
| 596 | * Write the variable with user input |
| 597 | */ |
| 598 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 599 | if (ret || (!write)) { |
| 600 | up(&i4_accel_mode_cfgp.sem); |
| 601 | return ret; |
| 602 | } |
| 603 | |
| 604 | memset(&nim, 0, sizeof(struct nss_ipv4_msg)); |
| 605 | nss_ipv4_msg_init(&nim, NSS_IPV4_RX_INTERFACE, NSS_IPV4_TX_ACCEL_MODE_CFG_MSG, |
| 606 | sizeof(struct nss_ipv4_accel_mode_cfg_msg), nss_ipv4_accel_mode_cfg_callback, NULL); |
| 607 | |
| 608 | nipcm = &nim.msg.accel_mode_cfg; |
| 609 | nipcm->mode = htonl(nss_ipv4_accel_mode_cfg); |
| 610 | nss_tx_status = nss_ipv4_tx(nss_ctx, &nim); |
| 611 | |
| 612 | if (nss_tx_status != NSS_TX_SUCCESS) { |
| 613 | nss_warning("%p: Send acceleration mode message failed\n", nss_ctx); |
| 614 | goto fail; |
| 615 | } |
| 616 | |
| 617 | /* |
| 618 | * Blocking call, wait till we get ACK for this msg. |
| 619 | */ |
| 620 | ret = wait_for_completion_timeout(&i4_accel_mode_cfgp.complete, msecs_to_jiffies(NSS_IPV4_TX_MSG_TIMEOUT)); |
| 621 | if (ret == 0) { |
| 622 | nss_warning("%p: Waiting for ack timed out\n", nss_ctx); |
| 623 | goto fail; |
| 624 | } |
| 625 | |
| 626 | if (NSS_FAILURE == i4_accel_mode_cfgp.response) { |
| 627 | nss_warning("%p: accel mode configure failed\n", nss_ctx); |
| 628 | goto fail; |
| 629 | } |
| 630 | |
| 631 | up(&i4_accel_mode_cfgp.sem); |
| 632 | return 0; |
| 633 | |
| 634 | fail: |
| 635 | nss_ipv4_accel_mode_cfg = i4_accel_mode_cfgp.current_value; |
| 636 | up(&i4_accel_mode_cfgp.sem); |
| 637 | return -EIO; |
| 638 | } |
| 639 | |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 640 | static struct ctl_table nss_ipv4_table[] = { |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 641 | { |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 642 | .procname = "ipv4_conn", |
| 643 | .data = &nss_ipv4_conn_cfg, |
| 644 | .maxlen = sizeof(int), |
| 645 | .mode = 0644, |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame^] | 646 | .proc_handler = &nss_ipv4_conn_cfg_handler, |
| 647 | }, |
| 648 | { |
| 649 | .procname = "ipv4_accel_mode", |
| 650 | .data = &nss_ipv4_accel_mode_cfg, |
| 651 | .maxlen = sizeof(int), |
| 652 | .mode = 0644, |
| 653 | .proc_handler = &nss_ipv4_accel_mode_cfg_handler, |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 654 | }, |
| 655 | { } |
| 656 | }; |
| 657 | |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 658 | static struct ctl_table nss_ipv4_dir[] = { |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 659 | { |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 660 | .procname = "ipv4cfg", |
| 661 | .mode = 0555, |
| 662 | .child = nss_ipv4_table, |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 663 | }, |
| 664 | { } |
| 665 | }; |
| 666 | |
| 667 | |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 668 | static struct ctl_table nss_ipv4_root_dir[] = { |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 669 | { |
| 670 | .procname = "nss", |
| 671 | .mode = 0555, |
| 672 | .child = nss_ipv4_dir, |
| 673 | }, |
| 674 | { } |
| 675 | }; |
| 676 | |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 677 | static struct ctl_table nss_ipv4_root[] = { |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 678 | { |
| 679 | .procname = "dev", |
| 680 | .mode = 0555, |
| 681 | .child = nss_ipv4_root_dir, |
| 682 | }, |
| 683 | { } |
| 684 | }; |
| 685 | |
| 686 | static struct ctl_table_header *nss_ipv4_header; |
| 687 | |
| 688 | /* |
| 689 | * nss_ipv4_register_sysctl() |
| 690 | * Register sysctl specific to ipv4 |
| 691 | */ |
| 692 | void nss_ipv4_register_sysctl(void) |
| 693 | { |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame^] | 694 | sema_init(&i4_conn_cfgp.sem, 1); |
| 695 | init_completion(&i4_conn_cfgp.complete); |
| 696 | |
| 697 | sema_init(&i4_accel_mode_cfgp.sem, 1); |
| 698 | init_completion(&i4_accel_mode_cfgp.complete); |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 699 | |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 700 | /* |
| 701 | * Register sysctl table. |
| 702 | */ |
| 703 | nss_ipv4_header = register_sysctl_table(nss_ipv4_root); |
| 704 | } |
| 705 | |
| 706 | /* |
| 707 | * nss_ipv4_unregister_sysctl() |
| 708 | * Unregister sysctl specific to ipv4 |
| 709 | */ |
| 710 | void nss_ipv4_unregister_sysctl(void) |
| 711 | { |
| 712 | /* |
| 713 | * Unregister sysctl table. |
| 714 | */ |
| 715 | if (nss_ipv4_header) { |
| 716 | unregister_sysctl_table(nss_ipv4_header); |
| 717 | } |
| 718 | } |
| 719 | |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 720 | /* |
| 721 | * nss_ipv4_msg_init() |
| 722 | * Initialize IPv4 message. |
| 723 | */ |
| 724 | void nss_ipv4_msg_init(struct nss_ipv4_msg *nim, uint16_t if_num, uint32_t type, uint32_t len, |
Sundarajan Srinivasan | 30a53d4 | 2015-01-30 10:52:08 -0800 | [diff] [blame] | 725 | nss_ipv4_msg_callback_t cb, void *app_data) |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 726 | { |
| 727 | nss_cmn_msg_init(&nim->cm, if_num, type, len, (void *)cb, app_data); |
| 728 | } |
| 729 | |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 730 | EXPORT_SYMBOL(nss_ipv4_tx); |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 731 | EXPORT_SYMBOL(nss_ipv4_tx_with_size); |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 732 | EXPORT_SYMBOL(nss_ipv4_notify_register); |
| 733 | EXPORT_SYMBOL(nss_ipv4_notify_unregister); |
Suruchi Agarwal | 611ecd0 | 2016-08-04 15:54:35 -0700 | [diff] [blame] | 734 | EXPORT_SYMBOL(nss_ipv4_conn_sync_many_notify_register); |
| 735 | EXPORT_SYMBOL(nss_ipv4_conn_sync_many_notify_unregister); |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 736 | EXPORT_SYMBOL(nss_ipv4_get_mgr); |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 737 | EXPORT_SYMBOL(nss_ipv4_register_sysctl); |
| 738 | EXPORT_SYMBOL(nss_ipv4_unregister_sysctl); |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 739 | EXPORT_SYMBOL(nss_ipv4_msg_init); |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 740 | EXPORT_SYMBOL(nss_ipv4_update_conn_count); |