Bharath M Kumar | cc666e9 | 2014-12-24 19:17:28 +0530 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Stephen Wang | 3e2dbd1 | 2018-03-14 17:28:17 -0700 | [diff] [blame^] | 3 | * Copyright (c) 2015-2018, 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" |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 18 | #include "nss_wifi_stats.h" |
Bharath M Kumar | cc666e9 | 2014-12-24 19:17:28 +0530 | [diff] [blame] | 19 | |
ratheesh kannoth | eb2a0a8 | 2017-05-04 09:20:17 +0530 | [diff] [blame] | 20 | /* |
| 21 | * nss_wifi_get_context() |
| 22 | * Get NSS context of Wifi. |
| 23 | */ |
| 24 | struct nss_ctx_instance *nss_wifi_get_context() |
| 25 | { |
| 26 | return (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.wifi_handler_id]; |
| 27 | } |
Bharath M Kumar | cc666e9 | 2014-12-24 19:17:28 +0530 | [diff] [blame] | 28 | |
| 29 | /* |
| 30 | * nss_wifi_handler() |
| 31 | * Handle NSS -> HLOS messages for wifi |
| 32 | */ |
| 33 | static void nss_wifi_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data) |
| 34 | { |
| 35 | struct nss_wifi_msg *ntm = (struct nss_wifi_msg *)ncm; |
| 36 | void *ctx; |
| 37 | nss_wifi_msg_callback_t cb; |
| 38 | |
| 39 | nss_info("%p: NSS ->HLOS message for wifi\n", nss_ctx); |
| 40 | |
| 41 | BUG_ON(((ncm->interface < NSS_WIFI_INTERFACE0) || (ncm->interface > NSS_WIFI_INTERFACE2))); |
| 42 | |
| 43 | /* |
| 44 | * Is this a valid request/response packet? |
| 45 | */ |
| 46 | if (ncm->type >= NSS_WIFI_MAX_MSG) { |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 47 | nss_warning("%p: received invalid message %d for wifi interface", nss_ctx, ncm->type); |
Bharath M Kumar | cc666e9 | 2014-12-24 19:17:28 +0530 | [diff] [blame] | 48 | return; |
| 49 | } |
| 50 | |
Suruchi Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 51 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_wifi_msg)) { |
| 52 | 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] | 53 | return; |
| 54 | } |
| 55 | |
| 56 | /* |
| 57 | * Snoop messages for local driver and handle |
| 58 | */ |
| 59 | switch (ntm->cm.type) { |
| 60 | case NSS_WIFI_STATS_MSG: |
| 61 | /* |
| 62 | * To create the old API gmac statistics, we use the new extended GMAC stats. |
| 63 | */ |
| 64 | nss_wifi_stats_sync(nss_ctx, &ntm->msg.statsmsg, ncm->interface); |
| 65 | break; |
| 66 | } |
| 67 | |
| 68 | /* |
| 69 | * Update the callback and app_data for NOTIFY messages, wifi sends all notify messages |
| 70 | * to the same callback/app_data. |
| 71 | */ |
| 72 | if (ncm->response == NSS_CMM_RESPONSE_NOTIFY) { |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 73 | 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] | 74 | } |
| 75 | |
| 76 | /* |
| 77 | * Log failures |
| 78 | */ |
| 79 | nss_core_log_msg_failures(nss_ctx, ncm); |
| 80 | |
| 81 | /* |
| 82 | * Do we have a call back |
| 83 | */ |
| 84 | if (!ncm->cb) { |
| 85 | nss_info("%p: cb null for wifi interface %d", nss_ctx, ncm->interface); |
| 86 | return; |
| 87 | } |
| 88 | |
| 89 | /* |
| 90 | * Get callback & context |
| 91 | */ |
| 92 | cb = (nss_wifi_msg_callback_t)ncm->cb; |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 93 | ctx = nss_ctx->subsys_dp_register[ncm->interface].ndev; |
Bharath M Kumar | cc666e9 | 2014-12-24 19:17:28 +0530 | [diff] [blame] | 94 | |
| 95 | /* |
| 96 | * call wifi msg callback |
| 97 | */ |
| 98 | if (!ctx) { |
| 99 | nss_warning("%p: Event received for wifi interface %d before registration", nss_ctx, ncm->interface); |
| 100 | return; |
| 101 | } |
| 102 | |
| 103 | cb(ctx, ntm); |
| 104 | } |
| 105 | |
| 106 | /* |
| 107 | * nss_wifi_tx_msg |
| 108 | * Transmit a wifi message to NSS FW |
| 109 | */ |
| 110 | nss_tx_status_t nss_wifi_tx_msg(struct nss_ctx_instance *nss_ctx, struct nss_wifi_msg *msg) |
| 111 | { |
Bharath M Kumar | cc666e9 | 2014-12-24 19:17:28 +0530 | [diff] [blame] | 112 | struct nss_cmn_msg *ncm = &msg->cm; |
Bharath M Kumar | cc666e9 | 2014-12-24 19:17:28 +0530 | [diff] [blame] | 113 | |
| 114 | if (ncm->type > NSS_WIFI_MAX_MSG) { |
| 115 | nss_warning("%p: wifi message type out of range: %d", nss_ctx, ncm->type); |
| 116 | return NSS_TX_FAILURE; |
| 117 | } |
| 118 | |
Stephen Wang | 3e2dbd1 | 2018-03-14 17:28:17 -0700 | [diff] [blame^] | 119 | return nss_core_send_cmd(nss_ctx, msg, sizeof(*msg), NSS_NBUF_PAYLOAD_SIZE); |
Bharath M Kumar | cc666e9 | 2014-12-24 19:17:28 +0530 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | /* |
| 123 | **************************************** |
| 124 | * Register/Unregister/Miscellaneous APIs |
| 125 | **************************************** |
| 126 | */ |
| 127 | |
| 128 | /* |
| 129 | * nss_register_wifi_if() |
| 130 | * Register Wifi with nss driver |
| 131 | */ |
| 132 | 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] | 133 | nss_wifi_callback_t wifi_ext_callback, |
Bharath M Kumar | cc666e9 | 2014-12-24 19:17:28 +0530 | [diff] [blame] | 134 | nss_wifi_msg_callback_t event_callback, struct net_device *netdev, uint32_t features) |
| 135 | { |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 136 | 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] | 137 | |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 138 | nss_assert(nss_ctx); |
| 139 | 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] | 140 | |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 141 | nss_info("%p: nss_register_wifi_if if_num %d wifictx %p", nss_ctx, if_num, netdev); |
| 142 | |
Jackson Bockus | 7ca70ec | 2017-07-17 13:47:29 -0700 | [diff] [blame] | 143 | nss_core_register_subsys_dp(nss_ctx, if_num, wifi_callback, wifi_ext_callback, NULL, netdev, features); |
Bharath M Kumar | cc666e9 | 2014-12-24 19:17:28 +0530 | [diff] [blame] | 144 | |
| 145 | nss_top_main.wifi_msg_callback = event_callback; |
| 146 | |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 147 | return nss_ctx; |
Bharath M Kumar | cc666e9 | 2014-12-24 19:17:28 +0530 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | /* |
| 151 | * nss_unregister_wifi_if() |
| 152 | * Unregister wifi with nss driver |
| 153 | */ |
| 154 | void nss_unregister_wifi_if(uint32_t if_num) |
| 155 | { |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 156 | 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] | 157 | |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 158 | nss_assert(nss_ctx); |
| 159 | nss_assert((if_num >= NSS_MAX_VIRTUAL_INTERFACES) && (if_num < NSS_MAX_NET_INTERFACES)); |
| 160 | |
Radha krishna Simha Jiguru | f85b579 | 2017-11-28 14:52:40 +0530 | [diff] [blame] | 161 | nss_ctx->nss_top->wifi_msg_callback = NULL; |
Jackson Bockus | 7ca70ec | 2017-07-17 13:47:29 -0700 | [diff] [blame] | 162 | nss_core_unregister_subsys_dp(nss_ctx, if_num); |
Bharath M Kumar | cc666e9 | 2014-12-24 19:17:28 +0530 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | /* |
| 166 | * nss_wifi_register_handler() |
| 167 | * Register handle for notfication messages received on wifi interface |
| 168 | */ |
| 169 | void nss_wifi_register_handler(void ) |
| 170 | { |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 171 | struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.wifi_handler_id]; |
| 172 | |
| 173 | nss_assert(nss_ctx); |
| 174 | |
Bharath M Kumar | cc666e9 | 2014-12-24 19:17:28 +0530 | [diff] [blame] | 175 | nss_info("nss_wifi_register_handler"); |
| 176 | |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 177 | nss_core_register_handler(nss_ctx, NSS_WIFI_INTERFACE0, nss_wifi_handler, NULL); |
| 178 | nss_core_register_handler(nss_ctx, NSS_WIFI_INTERFACE1, nss_wifi_handler, NULL); |
| 179 | nss_core_register_handler(nss_ctx, NSS_WIFI_INTERFACE2, nss_wifi_handler, NULL); |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 180 | |
| 181 | nss_wifi_stats_dentry_create(); |
Bharath M Kumar | cc666e9 | 2014-12-24 19:17:28 +0530 | [diff] [blame] | 182 | } |
| 183 | |
ratheesh kannoth | eb2a0a8 | 2017-05-04 09:20:17 +0530 | [diff] [blame] | 184 | EXPORT_SYMBOL(nss_wifi_get_context); |
Bharath M Kumar | cc666e9 | 2014-12-24 19:17:28 +0530 | [diff] [blame] | 185 | EXPORT_SYMBOL(nss_wifi_tx_msg); |
| 186 | EXPORT_SYMBOL(nss_register_wifi_if); |
| 187 | EXPORT_SYMBOL(nss_unregister_wifi_if); |