blob: bfcca627cd444d69d8833764a5be4a3379291a8d [file] [log] [blame]
Shashank Balashankar512cb602016-08-01 17:57:42 -07001/*
2 **************************************************************************
Stephen Wangaed46332016-12-12 17:29:03 -08003 * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
Shashank Balashankar512cb602016-08-01 17:57:42 -07004 * 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/*
18 * nss_edma.c
19 * NSS EDMA APIs
20 */
21
22#include "nss_tx_rx_common.h"
23
24/*
25 **********************************
26 Rx APIs
27 **********************************
28 */
29
30/*
31 * nss_edma_metadata_port_stats_sync()
32 * Handle the syncing of EDMA port statistics.
33 */
34static void nss_edma_metadata_port_stats_sync(struct nss_ctx_instance *nss_ctx, struct nss_edma_port_stats_sync *nepss)
35{
ratheesh kannoth93ba95c2017-07-13 15:52:52 +053036 int i;
Shashank Balashankar512cb602016-08-01 17:57:42 -070037 struct nss_top_instance *nss_top = nss_ctx->nss_top;
38
39 spin_lock_bh(&nss_top->stats_lock);
40
41 /*
42 * edma port stats
43 * We process a subset of port stats since msg payload is not enough to hold all ports at once.
44 */
45 for (i = nepss->start_port; i < nepss->end_port; i++) {
ratheesh kannoth93ba95c2017-07-13 15:52:52 +053046 int k;
Shashank Balashankar512cb602016-08-01 17:57:42 -070047
ratheesh kannoth93ba95c2017-07-13 15:52:52 +053048 nss_top->stats_edma.port[i].port_stats[NSS_STATS_NODE_RX_PKTS] += nepss->port_stats[i].node_stats.rx_packets;
49 nss_top->stats_edma.port[i].port_stats[NSS_STATS_NODE_RX_BYTES] += nepss->port_stats[i].node_stats.rx_bytes;
50 nss_top->stats_edma.port[i].port_stats[NSS_STATS_NODE_TX_PKTS] += nepss->port_stats[i].node_stats.tx_packets;
51 nss_top->stats_edma.port[i].port_stats[NSS_STATS_NODE_TX_BYTES] += nepss->port_stats[i].node_stats.tx_bytes;
52
53 for (k = 0; k < NSS_MAX_NUM_PRI; k++) {
54 nss_top->stats_edma.port[i].port_stats[NSS_STATS_NODE_RX_QUEUE_0_DROPPED + k] += nepss->port_stats[i].node_stats.rx_dropped[k];
55 }
56
57 nss_top->stats_edma.port[i].port_type = nepss->port_stats[i].port_type;
58 nss_top->stats_edma.port[i].port_ring_map[NSS_EDMA_PORT_RX_RING] = nepss->port_stats[i].edma_rx_ring;
59 nss_top->stats_edma.port[i].port_ring_map[NSS_EDMA_PORT_TX_RING] = nepss->port_stats[i].edma_tx_ring;
Shashank Balashankar512cb602016-08-01 17:57:42 -070060 }
61
62 spin_unlock_bh(&nss_top->stats_lock);
63}
64
65/*
66 * nss_edma_metadata_ring_stats_sync()
67 * Handle the syncing of EDMA ring statistics.
68 */
69static void nss_edma_metadata_ring_stats_sync(struct nss_ctx_instance *nss_ctx, struct nss_edma_ring_stats_sync *nerss)
70{
ratheesh kannoth93ba95c2017-07-13 15:52:52 +053071 int i;
Shashank Balashankar512cb602016-08-01 17:57:42 -070072 struct nss_top_instance *nss_top = nss_ctx->nss_top;
73
74 spin_lock_bh(&nss_top->stats_lock);
75
76 /*
77 * edma tx ring stats
78 */
79 for (i = 0; i < NSS_EDMA_NUM_TX_RING_MAX; i++) {
80 nss_top->stats_edma.tx_stats[i][NSS_STATS_EDMA_TX_ERR] += nerss->tx_ring[i].tx_err;
81 nss_top->stats_edma.tx_stats[i][NSS_STATS_EDMA_TX_DROPPED] += nerss->tx_ring[i].tx_dropped;
82 nss_top->stats_edma.tx_stats[i][NSS_STATS_EDMA_TX_DESC] += nerss->tx_ring[i].desc_cnt;
83 }
84
85 /*
86 * edma rx ring stats
87 */
88 for (i = 0; i < NSS_EDMA_NUM_RX_RING_MAX; i++) {
89 nss_top->stats_edma.rx_stats[i][NSS_STATS_EDMA_RX_CSUM_ERR] += nerss->rx_ring[i].rx_csum_err;
90 nss_top->stats_edma.rx_stats[i][NSS_STATS_EDMA_RX_DESC] += nerss->rx_ring[i].desc_cnt;
Shashank Balashankarcbe48992017-06-27 13:51:28 -070091 nss_top->stats_edma.rx_stats[i][NSS_STATS_EDMA_RX_QOS_ERR] += nerss->rx_ring[i].qos_err;
Shashank Balashankar512cb602016-08-01 17:57:42 -070092 }
93
94 /*
95 * edma tx cmpl ring stats
96 */
97 for (i = 0; i < NSS_EDMA_NUM_TXCMPL_RING_MAX; i++) {
98 nss_top->stats_edma.txcmpl_stats[i][NSS_STATS_EDMA_TXCMPL_DESC] += nerss->txcmpl_ring[i].desc_cnt;
99 }
100
101 /*
102 * edma rx fill ring stats
103 */
104 for (i = 0; i < NSS_EDMA_NUM_RXFILL_RING_MAX; i++) {
105 nss_top->stats_edma.rxfill_stats[i][NSS_STATS_EDMA_RXFILL_DESC] += nerss->rxfill_ring[i].desc_cnt;
106 }
107
108 spin_unlock_bh(&nss_top->stats_lock);
109}
110
111/*
Santosh Kivatib65b68b2017-05-18 13:30:58 -0700112 * nss_edma_metadata_err_stats_sync()
113 * Handle the syncing of EDMA error statistics.
114 */
115static void nss_edma_metadata_err_stats_sync(struct nss_ctx_instance *nss_ctx, struct nss_edma_err_stats_sync *nerss)
116{
117
118 struct nss_top_instance *nss_top = nss_ctx->nss_top;
119
120 spin_lock_bh(&nss_top->stats_lock);
121 nss_top->stats_edma.misc_err[NSS_EDMA_AXI_RD_ERR] += nerss->msg_err_stats.axi_rd_err;
122 nss_top->stats_edma.misc_err[NSS_EDMA_AXI_WR_ERR] += nerss->msg_err_stats.axi_wr_err;
123 nss_top->stats_edma.misc_err[NSS_EDMA_RX_DESC_FIFO_FULL_ERR] += nerss->msg_err_stats.rx_desc_fifo_full_err;
124 nss_top->stats_edma.misc_err[NSS_EDMA_RX_BUF_SIZE_ERR] += nerss->msg_err_stats.rx_buf_size_err;
125 nss_top->stats_edma.misc_err[NSS_EDMA_TX_SRAM_FULL_ERR] += nerss->msg_err_stats.tx_sram_full_err;
126 nss_top->stats_edma.misc_err[NSS_EDMA_TX_CMPL_BUF_FULL_ERR] += nerss->msg_err_stats.tx_cmpl_buf_full_err;
127 nss_top->stats_edma.misc_err[NSS_EDMA_PKT_LEN_LA64K_ERR] += nerss->msg_err_stats.pkt_len_la64k_err;
128 nss_top->stats_edma.misc_err[NSS_EDMA_PKT_LEN_LE33_ERR] += nerss->msg_err_stats.pkt_len_le33_err;
129 nss_top->stats_edma.misc_err[NSS_EDMA_DATA_LEN_ERR] += nerss->msg_err_stats.data_len_err;
Santosh Kivati28c20042017-07-11 16:47:57 -0700130 nss_top->stats_edma.misc_err[NSS_EDMA_ALLOC_FAIL_CNT] += nerss->msg_err_stats.alloc_fail_cnt;
Santosh Kivatib65b68b2017-05-18 13:30:58 -0700131 spin_unlock_bh(&nss_top->stats_lock);
132}
133
134/*
Shashank Balashankar512cb602016-08-01 17:57:42 -0700135 * nss_edma_interface_handler()
136 * Handle NSS -> HLOS messages for EDMA node
137 */
138static void nss_edma_interface_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data)
139{
140 struct nss_edma_msg *nem = (struct nss_edma_msg *)ncm;
141 nss_edma_msg_callback_t cb;
142
143 /*
144 * Is this a valid request/response packet?
145 */
146 if (nem->cm.type >= NSS_METADATA_TYPE_EDMA_MAX) {
147 nss_warning("%p: received invalid message %d for edma interface", nss_ctx, nem->cm.type);
148 return;
149 }
150
151 /*
152 * Handle different types of messages
153 */
154 switch (nem->cm.type) {
155 case NSS_METADATA_TYPE_EDMA_PORT_STATS_SYNC:
156 nss_edma_metadata_port_stats_sync(nss_ctx, &nem->msg.port_stats);
157 break;
Shashank Balashankar512cb602016-08-01 17:57:42 -0700158 case NSS_METADATA_TYPE_EDMA_RING_STATS_SYNC:
159 nss_edma_metadata_ring_stats_sync(nss_ctx, &nem->msg.ring_stats);
160 break;
Santosh Kivatib65b68b2017-05-18 13:30:58 -0700161 case NSS_METADATA_TYPE_EDMA_ERR_STATS_SYNC:
162 nss_edma_metadata_err_stats_sync(nss_ctx, &nem->msg.err_stats);
163 break;
Shashank Balashankar512cb602016-08-01 17:57:42 -0700164 default:
165 if (ncm->response != NSS_CMN_RESPONSE_ACK) {
166 /*
167 * Check response
168 */
169 nss_info("%p: Received response %d for type %d, interface %d",
170 nss_ctx, ncm->response, ncm->type, ncm->interface);
171 }
172 }
173
174 /*
175 * Update the callback and app_data for NOTIFY messages, edma sends all notify messages
176 * to the same callback/app_data.
177 */
178 if (nem->cm.response == NSS_CMM_RESPONSE_NOTIFY) {
Stephen Wangaed46332016-12-12 17:29:03 -0800179 ncm->cb = (nss_ptr_t)nss_ctx->nss_top->edma_callback;
180 ncm->app_data = (nss_ptr_t)nss_ctx->nss_top->edma_ctx;
Shashank Balashankar512cb602016-08-01 17:57:42 -0700181 }
182
183 /*
184 * Do we have a callback?
185 */
186 if (!ncm->cb) {
187 return;
188 }
189
190 /*
191 * Callback
192 */
193 cb = (nss_edma_msg_callback_t)ncm->cb;
194 cb((void *)ncm->app_data, nem);
195}
196
197/*
198 * nss_edma_notify_register()
199 * Register to received EDMA events.
200 */
201struct nss_ctx_instance *nss_edma_notify_register(nss_edma_msg_callback_t cb, void *app_data)
202{
203 nss_top_main.edma_callback = cb;
204 nss_top_main.edma_ctx = app_data;
205 return &nss_top_main.nss[nss_top_main.edma_handler_id];
206}
207EXPORT_SYMBOL(nss_edma_notify_register);
208
209/*
210 * nss_edma_notify_unregister()
211 * Unregister to received EDMA events.
212 */
213void nss_edma_notify_unregister(void)
214{
215 nss_top_main.edma_callback = NULL;
216}
217EXPORT_SYMBOL(nss_edma_notify_unregister);
218
219/*
Thomas Wu91f4bdf2017-06-09 12:03:02 -0700220 * nss_get_edma_context()
221 */
222struct nss_ctx_instance *nss_edma_get_context(void)
223{
224 return (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.edma_handler_id];
225}
226EXPORT_SYMBOL(nss_edma_get_context);
227
228/*
Shashank Balashankar512cb602016-08-01 17:57:42 -0700229 * nss_edma_register_handler()
230 */
231void nss_edma_register_handler(void)
232{
Thomas Wu91f4bdf2017-06-09 12:03:02 -0700233 struct nss_ctx_instance *nss_ctx = nss_edma_get_context();
234
235 nss_core_register_handler(nss_ctx, NSS_EDMA_INTERFACE, nss_edma_interface_handler, NULL);
Shashank Balashankar512cb602016-08-01 17:57:42 -0700236}