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