Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, 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" |
Sakthi Vignesh Radhakrishnan | 8d02a2d | 2017-09-06 14:38:59 -0700 | [diff] [blame] | 22 | #include "nss_dscp_map.h" |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 23 | #include "nss_ipv6_stats.h" |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 24 | |
Sakthi Vignesh Radhakrishnan | 8d02a2d | 2017-09-06 14:38:59 -0700 | [diff] [blame] | 25 | #define NSS_IPV6_TX_MSG_TIMEOUT 1000 /* 1 sec timeout for IPv6 messages */ |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 26 | |
| 27 | /* |
| 28 | * Private data structure for ipv6 configure messages |
| 29 | */ |
| 30 | struct nss_ipv6_cfg_pvt { |
Sakthi Vignesh Radhakrishnan | 8d02a2d | 2017-09-06 14:38:59 -0700 | [diff] [blame] | 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_ipv6_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 | /* |
Sakthi Vignesh Radhakrishnan | 8d02a2d | 2017-09-06 14:38:59 -0700 | [diff] [blame] | 39 | * Private data structure for ipv6 connection information. |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 40 | */ |
| 41 | struct nss_ipv6_conn_table_info { |
| 42 | uint32_t ce_table_size; /* Size of connection entry table in NSS FW */ |
| 43 | uint32_t cme_table_size; /* Size of connection match entry table 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_ipv6_ct_info; |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 47 | |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 48 | int nss_ipv6_conn_cfg = NSS_DEFAULT_NUM_CONN; |
Stephen Wang | f6a9acb | 2017-08-23 10:35:39 -0700 | [diff] [blame] | 49 | int nss_ipv6_accel_mode_cfg __read_mostly = 1; |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 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 | |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -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_ipv6_msg_callback_t nss_ipv6_conn_sync_many_msg_cb = NULL; |
| 57 | |
| 58 | /* |
Sakthi Vignesh Radhakrishnan | 8d02a2d | 2017-09-06 14:38:59 -0700 | [diff] [blame] | 59 | * nss_ipv6_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_ipv6_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/ipv6cfg/ipv6_dscp_map\n\n"); |
| 66 | nss_info_always("dscp[0-63] action[0-%u] prio[0-%u]:\n\n", |
| 67 | NSS_IPV6_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 | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 72 | * nss_ipv6_rx_msg_handler() |
| 73 | * Handle NSS -> HLOS messages for IPv6 bridge/route |
| 74 | */ |
| 75 | static void nss_ipv6_rx_msg_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data) |
| 76 | { |
| 77 | struct nss_ipv6_msg *nim = (struct nss_ipv6_msg *)ncm; |
| 78 | nss_ipv6_msg_callback_t cb; |
| 79 | |
| 80 | BUG_ON(ncm->interface != NSS_IPV6_RX_INTERFACE); |
| 81 | |
| 82 | /* |
| 83 | * Is this a valid request/response packet? |
| 84 | */ |
Murat Sezgin | 5c8c736 | 2014-09-02 17:58:21 -0700 | [diff] [blame] | 85 | if (ncm->type >= NSS_IPV6_MAX_MSG_TYPES) { |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 86 | nss_warning("%p: received invalid message %d for IPv6 interface", nss_ctx, nim->cm.type); |
| 87 | return; |
| 88 | } |
| 89 | |
Suruchi Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 90 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_ipv6_msg)) { |
| 91 | 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] | 92 | return; |
| 93 | } |
| 94 | |
| 95 | /* |
Suruchi Agarwal | e3940e7 | 2016-07-06 15:56:51 -0700 | [diff] [blame] | 96 | * Trace messages. |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 97 | */ |
Suruchi Agarwal | e3940e7 | 2016-07-06 15:56:51 -0700 | [diff] [blame] | 98 | nss_ipv6_log_rx_msg(nim); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 99 | |
| 100 | /* |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 101 | * Handle deprecated messages. Eventually these messages should be removed. |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 102 | */ |
| 103 | switch (nim->cm.type) { |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 104 | case NSS_IPV6_RX_NODE_STATS_SYNC_MSG: |
| 105 | /* |
| 106 | * Update driver statistics on node sync. |
| 107 | */ |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 108 | nss_ipv6_stats_node_sync(nss_ctx, &nim->msg.node_stats); |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 109 | break; |
| 110 | |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 111 | case NSS_IPV6_RX_CONN_STATS_SYNC_MSG: |
| 112 | /* |
| 113 | * Update driver statistics on connection sync. |
| 114 | */ |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 115 | nss_ipv6_stats_conn_sync(nss_ctx, &nim->msg.conn_stats); |
Sakthi Vignesh Radhakrishnan | 515f8c2 | 2014-06-21 15:04:19 -0700 | [diff] [blame] | 116 | break; |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 117 | |
| 118 | case NSS_IPV6_TX_CONN_STATS_SYNC_MANY_MSG: |
| 119 | /* |
| 120 | * Update driver statistics on connection sync many. |
| 121 | */ |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 122 | nss_ipv6_stats_conn_sync_many(nss_ctx, &nim->msg.conn_stats_many); |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 123 | ncm->cb = (nss_ptr_t)nss_ipv6_conn_sync_many_msg_cb; |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 124 | break; |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 125 | } |
Abhishek Rastogi | 55f3945 | 2014-05-08 19:23:29 +0530 | [diff] [blame] | 126 | |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 127 | /* |
| 128 | * Update the callback and app_data for NOTIFY messages, IPv6 sends all notify messages |
| 129 | * to the same callback/app_data. |
| 130 | */ |
| 131 | if (nim->cm.response == NSS_CMM_RESPONSE_NOTIFY) { |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 132 | ncm->cb = (nss_ptr_t)nss_ctx->nss_top->ipv6_callback; |
| 133 | ncm->app_data = (nss_ptr_t)nss_ctx->nss_top->ipv6_ctx; |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | /* |
| 137 | * Do we have a callback? |
| 138 | */ |
| 139 | if (!ncm->cb) { |
| 140 | return; |
| 141 | } |
| 142 | |
| 143 | /* |
| 144 | * Callback |
| 145 | */ |
| 146 | cb = (nss_ipv6_msg_callback_t)ncm->cb; |
| 147 | cb((void *)ncm->app_data, nim); |
| 148 | } |
| 149 | |
| 150 | /* |
Sakthi Vignesh Radhakrishnan | 8d02a2d | 2017-09-06 14:38:59 -0700 | [diff] [blame] | 151 | * nss_ipv6_tx_sync_callback() |
| 152 | * Callback to handle the completion of synchronous tx messages. |
| 153 | */ |
| 154 | static void nss_ipv6_tx_sync_callback(void *app_data, struct nss_ipv6_msg *nim) |
| 155 | { |
| 156 | nss_ipv6_msg_callback_t callback = (nss_ipv6_msg_callback_t)nss_ipv6_pvt.cb; |
| 157 | void *data = nss_ipv6_pvt.app_data; |
| 158 | |
| 159 | nss_ipv6_pvt.cb = NULL; |
| 160 | nss_ipv6_pvt.app_data = NULL; |
| 161 | |
| 162 | if (nim->cm.response != NSS_CMN_RESPONSE_ACK) { |
| 163 | nss_warning("ipv6 error response %d\n", nim->cm.response); |
| 164 | nss_ipv6_pvt.response = NSS_TX_FAILURE; |
| 165 | } else { |
| 166 | nss_ipv6_pvt.response = NSS_TX_SUCCESS; |
| 167 | } |
| 168 | |
| 169 | if (callback) { |
| 170 | callback(data, nim); |
| 171 | } |
| 172 | |
| 173 | complete(&nss_ipv6_pvt.complete); |
| 174 | } |
| 175 | |
| 176 | /* |
| 177 | * nss_ipv6_dscp_action_get() |
| 178 | * Gets the action mapped to dscp. |
| 179 | */ |
| 180 | enum nss_ipv6_dscp_map_actions nss_ipv6_dscp_action_get(uint8_t dscp) |
| 181 | { |
Sakthi Vignesh Radhakrishnan | 1f7a66b | 2017-10-18 09:33:22 -0700 | [diff] [blame] | 182 | if (dscp >= NSS_DSCP_MAP_ARRAY_SIZE) { |
Sakthi Vignesh Radhakrishnan | 8d02a2d | 2017-09-06 14:38:59 -0700 | [diff] [blame] | 183 | nss_warning("dscp:%u invalid\n", dscp); |
| 184 | return NSS_IPV6_DSCP_MAP_ACTION_MAX; |
| 185 | } |
| 186 | |
| 187 | return mapping[dscp].action; |
| 188 | } |
| 189 | EXPORT_SYMBOL(nss_ipv6_dscp_action_get); |
| 190 | |
| 191 | /* |
| 192 | * nss_ipv6_max_conn_count() |
| 193 | * Return the maximum number of IPv6 connections that the NSS acceleration engine supports. |
| 194 | */ |
| 195 | int nss_ipv6_max_conn_count(void) |
| 196 | { |
| 197 | return nss_ipv6_conn_cfg; |
| 198 | } |
| 199 | EXPORT_SYMBOL(nss_ipv6_max_conn_count); |
| 200 | |
| 201 | /* |
| 202 | * nss_ipv6_conn_inquiry() |
| 203 | * Inquiry if a connection has been established in NSS FW |
| 204 | */ |
| 205 | nss_tx_status_t nss_ipv6_conn_inquiry(struct nss_ipv6_5tuple *ipv6_5t_p, |
| 206 | nss_ipv6_msg_callback_t cb) |
| 207 | { |
| 208 | nss_tx_status_t nss_tx_status; |
| 209 | struct nss_ipv6_msg nim; |
| 210 | struct nss_ctx_instance *nss_ctx = &nss_top_main.nss[0]; |
| 211 | |
| 212 | /* |
| 213 | * Initialize inquiry message structure. |
| 214 | * This is async message and the result will be returned |
| 215 | * to the caller by the msg_callback passed in. |
| 216 | */ |
| 217 | memset(&nim, 0, sizeof(nim)); |
| 218 | nss_ipv6_msg_init(&nim, NSS_IPV6_RX_INTERFACE, |
| 219 | NSS_IPV6_TX_CONN_CFG_INQUIRY_MSG, |
| 220 | sizeof(struct nss_ipv6_inquiry_msg), |
| 221 | cb, NULL); |
| 222 | nim.msg.inquiry.rr.tuple = *ipv6_5t_p; |
| 223 | nss_tx_status = nss_ipv6_tx(nss_ctx, &nim); |
| 224 | if (nss_tx_status != NSS_TX_SUCCESS) { |
| 225 | nss_warning("%p: Send inquiry message failed\n", ipv6_5t_p); |
| 226 | } |
| 227 | |
| 228 | return nss_tx_status; |
| 229 | } |
| 230 | EXPORT_SYMBOL(nss_ipv6_conn_inquiry); |
| 231 | |
| 232 | /* |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 233 | * nss_ipv6_tx_with_size() |
| 234 | * Transmit an ipv6 message to the FW with a specified size. |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 235 | */ |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 236 | 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] | 237 | { |
| 238 | struct nss_ipv6_msg *nim2; |
| 239 | struct nss_cmn_msg *ncm = &nim->cm; |
| 240 | struct sk_buff *nbuf; |
| 241 | int32_t status; |
| 242 | |
| 243 | NSS_VERIFY_CTX_MAGIC(nss_ctx); |
| 244 | if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) { |
| 245 | nss_warning("%p: ipv6 msg dropped as core not ready", nss_ctx); |
| 246 | return NSS_TX_FAILURE_NOT_READY; |
| 247 | } |
| 248 | |
| 249 | /* |
| 250 | * Sanity check the message |
| 251 | */ |
| 252 | if (ncm->interface != NSS_IPV6_RX_INTERFACE) { |
| 253 | nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface); |
| 254 | return NSS_TX_FAILURE; |
| 255 | } |
| 256 | |
Murat Sezgin | 5c8c736 | 2014-09-02 17:58:21 -0700 | [diff] [blame] | 257 | if (ncm->type >= NSS_IPV6_MAX_MSG_TYPES) { |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 258 | nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type); |
| 259 | return NSS_TX_FAILURE; |
| 260 | } |
| 261 | |
Suruchi Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 262 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_ipv6_msg)) { |
| 263 | 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] | 264 | return NSS_TX_FAILURE; |
| 265 | } |
| 266 | |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 267 | if(size > PAGE_SIZE) { |
| 268 | nss_warning("%p: tx request size too large: %u", nss_ctx, size); |
| 269 | return NSS_TX_FAILURE; |
| 270 | } |
| 271 | |
| 272 | nbuf = dev_alloc_skb(size); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 273 | if (unlikely(!nbuf)) { |
Sundarajan Srinivasan | 62fee7e | 2015-01-22 11:13:10 -0800 | [diff] [blame] | 274 | 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] | 275 | nss_warning("%p: msg dropped as command allocation failed", nss_ctx); |
| 276 | return NSS_TX_FAILURE; |
| 277 | } |
| 278 | |
| 279 | /* |
| 280 | * Copy the message to our skb. |
| 281 | */ |
Suruchi Agarwal | ea2e523 | 2016-09-14 10:32:08 -0700 | [diff] [blame] | 282 | nim2 = (struct nss_ipv6_msg *)skb_put(nbuf, size); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 283 | memcpy(nim2, nim, sizeof(struct nss_ipv6_msg)); |
| 284 | |
Suruchi Agarwal | e3940e7 | 2016-07-06 15:56:51 -0700 | [diff] [blame] | 285 | /* |
| 286 | * Trace messages. |
| 287 | */ |
| 288 | nss_ipv6_log_tx_msg(nim); |
| 289 | |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 290 | status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0); |
| 291 | if (status != NSS_CORE_STATUS_SUCCESS) { |
Pamidipati, Vijay | b6e3884 | 2014-09-16 10:26:05 +0530 | [diff] [blame] | 292 | dev_kfree_skb_any(nbuf); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 293 | nss_warning("%p: Unable to enqueue 'Destroy IPv6' rule\n", nss_ctx); |
| 294 | return NSS_TX_FAILURE; |
| 295 | } |
| 296 | |
Stephen Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 297 | nss_hal_send_interrupt(nss_ctx, NSS_H2N_INTR_DATA_COMMAND_QUEUE); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 298 | |
| 299 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]); |
| 300 | return NSS_TX_SUCCESS; |
| 301 | } |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 302 | EXPORT_SYMBOL(nss_ipv6_tx_with_size); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 303 | |
| 304 | /* |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 305 | * nss_ipv6_tx() |
Suruchi Agarwal | 611ecd0 | 2016-08-04 15:54:35 -0700 | [diff] [blame] | 306 | * Transmit an ipv6 message to the FW. |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 307 | */ |
| 308 | nss_tx_status_t nss_ipv6_tx(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_msg *nim) |
| 309 | { |
| 310 | return nss_ipv6_tx_with_size(nss_ctx, nim, NSS_NBUF_PAYLOAD_SIZE); |
| 311 | } |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 312 | EXPORT_SYMBOL(nss_ipv6_tx); |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 313 | |
| 314 | /* |
Sakthi Vignesh Radhakrishnan | 8d02a2d | 2017-09-06 14:38:59 -0700 | [diff] [blame] | 315 | * nss_ipv6_tx_sync() |
| 316 | * Transmit a synchronous ipv6 message to the FW. |
| 317 | */ |
| 318 | nss_tx_status_t nss_ipv6_tx_sync(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_msg *nim) |
| 319 | { |
| 320 | nss_tx_status_t status; |
| 321 | int ret = 0; |
| 322 | |
| 323 | down(&nss_ipv6_pvt.sem); |
| 324 | nss_ipv6_pvt.cb = (void *)nim->cm.cb; |
| 325 | nss_ipv6_pvt.app_data = (void *)nim->cm.app_data; |
| 326 | |
| 327 | nim->cm.cb = (nss_ptr_t)nss_ipv6_tx_sync_callback; |
| 328 | nim->cm.app_data = (nss_ptr_t)NULL; |
| 329 | |
| 330 | status = nss_ipv6_tx(nss_ctx, nim); |
| 331 | if (status != NSS_TX_SUCCESS) { |
| 332 | nss_warning("%p: nss ipv6 msg tx failed\n", nss_ctx); |
| 333 | up(&nss_ipv6_pvt.sem); |
| 334 | return status; |
| 335 | } |
| 336 | |
| 337 | ret = wait_for_completion_timeout(&nss_ipv6_pvt.complete, msecs_to_jiffies(NSS_IPV6_TX_MSG_TIMEOUT)); |
| 338 | if (!ret) { |
| 339 | nss_warning("%p: IPv6 tx sync failed due to timeout\n", nss_ctx); |
| 340 | nss_ipv6_pvt.response = NSS_TX_FAILURE; |
| 341 | } |
| 342 | |
| 343 | status = nss_ipv6_pvt.response; |
| 344 | up(&nss_ipv6_pvt.sem); |
| 345 | return status; |
| 346 | } |
| 347 | EXPORT_SYMBOL(nss_ipv6_tx_sync); |
| 348 | |
| 349 | /* |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 350 | ********************************** |
| 351 | Register/Unregister/Miscellaneous APIs |
| 352 | ********************************** |
| 353 | */ |
| 354 | |
| 355 | /* |
| 356 | * nss_ipv6_notify_register() |
| 357 | * Register to received IPv6 events. |
| 358 | * |
| 359 | * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv6 on any core? |
| 360 | */ |
| 361 | struct nss_ctx_instance *nss_ipv6_notify_register(nss_ipv6_msg_callback_t cb, void *app_data) |
| 362 | { |
| 363 | /* |
| 364 | * TODO: We need to have a new array in support of the new API |
| 365 | * TODO: If we use a per-context array, we would move the array into nss_ctx based. |
| 366 | */ |
| 367 | nss_top_main.ipv6_callback = cb; |
| 368 | nss_top_main.ipv6_ctx = app_data; |
| 369 | return &nss_top_main.nss[nss_top_main.ipv6_handler_id]; |
| 370 | } |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 371 | EXPORT_SYMBOL(nss_ipv6_notify_register); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 372 | |
| 373 | /* |
| 374 | * nss_ipv6_notify_unregister() |
| 375 | * Unregister to received IPv6 events. |
| 376 | * |
| 377 | * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv6 on any core? |
| 378 | */ |
| 379 | void nss_ipv6_notify_unregister(void) |
| 380 | { |
| 381 | nss_top_main.ipv6_callback = NULL; |
| 382 | } |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 383 | EXPORT_SYMBOL(nss_ipv6_notify_unregister); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 384 | |
| 385 | /* |
Suruchi Agarwal | 611ecd0 | 2016-08-04 15:54:35 -0700 | [diff] [blame] | 386 | * nss_ipv6_conn_sync_many_notify_register() |
| 387 | * Register to receive IPv6 conn_sync_many message response. |
| 388 | */ |
| 389 | void nss_ipv6_conn_sync_many_notify_register(nss_ipv6_msg_callback_t cb) |
| 390 | { |
| 391 | nss_ipv6_conn_sync_many_msg_cb = cb; |
| 392 | } |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 393 | EXPORT_SYMBOL(nss_ipv6_conn_sync_many_notify_register); |
Suruchi Agarwal | 611ecd0 | 2016-08-04 15:54:35 -0700 | [diff] [blame] | 394 | |
| 395 | /* |
| 396 | * nss_ipv6_conn_sync_many_notify_unregister() |
| 397 | * Unregister to receive IPv6 conn_sync_many message response. |
| 398 | */ |
| 399 | void nss_ipv6_conn_sync_many_notify_unregister(void) |
| 400 | { |
| 401 | nss_ipv6_conn_sync_many_msg_cb = NULL; |
| 402 | } |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 403 | EXPORT_SYMBOL(nss_ipv6_conn_sync_many_notify_unregister); |
Suruchi Agarwal | 611ecd0 | 2016-08-04 15:54:35 -0700 | [diff] [blame] | 404 | |
| 405 | /* |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 406 | * nss_ipv6_get_mgr() |
| 407 | * |
| 408 | * TODO: This only suppports a single ipv6, do we ever want to support more? |
| 409 | */ |
| 410 | struct nss_ctx_instance *nss_ipv6_get_mgr(void) |
| 411 | { |
| 412 | return (void *)&nss_top_main.nss[nss_top_main.ipv6_handler_id]; |
| 413 | } |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 414 | EXPORT_SYMBOL(nss_ipv6_get_mgr); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 415 | |
| 416 | /* |
| 417 | * nss_ipv6_register_handler() |
| 418 | * Register our handler to receive messages for this interface |
| 419 | */ |
| 420 | void nss_ipv6_register_handler() |
| 421 | { |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 422 | struct nss_ctx_instance *nss_ctx = nss_ipv6_get_mgr(); |
| 423 | |
| 424 | if (nss_core_register_handler(nss_ctx, NSS_IPV6_RX_INTERFACE, nss_ipv6_rx_msg_handler, NULL) != NSS_CORE_STATUS_SUCCESS) { |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 425 | nss_warning("IPv6 handler failed to register"); |
| 426 | } |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 427 | |
| 428 | nss_ipv6_stats_dentry_create(); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 429 | } |
| 430 | |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 431 | /* |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 432 | * nss_ipv6_conn_cfg_process_callback() |
| 433 | * Call back function for the ipv6 connection configuration process. |
| 434 | */ |
| 435 | static void nss_ipv6_conn_cfg_process_callback(void *app_data, struct nss_ipv6_msg *nim) |
| 436 | { |
| 437 | struct nss_ipv6_rule_conn_cfg_msg *nirccm = &nim->msg.rule_conn_cfg; |
| 438 | struct nss_ctx_instance *nss_ctx __maybe_unused = nss_ipv6_get_mgr(); |
| 439 | |
| 440 | if (nim->cm.response != NSS_CMN_RESPONSE_ACK) { |
| 441 | nss_warning("%p: IPv6 connection configuration failed with error: %d\n", nss_ctx, nim->cm.error); |
Stephen Wang | 0143369 | 2017-10-30 14:45:11 -0700 | [diff] [blame] | 442 | nss_core_update_max_ipv6_conn(NSS_FW_DEFAULT_NUM_CONN); |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 443 | nss_ipv6_free_conn_tables(); |
| 444 | return; |
| 445 | } |
| 446 | |
| 447 | nss_ipv6_conn_cfg = ntohl(nirccm->num_conn); |
| 448 | |
| 449 | nss_warning("%p: IPv6 connection configuration success: %d\n", nss_ctx, nim->cm.error); |
| 450 | } |
| 451 | |
| 452 | /* |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 453 | * nss_ipv6_conn_cfg_process() |
| 454 | * Process request to configure number of ipv6 connections |
| 455 | */ |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 456 | static int nss_ipv6_conn_cfg_process(struct nss_ctx_instance *nss_ctx, int conn) |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 457 | { |
| 458 | struct nss_ipv6_msg nim; |
| 459 | struct nss_ipv6_rule_conn_cfg_msg *nirccm; |
| 460 | nss_tx_status_t nss_tx_status; |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 461 | |
| 462 | if ((!nss_ipv6_ct_info.ce_table_size) || (!nss_ipv6_ct_info.cme_table_size)) { |
| 463 | nss_warning("%p: connection entry or connection match entry table size not available\n", |
| 464 | nss_ctx); |
| 465 | return -EINVAL; |
| 466 | } |
| 467 | |
| 468 | nss_info("%p: IPv6 supported connections: %d\n", nss_ctx, conn); |
| 469 | |
| 470 | nss_ipv6_ct_info.ce_mem = __get_free_pages(GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO, |
| 471 | get_order(nss_ipv6_ct_info.ce_table_size)); |
| 472 | if (!nss_ipv6_ct_info.ce_mem) { |
| 473 | nss_warning("%p: Memory allocation failed for IPv6 Connections: %d\n", |
| 474 | nss_ctx, |
| 475 | conn); |
| 476 | goto fail; |
| 477 | } |
| 478 | nss_warning("%p: CE Memory allocated for IPv6 Connections: %d\n", |
| 479 | nss_ctx, |
| 480 | conn); |
| 481 | |
| 482 | nss_ipv6_ct_info.cme_mem = __get_free_pages(GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO, |
| 483 | get_order(nss_ipv6_ct_info.cme_table_size)); |
| 484 | if (!nss_ipv6_ct_info.cme_mem) { |
| 485 | nss_warning("%p: Memory allocation failed for IPv6 Connections: %d\n", |
| 486 | nss_ctx, |
| 487 | conn); |
| 488 | goto fail; |
| 489 | } |
| 490 | nss_warning("%p: CME Memory allocated for IPv6 Connections: %d\n", |
| 491 | nss_ctx, |
| 492 | conn); |
| 493 | |
| 494 | memset(&nim, 0, sizeof(struct nss_ipv6_msg)); |
| 495 | nss_ipv6_msg_init(&nim, NSS_IPV6_RX_INTERFACE, NSS_IPV6_TX_CONN_CFG_RULE_MSG, |
| 496 | sizeof(struct nss_ipv6_rule_conn_cfg_msg), nss_ipv6_conn_cfg_process_callback, NULL); |
| 497 | |
| 498 | nirccm = &nim.msg.rule_conn_cfg; |
| 499 | nirccm->num_conn = htonl(conn); |
Suruchi Agarwal | 8c9e716 | 2017-08-17 15:58:40 -0700 | [diff] [blame] | 500 | nirccm->ce_mem = dma_map_single(nss_ctx->dev, (void *)nss_ipv6_ct_info.ce_mem, nss_ipv6_ct_info.ce_table_size, DMA_TO_DEVICE); |
| 501 | if (unlikely(dma_mapping_error(nss_ctx->dev, nirccm->ce_mem))) { |
| 502 | nss_warning("%p: DMA mapping failed for virtual address = %p", nss_ctx, (void *)nss_ipv6_ct_info.ce_mem); |
| 503 | goto fail; |
| 504 | } |
| 505 | |
| 506 | nirccm->cme_mem = dma_map_single(nss_ctx->dev, (void *)nss_ipv6_ct_info.cme_mem, nss_ipv6_ct_info.cme_table_size, DMA_TO_DEVICE); |
| 507 | if (unlikely(dma_mapping_error(nss_ctx->dev, nirccm->cme_mem))) { |
| 508 | nss_warning("%p: DMA mapping failed for virtual address = %p", nss_ctx, (void *)nss_ipv6_ct_info.cme_mem); |
| 509 | goto fail; |
| 510 | } |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 511 | |
| 512 | nss_tx_status = nss_ipv6_tx(nss_ctx, &nim); |
| 513 | if (nss_tx_status != NSS_TX_SUCCESS) { |
| 514 | nss_warning("%p: nss_tx error setting IPv6 Connections: %d\n", |
| 515 | nss_ctx, |
| 516 | conn); |
| 517 | goto fail; |
| 518 | } |
| 519 | |
| 520 | return 0; |
| 521 | |
| 522 | fail: |
| 523 | nss_ipv6_free_conn_tables(); |
| 524 | return -EINVAL; |
| 525 | } |
| 526 | |
| 527 | /* |
| 528 | * nss_ipv6_update_conn_count_callback() |
| 529 | * Call back function for the ipv6 get connection info message. |
| 530 | */ |
| 531 | static void nss_ipv6_update_conn_count_callback(void *app_data, struct nss_ipv6_msg *nim) |
| 532 | { |
| 533 | struct nss_ipv6_rule_conn_get_table_size_msg *nircgts = &nim->msg.size; |
| 534 | struct nss_ctx_instance *nss_ctx = nss_ipv6_get_mgr(); |
| 535 | |
| 536 | if (nim->cm.response != NSS_CMN_RESPONSE_ACK) { |
| 537 | nss_warning("%p: IPv6 fetch connection info failed with error: %d\n", nss_ctx, nim->cm.error); |
Stephen Wang | 0143369 | 2017-10-30 14:45:11 -0700 | [diff] [blame] | 538 | nss_core_update_max_ipv6_conn(NSS_FW_DEFAULT_NUM_CONN); |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 539 | return; |
| 540 | } |
| 541 | |
| 542 | nss_info("IPv6 get connection info success\n"); |
| 543 | |
| 544 | nss_ipv6_ct_info.ce_table_size = ntohl(nircgts->ce_table_size); |
| 545 | nss_ipv6_ct_info.cme_table_size = ntohl(nircgts->cme_table_size); |
| 546 | |
| 547 | if (nss_ipv6_conn_cfg_process(nss_ctx, ntohl(nircgts->num_conn)) != 0) { |
| 548 | nss_warning("%p: IPv6 connection entry or connection match entry table size\ |
| 549 | not available\n", nss_ctx); |
| 550 | } |
| 551 | |
| 552 | return; |
| 553 | } |
| 554 | |
| 555 | /* |
| 556 | * nss_ipv6_update_conn_count() |
| 557 | * Sets the maximum number of IPv6 connections. |
| 558 | * |
| 559 | * It first gets the connection tables size information from NSS FW |
| 560 | * and then configures the connections in NSS FW. |
| 561 | */ |
| 562 | int nss_ipv6_update_conn_count(int ipv6_num_conn) |
| 563 | { |
| 564 | struct nss_ctx_instance *nss_ctx = nss_ipv6_get_mgr(); |
| 565 | struct nss_ipv6_msg nim; |
| 566 | struct nss_ipv6_rule_conn_get_table_size_msg *nircgts; |
| 567 | nss_tx_status_t nss_tx_status; |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 568 | uint32_t sum_of_conn; |
| 569 | |
| 570 | /* |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 571 | * By default, NSS FW is configured with default number of connections. |
| 572 | */ |
Stephen Wang | 0143369 | 2017-10-30 14:45:11 -0700 | [diff] [blame] | 573 | if (ipv6_num_conn == NSS_FW_DEFAULT_NUM_CONN) { |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 574 | nss_info("%p: Default number of connections (%d) already configured\n", nss_ctx, ipv6_num_conn); |
| 575 | return 0; |
| 576 | } |
| 577 | |
| 578 | /* |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 579 | * Specifications for input |
| 580 | * 1) The input should be power of 2. |
| 581 | * 2) Input for ipv4 and ipv6 sum togther should not exceed 8k |
| 582 | * 3) Min. value should be at leat 256 connections. This is the |
| 583 | * minimum connections we will support for each of them. |
| 584 | */ |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 585 | sum_of_conn = nss_ipv4_conn_cfg + ipv6_num_conn; |
| 586 | if ((ipv6_num_conn & NSS_NUM_CONN_QUANTA_MASK) || |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 587 | (sum_of_conn > NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6) || |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 588 | (ipv6_num_conn < NSS_MIN_NUM_CONN)) { |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 589 | nss_warning("%p: input supported connections (%d) does not adhere\ |
| 590 | specifications\n1) not power of 2,\n2) is less than \ |
| 591 | min val: %d, OR\n IPv4/6 total exceeds %d\n", |
| 592 | nss_ctx, |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 593 | ipv6_num_conn, |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 594 | NSS_MIN_NUM_CONN, |
| 595 | NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6); |
| 596 | return -EINVAL; |
| 597 | } |
| 598 | |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 599 | memset(&nim, 0, sizeof(struct nss_ipv6_msg)); |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 600 | nss_ipv6_msg_init(&nim, NSS_IPV6_RX_INTERFACE, NSS_IPV6_TX_CONN_TABLE_SIZE_MSG, |
| 601 | sizeof(struct nss_ipv6_rule_conn_get_table_size_msg), nss_ipv6_update_conn_count_callback, NULL); |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 602 | |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 603 | nircgts = &nim.msg.size; |
| 604 | nircgts->num_conn = htonl(ipv6_num_conn); |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 605 | nss_tx_status = nss_ipv6_tx(nss_ctx, &nim); |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 606 | if (nss_tx_status != NSS_TX_SUCCESS) { |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 607 | nss_warning("%p: Send acceleration mode message failed\n", nss_ctx); |
| 608 | return -EINVAL; |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | return 0; |
| 612 | } |
| 613 | |
| 614 | /* |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 615 | * nss_ipv6_free_conn_tables() |
| 616 | * Frees memory allocated for connection tables |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 617 | */ |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 618 | void nss_ipv6_free_conn_tables(void) |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 619 | { |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 620 | if (nss_ipv6_ct_info.ce_mem) { |
| 621 | free_pages(nss_ipv6_ct_info.ce_mem, get_order(nss_ipv6_ct_info.ce_table_size)); |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 622 | } |
| 623 | |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 624 | if (nss_ipv6_ct_info.cme_mem) { |
| 625 | free_pages(nss_ipv6_ct_info.cme_mem, get_order(nss_ipv6_ct_info.cme_table_size)); |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 626 | } |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 627 | |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 628 | memset(&nss_ipv6_ct_info, 0, sizeof(struct nss_ipv6_conn_table_info)); |
| 629 | return; |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 630 | } |
| 631 | |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 632 | /* |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 633 | * nss_ipv6_accel_mode_cfg_handler() |
| 634 | * Configure acceleration mode for IPv6 |
| 635 | */ |
| 636 | static int nss_ipv6_accel_mode_cfg_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos) |
| 637 | { |
| 638 | struct nss_top_instance *nss_top = &nss_top_main; |
| 639 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[0]; |
| 640 | struct nss_ipv6_msg nim; |
| 641 | struct nss_ipv6_accel_mode_cfg_msg *nipcm; |
| 642 | nss_tx_status_t nss_tx_status; |
| 643 | int ret = NSS_FAILURE; |
Sakthi Vignesh Radhakrishnan | 8d02a2d | 2017-09-06 14:38:59 -0700 | [diff] [blame] | 644 | int current_value; |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 645 | |
| 646 | /* |
| 647 | * Take snap shot of current value |
| 648 | */ |
Sakthi Vignesh Radhakrishnan | 8d02a2d | 2017-09-06 14:38:59 -0700 | [diff] [blame] | 649 | current_value = nss_ipv6_accel_mode_cfg; |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 650 | |
| 651 | /* |
| 652 | * Write the variable with user input |
| 653 | */ |
| 654 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 655 | if (ret || (!write)) { |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 656 | return ret; |
| 657 | } |
| 658 | |
| 659 | memset(&nim, 0, sizeof(struct nss_ipv6_msg)); |
| 660 | nss_ipv6_msg_init(&nim, NSS_IPV6_RX_INTERFACE, NSS_IPV6_TX_ACCEL_MODE_CFG_MSG, |
Sakthi Vignesh Radhakrishnan | 8d02a2d | 2017-09-06 14:38:59 -0700 | [diff] [blame] | 661 | sizeof(struct nss_ipv6_accel_mode_cfg_msg), NULL, NULL); |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 662 | |
| 663 | nipcm = &nim.msg.accel_mode_cfg; |
| 664 | nipcm->mode = htonl(nss_ipv6_accel_mode_cfg); |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 665 | |
Sakthi Vignesh Radhakrishnan | 8d02a2d | 2017-09-06 14:38:59 -0700 | [diff] [blame] | 666 | nss_tx_status = nss_ipv6_tx_sync(nss_ctx, &nim); |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 667 | if (nss_tx_status != NSS_TX_SUCCESS) { |
| 668 | nss_warning("%p: Send acceleration mode message failed\n", nss_ctx); |
Sakthi Vignesh Radhakrishnan | 8d02a2d | 2017-09-06 14:38:59 -0700 | [diff] [blame] | 669 | nss_ipv6_accel_mode_cfg = current_value; |
| 670 | return -EIO; |
| 671 | } |
| 672 | |
| 673 | return 0; |
| 674 | } |
| 675 | |
| 676 | /* |
| 677 | * nss_ipv6_dscp_map_cfg_handler() |
| 678 | * Sysctl handler for dscp/pri mappings. |
| 679 | */ |
| 680 | static int nss_ipv6_dscp_map_cfg_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos) |
| 681 | { |
| 682 | struct nss_top_instance *nss_top = &nss_top_main; |
| 683 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[0]; |
| 684 | struct nss_dscp_map_parse out; |
| 685 | struct nss_ipv6_msg nim; |
| 686 | struct nss_ipv6_dscp2pri_cfg_msg *nipd2p; |
| 687 | nss_tx_status_t status; |
| 688 | int ret; |
| 689 | |
| 690 | if (!write) { |
| 691 | return nss_dscp_map_print(ctl, buffer, lenp, ppos, mapping); |
| 692 | } |
| 693 | |
| 694 | ret = nss_dscp_map_parse(ctl, buffer, lenp, ppos, &out); |
| 695 | if (ret) { |
| 696 | nss_warning("failed to parse dscp mapping:%d\n", ret); |
| 697 | return ret; |
| 698 | } |
| 699 | |
| 700 | if (out.action >= NSS_IPV6_DSCP_MAP_ACTION_MAX) { |
| 701 | nss_warning("invalid action value: %d\n", out.action); |
| 702 | nss_ipv6_dscp_map_usage(); |
| 703 | return -EINVAL; |
| 704 | } |
| 705 | |
| 706 | memset(&nim, 0, sizeof(struct nss_ipv6_msg)); |
| 707 | nss_ipv6_msg_init(&nim, NSS_IPV6_RX_INTERFACE, NSS_IPV6_TX_DSCP2PRI_CFG_MSG, |
| 708 | sizeof(struct nss_ipv6_dscp2pri_cfg_msg), NULL, NULL); |
| 709 | |
| 710 | nipd2p = &nim.msg.dscp2pri_cfg; |
| 711 | nipd2p->dscp = out.dscp; |
| 712 | nipd2p->priority = out.priority; |
| 713 | |
| 714 | status = nss_ipv6_tx_sync(nss_ctx, &nim); |
| 715 | if (status != NSS_TX_SUCCESS) { |
| 716 | nss_warning("%p: ipv6 dscp2pri config message failed\n", nss_ctx); |
| 717 | return -EFAULT; |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | /* |
Sakthi Vignesh Radhakrishnan | 8d02a2d | 2017-09-06 14:38:59 -0700 | [diff] [blame] | 721 | * NSS firmware acknowleged the configuration, so update the mapping |
| 722 | * table on HOST side as well. |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 723 | */ |
Sakthi Vignesh Radhakrishnan | 8d02a2d | 2017-09-06 14:38:59 -0700 | [diff] [blame] | 724 | mapping[out.dscp].action = out.action; |
| 725 | mapping[out.dscp].priority = out.priority; |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 726 | |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 727 | return 0; |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 728 | } |
| 729 | |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 730 | static struct ctl_table nss_ipv6_table[] = { |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 731 | { |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 732 | .procname = "ipv6_accel_mode", |
| 733 | .data = &nss_ipv6_accel_mode_cfg, |
| 734 | .maxlen = sizeof(int), |
| 735 | .mode = 0644, |
| 736 | .proc_handler = &nss_ipv6_accel_mode_cfg_handler, |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 737 | }, |
Sakthi Vignesh Radhakrishnan | 8d02a2d | 2017-09-06 14:38:59 -0700 | [diff] [blame] | 738 | { |
| 739 | .procname = "ipv6_dscp_map", |
| 740 | .data = &mapping[NSS_DSCP_MAP_ARRAY_SIZE], |
| 741 | .maxlen = sizeof(struct nss_dscp_map_entry), |
| 742 | .mode = 0644, |
| 743 | .proc_handler = &nss_ipv6_dscp_map_cfg_handler, |
| 744 | }, |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 745 | { } |
| 746 | }; |
| 747 | |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 748 | static struct ctl_table nss_ipv6_dir[] = { |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 749 | { |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 750 | .procname = "ipv6cfg", |
| 751 | .mode = 0555, |
| 752 | .child = nss_ipv6_table, |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 753 | }, |
| 754 | { } |
| 755 | }; |
| 756 | |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 757 | static struct ctl_table nss_ipv6_root_dir[] = { |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 758 | { |
| 759 | .procname = "nss", |
| 760 | .mode = 0555, |
| 761 | .child = nss_ipv6_dir, |
| 762 | }, |
| 763 | { } |
| 764 | }; |
| 765 | |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 766 | static struct ctl_table nss_ipv6_root[] = { |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 767 | { |
| 768 | .procname = "dev", |
| 769 | .mode = 0555, |
| 770 | .child = nss_ipv6_root_dir, |
| 771 | }, |
| 772 | { } |
| 773 | }; |
| 774 | |
| 775 | static struct ctl_table_header *nss_ipv6_header; |
| 776 | |
| 777 | /* |
| 778 | * nss_ipv6_register_sysctl() |
Kiran Kumar C.S.K | fadf92d | 2015-06-26 12:48:33 +0530 | [diff] [blame] | 779 | * Register sysctl specific to ipv6 |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 780 | */ |
| 781 | void nss_ipv6_register_sysctl(void) |
| 782 | { |
Sakthi Vignesh Radhakrishnan | 8d02a2d | 2017-09-06 14:38:59 -0700 | [diff] [blame] | 783 | sema_init(&nss_ipv6_pvt.sem, 1); |
| 784 | init_completion(&nss_ipv6_pvt.complete); |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 785 | |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 786 | /* |
| 787 | * Register sysctl table. |
| 788 | */ |
| 789 | nss_ipv6_header = register_sysctl_table(nss_ipv6_root); |
| 790 | } |
| 791 | |
| 792 | /* |
| 793 | * nss_ipv6_unregister_sysctl() |
Kiran Kumar C.S.K | fadf92d | 2015-06-26 12:48:33 +0530 | [diff] [blame] | 794 | * Unregister sysctl specific to ipv6 |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 795 | */ |
| 796 | void nss_ipv6_unregister_sysctl(void) |
| 797 | { |
| 798 | /* |
| 799 | * Unregister sysctl table. |
| 800 | */ |
| 801 | if (nss_ipv6_header) { |
| 802 | unregister_sysctl_table(nss_ipv6_header); |
| 803 | } |
| 804 | } |
| 805 | |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 806 | /* |
| 807 | * nss_ipv6_msg_init() |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 808 | * Initialize IPv6 message. |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 809 | */ |
| 810 | 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] | 811 | nss_ipv6_msg_callback_t cb, void *app_data) |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 812 | { |
| 813 | nss_cmn_msg_init(&nim->cm, if_num, type, len, (void *)cb, app_data); |
| 814 | } |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 815 | EXPORT_SYMBOL(nss_ipv6_msg_init); |