blob: f135fd25c83f3b091a2a9c086d26b8209146b996 [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
81 nss_hal_send_interrupt(nss_ctx->nmap, nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit,
82 NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE);
83
84 NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]);
85
86 return NSS_TX_SUCCESS;
87}
88
89/*
90 **********************************
91 Rx APIs
92 **********************************
93 */
94
95/*
Murat Sezgin2f9241a2015-06-25 13:01:51 -070096 * nss_pppoe_session_reset()
97 * Reset PPPoE session when session is destroyed.
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +053098 */
Murat Sezgin2f9241a2015-06-25 13:01:51 -070099static 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 +0530100{
Murat Sezgin2f9241a2015-06-25 13:01:51 -0700101 uint32_t i;
102 uint32_t interface = npsr->interface;
103 uint32_t session_index = npsr->session_index;
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530104
105 /*
Murat Sezgin2f9241a2015-06-25 13:01:51 -0700106 * Reset the PPPoE statistics for this specific session.
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530107 */
108 spin_lock_bh(&nss_ctx->nss_top->stats_lock);
Murat Sezgin2f9241a2015-06-25 13:01:51 -0700109 for (i = 0; i < NSS_PPPOE_EXCEPTION_EVENT_MAX; i++) {
110 nss_ctx->nss_top->stats_if_exception_pppoe[interface][session_index][i] = 0;
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530111 }
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530112 spin_unlock_bh(&nss_ctx->nss_top->stats_lock);
113}
114
115/*
116 * nss_pppoe_exception_stats_sync()
117 * Handle the syncing of PPPoE exception statistics.
118 */
119static void nss_pppoe_exception_stats_sync(struct nss_ctx_instance *nss_ctx, struct nss_pppoe_conn_stats_sync_msg *npess)
120{
121 struct nss_top_instance *nss_top = nss_ctx->nss_top;
122 uint32_t index = npess->index;
123 uint32_t interface_num = npess->interface_num;
124 uint32_t i;
125
126 spin_lock_bh(&nss_top->stats_lock);
127
128 if (interface_num >= NSS_MAX_PHYSICAL_INTERFACES) {
Murat Sezgin524f90c2014-11-13 17:39:17 -0800129 spin_unlock_bh(&nss_top->stats_lock);
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530130 nss_warning("%p: Incorrect interface number %d for PPPoE exception stats", nss_ctx, interface_num);
131 return;
132 }
133
134 /*
135 * pppoe exception stats
136 */
137 for (i = 0; i < NSS_PPPOE_EXCEPTION_EVENT_MAX; i++) {
138 nss_top->stats_if_exception_pppoe[interface_num][index][i] += npess->exception_events_pppoe[i];
139 }
140
141 spin_unlock_bh(&nss_top->stats_lock);
142}
143
144/*
145 * nss_pppoe_node_stats_sync()
146 * Handle the syncing of PPPoE node statistics.
147 */
148static void nss_pppoe_node_stats_sync(struct nss_ctx_instance *nss_ctx, struct nss_pppoe_node_stats_sync_msg *npess)
149{
150 struct nss_top_instance *nss_top = nss_ctx->nss_top;
151
152 spin_lock_bh(&nss_top->stats_lock);
153
154 nss_top->stats_node[NSS_PPPOE_RX_INTERFACE][NSS_STATS_NODE_RX_PKTS] += npess->node_stats.rx_packets;
155 nss_top->stats_node[NSS_PPPOE_RX_INTERFACE][NSS_STATS_NODE_RX_BYTES] += npess->node_stats.rx_bytes;
156 nss_top->stats_node[NSS_PPPOE_RX_INTERFACE][NSS_STATS_NODE_RX_DROPPED] += npess->node_stats.rx_dropped;
157 nss_top->stats_node[NSS_PPPOE_RX_INTERFACE][NSS_STATS_NODE_TX_PKTS] += npess->node_stats.tx_packets;
158 nss_top->stats_node[NSS_PPPOE_RX_INTERFACE][NSS_STATS_NODE_TX_BYTES] += npess->node_stats.tx_bytes;
159
160 nss_top->stats_pppoe[NSS_STATS_PPPOE_SESSION_CREATE_REQUESTS] += npess->pppoe_session_create_requests;
161 nss_top->stats_pppoe[NSS_STATS_PPPOE_SESSION_CREATE_FAILURES] += npess->pppoe_session_create_failures;
162 nss_top->stats_pppoe[NSS_STATS_PPPOE_SESSION_DESTROY_REQUESTS] += npess->pppoe_session_destroy_requests;
Murat Sezgin2f9241a2015-06-25 13:01:51 -0700163 nss_top->stats_pppoe[NSS_STATS_PPPOE_SESSION_DESTROY_REQUESTS] += npess->pppoe_session_destroy_requests;
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530164
165 spin_unlock_bh(&nss_top->stats_lock);
166}
167
168/*
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530169 * nss_pppoe_rx_msg_handler()
170 * Handle NSS -> HLOS messages for PPPoE
171 */
172static void nss_pppoe_rx_msg_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data)
173{
174 struct nss_pppoe_msg *nim = (struct nss_pppoe_msg *)ncm;
175
176 BUG_ON(ncm->interface != NSS_PPPOE_RX_INTERFACE);
177
178 /*
179 * Sanity check the message type
180 */
181 if (ncm->type > NSS_PPPOE_MAX) {
182 nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
183 return;
184 }
185
Suruchi Agarwalef8a8702016-01-08 12:40:08 -0800186 if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_pppoe_msg)) {
187 nss_warning("%p: message length is invalid: %d", nss_ctx, nss_cmn_get_msg_len(ncm));
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530188 return;
189 }
190
191 /*
192 * Log failures
193 */
194 nss_core_log_msg_failures(nss_ctx, ncm);
195
196 /*
197 * Handling PPPoE messages coming from NSS fw.
198 */
199 switch (nim->cm.type) {
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530200 case NSS_PPPOE_RX_NODE_STATS_SYNC:
201 nss_pppoe_node_stats_sync(nss_ctx, &nim->msg.pppoe_node_stats_sync);
202 break;
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530203 case NSS_PPPOE_RX_CONN_STATS_SYNC:
204 nss_pppoe_exception_stats_sync(nss_ctx, &nim->msg.pppoe_conn_stats_sync);
205 break;
Murat Sezgin2f9241a2015-06-25 13:01:51 -0700206 case NSS_PPPOE_RX_SESSION_RESET:
207 nss_pppoe_session_reset(nss_ctx, &nim->msg.pppoe_session_reset);
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530208 break;
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530209 default:
210 nss_warning("%p: Received response %d for type %d, interface %d",
211 nss_ctx, ncm->response, ncm->type, ncm->interface);
212 }
213}
214
215/*
216 * nss_pppoe_register_handler()
217 */
218void nss_pppoe_register_handler()
219{
220 nss_core_register_handler(NSS_PPPOE_RX_INTERFACE, nss_pppoe_rx_msg_handler, NULL);
221}
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700222
223/*
224 * nss_pppoe_msg_init()
225 * Initialize pppoe message.
226 */
227void nss_pppoe_msg_init(struct nss_pppoe_msg *npm, uint16_t if_num, uint32_t type, uint32_t len,
228 void *cb, void *app_data)
229{
230 nss_cmn_msg_init(&npm->cm, if_num, type, len, (void *)cb, app_data);
231}
232