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_user, CONFIG_NET_DSA_LOG_LEVEL);
9 
10 #include <zephyr/net/ethernet.h>
11 #include <zephyr/net/dsa_core.h>
12 
dsa_user_get_iface(struct net_if * iface,int port_idx)13 struct net_if *dsa_user_get_iface(struct net_if *iface, int port_idx)
14 {
15 	struct ethernet_context *eth_ctx = net_if_l2_data(iface);
16 	struct dsa_switch_context *dsa_switch_ctx;
17 
18 	if (eth_ctx == NULL || eth_ctx->dsa_switch_ctx == NULL) {
19 		LOG_ERR("Iface %p context not available!", iface);
20 		return NULL;
21 	}
22 
23 	dsa_switch_ctx = eth_ctx->dsa_switch_ctx;
24 
25 	if (port_idx < 0 || port_idx >= dsa_switch_ctx->num_ports) {
26 		return NULL;
27 	}
28 
29 	return dsa_switch_ctx->iface_user[port_idx];
30 }
31