blob: 18faea23777e163c41629d479d43d7ce23f920a9 [file] [log] [blame]
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +05301/*
2 **************************************************************************
Yu Huang8c107082017-07-24 14:58:26 -07003 * Copyright (c) 2013-2017, 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{
32 struct nss_pppoe_msg *nim2;
33 struct nss_cmn_msg *ncm = &nim->cm;
34 struct sk_buff *nbuf;
35 int32_t status;
36
37 NSS_VERIFY_CTX_MAGIC(nss_ctx);
38
39 if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
40 nss_warning("%p: pppoe msg dropped as core not ready", nss_ctx);
41 return NSS_TX_FAILURE_NOT_READY;
42 }
43
44 /*
45 * Sanity check the message
46 */
47 if (ncm->interface != NSS_PPPOE_RX_INTERFACE) {
48 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
49 return NSS_TX_FAILURE;
50 }
51
52 if (ncm->type > NSS_PPPOE_MAX) {
53 nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
54 return NSS_TX_FAILURE;
55 }
56
Suruchi Agarwalef8a8702016-01-08 12:40:08 -080057 if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_pppoe_msg)) {
58 nss_warning("%p: message length is invalid: %d", nss_ctx, nss_cmn_get_msg_len(ncm));
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +053059 return NSS_TX_FAILURE;
60 }
61
Pamidipati, Vijayb6e38842014-09-16 10:26:05 +053062 nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE);
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +053063 if (unlikely(!nbuf)) {
Sundarajan Srinivasan62fee7e2015-01-22 11:13:10 -080064 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 +053065 nss_warning("%p: msg dropped as command allocation failed", nss_ctx);
66 return NSS_TX_FAILURE;
67 }
68
69 /*
70 * Copy the message to our skb.
71 */
72 nim2 = (struct nss_pppoe_msg *)skb_put(nbuf, sizeof(struct nss_pppoe_msg));
73 memcpy(nim2, nim, sizeof(struct nss_pppoe_msg));
74
75 status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0);
76 if (status != NSS_CORE_STATUS_SUCCESS) {
Pamidipati, Vijayb6e38842014-09-16 10:26:05 +053077 dev_kfree_skb_any(nbuf);
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +053078 nss_warning("%p: unable to enqueue PPPoE msg\n", nss_ctx);
79 return NSS_TX_FAILURE;
80 }
81
Stephen Wang90c67de2016-04-26 15:15:59 -070082 nss_hal_send_interrupt(nss_ctx, NSS_H2N_INTR_DATA_COMMAND_QUEUE);
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +053083
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/*
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +053096 * nss_pppoe_rx_msg_handler()
97 * Handle NSS -> HLOS messages for PPPoE
98 */
99static void nss_pppoe_rx_msg_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data)
100{
101 struct nss_pppoe_msg *nim = (struct nss_pppoe_msg *)ncm;
102
103 BUG_ON(ncm->interface != NSS_PPPOE_RX_INTERFACE);
104
105 /*
106 * Sanity check the message type
107 */
108 if (ncm->type > NSS_PPPOE_MAX) {
109 nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
110 return;
111 }
112
Suruchi Agarwalef8a8702016-01-08 12:40:08 -0800113 if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_pppoe_msg)) {
114 nss_warning("%p: message length is invalid: %d", nss_ctx, nss_cmn_get_msg_len(ncm));
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530115 return;
116 }
117
118 /*
119 * Log failures
120 */
121 nss_core_log_msg_failures(nss_ctx, ncm);
122
123 /*
124 * Handling PPPoE messages coming from NSS fw.
125 */
126 switch (nim->cm.type) {
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530127 case NSS_PPPOE_RX_NODE_STATS_SYNC:
Yu Huang8c107082017-07-24 14:58:26 -0700128 nss_pppoe_stats_node_sync(nss_ctx, &nim->msg.pppoe_node_stats_sync);
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530129 break;
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530130 case NSS_PPPOE_RX_CONN_STATS_SYNC:
Yu Huang8c107082017-07-24 14:58:26 -0700131 nss_pppoe_stats_exception_sync(nss_ctx, &nim->msg.pppoe_conn_stats_sync);
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530132 break;
Murat Sezgin2f9241a2015-06-25 13:01:51 -0700133 case NSS_PPPOE_RX_SESSION_RESET:
Yu Huang8c107082017-07-24 14:58:26 -0700134 nss_pppoe_stats_session_reset(nss_ctx, &nim->msg.pppoe_session_reset);
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530135 break;
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530136 default:
137 nss_warning("%p: Received response %d for type %d, interface %d",
138 nss_ctx, ncm->response, ncm->type, ncm->interface);
139 }
140}
141
142/*
143 * nss_pppoe_register_handler()
144 */
Thomas Wu91f4bdf2017-06-09 12:03:02 -0700145void nss_pppoe_register_handler(struct nss_ctx_instance *nss_ctx)
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530146{
Thomas Wu91f4bdf2017-06-09 12:03:02 -0700147 nss_core_register_handler(nss_ctx, NSS_PPPOE_RX_INTERFACE, nss_pppoe_rx_msg_handler, NULL);
Yu Huang8c107082017-07-24 14:58:26 -0700148
149 nss_pppoe_stats_dentry_create();
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530150}
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700151
152/*
153 * nss_pppoe_msg_init()
154 * Initialize pppoe message.
155 */
156void 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 -0700157 void *cb, void *app_data)
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700158{
159 nss_cmn_msg_init(&npm->cm, if_num, type, len, (void *)cb, app_data);
160}