Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp2031185pxf; Sat, 3 Apr 2021 08:32:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwMc3jeDqcHT6VG5qvbzGxrs/p4Y7j2FIWm4bWqa/gF/2T11EnDtfWmzSK50JbjXyzC6Z4T X-Received: by 2002:a17:906:72d1:: with SMTP id m17mr19361355ejl.118.1617463943528; Sat, 03 Apr 2021 08:32:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617463943; cv=none; d=google.com; s=arc-20160816; b=DYEzhpemmybyeHkuw8qCd6eZsuzc1RCkIxVphqeulHocdDbrJc1UY+4cmxPpaTlZkg GfOnGCSrw3Ll9grkwOy9cZ/mi5LumHE8HuRytHiHfGXU67c6CQGhEOeyHzOfErxmuHYL Qt3KobjW258hervU5Vw9hmWWfSgsMT5ez4tJ+aQvwglLpBLfgGlThTVp+I2d4PfirWoU PcxoPTUOJH3S9BWfBGLRWc9+oybPgQSzqyGDdd4dd7K14xrVTigrASUdOwVhJnr1Riaa dChso+i5X1LX5INCT+HTmFjFXHlbc3R2t0lTGGVlYCCmHm/tL7KiEOEeyQjx7ThzKDgo r4Vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=wjBImK0LQ5dvxLxLJaBC3FlQIeyrEjy8Xsz1skrcqI4=; b=m/i5Hyj8eEqzbVA/rVp3H/NLCnZaug3ljhla0TCL3ZyAzyCM0ZaEsqpC8nlla7AKmL ucZNN2wpDI68w8lNSBNLDUtNLYCstgDorxRvFep/IB8cku1w2X00ZH9uEmKCFi4e64vm SDwTYeHrxqXj8oDKaUPBCPE85c7yaB5QDuT8OAP8DWxzw7hyNZVnShBSYS3lKXafP4cV 57Lj0lO/ulcQJImF8OaCnm3ls8j+YoP9XyOsXAOiqstSXI4YjZYN2PgZxhpq//hG6t0Z 07j17Y9Mh/p0vchKW7klhvXH1Abm3b1g8QLJufKXS8ueW3UhlXi7LT7xd1fGA3HxsUoE O8fw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dr9si9789145ejc.436.2021.04.03.08.32.00; Sat, 03 Apr 2021 08:32:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236808AbhDCPbg (ORCPT + 99 others); Sat, 3 Apr 2021 11:31:36 -0400 Received: from vps0.lunn.ch ([185.16.172.187]:32884 "EHLO vps0.lunn.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236615AbhDCPbg (ORCPT ); Sat, 3 Apr 2021 11:31:36 -0400 Received: from andrew by vps0.lunn.ch with local (Exim 4.94) (envelope-from ) id 1lSiFE-00EeF7-TB; Sat, 03 Apr 2021 17:31:28 +0200 Date: Sat, 3 Apr 2021 17:31:28 +0200 From: Andrew Lunn To: Oleksij Rempel Cc: Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Jakub Kicinski , Russell King , Pengutronix Kernel Team , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org Subject: Re: [PATCH net-next v1 7/9] net: dsa: qca: ar9331: add bridge support Message-ID: References: <20210403114848.30528-1-o.rempel@pengutronix.de> <20210403114848.30528-8-o.rempel@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210403114848.30528-8-o.rempel@pengutronix.de> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Apr 03, 2021 at 01:48:46PM +0200, Oleksij Rempel wrote: > This switch is providing forwarding matrix, with it we can configure > individual bridges. Potentially we can configure more then one not VLAN > based bridge on this HW. > > Signed-off-by: Oleksij Rempel > --- > drivers/net/dsa/qca/ar9331.c | 73 ++++++++++++++++++++++++++++++++++++ > 1 file changed, 73 insertions(+) > > diff --git a/drivers/net/dsa/qca/ar9331.c b/drivers/net/dsa/qca/ar9331.c > index b2c22ba924f0..bf9588574205 100644 > --- a/drivers/net/dsa/qca/ar9331.c > +++ b/drivers/net/dsa/qca/ar9331.c > @@ -40,6 +40,7 @@ > */ > > #include > +#include > #include > #include > #include > @@ -1134,6 +1135,76 @@ static int ar9331_sw_set_ageing_time(struct dsa_switch *ds, > val); > } > > +static int ar9331_sw_port_bridge_join(struct dsa_switch *ds, int port, > + struct net_device *br) > +{ > + struct ar9331_sw_priv *priv = (struct ar9331_sw_priv *)ds->priv; > + struct regmap *regmap = priv->regmap; > + int port_mask = BIT(priv->cpu_port); > + int i, ret; > + u32 val; > + > + for (i = 0; i < ds->num_ports; i++) { > + if (dsa_to_port(ds, i)->bridge_dev != br) > + continue; > + > + if (!dsa_is_user_port(ds, port)) > + continue; > + > + val = FIELD_PREP(AR9331_SW_PORT_VLAN_PORT_VID_MEMBER, BIT(port)); > + ret = regmap_set_bits(regmap, AR9331_SW_REG_PORT_VLAN(i), val); > + if (ret) > + goto error; > + > + if (i != port) > + port_mask |= BIT(i); > + } > + > + val = FIELD_PREP(AR9331_SW_PORT_VLAN_PORT_VID_MEMBER, port_mask); > + ret = regmap_update_bits(regmap, AR9331_SW_REG_PORT_VLAN(port), > + AR9331_SW_PORT_VLAN_PORT_VID_MEMBER, val); > + if (ret) > + goto error; > + > + return 0; > +error: > + dev_err_ratelimited(priv->dev, "%s: error: %i\n", __func__, ret); > + > + return ret; > +} > + > +static void ar9331_sw_port_bridge_leave(struct dsa_switch *ds, int port, > + struct net_device *br) > +{ > + struct ar9331_sw_priv *priv = (struct ar9331_sw_priv *)ds->priv; > + struct regmap *regmap = priv->regmap; > + int i, ret; > + u32 val; > + > + for (i = 0; i < ds->num_ports; i++) { > + if (dsa_to_port(ds, i)->bridge_dev != br) > + continue; > + > + if (!dsa_is_user_port(ds, port)) > + continue; > + > + val = FIELD_PREP(AR9331_SW_PORT_VLAN_PORT_VID_MEMBER, BIT(port)); > + ret = regmap_clear_bits(regmap, AR9331_SW_REG_PORT_VLAN(i), val); > + if (ret) > + goto error; > + } Join and leave only seems to differ by: > + if (i != port) > + port_mask |= BIT(i); Maybe refactor the code to add a helper for the identical parts? Andrew