Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Stephen Wang | 3e2dbd1 | 2018-03-14 17:28:17 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2018, 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 | */ |
Suruchi Agarwal | e4ad24a | 2018-06-11 12:03:46 +0530 | [diff] [blame^] | 131 | if (nim->cm.response == NSS_CMN_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 | { |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 238 | struct nss_cmn_msg *ncm = &nim->cm; |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 239 | |
| 240 | /* |
| 241 | * Sanity check the message |
| 242 | */ |
| 243 | if (ncm->interface != NSS_IPV6_RX_INTERFACE) { |
| 244 | nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface); |
| 245 | return NSS_TX_FAILURE; |
| 246 | } |
| 247 | |
Murat Sezgin | 5c8c736 | 2014-09-02 17:58:21 -0700 | [diff] [blame] | 248 | if (ncm->type >= NSS_IPV6_MAX_MSG_TYPES) { |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 249 | nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type); |
| 250 | return NSS_TX_FAILURE; |
| 251 | } |
| 252 | |
Suruchi Agarwal | e3940e7 | 2016-07-06 15:56:51 -0700 | [diff] [blame] | 253 | /* |
| 254 | * Trace messages. |
| 255 | */ |
| 256 | nss_ipv6_log_tx_msg(nim); |
| 257 | |
Stephen Wang | 3e2dbd1 | 2018-03-14 17:28:17 -0700 | [diff] [blame] | 258 | return nss_core_send_cmd(nss_ctx, nim, sizeof(*nim), size); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 259 | } |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 260 | EXPORT_SYMBOL(nss_ipv6_tx_with_size); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 261 | |
| 262 | /* |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 263 | * nss_ipv6_tx() |
Suruchi Agarwal | 611ecd0 | 2016-08-04 15:54:35 -0700 | [diff] [blame] | 264 | * Transmit an ipv6 message to the FW. |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 265 | */ |
| 266 | nss_tx_status_t nss_ipv6_tx(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_msg *nim) |
| 267 | { |
| 268 | return nss_ipv6_tx_with_size(nss_ctx, nim, NSS_NBUF_PAYLOAD_SIZE); |
| 269 | } |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 270 | EXPORT_SYMBOL(nss_ipv6_tx); |
Stephen Wang | 709f9b5 | 2015-07-07 14:48:35 -0700 | [diff] [blame] | 271 | |
| 272 | /* |
Sakthi Vignesh Radhakrishnan | 8d02a2d | 2017-09-06 14:38:59 -0700 | [diff] [blame] | 273 | * nss_ipv6_tx_sync() |
| 274 | * Transmit a synchronous ipv6 message to the FW. |
| 275 | */ |
| 276 | nss_tx_status_t nss_ipv6_tx_sync(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_msg *nim) |
| 277 | { |
| 278 | nss_tx_status_t status; |
| 279 | int ret = 0; |
| 280 | |
| 281 | down(&nss_ipv6_pvt.sem); |
| 282 | nss_ipv6_pvt.cb = (void *)nim->cm.cb; |
| 283 | nss_ipv6_pvt.app_data = (void *)nim->cm.app_data; |
| 284 | |
| 285 | nim->cm.cb = (nss_ptr_t)nss_ipv6_tx_sync_callback; |
| 286 | nim->cm.app_data = (nss_ptr_t)NULL; |
| 287 | |
| 288 | status = nss_ipv6_tx(nss_ctx, nim); |
| 289 | if (status != NSS_TX_SUCCESS) { |
| 290 | nss_warning("%p: nss ipv6 msg tx failed\n", nss_ctx); |
| 291 | up(&nss_ipv6_pvt.sem); |
| 292 | return status; |
| 293 | } |
| 294 | |
| 295 | ret = wait_for_completion_timeout(&nss_ipv6_pvt.complete, msecs_to_jiffies(NSS_IPV6_TX_MSG_TIMEOUT)); |
| 296 | if (!ret) { |
| 297 | nss_warning("%p: IPv6 tx sync failed due to timeout\n", nss_ctx); |
| 298 | nss_ipv6_pvt.response = NSS_TX_FAILURE; |
| 299 | } |
| 300 | |
| 301 | status = nss_ipv6_pvt.response; |
| 302 | up(&nss_ipv6_pvt.sem); |
| 303 | return status; |
| 304 | } |
| 305 | EXPORT_SYMBOL(nss_ipv6_tx_sync); |
| 306 | |
| 307 | /* |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 308 | ********************************** |
| 309 | Register/Unregister/Miscellaneous APIs |
| 310 | ********************************** |
| 311 | */ |
| 312 | |
| 313 | /* |
| 314 | * nss_ipv6_notify_register() |
| 315 | * Register to received IPv6 events. |
| 316 | * |
| 317 | * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv6 on any core? |
| 318 | */ |
| 319 | struct nss_ctx_instance *nss_ipv6_notify_register(nss_ipv6_msg_callback_t cb, void *app_data) |
| 320 | { |
| 321 | /* |
| 322 | * TODO: We need to have a new array in support of the new API |
| 323 | * TODO: If we use a per-context array, we would move the array into nss_ctx based. |
| 324 | */ |
| 325 | nss_top_main.ipv6_callback = cb; |
| 326 | nss_top_main.ipv6_ctx = app_data; |
| 327 | return &nss_top_main.nss[nss_top_main.ipv6_handler_id]; |
| 328 | } |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 329 | EXPORT_SYMBOL(nss_ipv6_notify_register); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 330 | |
| 331 | /* |
| 332 | * nss_ipv6_notify_unregister() |
| 333 | * Unregister to received IPv6 events. |
| 334 | * |
| 335 | * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv6 on any core? |
| 336 | */ |
| 337 | void nss_ipv6_notify_unregister(void) |
| 338 | { |
| 339 | nss_top_main.ipv6_callback = NULL; |
| 340 | } |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 341 | EXPORT_SYMBOL(nss_ipv6_notify_unregister); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 342 | |
| 343 | /* |
Suruchi Agarwal | 611ecd0 | 2016-08-04 15:54:35 -0700 | [diff] [blame] | 344 | * nss_ipv6_conn_sync_many_notify_register() |
| 345 | * Register to receive IPv6 conn_sync_many message response. |
| 346 | */ |
| 347 | void nss_ipv6_conn_sync_many_notify_register(nss_ipv6_msg_callback_t cb) |
| 348 | { |
| 349 | nss_ipv6_conn_sync_many_msg_cb = cb; |
| 350 | } |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 351 | EXPORT_SYMBOL(nss_ipv6_conn_sync_many_notify_register); |
Suruchi Agarwal | 611ecd0 | 2016-08-04 15:54:35 -0700 | [diff] [blame] | 352 | |
| 353 | /* |
| 354 | * nss_ipv6_conn_sync_many_notify_unregister() |
| 355 | * Unregister to receive IPv6 conn_sync_many message response. |
| 356 | */ |
| 357 | void nss_ipv6_conn_sync_many_notify_unregister(void) |
| 358 | { |
| 359 | nss_ipv6_conn_sync_many_msg_cb = NULL; |
| 360 | } |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 361 | EXPORT_SYMBOL(nss_ipv6_conn_sync_many_notify_unregister); |
Suruchi Agarwal | 611ecd0 | 2016-08-04 15:54:35 -0700 | [diff] [blame] | 362 | |
| 363 | /* |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 364 | * nss_ipv6_get_mgr() |
| 365 | * |
| 366 | * TODO: This only suppports a single ipv6, do we ever want to support more? |
| 367 | */ |
| 368 | struct nss_ctx_instance *nss_ipv6_get_mgr(void) |
| 369 | { |
| 370 | return (void *)&nss_top_main.nss[nss_top_main.ipv6_handler_id]; |
| 371 | } |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 372 | EXPORT_SYMBOL(nss_ipv6_get_mgr); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 373 | |
| 374 | /* |
| 375 | * nss_ipv6_register_handler() |
| 376 | * Register our handler to receive messages for this interface |
| 377 | */ |
| 378 | void nss_ipv6_register_handler() |
| 379 | { |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 380 | struct nss_ctx_instance *nss_ctx = nss_ipv6_get_mgr(); |
| 381 | |
| 382 | 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] | 383 | nss_warning("IPv6 handler failed to register"); |
| 384 | } |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 385 | |
| 386 | nss_ipv6_stats_dentry_create(); |
Sol Kavy | 879eb8b | 2014-04-07 19:11:31 -0700 | [diff] [blame] | 387 | } |
| 388 | |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 389 | /* |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 390 | * nss_ipv6_conn_cfg_process_callback() |
| 391 | * Call back function for the ipv6 connection configuration process. |
| 392 | */ |
| 393 | static void nss_ipv6_conn_cfg_process_callback(void *app_data, struct nss_ipv6_msg *nim) |
| 394 | { |
| 395 | struct nss_ipv6_rule_conn_cfg_msg *nirccm = &nim->msg.rule_conn_cfg; |
| 396 | struct nss_ctx_instance *nss_ctx __maybe_unused = nss_ipv6_get_mgr(); |
| 397 | |
| 398 | if (nim->cm.response != NSS_CMN_RESPONSE_ACK) { |
| 399 | 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] | 400 | nss_core_update_max_ipv6_conn(NSS_FW_DEFAULT_NUM_CONN); |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 401 | nss_ipv6_free_conn_tables(); |
| 402 | return; |
| 403 | } |
| 404 | |
| 405 | nss_ipv6_conn_cfg = ntohl(nirccm->num_conn); |
| 406 | |
| 407 | nss_warning("%p: IPv6 connection configuration success: %d\n", nss_ctx, nim->cm.error); |
| 408 | } |
| 409 | |
| 410 | /* |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 411 | * nss_ipv6_conn_cfg_process() |
| 412 | * Process request to configure number of ipv6 connections |
| 413 | */ |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 414 | 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] | 415 | { |
| 416 | struct nss_ipv6_msg nim; |
| 417 | struct nss_ipv6_rule_conn_cfg_msg *nirccm; |
| 418 | nss_tx_status_t nss_tx_status; |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 419 | |
| 420 | if ((!nss_ipv6_ct_info.ce_table_size) || (!nss_ipv6_ct_info.cme_table_size)) { |
| 421 | nss_warning("%p: connection entry or connection match entry table size not available\n", |
| 422 | nss_ctx); |
| 423 | return -EINVAL; |
| 424 | } |
| 425 | |
| 426 | nss_info("%p: IPv6 supported connections: %d\n", nss_ctx, conn); |
| 427 | |
| 428 | nss_ipv6_ct_info.ce_mem = __get_free_pages(GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO, |
| 429 | get_order(nss_ipv6_ct_info.ce_table_size)); |
| 430 | if (!nss_ipv6_ct_info.ce_mem) { |
| 431 | nss_warning("%p: Memory allocation failed for IPv6 Connections: %d\n", |
| 432 | nss_ctx, |
| 433 | conn); |
| 434 | goto fail; |
| 435 | } |
| 436 | nss_warning("%p: CE Memory allocated for IPv6 Connections: %d\n", |
| 437 | nss_ctx, |
| 438 | conn); |
| 439 | |
| 440 | nss_ipv6_ct_info.cme_mem = __get_free_pages(GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO, |
| 441 | get_order(nss_ipv6_ct_info.cme_table_size)); |
| 442 | if (!nss_ipv6_ct_info.cme_mem) { |
| 443 | nss_warning("%p: Memory allocation failed for IPv6 Connections: %d\n", |
| 444 | nss_ctx, |
| 445 | conn); |
| 446 | goto fail; |
| 447 | } |
| 448 | nss_warning("%p: CME Memory allocated for IPv6 Connections: %d\n", |
| 449 | nss_ctx, |
| 450 | conn); |
| 451 | |
| 452 | memset(&nim, 0, sizeof(struct nss_ipv6_msg)); |
| 453 | nss_ipv6_msg_init(&nim, NSS_IPV6_RX_INTERFACE, NSS_IPV6_TX_CONN_CFG_RULE_MSG, |
| 454 | sizeof(struct nss_ipv6_rule_conn_cfg_msg), nss_ipv6_conn_cfg_process_callback, NULL); |
| 455 | |
| 456 | nirccm = &nim.msg.rule_conn_cfg; |
| 457 | nirccm->num_conn = htonl(conn); |
Suruchi Agarwal | 8c9e716 | 2017-08-17 15:58:40 -0700 | [diff] [blame] | 458 | 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); |
| 459 | if (unlikely(dma_mapping_error(nss_ctx->dev, nirccm->ce_mem))) { |
| 460 | nss_warning("%p: DMA mapping failed for virtual address = %p", nss_ctx, (void *)nss_ipv6_ct_info.ce_mem); |
| 461 | goto fail; |
| 462 | } |
| 463 | |
| 464 | 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); |
| 465 | if (unlikely(dma_mapping_error(nss_ctx->dev, nirccm->cme_mem))) { |
| 466 | nss_warning("%p: DMA mapping failed for virtual address = %p", nss_ctx, (void *)nss_ipv6_ct_info.cme_mem); |
| 467 | goto fail; |
| 468 | } |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 469 | |
| 470 | nss_tx_status = nss_ipv6_tx(nss_ctx, &nim); |
| 471 | if (nss_tx_status != NSS_TX_SUCCESS) { |
| 472 | nss_warning("%p: nss_tx error setting IPv6 Connections: %d\n", |
| 473 | nss_ctx, |
| 474 | conn); |
| 475 | goto fail; |
| 476 | } |
| 477 | |
| 478 | return 0; |
| 479 | |
| 480 | fail: |
| 481 | nss_ipv6_free_conn_tables(); |
| 482 | return -EINVAL; |
| 483 | } |
| 484 | |
| 485 | /* |
| 486 | * nss_ipv6_update_conn_count_callback() |
| 487 | * Call back function for the ipv6 get connection info message. |
| 488 | */ |
| 489 | static void nss_ipv6_update_conn_count_callback(void *app_data, struct nss_ipv6_msg *nim) |
| 490 | { |
| 491 | struct nss_ipv6_rule_conn_get_table_size_msg *nircgts = &nim->msg.size; |
| 492 | struct nss_ctx_instance *nss_ctx = nss_ipv6_get_mgr(); |
| 493 | |
| 494 | if (nim->cm.response != NSS_CMN_RESPONSE_ACK) { |
| 495 | 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] | 496 | nss_core_update_max_ipv6_conn(NSS_FW_DEFAULT_NUM_CONN); |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 497 | return; |
| 498 | } |
| 499 | |
| 500 | nss_info("IPv6 get connection info success\n"); |
| 501 | |
| 502 | nss_ipv6_ct_info.ce_table_size = ntohl(nircgts->ce_table_size); |
| 503 | nss_ipv6_ct_info.cme_table_size = ntohl(nircgts->cme_table_size); |
| 504 | |
| 505 | if (nss_ipv6_conn_cfg_process(nss_ctx, ntohl(nircgts->num_conn)) != 0) { |
| 506 | nss_warning("%p: IPv6 connection entry or connection match entry table size\ |
| 507 | not available\n", nss_ctx); |
| 508 | } |
| 509 | |
| 510 | return; |
| 511 | } |
| 512 | |
| 513 | /* |
| 514 | * nss_ipv6_update_conn_count() |
| 515 | * Sets the maximum number of IPv6 connections. |
| 516 | * |
| 517 | * It first gets the connection tables size information from NSS FW |
| 518 | * and then configures the connections in NSS FW. |
| 519 | */ |
| 520 | int nss_ipv6_update_conn_count(int ipv6_num_conn) |
| 521 | { |
| 522 | struct nss_ctx_instance *nss_ctx = nss_ipv6_get_mgr(); |
| 523 | struct nss_ipv6_msg nim; |
| 524 | struct nss_ipv6_rule_conn_get_table_size_msg *nircgts; |
| 525 | nss_tx_status_t nss_tx_status; |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 526 | uint32_t sum_of_conn; |
| 527 | |
| 528 | /* |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 529 | * By default, NSS FW is configured with default number of connections. |
| 530 | */ |
Stephen Wang | 0143369 | 2017-10-30 14:45:11 -0700 | [diff] [blame] | 531 | if (ipv6_num_conn == NSS_FW_DEFAULT_NUM_CONN) { |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 532 | nss_info("%p: Default number of connections (%d) already configured\n", nss_ctx, ipv6_num_conn); |
| 533 | return 0; |
| 534 | } |
| 535 | |
| 536 | /* |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 537 | * Specifications for input |
| 538 | * 1) The input should be power of 2. |
| 539 | * 2) Input for ipv4 and ipv6 sum togther should not exceed 8k |
| 540 | * 3) Min. value should be at leat 256 connections. This is the |
| 541 | * minimum connections we will support for each of them. |
| 542 | */ |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 543 | sum_of_conn = nss_ipv4_conn_cfg + ipv6_num_conn; |
| 544 | if ((ipv6_num_conn & NSS_NUM_CONN_QUANTA_MASK) || |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 545 | (sum_of_conn > NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6) || |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 546 | (ipv6_num_conn < NSS_MIN_NUM_CONN)) { |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 547 | nss_warning("%p: input supported connections (%d) does not adhere\ |
| 548 | specifications\n1) not power of 2,\n2) is less than \ |
| 549 | min val: %d, OR\n IPv4/6 total exceeds %d\n", |
| 550 | nss_ctx, |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 551 | ipv6_num_conn, |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 552 | NSS_MIN_NUM_CONN, |
| 553 | NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6); |
| 554 | return -EINVAL; |
| 555 | } |
| 556 | |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 557 | memset(&nim, 0, sizeof(struct nss_ipv6_msg)); |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 558 | nss_ipv6_msg_init(&nim, NSS_IPV6_RX_INTERFACE, NSS_IPV6_TX_CONN_TABLE_SIZE_MSG, |
| 559 | 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] | 560 | |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 561 | nircgts = &nim.msg.size; |
| 562 | nircgts->num_conn = htonl(ipv6_num_conn); |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 563 | nss_tx_status = nss_ipv6_tx(nss_ctx, &nim); |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 564 | if (nss_tx_status != NSS_TX_SUCCESS) { |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 565 | nss_warning("%p: Send acceleration mode message failed\n", nss_ctx); |
| 566 | return -EINVAL; |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | return 0; |
| 570 | } |
| 571 | |
| 572 | /* |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 573 | * nss_ipv6_free_conn_tables() |
| 574 | * Frees memory allocated for connection tables |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 575 | */ |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 576 | void nss_ipv6_free_conn_tables(void) |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 577 | { |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 578 | if (nss_ipv6_ct_info.ce_mem) { |
| 579 | 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] | 580 | } |
| 581 | |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 582 | if (nss_ipv6_ct_info.cme_mem) { |
| 583 | 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] | 584 | } |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 585 | |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 586 | memset(&nss_ipv6_ct_info, 0, sizeof(struct nss_ipv6_conn_table_info)); |
| 587 | return; |
Tushar Mathur | a3c1893 | 2015-08-24 20:27:21 +0530 | [diff] [blame] | 588 | } |
| 589 | |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 590 | /* |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 591 | * nss_ipv6_accel_mode_cfg_handler() |
| 592 | * Configure acceleration mode for IPv6 |
| 593 | */ |
| 594 | static int nss_ipv6_accel_mode_cfg_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos) |
| 595 | { |
| 596 | struct nss_top_instance *nss_top = &nss_top_main; |
| 597 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[0]; |
| 598 | struct nss_ipv6_msg nim; |
| 599 | struct nss_ipv6_accel_mode_cfg_msg *nipcm; |
| 600 | nss_tx_status_t nss_tx_status; |
| 601 | int ret = NSS_FAILURE; |
Sakthi Vignesh Radhakrishnan | 8d02a2d | 2017-09-06 14:38:59 -0700 | [diff] [blame] | 602 | int current_value; |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 603 | |
| 604 | /* |
| 605 | * Take snap shot of current value |
| 606 | */ |
Sakthi Vignesh Radhakrishnan | 8d02a2d | 2017-09-06 14:38:59 -0700 | [diff] [blame] | 607 | current_value = nss_ipv6_accel_mode_cfg; |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 608 | |
| 609 | /* |
| 610 | * Write the variable with user input |
| 611 | */ |
| 612 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 613 | if (ret || (!write)) { |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 614 | return ret; |
| 615 | } |
| 616 | |
| 617 | memset(&nim, 0, sizeof(struct nss_ipv6_msg)); |
| 618 | 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] | 619 | sizeof(struct nss_ipv6_accel_mode_cfg_msg), NULL, NULL); |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 620 | |
| 621 | nipcm = &nim.msg.accel_mode_cfg; |
| 622 | nipcm->mode = htonl(nss_ipv6_accel_mode_cfg); |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 623 | |
Sakthi Vignesh Radhakrishnan | 8d02a2d | 2017-09-06 14:38:59 -0700 | [diff] [blame] | 624 | nss_tx_status = nss_ipv6_tx_sync(nss_ctx, &nim); |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 625 | if (nss_tx_status != NSS_TX_SUCCESS) { |
| 626 | nss_warning("%p: Send acceleration mode message failed\n", nss_ctx); |
Sakthi Vignesh Radhakrishnan | 8d02a2d | 2017-09-06 14:38:59 -0700 | [diff] [blame] | 627 | nss_ipv6_accel_mode_cfg = current_value; |
| 628 | return -EIO; |
| 629 | } |
| 630 | |
| 631 | return 0; |
| 632 | } |
| 633 | |
| 634 | /* |
| 635 | * nss_ipv6_dscp_map_cfg_handler() |
| 636 | * Sysctl handler for dscp/pri mappings. |
| 637 | */ |
| 638 | static int nss_ipv6_dscp_map_cfg_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos) |
| 639 | { |
| 640 | struct nss_top_instance *nss_top = &nss_top_main; |
| 641 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[0]; |
| 642 | struct nss_dscp_map_parse out; |
| 643 | struct nss_ipv6_msg nim; |
| 644 | struct nss_ipv6_dscp2pri_cfg_msg *nipd2p; |
| 645 | nss_tx_status_t status; |
| 646 | int ret; |
| 647 | |
| 648 | if (!write) { |
| 649 | return nss_dscp_map_print(ctl, buffer, lenp, ppos, mapping); |
| 650 | } |
| 651 | |
| 652 | ret = nss_dscp_map_parse(ctl, buffer, lenp, ppos, &out); |
| 653 | if (ret) { |
| 654 | nss_warning("failed to parse dscp mapping:%d\n", ret); |
| 655 | return ret; |
| 656 | } |
| 657 | |
| 658 | if (out.action >= NSS_IPV6_DSCP_MAP_ACTION_MAX) { |
| 659 | nss_warning("invalid action value: %d\n", out.action); |
| 660 | nss_ipv6_dscp_map_usage(); |
| 661 | return -EINVAL; |
| 662 | } |
| 663 | |
| 664 | memset(&nim, 0, sizeof(struct nss_ipv6_msg)); |
| 665 | nss_ipv6_msg_init(&nim, NSS_IPV6_RX_INTERFACE, NSS_IPV6_TX_DSCP2PRI_CFG_MSG, |
| 666 | sizeof(struct nss_ipv6_dscp2pri_cfg_msg), NULL, NULL); |
| 667 | |
| 668 | nipd2p = &nim.msg.dscp2pri_cfg; |
| 669 | nipd2p->dscp = out.dscp; |
| 670 | nipd2p->priority = out.priority; |
| 671 | |
| 672 | status = nss_ipv6_tx_sync(nss_ctx, &nim); |
| 673 | if (status != NSS_TX_SUCCESS) { |
| 674 | nss_warning("%p: ipv6 dscp2pri config message failed\n", nss_ctx); |
| 675 | return -EFAULT; |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | /* |
Sakthi Vignesh Radhakrishnan | 8d02a2d | 2017-09-06 14:38:59 -0700 | [diff] [blame] | 679 | * NSS firmware acknowleged the configuration, so update the mapping |
| 680 | * table on HOST side as well. |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 681 | */ |
Sakthi Vignesh Radhakrishnan | 8d02a2d | 2017-09-06 14:38:59 -0700 | [diff] [blame] | 682 | mapping[out.dscp].action = out.action; |
| 683 | mapping[out.dscp].priority = out.priority; |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 684 | |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 685 | return 0; |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 686 | } |
| 687 | |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 688 | static struct ctl_table nss_ipv6_table[] = { |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 689 | { |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 690 | .procname = "ipv6_accel_mode", |
| 691 | .data = &nss_ipv6_accel_mode_cfg, |
| 692 | .maxlen = sizeof(int), |
| 693 | .mode = 0644, |
| 694 | .proc_handler = &nss_ipv6_accel_mode_cfg_handler, |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 695 | }, |
Sakthi Vignesh Radhakrishnan | 8d02a2d | 2017-09-06 14:38:59 -0700 | [diff] [blame] | 696 | { |
| 697 | .procname = "ipv6_dscp_map", |
| 698 | .data = &mapping[NSS_DSCP_MAP_ARRAY_SIZE], |
| 699 | .maxlen = sizeof(struct nss_dscp_map_entry), |
| 700 | .mode = 0644, |
| 701 | .proc_handler = &nss_ipv6_dscp_map_cfg_handler, |
| 702 | }, |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 703 | { } |
| 704 | }; |
| 705 | |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 706 | static struct ctl_table nss_ipv6_dir[] = { |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 707 | { |
Vijay Dewangan | 4861f4e | 2014-10-14 16:56:35 -0700 | [diff] [blame] | 708 | .procname = "ipv6cfg", |
| 709 | .mode = 0555, |
| 710 | .child = nss_ipv6_table, |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 711 | }, |
| 712 | { } |
| 713 | }; |
| 714 | |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 715 | static struct ctl_table nss_ipv6_root_dir[] = { |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 716 | { |
| 717 | .procname = "nss", |
| 718 | .mode = 0555, |
| 719 | .child = nss_ipv6_dir, |
| 720 | }, |
| 721 | { } |
| 722 | }; |
| 723 | |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 724 | static struct ctl_table nss_ipv6_root[] = { |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 725 | { |
| 726 | .procname = "dev", |
| 727 | .mode = 0555, |
| 728 | .child = nss_ipv6_root_dir, |
| 729 | }, |
| 730 | { } |
| 731 | }; |
| 732 | |
| 733 | static struct ctl_table_header *nss_ipv6_header; |
| 734 | |
| 735 | /* |
| 736 | * nss_ipv6_register_sysctl() |
Kiran Kumar C.S.K | fadf92d | 2015-06-26 12:48:33 +0530 | [diff] [blame] | 737 | * Register sysctl specific to ipv6 |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 738 | */ |
| 739 | void nss_ipv6_register_sysctl(void) |
| 740 | { |
Sakthi Vignesh Radhakrishnan | 8d02a2d | 2017-09-06 14:38:59 -0700 | [diff] [blame] | 741 | sema_init(&nss_ipv6_pvt.sem, 1); |
| 742 | init_completion(&nss_ipv6_pvt.complete); |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 743 | |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 744 | /* |
| 745 | * Register sysctl table. |
| 746 | */ |
| 747 | nss_ipv6_header = register_sysctl_table(nss_ipv6_root); |
| 748 | } |
| 749 | |
| 750 | /* |
| 751 | * nss_ipv6_unregister_sysctl() |
Kiran Kumar C.S.K | fadf92d | 2015-06-26 12:48:33 +0530 | [diff] [blame] | 752 | * Unregister sysctl specific to ipv6 |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 753 | */ |
| 754 | void nss_ipv6_unregister_sysctl(void) |
| 755 | { |
| 756 | /* |
| 757 | * Unregister sysctl table. |
| 758 | */ |
| 759 | if (nss_ipv6_header) { |
| 760 | unregister_sysctl_table(nss_ipv6_header); |
| 761 | } |
| 762 | } |
| 763 | |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 764 | /* |
| 765 | * nss_ipv6_msg_init() |
Stephen Wang | 0a2756a | 2016-08-04 15:52:47 -0700 | [diff] [blame] | 766 | * Initialize IPv6 message. |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 767 | */ |
| 768 | 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] | 769 | nss_ipv6_msg_callback_t cb, void *app_data) |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 770 | { |
| 771 | nss_cmn_msg_init(&nim->cm, if_num, type, len, (void *)cb, app_data); |
| 772 | } |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 773 | EXPORT_SYMBOL(nss_ipv6_msg_init); |