Re-design handling of physical and virtual interfaces
1) Fix message numbering by basing nss_virt_if.h and nss_phys_if.h on nss_if.h
2) Create backward compatible layer for virtual in nss_tx_rx_virt_if.c
3) Create new API in nss_virt_if.c
4) Create backward compatible layer for phsical in nss_tx_rx_phys_if.c
5) Create new API in nss_phys.c
Change-Id: Ibe8c8e60b5e841f0aeb201f8ad7be171c9ae979a
Signed-off-by: Sol Kavy <skavy@codeaurora.org>
diff --git a/Makefile b/Makefile
index e37733b..0ef7bf3 100755
--- a/Makefile
+++ b/Makefile
@@ -17,11 +17,36 @@
# ###################################################
obj-m += qca-nss-drv.o
-qca-nss-drv-objs := nss_init.o nss_core.o nss_stats.o nss_pm.o nss_tx_rx_ipv4.o nss_tx_rx_ipv6.o \
- nss_tx_rx_virt_if.o nss_tx_rx_phys_if.o \
- nss_tx_rx_crypto.o nss_tx_rx_ipsec.o nss_tx_rx_n2h.o nss_tx_rx_pppoe.o nss_tx_rx_generic.o \
- nss_tx_rx_freq.o nss_tx_rx_eth_rx.o nss_cmn.o nss_virt_if.o nss_ipv4.o \
- nss_tun6rd.o nss_tunipip6.o nss_lag.o
+
+qca-nss-drv-objs := \
+ nss_init.o \
+ nss_cmn.o \
+ nss_core.o \
+ nss_ipv4.o \
+ nss_lag.o \
+ nss_phys_if.o \
+ nss_pm.o \
+ nss_stats.o \
+ nss_tun6rd.o \
+ nss_tunipip6.o \
+ nss_virt_if.o
+
+#
+# TODO: Deprecated files should be removed before merge
+#
+qca-nss-drv-objs += \
+ nss_tx_rx_crypto.o \
+ nss_tx_rx_eth_rx.o \
+ nss_tx_rx_freq.o \
+ nss_tx_rx_generic.o \
+ nss_tx_rx_ipv4.o \
+ nss_tx_rx_ipv6.o \
+ nss_tx_rx_ipsec.o \
+ nss_tx_rx_n2h.o \
+ nss_tx_rx_pppoe.o \
+ nss_tx_rx_phys_if.o \
+ nss_tx_rx_virt_if.o
+
obj-m += qca-nss-connmgr-ipv4.o
obj-m += qca-nss-connmgr-ipv6.o
diff --git a/nss_api_if.h b/nss_api_if.h
index 50f6948..59ec67d 100755
--- a/nss_api_if.h
+++ b/nss_api_if.h
@@ -37,10 +37,13 @@
#include <linux/skbuff.h>
#include <linux/netdevice.h>
#include "nss_cmn.h"
-#include "nss_virt_if.h"
#include "nss_tun6rd.h"
#include "nss_tunipip6.h"
#include "nss_lag.h"
+#include "nss_ipv4.h"
+#include "nss_if.h"
+#include "nss_phys_if.h"
+#include "nss_virt_if.h"
/*
* Interface numbers are reserved in the
@@ -1151,6 +1154,7 @@
/**
* Callback to receive GMAC events
+ * TODO: This callback is deprecated in the new APIs.
*/
typedef void (*nss_phys_if_event_callback_t)(void *if_ctx, nss_gmac_event_t ev_type, void *buf, uint32_t len);
@@ -1554,8 +1558,7 @@
* Once Everything is arragned correctly, will be placed at top
*/
-#include "nss_ipv4.h"
-#include "nss_if.h"
+
/**@}*/
#endif /** __NSS_API_IF_H */
diff --git a/nss_core.c b/nss_core.c
index 96ed520..f411f41 100755
--- a/nss_core.c
+++ b/nss_core.c
@@ -38,7 +38,7 @@
void *app_data;
};
-struct nss_rx_cb_list nss_rx_interface_handlers[NSS_MAX_NET_INTERFACES];
+static struct nss_rx_cb_list nss_rx_interface_handlers[NSS_MAX_NET_INTERFACES];
/*
* nss_core_register_handler()
diff --git a/nss_core.h b/nss_core.h
index 3baa7a3..453f1d0 100755
--- a/nss_core.h
+++ b/nss_core.h
@@ -454,6 +454,7 @@
/*
* Network processing handler core ids (CORE0/CORE1) for various interfaces
*/
+ uint8_t phys_if_handler_id[4];
uint8_t shaping_handler_id;
uint8_t ipv4_handler_id;
uint8_t ipv6_handler_id;
@@ -462,12 +463,15 @@
uint8_t wlan_handler_id;
uint8_t tun6rd_handler_id;
uint8_t tunipip6_handler_id;
- uint8_t phys_if_handler_id[4];
uint8_t frequency_handler_id;
/*
* Data/Message callbacks for various interfaces
*/
+ nss_phys_if_rx_callback_t if_rx_callback[NSS_MAX_NET_INTERFACES];
+ /* Physical interface packet callback functions */
+ nss_phys_if_msg_callback_t phys_if_msg_callback[NSS_MAX_PHYSICAL_INTERFACES];
+ /* Physical interface event callback functions */
nss_ipv4_msg_callback_t ipv4_callback;
/* IPv4 sync/establish callback function */
nss_ipv6_callback_t ipv6_callback;
@@ -478,10 +482,6 @@
/* crypto interface data callback function */
nss_crypto_sync_callback_t crypto_sync_callback;
/* crypto interface sync callback function */
- nss_phys_if_rx_callback_t if_rx_callback[NSS_MAX_NET_INTERFACES];
- /* Physical interface packet callback functions */
- nss_phys_if_event_callback_t phys_if_event_callback[NSS_MAX_PHYSICAL_INTERFACES];
- /* Physical interface event callback functions */
nss_profiler_callback_t profiler_callback[NSS_MAX_CORES];
/* Profiler interface callback function */
nss_tun6rd_msg_callback_t tun6rd_msg_callback;
@@ -494,6 +494,12 @@
/* Registrants for bridge shaper bounce operations */
/*
+ * Interface contexts (network device)
+ */
+ struct net_device *if_ctx[NSS_MAX_NET_INTERFACES];
+ /* Phys/Virt interface context */
+
+ /*
* Interface contexts (non network device)
*/
void *ipv4_ctx; /* IPv4 connection manager context */
@@ -502,11 +508,7 @@
void *profiler_ctx[NSS_MAX_CORES];
/* Profiler interface context */
- /*
- * Interface contexts (network device)
- */
- struct net_device *if_ctx[NSS_MAX_NET_INTERFACES];
- /* Phys/Virt interface context */
+
/*
* Statistics for various interfaces
diff --git a/nss_if.c b/nss_if.c
deleted file mode 100755
index 6c9c955..0000000
--- a/nss_if.c
+++ /dev/null
@@ -1,252 +0,0 @@
-/*
- **************************************************************************
- * Copyright (c) 2014, 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_if.c
- * NSS Interface Messages
- */
-#include "nss_tx_rx_common.h"
-#include "nss_if.h"
-
-/*
- * Deprecated handler for old API.
- */
-extern void nss_rx_metadata_gmac_stats_sync(struct nss_ctx_instance *nss_ctx, struct nss_if_stats_sync *ngss, uint16_t interface);
-
-/*
- * nss_if_hanlder_update_driver_stats()
- * Update the local driver statistics
- */
-#if 0
-static void nss_if_hanlder_update_driver_stats(uint16_t interface, struct nss_if_stats_sync *ngss)
-{
- spin_lock_bh(&nss_top->stats_lock);
- nss_top->stats_gmac[id][NSS_STATS_GMAC_TOTAL_TICKS] += ngss->gmac_total_ticks;
- if (unlikely(nss_top->stats_gmac[id][NSS_STATS_GMAC_WORST_CASE_TICKS] < ngss->gmac_worst_case_ticks)) {
- nss_top->stats_gmac[id][NSS_STATS_GMAC_WORST_CASE_TICKS] = ngss->gmac_worst_case_ticks;
- }
- nss_top->stats_gmac[id][NSS_STATS_GMAC_ITERATIONS] += ngss->gmac_iterations;
- spin_unlock_bh(&nss_top->stats_lock);
-}
-#endif
-
-/*
- * nss_if_handler()
- * Handle NSS -> HLOS messages for IPv4 bridge/route
- */
-#if 0
-static void nss_if_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data)
-{
- struct nss_if_msg *nim = (struct nss_if_msg *)ncm;
- nss_if_msg_callback_t cb;
-
- /*
- * Sanity check the message type
- */
- if (ncm->type > NSS_IF_MAX_MSG_TYPES) {
- nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
- return;
- }
-
- /*
- * Update the callback and app_data for NOTIFY messages, IPv4 sends all notify messages
- * to the same callback/app_data.
- */
- if (nim->cm.response == NSS_CMM_RESPONSE_NOTIFY) {
- ncm->cb = (uint32_t)nss_ctx->nss_top->phys_if_event_callback[ncm->interface];
- // nim->app_data = nss_ctx->nss_top->ipv4_app_data;
- }
-
- /*
- * Log failures
- */
- nss_core_log_msg_failures(nss_ctx, ncm);
-
- /*
- * Handle deprecated messages. Eventually these messages should be removed.
- */
- switch (nim->cm.type) {
- case NSS_IF_STATS_SYNC:
- /*
- * Update local statistics
- */
- // nss_if_update_driver_stats( ncm->interface, &nim->msg.stats_sync);
- break;
- }
-
- /*
- * Do we have a callback?
- */
- if (!ncm->cb) {
- return;
- }
-
- /*
- * Callback
- */
- cb = (nss_if_msg_callback_t)ncm->cb;
- cb((void *)ncm->app_data, nim);
-}
-#endif
-/*
- * nss_if_tx()
- * Transmit an ipv4 message to the FW.
- */
-nss_tx_status_t nss_if_tx(struct nss_ctx_instance *nss_ctx, struct nss_if_msg *nim)
-{
- struct nss_if_msg *nim2;
- struct nss_cmn_msg *ncm = &nim->cm;
- struct sk_buff *nbuf;
- int32_t status;
-
- NSS_VERIFY_CTX_MAGIC(nss_ctx);
- if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
- nss_warning("%p: ipv4 msg dropped as core not ready", nss_ctx);
- return NSS_TX_FAILURE_NOT_READY;
- }
-
- /*
- * Sanity check the message
- */
- if (ncm->interface != NSS_IPV4_RX_INTERFACE) {
- nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
- return NSS_TX_FAILURE;
- }
-
- if (ncm->type > NSS_IF_MAX_MSG_TYPES) {
- nss_warning("%p: tx request type unknown: %d", nss_ctx, ncm->type);
- return NSS_TX_FAILURE;
- }
-
- if (ncm->len > sizeof(struct nss_if_msg)) {
- nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
- return NSS_TX_FAILURE;
- }
-
- nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE);
- if (unlikely(!nbuf)) {
- spin_lock_bh(&nss_ctx->nss_top->stats_lock);
- nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]++;
- spin_unlock_bh(&nss_ctx->nss_top->stats_lock);
- nss_warning("%p: msg dropped as command allocation failed", nss_ctx);
- return NSS_TX_FAILURE;
- }
-
- /*
- * Copy the message to our skb.
- */
- nim2 = (struct nss_if_msg *)skb_put(nbuf, sizeof(struct nss_if_msg));
- nim2 = nim;
-
- status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0);
- if (status != NSS_CORE_STATUS_SUCCESS) {
- dev_kfree_skb_any(nbuf);
- nss_warning("%p: Unable to enqueue 'Destroy IPv4' rule\n", nss_ctx);
- return NSS_TX_FAILURE;
- }
-
- nss_hal_send_interrupt(nss_ctx->nmap, nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit,
- NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE);
-
- NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]);
- return NSS_TX_SUCCESS;
-}
-
-/*
- **********************************
- Register/Unregister/Miscellaneous APIs
- **********************************
- */
-
-/*
- * nss_if_notify_register()
- * Register for notifications
- *
- * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv4 on any core?
- */
-void *nss_if_notify_register(uint32_t if_num, nss_if_msg_callback_t cb, void *app_data)
-{
- /*
- * TODO: We need to have a new array in support of the new API
- * TODO: If we use a per-context array, we would move the array into nss_ctx based.
- * TODO: See if we can convert the internal storage of netdev so as not to use void *.
- * TODO: Need to change the nss_top types to match the new ones and remove old code.
- */
- // uint8_t id = nss_top_main.phys_if_handler_id[if_num];
-
- // nss_top_main.phys_if_event_callback[if_num] = cb;
- return (void *)&nss_top_main.nss[nss_top_main.ipv4_handler_id];
-}
-
-/*
- * nss_if_data_register()
- * Register for data
- *
- * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv4 on any core?
- */
-void *nss_if_data_register(uint32_t if_num, struct net_device *netdev, nss_if_data_callback_t cb, void *app_data)
-{
- /*
- * TODO: We need to have a new array in support of the new API
- * TODO: If we use a per-context array, we would move the array into nss_ctx based.
- * TODO: See if we can convert the internal storage of netdev so as not to use void *.
- * TODO: Need to change the nss_top types to match the new ones and remove old code.
- */
- uint8_t id = nss_top_main.phys_if_handler_id[if_num];
- struct nss_ctx_instance *nss_ctx = &nss_top_main.nss[id];
-
- //nss_top_main.if_rx_callback[if_num] = cb;
- nss_top_main.if_ctx[if_num] = (void *)netdev;
- nss_ctx->phys_if_mtu[if_num] = NSS_ETH_NORMAL_FRAME_MTU;
- return (void *)&nss_top_main.nss[nss_top_main.ipv4_handler_id];
-}
-
-
-
-/*
- * nss_if_notify_unregister()
- * Unregister to received IPv4 events.
- *
- * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv4 on any core?
- */
-void nss_if_notify_unregister(void)
-{
- nss_top_main.ipv4_callback = NULL;
-}
-
-/*
- * nss_get_ipv4_mgr_ctx()
- *
- * TODO: This only suppports a single ipv4, do we ever want to support more?
- */
-struct nss_ctx_instance *nss_if_get_mgr(void)
-{
- return (void *)&nss_top_main.nss[nss_top_main.ipv4_handler_id];
-}
-
-/*
- * nss_if_register_handler()
- * Register our handler to receive messages for this interface
- */
-void nss_if_register_handler(void)
-{
-}
-
-EXPORT_SYMBOL(nss_if_tx);
-EXPORT_SYMBOL(nss_if_notify_register);
-EXPORT_SYMBOL(nss_if_notify_unregister);
-EXPORT_SYMBOL(nss_if_get_mgr);
-EXPORT_SYMBOL(nss_if_register_handler);
diff --git a/nss_if.h b/nss_if.h
index 4d72ec4..cfc63be 100755
--- a/nss_if.h
+++ b/nss_if.h
@@ -1,4 +1,20 @@
/*
+ **************************************************************************
+ * Copyright (c) 2014, Qualcomm Atheros, Inc.
+ * 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 Interface Messages
*/
@@ -14,7 +30,7 @@
NSS_IF_LINK_STATE_NOTIFY,
NSS_IF_MTU_CHANGE,
NSS_IF_MAC_ADDR_SET,
- NSS_IF_MSS_SET,
+ NSS_IF_RESERVED,
NSS_IF_STATS_SYNC,
NSS_IF_ISHAPER_ASSIGN,
NSS_IF_BSHAPER_ASSIGN,
@@ -22,7 +38,7 @@
NSS_IF_BSHAPER_UNASSIGN,
NSS_IF_ISHAPER_CONFIG,
NSS_IF_BSHAPER_CONFIG,
- NSS_IF_MAX_MSG_TYPES
+ NSS_IF_MAX_MSG_TYPES = 9999,
};
enum nss_if_error_types {
@@ -68,13 +84,6 @@
};
/*
- * The MSS (Maximum Segment Size) structure.
- */
-struct nss_if_mss_set {
- uint16_t mss; /* MSS value */
-};
-
-/*
* The NSS MAC address structure.
*/
struct nss_if_mac_address_set {
@@ -136,26 +145,13 @@
/*
* Message structure to send/receive phys i/f commands
*/
-struct nss_if_msg {
- struct nss_cmn_msg cm; /* Message Header */
- union {
- struct nss_if_link_state_notify link_state_notify; /* Message: notify link status */
- struct nss_if_open open; /* Message: open interface */
- struct nss_if_close close; /* Message: close interface */
- struct nss_if_mtu_change mtu_change; /* Message: MTU change notification */
- struct nss_if_mss_set mss_set; /* Message: set MSS */
- struct nss_if_mac_address_set mac_address_set; /* Message: set MAC address for i/f */
- struct nss_if_stats_sync stats_sync; /* Message: statistics sync */
- } msg;
+union nss_if_msgs {
+ struct nss_if_link_state_notify link_state_notify; /* Message: notify link status */
+ struct nss_if_open open; /* Message: open interface */
+ struct nss_if_close close; /* Message: close interface */
+ struct nss_if_mtu_change mtu_change; /* Message: MTU change notification */
+ struct nss_if_mac_address_set mac_address_set; /* Message: set MAC address for i/f */
+ struct nss_if_stats_sync stats_sync; /* Message: statistics sync */
};
-
-struct nss_ctx_instance;
-
-typedef void (*nss_if_msg_callback_t)(void *app_data, struct nss_if_msg *msg);
-typedef void (*nss_if_data_callback_t)(void *app_data, struct sk_buff *nbuf);
-
-extern nss_tx_status_t nss_if_tx(struct nss_ctx_instance *nss_ctx, struct nss_if_msg *msg);
-extern void *nss_if_notify_register(uint32_t if_num, nss_if_msg_callback_t msg_cb, void *app_data);
-extern void *nss_if_data_register(uint32_t if_num, struct net_device *netdev, nss_if_data_callback_t cb, void *app_data);
#endif /* __NSS_IF_H */
diff --git a/nss_init.c b/nss_init.c
index c6d6654..dfe399c 100755
--- a/nss_init.c
+++ b/nss_init.c
@@ -339,6 +339,7 @@
nss_pppoe_register_handler();
nss_eth_rx_register_handler();
nss_n2h_register_handler();
+ nss_virt_if_register_handler();
}
if (npd->ipv6_enabled == NSS_FEATURE_ENABLED) {
diff --git a/nss_ipv4.c b/nss_ipv4.c
index a46b5e6..7b8a09a 100755
--- a/nss_ipv4.c
+++ b/nss_ipv4.c
@@ -30,58 +30,31 @@
* Update driver specific information from the messsage.
*/
#if 0
-static void nss_ipv4_driver_update(void)
+static void nss_ipv4_driver_conn_update(struct nss_ipv4_msg *nim)
{
/*
* Update statistics maintained by NSS driver
*/
spin_lock_bh(&nss_top->stats_lock);
-
nss_top->stats_ipv4[NSS_STATS_IPV4_ACCELERATED_RX_PKTS] += nirs->flow_rx_packet_count + nirs->return_rx_packet_count;
nss_top->stats_ipv4[NSS_STATS_IPV4_ACCELERATED_RX_BYTES] += nirs->flow_rx_byte_count + nirs->return_rx_byte_count;
nss_top->stats_ipv4[NSS_STATS_IPV4_ACCELERATED_TX_PKTS] += nirs->flow_tx_packet_count + nirs->return_tx_packet_count;
nss_top->stats_ipv4[NSS_STATS_IPV4_ACCELERATED_TX_BYTES] += nirs->flow_tx_byte_count + nirs->return_tx_byte_count;
-
- /*
- * Update the PPPoE interface stats, if there is any PPPoE session on the interfaces.
- */
- if (nirs->flow_pppoe_session_id) {
- pppoe_dev = ppp_session_to_netdev(nirs->flow_pppoe_session_id, (uint8_t *)nirs->flow_pppoe_remote_mac);
- if (pppoe_dev) {
- ppp_update_stats(pppoe_dev, nirs->flow_rx_packet_count, nirs->flow_rx_byte_count,
- nirs->flow_tx_packet_count, nirs->flow_tx_byte_count);
- dev_put(pppoe_dev);
- }
- }
-
- if (nirs->return_pppoe_session_id) {
- pppoe_dev = ppp_session_to_netdev(nirs->return_pppoe_session_id, (uint8_t *)nirs->return_pppoe_remote_mac);
- if (pppoe_dev) {
- ppp_update_stats(pppoe_dev, nirs->return_rx_packet_count, nirs->return_rx_byte_count,
- nirs->return_tx_packet_count, nirs->return_tx_byte_count);
- dev_put(pppoe_dev);
- }
- }
-
- /*
- * TODO: Update per dev accelerated statistics
- */
spin_unlock_bh(&nss_top->stats_lock);
}
#endif
/*
- * nss_ipv4_handler()
+ * nss_ipv4_rx_msg_handler()
* Handle NSS -> HLOS messages for IPv4 bridge/route
*/
-static void nss_ipv4_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data)
+static void nss_ipv4_rx_msg_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data)
{
struct nss_ipv4_msg *nim = (struct nss_ipv4_msg *)ncm;
-
/*
* TODO: Turn back on for new APIs
*/
-// nss_ipv4_msg_callback_t cb;
+// nss_ipv4_rx_msg_callback_t cb;
BUG_ON(ncm->interface != NSS_IPV4_RX_INTERFACE);
@@ -98,7 +71,6 @@
return;
}
-
/*
* Update the callback and app_data for NOTIFY messages, IPv4 sends all notify messages
* to the same callback/app_data.
@@ -126,10 +98,12 @@
break;
}
+#if 0
/*
* Local driver updates for ipv4.
*/
-#if 0
+ nss_ipv4_driver_update(nim);
+
/*
* Do we have a callback?
*/
@@ -140,7 +114,7 @@
/*
* Callback
*/
- cb = (nss_ipv4_msg_callback_t)ncm->cb;
+ cb = (nss_ipv4_rx_msg_callback_t)ncm->cb;
cb((void *)ncm->app_data, nim);
#endif
}
@@ -257,9 +231,9 @@
* nss_ipv4_register_handler()
* Register our handler to receive messages for this interface
*/
-void nss_ipv4_register_handler()
+void nss_ipv4_register_handler(void)
{
- if (nss_core_register_handler(NSS_IPV4_RX_INTERFACE, nss_ipv4_handler, NULL) != NSS_CORE_STATUS_SUCCESS) {
+ if (nss_core_register_handler(NSS_IPV4_RX_INTERFACE, nss_ipv4_rx_msg_handler, NULL) != NSS_CORE_STATUS_SUCCESS) {
nss_warning("IPv4 handler failed to register");
}
}
diff --git a/nss_phys_if.c b/nss_phys_if.c
new file mode 100755
index 0000000..6bf8853
--- /dev/null
+++ b/nss_phys_if.c
@@ -0,0 +1,257 @@
+/*
+ **************************************************************************
+ * Copyright (c) 2014, 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_phy_if.c
+ * NSS physical interface functions
+ */
+
+#include "nss_tx_rx_common.h"
+#include "nss_phys_if.h"
+
+/*
+ * TODO: Once we are moved to the new API, this function is deprecated.
+ */
+extern void nss_rx_metadata_gmac_stats_sync(struct nss_ctx_instance *nss_ctx, struct nss_if_stats_sync *ngss, uint16_t interface);
+
+/*
+ * nss_phys_if_msg_handler()
+ * Handle NSS -> HLOS messages for physical interface/gmacs
+ */
+static void nss_phys_if_msg_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data)
+{
+ struct nss_phys_if_msg *nim = (struct nss_phys_if_msg *)ncm;
+
+ /*
+ * Sanity check the message type
+ */
+ if (ncm->type > NSS_IPV4_MAX_MSG_TYPES) {
+ nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
+ return;
+ }
+
+ if (ncm->interface > NSS_MAX_PHYSICAL_INTERFACES) {
+ nss_warning("%p: response for another interface: %d", nss_ctx, ncm->interface);
+ return;
+ }
+
+ if (ncm->len > sizeof(struct nss_phys_if_msg)) {
+ nss_warning("%p: message length too big: %d", nss_ctx, ncm->len);
+ return;
+ }
+
+ /*
+ * Log failures
+ */
+ nss_core_log_msg_failures(nss_ctx, ncm);
+
+ /*
+ * Handle deprecated messages.
+ */
+ switch (nim->cm.type) {
+ case NSS_PHYS_IF_STATS_SYNC:
+ return nss_rx_metadata_gmac_stats_sync(nss_ctx, &nim->msg.stats_sync, ncm->interface);
+ break;
+ }
+
+#if 0
+ /*
+ * Do we have a callback?
+ */
+ if (!ncm->cb) {
+ return;
+ }
+
+ /*
+ * Callback
+ */
+ cb = (nss_virt_if_rx_msg_callback_t)ncm->cb;
+ cb((void *)ncm->app_data, nvim);
+#endif
+}
+
+/*
+ * nss_phys_if_tx_buf()
+ * Send packet to physical interface owned by NSS
+ */
+nss_tx_status_t nss_phys_if_tx_buf(struct nss_ctx_instance *nss_ctx, struct sk_buff *os_buf, uint32_t if_num)
+{
+ int32_t status;
+
+ nss_trace("%p: Phys If Tx packet, id:%d, data=%p", nss_ctx, if_num, os_buf->data);
+
+ NSS_VERIFY_CTX_MAGIC(nss_ctx);
+ if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
+ nss_warning("%p: 'Phys If Tx' packet dropped as core not ready", nss_ctx);
+ return NSS_TX_FAILURE_NOT_READY;
+ }
+
+ status = nss_core_send_buffer(nss_ctx, if_num, os_buf, NSS_IF_DATA_QUEUE, H2N_BUFFER_PACKET, 0);
+ if (unlikely(status != NSS_CORE_STATUS_SUCCESS)) {
+ nss_warning("%p: Unable to enqueue 'Phys If Tx' packet\n", nss_ctx);
+ if (status == NSS_CORE_STATUS_FAILURE_QUEUE) {
+ return NSS_TX_FAILURE_QUEUE;
+ }
+
+ return NSS_TX_FAILURE;
+ }
+
+ /*
+ * Kick the NSS awake so it can process our new entry.
+ */
+ nss_hal_send_interrupt(nss_ctx->nmap, nss_ctx->h2n_desc_rings[NSS_IF_DATA_QUEUE].desc_ring.int_bit,
+ NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE);
+
+ NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_PACKET]);
+ return NSS_TX_SUCCESS;
+}
+
+/*
+ * nss_phys_if_tx_msg()
+ */
+nss_tx_status_t nss_phys_if_tx_msg(struct nss_ctx_instance *nss_ctx, struct nss_phys_if_msg *nvim)
+{
+ struct nss_cmn_msg *ncm = &nvim->cm;
+ struct nss_virt_if_msg *nvim2;
+ struct net_device *dev;
+ struct sk_buff *nbuf;
+ uint32_t if_num;
+ int32_t status;
+
+ if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
+ nss_warning("Interface could not be created as core not ready");
+ return -1;
+ }
+
+ /*
+ * Sanity check the message
+ */
+ if (!NSS_IS_IF_TYPE(PHYSICAL, ncm->interface)) {
+ nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
+ return NSS_TX_FAILURE;
+ }
+
+ if (ncm->type > NSS_PHYS_IF_MAX_MSG_TYPES) {
+ nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
+ return NSS_TX_FAILURE;
+ }
+
+ if (ncm->len > sizeof(struct nss_phys_if_msg)) {
+ nss_warning("%p: invalid length: %d", nss_ctx, ncm->len);
+ return NSS_TX_FAILURE;
+ }
+
+ if_num = ncm->interface;
+ dev = nss_top_main.if_ctx[if_num];
+ if (!dev) {
+ nss_warning("%p: Unregister physical interface %d: no context", nss_ctx, if_num);
+ return NSS_TX_FAILURE_BAD_PARAM;
+ }
+
+ nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE);
+ if (unlikely(!nbuf)) {
+ spin_lock_bh(&nss_ctx->nss_top->stats_lock);
+ nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]++;
+ spin_unlock_bh(&nss_ctx->nss_top->stats_lock);
+ nss_warning("%p: virtual interface %p: command allocation failed", nss_ctx, dev);
+ return -1;
+ }
+
+ nvim2 = (struct nss_virt_if_msg *)skb_put(nbuf, sizeof(struct nss_virt_if_msg));
+ memcpy(nvim2, nvim, sizeof(struct nss_virt_if_msg));
+
+ status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0);
+ if (status != NSS_CORE_STATUS_SUCCESS) {
+ dev_kfree_skb_any(nbuf);
+ nss_warning("%p: Unable to enqueue 'virtual interface' command\n", nss_ctx);
+ return -1;
+ }
+
+ nss_hal_send_interrupt(nss_ctx->nmap, nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit,
+ NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE);
+
+ return NSS_TX_SUCCESS;
+}
+
+/*
+ **********************************
+ Register/Unregister/Miscellaneous APIs
+ **********************************
+ */
+
+/*
+ * nss_phys_if_register()
+ */
+struct nss_ctx_instance *nss_phys_if_register(uint32_t if_num,
+ nss_phys_if_rx_callback_t rx_callback,
+ nss_phys_if_msg_callback_t msg_callback,
+ struct net_device *if_ctx)
+{
+ uint8_t id = nss_top_main.phys_if_handler_id[if_num];
+ struct nss_ctx_instance *nss_ctx = &nss_top_main.nss[id];
+
+ nss_assert(if_num <= NSS_MAX_PHYSICAL_INTERFACES);
+
+ nss_top_main.if_ctx[if_num] = (void *)if_ctx;
+ nss_top_main.if_rx_callback[if_num] = rx_callback;
+ nss_top_main.phys_if_msg_callback[if_num] = msg_callback;
+
+ nss_ctx->phys_if_mtu[if_num] = NSS_ETH_NORMAL_FRAME_MTU;
+ return nss_ctx;
+}
+
+/*
+ * nss_phys_if_unregister()
+ */
+void nss_phys_if_unregister(uint32_t if_num)
+{
+ nss_assert(if_num < NSS_MAX_PHYSICAL_INTERFACES);
+ nss_top_main.if_rx_callback[if_num] = NULL;
+ nss_top_main.phys_if_msg_callback[if_num] = NULL;
+ nss_top_main.if_ctx[if_num] = NULL;
+ nss_top_main.nss[0].phys_if_mtu[if_num] = 0;
+ nss_top_main.nss[1].phys_if_mtu[if_num] = 0;
+}
+
+/*
+ * nss_phys_if_get_napi_ctx()
+ * Get napi context
+ */
+nss_tx_status_t nss_phys_if_get_napi_ctx(struct nss_ctx_instance *nss_ctx, struct napi_struct **napi_ctx)
+{
+ nss_info("%p: Get interrupt context, GMAC\n", nss_ctx);
+
+ NSS_VERIFY_CTX_MAGIC(nss_ctx);
+ if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
+ return NSS_TX_FAILURE_NOT_READY;
+ }
+
+ *napi_ctx = &nss_ctx->int_ctx[0].napi;
+ return NSS_TX_SUCCESS;
+}
+
+/*
+ * nss_phys_if_register_handler()
+ */
+void nss_phys_if_register_handler(uint32_t if_num)
+{
+ nss_core_register_handler(if_num, nss_phys_if_msg_handler, NULL);
+}
+
+EXPORT_SYMBOL(nss_phys_if_tx_msg);
+EXPORT_SYMBOL(nss_phys_if_get_napi_ctx);
+EXPORT_SYMBOL(nss_phys_if_register);
+EXPORT_SYMBOL(nss_phys_if_unregister);
diff --git a/nss_phys_if.h b/nss_phys_if.h
new file mode 100755
index 0000000..d7fdb7b
--- /dev/null
+++ b/nss_phys_if.h
@@ -0,0 +1,145 @@
+/*
+ **************************************************************************
+ * Copyright (c) 2014, Qualcomm Atheros, Inc.
+ * 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_phys_if
+ * Physical interface message structure
+ */
+
+#ifndef __NSS_PHYS_IF_H
+#define __NSS_PHYS_IF_H
+
+/*
+ * Physical IF
+ */
+
+/**
+ * @brief Request/Response types
+ */
+enum nss_phys_if_msg_types {
+ NSS_PHYS_IF_OPEN = NSS_IF_OPEN,
+ NSS_PHYS_IF_CLOSE = NSS_IF_CLOSE,
+ NSS_PHYS_IF_LINK_STATE_NOTIFY = NSS_IF_LINK_STATE_NOTIFY,
+ NSS_PHYS_IF_MTU_CHANGE = NSS_IF_MTU_CHANGE,
+ NSS_PHYS_IF_MAC_ADDR_SET = NSS_IF_MAC_ADDR_SET,
+ NSS_PHYS_IF_RESERVED = NSS_IF_RESERVED,
+ NSS_PHYS_IF_STATS_SYNC = NSS_IF_STATS_SYNC,
+ NSS_PHYS_IF_ISHAPER_ASSIGN = NSS_IF_ISHAPER_ASSIGN,
+ NSS_PHYS_IF_BSHAPER_ASSIGN = NSS_IF_BSHAPER_ASSIGN,
+ NSS_PHYS_IF_ISHAPER_UNASSIGN = NSS_IF_ISHAPER_UNASSIGN,
+ NSS_PHYS_IF_BSHAPER_UNASSIGN = NSS_IF_BSHAPER_UNASSIGN,
+ NSS_PHYS_IF_ISHAPER_CONFIG = NSS_IF_ISHAPER_CONFIG,
+ NSS_PHYS_IF_BSHAPER_CONFIG = NSS_IF_BSHAPER_CONFIG,
+ NSS_PHYS_IF_MAX_MSG_TYPES
+};
+
+/**
+ * Message structure to send/receive virtual interface commands
+ */
+struct nss_phys_if_msg {
+ struct nss_cmn_msg cm; /**> Message Header */
+ union nss_if_msgs msg; /**> Interfaces messages */
+};
+
+
+/**
+ * Callback to receive physical interface messages
+ */
+typedef void (*nss_phys_if_msg_callback_t)(void *app_data, struct nss_phys_if_msg *msg);
+
+/**
+ * TODO: Adjust to pass app_data as unknown to the list layer and netdev/sk as known.
+ */
+typedef void (*nss_phys_if_rx_callback_t)(void *app_data, void *os_buf);
+
+/**
+ * @brief Get NAPI context
+ *
+ * @param nss_ctx NSS context
+ * @param napi_ctx Pointer to address to return NAPI context
+ *
+ * @return nss_tx_status_t Tx status
+ */
+extern nss_tx_status_t nss_phys_if_get_napi_ctx(struct nss_ctx_instance *nss_ctx, struct napi_struct **napi_ctx);
+
+/**
+ * @brief Register to send/receive GMAC packets/messages
+ *
+ * @param if_num GMAC i/f number
+ * @param rx_callback Receive callback for packets
+ * @param event_callback Receive callback for events
+ * @param if_ctx Interface context provided in callback
+ * (must be OS network device context pointer e.g.
+ * struct net_device * in Linux)
+ *
+ * @return void* NSS context
+ */
+extern struct nss_ctx_instance *nss_phys_if_register(uint32_t if_num,
+ nss_phys_if_rx_callback_t rx_callback,
+ nss_phys_if_msg_callback_t msg_callback,
+ struct net_device *if_ctx);
+
+/**
+ * @brief Send GMAC packet
+ *
+ * @param nss_ctx NSS context
+ * @param os_buf OS buffer (e.g. skbuff)
+ * @param if_num GMAC i/f number
+ *
+ * @return nss_tx_status_t Tx status
+ */
+extern nss_tx_status_t nss_phys_if_tx_buf(struct nss_ctx_instance *nss_ctx, struct sk_buff *os_buf, uint32_t if_num);
+
+/**
+ * @brief Assign dynamic interface number to a virtual interface
+ *
+ * @param if_ctx Interface context
+ *
+ * @return int32_t Interface number
+ */
+extern int32_t nss_phys_if_assign_if_num(struct net_device *if_ctx);
+
+/**
+ * @brief Send message to virtual interface
+ *
+ * @param nvim Virtual interface message
+ *
+ * @return command Tx status
+ */
+nss_tx_status_t nss_phys_if_tx_msg(struct nss_ctx_instance *nss_ctx, struct nss_phys_if_msg *nvim);
+
+/**
+ * @brief Forward Native wifi packet from virtual interface
+ * -Expects packet with qca-nwifi format
+ * @param if_num Interface number (provided during
+ * registeration)
+ * @param skb HLOS data buffer (sk_buff in Linux)
+ * @return command Tx status
+ */
+extern nss_tx_status_t nss_phys_if_tx_nwifi_rxbuf(int32_t if_num, struct sk_buff *skb);
+
+/**
+ * @brief Forward virtual interface packets
+ *
+ * @param if_num Interface number (provided during
+ * registeration)
+ * @param skb HLOS data buffer (sk_buff in Linux)
+ *
+ * @return command Tx status
+ */
+extern nss_tx_status_t nss_phys_if_tx_eth_rxbuf(int32_t if_num, struct sk_buff *skb);
+
+#endif /* __NSS_PHYS_IF_H */
diff --git a/nss_tx_rx_common.h b/nss_tx_rx_common.h
index d95c604..2ed8514 100755
--- a/nss_tx_rx_common.h
+++ b/nss_tx_rx_common.h
@@ -61,12 +61,13 @@
/*
* CB handlers for variour interfaces
*/
+extern void nss_phys_if_register_handler(uint32_t if_num);
+extern void nss_virt_if_register_handler(void);
extern void nss_crypto_register_handler(void);
extern void nss_ipsec_register_handler(void);
extern void nss_ipv4_register_handler(void);
extern void nss_ipv6_register_handler(void);
extern void nss_n2h_register_handler(void);
-extern void nss_phys_if_register_handler(uint32_t if_num);
extern void nss_tun6rd_register_handler(void);
extern void nss_tunipip6_register_handler(void);
extern void nss_pppoe_register_handler(void);
diff --git a/nss_tx_rx_phys_if.c b/nss_tx_rx_phys_if.c
index 11b5f4c..590f6a7 100755
--- a/nss_tx_rx_phys_if.c
+++ b/nss_tx_rx_phys_if.c
@@ -18,331 +18,13 @@
* nss_tx_rx_phys_if.c
* NSS Physical i/f (gmac) APIs
*/
-
#include "nss_tx_rx_common.h"
/*
- **********************************
- Tx APIs
- **********************************
+ * Maintain a private list of callbacks as the nss_top list
+ * if for new registrations.
*/
-
-/*
- * nss_tx_phys_if_buf ()
- * Send packet to physical interface owned by NSS
- */
-nss_tx_status_t nss_tx_phys_if_buf(void *ctx, struct sk_buff *os_buf, uint32_t if_num)
-{
- struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)ctx;
- int32_t status;
-
- nss_trace("%p: Phys If Tx packet, id:%d, data=%p", nss_ctx, if_num, os_buf->data);
-
- NSS_VERIFY_CTX_MAGIC(nss_ctx);
- if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
- nss_warning("%p: 'Phys If Tx' packet dropped as core not ready", nss_ctx);
- return NSS_TX_FAILURE_NOT_READY;
- }
-
- status = nss_core_send_buffer(nss_ctx, if_num, os_buf, NSS_IF_DATA_QUEUE, H2N_BUFFER_PACKET, 0);
- if (unlikely(status != NSS_CORE_STATUS_SUCCESS)) {
- nss_warning("%p: Unable to enqueue 'Phys If Tx' packet\n", nss_ctx);
- if (status == NSS_CORE_STATUS_FAILURE_QUEUE) {
- return NSS_TX_FAILURE_QUEUE;
- }
-
- return NSS_TX_FAILURE;
- }
-
- /*
- * Kick the NSS awake so it can process our new entry.
- */
- nss_hal_send_interrupt(nss_ctx->nmap, nss_ctx->h2n_desc_rings[NSS_IF_DATA_QUEUE].desc_ring.int_bit,
- NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE);
-
- NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_PACKET]);
- return NSS_TX_SUCCESS;
-}
-
-/*
- * nss_tx_phys_if_open()
- * Send open command to physical interface
- */
-nss_tx_status_t nss_tx_phys_if_open(void *ctx, uint32_t tx_desc_ring, uint32_t rx_desc_ring, uint32_t if_num)
-{
- struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *) ctx;
- struct sk_buff *nbuf;
- int32_t status;
- struct nss_if_msg *nim;
- struct nss_if_open *nio;
-
- nss_info("%p: Phys If Open, id:%d, TxDesc: %x, RxDesc: %x\n", nss_ctx, if_num, tx_desc_ring, rx_desc_ring);
-
- NSS_VERIFY_CTX_MAGIC(nss_ctx);
- if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
- nss_warning("%p: 'Phys If Open' rule dropped as core not ready", nss_ctx);
- return NSS_TX_FAILURE_NOT_READY;
- }
-
- nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE);
- if (unlikely(!nbuf)) {
- spin_lock_bh(&nss_ctx->nss_top->stats_lock);
- nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]++;
- spin_unlock_bh(&nss_ctx->nss_top->stats_lock);
- nss_warning("%p: 'Phys If Open' rule dropped as command allocation failed", nss_ctx);
- return NSS_TX_FAILURE;
- }
-
- nim = (struct nss_if_msg *)skb_put(nbuf, sizeof(struct nss_if_msg));
- nim->cm.interface = if_num;
- nim->cm.version = NSS_HLOS_MESSAGE_VERSION;
- nim->cm.type = NSS_TX_METADATA_TYPE_INTERFACE_OPEN;
- nim->cm.len = sizeof(struct nss_if_open);
-
- nio = &nim->msg.open;
-
- nio->tx_desc_ring = tx_desc_ring;
- nio->rx_desc_ring = rx_desc_ring;
-
- status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0);
- if (status != NSS_CORE_STATUS_SUCCESS) {
- dev_kfree_skb_any(nbuf);
- nss_warning("%p: Unable to enqueue 'Phys If Open' rule\n", nss_ctx);
- return NSS_TX_FAILURE;
- }
-
- nss_hal_send_interrupt(nss_ctx->nmap, nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit,
- NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE);
-
- NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]);
- return NSS_TX_SUCCESS;
-}
-
-/*
- * nss_tx_phys_if_close()
- * Send close command to physical interface
- */
-nss_tx_status_t nss_tx_phys_if_close(void *ctx, uint32_t if_num)
-{
- struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *) ctx;
- struct sk_buff *nbuf;
- int32_t status;
- struct nss_if_msg *nim;
- struct nss_if_close *nic;
-
- nss_info("%p: Phys If Close, id:%d \n", nss_ctx, if_num);
-
- NSS_VERIFY_CTX_MAGIC(nss_ctx);
- if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
- nss_warning("%p: 'Phys If Close' rule dropped as core not ready", nss_ctx);
- return NSS_TX_FAILURE_NOT_READY;
- }
-
- nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE);
- if (unlikely(!nbuf)) {
- spin_lock_bh(&nss_ctx->nss_top->stats_lock);
- nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]++;
- spin_unlock_bh(&nss_ctx->nss_top->stats_lock);
- nss_warning("%p: 'Phys If Close' rule dropped as command allocation failed", nss_ctx);
- return NSS_TX_FAILURE;
- }
-
- nim = (struct nss_if_msg *)skb_put(nbuf, sizeof(struct nss_if_msg));
- nim->cm.interface = if_num;
- nim->cm.version = NSS_HLOS_MESSAGE_VERSION;
- nim->cm.type = NSS_TX_METADATA_TYPE_INTERFACE_CLOSE;
- nim->cm.len = sizeof(struct nss_if_close);
-
- nic = &nim->msg.close;
-
- status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0);
- if (status != NSS_CORE_STATUS_SUCCESS) {
- dev_kfree_skb_any(nbuf);
- nss_info("%p: Unable to enqueue 'Phys If Close' rule\n", nss_ctx);
- return NSS_TX_FAILURE;
- }
-
- nss_hal_send_interrupt(nss_ctx->nmap, nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit,
- NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE);
-
- NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]);
- return NSS_TX_SUCCESS;
-}
-
-/*
- * nss_tx_phys_if_link_state()
- * Send link state to physical interface
- */
-nss_tx_status_t nss_tx_phys_if_link_state(void *ctx, uint32_t link_state, uint32_t if_num)
-{
- struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *) ctx;
- struct sk_buff *nbuf;
- int32_t status;
- struct nss_if_msg *nim;
- struct nss_if_link_state_notify *nils;
-
- nss_info("%p: Phys If Link State, id:%d, State: %x\n", nss_ctx, if_num, link_state);
-
- NSS_VERIFY_CTX_MAGIC(nss_ctx);
- if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
- nss_warning("%p: 'Phys If Link State' rule dropped as core not ready", nss_ctx);
- return NSS_TX_FAILURE_NOT_READY;
- }
-
- nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE);
- if (unlikely(!nbuf)) {
- spin_lock_bh(&nss_ctx->nss_top->stats_lock);
- nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]++;
- spin_unlock_bh(&nss_ctx->nss_top->stats_lock);
- nss_warning("%p: 'Phys If Link State' rule dropped as command allocation failed", nss_ctx);
- return NSS_TX_FAILURE;
- }
-
- nim = (struct nss_if_msg *)skb_put(nbuf, sizeof(struct nss_if_msg));
- nim->cm.interface = if_num;
- nim->cm.version = NSS_HLOS_MESSAGE_VERSION;
- nim->cm.type = NSS_TX_METADATA_TYPE_INTERFACE_LINK_STATE_NOTIFY;
- nim->cm.len = sizeof(struct nss_if_link_state_notify);
-
- nils = &nim->msg.link_state_notify;
- nils->state = link_state;
-
- status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0);
- if (status != NSS_CORE_STATUS_SUCCESS) {
- dev_kfree_skb_any(nbuf);
- nss_warning("%p: Unable to enqueue 'Phys If Link State' rule\n", nss_ctx);
- return NSS_TX_FAILURE;
- }
-
- nss_hal_send_interrupt(nss_ctx->nmap, nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit,
- NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE);
-
- NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]);
- return NSS_TX_SUCCESS;
-}
-
-/*
- * nss_tx_phys_if_mac_addr()
- * Send a MAC address to physical interface
- */
-nss_tx_status_t nss_tx_phys_if_mac_addr(void *ctx, uint8_t *addr, uint32_t if_num)
-{
- struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *) ctx;
- struct sk_buff *nbuf;
- int32_t status;
- struct nss_if_msg *nim;
- struct nss_if_mac_address_set *nmas;
-
- nss_info("%p: Phys If MAC Address, id:%d\n", nss_ctx, if_num);
- nss_assert(addr != 0);
-
- NSS_VERIFY_CTX_MAGIC(nss_ctx);
- if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
- nss_warning("%p: 'Phys If MAC Address' rule dropped as core not ready", nss_ctx);
- return NSS_TX_FAILURE_NOT_READY;
- }
-
- nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE);
- if (unlikely(!nbuf)) {
- spin_lock_bh(&nss_ctx->nss_top->stats_lock);
- nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]++;
- spin_unlock_bh(&nss_ctx->nss_top->stats_lock);
- nss_warning("%p: 'Phys If MAC Address' rule dropped as command allocation failed", nss_ctx);
- return NSS_TX_FAILURE;
- }
-
- nim = (struct nss_if_msg *)skb_put(nbuf, sizeof(struct nss_if_msg));
- nim->cm.interface = if_num;
- nim->cm.version = NSS_HLOS_MESSAGE_VERSION;
- nim->cm.type = NSS_TX_METADATA_TYPE_INTERFACE_MAC_ADDR_SET;
- nim->cm.len = sizeof(struct nss_if_mac_address_set);
-
- nmas = &nim->msg.mac_address_set;
- memcpy(nmas->mac_addr, addr, ETH_ALEN);
-
- status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0);
- if (status != NSS_CORE_STATUS_SUCCESS) {
- dev_kfree_skb_any(nbuf);
- nss_warning("%p: Unable to enqueue 'Phys If Mac Address' rule\n", nss_ctx);
- return NSS_TX_FAILURE;
- }
-
- nss_hal_send_interrupt(nss_ctx->nmap, nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit,
- NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE);
-
- NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]);
- return NSS_TX_SUCCESS;
-}
-
-/*
- * nss_tx_phys_if_change_mtu()
- * Send a MTU change command
- */
-nss_tx_status_t nss_tx_phys_if_change_mtu(void *ctx, uint32_t mtu, uint32_t if_num)
-{
- struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *) ctx;
- struct sk_buff *nbuf;
- int32_t status, i;
- uint16_t max_mtu;
- struct nss_if_msg *nim;
- struct nss_if_mtu_change *nimc;
-
- nss_info("%p: Phys If Change MTU, id:%d, mtu=%d\n", nss_ctx, if_num, mtu);
-
- NSS_VERIFY_CTX_MAGIC(nss_ctx);
- if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
- return NSS_TX_FAILURE_NOT_READY;
- }
-
- nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE);
- if (unlikely(!nbuf)) {
- spin_lock_bh(&nss_ctx->nss_top->stats_lock);
- nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]++;
- spin_unlock_bh(&nss_ctx->nss_top->stats_lock);
- nss_warning("%p: 'Phys If Change MTU' rule dropped as command allocation failed", nss_ctx);
- return NSS_TX_FAILURE;
- }
-
- nim = (struct nss_if_msg *)skb_put(nbuf, sizeof(struct nss_if_msg));
- nim->cm.interface = if_num;
- nim->cm.version = NSS_HLOS_MESSAGE_VERSION;
- nim->cm.type = NSS_TX_METADATA_TYPE_INTERFACE_MTU_CHANGE;
- nim->cm.len = sizeof(struct nss_if_mtu_change);
-
- nimc = &nim->msg.mtu_change;
- nimc->min_buf_size = (uint16_t)mtu + NSS_NBUF_ETH_EXTRA;
-
- status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0);
- if (status != NSS_CORE_STATUS_SUCCESS) {
- dev_kfree_skb_any(nbuf);
- nss_warning("%p: Unable to enqueue 'Phys If Change MTU' rule\n", nss_ctx);
- return NSS_TX_FAILURE;
- }
-
- nss_ctx->phys_if_mtu[if_num] = (uint16_t)mtu;
- max_mtu = nss_ctx->phys_if_mtu[0];
- for (i = 1; i < NSS_MAX_PHYSICAL_INTERFACES; i++) {
- if (max_mtu < nss_ctx->phys_if_mtu[i]) {
- max_mtu = nss_ctx->phys_if_mtu[i];
- }
- }
-
- if (max_mtu <= NSS_ETH_NORMAL_FRAME_MTU) {
- max_mtu = NSS_ETH_NORMAL_FRAME_MTU;
- } else if (max_mtu <= NSS_ETH_MINI_JUMBO_FRAME_MTU) {
- max_mtu = NSS_ETH_MINI_JUMBO_FRAME_MTU;
- } else if (max_mtu <= NSS_ETH_FULL_JUMBO_FRAME_MTU) {
- max_mtu = NSS_ETH_FULL_JUMBO_FRAME_MTU;
- }
-
- nss_ctx->max_buf_size = ((max_mtu + ETH_HLEN + SMP_CACHE_BYTES - 1) & ~(SMP_CACHE_BYTES - 1)) + NSS_NBUF_PAD_EXTRA;
-
- nss_hal_send_interrupt(nss_ctx->nmap, nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit,
- NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE);
-
- NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]);
- return NSS_TX_SUCCESS;
-}
+nss_phys_if_event_callback_t nss_tx_rx_phys_if_event_callback[NSS_MAX_PHYSICAL_INTERFACES];
/*
**********************************
@@ -354,7 +36,7 @@
* nss_rx_metadata_gmac_stats_sync()
* Handle the syncing of GMAC stats.
*/
-static void nss_rx_metadata_gmac_stats_sync(struct nss_ctx_instance *nss_ctx, struct nss_if_stats_sync *ngss, uint16_t interface)
+void nss_rx_metadata_gmac_stats_sync(struct nss_ctx_instance *nss_ctx, struct nss_if_stats_sync *ngss, uint16_t interface)
{
void *ctx;
nss_phys_if_event_callback_t cb;
@@ -366,8 +48,8 @@
return;
}
+ cb = nss_tx_rx_phys_if_event_callback[id];
ctx = nss_ctx->nss_top->if_ctx[id];
- cb = nss_ctx->nss_top->phys_if_event_callback[id];
/*
* Call GMAC driver callback
@@ -390,35 +72,146 @@
}
/*
- * nss_rx_phys_if_interface_handler()
- * Handle NSS -> HLOS messages for physical interface/gmacs
+ **********************************
+ Tx APIs
+ **********************************
*/
-static void nss_rx_phys_if_interface_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data)
+
+/*
+ * nss_tx_phys_if_buf ()
+ * Send packet to physical interface owned by NSS
+ */
+nss_tx_status_t nss_tx_phys_if_buf(void *ctx, struct sk_buff *os_buf, uint32_t if_num)
{
- struct nss_if_msg *nim = (struct nss_if_msg *)ncm;
+ struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *) ctx;
+ return nss_phys_if_tx_buf(nss_ctx, os_buf, if_num);
+}
+
+/*
+ * nss_tx_phys_if_open()
+ * Send open command to physical interface
+ */
+nss_tx_status_t nss_tx_phys_if_open(void *ctx, uint32_t tx_desc_ring, uint32_t rx_desc_ring, uint32_t if_num)
+{
+ struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *) ctx;
+ struct nss_phys_if_msg nim;
+ struct nss_if_open *nio;
+
+ NSS_VERIFY_CTX_MAGIC(nss_ctx);
+ nss_info("%p: Phys If Open, id:%d, TxDesc: %x, RxDesc: %x\n", nss_ctx, if_num, tx_desc_ring, rx_desc_ring);
+
+ nss_cmn_msg_init(&nim.cm, if_num, NSS_TX_METADATA_TYPE_INTERFACE_OPEN,
+ sizeof(struct nss_if_open), NULL, NULL);
+
+ nio = &nim.msg.open;
+ nio->tx_desc_ring = tx_desc_ring;
+ nio->rx_desc_ring = rx_desc_ring;
+ return nss_phys_if_tx_msg(nss_ctx, &nim);
+}
+
+/*
+ * nss_tx_phys_if_close()
+ * Send close command to physical interface
+ */
+nss_tx_status_t nss_tx_phys_if_close(void *ctx, uint32_t if_num)
+{
+ struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *) ctx;
+ struct nss_phys_if_msg nim;
+
+ NSS_VERIFY_CTX_MAGIC(nss_ctx);
+ nss_info("%p: Phys If Close, id:%d \n", nss_ctx, if_num);
+
+ nss_cmn_msg_init(&nim.cm, if_num, NSS_TX_METADATA_TYPE_INTERFACE_CLOSE,
+ sizeof(struct nss_if_close), NULL, NULL);
+
+ return nss_phys_if_tx_msg(nss_ctx, &nim);
+}
+
+/*
+ * nss_tx_phys_if_link_state()
+ * Send link state to physical interface
+ */
+nss_tx_status_t nss_tx_phys_if_link_state(void *ctx, uint32_t link_state, uint32_t if_num)
+{
+ struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *) ctx;
+ struct nss_phys_if_msg nim;
+ struct nss_if_link_state_notify *nils;
+
+ NSS_VERIFY_CTX_MAGIC(nss_ctx);
+ nss_info("%p: Phys If Link State, id:%d, State: %x\n", nss_ctx, if_num, link_state);
+
+ nss_cmn_msg_init(&nim.cm, if_num, NSS_TX_METADATA_TYPE_INTERFACE_LINK_STATE_NOTIFY,
+ sizeof(struct nss_if_link_state_notify), NULL, NULL);
+
+ nils = &nim.msg.link_state_notify;
+ nils->state = link_state;
+ return nss_phys_if_tx_msg(nss_ctx, &nim);
+}
+
+/*
+ * nss_tx_phys_if_mac_addr()
+ * Send a MAC address to physical interface
+ */
+nss_tx_status_t nss_tx_phys_if_mac_addr(void *ctx, uint8_t *addr, uint32_t if_num)
+{
+ struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *) ctx;
+ struct nss_phys_if_msg nim;
+ struct nss_if_mac_address_set *nmas;
+
+ NSS_VERIFY_CTX_MAGIC(nss_ctx);
+ nss_info("%p: Phys If MAC Address, id:%d\n", nss_ctx, if_num);
+ nss_assert(addr != 0);
+
+ nss_cmn_msg_init(&nim.cm, if_num, NSS_TX_METADATA_TYPE_INTERFACE_MAC_ADDR_SET,
+ sizeof(struct nss_if_mac_address_set), NULL, NULL);
+
+ nmas = &nim.msg.mac_address_set;
+ memcpy(nmas->mac_addr, addr, ETH_ALEN);
+ return nss_phys_if_tx_msg(nss_ctx, &nim);
+}
+
+/*
+ * nss_tx_phys_if_change_mtu()
+ * Send a MTU change command
+ */
+nss_tx_status_t nss_tx_phys_if_change_mtu(void *ctx, uint32_t mtu, uint32_t if_num)
+{
+ struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *) ctx;
+ struct nss_phys_if_msg nim;
+ struct nss_if_mtu_change *nimc;
+ int32_t i;
+ uint16_t max_mtu;
+
+ NSS_VERIFY_CTX_MAGIC(nss_ctx);
+ nss_info("%p: Phys If Change MTU, id:%d, mtu=%d\n", nss_ctx, if_num, mtu);
+ nss_cmn_msg_init(&nim.cm, if_num, NSS_TX_METADATA_TYPE_INTERFACE_MTU_CHANGE,
+ sizeof(struct nss_if_mtu_change), NULL, NULL);
+
+ nimc = &nim.msg.mtu_change;
+ nimc->min_buf_size = (uint16_t)mtu + NSS_NBUF_ETH_EXTRA;
/*
- * Is this a valid request/response packet?
+ * TODO: If we want to maintain this in the long run, we will need to place
+ * this in the ack side of the MTU_CHANGE request.
*/
- if (nim->cm.type >= NSS_METADATA_TYPE_INTERFACE_MAX) {
- nss_warning("%p: received invalid message %d for physical interface", nss_ctx, nim->cm.type);
- return;
- }
-
-
- switch (nim->cm.type) {
- case NSS_RX_METADATA_TYPE_INTERFACE_STATS_SYNC:
- nss_rx_metadata_gmac_stats_sync(nss_ctx, &nim->msg.stats_sync, ncm->interface);
- break;
- default:
- if (ncm->response != NSS_CMN_RESPONSE_ACK) {
- /*
- * Check response
- */
- nss_info("%p: Received response %d for type %d, interface %d",
- nss_ctx, ncm->response, ncm->type, ncm->interface);
+ nss_ctx->phys_if_mtu[if_num] = (uint16_t)mtu;
+ max_mtu = nss_ctx->phys_if_mtu[0];
+ for (i = 1; i < NSS_MAX_PHYSICAL_INTERFACES; i++) {
+ if (max_mtu < nss_ctx->phys_if_mtu[i]) {
+ max_mtu = nss_ctx->phys_if_mtu[i];
}
}
+
+ if (max_mtu <= NSS_ETH_NORMAL_FRAME_MTU) {
+ max_mtu = NSS_ETH_NORMAL_FRAME_MTU;
+ } else if (max_mtu <= NSS_ETH_MINI_JUMBO_FRAME_MTU) {
+ max_mtu = NSS_ETH_MINI_JUMBO_FRAME_MTU;
+ } else if (max_mtu <= NSS_ETH_FULL_JUMBO_FRAME_MTU) {
+ max_mtu = NSS_ETH_FULL_JUMBO_FRAME_MTU;
+ }
+ nss_ctx->max_buf_size = ((max_mtu + ETH_HLEN + SMP_CACHE_BYTES - 1) & ~(SMP_CACHE_BYTES - 1)) + NSS_NBUF_PAD_EXTRA;
+
+ return nss_phys_if_tx_msg(nss_ctx, &nim);
}
/*
@@ -441,21 +234,20 @@
nss_top_main.if_ctx[if_num] = (void *)if_ctx;
nss_top_main.if_rx_callback[if_num] = rx_callback;
- nss_top_main.phys_if_event_callback[if_num] = event_callback;
+ nss_tx_rx_phys_if_event_callback[if_num] = event_callback;
nss_ctx->phys_if_mtu[if_num] = NSS_ETH_NORMAL_FRAME_MTU;
- return (void *)nss_ctx;
+ return nss_ctx;
}
/*
- * nss_unregister_phys_if()
+ * nss_unregister_phys_if_()
*/
void nss_unregister_phys_if(uint32_t if_num)
{
nss_assert(if_num < NSS_MAX_PHYSICAL_INTERFACES);
-
nss_top_main.if_rx_callback[if_num] = NULL;
- nss_top_main.phys_if_event_callback[if_num] = NULL;
+ nss_tx_rx_phys_if_event_callback[if_num] = NULL;
nss_top_main.if_ctx[if_num] = NULL;
nss_top_main.nss[0].phys_if_mtu[if_num] = 0;
nss_top_main.nss[1].phys_if_mtu[if_num] = 0;
@@ -463,34 +255,13 @@
/*
* nss_tx_phys_if_get_napi_ctx()
- * Get napi context
+ * Obtain the napi context that is used to handle packet processing.
*/
-nss_tx_status_t nss_tx_phys_if_get_napi_ctx(void *ctx, struct napi_struct **napi_ctx)
+nss_tx_status_t nss_tx_phys_if_get_napi_ctx(void *nss_ctx, struct napi_struct **napi_ctx)
{
- struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *) ctx;
-
- nss_info("%p: Get interrupt context, GMAC\n", nss_ctx);
-
- NSS_VERIFY_CTX_MAGIC(nss_ctx);
- if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
- return NSS_TX_FAILURE_NOT_READY;
- }
-
- *napi_ctx = &nss_ctx->int_ctx[0].napi;
-
- return NSS_TX_SUCCESS;
+ return nss_phys_if_get_napi_ctx((struct nss_ctx_instance *)nss_ctx, napi_ctx);
}
-/*
- * nss_phys_if_register_handler()
- */
-void nss_phys_if_register_handler(uint32_t if_num)
-{
- nss_core_register_handler(if_num, nss_rx_phys_if_interface_handler, NULL);
-}
-
-EXPORT_SYMBOL(nss_register_phys_if);
-EXPORT_SYMBOL(nss_unregister_phys_if);
EXPORT_SYMBOL(nss_tx_phys_if_buf);
EXPORT_SYMBOL(nss_tx_phys_if_open);
EXPORT_SYMBOL(nss_tx_phys_if_close);
@@ -498,3 +269,7 @@
EXPORT_SYMBOL(nss_tx_phys_if_change_mtu);
EXPORT_SYMBOL(nss_tx_phys_if_mac_addr);
EXPORT_SYMBOL(nss_tx_phys_if_get_napi_ctx);
+EXPORT_SYMBOL(nss_register_phys_if);
+EXPORT_SYMBOL(nss_unregister_phys_if);
+
+
diff --git a/nss_tx_rx_virt_if.c b/nss_tx_rx_virt_if.c
index 3e2c513..072c510 100755
--- a/nss_tx_rx_virt_if.c
+++ b/nss_tx_rx_virt_if.c
@@ -136,11 +136,10 @@
*/
void *nss_create_virt_if(struct net_device *if_ctx)
{
- int32_t if_num, status;
- struct sk_buff *nbuf;
- struct nss_virt_if_msg *nvim;
+ struct nss_virt_if_msg nvim;
struct nss_virt_if_create *nvic;
struct nss_ctx_instance *nss_ctx = &nss_top_main.nss[nss_top_main.ipv4_handler_id];
+ int32_t if_num;
if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
nss_warning("Interface could not be created as core not ready");
@@ -178,33 +177,14 @@
return NULL;
}
- nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE);
- if (unlikely(!nbuf)) {
- spin_lock_bh(&nss_ctx->nss_top->stats_lock);
- nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]++;
- spin_unlock_bh(&nss_ctx->nss_top->stats_lock);
- nss_warning("%p: Register virtual interface %p: command allocation failed", nss_ctx, if_ctx);
- return NULL;
- }
+ nss_cmn_msg_init(&nvim.cm, if_num, NSS_VIRT_IF_TX_CREATE_MSG,
+ sizeof(struct nss_virt_if_create), NULL, NULL);
- nvim = (struct nss_virt_if_msg *)skb_put(nbuf, sizeof(struct nss_virt_if_msg));
- nvim->cm.interface = if_num;
- nvim->cm.version = NSS_HLOS_MESSAGE_VERSION;
- nvim->cm.type = NSS_VIRT_IF_TX_CREATE_MSG;
- nvim->cm.len = sizeof(struct nss_virt_if_create);
-
- nvic = &nvim->msg.create;
+ nvic = &nvim.msg.create;
nvic->flags = 0;
memcpy(nvic->mac_addr, if_ctx->dev_addr, ETH_HLEN);
- status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0);
- if (status != NSS_CORE_STATUS_SUCCESS) {
- dev_kfree_skb_any(nbuf);
- nss_warning("%p: Unable to enqueue 'Register virtual interface' rule\n", nss_ctx);
- return NULL;
- }
- nss_hal_send_interrupt(nss_ctx->nmap, nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit,
- NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE);
+ (void)nss_virt_if_tx_msg(&nvim);
/*
* Hold a reference to the net_device
@@ -224,10 +204,8 @@
*/
nss_tx_status_t nss_destroy_virt_if(void *ctx)
{
- int32_t status, if_num;
- struct sk_buff *nbuf;
- struct nss_virt_if_msg *nvim;
- struct nss_virt_if_destroy *nvid;
+ int32_t if_num;
+ struct nss_virt_if_msg nvim;
struct net_device *dev;
struct nss_ctx_instance *nss_ctx = &nss_top_main.nss[nss_top_main.ipv4_handler_id];
@@ -255,51 +233,15 @@
nss_info("%p:Unregister virtual interface %d (%p)", nss_ctx, if_num, dev);
dev_put(dev);
- nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE);
- if (unlikely(!nbuf)) {
- spin_lock_bh(&nss_ctx->nss_top->stats_lock);
- nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]++;
- spin_unlock_bh(&nss_ctx->nss_top->stats_lock);
- nss_warning("%p: Unregister virtual interface %d: command allocation failed", nss_ctx, if_num);
- return NSS_TX_FAILURE;
- }
+ nss_cmn_msg_init(&nvim.cm, if_num, NSS_VIRT_IF_TX_DESTROY_MSG,
+ sizeof(struct nss_virt_if_destroy), NULL, NULL);
- nvim = (struct nss_virt_if_msg *)skb_put(nbuf, sizeof(struct nss_virt_if_msg));
- nvim->cm.interface = if_num;
- nvim->cm.version = NSS_HLOS_MESSAGE_VERSION;
- nvim->cm.type = NSS_VIRT_IF_TX_DESTROY_MSG;
- nvim->cm.len = sizeof(struct nss_virt_if_destroy);
-
- nvid = &nvim->msg.destroy;
-
- status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0);
- if (status != NSS_CORE_STATUS_SUCCESS) {
- dev_kfree_skb_any(nbuf);
- nss_warning("%p: Unable to enqueue 'unregister virtual interface' rule\n", nss_ctx);
- return NSS_TX_FAILURE_QUEUE;
- }
-
- nss_hal_send_interrupt(nss_ctx->nmap, nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit,
- NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE);
-
- return NSS_TX_SUCCESS;
+ return nss_virt_if_tx_msg(&nvim);
}
-/*
- * nss_virt_if_get_interface_num()
- * Get interface number for a virtual interface
- */
-int32_t nss_virt_if_get_interface_num(void *if_ctx)
-{
- int32_t if_num = (int32_t)if_ctx;
- nss_assert(NSS_IS_IF_TYPE(VIRTUAL, if_num));
- return if_num;
-}
-
-
-EXPORT_SYMBOL(nss_create_virt_if);
-EXPORT_SYMBOL(nss_destroy_virt_if);
EXPORT_SYMBOL(nss_tx_virt_if_rxbuf);
EXPORT_SYMBOL(nss_tx_virt_if_rx_nwifibuf);
-EXPORT_SYMBOL(nss_virt_if_get_interface_num);
+EXPORT_SYMBOL(nss_create_virt_if);
+EXPORT_SYMBOL(nss_destroy_virt_if);
+
diff --git a/nss_virt_if.c b/nss_virt_if.c
index 654f6bc..9a361b0 100755
--- a/nss_virt_if.c
+++ b/nss_virt_if.c
@@ -26,10 +26,51 @@
extern int nss_ctl_redirect;
/*
- * nss_virt_if_rxbuf()
+ * nss_virt_if_msg_handler()
+ * Handle msg responses from the FW on virtual interfaces
+ */
+static void nss_virt_if_msg_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data)
+{
+ struct nss_virt_if_msg *nvim = (struct nss_virt_if_msg *)ncm;
+ nss_virt_if_msg_callback_t cb;
+
+ /*
+ * Sanity check the message type
+ */
+ if (ncm->type > NSS_IPV4_MAX_MSG_TYPES) {
+ nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
+ return;
+ }
+
+ if (ncm->len > sizeof(struct nss_virt_if_msg)) {
+ nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
+ return;
+ }
+
+ /*
+ * Log failures
+ */
+ nss_core_log_msg_failures(nss_ctx, ncm);
+
+ /*
+ * Do we have a callback?
+ */
+ if (!ncm->cb) {
+ return;
+ }
+
+ /*
+ * Callback
+ */
+ cb = (nss_virt_if_msg_callback_t)ncm->cb;
+ cb((void *)ncm->app_data, nvim);
+}
+
+/*
+ * nss_virt_if_tx_rxbuf()
* HLOS interface has received a packet which we redirect to the NSS, if appropriate to do so.
*/
-static nss_tx_status_t nss_virt_if_rxbuf(int32_t if_num, struct sk_buff *skb, uint32_t nwifi)
+static nss_tx_status_t nss_virt_if_tx_rxbuf(int32_t if_num, struct sk_buff *skb, uint32_t nwifi)
{
int32_t status;
struct nss_ctx_instance *nss_ctx = &nss_top_main.nss[nss_top_main.ipv4_handler_id];
@@ -106,7 +147,7 @@
*/
nss_tx_status_t nss_virt_if_tx_eth_rxbuf(int32_t if_num, struct sk_buff *skb)
{
- return nss_virt_if_rxbuf(if_num, skb, 0);
+ return nss_virt_if_tx_rxbuf(if_num, skb, 0);
}
/*
@@ -114,7 +155,98 @@
*/
nss_tx_status_t nss_virt_if_tx_nwifi_rxbuf(int32_t if_num, struct sk_buff *skb)
{
- return nss_virt_if_rxbuf(if_num, skb, 1);
+ return nss_virt_if_tx_rxbuf(if_num, skb, 1);
+}
+
+
+/*
+ * nss_virt_if_tx_msg()
+ */
+nss_tx_status_t nss_virt_if_tx_msg(struct nss_virt_if_msg *nvim)
+{
+ int32_t if_num, status;
+ struct sk_buff *nbuf;
+ struct nss_cmn_msg *ncm = &nvim->cm;
+ struct net_device *dev;
+ struct nss_virt_if_msg *nvim2;
+ struct nss_ctx_instance *nss_ctx = &nss_top_main.nss[nss_top_main.ipv4_handler_id];
+
+ if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
+ nss_warning("Interface could not be created as core not ready");
+ return -1;
+ }
+
+ /*
+ * Sanity check the message
+ */
+ if (!NSS_IS_IF_TYPE(VIRTUAL, ncm->interface)) {
+ nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
+ return NSS_TX_FAILURE;
+ }
+
+ if (ncm->type > NSS_VIRT_IF_MAX_MSG_TYPES) {
+ nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
+ return NSS_TX_FAILURE;
+ }
+
+ if (ncm->len > sizeof(struct nss_virt_if_msg)) {
+ nss_warning("%p: invalid length: %d", nss_ctx, ncm->len);
+ return NSS_TX_FAILURE;
+ }
+
+ if_num = ncm->interface;
+ dev = nss_top_main.if_ctx[if_num];
+ if (!dev) {
+ nss_warning("%p: Unregister virtual interface %d: no context", nss_ctx, if_num);
+ return NSS_TX_FAILURE_BAD_PARAM;
+ }
+
+ if (ncm->type == NSS_VIRT_IF_TX_DESTROY_MSG) {
+ /*
+ * Set this context to NULL
+ */
+ spin_lock_bh(&nss_top_main.lock);
+ nss_top_main.if_ctx[if_num] = NULL;
+ spin_unlock_bh(&nss_top_main.lock);
+ dev_put(dev);
+ nss_info("%p:Unregister virtual interface %d (%p)", nss_ctx, if_num, dev);
+
+ }
+
+ nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE);
+ if (unlikely(!nbuf)) {
+ spin_lock_bh(&nss_ctx->nss_top->stats_lock);
+ nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]++;
+ spin_unlock_bh(&nss_ctx->nss_top->stats_lock);
+ nss_warning("%p: virtual interface %p: command allocation failed", nss_ctx, dev);
+ return -1;
+ }
+
+ nvim2 = (struct nss_virt_if_msg *)skb_put(nbuf, sizeof(struct nss_virt_if_msg));
+ memcpy(nvim2, nvim, sizeof(struct nss_virt_if_msg));
+
+ status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0);
+ if (status != NSS_CORE_STATUS_SUCCESS) {
+ dev_kfree_skb_any(nbuf);
+ nss_warning("%p: Unable to enqueue 'virtual interface' command\n", nss_ctx);
+ return -1;
+ }
+
+ nss_hal_send_interrupt(nss_ctx->nmap, nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit,
+ NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE);
+
+ /*
+ * Hold a reference to the net_device
+ */
+ if (ncm->type == NSS_VIRT_IF_TX_CREATE_MSG) {
+ dev_hold(dev);
+ }
+
+ /*
+ * The context returned is the virtual interface # which is, essentially, the index into the if_ctx
+ * array that is holding the net_device pointer
+ */
+ return NSS_TX_SUCCESS;
}
/*
@@ -161,100 +293,31 @@
}
/*
- * nss_virt_if_tx_msg()
+ * nss_virt_if_get_interface_num()
+ * Get interface number for a virtual interface
*/
-nss_tx_status_t nss_virt_if_tx_msg(struct nss_virt_if_msg *nvim)
+int32_t nss_virt_if_get_interface_num(void *if_ctx)
{
- int32_t if_num, status;
- struct sk_buff *nbuf;
- struct nss_cmn_msg *ncm = &nvim->cm;
- struct net_device *dev;
- struct nss_virt_if_msg *nvim2;
- struct nss_ctx_instance *nss_ctx = &nss_top_main.nss[nss_top_main.ipv4_handler_id];
+ int32_t if_num = (int32_t)if_ctx;
+ nss_assert(NSS_IS_IF_TYPE(VIRTUAL, if_num));
+ return if_num;
+}
- if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
- nss_warning("Interface could not be created as core not ready");
- return -1;
+/*
+ * nss_phys_if_register_handler()
+ */
+void nss_virt_if_register_handler(void)
+{
+ int i;
+ int end = NSS_VIRTUAL_IF_START + NSS_MAX_VIRTUAL_INTERFACES;
+ for (i = NSS_VIRTUAL_IF_START; i < end; i++) {
+ nss_core_register_handler(i, nss_virt_if_msg_handler, NULL);
}
-
- /*
- * Sanity check the message
- */
- if (!NSS_IS_IF_TYPE(VIRTUAL, ncm->interface)) {
- nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
- return NSS_TX_FAILURE;
- }
-
- if (ncm->type > NSS_VIRT_IF_MAX_MSG_TYPES) {
- nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
- return NSS_TX_FAILURE;
- }
-
- if (ncm->len > sizeof(struct nss_virt_if_msg)) {
- nss_warning("%p: invalid length: %d", nss_ctx, ncm->len);
- return NSS_TX_FAILURE;
- }
-
- if_num = ncm->interface;
- dev = nss_top_main.if_ctx[if_num];
- if (!dev) {
- nss_warning("%p: Unregister virtual interface %d: no context", nss_ctx, if_num);
- return NSS_TX_FAILURE_BAD_PARAM;
- }
-
- if (ncm->type == NSS_VIRT_IF_TX_DESTROY_MSG) {
- spin_lock_bh(&nss_top_main.lock);
-
- /*
- * Set this context to NULL
- */
- nss_top_main.if_ctx[if_num] = NULL;
- spin_unlock_bh(&nss_top_main.lock);
-
- dev_put(dev);
- nss_info("%p:Unregister virtual interface %d (%p)", nss_ctx, if_num, dev);
-
- }
-
- nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE);
- if (unlikely(!nbuf)) {
- spin_lock_bh(&nss_ctx->nss_top->stats_lock);
- nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]++;
- spin_unlock_bh(&nss_ctx->nss_top->stats_lock);
- nss_warning("%p: virtual interface %p: command allocation failed", nss_ctx, dev);
- return -1;
- }
-
- nvim2 = (struct nss_virt_if_msg *)skb_put(nbuf, sizeof(struct nss_virt_if_msg));
- memcpy(nvim2, nvim, sizeof(struct nss_virt_if_msg));
-
- status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0);
- if (status != NSS_CORE_STATUS_SUCCESS) {
- dev_kfree_skb_any(nbuf);
- nss_warning("%p: Unable to enqueue 'virtual interface' command\n", nss_ctx);
- return -1;
- }
-
- nss_hal_send_interrupt(nss_ctx->nmap, nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit,
- NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE);
-
- /*
- * Hold a reference to the net_device
- */
- if (ncm->type == NSS_VIRT_IF_TX_CREATE_MSG) {
- dev_hold(dev);
- }
-
- /*
- * The context returned is the virtual interface # which is, essentially, the index into the if_ctx
- * array that is holding the net_device pointer
- */
- return NSS_TX_SUCCESS;
}
EXPORT_SYMBOL(nss_virt_if_assign_if_num);
EXPORT_SYMBOL(nss_virt_if_tx_msg);
EXPORT_SYMBOL(nss_virt_if_tx_nwifi_rxbuf);
EXPORT_SYMBOL(nss_virt_if_tx_eth_rxbuf);
-
+EXPORT_SYMBOL(nss_virt_if_get_interface_num);
diff --git a/nss_virt_if.h b/nss_virt_if.h
index cefa536..06c7e4a 100755
--- a/nss_virt_if.h
+++ b/nss_virt_if.h
@@ -22,6 +22,8 @@
#ifndef __NSS_VIRT_IF_H
#define __NSS_VIRT_IF_H
+#include "nss_if.h"
+
/*
* Virtual IF/Redirect
*/
@@ -29,8 +31,21 @@
/**
* @brief Request/Response types
*/
-enum nss_virt_if_metadata_types {
- NSS_VIRT_IF_TX_CREATE_MSG,
+enum nss_virt_if_msg_types {
+ NSS_VIRT_IF_OPEN = NSS_IF_OPEN,
+ NSS_VIRT_IF_CLOSE = NSS_IF_CLOSE,
+ NSS_VIRT_IF_LINK_STATE_NOTIFY = NSS_IF_LINK_STATE_NOTIFY,
+ NSS_VIRT_IF_MTU_CHANGE = NSS_IF_MTU_CHANGE,
+ NSS_VIRT_IF_MAC_ADDR_SET = NSS_IF_MAC_ADDR_SET,
+ NSS_VIRT_IF_RESERVED = NSS_IF_RESERVED,
+ NSS_VIRT_IF_STATS_SYNC = NSS_IF_STATS_SYNC,
+ NSS_VIRT_IF_ISHAPER_ASSIGN = NSS_IF_ISHAPER_ASSIGN,
+ NSS_VIRT_IF_BSHAPER_ASSIGN = NSS_IF_BSHAPER_ASSIGN,
+ NSS_VIRT_IF_ISHAPER_UNASSIGN = NSS_IF_ISHAPER_UNASSIGN,
+ NSS_VIRT_IF_BSHAPER_UNASSIGN = NSS_IF_BSHAPER_UNASSIGN,
+ NSS_VIRT_IF_ISHAPER_CONFIG = NSS_IF_ISHAPER_CONFIG,
+ NSS_VIRT_IF_BSHAPER_CONFIG = NSS_IF_BSHAPER_CONFIG,
+ NSS_VIRT_IF_TX_CREATE_MSG = NSS_IF_MAX_MSG_TYPES + 1,
NSS_VIRT_IF_TX_DESTROY_MSG,
NSS_VIRT_IF_MAX_MSG_TYPES,
};
@@ -56,11 +71,14 @@
struct nss_virt_if_msg {
struct nss_cmn_msg cm; /**> Message Header */
union {
+ union nss_if_msgs if_msgs;
struct nss_virt_if_create create; /**> Message: create virt if rule */
struct nss_virt_if_destroy destroy; /**> Message: destroy virt if rule */
} msg;
};
+typedef void (*nss_virt_if_msg_callback_t)(void *app_data, struct nss_virt_if_msg *msg);
+
/**
* @brief Assign dynamic interface number to a virtual interface
*