Ankit Dhanuka | 2ae20a8 | 2014-08-25 18:04:00 +0530 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Stephen Wang | 3e2dbd1 | 2018-03-14 17:28:17 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2018, The Linux Foundation. All rights reserved. |
Ankit Dhanuka | 2ae20a8 | 2014-08-25 18:04:00 +0530 | [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 | #include "nss_tx_rx_common.h" |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 18 | #include "nss_sjack_stats.h" |
Sachin Shashidhar | 1f8ccf8 | 2018-08-08 14:32:13 -0700 | [diff] [blame] | 19 | #include "nss_sjack_log.h" |
Ankit Dhanuka | 1499999 | 2014-11-12 15:35:11 +0530 | [diff] [blame] | 20 | |
| 21 | /* |
Ankit Dhanuka | 2ae20a8 | 2014-08-25 18:04:00 +0530 | [diff] [blame] | 22 | * nss_sjack_handler() |
| 23 | * Handle NSS -> HLOS messages for sjack |
| 24 | */ |
| 25 | static void nss_sjack_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, |
| 26 | __attribute__((unused))void *app_data) |
| 27 | { |
| 28 | void *ctx; |
| 29 | nss_sjack_msg_callback_t cb; |
Ankit Dhanuka | 1499999 | 2014-11-12 15:35:11 +0530 | [diff] [blame] | 30 | struct nss_sjack_msg *nsm = (struct nss_sjack_msg *)ncm; |
Ankit Dhanuka | 2ae20a8 | 2014-08-25 18:04:00 +0530 | [diff] [blame] | 31 | |
| 32 | BUG_ON(ncm->interface != NSS_SJACK_INTERFACE); |
| 33 | |
| 34 | /* |
Sachin Shashidhar | 1f8ccf8 | 2018-08-08 14:32:13 -0700 | [diff] [blame] | 35 | * Trace Messages |
| 36 | */ |
| 37 | nss_sjack_log_rx_msg(nsm); |
| 38 | |
| 39 | /* |
Ankit Dhanuka | 2ae20a8 | 2014-08-25 18:04:00 +0530 | [diff] [blame] | 40 | * Is this a valid request/response packet? |
| 41 | */ |
| 42 | if (ncm->type >= NSS_SJACK_MAX_MSG_TYPE) { |
| 43 | nss_warning("%p: received invalid message %d for sjack interface", nss_ctx, ncm->type); |
| 44 | return; |
| 45 | } |
| 46 | |
Suruchi Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 47 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_sjack_msg)) { |
| 48 | nss_warning("%p: Length of message is greater than required: %d", nss_ctx, nss_cmn_get_msg_len(ncm)); |
Ankit Dhanuka | 2ae20a8 | 2014-08-25 18:04:00 +0530 | [diff] [blame] | 49 | return; |
| 50 | } |
| 51 | |
| 52 | /* |
| 53 | * Update the callback and app_data for NOTIFY messages, sjack sends all notify messages |
| 54 | * to the same callback/app_data. |
| 55 | */ |
Suruchi Agarwal | e4ad24a | 2018-06-11 12:03:46 +0530 | [diff] [blame] | 56 | if (ncm->response == NSS_CMN_RESPONSE_NOTIFY) { |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 57 | ncm->cb = (nss_ptr_t)nss_ctx->nss_top->if_rx_msg_callback[ncm->interface]; |
Ankit Dhanuka | 2ae20a8 | 2014-08-25 18:04:00 +0530 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | /* |
| 61 | * Log failures |
| 62 | */ |
| 63 | nss_core_log_msg_failures(nss_ctx, ncm); |
| 64 | |
Ankit Dhanuka | 1499999 | 2014-11-12 15:35:11 +0530 | [diff] [blame] | 65 | switch (ncm->type) { |
| 66 | case NSS_SJACK_STATS_SYNC_MSG: |
| 67 | /* |
| 68 | * Update sjack statistics on node sync. |
| 69 | */ |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 70 | nss_sjack_stats_node_sync(nss_ctx, &nsm->msg.stats_sync); |
Ankit Dhanuka | 1499999 | 2014-11-12 15:35:11 +0530 | [diff] [blame] | 71 | break; |
| 72 | } |
| 73 | |
Ankit Dhanuka | 2ae20a8 | 2014-08-25 18:04:00 +0530 | [diff] [blame] | 74 | /* |
| 75 | * Do we have a call back |
| 76 | */ |
| 77 | if (!ncm->cb) { |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | /* |
| 82 | * callback |
| 83 | */ |
| 84 | cb = (nss_sjack_msg_callback_t)ncm->cb; |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 85 | ctx = nss_ctx->subsys_dp_register[ncm->interface].ndev; |
Ankit Dhanuka | 2ae20a8 | 2014-08-25 18:04:00 +0530 | [diff] [blame] | 86 | |
| 87 | cb(ctx, ncm); |
| 88 | } |
| 89 | |
Ankit Dhanuka | 2ae20a8 | 2014-08-25 18:04:00 +0530 | [diff] [blame] | 90 | /* |
| 91 | * nss_sjack_tx_msg() |
| 92 | * Transmit a sjack message to NSSFW |
| 93 | */ |
| 94 | nss_tx_status_t nss_sjack_tx_msg(struct nss_ctx_instance *nss_ctx, struct nss_sjack_msg *msg) |
| 95 | { |
Ankit Dhanuka | 2ae20a8 | 2014-08-25 18:04:00 +0530 | [diff] [blame] | 96 | struct nss_cmn_msg *ncm = &msg->cm; |
Ankit Dhanuka | 2ae20a8 | 2014-08-25 18:04:00 +0530 | [diff] [blame] | 97 | |
| 98 | /* |
Sachin Shashidhar | 1f8ccf8 | 2018-08-08 14:32:13 -0700 | [diff] [blame] | 99 | * Trace Messages |
| 100 | */ |
| 101 | nss_sjack_log_tx_msg(msg); |
| 102 | |
| 103 | /* |
Ankit Dhanuka | 2ae20a8 | 2014-08-25 18:04:00 +0530 | [diff] [blame] | 104 | * Sanity check the message |
| 105 | */ |
| 106 | if (ncm->interface != NSS_SJACK_INTERFACE) { |
| 107 | nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface); |
| 108 | return NSS_TX_FAILURE; |
| 109 | } |
| 110 | |
| 111 | if (ncm->type > NSS_SJACK_MAX_MSG_TYPE) { |
| 112 | nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type); |
| 113 | return NSS_TX_FAILURE; |
| 114 | } |
| 115 | |
Stephen Wang | 3e2dbd1 | 2018-03-14 17:28:17 -0700 | [diff] [blame] | 116 | return nss_core_send_cmd(nss_ctx, msg, sizeof(*msg), NSS_NBUF_PAYLOAD_SIZE); |
Ankit Dhanuka | 2ae20a8 | 2014-08-25 18:04:00 +0530 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | /* |
| 120 | * nss_sjack_register_if() |
| 121 | */ |
| 122 | struct nss_ctx_instance *nss_sjack_register_if(uint32_t if_num, struct net_device *netdev, |
| 123 | nss_sjack_msg_callback_t event_callback) |
| 124 | { |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 125 | struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.sjack_handler_id]; |
| 126 | |
| 127 | nss_assert(nss_ctx); |
Ankit Dhanuka | 2ae20a8 | 2014-08-25 18:04:00 +0530 | [diff] [blame] | 128 | nss_assert(if_num == NSS_SJACK_INTERFACE); |
| 129 | |
Jackson Bockus | 7ca70ec | 2017-07-17 13:47:29 -0700 | [diff] [blame] | 130 | nss_core_register_subsys_dp(nss_ctx, if_num, NULL, NULL, NULL, netdev, 0); |
Sundarajan Srinivasan | 7037484 | 2014-11-19 15:22:52 -0800 | [diff] [blame] | 131 | |
Ankit Dhanuka | 2ae20a8 | 2014-08-25 18:04:00 +0530 | [diff] [blame] | 132 | nss_top_main.if_rx_msg_callback[if_num] = event_callback; |
| 133 | |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 134 | return nss_ctx; |
Ankit Dhanuka | 2ae20a8 | 2014-08-25 18:04:00 +0530 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | /* |
| 138 | * nss_sjack_unregister_if() |
| 139 | */ |
| 140 | void nss_sjack_unregister_if(uint32_t if_num) |
| 141 | { |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 142 | struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.sjack_handler_id]; |
| 143 | |
| 144 | nss_assert(nss_ctx); |
Ankit Dhanuka | 2ae20a8 | 2014-08-25 18:04:00 +0530 | [diff] [blame] | 145 | nss_assert(if_num == NSS_SJACK_INTERFACE); |
| 146 | |
Jackson Bockus | 7ca70ec | 2017-07-17 13:47:29 -0700 | [diff] [blame] | 147 | nss_core_unregister_subsys_dp(nss_ctx, if_num); |
Ankit Dhanuka | 2ae20a8 | 2014-08-25 18:04:00 +0530 | [diff] [blame] | 148 | nss_top_main.if_rx_msg_callback[if_num] = NULL; |
| 149 | |
| 150 | return; |
| 151 | } |
| 152 | |
| 153 | /* |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 154 | * nss_sjack_get_context() |
| 155 | * get NSS context instance for sjack |
| 156 | */ |
| 157 | struct nss_ctx_instance *nss_sjack_get_context(void) |
| 158 | { |
| 159 | return &nss_top_main.nss[nss_top_main.sjack_handler_id]; |
| 160 | } |
| 161 | EXPORT_SYMBOL(nss_sjack_get_context); |
| 162 | |
| 163 | /* |
Ankit Dhanuka | 2ae20a8 | 2014-08-25 18:04:00 +0530 | [diff] [blame] | 164 | * nss_sjack_register_handler() |
| 165 | * Registering handler for sending msg to sjack node on NSS. |
| 166 | */ |
| 167 | void nss_sjack_register_handler(void) |
| 168 | { |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 169 | struct nss_ctx_instance *nss_ctx = nss_sjack_get_context(); |
| 170 | |
| 171 | nss_core_register_handler(nss_ctx, NSS_SJACK_INTERFACE, nss_sjack_handler, NULL); |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 172 | |
| 173 | nss_sjack_stats_dentry_create(); |
Ankit Dhanuka | 2ae20a8 | 2014-08-25 18:04:00 +0530 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | EXPORT_SYMBOL(nss_sjack_register_if); |
| 177 | EXPORT_SYMBOL(nss_sjack_unregister_if); |
| 178 | EXPORT_SYMBOL(nss_sjack_tx_msg); |