Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp215261ybz; Tue, 21 Apr 2020 07:44:53 -0700 (PDT) X-Google-Smtp-Source: APiQypIskAKYDr32TRW6YP5Mv6TRWsy4snM1vLOsSd42COl0dLeSZYrg5hSH5SE3qESf8JdVOXU8 X-Received: by 2002:a17:906:b253:: with SMTP id ce19mr22701210ejb.341.1587480292811; Tue, 21 Apr 2020 07:44:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587480292; cv=none; d=google.com; s=arc-20160816; b=bfLt2EWXbQHyiDbiBjzTxVV3wSKOijxebjWCQ6Jwmb+3ZC+nmVocy+QHZqWH540P32 vsGzXGKVIztWJKBDXaZUu+qAeZBzP4QELiAKJg44FDMjFb/EIDyvhWi9tS17zalkTuEg 26gZAl1IO38Om1nEn3v5aibaWhwWYVLlYJrr2O2/bti/DajO7S18PUVlA5wGRrsxcQOV B1/HLhpWYB29XSzfp6VVBuJgp0Awyb6SPN781gJtBkCQ1IUrKtYHYnkDvxSElT78cGZo TIiQ8X35hYz3v9bfAFxKcZdVQMA29XbV9/4mrvF0SjFxGSTLNzXkDzRW0d0zFRoz9Nuk vXlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:ironport-sdr:dkim-signature; bh=XqPCOhU/kpjbKd6+Gm1Hah9Db7CsZ1pqkqsLcHtopXY=; b=tSd9TzuU5zabyZ/B+/3y996x50Y1vcbnJ4O9CJC7izox+AYe67b9qynGPiVzgDa+aQ 645FeT4XZkVWdPMw2L/mbrC3fC8XXV5Tc/c6pYeAKyhvumvIUyZattDewJOM1bwuhvU8 s8JpTQTYydcZALzlUJ8J7VrBZjT9dO+XQHBMVurS5L/r0lneGcmBbipvBrivFtFDUDyB PypgH9q5DZd4qEK55+a4vc1ydt1o/oVmk+ecspmlynEHLfgqCZA8r2lu9V5lWJts/dvh D9bYWTZ9CPd4rdchffmWBLkCQjE8jxPgZ9WIHtbXSSBzLq1nN2qb3bj7sspRpqjhCIFL F69g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@microchip.com header.s=mchp header.b=zxH3t+dC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=microchip.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qh13si1812283ejb.438.2020.04.21.07.44.29; Tue, 21 Apr 2020 07:44:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@microchip.com header.s=mchp header.b=zxH3t+dC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729287AbgDUOnJ (ORCPT + 99 others); Tue, 21 Apr 2020 10:43:09 -0400 Received: from esa2.microchip.iphmx.com ([68.232.149.84]:61621 "EHLO esa2.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729215AbgDUOnA (ORCPT ); Tue, 21 Apr 2020 10:43:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1587480179; x=1619016179; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=Hc+MoQCsZ+0eHVVASI3piUCCfhXhUcDloOdjWoWOcAA=; b=zxH3t+dCH3ShXgCxKilIggNhOi7VVIcmQZnG6ggzzDyOjkEOTaXzFyJp Hz1ne/ZH5gXz70AguDKxbWakWCfMfZtiTNXp/bzSHAMs6BOBOS87UEdAP kx6Bxy7EZd4rzTsBXPMXVmrIUhJzLLIPvDS+ckcT6wU1wVOMjp8einK+U N0OZYAf8bv56dlcrpmPcD4TwOcsxNgVs13l3K8jpBzwgWPt64TDcFcFZI ZZa1fwHbBc13P2WqLh5yv2HZHGXHKiN6PixFy9zKCIe1HpzBNOCd6vw1l orL8EAw4dp1hHKt4jRNfjnfcHch3dfn1we0Dv2P+Oqh34ARqoymXHCWHa Q==; IronPort-SDR: rn5KX+oB4lCvJyS4nmxKjNmv5Pa43PwIpy6lYFqdR7nlgZf0G7lT3dDP3s5CAiDjrMDMvWRCQm OGd01CzlIR2d6xTg75b8a57y8ZIdfFH6xgNhV+DpSSVVsZamqlv2E1wWaPlkCM910UKqI6NPed efenUP/TFM3YtLBbc9hf8oYe+234keJOJefOLIAGiWn8K966Gs85EZH7BQJS4FHu2kmSlAsyV7 KqHL0424fCUmgFHtYYOYzMHOtSD0LA2rTEyh1Q6MlJrO2j1UWTlNunaQ+jroclnTYqFKP7O3PY SPE= X-IronPort-AV: E=Sophos;i="5.72,410,1580799600"; d="scan'208";a="72862656" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 21 Apr 2020 07:42:59 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Tue, 21 Apr 2020 07:42:58 -0700 Received: from soft-dev3.microsemi.net (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.1713.5 via Frontend Transport; Tue, 21 Apr 2020 07:42:56 -0700 From: Horatiu Vultur To: , , , , , , , , , , , CC: Horatiu Vultur Subject: [PATCH net-next v2 07/11] bridge: switchdev: mrp: Implement MRP API for switchdev Date: Tue, 21 Apr 2020 16:37:48 +0200 Message-ID: <20200421143752.2248-8-horatiu.vultur@microchip.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200421143752.2248-1-horatiu.vultur@microchip.com> References: <20200421143752.2248-1-horatiu.vultur@microchip.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Implement the MRP api for switchdev. These functions will just eventually call the switchdev functions: switchdev_port_obj_add/del and switchdev_port_attr_set. Signed-off-by: Horatiu Vultur --- net/bridge/Makefile | 2 + net/bridge/br_mrp_switchdev.c | 141 ++++++++++++++++++++++++++++++++++ 2 files changed, 143 insertions(+) create mode 100644 net/bridge/br_mrp_switchdev.c diff --git a/net/bridge/Makefile b/net/bridge/Makefile index 49da7ae6f077..3cacf9dd78d5 100644 --- a/net/bridge/Makefile +++ b/net/bridge/Makefile @@ -25,3 +25,5 @@ bridge-$(CONFIG_BRIDGE_VLAN_FILTERING) += br_vlan.o br_vlan_tunnel.o br_vlan_opt bridge-$(CONFIG_NET_SWITCHDEV) += br_switchdev.o obj-$(CONFIG_NETFILTER) += netfilter/ + +bridge-$(CONFIG_BRIDGE_MRP) += br_mrp_switchdev.o diff --git a/net/bridge/br_mrp_switchdev.c b/net/bridge/br_mrp_switchdev.c new file mode 100644 index 000000000000..6ece7817c757 --- /dev/null +++ b/net/bridge/br_mrp_switchdev.c @@ -0,0 +1,141 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include + +#include "br_private_mrp.h" + +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, + }; + int err; + + err = switchdev_port_obj_add(br->dev, &mrp_obj.obj, NULL); + + if (err && err != -EOPNOTSUPP) + return err; + + return 0; +} + +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, + }; + int err; + + err = switchdev_port_obj_del(br->dev, &mrp_obj.obj); + + if (err && err != -EOPNOTSUPP) + return err; + + return 0; +} + +int 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, + }; + int err; + + if (role == BR_MRP_RING_ROLE_DISABLED) + err = switchdev_port_obj_del(br->dev, &mrp_role.obj); + else + err = switchdev_port_obj_add(br->dev, &mrp_role.obj, NULL); + + return err; +} + +int br_mrp_switchdev_send_ring_test(struct net_bridge *br, + struct br_mrp *mrp, u32 interval, + u8 max_miss, u32 period) +{ + struct switchdev_obj_ring_test_mrp test = { + .obj.orig_dev = br->dev, + .obj.id = SWITCHDEV_OBJ_ID_RING_TEST_MRP, + .interval = interval, + .max_miss = max_miss, + .ring_id = mrp->ring_id, + .period = period, + }; + int err; + + if (interval == 0) + err = switchdev_port_obj_del(br->dev, &test.obj); + else + err = switchdev_port_obj_add(br->dev, &test.obj, NULL); + + return err; +} + +int br_mrp_switchdev_set_ring_state(struct net_bridge *br, + struct br_mrp *mrp, + enum br_mrp_ring_state_type state) +{ + struct switchdev_obj_ring_state_mrp mrp_state = { + .obj.orig_dev = br->dev, + .obj.id = SWITCHDEV_OBJ_ID_RING_STATE_MRP, + .ring_state = state, + .ring_id = mrp->ring_id, + }; + int err; + + err = switchdev_port_obj_add(br->dev, &mrp_state.obj, NULL); + + if (err && err != -EOPNOTSUPP) + return err; + + return 0; +} + +int br_mrp_port_switchdev_set_state(struct net_bridge_port *p, + enum br_mrp_port_state_type state) +{ + struct switchdev_attr attr = { + .orig_dev = p->dev, + .id = SWITCHDEV_ATTR_ID_MRP_PORT_STATE, + .u.mrp_port_state = state, + }; + int err; + + err = switchdev_port_attr_set(p->dev, &attr); + if (err && err != -EOPNOTSUPP) + br_warn(p->br, "error setting offload MRP state on port %u(%s)\n", + (unsigned int)p->port_no, p->dev->name); + + return err; +} + +int br_mrp_port_switchdev_set_role(struct net_bridge_port *p, + enum br_mrp_port_role_type role) +{ + struct switchdev_attr attr = { + .orig_dev = p->dev, + .id = SWITCHDEV_ATTR_ID_MRP_PORT_ROLE, + .u.mrp_port_role = role, + }; + int err; + + err = switchdev_port_attr_set(p->dev, &attr); + if (err && err != -EOPNOTSUPP) + return err; + + return 0; +} + -- 2.17.1