From patchwork Wed Feb 25 15:24:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 443438 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 B11B91400B6 for ; Thu, 26 Feb 2015 02:24:50 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="verification failed; unprotected key" header.d=gmail.com header.i=@gmail.com header.b=AqG0sKPF; dkim-adsp=none (unprotected policy); dkim-atps=neutral Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 8610628C155; Wed, 25 Feb 2015 16:24:34 +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 AF10D28C155 for ; Wed, 25 Feb 2015 16:24:25 +0100 (CET) X-policyd-weight: using cached result; rate: -8.5 Received: from mail-wi0-f172.google.com (mail-wi0-f172.google.com [209.85.212.172]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Wed, 25 Feb 2015 16:24:23 +0100 (CET) Received: by mail-wi0-f172.google.com with SMTP id l15so34132849wiw.5 for ; Wed, 25 Feb 2015 07:24:32 -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=GDN5hC1HhqNydoP7+vsxOrhc30vZiwIhnGsb+lzoNGg=; b=AqG0sKPFu60h9PZaiRHfro3g6CFjIg+prtaNgTQjk2Dt2mkVljocba+n4SIuM8FLF/ ghGi5cC4esasuu0lPDbqnFhO8szwN00x1Vr2iEUCtMSd1F3Dkl9m0KPHzDFJB/leJO2V BsRILSWOFwKcsAS1Y9Xl0gYVZ1MJIrJgCBTlSZb8HKdrmw9wDtlSK3pVak1HCiUm8Q5c 6UCpPHPT55389JzzNHPZInkq3mA8HodUubbWa7BrPqvShQYn+juRnNsAWK71+oFEkNSP pxDb+P5ZKovkGzHaX0YgIrWjc4mfnJQhJsCrYRL29PwTYGBh6+aU1OH199xCog5mKJu5 WaNQ== X-Received: by 10.180.73.205 with SMTP id n13mr7339504wiv.64.1424877872646; Wed, 25 Feb 2015 07:24:32 -0800 (PST) Received: from orion.local ([194.105.29.179]) by mx.google.com with ESMTPSA id j9sm65270756wjy.18.2015.02.25.07.24.32 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 25 Feb 2015 07:24:32 -0800 (PST) From: Alexandru Ardelean To: openwrt-devel@lists.openwrt.org Date: Wed, 25 Feb 2015 17:24:22 +0200 Message-Id: <1424877864-30726-1-git-send-email-ardeleanalex@gmail.com> X-Mailer: git-send-email 2.1.2 Subject: [OpenWrt-Devel] [PATCH 1/3] b53: add swconfig logic to enable/disable management 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" Feature implemented and tested on BCM53128. This enables the Managed Mode of the b53 switch. Two things need setup after the managed mode bit is set. - The CPU port needs to be explicitly enabled. CPU ports seems disabled by default when managed mode is enabled - The Broadcom Tag/Header needs to be explicitly disabled. When managed mode is enabled, frames seem to include tag bytes when sent to the CPU, because the tag is enabled by default. After it's enabled, it will behave like unmanaged modei plus some extra behaviour. In unmanaged mode, the switch chip tries to be smart about dropping some frames based on IEEE standards. Specifically regarding reserved multicast addresses that get dropped in unmanaged mode. Signed-off-by: Alexandru Ardelean --- .../generic/files/drivers/net/phy/b53/b53_common.c | 55 ++++++++++++++++++++++ .../generic/files/drivers/net/phy/b53/b53_priv.h | 1 + .../generic/files/drivers/net/phy/b53/b53_regs.h | 4 ++ 3 files changed, 60 insertions(+) diff --git a/target/linux/generic/files/drivers/net/phy/b53/b53_common.c b/target/linux/generic/files/drivers/net/phy/b53/b53_common.c index fd1e78a..a7093ee 100644 --- a/target/linux/generic/files/drivers/net/phy/b53/b53_common.c +++ b/target/linux/generic/files/drivers/net/phy/b53/b53_common.c @@ -317,6 +317,29 @@ static void b53_enable_vlan(struct b53_device *dev, int enable) b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt); } +static void b53_enable_management(struct b53_device *dev) +{ + u8 mgmt, gc; + u8 brcm_hdr_ctrl; + + /* Management has been disabled by by clearing the SM_SW_FWD_MODE bit + * in b53_enable_vlan() or b53_reset_switch() */ + if (!dev->enable_management) + return; + b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt); + b53_read8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, &gc); + b53_read8(dev, B53_MGMT_PAGE, B53_BRCM_HDR_CTRL, &brcm_hdr_ctrl); + + mgmt |= SM_SW_FWD_MODE; + gc |= GC_FRM_MGMT_PORT_MII; + /* Chip inserts tag in frame when managed mode is on; not needed yet */ + brcm_hdr_ctrl &= ~B53_BRCM_HDR_EN; + + b53_write8(dev, B53_CTRL_PAGE, B53_BRCM_HDR_CTRL, brcm_hdr_ctrl); + b53_write8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, gc); + b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt); +} + static int b53_set_jumbo(struct b53_device *dev, int enable, int allow_10_100) { u32 port_mask = 0; @@ -669,6 +692,7 @@ static int b53_apply(struct b53_device *dev) if (!is5325(dev) && !is5365(dev)) b53_set_jumbo(dev, dev->enable_jumbo, 1); + b53_enable_management(dev); return 0; } @@ -1320,6 +1344,28 @@ static int b53_port_get_link(struct switch_dev *dev, int port, } +static int b53_global_get_management(struct switch_dev *dev, + const struct switch_attr *attr, + struct switch_val *val) +{ + struct b53_device *priv = sw_to_b53(dev); + + val->value.i = priv->enable_management; + + return 0; +} + +static int b53_global_set_management(struct switch_dev *dev, + const struct switch_attr *attr, + struct switch_val *val) +{ + struct b53_device *priv = sw_to_b53(dev); + + priv->enable_management = val->value.i; + + return 0; +} + static int b53_global_reset_switch(struct switch_dev *dev) { struct b53_device *priv = sw_to_b53(dev); @@ -1328,6 +1374,7 @@ static int b53_global_reset_switch(struct switch_dev *dev) priv->enable_vlan = 0; priv->enable_jumbo = 0; priv->allow_vid_4095 = 0; + priv->enable_management = 0; memset(priv->vlans, 0, sizeof(priv->vlans) * dev->vlans); memset(priv->ports, 0, sizeof(priv->ports) * dev->ports); @@ -1495,6 +1542,14 @@ static struct switch_attr b53_global_ops[] = { .get = b53_global_get_4095_enable, .max = 1, }, + { + .type = SWITCH_TYPE_INT, + .name = "enable_management", + .description = "Enable Management", + .set = b53_global_set_management, + .get = b53_global_get_management, + .max = 1, + }, #ifdef CONFIG_B53_HW_DEBUG_FEATURES { .type = SWITCH_TYPE_STRING, diff --git a/target/linux/generic/files/drivers/net/phy/b53/b53_priv.h b/target/linux/generic/files/drivers/net/phy/b53/b53_priv.h index 395a76c..15df201 100644 --- a/target/linux/generic/files/drivers/net/phy/b53/b53_priv.h +++ b/target/linux/generic/files/drivers/net/phy/b53/b53_priv.h @@ -130,6 +130,7 @@ struct b53_device { unsigned enable_vlan:1; unsigned enable_jumbo:1; unsigned allow_vid_4095:1; + unsigned enable_management:1; #ifdef CONFIG_B53_HW_DEBUG_FEATURES struct { unsigned enable:1; diff --git a/target/linux/generic/files/drivers/net/phy/b53/b53_regs.h b/target/linux/generic/files/drivers/net/phy/b53/b53_regs.h index 33a763c..c429fd3 100644 --- a/target/linux/generic/files/drivers/net/phy/b53/b53_regs.h +++ b/target/linux/generic/files/drivers/net/phy/b53/b53_regs.h @@ -166,6 +166,10 @@ static inline u64 b53_mac_array_to_u64(const u8 *u8_arr) { #define GC_FRM_MGMT_PORT_04 0x00 #define GC_FRM_MGMT_PORT_MII 0x80 +/* Broadcom Header Control Register (8 bit) */ +#define B53_BRCM_HDR_CTRL 0x03 +#define B53_BRCM_HDR_EN BIT(0) + /* Mirror Capture Control Register (16 bit) */ #define B53_MIRROR_CTRL 0x10 #define B53_CAP_PORT_SET(r,p) (r = (r & ~0x0f) | (p & 0x0f))