From patchwork Mon Mar 15 21:13:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 402364 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E0CFC433E0 for ; Mon, 15 Mar 2021 21:15:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0F6A564F3F for ; Mon, 15 Mar 2021 21:15:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231683AbhCOVPN (ORCPT ); Mon, 15 Mar 2021 17:15:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230038AbhCOVPI (ORCPT ); Mon, 15 Mar 2021 17:15:08 -0400 Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B0D9C06174A for ; Mon, 15 Mar 2021 14:15:08 -0700 (PDT) Received: by mail-lj1-x236.google.com with SMTP id 15so17980452ljj.0 for ; Mon, 15 Mar 2021 14:15:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:organization:content-transfer-encoding; bh=13sNGlYWXsP7JyqZBCNf8smPbsLjBihO3000tHNoA2A=; b=XL2GsPiO0UQ9d0Y42n827D331XXs0LYgiEykwVs7wKB0vniHPDsm2G1F2V8OD2e+/g Vg2mhHgu72b3dtig5WmQDLT932aiB6d5v7tPU8NW++DWUhS81PqLH92bahFsJ37eOF2J jaG/d4SX+Y0I8BipT4/TCAx9m1y+iSSNmzIamVjoLJQa/lNAdGEtxKTRuFYXJ95+8+cs fVgddgbcwPHpXXz9H/fAvrCjEKZRX6ojGhaghBhCo2HnPsw/RetFygZSWBWzQz/QlpKV 8XKx03AHvj2bTTC+tJcWlHB3Ta9mZVFWiBCDN/21RbSBllgm8Onx8QR4gRSCxUNa8DSU 0psA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:organization:content-transfer-encoding; bh=13sNGlYWXsP7JyqZBCNf8smPbsLjBihO3000tHNoA2A=; b=JUtwjaSSiCnlnGAqlU2JWfOTe3I6bXB7ZEurlkfE6J5opSIuGUJCAQg5+dnvV8rMuH 3diD/slmSAq6reFigCeCPfz0EnqIvtrEyI7G2PADxco4J4gBLF1A0ykwZYZsKZ+xFJyl MwVriaUM9LswMvjKFSFoRIcNeZyzg1uG7UA9o1AT+rVMQ8X2vk6LXzbDSz0oir76C5GF BhazNJTBNHrr5rClLCZ9G/Ko/OXEtz3P4h/KPelsVf+Y1M/kjRybZHK8CJjqldEDS+pe +y9ZaunvneL4h3Rd2N5qXwiyMpC1xlcVVv1Lmrv7gkOd6CNyPcApPjpmCa6wCSclEEO6 Mu6g== X-Gm-Message-State: AOAM533JIS04p/DP6hI81wbCCOWJtC71bkapv+Az391hdcnTNxC1SDOF C37FUcebawRODAxX+WkxDlSFuQ== X-Google-Smtp-Source: ABdhPJyRI8TZTYPOof7uKzOHd8u7t5WNQix9U4MxQH/LfzQVt3NM5FSOyVCWVBZC1F7LDsu1dE4hEA== X-Received: by 2002:a2e:b88e:: with SMTP id r14mr559770ljp.450.1615842906529; Mon, 15 Mar 2021 14:15:06 -0700 (PDT) Received: from veiron.westermo.com (static-193-12-47-89.cust.tele2.se. [193.12.47.89]) by smtp.gmail.com with ESMTPSA id v11sm2975003ljp.63.2021.03.15.14.15.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 14:15:06 -0700 (PDT) From: Tobias Waldekranz To: davem@davemloft.net, kuba@kernel.org Cc: andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, olteanv@gmail.com, netdev@vger.kernel.org Subject: [PATCH net-next 1/5] net: dsa: mv88e6xxx: Provide generic VTU iterator Date: Mon, 15 Mar 2021 22:13:56 +0100 Message-Id: <20210315211400.2805330-2-tobias@waldekranz.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210315211400.2805330-1-tobias@waldekranz.com> References: <20210315211400.2805330-1-tobias@waldekranz.com> MIME-Version: 1.0 Organization: Westermo Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Move the intricacies of correctly iterating over the VTU to a common implementation. Signed-off-by: Tobias Waldekranz Reviewed-by: Andrew Lunn --- drivers/net/dsa/mv88e6xxx/chip.c | 100 ++++++++++++++++++++----------- 1 file changed, 64 insertions(+), 36 deletions(-) diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index 903d619e08ed..c70d4b7db4f5 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -1481,6 +1481,37 @@ static int mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip, return chip->info->ops->vtu_getnext(chip, entry); } +static int mv88e6xxx_vtu_walk(struct mv88e6xxx_chip *chip, + int (*cb)(struct mv88e6xxx_chip *chip, + const struct mv88e6xxx_vtu_entry *entry, + void *priv), + void *priv) +{ + struct mv88e6xxx_vtu_entry entry = { + .vid = mv88e6xxx_max_vid(chip), + .valid = false, + }; + int err; + + if (!chip->info->ops->vtu_getnext) + return -EOPNOTSUPP; + + do { + err = chip->info->ops->vtu_getnext(chip, &entry); + if (err) + return err; + + if (!entry.valid) + break; + + err = cb(chip, &entry, priv); + if (err) + return err; + } while (entry.vid < mv88e6xxx_max_vid(chip)); + + return 0; +} + static int mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip, struct mv88e6xxx_vtu_entry *entry) { @@ -1490,9 +1521,18 @@ static int mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip, return chip->info->ops->vtu_loadpurge(chip, entry); } +static int mv88e6xxx_fid_map_vlan(struct mv88e6xxx_chip *chip, + const struct mv88e6xxx_vtu_entry *entry, + void *_fid_bitmap) +{ + unsigned long *fid_bitmap = _fid_bitmap; + + set_bit(entry->fid, fid_bitmap); + return 0; +} + int mv88e6xxx_fid_map(struct mv88e6xxx_chip *chip, unsigned long *fid_bitmap) { - struct mv88e6xxx_vtu_entry vlan; int i, err; u16 fid; @@ -1508,21 +1548,7 @@ int mv88e6xxx_fid_map(struct mv88e6xxx_chip *chip, unsigned long *fid_bitmap) } /* Set every FID bit used by the VLAN entries */ - vlan.vid = mv88e6xxx_max_vid(chip); - vlan.valid = false; - - do { - err = mv88e6xxx_vtu_getnext(chip, &vlan); - if (err) - return err; - - if (!vlan.valid) - break; - - set_bit(vlan.fid, fid_bitmap); - } while (vlan.vid < mv88e6xxx_max_vid(chip)); - - return 0; + return mv88e6xxx_vtu_walk(chip, mv88e6xxx_fid_map_vlan, fid_bitmap); } static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid) @@ -2168,10 +2194,30 @@ static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip, return err; } +struct mv88e6xxx_port_db_dump_vlan_ctx { + int port; + dsa_fdb_dump_cb_t *cb; + void *data; +}; + +static int mv88e6xxx_port_db_dump_vlan(struct mv88e6xxx_chip *chip, + const struct mv88e6xxx_vtu_entry *entry, + void *_data) +{ + struct mv88e6xxx_port_db_dump_vlan_ctx *ctx = _data; + + return mv88e6xxx_port_db_dump_fid(chip, entry->fid, entry->vid, + ctx->port, ctx->cb, ctx->data); +} + static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port, dsa_fdb_dump_cb_t *cb, void *data) { - struct mv88e6xxx_vtu_entry vlan; + struct mv88e6xxx_port_db_dump_vlan_ctx ctx = { + .port = port, + .cb = cb, + .data = data, + }; u16 fid; int err; @@ -2184,25 +2230,7 @@ static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port, if (err) return err; - /* Dump VLANs' Filtering Information Databases */ - vlan.vid = mv88e6xxx_max_vid(chip); - vlan.valid = false; - - do { - err = mv88e6xxx_vtu_getnext(chip, &vlan); - if (err) - return err; - - if (!vlan.valid) - break; - - err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port, - cb, data); - if (err) - return err; - } while (vlan.vid < mv88e6xxx_max_vid(chip)); - - return err; + return mv88e6xxx_vtu_walk(chip, mv88e6xxx_port_db_dump_vlan, &ctx); } static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port, From patchwork Mon Mar 15 21:13:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 402362 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73FA6C433E6 for ; Mon, 15 Mar 2021 21:15:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2C44B64E13 for ; Mon, 15 Mar 2021 21:15:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231858AbhCOVPO (ORCPT ); Mon, 15 Mar 2021 17:15:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230330AbhCOVPJ (ORCPT ); Mon, 15 Mar 2021 17:15:09 -0400 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C228EC06174A for ; Mon, 15 Mar 2021 14:15:08 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id m22so59092489lfg.5 for ; Mon, 15 Mar 2021 14:15:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:organization:content-transfer-encoding; bh=4PXGw3uTopKOX12zGc4cs1F/+LDcHOWa0xhpMMXr6uQ=; b=u6H5ii0vyRCiaCNFoVq82IGksW/t/np9azuAJuC+E+++290VpvyUj79sHZfOpgqTSp xhhGy979YjicQMBzTMKN+vcLUIj75YZrgXk5OcanmXwaTQVHeynAhehMFTLWAmj+1US8 +8UwrG1RT7063cEnCKXS0pDTJQ4TJ4IuHPZ8Y6N+jbwODcKZs/RbNjmt2F04I6ey+owp AzMMt3adxan0MdqalkdW1roBPtdv4PHrYkzk04m3kJj/zps6WtbHCtRlbBrRZVi4mR3n EvFxt42s5P/6ElpEskpnCWKfAYEiefgC5H92f9mYzfWSAwzulBo1pC7m/bqcTH+FYtUs Yifw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:organization:content-transfer-encoding; bh=4PXGw3uTopKOX12zGc4cs1F/+LDcHOWa0xhpMMXr6uQ=; b=Nnii4R6Zb2OmAm6cQ5KxATyY9L6NZKO0FYr6VOjcITc+sWdAe+iamCmPkNrdMpNzqc WKXQsomDhM90gbb0xnvku5CAgPBlytWflS/aPfcfPkfMq2qIGSO41IgmPtgAGPAoBHdD Y9ho0WIsvl0uLm1m/caoHK9cskrUxUPFIreYDv3IfEZ4Mn4doTl3GAd1rIeThzES13yu gVMW0vY08UrWa2800ONnytpI5Lrg4VnHSlIadxHiYLOnZPl4fu4aJnbWW6TPIL0O7/eT X8TlLs/WOM/vQsa1LvEFApn8RdJi/8l4NnIAf2xIIsA/yUO9WK4kg8IcIT5kylHt+rae ZqUg== X-Gm-Message-State: AOAM532N5XlXRGx2Eit+kEB+QS1ED5WP5FOOorXCXdy0ON1XdWwogzR1 +R8g19Ow58+AxXsFhfUiS772eQ== X-Google-Smtp-Source: ABdhPJwffxfpOWRQ3ZFHvfqrri3g+MF/Dxz1i9hIT4auyAxvtXZz42BZl/ybN+FxlBHaDLeoq2Q9Yw== X-Received: by 2002:a19:ed8:: with SMTP id 207mr8661331lfo.164.1615842907269; Mon, 15 Mar 2021 14:15:07 -0700 (PDT) Received: from veiron.westermo.com (static-193-12-47-89.cust.tele2.se. [193.12.47.89]) by smtp.gmail.com with ESMTPSA id v11sm2975003ljp.63.2021.03.15.14.15.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 14:15:06 -0700 (PDT) From: Tobias Waldekranz To: davem@davemloft.net, kuba@kernel.org Cc: andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, olteanv@gmail.com, netdev@vger.kernel.org Subject: [PATCH net-next 2/5] net: dsa: mv88e6xxx: Remove some bureaucracy around querying the VTU Date: Mon, 15 Mar 2021 22:13:57 +0100 Message-Id: <20210315211400.2805330-3-tobias@waldekranz.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210315211400.2805330-1-tobias@waldekranz.com> References: <20210315211400.2805330-1-tobias@waldekranz.com> MIME-Version: 1.0 Organization: Westermo Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The hardware has a somewhat quirky protocol for reading out the VTU entry for a particular VID. But there is no reason why we cannot create a better API for ourselves in the driver. Signed-off-by: Tobias Waldekranz --- drivers/net/dsa/mv88e6xxx/chip.c | 45 ++++++++++++++------------------ 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index c70d4b7db4f5..86027e98d83d 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -1472,13 +1472,23 @@ static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip) return mv88e6xxx_g1_vtu_flush(chip); } -static int mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip, - struct mv88e6xxx_vtu_entry *entry) +static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid, + struct mv88e6xxx_vtu_entry *entry) { + int err; + if (!chip->info->ops->vtu_getnext) return -EOPNOTSUPP; - return chip->info->ops->vtu_getnext(chip, entry); + entry->vid = vid - 1; + entry->valid = false; + + err = chip->info->ops->vtu_getnext(chip, entry); + + if (entry->vid != vid) + entry->valid = false; + + return err; } static int mv88e6xxx_vtu_walk(struct mv88e6xxx_chip *chip, @@ -1585,19 +1595,13 @@ static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port, if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port)) return 0; - vlan.vid = vid - 1; - vlan.valid = false; - - err = mv88e6xxx_vtu_getnext(chip, &vlan); + err = mv88e6xxx_vtu_get(chip, vid, &vlan); if (err) return err; if (!vlan.valid) return 0; - if (vlan.vid != vid) - return 0; - for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) { if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i)) continue; @@ -1679,15 +1683,12 @@ static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port, if (err) return err; } else { - vlan.vid = vid - 1; - vlan.valid = false; - - err = mv88e6xxx_vtu_getnext(chip, &vlan); + err = mv88e6xxx_vtu_get(chip, vid, &vlan); if (err) return err; /* switchdev expects -EOPNOTSUPP to honor software VLANs */ - if (vlan.vid != vid || !vlan.valid) + if (!vlan.valid) return -EOPNOTSUPP; fid = vlan.fid; @@ -1964,14 +1965,11 @@ static int mv88e6xxx_port_vlan_join(struct mv88e6xxx_chip *chip, int port, struct mv88e6xxx_vtu_entry vlan; int i, err; - vlan.vid = vid - 1; - vlan.valid = false; - - err = mv88e6xxx_vtu_getnext(chip, &vlan); + err = mv88e6xxx_vtu_get(chip, vid, &vlan); if (err) return err; - if (vlan.vid != vid || !vlan.valid) { + if (!vlan.valid) { memset(&vlan, 0, sizeof(vlan)); err = mv88e6xxx_atu_new(chip, &vlan.fid); @@ -2067,17 +2065,14 @@ static int mv88e6xxx_port_vlan_leave(struct mv88e6xxx_chip *chip, if (!vid) return -EOPNOTSUPP; - vlan.vid = vid - 1; - vlan.valid = false; - - err = mv88e6xxx_vtu_getnext(chip, &vlan); + err = mv88e6xxx_vtu_get(chip, vid, &vlan); if (err) return err; /* If the VLAN doesn't exist in hardware or the port isn't a member, * tell switchdev that this VLAN is likely handled in software. */ - if (vlan.vid != vid || !vlan.valid || + if (!vlan.valid || vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) return -EOPNOTSUPP; From patchwork Mon Mar 15 21:13:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 400986 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C20DFC4332D for ; Mon, 15 Mar 2021 21:15:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8F07C64F3F for ; Mon, 15 Mar 2021 21:15:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232307AbhCOVPP (ORCPT ); Mon, 15 Mar 2021 17:15:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230469AbhCOVPJ (ORCPT ); Mon, 15 Mar 2021 17:15:09 -0400 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58EB6C06174A for ; Mon, 15 Mar 2021 14:15:09 -0700 (PDT) Received: by mail-lf1-x12d.google.com with SMTP id v9so59144870lfa.1 for ; Mon, 15 Mar 2021 14:15:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:organization:content-transfer-encoding; bh=/fEDJ/+UtGgOsosVbiVuQs5SVczo3uICiP9N+8NI0Gk=; b=zVYKtfyvKhQdO0/DvbCRgRbHjdpR8Vcktyx0qjh6gzmaobdAnz3IPF9KuUo7jvkap7 f6FgiuMpct/T2P6bgUQdRXpz9q90v/PR9v0EcGrY7pAZBAhIur0fYvIY6tocARHVm+C+ rGeYvjaFcgrd7XbpUwZooNISrie9BjtyiJ8nAA/Y8S7RojZTQR8xA9UEp2+bl7IXT6c6 6x+zo9NFYnKo5haou3UMV9Sj9Fzj/ECnAEogThfg011C9+KKaDkxQ0MFaGdsFHGG1cdk LQoRVAWIEqqMOxZ7kB/6aAty90apDUl1yoKRrw+V4E0xnsLiKROocSr6zSsEAiVk0YcT 6eTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:organization:content-transfer-encoding; bh=/fEDJ/+UtGgOsosVbiVuQs5SVczo3uICiP9N+8NI0Gk=; b=Td2POlM08p3ZvLZSXNj/A5tn1k/D/79dv5WxUNkH2O3nyWvZMi70lSrPbr7YJgBNl9 RjGet9D1BVBzs5JcT2ME5V5J8PyWHFF8l2IwdItFNWr7DehBmbGiY9ZNnrD9ENcF37Dj DPa8yvqrPGJFcTO9sc6USjd5KxQrPkFIVhaL40rjffZXV+KKSqCEFfWZNQV5QBx7bzBp dmd4mZ3170j7hL1RHe/NjwLk+U4wtrbbslRC8Sz818XbdjSCiOEF8iaw2PfeaaocEqMr R61Hy5rKjO9nDsy/aS3Yp4Q4xhv255S2OzwuH2N2oYUNycZDERGqes7SQB9yIjS69y48 dsqg== X-Gm-Message-State: AOAM531ccFU9HOHUtMulMVJ1ObUeLRJ2rWUyiE6pgnju35/cFJg8m555 d2ZqE6d/S6GMYfdGDOPlcfnLT7h0NHuLU5ox X-Google-Smtp-Source: ABdhPJzy28qmHZMc6p2lj5ENY4YdNuz20am3qJvaq5cSa5guD1EAuhqnTwhF9O1xwq1ZC0NEcV3pVw== X-Received: by 2002:a05:6512:200a:: with SMTP id a10mr8636103lfb.564.1615842907893; Mon, 15 Mar 2021 14:15:07 -0700 (PDT) Received: from veiron.westermo.com (static-193-12-47-89.cust.tele2.se. [193.12.47.89]) by smtp.gmail.com with ESMTPSA id v11sm2975003ljp.63.2021.03.15.14.15.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 14:15:07 -0700 (PDT) From: Tobias Waldekranz To: davem@davemloft.net, kuba@kernel.org Cc: andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, olteanv@gmail.com, netdev@vger.kernel.org Subject: [PATCH net-next 3/5] net: dsa: mv88e6xxx: Flood all traffic classes on standalone ports Date: Mon, 15 Mar 2021 22:13:58 +0100 Message-Id: <20210315211400.2805330-4-tobias@waldekranz.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210315211400.2805330-1-tobias@waldekranz.com> References: <20210315211400.2805330-1-tobias@waldekranz.com> MIME-Version: 1.0 Organization: Westermo Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org In accordance with the comment in dsa_port_bridge_leave, standalone ports shall be configured to flood all types of traffic. This change aligns the mv88e6xxx driver with that policy. Previously a standalone port would initially not egress any unknown traffic, but after joining and then leaving a bridge, it would. This does not matter that much since we only ever send FROM_CPUs on standalone ports, but it seems prudent to make sure that the initial values match those that are applied after a bridging/unbridging cycle. Signed-off-by: Tobias Waldekranz Reviewed-by: Vladimir Oltean Reviewed-by: Florian Fainelli Reviewed-by: Andrew Lunn --- drivers/net/dsa/mv88e6xxx/chip.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index 86027e98d83d..01e4ac32d1e5 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -2457,19 +2457,15 @@ static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port) static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port) { - struct dsa_switch *ds = chip->ds; - bool flood; int err; - /* Upstream ports flood frames with unknown unicast or multicast DA */ - flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port); if (chip->info->ops->port_set_ucast_flood) { - err = chip->info->ops->port_set_ucast_flood(chip, port, flood); + err = chip->info->ops->port_set_ucast_flood(chip, port, true); if (err) return err; } if (chip->info->ops->port_set_mcast_flood) { - err = chip->info->ops->port_set_mcast_flood(chip, port, flood); + err = chip->info->ops->port_set_mcast_flood(chip, port, true); if (err) return err; } From patchwork Mon Mar 15 21:13:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 400987 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97CC3C433E9 for ; Mon, 15 Mar 2021 21:15:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 47BA564F50 for ; Mon, 15 Mar 2021 21:15:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232025AbhCOVPO (ORCPT ); Mon, 15 Mar 2021 17:15:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231178AbhCOVPK (ORCPT ); Mon, 15 Mar 2021 17:15:10 -0400 Received: from mail-lj1-x231.google.com (mail-lj1-x231.google.com [IPv6:2a00:1450:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04230C06175F for ; Mon, 15 Mar 2021 14:15:10 -0700 (PDT) Received: by mail-lj1-x231.google.com with SMTP id z25so17990957lja.3 for ; Mon, 15 Mar 2021 14:15:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:organization:content-transfer-encoding; bh=NBVpGbR92gdeBgZlfx4q1NYmX4rD8uVZtTpiu2+w42Y=; b=nuGTEtX5V3gsp7jFgJHXSUisqe9dkxzKwCM3qOkIr7Iy/Lo16PRsiRoEq4bIicAcqt o/XhqX+DCgGnFUo94dKiERW+Iybxq1AIGqF7Ae0TXXzgGfSVyWm1L1KoumLhFAZiLL7f XucQWyl+VWWkEO/Y/1VBDSJMeJIi9tqv3YuSOw7gQBg3NaJMGX5XlE7Otd5PsXLCIY6N hVg7bs7DqwhOuHWYHKsOCLynoahnDK/KVlhjMxkEguXB4f4Pz6SoPnzU+8lPW8G48f3W n+QIWSRcNqor+7Xl16qYoZNnzWq+w4mo/VSOOWggTl8OHRQRiarouI/MlbrJoez070gV EhrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:organization:content-transfer-encoding; bh=NBVpGbR92gdeBgZlfx4q1NYmX4rD8uVZtTpiu2+w42Y=; b=f4txTk/wbn9FF1m66ElBV3rzYvEjx1MyqVWgIVrFpSvobqoSBQpe6kfCBb943ddcUL JfhaTAHeo5qagUjeesuDevXXAiwl4pVaiQ/3lCcthU9w8V+zKNplwdi9CaT+RCG51TaV 5d7dt4jKfA2NgXKdbzxwArAWLxCGpWpxSeeUok6Xry9AHL0tt7CXy7lC2Q3toCWuCGMA cg0R3E8PyInhdNr97VrI7mV2aZuux1CeykJH8/K5loRMadxtAugXnDY85w6Ioxx8XtJh ogxQHEZ9/diXOF3fvC/mBw/BA8Ow0RZxYFhXQZwmvm95tUaggPfwHiUZbml5eGYZ11kx cETQ== X-Gm-Message-State: AOAM532Z0ngVvEBfxkqgnKBGIqSLU22bvNI1CHEMY1dHFMPoQ+2XAArd XuM3sDaNHcWYDusuyZE0v8zQDw== X-Google-Smtp-Source: ABdhPJwV9DZeL0hm4N9aKm1FQPuELBTh2dF5zIVYdl1NJ8LfPpWB8UNCV01mA6aOOaxoLv0kFh025w== X-Received: by 2002:a2e:974f:: with SMTP id f15mr581138ljj.352.1615842908529; Mon, 15 Mar 2021 14:15:08 -0700 (PDT) Received: from veiron.westermo.com (static-193-12-47-89.cust.tele2.se. [193.12.47.89]) by smtp.gmail.com with ESMTPSA id v11sm2975003ljp.63.2021.03.15.14.15.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 14:15:08 -0700 (PDT) From: Tobias Waldekranz To: davem@davemloft.net, kuba@kernel.org Cc: andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, olteanv@gmail.com, netdev@vger.kernel.org Subject: [PATCH net-next 4/5] net: dsa: mv88e6xxx: Offload bridge learning flag Date: Mon, 15 Mar 2021 22:13:59 +0100 Message-Id: <20210315211400.2805330-5-tobias@waldekranz.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210315211400.2805330-1-tobias@waldekranz.com> References: <20210315211400.2805330-1-tobias@waldekranz.com> MIME-Version: 1.0 Organization: Westermo Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Allow a user to control automatic learning per port. Many chips have an explicit "LearningDisable"-bit that can be used for this, but we opt for setting/clearing the PAV instead, as it works on all devices at least as far back as 6083. Signed-off-by: Tobias Waldekranz --- drivers/net/dsa/mv88e6xxx/chip.c | 29 +++++++++++++++++++++-------- drivers/net/dsa/mv88e6xxx/port.c | 21 +++++++++++++++++++++ drivers/net/dsa/mv88e6xxx/port.h | 2 ++ 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index 01e4ac32d1e5..48e65f22641e 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -2689,15 +2689,20 @@ static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port) return err; } - /* Port Association Vector: when learning source addresses - * of packets, add the address to the address database using - * a port bitmap that has only the bit for this port set and - * the other bits clear. + /* Port Association Vector: disable automatic address learning + * on all user ports since they start out in standalone + * mode. When joining a bridge, learning will be configured to + * match the bridge port settings. Enable learning on all + * DSA/CPU ports. NOTE: FROM_CPU frames always bypass the + * learning process. + * + * Disable HoldAt1, IntOnAgeOut, LockedPort, IgnoreWrongData, + * and RefreshLocked. I.e. setup standard automatic learning. */ - reg = 1 << port; - /* Disable learning for CPU port */ - if (dsa_is_cpu_port(ds, port)) + if (dsa_is_user_port(ds, port)) reg = 0; + else + reg = 1 << port; err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR, reg); @@ -5426,7 +5431,7 @@ static int mv88e6xxx_port_pre_bridge_flags(struct dsa_switch *ds, int port, struct mv88e6xxx_chip *chip = ds->priv; const struct mv88e6xxx_ops *ops; - if (flags.mask & ~(BR_FLOOD | BR_MCAST_FLOOD)) + if (flags.mask & ~(BR_LEARNING | BR_FLOOD | BR_MCAST_FLOOD)) return -EINVAL; ops = chip->info->ops; @@ -5449,6 +5454,14 @@ static int mv88e6xxx_port_bridge_flags(struct dsa_switch *ds, int port, mv88e6xxx_reg_lock(chip); + if (flags.mask & BR_LEARNING) { + u16 pav = (flags.val & BR_LEARNING) ? (1 << port) : 0; + + err = mv88e6xxx_port_set_assoc_vector(chip, port, pav); + if (err) + goto out; + } + if (flags.mask & BR_FLOOD) { bool unicast = !!(flags.val & BR_FLOOD); diff --git a/drivers/net/dsa/mv88e6xxx/port.c b/drivers/net/dsa/mv88e6xxx/port.c index 4561f289ab76..d716cd61b6c6 100644 --- a/drivers/net/dsa/mv88e6xxx/port.c +++ b/drivers/net/dsa/mv88e6xxx/port.c @@ -1171,6 +1171,27 @@ int mv88e6097_port_egress_rate_limiting(struct mv88e6xxx_chip *chip, int port) 0x0001); } +/* Offset 0x0B: Port Association Vector */ + +int mv88e6xxx_port_set_assoc_vector(struct mv88e6xxx_chip *chip, int port, + u16 pav) +{ + u16 reg, mask; + int err; + + err = mv88e6xxx_port_read(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR, + ®); + if (err) + return err; + + mask = GENMASK(mv88e6xxx_num_ports(chip), 0); + reg &= ~mask; + reg |= pav & mask; + + return mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR, + reg); +} + /* Offset 0x0C: Port ATU Control */ int mv88e6xxx_port_disable_learn_limit(struct mv88e6xxx_chip *chip, int port) diff --git a/drivers/net/dsa/mv88e6xxx/port.h b/drivers/net/dsa/mv88e6xxx/port.h index e6d0eaa6aa1d..635b6571a0e9 100644 --- a/drivers/net/dsa/mv88e6xxx/port.h +++ b/drivers/net/dsa/mv88e6xxx/port.h @@ -361,6 +361,8 @@ int mv88e6165_port_set_jumbo_size(struct mv88e6xxx_chip *chip, int port, size_t size); int mv88e6095_port_egress_rate_limiting(struct mv88e6xxx_chip *chip, int port); int mv88e6097_port_egress_rate_limiting(struct mv88e6xxx_chip *chip, int port); +int mv88e6xxx_port_set_assoc_vector(struct mv88e6xxx_chip *chip, int port, + u16 pav); int mv88e6097_port_pause_limit(struct mv88e6xxx_chip *chip, int port, u8 in, u8 out); int mv88e6390_port_pause_limit(struct mv88e6xxx_chip *chip, int port, u8 in, From patchwork Mon Mar 15 21:14:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 402363 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9BCFFC43381 for ; Mon, 15 Mar 2021 21:15:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 686B964F52 for ; Mon, 15 Mar 2021 21:15:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232392AbhCOVPQ (ORCPT ); Mon, 15 Mar 2021 17:15:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231194AbhCOVPL (ORCPT ); Mon, 15 Mar 2021 17:15:11 -0400 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2F2AC06174A for ; Mon, 15 Mar 2021 14:15:10 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id t18so11345345lfl.3 for ; Mon, 15 Mar 2021 14:15:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:organization:content-transfer-encoding; bh=OxZK0EpkWuwxaCH5ICgb9sgxnbVsd3E2N4MHrwUkx8s=; b=dXlQ7SMyfSmLSUU+sWRXv4FZ3LEx89DlUxfp5Jq9BMN24TdhoJlQVurWPJnA609uGY 96MQF9nowa5GexugRSVdSWKANLEgkCsA+F9ZyeqHbSFVcr4tdVwXU0MYX/tNwUiwzJWg OHSgZOStmZ8HMWnGvhgAL43HKJE4Gi17qFY/y2gRrCDCMTyPvNNSfRHSuDCx/2Pxb1G7 nr+AaTtsSEQQ9U+0OQhVkSx+LXkGuzel4SbY6RohHKHf5EirbLak5LeQctOm2jA7vwlG W5LwSY33E8UuWL/0GCyeZxDdDRmhB9QwPOp3zKYRvHIhhs8Xo8k+K0VoGJlTpn6wnPee FxlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:organization:content-transfer-encoding; bh=OxZK0EpkWuwxaCH5ICgb9sgxnbVsd3E2N4MHrwUkx8s=; b=Wvh125NbfoIQGimFd6RDhAPdpDEsLZxN8cmLlHJky4CzFHhH/ksRA7aeC2Ni5RHwoT xPXOyfaqEQPekhu2HfuKvkaIVCRGtPF8AaOKvTl8QgWboUvLKoOBzCnKuxBBH4k0Xh0j ds7ECyDOiONVP+Pnnh/kztoZdqIJUAZJ40gzgIPqHLO67/jGxYiXfyCS2sqhxv+mcoof t4vq5PLVItIKftix6l4pA4mBzeGhCYMlRnL5ovei5oYcYQMSSiuCypRURhz7CKc5usiB /bt/sdv87UC7l6lpYVbTt65+iAFFpGkL6UrOFv0mtFg9NakSDRhYy0Idx7gq+uASUAkg GUOQ== X-Gm-Message-State: AOAM531kkt7OrOdJXf2C8Bz1JlAYvhP46fFMzYuKVmr/uGaqkdalcOgq 62K+F/XGbgZmTBhY/LANebuscA== X-Google-Smtp-Source: ABdhPJz4o+QshmOCB9zoagYuFW5MY9OmiyLkJzXGocOJ/0w0ye/kQIlNbfEA/AsS5nZBOYUL89bvmw== X-Received: by 2002:ac2:5e62:: with SMTP id a2mr9722608lfr.385.1615842909237; Mon, 15 Mar 2021 14:15:09 -0700 (PDT) Received: from veiron.westermo.com (static-193-12-47-89.cust.tele2.se. [193.12.47.89]) by smtp.gmail.com with ESMTPSA id v11sm2975003ljp.63.2021.03.15.14.15.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 14:15:08 -0700 (PDT) From: Tobias Waldekranz To: davem@davemloft.net, kuba@kernel.org Cc: andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, olteanv@gmail.com, netdev@vger.kernel.org Subject: [PATCH net-next 5/5] net: dsa: mv88e6xxx: Offload bridge broadcast flooding flag Date: Mon, 15 Mar 2021 22:14:00 +0100 Message-Id: <20210315211400.2805330-6-tobias@waldekranz.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210315211400.2805330-1-tobias@waldekranz.com> References: <20210315211400.2805330-1-tobias@waldekranz.com> MIME-Version: 1.0 Organization: Westermo Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org These switches have two modes of classifying broadcast: 1. Broadcast is multicast. 2. Broadcast is its own unique thing that is always flooded everywhere. This driver uses the first option, making sure to load the broadcast address into all active databases. Because of this, we can support per-port broadcast flooding by (1) making sure to only set the subset of ports that have it enabled whenever joining a new bridge or VLAN, and (2) by updating all active databases whenever the setting is changed on a port. Signed-off-by: Tobias Waldekranz --- drivers/net/dsa/mv88e6xxx/chip.c | 68 +++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index 48e65f22641e..e6987c501fb7 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -1950,6 +1950,18 @@ static int mv88e6xxx_broadcast_setup(struct mv88e6xxx_chip *chip, u16 vid) int err; for (port = 0; port < mv88e6xxx_num_ports(chip); port++) { + struct dsa_port *dp = dsa_to_port(chip->ds, port); + + if (dsa_is_unused_port(chip->ds, port)) + continue; + + if (dsa_is_user_port(chip->ds, port) && dp->bridge_dev && + !br_port_flag_is_set(dp->slave, BR_BCAST_FLOOD)) + /* Skip bridged user ports where broadcast + * flooding is disabled. + */ + continue; + err = mv88e6xxx_port_add_broadcast(chip, port, vid); if (err) return err; @@ -1958,6 +1970,51 @@ static int mv88e6xxx_broadcast_setup(struct mv88e6xxx_chip *chip, u16 vid) return 0; } +struct mv88e6xxx_port_broadcast_sync_ctx { + int port; + bool flood; +}; + +static int +mv88e6xxx_port_broadcast_sync_vlan(struct mv88e6xxx_chip *chip, + const struct mv88e6xxx_vtu_entry *vlan, + void *_ctx) +{ + const char broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; + struct mv88e6xxx_port_broadcast_sync_ctx *ctx = _ctx; + u8 state; + + if (ctx->flood) + state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC; + else + state = MV88E6XXX_G1_ATU_DATA_STATE_MC_UNUSED; + + return mv88e6xxx_port_db_load_purge(chip, ctx->port, broadcast, + vlan->vid, state); +} + +static int mv88e6xxx_port_broadcast_sync(struct mv88e6xxx_chip *chip, int port, + bool flood) +{ + struct mv88e6xxx_port_broadcast_sync_ctx ctx = { + .port = port, + .flood = flood, + }; + struct mv88e6xxx_vtu_entry vid0 = { + .vid = 0, + }; + int err; + + /* Update the port's private database... */ + err = mv88e6xxx_port_broadcast_sync_vlan(chip, &vid0, &ctx); + if (err) + return err; + + /* ...and the database for all VLANs. */ + return mv88e6xxx_vtu_walk(chip, mv88e6xxx_port_broadcast_sync_vlan, + &ctx); +} + static int mv88e6xxx_port_vlan_join(struct mv88e6xxx_chip *chip, int port, u16 vid, u8 member, bool warn) { @@ -5431,7 +5488,8 @@ static int mv88e6xxx_port_pre_bridge_flags(struct dsa_switch *ds, int port, struct mv88e6xxx_chip *chip = ds->priv; const struct mv88e6xxx_ops *ops; - if (flags.mask & ~(BR_LEARNING | BR_FLOOD | BR_MCAST_FLOOD)) + if (flags.mask & ~(BR_LEARNING | BR_FLOOD | BR_MCAST_FLOOD | + BR_BCAST_FLOOD)) return -EINVAL; ops = chip->info->ops; @@ -5480,6 +5538,14 @@ static int mv88e6xxx_port_bridge_flags(struct dsa_switch *ds, int port, goto out; } + if (flags.mask & BR_BCAST_FLOOD) { + bool broadcast = !!(flags.val & BR_BCAST_FLOOD); + + err = mv88e6xxx_port_broadcast_sync(chip, port, broadcast); + if (err) + goto out; + } + out: mv88e6xxx_reg_unlock(chip);