Sivanesan Rajapupathi | 5c31b21 | 2016-01-06 16:21:57 -0500 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Stephen Wang | 3e2dbd1 | 2018-03-14 17:28:17 -0700 | [diff] [blame^] | 3 | * Copyright (c) 2016-2018 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" |
| 28 | |
| 29 | /* |
| 30 | * nss_oam_rx_msg_handler() |
| 31 | * Message handler for OAM messages from NSS |
| 32 | */ |
| 33 | static void nss_oam_rx_msg_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused)) void *app_data) |
| 34 | { |
| 35 | struct nss_oam_msg *nom = (struct nss_oam_msg *)ncm; |
| 36 | nss_oam_msg_callback_t cb; |
| 37 | |
| 38 | /* |
| 39 | * Sanity check the message type |
| 40 | */ |
Suruchi Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 41 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_oam_msg)) { |
| 42 | nss_warning("%p: 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] | 43 | return; |
| 44 | } |
| 45 | |
| 46 | if (ncm->type > NSS_OAM_MSG_TYPE_MAX) { |
| 47 | nss_warning("%p: received with invalid resp type: %d", nss_ctx, ncm->type); |
| 48 | return; |
| 49 | } |
| 50 | |
| 51 | /* |
| 52 | * Log the failures |
| 53 | */ |
| 54 | nss_core_log_msg_failures(nss_ctx, ncm); |
| 55 | |
| 56 | if (ncm->response == NSS_CMM_RESPONSE_NOTIFY) { |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 57 | ncm->cb = (nss_ptr_t)nss_top_main.oam_callback; |
| 58 | ncm->app_data = (nss_ptr_t)nss_top_main.oam_ctx; |
Sivanesan Rajapupathi | 5c31b21 | 2016-01-06 16:21:57 -0500 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | cb = (nss_oam_msg_callback_t)ncm->cb; |
| 62 | if (unlikely(!cb)) { |
| 63 | nss_trace("%p: rx handler has been unregistered for i/f: %d", nss_ctx, ncm->interface); |
| 64 | return; |
| 65 | } |
| 66 | cb((void *)ncm->app_data, nom); |
| 67 | } |
| 68 | |
| 69 | /* |
| 70 | * nss_oam_tx() |
| 71 | * Transmit an oam message to the FW. |
| 72 | */ |
| 73 | nss_tx_status_t nss_oam_tx_msg(struct nss_ctx_instance *nss_ctx, struct nss_oam_msg *nom) |
| 74 | { |
Sivanesan Rajapupathi | 5c31b21 | 2016-01-06 16:21:57 -0500 | [diff] [blame] | 75 | struct nss_cmn_msg *ncm = &nom->cm; |
Sivanesan Rajapupathi | 5c31b21 | 2016-01-06 16:21:57 -0500 | [diff] [blame] | 76 | |
| 77 | if (ncm->type > NSS_OAM_MSG_TYPE_MAX) { |
| 78 | nss_warning("%p: CMD type for oam module is invalid - %d", nss_ctx, ncm->type); |
| 79 | return NSS_TX_FAILURE_BAD_PARAM; |
| 80 | } |
| 81 | |
| 82 | if (ncm->interface != NSS_OAM_INTERFACE) { |
| 83 | nss_warning("%p: tx message request for another interface: %d", nss_ctx, ncm->interface); |
| 84 | return NSS_TX_FAILURE; |
| 85 | } |
| 86 | |
Stephen Wang | 3e2dbd1 | 2018-03-14 17:28:17 -0700 | [diff] [blame^] | 87 | 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] | 88 | } |
| 89 | EXPORT_SYMBOL(nss_oam_tx_msg); |
| 90 | |
| 91 | /* |
| 92 | * nss_oam_notify_register() |
| 93 | * Register to receive OAM events. |
| 94 | */ |
| 95 | struct nss_ctx_instance *nss_oam_notify_register(nss_oam_msg_callback_t cb, void *app_data) |
| 96 | { |
| 97 | if (nss_top_main.oam_ctx || nss_top_main.oam_callback) { |
| 98 | nss_warning("Failed to register notify callback - already registered\n"); |
| 99 | return NULL; |
| 100 | } |
| 101 | |
| 102 | nss_top_main.oam_ctx = app_data; |
| 103 | nss_top_main.oam_callback = cb; |
| 104 | return &nss_top_main.nss[nss_top_main.oam_handler_id]; |
| 105 | } |
| 106 | EXPORT_SYMBOL(nss_oam_notify_register); |
| 107 | |
| 108 | /* |
| 109 | * nss_oam_notify_unregister() |
| 110 | * Unregister to received OAM events. |
| 111 | */ |
| 112 | void nss_oam_notify_unregister(void) |
| 113 | { |
| 114 | nss_top_main.oam_callback = NULL; |
| 115 | nss_top_main.oam_ctx = NULL; |
| 116 | } |
| 117 | EXPORT_SYMBOL(nss_oam_notify_unregister); |
| 118 | |
| 119 | /* |
| 120 | * nss_register_oam_handler() |
| 121 | * Register our handler to receive messages for this interface |
| 122 | */ |
| 123 | void nss_oam_register_handler(void) |
| 124 | { |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 125 | struct nss_ctx_instance *nss_ctx = &nss_top_main.nss[nss_top_main.oam_handler_id]; |
| 126 | |
| 127 | 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] | 128 | nss_warning("OAM handler failed to register"); |
| 129 | } |
| 130 | } |