blob: c89d01664fb5868cb4a6ff518a63846b28f7cc31 [file] [log] [blame]
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +05301/*
2 **************************************************************************
Stephen Wang3e2dbd12018-03-14 17:28:17 -07003 * Copyright (c) 2013-2018, 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>
Yu Huang8c107082017-07-24 14:58:26 -070024#include "nss_pppoe_stats.h"
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +053025
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +053026/*
27 * nss_pppoe_tx()
28 * Transmit an PPPoe message to the FW.
29 */
30nss_tx_status_t nss_pppoe_tx(struct nss_ctx_instance *nss_ctx, struct nss_pppoe_msg *nim)
31{
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +053032 struct nss_cmn_msg *ncm = &nim->cm;
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +053033
34 /*
35 * Sanity check the message
36 */
37 if (ncm->interface != NSS_PPPOE_RX_INTERFACE) {
38 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
39 return NSS_TX_FAILURE;
40 }
41
42 if (ncm->type > NSS_PPPOE_MAX) {
43 nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
44 return NSS_TX_FAILURE;
45 }
46
Stephen Wang3e2dbd12018-03-14 17:28:17 -070047 return nss_core_send_cmd(nss_ctx, nim, sizeof(*nim), NSS_NBUF_PAYLOAD_SIZE);
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +053048}
49
50/*
51 **********************************
52 Rx APIs
53 **********************************
54 */
55
56/*
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +053057 * nss_pppoe_rx_msg_handler()
58 * Handle NSS -> HLOS messages for PPPoE
59 */
60static void nss_pppoe_rx_msg_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data)
61{
62 struct nss_pppoe_msg *nim = (struct nss_pppoe_msg *)ncm;
63
64 BUG_ON(ncm->interface != NSS_PPPOE_RX_INTERFACE);
65
66 /*
67 * Sanity check the message type
68 */
69 if (ncm->type > NSS_PPPOE_MAX) {
70 nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
71 return;
72 }
73
Suruchi Agarwalef8a8702016-01-08 12:40:08 -080074 if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_pppoe_msg)) {
75 nss_warning("%p: message length is invalid: %d", nss_ctx, nss_cmn_get_msg_len(ncm));
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +053076 return;
77 }
78
79 /*
80 * Log failures
81 */
82 nss_core_log_msg_failures(nss_ctx, ncm);
83
84 /*
85 * Handling PPPoE messages coming from NSS fw.
86 */
87 switch (nim->cm.type) {
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +053088 case NSS_PPPOE_RX_NODE_STATS_SYNC:
Yu Huang8c107082017-07-24 14:58:26 -070089 nss_pppoe_stats_node_sync(nss_ctx, &nim->msg.pppoe_node_stats_sync);
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +053090 break;
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +053091 case NSS_PPPOE_RX_CONN_STATS_SYNC:
Yu Huang8c107082017-07-24 14:58:26 -070092 nss_pppoe_stats_exception_sync(nss_ctx, &nim->msg.pppoe_conn_stats_sync);
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +053093 break;
Murat Sezgin2f9241a2015-06-25 13:01:51 -070094 case NSS_PPPOE_RX_SESSION_RESET:
Yu Huang8c107082017-07-24 14:58:26 -070095 nss_pppoe_stats_session_reset(nss_ctx, &nim->msg.pppoe_session_reset);
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +053096 break;
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +053097 default:
98 nss_warning("%p: Received response %d for type %d, interface %d",
99 nss_ctx, ncm->response, ncm->type, ncm->interface);
100 }
101}
102
103/*
104 * nss_pppoe_register_handler()
105 */
Thomas Wu91f4bdf2017-06-09 12:03:02 -0700106void nss_pppoe_register_handler(struct nss_ctx_instance *nss_ctx)
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530107{
Thomas Wu91f4bdf2017-06-09 12:03:02 -0700108 nss_core_register_handler(nss_ctx, NSS_PPPOE_RX_INTERFACE, nss_pppoe_rx_msg_handler, NULL);
Yu Huang8c107082017-07-24 14:58:26 -0700109
110 nss_pppoe_stats_dentry_create();
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530111}
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700112
113/*
114 * nss_pppoe_msg_init()
115 * Initialize pppoe message.
116 */
117void 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 -0700118 void *cb, void *app_data)
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700119{
120 nss_cmn_msg_init(&npm->cm, if_num, type, len, (void *)cb, app_data);
121}