blob: baf43d352f71eafff204e35f743a1eeff53ccc34 [file] [log] [blame]
Sivanesan Rajapupathi5c31b212016-01-06 16:21:57 -05001/*
2 **************************************************************************
Kyle Swensondd7b2962021-03-16 13:46:32 -06003 * Copyright (c) 2016-2018, 2020 The Linux Foundation. All rights reserved.
Sivanesan Rajapupathi5c31b212016-01-06 16:21:57 -05004 * 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_oam.c
19 * OAM - Operations, Administration and Maintenance Service for NSS
20 *
21 * This adapter module is responsible for sending and
22 * receiving to and from NSS FW
23 * This file contains the API for communicating NSS FW to send/receive
24 * commands OAM commands.
25 */
26
27#include "nss_tx_rx_common.h"
Sachin Shashidhara802cc32018-08-07 11:06:17 -070028#include "nss_oam_log.h"
Sivanesan Rajapupathi5c31b212016-01-06 16:21:57 -050029
30/*
31 * nss_oam_rx_msg_handler()
32 * Message handler for OAM messages from NSS
33 */
34static void nss_oam_rx_msg_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused)) void *app_data)
35{
36 struct nss_oam_msg *nom = (struct nss_oam_msg *)ncm;
37 nss_oam_msg_callback_t cb;
38
39 /*
Sachin Shashidhara802cc32018-08-07 11:06:17 -070040 * Trace Messages
41 */
42 nss_oam_log_rx_msg(nom);
43
44 /*
Sivanesan Rajapupathi5c31b212016-01-06 16:21:57 -050045 * Sanity check the message type
46 */
Suruchi Agarwalef8a8702016-01-08 12:40:08 -080047 if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_oam_msg)) {
Kyle Swensondd7b2962021-03-16 13:46:32 -060048 nss_warning("%px: recevied with invalid msg size: %d", nss_ctx, nss_cmn_get_msg_len(ncm));
Sivanesan Rajapupathi5c31b212016-01-06 16:21:57 -050049 return;
50 }
51
52 if (ncm->type > NSS_OAM_MSG_TYPE_MAX) {
Kyle Swensondd7b2962021-03-16 13:46:32 -060053 nss_warning("%px: received with invalid resp type: %d", nss_ctx, ncm->type);
Sivanesan Rajapupathi5c31b212016-01-06 16:21:57 -050054 return;
55 }
56
57 /*
58 * Log the failures
59 */
60 nss_core_log_msg_failures(nss_ctx, ncm);
61
Suruchi Agarwale4ad24a2018-06-11 12:03:46 +053062 if (ncm->response == NSS_CMN_RESPONSE_NOTIFY) {
Stephen Wangaed46332016-12-12 17:29:03 -080063 ncm->cb = (nss_ptr_t)nss_top_main.oam_callback;
64 ncm->app_data = (nss_ptr_t)nss_top_main.oam_ctx;
Sivanesan Rajapupathi5c31b212016-01-06 16:21:57 -050065 }
66
67 cb = (nss_oam_msg_callback_t)ncm->cb;
68 if (unlikely(!cb)) {
Kyle Swensondd7b2962021-03-16 13:46:32 -060069 nss_trace("%px: rx handler has been unregistered for i/f: %d", nss_ctx, ncm->interface);
Sivanesan Rajapupathi5c31b212016-01-06 16:21:57 -050070 return;
71 }
72 cb((void *)ncm->app_data, nom);
73}
74
75/*
76 * nss_oam_tx()
77 * Transmit an oam message to the FW.
78 */
79nss_tx_status_t nss_oam_tx_msg(struct nss_ctx_instance *nss_ctx, struct nss_oam_msg *nom)
80{
Sivanesan Rajapupathi5c31b212016-01-06 16:21:57 -050081 struct nss_cmn_msg *ncm = &nom->cm;
Sivanesan Rajapupathi5c31b212016-01-06 16:21:57 -050082
Sachin Shashidhara802cc32018-08-07 11:06:17 -070083 /*
84 * Trace Messages
85 */
86 nss_oam_log_tx_msg(nom);
87
Sivanesan Rajapupathi5c31b212016-01-06 16:21:57 -050088 if (ncm->type > NSS_OAM_MSG_TYPE_MAX) {
Kyle Swensondd7b2962021-03-16 13:46:32 -060089 nss_warning("%px: CMD type for oam module is invalid - %d", nss_ctx, ncm->type);
Sivanesan Rajapupathi5c31b212016-01-06 16:21:57 -050090 return NSS_TX_FAILURE_BAD_PARAM;
91 }
92
93 if (ncm->interface != NSS_OAM_INTERFACE) {
Kyle Swensondd7b2962021-03-16 13:46:32 -060094 nss_warning("%px: tx message request for another interface: %d", nss_ctx, ncm->interface);
Sivanesan Rajapupathi5c31b212016-01-06 16:21:57 -050095 return NSS_TX_FAILURE;
96 }
97
Stephen Wang3e2dbd12018-03-14 17:28:17 -070098 return nss_core_send_cmd(nss_ctx, nom, sizeof(*nom), NSS_NBUF_PAYLOAD_SIZE);
Sivanesan Rajapupathi5c31b212016-01-06 16:21:57 -050099}
100EXPORT_SYMBOL(nss_oam_tx_msg);
101
102/*
103 * nss_oam_notify_register()
104 * Register to receive OAM events.
105 */
106struct nss_ctx_instance *nss_oam_notify_register(nss_oam_msg_callback_t cb, void *app_data)
107{
108 if (nss_top_main.oam_ctx || nss_top_main.oam_callback) {
109 nss_warning("Failed to register notify callback - already registered\n");
110 return NULL;
111 }
112
113 nss_top_main.oam_ctx = app_data;
114 nss_top_main.oam_callback = cb;
115 return &nss_top_main.nss[nss_top_main.oam_handler_id];
116}
117EXPORT_SYMBOL(nss_oam_notify_register);
118
119/*
120 * nss_oam_notify_unregister()
121 * Unregister to received OAM events.
122 */
123void nss_oam_notify_unregister(void)
124{
125 nss_top_main.oam_callback = NULL;
126 nss_top_main.oam_ctx = NULL;
127}
128EXPORT_SYMBOL(nss_oam_notify_unregister);
129
130/*
131 * nss_register_oam_handler()
132 * Register our handler to receive messages for this interface
133 */
134void nss_oam_register_handler(void)
135{
Thomas Wu91f4bdf2017-06-09 12:03:02 -0700136 struct nss_ctx_instance *nss_ctx = &nss_top_main.nss[nss_top_main.oam_handler_id];
137
138 if (nss_core_register_handler(nss_ctx, NSS_OAM_INTERFACE, nss_oam_rx_msg_handler, NULL) != NSS_CORE_STATUS_SUCCESS) {
Sivanesan Rajapupathi5c31b212016-01-06 16:21:57 -0500139 nss_warning("OAM handler failed to register");
140 }
141}