Bharath M Kumar | cc666e9 | 2014-12-24 19:17:28 +0530 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 3 | * Copyright (c) 2015-2017, The Linux Foundation. All rights reserved. |
Bharath M Kumar | cc666e9 | 2014-12-24 19:17:28 +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 | #include "nss_tx_rx_common.h" |
| 18 | |
| 19 | /* |
| 20 | * nss_wifi_stats_sync() |
| 21 | * Handle the syncing of WIFI stats. |
| 22 | */ |
| 23 | void nss_wifi_stats_sync(struct nss_ctx_instance *nss_ctx, |
| 24 | struct nss_wifi_stats_sync_msg *stats, uint16_t interface) |
| 25 | { |
| 26 | struct nss_top_instance *nss_top = nss_ctx->nss_top; |
Radha krishna Simha Jiguru | 3a7439f | 2015-09-11 13:29:12 +0530 | [diff] [blame] | 27 | uint32_t radio_id = interface - NSS_WIFI_INTERFACE0; |
Pamidipati, Vijay | 670ce7e | 2016-03-15 16:46:59 +0530 | [diff] [blame] | 28 | uint8_t i = 0; |
Radha krishna Simha Jiguru | 3a7439f | 2015-09-11 13:29:12 +0530 | [diff] [blame] | 29 | |
| 30 | if (radio_id >= NSS_MAX_WIFI_RADIO_INTERFACES) { |
| 31 | nss_warning("%p: invalid interface: %d", nss_ctx, interface); |
| 32 | return; |
| 33 | } |
Bharath M Kumar | cc666e9 | 2014-12-24 19:17:28 +0530 | [diff] [blame] | 34 | |
| 35 | spin_lock_bh(&nss_top->stats_lock); |
| 36 | |
| 37 | /* |
| 38 | * Tx/Rx stats |
| 39 | */ |
Radha krishna Simha Jiguru | 3a7439f | 2015-09-11 13:29:12 +0530 | [diff] [blame] | 40 | nss_top->stats_wifi[radio_id][NSS_STATS_WIFI_RX_PKTS] += stats->node_stats.rx_packets; |
| 41 | nss_top->stats_wifi[radio_id][NSS_STATS_WIFI_RX_DROPPED] += stats->node_stats.rx_dropped; |
| 42 | nss_top->stats_wifi[radio_id][NSS_STATS_WIFI_TX_PKTS] += stats->node_stats.tx_packets; |
| 43 | nss_top->stats_wifi[radio_id][NSS_STATS_WIFI_TX_DROPPED] += stats->tx_transmit_dropped; |
| 44 | nss_top->stats_wifi[radio_id][NSS_STATS_WIFI_TX_COMPLETED] += stats->tx_transmit_completions; |
| 45 | nss_top->stats_wifi[radio_id][NSS_STATS_WIFI_MGMT_RCV_CNT] += stats->tx_mgmt_rcv_cnt; |
| 46 | nss_top->stats_wifi[radio_id][NSS_STATS_WIFI_MGMT_TX_PKTS] += stats->tx_mgmt_pkts; |
| 47 | nss_top->stats_wifi[radio_id][NSS_STATS_WIFI_MGMT_TX_DROPPED] += stats->tx_mgmt_dropped; |
| 48 | nss_top->stats_wifi[radio_id][NSS_STATS_WIFI_MGMT_TX_COMPLETIONS] += stats->tx_mgmt_completions; |
Radha krishna Simha Jiguru | 36304d1 | 2015-12-03 20:21:02 +0530 | [diff] [blame] | 49 | nss_top->stats_wifi[radio_id][NSS_STATS_WIFI_TX_INV_PEER_ENQUEUE_CNT] += stats->tx_inv_peer_enq_cnt; |
Radha krishna Simha Jiguru | 3a7439f | 2015-09-11 13:29:12 +0530 | [diff] [blame] | 50 | nss_top->stats_wifi[radio_id][NSS_STATS_WIFI_RX_INV_PEER_RCV_CNT] += stats->rx_inv_peer_rcv_cnt; |
| 51 | nss_top->stats_wifi[radio_id][NSS_STATS_WIFI_RX_PN_CHECK_FAILED] += stats->rx_pn_check_failed; |
| 52 | nss_top->stats_wifi[radio_id][NSS_STATS_WIFI_RX_DELIVERED] += stats->rx_pkts_deliverd; |
Ankit Dhanuka | 5a17819 | 2015-09-22 16:40:12 +0530 | [diff] [blame] | 53 | nss_top->stats_wifi[radio_id][NSS_STATS_WIFI_RX_BYTES_DELIVERED] += stats->rx_bytes_deliverd; |
| 54 | nss_top->stats_wifi[radio_id][NSS_STATS_WIFI_TX_BYTES_COMPLETED] += stats->tx_bytes_transmit_completions; |
Radha krishna Simha Jiguru | 36304d1 | 2015-12-03 20:21:02 +0530 | [diff] [blame] | 55 | nss_top->stats_wifi[radio_id][NSS_STATS_WIFI_RX_DELIVER_UNALIGNED_DROP_CNT] += stats->rx_deliver_unaligned_drop_cnt; |
Bharath M Kumar | cc666e9 | 2014-12-24 19:17:28 +0530 | [diff] [blame] | 56 | |
Pamidipati, Vijay | 670ce7e | 2016-03-15 16:46:59 +0530 | [diff] [blame] | 57 | for (i = 0; i < NSS_WIFI_TX_NUM_TOS_TIDS; i++) { |
| 58 | nss_top->stats_wifi[radio_id][NSS_STATS_WIFI_TIDQ_ENQUEUE_CNT + i] += stats->tidq_enqueue_cnt[i]; |
| 59 | nss_top->stats_wifi[radio_id][NSS_STATS_WIFI_TIDQ_DEQUEUE_CNT + i] += stats->tidq_dequeue_cnt[i]; |
| 60 | nss_top->stats_wifi[radio_id][NSS_STATS_WIFI_TIDQ_ENQUEUE_FAIL_CNT + i] += stats->tidq_enqueue_fail_cnt[i]; |
| 61 | nss_top->stats_wifi[radio_id][NSS_STATS_WIFI_TIDQ_TTL_EXPIRE_CNT + i] += stats->tidq_ttl_expire_cnt[i]; |
| 62 | nss_top->stats_wifi[radio_id][NSS_STATS_WIFI_TIDQ_DEQUEUE_REQ_CNT + i] += stats->tidq_dequeue_req_cnt[i]; |
| 63 | } |
| 64 | |
| 65 | nss_top->stats_wifi[radio_id][NSS_STATS_WIFI_RX_HTT_FETCH_CNT] += stats->rx_htt_fetch_cnt; |
| 66 | nss_top->stats_wifi[radio_id][NSS_STATS_WIFI_TOTAL_TIDQ_DEPTH] = stats->total_tidq_depth; |
| 67 | nss_top->stats_wifi[radio_id][NSS_STATS_WIFI_TOTAL_TIDQ_BYPASS_CNT] += stats->total_tidq_bypass_cnt; |
| 68 | nss_top->stats_wifi[radio_id][NSS_STATS_WIFI_GLOBAL_Q_FULL_CNT] += stats->global_q_full_cnt; |
| 69 | nss_top->stats_wifi[radio_id][NSS_STATS_WIFI_TIDQ_FULL_CNT] += stats->tidq_full_cnt; |
| 70 | |
Bharath M Kumar | cc666e9 | 2014-12-24 19:17:28 +0530 | [diff] [blame] | 71 | spin_unlock_bh(&nss_top->stats_lock); |
| 72 | } |
| 73 | |
ratheesh kannoth | eb2a0a8 | 2017-05-04 09:20:17 +0530 | [diff] [blame] | 74 | /* |
| 75 | * nss_wifi_get_context() |
| 76 | * Get NSS context of Wifi. |
| 77 | */ |
| 78 | struct nss_ctx_instance *nss_wifi_get_context() |
| 79 | { |
| 80 | return (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.wifi_handler_id]; |
| 81 | } |
Bharath M Kumar | cc666e9 | 2014-12-24 19:17:28 +0530 | [diff] [blame] | 82 | |
| 83 | /* |
| 84 | * nss_wifi_handler() |
| 85 | * Handle NSS -> HLOS messages for wifi |
| 86 | */ |
| 87 | static void nss_wifi_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data) |
| 88 | { |
| 89 | struct nss_wifi_msg *ntm = (struct nss_wifi_msg *)ncm; |
| 90 | void *ctx; |
| 91 | nss_wifi_msg_callback_t cb; |
| 92 | |
| 93 | nss_info("%p: NSS ->HLOS message for wifi\n", nss_ctx); |
| 94 | |
| 95 | BUG_ON(((ncm->interface < NSS_WIFI_INTERFACE0) || (ncm->interface > NSS_WIFI_INTERFACE2))); |
| 96 | |
| 97 | /* |
| 98 | * Is this a valid request/response packet? |
| 99 | */ |
| 100 | if (ncm->type >= NSS_WIFI_MAX_MSG) { |
| 101 | nss_warning("%p: received invalid message %d for wifi interface", nss_ctx, ncm->type); |
| 102 | return; |
| 103 | } |
| 104 | |
Suruchi Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 105 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_wifi_msg)) { |
| 106 | nss_warning("%p: Length of message is greater than required: %d", nss_ctx, nss_cmn_get_msg_len(ncm)); |
Bharath M Kumar | cc666e9 | 2014-12-24 19:17:28 +0530 | [diff] [blame] | 107 | return; |
| 108 | } |
| 109 | |
| 110 | /* |
| 111 | * Snoop messages for local driver and handle |
| 112 | */ |
| 113 | switch (ntm->cm.type) { |
| 114 | case NSS_WIFI_STATS_MSG: |
| 115 | /* |
| 116 | * To create the old API gmac statistics, we use the new extended GMAC stats. |
| 117 | */ |
| 118 | nss_wifi_stats_sync(nss_ctx, &ntm->msg.statsmsg, ncm->interface); |
| 119 | break; |
| 120 | } |
| 121 | |
| 122 | /* |
| 123 | * Update the callback and app_data for NOTIFY messages, wifi sends all notify messages |
| 124 | * to the same callback/app_data. |
| 125 | */ |
| 126 | if (ncm->response == NSS_CMM_RESPONSE_NOTIFY) { |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 127 | ncm->cb = (nss_ptr_t)nss_ctx->nss_top->wifi_msg_callback; |
Bharath M Kumar | cc666e9 | 2014-12-24 19:17:28 +0530 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | /* |
| 131 | * Log failures |
| 132 | */ |
| 133 | nss_core_log_msg_failures(nss_ctx, ncm); |
| 134 | |
| 135 | /* |
| 136 | * Do we have a call back |
| 137 | */ |
| 138 | if (!ncm->cb) { |
| 139 | nss_info("%p: cb null for wifi interface %d", nss_ctx, ncm->interface); |
| 140 | return; |
| 141 | } |
| 142 | |
| 143 | /* |
| 144 | * Get callback & context |
| 145 | */ |
| 146 | cb = (nss_wifi_msg_callback_t)ncm->cb; |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 147 | ctx = nss_ctx->subsys_dp_register[ncm->interface].ndev; |
Bharath M Kumar | cc666e9 | 2014-12-24 19:17:28 +0530 | [diff] [blame] | 148 | |
| 149 | /* |
| 150 | * call wifi msg callback |
| 151 | */ |
| 152 | if (!ctx) { |
| 153 | nss_warning("%p: Event received for wifi interface %d before registration", nss_ctx, ncm->interface); |
| 154 | return; |
| 155 | } |
| 156 | |
| 157 | cb(ctx, ntm); |
| 158 | } |
| 159 | |
| 160 | /* |
| 161 | * nss_wifi_tx_msg |
| 162 | * Transmit a wifi message to NSS FW |
| 163 | */ |
| 164 | nss_tx_status_t nss_wifi_tx_msg(struct nss_ctx_instance *nss_ctx, struct nss_wifi_msg *msg) |
| 165 | { |
| 166 | struct nss_wifi_msg *nm; |
| 167 | struct nss_cmn_msg *ncm = &msg->cm; |
| 168 | struct sk_buff *nbuf; |
| 169 | int32_t status; |
| 170 | |
| 171 | NSS_VERIFY_CTX_MAGIC(nss_ctx); |
| 172 | |
| 173 | if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) { |
| 174 | nss_warning("%p: wifi message dropped as core not ready", nss_ctx); |
| 175 | return NSS_TX_FAILURE_NOT_READY; |
| 176 | } |
| 177 | |
| 178 | if (ncm->type > NSS_WIFI_MAX_MSG) { |
| 179 | nss_warning("%p: wifi message type out of range: %d", nss_ctx, ncm->type); |
| 180 | return NSS_TX_FAILURE; |
| 181 | } |
| 182 | |
Suruchi Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 183 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_wifi_msg)) { |
| 184 | nss_warning("%p: wifi message length is invalid: %d", nss_ctx, nss_cmn_get_msg_len(ncm)); |
Bharath M Kumar | cc666e9 | 2014-12-24 19:17:28 +0530 | [diff] [blame] | 185 | return NSS_TX_FAILURE; |
| 186 | } |
| 187 | |
| 188 | nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE); |
| 189 | if (unlikely(!nbuf)) { |
| 190 | spin_lock_bh(&nss_ctx->nss_top->stats_lock); |
| 191 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]); |
| 192 | spin_unlock_bh(&nss_ctx->nss_top->stats_lock); |
| 193 | nss_warning("%p: wifi message dropped as command allocation failed", nss_ctx); |
| 194 | return NSS_TX_FAILURE; |
| 195 | } |
| 196 | |
| 197 | /* |
| 198 | * Copy the message to our skb |
| 199 | */ |
| 200 | nm = (struct nss_wifi_msg *)skb_put(nbuf, sizeof(struct nss_wifi_msg)); |
| 201 | memcpy(nm, msg, sizeof(struct nss_wifi_msg)); |
| 202 | |
| 203 | status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0); |
| 204 | if (status != NSS_CORE_STATUS_SUCCESS) { |
| 205 | dev_kfree_skb_any(nbuf); |
| 206 | nss_warning("%p: Unable to enqueue 'wifi message'", nss_ctx); |
| 207 | return NSS_TX_FAILURE; |
| 208 | } |
| 209 | |
Stephen Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 210 | nss_hal_send_interrupt(nss_ctx, NSS_H2N_INTR_DATA_COMMAND_QUEUE); |
Bharath M Kumar | cc666e9 | 2014-12-24 19:17:28 +0530 | [diff] [blame] | 211 | |
| 212 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]); |
| 213 | |
| 214 | return NSS_TX_SUCCESS; |
| 215 | } |
| 216 | |
| 217 | /* |
| 218 | **************************************** |
| 219 | * Register/Unregister/Miscellaneous APIs |
| 220 | **************************************** |
| 221 | */ |
| 222 | |
| 223 | /* |
| 224 | * nss_register_wifi_if() |
| 225 | * Register Wifi with nss driver |
| 226 | */ |
| 227 | struct nss_ctx_instance *nss_register_wifi_if(uint32_t if_num, nss_wifi_callback_t wifi_callback, |
Radha krishna Simha Jiguru | 427d603 | 2015-07-07 19:06:07 +0530 | [diff] [blame] | 228 | nss_wifi_callback_t wifi_ext_callback, |
Bharath M Kumar | cc666e9 | 2014-12-24 19:17:28 +0530 | [diff] [blame] | 229 | nss_wifi_msg_callback_t event_callback, struct net_device *netdev, uint32_t features) |
| 230 | { |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 231 | struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.wifi_handler_id]; |
Bharath M Kumar | cc666e9 | 2014-12-24 19:17:28 +0530 | [diff] [blame] | 232 | |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 233 | nss_assert(nss_ctx); |
| 234 | nss_assert((if_num >= NSS_MAX_VIRTUAL_INTERFACES) && (if_num < NSS_MAX_NET_INTERFACES)); |
Bharath M Kumar | cc666e9 | 2014-12-24 19:17:28 +0530 | [diff] [blame] | 235 | |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 236 | nss_info("%p: nss_register_wifi_if if_num %d wifictx %p", nss_ctx, if_num, netdev); |
| 237 | |
| 238 | nss_ctx->subsys_dp_register[if_num].ndev = netdev; |
| 239 | nss_ctx->subsys_dp_register[if_num].cb = wifi_callback; |
| 240 | nss_ctx->subsys_dp_register[if_num].ext_cb = wifi_ext_callback; |
| 241 | nss_ctx->subsys_dp_register[if_num].app_data = NULL; |
| 242 | nss_ctx->subsys_dp_register[if_num].features = features; |
Bharath M Kumar | cc666e9 | 2014-12-24 19:17:28 +0530 | [diff] [blame] | 243 | |
| 244 | nss_top_main.wifi_msg_callback = event_callback; |
| 245 | |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 246 | return nss_ctx; |
Bharath M Kumar | cc666e9 | 2014-12-24 19:17:28 +0530 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | /* |
| 250 | * nss_unregister_wifi_if() |
| 251 | * Unregister wifi with nss driver |
| 252 | */ |
| 253 | void nss_unregister_wifi_if(uint32_t if_num) |
| 254 | { |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 255 | struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.wifi_handler_id]; |
Bharath M Kumar | cc666e9 | 2014-12-24 19:17:28 +0530 | [diff] [blame] | 256 | |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 257 | nss_assert(nss_ctx); |
| 258 | nss_assert((if_num >= NSS_MAX_VIRTUAL_INTERFACES) && (if_num < NSS_MAX_NET_INTERFACES)); |
| 259 | |
| 260 | nss_ctx->subsys_dp_register[if_num].ndev = NULL; |
| 261 | nss_ctx->subsys_dp_register[if_num].cb = NULL; |
| 262 | nss_ctx->subsys_dp_register[if_num].ext_cb = NULL; |
| 263 | nss_ctx->subsys_dp_register[if_num].app_data = NULL; |
| 264 | nss_ctx->subsys_dp_register[if_num].features = 0; |
Bharath M Kumar | cc666e9 | 2014-12-24 19:17:28 +0530 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | /* |
| 268 | * nss_wifi_register_handler() |
| 269 | * Register handle for notfication messages received on wifi interface |
| 270 | */ |
| 271 | void nss_wifi_register_handler(void ) |
| 272 | { |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 273 | struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.wifi_handler_id]; |
| 274 | |
| 275 | nss_assert(nss_ctx); |
| 276 | |
Bharath M Kumar | cc666e9 | 2014-12-24 19:17:28 +0530 | [diff] [blame] | 277 | nss_info("nss_wifi_register_handler"); |
| 278 | |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 279 | nss_core_register_handler(nss_ctx, NSS_WIFI_INTERFACE0, nss_wifi_handler, NULL); |
| 280 | nss_core_register_handler(nss_ctx, NSS_WIFI_INTERFACE1, nss_wifi_handler, NULL); |
| 281 | nss_core_register_handler(nss_ctx, NSS_WIFI_INTERFACE2, nss_wifi_handler, NULL); |
Bharath M Kumar | cc666e9 | 2014-12-24 19:17:28 +0530 | [diff] [blame] | 282 | } |
| 283 | |
ratheesh kannoth | eb2a0a8 | 2017-05-04 09:20:17 +0530 | [diff] [blame] | 284 | EXPORT_SYMBOL(nss_wifi_get_context); |
Bharath M Kumar | cc666e9 | 2014-12-24 19:17:28 +0530 | [diff] [blame] | 285 | EXPORT_SYMBOL(nss_wifi_tx_msg); |
| 286 | EXPORT_SYMBOL(nss_register_wifi_if); |
| 287 | EXPORT_SYMBOL(nss_unregister_wifi_if); |