Zephyr API Documentation  3.7.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
dsa.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 DENX Software Engineering GmbH
3 * Lukasz Majewski <lukma@denx.de>
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
11#ifndef ZEPHYR_INCLUDE_NET_DSA_H_
12#define ZEPHYR_INCLUDE_NET_DSA_H_
13
14#include <zephyr/device.h>
15#include <zephyr/net/net_if.h>
16
26#define NET_DSA_PORT_MAX_COUNT 8
27#define DSA_STATUS_PERIOD_MS K_MSEC(1000)
28
29/*
30 * Size of the DSA TAG:
31 * - KSZ8794 - 1 byte
32 */
33#if defined(CONFIG_DSA_KSZ8794) && defined(CONFIG_DSA_KSZ_TAIL_TAGGING)
34#define DSA_TAG_SIZE 1
35#else
36#define DSA_TAG_SIZE 0
37#endif
38
41#ifdef __cplusplus
42extern "C" {
43#endif
44
57int dsa_tx(const struct device *dev, struct net_pkt *pkt);
58
72typedef enum net_verdict (*dsa_net_recv_cb_t)(struct net_if *iface,
73 struct net_pkt *pkt);
74
84
93struct net_if *dsa_net_recv(struct net_if *iface, struct net_pkt **pkt);
94
98typedef int (*dsa_send_t)(const struct device *dev, struct net_pkt *pkt);
99
110
120
129struct dsa_context {
131 struct net_if *iface_slave[NET_DSA_PORT_MAX_COUNT];
132
134 struct net_if *iface_master;
135
137 struct dsa_api *dapi;
138
140 struct k_work_delayable dsa_work;
141
143 uint8_t num_slave_ports;
144
146 bool link_up[NET_DSA_PORT_MAX_COUNT];
147
149 void *prv_data;
150};
151
156struct dsa_api {
158 struct net_if *(*dsa_get_iface)(struct net_if *iface,
159 struct net_pkt *pkt);
160 /*
161 * Callbacks required for DSA switch initialization and configuration.
162 *
163 * Each switch instance (e.g. two KSZ8794 ICs) would have its own struct
164 * dsa_context.
165 */
167 int (*switch_read)(const struct device *dev, uint16_t reg_addr,
168 uint8_t *value);
170 int (*switch_write)(const struct device *dev, uint16_t reg_addr,
171 uint8_t value);
172
174 int (*switch_set_mac_table_entry)(const struct device *dev,
175 const uint8_t *mac,
176 uint8_t fw_port,
177 uint16_t tbl_entry_idx,
179
181 int (*switch_get_mac_table_entry)(const struct device *dev,
182 uint8_t *buf,
183 uint16_t tbl_entry_idx);
184
185 /*
186 * DSA helper callbacks
187 */
188 struct net_pkt *(*dsa_xmit_pkt)(struct net_if *iface,
189 struct net_pkt *pkt);
190};
191
205struct net_if *dsa_get_slave_port(struct net_if *iface, int slave_num);
206
216int dsa_switch_read(struct net_if *iface, uint16_t reg_addr, uint8_t *value);
217
227int dsa_switch_write(struct net_if *iface, uint16_t reg_addr, uint8_t value);
228
241 const uint8_t *mac,
242 uint8_t fw_port,
243 uint16_t tbl_entry_idx,
245
256 uint8_t *buf,
257 uint16_t tbl_entry_idx);
258
266};
267
268#ifdef __cplusplus
269}
270#endif
271
275#endif /* ZEPHYR_INCLUDE_NET_DSA_H_ */
struct net_if * dsa_net_recv(struct net_if *iface, struct net_pkt **pkt)
Set DSA interface to packet.
bool dsa_is_port_master(struct net_if *iface)
DSA helper function to check if port is master.
int dsa_switch_read(struct net_if *iface, uint16_t reg_addr, uint8_t *value)
Read from DSA switch register.
int dsa_switch_get_mac_table_entry(struct net_if *iface, uint8_t *buf, uint16_t tbl_entry_idx)
Read static MAC table entry.
int dsa_tx(const struct device *dev, struct net_pkt *pkt)
DSA generic transmit function.
int dsa_register_master_tx(struct net_if *iface, dsa_send_t fn)
DSA helper function to register transmit function for master.
enum net_verdict(* dsa_net_recv_cb_t)(struct net_if *iface, struct net_pkt *pkt)
DSA (MGMT) Receive packet callback.
Definition: dsa.h:72
struct net_if * dsa_get_slave_port(struct net_if *iface, int slave_num)
Get network interface of a slave port.
int dsa_switch_set_mac_table_entry(struct net_if *iface, const uint8_t *mac, uint8_t fw_port, uint16_t tbl_entry_idx, uint16_t flags)
Write static MAC table entry.
int dsa_switch_write(struct net_if *iface, uint16_t reg_addr, uint8_t value)
Write to DSA switch.
int(* dsa_send_t)(const struct device *dev, struct net_pkt *pkt)
Pointer to master interface send function.
Definition: dsa.h:98
int dsa_register_recv_callback(struct net_if *iface, dsa_net_recv_cb_t cb)
Register DSA Rx callback functions.
net_verdict
Net Verdict.
Definition: net_core.h:100
Public API for network interface.
flags
Definition: parser.h:96
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
__UINT16_TYPE__ uint16_t
Definition: stdint.h:89
Runtime device structure (in ROM) per driver instance.
Definition: device.h:403
Structure to provide mac address for each LAN interface.
Definition: dsa.h:263
uint8_t mac_addr[6]
MAC address for each LAN{123.,} ports.
Definition: dsa.h:265
A structure used to submit work after a delay.
Definition: kernel.h:3908
Network Interface structure.
Definition: net_if.h:678
Network packet.
Definition: net_pkt.h:67
struct net_if * iface
Network interface.
Definition: net_pkt.h:90