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