Zephyr API Documentation 4.2.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
dsa_core.h
Go to the documentation of this file.
1/*
2 * Copyright 2025 NXP
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
9
10#ifndef ZEPHYR_INCLUDE_NET_DSA_CORE_H_
11#define ZEPHYR_INCLUDE_NET_DSA_CORE_H_
12
13#include <errno.h>
14#include <zephyr/device.h>
15#include <zephyr/devicetree.h>
16#include <zephyr/net/net_if.h>
17#include <zephyr/net/phy.h>
18#include <zephyr/net/ethernet.h>
19
28
30
31#if defined(CONFIG_DSA_PORT_MAX_COUNT)
32#define DSA_PORT_MAX_COUNT CONFIG_DSA_PORT_MAX_COUNT
33#else
34#define DSA_PORT_MAX_COUNT 0
35#endif
36
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
50#define DSA_PORT_INST_INIT(port, n, cfg) \
51 NET_DEVICE_INIT_INSTANCE(CONCAT(dsa_, n, port), DEVICE_DT_NAME(port), DT_REG_ADDR(port), \
52 dsa_port_initialize, NULL, &dsa_switch_context_##n, cfg, \
53 CONFIG_ETH_INIT_PRIORITY, &dsa_eth_api, ETHERNET_L2, \
54 NET_L2_GET_CTX_TYPE(ETHERNET_L2), NET_ETH_MTU);
55
64#define DSA_SWITCH_INST_INIT(n, _dapi, data, fn) \
65 struct dsa_switch_context dsa_switch_context_##n = { \
66 .dapi = _dapi, \
67 .prv_data = data, \
68 .init_ports = 0, \
69 .num_ports = DT_INST_CHILD_NUM_STATUS_OKAY(n), \
70 }; \
71 DT_INST_FOREACH_CHILD_STATUS_OKAY_VARGS(n, fn, n);
72
76 struct net_if *iface_user[DSA_PORT_MAX_COUNT];
77
80
82 struct dsa_api *dapi;
83
85 void *prv_data;
86
89
92
95};
96
101struct dsa_api {
103
105 struct net_if *(*recv)(struct net_if *iface, struct net_pkt *pkt);
106
108 struct net_pkt *(*xmit)(struct net_if *iface, struct net_pkt *pkt);
109
111 int (*port_init)(const struct device *dev);
112
114 void (*port_phylink_change)(const struct device *dev, struct phy_link_state *state,
115 void *user_data);
116
119
120#if defined(CONFIG_NET_L2_PTP) || defined(__DOXYGEN__)
125 int (*port_txtstamp)(const struct device *dev, struct net_pkt *pkt);
126#endif
128 int (*switch_setup)(const struct dsa_switch_context *dsa_switch_ctx);
129
131 int (*connect_tag_protocol)(struct dsa_switch_context *dsa_switch_ctx, int tag_proto);
132
134 enum ethernet_hw_caps (*get_capabilities)(const struct device *dev);
135
137 int (*set_config)(const struct device *dev,
138 enum ethernet_config_type type,
139 const struct ethernet_config *config);
140
142 int (*get_config)(const struct device *dev,
143 enum ethernet_config_type type,
144 struct ethernet_config *config);
145};
146
156 const int port_idx;
158 const struct device *phy_dev;
160 const char *phy_mode;
162 const int tag_proto;
165#if defined(CONFIG_NET_L2_PTP) || defined(__DOXYGEN__)
170 const struct device *ptp_clock;
171#endif
174};
175
177
178/*
179 * DSA port init
180 *
181 * Returns:
182 * - 0 if ok, < 0 if error
183 */
184int dsa_port_initialize(const struct device *dev);
185
186/*
187 * DSA transmit function
188 *
189 * param dev: Port device to transmit
190 * param pkt: Network packet
191 *
192 * Returns:
193 * - 0 if ok, < 0 if error
194 */
195int dsa_xmit(const struct device *dev, struct net_pkt *pkt);
196
197/*
198 * DSA receive function
199 *
200 * param iface: Interface of conduit port
201 * param pkt: Network packet
202 *
203 * Returns:
204 * - Interface to redirect
205 */
206struct net_if *dsa_recv(struct net_if *iface, struct net_pkt *pkt);
207
208/*
209 * DSA ethernet init function to handle flags
210 *
211 * param iface: Interface of port
212 *
213 * Returns:
214 * - 0 if ok, < 0 if error
215 */
216int dsa_eth_init(struct net_if *iface);
217
218/* Ethernet APIs definition for switch ports */
219extern const struct ethernet_api dsa_eth_api;
220
222
232struct net_if *dsa_user_get_iface(struct net_if *iface, int port_idx);
233
234#ifdef __cplusplus
235}
236#endif
237
241#endif /* ZEPHYR_INCLUDE_NET_DSA_CORE_H_ */
Devicetree main header.
System error numbers.
Ethernet.
struct net_if * dsa_user_get_iface(struct net_if *iface, int port_idx)
Get network interface of a user port.
ethernet_hw_caps
Ethernet hardware capabilities.
Definition ethernet.h:146
Public API for network interface.
state
Definition parser_state.h:29
Public APIs for Ethernet PHY drivers.
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
Runtime device structure (in ROM) per driver instance.
Definition device.h:510
Structure to provide DSA switch api callbacks - it is an augmented struct ethernet_api.
Definition dsa_core.h:101
void(* port_phylink_change)(const struct device *dev, struct phy_link_state *state, void *user_data)
Port link change.
Definition dsa_core.h:114
int(* get_config)(const struct device *dev, enum ethernet_config_type type, struct ethernet_config *config)
Get hardware specific configuration.
Definition dsa_core.h:142
int(* switch_setup)(const struct dsa_switch_context *dsa_switch_ctx)
Switch setup.
Definition dsa_core.h:128
void(* port_generate_random_mac)(uint8_t *mac_addr)
Port generates random mac address.
Definition dsa_core.h:118
int(* port_init)(const struct device *dev)
Port init.
Definition dsa_core.h:111
enum ethernet_hw_caps(* get_capabilities)(const struct device *dev)
Get the device capabilities.
Definition dsa_core.h:134
int(* connect_tag_protocol)(struct dsa_switch_context *dsa_switch_ctx, int tag_proto)
Connect the switch to the tag protocol.
Definition dsa_core.h:131
int(* port_txtstamp)(const struct device *dev, struct net_pkt *pkt)
Port TX timestamp handling.
Definition dsa_core.h:125
int(* set_config)(const struct device *dev, enum ethernet_config_type type, const struct ethernet_config *config)
Set specific hardware configuration.
Definition dsa_core.h:137
Structure of DSA port configuration.
Definition dsa_core.h:150
const bool use_random_mac_addr
Use random mac address or not.
Definition dsa_core.h:154
const struct device * ptp_clock
PTP clock used on the port.
Definition dsa_core.h:170
void * prv_config
Instance specific config.
Definition dsa_core.h:173
const int port_idx
Port index.
Definition dsa_core.h:156
const int tag_proto
Tag protocol.
Definition dsa_core.h:162
const char * phy_mode
PHY mode.
Definition dsa_core.h:160
uint8_t mac_addr[6]
Port mac address.
Definition dsa_core.h:152
const struct device * ethernet_connection
Ethernet device connected to the port.
Definition dsa_core.h:164
const struct device * phy_dev
PHY device.
Definition dsa_core.h:158
DSA switch context data.
Definition dsa_core.h:74
void * tagger_data
DSA tagger data provided by instance when connecting to tag protocol.
Definition dsa_core.h:94
void * prv_data
Instance specific data.
Definition dsa_core.h:85
struct net_if * iface_conduit
Pointer to DSA conduit network interface.
Definition dsa_core.h:79
struct dsa_api * dapi
DSA specific API callbacks.
Definition dsa_core.h:82
uint8_t init_ports
Number of initialized ports in the DSA switch.
Definition dsa_core.h:91
struct net_if * iface_user[DSA_PORT_MAX_COUNT]
Pointers to all DSA user network interfaces.
Definition dsa_core.h:76
uint8_t num_ports
Number of ports in the DSA switch.
Definition dsa_core.h:88
Ethernet L2 API operations.
Definition ethernet.h:532
Network Interface structure.
Definition net_if.h:726
Network packet.
Definition net_pkt.h:91