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