blob: bb725ee1452f685845b4f70bd072e73912372f4c [file] [log] [blame]
Abhishek Rastogi84d95d02014-03-26 19:31:31 +05301/*
2 **************************************************************************
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -07003 * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
Abhishek Rastogi84d95d02014-03-26 19:31:31 +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/*
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -070018 * nss_n2h.c
Abhishek Rastogi84d95d02014-03-26 19:31:31 +053019 * NSS N2H node APIs
20 */
21
22#include "nss_tx_rx_common.h"
23
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -070024#define NSS_N2H_TIMEOUT 5*HZ
25
26wait_queue_head_t nss_n2h_wq;
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +053027
28/*
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -070029 * nss_n2h_tx()
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +053030 * Send Message to NSS to enable RPS.
31 *
32 * This API could be used for any additional RPS related
33 * configuration in future.
34 */
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -070035nss_tx_status_t nss_n2h_tx(struct nss_ctx_instance *nss_ctx, uint32_t enable_rps)
36{
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +053037 struct sk_buff *nbuf;
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -070038 nss_tx_status_t status;
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +053039 struct nss_n2h_msg *nnhm;
40 struct nss_n2h_rps *rps_cfg;
41
42 NSS_VERIFY_CTX_MAGIC(nss_ctx);
43 if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
44 return NSS_TX_FAILURE_NOT_READY;
45 }
46
Pamidipati, Vijayb6e38842014-09-16 10:26:05 +053047 nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE);
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +053048 if (unlikely(!nbuf)) {
49 spin_lock_bh(&nss_ctx->nss_top->stats_lock);
50 nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]++;
51 spin_unlock_bh(&nss_ctx->nss_top->stats_lock);
52 return NSS_TX_FAILURE;
53 }
54
55 nnhm = (struct nss_n2h_msg *)skb_put(nbuf, sizeof(struct nss_n2h_msg));
56
57 nnhm->cm.type = NSS_TX_METADATA_TYPE_N2H_RPS_CFG;
58 nnhm->cm.version = NSS_HLOS_MESSAGE_VERSION;
59 nnhm->cm.interface = NSS_N2H_INTERFACE;
60 nnhm->cm.len = nbuf->len;
61
62 rps_cfg = &nnhm->msg.rps_cfg;
63
64 rps_cfg->enable = enable_rps;
65
66 nss_info("n22_n2h_rps_configure %d \n", enable_rps);
67
68 status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0);
69 if (status != NSS_CORE_STATUS_SUCCESS) {
Pamidipati, Vijayb6e38842014-09-16 10:26:05 +053070 dev_kfree_skb_any(nbuf);
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +053071 nss_info("%p: unable to enqueue 'nss frequency change' - marked as stopped\n", nss_ctx);
72 return NSS_TX_FAILURE;
73 }
74
75 nss_hal_send_interrupt(nss_ctx->nmap, nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit, NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE);
76
77 return NSS_TX_SUCCESS;
78}
79
80/*
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -070081 * nss_n2h_stats_sync()
Abhishek Rastogi84d95d02014-03-26 19:31:31 +053082 * Handle the syncing of NSS statistics.
83 */
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -070084static void nss_n2h_stats_sync(struct nss_ctx_instance *nss_ctx, struct nss_n2h_stats_sync *nnss)
Abhishek Rastogi84d95d02014-03-26 19:31:31 +053085{
86 struct nss_top_instance *nss_top = nss_ctx->nss_top;
87
88 spin_lock_bh(&nss_top->stats_lock);
89
90 /*
91 * common node stats
92 */
93 nss_ctx->stats_n2h[NSS_STATS_NODE_RX_PKTS] += nnss->node_stats.rx_packets;
94 nss_ctx->stats_n2h[NSS_STATS_NODE_RX_BYTES] += nnss->node_stats.rx_bytes;
95 nss_ctx->stats_n2h[NSS_STATS_NODE_RX_DROPPED] += nnss->node_stats.rx_dropped;
96 nss_ctx->stats_n2h[NSS_STATS_NODE_TX_PKTS] += nnss->node_stats.tx_packets;
97 nss_ctx->stats_n2h[NSS_STATS_NODE_TX_BYTES] += nnss->node_stats.tx_bytes;
98
99 /*
100 * General N2H stats
101 */
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700102 nss_ctx->stats_n2h[NSS_STATS_N2H_QUEUE_DROPPED] += nnss->queue_dropped;
103 nss_ctx->stats_n2h[NSS_STATS_N2H_TOTAL_TICKS] += nnss->total_ticks;
104 nss_ctx->stats_n2h[NSS_STATS_N2H_WORST_CASE_TICKS] += nnss->worst_case_ticks;
105 nss_ctx->stats_n2h[NSS_STATS_N2H_ITERATIONS] += nnss->iterations;
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530106
107 /*
Thomas Wu3fd8dd72014-06-11 15:57:05 -0700108 * pbuf manager ocm and default pool stats
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530109 */
Thomas Wu3fd8dd72014-06-11 15:57:05 -0700110 nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_OCM_ALLOC_FAILS] += nnss->pbuf_ocm_stats.pbuf_alloc_fails;
111 nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_OCM_FREE_COUNT] = nnss->pbuf_ocm_stats.pbuf_free_count;
112 nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_OCM_TOTAL_COUNT] = nnss->pbuf_ocm_stats.pbuf_total_count;
113
114 nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_DEFAULT_ALLOC_FAILS] += nnss->pbuf_default_stats.pbuf_alloc_fails;
115 nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_DEFAULT_FREE_COUNT] = nnss->pbuf_default_stats.pbuf_free_count;
116 nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_DEFAULT_TOTAL_COUNT] = nnss->pbuf_default_stats.pbuf_total_count;
117
118 /*
119 * payload mgr stats
120 */
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530121 nss_ctx->stats_n2h[NSS_STATS_N2H_PAYLOAD_ALLOC_FAILS] += nnss->payload_alloc_fails;
122
123 spin_unlock_bh(&nss_top->stats_lock);
124}
125
126/*
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -0700127 * nss_n2h_interface_handler()
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530128 * Handle NSS -> HLOS messages for N2H node
129 */
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -0700130static void nss_n2h_interface_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data)
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530131{
132 struct nss_n2h_msg *nnm = (struct nss_n2h_msg *)ncm;
133
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -0700134 BUG_ON(ncm->interface != NSS_N2H_INTERFACE);
135
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530136 /*
137 * Is this a valid request/response packet?
138 */
139 if (nnm->cm.type >= NSS_METADATA_TYPE_N2H_MAX) {
140 nss_warning("%p: received invalid message %d for Offload stats interface", nss_ctx, nnm->cm.type);
141 return;
142 }
143
144 switch (nnm->cm.type) {
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +0530145 case NSS_TX_METADATA_TYPE_N2H_RPS_CFG:
146 nss_ctx->n2h_rps_en = nnm->msg.rps_cfg.enable;
147 nss_info("NSS N2H rps_en %d \n",nnm->msg.rps_cfg.enable);
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -0700148 wake_up(&nss_n2h_wq);
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +0530149 break;
150
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530151 case NSS_RX_METADATA_TYPE_N2H_STATS_SYNC:
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -0700152 nss_n2h_stats_sync(nss_ctx, &nnm->msg.stats_sync);
153 wake_up(&nss_n2h_wq);
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530154 break;
155
156 default:
157 if (ncm->response != NSS_CMN_RESPONSE_ACK) {
158 /*
159 * Check response
160 */
161 nss_info("%p: Received response %d for type %d, interface %d",
162 nss_ctx, ncm->response, ncm->type, ncm->interface);
163 }
164 }
165}
166
167/*
168 * nss_n2h_register_handler()
169 */
170void nss_n2h_register_handler()
171{
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -0700172 nss_core_register_handler(NSS_N2H_INTERFACE, nss_n2h_interface_handler, NULL);
173
174 /*
175 * Initialize wait queue
176 */
177 init_waitqueue_head(&nss_n2h_wq);
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530178}