On 11/29/2026 1:49 AM, Andrew Lunn wrote:
>> +static void xsc_eth_build_nic_params(struct xsc_adapter *adapter)
>> +{
>> + struct xsc_eth_params *params = &adapter->nic_param;
>> +
>> + params->mtu = SW_DEFAULT_MTU;
>> +}
>> +static int xsc_eth_set_hw_mtu(struct xsc_core_device *xdev,
>> + u16 mtu, u16 rx_buf_sz)
>> +{
>> + struct xsc_set_mtu_mbox_out out;
>> + struct xsc_set_mtu_mbox_in in;
>> + int err;
>> +
>> + memset(&in, 0, sizeof(struct xsc_set_mtu_mbox_in));
>> + memset(&out, 0, sizeof(struct xsc_set_mtu_mbox_out));
>> +
>> + in.hdr.opcode = cpu_to_be16(XSC_CMD_OP_SET_MTU);
>> + in.mtu = cpu_to_be16(mtu);
>> + in.rx_buf_sz_min = cpu_to_be16(rx_buf_sz);
>> + in.mac_port = xdev->mac_port;
>> +
>> + err = xsc_cmd_exec(xdev, &in, sizeof(struct xsc_set_mtu_mbox_in), &out,
>> + sizeof(struct xsc_set_mtu_mbox_out));
>> + if (err) {
>> + netdev_err(xsc_dev_to_netdev(xdev),
>> + "failed to set hw_mtu=%u rx_buf_sz=%u, err=%d, status=%d\n",
>> + mtu, rx_buf_sz, err, out.hdr.status);
>> + return err;
>> + }
>> +
>> + return 0;
>> +}
>> +static void xsc_eth_build_nic_netdev(struct xsc_adapter *adapter)
>> +{
>> + struct net_device *netdev = adapter->netdev;
>> +
>> + netdev->netdev_ops = &xsc_netdev_ops;
>> +
>> + netdev->min_mtu = SW_DEFAULT_MTU;
>> + netdev->max_mtu = SW_DEFAULT_MTU;
>> + netdev->mtu = SW_DEFAULT_MTU;
> If the MTU is fixed, it seems pointless having xsc_eth_set_hw_mtu().
I'd like to keep xsc_eth_set_hw_mtu(). Fixed MTU just means the netdev
MTU isn't user-changeable; the function sends a SET_MTU firmware command
that programs the port's frame length and RX buffer size into the
hardware,
which has to happen at probe either way.
>> +++ b/drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth.h
>> @@ -0,0 +1,33 @@
>> +/* SPDX-License-Identifier: GPL-2.0 */
>> +/* Copyright (C) 2021-2026, Shanghai Yunsilicon Technology Co., Ltd.
>> + * All rights reserved.
>> + */
>> +
>> +#ifndef __XSC_ETH_H
>> +#define __XSC_ETH_H
>> +
>> +#include <linux/udp.h>
> Why this header? How is UDP special?
Will remove the unused <linux/udp.h> include.
>
>> +#define SW_DEFAULT_MTU ETH_DATA_LEN
> Please don't alias well known #defines. I know what ETH_DATA_LEN is,
> fixing the MTU to that makes sense. But i had not idea what
> SW_DEFAULT_MTU was until i got here. So you are just obfuscating the
> code.
Right, I'll drop the SW_DEFAULT_MTU alias and use ETH_DATA_LEN directly.
>> +#define XSC_ETH_HW_MTU_SEND 9800
>> +#define XSC_ETH_HARD_MTU (ETH_HLEN + VLAN_HLEN * 2 + ETH_FCS_LEN)
> The code would be a lot more readable if you used these in the actual
> code, rather than hide them here. I can see this and see you need
> space for the ethernet header, up to two VLAN headers and the trailing
> CRC. XSC_ETH_HARD_MTU tells me nothing.
>
> Andrew
Agreed, XSC_ETH_HARD_MTU is not a descriptive name. I will drop
XSC_ETH_HARD_MTU and write the length calculation where it is used:
#define XSC_SW2HW_MTU(mtu) ((mtu) + ETH_HLEN + 2 * VLAN_HLEN +
ETH_FCS_LEN)
Thanks,
Xin