Zephyr Project API 4.4.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 ETH_NET_DEVICE_DT_DEFINE(port, dsa_port_initialize, NULL, &dsa_switch_context_##n, cfg, \
52 CONFIG_ETH_INIT_PRIORITY, &dsa_eth_api, NET_ETH_MTU)
53
61#define DSA_SWITCH_INST_INIT(n, _dapi, data, fn) \
62 struct dsa_switch_context dsa_switch_context_##n = { \
63 .dapi = _dapi, \
64 .prv_data = data, \
65 .init_ports = 0, \
66 .num_ports = DT_INST_CHILD_NUM_STATUS_OKAY(n), \
67 }; \
68 DT_INST_FOREACH_CHILD_STATUS_OKAY_VARGS(n, fn, n);
69
73 struct net_if *iface_user[DSA_PORT_MAX_COUNT];
74
77
79 struct dsa_api *dapi;
80
82 void *prv_data;
83
86
89
92};
93
98struct dsa_api {
100
102 struct net_if *(*recv)(struct net_if *iface, struct net_pkt *pkt);
103
105 struct net_pkt *(*xmit)(struct net_if *iface, struct net_pkt *pkt);
106
108 int (*port_init)(const struct device *dev);
109
111 void (*port_phylink_change)(const struct device *dev, struct phy_link_state *state,
112 void *user_data);
113
114#if defined(CONFIG_NET_L2_PTP) || defined(__DOXYGEN__)
119 int (*port_txtstamp)(const struct device *dev, struct net_pkt *pkt);
120#endif
122 int (*switch_setup)(const struct dsa_switch_context *dsa_switch_ctx);
123
125 int (*connect_tag_protocol)(struct dsa_switch_context *dsa_switch_ctx, int tag_proto);
126
128 enum ethernet_hw_caps (*get_capabilities)(const struct device *dev);
129
131 int (*set_config)(const struct device *dev,
132 enum ethernet_config_type type,
133 const struct ethernet_config *config);
134
136 int (*get_config)(const struct device *dev,
137 enum ethernet_config_type type,
138 struct ethernet_config *config);
139};
140
148 const int port_idx;
150 const struct device *phy_dev;
152 const char *phy_mode;
154 const int tag_proto;
157#if defined(CONFIG_NET_L2_PTP) || defined(__DOXYGEN__)
162 const struct device *ptp_clock;
163#endif
166};
167
169
170/*
171 * DSA port init
172 *
173 * Returns:
174 * - 0 if ok, < 0 if error
175 */
176int dsa_port_initialize(const struct device *dev);
177
178/*
179 * DSA transmit function
180 *
181 * param dev: Port device to transmit
182 * param pkt: Network packet
183 *
184 * Returns:
185 * - 0 if ok, < 0 if error
186 */
187int dsa_xmit(const struct device *dev, struct net_pkt *pkt);
188
189/*
190 * DSA receive function
191 *
192 * param iface: Interface of conduit port
193 * param pkt: Network packet
194 *
195 * Returns:
196 * - Interface to redirect
197 */
198struct net_if *dsa_recv(struct net_if *iface, struct net_pkt *pkt);
199
200/*
201 * DSA ethernet init function to handle flags
202 *
203 * param iface: Interface of port
204 *
205 * Returns:
206 * - 0 if ok, < 0 if error
207 */
208int dsa_eth_init(struct net_if *iface);
209
210/* Ethernet APIs definition for switch ports */
211extern const struct ethernet_api dsa_eth_api;
212
214
224struct net_if *dsa_user_get_iface(struct net_if *iface, int port_idx);
225
226#ifdef __cplusplus
227}
228#endif
229
233#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:144
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:513
Structure to provide DSA switch api callbacks - it is an augmented struct ethernet_api.
Definition dsa_core.h:98
void(* port_phylink_change)(const struct device *dev, struct phy_link_state *state, void *user_data)
Port link change.
Definition dsa_core.h:111
int(* get_config)(const struct device *dev, enum ethernet_config_type type, struct ethernet_config *config)
Get hardware specific configuration.
Definition dsa_core.h:136
int(* switch_setup)(const struct dsa_switch_context *dsa_switch_ctx)
Switch setup.
Definition dsa_core.h:122
int(* port_init)(const struct device *dev)
Port init.
Definition dsa_core.h:108
enum ethernet_hw_caps(* get_capabilities)(const struct device *dev)
Get the device capabilities.
Definition dsa_core.h:128
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:125
int(* port_txtstamp)(const struct device *dev, struct net_pkt *pkt)
Port TX timestamp handling.
Definition dsa_core.h:119
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:131
Structure of DSA port configuration.
Definition dsa_core.h:144
const struct device * ptp_clock
PTP clock used on the port.
Definition dsa_core.h:162
void * prv_config
Instance specific config.
Definition dsa_core.h:165
const int port_idx
Port index.
Definition dsa_core.h:148
const int tag_proto
Tag protocol.
Definition dsa_core.h:154
const char * phy_mode
PHY mode.
Definition dsa_core.h:152
const struct device * ethernet_connection
Ethernet device connected to the port.
Definition dsa_core.h:156
struct net_eth_mac_config mcfg
Port mac address.
Definition dsa_core.h:146
const struct device * phy_dev
PHY device.
Definition dsa_core.h:150
DSA switch context data.
Definition dsa_core.h:71
void * tagger_data
DSA tagger data provided by instance when connecting to tag protocol.
Definition dsa_core.h:91
void * prv_data
Instance specific data.
Definition dsa_core.h:82
struct net_if * iface_conduit
Pointer to DSA conduit network interface.
Definition dsa_core.h:76
struct dsa_api * dapi
DSA specific API callbacks.
Definition dsa_core.h:79
uint8_t init_ports
Number of initialized ports in the DSA switch.
Definition dsa_core.h:88
struct net_if * iface_user[DSA_PORT_MAX_COUNT]
Pointers to all DSA user network interfaces.
Definition dsa_core.h:73
uint8_t num_ports
Number of ports in the DSA switch.
Definition dsa_core.h:85
Ethernet L2 API operations.
Definition ethernet.h:487
MAC address configuration.
Definition ethernet.h:1222
Network Interface structure.
Definition net_if.h:735
Network packet.
Definition net_pkt.h:119