Shashank Balashankar | 512cb60 | 2016-08-01 17:57:42 -0700 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Suruchi Agarwal | e4ad24a | 2018-06-11 12:03:46 +0530 | [diff] [blame] | 3 | * Copyright (c) 2016-2018, The Linux Foundation. All rights reserved. |
Shashank Balashankar | 512cb60 | 2016-08-01 17:57:42 -0700 | [diff] [blame] | 4 | * 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 Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 23 | #include "nss_edma_stats.h" |
Shashank Balashankar | 512cb60 | 2016-08-01 17:57:42 -0700 | [diff] [blame] | 24 | |
| 25 | /* |
| 26 | ********************************** |
| 27 | Rx APIs |
| 28 | ********************************** |
| 29 | */ |
| 30 | |
| 31 | /* |
Shashank Balashankar | 512cb60 | 2016-08-01 17:57:42 -0700 | [diff] [blame] | 32 | * nss_edma_interface_handler() |
| 33 | * Handle NSS -> HLOS messages for EDMA node |
| 34 | */ |
| 35 | static 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 Balashankar | 512cb60 | 2016-08-01 17:57:42 -0700 | [diff] [blame] | 55 | case NSS_METADATA_TYPE_EDMA_RING_STATS_SYNC: |
| 56 | nss_edma_metadata_ring_stats_sync(nss_ctx, &nem->msg.ring_stats); |
| 57 | break; |
Santosh Kivati | b65b68b | 2017-05-18 13:30:58 -0700 | [diff] [blame] | 58 | case NSS_METADATA_TYPE_EDMA_ERR_STATS_SYNC: |
| 59 | nss_edma_metadata_err_stats_sync(nss_ctx, &nem->msg.err_stats); |
| 60 | break; |
Shashank Balashankar | 512cb60 | 2016-08-01 17:57:42 -0700 | [diff] [blame] | 61 | 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 Agarwal | e4ad24a | 2018-06-11 12:03:46 +0530 | [diff] [blame] | 75 | if (nem->cm.response == NSS_CMN_RESPONSE_NOTIFY) { |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 76 | 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 Balashankar | 512cb60 | 2016-08-01 17:57:42 -0700 | [diff] [blame] | 78 | } |
| 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 | */ |
| 98 | struct 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 | } |
| 104 | EXPORT_SYMBOL(nss_edma_notify_register); |
| 105 | |
| 106 | /* |
| 107 | * nss_edma_notify_unregister() |
| 108 | * Unregister to received EDMA events. |
| 109 | */ |
| 110 | void nss_edma_notify_unregister(void) |
| 111 | { |
| 112 | nss_top_main.edma_callback = NULL; |
| 113 | } |
| 114 | EXPORT_SYMBOL(nss_edma_notify_unregister); |
| 115 | |
| 116 | /* |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 117 | * nss_get_edma_context() |
| 118 | */ |
| 119 | struct 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 | } |
| 123 | EXPORT_SYMBOL(nss_edma_get_context); |
| 124 | |
| 125 | /* |
Shashank Balashankar | 512cb60 | 2016-08-01 17:57:42 -0700 | [diff] [blame] | 126 | * nss_edma_register_handler() |
| 127 | */ |
| 128 | void nss_edma_register_handler(void) |
| 129 | { |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 130 | 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 Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 133 | |
| 134 | nss_edma_stats_dentry_create(); |
Shashank Balashankar | 512cb60 | 2016-08-01 17:57:42 -0700 | [diff] [blame] | 135 | } |