Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
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 <device.h>
15#include <net/net_if.h>
16
24#define NET_DSA_PORT_MAX_COUNT 8
25#define DSA_STATUS_PERIOD_MS K_MSEC(1000)
26
27/*
28 * Size of the DSA TAG:
29 * - KSZ8794 - 1 byte
30 */
31#if defined(CONFIG_DSA_KSZ8794) && defined(DSA_KSZ_TAIL_TAGGING)
32#define DSA_TAG_SIZE 1
33#else
34#define DSA_TAG_SIZE 0
35#endif
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
53int dsa_tx(const struct device *dev, struct net_pkt *pkt);
54
68typedef enum net_verdict (*dsa_net_recv_cb_t)(struct net_if *iface,
69 struct net_pkt *pkt);
70
80
89struct net_if *dsa_net_recv(struct net_if *iface, struct net_pkt **pkt);
90
94typedef int (*dsa_send_t)(const struct device *dev, struct net_pkt *pkt);
95
106
116
125struct dsa_context {
127 struct net_if *iface_slave[NET_DSA_PORT_MAX_COUNT];
128
130 struct net_if *iface_master;
131
133 struct dsa_api *dapi;
134
136 struct k_work_delayable dsa_work;
137
139 uint8_t num_slave_ports;
140
142 bool link_up[NET_DSA_PORT_MAX_COUNT];
143
145 void *prv_data;
146};
147
152struct dsa_api {
154 struct net_if *(*dsa_get_iface)(struct net_if *iface,
155 struct net_pkt *pkt);
156 /*
157 * Callbacks required for DSA switch initialization and configuration.
158 *
159 * Each switch instance (e.g. two KSZ8794 ICs) would have its own struct
160 * dsa_context.
161 */
163 int (*switch_read)(const struct device *dev, uint16_t reg_addr,
164 uint8_t *value);
166 int (*switch_write)(const struct device *dev, uint16_t reg_addr,
167 uint8_t value);
168
170 int (*switch_set_mac_table_entry)(const struct device *dev,
171 const uint8_t *mac,
172 uint8_t fw_port,
173 uint16_t tbl_entry_idx,
175
177 int (*switch_get_mac_table_entry)(const struct device *dev,
178 uint8_t *buf,
179 uint16_t tbl_entry_idx);
180
181 /*
182 * DSA helper callbacks
183 */
184 struct net_pkt *(*dsa_xmit_pkt)(struct net_if *iface,
185 struct net_pkt *pkt);
186};
187
201struct net_if *dsa_get_slave_port(struct net_if *iface, int slave_num);
202
212int dsa_switch_read(struct net_if *iface, uint16_t reg_addr, uint8_t *value);
213
223int dsa_switch_write(struct net_if *iface, uint16_t reg_addr, uint8_t value);
224
237 const uint8_t *mac,
238 uint8_t fw_port,
239 uint16_t tbl_entry_idx,
241
252 uint8_t *buf,
253 uint16_t tbl_entry_idx);
254
262};
263
264#ifdef __cplusplus
265}
266#endif
267
271#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.
#define NET_DSA_PORT_MAX_COUNT
Definition: dsa.h:24
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:68
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:94
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:97
flags
Definition: http_parser.h:131
Public API for network interface.
__UINT8_TYPE__ uint8_t
Definition: stdint.h:58
__UINT16_TYPE__ uint16_t
Definition: stdint.h:59
Runtime device structure (in ROM) per driver instance.
Definition: device.h:367
Structure to provide mac address for each LAN interface.
Definition: dsa.h:259
uint8_t mac_addr[6]
Definition: dsa.h:261
A structure used to submit work after a delay.
Definition: kernel.h:3651
Network Interface structure.
Definition: net_if.h:468
Network packet.
Definition: net_pkt.h:62
struct net_if * iface
Definition: net_pkt.h:85