net/bridge/br_mrp_switchdev.c
Source file repositories/reference/linux-study-clean/net/bridge/br_mrp_switchdev.c
File Facts
- System
- Linux kernel
- Corpus path
net/bridge/br_mrp_switchdev.c- Extension
.c- Size
- 5924 bytes
- Lines
- 242
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: implementation source
- Status
- source implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
net/switchdev.hbr_private_mrp.h
Detected Declarations
function br_mrp_switchdev_port_objfunction br_mrp_switchdev_addfunction br_mrp_switchdev_delfunction br_mrp_switchdev_set_ring_rolefunction br_mrp_switchdev_send_ring_testfunction br_mrp_switchdev_set_ring_statefunction br_mrp_switchdev_set_in_rolefunction br_mrp_switchdev_set_in_statefunction br_mrp_switchdev_send_in_testfunction br_mrp_port_switchdev_set_statefunction br_mrp_port_switchdev_set_role
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
#include <net/switchdev.h>
#include "br_private_mrp.h"
static enum br_mrp_hw_support
br_mrp_switchdev_port_obj(struct net_bridge *br,
const struct switchdev_obj *obj, bool add)
{
int err;
if (add)
err = switchdev_port_obj_add(br->dev, obj, NULL);
else
err = switchdev_port_obj_del(br->dev, obj);
/* In case of success just return and notify the SW that doesn't need
* to do anything
*/
if (!err)
return BR_MRP_HW;
if (err != -EOPNOTSUPP)
return BR_MRP_NONE;
/* Continue with SW backup */
return BR_MRP_SW;
}
int br_mrp_switchdev_add(struct net_bridge *br, struct br_mrp *mrp)
{
struct switchdev_obj_mrp mrp_obj = {
.obj.orig_dev = br->dev,
.obj.id = SWITCHDEV_OBJ_ID_MRP,
.p_port = rtnl_dereference(mrp->p_port)->dev,
.s_port = rtnl_dereference(mrp->s_port)->dev,
.ring_id = mrp->ring_id,
.prio = mrp->prio,
};
if (!IS_ENABLED(CONFIG_NET_SWITCHDEV))
return 0;
return switchdev_port_obj_add(br->dev, &mrp_obj.obj, NULL);
}
int br_mrp_switchdev_del(struct net_bridge *br, struct br_mrp *mrp)
{
struct switchdev_obj_mrp mrp_obj = {
.obj.orig_dev = br->dev,
.obj.id = SWITCHDEV_OBJ_ID_MRP,
.p_port = NULL,
.s_port = NULL,
.ring_id = mrp->ring_id,
};
if (!IS_ENABLED(CONFIG_NET_SWITCHDEV))
return 0;
return switchdev_port_obj_del(br->dev, &mrp_obj.obj);
}
enum br_mrp_hw_support
br_mrp_switchdev_set_ring_role(struct net_bridge *br, struct br_mrp *mrp,
enum br_mrp_ring_role_type role)
{
struct switchdev_obj_ring_role_mrp mrp_role = {
.obj.orig_dev = br->dev,
.obj.id = SWITCHDEV_OBJ_ID_RING_ROLE_MRP,
.ring_role = role,
.ring_id = mrp->ring_id,
.sw_backup = false,
};
enum br_mrp_hw_support support;
int err;
if (!IS_ENABLED(CONFIG_NET_SWITCHDEV))
return BR_MRP_SW;
support = br_mrp_switchdev_port_obj(br, &mrp_role.obj,
role != BR_MRP_RING_ROLE_DISABLED);
if (support != BR_MRP_SW)
return support;
/* If the driver can't configure to run completely the protocol in HW,
* then try again to configure the HW so the SW can run the protocol.
*/
mrp_role.sw_backup = true;
if (role != BR_MRP_RING_ROLE_DISABLED)
Annotation
- Immediate include surface: `net/switchdev.h`, `br_private_mrp.h`.
- Detected declarations: `function br_mrp_switchdev_port_obj`, `function br_mrp_switchdev_add`, `function br_mrp_switchdev_del`, `function br_mrp_switchdev_set_ring_role`, `function br_mrp_switchdev_send_ring_test`, `function br_mrp_switchdev_set_ring_state`, `function br_mrp_switchdev_set_in_role`, `function br_mrp_switchdev_set_in_state`, `function br_mrp_switchdev_send_in_test`, `function br_mrp_port_switchdev_set_state`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.