Sivanesan Rajapupathi | 5c31b21 | 2016-01-06 16:21:57 -0500 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Kyle Swenson | dd7b296 | 2021-03-16 13:46:32 -0600 | [diff] [blame^] | 3 | * Copyright (c) 2016-2018, 2020 The Linux Foundation. All rights reserved. |
Sivanesan Rajapupathi | 5c31b21 | 2016-01-06 16:21:57 -0500 | [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_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 Shashidhar | a802cc3 | 2018-08-07 11:06:17 -0700 | [diff] [blame] | 28 | #include "nss_oam_log.h" |
Sivanesan Rajapupathi | 5c31b21 | 2016-01-06 16:21:57 -0500 | [diff] [blame] | 29 | |
| 30 | /* |
| 31 | * nss_oam_rx_msg_handler() |
| 32 | * Message handler for OAM messages from NSS |
| 33 | */ |
| 34 | static 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 Shashidhar | a802cc3 | 2018-08-07 11:06:17 -0700 | [diff] [blame] | 40 | * Trace Messages |
| 41 | */ |
| 42 | nss_oam_log_rx_msg(nom); |
| 43 | |
| 44 | /* |
Sivanesan Rajapupathi | 5c31b21 | 2016-01-06 16:21:57 -0500 | [diff] [blame] | 45 | * Sanity check the message type |
| 46 | */ |
Suruchi Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 47 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_oam_msg)) { |
Kyle Swenson | dd7b296 | 2021-03-16 13:46:32 -0600 | [diff] [blame^] | 48 | nss_warning("%px: recevied with invalid msg size: %d", nss_ctx, nss_cmn_get_msg_len(ncm)); |
Sivanesan Rajapupathi | 5c31b21 | 2016-01-06 16:21:57 -0500 | [diff] [blame] | 49 | return; |
| 50 | } |
| 51 | |
| 52 | if (ncm->type > NSS_OAM_MSG_TYPE_MAX) { |
Kyle Swenson | dd7b296 | 2021-03-16 13:46:32 -0600 | [diff] [blame^] | 53 | nss_warning("%px: received with invalid resp type: %d", nss_ctx, ncm->type); |
Sivanesan Rajapupathi | 5c31b21 | 2016-01-06 16:21:57 -0500 | [diff] [blame] | 54 | return; |
| 55 | } |
| 56 | |
| 57 | /* |
| 58 | * Log the failures |
| 59 | */ |
| 60 | nss_core_log_msg_failures(nss_ctx, ncm); |
| 61 | |
Suruchi Agarwal | e4ad24a | 2018-06-11 12:03:46 +0530 | [diff] [blame] | 62 | if (ncm->response == NSS_CMN_RESPONSE_NOTIFY) { |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 63 | ncm->cb = (nss_ptr_t)nss_top_main.oam_callback; |
| 64 | ncm->app_data = (nss_ptr_t)nss_top_main.oam_ctx; |
Sivanesan Rajapupathi | 5c31b21 | 2016-01-06 16:21:57 -0500 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | cb = (nss_oam_msg_callback_t)ncm->cb; |
| 68 | if (unlikely(!cb)) { |
Kyle Swenson | dd7b296 | 2021-03-16 13:46:32 -0600 | [diff] [blame^] | 69 | nss_trace("%px: rx handler has been unregistered for i/f: %d", nss_ctx, ncm->interface); |
Sivanesan Rajapupathi | 5c31b21 | 2016-01-06 16:21:57 -0500 | [diff] [blame] | 70 | 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 | */ |
| 79 | nss_tx_status_t nss_oam_tx_msg(struct nss_ctx_instance *nss_ctx, struct nss_oam_msg *nom) |
| 80 | { |
Sivanesan Rajapupathi | 5c31b21 | 2016-01-06 16:21:57 -0500 | [diff] [blame] | 81 | struct nss_cmn_msg *ncm = &nom->cm; |
Sivanesan Rajapupathi | 5c31b21 | 2016-01-06 16:21:57 -0500 | [diff] [blame] | 82 | |
Sachin Shashidhar | a802cc3 | 2018-08-07 11:06:17 -0700 | [diff] [blame] | 83 | /* |
| 84 | * Trace Messages |
| 85 | */ |
| 86 | nss_oam_log_tx_msg(nom); |
| 87 | |
Sivanesan Rajapupathi | 5c31b21 | 2016-01-06 16:21:57 -0500 | [diff] [blame] | 88 | if (ncm->type > NSS_OAM_MSG_TYPE_MAX) { |
Kyle Swenson | dd7b296 | 2021-03-16 13:46:32 -0600 | [diff] [blame^] | 89 | nss_warning("%px: CMD type for oam module is invalid - %d", nss_ctx, ncm->type); |
Sivanesan Rajapupathi | 5c31b21 | 2016-01-06 16:21:57 -0500 | [diff] [blame] | 90 | return NSS_TX_FAILURE_BAD_PARAM; |
| 91 | } |
| 92 | |
| 93 | if (ncm->interface != NSS_OAM_INTERFACE) { |
Kyle Swenson | dd7b296 | 2021-03-16 13:46:32 -0600 | [diff] [blame^] | 94 | nss_warning("%px: tx message request for another interface: %d", nss_ctx, ncm->interface); |
Sivanesan Rajapupathi | 5c31b21 | 2016-01-06 16:21:57 -0500 | [diff] [blame] | 95 | return NSS_TX_FAILURE; |
| 96 | } |
| 97 | |
Stephen Wang | 3e2dbd1 | 2018-03-14 17:28:17 -0700 | [diff] [blame] | 98 | return nss_core_send_cmd(nss_ctx, nom, sizeof(*nom), NSS_NBUF_PAYLOAD_SIZE); |
Sivanesan Rajapupathi | 5c31b21 | 2016-01-06 16:21:57 -0500 | [diff] [blame] | 99 | } |
| 100 | EXPORT_SYMBOL(nss_oam_tx_msg); |
| 101 | |
| 102 | /* |
| 103 | * nss_oam_notify_register() |
| 104 | * Register to receive OAM events. |
| 105 | */ |
| 106 | struct 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 | } |
| 117 | EXPORT_SYMBOL(nss_oam_notify_register); |
| 118 | |
| 119 | /* |
| 120 | * nss_oam_notify_unregister() |
| 121 | * Unregister to received OAM events. |
| 122 | */ |
| 123 | void nss_oam_notify_unregister(void) |
| 124 | { |
| 125 | nss_top_main.oam_callback = NULL; |
| 126 | nss_top_main.oam_ctx = NULL; |
| 127 | } |
| 128 | EXPORT_SYMBOL(nss_oam_notify_unregister); |
| 129 | |
| 130 | /* |
| 131 | * nss_register_oam_handler() |
| 132 | * Register our handler to receive messages for this interface |
| 133 | */ |
| 134 | void nss_oam_register_handler(void) |
| 135 | { |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 136 | 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 Rajapupathi | 5c31b21 | 2016-01-06 16:21:57 -0500 | [diff] [blame] | 139 | nss_warning("OAM handler failed to register"); |
| 140 | } |
| 141 | } |