Zephyr API Documentation 4.0.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
28#define NET_DSA_PORT_MAX_COUNT 8
29#define DSA_STATUS_PERIOD_MS K_MSEC(1000)
30
31/*
32 * Size of the DSA TAG:
33 * - KSZ8794 - 1 byte
34 */
35#if defined(CONFIG_DSA_KSZ8794) && defined(CONFIG_DSA_KSZ_TAIL_TAGGING)
36#define DSA_TAG_SIZE 1
37#else
38#define DSA_TAG_SIZE 0
39#endif
40
43#ifdef __cplusplus
44extern "C" {
45#endif
46
59int dsa_tx(const struct device *dev, struct net_pkt *pkt);
60
74typedef enum net_verdict (*dsa_net_recv_cb_t)(struct net_if *iface,
75 struct net_pkt *pkt);
76
86
95struct net_if *dsa_net_recv(struct net_if *iface, struct net_pkt **pkt);
96
100typedef int (*dsa_send_t)(const struct device *dev, struct net_pkt *pkt);
101
112
122
131struct dsa_context {
133 struct net_if *iface_slave[NET_DSA_PORT_MAX_COUNT];
134
136 struct net_if *iface_master;
137
139 struct dsa_api *dapi;
140
142 struct k_work_delayable dsa_work;
143
145 uint8_t num_slave_ports;
146
148 bool link_up[NET_DSA_PORT_MAX_COUNT];
149
151 void *prv_data;
152};
153
158struct dsa_api {
160 struct net_if *(*dsa_get_iface)(struct net_if *iface,
161 struct net_pkt *pkt);
162 /*
163 * Callbacks required for DSA switch initialization and configuration.
164 *
165 * Each switch instance (e.g. two KSZ8794 ICs) would have its own struct
166 * dsa_context.
167 */
169 int (*switch_read)(const struct device *dev, uint16_t reg_addr,
170 uint8_t *value);
172 int (*switch_write)(const struct device *dev, uint16_t reg_addr,
173 uint8_t value);
174
176 int (*switch_set_mac_table_entry)(const struct device *dev,
177 const uint8_t *mac,
178 uint8_t fw_port,
179 uint16_t tbl_entry_idx,
181
183 int (*switch_get_mac_table_entry)(const struct device *dev,
184 uint8_t *buf,
185 uint16_t tbl_entry_idx);
186
187 /*
188 * DSA helper callbacks
189 */
190 struct net_pkt *(*dsa_xmit_pkt)(struct net_if *iface,
191 struct net_pkt *pkt);
192};
193
207struct net_if *dsa_get_slave_port(struct net_if *iface, int slave_num);
208
218int dsa_switch_read(struct net_if *iface, uint16_t reg_addr, uint8_t *value);
219
229int dsa_switch_write(struct net_if *iface, uint16_t reg_addr, uint8_t value);
230
243 const uint8_t *mac,
244 uint8_t fw_port,
245 uint16_t tbl_entry_idx,
247
258 uint8_t *buf,
259 uint16_t tbl_entry_idx);
260
269
270#ifdef __cplusplus
271}
272#endif
273
277#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:74
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:100
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:102
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:412
Structure to provide mac address for each LAN interface.
Definition dsa.h:265
uint8_t mac_addr[6]
MAC address for each LAN{123.,} ports.
Definition dsa.h:267
A structure used to submit work after a delay.
Definition kernel.h:4013
Network Interface structure.
Definition net_if.h:692
Network packet.
Definition net_pkt.h:91
struct net_if * iface
Network interface.
Definition net_pkt.h:114