Skip to content

Commit 54a6e86

Browse files
WeiFang-NXPPaolo Abeni
authored andcommitted
net: fec: add fec_build_skb() to build a skb
Extract the helper fec_build_skb() from fec_enet_rx_queue(), so that the code for building a skb is centralized in fec_build_skb(), which makes the code of fec_enet_rx_queue() more concise and readable. Signed-off-by: Wei Fang <wei.fang@nxp.com> Reviewed-by: Frank Li <Frank.Li@nxp.com> Link: https://patch.msgid.link/20260205085742.2685134-5-wei.fang@nxp.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent 385d19b commit 54a6e86

1 file changed

Lines changed: 60 additions & 46 deletions

File tree

drivers/net/ethernet/freescale/fec_main.c

Lines changed: 60 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,6 +1782,59 @@ static int fec_rx_error_check(struct net_device *ndev, u16 status)
17821782
return 0;
17831783
}
17841784

1785+
static struct sk_buff *fec_build_skb(struct fec_enet_private *fep,
1786+
struct fec_enet_priv_rx_q *rxq,
1787+
struct bufdesc *bdp,
1788+
struct page *page, u32 len)
1789+
{
1790+
struct net_device *ndev = fep->netdev;
1791+
struct bufdesc_ex *ebdp;
1792+
struct sk_buff *skb;
1793+
1794+
skb = build_skb(page_address(page),
1795+
PAGE_SIZE << fep->pagepool_order);
1796+
if (unlikely(!skb)) {
1797+
page_pool_recycle_direct(rxq->page_pool, page);
1798+
ndev->stats.rx_dropped++;
1799+
if (net_ratelimit())
1800+
netdev_err(ndev, "build_skb failed\n");
1801+
1802+
return NULL;
1803+
}
1804+
1805+
skb_reserve(skb, FEC_ENET_XDP_HEADROOM + fep->rx_shift);
1806+
skb_put(skb, len);
1807+
skb_mark_for_recycle(skb);
1808+
1809+
/* Get offloads from the enhanced buffer descriptor */
1810+
if (fep->bufdesc_ex) {
1811+
ebdp = (struct bufdesc_ex *)bdp;
1812+
1813+
/* If this is a VLAN packet remove the VLAN Tag */
1814+
if (ebdp->cbd_esc & cpu_to_fec32(BD_ENET_RX_VLAN))
1815+
fec_enet_rx_vlan(ndev, skb);
1816+
1817+
/* Get receive timestamp from the skb */
1818+
if (fep->hwts_rx_en)
1819+
fec_enet_hwtstamp(fep, fec32_to_cpu(ebdp->ts),
1820+
skb_hwtstamps(skb));
1821+
1822+
if (fep->csum_flags & FLAG_RX_CSUM_ENABLED) {
1823+
if (!(ebdp->cbd_esc &
1824+
cpu_to_fec32(FLAG_RX_CSUM_ERROR)))
1825+
/* don't check it */
1826+
skb->ip_summed = CHECKSUM_UNNECESSARY;
1827+
else
1828+
skb_checksum_none_assert(skb);
1829+
}
1830+
}
1831+
1832+
skb->protocol = eth_type_trans(skb, ndev);
1833+
skb_record_rx_queue(skb, rxq->bd.qid);
1834+
1835+
return skb;
1836+
}
1837+
17851838
/* During a receive, the bd_rx.cur points to the current incoming buffer.
17861839
* When we update through the ring, if the next incoming buffer has
17871840
* not been given to the system, we just set the empty indicator,
@@ -1797,7 +1850,6 @@ fec_enet_rx_queue(struct net_device *ndev, u16 queue_id, int budget)
17971850
struct sk_buff *skb;
17981851
ushort pkt_len;
17991852
int pkt_received = 0;
1800-
struct bufdesc_ex *ebdp = NULL;
18011853
int index = 0;
18021854
bool need_swap = fep->quirks & FEC_QUIRK_SWAP_FRAME;
18031855
u32 data_start = FEC_ENET_XDP_HEADROOM + fep->rx_shift;
@@ -1867,59 +1919,21 @@ fec_enet_rx_queue(struct net_device *ndev, u16 queue_id, int budget)
18671919
goto rx_processing_done;
18681920
}
18691921

1870-
/* The packet length includes FCS, but we don't want to
1871-
* include that when passing upstream as it messes up
1872-
* bridging applications.
1873-
*/
1874-
skb = build_skb(page_address(page),
1875-
PAGE_SIZE << fep->pagepool_order);
1876-
if (unlikely(!skb)) {
1877-
page_pool_recycle_direct(rxq->page_pool, page);
1878-
ndev->stats.rx_dropped++;
1879-
1880-
netdev_err_once(ndev, "build_skb failed!\n");
1881-
goto rx_processing_done;
1882-
}
1883-
1884-
skb_reserve(skb, data_start);
1885-
skb_put(skb, pkt_len - sub_len);
1886-
skb_mark_for_recycle(skb);
1887-
18881922
if (unlikely(need_swap)) {
18891923
u8 *data;
18901924

18911925
data = page_address(page) + FEC_ENET_XDP_HEADROOM;
18921926
swap_buffer(data, pkt_len);
18931927
}
18941928

1895-
/* Extract the enhanced buffer descriptor */
1896-
ebdp = NULL;
1897-
if (fep->bufdesc_ex)
1898-
ebdp = (struct bufdesc_ex *)bdp;
1899-
1900-
/* If this is a VLAN packet remove the VLAN Tag */
1901-
if (fep->bufdesc_ex &&
1902-
(ebdp->cbd_esc & cpu_to_fec32(BD_ENET_RX_VLAN)))
1903-
fec_enet_rx_vlan(ndev, skb);
1904-
1905-
skb->protocol = eth_type_trans(skb, ndev);
1906-
1907-
/* Get receive timestamp from the skb */
1908-
if (fep->hwts_rx_en && fep->bufdesc_ex)
1909-
fec_enet_hwtstamp(fep, fec32_to_cpu(ebdp->ts),
1910-
skb_hwtstamps(skb));
1911-
1912-
if (fep->bufdesc_ex &&
1913-
(fep->csum_flags & FLAG_RX_CSUM_ENABLED)) {
1914-
if (!(ebdp->cbd_esc & cpu_to_fec32(FLAG_RX_CSUM_ERROR))) {
1915-
/* don't check it */
1916-
skb->ip_summed = CHECKSUM_UNNECESSARY;
1917-
} else {
1918-
skb_checksum_none_assert(skb);
1919-
}
1920-
}
1929+
/* The packet length includes FCS, but we don't want to
1930+
* include that when passing upstream as it messes up
1931+
* bridging applications.
1932+
*/
1933+
skb = fec_build_skb(fep, rxq, bdp, page, pkt_len - sub_len);
1934+
if (!skb)
1935+
goto rx_processing_done;
19211936

1922-
skb_record_rx_queue(skb, queue_id);
19231937
napi_gro_receive(&fep->napi, skb);
19241938

19251939
rx_processing_done:

0 commit comments

Comments
 (0)