blob: 6e8ba0417af891ff5a2b6f76fc324ebe5c5ee301 [file] [log] [blame]
Bharath M Kumarcc666e92014-12-24 19:17:28 +05301/*
2 **************************************************************************
Stephen Wang3e2dbd12018-03-14 17:28:17 -07003 * Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
Bharath M Kumarcc666e92014-12-24 19:17:28 +05304 * 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 Huang8c107082017-07-24 14:58:26 -070018#include "nss_wifi_stats.h"
Bharath M Kumarcc666e92014-12-24 19:17:28 +053019
ratheesh kannotheb2a0a82017-05-04 09:20:17 +053020/*
21 * nss_wifi_get_context()
22 * Get NSS context of Wifi.
23 */
24struct 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 Kumarcc666e92014-12-24 19:17:28 +053028
29/*
30 * nss_wifi_handler()
31 * Handle NSS -> HLOS messages for wifi
32 */
33static 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 Huang8c107082017-07-24 14:58:26 -070047 nss_warning("%p: received invalid message %d for wifi interface", nss_ctx, ncm->type);
Bharath M Kumarcc666e92014-12-24 19:17:28 +053048 return;
49 }
50
Suruchi Agarwalef8a8702016-01-08 12:40:08 -080051 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 Kumarcc666e92014-12-24 19:17:28 +053053 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 Wangaed46332016-12-12 17:29:03 -080073 ncm->cb = (nss_ptr_t)nss_ctx->nss_top->wifi_msg_callback;
Bharath M Kumarcc666e92014-12-24 19:17:28 +053074 }
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 Wang84e0e992016-09-07 12:31:40 -070093 ctx = nss_ctx->subsys_dp_register[ncm->interface].ndev;
Bharath M Kumarcc666e92014-12-24 19:17:28 +053094
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 */
110nss_tx_status_t nss_wifi_tx_msg(struct nss_ctx_instance *nss_ctx, struct nss_wifi_msg *msg)
111{
Bharath M Kumarcc666e92014-12-24 19:17:28 +0530112 struct nss_cmn_msg *ncm = &msg->cm;
Bharath M Kumarcc666e92014-12-24 19:17:28 +0530113
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 Wang3e2dbd12018-03-14 17:28:17 -0700119 return nss_core_send_cmd(nss_ctx, msg, sizeof(*msg), NSS_NBUF_PAYLOAD_SIZE);
Bharath M Kumarcc666e92014-12-24 19:17:28 +0530120}
121
122/*
123 ****************************************
124 * Register/Unregister/Miscellaneous APIs
125 ****************************************
126 */
127
128/*
129 * nss_register_wifi_if()
130 * Register Wifi with nss driver
131 */
132struct nss_ctx_instance *nss_register_wifi_if(uint32_t if_num, nss_wifi_callback_t wifi_callback,
Radha krishna Simha Jiguru427d6032015-07-07 19:06:07 +0530133 nss_wifi_callback_t wifi_ext_callback,
Bharath M Kumarcc666e92014-12-24 19:17:28 +0530134 nss_wifi_msg_callback_t event_callback, struct net_device *netdev, uint32_t features)
135{
Stephen Wang84e0e992016-09-07 12:31:40 -0700136 struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.wifi_handler_id];
Bharath M Kumarcc666e92014-12-24 19:17:28 +0530137
Stephen Wang84e0e992016-09-07 12:31:40 -0700138 nss_assert(nss_ctx);
139 nss_assert((if_num >= NSS_MAX_VIRTUAL_INTERFACES) && (if_num < NSS_MAX_NET_INTERFACES));
Bharath M Kumarcc666e92014-12-24 19:17:28 +0530140
Stephen Wang84e0e992016-09-07 12:31:40 -0700141 nss_info("%p: nss_register_wifi_if if_num %d wifictx %p", nss_ctx, if_num, netdev);
142
Jackson Bockus7ca70ec2017-07-17 13:47:29 -0700143 nss_core_register_subsys_dp(nss_ctx, if_num, wifi_callback, wifi_ext_callback, NULL, netdev, features);
Bharath M Kumarcc666e92014-12-24 19:17:28 +0530144
145 nss_top_main.wifi_msg_callback = event_callback;
146
Stephen Wang84e0e992016-09-07 12:31:40 -0700147 return nss_ctx;
Bharath M Kumarcc666e92014-12-24 19:17:28 +0530148}
149
150/*
151 * nss_unregister_wifi_if()
152 * Unregister wifi with nss driver
153 */
154void nss_unregister_wifi_if(uint32_t if_num)
155{
Stephen Wang84e0e992016-09-07 12:31:40 -0700156 struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.wifi_handler_id];
Bharath M Kumarcc666e92014-12-24 19:17:28 +0530157
Stephen Wang84e0e992016-09-07 12:31:40 -0700158 nss_assert(nss_ctx);
159 nss_assert((if_num >= NSS_MAX_VIRTUAL_INTERFACES) && (if_num < NSS_MAX_NET_INTERFACES));
160
Radha krishna Simha Jiguruf85b5792017-11-28 14:52:40 +0530161 nss_ctx->nss_top->wifi_msg_callback = NULL;
Jackson Bockus7ca70ec2017-07-17 13:47:29 -0700162 nss_core_unregister_subsys_dp(nss_ctx, if_num);
Bharath M Kumarcc666e92014-12-24 19:17:28 +0530163}
164
165/*
166 * nss_wifi_register_handler()
167 * Register handle for notfication messages received on wifi interface
168 */
169void nss_wifi_register_handler(void )
170{
Thomas Wu91f4bdf2017-06-09 12:03:02 -0700171 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 Kumarcc666e92014-12-24 19:17:28 +0530175 nss_info("nss_wifi_register_handler");
176
Thomas Wu91f4bdf2017-06-09 12:03:02 -0700177 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 Huang8c107082017-07-24 14:58:26 -0700180
181 nss_wifi_stats_dentry_create();
Bharath M Kumarcc666e92014-12-24 19:17:28 +0530182}
183
ratheesh kannotheb2a0a82017-05-04 09:20:17 +0530184EXPORT_SYMBOL(nss_wifi_get_context);
Bharath M Kumarcc666e92014-12-24 19:17:28 +0530185EXPORT_SYMBOL(nss_wifi_tx_msg);
186EXPORT_SYMBOL(nss_register_wifi_if);
187EXPORT_SYMBOL(nss_unregister_wifi_if);