Zephyr Project API 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
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
30#if defined(CONFIG_DSA_PORT_MAX_COUNT)
31#define DSA_PORT_MAX_COUNT CONFIG_DSA_PORT_MAX_COUNT
32#else
33#define DSA_PORT_MAX_COUNT 0
34#endif
35
36#if defined(CONFIG_DSA_TAG_SIZE)
37#define DSA_TAG_SIZE CONFIG_DSA_TAG_SIZE
38#else
39#define DSA_TAG_SIZE 0
40#endif
41
44#ifdef __cplusplus
45extern "C" {
46#endif
47
55#define DSA_PORT_INST_INIT(port, n, cfg) \
56 NET_DEVICE_INIT_INSTANCE(CONCAT(dsa_, n, port), DEVICE_DT_NAME(port), DT_REG_ADDR(port), \
57 dsa_port_initialize, NULL, &dsa_switch_context_##n, cfg, \
58 CONFIG_ETH_INIT_PRIORITY, &dsa_eth_api, ETHERNET_L2, \
59 NET_L2_GET_CTX_TYPE(ETHERNET_L2), NET_ETH_MTU);
60
69#define DSA_SWITCH_INST_INIT(n, _dapi, data, fn) \
70 struct dsa_switch_context dsa_switch_context_##n = { \
71 .dapi = _dapi, \
72 .prv_data = data, \
73 .init_ports = 0, \
74 .num_ports = DT_INST_CHILD_NUM_STATUS_OKAY(n), \
75 }; \
76 DT_INST_FOREACH_CHILD_STATUS_OKAY_VARGS(n, fn, n);
77
81 struct net_if *iface_user[DSA_PORT_MAX_COUNT];
82
85
87 struct dsa_api *dapi;
88
90 void *prv_data;
91
94
97};
98
103struct dsa_api {
107 struct net_if *(*recv)(struct net_if *iface, struct net_pkt *pkt);
108
110 struct net_pkt *(*xmit)(struct net_if *iface, struct net_pkt *pkt);
111
113 int (*port_init)(const struct device *dev);
114
116 void (*port_phylink_change)(const struct device *dev, struct phy_link_state *state,
117 void *user_data);
118
121
123 int (*switch_setup)(const struct dsa_switch_context *dsa_switch_ctx);
124};
125
135 const int port_idx;
137 const struct device *phy_dev;
139 const char *phy_mode;
141 const int tag_proto;
146};
147
150enum dsa_port_type {
151 NON_DSA_PORT,
152 DSA_CONDUIT_PORT,
153 DSA_USER_PORT,
154 DSA_CPU_PORT,
155 DSA_PORT,
156};
157
158/*
159 * DSA port init
160 *
161 * Returns:
162 * - 0 if ok, < 0 if error
163 */
164int dsa_port_initialize(const struct device *dev);
165
166/*
167 * DSA transmit function
168 *
169 * param dev: Port device to transmit
170 * param pkt: Network packet
171 *
172 * Returns:
173 * - 0 if ok, < 0 if error
174 */
175int dsa_xmit(const struct device *dev, struct net_pkt *pkt);
176
177/*
178 * DSA receive function
179 *
180 * param iface: Interface of conduit port
181 * param pkt: Network packet
182 *
183 * Returns:
184 * - Interface to redirect
185 */
186struct net_if *dsa_recv(struct net_if *iface, struct net_pkt *pkt);
187
188/*
189 * DSA ethernet init function to handle flags
190 *
191 * param iface: Interface of port
192 *
193 * Returns:
194 * - 0 if ok, < 0 if error
195 */
196int dsa_eth_init(struct net_if *iface);
197
198/* Ethernet APIs definition for switch ports */
199extern const struct ethernet_api dsa_eth_api;
200
212struct net_if *dsa_user_get_iface(struct net_if *iface, int port_idx);
213
214#ifdef __cplusplus
215}
216#endif
217
221#endif /* ZEPHYR_INCLUDE_NET_DSA_CORE_H_ */
Devicetree main header.
System error numbers.
struct net_if * dsa_user_get_iface(struct net_if *iface, int port_idx)
Get network interface of a user port.
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:103
void(* port_phylink_change)(const struct device *dev, struct phy_link_state *state, void *user_data)
Port link change.
Definition dsa_core.h:116
int(* switch_setup)(const struct dsa_switch_context *dsa_switch_ctx)
Switch setup.
Definition dsa_core.h:123
void(* port_generate_random_mac)(uint8_t *mac_addr)
Port generates random mac address.
Definition dsa_core.h:120
int(* port_init)(const struct device *dev)
Port init.
Definition dsa_core.h:113
Structure of DSA port configuration.
Definition dsa_core.h:129
const bool use_random_mac_addr
Use random mac address or not.
Definition dsa_core.h:133
void * prv_config
Instance specific config.
Definition dsa_core.h:145
const int port_idx
Port index.
Definition dsa_core.h:135
const int tag_proto
Tag protocol.
Definition dsa_core.h:141
const char * phy_mode
PHY mode.
Definition dsa_core.h:139
uint8_t mac_addr[6]
Port mac address.
Definition dsa_core.h:131
const struct device * ethernet_connection
Ethernet device connected to the port.
Definition dsa_core.h:143
const struct device * phy_dev
PHY device.
Definition dsa_core.h:137
DSA switch context data.
Definition dsa_core.h:79
void * prv_data
Instance specific data.
Definition dsa_core.h:90
struct net_if * iface_conduit
Pointer to DSA conduit network interface.
Definition dsa_core.h:84
struct dsa_api * dapi
DSA specific API callbacks.
Definition dsa_core.h:87
uint8_t init_ports
Number of initialized ports in the DSA switch.
Definition dsa_core.h:96
struct net_if * iface_user[DSA_PORT_MAX_COUNT]
Pointers to all DSA user network interfaces.
Definition dsa_core.h:81
uint8_t num_ports
Number of ports in the DSA switch.
Definition dsa_core.h:93
Ethernet L2 API operations.
Definition ethernet.h:518
Network Interface structure.
Definition net_if.h:726
Network packet.
Definition net_pkt.h:91