From patchwork Mon Dec 13 10:14:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Horatiu Vultur X-Patchwork-Id: 12673601 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D3B3C433EF for ; Mon, 13 Dec 2021 10:19:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237720AbhLMKTG (ORCPT ); Mon, 13 Dec 2021 05:19:06 -0500 Received: from esa.microchip.iphmx.com ([68.232.153.233]:3448 "EHLO esa.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243972AbhLMKPB (ORCPT ); Mon, 13 Dec 2021 05:15:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1639390500; x=1670926500; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CT7jtIkme9AhFMoPO9xaJSjN1ls35Idn183GYh+dElo=; b=Q02coIZS/t1e5rHb3870i+QEKPsLpPNm8aN6w8u/Z14ffel4C0FR8guQ OjZAuS68S7ASO+cnKQc4vlz6iSRvzIbA6edJCkfFqCkt0yeigAnX+tAqT 56sHuL2iYRFDL5+BK3dG5d3bTUR4mZPVRQAqg2oYt2aYtmELHm0QVErG1 5c0cdfoE4239JTTWww14cF1KVgFXGb8xMeK8iMPr3zsCnXIwhn0H3YzWE o0zvRGAz5aYRDeMzgBjWxlZgllQ+if0gv4hHwO3q4jzyTGb1jFHGkCd/2 jDQ49JOT1ktbakCMEk8UIOVeX1/nvY99X6ZTVUmQrCV+USp5+hGWt06Hb Q==; IronPort-SDR: Gus5mUqA6q4Ae0kicWKcQQdrOKnn/Vm2ktLSq5tD1xYYx13Y+v6DX1Eit0G0SCqwcUTLVH0ROA tle17Pr7PnAhs6L1YQ7Fwo6ncErJs/+L6ClX1LgC7rplBqCEzyMIEFxp4vZQwQnGnYx4g0FOvp p+j0UBpJkAGiRU1EWGHBTXOhRZTniXRlG307gqyIPdmtUEFrG4vdS74EyfjMgD1ZpatfqE/fzx 9YYP11morZ3tPljrBYQStCdKP97HoSYuu/Fn+O9qCN+fPAEwemqdUCbqN2PLKxyPXA+HkxYPGm R9KPEZz6HvT/zcXT5rcrfJf7 X-IronPort-AV: E=Sophos;i="5.88,202,1635231600"; d="scan'208";a="147013373" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa3.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 13 Dec 2021 03:14:57 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 13 Dec 2021 03:14:57 -0700 Received: from soft-dev3-1.microsemi.net (10.10.115.15) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Mon, 13 Dec 2021 03:14:54 -0700 From: Horatiu Vultur To: , , CC: , , , , , , , , , Horatiu Vultur Subject: [PATCH net-next v4 01/10] net: lan966x: Add registers that are used for switch and vlan functionality Date: Mon, 13 Dec 2021 11:14:23 +0100 Message-ID: <20211213101432.2668820-2-horatiu.vultur@microchip.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211213101432.2668820-1-horatiu.vultur@microchip.com> References: <20211213101432.2668820-1-horatiu.vultur@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org This patch adds the registers that will be used to enable switchdev and vlan functionality in the HW. Signed-off-by: Horatiu Vultur --- .../ethernet/microchip/lan966x/lan966x_regs.h | 129 ++++++++++++++++++ 1 file changed, 129 insertions(+) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_regs.h b/drivers/net/ethernet/microchip/lan966x/lan966x_regs.h index 879dcd807dec..2f2b26b9f8c6 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_regs.h +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_regs.h @@ -61,6 +61,9 @@ enum lan966x_target { #define ANA_ADVLEARN_VLAN_CHK_GET(x)\ FIELD_GET(ANA_ADVLEARN_VLAN_CHK, x) +/* ANA:ANA:VLANMASK */ +#define ANA_VLANMASK __REG(TARGET_ANA, 0, 1, 29824, 0, 1, 244, 8, 0, 1, 4) + /* ANA:ANA:ANAINTR */ #define ANA_ANAINTR __REG(TARGET_ANA, 0, 1, 29824, 0, 1, 244, 16, 0, 1, 4) @@ -184,6 +187,102 @@ enum lan966x_target { #define ANA_MACACCESS_MAC_TABLE_CMD_GET(x)\ FIELD_GET(ANA_MACACCESS_MAC_TABLE_CMD, x) +/* ANA:ANA_TABLES:MACTINDX */ +#define ANA_MACTINDX __REG(TARGET_ANA, 0, 1, 27520, 0, 1, 128, 52, 0, 1, 4) + +#define ANA_MACTINDX_BUCKET GENMASK(12, 11) +#define ANA_MACTINDX_BUCKET_SET(x)\ + FIELD_PREP(ANA_MACTINDX_BUCKET, x) +#define ANA_MACTINDX_BUCKET_GET(x)\ + FIELD_GET(ANA_MACTINDX_BUCKET, x) + +#define ANA_MACTINDX_M_INDEX GENMASK(10, 0) +#define ANA_MACTINDX_M_INDEX_SET(x)\ + FIELD_PREP(ANA_MACTINDX_M_INDEX, x) +#define ANA_MACTINDX_M_INDEX_GET(x)\ + FIELD_GET(ANA_MACTINDX_M_INDEX, x) + +/* ANA:ANA_TABLES:VLAN_PORT_MASK */ +#define ANA_VLAN_PORT_MASK __REG(TARGET_ANA, 0, 1, 27520, 0, 1, 128, 56, 0, 1, 4) + +#define ANA_VLAN_PORT_MASK_VLAN_PORT_MASK GENMASK(8, 0) +#define ANA_VLAN_PORT_MASK_VLAN_PORT_MASK_SET(x)\ + FIELD_PREP(ANA_VLAN_PORT_MASK_VLAN_PORT_MASK, x) +#define ANA_VLAN_PORT_MASK_VLAN_PORT_MASK_GET(x)\ + FIELD_GET(ANA_VLAN_PORT_MASK_VLAN_PORT_MASK, x) + +/* ANA:ANA_TABLES:VLANACCESS */ +#define ANA_VLANACCESS __REG(TARGET_ANA, 0, 1, 27520, 0, 1, 128, 60, 0, 1, 4) + +#define ANA_VLANACCESS_VLAN_TBL_CMD GENMASK(1, 0) +#define ANA_VLANACCESS_VLAN_TBL_CMD_SET(x)\ + FIELD_PREP(ANA_VLANACCESS_VLAN_TBL_CMD, x) +#define ANA_VLANACCESS_VLAN_TBL_CMD_GET(x)\ + FIELD_GET(ANA_VLANACCESS_VLAN_TBL_CMD, x) + +/* ANA:ANA_TABLES:VLANTIDX */ +#define ANA_VLANTIDX __REG(TARGET_ANA, 0, 1, 27520, 0, 1, 128, 64, 0, 1, 4) + +#define ANA_VLANTIDX_VLAN_PGID_CPU_DIS BIT(18) +#define ANA_VLANTIDX_VLAN_PGID_CPU_DIS_SET(x)\ + FIELD_PREP(ANA_VLANTIDX_VLAN_PGID_CPU_DIS, x) +#define ANA_VLANTIDX_VLAN_PGID_CPU_DIS_GET(x)\ + FIELD_GET(ANA_VLANTIDX_VLAN_PGID_CPU_DIS, x) + +#define ANA_VLANTIDX_V_INDEX GENMASK(11, 0) +#define ANA_VLANTIDX_V_INDEX_SET(x)\ + FIELD_PREP(ANA_VLANTIDX_V_INDEX, x) +#define ANA_VLANTIDX_V_INDEX_GET(x)\ + FIELD_GET(ANA_VLANTIDX_V_INDEX, x) + +/* ANA:PORT:VLAN_CFG */ +#define ANA_VLAN_CFG(g) __REG(TARGET_ANA, 0, 1, 28672, g, 9, 128, 0, 0, 1, 4) + +#define ANA_VLAN_CFG_VLAN_AWARE_ENA BIT(20) +#define ANA_VLAN_CFG_VLAN_AWARE_ENA_SET(x)\ + FIELD_PREP(ANA_VLAN_CFG_VLAN_AWARE_ENA, x) +#define ANA_VLAN_CFG_VLAN_AWARE_ENA_GET(x)\ + FIELD_GET(ANA_VLAN_CFG_VLAN_AWARE_ENA, x) + +#define ANA_VLAN_CFG_VLAN_POP_CNT GENMASK(19, 18) +#define ANA_VLAN_CFG_VLAN_POP_CNT_SET(x)\ + FIELD_PREP(ANA_VLAN_CFG_VLAN_POP_CNT, x) +#define ANA_VLAN_CFG_VLAN_POP_CNT_GET(x)\ + FIELD_GET(ANA_VLAN_CFG_VLAN_POP_CNT, x) + +#define ANA_VLAN_CFG_VLAN_VID GENMASK(11, 0) +#define ANA_VLAN_CFG_VLAN_VID_SET(x)\ + FIELD_PREP(ANA_VLAN_CFG_VLAN_VID, x) +#define ANA_VLAN_CFG_VLAN_VID_GET(x)\ + FIELD_GET(ANA_VLAN_CFG_VLAN_VID, x) + +/* ANA:PORT:DROP_CFG */ +#define ANA_DROP_CFG(g) __REG(TARGET_ANA, 0, 1, 28672, g, 9, 128, 4, 0, 1, 4) + +#define ANA_DROP_CFG_DROP_UNTAGGED_ENA BIT(6) +#define ANA_DROP_CFG_DROP_UNTAGGED_ENA_SET(x)\ + FIELD_PREP(ANA_DROP_CFG_DROP_UNTAGGED_ENA, x) +#define ANA_DROP_CFG_DROP_UNTAGGED_ENA_GET(x)\ + FIELD_GET(ANA_DROP_CFG_DROP_UNTAGGED_ENA, x) + +#define ANA_DROP_CFG_DROP_PRIO_S_TAGGED_ENA BIT(3) +#define ANA_DROP_CFG_DROP_PRIO_S_TAGGED_ENA_SET(x)\ + FIELD_PREP(ANA_DROP_CFG_DROP_PRIO_S_TAGGED_ENA, x) +#define ANA_DROP_CFG_DROP_PRIO_S_TAGGED_ENA_GET(x)\ + FIELD_GET(ANA_DROP_CFG_DROP_PRIO_S_TAGGED_ENA, x) + +#define ANA_DROP_CFG_DROP_PRIO_C_TAGGED_ENA BIT(2) +#define ANA_DROP_CFG_DROP_PRIO_C_TAGGED_ENA_SET(x)\ + FIELD_PREP(ANA_DROP_CFG_DROP_PRIO_C_TAGGED_ENA, x) +#define ANA_DROP_CFG_DROP_PRIO_C_TAGGED_ENA_GET(x)\ + FIELD_GET(ANA_DROP_CFG_DROP_PRIO_C_TAGGED_ENA, x) + +#define ANA_DROP_CFG_DROP_MC_SMAC_ENA BIT(0) +#define ANA_DROP_CFG_DROP_MC_SMAC_ENA_SET(x)\ + FIELD_PREP(ANA_DROP_CFG_DROP_MC_SMAC_ENA, x) +#define ANA_DROP_CFG_DROP_MC_SMAC_ENA_GET(x)\ + FIELD_GET(ANA_DROP_CFG_DROP_MC_SMAC_ENA, x) + /* ANA:PORT:CPU_FWD_CFG */ #define ANA_CPU_FWD_CFG(g) __REG(TARGET_ANA, 0, 1, 28672, g, 9, 128, 96, 0, 1, 4) @@ -589,6 +688,36 @@ enum lan966x_target { /* QSYS:RES_CTRL:RES_CFG */ #define QSYS_RES_CFG(g) __REG(TARGET_QSYS, 0, 1, 32768, g, 1024, 8, 0, 0, 1, 4) +/* REW:PORT:PORT_VLAN_CFG */ +#define REW_PORT_VLAN_CFG(g) __REG(TARGET_REW, 0, 1, 0, g, 10, 128, 0, 0, 1, 4) + +#define REW_PORT_VLAN_CFG_PORT_TPID GENMASK(31, 16) +#define REW_PORT_VLAN_CFG_PORT_TPID_SET(x)\ + FIELD_PREP(REW_PORT_VLAN_CFG_PORT_TPID, x) +#define REW_PORT_VLAN_CFG_PORT_TPID_GET(x)\ + FIELD_GET(REW_PORT_VLAN_CFG_PORT_TPID, x) + +#define REW_PORT_VLAN_CFG_PORT_VID GENMASK(11, 0) +#define REW_PORT_VLAN_CFG_PORT_VID_SET(x)\ + FIELD_PREP(REW_PORT_VLAN_CFG_PORT_VID, x) +#define REW_PORT_VLAN_CFG_PORT_VID_GET(x)\ + FIELD_GET(REW_PORT_VLAN_CFG_PORT_VID, x) + +/* REW:PORT:TAG_CFG */ +#define REW_TAG_CFG(g) __REG(TARGET_REW, 0, 1, 0, g, 10, 128, 4, 0, 1, 4) + +#define REW_TAG_CFG_TAG_CFG GENMASK(8, 7) +#define REW_TAG_CFG_TAG_CFG_SET(x)\ + FIELD_PREP(REW_TAG_CFG_TAG_CFG, x) +#define REW_TAG_CFG_TAG_CFG_GET(x)\ + FIELD_GET(REW_TAG_CFG_TAG_CFG, x) + +#define REW_TAG_CFG_TAG_TPID_CFG GENMASK(6, 5) +#define REW_TAG_CFG_TAG_TPID_CFG_SET(x)\ + FIELD_PREP(REW_TAG_CFG_TAG_TPID_CFG, x) +#define REW_TAG_CFG_TAG_TPID_CFG_GET(x)\ + FIELD_GET(REW_TAG_CFG_TAG_TPID_CFG, x) + /* REW:PORT:PORT_CFG */ #define REW_PORT_CFG(g) __REG(TARGET_REW, 0, 1, 0, g, 10, 128, 8, 0, 1, 4) From patchwork Mon Dec 13 10:14:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Horatiu Vultur X-Patchwork-Id: 12673603 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3702DC433FE for ; Mon, 13 Dec 2021 10:19:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245077AbhLMKTJ (ORCPT ); Mon, 13 Dec 2021 05:19:09 -0500 Received: from esa.microchip.iphmx.com ([68.232.153.233]:3463 "EHLO esa.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243987AbhLMKPC (ORCPT ); Mon, 13 Dec 2021 05:15:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1639390501; x=1670926501; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=V+Jv9MaMFqvcBDNSlIjW3tUS0kwQ8RDWb5PfDQGs6NU=; b=SPFas1cbqyiU3lLweIksQTDvc1n6i5kABhORH1VbHBj4uYRRSAserCEb lKj0xIzoOihlyFQFmJ5z6VTaqe0luX+rPfy4qqs/1t1/gEPJRAWxxBjAK 3RrBpWFK/AzE77idTwozXpmimyYt3sgaeYfya/QaoazpkAiCrbZQLGut0 EccsP+0pvvGDGXh0EwWIHicKugxdBCSqtIogEQpgODerlkqIWJwcyMbgF TZPPlQ3imLs2unCovWCxGlaGnAfqlQ2IoOzPl7wZDBIKJDSSWMEcWU1M4 fXl7qvhs8/P2Wr3zuo92X37BV16an65FGXifuqw3CSY0oCHluP1hgDBa1 Q==; IronPort-SDR: yOpSMrsFf9gV7hKYwW+bqXe0385gEc88EBCZap+PqjJyzDibmssJZnFmNldL5YB1GqXJ1vKlYr Pigf0I23KGFytgHrth51Gb/UkErqxQ7plPZC4NQwtwZ6RsDhTOs+byn5ZJ4rlcDgqyY8FG/29Q C0rF0qNuvF1WMM5RPBy8Lt9XfNCEykGo+m88SpqvVKzSlBNCxDKvat1vjzUafNJVKwCSBO4UcD o2429y60LW50rw/nqboJFOPbVLw86vpDGp3H/AYSs1Yfo+IkprZZGrD4lpDkEu8AXGzC2zHqJu XK+vCFmD5omsOoEixiQ0ITg5 X-IronPort-AV: E=Sophos;i="5.88,202,1635231600"; d="scan'208";a="147013397" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa3.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 13 Dec 2021 03:15:01 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 13 Dec 2021 03:15:00 -0700 Received: from soft-dev3-1.microsemi.net (10.10.115.15) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Mon, 13 Dec 2021 03:14:57 -0700 From: Horatiu Vultur To: , , CC: , , , , , , , , , Horatiu Vultur Subject: [PATCH net-next v4 02/10] dt-bindings: net: lan966x: Extend with the analyzer interrupt Date: Mon, 13 Dec 2021 11:14:24 +0100 Message-ID: <20211213101432.2668820-3-horatiu.vultur@microchip.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211213101432.2668820-1-horatiu.vultur@microchip.com> References: <20211213101432.2668820-1-horatiu.vultur@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Extend dt-bindings for lan966x with analyzer interrupt. This interrupt can be generated for example when the HW learn/forgets an entry in the MAC table. Reviewed-by: Vladimir Oltean Signed-off-by: Horatiu Vultur Acked-by: Rob Herring --- .../devicetree/bindings/net/microchip,lan966x-switch.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/devicetree/bindings/net/microchip,lan966x-switch.yaml b/Documentation/devicetree/bindings/net/microchip,lan966x-switch.yaml index 5bee665d5fcf..e79e4e166ad8 100644 --- a/Documentation/devicetree/bindings/net/microchip,lan966x-switch.yaml +++ b/Documentation/devicetree/bindings/net/microchip,lan966x-switch.yaml @@ -37,12 +37,14 @@ properties: items: - description: register based extraction - description: frame dma based extraction + - description: analyzer interrupt interrupt-names: minItems: 1 items: - const: xtr - const: fdma + - const: ana resets: items: From patchwork Mon Dec 13 10:14:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Horatiu Vultur X-Patchwork-Id: 12673605 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D2FAC43217 for ; Mon, 13 Dec 2021 10:19:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245093AbhLMKTL (ORCPT ); Mon, 13 Dec 2021 05:19:11 -0500 Received: from esa.microchip.iphmx.com ([68.232.154.123]:31213 "EHLO esa.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244004AbhLMKPF (ORCPT ); Mon, 13 Dec 2021 05:15:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1639390504; x=1670926504; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VUU+4GyCpyEgeHzmSHp3p6f+/VZRvOBHNDru078eO2o=; b=xC4bHLbdms5Ar8cmzgpt3pKWoy3WgeDdpPsODkWOVHSde13cRmYOSuts QBtQCc691jgk4lltX+9GOVLz1eUp73nDUsxY7Z2uV7NodkwvIOXQBK19H gbznmZCis791QpM1Qy9aqFoNYLYTKOkT8mA2BRvDZFTMnQlx3GQkuT7N6 rXWhPUp+k09kIaqpUjj6KQcCUwBLzwJYJaCsycdmaky7/rpxJdm3SykQk l+457J1SoFeJWZQZBvQ+ur/0d8d3dRE7dpUGJUzyk63EPxdg9Q9hRzZ5b iuZzp/A6WtLzLKMRlEfPtkcHdwMoOBQd3P9fFEF0EiRW953AaDGHDnxDz w==; IronPort-SDR: wVTPTM3sBYxza5DG+h4i3HU4UttawzLdS/VoXpbOK0yf0dHwsNdEd+pPeRV62HKBJPqT9H3+kr SltF9mz5bKPW966ODzJ/zATEn3Caamg403jaCxxt40x+o9rKMuDaAM8Y8sk0VoYw28OA+WJQtm 6Lt+Xp/0/rbgbxHXG163Rno6jQflyeuA5Cg5zbK+89D1Fup+98YUsTfq88f4q6xhKyhAl6emB+ AxiFPN+7EISXchDQ2JONJpa8TvyRCfUeHA+nQRtrzi1RJ6KGolb3FARM7/+58r0gRiCrrfimKo HHkCLk9CKPaKAHjg8sTrdx/Z X-IronPort-AV: E=Sophos;i="5.88,202,1635231600"; d="scan'208";a="139554896" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa4.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 13 Dec 2021 03:15:03 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 13 Dec 2021 03:15:03 -0700 Received: from soft-dev3-1.microsemi.net (10.10.115.15) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Mon, 13 Dec 2021 03:15:00 -0700 From: Horatiu Vultur To: , , CC: , , , , , , , , , Horatiu Vultur Subject: [PATCH net-next v4 03/10] net: lan966x: add support for interrupts from analyzer Date: Mon, 13 Dec 2021 11:14:25 +0100 Message-ID: <20211213101432.2668820-4-horatiu.vultur@microchip.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211213101432.2668820-1-horatiu.vultur@microchip.com> References: <20211213101432.2668820-1-horatiu.vultur@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org This patch adds support for handling the interrupts generated by the analyzer. Currently, only the MAC table generates these interrupts. The MAC table will generate an interrupt whenever it learns or forgets an entry in the table. It is the SW responsibility figure out which entries were added/removed. Signed-off-by: Horatiu Vultur --- .../ethernet/microchip/lan966x/lan966x_mac.c | 237 ++++++++++++++++++ .../ethernet/microchip/lan966x/lan966x_main.c | 23 ++ .../ethernet/microchip/lan966x/lan966x_main.h | 6 + 3 files changed, 266 insertions(+) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_mac.c b/drivers/net/ethernet/microchip/lan966x/lan966x_mac.c index f6878b9f57ef..855ea514f438 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_mac.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_mac.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0+ +#include #include "lan966x_main.h" #define LAN966X_MAC_COLUMNS 4 @@ -13,6 +14,23 @@ #define MACACCESS_CMD_WRITE 7 #define MACACCESS_CMD_SYNC_GET_NEXT 8 +#define LAN966X_MAC_INVALID_ROW -1 + +struct lan966x_mac_entry { + struct list_head list; + unsigned char mac[ETH_ALEN] __aligned(2); + u16 vid; + u16 port_index; + int row; +}; + +struct lan966x_mac_raw_entry { + u32 mach; + u32 macl; + u32 maca; + bool processed; +}; + static int lan966x_mac_get_status(struct lan966x *lan966x) { return lan_rd(lan966x, ANA_MACACCESS); @@ -98,4 +116,223 @@ void lan966x_mac_init(struct lan966x *lan966x) /* Clear the MAC table */ lan_wr(MACACCESS_CMD_INIT, lan966x, ANA_MACACCESS); lan966x_mac_wait_for_completion(lan966x); + + spin_lock_init(&lan966x->mac_lock); + INIT_LIST_HEAD(&lan966x->mac_entries); +} + +static struct lan966x_mac_entry *lan966x_mac_alloc_entry(const unsigned char *mac, + u16 vid, u16 port_index) +{ + struct lan966x_mac_entry *mac_entry; + + mac_entry = kzalloc(sizeof(*mac_entry), GFP_KERNEL); + if (!mac_entry) + return NULL; + + memcpy(mac_entry->mac, mac, ETH_ALEN); + mac_entry->vid = vid; + mac_entry->port_index = port_index; + mac_entry->row = LAN966X_MAC_INVALID_ROW; + return mac_entry; +} + +static void lan966x_fdb_call_notifiers(enum switchdev_notifier_type type, + const char *mac, u16 vid, + struct net_device *dev) +{ + struct switchdev_notifier_fdb_info info = { 0 }; + + info.addr = mac; + info.vid = vid; + info.offloaded = true; + call_switchdev_notifiers(type, dev, &info.info, NULL); +} + +void lan966x_mac_purge_entries(struct lan966x *lan966x) +{ + struct lan966x_mac_entry *mac_entry, *tmp; + + spin_lock(&lan966x->mac_lock); + list_for_each_entry_safe(mac_entry, tmp, &lan966x->mac_entries, + list) { + lan966x_mac_forget(lan966x, mac_entry->mac, mac_entry->vid, + ENTRYTYPE_LOCKED); + + list_del(&mac_entry->list); + kfree(mac_entry); + } + spin_unlock(&lan966x->mac_lock); +} + +static void lan966x_mac_notifiers(enum switchdev_notifier_type type, + unsigned char *mac, u32 vid, + struct net_device *dev) +{ + rtnl_lock(); + lan966x_fdb_call_notifiers(type, mac, vid, dev); + rtnl_unlock(); +} + +static void lan966x_mac_process_raw_entry(struct lan966x_mac_raw_entry *raw_entry, + u8 *mac, u16 *vid, u32 *dest_idx) +{ + mac[0] = (raw_entry->mach >> 8) & 0xff; + mac[1] = (raw_entry->mach >> 0) & 0xff; + mac[2] = (raw_entry->macl >> 24) & 0xff; + mac[3] = (raw_entry->macl >> 16) & 0xff; + mac[4] = (raw_entry->macl >> 8) & 0xff; + mac[5] = (raw_entry->macl >> 0) & 0xff; + + *vid = (raw_entry->mach >> 16) & 0xfff; + *dest_idx = ANA_MACACCESS_DEST_IDX_GET(raw_entry->maca); +} + +static void lan966x_mac_irq_process(struct lan966x *lan966x, u32 row, + struct lan966x_mac_raw_entry *raw_entries) +{ + struct lan966x_mac_entry *mac_entry, *tmp; + unsigned char mac[ETH_ALEN] __aligned(2); + u32 dest_idx; + u32 column; + u16 vid; + + spin_lock(&lan966x->mac_lock); + list_for_each_entry_safe(mac_entry, tmp, &lan966x->mac_entries, list) { + bool found = false; + + if (mac_entry->row != row) + continue; + + for (column = 0; column < LAN966X_MAC_COLUMNS; ++column) { + /* All the valid entries are at the start of the row, + * so when get one invalid entry it can just skip the + * rest of the columns + */ + if (!ANA_MACACCESS_VALID_GET(raw_entries[column].maca)) + break; + + lan966x_mac_process_raw_entry(&raw_entries[column], + mac, &vid, &dest_idx); + WARN_ON(dest_idx > lan966x->num_phys_ports); + + /* If the entry in SW is found, then there is nothing + * to do + */ + if (mac_entry->vid == vid && + ether_addr_equal(mac_entry->mac, mac) && + mac_entry->port_index == dest_idx) { + raw_entries[column].processed = true; + found = true; + break; + } + } + + if (!found) { + /* Notify the bridge that the entry doesn't exist + * anymore in the HW and remove the entry from the SW + * list + */ + lan966x_mac_notifiers(SWITCHDEV_FDB_DEL_TO_BRIDGE, + mac_entry->mac, mac_entry->vid, + lan966x->ports[mac_entry->port_index]->dev); + + list_del(&mac_entry->list); + kfree(mac_entry); + } + } + spin_unlock(&lan966x->mac_lock); + + /* Now go to the list of columns and see if any entry was not in the SW + * list, then that means that the entry is new so it needs to notify the + * bridge. + */ + for (column = 0; column < LAN966X_MAC_COLUMNS; ++column) { + /* All the valid entries are at the start of the row, so when + * get one invalid entry it can just skip the rest of the columns + */ + if (!ANA_MACACCESS_VALID_GET(raw_entries[column].maca)) + break; + + /* If the entry already exists then don't do anything */ + if (raw_entries[column].processed) + continue; + + lan966x_mac_process_raw_entry(&raw_entries[column], + mac, &vid, &dest_idx); + WARN_ON(dest_idx > lan966x->num_phys_ports); + + mac_entry = lan966x_mac_alloc_entry(mac, vid, dest_idx); + if (!mac_entry) + return; + + mac_entry->row = row; + + spin_lock(&lan966x->mac_lock); + list_add_tail(&mac_entry->list, &lan966x->mac_entries); + spin_unlock(&lan966x->mac_lock); + + lan966x_mac_notifiers(SWITCHDEV_FDB_ADD_TO_BRIDGE, + mac, vid, lan966x->ports[dest_idx]->dev); + } +} + +irqreturn_t lan966x_mac_irq_handler(struct lan966x *lan966x) +{ + struct lan966x_mac_raw_entry entry[LAN966X_MAC_COLUMNS] = { 0 }; + u32 index, column; + bool stop = true; + u32 val; + + /* Start the scan from 0, 0 */ + lan_wr(ANA_MACTINDX_M_INDEX_SET(0) | + ANA_MACTINDX_BUCKET_SET(0), + lan966x, ANA_MACTINDX); + + while (1) { + lan_rmw(ANA_MACACCESS_MAC_TABLE_CMD_SET(MACACCESS_CMD_SYNC_GET_NEXT), + ANA_MACACCESS_MAC_TABLE_CMD, + lan966x, ANA_MACACCESS); + lan966x_mac_wait_for_completion(lan966x); + + val = lan_rd(lan966x, ANA_MACTINDX); + index = ANA_MACTINDX_M_INDEX_GET(val); + column = ANA_MACTINDX_BUCKET_GET(val); + + /* The SYNC-GET-NEXT returns all the entries(4) in a row in + * which is suffered a change. By change it means that new entry + * was added or an entry was removed because of ageing. + * It would return all the columns for that row. And after that + * it would return the next row The stop conditions of the + * SYNC-GET-NEXT is when it reaches 'directly' to row 0 + * column 3. So if SYNC-GET-NEXT returns row 0 and column 0 + * then it is required to continue to read more even if it + * reaches row 0 and column 3. + */ + if (index == 0 && column == 0) + stop = false; + + if (column == LAN966X_MAC_COLUMNS - 1 && + index == 0 && stop) + break; + + entry[column].mach = lan_rd(lan966x, ANA_MACHDATA); + entry[column].macl = lan_rd(lan966x, ANA_MACLDATA); + entry[column].maca = lan_rd(lan966x, ANA_MACACCESS); + + /* Once all the columns are read process them */ + if (column == LAN966X_MAC_COLUMNS - 1) { + lan966x_mac_irq_process(lan966x, index, entry); + /* A row was processed so it is safe to assume that the + * next row/column can be the stop condition + */ + stop = true; + } + } + + lan_rmw(ANA_ANAINTR_INTR_SET(0), + ANA_ANAINTR_INTR, + lan966x, ANA_ANAINTR); + + return IRQ_HANDLED; } diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c index 101c1f005baf..7c6d6293611a 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c @@ -527,6 +527,13 @@ static irqreturn_t lan966x_xtr_irq_handler(int irq, void *args) return IRQ_HANDLED; } +static irqreturn_t lan966x_ana_irq_handler(int irq, void *args) +{ + struct lan966x *lan966x = args; + + return lan966x_mac_irq_handler(lan966x); +} + static void lan966x_cleanup_ports(struct lan966x *lan966x) { struct lan966x_port *port; @@ -554,6 +561,11 @@ static void lan966x_cleanup_ports(struct lan966x *lan966x) disable_irq(lan966x->xtr_irq); lan966x->xtr_irq = -ENXIO; + + if (lan966x->ana_irq) { + disable_irq(lan966x->ana_irq); + lan966x->ana_irq = -ENXIO; + } } static int lan966x_probe_port(struct lan966x *lan966x, u32 p, @@ -870,6 +882,15 @@ static int lan966x_probe(struct platform_device *pdev) return -ENODEV; } + lan966x->ana_irq = platform_get_irq_byname(pdev, "ana"); + if (lan966x->ana_irq) { + err = devm_request_threaded_irq(&pdev->dev, lan966x->ana_irq, NULL, + lan966x_ana_irq_handler, IRQF_ONESHOT, + "ana irq", lan966x); + if (err) + return dev_err_probe(&pdev->dev, err, "Unable to use ana irq"); + } + /* init switch */ lan966x_init(lan966x); lan966x_stats_init(lan966x); @@ -923,6 +944,8 @@ static int lan966x_remove(struct platform_device *pdev) destroy_workqueue(lan966x->stats_queue); mutex_destroy(&lan966x->stats_lock); + lan966x_mac_purge_entries(lan966x); + return 0; } diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h index 7e5a3b6f168d..ba548d65b58a 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h @@ -75,6 +75,9 @@ struct lan966x { u8 base_mac[ETH_ALEN]; + struct list_head mac_entries; + spinlock_t mac_lock; /* lock for mac_entries list */ + /* stats */ const struct lan966x_stat_layout *stats_layout; u32 num_stats; @@ -87,6 +90,7 @@ struct lan966x { /* interrupts */ int xtr_irq; + int ana_irq; }; struct lan966x_port_config { @@ -141,6 +145,8 @@ int lan966x_mac_forget(struct lan966x *lan966x, int lan966x_mac_cpu_learn(struct lan966x *lan966x, const char *addr, u16 vid); int lan966x_mac_cpu_forget(struct lan966x *lan966x, const char *addr, u16 vid); void lan966x_mac_init(struct lan966x *lan966x); +void lan966x_mac_purge_entries(struct lan966x *lan966x); +irqreturn_t lan966x_mac_irq_handler(struct lan966x *lan966x); static inline void __iomem *lan_addr(void __iomem *base[], int id, int tinst, int tcnt, From patchwork Mon Dec 13 10:14:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Horatiu Vultur X-Patchwork-Id: 12673575 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1CCD7C433F5 for ; Mon, 13 Dec 2021 10:18:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241665AbhLMKSD (ORCPT ); Mon, 13 Dec 2021 05:18:03 -0500 Received: from esa.microchip.iphmx.com ([68.232.153.233]:3474 "EHLO esa.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240634AbhLMKPI (ORCPT ); Mon, 13 Dec 2021 05:15:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1639390507; x=1670926507; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xsrMov8Nc2zo7+8f7qZPWzWqduz/ggZeTzIZrGttFbg=; b=P0a0NZP7yrIxt6LxKU1opCl9QUl1emc+m7Wl+CJavN/kodf++tJC+cZX Xclg7s6zUh7isyrxdFMh1xCCxAqKuOBTfmwe1a6+ARVNQEzSoHk9SzILQ JGsQ3qKVMZCECnMTXWhsQdDW16t8HqvonoOeAuZcPJtkyOt1lsu5TCnxn KQkJY31j2VQBDEV+UvYDKXAZ/O4PUc5hQWW5K+285xVwGy4q1Px+ZG0Da YG6cIp0nT0x48WHAChC5CZmAbqnW+DPwbrTXfsuvvpEovF6388oy1FETa N4K4QvsMzUZucuLCuEgKBl8cZP7BTSdd2cPauPaF1C4LfiILoTTG/cFRE g==; IronPort-SDR: OE+QeyG/TsV2j6m+CnnLeiYEr3Qsciuf94W4qbLlSHts/MG2OwqDmUjs50FAS7unPFpuNZdvxt 0uboV8Sz4HFewJOFhwbSO9cMiLjlNJAZZQr0qhxDp0WJCzykiH4kErOadLkQrdXPQeGpv2+vm4 Zac0O3kPsWcsVXyuhvhrwLLnxZ2/+1+5dhoToRr6vbDNiHI7C5I8pUyLzwIE8/3IeTwih+62QC qT+dJmIMYOF+qXgCQaT8nOJXbcqsI97Q5ZtlL/X8hukbF4AMGKVE4d469bxIQRDV6DjD+ogHzz NiwUaM3Hh0vRutvvklmeM5iL X-IronPort-AV: E=Sophos;i="5.88,202,1635231600"; d="scan'208";a="147013419" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa3.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 13 Dec 2021 03:15:06 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) 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.2375.17; Mon, 13 Dec 2021 03:15:06 -0700 Received: from soft-dev3-1.microsemi.net (10.10.115.15) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Mon, 13 Dec 2021 03:15:03 -0700 From: Horatiu Vultur To: , , CC: , , , , , , , , , Horatiu Vultur Subject: [PATCH net-next v4 04/10] net: lan966x: More MAC table functionality Date: Mon, 13 Dec 2021 11:14:26 +0100 Message-ID: <20211213101432.2668820-5-horatiu.vultur@microchip.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211213101432.2668820-1-horatiu.vultur@microchip.com> References: <20211213101432.2668820-1-horatiu.vultur@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org This patch adds support for adding/removing mac entries in the SW list of entries and in the HW table. This is used by the bridge functionality. Signed-off-by: Horatiu Vultur --- .../ethernet/microchip/lan966x/lan966x_mac.c | 105 ++++++++++++++++++ .../ethernet/microchip/lan966x/lan966x_main.h | 9 ++ 2 files changed, 114 insertions(+) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_mac.c b/drivers/net/ethernet/microchip/lan966x/lan966x_mac.c index 855ea514f438..efadb8d326cc 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_mac.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_mac.c @@ -111,6 +111,14 @@ int lan966x_mac_cpu_forget(struct lan966x *lan966x, const char *addr, u16 vid) return lan966x_mac_forget(lan966x, addr, vid, ENTRYTYPE_LOCKED); } +void lan966x_mac_set_ageing(struct lan966x *lan966x, + u32 ageing) +{ + lan_rmw(ANA_AUTOAGE_AGE_PERIOD_SET(ageing / 2), + ANA_AUTOAGE_AGE_PERIOD, + lan966x, ANA_AUTOAGE); +} + void lan966x_mac_init(struct lan966x *lan966x) { /* Clear the MAC table */ @@ -137,6 +145,48 @@ static struct lan966x_mac_entry *lan966x_mac_alloc_entry(const unsigned char *ma return mac_entry; } +static struct lan966x_mac_entry *lan966x_mac_find_entry(struct lan966x *lan966x, + const unsigned char *mac, + u16 vid, u16 port_index) +{ + struct lan966x_mac_entry *res = NULL; + struct lan966x_mac_entry *mac_entry; + + spin_lock(&lan966x->mac_lock); + list_for_each_entry(mac_entry, &lan966x->mac_entries, list) { + if (mac_entry->vid == vid && + ether_addr_equal(mac, mac_entry->mac) && + mac_entry->port_index == port_index) { + res = mac_entry; + break; + } + } + spin_unlock(&lan966x->mac_lock); + + return res; +} + +static int lan966x_mac_lookup(struct lan966x *lan966x, + const unsigned char mac[ETH_ALEN], + unsigned int vid, enum macaccess_entry_type type) +{ + int ret; + + lan966x_mac_select(lan966x, mac, vid); + + /* Issue a read command */ + lan_wr(ANA_MACACCESS_ENTRYTYPE_SET(type) | + ANA_MACACCESS_VALID_SET(1) | + ANA_MACACCESS_MAC_TABLE_CMD_SET(MACACCESS_CMD_READ), + lan966x, ANA_MACACCESS); + + ret = lan966x_mac_wait_for_completion(lan966x); + if (ret) + return ret; + + return ANA_MACACCESS_VALID_GET(lan_rd(lan966x, ANA_MACACCESS)); +} + static void lan966x_fdb_call_notifiers(enum switchdev_notifier_type type, const char *mac, u16 vid, struct net_device *dev) @@ -149,6 +199,61 @@ static void lan966x_fdb_call_notifiers(enum switchdev_notifier_type type, call_switchdev_notifiers(type, dev, &info.info, NULL); } +int lan966x_mac_add_entry(struct lan966x *lan966x, struct lan966x_port *port, + const unsigned char *addr, u16 vid) +{ + struct lan966x_mac_entry *mac_entry; + + if (lan966x_mac_lookup(lan966x, addr, vid, ENTRYTYPE_NORMAL)) + return 0; + + /* In case the entry already exists, don't add it again to SW, + * just update HW, but we need to look in the actual HW because + * it is possible for an entry to be learn by HW and before we + * get the interrupt the frame will reach CPU and the CPU will + * add the entry but without the extern_learn flag. + */ + mac_entry = lan966x_mac_find_entry(lan966x, addr, vid, port->chip_port); + if (mac_entry) + return lan966x_mac_learn(lan966x, port->chip_port, + addr, vid, ENTRYTYPE_LOCKED); + + mac_entry = lan966x_mac_alloc_entry(addr, vid, port->chip_port); + if (!mac_entry) + return -ENOMEM; + + spin_lock(&lan966x->mac_lock); + list_add_tail(&mac_entry->list, &lan966x->mac_entries); + spin_unlock(&lan966x->mac_lock); + + lan966x_mac_learn(lan966x, port->chip_port, addr, vid, ENTRYTYPE_LOCKED); + lan966x_fdb_call_notifiers(SWITCHDEV_FDB_OFFLOADED, addr, vid, port->dev); + + return 0; +} + +int lan966x_mac_del_entry(struct lan966x *lan966x, const unsigned char *addr, + u16 vid) +{ + struct lan966x_mac_entry *mac_entry, *tmp; + + spin_lock(&lan966x->mac_lock); + list_for_each_entry_safe(mac_entry, tmp, &lan966x->mac_entries, + list) { + if (mac_entry->vid == vid && + ether_addr_equal(addr, mac_entry->mac)) { + lan966x_mac_forget(lan966x, mac_entry->mac, mac_entry->vid, + ENTRYTYPE_LOCKED); + + list_del(&mac_entry->list); + kfree(mac_entry); + } + } + spin_unlock(&lan966x->mac_lock); + + return 0; +} + void lan966x_mac_purge_entries(struct lan966x *lan966x) { struct lan966x_mac_entry *mac_entry, *tmp; diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h index ba548d65b58a..fcd5d09a070c 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h @@ -145,6 +145,15 @@ int lan966x_mac_forget(struct lan966x *lan966x, int lan966x_mac_cpu_learn(struct lan966x *lan966x, const char *addr, u16 vid); int lan966x_mac_cpu_forget(struct lan966x *lan966x, const char *addr, u16 vid); void lan966x_mac_init(struct lan966x *lan966x); +void lan966x_mac_set_ageing(struct lan966x *lan966x, + u32 ageing); +int lan966x_mac_del_entry(struct lan966x *lan966x, + const unsigned char *addr, + u16 vid); +int lan966x_mac_add_entry(struct lan966x *lan966x, + struct lan966x_port *port, + const unsigned char *addr, + u16 vid); void lan966x_mac_purge_entries(struct lan966x *lan966x); irqreturn_t lan966x_mac_irq_handler(struct lan966x *lan966x); From patchwork Mon Dec 13 10:14:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Horatiu Vultur X-Patchwork-Id: 12673577 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C06EC433F5 for ; Mon, 13 Dec 2021 10:18:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241715AbhLMKSF (ORCPT ); Mon, 13 Dec 2021 05:18:05 -0500 Received: from esa.microchip.iphmx.com ([68.232.153.233]:35152 "EHLO esa.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244034AbhLMKPK (ORCPT ); Mon, 13 Dec 2021 05:15:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1639390511; x=1670926511; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XAdzmxpdwlwegMMiO4X2SQ0N3ZT1uNUVVFy9jxtxXZ8=; b=YazbLvbDGFtfm99TFCBwf+W0DetoLb/TZVeoRuIGmuXrpCnhLOeRXQFi 1XWMGipRfTnEUri55ktUERdgZehsBwpotIW0LmYchZf11oI1Ta+9HxiNe J1co0kLT5p6Wfp45p7W6Aw1RRkykJseA7jzzYjg3FSAHWdi+80F0jnwwH vHzeELqTJ82N98U8aekBZd9ukKHtEicXmSsMB5iGn9oXsa2vLLlDEfsdi rkz3fVxDWvjBYbznopDlfYUtF9DoM6nPzkBMMm9BNfOCyG9J9IPZBsGLH QcWV/1mp8kGStr6iPjxu282Q/HefaQ/TPgdgcFCJZjPad7fAjU712jsge A==; IronPort-SDR: 2+2iRXzydXm8BDGy4ZKKpmshkI6stlfxm3Up/fbW6dU5SbSxrHLbrol8I3Z+WCJ3FMB+nhlvaU jBVcD73guzS7oq6S+WcN4yEgVLGw1tI8tYqZXrdaLTyqii7+xkCpSfsjBzPJg7Q+nIHjmVYWV2 OulI3dJs+ADJizBg5Jt/5aF22nrBPgYLkh2TKiMZjScK/7z5LOgF64qDDAF9P0rKiD/AnJMI81 JdRpUW7XD46xKpBzPn6CsMBcAlYa3IGiz/5S7OpYO+cB2uCnSdtSEeCOJaz65c/Xt+bW0DHmdI i1HdwNKNvRgmKsrVmbf+UjXj X-IronPort-AV: E=Sophos;i="5.88,202,1635231600"; d="scan'208";a="146445586" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa5.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 13 Dec 2021 03:15:09 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 13 Dec 2021 03:15:08 -0700 Received: from soft-dev3-1.microsemi.net (10.10.115.15) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Mon, 13 Dec 2021 03:15:06 -0700 From: Horatiu Vultur To: , , CC: , , , , , , , , , Horatiu Vultur Subject: [PATCH net-next v4 05/10] net: lan966x: Add vlan support Date: Mon, 13 Dec 2021 11:14:27 +0100 Message-ID: <20211213101432.2668820-6-horatiu.vultur@microchip.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211213101432.2668820-1-horatiu.vultur@microchip.com> References: <20211213101432.2668820-1-horatiu.vultur@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org This adds support for vlan in lan966x. This allows add/remove front ports from vlans and also allows the CPU port to be added/remove from vlans. In this way it is possible to filter frames towards the CPU based on the vlan. Signed-off-by: Horatiu Vultur --- .../net/ethernet/microchip/lan966x/Makefile | 2 +- .../ethernet/microchip/lan966x/lan966x_main.c | 39 +- .../ethernet/microchip/lan966x/lan966x_main.h | 39 +- .../ethernet/microchip/lan966x/lan966x_vlan.c | 430 ++++++++++++++++++ 4 files changed, 505 insertions(+), 5 deletions(-) create mode 100644 drivers/net/ethernet/microchip/lan966x/lan966x_vlan.c diff --git a/drivers/net/ethernet/microchip/lan966x/Makefile b/drivers/net/ethernet/microchip/lan966x/Makefile index 2989ba528236..f7e6068a91cb 100644 --- a/drivers/net/ethernet/microchip/lan966x/Makefile +++ b/drivers/net/ethernet/microchip/lan966x/Makefile @@ -6,4 +6,4 @@ obj-$(CONFIG_LAN966X_SWITCH) += lan966x-switch.o lan966x-switch-objs := lan966x_main.o lan966x_phylink.o lan966x_port.o \ - lan966x_mac.o lan966x_ethtool.o + lan966x_mac.o lan966x_ethtool.o lan966x_vlan.o diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c index 7c6d6293611a..512c3d52bf4b 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c @@ -103,17 +103,18 @@ static int lan966x_create_targets(struct platform_device *pdev, static int lan966x_port_set_mac_address(struct net_device *dev, void *p) { struct lan966x_port *port = netdev_priv(dev); + u16 pvid = lan966x_vlan_port_get_pvid(port); struct lan966x *lan966x = port->lan966x; const struct sockaddr *addr = p; int ret; /* Learn the new net device MAC address in the mac table. */ - ret = lan966x_mac_cpu_learn(lan966x, addr->sa_data, port->pvid); + ret = lan966x_mac_cpu_learn(lan966x, addr->sa_data, pvid); if (ret) return ret; /* Then forget the previous one. */ - ret = lan966x_mac_cpu_forget(lan966x, dev->dev_addr, port->pvid); + ret = lan966x_mac_cpu_forget(lan966x, dev->dev_addr, pvid); if (ret) return ret; @@ -283,6 +284,12 @@ static void lan966x_ifh_set_ipv(void *ifh, u64 bypass) IFH_POS_IPV, IFH_LEN * 4, PACK, 0); } +static void lan966x_ifh_set_vid(void *ifh, u64 vid) +{ + packing(ifh, &vid, IFH_POS_TCI + IFH_WID_TCI - 1, + IFH_POS_TCI, IFH_LEN * 4, PACK, 0); +} + static int lan966x_port_xmit(struct sk_buff *skb, struct net_device *dev) { struct lan966x_port *port = netdev_priv(dev); @@ -294,6 +301,7 @@ static int lan966x_port_xmit(struct sk_buff *skb, struct net_device *dev) lan966x_ifh_set_port(ifh, BIT_ULL(port->chip_port)); lan966x_ifh_set_qos_class(ifh, skb->priority >= 7 ? 0x7 : skb->priority); lan966x_ifh_set_ipv(ifh, skb->priority >= 7 ? 0x7 : skb->priority); + lan966x_ifh_set_vid(ifh, skb_vlan_tag_get(skb)); return lan966x_port_ifh_xmit(skb, ifh, dev); } @@ -365,6 +373,18 @@ static int lan966x_port_get_parent_id(struct net_device *dev, return 0; } +static int lan966x_port_set_features(struct net_device *dev, + netdev_features_t features) +{ + struct lan966x_port *port = netdev_priv(dev); + netdev_features_t changed = dev->features ^ features; + + if (changed & NETIF_F_HW_VLAN_CTAG_FILTER) + lan966x_vlan_mode(port, features); + + return 0; +} + static const struct net_device_ops lan966x_port_netdev_ops = { .ndo_open = lan966x_port_open, .ndo_stop = lan966x_port_stop, @@ -376,6 +396,9 @@ static const struct net_device_ops lan966x_port_netdev_ops = { .ndo_get_stats64 = lan966x_stats_get, .ndo_set_mac_address = lan966x_port_set_mac_address, .ndo_get_port_parent_id = lan966x_port_get_parent_id, + .ndo_set_features = lan966x_port_set_features, + .ndo_vlan_rx_add_vid = lan966x_vlan_rx_add_vid, + .ndo_vlan_rx_kill_vid = lan966x_vlan_rx_kill_vid, }; static int lan966x_port_xtr_status(struct lan966x *lan966x, u8 grp) @@ -590,13 +613,16 @@ static int lan966x_probe_port(struct lan966x *lan966x, u32 p, port->dev = dev; port->lan966x = lan966x; port->chip_port = p; - port->pvid = PORT_PVID; lan966x->ports[p] = port; dev->max_mtu = ETH_MAX_MTU; dev->netdev_ops = &lan966x_port_netdev_ops; dev->ethtool_ops = &lan966x_ethtool_ops; + dev->hw_features |= NETIF_F_HW_VLAN_CTAG_FILTER; + dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER | + NETIF_F_HW_VLAN_CTAG_TX | + NETIF_F_HW_VLAN_STAG_TX; dev->needed_headroom = IFH_LEN * sizeof(u32); eth_hw_addr_gen(dev, lan966x->base_mac, p + 1); @@ -643,6 +669,10 @@ static int lan966x_probe_port(struct lan966x *lan966x, u32 p, return err; } + lan966x_vlan_port_set_vlan_aware(port, 0); + lan966x_vlan_port_set_vid(port, HOST_PVID, false, false); + lan966x_vlan_port_apply(port); + return 0; } @@ -653,6 +683,9 @@ static void lan966x_init(struct lan966x *lan966x) /* MAC table initialization */ lan966x_mac_init(lan966x); + /* Vlan initialization */ + lan966x_vlan_init(lan966x); + /* Flush queues */ lan_wr(lan_rd(lan966x, QS_XTR_FLUSH) | GENMASK(1, 0), diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h index fcd5d09a070c..306d52ed140d 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h @@ -4,6 +4,7 @@ #define __LAN966X_MAIN_H__ #include +#include #include #include #include @@ -22,7 +23,8 @@ #define PGID_SRC 80 #define PGID_ENTRIES 89 -#define PORT_PVID 0 +#define UNAWARE_PVID 0 +#define HOST_PVID 4095 /* Reserved amount for (SRC, PRIO) at index 8*SRC + PRIO */ #define QSYS_Q_RSRV 95 @@ -78,6 +80,9 @@ struct lan966x { struct list_head mac_entries; spinlock_t mac_lock; /* lock for mac_entries list */ + u16 vlan_mask[VLAN_N_VID]; + DECLARE_BITMAP(cpu_vlan_mask, VLAN_N_VID); + /* stats */ const struct lan966x_stat_layout *stats_layout; u32 num_stats; @@ -109,6 +114,8 @@ struct lan966x_port { u8 chip_port; u16 pvid; + u16 vid; + u8 vlan_aware; struct phylink_config phylink_config; struct phylink_pcs phylink_pcs; @@ -157,6 +164,36 @@ int lan966x_mac_add_entry(struct lan966x *lan966x, void lan966x_mac_purge_entries(struct lan966x *lan966x); irqreturn_t lan966x_mac_irq_handler(struct lan966x *lan966x); +void lan966x_vlan_init(struct lan966x *lan966x); +void lan966x_vlan_port_apply(struct lan966x_port *port); + +int lan966x_vlan_rx_add_vid(struct net_device *dev, __be16 proto, u16 vid); +int lan966x_vlan_rx_kill_vid(struct net_device *dev, __be16 proto, u16 vid); + +void lan966x_vlan_mode(struct lan966x_port *port, netdev_features_t features); +u16 lan966x_vlan_port_get_pvid(struct lan966x_port *port); + +bool lan966x_vlan_cpu_member_cpu_vlan_mask(struct lan966x *lan966x, u16 vid); +bool lan966x_vlan_port_any_vlan_mask(struct lan966x *lan966x, u16 vid); + +void lan966x_vlan_cpu_set_vlan_aware(struct lan966x_port *port); +void lan966x_vlan_port_set_vlan_aware(struct lan966x_port *port, + bool vlan_aware); +int lan966x_vlan_port_set_vid(struct lan966x_port *port, u16 vid, + bool pvid, bool untagged); +int lan966x_vlan_port_add_vlan(struct lan966x_port *port, + u16 vid, + bool pvid, + bool untagged); +int lan966x_vlan_port_del_vlan(struct lan966x_port *port, + u16 vid); +int lan966x_vlan_cpu_add_vlan(struct lan966x *lan966x, + struct net_device *dev, + u16 vid); +int lan966x_vlan_cpu_del_vlan(struct lan966x *lan966x, + struct net_device *dev, + u16 vid); + static inline void __iomem *lan_addr(void __iomem *base[], int id, int tinst, int tcnt, int gbase, int ginst, diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_vlan.c b/drivers/net/ethernet/microchip/lan966x/lan966x_vlan.c new file mode 100644 index 000000000000..78d18ab00d81 --- /dev/null +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_vlan.c @@ -0,0 +1,430 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include "lan966x_main.h" + +#define VLANACCESS_CMD_IDLE 0 +#define VLANACCESS_CMD_READ 1 +#define VLANACCESS_CMD_WRITE 2 +#define VLANACCESS_CMD_INIT 3 + +static int lan966x_vlan_get_status(struct lan966x *lan966x) +{ + return lan_rd(lan966x, ANA_VLANACCESS); +} + +static int lan966x_vlan_wait_for_completion(struct lan966x *lan966x) +{ + u32 val; + + return readx_poll_timeout(lan966x_vlan_get_status, + lan966x, val, + (val & ANA_VLANACCESS_VLAN_TBL_CMD) == + VLANACCESS_CMD_IDLE, + TABLE_UPDATE_SLEEP_US, TABLE_UPDATE_TIMEOUT_US); +} + +static int lan966x_vlan_set_mask(struct lan966x *lan966x, u16 vid) +{ + u16 mask = lan966x->vlan_mask[vid]; + bool cpu_dis; + + cpu_dis = !(mask & BIT(CPU_PORT)); + + /* Set flags and the VID to configure */ + lan_rmw(ANA_VLANTIDX_VLAN_PGID_CPU_DIS_SET(cpu_dis) | + ANA_VLANTIDX_V_INDEX_SET(vid), + ANA_VLANTIDX_VLAN_PGID_CPU_DIS | + ANA_VLANTIDX_V_INDEX, + lan966x, ANA_VLANTIDX); + + /* Set the vlan port members mask */ + lan_rmw(ANA_VLAN_PORT_MASK_VLAN_PORT_MASK_SET(mask), + ANA_VLAN_PORT_MASK_VLAN_PORT_MASK, + lan966x, ANA_VLAN_PORT_MASK); + + /* Issue a write command */ + lan_rmw(ANA_VLANACCESS_VLAN_TBL_CMD_SET(VLANACCESS_CMD_WRITE), + ANA_VLANACCESS_VLAN_TBL_CMD, + lan966x, ANA_VLANACCESS); + + return lan966x_vlan_wait_for_completion(lan966x); +} + +void lan966x_vlan_init(struct lan966x *lan966x) +{ + u16 port, vid; + + /* Clear VLAN table, by default all ports are members of all VLANS */ + lan_rmw(ANA_VLANACCESS_VLAN_TBL_CMD_SET(VLANACCESS_CMD_INIT), + ANA_VLANACCESS_VLAN_TBL_CMD, + lan966x, ANA_VLANACCESS); + lan966x_vlan_wait_for_completion(lan966x); + + for (vid = 1; vid < VLAN_N_VID; vid++) { + lan966x->vlan_mask[vid] = 0; + lan966x_vlan_set_mask(lan966x, vid); + } + + /* Set all the ports + cpu to be part of HOST_PVID and UNAWARE_PVID */ + lan966x->vlan_mask[HOST_PVID] = + GENMASK(lan966x->num_phys_ports - 1, 0) | BIT(CPU_PORT); + lan966x_vlan_set_mask(lan966x, HOST_PVID); + + lan966x->vlan_mask[UNAWARE_PVID] = + GENMASK(lan966x->num_phys_ports - 1, 0) | BIT(CPU_PORT); + lan966x_vlan_set_mask(lan966x, UNAWARE_PVID); + + /* Configure the CPU port to be vlan aware */ + lan_wr(ANA_VLAN_CFG_VLAN_VID_SET(0) | + ANA_VLAN_CFG_VLAN_AWARE_ENA_SET(1) | + ANA_VLAN_CFG_VLAN_POP_CNT_SET(1), + lan966x, ANA_VLAN_CFG(CPU_PORT)); + + /* Set vlan ingress filter mask to all ports */ + lan_wr(GENMASK(lan966x->num_phys_ports, 0), + lan966x, ANA_VLANMASK); + + for (port = 0; port < lan966x->num_phys_ports; port++) { + lan_wr(0, lan966x, REW_PORT_VLAN_CFG(port)); + lan_wr(0, lan966x, REW_TAG_CFG(port)); + } +} + +static int lan966x_vlan_port_add_vlan_mask(struct lan966x_port *port, u16 vid) +{ + struct lan966x *lan966x = port->lan966x; + u8 p = port->chip_port; + + lan966x->vlan_mask[vid] |= BIT(p); + return lan966x_vlan_set_mask(lan966x, vid); +} + +static int lan966x_vlan_port_del_vlan_mask(struct lan966x_port *port, u16 vid) +{ + struct lan966x *lan966x = port->lan966x; + u8 p = port->chip_port; + + lan966x->vlan_mask[vid] &= ~BIT(p); + return lan966x_vlan_set_mask(lan966x, vid); +} + +static bool lan966x_vlan_port_member_vlan_mask(struct lan966x_port *port, u16 vid) +{ + struct lan966x *lan966x = port->lan966x; + u8 p = port->chip_port; + + return lan966x->vlan_mask[vid] & BIT(p); +} + +bool lan966x_vlan_port_any_vlan_mask(struct lan966x *lan966x, u16 vid) +{ + return !!(lan966x->vlan_mask[vid] & ~BIT(CPU_PORT)); +} + +static int lan966x_vlan_cpu_add_vlan_mask(struct lan966x *lan966x, u16 vid) +{ + lan966x->vlan_mask[vid] |= BIT(CPU_PORT); + return lan966x_vlan_set_mask(lan966x, vid); +} + +static int lan966x_vlan_cpu_del_vlan_mask(struct lan966x *lan966x, u16 vid) +{ + lan966x->vlan_mask[vid] &= ~BIT(CPU_PORT); + return lan966x_vlan_set_mask(lan966x, vid); +} + +static void lan966x_vlan_cpu_add_cpu_vlan_mask(struct lan966x *lan966x, u16 vid) +{ + set_bit(vid, lan966x->cpu_vlan_mask); +} + +static void lan966x_vlan_cpu_del_cpu_vlan_mask(struct lan966x *lan966x, u16 vid) +{ + clear_bit(vid, lan966x->cpu_vlan_mask); +} + +bool lan966x_vlan_cpu_member_cpu_vlan_mask(struct lan966x *lan966x, u16 vid) +{ + return test_bit(vid, lan966x->cpu_vlan_mask); +} + +u16 lan966x_vlan_port_get_pvid(struct lan966x_port *port) +{ + return port->vlan_aware ? port->pvid : UNAWARE_PVID; +} + +int lan966x_vlan_port_set_vid(struct lan966x_port *port, u16 vid, + bool pvid, bool untagged) +{ + struct lan966x *lan966x = port->lan966x; + + /* Egress vlan classification */ + if (untagged && port->vid != vid) { + if (port->vid) { + dev_err(lan966x->dev, + "Port already has a native VLAN: %d\n", + port->vid); + return -EBUSY; + } + port->vid = vid; + } + + /* Default ingress vlan classification */ + if (pvid) + port->pvid = vid; + + return 0; +} + +static int lan966x_vlan_port_remove_vid(struct lan966x_port *port, u16 vid) +{ + if (port->pvid == vid) + port->pvid = 0; + + if (port->vid == vid) + port->vid = 0; + + return 0; +} + +void lan966x_vlan_port_set_vlan_aware(struct lan966x_port *port, + bool vlan_aware) +{ + port->vlan_aware = vlan_aware; +} + +void lan966x_vlan_cpu_set_vlan_aware(struct lan966x_port *port) +{ + struct lan966x *lan966x = port->lan966x; + + if (!port->vlan_aware) { + /* In case of vlan unaware, all the ports will be set in + * UNAWARE_PVID and have their PVID set to this PVID + * The CPU doesn't need to be added because it is always part of + * that vlan, it is required just to add entries in the MAC + * table for the front port and the CPU + */ + lan966x_mac_cpu_learn(lan966x, port->dev->dev_addr, UNAWARE_PVID); + + lan966x_vlan_port_add_vlan_mask(port, UNAWARE_PVID); + lan966x_vlan_port_apply(port); + } else { + /* In case of vlan aware, just clear what happened when changed + * to vlan unaware + */ + lan966x_mac_cpu_forget(lan966x, port->dev->dev_addr, UNAWARE_PVID); + + lan966x_vlan_port_del_vlan_mask(port, UNAWARE_PVID); + lan966x_vlan_port_apply(port); + } +} + +void lan966x_vlan_port_apply(struct lan966x_port *port) +{ + struct lan966x *lan966x = port->lan966x; + u16 pvid; + u32 val; + + pvid = lan966x_vlan_port_get_pvid(port); + + /* Ingress clasification (ANA_PORT_VLAN_CFG) */ + /* Default vlan to casify for untagged frames (may be zero) */ + val = ANA_VLAN_CFG_VLAN_VID_SET(pvid); + if (port->vlan_aware) + val |= ANA_VLAN_CFG_VLAN_AWARE_ENA_SET(1) | + ANA_VLAN_CFG_VLAN_POP_CNT_SET(1); + + lan_rmw(val, + ANA_VLAN_CFG_VLAN_VID | ANA_VLAN_CFG_VLAN_AWARE_ENA | + ANA_VLAN_CFG_VLAN_POP_CNT, + lan966x, ANA_VLAN_CFG(port->chip_port)); + + /* Drop frames with multicast source address */ + val = ANA_DROP_CFG_DROP_MC_SMAC_ENA_SET(1); + if (port->vlan_aware && !pvid) + /* If port is vlan-aware and tagged, drop untagged and priority + * tagged frames. + */ + val |= ANA_DROP_CFG_DROP_UNTAGGED_ENA_SET(1) | + ANA_DROP_CFG_DROP_PRIO_S_TAGGED_ENA_SET(1) | + ANA_DROP_CFG_DROP_PRIO_C_TAGGED_ENA_SET(1); + + lan_wr(val, lan966x, ANA_DROP_CFG(port->chip_port)); + + /* Egress configuration (REW_TAG_CFG): VLAN tag type to 8021Q */ + val = REW_TAG_CFG_TAG_TPID_CFG_SET(0); + if (port->vlan_aware) { + if (port->vid) + /* Tag all frames except when VID == DEFAULT_VLAN */ + val |= REW_TAG_CFG_TAG_CFG_SET(1); + else + val |= REW_TAG_CFG_TAG_CFG_SET(3); + } + + /* Update only some bits in the register */ + lan_rmw(val, + REW_TAG_CFG_TAG_TPID_CFG | REW_TAG_CFG_TAG_CFG, + lan966x, REW_TAG_CFG(port->chip_port)); + + /* Set default VLAN and tag type to 8021Q */ + lan_rmw(REW_PORT_VLAN_CFG_PORT_TPID_SET(ETH_P_8021Q) | + REW_PORT_VLAN_CFG_PORT_VID_SET(port->vid), + REW_PORT_VLAN_CFG_PORT_TPID | + REW_PORT_VLAN_CFG_PORT_VID, + lan966x, REW_PORT_VLAN_CFG(port->chip_port)); +} + +int lan966x_vlan_port_add_vlan(struct lan966x_port *port, + u16 vid, + bool pvid, + bool untagged) +{ + struct lan966x *lan966x = port->lan966x; + + /* If the CPU(br) is already part of the vlan then add the MAC + * address of the device in MAC table to copy the frames to the + * CPU(br). If the CPU(br) is not part of the vlan then it would + * just drop the frames. + */ + if (lan966x_vlan_cpu_member_cpu_vlan_mask(lan966x, vid)) { + lan966x_mac_cpu_learn(lan966x, port->dev->dev_addr, vid); + lan966x_vlan_cpu_add_vlan_mask(lan966x, vid); + } + + lan966x_vlan_port_set_vid(port, vid, pvid, untagged); + lan966x_vlan_port_add_vlan_mask(port, vid); + lan966x_vlan_port_apply(port); + + return 0; +} + +int lan966x_vlan_port_del_vlan(struct lan966x_port *port, + u16 vid) +{ + struct lan966x *lan966x = port->lan966x; + + /* In case the CPU(br) is part of the vlan then remove the MAC entry + * because frame doesn't need to reach to CPU + */ + if (lan966x_vlan_cpu_member_cpu_vlan_mask(lan966x, vid)) + lan966x_mac_cpu_forget(lan966x, port->dev->dev_addr, vid); + + lan966x_vlan_port_remove_vid(port, vid); + lan966x_vlan_port_del_vlan_mask(port, vid); + lan966x_vlan_port_apply(port); + + /* In case there are no other ports in vlan then remove the CPU from + * that vlan but still keep it in the mask because it may be needed + * again then another port gets added in tha vlan + */ + if (!lan966x_vlan_port_any_vlan_mask(lan966x, vid)) + lan966x_vlan_cpu_del_vlan_mask(lan966x, vid); + + return 0; +} + +int lan966x_vlan_cpu_add_vlan(struct lan966x *lan966x, + struct net_device *dev, + u16 vid) +{ + int p; + + /* Iterate over the ports and see which ones are part of the + * vlan and for those ports add entry in the MAC table to + * copy the frames to the CPU + */ + for (p = 0; p < lan966x->num_phys_ports; p++) { + struct lan966x_port *port = lan966x->ports[p]; + + if (!port || + !lan966x_vlan_port_member_vlan_mask(port, vid)) + continue; + + lan966x_mac_cpu_learn(lan966x, port->dev->dev_addr, vid); + } + + /* Add an entry in the MAC table for the CPU + * Add the CPU part of the vlan only if there is another port in that + * vlan otherwise all the broadcast frames in that vlan will go to CPU + * even if none of the ports are in the vlan and then the CPU will just + * need to discard these frames. It is required to store this + * information so when a front port is added then it would add also the + * CPU port. + */ + if (lan966x_vlan_port_any_vlan_mask(lan966x, vid)) { + lan966x_mac_cpu_learn(lan966x, dev->dev_addr, vid); + lan966x_vlan_cpu_add_vlan_mask(lan966x, vid); + } + + lan966x_vlan_cpu_add_cpu_vlan_mask(lan966x, vid); + + return 0; +} + +int lan966x_vlan_cpu_del_vlan(struct lan966x *lan966x, + struct net_device *dev, + u16 vid) +{ + int p; + + /* Iterate over the ports and see which ones are part of the + * vlan and for those ports remove entry in the MAC table to + * copy the frames to the CPU + */ + for (p = 0; p < lan966x->num_phys_ports; p++) { + struct lan966x_port *port = lan966x->ports[p]; + + if (!port || + !lan966x_vlan_port_member_vlan_mask(port, vid)) + continue; + + lan966x_mac_cpu_forget(lan966x, port->dev->dev_addr, vid); + } + + /* Remove an entry in the MAC table for the CPU */ + lan966x_mac_cpu_forget(lan966x, dev->dev_addr, vid); + + /* Remove the CPU part of the vlan */ + lan966x_vlan_cpu_del_cpu_vlan_mask(lan966x, vid); + lan966x_vlan_cpu_del_vlan_mask(lan966x, vid); + + return 0; +} + +int lan966x_vlan_rx_add_vid(struct net_device *dev, __be16 proto, u16 vid) +{ + struct lan966x_port *port = netdev_priv(dev); + + lan966x_vlan_port_set_vid(port, vid, false, false); + lan966x_vlan_port_add_vlan_mask(port, vid); + lan966x_vlan_port_apply(port); + + return 0; +} + +int lan966x_vlan_rx_kill_vid(struct net_device *dev, __be16 proto, + u16 vid) +{ + struct lan966x_port *port = netdev_priv(dev); + + lan966x_vlan_port_remove_vid(port, vid); + lan966x_vlan_port_del_vlan_mask(port, vid); + lan966x_vlan_port_apply(port); + + return 0; +} + +void lan966x_vlan_mode(struct lan966x_port *port, + netdev_features_t features) +{ + struct lan966x *lan966x = port->lan966x; + u32 val; + + /* Filtering */ + val = lan_rd(lan966x, ANA_VLANMASK); + if (features & NETIF_F_HW_VLAN_CTAG_FILTER) + val |= BIT(port->chip_port); + else + val &= ~BIT(port->chip_port); + lan_wr(val, lan966x, ANA_VLANMASK); +} From patchwork Mon Dec 13 10:14:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Horatiu Vultur X-Patchwork-Id: 12673607 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8E53BC433F5 for ; Mon, 13 Dec 2021 10:19:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245112AbhLMKTO (ORCPT ); Mon, 13 Dec 2021 05:19:14 -0500 Received: from esa.microchip.iphmx.com ([68.232.154.123]:34207 "EHLO esa.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244058AbhLMKPN (ORCPT ); Mon, 13 Dec 2021 05:15:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1639390513; x=1670926513; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1E5hEl0H/Es1Xfn+OtXl9Unn2exeg6OIRZOBRAEd+Ds=; b=Hm+TZ+y+85M+ZPuiP/uOuUGTunhR9Wf1tO0IedUU7q02ezM4AnUGZzCs 90gTkcVyjgVG3rAkwaqQ7WBoxnyJ8nc8U0txZJJ6YxW9j5G7p6h7TCvLE LbPG/4vnwooxG/sFSsBB0vNAWixA3Ey9poleXTN+7GbDEHDn9VN2Nf5Dd yShahFcnmpk1okleC3UFE1i/BMjBaRHx4siXA/aMn8TXqLqBs9bfgdx5S Y6kyDo8eDCZlV9VgyUOxrjXrmHDdUvKc5Py1B5whynImL+nsYoTArKoFr o6+zQtfYAkXiqmcOWLYnFUSZ5DUOn/SmdJ5rJFP439spWVoMh3MrtcVAA Q==; IronPort-SDR: qeGGFY7r0k+UWk8I9LEjKIl5bZUT2WiaTy/SDd24ZuYTbJ5hoASpcqcV5n7lKsnYMfBtjbJkS3 pNwCdNm5o+yluUR0k5i/KkiOES59DjX8OCEjsV0ITGPcbRZ06V4gzE86NmCSTHoMktNFunQPCz hiAMcon6frnOi4rC1scj5EaBBXiCFes5zZELzf2Az+pnyELlBy5vM6uy2AeXoRNKXa7Rg81uNH Ir5MAJxDyVclUbe8UlD67DI9kEaNvr8sv1cDmD0l++w4P9OUVh3KnOefdfZ5uYR6i8m6+8vKDl A5KzgTKchvPZnWKFs9nnLJG1 X-IronPort-AV: E=Sophos;i="5.88,202,1635231600"; d="scan'208";a="142171770" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 13 Dec 2021 03:15:12 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) 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.2375.17; Mon, 13 Dec 2021 03:15:11 -0700 Received: from soft-dev3-1.microsemi.net (10.10.115.15) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Mon, 13 Dec 2021 03:15:09 -0700 From: Horatiu Vultur To: , , CC: , , , , , , , , , Horatiu Vultur Subject: [PATCH net-next v4 06/10] net: lan966x: Remove .ndo_change_rx_flags Date: Mon, 13 Dec 2021 11:14:28 +0100 Message-ID: <20211213101432.2668820-7-horatiu.vultur@microchip.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211213101432.2668820-1-horatiu.vultur@microchip.com> References: <20211213101432.2668820-1-horatiu.vultur@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The function lan966x_port_change_rx_flags() was used only when IFF_PROMISC flag was set. In that case it was setting to copy all the frames to the CPU instead of removing any RX filters. Therefore remove it. Fixes: d28d6d2e37d10d ("net: lan966x: add port module support") Signed-off-by: Horatiu Vultur --- .../ethernet/microchip/lan966x/lan966x_main.c | 23 ------------------- 1 file changed, 23 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c index 512c3d52bf4b..22bb2e4dfdb2 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c @@ -306,28 +306,6 @@ static int lan966x_port_xmit(struct sk_buff *skb, struct net_device *dev) return lan966x_port_ifh_xmit(skb, ifh, dev); } -static void lan966x_set_promisc(struct lan966x_port *port, bool enable) -{ - struct lan966x *lan966x = port->lan966x; - - lan_rmw(ANA_CPU_FWD_CFG_SRC_COPY_ENA_SET(enable), - ANA_CPU_FWD_CFG_SRC_COPY_ENA, - lan966x, ANA_CPU_FWD_CFG(port->chip_port)); -} - -static void lan966x_port_change_rx_flags(struct net_device *dev, int flags) -{ - struct lan966x_port *port = netdev_priv(dev); - - if (!(flags & IFF_PROMISC)) - return; - - if (dev->flags & IFF_PROMISC) - lan966x_set_promisc(port, true); - else - lan966x_set_promisc(port, false); -} - static int lan966x_port_change_mtu(struct net_device *dev, int new_mtu) { struct lan966x_port *port = netdev_priv(dev); @@ -389,7 +367,6 @@ static const struct net_device_ops lan966x_port_netdev_ops = { .ndo_open = lan966x_port_open, .ndo_stop = lan966x_port_stop, .ndo_start_xmit = lan966x_port_xmit, - .ndo_change_rx_flags = lan966x_port_change_rx_flags, .ndo_change_mtu = lan966x_port_change_mtu, .ndo_set_rx_mode = lan966x_port_set_rx_mode, .ndo_get_phys_port_name = lan966x_port_get_phys_port_name, From patchwork Mon Dec 13 10:14:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Horatiu Vultur X-Patchwork-Id: 12673581 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82FEEC433F5 for ; Mon, 13 Dec 2021 10:18:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242119AbhLMKSK (ORCPT ); Mon, 13 Dec 2021 05:18:10 -0500 Received: from esa.microchip.iphmx.com ([68.232.153.233]:35175 "EHLO esa.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230421AbhLMKPS (ORCPT ); Mon, 13 Dec 2021 05:15:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1639390519; x=1670926519; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jcgDApbPjCciLcCAATi51bNSJErLRfWXeqJ7NnYOG60=; b=NRWrVVYOan+vR76Zw3VtTRT9GVH5BLKIUhmdcYJ73bgt3+OowQq7JOKr qBVFKfLFZazabMULZKJ3BZ8TZ+ydsSW093LY/AJfPtqEnh9joXo7mJb18 /vTC2z+ev6xDotWJUIKiEeYEtDb3oaSTgXjNROBehQtcZ+R4lzRhbpq4P Gbf0Oej9IlnQzHUz9COkCIaRXABa3N8MYHWGxyy/rlka//iLRE2n0P5ee 4krvIqFWic0Qb1DGAUEQ0EUREWe/f80SUT4ZhTzbHY3YsT03x2vR1P8Fq eYkmgAXa7bBAwHMG5aINffBJioEpzhaf+1vn0rALkmexSEapng+W5Y5K5 w==; IronPort-SDR: zK2Djz/1hgCo6xeBZRH7bwGe+xh1mjmmc/pOugcf5np0T7C4dofmDxtUyML3n5td//bGyJMtEU At0XBYspnDe6jNHdlVr1TXuHNwOHRIZ/dMMIBERDkIfgOZKjz3djvUAWd+Hmoz9VJCy7NgpeZM GqIjVKYl5HdLaRkmBQmlsr1qWwxDABymSXjXWvMGV7mpkZJeF77ChFvqlvrVxScy8F8Vh3ZbnM E+QTI2mmyNK1p8ze62VRlRgf8pY6WeLYsoo2eGk+9G7VsKHfNYp1i7uhSQoWsrgLh34dQrgZCY 1qNscnMw8leFXHTbx5Zr3c7b X-IronPort-AV: E=Sophos;i="5.88,202,1635231600"; d="scan'208";a="146445635" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa5.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 13 Dec 2021 03:15:18 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 13 Dec 2021 03:15:14 -0700 Received: from soft-dev3-1.microsemi.net (10.10.115.15) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Mon, 13 Dec 2021 03:15:12 -0700 From: Horatiu Vultur To: , , CC: , , , , , , , , , Horatiu Vultur Subject: [PATCH net-next v4 07/10] net: lan966x: Add support to offload the forwarding. Date: Mon, 13 Dec 2021 11:14:29 +0100 Message-ID: <20211213101432.2668820-8-horatiu.vultur@microchip.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211213101432.2668820-1-horatiu.vultur@microchip.com> References: <20211213101432.2668820-1-horatiu.vultur@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org This patch adds basic support to offload in the HW the forwarding of the frames. The driver registers to the switchdev callbacks and implements the callbacks for attributes SWITCHDEV_ATTR_ID_PORT_STP_STATE and SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME. It is not allowed to add a lan966x port to a bridge that contains a different interface than lan966x. Signed-off-by: Horatiu Vultur --- .../net/ethernet/microchip/lan966x/Kconfig | 1 + .../net/ethernet/microchip/lan966x/Makefile | 3 +- .../ethernet/microchip/lan966x/lan966x_main.c | 19 +- .../ethernet/microchip/lan966x/lan966x_main.h | 19 + .../microchip/lan966x/lan966x_switchdev.c | 398 ++++++++++++++++++ .../ethernet/microchip/lan966x/lan966x_vlan.c | 14 +- 6 files changed, 449 insertions(+), 5 deletions(-) create mode 100644 drivers/net/ethernet/microchip/lan966x/lan966x_switchdev.c diff --git a/drivers/net/ethernet/microchip/lan966x/Kconfig b/drivers/net/ethernet/microchip/lan966x/Kconfig index 2860a8c9923d..ac273f84b69e 100644 --- a/drivers/net/ethernet/microchip/lan966x/Kconfig +++ b/drivers/net/ethernet/microchip/lan966x/Kconfig @@ -2,6 +2,7 @@ config LAN966X_SWITCH tristate "Lan966x switch driver" depends on HAS_IOMEM depends on OF + depends on NET_SWITCHDEV select PHYLINK select PACKING help diff --git a/drivers/net/ethernet/microchip/lan966x/Makefile b/drivers/net/ethernet/microchip/lan966x/Makefile index f7e6068a91cb..d489a34fc643 100644 --- a/drivers/net/ethernet/microchip/lan966x/Makefile +++ b/drivers/net/ethernet/microchip/lan966x/Makefile @@ -6,4 +6,5 @@ obj-$(CONFIG_LAN966X_SWITCH) += lan966x-switch.o lan966x-switch-objs := lan966x_main.o lan966x_phylink.o lan966x_port.o \ - lan966x_mac.o lan966x_ethtool.o lan966x_vlan.o + lan966x_mac.o lan966x_ethtool.o lan966x_vlan.o \ + lan966x_switchdev.o diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c index 22bb2e4dfdb2..08d8b230548b 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c @@ -378,6 +378,11 @@ static const struct net_device_ops lan966x_port_netdev_ops = { .ndo_vlan_rx_kill_vid = lan966x_vlan_rx_kill_vid, }; +bool lan966x_netdevice_check(const struct net_device *dev) +{ + return dev->netdev_ops == &lan966x_port_netdev_ops; +} + static int lan966x_port_xtr_status(struct lan966x *lan966x, u8 grp) { return lan_rd(lan966x, QS_XTR_RD(grp)); @@ -514,6 +519,9 @@ static irqreturn_t lan966x_xtr_irq_handler(int irq, void *args) skb->protocol = eth_type_trans(skb, dev); + if (lan966x->bridge_mask & BIT(src_port)) + skb->offload_fwd_mark = 1; + netif_rx_ni(skb); dev->stats.rx_bytes += len; dev->stats.rx_packets++; @@ -604,9 +612,6 @@ static int lan966x_probe_port(struct lan966x *lan966x, u32 p, eth_hw_addr_gen(dev, lan966x->base_mac, p + 1); - lan966x_mac_learn(lan966x, PGID_CPU, dev->dev_addr, port->pvid, - ENTRYTYPE_LOCKED); - port->phylink_config.dev = &port->dev->dev; port->phylink_config.type = PHYLINK_NETDEV; port->phylink_pcs.poll = true; @@ -930,6 +935,11 @@ static int lan966x_probe(struct platform_device *pdev) lan966x_port_init(lan966x->ports[p]); } + lan966x_ext_init(lan966x); + err = lan966x_register_notifier_blocks(lan966x); + if (err) + goto cleanup_ports; + return 0; cleanup_ports: @@ -948,6 +958,8 @@ static int lan966x_remove(struct platform_device *pdev) { struct lan966x *lan966x = platform_get_drvdata(pdev); + lan966x_unregister_notifier_blocks(lan966x); + lan966x_cleanup_ports(lan966x); cancel_delayed_work_sync(&lan966x->stats_work); @@ -955,6 +967,7 @@ static int lan966x_remove(struct platform_device *pdev) mutex_destroy(&lan966x->stats_lock); lan966x_mac_purge_entries(lan966x); + lan966x_ext_purge_entries(lan966x); return 0; } diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h index 306d52ed140d..ac5ae30468ff 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h @@ -77,9 +77,20 @@ struct lan966x { u8 base_mac[ETH_ALEN]; + struct net_device *bridge; + u16 bridge_mask; + u16 bridge_fwd_mask; + struct list_head mac_entries; spinlock_t mac_lock; /* lock for mac_entries list */ + struct list_head ext_entries; + + /* Notifiers */ + struct notifier_block netdevice_nb; + struct notifier_block switchdev_nb; + struct notifier_block switchdev_blocking_nb; + u16 vlan_mask[VLAN_N_VID]; DECLARE_BITMAP(cpu_vlan_mask, VLAN_N_VID); @@ -129,6 +140,11 @@ extern const struct phylink_mac_ops lan966x_phylink_mac_ops; extern const struct phylink_pcs_ops lan966x_phylink_pcs_ops; extern const struct ethtool_ops lan966x_ethtool_ops; +bool lan966x_netdevice_check(const struct net_device *dev); + +int lan966x_register_notifier_blocks(struct lan966x *lan966x); +void lan966x_unregister_notifier_blocks(struct lan966x *lan966x); + void lan966x_stats_get(struct net_device *dev, struct rtnl_link_stats64 *stats); int lan966x_stats_init(struct lan966x *lan966x); @@ -194,6 +210,9 @@ int lan966x_vlan_cpu_del_vlan(struct lan966x *lan966x, struct net_device *dev, u16 vid); +void lan966x_ext_purge_entries(struct lan966x *lan966x); +void lan966x_ext_init(struct lan966x *lan966x); + static inline void __iomem *lan_addr(void __iomem *base[], int id, int tinst, int tcnt, int gbase, int ginst, diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_switchdev.c b/drivers/net/ethernet/microchip/lan966x/lan966x_switchdev.c new file mode 100644 index 000000000000..3f6d361ad65b --- /dev/null +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_switchdev.c @@ -0,0 +1,398 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include +#include + +#include "lan966x_main.h" + +struct lan966x_ext_entry { + struct list_head list; + struct net_device *dev; + u32 ports; +}; + +static void lan966x_update_fwd_mask(struct lan966x *lan966x) +{ + int i; + + for (i = 0; i < lan966x->num_phys_ports; i++) { + struct lan966x_port *port = lan966x->ports[i]; + unsigned long mask = 0; + + if (port && lan966x->bridge_fwd_mask & BIT(i)) + mask = lan966x->bridge_fwd_mask & ~BIT(i); + + mask |= BIT(CPU_PORT); + + lan_wr(ANA_PGID_PGID_SET(mask), + lan966x, ANA_PGID(PGID_SRC + i)); + } +} + +static void lan966x_port_stp_state_set(struct lan966x_port *port, u8 state) +{ + struct lan966x *lan966x = port->lan966x; + bool learn_ena = false; + + if (state == BR_STATE_FORWARDING || state == BR_STATE_LEARNING) + learn_ena = true; + + if (state == BR_STATE_FORWARDING) + lan966x->bridge_fwd_mask |= BIT(port->chip_port); + else + lan966x->bridge_fwd_mask &= ~BIT(port->chip_port); + + lan_rmw(ANA_PORT_CFG_LEARN_ENA_SET(learn_ena), + ANA_PORT_CFG_LEARN_ENA, + lan966x, ANA_PORT_CFG(port->chip_port)); + + lan966x_update_fwd_mask(lan966x); +} + +static void lan966x_port_ageing_set(struct lan966x_port *port, + unsigned long ageing_clock_t) +{ + unsigned long ageing_jiffies = clock_t_to_jiffies(ageing_clock_t); + u32 ageing_time = jiffies_to_msecs(ageing_jiffies) / 1000; + + lan966x_mac_set_ageing(port->lan966x, ageing_time); +} + +static int lan966x_port_attr_set(struct net_device *dev, const void *ctx, + const struct switchdev_attr *attr, + struct netlink_ext_ack *extack) +{ + struct lan966x_port *port = netdev_priv(dev); + int err = 0; + + switch (attr->id) { + case SWITCHDEV_ATTR_ID_PORT_STP_STATE: + lan966x_port_stp_state_set(port, attr->u.stp_state); + break; + case SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME: + lan966x_port_ageing_set(port, attr->u.ageing_time); + break; + default: + err = -EOPNOTSUPP; + break; + } + + return err; +} + +static int lan966x_port_bridge_join(struct lan966x_port *port, + struct net_device *bridge, + struct netlink_ext_ack *extack) +{ + struct lan966x *lan966x = port->lan966x; + struct net_device *dev = port->dev; + int err; + + if (!lan966x->bridge_mask) { + lan966x->bridge = bridge; + } else { + if (lan966x->bridge != bridge) + return -ENODEV; + } + + err = switchdev_bridge_port_offload(dev, dev, NULL, NULL, NULL, + false, extack); + if (err) + return err; + + lan966x->bridge_mask |= BIT(port->chip_port); + + return 0; +} + +static void lan966x_port_bridge_leave(struct lan966x_port *port, + struct net_device *bridge) +{ + struct lan966x *lan966x = port->lan966x; + + lan966x->bridge_mask &= ~BIT(port->chip_port); + + if (!lan966x->bridge_mask) + lan966x->bridge = NULL; + + /* Set the port back to host mode */ + lan966x_vlan_port_set_vlan_aware(port, false); + lan966x_vlan_port_set_vid(port, HOST_PVID, false, false); + lan966x_vlan_port_apply(port); + + lan966x_mac_cpu_learn(lan966x, port->dev->dev_addr, HOST_PVID); +} + +static int lan966x_port_changeupper(struct net_device *dev, + struct netdev_notifier_changeupper_info *info) +{ + struct lan966x_port *port = netdev_priv(dev); + struct netlink_ext_ack *extack; + int err = 0; + + extack = netdev_notifier_info_to_extack(&info->info); + + if (netif_is_bridge_master(info->upper_dev)) { + if (info->linking) + err = lan966x_port_bridge_join(port, info->upper_dev, + extack); + else + lan966x_port_bridge_leave(port, info->upper_dev); + } + + return err; +} + +static int lan966x_port_prechangeupper(struct net_device *dev, + struct netdev_notifier_changeupper_info *info) +{ + struct lan966x_port *port = netdev_priv(dev); + struct lan966x *lan966x = port->lan966x; + + if (netif_is_bridge_master(info->upper_dev) && !info->linking) + switchdev_bridge_port_unoffload(port->dev, port, + &lan966x->netdevice_nb, + &lan966x->switchdev_blocking_nb); + + return NOTIFY_DONE; +} + +static int lan966x_port_add_addr(struct net_device *dev, bool up) +{ + struct lan966x_port *port = netdev_priv(dev); + struct lan966x *lan966x = port->lan966x; + u16 vid; + + vid = lan966x_vlan_port_get_pvid(port); + + if (up) + lan966x_mac_cpu_learn(lan966x, dev->dev_addr, vid); + else + lan966x_mac_cpu_forget(lan966x, dev->dev_addr, vid); + + return 0; +} + +static struct lan966x_ext_entry *lan966x_ext_find_entry(struct lan966x *lan966x, + struct net_device *dev) +{ + struct lan966x_ext_entry *ext_entry; + + list_for_each_entry(ext_entry, &lan966x->ext_entries, list) { + if (ext_entry->dev == dev) + return ext_entry; + } + + return NULL; +} + +static bool lan966x_ext_add_entry(struct lan966x *lan966x, + struct net_device *dev) +{ + struct lan966x_ext_entry *ext_entry; + + ext_entry = lan966x_ext_find_entry(lan966x, dev); + if (ext_entry) { + ext_entry->ports++; + return true; + } + + ext_entry = kzalloc(sizeof(*ext_entry), GFP_KERNEL); + if (!ext_entry) + return false; + + ext_entry->dev = dev; + ext_entry->ports = 1; + list_add_tail(&ext_entry->list, &lan966x->ext_entries); + return true; +} + +static void lan966x_ext_remove_entry(struct lan966x *lan966x, + struct net_device *dev) +{ + struct lan966x_ext_entry *ext_entry; + + ext_entry = lan966x_ext_find_entry(lan966x, dev); + if (!ext_entry) + return; + + ext_entry->ports--; + if (!ext_entry->ports) { + list_del(&ext_entry->list); + kfree(ext_entry); + } +} + +void lan966x_ext_init(struct lan966x *lan966x) +{ + INIT_LIST_HEAD(&lan966x->ext_entries); +} + +void lan966x_ext_purge_entries(struct lan966x *lan966x) +{ + struct lan966x_ext_entry *ext_entry, *tmp; + + list_for_each_entry_safe(ext_entry, tmp, &lan966x->ext_entries, list) { + list_del(&ext_entry->list); + kfree(ext_entry); + } +} + +static int lan966x_ext_check_entry(struct lan966x *lan966x, + struct net_device *dev, + unsigned long event, + void *ptr) +{ + struct netdev_notifier_changeupper_info *info; + + if (event != NETDEV_PRECHANGEUPPER) + return 0; + + info = ptr; + if (!netif_is_bridge_master(info->upper_dev)) + return 0; + + /* If the master is used by lan966x, then don't allow the foreign + * interfaces to be added + */ + if (lan966x->bridge == info->upper_dev) + return -EOPNOTSUPP; + + /* The master is not used by lan966x so return OK, but keep the + * master in a cache in case at a later point one of the lan966x ports + * is added to it. In that case don't allow it. + */ + if (info->linking) { + if (!lan966x_ext_add_entry(lan966x, info->upper_dev)) + return -EOPNOTSUPP; + } else { + lan966x_ext_remove_entry(lan966x, info->upper_dev); + } + + return NOTIFY_DONE; +} + +static bool lan966x_port_ext_check_entry(struct net_device *dev, + struct netdev_notifier_changeupper_info *info) +{ + struct lan966x_port *port = netdev_priv(dev); + struct lan966x *lan966x = port->lan966x; + + if (!netif_is_bridge_master(info->upper_dev) || !info->linking) + return true; + + return lan966x_ext_find_entry(lan966x, info->upper_dev) ? false : true; +} + +static int lan966x_netdevice_port_event(struct net_device *dev, + struct notifier_block *nb, + unsigned long event, void *ptr) +{ + struct lan966x *lan966x = container_of(nb, struct lan966x, netdevice_nb); + int err = 0; + + if (!lan966x_netdevice_check(dev)) + return lan966x_ext_check_entry(lan966x, dev, event, ptr); + + switch (event) { + case NETDEV_PRECHANGEUPPER: + if (!lan966x_port_ext_check_entry(dev, ptr)) + return -EOPNOTSUPP; + + err = lan966x_port_prechangeupper(dev, ptr); + break; + case NETDEV_CHANGEUPPER: + err = lan966x_port_changeupper(dev, ptr); + break; + case NETDEV_PRE_UP: + err = lan966x_port_add_addr(dev, true); + break; + case NETDEV_DOWN: + err = lan966x_port_add_addr(dev, false); + break; + } + + return err; +} + +static int lan966x_netdevice_event(struct notifier_block *nb, + unsigned long event, void *ptr) +{ + struct net_device *dev = netdev_notifier_info_to_dev(ptr); + int ret; + + ret = lan966x_netdevice_port_event(dev, nb, event, ptr); + + return notifier_from_errno(ret); +} + +static int lan966x_switchdev_event(struct notifier_block *nb, + unsigned long event, void *ptr) +{ + struct net_device *dev = switchdev_notifier_info_to_dev(ptr); + int err; + + switch (event) { + case SWITCHDEV_PORT_ATTR_SET: + err = switchdev_handle_port_attr_set(dev, ptr, + lan966x_netdevice_check, + lan966x_port_attr_set); + return notifier_from_errno(err); + } + + return NOTIFY_DONE; +} + +static int lan966x_switchdev_blocking_event(struct notifier_block *nb, + unsigned long event, + void *ptr) +{ + struct net_device *dev = switchdev_notifier_info_to_dev(ptr); + int err; + + switch (event) { + case SWITCHDEV_PORT_ATTR_SET: + err = switchdev_handle_port_attr_set(dev, ptr, + lan966x_netdevice_check, + lan966x_port_attr_set); + return notifier_from_errno(err); + } + + return NOTIFY_DONE; +} + +int lan966x_register_notifier_blocks(struct lan966x *lan966x) +{ + int err; + + lan966x->netdevice_nb.notifier_call = lan966x_netdevice_event; + err = register_netdevice_notifier(&lan966x->netdevice_nb); + if (err) + return err; + + lan966x->switchdev_nb.notifier_call = lan966x_switchdev_event; + err = register_switchdev_notifier(&lan966x->switchdev_nb); + if (err) + goto err_switchdev_nb; + + lan966x->switchdev_blocking_nb.notifier_call = lan966x_switchdev_blocking_event; + err = register_switchdev_blocking_notifier(&lan966x->switchdev_blocking_nb); + if (err) + goto err_switchdev_blocking_nb; + + return 0; + +err_switchdev_blocking_nb: + unregister_switchdev_notifier(&lan966x->switchdev_nb); +err_switchdev_nb: + unregister_netdevice_notifier(&lan966x->netdevice_nb); + + return err; +} + +void lan966x_unregister_notifier_blocks(struct lan966x *lan966x) +{ + unregister_switchdev_blocking_notifier(&lan966x->switchdev_blocking_nb); + unregister_switchdev_notifier(&lan966x->switchdev_nb); + unregister_netdevice_notifier(&lan966x->netdevice_nb); +} diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_vlan.c b/drivers/net/ethernet/microchip/lan966x/lan966x_vlan.c index 78d18ab00d81..268e93328a08 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_vlan.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_vlan.c @@ -150,6 +150,11 @@ bool lan966x_vlan_cpu_member_cpu_vlan_mask(struct lan966x *lan966x, u16 vid) u16 lan966x_vlan_port_get_pvid(struct lan966x_port *port) { + struct lan966x *lan966x = port->lan966x; + + if (!(lan966x->bridge_mask & BIT(port->chip_port))) + return HOST_PVID; + return port->vlan_aware ? port->pvid : UNAWARE_PVID; } @@ -205,6 +210,8 @@ void lan966x_vlan_cpu_set_vlan_aware(struct lan966x_port *port) * table for the front port and the CPU */ lan966x_mac_cpu_learn(lan966x, port->dev->dev_addr, UNAWARE_PVID); + lan966x_mac_cpu_learn(lan966x, lan966x->bridge->dev_addr, + UNAWARE_PVID); lan966x_vlan_port_add_vlan_mask(port, UNAWARE_PVID); lan966x_vlan_port_apply(port); @@ -213,6 +220,8 @@ void lan966x_vlan_cpu_set_vlan_aware(struct lan966x_port *port) * to vlan unaware */ lan966x_mac_cpu_forget(lan966x, port->dev->dev_addr, UNAWARE_PVID); + lan966x_mac_cpu_forget(lan966x, lan966x->bridge->dev_addr, + UNAWARE_PVID); lan966x_vlan_port_del_vlan_mask(port, UNAWARE_PVID); lan966x_vlan_port_apply(port); @@ -288,6 +297,7 @@ int lan966x_vlan_port_add_vlan(struct lan966x_port *port, */ if (lan966x_vlan_cpu_member_cpu_vlan_mask(lan966x, vid)) { lan966x_mac_cpu_learn(lan966x, port->dev->dev_addr, vid); + lan966x_mac_cpu_learn(lan966x, lan966x->bridge->dev_addr, vid); lan966x_vlan_cpu_add_vlan_mask(lan966x, vid); } @@ -317,8 +327,10 @@ int lan966x_vlan_port_del_vlan(struct lan966x_port *port, * that vlan but still keep it in the mask because it may be needed * again then another port gets added in tha vlan */ - if (!lan966x_vlan_port_any_vlan_mask(lan966x, vid)) + if (!lan966x_vlan_port_any_vlan_mask(lan966x, vid)) { + lan966x_mac_cpu_forget(lan966x, lan966x->bridge->dev_addr, vid); lan966x_vlan_cpu_del_vlan_mask(lan966x, vid); + } return 0; } From patchwork Mon Dec 13 10:14:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Horatiu Vultur X-Patchwork-Id: 12673583 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AEDB0C433FE for ; Mon, 13 Dec 2021 10:18:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242176AbhLMKSR (ORCPT ); Mon, 13 Dec 2021 05:18:17 -0500 Received: from esa.microchip.iphmx.com ([68.232.153.233]:39257 "EHLO esa.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240929AbhLMKPW (ORCPT ); Mon, 13 Dec 2021 05:15:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1639390522; x=1670926522; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/HkjVWPq1fJHYY0KDZj1tXRPQsrneOA3XW4Fxk0+VNg=; b=xJLjqeSAq4rP4hjiHe6g9XsISVewKBaE64AwyAOAbqqnFvxQbVQa80m5 avjMmJ/qZdwchYQn5sW1HQZ8FT+SuusA3rCBRy4uRGxdtNHSbyUVFVdN2 Y3C8MIOT2tqfgRahHWI5MHoH19deNTqdbB3h08icgtfq1H74OXwnT5Rtg hvRp1UBr1E050ggGYoYQoyz6kTZrMVLk2MXUuLFOYXQfHMRKajzr80RUK z4f93jr0RtN55Qz4ZfmefGiNrJR78Mcv+4JaaNbUTUSf1kKFBp7IzBPsT j8UitxutWzD24HS9bkxMNu7jhwl0b+Tw46c3rx1ssFBw7vXfYjSG3Wlqk w==; IronPort-SDR: 5ckZZrfVuIDwDB2NPLSis/frYepcHg4OUPIRmE5isn6lNQkU/29HI4jdlQ93ZlbGXdmDBInyAB Mc2ZQMjbU5ABzNwpEe476TZ1dMMweFaqyik8p2HepxiSqCDGQ42Ajs+clie1fiFcN1tAXI5C4v jEN2/dRj/eD/j1ku2pmiE6UPDkILLWeATKTpbbGUq/4BfJgTLP8oNUbuNk2OYSEYdSM+4lmsAs y3s/Ns1oaZSPbJkTf/88eFNZPJJtEcuEpkMbaFSTn/pIK3qu8+qRdpg6AQutLE5Et90QkvNRtS IiMcPzWRdq2rbHljVeoRItD3 X-IronPort-AV: E=Sophos;i="5.88,202,1635231600"; d="scan'208";a="155251648" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa1.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 13 Dec 2021 03:15:21 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 13 Dec 2021 03:15:17 -0700 Received: from soft-dev3-1.microsemi.net (10.10.115.15) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Mon, 13 Dec 2021 03:15:14 -0700 From: Horatiu Vultur To: , , CC: , , , , , , , , , Horatiu Vultur Subject: [PATCH net-next v4 08/10] net: lan966x: Extend switchdev with vlan support Date: Mon, 13 Dec 2021 11:14:30 +0100 Message-ID: <20211213101432.2668820-9-horatiu.vultur@microchip.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211213101432.2668820-1-horatiu.vultur@microchip.com> References: <20211213101432.2668820-1-horatiu.vultur@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Implement the switchdev calls SWITCHDEV_OBJ_ID_PORT_VLAN and SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING. Signed-off-by: Horatiu Vultur --- .../microchip/lan966x/lan966x_switchdev.c | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_switchdev.c b/drivers/net/ethernet/microchip/lan966x/lan966x_switchdev.c index 3f6d361ad65b..062b9fc80e7d 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_switchdev.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_switchdev.c @@ -72,6 +72,11 @@ static int lan966x_port_attr_set(struct net_device *dev, const void *ctx, case SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME: lan966x_port_ageing_set(port, attr->u.ageing_time); break; + case SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING: + lan966x_vlan_port_set_vlan_aware(port, attr->u.vlan_filtering); + lan966x_vlan_port_apply(port); + lan966x_vlan_cpu_set_vlan_aware(port); + break; default: err = -EOPNOTSUPP; break; @@ -343,6 +348,112 @@ static int lan966x_switchdev_event(struct notifier_block *nb, return NOTIFY_DONE; } +static int lan966x_handle_port_vlan_add(struct net_device *dev, + struct notifier_block *nb, + const struct switchdev_obj_port_vlan *v) +{ + struct lan966x_port *port; + struct lan966x *lan966x; + + /* When adding a port to a vlan, we get a callback for the port but + * also for the bridge. When get the callback for the bridge just bail + * out. Then when the bridge is added to the vlan, then we get a + * callback here but in this case the flags has set: + * BRIDGE_VLAN_INFO_BRENTRY. In this case it means that the CPU + * port is added to the vlan, so the broadcast frames and unicast frames + * with dmac of the bridge should be foward to CPU. + */ + if (netif_is_bridge_master(dev) && + !(v->flags & BRIDGE_VLAN_INFO_BRENTRY)) + return 0; + + lan966x = container_of(nb, struct lan966x, switchdev_blocking_nb); + + /* In case the port gets called */ + if (!(netif_is_bridge_master(dev))) { + if (!lan966x_netdevice_check(dev)) + return -EOPNOTSUPP; + + port = netdev_priv(dev); + return lan966x_vlan_port_add_vlan(port, v->vid, + v->flags & BRIDGE_VLAN_INFO_PVID, + v->flags & BRIDGE_VLAN_INFO_UNTAGGED); + } + + /* In case the bridge gets called */ + if (netif_is_bridge_master(dev)) + return lan966x_vlan_cpu_add_vlan(lan966x, dev, v->vid); + + return 0; +} + +static int lan966x_handle_port_obj_add(struct net_device *dev, + struct notifier_block *nb, + struct switchdev_notifier_port_obj_info *info) +{ + const struct switchdev_obj *obj = info->obj; + int err; + + switch (obj->id) { + case SWITCHDEV_OBJ_ID_PORT_VLAN: + err = lan966x_handle_port_vlan_add(dev, nb, + SWITCHDEV_OBJ_PORT_VLAN(obj)); + break; + default: + err = -EOPNOTSUPP; + break; + } + + info->handled = true; + return err; +} + +static int lan966x_handle_port_vlan_del(struct net_device *dev, + struct notifier_block *nb, + const struct switchdev_obj_port_vlan *v) +{ + struct lan966x_port *port; + struct lan966x *lan966x; + + lan966x = container_of(nb, struct lan966x, switchdev_blocking_nb); + + /* In case the physical port gets called */ + if (!netif_is_bridge_master(dev)) { + if (!lan966x_netdevice_check(dev)) + return -EOPNOTSUPP; + + port = netdev_priv(dev); + return lan966x_vlan_port_del_vlan(port, v->vid); + } + + /* In case the bridge gets called */ + if (netif_is_bridge_master(dev)) + return lan966x_vlan_cpu_del_vlan(lan966x, dev, v->vid); + + return 0; +} + +static int lan966x_handle_port_obj_del(struct net_device *dev, + struct notifier_block *nb, + struct switchdev_notifier_port_obj_info *info) +{ + const struct switchdev_obj *obj = info->obj; + int err; + + switch (obj->id) { + case SWITCHDEV_OBJ_ID_PORT_VLAN: + err = lan966x_handle_port_vlan_del(dev, nb, + SWITCHDEV_OBJ_PORT_VLAN(obj)); + break; + default: + err = -EOPNOTSUPP; + break; + } + + info->handled = true; + return err; +} + static int lan966x_switchdev_blocking_event(struct notifier_block *nb, unsigned long event, void *ptr) @@ -351,6 +462,12 @@ static int lan966x_switchdev_blocking_event(struct notifier_block *nb, int err; switch (event) { + case SWITCHDEV_PORT_OBJ_ADD: + err = lan966x_handle_port_obj_add(dev, nb, ptr); + return notifier_from_errno(err); + case SWITCHDEV_PORT_OBJ_DEL: + err = lan966x_handle_port_obj_del(dev, nb, ptr); + return notifier_from_errno(err); case SWITCHDEV_PORT_ATTR_SET: err = switchdev_handle_port_attr_set(dev, ptr, lan966x_netdevice_check, From patchwork Mon Dec 13 10:14:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Horatiu Vultur X-Patchwork-Id: 12673609 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73C67C433EF for ; Mon, 13 Dec 2021 10:19:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245126AbhLMKTR (ORCPT ); Mon, 13 Dec 2021 05:19:17 -0500 Received: from esa.microchip.iphmx.com ([68.232.153.233]:35196 "EHLO esa.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239323AbhLMKP2 (ORCPT ); Mon, 13 Dec 2021 05:15:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1639390528; x=1670926528; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=haaajnQ9KdQzf5Mx5HH6B82QTnOP2wKd/LjkryL7T0I=; b=d3BhcTdRsfRx3TDzVSmdM5NFN1QaAjF8CsrK47r3IIrVp65lHYKL/pAX 1v5XfeCOrvDenFLp/fAK0kjy7GvPIHmiggX+a98CwC9AHrPJhxNm9kIOi XGmUY4ynT5xZj1tMXfse7Mdg/kQj089R8vAj5tWWrxLrECVn3Dy+tgC+L 1MQGcV+YTqYTwiipxe3LEpwomk6q+5mejGWqj6Xdc9V1TxRi29V6/UpCR BVz2QACfvMbpIcUCiVEWw95UmaJtK/zMdc9a4V8hoOQrU3BRNZlhCm4OW 5HgBa/eJML7zmJkzuN/p1FSROKNHDBC2ws0EHhxs6nUJiRa4KuBes6UAa Q==; IronPort-SDR: R9RkZw/20RZHlrXowl1QK9fVHLsJyjqoCxZeDkhP9qWReed1rlpdMojtidH8C3aJjI6WMeLxG3 lebTLJuxVnKY/3pog7o7D+15aNtMznvre3f6073EaYemaOOXJW3gHX8FB1qLDmS0Nm++HHe11Q YOPv55Azgf2ILpY9YEpsYEygI0YdZNieaRX1TMMmjXR6OmSFTO/LqKe9Lc0Z2+bGKFrqgkVJHF FIXshD92gqRqDCHwjg8l42CdTLCurTseCCvFQsFlCXDksuS3hved4By2jYyAsfXmMhWRNKfH3v M4ghsaMX0lw/3zPjz0VzGqPh X-IronPort-AV: E=Sophos;i="5.88,202,1635231600"; d="scan'208";a="146445674" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa5.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 13 Dec 2021 03:15:26 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 13 Dec 2021 03:15:20 -0700 Received: from soft-dev3-1.microsemi.net (10.10.115.15) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Mon, 13 Dec 2021 03:15:17 -0700 From: Horatiu Vultur To: , , CC: , , , , , , , , , Horatiu Vultur Subject: [PATCH net-next v4 09/10] net: lan966x: Extend switchdev bridge flags Date: Mon, 13 Dec 2021 11:14:31 +0100 Message-ID: <20211213101432.2668820-10-horatiu.vultur@microchip.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211213101432.2668820-1-horatiu.vultur@microchip.com> References: <20211213101432.2668820-1-horatiu.vultur@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Currently allow a port to be part or not of the multicast flooding mask. By implementing the switchdev calls SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS and SWITCHDEV_ATTR_ID_PORT_PRE_BRIDGE_FLAGS. Signed-off-by: Horatiu Vultur --- .../microchip/lan966x/lan966x_switchdev.c | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_switchdev.c b/drivers/net/ethernet/microchip/lan966x/lan966x_switchdev.c index 062b9fc80e7d..bda8fdf9514a 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_switchdev.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_switchdev.c @@ -11,6 +11,34 @@ struct lan966x_ext_entry { u32 ports; }; +static void lan966x_port_bridge_flags(struct lan966x_port *port, + struct switchdev_brport_flags flags) +{ + u32 val = lan_rd(port->lan966x, ANA_PGID(PGID_MC)); + + val = ANA_PGID_PGID_GET(val); + + if (flags.mask & BR_MCAST_FLOOD) { + if (flags.val & BR_MCAST_FLOOD) + val |= BIT(port->chip_port); + else + val &= ~BIT(port->chip_port); + } + + lan_rmw(ANA_PGID_PGID_SET(val), + ANA_PGID_PGID, + port->lan966x, ANA_PGID(PGID_MC)); +} + +static int lan966x_port_pre_bridge_flags(struct lan966x_port *port, + struct switchdev_brport_flags flags) +{ + if (flags.mask & ~BR_MCAST_FLOOD) + return -EINVAL; + + return 0; +} + static void lan966x_update_fwd_mask(struct lan966x *lan966x) { int i; @@ -66,6 +94,12 @@ static int lan966x_port_attr_set(struct net_device *dev, const void *ctx, int err = 0; switch (attr->id) { + case SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS: + lan966x_port_bridge_flags(port, attr->u.brport_flags); + break; + case SWITCHDEV_ATTR_ID_PORT_PRE_BRIDGE_FLAGS: + err = lan966x_port_pre_bridge_flags(port, attr->u.brport_flags); + break; case SWITCHDEV_ATTR_ID_PORT_STP_STATE: lan966x_port_stp_state_set(port, attr->u.stp_state); break; From patchwork Mon Dec 13 10:14:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Horatiu Vultur X-Patchwork-Id: 12673611 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC73DC433FE for ; Mon, 13 Dec 2021 10:19:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245135AbhLMKTW (ORCPT ); Mon, 13 Dec 2021 05:19:22 -0500 Received: from esa.microchip.iphmx.com ([68.232.153.233]:39276 "EHLO esa.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241040AbhLMKP3 (ORCPT ); Mon, 13 Dec 2021 05:15:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1639390529; x=1670926529; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Yejz+/qMnRgODShJ7pv3TY59AOtWMNgqaF6rFnE30qA=; b=EvvBkm2OqHVaT2Zc9doIc8AwfwgRKlk6nm1YLESB32BVbyC8BhqV1aU7 pQciTUoQieVYv+2LzNiSNGMMOw9n3HHJIssuV8pmqn5iSkgBqmjM2mwTN iBZz2xTOiWs2HRhu0q7OKOEIUBYXAiPIf5RjRnOyy+CwaML3CwMLeopcK rNfrjek+BedNxDdzdZmeqjs8OKGxarsv5hUtsSJi8+TekErPRgjrfKDJM sFOG9cz97D68TElKYuWWbzfGzvMqmdfLZjD3Qb+HZ3O6lOGBxNLCJGsZP heAQ3qjea9W05HtraWQLNsywi1WX/gU9V6sKdZYkPeDDYxoK+rieE8Vg1 A==; IronPort-SDR: Ha/r/XTXBV+PXVFljVtFaa4/Brh8hlkbIsOPBIDPwwV7MPXSN0f5cQDEBMIZXWfq4odY/4YjyE T56ze8Q03qLt9inTuA1TmUx/WAi4fFTWAEKTIIIfe/OaqxeSejQF70Vxn9IVhQvPzHFxSbWFuM akf0PXXXWsHtkr7VIL4/Wkhluir4HAj6ic8n685D5mHm/YUuoJwKlF4ax3E2OY/y45QstcXeNH 1+LefZTN5vi3oQuVjn12V8dyhpzQQJDj9dY0xuuX1oLUZPl/ct71vyt6No2qyvstxW7srmxWvN dbfOu5w2e8FD4FVw2hqKSZir X-IronPort-AV: E=Sophos;i="5.88,202,1635231600"; d="scan'208";a="155251672" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa1.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 13 Dec 2021 03:15:28 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 13 Dec 2021 03:15:23 -0700 Received: from soft-dev3-1.microsemi.net (10.10.115.15) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Mon, 13 Dec 2021 03:15:20 -0700 From: Horatiu Vultur To: , , CC: , , , , , , , , , Horatiu Vultur Subject: [PATCH net-next v4 10/10] net: lan966x: Extend switchdev with fdb support Date: Mon, 13 Dec 2021 11:14:32 +0100 Message-ID: <20211213101432.2668820-11-horatiu.vultur@microchip.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211213101432.2668820-1-horatiu.vultur@microchip.com> References: <20211213101432.2668820-1-horatiu.vultur@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Extend lan966x driver with fdb support by implementing the switchdev calls SWITCHDEV_FDB_ADD_TO_DEVICE and SWITCHDEV_FDB_DEL_TO_DEVICE. Signed-off-by: Horatiu Vultur --- .../net/ethernet/microchip/lan966x/Makefile | 2 +- .../ethernet/microchip/lan966x/lan966x_fdb.c | 214 ++++++++++++++++++ .../ethernet/microchip/lan966x/lan966x_main.c | 8 + .../ethernet/microchip/lan966x/lan966x_main.h | 10 + .../microchip/lan966x/lan966x_switchdev.c | 5 + .../ethernet/microchip/lan966x/lan966x_vlan.c | 4 + 6 files changed, 242 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/microchip/lan966x/lan966x_fdb.c diff --git a/drivers/net/ethernet/microchip/lan966x/Makefile b/drivers/net/ethernet/microchip/lan966x/Makefile index d489a34fc643..f531caf4a6b8 100644 --- a/drivers/net/ethernet/microchip/lan966x/Makefile +++ b/drivers/net/ethernet/microchip/lan966x/Makefile @@ -7,4 +7,4 @@ obj-$(CONFIG_LAN966X_SWITCH) += lan966x-switch.o lan966x-switch-objs := lan966x_main.o lan966x_phylink.o lan966x_port.o \ lan966x_mac.o lan966x_ethtool.o lan966x_vlan.o \ - lan966x_switchdev.o + lan966x_switchdev.o lan966x_fdb.o diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_fdb.c b/drivers/net/ethernet/microchip/lan966x/lan966x_fdb.c new file mode 100644 index 000000000000..0647f922f116 --- /dev/null +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_fdb.c @@ -0,0 +1,214 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include + +#include "lan966x_main.h" + +struct lan966x_fdb_event_work { + struct work_struct work; + struct switchdev_notifier_fdb_info fdb_info; + struct net_device *dev; + struct lan966x *lan966x; + unsigned long event; +}; + +struct lan966x_fdb_entry { + struct list_head list; + unsigned char mac[ETH_ALEN] __aligned(2); + u16 vid; +}; + +static void lan966x_fdb_add_entry(struct lan966x *lan966x, + struct switchdev_notifier_fdb_info *fdb_info) +{ + struct lan966x_fdb_entry *fdb_entry; + + fdb_entry = kzalloc(sizeof(*fdb_entry), GFP_KERNEL); + if (!fdb_entry) + return; + + memcpy(fdb_entry->mac, fdb_info->addr, ETH_ALEN); + fdb_entry->vid = fdb_info->vid; + list_add_tail(&fdb_entry->list, &lan966x->fdb_entries); +} + +static void lan966x_fdb_del_entry(struct lan966x *lan966x, + struct switchdev_notifier_fdb_info *fdb_info) +{ + struct lan966x_fdb_entry *fdb_entry, *tmp; + + list_for_each_entry_safe(fdb_entry, tmp, &lan966x->fdb_entries, + list) { + if (fdb_entry->vid == fdb_info->vid && + ether_addr_equal(fdb_entry->mac, fdb_info->addr)) { + list_del(&fdb_entry->list); + kfree(fdb_entry); + + break; + } + } +} + +void lan966x_fdb_write_entries(struct lan966x *lan966x, u16 vid) +{ + struct lan966x_fdb_entry *fdb_entry; + + list_for_each_entry(fdb_entry, &lan966x->fdb_entries, list) { + if (fdb_entry->vid != vid) + continue; + + lan966x_mac_cpu_learn(lan966x, fdb_entry->mac, fdb_entry->vid); + } +} + +void lan966x_fdb_erase_entries(struct lan966x *lan966x, u16 vid) +{ + struct lan966x_fdb_entry *fdb_entry; + + list_for_each_entry(fdb_entry, &lan966x->fdb_entries, list) { + if (fdb_entry->vid != vid) + continue; + + lan966x_mac_cpu_forget(lan966x, fdb_entry->mac, fdb_entry->vid); + } +} + +static void lan966x_fdb_purge_entries(struct lan966x *lan966x) +{ + struct lan966x_fdb_entry *fdb_entry, *tmp; + + list_for_each_entry_safe(fdb_entry, tmp, &lan966x->fdb_entries, list) { + list_del(&fdb_entry->list); + kfree(fdb_entry); + } +} + +int lan966x_fdb_init(struct lan966x *lan966x) +{ + INIT_LIST_HEAD(&lan966x->fdb_entries); + lan966x->fdb_work = alloc_ordered_workqueue("lan966x_order", 0); + if (!lan966x->fdb_work) + return -ENOMEM; + + return 0; +} + +void lan966x_fdb_deinit(struct lan966x *lan966x) +{ + destroy_workqueue(lan966x->fdb_work); + lan966x_fdb_purge_entries(lan966x); +} + +static void lan966x_fdb_event_work(struct work_struct *work) +{ + struct lan966x_fdb_event_work *fdb_work = + container_of(work, struct lan966x_fdb_event_work, work); + struct switchdev_notifier_fdb_info *fdb_info; + struct net_device *dev = fdb_work->dev; + struct lan966x_port *port; + struct lan966x *lan966x; + + fdb_info = &fdb_work->fdb_info; + lan966x = fdb_work->lan966x; + + if (lan966x_netdevice_check(dev)) { + port = netdev_priv(dev); + + switch (fdb_work->event) { + case SWITCHDEV_FDB_ADD_TO_DEVICE: + if (!fdb_info->added_by_user) + break; + lan966x_mac_add_entry(lan966x, port, fdb_info->addr, + fdb_info->vid); + break; + case SWITCHDEV_FDB_DEL_TO_DEVICE: + if (!fdb_info->added_by_user) + break; + lan966x_mac_del_entry(lan966x, fdb_info->addr, + fdb_info->vid); + break; + } + } else { + if (!netif_is_bridge_master(dev)) + goto out; + + /* If the CPU is not part of the vlan then there is no point + * to copy the frames to the CPU because they will be dropped + */ + if (!lan966x_vlan_cpu_member_cpu_vlan_mask(lan966x, + fdb_info->vid)) + goto out; + + /* In case the bridge is called */ + switch (fdb_work->event) { + case SWITCHDEV_FDB_ADD_TO_DEVICE: + /* If there is no front port in this vlan, there is no + * point to copy the frame to CPU because it would be + * just dropped at later point. So add it only if + * there is a port but it is required to store the fdb + * entry for later point when a port actually gets in + * the vlan. + */ + lan966x_fdb_add_entry(lan966x, fdb_info); + if (!lan966x_vlan_port_any_vlan_mask(lan966x, fdb_info->vid)) + break; + + lan966x_mac_cpu_learn(lan966x, fdb_info->addr, fdb_info->vid); + break; + case SWITCHDEV_FDB_DEL_TO_DEVICE: + /* It is OK to always forget the entry */ + lan966x_fdb_del_entry(lan966x, fdb_info); + lan966x_mac_cpu_forget(lan966x, fdb_info->addr, fdb_info->vid); + break; + } + } + +out: + kfree(fdb_work->fdb_info.addr); + kfree(fdb_work); + dev_put(dev); +} + +int lan966x_handle_fdb(struct lan966x *lan966x, + unsigned long event, void *ptr) +{ + struct net_device *dev = switchdev_notifier_info_to_dev(ptr); + struct switchdev_notifier_fdb_info *fdb_info; + struct switchdev_notifier_info *info = ptr; + struct lan966x_fdb_event_work *fdb_work; + + switch (event) { + case SWITCHDEV_FDB_ADD_TO_DEVICE: + case SWITCHDEV_FDB_DEL_TO_DEVICE: + fdb_info = container_of(info, + struct switchdev_notifier_fdb_info, + info); + + if (lan966x_netdevice_check(dev) && !fdb_info->added_by_user) + break; + + fdb_work = kzalloc(sizeof(*fdb_work), GFP_ATOMIC); + if (!fdb_work) + return -ENOMEM; + + fdb_work->dev = dev; + fdb_work->lan966x = lan966x; + fdb_work->event = event; + INIT_WORK(&fdb_work->work, lan966x_fdb_event_work); + memcpy(&fdb_work->fdb_info, ptr, sizeof(fdb_work->fdb_info)); + fdb_work->fdb_info.addr = kzalloc(ETH_ALEN, GFP_ATOMIC); + if (!fdb_work->fdb_info.addr) + goto err_addr_alloc; + + ether_addr_copy((u8 *)fdb_work->fdb_info.addr, fdb_info->addr); + dev_hold(dev); + + queue_work(lan966x->fdb_work, &fdb_work->work); + break; + } + + return 0; +err_addr_alloc: + kfree(fdb_work); + return -ENOMEM; +} diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c index 08d8b230548b..e97d47aecad9 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c @@ -940,8 +940,15 @@ static int lan966x_probe(struct platform_device *pdev) if (err) goto cleanup_ports; + err = lan966x_fdb_init(lan966x); + if (err) + goto unregister_notifier_blocks; + return 0; +unregister_notifier_blocks: + lan966x_unregister_notifier_blocks(lan966x); + cleanup_ports: fwnode_handle_put(portnp); @@ -968,6 +975,7 @@ static int lan966x_remove(struct platform_device *pdev) lan966x_mac_purge_entries(lan966x); lan966x_ext_purge_entries(lan966x); + lan966x_fdb_deinit(lan966x); return 0; } diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h index ac5ae30468ff..461b46eb2896 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h @@ -84,6 +84,7 @@ struct lan966x { struct list_head mac_entries; spinlock_t mac_lock; /* lock for mac_entries list */ + struct list_head fdb_entries; struct list_head ext_entries; /* Notifiers */ @@ -107,6 +108,9 @@ struct lan966x { /* interrupts */ int xtr_irq; int ana_irq; + + /* worqueue for fdb */ + struct workqueue_struct *fdb_work; }; struct lan966x_port_config { @@ -210,6 +214,12 @@ int lan966x_vlan_cpu_del_vlan(struct lan966x *lan966x, struct net_device *dev, u16 vid); +void lan966x_fdb_write_entries(struct lan966x *lan966x, u16 vid); +void lan966x_fdb_erase_entries(struct lan966x *lan966x, u16 vid); +int lan966x_fdb_init(struct lan966x *lan966x); +void lan966x_fdb_deinit(struct lan966x *lan966x); +int lan966x_handle_fdb(struct lan966x *lan966x, unsigned long event, void *ptr); + void lan966x_ext_purge_entries(struct lan966x *lan966x); void lan966x_ext_init(struct lan966x *lan966x); diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_switchdev.c b/drivers/net/ethernet/microchip/lan966x/lan966x_switchdev.c index bda8fdf9514a..704613e038cb 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_switchdev.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_switchdev.c @@ -368,6 +368,7 @@ static int lan966x_netdevice_event(struct notifier_block *nb, static int lan966x_switchdev_event(struct notifier_block *nb, unsigned long event, void *ptr) { + struct lan966x *lan966x = container_of(nb, struct lan966x, switchdev_nb); struct net_device *dev = switchdev_notifier_info_to_dev(ptr); int err; @@ -377,6 +378,10 @@ static int lan966x_switchdev_event(struct notifier_block *nb, lan966x_netdevice_check, lan966x_port_attr_set); return notifier_from_errno(err); + case SWITCHDEV_FDB_ADD_TO_DEVICE: + case SWITCHDEV_FDB_DEL_TO_DEVICE: + err = lan966x_handle_fdb(lan966x, event, ptr); + return notifier_from_errno(err); } return NOTIFY_DONE; diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_vlan.c b/drivers/net/ethernet/microchip/lan966x/lan966x_vlan.c index 268e93328a08..4d9edf70234e 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_vlan.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_vlan.c @@ -299,6 +299,7 @@ int lan966x_vlan_port_add_vlan(struct lan966x_port *port, lan966x_mac_cpu_learn(lan966x, port->dev->dev_addr, vid); lan966x_mac_cpu_learn(lan966x, lan966x->bridge->dev_addr, vid); lan966x_vlan_cpu_add_vlan_mask(lan966x, vid); + lan966x_fdb_write_entries(lan966x, vid); } lan966x_vlan_port_set_vid(port, vid, pvid, untagged); @@ -330,6 +331,7 @@ int lan966x_vlan_port_del_vlan(struct lan966x_port *port, if (!lan966x_vlan_port_any_vlan_mask(lan966x, vid)) { lan966x_mac_cpu_forget(lan966x, lan966x->bridge->dev_addr, vid); lan966x_vlan_cpu_del_vlan_mask(lan966x, vid); + lan966x_fdb_erase_entries(lan966x, vid); } return 0; @@ -369,6 +371,7 @@ int lan966x_vlan_cpu_add_vlan(struct lan966x *lan966x, } lan966x_vlan_cpu_add_cpu_vlan_mask(lan966x, vid); + lan966x_fdb_write_entries(lan966x, vid); return 0; } @@ -399,6 +402,7 @@ int lan966x_vlan_cpu_del_vlan(struct lan966x *lan966x, /* Remove the CPU part of the vlan */ lan966x_vlan_cpu_del_cpu_vlan_mask(lan966x, vid); lan966x_vlan_cpu_del_vlan_mask(lan966x, vid); + lan966x_fdb_erase_entries(lan966x, vid); return 0; }