Manish Verma | 8a56a48 | 2019-05-20 12:46:31 +0530 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
| 3 | * Copyright (c) 2019, The Linux Foundation. All rights reserved. |
| 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 | #include "nss_tx_rx_common.h" |
Manish Verma | 30fbe18 | 2019-06-17 21:02:24 +0530 | [diff] [blame^] | 18 | #include "nss_igs_stats.h" |
Manish Verma | 8a56a48 | 2019-05-20 12:46:31 +0530 | [diff] [blame] | 19 | |
| 20 | /* |
| 21 | * nss_igs_verify_if_num() |
| 22 | * Verify interface number passed to us. |
| 23 | */ |
| 24 | bool nss_igs_verify_if_num(uint32_t if_num) |
| 25 | { |
| 26 | enum nss_dynamic_interface_type if_type; |
| 27 | |
| 28 | if_type = nss_dynamic_interface_get_type(nss_igs_get_context(), if_num); |
| 29 | |
| 30 | if (if_type == NSS_DYNAMIC_INTERFACE_TYPE_IGS) { |
| 31 | return true; |
| 32 | } |
| 33 | return false; |
| 34 | } |
| 35 | EXPORT_SYMBOL(nss_igs_verify_if_num); |
| 36 | |
| 37 | /* |
| 38 | * nss_igs_handler() |
| 39 | * Handle NSS -> HLOS messages for igs device |
| 40 | */ |
| 41 | static void nss_igs_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, |
| 42 | void *app_data) |
| 43 | { |
| 44 | void *ctx; |
| 45 | nss_igs_msg_callback_t cb; |
| 46 | |
| 47 | NSS_VERIFY_CTX_MAGIC(nss_ctx); |
| 48 | BUG_ON(!nss_igs_verify_if_num(ncm->interface)); |
| 49 | |
| 50 | /* |
| 51 | * Is this a valid request/response packet? |
| 52 | */ |
| 53 | if (ncm->type >= NSS_IGS_MSG_MAX) { |
| 54 | nss_warning("%p: received invalid message %d for IGS interface", nss_ctx, ncm->type); |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_igs_msg)) { |
| 59 | nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface); |
| 60 | return; |
| 61 | } |
| 62 | |
| 63 | switch (ncm->type) { |
| 64 | case NSS_IGS_MSG_SYNC_STATS: |
Manish Verma | 30fbe18 | 2019-06-17 21:02:24 +0530 | [diff] [blame^] | 65 | /* |
| 66 | * Debug stats embedded in stats msg. |
| 67 | */ |
| 68 | nss_igs_stats_sync(nss_ctx, ncm, ncm->interface); |
Manish Verma | 8a56a48 | 2019-05-20 12:46:31 +0530 | [diff] [blame] | 69 | break; |
| 70 | } |
| 71 | |
| 72 | /* |
| 73 | * Update the callback and app_data for NOTIFY messages |
| 74 | */ |
| 75 | if (ncm->response == NSS_CMN_RESPONSE_NOTIFY) { |
| 76 | ncm->cb = (nss_ptr_t)nss_top_main.if_rx_msg_callback[ncm->interface]; |
| 77 | ncm->app_data = (nss_ptr_t)app_data; |
| 78 | } |
| 79 | |
| 80 | /* |
| 81 | * callback |
| 82 | */ |
| 83 | cb = (nss_igs_msg_callback_t)ncm->cb; |
| 84 | ctx = (void *)ncm->app_data; |
| 85 | |
| 86 | /* |
| 87 | * call igs callback |
| 88 | */ |
| 89 | if (!cb) { |
| 90 | nss_warning("%p: No callback for igs interface %d", |
| 91 | nss_ctx, ncm->interface); |
| 92 | return; |
| 93 | } |
| 94 | |
| 95 | cb(ctx, ncm); |
| 96 | } |
| 97 | |
| 98 | /* |
| 99 | * nss_igs_unregister_if() |
| 100 | * Un-registers IGS interface from the NSS firmware. |
| 101 | */ |
| 102 | void nss_igs_unregister_if(uint32_t if_num) |
| 103 | { |
| 104 | struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.igs_handler_id]; |
| 105 | |
| 106 | nss_assert(nss_ctx); |
| 107 | nss_assert(nss_igs_verify_if_num(if_num)); |
| 108 | |
| 109 | nss_core_unregister_subsys_dp(nss_ctx, if_num); |
| 110 | |
| 111 | nss_top_main.if_rx_msg_callback[if_num] = NULL; |
| 112 | |
| 113 | nss_core_unregister_handler(nss_ctx, if_num); |
Manish Verma | 30fbe18 | 2019-06-17 21:02:24 +0530 | [diff] [blame^] | 114 | |
| 115 | nss_igs_stats_reset(if_num); |
Manish Verma | 8a56a48 | 2019-05-20 12:46:31 +0530 | [diff] [blame] | 116 | } |
| 117 | EXPORT_SYMBOL(nss_igs_unregister_if); |
| 118 | |
| 119 | /* |
| 120 | * nss_igs_register_if() |
| 121 | * Registers the IGS interface with NSS FW. |
| 122 | */ |
| 123 | struct nss_ctx_instance *nss_igs_register_if(uint32_t if_num, uint32_t type, |
| 124 | nss_igs_msg_callback_t event_callback, struct net_device *netdev, |
| 125 | uint32_t features) |
| 126 | { |
| 127 | struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.igs_handler_id]; |
| 128 | |
| 129 | nss_assert(nss_ctx); |
| 130 | nss_assert(nss_igs_verify_if_num(if_num)); |
| 131 | |
| 132 | nss_core_register_subsys_dp(nss_ctx, if_num, NULL, 0, netdev, netdev, features); |
| 133 | nss_core_set_subsys_dp_type(nss_ctx, netdev, if_num, type); |
| 134 | |
| 135 | nss_top_main.if_rx_msg_callback[if_num] = event_callback; |
| 136 | |
| 137 | nss_core_register_handler(nss_ctx, if_num, nss_igs_handler, netdev); |
Manish Verma | 30fbe18 | 2019-06-17 21:02:24 +0530 | [diff] [blame^] | 138 | nss_igs_stats_dentry_create(); |
| 139 | |
| 140 | nss_igs_stats_init(if_num, netdev); |
Manish Verma | 8a56a48 | 2019-05-20 12:46:31 +0530 | [diff] [blame] | 141 | |
| 142 | return nss_ctx; |
| 143 | } |
| 144 | EXPORT_SYMBOL(nss_igs_register_if); |
| 145 | |
| 146 | /* |
| 147 | * nss_igs_get_context() |
| 148 | * Get the IGS context. |
| 149 | */ |
| 150 | struct nss_ctx_instance *nss_igs_get_context() |
| 151 | { |
| 152 | return (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.igs_handler_id]; |
| 153 | } |
| 154 | EXPORT_SYMBOL(nss_igs_get_context); |