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