Skip to content

Commit ff306e9

Browse files
WeiFang-NXPPaolo Abeni
authored andcommitted
net: fec: add fec_rx_error_check() to check RX errors
Extract fec_rx_error_check() from fec_enet_rx_queue(), this helper is used to check RX errors. And it will be used in XDP and XDP zero copy paths in subsequent patches. Signed-off-by: Wei Fang <wei.fang@nxp.com> Reviewed-by: Frank Li <Frank.Li@nxp.com> Link: https://patch.msgid.link/20260205085742.2685134-3-wei.fang@nxp.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent c8d4ad9 commit ff306e9

1 file changed

Lines changed: 36 additions & 22 deletions

File tree

drivers/net/ethernet/freescale/fec_main.c

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,6 +1747,41 @@ static void fec_enet_rx_vlan(const struct net_device *ndev, struct sk_buff *skb)
17471747
}
17481748
}
17491749

1750+
static int fec_rx_error_check(struct net_device *ndev, u16 status)
1751+
{
1752+
if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH | BD_ENET_RX_NO |
1753+
BD_ENET_RX_CR | BD_ENET_RX_OV | BD_ENET_RX_LAST |
1754+
BD_ENET_RX_CL)) {
1755+
ndev->stats.rx_errors++;
1756+
1757+
if (status & BD_ENET_RX_OV) {
1758+
/* FIFO overrun */
1759+
ndev->stats.rx_fifo_errors++;
1760+
return -EIO;
1761+
}
1762+
1763+
if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH |
1764+
BD_ENET_RX_LAST)) {
1765+
/* Frame too long or too short. */
1766+
ndev->stats.rx_length_errors++;
1767+
if ((status & BD_ENET_RX_LAST) && net_ratelimit())
1768+
netdev_err(ndev, "rcv is not +last\n");
1769+
}
1770+
1771+
/* CRC Error */
1772+
if (status & BD_ENET_RX_CR)
1773+
ndev->stats.rx_crc_errors++;
1774+
1775+
/* Report late collisions as a frame error. */
1776+
if (status & (BD_ENET_RX_NO | BD_ENET_RX_CL))
1777+
ndev->stats.rx_frame_errors++;
1778+
1779+
return -EIO;
1780+
}
1781+
1782+
return 0;
1783+
}
1784+
17501785
/* During a receive, the bd_rx.cur points to the current incoming buffer.
17511786
* When we update through the ring, if the next incoming buffer has
17521787
* not been given to the system, we just set the empty indicator,
@@ -1807,29 +1842,8 @@ fec_enet_rx_queue(struct net_device *ndev, u16 queue_id, int budget)
18071842

18081843
/* Check for errors. */
18091844
status ^= BD_ENET_RX_LAST;
1810-
if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH | BD_ENET_RX_NO |
1811-
BD_ENET_RX_CR | BD_ENET_RX_OV | BD_ENET_RX_LAST |
1812-
BD_ENET_RX_CL)) {
1813-
ndev->stats.rx_errors++;
1814-
if (status & BD_ENET_RX_OV) {
1815-
/* FIFO overrun */
1816-
ndev->stats.rx_fifo_errors++;
1817-
goto rx_processing_done;
1818-
}
1819-
if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH
1820-
| BD_ENET_RX_LAST)) {
1821-
/* Frame too long or too short. */
1822-
ndev->stats.rx_length_errors++;
1823-
if (status & BD_ENET_RX_LAST)
1824-
netdev_err(ndev, "rcv is not +last\n");
1825-
}
1826-
if (status & BD_ENET_RX_CR) /* CRC Error */
1827-
ndev->stats.rx_crc_errors++;
1828-
/* Report late collisions as a frame error. */
1829-
if (status & (BD_ENET_RX_NO | BD_ENET_RX_CL))
1830-
ndev->stats.rx_frame_errors++;
1845+
if (unlikely(fec_rx_error_check(ndev, status)))
18311846
goto rx_processing_done;
1832-
}
18331847

18341848
/* Process the incoming frame. */
18351849
ndev->stats.rx_packets++;

0 commit comments

Comments
 (0)