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