Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 1 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame^] | 2 | * ************************************************************************** |
| 3 | * Copyright (c) 2014, Qualcomm Atheros, Inc. |
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 |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [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. |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [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 | #include "nss_api_if.h" |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 19 | |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 20 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame^] | 21 | * nss_tun6rd_handler() |
| 22 | * Handle NSS -> HLOS messages for 6rd tunnel |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 23 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame^] | 24 | 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] | 25 | { |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame^] | 26 | struct nss_tun6rd_msg *ntm = (struct nss_tun6rd_msg *)ncm; |
| 27 | void *ctx; |
| 28 | nss_tun6rd_msg_callback_t cb; |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 29 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame^] | 30 | BUG_ON(ncm->interface != NSS_TUN6RD_INTERFACE); |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 31 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame^] | 32 | * Is this a valid request/response packet? |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 33 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame^] | 34 | if (ncm->type >= NSS_TUN6RD_MAX) { |
| 35 | 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] | 36 | return; |
| 37 | } |
| 38 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame^] | 39 | if (ncm->len > sizeof(struct nss_tun6rd_msg)) { |
| 40 | 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] | 41 | return; |
| 42 | } |
| 43 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame^] | 44 | /* |
| 45 | * Update the callback and app_data for NOTIFY messages, tun6rd sends all notify messages |
| 46 | * to the same callback/app_data. |
| 47 | */ |
| 48 | if (ncm->response == NSS_CMM_RESPONSE_NOTIFY) { |
| 49 | ncm->cb = (uint32_t)nss_ctx->nss_top->tun6rd_msg_callback; |
| 50 | } |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 51 | |
| 52 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame^] | 53 | * Log failures |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 54 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame^] | 55 | nss_core_log_msg_failures(nss_ctx, ncm); |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 56 | |
| 57 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame^] | 58 | * Do we have a call back |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 59 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame^] | 60 | if (!ncm->cb) { |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 61 | return; |
| 62 | } |
| 63 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame^] | 64 | /* |
| 65 | * callback |
| 66 | */ |
| 67 | cb = (nss_tun6rd_msg_callback_t)ncm->cb; |
| 68 | ctx = nss_ctx->nss_top->if_ctx[ncm->interface]; |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 69 | |
| 70 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame^] | 71 | * call 6rd tunnel callback |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 72 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame^] | 73 | if (!ctx) { |
| 74 | 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] | 75 | return; |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 76 | } |
| 77 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame^] | 78 | cb(ctx, ntm); |
| 79 | } |
| 80 | |
| 81 | |
| 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 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame^] | 102 | if (ncm->interface != NSS_TUN6RD_INTERFACE) { |
| 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 | |
| 112 | if (ncm->len > sizeof(struct nss_tun6rd_msg)) { |
| 113 | nss_warning("%p: message length is invalid: %d", nss_ctx, ncm->len); |
| 114 | return NSS_TX_FAILURE; |
| 115 | } |
| 116 | |
| 117 | nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE); |
| 118 | if (unlikely(!nbuf)) { |
| 119 | spin_lock_bh(&nss_ctx->nss_top->stats_lock); |
| 120 | nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]++; |
| 121 | spin_unlock_bh(&nss_ctx->nss_top->stats_lock); |
| 122 | nss_warning("%p: msg dropped as command allocation failed", nss_ctx); |
| 123 | return NSS_TX_FAILURE; |
| 124 | } |
| 125 | |
| 126 | /* |
| 127 | * Copy the message to our skb |
| 128 | */ |
| 129 | nm = (struct nss_tun6rd_msg *)skb_put(nbuf, sizeof(struct nss_tun6rd_msg)); |
| 130 | memcpy(nm, msg, sizeof(struct nss_tun6rd_msg)); |
| 131 | |
| 132 | status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0); |
| 133 | if (status != NSS_CORE_STATUS_SUCCESS) { |
| 134 | dev_kfree_skb_any(nbuf); |
| 135 | nss_warning("%p: Unable to enqueue 'tun6rd message' \n", nss_ctx); |
| 136 | return NSS_TX_FAILURE; |
| 137 | } |
| 138 | |
| 139 | nss_hal_send_interrupt(nss_ctx->nmap, nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit, |
| 140 | NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE); |
| 141 | |
| 142 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]); |
| 143 | return NSS_TX_SUCCESS; |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame^] | 147 | *********************************** |
| 148 | * Register/Unregister/Miscellaneous APIs |
| 149 | *********************************** |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 150 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame^] | 151 | |
| 152 | /* |
| 153 | * nss_register_tun6rd_if() |
| 154 | */ |
| 155 | struct nss_ctx_instance *nss_register_tun6rd_if(uint32_t if_num, |
| 156 | nss_tun6rd_callback_t tun6rd_callback, |
| 157 | nss_tun6rd_msg_callback_t event_callback, struct net_device *netdev) |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 158 | { |
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 | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 160 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame^] | 161 | nss_top_main.if_ctx[if_num] = netdev; |
| 162 | nss_top_main.if_rx_callback[if_num] = tun6rd_callback; |
| 163 | nss_top_main.tun6rd_msg_callback = event_callback; |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 164 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame^] | 165 | 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] | 166 | } |
| 167 | |
| 168 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame^] | 169 | * nss_unregister_tun6rd_if() |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 170 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame^] | 171 | void nss_unregister_tun6rd_if(uint32_t if_num) |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 172 | { |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame^] | 173 | 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] | 174 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame^] | 175 | nss_top_main.if_rx_callback[if_num] = NULL; |
| 176 | nss_top_main.if_ctx[if_num] = NULL; |
| 177 | nss_top_main.tun6rd_msg_callback = NULL; |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame^] | 181 | * nss_tun6rd_register_handler() |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 182 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame^] | 183 | void nss_tun6rd_register_handler() |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 184 | { |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame^] | 185 | nss_core_register_handler(NSS_TUN6RD_INTERFACE, nss_tun6rd_handler, NULL); |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 186 | } |
| 187 | |
Radhakrishna Jiguru | 5ad493d | 2013-11-25 20:17:54 +0530 | [diff] [blame] | 188 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame^] | 189 | EXPORT_SYMBOL(nss_tun6rd_tx); |
| 190 | EXPORT_SYMBOL(nss_register_tun6rd_if); |
| 191 | EXPORT_SYMBOL(nss_unregister_tun6rd_if); |