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 | ************************************************************************** |
| 3 | * Copyright (c) 2014, 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 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 38 | if (ncm->len > sizeof(struct nss_tunipip6_msg)) { |
| 39 | nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface); |
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) { |
| 48 | ncm->cb = (uint32_t)nss_ctx->nss_top->tunipip6_msg_callback; |
| 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; |
| 67 | ctx = nss_ctx->nss_top->if_ctx[ncm->interface]; |
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 | |
| 110 | if (ncm->len > sizeof(struct nss_tunipip6_msg)) { |
| 111 | nss_warning("%p: message length is invalid: %d", nss_ctx, ncm->len); |
| 112 | return NSS_TX_FAILURE; |
| 113 | } |
| 114 | |
| 115 | nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE); |
| 116 | if (unlikely(!nbuf)) { |
| 117 | spin_lock_bh(&nss_ctx->nss_top->stats_lock); |
| 118 | nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]++; |
| 119 | spin_unlock_bh(&nss_ctx->nss_top->stats_lock); |
| 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_tunipip6_msg *)skb_put(nbuf, sizeof(struct nss_tunipip6_msg)); |
| 128 | memcpy(nm, msg, sizeof(struct nss_tunipip6_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) { |
| 132 | dev_kfree_skb_any(nbuf); |
| 133 | nss_warning("%p: Unable to enqueue 'tun6rd message' \n", nss_ctx); |
| 134 | return NSS_TX_FAILURE; |
| 135 | } |
| 136 | |
| 137 | nss_hal_send_interrupt(nss_ctx->nmap, nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit, |
| 138 | NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE); |
| 139 | |
| 140 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]); |
| 141 | return NSS_TX_SUCCESS; |
Radhakrishna Jiguru | 5ad493d | 2013-11-25 20:17:54 +0530 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 145 | * ********************************** |
| 146 | * Register/Unregister/Miscellaneous APIs |
| 147 | * ********************************** |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 148 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 149 | |
| 150 | /* |
| 151 | * nss_register_tunipip6_if() |
| 152 | */ |
| 153 | struct nss_ctx_instance *nss_register_tunipip6_if(uint32_t if_num, |
| 154 | nss_tunipip6_callback_t tunipip6_callback, |
| 155 | nss_tunipip6_msg_callback_t event_callback, struct net_device *netdev) |
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 | 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] | 158 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 159 | nss_top_main.if_ctx[if_num] = netdev; |
| 160 | nss_top_main.if_rx_callback[if_num] = tunipip6_callback; |
| 161 | nss_top_main.tunipip6_msg_callback = event_callback; |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 162 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 163 | return (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.tunipip6_handler_id]; |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 167 | * nss_unregister_tunipip6_if() |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 168 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 169 | void nss_unregister_tunipip6_if(uint32_t if_num) |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 170 | { |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 171 | 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] | 172 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 173 | nss_top_main.if_rx_callback[if_num] = NULL; |
| 174 | nss_top_main.if_ctx[if_num] = NULL; |
| 175 | nss_top_main.tunipip6_msg_callback = NULL; |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 176 | } |
| 177 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 178 | /* |
| 179 | * nss_tunipip6_register_handler() |
| 180 | */ |
| 181 | void nss_tunipip6_register_handler() |
| 182 | { |
| 183 | nss_core_register_handler(NSS_TUNIPIP6_INTERFACE, nss_tunipip6_handler, NULL); |
| 184 | } |
Bharath M Kumar | 614bbf8 | 2013-08-31 20:18:44 +0530 | [diff] [blame] | 185 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 186 | EXPORT_SYMBOL(nss_tunipip6_tx); |
| 187 | EXPORT_SYMBOL(nss_register_tunipip6_if); |
| 188 | EXPORT_SYMBOL(nss_unregister_tunipip6_if); |