From patchwork Fri Feb 13 19:10:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 439616 X-Patchwork-Delegate: jogo@openwrt.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id DC41F1401AF for ; Sat, 14 Feb 2015 06:11:00 +1100 (AEDT) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id BE07B28A677; Fri, 13 Feb 2015 20:08:15 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID autolearn=unavailable version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 7FE6128A677 for ; Fri, 13 Feb 2015 20:08:11 +0100 (CET) X-policyd-weight: using cached result; rate: -8.5 Received: from mail-wg0-f41.google.com (mail-wg0-f41.google.com [74.125.82.41]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Fri, 13 Feb 2015 20:08:11 +0100 (CET) Received: by mail-wg0-f41.google.com with SMTP id b13so18633783wgh.0 for ; Fri, 13 Feb 2015 11:10:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=HXnAjpzKRPSxtUWylsmrsaZCAnwugBES4x4O+7ytWfU=; b=Y4f6DM93fqb7NY7hy/NE6AtJiZVRiIWtteRhCT5I7C8sfXrklT1SAuTP8E/MRDX9vn Pr9Q0OnkB5xZQ0k8U/BDegqa+fXhnzj4UkglLpBp4Jy28Ar2qkPH08fWBuIM8mHxfF36 tmHlWl+Flf36ceeXLpvO0Ys5DtsINL77gP4K2Qd4KgF+xzK0wpO2MsE285RDcQRYfH4p 37SCJR1Werh2CHn14/8VJRTXyOAreNfCZMXAXj1OjZnnHLq8mQ+/v0GXXgENdLphBpWW F+MLK1ISewHNychkEbqu5hEzMzy9W8mVCLeh880pmj1G4HwbWsvUuvOMkMEAULXS3+Qz ztMg== X-Received: by 10.194.2.75 with SMTP id 11mr21266059wjs.78.1423854650750; Fri, 13 Feb 2015 11:10:50 -0800 (PST) Received: from linux-kkns.site ([188.24.73.24]) by mx.google.com with ESMTPSA id e4sm11194287wjw.48.2015.02.13.11.10.49 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Feb 2015 11:10:50 -0800 (PST) From: Alexandru Ardelean To: openwrt-devel@lists.openwrt.org Date: Fri, 13 Feb 2015 21:10:24 +0200 Message-Id: <1423854624-7631-1-git-send-email-ardeleanalex@gmail.com> X-Mailer: git-send-email 1.8.4.5 Subject: [OpenWrt-Devel] [PATCH] b53: Allow to enable/disable port protection for b53 switch X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" From: Helmut Schaa Signed-off-by: Helmut Schaa --- .../generic/files/drivers/net/phy/b53/b53_common.c | 44 ++++++++++++++++++++++ .../generic/files/drivers/net/phy/b53/b53_priv.h | 1 + .../generic/files/drivers/net/phy/b53/b53_regs.h | 3 ++ 3 files changed, 48 insertions(+) diff --git a/openwrt/target/linux/generic/files/drivers/net/phy/b53/b53_common.c b/openwrt/target/linux/generic/files/drivers/net/phy/b53/b53_common.c index b82bc93..e4cfc29 100644 --- a/openwrt/target/linux/generic/files/drivers/net/phy/b53/b53_common.c +++ b/openwrt/target/linux/generic/files/drivers/net/phy/b53/b53_common.c @@ -363,6 +363,7 @@ static int b53_flush_arl(struct b53_device *dev) static void b53_enable_ports(struct b53_device *dev) { unsigned i; + u16 protected = 0; b53_for_each_port(dev, i) { u8 port_ctrl; @@ -401,7 +402,13 @@ static void b53_enable_ports(struct b53_device *dev) if (!is63xx(dev) && !(is5301x(dev) && i == 6)) b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(i), port_ctrl); + + /* Enable/disable port protection */ + if (dev->ports[i].protected) + protected |= BIT(i); } + + b53_write16(dev, B53_CTRL_PAGE, B53_PROTECTED_PORT_SELECTION, protected); } static void b53_enable_mib(struct b53_device *dev) @@ -862,6 +869,35 @@ static int b53_port_get_mib(struct switch_dev *sw_dev, return 0; } +static int b53_port_get_protected(struct switch_dev *sw_dev, + const struct switch_attr *attr, + struct switch_val *val) +{ + struct b53_device *dev = sw_to_b53(sw_dev); + int port = val->port_vlan; + + if (!(BIT(port) & dev->enabled_ports)) + return -1; + + val->value.i = !!(dev->ports[port].protected); + + return 0; +} + +static int b53_port_set_protected(struct switch_dev *sw_dev, + const struct switch_attr *attr, + struct switch_val *val) +{ + struct b53_device *dev = sw_to_b53(sw_dev); + int port = val->port_vlan; + + if (!(BIT(port) & dev->enabled_ports)) + return -1; + + dev->ports[port].protected = !!(val->value.i); + return 0; +} + static struct switch_attr b53_global_ops_25[] = { { .type = SWITCH_TYPE_INT, @@ -948,6 +984,14 @@ static struct switch_attr b53_port_ops[] = { .description = "Get port's MIB counters", .get = b53_port_get_mib, }, + { + .type = SWITCH_TYPE_INT, + .name = "protected", + .description = "Enable protected mode", + .set = b53_port_set_protected, + .get = b53_port_get_protected, + .max = 1, + }, }; static struct switch_attr b53_no_ops[] = { diff --git a/openwrt/target/linux/generic/files/drivers/net/phy/b53/b53_priv.h b/openwrt/target/linux/generic/files/drivers/net/phy/b53/b53_priv.h index ce5b530..87ecbb5 100644 --- a/openwrt/target/linux/generic/files/drivers/net/phy/b53/b53_priv.h +++ b/openwrt/target/linux/generic/files/drivers/net/phy/b53/b53_priv.h @@ -65,6 +65,7 @@ struct b53_vlan { struct b53_port { unsigned int pvid:12; + unsigned int protected:1; }; struct b53_device { diff --git a/openwrt/target/linux/generic/files/drivers/net/phy/b53/b53_regs.h b/openwrt/target/linux/generic/files/drivers/net/phy/b53/b53_regs.h index ba50915..0f5b2cb 100644 --- a/openwrt/target/linux/generic/files/drivers/net/phy/b53/b53_regs.h +++ b/openwrt/target/linux/generic/files/drivers/net/phy/b53/b53_regs.h @@ -95,6 +95,9 @@ #define B53_MC_FWD_EN BIT(7) /* (16 bit) */ +#define B53_PROTECTED_PORT_SELECTION 0x24 + +/* (16 bit) */ #define B53_UC_FLOOD_MASK 0x32 #define B53_MC_FLOOD_MASK 0x34 #define B53_IPMC_FLOOD_MASK 0x36