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 | ************************************************************************** |
| 3 | * Copyright (c) 2014, 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; |
| 27 | nss_tun6rd_msg_callback_t cb; |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 28 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 29 | BUG_ON(ncm->interface != NSS_TUN6RD_INTERFACE); |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +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 | 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 | if (ncm->type >= NSS_TUN6RD_MAX) { |
| 34 | 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] | 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_tun6rd_msg)) { |
| 39 | nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface); |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 40 | return; |
| 41 | } |
| 42 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 43 | /* |
| 44 | * Update the callback and app_data for NOTIFY messages, tun6rd sends all notify messages |
| 45 | * to the same callback/app_data. |
| 46 | */ |
| 47 | if (ncm->response == NSS_CMM_RESPONSE_NOTIFY) { |
| 48 | ncm->cb = (uint32_t)nss_ctx->nss_top->tun6rd_msg_callback; |
| 49 | } |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 50 | |
| 51 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 52 | * Log failures |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 53 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 54 | nss_core_log_msg_failures(nss_ctx, ncm); |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 55 | |
| 56 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 57 | * Do we have a call back |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 58 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 59 | if (!ncm->cb) { |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 60 | return; |
| 61 | } |
| 62 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 63 | /* |
| 64 | * callback |
| 65 | */ |
| 66 | cb = (nss_tun6rd_msg_callback_t)ncm->cb; |
| 67 | ctx = nss_ctx->nss_top->if_ctx[ncm->interface]; |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 68 | |
| 69 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 70 | * call 6rd tunnel callback |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 71 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 72 | if (!ctx) { |
| 73 | 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] | 74 | return; |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 75 | } |
| 76 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 77 | cb(ctx, ntm); |
| 78 | } |
| 79 | |
| 80 | |
| 81 | /* |
| 82 | * nss_tun6rd_tx() |
| 83 | * Transmit a tun6rd message to NSSFW |
| 84 | */ |
| 85 | nss_tx_status_t nss_tun6rd_tx(struct nss_ctx_instance *nss_ctx, struct nss_tun6rd_msg *msg) |
| 86 | { |
| 87 | struct nss_tun6rd_msg *nm; |
| 88 | struct nss_cmn_msg *ncm = &msg->cm; |
| 89 | struct sk_buff *nbuf; |
| 90 | int32_t status; |
| 91 | |
| 92 | NSS_VERIFY_CTX_MAGIC(nss_ctx); |
| 93 | if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) { |
| 94 | nss_warning("%p: tun6rd msg dropped as core not ready", nss_ctx); |
| 95 | return NSS_TX_FAILURE_NOT_READY; |
| 96 | } |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 97 | |
| 98 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 99 | * Sanity check the message |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 100 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 101 | if (ncm->interface != NSS_TUN6RD_INTERFACE) { |
| 102 | nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface); |
| 103 | return NSS_TX_FAILURE; |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 104 | } |
| 105 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 106 | if (ncm->type > NSS_TUN6RD_MAX) { |
| 107 | nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type); |
| 108 | return NSS_TX_FAILURE; |
| 109 | } |
| 110 | |
| 111 | if (ncm->len > sizeof(struct nss_tun6rd_msg)) { |
| 112 | nss_warning("%p: message length is invalid: %d", nss_ctx, ncm->len); |
| 113 | return NSS_TX_FAILURE; |
| 114 | } |
| 115 | |
Pamidipati, Vijay | ce98bbe | 2014-08-19 11:21:00 +0530 | [diff] [blame] | 116 | nbuf = nss_skb_alloc(NSS_NBUF_PAYLOAD_SIZE); |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 117 | if (unlikely(!nbuf)) { |
| 118 | spin_lock_bh(&nss_ctx->nss_top->stats_lock); |
| 119 | nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]++; |
| 120 | spin_unlock_bh(&nss_ctx->nss_top->stats_lock); |
| 121 | nss_warning("%p: msg dropped as command allocation failed", nss_ctx); |
| 122 | return NSS_TX_FAILURE; |
| 123 | } |
| 124 | |
| 125 | /* |
| 126 | * Copy the message to our skb |
| 127 | */ |
| 128 | nm = (struct nss_tun6rd_msg *)skb_put(nbuf, sizeof(struct nss_tun6rd_msg)); |
| 129 | memcpy(nm, msg, sizeof(struct nss_tun6rd_msg)); |
| 130 | |
| 131 | status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0); |
| 132 | if (status != NSS_CORE_STATUS_SUCCESS) { |
Pamidipati, Vijay | ce98bbe | 2014-08-19 11:21:00 +0530 | [diff] [blame] | 133 | nss_skb_free(nbuf); |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 134 | nss_warning("%p: Unable to enqueue 'tun6rd message' \n", nss_ctx); |
| 135 | return NSS_TX_FAILURE; |
| 136 | } |
| 137 | |
| 138 | nss_hal_send_interrupt(nss_ctx->nmap, nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit, |
| 139 | NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE); |
| 140 | |
| 141 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]); |
| 142 | return NSS_TX_SUCCESS; |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 146 | *********************************** |
| 147 | * Register/Unregister/Miscellaneous APIs |
| 148 | *********************************** |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 149 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 150 | |
| 151 | /* |
| 152 | * nss_register_tun6rd_if() |
| 153 | */ |
| 154 | struct nss_ctx_instance *nss_register_tun6rd_if(uint32_t if_num, |
| 155 | nss_tun6rd_callback_t tun6rd_callback, |
| 156 | nss_tun6rd_msg_callback_t event_callback, struct net_device *netdev) |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 157 | { |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 158 | nss_assert((if_num >= NSS_MAX_VIRTUAL_INTERFACES) && (if_num < NSS_MAX_NET_INTERFACES)); |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 159 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 160 | nss_top_main.if_ctx[if_num] = netdev; |
| 161 | nss_top_main.if_rx_callback[if_num] = tun6rd_callback; |
| 162 | nss_top_main.tun6rd_msg_callback = event_callback; |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 163 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 164 | 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] | 165 | } |
| 166 | |
| 167 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 168 | * nss_unregister_tun6rd_if() |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 169 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 170 | void nss_unregister_tun6rd_if(uint32_t if_num) |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 171 | { |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 172 | nss_assert((if_num >= NSS_MAX_VIRTUAL_INTERFACES) && (if_num < NSS_MAX_NET_INTERFACES)); |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 173 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 174 | nss_top_main.if_rx_callback[if_num] = NULL; |
| 175 | nss_top_main.if_ctx[if_num] = NULL; |
| 176 | nss_top_main.tun6rd_msg_callback = NULL; |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 180 | * nss_tun6rd_register_handler() |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 181 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 182 | void nss_tun6rd_register_handler() |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 183 | { |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 184 | nss_core_register_handler(NSS_TUN6RD_INTERFACE, nss_tun6rd_handler, NULL); |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 185 | } |
| 186 | |
Radhakrishna Jiguru | 5ad493d | 2013-11-25 20:17:54 +0530 | [diff] [blame] | 187 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 188 | EXPORT_SYMBOL(nss_tun6rd_tx); |
| 189 | EXPORT_SYMBOL(nss_register_tun6rd_if); |
| 190 | EXPORT_SYMBOL(nss_unregister_tun6rd_if); |