blob: ca60fd6699df02ec3b346bb33206daeebeeeba95 [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"
Sachin Shashidhar9449ad12018-08-19 22:08:01 -070019#include "nss_wifi_log.h"
Bharath M Kumarcc666e92014-12-24 19:17:28 +053020
ratheesh kannotheb2a0a82017-05-04 09:20:17 +053021/*
22 * nss_wifi_get_context()
23 * Get NSS context of Wifi.
24 */
25struct 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 Kumarcc666e92014-12-24 19:17:28 +053029
30/*
31 * nss_wifi_handler()
32 * Handle NSS -> HLOS messages for wifi
33 */
34static 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 Shashidhar9449ad12018-08-19 22:08:01 -070045 * Trace messages.
46 */
47 nss_wifi_log_rx_msg(ntm);
48
49 /*
Bharath M Kumarcc666e92014-12-24 19:17:28 +053050 * Is this a valid request/response packet?
51 */
52 if (ncm->type >= NSS_WIFI_MAX_MSG) {
Yu Huang8c107082017-07-24 14:58:26 -070053 nss_warning("%p: received invalid message %d for wifi interface", nss_ctx, ncm->type);
Bharath M Kumarcc666e92014-12-24 19:17:28 +053054 return;
55 }
56
Suruchi Agarwalef8a8702016-01-08 12:40:08 -080057 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 Kumarcc666e92014-12-24 19:17:28 +053059 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 Agarwale4ad24a2018-06-11 12:03:46 +053078 if (ncm->response == NSS_CMN_RESPONSE_NOTIFY) {
Stephen Wangaed46332016-12-12 17:29:03 -080079 ncm->cb = (nss_ptr_t)nss_ctx->nss_top->wifi_msg_callback;
Bharath M Kumarcc666e92014-12-24 19:17:28 +053080 }
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 Wang84e0e992016-09-07 12:31:40 -070099 ctx = nss_ctx->subsys_dp_register[ncm->interface].ndev;
Bharath M Kumarcc666e92014-12-24 19:17:28 +0530100
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 */
116nss_tx_status_t nss_wifi_tx_msg(struct nss_ctx_instance *nss_ctx, struct nss_wifi_msg *msg)
117{
Bharath M Kumarcc666e92014-12-24 19:17:28 +0530118 struct nss_cmn_msg *ncm = &msg->cm;
Bharath M Kumarcc666e92014-12-24 19:17:28 +0530119
Sachin Shashidhar9449ad12018-08-19 22:08:01 -0700120 /*
121 * Trace messages.
122 */
123 nss_wifi_log_tx_msg(msg);
124
Bharath M Kumarcc666e92014-12-24 19:17:28 +0530125 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 Wang3e2dbd12018-03-14 17:28:17 -0700130 return nss_core_send_cmd(nss_ctx, msg, sizeof(*msg), NSS_NBUF_PAYLOAD_SIZE);
Bharath M Kumarcc666e92014-12-24 19:17:28 +0530131}
132
133/*
134 ****************************************
135 * Register/Unregister/Miscellaneous APIs
136 ****************************************
137 */
138
139/*
140 * nss_register_wifi_if()
141 * Register Wifi with nss driver
142 */
143struct 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 +0530144 nss_wifi_callback_t wifi_ext_callback,
Bharath M Kumarcc666e92014-12-24 19:17:28 +0530145 nss_wifi_msg_callback_t event_callback, struct net_device *netdev, uint32_t features)
146{
Stephen Wang84e0e992016-09-07 12:31:40 -0700147 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 +0530148
Stephen Wang84e0e992016-09-07 12:31:40 -0700149 nss_assert(nss_ctx);
150 nss_assert((if_num >= NSS_MAX_VIRTUAL_INTERFACES) && (if_num < NSS_MAX_NET_INTERFACES));
Bharath M Kumarcc666e92014-12-24 19:17:28 +0530151
Stephen Wang84e0e992016-09-07 12:31:40 -0700152 nss_info("%p: nss_register_wifi_if if_num %d wifictx %p", nss_ctx, if_num, netdev);
153
Jackson Bockus7ca70ec2017-07-17 13:47:29 -0700154 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 +0530155
156 nss_top_main.wifi_msg_callback = event_callback;
157
Stephen Wang84e0e992016-09-07 12:31:40 -0700158 return nss_ctx;
Bharath M Kumarcc666e92014-12-24 19:17:28 +0530159}
160
161/*
162 * nss_unregister_wifi_if()
163 * Unregister wifi with nss driver
164 */
165void nss_unregister_wifi_if(uint32_t if_num)
166{
Stephen Wang84e0e992016-09-07 12:31:40 -0700167 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 +0530168
Stephen Wang84e0e992016-09-07 12:31:40 -0700169 nss_assert(nss_ctx);
170 nss_assert((if_num >= NSS_MAX_VIRTUAL_INTERFACES) && (if_num < NSS_MAX_NET_INTERFACES));
171
Radha krishna Simha Jiguruf85b5792017-11-28 14:52:40 +0530172 nss_ctx->nss_top->wifi_msg_callback = NULL;
Jackson Bockus7ca70ec2017-07-17 13:47:29 -0700173 nss_core_unregister_subsys_dp(nss_ctx, if_num);
Bharath M Kumarcc666e92014-12-24 19:17:28 +0530174}
175
176/*
177 * nss_wifi_register_handler()
178 * Register handle for notfication messages received on wifi interface
179 */
180void nss_wifi_register_handler(void )
181{
Thomas Wu91f4bdf2017-06-09 12:03:02 -0700182 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 Kumarcc666e92014-12-24 19:17:28 +0530186 nss_info("nss_wifi_register_handler");
187
Thomas Wu91f4bdf2017-06-09 12:03:02 -0700188 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 Huang8c107082017-07-24 14:58:26 -0700191
192 nss_wifi_stats_dentry_create();
Bharath M Kumarcc666e92014-12-24 19:17:28 +0530193}
194
ratheesh kannotheb2a0a82017-05-04 09:20:17 +0530195EXPORT_SYMBOL(nss_wifi_get_context);
Bharath M Kumarcc666e92014-12-24 19:17:28 +0530196EXPORT_SYMBOL(nss_wifi_tx_msg);
197EXPORT_SYMBOL(nss_register_wifi_if);
198EXPORT_SYMBOL(nss_unregister_wifi_if);