Ankit Dhanuka | a1569ce | 2014-05-13 19:58:06 +0530 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 3 | * Copyright (c) 2013-2017, The Linux Foundation. All rights reserved. |
Ankit Dhanuka | a1569ce | 2014-05-13 19:58:06 +0530 | [diff] [blame] | 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_pppoe.c |
| 19 | * NSS PPPoE APIs |
| 20 | */ |
| 21 | |
| 22 | #include "nss_tx_rx_common.h" |
Murat Sezgin | d80f3bd | 2014-12-10 15:38:06 -0800 | [diff] [blame] | 23 | #include <linux/if_pppox.h> |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 24 | #include "nss_pppoe_stats.h" |
Ankit Dhanuka | a1569ce | 2014-05-13 19:58:06 +0530 | [diff] [blame] | 25 | |
Ankit Dhanuka | a1569ce | 2014-05-13 19:58:06 +0530 | [diff] [blame] | 26 | /* |
| 27 | * nss_pppoe_tx() |
| 28 | * Transmit an PPPoe message to the FW. |
| 29 | */ |
| 30 | nss_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 Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 57 | 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 Dhanuka | a1569ce | 2014-05-13 19:58:06 +0530 | [diff] [blame] | 59 | return NSS_TX_FAILURE; |
| 60 | } |
| 61 | |
Pamidipati, Vijay | b6e3884 | 2014-09-16 10:26:05 +0530 | [diff] [blame] | 62 | nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE); |
Ankit Dhanuka | a1569ce | 2014-05-13 19:58:06 +0530 | [diff] [blame] | 63 | if (unlikely(!nbuf)) { |
Sundarajan Srinivasan | 62fee7e | 2015-01-22 11:13:10 -0800 | [diff] [blame] | 64 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]); |
Ankit Dhanuka | a1569ce | 2014-05-13 19:58:06 +0530 | [diff] [blame] | 65 | 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, Vijay | b6e3884 | 2014-09-16 10:26:05 +0530 | [diff] [blame] | 77 | dev_kfree_skb_any(nbuf); |
Ankit Dhanuka | a1569ce | 2014-05-13 19:58:06 +0530 | [diff] [blame] | 78 | nss_warning("%p: unable to enqueue PPPoE msg\n", nss_ctx); |
| 79 | return NSS_TX_FAILURE; |
| 80 | } |
| 81 | |
Stephen Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 82 | nss_hal_send_interrupt(nss_ctx, NSS_H2N_INTR_DATA_COMMAND_QUEUE); |
Ankit Dhanuka | a1569ce | 2014-05-13 19:58:06 +0530 | [diff] [blame] | 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 | /* |
Ankit Dhanuka | a1569ce | 2014-05-13 19:58:06 +0530 | [diff] [blame] | 96 | * nss_pppoe_rx_msg_handler() |
| 97 | * Handle NSS -> HLOS messages for PPPoE |
| 98 | */ |
| 99 | static 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 Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 113 | 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 Dhanuka | a1569ce | 2014-05-13 19:58:06 +0530 | [diff] [blame] | 115 | 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 Dhanuka | a1569ce | 2014-05-13 19:58:06 +0530 | [diff] [blame] | 127 | case NSS_PPPOE_RX_NODE_STATS_SYNC: |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 128 | nss_pppoe_stats_node_sync(nss_ctx, &nim->msg.pppoe_node_stats_sync); |
Ankit Dhanuka | a1569ce | 2014-05-13 19:58:06 +0530 | [diff] [blame] | 129 | break; |
Ankit Dhanuka | a1569ce | 2014-05-13 19:58:06 +0530 | [diff] [blame] | 130 | case NSS_PPPOE_RX_CONN_STATS_SYNC: |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 131 | nss_pppoe_stats_exception_sync(nss_ctx, &nim->msg.pppoe_conn_stats_sync); |
Ankit Dhanuka | a1569ce | 2014-05-13 19:58:06 +0530 | [diff] [blame] | 132 | break; |
Murat Sezgin | 2f9241a | 2015-06-25 13:01:51 -0700 | [diff] [blame] | 133 | case NSS_PPPOE_RX_SESSION_RESET: |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 134 | nss_pppoe_stats_session_reset(nss_ctx, &nim->msg.pppoe_session_reset); |
Ankit Dhanuka | a1569ce | 2014-05-13 19:58:06 +0530 | [diff] [blame] | 135 | break; |
Ankit Dhanuka | a1569ce | 2014-05-13 19:58:06 +0530 | [diff] [blame] | 136 | 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 Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 145 | void nss_pppoe_register_handler(struct nss_ctx_instance *nss_ctx) |
Ankit Dhanuka | a1569ce | 2014-05-13 19:58:06 +0530 | [diff] [blame] | 146 | { |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 147 | nss_core_register_handler(nss_ctx, NSS_PPPOE_RX_INTERFACE, nss_pppoe_rx_msg_handler, NULL); |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 148 | |
| 149 | nss_pppoe_stats_dentry_create(); |
Ankit Dhanuka | a1569ce | 2014-05-13 19:58:06 +0530 | [diff] [blame] | 150 | } |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 151 | |
| 152 | /* |
| 153 | * nss_pppoe_msg_init() |
| 154 | * Initialize pppoe message. |
| 155 | */ |
| 156 | void nss_pppoe_msg_init(struct nss_pppoe_msg *npm, uint16_t if_num, uint32_t type, uint32_t len, |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 157 | void *cb, void *app_data) |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 158 | { |
| 159 | nss_cmn_msg_init(&npm->cm, if_num, type, len, (void *)cb, app_data); |
| 160 | } |