Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved. |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [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 | /* |
Sundarajan Srinivasan | f1e5746 | 2014-09-17 15:24:01 -0700 | [diff] [blame] | 18 | * nss_n2h.c |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 19 | * NSS N2H node APIs |
| 20 | */ |
| 21 | |
| 22 | #include "nss_tx_rx_common.h" |
| 23 | |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 24 | #define NSS_CORE_0 0 |
| 25 | #define NSS_CORE_1 1 |
Pamidipati, Vijay | efcc469 | 2014-05-09 14:47:38 +0530 | [diff] [blame] | 26 | |
| 27 | /* |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 28 | * This number is chosen becuase currently default IPV4 + IPV6 |
| 29 | * connection size is 1024 + 1024 = 2048. |
| 30 | * FYI: However this doesnt have any impact on n2h/ipv6 connections |
Pamidipati, Vijay | efcc469 | 2014-05-09 14:47:38 +0530 | [diff] [blame] | 31 | */ |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 32 | #define NSS_N2H_MIN_EMPTY_POOL_BUF_SZ 2048 |
| 33 | #define NSS_N2H_DEFAULT_EMPTY_POOL_BUF_SZ 8192 |
Pamidipati, Vijay | efcc469 | 2014-05-09 14:47:38 +0530 | [diff] [blame] | 34 | |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 35 | int nss_n2h_empty_pool_buf_cfg[NSS_MAX_CORES] __read_mostly = {NSS_N2H_DEFAULT_EMPTY_POOL_BUF_SZ, NSS_N2H_DEFAULT_EMPTY_POOL_BUF_SZ}; |
Pamidipati, Vijay | efcc469 | 2014-05-09 14:47:38 +0530 | [diff] [blame] | 36 | |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 37 | struct nss_n2h_registered_data { |
| 38 | nss_n2h_msg_callback_t n2h_callback; |
| 39 | void *app_data; |
| 40 | }; |
Pamidipati, Vijay | efcc469 | 2014-05-09 14:47:38 +0530 | [diff] [blame] | 41 | |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 42 | static struct nss_n2h_cfg_pvt nss_n2h_nepbcfgp[NSS_MAX_CORES]; |
| 43 | static struct nss_n2h_registered_data nss_n2h_rd[NSS_MAX_CORES]; |
Vijay Dewangan | 634ce59 | 2015-01-07 17:21:09 -0800 | [diff] [blame] | 44 | static struct nss_n2h_cfg_pvt nss_n2h_rcp; |
Pamidipati, Vijay | efcc469 | 2014-05-09 14:47:38 +0530 | [diff] [blame] | 45 | |
| 46 | /* |
Sundarajan Srinivasan | f1e5746 | 2014-09-17 15:24:01 -0700 | [diff] [blame] | 47 | * nss_n2h_stats_sync() |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 48 | * Handle the syncing of NSS statistics. |
| 49 | */ |
Sundarajan Srinivasan | f1e5746 | 2014-09-17 15:24:01 -0700 | [diff] [blame] | 50 | static void nss_n2h_stats_sync(struct nss_ctx_instance *nss_ctx, struct nss_n2h_stats_sync *nnss) |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 51 | { |
| 52 | struct nss_top_instance *nss_top = nss_ctx->nss_top; |
| 53 | |
| 54 | spin_lock_bh(&nss_top->stats_lock); |
| 55 | |
| 56 | /* |
| 57 | * common node stats |
| 58 | */ |
| 59 | nss_ctx->stats_n2h[NSS_STATS_NODE_RX_PKTS] += nnss->node_stats.rx_packets; |
| 60 | nss_ctx->stats_n2h[NSS_STATS_NODE_RX_BYTES] += nnss->node_stats.rx_bytes; |
| 61 | nss_ctx->stats_n2h[NSS_STATS_NODE_RX_DROPPED] += nnss->node_stats.rx_dropped; |
| 62 | nss_ctx->stats_n2h[NSS_STATS_NODE_TX_PKTS] += nnss->node_stats.tx_packets; |
| 63 | nss_ctx->stats_n2h[NSS_STATS_NODE_TX_BYTES] += nnss->node_stats.tx_bytes; |
| 64 | |
| 65 | /* |
| 66 | * General N2H stats |
| 67 | */ |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 68 | nss_ctx->stats_n2h[NSS_STATS_N2H_QUEUE_DROPPED] += nnss->queue_dropped; |
| 69 | nss_ctx->stats_n2h[NSS_STATS_N2H_TOTAL_TICKS] += nnss->total_ticks; |
| 70 | nss_ctx->stats_n2h[NSS_STATS_N2H_WORST_CASE_TICKS] += nnss->worst_case_ticks; |
| 71 | nss_ctx->stats_n2h[NSS_STATS_N2H_ITERATIONS] += nnss->iterations; |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 72 | |
| 73 | /* |
Thomas Wu | 3fd8dd7 | 2014-06-11 15:57:05 -0700 | [diff] [blame] | 74 | * pbuf manager ocm and default pool stats |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 75 | */ |
Thomas Wu | 3fd8dd7 | 2014-06-11 15:57:05 -0700 | [diff] [blame] | 76 | nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_OCM_ALLOC_FAILS] += nnss->pbuf_ocm_stats.pbuf_alloc_fails; |
| 77 | nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_OCM_FREE_COUNT] = nnss->pbuf_ocm_stats.pbuf_free_count; |
| 78 | nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_OCM_TOTAL_COUNT] = nnss->pbuf_ocm_stats.pbuf_total_count; |
| 79 | |
| 80 | nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_DEFAULT_ALLOC_FAILS] += nnss->pbuf_default_stats.pbuf_alloc_fails; |
| 81 | nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_DEFAULT_FREE_COUNT] = nnss->pbuf_default_stats.pbuf_free_count; |
| 82 | nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_DEFAULT_TOTAL_COUNT] = nnss->pbuf_default_stats.pbuf_total_count; |
| 83 | |
| 84 | /* |
| 85 | * payload mgr stats |
| 86 | */ |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 87 | nss_ctx->stats_n2h[NSS_STATS_N2H_PAYLOAD_ALLOC_FAILS] += nnss->payload_alloc_fails; |
Thomas Wu | 5367984 | 2015-01-22 13:37:35 -0800 | [diff] [blame] | 88 | nss_ctx->stats_n2h[NSS_STATS_N2H_PAYLOAD_FREE_COUNT] = nnss->payload_free_count; |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 89 | |
Sakthi Vignesh Radhakrishnan | 2a8ee96 | 2014-11-22 13:35:38 -0800 | [diff] [blame] | 90 | /* |
| 91 | * Host <=> NSS control traffic stats |
| 92 | */ |
| 93 | nss_ctx->stats_n2h[NSS_STATS_N2H_H2N_CONTROL_PACKETS] += nnss->h2n_ctrl_pkts; |
| 94 | nss_ctx->stats_n2h[NSS_STATS_N2H_H2N_CONTROL_BYTES] += nnss->h2n_ctrl_bytes; |
| 95 | nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_CONTROL_PACKETS] += nnss->n2h_ctrl_pkts; |
| 96 | nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_CONTROL_BYTES] += nnss->n2h_ctrl_bytes; |
| 97 | |
| 98 | /* |
| 99 | * Host <=> NSS control data traffic stats |
| 100 | */ |
| 101 | nss_ctx->stats_n2h[NSS_STATS_N2H_H2N_DATA_PACKETS] += nnss->h2n_data_pkts; |
| 102 | nss_ctx->stats_n2h[NSS_STATS_N2H_H2N_DATA_BYTES] += nnss->h2n_data_bytes; |
| 103 | nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_DATA_PACKETS] += nnss->n2h_data_pkts; |
| 104 | nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_DATA_BYTES] += nnss->n2h_data_bytes; |
| 105 | |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 106 | spin_unlock_bh(&nss_top->stats_lock); |
| 107 | } |
| 108 | |
| 109 | /* |
Sundarajan Srinivasan | f1e5746 | 2014-09-17 15:24:01 -0700 | [diff] [blame] | 110 | * nss_n2h_interface_handler() |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 111 | * Handle NSS -> HLOS messages for N2H node |
| 112 | */ |
Vijay Dewangan | 634ce59 | 2015-01-07 17:21:09 -0800 | [diff] [blame] | 113 | static void nss_n2h_interface_handler(struct nss_ctx_instance *nss_ctx, |
| 114 | struct nss_cmn_msg *ncm, |
| 115 | __attribute__((unused))void *app_data) |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 116 | { |
| 117 | struct nss_n2h_msg *nnm = (struct nss_n2h_msg *)ncm; |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 118 | nss_n2h_msg_callback_t cb; |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 119 | |
Sundarajan Srinivasan | f1e5746 | 2014-09-17 15:24:01 -0700 | [diff] [blame] | 120 | BUG_ON(ncm->interface != NSS_N2H_INTERFACE); |
| 121 | |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 122 | /* |
| 123 | * Is this a valid request/response packet? |
| 124 | */ |
| 125 | if (nnm->cm.type >= NSS_METADATA_TYPE_N2H_MAX) { |
| 126 | nss_warning("%p: received invalid message %d for Offload stats interface", nss_ctx, nnm->cm.type); |
| 127 | return; |
| 128 | } |
| 129 | |
| 130 | switch (nnm->cm.type) { |
Pamidipati, Vijay | efcc469 | 2014-05-09 14:47:38 +0530 | [diff] [blame] | 131 | case NSS_TX_METADATA_TYPE_N2H_RPS_CFG: |
Pamidipati, Vijay | efcc469 | 2014-05-09 14:47:38 +0530 | [diff] [blame] | 132 | nss_info("NSS N2H rps_en %d \n",nnm->msg.rps_cfg.enable); |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 133 | break; |
| 134 | |
| 135 | case NSS_TX_METADATA_TYPE_N2H_EMPTY_POOL_BUF_CFG: |
| 136 | nss_info("%p: empty pool buf cfg response from FW", nss_ctx); |
Pamidipati, Vijay | efcc469 | 2014-05-09 14:47:38 +0530 | [diff] [blame] | 137 | break; |
| 138 | |
Radha krishna Simha Jiguru | 7f424d5 | 2015-02-10 19:41:01 +0530 | [diff] [blame] | 139 | case NSS_TX_METADATA_TYPE_N2H_FLUSH_PAYLOADS: |
| 140 | nss_info("%p: flush payloads cmd response from FW", nss_ctx); |
| 141 | break; |
| 142 | |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 143 | case NSS_RX_METADATA_TYPE_N2H_STATS_SYNC: |
Sundarajan Srinivasan | f1e5746 | 2014-09-17 15:24:01 -0700 | [diff] [blame] | 144 | nss_n2h_stats_sync(nss_ctx, &nnm->msg.stats_sync); |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 145 | break; |
| 146 | |
| 147 | default: |
| 148 | if (ncm->response != NSS_CMN_RESPONSE_ACK) { |
| 149 | /* |
| 150 | * Check response |
| 151 | */ |
| 152 | nss_info("%p: Received response %d for type %d, interface %d", |
| 153 | nss_ctx, ncm->response, ncm->type, ncm->interface); |
| 154 | } |
| 155 | } |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 156 | |
| 157 | /* |
| 158 | * Update the callback and app_data for NOTIFY messages, IPv4 sends all notify messages |
| 159 | * to the same callback/app_data. |
| 160 | */ |
| 161 | if (nnm->cm.response == NSS_CMM_RESPONSE_NOTIFY) { |
| 162 | /* |
| 163 | * Place holder for the user to create right call |
| 164 | * back and app data when response is NSS_CMM_RESPONSE_NOTIFY |
| 165 | */ |
| 166 | ncm->cb = (uint32_t)nss_n2h_rd[nss_ctx->id].n2h_callback; |
| 167 | ncm->app_data = (uint32_t)nss_n2h_rd[nss_ctx->id].app_data; |
| 168 | } |
| 169 | |
| 170 | /* |
| 171 | * Do we have a callback? |
| 172 | */ |
| 173 | if (!ncm->cb) { |
| 174 | return; |
| 175 | } |
| 176 | |
| 177 | /* |
| 178 | * Callback |
| 179 | */ |
| 180 | cb = (nss_n2h_msg_callback_t)ncm->cb; |
| 181 | cb((void *)ncm->app_data, nnm); |
| 182 | } |
| 183 | |
| 184 | /* |
Vijay Dewangan | 634ce59 | 2015-01-07 17:21:09 -0800 | [diff] [blame] | 185 | * nss_n2h_rps_cfg_callback() |
| 186 | * call back function for rps configuration |
| 187 | */ |
| 188 | static void nss_n2h_rps_cfg_callback(void *app_data, struct nss_n2h_msg *nnm) |
| 189 | { |
| 190 | struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)app_data; |
| 191 | if (nnm->cm.response != NSS_CMN_RESPONSE_ACK) { |
| 192 | |
| 193 | /* |
| 194 | * Error, hence we are not updating the nss_n2h_empty_pool_buf |
| 195 | * Restore the current_value to its previous state |
| 196 | */ |
| 197 | nss_n2h_rcp.response = NSS_FAILURE; |
| 198 | complete(&nss_n2h_rcp.complete); |
| 199 | nss_warning("%p: RPS configuration failed : %d\n", nss_ctx, |
| 200 | nnm->cm.error); |
| 201 | return; |
| 202 | } |
| 203 | |
| 204 | nss_info("%p: RPS configuration succeeded: %d\n", nss_ctx, |
| 205 | nnm->cm.error); |
| 206 | nss_ctx->n2h_rps_en = nnm->msg.rps_cfg.enable; |
| 207 | nss_n2h_rcp.response = NSS_SUCCESS; |
| 208 | complete(&nss_n2h_rcp.complete); |
| 209 | } |
| 210 | |
| 211 | /* |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 212 | * nss_n2h_empty_pool_buf_cfg_core1_callback() |
| 213 | * call back function for the n2h connection configuration handler |
| 214 | */ |
| 215 | static void nss_n2h_empty_pool_buf_cfg_callback(void *app_data, |
| 216 | struct nss_n2h_msg *nnm) |
| 217 | { |
| 218 | int core_num = (int)app_data; |
| 219 | if (nnm->cm.response != NSS_CMN_RESPONSE_ACK) { |
| 220 | struct nss_n2h_empty_pool_buf *nnepbcm; |
| 221 | nnepbcm = &nnm->msg.empty_pool_buf_cfg; |
| 222 | |
| 223 | /* |
| 224 | * Error, hence we are not updating the nss_n2h_empty_pool_buf |
| 225 | * Restore the current_value to its previous state |
| 226 | */ |
| 227 | nss_warning("Core %d empty pool buf set failure: %d\n", core_num, nnm->cm.error); |
| 228 | nss_n2h_nepbcfgp[core_num].response = NSS_FAILURE; |
| 229 | complete(&nss_n2h_nepbcfgp[core_num].complete); |
| 230 | return; |
| 231 | } |
| 232 | |
| 233 | /* |
| 234 | * Sucess at NSS FW, hence updating nss_n2h_empty_pool_buf, with the valid value |
| 235 | * saved at the sysctl handler. |
| 236 | */ |
| 237 | nss_info("Core %d empty pool buf set success: %d\n", core_num, nnm->cm.error); |
| 238 | nss_n2h_nepbcfgp[core_num].response = NSS_SUCCESS; |
| 239 | complete(&nss_n2h_nepbcfgp[core_num].complete); |
| 240 | } |
| 241 | |
| 242 | /* |
| 243 | * nss_n2h_empty_pool_buf_core1_handler() |
| 244 | * Sets the number of connections for IPv4 |
| 245 | */ |
| 246 | static int nss_n2h_set_empty_pool_buf(ctl_table *ctl, int write, void __user *buffer, |
| 247 | size_t *lenp, loff_t *ppos, |
| 248 | int core_num, int *new_val) |
| 249 | { |
| 250 | struct nss_top_instance *nss_top = &nss_top_main; |
| 251 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num]; |
| 252 | struct nss_n2h_msg nnm; |
| 253 | struct nss_n2h_empty_pool_buf *nnepbcm; |
| 254 | nss_tx_status_t nss_tx_status; |
| 255 | int ret = NSS_FAILURE; |
| 256 | |
| 257 | /* |
| 258 | * Acquiring semaphore |
| 259 | */ |
| 260 | down(&nss_n2h_nepbcfgp[core_num].sem); |
| 261 | |
| 262 | /* |
| 263 | * Take snap shot of current value |
| 264 | */ |
| 265 | nss_n2h_nepbcfgp[core_num].current_value = *new_val; |
| 266 | |
| 267 | /* |
| 268 | * Write the variable with user input |
| 269 | */ |
| 270 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 271 | if (ret || (!write)) { |
| 272 | up(&nss_n2h_nepbcfgp[core_num].sem); |
| 273 | return ret; |
| 274 | } |
| 275 | |
| 276 | /* |
| 277 | * Input for n2h should be atleast 2048 to support defalt connections |
| 278 | * of 1024 (IPV4) + 1024 (IPV6) connections. |
| 279 | */ |
| 280 | if ((*new_val < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ)) { |
| 281 | nss_warning("%p: core %d setting %d is less than minimum number of buffer", |
| 282 | nss_ctx, core_num, *new_val); |
Stephen Wang | 0676102 | 2015-03-03 16:38:42 -0800 | [diff] [blame^] | 283 | goto failure; |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | nss_info("%p: core %d number of empty pool buffer is : %d\n", |
| 287 | nss_ctx, core_num, *new_val); |
| 288 | |
| 289 | nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, |
| 290 | NSS_TX_METADATA_TYPE_N2H_EMPTY_POOL_BUF_CFG, |
| 291 | sizeof(struct nss_n2h_empty_pool_buf), |
Vijay Dewangan | 634ce59 | 2015-01-07 17:21:09 -0800 | [diff] [blame] | 292 | nss_n2h_empty_pool_buf_cfg_callback, |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 293 | (void *)core_num); |
| 294 | |
| 295 | nnepbcm = &nnm.msg.empty_pool_buf_cfg; |
| 296 | nnepbcm->pool_size = htonl(*new_val); |
| 297 | nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm); |
| 298 | |
| 299 | if (nss_tx_status != NSS_TX_SUCCESS) { |
| 300 | nss_warning("%p: core %d nss_tx error setting empty pool buffer: %d\n", |
| 301 | nss_ctx, core_num, *new_val); |
Stephen Wang | 0676102 | 2015-03-03 16:38:42 -0800 | [diff] [blame^] | 302 | goto failure; |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | /* |
| 306 | * Blocking call, wait till we get ACK for this msg. |
| 307 | */ |
| 308 | ret = wait_for_completion_timeout(&nss_n2h_nepbcfgp[core_num].complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT)); |
| 309 | if (ret == 0) { |
| 310 | nss_warning("%p: core %d Waiting for ack timed out\n", nss_ctx, core_num); |
Stephen Wang | 0676102 | 2015-03-03 16:38:42 -0800 | [diff] [blame^] | 311 | goto failure; |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | /* |
| 315 | * ACK/NACK received from NSS FW |
| 316 | * If ACK: Callback function will update nss_n2h_empty_pool_buf with |
| 317 | * nss_n2h_nepbcfgp.num_conn_valid, which holds the user input |
| 318 | */ |
| 319 | if (NSS_FAILURE == nss_n2h_nepbcfgp[core_num].response) { |
Stephen Wang | 0676102 | 2015-03-03 16:38:42 -0800 | [diff] [blame^] | 320 | goto failure; |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | up(&nss_n2h_nepbcfgp[core_num].sem); |
| 324 | return NSS_SUCCESS; |
Stephen Wang | 0676102 | 2015-03-03 16:38:42 -0800 | [diff] [blame^] | 325 | |
| 326 | failure: |
| 327 | /* |
| 328 | * Restore the current_value to its previous state |
| 329 | */ |
| 330 | *new_val = nss_n2h_nepbcfgp[core_num].current_value; |
| 331 | up(&nss_n2h_nepbcfgp[core_num].sem); |
| 332 | return NSS_FAILURE; |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | /* |
Radha krishna Simha Jiguru | 7f424d5 | 2015-02-10 19:41:01 +0530 | [diff] [blame] | 336 | * nss_n2h_flush_payloads() |
| 337 | * Sends a command down to NSS for flushing all payloads |
| 338 | */ |
| 339 | nss_tx_status_t nss_n2h_flush_payloads(struct nss_ctx_instance *nss_ctx) |
| 340 | { |
| 341 | struct nss_n2h_msg nnm; |
| 342 | struct nss_n2h_flush_payloads *nnflshpl; |
| 343 | nss_tx_status_t nss_tx_status; |
| 344 | |
| 345 | nnflshpl = &nnm.msg.flush_payloads; |
| 346 | |
| 347 | /* |
| 348 | * TODO: No additional information sent in message |
| 349 | * as of now. Need to initialize message content accordingly |
| 350 | * if needed. |
| 351 | */ |
| 352 | nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, |
| 353 | NSS_TX_METADATA_TYPE_N2H_FLUSH_PAYLOADS, |
| 354 | sizeof(struct nss_n2h_flush_payloads), |
| 355 | NULL, |
| 356 | NULL); |
| 357 | |
| 358 | nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm); |
| 359 | if (nss_tx_status != NSS_TX_SUCCESS) { |
| 360 | nss_warning("%p: failed to send flush payloads command to NSS\n", |
| 361 | nss_ctx); |
| 362 | |
| 363 | return NSS_TX_FAILURE; |
| 364 | } |
| 365 | |
| 366 | return NSS_TX_SUCCESS; |
| 367 | } |
| 368 | |
| 369 | /* |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 370 | * nss_n2h_empty_pool_buf_core1_handler() |
| 371 | * Sets the number of empty buffer for core 1 |
| 372 | */ |
| 373 | static int nss_n2h_empty_pool_buf_cfg_core1_handler(ctl_table *ctl, |
| 374 | int write, void __user *buffer, |
| 375 | size_t *lenp, loff_t *ppos) |
| 376 | { |
| 377 | return nss_n2h_set_empty_pool_buf(ctl, write, buffer, lenp, ppos, |
| 378 | NSS_CORE_1, &nss_n2h_empty_pool_buf_cfg[NSS_CORE_1]); |
| 379 | } |
| 380 | |
| 381 | /* |
| 382 | * nss_n2h_empty_pool_buf_core0_handler() |
| 383 | * Sets the number of empty buffer for core 0 |
| 384 | */ |
| 385 | static int nss_n2h_empty_pool_buf_cfg_core0_handler(ctl_table *ctl, |
| 386 | int write, void __user *buffer, |
| 387 | size_t *lenp, loff_t *ppos) |
| 388 | { |
| 389 | return nss_n2h_set_empty_pool_buf(ctl, write, buffer, lenp, ppos, |
| 390 | NSS_CORE_0, &nss_n2h_empty_pool_buf_cfg[NSS_CORE_0]); |
| 391 | } |
| 392 | |
Vijay Dewangan | 634ce59 | 2015-01-07 17:21:09 -0800 | [diff] [blame] | 393 | /* |
| 394 | * nss_n2h_rps_cfg() |
| 395 | * Send Message to NSS to enable RPS. |
| 396 | */ |
| 397 | nss_tx_status_t nss_n2h_rps_cfg(struct nss_ctx_instance *nss_ctx, int enable_rps) |
| 398 | { |
| 399 | struct nss_n2h_msg nnm; |
| 400 | struct nss_n2h_rps *rps_cfg; |
| 401 | nss_tx_status_t nss_tx_status; |
| 402 | int ret; |
| 403 | |
| 404 | down(&nss_n2h_rcp.sem); |
| 405 | nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, NSS_TX_METADATA_TYPE_N2H_RPS_CFG, |
| 406 | sizeof(struct nss_n2h_rps), |
| 407 | nss_n2h_rps_cfg_callback, |
| 408 | (void *)nss_ctx); |
| 409 | |
| 410 | rps_cfg = &nnm.msg.rps_cfg; |
| 411 | rps_cfg->enable = enable_rps; |
| 412 | |
| 413 | nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm); |
| 414 | |
| 415 | if (nss_tx_status != NSS_TX_SUCCESS) { |
| 416 | nss_warning("%p: nss_tx error setting rps\n", nss_ctx); |
| 417 | |
| 418 | up(&nss_n2h_rcp.sem); |
| 419 | return NSS_FAILURE; |
| 420 | } |
| 421 | |
| 422 | /* |
| 423 | * Blocking call, wait till we get ACK for this msg. |
| 424 | */ |
| 425 | ret = wait_for_completion_timeout(&nss_n2h_rcp.complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT)); |
| 426 | if (ret == 0) { |
| 427 | nss_warning("%p: Waiting for ack timed out\n", nss_ctx); |
| 428 | up(&nss_n2h_rcp.sem); |
| 429 | return NSS_FAILURE; |
| 430 | } |
| 431 | |
| 432 | /* |
| 433 | * ACK/NACK received from NSS FW |
| 434 | * If ACK: Callback function will update nss_n2h_empty_pool_buf with |
| 435 | * nss_n2h_nepbcfgp.num_conn_valid, which holds the user input |
| 436 | */ |
| 437 | if (NSS_FAILURE == nss_n2h_rcp.response) { |
| 438 | up(&nss_n2h_rcp.sem); |
| 439 | return NSS_FAILURE; |
| 440 | } |
| 441 | |
| 442 | up(&nss_n2h_rcp.sem); |
| 443 | return NSS_SUCCESS; |
| 444 | } |
| 445 | |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 446 | static ctl_table nss_n2h_table[] = { |
| 447 | { |
| 448 | .procname = "n2h_empty_pool_buf_core0", |
| 449 | .data = &nss_n2h_empty_pool_buf_cfg[NSS_CORE_0], |
| 450 | .maxlen = sizeof(int), |
| 451 | .mode = 0644, |
| 452 | .proc_handler = &nss_n2h_empty_pool_buf_cfg_core0_handler, |
| 453 | }, |
| 454 | { |
| 455 | .procname = "n2h_empty_pool_buf_core1", |
| 456 | .data = &nss_n2h_empty_pool_buf_cfg[NSS_CORE_1], |
| 457 | .maxlen = sizeof(int), |
| 458 | .mode = 0644, |
| 459 | .proc_handler = &nss_n2h_empty_pool_buf_cfg_core1_handler, |
| 460 | }, |
| 461 | |
| 462 | { } |
| 463 | }; |
| 464 | |
| 465 | static ctl_table nss_n2h_dir[] = { |
| 466 | { |
| 467 | .procname = "n2hcfg", |
| 468 | .mode = 0555, |
| 469 | .child = nss_n2h_table, |
| 470 | }, |
| 471 | { } |
| 472 | }; |
| 473 | |
| 474 | |
| 475 | static ctl_table nss_n2h_root_dir[] = { |
| 476 | { |
| 477 | .procname = "nss", |
| 478 | .mode = 0555, |
| 479 | .child = nss_n2h_dir, |
| 480 | }, |
| 481 | { } |
| 482 | }; |
| 483 | |
| 484 | static ctl_table nss_n2h_root[] = { |
| 485 | { |
| 486 | .procname = "dev", |
| 487 | .mode = 0555, |
| 488 | .child = nss_n2h_root_dir, |
| 489 | }, |
| 490 | { } |
| 491 | }; |
| 492 | |
| 493 | static struct ctl_table_header *nss_n2h_header; |
| 494 | |
| 495 | /* |
| 496 | * nss_n2h_msg_init() |
| 497 | * Initialize IPv4 message. |
| 498 | */ |
| 499 | void nss_n2h_msg_init(struct nss_n2h_msg *nim, uint16_t if_num, uint32_t type, |
Vijay Dewangan | 634ce59 | 2015-01-07 17:21:09 -0800 | [diff] [blame] | 500 | uint32_t len, nss_n2h_msg_callback_t cb, void *app_data) |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 501 | { |
| 502 | nss_cmn_msg_init(&nim->cm, if_num, type, len, (void *)cb, app_data); |
| 503 | } |
| 504 | |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 505 | /* |
| 506 | * nss_n2h_register_sysctl() |
| 507 | * Register sysctl specific to n2h |
| 508 | */ |
| 509 | void nss_n2h_empty_pool_buf_register_sysctl(void) |
| 510 | { |
| 511 | /* |
| 512 | * Register sysctl table. |
| 513 | */ |
| 514 | nss_n2h_header = register_sysctl_table(nss_n2h_root); |
| 515 | |
| 516 | /* |
| 517 | * Core0 |
| 518 | */ |
| 519 | sema_init(&nss_n2h_nepbcfgp[NSS_CORE_0].sem, 1); |
| 520 | init_completion(&nss_n2h_nepbcfgp[NSS_CORE_0].complete); |
| 521 | nss_n2h_nepbcfgp[NSS_CORE_0].current_value = nss_n2h_empty_pool_buf_cfg[NSS_CORE_0]; |
| 522 | |
| 523 | /* |
| 524 | * Core1 |
| 525 | */ |
| 526 | sema_init(&nss_n2h_nepbcfgp[NSS_CORE_1].sem, 1); |
| 527 | init_completion(&nss_n2h_nepbcfgp[NSS_CORE_1].complete); |
| 528 | nss_n2h_nepbcfgp[NSS_CORE_1].current_value = nss_n2h_empty_pool_buf_cfg[NSS_CORE_1]; |
| 529 | } |
| 530 | |
| 531 | /* |
| 532 | * nss_n2h_unregister_sysctl() |
| 533 | * Unregister sysctl specific to n2h |
| 534 | */ |
| 535 | void nss_n2h_empty_pool_buf_unregister_sysctl(void) |
| 536 | { |
| 537 | /* |
| 538 | * Unregister sysctl table. |
| 539 | */ |
| 540 | if (nss_n2h_header) { |
| 541 | unregister_sysctl_table(nss_n2h_header); |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | /* |
| 546 | * nss_n2h_tx_msg() |
| 547 | * Send messages to NSS n2h pacakge |
| 548 | */ |
| 549 | nss_tx_status_t nss_n2h_tx_msg(struct nss_ctx_instance *nss_ctx, struct nss_n2h_msg *nnm) |
| 550 | { |
| 551 | struct nss_n2h_msg *nnm2; |
| 552 | struct nss_cmn_msg *ncm = &nnm->cm; |
| 553 | struct sk_buff *nbuf; |
| 554 | nss_tx_status_t status; |
| 555 | |
| 556 | NSS_VERIFY_CTX_MAGIC(nss_ctx); |
| 557 | if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) { |
| 558 | return NSS_TX_FAILURE_NOT_READY; |
| 559 | } |
| 560 | |
| 561 | /* |
| 562 | * Sanity check the message |
| 563 | */ |
| 564 | if (ncm->interface != NSS_N2H_INTERFACE) { |
| 565 | nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface); |
| 566 | return NSS_TX_FAILURE; |
| 567 | } |
| 568 | |
| 569 | if (ncm->type >= NSS_METADATA_TYPE_N2H_MAX) { |
| 570 | nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type); |
| 571 | return NSS_TX_FAILURE; |
| 572 | } |
| 573 | |
| 574 | if (ncm->len > sizeof(struct nss_n2h_msg)) { |
| 575 | nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface); |
| 576 | return NSS_TX_FAILURE; |
| 577 | } |
| 578 | |
| 579 | |
| 580 | nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE); |
| 581 | if (unlikely(!nbuf)) { |
| 582 | spin_lock_bh(&nss_ctx->nss_top->stats_lock); |
| 583 | nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]++; |
| 584 | spin_unlock_bh(&nss_ctx->nss_top->stats_lock); |
| 585 | return NSS_TX_FAILURE; |
| 586 | } |
| 587 | |
| 588 | /* |
| 589 | * Copy the message to our skb. |
| 590 | */ |
| 591 | nnm2 = (struct nss_n2h_msg *)skb_put(nbuf, sizeof(struct nss_n2h_msg)); |
| 592 | memcpy(nnm2, nnm, sizeof(struct nss_n2h_msg)); |
| 593 | status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0); |
| 594 | if (status != NSS_CORE_STATUS_SUCCESS) { |
| 595 | dev_kfree_skb_any(nbuf); |
| 596 | nss_info("%p: unable to enqueue 'nss frequency change' - marked as stopped\n", nss_ctx); |
| 597 | return NSS_TX_FAILURE; |
| 598 | } |
| 599 | |
| 600 | nss_hal_send_interrupt(nss_ctx->nmap, |
| 601 | nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit, |
| 602 | NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE); |
| 603 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]); |
| 604 | return NSS_TX_SUCCESS; |
| 605 | } |
| 606 | |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 607 | /* |
| 608 | * nss_n2h_notify_register() |
| 609 | * Register to received N2H events. |
| 610 | * |
| 611 | * NOTE: Do we want to pass an nss_ctx here so that we can register for n2h on any core? |
| 612 | */ |
| 613 | struct nss_ctx_instance *nss_n2h_notify_register(int core, nss_n2h_msg_callback_t cb, void *app_data) |
| 614 | { |
| 615 | if (core >= NSS_MAX_CORES) { |
| 616 | nss_warning("Input core number %d is wrong \n", core); |
| 617 | return NULL; |
| 618 | } |
| 619 | /* |
| 620 | * TODO: We need to have a new array in support of the new API |
| 621 | * TODO: If we use a per-context array, we would move the array into nss_ctx based. |
| 622 | */ |
| 623 | nss_n2h_rd[core].n2h_callback = cb; |
| 624 | nss_n2h_rd[core].app_data = app_data; |
| 625 | return &nss_top_main.nss[core]; |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | /* |
| 629 | * nss_n2h_register_handler() |
| 630 | */ |
| 631 | void nss_n2h_register_handler() |
| 632 | { |
Sundarajan Srinivasan | f1e5746 | 2014-09-17 15:24:01 -0700 | [diff] [blame] | 633 | nss_core_register_handler(NSS_N2H_INTERFACE, nss_n2h_interface_handler, NULL); |
| 634 | |
Vijay Dewangan | 634ce59 | 2015-01-07 17:21:09 -0800 | [diff] [blame] | 635 | /* |
| 636 | * RPS sema init |
| 637 | */ |
| 638 | sema_init(&nss_n2h_rcp.sem, 1); |
| 639 | init_completion(&nss_n2h_rcp.complete); |
| 640 | |
| 641 | |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 642 | nss_n2h_notify_register(NSS_CORE_0, NULL, NULL); |
| 643 | nss_n2h_notify_register(NSS_CORE_1, NULL, NULL); |
| 644 | |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 645 | } |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 646 | |
| 647 | EXPORT_SYMBOL(nss_n2h_notify_register); |
Vijay Dewangan | ac7efc4 | 2015-02-09 16:04:53 -0800 | [diff] [blame] | 648 | EXPORT_SYMBOL(nss_n2h_empty_pool_buf_register_sysctl); |