123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- #ifndef ZEPHYR_INCLUDE_NET_DSA_H_
- #define ZEPHYR_INCLUDE_NET_DSA_H_
- #include <device.h>
- #include <net/net_if.h>
- #define NET_DSA_PORT_MAX_COUNT 8
- #define DSA_STATUS_PERIOD_MS K_MSEC(1000)
- #if defined(CONFIG_DSA_KSZ8794) && defined(DSA_KSZ_TAIL_TAGGING)
- #define DSA_TAG_SIZE 1
- #else
- #define DSA_TAG_SIZE 0
- #endif
- #ifdef __cplusplus
- extern "C" {
- #endif
- int dsa_tx(const struct device *dev, struct net_pkt *pkt);
- typedef enum net_verdict (*dsa_net_recv_cb_t)(struct net_if *iface,
- struct net_pkt *pkt);
- int dsa_register_recv_callback(struct net_if *iface, dsa_net_recv_cb_t cb);
- struct net_if *dsa_net_recv(struct net_if *iface, struct net_pkt **pkt);
- typedef int (*dsa_send_t)(const struct device *dev, struct net_pkt *pkt);
- int dsa_register_master_tx(struct net_if *iface, dsa_send_t fn);
- bool dsa_is_port_master(struct net_if *iface);
- struct dsa_context {
-
- struct net_if *iface_slave[NET_DSA_PORT_MAX_COUNT];
-
- struct net_if *iface_master;
-
- struct dsa_api *dapi;
-
- struct k_work_delayable dsa_work;
-
- uint8_t num_slave_ports;
-
- bool link_up[NET_DSA_PORT_MAX_COUNT];
-
- void *prv_data;
- };
- struct dsa_api {
-
- struct net_if *(*dsa_get_iface)(struct net_if *iface,
- struct net_pkt *pkt);
-
-
- int (*switch_read)(const struct device *dev, uint16_t reg_addr,
- uint8_t *value);
-
- int (*switch_write)(const struct device *dev, uint16_t reg_addr,
- uint8_t value);
-
- int (*switch_set_mac_table_entry)(const struct device *dev,
- const uint8_t *mac,
- uint8_t fw_port,
- uint16_t tbl_entry_idx,
- uint16_t flags);
-
- int (*switch_get_mac_table_entry)(const struct device *dev,
- uint8_t *buf,
- uint16_t tbl_entry_idx);
-
- struct net_pkt *(*dsa_xmit_pkt)(struct net_if *iface,
- struct net_pkt *pkt);
- };
- struct net_if *dsa_get_slave_port(struct net_if *iface, int slave_num);
- int dsa_switch_read(struct net_if *iface, uint16_t reg_addr, uint8_t *value);
- int dsa_switch_write(struct net_if *iface, uint16_t reg_addr, uint8_t value);
- 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);
- int dsa_switch_get_mac_table_entry(struct net_if *iface,
- uint8_t *buf,
- uint16_t tbl_entry_idx);
- struct dsa_slave_config {
-
- uint8_t mac_addr[6];
- };
- #ifdef __cplusplus
- }
- #endif
- #endif
|