Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +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 | 614bbf8 | 2013-08-31 20:18:44 +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 | 614bbf8 | 2013-08-31 20:18:44 +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 | 614bbf8 | 2013-08-31 20:18:44 +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 | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 18 | |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 19 | /* |
Ken Zhu | 648cf3d | 2017-10-06 17:44:53 -0700 | [diff] [blame] | 20 | * nss_tunipip6_verify_if_num |
| 21 | * Verify the interface is a valid interface |
| 22 | */ |
| 23 | static bool nss_tunipip6_verify_if_num(uint32_t if_num) |
| 24 | { |
| 25 | return nss_dynamic_interface_get_type(nss_tunipip6_get_context(), if_num) == NSS_DYNAMIC_INTERFACE_TYPE_TUNIPIP6; |
| 26 | } |
| 27 | |
| 28 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 29 | * nss_tunipip6_handler() |
Sol Kavy | 359ef15 | 2014-04-04 11:55:24 -0700 | [diff] [blame] | 30 | * Handle NSS -> HLOS messages for 6rd tunnel |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 31 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 32 | static void nss_tunipip6_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data) |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 33 | { |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 34 | struct nss_tunipip6_msg *ntm = (struct nss_tunipip6_msg *)ncm; |
| 35 | void *ctx; |
| 36 | nss_tunipip6_msg_callback_t cb; |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 37 | |
Ken Zhu | 648cf3d | 2017-10-06 17:44:53 -0700 | [diff] [blame] | 38 | BUG_ON(!nss_tunipip6_verify_if_num(ncm->interface)); |
| 39 | |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 40 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 41 | * Is this a valid request/response packet? |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 42 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 43 | if (ncm->type >= NSS_TUNIPIP6_MAX) { |
| 44 | nss_warning("%p: received invalid message %d for DS-Lite interface", nss_ctx, ncm->type); |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 45 | return; |
| 46 | } |
| 47 | |
Suruchi Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 48 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_tunipip6_msg)) { |
| 49 | nss_warning("%p: Length of message is greater than required: %d", nss_ctx, nss_cmn_get_msg_len(ncm)); |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 50 | return; |
| 51 | } |
| 52 | |
| 53 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 54 | * Update the callback and app_data for NOTIFY messages, tun6rd sends all notify messages |
| 55 | * to the same callback/app_data. |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 56 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 57 | if (ncm->response == NSS_CMM_RESPONSE_NOTIFY) { |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 58 | ncm->cb = (nss_ptr_t)nss_ctx->nss_top->tunipip6_msg_callback; |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | /* |
| 62 | * Log failures |
| 63 | */ |
| 64 | nss_core_log_msg_failures(nss_ctx, ncm); |
| 65 | |
| 66 | /* |
| 67 | * Do we have a call back |
| 68 | */ |
| 69 | if (!ncm->cb) { |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 70 | return; |
| 71 | } |
| 72 | |
| 73 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 74 | * callback |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 75 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 76 | cb = (nss_tunipip6_msg_callback_t)ncm->cb; |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 77 | ctx = nss_ctx->subsys_dp_register[ncm->interface].ndev; |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 78 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 79 | /* |
| 80 | * call ipip6 tunnel callback |
| 81 | */ |
| 82 | if (!ctx) { |
| 83 | nss_warning("%p: Event received for DS-Lite tunnel interface %d before registration", nss_ctx, ncm->interface); |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 84 | return; |
| 85 | } |
| 86 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 87 | cb(ctx, ntm); |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 91 | * nss_tunipip6_tx() |
| 92 | * Transmit a tun6rd message to NSSFW |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 93 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 94 | nss_tx_status_t nss_tunipip6_tx(struct nss_ctx_instance *nss_ctx, struct nss_tunipip6_msg *msg) |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 95 | { |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 96 | struct nss_tunipip6_msg *nm; |
| 97 | struct nss_cmn_msg *ncm = &msg->cm; |
| 98 | struct sk_buff *nbuf; |
| 99 | int32_t status; |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 100 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 101 | NSS_VERIFY_CTX_MAGIC(nss_ctx); |
| 102 | if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) { |
| 103 | nss_warning("%p: tun6rd msg dropped as core not ready", nss_ctx); |
| 104 | return NSS_TX_FAILURE_NOT_READY; |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 105 | } |
| 106 | |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 107 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 108 | * Sanity check the message |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 109 | */ |
Ken Zhu | 648cf3d | 2017-10-06 17:44:53 -0700 | [diff] [blame] | 110 | if (!nss_tunipip6_verify_if_num(ncm->interface)) { |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 111 | nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface); |
| 112 | return NSS_TX_FAILURE; |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 113 | } |
| 114 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 115 | if (ncm->type > NSS_TUNIPIP6_MAX) { |
| 116 | nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type); |
| 117 | return NSS_TX_FAILURE; |
Radhakrishna Jiguru | 5ad493d | 2013-11-25 20:17:54 +0530 | [diff] [blame] | 118 | } |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 119 | |
Suruchi Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 120 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_tunipip6_msg)) { |
| 121 | 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] | 122 | return NSS_TX_FAILURE; |
| 123 | } |
| 124 | |
Pamidipati, Vijay | b6e3884 | 2014-09-16 10:26:05 +0530 | [diff] [blame] | 125 | nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE); |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 126 | if (unlikely(!nbuf)) { |
Sundarajan Srinivasan | 62fee7e | 2015-01-22 11:13:10 -0800 | [diff] [blame] | 127 | 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] | 128 | nss_warning("%p: msg dropped as command allocation failed", nss_ctx); |
| 129 | return NSS_TX_FAILURE; |
| 130 | } |
| 131 | |
| 132 | /* |
| 133 | * Copy the message to our skb |
| 134 | */ |
| 135 | nm = (struct nss_tunipip6_msg *)skb_put(nbuf, sizeof(struct nss_tunipip6_msg)); |
| 136 | memcpy(nm, msg, sizeof(struct nss_tunipip6_msg)); |
| 137 | |
| 138 | status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0); |
| 139 | if (status != NSS_CORE_STATUS_SUCCESS) { |
Pamidipati, Vijay | b6e3884 | 2014-09-16 10:26:05 +0530 | [diff] [blame] | 140 | dev_kfree_skb_any(nbuf); |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 141 | nss_warning("%p: Unable to enqueue 'tun6rd message' \n", nss_ctx); |
| 142 | return NSS_TX_FAILURE; |
| 143 | } |
| 144 | |
Stephen Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 145 | 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] | 146 | |
| 147 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]); |
| 148 | return NSS_TX_SUCCESS; |
Radhakrishna Jiguru | 5ad493d | 2013-11-25 20:17:54 +0530 | [diff] [blame] | 149 | } |
Ken Zhu | 648cf3d | 2017-10-06 17:44:53 -0700 | [diff] [blame] | 150 | EXPORT_SYMBOL(nss_tunipip6_tx); |
Radhakrishna Jiguru | 5ad493d | 2013-11-25 20:17:54 +0530 | [diff] [blame] | 151 | |
| 152 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 153 | * ********************************** |
| 154 | * Register/Unregister/Miscellaneous APIs |
| 155 | * ********************************** |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 156 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 157 | |
| 158 | /* |
| 159 | * nss_register_tunipip6_if() |
| 160 | */ |
| 161 | struct nss_ctx_instance *nss_register_tunipip6_if(uint32_t if_num, |
| 162 | nss_tunipip6_callback_t tunipip6_callback, |
Sundarajan Srinivasan | 7037484 | 2014-11-19 15:22:52 -0800 | [diff] [blame] | 163 | nss_tunipip6_msg_callback_t event_callback, |
| 164 | struct net_device *netdev, |
| 165 | uint32_t features) |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 166 | { |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 167 | struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.tunipip6_handler_id]; |
| 168 | |
| 169 | nss_assert(nss_ctx); |
Ken Zhu | 648cf3d | 2017-10-06 17:44:53 -0700 | [diff] [blame] | 170 | nss_assert(nss_tunipip6_verify_if_num(if_num)); |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 171 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 172 | nss_top_main.tunipip6_msg_callback = event_callback; |
Jackson Bockus | 7ca70ec | 2017-07-17 13:47:29 -0700 | [diff] [blame] | 173 | nss_core_register_subsys_dp(nss_ctx, if_num, tunipip6_callback, NULL, NULL, netdev, features); |
Ken Zhu | 648cf3d | 2017-10-06 17:44:53 -0700 | [diff] [blame] | 174 | nss_core_register_handler(nss_ctx, if_num, nss_tunipip6_handler, NULL); |
Sundarajan Srinivasan | 7037484 | 2014-11-19 15:22:52 -0800 | [diff] [blame] | 175 | |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 176 | return nss_ctx; |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 177 | } |
Ken Zhu | 648cf3d | 2017-10-06 17:44:53 -0700 | [diff] [blame] | 178 | EXPORT_SYMBOL(nss_register_tunipip6_if); |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 179 | |
| 180 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 181 | * nss_unregister_tunipip6_if() |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 182 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 183 | void nss_unregister_tunipip6_if(uint32_t if_num) |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 184 | { |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 185 | struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.tunipip6_handler_id]; |
| 186 | |
| 187 | nss_assert(nss_ctx); |
Ken Zhu | 648cf3d | 2017-10-06 17:44:53 -0700 | [diff] [blame] | 188 | nss_assert(nss_tunipip6_verify_if_num(if_num)); |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 189 | |
Jackson Bockus | 7ca70ec | 2017-07-17 13:47:29 -0700 | [diff] [blame] | 190 | nss_core_unregister_subsys_dp(nss_ctx, if_num); |
| 191 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 192 | nss_top_main.tunipip6_msg_callback = NULL; |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 193 | } |
Ken Zhu | 648cf3d | 2017-10-06 17:44:53 -0700 | [diff] [blame] | 194 | EXPORT_SYMBOL(nss_unregister_tunipip6_if); |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 195 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 196 | /* |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 197 | * nss_tunipip6_get_context() |
| 198 | */ |
| 199 | struct nss_ctx_instance *nss_tunipip6_get_context(void) |
| 200 | { |
| 201 | return (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.tunipip6_handler_id]; |
| 202 | } |
Ken Zhu | 648cf3d | 2017-10-06 17:44:53 -0700 | [diff] [blame] | 203 | EXPORT_SYMBOL(nss_tunipip6_get_context); |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 204 | |
| 205 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 206 | * nss_tunipip6_register_handler() |
| 207 | */ |
| 208 | void nss_tunipip6_register_handler() |
| 209 | { |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 210 | struct nss_ctx_instance *nss_ctx = nss_tunipip6_get_context(); |
| 211 | |
| 212 | nss_core_register_handler(nss_ctx, NSS_TUNIPIP6_INTERFACE, nss_tunipip6_handler, NULL); |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 213 | } |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 214 | |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 215 | /* |
| 216 | * nss_tunipip6_msg_init() |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 217 | * Initialize nss_tunipip6 msg. |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 218 | */ |
| 219 | void nss_tunipip6_msg_init(struct nss_tunipip6_msg *ntm, uint16_t if_num, uint32_t type, uint32_t len, void *cb, void *app_data) |
| 220 | { |
| 221 | nss_cmn_msg_init(&ntm->cm, if_num, type, len, cb, app_data); |
| 222 | } |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 223 | EXPORT_SYMBOL(nss_tunipip6_msg_init); |