Skip to content

Commit ab90049

Browse files
committed
net: dsa: support tag protocol setup
Supported tag protocol setup. Signed-off-by: Yangbo Lu <[email protected]>
1 parent 5ec0588 commit ab90049

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

subsys/net/l2/ethernet/dsa/dsa_port.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ LOG_MODULE_REGISTER(net_dsa_port, CONFIG_NET_DSA_LOG_LEVEL);
1010
#include <zephyr/net/ethernet.h>
1111
#include <zephyr/net/phy.h>
1212
#include <zephyr/net/dsa_core.h>
13+
#include "dsa_tag.h"
1314

1415
#if defined(CONFIG_NET_INTERFACE_NAME_LEN)
1516
#define INTERFACE_NAME_LEN CONFIG_NET_INTERFACE_NAME_LEN
@@ -28,19 +29,18 @@ int dsa_port_initialize(const struct device *dev)
2829

2930
dsa_switch_ctx->init_ports++;
3031

31-
/* Find conduit port */
32+
/* Find the connection of conduit port and cpu port */
3233
if (dsa_switch_ctx->iface_conduit == NULL && cfg->ethernet_connection != NULL) {
3334
dsa_switch_ctx->iface_conduit = net_if_lookup_by_dev(cfg->ethernet_connection);
3435
if (dsa_switch_ctx->iface_conduit == NULL) {
3536
LOG_ERR("DSA: Conduit iface NOT found!");
3637
}
3738

39+
/* Set up tag protocol on the cpu port */
3840
eth_ctx->dsa_port = DSA_CPU_PORT;
41+
dsa_tag_setup(dev);
3942

40-
/*
41-
* Provide pointer to DSA switch context to conduit's eth interface
42-
* struct ethernet_context
43-
*/
43+
/* Provide DSA information to the conduit port */
4444
eth_ctx_conduit = net_if_l2_data(dsa_switch_ctx->iface_conduit);
4545
eth_ctx_conduit->dsa_switch_ctx = dsa_switch_ctx;
4646
eth_ctx_conduit->dsa_port = DSA_CONDUIT_PORT;

subsys/net/l2/ethernet/dsa/dsa_tag.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <zephyr/net/ethernet.h>
88
#include <zephyr/net/dsa_core.h>
9+
#include "dsa_tag.h"
910

1011
struct net_if *dsa_tag_recv(struct net_if *iface, struct net_pkt *pkt)
1112
{
@@ -36,3 +37,20 @@ struct net_pkt *dsa_tag_xmit(struct net_if *iface, struct net_pkt *pkt)
3637

3738
return dsa_switch_ctx->dapi->xmit(iface, pkt);
3839
}
40+
41+
void dsa_tag_setup(const struct device *dev_cpu)
42+
{
43+
const struct dsa_port_config *cfg = dev_cpu->config;
44+
struct dsa_switch_context *dsa_switch_ctx = dev_cpu->data;
45+
46+
switch (cfg->tag_proto) {
47+
case DSA_TAG_PROTO_NETC:
48+
dsa_switch_ctx->dapi->recv = dsa_tag_netc_recv;
49+
dsa_switch_ctx->dapi->xmit = dsa_tag_netc_xmit;
50+
break;
51+
default:
52+
dsa_switch_ctx->dapi->recv = NULL;
53+
dsa_switch_ctx->dapi->xmit = NULL;
54+
break;
55+
}
56+
}

subsys/net/l2/ethernet/dsa/dsa_tag.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010

1111
struct net_if *dsa_tag_recv(struct net_if *iface, struct net_pkt *pkt);
1212
struct net_pkt *dsa_tag_xmit(struct net_if *iface, struct net_pkt *pkt);
13+
void dsa_tag_setup(const struct device *dev_cpu);
1314

1415
#endif

0 commit comments

Comments
 (0)