blob: d8a96e58b652614479e6b2ff91ef5c4404060d5c [file] [log] [blame]
Sol Kavy879eb8b2014-04-07 19:11:31 -07001/*
2 **************************************************************************
3 * Copyright (c) 2014, The Linux Foundation. All rights reserved.
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
6 * above copyright notice and this permission notice appear in all copies.
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.
14 **************************************************************************
15 */
16
17/*
18 * nss_ipv6.c
19 * NSS IPv6 APIs
20 */
21#include <linux/ppp_channel.h>
22#include "nss_tx_rx_common.h"
Sol Kavy879eb8b2014-04-07 19:11:31 -070023
24extern void nss_rx_metadata_ipv6_rule_establish(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_rule_establish *nire);
25extern void nss_rx_ipv6_sync(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_conn_sync *nirs);
26
27/*
28 * nss_ipv6_driver_conn_sync_update()
29 * Update driver specific information from the messsage.
30 */
31static void nss_ipv6_driver_conn_sync_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_conn_sync *nics)
32{
33 struct nss_top_instance *nss_top = nss_ctx->nss_top;
34 struct net_device *pppoe_dev = NULL;
35
36 /*
37 * Update statistics maintained by NSS driver
38 */
39 spin_lock_bh(&nss_top->stats_lock);
40 nss_top->stats_ipv6[NSS_STATS_IPV6_ACCELERATED_RX_PKTS] += nics->flow_rx_packet_count + nics->return_rx_packet_count;
41 nss_top->stats_ipv6[NSS_STATS_IPV6_ACCELERATED_RX_BYTES] += nics->flow_rx_byte_count + nics->return_rx_byte_count;
42 nss_top->stats_ipv6[NSS_STATS_IPV6_ACCELERATED_TX_PKTS] += nics->flow_tx_packet_count + nics->return_tx_packet_count;
43 nss_top->stats_ipv6[NSS_STATS_IPV6_ACCELERATED_TX_BYTES] += nics->flow_tx_byte_count + nics->return_tx_byte_count;
Abhishek Rastogi55f39452014-05-08 19:23:29 +053044 spin_unlock_bh(&nss_top->stats_lock);
Sol Kavy879eb8b2014-04-07 19:11:31 -070045
46 /*
47 * Update the PPPoE interface stats, if there is any PPPoE session on the interfaces.
48 */
49 if (nics->flow_pppoe_session_id) {
50 pppoe_dev = ppp_session_to_netdev(nics->flow_pppoe_session_id, (uint8_t *)nics->flow_pppoe_remote_mac);
51 if (pppoe_dev) {
52 ppp_update_stats(pppoe_dev, nics->flow_rx_packet_count, nics->flow_rx_byte_count,
53 nics->flow_tx_packet_count, nics->flow_tx_byte_count);
54 dev_put(pppoe_dev);
55 }
56 }
57
58 if (nics->return_pppoe_session_id) {
59 pppoe_dev = ppp_session_to_netdev(nics->return_pppoe_session_id, (uint8_t *)nics->return_pppoe_remote_mac);
60 if (pppoe_dev) {
61 ppp_update_stats(pppoe_dev, nics->return_rx_packet_count, nics->return_rx_byte_count,
62 nics->return_tx_packet_count, nics->return_tx_byte_count);
63 dev_put(pppoe_dev);
64 }
65 }
66
67}
68
69/*
Murat Sezgin0c0561d2014-04-09 18:55:58 -070070 * nss_ipv6_driver_node_sync_update)
71 * Update driver specific information from the messsage.
72 */
73static void nss_ipv6_driver_node_sync_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_node_sync *nins)
74{
75 struct nss_top_instance *nss_top = nss_ctx->nss_top;
76 uint32_t i;
77
78 /*
79 * Update statistics maintained by NSS driver
80 */
81 spin_lock_bh(&nss_top->stats_lock);
82 nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_RX_PKTS] += nins->node_stats.rx_packets;
83 nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_RX_BYTES] += nins->node_stats.rx_bytes;
84 nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_RX_DROPPED] += nins->node_stats.rx_dropped;
85 nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_TX_PKTS] += nins->node_stats.tx_packets;
86 nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_TX_BYTES] += nins->node_stats.tx_bytes;
87
Murat Sezgin0c0561d2014-04-09 18:55:58 -070088 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_CREATE_REQUESTS] += nins->ipv6_connection_create_requests;
89 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_CREATE_COLLISIONS] += nins->ipv6_connection_create_collisions;
90 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_CREATE_INVALID_INTERFACE] += nins->ipv6_connection_create_invalid_interface;
91 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_DESTROY_REQUESTS] += nins->ipv6_connection_destroy_requests;
92 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_DESTROY_MISSES] += nins->ipv6_connection_destroy_misses;
93 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_HASH_HITS] += nins->ipv6_connection_hash_hits;
94 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_HASH_REORDERS] += nins->ipv6_connection_hash_reorders;
95 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_FLUSHES] += nins->ipv6_connection_flushes;
96 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_EVICTIONS] += nins->ipv6_connection_evictions;
97
98 for (i = 0; i < NSS_EXCEPTION_EVENT_IPV6_MAX; i++) {
99 nss_top->stats_if_exception_ipv6[i] += nins->exception_events[i];
100 }
101 spin_unlock_bh(&nss_top->stats_lock);
102}
103
104/*
Sol Kavy879eb8b2014-04-07 19:11:31 -0700105 * nss_ipv6_rx_msg_handler()
106 * Handle NSS -> HLOS messages for IPv6 bridge/route
107 */
108static void nss_ipv6_rx_msg_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data)
109{
110 struct nss_ipv6_msg *nim = (struct nss_ipv6_msg *)ncm;
111 nss_ipv6_msg_callback_t cb;
112
113 BUG_ON(ncm->interface != NSS_IPV6_RX_INTERFACE);
114
115 /*
116 * Is this a valid request/response packet?
117 */
118 if (nim->cm.type >= NSS_IPV6_MAX_MSG_TYPES) {
119 nss_warning("%p: received invalid message %d for IPv6 interface", nss_ctx, nim->cm.type);
120 return;
121 }
122
123 if (ncm->len > sizeof(struct nss_ipv6_msg)) {
124 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
125 return;
126 }
127
128 /*
129 * Log failures
130 */
131 nss_core_log_msg_failures(nss_ctx, ncm);
132
133 /*
134 * Handle deprecated messages. Eventually these messages should be removed.
135 */
136 switch (nim->cm.type) {
137 case NSS_IPV6_RX_ESTABLISH_RULE_MSG:
138 nss_rx_metadata_ipv6_rule_establish(nss_ctx, &nim->msg.rule_establish);
139 break;
140
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700141 case NSS_IPV6_RX_NODE_STATS_SYNC_MSG:
142 /*
143 * Update driver statistics on node sync.
144 */
145 nss_ipv6_driver_node_sync_update(nss_ctx, &nim->msg.node_stats);
146 break;
147
Sol Kavy879eb8b2014-04-07 19:11:31 -0700148 case NSS_IPV6_RX_CONN_STATS_SYNC_MSG:
149 /*
150 * Update driver statistics on connection sync.
151 */
152 nss_ipv6_driver_conn_sync_update(nss_ctx, &nim->msg.conn_stats);
153 return nss_rx_ipv6_sync(nss_ctx, &nim->msg.conn_stats);
154 break;
155 }
Abhishek Rastogi55f39452014-05-08 19:23:29 +0530156
Sol Kavy879eb8b2014-04-07 19:11:31 -0700157 /*
158 * Update the callback and app_data for NOTIFY messages, IPv6 sends all notify messages
159 * to the same callback/app_data.
160 */
161 if (nim->cm.response == NSS_CMM_RESPONSE_NOTIFY) {
162 ncm->cb = (uint32_t)nss_ctx->nss_top->ipv6_callback;
163 ncm->app_data = (uint32_t)nss_ctx->nss_top->ipv6_ctx;
164 }
165
166 /*
167 * Do we have a callback?
168 */
169 if (!ncm->cb) {
170 return;
171 }
172
173 /*
174 * Callback
175 */
176 cb = (nss_ipv6_msg_callback_t)ncm->cb;
177 cb((void *)ncm->app_data, nim);
178}
179
180/*
181 * nss_ipv6_tx()
182 * Transmit an ipv6 message to the FW.
183 */
184nss_tx_status_t nss_ipv6_tx(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_msg *nim)
185{
186 struct nss_ipv6_msg *nim2;
187 struct nss_cmn_msg *ncm = &nim->cm;
188 struct sk_buff *nbuf;
189 int32_t status;
190
191 NSS_VERIFY_CTX_MAGIC(nss_ctx);
192 if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
193 nss_warning("%p: ipv6 msg dropped as core not ready", nss_ctx);
194 return NSS_TX_FAILURE_NOT_READY;
195 }
196
197 /*
198 * Sanity check the message
199 */
200 if (ncm->interface != NSS_IPV6_RX_INTERFACE) {
201 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
202 return NSS_TX_FAILURE;
203 }
204
205 if (ncm->type > NSS_IPV6_MAX_MSG_TYPES) {
206 nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
207 return NSS_TX_FAILURE;
208 }
209
210 if (ncm->len > sizeof(struct nss_ipv6_msg)) {
211 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
212 return NSS_TX_FAILURE;
213 }
214
215 nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE);
216 if (unlikely(!nbuf)) {
217 spin_lock_bh(&nss_ctx->nss_top->stats_lock);
218 nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]++;
219 spin_unlock_bh(&nss_ctx->nss_top->stats_lock);
220 nss_warning("%p: msg dropped as command allocation failed", nss_ctx);
221 return NSS_TX_FAILURE;
222 }
223
224 /*
225 * Copy the message to our skb.
226 */
227 nim2 = (struct nss_ipv6_msg *)skb_put(nbuf, sizeof(struct nss_ipv6_msg));
228 memcpy(nim2, nim, sizeof(struct nss_ipv6_msg));
229
230 status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0);
231 if (status != NSS_CORE_STATUS_SUCCESS) {
232 dev_kfree_skb_any(nbuf);
233 nss_warning("%p: Unable to enqueue 'Destroy IPv6' rule\n", nss_ctx);
234 return NSS_TX_FAILURE;
235 }
236
237 nss_hal_send_interrupt(nss_ctx->nmap, nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit,
238 NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE);
239
240 NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]);
241 return NSS_TX_SUCCESS;
242}
243
244/*
245 **********************************
246 Register/Unregister/Miscellaneous APIs
247 **********************************
248 */
249
250/*
251 * nss_ipv6_notify_register()
252 * Register to received IPv6 events.
253 *
254 * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv6 on any core?
255 */
256struct nss_ctx_instance *nss_ipv6_notify_register(nss_ipv6_msg_callback_t cb, void *app_data)
257{
258 /*
259 * TODO: We need to have a new array in support of the new API
260 * TODO: If we use a per-context array, we would move the array into nss_ctx based.
261 */
262 nss_top_main.ipv6_callback = cb;
263 nss_top_main.ipv6_ctx = app_data;
264 return &nss_top_main.nss[nss_top_main.ipv6_handler_id];
265}
266
267/*
268 * nss_ipv6_notify_unregister()
269 * Unregister to received IPv6 events.
270 *
271 * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv6 on any core?
272 */
273void nss_ipv6_notify_unregister(void)
274{
275 nss_top_main.ipv6_callback = NULL;
276}
277
278/*
279 * nss_ipv6_get_mgr()
280 *
281 * TODO: This only suppports a single ipv6, do we ever want to support more?
282 */
283struct nss_ctx_instance *nss_ipv6_get_mgr(void)
284{
285 return (void *)&nss_top_main.nss[nss_top_main.ipv6_handler_id];
286}
287
288/*
289 * nss_ipv6_register_handler()
290 * Register our handler to receive messages for this interface
291 */
292void nss_ipv6_register_handler()
293{
294 if (nss_core_register_handler(NSS_IPV6_RX_INTERFACE, nss_ipv6_rx_msg_handler, NULL) != NSS_CORE_STATUS_SUCCESS) {
295 nss_warning("IPv6 handler failed to register");
296 }
297}
298
299EXPORT_SYMBOL(nss_ipv6_tx);
300EXPORT_SYMBOL(nss_ipv6_notify_register);
301EXPORT_SYMBOL(nss_ipv6_notify_unregister);
302EXPORT_SYMBOL(nss_ipv6_get_mgr);
303EXPORT_SYMBOL(nss_ipv6_register_handler);