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