Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Stephen Wang | efd3851 | 2017-01-24 14:01:02 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2017, 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 |
ratheesh kannoth | ab436af | 2017-07-20 08:51:07 +0530 | [diff] [blame] | 28 | #define NSS_N2H_TX_TIMEOUT 3000 /* 3 Seconds */ |
Pamidipati, Vijay | efcc469 | 2014-05-09 14:47:38 +0530 | [diff] [blame] | 29 | |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 30 | int nss_n2h_empty_pool_buf_cfg[NSS_MAX_CORES] __read_mostly = {-1, -1}; |
Sachin Shashidhar | 475012b | 2017-03-13 16:56:07 -0700 | [diff] [blame] | 31 | int nss_n2h_empty_paged_pool_buf_cfg[NSS_MAX_CORES] __read_mostly = {-1, -1}; |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 32 | int nss_n2h_water_mark[NSS_MAX_CORES][2] __read_mostly = {{-1, -1}, {-1, -1} }; |
Sachin Shashidhar | 475012b | 2017-03-13 16:56:07 -0700 | [diff] [blame] | 33 | int nss_n2h_paged_water_mark[NSS_MAX_CORES][2] __read_mostly = {{-1, -1}, {-1, -1} }; |
Pamidipati, Vijay | ee9c297 | 2016-01-10 08:13:19 +0530 | [diff] [blame] | 34 | int nss_n2h_wifi_pool_buf_cfg __read_mostly = -1; |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 35 | int nss_n2h_rps_config __read_mostly; |
| 36 | int nss_n2h_core0_mitigation_cfg __read_mostly = 1; |
| 37 | int nss_n2h_core1_mitigation_cfg __read_mostly = 1; |
| 38 | int nss_n2h_core0_add_buf_pool_size __read_mostly; |
| 39 | int nss_n2h_core1_add_buf_pool_size __read_mostly; |
Pamidipati, Vijay | efcc469 | 2014-05-09 14:47:38 +0530 | [diff] [blame] | 40 | |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 41 | struct nss_n2h_registered_data { |
| 42 | nss_n2h_msg_callback_t n2h_callback; |
| 43 | void *app_data; |
| 44 | }; |
Pamidipati, Vijay | efcc469 | 2014-05-09 14:47:38 +0530 | [diff] [blame] | 45 | |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 46 | static struct nss_n2h_cfg_pvt nss_n2h_nepbcfgp[NSS_MAX_CORES]; |
| 47 | static struct nss_n2h_registered_data nss_n2h_rd[NSS_MAX_CORES]; |
Vijay Dewangan | 634ce59 | 2015-01-07 17:21:09 -0800 | [diff] [blame] | 48 | static struct nss_n2h_cfg_pvt nss_n2h_rcp; |
Kalyan Tallapragada | b50e890 | 2015-08-06 17:00:54 +0530 | [diff] [blame] | 49 | static struct nss_n2h_cfg_pvt nss_n2h_mitigationcp[NSS_CORE_MAX]; |
| 50 | static struct nss_n2h_cfg_pvt nss_n2h_bufcp[NSS_CORE_MAX]; |
Pamidipati, Vijay | ee9c297 | 2016-01-10 08:13:19 +0530 | [diff] [blame] | 51 | static struct nss_n2h_cfg_pvt nss_n2h_wp; |
ratheesh kannoth | ab436af | 2017-07-20 08:51:07 +0530 | [diff] [blame] | 52 | static struct nss_n2h_cfg_pvt nss_n2h_q_cfg_pvt; |
Pamidipati, Vijay | efcc469 | 2014-05-09 14:47:38 +0530 | [diff] [blame] | 53 | |
| 54 | /* |
Sundarajan Srinivasan | f1e5746 | 2014-09-17 15:24:01 -0700 | [diff] [blame] | 55 | * nss_n2h_stats_sync() |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 56 | * Handle the syncing of NSS statistics. |
| 57 | */ |
Sundarajan Srinivasan | f1e5746 | 2014-09-17 15:24:01 -0700 | [diff] [blame] | 58 | 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] | 59 | { |
| 60 | struct nss_top_instance *nss_top = nss_ctx->nss_top; |
ratheesh kannoth | 93ba95c | 2017-07-13 15:52:52 +0530 | [diff] [blame] | 61 | int j; |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 62 | |
| 63 | spin_lock_bh(&nss_top->stats_lock); |
| 64 | |
| 65 | /* |
| 66 | * common node stats |
| 67 | */ |
| 68 | nss_ctx->stats_n2h[NSS_STATS_NODE_RX_PKTS] += nnss->node_stats.rx_packets; |
| 69 | nss_ctx->stats_n2h[NSS_STATS_NODE_RX_BYTES] += nnss->node_stats.rx_bytes; |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 70 | nss_ctx->stats_n2h[NSS_STATS_NODE_TX_PKTS] += nnss->node_stats.tx_packets; |
| 71 | nss_ctx->stats_n2h[NSS_STATS_NODE_TX_BYTES] += nnss->node_stats.tx_bytes; |
| 72 | |
ratheesh kannoth | 93ba95c | 2017-07-13 15:52:52 +0530 | [diff] [blame] | 73 | for (j = 0; j < NSS_MAX_NUM_PRI; j++) { |
| 74 | nss_ctx->stats_n2h[NSS_STATS_NODE_RX_QUEUE_0_DROPPED + j] += nnss->node_stats.rx_dropped[j]; |
| 75 | } |
| 76 | |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 77 | /* |
| 78 | * General N2H stats |
| 79 | */ |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 80 | nss_ctx->stats_n2h[NSS_STATS_N2H_QUEUE_DROPPED] += nnss->queue_dropped; |
| 81 | nss_ctx->stats_n2h[NSS_STATS_N2H_TOTAL_TICKS] += nnss->total_ticks; |
| 82 | nss_ctx->stats_n2h[NSS_STATS_N2H_WORST_CASE_TICKS] += nnss->worst_case_ticks; |
| 83 | nss_ctx->stats_n2h[NSS_STATS_N2H_ITERATIONS] += nnss->iterations; |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 84 | |
| 85 | /* |
Thomas Wu | 3fd8dd7 | 2014-06-11 15:57:05 -0700 | [diff] [blame] | 86 | * pbuf manager ocm and default pool stats |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 87 | */ |
Thomas Wu | 3fd8dd7 | 2014-06-11 15:57:05 -0700 | [diff] [blame] | 88 | nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_OCM_ALLOC_FAILS] += nnss->pbuf_ocm_stats.pbuf_alloc_fails; |
| 89 | nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_OCM_FREE_COUNT] = nnss->pbuf_ocm_stats.pbuf_free_count; |
| 90 | nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_OCM_TOTAL_COUNT] = nnss->pbuf_ocm_stats.pbuf_total_count; |
| 91 | |
| 92 | nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_DEFAULT_ALLOC_FAILS] += nnss->pbuf_default_stats.pbuf_alloc_fails; |
| 93 | nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_DEFAULT_FREE_COUNT] = nnss->pbuf_default_stats.pbuf_free_count; |
| 94 | nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_DEFAULT_TOTAL_COUNT] = nnss->pbuf_default_stats.pbuf_total_count; |
| 95 | |
| 96 | /* |
| 97 | * payload mgr stats |
| 98 | */ |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 99 | 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] | 100 | 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] | 101 | |
Sakthi Vignesh Radhakrishnan | 2a8ee96 | 2014-11-22 13:35:38 -0800 | [diff] [blame] | 102 | /* |
| 103 | * Host <=> NSS control traffic stats |
| 104 | */ |
| 105 | nss_ctx->stats_n2h[NSS_STATS_N2H_H2N_CONTROL_PACKETS] += nnss->h2n_ctrl_pkts; |
| 106 | nss_ctx->stats_n2h[NSS_STATS_N2H_H2N_CONTROL_BYTES] += nnss->h2n_ctrl_bytes; |
| 107 | nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_CONTROL_PACKETS] += nnss->n2h_ctrl_pkts; |
| 108 | nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_CONTROL_BYTES] += nnss->n2h_ctrl_bytes; |
| 109 | |
| 110 | /* |
| 111 | * Host <=> NSS control data traffic stats |
| 112 | */ |
| 113 | nss_ctx->stats_n2h[NSS_STATS_N2H_H2N_DATA_PACKETS] += nnss->h2n_data_pkts; |
| 114 | nss_ctx->stats_n2h[NSS_STATS_N2H_H2N_DATA_BYTES] += nnss->h2n_data_bytes; |
| 115 | nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_DATA_PACKETS] += nnss->n2h_data_pkts; |
| 116 | nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_DATA_BYTES] += nnss->n2h_data_bytes; |
| 117 | |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 118 | /* |
| 119 | * Payloads related stats |
| 120 | */ |
| 121 | nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_TOT_PAYLOADS] = nnss->tot_payloads; |
| 122 | |
Guojun Jin | 85dfa7b | 2015-09-02 15:13:56 -0700 | [diff] [blame] | 123 | nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_INTERFACE_INVALID] += nnss->data_interface_invalid; |
| 124 | |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 125 | spin_unlock_bh(&nss_top->stats_lock); |
| 126 | } |
| 127 | |
| 128 | /* |
Sundarajan Srinivasan | f1e5746 | 2014-09-17 15:24:01 -0700 | [diff] [blame] | 129 | * nss_n2h_interface_handler() |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 130 | * Handle NSS -> HLOS messages for N2H node |
| 131 | */ |
Vijay Dewangan | 634ce59 | 2015-01-07 17:21:09 -0800 | [diff] [blame] | 132 | static void nss_n2h_interface_handler(struct nss_ctx_instance *nss_ctx, |
| 133 | struct nss_cmn_msg *ncm, |
Arunkumar T | ba9b4a0 | 2016-11-07 11:41:14 +0530 | [diff] [blame] | 134 | void *app_data) |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 135 | { |
| 136 | struct nss_n2h_msg *nnm = (struct nss_n2h_msg *)ncm; |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 137 | nss_n2h_msg_callback_t cb; |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 138 | |
Sundarajan Srinivasan | f1e5746 | 2014-09-17 15:24:01 -0700 | [diff] [blame] | 139 | BUG_ON(ncm->interface != NSS_N2H_INTERFACE); |
| 140 | |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 141 | /* |
| 142 | * Is this a valid request/response packet? |
| 143 | */ |
| 144 | if (nnm->cm.type >= NSS_METADATA_TYPE_N2H_MAX) { |
| 145 | nss_warning("%p: received invalid message %d for Offload stats interface", nss_ctx, nnm->cm.type); |
| 146 | return; |
| 147 | } |
| 148 | |
| 149 | switch (nnm->cm.type) { |
Pamidipati, Vijay | efcc469 | 2014-05-09 14:47:38 +0530 | [diff] [blame] | 150 | case NSS_TX_METADATA_TYPE_N2H_RPS_CFG: |
Pamidipati, Vijay | efcc469 | 2014-05-09 14:47:38 +0530 | [diff] [blame] | 151 | 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] | 152 | break; |
| 153 | |
Kalyan Tallapragada | b50e890 | 2015-08-06 17:00:54 +0530 | [diff] [blame] | 154 | case NSS_TX_METADATA_TYPE_N2H_MITIGATION_CFG: |
| 155 | nss_info("NSS N2H mitigation_dis %d \n",nnm->msg.mitigation_cfg.enable); |
| 156 | break; |
| 157 | |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 158 | case NSS_TX_METADATA_TYPE_N2H_EMPTY_POOL_BUF_CFG: |
| 159 | nss_info("%p: empty pool buf cfg response from FW", nss_ctx); |
Pamidipati, Vijay | efcc469 | 2014-05-09 14:47:38 +0530 | [diff] [blame] | 160 | break; |
| 161 | |
Radha krishna Simha Jiguru | 7f424d5 | 2015-02-10 19:41:01 +0530 | [diff] [blame] | 162 | case NSS_TX_METADATA_TYPE_N2H_FLUSH_PAYLOADS: |
| 163 | nss_info("%p: flush payloads cmd response from FW", nss_ctx); |
| 164 | break; |
| 165 | |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 166 | case NSS_RX_METADATA_TYPE_N2H_STATS_SYNC: |
Sundarajan Srinivasan | f1e5746 | 2014-09-17 15:24:01 -0700 | [diff] [blame] | 167 | nss_n2h_stats_sync(nss_ctx, &nnm->msg.stats_sync); |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 168 | break; |
| 169 | |
| 170 | default: |
| 171 | if (ncm->response != NSS_CMN_RESPONSE_ACK) { |
| 172 | /* |
| 173 | * Check response |
| 174 | */ |
| 175 | nss_info("%p: Received response %d for type %d, interface %d", |
| 176 | nss_ctx, ncm->response, ncm->type, ncm->interface); |
| 177 | } |
| 178 | } |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 179 | |
| 180 | /* |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 181 | * 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] | 182 | * to the same callback/app_data. |
| 183 | */ |
| 184 | if (nnm->cm.response == NSS_CMM_RESPONSE_NOTIFY) { |
| 185 | /* |
| 186 | * Place holder for the user to create right call |
| 187 | * back and app data when response is NSS_CMM_RESPONSE_NOTIFY |
| 188 | */ |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 189 | ncm->cb = (nss_ptr_t)nss_n2h_rd[nss_ctx->id].n2h_callback; |
| 190 | ncm->app_data = (nss_ptr_t)nss_n2h_rd[nss_ctx->id].app_data; |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | /* |
| 194 | * Do we have a callback? |
| 195 | */ |
| 196 | if (!ncm->cb) { |
| 197 | return; |
| 198 | } |
| 199 | |
| 200 | /* |
| 201 | * Callback |
| 202 | */ |
| 203 | cb = (nss_n2h_msg_callback_t)ncm->cb; |
| 204 | cb((void *)ncm->app_data, nnm); |
| 205 | } |
| 206 | |
| 207 | /* |
Vijay Dewangan | 634ce59 | 2015-01-07 17:21:09 -0800 | [diff] [blame] | 208 | * nss_n2h_rps_cfg_callback() |
| 209 | * call back function for rps configuration |
| 210 | */ |
| 211 | static void nss_n2h_rps_cfg_callback(void *app_data, struct nss_n2h_msg *nnm) |
| 212 | { |
| 213 | struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)app_data; |
| 214 | if (nnm->cm.response != NSS_CMN_RESPONSE_ACK) { |
| 215 | |
| 216 | /* |
| 217 | * Error, hence we are not updating the nss_n2h_empty_pool_buf |
| 218 | * Restore the current_value to its previous state |
| 219 | */ |
| 220 | nss_n2h_rcp.response = NSS_FAILURE; |
| 221 | complete(&nss_n2h_rcp.complete); |
| 222 | nss_warning("%p: RPS configuration failed : %d\n", nss_ctx, |
| 223 | nnm->cm.error); |
| 224 | return; |
| 225 | } |
| 226 | |
| 227 | nss_info("%p: RPS configuration succeeded: %d\n", nss_ctx, |
| 228 | nnm->cm.error); |
| 229 | nss_ctx->n2h_rps_en = nnm->msg.rps_cfg.enable; |
| 230 | nss_n2h_rcp.response = NSS_SUCCESS; |
| 231 | complete(&nss_n2h_rcp.complete); |
| 232 | } |
| 233 | |
| 234 | /* |
Kalyan Tallapragada | b50e890 | 2015-08-06 17:00:54 +0530 | [diff] [blame] | 235 | * nss_n2h_mitigation_cfg_callback() |
| 236 | * call back function for mitigation configuration |
| 237 | */ |
| 238 | static void nss_n2h_mitigation_cfg_callback(void *app_data, struct nss_n2h_msg *nnm) |
| 239 | { |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 240 | uint32_t core_num = (uint32_t)(nss_ptr_t)app_data; |
Kalyan Tallapragada | b50e890 | 2015-08-06 17:00:54 +0530 | [diff] [blame] | 241 | struct nss_top_instance *nss_top = &nss_top_main; |
| 242 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num]; |
| 243 | |
| 244 | if (nnm->cm.response != NSS_CMN_RESPONSE_ACK) { |
| 245 | |
| 246 | /* |
| 247 | * Error, hence we are not updating the nss_n2h_mitigate_en |
| 248 | */ |
| 249 | nss_n2h_mitigationcp[core_num].response = NSS_FAILURE; |
| 250 | complete(&nss_n2h_mitigationcp[core_num].complete); |
| 251 | nss_warning("core%d: MITIGATION configuration failed : %d\n", core_num, nnm->cm.error); |
| 252 | return; |
| 253 | } |
| 254 | |
| 255 | nss_info("core%d: MITIGATION configuration succeeded: %d\n", core_num, nnm->cm.error); |
| 256 | |
| 257 | nss_ctx->n2h_mitigate_en = nnm->msg.mitigation_cfg.enable; |
| 258 | nss_n2h_mitigationcp[core_num].response = NSS_SUCCESS; |
| 259 | complete(&nss_n2h_mitigationcp[core_num].complete); |
| 260 | } |
| 261 | |
| 262 | /* |
| 263 | * nss_n2h_buf_cfg_callback() |
| 264 | * call back function for pbuf configuration |
| 265 | */ |
| 266 | static void nss_n2h_bufs_cfg_callback(void *app_data, struct nss_n2h_msg *nnm) |
| 267 | { |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 268 | uint32_t core_num = (uint32_t)(nss_ptr_t)app_data; |
Kalyan Tallapragada | b50e890 | 2015-08-06 17:00:54 +0530 | [diff] [blame] | 269 | unsigned int allocated_sz; |
| 270 | |
| 271 | struct nss_top_instance *nss_top = &nss_top_main; |
| 272 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num]; |
| 273 | |
| 274 | if (nnm->cm.response != NSS_CMN_RESPONSE_ACK) { |
| 275 | nss_n2h_bufcp[core_num].response = NSS_FAILURE; |
| 276 | nss_warning("core%d: buf configuration failed : %d\n", core_num, nnm->cm.error); |
| 277 | goto done; |
| 278 | } |
| 279 | |
| 280 | nss_info("core%d: buf configuration succeeded: %d\n", core_num, nnm->cm.error); |
| 281 | |
| 282 | allocated_sz = nnm->msg.buf_pool.nss_buf_page_size * nnm->msg.buf_pool.nss_buf_num_pages; |
| 283 | nss_ctx->buf_sz_allocated += allocated_sz; |
| 284 | |
| 285 | nss_n2h_bufcp[core_num].response = NSS_SUCCESS; |
| 286 | |
| 287 | done: |
| 288 | complete(&nss_n2h_bufcp[core_num].complete); |
| 289 | } |
| 290 | |
| 291 | /* |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 292 | * nss_n2h_payload_stats_callback() |
| 293 | * It gets called response to payload accounting. |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 294 | */ |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 295 | static void nss_n2h_payload_stats_callback(void *app_data, |
| 296 | struct nss_n2h_msg *nnm) |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 297 | { |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 298 | uint32_t core_num = (uint32_t)(nss_ptr_t)app_data; |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 299 | |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 300 | if (nnm->cm.response != NSS_CMN_RESPONSE_ACK) { |
| 301 | struct nss_n2h_empty_pool_buf *nnepbcm; |
| 302 | nnepbcm = &nnm->msg.empty_pool_buf_cfg; |
| 303 | |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 304 | nss_warning("%d: core empty pool buf set failure: %d\n", |
| 305 | core_num, nnm->cm.error); |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 306 | nss_n2h_nepbcfgp[core_num].response = NSS_FAILURE; |
| 307 | complete(&nss_n2h_nepbcfgp[core_num].complete); |
| 308 | return; |
| 309 | } |
| 310 | |
Sachin Shashidhar | 475012b | 2017-03-13 16:56:07 -0700 | [diff] [blame] | 311 | if (nnm->cm.type == NSS_TX_METADATA_TYPE_GET_WATER_MARK) { |
| 312 | nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.pool_size = |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 313 | ntohl(nnm->msg.payload_info.pool_size); |
Sachin Shashidhar | 475012b | 2017-03-13 16:56:07 -0700 | [diff] [blame] | 314 | nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.low_water = |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 315 | ntohl(nnm->msg.payload_info.low_water); |
Sachin Shashidhar | 475012b | 2017-03-13 16:56:07 -0700 | [diff] [blame] | 316 | nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.high_water = |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 317 | ntohl(nnm->msg.payload_info.high_water); |
| 318 | } |
| 319 | |
Sachin Shashidhar | 475012b | 2017-03-13 16:56:07 -0700 | [diff] [blame] | 320 | if (nnm->cm.type == NSS_TX_METADATA_TYPE_GET_PAGED_WATER_MARK) { |
| 321 | nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.pool_size = |
| 322 | ntohl(nnm->msg.paged_payload_info.pool_size); |
| 323 | nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.low_water = |
| 324 | ntohl(nnm->msg.paged_payload_info.low_water); |
| 325 | nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.high_water = |
| 326 | ntohl(nnm->msg.paged_payload_info.high_water); |
| 327 | } |
| 328 | |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 329 | nss_n2h_nepbcfgp[core_num].response = NSS_SUCCESS; |
| 330 | complete(&nss_n2h_nepbcfgp[core_num].complete); |
| 331 | } |
| 332 | |
| 333 | /* |
Pamidipati, Vijay | ee9c297 | 2016-01-10 08:13:19 +0530 | [diff] [blame] | 334 | * nss_n2h_set_wifi_payloads_callback() |
| 335 | * call back function for response to wifi pool configuration |
| 336 | * |
| 337 | */ |
| 338 | static void nss_n2h_set_wifi_payloads_callback(void *app_data, |
| 339 | struct nss_n2h_msg *nnm) |
| 340 | { |
Arunkumar T | ba9b4a0 | 2016-11-07 11:41:14 +0530 | [diff] [blame] | 341 | struct nss_ctx_instance *nss_ctx __maybe_unused = (struct nss_ctx_instance *)app_data; |
Pamidipati, Vijay | ee9c297 | 2016-01-10 08:13:19 +0530 | [diff] [blame] | 342 | if (nnm->cm.response != NSS_CMN_RESPONSE_ACK) { |
| 343 | |
| 344 | nss_n2h_wp.response = NSS_FAILURE; |
| 345 | complete(&nss_n2h_wp.complete); |
| 346 | nss_warning("%p: wifi pool configuration failed : %d\n", nss_ctx, |
| 347 | nnm->cm.error); |
| 348 | return; |
| 349 | } |
| 350 | |
| 351 | nss_info("%p: wifi payload configuration succeeded: %d\n", nss_ctx, |
| 352 | nnm->cm.error); |
| 353 | nss_n2h_wp.response = NSS_SUCCESS; |
| 354 | complete(&nss_n2h_wp.complete); |
| 355 | } |
| 356 | |
| 357 | /* |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 358 | * nss_n2h_get_payload_info() |
Sachin Shashidhar | 475012b | 2017-03-13 16:56:07 -0700 | [diff] [blame] | 359 | * Gets Payload information. |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 360 | */ |
Sachin Shashidhar | 475012b | 2017-03-13 16:56:07 -0700 | [diff] [blame] | 361 | static int nss_n2h_get_payload_info(nss_ptr_t core_num, struct nss_n2h_msg *nnm, struct nss_n2h_payload_info *nnepbcm) |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 362 | { |
| 363 | struct nss_top_instance *nss_top = &nss_top_main; |
| 364 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num]; |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 365 | nss_tx_status_t nss_tx_status; |
| 366 | int ret = NSS_FAILURE; |
| 367 | |
| 368 | /* |
| 369 | * Note that semaphore should be already held. |
| 370 | */ |
| 371 | |
Sachin Shashidhar | 475012b | 2017-03-13 16:56:07 -0700 | [diff] [blame] | 372 | nss_tx_status = nss_n2h_tx_msg(nss_ctx, nnm); |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 373 | |
| 374 | if (nss_tx_status != NSS_TX_SUCCESS) { |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 375 | nss_warning("%p: core %d nss_tx error errorn", nss_ctx, (int)core_num); |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 376 | return NSS_FAILURE; |
| 377 | } |
| 378 | |
| 379 | /* |
| 380 | * Blocking call, wait till we get ACK for this msg. |
| 381 | */ |
| 382 | ret = wait_for_completion_timeout(&nss_n2h_nepbcfgp[core_num].complete, |
| 383 | msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT)); |
| 384 | if (ret == 0) { |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 385 | nss_warning("%p: core %d waiting for ack timed out\n", nss_ctx, (int)core_num); |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 386 | return NSS_FAILURE; |
| 387 | } |
| 388 | |
| 389 | if (NSS_FAILURE == nss_n2h_nepbcfgp[core_num].response) { |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 390 | nss_warning("%p: core %d response returned failure\n", nss_ctx, (int)core_num); |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 391 | return NSS_FAILURE; |
| 392 | } |
| 393 | |
| 394 | return NSS_SUCCESS; |
| 395 | } |
| 396 | |
| 397 | /* |
Sachin Shashidhar | 475012b | 2017-03-13 16:56:07 -0700 | [diff] [blame] | 398 | * nss_n2h_get_default_payload_info() |
| 399 | * Gets the default payload information. |
| 400 | */ |
| 401 | static int nss_n2h_get_default_payload_info(nss_ptr_t core_num) |
| 402 | { |
| 403 | struct nss_n2h_msg nnm; |
| 404 | |
| 405 | nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, |
| 406 | NSS_TX_METADATA_TYPE_GET_WATER_MARK, |
| 407 | sizeof(struct nss_n2h_payload_info), |
| 408 | nss_n2h_payload_stats_callback, |
| 409 | (void *)core_num); |
| 410 | |
| 411 | return nss_n2h_get_payload_info(core_num, &nnm, |
| 412 | &nnm.msg.payload_info); |
| 413 | } |
| 414 | |
| 415 | /* |
| 416 | * nss_n2h_get_paged_payload_info() |
| 417 | * Gets the paged payload information. |
| 418 | */ |
| 419 | static int nss_n2h_get_paged_payload_info(nss_ptr_t core_num) |
| 420 | { |
| 421 | struct nss_n2h_msg nnm; |
| 422 | |
| 423 | nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, |
| 424 | NSS_TX_METADATA_TYPE_GET_PAGED_WATER_MARK, |
| 425 | sizeof(struct nss_n2h_payload_info), |
| 426 | nss_n2h_payload_stats_callback, |
| 427 | (void *)core_num); |
| 428 | |
| 429 | return nss_n2h_get_payload_info(core_num, &nnm, |
| 430 | &nnm.msg.paged_payload_info); |
| 431 | } |
| 432 | |
| 433 | /* |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 434 | * nss_n2h_set_empty_pool_buf() |
| 435 | * Sets empty pool buffer |
| 436 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 437 | 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] | 438 | void __user *buffer, |
| 439 | size_t *lenp, loff_t *ppos, |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 440 | nss_ptr_t core_num, int *new_val) |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 441 | { |
| 442 | struct nss_top_instance *nss_top = &nss_top_main; |
| 443 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num]; |
| 444 | struct nss_n2h_msg nnm; |
| 445 | struct nss_n2h_empty_pool_buf *nnepbcm; |
| 446 | nss_tx_status_t nss_tx_status; |
| 447 | int ret = NSS_FAILURE; |
| 448 | |
| 449 | /* |
| 450 | * Acquiring semaphore |
| 451 | */ |
| 452 | down(&nss_n2h_nepbcfgp[core_num].sem); |
| 453 | |
| 454 | /* |
| 455 | * Take snap shot of current value |
| 456 | */ |
Sachin Shashidhar | 475012b | 2017-03-13 16:56:07 -0700 | [diff] [blame] | 457 | nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.pool_size = *new_val; |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 458 | |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 459 | if (!write) { |
Sachin Shashidhar | 475012b | 2017-03-13 16:56:07 -0700 | [diff] [blame] | 460 | ret = nss_n2h_get_default_payload_info(core_num); |
| 461 | *new_val = nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.pool_size; |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 462 | if (ret == NSS_FAILURE) { |
| 463 | up(&nss_n2h_nepbcfgp[core_num].sem); |
| 464 | return -EBUSY; |
| 465 | } |
| 466 | |
| 467 | up(&nss_n2h_nepbcfgp[core_num].sem); |
| 468 | |
| 469 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 470 | return ret; |
| 471 | } |
| 472 | |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 473 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 474 | if (ret) { |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 475 | up(&nss_n2h_nepbcfgp[core_num].sem); |
| 476 | return ret; |
| 477 | } |
| 478 | |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 479 | if ((*new_val < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ)) { |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 480 | nss_warning("%p: core %d setting %d < min number of buffer", |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 481 | nss_ctx, (int)core_num, *new_val); |
Stephen Wang | 0676102 | 2015-03-03 16:38:42 -0800 | [diff] [blame] | 482 | goto failure; |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | nss_info("%p: core %d number of empty pool buffer is : %d\n", |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 486 | nss_ctx, (int)core_num, *new_val); |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 487 | |
| 488 | nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, |
| 489 | NSS_TX_METADATA_TYPE_N2H_EMPTY_POOL_BUF_CFG, |
| 490 | sizeof(struct nss_n2h_empty_pool_buf), |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 491 | nss_n2h_payload_stats_callback, |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 492 | (nss_ptr_t *)core_num); |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 493 | |
| 494 | nnepbcm = &nnm.msg.empty_pool_buf_cfg; |
| 495 | nnepbcm->pool_size = htonl(*new_val); |
| 496 | nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm); |
| 497 | |
| 498 | if (nss_tx_status != NSS_TX_SUCCESS) { |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 499 | nss_warning("%p: core %d nss_tx error empty pool buffer: %d\n", |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 500 | nss_ctx, (int)core_num, *new_val); |
Stephen Wang | 0676102 | 2015-03-03 16:38:42 -0800 | [diff] [blame] | 501 | goto failure; |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | /* |
| 505 | * Blocking call, wait till we get ACK for this msg. |
| 506 | */ |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 507 | ret = wait_for_completion_timeout(&nss_n2h_nepbcfgp[core_num].complete, |
| 508 | msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT)); |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 509 | if (ret == 0) { |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 510 | nss_warning("%p: core %d Waiting for ack timed out\n", nss_ctx, (int)core_num); |
Stephen Wang | 0676102 | 2015-03-03 16:38:42 -0800 | [diff] [blame] | 511 | goto failure; |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | /* |
| 515 | * ACK/NACK received from NSS FW |
| 516 | * If ACK: Callback function will update nss_n2h_empty_pool_buf with |
| 517 | * nss_n2h_nepbcfgp.num_conn_valid, which holds the user input |
| 518 | */ |
| 519 | if (NSS_FAILURE == nss_n2h_nepbcfgp[core_num].response) { |
Stephen Wang | 0676102 | 2015-03-03 16:38:42 -0800 | [diff] [blame] | 520 | goto failure; |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | up(&nss_n2h_nepbcfgp[core_num].sem); |
Thomas Wu | 651b390 | 2015-05-12 11:21:09 -0700 | [diff] [blame] | 524 | return 0; |
Stephen Wang | 0676102 | 2015-03-03 16:38:42 -0800 | [diff] [blame] | 525 | |
| 526 | failure: |
| 527 | /* |
| 528 | * Restore the current_value to its previous state |
| 529 | */ |
Sachin Shashidhar | 475012b | 2017-03-13 16:56:07 -0700 | [diff] [blame] | 530 | *new_val = nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.pool_size; |
| 531 | up(&nss_n2h_nepbcfgp[core_num].sem); |
| 532 | return NSS_FAILURE; |
| 533 | } |
| 534 | |
| 535 | /* |
| 536 | * nss_n2h_set_empty_paged_pool_buf() |
| 537 | * Sets empty paged pool buffer |
| 538 | */ |
| 539 | static int nss_n2h_set_empty_paged_pool_buf(struct ctl_table *ctl, int write, |
| 540 | void __user *buffer, |
| 541 | size_t *lenp, loff_t *ppos, |
| 542 | nss_ptr_t core_num, int *new_val) |
| 543 | { |
| 544 | struct nss_top_instance *nss_top = &nss_top_main; |
| 545 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num]; |
| 546 | struct nss_n2h_msg nnm; |
| 547 | struct nss_n2h_empty_pool_buf *nneppbcm; |
| 548 | nss_tx_status_t nss_tx_status; |
| 549 | int ret = NSS_FAILURE; |
| 550 | |
| 551 | /* |
| 552 | * Acquiring semaphore |
| 553 | */ |
| 554 | down(&nss_n2h_nepbcfgp[core_num].sem); |
| 555 | |
| 556 | /* |
| 557 | * Take snap shot of current value |
| 558 | */ |
| 559 | nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.pool_size = *new_val; |
| 560 | |
| 561 | if (!write) { |
| 562 | ret = nss_n2h_get_paged_payload_info(core_num); |
| 563 | *new_val = nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.pool_size; |
| 564 | if (ret == NSS_FAILURE) { |
| 565 | up(&nss_n2h_nepbcfgp[core_num].sem); |
| 566 | return -EBUSY; |
| 567 | } |
| 568 | |
| 569 | up(&nss_n2h_nepbcfgp[core_num].sem); |
| 570 | |
| 571 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 572 | return ret; |
| 573 | } |
| 574 | |
| 575 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 576 | if (ret) { |
| 577 | up(&nss_n2h_nepbcfgp[core_num].sem); |
| 578 | return ret; |
| 579 | } |
| 580 | |
| 581 | if ((*new_val < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ)) { |
| 582 | nss_warning("%p: core %d setting %d < min number of buffer", |
| 583 | nss_ctx, (int)core_num, *new_val); |
| 584 | goto failure; |
| 585 | } |
| 586 | |
| 587 | nss_info("%p: core %d number of empty paged pool buffer is : %d\n", |
| 588 | nss_ctx, (int)core_num, *new_val); |
| 589 | |
| 590 | nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, |
| 591 | NSS_TX_METADATA_TYPE_N2H_EMPTY_PAGED_POOL_BUF_CFG, |
| 592 | sizeof(struct nss_n2h_empty_pool_buf), |
| 593 | nss_n2h_payload_stats_callback, |
| 594 | (nss_ptr_t *)core_num); |
| 595 | |
| 596 | nneppbcm = &nnm.msg.empty_pool_buf_cfg; |
| 597 | nneppbcm->pool_size = htonl(*new_val); |
| 598 | nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm); |
| 599 | |
| 600 | if (nss_tx_status != NSS_TX_SUCCESS) { |
| 601 | nss_warning("%p: core %d nss_tx error empty paged pool buffer: %d\n", |
| 602 | nss_ctx, (int)core_num, *new_val); |
| 603 | goto failure; |
| 604 | } |
| 605 | |
| 606 | /* |
| 607 | * Blocking call, wait till we get ACK for this msg. |
| 608 | */ |
| 609 | ret = wait_for_completion_timeout(&nss_n2h_nepbcfgp[core_num].complete, |
| 610 | msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT)); |
| 611 | if (ret == 0) { |
| 612 | nss_warning("%p: core %d Waiting for ack timed out\n", nss_ctx, (int)core_num); |
| 613 | goto failure; |
| 614 | } |
| 615 | |
| 616 | /* |
| 617 | * ACK/NACK received from NSS FW |
| 618 | * If ACK: Callback function will update nss_n2h_empty_pool_buf with |
| 619 | * nss_n2h_nepbcfgp.num_conn_valid, which holds the user input |
| 620 | */ |
| 621 | if (NSS_FAILURE == nss_n2h_nepbcfgp[core_num].response) { |
| 622 | goto failure; |
| 623 | } |
| 624 | |
| 625 | up(&nss_n2h_nepbcfgp[core_num].sem); |
| 626 | return 0; |
| 627 | |
| 628 | failure: |
| 629 | /* |
| 630 | * Restore the current_value to its previous state |
| 631 | */ |
| 632 | *new_val = nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.pool_size; |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 633 | up(&nss_n2h_nepbcfgp[core_num].sem); |
| 634 | return NSS_FAILURE; |
| 635 | } |
| 636 | |
| 637 | /* |
| 638 | * nss_n2h_set_water_mark() |
| 639 | * Sets water mark for N2H SOS |
| 640 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 641 | 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] | 642 | void __user *buffer, |
| 643 | size_t *lenp, loff_t *ppos, |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 644 | uint32_t core_num, int *low, int *high) |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 645 | { |
| 646 | struct nss_top_instance *nss_top = &nss_top_main; |
| 647 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num]; |
| 648 | struct nss_n2h_msg nnm; |
| 649 | struct nss_n2h_water_mark *wm; |
| 650 | nss_tx_status_t nss_tx_status; |
| 651 | int ret = NSS_FAILURE; |
| 652 | |
| 653 | /* |
| 654 | * Acquiring semaphore |
| 655 | */ |
| 656 | down(&nss_n2h_nepbcfgp[core_num].sem); |
| 657 | |
| 658 | /* |
| 659 | * Take snap shot of current value |
| 660 | */ |
Sachin Shashidhar | 475012b | 2017-03-13 16:56:07 -0700 | [diff] [blame] | 661 | nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.low_water = *low; |
| 662 | nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.high_water = *high; |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 663 | |
Sachin Shashidhar | 475012b | 2017-03-13 16:56:07 -0700 | [diff] [blame] | 664 | if (!write || *low == -1 || *high == -1) { |
| 665 | ret = nss_n2h_get_default_payload_info(core_num); |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 666 | if (ret == NSS_FAILURE) { |
| 667 | up(&nss_n2h_nepbcfgp[core_num].sem); |
| 668 | return -EBUSY; |
| 669 | } |
| 670 | |
Sachin Shashidhar | 475012b | 2017-03-13 16:56:07 -0700 | [diff] [blame] | 671 | *low = nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.low_water; |
| 672 | *high = nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.high_water; |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
Sachin Shashidhar | 475012b | 2017-03-13 16:56:07 -0700 | [diff] [blame] | 676 | if (!write || ret) { |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 677 | up(&nss_n2h_nepbcfgp[core_num].sem); |
| 678 | return ret; |
| 679 | } |
| 680 | |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 681 | if ((*low < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ) || |
| 682 | (*high < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ)) { |
| 683 | nss_warning("%p: core %d setting %d, %d < min number of buffer", |
| 684 | nss_ctx, core_num, *low, *high); |
| 685 | goto failure; |
| 686 | } |
| 687 | |
Pamidipati, Vijay | ee9c297 | 2016-01-10 08:13:19 +0530 | [diff] [blame] | 688 | if ((*low > NSS_N2H_MAX_EMPTY_POOL_BUF_SZ) || |
| 689 | (*high > NSS_N2H_MAX_EMPTY_POOL_BUF_SZ)) { |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 690 | nss_warning("%p: core %d setting %d, %d is > upper limit", |
| 691 | nss_ctx, core_num, *low, *high); |
| 692 | goto failure; |
| 693 | } |
| 694 | |
| 695 | if (*low > *high) { |
| 696 | nss_warning("%p: core %d setting low %d is more than high %d", |
| 697 | nss_ctx, core_num, *low, *high); |
| 698 | goto failure; |
| 699 | } |
| 700 | |
| 701 | nss_info("%p: core %d number of low : %d and high : %d\n", |
| 702 | nss_ctx, core_num, *low, *high); |
| 703 | |
| 704 | nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, |
| 705 | NSS_TX_METADATA_TYPE_SET_WATER_MARK, |
| 706 | sizeof(struct nss_n2h_water_mark), |
| 707 | nss_n2h_payload_stats_callback, |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 708 | (void *)(nss_ptr_t)core_num); |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 709 | |
| 710 | wm = &nnm.msg.wm; |
| 711 | wm->low_water = htonl(*low); |
| 712 | wm->high_water = htonl(*high); |
| 713 | nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm); |
| 714 | |
| 715 | if (nss_tx_status != NSS_TX_SUCCESS) { |
| 716 | nss_warning("%p: core %d nss_tx error setting : %d, %d\n", |
| 717 | nss_ctx, core_num, *low, *high); |
| 718 | goto failure; |
| 719 | } |
| 720 | |
| 721 | /* |
| 722 | * Blocking call, wait till we get ACK for this msg. |
| 723 | */ |
| 724 | ret = wait_for_completion_timeout(&nss_n2h_nepbcfgp[core_num].complete, |
| 725 | msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT)); |
| 726 | if (ret == 0) { |
| 727 | nss_warning("%p: core %d Waiting for ack timed out\n", nss_ctx, |
| 728 | core_num); |
| 729 | goto failure; |
| 730 | } |
| 731 | |
| 732 | /* |
| 733 | * ACK/NACK received from NSS FW |
| 734 | */ |
| 735 | if (NSS_FAILURE == nss_n2h_nepbcfgp[core_num].response) |
| 736 | goto failure; |
| 737 | |
| 738 | up(&nss_n2h_nepbcfgp[core_num].sem); |
| 739 | return NSS_SUCCESS; |
| 740 | |
| 741 | failure: |
| 742 | /* |
| 743 | * Restore the current_value to its previous state |
| 744 | */ |
Sachin Shashidhar | 475012b | 2017-03-13 16:56:07 -0700 | [diff] [blame] | 745 | *low = nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.low_water; |
| 746 | *high = nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.high_water; |
| 747 | up(&nss_n2h_nepbcfgp[core_num].sem); |
| 748 | return -EINVAL; |
| 749 | } |
| 750 | |
| 751 | /* |
| 752 | * nss_n2h_set_paged_water_mark() |
| 753 | * Sets water mark for paged pool N2H SOS |
| 754 | */ |
| 755 | static int nss_n2h_set_paged_water_mark(struct ctl_table *ctl, int write, |
| 756 | void __user *buffer, |
| 757 | size_t *lenp, loff_t *ppos, |
| 758 | uint32_t core_num, int *low, int *high) |
| 759 | { |
| 760 | struct nss_top_instance *nss_top = &nss_top_main; |
| 761 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num]; |
| 762 | struct nss_n2h_msg nnm; |
| 763 | struct nss_n2h_water_mark *pwm; |
| 764 | nss_tx_status_t nss_tx_status; |
| 765 | int ret = NSS_FAILURE; |
| 766 | |
| 767 | /* |
| 768 | * Acquiring semaphore |
| 769 | */ |
| 770 | down(&nss_n2h_nepbcfgp[core_num].sem); |
| 771 | |
| 772 | /* |
| 773 | * Take snap shot of current value |
| 774 | */ |
| 775 | nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.low_water = *low; |
| 776 | nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.high_water = *high; |
| 777 | |
| 778 | if (!write || *low == -1 || *high == -1) { |
| 779 | ret = nss_n2h_get_paged_payload_info(core_num); |
| 780 | if (ret == NSS_FAILURE) { |
| 781 | up(&nss_n2h_nepbcfgp[core_num].sem); |
| 782 | return -EBUSY; |
| 783 | } |
| 784 | |
| 785 | *low = nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.low_water; |
| 786 | *high = nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.high_water; |
| 787 | } |
| 788 | |
| 789 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 790 | if (!write || ret) { |
| 791 | up(&nss_n2h_nepbcfgp[core_num].sem); |
| 792 | return ret; |
| 793 | } |
| 794 | |
| 795 | if ((*low < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ) || |
| 796 | (*high < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ)) { |
| 797 | nss_warning("%p: core %d setting %d, %d < min number of buffer", |
| 798 | nss_ctx, core_num, *low, *high); |
| 799 | goto failure; |
| 800 | } |
| 801 | |
| 802 | if ((*low > NSS_N2H_MAX_EMPTY_POOL_BUF_SZ) || |
| 803 | (*high > NSS_N2H_MAX_EMPTY_POOL_BUF_SZ)) { |
| 804 | nss_warning("%p: core %d setting %d, %d is > upper limit", |
| 805 | nss_ctx, core_num, *low, *high); |
| 806 | goto failure; |
| 807 | } |
| 808 | |
| 809 | if (*low > *high) { |
| 810 | nss_warning("%p: core %d setting low %d is more than high %d", |
| 811 | nss_ctx, core_num, *low, *high); |
| 812 | goto failure; |
| 813 | } |
| 814 | |
| 815 | nss_info("%p: core %d number of low : %d and high : %d\n", |
| 816 | nss_ctx, core_num, *low, *high); |
| 817 | |
| 818 | nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, |
| 819 | NSS_TX_METADATA_TYPE_SET_PAGED_WATER_MARK, |
| 820 | sizeof(struct nss_n2h_water_mark), |
| 821 | nss_n2h_payload_stats_callback, |
| 822 | (void *)(nss_ptr_t)core_num); |
| 823 | |
| 824 | pwm = &nnm.msg.wm_paged; |
| 825 | pwm->low_water = htonl(*low); |
| 826 | pwm->high_water = htonl(*high); |
| 827 | nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm); |
| 828 | |
| 829 | if (nss_tx_status != NSS_TX_SUCCESS) { |
| 830 | nss_warning("%p: core %d nss_tx error setting : %d, %d\n", |
| 831 | nss_ctx, core_num, *low, *high); |
| 832 | goto failure; |
| 833 | } |
| 834 | |
| 835 | /* |
| 836 | * Blocking call, wait till we get ACK for this msg. |
| 837 | */ |
| 838 | ret = wait_for_completion_timeout(&nss_n2h_nepbcfgp[core_num].complete, |
| 839 | msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT)); |
| 840 | if (ret == 0) { |
| 841 | nss_warning("%p: core %d Waiting for ack timed out\n", nss_ctx, |
| 842 | core_num); |
| 843 | goto failure; |
| 844 | } |
| 845 | |
| 846 | /* |
| 847 | * ACK/NACK received from NSS FW |
| 848 | */ |
| 849 | if (NSS_FAILURE == nss_n2h_nepbcfgp[core_num].response) |
| 850 | goto failure; |
| 851 | |
| 852 | up(&nss_n2h_nepbcfgp[core_num].sem); |
| 853 | return NSS_SUCCESS; |
| 854 | |
| 855 | failure: |
| 856 | /* |
| 857 | * Restore the current_value to its previous state |
| 858 | */ |
| 859 | *low = nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.low_water; |
| 860 | *high = nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.high_water; |
Stephen Wang | 0676102 | 2015-03-03 16:38:42 -0800 | [diff] [blame] | 861 | up(&nss_n2h_nepbcfgp[core_num].sem); |
Thomas Wu | 651b390 | 2015-05-12 11:21:09 -0700 | [diff] [blame] | 862 | return -EINVAL; |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | /* |
Pamidipati, Vijay | ee9c297 | 2016-01-10 08:13:19 +0530 | [diff] [blame] | 866 | * nss_n2h_cfg_wifi_pool() |
| 867 | * Sets number of wifi payloads to adjust high water mark for N2H SoS |
| 868 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 869 | 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] | 870 | void __user *buffer, |
| 871 | size_t *lenp, loff_t *ppos, |
| 872 | int *payloads) |
| 873 | { |
| 874 | struct nss_top_instance *nss_top = &nss_top_main; |
| 875 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[0]; |
| 876 | struct nss_n2h_msg nnm; |
| 877 | struct nss_n2h_wifi_payloads *wp; |
| 878 | nss_tx_status_t nss_tx_status; |
| 879 | int ret = NSS_FAILURE; |
| 880 | |
| 881 | /* |
| 882 | * Acquiring semaphore |
| 883 | */ |
| 884 | down(&nss_n2h_wp.sem); |
| 885 | |
| 886 | if (!write) { |
| 887 | *payloads = nss_n2h_wp.wifi_pool; |
| 888 | |
| 889 | up(&nss_n2h_wp.sem); |
| 890 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 891 | return ret; |
| 892 | } |
| 893 | |
| 894 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 895 | if (ret) { |
| 896 | up(&nss_n2h_wp.sem); |
| 897 | return ret; |
| 898 | } |
| 899 | |
| 900 | /* |
| 901 | * If payloads parameter is not set, we do |
| 902 | * nothing. |
| 903 | */ |
| 904 | if (*payloads == -1) |
| 905 | goto failure; |
| 906 | |
| 907 | if ((*payloads < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ)) { |
| 908 | nss_warning("%p: wifi setting %d < min number of buffer", |
| 909 | nss_ctx, *payloads); |
| 910 | goto failure; |
| 911 | } |
| 912 | |
| 913 | if ((*payloads > NSS_N2H_MAX_EMPTY_POOL_BUF_SZ)) { |
| 914 | nss_warning("%p: wifi setting %d > max number of buffer", |
| 915 | nss_ctx, *payloads); |
| 916 | goto failure; |
| 917 | } |
| 918 | |
| 919 | nss_info("%p: wifi payloads : %d\n", |
| 920 | nss_ctx, *payloads); |
| 921 | |
| 922 | nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, |
| 923 | NSS_TX_METADATA_TYPE_N2H_WIFI_POOL_BUF_CFG, |
| 924 | sizeof(struct nss_n2h_wifi_payloads), |
| 925 | nss_n2h_set_wifi_payloads_callback, |
| 926 | (void *)nss_ctx); |
| 927 | |
| 928 | wp = &nnm.msg.wp; |
| 929 | wp->payloads = htonl(*payloads); |
| 930 | nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm); |
| 931 | |
| 932 | if (nss_tx_status != NSS_TX_SUCCESS) { |
| 933 | nss_warning("%p: wifi setting %d nss_tx error", |
| 934 | nss_ctx, *payloads); |
| 935 | goto failure; |
| 936 | } |
| 937 | |
| 938 | /* |
| 939 | * Blocking call, wait till we get ACK for this msg. |
| 940 | */ |
| 941 | ret = wait_for_completion_timeout(&nss_n2h_wp.complete, |
| 942 | msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT)); |
| 943 | if (ret == 0) { |
| 944 | nss_warning("%p: Waiting for ack timed out\n", nss_ctx); |
| 945 | goto failure; |
| 946 | } |
| 947 | |
| 948 | /* |
| 949 | * ACK/NACK received from NSS FW |
| 950 | */ |
| 951 | if (NSS_FAILURE == nss_n2h_wp.response) |
| 952 | goto failure; |
| 953 | |
| 954 | up(&nss_n2h_wp.sem); |
| 955 | return NSS_SUCCESS; |
| 956 | |
| 957 | failure: |
| 958 | up(&nss_n2h_wp.sem); |
| 959 | return -EINVAL; |
| 960 | } |
| 961 | |
| 962 | /* |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 963 | * nss_n2h_empty_pool_buf_core1_handler() |
| 964 | * Sets the number of empty buffer for core 1 |
| 965 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 966 | 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] | 967 | int write, void __user *buffer, |
| 968 | size_t *lenp, loff_t *ppos) |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 969 | { |
| 970 | return nss_n2h_set_empty_pool_buf(ctl, write, buffer, lenp, ppos, |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 971 | NSS_CORE_1, &nss_n2h_empty_pool_buf_cfg[NSS_CORE_1]); |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | /* |
| 975 | * nss_n2h_empty_pool_buf_core0_handler() |
| 976 | * Sets the number of empty buffer for core 0 |
| 977 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 978 | 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] | 979 | int write, void __user *buffer, |
| 980 | size_t *lenp, loff_t *ppos) |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 981 | { |
| 982 | return nss_n2h_set_empty_pool_buf(ctl, write, buffer, lenp, ppos, |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 983 | NSS_CORE_0, &nss_n2h_empty_pool_buf_cfg[NSS_CORE_0]); |
| 984 | } |
| 985 | |
| 986 | /* |
Sachin Shashidhar | 475012b | 2017-03-13 16:56:07 -0700 | [diff] [blame] | 987 | * nss_n2h_empty_paged_pool_buf_cfg_core1_handler() |
| 988 | * Sets the number of empty paged buffer for core 1 |
| 989 | */ |
| 990 | static int nss_n2h_empty_paged_pool_buf_cfg_core1_handler(struct ctl_table *ctl, |
| 991 | int write, void __user *buffer, |
| 992 | size_t *lenp, loff_t *ppos) |
| 993 | { |
| 994 | return nss_n2h_set_empty_paged_pool_buf(ctl, write, buffer, lenp, ppos, |
| 995 | NSS_CORE_1, &nss_n2h_empty_paged_pool_buf_cfg[NSS_CORE_1]); |
| 996 | } |
| 997 | |
| 998 | /* |
| 999 | * nss_n2h_empty_paged_pool_buf_cfg_core0_handler() |
| 1000 | * Sets the number of empty paged buffer for core 0 |
| 1001 | */ |
| 1002 | static int nss_n2h_empty_paged_pool_buf_cfg_core0_handler(struct ctl_table *ctl, |
| 1003 | int write, void __user *buffer, |
| 1004 | size_t *lenp, loff_t *ppos) |
| 1005 | { |
| 1006 | return nss_n2h_set_empty_paged_pool_buf(ctl, write, buffer, lenp, ppos, |
| 1007 | NSS_CORE_0, &nss_n2h_empty_paged_pool_buf_cfg[NSS_CORE_0]); |
| 1008 | } |
| 1009 | |
| 1010 | /* |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 1011 | * nss_n2h_water_mark_core1_handler() |
| 1012 | * Sets water mark for core 1 |
| 1013 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 1014 | static int nss_n2h_water_mark_core1_handler(struct ctl_table *ctl, |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 1015 | int write, void __user *buffer, |
| 1016 | size_t *lenp, loff_t *ppos) |
| 1017 | { |
| 1018 | return nss_n2h_set_water_mark(ctl, write, buffer, lenp, ppos, |
| 1019 | NSS_CORE_1, &nss_n2h_water_mark[NSS_CORE_1][0], |
| 1020 | &nss_n2h_water_mark[NSS_CORE_1][1]); |
| 1021 | } |
| 1022 | |
| 1023 | /* |
| 1024 | * nss_n2h_water_mark_core0_handler() |
| 1025 | * Sets water mark for core 0 |
| 1026 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 1027 | static int nss_n2h_water_mark_core0_handler(struct ctl_table *ctl, |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 1028 | int write, void __user *buffer, |
| 1029 | size_t *lenp, loff_t *ppos) |
| 1030 | { |
| 1031 | return nss_n2h_set_water_mark(ctl, write, buffer, lenp, ppos, |
| 1032 | NSS_CORE_0, &nss_n2h_water_mark[NSS_CORE_0][0], |
| 1033 | &nss_n2h_water_mark[NSS_CORE_0][1]); |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 1034 | } |
| 1035 | |
Vijay Dewangan | 634ce59 | 2015-01-07 17:21:09 -0800 | [diff] [blame] | 1036 | /* |
Sachin Shashidhar | 475012b | 2017-03-13 16:56:07 -0700 | [diff] [blame] | 1037 | * nss_n2h_paged_water_mark_core1_handler() |
| 1038 | * Sets paged water mark for core 1 |
| 1039 | */ |
| 1040 | static int nss_n2h_paged_water_mark_core1_handler(struct ctl_table *ctl, |
| 1041 | int write, void __user *buffer, |
| 1042 | size_t *lenp, loff_t *ppos) |
| 1043 | { |
| 1044 | return nss_n2h_set_paged_water_mark(ctl, write, buffer, lenp, ppos, |
| 1045 | NSS_CORE_1, &nss_n2h_paged_water_mark[NSS_CORE_1][0], |
| 1046 | &nss_n2h_paged_water_mark[NSS_CORE_1][1]); |
| 1047 | } |
| 1048 | |
Sachin Shashidhar | 475012b | 2017-03-13 16:56:07 -0700 | [diff] [blame] | 1049 | /* |
| 1050 | * nss_n2h_paged_water_mark_core0_handler() |
| 1051 | * Sets paged water mark for core 0 |
| 1052 | */ |
| 1053 | static int nss_n2h_paged_water_mark_core0_handler(struct ctl_table *ctl, |
| 1054 | int write, void __user *buffer, |
| 1055 | size_t *lenp, loff_t *ppos) |
| 1056 | { |
| 1057 | return nss_n2h_set_paged_water_mark(ctl, write, buffer, lenp, ppos, |
| 1058 | NSS_CORE_0, &nss_n2h_paged_water_mark[NSS_CORE_0][0], |
| 1059 | &nss_n2h_paged_water_mark[NSS_CORE_0][1]); |
| 1060 | } |
| 1061 | |
| 1062 | /* |
Pamidipati, Vijay | ee9c297 | 2016-01-10 08:13:19 +0530 | [diff] [blame] | 1063 | * nss_n2h_wifi_payloads_handler() |
| 1064 | * Sets number of wifi payloads |
| 1065 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 1066 | static int nss_n2h_wifi_payloads_handler(struct ctl_table *ctl, |
Pamidipati, Vijay | ee9c297 | 2016-01-10 08:13:19 +0530 | [diff] [blame] | 1067 | int write, void __user *buffer, |
| 1068 | size_t *lenp, loff_t *ppos) |
| 1069 | { |
| 1070 | return nss_n2h_cfg_wifi_pool(ctl, write, buffer, lenp, ppos, |
| 1071 | &nss_n2h_wifi_pool_buf_cfg); |
| 1072 | } |
| 1073 | |
| 1074 | /* |
ratheesh kannoth | ab436af | 2017-07-20 08:51:07 +0530 | [diff] [blame] | 1075 | * nss_n2h_update_queue_config_callback() |
| 1076 | * Callback to handle the completion of queue config command |
ratheesh kannoth | 024a6e8 | 2017-05-18 17:48:10 +0530 | [diff] [blame] | 1077 | */ |
ratheesh kannoth | ab436af | 2017-07-20 08:51:07 +0530 | [diff] [blame] | 1078 | static void nss_n2h_update_queue_config_callback(void *app_data, struct nss_n2h_msg *nim) |
ratheesh kannoth | 024a6e8 | 2017-05-18 17:48:10 +0530 | [diff] [blame] | 1079 | { |
ratheesh kannoth | ab436af | 2017-07-20 08:51:07 +0530 | [diff] [blame] | 1080 | if (nim->cm.response != NSS_CMN_RESPONSE_ACK) { |
| 1081 | nss_warning("n2h Error response %d\n", nim->cm.response); |
| 1082 | nss_n2h_q_cfg_pvt.response = NSS_TX_FAILURE; |
| 1083 | } else { |
| 1084 | nss_n2h_q_cfg_pvt.response = NSS_TX_SUCCESS; |
| 1085 | } |
| 1086 | |
| 1087 | complete(&nss_n2h_q_cfg_pvt.complete); |
| 1088 | } |
| 1089 | |
| 1090 | /* |
| 1091 | * nss_n2h_update_queue_config_async() |
| 1092 | * Asynchronous call to send pnode queue configuration. |
| 1093 | */ |
| 1094 | nss_tx_status_t nss_n2h_update_queue_config_async(struct nss_ctx_instance *nss_ctx, bool mq_en, uint16_t *qlimits) |
| 1095 | { |
| 1096 | |
ratheesh kannoth | 024a6e8 | 2017-05-18 17:48:10 +0530 | [diff] [blame] | 1097 | struct nss_n2h_msg nnm; |
| 1098 | struct nss_n2h_pnode_queue_config *cfg; |
| 1099 | nss_tx_status_t status; |
ratheesh kannoth | 024a6e8 | 2017-05-18 17:48:10 +0530 | [diff] [blame] | 1100 | int i; |
| 1101 | |
| 1102 | if (!mq_en) { |
| 1103 | return NSS_TX_SUCCESS; |
| 1104 | } |
| 1105 | |
ratheesh kannoth | 93ba95c | 2017-07-13 15:52:52 +0530 | [diff] [blame] | 1106 | /* |
| 1107 | * MQ mode doesnot make any sense if number of priority queues in NSS |
| 1108 | * is 1 |
| 1109 | */ |
| 1110 | if (NSS_MAX_NUM_PRI <= 1) { |
| 1111 | return NSS_TX_SUCCESS; |
| 1112 | } |
| 1113 | |
ratheesh kannoth | ab436af | 2017-07-20 08:51:07 +0530 | [diff] [blame] | 1114 | memset(&nnm, 0, sizeof(struct nss_n2h_msg)); |
ratheesh kannoth | 024a6e8 | 2017-05-18 17:48:10 +0530 | [diff] [blame] | 1115 | |
ratheesh kannoth | 024a6e8 | 2017-05-18 17:48:10 +0530 | [diff] [blame] | 1116 | nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, |
| 1117 | NSS_TX_METADATA_TYPE_N2H_SET_PNODE_QUEUE_CFG, |
| 1118 | sizeof(struct nss_n2h_pnode_queue_config), NULL, 0); |
| 1119 | |
ratheesh kannoth | ab436af | 2017-07-20 08:51:07 +0530 | [diff] [blame] | 1120 | cfg = &nnm.msg.pn_q_cfg; |
| 1121 | |
| 1122 | /* |
| 1123 | * Update limits |
| 1124 | */ |
| 1125 | for (i = 0; i < NSS_MAX_NUM_PRI; i++) { |
| 1126 | cfg->qlimits[i] = qlimits[i]; |
| 1127 | } |
| 1128 | cfg->mq_en = true; |
| 1129 | |
ratheesh kannoth | 024a6e8 | 2017-05-18 17:48:10 +0530 | [diff] [blame] | 1130 | status = nss_n2h_tx_msg(nss_ctx, &nnm); |
| 1131 | if (status != NSS_TX_SUCCESS) { |
| 1132 | nss_warning("%p: nss_tx error to send pnode queue config\n", nss_ctx); |
| 1133 | return status; |
| 1134 | } |
| 1135 | |
| 1136 | return NSS_TX_SUCCESS; |
ratheesh kannoth | 024a6e8 | 2017-05-18 17:48:10 +0530 | [diff] [blame] | 1137 | } |
ratheesh kannoth | ab436af | 2017-07-20 08:51:07 +0530 | [diff] [blame] | 1138 | EXPORT_SYMBOL(nss_n2h_update_queue_config_async); |
| 1139 | |
| 1140 | /* |
| 1141 | * nss_n2h_update_queue_config_sync() |
| 1142 | * Synchronous call to send pnode queue configuration. |
| 1143 | */ |
| 1144 | nss_tx_status_t nss_n2h_update_queue_config_sync(struct nss_ctx_instance *nss_ctx, bool mq_en, uint16_t *qlimits) |
| 1145 | { |
| 1146 | |
| 1147 | struct nss_n2h_msg nnm; |
| 1148 | struct nss_n2h_pnode_queue_config *cfg; |
| 1149 | nss_tx_status_t status; |
| 1150 | int ret, i; |
| 1151 | |
| 1152 | if (!mq_en) { |
| 1153 | return NSS_TX_SUCCESS; |
| 1154 | } |
| 1155 | |
ratheesh kannoth | 93ba95c | 2017-07-13 15:52:52 +0530 | [diff] [blame] | 1156 | /* |
| 1157 | * MQ mode doesnot make any sense if number of priority queues in NSS |
| 1158 | * is 1 |
| 1159 | */ |
| 1160 | if (NSS_MAX_NUM_PRI <= 1) { |
| 1161 | return NSS_TX_SUCCESS; |
| 1162 | } |
| 1163 | |
ratheesh kannoth | ab436af | 2017-07-20 08:51:07 +0530 | [diff] [blame] | 1164 | memset(&nnm, 0, sizeof(struct nss_n2h_msg)); |
| 1165 | |
| 1166 | nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, |
| 1167 | NSS_TX_METADATA_TYPE_N2H_SET_PNODE_QUEUE_CFG, |
| 1168 | sizeof(struct nss_n2h_pnode_queue_config), nss_n2h_update_queue_config_callback, 0); |
| 1169 | |
| 1170 | cfg = &nnm.msg.pn_q_cfg; |
| 1171 | |
| 1172 | /* |
| 1173 | * Update limits |
| 1174 | */ |
| 1175 | for (i = 0; i < NSS_MAX_NUM_PRI; i++) { |
| 1176 | cfg->qlimits[i] = qlimits[i]; |
| 1177 | } |
| 1178 | cfg->mq_en = true; |
| 1179 | |
| 1180 | down(&nss_n2h_q_cfg_pvt.sem); |
| 1181 | |
| 1182 | status = nss_n2h_tx_msg(nss_ctx, &nnm); |
| 1183 | |
| 1184 | if (status != NSS_TX_SUCCESS) { |
| 1185 | nss_warning("%p: n2h_tx_msg failed\n", nss_ctx); |
| 1186 | up(&nss_n2h_q_cfg_pvt.sem); |
| 1187 | return status; |
| 1188 | } |
| 1189 | ret = wait_for_completion_timeout(&nss_n2h_q_cfg_pvt.complete, msecs_to_jiffies(NSS_N2H_TX_TIMEOUT)); |
| 1190 | |
| 1191 | if (!ret) { |
| 1192 | nss_warning("%p: Timeout expired for pnode queue config sync message\n", nss_ctx); |
| 1193 | nss_n2h_q_cfg_pvt.response = NSS_TX_FAILURE; |
| 1194 | } |
| 1195 | |
| 1196 | status = nss_n2h_q_cfg_pvt.response; |
| 1197 | up(&nss_n2h_q_cfg_pvt.sem); |
| 1198 | return status; |
| 1199 | } |
| 1200 | EXPORT_SYMBOL(nss_n2h_update_queue_config_sync); |
ratheesh kannoth | 024a6e8 | 2017-05-18 17:48:10 +0530 | [diff] [blame] | 1201 | |
| 1202 | /* |
Vijay Dewangan | 634ce59 | 2015-01-07 17:21:09 -0800 | [diff] [blame] | 1203 | * nss_n2h_rps_cfg() |
| 1204 | * Send Message to NSS to enable RPS. |
| 1205 | */ |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 1206 | 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] | 1207 | { |
| 1208 | struct nss_n2h_msg nnm; |
| 1209 | struct nss_n2h_rps *rps_cfg; |
| 1210 | nss_tx_status_t nss_tx_status; |
| 1211 | int ret; |
| 1212 | |
| 1213 | down(&nss_n2h_rcp.sem); |
| 1214 | nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, NSS_TX_METADATA_TYPE_N2H_RPS_CFG, |
| 1215 | sizeof(struct nss_n2h_rps), |
| 1216 | nss_n2h_rps_cfg_callback, |
| 1217 | (void *)nss_ctx); |
| 1218 | |
| 1219 | rps_cfg = &nnm.msg.rps_cfg; |
| 1220 | rps_cfg->enable = enable_rps; |
| 1221 | |
| 1222 | nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm); |
| 1223 | |
| 1224 | if (nss_tx_status != NSS_TX_SUCCESS) { |
| 1225 | nss_warning("%p: nss_tx error setting rps\n", nss_ctx); |
| 1226 | |
| 1227 | up(&nss_n2h_rcp.sem); |
| 1228 | return NSS_FAILURE; |
| 1229 | } |
| 1230 | |
| 1231 | /* |
| 1232 | * Blocking call, wait till we get ACK for this msg. |
| 1233 | */ |
| 1234 | ret = wait_for_completion_timeout(&nss_n2h_rcp.complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT)); |
| 1235 | if (ret == 0) { |
| 1236 | nss_warning("%p: Waiting for ack timed out\n", nss_ctx); |
| 1237 | up(&nss_n2h_rcp.sem); |
| 1238 | return NSS_FAILURE; |
| 1239 | } |
| 1240 | |
| 1241 | /* |
| 1242 | * ACK/NACK received from NSS FW |
| 1243 | * If ACK: Callback function will update nss_n2h_empty_pool_buf with |
| 1244 | * nss_n2h_nepbcfgp.num_conn_valid, which holds the user input |
| 1245 | */ |
| 1246 | if (NSS_FAILURE == nss_n2h_rcp.response) { |
| 1247 | up(&nss_n2h_rcp.sem); |
| 1248 | return NSS_FAILURE; |
| 1249 | } |
| 1250 | |
| 1251 | up(&nss_n2h_rcp.sem); |
| 1252 | return NSS_SUCCESS; |
| 1253 | } |
| 1254 | |
Kalyan Tallapragada | b50e890 | 2015-08-06 17:00:54 +0530 | [diff] [blame] | 1255 | /* |
| 1256 | * nss_n2h_mitigation_cfg() |
| 1257 | * Send Message to NSS to disable MITIGATION. |
| 1258 | */ |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 1259 | 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] | 1260 | { |
| 1261 | struct nss_n2h_msg nnm; |
| 1262 | struct nss_n2h_mitigation *mitigation_cfg; |
| 1263 | nss_tx_status_t nss_tx_status; |
| 1264 | int ret; |
| 1265 | |
| 1266 | nss_assert(core_num < NSS_CORE_MAX); |
| 1267 | |
| 1268 | down(&nss_n2h_mitigationcp[core_num].sem); |
| 1269 | nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, NSS_TX_METADATA_TYPE_N2H_MITIGATION_CFG, |
| 1270 | sizeof(struct nss_n2h_mitigation), |
| 1271 | nss_n2h_mitigation_cfg_callback, |
| 1272 | (void *)core_num); |
| 1273 | |
| 1274 | mitigation_cfg = &nnm.msg.mitigation_cfg; |
| 1275 | mitigation_cfg->enable = enable_mitigation; |
| 1276 | |
| 1277 | nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm); |
| 1278 | |
| 1279 | if (nss_tx_status != NSS_TX_SUCCESS) { |
| 1280 | nss_warning("%p: nss_tx error setting mitigation\n", nss_ctx); |
| 1281 | goto failure; |
| 1282 | } |
| 1283 | |
| 1284 | /* |
| 1285 | * Blocking call, wait till we get ACK for this msg. |
| 1286 | */ |
| 1287 | ret = wait_for_completion_timeout(&nss_n2h_mitigationcp[core_num].complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT)); |
| 1288 | if (ret == 0) { |
| 1289 | nss_warning("%p: Waiting for ack timed out\n", nss_ctx); |
| 1290 | goto failure; |
| 1291 | } |
| 1292 | |
| 1293 | /* |
| 1294 | * ACK/NACK received from NSS FW |
| 1295 | */ |
| 1296 | if (NSS_FAILURE == nss_n2h_mitigationcp[core_num].response) { |
| 1297 | goto failure; |
| 1298 | } |
| 1299 | |
| 1300 | up(&nss_n2h_mitigationcp[core_num].sem); |
| 1301 | return NSS_SUCCESS; |
| 1302 | |
| 1303 | failure: |
| 1304 | up(&nss_n2h_mitigationcp[core_num].sem); |
| 1305 | return NSS_FAILURE; |
| 1306 | } |
| 1307 | |
| 1308 | static inline void nss_n2h_buf_pool_free(struct nss_n2h_buf_pool *buf_pool) |
| 1309 | { |
| 1310 | int page_count; |
| 1311 | for (page_count = 0; page_count < buf_pool->nss_buf_num_pages; page_count++) { |
Stephen Wang | 7df6883 | 2017-08-10 16:54:35 -0700 | [diff] [blame] | 1312 | kfree((void *)buf_pool->nss_buf_pool_vaddr[page_count]); |
Kalyan Tallapragada | b50e890 | 2015-08-06 17:00:54 +0530 | [diff] [blame] | 1313 | } |
| 1314 | } |
| 1315 | |
| 1316 | /* |
| 1317 | * nss_n2h_buf_cfg() |
| 1318 | * Send Message to NSS to enable pbufs. |
| 1319 | */ |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 1320 | static nss_tx_status_t nss_n2h_buf_pool_cfg(struct nss_ctx_instance *nss_ctx, |
Tallapragada | 4b0161b | 2016-07-07 21:38:34 +0530 | [diff] [blame] | 1321 | int buf_pool_size, nss_core_id_t core_num) |
Kalyan Tallapragada | b50e890 | 2015-08-06 17:00:54 +0530 | [diff] [blame] | 1322 | { |
| 1323 | static struct nss_n2h_msg nnm; |
| 1324 | struct nss_n2h_buf_pool *buf_pool; |
| 1325 | nss_tx_status_t nss_tx_status; |
| 1326 | int ret; |
| 1327 | int page_count; |
| 1328 | int num_pages = ALIGN(buf_pool_size, PAGE_SIZE)/PAGE_SIZE; |
| 1329 | |
| 1330 | nss_assert(core_num < NSS_CORE_MAX); |
| 1331 | |
| 1332 | nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, NSS_METADATA_TYPE_N2H_ADD_BUF_POOL, |
| 1333 | sizeof(struct nss_n2h_buf_pool), |
| 1334 | nss_n2h_bufs_cfg_callback, |
| 1335 | (void *)core_num); |
| 1336 | |
| 1337 | do { |
| 1338 | |
| 1339 | down(&nss_n2h_bufcp[core_num].sem); |
| 1340 | |
| 1341 | buf_pool = &nnm.msg.buf_pool; |
| 1342 | buf_pool->nss_buf_page_size = PAGE_SIZE; |
| 1343 | |
| 1344 | for (page_count = 0; page_count < MAX_PAGES_PER_MSG && num_pages; page_count++, num_pages--) { |
Kalyan Tallapragada | b50e890 | 2015-08-06 17:00:54 +0530 | [diff] [blame] | 1345 | void *kern_addr = kzalloc(PAGE_SIZE, GFP_ATOMIC); |
| 1346 | if (!kern_addr) { |
| 1347 | BUG_ON(!page_count); |
| 1348 | break; |
| 1349 | } |
Kalyan Tallapragada | b50e890 | 2015-08-06 17:00:54 +0530 | [diff] [blame] | 1350 | |
Radha krishna Simha Jiguru | 60068fb | 2017-07-28 17:40:52 +0530 | [diff] [blame] | 1351 | kmemleak_not_leak(kern_addr); |
Stephen Wang | 7df6883 | 2017-08-10 16:54:35 -0700 | [diff] [blame] | 1352 | buf_pool->nss_buf_pool_vaddr[page_count] = (nss_ptr_t)kern_addr; |
Stephen Wang | efd3851 | 2017-01-24 14:01:02 -0800 | [diff] [blame] | 1353 | buf_pool->nss_buf_pool_addr[page_count] = dma_map_single(nss_ctx->dev, kern_addr, PAGE_SIZE, DMA_TO_DEVICE); |
Kalyan Tallapragada | b50e890 | 2015-08-06 17:00:54 +0530 | [diff] [blame] | 1354 | } |
| 1355 | |
| 1356 | buf_pool->nss_buf_num_pages = page_count; |
| 1357 | nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm); |
| 1358 | if (nss_tx_status != NSS_TX_SUCCESS) { |
| 1359 | |
| 1360 | nss_n2h_buf_pool_free(buf_pool); |
| 1361 | nss_warning("%p: nss_tx error setting pbuf\n", nss_ctx); |
| 1362 | goto failure; |
| 1363 | } |
| 1364 | |
| 1365 | /* |
| 1366 | * Blocking call, wait till we get ACK for this msg. |
| 1367 | */ |
| 1368 | ret = wait_for_completion_timeout(&nss_n2h_bufcp[core_num].complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT)); |
| 1369 | if (ret == 0) { |
| 1370 | nss_warning("%p: Waiting for ack timed out\n", nss_ctx); |
| 1371 | goto failure; |
| 1372 | } |
| 1373 | |
| 1374 | /* |
| 1375 | * ACK/NACK received from NSS FW |
| 1376 | */ |
| 1377 | if (NSS_FAILURE == nss_n2h_bufcp[core_num].response) { |
| 1378 | |
| 1379 | nss_n2h_buf_pool_free(buf_pool); |
| 1380 | goto failure; |
| 1381 | } |
| 1382 | |
| 1383 | up(&nss_n2h_bufcp[core_num].sem); |
| 1384 | } while(num_pages); |
| 1385 | |
| 1386 | return NSS_SUCCESS; |
| 1387 | failure: |
| 1388 | up(&nss_n2h_bufcp[core_num].sem); |
| 1389 | return NSS_FAILURE; |
| 1390 | } |
| 1391 | |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 1392 | /* |
| 1393 | * nss_rps_handler() |
| 1394 | * Enable NSS RPS |
| 1395 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 1396 | 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] | 1397 | { |
| 1398 | struct nss_top_instance *nss_top = &nss_top_main; |
| 1399 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[0]; |
| 1400 | int ret; |
Kalyan Tallapragada | b50e890 | 2015-08-06 17:00:54 +0530 | [diff] [blame] | 1401 | |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 1402 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 1403 | if (!ret) { |
| 1404 | if ((write) && (nss_n2h_rps_config == 1)) { |
| 1405 | printk(KERN_INFO "Enabling NSS RPS\n"); |
| 1406 | |
| 1407 | return nss_n2h_rps_cfg(nss_ctx, 1); |
| 1408 | } |
| 1409 | |
| 1410 | if ((write) && (nss_n2h_rps_config == 0)) { |
| 1411 | printk(KERN_INFO "Runtime disabling of NSS RPS not supported\n"); |
| 1412 | return ret; |
| 1413 | } |
| 1414 | |
| 1415 | if (write) { |
| 1416 | printk(KERN_INFO "Invalid input value.Valid values are 0 and 1\n"); |
| 1417 | } |
| 1418 | |
| 1419 | } |
| 1420 | |
| 1421 | return ret; |
| 1422 | } |
| 1423 | |
| 1424 | /* |
| 1425 | * nss_mitigation_handler() |
| 1426 | * Enable NSS MITIGATION |
| 1427 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 1428 | 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] | 1429 | { |
| 1430 | struct nss_top_instance *nss_top = &nss_top_main; |
| 1431 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[NSS_CORE_0]; |
| 1432 | int ret; |
| 1433 | |
| 1434 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 1435 | if (ret) { |
| 1436 | return ret; |
| 1437 | } |
| 1438 | |
| 1439 | /* |
| 1440 | * It's a read operation |
| 1441 | */ |
| 1442 | if (!write) { |
| 1443 | return ret; |
| 1444 | } |
| 1445 | |
| 1446 | if (!nss_n2h_core0_mitigation_cfg) { |
| 1447 | printk(KERN_INFO "Disabling NSS MITIGATION\n"); |
| 1448 | nss_n2h_mitigation_cfg(nss_ctx, 0, NSS_CORE_0); |
| 1449 | return 0; |
| 1450 | } |
| 1451 | printk(KERN_INFO "Invalid input value.Valid value is 0, Runtime re-enabling not supported\n"); |
| 1452 | return -EINVAL; |
| 1453 | } |
| 1454 | |
| 1455 | /* |
| 1456 | * nss_mitigation_handler() |
| 1457 | * Enable NSS MITIGATION |
| 1458 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 1459 | 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] | 1460 | { |
| 1461 | struct nss_top_instance *nss_top = &nss_top_main; |
| 1462 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[NSS_CORE_1]; |
| 1463 | int ret; |
| 1464 | |
| 1465 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 1466 | if (ret) { |
| 1467 | return ret; |
| 1468 | } |
| 1469 | |
| 1470 | /* |
| 1471 | * It's a read operation |
| 1472 | */ |
| 1473 | if (!write) { |
| 1474 | return ret; |
| 1475 | } |
| 1476 | |
| 1477 | if (!nss_n2h_core1_mitigation_cfg) { |
| 1478 | printk(KERN_INFO "Disabling NSS MITIGATION\n"); |
| 1479 | nss_n2h_mitigation_cfg(nss_ctx, 0, NSS_CORE_1); |
| 1480 | return 0; |
| 1481 | } |
| 1482 | printk(KERN_INFO "Invalid input value.Valid value is 0, Runtime re-enabling not supported\n"); |
| 1483 | return -EINVAL; |
| 1484 | } |
| 1485 | |
| 1486 | /* |
| 1487 | * nss_buf_handler() |
| 1488 | * Add extra NSS bufs from host memory |
| 1489 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 1490 | 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] | 1491 | { |
| 1492 | struct nss_top_instance *nss_top = &nss_top_main; |
| 1493 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[NSS_CORE_0]; |
| 1494 | int ret; |
| 1495 | |
| 1496 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 1497 | if (ret) { |
| 1498 | return ret; |
| 1499 | } |
| 1500 | |
| 1501 | /* |
| 1502 | * It's a read operation |
| 1503 | */ |
| 1504 | if (!write) { |
| 1505 | return ret; |
| 1506 | } |
| 1507 | |
| 1508 | if (nss_ctx->buf_sz_allocated) { |
| 1509 | nss_n2h_core0_add_buf_pool_size = nss_ctx->buf_sz_allocated; |
| 1510 | return -EPERM; |
| 1511 | } |
| 1512 | |
| 1513 | if ((nss_n2h_core0_add_buf_pool_size >= 1) && (nss_n2h_core0_add_buf_pool_size <= NSS_N2H_MAX_BUF_POOL_SIZE)) { |
| 1514 | printk(KERN_INFO "configuring additional NSS pbufs\n"); |
| 1515 | ret = nss_n2h_buf_pool_cfg(nss_ctx, nss_n2h_core0_add_buf_pool_size, NSS_CORE_0); |
| 1516 | nss_n2h_core0_add_buf_pool_size = nss_ctx->buf_sz_allocated; |
| 1517 | printk(KERN_INFO "additional pbufs of size %d got added to NSS\n", nss_ctx->buf_sz_allocated); |
| 1518 | return ret; |
| 1519 | } |
| 1520 | |
| 1521 | printk(KERN_INFO "Invalid input value. should be greater than 1 and less than %d\n", NSS_N2H_MAX_BUF_POOL_SIZE); |
| 1522 | return -EINVAL; |
| 1523 | } |
| 1524 | |
| 1525 | /* |
| 1526 | * nss_n2h_buf_handler() |
| 1527 | * Add extra NSS bufs from host memory |
| 1528 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 1529 | 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] | 1530 | { |
| 1531 | struct nss_top_instance *nss_top = &nss_top_main; |
| 1532 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[NSS_CORE_1]; |
| 1533 | int ret; |
| 1534 | |
| 1535 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 1536 | if (ret) { |
| 1537 | return ret; |
| 1538 | } |
| 1539 | |
| 1540 | /* |
| 1541 | * It's a read operation |
| 1542 | */ |
| 1543 | if (!write) { |
| 1544 | return ret; |
| 1545 | } |
| 1546 | |
| 1547 | if (nss_ctx->buf_sz_allocated) { |
| 1548 | nss_n2h_core1_add_buf_pool_size = nss_ctx->buf_sz_allocated; |
| 1549 | return -EPERM; |
| 1550 | } |
| 1551 | |
| 1552 | if ((nss_n2h_core1_add_buf_pool_size >= 1) && (nss_n2h_core1_add_buf_pool_size <= NSS_N2H_MAX_BUF_POOL_SIZE)) { |
| 1553 | printk(KERN_INFO "configuring additional NSS pbufs\n"); |
| 1554 | ret = nss_n2h_buf_pool_cfg(nss_ctx, nss_n2h_core1_add_buf_pool_size, NSS_CORE_1); |
| 1555 | nss_n2h_core1_add_buf_pool_size = nss_ctx->buf_sz_allocated; |
| 1556 | printk(KERN_INFO "additional pbufs of size %d got added to NSS\n", nss_ctx->buf_sz_allocated); |
| 1557 | return ret; |
| 1558 | } |
| 1559 | |
| 1560 | printk(KERN_INFO "Invalid input value. should be greater than 1 and less than %d\n", NSS_N2H_MAX_BUF_POOL_SIZE); |
| 1561 | return -EINVAL; |
| 1562 | } |
Kalyan Tallapragada | b50e890 | 2015-08-06 17:00:54 +0530 | [diff] [blame] | 1563 | |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 1564 | static struct ctl_table nss_n2h_table[] = { |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 1565 | { |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 1566 | .procname = "n2h_empty_pool_buf_core0", |
| 1567 | .data = &nss_n2h_empty_pool_buf_cfg[NSS_CORE_0], |
| 1568 | .maxlen = sizeof(int), |
| 1569 | .mode = 0644, |
| 1570 | .proc_handler = &nss_n2h_empty_pool_buf_cfg_core0_handler, |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 1571 | }, |
| 1572 | { |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 1573 | .procname = "n2h_empty_pool_buf_core1", |
| 1574 | .data = &nss_n2h_empty_pool_buf_cfg[NSS_CORE_1], |
| 1575 | .maxlen = sizeof(int), |
| 1576 | .mode = 0644, |
| 1577 | .proc_handler = &nss_n2h_empty_pool_buf_cfg_core1_handler, |
| 1578 | }, |
| 1579 | { |
Sachin Shashidhar | 475012b | 2017-03-13 16:56:07 -0700 | [diff] [blame] | 1580 | .procname = "n2h_empty_paged_pool_buf_core0", |
| 1581 | .data = &nss_n2h_empty_paged_pool_buf_cfg[NSS_CORE_0], |
| 1582 | .maxlen = sizeof(int), |
| 1583 | .mode = 0644, |
| 1584 | .proc_handler = &nss_n2h_empty_paged_pool_buf_cfg_core0_handler, |
| 1585 | }, |
| 1586 | { |
| 1587 | .procname = "n2h_empty_paged_pool_buf_core1", |
| 1588 | .data = &nss_n2h_empty_paged_pool_buf_cfg[NSS_CORE_1], |
| 1589 | .maxlen = sizeof(int), |
| 1590 | .mode = 0644, |
| 1591 | .proc_handler = &nss_n2h_empty_paged_pool_buf_cfg_core1_handler, |
| 1592 | }, |
| 1593 | |
| 1594 | { |
Saurabh Misra | 71034db | 2015-06-04 16:18:38 -0700 | [diff] [blame] | 1595 | .procname = "n2h_low_water_core0", |
| 1596 | .data = &nss_n2h_water_mark[NSS_CORE_0][0], |
| 1597 | .maxlen = sizeof(int), |
| 1598 | .mode = 0644, |
| 1599 | .proc_handler = &nss_n2h_water_mark_core0_handler, |
| 1600 | }, |
| 1601 | { |
| 1602 | .procname = "n2h_low_water_core1", |
| 1603 | .data = &nss_n2h_water_mark[NSS_CORE_1][0], |
| 1604 | .maxlen = sizeof(int), |
| 1605 | .mode = 0644, |
| 1606 | .proc_handler = &nss_n2h_water_mark_core1_handler, |
| 1607 | }, |
| 1608 | { |
| 1609 | .procname = "n2h_high_water_core0", |
| 1610 | .data = &nss_n2h_water_mark[NSS_CORE_0][1], |
| 1611 | .maxlen = sizeof(int), |
| 1612 | .mode = 0644, |
| 1613 | .proc_handler = &nss_n2h_water_mark_core0_handler, |
| 1614 | }, |
| 1615 | { |
| 1616 | .procname = "n2h_high_water_core1", |
| 1617 | .data = &nss_n2h_water_mark[NSS_CORE_1][1], |
| 1618 | .maxlen = sizeof(int), |
| 1619 | .mode = 0644, |
| 1620 | .proc_handler = &nss_n2h_water_mark_core1_handler, |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 1621 | }, |
Pamidipati, Vijay | ee9c297 | 2016-01-10 08:13:19 +0530 | [diff] [blame] | 1622 | { |
Sachin Shashidhar | 475012b | 2017-03-13 16:56:07 -0700 | [diff] [blame] | 1623 | .procname = "n2h_paged_low_water_core0", |
| 1624 | .data = &nss_n2h_paged_water_mark[NSS_CORE_0][0], |
| 1625 | .maxlen = sizeof(int), |
| 1626 | .mode = 0644, |
| 1627 | .proc_handler = &nss_n2h_paged_water_mark_core0_handler, |
| 1628 | }, |
| 1629 | { |
| 1630 | .procname = "n2h_paged_low_water_core1", |
| 1631 | .data = &nss_n2h_paged_water_mark[NSS_CORE_1][0], |
| 1632 | .maxlen = sizeof(int), |
| 1633 | .mode = 0644, |
| 1634 | .proc_handler = &nss_n2h_paged_water_mark_core1_handler, |
| 1635 | }, |
| 1636 | { |
| 1637 | .procname = "n2h_paged_high_water_core0", |
| 1638 | .data = &nss_n2h_paged_water_mark[NSS_CORE_0][1], |
| 1639 | .maxlen = sizeof(int), |
| 1640 | .mode = 0644, |
| 1641 | .proc_handler = &nss_n2h_paged_water_mark_core0_handler, |
| 1642 | }, |
| 1643 | { |
| 1644 | .procname = "n2h_paged_high_water_core1", |
| 1645 | .data = &nss_n2h_paged_water_mark[NSS_CORE_1][1], |
| 1646 | .maxlen = sizeof(int), |
| 1647 | .mode = 0644, |
| 1648 | .proc_handler = &nss_n2h_paged_water_mark_core1_handler, |
| 1649 | }, |
| 1650 | { |
Pamidipati, Vijay | ee9c297 | 2016-01-10 08:13:19 +0530 | [diff] [blame] | 1651 | .procname = "n2h_wifi_pool_buf", |
| 1652 | .data = &nss_n2h_wifi_pool_buf_cfg, |
| 1653 | .maxlen = sizeof(int), |
| 1654 | .mode = 0644, |
| 1655 | .proc_handler = &nss_n2h_wifi_payloads_handler, |
| 1656 | }, |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 1657 | { |
| 1658 | .procname = "rps", |
| 1659 | .data = &nss_n2h_rps_config, |
| 1660 | .maxlen = sizeof(int), |
| 1661 | .mode = 0644, |
| 1662 | .proc_handler = &nss_n2h_rpscfg_handler, |
| 1663 | }, |
| 1664 | { |
| 1665 | .procname = "mitigation_core0", |
| 1666 | .data = &nss_n2h_core0_mitigation_cfg, |
| 1667 | .maxlen = sizeof(int), |
| 1668 | .mode = 0644, |
| 1669 | .proc_handler = &nss_n2h_mitigationcfg_core0_handler, |
| 1670 | }, |
| 1671 | { |
| 1672 | .procname = "mitigation_core1", |
| 1673 | .data = &nss_n2h_core1_mitigation_cfg, |
| 1674 | .maxlen = sizeof(int), |
| 1675 | .mode = 0644, |
| 1676 | .proc_handler = &nss_n2h_mitigationcfg_core1_handler, |
| 1677 | }, |
| 1678 | { |
| 1679 | .procname = "extra_pbuf_core0", |
| 1680 | .data = &nss_n2h_core0_add_buf_pool_size, |
| 1681 | .maxlen = sizeof(int), |
| 1682 | .mode = 0644, |
| 1683 | .proc_handler = &nss_n2h_buf_cfg_core0_handler, |
| 1684 | }, |
| 1685 | { |
| 1686 | .procname = "extra_pbuf_core1", |
| 1687 | .data = &nss_n2h_core1_add_buf_pool_size, |
| 1688 | .maxlen = sizeof(int), |
| 1689 | .mode = 0644, |
| 1690 | .proc_handler = &nss_n2h_buf_cfg_core1_handler, |
| 1691 | }, |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 1692 | |
| 1693 | { } |
| 1694 | }; |
| 1695 | |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 1696 | static struct ctl_table nss_n2h_dir[] = { |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 1697 | { |
| 1698 | .procname = "n2hcfg", |
| 1699 | .mode = 0555, |
| 1700 | .child = nss_n2h_table, |
| 1701 | }, |
| 1702 | { } |
| 1703 | }; |
| 1704 | |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 1705 | static struct ctl_table nss_n2h_root_dir[] = { |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 1706 | { |
| 1707 | .procname = "nss", |
| 1708 | .mode = 0555, |
| 1709 | .child = nss_n2h_dir, |
| 1710 | }, |
| 1711 | { } |
| 1712 | }; |
| 1713 | |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 1714 | static struct ctl_table nss_n2h_root[] = { |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 1715 | { |
| 1716 | .procname = "dev", |
| 1717 | .mode = 0555, |
| 1718 | .child = nss_n2h_root_dir, |
| 1719 | }, |
| 1720 | { } |
| 1721 | }; |
| 1722 | |
| 1723 | static struct ctl_table_header *nss_n2h_header; |
| 1724 | |
| 1725 | /* |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 1726 | * nss_n2h_flush_payloads() |
| 1727 | * Sends a command down to NSS for flushing all payloads |
| 1728 | */ |
| 1729 | nss_tx_status_t nss_n2h_flush_payloads(struct nss_ctx_instance *nss_ctx) |
| 1730 | { |
| 1731 | struct nss_n2h_msg nnm; |
| 1732 | struct nss_n2h_flush_payloads *nnflshpl; |
| 1733 | nss_tx_status_t nss_tx_status; |
| 1734 | |
| 1735 | nnflshpl = &nnm.msg.flush_payloads; |
| 1736 | |
| 1737 | /* |
| 1738 | * TODO: No additional information sent in message |
| 1739 | * as of now. Need to initialize message content accordingly |
| 1740 | * if needed. |
| 1741 | */ |
| 1742 | nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, |
| 1743 | NSS_TX_METADATA_TYPE_N2H_FLUSH_PAYLOADS, |
| 1744 | sizeof(struct nss_n2h_flush_payloads), |
| 1745 | NULL, |
| 1746 | NULL); |
| 1747 | |
| 1748 | nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm); |
| 1749 | if (nss_tx_status != NSS_TX_SUCCESS) { |
| 1750 | nss_warning("%p: failed to send flush payloads command to NSS\n", |
| 1751 | nss_ctx); |
| 1752 | |
| 1753 | return NSS_TX_FAILURE; |
| 1754 | } |
| 1755 | |
| 1756 | return NSS_TX_SUCCESS; |
| 1757 | } |
| 1758 | |
| 1759 | /* |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 1760 | * nss_n2h_msg_init() |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 1761 | * Initialize n2h message. |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 1762 | */ |
| 1763 | 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] | 1764 | uint32_t len, nss_n2h_msg_callback_t cb, void *app_data) |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 1765 | { |
| 1766 | nss_cmn_msg_init(&nim->cm, if_num, type, len, (void *)cb, app_data); |
| 1767 | } |
| 1768 | |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 1769 | /* |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 1770 | * nss_n2h_tx_msg() |
| 1771 | * Send messages to NSS n2h pacakge |
| 1772 | */ |
| 1773 | nss_tx_status_t nss_n2h_tx_msg(struct nss_ctx_instance *nss_ctx, struct nss_n2h_msg *nnm) |
| 1774 | { |
| 1775 | struct nss_n2h_msg *nnm2; |
| 1776 | struct nss_cmn_msg *ncm = &nnm->cm; |
| 1777 | struct sk_buff *nbuf; |
| 1778 | nss_tx_status_t status; |
| 1779 | |
| 1780 | NSS_VERIFY_CTX_MAGIC(nss_ctx); |
| 1781 | if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) { |
| 1782 | return NSS_TX_FAILURE_NOT_READY; |
| 1783 | } |
| 1784 | |
| 1785 | /* |
| 1786 | * Sanity check the message |
| 1787 | */ |
| 1788 | if (ncm->interface != NSS_N2H_INTERFACE) { |
| 1789 | nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface); |
| 1790 | return NSS_TX_FAILURE; |
| 1791 | } |
| 1792 | |
| 1793 | if (ncm->type >= NSS_METADATA_TYPE_N2H_MAX) { |
| 1794 | nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type); |
| 1795 | return NSS_TX_FAILURE; |
| 1796 | } |
| 1797 | |
Suruchi Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 1798 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_n2h_msg)) { |
| 1799 | 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] | 1800 | return NSS_TX_FAILURE; |
| 1801 | } |
| 1802 | |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 1803 | nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE); |
| 1804 | if (unlikely(!nbuf)) { |
Sundarajan Srinivasan | 62fee7e | 2015-01-22 11:13:10 -0800 | [diff] [blame] | 1805 | 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] | 1806 | return NSS_TX_FAILURE; |
| 1807 | } |
| 1808 | |
| 1809 | /* |
| 1810 | * Copy the message to our skb. |
| 1811 | */ |
| 1812 | nnm2 = (struct nss_n2h_msg *)skb_put(nbuf, sizeof(struct nss_n2h_msg)); |
| 1813 | memcpy(nnm2, nnm, sizeof(struct nss_n2h_msg)); |
| 1814 | status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0); |
| 1815 | if (status != NSS_CORE_STATUS_SUCCESS) { |
| 1816 | dev_kfree_skb_any(nbuf); |
| 1817 | nss_info("%p: unable to enqueue 'nss frequency change' - marked as stopped\n", nss_ctx); |
| 1818 | return NSS_TX_FAILURE; |
| 1819 | } |
| 1820 | |
Stephen Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 1821 | nss_hal_send_interrupt(nss_ctx, NSS_H2N_INTR_DATA_COMMAND_QUEUE); |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 1822 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]); |
| 1823 | return NSS_TX_SUCCESS; |
| 1824 | } |
| 1825 | |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 1826 | /* |
| 1827 | * nss_n2h_notify_register() |
| 1828 | * Register to received N2H events. |
| 1829 | * |
| 1830 | * NOTE: Do we want to pass an nss_ctx here so that we can register for n2h on any core? |
| 1831 | */ |
| 1832 | struct nss_ctx_instance *nss_n2h_notify_register(int core, nss_n2h_msg_callback_t cb, void *app_data) |
| 1833 | { |
| 1834 | if (core >= NSS_MAX_CORES) { |
| 1835 | nss_warning("Input core number %d is wrong \n", core); |
| 1836 | return NULL; |
| 1837 | } |
| 1838 | /* |
| 1839 | * TODO: We need to have a new array in support of the new API |
| 1840 | * TODO: If we use a per-context array, we would move the array into nss_ctx based. |
| 1841 | */ |
| 1842 | nss_n2h_rd[core].n2h_callback = cb; |
| 1843 | nss_n2h_rd[core].app_data = app_data; |
| 1844 | return &nss_top_main.nss[core]; |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 1845 | } |
| 1846 | |
| 1847 | /* |
| 1848 | * nss_n2h_register_handler() |
| 1849 | */ |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 1850 | void nss_n2h_register_handler(struct nss_ctx_instance *nss_ctx) |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 1851 | { |
ratheesh kannoth | ab436af | 2017-07-20 08:51:07 +0530 | [diff] [blame] | 1852 | sema_init(&nss_n2h_q_cfg_pvt.sem, 1); |
| 1853 | init_completion(&nss_n2h_q_cfg_pvt.complete); |
| 1854 | |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 1855 | nss_core_register_handler(nss_ctx, NSS_N2H_INTERFACE, nss_n2h_interface_handler, NULL); |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 1856 | } |
Sundarajan Srinivasan | f1e5746 | 2014-09-17 15:24:01 -0700 | [diff] [blame] | 1857 | |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 1858 | /* |
| 1859 | * nss_n2h_register_sysctl() |
| 1860 | */ |
| 1861 | void nss_n2h_register_sysctl(void) |
| 1862 | { |
Vijay Dewangan | 634ce59 | 2015-01-07 17:21:09 -0800 | [diff] [blame] | 1863 | /* |
| 1864 | * RPS sema init |
| 1865 | */ |
| 1866 | sema_init(&nss_n2h_rcp.sem, 1); |
| 1867 | init_completion(&nss_n2h_rcp.complete); |
| 1868 | |
Kalyan Tallapragada | b50e890 | 2015-08-06 17:00:54 +0530 | [diff] [blame] | 1869 | /* |
| 1870 | * MITIGATION sema init for core0 |
| 1871 | */ |
| 1872 | sema_init(&nss_n2h_mitigationcp[NSS_CORE_0].sem, 1); |
| 1873 | init_completion(&nss_n2h_mitigationcp[NSS_CORE_0].complete); |
| 1874 | |
| 1875 | /* |
| 1876 | * MITIGATION sema init for core1 |
| 1877 | */ |
| 1878 | sema_init(&nss_n2h_mitigationcp[NSS_CORE_1].sem, 1); |
| 1879 | init_completion(&nss_n2h_mitigationcp[NSS_CORE_1].complete); |
| 1880 | |
| 1881 | /* |
| 1882 | * PBUF addition sema init for core0 |
| 1883 | */ |
| 1884 | sema_init(&nss_n2h_bufcp[NSS_CORE_0].sem, 1); |
| 1885 | init_completion(&nss_n2h_bufcp[NSS_CORE_0].complete); |
| 1886 | |
| 1887 | /* |
| 1888 | * PBUF addition sema init for core1 |
| 1889 | */ |
| 1890 | sema_init(&nss_n2h_bufcp[NSS_CORE_1].sem, 1); |
| 1891 | init_completion(&nss_n2h_bufcp[NSS_CORE_1].complete); |
Vijay Dewangan | 634ce59 | 2015-01-07 17:21:09 -0800 | [diff] [blame] | 1892 | |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 1893 | /* |
| 1894 | * Core0 |
| 1895 | */ |
| 1896 | sema_init(&nss_n2h_nepbcfgp[NSS_CORE_0].sem, 1); |
| 1897 | init_completion(&nss_n2h_nepbcfgp[NSS_CORE_0].complete); |
Sachin Shashidhar | 475012b | 2017-03-13 16:56:07 -0700 | [diff] [blame] | 1898 | nss_n2h_nepbcfgp[NSS_CORE_0].empty_buf_pool_info.pool_size = |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 1899 | nss_n2h_empty_pool_buf_cfg[NSS_CORE_0]; |
Sachin Shashidhar | 475012b | 2017-03-13 16:56:07 -0700 | [diff] [blame] | 1900 | nss_n2h_nepbcfgp[NSS_CORE_0].empty_buf_pool_info.low_water = |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 1901 | nss_n2h_water_mark[NSS_CORE_0][0]; |
Sachin Shashidhar | 475012b | 2017-03-13 16:56:07 -0700 | [diff] [blame] | 1902 | nss_n2h_nepbcfgp[NSS_CORE_0].empty_buf_pool_info.high_water = |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 1903 | nss_n2h_water_mark[NSS_CORE_0][1]; |
Sachin Shashidhar | 475012b | 2017-03-13 16:56:07 -0700 | [diff] [blame] | 1904 | nss_n2h_nepbcfgp[NSS_CORE_0].empty_paged_buf_pool_info.pool_size = |
| 1905 | nss_n2h_empty_paged_pool_buf_cfg[NSS_CORE_0]; |
| 1906 | nss_n2h_nepbcfgp[NSS_CORE_0].empty_paged_buf_pool_info.low_water = |
| 1907 | nss_n2h_paged_water_mark[NSS_CORE_0][0]; |
| 1908 | nss_n2h_nepbcfgp[NSS_CORE_0].empty_paged_buf_pool_info.high_water = |
| 1909 | nss_n2h_paged_water_mark[NSS_CORE_0][1]; |
| 1910 | |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 1911 | /* |
| 1912 | * Core1 |
| 1913 | */ |
| 1914 | sema_init(&nss_n2h_nepbcfgp[NSS_CORE_1].sem, 1); |
| 1915 | init_completion(&nss_n2h_nepbcfgp[NSS_CORE_1].complete); |
Sachin Shashidhar | 475012b | 2017-03-13 16:56:07 -0700 | [diff] [blame] | 1916 | nss_n2h_nepbcfgp[NSS_CORE_1].empty_buf_pool_info.pool_size = |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 1917 | nss_n2h_empty_pool_buf_cfg[NSS_CORE_1]; |
Sachin Shashidhar | 475012b | 2017-03-13 16:56:07 -0700 | [diff] [blame] | 1918 | nss_n2h_nepbcfgp[NSS_CORE_1].empty_buf_pool_info.low_water = |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 1919 | nss_n2h_water_mark[NSS_CORE_1][0]; |
Sachin Shashidhar | 475012b | 2017-03-13 16:56:07 -0700 | [diff] [blame] | 1920 | nss_n2h_nepbcfgp[NSS_CORE_1].empty_buf_pool_info.high_water = |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 1921 | nss_n2h_water_mark[NSS_CORE_1][1]; |
Sachin Shashidhar | 475012b | 2017-03-13 16:56:07 -0700 | [diff] [blame] | 1922 | nss_n2h_nepbcfgp[NSS_CORE_1].empty_paged_buf_pool_info.pool_size = |
| 1923 | nss_n2h_empty_paged_pool_buf_cfg[NSS_CORE_1]; |
| 1924 | nss_n2h_nepbcfgp[NSS_CORE_1].empty_paged_buf_pool_info.low_water = |
| 1925 | nss_n2h_paged_water_mark[NSS_CORE_1][0]; |
| 1926 | nss_n2h_nepbcfgp[NSS_CORE_1].empty_paged_buf_pool_info.high_water = |
| 1927 | nss_n2h_paged_water_mark[NSS_CORE_1][1]; |
| 1928 | |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 1929 | /* |
| 1930 | * WiFi pool buf cfg sema init |
| 1931 | */ |
| 1932 | sema_init(&nss_n2h_wp.sem, 1); |
| 1933 | init_completion(&nss_n2h_wp.complete); |
| 1934 | |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 1935 | nss_n2h_notify_register(NSS_CORE_0, NULL, NULL); |
| 1936 | nss_n2h_notify_register(NSS_CORE_1, NULL, NULL); |
| 1937 | |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 1938 | /* |
| 1939 | * Register sysctl table. |
| 1940 | */ |
| 1941 | nss_n2h_header = register_sysctl_table(nss_n2h_root); |
| 1942 | } |
| 1943 | |
| 1944 | /* |
| 1945 | * nss_n2h_unregister_sysctl() |
| 1946 | * Unregister sysctl specific to n2h |
| 1947 | */ |
| 1948 | void nss_n2h_unregister_sysctl(void) |
| 1949 | { |
| 1950 | /* |
| 1951 | * Unregister sysctl table. |
| 1952 | */ |
| 1953 | if (nss_n2h_header) { |
| 1954 | unregister_sysctl_table(nss_n2h_header); |
| 1955 | } |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 1956 | } |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 1957 | |
| 1958 | EXPORT_SYMBOL(nss_n2h_notify_register); |