.../net/ethernet/marvell/octeontx2/nic/otx2_common.c | 3 ++- .../net/ethernet/marvell/octeontx2/nic/otx2_common.h | 1 + drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c | 3 +++ drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c | 10 ++++++++++ drivers/net/ethernet/marvell/octeontx2/nic/rep.c | 12 +++++++++++- drivers/net/ethernet/marvell/octeontx2/nic/rep.h | 1 + 6 files changed, 28 insertions(+), 2 deletions(-)
Implement packet length validation before submitting packets to
the hardware to prevent MAXLEN_ERR. Increment tx_dropped counter
on failure.
Fixes: 3184fb5ba96e ("octeontx2-vf: Virtual function driver support")
Fixes: 22f858796758 ("octeontx2-pf: Add basic net_device_ops")
Fixes: 3ca6c4c882a7 ("octeontx2-pf: Add packet transmission support")
Signed-off-by: Hariprasad Kelam <hkelam@marvell.com>
---
v3 * Define driver specific counter for storing dropped packets
v2 * Add the packet length check for rep dev
Increment tx_dropped counter on failure
.../net/ethernet/marvell/octeontx2/nic/otx2_common.c | 3 ++-
.../net/ethernet/marvell/octeontx2/nic/otx2_common.h | 1 +
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c | 3 +++
drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c | 10 ++++++++++
drivers/net/ethernet/marvell/octeontx2/nic/rep.c | 12 +++++++++++-
drivers/net/ethernet/marvell/octeontx2/nic/rep.h | 1 +
6 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
index 6b5c9536d26d..e480c8692baa 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
@@ -124,7 +124,8 @@ void otx2_get_dev_stats(struct otx2_nic *pfvf)
dev_stats->rx_ucast_frames;
dev_stats->tx_bytes = OTX2_GET_TX_STATS(TX_OCTS);
- dev_stats->tx_drops = OTX2_GET_TX_STATS(TX_DROP);
+ dev_stats->tx_drops = OTX2_GET_TX_STATS(TX_DROP) +
+ dev_stats->tx_discards;
dev_stats->tx_bcast_frames = OTX2_GET_TX_STATS(TX_BCAST);
dev_stats->tx_mcast_frames = OTX2_GET_TX_STATS(TX_MCAST);
dev_stats->tx_ucast_frames = OTX2_GET_TX_STATS(TX_UCAST);
diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h
index ca0e6ab12ceb..a58c902eb75d 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h
@@ -149,6 +149,7 @@ struct otx2_dev_stats {
u64 tx_bcast_frames;
u64 tx_mcast_frames;
u64 tx_drops;
+ u64 tx_discards;
};
/* Driver counted stats */
diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
index db7c466fdc39..f9cf6a8f2f9b 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
@@ -2153,6 +2153,7 @@ static netdev_tx_t otx2_xmit(struct sk_buff *skb, struct net_device *netdev)
{
struct otx2_nic *pf = netdev_priv(netdev);
int qidx = skb_get_queue_mapping(skb);
+ struct otx2_dev_stats *dev_stats;
struct otx2_snd_queue *sq;
struct netdev_queue *txq;
int sq_idx;
@@ -2165,6 +2166,8 @@ static netdev_tx_t otx2_xmit(struct sk_buff *skb, struct net_device *netdev)
/* Check for minimum and maximum packet length */
if (skb->len <= ETH_HLEN ||
(!skb_shinfo(skb)->gso_size && skb->len > pf->tx_max_pktlen)) {
+ dev_stats = &pf->hw.dev_stats;
+ dev_stats->tx_discards++;
dev_kfree_skb(skb);
return NETDEV_TX_OK;
}
diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c
index 8a8b598bd389..3bb55e4a11d3 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c
@@ -391,9 +391,19 @@ static netdev_tx_t otx2vf_xmit(struct sk_buff *skb, struct net_device *netdev)
{
struct otx2_nic *vf = netdev_priv(netdev);
int qidx = skb_get_queue_mapping(skb);
+ struct otx2_dev_stats *dev_stats;
struct otx2_snd_queue *sq;
struct netdev_queue *txq;
+ /* Check for minimum and maximum packet length */
+ if (skb->len <= ETH_HLEN ||
+ (!skb_shinfo(skb)->gso_size && skb->len > vf->tx_max_pktlen)) {
+ dev_stats = &vf->hw.dev_stats;
+ dev_stats->tx_discards++;
+ dev_kfree_skb(skb);
+ return NETDEV_TX_OK;
+ }
+
sq = &vf->qset.sq[qidx];
txq = netdev_get_tx_queue(netdev, qidx);
diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/rep.c b/drivers/net/ethernet/marvell/octeontx2/nic/rep.c
index 2cd3da3b6843..d2412d027f6f 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/rep.c
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/rep.c
@@ -371,7 +371,7 @@ static void rvu_rep_get_stats(struct work_struct *work)
stats->rx_mcast_frames = rsp->rx.mcast;
stats->tx_bytes = rsp->tx.octs;
stats->tx_frames = rsp->tx.ucast + rsp->tx.bcast + rsp->tx.mcast;
- stats->tx_drops = rsp->tx.drop;
+ stats->tx_drops = rsp->tx.drop + stats->tx_discards;
exit:
mutex_unlock(&priv->mbox.lock);
}
@@ -418,6 +418,16 @@ static netdev_tx_t rvu_rep_xmit(struct sk_buff *skb, struct net_device *dev)
struct otx2_nic *pf = rep->mdev;
struct otx2_snd_queue *sq;
struct netdev_queue *txq;
+ struct rep_stats *stats;
+
+ /* Check for minimum and maximum packet length */
+ if (skb->len <= ETH_HLEN ||
+ (!skb_shinfo(skb)->gso_size && skb->len > pf->tx_max_pktlen)) {
+ stats = &rep->stats;
+ stats->tx_discards++;
+ dev_kfree_skb(skb);
+ return NETDEV_TX_OK;
+ }
sq = &pf->qset.sq[rep->rep_id];
txq = netdev_get_tx_queue(dev, 0);
diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/rep.h b/drivers/net/ethernet/marvell/octeontx2/nic/rep.h
index 38446b3e4f13..277615ed7174 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/rep.h
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/rep.h
@@ -27,6 +27,7 @@ struct rep_stats {
u64 tx_bytes;
u64 tx_frames;
u64 tx_drops;
+ u64 tx_discards;
};
struct rep_dev {
--
2.34.1
On Mon, Jul 21, 2025 at 02:28:15PM +0530, Hariprasad Kelam wrote: > Implement packet length validation before submitting packets to > the hardware to prevent MAXLEN_ERR. Increment tx_dropped counter > on failure. Sorry, i did not look at previous versions of this patch, so i might be asking a question some other Reviewer already asked. How expensive is MAXLEN_ERR? What do you need to do when it happens? I would _guess_ that if ndev->mtu is set correctly, and any change to it validated, you are going to get very few packets which are too big. Is it better to introduce this test on the hot path which effects every single packet, or just deal with MAXLEN_ERR if it ever actually happens, so leaving the hot path optimised for the common case? Maybe you could include something about this in the commit message? Andrew
On 2025-07-21 at 19:28:05, Andrew Lunn (andrew@lunn.ch) wrote: > On Mon, Jul 21, 2025 at 02:28:15PM +0530, Hariprasad Kelam wrote: > > Implement packet length validation before submitting packets to > > the hardware to prevent MAXLEN_ERR. Increment tx_dropped counter > > on failure. > > Sorry, i did not look at previous versions of this patch, so i might > be asking a question some other Reviewer already asked. > > How expensive is MAXLEN_ERR? What do you need to do when it happens? > On error case, hardware raises the queue interrupts about max lenth errors goes to hang state. Driver needs to execute reset to come out of the state. > I would _guess_ that if ndev->mtu is set correctly, and any change to > it validated, you are going to get very few packets which are too big. > > Is it better to introduce this test on the hot path which effects > every single packet, or just deal with MAXLEN_ERR if it ever actually > happens, so leaving the hot path optimised for the common case? > > Maybe you could include something about this in the commit message? > ACK will update the commit description. > Andrew >
© 2016 - 2025 Red Hat, Inc.