blob: 25b9942d5df5d2a1021c48ad58110afe86028958 [file] [log] [blame]
Bharath M Kumar614bbf82013-08-31 20:18:44 +05301/*
Murat Sezgin84ca6512014-04-14 13:57:24 -07002 **************************************************************************
3 * Copyright (c) 2014, The Linux Foundation. All rights reserved.
Bharath M Kumar614bbf82013-08-31 20:18:44 +05304 * 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 Sezgin84ca6512014-04-14 13:57:24 -07006 * above copyright notice and this permission notice appear in all copies.
Bharath M Kumar614bbf82013-08-31 20:18:44 +05307 * 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 Sezgin84ca6512014-04-14 13:57:24 -070014 **************************************************************************
Bharath M Kumar614bbf82013-08-31 20:18:44 +053015 */
16
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +053017#include "nss_tx_rx_common.h"
Bharath M Kumar614bbf82013-08-31 20:18:44 +053018
Bharath M Kumar614bbf82013-08-31 20:18:44 +053019/*
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +053020 * nss_tunipip6_handler()
Sol Kavy359ef152014-04-04 11:55:24 -070021 * Handle NSS -> HLOS messages for 6rd tunnel
Bharath M Kumar614bbf82013-08-31 20:18:44 +053022 */
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +053023static void nss_tunipip6_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data)
Bharath M Kumar614bbf82013-08-31 20:18:44 +053024{
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +053025 struct nss_tunipip6_msg *ntm = (struct nss_tunipip6_msg *)ncm;
26 void *ctx;
27 nss_tunipip6_msg_callback_t cb;
Bharath M Kumar614bbf82013-08-31 20:18:44 +053028
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +053029 BUG_ON(ncm->interface != NSS_TUNIPIP6_INTERFACE);
Bharath M Kumar614bbf82013-08-31 20:18:44 +053030 /*
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +053031 * Is this a valid request/response packet?
Bharath M Kumar614bbf82013-08-31 20:18:44 +053032 */
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +053033 if (ncm->type >= NSS_TUNIPIP6_MAX) {
34 nss_warning("%p: received invalid message %d for DS-Lite interface", nss_ctx, ncm->type);
Bharath M Kumar614bbf82013-08-31 20:18:44 +053035 return;
36 }
37
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +053038 if (ncm->len > sizeof(struct nss_tunipip6_msg)) {
39 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
Bharath M Kumar614bbf82013-08-31 20:18:44 +053040 return;
41 }
42
43 /*
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +053044 * Update the callback and app_data for NOTIFY messages, tun6rd sends all notify messages
45 * to the same callback/app_data.
Bharath M Kumar614bbf82013-08-31 20:18:44 +053046 */
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +053047 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 Kumar614bbf82013-08-31 20:18:44 +053060 return;
61 }
62
63 /*
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +053064 * callback
Bharath M Kumar614bbf82013-08-31 20:18:44 +053065 */
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +053066 cb = (nss_tunipip6_msg_callback_t)ncm->cb;
67 ctx = nss_ctx->nss_top->if_ctx[ncm->interface];
Bharath M Kumar614bbf82013-08-31 20:18:44 +053068
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +053069 /*
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 Kumar614bbf82013-08-31 20:18:44 +053074 return;
75 }
76
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +053077 cb(ctx, ntm);
Bharath M Kumar614bbf82013-08-31 20:18:44 +053078}
79
80/*
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +053081 * nss_tunipip6_tx()
82 * Transmit a tun6rd message to NSSFW
Bharath M Kumar614bbf82013-08-31 20:18:44 +053083 */
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +053084nss_tx_status_t nss_tunipip6_tx(struct nss_ctx_instance *nss_ctx, struct nss_tunipip6_msg *msg)
Bharath M Kumar614bbf82013-08-31 20:18:44 +053085{
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +053086 struct nss_tunipip6_msg *nm;
87 struct nss_cmn_msg *ncm = &msg->cm;
88 struct sk_buff *nbuf;
89 int32_t status;
Bharath M Kumar614bbf82013-08-31 20:18:44 +053090
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +053091 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 Kumar614bbf82013-08-31 20:18:44 +053095 }
96
Bharath M Kumar614bbf82013-08-31 20:18:44 +053097 /*
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +053098 * Sanity check the message
Bharath M Kumar614bbf82013-08-31 20:18:44 +053099 */
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +0530100 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 Kumar614bbf82013-08-31 20:18:44 +0530103 }
104
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +0530105 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 Jiguru5ad493d2013-11-25 20:17:54 +0530108 }
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +0530109
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 Jiguru5ad493d2013-11-25 20:17:54 +0530142}
143
144/*
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +0530145 * **********************************
146 * Register/Unregister/Miscellaneous APIs
147 * **********************************
Bharath M Kumar614bbf82013-08-31 20:18:44 +0530148 */
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +0530149
150/*
151 * nss_register_tunipip6_if()
152 */
153struct 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 Kumar614bbf82013-08-31 20:18:44 +0530156{
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +0530157 nss_assert((if_num >= NSS_MAX_VIRTUAL_INTERFACES) && (if_num < NSS_MAX_NET_INTERFACES));
Bharath M Kumar614bbf82013-08-31 20:18:44 +0530158
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +0530159 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 Kumar614bbf82013-08-31 20:18:44 +0530162
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +0530163 return (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.tunipip6_handler_id];
Bharath M Kumar614bbf82013-08-31 20:18:44 +0530164}
165
166/*
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +0530167 * nss_unregister_tunipip6_if()
Bharath M Kumar614bbf82013-08-31 20:18:44 +0530168 */
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +0530169void nss_unregister_tunipip6_if(uint32_t if_num)
Bharath M Kumar614bbf82013-08-31 20:18:44 +0530170{
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +0530171 nss_assert((if_num >= NSS_MAX_VIRTUAL_INTERFACES) && (if_num < NSS_MAX_NET_INTERFACES));
Bharath M Kumar614bbf82013-08-31 20:18:44 +0530172
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +0530173 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 Kumar614bbf82013-08-31 20:18:44 +0530176}
177
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +0530178/*
179 * nss_tunipip6_register_handler()
180 */
181void nss_tunipip6_register_handler()
182{
183 nss_core_register_handler(NSS_TUNIPIP6_INTERFACE, nss_tunipip6_handler, NULL);
184}
Bharath M Kumar614bbf82013-08-31 20:18:44 +0530185
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +0530186EXPORT_SYMBOL(nss_tunipip6_tx);
187EXPORT_SYMBOL(nss_register_tunipip6_if);
188EXPORT_SYMBOL(nss_unregister_tunipip6_if);