net: mana: Add support for coalesced RX packets
Subsystems (5)
cover net: mana: Add support for coalesced RX packets
From: Haiyang Zhang <[email protected]>
Our NIC can have up to 4 RX packets on 1 CQE. To support this feature, update the RX code path, and ethtool handler. Also add counters for it.
Haiyang Zhang (2):
net: mana: Add support for coalesced RX packets on CQE
net: mana: Add ethtool counters for RX CQEs in coalesced type
drivers/net/ethernet/microsoft/mana/mana_en.c | 49 +++++++++---- .../ethernet/microsoft/mana/mana_ethtool.c | 72 +++++++++++++++++-- include/net/mana/mana.h | 12 ++-- 3 files changed, 112 insertions(+), 21 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/2 net: mana: Add support for coalesced RX packets on CQE
From: Haiyang Zhang <[email protected]>
Our NIC can have up to 4 RX packets on 1 CQE. To support this feature, check and process the type CQE_RX_COALESCED_4. The default setting is disabled, to avoid possible regression on latency.
And add ethtool handler to switch this feature. To turn it on, run:
ethtool -C <nic> rx-frames 4
To turn it off:
ethtool -C <nic> rx-frames 1
--- drivers/net/ethernet/microsoft/mana/mana_en.c | 32 ++++++----- .../ethernet/microsoft/mana/mana_ethtool.c | 55 +++++++++++++++++++ include/net/mana/mana.h | 2 + 3 files changed, 74 insertions(+), 15 deletions(-)
drivers/net/ethernet/microsoft/mana/mana_en.c +17 -15
@@ -1330,7 +1330,7 @@ static int mana_cfg_vport_steering(struct mana_port_context *apc, req->update_hashkey = update_key; req->update_indir_tab = update_tab; req->default_rxobj = apc->default_rxobj; - req->cqe_coalescing_enable =0 ; + req->cqe_coalescing_enable = apc->cqe_coalescing_enable;if (update_key)memcpy (&req->hashkey, apc->hashkey,MANA_HASH_KEY_SIZE );
@@ -1864,11 +1864,12 @@ static struct sk_buff *mana_build_skb(struct mana_rxq *rxq, void *buf_va, }static void mana_rx_skb (void *buf_va,bool from_pool, -struct mana_rxcomp_oob *cqe,struct mana_rxq *rxq) +struct mana_rxcomp_oob *cqe,struct mana_rxq *rxq, +int i) {struct mana_stats_rx *rx_stats = &rxq->stats;struct net_device *ndev = rxq->ndev; -uint pkt_len = cqe->ppi[0 ].pkt_len; +uint pkt_len = cqe->ppi[i].pkt_len;u16 rxq_idx = rxq->rxq_idx;struct napi_struct *napi;struct xdp_buff xdp = {};
@@ -1912,7 +1913,7 @@ static void mana_rx_skb(void *buf_va, bool from_pool, }if (cqe->rx_hashtype !=0 && (ndev->features &NETIF_F_RXHASH )) { - hash_value = cqe->ppi[0 ].pkt_hash; + hash_value = cqe->ppi[i].pkt_hash;if (cqe->rx_hashtype &MANA_HASH_L4 )skb_set_hash (skb, hash_value,PKT_HASH_TYPE_L4 );
@@ -2047,9 +2048,11 @@ static void mana_process_rx_cqe(struct mana_rxq *rxq, struct mana_cq *cq,struct mana_recv_buf_oob *rxbuf_oob;struct mana_port_context *apc;struct device *dev = gc->dev; +bool coalesced = false;void *old_buf =NULL ;u32 curr, pktlen;bool old_fp; +int i =0 ; apc =netdev_priv (ndev);
@@ -2064,9 +2067,8 @@ static void mana_process_rx_cqe(struct mana_rxq *rxq, struct mana_cq *cq, goto drop;case CQE_RX_COALESCED_4 : -netdev_err (ndev,"RX coalescing is unsupported\n" ); - apc->eth_stats.rx_coalesced_err++; -return ; + coalesced = true; +break ;case CQE_RX_OBJECT_FENCE :complete (&rxq->fence_event);
@@ -2079,14 +2081,10 @@ static void mana_process_rx_cqe(struct mana_rxq *rxq, struct mana_cq *cq,return ; } - pktlen = oob->ppi[0 ].pkt_len; - -if (pktlen ==0 ) { -/* data packets should never have packetlength of zero */ -netdev_err (ndev,"RX pkt len=0, rq=%u, cq=%u, rxobj=0x%llx\n" , - rxq->gdma_id, cq->gdma_id, rxq->rxobj); +nextpkt: + pktlen = oob->ppi[i].pkt_len; +if (pktlen ==0 )return ; - } curr = rxq->buf_index; rxbuf_oob = &rxq->rx_oobs[curr];
@@ -2097,12 +2095,15 @@ static void mana_process_rx_cqe(struct mana_rxq *rxq, struct mana_cq *cq,/* Unsuccessful refill will have old_buf == NULL. * In this case, mana_rx_skb() will drop the packet. */ -mana_rx_skb (old_buf, old_fp, oob, rxq); +mana_rx_skb (old_buf, old_fp, oob, rxq, i); drop:mana_move_wq_tail (rxq->gdma_rq, rxbuf_oob->wqe_inf.wqe_size_in_bu);mana_post_pkt_rxq (rxq); + +if (coalesced && (++i <MANA_RXCOMP_OOB_NUM_PPI )) + goto nextpkt; }static void mana_poll_rx_cq (struct mana_cq *cq)
@@ -3276,6 +3277,7 @@ static int mana_probe_port(struct mana_context *ac, int port_idx, apc->port_handle =INVALID_MANA_HANDLE ; apc->pf_filter_handle =INVALID_MANA_HANDLE ; apc->port_idx = port_idx; + apc->cqe_coalescing_enable =0 ;mutex_init (&apc->vport_mutex); apc->vport_use_count =0 ;
drivers/net/ethernet/microsoft/mana/mana_ethtool.c +55 -0
73 lines not on this page · raw message
include/net/mana/mana.h +2 -0
@@ -556,6 +556,8 @@ struct mana_port_context {bool port_is_up;bool port_st_save;/* Saved port state */ +u8 cqe_coalescing_enable; +struct mana_ethtool_stats eth_stats;struct mana_ethtool_phy_stats phy_stats;
Signature · 1 line
2.34.1
PATCH 2/2 net: mana: Add ethtool counters for RX CQEs in coalesced type
In reply to Haiyang ZhangFrom: Haiyang Zhang <[email protected]>
For RX CQEs with type CQE_RX_COALESCED_4, to measure the coalescing efficiency, add counters to count how many contains 2, 3, 4 packets respectively.
Also, add a counter for the error case of first packet with length == 0.
--- drivers/net/ethernet/microsoft/mana/mana_en.c | 25 +++++++++++++++++-- .../ethernet/microsoft/mana/mana_ethtool.c | 17 ++++++++++--- include/net/mana/mana.h | 10 +++++--- 3 files changed, 42 insertions(+), 10 deletions(-)
drivers/net/ethernet/microsoft/mana/mana_en.c +23 -2
@@ -2083,8 +2083,22 @@ static void mana_process_rx_cqe(struct mana_rxq *rxq, struct mana_cq *cq, nextpkt: pktlen = oob->ppi[i].pkt_len; -if (pktlen ==0 ) +if (pktlen ==0 ) { +/* Collect coalesced CQE count based on packets processed. +* Coalesced CQEs have at least 2 packets, so index is i - 2. +*/ +if (i >1 ) { +u64_stats_update_begin (&rxq->stats.syncp); + rxq->stats.coalesced_cqe[i -2 ]++; +u64_stats_update_end (&rxq->stats.syncp); + }else if (i ==0 ) { +/* Error case stat */ +u64_stats_update_begin (&rxq->stats.syncp); + rxq->stats.pkt_len0_err++; +u64_stats_update_end (&rxq->stats.syncp); + }return ; + } curr = rxq->buf_index; rxbuf_oob = &rxq->rx_oobs[curr];
@@ -2102,8 +2116,15 @@ static void mana_process_rx_cqe(struct mana_rxq *rxq, struct mana_cq *cq,mana_post_pkt_rxq (rxq); -if (coalesced && (++i <MANA_RXCOMP_OOB_NUM_PPI )) +if (!coalesced) +return ; + +if (++i <MANA_RXCOMP_OOB_NUM_PPI ) goto nextpkt; + +u64_stats_update_begin (&rxq->stats.syncp); + rxq->stats.coalesced_cqe[MANA_RXCOMP_OOB_NUM_PPI -2 ]++; +u64_stats_update_end (&rxq->stats.syncp); }static void mana_poll_rx_cq (struct mana_cq *cq)
drivers/net/ethernet/microsoft/mana/mana_ethtool.c +13 -4
@@ -20,8 +20,6 @@ static const struct mana_stats_desc mana_eth_stats[] = { tx_cqe_unknown_type)}, {"tx_linear_pkt_cnt" , offsetof(struct mana_ethtool_stats , tx_linear_pkt_cnt)}, - {"rx_coalesced_err", offsetof(struct mana_ethtool_stats, - rx_coalesced_err)}, {"rx_cqe_unknown_type", offsetof(struct mana_ethtool_stats, rx_cqe_unknown_type)}, };
@@ -151,7 +149,7 @@ static void mana_get_strings(struct net_device *ndev, u32 stringset, u8 *data) {struct mana_port_context *apc =netdev_priv (ndev);unsigned int num_queues = apc->num_queues; -int i; +int i, j;if (stringset !=ETH_SS_STATS )return ;
@@ -170,6 +168,9 @@ static void mana_get_strings(struct net_device *ndev, u32 stringset, u8 *data)ethtool_sprintf (&data,"rx_%d_xdp_drop" , i);ethtool_sprintf (&data,"rx_%d_xdp_tx" , i);ethtool_sprintf (&data,"rx_%d_xdp_redirect" , i); +ethtool_sprintf (&data,"rx_%d_pkt_len0_err" , i); +for (j =0 ; j <MANA_RXCOMP_OOB_NUM_PPI -1 ; j++) +ethtool_sprintf (&data,"rx_%d_coalesced_cqe_%d" , i, j +2 ); }for (i =0 ; i < num_queues; i++) {
@@ -203,6 +204,8 @@ static void mana_get_ethtool_stats(struct net_device *ndev,u64 xdp_xmit;u64 xdp_drop;u64 xdp_tx; +u64 pkt_len0_err; +u64 coalesced_cqe[MANA_RXCOMP_OOB_NUM_PPI -1 ];u64 tso_packets;u64 tso_bytes;u64 tso_inner_packets;
@@ -211,7 +214,7 @@ static void mana_get_ethtool_stats(struct net_device *ndev,u64 short_pkt_fmt;u64 csum_partial;u64 mana_map_err; -int q, i =0 ; +int q, i =0 , j;if (!apc->port_is_up)return ;
@@ -241,6 +244,9 @@ static void mana_get_ethtool_stats(struct net_device *ndev, xdp_drop = rx_stats->xdp_drop; xdp_tx = rx_stats->xdp_tx; xdp_redirect = rx_stats->xdp_redirect; + pkt_len0_err = rx_stats->pkt_len0_err; +for (j =0 ; j <MANA_RXCOMP_OOB_NUM_PPI -1 ; j++) + coalesced_cqe[j] = rx_stats->coalesced_cqe[j]; }while (u64_stats_fetch_retry (&rx_stats->syncp, start)); data[i++] = packets;
@@ -248,6 +254,9 @@ static void mana_get_ethtool_stats(struct net_device *ndev, data[i++] = xdp_drop; data[i++] = xdp_tx; data[i++] = xdp_redirect; + data[i++] = pkt_len0_err; +for (j =0 ; j <MANA_RXCOMP_OOB_NUM_PPI -1 ; j++) + data[i++] = coalesced_cqe[j]; }for (q =0 ; q < num_queues; q++) {
include/net/mana/mana.h +6 -4
@@ -61,8 +61,11 @@ enum TRI_STATE {#define MAX_PORTS_IN_MANA_DEV 256 +/* Maximum number of packets per coalesced CQE */ +#define MANA_RXCOMP_OOB_NUM_PPI 4 +/* Update this count whenever the respective structures are changed */ -#define MANA_STATS_RX_COUNT 5 +#define MANA_STATS_RX_COUNT (6 + MANA_RXCOMP_OOB_NUM_PPI - 1)#define MANA_STATS_TX_COUNT 11#define MANA_RX_FRAG_ALIGNMENT 64
@@ -73,6 +76,8 @@ struct mana_stats_rx {u64 xdp_drop;u64 xdp_tx;u64 xdp_redirect; +u64 pkt_len0_err; +u64 coalesced_cqe[MANA_RXCOMP_OOB_NUM_PPI -1 ];struct u64_stats_sync syncp; };
@@ -227,8 +232,6 @@ struct mana_rxcomp_perpkt_info {u32 pkt_hash; };/* HW DATA */ -#define MANA_RXCOMP_OOB_NUM_PPI 4 -/* Receive completion OOB */ struct mana_rxcomp_oob {struct mana_cqe_header cqe_hdr;
@@ -378,7 +381,6 @@ struct mana_ethtool_stats {u64 tx_cqe_err;u64 tx_cqe_unknown_type;u64 tx_linear_pkt_cnt; -u64 rx_coalesced_err;u64 rx_cqe_unknown_type; };
Signature · 1 line
2.34.1
Jakub Kicinski
maintainerRe: [PATCH net-next, 1/2] net: mana: Add support for coalesced RX packets on CQE
In reply to Haiyang Zhangdrivers/net/ethernet/microsoft/mana/mana_ethtool.c static void mana_get_channels(struct net_device *ndev, · line 444
Quoted 2 lines · On Fri, 2 Jan 2026 13:35:57 -0800 Haiyang Zhang wrote:
drivers/net/ethernet/microsoft/mana/mana_ethtool.c +2
-0+NL_SET_ERR_MSG_FMT (extack,"Set rx-frames to %u failed:%d\n" , + ec->rx_max_coalesced_frames, err);
No trailing new line in extack messages, please.
Also please do not duplicate the err value in the message itself, it's already passed to user space. Well behaved user space will format this as eg:
Set rx-frames to 123 failed:-11: Invalid argument
Signature · 1 line
pw-bot: cr
Haiyang Zhang
maintainerRE: [EXTERNAL] Re: [PATCH net-next, 1/2] net: mana: Add support for coalesced RX packets on CQE
Quoted 32 lines
-----Original Message-----
From: Jakub Kicinski <[email protected]>
Sent: Friday, January 2, 2026 7:12 PM
To: Haiyang Zhang <[email protected]>
Cc: [email protected]; [email protected]; KY Srinivasan <[email protected]>; Haiyang Zhang <[email protected]>; Wei Liu <[email protected]>; Dexuan Cui <[email protected]>; Andrew Lunn <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Paolo Abeni <[email protected]>; Long Li <[email protected]>; Konstantin Taranov <[email protected]>; Simon Horman <[email protected]>; Erni Sri Satya Vennela <[email protected]>; Shradha Gupta <[email protected]>; Saurabh Sengar <[email protected]>; Aditya Garg <[email protected]>; Dipayaan Roy <[email protected]>; Shiraz Saleem <[email protected]>; [email protected]; linux- [email protected]; Paul Rosswurm <[email protected]>
Subject: [EXTERNAL] Re: [PATCH net-next, 1/2] net: mana: Add support for coalesced RX packets on CQEdrivers/net/ethernet/microsoft/mana/mana_ethtool.c static void mana_get_channels(struct net_device *ndev, · line 444
Quoted 2 lines · On Fri, 2 Jan 2026 13:35:57 -0800 Haiyang Zhang wrote:
drivers/net/ethernet/microsoft/mana/mana_ethtool.c +2
-0+NL_SET_ERR_MSG_FMT (extack,"Set rx-frames to %u failed:%d\n" , + ec->rx_max_coalesced_frames, err);No trailing new line in extack messages, please.
Also please do not duplicate the err value in the message itself, it's already passed to user space. Well behaved user space will format this as eg:
Quoted 1 line
Set rx-frames to 123 failed:-11: Invalid argument
I will update the patch.
Thanks,
- Haiyang