Skip to content

Commit fd12f2f

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

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed

include/zephyr/net/dsa_core.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ struct dsa_port_config {
137137
const struct device *phy_dev;
138138
/** PHY mode */
139139
const char *phy_mode;
140+
/** Tag protocol */
141+
const int tag_proto;
140142
/** Ethernet device connected to the port */
141143
const struct device *ethernet_connection;
142144
/** Instance specific config */

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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
#include <zephyr/logging/log.h>
8+
LOG_MODULE_REGISTER(net_dsa_tag, CONFIG_NET_DSA_LOG_LEVEL);
9+
710
#include <zephyr/net/ethernet.h>
811
#include <zephyr/net/dsa_core.h>
12+
#include "dsa_tag.h"
913

1014
struct net_if *dsa_tag_recv(struct net_if *iface, struct net_pkt *pkt)
1115
{
@@ -36,3 +40,24 @@ struct net_pkt *dsa_tag_xmit(struct net_if *iface, struct net_pkt *pkt)
3640

3741
return dsa_switch_ctx->dapi->xmit(iface, pkt);
3842
}
43+
44+
void dsa_tag_setup(const struct device *dev_cpu)
45+
{
46+
const struct dsa_port_config *cfg = dev_cpu->config;
47+
struct dsa_switch_context *dsa_switch_ctx = dev_cpu->data;
48+
49+
switch (cfg->tag_proto) {
50+
#ifdef CONFIG_DSA_TAG_PROTOCOL_NETC
51+
case DSA_TAG_PROTO_NETC:
52+
dsa_switch_ctx->dapi->recv = dsa_tag_netc_recv;
53+
dsa_switch_ctx->dapi->xmit = dsa_tag_netc_xmit;
54+
break;
55+
#endif
56+
case DSA_TAG_PROTO_NOTAG:
57+
dsa_switch_ctx->dapi->recv = NULL;
58+
dsa_switch_ctx->dapi->xmit = NULL;
59+
break;
60+
default:
61+
LOG_ERR("DSA tag protocol %d not supported", cfg->tag_proto);
62+
}
63+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66
#ifndef ZEPHYR_SUBSYS_DSA_TAG_PRIV_H_
77
#define ZEPHYR_SUBSYS_DSA_TAG_PRIV_H_
88

9+
#include <zephyr/dt-bindings/ethernet/dsa_tag_proto.h>
10+
#ifdef CONFIG_DSA_TAG_PROTOCOL_NETC
11+
#include "dsa_tag_netc.h"
12+
#endif
13+
914
struct net_if *dsa_tag_recv(struct net_if *iface, struct net_pkt *pkt);
1015
struct net_pkt *dsa_tag_xmit(struct net_if *iface, struct net_pkt *pkt);
16+
void dsa_tag_setup(const struct device *dev_cpu);
1117

1218
#endif

0 commit comments

Comments
 (0)