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