[qca-nss-drv] Added support for client map interface
Change-Id: I4439780c5874e986742f62081a78a07c1806708b
Signed-off-by: Suman Ghosh <sumaghos@codeaurora.org>
Signed-off-by: Suruchi Suman <surusuma@codeaurora.org>
diff --git a/Makefile b/Makefile
index 0fd7b9f..f7bda00 100644
--- a/Makefile
+++ b/Makefile
@@ -18,6 +18,9 @@
nss_capwap.o \
nss_capwap_log.o \
nss_capwap_stats.o \
+ nss_clmap.o \
+ nss_clmap_log.o \
+ nss_clmap_stats.o \
nss_cmn.o \
nss_core.o \
nss_coredump.o \
diff --git a/exports/nss_api_if.h b/exports/nss_api_if.h
index 8ed1aff..09de8c2 100644
--- a/exports/nss_api_if.h
+++ b/exports/nss_api_if.h
@@ -79,6 +79,7 @@
#include "nss_freq.h"
#include "nss_tstamp.h"
#include "nss_gre_redir_mark.h"
+#include "nss_clmap.h"
#endif
/**
diff --git a/exports/nss_clmap.h b/exports/nss_clmap.h
new file mode 100644
index 0000000..5748e8e
--- /dev/null
+++ b/exports/nss_clmap.h
@@ -0,0 +1,296 @@
+/*
+ **************************************************************************
+ * Copyright (c) 2019, The Linux Foundation. All rights reserved.
+ * Permission to use, copy, modify, and/or distribute this software for
+ * any purpose with or without fee is hereby granted, provided that the
+ * above copyright notice and this permission notice appear in all copies.
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ **************************************************************************
+ */
+
+/*
+ * @file nss_clmap.h
+ * NSS client map interface definitions.
+ */
+
+#ifndef __NSS_CLMAP_H
+#define __NSS_CLMAP_H
+
+/**
+ * Maximum number of supported client map interface.
+ */
+#define NSS_CLMAP_MAX_INTERFACES 1
+
+/**
+ * nss_clmap_msg_type
+ * Client map message types.
+ */
+typedef enum nss_clmap_msg_type {
+ NSS_CLMAP_MSG_TYPE_SYNC_STATS, /**< Statistics synchronization message. */
+ NSS_CLMAP_MSG_TYPE_INTERFACE_ENABLE, /**< Enable the interface. */
+ NSS_CLMAP_MSG_TYPE_INTERFACE_DISABLE, /**< Disable the interface. */
+ NSS_CLMAP_MSG_TYPE_MAC_ADD, /**< Add MAC rule to the database. */
+ NSS_CLMAP_MSG_TYPE_MAC_DEL, /**< Remove MAC rule from the database. */
+ NSS_CLMAP_MSG_TYPE_MAC_FLUSH, /**< Flush all the MAC rules for a tunnel. */
+ NSS_CLMAP_MSG_TYPE_MAX, /**< Maximum message type. */
+} nss_clmap_msg_type_t;
+
+/**
+ * nss_clmap_error_types
+ * Error types for client map responses to messages from the host.
+ */
+typedef enum nss_clmap_error_types {
+ NSS_CLMAP_ERROR_UNKNOWN_TYPE = 1, /**< Unknown type error. */
+ NSS_CLMAP_ERROR_INTERFACE_DISABLED, /**< Interface is already disabled. */
+ NSS_CLMAP_ERROR_INTERFACE_ENABLED, /**< Interface is already enabled. */
+ NSS_CLMAP_ERROR_INVALID_VLAN, /**< Invalid VLAN. */
+ NSS_CLMAP_ERROR_INVALID_TUNNEL, /**< Invalid tunnel. */
+ NSS_CLMAP_ERROR_MAC_TABLE_FULL, /**< MAC table is full. */
+ NSS_CLMAP_ERROR_MAC_EXIST, /**< MAC does already exist in the table. */
+ NSS_CLMAP_ERROR_MAC_NOT_EXIST, /**< MAC does not exist in the table. */
+ NSS_CLMAP_ERROR_MAC_ENTRY_UNHASHED, /**< MAC entry is not hashed in table. */
+ NSS_CLMAP_ERROR_MAC_ENTRY_INSERT_FAILED,
+ /**< Insertion into MAC table failed. */
+ NSS_CLMAP_ERROR_MAC_ENTRY_ALLOC_FAILED, /**< MAC entry allocation failed. */
+ NSS_CLMAP_ERROR_MAC_ENTRY_DELETE_FAILED,/**< MAC entry deletion failed. */
+ NSS_CLMAP_ERROR_MAX, /**< Maximum error type. */
+} nss_clmap_error_t;
+
+/**
+ * nss_clmap_stats_msg
+ * Per-interface statistics messages from the NSS firmware.
+ */
+struct nss_clmap_stats_msg {
+ struct nss_cmn_node_stats node_stats; /**< Common firmware statistics. */
+ uint32_t dropped_macdb_lookup_failed; /**< Dropped due to MAC database look up failed. */
+ uint32_t dropped_invalid_packet_size; /**< Dropped due to invalid size packets. */
+ uint32_t dropped_low_hroom; /**< Dropped due to insufficent headroom. */
+ uint32_t dropped_next_node_queue_full; /**< Dropped due to next node queue full. */
+ uint32_t dropped_pbuf_alloc_failed; /**< Dropped due to buffer allocation failure. */
+ uint32_t dropped_linear_failed; /**< Dropped due to liner copy failure. */
+ uint32_t shared_packet_count; /**< Shared packet count. */
+ uint32_t ethernet_frame_error; /**< Ethernet frame error count. */
+};
+
+/**
+ * nss_clmap_mac_msg
+ * CLient map MAC message structure.
+ */
+struct nss_clmap_mac_msg {
+ uint32_t vlan_id; /**< VLAN ID. */
+ uint32_t nexthop_ifnum; /**< Next hop interface number. */
+ uint32_t needed_headroom; /**< Headroom to be added. */
+ uint16_t mac_addr[3]; /**< MAC address. */
+ uint8_t flags; /**< Flags that carry metadata information. */
+ uint8_t reserved; /**< Reserved. */
+};
+
+/**
+ * nss_clmap_flush_mac_msg
+ * CLient flush map MAC message structure.
+ */
+struct nss_clmap_flush_mac_msg {
+ uint32_t nexthop_ifnum; /**< Next hop interface number. */
+};
+
+/**
+ * nss_clmap_msg
+ * Data for sending and receiving client map messages.
+ */
+struct nss_clmap_msg {
+ struct nss_cmn_msg cm; /**< Common message header. */
+
+ /**
+ * Payload of a client map common message.
+ */
+ union {
+ struct nss_clmap_stats_msg stats;
+ /**< Client map statistics. */
+ struct nss_clmap_mac_msg mac_add;
+ /**< MAC rule add message. */
+ struct nss_clmap_mac_msg mac_del;
+ /**< MAC rule delete message. */
+ struct nss_clmap_flush_mac_msg mac_flush;
+ /**< MAC rule flush message. */
+ } msg; /**< Message payload. */
+};
+
+/**
+ * Callback function for receiving client map data.
+ *
+ * @datatypes
+ * net_device \n
+ * sk_buff \n
+ * napi_struct
+ *
+ * @param[in] netdev Pointer to the associated network device.
+ * @param[in] skb Pointer to the data socket buffer.
+ * @param[in] napi Pointer to the NAPI structure.
+ */
+typedef void (*nss_clmap_buf_callback_t)(struct net_device *netdev, struct sk_buff *skb, struct napi_struct *napi);
+
+/**
+ * Callback function for receiving client map messages.
+ *
+ * @datatypes
+ * nss_cmn_msg
+ *
+ * @param[in] app_data Pointer to the application context of the message.
+ * @param[in] msg Pointer to the message data.
+ */
+typedef void (*nss_clmap_msg_callback_t)(void *app_data, struct nss_cmn_msg *msg);
+
+/**
+ * nss_clmap_tx_msg
+ * Sends client map messages to the NSS.
+ *
+ * Do not call this function from a softirq or interrupt because it
+ * might sleep if the NSS firmware is busy serving another host thread.
+ *
+ * @datatypes
+ * nss_ctx_instance \n
+ * nss_clmap_msg
+ *
+ * @param[in] nss_ctx Pointer to the NSS context.
+ * @param[in,out] msg Pointer to the message data.
+ *
+ * @return
+ * Status of the Tx operation.
+ */
+extern nss_tx_status_t nss_clmap_tx_msg(struct nss_ctx_instance *nss_ctx, struct nss_clmap_msg *msg);
+
+/**
+ * nss_clmap_tx_msg_sync
+ * Sends client map messages to the NSS.
+ *
+ * Do not call this function from a softirq or interrupt because it
+ * might sleep if the NSS firmware is busy serving another host thread.
+ *
+ * @datatypes
+ * nss_ctx_instance \n
+ * nss_clmap_msg
+ *
+ * @param[in] nss_ctx Pointer to the NSS context.
+ * @param[in,out] msg Pointer to the message data.
+ *
+ * @return
+ * Status of the Tx operation.
+ */
+extern nss_tx_status_t nss_clmap_tx_msg_sync(struct nss_ctx_instance *nss_ctx, struct nss_clmap_msg *msg);
+
+/**
+ * nss_clmap_tx_buf
+ * Sends a client map data buffer to the NSS interface.
+ *
+ * @datatypes
+ * nss_ctx_instance \n
+ * sk_buff
+ *
+ * @param[in] nss_ctx Pointer to the NSS context.
+ * @param[in] os_buf Pointer to the data buffer.
+ * @param[in] if_num NSS interface number.
+ *
+ * @return
+ * Status of the Tx operation.
+ */
+extern nss_tx_status_t nss_clmap_tx_buf(struct nss_ctx_instance *nss_ctx, struct sk_buff *buf, uint32_t if_num);
+
+/**
+ * nss_clmap_unregister
+ * Deregisters the client map interface from the NSS interface.
+ *
+ * @param[in] if_num NSS interface number.
+ *
+ * @return
+ * TRUE or FALSE
+ *
+ * @dependencies
+ * The interface must have been previously registered.
+ */
+extern bool nss_clmap_unregister(uint32_t if_num);
+
+/**
+ * nss_clmap_register
+ * Registers the client map interface with the NSS for sending and
+ * receiving interface messages.
+ *
+ * @datatypes
+ * nss_clmap_msg_callback_t \n
+ * nss_clmap_buf_callback_t \n
+ * net_device
+ *
+ * @param[in] if_num NSS interface number.
+ * @param[in] dynamic_interface_type NSS interface type.
+ * @param[in] data_cb Data callback for the client map data.
+ * @param[in] notify_cb Notify callback for the client map data.
+ * @param[in] netdev Pointer to the associated network device.
+ * @param[in] features Data socket buffer types supported by this interface.
+ *
+ * @return
+ * Pointer to the NSS core context.
+ */
+extern struct nss_ctx_instance *nss_clmap_register(uint32_t if_num, uint32_t dynamic_interface_type,
+ nss_clmap_buf_callback_t data_cb, nss_clmap_msg_callback_t notify_cb,
+ struct net_device *netdev, uint32_t features);
+
+/**
+ * nss_clmap_get_ctx
+ * Get the NSS context.
+ *
+ * @return
+ * Pointer to the NSS core context.
+ */
+extern struct nss_ctx_instance *nss_clmap_get_ctx(void);
+
+/**
+ * nss_clmap_ifnum_with_core_id
+ * Gets the client map interface number with the core ID.
+ *
+ * @param[in] if_num NSS interface number.
+ *
+ * @return
+ * Interface number with the core ID.
+ */
+extern int nss_clmap_ifnum_with_core_id(int if_num);
+
+/**
+ * nss_clmap_init
+ * Initializes the client map interface.
+ *
+ * @return
+ * None.
+ */
+extern void nss_clmap_init(void);
+
+/**
+ * nss_clmap_msg_init
+ * Initializes a client map message.
+ *
+ * @datatypes
+ * nss_clmap_msg \n
+ * nss_clmap_msg_callback_t
+ *
+ * @param[in,out] ncm Pointer to the message.
+ * @param[in] if_num NSS interface number.
+ * @param[in] type Type of message.
+ * @param[in] len Size of the payload.
+ * @param[in] cb Callback function for the message.
+ * @param[in] app_data Pointer to the application context of the message.
+ *
+ * @return
+ * None.
+ */
+extern void nss_clmap_msg_init(struct nss_clmap_msg *ncm, uint16_t if_num, uint32_t type, uint32_t len,
+ nss_clmap_msg_callback_t cb, void *app_data);
+
+/**
+ * @}
+ */
+
+#endif /* __NSS_CLMAP_H */
diff --git a/nss_clmap.c b/nss_clmap.c
new file mode 100644
index 0000000..a76fd64
--- /dev/null
+++ b/nss_clmap.c
@@ -0,0 +1,325 @@
+/*
+ **************************************************************************
+ * Copyright (c) 2019, The Linux Foundation. All rights reserved.
+ * Permission to use, copy, modify, and/or distribute this software for
+ * any purpose with or without fee is hereby granted, provided that the
+ * above copyright notice and this permission notice appear in all copies.
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ **************************************************************************
+ */
+
+ /*
+ * nss_clmap.c
+ * NSS clmap driver interface APIs
+ */
+#include "nss_core.h"
+#include "nss_clmap.h"
+#include "nss_cmn.h"
+#include "nss_tx_rx_common.h"
+#include "nss_clmap_stats.h"
+#include "nss_clmap_log.h"
+
+#define NSS_CLMAP_TX_TIMEOUT 3000
+
+/*
+ * Private data structure
+ */
+static struct nss_clmap_pvt {
+ struct semaphore sem; /* Semaphore structure. */
+ struct completion complete; /* Completion structure. */
+ int response; /* Response from FW. */
+ void *cb; /* Original cb for msgs. */
+ void *app_data; /* Original app_data for msgs. */
+} clmap_pvt;
+
+/*
+ * nss_clmap_verify_if_num()
+ * Verify if_num passed to us.
+ */
+static bool nss_clmap_verify_if_num(uint32_t if_num)
+{
+ uint32_t type = nss_dynamic_interface_get_type(nss_clmap_get_ctx(), if_num);
+
+ return ((type == NSS_DYNAMIC_INTERFACE_TYPE_CLMAP_US) ||
+ (type == NSS_DYNAMIC_INTERFACE_TYPE_CLMAP_DS));
+}
+
+/*
+ * nss_clmap_callback()
+ * Callback to handle the completion of NSS->HLOS messages.
+ */
+static void nss_clmap_callback(void *app_data, struct nss_clmap_msg *nclm)
+{
+ clmap_pvt.response = NSS_TX_SUCCESS;
+ clmap_pvt.cb = NULL;
+ clmap_pvt.app_data = NULL;
+
+ if (nclm->cm.response != NSS_CMN_RESPONSE_ACK) {
+ nss_warning("clmap Error response %d\n", nclm->cm.response);
+ clmap_pvt.response = nclm->cm.response;
+ }
+
+ /*
+ * Write memory barrier.
+ */
+ smp_wmb();
+ complete(&clmap_pvt.complete);
+}
+
+/*
+ * nss_clmap_handler()
+ * Handle NSS -> HLOS messages for clmap.
+ */
+static void nss_clmap_msg_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data)
+{
+ struct nss_clmap_msg *nclm = (struct nss_clmap_msg *)ncm;
+ nss_clmap_msg_callback_t cb;
+
+ BUG_ON(!nss_clmap_verify_if_num(ncm->interface));
+ NSS_VERIFY_CTX_MAGIC(nss_ctx);
+
+ /*
+ * Is this a valid request/response packet?
+ */
+ if (ncm->type >= NSS_CLMAP_MSG_TYPE_MAX) {
+ nss_warning("%p: received invalid message %d for clmap interface", nss_ctx, ncm->type);
+ return;
+ }
+
+ if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_clmap_msg)) {
+ nss_warning("%p: Length of message is greater than required: %d", nss_ctx, nss_cmn_get_msg_len(ncm));
+ return;
+ }
+
+ /*
+ * Trace messages.
+ */
+ nss_core_log_msg_failures(nss_ctx, ncm);
+ nss_clmap_log_rx_msg(nclm);
+
+ switch (nclm->cm.type) {
+ case NSS_CLMAP_MSG_TYPE_SYNC_STATS:
+ nss_clmap_stats_sync(nss_ctx, &nclm->msg.stats, ncm->interface);
+ break;
+ }
+
+ /*
+ * Update the callback and app_data for NOTIFY messages.
+ */
+ if (ncm->response == NSS_CMN_RESPONSE_NOTIFY) {
+ ncm->cb = (nss_ptr_t)nss_top_main.if_rx_msg_callback[ncm->interface];
+ ncm->app_data = (nss_ptr_t)nss_ctx->nss_rx_interface_handlers[nss_ctx->id][ncm->interface].app_data;
+ }
+
+ /*
+ * Do we have a callback
+ */
+ cb = (nss_clmap_msg_callback_t)ncm->cb;
+ if (!cb) {
+ nss_trace("%p: cb is null for interface %d", nss_ctx, ncm->interface);
+ return;
+ }
+
+ cb((void *)ncm->app_data, ncm);
+}
+
+/*
+ * nss_clmap_tx_msg()
+ * Transmit a clmap message to NSS FW. Don't call this from softirq/interrupts.
+ */
+nss_tx_status_t nss_clmap_tx_msg(struct nss_ctx_instance *nss_ctx, struct nss_clmap_msg *msg)
+{
+ struct nss_cmn_msg *ncm = &msg->cm;
+
+ if (!nss_clmap_verify_if_num(msg->cm.interface)) {
+ return NSS_TX_FAILURE_BAD_PARAM;
+ }
+
+ if (ncm->type >= NSS_CLMAP_MSG_TYPE_MAX) {
+ return NSS_TX_FAILURE_BAD_PARAM;
+ }
+
+ /*
+ * Trace messages.
+ */
+ nss_clmap_log_tx_msg(msg);
+
+ return nss_core_send_cmd(nss_ctx, msg, sizeof(*msg), NSS_NBUF_PAYLOAD_SIZE);
+}
+EXPORT_SYMBOL(nss_clmap_tx_msg);
+
+/*
+ * nss_clmap_tx_msg_sync()
+ * Transmit a clmap message to NSS firmware synchronously.
+ */
+nss_tx_status_t nss_clmap_tx_msg_sync(struct nss_ctx_instance *nss_ctx, struct nss_clmap_msg *nclm)
+{
+ nss_tx_status_t status;
+ int ret;
+
+ down(&clmap_pvt.sem);
+ nclm->cm.cb = (nss_ptr_t)nss_clmap_callback;
+ nclm->cm.app_data = (nss_ptr_t)NULL;
+
+ status = nss_clmap_tx_msg(nss_ctx, nclm);
+ if (status != NSS_TX_SUCCESS) {
+ nss_warning("%p: clmap_tx_msg failed\n", nss_ctx);
+ up(&clmap_pvt.sem);
+ return status;
+ }
+
+ ret = wait_for_completion_timeout(&clmap_pvt.complete, msecs_to_jiffies(NSS_CLMAP_TX_TIMEOUT));
+ if (!ret) {
+ nss_warning("%p: clmap tx sync failed due to timeout\n", nss_ctx);
+ clmap_pvt.response = NSS_TX_FAILURE;
+ }
+
+ status = clmap_pvt.response;
+ up(&clmap_pvt.sem);
+ return status;
+}
+EXPORT_SYMBOL(nss_clmap_tx_msg_sync);
+
+/*
+ * nss_clmap_tx_buf()
+ * Transmit data buffer (skb) to a NSS interface number
+ */
+nss_tx_status_t nss_clmap_tx_buf(struct nss_ctx_instance *nss_ctx, struct sk_buff *buf, uint32_t if_num)
+{
+ BUG_ON(!nss_clmap_verify_if_num(if_num));
+
+ return nss_core_send_packet(nss_ctx, buf, if_num, H2N_BIT_FLAG_VIRTUAL_BUFFER);
+}
+EXPORT_SYMBOL(nss_clmap_tx_buf);
+
+/*
+ * nss_clmap_unregister()
+ * Un-register a clmap interface from NSS.
+ */
+bool nss_clmap_unregister(uint32_t if_num)
+{
+ struct nss_ctx_instance *nss_ctx;
+
+ nss_ctx = nss_clmap_get_ctx();
+ NSS_VERIFY_CTX_MAGIC(nss_ctx);
+
+ if (!nss_clmap_verify_if_num(if_num)) {
+ nss_warning("%p: clmap unregister request received for invalid interface %d", nss_ctx, if_num);
+ return false;
+ }
+
+ nss_clmap_stats_session_unregister(if_num);
+ nss_core_unregister_handler(nss_ctx, if_num);
+ nss_core_unregister_subsys_dp(nss_ctx, if_num);
+ nss_top_main.if_rx_msg_callback[if_num] = NULL;
+
+ return true;
+}
+EXPORT_SYMBOL(nss_clmap_unregister);
+
+/*
+ * nss_clmap_register()
+ * Registers a clmap interface with the NSS.
+ */
+struct nss_ctx_instance *nss_clmap_register(uint32_t if_num,
+ uint32_t di_type,
+ nss_clmap_buf_callback_t data_cb,
+ nss_clmap_msg_callback_t notify_cb,
+ struct net_device *netdev,
+ uint32_t features)
+{
+ struct nss_ctx_instance *nss_ctx;
+ int core_status;
+ bool stats_status = false;
+
+ nss_ctx = nss_clmap_get_ctx();
+ NSS_VERIFY_CTX_MAGIC(nss_ctx);
+
+ if (!nss_clmap_verify_if_num(if_num)) {
+ nss_warning("%p: clmap register request received for invalid interface %d", nss_ctx, if_num);
+ return NULL;
+ }
+
+ if (di_type == NSS_DYNAMIC_INTERFACE_TYPE_CLMAP_US) {
+ stats_status = nss_clmap_stats_session_register(if_num, NSS_CLMAP_INTERFACE_TYPE_US, netdev);
+ } else {
+ stats_status = nss_clmap_stats_session_register(if_num, NSS_CLMAP_INTERFACE_TYPE_DS, netdev);
+ }
+
+ if (!stats_status) {
+ nss_warning("%p: statistics registration failed for interface: %d\n", nss_ctx, if_num);
+ return NULL;
+ }
+
+ core_status = nss_core_register_handler(nss_ctx, if_num, nss_clmap_msg_handler, (void *)netdev);
+ if (core_status != NSS_CORE_STATUS_SUCCESS) {
+ nss_clmap_stats_session_unregister(if_num);
+ nss_warning("%p: NSS core register handler failed for if_num:%d with error :%d", nss_ctx, if_num, core_status);
+ return NULL;
+ }
+
+ nss_core_register_subsys_dp(nss_ctx, if_num, data_cb, NULL, (void *)netdev, netdev, features);
+ nss_core_set_subsys_dp_type(nss_ctx, netdev, if_num, di_type);
+ nss_top_main.if_rx_msg_callback[if_num] = notify_cb;
+
+ return nss_ctx;
+}
+EXPORT_SYMBOL(nss_clmap_register);
+
+/*
+ * nss_clmap_ifnum_with_core_id()
+ * Append core ID to clmap interface num.
+ */
+int nss_clmap_ifnum_with_core_id(int if_num)
+{
+ struct nss_ctx_instance *nss_ctx = nss_clmap_get_ctx();
+
+ NSS_VERIFY_CTX_MAGIC(nss_ctx);
+ if (!nss_is_dynamic_interface(if_num)) {
+ nss_warning("%p: Invalid if_num: %d, must be a dynamic interface\n", nss_ctx, if_num);
+ return 0;
+ }
+ return NSS_INTERFACE_NUM_APPEND_COREID(nss_ctx, if_num);
+}
+EXPORT_SYMBOL(nss_clmap_ifnum_with_core_id);
+
+/*
+ * nss_clmap_msg_init()
+ * Initialize clmap message.
+ */
+void nss_clmap_msg_init(struct nss_clmap_msg *ncm, uint16_t if_num, uint32_t type, uint32_t len,
+ nss_clmap_msg_callback_t cb, void *app_data)
+{
+ nss_cmn_msg_init(&ncm->cm, if_num, type, len, (void*)cb, app_data);
+}
+EXPORT_SYMBOL(nss_clmap_msg_init);
+
+/*
+ * nss_clmap_get_ctx()
+ * Return a clmap NSS context.
+ */
+struct nss_ctx_instance *nss_clmap_get_ctx()
+{
+ struct nss_ctx_instance *nss_ctx;
+
+ nss_ctx = (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.clmap_handler_id];
+ return nss_ctx;
+}
+EXPORT_SYMBOL(nss_clmap_get_ctx);
+
+/*
+ * nss_clmap_init()
+ * Initializes clmap. Gets called from nss_init.c.
+ */
+void nss_clmap_init()
+{
+ nss_clmap_stats_dentry_create();
+ sema_init(&clmap_pvt.sem, 1);
+ init_completion(&clmap_pvt.complete);
+}
diff --git a/nss_clmap_log.c b/nss_clmap_log.c
new file mode 100644
index 0000000..0d5c2a6
--- /dev/null
+++ b/nss_clmap_log.c
@@ -0,0 +1,207 @@
+/*
+ **************************************************************************
+ * Copyright (c) 2019, The Linux Foundation. All rights reserved.
+ * Permission to use, copy, modify, and/or distribute this software for
+ * any purpose with or without fee is hereby granted, provided that the
+ * above copyright notice and this permission notice appear in all copies.
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ **************************************************************************
+ */
+
+/*
+ * nss_clmap_log.c
+ * NSS clmap logger file.
+ */
+
+#include "nss_core.h"
+
+/*
+ * nss_clmap_log_message_types_str
+ * clmap message strings
+ */
+static char *nss_clmap_log_message_types_str[NSS_CLMAP_MSG_TYPE_MAX] __maybe_unused = {
+ "Clmap sync stats",
+ "Clmap enable interface",
+ "Clmap disable interface",
+ "Clmap add MAC rule",
+ "Clmap delete MAC rule",
+ "Clmap flush MAC rule"
+};
+
+/*
+ * nss_clmap_log_error_types_str
+ * Strings for error types for clmap messages
+ */
+static char *nss_clmap_log_error_types_str[NSS_CLMAP_ERROR_MAX] __maybe_unused = {
+ "Clmap unknown error",
+ "Clmap interface disabled",
+ "Clmap interface enabled",
+ "Clmap invalid VLAN",
+ "Clmap invalid tunnel ID",
+ "Clmap MAC table full",
+ "Clmap MAC exists",
+ "Clmap MAC does not exist",
+ "Clmap MAC entry unhashed",
+ "Clmap MAC entry insert failed",
+ "Clmap MAC entry alloc failed",
+ "Clmap MAC entry delete failed"
+};
+
+/*
+ * nss_clmap_log_mac_msg()
+ * Log NSS clmap MAC rule message.
+ */
+static void nss_clmap_log_mac_msg(struct nss_clmap_mac_msg *npvcm)
+{
+ nss_trace("%p: NSS clmap MAC message \n"
+ "Clmap Mac Addr: %x : %x : %x"
+ "Clmap Flags: %u\n"
+ "Clmap VLAN ID: %u\n"
+ "Clmap Next-hop Interface Number: %d\n",
+ npvcm,
+ npvcm->mac_addr[0], npvcm->mac_addr[1],
+ npvcm->mac_addr[2], npvcm->flags,
+ npvcm->vlan_id, npvcm->nexthop_ifnum);
+}
+
+/*
+ * nss_clmap_log_interface_enable_msg()
+ * Log NSS clmap rule enable message.
+ */
+static void nss_clmap_log_interface_enable_msg(struct nss_clmap_msg *npvm)
+{
+ nss_trace("%p: NSS clmap interface state message: Enable \n", npvm);
+}
+
+/*
+ * nss_clmap_log_interface_disable_msg()
+ * Log NSS clmap rule disable message.
+ */
+static void nss_clmap_log_interface_disable_msg(struct nss_clmap_msg *npvm)
+{
+ nss_trace("%p: NSS clmap interface state message: Disable \n", npvm);
+}
+
+/*
+ * nss_clmap_log_mac_add_msg()
+ * Log NSS clmap mac rule add message.
+ */
+static void nss_clmap_log_mac_add_msg(struct nss_clmap_msg *npvm)
+{
+ struct nss_clmap_mac_msg *npvcm __maybe_unused = &npvm->msg.mac_add;
+ nss_clmap_log_mac_msg(npvcm);
+}
+
+/*
+ * nss_clmap_log_mac_del_msg()
+ * Log NSS clmap mac rule del message.
+ */
+static void nss_clmap_log_mac_del_msg(struct nss_clmap_msg *npvm)
+{
+ struct nss_clmap_mac_msg *npvcm __maybe_unused = &npvm->msg.mac_del;
+ nss_clmap_log_mac_msg(npvcm);
+}
+
+/*
+ * nss_clmap_log_mac_flush_msg()
+ * Log NSS clmap mac rule flush message.
+ */
+static void nss_clmap_log_mac_flush_msg(struct nss_clmap_msg *npvm)
+{
+ struct nss_clmap_flush_mac_msg *npvcm __maybe_unused = &npvm->msg.mac_flush;
+ nss_trace("%p: NSS clmap MAC flush message \n"
+ "Clmap Next-hop Interface Number: %d\n",
+ npvcm, npvcm->nexthop_ifnum);
+}
+
+/*
+ * nss_clmap_log_verbose()
+ * Log message contents.
+ */
+static void nss_clmap_log_verbose(struct nss_clmap_msg *npvm)
+{
+ switch (npvm->cm.type) {
+ case NSS_CLMAP_MSG_TYPE_INTERFACE_ENABLE:
+ nss_clmap_log_interface_enable_msg(npvm);
+ break;
+
+ case NSS_CLMAP_MSG_TYPE_INTERFACE_DISABLE:
+ nss_clmap_log_interface_disable_msg(npvm);
+ break;
+
+ case NSS_CLMAP_MSG_TYPE_MAC_ADD:
+ nss_clmap_log_mac_add_msg(npvm);
+ break;
+
+ case NSS_CLMAP_MSG_TYPE_MAC_DEL:
+ nss_clmap_log_mac_del_msg(npvm);
+ break;
+
+ case NSS_CLMAP_MSG_TYPE_MAC_FLUSH:
+ nss_clmap_log_mac_flush_msg(npvm);
+ break;
+
+ case NSS_CLMAP_MSG_TYPE_SYNC_STATS:
+ break;
+
+ default:
+ nss_trace("%p: Invalid message type\n", npvm);
+ break;
+ }
+}
+
+/*
+ * nss_clmap_log_tx_msg()
+ * Log messages transmitted to FW.
+ */
+void nss_clmap_log_tx_msg(struct nss_clmap_msg *npvm)
+{
+ if (npvm->cm.type >= NSS_CLMAP_MSG_TYPE_MAX) {
+ nss_warning("%p: Invalid message type\n", npvm);
+ return;
+ }
+
+ nss_info("%p: type[%d]:%s\n", npvm, npvm->cm.type, nss_clmap_log_message_types_str[npvm->cm.type]);
+ nss_clmap_log_verbose(npvm);
+}
+
+/*
+ * nss_clmap_log_rx_msg()
+ * Log messages received from FW.
+ */
+void nss_clmap_log_rx_msg(struct nss_clmap_msg *npvm)
+{
+ if (npvm->cm.response >= NSS_CMN_RESPONSE_LAST) {
+ nss_warning("%p: Invalid response\n", npvm);
+ return;
+ }
+
+ if (npvm->cm.response == NSS_CMN_RESPONSE_NOTIFY || (npvm->cm.response == NSS_CMN_RESPONSE_ACK)) {
+ nss_info("%p: type[%d]:%s, response[%d]:%s\n", npvm, npvm->cm.type,
+ nss_clmap_log_message_types_str[npvm->cm.type],
+ npvm->cm.response, nss_cmn_response_str[npvm->cm.response]);
+ goto verbose;
+ }
+
+ if (npvm->cm.error >= NSS_CLMAP_ERROR_MAX) {
+ nss_warning("%p: msg failure - type[%d]:%s, response[%d]:%s, error[%d]:Invalid error\n",
+ npvm, npvm->cm.type, nss_clmap_log_message_types_str[npvm->cm.type],
+ npvm->cm.response, nss_cmn_response_str[npvm->cm.response],
+ npvm->cm.error);
+ goto verbose;
+ }
+
+ nss_info("%p: msg nack - type[%d]:%s, response[%d]:%s, error[%d]:%s\n",
+ npvm, npvm->cm.type, nss_clmap_log_message_types_str[npvm->cm.type],
+ npvm->cm.response, nss_cmn_response_str[npvm->cm.response],
+ npvm->cm.error, nss_clmap_log_error_types_str[npvm->cm.error]);
+
+verbose:
+ nss_clmap_log_verbose(npvm);
+}
diff --git a/nss_clmap_log.h b/nss_clmap_log.h
new file mode 100644
index 0000000..6d193d3
--- /dev/null
+++ b/nss_clmap_log.h
@@ -0,0 +1,37 @@
+/*
+ ******************************************************************************
+ * Copyright (c) 2019, The Linux Foundation. All rights reserved.
+ * Permission to use, copy, modify, and/or distribute this software for
+ * any purpose with or without fee is hereby granted, provided that the
+ * above copyright notice and this permission notice appear in all copies.
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ * ****************************************************************************
+ */
+
+#ifndef __NSS_CLMAP_LOG_H__
+#define __NSS_CLMAP_LOG_H__
+
+/*
+ * nss_clmap_log.h
+ * NSS clmap Log Header File.
+ */
+
+/*
+ * nss_clmap_log_tx_msg
+ * Logs a clmap message that is sent to the NSS firmware.
+ */
+void nss_clmap_log_tx_msg(struct nss_clmap_msg *ncm);
+
+/*
+ * nss_clmap_log_rx_msg
+ * Logs a clmap message that is received from the NSS firmware.
+ */
+void nss_clmap_log_rx_msg(struct nss_clmap_msg *ncm);
+
+#endif /* __NSS_CLMAP_LOG_H__ */
diff --git a/nss_clmap_stats.c b/nss_clmap_stats.c
new file mode 100644
index 0000000..8a8884a
--- /dev/null
+++ b/nss_clmap_stats.c
@@ -0,0 +1,250 @@
+/*
+ **************************************************************************
+ * Copyright (c) 2019, The Linux Foundation. All rights reserved.
+ * Permission to use, copy, modify, and/or distribute this software for
+ * any purpose with or without fee is hereby granted, provided that the
+ * above copyright notice and this permission notice appear in all copies.
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ **************************************************************************
+ */
+
+#include "nss_tx_rx_common.h"
+#include "nss_clmap_stats.h"
+
+DEFINE_SPINLOCK(nss_clmap_stats_lock);
+
+struct nss_clmap_stats *stats_db[NSS_CLMAP_MAX_DEBUG_INTERFACES] = {NULL};
+
+/*
+ * nss_clmap_interface_type_str
+ * Clmap interface type string.
+ */
+static char *nss_clmap_interface_type_str[NSS_CLMAP_INTERFACE_TYPE_MAX] = {
+ "Upstream",
+ "Downstream"
+};
+
+/*
+ * nss_clmap_stats_str
+ * Clmap statistics strings for nss tunnel stats
+ */
+static char *nss_clmap_stats_str[NSS_CLMAP_INTERFACE_STATS_MAX] = {
+ "rx_pkts",
+ "rx_bytes",
+ "tx_pkts",
+ "tx_bytes",
+ "rx_queue_0_dropped",
+ "rx_queue_1_dropped",
+ "rx_queue_2_dropped",
+ "rx_queue_3_dropped",
+ "MAC DB look up failed",
+ "Invalid packet count",
+ "Headroom drop",
+ "Next node queue full drop",
+ "Pbuf alloc failed drop",
+ "Linear failed drop",
+ "Shared packet count",
+ "Ethernet frame error"
+};
+
+/*
+ * nss_clmap_stats_session_register
+ * Register debug statistic for clmap session.
+ */
+bool nss_clmap_stats_session_register(uint32_t if_num, uint32_t if_type, struct net_device *netdev)
+{
+ uint32_t i;
+ bool stats_status = false;
+
+ spin_lock_bh(&nss_clmap_stats_lock);
+ for (i = 0; i < NSS_CLMAP_MAX_DEBUG_INTERFACES; i++) {
+ if (!stats_db[i]) {
+ stats_db[i] = (struct nss_clmap_stats *)kzalloc(sizeof(struct nss_clmap_stats), GFP_KERNEL);
+ if (!stats_db[i]) {
+ nss_warning("%p: could not allocate memory for statistics database for interface id: %d\n", netdev, if_num);
+ break;
+ }
+ stats_db[i]->valid = true;
+ stats_db[i]->nss_if_num = if_num;
+ stats_db[i]->nss_if_type = if_type;
+ stats_db[i]->if_index = netdev->ifindex;
+ stats_status = true;
+ break;
+ }
+ }
+ spin_unlock_bh(&nss_clmap_stats_lock);
+ return stats_status;
+}
+
+/*
+ * nss_clmap_stats_session_unregister
+ * Unregister debug statistic for clmap session.
+ */
+void nss_clmap_stats_session_unregister(uint32_t if_num)
+{
+ uint32_t i;
+
+ spin_lock_bh(&nss_clmap_stats_lock);
+ for (i = 0; i < NSS_CLMAP_MAX_DEBUG_INTERFACES; i++) {
+ if (stats_db[i] && (stats_db[i]->nss_if_num == if_num)) {
+ kfree(stats_db[i]);
+ stats_db[i] = NULL;
+ break;
+ }
+ }
+ spin_unlock_bh(&nss_clmap_stats_lock);
+}
+
+/*
+ * nss_clmap_get_debug_stats()
+ * Get clmap debug statistics.
+ */
+static void nss_clmap_get_debug_stats(struct nss_clmap_stats *stats)
+{
+ uint32_t i;
+
+ spin_lock_bh(&nss_clmap_stats_lock);
+ for (i = 0; i < NSS_CLMAP_MAX_DEBUG_INTERFACES; i++) {
+ if (stats_db[i]) {
+ memcpy(stats, stats_db[i], sizeof(struct nss_clmap_stats));
+ stats++;
+ }
+ }
+ spin_unlock_bh(&nss_clmap_stats_lock);
+}
+
+/*
+ * nss_clmap_stats_read()
+ * Read clmap statistics
+ */
+static ssize_t nss_clmap_stats_read(struct file *fp, char __user *ubuf,
+ size_t sz, loff_t *ppos)
+{
+ uint32_t max_output_lines = 2 + (NSS_CLMAP_INTERFACE_STATS_MAX * NSS_CLMAP_MAX_DEBUG_INTERFACES + 2) + 2;
+ size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines;
+ size_t size_wr = 0;
+ ssize_t bytes_read = 0;
+ struct net_device *dev;
+ uint32_t id, i;
+ struct nss_clmap_stats *clmap_stats = NULL;
+
+ char *lbuf = kzalloc(size_al, GFP_KERNEL);
+ if (unlikely(!lbuf)) {
+ nss_warning("Could not allocate memory for local statistics buffer");
+ return 0;
+ }
+
+ /*
+ * Allocate statistics memory only for all interfaces.
+ */
+ clmap_stats = kzalloc((NSS_CLMAP_MAX_DEBUG_INTERFACES * sizeof(struct nss_clmap_stats)), GFP_KERNEL);
+ if (unlikely(!clmap_stats)) {
+ nss_warning("Could not allocate memory for populating clmap statistics\n");
+ kfree(lbuf);
+ return 0;
+ }
+
+ /*
+ * Get clmap statistics.
+ */
+ nss_clmap_get_debug_stats(clmap_stats);
+ size_wr = scnprintf(lbuf + size_wr, size_al - size_wr,
+ "\n clmap Interface statistics start:\n\n");
+ for (id = 0; id < NSS_CLMAP_MAX_DEBUG_INTERFACES; id++) {
+ struct nss_clmap_stats *clmsp = clmap_stats + id;
+
+ if (!(clmsp->valid)) {
+ continue;
+ }
+
+ dev = dev_get_by_index(&init_net, clmsp->if_index);
+ if (unlikely(!dev)) {
+ nss_warning("No netdev available for nss interface id:%d\n", clmsp->nss_if_type);
+ continue;
+ }
+
+ size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "%d. nss interface id=%d, interface type=%s, netdevice=%s\n", id,
+ clmsp->nss_if_num, nss_clmap_interface_type_str[clmsp->nss_if_type], dev->name);
+ dev_put(dev);
+
+ for (i = 0; i < NSS_CLMAP_INTERFACE_STATS_MAX; i++) {
+ size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
+ "\t%s = %llu\n", nss_clmap_stats_str[i],
+ clmsp->stats[i]);
+ }
+ size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\n");
+ }
+
+ size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
+ "\n clmap Interface statistics end\n");
+ bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, size_wr);
+
+ kfree(clmap_stats);
+ kfree(lbuf);
+ return bytes_read;
+}
+
+/*
+ * nss_clmap_stats_sync()
+ * Sync function for clmap statistics
+ */
+void nss_clmap_stats_sync(struct nss_ctx_instance *nss_ctx, struct nss_clmap_stats_msg *stats_msg, uint32_t if_num)
+{
+ uint32_t i;
+ struct nss_clmap_stats *s = NULL;
+
+ NSS_VERIFY_CTX_MAGIC(nss_ctx);
+
+ spin_lock_bh(&nss_clmap_stats_lock);
+ for (i = 0; i < NSS_CLMAP_MAX_DEBUG_INTERFACES; i++) {
+ if (stats_db[i] && (stats_db[i]->nss_if_num == if_num)) {
+ s = stats_db[i];
+ break;
+ }
+ }
+
+ if (!s) {
+ spin_unlock_bh(&nss_clmap_stats_lock);
+ nss_warning("%p: Interface not found: %u", nss_ctx, if_num);
+ return;
+ }
+
+ s->stats[NSS_CLMAP_INTERFACE_STATS_RX_PKTS] += stats_msg->node_stats.rx_packets;
+ s->stats[NSS_CLMAP_INTERFACE_STATS_RX_BYTES] += stats_msg->node_stats.rx_bytes;
+ s->stats[NSS_CLMAP_INTERFACE_STATS_TX_PKTS] += stats_msg->node_stats.tx_packets;
+ s->stats[NSS_CLMAP_INTERFACE_STATS_TX_BYTES] += stats_msg->node_stats.tx_bytes;
+
+ for (i = 0; i < NSS_MAX_NUM_PRI; i++) {
+ s->stats[NSS_CLMAP_INTERFACE_STATS_RX_QUEUE_0_DROPPED + i] += stats_msg->node_stats.rx_dropped[i];
+ }
+
+ s->stats[NSS_CLMAP_INTERFACE_STATS_DROPPED_MACDB_LOOKUP_FAILED] += stats_msg->dropped_macdb_lookup_failed;
+ s->stats[NSS_CLMAP_INTERFACE_STATS_DROPPED_INVALID_PACKET_SIZE] += stats_msg->dropped_invalid_packet_size;
+ s->stats[NSS_CLMAP_INTERFACE_STATS_DROPPED_LOW_HEADROOM] += stats_msg->dropped_low_hroom;
+ s->stats[NSS_CLMAP_INTERFACE_STATS_DROPPED_NEXT_NODE_QUEUE_FULL] += stats_msg->dropped_next_node_queue_full;
+ s->stats[NSS_CLMAP_INTERFACE_STATS_DROPPED_PBUF_ALLOC_FAILED] += stats_msg->dropped_pbuf_alloc_failed;
+ s->stats[NSS_CLMAP_INTERFACE_STATS_DROPPED_LINEAR_FAILED] += stats_msg->dropped_linear_failed;
+ s->stats[NSS_CLMAP_INTERFACE_STATS_SHARED_PACKET_CNT] += stats_msg->shared_packet_count;
+ s->stats[NSS_CLMAP_INTERFACE_STATS_ETHERNET_FRAME_ERROR] += stats_msg->ethernet_frame_error;
+ spin_unlock_bh(&nss_clmap_stats_lock);
+}
+
+/*
+ * nss_clmap_stats_ops
+ */
+NSS_STATS_DECLARE_FILE_OPERATIONS(clmap)
+
+/*
+ * nss_clmap_stats_dentry_create()
+ * Create client map statistics debug entry.
+ */
+void nss_clmap_stats_dentry_create(void)
+{
+ nss_stats_create_dentry("clmap", &nss_clmap_stats_ops);
+}
diff --git a/nss_clmap_stats.h b/nss_clmap_stats.h
new file mode 100644
index 0000000..3464309
--- /dev/null
+++ b/nss_clmap_stats.h
@@ -0,0 +1,73 @@
+/*
+ ******************************************************************************
+ * Copyright (c) 2019, The Linux Foundation. All rights reserved.
+ * Permission to use, copy, modify, and/or distribute this software for
+ * any purpose with or without fee is hereby granted, provided that the
+ * above copyright notice and this permission notice appear in all copies.
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ * ****************************************************************************
+ */
+
+#ifndef __NSS_CLMAP_STATS_H
+#define __NSS_CLMAP_STATS_H
+
+#define NSS_CLMAP_MAX_DEBUG_INTERFACES 2 * NSS_CLMAP_MAX_INTERFACES
+
+/*
+ * Clmap NSS interface type.
+ */
+enum nss_clmap_interface_type {
+ NSS_CLMAP_INTERFACE_TYPE_US,
+ NSS_CLMAP_INTERFACE_TYPE_DS,
+ NSS_CLMAP_INTERFACE_TYPE_MAX
+};
+
+/*
+ * Clmap statistic counters.
+ */
+enum nss_clmap_stats_type {
+ NSS_CLMAP_INTERFACE_STATS_RX_PKTS,
+ NSS_CLMAP_INTERFACE_STATS_RX_BYTES,
+ NSS_CLMAP_INTERFACE_STATS_TX_PKTS,
+ NSS_CLMAP_INTERFACE_STATS_TX_BYTES,
+ NSS_CLMAP_INTERFACE_STATS_RX_QUEUE_0_DROPPED,
+ NSS_CLMAP_INTERFACE_STATS_RX_QUEUE_1_DROPPED,
+ NSS_CLMAP_INTERFACE_STATS_RX_QUEUE_2_DROPPED,
+ NSS_CLMAP_INTERFACE_STATS_RX_QUEUE_3_DROPPED,
+ NSS_CLMAP_INTERFACE_STATS_DROPPED_MACDB_LOOKUP_FAILED,
+ NSS_CLMAP_INTERFACE_STATS_DROPPED_INVALID_PACKET_SIZE,
+ NSS_CLMAP_INTERFACE_STATS_DROPPED_LOW_HEADROOM,
+ NSS_CLMAP_INTERFACE_STATS_DROPPED_NEXT_NODE_QUEUE_FULL,
+ NSS_CLMAP_INTERFACE_STATS_DROPPED_PBUF_ALLOC_FAILED,
+ NSS_CLMAP_INTERFACE_STATS_DROPPED_LINEAR_FAILED,
+ NSS_CLMAP_INTERFACE_STATS_SHARED_PACKET_CNT,
+ NSS_CLMAP_INTERFACE_STATS_ETHERNET_FRAME_ERROR,
+ NSS_CLMAP_INTERFACE_STATS_MAX,
+};
+
+/*
+ * Clmap session debug statistics.
+ */
+struct nss_clmap_stats {
+ uint64_t stats[NSS_CLMAP_INTERFACE_STATS_MAX];
+ int32_t if_index;
+ uint32_t nss_if_num; /* NSS interface number. */
+ enum nss_clmap_interface_type nss_if_type; /* NSS interface type. */
+ bool valid;
+};
+
+/*
+ * Clmap statistics APIs.
+ */
+extern bool nss_clmap_stats_session_register(uint32_t if_num, enum nss_clmap_interface_type if_type, struct net_device *netdev);
+extern void nss_clmap_stats_session_unregister(uint32_t if_num);
+extern void nss_clmap_stats_sync(struct nss_ctx_instance *nss_ctx, struct nss_clmap_stats_msg *stats_msg, uint32_t if_num);
+extern void nss_clmap_stats_dentry_create(void);
+
+#endif /* __NSS_CLMAP_STATS_H */
diff --git a/nss_core.h b/nss_core.h
index 47e49cc..ff2a0c9 100644
--- a/nss_core.h
+++ b/nss_core.h
@@ -609,6 +609,7 @@
uint8_t pvxlan_handler_id;
uint8_t igs_handler_id;
uint8_t gre_redir_mark_handler_id;
+ uint8_t clmap_handler_id;
/*
* Data/Message callbacks for various interfaces
@@ -916,6 +917,8 @@
/* Does this core handle igs? */
enum nss_feature_enabled gre_redir_mark_enabled;
/* Does this core handle GRE redir mark? */
+ enum nss_feature_enabled clmap_enabled;
+ /* Does this core handle clmap? */
};
#endif
diff --git a/nss_hal/nss_hal.c b/nss_hal/nss_hal.c
index 75f68d6..70c5970 100644
--- a/nss_hal/nss_hal.c
+++ b/nss_hal/nss_hal.c
@@ -121,6 +121,7 @@
npd->pptp_enabled = of_property_read_bool(np, "qcom,pptp-enabled");
npd->portid_enabled = of_property_read_bool(np, "qcom,portid-enabled");
npd->pvxlan_enabled = of_property_read_bool(np, "qcom,pvxlan-enabled");
+ npd->clmap_enabled = of_property_read_bool(np, "qcom,clmap-enabled");
npd->qvpn_enabled = of_property_read_bool(np, "qcom,qvpn-enabled");
npd->shaping_enabled = of_property_read_bool(np, "qcom,shaping-enabled");
npd->tstamp_enabled = of_property_read_bool(np, "qcom,tstamp-enabled");
@@ -542,6 +543,12 @@
nss_gre_redir_mark_register_handler();
}
+ if (npd->clmap_enabled == NSS_FEATURE_ENABLED) {
+ nss_top->clmap_handler_id = nss_dev->id;
+ nss_top->dynamic_interface_table[NSS_DYNAMIC_INTERFACE_TYPE_CLMAP_US] = nss_dev->id;
+ nss_top->dynamic_interface_table[NSS_DYNAMIC_INTERFACE_TYPE_CLMAP_DS] = nss_dev->id;
+ }
+
if (nss_ctx->id == 0) {
#if (NSS_FREQ_SCALE_SUPPORT == 1)
nss_freq_register_handler();
diff --git a/nss_init.c b/nss_init.c
index 8ae7a7d..39f4652 100644
--- a/nss_init.c
+++ b/nss_init.c
@@ -823,6 +823,11 @@
nss_pvxlan_init();
/*
+ * Init clmap
+ */
+ nss_clmap_init();
+
+ /*
* INIT ppe on supported platform
*/
if (of_machine_is_compatible("qcom,ipq807x") || of_machine_is_compatible("qcom,ipq6018")) {