Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Pamidipati, Vijay | ee9c297 | 2016-01-10 08:13:19 +0530 | [diff] [blame] | 3 | * Copyright (c) 2013-2016, 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 | |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 24 | #define NSS_N2H_MAX_BUF_POOL_SIZE (1024 * 1024 * 8) /* 8MB */ |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 25 | #define NSS_N2H_MIN_EMPTY_POOL_BUF_SZ 32 |
Pamidipati, Vijay | ee9c297 | 2016-01-10 08:13:19 +0530 | [diff] [blame] | 26 | #define NSS_N2H_MAX_EMPTY_POOL_BUF_SZ 65536 |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 27 | #define NSS_N2H_DEFAULT_EMPTY_POOL_BUF_SZ 8192 |
Pamidipati, Vijay | efcc469 | 2014-05-09 14:47:38 +0530 | [diff] [blame] | 28 | |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 29 | int nss_n2h_empty_pool_buf_cfg[NSS_MAX_CORES] __read_mostly = {-1, -1}; |
| 30 | int nss_n2h_water_mark[NSS_MAX_CORES][2] __read_mostly = {{-1, -1}, {-1, -1} }; |
Pamidipati, Vijay | ee9c297 | 2016-01-10 08:13:19 +0530 | [diff] [blame] | 31 | int nss_n2h_wifi_pool_buf_cfg __read_mostly = -1; |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 32 | int nss_n2h_rps_config __read_mostly; |
| 33 | int nss_n2h_core0_mitigation_cfg __read_mostly = 1; |
| 34 | int nss_n2h_core1_mitigation_cfg __read_mostly = 1; |
| 35 | int nss_n2h_core0_add_buf_pool_size __read_mostly; |
| 36 | int nss_n2h_core1_add_buf_pool_size __read_mostly; |
Pamidipati, Vijay | efcc469 | 2014-05-09 14:47:38 +0530 | [diff] [blame] | 37 | |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 38 | struct nss_n2h_registered_data { |
| 39 | nss_n2h_msg_callback_t n2h_callback; |
| 40 | void *app_data; |
| 41 | }; |
Pamidipati, Vijay | efcc469 | 2014-05-09 14:47:38 +0530 | [diff] [blame] | 42 | |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 43 | static struct nss_n2h_cfg_pvt nss_n2h_nepbcfgp[NSS_MAX_CORES]; |
| 44 | static struct nss_n2h_registered_data nss_n2h_rd[NSS_MAX_CORES]; |
Vijay Dewangan | 634ce59 | 2015-01-07 17:21:09 -0800 | [diff] [blame] | 45 | static struct nss_n2h_cfg_pvt nss_n2h_rcp; |
Kalyan Tallapragada | b50e890 | 2015-08-06 17:00:54 +0530 | [diff] [blame] | 46 | static struct nss_n2h_cfg_pvt nss_n2h_mitigationcp[NSS_CORE_MAX]; |
| 47 | static struct nss_n2h_cfg_pvt nss_n2h_bufcp[NSS_CORE_MAX]; |
Pamidipati, Vijay | ee9c297 | 2016-01-10 08:13:19 +0530 | [diff] [blame] | 48 | static struct nss_n2h_cfg_pvt nss_n2h_wp; |
Pamidipati, Vijay | efcc469 | 2014-05-09 14:47:38 +0530 | [diff] [blame] | 49 | |
| 50 | /* |
Sundarajan Srinivasan | f1e5746 | 2014-09-17 15:24:01 -0700 | [diff] [blame] | 51 | * nss_n2h_stats_sync() |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 52 | * Handle the syncing of NSS statistics. |
| 53 | */ |
Sundarajan Srinivasan | f1e5746 | 2014-09-17 15:24:01 -0700 | [diff] [blame] | 54 | 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] | 55 | { |
| 56 | struct nss_top_instance *nss_top = nss_ctx->nss_top; |
| 57 | |
| 58 | spin_lock_bh(&nss_top->stats_lock); |
| 59 | |
| 60 | /* |
| 61 | * common node stats |
| 62 | */ |
| 63 | nss_ctx->stats_n2h[NSS_STATS_NODE_RX_PKTS] += nnss->node_stats.rx_packets; |
| 64 | nss_ctx->stats_n2h[NSS_STATS_NODE_RX_BYTES] += nnss->node_stats.rx_bytes; |
| 65 | nss_ctx->stats_n2h[NSS_STATS_NODE_RX_DROPPED] += nnss->node_stats.rx_dropped; |
| 66 | nss_ctx->stats_n2h[NSS_STATS_NODE_TX_PKTS] += nnss->node_stats.tx_packets; |
| 67 | nss_ctx->stats_n2h[NSS_STATS_NODE_TX_BYTES] += nnss->node_stats.tx_bytes; |
| 68 | |
| 69 | /* |
| 70 | * General N2H stats |
| 71 | */ |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 72 | nss_ctx->stats_n2h[NSS_STATS_N2H_QUEUE_DROPPED] += nnss->queue_dropped; |
| 73 | nss_ctx->stats_n2h[NSS_STATS_N2H_TOTAL_TICKS] += nnss->total_ticks; |
| 74 | nss_ctx->stats_n2h[NSS_STATS_N2H_WORST_CASE_TICKS] += nnss->worst_case_ticks; |
| 75 | nss_ctx->stats_n2h[NSS_STATS_N2H_ITERATIONS] += nnss->iterations; |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 76 | |
| 77 | /* |
Thomas Wu | 3fd8dd7 | 2014-06-11 15:57:05 -0700 | [diff] [blame] | 78 | * pbuf manager ocm and default pool stats |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 79 | */ |
Thomas Wu | 3fd8dd7 | 2014-06-11 15:57:05 -0700 | [diff] [blame] | 80 | nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_OCM_ALLOC_FAILS] += nnss->pbuf_ocm_stats.pbuf_alloc_fails; |
| 81 | nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_OCM_FREE_COUNT] = nnss->pbuf_ocm_stats.pbuf_free_count; |
| 82 | nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_OCM_TOTAL_COUNT] = nnss->pbuf_ocm_stats.pbuf_total_count; |
| 83 | |
| 84 | nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_DEFAULT_ALLOC_FAILS] += nnss->pbuf_default_stats.pbuf_alloc_fails; |
| 85 | nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_DEFAULT_FREE_COUNT] = nnss->pbuf_default_stats.pbuf_free_count; |
| 86 | nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_DEFAULT_TOTAL_COUNT] = nnss->pbuf_default_stats.pbuf_total_count; |
| 87 | |
| 88 | /* |
| 89 | * payload mgr stats |
| 90 | */ |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 91 | 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] | 92 | 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] | 93 | |
Sakthi Vignesh Radhakrishnan | 2a8ee96 | 2014-11-22 13:35:38 -0800 | [diff] [blame] | 94 | /* |
| 95 | * Host <=> NSS control traffic stats |
| 96 | */ |
| 97 | nss_ctx->stats_n2h[NSS_STATS_N2H_H2N_CONTROL_PACKETS] += nnss->h2n_ctrl_pkts; |
| 98 | nss_ctx->stats_n2h[NSS_STATS_N2H_H2N_CONTROL_BYTES] += nnss->h2n_ctrl_bytes; |
| 99 | nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_CONTROL_PACKETS] += nnss->n2h_ctrl_pkts; |
| 100 | nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_CONTROL_BYTES] += nnss->n2h_ctrl_bytes; |
| 101 | |
| 102 | /* |
| 103 | * Host <=> NSS control data traffic stats |
| 104 | */ |
| 105 | nss_ctx->stats_n2h[NSS_STATS_N2H_H2N_DATA_PACKETS] += nnss->h2n_data_pkts; |
| 106 | nss_ctx->stats_n2h[NSS_STATS_N2H_H2N_DATA_BYTES] += nnss->h2n_data_bytes; |
| 107 | nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_DATA_PACKETS] += nnss->n2h_data_pkts; |
| 108 | nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_DATA_BYTES] += nnss->n2h_data_bytes; |
| 109 | |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 110 | /* |
| 111 | * Payloads related stats |
| 112 | */ |
| 113 | nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_TOT_PAYLOADS] = nnss->tot_payloads; |
| 114 | |
Guojun Jin | 85dfa7b | 2015-09-02 15:13:56 -0700 | [diff] [blame] | 115 | nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_INTERFACE_INVALID] += nnss->data_interface_invalid; |
| 116 | |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 117 | spin_unlock_bh(&nss_top->stats_lock); |
| 118 | } |
| 119 | |
| 120 | /* |
Sundarajan Srinivasan | f1e5746 | 2014-09-17 15:24:01 -0700 | [diff] [blame] | 121 | * nss_n2h_interface_handler() |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 122 | * Handle NSS -> HLOS messages for N2H node |
| 123 | */ |
Vijay Dewangan | 634ce59 | 2015-01-07 17:21:09 -0800 | [diff] [blame] | 124 | static void nss_n2h_interface_handler(struct nss_ctx_instance *nss_ctx, |
| 125 | struct nss_cmn_msg *ncm, |
| 126 | __attribute__((unused))void *app_data) |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 127 | { |
| 128 | struct nss_n2h_msg *nnm = (struct nss_n2h_msg *)ncm; |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 129 | nss_n2h_msg_callback_t cb; |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 130 | |
Sundarajan Srinivasan | f1e5746 | 2014-09-17 15:24:01 -0700 | [diff] [blame] | 131 | BUG_ON(ncm->interface != NSS_N2H_INTERFACE); |
| 132 | |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 133 | /* |
| 134 | * Is this a valid request/response packet? |
| 135 | */ |
| 136 | if (nnm->cm.type >= NSS_METADATA_TYPE_N2H_MAX) { |
| 137 | nss_warning("%p: received invalid message %d for Offload stats interface", nss_ctx, nnm->cm.type); |
| 138 | return; |
| 139 | } |
| 140 | |
| 141 | switch (nnm->cm.type) { |
Pamidipati, Vijay | efcc469 | 2014-05-09 14:47:38 +0530 | [diff] [blame] | 142 | case NSS_TX_METADATA_TYPE_N2H_RPS_CFG: |
Pamidipati, Vijay | efcc469 | 2014-05-09 14:47:38 +0530 | [diff] [blame] | 143 | 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] | 144 | break; |
| 145 | |
Kalyan Tallapragada | b50e890 | 2015-08-06 17:00:54 +0530 | [diff] [blame] | 146 | case NSS_TX_METADATA_TYPE_N2H_MITIGATION_CFG: |
| 147 | nss_info("NSS N2H mitigation_dis %d \n",nnm->msg.mitigation_cfg.enable); |
| 148 | break; |
| 149 | |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 150 | case NSS_TX_METADATA_TYPE_N2H_EMPTY_POOL_BUF_CFG: |
| 151 | nss_info("%p: empty pool buf cfg response from FW", nss_ctx); |
Pamidipati, Vijay | efcc469 | 2014-05-09 14:47:38 +0530 | [diff] [blame] | 152 | break; |
| 153 | |
Radha krishna Simha Jiguru | 7f424d5 | 2015-02-10 19:41:01 +0530 | [diff] [blame] | 154 | case NSS_TX_METADATA_TYPE_N2H_FLUSH_PAYLOADS: |
| 155 | nss_info("%p: flush payloads cmd response from FW", nss_ctx); |
| 156 | break; |
| 157 | |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 158 | case NSS_RX_METADATA_TYPE_N2H_STATS_SYNC: |
Sundarajan Srinivasan | f1e5746 | 2014-09-17 15:24:01 -0700 | [diff] [blame] | 159 | nss_n2h_stats_sync(nss_ctx, &nnm->msg.stats_sync); |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 160 | break; |
| 161 | |
| 162 | default: |
| 163 | if (ncm->response != NSS_CMN_RESPONSE_ACK) { |
| 164 | /* |
| 165 | * Check response |
| 166 | */ |
| 167 | nss_info("%p: Received response %d for type %d, interface %d", |
| 168 | nss_ctx, ncm->response, ncm->type, ncm->interface); |
| 169 | } |
| 170 | } |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 171 | |
| 172 | /* |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 173 | * Update the callback and app_data for NOTIFY messages, n2h sends all notify messages |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 174 | * to the same callback/app_data. |
| 175 | */ |
| 176 | if (nnm->cm.response == NSS_CMM_RESPONSE_NOTIFY) { |
| 177 | /* |
| 178 | * Place holder for the user to create right call |
| 179 | * back and app data when response is NSS_CMM_RESPONSE_NOTIFY |
| 180 | */ |
| 181 | ncm->cb = (uint32_t)nss_n2h_rd[nss_ctx->id].n2h_callback; |
| 182 | ncm->app_data = (uint32_t)nss_n2h_rd[nss_ctx->id].app_data; |
| 183 | } |
| 184 | |
| 185 | /* |
| 186 | * Do we have a callback? |
| 187 | */ |
| 188 | if (!ncm->cb) { |
| 189 | return; |
| 190 | } |
| 191 | |
| 192 | /* |
| 193 | * Callback |
| 194 | */ |
| 195 | cb = (nss_n2h_msg_callback_t)ncm->cb; |
| 196 | cb((void *)ncm->app_data, nnm); |
| 197 | } |
| 198 | |
| 199 | /* |
Vijay Dewangan | 634ce59 | 2015-01-07 17:21:09 -0800 | [diff] [blame] | 200 | * nss_n2h_rps_cfg_callback() |
| 201 | * call back function for rps configuration |
| 202 | */ |
| 203 | static void nss_n2h_rps_cfg_callback(void *app_data, struct nss_n2h_msg *nnm) |
| 204 | { |
| 205 | struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)app_data; |
| 206 | if (nnm->cm.response != NSS_CMN_RESPONSE_ACK) { |
| 207 | |
| 208 | /* |
| 209 | * Error, hence we are not updating the nss_n2h_empty_pool_buf |
| 210 | * Restore the current_value to its previous state |
| 211 | */ |
| 212 | nss_n2h_rcp.response = NSS_FAILURE; |
| 213 | complete(&nss_n2h_rcp.complete); |
| 214 | nss_warning("%p: RPS configuration failed : %d\n", nss_ctx, |
| 215 | nnm->cm.error); |
| 216 | return; |
| 217 | } |
| 218 | |
| 219 | nss_info("%p: RPS configuration succeeded: %d\n", nss_ctx, |
| 220 | nnm->cm.error); |
| 221 | nss_ctx->n2h_rps_en = nnm->msg.rps_cfg.enable; |
| 222 | nss_n2h_rcp.response = NSS_SUCCESS; |
| 223 | complete(&nss_n2h_rcp.complete); |
| 224 | } |
| 225 | |
| 226 | /* |
Kalyan Tallapragada | b50e890 | 2015-08-06 17:00:54 +0530 | [diff] [blame] | 227 | * nss_n2h_mitigation_cfg_callback() |
| 228 | * call back function for mitigation configuration |
| 229 | */ |
| 230 | static void nss_n2h_mitigation_cfg_callback(void *app_data, struct nss_n2h_msg *nnm) |
| 231 | { |
| 232 | int core_num = (int)app_data; |
| 233 | struct nss_top_instance *nss_top = &nss_top_main; |
| 234 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num]; |
| 235 | |
| 236 | if (nnm->cm.response != NSS_CMN_RESPONSE_ACK) { |
| 237 | |
| 238 | /* |
| 239 | * Error, hence we are not updating the nss_n2h_mitigate_en |
| 240 | */ |
| 241 | nss_n2h_mitigationcp[core_num].response = NSS_FAILURE; |
| 242 | complete(&nss_n2h_mitigationcp[core_num].complete); |
| 243 | nss_warning("core%d: MITIGATION configuration failed : %d\n", core_num, nnm->cm.error); |
| 244 | return; |
| 245 | } |
| 246 | |
| 247 | nss_info("core%d: MITIGATION configuration succeeded: %d\n", core_num, nnm->cm.error); |
| 248 | |
| 249 | nss_ctx->n2h_mitigate_en = nnm->msg.mitigation_cfg.enable; |
| 250 | nss_n2h_mitigationcp[core_num].response = NSS_SUCCESS; |
| 251 | complete(&nss_n2h_mitigationcp[core_num].complete); |
| 252 | } |
| 253 | |
| 254 | /* |
| 255 | * nss_n2h_buf_cfg_callback() |
| 256 | * call back function for pbuf configuration |
| 257 | */ |
| 258 | static void nss_n2h_bufs_cfg_callback(void *app_data, struct nss_n2h_msg *nnm) |
| 259 | { |
| 260 | int core_num = (int)app_data; |
| 261 | unsigned int allocated_sz; |
| 262 | |
| 263 | struct nss_top_instance *nss_top = &nss_top_main; |
| 264 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num]; |
| 265 | |
| 266 | if (nnm->cm.response != NSS_CMN_RESPONSE_ACK) { |
| 267 | nss_n2h_bufcp[core_num].response = NSS_FAILURE; |
| 268 | nss_warning("core%d: buf configuration failed : %d\n", core_num, nnm->cm.error); |
| 269 | goto done; |
| 270 | } |
| 271 | |
| 272 | nss_info("core%d: buf configuration succeeded: %d\n", core_num, nnm->cm.error); |
| 273 | |
| 274 | allocated_sz = nnm->msg.buf_pool.nss_buf_page_size * nnm->msg.buf_pool.nss_buf_num_pages; |
| 275 | nss_ctx->buf_sz_allocated += allocated_sz; |
| 276 | |
| 277 | nss_n2h_bufcp[core_num].response = NSS_SUCCESS; |
| 278 | |
| 279 | done: |
| 280 | complete(&nss_n2h_bufcp[core_num].complete); |
| 281 | } |
| 282 | |
| 283 | /* |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 284 | * nss_n2h_payload_stats_callback() |
| 285 | * It gets called response to payload accounting. |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 286 | */ |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 287 | static void nss_n2h_payload_stats_callback(void *app_data, |
| 288 | struct nss_n2h_msg *nnm) |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 289 | { |
| 290 | int core_num = (int)app_data; |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 291 | |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 292 | if (nnm->cm.response != NSS_CMN_RESPONSE_ACK) { |
| 293 | struct nss_n2h_empty_pool_buf *nnepbcm; |
| 294 | nnepbcm = &nnm->msg.empty_pool_buf_cfg; |
| 295 | |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 296 | nss_warning("%d: core empty pool buf set failure: %d\n", |
| 297 | core_num, nnm->cm.error); |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 298 | nss_n2h_nepbcfgp[core_num].response = NSS_FAILURE; |
| 299 | complete(&nss_n2h_nepbcfgp[core_num].complete); |
| 300 | return; |
| 301 | } |
| 302 | |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 303 | if (nnm->cm.type == NSS_TX_METADATA_TYPE_GET_PAYLOAD_INFO) { |
| 304 | nss_n2h_nepbcfgp[core_num].empty_buf_pool = |
| 305 | ntohl(nnm->msg.payload_info.pool_size); |
| 306 | nss_n2h_nepbcfgp[core_num].low_water = |
| 307 | ntohl(nnm->msg.payload_info.low_water); |
| 308 | nss_n2h_nepbcfgp[core_num].high_water = |
| 309 | ntohl(nnm->msg.payload_info.high_water); |
| 310 | } |
| 311 | |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 312 | nss_n2h_nepbcfgp[core_num].response = NSS_SUCCESS; |
| 313 | complete(&nss_n2h_nepbcfgp[core_num].complete); |
| 314 | } |
| 315 | |
| 316 | /* |
Pamidipati, Vijay | ee9c297 | 2016-01-10 08:13:19 +0530 | [diff] [blame] | 317 | * nss_n2h_set_wifi_payloads_callback() |
| 318 | * call back function for response to wifi pool configuration |
| 319 | * |
| 320 | */ |
| 321 | static void nss_n2h_set_wifi_payloads_callback(void *app_data, |
| 322 | struct nss_n2h_msg *nnm) |
| 323 | { |
| 324 | struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)app_data; |
| 325 | if (nnm->cm.response != NSS_CMN_RESPONSE_ACK) { |
| 326 | |
| 327 | nss_n2h_wp.response = NSS_FAILURE; |
| 328 | complete(&nss_n2h_wp.complete); |
| 329 | nss_warning("%p: wifi pool configuration failed : %d\n", nss_ctx, |
| 330 | nnm->cm.error); |
| 331 | return; |
| 332 | } |
| 333 | |
| 334 | nss_info("%p: wifi payload configuration succeeded: %d\n", nss_ctx, |
| 335 | nnm->cm.error); |
| 336 | nss_n2h_wp.response = NSS_SUCCESS; |
| 337 | complete(&nss_n2h_wp.complete); |
| 338 | } |
| 339 | |
| 340 | /* |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 341 | * nss_n2h_get_payload_info() |
| 342 | * Gets Payload information |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 343 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame^] | 344 | static int nss_n2h_get_payload_info(struct ctl_table *ctl, int write, |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 345 | void __user *buffer, size_t *lenp, loff_t *ppos, |
| 346 | int core_num) |
| 347 | { |
| 348 | struct nss_top_instance *nss_top = &nss_top_main; |
| 349 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num]; |
| 350 | struct nss_n2h_msg nnm; |
| 351 | struct nss_n2h_payload_info *nnepbcm; |
| 352 | nss_tx_status_t nss_tx_status; |
| 353 | int ret = NSS_FAILURE; |
| 354 | |
| 355 | /* |
| 356 | * Note that semaphore should be already held. |
| 357 | */ |
| 358 | |
| 359 | nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, |
| 360 | NSS_TX_METADATA_TYPE_GET_PAYLOAD_INFO, |
| 361 | sizeof(struct nss_n2h_payload_info), |
| 362 | nss_n2h_payload_stats_callback, |
| 363 | (void *)core_num); |
| 364 | |
| 365 | nnepbcm = &nnm.msg.payload_info; |
| 366 | nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm); |
| 367 | |
| 368 | if (nss_tx_status != NSS_TX_SUCCESS) { |
| 369 | nss_warning("%p: core %d nss_tx error errorn", |
| 370 | nss_ctx, core_num); |
| 371 | return NSS_FAILURE; |
| 372 | } |
| 373 | |
| 374 | /* |
| 375 | * Blocking call, wait till we get ACK for this msg. |
| 376 | */ |
| 377 | ret = wait_for_completion_timeout(&nss_n2h_nepbcfgp[core_num].complete, |
| 378 | msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT)); |
| 379 | if (ret == 0) { |
| 380 | nss_warning("%p: core %d waiting for ack timed out\n", nss_ctx, |
| 381 | core_num); |
| 382 | return NSS_FAILURE; |
| 383 | } |
| 384 | |
| 385 | if (NSS_FAILURE == nss_n2h_nepbcfgp[core_num].response) { |
| 386 | nss_warning("%p: core %d response returned failure\n", nss_ctx, |
| 387 | core_num); |
| 388 | return NSS_FAILURE; |
| 389 | } |
| 390 | |
| 391 | return NSS_SUCCESS; |
| 392 | } |
| 393 | |
| 394 | /* |
| 395 | * nss_n2h_set_empty_pool_buf() |
| 396 | * Sets empty pool buffer |
| 397 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame^] | 398 | static int nss_n2h_set_empty_pool_buf(struct ctl_table *ctl, int write, |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 399 | void __user *buffer, |
| 400 | size_t *lenp, loff_t *ppos, |
| 401 | int core_num, int *new_val) |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 402 | { |
| 403 | struct nss_top_instance *nss_top = &nss_top_main; |
| 404 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num]; |
| 405 | struct nss_n2h_msg nnm; |
| 406 | struct nss_n2h_empty_pool_buf *nnepbcm; |
| 407 | nss_tx_status_t nss_tx_status; |
| 408 | int ret = NSS_FAILURE; |
| 409 | |
| 410 | /* |
| 411 | * Acquiring semaphore |
| 412 | */ |
| 413 | down(&nss_n2h_nepbcfgp[core_num].sem); |
| 414 | |
| 415 | /* |
| 416 | * Take snap shot of current value |
| 417 | */ |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 418 | nss_n2h_nepbcfgp[core_num].empty_buf_pool = *new_val; |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 419 | |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 420 | if (!write) { |
| 421 | ret = nss_n2h_get_payload_info(ctl, write, buffer, lenp, ppos, |
| 422 | core_num); |
| 423 | *new_val = nss_n2h_nepbcfgp[core_num].empty_buf_pool; |
| 424 | if (ret == NSS_FAILURE) { |
| 425 | up(&nss_n2h_nepbcfgp[core_num].sem); |
| 426 | return -EBUSY; |
| 427 | } |
| 428 | |
| 429 | up(&nss_n2h_nepbcfgp[core_num].sem); |
| 430 | |
| 431 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 432 | return ret; |
| 433 | } |
| 434 | |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 435 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 436 | if (ret) { |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 437 | up(&nss_n2h_nepbcfgp[core_num].sem); |
| 438 | return ret; |
| 439 | } |
| 440 | |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 441 | if ((*new_val < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ)) { |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 442 | nss_warning("%p: core %d setting %d < min number of buffer", |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 443 | nss_ctx, core_num, *new_val); |
Stephen Wang | 0676102 | 2015-03-03 16:38:42 -0800 | [diff] [blame] | 444 | goto failure; |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | nss_info("%p: core %d number of empty pool buffer is : %d\n", |
| 448 | nss_ctx, core_num, *new_val); |
| 449 | |
| 450 | nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, |
| 451 | NSS_TX_METADATA_TYPE_N2H_EMPTY_POOL_BUF_CFG, |
| 452 | sizeof(struct nss_n2h_empty_pool_buf), |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 453 | nss_n2h_payload_stats_callback, |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 454 | (void *)core_num); |
| 455 | |
| 456 | nnepbcm = &nnm.msg.empty_pool_buf_cfg; |
| 457 | nnepbcm->pool_size = htonl(*new_val); |
| 458 | nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm); |
| 459 | |
| 460 | if (nss_tx_status != NSS_TX_SUCCESS) { |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 461 | nss_warning("%p: core %d nss_tx error empty pool buffer: %d\n", |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 462 | nss_ctx, core_num, *new_val); |
Stephen Wang | 0676102 | 2015-03-03 16:38:42 -0800 | [diff] [blame] | 463 | goto failure; |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | /* |
| 467 | * Blocking call, wait till we get ACK for this msg. |
| 468 | */ |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 469 | ret = wait_for_completion_timeout(&nss_n2h_nepbcfgp[core_num].complete, |
| 470 | msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT)); |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 471 | if (ret == 0) { |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 472 | nss_warning("%p: core %d Waiting for ack timed out\n", nss_ctx, |
| 473 | core_num); |
Stephen Wang | 0676102 | 2015-03-03 16:38:42 -0800 | [diff] [blame] | 474 | goto failure; |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | /* |
| 478 | * ACK/NACK received from NSS FW |
| 479 | * If ACK: Callback function will update nss_n2h_empty_pool_buf with |
| 480 | * nss_n2h_nepbcfgp.num_conn_valid, which holds the user input |
| 481 | */ |
| 482 | if (NSS_FAILURE == nss_n2h_nepbcfgp[core_num].response) { |
Stephen Wang | 0676102 | 2015-03-03 16:38:42 -0800 | [diff] [blame] | 483 | goto failure; |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | up(&nss_n2h_nepbcfgp[core_num].sem); |
Thomas Wu | 651b390 | 2015-05-12 11:21:09 -0700 | [diff] [blame] | 487 | return 0; |
Stephen Wang | 0676102 | 2015-03-03 16:38:42 -0800 | [diff] [blame] | 488 | |
| 489 | failure: |
| 490 | /* |
| 491 | * Restore the current_value to its previous state |
| 492 | */ |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 493 | *new_val = nss_n2h_nepbcfgp[core_num].empty_buf_pool; |
| 494 | up(&nss_n2h_nepbcfgp[core_num].sem); |
| 495 | return NSS_FAILURE; |
| 496 | } |
| 497 | |
| 498 | /* |
| 499 | * nss_n2h_set_water_mark() |
| 500 | * Sets water mark for N2H SOS |
| 501 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame^] | 502 | static int nss_n2h_set_water_mark(struct ctl_table *ctl, int write, |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 503 | void __user *buffer, |
| 504 | size_t *lenp, loff_t *ppos, |
| 505 | int core_num, int *low, int *high) |
| 506 | { |
| 507 | struct nss_top_instance *nss_top = &nss_top_main; |
| 508 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num]; |
| 509 | struct nss_n2h_msg nnm; |
| 510 | struct nss_n2h_water_mark *wm; |
| 511 | nss_tx_status_t nss_tx_status; |
| 512 | int ret = NSS_FAILURE; |
| 513 | |
| 514 | /* |
| 515 | * Acquiring semaphore |
| 516 | */ |
| 517 | down(&nss_n2h_nepbcfgp[core_num].sem); |
| 518 | |
| 519 | /* |
| 520 | * Take snap shot of current value |
| 521 | */ |
| 522 | nss_n2h_nepbcfgp[core_num].low_water = *low; |
| 523 | nss_n2h_nepbcfgp[core_num].high_water = *high; |
| 524 | |
| 525 | if (!write) { |
| 526 | ret = nss_n2h_get_payload_info(ctl, write, buffer, lenp, ppos, |
| 527 | core_num); |
| 528 | *low = nss_n2h_nepbcfgp[core_num].low_water; |
| 529 | *high = nss_n2h_nepbcfgp[core_num].high_water; |
| 530 | |
| 531 | if (ret == NSS_FAILURE) { |
| 532 | up(&nss_n2h_nepbcfgp[core_num].sem); |
| 533 | return -EBUSY; |
| 534 | } |
| 535 | |
| 536 | up(&nss_n2h_nepbcfgp[core_num].sem); |
| 537 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 538 | return ret; |
| 539 | } |
| 540 | |
| 541 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 542 | if (ret) { |
| 543 | up(&nss_n2h_nepbcfgp[core_num].sem); |
| 544 | return ret; |
| 545 | } |
| 546 | |
| 547 | /* |
| 548 | * If either low or high water mark is not set then we do |
| 549 | * nothing. |
| 550 | */ |
| 551 | if (*low == -1 || *high == -1) |
| 552 | goto failure; |
| 553 | |
| 554 | if ((*low < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ) || |
| 555 | (*high < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ)) { |
| 556 | nss_warning("%p: core %d setting %d, %d < min number of buffer", |
| 557 | nss_ctx, core_num, *low, *high); |
| 558 | goto failure; |
| 559 | } |
| 560 | |
Pamidipati, Vijay | ee9c297 | 2016-01-10 08:13:19 +0530 | [diff] [blame] | 561 | if ((*low > NSS_N2H_MAX_EMPTY_POOL_BUF_SZ) || |
| 562 | (*high > NSS_N2H_MAX_EMPTY_POOL_BUF_SZ)) { |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 563 | nss_warning("%p: core %d setting %d, %d is > upper limit", |
| 564 | nss_ctx, core_num, *low, *high); |
| 565 | goto failure; |
| 566 | } |
| 567 | |
| 568 | if (*low > *high) { |
| 569 | nss_warning("%p: core %d setting low %d is more than high %d", |
| 570 | nss_ctx, core_num, *low, *high); |
| 571 | goto failure; |
| 572 | } |
| 573 | |
| 574 | nss_info("%p: core %d number of low : %d and high : %d\n", |
| 575 | nss_ctx, core_num, *low, *high); |
| 576 | |
| 577 | nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, |
| 578 | NSS_TX_METADATA_TYPE_SET_WATER_MARK, |
| 579 | sizeof(struct nss_n2h_water_mark), |
| 580 | nss_n2h_payload_stats_callback, |
| 581 | (void *)core_num); |
| 582 | |
| 583 | wm = &nnm.msg.wm; |
| 584 | wm->low_water = htonl(*low); |
| 585 | wm->high_water = htonl(*high); |
| 586 | nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm); |
| 587 | |
| 588 | if (nss_tx_status != NSS_TX_SUCCESS) { |
| 589 | nss_warning("%p: core %d nss_tx error setting : %d, %d\n", |
| 590 | nss_ctx, core_num, *low, *high); |
| 591 | goto failure; |
| 592 | } |
| 593 | |
| 594 | /* |
| 595 | * Blocking call, wait till we get ACK for this msg. |
| 596 | */ |
| 597 | ret = wait_for_completion_timeout(&nss_n2h_nepbcfgp[core_num].complete, |
| 598 | msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT)); |
| 599 | if (ret == 0) { |
| 600 | nss_warning("%p: core %d Waiting for ack timed out\n", nss_ctx, |
| 601 | core_num); |
| 602 | goto failure; |
| 603 | } |
| 604 | |
| 605 | /* |
| 606 | * ACK/NACK received from NSS FW |
| 607 | */ |
| 608 | if (NSS_FAILURE == nss_n2h_nepbcfgp[core_num].response) |
| 609 | goto failure; |
| 610 | |
| 611 | up(&nss_n2h_nepbcfgp[core_num].sem); |
| 612 | return NSS_SUCCESS; |
| 613 | |
| 614 | failure: |
| 615 | /* |
| 616 | * Restore the current_value to its previous state |
| 617 | */ |
| 618 | *low = nss_n2h_nepbcfgp[core_num].low_water; |
| 619 | *high = nss_n2h_nepbcfgp[core_num].high_water; |
Stephen Wang | 0676102 | 2015-03-03 16:38:42 -0800 | [diff] [blame] | 620 | up(&nss_n2h_nepbcfgp[core_num].sem); |
Thomas Wu | 651b390 | 2015-05-12 11:21:09 -0700 | [diff] [blame] | 621 | return -EINVAL; |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | /* |
Pamidipati, Vijay | ee9c297 | 2016-01-10 08:13:19 +0530 | [diff] [blame] | 625 | * nss_n2h_cfg_wifi_pool() |
| 626 | * Sets number of wifi payloads to adjust high water mark for N2H SoS |
| 627 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame^] | 628 | static int nss_n2h_cfg_wifi_pool(struct ctl_table *ctl, int write, |
Pamidipati, Vijay | ee9c297 | 2016-01-10 08:13:19 +0530 | [diff] [blame] | 629 | void __user *buffer, |
| 630 | size_t *lenp, loff_t *ppos, |
| 631 | int *payloads) |
| 632 | { |
| 633 | struct nss_top_instance *nss_top = &nss_top_main; |
| 634 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[0]; |
| 635 | struct nss_n2h_msg nnm; |
| 636 | struct nss_n2h_wifi_payloads *wp; |
| 637 | nss_tx_status_t nss_tx_status; |
| 638 | int ret = NSS_FAILURE; |
| 639 | |
| 640 | /* |
| 641 | * Acquiring semaphore |
| 642 | */ |
| 643 | down(&nss_n2h_wp.sem); |
| 644 | |
| 645 | if (!write) { |
| 646 | *payloads = nss_n2h_wp.wifi_pool; |
| 647 | |
| 648 | up(&nss_n2h_wp.sem); |
| 649 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 650 | return ret; |
| 651 | } |
| 652 | |
| 653 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 654 | if (ret) { |
| 655 | up(&nss_n2h_wp.sem); |
| 656 | return ret; |
| 657 | } |
| 658 | |
| 659 | /* |
| 660 | * If payloads parameter is not set, we do |
| 661 | * nothing. |
| 662 | */ |
| 663 | if (*payloads == -1) |
| 664 | goto failure; |
| 665 | |
| 666 | if ((*payloads < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ)) { |
| 667 | nss_warning("%p: wifi setting %d < min number of buffer", |
| 668 | nss_ctx, *payloads); |
| 669 | goto failure; |
| 670 | } |
| 671 | |
| 672 | if ((*payloads > NSS_N2H_MAX_EMPTY_POOL_BUF_SZ)) { |
| 673 | nss_warning("%p: wifi setting %d > max number of buffer", |
| 674 | nss_ctx, *payloads); |
| 675 | goto failure; |
| 676 | } |
| 677 | |
| 678 | nss_info("%p: wifi payloads : %d\n", |
| 679 | nss_ctx, *payloads); |
| 680 | |
| 681 | nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, |
| 682 | NSS_TX_METADATA_TYPE_N2H_WIFI_POOL_BUF_CFG, |
| 683 | sizeof(struct nss_n2h_wifi_payloads), |
| 684 | nss_n2h_set_wifi_payloads_callback, |
| 685 | (void *)nss_ctx); |
| 686 | |
| 687 | wp = &nnm.msg.wp; |
| 688 | wp->payloads = htonl(*payloads); |
| 689 | nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm); |
| 690 | |
| 691 | if (nss_tx_status != NSS_TX_SUCCESS) { |
| 692 | nss_warning("%p: wifi setting %d nss_tx error", |
| 693 | nss_ctx, *payloads); |
| 694 | goto failure; |
| 695 | } |
| 696 | |
| 697 | /* |
| 698 | * Blocking call, wait till we get ACK for this msg. |
| 699 | */ |
| 700 | ret = wait_for_completion_timeout(&nss_n2h_wp.complete, |
| 701 | msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT)); |
| 702 | if (ret == 0) { |
| 703 | nss_warning("%p: Waiting for ack timed out\n", nss_ctx); |
| 704 | goto failure; |
| 705 | } |
| 706 | |
| 707 | /* |
| 708 | * ACK/NACK received from NSS FW |
| 709 | */ |
| 710 | if (NSS_FAILURE == nss_n2h_wp.response) |
| 711 | goto failure; |
| 712 | |
| 713 | up(&nss_n2h_wp.sem); |
| 714 | return NSS_SUCCESS; |
| 715 | |
| 716 | failure: |
| 717 | up(&nss_n2h_wp.sem); |
| 718 | return -EINVAL; |
| 719 | } |
| 720 | |
| 721 | /* |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 722 | * nss_n2h_empty_pool_buf_core1_handler() |
| 723 | * Sets the number of empty buffer for core 1 |
| 724 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame^] | 725 | static int nss_n2h_empty_pool_buf_cfg_core1_handler(struct ctl_table *ctl, |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 726 | int write, void __user *buffer, |
| 727 | size_t *lenp, loff_t *ppos) |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 728 | { |
| 729 | return nss_n2h_set_empty_pool_buf(ctl, write, buffer, lenp, ppos, |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 730 | NSS_CORE_1, &nss_n2h_empty_pool_buf_cfg[NSS_CORE_1]); |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | /* |
| 734 | * nss_n2h_empty_pool_buf_core0_handler() |
| 735 | * Sets the number of empty buffer for core 0 |
| 736 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame^] | 737 | static int nss_n2h_empty_pool_buf_cfg_core0_handler(struct ctl_table *ctl, |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 738 | int write, void __user *buffer, |
| 739 | size_t *lenp, loff_t *ppos) |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 740 | { |
| 741 | return nss_n2h_set_empty_pool_buf(ctl, write, buffer, lenp, ppos, |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 742 | NSS_CORE_0, &nss_n2h_empty_pool_buf_cfg[NSS_CORE_0]); |
| 743 | } |
| 744 | |
| 745 | /* |
| 746 | * nss_n2h_water_mark_core1_handler() |
| 747 | * Sets water mark for core 1 |
| 748 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame^] | 749 | static int nss_n2h_water_mark_core1_handler(struct ctl_table *ctl, |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 750 | int write, void __user *buffer, |
| 751 | size_t *lenp, loff_t *ppos) |
| 752 | { |
| 753 | return nss_n2h_set_water_mark(ctl, write, buffer, lenp, ppos, |
| 754 | NSS_CORE_1, &nss_n2h_water_mark[NSS_CORE_1][0], |
| 755 | &nss_n2h_water_mark[NSS_CORE_1][1]); |
| 756 | } |
| 757 | |
| 758 | /* |
| 759 | * nss_n2h_water_mark_core0_handler() |
| 760 | * Sets water mark for core 0 |
| 761 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame^] | 762 | static int nss_n2h_water_mark_core0_handler(struct ctl_table *ctl, |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 763 | int write, void __user *buffer, |
| 764 | size_t *lenp, loff_t *ppos) |
| 765 | { |
| 766 | return nss_n2h_set_water_mark(ctl, write, buffer, lenp, ppos, |
| 767 | NSS_CORE_0, &nss_n2h_water_mark[NSS_CORE_0][0], |
| 768 | &nss_n2h_water_mark[NSS_CORE_0][1]); |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 769 | } |
| 770 | |
Vijay Dewangan | 634ce59 | 2015-01-07 17:21:09 -0800 | [diff] [blame] | 771 | /* |
Pamidipati, Vijay | ee9c297 | 2016-01-10 08:13:19 +0530 | [diff] [blame] | 772 | * nss_n2h_wifi_payloads_handler() |
| 773 | * Sets number of wifi payloads |
| 774 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame^] | 775 | static int nss_n2h_wifi_payloads_handler(struct ctl_table *ctl, |
Pamidipati, Vijay | ee9c297 | 2016-01-10 08:13:19 +0530 | [diff] [blame] | 776 | int write, void __user *buffer, |
| 777 | size_t *lenp, loff_t *ppos) |
| 778 | { |
| 779 | return nss_n2h_cfg_wifi_pool(ctl, write, buffer, lenp, ppos, |
| 780 | &nss_n2h_wifi_pool_buf_cfg); |
| 781 | } |
| 782 | |
| 783 | /* |
Vijay Dewangan | 634ce59 | 2015-01-07 17:21:09 -0800 | [diff] [blame] | 784 | * nss_n2h_rps_cfg() |
| 785 | * Send Message to NSS to enable RPS. |
| 786 | */ |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 787 | static nss_tx_status_t nss_n2h_rps_cfg(struct nss_ctx_instance *nss_ctx, int enable_rps) |
Vijay Dewangan | 634ce59 | 2015-01-07 17:21:09 -0800 | [diff] [blame] | 788 | { |
| 789 | struct nss_n2h_msg nnm; |
| 790 | struct nss_n2h_rps *rps_cfg; |
| 791 | nss_tx_status_t nss_tx_status; |
| 792 | int ret; |
| 793 | |
| 794 | down(&nss_n2h_rcp.sem); |
| 795 | nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, NSS_TX_METADATA_TYPE_N2H_RPS_CFG, |
| 796 | sizeof(struct nss_n2h_rps), |
| 797 | nss_n2h_rps_cfg_callback, |
| 798 | (void *)nss_ctx); |
| 799 | |
| 800 | rps_cfg = &nnm.msg.rps_cfg; |
| 801 | rps_cfg->enable = enable_rps; |
| 802 | |
| 803 | nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm); |
| 804 | |
| 805 | if (nss_tx_status != NSS_TX_SUCCESS) { |
| 806 | nss_warning("%p: nss_tx error setting rps\n", nss_ctx); |
| 807 | |
| 808 | up(&nss_n2h_rcp.sem); |
| 809 | return NSS_FAILURE; |
| 810 | } |
| 811 | |
| 812 | /* |
| 813 | * Blocking call, wait till we get ACK for this msg. |
| 814 | */ |
| 815 | ret = wait_for_completion_timeout(&nss_n2h_rcp.complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT)); |
| 816 | if (ret == 0) { |
| 817 | nss_warning("%p: Waiting for ack timed out\n", nss_ctx); |
| 818 | up(&nss_n2h_rcp.sem); |
| 819 | return NSS_FAILURE; |
| 820 | } |
| 821 | |
| 822 | /* |
| 823 | * ACK/NACK received from NSS FW |
| 824 | * If ACK: Callback function will update nss_n2h_empty_pool_buf with |
| 825 | * nss_n2h_nepbcfgp.num_conn_valid, which holds the user input |
| 826 | */ |
| 827 | if (NSS_FAILURE == nss_n2h_rcp.response) { |
| 828 | up(&nss_n2h_rcp.sem); |
| 829 | return NSS_FAILURE; |
| 830 | } |
| 831 | |
| 832 | up(&nss_n2h_rcp.sem); |
| 833 | return NSS_SUCCESS; |
| 834 | } |
| 835 | |
Kalyan Tallapragada | b50e890 | 2015-08-06 17:00:54 +0530 | [diff] [blame] | 836 | /* |
| 837 | * nss_n2h_mitigation_cfg() |
| 838 | * Send Message to NSS to disable MITIGATION. |
| 839 | */ |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 840 | static nss_tx_status_t nss_n2h_mitigation_cfg(struct nss_ctx_instance *nss_ctx, int enable_mitigation, nss_core_id_t core_num) |
Kalyan Tallapragada | b50e890 | 2015-08-06 17:00:54 +0530 | [diff] [blame] | 841 | { |
| 842 | struct nss_n2h_msg nnm; |
| 843 | struct nss_n2h_mitigation *mitigation_cfg; |
| 844 | nss_tx_status_t nss_tx_status; |
| 845 | int ret; |
| 846 | |
| 847 | nss_assert(core_num < NSS_CORE_MAX); |
| 848 | |
| 849 | down(&nss_n2h_mitigationcp[core_num].sem); |
| 850 | nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, NSS_TX_METADATA_TYPE_N2H_MITIGATION_CFG, |
| 851 | sizeof(struct nss_n2h_mitigation), |
| 852 | nss_n2h_mitigation_cfg_callback, |
| 853 | (void *)core_num); |
| 854 | |
| 855 | mitigation_cfg = &nnm.msg.mitigation_cfg; |
| 856 | mitigation_cfg->enable = enable_mitigation; |
| 857 | |
| 858 | nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm); |
| 859 | |
| 860 | if (nss_tx_status != NSS_TX_SUCCESS) { |
| 861 | nss_warning("%p: nss_tx error setting mitigation\n", nss_ctx); |
| 862 | goto failure; |
| 863 | } |
| 864 | |
| 865 | /* |
| 866 | * Blocking call, wait till we get ACK for this msg. |
| 867 | */ |
| 868 | ret = wait_for_completion_timeout(&nss_n2h_mitigationcp[core_num].complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT)); |
| 869 | if (ret == 0) { |
| 870 | nss_warning("%p: Waiting for ack timed out\n", nss_ctx); |
| 871 | goto failure; |
| 872 | } |
| 873 | |
| 874 | /* |
| 875 | * ACK/NACK received from NSS FW |
| 876 | */ |
| 877 | if (NSS_FAILURE == nss_n2h_mitigationcp[core_num].response) { |
| 878 | goto failure; |
| 879 | } |
| 880 | |
| 881 | up(&nss_n2h_mitigationcp[core_num].sem); |
| 882 | return NSS_SUCCESS; |
| 883 | |
| 884 | failure: |
| 885 | up(&nss_n2h_mitigationcp[core_num].sem); |
| 886 | return NSS_FAILURE; |
| 887 | } |
| 888 | |
| 889 | static inline void nss_n2h_buf_pool_free(struct nss_n2h_buf_pool *buf_pool) |
| 890 | { |
| 891 | int page_count; |
| 892 | for (page_count = 0; page_count < buf_pool->nss_buf_num_pages; page_count++) { |
| 893 | kfree(buf_pool->nss_buf_pool_vaddr[page_count]); |
| 894 | } |
| 895 | } |
| 896 | |
| 897 | /* |
| 898 | * nss_n2h_buf_cfg() |
| 899 | * Send Message to NSS to enable pbufs. |
| 900 | */ |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 901 | static nss_tx_status_t nss_n2h_buf_pool_cfg(struct nss_ctx_instance *nss_ctx, |
Kalyan Tallapragada | b50e890 | 2015-08-06 17:00:54 +0530 | [diff] [blame] | 902 | int buf_pool_size, nss_core_id_t core_num) |
| 903 | { |
| 904 | static struct nss_n2h_msg nnm; |
| 905 | struct nss_n2h_buf_pool *buf_pool; |
| 906 | nss_tx_status_t nss_tx_status; |
| 907 | int ret; |
| 908 | int page_count; |
| 909 | int num_pages = ALIGN(buf_pool_size, PAGE_SIZE)/PAGE_SIZE; |
| 910 | |
| 911 | nss_assert(core_num < NSS_CORE_MAX); |
| 912 | |
| 913 | nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, NSS_METADATA_TYPE_N2H_ADD_BUF_POOL, |
| 914 | sizeof(struct nss_n2h_buf_pool), |
| 915 | nss_n2h_bufs_cfg_callback, |
| 916 | (void *)core_num); |
| 917 | |
| 918 | do { |
| 919 | |
| 920 | down(&nss_n2h_bufcp[core_num].sem); |
| 921 | |
| 922 | buf_pool = &nnm.msg.buf_pool; |
| 923 | buf_pool->nss_buf_page_size = PAGE_SIZE; |
| 924 | |
| 925 | for (page_count = 0; page_count < MAX_PAGES_PER_MSG && num_pages; page_count++, num_pages--) { |
| 926 | |
| 927 | void *kern_addr = kzalloc(PAGE_SIZE, GFP_ATOMIC); |
| 928 | if (!kern_addr) { |
| 929 | BUG_ON(!page_count); |
| 930 | break; |
| 931 | } |
| 932 | BUG_ON((long unsigned int)kern_addr % PAGE_SIZE); |
| 933 | |
| 934 | buf_pool->nss_buf_pool_vaddr[page_count] = kern_addr; |
| 935 | buf_pool->nss_buf_pool_addr[page_count] = dma_map_single(NULL, kern_addr, PAGE_SIZE, DMA_TO_DEVICE); |
| 936 | } |
| 937 | |
| 938 | buf_pool->nss_buf_num_pages = page_count; |
| 939 | nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm); |
| 940 | if (nss_tx_status != NSS_TX_SUCCESS) { |
| 941 | |
| 942 | nss_n2h_buf_pool_free(buf_pool); |
| 943 | nss_warning("%p: nss_tx error setting pbuf\n", nss_ctx); |
| 944 | goto failure; |
| 945 | } |
| 946 | |
| 947 | /* |
| 948 | * Blocking call, wait till we get ACK for this msg. |
| 949 | */ |
| 950 | ret = wait_for_completion_timeout(&nss_n2h_bufcp[core_num].complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT)); |
| 951 | if (ret == 0) { |
| 952 | nss_warning("%p: Waiting for ack timed out\n", nss_ctx); |
| 953 | goto failure; |
| 954 | } |
| 955 | |
| 956 | /* |
| 957 | * ACK/NACK received from NSS FW |
| 958 | */ |
| 959 | if (NSS_FAILURE == nss_n2h_bufcp[core_num].response) { |
| 960 | |
| 961 | nss_n2h_buf_pool_free(buf_pool); |
| 962 | goto failure; |
| 963 | } |
| 964 | |
| 965 | up(&nss_n2h_bufcp[core_num].sem); |
| 966 | } while(num_pages); |
| 967 | |
| 968 | return NSS_SUCCESS; |
| 969 | failure: |
| 970 | up(&nss_n2h_bufcp[core_num].sem); |
| 971 | return NSS_FAILURE; |
| 972 | } |
| 973 | |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 974 | /* |
| 975 | * nss_rps_handler() |
| 976 | * Enable NSS RPS |
| 977 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame^] | 978 | static int nss_n2h_rpscfg_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos) |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 979 | { |
| 980 | struct nss_top_instance *nss_top = &nss_top_main; |
| 981 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[0]; |
| 982 | int ret; |
Kalyan Tallapragada | b50e890 | 2015-08-06 17:00:54 +0530 | [diff] [blame] | 983 | |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 984 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 985 | if (!ret) { |
| 986 | if ((write) && (nss_n2h_rps_config == 1)) { |
| 987 | printk(KERN_INFO "Enabling NSS RPS\n"); |
| 988 | |
| 989 | return nss_n2h_rps_cfg(nss_ctx, 1); |
| 990 | } |
| 991 | |
| 992 | if ((write) && (nss_n2h_rps_config == 0)) { |
| 993 | printk(KERN_INFO "Runtime disabling of NSS RPS not supported\n"); |
| 994 | return ret; |
| 995 | } |
| 996 | |
| 997 | if (write) { |
| 998 | printk(KERN_INFO "Invalid input value.Valid values are 0 and 1\n"); |
| 999 | } |
| 1000 | |
| 1001 | } |
| 1002 | |
| 1003 | return ret; |
| 1004 | } |
| 1005 | |
| 1006 | /* |
| 1007 | * nss_mitigation_handler() |
| 1008 | * Enable NSS MITIGATION |
| 1009 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame^] | 1010 | static int nss_n2h_mitigationcfg_core0_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos) |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 1011 | { |
| 1012 | struct nss_top_instance *nss_top = &nss_top_main; |
| 1013 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[NSS_CORE_0]; |
| 1014 | int ret; |
| 1015 | |
| 1016 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 1017 | if (ret) { |
| 1018 | return ret; |
| 1019 | } |
| 1020 | |
| 1021 | /* |
| 1022 | * It's a read operation |
| 1023 | */ |
| 1024 | if (!write) { |
| 1025 | return ret; |
| 1026 | } |
| 1027 | |
| 1028 | if (!nss_n2h_core0_mitigation_cfg) { |
| 1029 | printk(KERN_INFO "Disabling NSS MITIGATION\n"); |
| 1030 | nss_n2h_mitigation_cfg(nss_ctx, 0, NSS_CORE_0); |
| 1031 | return 0; |
| 1032 | } |
| 1033 | printk(KERN_INFO "Invalid input value.Valid value is 0, Runtime re-enabling not supported\n"); |
| 1034 | return -EINVAL; |
| 1035 | } |
| 1036 | |
| 1037 | /* |
| 1038 | * nss_mitigation_handler() |
| 1039 | * Enable NSS MITIGATION |
| 1040 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame^] | 1041 | static int nss_n2h_mitigationcfg_core1_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos) |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 1042 | { |
| 1043 | struct nss_top_instance *nss_top = &nss_top_main; |
| 1044 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[NSS_CORE_1]; |
| 1045 | int ret; |
| 1046 | |
| 1047 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 1048 | if (ret) { |
| 1049 | return ret; |
| 1050 | } |
| 1051 | |
| 1052 | /* |
| 1053 | * It's a read operation |
| 1054 | */ |
| 1055 | if (!write) { |
| 1056 | return ret; |
| 1057 | } |
| 1058 | |
| 1059 | if (!nss_n2h_core1_mitigation_cfg) { |
| 1060 | printk(KERN_INFO "Disabling NSS MITIGATION\n"); |
| 1061 | nss_n2h_mitigation_cfg(nss_ctx, 0, NSS_CORE_1); |
| 1062 | return 0; |
| 1063 | } |
| 1064 | printk(KERN_INFO "Invalid input value.Valid value is 0, Runtime re-enabling not supported\n"); |
| 1065 | return -EINVAL; |
| 1066 | } |
| 1067 | |
| 1068 | /* |
| 1069 | * nss_buf_handler() |
| 1070 | * Add extra NSS bufs from host memory |
| 1071 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame^] | 1072 | static int nss_n2h_buf_cfg_core0_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos) |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 1073 | { |
| 1074 | struct nss_top_instance *nss_top = &nss_top_main; |
| 1075 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[NSS_CORE_0]; |
| 1076 | int ret; |
| 1077 | |
| 1078 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 1079 | if (ret) { |
| 1080 | return ret; |
| 1081 | } |
| 1082 | |
| 1083 | /* |
| 1084 | * It's a read operation |
| 1085 | */ |
| 1086 | if (!write) { |
| 1087 | return ret; |
| 1088 | } |
| 1089 | |
| 1090 | if (nss_ctx->buf_sz_allocated) { |
| 1091 | nss_n2h_core0_add_buf_pool_size = nss_ctx->buf_sz_allocated; |
| 1092 | return -EPERM; |
| 1093 | } |
| 1094 | |
| 1095 | if ((nss_n2h_core0_add_buf_pool_size >= 1) && (nss_n2h_core0_add_buf_pool_size <= NSS_N2H_MAX_BUF_POOL_SIZE)) { |
| 1096 | printk(KERN_INFO "configuring additional NSS pbufs\n"); |
| 1097 | ret = nss_n2h_buf_pool_cfg(nss_ctx, nss_n2h_core0_add_buf_pool_size, NSS_CORE_0); |
| 1098 | nss_n2h_core0_add_buf_pool_size = nss_ctx->buf_sz_allocated; |
| 1099 | printk(KERN_INFO "additional pbufs of size %d got added to NSS\n", nss_ctx->buf_sz_allocated); |
| 1100 | return ret; |
| 1101 | } |
| 1102 | |
| 1103 | printk(KERN_INFO "Invalid input value. should be greater than 1 and less than %d\n", NSS_N2H_MAX_BUF_POOL_SIZE); |
| 1104 | return -EINVAL; |
| 1105 | } |
| 1106 | |
| 1107 | /* |
| 1108 | * nss_n2h_buf_handler() |
| 1109 | * Add extra NSS bufs from host memory |
| 1110 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame^] | 1111 | static int nss_n2h_buf_cfg_core1_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos) |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 1112 | { |
| 1113 | struct nss_top_instance *nss_top = &nss_top_main; |
| 1114 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[NSS_CORE_1]; |
| 1115 | int ret; |
| 1116 | |
| 1117 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 1118 | if (ret) { |
| 1119 | return ret; |
| 1120 | } |
| 1121 | |
| 1122 | /* |
| 1123 | * It's a read operation |
| 1124 | */ |
| 1125 | if (!write) { |
| 1126 | return ret; |
| 1127 | } |
| 1128 | |
| 1129 | if (nss_ctx->buf_sz_allocated) { |
| 1130 | nss_n2h_core1_add_buf_pool_size = nss_ctx->buf_sz_allocated; |
| 1131 | return -EPERM; |
| 1132 | } |
| 1133 | |
| 1134 | if ((nss_n2h_core1_add_buf_pool_size >= 1) && (nss_n2h_core1_add_buf_pool_size <= NSS_N2H_MAX_BUF_POOL_SIZE)) { |
| 1135 | printk(KERN_INFO "configuring additional NSS pbufs\n"); |
| 1136 | ret = nss_n2h_buf_pool_cfg(nss_ctx, nss_n2h_core1_add_buf_pool_size, NSS_CORE_1); |
| 1137 | nss_n2h_core1_add_buf_pool_size = nss_ctx->buf_sz_allocated; |
| 1138 | printk(KERN_INFO "additional pbufs of size %d got added to NSS\n", nss_ctx->buf_sz_allocated); |
| 1139 | return ret; |
| 1140 | } |
| 1141 | |
| 1142 | printk(KERN_INFO "Invalid input value. should be greater than 1 and less than %d\n", NSS_N2H_MAX_BUF_POOL_SIZE); |
| 1143 | return -EINVAL; |
| 1144 | } |
Kalyan Tallapragada | b50e890 | 2015-08-06 17:00:54 +0530 | [diff] [blame] | 1145 | |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame^] | 1146 | static struct ctl_table nss_n2h_table[] = { |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 1147 | { |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 1148 | .procname = "n2h_empty_pool_buf_core0", |
| 1149 | .data = &nss_n2h_empty_pool_buf_cfg[NSS_CORE_0], |
| 1150 | .maxlen = sizeof(int), |
| 1151 | .mode = 0644, |
| 1152 | .proc_handler = &nss_n2h_empty_pool_buf_cfg_core0_handler, |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 1153 | }, |
| 1154 | { |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 1155 | .procname = "n2h_empty_pool_buf_core1", |
| 1156 | .data = &nss_n2h_empty_pool_buf_cfg[NSS_CORE_1], |
| 1157 | .maxlen = sizeof(int), |
| 1158 | .mode = 0644, |
| 1159 | .proc_handler = &nss_n2h_empty_pool_buf_cfg_core1_handler, |
| 1160 | }, |
| 1161 | { |
| 1162 | .procname = "n2h_low_water_core0", |
| 1163 | .data = &nss_n2h_water_mark[NSS_CORE_0][0], |
| 1164 | .maxlen = sizeof(int), |
| 1165 | .mode = 0644, |
| 1166 | .proc_handler = &nss_n2h_water_mark_core0_handler, |
| 1167 | }, |
| 1168 | { |
| 1169 | .procname = "n2h_low_water_core1", |
| 1170 | .data = &nss_n2h_water_mark[NSS_CORE_1][0], |
| 1171 | .maxlen = sizeof(int), |
| 1172 | .mode = 0644, |
| 1173 | .proc_handler = &nss_n2h_water_mark_core1_handler, |
| 1174 | }, |
| 1175 | { |
| 1176 | .procname = "n2h_high_water_core0", |
| 1177 | .data = &nss_n2h_water_mark[NSS_CORE_0][1], |
| 1178 | .maxlen = sizeof(int), |
| 1179 | .mode = 0644, |
| 1180 | .proc_handler = &nss_n2h_water_mark_core0_handler, |
| 1181 | }, |
| 1182 | { |
| 1183 | .procname = "n2h_high_water_core1", |
| 1184 | .data = &nss_n2h_water_mark[NSS_CORE_1][1], |
| 1185 | .maxlen = sizeof(int), |
| 1186 | .mode = 0644, |
| 1187 | .proc_handler = &nss_n2h_water_mark_core1_handler, |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 1188 | }, |
Pamidipati, Vijay | ee9c297 | 2016-01-10 08:13:19 +0530 | [diff] [blame] | 1189 | { |
| 1190 | .procname = "n2h_wifi_pool_buf", |
| 1191 | .data = &nss_n2h_wifi_pool_buf_cfg, |
| 1192 | .maxlen = sizeof(int), |
| 1193 | .mode = 0644, |
| 1194 | .proc_handler = &nss_n2h_wifi_payloads_handler, |
| 1195 | }, |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 1196 | { |
| 1197 | .procname = "rps", |
| 1198 | .data = &nss_n2h_rps_config, |
| 1199 | .maxlen = sizeof(int), |
| 1200 | .mode = 0644, |
| 1201 | .proc_handler = &nss_n2h_rpscfg_handler, |
| 1202 | }, |
| 1203 | { |
| 1204 | .procname = "mitigation_core0", |
| 1205 | .data = &nss_n2h_core0_mitigation_cfg, |
| 1206 | .maxlen = sizeof(int), |
| 1207 | .mode = 0644, |
| 1208 | .proc_handler = &nss_n2h_mitigationcfg_core0_handler, |
| 1209 | }, |
| 1210 | { |
| 1211 | .procname = "mitigation_core1", |
| 1212 | .data = &nss_n2h_core1_mitigation_cfg, |
| 1213 | .maxlen = sizeof(int), |
| 1214 | .mode = 0644, |
| 1215 | .proc_handler = &nss_n2h_mitigationcfg_core1_handler, |
| 1216 | }, |
| 1217 | { |
| 1218 | .procname = "extra_pbuf_core0", |
| 1219 | .data = &nss_n2h_core0_add_buf_pool_size, |
| 1220 | .maxlen = sizeof(int), |
| 1221 | .mode = 0644, |
| 1222 | .proc_handler = &nss_n2h_buf_cfg_core0_handler, |
| 1223 | }, |
| 1224 | { |
| 1225 | .procname = "extra_pbuf_core1", |
| 1226 | .data = &nss_n2h_core1_add_buf_pool_size, |
| 1227 | .maxlen = sizeof(int), |
| 1228 | .mode = 0644, |
| 1229 | .proc_handler = &nss_n2h_buf_cfg_core1_handler, |
| 1230 | }, |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 1231 | |
| 1232 | { } |
| 1233 | }; |
| 1234 | |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame^] | 1235 | static struct ctl_table nss_n2h_dir[] = { |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 1236 | { |
| 1237 | .procname = "n2hcfg", |
| 1238 | .mode = 0555, |
| 1239 | .child = nss_n2h_table, |
| 1240 | }, |
| 1241 | { } |
| 1242 | }; |
| 1243 | |
| 1244 | |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame^] | 1245 | static struct ctl_table nss_n2h_root_dir[] = { |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 1246 | { |
| 1247 | .procname = "nss", |
| 1248 | .mode = 0555, |
| 1249 | .child = nss_n2h_dir, |
| 1250 | }, |
| 1251 | { } |
| 1252 | }; |
| 1253 | |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame^] | 1254 | static struct ctl_table nss_n2h_root[] = { |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 1255 | { |
| 1256 | .procname = "dev", |
| 1257 | .mode = 0555, |
| 1258 | .child = nss_n2h_root_dir, |
| 1259 | }, |
| 1260 | { } |
| 1261 | }; |
| 1262 | |
| 1263 | static struct ctl_table_header *nss_n2h_header; |
| 1264 | |
| 1265 | /* |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 1266 | * nss_n2h_flush_payloads() |
| 1267 | * Sends a command down to NSS for flushing all payloads |
| 1268 | */ |
| 1269 | nss_tx_status_t nss_n2h_flush_payloads(struct nss_ctx_instance *nss_ctx) |
| 1270 | { |
| 1271 | struct nss_n2h_msg nnm; |
| 1272 | struct nss_n2h_flush_payloads *nnflshpl; |
| 1273 | nss_tx_status_t nss_tx_status; |
| 1274 | |
| 1275 | nnflshpl = &nnm.msg.flush_payloads; |
| 1276 | |
| 1277 | /* |
| 1278 | * TODO: No additional information sent in message |
| 1279 | * as of now. Need to initialize message content accordingly |
| 1280 | * if needed. |
| 1281 | */ |
| 1282 | nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, |
| 1283 | NSS_TX_METADATA_TYPE_N2H_FLUSH_PAYLOADS, |
| 1284 | sizeof(struct nss_n2h_flush_payloads), |
| 1285 | NULL, |
| 1286 | NULL); |
| 1287 | |
| 1288 | nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm); |
| 1289 | if (nss_tx_status != NSS_TX_SUCCESS) { |
| 1290 | nss_warning("%p: failed to send flush payloads command to NSS\n", |
| 1291 | nss_ctx); |
| 1292 | |
| 1293 | return NSS_TX_FAILURE; |
| 1294 | } |
| 1295 | |
| 1296 | return NSS_TX_SUCCESS; |
| 1297 | } |
| 1298 | |
| 1299 | /* |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 1300 | * nss_n2h_msg_init() |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 1301 | * Initialize n2h message. |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 1302 | */ |
| 1303 | 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] | 1304 | uint32_t len, nss_n2h_msg_callback_t cb, void *app_data) |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 1305 | { |
| 1306 | nss_cmn_msg_init(&nim->cm, if_num, type, len, (void *)cb, app_data); |
| 1307 | } |
| 1308 | |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 1309 | /* |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 1310 | * nss_n2h_tx_msg() |
| 1311 | * Send messages to NSS n2h pacakge |
| 1312 | */ |
| 1313 | nss_tx_status_t nss_n2h_tx_msg(struct nss_ctx_instance *nss_ctx, struct nss_n2h_msg *nnm) |
| 1314 | { |
| 1315 | struct nss_n2h_msg *nnm2; |
| 1316 | struct nss_cmn_msg *ncm = &nnm->cm; |
| 1317 | struct sk_buff *nbuf; |
| 1318 | nss_tx_status_t status; |
| 1319 | |
| 1320 | NSS_VERIFY_CTX_MAGIC(nss_ctx); |
| 1321 | if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) { |
| 1322 | return NSS_TX_FAILURE_NOT_READY; |
| 1323 | } |
| 1324 | |
| 1325 | /* |
| 1326 | * Sanity check the message |
| 1327 | */ |
| 1328 | if (ncm->interface != NSS_N2H_INTERFACE) { |
| 1329 | nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface); |
| 1330 | return NSS_TX_FAILURE; |
| 1331 | } |
| 1332 | |
| 1333 | if (ncm->type >= NSS_METADATA_TYPE_N2H_MAX) { |
| 1334 | nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type); |
| 1335 | return NSS_TX_FAILURE; |
| 1336 | } |
| 1337 | |
Suruchi Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 1338 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_n2h_msg)) { |
| 1339 | nss_warning("%p: tx request for another interface: %d", nss_ctx, nss_cmn_get_msg_len(ncm)); |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 1340 | return NSS_TX_FAILURE; |
| 1341 | } |
| 1342 | |
| 1343 | |
| 1344 | nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE); |
| 1345 | if (unlikely(!nbuf)) { |
Sundarajan Srinivasan | 62fee7e | 2015-01-22 11:13:10 -0800 | [diff] [blame] | 1346 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]); |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 1347 | return NSS_TX_FAILURE; |
| 1348 | } |
| 1349 | |
| 1350 | /* |
| 1351 | * Copy the message to our skb. |
| 1352 | */ |
| 1353 | nnm2 = (struct nss_n2h_msg *)skb_put(nbuf, sizeof(struct nss_n2h_msg)); |
| 1354 | memcpy(nnm2, nnm, sizeof(struct nss_n2h_msg)); |
| 1355 | status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0); |
| 1356 | if (status != NSS_CORE_STATUS_SUCCESS) { |
| 1357 | dev_kfree_skb_any(nbuf); |
| 1358 | nss_info("%p: unable to enqueue 'nss frequency change' - marked as stopped\n", nss_ctx); |
| 1359 | return NSS_TX_FAILURE; |
| 1360 | } |
| 1361 | |
| 1362 | nss_hal_send_interrupt(nss_ctx->nmap, |
| 1363 | nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit, |
| 1364 | NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE); |
| 1365 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]); |
| 1366 | return NSS_TX_SUCCESS; |
| 1367 | } |
| 1368 | |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 1369 | /* |
| 1370 | * nss_n2h_notify_register() |
| 1371 | * Register to received N2H events. |
| 1372 | * |
| 1373 | * NOTE: Do we want to pass an nss_ctx here so that we can register for n2h on any core? |
| 1374 | */ |
| 1375 | struct nss_ctx_instance *nss_n2h_notify_register(int core, nss_n2h_msg_callback_t cb, void *app_data) |
| 1376 | { |
| 1377 | if (core >= NSS_MAX_CORES) { |
| 1378 | nss_warning("Input core number %d is wrong \n", core); |
| 1379 | return NULL; |
| 1380 | } |
| 1381 | /* |
| 1382 | * TODO: We need to have a new array in support of the new API |
| 1383 | * TODO: If we use a per-context array, we would move the array into nss_ctx based. |
| 1384 | */ |
| 1385 | nss_n2h_rd[core].n2h_callback = cb; |
| 1386 | nss_n2h_rd[core].app_data = app_data; |
| 1387 | return &nss_top_main.nss[core]; |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | /* |
| 1391 | * nss_n2h_register_handler() |
| 1392 | */ |
| 1393 | void nss_n2h_register_handler() |
| 1394 | { |
Sundarajan Srinivasan | f1e5746 | 2014-09-17 15:24:01 -0700 | [diff] [blame] | 1395 | nss_core_register_handler(NSS_N2H_INTERFACE, nss_n2h_interface_handler, NULL); |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 1396 | } |
Sundarajan Srinivasan | f1e5746 | 2014-09-17 15:24:01 -0700 | [diff] [blame] | 1397 | |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 1398 | /* |
| 1399 | * nss_n2h_register_sysctl() |
| 1400 | */ |
| 1401 | void nss_n2h_register_sysctl(void) |
| 1402 | { |
Vijay Dewangan | 634ce59 | 2015-01-07 17:21:09 -0800 | [diff] [blame] | 1403 | /* |
| 1404 | * RPS sema init |
| 1405 | */ |
| 1406 | sema_init(&nss_n2h_rcp.sem, 1); |
| 1407 | init_completion(&nss_n2h_rcp.complete); |
| 1408 | |
Kalyan Tallapragada | b50e890 | 2015-08-06 17:00:54 +0530 | [diff] [blame] | 1409 | /* |
| 1410 | * MITIGATION sema init for core0 |
| 1411 | */ |
| 1412 | sema_init(&nss_n2h_mitigationcp[NSS_CORE_0].sem, 1); |
| 1413 | init_completion(&nss_n2h_mitigationcp[NSS_CORE_0].complete); |
| 1414 | |
| 1415 | /* |
| 1416 | * MITIGATION sema init for core1 |
| 1417 | */ |
| 1418 | sema_init(&nss_n2h_mitigationcp[NSS_CORE_1].sem, 1); |
| 1419 | init_completion(&nss_n2h_mitigationcp[NSS_CORE_1].complete); |
| 1420 | |
| 1421 | /* |
| 1422 | * PBUF addition sema init for core0 |
| 1423 | */ |
| 1424 | sema_init(&nss_n2h_bufcp[NSS_CORE_0].sem, 1); |
| 1425 | init_completion(&nss_n2h_bufcp[NSS_CORE_0].complete); |
| 1426 | |
| 1427 | /* |
| 1428 | * PBUF addition sema init for core1 |
| 1429 | */ |
| 1430 | sema_init(&nss_n2h_bufcp[NSS_CORE_1].sem, 1); |
| 1431 | init_completion(&nss_n2h_bufcp[NSS_CORE_1].complete); |
Vijay Dewangan | 634ce59 | 2015-01-07 17:21:09 -0800 | [diff] [blame] | 1432 | |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 1433 | /* |
| 1434 | * Core0 |
| 1435 | */ |
| 1436 | sema_init(&nss_n2h_nepbcfgp[NSS_CORE_0].sem, 1); |
| 1437 | init_completion(&nss_n2h_nepbcfgp[NSS_CORE_0].complete); |
| 1438 | nss_n2h_nepbcfgp[NSS_CORE_0].empty_buf_pool = |
| 1439 | nss_n2h_empty_pool_buf_cfg[NSS_CORE_0]; |
| 1440 | nss_n2h_nepbcfgp[NSS_CORE_0].low_water = |
| 1441 | nss_n2h_water_mark[NSS_CORE_0][0]; |
| 1442 | nss_n2h_nepbcfgp[NSS_CORE_0].high_water = |
| 1443 | nss_n2h_water_mark[NSS_CORE_0][1]; |
| 1444 | |
| 1445 | /* |
| 1446 | * Core1 |
| 1447 | */ |
| 1448 | sema_init(&nss_n2h_nepbcfgp[NSS_CORE_1].sem, 1); |
| 1449 | init_completion(&nss_n2h_nepbcfgp[NSS_CORE_1].complete); |
| 1450 | nss_n2h_nepbcfgp[NSS_CORE_1].empty_buf_pool = |
| 1451 | nss_n2h_empty_pool_buf_cfg[NSS_CORE_1]; |
| 1452 | nss_n2h_nepbcfgp[NSS_CORE_1].low_water = |
| 1453 | nss_n2h_water_mark[NSS_CORE_1][0]; |
| 1454 | nss_n2h_nepbcfgp[NSS_CORE_1].high_water = |
| 1455 | nss_n2h_water_mark[NSS_CORE_1][1]; |
| 1456 | |
| 1457 | /* |
| 1458 | * WiFi pool buf cfg sema init |
| 1459 | */ |
| 1460 | sema_init(&nss_n2h_wp.sem, 1); |
| 1461 | init_completion(&nss_n2h_wp.complete); |
| 1462 | |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 1463 | nss_n2h_notify_register(NSS_CORE_0, NULL, NULL); |
| 1464 | nss_n2h_notify_register(NSS_CORE_1, NULL, NULL); |
| 1465 | |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 1466 | /* |
| 1467 | * Register sysctl table. |
| 1468 | */ |
| 1469 | nss_n2h_header = register_sysctl_table(nss_n2h_root); |
| 1470 | } |
| 1471 | |
| 1472 | /* |
| 1473 | * nss_n2h_unregister_sysctl() |
| 1474 | * Unregister sysctl specific to n2h |
| 1475 | */ |
| 1476 | void nss_n2h_unregister_sysctl(void) |
| 1477 | { |
| 1478 | /* |
| 1479 | * Unregister sysctl table. |
| 1480 | */ |
| 1481 | if (nss_n2h_header) { |
| 1482 | unregister_sysctl_table(nss_n2h_header); |
| 1483 | } |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 1484 | } |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 1485 | |
| 1486 | EXPORT_SYMBOL(nss_n2h_notify_register); |