net: dsa: support dsa protocol registering with iterable section
Supported dsa protocol registering with iterable section. Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
This commit is contained in:
committed by
Fabio Baltieri
parent
d9d46c0ce3
commit
1b14cb18a2
@@ -240,6 +240,10 @@ if(CONFIG_NET_SOCKETS_SERVICE)
|
||||
)
|
||||
endif()
|
||||
|
||||
if(CONFIG_NET_DSA)
|
||||
zephyr_iterable_section(NAME dsa_tag_register KVMA RAM_REGION GROUP RODATA_REGION)
|
||||
endif()
|
||||
|
||||
if(CONFIG_INPUT)
|
||||
zephyr_iterable_section(NAME input_callback KVMA RAM_REGION GROUP RODATA_REGION)
|
||||
endif()
|
||||
|
||||
@@ -33,3 +33,7 @@
|
||||
#if defined(CONFIG_NET_SOCKETS_SERVICE)
|
||||
ITERABLE_SECTION_ROM(net_socket_service_desc, Z_LINK_ITERABLE_SUBALIGN)
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_NET_DSA)
|
||||
ITERABLE_SECTION_ROM(dsa_tag_register, Z_LINK_ITERABLE_SUBALIGN)
|
||||
#endif
|
||||
|
||||
@@ -21,14 +21,32 @@
|
||||
*/
|
||||
|
||||
#include <zephyr/dt-bindings/ethernet/dsa_tag_proto.h>
|
||||
#ifdef CONFIG_DSA_TAG_PROTOCOL_NETC
|
||||
#include <zephyr/net/dsa_tag_netc.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Registration information for a dsa tag protocol
|
||||
*/
|
||||
struct dsa_tag_register {
|
||||
/** Protocol ID */
|
||||
int proto;
|
||||
|
||||
/** Received packet handler */
|
||||
struct net_if *(*recv)(struct net_if *iface, struct net_pkt *pkt);
|
||||
|
||||
/** Transmit packet handler */
|
||||
struct net_pkt *(*xmit)(struct net_if *iface, struct net_pkt *pkt);
|
||||
};
|
||||
|
||||
#define DSA_TAG_REGISTER(_proto, _recv, _xmit) \
|
||||
static const STRUCT_SECTION_ITERABLE(dsa_tag_register, __dsa_tag_register_##_proto) = { \
|
||||
.proto = _proto, \
|
||||
.recv = _recv, \
|
||||
.xmit = _xmit, \
|
||||
}
|
||||
|
||||
/** @cond INTERNAL_HIDDEN */
|
||||
|
||||
/*
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
/*
|
||||
* Copyright 2025 NXP
|
||||
*
|
||||
* SPDX-FileCopyrightText: Copyright 2025-2026 NXP
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef ZEPHYR_SUBSYS_DSA_TAG_NETC_H_
|
||||
@@ -13,6 +12,4 @@ struct dsa_tag_netc_data {
|
||||
#endif
|
||||
};
|
||||
|
||||
struct net_if *dsa_tag_netc_recv(struct net_if *iface, struct net_pkt *pkt);
|
||||
struct net_pkt *dsa_tag_netc_xmit(struct net_if *iface, struct net_pkt *pkt);
|
||||
#endif /* ZEPHYR_SUBSYS_DSA_TAG_NETC_H_ */
|
||||
|
||||
@@ -44,19 +44,18 @@ void dsa_tag_setup(const struct device *dev_cpu)
|
||||
{
|
||||
const struct dsa_port_config *cfg = dev_cpu->config;
|
||||
struct dsa_switch_context *dsa_switch_ctx = dev_cpu->data;
|
||||
bool match = false;
|
||||
|
||||
switch (cfg->tag_proto) {
|
||||
#ifdef CONFIG_DSA_TAG_PROTOCOL_NETC
|
||||
case DSA_TAG_PROTO_NETC:
|
||||
dsa_switch_ctx->dapi->recv = dsa_tag_netc_recv;
|
||||
dsa_switch_ctx->dapi->xmit = dsa_tag_netc_xmit;
|
||||
break;
|
||||
#endif
|
||||
case DSA_TAG_PROTO_NOTAG:
|
||||
dsa_switch_ctx->dapi->recv = NULL;
|
||||
dsa_switch_ctx->dapi->xmit = NULL;
|
||||
break;
|
||||
default:
|
||||
STRUCT_SECTION_FOREACH(dsa_tag_register, tag) {
|
||||
if (tag->proto == cfg->tag_proto) {
|
||||
dsa_switch_ctx->dapi->recv = tag->recv;
|
||||
dsa_switch_ctx->dapi->xmit = tag->xmit;
|
||||
match = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ((!match) && (cfg->tag_proto != DSA_TAG_PROTO_NOTAG)) {
|
||||
LOG_ERR("DSA tag protocol %d not supported", cfg->tag_proto);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
/*
|
||||
* Copyright 2025 NXP
|
||||
*
|
||||
* SPDX-FileCopyrightText: Copyright 2025-2026 NXP
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
@@ -9,6 +8,7 @@ LOG_MODULE_REGISTER(net_dsa_tag_netc, CONFIG_NET_DSA_LOG_LEVEL);
|
||||
|
||||
#include <zephyr/net/ethernet.h>
|
||||
#include <zephyr/net/dsa_core.h>
|
||||
#include <zephyr/net/dsa_tag.h>
|
||||
#include <zephyr/net/dsa_tag_netc.h>
|
||||
#include "fsl_netc_tag.h"
|
||||
|
||||
@@ -157,3 +157,5 @@ struct net_pkt *dsa_tag_netc_xmit(struct net_if *iface, struct net_pkt *pkt)
|
||||
net_pkt_cursor_init(pkt);
|
||||
return pkt;
|
||||
}
|
||||
|
||||
DSA_TAG_REGISTER(DSA_TAG_PROTO_NETC, dsa_tag_netc_recv, dsa_tag_netc_xmit);
|
||||
|
||||
Reference in New Issue
Block a user