Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp2378824pxf; Sat, 3 Apr 2021 23:05:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwL2kLcMHMWvkxMt/ElH745ALgjahO8qAoyVUfAHLPn6A7kzUfVP786rC7PNMS+MXlXyGnR X-Received: by 2002:a5e:990f:: with SMTP id t15mr15404410ioj.180.1617516337696; Sat, 03 Apr 2021 23:05:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617516337; cv=none; d=google.com; s=arc-20160816; b=iCmxcMVDB77OQNWsQbqMXjB2fO3Efn1fX/HUFerbjJ8ocs3CyQ2nlr3BpYtbXVq/rZ MXpSIAo5laqG5zvdSpfPVNoLmDzA73qg+u9sZ09Oc/YnVrpcfKVd+r2J4NmajZIlW4kp cslrh/zgrc9G5ajDXZDnpXsrd09ONwvj8LFWt+SuXVeXHFI769mXXg7voRnAgYQS3O6y Zw/oI9J6i2V+sUrDDfr43gLcu96+B3o/Ybjs0L/M1VjwpIQIALJuLWxwCdzWiC+IeFR6 LvqBne1unhCXtUmf9sHrL808p340hJkbMbJyHF6N26PSB5do+lG1USFBZxkIKC/xgn9I +XoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=MKuh5jxGMa1xGTyQSl1tE3MrghO2Y1kJfEr3aWwqz7k=; b=ctAijYAL0Z27DUQvr/lXiu2AsK0IvouxF8dcsN6+pYkJROAKkc0I5rN/ShRGpZpO9F RNW4n0L2jQr1aL3NSesxaqa9NJA3C6MEa2bRsIkJGaBdkCjtORwHxr5TW2Ac5E8jPBBe dvywJu+eGtr/6Ic35bQrBp4NquC1v3Cro5KZYeDlX+SGmaISgjomWlXA6YUFIwHnDZat w8WehQP0U6e6YzGaiVzZ2f1MVwpXSmtc0zWz4TfPOnrGythuLK9Ob+XhYtFzrDdwJ3Xq lvvwFdiI+3gB3MOL0fdE2z4B0dL1/hWJhW71x+g9dAnPHZRg9itpqBf2JCIHVEOUw9q0 n3Yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.net header.s=badeba3b8450 header.b="gmUEV/MP"; 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 b12si11698889jaq.101.2021.04.03.23.05.24; Sat, 03 Apr 2021 23:05:37 -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; dkim=pass header.i=@gmx.net header.s=badeba3b8450 header.b="gmUEV/MP"; 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 S232338AbhDDGFF (ORCPT + 99 others); Sun, 4 Apr 2021 02:05:05 -0400 Received: from mout.gmx.net ([212.227.15.19]:52127 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229566AbhDDGFC (ORCPT ); Sun, 4 Apr 2021 02:05:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1617516287; bh=wfWZ0j/dMPCdegx9KjeoR7iuxOiNjoYJMvG3Z5+9snQ=; h=X-UI-Sender-Class:Subject:To:Cc:References:From:Date:In-Reply-To; b=gmUEV/MP5ujQ9LjmwhnHWnC5jdBSubnWEbJlnLE72is1rQBPyOEQSTbR+j45Kb4fq hI/aAnrDTpAf8//C9iV7unBh2WKqcornT5VWvOp+FfQauY9ma01oJRUIeGprxCd7v9 cEN4qnhOgLUsetTCtT8ajd6uAFZVd/du65KxF++k= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.178.44] ([95.91.192.147]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1N6sn7-1lfOXR3IeV-018MBg; Sun, 04 Apr 2021 08:04:46 +0200 Subject: Re: [PATCH net-next v1 4/9] net: dsa: qca: ar9331: make proper initial port defaults To: Vladimir Oltean , Oleksij Rempel Cc: Andrew Lunn , Vivien Didelot , Florian Fainelli , "David S. Miller" , Jakub Kicinski , Russell King , Pengutronix Kernel Team , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org References: <20210403114848.30528-1-o.rempel@pengutronix.de> <20210403114848.30528-5-o.rempel@pengutronix.de> <20210404001630.paqmt4v63d5gewy5@skbuf> From: Oleksij Rempel Message-ID: Date: Sun, 4 Apr 2021 08:04:44 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: <20210404001630.paqmt4v63d5gewy5@skbuf> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:DroEABeeuDI2OiLwvdHA0jAVifanj7KQVAZp/9D6C0bI+GOt9DR 8W1ZCaA+7Rdb3ZckShg5c2jQuL/hDsGZRvwN3jBKK+zJzt5Tw7uGaVCcl1qhrYBCm96z0B1 26C+QMrKvD1FyEF2firqjkwhONp0riS+25jA6tdk/OPfj7YMx4SbZrqy8hKfRJw8/yMmymB sDlq7Bthivm97ARF2M4WQ== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:wHK9S2rjuAg=:cKkkusv0FVSzeqK3fp9Urw sOOydvc/MztCG7dEL7HbPcEGPEWke317J6pREHnzcNOZbb+Add6EW/hTNrBQkYt+BFTN/5RDF cGJI5v7wZaB+8blD2GcUe3ArRqKra7Cs1IX9h67g65d6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rDOwsLVpYwW7UPoaTnMoE7WWd8IcIpUrVi29V4WKd33R01keWWSQIGzTEGfQ K2Xv/mH/boz3yFWqv Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am 04.04.21 um 02:16 schrieb Vladimir Oltean: > On Sat, Apr 03, 2021 at 01:48:43PM +0200, Oleksij Rempel wrote: >> Make sure that all external port are actually isolated from each other, >> so no packets are leaked. >> >> Signed-off-by: Oleksij Rempel >> --- >> drivers/net/dsa/qca/ar9331.c | 145 ++++++++++++++++++++++++++++++++++- >> 1 file changed, 143 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/net/dsa/qca/ar9331.c b/drivers/net/dsa/qca/ar9331.= c >> index 9a5035b2f0ff..a3de3598fbf5 100644 >> --- a/drivers/net/dsa/qca/ar9331.c >> +++ b/drivers/net/dsa/qca/ar9331.c >> @@ -60,10 +60,19 @@ >> >> /* MIB registers */ >> #define AR9331_MIB_COUNTER(x) (0x20000 + ((x) * 0x100)) >> >> @@ -229,6 +278,7 @@ struct ar9331_sw_priv { >> struct regmap *regmap; >> struct reset_control *sw_reset; >> struct ar9331_sw_port port[AR9331_SW_PORTS]; >> + int cpu_port; >> }; >> >> static struct ar9331_sw_priv *ar9331_sw_port_to_priv(struct ar9331_sw_= port *port) >> @@ -371,12 +421,72 @@ static int ar9331_sw_mbus_init(struct ar9331_sw_p= riv *priv) >> return 0; >> } >> >> -static int ar9331_sw_setup(struct dsa_switch *ds) >> +static int ar9331_sw_setup_port(struct dsa_switch *ds, int port) >> { >> struct ar9331_sw_priv *priv =3D (struct ar9331_sw_priv *)ds->priv; >> struct regmap *regmap =3D priv->regmap; >> + u32 port_mask, port_ctrl, val; >> int ret; >> >> + /* Generate default port settings */ >> + port_ctrl =3D FIELD_PREP(AR9331_SW_PORT_CTRL_PORT_STATE, >> + AR9331_SW_PORT_CTRL_PORT_STATE_DISABLED); >> + >> + if (dsa_is_cpu_port(ds, port)) { >> + /* >> + * CPU port should be allowed to communicate with all user >> + * ports. >> + */ >> + //port_mask =3D dsa_user_ports(ds); > > Code commented out should ideally not be part of a submitted patch. Sorry I overlooked this one > And the networking comment style is: > > /* CPU port should be allowed to communicate with all user > * ports. > */ Aaa... networking part of kernel code... >> + port_mask =3D 0; >> + /* >> + * Enable atheros header on CPU port. This will allow us >> + * communicate with each port separately >> + */ >> + port_ctrl |=3D AR9331_SW_PORT_CTRL_HEAD_EN; >> + port_ctrl |=3D AR9331_SW_PORT_CTRL_LEARN_EN; >> + } else if (dsa_is_user_port(ds, port)) { >> + /* >> + * User ports should communicate only with the CPU port. >> + */ >> + port_mask =3D BIT(priv->cpu_port); > > For all you care, the CPU port here is dsa_to_port(ds, port)->cpu_dp->in= dex, > no need to go to those lengths in order to find it. DSA does not have > fixed number for the CPU port but a CPU port pointer per port in order > to not close the door for the future support of multiple CPU ports. ok. >> + /* Enable unicast address learning by default */ >> + port_ctrl |=3D AR9331_SW_PORT_CTRL_LEARN_EN >> + /* IGMP snooping seems to work correctly, let's use it */ >> + | AR9331_SW_PORT_CTRL_IGMP_MLD_EN > > I don't really like this ad-hoc enablement of IGMP/MLD snooping from the= driver, > please add the pass-through in DSA for SWITCHDEV_ATTR_ID_BRIDGE_MC_DISAB= LED > (dsa_slave_port_attr_set, dsa_port_switchdev_sync, dsa_port_switchdev_un= sync > should all call a dsa_switch_ops :: port_snoop_igmp_mld function) and th= en > toggle this bit from there. sounds good. Looks like there are few more driver need to be fixed: drivers/net/dsa/lan9303-core.c drivers/net/dsa/mv88e6xxx/chip.c > >> + | AR9331_SW_PORT_CTRL_SINGLE_VLAN_EN; >> + } else { >> + /* Other ports do not need to communicate at all */ >> + port_mask =3D 0; >> + } >> + >> + val =3D FIELD_PREP(AR9331_SW_PORT_VLAN_8021Q_MODE, >> + AR9331_SW_8021Q_MODE_NONE) | >> + FIELD_PREP(AR9331_SW_PORT_VLAN_PORT_VID_MEMBER, port_mask) | >> + FIELD_PREP(AR9331_SW_PORT_VLAN_PORT_VID, >> + AR9331_SW_PORT_VLAN_PORT_VID_DEF); >> + >> + ret =3D regmap_write(regmap, AR9331_SW_REG_PORT_VLAN(port), val); >> + if (ret) >> + goto error; >> + >> + ret =3D regmap_write(regmap, AR9331_SW_REG_PORT_CTRL(port), port_ctrl= ); >> + if (ret) >> + goto error; >> + >> + return 0; >> +error: >> + dev_err_ratelimited(priv->dev, "%s: error: %i\n", __func__, ret); >> + >> + return ret; >> +} >> + >> +static int ar9331_sw_setup(struct dsa_switch *ds) >> +{ >> + struct ar9331_sw_priv *priv =3D (struct ar9331_sw_priv *)ds->priv; >> + struct regmap *regmap =3D priv->regmap; >> + int ret, i; >> + >> ret =3D ar9331_sw_reset(priv); >> if (ret) >> return ret; >> @@ -390,7 +500,8 @@ static int ar9331_sw_setup(struct dsa_switch *ds) >> >> /* Do not drop broadcast frames */ >> ret =3D regmap_write_bits(regmap, AR9331_SW_REG_FLOOD_MASK, >> - AR9331_SW_FLOOD_MASK_BROAD_TO_CPU, >> + AR9331_SW_FLOOD_MASK_BROAD_TO_CPU >> + | AR9331_SW_FLOOD_MASK_MULTI_FLOOD_DP, >> AR9331_SW_FLOOD_MASK_BROAD_TO_CPU); >> if (ret) >> goto error; >> @@ -402,6 +513,36 @@ static int ar9331_sw_setup(struct dsa_switch *ds) >> if (ret) >> goto error; >> >> + /* >> + * Configure the ARL: >> + * AR9331_SW_AT_ARP_EN - why? >> + * AR9331_SW_AT_LEARN_CHANGE_EN - why? >> + */ > > Good question, why? I still do not know if it is a good idea. This bits are enabled by default. May be you can help me understand it. Datasheet says: ARP_EN: ARP frame acknowledge enable. Setting this bit to 1 is an acknowledgement by the hardware of a received ARP frame and allows it to be copied to the CPU port. LEARN_CHANGE_EN: 0 - If a hash violation occurs during learning, no new address will be learned in the ARL 1 - Enables a new MAC address change if a hash violation occurs during learning =2D- Regards, Oleksij