blob: d8b439813da2875b99c0a812701551bd44a5a91c [file] [log] [blame]
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +05301/*
2 **************************************************************************
Suruchi Agarwalef8a8702016-01-08 12:40:08 -08003 * Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +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
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_pppoe.c
19 * NSS PPPoE APIs
20 */
21
22#include "nss_tx_rx_common.h"
Murat Sezgind80f3bd2014-12-10 15:38:06 -080023#include <linux/if_pppox.h>
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +053024
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +053025/*
26 * nss_pppoe_tx()
27 * Transmit an PPPoe message to the FW.
28 */
29nss_tx_status_t nss_pppoe_tx(struct nss_ctx_instance *nss_ctx, struct nss_pppoe_msg *nim)
30{
31 struct nss_pppoe_msg *nim2;
32 struct nss_cmn_msg *ncm = &nim->cm;
33 struct sk_buff *nbuf;
34 int32_t status;
35
36 NSS_VERIFY_CTX_MAGIC(nss_ctx);
37
38 if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
39 nss_warning("%p: pppoe msg dropped as core not ready", nss_ctx);
40 return NSS_TX_FAILURE_NOT_READY;
41 }
42
43 /*
44 * Sanity check the message
45 */
46 if (ncm->interface != NSS_PPPOE_RX_INTERFACE) {
47 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
48 return NSS_TX_FAILURE;
49 }
50
51 if (ncm->type > NSS_PPPOE_MAX) {
52 nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
53 return NSS_TX_FAILURE;
54 }
55
Suruchi Agarwalef8a8702016-01-08 12:40:08 -080056 if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_pppoe_msg)) {
57 nss_warning("%p: message length is invalid: %d", nss_ctx, nss_cmn_get_msg_len(ncm));
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +053058 return NSS_TX_FAILURE;
59 }
60
Pamidipati, Vijayb6e38842014-09-16 10:26:05 +053061 nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE);
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +053062 if (unlikely(!nbuf)) {
Sundarajan Srinivasan62fee7e2015-01-22 11:13:10 -080063 NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]);
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +053064 nss_warning("%p: msg dropped as command allocation failed", nss_ctx);
65 return NSS_TX_FAILURE;
66 }
67
68 /*
69 * Copy the message to our skb.
70 */
71 nim2 = (struct nss_pppoe_msg *)skb_put(nbuf, sizeof(struct nss_pppoe_msg));
72 memcpy(nim2, nim, sizeof(struct nss_pppoe_msg));
73
74 status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0);
75 if (status != NSS_CORE_STATUS_SUCCESS) {
Pamidipati, Vijayb6e38842014-09-16 10:26:05 +053076 dev_kfree_skb_any(nbuf);
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +053077 nss_warning("%p: unable to enqueue PPPoE msg\n", nss_ctx);
78 return NSS_TX_FAILURE;
79 }
80
Stephen Wang90c67de2016-04-26 15:15:59 -070081 nss_hal_send_interrupt(nss_ctx, NSS_H2N_INTR_DATA_COMMAND_QUEUE);
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +053082
83 NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]);
84
85 return NSS_TX_SUCCESS;
86}
87
88/*
89 **********************************
90 Rx APIs
91 **********************************
92 */
93
94/*
Murat Sezgin2f9241a2015-06-25 13:01:51 -070095 * nss_pppoe_session_reset()
96 * Reset PPPoE session when session is destroyed.
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +053097 */
Murat Sezgin2f9241a2015-06-25 13:01:51 -070098static void nss_pppoe_session_reset(struct nss_ctx_instance *nss_ctx, struct nss_pppoe_session_reset_msg *npsr)
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +053099{
Murat Sezgin2f9241a2015-06-25 13:01:51 -0700100 uint32_t i;
101 uint32_t interface = npsr->interface;
102 uint32_t session_index = npsr->session_index;
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530103
104 /*
Murat Sezgin2f9241a2015-06-25 13:01:51 -0700105 * Reset the PPPoE statistics for this specific session.
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530106 */
107 spin_lock_bh(&nss_ctx->nss_top->stats_lock);
Murat Sezgin2f9241a2015-06-25 13:01:51 -0700108 for (i = 0; i < NSS_PPPOE_EXCEPTION_EVENT_MAX; i++) {
109 nss_ctx->nss_top->stats_if_exception_pppoe[interface][session_index][i] = 0;
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530110 }
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530111 spin_unlock_bh(&nss_ctx->nss_top->stats_lock);
112}
113
114/*
115 * nss_pppoe_exception_stats_sync()
116 * Handle the syncing of PPPoE exception statistics.
117 */
118static void nss_pppoe_exception_stats_sync(struct nss_ctx_instance *nss_ctx, struct nss_pppoe_conn_stats_sync_msg *npess)
119{
120 struct nss_top_instance *nss_top = nss_ctx->nss_top;
121 uint32_t index = npess->index;
122 uint32_t interface_num = npess->interface_num;
123 uint32_t i;
124
125 spin_lock_bh(&nss_top->stats_lock);
126
127 if (interface_num >= NSS_MAX_PHYSICAL_INTERFACES) {
Murat Sezgin524f90c2014-11-13 17:39:17 -0800128 spin_unlock_bh(&nss_top->stats_lock);
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530129 nss_warning("%p: Incorrect interface number %d for PPPoE exception stats", nss_ctx, interface_num);
130 return;
131 }
132
133 /*
134 * pppoe exception stats
135 */
136 for (i = 0; i < NSS_PPPOE_EXCEPTION_EVENT_MAX; i++) {
137 nss_top->stats_if_exception_pppoe[interface_num][index][i] += npess->exception_events_pppoe[i];
138 }
139
140 spin_unlock_bh(&nss_top->stats_lock);
141}
142
143/*
144 * nss_pppoe_node_stats_sync()
145 * Handle the syncing of PPPoE node statistics.
146 */
147static void nss_pppoe_node_stats_sync(struct nss_ctx_instance *nss_ctx, struct nss_pppoe_node_stats_sync_msg *npess)
148{
149 struct nss_top_instance *nss_top = nss_ctx->nss_top;
150
151 spin_lock_bh(&nss_top->stats_lock);
152
153 nss_top->stats_node[NSS_PPPOE_RX_INTERFACE][NSS_STATS_NODE_RX_PKTS] += npess->node_stats.rx_packets;
154 nss_top->stats_node[NSS_PPPOE_RX_INTERFACE][NSS_STATS_NODE_RX_BYTES] += npess->node_stats.rx_bytes;
155 nss_top->stats_node[NSS_PPPOE_RX_INTERFACE][NSS_STATS_NODE_RX_DROPPED] += npess->node_stats.rx_dropped;
156 nss_top->stats_node[NSS_PPPOE_RX_INTERFACE][NSS_STATS_NODE_TX_PKTS] += npess->node_stats.tx_packets;
157 nss_top->stats_node[NSS_PPPOE_RX_INTERFACE][NSS_STATS_NODE_TX_BYTES] += npess->node_stats.tx_bytes;
158
159 nss_top->stats_pppoe[NSS_STATS_PPPOE_SESSION_CREATE_REQUESTS] += npess->pppoe_session_create_requests;
160 nss_top->stats_pppoe[NSS_STATS_PPPOE_SESSION_CREATE_FAILURES] += npess->pppoe_session_create_failures;
161 nss_top->stats_pppoe[NSS_STATS_PPPOE_SESSION_DESTROY_REQUESTS] += npess->pppoe_session_destroy_requests;
Murat Sezgin2f9241a2015-06-25 13:01:51 -0700162 nss_top->stats_pppoe[NSS_STATS_PPPOE_SESSION_DESTROY_REQUESTS] += npess->pppoe_session_destroy_requests;
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530163
164 spin_unlock_bh(&nss_top->stats_lock);
165}
166
167/*
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530168 * nss_pppoe_rx_msg_handler()
169 * Handle NSS -> HLOS messages for PPPoE
170 */
171static void nss_pppoe_rx_msg_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data)
172{
173 struct nss_pppoe_msg *nim = (struct nss_pppoe_msg *)ncm;
174
175 BUG_ON(ncm->interface != NSS_PPPOE_RX_INTERFACE);
176
177 /*
178 * Sanity check the message type
179 */
180 if (ncm->type > NSS_PPPOE_MAX) {
181 nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
182 return;
183 }
184
Suruchi Agarwalef8a8702016-01-08 12:40:08 -0800185 if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_pppoe_msg)) {
186 nss_warning("%p: message length is invalid: %d", nss_ctx, nss_cmn_get_msg_len(ncm));
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530187 return;
188 }
189
190 /*
191 * Log failures
192 */
193 nss_core_log_msg_failures(nss_ctx, ncm);
194
195 /*
196 * Handling PPPoE messages coming from NSS fw.
197 */
198 switch (nim->cm.type) {
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530199 case NSS_PPPOE_RX_NODE_STATS_SYNC:
200 nss_pppoe_node_stats_sync(nss_ctx, &nim->msg.pppoe_node_stats_sync);
201 break;
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530202 case NSS_PPPOE_RX_CONN_STATS_SYNC:
203 nss_pppoe_exception_stats_sync(nss_ctx, &nim->msg.pppoe_conn_stats_sync);
204 break;
Murat Sezgin2f9241a2015-06-25 13:01:51 -0700205 case NSS_PPPOE_RX_SESSION_RESET:
206 nss_pppoe_session_reset(nss_ctx, &nim->msg.pppoe_session_reset);
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530207 break;
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530208 default:
209 nss_warning("%p: Received response %d for type %d, interface %d",
210 nss_ctx, ncm->response, ncm->type, ncm->interface);
211 }
212}
213
214/*
215 * nss_pppoe_register_handler()
216 */
Thomas Wu91f4bdf2017-06-09 12:03:02 -0700217void nss_pppoe_register_handler(struct nss_ctx_instance *nss_ctx)
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530218{
Thomas Wu91f4bdf2017-06-09 12:03:02 -0700219 nss_core_register_handler(nss_ctx, NSS_PPPOE_RX_INTERFACE, nss_pppoe_rx_msg_handler, NULL);
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530220}
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700221
222/*
223 * nss_pppoe_msg_init()
224 * Initialize pppoe message.
225 */
226void nss_pppoe_msg_init(struct nss_pppoe_msg *npm, uint16_t if_num, uint32_t type, uint32_t len,
Thomas Wu91f4bdf2017-06-09 12:03:02 -0700227 void *cb, void *app_data)
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700228{
229 nss_cmn_msg_init(&npm->cm, if_num, type, len, (void *)cb, app_data);
230}
231