Bharath M Kumar | cc666e9 | 2014-12-24 19:17:28 +0530 | [diff] [blame^] | 1 | /* |
| 2 | ************************************************************************** |
| 3 | * Copyright (c) 2015, The Linux Foundation. All rights reserved. |
| 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; |
| 27 | |
| 28 | spin_lock_bh(&nss_top->stats_lock); |
| 29 | |
| 30 | /* |
| 31 | * Tx/Rx stats |
| 32 | */ |
| 33 | nss_top->stats_wifi[interface][NSS_STATS_WIFI_RX_PKTS] += stats->node_stats.rx_packets; |
| 34 | nss_top->stats_wifi[interface][NSS_STATS_WIFI_RX_DROPPED] += stats->node_stats.rx_dropped; |
| 35 | nss_top->stats_wifi[interface][NSS_STATS_WIFI_TX_PKTS] += stats->node_stats.tx_packets; |
| 36 | nss_top->stats_wifi[interface][NSS_STATS_WIFI_TX_DROPPED] += stats->tx_transmit_dropped; |
| 37 | nss_top->stats_wifi[interface][NSS_STATS_WIFI_TX_COMPLETED] += stats->tx_transmit_completions; |
| 38 | nss_top->stats_wifi[interface][NSS_STATS_WIFI_MGMT_RCV_CNT] += stats->tx_mgmt_rcv_cnt; |
| 39 | nss_top->stats_wifi[interface][NSS_STATS_WIFI_MGMT_TX_PKTS] += stats->tx_mgmt_pkts; |
| 40 | nss_top->stats_wifi[interface][NSS_STATS_WIFI_MGMT_TX_DROPPED] += stats->tx_mgmt_dropped; |
| 41 | nss_top->stats_wifi[interface][NSS_STATS_WIFI_MGMT_TX_COMPLETIONS] += stats->tx_mgmt_completions; |
| 42 | nss_top->stats_wifi[interface][NSS_STATS_WIFI_RX_INV_PEER_ENQUEUE_CNT] += stats->tx_inv_peer_enq_cnt; |
| 43 | nss_top->stats_wifi[interface][NSS_STATS_WIFI_RX_INV_PEER_RCV_CNT] += stats->rx_inv_peer_rcv_cnt; |
| 44 | nss_top->stats_wifi[interface][NSS_STATS_WIFI_RX_PN_CHECK_FAILED] += stats->rx_pn_check_failed; |
| 45 | nss_top->stats_wifi[interface][NSS_STATS_WIFI_RX_DELIVERED] += stats->rx_pkts_deliverd; |
| 46 | |
| 47 | spin_unlock_bh(&nss_top->stats_lock); |
| 48 | } |
| 49 | |
| 50 | |
| 51 | /* |
| 52 | * nss_wifi_handler() |
| 53 | * Handle NSS -> HLOS messages for wifi |
| 54 | */ |
| 55 | static void nss_wifi_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data) |
| 56 | { |
| 57 | struct nss_wifi_msg *ntm = (struct nss_wifi_msg *)ncm; |
| 58 | void *ctx; |
| 59 | nss_wifi_msg_callback_t cb; |
| 60 | |
| 61 | nss_info("%p: NSS ->HLOS message for wifi\n", nss_ctx); |
| 62 | |
| 63 | BUG_ON(((ncm->interface < NSS_WIFI_INTERFACE0) || (ncm->interface > NSS_WIFI_INTERFACE2))); |
| 64 | |
| 65 | /* |
| 66 | * Is this a valid request/response packet? |
| 67 | */ |
| 68 | if (ncm->type >= NSS_WIFI_MAX_MSG) { |
| 69 | nss_warning("%p: received invalid message %d for wifi interface", nss_ctx, ncm->type); |
| 70 | return; |
| 71 | } |
| 72 | |
| 73 | if (ncm->len > sizeof(struct nss_wifi_msg)) { |
| 74 | nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface); |
| 75 | return; |
| 76 | } |
| 77 | |
| 78 | /* |
| 79 | * Snoop messages for local driver and handle |
| 80 | */ |
| 81 | switch (ntm->cm.type) { |
| 82 | case NSS_WIFI_STATS_MSG: |
| 83 | /* |
| 84 | * To create the old API gmac statistics, we use the new extended GMAC stats. |
| 85 | */ |
| 86 | nss_wifi_stats_sync(nss_ctx, &ntm->msg.statsmsg, ncm->interface); |
| 87 | break; |
| 88 | } |
| 89 | |
| 90 | /* |
| 91 | * Update the callback and app_data for NOTIFY messages, wifi sends all notify messages |
| 92 | * to the same callback/app_data. |
| 93 | */ |
| 94 | if (ncm->response == NSS_CMM_RESPONSE_NOTIFY) { |
| 95 | ncm->cb = (uint32_t)nss_ctx->nss_top->wifi_msg_callback; |
| 96 | } |
| 97 | |
| 98 | /* |
| 99 | * Log failures |
| 100 | */ |
| 101 | nss_core_log_msg_failures(nss_ctx, ncm); |
| 102 | |
| 103 | /* |
| 104 | * Do we have a call back |
| 105 | */ |
| 106 | if (!ncm->cb) { |
| 107 | nss_info("%p: cb null for wifi interface %d", nss_ctx, ncm->interface); |
| 108 | return; |
| 109 | } |
| 110 | |
| 111 | /* |
| 112 | * Get callback & context |
| 113 | */ |
| 114 | cb = (nss_wifi_msg_callback_t)ncm->cb; |
| 115 | ctx = nss_ctx->nss_top->subsys_dp_register[ncm->interface].ndev; |
| 116 | |
| 117 | /* |
| 118 | * call wifi msg callback |
| 119 | */ |
| 120 | if (!ctx) { |
| 121 | nss_warning("%p: Event received for wifi interface %d before registration", nss_ctx, ncm->interface); |
| 122 | return; |
| 123 | } |
| 124 | |
| 125 | cb(ctx, ntm); |
| 126 | } |
| 127 | |
| 128 | /* |
| 129 | * nss_wifi_tx_msg |
| 130 | * Transmit a wifi message to NSS FW |
| 131 | */ |
| 132 | nss_tx_status_t nss_wifi_tx_msg(struct nss_ctx_instance *nss_ctx, struct nss_wifi_msg *msg) |
| 133 | { |
| 134 | struct nss_wifi_msg *nm; |
| 135 | struct nss_cmn_msg *ncm = &msg->cm; |
| 136 | struct sk_buff *nbuf; |
| 137 | int32_t status; |
| 138 | |
| 139 | NSS_VERIFY_CTX_MAGIC(nss_ctx); |
| 140 | |
| 141 | if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) { |
| 142 | nss_warning("%p: wifi message dropped as core not ready", nss_ctx); |
| 143 | return NSS_TX_FAILURE_NOT_READY; |
| 144 | } |
| 145 | |
| 146 | if (ncm->type > NSS_WIFI_MAX_MSG) { |
| 147 | nss_warning("%p: wifi message type out of range: %d", nss_ctx, ncm->type); |
| 148 | return NSS_TX_FAILURE; |
| 149 | } |
| 150 | |
| 151 | if (ncm->len > sizeof(struct nss_wifi_msg)) { |
| 152 | nss_warning("%p: wifi message length is invalid: %d", nss_ctx, ncm->len); |
| 153 | return NSS_TX_FAILURE; |
| 154 | } |
| 155 | |
| 156 | nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE); |
| 157 | if (unlikely(!nbuf)) { |
| 158 | spin_lock_bh(&nss_ctx->nss_top->stats_lock); |
| 159 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]); |
| 160 | spin_unlock_bh(&nss_ctx->nss_top->stats_lock); |
| 161 | nss_warning("%p: wifi message dropped as command allocation failed", nss_ctx); |
| 162 | return NSS_TX_FAILURE; |
| 163 | } |
| 164 | |
| 165 | /* |
| 166 | * Copy the message to our skb |
| 167 | */ |
| 168 | nm = (struct nss_wifi_msg *)skb_put(nbuf, sizeof(struct nss_wifi_msg)); |
| 169 | memcpy(nm, msg, sizeof(struct nss_wifi_msg)); |
| 170 | |
| 171 | status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0); |
| 172 | if (status != NSS_CORE_STATUS_SUCCESS) { |
| 173 | dev_kfree_skb_any(nbuf); |
| 174 | nss_warning("%p: Unable to enqueue 'wifi message'", nss_ctx); |
| 175 | return NSS_TX_FAILURE; |
| 176 | } |
| 177 | |
| 178 | nss_hal_send_interrupt(nss_ctx->nmap, nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit, |
| 179 | NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE); |
| 180 | |
| 181 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]); |
| 182 | |
| 183 | return NSS_TX_SUCCESS; |
| 184 | } |
| 185 | |
| 186 | /* |
| 187 | **************************************** |
| 188 | * Register/Unregister/Miscellaneous APIs |
| 189 | **************************************** |
| 190 | */ |
| 191 | |
| 192 | /* |
| 193 | * nss_register_wifi_if() |
| 194 | * Register Wifi with nss driver |
| 195 | */ |
| 196 | struct nss_ctx_instance *nss_register_wifi_if(uint32_t if_num, nss_wifi_callback_t wifi_callback, |
| 197 | nss_wifi_msg_callback_t event_callback, struct net_device *netdev, uint32_t features) |
| 198 | { |
| 199 | nss_assert((if_num >= NSS_MAX_VIRTUAL_INTERFACES) && (if_num < NSS_MAX_NET_INTERFACES)); |
| 200 | |
| 201 | nss_info("nss_register_wifi_if if_num %d wifictx %p", if_num, netdev); |
| 202 | |
| 203 | nss_top_main.subsys_dp_register[if_num].ndev = netdev; |
| 204 | nss_top_main.subsys_dp_register[if_num].cb = wifi_callback; |
| 205 | nss_top_main.subsys_dp_register[if_num].app_data = NULL; |
| 206 | nss_top_main.subsys_dp_register[if_num].features = features; |
| 207 | |
| 208 | nss_top_main.wifi_msg_callback = event_callback; |
| 209 | |
| 210 | return (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.wifi_handler_id]; |
| 211 | } |
| 212 | |
| 213 | /* |
| 214 | * nss_unregister_wifi_if() |
| 215 | * Unregister wifi with nss driver |
| 216 | */ |
| 217 | void nss_unregister_wifi_if(uint32_t if_num) |
| 218 | { |
| 219 | nss_assert((if_num >= NSS_MAX_VIRTUAL_INTERFACES) && (if_num < NSS_MAX_NET_INTERFACES)); |
| 220 | |
| 221 | nss_top_main.subsys_dp_register[if_num].ndev = NULL; |
| 222 | nss_top_main.subsys_dp_register[if_num].cb = NULL; |
| 223 | nss_top_main.subsys_dp_register[if_num].app_data = NULL; |
| 224 | nss_top_main.subsys_dp_register[if_num].features = 0; |
| 225 | |
| 226 | nss_top_main.wifi_msg_callback = NULL; |
| 227 | |
| 228 | nss_core_unregister_handler(if_num); |
| 229 | } |
| 230 | |
| 231 | /* |
| 232 | * nss_wifi_register_handler() |
| 233 | * Register handle for notfication messages received on wifi interface |
| 234 | */ |
| 235 | void nss_wifi_register_handler(void ) |
| 236 | { |
| 237 | nss_info("nss_wifi_register_handler"); |
| 238 | |
| 239 | nss_core_register_handler(NSS_WIFI_INTERFACE0, nss_wifi_handler, NULL); |
| 240 | nss_core_register_handler(NSS_WIFI_INTERFACE1, nss_wifi_handler, NULL); |
| 241 | nss_core_register_handler(NSS_WIFI_INTERFACE2, nss_wifi_handler, NULL); |
| 242 | } |
| 243 | |
| 244 | EXPORT_SYMBOL(nss_wifi_tx_msg); |
| 245 | EXPORT_SYMBOL(nss_register_wifi_if); |
| 246 | EXPORT_SYMBOL(nss_unregister_wifi_if); |