[qca-nss-drv] Set the REUSABLE flag for NSS send API
By default all the NSS data/cmd APIs send the buffers
with no reuse flag set. The nss core send logic sets
the reuse flag based on the some default conditions.
The current patch flips the logic where it sends all the data/cmd
packets with reusable flag and nss-core send logic resets
the reusable flag if they fail to meet the conditions of reuse. This
provides the flexibility where a user can explicitly call the send
APIs witn/without the reusable flag.
Change-Id: I883ca9bf25fe2b79a2f03663be2e1166f4454bec
Signed-off-by: Aniruddha Paul <paulani@codeaurora.org>
diff --git a/exports/nss_cmn.h b/exports/nss_cmn.h
index 9f2ee96..a3fc289 100644
--- a/exports/nss_cmn.h
+++ b/exports/nss_cmn.h
@@ -293,21 +293,6 @@
extern bool nss_cmn_interface_is_redirect(struct nss_ctx_instance *nss_ctx, int32_t interface_num);
/**
- * nss_cmn_interface_is_reuse_not_supported
- * Determines if the interface supports SKB no-reuse.
- *
- * @datatypes
- * nss_ctx_instance
- *
- * @param[in] nss_ctx Pointer to the NSS context.
- * @param[in] interface_num NSS interface number.
- *
- * @return
- * TRUE if the interface number supports SKB reuse. Otherwise FALSE.
- */
-extern bool nss_cmn_interface_is_reuse_not_supported(struct nss_ctx_instance *nss_ctx, int32_t interface_num);
-
-/**
* nss_cmn_append_core_id
* Append core ID on NSS interface number.
*
diff --git a/nss_capwap.c b/nss_capwap.c
index c69dcea..7e8ce33 100644
--- a/nss_capwap.c
+++ b/nss_capwap.c
@@ -322,7 +322,7 @@
{
BUG_ON(!nss_capwap_verify_if_num(if_num));
- return nss_core_send_packet(nss_ctx, os_buf, if_num, H2N_BIT_FLAG_VIRTUAL_BUFFER);
+ return nss_core_send_packet(nss_ctx, os_buf, if_num, H2N_BIT_FLAG_VIRTUAL_BUFFER | H2N_BIT_FLAG_BUFFER_REUSABLE);
}
EXPORT_SYMBOL(nss_capwap_tx_buf);
diff --git a/nss_cmn.c b/nss_cmn.c
index f818847..391c277 100644
--- a/nss_cmn.c
+++ b/nss_cmn.c
@@ -205,22 +205,6 @@
EXPORT_SYMBOL(nss_cmn_interface_is_redirect);
/*
- * nss_cmn_interface_is_reuse_not_supported()
- * Determines if the interface supports skb no-reuse.
- */
-bool nss_cmn_interface_is_reuse_not_supported(struct nss_ctx_instance *nss_ctx, int32_t interface_num)
-{
- enum nss_dynamic_interface_type type = NSS_DYNAMIC_INTERFACE_TYPE_NONE;
-
- /*
- * Check if the interface belongs to the GRE exception DS.
- */
- type = nss_dynamic_interface_get_type(nss_ctx, interface_num);
- return type == NSS_DYNAMIC_INTERFACE_TYPE_GRE_REDIR_EXCEPTION_DS;
-}
-EXPORT_SYMBOL(nss_cmn_interface_is_reuse_not_supported);
-
-/*
* nss_cmn_rx_dropped_sum()
* Sum rx_dropped count.
*/
diff --git a/nss_core.c b/nss_core.c
index bf9fdf0..b41a209 100644
--- a/nss_core.c
+++ b/nss_core.c
@@ -966,7 +966,7 @@
* and count the test packets properly.
*/
NSS_PKT_STATS_INC(&nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_RX_STATUS]);
- status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_H2N_DATA_QUEUE, H2N_BUFFER_RATE_TEST, 0);
+ status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_H2N_DATA_QUEUE, H2N_BUFFER_RATE_TEST, H2N_BIT_FLAG_BUFFER_REUSABLE);
if (unlikely(status != NSS_CORE_STATUS_SUCCESS)) {
dev_kfree_skb_any(nbuf);
nss_warning("%p: Unable to enqueue\n", nss_ctx);
@@ -2380,27 +2380,13 @@
#if (NSS_SKB_REUSE_SUPPORT == 1)
/*
- * nss_skb_can_reuse
+ * nss_core_skb_can_reuse
* check if skb can be reuse
*/
-static inline bool nss_skb_can_reuse(struct nss_ctx_instance *nss_ctx,
+static inline bool nss_core_skb_can_reuse(struct nss_ctx_instance *nss_ctx,
uint32_t if_num, struct sk_buff *nbuf, int min_skb_size)
{
/*
- * Don't re-use if this is a redirect interface.
- */
- if (nss_cmn_interface_is_redirect(nss_ctx, if_num)) {
- return false;
- }
-
- /*
- * Check if this interface supports skb reuse.
- */
- if (nss_cmn_interface_is_reuse_not_supported(nss_ctx, if_num)) {
- return false;
- }
-
- /*
* If we have to call a destructor, we can't re-use the buffer?
*/
if (unlikely(nbuf->destructor != NULL)) {
@@ -2543,9 +2529,16 @@
#if (NSS_SKB_REUSE_SUPPORT == 1)
/*
- * Check if the skb is reuseable without resetting its fields.
+ * Check if the caller indicates that the buffer is not to be re-used (kept in the accelerator).
*/
- if (unlikely(!nss_skb_can_reuse(nss_ctx, if_num, nbuf, nss_ctx->max_buf_size))) {
+ if (unlikely(!(bit_flags & H2N_BIT_FLAG_BUFFER_REUSABLE))) {
+ goto no_reuse;
+ }
+
+ /*
+ * Since the caller is allowing re-use, we now check if the skb meets the criteria.
+ */
+ if (unlikely(!nss_core_skb_can_reuse(nss_ctx, if_num, nbuf, nss_ctx->max_buf_size))) {
goto no_reuse;
}
@@ -2562,7 +2555,6 @@
/*
* We are allowed to re-use the packet
*/
- bit_flags |= H2N_BIT_FLAG_BUFFER_REUSE;
nss_core_write_one_descriptor(desc, buffer_type, frag0phyaddr, if_num,
(nss_ptr_t)nbuf, (uint16_t)(nbuf->data - nbuf->head), nbuf->len,
sz, (uint32_t)nbuf->priority, mss, bit_flags);
@@ -2580,6 +2572,7 @@
no_reuse:
#endif
+ bit_flags &= ~H2N_BIT_FLAG_BUFFER_REUSABLE;
frag0phyaddr = nss_core_dma_map_single(nss_ctx->dev, nbuf);
if (unlikely(dma_mapping_error(nss_ctx->dev, frag0phyaddr))) {
nss_warning("%p: DMA mapping failed for virtual address = %p", nss_ctx, nbuf->head);
@@ -2626,6 +2619,11 @@
* Set the appropriate flags.
*/
bit_flags = (flags | H2N_BIT_FLAG_DISCARD);
+
+ /*
+ * Reset the reuse flag for non-linear buffers.
+ */
+ bit_flags &= ~H2N_BIT_FLAG_BUFFER_REUSABLE;
if (likely(nbuf->ip_summed == CHECKSUM_PARTIAL)) {
bit_flags |= H2N_BIT_FLAG_GEN_IP_TRANSPORT_CHECKSUM;
bit_flags |= H2N_BIT_FLAG_GEN_IPV4_IP_CHECKSUM;
@@ -2716,6 +2714,11 @@
* Copy and Set bit flags
*/
bit_flags = flags;
+
+ /*
+ * Reset the reuse flag for non-linear buffers.
+ */
+ bit_flags &= ~H2N_BIT_FLAG_BUFFER_REUSABLE;
if (likely(nbuf->ip_summed == CHECKSUM_PARTIAL)) {
bit_flags |= H2N_BIT_FLAG_GEN_IP_TRANSPORT_CHECKSUM;
bit_flags |= H2N_BIT_FLAG_GEN_IPV4_IP_CHECKSUM;
@@ -3026,7 +3029,7 @@
memcpy(skb_put(nbuf, buf_size), (void *)ncm, size);
- status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_H2N_CMD_QUEUE, H2N_BUFFER_CTRL, 0);
+ status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_H2N_CMD_QUEUE, H2N_BUFFER_CTRL, H2N_BIT_FLAG_BUFFER_REUSABLE);
if (status != NSS_CORE_STATUS_SUCCESS) {
dev_kfree_skb_any(nbuf);
NSS_PKT_STATS_INC(&nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_QUEUE_FULL]);
diff --git a/nss_crypto.c b/nss_crypto.c
index 18ae4f3..b2603eb 100644
--- a/nss_crypto.c
+++ b/nss_crypto.c
@@ -164,7 +164,7 @@
return NSS_TX_FAILURE_NOT_READY;
}
- status = nss_core_send_buffer(nss_ctx, if_num, skb, NSS_IF_H2N_DATA_QUEUE, H2N_BUFFER_PACKET, 0);
+ status = nss_core_send_buffer(nss_ctx, if_num, skb, NSS_IF_H2N_DATA_QUEUE, H2N_BUFFER_PACKET, H2N_BIT_FLAG_BUFFER_REUSABLE);
if (unlikely(status != NSS_CORE_STATUS_SUCCESS)) {
nss_warning("%p: tx_data Unable to enqueue packet", nss_ctx);
if (status == NSS_CORE_STATUS_FAILURE_QUEUE) {
diff --git a/nss_crypto_cmn.c b/nss_crypto_cmn.c
index 13133a8..9a31e0f 100644
--- a/nss_crypto_cmn.c
+++ b/nss_crypto_cmn.c
@@ -233,7 +233,7 @@
return NSS_TX_FAILURE_NOT_READY;
}
- status = nss_core_send_buffer(nss_ctx, if_num, skb, NSS_IF_H2N_DATA_QUEUE, H2N_BUFFER_PACKET, 0);
+ status = nss_core_send_buffer(nss_ctx, if_num, skb, NSS_IF_H2N_DATA_QUEUE, H2N_BUFFER_PACKET, H2N_BIT_FLAG_BUFFER_REUSABLE);
switch (status) {
case NSS_CORE_STATUS_SUCCESS:
break;
diff --git a/nss_dtls.c b/nss_dtls.c
index f3aedc5..eaf7ce7 100644
--- a/nss_dtls.c
+++ b/nss_dtls.c
@@ -1,6 +1,6 @@
/*
**************************************************************************
- * Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2016-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.
@@ -260,7 +260,7 @@
{
BUG_ON(!nss_dtls_verify_if_num(if_num));
- return nss_core_send_packet(nss_ctx, skb, if_num, H2N_BIT_FLAG_VIRTUAL_BUFFER);
+ return nss_core_send_packet(nss_ctx, skb, if_num, H2N_BIT_FLAG_VIRTUAL_BUFFER | H2N_BIT_FLAG_BUFFER_REUSABLE);
}
EXPORT_SYMBOL(nss_dtls_tx_buf);
diff --git a/nss_dtls_cmn.c b/nss_dtls_cmn.c
index edce996..c0d76b6 100644
--- a/nss_dtls_cmn.c
+++ b/nss_dtls_cmn.c
@@ -229,7 +229,7 @@
if (!nss_dtls_cmn_verify_ifnum(nss_ctx, if_num))
return NSS_TX_FAILURE;
- return nss_core_send_packet(nss_ctx, skb, if_num, H2N_BIT_FLAG_VIRTUAL_BUFFER);
+ return nss_core_send_packet(nss_ctx, skb, if_num, H2N_BIT_FLAG_VIRTUAL_BUFFER | H2N_BIT_FLAG_BUFFER_REUSABLE);
}
EXPORT_SYMBOL(nss_dtls_cmn_tx_buf);
diff --git a/nss_gre.c b/nss_gre.c
index d1f06c7..c5d1ee2 100644
--- a/nss_gre.c
+++ b/nss_gre.c
@@ -276,7 +276,7 @@
*/
nss_tx_status_t nss_gre_tx_buf(struct nss_ctx_instance *nss_ctx, uint32_t if_num, struct sk_buff *skb)
{
- return nss_core_send_packet(nss_ctx, skb, if_num, H2N_BIT_FLAG_VIRTUAL_BUFFER);
+ return nss_core_send_packet(nss_ctx, skb, if_num, H2N_BIT_FLAG_VIRTUAL_BUFFER | H2N_BIT_FLAG_BUFFER_REUSABLE);
}
EXPORT_SYMBOL(nss_gre_tx_buf);
diff --git a/nss_gre_redir.c b/nss_gre_redir.c
index ef8eec3..6f6fb66 100644
--- a/nss_gre_redir.c
+++ b/nss_gre_redir.c
@@ -630,7 +630,7 @@
return NSS_TX_FAILURE_BAD_PARAM;
}
- return nss_core_send_packet(nss_ctx, os_buf, if_num, 0);
+ return nss_core_send_packet(nss_ctx, os_buf, if_num, H2N_BIT_FLAG_BUFFER_REUSABLE);
}
EXPORT_SYMBOL(nss_gre_redir_tx_buf);
diff --git a/nss_gre_tunnel.c b/nss_gre_tunnel.c
index 435102b..a52a205 100644
--- a/nss_gre_tunnel.c
+++ b/nss_gre_tunnel.c
@@ -1,6 +1,6 @@
/*
**************************************************************************
- * Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2016-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.
@@ -198,7 +198,7 @@
{
BUG_ON(!nss_gre_tunnel_verify_if_num(if_num));
- return nss_core_send_packet(nss_ctx, skb, if_num, H2N_BIT_FLAG_VIRTUAL_BUFFER);
+ return nss_core_send_packet(nss_ctx, skb, if_num, H2N_BIT_FLAG_VIRTUAL_BUFFER | H2N_BIT_FLAG_BUFFER_REUSABLE);
}
EXPORT_SYMBOL(nss_gre_tunnel_tx_buf);
diff --git a/nss_hlos_if.h b/nss_hlos_if.h
index 7d2c50c..d8ffbe3 100644
--- a/nss_hlos_if.h
+++ b/nss_hlos_if.h
@@ -234,7 +234,7 @@
#define H2N_BIT_FLAG_SEGMENTATION_ENABLE 0x0100
#define H2N_BIT_FLAG_VIRTUAL_BUFFER 0x2000
-#define H2N_BIT_FLAG_BUFFER_REUSE 0x8000
+#define H2N_BIT_FLAG_BUFFER_REUSABLE 0x8000
/*
* HLOS to NSS descriptor structure.
diff --git a/nss_if.c b/nss_if.c
index 0607ba9..bce69f0 100644
--- a/nss_if.c
+++ b/nss_if.c
@@ -1,6 +1,6 @@
/*
**************************************************************************
- * Copyright (c) 2014-2016, 2018, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2014-2016, 2018-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.
@@ -83,7 +83,7 @@
return NSS_TX_FAILURE_BAD_PARAM;
}
- return nss_core_send_packet(nss_ctx, os_buf, if_num, 0);
+ return nss_core_send_packet(nss_ctx, os_buf, if_num, H2N_BIT_FLAG_BUFFER_REUSABLE);
}
/*
diff --git a/nss_ipsec.c b/nss_ipsec.c
index 2184bff..f3540e5 100644
--- a/nss_ipsec.c
+++ b/nss_ipsec.c
@@ -336,7 +336,7 @@
nss_trace("%p: IPsec If Tx packet, id:%d, data=%p", nss_ctx, if_num, skb->data);
- return nss_core_send_packet(nss_ctx, skb, if_num, 0);
+ return nss_core_send_packet(nss_ctx, skb, if_num, H2N_BIT_FLAG_BUFFER_REUSABLE);
}
EXPORT_SYMBOL(nss_ipsec_tx_buf);
diff --git a/nss_ipsec_cmn.c b/nss_ipsec_cmn.c
index a59fe54..8baa37d 100644
--- a/nss_ipsec_cmn.c
+++ b/nss_ipsec_cmn.c
@@ -394,7 +394,7 @@
return NSS_TX_FAILURE;
}
- return nss_core_send_packet(nss_ctx, os_buf, if_num, 0);
+ return nss_core_send_packet(nss_ctx, os_buf, if_num, H2N_BIT_FLAG_BUFFER_REUSABLE);
}
EXPORT_SYMBOL(nss_ipsec_cmn_tx_buf);
diff --git a/nss_phys_if.c b/nss_phys_if.c
index 60e5888..217f04d 100644
--- a/nss_phys_if.c
+++ b/nss_phys_if.c
@@ -177,7 +177,7 @@
return nss_tstamp_tx_buf(nss_ctx, os_buf, if_num);
}
- return nss_core_send_packet(nss_ctx, os_buf, if_num, 0);
+ return nss_core_send_packet(nss_ctx, os_buf, if_num, H2N_BIT_FLAG_BUFFER_REUSABLE);
}
/*
diff --git a/nss_pptp.c b/nss_pptp.c
index 5f0283c..2129db4 100644
--- a/nss_pptp.c
+++ b/nss_pptp.c
@@ -1,6 +1,6 @@
/*
**************************************************************************
- * Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2015-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.
@@ -345,7 +345,7 @@
{
nss_trace("%p: pptp If Tx packet, id:%d, data=%p", nss_ctx, if_num, skb->data);
- return nss_core_send_packet(nss_ctx, skb, if_num, 0);
+ return nss_core_send_packet(nss_ctx, skb, if_num, H2N_BIT_FLAG_BUFFER_REUSABLE);
}
/*
diff --git a/nss_pvxlan.c b/nss_pvxlan.c
index 6958abc..bdb9177 100644
--- a/nss_pvxlan.c
+++ b/nss_pvxlan.c
@@ -290,7 +290,7 @@
{
BUG_ON(!nss_pvxlan_verify_if_num(if_num));
- return nss_core_send_packet(nss_ctx, buf, if_num, H2N_BIT_FLAG_VIRTUAL_BUFFER);
+ return nss_core_send_packet(nss_ctx, buf, if_num, H2N_BIT_FLAG_VIRTUAL_BUFFER | H2N_BIT_FLAG_BUFFER_REUSABLE);
}
EXPORT_SYMBOL(nss_pvxlan_tx_buf);
diff --git a/nss_qvpn.c b/nss_qvpn.c
index 54889ba..46e3c13 100644
--- a/nss_qvpn.c
+++ b/nss_qvpn.c
@@ -271,7 +271,7 @@
return NSS_TX_FAILURE_BAD_PARAM;
}
- return nss_core_send_packet(nss_ctx, skb, if_num, 0);
+ return nss_core_send_packet(nss_ctx, skb, if_num, H2N_BIT_FLAG_BUFFER_REUSABLE);
}
EXPORT_SYMBOL(nss_qvpn_tx_buf);
diff --git a/nss_shaper.c b/nss_shaper.c
index 325e9ac..2e97486 100644
--- a/nss_shaper.c
+++ b/nss_shaper.c
@@ -290,7 +290,7 @@
}
spin_unlock_bh(&nss_top->lock);
- status = nss_core_send_buffer(nss_ctx, if_num, skb, NSS_IF_H2N_DATA_QUEUE, H2N_BUFFER_SHAPER_BOUNCE_INTERFACE, 0);
+ status = nss_core_send_buffer(nss_ctx, if_num, skb, NSS_IF_H2N_DATA_QUEUE, H2N_BUFFER_SHAPER_BOUNCE_INTERFACE, H2N_BIT_FLAG_BUFFER_REUSABLE);
if (status != NSS_CORE_STATUS_SUCCESS) {
return NSS_TX_FAILURE;
}
@@ -334,7 +334,7 @@
spin_unlock_bh(&nss_top->lock);
nss_info("%s: Bridge bounce skb: %p, if_num: %u, ctx: %p", __func__, skb, if_num, nss_ctx);
- status = nss_core_send_buffer(nss_ctx, if_num, skb, NSS_IF_H2N_DATA_QUEUE, H2N_BUFFER_SHAPER_BOUNCE_BRIDGE, 0);
+ status = nss_core_send_buffer(nss_ctx, if_num, skb, NSS_IF_H2N_DATA_QUEUE, H2N_BUFFER_SHAPER_BOUNCE_BRIDGE, H2N_BIT_FLAG_BUFFER_REUSABLE);
if (status != NSS_CORE_STATUS_SUCCESS) {
nss_info("%s: Bridge bounce core send rejected", __func__);
return NSS_TX_FAILURE;
diff --git a/nss_tstamp.c b/nss_tstamp.c
index 6ce5a22..bed36a2 100644
--- a/nss_tstamp.c
+++ b/nss_tstamp.c
@@ -352,7 +352,7 @@
h2n_hdr->ts_ifnum = if_num;
h2n_hdr->ts_tx_hdr_sz = hdr_sz;
- return nss_core_send_packet(nss_ctx, skb, NSS_TSTAMP_RX_INTERFACE, H2N_BIT_FLAG_VIRTUAL_BUFFER);
+ return nss_core_send_packet(nss_ctx, skb, NSS_TSTAMP_RX_INTERFACE, H2N_BIT_FLAG_VIRTUAL_BUFFER | H2N_BIT_FLAG_BUFFER_REUSABLE);
}
EXPORT_SYMBOL(nss_tstamp_tx_buf);
diff --git a/nss_wifi_if.c b/nss_wifi_if.c
index e695f1e..84d4c97 100644
--- a/nss_wifi_if.c
+++ b/nss_wifi_if.c
@@ -1,6 +1,6 @@
/*
**************************************************************************
- * Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2015-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.
diff --git a/nss_wifi_vdev.c b/nss_wifi_vdev.c
index b398b21..d4b29cd 100644
--- a/nss_wifi_vdev.c
+++ b/nss_wifi_vdev.c
@@ -179,7 +179,7 @@
return NSS_TX_FAILURE;
}
- status = nss_core_send_buffer(nss_ctx, 0, os_buf, NSS_IF_H2N_CMD_QUEUE, H2N_BUFFER_CTRL, 0);
+ status = nss_core_send_buffer(nss_ctx, 0, os_buf, NSS_IF_H2N_CMD_QUEUE, H2N_BUFFER_CTRL, H2N_BIT_FLAG_BUFFER_REUSABLE);
if (status != NSS_CORE_STATUS_SUCCESS) {
nss_warning("%p: Unable to enqueue 'wifi vdev message'", nss_ctx);
return NSS_TX_FAILURE;
@@ -201,7 +201,7 @@
{
BUG_ON(((if_num < NSS_DYNAMIC_IF_START) || (if_num >= (NSS_DYNAMIC_IF_START + NSS_MAX_DYNAMIC_INTERFACES))));
- return nss_core_send_packet(nss_ctx, os_buf, if_num, 0);
+ return nss_core_send_packet(nss_ctx, os_buf, if_num, H2N_BIT_FLAG_BUFFER_REUSABLE);
}
EXPORT_SYMBOL(nss_wifi_vdev_tx_buf);