1 /*
2  * Copyright (c) 2024 TOKITA Hiroshi
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /*
8  * This is not a real ethenet driver. It is used to instantiate struct
9  * devices for the "vnd,ethernet" devicetree compatible used in test code.
10  */
11 
12 #include <zephyr/net/ethernet.h>
13 
14 #define DT_DRV_COMPAT vnd_ethernet
15 
16 #if defined(CONFIG_NET_STATISTICS_ETHERNET)
17 struct net_stats_eth *vnd_ethernet_get_stats(const struct device *dev);
18 {
19 	ARG_UNUSED(dev);
20 
21 	return NULL;
22 }
23 
24 #endif
vnd_ethernet_start(const struct device * dev)25 int vnd_ethernet_start(const struct device *dev)
26 {
27 	ARG_UNUSED(dev);
28 
29 	return -ENOTSUP;
30 }
31 
vnd_ethernet_stop(const struct device * dev)32 int vnd_ethernet_stop(const struct device *dev)
33 {
34 	ARG_UNUSED(dev);
35 
36 	return -ENOTSUP;
37 }
38 
vnd_ethernet_get_capabilities(const struct device * dev)39 enum ethernet_hw_caps vnd_ethernet_get_capabilities(const struct device *dev)
40 {
41 	ARG_UNUSED(dev);
42 
43 	return 0;
44 }
45 
vnd_ethernet_set_config(const struct device * dev,enum ethernet_config_type type,const struct ethernet_config * config)46 int vnd_ethernet_set_config(const struct device *dev, enum ethernet_config_type type,
47 			    const struct ethernet_config *config)
48 {
49 	ARG_UNUSED(dev);
50 	ARG_UNUSED(type);
51 	ARG_UNUSED(config);
52 
53 	return -ENOTSUP;
54 }
55 
vnd_ethernet_get_config(const struct device * dev,enum ethernet_config_type type,struct ethernet_config * config)56 int vnd_ethernet_get_config(const struct device *dev, enum ethernet_config_type type,
57 			    struct ethernet_config *config)
58 {
59 	ARG_UNUSED(dev);
60 	ARG_UNUSED(type);
61 	ARG_UNUSED(config);
62 
63 	return -ENOTSUP;
64 }
65 
66 #if defined(CONFIG_NET_VLAN)
vnd_ethernet_vlan_setup(const struct device * dev,struct net_if * iface,uint16_t tag,bool enable)67 int vnd_ethernet_vlan_setup(const struct device *dev, struct net_if *iface, uint16_t tag,
68 			    bool enable)
69 {
70 	ARG_UNUSED(dev);
71 	ARG_UNUSED(iface);
72 	ARG_UNUSED(tag);
73 	ARG_UNUSED(enable);
74 
75 	return -ENOTSUP;
76 }
77 
78 #endif /* CONFIG_NET_VLAN */
79 
80 #if defined(CONFIG_PTP_CLOCK)
vnd_ethernet_get_ptp_clock(const struct device * dev)81 const struct device *vnd_ethernet_get_ptp_clock(const struct device *dev)
82 {
83 	ARG_UNUSED(dev);
84 
85 	return NULL;
86 }
87 
88 #endif /* CONFIG_PTP_CLOCK */
vnd_ethernet_get_phy(const struct device * dev)89 const struct device *vnd_ethernet_get_phy(const struct device *dev)
90 {
91 	ARG_UNUSED(dev);
92 
93 	return NULL;
94 }
95 
vnd_ethernet_send(const struct device * dev,struct net_pkt * pkt)96 int vnd_ethernet_send(const struct device *dev, struct net_pkt *pkt)
97 {
98 	ARG_UNUSED(dev);
99 	ARG_UNUSED(pkt);
100 
101 	return -ENOTSUP;
102 }
103 
vnd_ethernet_init(struct net_if * iface)104 void vnd_ethernet_init(struct net_if *iface)
105 {
106 	ARG_UNUSED(iface);
107 }
108 
109 struct ethernet_api vnd_ethernet_api = {
110 	.iface_api.init = vnd_ethernet_init,
111 #if defined(CONFIG_NET_STATISTICS_ETHERNET)
112 	.get_stats = vnd_ethernet_get_stats,
113 #endif
114 	.start = vnd_ethernet_start,
115 	.stop = vnd_ethernet_stop,
116 	.get_capabilities = vnd_ethernet_get_capabilities,
117 	.set_config = vnd_ethernet_set_config,
118 	.get_config = vnd_ethernet_get_config,
119 #if defined(CONFIG_NET_VLAN)
120 	.vlan_setup = vnd_ethernet_vlan_setup,
121 #endif /* CONFIG_NET_VLAN */
122 
123 #if defined(CONFIG_PTP_CLOCK)
124 	.get_ptp_clock = vnd_ethernet_get_ptp_clock,
125 #endif /* CONFIG_PTP_CLOCK */
126 	.get_phy = vnd_ethernet_get_phy,
127 	.send = vnd_ethernet_send,
128 };
129 
130 #define VND_ETHERNET_INIT(n)                                                                       \
131 	DEVICE_DT_INST_DEFINE(n, NULL, NULL, NULL, NULL, POST_KERNEL, CONFIG_ETH_INIT_PRIORITY,    \
132 			      &vnd_ethernet_api);
133 
134 DT_INST_FOREACH_STATUS_OKAY(VND_ETHERNET_INIT)
135