net: xilinx: axienet: Derive RX frame length from residue in dmaengine path
PATCH v2 1/1 net: xilinx: axienet: Derive RX frame length from residue in dmaengine path
The dmaengine RX path derived the received frame length from the descriptor APP metadata. That only works when the optional AXI4-Stream status/control interface is present, because the hardware populates the APP fields solely when that interface is enabled. On designs without it the length read back is invalid.
The AXI DMA engine already reports how many bytes it wrote into the buffer through the standard dmaengine residue mechanism. Compute the RX frame length as the posted buffer length minus result->residue, which is independent of the status/control interface and correct across all designs, including multi-descriptor frames where the residue is summed over the chain.
Drop the descriptor metadata lookup, which was only used for this purpose. Detect a failed transfer from dmaengine_result.result instead of the metadata pointer return value, and remove the now unused LEN_APP macro.
The transmit path is unaffected. It still passes APP metadata for checksum offload and derives its length from the skb.
---
Changes in v2:
- Refresh the patch against next-20261120 to address the reported git am failure. No intended change to the RX logic.
base-commit: 909ef7a9a30fa139e69e555e3606680f5cca7726
Apply failure reported in:
https://lore.kernel.org/lkml/[email protected]/
This patch was originally posted as part of the MCDMA series and can be applied independently of the other patches in that series.
https://lore.kernel.org/lkml/[email protected]/
--- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +5 -9
@@ -55,7 +55,6 @@#define TX_BD_NUM_MAX 4096#define RX_BD_NUM_MAX 4096#define DMA_NUM_APP_WORDS 5 -#define LEN_APP 4#define RX_BUF_NUM_DEFAULT 128/* Must be shorter than length of ethtool_drvinfo.driver field to fit */
@@ -1219,30 +1218,27 @@ axienet_start_xmit(struct sk_buff *skb, struct net_device *ndev)static void axienet_dma_rx_cb (void *data,const struct dmaengine_result *result) {struct skbuf_dma_descriptor *skbuf_dma; -size_t meta_len, meta_max_len, rx_len;struct axienet_local *lp = data;struct sk_buff *skb; -u32 *app_metadata; +size_t rx_len;int i; skbuf_dma =axienet_get_rx_desc (lp, lp->rx_ring_tail++); skb = skbuf_dma->skb; - app_metadata =dmaengine_desc_get_metadata_ptr (skbuf_dma->desc, &meta_len, - &meta_max_len);dma_unmap_single (lp->dev, skbuf_dma->dma_address, lp->max_frm_size,DMA_FROM_DEVICE ); skbuf_dma->skb =NULL ; -if (IS_ERR (app_metadata)) { +if (result->result !=DMA_TRANS_NOERROR ) {if (net_ratelimit ()) -netdev_err (lp->ndev,"Failed to get RX metadata pointer\n" ); +netdev_err (lp->ndev,"RX DMA transfer failed\n" );dev_kfree_skb_any (skb); lp->ndev->stats.rx_dropped++; goto rx_submit; } -/* TODO: Derive app word index programmatically */ - rx_len = (app_metadata[LEN_APP ] &0xFFFF ); +/* Actual length = posted buffer length - residue. */ + rx_len = lp->max_frm_size - result->residue;skb_put (skb, rx_len); skb->protocol =eth_type_trans (skb, lp->ndev); skb->ip_summed =CHECKSUM_NONE ;
Signature · 1 line
2.43.0
Quoted 17 lines · Srinivas Neeli
The dmaengine RX path derived the received frame length from the descriptor APP metadata. That only works when the optional AXI4-Stream status/control interface is present, because the hardware populates the APP fields solely when that interface is enabled. On designs without it the length read back is invalid.
The AXI DMA engine already reports how many bytes it wrote into the buffer through the standard dmaengine residue mechanism. Compute the RX frame length as the posted buffer length minus
result->residue, which is independent of the status/control interface and correct across all designs, including multi-descriptor frames where the residue is summed over the chain.Drop the descriptor metadata lookup, which was only used for this purpose. Detect a failed transfer from dmaengine_result.result instead of the metadata pointer return value, and remove the now unused
LEN_APPmacro.
Quoted 5 lines
The transmit path is unaffected. It still passes APP metadata for checksum offload and derives its length from the skb.
Reviewed-by Radhey Shyam Pandey <[email protected]>Signed-off-by Srinivas Neeli <[email protected]>
Thanks!
Suraj
Quoted 64 lines
---
Changes in v2:
- Refresh the patch against next-20261120 to address the reported git am failure. No intended change to the RX logic.
base-commit:909ef7a9a30fa139e69e555e3606680f5cca7726Apply failure reported in:
https://lore.kernel.org/lkml/[email protected]/This patch was originally posted as part of the MCDMA series and can be applied independently of the other patches in that series.
https://lore.kernel.org/lkml/[email protected]/--- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)drivers/net/ethernet/xilinx/xilinx_axienet_main.c +5
-9@@ -55,7 +55,6 @@#define TX_BD_NUM_MAX 4096#define RX_BD_NUM_MAX 4096#define DMA_NUM_APP_WORDS 5 -#define LEN_APP 4#define RX_BUF_NUM_DEFAULT 128/* Must be shorter than length of ethtool_drvinfo.driver field to fit */ @@ -1219,30 +1218,27 @@ axienet_start_xmit(struct sk_buff *skb, struct net_device *ndev)static void axienet_dma_rx_cb (void *data,const struct dmaengine_result *result) {struct skbuf_dma_descriptor *skbuf_dma; -size_t meta_len, meta_max_len, rx_len;struct axienet_local *lp = data;struct sk_buff *skb; -u32 *app_metadata; +size_t rx_len;int i; skbuf_dma =axienet_get_rx_desc (lp, lp->rx_ring_tail++); skb = skbuf_dma->skb; - app_metadata =dmaengine_desc_get_metadata_ptr (skbuf_dma->desc, &meta_len, - &meta_max_len);dma_unmap_single (lp->dev, skbuf_dma->dma_address, lp->max_frm_size,DMA_FROM_DEVICE ); skbuf_dma->skb =NULL ; -if (IS_ERR (app_metadata)) { +if (result->result !=DMA_TRANS_NOERROR ) {if (net_ratelimit ()) -netdev_err (lp->ndev,"Failed to get RX metadata pointer\n" ); +netdev_err (lp->ndev,"RX DMA transfer failed\n" );dev_kfree_skb_any (skb); lp->ndev->stats.rx_dropped++; goto rx_submit; } -/* TODO: Derive app word index programmatically */ - rx_len = (app_metadata[LEN_APP ] &0xFFFF ); +/* Actual length = posted buffer length - residue. */ + rx_len = lp->max_frm_size - result->residue;skb_put (skb, rx_len); skb->protocol =eth_type_trans (skb, lp->ndev); skb->ip_summed =CHECKSUM_NONE ;