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#ifdef CONFIG_DSA_TAG_SIZE
32#define DSA_TAG_SIZE CONFIG_DSA_TAG_SIZE
33#else
34#define DSA_TAG_SIZE 0
35#endif
36
39#ifdef __cplusplus
40extern "C" {
41#endif
42
55int dsa_tx(const struct device *dev, struct net_pkt *pkt);
56
70typedef enum net_verdict (*dsa_net_recv_cb_t)(struct net_if *iface,
71 struct net_pkt *pkt);
72
82
91struct net_if *dsa_net_recv(struct net_if *iface, struct net_pkt **pkt);
92
96typedef int (*dsa_send_t)(const struct device *dev, struct net_pkt *pkt);
97
108
118
127struct dsa_context {
129 struct net_if *iface_slave[NET_DSA_PORT_MAX_COUNT];
130
132 struct net_if *iface_master;
133
135 struct dsa_api *dapi;
136
138 struct k_work_delayable dsa_work;
139
141 uint8_t num_slave_ports;
142
144 bool link_up[NET_DSA_PORT_MAX_COUNT];
145
147 void *prv_data;
148};
149
154struct dsa_api {
156 struct net_if *(*dsa_get_iface)(struct net_if *iface,
157 struct net_pkt *pkt);
158 /*
159 * Callbacks required for DSA switch initialization and configuration.
160 *
161 * Each switch instance (e.g. two KSZ8794 ICs) would have its own struct
162 * dsa_context.
163 */
165 int (*switch_read)(const struct device *dev, uint16_t reg_addr,
166 uint8_t *value);
168 int (*switch_write)(const struct device *dev, uint16_t reg_addr,
169 uint8_t value);
170
172 int (*switch_set_mac_table_entry)(const struct device *dev,
173 const uint8_t *mac,
174 uint8_t fw_port,
175 uint16_t tbl_entry_idx,
177
179 int (*switch_get_mac_table_entry)(const struct device *dev,
180 uint8_t *buf,
181 uint16_t tbl_entry_idx);
182
183 /*
184 * DSA helper callbacks
185 */
186 struct net_pkt *(*dsa_xmit_pkt)(struct net_if *iface,
187 struct net_pkt *pkt);
188};
189
203struct net_if *dsa_get_slave_port(struct net_if *iface, int slave_num);
204
214int dsa_switch_read(struct net_if *iface, uint16_t reg_addr, uint8_t *value);
215
225int dsa_switch_write(struct net_if *iface, uint16_t reg_addr, uint8_t value);
226
239 const uint8_t *mac,
240 uint8_t fw_port,
241 uint16_t tbl_entry_idx,
243
254 uint8_t *buf,
255 uint16_t tbl_entry_idx);
256
265
266#ifdef __cplusplus
267}
268#endif
269
273#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:70
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:96
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:103
Public API for network interface.
flags
Definition parser.h:97
__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:453
Structure to provide mac address for each LAN interface.
Definition dsa.h:261
uint8_t mac_addr[6]
MAC address for each LAN{123.,} ports.
Definition dsa.h:263
A structure used to submit work after a delay.
Definition kernel.h:4034
Network Interface structure.
Definition net_if.h:698
Network packet.
Definition net_pkt.h:91
struct net_if * iface
Network interface.
Definition net_pkt.h:114