blob: 57feb1c3bd6e2852899bde774dcfc0a2745e8444 [file] [log] [blame]
Shashank Balashankar512cb602016-08-01 17:57:42 -07001/*
2 **************************************************************************
Suruchi Agarwale4ad24a2018-06-11 12:03:46 +05303 * Copyright (c) 2016-2018, 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"
Yu Huang8c107082017-07-24 14:58:26 -070023#include "nss_edma_stats.h"
Shashank Balashankar512cb602016-08-01 17:57:42 -070024
25/*
26 **********************************
27 Rx APIs
28 **********************************
29 */
30
31/*
Shashank Balashankar512cb602016-08-01 17:57:42 -070032 * nss_edma_interface_handler()
33 * Handle NSS -> HLOS messages for EDMA node
34 */
35static void nss_edma_interface_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data)
36{
37 struct nss_edma_msg *nem = (struct nss_edma_msg *)ncm;
38 nss_edma_msg_callback_t cb;
39
40 /*
41 * Is this a valid request/response packet?
42 */
43 if (nem->cm.type >= NSS_METADATA_TYPE_EDMA_MAX) {
44 nss_warning("%p: received invalid message %d for edma interface", nss_ctx, nem->cm.type);
45 return;
46 }
47
48 /*
49 * Handle different types of messages
50 */
51 switch (nem->cm.type) {
52 case NSS_METADATA_TYPE_EDMA_PORT_STATS_SYNC:
53 nss_edma_metadata_port_stats_sync(nss_ctx, &nem->msg.port_stats);
54 break;
Shashank Balashankar512cb602016-08-01 17:57:42 -070055 case NSS_METADATA_TYPE_EDMA_RING_STATS_SYNC:
56 nss_edma_metadata_ring_stats_sync(nss_ctx, &nem->msg.ring_stats);
57 break;
Santosh Kivatib65b68b2017-05-18 13:30:58 -070058 case NSS_METADATA_TYPE_EDMA_ERR_STATS_SYNC:
59 nss_edma_metadata_err_stats_sync(nss_ctx, &nem->msg.err_stats);
60 break;
Shashank Balashankar512cb602016-08-01 17:57:42 -070061 default:
62 if (ncm->response != NSS_CMN_RESPONSE_ACK) {
63 /*
64 * Check response
65 */
66 nss_info("%p: Received response %d for type %d, interface %d",
67 nss_ctx, ncm->response, ncm->type, ncm->interface);
68 }
69 }
70
71 /*
72 * Update the callback and app_data for NOTIFY messages, edma sends all notify messages
73 * to the same callback/app_data.
74 */
Suruchi Agarwale4ad24a2018-06-11 12:03:46 +053075 if (nem->cm.response == NSS_CMN_RESPONSE_NOTIFY) {
Stephen Wangaed46332016-12-12 17:29:03 -080076 ncm->cb = (nss_ptr_t)nss_ctx->nss_top->edma_callback;
77 ncm->app_data = (nss_ptr_t)nss_ctx->nss_top->edma_ctx;
Shashank Balashankar512cb602016-08-01 17:57:42 -070078 }
79
80 /*
81 * Do we have a callback?
82 */
83 if (!ncm->cb) {
84 return;
85 }
86
87 /*
88 * Callback
89 */
90 cb = (nss_edma_msg_callback_t)ncm->cb;
91 cb((void *)ncm->app_data, nem);
92}
93
94/*
95 * nss_edma_notify_register()
96 * Register to received EDMA events.
97 */
98struct nss_ctx_instance *nss_edma_notify_register(nss_edma_msg_callback_t cb, void *app_data)
99{
100 nss_top_main.edma_callback = cb;
101 nss_top_main.edma_ctx = app_data;
102 return &nss_top_main.nss[nss_top_main.edma_handler_id];
103}
104EXPORT_SYMBOL(nss_edma_notify_register);
105
106/*
107 * nss_edma_notify_unregister()
108 * Unregister to received EDMA events.
109 */
110void nss_edma_notify_unregister(void)
111{
112 nss_top_main.edma_callback = NULL;
113}
114EXPORT_SYMBOL(nss_edma_notify_unregister);
115
116/*
Thomas Wu91f4bdf2017-06-09 12:03:02 -0700117 * nss_get_edma_context()
118 */
119struct nss_ctx_instance *nss_edma_get_context(void)
120{
121 return (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.edma_handler_id];
122}
123EXPORT_SYMBOL(nss_edma_get_context);
124
125/*
Shashank Balashankar512cb602016-08-01 17:57:42 -0700126 * nss_edma_register_handler()
127 */
128void nss_edma_register_handler(void)
129{
Thomas Wu91f4bdf2017-06-09 12:03:02 -0700130 struct nss_ctx_instance *nss_ctx = nss_edma_get_context();
131
132 nss_core_register_handler(nss_ctx, NSS_EDMA_INTERFACE, nss_edma_interface_handler, NULL);
Yu Huang8c107082017-07-24 14:58:26 -0700133
134 nss_edma_stats_dentry_create();
Shashank Balashankar512cb602016-08-01 17:57:42 -0700135}