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 | |
Manish Verma | 2f3324e | 2019-10-14 21:30:50 +0530 | [diff] [blame] | 17 | #ifdef CONFIG_NET_CLS_ACT |
| 18 | #include <linux/tc_act/tc_nss_mirred.h> |
| 19 | #endif |
| 20 | |
Manish Verma | 8a56a48 | 2019-05-20 12:46:31 +0530 | [diff] [blame] | 21 | #include "nss_tx_rx_common.h" |
Manish Verma | 30fbe18 | 2019-06-17 21:02:24 +0530 | [diff] [blame] | 22 | #include "nss_igs_stats.h" |
Manish Verma | 8a56a48 | 2019-05-20 12:46:31 +0530 | [diff] [blame] | 23 | |
Manish Verma | 2f3324e | 2019-10-14 21:30:50 +0530 | [diff] [blame] | 24 | static struct module *nss_igs_module; |
| 25 | |
Manish Verma | 8a56a48 | 2019-05-20 12:46:31 +0530 | [diff] [blame] | 26 | /* |
| 27 | * nss_igs_verify_if_num() |
| 28 | * Verify interface number passed to us. |
| 29 | */ |
| 30 | bool nss_igs_verify_if_num(uint32_t if_num) |
| 31 | { |
| 32 | enum nss_dynamic_interface_type if_type; |
| 33 | |
| 34 | if_type = nss_dynamic_interface_get_type(nss_igs_get_context(), if_num); |
| 35 | |
| 36 | if (if_type == NSS_DYNAMIC_INTERFACE_TYPE_IGS) { |
| 37 | return true; |
| 38 | } |
| 39 | return false; |
| 40 | } |
| 41 | EXPORT_SYMBOL(nss_igs_verify_if_num); |
| 42 | |
| 43 | /* |
| 44 | * nss_igs_handler() |
| 45 | * Handle NSS -> HLOS messages for igs device |
| 46 | */ |
| 47 | static void nss_igs_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, |
| 48 | void *app_data) |
| 49 | { |
| 50 | void *ctx; |
| 51 | nss_igs_msg_callback_t cb; |
| 52 | |
| 53 | NSS_VERIFY_CTX_MAGIC(nss_ctx); |
| 54 | BUG_ON(!nss_igs_verify_if_num(ncm->interface)); |
| 55 | |
| 56 | /* |
| 57 | * Is this a valid request/response packet? |
| 58 | */ |
| 59 | if (ncm->type >= NSS_IGS_MSG_MAX) { |
| 60 | nss_warning("%p: received invalid message %d for IGS interface", nss_ctx, ncm->type); |
| 61 | return; |
| 62 | } |
| 63 | |
| 64 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_igs_msg)) { |
| 65 | nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface); |
| 66 | return; |
| 67 | } |
| 68 | |
| 69 | switch (ncm->type) { |
| 70 | case NSS_IGS_MSG_SYNC_STATS: |
Manish Verma | 30fbe18 | 2019-06-17 21:02:24 +0530 | [diff] [blame] | 71 | /* |
| 72 | * Debug stats embedded in stats msg. |
| 73 | */ |
| 74 | nss_igs_stats_sync(nss_ctx, ncm, ncm->interface); |
Manish Verma | 8a56a48 | 2019-05-20 12:46:31 +0530 | [diff] [blame] | 75 | break; |
| 76 | } |
| 77 | |
| 78 | /* |
| 79 | * Update the callback and app_data for NOTIFY messages |
| 80 | */ |
| 81 | if (ncm->response == NSS_CMN_RESPONSE_NOTIFY) { |
| 82 | ncm->cb = (nss_ptr_t)nss_top_main.if_rx_msg_callback[ncm->interface]; |
| 83 | ncm->app_data = (nss_ptr_t)app_data; |
| 84 | } |
| 85 | |
| 86 | /* |
| 87 | * callback |
| 88 | */ |
| 89 | cb = (nss_igs_msg_callback_t)ncm->cb; |
| 90 | ctx = (void *)ncm->app_data; |
| 91 | |
| 92 | /* |
| 93 | * call igs callback |
| 94 | */ |
| 95 | if (!cb) { |
| 96 | nss_warning("%p: No callback for igs interface %d", |
| 97 | nss_ctx, ncm->interface); |
| 98 | return; |
| 99 | } |
| 100 | |
| 101 | cb(ctx, ncm); |
| 102 | } |
| 103 | |
| 104 | /* |
| 105 | * nss_igs_unregister_if() |
| 106 | * Un-registers IGS interface from the NSS firmware. |
| 107 | */ |
| 108 | void nss_igs_unregister_if(uint32_t if_num) |
| 109 | { |
| 110 | struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.igs_handler_id]; |
| 111 | |
| 112 | nss_assert(nss_ctx); |
| 113 | nss_assert(nss_igs_verify_if_num(if_num)); |
| 114 | |
| 115 | nss_core_unregister_subsys_dp(nss_ctx, if_num); |
| 116 | |
| 117 | nss_top_main.if_rx_msg_callback[if_num] = NULL; |
| 118 | |
| 119 | nss_core_unregister_handler(nss_ctx, if_num); |
Manish Verma | 30fbe18 | 2019-06-17 21:02:24 +0530 | [diff] [blame] | 120 | |
| 121 | nss_igs_stats_reset(if_num); |
Manish Verma | 8a56a48 | 2019-05-20 12:46:31 +0530 | [diff] [blame] | 122 | } |
| 123 | EXPORT_SYMBOL(nss_igs_unregister_if); |
| 124 | |
| 125 | /* |
| 126 | * nss_igs_register_if() |
| 127 | * Registers the IGS interface with NSS FW. |
| 128 | */ |
| 129 | struct nss_ctx_instance *nss_igs_register_if(uint32_t if_num, uint32_t type, |
| 130 | nss_igs_msg_callback_t event_callback, struct net_device *netdev, |
| 131 | uint32_t features) |
| 132 | { |
| 133 | struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.igs_handler_id]; |
| 134 | |
| 135 | nss_assert(nss_ctx); |
| 136 | nss_assert(nss_igs_verify_if_num(if_num)); |
| 137 | |
| 138 | nss_core_register_subsys_dp(nss_ctx, if_num, NULL, 0, netdev, netdev, features); |
| 139 | nss_core_set_subsys_dp_type(nss_ctx, netdev, if_num, type); |
| 140 | |
| 141 | nss_top_main.if_rx_msg_callback[if_num] = event_callback; |
| 142 | |
| 143 | nss_core_register_handler(nss_ctx, if_num, nss_igs_handler, netdev); |
Manish Verma | 30fbe18 | 2019-06-17 21:02:24 +0530 | [diff] [blame] | 144 | nss_igs_stats_dentry_create(); |
| 145 | |
| 146 | nss_igs_stats_init(if_num, netdev); |
Manish Verma | 8a56a48 | 2019-05-20 12:46:31 +0530 | [diff] [blame] | 147 | |
| 148 | return nss_ctx; |
| 149 | } |
| 150 | EXPORT_SYMBOL(nss_igs_register_if); |
| 151 | |
| 152 | /* |
| 153 | * nss_igs_get_context() |
| 154 | * Get the IGS context. |
| 155 | */ |
| 156 | struct nss_ctx_instance *nss_igs_get_context() |
| 157 | { |
| 158 | return (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.igs_handler_id]; |
| 159 | } |
| 160 | EXPORT_SYMBOL(nss_igs_get_context); |
Manish Verma | 2f3324e | 2019-10-14 21:30:50 +0530 | [diff] [blame] | 161 | |
| 162 | #ifdef CONFIG_NET_CLS_ACT |
| 163 | /* |
| 164 | * nss_igs_module_save() |
| 165 | * Save the ingress shaping module reference. |
| 166 | */ |
| 167 | void nss_igs_module_save(struct tc_action_ops *act, struct module *module) |
| 168 | { |
| 169 | nss_assert(act); |
| 170 | nss_assert(act->type == TCA_ACT_MIRRED_NSS); |
| 171 | |
| 172 | nss_igs_module = module; |
| 173 | } |
| 174 | EXPORT_SYMBOL(nss_igs_module_save); |
| 175 | #endif |
| 176 | |
| 177 | /* |
| 178 | * nss_igs_module_get() |
| 179 | * Get the ingress shaping module reference. |
| 180 | */ |
| 181 | bool nss_igs_module_get() |
| 182 | { |
| 183 | nss_assert(nss_igs_module); |
| 184 | return try_module_get(nss_igs_module); |
| 185 | } |
| 186 | EXPORT_SYMBOL(nss_igs_module_get); |
| 187 | |
| 188 | /* |
| 189 | * nss_igs_module_put() |
| 190 | * Release the ingress shaping module reference. |
| 191 | */ |
| 192 | void nss_igs_module_put() |
| 193 | { |
| 194 | nss_assert(nss_igs_module); |
| 195 | module_put(nss_igs_module); |
| 196 | } |
| 197 | EXPORT_SYMBOL(nss_igs_module_put); |