mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-04-02 09:21:19 -04:00
net: fec: add change_mtu to support dynamic buffer allocation
Add a fec_change_mtu() handler to recalculate the pagepool_order based on the new_mtu value. And update the rx_frame_size accordingly when pagepool_order changes. MTU changes are only allowed when the adater is not running. Reviewed-by: Wei Fang <wei.fang@nxp.com> Signed-off-by: Shenwei Wang <shenwei.wang@nxp.com> Link: https://patch.msgid.link/20250910185211.721341-6-shenwei.wang@nxp.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
committed by
Jakub Kicinski
parent
5b14ed3ac5
commit
59e9bf037d
@@ -348,10 +348,11 @@ struct bufdesc_ex {
|
||||
* the skbuffer directly.
|
||||
*/
|
||||
|
||||
#define FEC_DRV_RESERVE_SPACE (XDP_PACKET_HEADROOM + \
|
||||
SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
|
||||
#define FEC_ENET_XDP_HEADROOM (XDP_PACKET_HEADROOM)
|
||||
#define FEC_ENET_RX_PAGES 256
|
||||
#define FEC_ENET_RX_FRSIZE (PAGE_SIZE - FEC_ENET_XDP_HEADROOM \
|
||||
- SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
|
||||
#define FEC_ENET_RX_FRSIZE (PAGE_SIZE - FEC_DRV_RESERVE_SPACE)
|
||||
#define FEC_ENET_RX_FRPPG (PAGE_SIZE / FEC_ENET_RX_FRSIZE)
|
||||
#define RX_RING_SIZE (FEC_ENET_RX_FRPPG * FEC_ENET_RX_PAGES)
|
||||
#define FEC_ENET_TX_FRSIZE 2048
|
||||
|
||||
@@ -470,14 +470,14 @@ fec_enet_create_page_pool(struct fec_enet_private *fep,
|
||||
{
|
||||
struct bpf_prog *xdp_prog = READ_ONCE(fep->xdp_prog);
|
||||
struct page_pool_params pp_params = {
|
||||
.order = 0,
|
||||
.order = fep->pagepool_order,
|
||||
.flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV,
|
||||
.pool_size = size,
|
||||
.nid = dev_to_node(&fep->pdev->dev),
|
||||
.dev = &fep->pdev->dev,
|
||||
.dma_dir = xdp_prog ? DMA_BIDIRECTIONAL : DMA_FROM_DEVICE,
|
||||
.offset = FEC_ENET_XDP_HEADROOM,
|
||||
.max_len = FEC_ENET_RX_FRSIZE,
|
||||
.max_len = fep->rx_frame_size,
|
||||
};
|
||||
int err;
|
||||
|
||||
@@ -4025,6 +4025,23 @@ static int fec_hwtstamp_set(struct net_device *ndev,
|
||||
return fec_ptp_set(ndev, config, extack);
|
||||
}
|
||||
|
||||
static int fec_change_mtu(struct net_device *ndev, int new_mtu)
|
||||
{
|
||||
struct fec_enet_private *fep = netdev_priv(ndev);
|
||||
int order;
|
||||
|
||||
if (netif_running(ndev))
|
||||
return -EBUSY;
|
||||
|
||||
order = get_order(new_mtu + ETH_HLEN + ETH_FCS_LEN
|
||||
+ FEC_DRV_RESERVE_SPACE);
|
||||
fep->rx_frame_size = (PAGE_SIZE << order) - FEC_DRV_RESERVE_SPACE;
|
||||
fep->pagepool_order = order;
|
||||
WRITE_ONCE(ndev->mtu, new_mtu);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct net_device_ops fec_netdev_ops = {
|
||||
.ndo_open = fec_enet_open,
|
||||
.ndo_stop = fec_enet_close,
|
||||
@@ -4034,6 +4051,7 @@ static const struct net_device_ops fec_netdev_ops = {
|
||||
.ndo_validate_addr = eth_validate_addr,
|
||||
.ndo_tx_timeout = fec_timeout,
|
||||
.ndo_set_mac_address = fec_set_mac_address,
|
||||
.ndo_change_mtu = fec_change_mtu,
|
||||
.ndo_eth_ioctl = phy_do_ioctl_running,
|
||||
.ndo_set_features = fec_set_features,
|
||||
.ndo_bpf = fec_enet_bpf,
|
||||
|
||||
Reference in New Issue
Block a user