1 /*
2  * Copyright 2025 NXP
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/logging/log.h>
8 LOG_MODULE_REGISTER(net_dsa_core, CONFIG_NET_DSA_LOG_LEVEL);
9 
10 #include <zephyr/net/ethernet.h>
11 #include <zephyr/net/dsa_core.h>
12 
13 #include "dsa_tag.h"
14 
dsa_recv(struct net_if * iface,struct net_pkt * pkt)15 struct net_if *dsa_recv(struct net_if *iface, struct net_pkt *pkt)
16 {
17 	if (iface == NULL || pkt == NULL) {
18 		return iface;
19 	}
20 
21 	/* Tag protocol handles to untag and re-direct interface */
22 	return dsa_tag_recv(iface, pkt);
23 }
24 
dsa_xmit(const struct device * dev,struct net_pkt * pkt)25 int dsa_xmit(const struct device *dev, struct net_pkt *pkt)
26 {
27 	struct dsa_switch_context *dsa_switch_ctx = dev->data;
28 	struct net_if *iface = net_if_lookup_by_dev(dev);
29 	struct net_if *iface_conduit = dsa_switch_ctx->iface_conduit;
30 	const struct device *dev_conduit = net_if_get_device(iface_conduit);
31 	const struct ethernet_api *eth_api_conduit = dev_conduit->api;
32 	/* Tag protocol handles pkt first */
33 	struct net_pkt *dsa_pkt = dsa_tag_xmit(iface, pkt);
34 
35 	/* Transmit from conduit port */
36 	return eth_api_conduit->send(dev_conduit, dsa_pkt);
37 }
38 
dsa_eth_init(struct net_if * iface)39 int dsa_eth_init(struct net_if *iface)
40 {
41 	struct ethernet_context *eth_ctx = net_if_l2_data(iface);
42 
43 	if (eth_ctx->dsa_port == DSA_CONDUIT_PORT) {
44 		net_if_flag_clear(iface, NET_IF_IPV4);
45 		net_if_flag_clear(iface, NET_IF_IPV6);
46 	}
47 
48 	return 0;
49 }
50