xref: /linux/drivers/net/ethernet/huawei/hinic3/hinic3_netdev_ops.c (revision ab93e0dd72c37d378dd936f031ffb83ff2bd87ce)
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
3 
4 #include <linux/etherdevice.h>
5 #include <linux/netdevice.h>
6 
7 #include "hinic3_hwif.h"
8 #include "hinic3_nic_cfg.h"
9 #include "hinic3_nic_dev.h"
10 #include "hinic3_nic_io.h"
11 #include "hinic3_rx.h"
12 #include "hinic3_tx.h"
13 
14 static int hinic3_open(struct net_device *netdev)
15 {
16 	/* Completed by later submission due to LoC limit. */
17 	return -EFAULT;
18 }
19 
20 static int hinic3_close(struct net_device *netdev)
21 {
22 	/* Completed by later submission due to LoC limit. */
23 	return -EFAULT;
24 }
25 
26 static int hinic3_change_mtu(struct net_device *netdev, int new_mtu)
27 {
28 	int err;
29 
30 	err = hinic3_set_port_mtu(netdev, new_mtu);
31 	if (err) {
32 		netdev_err(netdev, "Failed to change port mtu to %d\n",
33 			   new_mtu);
34 		return err;
35 	}
36 
37 	netdev_dbg(netdev, "Change mtu from %u to %d\n", netdev->mtu, new_mtu);
38 	WRITE_ONCE(netdev->mtu, new_mtu);
39 
40 	return 0;
41 }
42 
43 static int hinic3_set_mac_addr(struct net_device *netdev, void *addr)
44 {
45 	struct hinic3_nic_dev *nic_dev = netdev_priv(netdev);
46 	struct sockaddr *saddr = addr;
47 	int err;
48 
49 	if (!is_valid_ether_addr(saddr->sa_data))
50 		return -EADDRNOTAVAIL;
51 
52 	if (ether_addr_equal(netdev->dev_addr, saddr->sa_data))
53 		return 0;
54 
55 	err = hinic3_update_mac(nic_dev->hwdev, netdev->dev_addr,
56 				saddr->sa_data, 0,
57 				hinic3_global_func_id(nic_dev->hwdev));
58 
59 	if (err)
60 		return err;
61 
62 	eth_hw_addr_set(netdev, saddr->sa_data);
63 
64 	return 0;
65 }
66 
67 static const struct net_device_ops hinic3_netdev_ops = {
68 	.ndo_open             = hinic3_open,
69 	.ndo_stop             = hinic3_close,
70 	.ndo_change_mtu       = hinic3_change_mtu,
71 	.ndo_set_mac_address  = hinic3_set_mac_addr,
72 	.ndo_start_xmit       = hinic3_xmit_frame,
73 };
74 
75 void hinic3_set_netdev_ops(struct net_device *netdev)
76 {
77 	netdev->netdev_ops = &hinic3_netdev_ops;
78 }
79