blob: 8f45b427dfe8e490b8fcd9952f2e576379bcee30 [file] [log] [blame]
Bharath M Kumar614bbf82013-08-31 20:18:44 +05301/*
Murat Sezgin84ca6512014-04-14 13:57:24 -07002 **************************************************************************
Sundarajan Srinivasan62fee7e2015-01-22 11:13:10 -08003 * Copyright (c) 2014-2015, 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;
Sundarajan Srinivasan70374842014-11-19 15:22:52 -080067 ctx = nss_ctx->nss_top->subsys_dp_register[ncm->interface].ndev;
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
Pamidipati, Vijayb6e38842014-09-16 10:26:05 +0530115 nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE);
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +0530116 if (unlikely(!nbuf)) {
Sundarajan Srinivasan62fee7e2015-01-22 11:13:10 -0800117 NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]);
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +0530118 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, Vijayb6e38842014-09-16 10:26:05 +0530130 dev_kfree_skb_any(nbuf);
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +0530131 nss_warning("%p: Unable to enqueue 'tun6rd message' \n", nss_ctx);
132 return NSS_TX_FAILURE;
133 }
134
135 nss_hal_send_interrupt(nss_ctx->nmap, nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit,
136 NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE);
137
138 NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]);
139 return NSS_TX_SUCCESS;
Radhakrishna Jiguru5ad493d2013-11-25 20:17:54 +0530140}
141
142/*
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +0530143 * **********************************
144 * Register/Unregister/Miscellaneous APIs
145 * **********************************
Bharath M Kumar614bbf82013-08-31 20:18:44 +0530146 */
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +0530147
148/*
149 * nss_register_tunipip6_if()
150 */
151struct nss_ctx_instance *nss_register_tunipip6_if(uint32_t if_num,
152 nss_tunipip6_callback_t tunipip6_callback,
Sundarajan Srinivasan70374842014-11-19 15:22:52 -0800153 nss_tunipip6_msg_callback_t event_callback,
154 struct net_device *netdev,
155 uint32_t features)
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.tunipip6_msg_callback = event_callback;
Bharath M Kumar614bbf82013-08-31 20:18:44 +0530160
Sundarajan Srinivasan70374842014-11-19 15:22:52 -0800161 nss_top_main.subsys_dp_register[if_num].ndev = netdev;
162 nss_top_main.subsys_dp_register[if_num].cb = tunipip6_callback;
163 nss_top_main.subsys_dp_register[if_num].app_data = NULL;
164 nss_top_main.subsys_dp_register[if_num].features = features;
165
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +0530166 return (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.tunipip6_handler_id];
Bharath M Kumar614bbf82013-08-31 20:18:44 +0530167}
168
169/*
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +0530170 * nss_unregister_tunipip6_if()
Bharath M Kumar614bbf82013-08-31 20:18:44 +0530171 */
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +0530172void nss_unregister_tunipip6_if(uint32_t if_num)
Bharath M Kumar614bbf82013-08-31 20:18:44 +0530173{
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +0530174 nss_assert((if_num >= NSS_MAX_VIRTUAL_INTERFACES) && (if_num < NSS_MAX_NET_INTERFACES));
Bharath M Kumar614bbf82013-08-31 20:18:44 +0530175
Sundarajan Srinivasan70374842014-11-19 15:22:52 -0800176 nss_top_main.subsys_dp_register[if_num].cb = NULL;
177 nss_top_main.subsys_dp_register[if_num].ndev = NULL;
178 nss_top_main.subsys_dp_register[if_num].features = 0;
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +0530179 nss_top_main.tunipip6_msg_callback = NULL;
Bharath M Kumar614bbf82013-08-31 20:18:44 +0530180}
181
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +0530182/*
183 * nss_tunipip6_register_handler()
184 */
185void nss_tunipip6_register_handler()
186{
187 nss_core_register_handler(NSS_TUNIPIP6_INTERFACE, nss_tunipip6_handler, NULL);
188}
Bharath M Kumar614bbf82013-08-31 20:18:44 +0530189
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700190/*
191 * nss_tunipip6_msg_init()
192 * Initialize nss_tunipip6 msg.
193 */
194void nss_tunipip6_msg_init(struct nss_tunipip6_msg *ntm, uint16_t if_num, uint32_t type, uint32_t len, void *cb, void *app_data)
195{
196 nss_cmn_msg_init(&ntm->cm, if_num, type, len, cb, app_data);
197}
198
Radha krishna Simha Jiguru62a29e62014-04-04 17:28:53 +0530199EXPORT_SYMBOL(nss_tunipip6_tx);
200EXPORT_SYMBOL(nss_register_tunipip6_if);
201EXPORT_SYMBOL(nss_unregister_tunipip6_if);
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700202EXPORT_SYMBOL(nss_tunipip6_msg_init);