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