Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 1 | /* |
Murat Sezgin | 84ca651 | 2014-04-14 13:57:24 -0700 | [diff] [blame] | 2 | ************************************************************************** |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame^] | 3 | * Copyright (c) 2014-2017, The Linux Foundation. All rights reserved. |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +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 |
Murat Sezgin | 84ca651 | 2014-04-14 13:57:24 -0700 | [diff] [blame] | 6 | * above copyright notice and this permission notice appear in all copies. |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 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. |
Murat Sezgin | 84ca651 | 2014-04-14 13:57:24 -0700 | [diff] [blame] | 14 | ************************************************************************** |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 15 | */ |
| 16 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 17 | #include "nss_tx_rx_common.h" |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 18 | |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 19 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 20 | * nss_tun6rd_handler() |
| 21 | * Handle NSS -> HLOS messages for 6rd tunnel |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 22 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 23 | static void nss_tun6rd_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data) |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 24 | { |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 25 | struct nss_tun6rd_msg *ntm = (struct nss_tun6rd_msg *)ncm; |
| 26 | void *ctx; |
Zhu Ken | 0308242 | 2014-08-11 15:21:42 +0800 | [diff] [blame] | 27 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 28 | nss_tun6rd_msg_callback_t cb; |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 29 | |
Zhu Ken | 0308242 | 2014-08-11 15:21:42 +0800 | [diff] [blame] | 30 | BUG_ON(!nss_is_dynamic_interface(ncm->interface)); |
| 31 | |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 32 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 33 | * Is this a valid request/response packet? |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 34 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 35 | if (ncm->type >= NSS_TUN6RD_MAX) { |
| 36 | nss_warning("%p: received invalid message %d for Tun6RD interface", nss_ctx, ncm->type); |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 37 | return; |
| 38 | } |
| 39 | |
Suruchi Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 40 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_tun6rd_msg)) { |
| 41 | nss_warning("%p: Length of message is greater than required: %d", nss_ctx, nss_cmn_get_msg_len(ncm)); |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 42 | return; |
| 43 | } |
| 44 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 45 | /* |
| 46 | * Update the callback and app_data for NOTIFY messages, tun6rd sends all notify messages |
| 47 | * to the same callback/app_data. |
| 48 | */ |
| 49 | if (ncm->response == NSS_CMM_RESPONSE_NOTIFY) { |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame^] | 50 | ncm->cb = (nss_ptr_t)nss_ctx->nss_top->tun6rd_msg_callback; |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 51 | } |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 52 | |
| 53 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 54 | * Log failures |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 55 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 56 | nss_core_log_msg_failures(nss_ctx, ncm); |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 57 | |
| 58 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 59 | * Do we have a call back |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 60 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 61 | if (!ncm->cb) { |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 62 | return; |
| 63 | } |
| 64 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 65 | /* |
| 66 | * callback |
| 67 | */ |
| 68 | cb = (nss_tun6rd_msg_callback_t)ncm->cb; |
Sundarajan Srinivasan | 7037484 | 2014-11-19 15:22:52 -0800 | [diff] [blame] | 69 | ctx = nss_ctx->nss_top->subsys_dp_register[ncm->interface].ndev; |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 70 | |
| 71 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 72 | * call 6rd tunnel callback |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 73 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 74 | if (!ctx) { |
| 75 | nss_warning("%p: Event received for 6rd tunnel interface %d before registration", nss_ctx, ncm->interface); |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 76 | return; |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 77 | } |
| 78 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 79 | cb(ctx, ntm); |
| 80 | } |
| 81 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 82 | /* |
| 83 | * nss_tun6rd_tx() |
| 84 | * Transmit a tun6rd message to NSSFW |
| 85 | */ |
| 86 | nss_tx_status_t nss_tun6rd_tx(struct nss_ctx_instance *nss_ctx, struct nss_tun6rd_msg *msg) |
| 87 | { |
| 88 | struct nss_tun6rd_msg *nm; |
| 89 | struct nss_cmn_msg *ncm = &msg->cm; |
| 90 | struct sk_buff *nbuf; |
| 91 | int32_t status; |
| 92 | |
| 93 | NSS_VERIFY_CTX_MAGIC(nss_ctx); |
| 94 | if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) { |
| 95 | nss_warning("%p: tun6rd msg dropped as core not ready", nss_ctx); |
| 96 | return NSS_TX_FAILURE_NOT_READY; |
| 97 | } |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 98 | |
| 99 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 100 | * Sanity check the message |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 101 | */ |
Zhu Ken | 0308242 | 2014-08-11 15:21:42 +0800 | [diff] [blame] | 102 | if (!nss_is_dynamic_interface(ncm->interface)) { |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 103 | nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface); |
| 104 | return NSS_TX_FAILURE; |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 105 | } |
| 106 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 107 | if (ncm->type > NSS_TUN6RD_MAX) { |
| 108 | nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type); |
| 109 | return NSS_TX_FAILURE; |
| 110 | } |
| 111 | |
Suruchi Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 112 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_tun6rd_msg)) { |
| 113 | nss_warning("%p: message length is invalid: %d", nss_ctx, nss_cmn_get_msg_len(ncm)); |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 114 | return NSS_TX_FAILURE; |
| 115 | } |
| 116 | |
Pamidipati, Vijay | b6e3884 | 2014-09-16 10:26:05 +0530 | [diff] [blame] | 117 | nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE); |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 118 | if (unlikely(!nbuf)) { |
Sundarajan Srinivasan | 62fee7e | 2015-01-22 11:13:10 -0800 | [diff] [blame] | 119 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]); |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 120 | nss_warning("%p: msg dropped as command allocation failed", nss_ctx); |
| 121 | return NSS_TX_FAILURE; |
| 122 | } |
| 123 | |
| 124 | /* |
| 125 | * Copy the message to our skb |
| 126 | */ |
| 127 | nm = (struct nss_tun6rd_msg *)skb_put(nbuf, sizeof(struct nss_tun6rd_msg)); |
| 128 | memcpy(nm, msg, sizeof(struct nss_tun6rd_msg)); |
| 129 | |
| 130 | status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0); |
| 131 | if (status != NSS_CORE_STATUS_SUCCESS) { |
Pamidipati, Vijay | b6e3884 | 2014-09-16 10:26:05 +0530 | [diff] [blame] | 132 | dev_kfree_skb_any(nbuf); |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 133 | nss_warning("%p: Unable to enqueue 'tun6rd message' \n", nss_ctx); |
| 134 | return NSS_TX_FAILURE; |
| 135 | } |
| 136 | |
Stephen Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 137 | nss_hal_send_interrupt(nss_ctx, NSS_H2N_INTR_DATA_COMMAND_QUEUE); |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 138 | |
| 139 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]); |
| 140 | return NSS_TX_SUCCESS; |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 144 | *********************************** |
| 145 | * Register/Unregister/Miscellaneous APIs |
| 146 | *********************************** |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 147 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 148 | |
| 149 | /* |
| 150 | * nss_register_tun6rd_if() |
| 151 | */ |
Zhu Ken | 0308242 | 2014-08-11 15:21:42 +0800 | [diff] [blame] | 152 | struct nss_ctx_instance *nss_register_tun6rd_if(uint32_t if_num, nss_tun6rd_callback_t tun6rd_callback, |
Sundarajan Srinivasan | 7037484 | 2014-11-19 15:22:52 -0800 | [diff] [blame] | 153 | nss_tun6rd_msg_callback_t event_callback, struct net_device *netdev, uint32_t features) |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 154 | { |
Zhu Ken | 0308242 | 2014-08-11 15:21:42 +0800 | [diff] [blame] | 155 | nss_assert((if_num >= NSS_DYNAMIC_IF_START) && (if_num < NSS_SPECIAL_IF_START)); |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 156 | |
Sundarajan Srinivasan | 7037484 | 2014-11-19 15:22:52 -0800 | [diff] [blame] | 157 | nss_top_main.subsys_dp_register[if_num].ndev = netdev; |
| 158 | nss_top_main.subsys_dp_register[if_num].cb = tun6rd_callback; |
| 159 | nss_top_main.subsys_dp_register[if_num].app_data = NULL; |
| 160 | nss_top_main.subsys_dp_register[if_num].features = features; |
| 161 | |
Zhu Ken | 0308242 | 2014-08-11 15:21:42 +0800 | [diff] [blame] | 162 | nss_top_main.tun6rd_msg_callback = event_callback; |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 163 | |
Zhu Ken | 0308242 | 2014-08-11 15:21:42 +0800 | [diff] [blame] | 164 | nss_core_register_handler(if_num, nss_tun6rd_handler, NULL); |
| 165 | |
| 166 | return (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.tun6rd_handler_id]; |
| 167 | } |
| 168 | |
| 169 | /* |
| 170 | * nss_get_tun6rd_context() |
| 171 | */ |
| 172 | struct nss_ctx_instance * nss_tun6rd_get_context() |
| 173 | { |
| 174 | return (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.tun6rd_handler_id]; |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 178 | * nss_unregister_tun6rd_if() |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 179 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 180 | void nss_unregister_tun6rd_if(uint32_t if_num) |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 181 | { |
Sakthi Vignesh Radhakrishnan | 7a8fbe9 | 2015-02-23 16:23:29 -0800 | [diff] [blame] | 182 | nss_assert(nss_is_dynamic_interface(if_num)); |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 183 | |
Sundarajan Srinivasan | 7037484 | 2014-11-19 15:22:52 -0800 | [diff] [blame] | 184 | nss_top_main.subsys_dp_register[if_num].ndev = NULL; |
| 185 | nss_top_main.subsys_dp_register[if_num].cb = NULL; |
| 186 | nss_top_main.subsys_dp_register[if_num].app_data = NULL; |
| 187 | nss_top_main.subsys_dp_register[if_num].features = 0; |
| 188 | |
Zhu Ken | 0308242 | 2014-08-11 15:21:42 +0800 | [diff] [blame] | 189 | nss_top_main.tun6rd_msg_callback = NULL; |
| 190 | |
| 191 | nss_core_unregister_handler(if_num); |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 192 | } |
| 193 | |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 194 | /* |
| 195 | * nss_tun6rd_msg_init() |
| 196 | * Initialize nss_tun6rd msg. |
| 197 | */ |
| 198 | void nss_tun6rd_msg_init(struct nss_tun6rd_msg *ncm, uint16_t if_num, uint32_t type, uint32_t len, void *cb, void *app_data) |
| 199 | { |
| 200 | nss_cmn_msg_init(&ncm->cm, if_num, type, len, cb, app_data); |
| 201 | } |
| 202 | |
Zhu Ken | 0308242 | 2014-08-11 15:21:42 +0800 | [diff] [blame] | 203 | EXPORT_SYMBOL(nss_tun6rd_get_context); |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 204 | EXPORT_SYMBOL(nss_tun6rd_tx); |
| 205 | EXPORT_SYMBOL(nss_register_tun6rd_if); |
| 206 | EXPORT_SYMBOL(nss_unregister_tun6rd_if); |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 207 | EXPORT_SYMBOL(nss_tun6rd_msg_init); |