RE: [PATCH v2 net-next 4/5] net: fec: add change_mtu to support dynamic buffer allocation
From: Shenwei Wang
Date: Mon Aug 25 2025 - 08:35:31 EST
> -----Original Message-----
> From: Wei Fang <wei.fang@xxxxxxx>
> Sent: Sunday, August 24, 2025 9:13 PM
> To: Shenwei Wang <shenwei.wang@xxxxxxx>
> Cc: Clark Wang <xiaoning.wang@xxxxxxx>; Stanislav Fomichev
> <sdf@xxxxxxxxxxx>; imx@xxxxxxxxxxxxxxx; netdev@xxxxxxxxxxxxxxx; linux-
> kernel@xxxxxxxxxxxxxxx; dl-linux-imx <linux-imx@xxxxxxx>; Andrew Lunn
> <andrew+netdev@xxxxxxx>; David S. Miller <davem@xxxxxxxxxxxxx>; Eric
> Dumazet <edumazet@xxxxxxxxxx>; Jakub Kicinski <kuba@xxxxxxxxxx>; Paolo
> Abeni <pabeni@xxxxxxxxxx>; Alexei Starovoitov <ast@xxxxxxxxxx>; Daniel
> Borkmann <daniel@xxxxxxxxxxxxx>; Jesper Dangaard Brouer
> <hawk@xxxxxxxxxx>; John Fastabend <john.fastabend@xxxxxxxxx>
> Subject: RE: [PATCH v2 net-next 4/5] net: fec: add change_mtu to support
> dynamic buffer allocation
>
> > > > +static int fec_change_mtu(struct net_device *ndev, int new_mtu) {
> > > > + struct fec_enet_private *fep = netdev_priv(ndev);
> > > > + int order, done;
> > > > + bool running;
> > > > +
> > > > + order = get_order(new_mtu + ETH_HLEN + ETH_FCS_LEN);
> > > > + if (fep->pagepool_order == order) {
> > > > + WRITE_ONCE(ndev->mtu, new_mtu);
> > > > + return 0;
> > > > + }
> > > > +
> > > > + fep->pagepool_order = order;
> > > > + fep->rx_frame_size = (PAGE_SIZE << order) -
> > > FEC_ENET_XDP_HEADROOM
> > > > + - SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
> > > > +
> > >
> > > I think we need to add a check for rx_frame_size, as
> > > FEC_R_CNTRL[MAX_FL]
> > and
> > > FEC_FTRL[TRUNC_FL] only have 14 bits.
> >
> > That would be redundant, since rx_frame_size cannot exceed
> > max_buf_size which value would either be PKT_MAXBUF_SIZE or
> > MAX_JUMBO_BUF_SIZE.
> >
>
> Looked at the entire patch set, the rx_frame_size is set to FEC_FTRL[TRUNC_FL]
> and FEC_R_CNTRL[MAX_FL], and both TRUNC_FL and MAX_FL are 14 bits, if the
> value set exceeds the hardware capability, the driver should return an error.
>
> For example, the order is 3, so rx_frame_size is 0x7dc0, but MAX_FL will be set to
> 0x3dc0, that is not correct.
How can you get the order of 3? If the PAGE_SIZE is 4k, the order is no greater than 2.
Regards,
Shenwei