Skip to content

Commit 385d19b

Browse files
WeiFang-NXPPaolo Abeni
authored andcommitted
net: fec: add rx_shift to indicate the extra bytes padded in front of RX frame
The FEC of some platforms supports RX FIFO shift-16, it means the actual frame data starts at bit 16 of the first word read from RX FIFO aligning the Ethernet payload on a 32-bit boundary. The MAC writes two additional bytes in front of each frame received into the RX FIFO. Currently, the fec_enet_rx_queue() updates the data_start, sub_len and the rx_bytes statistics by checking whether FEC_QUIRK_HAS_RACC is set. This makes the code less concise, so rx_shift is added to represent the number of extra bytes padded in front of the RX frame. Furthermore, when adding separate RX handling functions for XDP copy mode and zero copy mode in the future, it will no longer be necessary to check FEC_QUIRK_HAS_RACC to update the corresponding variables. Signed-off-by: Wei Fang <wei.fang@nxp.com> Reviewed-by: Frank Li <Frank.Li@nxp.com> Link: https://patch.msgid.link/20260205085742.2685134-4-wei.fang@nxp.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent ff306e9 commit 385d19b

2 files changed

Lines changed: 9 additions & 13 deletions

File tree

drivers/net/ethernet/freescale/fec.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,7 @@ struct fec_enet_private {
643643
struct pm_qos_request pm_qos_req;
644644

645645
unsigned int tx_align;
646+
unsigned int rx_shift;
646647

647648
/* hw interrupt coalesce */
648649
unsigned int rx_pkts_itr;

drivers/net/ethernet/freescale/fec_main.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,22 +1800,14 @@ fec_enet_rx_queue(struct net_device *ndev, u16 queue_id, int budget)
18001800
struct bufdesc_ex *ebdp = NULL;
18011801
int index = 0;
18021802
bool need_swap = fep->quirks & FEC_QUIRK_SWAP_FRAME;
1803+
u32 data_start = FEC_ENET_XDP_HEADROOM + fep->rx_shift;
18031804
struct bpf_prog *xdp_prog = READ_ONCE(fep->xdp_prog);
18041805
u32 ret, xdp_result = FEC_ENET_XDP_PASS;
1805-
u32 data_start = FEC_ENET_XDP_HEADROOM;
1806+
u32 sub_len = 4 + fep->rx_shift;
18061807
int cpu = smp_processor_id();
18071808
struct xdp_buff xdp;
18081809
struct page *page;
18091810
__fec32 cbd_bufaddr;
1810-
u32 sub_len = 4;
1811-
1812-
/*If it has the FEC_QUIRK_HAS_RACC quirk property, the bit of
1813-
* FEC_RACC_SHIFT16 is set by default in the probe function.
1814-
*/
1815-
if (fep->quirks & FEC_QUIRK_HAS_RACC) {
1816-
data_start += 2;
1817-
sub_len += 2;
1818-
}
18191811

18201812
#if defined(CONFIG_COLDFIRE) && !defined(CONFIG_COLDFIRE_COHERENT_DMA)
18211813
/*
@@ -1848,9 +1840,7 @@ fec_enet_rx_queue(struct net_device *ndev, u16 queue_id, int budget)
18481840
/* Process the incoming frame. */
18491841
ndev->stats.rx_packets++;
18501842
pkt_len = fec16_to_cpu(bdp->cbd_datlen);
1851-
ndev->stats.rx_bytes += pkt_len;
1852-
if (fep->quirks & FEC_QUIRK_HAS_RACC)
1853-
ndev->stats.rx_bytes -= 2;
1843+
ndev->stats.rx_bytes += pkt_len - fep->rx_shift;
18541844

18551845
index = fec_enet_get_bd_index(bdp, &rxq->bd);
18561846
page = rxq->rx_buf[index];
@@ -4603,6 +4593,11 @@ fec_probe(struct platform_device *pdev)
46034593

46044594
ndev->max_mtu = fep->max_buf_size - VLAN_ETH_HLEN - ETH_FCS_LEN;
46054595

4596+
if (fep->quirks & FEC_QUIRK_HAS_RACC)
4597+
fep->rx_shift = 2;
4598+
else
4599+
fep->rx_shift = 0;
4600+
46064601
ret = register_netdev(ndev);
46074602
if (ret)
46084603
goto failed_register;

0 commit comments

Comments
 (0)