Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Suruchi Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, The Linux Foundation. All rights reserved. |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -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 | /* |
| 18 | * nss_ipv6.c |
| 19 | * NSS IPv6 APIs |
| 20 | */ |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 21 | #include "nss_tx_rx_common.h" |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 22 | |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 23 | int nss_ipv6_conn_cfg __read_mostly = NSS_DEFAULT_NUM_CONN; |
| 24 | static struct nss_conn_cfg_pvt i6cfgp; |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 25 | |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 26 | /* |
Suruchi Agarwal | 611ecd0 | 2016-08-04 15:54:35 -0700 | [diff] [blame^] | 27 | * Callback for conn_sync_many request message. |
| 28 | */ |
| 29 | nss_ipv6_msg_callback_t nss_ipv6_conn_sync_many_msg_cb = NULL; |
| 30 | |
| 31 | /* |
Gareth Williams | 958aa82 | 2015-02-04 19:36:39 +0000 | [diff] [blame] | 32 | * nss_ipv6_max_conn_count() |
| 33 | * Return the maximum number of IPv6 connections that the NSS acceleration engine supports. |
| 34 | */ |
| 35 | int nss_ipv6_max_conn_count(void) |
| 36 | { |
Tushar Mathur | 55ba130 | 2015-09-08 13:14:48 +0530 | [diff] [blame] | 37 | return nss_core_max_ipv6_conn_get(); |
Gareth Williams | 958aa82 | 2015-02-04 19:36:39 +0000 | [diff] [blame] | 38 | } |
| 39 | EXPORT_SYMBOL(nss_ipv6_max_conn_count); |
| 40 | |
| 41 | /* |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 42 | * nss_ipv6_driver_conn_sync_update() |
| 43 | * Update driver specific information from the messsage. |
| 44 | */ |
| 45 | static void nss_ipv6_driver_conn_sync_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_conn_sync *nics) |
| 46 | { |
| 47 | struct nss_top_instance *nss_top = nss_ctx->nss_top; |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 48 | |
| 49 | /* |
| 50 | * Update statistics maintained by NSS driver |
| 51 | */ |
| 52 | spin_lock_bh(&nss_top->stats_lock); |
| 53 | nss_top->stats_ipv6[NSS_STATS_IPV6_ACCELERATED_RX_PKTS] += nics->flow_rx_packet_count + nics->return_rx_packet_count; |
| 54 | nss_top->stats_ipv6[NSS_STATS_IPV6_ACCELERATED_RX_BYTES] += nics->flow_rx_byte_count + nics->return_rx_byte_count; |
| 55 | nss_top->stats_ipv6[NSS_STATS_IPV6_ACCELERATED_TX_PKTS] += nics->flow_tx_packet_count + nics->return_tx_packet_count; |
| 56 | nss_top->stats_ipv6[NSS_STATS_IPV6_ACCELERATED_TX_BYTES] += nics->flow_tx_byte_count + nics->return_tx_byte_count; |
Abhishek Rastogi | 55f3945 | 2014-05-08 19:23:29 +0530 | [diff] [blame] | 57 | spin_unlock_bh(&nss_top->stats_lock); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | /* |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 61 | * nss_ipv6_driver_conn_sync_many_update() |
| 62 | * Update driver specific information from the conn_sync_many messsage. |
| 63 | */ |
| 64 | static void nss_ipv6_driver_conn_sync_many_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_conn_sync_many_msg *nicsm) |
| 65 | { |
| 66 | uint32_t i; |
| 67 | |
| 68 | /* |
| 69 | * Sanity check for the stats count |
| 70 | */ |
| 71 | if (nicsm->count * sizeof(struct nss_ipv6_conn_sync) >= nicsm->size) { |
| 72 | nss_warning("%p: stats sync count %u exceeds the size of this msg %u", nss_ctx, nicsm->count, nicsm->size); |
| 73 | return; |
| 74 | } |
| 75 | |
| 76 | for (i = 0; i < nicsm->count; i++) { |
| 77 | nss_ipv6_driver_conn_sync_update(nss_ctx, &nicsm->conn_sync[i]); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | /* |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 82 | * nss_ipv6_driver_node_sync_update) |
| 83 | * Update driver specific information from the messsage. |
| 84 | */ |
| 85 | static void nss_ipv6_driver_node_sync_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_node_sync *nins) |
| 86 | { |
| 87 | struct nss_top_instance *nss_top = nss_ctx->nss_top; |
| 88 | uint32_t i; |
| 89 | |
| 90 | /* |
| 91 | * Update statistics maintained by NSS driver |
| 92 | */ |
| 93 | spin_lock_bh(&nss_top->stats_lock); |
| 94 | nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_RX_PKTS] += nins->node_stats.rx_packets; |
| 95 | nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_RX_BYTES] += nins->node_stats.rx_bytes; |
| 96 | nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_RX_DROPPED] += nins->node_stats.rx_dropped; |
| 97 | nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_TX_PKTS] += nins->node_stats.tx_packets; |
| 98 | nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_TX_BYTES] += nins->node_stats.tx_bytes; |
| 99 | |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 100 | nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_CREATE_REQUESTS] += nins->ipv6_connection_create_requests; |
| 101 | nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_CREATE_COLLISIONS] += nins->ipv6_connection_create_collisions; |
| 102 | nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_CREATE_INVALID_INTERFACE] += nins->ipv6_connection_create_invalid_interface; |
| 103 | nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_DESTROY_REQUESTS] += nins->ipv6_connection_destroy_requests; |
| 104 | nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_DESTROY_MISSES] += nins->ipv6_connection_destroy_misses; |
| 105 | nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_HASH_HITS] += nins->ipv6_connection_hash_hits; |
| 106 | nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_HASH_REORDERS] += nins->ipv6_connection_hash_reorders; |
| 107 | nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_FLUSHES] += nins->ipv6_connection_flushes; |
| 108 | nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_EVICTIONS] += nins->ipv6_connection_evictions; |
Selin Dag | 5d68caa | 2015-05-12 13:23:33 -0700 | [diff] [blame] | 109 | nss_top->stats_ipv6[NSS_STATS_IPV6_FRAGMENTATIONS] += nins->ipv6_fragmentations; |
| 110 | nss_top->stats_ipv6[NSS_STATS_IPV6_FRAG_FAILS] += nins->ipv6_frag_fails; |
Kiran Kumar C.S.K | fadf92d | 2015-06-26 12:48:33 +0530 | [diff] [blame] | 111 | nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_CREATE_REQUESTS] += nins->ipv6_mc_connection_create_requests; |
| 112 | nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_UPDATE_REQUESTS] += nins->ipv6_mc_connection_update_requests; |
| 113 | nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_CREATE_INVALID_INTERFACE] += nins->ipv6_mc_connection_create_invalid_interface; |
| 114 | nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_DESTROY_REQUESTS] += nins->ipv6_mc_connection_destroy_requests; |
| 115 | nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_DESTROY_MISSES] += nins->ipv6_mc_connection_destroy_misses; |
| 116 | nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_FLUSHES] += nins->ipv6_mc_connection_flushes; |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 117 | |
| 118 | for (i = 0; i < NSS_EXCEPTION_EVENT_IPV6_MAX; i++) { |
| 119 | nss_top->stats_if_exception_ipv6[i] += nins->exception_events[i]; |
| 120 | } |
| 121 | spin_unlock_bh(&nss_top->stats_lock); |
| 122 | } |
| 123 | |
| 124 | /* |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 125 | * nss_ipv6_rx_msg_handler() |
| 126 | * Handle NSS -> HLOS messages for IPv6 bridge/route |
| 127 | */ |
| 128 | static void nss_ipv6_rx_msg_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data) |
| 129 | { |
| 130 | struct nss_ipv6_msg *nim = (struct nss_ipv6_msg *)ncm; |
| 131 | nss_ipv6_msg_callback_t cb; |
| 132 | |
| 133 | BUG_ON(ncm->interface != NSS_IPV6_RX_INTERFACE); |
| 134 | |
| 135 | /* |
| 136 | * Is this a valid request/response packet? |
| 137 | */ |
Murat Sezgin | 5c8c736 | 2014-09-02 17:58:21 -0700 | [diff] [blame] | 138 | if (ncm->type >= NSS_IPV6_MAX_MSG_TYPES) { |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 139 | nss_warning("%p: received invalid message %d for IPv6 interface", nss_ctx, nim->cm.type); |
| 140 | return; |
| 141 | } |
| 142 | |
Suruchi Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 143 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_ipv6_msg)) { |
| 144 | nss_warning("%p: message length is invalid: %d", nss_ctx, nss_cmn_get_msg_len(ncm)); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 145 | return; |
| 146 | } |
| 147 | |
| 148 | /* |
| 149 | * Log failures |
| 150 | */ |
| 151 | nss_core_log_msg_failures(nss_ctx, ncm); |
| 152 | |
| 153 | /* |
| 154 | * Handle deprecated messages. Eventually these messages should be removed. |
| 155 | */ |
| 156 | switch (nim->cm.type) { |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 157 | case NSS_IPV6_RX_NODE_STATS_SYNC_MSG: |
| 158 | /* |
| 159 | * Update driver statistics on node sync. |
| 160 | */ |
| 161 | nss_ipv6_driver_node_sync_update(nss_ctx, &nim->msg.node_stats); |
| 162 | break; |
| 163 | |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 164 | case NSS_IPV6_RX_CONN_STATS_SYNC_MSG: |
| 165 | /* |
| 166 | * Update driver statistics on connection sync. |
| 167 | */ |
| 168 | nss_ipv6_driver_conn_sync_update(nss_ctx, &nim->msg.conn_stats); |
Sakthi Vignesh Radhakrishnan | 515f8c2 | 2014-06-21 15:04:19 -0700 | [diff] [blame] | 169 | break; |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 170 | |
| 171 | case NSS_IPV6_TX_CONN_STATS_SYNC_MANY_MSG: |
| 172 | /* |
| 173 | * Update driver statistics on connection sync many. |
| 174 | */ |
| 175 | nss_ipv6_driver_conn_sync_many_update(nss_ctx, &nim->msg.conn_stats_many); |
Suruchi Agarwal | 611ecd0 | 2016-08-04 15:54:35 -0700 | [diff] [blame^] | 176 | ncm->cb = (uint32_t)nss_ipv6_conn_sync_many_msg_cb; |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 177 | break; |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 178 | } |
Abhishek Rastogi | 55f3945 | 2014-05-08 19:23:29 +0530 | [diff] [blame] | 179 | |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 180 | /* |
| 181 | * Update the callback and app_data for NOTIFY messages, IPv6 sends all notify messages |
| 182 | * to the same callback/app_data. |
| 183 | */ |
| 184 | if (nim->cm.response == NSS_CMM_RESPONSE_NOTIFY) { |
| 185 | ncm->cb = (uint32_t)nss_ctx->nss_top->ipv6_callback; |
| 186 | ncm->app_data = (uint32_t)nss_ctx->nss_top->ipv6_ctx; |
| 187 | } |
| 188 | |
| 189 | /* |
| 190 | * Do we have a callback? |
| 191 | */ |
| 192 | if (!ncm->cb) { |
| 193 | return; |
| 194 | } |
| 195 | |
| 196 | /* |
| 197 | * Callback |
| 198 | */ |
| 199 | cb = (nss_ipv6_msg_callback_t)ncm->cb; |
| 200 | cb((void *)ncm->app_data, nim); |
| 201 | } |
| 202 | |
| 203 | /* |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 204 | * nss_ipv6_tx_with_size() |
| 205 | * Transmit an ipv6 message to the FW with a specified size. |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 206 | */ |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 207 | nss_tx_status_t nss_ipv6_tx_with_size(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_msg *nim, uint32_t size) |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 208 | { |
| 209 | struct nss_ipv6_msg *nim2; |
| 210 | struct nss_cmn_msg *ncm = &nim->cm; |
| 211 | struct sk_buff *nbuf; |
| 212 | int32_t status; |
| 213 | |
| 214 | NSS_VERIFY_CTX_MAGIC(nss_ctx); |
| 215 | if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) { |
| 216 | nss_warning("%p: ipv6 msg dropped as core not ready", nss_ctx); |
| 217 | return NSS_TX_FAILURE_NOT_READY; |
| 218 | } |
| 219 | |
| 220 | /* |
| 221 | * Sanity check the message |
| 222 | */ |
| 223 | if (ncm->interface != NSS_IPV6_RX_INTERFACE) { |
| 224 | nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface); |
| 225 | return NSS_TX_FAILURE; |
| 226 | } |
| 227 | |
Murat Sezgin | 5c8c736 | 2014-09-02 17:58:21 -0700 | [diff] [blame] | 228 | if (ncm->type >= NSS_IPV6_MAX_MSG_TYPES) { |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 229 | nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type); |
| 230 | return NSS_TX_FAILURE; |
| 231 | } |
| 232 | |
Suruchi Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 233 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_ipv6_msg)) { |
| 234 | nss_warning("%p: message length is invalid: %d", nss_ctx, nss_cmn_get_msg_len(ncm)); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 235 | return NSS_TX_FAILURE; |
| 236 | } |
| 237 | |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 238 | if(size > PAGE_SIZE) { |
| 239 | nss_warning("%p: tx request size too large: %u", nss_ctx, size); |
| 240 | return NSS_TX_FAILURE; |
| 241 | } |
| 242 | |
| 243 | nbuf = dev_alloc_skb(size); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 244 | if (unlikely(!nbuf)) { |
Sundarajan Srinivasan | 62fee7e | 2015-01-22 11:13:10 -0800 | [diff] [blame] | 245 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 246 | nss_warning("%p: msg dropped as command allocation failed", nss_ctx); |
| 247 | return NSS_TX_FAILURE; |
| 248 | } |
| 249 | |
| 250 | /* |
| 251 | * Copy the message to our skb. |
| 252 | */ |
| 253 | nim2 = (struct nss_ipv6_msg *)skb_put(nbuf, sizeof(struct nss_ipv6_msg)); |
| 254 | memcpy(nim2, nim, sizeof(struct nss_ipv6_msg)); |
| 255 | |
| 256 | status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0); |
| 257 | if (status != NSS_CORE_STATUS_SUCCESS) { |
Pamidipati, Vijay | b6e3884 | 2014-09-16 10:26:05 +0530 | [diff] [blame] | 258 | dev_kfree_skb_any(nbuf); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 259 | nss_warning("%p: Unable to enqueue 'Destroy IPv6' rule\n", nss_ctx); |
| 260 | return NSS_TX_FAILURE; |
| 261 | } |
| 262 | |
| 263 | nss_hal_send_interrupt(nss_ctx->nmap, nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit, |
| 264 | NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE); |
| 265 | |
| 266 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]); |
| 267 | return NSS_TX_SUCCESS; |
| 268 | } |
| 269 | |
| 270 | /* |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 271 | * nss_ipv6_tx() |
Suruchi Agarwal | 611ecd0 | 2016-08-04 15:54:35 -0700 | [diff] [blame^] | 272 | * Transmit an ipv6 message to the FW. |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 273 | */ |
| 274 | nss_tx_status_t nss_ipv6_tx(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_msg *nim) |
| 275 | { |
| 276 | return nss_ipv6_tx_with_size(nss_ctx, nim, NSS_NBUF_PAYLOAD_SIZE); |
| 277 | } |
| 278 | |
| 279 | /* |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 280 | ********************************** |
| 281 | Register/Unregister/Miscellaneous APIs |
| 282 | ********************************** |
| 283 | */ |
| 284 | |
| 285 | /* |
| 286 | * nss_ipv6_notify_register() |
| 287 | * Register to received IPv6 events. |
| 288 | * |
| 289 | * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv6 on any core? |
| 290 | */ |
| 291 | struct nss_ctx_instance *nss_ipv6_notify_register(nss_ipv6_msg_callback_t cb, void *app_data) |
| 292 | { |
| 293 | /* |
| 294 | * TODO: We need to have a new array in support of the new API |
| 295 | * TODO: If we use a per-context array, we would move the array into nss_ctx based. |
| 296 | */ |
| 297 | nss_top_main.ipv6_callback = cb; |
| 298 | nss_top_main.ipv6_ctx = app_data; |
| 299 | return &nss_top_main.nss[nss_top_main.ipv6_handler_id]; |
| 300 | } |
| 301 | |
| 302 | /* |
| 303 | * nss_ipv6_notify_unregister() |
| 304 | * Unregister to received IPv6 events. |
| 305 | * |
| 306 | * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv6 on any core? |
| 307 | */ |
| 308 | void nss_ipv6_notify_unregister(void) |
| 309 | { |
| 310 | nss_top_main.ipv6_callback = NULL; |
| 311 | } |
| 312 | |
| 313 | /* |
Suruchi Agarwal | 611ecd0 | 2016-08-04 15:54:35 -0700 | [diff] [blame^] | 314 | * nss_ipv6_conn_sync_many_notify_register() |
| 315 | * Register to receive IPv6 conn_sync_many message response. |
| 316 | */ |
| 317 | void nss_ipv6_conn_sync_many_notify_register(nss_ipv6_msg_callback_t cb) |
| 318 | { |
| 319 | nss_ipv6_conn_sync_many_msg_cb = cb; |
| 320 | } |
| 321 | |
| 322 | /* |
| 323 | * nss_ipv6_conn_sync_many_notify_unregister() |
| 324 | * Unregister to receive IPv6 conn_sync_many message response. |
| 325 | */ |
| 326 | void nss_ipv6_conn_sync_many_notify_unregister(void) |
| 327 | { |
| 328 | nss_ipv6_conn_sync_many_msg_cb = NULL; |
| 329 | } |
| 330 | |
| 331 | /* |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 332 | * nss_ipv6_get_mgr() |
| 333 | * |
| 334 | * TODO: This only suppports a single ipv6, do we ever want to support more? |
| 335 | */ |
| 336 | struct nss_ctx_instance *nss_ipv6_get_mgr(void) |
| 337 | { |
| 338 | return (void *)&nss_top_main.nss[nss_top_main.ipv6_handler_id]; |
| 339 | } |
| 340 | |
| 341 | /* |
| 342 | * nss_ipv6_register_handler() |
| 343 | * Register our handler to receive messages for this interface |
| 344 | */ |
| 345 | void nss_ipv6_register_handler() |
| 346 | { |
| 347 | if (nss_core_register_handler(NSS_IPV6_RX_INTERFACE, nss_ipv6_rx_msg_handler, NULL) != NSS_CORE_STATUS_SUCCESS) { |
| 348 | nss_warning("IPv6 handler failed to register"); |
| 349 | } |
| 350 | } |
| 351 | |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 352 | /* |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 353 | * nss_ipv6_conn_cfg_process() |
| 354 | * Process request to configure number of ipv6 connections |
| 355 | */ |
| 356 | static int nss_ipv6_conn_cfg_process(struct nss_ctx_instance *nss_ctx, int conn, |
| 357 | void (*cfg_cb)(void *app_data, struct nss_ipv6_msg *nim)) |
| 358 | { |
| 359 | struct nss_ipv6_msg nim; |
| 360 | struct nss_ipv6_rule_conn_cfg_msg *nirccm; |
| 361 | nss_tx_status_t nss_tx_status; |
| 362 | uint32_t sum_of_conn; |
| 363 | |
| 364 | /* |
| 365 | * Specifications for input |
| 366 | * 1) The input should be power of 2. |
| 367 | * 2) Input for ipv4 and ipv6 sum togther should not exceed 8k |
| 368 | * 3) Min. value should be at leat 256 connections. This is the |
| 369 | * minimum connections we will support for each of them. |
| 370 | */ |
| 371 | sum_of_conn = nss_ipv4_conn_cfg + conn; |
| 372 | if ((conn & NSS_NUM_CONN_QUANTA_MASK) || |
| 373 | (sum_of_conn > NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6) || |
| 374 | (conn < NSS_MIN_NUM_CONN)) { |
| 375 | nss_warning("%p: input supported connections (%d) does not adhere\ |
| 376 | specifications\n1) not power of 2,\n2) is less than \ |
| 377 | min val: %d, OR\n IPv4/6 total exceeds %d\n", |
| 378 | nss_ctx, |
| 379 | conn, |
| 380 | NSS_MIN_NUM_CONN, |
| 381 | NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6); |
| 382 | return -EINVAL; |
| 383 | } |
| 384 | |
| 385 | nss_info("%p: IPv6 supported connections: %d\n", nss_ctx, conn); |
| 386 | |
| 387 | memset(&nim, 0, sizeof(struct nss_ipv6_msg)); |
| 388 | nss_ipv6_msg_init(&nim, NSS_IPV6_RX_INTERFACE, NSS_IPV6_TX_CONN_CFG_RULE_MSG, |
| 389 | sizeof(struct nss_ipv6_rule_conn_cfg_msg), cfg_cb, NULL); |
| 390 | |
| 391 | nirccm = &nim.msg.rule_conn_cfg; |
| 392 | nirccm->num_conn = htonl(conn); |
| 393 | nss_tx_status = nss_ipv6_tx(nss_ctx, &nim); |
| 394 | |
| 395 | if (nss_tx_status != NSS_TX_SUCCESS) { |
| 396 | nss_warning("%p: nss_tx error setting IPv6 Connections: %d\n", |
| 397 | nss_ctx, |
| 398 | conn); |
| 399 | return -EIO; |
| 400 | } |
| 401 | |
| 402 | return 0; |
| 403 | } |
| 404 | |
| 405 | /* |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 406 | * nss_ipv6_conn_cfg_callback() |
| 407 | * call back function for the ipv6 connection configuration handler |
| 408 | */ |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 409 | static void nss_ipv6_conn_cfg_callback(void *app_data, struct nss_ipv6_msg *nim) |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 410 | { |
| 411 | if (nim->cm.response != NSS_CMN_RESPONSE_ACK) { |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 412 | /* |
Kiran Kumar C.S.K | fadf92d | 2015-06-26 12:48:33 +0530 | [diff] [blame] | 413 | * Error, hence we are not updating the nss_ipv6_conn_cfg |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 414 | * Restore the current_value to its previous state |
| 415 | */ |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 416 | i6cfgp.response = NSS_FAILURE; |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 417 | complete(&i6cfgp.complete); |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 418 | return; |
| 419 | } |
| 420 | |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 421 | /* |
Kiran Kumar C.S.K | fadf92d | 2015-06-26 12:48:33 +0530 | [diff] [blame] | 422 | * Sucess at NSS FW, hence updating nss_ipv6_conn_cfg, with the valid value |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 423 | * saved at the sysctl handler. |
| 424 | */ |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 425 | nss_info("IPv6 connection configuration success: %d\n", nim->cm.error); |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 426 | i6cfgp.response = NSS_SUCCESS; |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 427 | complete(&i6cfgp.complete); |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | |
| 431 | /* |
| 432 | * nss_ipv6_conn_cfg_handler() |
| 433 | * Sets the number of connections for IPv6 |
| 434 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 435 | static int nss_ipv6_conn_cfg_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos) |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 436 | { |
| 437 | struct nss_top_instance *nss_top = &nss_top_main; |
| 438 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[0]; |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 439 | int ret = NSS_FAILURE; |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 440 | |
| 441 | /* |
| 442 | * Acquiring semaphore |
| 443 | */ |
| 444 | down(&i6cfgp.sem); |
| 445 | |
| 446 | /* |
| 447 | * Take a snapshot of the current value |
| 448 | */ |
| 449 | i6cfgp.current_value = nss_ipv6_conn_cfg; |
| 450 | |
| 451 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 452 | if (ret || (!write)) { |
| 453 | up(&i6cfgp.sem); |
| 454 | return ret; |
| 455 | } |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 456 | |
| 457 | /* |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 458 | * Process request to change number of IPv6 connections |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 459 | */ |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 460 | ret = nss_ipv6_conn_cfg_process(nss_ctx, nss_ipv6_conn_cfg, nss_ipv6_conn_cfg_callback); |
| 461 | if (ret != 0) { |
Stephen Wang | 0676102 | 2015-03-03 16:38:42 -0800 | [diff] [blame] | 462 | goto failure; |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 463 | } |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 464 | |
| 465 | /* |
| 466 | * Blocking call, wait till we get ACK for this msg. |
| 467 | */ |
| 468 | ret = wait_for_completion_timeout(&i6cfgp.complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT)); |
| 469 | if (ret == 0) { |
| 470 | nss_warning("%p: Waiting for ack timed out\n", nss_ctx); |
Stephen Wang | 0676102 | 2015-03-03 16:38:42 -0800 | [diff] [blame] | 471 | goto failure; |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | /* |
| 475 | * ACK/NACK received from NSS FW |
Kiran Kumar C.S.K | fadf92d | 2015-06-26 12:48:33 +0530 | [diff] [blame] | 476 | * If ACK: Callback function will update nss_ipv6_conn_cfg with |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 477 | * i6cfgp.num_conn_valid, which holds the user input |
| 478 | */ |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 479 | if (NSS_FAILURE == i6cfgp.response) { |
Stephen Wang | 0676102 | 2015-03-03 16:38:42 -0800 | [diff] [blame] | 480 | goto failure; |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | up(&i6cfgp.sem); |
Thomas Wu | 651b390 | 2015-05-12 11:21:09 -0700 | [diff] [blame] | 484 | return 0; |
Stephen Wang | 0676102 | 2015-03-03 16:38:42 -0800 | [diff] [blame] | 485 | |
| 486 | failure: |
| 487 | /* |
| 488 | * Restore the current_value to its previous state |
| 489 | */ |
| 490 | nss_ipv6_conn_cfg = i6cfgp.current_value; |
| 491 | up(&i6cfgp.sem); |
Thomas Wu | 651b390 | 2015-05-12 11:21:09 -0700 | [diff] [blame] | 492 | return -EINVAL; |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 493 | } |
| 494 | |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 495 | /* |
| 496 | * nss_ipv6_update_conn_count_cb() |
| 497 | * call back function for the ipv6 connection count update handler |
| 498 | */ |
| 499 | static void nss_ipv6_update_conn_count_cb(void *app_data, struct nss_ipv6_msg *nim) |
| 500 | { |
| 501 | if (nim->cm.response != NSS_CMN_RESPONSE_ACK) { |
| 502 | nss_warning("IPv6 connection count update failed with error: %d\n", nim->cm.error); |
| 503 | return; |
| 504 | } |
| 505 | |
| 506 | nss_warning("IPv6 connection count update success: %d\n", nim->cm.error); |
| 507 | } |
| 508 | |
| 509 | /* |
| 510 | * nss_ipv6_update_conn_count() |
| 511 | * Sets the maximum number of connections for IPv6 |
| 512 | */ |
| 513 | int nss_ipv6_update_conn_count(int ipv6_num_conn) |
| 514 | { |
| 515 | struct nss_top_instance *nss_top = &nss_top_main; |
| 516 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[0]; |
| 517 | int saved_nss_ipv6_conn_cfg = nss_ipv6_conn_cfg; |
| 518 | int ret = 0; |
| 519 | |
| 520 | nss_ipv6_conn_cfg = ipv6_num_conn; |
| 521 | |
| 522 | /* |
| 523 | * Process request to change number of IPv6 connections |
| 524 | */ |
| 525 | ret = nss_ipv6_conn_cfg_process(nss_ctx, nss_ipv6_conn_cfg, nss_ipv6_update_conn_count_cb); |
| 526 | if (ret != 0) { |
| 527 | goto failure; |
| 528 | } |
| 529 | |
| 530 | return 0; |
| 531 | |
| 532 | failure: |
| 533 | nss_ipv6_conn_cfg = saved_nss_ipv6_conn_cfg; |
| 534 | return -EINVAL; |
| 535 | } |
| 536 | |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 537 | static struct ctl_table nss_ipv6_table[] = { |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 538 | { |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 539 | .procname = "ipv6_conn", |
| 540 | .data = &nss_ipv6_conn_cfg, |
| 541 | .maxlen = sizeof(int), |
| 542 | .mode = 0644, |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 543 | .proc_handler = &nss_ipv6_conn_cfg_handler, |
| 544 | }, |
| 545 | { } |
| 546 | }; |
| 547 | |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 548 | static struct ctl_table nss_ipv6_dir[] = { |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 549 | { |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 550 | .procname = "ipv6cfg", |
| 551 | .mode = 0555, |
| 552 | .child = nss_ipv6_table, |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 553 | }, |
| 554 | { } |
| 555 | }; |
| 556 | |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 557 | static struct ctl_table nss_ipv6_root_dir[] = { |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 558 | { |
| 559 | .procname = "nss", |
| 560 | .mode = 0555, |
| 561 | .child = nss_ipv6_dir, |
| 562 | }, |
| 563 | { } |
| 564 | }; |
| 565 | |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 566 | static struct ctl_table nss_ipv6_root[] = { |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 567 | { |
| 568 | .procname = "dev", |
| 569 | .mode = 0555, |
| 570 | .child = nss_ipv6_root_dir, |
| 571 | }, |
| 572 | { } |
| 573 | }; |
| 574 | |
| 575 | static struct ctl_table_header *nss_ipv6_header; |
| 576 | |
| 577 | /* |
| 578 | * nss_ipv6_register_sysctl() |
Kiran Kumar C.S.K | fadf92d | 2015-06-26 12:48:33 +0530 | [diff] [blame] | 579 | * Register sysctl specific to ipv6 |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 580 | */ |
| 581 | void nss_ipv6_register_sysctl(void) |
| 582 | { |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 583 | sema_init(&i6cfgp.sem, 1); |
| 584 | init_completion(&i6cfgp.complete); |
| 585 | i6cfgp.current_value = nss_ipv6_conn_cfg; |
| 586 | |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 587 | /* |
| 588 | * Register sysctl table. |
| 589 | */ |
| 590 | nss_ipv6_header = register_sysctl_table(nss_ipv6_root); |
| 591 | } |
| 592 | |
| 593 | /* |
| 594 | * nss_ipv6_unregister_sysctl() |
Kiran Kumar C.S.K | fadf92d | 2015-06-26 12:48:33 +0530 | [diff] [blame] | 595 | * Unregister sysctl specific to ipv6 |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 596 | */ |
| 597 | void nss_ipv6_unregister_sysctl(void) |
| 598 | { |
| 599 | /* |
| 600 | * Unregister sysctl table. |
| 601 | */ |
| 602 | if (nss_ipv6_header) { |
| 603 | unregister_sysctl_table(nss_ipv6_header); |
| 604 | } |
| 605 | } |
| 606 | |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 607 | /* |
| 608 | * nss_ipv6_msg_init() |
| 609 | * Initialize IPv6 message. |
| 610 | */ |
| 611 | void nss_ipv6_msg_init(struct nss_ipv6_msg *nim, uint16_t if_num, uint32_t type, uint32_t len, |
Sundarajan Srinivasan | 30a53d4 | 2015-01-30 10:52:08 -0800 | [diff] [blame] | 612 | nss_ipv6_msg_callback_t cb, void *app_data) |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 613 | { |
| 614 | nss_cmn_msg_init(&nim->cm, if_num, type, len, (void *)cb, app_data); |
| 615 | } |
| 616 | |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 617 | EXPORT_SYMBOL(nss_ipv6_tx); |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 618 | EXPORT_SYMBOL(nss_ipv6_tx_with_size); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 619 | EXPORT_SYMBOL(nss_ipv6_notify_register); |
| 620 | EXPORT_SYMBOL(nss_ipv6_notify_unregister); |
Suruchi Agarwal | 611ecd0 | 2016-08-04 15:54:35 -0700 | [diff] [blame^] | 621 | EXPORT_SYMBOL(nss_ipv6_conn_sync_many_notify_register); |
| 622 | EXPORT_SYMBOL(nss_ipv6_conn_sync_many_notify_unregister); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 623 | EXPORT_SYMBOL(nss_ipv6_get_mgr); |
| 624 | EXPORT_SYMBOL(nss_ipv6_register_handler); |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 625 | EXPORT_SYMBOL(nss_ipv6_register_sysctl); |
| 626 | EXPORT_SYMBOL(nss_ipv6_unregister_sysctl); |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 627 | EXPORT_SYMBOL(nss_ipv6_msg_init); |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 628 | EXPORT_SYMBOL(nss_ipv6_update_conn_count); |